From 31b3ef5e10d2b41c7ff7dee4c3e2c74429b76a29 Mon Sep 17 00:00:00 2001 From: "Calvin W. Metcalf B.S" Date: Mon, 15 Jul 2024 14:14:02 -0400 Subject: [PATCH] build --- dist/shp.js | 6343 +++------------------------------------------- dist/shp.min.js | 2 +- test/bundle.js | 6407 +++-------------------------------------------- 3 files changed, 664 insertions(+), 12088 deletions(-) diff --git a/dist/shp.js b/dist/shp.js index d337143..7b9a412 100644 --- a/dist/shp.js +++ b/dist/shp.js @@ -865,7 +865,7 @@ return -9999; } - function init$w() { + function init$v() { var con = this.b / this.a; this.es = 1 - con * con; if(!('x0' in this)){ @@ -954,13 +954,13 @@ var names$w = ["Mercator", "Popular Visualisation Pseudo Mercator", "Mercator_1SP", "Mercator_Auxiliary_Sphere", "merc"]; var merc = { - init: init$w, + init: init$v, forward: forward$u, inverse: inverse$u, names: names$w }; - function init$v() { + function init$u() { //no-op for longlat } @@ -969,7 +969,7 @@ } var names$v = ["longlat", "identity"]; var longlat = { - init: init$v, + init: init$u, forward: identity, inverse: identity, names: names$v @@ -2401,7 +2401,7 @@ */ var SET_ORIGIN_ROW_LETTERS = 'AFAFAF'; - var A = 65; // A + var A$1 = 65; // A var I = 73; // I var O = 79; // O var V = 86; // V @@ -2804,7 +2804,7 @@ var rollover = false; if (colInt > Z) { - colInt = colInt - Z + A - 1; + colInt = colInt - Z + A$1 - 1; rollover = true; } @@ -2821,11 +2821,11 @@ } if (colInt > Z) { - colInt = colInt - Z + A - 1; + colInt = colInt - Z + A$1 - 1; } if (rowInt > V) { - rowInt = rowInt - V + A - 1; + rowInt = rowInt - V + A$1 - 1; rollover = true; } else { @@ -2845,7 +2845,7 @@ } if (rowInt > V) { - rowInt = rowInt - V + A - 1; + rowInt = rowInt - V + A$1 - 1; } var twoLetter = String.fromCharCode(colInt) + String.fromCharCode(rowInt); @@ -2973,7 +2973,7 @@ if (rewindMarker) { throw ("Bad character: " + e); } - curCol = A; + curCol = A$1; rewindMarker = true; } eastingValue += 100000.0; @@ -3024,7 +3024,7 @@ if (rewindMarker) { // making sure that this loop ends throw ("Bad character: " + n); } - curRow = A; + curRow = A$1; rewindMarker = true; } northingValue += 100000.0; @@ -3205,7 +3205,7 @@ // https://github.com/mbloch/mapshaper-proj/blob/master/src/projections/tmerc.js - function init$u() { + function init$t() { this.x0 = this.x0 !== undefined ? this.x0 : 0; this.y0 = this.y0 !== undefined ? this.y0 : 0; this.long0 = this.long0 !== undefined ? this.long0 : 0; @@ -3362,7 +3362,7 @@ var names$t = ["Fast_Transverse_Mercator", "Fast Transverse Mercator"]; var tmerc = { - init: init$u, + init: init$t, forward: forward$s, inverse: inverse$s, names: names$t @@ -3469,7 +3469,7 @@ // https://github.com/mbloch/mapshaper-proj/blob/master/src/projections/etmerc.js - function init$t() { + function init$s() { if (!this.approx && (isNaN(this.es) || this.es <= 0)) { throw new Error('Incorrect elliptical usage. Try using the +approx option in the proj string, or PROJECTION["Fast_Transverse_Mercator"] in the WKT.'); } @@ -3624,7 +3624,7 @@ var names$s = ["Extended_Transverse_Mercator", "Extended Transverse Mercator", "etmerc", "Transverse_Mercator", "Transverse Mercator", "Gauss Kruger", "Gauss_Kruger", "tmerc"]; var etmerc = { - init: init$t, + init: init$s, forward: forward$r, inverse: inverse$r, names: names$s @@ -3646,7 +3646,7 @@ var dependsOn = 'etmerc'; - function init$s() { + function init$r() { var zone = adjust_zone(this.zone, this.long0); if (zone === undefined) { throw new Error('unknown utm zone'); @@ -3664,7 +3664,7 @@ var names$r = ["Universal Transverse Mercator System", "utm"]; var utm = { - init: init$s, + init: init$r, names: names$r, dependsOn: dependsOn }; @@ -3675,7 +3675,7 @@ var MAX_ITER$2 = 20; - function init$r() { + function init$q() { var sphi = Math.sin(this.lat0); var cphi = Math.cos(this.lat0); cphi *= cphi; @@ -3718,13 +3718,13 @@ var names$q = ["gauss"]; var gauss = { - init: init$r, + init: init$q, forward: forward$q, inverse: inverse$q, names: names$q }; - function init$q() { + function init$p() { gauss.init.apply(this); if (!this.rc) { return; @@ -3780,7 +3780,7 @@ var names$p = ["Stereographic_North_Pole", "Oblique_Stereographic", "sterea","Oblique Stereographic Alternative","Double_Stereographic"]; var sterea = { - init: init$q, + init: init$p, forward: forward$p, inverse: inverse$p, names: names$p @@ -3791,7 +3791,7 @@ return (Math.tan(0.5 * (HALF_PI + phit)) * Math.pow((1 - sinphi) / (1 + sinphi), 0.5 * eccen)); } - function init$p() { + function init$o() { // setting default parameters this.x0 = this.x0 || 0; @@ -3955,7 +3955,7 @@ var names$o = ["stere", "Stereographic_South_Pole", "Polar Stereographic (variant B)", "Polar_Stereographic"]; var stere = { - init: init$p, + init: init$o, forward: forward$o, inverse: inverse$o, names: names$o, @@ -3970,7 +3970,7 @@ http://www.swisstopo.admin.ch/internet/swisstopo/fr/home/topics/survey/sys/refsys/switzerland.parsysrelated1.31216.downloadList.77004.DownloadFile.tmp/swissprojectionfr.pdf */ - function init$o() { + function init$n() { var phy0 = this.lat0; this.lambda0 = this.long0; var sinPhy0 = Math.sin(phy0); @@ -4043,7 +4043,7 @@ var names$n = ["somerc"]; var somerc = { - init: init$o, + init: init$n, forward: forward$n, inverse: inverse$n, names: names$n @@ -4061,7 +4061,7 @@ /* Initialize the Oblique Mercator projection ------------------------------------------*/ - function init$n() { + function init$m() { var con, com, cosph0, D, F, H, L, sinph0, p, J, gamma = 0, gamma0, lamc = 0, lam1 = 0, lam2 = 0, phi1 = 0, phi2 = 0, alpha_c = 0; @@ -4280,13 +4280,13 @@ var names$m = ["Hotine_Oblique_Mercator", "Hotine Oblique Mercator", "Hotine_Oblique_Mercator_Azimuth_Natural_Origin", "Hotine_Oblique_Mercator_Two_Point_Natural_Origin", "Hotine_Oblique_Mercator_Azimuth_Center", "Oblique_Mercator", "omerc"]; var omerc = { - init: init$n, + init: init$m, forward: forward$m, inverse: inverse$m, names: names$m }; - function init$m() { + function init$l() { //double lat0; /* the reference latitude */ //double long0; /* the reference longitude */ @@ -4425,13 +4425,13 @@ ]; var lcc = { - init: init$m, + init: init$l, forward: forward$l, inverse: inverse$l, names: names$l }; - function init$l() { + function init$k() { this.a = 6377397.155; this.es = 0.006674372230614; this.e = Math.sqrt(this.es); @@ -4530,7 +4530,7 @@ var names$k = ["Krovak", "krovak"]; var krovak = { - init: init$l, + init: init$k, forward: forward$k, inverse: inverse$k, names: names$k @@ -4582,7 +4582,7 @@ return NaN; } - function init$k() { + function init$j() { if (!this.sphere) { this.e0 = e0fn(this.es); this.e1 = e1fn(this.es); @@ -4674,7 +4674,7 @@ var names$j = ["Cassini", "Cassini_Soldner", "cass"]; var cass = { - init: init$k, + init: init$j, forward: forward$j, inverse: inverse$j, names: names$j @@ -4705,7 +4705,7 @@ /* Initialize the Lambert Azimuthal Equal Area projection ------------------------------------------------------*/ - function init$j() { + function init$i() { var t = Math.abs(this.lat0); if (Math.abs(t - HALF_PI) < EPSLN) { this.mode = this.lat0 < 0 ? this.S_POLE : this.N_POLE; @@ -4974,7 +4974,7 @@ var names$i = ["Lambert Azimuthal Equal Area", "Lambert_Azimuthal_Equal_Area", "laea"]; var laea = { - init: init$j, + init: init$i, forward: forward$i, inverse: inverse$i, names: names$i, @@ -4991,7 +4991,7 @@ return Math.asin(x); } - function init$i() { + function init$h() { if (Math.abs(this.lat1 + this.lat2) < EPSLN) { return; @@ -5108,7 +5108,7 @@ var names$h = ["Albers_Conic_Equal_Area", "Albers", "aea"]; var aea = { - init: init$i, + init: init$h, forward: forward$h, inverse: inverse$h, names: names$h, @@ -5121,7 +5121,7 @@ http://mathworld.wolfram.com/GnomonicProjection.html Accessed: 12th November 2009 */ - function init$h() { + function init$g() { /* Place parameters in static storage for common use -------------------------------------------------*/ @@ -5210,7 +5210,7 @@ var names$g = ["gnom"]; var gnom = { - init: init$h, + init: init$g, forward: forward$g, inverse: inverse$g, names: names$g @@ -5253,7 +5253,7 @@ A User's Manual" by Gerald I. Evenden, USGS Open File Report 90-284and Release 4 Interim Reports (2003) */ - function init$g() { + function init$f() { //no-op if (!this.sphere) { this.k0 = msfnz(this.e, Math.sin(this.lat_ts), Math.cos(this.lat_ts)); @@ -5307,13 +5307,13 @@ var names$f = ["cea"]; var cea = { - init: init$g, + init: init$f, forward: forward$f, inverse: inverse$f, names: names$f }; - function init$f() { + function init$e() { this.x0 = this.x0 || 0; this.y0 = this.y0 || 0; @@ -5353,7 +5353,7 @@ var names$e = ["Equirectangular", "Equidistant_Cylindrical", "eqc"]; var eqc = { - init: init$f, + init: init$e, forward: forward$e, inverse: inverse$e, names: names$e @@ -5361,7 +5361,7 @@ var MAX_ITER$1 = 20; - function init$e() { + function init$d() { /* Place parameters in static storage for common use -------------------------------------------------*/ this.temp = this.b / this.a; @@ -5479,13 +5479,13 @@ var names$d = ["Polyconic", "poly"]; var poly = { - init: init$e, + init: init$d, forward: forward$d, inverse: inverse$d, names: names$d }; - function init$d() { + function init$c() { this.A = []; this.A[1] = 0.6399175073; this.A[2] = -0.1358797613; @@ -5688,7 +5688,7 @@ var names$c = ["New_Zealand_Map_Grid", "nzmg"]; var nzmg = { - init: init$d, + init: init$c, forward: forward$c, inverse: inverse$c, names: names$c @@ -5703,7 +5703,7 @@ /* Initialize the Miller Cylindrical projection -------------------------------------------*/ - function init$c() { + function init$b() { //no-op } @@ -5739,7 +5739,7 @@ var names$b = ["Miller_Cylindrical", "mill"]; var mill = { - init: init$c, + init: init$b, forward: forward$b, inverse: inverse$b, names: names$b @@ -5748,7 +5748,7 @@ var MAX_ITER = 20; - function init$b() { + function init$a() { /* Place parameters in static storage for common use -------------------------------------------------*/ @@ -5847,13 +5847,13 @@ var names$a = ["Sinusoidal", "sinu"]; var sinu = { - init: init$b, + init: init$a, forward: forward$a, inverse: inverse$a, names: names$a }; - function init$a() {} + function init$9() {} /* Mollweide forward equations--mapping lat,long to x,y ----------------------------------------------------*/ function forward$9(p) { @@ -5929,13 +5929,13 @@ var names$9 = ["Mollweide", "moll"]; var moll = { - init: init$a, + init: init$9, forward: forward$9, inverse: inverse$9, names: names$9 }; - function init$9() { + function init$8() { /* Place parameters in static storage for common use -------------------------------------------------*/ @@ -6036,7 +6036,7 @@ var names$8 = ["Equidistant_Conic", "eqdc"]; var eqdc = { - init: init$9, + init: init$8, forward: forward$8, inverse: inverse$8, names: names$8 @@ -6044,7 +6044,7 @@ /* Initialize the Van Der Grinten projection ----------------------------------------*/ - function init$8() { + function init$7() { //this.R = 6370997; //Radius of earth this.R = this.a; } @@ -6160,13 +6160,13 @@ var names$7 = ["Van_der_Grinten_I", "VanDerGrinten", "vandg"]; var vandg = { - init: init$8, + init: init$7, forward: forward$7, inverse: inverse$7, names: names$7 }; - function init$7() { + function init$6() { this.sin_p12 = Math.sin(this.lat0); this.cos_p12 = Math.cos(this.lat0); } @@ -6355,13 +6355,13 @@ var names$6 = ["Azimuthal_Equidistant", "aeqd"]; var aeqd = { - init: init$7, + init: init$6, forward: forward$6, inverse: inverse$6, names: names$6 }; - function init$6() { + function init$5() { //double temp; /* temporary variable */ /* Place parameters in static storage for common use @@ -6443,7 +6443,7 @@ var names$5 = ["ortho"]; var ortho = { - init: init$6, + init: init$5, forward: forward$5, inverse: inverse$5, names: names$5 @@ -6470,7 +6470,7 @@ AREA_3: 4 }; - function init$5() { + function init$4() { this.x0 = this.x0 || 0; this.y0 = this.y0 || 0; @@ -6810,7 +6810,7 @@ var names$4 = ["Quadrilateralized Spherical Cube", "Quadrilateralized_Spherical_Cube", "qsc"]; var qsc = { - init: init$5, + init: init$4, forward: forward$4, inverse: inverse$4, names: names$4 @@ -6891,7 +6891,7 @@ return x; } - function init$4() { + function init$3() { this.x0 = this.x0 || 0; this.y0 = this.y0 || 0; this.long0 = this.long0 || 0; @@ -6970,13 +6970,13 @@ var names$3 = ["Robinson", "robin"]; var robin = { - init: init$4, + init: init$3, forward: forward$3, inverse: inverse$3, names: names$3 }; - function init$3() { + function init$2() { this.name = 'geocent'; } @@ -6993,7 +6993,7 @@ var names$2 = ["Geocentric", 'geocentric', "geocent", "Geocent"]; var geocent = { - init: init$3, + init: init$2, forward: forward$2, inverse: inverse$2, names: names$2 @@ -7014,7 +7014,7 @@ lat0: { def: 0, num: true } // default is Equator, conversion to rad is automatic }; - function init$2() { + function init$1() { Object.keys(params).forEach(function (p) { if (typeof this[p] === "undefined") { this[p] = params[p].def; @@ -7159,13 +7159,13 @@ var names$1 = ["Tilted_Perspective", "tpers"]; var tpers = { - init: init$2, + init: init$1, forward: forward$1, inverse: inverse$1, names: names$1 }; - function init$1() { + function init() { this.flip_axis = (this.sweep === 'x' ? 1 : 0); this.h = Number(this.h); this.radius_g_1 = this.h / this.a; @@ -7316,7 +7316,7 @@ var names = ["Geostationary Satellite View", "Geostationary_Satellite", "geos"]; var geos = { - init: init$1, + init: init, forward: forward, inverse: inverse, names: names, @@ -7366,2421 +7366,157 @@ proj4.version = '__VERSION__'; includedProjections(proj4); - var global$1 = (typeof global !== "undefined" ? global : - typeof self !== "undefined" ? self : - typeof window !== "undefined" ? window : {}); - - var lookup = []; - var revLookup = []; - var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array; - var inited = false; - function init () { - inited = true; - var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; - for (var i = 0, len = code.length; i < len; ++i) { - lookup[i] = code[i]; - revLookup[code.charCodeAt(i)] = i; - } - - revLookup['-'.charCodeAt(0)] = 62; - revLookup['_'.charCodeAt(0)] = 63; - } + var f,m="deflate-raw",x=self.DecompressionStream;try{new x(m),f=async t=>{let n=new x(m),e=n.writable.getWriter(),i=n.readable.getReader();e.write(t),e.close();let c,o=[],s=0,a=0,l;for(;!(l=await i.read()).done;)c=l.value,o.push(c),s+=c.length;return o.length-1?(c=new Uint8Array(s),o.map(r=>{c.set(r,a),a+=r.length;}),c):o[0]};}catch{}var _=new TextDecoder,h=t=>{throw new Error("but-unzip~"+t)},E=t=>_.decode(t),A=t=>{let n=t.length-20,e=Math.max(n-65516,2);for(;(n=t.lastIndexOf(80,n-1))!==-1&&!(t[n+1]===75&&t[n+2]===5&&t[n+3]===6)&&n>e;);return n};function*C(t,n=f){let e=A(t);e===-1&&h(2);let i=(r,d)=>t.subarray(e+=r,e+=d),c=new DataView(t.buffer,t.byteOffset),o=r=>c.getUint16(r+e,!0),s=r=>c.getUint32(r+e,!0),a=o(10);for(a!==o(8)&&h(3),e=s(16);a--;){let r=o(10),d=o(28),g=o(30),y=o(32),b=s(20),w=s(42),p=E(i(46,d)),D=E(i(g,y)),L=e,u;e=w,u=i(30+o(26)+o(28),b),yield {filename:p,comment:D,read:()=>r&8?n(u):r?h(1):u},e=L;}} - function toByteArray (b64) { - if (!inited) { - init(); + const regex$1 = /.+\.(shp|dbf|json|prj|cpg)$/i; + var unzip = async (buffer) => { + const files = {}; + const proms = []; + for (const entry of C(buffer)) { + if (!regex$1.test(entry.filename)) { + continue; + } + proms.push(Promise.resolve(entry.read()).then(bytes => files[entry.filename] = bytes)); } - var i, j, l, tmp, placeHolders, arr; - var len = b64.length; - - if (len % 4 > 0) { - throw new Error('Invalid string. Length must be a multiple of 4') + await Promise.all(proms); + const out = {}; + const decoder = new TextDecoder(); + for (const [key, value] of Object.entries(files)) { + if (key.slice(-3).toLowerCase() === 'shp' || key.slice(-3).toLowerCase() === 'dbf') { + out[key] = new DataView(value.buffer, value.byteOffset, value.byteLength); + } else { + out[key] = decoder.decode(value); + } } + return out; + }; - // the number of equal signs (place holders) - // if there are two placeholders, than the two characters before it - // represent one byte - // if there is only one, then the three characters before it represent 2 bytes - // this is just a cheap hack to not do indexOf twice - placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0; - - // base64 is 4/3 + up to two characters of the original data - arr = new Arr(len * 3 / 4 - placeHolders); - - // if there are placeholders, only get up to the last complete 4 chars - l = placeHolders > 0 ? len - 4 : len; - - var L = 0; - - for (i = 0, j = 0; i < l; i += 4, j += 3) { - tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]; - arr[L++] = (tmp >> 16) & 0xFF; - arr[L++] = (tmp >> 8) & 0xFF; - arr[L++] = tmp & 0xFF; - } + const URL$1 = globalThis.URL; - if (placeHolders === 2) { - tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4); - arr[L++] = tmp & 0xFF; - } else if (placeHolders === 1) { - tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2); - arr[L++] = (tmp >> 8) & 0xFF; - arr[L++] = tmp & 0xFF; + var combine$1 = (base, type) => { + if (!type) { + return base; } + const url = new URL$1(base); + url.pathname = `${url.pathname}.${type}`; + return url.href; + }; - return arr - } - - function tripletToBase64 (num) { - return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F] - } + async function binaryAjax(_url, type) { - function encodeChunk (uint8, start, end) { - var tmp; - var output = []; - for (var i = start; i < end; i += 3) { - tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]); - output.push(tripletToBase64(tmp)); + const url = combine$1(_url, type); + const isOptionalTxt = type === 'prj' || type === 'cpg'; + try { + const resp = await fetch(url); + if (resp.status > 399) { + throw new Error(resp.statusText); + } + if (isOptionalTxt) { + return resp.text(); + } + const parsed = await resp.arrayBuffer(); + return new DataView(parsed) + } catch (e) { + if (isOptionalTxt || type === 'dbf') { + return false; + } + throw e; } - return output.join('') } - function fromByteArray (uint8) { - if (!inited) { - init(); - } - var tmp; - var len = uint8.length; - var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes - var output = ''; - var parts = []; - var maxChunkLength = 16383; // must be multiple of 3 - - // go through the array every three bytes, we'll deal with trailing stuff later - for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { - parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength))); + function isClockWise(array) { + let sum = 0; + let i = 1; + const len = array.length; + let prev, cur; + const bbox = [array[0][0], array[0][1], array[0][0], array[0][1]]; + while (i < len) { + prev = cur || array[0]; + cur = array[i]; + sum += ((cur[0] - prev[0]) * (cur[1] + prev[1])); + i++; + if (cur[0] < bbox[0]) { + bbox[0] = cur[0]; + } + if (cur[1] < bbox[1]) { + bbox[1] = cur[1]; + } + if (cur[0] > bbox[2]) { + bbox[2] = cur[0]; + } + if (cur[1] > bbox[3]) { + bbox[3] = cur[1]; + } } - - // pad the end with zeros, but make sure to not forget the extra bytes - if (extraBytes === 1) { - tmp = uint8[len - 1]; - output += lookup[tmp >> 2]; - output += lookup[(tmp << 4) & 0x3F]; - output += '=='; - } else if (extraBytes === 2) { - tmp = (uint8[len - 2] << 8) + (uint8[len - 1]); - output += lookup[tmp >> 10]; - output += lookup[(tmp >> 4) & 0x3F]; - output += lookup[(tmp << 2) & 0x3F]; - output += '='; + return { + ring: array, + clockWise: sum > 0, + bbox, + children: [] } - parts.push(output); - - return parts.join('') } - function read (buffer, offset, isLE, mLen, nBytes) { - var e, m; - var eLen = nBytes * 8 - mLen - 1; - var eMax = (1 << eLen) - 1; - var eBias = eMax >> 1; - var nBits = -7; - var i = isLE ? (nBytes - 1) : 0; - var d = isLE ? -1 : 1; - var s = buffer[offset + i]; - - i += d; - - e = s & ((1 << (-nBits)) - 1); - s >>= (-nBits); - nBits += eLen; - for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} - - m = e & ((1 << (-nBits)) - 1); - e >>= (-nBits); - nBits += mLen; - for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} - - if (e === 0) { - e = 1 - eBias; - } else if (e === eMax) { - return m ? NaN : ((s ? -1 : 1) * Infinity) - } else { - m = m + Math.pow(2, mLen); - e = e - eBias; + function contains(outer, inner) { + if (outer.bbox[0] > inner.bbox[0]) { + return false; + } + if (outer.bbox[1] > inner.bbox[1]) { + return false; + } + if (outer.bbox[2] < inner.bbox[2]) { + return false; + } + if (outer.bbox[3] < inner.bbox[3]) { + return false; } - return (s ? -1 : 1) * m * Math.pow(2, e - mLen) + return true; } - function write (buffer, value, offset, isLE, mLen, nBytes) { - var e, m, c; - var eLen = nBytes * 8 - mLen - 1; - var eMax = (1 << eLen) - 1; - var eBias = eMax >> 1; - var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0); - var i = isLE ? 0 : (nBytes - 1); - var d = isLE ? 1 : -1; - var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0; - - value = Math.abs(value); - - if (isNaN(value) || value === Infinity) { - m = isNaN(value) ? 1 : 0; - e = eMax; - } else { - e = Math.floor(Math.log(value) / Math.LN2); - if (value * (c = Math.pow(2, -e)) < 1) { - e--; - c *= 2; - } - if (e + eBias >= 1) { - value += rt / c; + function handleRings(rings) { + const outers = []; + const inners = []; + for (const ring of rings) { + const proccessed = isClockWise(ring); + if (proccessed.clockWise) { + outers.push(proccessed); } else { - value += rt * Math.pow(2, 1 - eBias); - } - if (value * c >= 2) { - e++; - c /= 2; + inners.push(proccessed); } + } + // this is an optimization, + // but it would also put in weird bad rings that would otherwise get left out + // if (outers.length === 1) { + // const out = [outers[0].ring] + // for (const inner of inners) { + // out.push(inner.ring); - if (e + eBias >= eMax) { - m = 0; - e = eMax; - } else if (e + eBias >= 1) { - m = (value * c - 1) * Math.pow(2, mLen); - e = e + eBias; - } else { - m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); - e = 0; + // } + // return [out]; + // } + for (const inner of inners) { + for (const outer of outers) { + if (contains(outer, inner)) { + outer.children.push(inner.ring); + break; + } } } - - for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} - - e = (e << mLen) | m; - eLen += mLen; - for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} - - buffer[offset + i - d] |= s * 128; + const out = []; + for (const outer of outers) { + out.push([outer.ring].concat(outer.children)); + } + return out; } - - var toString = {}.toString; - - var isArray = Array.isArray || function (arr) { - return toString.call(arr) == '[object Array]'; - }; - - /*! - * The buffer module from node.js, for the browser. - * - * @author Feross Aboukhadijeh - * @license MIT - */ - - var INSPECT_MAX_BYTES = 50; - - /** - * If `Buffer.TYPED_ARRAY_SUPPORT`: - * === true Use Uint8Array implementation (fastest) - * === false Use Object implementation (most compatible, even IE6) - * - * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, - * Opera 11.6+, iOS 4.2+. - * - * Due to various browser bugs, sometimes the Object implementation will be used even - * when the browser supports typed arrays. - * - * Note: - * - * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, - * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. - * - * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. - * - * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of - * incorrect length in some situations. - - * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they - * get the Object implementation, which is slower but behaves correctly. - */ - Buffer.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined - ? global$1.TYPED_ARRAY_SUPPORT - : true; - - /* - * Export kMaxLength after typed array support is determined. - */ - kMaxLength(); - - function kMaxLength () { - return Buffer.TYPED_ARRAY_SUPPORT - ? 0x7fffffff - : 0x3fffffff - } - - function createBuffer (that, length) { - if (kMaxLength() < length) { - throw new RangeError('Invalid typed array length') - } - if (Buffer.TYPED_ARRAY_SUPPORT) { - // Return an augmented `Uint8Array` instance, for best performance - that = new Uint8Array(length); - that.__proto__ = Buffer.prototype; - } else { - // Fallback: Return an object instance of the Buffer class - if (that === null) { - that = new Buffer(length); - } - that.length = length; - } - - return that - } - - /** - * The Buffer constructor returns instances of `Uint8Array` that have their - * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of - * `Uint8Array`, so the returned instances will have all the node `Buffer` methods - * and the `Uint8Array` methods. Square bracket notation works as expected -- it - * returns a single octet. - * - * The `Uint8Array` prototype remains unmodified. - */ - - function Buffer (arg, encodingOrOffset, length) { - if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { - return new Buffer(arg, encodingOrOffset, length) - } - - // Common case. - if (typeof arg === 'number') { - if (typeof encodingOrOffset === 'string') { - throw new Error( - 'If encoding is specified then the first argument must be a string' - ) - } - return allocUnsafe(this, arg) - } - return from(this, arg, encodingOrOffset, length) - } - - Buffer.poolSize = 8192; // not used by this implementation - - // TODO: Legacy, not needed anymore. Remove in next major version. - Buffer._augment = function (arr) { - arr.__proto__ = Buffer.prototype; - return arr - }; - - function from (that, value, encodingOrOffset, length) { - if (typeof value === 'number') { - throw new TypeError('"value" argument must not be a number') - } - - if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { - return fromArrayBuffer(that, value, encodingOrOffset, length) - } - - if (typeof value === 'string') { - return fromString(that, value, encodingOrOffset) - } - - return fromObject(that, value) - } - - /** - * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError - * if value is a number. - * Buffer.from(str[, encoding]) - * Buffer.from(array) - * Buffer.from(buffer) - * Buffer.from(arrayBuffer[, byteOffset[, length]]) - **/ - Buffer.from = function (value, encodingOrOffset, length) { - return from(null, value, encodingOrOffset, length) - }; - - if (Buffer.TYPED_ARRAY_SUPPORT) { - Buffer.prototype.__proto__ = Uint8Array.prototype; - Buffer.__proto__ = Uint8Array; - } - - function assertSize (size) { - if (typeof size !== 'number') { - throw new TypeError('"size" argument must be a number') - } else if (size < 0) { - throw new RangeError('"size" argument must not be negative') - } - } - - function alloc (that, size, fill, encoding) { - assertSize(size); - if (size <= 0) { - return createBuffer(that, size) - } - if (fill !== undefined) { - // Only pay attention to encoding if it's a string. This - // prevents accidentally sending in a number that would - // be interpretted as a start offset. - return typeof encoding === 'string' - ? createBuffer(that, size).fill(fill, encoding) - : createBuffer(that, size).fill(fill) - } - return createBuffer(that, size) - } - - /** - * Creates a new filled Buffer instance. - * alloc(size[, fill[, encoding]]) - **/ - Buffer.alloc = function (size, fill, encoding) { - return alloc(null, size, fill, encoding) - }; - - function allocUnsafe (that, size) { - assertSize(size); - that = createBuffer(that, size < 0 ? 0 : checked(size) | 0); - if (!Buffer.TYPED_ARRAY_SUPPORT) { - for (var i = 0; i < size; ++i) { - that[i] = 0; - } - } - return that - } - - /** - * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. - * */ - Buffer.allocUnsafe = function (size) { - return allocUnsafe(null, size) - }; - /** - * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. - */ - Buffer.allocUnsafeSlow = function (size) { - return allocUnsafe(null, size) - }; - - function fromString (that, string, encoding) { - if (typeof encoding !== 'string' || encoding === '') { - encoding = 'utf8'; - } - - if (!Buffer.isEncoding(encoding)) { - throw new TypeError('"encoding" must be a valid string encoding') - } - - var length = byteLength(string, encoding) | 0; - that = createBuffer(that, length); - - var actual = that.write(string, encoding); - - if (actual !== length) { - // Writing a hex string, for example, that contains invalid characters will - // cause everything after the first invalid character to be ignored. (e.g. - // 'abxxcd' will be treated as 'ab') - that = that.slice(0, actual); - } - - return that - } - - function fromArrayLike (that, array) { - var length = array.length < 0 ? 0 : checked(array.length) | 0; - that = createBuffer(that, length); - for (var i = 0; i < length; i += 1) { - that[i] = array[i] & 255; - } - return that - } - - function fromArrayBuffer (that, array, byteOffset, length) { - array.byteLength; // this throws if `array` is not a valid ArrayBuffer - - if (byteOffset < 0 || array.byteLength < byteOffset) { - throw new RangeError('\'offset\' is out of bounds') - } - - if (array.byteLength < byteOffset + (length || 0)) { - throw new RangeError('\'length\' is out of bounds') - } - - if (byteOffset === undefined && length === undefined) { - array = new Uint8Array(array); - } else if (length === undefined) { - array = new Uint8Array(array, byteOffset); - } else { - array = new Uint8Array(array, byteOffset, length); - } - - if (Buffer.TYPED_ARRAY_SUPPORT) { - // Return an augmented `Uint8Array` instance, for best performance - that = array; - that.__proto__ = Buffer.prototype; - } else { - // Fallback: Return an object instance of the Buffer class - that = fromArrayLike(that, array); - } - return that - } - - function fromObject (that, obj) { - if (internalIsBuffer(obj)) { - var len = checked(obj.length) | 0; - that = createBuffer(that, len); - - if (that.length === 0) { - return that - } - - obj.copy(that, 0, 0, len); - return that - } - - if (obj) { - if ((typeof ArrayBuffer !== 'undefined' && - obj.buffer instanceof ArrayBuffer) || 'length' in obj) { - if (typeof obj.length !== 'number' || isnan(obj.length)) { - return createBuffer(that, 0) - } - return fromArrayLike(that, obj) - } - - if (obj.type === 'Buffer' && isArray(obj.data)) { - return fromArrayLike(that, obj.data) - } - } - - throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') - } - - function checked (length) { - // Note: cannot use `length < kMaxLength()` here because that fails when - // length is NaN (which is otherwise coerced to zero.) - if (length >= kMaxLength()) { - throw new RangeError('Attempt to allocate Buffer larger than maximum ' + - 'size: 0x' + kMaxLength().toString(16) + ' bytes') - } - return length | 0 - } - Buffer.isBuffer = isBuffer; - function internalIsBuffer (b) { - return !!(b != null && b._isBuffer) - } - - Buffer.compare = function compare (a, b) { - if (!internalIsBuffer(a) || !internalIsBuffer(b)) { - throw new TypeError('Arguments must be Buffers') - } - - if (a === b) return 0 - - var x = a.length; - var y = b.length; - - for (var i = 0, len = Math.min(x, y); i < len; ++i) { - if (a[i] !== b[i]) { - x = a[i]; - y = b[i]; - break - } - } - - if (x < y) return -1 - if (y < x) return 1 - return 0 - }; - - Buffer.isEncoding = function isEncoding (encoding) { - switch (String(encoding).toLowerCase()) { - case 'hex': - case 'utf8': - case 'utf-8': - case 'ascii': - case 'latin1': - case 'binary': - case 'base64': - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return true - default: - return false - } - }; - - Buffer.concat = function concat (list, length) { - if (!isArray(list)) { - throw new TypeError('"list" argument must be an Array of Buffers') - } - - if (list.length === 0) { - return Buffer.alloc(0) - } - - var i; - if (length === undefined) { - length = 0; - for (i = 0; i < list.length; ++i) { - length += list[i].length; - } - } - - var buffer = Buffer.allocUnsafe(length); - var pos = 0; - for (i = 0; i < list.length; ++i) { - var buf = list[i]; - if (!internalIsBuffer(buf)) { - throw new TypeError('"list" argument must be an Array of Buffers') - } - buf.copy(buffer, pos); - pos += buf.length; - } - return buffer - }; - - function byteLength (string, encoding) { - if (internalIsBuffer(string)) { - return string.length - } - if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' && - (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) { - return string.byteLength - } - if (typeof string !== 'string') { - string = '' + string; - } - - var len = string.length; - if (len === 0) return 0 - - // Use a for loop to avoid recursion - var loweredCase = false; - for (;;) { - switch (encoding) { - case 'ascii': - case 'latin1': - case 'binary': - return len - case 'utf8': - case 'utf-8': - case undefined: - return utf8ToBytes(string).length - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return len * 2 - case 'hex': - return len >>> 1 - case 'base64': - return base64ToBytes(string).length - default: - if (loweredCase) return utf8ToBytes(string).length // assume utf8 - encoding = ('' + encoding).toLowerCase(); - loweredCase = true; - } - } - } - Buffer.byteLength = byteLength; - - function slowToString (encoding, start, end) { - var loweredCase = false; - - // No need to verify that "this.length <= MAX_UINT32" since it's a read-only - // property of a typed array. - - // This behaves neither like String nor Uint8Array in that we set start/end - // to their upper/lower bounds if the value passed is out of range. - // undefined is handled specially as per ECMA-262 6th Edition, - // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. - if (start === undefined || start < 0) { - start = 0; - } - // Return early if start > this.length. Done here to prevent potential uint32 - // coercion fail below. - if (start > this.length) { - return '' - } - - if (end === undefined || end > this.length) { - end = this.length; - } - - if (end <= 0) { - return '' - } - - // Force coersion to uint32. This will also coerce falsey/NaN values to 0. - end >>>= 0; - start >>>= 0; - - if (end <= start) { - return '' - } - - if (!encoding) encoding = 'utf8'; - - while (true) { - switch (encoding) { - case 'hex': - return hexSlice(this, start, end) - - case 'utf8': - case 'utf-8': - return utf8Slice(this, start, end) - - case 'ascii': - return asciiSlice(this, start, end) - - case 'latin1': - case 'binary': - return latin1Slice(this, start, end) - - case 'base64': - return base64Slice(this, start, end) - - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return utf16leSlice(this, start, end) - - default: - if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) - encoding = (encoding + '').toLowerCase(); - loweredCase = true; - } - } - } - - // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect - // Buffer instances. - Buffer.prototype._isBuffer = true; - - function swap (b, n, m) { - var i = b[n]; - b[n] = b[m]; - b[m] = i; - } - - Buffer.prototype.swap16 = function swap16 () { - var len = this.length; - if (len % 2 !== 0) { - throw new RangeError('Buffer size must be a multiple of 16-bits') - } - for (var i = 0; i < len; i += 2) { - swap(this, i, i + 1); - } - return this - }; - - Buffer.prototype.swap32 = function swap32 () { - var len = this.length; - if (len % 4 !== 0) { - throw new RangeError('Buffer size must be a multiple of 32-bits') - } - for (var i = 0; i < len; i += 4) { - swap(this, i, i + 3); - swap(this, i + 1, i + 2); - } - return this - }; - - Buffer.prototype.swap64 = function swap64 () { - var len = this.length; - if (len % 8 !== 0) { - throw new RangeError('Buffer size must be a multiple of 64-bits') - } - for (var i = 0; i < len; i += 8) { - swap(this, i, i + 7); - swap(this, i + 1, i + 6); - swap(this, i + 2, i + 5); - swap(this, i + 3, i + 4); - } - return this - }; - - Buffer.prototype.toString = function toString () { - var length = this.length | 0; - if (length === 0) return '' - if (arguments.length === 0) return utf8Slice(this, 0, length) - return slowToString.apply(this, arguments) - }; - - Buffer.prototype.equals = function equals (b) { - if (!internalIsBuffer(b)) throw new TypeError('Argument must be a Buffer') - if (this === b) return true - return Buffer.compare(this, b) === 0 - }; - - Buffer.prototype.inspect = function inspect () { - var str = ''; - var max = INSPECT_MAX_BYTES; - if (this.length > 0) { - str = this.toString('hex', 0, max).match(/.{2}/g).join(' '); - if (this.length > max) str += ' ... '; - } - return '' - }; - - Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { - if (!internalIsBuffer(target)) { - throw new TypeError('Argument must be a Buffer') - } - - if (start === undefined) { - start = 0; - } - if (end === undefined) { - end = target ? target.length : 0; - } - if (thisStart === undefined) { - thisStart = 0; - } - if (thisEnd === undefined) { - thisEnd = this.length; - } - - if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { - throw new RangeError('out of range index') - } - - if (thisStart >= thisEnd && start >= end) { - return 0 - } - if (thisStart >= thisEnd) { - return -1 - } - if (start >= end) { - return 1 - } - - start >>>= 0; - end >>>= 0; - thisStart >>>= 0; - thisEnd >>>= 0; - - if (this === target) return 0 - - var x = thisEnd - thisStart; - var y = end - start; - var len = Math.min(x, y); - - var thisCopy = this.slice(thisStart, thisEnd); - var targetCopy = target.slice(start, end); - - for (var i = 0; i < len; ++i) { - if (thisCopy[i] !== targetCopy[i]) { - x = thisCopy[i]; - y = targetCopy[i]; - break - } - } - - if (x < y) return -1 - if (y < x) return 1 - return 0 - }; - - // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, - // OR the last index of `val` in `buffer` at offset <= `byteOffset`. - // - // Arguments: - // - buffer - a Buffer to search - // - val - a string, Buffer, or number - // - byteOffset - an index into `buffer`; will be clamped to an int32 - // - encoding - an optional encoding, relevant is val is a string - // - dir - true for indexOf, false for lastIndexOf - function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { - // Empty buffer means no match - if (buffer.length === 0) return -1 - - // Normalize byteOffset - if (typeof byteOffset === 'string') { - encoding = byteOffset; - byteOffset = 0; - } else if (byteOffset > 0x7fffffff) { - byteOffset = 0x7fffffff; - } else if (byteOffset < -0x80000000) { - byteOffset = -0x80000000; - } - byteOffset = +byteOffset; // Coerce to Number. - if (isNaN(byteOffset)) { - // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer - byteOffset = dir ? 0 : (buffer.length - 1); - } - - // Normalize byteOffset: negative offsets start from the end of the buffer - if (byteOffset < 0) byteOffset = buffer.length + byteOffset; - if (byteOffset >= buffer.length) { - if (dir) return -1 - else byteOffset = buffer.length - 1; - } else if (byteOffset < 0) { - if (dir) byteOffset = 0; - else return -1 - } - - // Normalize val - if (typeof val === 'string') { - val = Buffer.from(val, encoding); - } - - // Finally, search either indexOf (if dir is true) or lastIndexOf - if (internalIsBuffer(val)) { - // Special case: looking for empty string/buffer always fails - if (val.length === 0) { - return -1 - } - return arrayIndexOf(buffer, val, byteOffset, encoding, dir) - } else if (typeof val === 'number') { - val = val & 0xFF; // Search for a byte value [0-255] - if (Buffer.TYPED_ARRAY_SUPPORT && - typeof Uint8Array.prototype.indexOf === 'function') { - if (dir) { - return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) - } else { - return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) - } - } - return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir) - } - - throw new TypeError('val must be string, number or Buffer') - } - - function arrayIndexOf (arr, val, byteOffset, encoding, dir) { - var indexSize = 1; - var arrLength = arr.length; - var valLength = val.length; - - if (encoding !== undefined) { - encoding = String(encoding).toLowerCase(); - if (encoding === 'ucs2' || encoding === 'ucs-2' || - encoding === 'utf16le' || encoding === 'utf-16le') { - if (arr.length < 2 || val.length < 2) { - return -1 - } - indexSize = 2; - arrLength /= 2; - valLength /= 2; - byteOffset /= 2; - } - } - - function read (buf, i) { - if (indexSize === 1) { - return buf[i] - } else { - return buf.readUInt16BE(i * indexSize) - } - } - - var i; - if (dir) { - var foundIndex = -1; - for (i = byteOffset; i < arrLength; i++) { - if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { - if (foundIndex === -1) foundIndex = i; - if (i - foundIndex + 1 === valLength) return foundIndex * indexSize - } else { - if (foundIndex !== -1) i -= i - foundIndex; - foundIndex = -1; - } - } - } else { - if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength; - for (i = byteOffset; i >= 0; i--) { - var found = true; - for (var j = 0; j < valLength; j++) { - if (read(arr, i + j) !== read(val, j)) { - found = false; - break - } - } - if (found) return i - } - } - - return -1 - } - - Buffer.prototype.includes = function includes (val, byteOffset, encoding) { - return this.indexOf(val, byteOffset, encoding) !== -1 - }; - - Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) { - return bidirectionalIndexOf(this, val, byteOffset, encoding, true) - }; - - Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) { - return bidirectionalIndexOf(this, val, byteOffset, encoding, false) - }; - - function hexWrite (buf, string, offset, length) { - offset = Number(offset) || 0; - var remaining = buf.length - offset; - if (!length) { - length = remaining; - } else { - length = Number(length); - if (length > remaining) { - length = remaining; - } - } - - // must be an even number of digits - var strLen = string.length; - if (strLen % 2 !== 0) throw new TypeError('Invalid hex string') - - if (length > strLen / 2) { - length = strLen / 2; - } - for (var i = 0; i < length; ++i) { - var parsed = parseInt(string.substr(i * 2, 2), 16); - if (isNaN(parsed)) return i - buf[offset + i] = parsed; - } - return i - } - - function utf8Write (buf, string, offset, length) { - return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) - } - - function asciiWrite (buf, string, offset, length) { - return blitBuffer(asciiToBytes(string), buf, offset, length) - } - - function latin1Write (buf, string, offset, length) { - return asciiWrite(buf, string, offset, length) - } - - function base64Write (buf, string, offset, length) { - return blitBuffer(base64ToBytes(string), buf, offset, length) - } - - function ucs2Write (buf, string, offset, length) { - return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) - } - - Buffer.prototype.write = function write (string, offset, length, encoding) { - // Buffer#write(string) - if (offset === undefined) { - encoding = 'utf8'; - length = this.length; - offset = 0; - // Buffer#write(string, encoding) - } else if (length === undefined && typeof offset === 'string') { - encoding = offset; - length = this.length; - offset = 0; - // Buffer#write(string, offset[, length][, encoding]) - } else if (isFinite(offset)) { - offset = offset | 0; - if (isFinite(length)) { - length = length | 0; - if (encoding === undefined) encoding = 'utf8'; - } else { - encoding = length; - length = undefined; - } - // legacy write(string, encoding, offset, length) - remove in v0.13 - } else { - throw new Error( - 'Buffer.write(string, encoding, offset[, length]) is no longer supported' - ) - } - - var remaining = this.length - offset; - if (length === undefined || length > remaining) length = remaining; - - if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { - throw new RangeError('Attempt to write outside buffer bounds') - } - - if (!encoding) encoding = 'utf8'; - - var loweredCase = false; - for (;;) { - switch (encoding) { - case 'hex': - return hexWrite(this, string, offset, length) - - case 'utf8': - case 'utf-8': - return utf8Write(this, string, offset, length) - - case 'ascii': - return asciiWrite(this, string, offset, length) - - case 'latin1': - case 'binary': - return latin1Write(this, string, offset, length) - - case 'base64': - // Warning: maxLength not taken into account in base64Write - return base64Write(this, string, offset, length) - - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return ucs2Write(this, string, offset, length) - - default: - if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) - encoding = ('' + encoding).toLowerCase(); - loweredCase = true; - } - } - }; - - Buffer.prototype.toJSON = function toJSON () { - return { - type: 'Buffer', - data: Array.prototype.slice.call(this._arr || this, 0) - } - }; - - function base64Slice (buf, start, end) { - if (start === 0 && end === buf.length) { - return fromByteArray(buf) - } else { - return fromByteArray(buf.slice(start, end)) - } - } - - function utf8Slice (buf, start, end) { - end = Math.min(buf.length, end); - var res = []; - - var i = start; - while (i < end) { - var firstByte = buf[i]; - var codePoint = null; - var bytesPerSequence = (firstByte > 0xEF) ? 4 - : (firstByte > 0xDF) ? 3 - : (firstByte > 0xBF) ? 2 - : 1; - - if (i + bytesPerSequence <= end) { - var secondByte, thirdByte, fourthByte, tempCodePoint; - - switch (bytesPerSequence) { - case 1: - if (firstByte < 0x80) { - codePoint = firstByte; - } - break - case 2: - secondByte = buf[i + 1]; - if ((secondByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F); - if (tempCodePoint > 0x7F) { - codePoint = tempCodePoint; - } - } - break - case 3: - secondByte = buf[i + 1]; - thirdByte = buf[i + 2]; - if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F); - if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { - codePoint = tempCodePoint; - } - } - break - case 4: - secondByte = buf[i + 1]; - thirdByte = buf[i + 2]; - fourthByte = buf[i + 3]; - if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F); - if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { - codePoint = tempCodePoint; - } - } - } - } - - if (codePoint === null) { - // we did not generate a valid codePoint so insert a - // replacement char (U+FFFD) and advance only 1 byte - codePoint = 0xFFFD; - bytesPerSequence = 1; - } else if (codePoint > 0xFFFF) { - // encode to utf16 (surrogate pair dance) - codePoint -= 0x10000; - res.push(codePoint >>> 10 & 0x3FF | 0xD800); - codePoint = 0xDC00 | codePoint & 0x3FF; - } - - res.push(codePoint); - i += bytesPerSequence; - } - - return decodeCodePointsArray(res) - } - - // Based on http://stackoverflow.com/a/22747272/680742, the browser with - // the lowest limit is Chrome, with 0x10000 args. - // We go 1 magnitude less, for safety - var MAX_ARGUMENTS_LENGTH = 0x1000; - - function decodeCodePointsArray (codePoints) { - var len = codePoints.length; - if (len <= MAX_ARGUMENTS_LENGTH) { - return String.fromCharCode.apply(String, codePoints) // avoid extra slice() - } - - // Decode in chunks to avoid "call stack size exceeded". - var res = ''; - var i = 0; - while (i < len) { - res += String.fromCharCode.apply( - String, - codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) - ); - } - return res - } - - function asciiSlice (buf, start, end) { - var ret = ''; - end = Math.min(buf.length, end); - - for (var i = start; i < end; ++i) { - ret += String.fromCharCode(buf[i] & 0x7F); - } - return ret - } - - function latin1Slice (buf, start, end) { - var ret = ''; - end = Math.min(buf.length, end); - - for (var i = start; i < end; ++i) { - ret += String.fromCharCode(buf[i]); - } - return ret - } - - function hexSlice (buf, start, end) { - var len = buf.length; - - if (!start || start < 0) start = 0; - if (!end || end < 0 || end > len) end = len; - - var out = ''; - for (var i = start; i < end; ++i) { - out += toHex(buf[i]); - } - return out - } - - function utf16leSlice (buf, start, end) { - var bytes = buf.slice(start, end); - var res = ''; - for (var i = 0; i < bytes.length; i += 2) { - res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256); - } - return res - } - - Buffer.prototype.slice = function slice (start, end) { - var len = this.length; - start = ~~start; - end = end === undefined ? len : ~~end; - - if (start < 0) { - start += len; - if (start < 0) start = 0; - } else if (start > len) { - start = len; - } - - if (end < 0) { - end += len; - if (end < 0) end = 0; - } else if (end > len) { - end = len; - } - - if (end < start) end = start; - - var newBuf; - if (Buffer.TYPED_ARRAY_SUPPORT) { - newBuf = this.subarray(start, end); - newBuf.__proto__ = Buffer.prototype; - } else { - var sliceLen = end - start; - newBuf = new Buffer(sliceLen, undefined); - for (var i = 0; i < sliceLen; ++i) { - newBuf[i] = this[i + start]; - } - } - - return newBuf - }; - - /* - * Need to make sure that buffer isn't trying to write out of bounds. - */ - function checkOffset (offset, ext, length) { - if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') - if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') - } - - Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { - offset = offset | 0; - byteLength = byteLength | 0; - if (!noAssert) checkOffset(offset, byteLength, this.length); - - var val = this[offset]; - var mul = 1; - var i = 0; - while (++i < byteLength && (mul *= 0x100)) { - val += this[offset + i] * mul; - } - - return val - }; - - Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { - offset = offset | 0; - byteLength = byteLength | 0; - if (!noAssert) { - checkOffset(offset, byteLength, this.length); - } - - var val = this[offset + --byteLength]; - var mul = 1; - while (byteLength > 0 && (mul *= 0x100)) { - val += this[offset + --byteLength] * mul; - } - - return val - }; - - Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { - if (!noAssert) checkOffset(offset, 1, this.length); - return this[offset] - }; - - Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length); - return this[offset] | (this[offset + 1] << 8) - }; - - Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length); - return (this[offset] << 8) | this[offset + 1] - }; - - Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length); - - return ((this[offset]) | - (this[offset + 1] << 8) | - (this[offset + 2] << 16)) + - (this[offset + 3] * 0x1000000) - }; - - Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length); - - return (this[offset] * 0x1000000) + - ((this[offset + 1] << 16) | - (this[offset + 2] << 8) | - this[offset + 3]) - }; - - Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { - offset = offset | 0; - byteLength = byteLength | 0; - if (!noAssert) checkOffset(offset, byteLength, this.length); - - var val = this[offset]; - var mul = 1; - var i = 0; - while (++i < byteLength && (mul *= 0x100)) { - val += this[offset + i] * mul; - } - mul *= 0x80; - - if (val >= mul) val -= Math.pow(2, 8 * byteLength); - - return val - }; - - Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { - offset = offset | 0; - byteLength = byteLength | 0; - if (!noAssert) checkOffset(offset, byteLength, this.length); - - var i = byteLength; - var mul = 1; - var val = this[offset + --i]; - while (i > 0 && (mul *= 0x100)) { - val += this[offset + --i] * mul; - } - mul *= 0x80; - - if (val >= mul) val -= Math.pow(2, 8 * byteLength); - - return val - }; - - Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { - if (!noAssert) checkOffset(offset, 1, this.length); - if (!(this[offset] & 0x80)) return (this[offset]) - return ((0xff - this[offset] + 1) * -1) - }; - - Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length); - var val = this[offset] | (this[offset + 1] << 8); - return (val & 0x8000) ? val | 0xFFFF0000 : val - }; - - Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length); - var val = this[offset + 1] | (this[offset] << 8); - return (val & 0x8000) ? val | 0xFFFF0000 : val - }; - - Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length); - - return (this[offset]) | - (this[offset + 1] << 8) | - (this[offset + 2] << 16) | - (this[offset + 3] << 24) - }; - - Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length); - - return (this[offset] << 24) | - (this[offset + 1] << 16) | - (this[offset + 2] << 8) | - (this[offset + 3]) - }; - - Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length); - return read(this, offset, true, 23, 4) - }; - - Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length); - return read(this, offset, false, 23, 4) - }; - - Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 8, this.length); - return read(this, offset, true, 52, 8) - }; - - Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 8, this.length); - return read(this, offset, false, 52, 8) - }; - - function checkInt (buf, value, offset, ext, max, min) { - if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance') - if (value > max || value < min) throw new RangeError('"value" argument is out of bounds') - if (offset + ext > buf.length) throw new RangeError('Index out of range') - } - - Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { - value = +value; - offset = offset | 0; - byteLength = byteLength | 0; - if (!noAssert) { - var maxBytes = Math.pow(2, 8 * byteLength) - 1; - checkInt(this, value, offset, byteLength, maxBytes, 0); - } - - var mul = 1; - var i = 0; - this[offset] = value & 0xFF; - while (++i < byteLength && (mul *= 0x100)) { - this[offset + i] = (value / mul) & 0xFF; - } - - return offset + byteLength - }; - - Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { - value = +value; - offset = offset | 0; - byteLength = byteLength | 0; - if (!noAssert) { - var maxBytes = Math.pow(2, 8 * byteLength) - 1; - checkInt(this, value, offset, byteLength, maxBytes, 0); - } - - var i = byteLength - 1; - var mul = 1; - this[offset + i] = value & 0xFF; - while (--i >= 0 && (mul *= 0x100)) { - this[offset + i] = (value / mul) & 0xFF; - } - - return offset + byteLength - }; - - Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0); - if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value); - this[offset] = (value & 0xff); - return offset + 1 - }; - - function objectWriteUInt16 (buf, value, offset, littleEndian) { - if (value < 0) value = 0xffff + value + 1; - for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) { - buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> - (littleEndian ? i : 1 - i) * 8; - } - } - - Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0); - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff); - this[offset + 1] = (value >>> 8); - } else { - objectWriteUInt16(this, value, offset, true); - } - return offset + 2 - }; - - Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0); - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 8); - this[offset + 1] = (value & 0xff); - } else { - objectWriteUInt16(this, value, offset, false); - } - return offset + 2 - }; - - function objectWriteUInt32 (buf, value, offset, littleEndian) { - if (value < 0) value = 0xffffffff + value + 1; - for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) { - buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff; - } - } - - Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0); - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset + 3] = (value >>> 24); - this[offset + 2] = (value >>> 16); - this[offset + 1] = (value >>> 8); - this[offset] = (value & 0xff); - } else { - objectWriteUInt32(this, value, offset, true); - } - return offset + 4 - }; - - Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0); - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 24); - this[offset + 1] = (value >>> 16); - this[offset + 2] = (value >>> 8); - this[offset + 3] = (value & 0xff); - } else { - objectWriteUInt32(this, value, offset, false); - } - return offset + 4 - }; - - Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1); - - checkInt(this, value, offset, byteLength, limit - 1, -limit); - } - - var i = 0; - var mul = 1; - var sub = 0; - this[offset] = value & 0xFF; - while (++i < byteLength && (mul *= 0x100)) { - if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { - sub = 1; - } - this[offset + i] = ((value / mul) >> 0) - sub & 0xFF; - } - - return offset + byteLength - }; - - Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1); - - checkInt(this, value, offset, byteLength, limit - 1, -limit); - } - - var i = byteLength - 1; - var mul = 1; - var sub = 0; - this[offset + i] = value & 0xFF; - while (--i >= 0 && (mul *= 0x100)) { - if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { - sub = 1; - } - this[offset + i] = ((value / mul) >> 0) - sub & 0xFF; - } - - return offset + byteLength - }; - - Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80); - if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value); - if (value < 0) value = 0xff + value + 1; - this[offset] = (value & 0xff); - return offset + 1 - }; - - Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000); - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff); - this[offset + 1] = (value >>> 8); - } else { - objectWriteUInt16(this, value, offset, true); - } - return offset + 2 - }; - - Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000); - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 8); - this[offset + 1] = (value & 0xff); - } else { - objectWriteUInt16(this, value, offset, false); - } - return offset + 2 - }; - - Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000); - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff); - this[offset + 1] = (value >>> 8); - this[offset + 2] = (value >>> 16); - this[offset + 3] = (value >>> 24); - } else { - objectWriteUInt32(this, value, offset, true); - } - return offset + 4 - }; - - Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000); - if (value < 0) value = 0xffffffff + value + 1; - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 24); - this[offset + 1] = (value >>> 16); - this[offset + 2] = (value >>> 8); - this[offset + 3] = (value & 0xff); - } else { - objectWriteUInt32(this, value, offset, false); - } - return offset + 4 - }; - - function checkIEEE754 (buf, value, offset, ext, max, min) { - if (offset + ext > buf.length) throw new RangeError('Index out of range') - if (offset < 0) throw new RangeError('Index out of range') - } - - function writeFloat (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - checkIEEE754(buf, value, offset, 4); - } - write(buf, value, offset, littleEndian, 23, 4); - return offset + 4 - } - - Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { - return writeFloat(this, value, offset, true, noAssert) - }; - - Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { - return writeFloat(this, value, offset, false, noAssert) - }; - - function writeDouble (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - checkIEEE754(buf, value, offset, 8); - } - write(buf, value, offset, littleEndian, 52, 8); - return offset + 8 - } - - Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { - return writeDouble(this, value, offset, true, noAssert) - }; - - Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { - return writeDouble(this, value, offset, false, noAssert) - }; - - // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) - Buffer.prototype.copy = function copy (target, targetStart, start, end) { - if (!start) start = 0; - if (!end && end !== 0) end = this.length; - if (targetStart >= target.length) targetStart = target.length; - if (!targetStart) targetStart = 0; - if (end > 0 && end < start) end = start; - - // Copy 0 bytes; we're done - if (end === start) return 0 - if (target.length === 0 || this.length === 0) return 0 - - // Fatal error conditions - if (targetStart < 0) { - throw new RangeError('targetStart out of bounds') - } - if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') - if (end < 0) throw new RangeError('sourceEnd out of bounds') - - // Are we oob? - if (end > this.length) end = this.length; - if (target.length - targetStart < end - start) { - end = target.length - targetStart + start; - } - - var len = end - start; - var i; - - if (this === target && start < targetStart && targetStart < end) { - // descending copy from end - for (i = len - 1; i >= 0; --i) { - target[i + targetStart] = this[i + start]; - } - } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { - // ascending copy from start - for (i = 0; i < len; ++i) { - target[i + targetStart] = this[i + start]; - } - } else { - Uint8Array.prototype.set.call( - target, - this.subarray(start, start + len), - targetStart - ); - } - - return len - }; - - // Usage: - // buffer.fill(number[, offset[, end]]) - // buffer.fill(buffer[, offset[, end]]) - // buffer.fill(string[, offset[, end]][, encoding]) - Buffer.prototype.fill = function fill (val, start, end, encoding) { - // Handle string cases: - if (typeof val === 'string') { - if (typeof start === 'string') { - encoding = start; - start = 0; - end = this.length; - } else if (typeof end === 'string') { - encoding = end; - end = this.length; - } - if (val.length === 1) { - var code = val.charCodeAt(0); - if (code < 256) { - val = code; - } - } - if (encoding !== undefined && typeof encoding !== 'string') { - throw new TypeError('encoding must be a string') - } - if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { - throw new TypeError('Unknown encoding: ' + encoding) - } - } else if (typeof val === 'number') { - val = val & 255; - } - - // Invalid ranges are not set to a default, so can range check early. - if (start < 0 || this.length < start || this.length < end) { - throw new RangeError('Out of range index') - } - - if (end <= start) { - return this - } - - start = start >>> 0; - end = end === undefined ? this.length : end >>> 0; - - if (!val) val = 0; - - var i; - if (typeof val === 'number') { - for (i = start; i < end; ++i) { - this[i] = val; - } - } else { - var bytes = internalIsBuffer(val) - ? val - : utf8ToBytes(new Buffer(val, encoding).toString()); - var len = bytes.length; - for (i = 0; i < end - start; ++i) { - this[i + start] = bytes[i % len]; - } - } - - return this - }; - - // HELPER FUNCTIONS - // ================ - - var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g; - - function base64clean (str) { - // Node strips out invalid characters like \n and \t from the string, base64-js does not - str = stringtrim(str).replace(INVALID_BASE64_RE, ''); - // Node converts strings with length < 2 to '' - if (str.length < 2) return '' - // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not - while (str.length % 4 !== 0) { - str = str + '='; - } - return str - } - - function stringtrim (str) { - if (str.trim) return str.trim() - return str.replace(/^\s+|\s+$/g, '') - } - - function toHex (n) { - if (n < 16) return '0' + n.toString(16) - return n.toString(16) - } - - function utf8ToBytes (string, units) { - units = units || Infinity; - var codePoint; - var length = string.length; - var leadSurrogate = null; - var bytes = []; - - for (var i = 0; i < length; ++i) { - codePoint = string.charCodeAt(i); - - // is surrogate component - if (codePoint > 0xD7FF && codePoint < 0xE000) { - // last char was a lead - if (!leadSurrogate) { - // no lead yet - if (codePoint > 0xDBFF) { - // unexpected trail - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); - continue - } else if (i + 1 === length) { - // unpaired lead - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); - continue - } - - // valid lead - leadSurrogate = codePoint; - - continue - } - - // 2 leads in a row - if (codePoint < 0xDC00) { - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); - leadSurrogate = codePoint; - continue - } - - // valid surrogate pair - codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000; - } else if (leadSurrogate) { - // valid bmp char, but last char was a lead - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); - } - - leadSurrogate = null; - - // encode utf8 - if (codePoint < 0x80) { - if ((units -= 1) < 0) break - bytes.push(codePoint); - } else if (codePoint < 0x800) { - if ((units -= 2) < 0) break - bytes.push( - codePoint >> 0x6 | 0xC0, - codePoint & 0x3F | 0x80 - ); - } else if (codePoint < 0x10000) { - if ((units -= 3) < 0) break - bytes.push( - codePoint >> 0xC | 0xE0, - codePoint >> 0x6 & 0x3F | 0x80, - codePoint & 0x3F | 0x80 - ); - } else if (codePoint < 0x110000) { - if ((units -= 4) < 0) break - bytes.push( - codePoint >> 0x12 | 0xF0, - codePoint >> 0xC & 0x3F | 0x80, - codePoint >> 0x6 & 0x3F | 0x80, - codePoint & 0x3F | 0x80 - ); - } else { - throw new Error('Invalid code point') - } - } - - return bytes - } - - function asciiToBytes (str) { - var byteArray = []; - for (var i = 0; i < str.length; ++i) { - // Node's code seems to be doing this and not & 0x7F.. - byteArray.push(str.charCodeAt(i) & 0xFF); - } - return byteArray - } - - function utf16leToBytes (str, units) { - var c, hi, lo; - var byteArray = []; - for (var i = 0; i < str.length; ++i) { - if ((units -= 2) < 0) break - - c = str.charCodeAt(i); - hi = c >> 8; - lo = c % 256; - byteArray.push(lo); - byteArray.push(hi); - } - - return byteArray - } - - - function base64ToBytes (str) { - return toByteArray(base64clean(str)) - } - - function blitBuffer (src, dst, offset, length) { - for (var i = 0; i < length; ++i) { - if ((i + offset >= dst.length) || (i >= src.length)) break - dst[i + offset] = src[i]; - } - return i - } - - function isnan (val) { - return val !== val // eslint-disable-line no-self-compare - } - - - // the following is from is-buffer, also by Feross Aboukhadijeh and with same lisence - // The _isBuffer check is for Safari 5-7 support, because it's missing - // Object.prototype.constructor. Remove this eventually - function isBuffer(obj) { - return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj)) - } - - function isFastBuffer (obj) { - return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj) - } - - // For Node v0.10 support. Remove this eventually. - function isSlowBuffer (obj) { - return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isFastBuffer(obj.slice(0, 0)) - } - - // shim for using process in browser - // based off https://github.com/defunctzombie/node-process/blob/master/browser.js - - function defaultSetTimout() { - throw new Error('setTimeout has not been defined'); - } - function defaultClearTimeout () { - throw new Error('clearTimeout has not been defined'); - } - var cachedSetTimeout = defaultSetTimout; - var cachedClearTimeout = defaultClearTimeout; - if (typeof global$1.setTimeout === 'function') { - cachedSetTimeout = setTimeout; - } - if (typeof global$1.clearTimeout === 'function') { - cachedClearTimeout = clearTimeout; - } - - function runTimeout(fun) { - if (cachedSetTimeout === setTimeout) { - //normal enviroments in sane situations - return setTimeout(fun, 0); - } - // if setTimeout wasn't available but was latter defined - if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { - cachedSetTimeout = setTimeout; - return setTimeout(fun, 0); - } - try { - // when when somebody has screwed with setTimeout but no I.E. maddness - return cachedSetTimeout(fun, 0); - } catch(e){ - try { - // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally - return cachedSetTimeout.call(null, fun, 0); - } catch(e){ - // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error - return cachedSetTimeout.call(this, fun, 0); - } - } - - - } - function runClearTimeout(marker) { - if (cachedClearTimeout === clearTimeout) { - //normal enviroments in sane situations - return clearTimeout(marker); - } - // if clearTimeout wasn't available but was latter defined - if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { - cachedClearTimeout = clearTimeout; - return clearTimeout(marker); - } - try { - // when when somebody has screwed with setTimeout but no I.E. maddness - return cachedClearTimeout(marker); - } catch (e){ - try { - // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally - return cachedClearTimeout.call(null, marker); - } catch (e){ - // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. - // Some versions of I.E. have different rules for clearTimeout vs setTimeout - return cachedClearTimeout.call(this, marker); - } - } - - - - } - var queue = []; - var draining = false; - var currentQueue; - var queueIndex = -1; - - function cleanUpNextTick() { - if (!draining || !currentQueue) { - return; - } - draining = false; - if (currentQueue.length) { - queue = currentQueue.concat(queue); - } else { - queueIndex = -1; - } - if (queue.length) { - drainQueue(); - } - } - - function drainQueue() { - if (draining) { - return; - } - var timeout = runTimeout(cleanUpNextTick); - draining = true; - - var len = queue.length; - while(len) { - currentQueue = queue; - queue = []; - while (++queueIndex < len) { - if (currentQueue) { - currentQueue[queueIndex].run(); - } - } - queueIndex = -1; - len = queue.length; - } - currentQueue = null; - draining = false; - runClearTimeout(timeout); - } - function nextTick(fun) { - var args = new Array(arguments.length - 1); - if (arguments.length > 1) { - for (var i = 1; i < arguments.length; i++) { - args[i - 1] = arguments[i]; - } - } - queue.push(new Item(fun, args)); - if (queue.length === 1 && !draining) { - runTimeout(drainQueue); - } - } - // v8 likes predictible objects - function Item(fun, array) { - this.fun = fun; - this.array = array; - } - Item.prototype.run = function () { - this.fun.apply(null, this.array); - }; - var title = 'browser'; - var platform = 'browser'; - var browser = true; - var env = {}; - var argv = []; - var version = ''; // empty string to avoid regexp issues - var versions = {}; - var release = {}; - var config = {}; - - function noop() {} - - var on = noop; - var addListener = noop; - var once = noop; - var off = noop; - var removeListener = noop; - var removeAllListeners = noop; - var emit = noop; - - function binding(name) { - throw new Error('process.binding is not supported'); - } - - function cwd () { return '/' } - function chdir (dir) { - throw new Error('process.chdir is not supported'); - }function umask() { return 0; } - - // from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js - var performance = global$1.performance || {}; - var performanceNow = - performance.now || - performance.mozNow || - performance.msNow || - performance.oNow || - performance.webkitNow || - function(){ return (new Date()).getTime() }; - - // generate timestamp or delta - // see http://nodejs.org/api/process.html#process_process_hrtime - function hrtime(previousTimestamp){ - var clocktime = performanceNow.call(performance)*1e-3; - var seconds = Math.floor(clocktime); - var nanoseconds = Math.floor((clocktime%1)*1e9); - if (previousTimestamp) { - seconds = seconds - previousTimestamp[0]; - nanoseconds = nanoseconds - previousTimestamp[1]; - if (nanoseconds<0) { - seconds--; - nanoseconds += 1e9; - } - } - return [seconds,nanoseconds] - } - - var startTime = new Date(); - function uptime() { - var currentTime = new Date(); - var dif = currentTime - startTime; - return dif / 1000; - } - - var browser$1 = { - nextTick: nextTick, - title: title, - browser: browser, - env: env, - argv: argv, - version: version, - versions: versions, - on: on, - addListener: addListener, - once: once, - off: off, - removeListener: removeListener, - removeAllListeners: removeAllListeners, - emit: emit, - binding: binding, - cwd: cwd, - chdir: chdir, - umask: umask, - hrtime: hrtime, - platform: platform, - release: release, - config: config, - uptime: uptime - }; - - var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; - - function getDefaultExportFromCjs (x) { - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; - } - - function getAugmentedNamespace(n) { - if (n.__esModule) return n; - var f = n.default; - if (typeof f == "function") { - var a = function a () { - if (this instanceof a) { - return Reflect.construct(f, arguments, this.constructor); - } - return f.apply(this, arguments); - }; - a.prototype = f.prototype; - } else a = {}; - Object.defineProperty(a, '__esModule', {value: true}); - Object.keys(n).forEach(function (k) { - var d = Object.getOwnPropertyDescriptor(n, k); - Object.defineProperty(a, k, d.get ? d : { - enumerable: true, - get: function () { - return n[k]; - } - }); - }); - return a; - } - - function commonjsRequire(path) { - throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.'); - } - - var jszip_min = {exports: {}}; - - (function (module, exports) { - !function(e){module.exports=e();}(function(){return function s(a,o,h){function u(r,e){if(!o[r]){if(!a[r]){var t="function"==typeof commonjsRequire&&commonjsRequire;if(!e&&t)return t(r,!0);if(l)return l(r,!0);var n=new Error("Cannot find module '"+r+"'");throw n.code="MODULE_NOT_FOUND",n}var i=o[r]={exports:{}};a[r][0].call(i.exports,function(e){var t=a[r][1][e];return u(t||e)},i,i.exports,s,a,o,h);}return o[r].exports}for(var l="function"==typeof commonjsRequire&&commonjsRequire,e=0;e>2,s=(3&t)<<4|r>>4,a=1>6:64,o=2>4,r=(15&i)<<4|(s=p.indexOf(e.charAt(o++)))>>2,n=(3&s)<<6|(a=p.indexOf(e.charAt(o++))),l[h++]=t,64!==s&&(l[h++]=r),64!==a&&(l[h++]=n);return l};},{"./support":30,"./utils":32}],2:[function(e,t,r){var n=e("./external"),i=e("./stream/DataWorker"),s=e("./stream/Crc32Probe"),a=e("./stream/DataLengthProbe");function o(e,t,r,n,i){this.compressedSize=e,this.uncompressedSize=t,this.crc32=r,this.compression=n,this.compressedContent=i;}o.prototype={getContentWorker:function(){var e=new i(n.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new a("data_length")),t=this;return e.on("end",function(){if(this.streamInfo.data_length!==t.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),e},getCompressedWorker:function(){return new i(n.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},o.createWorkerFrom=function(e,t,r){return e.pipe(new s).pipe(new a("uncompressedSize")).pipe(t.compressWorker(r)).pipe(new a("compressedSize")).withStreamInfo("compression",t)},t.exports=o;},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(e,t,r){var n=e("./stream/GenericWorker");r.STORE={magic:"\0\0",compressWorker:function(){return new n("STORE compression")},uncompressWorker:function(){return new n("STORE decompression")}},r.DEFLATE=e("./flate");},{"./flate":7,"./stream/GenericWorker":28}],4:[function(e,t,r){var n=e("./utils");var o=function(){for(var e,t=[],r=0;r<256;r++){e=r;for(var n=0;n<8;n++)e=1&e?3988292384^e>>>1:e>>>1;t[r]=e;}return t}();t.exports=function(e,t){return void 0!==e&&e.length?"string"!==n.getTypeOf(e)?function(e,t,r,n){var i=o,s=n+r;e^=-1;for(var a=n;a>>8^i[255&(e^t[a])];return -1^e}(0|t,e,e.length,0):function(e,t,r,n){var i=o,s=n+r;e^=-1;for(var a=n;a>>8^i[255&(e^t.charCodeAt(a))];return -1^e}(0|t,e,e.length,0):0};},{"./utils":32}],5:[function(e,t,r){r.base64=!1,r.binary=!1,r.dir=!1,r.createFolders=!0,r.date=null,r.compression=null,r.compressionOptions=null,r.comment=null,r.unixPermissions=null,r.dosPermissions=null;},{}],6:[function(e,t,r){var n=null;n="undefined"!=typeof Promise?Promise:e("lie"),t.exports={Promise:n};},{lie:37}],7:[function(e,t,r){var n="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array,i=e("pako"),s=e("./utils"),a=e("./stream/GenericWorker"),o=n?"uint8array":"array";function h(e,t){a.call(this,"FlateWorker/"+e),this._pako=null,this._pakoAction=e,this._pakoOptions=t,this.meta={};}r.magic="\b\0",s.inherits(h,a),h.prototype.processChunk=function(e){this.meta=e.meta,null===this._pako&&this._createPako(),this._pako.push(s.transformTo(o,e.data),!1);},h.prototype.flush=function(){a.prototype.flush.call(this),null===this._pako&&this._createPako(),this._pako.push([],!0);},h.prototype.cleanUp=function(){a.prototype.cleanUp.call(this),this._pako=null;},h.prototype._createPako=function(){this._pako=new i[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var t=this;this._pako.onData=function(e){t.push({data:e,meta:t.meta});};},r.compressWorker=function(e){return new h("Deflate",e)},r.uncompressWorker=function(){return new h("Inflate",{})};},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(e,t,r){function A(e,t){var r,n="";for(r=0;r>>=8;return n}function n(e,t,r,n,i,s){var a,o,h=e.file,u=e.compression,l=s!==O.utf8encode,f=I.transformTo("string",s(h.name)),c=I.transformTo("string",O.utf8encode(h.name)),d=h.comment,p=I.transformTo("string",s(d)),m=I.transformTo("string",O.utf8encode(d)),_=c.length!==h.name.length,g=m.length!==d.length,b="",v="",y="",w=h.dir,k=h.date,x={crc32:0,compressedSize:0,uncompressedSize:0};t&&!r||(x.crc32=e.crc32,x.compressedSize=e.compressedSize,x.uncompressedSize=e.uncompressedSize);var S=0;t&&(S|=8),l||!_&&!g||(S|=2048);var z=0,C=0;w&&(z|=16),"UNIX"===i?(C=798,z|=function(e,t){var r=e;return e||(r=t?16893:33204),(65535&r)<<16}(h.unixPermissions,w)):(C=20,z|=function(e){return 63&(e||0)}(h.dosPermissions)),a=k.getUTCHours(),a<<=6,a|=k.getUTCMinutes(),a<<=5,a|=k.getUTCSeconds()/2,o=k.getUTCFullYear()-1980,o<<=4,o|=k.getUTCMonth()+1,o<<=5,o|=k.getUTCDate(),_&&(v=A(1,1)+A(B(f),4)+c,b+="up"+A(v.length,2)+v),g&&(y=A(1,1)+A(B(p),4)+m,b+="uc"+A(y.length,2)+y);var E="";return E+="\n\0",E+=A(S,2),E+=u.magic,E+=A(a,2),E+=A(o,2),E+=A(x.crc32,4),E+=A(x.compressedSize,4),E+=A(x.uncompressedSize,4),E+=A(f.length,2),E+=A(b.length,2),{fileRecord:R.LOCAL_FILE_HEADER+E+f+b,dirRecord:R.CENTRAL_FILE_HEADER+A(C,2)+E+A(p.length,2)+"\0\0\0\0"+A(z,4)+A(n,4)+f+b+p}}var I=e("../utils"),i=e("../stream/GenericWorker"),O=e("../utf8"),B=e("../crc32"),R=e("../signature");function s(e,t,r,n){i.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=t,this.zipPlatform=r,this.encodeFileName=n,this.streamFiles=e,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[];}I.inherits(s,i),s.prototype.push=function(e){var t=e.meta.percent||0,r=this.entriesCount,n=this._sources.length;this.accumulate?this.contentBuffer.push(e):(this.bytesWritten+=e.data.length,i.prototype.push.call(this,{data:e.data,meta:{currentFile:this.currentFile,percent:r?(t+100*(r-n-1))/r:100}}));},s.prototype.openedSource=function(e){this.currentSourceOffset=this.bytesWritten,this.currentFile=e.file.name;var t=this.streamFiles&&!e.file.dir;if(t){var r=n(e,t,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:r.fileRecord,meta:{percent:0}});}else this.accumulate=!0;},s.prototype.closedSource=function(e){this.accumulate=!1;var t=this.streamFiles&&!e.file.dir,r=n(e,t,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(r.dirRecord),t)this.push({data:function(e){return R.DATA_DESCRIPTOR+A(e.crc32,4)+A(e.compressedSize,4)+A(e.uncompressedSize,4)}(e),meta:{percent:100}});else for(this.push({data:r.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null;},s.prototype.flush=function(){for(var e=this.bytesWritten,t=0;t=this.index;t--)r=(r<<8)+this.byteAt(t);return this.index+=e,r},readString:function(e){return n.transformTo("string",this.readData(e))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var e=this.readInt(4);return new Date(Date.UTC(1980+(e>>25&127),(e>>21&15)-1,e>>16&31,e>>11&31,e>>5&63,(31&e)<<1))}},t.exports=i;},{"../utils":32}],19:[function(e,t,r){var n=e("./Uint8ArrayReader");function i(e){n.call(this,e);}e("../utils").inherits(i,n),i.prototype.readData=function(e){this.checkOffset(e);var t=this.data.slice(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i;},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(e,t,r){var n=e("./DataReader");function i(e){n.call(this,e);}e("../utils").inherits(i,n),i.prototype.byteAt=function(e){return this.data.charCodeAt(this.zero+e)},i.prototype.lastIndexOfSignature=function(e){return this.data.lastIndexOf(e)-this.zero},i.prototype.readAndCheckSignature=function(e){return e===this.readData(4)},i.prototype.readData=function(e){this.checkOffset(e);var t=this.data.slice(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i;},{"../utils":32,"./DataReader":18}],21:[function(e,t,r){var n=e("./ArrayReader");function i(e){n.call(this,e);}e("../utils").inherits(i,n),i.prototype.readData=function(e){if(this.checkOffset(e),0===e)return new Uint8Array(0);var t=this.data.subarray(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i;},{"../utils":32,"./ArrayReader":17}],22:[function(e,t,r){var n=e("../utils"),i=e("../support"),s=e("./ArrayReader"),a=e("./StringReader"),o=e("./NodeBufferReader"),h=e("./Uint8ArrayReader");t.exports=function(e){var t=n.getTypeOf(e);return n.checkSupport(t),"string"!==t||i.uint8array?"nodebuffer"===t?new o(e):i.uint8array?new h(n.transformTo("uint8array",e)):new s(n.transformTo("array",e)):new a(e)};},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(e,t,r){r.LOCAL_FILE_HEADER="PK",r.CENTRAL_FILE_HEADER="PK",r.CENTRAL_DIRECTORY_END="PK",r.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK",r.ZIP64_CENTRAL_DIRECTORY_END="PK",r.DATA_DESCRIPTOR="PK\b";},{}],24:[function(e,t,r){var n=e("./GenericWorker"),i=e("../utils");function s(e){n.call(this,"ConvertWorker to "+e),this.destType=e;}i.inherits(s,n),s.prototype.processChunk=function(e){this.push({data:i.transformTo(this.destType,e.data),meta:e.meta});},t.exports=s;},{"../utils":32,"./GenericWorker":28}],25:[function(e,t,r){var n=e("./GenericWorker"),i=e("../crc32");function s(){n.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0);}e("../utils").inherits(s,n),s.prototype.processChunk=function(e){this.streamInfo.crc32=i(e.data,this.streamInfo.crc32||0),this.push(e);},t.exports=s;},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(e,t,r){var n=e("../utils"),i=e("./GenericWorker");function s(e){i.call(this,"DataLengthProbe for "+e),this.propName=e,this.withStreamInfo(e,0);}n.inherits(s,i),s.prototype.processChunk=function(e){if(e){var t=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=t+e.data.length;}i.prototype.processChunk.call(this,e);},t.exports=s;},{"../utils":32,"./GenericWorker":28}],27:[function(e,t,r){var n=e("../utils"),i=e("./GenericWorker");function s(e){i.call(this,"DataWorker");var t=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,e.then(function(e){t.dataIsReady=!0,t.data=e,t.max=e&&e.length||0,t.type=n.getTypeOf(e),t.isPaused||t._tickAndRepeat();},function(e){t.error(e);});}n.inherits(s,i),s.prototype.cleanUp=function(){i.prototype.cleanUp.call(this),this.data=null;},s.prototype.resume=function(){return !!i.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,n.delay(this._tickAndRepeat,[],this)),!0)},s.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(n.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0));},s.prototype._tick=function(){if(this.isPaused||this.isFinished)return !1;var e=null,t=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case"string":e=this.data.substring(this.index,t);break;case"uint8array":e=this.data.subarray(this.index,t);break;case"array":case"nodebuffer":e=this.data.slice(this.index,t);}return this.index=t,this.push({data:e,meta:{percent:this.max?this.index/this.max*100:0}})},t.exports=s;},{"../utils":32,"./GenericWorker":28}],28:[function(e,t,r){function n(e){this.name=e||"default",this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null;}n.prototype={push:function(e){this.emit("data",e);},end:function(){if(this.isFinished)return !1;this.flush();try{this.emit("end"),this.cleanUp(),this.isFinished=!0;}catch(e){this.emit("error",e);}return !0},error:function(e){return !this.isFinished&&(this.isPaused?this.generatedError=e:(this.isFinished=!0,this.emit("error",e),this.previous&&this.previous.error(e),this.cleanUp()),!0)},on:function(e,t){return this._listeners[e].push(t),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[];},emit:function(e,t){if(this._listeners[e])for(var r=0;r "+e:e}},t.exports=n;},{}],29:[function(e,t,r){var h=e("../utils"),i=e("./ConvertWorker"),s=e("./GenericWorker"),u=e("../base64"),n=e("../support"),a=e("../external"),o=null;if(n.nodestream)try{o=e("../nodejs/NodejsStreamOutputAdapter");}catch(e){}function l(e,o){return new a.Promise(function(t,r){var n=[],i=e._internalType,s=e._outputType,a=e._mimeType;e.on("data",function(e,t){n.push(e),o&&o(t);}).on("error",function(e){n=[],r(e);}).on("end",function(){try{var e=function(e,t,r){switch(e){case"blob":return h.newBlob(h.transformTo("arraybuffer",t),r);case"base64":return u.encode(t);default:return h.transformTo(e,t)}}(s,function(e,t){var r,n=0,i=null,s=0;for(r=0;r>>6:(r<65536?t[s++]=224|r>>>12:(t[s++]=240|r>>>18,t[s++]=128|r>>>12&63),t[s++]=128|r>>>6&63),t[s++]=128|63&r);return t}(e)},s.utf8decode=function(e){return h.nodebuffer?o.transformTo("nodebuffer",e).toString("utf-8"):function(e){var t,r,n,i,s=e.length,a=new Array(2*s);for(t=r=0;t>10&1023,a[r++]=56320|1023&n);}return a.length!==r&&(a.subarray?a=a.subarray(0,r):a.length=r),o.applyFromCharCode(a)}(e=o.transformTo(h.uint8array?"uint8array":"array",e))},o.inherits(a,n),a.prototype.processChunk=function(e){var t=o.transformTo(h.uint8array?"uint8array":"array",e.data);if(this.leftOver&&this.leftOver.length){if(h.uint8array){var r=t;(t=new Uint8Array(r.length+this.leftOver.length)).set(this.leftOver,0),t.set(r,this.leftOver.length);}else t=this.leftOver.concat(t);this.leftOver=null;}var n=function(e,t){var r;for((t=t||e.length)>e.length&&(t=e.length),r=t-1;0<=r&&128==(192&e[r]);)r--;return r<0?t:0===r?t:r+u[e[r]]>t?r:t}(t),i=t;n!==t.length&&(h.uint8array?(i=t.subarray(0,n),this.leftOver=t.subarray(n,t.length)):(i=t.slice(0,n),this.leftOver=t.slice(n,t.length))),this.push({data:s.utf8decode(i),meta:e.meta});},a.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:s.utf8decode(this.leftOver),meta:{}}),this.leftOver=null);},s.Utf8DecodeWorker=a,o.inherits(l,n),l.prototype.processChunk=function(e){this.push({data:s.utf8encode(e.data),meta:e.meta});},s.Utf8EncodeWorker=l;},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(e,t,a){var o=e("./support"),h=e("./base64"),r=e("./nodejsUtils"),u=e("./external");function n(e){return e}function l(e,t){for(var r=0;r>8;this.dir=!!(16&this.externalFileAttributes),0==e&&(this.dosPermissions=63&this.externalFileAttributes),3==e&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||"/"!==this.fileNameStr.slice(-1)||(this.dir=!0);},parseZIP64ExtraField:function(){if(this.extraFields[1]){var e=n(this.extraFields[1].value);this.uncompressedSize===s.MAX_VALUE_32BITS&&(this.uncompressedSize=e.readInt(8)),this.compressedSize===s.MAX_VALUE_32BITS&&(this.compressedSize=e.readInt(8)),this.localHeaderOffset===s.MAX_VALUE_32BITS&&(this.localHeaderOffset=e.readInt(8)),this.diskNumberStart===s.MAX_VALUE_32BITS&&(this.diskNumberStart=e.readInt(4));}},readExtraFields:function(e){var t,r,n,i=e.index+this.extraFieldsLength;for(this.extraFields||(this.extraFields={});e.index+4>>6:(r<65536?t[s++]=224|r>>>12:(t[s++]=240|r>>>18,t[s++]=128|r>>>12&63),t[s++]=128|r>>>6&63),t[s++]=128|63&r);return t},r.buf2binstring=function(e){return l(e,e.length)},r.binstring2buf=function(e){for(var t=new h.Buf8(e.length),r=0,n=t.length;r>10&1023,o[n++]=56320|1023&i);}return l(o,n)},r.utf8border=function(e,t){var r;for((t=t||e.length)>e.length&&(t=e.length),r=t-1;0<=r&&128==(192&e[r]);)r--;return r<0?t:0===r?t:r+u[e[r]]>t?r:t};},{"./common":41}],43:[function(e,t,r){t.exports=function(e,t,r,n){for(var i=65535&e|0,s=e>>>16&65535|0,a=0;0!==r;){for(r-=a=2e3>>1:e>>>1;t[r]=e;}return t}();t.exports=function(e,t,r,n){var i=o,s=n+r;e^=-1;for(var a=n;a>>8^i[255&(e^t[a])];return -1^e};},{}],46:[function(e,t,r){var h,c=e("../utils/common"),u=e("./trees"),d=e("./adler32"),p=e("./crc32"),n=e("./messages"),l=0,f=4,m=0,_=-2,g=-1,b=4,i=2,v=8,y=9,s=286,a=30,o=19,w=2*s+1,k=15,x=3,S=258,z=S+x+1,C=42,E=113,A=1,I=2,O=3,B=4;function R(e,t){return e.msg=n[t],t}function T(e){return (e<<1)-(4e.avail_out&&(r=e.avail_out),0!==r&&(c.arraySet(e.output,t.pending_buf,t.pending_out,r,e.next_out),e.next_out+=r,t.pending_out+=r,e.total_out+=r,e.avail_out-=r,t.pending-=r,0===t.pending&&(t.pending_out=0));}function N(e,t){u._tr_flush_block(e,0<=e.block_start?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,F(e.strm);}function U(e,t){e.pending_buf[e.pending++]=t;}function P(e,t){e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t;}function L(e,t){var r,n,i=e.max_chain_length,s=e.strstart,a=e.prev_length,o=e.nice_match,h=e.strstart>e.w_size-z?e.strstart-(e.w_size-z):0,u=e.window,l=e.w_mask,f=e.prev,c=e.strstart+S,d=u[s+a-1],p=u[s+a];e.prev_length>=e.good_match&&(i>>=2),o>e.lookahead&&(o=e.lookahead);do{if(u[(r=t)+a]===p&&u[r+a-1]===d&&u[r]===u[s]&&u[++r]===u[s+1]){s+=2,r++;do{}while(u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&sh&&0!=--i);return a<=e.lookahead?a:e.lookahead}function j(e){var t,r,n,i,s,a,o,h,u,l,f=e.w_size;do{if(i=e.window_size-e.lookahead-e.strstart,e.strstart>=f+(f-z)){for(c.arraySet(e.window,e.window,f,f,0),e.match_start-=f,e.strstart-=f,e.block_start-=f,t=r=e.hash_size;n=e.head[--t],e.head[t]=f<=n?n-f:0,--r;);for(t=r=f;n=e.prev[--t],e.prev[t]=f<=n?n-f:0,--r;);i+=f;}if(0===e.strm.avail_in)break;if(a=e.strm,o=e.window,h=e.strstart+e.lookahead,u=i,l=void 0,l=a.avail_in,u=x)for(s=e.strstart-e.insert,e.ins_h=e.window[s],e.ins_h=(e.ins_h<=x&&(e.ins_h=(e.ins_h<=x)if(n=u._tr_tally(e,e.strstart-e.match_start,e.match_length-x),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=x){for(e.match_length--;e.strstart++,e.ins_h=(e.ins_h<=x&&(e.ins_h=(e.ins_h<=x&&e.match_length<=e.prev_length){for(i=e.strstart+e.lookahead-x,n=u._tr_tally(e,e.strstart-1-e.prev_match,e.prev_length-x),e.lookahead-=e.prev_length-1,e.prev_length-=2;++e.strstart<=i&&(e.ins_h=(e.ins_h<e.pending_buf_size-5&&(r=e.pending_buf_size-5);;){if(e.lookahead<=1){if(j(e),0===e.lookahead&&t===l)return A;if(0===e.lookahead)break}e.strstart+=e.lookahead,e.lookahead=0;var n=e.block_start+r;if((0===e.strstart||e.strstart>=n)&&(e.lookahead=e.strstart-n,e.strstart=n,N(e,!1),0===e.strm.avail_out))return A;if(e.strstart-e.block_start>=e.w_size-z&&(N(e,!1),0===e.strm.avail_out))return A}return e.insert=0,t===f?(N(e,!0),0===e.strm.avail_out?O:B):(e.strstart>e.block_start&&(N(e,!1),e.strm.avail_out),A)}),new M(4,4,8,4,Z),new M(4,5,16,8,Z),new M(4,6,32,32,Z),new M(4,4,16,16,W),new M(8,16,32,32,W),new M(8,16,128,128,W),new M(8,32,128,256,W),new M(32,128,258,1024,W),new M(32,258,258,4096,W)],r.deflateInit=function(e,t){return Y(e,t,v,15,8,0)},r.deflateInit2=Y,r.deflateReset=K,r.deflateResetKeep=G,r.deflateSetHeader=function(e,t){return e&&e.state?2!==e.state.wrap?_:(e.state.gzhead=t,m):_},r.deflate=function(e,t){var r,n,i,s;if(!e||!e.state||5>8&255),U(n,n.gzhead.time>>16&255),U(n,n.gzhead.time>>24&255),U(n,9===n.level?2:2<=n.strategy||n.level<2?4:0),U(n,255&n.gzhead.os),n.gzhead.extra&&n.gzhead.extra.length&&(U(n,255&n.gzhead.extra.length),U(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(e.adler=p(e.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=69):(U(n,0),U(n,0),U(n,0),U(n,0),U(n,0),U(n,9===n.level?2:2<=n.strategy||n.level<2?4:0),U(n,3),n.status=E);else {var a=v+(n.w_bits-8<<4)<<8;a|=(2<=n.strategy||n.level<2?0:n.level<6?1:6===n.level?2:3)<<6,0!==n.strstart&&(a|=32),a+=31-a%31,n.status=E,P(n,a),0!==n.strstart&&(P(n,e.adler>>>16),P(n,65535&e.adler)),e.adler=1;}if(69===n.status)if(n.gzhead.extra){for(i=n.pending;n.gzindex<(65535&n.gzhead.extra.length)&&(n.pending!==n.pending_buf_size||(n.gzhead.hcrc&&n.pending>i&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),F(e),i=n.pending,n.pending!==n.pending_buf_size));)U(n,255&n.gzhead.extra[n.gzindex]),n.gzindex++;n.gzhead.hcrc&&n.pending>i&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),n.gzindex===n.gzhead.extra.length&&(n.gzindex=0,n.status=73);}else n.status=73;if(73===n.status)if(n.gzhead.name){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),F(e),i=n.pending,n.pending===n.pending_buf_size)){s=1;break}s=n.gzindexi&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),0===s&&(n.gzindex=0,n.status=91);}else n.status=91;if(91===n.status)if(n.gzhead.comment){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),F(e),i=n.pending,n.pending===n.pending_buf_size)){s=1;break}s=n.gzindexi&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),0===s&&(n.status=103);}else n.status=103;if(103===n.status&&(n.gzhead.hcrc?(n.pending+2>n.pending_buf_size&&F(e),n.pending+2<=n.pending_buf_size&&(U(n,255&e.adler),U(n,e.adler>>8&255),e.adler=0,n.status=E)):n.status=E),0!==n.pending){if(F(e),0===e.avail_out)return n.last_flush=-1,m}else if(0===e.avail_in&&T(t)<=T(r)&&t!==f)return R(e,-5);if(666===n.status&&0!==e.avail_in)return R(e,-5);if(0!==e.avail_in||0!==n.lookahead||t!==l&&666!==n.status){var o=2===n.strategy?function(e,t){for(var r;;){if(0===e.lookahead&&(j(e),0===e.lookahead)){if(t===l)return A;break}if(e.match_length=0,r=u._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,r&&(N(e,!1),0===e.strm.avail_out))return A}return e.insert=0,t===f?(N(e,!0),0===e.strm.avail_out?O:B):e.last_lit&&(N(e,!1),0===e.strm.avail_out)?A:I}(n,t):3===n.strategy?function(e,t){for(var r,n,i,s,a=e.window;;){if(e.lookahead<=S){if(j(e),e.lookahead<=S&&t===l)return A;if(0===e.lookahead)break}if(e.match_length=0,e.lookahead>=x&&0e.lookahead&&(e.match_length=e.lookahead);}if(e.match_length>=x?(r=u._tr_tally(e,1,e.match_length-x),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(r=u._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),r&&(N(e,!1),0===e.strm.avail_out))return A}return e.insert=0,t===f?(N(e,!0),0===e.strm.avail_out?O:B):e.last_lit&&(N(e,!1),0===e.strm.avail_out)?A:I}(n,t):h[n.level].func(n,t);if(o!==O&&o!==B||(n.status=666),o===A||o===O)return 0===e.avail_out&&(n.last_flush=-1),m;if(o===I&&(1===t?u._tr_align(n):5!==t&&(u._tr_stored_block(n,0,0,!1),3===t&&(D(n.head),0===n.lookahead&&(n.strstart=0,n.block_start=0,n.insert=0))),F(e),0===e.avail_out))return n.last_flush=-1,m}return t!==f?m:n.wrap<=0?1:(2===n.wrap?(U(n,255&e.adler),U(n,e.adler>>8&255),U(n,e.adler>>16&255),U(n,e.adler>>24&255),U(n,255&e.total_in),U(n,e.total_in>>8&255),U(n,e.total_in>>16&255),U(n,e.total_in>>24&255)):(P(n,e.adler>>>16),P(n,65535&e.adler)),F(e),0=r.w_size&&(0===s&&(D(r.head),r.strstart=0,r.block_start=0,r.insert=0),u=new c.Buf8(r.w_size),c.arraySet(u,t,l-r.w_size,r.w_size,0),t=u,l=r.w_size),a=e.avail_in,o=e.next_in,h=e.input,e.avail_in=l,e.next_in=0,e.input=t,j(r);r.lookahead>=x;){for(n=r.strstart,i=r.lookahead-(x-1);r.ins_h=(r.ins_h<>>=y=v>>>24,p-=y,0===(y=v>>>16&255))C[s++]=65535&v;else {if(!(16&y)){if(0==(64&y)){v=m[(65535&v)+(d&(1<>>=y,p-=y),p<15&&(d+=z[n++]<>>=y=v>>>24,p-=y,!(16&(y=v>>>16&255))){if(0==(64&y)){v=_[(65535&v)+(d&(1<>>=y,p-=y,(y=s-a)>3,d&=(1<<(p-=w<<3))-1,e.next_in=n,e.next_out=s,e.avail_in=n>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24)}function s(){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 I.Buf16(320),this.work=new I.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0;}function a(e){var t;return e&&e.state?(t=e.state,e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=P,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new I.Buf32(n),t.distcode=t.distdyn=new I.Buf32(i),t.sane=1,t.back=-1,N):U}function o(e){var t;return e&&e.state?((t=e.state).wsize=0,t.whave=0,t.wnext=0,a(e)):U}function h(e,t){var r,n;return e&&e.state?(n=e.state,t<0?(r=0,t=-t):(r=1+(t>>4),t<48&&(t&=15)),t&&(t<8||15=s.wsize?(I.arraySet(s.window,t,r-s.wsize,s.wsize,0),s.wnext=0,s.whave=s.wsize):(n<(i=s.wsize-s.wnext)&&(i=n),I.arraySet(s.window,t,r-n,i,s.wnext),(n-=i)?(I.arraySet(s.window,t,r-n,n,0),s.wnext=n,s.whave=s.wsize):(s.wnext+=i,s.wnext===s.wsize&&(s.wnext=0),s.whave>>8&255,r.check=B(r.check,E,2,0),l=u=0,r.mode=2;break}if(r.flags=0,r.head&&(r.head.done=!1),!(1&r.wrap)||(((255&u)<<8)+(u>>8))%31){e.msg="incorrect header check",r.mode=30;break}if(8!=(15&u)){e.msg="unknown compression method",r.mode=30;break}if(l-=4,k=8+(15&(u>>>=4)),0===r.wbits)r.wbits=k;else if(k>r.wbits){e.msg="invalid window size",r.mode=30;break}r.dmax=1<>8&1),512&r.flags&&(E[0]=255&u,E[1]=u>>>8&255,r.check=B(r.check,E,2,0)),l=u=0,r.mode=3;case 3:for(;l<32;){if(0===o)break e;o--,u+=n[s++]<>>8&255,E[2]=u>>>16&255,E[3]=u>>>24&255,r.check=B(r.check,E,4,0)),l=u=0,r.mode=4;case 4:for(;l<16;){if(0===o)break e;o--,u+=n[s++]<>8),512&r.flags&&(E[0]=255&u,E[1]=u>>>8&255,r.check=B(r.check,E,2,0)),l=u=0,r.mode=5;case 5:if(1024&r.flags){for(;l<16;){if(0===o)break e;o--,u+=n[s++]<>>8&255,r.check=B(r.check,E,2,0)),l=u=0;}else r.head&&(r.head.extra=null);r.mode=6;case 6:if(1024&r.flags&&(o<(d=r.length)&&(d=o),d&&(r.head&&(k=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Array(r.head.extra_len)),I.arraySet(r.head.extra,n,s,d,k)),512&r.flags&&(r.check=B(r.check,n,d,s)),o-=d,s+=d,r.length-=d),r.length))break e;r.length=0,r.mode=7;case 7:if(2048&r.flags){if(0===o)break e;for(d=0;k=n[s+d++],r.head&&k&&r.length<65536&&(r.head.name+=String.fromCharCode(k)),k&&d>9&1,r.head.done=!0),e.adler=r.check=0,r.mode=12;break;case 10:for(;l<32;){if(0===o)break e;o--,u+=n[s++]<>>=7&l,l-=7&l,r.mode=27;break}for(;l<3;){if(0===o)break e;o--,u+=n[s++]<>>=1)){case 0:r.mode=14;break;case 1:if(j(r),r.mode=20,6!==t)break;u>>>=2,l-=2;break e;case 2:r.mode=17;break;case 3:e.msg="invalid block type",r.mode=30;}u>>>=2,l-=2;break;case 14:for(u>>>=7&l,l-=7&l;l<32;){if(0===o)break e;o--,u+=n[s++]<>>16^65535)){e.msg="invalid stored block lengths",r.mode=30;break}if(r.length=65535&u,l=u=0,r.mode=15,6===t)break e;case 15:r.mode=16;case 16:if(d=r.length){if(o>>=5,l-=5,r.ndist=1+(31&u),u>>>=5,l-=5,r.ncode=4+(15&u),u>>>=4,l-=4,286>>=3,l-=3;}for(;r.have<19;)r.lens[A[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,S={bits:r.lenbits},x=T(0,r.lens,0,19,r.lencode,0,r.work,S),r.lenbits=S.bits,x){e.msg="invalid code lengths set",r.mode=30;break}r.have=0,r.mode=19;case 19:for(;r.have>>16&255,b=65535&C,!((_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>>=_,l-=_,r.lens[r.have++]=b;else {if(16===b){for(z=_+2;l>>=_,l-=_,0===r.have){e.msg="invalid bit length repeat",r.mode=30;break}k=r.lens[r.have-1],d=3+(3&u),u>>>=2,l-=2;}else if(17===b){for(z=_+3;l>>=_)),u>>>=3,l-=3;}else {for(z=_+7;l>>=_)),u>>>=7,l-=7;}if(r.have+d>r.nlen+r.ndist){e.msg="invalid bit length repeat",r.mode=30;break}for(;d--;)r.lens[r.have++]=k;}}if(30===r.mode)break;if(0===r.lens[256]){e.msg="invalid code -- missing end-of-block",r.mode=30;break}if(r.lenbits=9,S={bits:r.lenbits},x=T(D,r.lens,0,r.nlen,r.lencode,0,r.work,S),r.lenbits=S.bits,x){e.msg="invalid literal/lengths set",r.mode=30;break}if(r.distbits=6,r.distcode=r.distdyn,S={bits:r.distbits},x=T(F,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,S),r.distbits=S.bits,x){e.msg="invalid distances set",r.mode=30;break}if(r.mode=20,6===t)break e;case 20:r.mode=21;case 21:if(6<=o&&258<=h){e.next_out=a,e.avail_out=h,e.next_in=s,e.avail_in=o,r.hold=u,r.bits=l,R(e,c),a=e.next_out,i=e.output,h=e.avail_out,s=e.next_in,n=e.input,o=e.avail_in,u=r.hold,l=r.bits,12===r.mode&&(r.back=-1);break}for(r.back=0;g=(C=r.lencode[u&(1<>>16&255,b=65535&C,!((_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>v)])>>>16&255,b=65535&C,!(v+(_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>>=v,l-=v,r.back+=v;}if(u>>>=_,l-=_,r.back+=_,r.length=b,0===g){r.mode=26;break}if(32&g){r.back=-1,r.mode=12;break}if(64&g){e.msg="invalid literal/length code",r.mode=30;break}r.extra=15&g,r.mode=22;case 22:if(r.extra){for(z=r.extra;l>>=r.extra,l-=r.extra,r.back+=r.extra;}r.was=r.length,r.mode=23;case 23:for(;g=(C=r.distcode[u&(1<>>16&255,b=65535&C,!((_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>v)])>>>16&255,b=65535&C,!(v+(_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>>=v,l-=v,r.back+=v;}if(u>>>=_,l-=_,r.back+=_,64&g){e.msg="invalid distance code",r.mode=30;break}r.offset=b,r.extra=15&g,r.mode=24;case 24:if(r.extra){for(z=r.extra;l>>=r.extra,l-=r.extra,r.back+=r.extra;}if(r.offset>r.dmax){e.msg="invalid distance too far back",r.mode=30;break}r.mode=25;case 25:if(0===h)break e;if(d=c-h,r.offset>d){if((d=r.offset-d)>r.whave&&r.sane){e.msg="invalid distance too far back",r.mode=30;break}p=d>r.wnext?(d-=r.wnext,r.wsize-d):r.wnext-d,d>r.length&&(d=r.length),m=r.window;}else m=i,p=a-r.offset,d=r.length;for(hd?(m=R[T+a[v]],A[I+a[v]]):(m=96,0),h=1<>S)+(u-=h)]=p<<24|m<<16|_|0,0!==u;);for(h=1<>=1;if(0!==h?(E&=h-1,E+=h):E=0,v++,0==--O[b]){if(b===w)break;b=t[r+a[v]];}if(k>>7)]}function U(e,t){e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255;}function P(e,t,r){e.bi_valid>d-r?(e.bi_buf|=t<>d-e.bi_valid,e.bi_valid+=r-d):(e.bi_buf|=t<>>=1,r<<=1,0<--t;);return r>>>1}function Z(e,t,r){var n,i,s=new Array(g+1),a=0;for(n=1;n<=g;n++)s[n]=a=a+r[n-1]<<1;for(i=0;i<=t;i++){var o=e[2*i+1];0!==o&&(e[2*i]=j(s[o]++,o));}}function W(e){var t;for(t=0;t>1;1<=r;r--)G(e,s,r);for(i=h;r=e.heap[1],e.heap[1]=e.heap[e.heap_len--],G(e,s,1),n=e.heap[1],e.heap[--e.heap_max]=r,e.heap[--e.heap_max]=n,s[2*i]=s[2*r]+s[2*n],e.depth[i]=(e.depth[r]>=e.depth[n]?e.depth[r]:e.depth[n])+1,s[2*r+1]=s[2*n+1]=i,e.heap[1]=i++,G(e,s,1),2<=e.heap_len;);e.heap[--e.heap_max]=e.heap[1],function(e,t){var r,n,i,s,a,o,h=t.dyn_tree,u=t.max_code,l=t.stat_desc.static_tree,f=t.stat_desc.has_stree,c=t.stat_desc.extra_bits,d=t.stat_desc.extra_base,p=t.stat_desc.max_length,m=0;for(s=0;s<=g;s++)e.bl_count[s]=0;for(h[2*e.heap[e.heap_max]+1]=0,r=e.heap_max+1;r<_;r++)p<(s=h[2*h[2*(n=e.heap[r])+1]+1]+1)&&(s=p,m++),h[2*n+1]=s,u>=7;n>>=1)if(1&r&&0!==e.dyn_ltree[2*t])return o;if(0!==e.dyn_ltree[18]||0!==e.dyn_ltree[20]||0!==e.dyn_ltree[26])return h;for(t=32;t>>3,(s=e.static_len+3+7>>>3)<=i&&(i=s)):i=s=r+5,r+4<=i&&-1!==t?J(e,t,r,n):4===e.strategy||s===i?(P(e,2+(n?1:0),3),K(e,z,C)):(P(e,4+(n?1:0),3),function(e,t,r,n){var i;for(P(e,t-257,5),P(e,r-1,5),P(e,n-4,4),i=0;i>>8&255,e.pending_buf[e.d_buf+2*e.last_lit+1]=255&t,e.pending_buf[e.l_buf+e.last_lit]=255&r,e.last_lit++,0===t?e.dyn_ltree[2*r]++:(e.matches++,t--,e.dyn_ltree[2*(A[r]+u+1)]++,e.dyn_dtree[2*N(t)]++),e.last_lit===e.lit_bufsize-1},r._tr_align=function(e){P(e,2,3),L(e,m,z),function(e){16===e.bi_valid?(U(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):8<=e.bi_valid&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8);}(e);};},{"../utils/common":41}],53:[function(e,t,r){t.exports=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0;};},{}],54:[function(e,t,r){(function(e){!function(r,n){if(!r.setImmediate){var i,s,t,a,o=1,h={},u=!1,l=r.document,e=Object.getPrototypeOf&&Object.getPrototypeOf(r);e=e&&e.setTimeout?e:r,i="[object process]"==={}.toString.call(r.process)?function(e){browser$1.nextTick(function(){c(e);});}:function(){if(r.postMessage&&!r.importScripts){var e=!0,t=r.onmessage;return r.onmessage=function(){e=!1;},r.postMessage("","*"),r.onmessage=t,e}}()?(a="setImmediate$"+Math.random()+"$",r.addEventListener?r.addEventListener("message",d,!1):r.attachEvent("onmessage",d),function(e){r.postMessage(a+e,"*");}):r.MessageChannel?((t=new MessageChannel).port1.onmessage=function(e){c(e.data);},function(e){t.port2.postMessage(e);}):l&&"onreadystatechange"in l.createElement("script")?(s=l.documentElement,function(e){var t=l.createElement("script");t.onreadystatechange=function(){c(e),t.onreadystatechange=null,s.removeChild(t),t=null;},s.appendChild(t);}):function(e){setTimeout(c,0,e);},e.setImmediate=function(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),r=0;r { - const zip = new JSZip(); - await zip.loadAsync(buffer); - const files = zip.file(/.+/); - const out = {}; - await Promise.all(files.map(async (a) => { - let result; - if (a.name.slice(-3).toLowerCase() === 'shp' || a.name.slice(-3).toLowerCase() === 'dbf') { - result = await a.async('nodebuffer'); - } else { - result = await a.async('text'); - } - out[a.name] = result; - })); - return out; - }; - - const URL$1 = globalThis.URL; - - var combine$1 = (base, type) => { - if (!type) { - return base; - } - const url = new URL$1(base); - url.pathname = `${url.pathname}.${type}`; - return url.href; - }; - - function binaryAjax$1(_url, type) { - return new Promise(function (resolve, reject) { - const url = combine$1(_url, type); - const ajax = new XMLHttpRequest(); - ajax.open('GET', url, true); - if (type !== 'prj' && type !== 'cpg') { - ajax.responseType = 'arraybuffer'; - } - ajax.addEventListener('load', function () { - if (ajax.status > 399) { - if (type === 'prj' || type === 'cpg') { - return resolve(false); - } else { - return reject(new Error(ajax.status)); - } - } - if (type !== 'prj' && type !== 'cpg') { - return resolve(Buffer.from(ajax.response)); - } else { - return resolve(ajax.response); - } - }, false); - ajax.send(); - }); - } - - async function binaryAjax(_url, type) { - if (!globalThis.fetch) { - return binaryAjax$1(_url, type); - } - const url = combine$1(_url, type); - const isOptionalTxt = type === 'prj' || type === 'cpg'; - try { - const resp = await fetch(url); - if (resp.status > 399) { - throw new Error(resp.statusText); - } - if (isOptionalTxt) { - return resp.text(); - } - const parsed = await resp.arrayBuffer(); - return Buffer.from(parsed); - } catch (e) { - console.log('ERROR', e, type); - if (isOptionalTxt || type === 'dbf') { - return false; - } - throw e; - } - } - - function isClockWise(array) { - let sum = 0; - let i = 1; - const len = array.length; - let prev, cur; - const bbox = [array[0][0], array[0][1], array[0][0], array[0][1]]; - while (i < len) { - prev = cur || array[0]; - cur = array[i]; - sum += ((cur[0] - prev[0]) * (cur[1] + prev[1])); - i++; - if (cur[0] < bbox[0]) { - bbox[0] = cur[0]; - } - if (cur[1] < bbox[1]) { - bbox[1] = cur[1]; - } - if (cur[0] > bbox[2]) { - bbox[2] = cur[0]; - } - if (cur[1] > bbox[3]) { - bbox[3] = cur[1]; - } - } - return { - ring: array, - clockWise: sum > 0, - bbox, - children: [] - } - - } - - function contains(outer, inner) { - if (outer.bbox[0] > inner.bbox[0]) { - return false; - } - if (outer.bbox[1] > inner.bbox[1]) { - return false; - } - if (outer.bbox[2] < inner.bbox[2]) { - return false; - } - if (outer.bbox[3] < inner.bbox[3]) { - return false; - } - return true; - } - - function handleRings(rings) { - const outers = []; - const inners = []; - for (const ring of rings) { - const proccessed = isClockWise(ring); - if (proccessed.clockWise) { - outers.push(proccessed); - } else { - inners.push(proccessed); - } - } - // this is an optimization, - // but it would also put in weird bad rings that would otherwise get left out - // if (outers.length === 1) { - // const out = [outers[0].ring] - // for (const inner of inners) { - // out.push(inner.ring); - - // } - // return [out]; - // } - for (const inner of inners) { - for (const outer of outers) { - if (contains(outer, inner)) { - outer.children.push(inner.ring); - break; - } - } - } - const out = []; - for (const outer of outers) { - out.push([outer.ring].concat(outer.children)); - } - return out; - } - ParseShp.prototype.parsePoint = function (data) { - return { - type: 'Point', - coordinates: this.parseCoord(data, 0) - }; + ParseShp.prototype.parsePoint = function (data) { + return { + type: 'Point', + coordinates: this.parseCoord(data, 0) + }; }; ParseShp.prototype.parseZPoint = function (data) { const pointXY = this.parsePoint(data); - pointXY.coordinates.push(data.readDoubleLE(16)); + pointXY.coordinates.push(data.getFloat64(16, true)); return pointXY; }; ParseShp.prototype.parsePointArray = function (data, offset, num) { @@ -9796,7 +7532,7 @@ ParseShp.prototype.parseZPointArray = function (data, zOffset, num, coordinates) { let i = 0; while (i < num) { - coordinates[i].push(data.readDoubleLE(zOffset)); + coordinates[i].push(data.getFloat64(zOffset, true)); i++; zOffset += 8; } @@ -9814,7 +7550,7 @@ if (done === num) { nextNum = tot; } else { - nextNum = data.readInt32LE(partOffset); + nextNum = data.getInt32(partOffset, true); } pointNumber = nextNum - curNum; if (!pointNumber) { @@ -9836,7 +7572,7 @@ }; ParseShp.prototype.parseMultiPoint = function (data) { const out = {}; - const num = data.readInt32LE(32, true); + const num = data.getInt32(32, true); if (!num) { return null; } @@ -9865,7 +7601,7 @@ } let num; if (geoJson.type === 'Point') { - geoJson.coordinates.push(data.readDoubleLE(72)); + geoJson.coordinates.push(data.getFloat64(72, true)); return geoJson; } else { num = geoJson.coordinates.length; @@ -9876,7 +7612,7 @@ }; ParseShp.prototype.parsePolyline = function (data) { const out = {}; - const numParts = data.readInt32LE(32); + const numParts = data.getInt32(32, true); if (!numParts) { return null; } @@ -9888,7 +7624,7 @@ maxs[0], maxs[1] ]; - const num = data.readInt32LE(36); + const num = data.getInt32(36, true); let offset, partOffset; if (numParts === 1) { out.type = 'LineString'; @@ -9962,12 +7698,12 @@ function makeParseCoord(trans) { if (trans) { return function (data, offset) { - const args = [data.readDoubleLE(offset), data.readDoubleLE(offset + 8)]; + const args = [data.getFloat64(offset, true), data.getFloat64(offset + 8, true)]; return trans.inverse(args); }; } else { return function (data, offset) { - return [data.readDoubleLE(offset), data.readDoubleLE(offset + 8)]; + return [data.getFloat64(offset, true), data.getFloat64(offset + 8, true)]; }; } } @@ -9987,7 +7723,7 @@ num -= 20; } if (!(num in shpFuncObj)) { - throw new Error('I don\'t know that shp type'); + throw new Error(`I don't know shp type "${num}"`); } this.parseFunc = this[shpFuncObj[num]]; this.parseCoord = makeParseCoord(tran); @@ -9996,27 +7732,26 @@ return this.parseHeader().shpCode; }; ParseShp.prototype.parseHeader = function () { - const view = this.buffer.subarray(0, 100); + const view = this.buffer; return { - length: view.readInt32BE(6 << 2) << 1, - version: view.readInt32LE(7 << 2), - shpCode: view.readInt32LE(8 << 2), + length: view.getInt32(6 << 2) << 1, + version: view.getInt32(7 << 2, true), + shpCode: view.getInt32(8 << 2, true), bbox: [ - view.readDoubleLE(9 << 2), - view.readDoubleLE(11 << 2), - view.readDoubleLE(13 << 2), - view.readDoubleLE(15 << 2) + view.getFloat64(9 << 2, true), + view.getFloat64(11 << 2, true), + view.getFloat64(13 << 2, true), + view.getFloat64(15 << 2, true) ] }; }; ParseShp.prototype.getRows = function () { let offset = 100; - const olen = this.buffer.byteLength; - const len = olen - 8; + const len = this.buffer.byteLength - 8; const out = []; let current; while (offset <= len) { - current = this.getRow(offset, olen); + current = this.getRow(offset); if (!current) { break; } @@ -10030,11 +7765,9 @@ } return out; }; - ParseShp.prototype.getRow = function (offset, bufLen) { - const view = this.buffer.subarray(offset, offset + 12); - const len = view.readInt32BE(4) << 1; - const id = view.readInt32BE(0); - + ParseShp.prototype.getRow = function (offset) { + const id = this.buffer.getInt32(offset); + const len = this.buffer.getInt32(offset + 4) << 1; if (len === 0) { return { id: id, @@ -10043,3558 +7776,39 @@ }; } - if (offset + len + 8 > bufLen) { + if (offset + len + 8 > this.buffer.byteLength) { return; } - return { id: id, len: len, - data: this.buffer.subarray(offset + 12, offset + len + 8), - type: view.readInt32LE(8) + data: new DataView(this.buffer.buffer, this.buffer.byteOffset + offset + 12, len - 4), + type: this.buffer.getInt32(offset + 8, true) }; }; function parseShp (buffer, trans) { return new ParseShp(buffer, trans).rows; } - var encoding = {exports: {}}; - - (function (module) { - // This is free and unencumbered software released into the public domain. - // See LICENSE.md for more information. - - /** - * @fileoverview Global |this| required for resolving indexes in node. - * @suppress {globalThis} - */ - (function(global) { - - // If we're in node require encoding-indexes and attach it to the global. - if (module.exports && - !global["encoding-indexes"]) ; - - // - // Utilities - // - - /** - * @param {number} a The number to test. - * @param {number} min The minimum value in the range, inclusive. - * @param {number} max The maximum value in the range, inclusive. - * @return {boolean} True if a >= min and a <= max. - */ - function inRange(a, min, max) { - return min <= a && a <= max; - } - - /** - * @param {!Array.<*>} array The array to check. - * @param {*} item The item to look for in the array. - * @return {boolean} True if the item appears in the array. - */ - function includes(array, item) { - return array.indexOf(item) !== -1; - } - - var floor = Math.floor; - - /** - * @param {*} o - * @return {Object} - */ - function ToDictionary(o) { - if (o === undefined) return {}; - if (o === Object(o)) return o; - throw TypeError('Could not convert argument to dictionary'); - } - - /** - * @param {string} string Input string of UTF-16 code units. - * @return {!Array.} Code points. - */ - function stringToCodePoints(string) { - // https://heycam.github.io/webidl/#dfn-obtain-unicode - - // 1. Let S be the DOMString value. - var s = String(string); - - // 2. Let n be the length of S. - var n = s.length; - - // 3. Initialize i to 0. - var i = 0; - - // 4. Initialize U to be an empty sequence of Unicode characters. - var u = []; - - // 5. While i < n: - while (i < n) { - - // 1. Let c be the code unit in S at index i. - var c = s.charCodeAt(i); - - // 2. Depending on the value of c: - - // c < 0xD800 or c > 0xDFFF - if (c < 0xD800 || c > 0xDFFF) { - // Append to U the Unicode character with code point c. - u.push(c); - } - - // 0xDC00 ≤ c ≤ 0xDFFF - else if (0xDC00 <= c && c <= 0xDFFF) { - // Append to U a U+FFFD REPLACEMENT CHARACTER. - u.push(0xFFFD); - } - - // 0xD800 ≤ c ≤ 0xDBFF - else if (0xD800 <= c && c <= 0xDBFF) { - // 1. If i = n−1, then append to U a U+FFFD REPLACEMENT - // CHARACTER. - if (i === n - 1) { - u.push(0xFFFD); - } - // 2. Otherwise, i < n−1: - else { - // 1. Let d be the code unit in S at index i+1. - var d = s.charCodeAt(i + 1); - - // 2. If 0xDC00 ≤ d ≤ 0xDFFF, then: - if (0xDC00 <= d && d <= 0xDFFF) { - // 1. Let a be c & 0x3FF. - var a = c & 0x3FF; - - // 2. Let b be d & 0x3FF. - var b = d & 0x3FF; - - // 3. Append to U the Unicode character with code point - // 2^16+2^10*a+b. - u.push(0x10000 + (a << 10) + b); - - // 4. Set i to i+1. - i += 1; - } - - // 3. Otherwise, d < 0xDC00 or d > 0xDFFF. Append to U a - // U+FFFD REPLACEMENT CHARACTER. - else { - u.push(0xFFFD); - } - } - } - - // 3. Set i to i+1. - i += 1; - } - - // 6. Return U. - return u; - } - - /** - * @param {!Array.} code_points Array of code points. - * @return {string} string String of UTF-16 code units. - */ - function codePointsToString(code_points) { - var s = ''; - for (var i = 0; i < code_points.length; ++i) { - var cp = code_points[i]; - if (cp <= 0xFFFF) { - s += String.fromCharCode(cp); - } else { - cp -= 0x10000; - s += String.fromCharCode((cp >> 10) + 0xD800, - (cp & 0x3FF) + 0xDC00); - } - } - return s; - } - - - // - // Implementation of Encoding specification - // https://encoding.spec.whatwg.org/ - // - - // - // 4. Terminology - // - - /** - * An ASCII byte is a byte in the range 0x00 to 0x7F, inclusive. - * @param {number} a The number to test. - * @return {boolean} True if a is in the range 0x00 to 0x7F, inclusive. - */ - function isASCIIByte(a) { - return 0x00 <= a && a <= 0x7F; - } - - /** - * An ASCII code point is a code point in the range U+0000 to - * U+007F, inclusive. - */ - var isASCIICodePoint = isASCIIByte; - - - /** - * End-of-stream is a special token that signifies no more tokens - * are in the stream. - * @const - */ var end_of_stream = -1; - - /** - * A stream represents an ordered sequence of tokens. - * - * @constructor - * @param {!(Array.|Uint8Array)} tokens Array of tokens that provide - * the stream. - */ - function Stream(tokens) { - /** @type {!Array.} */ - this.tokens = [].slice.call(tokens); - // Reversed as push/pop is more efficient than shift/unshift. - this.tokens.reverse(); - } - - Stream.prototype = { - /** - * @return {boolean} True if end-of-stream has been hit. - */ - endOfStream: function() { - return !this.tokens.length; - }, - - /** - * When a token is read from a stream, the first token in the - * stream must be returned and subsequently removed, and - * end-of-stream must be returned otherwise. - * - * @return {number} Get the next token from the stream, or - * end_of_stream. - */ - read: function() { - if (!this.tokens.length) - return end_of_stream; - return this.tokens.pop(); - }, - - /** - * When one or more tokens are prepended to a stream, those tokens - * must be inserted, in given order, before the first token in the - * stream. - * - * @param {(number|!Array.)} token The token(s) to prepend to the - * stream. - */ - prepend: function(token) { - if (Array.isArray(token)) { - var tokens = /**@type {!Array.}*/(token); - while (tokens.length) - this.tokens.push(tokens.pop()); - } else { - this.tokens.push(token); - } - }, - - /** - * When one or more tokens are pushed to a stream, those tokens - * must be inserted, in given order, after the last token in the - * stream. - * - * @param {(number|!Array.)} token The tokens(s) to push to the - * stream. - */ - push: function(token) { - if (Array.isArray(token)) { - var tokens = /**@type {!Array.}*/(token); - while (tokens.length) - this.tokens.unshift(tokens.shift()); - } else { - this.tokens.unshift(token); - } - } - }; - - // - // 5. Encodings - // - - // 5.1 Encoders and decoders - - /** @const */ - var finished = -1; - - /** - * @param {boolean} fatal If true, decoding errors raise an exception. - * @param {number=} opt_code_point Override the standard fallback code point. - * @return {number} The code point to insert on a decoding error. - */ - function decoderError(fatal, opt_code_point) { - if (fatal) - throw TypeError('Decoder error'); - return opt_code_point || 0xFFFD; - } - - /** - * @param {number} code_point The code point that could not be encoded. - * @return {number} Always throws, no value is actually returned. - */ - function encoderError(code_point) { - throw TypeError('The code point ' + code_point + ' could not be encoded.'); - } - - // 5.2 Names and labels - - // TODO: Define @typedef for Encoding: {name:string,labels:Array.} - // https://github.com/google/closure-compiler/issues/247 - - /** - * @param {string} label The encoding label. - * @return {?{name:string,labels:Array.}} - */ - function getEncoding(label) { - // 1. Remove any leading and trailing ASCII whitespace from label. - label = String(label).trim().toLowerCase(); - - // 2. If label is an ASCII case-insensitive match for any of the - // labels listed in the table below, return the corresponding - // encoding, and failure otherwise. - if (Object.prototype.hasOwnProperty.call(label_to_encoding, label)) { - return label_to_encoding[label]; - } - return null; - } - - /** - * Encodings table: https://encoding.spec.whatwg.org/encodings.json - * @const - * @type {!Array.<{ - * heading: string, - * encodings: Array.<{name:string,labels:Array.}> - * }>} - */ - var encodings = [ - { - "encodings": [ - { - "labels": [ - "unicode-1-1-utf-8", - "utf-8", - "utf8" - ], - "name": "UTF-8" - } - ], - "heading": "The Encoding" - }, - { - "encodings": [ - { - "labels": [ - "866", - "cp866", - "csibm866", - "ibm866" - ], - "name": "IBM866" - }, - { - "labels": [ - "csisolatin2", - "iso-8859-2", - "iso-ir-101", - "iso8859-2", - "iso88592", - "iso_8859-2", - "iso_8859-2:1987", - "l2", - "latin2" - ], - "name": "ISO-8859-2" - }, - { - "labels": [ - "csisolatin3", - "iso-8859-3", - "iso-ir-109", - "iso8859-3", - "iso88593", - "iso_8859-3", - "iso_8859-3:1988", - "l3", - "latin3" - ], - "name": "ISO-8859-3" - }, - { - "labels": [ - "csisolatin4", - "iso-8859-4", - "iso-ir-110", - "iso8859-4", - "iso88594", - "iso_8859-4", - "iso_8859-4:1988", - "l4", - "latin4" - ], - "name": "ISO-8859-4" - }, - { - "labels": [ - "csisolatincyrillic", - "cyrillic", - "iso-8859-5", - "iso-ir-144", - "iso8859-5", - "iso88595", - "iso_8859-5", - "iso_8859-5:1988" - ], - "name": "ISO-8859-5" - }, - { - "labels": [ - "arabic", - "asmo-708", - "csiso88596e", - "csiso88596i", - "csisolatinarabic", - "ecma-114", - "iso-8859-6", - "iso-8859-6-e", - "iso-8859-6-i", - "iso-ir-127", - "iso8859-6", - "iso88596", - "iso_8859-6", - "iso_8859-6:1987" - ], - "name": "ISO-8859-6" - }, - { - "labels": [ - "csisolatingreek", - "ecma-118", - "elot_928", - "greek", - "greek8", - "iso-8859-7", - "iso-ir-126", - "iso8859-7", - "iso88597", - "iso_8859-7", - "iso_8859-7:1987", - "sun_eu_greek" - ], - "name": "ISO-8859-7" - }, - { - "labels": [ - "csiso88598e", - "csisolatinhebrew", - "hebrew", - "iso-8859-8", - "iso-8859-8-e", - "iso-ir-138", - "iso8859-8", - "iso88598", - "iso_8859-8", - "iso_8859-8:1988", - "visual" - ], - "name": "ISO-8859-8" - }, - { - "labels": [ - "csiso88598i", - "iso-8859-8-i", - "logical" - ], - "name": "ISO-8859-8-I" - }, - { - "labels": [ - "csisolatin6", - "iso-8859-10", - "iso-ir-157", - "iso8859-10", - "iso885910", - "l6", - "latin6" - ], - "name": "ISO-8859-10" - }, - { - "labels": [ - "iso-8859-13", - "iso8859-13", - "iso885913" - ], - "name": "ISO-8859-13" - }, - { - "labels": [ - "iso-8859-14", - "iso8859-14", - "iso885914" - ], - "name": "ISO-8859-14" - }, - { - "labels": [ - "csisolatin9", - "iso-8859-15", - "iso8859-15", - "iso885915", - "iso_8859-15", - "l9" - ], - "name": "ISO-8859-15" - }, - { - "labels": [ - "iso-8859-16" - ], - "name": "ISO-8859-16" - }, - { - "labels": [ - "cskoi8r", - "koi", - "koi8", - "koi8-r", - "koi8_r" - ], - "name": "KOI8-R" - }, - { - "labels": [ - "koi8-ru", - "koi8-u" - ], - "name": "KOI8-U" - }, - { - "labels": [ - "csmacintosh", - "mac", - "macintosh", - "x-mac-roman" - ], - "name": "macintosh" - }, - { - "labels": [ - "dos-874", - "iso-8859-11", - "iso8859-11", - "iso885911", - "tis-620", - "windows-874" - ], - "name": "windows-874" - }, - { - "labels": [ - "cp1250", - "windows-1250", - "x-cp1250" - ], - "name": "windows-1250" - }, - { - "labels": [ - "cp1251", - "windows-1251", - "x-cp1251" - ], - "name": "windows-1251" - }, - { - "labels": [ - "ansi_x3.4-1968", - "ascii", - "cp1252", - "cp819", - "csisolatin1", - "ibm819", - "iso-8859-1", - "iso-ir-100", - "iso8859-1", - "iso88591", - "iso_8859-1", - "iso_8859-1:1987", - "l1", - "latin1", - "us-ascii", - "windows-1252", - "x-cp1252" - ], - "name": "windows-1252" - }, - { - "labels": [ - "cp1253", - "windows-1253", - "x-cp1253" - ], - "name": "windows-1253" - }, - { - "labels": [ - "cp1254", - "csisolatin5", - "iso-8859-9", - "iso-ir-148", - "iso8859-9", - "iso88599", - "iso_8859-9", - "iso_8859-9:1989", - "l5", - "latin5", - "windows-1254", - "x-cp1254" - ], - "name": "windows-1254" - }, - { - "labels": [ - "cp1255", - "windows-1255", - "x-cp1255" - ], - "name": "windows-1255" - }, - { - "labels": [ - "cp1256", - "windows-1256", - "x-cp1256" - ], - "name": "windows-1256" - }, - { - "labels": [ - "cp1257", - "windows-1257", - "x-cp1257" - ], - "name": "windows-1257" - }, - { - "labels": [ - "cp1258", - "windows-1258", - "x-cp1258" - ], - "name": "windows-1258" - }, - { - "labels": [ - "x-mac-cyrillic", - "x-mac-ukrainian" - ], - "name": "x-mac-cyrillic" - } - ], - "heading": "Legacy single-byte encodings" - }, - { - "encodings": [ - { - "labels": [ - "chinese", - "csgb2312", - "csiso58gb231280", - "gb2312", - "gb_2312", - "gb_2312-80", - "gbk", - "iso-ir-58", - "x-gbk" - ], - "name": "GBK" - }, - { - "labels": [ - "gb18030" - ], - "name": "gb18030" - } - ], - "heading": "Legacy multi-byte Chinese (simplified) encodings" - }, - { - "encodings": [ - { - "labels": [ - "big5", - "big5-hkscs", - "cn-big5", - "csbig5", - "x-x-big5" - ], - "name": "Big5" - } - ], - "heading": "Legacy multi-byte Chinese (traditional) encodings" - }, - { - "encodings": [ - { - "labels": [ - "cseucpkdfmtjapanese", - "euc-jp", - "x-euc-jp" - ], - "name": "EUC-JP" - }, - { - "labels": [ - "csiso2022jp", - "iso-2022-jp" - ], - "name": "ISO-2022-JP" - }, - { - "labels": [ - "csshiftjis", - "ms932", - "ms_kanji", - "shift-jis", - "shift_jis", - "sjis", - "windows-31j", - "x-sjis" - ], - "name": "Shift_JIS" - } - ], - "heading": "Legacy multi-byte Japanese encodings" - }, - { - "encodings": [ - { - "labels": [ - "cseuckr", - "csksc56011987", - "euc-kr", - "iso-ir-149", - "korean", - "ks_c_5601-1987", - "ks_c_5601-1989", - "ksc5601", - "ksc_5601", - "windows-949" - ], - "name": "EUC-KR" - } - ], - "heading": "Legacy multi-byte Korean encodings" - }, - { - "encodings": [ - { - "labels": [ - "csiso2022kr", - "hz-gb-2312", - "iso-2022-cn", - "iso-2022-cn-ext", - "iso-2022-kr" - ], - "name": "replacement" - }, - { - "labels": [ - "utf-16be" - ], - "name": "UTF-16BE" - }, - { - "labels": [ - "utf-16", - "utf-16le" - ], - "name": "UTF-16LE" - }, - { - "labels": [ - "x-user-defined" - ], - "name": "x-user-defined" - } - ], - "heading": "Legacy miscellaneous encodings" - } - ]; - - // Label to encoding registry. - /** @type {Object.}>} */ - var label_to_encoding = {}; - encodings.forEach(function(category) { - category.encodings.forEach(function(encoding) { - encoding.labels.forEach(function(label) { - label_to_encoding[label] = encoding; - }); - }); - }); - - // Registry of of encoder/decoder factories, by encoding name. - /** @type {Object.} */ - var encoders = {}; - /** @type {Object.} */ - var decoders = {}; - - // - // 6. Indexes - // - - /** - * @param {number} pointer The |pointer| to search for. - * @param {(!Array.|undefined)} index The |index| to search within. - * @return {?number} The code point corresponding to |pointer| in |index|, - * or null if |code point| is not in |index|. - */ - function indexCodePointFor(pointer, index) { - if (!index) return null; - return index[pointer] || null; - } - - /** - * @param {number} code_point The |code point| to search for. - * @param {!Array.} index The |index| to search within. - * @return {?number} The first pointer corresponding to |code point| in - * |index|, or null if |code point| is not in |index|. - */ - function indexPointerFor(code_point, index) { - var pointer = index.indexOf(code_point); - return pointer === -1 ? null : pointer; - } - - /** - * @param {string} name Name of the index. - * @return {(!Array.|!Array.>)} - * */ - function index(name) { - if (!('encoding-indexes' in global)) { - throw Error("Indexes missing." + - " Did you forget to include encoding-indexes.js first?"); - } - return global['encoding-indexes'][name]; - } - - /** - * @param {number} pointer The |pointer| to search for in the gb18030 index. - * @return {?number} The code point corresponding to |pointer| in |index|, - * or null if |code point| is not in the gb18030 index. - */ - function indexGB18030RangesCodePointFor(pointer) { - // 1. If pointer is greater than 39419 and less than 189000, or - // pointer is greater than 1237575, return null. - if ((pointer > 39419 && pointer < 189000) || (pointer > 1237575)) - return null; - - // 2. If pointer is 7457, return code point U+E7C7. - if (pointer === 7457) return 0xE7C7; - - // 3. Let offset be the last pointer in index gb18030 ranges that - // is equal to or less than pointer and let code point offset be - // its corresponding code point. - var offset = 0; - var code_point_offset = 0; - var idx = index('gb18030-ranges'); - var i; - for (i = 0; i < idx.length; ++i) { - /** @type {!Array.} */ - var entry = idx[i]; - if (entry[0] <= pointer) { - offset = entry[0]; - code_point_offset = entry[1]; - } else { - break; - } - } - - // 4. Return a code point whose value is code point offset + - // pointer − offset. - return code_point_offset + pointer - offset; - } - - /** - * @param {number} code_point The |code point| to locate in the gb18030 index. - * @return {number} The first pointer corresponding to |code point| in the - * gb18030 index. - */ - function indexGB18030RangesPointerFor(code_point) { - // 1. If code point is U+E7C7, return pointer 7457. - if (code_point === 0xE7C7) return 7457; - - // 2. Let offset be the last code point in index gb18030 ranges - // that is equal to or less than code point and let pointer offset - // be its corresponding pointer. - var offset = 0; - var pointer_offset = 0; - var idx = index('gb18030-ranges'); - var i; - for (i = 0; i < idx.length; ++i) { - /** @type {!Array.} */ - var entry = idx[i]; - if (entry[1] <= code_point) { - offset = entry[1]; - pointer_offset = entry[0]; - } else { - break; - } - } - - // 3. Return a pointer whose value is pointer offset + code point - // − offset. - return pointer_offset + code_point - offset; - } - - /** - * @param {number} code_point The |code_point| to search for in the Shift_JIS - * index. - * @return {?number} The code point corresponding to |pointer| in |index|, - * or null if |code point| is not in the Shift_JIS index. - */ - function indexShiftJISPointerFor(code_point) { - // 1. Let index be index jis0208 excluding all entries whose - // pointer is in the range 8272 to 8835, inclusive. - shift_jis_index = shift_jis_index || - index('jis0208').map(function(code_point, pointer) { - return inRange(pointer, 8272, 8835) ? null : code_point; - }); - var index_ = shift_jis_index; - - // 2. Return the index pointer for code point in index. - return index_.indexOf(code_point); - } - var shift_jis_index; - - /** - * @param {number} code_point The |code_point| to search for in the big5 - * index. - * @return {?number} The code point corresponding to |pointer| in |index|, - * or null if |code point| is not in the big5 index. - */ - function indexBig5PointerFor(code_point) { - // 1. Let index be index Big5 excluding all entries whose pointer - big5_index_no_hkscs = big5_index_no_hkscs || - index('big5').map(function(code_point, pointer) { - return (pointer < (0xA1 - 0x81) * 157) ? null : code_point; - }); - var index_ = big5_index_no_hkscs; - - // 2. If code point is U+2550, U+255E, U+2561, U+256A, U+5341, or - // U+5345, return the last pointer corresponding to code point in - // index. - if (code_point === 0x2550 || code_point === 0x255E || - code_point === 0x2561 || code_point === 0x256A || - code_point === 0x5341 || code_point === 0x5345) { - return index_.lastIndexOf(code_point); - } - - // 3. Return the index pointer for code point in index. - return indexPointerFor(code_point, index_); - } - var big5_index_no_hkscs; - - // - // 8. API - // - - /** @const */ var DEFAULT_ENCODING = 'utf-8'; - - // 8.1 Interface TextDecoder - - /** - * @constructor - * @param {string=} label The label of the encoding; - * defaults to 'utf-8'. - * @param {Object=} options - */ - function TextDecoder(label, options) { - // Web IDL conventions - if (!(this instanceof TextDecoder)) - throw TypeError('Called as a function. Did you forget \'new\'?'); - label = label !== undefined ? String(label) : DEFAULT_ENCODING; - options = ToDictionary(options); - - // A TextDecoder object has an associated encoding, decoder, - // stream, ignore BOM flag (initially unset), BOM seen flag - // (initially unset), error mode (initially replacement), and do - // not flush flag (initially unset). - - /** @private */ - this._encoding = null; - /** @private @type {?Decoder} */ - this._decoder = null; - /** @private @type {boolean} */ - this._ignoreBOM = false; - /** @private @type {boolean} */ - this._BOMseen = false; - /** @private @type {string} */ - this._error_mode = 'replacement'; - /** @private @type {boolean} */ - this._do_not_flush = false; - - - // 1. Let encoding be the result of getting an encoding from - // label. - var encoding = getEncoding(label); - - // 2. If encoding is failure or replacement, throw a RangeError. - if (encoding === null || encoding.name === 'replacement') - throw RangeError('Unknown encoding: ' + label); - if (!decoders[encoding.name]) { - throw Error('Decoder not present.' + - ' Did you forget to include encoding-indexes.js first?'); - } - - // 3. Let dec be a new TextDecoder object. - var dec = this; - - // 4. Set dec's encoding to encoding. - dec._encoding = encoding; - - // 5. If options's fatal member is true, set dec's error mode to - // fatal. - if (Boolean(options['fatal'])) - dec._error_mode = 'fatal'; - - // 6. If options's ignoreBOM member is true, set dec's ignore BOM - // flag. - if (Boolean(options['ignoreBOM'])) - dec._ignoreBOM = true; - - // For pre-ES5 runtimes: - if (!Object.defineProperty) { - this.encoding = dec._encoding.name.toLowerCase(); - this.fatal = dec._error_mode === 'fatal'; - this.ignoreBOM = dec._ignoreBOM; - } - - // 7. Return dec. - return dec; - } - - if (Object.defineProperty) { - // The encoding attribute's getter must return encoding's name. - Object.defineProperty(TextDecoder.prototype, 'encoding', { - /** @this {TextDecoder} */ - get: function() { return this._encoding.name.toLowerCase(); } - }); - - // The fatal attribute's getter must return true if error mode - // is fatal, and false otherwise. - Object.defineProperty(TextDecoder.prototype, 'fatal', { - /** @this {TextDecoder} */ - get: function() { return this._error_mode === 'fatal'; } - }); - - // The ignoreBOM attribute's getter must return true if ignore - // BOM flag is set, and false otherwise. - Object.defineProperty(TextDecoder.prototype, 'ignoreBOM', { - /** @this {TextDecoder} */ - get: function() { return this._ignoreBOM; } - }); - } - - /** - * @param {BufferSource=} input The buffer of bytes to decode. - * @param {Object=} options - * @return {string} The decoded string. - */ - TextDecoder.prototype.decode = function decode(input, options) { - var bytes; - if (typeof input === 'object' && input instanceof ArrayBuffer) { - bytes = new Uint8Array(input); - } else if (typeof input === 'object' && 'buffer' in input && - input.buffer instanceof ArrayBuffer) { - bytes = new Uint8Array(input.buffer, - input.byteOffset, - input.byteLength); - } else { - bytes = new Uint8Array(0); - } - - options = ToDictionary(options); - - // 1. If the do not flush flag is unset, set decoder to a new - // encoding's decoder, set stream to a new stream, and unset the - // BOM seen flag. - if (!this._do_not_flush) { - this._decoder = decoders[this._encoding.name]({ - fatal: this._error_mode === 'fatal'}); - this._BOMseen = false; - } - - // 2. If options's stream is true, set the do not flush flag, and - // unset the do not flush flag otherwise. - this._do_not_flush = Boolean(options['stream']); - - // 3. If input is given, push a copy of input to stream. - // TODO: Align with spec algorithm - maintain stream on instance. - var input_stream = new Stream(bytes); - - // 4. Let output be a new stream. - var output = []; - - /** @type {?(number|!Array.)} */ - var result; - - // 5. While true: - while (true) { - // 1. Let token be the result of reading from stream. - var token = input_stream.read(); - - // 2. If token is end-of-stream and the do not flush flag is - // set, return output, serialized. - // TODO: Align with spec algorithm. - if (token === end_of_stream) - break; - - // 3. Otherwise, run these subsubsteps: - - // 1. Let result be the result of processing token for decoder, - // stream, output, and error mode. - result = this._decoder.handler(input_stream, token); - - // 2. If result is finished, return output, serialized. - if (result === finished) - break; - - if (result !== null) { - if (Array.isArray(result)) - output.push.apply(output, /**@type {!Array.}*/(result)); - else - output.push(result); - } - - // 3. Otherwise, if result is error, throw a TypeError. - // (Thrown in handler) - - // 4. Otherwise, do nothing. - } - // TODO: Align with spec algorithm. - if (!this._do_not_flush) { - do { - result = this._decoder.handler(input_stream, input_stream.read()); - if (result === finished) - break; - if (result === null) - continue; - if (Array.isArray(result)) - output.push.apply(output, /**@type {!Array.}*/(result)); - else - output.push(result); - } while (!input_stream.endOfStream()); - this._decoder = null; - } - - // A TextDecoder object also has an associated serialize stream - // algorithm... - /** - * @param {!Array.} stream - * @return {string} - * @this {TextDecoder} - */ - function serializeStream(stream) { - // 1. Let token be the result of reading from stream. - // (Done in-place on array, rather than as a stream) - - // 2. If encoding is UTF-8, UTF-16BE, or UTF-16LE, and ignore - // BOM flag and BOM seen flag are unset, run these subsubsteps: - if (includes(['UTF-8', 'UTF-16LE', 'UTF-16BE'], this._encoding.name) && - !this._ignoreBOM && !this._BOMseen) { - if (stream.length > 0 && stream[0] === 0xFEFF) { - // 1. If token is U+FEFF, set BOM seen flag. - this._BOMseen = true; - stream.shift(); - } else if (stream.length > 0) { - // 2. Otherwise, if token is not end-of-stream, set BOM seen - // flag and append token to stream. - this._BOMseen = true; - } else ; - } - // 4. Otherwise, return output. - return codePointsToString(stream); - } - - return serializeStream.call(this, output); - }; - - // 8.2 Interface TextEncoder - - /** - * @constructor - * @param {string=} label The label of the encoding. NONSTANDARD. - * @param {Object=} options NONSTANDARD. - */ - function TextEncoder(label, options) { - // Web IDL conventions - if (!(this instanceof TextEncoder)) - throw TypeError('Called as a function. Did you forget \'new\'?'); - options = ToDictionary(options); - - // A TextEncoder object has an associated encoding and encoder. - - /** @private */ - this._encoding = null; - /** @private @type {?Encoder} */ - this._encoder = null; - - // Non-standard - /** @private @type {boolean} */ - this._do_not_flush = false; - /** @private @type {string} */ - this._fatal = Boolean(options['fatal']) ? 'fatal' : 'replacement'; - - // 1. Let enc be a new TextEncoder object. - var enc = this; - - // 2. Set enc's encoding to UTF-8's encoder. - if (Boolean(options['NONSTANDARD_allowLegacyEncoding'])) { - // NONSTANDARD behavior. - label = label !== undefined ? String(label) : DEFAULT_ENCODING; - var encoding = getEncoding(label); - if (encoding === null || encoding.name === 'replacement') - throw RangeError('Unknown encoding: ' + label); - if (!encoders[encoding.name]) { - throw Error('Encoder not present.' + - ' Did you forget to include encoding-indexes.js first?'); - } - enc._encoding = encoding; - } else { - // Standard behavior. - enc._encoding = getEncoding('utf-8'); - - if (label !== undefined && 'console' in global) { - console.warn('TextEncoder constructor called with encoding label, ' - + 'which is ignored.'); - } - } - - // For pre-ES5 runtimes: - if (!Object.defineProperty) - this.encoding = enc._encoding.name.toLowerCase(); - - // 3. Return enc. - return enc; - } - - if (Object.defineProperty) { - // The encoding attribute's getter must return encoding's name. - Object.defineProperty(TextEncoder.prototype, 'encoding', { - /** @this {TextEncoder} */ - get: function() { return this._encoding.name.toLowerCase(); } - }); - } - - /** - * @param {string=} opt_string The string to encode. - * @param {Object=} options - * @return {!Uint8Array} Encoded bytes, as a Uint8Array. - */ - TextEncoder.prototype.encode = function encode(opt_string, options) { - opt_string = opt_string === undefined ? '' : String(opt_string); - options = ToDictionary(options); - - // NOTE: This option is nonstandard. None of the encodings - // permitted for encoding (i.e. UTF-8, UTF-16) are stateful when - // the input is a USVString so streaming is not necessary. - if (!this._do_not_flush) - this._encoder = encoders[this._encoding.name]({ - fatal: this._fatal === 'fatal'}); - this._do_not_flush = Boolean(options['stream']); - - // 1. Convert input to a stream. - var input = new Stream(stringToCodePoints(opt_string)); - - // 2. Let output be a new stream - var output = []; - - /** @type {?(number|!Array.)} */ - var result; - // 3. While true, run these substeps: - while (true) { - // 1. Let token be the result of reading from input. - var token = input.read(); - if (token === end_of_stream) - break; - // 2. Let result be the result of processing token for encoder, - // input, output. - result = this._encoder.handler(input, token); - if (result === finished) - break; - if (Array.isArray(result)) - output.push.apply(output, /**@type {!Array.}*/(result)); - else - output.push(result); - } - // TODO: Align with spec algorithm. - if (!this._do_not_flush) { - while (true) { - result = this._encoder.handler(input, input.read()); - if (result === finished) - break; - if (Array.isArray(result)) - output.push.apply(output, /**@type {!Array.}*/(result)); - else - output.push(result); - } - this._encoder = null; - } - // 3. If result is finished, convert output into a byte sequence, - // and then return a Uint8Array object wrapping an ArrayBuffer - // containing output. - return new Uint8Array(output); - }; - - - // - // 9. The encoding - // - - // 9.1 utf-8 - - // 9.1.1 utf-8 decoder - /** - * @constructor - * @implements {Decoder} - * @param {{fatal: boolean}} options - */ - function UTF8Decoder(options) { - var fatal = options.fatal; - - // utf-8's decoder's has an associated utf-8 code point, utf-8 - // bytes seen, and utf-8 bytes needed (all initially 0), a utf-8 - // lower boundary (initially 0x80), and a utf-8 upper boundary - // (initially 0xBF). - var /** @type {number} */ utf8_code_point = 0, - /** @type {number} */ utf8_bytes_seen = 0, - /** @type {number} */ utf8_bytes_needed = 0, - /** @type {number} */ utf8_lower_boundary = 0x80, - /** @type {number} */ utf8_upper_boundary = 0xBF; - - /** - * @param {Stream} stream The stream of bytes being decoded. - * @param {number} bite The next byte read from the stream. - * @return {?(number|!Array.)} The next code point(s) - * decoded, or null if not enough data exists in the input - * stream to decode a complete code point. - */ - this.handler = function(stream, bite) { - // 1. If byte is end-of-stream and utf-8 bytes needed is not 0, - // set utf-8 bytes needed to 0 and return error. - if (bite === end_of_stream && utf8_bytes_needed !== 0) { - utf8_bytes_needed = 0; - return decoderError(fatal); - } - - // 2. If byte is end-of-stream, return finished. - if (bite === end_of_stream) - return finished; - - // 3. If utf-8 bytes needed is 0, based on byte: - if (utf8_bytes_needed === 0) { - - // 0x00 to 0x7F - if (inRange(bite, 0x00, 0x7F)) { - // Return a code point whose value is byte. - return bite; - } - - // 0xC2 to 0xDF - else if (inRange(bite, 0xC2, 0xDF)) { - // 1. Set utf-8 bytes needed to 1. - utf8_bytes_needed = 1; - - // 2. Set UTF-8 code point to byte & 0x1F. - utf8_code_point = bite & 0x1F; - } - - // 0xE0 to 0xEF - else if (inRange(bite, 0xE0, 0xEF)) { - // 1. If byte is 0xE0, set utf-8 lower boundary to 0xA0. - if (bite === 0xE0) - utf8_lower_boundary = 0xA0; - // 2. If byte is 0xED, set utf-8 upper boundary to 0x9F. - if (bite === 0xED) - utf8_upper_boundary = 0x9F; - // 3. Set utf-8 bytes needed to 2. - utf8_bytes_needed = 2; - // 4. Set UTF-8 code point to byte & 0xF. - utf8_code_point = bite & 0xF; - } - - // 0xF0 to 0xF4 - else if (inRange(bite, 0xF0, 0xF4)) { - // 1. If byte is 0xF0, set utf-8 lower boundary to 0x90. - if (bite === 0xF0) - utf8_lower_boundary = 0x90; - // 2. If byte is 0xF4, set utf-8 upper boundary to 0x8F. - if (bite === 0xF4) - utf8_upper_boundary = 0x8F; - // 3. Set utf-8 bytes needed to 3. - utf8_bytes_needed = 3; - // 4. Set UTF-8 code point to byte & 0x7. - utf8_code_point = bite & 0x7; - } - - // Otherwise - else { - // Return error. - return decoderError(fatal); - } - - // Return continue. - return null; - } - - // 4. If byte is not in the range utf-8 lower boundary to utf-8 - // upper boundary, inclusive, run these substeps: - if (!inRange(bite, utf8_lower_boundary, utf8_upper_boundary)) { - - // 1. Set utf-8 code point, utf-8 bytes needed, and utf-8 - // bytes seen to 0, set utf-8 lower boundary to 0x80, and set - // utf-8 upper boundary to 0xBF. - utf8_code_point = utf8_bytes_needed = utf8_bytes_seen = 0; - utf8_lower_boundary = 0x80; - utf8_upper_boundary = 0xBF; - - // 2. Prepend byte to stream. - stream.prepend(bite); - - // 3. Return error. - return decoderError(fatal); - } - - // 5. Set utf-8 lower boundary to 0x80 and utf-8 upper boundary - // to 0xBF. - utf8_lower_boundary = 0x80; - utf8_upper_boundary = 0xBF; - - // 6. Set UTF-8 code point to (UTF-8 code point << 6) | (byte & - // 0x3F) - utf8_code_point = (utf8_code_point << 6) | (bite & 0x3F); - - // 7. Increase utf-8 bytes seen by one. - utf8_bytes_seen += 1; - - // 8. If utf-8 bytes seen is not equal to utf-8 bytes needed, - // continue. - if (utf8_bytes_seen !== utf8_bytes_needed) - return null; - - // 9. Let code point be utf-8 code point. - var code_point = utf8_code_point; - - // 10. Set utf-8 code point, utf-8 bytes needed, and utf-8 bytes - // seen to 0. - utf8_code_point = utf8_bytes_needed = utf8_bytes_seen = 0; - - // 11. Return a code point whose value is code point. - return code_point; - }; - } - - // 9.1.2 utf-8 encoder - /** - * @constructor - * @implements {Encoder} - * @param {{fatal: boolean}} options - */ - function UTF8Encoder(options) { - options.fatal; - /** - * @param {Stream} stream Input stream. - * @param {number} code_point Next code point read from the stream. - * @return {(number|!Array.)} Byte(s) to emit. - */ - this.handler = function(stream, code_point) { - // 1. If code point is end-of-stream, return finished. - if (code_point === end_of_stream) - return finished; - - // 2. If code point is an ASCII code point, return a byte whose - // value is code point. - if (isASCIICodePoint(code_point)) - return code_point; - - // 3. Set count and offset based on the range code point is in: - var count, offset; - // U+0080 to U+07FF, inclusive: - if (inRange(code_point, 0x0080, 0x07FF)) { - // 1 and 0xC0 - count = 1; - offset = 0xC0; - } - // U+0800 to U+FFFF, inclusive: - else if (inRange(code_point, 0x0800, 0xFFFF)) { - // 2 and 0xE0 - count = 2; - offset = 0xE0; - } - // U+10000 to U+10FFFF, inclusive: - else if (inRange(code_point, 0x10000, 0x10FFFF)) { - // 3 and 0xF0 - count = 3; - offset = 0xF0; - } - - // 4. Let bytes be a byte sequence whose first byte is (code - // point >> (6 × count)) + offset. - var bytes = [(code_point >> (6 * count)) + offset]; - - // 5. Run these substeps while count is greater than 0: - while (count > 0) { - - // 1. Set temp to code point >> (6 × (count − 1)). - var temp = code_point >> (6 * (count - 1)); - - // 2. Append to bytes 0x80 | (temp & 0x3F). - bytes.push(0x80 | (temp & 0x3F)); - - // 3. Decrease count by one. - count -= 1; - } - - // 6. Return bytes bytes, in order. - return bytes; - }; - } - - /** @param {{fatal: boolean}} options */ - encoders['UTF-8'] = function(options) { - return new UTF8Encoder(options); - }; - /** @param {{fatal: boolean}} options */ - decoders['UTF-8'] = function(options) { - return new UTF8Decoder(options); - }; - - // - // 10. Legacy single-byte encodings - // - - // 10.1 single-byte decoder - /** - * @constructor - * @implements {Decoder} - * @param {!Array.} index The encoding index. - * @param {{fatal: boolean}} options - */ - function SingleByteDecoder(index, options) { - var fatal = options.fatal; - /** - * @param {Stream} stream The stream of bytes being decoded. - * @param {number} bite The next byte read from the stream. - * @return {?(number|!Array.)} The next code point(s) - * decoded, or null if not enough data exists in the input - * stream to decode a complete code point. - */ - this.handler = function(stream, bite) { - // 1. If byte is end-of-stream, return finished. - if (bite === end_of_stream) - return finished; - - // 2. If byte is an ASCII byte, return a code point whose value - // is byte. - if (isASCIIByte(bite)) - return bite; - - // 3. Let code point be the index code point for byte − 0x80 in - // index single-byte. - var code_point = index[bite - 0x80]; - - // 4. If code point is null, return error. - if (code_point === null) - return decoderError(fatal); - - // 5. Return a code point whose value is code point. - return code_point; - }; - } - - // 10.2 single-byte encoder - /** - * @constructor - * @implements {Encoder} - * @param {!Array.} index The encoding index. - * @param {{fatal: boolean}} options - */ - function SingleByteEncoder(index, options) { - options.fatal; - /** - * @param {Stream} stream Input stream. - * @param {number} code_point Next code point read from the stream. - * @return {(number|!Array.)} Byte(s) to emit. - */ - this.handler = function(stream, code_point) { - // 1. If code point is end-of-stream, return finished. - if (code_point === end_of_stream) - return finished; - - // 2. If code point is an ASCII code point, return a byte whose - // value is code point. - if (isASCIICodePoint(code_point)) - return code_point; - - // 3. Let pointer be the index pointer for code point in index - // single-byte. - var pointer = indexPointerFor(code_point, index); - - // 4. If pointer is null, return error with code point. - if (pointer === null) - encoderError(code_point); - - // 5. Return a byte whose value is pointer + 0x80. - return pointer + 0x80; - }; - } - - (function() { - if (!('encoding-indexes' in global)) - return; - encodings.forEach(function(category) { - if (category.heading !== 'Legacy single-byte encodings') - return; - category.encodings.forEach(function(encoding) { - var name = encoding.name; - var idx = index(name.toLowerCase()); - /** @param {{fatal: boolean}} options */ - decoders[name] = function(options) { - return new SingleByteDecoder(idx, options); - }; - /** @param {{fatal: boolean}} options */ - encoders[name] = function(options) { - return new SingleByteEncoder(idx, options); - }; - }); - }); - }()); - - // - // 11. Legacy multi-byte Chinese (simplified) encodings - // - - // 11.1 gbk - - // 11.1.1 gbk decoder - // gbk's decoder is gb18030's decoder. - /** @param {{fatal: boolean}} options */ - decoders['GBK'] = function(options) { - return new GB18030Decoder(options); - }; - - // 11.1.2 gbk encoder - // gbk's encoder is gb18030's encoder with its gbk flag set. - /** @param {{fatal: boolean}} options */ - encoders['GBK'] = function(options) { - return new GB18030Encoder(options, true); - }; - - // 11.2 gb18030 - - // 11.2.1 gb18030 decoder - /** - * @constructor - * @implements {Decoder} - * @param {{fatal: boolean}} options - */ - function GB18030Decoder(options) { - var fatal = options.fatal; - // gb18030's decoder has an associated gb18030 first, gb18030 - // second, and gb18030 third (all initially 0x00). - var /** @type {number} */ gb18030_first = 0x00, - /** @type {number} */ gb18030_second = 0x00, - /** @type {number} */ gb18030_third = 0x00; - /** - * @param {Stream} stream The stream of bytes being decoded. - * @param {number} bite The next byte read from the stream. - * @return {?(number|!Array.)} The next code point(s) - * decoded, or null if not enough data exists in the input - * stream to decode a complete code point. - */ - this.handler = function(stream, bite) { - // 1. If byte is end-of-stream and gb18030 first, gb18030 - // second, and gb18030 third are 0x00, return finished. - if (bite === end_of_stream && gb18030_first === 0x00 && - gb18030_second === 0x00 && gb18030_third === 0x00) { - return finished; - } - // 2. If byte is end-of-stream, and gb18030 first, gb18030 - // second, or gb18030 third is not 0x00, set gb18030 first, - // gb18030 second, and gb18030 third to 0x00, and return error. - if (bite === end_of_stream && - (gb18030_first !== 0x00 || gb18030_second !== 0x00 || - gb18030_third !== 0x00)) { - gb18030_first = 0x00; - gb18030_second = 0x00; - gb18030_third = 0x00; - decoderError(fatal); - } - var code_point; - // 3. If gb18030 third is not 0x00, run these substeps: - if (gb18030_third !== 0x00) { - // 1. Let code point be null. - code_point = null; - // 2. If byte is in the range 0x30 to 0x39, inclusive, set - // code point to the index gb18030 ranges code point for - // (((gb18030 first − 0x81) × 10 + gb18030 second − 0x30) × - // 126 + gb18030 third − 0x81) × 10 + byte − 0x30. - if (inRange(bite, 0x30, 0x39)) { - code_point = indexGB18030RangesCodePointFor( - (((gb18030_first - 0x81) * 10 + gb18030_second - 0x30) * 126 + - gb18030_third - 0x81) * 10 + bite - 0x30); - } - - // 3. Let buffer be a byte sequence consisting of gb18030 - // second, gb18030 third, and byte, in order. - var buffer = [gb18030_second, gb18030_third, bite]; - - // 4. Set gb18030 first, gb18030 second, and gb18030 third to - // 0x00. - gb18030_first = 0x00; - gb18030_second = 0x00; - gb18030_third = 0x00; - - // 5. If code point is null, prepend buffer to stream and - // return error. - if (code_point === null) { - stream.prepend(buffer); - return decoderError(fatal); - } - - // 6. Return a code point whose value is code point. - return code_point; - } - - // 4. If gb18030 second is not 0x00, run these substeps: - if (gb18030_second !== 0x00) { - - // 1. If byte is in the range 0x81 to 0xFE, inclusive, set - // gb18030 third to byte and return continue. - if (inRange(bite, 0x81, 0xFE)) { - gb18030_third = bite; - return null; - } - - // 2. Prepend gb18030 second followed by byte to stream, set - // gb18030 first and gb18030 second to 0x00, and return error. - stream.prepend([gb18030_second, bite]); - gb18030_first = 0x00; - gb18030_second = 0x00; - return decoderError(fatal); - } - - // 5. If gb18030 first is not 0x00, run these substeps: - if (gb18030_first !== 0x00) { - - // 1. If byte is in the range 0x30 to 0x39, inclusive, set - // gb18030 second to byte and return continue. - if (inRange(bite, 0x30, 0x39)) { - gb18030_second = bite; - return null; - } - - // 2. Let lead be gb18030 first, let pointer be null, and set - // gb18030 first to 0x00. - var lead = gb18030_first; - var pointer = null; - gb18030_first = 0x00; - - // 3. Let offset be 0x40 if byte is less than 0x7F and 0x41 - // otherwise. - var offset = bite < 0x7F ? 0x40 : 0x41; - - // 4. If byte is in the range 0x40 to 0x7E, inclusive, or 0x80 - // to 0xFE, inclusive, set pointer to (lead − 0x81) × 190 + - // (byte − offset). - if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0x80, 0xFE)) - pointer = (lead - 0x81) * 190 + (bite - offset); - - // 5. Let code point be null if pointer is null and the index - // code point for pointer in index gb18030 otherwise. - code_point = pointer === null ? null : - indexCodePointFor(pointer, index('gb18030')); - - // 6. If code point is null and byte is an ASCII byte, prepend - // byte to stream. - if (code_point === null && isASCIIByte(bite)) - stream.prepend(bite); - - // 7. If code point is null, return error. - if (code_point === null) - return decoderError(fatal); - - // 8. Return a code point whose value is code point. - return code_point; - } - - // 6. If byte is an ASCII byte, return a code point whose value - // is byte. - if (isASCIIByte(bite)) - return bite; - - // 7. If byte is 0x80, return code point U+20AC. - if (bite === 0x80) - return 0x20AC; - - // 8. If byte is in the range 0x81 to 0xFE, inclusive, set - // gb18030 first to byte and return continue. - if (inRange(bite, 0x81, 0xFE)) { - gb18030_first = bite; - return null; - } - - // 9. Return error. - return decoderError(fatal); - }; - } - - // 11.2.2 gb18030 encoder - /** - * @constructor - * @implements {Encoder} - * @param {{fatal: boolean}} options - * @param {boolean=} gbk_flag - */ - function GB18030Encoder(options, gbk_flag) { - options.fatal; - // gb18030's decoder has an associated gbk flag (initially unset). - /** - * @param {Stream} stream Input stream. - * @param {number} code_point Next code point read from the stream. - * @return {(number|!Array.)} Byte(s) to emit. - */ - this.handler = function(stream, code_point) { - // 1. If code point is end-of-stream, return finished. - if (code_point === end_of_stream) - return finished; - - // 2. If code point is an ASCII code point, return a byte whose - // value is code point. - if (isASCIICodePoint(code_point)) - return code_point; - - // 3. If code point is U+E5E5, return error with code point. - if (code_point === 0xE5E5) - return encoderError(code_point); - - // 4. If the gbk flag is set and code point is U+20AC, return - // byte 0x80. - if (gbk_flag && code_point === 0x20AC) - return 0x80; - - // 5. Let pointer be the index pointer for code point in index - // gb18030. - var pointer = indexPointerFor(code_point, index('gb18030')); - - // 6. If pointer is not null, run these substeps: - if (pointer !== null) { - - // 1. Let lead be floor(pointer / 190) + 0x81. - var lead = floor(pointer / 190) + 0x81; - - // 2. Let trail be pointer % 190. - var trail = pointer % 190; - - // 3. Let offset be 0x40 if trail is less than 0x3F and 0x41 otherwise. - var offset = trail < 0x3F ? 0x40 : 0x41; - - // 4. Return two bytes whose values are lead and trail + offset. - return [lead, trail + offset]; - } - - // 7. If gbk flag is set, return error with code point. - if (gbk_flag) - return encoderError(code_point); - - // 8. Set pointer to the index gb18030 ranges pointer for code - // point. - pointer = indexGB18030RangesPointerFor(code_point); - - // 9. Let byte1 be floor(pointer / 10 / 126 / 10). - var byte1 = floor(pointer / 10 / 126 / 10); - - // 10. Set pointer to pointer − byte1 × 10 × 126 × 10. - pointer = pointer - byte1 * 10 * 126 * 10; - - // 11. Let byte2 be floor(pointer / 10 / 126). - var byte2 = floor(pointer / 10 / 126); - - // 12. Set pointer to pointer − byte2 × 10 × 126. - pointer = pointer - byte2 * 10 * 126; - - // 13. Let byte3 be floor(pointer / 10). - var byte3 = floor(pointer / 10); - - // 14. Let byte4 be pointer − byte3 × 10. - var byte4 = pointer - byte3 * 10; - - // 15. Return four bytes whose values are byte1 + 0x81, byte2 + - // 0x30, byte3 + 0x81, byte4 + 0x30. - return [byte1 + 0x81, - byte2 + 0x30, - byte3 + 0x81, - byte4 + 0x30]; - }; - } - - /** @param {{fatal: boolean}} options */ - encoders['gb18030'] = function(options) { - return new GB18030Encoder(options); - }; - /** @param {{fatal: boolean}} options */ - decoders['gb18030'] = function(options) { - return new GB18030Decoder(options); - }; - - - // - // 12. Legacy multi-byte Chinese (traditional) encodings - // - - // 12.1 Big5 - - // 12.1.1 Big5 decoder - /** - * @constructor - * @implements {Decoder} - * @param {{fatal: boolean}} options - */ - function Big5Decoder(options) { - var fatal = options.fatal; - // Big5's decoder has an associated Big5 lead (initially 0x00). - var /** @type {number} */ Big5_lead = 0x00; - - /** - * @param {Stream} stream The stream of bytes being decoded. - * @param {number} bite The next byte read from the stream. - * @return {?(number|!Array.)} The next code point(s) - * decoded, or null if not enough data exists in the input - * stream to decode a complete code point. - */ - this.handler = function(stream, bite) { - // 1. If byte is end-of-stream and Big5 lead is not 0x00, set - // Big5 lead to 0x00 and return error. - if (bite === end_of_stream && Big5_lead !== 0x00) { - Big5_lead = 0x00; - return decoderError(fatal); - } - - // 2. If byte is end-of-stream and Big5 lead is 0x00, return - // finished. - if (bite === end_of_stream && Big5_lead === 0x00) - return finished; - - // 3. If Big5 lead is not 0x00, let lead be Big5 lead, let - // pointer be null, set Big5 lead to 0x00, and then run these - // substeps: - if (Big5_lead !== 0x00) { - var lead = Big5_lead; - var pointer = null; - Big5_lead = 0x00; - - // 1. Let offset be 0x40 if byte is less than 0x7F and 0x62 - // otherwise. - var offset = bite < 0x7F ? 0x40 : 0x62; - - // 2. If byte is in the range 0x40 to 0x7E, inclusive, or 0xA1 - // to 0xFE, inclusive, set pointer to (lead − 0x81) × 157 + - // (byte − offset). - if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0xA1, 0xFE)) - pointer = (lead - 0x81) * 157 + (bite - offset); - - // 3. If there is a row in the table below whose first column - // is pointer, return the two code points listed in its second - // column - // Pointer | Code points - // --------+-------------- - // 1133 | U+00CA U+0304 - // 1135 | U+00CA U+030C - // 1164 | U+00EA U+0304 - // 1166 | U+00EA U+030C - switch (pointer) { - case 1133: return [0x00CA, 0x0304]; - case 1135: return [0x00CA, 0x030C]; - case 1164: return [0x00EA, 0x0304]; - case 1166: return [0x00EA, 0x030C]; - } - - // 4. Let code point be null if pointer is null and the index - // code point for pointer in index Big5 otherwise. - var code_point = (pointer === null) ? null : - indexCodePointFor(pointer, index('big5')); - - // 5. If code point is null and byte is an ASCII byte, prepend - // byte to stream. - if (code_point === null && isASCIIByte(bite)) - stream.prepend(bite); - - // 6. If code point is null, return error. - if (code_point === null) - return decoderError(fatal); - - // 7. Return a code point whose value is code point. - return code_point; - } - - // 4. If byte is an ASCII byte, return a code point whose value - // is byte. - if (isASCIIByte(bite)) - return bite; - - // 5. If byte is in the range 0x81 to 0xFE, inclusive, set Big5 - // lead to byte and return continue. - if (inRange(bite, 0x81, 0xFE)) { - Big5_lead = bite; - return null; - } - - // 6. Return error. - return decoderError(fatal); - }; - } - - // 12.1.2 Big5 encoder - /** - * @constructor - * @implements {Encoder} - * @param {{fatal: boolean}} options - */ - function Big5Encoder(options) { - options.fatal; - /** - * @param {Stream} stream Input stream. - * @param {number} code_point Next code point read from the stream. - * @return {(number|!Array.)} Byte(s) to emit. - */ - this.handler = function(stream, code_point) { - // 1. If code point is end-of-stream, return finished. - if (code_point === end_of_stream) - return finished; - - // 2. If code point is an ASCII code point, return a byte whose - // value is code point. - if (isASCIICodePoint(code_point)) - return code_point; - - // 3. Let pointer be the index Big5 pointer for code point. - var pointer = indexBig5PointerFor(code_point); - - // 4. If pointer is null, return error with code point. - if (pointer === null) - return encoderError(code_point); - - // 5. Let lead be floor(pointer / 157) + 0x81. - var lead = floor(pointer / 157) + 0x81; - - // 6. If lead is less than 0xA1, return error with code point. - if (lead < 0xA1) - return encoderError(code_point); - - // 7. Let trail be pointer % 157. - var trail = pointer % 157; - - // 8. Let offset be 0x40 if trail is less than 0x3F and 0x62 - // otherwise. - var offset = trail < 0x3F ? 0x40 : 0x62; - - // Return two bytes whose values are lead and trail + offset. - return [lead, trail + offset]; - }; - } - - /** @param {{fatal: boolean}} options */ - encoders['Big5'] = function(options) { - return new Big5Encoder(options); - }; - /** @param {{fatal: boolean}} options */ - decoders['Big5'] = function(options) { - return new Big5Decoder(options); - }; - - - // - // 13. Legacy multi-byte Japanese encodings - // - - // 13.1 euc-jp - - // 13.1.1 euc-jp decoder - /** - * @constructor - * @implements {Decoder} - * @param {{fatal: boolean}} options - */ - function EUCJPDecoder(options) { - var fatal = options.fatal; - - // euc-jp's decoder has an associated euc-jp jis0212 flag - // (initially unset) and euc-jp lead (initially 0x00). - var /** @type {boolean} */ eucjp_jis0212_flag = false, - /** @type {number} */ eucjp_lead = 0x00; - - /** - * @param {Stream} stream The stream of bytes being decoded. - * @param {number} bite The next byte read from the stream. - * @return {?(number|!Array.)} The next code point(s) - * decoded, or null if not enough data exists in the input - * stream to decode a complete code point. - */ - this.handler = function(stream, bite) { - // 1. If byte is end-of-stream and euc-jp lead is not 0x00, set - // euc-jp lead to 0x00, and return error. - if (bite === end_of_stream && eucjp_lead !== 0x00) { - eucjp_lead = 0x00; - return decoderError(fatal); - } - - // 2. If byte is end-of-stream and euc-jp lead is 0x00, return - // finished. - if (bite === end_of_stream && eucjp_lead === 0x00) - return finished; - - // 3. If euc-jp lead is 0x8E and byte is in the range 0xA1 to - // 0xDF, inclusive, set euc-jp lead to 0x00 and return a code - // point whose value is 0xFF61 − 0xA1 + byte. - if (eucjp_lead === 0x8E && inRange(bite, 0xA1, 0xDF)) { - eucjp_lead = 0x00; - return 0xFF61 - 0xA1 + bite; - } - - // 4. If euc-jp lead is 0x8F and byte is in the range 0xA1 to - // 0xFE, inclusive, set the euc-jp jis0212 flag, set euc-jp lead - // to byte, and return continue. - if (eucjp_lead === 0x8F && inRange(bite, 0xA1, 0xFE)) { - eucjp_jis0212_flag = true; - eucjp_lead = bite; - return null; - } - - // 5. If euc-jp lead is not 0x00, let lead be euc-jp lead, set - // euc-jp lead to 0x00, and run these substeps: - if (eucjp_lead !== 0x00) { - var lead = eucjp_lead; - eucjp_lead = 0x00; - - // 1. Let code point be null. - var code_point = null; - - // 2. If lead and byte are both in the range 0xA1 to 0xFE, - // inclusive, set code point to the index code point for (lead - // − 0xA1) × 94 + byte − 0xA1 in index jis0208 if the euc-jp - // jis0212 flag is unset and in index jis0212 otherwise. - if (inRange(lead, 0xA1, 0xFE) && inRange(bite, 0xA1, 0xFE)) { - code_point = indexCodePointFor( - (lead - 0xA1) * 94 + (bite - 0xA1), - index(!eucjp_jis0212_flag ? 'jis0208' : 'jis0212')); - } - - // 3. Unset the euc-jp jis0212 flag. - eucjp_jis0212_flag = false; - - // 4. If byte is not in the range 0xA1 to 0xFE, inclusive, - // prepend byte to stream. - if (!inRange(bite, 0xA1, 0xFE)) - stream.prepend(bite); - - // 5. If code point is null, return error. - if (code_point === null) - return decoderError(fatal); - - // 6. Return a code point whose value is code point. - return code_point; - } - - // 6. If byte is an ASCII byte, return a code point whose value - // is byte. - if (isASCIIByte(bite)) - return bite; - - // 7. If byte is 0x8E, 0x8F, or in the range 0xA1 to 0xFE, - // inclusive, set euc-jp lead to byte and return continue. - if (bite === 0x8E || bite === 0x8F || inRange(bite, 0xA1, 0xFE)) { - eucjp_lead = bite; - return null; - } - - // 8. Return error. - return decoderError(fatal); - }; - } - - // 13.1.2 euc-jp encoder - /** - * @constructor - * @implements {Encoder} - * @param {{fatal: boolean}} options - */ - function EUCJPEncoder(options) { - options.fatal; - /** - * @param {Stream} stream Input stream. - * @param {number} code_point Next code point read from the stream. - * @return {(number|!Array.)} Byte(s) to emit. - */ - this.handler = function(stream, code_point) { - // 1. If code point is end-of-stream, return finished. - if (code_point === end_of_stream) - return finished; - - // 2. If code point is an ASCII code point, return a byte whose - // value is code point. - if (isASCIICodePoint(code_point)) - return code_point; - - // 3. If code point is U+00A5, return byte 0x5C. - if (code_point === 0x00A5) - return 0x5C; - - // 4. If code point is U+203E, return byte 0x7E. - if (code_point === 0x203E) - return 0x7E; - - // 5. If code point is in the range U+FF61 to U+FF9F, inclusive, - // return two bytes whose values are 0x8E and code point − - // 0xFF61 + 0xA1. - if (inRange(code_point, 0xFF61, 0xFF9F)) - return [0x8E, code_point - 0xFF61 + 0xA1]; - - // 6. If code point is U+2212, set it to U+FF0D. - if (code_point === 0x2212) - code_point = 0xFF0D; - - // 7. Let pointer be the index pointer for code point in index - // jis0208. - var pointer = indexPointerFor(code_point, index('jis0208')); - - // 8. If pointer is null, return error with code point. - if (pointer === null) - return encoderError(code_point); - - // 9. Let lead be floor(pointer / 94) + 0xA1. - var lead = floor(pointer / 94) + 0xA1; - - // 10. Let trail be pointer % 94 + 0xA1. - var trail = pointer % 94 + 0xA1; - - // 11. Return two bytes whose values are lead and trail. - return [lead, trail]; - }; - } - - /** @param {{fatal: boolean}} options */ - encoders['EUC-JP'] = function(options) { - return new EUCJPEncoder(options); - }; - /** @param {{fatal: boolean}} options */ - decoders['EUC-JP'] = function(options) { - return new EUCJPDecoder(options); - }; - - // 13.2 iso-2022-jp - - // 13.2.1 iso-2022-jp decoder - /** - * @constructor - * @implements {Decoder} - * @param {{fatal: boolean}} options - */ - function ISO2022JPDecoder(options) { - var fatal = options.fatal; - /** @enum */ - var states = { - ASCII: 0, - Roman: 1, - Katakana: 2, - LeadByte: 3, - TrailByte: 4, - EscapeStart: 5, - Escape: 6 - }; - // iso-2022-jp's decoder has an associated iso-2022-jp decoder - // state (initially ASCII), iso-2022-jp decoder output state - // (initially ASCII), iso-2022-jp lead (initially 0x00), and - // iso-2022-jp output flag (initially unset). - var /** @type {number} */ iso2022jp_decoder_state = states.ASCII, - /** @type {number} */ iso2022jp_decoder_output_state = states.ASCII, - /** @type {number} */ iso2022jp_lead = 0x00, - /** @type {boolean} */ iso2022jp_output_flag = false; - /** - * @param {Stream} stream The stream of bytes being decoded. - * @param {number} bite The next byte read from the stream. - * @return {?(number|!Array.)} The next code point(s) - * decoded, or null if not enough data exists in the input - * stream to decode a complete code point. - */ - this.handler = function(stream, bite) { - // switching on iso-2022-jp decoder state: - switch (iso2022jp_decoder_state) { - default: - case states.ASCII: - // ASCII - // Based on byte: - - // 0x1B - if (bite === 0x1B) { - // Set iso-2022-jp decoder state to escape start and return - // continue. - iso2022jp_decoder_state = states.EscapeStart; - return null; - } - - // 0x00 to 0x7F, excluding 0x0E, 0x0F, and 0x1B - if (inRange(bite, 0x00, 0x7F) && bite !== 0x0E - && bite !== 0x0F && bite !== 0x1B) { - // Unset the iso-2022-jp output flag and return a code point - // whose value is byte. - iso2022jp_output_flag = false; - return bite; - } - - // end-of-stream - if (bite === end_of_stream) { - // Return finished. - return finished; - } - - // Otherwise - // Unset the iso-2022-jp output flag and return error. - iso2022jp_output_flag = false; - return decoderError(fatal); - - case states.Roman: - // Roman - // Based on byte: - - // 0x1B - if (bite === 0x1B) { - // Set iso-2022-jp decoder state to escape start and return - // continue. - iso2022jp_decoder_state = states.EscapeStart; - return null; - } - - // 0x5C - if (bite === 0x5C) { - // Unset the iso-2022-jp output flag and return code point - // U+00A5. - iso2022jp_output_flag = false; - return 0x00A5; - } - - // 0x7E - if (bite === 0x7E) { - // Unset the iso-2022-jp output flag and return code point - // U+203E. - iso2022jp_output_flag = false; - return 0x203E; - } - - // 0x00 to 0x7F, excluding 0x0E, 0x0F, 0x1B, 0x5C, and 0x7E - if (inRange(bite, 0x00, 0x7F) && bite !== 0x0E && bite !== 0x0F - && bite !== 0x1B && bite !== 0x5C && bite !== 0x7E) { - // Unset the iso-2022-jp output flag and return a code point - // whose value is byte. - iso2022jp_output_flag = false; - return bite; - } - - // end-of-stream - if (bite === end_of_stream) { - // Return finished. - return finished; - } - - // Otherwise - // Unset the iso-2022-jp output flag and return error. - iso2022jp_output_flag = false; - return decoderError(fatal); - - case states.Katakana: - // Katakana - // Based on byte: - - // 0x1B - if (bite === 0x1B) { - // Set iso-2022-jp decoder state to escape start and return - // continue. - iso2022jp_decoder_state = states.EscapeStart; - return null; - } - - // 0x21 to 0x5F - if (inRange(bite, 0x21, 0x5F)) { - // Unset the iso-2022-jp output flag and return a code point - // whose value is 0xFF61 − 0x21 + byte. - iso2022jp_output_flag = false; - return 0xFF61 - 0x21 + bite; - } - - // end-of-stream - if (bite === end_of_stream) { - // Return finished. - return finished; - } - - // Otherwise - // Unset the iso-2022-jp output flag and return error. - iso2022jp_output_flag = false; - return decoderError(fatal); - - case states.LeadByte: - // Lead byte - // Based on byte: - - // 0x1B - if (bite === 0x1B) { - // Set iso-2022-jp decoder state to escape start and return - // continue. - iso2022jp_decoder_state = states.EscapeStart; - return null; - } - - // 0x21 to 0x7E - if (inRange(bite, 0x21, 0x7E)) { - // Unset the iso-2022-jp output flag, set iso-2022-jp lead - // to byte, iso-2022-jp decoder state to trail byte, and - // return continue. - iso2022jp_output_flag = false; - iso2022jp_lead = bite; - iso2022jp_decoder_state = states.TrailByte; - return null; - } - - // end-of-stream - if (bite === end_of_stream) { - // Return finished. - return finished; - } - - // Otherwise - // Unset the iso-2022-jp output flag and return error. - iso2022jp_output_flag = false; - return decoderError(fatal); - - case states.TrailByte: - // Trail byte - // Based on byte: - - // 0x1B - if (bite === 0x1B) { - // Set iso-2022-jp decoder state to escape start and return - // continue. - iso2022jp_decoder_state = states.EscapeStart; - return decoderError(fatal); - } - - // 0x21 to 0x7E - if (inRange(bite, 0x21, 0x7E)) { - // 1. Set the iso-2022-jp decoder state to lead byte. - iso2022jp_decoder_state = states.LeadByte; - - // 2. Let pointer be (iso-2022-jp lead − 0x21) × 94 + byte − 0x21. - var pointer = (iso2022jp_lead - 0x21) * 94 + bite - 0x21; - - // 3. Let code point be the index code point for pointer in - // index jis0208. - var code_point = indexCodePointFor(pointer, index('jis0208')); - - // 4. If code point is null, return error. - if (code_point === null) - return decoderError(fatal); - - // 5. Return a code point whose value is code point. - return code_point; - } - - // end-of-stream - if (bite === end_of_stream) { - // Set the iso-2022-jp decoder state to lead byte, prepend - // byte to stream, and return error. - iso2022jp_decoder_state = states.LeadByte; - stream.prepend(bite); - return decoderError(fatal); - } - - // Otherwise - // Set iso-2022-jp decoder state to lead byte and return - // error. - iso2022jp_decoder_state = states.LeadByte; - return decoderError(fatal); - - case states.EscapeStart: - // Escape start - - // 1. If byte is either 0x24 or 0x28, set iso-2022-jp lead to - // byte, iso-2022-jp decoder state to escape, and return - // continue. - if (bite === 0x24 || bite === 0x28) { - iso2022jp_lead = bite; - iso2022jp_decoder_state = states.Escape; - return null; - } - - // 2. Prepend byte to stream. - stream.prepend(bite); - - // 3. Unset the iso-2022-jp output flag, set iso-2022-jp - // decoder state to iso-2022-jp decoder output state, and - // return error. - iso2022jp_output_flag = false; - iso2022jp_decoder_state = iso2022jp_decoder_output_state; - return decoderError(fatal); - - case states.Escape: - // Escape - - // 1. Let lead be iso-2022-jp lead and set iso-2022-jp lead to - // 0x00. - var lead = iso2022jp_lead; - iso2022jp_lead = 0x00; - - // 2. Let state be null. - var state = null; - - // 3. If lead is 0x28 and byte is 0x42, set state to ASCII. - if (lead === 0x28 && bite === 0x42) - state = states.ASCII; - - // 4. If lead is 0x28 and byte is 0x4A, set state to Roman. - if (lead === 0x28 && bite === 0x4A) - state = states.Roman; - - // 5. If lead is 0x28 and byte is 0x49, set state to Katakana. - if (lead === 0x28 && bite === 0x49) - state = states.Katakana; - - // 6. If lead is 0x24 and byte is either 0x40 or 0x42, set - // state to lead byte. - if (lead === 0x24 && (bite === 0x40 || bite === 0x42)) - state = states.LeadByte; - - // 7. If state is non-null, run these substeps: - if (state !== null) { - // 1. Set iso-2022-jp decoder state and iso-2022-jp decoder - // output state to states. - iso2022jp_decoder_state = iso2022jp_decoder_state = state; - - // 2. Let output flag be the iso-2022-jp output flag. - var output_flag = iso2022jp_output_flag; - - // 3. Set the iso-2022-jp output flag. - iso2022jp_output_flag = true; - - // 4. Return continue, if output flag is unset, and error - // otherwise. - return !output_flag ? null : decoderError(fatal); - } - - // 8. Prepend lead and byte to stream. - stream.prepend([lead, bite]); - - // 9. Unset the iso-2022-jp output flag, set iso-2022-jp - // decoder state to iso-2022-jp decoder output state and - // return error. - iso2022jp_output_flag = false; - iso2022jp_decoder_state = iso2022jp_decoder_output_state; - return decoderError(fatal); - } - }; - } - - // 13.2.2 iso-2022-jp encoder - /** - * @constructor - * @implements {Encoder} - * @param {{fatal: boolean}} options - */ - function ISO2022JPEncoder(options) { - options.fatal; - // iso-2022-jp's encoder has an associated iso-2022-jp encoder - // state which is one of ASCII, Roman, and jis0208 (initially - // ASCII). - /** @enum */ - var states = { - ASCII: 0, - Roman: 1, - jis0208: 2 - }; - var /** @type {number} */ iso2022jp_state = states.ASCII; - /** - * @param {Stream} stream Input stream. - * @param {number} code_point Next code point read from the stream. - * @return {(number|!Array.)} Byte(s) to emit. - */ - this.handler = function(stream, code_point) { - // 1. If code point is end-of-stream and iso-2022-jp encoder - // state is not ASCII, prepend code point to stream, set - // iso-2022-jp encoder state to ASCII, and return three bytes - // 0x1B 0x28 0x42. - if (code_point === end_of_stream && - iso2022jp_state !== states.ASCII) { - stream.prepend(code_point); - iso2022jp_state = states.ASCII; - return [0x1B, 0x28, 0x42]; - } - - // 2. If code point is end-of-stream and iso-2022-jp encoder - // state is ASCII, return finished. - if (code_point === end_of_stream && iso2022jp_state === states.ASCII) - return finished; - - // 3. If ISO-2022-JP encoder state is ASCII or Roman, and code - // point is U+000E, U+000F, or U+001B, return error with U+FFFD. - if ((iso2022jp_state === states.ASCII || - iso2022jp_state === states.Roman) && - (code_point === 0x000E || code_point === 0x000F || - code_point === 0x001B)) { - return encoderError(0xFFFD); - } - - // 4. If iso-2022-jp encoder state is ASCII and code point is an - // ASCII code point, return a byte whose value is code point. - if (iso2022jp_state === states.ASCII && - isASCIICodePoint(code_point)) - return code_point; - - // 5. If iso-2022-jp encoder state is Roman and code point is an - // ASCII code point, excluding U+005C and U+007E, or is U+00A5 - // or U+203E, run these substeps: - if (iso2022jp_state === states.Roman && - ((isASCIICodePoint(code_point) && - code_point !== 0x005C && code_point !== 0x007E) || - (code_point == 0x00A5 || code_point == 0x203E))) { - - // 1. If code point is an ASCII code point, return a byte - // whose value is code point. - if (isASCIICodePoint(code_point)) - return code_point; - - // 2. If code point is U+00A5, return byte 0x5C. - if (code_point === 0x00A5) - return 0x5C; - - // 3. If code point is U+203E, return byte 0x7E. - if (code_point === 0x203E) - return 0x7E; - } - - // 6. If code point is an ASCII code point, and iso-2022-jp - // encoder state is not ASCII, prepend code point to stream, set - // iso-2022-jp encoder state to ASCII, and return three bytes - // 0x1B 0x28 0x42. - if (isASCIICodePoint(code_point) && - iso2022jp_state !== states.ASCII) { - stream.prepend(code_point); - iso2022jp_state = states.ASCII; - return [0x1B, 0x28, 0x42]; - } - - // 7. If code point is either U+00A5 or U+203E, and iso-2022-jp - // encoder state is not Roman, prepend code point to stream, set - // iso-2022-jp encoder state to Roman, and return three bytes - // 0x1B 0x28 0x4A. - if ((code_point === 0x00A5 || code_point === 0x203E) && - iso2022jp_state !== states.Roman) { - stream.prepend(code_point); - iso2022jp_state = states.Roman; - return [0x1B, 0x28, 0x4A]; - } - - // 8. If code point is U+2212, set it to U+FF0D. - if (code_point === 0x2212) - code_point = 0xFF0D; - - // 9. Let pointer be the index pointer for code point in index - // jis0208. - var pointer = indexPointerFor(code_point, index('jis0208')); - - // 10. If pointer is null, return error with code point. - if (pointer === null) - return encoderError(code_point); - - // 11. If iso-2022-jp encoder state is not jis0208, prepend code - // point to stream, set iso-2022-jp encoder state to jis0208, - // and return three bytes 0x1B 0x24 0x42. - if (iso2022jp_state !== states.jis0208) { - stream.prepend(code_point); - iso2022jp_state = states.jis0208; - return [0x1B, 0x24, 0x42]; - } - - // 12. Let lead be floor(pointer / 94) + 0x21. - var lead = floor(pointer / 94) + 0x21; - - // 13. Let trail be pointer % 94 + 0x21. - var trail = pointer % 94 + 0x21; - - // 14. Return two bytes whose values are lead and trail. - return [lead, trail]; - }; - } - - /** @param {{fatal: boolean}} options */ - encoders['ISO-2022-JP'] = function(options) { - return new ISO2022JPEncoder(options); - }; - /** @param {{fatal: boolean}} options */ - decoders['ISO-2022-JP'] = function(options) { - return new ISO2022JPDecoder(options); - }; - - // 13.3 Shift_JIS - - // 13.3.1 Shift_JIS decoder - /** - * @constructor - * @implements {Decoder} - * @param {{fatal: boolean}} options - */ - function ShiftJISDecoder(options) { - var fatal = options.fatal; - // Shift_JIS's decoder has an associated Shift_JIS lead (initially - // 0x00). - var /** @type {number} */ Shift_JIS_lead = 0x00; - /** - * @param {Stream} stream The stream of bytes being decoded. - * @param {number} bite The next byte read from the stream. - * @return {?(number|!Array.)} The next code point(s) - * decoded, or null if not enough data exists in the input - * stream to decode a complete code point. - */ - this.handler = function(stream, bite) { - // 1. If byte is end-of-stream and Shift_JIS lead is not 0x00, - // set Shift_JIS lead to 0x00 and return error. - if (bite === end_of_stream && Shift_JIS_lead !== 0x00) { - Shift_JIS_lead = 0x00; - return decoderError(fatal); - } - - // 2. If byte is end-of-stream and Shift_JIS lead is 0x00, - // return finished. - if (bite === end_of_stream && Shift_JIS_lead === 0x00) - return finished; - - // 3. If Shift_JIS lead is not 0x00, let lead be Shift_JIS lead, - // let pointer be null, set Shift_JIS lead to 0x00, and then run - // these substeps: - if (Shift_JIS_lead !== 0x00) { - var lead = Shift_JIS_lead; - var pointer = null; - Shift_JIS_lead = 0x00; - - // 1. Let offset be 0x40, if byte is less than 0x7F, and 0x41 - // otherwise. - var offset = (bite < 0x7F) ? 0x40 : 0x41; - - // 2. Let lead offset be 0x81, if lead is less than 0xA0, and - // 0xC1 otherwise. - var lead_offset = (lead < 0xA0) ? 0x81 : 0xC1; - - // 3. If byte is in the range 0x40 to 0x7E, inclusive, or 0x80 - // to 0xFC, inclusive, set pointer to (lead − lead offset) × - // 188 + byte − offset. - if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0x80, 0xFC)) - pointer = (lead - lead_offset) * 188 + bite - offset; - - // 4. If pointer is in the range 8836 to 10715, inclusive, - // return a code point whose value is 0xE000 − 8836 + pointer. - if (inRange(pointer, 8836, 10715)) - return 0xE000 - 8836 + pointer; - - // 5. Let code point be null, if pointer is null, and the - // index code point for pointer in index jis0208 otherwise. - var code_point = (pointer === null) ? null : - indexCodePointFor(pointer, index('jis0208')); - - // 6. If code point is null and byte is an ASCII byte, prepend - // byte to stream. - if (code_point === null && isASCIIByte(bite)) - stream.prepend(bite); - - // 7. If code point is null, return error. - if (code_point === null) - return decoderError(fatal); - - // 8. Return a code point whose value is code point. - return code_point; - } - - // 4. If byte is an ASCII byte or 0x80, return a code point - // whose value is byte. - if (isASCIIByte(bite) || bite === 0x80) - return bite; - - // 5. If byte is in the range 0xA1 to 0xDF, inclusive, return a - // code point whose value is 0xFF61 − 0xA1 + byte. - if (inRange(bite, 0xA1, 0xDF)) - return 0xFF61 - 0xA1 + bite; - - // 6. If byte is in the range 0x81 to 0x9F, inclusive, or 0xE0 - // to 0xFC, inclusive, set Shift_JIS lead to byte and return - // continue. - if (inRange(bite, 0x81, 0x9F) || inRange(bite, 0xE0, 0xFC)) { - Shift_JIS_lead = bite; - return null; - } - - // 7. Return error. - return decoderError(fatal); - }; - } - - // 13.3.2 Shift_JIS encoder - /** - * @constructor - * @implements {Encoder} - * @param {{fatal: boolean}} options - */ - function ShiftJISEncoder(options) { - options.fatal; - /** - * @param {Stream} stream Input stream. - * @param {number} code_point Next code point read from the stream. - * @return {(number|!Array.)} Byte(s) to emit. - */ - this.handler = function(stream, code_point) { - // 1. If code point is end-of-stream, return finished. - if (code_point === end_of_stream) - return finished; - - // 2. If code point is an ASCII code point or U+0080, return a - // byte whose value is code point. - if (isASCIICodePoint(code_point) || code_point === 0x0080) - return code_point; - - // 3. If code point is U+00A5, return byte 0x5C. - if (code_point === 0x00A5) - return 0x5C; - - // 4. If code point is U+203E, return byte 0x7E. - if (code_point === 0x203E) - return 0x7E; - - // 5. If code point is in the range U+FF61 to U+FF9F, inclusive, - // return a byte whose value is code point − 0xFF61 + 0xA1. - if (inRange(code_point, 0xFF61, 0xFF9F)) - return code_point - 0xFF61 + 0xA1; - - // 6. If code point is U+2212, set it to U+FF0D. - if (code_point === 0x2212) - code_point = 0xFF0D; - - // 7. Let pointer be the index Shift_JIS pointer for code point. - var pointer = indexShiftJISPointerFor(code_point); - - // 8. If pointer is null, return error with code point. - if (pointer === null) - return encoderError(code_point); - - // 9. Let lead be floor(pointer / 188). - var lead = floor(pointer / 188); - - // 10. Let lead offset be 0x81, if lead is less than 0x1F, and - // 0xC1 otherwise. - var lead_offset = (lead < 0x1F) ? 0x81 : 0xC1; - - // 11. Let trail be pointer % 188. - var trail = pointer % 188; - - // 12. Let offset be 0x40, if trail is less than 0x3F, and 0x41 - // otherwise. - var offset = (trail < 0x3F) ? 0x40 : 0x41; - - // 13. Return two bytes whose values are lead + lead offset and - // trail + offset. - return [lead + lead_offset, trail + offset]; - }; - } - - /** @param {{fatal: boolean}} options */ - encoders['Shift_JIS'] = function(options) { - return new ShiftJISEncoder(options); - }; - /** @param {{fatal: boolean}} options */ - decoders['Shift_JIS'] = function(options) { - return new ShiftJISDecoder(options); - }; - - // - // 14. Legacy multi-byte Korean encodings - // - - // 14.1 euc-kr - - // 14.1.1 euc-kr decoder - /** - * @constructor - * @implements {Decoder} - * @param {{fatal: boolean}} options - */ - function EUCKRDecoder(options) { - var fatal = options.fatal; - - // euc-kr's decoder has an associated euc-kr lead (initially 0x00). - var /** @type {number} */ euckr_lead = 0x00; - /** - * @param {Stream} stream The stream of bytes being decoded. - * @param {number} bite The next byte read from the stream. - * @return {?(number|!Array.)} The next code point(s) - * decoded, or null if not enough data exists in the input - * stream to decode a complete code point. - */ - this.handler = function(stream, bite) { - // 1. If byte is end-of-stream and euc-kr lead is not 0x00, set - // euc-kr lead to 0x00 and return error. - if (bite === end_of_stream && euckr_lead !== 0) { - euckr_lead = 0x00; - return decoderError(fatal); - } - - // 2. If byte is end-of-stream and euc-kr lead is 0x00, return - // finished. - if (bite === end_of_stream && euckr_lead === 0) - return finished; - - // 3. If euc-kr lead is not 0x00, let lead be euc-kr lead, let - // pointer be null, set euc-kr lead to 0x00, and then run these - // substeps: - if (euckr_lead !== 0x00) { - var lead = euckr_lead; - var pointer = null; - euckr_lead = 0x00; - - // 1. If byte is in the range 0x41 to 0xFE, inclusive, set - // pointer to (lead − 0x81) × 190 + (byte − 0x41). - if (inRange(bite, 0x41, 0xFE)) - pointer = (lead - 0x81) * 190 + (bite - 0x41); - - // 2. Let code point be null, if pointer is null, and the - // index code point for pointer in index euc-kr otherwise. - var code_point = (pointer === null) - ? null : indexCodePointFor(pointer, index('euc-kr')); - - // 3. If code point is null and byte is an ASCII byte, prepend - // byte to stream. - if (pointer === null && isASCIIByte(bite)) - stream.prepend(bite); - - // 4. If code point is null, return error. - if (code_point === null) - return decoderError(fatal); - - // 5. Return a code point whose value is code point. - return code_point; - } - - // 4. If byte is an ASCII byte, return a code point whose value - // is byte. - if (isASCIIByte(bite)) - return bite; - - // 5. If byte is in the range 0x81 to 0xFE, inclusive, set - // euc-kr lead to byte and return continue. - if (inRange(bite, 0x81, 0xFE)) { - euckr_lead = bite; - return null; - } - - // 6. Return error. - return decoderError(fatal); - }; - } - - // 14.1.2 euc-kr encoder - /** - * @constructor - * @implements {Encoder} - * @param {{fatal: boolean}} options - */ - function EUCKREncoder(options) { - options.fatal; - /** - * @param {Stream} stream Input stream. - * @param {number} code_point Next code point read from the stream. - * @return {(number|!Array.)} Byte(s) to emit. - */ - this.handler = function(stream, code_point) { - // 1. If code point is end-of-stream, return finished. - if (code_point === end_of_stream) - return finished; - - // 2. If code point is an ASCII code point, return a byte whose - // value is code point. - if (isASCIICodePoint(code_point)) - return code_point; - - // 3. Let pointer be the index pointer for code point in index - // euc-kr. - var pointer = indexPointerFor(code_point, index('euc-kr')); - - // 4. If pointer is null, return error with code point. - if (pointer === null) - return encoderError(code_point); - - // 5. Let lead be floor(pointer / 190) + 0x81. - var lead = floor(pointer / 190) + 0x81; - - // 6. Let trail be pointer % 190 + 0x41. - var trail = (pointer % 190) + 0x41; - - // 7. Return two bytes whose values are lead and trail. - return [lead, trail]; - }; - } - - /** @param {{fatal: boolean}} options */ - encoders['EUC-KR'] = function(options) { - return new EUCKREncoder(options); - }; - /** @param {{fatal: boolean}} options */ - decoders['EUC-KR'] = function(options) { - return new EUCKRDecoder(options); - }; - - - // - // 15. Legacy miscellaneous encodings - // - - // 15.1 replacement - - // Not needed - API throws RangeError - - // 15.2 Common infrastructure for utf-16be and utf-16le - - /** - * @param {number} code_unit - * @param {boolean} utf16be - * @return {!Array.} bytes - */ - function convertCodeUnitToBytes(code_unit, utf16be) { - // 1. Let byte1 be code unit >> 8. - var byte1 = code_unit >> 8; - - // 2. Let byte2 be code unit & 0x00FF. - var byte2 = code_unit & 0x00FF; - - // 3. Then return the bytes in order: - // utf-16be flag is set: byte1, then byte2. - if (utf16be) - return [byte1, byte2]; - // utf-16be flag is unset: byte2, then byte1. - return [byte2, byte1]; - } - - // 15.2.1 shared utf-16 decoder - /** - * @constructor - * @implements {Decoder} - * @param {boolean} utf16_be True if big-endian, false if little-endian. - * @param {{fatal: boolean}} options - */ - function UTF16Decoder(utf16_be, options) { - var fatal = options.fatal; - var /** @type {?number} */ utf16_lead_byte = null, - /** @type {?number} */ utf16_lead_surrogate = null; - /** - * @param {Stream} stream The stream of bytes being decoded. - * @param {number} bite The next byte read from the stream. - * @return {?(number|!Array.)} The next code point(s) - * decoded, or null if not enough data exists in the input - * stream to decode a complete code point. - */ - this.handler = function(stream, bite) { - // 1. If byte is end-of-stream and either utf-16 lead byte or - // utf-16 lead surrogate is not null, set utf-16 lead byte and - // utf-16 lead surrogate to null, and return error. - if (bite === end_of_stream && (utf16_lead_byte !== null || - utf16_lead_surrogate !== null)) { - return decoderError(fatal); - } - - // 2. If byte is end-of-stream and utf-16 lead byte and utf-16 - // lead surrogate are null, return finished. - if (bite === end_of_stream && utf16_lead_byte === null && - utf16_lead_surrogate === null) { - return finished; - } - - // 3. If utf-16 lead byte is null, set utf-16 lead byte to byte - // and return continue. - if (utf16_lead_byte === null) { - utf16_lead_byte = bite; - return null; - } - - // 4. Let code unit be the result of: - var code_unit; - if (utf16_be) { - // utf-16be decoder flag is set - // (utf-16 lead byte << 8) + byte. - code_unit = (utf16_lead_byte << 8) + bite; - } else { - // utf-16be decoder flag is unset - // (byte << 8) + utf-16 lead byte. - code_unit = (bite << 8) + utf16_lead_byte; - } - // Then set utf-16 lead byte to null. - utf16_lead_byte = null; - - // 5. If utf-16 lead surrogate is not null, let lead surrogate - // be utf-16 lead surrogate, set utf-16 lead surrogate to null, - // and then run these substeps: - if (utf16_lead_surrogate !== null) { - var lead_surrogate = utf16_lead_surrogate; - utf16_lead_surrogate = null; - - // 1. If code unit is in the range U+DC00 to U+DFFF, - // inclusive, return a code point whose value is 0x10000 + - // ((lead surrogate − 0xD800) << 10) + (code unit − 0xDC00). - if (inRange(code_unit, 0xDC00, 0xDFFF)) { - return 0x10000 + (lead_surrogate - 0xD800) * 0x400 + - (code_unit - 0xDC00); - } - - // 2. Prepend the sequence resulting of converting code unit - // to bytes using utf-16be decoder flag to stream and return - // error. - stream.prepend(convertCodeUnitToBytes(code_unit, utf16_be)); - return decoderError(fatal); - } - - // 6. If code unit is in the range U+D800 to U+DBFF, inclusive, - // set utf-16 lead surrogate to code unit and return continue. - if (inRange(code_unit, 0xD800, 0xDBFF)) { - utf16_lead_surrogate = code_unit; - return null; - } - - // 7. If code unit is in the range U+DC00 to U+DFFF, inclusive, - // return error. - if (inRange(code_unit, 0xDC00, 0xDFFF)) - return decoderError(fatal); - - // 8. Return code point code unit. - return code_unit; - }; - } - - // 15.2.2 shared utf-16 encoder - /** - * @constructor - * @implements {Encoder} - * @param {boolean} utf16_be True if big-endian, false if little-endian. - * @param {{fatal: boolean}} options - */ - function UTF16Encoder(utf16_be, options) { - options.fatal; - /** - * @param {Stream} stream Input stream. - * @param {number} code_point Next code point read from the stream. - * @return {(number|!Array.)} Byte(s) to emit. - */ - this.handler = function(stream, code_point) { - // 1. If code point is end-of-stream, return finished. - if (code_point === end_of_stream) - return finished; - - // 2. If code point is in the range U+0000 to U+FFFF, inclusive, - // return the sequence resulting of converting code point to - // bytes using utf-16be encoder flag. - if (inRange(code_point, 0x0000, 0xFFFF)) - return convertCodeUnitToBytes(code_point, utf16_be); - - // 3. Let lead be ((code point − 0x10000) >> 10) + 0xD800, - // converted to bytes using utf-16be encoder flag. - var lead = convertCodeUnitToBytes( - ((code_point - 0x10000) >> 10) + 0xD800, utf16_be); - - // 4. Let trail be ((code point − 0x10000) & 0x3FF) + 0xDC00, - // converted to bytes using utf-16be encoder flag. - var trail = convertCodeUnitToBytes( - ((code_point - 0x10000) & 0x3FF) + 0xDC00, utf16_be); - - // 5. Return a byte sequence of lead followed by trail. - return lead.concat(trail); - }; - } - - // 15.3 utf-16be - // 15.3.1 utf-16be decoder - /** @param {{fatal: boolean}} options */ - encoders['UTF-16BE'] = function(options) { - return new UTF16Encoder(true, options); - }; - // 15.3.2 utf-16be encoder - /** @param {{fatal: boolean}} options */ - decoders['UTF-16BE'] = function(options) { - return new UTF16Decoder(true, options); - }; - - // 15.4 utf-16le - // 15.4.1 utf-16le decoder - /** @param {{fatal: boolean}} options */ - encoders['UTF-16LE'] = function(options) { - return new UTF16Encoder(false, options); - }; - // 15.4.2 utf-16le encoder - /** @param {{fatal: boolean}} options */ - decoders['UTF-16LE'] = function(options) { - return new UTF16Decoder(false, options); - }; - - // 15.5 x-user-defined - - // 15.5.1 x-user-defined decoder - /** - * @constructor - * @implements {Decoder} - * @param {{fatal: boolean}} options - */ - function XUserDefinedDecoder(options) { - options.fatal; - /** - * @param {Stream} stream The stream of bytes being decoded. - * @param {number} bite The next byte read from the stream. - * @return {?(number|!Array.)} The next code point(s) - * decoded, or null if not enough data exists in the input - * stream to decode a complete code point. - */ - this.handler = function(stream, bite) { - // 1. If byte is end-of-stream, return finished. - if (bite === end_of_stream) - return finished; - - // 2. If byte is an ASCII byte, return a code point whose value - // is byte. - if (isASCIIByte(bite)) - return bite; - - // 3. Return a code point whose value is 0xF780 + byte − 0x80. - return 0xF780 + bite - 0x80; - }; - } - - // 15.5.2 x-user-defined encoder - /** - * @constructor - * @implements {Encoder} - * @param {{fatal: boolean}} options - */ - function XUserDefinedEncoder(options) { - options.fatal; - /** - * @param {Stream} stream Input stream. - * @param {number} code_point Next code point read from the stream. - * @return {(number|!Array.)} Byte(s) to emit. - */ - this.handler = function(stream, code_point) { - // 1.If code point is end-of-stream, return finished. - if (code_point === end_of_stream) - return finished; - - // 2. If code point is an ASCII code point, return a byte whose - // value is code point. - if (isASCIICodePoint(code_point)) - return code_point; - - // 3. If code point is in the range U+F780 to U+F7FF, inclusive, - // return a byte whose value is code point − 0xF780 + 0x80. - if (inRange(code_point, 0xF780, 0xF7FF)) - return code_point - 0xF780 + 0x80; - - // 4. Return error with code point. - return encoderError(code_point); - }; - } - - /** @param {{fatal: boolean}} options */ - encoders['x-user-defined'] = function(options) { - return new XUserDefinedEncoder(options); - }; - /** @param {{fatal: boolean}} options */ - decoders['x-user-defined'] = function(options) { - return new XUserDefinedDecoder(options); - }; - - if (!global['TextEncoder']) - global['TextEncoder'] = TextEncoder; - if (!global['TextDecoder']) - global['TextDecoder'] = TextDecoder; - - if (module.exports) { - module.exports = { - TextEncoder: global['TextEncoder'], - TextDecoder: global['TextDecoder'], - EncodingIndexes: global["encoding-indexes"] - }; - } - - // For strict environments where `this` inside the global scope - // is `undefined`, take a pure object instead - }(commonjsGlobal || {})); - } (encoding)); - - // Copyright Joyent, Inc. and other Node contributors. - // - // Permission is hereby granted, free of charge, to any person obtaining a - // copy of this software and associated documentation files (the - // "Software"), to deal in the Software without restriction, including - // without limitation the rights to use, copy, modify, merge, publish, - // distribute, sublicense, and/or sell copies of the Software, and to permit - // persons to whom the Software is furnished to do so, subject to the - // following conditions: - // - // The above copyright notice and this permission notice shall be included - // in all copies or substantial portions of the Software. - // - // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - // USE OR OTHER DEALINGS IN THE SOFTWARE. - - var isBufferEncoding = Buffer.isEncoding - || function(encoding) { - switch (encoding && encoding.toLowerCase()) { - case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': case 'raw': return true; - default: return false; - } - }; - - - function assertEncoding(encoding) { - if (encoding && !isBufferEncoding(encoding)) { - throw new Error('Unknown encoding: ' + encoding); - } - } - - // StringDecoder provides an interface for efficiently splitting a series of - // buffers into a series of JS strings without breaking apart multi-byte - // characters. CESU-8 is handled as part of the UTF-8 encoding. - // - // @TODO Handling all encodings inside a single object makes it very difficult - // to reason about this code, so it should be split up in the future. - // @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code - // points as used by CESU-8. - function StringDecoder$1(encoding) { - this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, ''); - assertEncoding(encoding); - switch (this.encoding) { - case 'utf8': - // CESU-8 represents each of Surrogate Pair by 3-bytes - this.surrogateSize = 3; - break; - case 'ucs2': - case 'utf16le': - // UTF-16 represents each of Surrogate Pair by 2-bytes - this.surrogateSize = 2; - this.detectIncompleteChar = utf16DetectIncompleteChar; - break; - case 'base64': - // Base-64 stores 3 bytes in 4 chars, and pads the remainder. - this.surrogateSize = 3; - this.detectIncompleteChar = base64DetectIncompleteChar; - break; - default: - this.write = passThroughWrite; - return; - } - - // Enough space to store all bytes of a single character. UTF-8 needs 4 - // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate). - this.charBuffer = new Buffer(6); - // Number of bytes received for the current incomplete multi-byte character. - this.charReceived = 0; - // Number of bytes expected for the current incomplete multi-byte character. - this.charLength = 0; - } - - // write decodes the given buffer and returns it as JS string that is - // guaranteed to not contain any partial multi-byte characters. Any partial - // character found at the end of the buffer is buffered up, and will be - // returned when calling write again with the remaining bytes. - // - // Note: Converting a Buffer containing an orphan surrogate to a String - // currently works, but converting a String to a Buffer (via `new Buffer`, or - // Buffer#write) will replace incomplete surrogates with the unicode - // replacement character. See https://codereview.chromium.org/121173009/ . - StringDecoder$1.prototype.write = function(buffer) { - var charStr = ''; - // if our last write ended with an incomplete multibyte character - while (this.charLength) { - // determine how many remaining bytes this buffer has to offer for this char - var available = (buffer.length >= this.charLength - this.charReceived) ? - this.charLength - this.charReceived : - buffer.length; - - // add the new bytes to the char buffer - buffer.copy(this.charBuffer, this.charReceived, 0, available); - this.charReceived += available; - - if (this.charReceived < this.charLength) { - // still not enough chars in this buffer? wait for more ... - return ''; - } - - // remove bytes belonging to the current character from the buffer - buffer = buffer.slice(available, buffer.length); - - // get the character that was split - charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding); - - // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character - var charCode = charStr.charCodeAt(charStr.length - 1); - if (charCode >= 0xD800 && charCode <= 0xDBFF) { - this.charLength += this.surrogateSize; - charStr = ''; - continue; - } - this.charReceived = this.charLength = 0; - - // if there are no more bytes in this buffer, just emit our char - if (buffer.length === 0) { - return charStr; - } - break; - } - - // determine and set charLength / charReceived - this.detectIncompleteChar(buffer); - - var end = buffer.length; - if (this.charLength) { - // buffer the incomplete character bytes we got - buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end); - end -= this.charReceived; - } - - charStr += buffer.toString(this.encoding, 0, end); - - var end = charStr.length - 1; - var charCode = charStr.charCodeAt(end); - // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character - if (charCode >= 0xD800 && charCode <= 0xDBFF) { - var size = this.surrogateSize; - this.charLength += size; - this.charReceived += size; - this.charBuffer.copy(this.charBuffer, size, 0, size); - buffer.copy(this.charBuffer, 0, 0, size); - return charStr.substring(0, end); - } - - // or just emit the charStr - return charStr; - }; - - // detectIncompleteChar determines if there is an incomplete UTF-8 character at - // the end of the given buffer. If so, it sets this.charLength to the byte - // length that character, and sets this.charReceived to the number of bytes - // that are available for this character. - StringDecoder$1.prototype.detectIncompleteChar = function(buffer) { - // determine how many bytes we have to check at the end of this buffer - var i = (buffer.length >= 3) ? 3 : buffer.length; - - // Figure out if one of the last i bytes of our buffer announces an - // incomplete char. - for (; i > 0; i--) { - var c = buffer[buffer.length - i]; - - // See http://en.wikipedia.org/wiki/UTF-8#Description - - // 110XXXXX - if (i == 1 && c >> 5 == 0x06) { - this.charLength = 2; - break; - } - - // 1110XXXX - if (i <= 2 && c >> 4 == 0x0E) { - this.charLength = 3; - break; - } - - // 11110XXX - if (i <= 3 && c >> 3 == 0x1E) { - this.charLength = 4; - break; - } - } - this.charReceived = i; - }; - - StringDecoder$1.prototype.end = function(buffer) { - var res = ''; - if (buffer && buffer.length) - res = this.write(buffer); - - if (this.charReceived) { - var cr = this.charReceived; - var buf = this.charBuffer; - var enc = this.encoding; - res += buf.slice(0, cr).toString(enc); - } - - return res; - }; - - function passThroughWrite(buffer) { - return buffer.toString(this.encoding); - } - - function utf16DetectIncompleteChar(buffer) { - this.charReceived = buffer.length % 2; - this.charLength = this.charReceived ? 2 : 0; - } - - function base64DetectIncompleteChar(buffer) { - this.charReceived = buffer.length % 3; - this.charLength = this.charReceived ? 3 : 0; - } - - var stringDecoder = /*#__PURE__*/Object.freeze({ - __proto__: null, - StringDecoder: StringDecoder$1 - }); - - var require$$1 = /*@__PURE__*/getAugmentedNamespace(stringDecoder); - - var StringDecoder = require$$1.StringDecoder; - function defaultDecoder(data) { - var decoder = new StringDecoder(); - var out = decoder.write(data) + decoder.end(); - return out.replace(/\0/g, '').trim(); - } - var decoderBrowser = createDecoder$1; var regex = /^(?:ANSI\s)?(\d+)$/m; - function createDecoder$1(encoding, second) { + function createDecoder(encoding, second) { if (!encoding) { - return defaultDecoder; + return browserDecoder; } try { new TextDecoder(encoding.trim()); - } catch(e) { + } catch (e) { var match = regex.exec(encoding); if (match && !second) { - return createDecoder$1('windows-' + match[1], true); + return createDecoder('windows-' + match[1], true); } else { - return defaultDecoder; + encoding = undefined; + return browserDecoder; } } return browserDecoder; function browserDecoder(buffer) { - var decoder = new TextDecoder(encoding); + var decoder = new TextDecoder(encoding ? encoding : undefined); var out = decoder.decode(buffer, { stream: true }) + decoder.decode(); @@ -13602,13 +7816,12 @@ } } - var createDecoder = decoderBrowser; function dbfHeader(data) { var out = {}; - out.lastUpdated = new Date(data.readUInt8(1) + 1900, data.readUInt8(2), data.readUInt8(3)); - out.records = data.readUInt32LE(4); - out.headerLen = data.readUInt16LE(8); - out.recLen = data.readUInt16LE(10); + out.lastUpdated = new Date(data.getUint8(1) + 1900, data.getUint8(2), data.getUint8(3)); + out.records = data.getUint32(4, true); + out.headerLen = data.getUint16(8, true); + out.recLen = data.getUint16(10, true); return out; } @@ -13617,12 +7830,12 @@ var offset = 32; while (offset < headerLen) { out.push({ - name: decoder(data.slice(offset, offset + 11)), - dataType: String.fromCharCode(data.readUInt8(offset + 11)), - len: data.readUInt8(offset + 16), - decimal: data.readUInt8(offset + 17) + name: decoder(new Uint8Array(data.buffer.slice(data.byteOffset + offset, data.byteOffset + offset + 11))), + dataType: String.fromCharCode(data.getUint8(offset + 11)), + len: data.getUint8(offset + 16), + decimal: data.getUint8(offset + 17) }); - if (data.readUInt8(offset + 32) === 13) { + if (data.getUint8(offset + 32) === 13) { break; } else { offset += 32; @@ -13632,7 +7845,8 @@ } function rowFuncs(buffer, offset, len, type, decoder) { - var data = buffer.slice(offset, offset + len); + const data = new Uint8Array(buffer.buffer.slice(buffer.byteOffset + offset, buffer.byteOffset + offset + len)); + var textData = decoder(data); switch (type) { case 'N': @@ -13666,7 +7880,7 @@ return out; } - var parsedbf = function(buffer, encoding) { + function parseDbf (buffer, encoding) { var decoder = createDecoder(encoding); var header = dbfHeader(buffer); var rowHeaders = dbfRowHeader(buffer, header.headerLen - 1, decoder); @@ -13681,34 +7895,58 @@ records--; } return out; - }; - - var parseDbf = /*@__PURE__*/getDefaultExportFromCjs(parsedbf); + } const URL = globalThis.URL; - - function toBuffer(b) { + const toUitn8Arr = b => { if (!b) { throw new Error('forgot to pass buffer'); } - if (Buffer.isBuffer(b)) { - return b; - } if (isArrayBuffer(b)) { - return Buffer.from(b); + return new Uint8Array(b); } if (isArrayBuffer(b.buffer)) { if (b.BYTES_PER_ELEMENT === 1) { - return Buffer.from(b); + return b; } - return Buffer.from(b.buffer); + return new Uint8Array(b.buffer, b.byteOffset, b.byteLength); } - } + throw new Error('invalid buffer like object') + }; + const txtDecoder = new TextDecoder(); + const toString = (possibleString) => { + if (!possibleString) { + return; + } + if (typeof possibleString === 'string') { + return possibleString; + } + if (isArrayBuffer(possibleString) || ArrayBuffer.isView(possibleString) || isDataView(possibleString)) { + return txtDecoder.decode(possibleString); + } + }; + const toDataView = b => { + if (!b) { + throw new Error('forgot to pass buffer'); + } + if (isDataView(b)) { + return b; + } + if (isArrayBuffer(b)) { + return new DataView(b); + } + if (isArrayBuffer(b.buffer)) { + return new DataView(b.buffer, b.byteOffset, b.byteLength); + } + throw new Error('invalid buffer like object') + }; function isArrayBuffer(subject) { return subject instanceof globalThis.ArrayBuffer || Object.prototype.toString.call(subject) === '[object ArrayBuffer]'; } - + function isDataView(subject) { + return subject instanceof globalThis.DataView || Object.prototype.toString.call(subject) === '[object DataView]' + } const combine = function ([shp, dbf]) { const out = {}; @@ -13731,7 +7969,7 @@ }; const parseZip = async function (buffer, whiteList) { let key; - buffer = toBuffer(buffer); + buffer = toUitn8Arr(buffer); const zip = await unzip(buffer); const names = []; whiteList = whiteList || []; @@ -13810,13 +8048,31 @@ const url = new URL(base, globalThis?.document?.location); return url.pathname.slice(-4).toLowerCase() === suffix; }; + const fromObject = ({ shp, dbf, cpg, prj }) => { + const things = [ + _parseShp(shp, prj) + ]; + if (dbf) { + things.push(_parseDbf(dbf, cpg)); + } + return combine(things); + }; const getShapefile = async function (base, whiteList) { if (typeof base !== 'string') { - return parseZip(base); + if (isArrayBuffer(base) || ArrayBuffer.isView(base) || isDataView(base)) { + return parseZip(base); + } + if (base.shp) { + return fromObject(base); + } + throw new TypeError('must be a string, some sort of Buffer, or an object with at least a .shp property') } if (checkSuffix(base, '.zip')) { return getZip(base, whiteList); } + if (checkSuffix(base, '.shp')) { + base = base.slice(0, -4); + } const results = await Promise.all([ handleShp(base), handleDbf(base) @@ -13824,10 +8080,8 @@ return combine(results); }; const _parseShp = function (shp, prj) { - shp = toBuffer(shp); - if (Buffer.isBuffer(prj)) { - prj = prj.toString(); - } + shp = toDataView(shp); + prj = toString(prj); if (typeof prj === 'string') { try { prj = proj4(prj); @@ -13838,7 +8092,8 @@ return parseShp(shp, prj); }; const _parseDbf = function (dbf, cpg) { - dbf = toBuffer(dbf); + dbf = toDataView(dbf); + cpg = toString(cpg); return parseDbf(dbf, cpg); }; diff --git a/dist/shp.min.js b/dist/shp.min.js index b8557b5..4ae3fca 100644 --- a/dist/shp.min.js +++ b/dist/shp.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).shp=e()}(this,(function(){"use strict";var t=1,e=2,i=3,r=4,s=5,n=6378137,a=6356752.314,o=.0066943799901413165,h=484813681109536e-20,u=Math.PI/2,l=.16666666666666666,c=.04722222222222222,f=.022156084656084655,d=1e-10,p=.017453292519943295,m=57.29577951308232,g=Math.PI/4,_=2*Math.PI,y=3.14159265359,v={greenwich:0,lisbon:-9.131906111111,paris:2.337229166667,bogota:-74.080916666667,madrid:-3.687938888889,rome:12.452333333333,bern:7.439583333333,jakarta:106.807719444444,ferro:-17.666666666667,brussels:4.367975,stockholm:18.058277777778,athens:23.7163375,oslo:10.722916666667},b={ft:{to_meter:.3048},"us-ft":{to_meter:1200/3937}},w=/[\s_\-\/\(\)]/g;function M(t,e){if(t[e])return t[e];for(var i,r=Object.keys(t),s=e.toLowerCase().replace(w,""),n=-1;++n=this.text.length)return;t=this.text[this.place++]}switch(this.state){case k:return this.neutral(t);case 2:return this.keyword(t);case 4:return this.quoted(t);case 5:return this.afterquote(t);case 3:return this.number(t);case-1:return}},O.prototype.afterquote=function(t){if('"'===t)return this.word+='"',void(this.state=4);if(C.test(t))return this.word=this.word.trim(),void this.afterItem(t);throw new Error("havn't handled \""+t+'" in afterquote yet, index '+this.place)},O.prototype.afterItem=function(t){return","===t?(null!==this.word&&this.currentObject.push(this.word),this.word=null,void(this.state=k)):"]"===t?(this.level--,null!==this.word&&(this.currentObject.push(this.word),this.word=null),this.state=k,this.currentObject=this.stack.pop(),void(this.currentObject||(this.state=-1))):void 0},O.prototype.number=function(t){if(!I.test(t)){if(C.test(t))return this.word=parseFloat(this.word),void this.afterItem(t);throw new Error("havn't handled \""+t+'" in number yet, index '+this.place)}this.word+=t},O.prototype.quoted=function(t){'"'!==t?this.word+=t:this.state=5},O.prototype.keyword=function(t){if(S.test(t))this.word+=t;else{if("["===t){var e=[];return e.push(this.word),this.level++,null===this.root?this.root=e:this.currentObject.push(e),this.stack.push(this.currentObject),this.currentObject=e,void(this.state=k)}if(!C.test(t))throw new Error("havn't handled \""+t+'" in keyword yet, index '+this.place);this.afterItem(t)}},O.prototype.neutral=function(t){if(A.test(t))return this.word=t,void(this.state=2);if('"'===t)return this.word="",void(this.state=4);if(I.test(t))return this.word=t,void(this.state=3);if(!C.test(t))throw new Error("havn't handled \""+t+'" in neutral yet, index '+this.place);this.afterItem(t)},O.prototype.output=function(){for(;this.place0?90:-90)):(t.lat0=z(t.lat1>0?90:-90),t.lat_ts=t.lat1)}(s),s}function B(t){var e=this;if(2===arguments.length){var i=arguments[1];"string"==typeof i?"+"===i.charAt(0)?B[t]=x(arguments[1]):B[t]=T(arguments[1]):B[t]=i}else if(1===arguments.length){if(Array.isArray(t))return t.map((function(t){Array.isArray(t)?B.apply(e,t):B(t)}));if("string"==typeof t){if(t in B)return B[t]}else"EPSG"in t?B["EPSG:"+t.EPSG]=t:"ESRI"in t?B["ESRI:"+t.ESRI]=t:"IAU2000"in t?B["IAU2000:"+t.IAU2000]=t:console.log(t);return}}!function(t){t("EPSG:4326","+title=WGS 84 (long/lat) +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees"),t("EPSG:4269","+title=NAD83 (long/lat) +proj=longlat +a=6378137.0 +b=6356752.31414036 +ellps=GRS80 +datum=NAD83 +units=degrees"),t("EPSG:3857","+title=WGS 84 / Pseudo-Mercator +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs"),t.WGS84=t["EPSG:4326"],t["EPSG:3785"]=t["EPSG:3857"],t.GOOGLE=t["EPSG:3857"],t["EPSG:900913"]=t["EPSG:3857"],t["EPSG:102113"]=t["EPSG:3857"]}(B);var L=["PROJECTEDCRS","PROJCRS","GEOGCS","GEOCCS","PROJCS","LOCAL_CS","GEODCRS","GEODETICCRS","GEODETICDATUM","ENGCRS","ENGINEERINGCRS"];var D=["3857","900913","3785","102113"];function U(t){if(!function(t){return"string"==typeof t}(t))return t;if(function(t){return t in B}(t))return B[t];if(function(t){return L.some((function(e){return t.indexOf(e)>-1}))}(t)){var e=T(t);if(function(t){var e=M(t,"authority");if(e){var i=M(e,"epsg");return i&&D.indexOf(i)>-1}}(e))return B["EPSG:3857"];var i=function(t){var e=M(t,"extension");if(e)return M(e,"proj4")}(e);return i?x(i):e}return function(t){return"+"===t[0]}(t)?x(t):void 0}function j(t,e){var i,r;if(t=t||{},!e)return t;for(r in e)void 0!==(i=e[r])&&(t[r]=i);return t}function F(t,e,i){var r=t*e;return i/Math.sqrt(1-r*r)}function q(t){return t<0?-1:1}function G(t){return Math.abs(t)<=y?t:t-q(t)*_}function W(t,e,i){var r=t*i,s=.5*t;return r=Math.pow((1-r)/(1+r),s),Math.tan(.5*(u-e))/r}function Z(t,e){for(var i,r,s=.5*t,n=u-2*Math.atan(e),a=0;a<=15;a++)if(i=t*Math.sin(n),n+=r=u-2*Math.atan(e*Math.pow((1-i)/(1+i),s))-n,Math.abs(r)<=1e-10)return n;return-9999}function Y(t){return t}var H=[{init:function(){var t=this.b/this.a;this.es=1-t*t,"x0"in this||(this.x0=0),"y0"in this||(this.y0=0),this.e=Math.sqrt(this.es),this.lat_ts?this.sphere?this.k0=Math.cos(this.lat_ts):this.k0=F(this.e,Math.sin(this.lat_ts),Math.cos(this.lat_ts)):this.k0||(this.k?this.k0=this.k:this.k0=1)},forward:function(t){var e,i,r=t.x,s=t.y;if(s*m>90&&s*m<-90&&r*m>180&&r*m<-180)return null;if(Math.abs(Math.abs(s)-u)<=d)return null;if(this.sphere)e=this.x0+this.a*this.k0*G(r-this.long0),i=this.y0+this.a*this.k0*Math.log(Math.tan(g+.5*s));else{var n=Math.sin(s),a=W(this.e,s,n);e=this.x0+this.a*this.k0*G(r-this.long0),i=this.y0-this.a*this.k0*Math.log(a)}return t.x=e,t.y=i,t},inverse:function(t){var e,i,r=t.x-this.x0,s=t.y-this.y0;if(this.sphere)i=u-2*Math.atan(Math.exp(-s/(this.a*this.k0)));else{var n=Math.exp(-s/(this.a*this.k0));if(-9999===(i=Z(this.e,n)))return null}return e=G(this.long0+r/(this.a*this.k0)),t.x=e,t.y=i,t},names:["Mercator","Popular Visualisation Pseudo Mercator","Mercator_1SP","Mercator_Auxiliary_Sphere","merc"]},{init:function(){},forward:Y,inverse:Y,names:["longlat","identity"]}],K={},X=[];function J(t,e){var i=X.length;return t.names?(X[i]=t,t.names.forEach((function(t){K[t.toLowerCase()]=i})),this):(console.log(e),!0)}var Q={start:function(){H.forEach(J)},add:J,get:function(t){if(!t)return!1;var e=t.toLowerCase();return void 0!==K[e]&&X[K[e]]?X[K[e]]:void 0}},V={MERIT:{a:6378137,rf:298.257,ellipseName:"MERIT 1983"},SGS85:{a:6378136,rf:298.257,ellipseName:"Soviet Geodetic System 85"},GRS80:{a:6378137,rf:298.257222101,ellipseName:"GRS 1980(IUGG, 1980)"},IAU76:{a:6378140,rf:298.257,ellipseName:"IAU 1976"},airy:{a:6377563.396,b:6356256.91,ellipseName:"Airy 1830"},APL4:{a:6378137,rf:298.25,ellipseName:"Appl. Physics. 1965"},NWL9D:{a:6378145,rf:298.25,ellipseName:"Naval Weapons Lab., 1965"},mod_airy:{a:6377340.189,b:6356034.446,ellipseName:"Modified Airy"},andrae:{a:6377104.43,rf:300,ellipseName:"Andrae 1876 (Den., Iclnd.)"},aust_SA:{a:6378160,rf:298.25,ellipseName:"Australian Natl & S. Amer. 1969"},GRS67:{a:6378160,rf:298.247167427,ellipseName:"GRS 67(IUGG 1967)"},bessel:{a:6377397.155,rf:299.1528128,ellipseName:"Bessel 1841"},bess_nam:{a:6377483.865,rf:299.1528128,ellipseName:"Bessel 1841 (Namibia)"},clrk66:{a:6378206.4,b:6356583.8,ellipseName:"Clarke 1866"},clrk80:{a:6378249.145,rf:293.4663,ellipseName:"Clarke 1880 mod."},clrk80ign:{a:6378249.2,b:6356515,rf:293.4660213,ellipseName:"Clarke 1880 (IGN)"},clrk58:{a:6378293.645208759,rf:294.2606763692654,ellipseName:"Clarke 1858"},CPM:{a:6375738.7,rf:334.29,ellipseName:"Comm. des Poids et Mesures 1799"},delmbr:{a:6376428,rf:311.5,ellipseName:"Delambre 1810 (Belgium)"},engelis:{a:6378136.05,rf:298.2566,ellipseName:"Engelis 1985"},evrst30:{a:6377276.345,rf:300.8017,ellipseName:"Everest 1830"},evrst48:{a:6377304.063,rf:300.8017,ellipseName:"Everest 1948"},evrst56:{a:6377301.243,rf:300.8017,ellipseName:"Everest 1956"},evrst69:{a:6377295.664,rf:300.8017,ellipseName:"Everest 1969"},evrstSS:{a:6377298.556,rf:300.8017,ellipseName:"Everest (Sabah & Sarawak)"},fschr60:{a:6378166,rf:298.3,ellipseName:"Fischer (Mercury Datum) 1960"},fschr60m:{a:6378155,rf:298.3,ellipseName:"Fischer 1960"},fschr68:{a:6378150,rf:298.3,ellipseName:"Fischer 1968"},helmert:{a:6378200,rf:298.3,ellipseName:"Helmert 1906"},hough:{a:6378270,rf:297,ellipseName:"Hough"},intl:{a:6378388,rf:297,ellipseName:"International 1909 (Hayford)"},kaula:{a:6378163,rf:298.24,ellipseName:"Kaula 1961"},lerch:{a:6378139,rf:298.257,ellipseName:"Lerch 1979"},mprts:{a:6397300,rf:191,ellipseName:"Maupertius 1738"},new_intl:{a:6378157.5,b:6356772.2,ellipseName:"New International 1967"},plessis:{a:6376523,rf:6355863,ellipseName:"Plessis 1817 (France)"},krass:{a:6378245,rf:298.3,ellipseName:"Krassovsky, 1942"},SEasia:{a:6378155,b:6356773.3205,ellipseName:"Southeast Asia"},walbeck:{a:6376896,b:6355834.8467,ellipseName:"Walbeck"},WGS60:{a:6378165,rf:298.3,ellipseName:"WGS 60"},WGS66:{a:6378145,rf:298.25,ellipseName:"WGS 66"},WGS7:{a:6378135,rf:298.26,ellipseName:"WGS 72"}},$=V.WGS84={a:6378137,rf:298.257223563,ellipseName:"WGS 84"};V.sphere={a:6370997,b:6370997,ellipseName:"Normal Sphere (r=6370997)"};var tt={};tt.wgs84={towgs84:"0,0,0",ellipse:"WGS84",datumName:"WGS84"},tt.ch1903={towgs84:"674.374,15.056,405.346",ellipse:"bessel",datumName:"swiss"},tt.ggrs87={towgs84:"-199.87,74.79,246.62",ellipse:"GRS80",datumName:"Greek_Geodetic_Reference_System_1987"},tt.nad83={towgs84:"0,0,0",ellipse:"GRS80",datumName:"North_American_Datum_1983"},tt.nad27={nadgrids:"@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat",ellipse:"clrk66",datumName:"North_American_Datum_1927"},tt.potsdam={towgs84:"598.1,73.7,418.2,0.202,0.045,-2.455,6.7",ellipse:"bessel",datumName:"Potsdam Rauenberg 1950 DHDN"},tt.carthage={towgs84:"-263.0,6.0,431.0",ellipse:"clark80",datumName:"Carthage 1934 Tunisia"},tt.hermannskogel={towgs84:"577.326,90.129,463.919,5.137,1.474,5.297,2.4232",ellipse:"bessel",datumName:"Hermannskogel"},tt.militargeographische_institut={towgs84:"577.326,90.129,463.919,5.137,1.474,5.297,2.4232",ellipse:"bessel",datumName:"Militar-Geographische Institut"},tt.osni52={towgs84:"482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15",ellipse:"airy",datumName:"Irish National"},tt.ire65={towgs84:"482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15",ellipse:"mod_airy",datumName:"Ireland 1965"},tt.rassadiran={towgs84:"-133.63,-157.5,-158.62",ellipse:"intl",datumName:"Rassadiran"},tt.nzgd49={towgs84:"59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993",ellipse:"intl",datumName:"New Zealand Geodetic Datum 1949"},tt.osgb36={towgs84:"446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894",ellipse:"airy",datumName:"Airy 1830"},tt.s_jtsk={towgs84:"589,76,480",ellipse:"bessel",datumName:"S-JTSK (Ferro)"},tt.beduaram={towgs84:"-106,-87,188",ellipse:"clrk80",datumName:"Beduaram"},tt.gunung_segara={towgs84:"-403,684,41",ellipse:"bessel",datumName:"Gunung Segara Jakarta"},tt.rnb72={towgs84:"106.869,-52.2978,103.724,-0.33657,0.456955,-1.84218,1",ellipse:"intl",datumName:"Reseau National Belge 1972"};var et={};function it(t){if(0===t.length)return null;var e="@"===t[0];return e&&(t=t.slice(1)),"null"===t?{name:"null",mandatory:!e,grid:null,isNull:!0}:{name:t,mandatory:!e,grid:et[t]||null,isNull:!1}}function rt(t){return t/3600*Math.PI/180}function st(t,e,i){return String.fromCharCode.apply(null,new Uint8Array(t.buffer.slice(e,i)))}function nt(t){return t.map((function(t){return[rt(t.longitudeShift),rt(t.latitudeShift)]}))}function at(t,e,i){return{name:st(t,e+8,e+16).trim(),parent:st(t,e+24,e+24+8).trim(),lowerLatitude:t.getFloat64(e+72,i),upperLatitude:t.getFloat64(e+88,i),lowerLongitude:t.getFloat64(e+104,i),upperLongitude:t.getFloat64(e+120,i),latitudeInterval:t.getFloat64(e+136,i),longitudeInterval:t.getFloat64(e+152,i),gridNodeCount:t.getInt32(e+168,i)}}function ot(t,e,i,r){for(var s=e+176,n=[],a=0;a3&&(0===d.datum_params[3]&&0===d.datum_params[4]&&0===d.datum_params[5]&&0===d.datum_params[6]||(d.datum_type=e,d.datum_params[3]*=h,d.datum_params[4]*=h,d.datum_params[5]*=h,d.datum_params[6]=d.datum_params[6]/1e6+1))),f&&(d.datum_type=i,d.grids=f),d.a=o,d.b=u,d.es=l,d.ep2=c,d}(o.datumCode,o.datum_params,x.a,x.b,k.es,k.ep2,E);j(this,o),j(this,u),this.a=x.a,this.b=x.b,this.rf=x.rf,this.sphere=x.sphere,this.es=k.es,this.e=k.e,this.ep2=k.ep2,this.datum=A,this.init(),a(null,this)}else a(n)}else a(n)}function ut(t,e,i){var r,s,n,a,o=t.x,h=t.y,l=t.z?t.z:0;if(h<-u&&h>-1.001*u)h=-u;else if(h>u&&h<1.001*u)h=u;else{if(h<-u)return{x:-1/0,y:-1/0,z:t.z};if(h>u)return{x:1/0,y:1/0,z:t.z}}return o>Math.PI&&(o-=2*Math.PI),s=Math.sin(h),a=Math.cos(h),n=s*s,{x:((r=i/Math.sqrt(1-e*n))+l)*a*Math.cos(o),y:(r+l)*a*Math.sin(o),z:(r*(1-e)+l)*s}}function lt(t,e,i,r){var s,n,a,o,h,l,c,f,d,p,m,g,_,y,v,b=1e-12,w=t.x,M=t.y,x=t.z?t.z:0;if(s=Math.sqrt(w*w+M*M),n=Math.sqrt(w*w+M*M+x*x),s/i1e-24&&_<30);return{x:y,y:Math.atan(m/Math.abs(p)),z:v}}function ct(i){return i===t||i===e}function ft(r,h,u){if(function(i,r){return i.datum_type===r.datum_type&&!(i.a!==r.a||Math.abs(i.es-r.es)>5e-11)&&(i.datum_type===t?i.datum_params[0]===r.datum_params[0]&&i.datum_params[1]===r.datum_params[1]&&i.datum_params[2]===r.datum_params[2]:i.datum_type!==e||i.datum_params[0]===r.datum_params[0]&&i.datum_params[1]===r.datum_params[1]&&i.datum_params[2]===r.datum_params[2]&&i.datum_params[3]===r.datum_params[3]&&i.datum_params[4]===r.datum_params[4]&&i.datum_params[5]===r.datum_params[5]&&i.datum_params[6]===r.datum_params[6])}(r,h))return u;if(r.datum_type===s||h.datum_type===s)return u;var l=r.a,c=r.es;if(r.datum_type===i){if(0!==dt(r,!1,u))return;l=n,c=o}var f=h.a,d=h.b,p=h.es;if(h.datum_type===i&&(f=n,d=a,p=o),c===p&&l===f&&!ct(r.datum_type)&&!ct(h.datum_type))return u;if((u=ut(u,c,l),ct(r.datum_type)&&(u=function(i,r,s){if(r===t)return{x:i.x+s[0],y:i.y+s[1],z:i.z+s[2]};if(r===e){var n=s[0],a=s[1],o=s[2],h=s[3],u=s[4],l=s[5],c=s[6];return{x:c*(i.x-l*i.y+u*i.z)+n,y:c*(l*i.x+i.y-h*i.z)+a,z:c*(-u*i.x+h*i.y+i.z)+o}}}(u,r.datum_type,r.datum_params)),ct(h.datum_type)&&(u=function(i,r,s){if(r===t)return{x:i.x-s[0],y:i.y-s[1],z:i.z-s[2]};if(r===e){var n=s[0],a=s[1],o=s[2],h=s[3],u=s[4],l=s[5],c=s[6],f=(i.x-n)/c,d=(i.y-a)/c,p=(i.z-o)/c;return{x:f+l*d-u*p,y:-l*f+d+h*p,z:u*f-h*d+p}}}(u,h.datum_type,h.datum_params)),u=lt(u,p,f,d),h.datum_type===i)&&0!==dt(h,!0,u))return;return u}function dt(t,e,i){if(null===t.grids||0===t.grids.length)return console.log("Grid shift grids not found"),-1;var r={x:-i.x,y:i.y},s={x:Number.NaN,y:Number.NaN},n=[];t:for(var a=0;ar.y||d>r.x||_1e-12&&Math.abs(a.y)>1e-12);if(h<0)return console.log("Inverse grid shift iterator failed to converge."),r;r.x=G(n.x+i.ll[0]),r.y=n.y+i.ll[1]}else isNaN(n.x)||(r.x=t.x+n.x,r.y=t.y+n.y);return r}function mt(t,e){var i,r={x:t.x/e.del[0],y:t.y/e.del[1]},s=Math.floor(r.x),n=Math.floor(r.y),a=r.x-1*s,o=r.y-1*n,h={x:Number.NaN,y:Number.NaN};if(s<0||s>=e.lim[0])return h;if(n<0||n>=e.lim[1])return h;i=n*e.lim[0]+s;var u=e.cvs[i][0],l=e.cvs[i][1];i++;var c=e.cvs[i][0],f=e.cvs[i][1];i+=e.lim[0];var d=e.cvs[i][0],p=e.cvs[i][1];i--;var m=e.cvs[i][0],g=e.cvs[i][1],_=a*o,y=a*(1-o),v=(1-a)*(1-o),b=(1-a)*o;return h.x=v*u+y*c+b*m+_*d,h.y=v*l+y*f+b*g+_*p,h}function gt(t,e,i){var r,s,n,a=i.x,o=i.y,h=i.z||0,u={};for(n=0;n<3;n++)if(!e||2!==n||void 0!==i.z)switch(0===n?(r=a,s=-1!=="ew".indexOf(t.axis[n])?"x":"y"):1===n?(r=o,s=-1!=="ns".indexOf(t.axis[n])?"y":"x"):(r=h,s="z"),t.axis[n]){case"e":case"n":u[s]=r;break;case"w":case"s":u[s]=-r;break;case"u":void 0!==i[s]&&(u.z=r);break;case"d":void 0!==i[s]&&(u.z=-r);break;default:return null}return u}function _t(t){var e={x:t[0],y:t[1]};return t.length>2&&(e.z=t[2]),t.length>3&&(e.m=t[3]),e}function yt(t){if("function"==typeof Number.isFinite){if(Number.isFinite(t))return;throw new TypeError("coordinates must be finite numbers")}if("number"!=typeof t||t!=t||!isFinite(t))throw new TypeError("coordinates must be finite numbers")}function vt(r,s,n,a){var o,h=void 0!==(n=Array.isArray(n)?_t(n):{x:n.x,y:n.y,z:n.z,m:n.m}).z;if(function(t){yt(t.x),yt(t.y)}(n),r.datum&&s.datum&&function(r,s){return(r.datum.datum_type===t||r.datum.datum_type===e||r.datum.datum_type===i)&&"WGS84"!==s.datumCode||(s.datum.datum_type===t||s.datum.datum_type===e||s.datum.datum_type===i)&&"WGS84"!==r.datumCode}(r,s)&&(n=vt(r,o=new ht("WGS84"),n,a),r=o),a&&"enu"!==r.axis&&(n=gt(r,!1,n)),"longlat"===r.projName)n={x:n.x*p,y:n.y*p,z:n.z||0};else if(r.to_meter&&(n={x:n.x*r.to_meter,y:n.y*r.to_meter,z:n.z||0}),!(n=r.inverse(n)))return;if(r.from_greenwich&&(n.x+=r.from_greenwich),n=ft(r.datum,s.datum,n))return s.from_greenwich&&(n={x:n.x-s.from_greenwich,y:n.y,z:n.z||0}),"longlat"===s.projName?n={x:n.x*m,y:n.y*m,z:n.z||0}:(n=s.forward(n),s.to_meter&&(n={x:n.x/s.to_meter,y:n.y/s.to_meter,z:n.z||0})),a&&"enu"!==s.axis?gt(s,!0,n):(n&&!h&&delete n.z,n)}ht.projections=Q,ht.projections.start();var bt=ht("WGS84");function wt(t,e,i,r){var s,n,a;return Array.isArray(i)?(s=vt(t,e,i,r)||{x:NaN,y:NaN},i.length>2?void 0!==t.name&&"geocent"===t.name||void 0!==e.name&&"geocent"===e.name?"number"==typeof s.z?[s.x,s.y,s.z].concat(i.splice(3)):[s.x,s.y,i[2]].concat(i.splice(3)):[s.x,s.y].concat(i.splice(2)):[s.x,s.y]):(n=vt(t,e,i,r),2===(a=Object.keys(i)).length||a.forEach((function(r){if(void 0!==t.name&&"geocent"===t.name||void 0!==e.name&&"geocent"===e.name){if("x"===r||"y"===r||"z"===r)return}else if("x"===r||"y"===r)return;n[r]=i[r]})),n)}function Mt(t){return t instanceof ht?t:t.oProj?t.oProj:ht(t)}function xt(t,e,i){t=Mt(t);var r,s=!1;return void 0===e?(e=t,t=bt,s=!0):(void 0!==e.x||Array.isArray(e))&&(i=e,e=t,t=bt,s=!0),e=Mt(e),i?wt(t,e,i):(r={forward:function(i,r){return wt(t,e,i,r)},inverse:function(i,r){return wt(e,t,i,r)}},s&&(r.oProj=e),r)}var kt=6,Et="AJSAJS",At="AFAFAF",St=65,Ct=73,It=79,Ot=86,Pt=90,Rt={forward:Nt,inverse:function(t){var e=Lt(jt(t.toUpperCase()));if(e.lat&&e.lon)return[e.lon,e.lat,e.lon,e.lat];return[e.left,e.bottom,e.right,e.top]},toPoint:zt};function Nt(t,e){return e=e||5,function(t,e){var i="00000"+t.easting,r="00000"+t.northing;return t.zoneNumber+t.zoneLetter+(d=t.easting,p=t.northing,m=t.zoneNumber,g=Ut(m),_=Math.floor(d/1e5),y=Math.floor(p/1e5)%20,s=_,n=y,a=g,o=a-1,h=Et.charCodeAt(o),u=At.charCodeAt(o),l=h+s-1,c=u+n,f=!1,l>Pt&&(l=l-Pt+St-1,f=!0),(l===Ct||hCt||(l>Ct||hIt||(l>It||hPt&&(l=l-Pt+St-1),c>Ot?(c=c-Ot+St-1,f=!0):f=!1,(c===Ct||uCt||(c>Ct||uIt||(c>It||uOt&&(c=c-Ot+St-1),String.fromCharCode(l)+String.fromCharCode(c))+i.substr(i.length-5,e)+r.substr(r.length-5,e);var s,n,a,o,h,u,l,c,f;var d,p,m,g,_,y}(function(t){var e,i,r,s,n,a,o,h,u=t.lat,l=t.lon,c=6378137,f=.00669438,d=.9996,p=Tt(u),m=Tt(l);h=Math.floor((l+180)/6)+1,180===l&&(h=60);u>=56&&u<64&&l>=3&&l<12&&(h=32);u>=72&&u<84&&(l>=0&&l<9?h=31:l>=9&&l<21?h=33:l>=21&&l<33?h=35:l>=33&&l<42&&(h=37));o=Tt(6*(h-1)-180+3),e=f/(1-f),i=c/Math.sqrt(1-f*Math.sin(p)*Math.sin(p)),r=Math.tan(p)*Math.tan(p),s=e*Math.cos(p)*Math.cos(p),n=Math.cos(p)*(m-o),a=c*((1-f/4-3*f*f/64-5*f*f*f/256)*p-(3*f/8+3*f*f/32+45*f*f*f/1024)*Math.sin(2*p)+(15*f*f/256+45*f*f*f/1024)*Math.sin(4*p)-35*f*f*f/3072*Math.sin(6*p));var g=d*i*(n+(1-r+s)*n*n*n/6+(5-18*r+r*r+72*s-58*e)*n*n*n*n*n/120)+5e5,_=d*(a+i*Math.tan(p)*(n*n/2+(5-r+9*s+4*s*s)*n*n*n*n/24+(61-58*r+r*r+600*s-330*e)*n*n*n*n*n*n/720));u<0&&(_+=1e7);return{northing:Math.round(_),easting:Math.round(g),zoneNumber:h,zoneLetter:Dt(u)}}({lat:t[1],lon:t[0]}),e)}function zt(t){var e=Lt(jt(t.toUpperCase()));return e.lat&&e.lon?[e.lon,e.lat]:[(e.left+e.right)/2,(e.top+e.bottom)/2]}function Tt(t){return t*(Math.PI/180)}function Bt(t){return t/Math.PI*180}function Lt(t){var e=t.northing,i=t.easting,r=t.zoneLetter,s=t.zoneNumber;if(s<0||s>60)return null;var n,a,o,h,u,l,c,f,d,p=.9996,m=6378137,g=.00669438,_=(1-Math.sqrt(.99330562))/(1+Math.sqrt(.99330562)),y=i-5e5,v=e;r<"N"&&(v-=1e7),c=6*(s-1)-180+3,n=.006739496752268451,d=(f=v/p/6367449.145945056)+(3*_/2-27*_*_*_/32)*Math.sin(2*f)+(21*_*_/16-55*_*_*_*_/32)*Math.sin(4*f)+151*_*_*_/96*Math.sin(6*f),a=m/Math.sqrt(1-g*Math.sin(d)*Math.sin(d)),o=Math.tan(d)*Math.tan(d),h=n*Math.cos(d)*Math.cos(d),u=.99330562*m/Math.pow(1-g*Math.sin(d)*Math.sin(d),1.5),l=y/(a*p);var b=d-a*Math.tan(d)/u*(l*l/2-(5+3*o+10*h-4*h*h-9*n)*l*l*l*l/24+(61+90*o+298*h+45*o*o-1.6983531815716497-3*h*h)*l*l*l*l*l*l/720);b=Bt(b);var w,M=(l-(1+2*o+h)*l*l*l/6+(5-2*h+28*o-3*h*h+8*n+24*o*o)*l*l*l*l*l/120)/Math.cos(d);if(M=c+Bt(M),t.accuracy){var x=Lt({northing:t.northing+t.accuracy,easting:t.easting+t.accuracy,zoneLetter:t.zoneLetter,zoneNumber:t.zoneNumber});w={top:x.lat,right:x.lon,bottom:b,left:M}}else w={lat:b,lon:M};return w}function Dt(t){var e="Z";return 84>=t&&t>=72?e="X":72>t&&t>=64?e="W":64>t&&t>=56?e="V":56>t&&t>=48?e="U":48>t&&t>=40?e="T":40>t&&t>=32?e="S":32>t&&t>=24?e="R":24>t&&t>=16?e="Q":16>t&&t>=8?e="P":8>t&&t>=0?e="N":0>t&&t>=-8?e="M":-8>t&&t>=-16?e="L":-16>t&&t>=-24?e="K":-24>t&&t>=-32?e="J":-32>t&&t>=-40?e="H":-40>t&&t>=-48?e="G":-48>t&&t>=-56?e="F":-56>t&&t>=-64?e="E":-64>t&&t>=-72?e="D":-72>t&&t>=-80&&(e="C"),e}function Ut(t){var e=t%kt;return 0===e&&(e=kt),e}function jt(t){if(t&&0===t.length)throw"MGRSPoint coverting from nothing";for(var e,i=t.length,r=null,s="",n=0;!/[A-Z]/.test(e=t.charAt(n));){if(n>=2)throw"MGRSPoint bad conversion from: "+t;s+=e,n++}var a=parseInt(s,10);if(0===n||n+3>i)throw"MGRSPoint bad conversion from: "+t;var o=t.charAt(n++);if(o<="A"||"B"===o||"Y"===o||o>="Z"||"I"===o||"O"===o)throw"MGRSPoint zone letter "+o+" not handled: "+t;r=t.substring(n,n+=2);for(var h=Ut(a),u=function(t,e){var i=Et.charCodeAt(e-1),r=1e5,s=!1;for(;i!==t.charCodeAt(0);){if(++i===Ct&&i++,i===It&&i++,i>Pt){if(s)throw"Bad character: "+t;i=St,s=!0}r+=1e5}return r}(r.charAt(0),h),l=function(t,e){if(t>"V")throw"MGRSPoint given invalid Northing "+t;var i=At.charCodeAt(e-1),r=0,s=!1;for(;i!==t.charCodeAt(0);){if(++i===Ct&&i++,i===It&&i++,i>Ot){if(s)throw"Bad character: "+t;i=St,s=!0}r+=1e5}return r}(r.charAt(1),h);l0&&(f=1e5/Math.pow(10,m),d=t.substring(n,n+m),g=parseFloat(d)*f,p=t.substring(n+m),_=parseFloat(p)*f),{easting:g+u,northing:_+l,zoneLetter:o,zoneNumber:a,accuracy:f}}function Ft(t){var e;switch(t){case"C":e=11e5;break;case"D":e=2e6;break;case"E":e=28e5;break;case"F":e=37e5;break;case"G":e=46e5;break;case"H":e=55e5;break;case"J":e=64e5;break;case"K":e=73e5;break;case"L":e=82e5;break;case"M":e=91e5;break;case"N":e=0;break;case"P":e=8e5;break;case"Q":e=17e5;break;case"R":e=26e5;break;case"S":e=35e5;break;case"T":e=44e5;break;case"U":e=53e5;break;case"V":e=62e5;break;case"W":e=7e6;break;case"X":e=79e5;break;default:e=-1}if(e>=0)return e;throw"Invalid zone letter: "+t}function qt(t,e,i){if(!(this instanceof qt))return new qt(t,e,i);if(Array.isArray(t))this.x=t[0],this.y=t[1],this.z=t[2]||0;else if("object"==typeof t)this.x=t.x,this.y=t.y,this.z=t.z||0;else if("string"==typeof t&&void 0===e){var r=t.split(",");this.x=parseFloat(r[0],10),this.y=parseFloat(r[1],10),this.z=parseFloat(r[2],10)||0}else this.x=t,this.y=e,this.z=i||0;console.warn("proj4.Point will be removed in version 3, use proj4.toPoint")}qt.fromMGRS=function(t){return new qt(zt(t))},qt.prototype.toMGRS=function(t){return Nt([this.x,this.y],t)};var Gt=1,Wt=.25,Zt=.046875,Yt=.01953125,Ht=.01068115234375,Kt=.75,Xt=.46875,Jt=.013020833333333334,Qt=.007120768229166667,Vt=.3645833333333333,$t=.005696614583333333,te=.3076171875;function ee(t){var e=[];e[0]=Gt-t*(Wt+t*(Zt+t*(Yt+t*Ht))),e[1]=t*(Kt-t*(Zt+t*(Yt+t*Ht)));var i=t*t;return e[2]=i*(Xt-t*(Jt+t*Qt)),i*=t,e[3]=i*(Vt-t*$t),e[4]=i*t*te,e}function ie(t,e,i,r){return i*=e,e*=e,r[0]*t-i*(r[1]+e*(r[2]+e*(r[3]+e*r[4])))}var re=20;function se(t,e,i){for(var r=1/(1-e),s=t,n=re;n;--n){var a=Math.sin(s),o=1-e*a*a;if(s-=o=(ie(s,a,Math.cos(s),i)-t)*(o*Math.sqrt(o))*r,Math.abs(o)d?Math.tan(n):0,m=Math.pow(p,2),g=Math.pow(m,2);e=1-this.es*Math.pow(o,2),u/=Math.sqrt(e);var _=ie(n,o,h,this.en);i=this.a*(this.k0*u*(1+l/6*(1-m+c+l/20*(5-18*m+g+14*c-58*m*c+l/42*(61+179*g-g*m-479*m)))))+this.x0,r=this.a*(this.k0*(_-this.ml0+o*a*u/2*(1+l/12*(5-m+9*c+4*f+l/30*(61+g-58*m+270*c-330*m*c+l/56*(1385+543*g-g*m-3111*m))))))+this.y0}else{var y=h*Math.sin(a);if(Math.abs(Math.abs(y)-1)=1){if(y-1>d)return 93;r=0}else r=Math.acos(r);n<0&&(r=-r),r=this.a*this.k0*(r-this.lat0)+this.y0}return t.x=i,t.y=r,t},inverse:function(t){var e,i,r,s,n=(t.x-this.x0)*(1/this.a),a=(t.y-this.y0)*(1/this.a);if(this.es)if(i=se(e=this.ml0+a/this.k0,this.es,this.en),Math.abs(i)d?Math.tan(i):0,c=this.ep2*Math.pow(h,2),f=Math.pow(c,2),p=Math.pow(l,2),m=Math.pow(p,2);e=1-this.es*Math.pow(o,2);var g=n*Math.sqrt(e)/this.k0,_=Math.pow(g,2);r=i-(e*=l)*_/(1-this.es)*.5*(1-_/12*(5+3*p-9*c*p+c-4*f-_/30*(61+90*p-252*c*p+45*m+46*c-_/56*(1385+3633*p+4095*m+1574*m*p)))),s=G(this.long0+g*(1-_/6*(1+2*p+c-_/20*(5+28*p+24*m+8*c*p+6*c-_/42*(61+662*p+1320*m+720*m*p))))/h)}else r=u*q(a),s=0;else{var y=Math.exp(n/this.k0),v=.5*(y-1/y),b=this.lat0+a/this.k0,w=Math.cos(b);e=Math.sqrt((1-Math.pow(w,2))/(1+Math.pow(v,2))),r=Math.asin(e),a<0&&(r=-r),s=0===v&&0===w?0:G(Math.atan2(v,w)+this.long0)}return t.x=s,t.y=r,t},names:["Fast_Transverse_Mercator","Fast Transverse Mercator"]};function ae(t){var e=Math.exp(t);return e=(e-1/e)/2}function oe(t,e){t=Math.abs(t),e=Math.abs(e);var i=Math.max(t,e),r=Math.min(t,e)/(i||1);return i*Math.sqrt(1+Math.pow(r,2))}function he(t){var e=Math.abs(t);return e=function(t){var e=1+t,i=e-1;return 0===i?t:t*Math.log(e)/i}(e*(1+e/(oe(1,e)+1))),t<0?-e:e}function ue(t,e){for(var i,r=2*Math.cos(2*e),s=t.length-1,n=t[s],a=0;--s>=0;)i=r*n-a+t[s],a=n,n=i;return e+i*Math.sin(2*e)}function le(t,e,i){for(var r,s,n=Math.sin(e),a=Math.cos(e),o=ae(i),h=function(t){var e=Math.exp(t);return(e+1/e)/2}(i),u=2*a*h,l=-2*n*o,c=t.length-1,f=t[c],d=0,p=0,m=0;--c>=0;)r=p,s=d,f=u*(p=f)-r-l*(d=m)+t[c],m=l*p-s+u*d;return[(u=n*h)*f-(l=a*o)*m,u*m+l*f]}var ce={init:function(){if(!this.approx&&(isNaN(this.es)||this.es<=0))throw new Error('Incorrect elliptical usage. Try using the +approx option in the proj string, or PROJECTION["Fast_Transverse_Mercator"] in the WKT.');this.approx&&(ne.init.apply(this),this.forward=ne.forward,this.inverse=ne.inverse),this.x0=void 0!==this.x0?this.x0:0,this.y0=void 0!==this.y0?this.y0:0,this.long0=void 0!==this.long0?this.long0:0,this.lat0=void 0!==this.lat0?this.lat0:0,this.cgb=[],this.cbg=[],this.utg=[],this.gtu=[];var t=this.es/(1+Math.sqrt(1-this.es)),e=t/(2-t),i=e;this.cgb[0]=e*(2+e*(-2/3+e*(e*(116/45+e*(26/45+e*(-2854/675)))-2))),this.cbg[0]=e*(e*(2/3+e*(4/3+e*(-82/45+e*(32/45+e*(4642/4725)))))-2),i*=e,this.cgb[1]=i*(7/3+e*(e*(-227/45+e*(2704/315+e*(2323/945)))-1.6)),this.cbg[1]=i*(5/3+e*(-16/15+e*(-13/9+e*(904/315+e*(-1522/945))))),i*=e,this.cgb[2]=i*(56/15+e*(-136/35+e*(-1262/105+e*(73814/2835)))),this.cbg[2]=i*(-26/15+e*(34/21+e*(1.6+e*(-12686/2835)))),i*=e,this.cgb[3]=i*(4279/630+e*(-332/35+e*(-399572/14175))),this.cbg[3]=i*(1237/630+e*(e*(-24832/14175)-2.4)),i*=e,this.cgb[4]=i*(4174/315+e*(-144838/6237)),this.cbg[4]=i*(-734/315+e*(109598/31185)),i*=e,this.cgb[5]=i*(601676/22275),this.cbg[5]=i*(444337/155925),i=Math.pow(e,2),this.Qn=this.k0/(1+e)*(1+i*(1/4+i*(1/64+i/256))),this.utg[0]=e*(e*(2/3+e*(-37/96+e*(1/360+e*(81/512+e*(-96199/604800)))))-.5),this.gtu[0]=e*(.5+e*(-2/3+e*(5/16+e*(41/180+e*(-127/288+e*(7891/37800)))))),this.utg[1]=i*(-1/48+e*(-1/15+e*(437/1440+e*(-46/105+e*(1118711/3870720))))),this.gtu[1]=i*(13/48+e*(e*(557/1440+e*(281/630+e*(-1983433/1935360)))-.6)),i*=e,this.utg[2]=i*(-17/480+e*(37/840+e*(209/4480+e*(-5569/90720)))),this.gtu[2]=i*(61/240+e*(-103/140+e*(15061/26880+e*(167603/181440)))),i*=e,this.utg[3]=i*(-4397/161280+e*(11/504+e*(830251/7257600))),this.gtu[3]=i*(49561/161280+e*(-179/168+e*(6601661/7257600))),i*=e,this.utg[4]=i*(-4583/161280+e*(108847/3991680)),this.gtu[4]=i*(34729/80640+e*(-3418889/1995840)),i*=e,this.utg[5]=i*(-20648693/638668800),this.gtu[5]=.6650675310896665*i;var r=ue(this.cbg,this.lat0);this.Zb=-this.Qn*(r+function(t,e){for(var i,r=2*Math.cos(e),s=t.length-1,n=t[s],a=0;--s>=0;)i=r*n-a+t[s],a=n,n=i;return Math.sin(e)*i}(this.gtu,2*r))},forward:function(t){var e=G(t.x-this.long0),i=t.y;i=ue(this.cbg,i);var r=Math.sin(i),s=Math.cos(i),n=Math.sin(e),a=Math.cos(e);i=Math.atan2(r,a*s),e=Math.atan2(n*s,oe(r,s*a)),e=he(Math.tan(e));var o,h,u=le(this.gtu,2*i,2*e);return i+=u[0],e+=u[1],Math.abs(e)<=2.623395162778?(o=this.a*(this.Qn*e)+this.x0,h=this.a*(this.Qn*i+this.Zb)+this.y0):(o=1/0,h=1/0),t.x=o,t.y=h,t},inverse:function(t){var e,i,r=(t.x-this.x0)*(1/this.a),s=(t.y-this.y0)*(1/this.a);if(s=(s-this.Zb)/this.Qn,r/=this.Qn,Math.abs(r)<=2.623395162778){var n=le(this.utg,2*s,2*r);s+=n[0],r+=n[1],r=Math.atan(ae(r));var a=Math.sin(s),o=Math.cos(s),h=Math.sin(r),u=Math.cos(r);s=Math.atan2(a*u,oe(h,u*o)),e=G((r=Math.atan2(h,u*o))+this.long0),i=ue(this.cgb,s)}else e=1/0,i=1/0;return t.x=e,t.y=i,t},names:["Extended_Transverse_Mercator","Extended Transverse Mercator","etmerc","Transverse_Mercator","Transverse Mercator","Gauss Kruger","Gauss_Kruger","tmerc"]};var fe={init:function(){var t=function(t,e){if(void 0===t){if((t=Math.floor(30*(G(e)+Math.PI)/Math.PI)+1)<0)return 0;if(t>60)return 60}return t}(this.zone,this.long0);if(void 0===t)throw new Error("unknown utm zone");this.lat0=0,this.long0=(6*Math.abs(t)-183)*p,this.x0=5e5,this.y0=this.utmSouth?1e7:0,this.k0=.9996,ce.init.apply(this),this.forward=ce.forward,this.inverse=ce.inverse},names:["Universal Transverse Mercator System","utm"],dependsOn:"etmerc"};function de(t,e){return Math.pow((1-t)/(1+t),e)}var pe={init:function(){var t=Math.sin(this.lat0),e=Math.cos(this.lat0);e*=e,this.rc=Math.sqrt(1-this.es)/(1-this.es*t*t),this.C=Math.sqrt(1+this.es*e*e/(1-this.es)),this.phic0=Math.asin(t/this.C),this.ratexp=.5*this.C*this.e,this.K=Math.tan(.5*this.phic0+g)/(Math.pow(Math.tan(.5*this.lat0+g),this.C)*de(this.e*t,this.ratexp))},forward:function(t){var e=t.x,i=t.y;return t.y=2*Math.atan(this.K*Math.pow(Math.tan(.5*i+g),this.C)*de(this.e*Math.sin(i),this.ratexp))-u,t.x=this.C*e,t},inverse:function(t){for(var e=t.x/this.C,i=t.y,r=Math.pow(Math.tan(.5*i+g)/this.K,1/this.C),s=20;s>0&&(i=2*Math.atan(r*de(this.e*Math.sin(t.y),-.5*this.e))-u,!(Math.abs(i-t.y)<1e-14));--s)t.y=i;return s?(t.x=e,t.y=i,t):null},names:["gauss"]};var me={init:function(){pe.init.apply(this),this.rc&&(this.sinc0=Math.sin(this.phic0),this.cosc0=Math.cos(this.phic0),this.R2=2*this.rc,this.title||(this.title="Oblique Stereographic Alternative"))},forward:function(t){var e,i,r,s;return t.x=G(t.x-this.long0),pe.forward.apply(this,[t]),e=Math.sin(t.y),i=Math.cos(t.y),r=Math.cos(t.x),s=this.k0*this.R2/(1+this.sinc0*e+this.cosc0*i*r),t.x=s*i*Math.sin(t.x),t.y=s*(this.cosc0*e-this.sinc0*i*r),t.x=this.a*t.x+this.x0,t.y=this.a*t.y+this.y0,t},inverse:function(t){var e,i,r,s,n;if(t.x=(t.x-this.x0)/this.a,t.y=(t.y-this.y0)/this.a,t.x/=this.k0,t.y/=this.k0,n=oe(t.x,t.y)){var a=2*Math.atan2(n,this.R2);e=Math.sin(a),i=Math.cos(a),s=Math.asin(i*this.sinc0+t.y*e*this.cosc0/n),r=Math.atan2(t.x*e,n*this.cosc0*i-t.y*this.sinc0*e)}else s=this.phic0,r=0;return t.x=r,t.y=s,pe.inverse.apply(this,[t]),t.x=G(t.x+this.long0),t},names:["Stereographic_North_Pole","Oblique_Stereographic","sterea","Oblique Stereographic Alternative","Double_Stereographic"]};var ge={init:function(){this.x0=this.x0||0,this.y0=this.y0||0,this.lat0=this.lat0||0,this.long0=this.long0||0,this.coslat0=Math.cos(this.lat0),this.sinlat0=Math.sin(this.lat0),this.sphere?1===this.k0&&!isNaN(this.lat_ts)&&Math.abs(this.coslat0)<=d&&(this.k0=.5*(1+q(this.lat0)*Math.sin(this.lat_ts))):(Math.abs(this.coslat0)<=d&&(this.lat0>0?this.con=1:this.con=-1),this.cons=Math.sqrt(Math.pow(1+this.e,1+this.e)*Math.pow(1-this.e,1-this.e)),1===this.k0&&!isNaN(this.lat_ts)&&Math.abs(this.coslat0)<=d&&Math.abs(Math.cos(this.lat_ts))>d&&(this.k0=.5*this.cons*F(this.e,Math.sin(this.lat_ts),Math.cos(this.lat_ts))/W(this.e,this.con*this.lat_ts,this.con*Math.sin(this.lat_ts))),this.ms1=F(this.e,this.sinlat0,this.coslat0),this.X0=2*Math.atan(this.ssfn_(this.lat0,this.sinlat0,this.e))-u,this.cosX0=Math.cos(this.X0),this.sinX0=Math.sin(this.X0))},forward:function(t){var e,i,r,s,n,a,o=t.x,h=t.y,l=Math.sin(h),c=Math.cos(h),f=G(o-this.long0);return Math.abs(Math.abs(o-this.long0)-Math.PI)<=d&&Math.abs(h+this.lat0)<=d?(t.x=NaN,t.y=NaN,t):this.sphere?(e=2*this.k0/(1+this.sinlat0*l+this.coslat0*c*Math.cos(f)),t.x=this.a*e*c*Math.sin(f)+this.x0,t.y=this.a*e*(this.coslat0*l-this.sinlat0*c*Math.cos(f))+this.y0,t):(i=2*Math.atan(this.ssfn_(h,l,this.e))-u,s=Math.cos(i),r=Math.sin(i),Math.abs(this.coslat0)<=d?(n=W(this.e,h*this.con,this.con*l),a=2*this.a*this.k0*n/this.cons,t.x=this.x0+a*Math.sin(o-this.long0),t.y=this.y0-this.con*a*Math.cos(o-this.long0),t):(Math.abs(this.sinlat0)0?G(this.long0+Math.atan2(t.x,-1*t.y)):G(this.long0+Math.atan2(t.x,t.y)):G(this.long0+Math.atan2(t.x*Math.sin(o),a*this.coslat0*Math.cos(o)-t.y*this.sinlat0*Math.sin(o))),t.x=e,t.y=i,t)}if(Math.abs(this.coslat0)<=d){if(a<=d)return i=this.lat0,e=this.long0,t.x=e,t.y=i,t;t.x*=this.con,t.y*=this.con,r=a*this.cons/(2*this.a*this.k0),i=this.con*Z(this.e,r),e=this.con*G(this.con*this.long0+Math.atan2(t.x,-1*t.y))}else s=2*Math.atan(a*this.cosX0/(2*this.a*this.k0*this.ms1)),e=this.long0,a<=d?n=this.X0:(n=Math.asin(Math.cos(s)*this.sinX0+t.y*Math.sin(s)*this.cosX0/a),e=G(this.long0+Math.atan2(t.x*Math.sin(s),a*this.cosX0*Math.cos(s)-t.y*this.sinX0*Math.sin(s)))),i=-1*Z(this.e,Math.tan(.5*(u+n)));return t.x=e,t.y=i,t},names:["stere","Stereographic_South_Pole","Polar Stereographic (variant B)","Polar_Stereographic"],ssfn_:function(t,e,i){return e*=i,Math.tan(.5*(u+t))*Math.pow((1-e)/(1+e),.5*i)}};var _e={init:function(){var t=this.lat0;this.lambda0=this.long0;var e=Math.sin(t),i=this.a,r=1/this.rf,s=2*r-Math.pow(r,2),n=this.e=Math.sqrt(s);this.R=this.k0*i*Math.sqrt(1-s)/(1-s*Math.pow(e,2)),this.alpha=Math.sqrt(1+s/(1-s)*Math.pow(Math.cos(t),4)),this.b0=Math.asin(e/this.alpha);var a=Math.log(Math.tan(Math.PI/4+this.b0/2)),o=Math.log(Math.tan(Math.PI/4+t/2)),h=Math.log((1+n*e)/(1-n*e));this.K=a-this.alpha*o+this.alpha*n/2*h},forward:function(t){var e=Math.log(Math.tan(Math.PI/4-t.y/2)),i=this.e/2*Math.log((1+this.e*Math.sin(t.y))/(1-this.e*Math.sin(t.y))),r=-this.alpha*(e+i)+this.K,s=2*(Math.atan(Math.exp(r))-Math.PI/4),n=this.alpha*(t.x-this.lambda0),a=Math.atan(Math.sin(n)/(Math.sin(this.b0)*Math.tan(s)+Math.cos(this.b0)*Math.cos(n))),o=Math.asin(Math.cos(this.b0)*Math.sin(s)-Math.sin(this.b0)*Math.cos(s)*Math.cos(n));return t.y=this.R/2*Math.log((1+Math.sin(o))/(1-Math.sin(o)))+this.y0,t.x=this.R*a+this.x0,t},inverse:function(t){for(var e=t.x-this.x0,i=t.y-this.y0,r=e/this.R,s=2*(Math.atan(Math.exp(i/this.R))-Math.PI/4),n=Math.asin(Math.cos(this.b0)*Math.sin(s)+Math.sin(this.b0)*Math.cos(s)*Math.cos(r)),a=Math.atan(Math.sin(r)/(Math.cos(this.b0)*Math.cos(r)-Math.sin(this.b0)*Math.tan(s))),o=this.lambda0+a/this.alpha,h=0,u=n,l=-1e3,c=0;Math.abs(u-l)>1e-7;){if(++c>20)return;h=1/this.alpha*(Math.log(Math.tan(Math.PI/4+n/2))-this.K)+this.e*Math.log(Math.tan(Math.PI/4+Math.asin(this.e*Math.sin(u))/2)),l=u,u=2*Math.atan(Math.exp(h))-Math.PI/2}return t.x=o,t.y=u,t},names:["somerc"]},ye=1e-7;var ve={init:function(){var t,e,i,r,s,n,a,o,h,l,c,f,m,y=0,v=0,b=0,w=0,M=0,x=0,k=0;this.no_off=(m="object"==typeof(f=this).PROJECTION?Object.keys(f.PROJECTION)[0]:f.PROJECTION,"no_uoff"in f||"no_off"in f||-1!==["Hotine_Oblique_Mercator","Hotine_Oblique_Mercator_Azimuth_Natural_Origin"].indexOf(m)),this.no_rot="no_rot"in this;var E=!1;"alpha"in this&&(E=!0);var A=!1;if("rectified_grid_angle"in this&&(A=!0),E&&(k=this.alpha),A&&(y=this.rectified_grid_angle*p),E||A)v=this.longc;else if(b=this.long1,M=this.lat1,w=this.long2,x=this.lat2,Math.abs(M-x)<=ye||(t=Math.abs(M))<=ye||Math.abs(t-u)<=ye||Math.abs(Math.abs(this.lat0)-u)<=ye||Math.abs(Math.abs(x)-u)<=ye)throw new Error;var S=1-this.es;e=Math.sqrt(S),Math.abs(this.lat0)>d?(o=Math.sin(this.lat0),i=Math.cos(this.lat0),t=1-this.es*o*o,this.B=i*i,this.B=Math.sqrt(1+this.es*this.B*this.B/S),this.A=this.B*this.k0*e/t,(s=(r=this.B*e/(i*Math.sqrt(t)))*r-1)<=0?s=0:(s=Math.sqrt(s),this.lat0<0&&(s=-s)),this.E=s+=r,this.E*=Math.pow(W(this.e,this.lat0,o),this.B)):(this.B=1/e,this.A=this.k0,this.E=r=s=1),E||A?(E?(c=Math.asin(Math.sin(k)/r),A||(y=k)):(c=y,k=Math.asin(r*Math.sin(c))),this.lam0=v-Math.asin(.5*(s-1/s)*Math.tan(c))/this.B):(n=Math.pow(W(this.e,M,Math.sin(M)),this.B),a=Math.pow(W(this.e,x,Math.sin(x)),this.B),s=this.E/n,h=(a-n)/(a+n),l=((l=this.E*this.E)-a*n)/(l+a*n),(t=b-w)<-Math.pi?w-=_:t>Math.pi&&(w+=_),this.lam0=G(.5*(b+w)-Math.atan(l*Math.tan(.5*this.B*(b-w))/h)/this.B),c=Math.atan(2*Math.sin(this.B*G(b-this.lam0))/(s-1/s)),y=k=Math.asin(r*Math.sin(c))),this.singam=Math.sin(c),this.cosgam=Math.cos(c),this.sinrot=Math.sin(y),this.cosrot=Math.cos(y),this.rB=1/this.B,this.ArB=this.A*this.rB,this.BrA=1/this.ArB,this.A,this.B,this.no_off?this.u_0=0:(this.u_0=Math.abs(this.ArB*Math.atan(Math.sqrt(r*r-1)/Math.cos(k))),this.lat0<0&&(this.u_0=-this.u_0)),s=.5*c,this.v_pole_n=this.ArB*Math.log(Math.tan(g-s)),this.v_pole_s=this.ArB*Math.log(Math.tan(g+s))},forward:function(t){var e,i,r,s,n,a,o,h,l={};if(t.x=t.x-this.lam0,Math.abs(Math.abs(t.y)-u)>d){if(e=.5*((n=this.E/Math.pow(W(this.e,t.y,Math.sin(t.y)),this.B))-(a=1/n)),i=.5*(n+a),s=Math.sin(this.B*t.x),r=(e*this.singam-s*this.cosgam)/i,Math.abs(Math.abs(r)-1)0?this.v_pole_n:this.v_pole_s,o=this.ArB*t.y;return this.no_rot?(l.x=o,l.y=h):(o-=this.u_0,l.x=h*this.cosrot+o*this.sinrot,l.y=o*this.cosrot-h*this.sinrot),l.x=this.a*l.x+this.x0,l.y=this.a*l.y+this.y0,l},inverse:function(t){var e,i,r,s,n,a,o,h={};if(t.x=(t.x-this.x0)*(1/this.a),t.y=(t.y-this.y0)*(1/this.a),this.no_rot?(i=t.y,e=t.x):(i=t.x*this.cosrot-t.y*this.sinrot,e=t.y*this.cosrot+t.x*this.sinrot+this.u_0),s=.5*((r=Math.exp(-this.BrA*i))-1/r),n=.5*(r+1/r),o=((a=Math.sin(this.BrA*e))*this.cosgam+s*this.singam)/n,Math.abs(Math.abs(o)-1)d?this.ns=Math.log(r/o)/Math.log(s/h):this.ns=e,isNaN(this.ns)&&(this.ns=e),this.f0=r/(this.ns*Math.pow(s,this.ns)),this.rh=this.a*this.f0*Math.pow(u,this.ns),this.title||(this.title="Lambert Conformal Conic")}},forward:function(t){var e=t.x,i=t.y;Math.abs(2*Math.abs(i)-Math.PI)<=d&&(i=q(i)*(u-2*d));var r,s,n=Math.abs(Math.abs(i)-u);if(n>d)r=W(this.e,i,Math.sin(i)),s=this.a*this.f0*Math.pow(r,this.ns);else{if((n=i*this.ns)<=0)return null;s=0}var a=this.ns*G(e-this.long0);return t.x=this.k0*(s*Math.sin(a))+this.x0,t.y=this.k0*(this.rh-s*Math.cos(a))+this.y0,t},inverse:function(t){var e,i,r,s,n,a=(t.x-this.x0)/this.k0,o=this.rh-(t.y-this.y0)/this.k0;this.ns>0?(e=Math.sqrt(a*a+o*o),i=1):(e=-Math.sqrt(a*a+o*o),i=-1);var h=0;if(0!==e&&(h=Math.atan2(i*a,i*o)),0!==e||this.ns>0){if(i=1/this.ns,r=Math.pow(e/(this.a*this.f0),i),-9999===(s=Z(this.e,r)))return null}else s=-u;return n=G(h/this.ns+this.long0),t.x=n,t.y=s,t},names:["Lambert Tangential Conformal Conic Projection","Lambert_Conformal_Conic","Lambert_Conformal_Conic_1SP","Lambert_Conformal_Conic_2SP","lcc","Lambert Conic Conformal (1SP)","Lambert Conic Conformal (2SP)"]};var we={init:function(){this.a=6377397.155,this.es=.006674372230614,this.e=Math.sqrt(this.es),this.lat0||(this.lat0=.863937979737193),this.long0||(this.long0=.4334234309119251),this.k0||(this.k0=.9999),this.s45=.785398163397448,this.s90=2*this.s45,this.fi0=this.lat0,this.e2=this.es,this.e=Math.sqrt(this.e2),this.alfa=Math.sqrt(1+this.e2*Math.pow(Math.cos(this.fi0),4)/(1-this.e2)),this.uq=1.04216856380474,this.u0=Math.asin(Math.sin(this.fi0)/this.alfa),this.g=Math.pow((1+this.e*Math.sin(this.fi0))/(1-this.e*Math.sin(this.fi0)),this.alfa*this.e/2),this.k=Math.tan(this.u0/2+this.s45)/Math.pow(Math.tan(this.fi0/2+this.s45),this.alfa)*this.g,this.k1=this.k0,this.n0=this.a*Math.sqrt(1-this.e2)/(1-this.e2*Math.pow(Math.sin(this.fi0),2)),this.s0=1.37008346281555,this.n=Math.sin(this.s0),this.ro0=this.k1*this.n0/Math.tan(this.s0),this.ad=this.s90-this.uq},forward:function(t){var e,i,r,s,n,a,o,h=t.x,u=t.y,l=G(h-this.long0);return e=Math.pow((1+this.e*Math.sin(u))/(1-this.e*Math.sin(u)),this.alfa*this.e/2),i=2*(Math.atan(this.k*Math.pow(Math.tan(u/2+this.s45),this.alfa)/e)-this.s45),r=-l*this.alfa,s=Math.asin(Math.cos(this.ad)*Math.sin(i)+Math.sin(this.ad)*Math.cos(i)*Math.cos(r)),n=Math.asin(Math.cos(i)*Math.sin(r)/Math.cos(s)),a=this.n*n,o=this.ro0*Math.pow(Math.tan(this.s0/2+this.s45),this.n)/Math.pow(Math.tan(s/2+this.s45),this.n),t.y=o*Math.cos(a)/1,t.x=o*Math.sin(a)/1,this.czech||(t.y*=-1,t.x*=-1),t},inverse:function(t){var e,i,r,s,n,a,o,h=t.x;t.x=t.y,t.y=h,this.czech||(t.y*=-1,t.x*=-1),n=Math.sqrt(t.x*t.x+t.y*t.y),s=Math.atan2(t.y,t.x)/Math.sin(this.s0),r=2*(Math.atan(Math.pow(this.ro0/n,1/this.n)*Math.tan(this.s0/2+this.s45))-this.s45),e=Math.asin(Math.cos(this.ad)*Math.sin(r)-Math.sin(this.ad)*Math.cos(r)*Math.cos(s)),i=Math.asin(Math.cos(r)*Math.sin(s)/Math.cos(e)),t.x=this.long0-i/this.alfa,a=e,o=0;var u=0;do{t.y=2*(Math.atan(Math.pow(this.k,-1/this.alfa)*Math.pow(Math.tan(e/2+this.s45),1/this.alfa)*Math.pow((1+this.e*Math.sin(a))/(1-this.e*Math.sin(a)),this.e/2))-this.s45),Math.abs(a-t.y)<1e-10&&(o=1),a=t.y,u+=1}while(0===o&&u<15);return u>=15?null:t},names:["Krovak","krovak"]};function Me(t,e,i,r,s){return t*s-e*Math.sin(2*s)+i*Math.sin(4*s)-r*Math.sin(6*s)}function xe(t){return 1-.25*t*(1+t/16*(3+1.25*t))}function ke(t){return.375*t*(1+.25*t*(1+.46875*t))}function Ee(t){return.05859375*t*t*(1+.75*t)}function Ae(t){return t*t*t*(35/3072)}function Se(t,e,i){var r=e*i;return t/Math.sqrt(1-r*r)}function Ce(t){return Math.abs(t)1e-7?(1-t*t)*(e/(1-(i=t*e)*i)-.5/t*Math.log((1-i)/(1+i))):2*e}var Re=.3333333333333333,Ne=.17222222222222222,ze=.10257936507936508,Te=.06388888888888888,Be=.0664021164021164,Le=.016415012942191543;var De={init:function(){var t,e=Math.abs(this.lat0);if(Math.abs(e-u)0)switch(this.qp=Pe(this.e,1),this.mmf=.5/(1-this.es),this.apa=function(t){var e,i=[];return i[0]=t*Re,e=t*t,i[0]+=e*Ne,i[1]=e*Te,e*=t,i[0]+=e*ze,i[1]+=e*Be,i[2]=e*Le,i}(this.es),this.mode){case this.N_POLE:case this.S_POLE:this.dd=1;break;case this.EQUIT:this.rq=Math.sqrt(.5*this.qp),this.dd=1/this.rq,this.xmf=1,this.ymf=.5*this.qp;break;case this.OBLIQ:this.rq=Math.sqrt(.5*this.qp),t=Math.sin(this.lat0),this.sinb1=Pe(this.e,t)/this.qp,this.cosb1=Math.sqrt(1-this.sinb1*this.sinb1),this.dd=Math.cos(this.lat0)/(Math.sqrt(1-this.es*t*t)*this.rq*this.cosb1),this.ymf=(this.xmf=this.rq)/this.dd,this.xmf*=this.dd}else this.mode===this.OBLIQ&&(this.sinph0=Math.sin(this.lat0),this.cosph0=Math.cos(this.lat0))},forward:function(t){var e,i,r,s,n,a,o,h,l,c,f=t.x,p=t.y;if(f=G(f-this.long0),this.sphere){if(n=Math.sin(p),c=Math.cos(p),r=Math.cos(f),this.mode===this.OBLIQ||this.mode===this.EQUIT){if((i=this.mode===this.EQUIT?1+c*r:1+this.sinph0*n+this.cosph0*c*r)<=d)return null;e=(i=Math.sqrt(2/i))*c*Math.sin(f),i*=this.mode===this.EQUIT?n:this.cosph0*n-this.sinph0*c*r}else if(this.mode===this.N_POLE||this.mode===this.S_POLE){if(this.mode===this.N_POLE&&(r=-r),Math.abs(p+this.lat0)=0?(e=(l=Math.sqrt(a))*s,i=r*(this.mode===this.S_POLE?l:-l)):e=i=0}}return t.x=this.a*e+this.x0,t.y=this.a*i+this.y0,t},inverse:function(t){t.x-=this.x0,t.y-=this.y0;var e,i,r,s,n,a,o,h,l,c,f=t.x/this.a,p=t.y/this.a;if(this.sphere){var m,g=0,_=0;if((i=.5*(m=Math.sqrt(f*f+p*p)))>1)return null;switch(i=2*Math.asin(i),this.mode!==this.OBLIQ&&this.mode!==this.EQUIT||(_=Math.sin(i),g=Math.cos(i)),this.mode){case this.EQUIT:i=Math.abs(m)<=d?0:Math.asin(p*_/m),f*=_,p=g*m;break;case this.OBLIQ:i=Math.abs(m)<=d?this.lat0:Math.asin(g*this.sinph0+p*_*this.cosph0/m),f*=_*this.cosph0,p=(g-Math.sin(i)*this.sinph0)*m;break;case this.N_POLE:p=-p,i=u-i;break;case this.S_POLE:i-=u}e=0!==p||this.mode!==this.EQUIT&&this.mode!==this.OBLIQ?Math.atan2(f,p):0}else{if(o=0,this.mode===this.OBLIQ||this.mode===this.EQUIT){if(f/=this.dd,p*=this.dd,(a=Math.sqrt(f*f+p*p))1&&(t=t>1?1:-1),Math.asin(t)}var je={init:function(){Math.abs(this.lat1+this.lat2)d?this.ns0=(this.ms1*this.ms1-this.ms2*this.ms2)/(this.qs2-this.qs1):this.ns0=this.con,this.c=this.ms1*this.ms1+this.ns0*this.qs1,this.rh=this.a*Math.sqrt(this.c-this.ns0*this.qs0)/this.ns0)},forward:function(t){var e=t.x,i=t.y;this.sin_phi=Math.sin(i),this.cos_phi=Math.cos(i);var r=Pe(this.e3,this.sin_phi),s=this.a*Math.sqrt(this.c-this.ns0*r)/this.ns0,n=this.ns0*G(e-this.long0),a=s*Math.sin(n)+this.x0,o=this.rh-s*Math.cos(n)+this.y0;return t.x=a,t.y=o,t},inverse:function(t){var e,i,r,s,n,a;return t.x-=this.x0,t.y=this.rh-t.y+this.y0,this.ns0>=0?(e=Math.sqrt(t.x*t.x+t.y*t.y),r=1):(e=-Math.sqrt(t.x*t.x+t.y*t.y),r=-1),s=0,0!==e&&(s=Math.atan2(r*t.x,r*t.y)),r=e*this.ns0/this.a,this.sphere?a=Math.asin((this.c-r*r)/(2*this.ns0)):(i=(this.c-r*r)/this.ns0,a=this.phi1z(this.e3,i)),n=G(s/this.ns0+this.long0),t.x=n,t.y=a,t},names:["Albers_Conic_Equal_Area","Albers","aea"],phi1z:function(t,e){var i,r,s,n,a=Ue(.5*e);if(t0||Math.abs(n)<=d?(a=this.x0+1*this.a*i*Math.sin(r)/n,o=this.y0+1*this.a*(this.cos_p14*e-this.sin_p14*i*s)/n):(a=this.x0+this.infinity_dist*i*Math.sin(r),o=this.y0+this.infinity_dist*(this.cos_p14*e-this.sin_p14*i*s)),t.x=a,t.y=o,t},inverse:function(t){var e,i,r,s,n,a;return t.x=(t.x-this.x0)/this.a,t.y=(t.y-this.y0)/this.a,t.x/=this.k0,t.y/=this.k0,(e=Math.sqrt(t.x*t.x+t.y*t.y))?(s=Math.atan2(e,this.rc),i=Math.sin(s),a=Ue((r=Math.cos(s))*this.sin_p14+t.y*i*this.cos_p14/e),n=Math.atan2(t.x*i,e*this.cos_p14*r-t.y*this.sin_p14*i),n=G(this.long0+n)):(a=this.phic0,n=0),t.x=n,t.y=a,t},names:["gnom"]};var qe={init:function(){this.sphere||(this.k0=F(this.e,Math.sin(this.lat_ts),Math.cos(this.lat_ts)))},forward:function(t){var e,i,r=t.x,s=t.y,n=G(r-this.long0);if(this.sphere)e=this.x0+this.a*n*Math.cos(this.lat_ts),i=this.y0+this.a*Math.sin(s)/Math.cos(this.lat_ts);else{var a=Pe(this.e,Math.sin(s));e=this.x0+this.a*this.k0*n,i=this.y0+this.a*a*.5/this.k0}return t.x=e,t.y=i,t},inverse:function(t){var e,i;return t.x-=this.x0,t.y-=this.y0,this.sphere?(e=G(this.long0+t.x/this.a/Math.cos(this.lat_ts)),i=Math.asin(t.y/this.a*Math.cos(this.lat_ts))):(i=function(t,e){var i=1-(1-t*t)/(2*t)*Math.log((1-t)/(1+t));if(Math.abs(Math.abs(e)-i)<1e-6)return e<0?-1*u:u;for(var r,s,n,a,o=Math.asin(.5*e),h=0;h<30;h++)if(s=Math.sin(o),n=Math.cos(o),a=t*s,o+=r=Math.pow(1-a*a,2)/(2*n)*(e/(1-t*t)-s/(1-a*a)+.5/t*Math.log((1-a)/(1+a))),Math.abs(r)<=1e-10)return o;return NaN}(this.e,2*t.y*this.k0/this.a),e=G(this.long0+t.x/(this.a*this.k0))),t.x=e,t.y=i,t},names:["cea"]};var Ge={init:function(){this.x0=this.x0||0,this.y0=this.y0||0,this.lat0=this.lat0||0,this.long0=this.long0||0,this.lat_ts=this.lat_ts||0,this.title=this.title||"Equidistant Cylindrical (Plate Carre)",this.rc=Math.cos(this.lat_ts)},forward:function(t){var e=t.x,i=t.y,r=G(e-this.long0),s=Ce(i-this.lat0);return t.x=this.x0+this.a*r*this.rc,t.y=this.y0+this.a*s,t},inverse:function(t){var e=t.x,i=t.y;return t.x=G(this.long0+(e-this.x0)/(this.a*this.rc)),t.y=Ce(this.lat0+(i-this.y0)/this.a),t},names:["Equirectangular","Equidistant_Cylindrical","eqc"]};var We={init:function(){this.temp=this.b/this.a,this.es=1-Math.pow(this.temp,2),this.e=Math.sqrt(this.es),this.e0=xe(this.es),this.e1=ke(this.es),this.e2=Ee(this.es),this.e3=Ae(this.es),this.ml0=this.a*Me(this.e0,this.e1,this.e2,this.e3,this.lat0)},forward:function(t){var e,i,r,s=t.x,n=t.y,a=G(s-this.long0);if(r=a*Math.sin(n),this.sphere)Math.abs(n)<=d?(e=this.a*a,i=-1*this.a*this.lat0):(e=this.a*Math.sin(r)/Math.tan(n),i=this.a*(Ce(n-this.lat0)+(1-Math.cos(r))/Math.tan(n)));else if(Math.abs(n)<=d)e=this.a*a,i=-1*this.ml0;else{var o=Se(this.a,this.e,Math.sin(n))/Math.tan(n);e=o*Math.sin(r),i=this.a*Me(this.e0,this.e1,this.e2,this.e3,n)-this.ml0+o*(1-Math.cos(r))}return t.x=e+this.x0,t.y=i+this.y0,t},inverse:function(t){var e,i,r,s,n,a,o,h,u;if(r=t.x-this.x0,s=t.y-this.y0,this.sphere)if(Math.abs(s+this.a*this.lat0)<=d)e=G(r/this.a+this.long0),i=0;else{var l;for(a=this.lat0+s/this.a,o=r*r/this.a/this.a+a*a,h=a,n=20;n;--n)if(h+=u=-1*(a*(h*(l=Math.tan(h))+1)-h-.5*(h*h+o)*l)/((h-a)/l-1),Math.abs(u)<=d){i=h;break}e=G(this.long0+Math.asin(r*Math.tan(h)/this.a)/Math.sin(i))}else if(Math.abs(s+this.ml0)<=d)i=0,e=G(this.long0+r/this.a);else{var c,f,p,m,g;for(a=(this.ml0+s)/this.a,o=r*r/this.a/this.a+a*a,h=a,n=20;n;--n)if(g=this.e*Math.sin(h),c=Math.sqrt(1-g*g)*Math.tan(h),f=this.a*Me(this.e0,this.e1,this.e2,this.e3,h),p=this.e0-2*this.e1*Math.cos(2*h)+4*this.e2*Math.cos(4*h)-6*this.e3*Math.cos(6*h),h-=u=(a*(c*(m=f/this.a)+1)-m-.5*c*(m*m+o))/(this.es*Math.sin(2*h)*(m*m+o-2*a*m)/(4*c)+(a-m)*(c*p-2/Math.sin(2*h))-p),Math.abs(u)<=d){i=h;break}c=Math.sqrt(1-this.es*Math.pow(Math.sin(i),2))*Math.tan(i),e=G(this.long0+Math.asin(r*c/this.a)/Math.sin(i))}return t.x=e,t.y=i,t},names:["Polyconic","poly"]};var Ze={init:function(){this.A=[],this.A[1]=.6399175073,this.A[2]=-.1358797613,this.A[3]=.063294409,this.A[4]=-.02526853,this.A[5]=.0117879,this.A[6]=-.0055161,this.A[7]=.0026906,this.A[8]=-.001333,this.A[9]=67e-5,this.A[10]=-34e-5,this.B_re=[],this.B_im=[],this.B_re[1]=.7557853228,this.B_im[1]=0,this.B_re[2]=.249204646,this.B_im[2]=.003371507,this.B_re[3]=-.001541739,this.B_im[3]=.04105856,this.B_re[4]=-.10162907,this.B_im[4]=.01727609,this.B_re[5]=-.26623489,this.B_im[5]=-.36249218,this.B_re[6]=-.6870983,this.B_im[6]=-1.1651967,this.C_re=[],this.C_im=[],this.C_re[1]=1.3231270439,this.C_im[1]=0,this.C_re[2]=-.577245789,this.C_im[2]=-.007809598,this.C_re[3]=.508307513,this.C_im[3]=-.112208952,this.C_re[4]=-.15094762,this.C_im[4]=.18200602,this.C_re[5]=1.01418179,this.C_im[5]=1.64497696,this.C_re[6]=1.9660549,this.C_im[6]=2.5127645,this.D=[],this.D[1]=1.5627014243,this.D[2]=.5185406398,this.D[3]=-.03333098,this.D[4]=-.1052906,this.D[5]=-.0368594,this.D[6]=.007317,this.D[7]=.0122,this.D[8]=.00394,this.D[9]=-.0013},forward:function(t){var e,i=t.x,r=t.y-this.lat0,s=i-this.long0,n=r/h*1e-5,a=s,o=1,u=0;for(e=1;e<=10;e++)o*=n,u+=this.A[e]*o;var l,c=u,f=a,d=1,p=0,m=0,g=0;for(e=1;e<=6;e++)l=p*c+d*f,d=d*c-p*f,p=l,m=m+this.B_re[e]*d-this.B_im[e]*p,g=g+this.B_im[e]*d+this.B_re[e]*p;return t.x=g*this.a+this.x0,t.y=m*this.a+this.y0,t},inverse:function(t){var e,i,r=t.x,s=t.y,n=r-this.x0,a=(s-this.y0)/this.a,o=n/this.a,u=1,l=0,c=0,f=0;for(e=1;e<=6;e++)i=l*a+u*o,u=u*a-l*o,l=i,c=c+this.C_re[e]*u-this.C_im[e]*l,f=f+this.C_im[e]*u+this.C_re[e]*l;for(var d=0;d.999999999999&&(i=.999999999999),e=Math.asin(i);var r=G(this.long0+t.x/(.900316316158*this.a*Math.cos(e)));r<-Math.PI&&(r=-Math.PI),r>Math.PI&&(r=Math.PI),i=(2*e+Math.sin(2*e))/Math.PI,Math.abs(i)>1&&(i=1);var s=Math.asin(i);return t.x=r,t.y=s,t},names:["Mollweide","moll"]};var Xe={init:function(){Math.abs(this.lat1+this.lat2)=0?(i=Math.sqrt(t.x*t.x+t.y*t.y),e=1):(i=-Math.sqrt(t.x*t.x+t.y*t.y),e=-1);var n=0;return 0!==i&&(n=Math.atan2(e*t.x,e*t.y)),this.sphere?(s=G(this.long0+n/this.ns),r=Ce(this.g-i/this.a),t.x=s,t.y=r,t):(r=Ie(this.g-i/this.a,this.e0,this.e1,this.e2,this.e3),s=G(this.long0+n/this.ns),t.x=s,t.y=r,t)},names:["Equidistant_Conic","eqdc"]};var Je={init:function(){this.R=this.a},forward:function(t){var e,i,r=t.x,s=t.y,n=G(r-this.long0);Math.abs(s)<=d&&(e=this.x0+this.R*n,i=this.y0);var a=Ue(2*Math.abs(s/Math.PI));(Math.abs(n)<=d||Math.abs(Math.abs(s)-u)<=d)&&(e=this.x0,i=s>=0?this.y0+Math.PI*this.R*Math.tan(.5*a):this.y0+Math.PI*this.R*-Math.tan(.5*a));var o=.5*Math.abs(Math.PI/n-n/Math.PI),h=o*o,l=Math.sin(a),c=Math.cos(a),f=c/(l+c-1),p=f*f,m=f*(2/l-1),g=m*m,_=Math.PI*this.R*(o*(f-g)+Math.sqrt(h*(f-g)*(f-g)-(g+h)*(p-g)))/(g+h);n<0&&(_=-_),e=this.x0+_;var y=h+f;return _=Math.PI*this.R*(m*y-o*Math.sqrt((g+h)*(h+1)-y*y))/(g+h),i=s>=0?this.y0+_:this.y0-_,t.x=e,t.y=i,t},inverse:function(t){var e,i,r,s,n,a,o,h,u,l,c,f;return t.x-=this.x0,t.y-=this.y0,c=Math.PI*this.R,n=(r=t.x/c)*r+(s=t.y/c)*s,c=3*(s*s/(h=-2*(a=-Math.abs(s)*(1+n))+1+2*s*s+n*n)+(2*(o=a-2*s*s+r*r)*o*o/h/h/h-9*a*o/h/h)/27)/(u=(a-o*o/3/h)/h)/(l=2*Math.sqrt(-u/3)),Math.abs(c)>1&&(c=c>=0?1:-1),f=Math.acos(c)/3,i=t.y>=0?(-l*Math.cos(f+Math.PI/3)-o/3/h)*Math.PI:-(-l*Math.cos(f+Math.PI/3)-o/3/h)*Math.PI,e=Math.abs(r)2*u*this.a)return;return i=e/this.a,r=Math.sin(i),s=Math.cos(i),n=this.long0,Math.abs(e)<=d?a=this.lat0:(a=Ue(s*this.sin_p12+t.y*r*this.cos_p12/e),o=Math.abs(this.lat0)-u,n=Math.abs(o)<=d?this.lat0>=0?G(this.long0+Math.atan2(t.x,-t.y)):G(this.long0-Math.atan2(-t.x,t.y)):G(this.long0+Math.atan2(t.x*r,e*this.cos_p12*s-t.y*this.sin_p12*r))),t.x=n,t.y=a,t}return h=xe(this.es),l=ke(this.es),c=Ee(this.es),f=Ae(this.es),Math.abs(this.sin_p12-1)<=d?(a=Ie(((p=this.a*Me(h,l,c,f,u))-(e=Math.sqrt(t.x*t.x+t.y*t.y)))/this.a,h,l,c,f),n=G(this.long0+Math.atan2(t.x,-1*t.y)),t.x=n,t.y=a,t):Math.abs(this.sin_p12+1)<=d?(p=this.a*Me(h,l,c,f,u),a=Ie(((e=Math.sqrt(t.x*t.x+t.y*t.y))-p)/this.a,h,l,c,f),n=G(this.long0+Math.atan2(t.x,t.y)),t.x=n,t.y=a,t):(e=Math.sqrt(t.x*t.x+t.y*t.y),_=Math.atan2(t.x,t.y),m=Se(this.a,this.e,this.sin_p12),y=Math.cos(_),b=-(v=this.e*this.cos_p12*y)*v/(1-this.es),w=3*this.es*(1-b)*this.sin_p12*this.cos_p12*y/(1-this.es),k=1-b*(x=(M=e/m)-b*(1+b)*Math.pow(M,3)/6-w*(1+3*b)*Math.pow(M,4)/24)*x/2-M*x*x*x/6,g=Math.asin(this.sin_p12*Math.cos(x)+this.cos_p12*Math.sin(x)*y),n=G(this.long0+Math.asin(Math.sin(_)*Math.sin(x)/Math.cos(g))),E=Math.sin(g),a=Math.atan2((E-this.es*k*this.sin_p12)*Math.tan(g),E*(1-this.es)),t.x=n,t.y=a,t)},names:["Azimuthal_Equidistant","aeqd"]};var Ve={init:function(){this.sin_p14=Math.sin(this.lat0),this.cos_p14=Math.cos(this.lat0)},forward:function(t){var e,i,r,s,n,a,o,h=t.x,u=t.y;return r=G(h-this.long0),e=Math.sin(u),i=Math.cos(u),s=Math.cos(r),1,((n=this.sin_p14*e+this.cos_p14*i*s)>0||Math.abs(n)<=d)&&(a=1*this.a*i*Math.sin(r),o=this.y0+1*this.a*(this.cos_p14*e-this.sin_p14*i*s)),t.x=a,t.y=o,t},inverse:function(t){var e,i,r,s,n,a,o;return t.x-=this.x0,t.y-=this.y0,i=Ue((e=Math.sqrt(t.x*t.x+t.y*t.y))/this.a),r=Math.sin(i),s=Math.cos(i),a=this.long0,Math.abs(e)<=d?(o=this.lat0,t.x=a,t.y=o,t):(o=Ue(s*this.sin_p14+t.y*r*this.cos_p14/e),n=Math.abs(this.lat0)-u,Math.abs(n)<=d?(a=this.lat0>=0?G(this.long0+Math.atan2(t.x,-t.y)):G(this.long0-Math.atan2(-t.x,t.y)),t.x=a,t.y=o,t):(a=G(this.long0+Math.atan2(t.x*r,e*this.cos_p14*s-t.y*this.sin_p14*r)),t.x=a,t.y=o,t))},names:["ortho"]},$e=1,ti=2,ei=3,ii=4,ri=5,si=6,ni={AREA_0:1,AREA_1:2,AREA_2:3,AREA_3:4};function ai(t,e,i,r){var s;return tg&&s<=u+g?(r.value=ni.AREA_1,s-=u):s>u+g||s<=-(u+g)?(r.value=ni.AREA_2,s=s>=0?s-y:s+y):(r.value=ni.AREA_3,s+=u)),s}function oi(t,e){var i=t+e;return i<-y?i+=_:i>+y&&(i-=_),i}var hi={init:function(){this.x0=this.x0||0,this.y0=this.y0||0,this.lat0=this.lat0||0,this.long0=this.long0||0,this.lat_ts=this.lat_ts||0,this.title=this.title||"Quadrilateralized Spherical Cube",this.lat0>=u-g/2?this.face=ri:this.lat0<=-(u-g/2)?this.face=si:Math.abs(this.long0)<=g?this.face=$e:Math.abs(this.long0)<=u+g?this.face=this.long0>0?ti:ii:this.face=ei,0!==this.es&&(this.one_minus_f=1-(this.a-this.b)/this.a,this.one_minus_f_squared=this.one_minus_f*this.one_minus_f)},forward:function(t){var e,i,r,s,n,a,o={x:0,y:0},h={value:0};if(t.x-=this.long0,e=0!==this.es?Math.atan(this.one_minus_f_squared*Math.tan(t.y)):t.y,i=t.x,this.face===ri)s=u-e,i>=g&&i<=u+g?(h.value=ni.AREA_0,r=i-u):i>u+g||i<=-(u+g)?(h.value=ni.AREA_1,r=i>0?i-y:i+y):i>-(u+g)&&i<=-g?(h.value=ni.AREA_2,r=i+u):(h.value=ni.AREA_3,r=i);else if(this.face===si)s=u+e,i>=g&&i<=u+g?(h.value=ni.AREA_0,r=-i+u):i=-g?(h.value=ni.AREA_1,r=-i):i<-g&&i>=-(u+g)?(h.value=ni.AREA_2,r=-i-u):(h.value=ni.AREA_3,r=i>0?-i+y:-i-y);else{var l,c,f,d,p,m;this.face===ti?i=oi(i,+u):this.face===ei?i=oi(i,+y):this.face===ii&&(i=oi(i,-u)),d=Math.sin(e),p=Math.cos(e),m=Math.sin(i),l=p*Math.cos(i),c=p*m,f=d,this.face===$e?r=ai(s=Math.acos(l),f,c,h):this.face===ti?r=ai(s=Math.acos(c),f,-l,h):this.face===ei?r=ai(s=Math.acos(-l),f,-c,h):this.face===ii?r=ai(s=Math.acos(-c),f,l,h):(s=r=0,h.value=ni.AREA_0)}return a=Math.atan(12/y*(r+Math.acos(Math.sin(r)*Math.cos(g))-u)),n=Math.sqrt((1-Math.cos(s))/(Math.cos(a)*Math.cos(a))/(1-Math.cos(Math.atan(1/Math.cos(r))))),h.value===ni.AREA_1?a+=u:h.value===ni.AREA_2?a+=y:h.value===ni.AREA_3&&(a+=1.5*y),o.x=n*Math.cos(a),o.y=n*Math.sin(a),o.x=o.x*this.a+this.x0,o.y=o.y*this.a+this.y0,t.x=o.x,t.y=o.y,t},inverse:function(t){var e,i,r,s,n,a,o,h,l,c,f,d,p={lam:0,phi:0},m={value:0};if(t.x=(t.x-this.x0)/this.a,t.y=(t.y-this.y0)/this.a,i=Math.atan(Math.sqrt(t.x*t.x+t.y*t.y)),e=Math.atan2(t.y,t.x),t.x>=0&&t.x>=Math.abs(t.y)?m.value=ni.AREA_0:t.y>=0&&t.y>=Math.abs(t.x)?(m.value=ni.AREA_1,e-=u):t.x<0&&-t.x>=Math.abs(t.y)?(m.value=ni.AREA_2,e=e<0?e+y:e-y):(m.value=ni.AREA_3,e+=u),l=y/12*Math.tan(e),n=Math.sin(l)/(Math.cos(l)-1/Math.sqrt(2)),a=Math.atan(n),(o=1-(r=Math.cos(e))*r*(s=Math.tan(i))*s*(1-Math.cos(Math.atan(1/Math.cos(a)))))<-1?o=-1:o>1&&(o=1),this.face===ri)h=Math.acos(o),p.phi=u-h,m.value===ni.AREA_0?p.lam=a+u:m.value===ni.AREA_1?p.lam=a<0?a+y:a-y:m.value===ni.AREA_2?p.lam=a-u:p.lam=a;else if(this.face===si)h=Math.acos(o),p.phi=h-u,m.value===ni.AREA_0?p.lam=-a+u:m.value===ni.AREA_1?p.lam=-a:m.value===ni.AREA_2?p.lam=-a-u:p.lam=a<0?-a-y:-a+y;else{var g,_,v;l=(g=o)*g,_=(l+=(v=l>=1?0:Math.sqrt(1-l)*Math.sin(a))*v)>=1?0:Math.sqrt(1-l),m.value===ni.AREA_1?(l=_,_=-v,v=l):m.value===ni.AREA_2?(_=-_,v=-v):m.value===ni.AREA_3&&(l=_,_=v,v=-l),this.face===ti?(l=g,g=-_,_=l):this.face===ei?(g=-g,_=-_):this.face===ii&&(l=g,g=_,_=-l),p.phi=Math.acos(-v)-u,p.lam=Math.atan2(_,g),this.face===ti?p.lam=oi(p.lam,-u):this.face===ei?p.lam=oi(p.lam,-y):this.face===ii&&(p.lam=oi(p.lam,+u))}return 0!==this.es&&(c=p.phi<0?1:0,f=Math.tan(p.phi),d=this.b/Math.sqrt(f*f+this.one_minus_f_squared),p.phi=Math.atan(Math.sqrt(this.a*this.a-d*d)/(this.one_minus_f*d)),c&&(p.phi=-p.phi)),p.lam+=this.long0,t.x=p.lam,t.y=p.phi,t},names:["Quadrilateralized Spherical Cube","Quadrilateralized_Spherical_Cube","qsc"]},ui=[[1,22199e-21,-715515e-10,31103e-10],[.9986,-482243e-9,-24897e-9,-13309e-10],[.9954,-83103e-8,-448605e-10,-9.86701e-7],[.99,-.00135364,-59661e-9,36777e-10],[.9822,-.00167442,-449547e-11,-572411e-11],[.973,-.00214868,-903571e-10,1.8736e-8],[.96,-.00305085,-900761e-10,164917e-11],[.9427,-.00382792,-653386e-10,-26154e-10],[.9216,-.00467746,-10457e-8,481243e-11],[.8962,-.00536223,-323831e-10,-543432e-11],[.8679,-.00609363,-113898e-9,332484e-11],[.835,-.00698325,-640253e-10,9.34959e-7],[.7986,-.00755338,-500009e-10,9.35324e-7],[.7597,-.00798324,-35971e-9,-227626e-11],[.7186,-.00851367,-701149e-10,-86303e-10],[.6732,-.00986209,-199569e-9,191974e-10],[.6213,-.010418,883923e-10,624051e-11],[.5722,-.00906601,182e-6,624051e-11],[.5322,-.00677797,275608e-9,624051e-11]],li=[[-520417e-23,.0124,121431e-23,-845284e-16],[.062,.0124,-1.26793e-9,4.22642e-10],[.124,.0124,5.07171e-9,-1.60604e-9],[.186,.0123999,-1.90189e-8,6.00152e-9],[.248,.0124002,7.10039e-8,-2.24e-8],[.31,.0123992,-2.64997e-7,8.35986e-8],[.372,.0124029,9.88983e-7,-3.11994e-7],[.434,.0123893,-369093e-11,-4.35621e-7],[.4958,.0123198,-102252e-10,-3.45523e-7],[.5571,.0121916,-154081e-10,-5.82288e-7],[.6176,.0119938,-241424e-10,-5.25327e-7],[.6769,.011713,-320223e-10,-5.16405e-7],[.7346,.0113541,-397684e-10,-6.09052e-7],[.7903,.0109107,-489042e-10,-104739e-11],[.8435,.0103431,-64615e-9,-1.40374e-9],[.8936,.00969686,-64636e-9,-8547e-9],[.9394,.00840947,-192841e-9,-42106e-10],[.9761,.00616527,-256e-6,-42106e-10],[1,.00328947,-319159e-9,-42106e-10]],ci=.8487,fi=1.3523,di=m/5,pi=1/di,mi=18,gi=function(t,e){return t[0]+e*(t[1]+e*(t[2]+e*t[3]))};var _i={init:function(){this.x0=this.x0||0,this.y0=this.y0||0,this.long0=this.long0||0,this.es=0,this.title=this.title||"Robinson"},forward:function(t){var e=G(t.x-this.long0),i=Math.abs(t.y),r=Math.floor(i*di);r<0?r=0:r>=mi&&(r=17);var s={x:gi(ui[r],i=m*(i-pi*r))*e,y:gi(li[r],i)};return t.y<0&&(s.y=-s.y),s.x=s.x*this.a*ci+this.x0,s.y=s.y*this.a*fi+this.y0,s},inverse:function(t){var e={x:(t.x-this.x0)/(this.a*ci),y:Math.abs(t.y-this.y0)/(this.a*fi)};if(e.y>=1)e.x/=ui[18][0],e.y=t.y<0?-u:u;else{var i=Math.floor(e.y*mi);for(i<0?i=0:i>=mi&&(i=17);;)if(li[i][0]>e.y)--i;else{if(!(li[i+1][0]<=e.y))break;++i}var r=li[i],s=5*(e.y-r[0])/(li[i+1][0]-r[0]);s=function(t,e,i,r){for(var s=e;r;--r){var n=t(s);if(s-=n,Math.abs(n)1e10)throw new Error;if(this.radius_g=1+this.radius_g_1,this.C=this.radius_g*this.radius_g-1,0!==this.es){var t=1-this.es,e=1/t;this.radius_p=Math.sqrt(t),this.radius_p2=t,this.radius_p_inv2=e,this.shape="ellipse"}else this.radius_p=1,this.radius_p2=1,this.radius_p_inv2=1,this.shape="sphere";this.title||(this.title="Geostationary Satellite View")},forward:function(t){var e,i,r,s,n=t.x,a=t.y;if(n-=this.long0,"ellipse"===this.shape){a=Math.atan(this.radius_p2*Math.tan(a));var o=this.radius_p/oe(this.radius_p*Math.cos(a),Math.sin(a));if(i=o*Math.cos(n)*Math.cos(a),r=o*Math.sin(n)*Math.cos(a),s=o*Math.sin(a),(this.radius_g-i)*i-r*r-s*s*this.radius_p_inv2<0)return t.x=Number.NaN,t.y=Number.NaN,t;e=this.radius_g-i,this.flip_axis?(t.x=this.radius_g_1*Math.atan(r/oe(s,e)),t.y=this.radius_g_1*Math.atan(s/e)):(t.x=this.radius_g_1*Math.atan(r/e),t.y=this.radius_g_1*Math.atan(s/oe(r,e)))}else"sphere"===this.shape&&(e=Math.cos(a),i=Math.cos(n)*e,r=Math.sin(n)*e,s=Math.sin(a),e=this.radius_g-i,this.flip_axis?(t.x=this.radius_g_1*Math.atan(r/oe(s,e)),t.y=this.radius_g_1*Math.atan(s/e)):(t.x=this.radius_g_1*Math.atan(r/e),t.y=this.radius_g_1*Math.atan(s/oe(r,e))));return t.x=t.x*this.a,t.y=t.y*this.a,t},inverse:function(t){var e,i,r,s,n=-1,a=0,o=0;if(t.x=t.x/this.a,t.y=t.y/this.a,"ellipse"===this.shape){this.flip_axis?(o=Math.tan(t.y/this.radius_g_1),a=Math.tan(t.x/this.radius_g_1)*oe(1,o)):(a=Math.tan(t.x/this.radius_g_1),o=Math.tan(t.y/this.radius_g_1)*oe(1,a));var h=o/this.radius_p;if(e=a*a+h*h+n*n,(r=(i=2*this.radius_g*n)*i-4*e*this.C)<0)return t.x=Number.NaN,t.y=Number.NaN,t;s=(-i-Math.sqrt(r))/(2*e),n=this.radius_g+s*n,a*=s,o*=s,t.x=Math.atan2(a,n),t.y=Math.atan(o*Math.cos(t.x)/n),t.y=Math.atan(this.radius_p_inv2*Math.tan(t.y))}else if("sphere"===this.shape){if(this.flip_axis?(o=Math.tan(t.y/this.radius_g_1),a=Math.tan(t.x/this.radius_g_1)*Math.sqrt(1+o*o)):(a=Math.tan(t.x/this.radius_g_1),o=Math.tan(t.y/this.radius_g_1)*Math.sqrt(1+a*a)),e=a*a+o*o+n*n,(r=(i=2*this.radius_g*n)*i-4*e*this.C)<0)return t.x=Number.NaN,t.y=Number.NaN,t;s=(-i-Math.sqrt(r))/(2*e),n=this.radius_g+s*n,a*=s,o*=s,t.x=Math.atan2(a,n),t.y=Math.atan(o*Math.cos(t.x)/n)}return t.x=t.x+this.long0,t},names:["Geostationary Satellite View","Geostationary_Satellite","geos"]};xt.defaultDatum="WGS84",xt.Proj=ht,xt.WGS84=new xt.Proj("WGS84"),xt.Point=qt,xt.toPoint=_t,xt.defs=B,xt.nadgrid=function(t,e){var i=new DataView(e),r=function(t){var e=t.getInt32(8,!1);if(11===e)return!1;e=t.getInt32(8,!0),11!==e&&console.warn("Failed to detect nadgrid endian-ness, defaulting to little-endian");return!0}(i),s=function(t,e){return{nFields:t.getInt32(8,e),nSubgridFields:t.getInt32(24,e),nSubgrids:t.getInt32(40,e),shiftType:st(t,56,64).trim(),fromSemiMajorAxis:t.getFloat64(120,e),fromSemiMinorAxis:t.getFloat64(136,e),toSemiMajorAxis:t.getFloat64(152,e),toSemiMinorAxis:t.getFloat64(168,e)}}(i,r),n=function(t,e,i){for(var r=176,s=[],n=0;n>18&63]+Si[s>>12&63]+Si[s>>6&63]+Si[63&s]);return n.join("")}function Ni(t){var e;Oi||Pi();for(var i=t.length,r=i%3,s="",n=[],a=16383,o=0,h=i-r;oh?h:o+a));return 1===r?(e=t[i-1],s+=Si[e>>2],s+=Si[e<<4&63],s+="=="):2===r&&(e=(t[i-2]<<8)+t[i-1],s+=Si[e>>10],s+=Si[e>>4&63],s+=Si[e<<2&63],s+="="),n.push(s),n.join("")}function zi(t,e,i,r,s){var n,a,o=8*s-r-1,h=(1<>1,l=-7,c=i?s-1:0,f=i?-1:1,d=t[e+c];for(c+=f,n=d&(1<<-l)-1,d>>=-l,l+=o;l>0;n=256*n+t[e+c],c+=f,l-=8);for(a=n&(1<<-l)-1,n>>=-l,l+=r;l>0;a=256*a+t[e+c],c+=f,l-=8);if(0===n)n=1-u;else{if(n===h)return a?NaN:1/0*(d?-1:1);a+=Math.pow(2,r),n-=u}return(d?-1:1)*a*Math.pow(2,n-r)}function Ti(t,e,i,r,s,n){var a,o,h,u=8*n-s-1,l=(1<>1,f=23===s?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:n-1,p=r?1:-1,m=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(o=isNaN(e)?1:0,a=l):(a=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-a))<1&&(a--,h*=2),(e+=a+c>=1?f/h:f*Math.pow(2,1-c))*h>=2&&(a++,h/=2),a+c>=l?(o=0,a=l):a+c>=1?(o=(e*h-1)*Math.pow(2,s),a+=c):(o=e*Math.pow(2,c-1)*Math.pow(2,s),a=0));s>=8;t[i+d]=255&o,d+=p,o/=256,s-=8);for(a=a<0;t[i+d]=255&a,d+=p,a/=256,u-=8);t[i+d-p]|=128*m}var Bi={}.toString,Li=Array.isArray||function(t){return"[object Array]"==Bi.call(t)};function Di(){return ji.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function Ui(t,e){if(Di()=Di())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Di().toString(16)+" bytes");return 0|t}function Yi(t){return!(null==t||!t._isBuffer)}function Hi(t,e){if(Yi(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var i=t.length;if(0===i)return 0;for(var r=!1;;)switch(e){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":case void 0:return br(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return wr(t).length;default:if(r)return br(t).length;e=(""+e).toLowerCase(),r=!0}}function Ki(t,e,i){var r=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return ur(this,e,i);case"utf8":case"utf-8":return nr(this,e,i);case"ascii":return or(this,e,i);case"latin1":case"binary":return hr(this,e,i);case"base64":return sr(this,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return lr(this,e,i);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=!0}}function Xi(t,e,i){var r=t[e];t[e]=t[i],t[i]=r}function Ji(t,e,i,r,s){if(0===t.length)return-1;if("string"==typeof i?(r=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),i=+i,isNaN(i)&&(i=s?0:t.length-1),i<0&&(i=t.length+i),i>=t.length){if(s)return-1;i=t.length-1}else if(i<0){if(!s)return-1;i=0}if("string"==typeof e&&(e=ji.from(e,r)),Yi(e))return 0===e.length?-1:Qi(t,e,i,r,s);if("number"==typeof e)return e&=255,ji.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?s?Uint8Array.prototype.indexOf.call(t,e,i):Uint8Array.prototype.lastIndexOf.call(t,e,i):Qi(t,[e],i,r,s);throw new TypeError("val must be string, number or Buffer")}function Qi(t,e,i,r,s){var n,a=1,o=t.length,h=e.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(t.length<2||e.length<2)return-1;a=2,o/=2,h/=2,i/=2}function u(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(s){var l=-1;for(n=i;no&&(i=o-h),n=i;n>=0;n--){for(var c=!0,f=0;fs&&(r=s):r=s;var n=e.length;if(n%2!=0)throw new TypeError("Invalid hex string");r>n/2&&(r=n/2);for(var a=0;a>8,s=i%256,n.push(s),n.push(r);return n}(e,t.length-i),t,i,r)}function sr(t,e,i){return 0===e&&i===t.length?Ni(t):Ni(t.slice(e,i))}function nr(t,e,i){i=Math.min(t.length,i);for(var r=[],s=e;s239?4:u>223?3:u>191?2:1;if(s+c<=i)switch(c){case 1:u<128&&(l=u);break;case 2:128==(192&(n=t[s+1]))&&(h=(31&u)<<6|63&n)>127&&(l=h);break;case 3:n=t[s+1],a=t[s+2],128==(192&n)&&128==(192&a)&&(h=(15&u)<<12|(63&n)<<6|63&a)>2047&&(h<55296||h>57343)&&(l=h);break;case 4:n=t[s+1],a=t[s+2],o=t[s+3],128==(192&n)&&128==(192&a)&&128==(192&o)&&(h=(15&u)<<18|(63&n)<<12|(63&a)<<6|63&o)>65535&&h<1114112&&(l=h)}null===l?(l=65533,c=1):l>65535&&(l-=65536,r.push(l>>>10&1023|55296),l=56320|1023&l),r.push(l),s+=c}return function(t){var e=t.length;if(e<=ar)return String.fromCharCode.apply(String,t);var i="",r=0;for(;r0&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(t+=" ... ")),""},ji.prototype.compare=function(t,e,i,r,s){if(!Yi(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===i&&(i=t?t.length:0),void 0===r&&(r=0),void 0===s&&(s=this.length),e<0||i>t.length||r<0||s>this.length)throw new RangeError("out of range index");if(r>=s&&e>=i)return 0;if(r>=s)return-1;if(e>=i)return 1;if(this===t)return 0;for(var n=(s>>>=0)-(r>>>=0),a=(i>>>=0)-(e>>>=0),o=Math.min(n,a),h=this.slice(r,s),u=t.slice(e,i),l=0;ls)&&(i=s),t.length>0&&(i<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var n=!1;;)switch(r){case"hex":return Vi(this,t,e,i);case"utf8":case"utf-8":return $i(this,t,e,i);case"ascii":return tr(this,t,e,i);case"latin1":case"binary":return er(this,t,e,i);case"base64":return ir(this,t,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return rr(this,t,e,i);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),n=!0}},ji.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var ar=4096;function or(t,e,i){var r="";i=Math.min(t.length,i);for(var s=e;sr)&&(i=r);for(var s="",n=e;ni)throw new RangeError("Trying to access beyond buffer length")}function fr(t,e,i,r,s,n){if(!Yi(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>s||et.length)throw new RangeError("Index out of range")}function dr(t,e,i,r){e<0&&(e=65535+e+1);for(var s=0,n=Math.min(t.length-i,2);s>>8*(r?s:1-s)}function pr(t,e,i,r){e<0&&(e=4294967295+e+1);for(var s=0,n=Math.min(t.length-i,4);s>>8*(r?s:3-s)&255}function mr(t,e,i,r,s,n){if(i+r>t.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function gr(t,e,i,r,s){return s||mr(t,0,i,4),Ti(t,e,i,r,23,4),i+4}function _r(t,e,i,r,s){return s||mr(t,0,i,8),Ti(t,e,i,r,52,8),i+8}ji.prototype.slice=function(t,e){var i,r=this.length;if((t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e0&&(s*=256);)r+=this[t+--e]*s;return r},ji.prototype.readUInt8=function(t,e){return e||cr(t,1,this.length),this[t]},ji.prototype.readUInt16LE=function(t,e){return e||cr(t,2,this.length),this[t]|this[t+1]<<8},ji.prototype.readUInt16BE=function(t,e){return e||cr(t,2,this.length),this[t]<<8|this[t+1]},ji.prototype.readUInt32LE=function(t,e){return e||cr(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},ji.prototype.readUInt32BE=function(t,e){return e||cr(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},ji.prototype.readIntLE=function(t,e,i){t|=0,e|=0,i||cr(t,e,this.length);for(var r=this[t],s=1,n=0;++n=(s*=128)&&(r-=Math.pow(2,8*e)),r},ji.prototype.readIntBE=function(t,e,i){t|=0,e|=0,i||cr(t,e,this.length);for(var r=e,s=1,n=this[t+--r];r>0&&(s*=256);)n+=this[t+--r]*s;return n>=(s*=128)&&(n-=Math.pow(2,8*e)),n},ji.prototype.readInt8=function(t,e){return e||cr(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},ji.prototype.readInt16LE=function(t,e){e||cr(t,2,this.length);var i=this[t]|this[t+1]<<8;return 32768&i?4294901760|i:i},ji.prototype.readInt16BE=function(t,e){e||cr(t,2,this.length);var i=this[t+1]|this[t]<<8;return 32768&i?4294901760|i:i},ji.prototype.readInt32LE=function(t,e){return e||cr(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},ji.prototype.readInt32BE=function(t,e){return e||cr(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},ji.prototype.readFloatLE=function(t,e){return e||cr(t,4,this.length),zi(this,t,!0,23,4)},ji.prototype.readFloatBE=function(t,e){return e||cr(t,4,this.length),zi(this,t,!1,23,4)},ji.prototype.readDoubleLE=function(t,e){return e||cr(t,8,this.length),zi(this,t,!0,52,8)},ji.prototype.readDoubleBE=function(t,e){return e||cr(t,8,this.length),zi(this,t,!1,52,8)},ji.prototype.writeUIntLE=function(t,e,i,r){(t=+t,e|=0,i|=0,r)||fr(this,t,e,i,Math.pow(2,8*i)-1,0);var s=1,n=0;for(this[e]=255&t;++n=0&&(n*=256);)this[e+s]=t/n&255;return e+i},ji.prototype.writeUInt8=function(t,e,i){return t=+t,e|=0,i||fr(this,t,e,1,255,0),ji.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},ji.prototype.writeUInt16LE=function(t,e,i){return t=+t,e|=0,i||fr(this,t,e,2,65535,0),ji.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):dr(this,t,e,!0),e+2},ji.prototype.writeUInt16BE=function(t,e,i){return t=+t,e|=0,i||fr(this,t,e,2,65535,0),ji.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):dr(this,t,e,!1),e+2},ji.prototype.writeUInt32LE=function(t,e,i){return t=+t,e|=0,i||fr(this,t,e,4,4294967295,0),ji.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):pr(this,t,e,!0),e+4},ji.prototype.writeUInt32BE=function(t,e,i){return t=+t,e|=0,i||fr(this,t,e,4,4294967295,0),ji.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):pr(this,t,e,!1),e+4},ji.prototype.writeIntLE=function(t,e,i,r){if(t=+t,e|=0,!r){var s=Math.pow(2,8*i-1);fr(this,t,e,i,s-1,-s)}var n=0,a=1,o=0;for(this[e]=255&t;++n=0&&(a*=256);)t<0&&0===o&&0!==this[e+n+1]&&(o=1),this[e+n]=(t/a|0)-o&255;return e+i},ji.prototype.writeInt8=function(t,e,i){return t=+t,e|=0,i||fr(this,t,e,1,127,-128),ji.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},ji.prototype.writeInt16LE=function(t,e,i){return t=+t,e|=0,i||fr(this,t,e,2,32767,-32768),ji.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):dr(this,t,e,!0),e+2},ji.prototype.writeInt16BE=function(t,e,i){return t=+t,e|=0,i||fr(this,t,e,2,32767,-32768),ji.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):dr(this,t,e,!1),e+2},ji.prototype.writeInt32LE=function(t,e,i){return t=+t,e|=0,i||fr(this,t,e,4,2147483647,-2147483648),ji.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):pr(this,t,e,!0),e+4},ji.prototype.writeInt32BE=function(t,e,i){return t=+t,e|=0,i||fr(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),ji.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):pr(this,t,e,!1),e+4},ji.prototype.writeFloatLE=function(t,e,i){return gr(this,t,e,!0,i)},ji.prototype.writeFloatBE=function(t,e,i){return gr(this,t,e,!1,i)},ji.prototype.writeDoubleLE=function(t,e,i){return _r(this,t,e,!0,i)},ji.prototype.writeDoubleBE=function(t,e,i){return _r(this,t,e,!1,i)},ji.prototype.copy=function(t,e,i,r){if(i||(i=0),r||0===r||(r=this.length),e>=t.length&&(e=t.length),e||(e=0),r>0&&r=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-e=0;--s)t[s+e]=this[s+i];else if(n<1e3||!ji.TYPED_ARRAY_SUPPORT)for(s=0;s>>=0,i=void 0===i?this.length:i>>>0,t||(t=0),"number"==typeof t)for(n=e;n55295&&i<57344){if(!s){if(i>56319){(e-=3)>-1&&n.push(239,191,189);continue}if(a+1===r){(e-=3)>-1&&n.push(239,191,189);continue}s=i;continue}if(i<56320){(e-=3)>-1&&n.push(239,191,189),s=i;continue}i=65536+(s-55296<<10|i-56320)}else s&&(e-=3)>-1&&n.push(239,191,189);if(s=null,i<128){if((e-=1)<0)break;n.push(i)}else if(i<2048){if((e-=2)<0)break;n.push(i>>6|192,63&i|128)}else if(i<65536){if((e-=3)<0)break;n.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;n.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return n}function wr(t){return function(t){var e,i,r,s,n,a;Oi||Pi();var o=t.length;if(o%4>0)throw new Error("Invalid string. Length must be a multiple of 4");n="="===t[o-2]?2:"="===t[o-1]?1:0,a=new Ii(3*o/4-n),r=n>0?o-4:o;var h=0;for(e=0,i=0;e>16&255,a[h++]=s>>8&255,a[h++]=255&s;return 2===n?(s=Ci[t.charCodeAt(e)]<<2|Ci[t.charCodeAt(e+1)]>>4,a[h++]=255&s):1===n&&(s=Ci[t.charCodeAt(e)]<<10|Ci[t.charCodeAt(e+1)]<<4|Ci[t.charCodeAt(e+2)]>>2,a[h++]=s>>8&255,a[h++]=255&s),a}(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(yr,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function Mr(t,e,i,r){for(var s=0;s=e.length||s>=t.length);++s)e[s+i]=t[s];return s}function xr(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}function kr(){throw new Error("setTimeout has not been defined")}function Er(){throw new Error("clearTimeout has not been defined")}var Ar=kr,Sr=Er;function Cr(t){if(Ar===setTimeout)return setTimeout(t,0);if((Ar===kr||!Ar)&&setTimeout)return Ar=setTimeout,setTimeout(t,0);try{return Ar(t,0)}catch(e){try{return Ar.call(null,t,0)}catch(e){return Ar.call(this,t,0)}}}"function"==typeof Ai.setTimeout&&(Ar=setTimeout),"function"==typeof Ai.clearTimeout&&(Sr=clearTimeout);var Ir,Or=[],Pr=!1,Rr=-1;function Nr(){Pr&&Ir&&(Pr=!1,Ir.length?Or=Ir.concat(Or):Rr=-1,Or.length&&zr())}function zr(){if(!Pr){var t=Cr(Nr);Pr=!0;for(var e=Or.length;e;){for(Ir=Or,Or=[];++Rr1)for(var i=1;i>2,o=(3&e)<<4|i>>4,h=1>6:64,u=2>4,i=(15&a)<<4|(o=n.indexOf(t.charAt(u++)))>>2,r=(3&o)<<6|(h=n.indexOf(t.charAt(u++))),f[l++]=e,64!==o&&(f[l++]=i),64!==h&&(f[l++]=r);return f}},{"./support":30,"./utils":32}],2:[function(t,e,i){var r=t("./external"),s=t("./stream/DataWorker"),n=t("./stream/Crc32Probe"),a=t("./stream/DataLengthProbe");function o(t,e,i,r,s){this.compressedSize=t,this.uncompressedSize=e,this.crc32=i,this.compression=r,this.compressedContent=s}o.prototype={getContentWorker:function(){var t=new s(r.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new a("data_length")),e=this;return t.on("end",(function(){if(this.streamInfo.data_length!==e.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")})),t},getCompressedWorker:function(){return new s(r.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},o.createWorkerFrom=function(t,e,i){return t.pipe(new n).pipe(new a("uncompressedSize")).pipe(e.compressWorker(i)).pipe(new a("compressedSize")).withStreamInfo("compression",e)},e.exports=o},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(t,e,i){var r=t("./stream/GenericWorker");i.STORE={magic:"\0\0",compressWorker:function(){return new r("STORE compression")},uncompressWorker:function(){return new r("STORE decompression")}},i.DEFLATE=t("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(t,e,i){var r=t("./utils"),s=function(){for(var t,e=[],i=0;i<256;i++){t=i;for(var r=0;r<8;r++)t=1&t?3988292384^t>>>1:t>>>1;e[i]=t}return e}();e.exports=function(t,e){return void 0!==t&&t.length?"string"!==r.getTypeOf(t)?function(t,e,i,r){var n=s,a=r+i;t^=-1;for(var o=r;o>>8^n[255&(t^e[o])];return~t}(0|e,t,t.length,0):function(t,e,i,r){var n=s,a=r+i;t^=-1;for(var o=r;o>>8^n[255&(t^e.charCodeAt(o))];return~t}(0|e,t,t.length,0):0}},{"./utils":32}],5:[function(t,e,i){i.base64=!1,i.binary=!1,i.dir=!1,i.createFolders=!0,i.date=null,i.compression=null,i.compressionOptions=null,i.comment=null,i.unixPermissions=null,i.dosPermissions=null},{}],6:[function(t,e,i){var r=null;r="undefined"!=typeof Promise?Promise:t("lie"),e.exports={Promise:r}},{lie:37}],7:[function(t,e,i){var r="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array,s=t("pako"),n=t("./utils"),a=t("./stream/GenericWorker"),o=r?"uint8array":"array";function h(t,e){a.call(this,"FlateWorker/"+t),this._pako=null,this._pakoAction=t,this._pakoOptions=e,this.meta={}}i.magic="\b\0",n.inherits(h,a),h.prototype.processChunk=function(t){this.meta=t.meta,null===this._pako&&this._createPako(),this._pako.push(n.transformTo(o,t.data),!1)},h.prototype.flush=function(){a.prototype.flush.call(this),null===this._pako&&this._createPako(),this._pako.push([],!0)},h.prototype.cleanUp=function(){a.prototype.cleanUp.call(this),this._pako=null},h.prototype._createPako=function(){this._pako=new s[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var t=this;this._pako.onData=function(e){t.push({data:e,meta:t.meta})}},i.compressWorker=function(t){return new h("Deflate",t)},i.uncompressWorker=function(){return new h("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(t,e,i){function r(t,e){var i,r="";for(i=0;i>>=8;return r}function s(t,e,i,s,a,l){var c,f,d=t.file,p=t.compression,m=l!==o.utf8encode,g=n.transformTo("string",l(d.name)),_=n.transformTo("string",o.utf8encode(d.name)),y=d.comment,v=n.transformTo("string",l(y)),b=n.transformTo("string",o.utf8encode(y)),w=_.length!==d.name.length,M=b.length!==y.length,x="",k="",E="",A=d.dir,S=d.date,C={crc32:0,compressedSize:0,uncompressedSize:0};e&&!i||(C.crc32=t.crc32,C.compressedSize=t.compressedSize,C.uncompressedSize=t.uncompressedSize);var I=0;e&&(I|=8),m||!w&&!M||(I|=2048);var O=0,P=0;A&&(O|=16),"UNIX"===a?(P=798,O|=function(t,e){var i=t;return t||(i=e?16893:33204),(65535&i)<<16}(d.unixPermissions,A)):(P=20,O|=function(t){return 63&(t||0)}(d.dosPermissions)),c=S.getUTCHours(),c<<=6,c|=S.getUTCMinutes(),c<<=5,c|=S.getUTCSeconds()/2,f=S.getUTCFullYear()-1980,f<<=4,f|=S.getUTCMonth()+1,f<<=5,f|=S.getUTCDate(),w&&(k=r(1,1)+r(h(g),4)+_,x+="up"+r(k.length,2)+k),M&&(E=r(1,1)+r(h(v),4)+b,x+="uc"+r(E.length,2)+E);var R="";return R+="\n\0",R+=r(I,2),R+=p.magic,R+=r(c,2),R+=r(f,2),R+=r(C.crc32,4),R+=r(C.compressedSize,4),R+=r(C.uncompressedSize,4),R+=r(g.length,2),R+=r(x.length,2),{fileRecord:u.LOCAL_FILE_HEADER+R+g+x,dirRecord:u.CENTRAL_FILE_HEADER+r(P,2)+R+r(v.length,2)+"\0\0\0\0"+r(O,4)+r(s,4)+g+x+v}}var n=t("../utils"),a=t("../stream/GenericWorker"),o=t("../utf8"),h=t("../crc32"),u=t("../signature");function l(t,e,i,r){a.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=e,this.zipPlatform=i,this.encodeFileName=r,this.streamFiles=t,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}n.inherits(l,a),l.prototype.push=function(t){var e=t.meta.percent||0,i=this.entriesCount,r=this._sources.length;this.accumulate?this.contentBuffer.push(t):(this.bytesWritten+=t.data.length,a.prototype.push.call(this,{data:t.data,meta:{currentFile:this.currentFile,percent:i?(e+100*(i-r-1))/i:100}}))},l.prototype.openedSource=function(t){this.currentSourceOffset=this.bytesWritten,this.currentFile=t.file.name;var e=this.streamFiles&&!t.file.dir;if(e){var i=s(t,e,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:i.fileRecord,meta:{percent:0}})}else this.accumulate=!0},l.prototype.closedSource=function(t){this.accumulate=!1;var e=this.streamFiles&&!t.file.dir,i=s(t,e,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(i.dirRecord),e)this.push({data:function(t){return u.DATA_DESCRIPTOR+r(t.crc32,4)+r(t.compressedSize,4)+r(t.uncompressedSize,4)}(t),meta:{percent:100}});else for(this.push({data:i.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null},l.prototype.flush=function(){for(var t=this.bytesWritten,e=0;e=this.index;e--)i=(i<<8)+this.byteAt(e);return this.index+=t,i},readString:function(t){return r.transformTo("string",this.readData(t))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var t=this.readInt(4);return new Date(Date.UTC(1980+(t>>25&127),(t>>21&15)-1,t>>16&31,t>>11&31,t>>5&63,(31&t)<<1))}},e.exports=s},{"../utils":32}],19:[function(t,e,i){var r=t("./Uint8ArrayReader");function s(t){r.call(this,t)}t("../utils").inherits(s,r),s.prototype.readData=function(t){this.checkOffset(t);var e=this.data.slice(this.zero+this.index,this.zero+this.index+t);return this.index+=t,e},e.exports=s},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(t,e,i){var r=t("./DataReader");function s(t){r.call(this,t)}t("../utils").inherits(s,r),s.prototype.byteAt=function(t){return this.data.charCodeAt(this.zero+t)},s.prototype.lastIndexOfSignature=function(t){return this.data.lastIndexOf(t)-this.zero},s.prototype.readAndCheckSignature=function(t){return t===this.readData(4)},s.prototype.readData=function(t){this.checkOffset(t);var e=this.data.slice(this.zero+this.index,this.zero+this.index+t);return this.index+=t,e},e.exports=s},{"../utils":32,"./DataReader":18}],21:[function(t,e,i){var r=t("./ArrayReader");function s(t){r.call(this,t)}t("../utils").inherits(s,r),s.prototype.readData=function(t){if(this.checkOffset(t),0===t)return new Uint8Array(0);var e=this.data.subarray(this.zero+this.index,this.zero+this.index+t);return this.index+=t,e},e.exports=s},{"../utils":32,"./ArrayReader":17}],22:[function(t,e,i){var r=t("../utils"),s=t("../support"),n=t("./ArrayReader"),a=t("./StringReader"),o=t("./NodeBufferReader"),h=t("./Uint8ArrayReader");e.exports=function(t){var e=r.getTypeOf(t);return r.checkSupport(e),"string"!==e||s.uint8array?"nodebuffer"===e?new o(t):s.uint8array?new h(r.transformTo("uint8array",t)):new n(r.transformTo("array",t)):new a(t)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(t,e,i){i.LOCAL_FILE_HEADER="PK",i.CENTRAL_FILE_HEADER="PK",i.CENTRAL_DIRECTORY_END="PK",i.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK",i.ZIP64_CENTRAL_DIRECTORY_END="PK",i.DATA_DESCRIPTOR="PK\b"},{}],24:[function(t,e,i){var r=t("./GenericWorker"),s=t("../utils");function n(t){r.call(this,"ConvertWorker to "+t),this.destType=t}s.inherits(n,r),n.prototype.processChunk=function(t){this.push({data:s.transformTo(this.destType,t.data),meta:t.meta})},e.exports=n},{"../utils":32,"./GenericWorker":28}],25:[function(t,e,i){var r=t("./GenericWorker"),s=t("../crc32");function n(){r.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0)}t("../utils").inherits(n,r),n.prototype.processChunk=function(t){this.streamInfo.crc32=s(t.data,this.streamInfo.crc32||0),this.push(t)},e.exports=n},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(t,e,i){var r=t("../utils"),s=t("./GenericWorker");function n(t){s.call(this,"DataLengthProbe for "+t),this.propName=t,this.withStreamInfo(t,0)}r.inherits(n,s),n.prototype.processChunk=function(t){if(t){var e=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=e+t.data.length}s.prototype.processChunk.call(this,t)},e.exports=n},{"../utils":32,"./GenericWorker":28}],27:[function(t,e,i){var r=t("../utils"),s=t("./GenericWorker");function n(t){s.call(this,"DataWorker");var e=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,t.then((function(t){e.dataIsReady=!0,e.data=t,e.max=t&&t.length||0,e.type=r.getTypeOf(t),e.isPaused||e._tickAndRepeat()}),(function(t){e.error(t)}))}r.inherits(n,s),n.prototype.cleanUp=function(){s.prototype.cleanUp.call(this),this.data=null},n.prototype.resume=function(){return!!s.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,r.delay(this._tickAndRepeat,[],this)),!0)},n.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(r.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},n.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var t=null,e=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case"string":t=this.data.substring(this.index,e);break;case"uint8array":t=this.data.subarray(this.index,e);break;case"array":case"nodebuffer":t=this.data.slice(this.index,e)}return this.index=e,this.push({data:t,meta:{percent:this.max?this.index/this.max*100:0}})},e.exports=n},{"../utils":32,"./GenericWorker":28}],28:[function(t,e,i){function r(t){this.name=t||"default",this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null}r.prototype={push:function(t){this.emit("data",t)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit("end"),this.cleanUp(),this.isFinished=!0}catch(t){this.emit("error",t)}return!0},error:function(t){return!this.isFinished&&(this.isPaused?this.generatedError=t:(this.isFinished=!0,this.emit("error",t),this.previous&&this.previous.error(t),this.cleanUp()),!0)},on:function(t,e){return this._listeners[t].push(e),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(t,e){if(this._listeners[t])for(var i=0;i "+t:t}},e.exports=r},{}],29:[function(t,e,i){var r=t("../utils"),s=t("./ConvertWorker"),n=t("./GenericWorker"),a=t("../base64"),o=t("../support"),h=t("../external"),u=null;if(o.nodestream)try{u=t("../nodejs/NodejsStreamOutputAdapter")}catch(t){}function l(t,e){return new h.Promise((function(i,s){var n=[],o=t._internalType,h=t._outputType,u=t._mimeType;t.on("data",(function(t,i){n.push(t),e&&e(i)})).on("error",(function(t){n=[],s(t)})).on("end",(function(){try{var t=function(t,e,i){switch(t){case"blob":return r.newBlob(r.transformTo("arraybuffer",e),i);case"base64":return a.encode(e);default:return r.transformTo(t,e)}}(h,function(t,e){var i,r=0,s=null,n=0;for(i=0;i>>6:(i<65536?e[a++]=224|i>>>12:(e[a++]=240|i>>>18,e[a++]=128|i>>>12&63),e[a++]=128|i>>>6&63),e[a++]=128|63&i);return e}(t)},i.utf8decode=function(t){return s.nodebuffer?r.transformTo("nodebuffer",t).toString("utf-8"):function(t){var e,i,s,n,a=t.length,h=new Array(2*a);for(e=i=0;e>10&1023,h[i++]=56320|1023&s)}return h.length!==i&&(h.subarray?h=h.subarray(0,i):h.length=i),r.applyFromCharCode(h)}(t=r.transformTo(s.uint8array?"uint8array":"array",t))},r.inherits(u,a),u.prototype.processChunk=function(t){var e=r.transformTo(s.uint8array?"uint8array":"array",t.data);if(this.leftOver&&this.leftOver.length){if(s.uint8array){var n=e;(e=new Uint8Array(n.length+this.leftOver.length)).set(this.leftOver,0),e.set(n,this.leftOver.length)}else e=this.leftOver.concat(e);this.leftOver=null}var a=function(t,e){var i;for((e=e||t.length)>t.length&&(e=t.length),i=e-1;0<=i&&128==(192&t[i]);)i--;return i<0||0===i?e:i+o[t[i]]>e?i:e}(e),h=e;a!==e.length&&(s.uint8array?(h=e.subarray(0,a),this.leftOver=e.subarray(a,e.length)):(h=e.slice(0,a),this.leftOver=e.slice(a,e.length))),this.push({data:i.utf8decode(h),meta:t.meta})},u.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:i.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},i.Utf8DecodeWorker=u,r.inherits(l,a),l.prototype.processChunk=function(t){this.push({data:i.utf8encode(t.data),meta:t.meta})},i.Utf8EncodeWorker=l},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(t,e,i){var r=t("./support"),s=t("./base64"),n=t("./nodejsUtils"),a=t("./external");function o(t){return t}function h(t,e){for(var i=0;i>8;this.dir=!!(16&this.externalFileAttributes),0==t&&(this.dosPermissions=63&this.externalFileAttributes),3==t&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||"/"!==this.fileNameStr.slice(-1)||(this.dir=!0)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var t=r(this.extraFields[1].value);this.uncompressedSize===s.MAX_VALUE_32BITS&&(this.uncompressedSize=t.readInt(8)),this.compressedSize===s.MAX_VALUE_32BITS&&(this.compressedSize=t.readInt(8)),this.localHeaderOffset===s.MAX_VALUE_32BITS&&(this.localHeaderOffset=t.readInt(8)),this.diskNumberStart===s.MAX_VALUE_32BITS&&(this.diskNumberStart=t.readInt(4))}},readExtraFields:function(t){var e,i,r,s=t.index+this.extraFieldsLength;for(this.extraFields||(this.extraFields={});t.index+4>>6:(i<65536?e[a++]=224|i>>>12:(e[a++]=240|i>>>18,e[a++]=128|i>>>12&63),e[a++]=128|i>>>6&63),e[a++]=128|63&i);return e},i.buf2binstring=function(t){return h(t,t.length)},i.binstring2buf=function(t){for(var e=new r.Buf8(t.length),i=0,s=e.length;i>10&1023,u[r++]=56320|1023&s)}return h(u,r)},i.utf8border=function(t,e){var i;for((e=e||t.length)>t.length&&(e=t.length),i=e-1;0<=i&&128==(192&t[i]);)i--;return i<0||0===i?e:i+a[t[i]]>e?i:e}},{"./common":41}],43:[function(t,e,i){e.exports=function(t,e,i,r){for(var s=65535&t,n=t>>>16&65535,a=0;0!==i;){for(i-=a=2e3>>1:t>>>1;e[i]=t}return e}();e.exports=function(t,e,i,s){var n=r,a=s+i;t^=-1;for(var o=s;o>>8^n[255&(t^e[o])];return~t}},{}],46:[function(t,e,i){var r,s=t("../utils/common"),n=t("./trees"),a=t("./adler32"),o=t("./crc32"),h=t("./messages"),u=0,l=4,c=0,f=-2,d=-1,p=4,m=2,g=8,_=9,y=286,v=30,b=19,w=2*y+1,M=15,x=3,k=258,E=k+x+1,A=42,S=113,C=1,I=2,O=3,P=4;function R(t,e){return t.msg=h[e],e}function N(t){return(t<<1)-(4t.avail_out&&(i=t.avail_out),0!==i&&(s.arraySet(t.output,e.pending_buf,e.pending_out,i,t.next_out),t.next_out+=i,e.pending_out+=i,t.total_out+=i,t.avail_out-=i,e.pending-=i,0===e.pending&&(e.pending_out=0))}function B(t,e){n._tr_flush_block(t,0<=t.block_start?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,T(t.strm)}function L(t,e){t.pending_buf[t.pending++]=e}function D(t,e){t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e}function U(t,e){var i,r,s=t.max_chain_length,n=t.strstart,a=t.prev_length,o=t.nice_match,h=t.strstart>t.w_size-E?t.strstart-(t.w_size-E):0,u=t.window,l=t.w_mask,c=t.prev,f=t.strstart+k,d=u[n+a-1],p=u[n+a];t.prev_length>=t.good_match&&(s>>=2),o>t.lookahead&&(o=t.lookahead);do{if(u[(i=e)+a]===p&&u[i+a-1]===d&&u[i]===u[n]&&u[++i]===u[n+1]){n+=2,i++;do{}while(u[++n]===u[++i]&&u[++n]===u[++i]&&u[++n]===u[++i]&&u[++n]===u[++i]&&u[++n]===u[++i]&&u[++n]===u[++i]&&u[++n]===u[++i]&&u[++n]===u[++i]&&nh&&0!=--s);return a<=t.lookahead?a:t.lookahead}function j(t){var e,i,r,n,h,u,l,c,f,d,p=t.w_size;do{if(n=t.window_size-t.lookahead-t.strstart,t.strstart>=p+(p-E)){for(s.arraySet(t.window,t.window,p,p,0),t.match_start-=p,t.strstart-=p,t.block_start-=p,e=i=t.hash_size;r=t.head[--e],t.head[e]=p<=r?r-p:0,--i;);for(e=i=p;r=t.prev[--e],t.prev[e]=p<=r?r-p:0,--i;);n+=p}if(0===t.strm.avail_in)break;if(u=t.strm,l=t.window,c=t.strstart+t.lookahead,d=void 0,(f=n)<(d=u.avail_in)&&(d=f),i=0===d?0:(u.avail_in-=d,s.arraySet(l,u.input,u.next_in,d,c),1===u.state.wrap?u.adler=a(u.adler,l,d,c):2===u.state.wrap&&(u.adler=o(u.adler,l,d,c)),u.next_in+=d,u.total_in+=d,d),t.lookahead+=i,t.lookahead+t.insert>=x)for(h=t.strstart-t.insert,t.ins_h=t.window[h],t.ins_h=(t.ins_h<=x&&(t.ins_h=(t.ins_h<=x)if(r=n._tr_tally(t,t.strstart-t.match_start,t.match_length-x),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=x){for(t.match_length--;t.strstart++,t.ins_h=(t.ins_h<=x&&(t.ins_h=(t.ins_h<=x&&t.match_length<=t.prev_length){for(s=t.strstart+t.lookahead-x,r=n._tr_tally(t,t.strstart-1-t.prev_match,t.prev_length-x),t.lookahead-=t.prev_length-1,t.prev_length-=2;++t.strstart<=s&&(t.ins_h=(t.ins_h<t.pending_buf_size-5&&(i=t.pending_buf_size-5);;){if(t.lookahead<=1){if(j(t),0===t.lookahead&&e===u)return C;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;var r=t.block_start+i;if((0===t.strstart||t.strstart>=r)&&(t.lookahead=t.strstart-r,t.strstart=r,B(t,!1),0===t.strm.avail_out))return C;if(t.strstart-t.block_start>=t.w_size-E&&(B(t,!1),0===t.strm.avail_out))return C}return t.insert=0,e===l?(B(t,!0),0===t.strm.avail_out?O:P):(t.strstart>t.block_start&&(B(t,!1),t.strm.avail_out),C)})),new G(4,4,8,4,F),new G(4,5,16,8,F),new G(4,6,32,32,F),new G(4,4,16,16,q),new G(8,16,32,32,q),new G(8,16,128,128,q),new G(8,32,128,256,q),new G(32,128,258,1024,q),new G(32,258,258,4096,q)],i.deflateInit=function(t,e){return H(t,e,g,15,8,0)},i.deflateInit2=H,i.deflateReset=Y,i.deflateResetKeep=Z,i.deflateSetHeader=function(t,e){return t&&t.state?2!==t.state.wrap?f:(t.state.gzhead=e,c):f},i.deflate=function(t,e){var i,s,a,h;if(!t||!t.state||5>8&255),L(s,s.gzhead.time>>16&255),L(s,s.gzhead.time>>24&255),L(s,9===s.level?2:2<=s.strategy||s.level<2?4:0),L(s,255&s.gzhead.os),s.gzhead.extra&&s.gzhead.extra.length&&(L(s,255&s.gzhead.extra.length),L(s,s.gzhead.extra.length>>8&255)),s.gzhead.hcrc&&(t.adler=o(t.adler,s.pending_buf,s.pending,0)),s.gzindex=0,s.status=69):(L(s,0),L(s,0),L(s,0),L(s,0),L(s,0),L(s,9===s.level?2:2<=s.strategy||s.level<2?4:0),L(s,3),s.status=S);else{var d=g+(s.w_bits-8<<4)<<8;d|=(2<=s.strategy||s.level<2?0:s.level<6?1:6===s.level?2:3)<<6,0!==s.strstart&&(d|=32),d+=31-d%31,s.status=S,D(s,d),0!==s.strstart&&(D(s,t.adler>>>16),D(s,65535&t.adler)),t.adler=1}if(69===s.status)if(s.gzhead.extra){for(a=s.pending;s.gzindex<(65535&s.gzhead.extra.length)&&(s.pending!==s.pending_buf_size||(s.gzhead.hcrc&&s.pending>a&&(t.adler=o(t.adler,s.pending_buf,s.pending-a,a)),T(t),a=s.pending,s.pending!==s.pending_buf_size));)L(s,255&s.gzhead.extra[s.gzindex]),s.gzindex++;s.gzhead.hcrc&&s.pending>a&&(t.adler=o(t.adler,s.pending_buf,s.pending-a,a)),s.gzindex===s.gzhead.extra.length&&(s.gzindex=0,s.status=73)}else s.status=73;if(73===s.status)if(s.gzhead.name){a=s.pending;do{if(s.pending===s.pending_buf_size&&(s.gzhead.hcrc&&s.pending>a&&(t.adler=o(t.adler,s.pending_buf,s.pending-a,a)),T(t),a=s.pending,s.pending===s.pending_buf_size)){h=1;break}h=s.gzindexa&&(t.adler=o(t.adler,s.pending_buf,s.pending-a,a)),0===h&&(s.gzindex=0,s.status=91)}else s.status=91;if(91===s.status)if(s.gzhead.comment){a=s.pending;do{if(s.pending===s.pending_buf_size&&(s.gzhead.hcrc&&s.pending>a&&(t.adler=o(t.adler,s.pending_buf,s.pending-a,a)),T(t),a=s.pending,s.pending===s.pending_buf_size)){h=1;break}h=s.gzindexa&&(t.adler=o(t.adler,s.pending_buf,s.pending-a,a)),0===h&&(s.status=103)}else s.status=103;if(103===s.status&&(s.gzhead.hcrc?(s.pending+2>s.pending_buf_size&&T(t),s.pending+2<=s.pending_buf_size&&(L(s,255&t.adler),L(s,t.adler>>8&255),t.adler=0,s.status=S)):s.status=S),0!==s.pending){if(T(t),0===t.avail_out)return s.last_flush=-1,c}else if(0===t.avail_in&&N(e)<=N(i)&&e!==l)return R(t,-5);if(666===s.status&&0!==t.avail_in)return R(t,-5);if(0!==t.avail_in||0!==s.lookahead||e!==u&&666!==s.status){var p=2===s.strategy?function(t,e){for(var i;;){if(0===t.lookahead&&(j(t),0===t.lookahead)){if(e===u)return C;break}if(t.match_length=0,i=n._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,i&&(B(t,!1),0===t.strm.avail_out))return C}return t.insert=0,e===l?(B(t,!0),0===t.strm.avail_out?O:P):t.last_lit&&(B(t,!1),0===t.strm.avail_out)?C:I}(s,e):3===s.strategy?function(t,e){for(var i,r,s,a,o=t.window;;){if(t.lookahead<=k){if(j(t),t.lookahead<=k&&e===u)return C;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=x&&0t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=x?(i=n._tr_tally(t,1,t.match_length-x),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(i=n._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),i&&(B(t,!1),0===t.strm.avail_out))return C}return t.insert=0,e===l?(B(t,!0),0===t.strm.avail_out?O:P):t.last_lit&&(B(t,!1),0===t.strm.avail_out)?C:I}(s,e):r[s.level].func(s,e);if(p!==O&&p!==P||(s.status=666),p===C||p===O)return 0===t.avail_out&&(s.last_flush=-1),c;if(p===I&&(1===e?n._tr_align(s):5!==e&&(n._tr_stored_block(s,0,0,!1),3===e&&(z(s.head),0===s.lookahead&&(s.strstart=0,s.block_start=0,s.insert=0))),T(t),0===t.avail_out))return s.last_flush=-1,c}return e!==l?c:s.wrap<=0?1:(2===s.wrap?(L(s,255&t.adler),L(s,t.adler>>8&255),L(s,t.adler>>16&255),L(s,t.adler>>24&255),L(s,255&t.total_in),L(s,t.total_in>>8&255),L(s,t.total_in>>16&255),L(s,t.total_in>>24&255)):(D(s,t.adler>>>16),D(s,65535&t.adler)),T(t),0=i.w_size&&(0===o&&(z(i.head),i.strstart=0,i.block_start=0,i.insert=0),d=new s.Buf8(i.w_size),s.arraySet(d,e,p-i.w_size,i.w_size,0),e=d,p=i.w_size),h=t.avail_in,u=t.next_in,l=t.input,t.avail_in=p,t.next_in=0,t.input=e,j(i);i.lookahead>=x;){for(r=i.strstart,n=i.lookahead-(x-1);i.ins_h=(i.ins_h<>>=b=v>>>24,p-=b,0==(b=v>>>16&255))A[n++]=65535&v;else{if(!(16&b)){if(!(64&b)){v=m[(65535&v)+(d&(1<>>=b,p-=b),p<15&&(d+=E[r++]<>>=b=v>>>24,p-=b,!(16&(b=v>>>16&255))){if(!(64&b)){v=g[(65535&v)+(d&(1<>>=b,p-=b,(b=n-a)>3,d&=(1<<(p-=w<<3))-1,t.next_in=r,t.next_out=n,t.avail_in=r>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24)}function g(){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 r.Buf16(320),this.work=new r.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function _(t){var e;return t&&t.state?(e=t.state,t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=f,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new r.Buf32(d),e.distcode=e.distdyn=new r.Buf32(p),e.sane=1,e.back=-1,l):c}function y(t){var e;return t&&t.state?((e=t.state).wsize=0,e.whave=0,e.wnext=0,_(t)):c}function v(t,e){var i,r;return t&&t.state?(r=t.state,e<0?(i=0,e=-e):(i=1+(e>>4),e<48&&(e&=15)),e&&(e<8||15=a.wsize?(r.arraySet(a.window,e,i-a.wsize,a.wsize,0),a.wnext=0,a.whave=a.wsize):(s<(n=a.wsize-a.wnext)&&(n=s),r.arraySet(a.window,e,i-s,n,a.wnext),(s-=n)?(r.arraySet(a.window,e,i-s,s,0),a.wnext=s,a.whave=a.wsize):(a.wnext+=n,a.wnext===a.wsize&&(a.wnext=0),a.whave>>8&255,i.check=n(i.check,j,2,0),w=b=0,i.mode=2;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&b)<<8)+(b>>8))%31){t.msg="incorrect header check",i.mode=30;break}if(8!=(15&b)){t.msg="unknown compression method",i.mode=30;break}if(w-=4,T=8+(15&(b>>>=4)),0===i.wbits)i.wbits=T;else if(T>i.wbits){t.msg="invalid window size",i.mode=30;break}i.dmax=1<>8&1),512&i.flags&&(j[0]=255&b,j[1]=b>>>8&255,i.check=n(i.check,j,2,0)),w=b=0,i.mode=3;case 3:for(;w<32;){if(0===y)break t;y--,b+=d[g++]<>>8&255,j[2]=b>>>16&255,j[3]=b>>>24&255,i.check=n(i.check,j,4,0)),w=b=0,i.mode=4;case 4:for(;w<16;){if(0===y)break t;y--,b+=d[g++]<>8),512&i.flags&&(j[0]=255&b,j[1]=b>>>8&255,i.check=n(i.check,j,2,0)),w=b=0,i.mode=5;case 5:if(1024&i.flags){for(;w<16;){if(0===y)break t;y--,b+=d[g++]<>>8&255,i.check=n(i.check,j,2,0)),w=b=0}else i.head&&(i.head.extra=null);i.mode=6;case 6:if(1024&i.flags&&(y<(A=i.length)&&(A=y),A&&(i.head&&(T=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Array(i.head.extra_len)),r.arraySet(i.head.extra,d,g,A,T)),512&i.flags&&(i.check=n(i.check,d,A,g)),y-=A,g+=A,i.length-=A),i.length))break t;i.length=0,i.mode=7;case 7:if(2048&i.flags){if(0===y)break t;for(A=0;T=d[g+A++],i.head&&T&&i.length<65536&&(i.head.name+=String.fromCharCode(T)),T&&A>9&1,i.head.done=!0),t.adler=i.check=0,i.mode=12;break;case 10:for(;w<32;){if(0===y)break t;y--,b+=d[g++]<>>=7&w,w-=7&w,i.mode=27;break}for(;w<3;){if(0===y)break t;y--,b+=d[g++]<>>=1)){case 0:i.mode=14;break;case 1:if(k(i),i.mode=20,6!==e)break;b>>>=2,w-=2;break t;case 2:i.mode=17;break;case 3:t.msg="invalid block type",i.mode=30}b>>>=2,w-=2;break;case 14:for(b>>>=7&w,w-=7&w;w<32;){if(0===y)break t;y--,b+=d[g++]<>>16^65535)){t.msg="invalid stored block lengths",i.mode=30;break}if(i.length=65535&b,w=b=0,i.mode=15,6===e)break t;case 15:i.mode=16;case 16:if(A=i.length){if(y>>=5,w-=5,i.ndist=1+(31&b),b>>>=5,w-=5,i.ncode=4+(15&b),b>>>=4,w-=4,286>>=3,w-=3}for(;i.have<19;)i.lens[F[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,L={bits:i.lenbits},B=o(0,i.lens,0,19,i.lencode,0,i.work,L),i.lenbits=L.bits,B){t.msg="invalid code lengths set",i.mode=30;break}i.have=0,i.mode=19;case 19:for(;i.have>>16&255,P=65535&U,!((I=U>>>24)<=w);){if(0===y)break t;y--,b+=d[g++]<>>=I,w-=I,i.lens[i.have++]=P;else{if(16===P){for(D=I+2;w>>=I,w-=I,0===i.have){t.msg="invalid bit length repeat",i.mode=30;break}T=i.lens[i.have-1],A=3+(3&b),b>>>=2,w-=2}else if(17===P){for(D=I+3;w>>=I)),b>>>=3,w-=3}else{for(D=I+7;w>>=I)),b>>>=7,w-=7}if(i.have+A>i.nlen+i.ndist){t.msg="invalid bit length repeat",i.mode=30;break}for(;A--;)i.lens[i.have++]=T}}if(30===i.mode)break;if(0===i.lens[256]){t.msg="invalid code -- missing end-of-block",i.mode=30;break}if(i.lenbits=9,L={bits:i.lenbits},B=o(h,i.lens,0,i.nlen,i.lencode,0,i.work,L),i.lenbits=L.bits,B){t.msg="invalid literal/lengths set",i.mode=30;break}if(i.distbits=6,i.distcode=i.distdyn,L={bits:i.distbits},B=o(u,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,L),i.distbits=L.bits,B){t.msg="invalid distances set",i.mode=30;break}if(i.mode=20,6===e)break t;case 20:i.mode=21;case 21:if(6<=y&&258<=v){t.next_out=_,t.avail_out=v,t.next_in=g,t.avail_in=y,i.hold=b,i.bits=w,a(t,x),_=t.next_out,p=t.output,v=t.avail_out,g=t.next_in,d=t.input,y=t.avail_in,b=i.hold,w=i.bits,12===i.mode&&(i.back=-1);break}for(i.back=0;O=(U=i.lencode[b&(1<>>16&255,P=65535&U,!((I=U>>>24)<=w);){if(0===y)break t;y--,b+=d[g++]<>R)])>>>16&255,P=65535&U,!(R+(I=U>>>24)<=w);){if(0===y)break t;y--,b+=d[g++]<>>=R,w-=R,i.back+=R}if(b>>>=I,w-=I,i.back+=I,i.length=P,0===O){i.mode=26;break}if(32&O){i.back=-1,i.mode=12;break}if(64&O){t.msg="invalid literal/length code",i.mode=30;break}i.extra=15&O,i.mode=22;case 22:if(i.extra){for(D=i.extra;w>>=i.extra,w-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=23;case 23:for(;O=(U=i.distcode[b&(1<>>16&255,P=65535&U,!((I=U>>>24)<=w);){if(0===y)break t;y--,b+=d[g++]<>R)])>>>16&255,P=65535&U,!(R+(I=U>>>24)<=w);){if(0===y)break t;y--,b+=d[g++]<>>=R,w-=R,i.back+=R}if(b>>>=I,w-=I,i.back+=I,64&O){t.msg="invalid distance code",i.mode=30;break}i.offset=P,i.extra=15&O,i.mode=24;case 24:if(i.extra){for(D=i.extra;w>>=i.extra,w-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){t.msg="invalid distance too far back",i.mode=30;break}i.mode=25;case 25:if(0===v)break t;if(A=x-v,i.offset>A){if((A=i.offset-A)>i.whave&&i.sane){t.msg="invalid distance too far back",i.mode=30;break}S=A>i.wnext?(A-=i.wnext,i.wsize-A):i.wnext-A,A>i.length&&(A=i.length),C=i.window}else C=p,S=_-i.offset,A=i.length;for(vy?(b=L[D+c[k]],N[z+c[k]]):(b=96,0),d=1<>I)+(p-=d)]=v<<24|b<<16|w,0!==p;);for(d=1<>=1;if(0!==d?(R&=d-1,R+=d):R=0,k++,0==--T[x]){if(x===A)break;x=e[i+c[k]]}if(S>>7)]}function L(t,e){t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255}function D(t,e,i){t.bi_valid>m-i?(t.bi_buf|=e<>m-t.bi_valid,t.bi_valid+=i-m):(t.bi_buf|=e<>>=1,i<<=1,0<--e;);return i>>>1}function F(t,e,i){var r,s,n=new Array(p+1),a=0;for(r=1;r<=p;r++)n[r]=a=a+i[r-1]<<1;for(s=0;s<=e;s++){var o=t[2*s+1];0!==o&&(t[2*s]=j(n[o]++,o))}}function q(t){var e;for(e=0;e>1;1<=i;i--)Z(t,n,i);for(s=h;i=t.heap[1],t.heap[1]=t.heap[t.heap_len--],Z(t,n,1),r=t.heap[1],t.heap[--t.heap_max]=i,t.heap[--t.heap_max]=r,n[2*s]=n[2*i]+n[2*r],t.depth[s]=(t.depth[i]>=t.depth[r]?t.depth[i]:t.depth[r])+1,n[2*i+1]=n[2*r+1]=s,t.heap[1]=s++,Z(t,n,1),2<=t.heap_len;);t.heap[--t.heap_max]=t.heap[1],function(t,e){var i,r,s,n,a,o,h=e.dyn_tree,u=e.max_code,l=e.stat_desc.static_tree,c=e.stat_desc.has_stree,f=e.stat_desc.extra_bits,m=e.stat_desc.extra_base,g=e.stat_desc.max_length,_=0;for(n=0;n<=p;n++)t.bl_count[n]=0;for(h[2*t.heap[t.heap_max]+1]=0,i=t.heap_max+1;i>=7;r>>=1)if(1&i&&0!==t.dyn_ltree[2*e])return s;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return n;for(e=32;e>>3,(o=t.static_len+3+7>>>3)<=a&&(a=o)):a=o=i+5,i+4<=a&&-1!==e?Q(t,e,i,r):4===t.strategy||o===a?(D(t,2+(r?1:0),3),Y(t,E,A)):(D(t,4+(r?1:0),3),function(t,e,i,r){var s;for(D(t,e-257,5),D(t,i-1,5),D(t,r-4,4),s=0;s>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&i,t.last_lit++,0===e?t.dyn_ltree[2*i]++:(t.matches++,e--,t.dyn_ltree[2*(C[i]+u+1)]++,t.dyn_dtree[2*B(e)]++),t.last_lit===t.lit_bufsize-1},i._tr_align=function(t){D(t,2,3),U(t,_,E),function(t){16===t.bi_valid?(L(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):8<=t.bi_valid&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)}(t)}},{"../utils/common":41}],53:[function(t,e,i){e.exports=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}},{}],54:[function(t,e,i){(function(t){!function(t,e){if(!t.setImmediate){var i,r,s,n,a=1,o={},h=!1,u=t.document,l=Object.getPrototypeOf&&Object.getPrototypeOf(t);l=l&&l.setTimeout?l:t,i="[object process]"==={}.toString.call(t.process)?function(t){Hr.nextTick((function(){f(t)}))}:function(){if(t.postMessage&&!t.importScripts){var e=!0,i=t.onmessage;return t.onmessage=function(){e=!1},t.postMessage("","*"),t.onmessage=i,e}}()?(n="setImmediate$"+Math.random()+"$",t.addEventListener?t.addEventListener("message",d,!1):t.attachEvent("onmessage",d),function(e){t.postMessage(n+e,"*")}):t.MessageChannel?((s=new MessageChannel).port1.onmessage=function(t){f(t.data)},function(t){s.port2.postMessage(t)}):u&&"onreadystatechange"in u.createElement("script")?(r=u.documentElement,function(t){var e=u.createElement("script");e.onreadystatechange=function(){f(t),e.onreadystatechange=null,r.removeChild(e),e=null},r.appendChild(e)}):function(t){setTimeout(f,0,t)},l.setImmediate=function(t){"function"!=typeof t&&(t=new Function(""+t));for(var e=new Array(arguments.length-1),r=0;r{if(!e)return t;const i=new ts(t);return i.pathname=`${i.pathname}.${e}`,i.href};async function is(t,e){if(!globalThis.fetch)return function(t,e){return new Promise((function(i,r){const s=es(t,e),n=new XMLHttpRequest;n.open("GET",s,!0),"prj"!==e&&"cpg"!==e&&(n.responseType="arraybuffer"),n.addEventListener("load",(function(){return n.status>399?"prj"===e||"cpg"===e?i(!1):r(new Error(n.status)):i("prj"!==e&&"cpg"!==e?ji.from(n.response):n.response)}),!1),n.send()}))}(t,e);const i=es(t,e),r="prj"===e||"cpg"===e;try{const t=await fetch(i);if(t.status>399)throw new Error(t.statusText);if(r)return t.text();const e=await t.arrayBuffer();return ji.from(e)}catch(t){if(console.log("ERROR",t,e),r||"dbf"===e)return!1;throw t}}function rs(t){let e=0,i=1;const r=t.length;let s,n;const a=[t[0][0],t[0][1],t[0][0],t[0][1]];for(;ia[2]&&(a[2]=n[0]),n[1]>a[3]&&(a[3]=n[1]);return{ring:t,clockWise:e>0,bbox:a,children:[]}}function ss(t,e){return!(t.bbox[0]>e.bbox[0])&&(!(t.bbox[1]>e.bbox[1])&&(!(t.bbox[2]20&&(e-=20),!(e in ns))throw new Error("I don't know that shp type");var i;this.parseFunc=this[ns[e]],this.parseCoord=(i=t)?function(t,e){const r=[t.readDoubleLE(e),t.readDoubleLE(e+8)];return i.inverse(r)}:function(t,e){return[t.readDoubleLE(e),t.readDoubleLE(e+8)]}},as.prototype.getShpCode=function(){return this.parseHeader().shpCode},as.prototype.parseHeader=function(){const t=this.buffer.subarray(0,100);return{length:t.readInt32BE(24)<<1,version:t.readInt32LE(28),shpCode:t.readInt32LE(32),bbox:[t.readDoubleLE(36),t.readDoubleLE(44),t.readDoubleLE(52),t.readDoubleLE(60)]}},as.prototype.getRows=function(){let t=100;const e=this.buffer.byteLength,i=e-8,r=[];let s;for(;t<=i&&(s=this.getRow(t,e),s);)t+=8,t+=s.len,s.type?r.push(this.parseFunc(s.data)):r.push(null);return r},as.prototype.getRow=function(t,e){const i=this.buffer.subarray(t,t+12),r=i.readInt32BE(4)<<1,s=i.readInt32BE(0);return 0===r?{id:s,len:r,type:0}:t+r+8>e?void 0:{id:s,len:r,data:this.buffer.subarray(t+12,t+r+8),type:i.readInt32LE(8)}};!function(t){!function(e){function i(t,e,i){return e<=t&&t<=i}t.exports&&e["encoding-indexes"];var r=Math.floor;function s(t){if(void 0===t)return{};if(t===Object(t))return t;throw TypeError("Could not convert argument to dictionary")}function n(t){return 0<=t&&t<=127}var a=n,o=-1;function h(t){this.tokens=[].slice.call(t),this.tokens.reverse()}h.prototype={endOfStream:function(){return!this.tokens.length},read:function(){return this.tokens.length?this.tokens.pop():o},prepend:function(t){if(Array.isArray(t))for(var e=t;e.length;)this.tokens.push(e.pop());else this.tokens.push(t)},push:function(t){if(Array.isArray(t))for(var e=t;e.length;)this.tokens.unshift(e.shift());else this.tokens.unshift(t)}};var u=-1;function l(t,e){if(t)throw TypeError("Decoder error");return e||65533}function c(t){throw TypeError("The code point "+t+" could not be encoded.")}function f(t){return t=String(t).trim().toLowerCase(),Object.prototype.hasOwnProperty.call(p,t)?p[t]:null}var d=[{encodings:[{labels:["unicode-1-1-utf-8","utf-8","utf8"],name:"UTF-8"}],heading:"The Encoding"},{encodings:[{labels:["866","cp866","csibm866","ibm866"],name:"IBM866"},{labels:["csisolatin2","iso-8859-2","iso-ir-101","iso8859-2","iso88592","iso_8859-2","iso_8859-2:1987","l2","latin2"],name:"ISO-8859-2"},{labels:["csisolatin3","iso-8859-3","iso-ir-109","iso8859-3","iso88593","iso_8859-3","iso_8859-3:1988","l3","latin3"],name:"ISO-8859-3"},{labels:["csisolatin4","iso-8859-4","iso-ir-110","iso8859-4","iso88594","iso_8859-4","iso_8859-4:1988","l4","latin4"],name:"ISO-8859-4"},{labels:["csisolatincyrillic","cyrillic","iso-8859-5","iso-ir-144","iso8859-5","iso88595","iso_8859-5","iso_8859-5:1988"],name:"ISO-8859-5"},{labels:["arabic","asmo-708","csiso88596e","csiso88596i","csisolatinarabic","ecma-114","iso-8859-6","iso-8859-6-e","iso-8859-6-i","iso-ir-127","iso8859-6","iso88596","iso_8859-6","iso_8859-6:1987"],name:"ISO-8859-6"},{labels:["csisolatingreek","ecma-118","elot_928","greek","greek8","iso-8859-7","iso-ir-126","iso8859-7","iso88597","iso_8859-7","iso_8859-7:1987","sun_eu_greek"],name:"ISO-8859-7"},{labels:["csiso88598e","csisolatinhebrew","hebrew","iso-8859-8","iso-8859-8-e","iso-ir-138","iso8859-8","iso88598","iso_8859-8","iso_8859-8:1988","visual"],name:"ISO-8859-8"},{labels:["csiso88598i","iso-8859-8-i","logical"],name:"ISO-8859-8-I"},{labels:["csisolatin6","iso-8859-10","iso-ir-157","iso8859-10","iso885910","l6","latin6"],name:"ISO-8859-10"},{labels:["iso-8859-13","iso8859-13","iso885913"],name:"ISO-8859-13"},{labels:["iso-8859-14","iso8859-14","iso885914"],name:"ISO-8859-14"},{labels:["csisolatin9","iso-8859-15","iso8859-15","iso885915","iso_8859-15","l9"],name:"ISO-8859-15"},{labels:["iso-8859-16"],name:"ISO-8859-16"},{labels:["cskoi8r","koi","koi8","koi8-r","koi8_r"],name:"KOI8-R"},{labels:["koi8-ru","koi8-u"],name:"KOI8-U"},{labels:["csmacintosh","mac","macintosh","x-mac-roman"],name:"macintosh"},{labels:["dos-874","iso-8859-11","iso8859-11","iso885911","tis-620","windows-874"],name:"windows-874"},{labels:["cp1250","windows-1250","x-cp1250"],name:"windows-1250"},{labels:["cp1251","windows-1251","x-cp1251"],name:"windows-1251"},{labels:["ansi_x3.4-1968","ascii","cp1252","cp819","csisolatin1","ibm819","iso-8859-1","iso-ir-100","iso8859-1","iso88591","iso_8859-1","iso_8859-1:1987","l1","latin1","us-ascii","windows-1252","x-cp1252"],name:"windows-1252"},{labels:["cp1253","windows-1253","x-cp1253"],name:"windows-1253"},{labels:["cp1254","csisolatin5","iso-8859-9","iso-ir-148","iso8859-9","iso88599","iso_8859-9","iso_8859-9:1989","l5","latin5","windows-1254","x-cp1254"],name:"windows-1254"},{labels:["cp1255","windows-1255","x-cp1255"],name:"windows-1255"},{labels:["cp1256","windows-1256","x-cp1256"],name:"windows-1256"},{labels:["cp1257","windows-1257","x-cp1257"],name:"windows-1257"},{labels:["cp1258","windows-1258","x-cp1258"],name:"windows-1258"},{labels:["x-mac-cyrillic","x-mac-ukrainian"],name:"x-mac-cyrillic"}],heading:"Legacy single-byte encodings"},{encodings:[{labels:["chinese","csgb2312","csiso58gb231280","gb2312","gb_2312","gb_2312-80","gbk","iso-ir-58","x-gbk"],name:"GBK"},{labels:["gb18030"],name:"gb18030"}],heading:"Legacy multi-byte Chinese (simplified) encodings"},{encodings:[{labels:["big5","big5-hkscs","cn-big5","csbig5","x-x-big5"],name:"Big5"}],heading:"Legacy multi-byte Chinese (traditional) encodings"},{encodings:[{labels:["cseucpkdfmtjapanese","euc-jp","x-euc-jp"],name:"EUC-JP"},{labels:["csiso2022jp","iso-2022-jp"],name:"ISO-2022-JP"},{labels:["csshiftjis","ms932","ms_kanji","shift-jis","shift_jis","sjis","windows-31j","x-sjis"],name:"Shift_JIS"}],heading:"Legacy multi-byte Japanese encodings"},{encodings:[{labels:["cseuckr","csksc56011987","euc-kr","iso-ir-149","korean","ks_c_5601-1987","ks_c_5601-1989","ksc5601","ksc_5601","windows-949"],name:"EUC-KR"}],heading:"Legacy multi-byte Korean encodings"},{encodings:[{labels:["csiso2022kr","hz-gb-2312","iso-2022-cn","iso-2022-cn-ext","iso-2022-kr"],name:"replacement"},{labels:["utf-16be"],name:"UTF-16BE"},{labels:["utf-16","utf-16le"],name:"UTF-16LE"},{labels:["x-user-defined"],name:"x-user-defined"}],heading:"Legacy miscellaneous encodings"}],p={};d.forEach((function(t){t.encodings.forEach((function(t){t.labels.forEach((function(e){p[e]=t}))}))}));var m,g,_={},y={};function v(t,e){return e&&e[t]||null}function b(t,e){var i=e.indexOf(t);return-1===i?null:i}function w(t){if(!("encoding-indexes"in e))throw Error("Indexes missing. Did you forget to include encoding-indexes.js first?");return e["encoding-indexes"][t]}var M="utf-8";function x(t,e){if(!(this instanceof x))throw TypeError("Called as a function. Did you forget 'new'?");t=void 0!==t?String(t):M,e=s(e),this._encoding=null,this._decoder=null,this._ignoreBOM=!1,this._BOMseen=!1,this._error_mode="replacement",this._do_not_flush=!1;var i=f(t);if(null===i||"replacement"===i.name)throw RangeError("Unknown encoding: "+t);if(!y[i.name])throw Error("Decoder not present. Did you forget to include encoding-indexes.js first?");var r=this;return r._encoding=i,Boolean(e.fatal)&&(r._error_mode="fatal"),Boolean(e.ignoreBOM)&&(r._ignoreBOM=!0),Object.defineProperty||(this.encoding=r._encoding.name.toLowerCase(),this.fatal="fatal"===r._error_mode,this.ignoreBOM=r._ignoreBOM),r}function k(t,i){if(!(this instanceof k))throw TypeError("Called as a function. Did you forget 'new'?");i=s(i),this._encoding=null,this._encoder=null,this._do_not_flush=!1,this._fatal=Boolean(i.fatal)?"fatal":"replacement";var r=this;if(Boolean(i.NONSTANDARD_allowLegacyEncoding)){var n=f(t=void 0!==t?String(t):M);if(null===n||"replacement"===n.name)throw RangeError("Unknown encoding: "+t);if(!_[n.name])throw Error("Encoder not present. Did you forget to include encoding-indexes.js first?");r._encoding=n}else r._encoding=f("utf-8"),void 0!==t&&"console"in e&&console.warn("TextEncoder constructor called with encoding label, which is ignored.");return Object.defineProperty||(this.encoding=r._encoding.name.toLowerCase()),r}function E(t){var e=t.fatal,r=0,s=0,n=0,a=128,h=191;this.handler=function(t,c){if(c===o&&0!==n)return n=0,l(e);if(c===o)return u;if(0===n){if(i(c,0,127))return c;if(i(c,194,223))n=1,r=31&c;else if(i(c,224,239))224===c&&(a=160),237===c&&(h=159),n=2,r=15&c;else{if(!i(c,240,244))return l(e);240===c&&(a=144),244===c&&(h=143),n=3,r=7&c}return null}if(!i(c,a,h))return r=n=s=0,a=128,h=191,t.prepend(c),l(e);if(a=128,h=191,r=r<<6|63&c,(s+=1)!==n)return null;var f=r;return r=n=s=0,f}}function A(t){t.fatal,this.handler=function(t,e){if(e===o)return u;if(a(e))return e;var r,s;i(e,128,2047)?(r=1,s=192):i(e,2048,65535)?(r=2,s=224):i(e,65536,1114111)&&(r=3,s=240);for(var n=[(e>>6*r)+s];r>0;){var h=e>>6*(r-1);n.push(128|63&h),r-=1}return n}}function S(t,e){var i=e.fatal;this.handler=function(e,r){if(r===o)return u;if(n(r))return r;var s=t[r-128];return null===s?l(i):s}}function C(t,e){e.fatal,this.handler=function(e,i){if(i===o)return u;if(a(i))return i;var r=b(i,t);return null===r&&c(i),r+128}}function I(t){var e=t.fatal,r=0,s=0,a=0;this.handler=function(t,h){if(h===o&&0===r&&0===s&&0===a)return u;var c;if(h!==o||0===r&&0===s&&0===a||(r=0,s=0,a=0,l(e)),0!==a){c=null,i(h,48,57)&&(c=function(t){if(t>39419&&t<189e3||t>1237575)return null;if(7457===t)return 59335;var e,i=0,r=0,s=w("gb18030-ranges");for(e=0;e>8,r=255&t;return e?[i,r]:[r,i]}function q(t,e){var r=e.fatal,s=null,n=null;this.handler=function(e,a){if(a===o&&(null!==s||null!==n))return l(r);if(a===o&&null===s&&null===n)return u;if(null===s)return s=a,null;var h;if(h=t?(s<<8)+a:(a<<8)+s,s=null,null!==n){var c=n;return n=null,i(h,56320,57343)?65536+1024*(c-55296)+(h-56320):(e.prepend(F(h,t)),l(r))}return i(h,55296,56319)?(n=h,null):i(h,56320,57343)?l(r):h}}function G(t,e){e.fatal,this.handler=function(e,r){if(r===o)return u;if(i(r,0,65535))return F(r,t);var s=F(55296+(r-65536>>10),t),n=F(56320+(r-65536&1023),t);return s.concat(n)}}function W(t){t.fatal,this.handler=function(t,e){return e===o?u:n(e)?e:63360+e-128}}function Z(t){t.fatal,this.handler=function(t,e){return e===o?u:a(e)?e:i(e,63360,63487)?e-63360+128:c(e)}}Object.defineProperty&&(Object.defineProperty(x.prototype,"encoding",{get:function(){return this._encoding.name.toLowerCase()}}),Object.defineProperty(x.prototype,"fatal",{get:function(){return"fatal"===this._error_mode}}),Object.defineProperty(x.prototype,"ignoreBOM",{get:function(){return this._ignoreBOM}})),x.prototype.decode=function(t,e){var i;i="object"==typeof t&&t instanceof ArrayBuffer?new Uint8Array(t):"object"==typeof t&&"buffer"in t&&t.buffer instanceof ArrayBuffer?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(0),e=s(e),this._do_not_flush||(this._decoder=y[this._encoding.name]({fatal:"fatal"===this._error_mode}),this._BOMseen=!1),this._do_not_flush=Boolean(e.stream);for(var r,n=new h(i),a=[];;){var l=n.read();if(l===o)break;if((r=this._decoder.handler(n,l))===u)break;null!==r&&(Array.isArray(r)?a.push.apply(a,r):a.push(r))}if(!this._do_not_flush){do{if((r=this._decoder.handler(n,n.read()))===u)break;null!==r&&(Array.isArray(r)?a.push.apply(a,r):a.push(r))}while(!n.endOfStream());this._decoder=null}return function(t){var e,i;return e=["UTF-8","UTF-16LE","UTF-16BE"],i=this._encoding.name,-1===e.indexOf(i)||this._ignoreBOM||this._BOMseen||(t.length>0&&65279===t[0]?(this._BOMseen=!0,t.shift()):t.length>0&&(this._BOMseen=!0)),function(t){for(var e="",i=0;i>10),56320+(1023&r)))}return e}(t)}.call(this,a)},Object.defineProperty&&Object.defineProperty(k.prototype,"encoding",{get:function(){return this._encoding.name.toLowerCase()}}),k.prototype.encode=function(t,e){t=void 0===t?"":String(t),e=s(e),this._do_not_flush||(this._encoder=_[this._encoding.name]({fatal:"fatal"===this._fatal})),this._do_not_flush=Boolean(e.stream);for(var i,r=new h(function(t){for(var e=String(t),i=e.length,r=0,s=[];r57343)s.push(n);else if(56320<=n&&n<=57343)s.push(65533);else if(55296<=n&&n<=56319)if(r===i-1)s.push(65533);else{var a=e.charCodeAt(r+1);if(56320<=a&&a<=57343){var o=1023&n,h=1023&a;s.push(65536+(o<<10)+h),r+=1}else s.push(65533)}r+=1}return s}(t)),n=[];;){var a=r.read();if(a===o)break;if((i=this._encoder.handler(r,a))===u)break;Array.isArray(i)?n.push.apply(n,i):n.push(i)}if(!this._do_not_flush){for(;(i=this._encoder.handler(r,r.read()))!==u;)Array.isArray(i)?n.push.apply(n,i):n.push(i);this._encoder=null}return new Uint8Array(n)},_["UTF-8"]=function(t){return new A(t)},y["UTF-8"]=function(t){return new E(t)},"encoding-indexes"in e&&d.forEach((function(t){"Legacy single-byte encodings"===t.heading&&t.encodings.forEach((function(t){var e=t.name,i=w(e.toLowerCase());y[e]=function(t){return new S(i,t)},_[e]=function(t){return new C(i,t)}}))})),y.GBK=function(t){return new I(t)},_.GBK=function(t){return new O(t,!0)},_.gb18030=function(t){return new O(t)},y.gb18030=function(t){return new I(t)},_.Big5=function(t){return new R(t)},y.Big5=function(t){return new P(t)},_["EUC-JP"]=function(t){return new z(t)},y["EUC-JP"]=function(t){return new N(t)},_["ISO-2022-JP"]=function(t){return new B(t)},y["ISO-2022-JP"]=function(t){return new T(t)},_.Shift_JIS=function(t){return new D(t)},y.Shift_JIS=function(t){return new L(t)},_["EUC-KR"]=function(t){return new j(t)},y["EUC-KR"]=function(t){return new U(t)},_["UTF-16BE"]=function(t){return new G(!0,t)},y["UTF-16BE"]=function(t){return new q(!0,t)},_["UTF-16LE"]=function(t){return new G(!1,t)},y["UTF-16LE"]=function(t){return new q(!1,t)},_["x-user-defined"]=function(t){return new Z(t)},y["x-user-defined"]=function(t){return new W(t)},e.TextEncoder||(e.TextEncoder=k),e.TextDecoder||(e.TextDecoder=x),t.exports&&(t.exports={TextEncoder:e.TextEncoder,TextDecoder:e.TextDecoder,EncodingIndexes:e["encoding-indexes"]})}(Kr||{})}({exports:{}});var hs=ji.isEncoding||function(t){switch(t&&t.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function us(t){switch(this.encoding=(t||"utf8").toLowerCase().replace(/[-_]/,""),function(t){if(t&&!hs(t))throw new Error("Unknown encoding: "+t)}(t),this.encoding){case"utf8":this.surrogateSize=3;break;case"ucs2":case"utf16le":this.surrogateSize=2,this.detectIncompleteChar=cs;break;case"base64":this.surrogateSize=3,this.detectIncompleteChar=fs;break;default:return void(this.write=ls)}this.charBuffer=new ji(6),this.charReceived=0,this.charLength=0}function ls(t){return t.toString(this.encoding)}function cs(t){this.charReceived=t.length%2,this.charLength=this.charReceived?2:0}function fs(t){this.charReceived=t.length%3,this.charLength=this.charReceived?3:0}us.prototype.write=function(t){for(var e="";this.charLength;){var i=t.length>=this.charLength-this.charReceived?this.charLength-this.charReceived:t.length;if(t.copy(this.charBuffer,this.charReceived,0,i),this.charReceived+=i,this.charReceived=55296&&s<=56319)){if(this.charReceived=this.charLength=0,0===t.length)return e;break}this.charLength+=this.surrogateSize,e=""}this.detectIncompleteChar(t);var r=t.length;this.charLength&&(t.copy(this.charBuffer,0,t.length-this.charReceived,r),r-=this.charReceived);var s;r=(e+=t.toString(this.encoding,0,r)).length-1;if((s=e.charCodeAt(r))>=55296&&s<=56319){var n=this.surrogateSize;return this.charLength+=n,this.charReceived+=n,this.charBuffer.copy(this.charBuffer,n,0,n),t.copy(this.charBuffer,0,0,n),e.substring(0,r)}return e},us.prototype.detectIncompleteChar=function(t){for(var e=t.length>=3?3:t.length;e>0;e--){var i=t[t.length-e];if(1==e&&i>>5==6){this.charLength=2;break}if(e<=2&&i>>4==14){this.charLength=3;break}if(e<=3&&i>>3==30){this.charLength=4;break}}this.charReceived=e},us.prototype.end=function(t){var e="";if(t&&t.length&&(e=this.write(t)),this.charReceived){var i=this.charReceived,r=this.charBuffer,s=this.encoding;e+=r.slice(0,i).toString(s)}return e};var ds=Jr(Object.freeze({__proto__:null,StringDecoder:us})).StringDecoder;function ps(t){var e=new ds;return(e.write(t)+e.end()).replace(/\0/g,"").trim()}var ms=function t(e,i){if(!e)return ps;try{new TextDecoder(e.trim())}catch(s){var r=gs.exec(e);return r&&!i?t("windows-"+r[1],!0):ps}return function(t){var i=new TextDecoder(e);return(i.decode(t,{stream:!0})+i.decode()).replace(/\0/g,"").trim()}},gs=/^(?:ANSI\s)?(\d+)$/m;var _s=ms;function ys(t,e,i,r,s){var n=s(t.slice(e,e+i));switch(r){case"N":case"F":case"O":return parseFloat(n,10);case"D":return new Date(n.slice(0,4),parseInt(n.slice(4,6),10)-1,n.slice(6,8));case"L":return"y"===n.toLowerCase()||"t"===n.toLowerCase();default:return n}}function vs(t,e,i,r){for(var s,n,a={},o=0,h=i.length;o{const e=new $r;await e.loadAsync(t);const i=e.file(/.+/),r={};return await Promise.all(i.map((async t=>{let e;e="shp"===t.name.slice(-3).toLowerCase()||"dbf"===t.name.slice(-3).toLowerCase()?await t.async("nodebuffer"):await t.async("text"),r[t.name]=e}))),r})(t),s=[];for(i in e=e||[],r)-1===i.indexOf("__MACOSX")&&(".shp"===i.slice(-4).toLowerCase()?(s.push(i.slice(0,-4)),r[i.slice(0,-3)+i.slice(-3).toLowerCase()]=r[i]):".prj"===i.slice(-4).toLowerCase()?r[i.slice(0,-3)+i.slice(-3).toLowerCase()]=xt(r[i]):".json"===i.slice(-5).toLowerCase()||e.indexOf(i.split(".").pop())>-1?s.push(i.slice(0,-3)+i.slice(-3).toLowerCase()):".dbf"!==i.slice(-4).toLowerCase()&&".cpg"!==i.slice(-4).toLowerCase()||(r[i.slice(0,-3)+i.slice(-3).toLowerCase()]=r[i]));if(!s.length)throw new Error("no layers founds");const n=s.map((function(t){let i,s;const n=t.lastIndexOf(".");return n>-1&&t.slice(n).indexOf("json")>-1?(i=JSON.parse(r[t]),i.fileName=t.slice(0,n)):e.indexOf(t.slice(n+1))>-1?(i=r[t],i.fileName=t):(r[t+".dbf"]&&(s=ws(r[t+".dbf"],r[t+".cpg"])),i=Es([os(r[t+".shp"],r[t+".prj"]),s]),i.fileName=t),i}));return 1===n.length?n[0]:n};const Ss=async t=>{const e=await Promise.all([is(t,"shp"),is(t,"prj")]);let i=!1;try{e[1]&&(i=xt(e[1]))}catch(t){i=!1}return os(e[0],i)},Cs=async t=>{const[e,i]=await Promise.all([is(t,"dbf"),is(t,"cpg")]);if(e)return ws(e,i)},Is=async function(t,e){if("string"!=typeof t)return As(t);if(((t,e)=>new Ms(t,globalThis?.document?.location).pathname.slice(-4).toLowerCase()===e)(t,".zip"))return async function(t,e){const i=await is(t);return As(i,e)}(t,e);const i=await Promise.all([Ss(t),Cs(t)]);return Es(i)};return Is.combine=Es,Is.parseDbf=function(t,e){return t=xs(t),ws(t,e)},Is.parseZip=As,Is.parseShp=function(t,e){if(t=xs(t),ji.isBuffer(e)&&(e=e.toString()),"string"==typeof e)try{e=xt(e)}catch(t){e=!1}return os(t,e)},Is})); +!function(t,s){"object"==typeof exports&&"undefined"!=typeof module?module.exports=s():"function"==typeof define&&define.amd?define(s):(t="undefined"!=typeof globalThis?globalThis:t||self).shp=s()}(this,(function(){"use strict";var t=1,s=2,i=3,a=4,h=5,e=6378137,r=6356752.314,n=.0066943799901413165,o=484813681109536e-20,l=Math.PI/2,u=.16666666666666666,c=.04722222222222222,f=.022156084656084655,M=1e-10,p=.017453292519943295,d=57.29577951308232,y=Math.PI/4,m=2*Math.PI,_=3.14159265359,g={greenwich:0,lisbon:-9.131906111111,paris:2.337229166667,bogota:-74.080916666667,madrid:-3.687938888889,rome:12.452333333333,bern:7.439583333333,jakarta:106.807719444444,ferro:-17.666666666667,brussels:4.367975,stockholm:18.058277777778,athens:23.7163375,oslo:10.722916666667},x={ft:{to_meter:.3048},"us-ft":{to_meter:1200/3937}},v=/[\s_\-\/\(\)]/g;function b(t,s){if(t[s])return t[s];for(var i,a=Object.keys(t),h=s.toLowerCase().replace(v,""),e=-1;++e=this.text.length)return;t=this.text[this.place++]}switch(this.state){case A:return this.neutral(t);case 2:return this.keyword(t);case 4:return this.quoted(t);case 5:return this.afterquote(t);case 3:return this.number(t);case-1:return}},I.prototype.afterquote=function(t){if('"'===t)return this.word+='"',void(this.state=4);if(E.test(t))return this.word=this.word.trim(),void this.afterItem(t);throw new Error("havn't handled \""+t+'" in afterquote yet, index '+this.place)},I.prototype.afterItem=function(t){return","===t?(null!==this.word&&this.currentObject.push(this.word),this.word=null,void(this.state=A)):"]"===t?(this.level--,null!==this.word&&(this.currentObject.push(this.word),this.word=null),this.state=A,this.currentObject=this.stack.pop(),void(this.currentObject||(this.state=-1))):void 0},I.prototype.number=function(t){if(!S.test(t)){if(E.test(t))return this.word=parseFloat(this.word),void this.afterItem(t);throw new Error("havn't handled \""+t+'" in number yet, index '+this.place)}this.word+=t},I.prototype.quoted=function(t){'"'!==t?this.word+=t:this.state=5},I.prototype.keyword=function(t){if(P.test(t))this.word+=t;else{if("["===t){var s=[];return s.push(this.word),this.level++,null===this.root?this.root=s:this.currentObject.push(s),this.stack.push(this.currentObject),this.currentObject=s,void(this.state=A)}if(!E.test(t))throw new Error("havn't handled \""+t+'" in keyword yet, index '+this.place);this.afterItem(t)}},I.prototype.neutral=function(t){if(N.test(t))return this.word=t,void(this.state=2);if('"'===t)return this.word="",void(this.state=4);if(S.test(t))return this.word=t,void(this.state=3);if(!E.test(t))throw new Error("havn't handled \""+t+'" in neutral yet, index '+this.place);this.afterItem(t)},I.prototype.output=function(){for(;this.place0?90:-90)):(t.lat0=L(t.lat1>0?90:-90),t.lat_ts=t.lat1)}(h),h}function j(t){var s=this;if(2===arguments.length){var i=arguments[1];"string"==typeof i?"+"===i.charAt(0)?j[t]=w(arguments[1]):j[t]=R(arguments[1]):j[t]=i}else if(1===arguments.length){if(Array.isArray(t))return t.map((function(t){Array.isArray(t)?j.apply(s,t):j(t)}));if("string"==typeof t){if(t in j)return j[t]}else"EPSG"in t?j["EPSG:"+t.EPSG]=t:"ESRI"in t?j["ESRI:"+t.ESRI]=t:"IAU2000"in t?j["IAU2000:"+t.IAU2000]=t:console.log(t);return}}!function(t){t("EPSG:4326","+title=WGS 84 (long/lat) +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees"),t("EPSG:4269","+title=NAD83 (long/lat) +proj=longlat +a=6378137.0 +b=6356752.31414036 +ellps=GRS80 +datum=NAD83 +units=degrees"),t("EPSG:3857","+title=WGS 84 / Pseudo-Mercator +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs"),t.WGS84=t["EPSG:4326"],t["EPSG:3785"]=t["EPSG:3857"],t.GOOGLE=t["EPSG:3857"],t["EPSG:900913"]=t["EPSG:3857"],t["EPSG:102113"]=t["EPSG:3857"]}(j);var G=["PROJECTEDCRS","PROJCRS","GEOGCS","GEOCCS","PROJCS","LOCAL_CS","GEODCRS","GEODETICCRS","GEODETICDATUM","ENGCRS","ENGINEERINGCRS"];var T=["3857","900913","3785","102113"];function z(t){if(!function(t){return"string"==typeof t}(t))return t;if(function(t){return t in j}(t))return j[t];if(function(t){return G.some((function(s){return t.indexOf(s)>-1}))}(t)){var s=R(t);if(function(t){var s=b(t,"authority");if(s){var i=b(s,"epsg");return i&&T.indexOf(i)>-1}}(s))return j["EPSG:3857"];var i=function(t){var s=b(t,"extension");if(s)return b(s,"proj4")}(s);return i?w(i):s}return function(t){return"+"===t[0]}(t)?w(t):void 0}function B(t,s){var i,a;if(t=t||{},!s)return t;for(a in s)void 0!==(i=s[a])&&(t[a]=i);return t}function D(t,s,i){var a=t*s;return i/Math.sqrt(1-a*a)}function F(t){return t<0?-1:1}function U(t){return Math.abs(t)<=_?t:t-F(t)*m}function Q(t,s,i){var a=t*i,h=.5*t;return a=Math.pow((1-a)/(1+a),h),Math.tan(.5*(l-s))/a}function W(t,s){for(var i,a,h=.5*t,e=l-2*Math.atan(s),r=0;r<=15;r++)if(i=t*Math.sin(e),e+=a=l-2*Math.atan(s*Math.pow((1-i)/(1+i),h))-e,Math.abs(a)<=1e-10)return e;return-9999}var Z={init:function(){var t=this.b/this.a;this.es=1-t*t,"x0"in this||(this.x0=0),"y0"in this||(this.y0=0),this.e=Math.sqrt(this.es),this.lat_ts?this.sphere?this.k0=Math.cos(this.lat_ts):this.k0=D(this.e,Math.sin(this.lat_ts),Math.cos(this.lat_ts)):this.k0||(this.k?this.k0=this.k:this.k0=1)},forward:function(t){var s,i,a=t.x,h=t.y;if(h*d>90&&h*d<-90&&a*d>180&&a*d<-180)return null;if(Math.abs(Math.abs(h)-l)<=M)return null;if(this.sphere)s=this.x0+this.a*this.k0*U(a-this.long0),i=this.y0+this.a*this.k0*Math.log(Math.tan(y+.5*h));else{var e=Math.sin(h),r=Q(this.e,h,e);s=this.x0+this.a*this.k0*U(a-this.long0),i=this.y0-this.a*this.k0*Math.log(r)}return t.x=s,t.y=i,t},inverse:function(t){var s,i,a=t.x-this.x0,h=t.y-this.y0;if(this.sphere)i=l-2*Math.atan(Math.exp(-h/(this.a*this.k0)));else{var e=Math.exp(-h/(this.a*this.k0));if(-9999===(i=W(this.e,e)))return null}return s=U(this.long0+a/(this.a*this.k0)),t.x=s,t.y=i,t},names:["Mercator","Popular Visualisation Pseudo Mercator","Mercator_1SP","Mercator_Auxiliary_Sphere","merc"]};function H(t){return t}var V=[Z,{init:function(){},forward:H,inverse:H,names:["longlat","identity"]}],X={},J=[];function K(t,s){var i=J.length;return t.names?(J[i]=t,t.names.forEach((function(t){X[t.toLowerCase()]=i})),this):(console.log(s),!0)}var $={start:function(){V.forEach(K)},add:K,get:function(t){if(!t)return!1;var s=t.toLowerCase();return void 0!==X[s]&&J[X[s]]?J[X[s]]:void 0}},Y={MERIT:{a:6378137,rf:298.257,ellipseName:"MERIT 1983"},SGS85:{a:6378136,rf:298.257,ellipseName:"Soviet Geodetic System 85"},GRS80:{a:6378137,rf:298.257222101,ellipseName:"GRS 1980(IUGG, 1980)"},IAU76:{a:6378140,rf:298.257,ellipseName:"IAU 1976"},airy:{a:6377563.396,b:6356256.91,ellipseName:"Airy 1830"},APL4:{a:6378137,rf:298.25,ellipseName:"Appl. Physics. 1965"},NWL9D:{a:6378145,rf:298.25,ellipseName:"Naval Weapons Lab., 1965"},mod_airy:{a:6377340.189,b:6356034.446,ellipseName:"Modified Airy"},andrae:{a:6377104.43,rf:300,ellipseName:"Andrae 1876 (Den., Iclnd.)"},aust_SA:{a:6378160,rf:298.25,ellipseName:"Australian Natl & S. Amer. 1969"},GRS67:{a:6378160,rf:298.247167427,ellipseName:"GRS 67(IUGG 1967)"},bessel:{a:6377397.155,rf:299.1528128,ellipseName:"Bessel 1841"},bess_nam:{a:6377483.865,rf:299.1528128,ellipseName:"Bessel 1841 (Namibia)"},clrk66:{a:6378206.4,b:6356583.8,ellipseName:"Clarke 1866"},clrk80:{a:6378249.145,rf:293.4663,ellipseName:"Clarke 1880 mod."},clrk80ign:{a:6378249.2,b:6356515,rf:293.4660213,ellipseName:"Clarke 1880 (IGN)"},clrk58:{a:6378293.645208759,rf:294.2606763692654,ellipseName:"Clarke 1858"},CPM:{a:6375738.7,rf:334.29,ellipseName:"Comm. des Poids et Mesures 1799"},delmbr:{a:6376428,rf:311.5,ellipseName:"Delambre 1810 (Belgium)"},engelis:{a:6378136.05,rf:298.2566,ellipseName:"Engelis 1985"},evrst30:{a:6377276.345,rf:300.8017,ellipseName:"Everest 1830"},evrst48:{a:6377304.063,rf:300.8017,ellipseName:"Everest 1948"},evrst56:{a:6377301.243,rf:300.8017,ellipseName:"Everest 1956"},evrst69:{a:6377295.664,rf:300.8017,ellipseName:"Everest 1969"},evrstSS:{a:6377298.556,rf:300.8017,ellipseName:"Everest (Sabah & Sarawak)"},fschr60:{a:6378166,rf:298.3,ellipseName:"Fischer (Mercury Datum) 1960"},fschr60m:{a:6378155,rf:298.3,ellipseName:"Fischer 1960"},fschr68:{a:6378150,rf:298.3,ellipseName:"Fischer 1968"},helmert:{a:6378200,rf:298.3,ellipseName:"Helmert 1906"},hough:{a:6378270,rf:297,ellipseName:"Hough"},intl:{a:6378388,rf:297,ellipseName:"International 1909 (Hayford)"},kaula:{a:6378163,rf:298.24,ellipseName:"Kaula 1961"},lerch:{a:6378139,rf:298.257,ellipseName:"Lerch 1979"},mprts:{a:6397300,rf:191,ellipseName:"Maupertius 1738"},new_intl:{a:6378157.5,b:6356772.2,ellipseName:"New International 1967"},plessis:{a:6376523,rf:6355863,ellipseName:"Plessis 1817 (France)"},krass:{a:6378245,rf:298.3,ellipseName:"Krassovsky, 1942"},SEasia:{a:6378155,b:6356773.3205,ellipseName:"Southeast Asia"},walbeck:{a:6376896,b:6355834.8467,ellipseName:"Walbeck"},WGS60:{a:6378165,rf:298.3,ellipseName:"WGS 60"},WGS66:{a:6378145,rf:298.25,ellipseName:"WGS 66"},WGS7:{a:6378135,rf:298.26,ellipseName:"WGS 72"}},tt=Y.WGS84={a:6378137,rf:298.257223563,ellipseName:"WGS 84"};Y.sphere={a:6370997,b:6370997,ellipseName:"Normal Sphere (r=6370997)"};var st={};st.wgs84={towgs84:"0,0,0",ellipse:"WGS84",datumName:"WGS84"},st.ch1903={towgs84:"674.374,15.056,405.346",ellipse:"bessel",datumName:"swiss"},st.ggrs87={towgs84:"-199.87,74.79,246.62",ellipse:"GRS80",datumName:"Greek_Geodetic_Reference_System_1987"},st.nad83={towgs84:"0,0,0",ellipse:"GRS80",datumName:"North_American_Datum_1983"},st.nad27={nadgrids:"@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat",ellipse:"clrk66",datumName:"North_American_Datum_1927"},st.potsdam={towgs84:"598.1,73.7,418.2,0.202,0.045,-2.455,6.7",ellipse:"bessel",datumName:"Potsdam Rauenberg 1950 DHDN"},st.carthage={towgs84:"-263.0,6.0,431.0",ellipse:"clark80",datumName:"Carthage 1934 Tunisia"},st.hermannskogel={towgs84:"577.326,90.129,463.919,5.137,1.474,5.297,2.4232",ellipse:"bessel",datumName:"Hermannskogel"},st.militargeographische_institut={towgs84:"577.326,90.129,463.919,5.137,1.474,5.297,2.4232",ellipse:"bessel",datumName:"Militar-Geographische Institut"},st.osni52={towgs84:"482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15",ellipse:"airy",datumName:"Irish National"},st.ire65={towgs84:"482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15",ellipse:"mod_airy",datumName:"Ireland 1965"},st.rassadiran={towgs84:"-133.63,-157.5,-158.62",ellipse:"intl",datumName:"Rassadiran"},st.nzgd49={towgs84:"59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993",ellipse:"intl",datumName:"New Zealand Geodetic Datum 1949"},st.osgb36={towgs84:"446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894",ellipse:"airy",datumName:"Airy 1830"},st.s_jtsk={towgs84:"589,76,480",ellipse:"bessel",datumName:"S-JTSK (Ferro)"},st.beduaram={towgs84:"-106,-87,188",ellipse:"clrk80",datumName:"Beduaram"},st.gunung_segara={towgs84:"-403,684,41",ellipse:"bessel",datumName:"Gunung Segara Jakarta"},st.rnb72={towgs84:"106.869,-52.2978,103.724,-0.33657,0.456955,-1.84218,1",ellipse:"intl",datumName:"Reseau National Belge 1972"};var it={};function at(t){if(0===t.length)return null;var s="@"===t[0];return s&&(t=t.slice(1)),"null"===t?{name:"null",mandatory:!s,grid:null,isNull:!0}:{name:t,mandatory:!s,grid:it[t]||null,isNull:!1}}function ht(t){return t/3600*Math.PI/180}function et(t,s,i){return String.fromCharCode.apply(null,new Uint8Array(t.buffer.slice(s,i)))}function rt(t){return t.map((function(t){return[ht(t.longitudeShift),ht(t.latitudeShift)]}))}function nt(t,s,i){return{name:et(t,s+8,s+16).trim(),parent:et(t,s+24,s+24+8).trim(),lowerLatitude:t.getFloat64(s+72,i),upperLatitude:t.getFloat64(s+88,i),lowerLongitude:t.getFloat64(s+104,i),upperLongitude:t.getFloat64(s+120,i),latitudeInterval:t.getFloat64(s+136,i),longitudeInterval:t.getFloat64(s+152,i),gridNodeCount:t.getInt32(s+168,i)}}function ot(t,s,i,a){for(var h=s+176,e=[],r=0;r3&&(0===M.datum_params[3]&&0===M.datum_params[4]&&0===M.datum_params[5]&&0===M.datum_params[6]||(M.datum_type=s,M.datum_params[3]*=o,M.datum_params[4]*=o,M.datum_params[5]*=o,M.datum_params[6]=M.datum_params[6]/1e6+1))),f&&(M.datum_type=i,M.grids=f),M.a=n,M.b=l,M.es=u,M.ep2=c,M}(n.datumCode,n.datum_params,w.a,w.b,A.es,A.ep2,C);B(this,n),B(this,l),this.a=w.a,this.b=w.b,this.rf=w.rf,this.sphere=w.sphere,this.es=A.es,this.e=A.e,this.ep2=A.ep2,this.datum=N,this.init(),r(null,this)}else r(e)}else r(e)}function ut(t,s,i){var a,h,e,r,n=t.x,o=t.y,u=t.z?t.z:0;if(o<-l&&o>-1.001*l)o=-l;else if(o>l&&o<1.001*l)o=l;else{if(o<-l)return{x:-1/0,y:-1/0,z:t.z};if(o>l)return{x:1/0,y:1/0,z:t.z}}return n>Math.PI&&(n-=2*Math.PI),h=Math.sin(o),r=Math.cos(o),e=h*h,{x:((a=i/Math.sqrt(1-s*e))+u)*r*Math.cos(n),y:(a+u)*r*Math.sin(n),z:(a*(1-s)+u)*h}}function ct(t,s,i,a){var h,e,r,n,o,u,c,f,M,p,d,y,m,_,g,x=1e-12,v=t.x,b=t.y,w=t.z?t.z:0;if(h=Math.sqrt(v*v+b*b),e=Math.sqrt(v*v+b*b+w*w),h/i1e-24&&m<30);return{x:_,y:Math.atan(d/Math.abs(p)),z:g}}function ft(i){return i===t||i===s}function Mt(a,o,l){if(function(i,a){return i.datum_type===a.datum_type&&!(i.a!==a.a||Math.abs(i.es-a.es)>5e-11)&&(i.datum_type===t?i.datum_params[0]===a.datum_params[0]&&i.datum_params[1]===a.datum_params[1]&&i.datum_params[2]===a.datum_params[2]:i.datum_type!==s||i.datum_params[0]===a.datum_params[0]&&i.datum_params[1]===a.datum_params[1]&&i.datum_params[2]===a.datum_params[2]&&i.datum_params[3]===a.datum_params[3]&&i.datum_params[4]===a.datum_params[4]&&i.datum_params[5]===a.datum_params[5]&&i.datum_params[6]===a.datum_params[6])}(a,o))return l;if(a.datum_type===h||o.datum_type===h)return l;var u=a.a,c=a.es;if(a.datum_type===i){if(0!==pt(a,!1,l))return;u=e,c=n}var f=o.a,M=o.b,p=o.es;if(o.datum_type===i&&(f=e,M=r,p=n),c===p&&u===f&&!ft(a.datum_type)&&!ft(o.datum_type))return l;if((l=ut(l,c,u),ft(a.datum_type)&&(l=function(i,a,h){if(a===t)return{x:i.x+h[0],y:i.y+h[1],z:i.z+h[2]};if(a===s){var e=h[0],r=h[1],n=h[2],o=h[3],l=h[4],u=h[5],c=h[6];return{x:c*(i.x-u*i.y+l*i.z)+e,y:c*(u*i.x+i.y-o*i.z)+r,z:c*(-l*i.x+o*i.y+i.z)+n}}}(l,a.datum_type,a.datum_params)),ft(o.datum_type)&&(l=function(i,a,h){if(a===t)return{x:i.x-h[0],y:i.y-h[1],z:i.z-h[2]};if(a===s){var e=h[0],r=h[1],n=h[2],o=h[3],l=h[4],u=h[5],c=h[6],f=(i.x-e)/c,M=(i.y-r)/c,p=(i.z-n)/c;return{x:f+u*M-l*p,y:-u*f+M+o*p,z:l*f-o*M+p}}}(l,o.datum_type,o.datum_params)),l=ct(l,p,f,M),o.datum_type===i)&&0!==pt(o,!0,l))return;return l}function pt(t,s,i){if(null===t.grids||0===t.grids.length)return console.log("Grid shift grids not found"),-1;var a={x:-i.x,y:i.y},h={x:Number.NaN,y:Number.NaN},e=[];t:for(var r=0;ra.y||M>a.x||m1e-12&&Math.abs(r.y)>1e-12);if(o<0)return console.log("Inverse grid shift iterator failed to converge."),a;a.x=U(e.x+i.ll[0]),a.y=e.y+i.ll[1]}else isNaN(e.x)||(a.x=t.x+e.x,a.y=t.y+e.y);return a}function yt(t,s){var i,a={x:t.x/s.del[0],y:t.y/s.del[1]},h=Math.floor(a.x),e=Math.floor(a.y),r=a.x-1*h,n=a.y-1*e,o={x:Number.NaN,y:Number.NaN};if(h<0||h>=s.lim[0])return o;if(e<0||e>=s.lim[1])return o;i=e*s.lim[0]+h;var l=s.cvs[i][0],u=s.cvs[i][1];i++;var c=s.cvs[i][0],f=s.cvs[i][1];i+=s.lim[0];var M=s.cvs[i][0],p=s.cvs[i][1];i--;var d=s.cvs[i][0],y=s.cvs[i][1],m=r*n,_=r*(1-n),g=(1-r)*(1-n),x=(1-r)*n;return o.x=g*l+_*c+x*d+m*M,o.y=g*u+_*f+x*y+m*p,o}function mt(t,s,i){var a,h,e,r=i.x,n=i.y,o=i.z||0,l={};for(e=0;e<3;e++)if(!s||2!==e||void 0!==i.z)switch(0===e?(a=r,h=-1!=="ew".indexOf(t.axis[e])?"x":"y"):1===e?(a=n,h=-1!=="ns".indexOf(t.axis[e])?"y":"x"):(a=o,h="z"),t.axis[e]){case"e":case"n":l[h]=a;break;case"w":case"s":l[h]=-a;break;case"u":void 0!==i[h]&&(l.z=a);break;case"d":void 0!==i[h]&&(l.z=-a);break;default:return null}return l}function _t(t){var s={x:t[0],y:t[1]};return t.length>2&&(s.z=t[2]),t.length>3&&(s.m=t[3]),s}function gt(t){if("function"==typeof Number.isFinite){if(Number.isFinite(t))return;throw new TypeError("coordinates must be finite numbers")}if("number"!=typeof t||t!=t||!isFinite(t))throw new TypeError("coordinates must be finite numbers")}function xt(a,h,e,r){var n,o=void 0!==(e=Array.isArray(e)?_t(e):{x:e.x,y:e.y,z:e.z,m:e.m}).z;if(function(t){gt(t.x),gt(t.y)}(e),a.datum&&h.datum&&function(a,h){return(a.datum.datum_type===t||a.datum.datum_type===s||a.datum.datum_type===i)&&"WGS84"!==h.datumCode||(h.datum.datum_type===t||h.datum.datum_type===s||h.datum.datum_type===i)&&"WGS84"!==a.datumCode}(a,h)&&(e=xt(a,n=new lt("WGS84"),e,r),a=n),r&&"enu"!==a.axis&&(e=mt(a,!1,e)),"longlat"===a.projName)e={x:e.x*p,y:e.y*p,z:e.z||0};else if(a.to_meter&&(e={x:e.x*a.to_meter,y:e.y*a.to_meter,z:e.z||0}),!(e=a.inverse(e)))return;if(a.from_greenwich&&(e.x+=a.from_greenwich),e=Mt(a.datum,h.datum,e))return h.from_greenwich&&(e={x:e.x-h.from_greenwich,y:e.y,z:e.z||0}),"longlat"===h.projName?e={x:e.x*d,y:e.y*d,z:e.z||0}:(e=h.forward(e),h.to_meter&&(e={x:e.x/h.to_meter,y:e.y/h.to_meter,z:e.z||0})),r&&"enu"!==h.axis?mt(h,!0,e):(e&&!o&&delete e.z,e)}lt.projections=$,lt.projections.start();var vt=lt("WGS84");function bt(t,s,i,a){var h,e,r;return Array.isArray(i)?(h=xt(t,s,i,a)||{x:NaN,y:NaN},i.length>2?void 0!==t.name&&"geocent"===t.name||void 0!==s.name&&"geocent"===s.name?"number"==typeof h.z?[h.x,h.y,h.z].concat(i.splice(3)):[h.x,h.y,i[2]].concat(i.splice(3)):[h.x,h.y].concat(i.splice(2)):[h.x,h.y]):(e=xt(t,s,i,a),2===(r=Object.keys(i)).length||r.forEach((function(a){if(void 0!==t.name&&"geocent"===t.name||void 0!==s.name&&"geocent"===s.name){if("x"===a||"y"===a||"z"===a)return}else if("x"===a||"y"===a)return;e[a]=i[a]})),e)}function wt(t){return t instanceof lt?t:t.oProj?t.oProj:lt(t)}function At(t,s,i){t=wt(t);var a,h=!1;return void 0===s?(s=t,t=vt,h=!0):(void 0!==s.x||Array.isArray(s))&&(i=s,s=t,t=vt,h=!0),s=wt(s),i?bt(t,s,i):(a={forward:function(i,a){return bt(t,s,i,a)},inverse:function(i,a){return bt(s,t,i,a)}},h&&(a.oProj=s),a)}var Ct=6,Nt="AJSAJS",Pt="AFAFAF",Et=65,St=73,It=79,kt=86,Ot=90,qt={forward:Lt,inverse:function(t){var s=Tt(Dt(t.toUpperCase()));if(s.lat&&s.lon)return[s.lon,s.lat,s.lon,s.lat];return[s.left,s.bottom,s.right,s.top]},toPoint:Rt};function Lt(t,s){return s=s||5,function(t,s){var i="00000"+t.easting,a="00000"+t.northing;return t.zoneNumber+t.zoneLetter+(M=t.easting,p=t.northing,d=t.zoneNumber,y=Bt(d),m=Math.floor(M/1e5),_=Math.floor(p/1e5)%20,h=m,e=_,r=y,n=r-1,o=Nt.charCodeAt(n),l=Pt.charCodeAt(n),u=o+h-1,c=l+e,f=!1,u>Ot&&(u=u-Ot+Et-1,f=!0),(u===St||oSt||(u>St||oIt||(u>It||oOt&&(u=u-Ot+Et-1),c>kt?(c=c-kt+Et-1,f=!0):f=!1,(c===St||lSt||(c>St||lIt||(c>It||lkt&&(c=c-kt+Et-1),String.fromCharCode(u)+String.fromCharCode(c))+i.substr(i.length-5,s)+a.substr(a.length-5,s);var h,e,r,n,o,l,u,c,f;var M,p,d,y,m,_}(function(t){var s,i,a,h,e,r,n,o,l=t.lat,u=t.lon,c=6378137,f=.00669438,M=.9996,p=jt(l),d=jt(u);o=Math.floor((u+180)/6)+1,180===u&&(o=60);l>=56&&l<64&&u>=3&&u<12&&(o=32);l>=72&&l<84&&(u>=0&&u<9?o=31:u>=9&&u<21?o=33:u>=21&&u<33?o=35:u>=33&&u<42&&(o=37));n=jt(6*(o-1)-180+3),s=f/(1-f),i=c/Math.sqrt(1-f*Math.sin(p)*Math.sin(p)),a=Math.tan(p)*Math.tan(p),h=s*Math.cos(p)*Math.cos(p),e=Math.cos(p)*(d-n),r=c*((1-f/4-3*f*f/64-5*f*f*f/256)*p-(3*f/8+3*f*f/32+45*f*f*f/1024)*Math.sin(2*p)+(15*f*f/256+45*f*f*f/1024)*Math.sin(4*p)-35*f*f*f/3072*Math.sin(6*p));var y=M*i*(e+(1-a+h)*e*e*e/6+(5-18*a+a*a+72*h-58*s)*e*e*e*e*e/120)+5e5,m=M*(r+i*Math.tan(p)*(e*e/2+(5-a+9*h+4*h*h)*e*e*e*e/24+(61-58*a+a*a+600*h-330*s)*e*e*e*e*e*e/720));l<0&&(m+=1e7);return{northing:Math.round(m),easting:Math.round(y),zoneNumber:o,zoneLetter:zt(l)}}({lat:t[1],lon:t[0]}),s)}function Rt(t){var s=Tt(Dt(t.toUpperCase()));return s.lat&&s.lon?[s.lon,s.lat]:[(s.left+s.right)/2,(s.top+s.bottom)/2]}function jt(t){return t*(Math.PI/180)}function Gt(t){return t/Math.PI*180}function Tt(t){var s=t.northing,i=t.easting,a=t.zoneLetter,h=t.zoneNumber;if(h<0||h>60)return null;var e,r,n,o,l,u,c,f,M,p=.9996,d=6378137,y=.00669438,m=(1-Math.sqrt(.99330562))/(1+Math.sqrt(.99330562)),_=i-5e5,g=s;a<"N"&&(g-=1e7),c=6*(h-1)-180+3,e=.006739496752268451,M=(f=g/p/6367449.145945056)+(3*m/2-27*m*m*m/32)*Math.sin(2*f)+(21*m*m/16-55*m*m*m*m/32)*Math.sin(4*f)+151*m*m*m/96*Math.sin(6*f),r=d/Math.sqrt(1-y*Math.sin(M)*Math.sin(M)),n=Math.tan(M)*Math.tan(M),o=e*Math.cos(M)*Math.cos(M),l=.99330562*d/Math.pow(1-y*Math.sin(M)*Math.sin(M),1.5),u=_/(r*p);var x=M-r*Math.tan(M)/l*(u*u/2-(5+3*n+10*o-4*o*o-9*e)*u*u*u*u/24+(61+90*n+298*o+45*n*n-1.6983531815716497-3*o*o)*u*u*u*u*u*u/720);x=Gt(x);var v,b=(u-(1+2*n+o)*u*u*u/6+(5-2*o+28*n-3*o*o+8*e+24*n*n)*u*u*u*u*u/120)/Math.cos(M);if(b=c+Gt(b),t.accuracy){var w=Tt({northing:t.northing+t.accuracy,easting:t.easting+t.accuracy,zoneLetter:t.zoneLetter,zoneNumber:t.zoneNumber});v={top:w.lat,right:w.lon,bottom:x,left:b}}else v={lat:x,lon:b};return v}function zt(t){var s="Z";return 84>=t&&t>=72?s="X":72>t&&t>=64?s="W":64>t&&t>=56?s="V":56>t&&t>=48?s="U":48>t&&t>=40?s="T":40>t&&t>=32?s="S":32>t&&t>=24?s="R":24>t&&t>=16?s="Q":16>t&&t>=8?s="P":8>t&&t>=0?s="N":0>t&&t>=-8?s="M":-8>t&&t>=-16?s="L":-16>t&&t>=-24?s="K":-24>t&&t>=-32?s="J":-32>t&&t>=-40?s="H":-40>t&&t>=-48?s="G":-48>t&&t>=-56?s="F":-56>t&&t>=-64?s="E":-64>t&&t>=-72?s="D":-72>t&&t>=-80&&(s="C"),s}function Bt(t){var s=t%Ct;return 0===s&&(s=Ct),s}function Dt(t){if(t&&0===t.length)throw"MGRSPoint coverting from nothing";for(var s,i=t.length,a=null,h="",e=0;!/[A-Z]/.test(s=t.charAt(e));){if(e>=2)throw"MGRSPoint bad conversion from: "+t;h+=s,e++}var r=parseInt(h,10);if(0===e||e+3>i)throw"MGRSPoint bad conversion from: "+t;var n=t.charAt(e++);if(n<="A"||"B"===n||"Y"===n||n>="Z"||"I"===n||"O"===n)throw"MGRSPoint zone letter "+n+" not handled: "+t;a=t.substring(e,e+=2);for(var o=Bt(r),l=function(t,s){var i=Nt.charCodeAt(s-1),a=1e5,h=!1;for(;i!==t.charCodeAt(0);){if(++i===St&&i++,i===It&&i++,i>Ot){if(h)throw"Bad character: "+t;i=Et,h=!0}a+=1e5}return a}(a.charAt(0),o),u=function(t,s){if(t>"V")throw"MGRSPoint given invalid Northing "+t;var i=Pt.charCodeAt(s-1),a=0,h=!1;for(;i!==t.charCodeAt(0);){if(++i===St&&i++,i===It&&i++,i>kt){if(h)throw"Bad character: "+t;i=Et,h=!0}a+=1e5}return a}(a.charAt(1),o);u0&&(f=1e5/Math.pow(10,d),M=t.substring(e,e+d),y=parseFloat(M)*f,p=t.substring(e+d),m=parseFloat(p)*f),{easting:y+l,northing:m+u,zoneLetter:n,zoneNumber:r,accuracy:f}}function Ft(t){var s;switch(t){case"C":s=11e5;break;case"D":s=2e6;break;case"E":s=28e5;break;case"F":s=37e5;break;case"G":s=46e5;break;case"H":s=55e5;break;case"J":s=64e5;break;case"K":s=73e5;break;case"L":s=82e5;break;case"M":s=91e5;break;case"N":s=0;break;case"P":s=8e5;break;case"Q":s=17e5;break;case"R":s=26e5;break;case"S":s=35e5;break;case"T":s=44e5;break;case"U":s=53e5;break;case"V":s=62e5;break;case"W":s=7e6;break;case"X":s=79e5;break;default:s=-1}if(s>=0)return s;throw"Invalid zone letter: "+t}function Ut(t,s,i){if(!(this instanceof Ut))return new Ut(t,s,i);if(Array.isArray(t))this.x=t[0],this.y=t[1],this.z=t[2]||0;else if("object"==typeof t)this.x=t.x,this.y=t.y,this.z=t.z||0;else if("string"==typeof t&&void 0===s){var a=t.split(",");this.x=parseFloat(a[0],10),this.y=parseFloat(a[1],10),this.z=parseFloat(a[2],10)||0}else this.x=t,this.y=s,this.z=i||0;console.warn("proj4.Point will be removed in version 3, use proj4.toPoint")}Ut.fromMGRS=function(t){return new Ut(Rt(t))},Ut.prototype.toMGRS=function(t){return Lt([this.x,this.y],t)};var Qt=1,Wt=.25,Zt=.046875,Ht=.01953125,Vt=.01068115234375,Xt=.75,Jt=.46875,Kt=.013020833333333334,$t=.007120768229166667,Yt=.3645833333333333,ts=.005696614583333333,ss=.3076171875;function is(t){var s=[];s[0]=Qt-t*(Wt+t*(Zt+t*(Ht+t*Vt))),s[1]=t*(Xt-t*(Zt+t*(Ht+t*Vt)));var i=t*t;return s[2]=i*(Jt-t*(Kt+t*$t)),i*=t,s[3]=i*(Yt-t*ts),s[4]=i*t*ss,s}function as(t,s,i,a){return i*=s,s*=s,a[0]*t-i*(a[1]+s*(a[2]+s*(a[3]+s*a[4])))}var hs=20;function es(t,s,i){for(var a=1/(1-s),h=t,e=hs;e;--e){var r=Math.sin(h),n=1-s*r*r;if(h-=n=(as(h,r,Math.cos(h),i)-t)*(n*Math.sqrt(n))*a,Math.abs(n)M?Math.tan(e):0,d=Math.pow(p,2),y=Math.pow(d,2);s=1-this.es*Math.pow(n,2),l/=Math.sqrt(s);var m=as(e,n,o,this.en);i=this.a*(this.k0*l*(1+u/6*(1-d+c+u/20*(5-18*d+y+14*c-58*d*c+u/42*(61+179*y-y*d-479*d)))))+this.x0,a=this.a*(this.k0*(m-this.ml0+n*r*l/2*(1+u/12*(5-d+9*c+4*f+u/30*(61+y-58*d+270*c-330*d*c+u/56*(1385+543*y-y*d-3111*d))))))+this.y0}else{var _=o*Math.sin(r);if(Math.abs(Math.abs(_)-1)=1){if(_-1>M)return 93;a=0}else a=Math.acos(a);e<0&&(a=-a),a=this.a*this.k0*(a-this.lat0)+this.y0}return t.x=i,t.y=a,t},inverse:function(t){var s,i,a,h,e=(t.x-this.x0)*(1/this.a),r=(t.y-this.y0)*(1/this.a);if(this.es)if(i=es(s=this.ml0+r/this.k0,this.es,this.en),Math.abs(i)M?Math.tan(i):0,c=this.ep2*Math.pow(o,2),f=Math.pow(c,2),p=Math.pow(u,2),d=Math.pow(p,2);s=1-this.es*Math.pow(n,2);var y=e*Math.sqrt(s)/this.k0,m=Math.pow(y,2);a=i-(s*=u)*m/(1-this.es)*.5*(1-m/12*(5+3*p-9*c*p+c-4*f-m/30*(61+90*p-252*c*p+45*d+46*c-m/56*(1385+3633*p+4095*d+1574*d*p)))),h=U(this.long0+y*(1-m/6*(1+2*p+c-m/20*(5+28*p+24*d+8*c*p+6*c-m/42*(61+662*p+1320*d+720*d*p))))/o)}else a=l*F(r),h=0;else{var _=Math.exp(e/this.k0),g=.5*(_-1/_),x=this.lat0+r/this.k0,v=Math.cos(x);s=Math.sqrt((1-Math.pow(v,2))/(1+Math.pow(g,2))),a=Math.asin(s),r<0&&(a=-a),h=0===g&&0===v?0:U(Math.atan2(g,v)+this.long0)}return t.x=h,t.y=a,t},names:["Fast_Transverse_Mercator","Fast Transverse Mercator"]};function ns(t){var s=Math.exp(t);return s=(s-1/s)/2}function os(t,s){t=Math.abs(t),s=Math.abs(s);var i=Math.max(t,s),a=Math.min(t,s)/(i||1);return i*Math.sqrt(1+Math.pow(a,2))}function ls(t){var s=Math.abs(t);return s=function(t){var s=1+t,i=s-1;return 0===i?t:t*Math.log(s)/i}(s*(1+s/(os(1,s)+1))),t<0?-s:s}function us(t,s){for(var i,a=2*Math.cos(2*s),h=t.length-1,e=t[h],r=0;--h>=0;)i=a*e-r+t[h],r=e,e=i;return s+i*Math.sin(2*s)}function cs(t,s,i){for(var a,h,e=Math.sin(s),r=Math.cos(s),n=ns(i),o=function(t){var s=Math.exp(t);return(s+1/s)/2}(i),l=2*r*o,u=-2*e*n,c=t.length-1,f=t[c],M=0,p=0,d=0;--c>=0;)a=p,h=M,f=l*(p=f)-a-u*(M=d)+t[c],d=u*p-h+l*M;return[(l=e*o)*f-(u=r*n)*d,l*d+u*f]}var fs={init:function(){if(!this.approx&&(isNaN(this.es)||this.es<=0))throw new Error('Incorrect elliptical usage. Try using the +approx option in the proj string, or PROJECTION["Fast_Transverse_Mercator"] in the WKT.');this.approx&&(rs.init.apply(this),this.forward=rs.forward,this.inverse=rs.inverse),this.x0=void 0!==this.x0?this.x0:0,this.y0=void 0!==this.y0?this.y0:0,this.long0=void 0!==this.long0?this.long0:0,this.lat0=void 0!==this.lat0?this.lat0:0,this.cgb=[],this.cbg=[],this.utg=[],this.gtu=[];var t=this.es/(1+Math.sqrt(1-this.es)),s=t/(2-t),i=s;this.cgb[0]=s*(2+s*(-2/3+s*(s*(116/45+s*(26/45+s*(-2854/675)))-2))),this.cbg[0]=s*(s*(2/3+s*(4/3+s*(-82/45+s*(32/45+s*(4642/4725)))))-2),i*=s,this.cgb[1]=i*(7/3+s*(s*(-227/45+s*(2704/315+s*(2323/945)))-1.6)),this.cbg[1]=i*(5/3+s*(-16/15+s*(-13/9+s*(904/315+s*(-1522/945))))),i*=s,this.cgb[2]=i*(56/15+s*(-136/35+s*(-1262/105+s*(73814/2835)))),this.cbg[2]=i*(-26/15+s*(34/21+s*(1.6+s*(-12686/2835)))),i*=s,this.cgb[3]=i*(4279/630+s*(-332/35+s*(-399572/14175))),this.cbg[3]=i*(1237/630+s*(s*(-24832/14175)-2.4)),i*=s,this.cgb[4]=i*(4174/315+s*(-144838/6237)),this.cbg[4]=i*(-734/315+s*(109598/31185)),i*=s,this.cgb[5]=i*(601676/22275),this.cbg[5]=i*(444337/155925),i=Math.pow(s,2),this.Qn=this.k0/(1+s)*(1+i*(1/4+i*(1/64+i/256))),this.utg[0]=s*(s*(2/3+s*(-37/96+s*(1/360+s*(81/512+s*(-96199/604800)))))-.5),this.gtu[0]=s*(.5+s*(-2/3+s*(5/16+s*(41/180+s*(-127/288+s*(7891/37800)))))),this.utg[1]=i*(-1/48+s*(-1/15+s*(437/1440+s*(-46/105+s*(1118711/3870720))))),this.gtu[1]=i*(13/48+s*(s*(557/1440+s*(281/630+s*(-1983433/1935360)))-.6)),i*=s,this.utg[2]=i*(-17/480+s*(37/840+s*(209/4480+s*(-5569/90720)))),this.gtu[2]=i*(61/240+s*(-103/140+s*(15061/26880+s*(167603/181440)))),i*=s,this.utg[3]=i*(-4397/161280+s*(11/504+s*(830251/7257600))),this.gtu[3]=i*(49561/161280+s*(-179/168+s*(6601661/7257600))),i*=s,this.utg[4]=i*(-4583/161280+s*(108847/3991680)),this.gtu[4]=i*(34729/80640+s*(-3418889/1995840)),i*=s,this.utg[5]=i*(-20648693/638668800),this.gtu[5]=.6650675310896665*i;var a=us(this.cbg,this.lat0);this.Zb=-this.Qn*(a+function(t,s){for(var i,a=2*Math.cos(s),h=t.length-1,e=t[h],r=0;--h>=0;)i=a*e-r+t[h],r=e,e=i;return Math.sin(s)*i}(this.gtu,2*a))},forward:function(t){var s=U(t.x-this.long0),i=t.y;i=us(this.cbg,i);var a=Math.sin(i),h=Math.cos(i),e=Math.sin(s),r=Math.cos(s);i=Math.atan2(a,r*h),s=Math.atan2(e*h,os(a,h*r)),s=ls(Math.tan(s));var n,o,l=cs(this.gtu,2*i,2*s);return i+=l[0],s+=l[1],Math.abs(s)<=2.623395162778?(n=this.a*(this.Qn*s)+this.x0,o=this.a*(this.Qn*i+this.Zb)+this.y0):(n=1/0,o=1/0),t.x=n,t.y=o,t},inverse:function(t){var s,i,a=(t.x-this.x0)*(1/this.a),h=(t.y-this.y0)*(1/this.a);if(h=(h-this.Zb)/this.Qn,a/=this.Qn,Math.abs(a)<=2.623395162778){var e=cs(this.utg,2*h,2*a);h+=e[0],a+=e[1],a=Math.atan(ns(a));var r=Math.sin(h),n=Math.cos(h),o=Math.sin(a),l=Math.cos(a);h=Math.atan2(r*l,os(o,l*n)),s=U((a=Math.atan2(o,l*n))+this.long0),i=us(this.cgb,h)}else s=1/0,i=1/0;return t.x=s,t.y=i,t},names:["Extended_Transverse_Mercator","Extended Transverse Mercator","etmerc","Transverse_Mercator","Transverse Mercator","Gauss Kruger","Gauss_Kruger","tmerc"]};var Ms={init:function(){var t=function(t,s){if(void 0===t){if((t=Math.floor(30*(U(s)+Math.PI)/Math.PI)+1)<0)return 0;if(t>60)return 60}return t}(this.zone,this.long0);if(void 0===t)throw new Error("unknown utm zone");this.lat0=0,this.long0=(6*Math.abs(t)-183)*p,this.x0=5e5,this.y0=this.utmSouth?1e7:0,this.k0=.9996,fs.init.apply(this),this.forward=fs.forward,this.inverse=fs.inverse},names:["Universal Transverse Mercator System","utm"],dependsOn:"etmerc"};function ps(t,s){return Math.pow((1-t)/(1+t),s)}var ds={init:function(){var t=Math.sin(this.lat0),s=Math.cos(this.lat0);s*=s,this.rc=Math.sqrt(1-this.es)/(1-this.es*t*t),this.C=Math.sqrt(1+this.es*s*s/(1-this.es)),this.phic0=Math.asin(t/this.C),this.ratexp=.5*this.C*this.e,this.K=Math.tan(.5*this.phic0+y)/(Math.pow(Math.tan(.5*this.lat0+y),this.C)*ps(this.e*t,this.ratexp))},forward:function(t){var s=t.x,i=t.y;return t.y=2*Math.atan(this.K*Math.pow(Math.tan(.5*i+y),this.C)*ps(this.e*Math.sin(i),this.ratexp))-l,t.x=this.C*s,t},inverse:function(t){for(var s=t.x/this.C,i=t.y,a=Math.pow(Math.tan(.5*i+y)/this.K,1/this.C),h=20;h>0&&(i=2*Math.atan(a*ps(this.e*Math.sin(t.y),-.5*this.e))-l,!(Math.abs(i-t.y)<1e-14));--h)t.y=i;return h?(t.x=s,t.y=i,t):null},names:["gauss"]};var ys={init:function(){ds.init.apply(this),this.rc&&(this.sinc0=Math.sin(this.phic0),this.cosc0=Math.cos(this.phic0),this.R2=2*this.rc,this.title||(this.title="Oblique Stereographic Alternative"))},forward:function(t){var s,i,a,h;return t.x=U(t.x-this.long0),ds.forward.apply(this,[t]),s=Math.sin(t.y),i=Math.cos(t.y),a=Math.cos(t.x),h=this.k0*this.R2/(1+this.sinc0*s+this.cosc0*i*a),t.x=h*i*Math.sin(t.x),t.y=h*(this.cosc0*s-this.sinc0*i*a),t.x=this.a*t.x+this.x0,t.y=this.a*t.y+this.y0,t},inverse:function(t){var s,i,a,h,e;if(t.x=(t.x-this.x0)/this.a,t.y=(t.y-this.y0)/this.a,t.x/=this.k0,t.y/=this.k0,e=os(t.x,t.y)){var r=2*Math.atan2(e,this.R2);s=Math.sin(r),i=Math.cos(r),h=Math.asin(i*this.sinc0+t.y*s*this.cosc0/e),a=Math.atan2(t.x*s,e*this.cosc0*i-t.y*this.sinc0*s)}else h=this.phic0,a=0;return t.x=a,t.y=h,ds.inverse.apply(this,[t]),t.x=U(t.x+this.long0),t},names:["Stereographic_North_Pole","Oblique_Stereographic","sterea","Oblique Stereographic Alternative","Double_Stereographic"]};var ms={init:function(){this.x0=this.x0||0,this.y0=this.y0||0,this.lat0=this.lat0||0,this.long0=this.long0||0,this.coslat0=Math.cos(this.lat0),this.sinlat0=Math.sin(this.lat0),this.sphere?1===this.k0&&!isNaN(this.lat_ts)&&Math.abs(this.coslat0)<=M&&(this.k0=.5*(1+F(this.lat0)*Math.sin(this.lat_ts))):(Math.abs(this.coslat0)<=M&&(this.lat0>0?this.con=1:this.con=-1),this.cons=Math.sqrt(Math.pow(1+this.e,1+this.e)*Math.pow(1-this.e,1-this.e)),1===this.k0&&!isNaN(this.lat_ts)&&Math.abs(this.coslat0)<=M&&Math.abs(Math.cos(this.lat_ts))>M&&(this.k0=.5*this.cons*D(this.e,Math.sin(this.lat_ts),Math.cos(this.lat_ts))/Q(this.e,this.con*this.lat_ts,this.con*Math.sin(this.lat_ts))),this.ms1=D(this.e,this.sinlat0,this.coslat0),this.X0=2*Math.atan(this.ssfn_(this.lat0,this.sinlat0,this.e))-l,this.cosX0=Math.cos(this.X0),this.sinX0=Math.sin(this.X0))},forward:function(t){var s,i,a,h,e,r,n=t.x,o=t.y,u=Math.sin(o),c=Math.cos(o),f=U(n-this.long0);return Math.abs(Math.abs(n-this.long0)-Math.PI)<=M&&Math.abs(o+this.lat0)<=M?(t.x=NaN,t.y=NaN,t):this.sphere?(s=2*this.k0/(1+this.sinlat0*u+this.coslat0*c*Math.cos(f)),t.x=this.a*s*c*Math.sin(f)+this.x0,t.y=this.a*s*(this.coslat0*u-this.sinlat0*c*Math.cos(f))+this.y0,t):(i=2*Math.atan(this.ssfn_(o,u,this.e))-l,h=Math.cos(i),a=Math.sin(i),Math.abs(this.coslat0)<=M?(e=Q(this.e,o*this.con,this.con*u),r=2*this.a*this.k0*e/this.cons,t.x=this.x0+r*Math.sin(n-this.long0),t.y=this.y0-this.con*r*Math.cos(n-this.long0),t):(Math.abs(this.sinlat0)0?U(this.long0+Math.atan2(t.x,-1*t.y)):U(this.long0+Math.atan2(t.x,t.y)):U(this.long0+Math.atan2(t.x*Math.sin(n),r*this.coslat0*Math.cos(n)-t.y*this.sinlat0*Math.sin(n))),t.x=s,t.y=i,t)}if(Math.abs(this.coslat0)<=M){if(r<=M)return i=this.lat0,s=this.long0,t.x=s,t.y=i,t;t.x*=this.con,t.y*=this.con,a=r*this.cons/(2*this.a*this.k0),i=this.con*W(this.e,a),s=this.con*U(this.con*this.long0+Math.atan2(t.x,-1*t.y))}else h=2*Math.atan(r*this.cosX0/(2*this.a*this.k0*this.ms1)),s=this.long0,r<=M?e=this.X0:(e=Math.asin(Math.cos(h)*this.sinX0+t.y*Math.sin(h)*this.cosX0/r),s=U(this.long0+Math.atan2(t.x*Math.sin(h),r*this.cosX0*Math.cos(h)-t.y*this.sinX0*Math.sin(h)))),i=-1*W(this.e,Math.tan(.5*(l+e)));return t.x=s,t.y=i,t},names:["stere","Stereographic_South_Pole","Polar Stereographic (variant B)","Polar_Stereographic"],ssfn_:function(t,s,i){return s*=i,Math.tan(.5*(l+t))*Math.pow((1-s)/(1+s),.5*i)}};var _s={init:function(){var t=this.lat0;this.lambda0=this.long0;var s=Math.sin(t),i=this.a,a=1/this.rf,h=2*a-Math.pow(a,2),e=this.e=Math.sqrt(h);this.R=this.k0*i*Math.sqrt(1-h)/(1-h*Math.pow(s,2)),this.alpha=Math.sqrt(1+h/(1-h)*Math.pow(Math.cos(t),4)),this.b0=Math.asin(s/this.alpha);var r=Math.log(Math.tan(Math.PI/4+this.b0/2)),n=Math.log(Math.tan(Math.PI/4+t/2)),o=Math.log((1+e*s)/(1-e*s));this.K=r-this.alpha*n+this.alpha*e/2*o},forward:function(t){var s=Math.log(Math.tan(Math.PI/4-t.y/2)),i=this.e/2*Math.log((1+this.e*Math.sin(t.y))/(1-this.e*Math.sin(t.y))),a=-this.alpha*(s+i)+this.K,h=2*(Math.atan(Math.exp(a))-Math.PI/4),e=this.alpha*(t.x-this.lambda0),r=Math.atan(Math.sin(e)/(Math.sin(this.b0)*Math.tan(h)+Math.cos(this.b0)*Math.cos(e))),n=Math.asin(Math.cos(this.b0)*Math.sin(h)-Math.sin(this.b0)*Math.cos(h)*Math.cos(e));return t.y=this.R/2*Math.log((1+Math.sin(n))/(1-Math.sin(n)))+this.y0,t.x=this.R*r+this.x0,t},inverse:function(t){for(var s=t.x-this.x0,i=t.y-this.y0,a=s/this.R,h=2*(Math.atan(Math.exp(i/this.R))-Math.PI/4),e=Math.asin(Math.cos(this.b0)*Math.sin(h)+Math.sin(this.b0)*Math.cos(h)*Math.cos(a)),r=Math.atan(Math.sin(a)/(Math.cos(this.b0)*Math.cos(a)-Math.sin(this.b0)*Math.tan(h))),n=this.lambda0+r/this.alpha,o=0,l=e,u=-1e3,c=0;Math.abs(l-u)>1e-7;){if(++c>20)return;o=1/this.alpha*(Math.log(Math.tan(Math.PI/4+e/2))-this.K)+this.e*Math.log(Math.tan(Math.PI/4+Math.asin(this.e*Math.sin(l))/2)),u=l,l=2*Math.atan(Math.exp(o))-Math.PI/2}return t.x=n,t.y=l,t},names:["somerc"]},gs=1e-7;var xs={init:function(){var t,s,i,a,h,e,r,n,o,u,c,f,d,_=0,g=0,x=0,v=0,b=0,w=0,A=0;this.no_off=(d="object"==typeof(f=this).PROJECTION?Object.keys(f.PROJECTION)[0]:f.PROJECTION,"no_uoff"in f||"no_off"in f||-1!==["Hotine_Oblique_Mercator","Hotine_Oblique_Mercator_Azimuth_Natural_Origin"].indexOf(d)),this.no_rot="no_rot"in this;var C=!1;"alpha"in this&&(C=!0);var N=!1;if("rectified_grid_angle"in this&&(N=!0),C&&(A=this.alpha),N&&(_=this.rectified_grid_angle*p),C||N)g=this.longc;else if(x=this.long1,b=this.lat1,v=this.long2,w=this.lat2,Math.abs(b-w)<=gs||(t=Math.abs(b))<=gs||Math.abs(t-l)<=gs||Math.abs(Math.abs(this.lat0)-l)<=gs||Math.abs(Math.abs(w)-l)<=gs)throw new Error;var P=1-this.es;s=Math.sqrt(P),Math.abs(this.lat0)>M?(n=Math.sin(this.lat0),i=Math.cos(this.lat0),t=1-this.es*n*n,this.B=i*i,this.B=Math.sqrt(1+this.es*this.B*this.B/P),this.A=this.B*this.k0*s/t,(h=(a=this.B*s/(i*Math.sqrt(t)))*a-1)<=0?h=0:(h=Math.sqrt(h),this.lat0<0&&(h=-h)),this.E=h+=a,this.E*=Math.pow(Q(this.e,this.lat0,n),this.B)):(this.B=1/s,this.A=this.k0,this.E=a=h=1),C||N?(C?(c=Math.asin(Math.sin(A)/a),N||(_=A)):(c=_,A=Math.asin(a*Math.sin(c))),this.lam0=g-Math.asin(.5*(h-1/h)*Math.tan(c))/this.B):(e=Math.pow(Q(this.e,b,Math.sin(b)),this.B),r=Math.pow(Q(this.e,w,Math.sin(w)),this.B),h=this.E/e,o=(r-e)/(r+e),u=((u=this.E*this.E)-r*e)/(u+r*e),(t=x-v)<-Math.pi?v-=m:t>Math.pi&&(v+=m),this.lam0=U(.5*(x+v)-Math.atan(u*Math.tan(.5*this.B*(x-v))/o)/this.B),c=Math.atan(2*Math.sin(this.B*U(x-this.lam0))/(h-1/h)),_=A=Math.asin(a*Math.sin(c))),this.singam=Math.sin(c),this.cosgam=Math.cos(c),this.sinrot=Math.sin(_),this.cosrot=Math.cos(_),this.rB=1/this.B,this.ArB=this.A*this.rB,this.BrA=1/this.ArB,this.A,this.B,this.no_off?this.u_0=0:(this.u_0=Math.abs(this.ArB*Math.atan(Math.sqrt(a*a-1)/Math.cos(A))),this.lat0<0&&(this.u_0=-this.u_0)),h=.5*c,this.v_pole_n=this.ArB*Math.log(Math.tan(y-h)),this.v_pole_s=this.ArB*Math.log(Math.tan(y+h))},forward:function(t){var s,i,a,h,e,r,n,o,u={};if(t.x=t.x-this.lam0,Math.abs(Math.abs(t.y)-l)>M){if(s=.5*((e=this.E/Math.pow(Q(this.e,t.y,Math.sin(t.y)),this.B))-(r=1/e)),i=.5*(e+r),h=Math.sin(this.B*t.x),a=(s*this.singam-h*this.cosgam)/i,Math.abs(Math.abs(a)-1)0?this.v_pole_n:this.v_pole_s,n=this.ArB*t.y;return this.no_rot?(u.x=n,u.y=o):(n-=this.u_0,u.x=o*this.cosrot+n*this.sinrot,u.y=n*this.cosrot-o*this.sinrot),u.x=this.a*u.x+this.x0,u.y=this.a*u.y+this.y0,u},inverse:function(t){var s,i,a,h,e,r,n,o={};if(t.x=(t.x-this.x0)*(1/this.a),t.y=(t.y-this.y0)*(1/this.a),this.no_rot?(i=t.y,s=t.x):(i=t.x*this.cosrot-t.y*this.sinrot,s=t.y*this.cosrot+t.x*this.sinrot+this.u_0),h=.5*((a=Math.exp(-this.BrA*i))-1/a),e=.5*(a+1/a),n=((r=Math.sin(this.BrA*s))*this.cosgam+h*this.singam)/e,Math.abs(Math.abs(n)-1)M?this.ns=Math.log(a/n)/Math.log(h/o):this.ns=s,isNaN(this.ns)&&(this.ns=s),this.f0=a/(this.ns*Math.pow(h,this.ns)),this.rh=this.a*this.f0*Math.pow(l,this.ns),this.title||(this.title="Lambert Conformal Conic")}},forward:function(t){var s=t.x,i=t.y;Math.abs(2*Math.abs(i)-Math.PI)<=M&&(i=F(i)*(l-2*M));var a,h,e=Math.abs(Math.abs(i)-l);if(e>M)a=Q(this.e,i,Math.sin(i)),h=this.a*this.f0*Math.pow(a,this.ns);else{if((e=i*this.ns)<=0)return null;h=0}var r=this.ns*U(s-this.long0);return t.x=this.k0*(h*Math.sin(r))+this.x0,t.y=this.k0*(this.rh-h*Math.cos(r))+this.y0,t},inverse:function(t){var s,i,a,h,e,r=(t.x-this.x0)/this.k0,n=this.rh-(t.y-this.y0)/this.k0;this.ns>0?(s=Math.sqrt(r*r+n*n),i=1):(s=-Math.sqrt(r*r+n*n),i=-1);var o=0;if(0!==s&&(o=Math.atan2(i*r,i*n)),0!==s||this.ns>0){if(i=1/this.ns,a=Math.pow(s/(this.a*this.f0),i),-9999===(h=W(this.e,a)))return null}else h=-l;return e=U(o/this.ns+this.long0),t.x=e,t.y=h,t},names:["Lambert Tangential Conformal Conic Projection","Lambert_Conformal_Conic","Lambert_Conformal_Conic_1SP","Lambert_Conformal_Conic_2SP","lcc","Lambert Conic Conformal (1SP)","Lambert Conic Conformal (2SP)"]};var bs={init:function(){this.a=6377397.155,this.es=.006674372230614,this.e=Math.sqrt(this.es),this.lat0||(this.lat0=.863937979737193),this.long0||(this.long0=.4334234309119251),this.k0||(this.k0=.9999),this.s45=.785398163397448,this.s90=2*this.s45,this.fi0=this.lat0,this.e2=this.es,this.e=Math.sqrt(this.e2),this.alfa=Math.sqrt(1+this.e2*Math.pow(Math.cos(this.fi0),4)/(1-this.e2)),this.uq=1.04216856380474,this.u0=Math.asin(Math.sin(this.fi0)/this.alfa),this.g=Math.pow((1+this.e*Math.sin(this.fi0))/(1-this.e*Math.sin(this.fi0)),this.alfa*this.e/2),this.k=Math.tan(this.u0/2+this.s45)/Math.pow(Math.tan(this.fi0/2+this.s45),this.alfa)*this.g,this.k1=this.k0,this.n0=this.a*Math.sqrt(1-this.e2)/(1-this.e2*Math.pow(Math.sin(this.fi0),2)),this.s0=1.37008346281555,this.n=Math.sin(this.s0),this.ro0=this.k1*this.n0/Math.tan(this.s0),this.ad=this.s90-this.uq},forward:function(t){var s,i,a,h,e,r,n,o=t.x,l=t.y,u=U(o-this.long0);return s=Math.pow((1+this.e*Math.sin(l))/(1-this.e*Math.sin(l)),this.alfa*this.e/2),i=2*(Math.atan(this.k*Math.pow(Math.tan(l/2+this.s45),this.alfa)/s)-this.s45),a=-u*this.alfa,h=Math.asin(Math.cos(this.ad)*Math.sin(i)+Math.sin(this.ad)*Math.cos(i)*Math.cos(a)),e=Math.asin(Math.cos(i)*Math.sin(a)/Math.cos(h)),r=this.n*e,n=this.ro0*Math.pow(Math.tan(this.s0/2+this.s45),this.n)/Math.pow(Math.tan(h/2+this.s45),this.n),t.y=n*Math.cos(r)/1,t.x=n*Math.sin(r)/1,this.czech||(t.y*=-1,t.x*=-1),t},inverse:function(t){var s,i,a,h,e,r,n,o=t.x;t.x=t.y,t.y=o,this.czech||(t.y*=-1,t.x*=-1),e=Math.sqrt(t.x*t.x+t.y*t.y),h=Math.atan2(t.y,t.x)/Math.sin(this.s0),a=2*(Math.atan(Math.pow(this.ro0/e,1/this.n)*Math.tan(this.s0/2+this.s45))-this.s45),s=Math.asin(Math.cos(this.ad)*Math.sin(a)-Math.sin(this.ad)*Math.cos(a)*Math.cos(h)),i=Math.asin(Math.cos(a)*Math.sin(h)/Math.cos(s)),t.x=this.long0-i/this.alfa,r=s,n=0;var l=0;do{t.y=2*(Math.atan(Math.pow(this.k,-1/this.alfa)*Math.pow(Math.tan(s/2+this.s45),1/this.alfa)*Math.pow((1+this.e*Math.sin(r))/(1-this.e*Math.sin(r)),this.e/2))-this.s45),Math.abs(r-t.y)<1e-10&&(n=1),r=t.y,l+=1}while(0===n&&l<15);return l>=15?null:t},names:["Krovak","krovak"]};function ws(t,s,i,a,h){return t*h-s*Math.sin(2*h)+i*Math.sin(4*h)-a*Math.sin(6*h)}function As(t){return 1-.25*t*(1+t/16*(3+1.25*t))}function Cs(t){return.375*t*(1+.25*t*(1+.46875*t))}function Ns(t){return.05859375*t*t*(1+.75*t)}function Ps(t){return t*t*t*(35/3072)}function Es(t,s,i){var a=s*i;return t/Math.sqrt(1-a*a)}function Ss(t){return Math.abs(t)1e-7?(1-t*t)*(s/(1-(i=t*s)*i)-.5/t*Math.log((1-i)/(1+i))):2*s}var qs=.3333333333333333,Ls=.17222222222222222,Rs=.10257936507936508,js=.06388888888888888,Gs=.0664021164021164,Ts=.016415012942191543;var zs={init:function(){var t,s=Math.abs(this.lat0);if(Math.abs(s-l)0)switch(this.qp=Os(this.e,1),this.mmf=.5/(1-this.es),this.apa=function(t){var s,i=[];return i[0]=t*qs,s=t*t,i[0]+=s*Ls,i[1]=s*js,s*=t,i[0]+=s*Rs,i[1]+=s*Gs,i[2]=s*Ts,i}(this.es),this.mode){case this.N_POLE:case this.S_POLE:this.dd=1;break;case this.EQUIT:this.rq=Math.sqrt(.5*this.qp),this.dd=1/this.rq,this.xmf=1,this.ymf=.5*this.qp;break;case this.OBLIQ:this.rq=Math.sqrt(.5*this.qp),t=Math.sin(this.lat0),this.sinb1=Os(this.e,t)/this.qp,this.cosb1=Math.sqrt(1-this.sinb1*this.sinb1),this.dd=Math.cos(this.lat0)/(Math.sqrt(1-this.es*t*t)*this.rq*this.cosb1),this.ymf=(this.xmf=this.rq)/this.dd,this.xmf*=this.dd}else this.mode===this.OBLIQ&&(this.sinph0=Math.sin(this.lat0),this.cosph0=Math.cos(this.lat0))},forward:function(t){var s,i,a,h,e,r,n,o,u,c,f=t.x,p=t.y;if(f=U(f-this.long0),this.sphere){if(e=Math.sin(p),c=Math.cos(p),a=Math.cos(f),this.mode===this.OBLIQ||this.mode===this.EQUIT){if((i=this.mode===this.EQUIT?1+c*a:1+this.sinph0*e+this.cosph0*c*a)<=M)return null;s=(i=Math.sqrt(2/i))*c*Math.sin(f),i*=this.mode===this.EQUIT?e:this.cosph0*e-this.sinph0*c*a}else if(this.mode===this.N_POLE||this.mode===this.S_POLE){if(this.mode===this.N_POLE&&(a=-a),Math.abs(p+this.lat0)=0?(s=(u=Math.sqrt(r))*h,i=a*(this.mode===this.S_POLE?u:-u)):s=i=0}}return t.x=this.a*s+this.x0,t.y=this.a*i+this.y0,t},inverse:function(t){t.x-=this.x0,t.y-=this.y0;var s,i,a,h,e,r,n,o,u,c,f=t.x/this.a,p=t.y/this.a;if(this.sphere){var d,y=0,m=0;if((i=.5*(d=Math.sqrt(f*f+p*p)))>1)return null;switch(i=2*Math.asin(i),this.mode!==this.OBLIQ&&this.mode!==this.EQUIT||(m=Math.sin(i),y=Math.cos(i)),this.mode){case this.EQUIT:i=Math.abs(d)<=M?0:Math.asin(p*m/d),f*=m,p=y*d;break;case this.OBLIQ:i=Math.abs(d)<=M?this.lat0:Math.asin(y*this.sinph0+p*m*this.cosph0/d),f*=m*this.cosph0,p=(y-Math.sin(i)*this.sinph0)*d;break;case this.N_POLE:p=-p,i=l-i;break;case this.S_POLE:i-=l}s=0!==p||this.mode!==this.EQUIT&&this.mode!==this.OBLIQ?Math.atan2(f,p):0}else{if(n=0,this.mode===this.OBLIQ||this.mode===this.EQUIT){if(f/=this.dd,p*=this.dd,(r=Math.sqrt(f*f+p*p))1&&(t=t>1?1:-1),Math.asin(t)}var Ds={init:function(){Math.abs(this.lat1+this.lat2)M?this.ns0=(this.ms1*this.ms1-this.ms2*this.ms2)/(this.qs2-this.qs1):this.ns0=this.con,this.c=this.ms1*this.ms1+this.ns0*this.qs1,this.rh=this.a*Math.sqrt(this.c-this.ns0*this.qs0)/this.ns0)},forward:function(t){var s=t.x,i=t.y;this.sin_phi=Math.sin(i),this.cos_phi=Math.cos(i);var a=Os(this.e3,this.sin_phi),h=this.a*Math.sqrt(this.c-this.ns0*a)/this.ns0,e=this.ns0*U(s-this.long0),r=h*Math.sin(e)+this.x0,n=this.rh-h*Math.cos(e)+this.y0;return t.x=r,t.y=n,t},inverse:function(t){var s,i,a,h,e,r;return t.x-=this.x0,t.y=this.rh-t.y+this.y0,this.ns0>=0?(s=Math.sqrt(t.x*t.x+t.y*t.y),a=1):(s=-Math.sqrt(t.x*t.x+t.y*t.y),a=-1),h=0,0!==s&&(h=Math.atan2(a*t.x,a*t.y)),a=s*this.ns0/this.a,this.sphere?r=Math.asin((this.c-a*a)/(2*this.ns0)):(i=(this.c-a*a)/this.ns0,r=this.phi1z(this.e3,i)),e=U(h/this.ns0+this.long0),t.x=e,t.y=r,t},names:["Albers_Conic_Equal_Area","Albers","aea"],phi1z:function(t,s){var i,a,h,e,r=Bs(.5*s);if(t0||Math.abs(e)<=M?(r=this.x0+1*this.a*i*Math.sin(a)/e,n=this.y0+1*this.a*(this.cos_p14*s-this.sin_p14*i*h)/e):(r=this.x0+this.infinity_dist*i*Math.sin(a),n=this.y0+this.infinity_dist*(this.cos_p14*s-this.sin_p14*i*h)),t.x=r,t.y=n,t},inverse:function(t){var s,i,a,h,e,r;return t.x=(t.x-this.x0)/this.a,t.y=(t.y-this.y0)/this.a,t.x/=this.k0,t.y/=this.k0,(s=Math.sqrt(t.x*t.x+t.y*t.y))?(h=Math.atan2(s,this.rc),i=Math.sin(h),r=Bs((a=Math.cos(h))*this.sin_p14+t.y*i*this.cos_p14/s),e=Math.atan2(t.x*i,s*this.cos_p14*a-t.y*this.sin_p14*i),e=U(this.long0+e)):(r=this.phic0,e=0),t.x=e,t.y=r,t},names:["gnom"]};var Us={init:function(){this.sphere||(this.k0=D(this.e,Math.sin(this.lat_ts),Math.cos(this.lat_ts)))},forward:function(t){var s,i,a=t.x,h=t.y,e=U(a-this.long0);if(this.sphere)s=this.x0+this.a*e*Math.cos(this.lat_ts),i=this.y0+this.a*Math.sin(h)/Math.cos(this.lat_ts);else{var r=Os(this.e,Math.sin(h));s=this.x0+this.a*this.k0*e,i=this.y0+this.a*r*.5/this.k0}return t.x=s,t.y=i,t},inverse:function(t){var s,i;return t.x-=this.x0,t.y-=this.y0,this.sphere?(s=U(this.long0+t.x/this.a/Math.cos(this.lat_ts)),i=Math.asin(t.y/this.a*Math.cos(this.lat_ts))):(i=function(t,s){var i=1-(1-t*t)/(2*t)*Math.log((1-t)/(1+t));if(Math.abs(Math.abs(s)-i)<1e-6)return s<0?-1*l:l;for(var a,h,e,r,n=Math.asin(.5*s),o=0;o<30;o++)if(h=Math.sin(n),e=Math.cos(n),r=t*h,n+=a=Math.pow(1-r*r,2)/(2*e)*(s/(1-t*t)-h/(1-r*r)+.5/t*Math.log((1-r)/(1+r))),Math.abs(a)<=1e-10)return n;return NaN}(this.e,2*t.y*this.k0/this.a),s=U(this.long0+t.x/(this.a*this.k0))),t.x=s,t.y=i,t},names:["cea"]};var Qs={init:function(){this.x0=this.x0||0,this.y0=this.y0||0,this.lat0=this.lat0||0,this.long0=this.long0||0,this.lat_ts=this.lat_ts||0,this.title=this.title||"Equidistant Cylindrical (Plate Carre)",this.rc=Math.cos(this.lat_ts)},forward:function(t){var s=t.x,i=t.y,a=U(s-this.long0),h=Ss(i-this.lat0);return t.x=this.x0+this.a*a*this.rc,t.y=this.y0+this.a*h,t},inverse:function(t){var s=t.x,i=t.y;return t.x=U(this.long0+(s-this.x0)/(this.a*this.rc)),t.y=Ss(this.lat0+(i-this.y0)/this.a),t},names:["Equirectangular","Equidistant_Cylindrical","eqc"]};var Ws={init:function(){this.temp=this.b/this.a,this.es=1-Math.pow(this.temp,2),this.e=Math.sqrt(this.es),this.e0=As(this.es),this.e1=Cs(this.es),this.e2=Ns(this.es),this.e3=Ps(this.es),this.ml0=this.a*ws(this.e0,this.e1,this.e2,this.e3,this.lat0)},forward:function(t){var s,i,a,h=t.x,e=t.y,r=U(h-this.long0);if(a=r*Math.sin(e),this.sphere)Math.abs(e)<=M?(s=this.a*r,i=-1*this.a*this.lat0):(s=this.a*Math.sin(a)/Math.tan(e),i=this.a*(Ss(e-this.lat0)+(1-Math.cos(a))/Math.tan(e)));else if(Math.abs(e)<=M)s=this.a*r,i=-1*this.ml0;else{var n=Es(this.a,this.e,Math.sin(e))/Math.tan(e);s=n*Math.sin(a),i=this.a*ws(this.e0,this.e1,this.e2,this.e3,e)-this.ml0+n*(1-Math.cos(a))}return t.x=s+this.x0,t.y=i+this.y0,t},inverse:function(t){var s,i,a,h,e,r,n,o,l;if(a=t.x-this.x0,h=t.y-this.y0,this.sphere)if(Math.abs(h+this.a*this.lat0)<=M)s=U(a/this.a+this.long0),i=0;else{var u;for(r=this.lat0+h/this.a,n=a*a/this.a/this.a+r*r,o=r,e=20;e;--e)if(o+=l=-1*(r*(o*(u=Math.tan(o))+1)-o-.5*(o*o+n)*u)/((o-r)/u-1),Math.abs(l)<=M){i=o;break}s=U(this.long0+Math.asin(a*Math.tan(o)/this.a)/Math.sin(i))}else if(Math.abs(h+this.ml0)<=M)i=0,s=U(this.long0+a/this.a);else{var c,f,p,d,y;for(r=(this.ml0+h)/this.a,n=a*a/this.a/this.a+r*r,o=r,e=20;e;--e)if(y=this.e*Math.sin(o),c=Math.sqrt(1-y*y)*Math.tan(o),f=this.a*ws(this.e0,this.e1,this.e2,this.e3,o),p=this.e0-2*this.e1*Math.cos(2*o)+4*this.e2*Math.cos(4*o)-6*this.e3*Math.cos(6*o),o-=l=(r*(c*(d=f/this.a)+1)-d-.5*c*(d*d+n))/(this.es*Math.sin(2*o)*(d*d+n-2*r*d)/(4*c)+(r-d)*(c*p-2/Math.sin(2*o))-p),Math.abs(l)<=M){i=o;break}c=Math.sqrt(1-this.es*Math.pow(Math.sin(i),2))*Math.tan(i),s=U(this.long0+Math.asin(a*c/this.a)/Math.sin(i))}return t.x=s,t.y=i,t},names:["Polyconic","poly"]};var Zs={init:function(){this.A=[],this.A[1]=.6399175073,this.A[2]=-.1358797613,this.A[3]=.063294409,this.A[4]=-.02526853,this.A[5]=.0117879,this.A[6]=-.0055161,this.A[7]=.0026906,this.A[8]=-.001333,this.A[9]=67e-5,this.A[10]=-34e-5,this.B_re=[],this.B_im=[],this.B_re[1]=.7557853228,this.B_im[1]=0,this.B_re[2]=.249204646,this.B_im[2]=.003371507,this.B_re[3]=-.001541739,this.B_im[3]=.04105856,this.B_re[4]=-.10162907,this.B_im[4]=.01727609,this.B_re[5]=-.26623489,this.B_im[5]=-.36249218,this.B_re[6]=-.6870983,this.B_im[6]=-1.1651967,this.C_re=[],this.C_im=[],this.C_re[1]=1.3231270439,this.C_im[1]=0,this.C_re[2]=-.577245789,this.C_im[2]=-.007809598,this.C_re[3]=.508307513,this.C_im[3]=-.112208952,this.C_re[4]=-.15094762,this.C_im[4]=.18200602,this.C_re[5]=1.01418179,this.C_im[5]=1.64497696,this.C_re[6]=1.9660549,this.C_im[6]=2.5127645,this.D=[],this.D[1]=1.5627014243,this.D[2]=.5185406398,this.D[3]=-.03333098,this.D[4]=-.1052906,this.D[5]=-.0368594,this.D[6]=.007317,this.D[7]=.0122,this.D[8]=.00394,this.D[9]=-.0013},forward:function(t){var s,i=t.x,a=t.y-this.lat0,h=i-this.long0,e=a/o*1e-5,r=h,n=1,l=0;for(s=1;s<=10;s++)n*=e,l+=this.A[s]*n;var u,c=l,f=r,M=1,p=0,d=0,y=0;for(s=1;s<=6;s++)u=p*c+M*f,M=M*c-p*f,p=u,d=d+this.B_re[s]*M-this.B_im[s]*p,y=y+this.B_im[s]*M+this.B_re[s]*p;return t.x=y*this.a+this.x0,t.y=d*this.a+this.y0,t},inverse:function(t){var s,i,a=t.x,h=t.y,e=a-this.x0,r=(h-this.y0)/this.a,n=e/this.a,l=1,u=0,c=0,f=0;for(s=1;s<=6;s++)i=u*r+l*n,l=l*r-u*n,u=i,c=c+this.C_re[s]*l-this.C_im[s]*u,f=f+this.C_im[s]*l+this.C_re[s]*u;for(var M=0;M.999999999999&&(i=.999999999999),s=Math.asin(i);var a=U(this.long0+t.x/(.900316316158*this.a*Math.cos(s)));a<-Math.PI&&(a=-Math.PI),a>Math.PI&&(a=Math.PI),i=(2*s+Math.sin(2*s))/Math.PI,Math.abs(i)>1&&(i=1);var h=Math.asin(i);return t.x=a,t.y=h,t},names:["Mollweide","moll"]};var Js={init:function(){Math.abs(this.lat1+this.lat2)=0?(i=Math.sqrt(t.x*t.x+t.y*t.y),s=1):(i=-Math.sqrt(t.x*t.x+t.y*t.y),s=-1);var e=0;return 0!==i&&(e=Math.atan2(s*t.x,s*t.y)),this.sphere?(h=U(this.long0+e/this.ns),a=Ss(this.g-i/this.a),t.x=h,t.y=a,t):(a=Is(this.g-i/this.a,this.e0,this.e1,this.e2,this.e3),h=U(this.long0+e/this.ns),t.x=h,t.y=a,t)},names:["Equidistant_Conic","eqdc"]};var Ks={init:function(){this.R=this.a},forward:function(t){var s,i,a=t.x,h=t.y,e=U(a-this.long0);Math.abs(h)<=M&&(s=this.x0+this.R*e,i=this.y0);var r=Bs(2*Math.abs(h/Math.PI));(Math.abs(e)<=M||Math.abs(Math.abs(h)-l)<=M)&&(s=this.x0,i=h>=0?this.y0+Math.PI*this.R*Math.tan(.5*r):this.y0+Math.PI*this.R*-Math.tan(.5*r));var n=.5*Math.abs(Math.PI/e-e/Math.PI),o=n*n,u=Math.sin(r),c=Math.cos(r),f=c/(u+c-1),p=f*f,d=f*(2/u-1),y=d*d,m=Math.PI*this.R*(n*(f-y)+Math.sqrt(o*(f-y)*(f-y)-(y+o)*(p-y)))/(y+o);e<0&&(m=-m),s=this.x0+m;var _=o+f;return m=Math.PI*this.R*(d*_-n*Math.sqrt((y+o)*(o+1)-_*_))/(y+o),i=h>=0?this.y0+m:this.y0-m,t.x=s,t.y=i,t},inverse:function(t){var s,i,a,h,e,r,n,o,l,u,c,f;return t.x-=this.x0,t.y-=this.y0,c=Math.PI*this.R,e=(a=t.x/c)*a+(h=t.y/c)*h,c=3*(h*h/(o=-2*(r=-Math.abs(h)*(1+e))+1+2*h*h+e*e)+(2*(n=r-2*h*h+a*a)*n*n/o/o/o-9*r*n/o/o)/27)/(l=(r-n*n/3/o)/o)/(u=2*Math.sqrt(-l/3)),Math.abs(c)>1&&(c=c>=0?1:-1),f=Math.acos(c)/3,i=t.y>=0?(-u*Math.cos(f+Math.PI/3)-n/3/o)*Math.PI:-(-u*Math.cos(f+Math.PI/3)-n/3/o)*Math.PI,s=Math.abs(a)2*l*this.a)return;return i=s/this.a,a=Math.sin(i),h=Math.cos(i),e=this.long0,Math.abs(s)<=M?r=this.lat0:(r=Bs(h*this.sin_p12+t.y*a*this.cos_p12/s),n=Math.abs(this.lat0)-l,e=Math.abs(n)<=M?this.lat0>=0?U(this.long0+Math.atan2(t.x,-t.y)):U(this.long0-Math.atan2(-t.x,t.y)):U(this.long0+Math.atan2(t.x*a,s*this.cos_p12*h-t.y*this.sin_p12*a))),t.x=e,t.y=r,t}return o=As(this.es),u=Cs(this.es),c=Ns(this.es),f=Ps(this.es),Math.abs(this.sin_p12-1)<=M?(r=Is(((p=this.a*ws(o,u,c,f,l))-(s=Math.sqrt(t.x*t.x+t.y*t.y)))/this.a,o,u,c,f),e=U(this.long0+Math.atan2(t.x,-1*t.y)),t.x=e,t.y=r,t):Math.abs(this.sin_p12+1)<=M?(p=this.a*ws(o,u,c,f,l),r=Is(((s=Math.sqrt(t.x*t.x+t.y*t.y))-p)/this.a,o,u,c,f),e=U(this.long0+Math.atan2(t.x,t.y)),t.x=e,t.y=r,t):(s=Math.sqrt(t.x*t.x+t.y*t.y),m=Math.atan2(t.x,t.y),d=Es(this.a,this.e,this.sin_p12),_=Math.cos(m),x=-(g=this.e*this.cos_p12*_)*g/(1-this.es),v=3*this.es*(1-x)*this.sin_p12*this.cos_p12*_/(1-this.es),A=1-x*(w=(b=s/d)-x*(1+x)*Math.pow(b,3)/6-v*(1+3*x)*Math.pow(b,4)/24)*w/2-b*w*w*w/6,y=Math.asin(this.sin_p12*Math.cos(w)+this.cos_p12*Math.sin(w)*_),e=U(this.long0+Math.asin(Math.sin(m)*Math.sin(w)/Math.cos(y))),C=Math.sin(y),r=Math.atan2((C-this.es*A*this.sin_p12)*Math.tan(y),C*(1-this.es)),t.x=e,t.y=r,t)},names:["Azimuthal_Equidistant","aeqd"]};var Ys={init:function(){this.sin_p14=Math.sin(this.lat0),this.cos_p14=Math.cos(this.lat0)},forward:function(t){var s,i,a,h,e,r,n,o=t.x,l=t.y;return a=U(o-this.long0),s=Math.sin(l),i=Math.cos(l),h=Math.cos(a),1,((e=this.sin_p14*s+this.cos_p14*i*h)>0||Math.abs(e)<=M)&&(r=1*this.a*i*Math.sin(a),n=this.y0+1*this.a*(this.cos_p14*s-this.sin_p14*i*h)),t.x=r,t.y=n,t},inverse:function(t){var s,i,a,h,e,r,n;return t.x-=this.x0,t.y-=this.y0,i=Bs((s=Math.sqrt(t.x*t.x+t.y*t.y))/this.a),a=Math.sin(i),h=Math.cos(i),r=this.long0,Math.abs(s)<=M?(n=this.lat0,t.x=r,t.y=n,t):(n=Bs(h*this.sin_p14+t.y*a*this.cos_p14/s),e=Math.abs(this.lat0)-l,Math.abs(e)<=M?(r=this.lat0>=0?U(this.long0+Math.atan2(t.x,-t.y)):U(this.long0-Math.atan2(-t.x,t.y)),t.x=r,t.y=n,t):(r=U(this.long0+Math.atan2(t.x*a,s*this.cos_p14*h-t.y*this.sin_p14*a)),t.x=r,t.y=n,t))},names:["ortho"]},ti=1,si=2,ii=3,ai=4,hi=5,ei=6,ri={AREA_0:1,AREA_1:2,AREA_2:3,AREA_3:4};function ni(t,s,i,a){var h;return ty&&h<=l+y?(a.value=ri.AREA_1,h-=l):h>l+y||h<=-(l+y)?(a.value=ri.AREA_2,h=h>=0?h-_:h+_):(a.value=ri.AREA_3,h+=l)),h}function oi(t,s){var i=t+s;return i<-_?i+=m:i>+_&&(i-=m),i}var li={init:function(){this.x0=this.x0||0,this.y0=this.y0||0,this.lat0=this.lat0||0,this.long0=this.long0||0,this.lat_ts=this.lat_ts||0,this.title=this.title||"Quadrilateralized Spherical Cube",this.lat0>=l-y/2?this.face=hi:this.lat0<=-(l-y/2)?this.face=ei:Math.abs(this.long0)<=y?this.face=ti:Math.abs(this.long0)<=l+y?this.face=this.long0>0?si:ai:this.face=ii,0!==this.es&&(this.one_minus_f=1-(this.a-this.b)/this.a,this.one_minus_f_squared=this.one_minus_f*this.one_minus_f)},forward:function(t){var s,i,a,h,e,r,n={x:0,y:0},o={value:0};if(t.x-=this.long0,s=0!==this.es?Math.atan(this.one_minus_f_squared*Math.tan(t.y)):t.y,i=t.x,this.face===hi)h=l-s,i>=y&&i<=l+y?(o.value=ri.AREA_0,a=i-l):i>l+y||i<=-(l+y)?(o.value=ri.AREA_1,a=i>0?i-_:i+_):i>-(l+y)&&i<=-y?(o.value=ri.AREA_2,a=i+l):(o.value=ri.AREA_3,a=i);else if(this.face===ei)h=l+s,i>=y&&i<=l+y?(o.value=ri.AREA_0,a=-i+l):i=-y?(o.value=ri.AREA_1,a=-i):i<-y&&i>=-(l+y)?(o.value=ri.AREA_2,a=-i-l):(o.value=ri.AREA_3,a=i>0?-i+_:-i-_);else{var u,c,f,M,p,d;this.face===si?i=oi(i,+l):this.face===ii?i=oi(i,+_):this.face===ai&&(i=oi(i,-l)),M=Math.sin(s),p=Math.cos(s),d=Math.sin(i),u=p*Math.cos(i),c=p*d,f=M,this.face===ti?a=ni(h=Math.acos(u),f,c,o):this.face===si?a=ni(h=Math.acos(c),f,-u,o):this.face===ii?a=ni(h=Math.acos(-u),f,-c,o):this.face===ai?a=ni(h=Math.acos(-c),f,u,o):(h=a=0,o.value=ri.AREA_0)}return r=Math.atan(12/_*(a+Math.acos(Math.sin(a)*Math.cos(y))-l)),e=Math.sqrt((1-Math.cos(h))/(Math.cos(r)*Math.cos(r))/(1-Math.cos(Math.atan(1/Math.cos(a))))),o.value===ri.AREA_1?r+=l:o.value===ri.AREA_2?r+=_:o.value===ri.AREA_3&&(r+=1.5*_),n.x=e*Math.cos(r),n.y=e*Math.sin(r),n.x=n.x*this.a+this.x0,n.y=n.y*this.a+this.y0,t.x=n.x,t.y=n.y,t},inverse:function(t){var s,i,a,h,e,r,n,o,u,c,f,M,p={lam:0,phi:0},d={value:0};if(t.x=(t.x-this.x0)/this.a,t.y=(t.y-this.y0)/this.a,i=Math.atan(Math.sqrt(t.x*t.x+t.y*t.y)),s=Math.atan2(t.y,t.x),t.x>=0&&t.x>=Math.abs(t.y)?d.value=ri.AREA_0:t.y>=0&&t.y>=Math.abs(t.x)?(d.value=ri.AREA_1,s-=l):t.x<0&&-t.x>=Math.abs(t.y)?(d.value=ri.AREA_2,s=s<0?s+_:s-_):(d.value=ri.AREA_3,s+=l),u=_/12*Math.tan(s),e=Math.sin(u)/(Math.cos(u)-1/Math.sqrt(2)),r=Math.atan(e),(n=1-(a=Math.cos(s))*a*(h=Math.tan(i))*h*(1-Math.cos(Math.atan(1/Math.cos(r)))))<-1?n=-1:n>1&&(n=1),this.face===hi)o=Math.acos(n),p.phi=l-o,d.value===ri.AREA_0?p.lam=r+l:d.value===ri.AREA_1?p.lam=r<0?r+_:r-_:d.value===ri.AREA_2?p.lam=r-l:p.lam=r;else if(this.face===ei)o=Math.acos(n),p.phi=o-l,d.value===ri.AREA_0?p.lam=-r+l:d.value===ri.AREA_1?p.lam=-r:d.value===ri.AREA_2?p.lam=-r-l:p.lam=r<0?-r-_:-r+_;else{var y,m,g;u=(y=n)*y,m=(u+=(g=u>=1?0:Math.sqrt(1-u)*Math.sin(r))*g)>=1?0:Math.sqrt(1-u),d.value===ri.AREA_1?(u=m,m=-g,g=u):d.value===ri.AREA_2?(m=-m,g=-g):d.value===ri.AREA_3&&(u=m,m=g,g=-u),this.face===si?(u=y,y=-m,m=u):this.face===ii?(y=-y,m=-m):this.face===ai&&(u=y,y=m,m=-u),p.phi=Math.acos(-g)-l,p.lam=Math.atan2(m,y),this.face===si?p.lam=oi(p.lam,-l):this.face===ii?p.lam=oi(p.lam,-_):this.face===ai&&(p.lam=oi(p.lam,+l))}return 0!==this.es&&(c=p.phi<0?1:0,f=Math.tan(p.phi),M=this.b/Math.sqrt(f*f+this.one_minus_f_squared),p.phi=Math.atan(Math.sqrt(this.a*this.a-M*M)/(this.one_minus_f*M)),c&&(p.phi=-p.phi)),p.lam+=this.long0,t.x=p.lam,t.y=p.phi,t},names:["Quadrilateralized Spherical Cube","Quadrilateralized_Spherical_Cube","qsc"]},ui=[[1,22199e-21,-715515e-10,31103e-10],[.9986,-482243e-9,-24897e-9,-13309e-10],[.9954,-83103e-8,-448605e-10,-9.86701e-7],[.99,-.00135364,-59661e-9,36777e-10],[.9822,-.00167442,-449547e-11,-572411e-11],[.973,-.00214868,-903571e-10,1.8736e-8],[.96,-.00305085,-900761e-10,164917e-11],[.9427,-.00382792,-653386e-10,-26154e-10],[.9216,-.00467746,-10457e-8,481243e-11],[.8962,-.00536223,-323831e-10,-543432e-11],[.8679,-.00609363,-113898e-9,332484e-11],[.835,-.00698325,-640253e-10,9.34959e-7],[.7986,-.00755338,-500009e-10,9.35324e-7],[.7597,-.00798324,-35971e-9,-227626e-11],[.7186,-.00851367,-701149e-10,-86303e-10],[.6732,-.00986209,-199569e-9,191974e-10],[.6213,-.010418,883923e-10,624051e-11],[.5722,-.00906601,182e-6,624051e-11],[.5322,-.00677797,275608e-9,624051e-11]],ci=[[-520417e-23,.0124,121431e-23,-845284e-16],[.062,.0124,-1.26793e-9,4.22642e-10],[.124,.0124,5.07171e-9,-1.60604e-9],[.186,.0123999,-1.90189e-8,6.00152e-9],[.248,.0124002,7.10039e-8,-2.24e-8],[.31,.0123992,-2.64997e-7,8.35986e-8],[.372,.0124029,9.88983e-7,-3.11994e-7],[.434,.0123893,-369093e-11,-4.35621e-7],[.4958,.0123198,-102252e-10,-3.45523e-7],[.5571,.0121916,-154081e-10,-5.82288e-7],[.6176,.0119938,-241424e-10,-5.25327e-7],[.6769,.011713,-320223e-10,-5.16405e-7],[.7346,.0113541,-397684e-10,-6.09052e-7],[.7903,.0109107,-489042e-10,-104739e-11],[.8435,.0103431,-64615e-9,-1.40374e-9],[.8936,.00969686,-64636e-9,-8547e-9],[.9394,.00840947,-192841e-9,-42106e-10],[.9761,.00616527,-256e-6,-42106e-10],[1,.00328947,-319159e-9,-42106e-10]],fi=.8487,Mi=1.3523,pi=d/5,di=1/pi,yi=18,mi=function(t,s){return t[0]+s*(t[1]+s*(t[2]+s*t[3]))};var _i={init:function(){this.x0=this.x0||0,this.y0=this.y0||0,this.long0=this.long0||0,this.es=0,this.title=this.title||"Robinson"},forward:function(t){var s=U(t.x-this.long0),i=Math.abs(t.y),a=Math.floor(i*pi);a<0?a=0:a>=yi&&(a=17);var h={x:mi(ui[a],i=d*(i-di*a))*s,y:mi(ci[a],i)};return t.y<0&&(h.y=-h.y),h.x=h.x*this.a*fi+this.x0,h.y=h.y*this.a*Mi+this.y0,h},inverse:function(t){var s={x:(t.x-this.x0)/(this.a*fi),y:Math.abs(t.y-this.y0)/(this.a*Mi)};if(s.y>=1)s.x/=ui[18][0],s.y=t.y<0?-l:l;else{var i=Math.floor(s.y*yi);for(i<0?i=0:i>=yi&&(i=17);;)if(ci[i][0]>s.y)--i;else{if(!(ci[i+1][0]<=s.y))break;++i}var a=ci[i],h=5*(s.y-a[0])/(ci[i+1][0]-a[0]);h=function(t,s,i,a){for(var h=s;a;--a){var e=t(h);if(h-=e,Math.abs(e)1e10)throw new Error;if(this.radius_g=1+this.radius_g_1,this.C=this.radius_g*this.radius_g-1,0!==this.es){var t=1-this.es,s=1/t;this.radius_p=Math.sqrt(t),this.radius_p2=t,this.radius_p_inv2=s,this.shape="ellipse"}else this.radius_p=1,this.radius_p2=1,this.radius_p_inv2=1,this.shape="sphere";this.title||(this.title="Geostationary Satellite View")},forward:function(t){var s,i,a,h,e=t.x,r=t.y;if(e-=this.long0,"ellipse"===this.shape){r=Math.atan(this.radius_p2*Math.tan(r));var n=this.radius_p/os(this.radius_p*Math.cos(r),Math.sin(r));if(i=n*Math.cos(e)*Math.cos(r),a=n*Math.sin(e)*Math.cos(r),h=n*Math.sin(r),(this.radius_g-i)*i-a*a-h*h*this.radius_p_inv2<0)return t.x=Number.NaN,t.y=Number.NaN,t;s=this.radius_g-i,this.flip_axis?(t.x=this.radius_g_1*Math.atan(a/os(h,s)),t.y=this.radius_g_1*Math.atan(h/s)):(t.x=this.radius_g_1*Math.atan(a/s),t.y=this.radius_g_1*Math.atan(h/os(a,s)))}else"sphere"===this.shape&&(s=Math.cos(r),i=Math.cos(e)*s,a=Math.sin(e)*s,h=Math.sin(r),s=this.radius_g-i,this.flip_axis?(t.x=this.radius_g_1*Math.atan(a/os(h,s)),t.y=this.radius_g_1*Math.atan(h/s)):(t.x=this.radius_g_1*Math.atan(a/s),t.y=this.radius_g_1*Math.atan(h/os(a,s))));return t.x=t.x*this.a,t.y=t.y*this.a,t},inverse:function(t){var s,i,a,h,e=-1,r=0,n=0;if(t.x=t.x/this.a,t.y=t.y/this.a,"ellipse"===this.shape){this.flip_axis?(n=Math.tan(t.y/this.radius_g_1),r=Math.tan(t.x/this.radius_g_1)*os(1,n)):(r=Math.tan(t.x/this.radius_g_1),n=Math.tan(t.y/this.radius_g_1)*os(1,r));var o=n/this.radius_p;if(s=r*r+o*o+e*e,(a=(i=2*this.radius_g*e)*i-4*s*this.C)<0)return t.x=Number.NaN,t.y=Number.NaN,t;h=(-i-Math.sqrt(a))/(2*s),e=this.radius_g+h*e,r*=h,n*=h,t.x=Math.atan2(r,e),t.y=Math.atan(n*Math.cos(t.x)/e),t.y=Math.atan(this.radius_p_inv2*Math.tan(t.y))}else if("sphere"===this.shape){if(this.flip_axis?(n=Math.tan(t.y/this.radius_g_1),r=Math.tan(t.x/this.radius_g_1)*Math.sqrt(1+n*n)):(r=Math.tan(t.x/this.radius_g_1),n=Math.tan(t.y/this.radius_g_1)*Math.sqrt(1+r*r)),s=r*r+n*n+e*e,(a=(i=2*this.radius_g*e)*i-4*s*this.C)<0)return t.x=Number.NaN,t.y=Number.NaN,t;h=(-i-Math.sqrt(a))/(2*s),e=this.radius_g+h*e,r*=h,n*=h,t.x=Math.atan2(r,e),t.y=Math.atan(n*Math.cos(t.x)/e)}return t.x=t.x+this.long0,t},names:["Geostationary Satellite View","Geostationary_Satellite","geos"]};At.defaultDatum="WGS84",At.Proj=lt,At.WGS84=new At.Proj("WGS84"),At.Point=Ut,At.toPoint=_t,At.defs=j,At.nadgrid=function(t,s){var i=new DataView(s),a=function(t){var s=t.getInt32(8,!1);if(11===s)return!1;s=t.getInt32(8,!0),11!==s&&console.warn("Failed to detect nadgrid endian-ness, defaulting to little-endian");return!0}(i),h=function(t,s){return{nFields:t.getInt32(8,s),nSubgridFields:t.getInt32(24,s),nSubgrids:t.getInt32(40,s),shiftType:et(t,56,64).trim(),fromSemiMajorAxis:t.getFloat64(120,s),fromSemiMinorAxis:t.getFloat64(136,s),toSemiMajorAxis:t.getFloat64(152,s),toSemiMinorAxis:t.getFloat64(168,s)}}(i,a),e=function(t,s,i){for(var a=176,h=[],e=0;e{let s=new Si(Ei),i=s.writable.getWriter(),a=s.readable.getReader();i.write(t),i.close();let h,e,r=[],n=0,o=0;for(;!(e=await a.read()).done;)h=e.value,r.push(h),n+=h.length;return r.length-1?(h=new Uint8Array(n),r.map((t=>{h.set(t,o),o+=t.length})),h):r[0]}}catch{}var Ii=new TextDecoder,ki=t=>{throw new Error("but-unzip~"+t)},Oi=t=>Ii.decode(t);function*qi(t,s=Pi){let i=(t=>{let s=t.length-20,i=Math.max(s-65516,2);for(;-1!==(s=t.lastIndexOf(80,s-1))&&(75!==t[s+1]||5!==t[s+2]||6!==t[s+3])&&s>i;);return s})(t);-1===i&&ki(2);let a=(s,a)=>t.subarray(i+=s,i+=a),h=new DataView(t.buffer,t.byteOffset),e=t=>h.getUint16(t+i,!0),r=t=>h.getUint32(t+i,!0),n=e(10);for(n!==e(8)&&ki(3),i=r(16);n--;){let t,h=e(10),n=e(28),o=e(30),l=e(32),u=r(20),c=r(42),f=Oi(a(46,n)),M=Oi(a(o,l)),p=i;i=c,t=a(30+e(26)+e(28),u),yield{filename:f,comment:M,read:()=>8&h?s(t):h?ki(1):t},i=p}}const Li=/.+\.(shp|dbf|json|prj|cpg)$/i;const Ri=globalThis.URL;var ji=(t,s)=>{if(!s)return t;const i=new Ri(t);return i.pathname=`${i.pathname}.${s}`,i.href};async function Gi(t,s){const i=ji(t,s),a="prj"===s||"cpg"===s;try{const t=await fetch(i);if(t.status>399)throw new Error(t.statusText);if(a)return t.text();const s=await t.arrayBuffer();return new DataView(s)}catch(t){if(a||"dbf"===s)return!1;throw t}}function Ti(t){let s=0,i=1;const a=t.length;let h,e;const r=[t[0][0],t[0][1],t[0][0],t[0][1]];for(;ir[2]&&(r[2]=e[0]),e[1]>r[3]&&(r[3]=e[1]);return{ring:t,clockWise:s>0,bbox:r,children:[]}}function zi(t,s){return!(t.bbox[0]>s.bbox[0])&&(!(t.bbox[1]>s.bbox[1])&&(!(t.bbox[2]20&&(s-=20),!(s in Bi))throw new Error(`I don't know shp type "${s}"`);var i;this.parseFunc=this[Bi[s]],this.parseCoord=(i=t)?function(t,s){const a=[t.getFloat64(s,!0),t.getFloat64(s+8,!0)];return i.inverse(a)}:function(t,s){return[t.getFloat64(s,!0),t.getFloat64(s+8,!0)]}},Di.prototype.getShpCode=function(){return this.parseHeader().shpCode},Di.prototype.parseHeader=function(){const t=this.buffer;return{length:t.getInt32(24)<<1,version:t.getInt32(28,!0),shpCode:t.getInt32(32,!0),bbox:[t.getFloat64(36,!0),t.getFloat64(44,!0),t.getFloat64(52,!0),t.getFloat64(60,!0)]}},Di.prototype.getRows=function(){let t=100;const s=this.buffer.byteLength-8,i=[];let a;for(;t<=s&&(a=this.getRow(t),a);)t+=8,t+=a.len,a.type?i.push(this.parseFunc(a.data)):i.push(null);return i},Di.prototype.getRow=function(t){const s=this.buffer.getInt32(t),i=this.buffer.getInt32(t+4)<<1;return 0===i?{id:s,len:i,type:0}:t+i+8>this.buffer.byteLength?void 0:{id:s,len:i,data:new DataView(this.buffer.buffer,this.buffer.byteOffset+t+12,i-4),type:this.buffer.getInt32(t+8,!0)}};var Ui=/^(?:ANSI\s)?(\d+)$/m;function Qi(t,s){if(!t)return a;try{new TextDecoder(t.trim())}catch(h){var i=Ui.exec(t);return i&&!s?Qi("windows-"+i[1],!0):(t=void 0,a)}return a;function a(s){var i=new TextDecoder(t||void 0);return(i.decode(s,{stream:!0})+i.decode()).replace(/\0/g,"").trim()}}function Wi(t,s,i,a,h){var e=h(new Uint8Array(t.buffer.slice(t.byteOffset+s,t.byteOffset+s+i)));switch(a){case"N":case"F":case"O":return parseFloat(e,10);case"D":return new Date(e.slice(0,4),parseInt(e.slice(4,6),10)-1,e.slice(6,8));case"L":return"y"===e.toLowerCase()||"t"===e.toLowerCase();default:return e}}function Zi(t,s,i,a){for(var h,e,r={},n=0,o=i.length;n{if(t)return"string"==typeof t?t:$i(t)||ArrayBuffer.isView(t)||Yi(t)?Xi.decode(t):void 0},Ki=t=>{if(!t)throw new Error("forgot to pass buffer");if(Yi(t))return t;if($i(t))return new DataView(t);if($i(t.buffer))return new DataView(t.buffer,t.byteOffset,t.byteLength);throw new Error("invalid buffer like object")};function $i(t){return t instanceof globalThis.ArrayBuffer||"[object ArrayBuffer]"===Object.prototype.toString.call(t)}function Yi(t){return t instanceof globalThis.DataView||"[object DataView]"===Object.prototype.toString.call(t)}const ta=function([t,s]){const i={type:"FeatureCollection",features:[]};let a=0;const h=t.length;for(s||(s=[]);a{if(!t)throw new Error("forgot to pass buffer");if($i(t))return new Uint8Array(t);if($i(t.buffer))return 1===t.BYTES_PER_ELEMENT?t:new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("invalid buffer like object")})(t);const a=await(async t=>{const s={},i=[];for(const a of qi(t))Li.test(a.filename)&&i.push(Promise.resolve(a.read()).then((t=>s[a.filename]=t)));await Promise.all(i);const a={},h=new TextDecoder;for(const[t,i]of Object.entries(s))"shp"===t.slice(-3).toLowerCase()||"dbf"===t.slice(-3).toLowerCase()?a[t]=new DataView(i.buffer,i.byteOffset,i.byteLength):a[t]=h.decode(i);return a})(t),h=[];for(i in s=s||[],a)-1===i.indexOf("__MACOSX")&&(".shp"===i.slice(-4).toLowerCase()?(h.push(i.slice(0,-4)),a[i.slice(0,-3)+i.slice(-3).toLowerCase()]=a[i]):".prj"===i.slice(-4).toLowerCase()?a[i.slice(0,-3)+i.slice(-3).toLowerCase()]=At(a[i]):".json"===i.slice(-5).toLowerCase()||s.indexOf(i.split(".").pop())>-1?h.push(i.slice(0,-3)+i.slice(-3).toLowerCase()):".dbf"!==i.slice(-4).toLowerCase()&&".cpg"!==i.slice(-4).toLowerCase()||(a[i.slice(0,-3)+i.slice(-3).toLowerCase()]=a[i]));if(!h.length)throw new Error("no layers founds");const e=h.map((function(t){let i,h;const e=t.lastIndexOf(".");return e>-1&&t.slice(e).indexOf("json")>-1?(i=JSON.parse(a[t]),i.fileName=t.slice(0,e)):s.indexOf(t.slice(e+1))>-1?(i=a[t],i.fileName=t):(a[t+".dbf"]&&(h=Hi(a[t+".dbf"],a[t+".cpg"])),i=ta([Fi(a[t+".shp"],a[t+".prj"]),h]),i.fileName=t),i}));return 1===e.length?e[0]:e};const ia=async t=>{const s=await Promise.all([Gi(t,"shp"),Gi(t,"prj")]);let i=!1;try{s[1]&&(i=At(s[1]))}catch(t){i=!1}return Fi(s[0],i)},aa=async t=>{const[s,i]=await Promise.all([Gi(t,"dbf"),Gi(t,"cpg")]);if(s)return Hi(s,i)},ha=(t,s)=>new Vi(t,globalThis?.document?.location).pathname.slice(-4).toLowerCase()===s,ea=async function(t,s){if("string"!=typeof t){if($i(t)||ArrayBuffer.isView(t)||Yi(t))return sa(t);if(t.shp)return(({shp:t,dbf:s,cpg:i,prj:a})=>{const h=[ra(t,a)];return s&&h.push(na(s,i)),ta(h)})(t);throw new TypeError("must be a string, some sort of Buffer, or an object with at least a .shp property")}if(ha(t,".zip"))return async function(t,s){const i=await Gi(t);return sa(i,s)}(t,s);ha(t,".shp")&&(t=t.slice(0,-4));const i=await Promise.all([ia(t),aa(t)]);return ta(i)},ra=function(t,s){if(t=Ki(t),"string"==typeof(s=Ji(s)))try{s=At(s)}catch(t){s=!1}return Fi(t,s)},na=function(t,s){return Hi(t=Ki(t),s=Ji(s))};return ea.combine=ta,ea.parseDbf=na,ea.parseZip=sa,ea.parseShp=ra,ea})); diff --git a/test/bundle.js b/test/bundle.js index ff53f98..02158ba 100644 --- a/test/bundle.js +++ b/test/bundle.js @@ -862,7 +862,7 @@ return -9999; } - function init$w() { + function init$v() { var con = this.b / this.a; this.es = 1 - con * con; if(!('x0' in this)){ @@ -951,13 +951,13 @@ var names$w = ["Mercator", "Popular Visualisation Pseudo Mercator", "Mercator_1SP", "Mercator_Auxiliary_Sphere", "merc"]; var merc = { - init: init$w, + init: init$v, forward: forward$u, inverse: inverse$u, names: names$w }; - function init$v() { + function init$u() { //no-op for longlat } @@ -966,7 +966,7 @@ } var names$v = ["longlat", "identity"]; var longlat = { - init: init$v, + init: init$u, forward: identity, inverse: identity, names: names$v @@ -989,7 +989,7 @@ return this; } - function get(name) { + function get$1(name) { if (!name) { return false; } @@ -1005,7 +1005,7 @@ var projections = { start: start, add: add, - get: get + get: get$1 }; var exports$2 = {}; @@ -2398,7 +2398,7 @@ */ var SET_ORIGIN_ROW_LETTERS = 'AFAFAF'; - var A = 65; // A + var A$1 = 65; // A var I = 73; // I var O = 79; // O var V = 86; // V @@ -2801,7 +2801,7 @@ var rollover = false; if (colInt > Z) { - colInt = colInt - Z + A - 1; + colInt = colInt - Z + A$1 - 1; rollover = true; } @@ -2818,11 +2818,11 @@ } if (colInt > Z) { - colInt = colInt - Z + A - 1; + colInt = colInt - Z + A$1 - 1; } if (rowInt > V) { - rowInt = rowInt - V + A - 1; + rowInt = rowInt - V + A$1 - 1; rollover = true; } else { @@ -2842,7 +2842,7 @@ } if (rowInt > V) { - rowInt = rowInt - V + A - 1; + rowInt = rowInt - V + A$1 - 1; } var twoLetter = String.fromCharCode(colInt) + String.fromCharCode(rowInt); @@ -2970,7 +2970,7 @@ if (rewindMarker) { throw ("Bad character: " + e); } - curCol = A; + curCol = A$1; rewindMarker = true; } eastingValue += 100000.0; @@ -3021,7 +3021,7 @@ if (rewindMarker) { // making sure that this loop ends throw ("Bad character: " + n); } - curRow = A; + curRow = A$1; rewindMarker = true; } northingValue += 100000.0; @@ -3202,7 +3202,7 @@ // https://github.com/mbloch/mapshaper-proj/blob/master/src/projections/tmerc.js - function init$u() { + function init$t() { this.x0 = this.x0 !== undefined ? this.x0 : 0; this.y0 = this.y0 !== undefined ? this.y0 : 0; this.long0 = this.long0 !== undefined ? this.long0 : 0; @@ -3359,7 +3359,7 @@ var names$t = ["Fast_Transverse_Mercator", "Fast Transverse Mercator"]; var tmerc = { - init: init$u, + init: init$t, forward: forward$s, inverse: inverse$s, names: names$t @@ -3466,7 +3466,7 @@ // https://github.com/mbloch/mapshaper-proj/blob/master/src/projections/etmerc.js - function init$t() { + function init$s() { if (!this.approx && (isNaN(this.es) || this.es <= 0)) { throw new Error('Incorrect elliptical usage. Try using the +approx option in the proj string, or PROJECTION["Fast_Transverse_Mercator"] in the WKT.'); } @@ -3621,7 +3621,7 @@ var names$s = ["Extended_Transverse_Mercator", "Extended Transverse Mercator", "etmerc", "Transverse_Mercator", "Transverse Mercator", "Gauss Kruger", "Gauss_Kruger", "tmerc"]; var etmerc = { - init: init$t, + init: init$s, forward: forward$r, inverse: inverse$r, names: names$s @@ -3643,7 +3643,7 @@ var dependsOn = 'etmerc'; - function init$s() { + function init$r() { var zone = adjust_zone(this.zone, this.long0); if (zone === undefined) { throw new Error('unknown utm zone'); @@ -3661,7 +3661,7 @@ var names$r = ["Universal Transverse Mercator System", "utm"]; var utm = { - init: init$s, + init: init$r, names: names$r, dependsOn: dependsOn }; @@ -3672,7 +3672,7 @@ var MAX_ITER$2 = 20; - function init$r() { + function init$q() { var sphi = Math.sin(this.lat0); var cphi = Math.cos(this.lat0); cphi *= cphi; @@ -3715,13 +3715,13 @@ var names$q = ["gauss"]; var gauss = { - init: init$r, + init: init$q, forward: forward$q, inverse: inverse$q, names: names$q }; - function init$q() { + function init$p() { gauss.init.apply(this); if (!this.rc) { return; @@ -3777,7 +3777,7 @@ var names$p = ["Stereographic_North_Pole", "Oblique_Stereographic", "sterea","Oblique Stereographic Alternative","Double_Stereographic"]; var sterea = { - init: init$q, + init: init$p, forward: forward$p, inverse: inverse$p, names: names$p @@ -3788,7 +3788,7 @@ return (Math.tan(0.5 * (HALF_PI + phit)) * Math.pow((1 - sinphi) / (1 + sinphi), 0.5 * eccen)); } - function init$p() { + function init$o() { // setting default parameters this.x0 = this.x0 || 0; @@ -3952,7 +3952,7 @@ var names$o = ["stere", "Stereographic_South_Pole", "Polar Stereographic (variant B)", "Polar_Stereographic"]; var stere = { - init: init$p, + init: init$o, forward: forward$o, inverse: inverse$o, names: names$o, @@ -3967,7 +3967,7 @@ http://www.swisstopo.admin.ch/internet/swisstopo/fr/home/topics/survey/sys/refsys/switzerland.parsysrelated1.31216.downloadList.77004.DownloadFile.tmp/swissprojectionfr.pdf */ - function init$o() { + function init$n() { var phy0 = this.lat0; this.lambda0 = this.long0; var sinPhy0 = Math.sin(phy0); @@ -4040,7 +4040,7 @@ var names$n = ["somerc"]; var somerc = { - init: init$o, + init: init$n, forward: forward$n, inverse: inverse$n, names: names$n @@ -4058,7 +4058,7 @@ /* Initialize the Oblique Mercator projection ------------------------------------------*/ - function init$n() { + function init$m() { var con, com, cosph0, D, F, H, L, sinph0, p, J, gamma = 0, gamma0, lamc = 0, lam1 = 0, lam2 = 0, phi1 = 0, phi2 = 0, alpha_c = 0; @@ -4277,13 +4277,13 @@ var names$m = ["Hotine_Oblique_Mercator", "Hotine Oblique Mercator", "Hotine_Oblique_Mercator_Azimuth_Natural_Origin", "Hotine_Oblique_Mercator_Two_Point_Natural_Origin", "Hotine_Oblique_Mercator_Azimuth_Center", "Oblique_Mercator", "omerc"]; var omerc = { - init: init$n, + init: init$m, forward: forward$m, inverse: inverse$m, names: names$m }; - function init$m() { + function init$l() { //double lat0; /* the reference latitude */ //double long0; /* the reference longitude */ @@ -4422,13 +4422,13 @@ ]; var lcc = { - init: init$m, + init: init$l, forward: forward$l, inverse: inverse$l, names: names$l }; - function init$l() { + function init$k() { this.a = 6377397.155; this.es = 0.006674372230614; this.e = Math.sqrt(this.es); @@ -4527,7 +4527,7 @@ var names$k = ["Krovak", "krovak"]; var krovak = { - init: init$l, + init: init$k, forward: forward$k, inverse: inverse$k, names: names$k @@ -4579,7 +4579,7 @@ return NaN; } - function init$k() { + function init$j() { if (!this.sphere) { this.e0 = e0fn(this.es); this.e1 = e1fn(this.es); @@ -4671,7 +4671,7 @@ var names$j = ["Cassini", "Cassini_Soldner", "cass"]; var cass = { - init: init$k, + init: init$j, forward: forward$j, inverse: inverse$j, names: names$j @@ -4702,7 +4702,7 @@ /* Initialize the Lambert Azimuthal Equal Area projection ------------------------------------------------------*/ - function init$j() { + function init$i() { var t = Math.abs(this.lat0); if (Math.abs(t - HALF_PI) < EPSLN) { this.mode = this.lat0 < 0 ? this.S_POLE : this.N_POLE; @@ -4971,7 +4971,7 @@ var names$i = ["Lambert Azimuthal Equal Area", "Lambert_Azimuthal_Equal_Area", "laea"]; var laea = { - init: init$j, + init: init$i, forward: forward$i, inverse: inverse$i, names: names$i, @@ -4988,7 +4988,7 @@ return Math.asin(x); } - function init$i() { + function init$h() { if (Math.abs(this.lat1 + this.lat2) < EPSLN) { return; @@ -5105,7 +5105,7 @@ var names$h = ["Albers_Conic_Equal_Area", "Albers", "aea"]; var aea = { - init: init$i, + init: init$h, forward: forward$h, inverse: inverse$h, names: names$h, @@ -5118,7 +5118,7 @@ http://mathworld.wolfram.com/GnomonicProjection.html Accessed: 12th November 2009 */ - function init$h() { + function init$g() { /* Place parameters in static storage for common use -------------------------------------------------*/ @@ -5207,7 +5207,7 @@ var names$g = ["gnom"]; var gnom = { - init: init$h, + init: init$g, forward: forward$g, inverse: inverse$g, names: names$g @@ -5250,7 +5250,7 @@ A User's Manual" by Gerald I. Evenden, USGS Open File Report 90-284and Release 4 Interim Reports (2003) */ - function init$g() { + function init$f() { //no-op if (!this.sphere) { this.k0 = msfnz(this.e, Math.sin(this.lat_ts), Math.cos(this.lat_ts)); @@ -5304,13 +5304,13 @@ var names$f = ["cea"]; var cea = { - init: init$g, + init: init$f, forward: forward$f, inverse: inverse$f, names: names$f }; - function init$f() { + function init$e() { this.x0 = this.x0 || 0; this.y0 = this.y0 || 0; @@ -5350,7 +5350,7 @@ var names$e = ["Equirectangular", "Equidistant_Cylindrical", "eqc"]; var eqc = { - init: init$f, + init: init$e, forward: forward$e, inverse: inverse$e, names: names$e @@ -5358,7 +5358,7 @@ var MAX_ITER$1 = 20; - function init$e() { + function init$d() { /* Place parameters in static storage for common use -------------------------------------------------*/ this.temp = this.b / this.a; @@ -5476,13 +5476,13 @@ var names$d = ["Polyconic", "poly"]; var poly = { - init: init$e, + init: init$d, forward: forward$d, inverse: inverse$d, names: names$d }; - function init$d() { + function init$c() { this.A = []; this.A[1] = 0.6399175073; this.A[2] = -0.1358797613; @@ -5685,7 +5685,7 @@ var names$c = ["New_Zealand_Map_Grid", "nzmg"]; var nzmg = { - init: init$d, + init: init$c, forward: forward$c, inverse: inverse$c, names: names$c @@ -5700,7 +5700,7 @@ /* Initialize the Miller Cylindrical projection -------------------------------------------*/ - function init$c() { + function init$b() { //no-op } @@ -5736,7 +5736,7 @@ var names$b = ["Miller_Cylindrical", "mill"]; var mill = { - init: init$c, + init: init$b, forward: forward$b, inverse: inverse$b, names: names$b @@ -5745,7 +5745,7 @@ var MAX_ITER = 20; - function init$b() { + function init$a() { /* Place parameters in static storage for common use -------------------------------------------------*/ @@ -5844,13 +5844,13 @@ var names$a = ["Sinusoidal", "sinu"]; var sinu = { - init: init$b, + init: init$a, forward: forward$a, inverse: inverse$a, names: names$a }; - function init$a() {} + function init$9() {} /* Mollweide forward equations--mapping lat,long to x,y ----------------------------------------------------*/ function forward$9(p) { @@ -5926,13 +5926,13 @@ var names$9 = ["Mollweide", "moll"]; var moll = { - init: init$a, + init: init$9, forward: forward$9, inverse: inverse$9, names: names$9 }; - function init$9() { + function init$8() { /* Place parameters in static storage for common use -------------------------------------------------*/ @@ -6033,7 +6033,7 @@ var names$8 = ["Equidistant_Conic", "eqdc"]; var eqdc = { - init: init$9, + init: init$8, forward: forward$8, inverse: inverse$8, names: names$8 @@ -6041,7 +6041,7 @@ /* Initialize the Van Der Grinten projection ----------------------------------------*/ - function init$8() { + function init$7() { //this.R = 6370997; //Radius of earth this.R = this.a; } @@ -6157,13 +6157,13 @@ var names$7 = ["Van_der_Grinten_I", "VanDerGrinten", "vandg"]; var vandg = { - init: init$8, + init: init$7, forward: forward$7, inverse: inverse$7, names: names$7 }; - function init$7() { + function init$6() { this.sin_p12 = Math.sin(this.lat0); this.cos_p12 = Math.cos(this.lat0); } @@ -6352,13 +6352,13 @@ var names$6 = ["Azimuthal_Equidistant", "aeqd"]; var aeqd = { - init: init$7, + init: init$6, forward: forward$6, inverse: inverse$6, names: names$6 }; - function init$6() { + function init$5() { //double temp; /* temporary variable */ /* Place parameters in static storage for common use @@ -6440,7 +6440,7 @@ var names$5 = ["ortho"]; var ortho = { - init: init$6, + init: init$5, forward: forward$5, inverse: inverse$5, names: names$5 @@ -6467,7 +6467,7 @@ AREA_3: 4 }; - function init$5() { + function init$4() { this.x0 = this.x0 || 0; this.y0 = this.y0 || 0; @@ -6807,7 +6807,7 @@ var names$4 = ["Quadrilateralized Spherical Cube", "Quadrilateralized_Spherical_Cube", "qsc"]; var qsc = { - init: init$5, + init: init$4, forward: forward$4, inverse: inverse$4, names: names$4 @@ -6888,7 +6888,7 @@ return x; } - function init$4() { + function init$3() { this.x0 = this.x0 || 0; this.y0 = this.y0 || 0; this.long0 = this.long0 || 0; @@ -6967,13 +6967,13 @@ var names$3 = ["Robinson", "robin"]; var robin = { - init: init$4, + init: init$3, forward: forward$3, inverse: inverse$3, names: names$3 }; - function init$3() { + function init$2() { this.name = 'geocent'; } @@ -6990,7 +6990,7 @@ var names$2 = ["Geocentric", 'geocentric', "geocent", "Geocent"]; var geocent = { - init: init$3, + init: init$2, forward: forward$2, inverse: inverse$2, names: names$2 @@ -7011,7 +7011,7 @@ lat0: { def: 0, num: true } // default is Equator, conversion to rad is automatic }; - function init$2() { + function init$1() { Object.keys(params).forEach(function (p) { if (typeof this[p] === "undefined") { this[p] = params[p].def; @@ -7156,13 +7156,13 @@ var names$1 = ["Tilted_Perspective", "tpers"]; var tpers = { - init: init$2, + init: init$1, forward: forward$1, inverse: inverse$1, names: names$1 }; - function init$1() { + function init() { this.flip_axis = (this.sweep === 'x' ? 1 : 0); this.h = Number(this.h); this.radius_g_1 = this.h / this.a; @@ -7313,7 +7313,7 @@ var names = ["Geostationary Satellite View", "Geostationary_Satellite", "geos"]; var geos = { - init: init$1, + init: init, forward: forward, inverse: inverse, names: names, @@ -7363,2421 +7363,157 @@ proj4.version = '__VERSION__'; includedProjections(proj4); - var global$1 = (typeof global !== "undefined" ? global : - typeof self !== "undefined" ? self : - typeof window !== "undefined" ? window : {}); - - var lookup = []; - var revLookup = []; - var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array; - var inited = false; - function init () { - inited = true; - var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; - for (var i = 0, len = code.length; i < len; ++i) { - lookup[i] = code[i]; - revLookup[code.charCodeAt(i)] = i; - } - - revLookup['-'.charCodeAt(0)] = 62; - revLookup['_'.charCodeAt(0)] = 63; - } + var f,m="deflate-raw",x=self.DecompressionStream;try{new x(m),f=async t=>{let n=new x(m),e=n.writable.getWriter(),i=n.readable.getReader();e.write(t),e.close();let c,o=[],s=0,a=0,l;for(;!(l=await i.read()).done;)c=l.value,o.push(c),s+=c.length;return o.length-1?(c=new Uint8Array(s),o.map(r=>{c.set(r,a),a+=r.length;}),c):o[0]};}catch{}var _=new TextDecoder,h=t=>{throw new Error("but-unzip~"+t)},E=t=>_.decode(t),A=t=>{let n=t.length-20,e=Math.max(n-65516,2);for(;(n=t.lastIndexOf(80,n-1))!==-1&&!(t[n+1]===75&&t[n+2]===5&&t[n+3]===6)&&n>e;);return n};function*C(t,n=f){let e=A(t);e===-1&&h(2);let i=(r,d)=>t.subarray(e+=r,e+=d),c=new DataView(t.buffer,t.byteOffset),o=r=>c.getUint16(r+e,!0),s=r=>c.getUint32(r+e,!0),a=o(10);for(a!==o(8)&&h(3),e=s(16);a--;){let r=o(10),d=o(28),g=o(30),y=o(32),b=s(20),w=s(42),p=E(i(46,d)),D=E(i(g,y)),L=e,u;e=w,u=i(30+o(26)+o(28),b),yield {filename:p,comment:D,read:()=>r&8?n(u):r?h(1):u},e=L;}} - function toByteArray (b64) { - if (!inited) { - init(); + const regex$1 = /.+\.(shp|dbf|json|prj|cpg)$/i; + var unzip = async (buffer) => { + const files = {}; + const proms = []; + for (const entry of C(buffer)) { + if (!regex$1.test(entry.filename)) { + continue; + } + proms.push(Promise.resolve(entry.read()).then(bytes => files[entry.filename] = bytes)); } - var i, j, l, tmp, placeHolders, arr; - var len = b64.length; - - if (len % 4 > 0) { - throw new Error('Invalid string. Length must be a multiple of 4') + await Promise.all(proms); + const out = {}; + const decoder = new TextDecoder(); + for (const [key, value] of Object.entries(files)) { + if (key.slice(-3).toLowerCase() === 'shp' || key.slice(-3).toLowerCase() === 'dbf') { + out[key] = new DataView(value.buffer, value.byteOffset, value.byteLength); + } else { + out[key] = decoder.decode(value); + } } + return out; + }; - // the number of equal signs (place holders) - // if there are two placeholders, than the two characters before it - // represent one byte - // if there is only one, then the three characters before it represent 2 bytes - // this is just a cheap hack to not do indexOf twice - placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0; - - // base64 is 4/3 + up to two characters of the original data - arr = new Arr(len * 3 / 4 - placeHolders); - - // if there are placeholders, only get up to the last complete 4 chars - l = placeHolders > 0 ? len - 4 : len; - - var L = 0; - - for (i = 0, j = 0; i < l; i += 4, j += 3) { - tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]; - arr[L++] = (tmp >> 16) & 0xFF; - arr[L++] = (tmp >> 8) & 0xFF; - arr[L++] = tmp & 0xFF; - } + const URL$1 = globalThis.URL; - if (placeHolders === 2) { - tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4); - arr[L++] = tmp & 0xFF; - } else if (placeHolders === 1) { - tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2); - arr[L++] = (tmp >> 8) & 0xFF; - arr[L++] = tmp & 0xFF; + var combine$1 = (base, type) => { + if (!type) { + return base; } + const url = new URL$1(base); + url.pathname = `${url.pathname}.${type}`; + return url.href; + }; - return arr - } - - function tripletToBase64 (num) { - return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F] - } + async function binaryAjax(_url, type) { - function encodeChunk (uint8, start, end) { - var tmp; - var output = []; - for (var i = start; i < end; i += 3) { - tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]); - output.push(tripletToBase64(tmp)); + const url = combine$1(_url, type); + const isOptionalTxt = type === 'prj' || type === 'cpg'; + try { + const resp = await fetch(url); + if (resp.status > 399) { + throw new Error(resp.statusText); + } + if (isOptionalTxt) { + return resp.text(); + } + const parsed = await resp.arrayBuffer(); + return new DataView(parsed) + } catch (e) { + if (isOptionalTxt || type === 'dbf') { + return false; + } + throw e; } - return output.join('') } - function fromByteArray (uint8) { - if (!inited) { - init(); - } - var tmp; - var len = uint8.length; - var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes - var output = ''; - var parts = []; - var maxChunkLength = 16383; // must be multiple of 3 - - // go through the array every three bytes, we'll deal with trailing stuff later - for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { - parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength))); + function isClockWise(array) { + let sum = 0; + let i = 1; + const len = array.length; + let prev, cur; + const bbox = [array[0][0], array[0][1], array[0][0], array[0][1]]; + while (i < len) { + prev = cur || array[0]; + cur = array[i]; + sum += ((cur[0] - prev[0]) * (cur[1] + prev[1])); + i++; + if (cur[0] < bbox[0]) { + bbox[0] = cur[0]; + } + if (cur[1] < bbox[1]) { + bbox[1] = cur[1]; + } + if (cur[0] > bbox[2]) { + bbox[2] = cur[0]; + } + if (cur[1] > bbox[3]) { + bbox[3] = cur[1]; + } } - - // pad the end with zeros, but make sure to not forget the extra bytes - if (extraBytes === 1) { - tmp = uint8[len - 1]; - output += lookup[tmp >> 2]; - output += lookup[(tmp << 4) & 0x3F]; - output += '=='; - } else if (extraBytes === 2) { - tmp = (uint8[len - 2] << 8) + (uint8[len - 1]); - output += lookup[tmp >> 10]; - output += lookup[(tmp >> 4) & 0x3F]; - output += lookup[(tmp << 2) & 0x3F]; - output += '='; + return { + ring: array, + clockWise: sum > 0, + bbox, + children: [] } - parts.push(output); - - return parts.join('') } - function read (buffer, offset, isLE, mLen, nBytes) { - var e, m; - var eLen = nBytes * 8 - mLen - 1; - var eMax = (1 << eLen) - 1; - var eBias = eMax >> 1; - var nBits = -7; - var i = isLE ? (nBytes - 1) : 0; - var d = isLE ? -1 : 1; - var s = buffer[offset + i]; - - i += d; - - e = s & ((1 << (-nBits)) - 1); - s >>= (-nBits); - nBits += eLen; - for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} - - m = e & ((1 << (-nBits)) - 1); - e >>= (-nBits); - nBits += mLen; - for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} - - if (e === 0) { - e = 1 - eBias; - } else if (e === eMax) { - return m ? NaN : ((s ? -1 : 1) * Infinity) - } else { - m = m + Math.pow(2, mLen); - e = e - eBias; + function contains(outer, inner) { + if (outer.bbox[0] > inner.bbox[0]) { + return false; + } + if (outer.bbox[1] > inner.bbox[1]) { + return false; + } + if (outer.bbox[2] < inner.bbox[2]) { + return false; + } + if (outer.bbox[3] < inner.bbox[3]) { + return false; } - return (s ? -1 : 1) * m * Math.pow(2, e - mLen) + return true; } - function write (buffer, value, offset, isLE, mLen, nBytes) { - var e, m, c; - var eLen = nBytes * 8 - mLen - 1; - var eMax = (1 << eLen) - 1; - var eBias = eMax >> 1; - var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0); - var i = isLE ? 0 : (nBytes - 1); - var d = isLE ? 1 : -1; - var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0; - - value = Math.abs(value); - - if (isNaN(value) || value === Infinity) { - m = isNaN(value) ? 1 : 0; - e = eMax; - } else { - e = Math.floor(Math.log(value) / Math.LN2); - if (value * (c = Math.pow(2, -e)) < 1) { - e--; - c *= 2; - } - if (e + eBias >= 1) { - value += rt / c; + function handleRings(rings) { + const outers = []; + const inners = []; + for (const ring of rings) { + const proccessed = isClockWise(ring); + if (proccessed.clockWise) { + outers.push(proccessed); } else { - value += rt * Math.pow(2, 1 - eBias); - } - if (value * c >= 2) { - e++; - c /= 2; + inners.push(proccessed); } + } + // this is an optimization, + // but it would also put in weird bad rings that would otherwise get left out + // if (outers.length === 1) { + // const out = [outers[0].ring] + // for (const inner of inners) { + // out.push(inner.ring); - if (e + eBias >= eMax) { - m = 0; - e = eMax; - } else if (e + eBias >= 1) { - m = (value * c - 1) * Math.pow(2, mLen); - e = e + eBias; - } else { - m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); - e = 0; + // } + // return [out]; + // } + for (const inner of inners) { + for (const outer of outers) { + if (contains(outer, inner)) { + outer.children.push(inner.ring); + break; + } } } - - for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} - - e = (e << mLen) | m; - eLen += mLen; - for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} - - buffer[offset + i - d] |= s * 128; + const out = []; + for (const outer of outers) { + out.push([outer.ring].concat(outer.children)); + } + return out; } - - var toString$1 = {}.toString; - - var isArray = Array.isArray || function (arr) { - return toString$1.call(arr) == '[object Array]'; - }; - - /*! - * The buffer module from node.js, for the browser. - * - * @author Feross Aboukhadijeh - * @license MIT - */ - - var INSPECT_MAX_BYTES = 50; - - /** - * If `Buffer.TYPED_ARRAY_SUPPORT`: - * === true Use Uint8Array implementation (fastest) - * === false Use Object implementation (most compatible, even IE6) - * - * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, - * Opera 11.6+, iOS 4.2+. - * - * Due to various browser bugs, sometimes the Object implementation will be used even - * when the browser supports typed arrays. - * - * Note: - * - * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, - * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. - * - * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. - * - * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of - * incorrect length in some situations. - - * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they - * get the Object implementation, which is slower but behaves correctly. - */ - Buffer.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined - ? global$1.TYPED_ARRAY_SUPPORT - : true; - - /* - * Export kMaxLength after typed array support is determined. - */ - kMaxLength(); - - function kMaxLength () { - return Buffer.TYPED_ARRAY_SUPPORT - ? 0x7fffffff - : 0x3fffffff - } - - function createBuffer (that, length) { - if (kMaxLength() < length) { - throw new RangeError('Invalid typed array length') - } - if (Buffer.TYPED_ARRAY_SUPPORT) { - // Return an augmented `Uint8Array` instance, for best performance - that = new Uint8Array(length); - that.__proto__ = Buffer.prototype; - } else { - // Fallback: Return an object instance of the Buffer class - if (that === null) { - that = new Buffer(length); - } - that.length = length; - } - - return that - } - - /** - * The Buffer constructor returns instances of `Uint8Array` that have their - * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of - * `Uint8Array`, so the returned instances will have all the node `Buffer` methods - * and the `Uint8Array` methods. Square bracket notation works as expected -- it - * returns a single octet. - * - * The `Uint8Array` prototype remains unmodified. - */ - - function Buffer (arg, encodingOrOffset, length) { - if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { - return new Buffer(arg, encodingOrOffset, length) - } - - // Common case. - if (typeof arg === 'number') { - if (typeof encodingOrOffset === 'string') { - throw new Error( - 'If encoding is specified then the first argument must be a string' - ) - } - return allocUnsafe(this, arg) - } - return from(this, arg, encodingOrOffset, length) - } - - Buffer.poolSize = 8192; // not used by this implementation - - // TODO: Legacy, not needed anymore. Remove in next major version. - Buffer._augment = function (arr) { - arr.__proto__ = Buffer.prototype; - return arr - }; - - function from (that, value, encodingOrOffset, length) { - if (typeof value === 'number') { - throw new TypeError('"value" argument must not be a number') - } - - if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { - return fromArrayBuffer(that, value, encodingOrOffset, length) - } - - if (typeof value === 'string') { - return fromString(that, value, encodingOrOffset) - } - - return fromObject(that, value) - } - - /** - * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError - * if value is a number. - * Buffer.from(str[, encoding]) - * Buffer.from(array) - * Buffer.from(buffer) - * Buffer.from(arrayBuffer[, byteOffset[, length]]) - **/ - Buffer.from = function (value, encodingOrOffset, length) { - return from(null, value, encodingOrOffset, length) - }; - - if (Buffer.TYPED_ARRAY_SUPPORT) { - Buffer.prototype.__proto__ = Uint8Array.prototype; - Buffer.__proto__ = Uint8Array; - } - - function assertSize (size) { - if (typeof size !== 'number') { - throw new TypeError('"size" argument must be a number') - } else if (size < 0) { - throw new RangeError('"size" argument must not be negative') - } - } - - function alloc (that, size, fill, encoding) { - assertSize(size); - if (size <= 0) { - return createBuffer(that, size) - } - if (fill !== undefined) { - // Only pay attention to encoding if it's a string. This - // prevents accidentally sending in a number that would - // be interpretted as a start offset. - return typeof encoding === 'string' - ? createBuffer(that, size).fill(fill, encoding) - : createBuffer(that, size).fill(fill) - } - return createBuffer(that, size) - } - - /** - * Creates a new filled Buffer instance. - * alloc(size[, fill[, encoding]]) - **/ - Buffer.alloc = function (size, fill, encoding) { - return alloc(null, size, fill, encoding) - }; - - function allocUnsafe (that, size) { - assertSize(size); - that = createBuffer(that, size < 0 ? 0 : checked(size) | 0); - if (!Buffer.TYPED_ARRAY_SUPPORT) { - for (var i = 0; i < size; ++i) { - that[i] = 0; - } - } - return that - } - - /** - * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. - * */ - Buffer.allocUnsafe = function (size) { - return allocUnsafe(null, size) - }; - /** - * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. - */ - Buffer.allocUnsafeSlow = function (size) { - return allocUnsafe(null, size) - }; - - function fromString (that, string, encoding) { - if (typeof encoding !== 'string' || encoding === '') { - encoding = 'utf8'; - } - - if (!Buffer.isEncoding(encoding)) { - throw new TypeError('"encoding" must be a valid string encoding') - } - - var length = byteLength(string, encoding) | 0; - that = createBuffer(that, length); - - var actual = that.write(string, encoding); - - if (actual !== length) { - // Writing a hex string, for example, that contains invalid characters will - // cause everything after the first invalid character to be ignored. (e.g. - // 'abxxcd' will be treated as 'ab') - that = that.slice(0, actual); - } - - return that - } - - function fromArrayLike (that, array) { - var length = array.length < 0 ? 0 : checked(array.length) | 0; - that = createBuffer(that, length); - for (var i = 0; i < length; i += 1) { - that[i] = array[i] & 255; - } - return that - } - - function fromArrayBuffer (that, array, byteOffset, length) { - array.byteLength; // this throws if `array` is not a valid ArrayBuffer - - if (byteOffset < 0 || array.byteLength < byteOffset) { - throw new RangeError('\'offset\' is out of bounds') - } - - if (array.byteLength < byteOffset + (length || 0)) { - throw new RangeError('\'length\' is out of bounds') - } - - if (byteOffset === undefined && length === undefined) { - array = new Uint8Array(array); - } else if (length === undefined) { - array = new Uint8Array(array, byteOffset); - } else { - array = new Uint8Array(array, byteOffset, length); - } - - if (Buffer.TYPED_ARRAY_SUPPORT) { - // Return an augmented `Uint8Array` instance, for best performance - that = array; - that.__proto__ = Buffer.prototype; - } else { - // Fallback: Return an object instance of the Buffer class - that = fromArrayLike(that, array); - } - return that - } - - function fromObject (that, obj) { - if (internalIsBuffer(obj)) { - var len = checked(obj.length) | 0; - that = createBuffer(that, len); - - if (that.length === 0) { - return that - } - - obj.copy(that, 0, 0, len); - return that - } - - if (obj) { - if ((typeof ArrayBuffer !== 'undefined' && - obj.buffer instanceof ArrayBuffer) || 'length' in obj) { - if (typeof obj.length !== 'number' || isnan(obj.length)) { - return createBuffer(that, 0) - } - return fromArrayLike(that, obj) - } - - if (obj.type === 'Buffer' && isArray(obj.data)) { - return fromArrayLike(that, obj.data) - } - } - - throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') - } - - function checked (length) { - // Note: cannot use `length < kMaxLength()` here because that fails when - // length is NaN (which is otherwise coerced to zero.) - if (length >= kMaxLength()) { - throw new RangeError('Attempt to allocate Buffer larger than maximum ' + - 'size: 0x' + kMaxLength().toString(16) + ' bytes') - } - return length | 0 - } - Buffer.isBuffer = isBuffer; - function internalIsBuffer (b) { - return !!(b != null && b._isBuffer) - } - - Buffer.compare = function compare (a, b) { - if (!internalIsBuffer(a) || !internalIsBuffer(b)) { - throw new TypeError('Arguments must be Buffers') - } - - if (a === b) return 0 - - var x = a.length; - var y = b.length; - - for (var i = 0, len = Math.min(x, y); i < len; ++i) { - if (a[i] !== b[i]) { - x = a[i]; - y = b[i]; - break - } - } - - if (x < y) return -1 - if (y < x) return 1 - return 0 - }; - - Buffer.isEncoding = function isEncoding (encoding) { - switch (String(encoding).toLowerCase()) { - case 'hex': - case 'utf8': - case 'utf-8': - case 'ascii': - case 'latin1': - case 'binary': - case 'base64': - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return true - default: - return false - } - }; - - Buffer.concat = function concat (list, length) { - if (!isArray(list)) { - throw new TypeError('"list" argument must be an Array of Buffers') - } - - if (list.length === 0) { - return Buffer.alloc(0) - } - - var i; - if (length === undefined) { - length = 0; - for (i = 0; i < list.length; ++i) { - length += list[i].length; - } - } - - var buffer = Buffer.allocUnsafe(length); - var pos = 0; - for (i = 0; i < list.length; ++i) { - var buf = list[i]; - if (!internalIsBuffer(buf)) { - throw new TypeError('"list" argument must be an Array of Buffers') - } - buf.copy(buffer, pos); - pos += buf.length; - } - return buffer - }; - - function byteLength (string, encoding) { - if (internalIsBuffer(string)) { - return string.length - } - if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' && - (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) { - return string.byteLength - } - if (typeof string !== 'string') { - string = '' + string; - } - - var len = string.length; - if (len === 0) return 0 - - // Use a for loop to avoid recursion - var loweredCase = false; - for (;;) { - switch (encoding) { - case 'ascii': - case 'latin1': - case 'binary': - return len - case 'utf8': - case 'utf-8': - case undefined: - return utf8ToBytes(string).length - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return len * 2 - case 'hex': - return len >>> 1 - case 'base64': - return base64ToBytes(string).length - default: - if (loweredCase) return utf8ToBytes(string).length // assume utf8 - encoding = ('' + encoding).toLowerCase(); - loweredCase = true; - } - } - } - Buffer.byteLength = byteLength; - - function slowToString (encoding, start, end) { - var loweredCase = false; - - // No need to verify that "this.length <= MAX_UINT32" since it's a read-only - // property of a typed array. - - // This behaves neither like String nor Uint8Array in that we set start/end - // to their upper/lower bounds if the value passed is out of range. - // undefined is handled specially as per ECMA-262 6th Edition, - // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. - if (start === undefined || start < 0) { - start = 0; - } - // Return early if start > this.length. Done here to prevent potential uint32 - // coercion fail below. - if (start > this.length) { - return '' - } - - if (end === undefined || end > this.length) { - end = this.length; - } - - if (end <= 0) { - return '' - } - - // Force coersion to uint32. This will also coerce falsey/NaN values to 0. - end >>>= 0; - start >>>= 0; - - if (end <= start) { - return '' - } - - if (!encoding) encoding = 'utf8'; - - while (true) { - switch (encoding) { - case 'hex': - return hexSlice(this, start, end) - - case 'utf8': - case 'utf-8': - return utf8Slice(this, start, end) - - case 'ascii': - return asciiSlice(this, start, end) - - case 'latin1': - case 'binary': - return latin1Slice(this, start, end) - - case 'base64': - return base64Slice(this, start, end) - - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return utf16leSlice(this, start, end) - - default: - if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) - encoding = (encoding + '').toLowerCase(); - loweredCase = true; - } - } - } - - // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect - // Buffer instances. - Buffer.prototype._isBuffer = true; - - function swap (b, n, m) { - var i = b[n]; - b[n] = b[m]; - b[m] = i; - } - - Buffer.prototype.swap16 = function swap16 () { - var len = this.length; - if (len % 2 !== 0) { - throw new RangeError('Buffer size must be a multiple of 16-bits') - } - for (var i = 0; i < len; i += 2) { - swap(this, i, i + 1); - } - return this - }; - - Buffer.prototype.swap32 = function swap32 () { - var len = this.length; - if (len % 4 !== 0) { - throw new RangeError('Buffer size must be a multiple of 32-bits') - } - for (var i = 0; i < len; i += 4) { - swap(this, i, i + 3); - swap(this, i + 1, i + 2); - } - return this - }; - - Buffer.prototype.swap64 = function swap64 () { - var len = this.length; - if (len % 8 !== 0) { - throw new RangeError('Buffer size must be a multiple of 64-bits') - } - for (var i = 0; i < len; i += 8) { - swap(this, i, i + 7); - swap(this, i + 1, i + 6); - swap(this, i + 2, i + 5); - swap(this, i + 3, i + 4); - } - return this - }; - - Buffer.prototype.toString = function toString () { - var length = this.length | 0; - if (length === 0) return '' - if (arguments.length === 0) return utf8Slice(this, 0, length) - return slowToString.apply(this, arguments) - }; - - Buffer.prototype.equals = function equals (b) { - if (!internalIsBuffer(b)) throw new TypeError('Argument must be a Buffer') - if (this === b) return true - return Buffer.compare(this, b) === 0 - }; - - Buffer.prototype.inspect = function inspect () { - var str = ''; - var max = INSPECT_MAX_BYTES; - if (this.length > 0) { - str = this.toString('hex', 0, max).match(/.{2}/g).join(' '); - if (this.length > max) str += ' ... '; - } - return '' - }; - - Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { - if (!internalIsBuffer(target)) { - throw new TypeError('Argument must be a Buffer') - } - - if (start === undefined) { - start = 0; - } - if (end === undefined) { - end = target ? target.length : 0; - } - if (thisStart === undefined) { - thisStart = 0; - } - if (thisEnd === undefined) { - thisEnd = this.length; - } - - if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { - throw new RangeError('out of range index') - } - - if (thisStart >= thisEnd && start >= end) { - return 0 - } - if (thisStart >= thisEnd) { - return -1 - } - if (start >= end) { - return 1 - } - - start >>>= 0; - end >>>= 0; - thisStart >>>= 0; - thisEnd >>>= 0; - - if (this === target) return 0 - - var x = thisEnd - thisStart; - var y = end - start; - var len = Math.min(x, y); - - var thisCopy = this.slice(thisStart, thisEnd); - var targetCopy = target.slice(start, end); - - for (var i = 0; i < len; ++i) { - if (thisCopy[i] !== targetCopy[i]) { - x = thisCopy[i]; - y = targetCopy[i]; - break - } - } - - if (x < y) return -1 - if (y < x) return 1 - return 0 - }; - - // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, - // OR the last index of `val` in `buffer` at offset <= `byteOffset`. - // - // Arguments: - // - buffer - a Buffer to search - // - val - a string, Buffer, or number - // - byteOffset - an index into `buffer`; will be clamped to an int32 - // - encoding - an optional encoding, relevant is val is a string - // - dir - true for indexOf, false for lastIndexOf - function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { - // Empty buffer means no match - if (buffer.length === 0) return -1 - - // Normalize byteOffset - if (typeof byteOffset === 'string') { - encoding = byteOffset; - byteOffset = 0; - } else if (byteOffset > 0x7fffffff) { - byteOffset = 0x7fffffff; - } else if (byteOffset < -0x80000000) { - byteOffset = -0x80000000; - } - byteOffset = +byteOffset; // Coerce to Number. - if (isNaN(byteOffset)) { - // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer - byteOffset = dir ? 0 : (buffer.length - 1); - } - - // Normalize byteOffset: negative offsets start from the end of the buffer - if (byteOffset < 0) byteOffset = buffer.length + byteOffset; - if (byteOffset >= buffer.length) { - if (dir) return -1 - else byteOffset = buffer.length - 1; - } else if (byteOffset < 0) { - if (dir) byteOffset = 0; - else return -1 - } - - // Normalize val - if (typeof val === 'string') { - val = Buffer.from(val, encoding); - } - - // Finally, search either indexOf (if dir is true) or lastIndexOf - if (internalIsBuffer(val)) { - // Special case: looking for empty string/buffer always fails - if (val.length === 0) { - return -1 - } - return arrayIndexOf(buffer, val, byteOffset, encoding, dir) - } else if (typeof val === 'number') { - val = val & 0xFF; // Search for a byte value [0-255] - if (Buffer.TYPED_ARRAY_SUPPORT && - typeof Uint8Array.prototype.indexOf === 'function') { - if (dir) { - return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) - } else { - return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) - } - } - return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir) - } - - throw new TypeError('val must be string, number or Buffer') - } - - function arrayIndexOf (arr, val, byteOffset, encoding, dir) { - var indexSize = 1; - var arrLength = arr.length; - var valLength = val.length; - - if (encoding !== undefined) { - encoding = String(encoding).toLowerCase(); - if (encoding === 'ucs2' || encoding === 'ucs-2' || - encoding === 'utf16le' || encoding === 'utf-16le') { - if (arr.length < 2 || val.length < 2) { - return -1 - } - indexSize = 2; - arrLength /= 2; - valLength /= 2; - byteOffset /= 2; - } - } - - function read (buf, i) { - if (indexSize === 1) { - return buf[i] - } else { - return buf.readUInt16BE(i * indexSize) - } - } - - var i; - if (dir) { - var foundIndex = -1; - for (i = byteOffset; i < arrLength; i++) { - if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { - if (foundIndex === -1) foundIndex = i; - if (i - foundIndex + 1 === valLength) return foundIndex * indexSize - } else { - if (foundIndex !== -1) i -= i - foundIndex; - foundIndex = -1; - } - } - } else { - if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength; - for (i = byteOffset; i >= 0; i--) { - var found = true; - for (var j = 0; j < valLength; j++) { - if (read(arr, i + j) !== read(val, j)) { - found = false; - break - } - } - if (found) return i - } - } - - return -1 - } - - Buffer.prototype.includes = function includes (val, byteOffset, encoding) { - return this.indexOf(val, byteOffset, encoding) !== -1 - }; - - Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) { - return bidirectionalIndexOf(this, val, byteOffset, encoding, true) - }; - - Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) { - return bidirectionalIndexOf(this, val, byteOffset, encoding, false) - }; - - function hexWrite (buf, string, offset, length) { - offset = Number(offset) || 0; - var remaining = buf.length - offset; - if (!length) { - length = remaining; - } else { - length = Number(length); - if (length > remaining) { - length = remaining; - } - } - - // must be an even number of digits - var strLen = string.length; - if (strLen % 2 !== 0) throw new TypeError('Invalid hex string') - - if (length > strLen / 2) { - length = strLen / 2; - } - for (var i = 0; i < length; ++i) { - var parsed = parseInt(string.substr(i * 2, 2), 16); - if (isNaN(parsed)) return i - buf[offset + i] = parsed; - } - return i - } - - function utf8Write (buf, string, offset, length) { - return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) - } - - function asciiWrite (buf, string, offset, length) { - return blitBuffer(asciiToBytes(string), buf, offset, length) - } - - function latin1Write (buf, string, offset, length) { - return asciiWrite(buf, string, offset, length) - } - - function base64Write (buf, string, offset, length) { - return blitBuffer(base64ToBytes(string), buf, offset, length) - } - - function ucs2Write (buf, string, offset, length) { - return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) - } - - Buffer.prototype.write = function write (string, offset, length, encoding) { - // Buffer#write(string) - if (offset === undefined) { - encoding = 'utf8'; - length = this.length; - offset = 0; - // Buffer#write(string, encoding) - } else if (length === undefined && typeof offset === 'string') { - encoding = offset; - length = this.length; - offset = 0; - // Buffer#write(string, offset[, length][, encoding]) - } else if (isFinite(offset)) { - offset = offset | 0; - if (isFinite(length)) { - length = length | 0; - if (encoding === undefined) encoding = 'utf8'; - } else { - encoding = length; - length = undefined; - } - // legacy write(string, encoding, offset, length) - remove in v0.13 - } else { - throw new Error( - 'Buffer.write(string, encoding, offset[, length]) is no longer supported' - ) - } - - var remaining = this.length - offset; - if (length === undefined || length > remaining) length = remaining; - - if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { - throw new RangeError('Attempt to write outside buffer bounds') - } - - if (!encoding) encoding = 'utf8'; - - var loweredCase = false; - for (;;) { - switch (encoding) { - case 'hex': - return hexWrite(this, string, offset, length) - - case 'utf8': - case 'utf-8': - return utf8Write(this, string, offset, length) - - case 'ascii': - return asciiWrite(this, string, offset, length) - - case 'latin1': - case 'binary': - return latin1Write(this, string, offset, length) - - case 'base64': - // Warning: maxLength not taken into account in base64Write - return base64Write(this, string, offset, length) - - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return ucs2Write(this, string, offset, length) - - default: - if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) - encoding = ('' + encoding).toLowerCase(); - loweredCase = true; - } - } - }; - - Buffer.prototype.toJSON = function toJSON () { - return { - type: 'Buffer', - data: Array.prototype.slice.call(this._arr || this, 0) - } - }; - - function base64Slice (buf, start, end) { - if (start === 0 && end === buf.length) { - return fromByteArray(buf) - } else { - return fromByteArray(buf.slice(start, end)) - } - } - - function utf8Slice (buf, start, end) { - end = Math.min(buf.length, end); - var res = []; - - var i = start; - while (i < end) { - var firstByte = buf[i]; - var codePoint = null; - var bytesPerSequence = (firstByte > 0xEF) ? 4 - : (firstByte > 0xDF) ? 3 - : (firstByte > 0xBF) ? 2 - : 1; - - if (i + bytesPerSequence <= end) { - var secondByte, thirdByte, fourthByte, tempCodePoint; - - switch (bytesPerSequence) { - case 1: - if (firstByte < 0x80) { - codePoint = firstByte; - } - break - case 2: - secondByte = buf[i + 1]; - if ((secondByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F); - if (tempCodePoint > 0x7F) { - codePoint = tempCodePoint; - } - } - break - case 3: - secondByte = buf[i + 1]; - thirdByte = buf[i + 2]; - if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F); - if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { - codePoint = tempCodePoint; - } - } - break - case 4: - secondByte = buf[i + 1]; - thirdByte = buf[i + 2]; - fourthByte = buf[i + 3]; - if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F); - if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { - codePoint = tempCodePoint; - } - } - } - } - - if (codePoint === null) { - // we did not generate a valid codePoint so insert a - // replacement char (U+FFFD) and advance only 1 byte - codePoint = 0xFFFD; - bytesPerSequence = 1; - } else if (codePoint > 0xFFFF) { - // encode to utf16 (surrogate pair dance) - codePoint -= 0x10000; - res.push(codePoint >>> 10 & 0x3FF | 0xD800); - codePoint = 0xDC00 | codePoint & 0x3FF; - } - - res.push(codePoint); - i += bytesPerSequence; - } - - return decodeCodePointsArray(res) - } - - // Based on http://stackoverflow.com/a/22747272/680742, the browser with - // the lowest limit is Chrome, with 0x10000 args. - // We go 1 magnitude less, for safety - var MAX_ARGUMENTS_LENGTH = 0x1000; - - function decodeCodePointsArray (codePoints) { - var len = codePoints.length; - if (len <= MAX_ARGUMENTS_LENGTH) { - return String.fromCharCode.apply(String, codePoints) // avoid extra slice() - } - - // Decode in chunks to avoid "call stack size exceeded". - var res = ''; - var i = 0; - while (i < len) { - res += String.fromCharCode.apply( - String, - codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) - ); - } - return res - } - - function asciiSlice (buf, start, end) { - var ret = ''; - end = Math.min(buf.length, end); - - for (var i = start; i < end; ++i) { - ret += String.fromCharCode(buf[i] & 0x7F); - } - return ret - } - - function latin1Slice (buf, start, end) { - var ret = ''; - end = Math.min(buf.length, end); - - for (var i = start; i < end; ++i) { - ret += String.fromCharCode(buf[i]); - } - return ret - } - - function hexSlice (buf, start, end) { - var len = buf.length; - - if (!start || start < 0) start = 0; - if (!end || end < 0 || end > len) end = len; - - var out = ''; - for (var i = start; i < end; ++i) { - out += toHex(buf[i]); - } - return out - } - - function utf16leSlice (buf, start, end) { - var bytes = buf.slice(start, end); - var res = ''; - for (var i = 0; i < bytes.length; i += 2) { - res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256); - } - return res - } - - Buffer.prototype.slice = function slice (start, end) { - var len = this.length; - start = ~~start; - end = end === undefined ? len : ~~end; - - if (start < 0) { - start += len; - if (start < 0) start = 0; - } else if (start > len) { - start = len; - } - - if (end < 0) { - end += len; - if (end < 0) end = 0; - } else if (end > len) { - end = len; - } - - if (end < start) end = start; - - var newBuf; - if (Buffer.TYPED_ARRAY_SUPPORT) { - newBuf = this.subarray(start, end); - newBuf.__proto__ = Buffer.prototype; - } else { - var sliceLen = end - start; - newBuf = new Buffer(sliceLen, undefined); - for (var i = 0; i < sliceLen; ++i) { - newBuf[i] = this[i + start]; - } - } - - return newBuf - }; - - /* - * Need to make sure that buffer isn't trying to write out of bounds. - */ - function checkOffset (offset, ext, length) { - if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') - if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') - } - - Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { - offset = offset | 0; - byteLength = byteLength | 0; - if (!noAssert) checkOffset(offset, byteLength, this.length); - - var val = this[offset]; - var mul = 1; - var i = 0; - while (++i < byteLength && (mul *= 0x100)) { - val += this[offset + i] * mul; - } - - return val - }; - - Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { - offset = offset | 0; - byteLength = byteLength | 0; - if (!noAssert) { - checkOffset(offset, byteLength, this.length); - } - - var val = this[offset + --byteLength]; - var mul = 1; - while (byteLength > 0 && (mul *= 0x100)) { - val += this[offset + --byteLength] * mul; - } - - return val - }; - - Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { - if (!noAssert) checkOffset(offset, 1, this.length); - return this[offset] - }; - - Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length); - return this[offset] | (this[offset + 1] << 8) - }; - - Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length); - return (this[offset] << 8) | this[offset + 1] - }; - - Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length); - - return ((this[offset]) | - (this[offset + 1] << 8) | - (this[offset + 2] << 16)) + - (this[offset + 3] * 0x1000000) - }; - - Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length); - - return (this[offset] * 0x1000000) + - ((this[offset + 1] << 16) | - (this[offset + 2] << 8) | - this[offset + 3]) - }; - - Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { - offset = offset | 0; - byteLength = byteLength | 0; - if (!noAssert) checkOffset(offset, byteLength, this.length); - - var val = this[offset]; - var mul = 1; - var i = 0; - while (++i < byteLength && (mul *= 0x100)) { - val += this[offset + i] * mul; - } - mul *= 0x80; - - if (val >= mul) val -= Math.pow(2, 8 * byteLength); - - return val - }; - - Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { - offset = offset | 0; - byteLength = byteLength | 0; - if (!noAssert) checkOffset(offset, byteLength, this.length); - - var i = byteLength; - var mul = 1; - var val = this[offset + --i]; - while (i > 0 && (mul *= 0x100)) { - val += this[offset + --i] * mul; - } - mul *= 0x80; - - if (val >= mul) val -= Math.pow(2, 8 * byteLength); - - return val - }; - - Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { - if (!noAssert) checkOffset(offset, 1, this.length); - if (!(this[offset] & 0x80)) return (this[offset]) - return ((0xff - this[offset] + 1) * -1) - }; - - Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length); - var val = this[offset] | (this[offset + 1] << 8); - return (val & 0x8000) ? val | 0xFFFF0000 : val - }; - - Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length); - var val = this[offset + 1] | (this[offset] << 8); - return (val & 0x8000) ? val | 0xFFFF0000 : val - }; - - Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length); - - return (this[offset]) | - (this[offset + 1] << 8) | - (this[offset + 2] << 16) | - (this[offset + 3] << 24) - }; - - Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length); - - return (this[offset] << 24) | - (this[offset + 1] << 16) | - (this[offset + 2] << 8) | - (this[offset + 3]) - }; - - Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length); - return read(this, offset, true, 23, 4) - }; - - Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length); - return read(this, offset, false, 23, 4) - }; - - Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 8, this.length); - return read(this, offset, true, 52, 8) - }; - - Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 8, this.length); - return read(this, offset, false, 52, 8) - }; - - function checkInt (buf, value, offset, ext, max, min) { - if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance') - if (value > max || value < min) throw new RangeError('"value" argument is out of bounds') - if (offset + ext > buf.length) throw new RangeError('Index out of range') - } - - Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { - value = +value; - offset = offset | 0; - byteLength = byteLength | 0; - if (!noAssert) { - var maxBytes = Math.pow(2, 8 * byteLength) - 1; - checkInt(this, value, offset, byteLength, maxBytes, 0); - } - - var mul = 1; - var i = 0; - this[offset] = value & 0xFF; - while (++i < byteLength && (mul *= 0x100)) { - this[offset + i] = (value / mul) & 0xFF; - } - - return offset + byteLength - }; - - Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { - value = +value; - offset = offset | 0; - byteLength = byteLength | 0; - if (!noAssert) { - var maxBytes = Math.pow(2, 8 * byteLength) - 1; - checkInt(this, value, offset, byteLength, maxBytes, 0); - } - - var i = byteLength - 1; - var mul = 1; - this[offset + i] = value & 0xFF; - while (--i >= 0 && (mul *= 0x100)) { - this[offset + i] = (value / mul) & 0xFF; - } - - return offset + byteLength - }; - - Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0); - if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value); - this[offset] = (value & 0xff); - return offset + 1 - }; - - function objectWriteUInt16 (buf, value, offset, littleEndian) { - if (value < 0) value = 0xffff + value + 1; - for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) { - buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> - (littleEndian ? i : 1 - i) * 8; - } - } - - Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0); - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff); - this[offset + 1] = (value >>> 8); - } else { - objectWriteUInt16(this, value, offset, true); - } - return offset + 2 - }; - - Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0); - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 8); - this[offset + 1] = (value & 0xff); - } else { - objectWriteUInt16(this, value, offset, false); - } - return offset + 2 - }; - - function objectWriteUInt32 (buf, value, offset, littleEndian) { - if (value < 0) value = 0xffffffff + value + 1; - for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) { - buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff; - } - } - - Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0); - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset + 3] = (value >>> 24); - this[offset + 2] = (value >>> 16); - this[offset + 1] = (value >>> 8); - this[offset] = (value & 0xff); - } else { - objectWriteUInt32(this, value, offset, true); - } - return offset + 4 - }; - - Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0); - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 24); - this[offset + 1] = (value >>> 16); - this[offset + 2] = (value >>> 8); - this[offset + 3] = (value & 0xff); - } else { - objectWriteUInt32(this, value, offset, false); - } - return offset + 4 - }; - - Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1); - - checkInt(this, value, offset, byteLength, limit - 1, -limit); - } - - var i = 0; - var mul = 1; - var sub = 0; - this[offset] = value & 0xFF; - while (++i < byteLength && (mul *= 0x100)) { - if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { - sub = 1; - } - this[offset + i] = ((value / mul) >> 0) - sub & 0xFF; - } - - return offset + byteLength - }; - - Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1); - - checkInt(this, value, offset, byteLength, limit - 1, -limit); - } - - var i = byteLength - 1; - var mul = 1; - var sub = 0; - this[offset + i] = value & 0xFF; - while (--i >= 0 && (mul *= 0x100)) { - if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { - sub = 1; - } - this[offset + i] = ((value / mul) >> 0) - sub & 0xFF; - } - - return offset + byteLength - }; - - Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80); - if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value); - if (value < 0) value = 0xff + value + 1; - this[offset] = (value & 0xff); - return offset + 1 - }; - - Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000); - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff); - this[offset + 1] = (value >>> 8); - } else { - objectWriteUInt16(this, value, offset, true); - } - return offset + 2 - }; - - Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000); - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 8); - this[offset + 1] = (value & 0xff); - } else { - objectWriteUInt16(this, value, offset, false); - } - return offset + 2 - }; - - Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000); - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff); - this[offset + 1] = (value >>> 8); - this[offset + 2] = (value >>> 16); - this[offset + 3] = (value >>> 24); - } else { - objectWriteUInt32(this, value, offset, true); - } - return offset + 4 - }; - - Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { - value = +value; - offset = offset | 0; - if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000); - if (value < 0) value = 0xffffffff + value + 1; - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 24); - this[offset + 1] = (value >>> 16); - this[offset + 2] = (value >>> 8); - this[offset + 3] = (value & 0xff); - } else { - objectWriteUInt32(this, value, offset, false); - } - return offset + 4 - }; - - function checkIEEE754 (buf, value, offset, ext, max, min) { - if (offset + ext > buf.length) throw new RangeError('Index out of range') - if (offset < 0) throw new RangeError('Index out of range') - } - - function writeFloat (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - checkIEEE754(buf, value, offset, 4); - } - write(buf, value, offset, littleEndian, 23, 4); - return offset + 4 - } - - Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { - return writeFloat(this, value, offset, true, noAssert) - }; - - Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { - return writeFloat(this, value, offset, false, noAssert) - }; - - function writeDouble (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - checkIEEE754(buf, value, offset, 8); - } - write(buf, value, offset, littleEndian, 52, 8); - return offset + 8 - } - - Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { - return writeDouble(this, value, offset, true, noAssert) - }; - - Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { - return writeDouble(this, value, offset, false, noAssert) - }; - - // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) - Buffer.prototype.copy = function copy (target, targetStart, start, end) { - if (!start) start = 0; - if (!end && end !== 0) end = this.length; - if (targetStart >= target.length) targetStart = target.length; - if (!targetStart) targetStart = 0; - if (end > 0 && end < start) end = start; - - // Copy 0 bytes; we're done - if (end === start) return 0 - if (target.length === 0 || this.length === 0) return 0 - - // Fatal error conditions - if (targetStart < 0) { - throw new RangeError('targetStart out of bounds') - } - if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') - if (end < 0) throw new RangeError('sourceEnd out of bounds') - - // Are we oob? - if (end > this.length) end = this.length; - if (target.length - targetStart < end - start) { - end = target.length - targetStart + start; - } - - var len = end - start; - var i; - - if (this === target && start < targetStart && targetStart < end) { - // descending copy from end - for (i = len - 1; i >= 0; --i) { - target[i + targetStart] = this[i + start]; - } - } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { - // ascending copy from start - for (i = 0; i < len; ++i) { - target[i + targetStart] = this[i + start]; - } - } else { - Uint8Array.prototype.set.call( - target, - this.subarray(start, start + len), - targetStart - ); - } - - return len - }; - - // Usage: - // buffer.fill(number[, offset[, end]]) - // buffer.fill(buffer[, offset[, end]]) - // buffer.fill(string[, offset[, end]][, encoding]) - Buffer.prototype.fill = function fill (val, start, end, encoding) { - // Handle string cases: - if (typeof val === 'string') { - if (typeof start === 'string') { - encoding = start; - start = 0; - end = this.length; - } else if (typeof end === 'string') { - encoding = end; - end = this.length; - } - if (val.length === 1) { - var code = val.charCodeAt(0); - if (code < 256) { - val = code; - } - } - if (encoding !== undefined && typeof encoding !== 'string') { - throw new TypeError('encoding must be a string') - } - if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { - throw new TypeError('Unknown encoding: ' + encoding) - } - } else if (typeof val === 'number') { - val = val & 255; - } - - // Invalid ranges are not set to a default, so can range check early. - if (start < 0 || this.length < start || this.length < end) { - throw new RangeError('Out of range index') - } - - if (end <= start) { - return this - } - - start = start >>> 0; - end = end === undefined ? this.length : end >>> 0; - - if (!val) val = 0; - - var i; - if (typeof val === 'number') { - for (i = start; i < end; ++i) { - this[i] = val; - } - } else { - var bytes = internalIsBuffer(val) - ? val - : utf8ToBytes(new Buffer(val, encoding).toString()); - var len = bytes.length; - for (i = 0; i < end - start; ++i) { - this[i + start] = bytes[i % len]; - } - } - - return this - }; - - // HELPER FUNCTIONS - // ================ - - var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g; - - function base64clean (str) { - // Node strips out invalid characters like \n and \t from the string, base64-js does not - str = stringtrim(str).replace(INVALID_BASE64_RE, ''); - // Node converts strings with length < 2 to '' - if (str.length < 2) return '' - // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not - while (str.length % 4 !== 0) { - str = str + '='; - } - return str - } - - function stringtrim (str) { - if (str.trim) return str.trim() - return str.replace(/^\s+|\s+$/g, '') - } - - function toHex (n) { - if (n < 16) return '0' + n.toString(16) - return n.toString(16) - } - - function utf8ToBytes (string, units) { - units = units || Infinity; - var codePoint; - var length = string.length; - var leadSurrogate = null; - var bytes = []; - - for (var i = 0; i < length; ++i) { - codePoint = string.charCodeAt(i); - - // is surrogate component - if (codePoint > 0xD7FF && codePoint < 0xE000) { - // last char was a lead - if (!leadSurrogate) { - // no lead yet - if (codePoint > 0xDBFF) { - // unexpected trail - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); - continue - } else if (i + 1 === length) { - // unpaired lead - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); - continue - } - - // valid lead - leadSurrogate = codePoint; - - continue - } - - // 2 leads in a row - if (codePoint < 0xDC00) { - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); - leadSurrogate = codePoint; - continue - } - - // valid surrogate pair - codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000; - } else if (leadSurrogate) { - // valid bmp char, but last char was a lead - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); - } - - leadSurrogate = null; - - // encode utf8 - if (codePoint < 0x80) { - if ((units -= 1) < 0) break - bytes.push(codePoint); - } else if (codePoint < 0x800) { - if ((units -= 2) < 0) break - bytes.push( - codePoint >> 0x6 | 0xC0, - codePoint & 0x3F | 0x80 - ); - } else if (codePoint < 0x10000) { - if ((units -= 3) < 0) break - bytes.push( - codePoint >> 0xC | 0xE0, - codePoint >> 0x6 & 0x3F | 0x80, - codePoint & 0x3F | 0x80 - ); - } else if (codePoint < 0x110000) { - if ((units -= 4) < 0) break - bytes.push( - codePoint >> 0x12 | 0xF0, - codePoint >> 0xC & 0x3F | 0x80, - codePoint >> 0x6 & 0x3F | 0x80, - codePoint & 0x3F | 0x80 - ); - } else { - throw new Error('Invalid code point') - } - } - - return bytes - } - - function asciiToBytes (str) { - var byteArray = []; - for (var i = 0; i < str.length; ++i) { - // Node's code seems to be doing this and not & 0x7F.. - byteArray.push(str.charCodeAt(i) & 0xFF); - } - return byteArray - } - - function utf16leToBytes (str, units) { - var c, hi, lo; - var byteArray = []; - for (var i = 0; i < str.length; ++i) { - if ((units -= 2) < 0) break - - c = str.charCodeAt(i); - hi = c >> 8; - lo = c % 256; - byteArray.push(lo); - byteArray.push(hi); - } - - return byteArray - } - - - function base64ToBytes (str) { - return toByteArray(base64clean(str)) - } - - function blitBuffer (src, dst, offset, length) { - for (var i = 0; i < length; ++i) { - if ((i + offset >= dst.length) || (i >= src.length)) break - dst[i + offset] = src[i]; - } - return i - } - - function isnan (val) { - return val !== val // eslint-disable-line no-self-compare - } - - - // the following is from is-buffer, also by Feross Aboukhadijeh and with same lisence - // The _isBuffer check is for Safari 5-7 support, because it's missing - // Object.prototype.constructor. Remove this eventually - function isBuffer(obj) { - return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj)) - } - - function isFastBuffer (obj) { - return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj) - } - - // For Node v0.10 support. Remove this eventually. - function isSlowBuffer (obj) { - return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isFastBuffer(obj.slice(0, 0)) - } - - // shim for using process in browser - // based off https://github.com/defunctzombie/node-process/blob/master/browser.js - - function defaultSetTimout() { - throw new Error('setTimeout has not been defined'); - } - function defaultClearTimeout () { - throw new Error('clearTimeout has not been defined'); - } - var cachedSetTimeout = defaultSetTimout; - var cachedClearTimeout = defaultClearTimeout; - if (typeof global$1.setTimeout === 'function') { - cachedSetTimeout = setTimeout; - } - if (typeof global$1.clearTimeout === 'function') { - cachedClearTimeout = clearTimeout; - } - - function runTimeout(fun) { - if (cachedSetTimeout === setTimeout) { - //normal enviroments in sane situations - return setTimeout(fun, 0); - } - // if setTimeout wasn't available but was latter defined - if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { - cachedSetTimeout = setTimeout; - return setTimeout(fun, 0); - } - try { - // when when somebody has screwed with setTimeout but no I.E. maddness - return cachedSetTimeout(fun, 0); - } catch(e){ - try { - // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally - return cachedSetTimeout.call(null, fun, 0); - } catch(e){ - // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error - return cachedSetTimeout.call(this, fun, 0); - } - } - - - } - function runClearTimeout(marker) { - if (cachedClearTimeout === clearTimeout) { - //normal enviroments in sane situations - return clearTimeout(marker); - } - // if clearTimeout wasn't available but was latter defined - if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { - cachedClearTimeout = clearTimeout; - return clearTimeout(marker); - } - try { - // when when somebody has screwed with setTimeout but no I.E. maddness - return cachedClearTimeout(marker); - } catch (e){ - try { - // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally - return cachedClearTimeout.call(null, marker); - } catch (e){ - // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. - // Some versions of I.E. have different rules for clearTimeout vs setTimeout - return cachedClearTimeout.call(this, marker); - } - } - - - - } - var queue = []; - var draining = false; - var currentQueue; - var queueIndex = -1; - - function cleanUpNextTick() { - if (!draining || !currentQueue) { - return; - } - draining = false; - if (currentQueue.length) { - queue = currentQueue.concat(queue); - } else { - queueIndex = -1; - } - if (queue.length) { - drainQueue(); - } - } - - function drainQueue() { - if (draining) { - return; - } - var timeout = runTimeout(cleanUpNextTick); - draining = true; - - var len = queue.length; - while(len) { - currentQueue = queue; - queue = []; - while (++queueIndex < len) { - if (currentQueue) { - currentQueue[queueIndex].run(); - } - } - queueIndex = -1; - len = queue.length; - } - currentQueue = null; - draining = false; - runClearTimeout(timeout); - } - function nextTick(fun) { - var args = new Array(arguments.length - 1); - if (arguments.length > 1) { - for (var i = 1; i < arguments.length; i++) { - args[i - 1] = arguments[i]; - } - } - queue.push(new Item(fun, args)); - if (queue.length === 1 && !draining) { - runTimeout(drainQueue); - } - } - // v8 likes predictible objects - function Item(fun, array) { - this.fun = fun; - this.array = array; - } - Item.prototype.run = function () { - this.fun.apply(null, this.array); - }; - var title = 'browser'; - var platform = 'browser'; - var browser = true; - var env = {}; - var argv = []; - var version = ''; // empty string to avoid regexp issues - var versions = {}; - var release = {}; - var config$1 = {}; - - function noop() {} - - var on = noop; - var addListener = noop; - var once = noop; - var off = noop; - var removeListener = noop; - var removeAllListeners = noop; - var emit = noop; - - function binding(name) { - throw new Error('process.binding is not supported'); - } - - function cwd () { return '/' } - function chdir (dir) { - throw new Error('process.chdir is not supported'); - }function umask() { return 0; } - - // from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js - var performance = global$1.performance || {}; - var performanceNow = - performance.now || - performance.mozNow || - performance.msNow || - performance.oNow || - performance.webkitNow || - function(){ return (new Date()).getTime() }; - - // generate timestamp or delta - // see http://nodejs.org/api/process.html#process_process_hrtime - function hrtime(previousTimestamp){ - var clocktime = performanceNow.call(performance)*1e-3; - var seconds = Math.floor(clocktime); - var nanoseconds = Math.floor((clocktime%1)*1e9); - if (previousTimestamp) { - seconds = seconds - previousTimestamp[0]; - nanoseconds = nanoseconds - previousTimestamp[1]; - if (nanoseconds<0) { - seconds--; - nanoseconds += 1e9; - } - } - return [seconds,nanoseconds] - } - - var startTime = new Date(); - function uptime() { - var currentTime = new Date(); - var dif = currentTime - startTime; - return dif / 1000; - } - - var browser$1 = { - nextTick: nextTick, - title: title, - browser: browser, - env: env, - argv: argv, - version: version, - versions: versions, - on: on, - addListener: addListener, - once: once, - off: off, - removeListener: removeListener, - removeAllListeners: removeAllListeners, - emit: emit, - binding: binding, - cwd: cwd, - chdir: chdir, - umask: umask, - hrtime: hrtime, - platform: platform, - release: release, - config: config$1, - uptime: uptime - }; - - var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; - - function getDefaultExportFromCjs (x) { - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; - } - - function getAugmentedNamespace(n) { - if (n.__esModule) return n; - var f = n.default; - if (typeof f == "function") { - var a = function a () { - if (this instanceof a) { - return Reflect.construct(f, arguments, this.constructor); - } - return f.apply(this, arguments); - }; - a.prototype = f.prototype; - } else a = {}; - Object.defineProperty(a, '__esModule', {value: true}); - Object.keys(n).forEach(function (k) { - var d = Object.getOwnPropertyDescriptor(n, k); - Object.defineProperty(a, k, d.get ? d : { - enumerable: true, - get: function () { - return n[k]; - } - }); - }); - return a; - } - - function commonjsRequire(path) { - throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.'); - } - - var jszip_min = {exports: {}}; - - (function (module, exports) { - !function(e){module.exports=e();}(function(){return function s(a,o,h){function u(r,e){if(!o[r]){if(!a[r]){var t="function"==typeof commonjsRequire&&commonjsRequire;if(!e&&t)return t(r,!0);if(l)return l(r,!0);var n=new Error("Cannot find module '"+r+"'");throw n.code="MODULE_NOT_FOUND",n}var i=o[r]={exports:{}};a[r][0].call(i.exports,function(e){var t=a[r][1][e];return u(t||e)},i,i.exports,s,a,o,h);}return o[r].exports}for(var l="function"==typeof commonjsRequire&&commonjsRequire,e=0;e>2,s=(3&t)<<4|r>>4,a=1>6:64,o=2>4,r=(15&i)<<4|(s=p.indexOf(e.charAt(o++)))>>2,n=(3&s)<<6|(a=p.indexOf(e.charAt(o++))),l[h++]=t,64!==s&&(l[h++]=r),64!==a&&(l[h++]=n);return l};},{"./support":30,"./utils":32}],2:[function(e,t,r){var n=e("./external"),i=e("./stream/DataWorker"),s=e("./stream/Crc32Probe"),a=e("./stream/DataLengthProbe");function o(e,t,r,n,i){this.compressedSize=e,this.uncompressedSize=t,this.crc32=r,this.compression=n,this.compressedContent=i;}o.prototype={getContentWorker:function(){var e=new i(n.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new a("data_length")),t=this;return e.on("end",function(){if(this.streamInfo.data_length!==t.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),e},getCompressedWorker:function(){return new i(n.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},o.createWorkerFrom=function(e,t,r){return e.pipe(new s).pipe(new a("uncompressedSize")).pipe(t.compressWorker(r)).pipe(new a("compressedSize")).withStreamInfo("compression",t)},t.exports=o;},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(e,t,r){var n=e("./stream/GenericWorker");r.STORE={magic:"\0\0",compressWorker:function(){return new n("STORE compression")},uncompressWorker:function(){return new n("STORE decompression")}},r.DEFLATE=e("./flate");},{"./flate":7,"./stream/GenericWorker":28}],4:[function(e,t,r){var n=e("./utils");var o=function(){for(var e,t=[],r=0;r<256;r++){e=r;for(var n=0;n<8;n++)e=1&e?3988292384^e>>>1:e>>>1;t[r]=e;}return t}();t.exports=function(e,t){return void 0!==e&&e.length?"string"!==n.getTypeOf(e)?function(e,t,r,n){var i=o,s=n+r;e^=-1;for(var a=n;a>>8^i[255&(e^t[a])];return -1^e}(0|t,e,e.length,0):function(e,t,r,n){var i=o,s=n+r;e^=-1;for(var a=n;a>>8^i[255&(e^t.charCodeAt(a))];return -1^e}(0|t,e,e.length,0):0};},{"./utils":32}],5:[function(e,t,r){r.base64=!1,r.binary=!1,r.dir=!1,r.createFolders=!0,r.date=null,r.compression=null,r.compressionOptions=null,r.comment=null,r.unixPermissions=null,r.dosPermissions=null;},{}],6:[function(e,t,r){var n=null;n="undefined"!=typeof Promise?Promise:e("lie"),t.exports={Promise:n};},{lie:37}],7:[function(e,t,r){var n="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array,i=e("pako"),s=e("./utils"),a=e("./stream/GenericWorker"),o=n?"uint8array":"array";function h(e,t){a.call(this,"FlateWorker/"+e),this._pako=null,this._pakoAction=e,this._pakoOptions=t,this.meta={};}r.magic="\b\0",s.inherits(h,a),h.prototype.processChunk=function(e){this.meta=e.meta,null===this._pako&&this._createPako(),this._pako.push(s.transformTo(o,e.data),!1);},h.prototype.flush=function(){a.prototype.flush.call(this),null===this._pako&&this._createPako(),this._pako.push([],!0);},h.prototype.cleanUp=function(){a.prototype.cleanUp.call(this),this._pako=null;},h.prototype._createPako=function(){this._pako=new i[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var t=this;this._pako.onData=function(e){t.push({data:e,meta:t.meta});};},r.compressWorker=function(e){return new h("Deflate",e)},r.uncompressWorker=function(){return new h("Inflate",{})};},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(e,t,r){function A(e,t){var r,n="";for(r=0;r>>=8;return n}function n(e,t,r,n,i,s){var a,o,h=e.file,u=e.compression,l=s!==O.utf8encode,f=I.transformTo("string",s(h.name)),c=I.transformTo("string",O.utf8encode(h.name)),d=h.comment,p=I.transformTo("string",s(d)),m=I.transformTo("string",O.utf8encode(d)),_=c.length!==h.name.length,g=m.length!==d.length,b="",v="",y="",w=h.dir,k=h.date,x={crc32:0,compressedSize:0,uncompressedSize:0};t&&!r||(x.crc32=e.crc32,x.compressedSize=e.compressedSize,x.uncompressedSize=e.uncompressedSize);var S=0;t&&(S|=8),l||!_&&!g||(S|=2048);var z=0,C=0;w&&(z|=16),"UNIX"===i?(C=798,z|=function(e,t){var r=e;return e||(r=t?16893:33204),(65535&r)<<16}(h.unixPermissions,w)):(C=20,z|=function(e){return 63&(e||0)}(h.dosPermissions)),a=k.getUTCHours(),a<<=6,a|=k.getUTCMinutes(),a<<=5,a|=k.getUTCSeconds()/2,o=k.getUTCFullYear()-1980,o<<=4,o|=k.getUTCMonth()+1,o<<=5,o|=k.getUTCDate(),_&&(v=A(1,1)+A(B(f),4)+c,b+="up"+A(v.length,2)+v),g&&(y=A(1,1)+A(B(p),4)+m,b+="uc"+A(y.length,2)+y);var E="";return E+="\n\0",E+=A(S,2),E+=u.magic,E+=A(a,2),E+=A(o,2),E+=A(x.crc32,4),E+=A(x.compressedSize,4),E+=A(x.uncompressedSize,4),E+=A(f.length,2),E+=A(b.length,2),{fileRecord:R.LOCAL_FILE_HEADER+E+f+b,dirRecord:R.CENTRAL_FILE_HEADER+A(C,2)+E+A(p.length,2)+"\0\0\0\0"+A(z,4)+A(n,4)+f+b+p}}var I=e("../utils"),i=e("../stream/GenericWorker"),O=e("../utf8"),B=e("../crc32"),R=e("../signature");function s(e,t,r,n){i.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=t,this.zipPlatform=r,this.encodeFileName=n,this.streamFiles=e,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[];}I.inherits(s,i),s.prototype.push=function(e){var t=e.meta.percent||0,r=this.entriesCount,n=this._sources.length;this.accumulate?this.contentBuffer.push(e):(this.bytesWritten+=e.data.length,i.prototype.push.call(this,{data:e.data,meta:{currentFile:this.currentFile,percent:r?(t+100*(r-n-1))/r:100}}));},s.prototype.openedSource=function(e){this.currentSourceOffset=this.bytesWritten,this.currentFile=e.file.name;var t=this.streamFiles&&!e.file.dir;if(t){var r=n(e,t,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:r.fileRecord,meta:{percent:0}});}else this.accumulate=!0;},s.prototype.closedSource=function(e){this.accumulate=!1;var t=this.streamFiles&&!e.file.dir,r=n(e,t,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(r.dirRecord),t)this.push({data:function(e){return R.DATA_DESCRIPTOR+A(e.crc32,4)+A(e.compressedSize,4)+A(e.uncompressedSize,4)}(e),meta:{percent:100}});else for(this.push({data:r.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null;},s.prototype.flush=function(){for(var e=this.bytesWritten,t=0;t=this.index;t--)r=(r<<8)+this.byteAt(t);return this.index+=e,r},readString:function(e){return n.transformTo("string",this.readData(e))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var e=this.readInt(4);return new Date(Date.UTC(1980+(e>>25&127),(e>>21&15)-1,e>>16&31,e>>11&31,e>>5&63,(31&e)<<1))}},t.exports=i;},{"../utils":32}],19:[function(e,t,r){var n=e("./Uint8ArrayReader");function i(e){n.call(this,e);}e("../utils").inherits(i,n),i.prototype.readData=function(e){this.checkOffset(e);var t=this.data.slice(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i;},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(e,t,r){var n=e("./DataReader");function i(e){n.call(this,e);}e("../utils").inherits(i,n),i.prototype.byteAt=function(e){return this.data.charCodeAt(this.zero+e)},i.prototype.lastIndexOfSignature=function(e){return this.data.lastIndexOf(e)-this.zero},i.prototype.readAndCheckSignature=function(e){return e===this.readData(4)},i.prototype.readData=function(e){this.checkOffset(e);var t=this.data.slice(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i;},{"../utils":32,"./DataReader":18}],21:[function(e,t,r){var n=e("./ArrayReader");function i(e){n.call(this,e);}e("../utils").inherits(i,n),i.prototype.readData=function(e){if(this.checkOffset(e),0===e)return new Uint8Array(0);var t=this.data.subarray(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i;},{"../utils":32,"./ArrayReader":17}],22:[function(e,t,r){var n=e("../utils"),i=e("../support"),s=e("./ArrayReader"),a=e("./StringReader"),o=e("./NodeBufferReader"),h=e("./Uint8ArrayReader");t.exports=function(e){var t=n.getTypeOf(e);return n.checkSupport(t),"string"!==t||i.uint8array?"nodebuffer"===t?new o(e):i.uint8array?new h(n.transformTo("uint8array",e)):new s(n.transformTo("array",e)):new a(e)};},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(e,t,r){r.LOCAL_FILE_HEADER="PK",r.CENTRAL_FILE_HEADER="PK",r.CENTRAL_DIRECTORY_END="PK",r.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK",r.ZIP64_CENTRAL_DIRECTORY_END="PK",r.DATA_DESCRIPTOR="PK\b";},{}],24:[function(e,t,r){var n=e("./GenericWorker"),i=e("../utils");function s(e){n.call(this,"ConvertWorker to "+e),this.destType=e;}i.inherits(s,n),s.prototype.processChunk=function(e){this.push({data:i.transformTo(this.destType,e.data),meta:e.meta});},t.exports=s;},{"../utils":32,"./GenericWorker":28}],25:[function(e,t,r){var n=e("./GenericWorker"),i=e("../crc32");function s(){n.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0);}e("../utils").inherits(s,n),s.prototype.processChunk=function(e){this.streamInfo.crc32=i(e.data,this.streamInfo.crc32||0),this.push(e);},t.exports=s;},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(e,t,r){var n=e("../utils"),i=e("./GenericWorker");function s(e){i.call(this,"DataLengthProbe for "+e),this.propName=e,this.withStreamInfo(e,0);}n.inherits(s,i),s.prototype.processChunk=function(e){if(e){var t=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=t+e.data.length;}i.prototype.processChunk.call(this,e);},t.exports=s;},{"../utils":32,"./GenericWorker":28}],27:[function(e,t,r){var n=e("../utils"),i=e("./GenericWorker");function s(e){i.call(this,"DataWorker");var t=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,e.then(function(e){t.dataIsReady=!0,t.data=e,t.max=e&&e.length||0,t.type=n.getTypeOf(e),t.isPaused||t._tickAndRepeat();},function(e){t.error(e);});}n.inherits(s,i),s.prototype.cleanUp=function(){i.prototype.cleanUp.call(this),this.data=null;},s.prototype.resume=function(){return !!i.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,n.delay(this._tickAndRepeat,[],this)),!0)},s.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(n.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0));},s.prototype._tick=function(){if(this.isPaused||this.isFinished)return !1;var e=null,t=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case"string":e=this.data.substring(this.index,t);break;case"uint8array":e=this.data.subarray(this.index,t);break;case"array":case"nodebuffer":e=this.data.slice(this.index,t);}return this.index=t,this.push({data:e,meta:{percent:this.max?this.index/this.max*100:0}})},t.exports=s;},{"../utils":32,"./GenericWorker":28}],28:[function(e,t,r){function n(e){this.name=e||"default",this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null;}n.prototype={push:function(e){this.emit("data",e);},end:function(){if(this.isFinished)return !1;this.flush();try{this.emit("end"),this.cleanUp(),this.isFinished=!0;}catch(e){this.emit("error",e);}return !0},error:function(e){return !this.isFinished&&(this.isPaused?this.generatedError=e:(this.isFinished=!0,this.emit("error",e),this.previous&&this.previous.error(e),this.cleanUp()),!0)},on:function(e,t){return this._listeners[e].push(t),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[];},emit:function(e,t){if(this._listeners[e])for(var r=0;r "+e:e}},t.exports=n;},{}],29:[function(e,t,r){var h=e("../utils"),i=e("./ConvertWorker"),s=e("./GenericWorker"),u=e("../base64"),n=e("../support"),a=e("../external"),o=null;if(n.nodestream)try{o=e("../nodejs/NodejsStreamOutputAdapter");}catch(e){}function l(e,o){return new a.Promise(function(t,r){var n=[],i=e._internalType,s=e._outputType,a=e._mimeType;e.on("data",function(e,t){n.push(e),o&&o(t);}).on("error",function(e){n=[],r(e);}).on("end",function(){try{var e=function(e,t,r){switch(e){case"blob":return h.newBlob(h.transformTo("arraybuffer",t),r);case"base64":return u.encode(t);default:return h.transformTo(e,t)}}(s,function(e,t){var r,n=0,i=null,s=0;for(r=0;r>>6:(r<65536?t[s++]=224|r>>>12:(t[s++]=240|r>>>18,t[s++]=128|r>>>12&63),t[s++]=128|r>>>6&63),t[s++]=128|63&r);return t}(e)},s.utf8decode=function(e){return h.nodebuffer?o.transformTo("nodebuffer",e).toString("utf-8"):function(e){var t,r,n,i,s=e.length,a=new Array(2*s);for(t=r=0;t>10&1023,a[r++]=56320|1023&n);}return a.length!==r&&(a.subarray?a=a.subarray(0,r):a.length=r),o.applyFromCharCode(a)}(e=o.transformTo(h.uint8array?"uint8array":"array",e))},o.inherits(a,n),a.prototype.processChunk=function(e){var t=o.transformTo(h.uint8array?"uint8array":"array",e.data);if(this.leftOver&&this.leftOver.length){if(h.uint8array){var r=t;(t=new Uint8Array(r.length+this.leftOver.length)).set(this.leftOver,0),t.set(r,this.leftOver.length);}else t=this.leftOver.concat(t);this.leftOver=null;}var n=function(e,t){var r;for((t=t||e.length)>e.length&&(t=e.length),r=t-1;0<=r&&128==(192&e[r]);)r--;return r<0?t:0===r?t:r+u[e[r]]>t?r:t}(t),i=t;n!==t.length&&(h.uint8array?(i=t.subarray(0,n),this.leftOver=t.subarray(n,t.length)):(i=t.slice(0,n),this.leftOver=t.slice(n,t.length))),this.push({data:s.utf8decode(i),meta:e.meta});},a.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:s.utf8decode(this.leftOver),meta:{}}),this.leftOver=null);},s.Utf8DecodeWorker=a,o.inherits(l,n),l.prototype.processChunk=function(e){this.push({data:s.utf8encode(e.data),meta:e.meta});},s.Utf8EncodeWorker=l;},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(e,t,a){var o=e("./support"),h=e("./base64"),r=e("./nodejsUtils"),u=e("./external");function n(e){return e}function l(e,t){for(var r=0;r>8;this.dir=!!(16&this.externalFileAttributes),0==e&&(this.dosPermissions=63&this.externalFileAttributes),3==e&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||"/"!==this.fileNameStr.slice(-1)||(this.dir=!0);},parseZIP64ExtraField:function(){if(this.extraFields[1]){var e=n(this.extraFields[1].value);this.uncompressedSize===s.MAX_VALUE_32BITS&&(this.uncompressedSize=e.readInt(8)),this.compressedSize===s.MAX_VALUE_32BITS&&(this.compressedSize=e.readInt(8)),this.localHeaderOffset===s.MAX_VALUE_32BITS&&(this.localHeaderOffset=e.readInt(8)),this.diskNumberStart===s.MAX_VALUE_32BITS&&(this.diskNumberStart=e.readInt(4));}},readExtraFields:function(e){var t,r,n,i=e.index+this.extraFieldsLength;for(this.extraFields||(this.extraFields={});e.index+4>>6:(r<65536?t[s++]=224|r>>>12:(t[s++]=240|r>>>18,t[s++]=128|r>>>12&63),t[s++]=128|r>>>6&63),t[s++]=128|63&r);return t},r.buf2binstring=function(e){return l(e,e.length)},r.binstring2buf=function(e){for(var t=new h.Buf8(e.length),r=0,n=t.length;r>10&1023,o[n++]=56320|1023&i);}return l(o,n)},r.utf8border=function(e,t){var r;for((t=t||e.length)>e.length&&(t=e.length),r=t-1;0<=r&&128==(192&e[r]);)r--;return r<0?t:0===r?t:r+u[e[r]]>t?r:t};},{"./common":41}],43:[function(e,t,r){t.exports=function(e,t,r,n){for(var i=65535&e|0,s=e>>>16&65535|0,a=0;0!==r;){for(r-=a=2e3>>1:e>>>1;t[r]=e;}return t}();t.exports=function(e,t,r,n){var i=o,s=n+r;e^=-1;for(var a=n;a>>8^i[255&(e^t[a])];return -1^e};},{}],46:[function(e,t,r){var h,c=e("../utils/common"),u=e("./trees"),d=e("./adler32"),p=e("./crc32"),n=e("./messages"),l=0,f=4,m=0,_=-2,g=-1,b=4,i=2,v=8,y=9,s=286,a=30,o=19,w=2*s+1,k=15,x=3,S=258,z=S+x+1,C=42,E=113,A=1,I=2,O=3,B=4;function R(e,t){return e.msg=n[t],t}function T(e){return (e<<1)-(4e.avail_out&&(r=e.avail_out),0!==r&&(c.arraySet(e.output,t.pending_buf,t.pending_out,r,e.next_out),e.next_out+=r,t.pending_out+=r,e.total_out+=r,e.avail_out-=r,t.pending-=r,0===t.pending&&(t.pending_out=0));}function N(e,t){u._tr_flush_block(e,0<=e.block_start?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,F(e.strm);}function U(e,t){e.pending_buf[e.pending++]=t;}function P(e,t){e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t;}function L(e,t){var r,n,i=e.max_chain_length,s=e.strstart,a=e.prev_length,o=e.nice_match,h=e.strstart>e.w_size-z?e.strstart-(e.w_size-z):0,u=e.window,l=e.w_mask,f=e.prev,c=e.strstart+S,d=u[s+a-1],p=u[s+a];e.prev_length>=e.good_match&&(i>>=2),o>e.lookahead&&(o=e.lookahead);do{if(u[(r=t)+a]===p&&u[r+a-1]===d&&u[r]===u[s]&&u[++r]===u[s+1]){s+=2,r++;do{}while(u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&sh&&0!=--i);return a<=e.lookahead?a:e.lookahead}function j(e){var t,r,n,i,s,a,o,h,u,l,f=e.w_size;do{if(i=e.window_size-e.lookahead-e.strstart,e.strstart>=f+(f-z)){for(c.arraySet(e.window,e.window,f,f,0),e.match_start-=f,e.strstart-=f,e.block_start-=f,t=r=e.hash_size;n=e.head[--t],e.head[t]=f<=n?n-f:0,--r;);for(t=r=f;n=e.prev[--t],e.prev[t]=f<=n?n-f:0,--r;);i+=f;}if(0===e.strm.avail_in)break;if(a=e.strm,o=e.window,h=e.strstart+e.lookahead,u=i,l=void 0,l=a.avail_in,u=x)for(s=e.strstart-e.insert,e.ins_h=e.window[s],e.ins_h=(e.ins_h<=x&&(e.ins_h=(e.ins_h<=x)if(n=u._tr_tally(e,e.strstart-e.match_start,e.match_length-x),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=x){for(e.match_length--;e.strstart++,e.ins_h=(e.ins_h<=x&&(e.ins_h=(e.ins_h<=x&&e.match_length<=e.prev_length){for(i=e.strstart+e.lookahead-x,n=u._tr_tally(e,e.strstart-1-e.prev_match,e.prev_length-x),e.lookahead-=e.prev_length-1,e.prev_length-=2;++e.strstart<=i&&(e.ins_h=(e.ins_h<e.pending_buf_size-5&&(r=e.pending_buf_size-5);;){if(e.lookahead<=1){if(j(e),0===e.lookahead&&t===l)return A;if(0===e.lookahead)break}e.strstart+=e.lookahead,e.lookahead=0;var n=e.block_start+r;if((0===e.strstart||e.strstart>=n)&&(e.lookahead=e.strstart-n,e.strstart=n,N(e,!1),0===e.strm.avail_out))return A;if(e.strstart-e.block_start>=e.w_size-z&&(N(e,!1),0===e.strm.avail_out))return A}return e.insert=0,t===f?(N(e,!0),0===e.strm.avail_out?O:B):(e.strstart>e.block_start&&(N(e,!1),e.strm.avail_out),A)}),new M(4,4,8,4,Z),new M(4,5,16,8,Z),new M(4,6,32,32,Z),new M(4,4,16,16,W),new M(8,16,32,32,W),new M(8,16,128,128,W),new M(8,32,128,256,W),new M(32,128,258,1024,W),new M(32,258,258,4096,W)],r.deflateInit=function(e,t){return Y(e,t,v,15,8,0)},r.deflateInit2=Y,r.deflateReset=K,r.deflateResetKeep=G,r.deflateSetHeader=function(e,t){return e&&e.state?2!==e.state.wrap?_:(e.state.gzhead=t,m):_},r.deflate=function(e,t){var r,n,i,s;if(!e||!e.state||5>8&255),U(n,n.gzhead.time>>16&255),U(n,n.gzhead.time>>24&255),U(n,9===n.level?2:2<=n.strategy||n.level<2?4:0),U(n,255&n.gzhead.os),n.gzhead.extra&&n.gzhead.extra.length&&(U(n,255&n.gzhead.extra.length),U(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(e.adler=p(e.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=69):(U(n,0),U(n,0),U(n,0),U(n,0),U(n,0),U(n,9===n.level?2:2<=n.strategy||n.level<2?4:0),U(n,3),n.status=E);else {var a=v+(n.w_bits-8<<4)<<8;a|=(2<=n.strategy||n.level<2?0:n.level<6?1:6===n.level?2:3)<<6,0!==n.strstart&&(a|=32),a+=31-a%31,n.status=E,P(n,a),0!==n.strstart&&(P(n,e.adler>>>16),P(n,65535&e.adler)),e.adler=1;}if(69===n.status)if(n.gzhead.extra){for(i=n.pending;n.gzindex<(65535&n.gzhead.extra.length)&&(n.pending!==n.pending_buf_size||(n.gzhead.hcrc&&n.pending>i&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),F(e),i=n.pending,n.pending!==n.pending_buf_size));)U(n,255&n.gzhead.extra[n.gzindex]),n.gzindex++;n.gzhead.hcrc&&n.pending>i&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),n.gzindex===n.gzhead.extra.length&&(n.gzindex=0,n.status=73);}else n.status=73;if(73===n.status)if(n.gzhead.name){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),F(e),i=n.pending,n.pending===n.pending_buf_size)){s=1;break}s=n.gzindexi&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),0===s&&(n.gzindex=0,n.status=91);}else n.status=91;if(91===n.status)if(n.gzhead.comment){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),F(e),i=n.pending,n.pending===n.pending_buf_size)){s=1;break}s=n.gzindexi&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),0===s&&(n.status=103);}else n.status=103;if(103===n.status&&(n.gzhead.hcrc?(n.pending+2>n.pending_buf_size&&F(e),n.pending+2<=n.pending_buf_size&&(U(n,255&e.adler),U(n,e.adler>>8&255),e.adler=0,n.status=E)):n.status=E),0!==n.pending){if(F(e),0===e.avail_out)return n.last_flush=-1,m}else if(0===e.avail_in&&T(t)<=T(r)&&t!==f)return R(e,-5);if(666===n.status&&0!==e.avail_in)return R(e,-5);if(0!==e.avail_in||0!==n.lookahead||t!==l&&666!==n.status){var o=2===n.strategy?function(e,t){for(var r;;){if(0===e.lookahead&&(j(e),0===e.lookahead)){if(t===l)return A;break}if(e.match_length=0,r=u._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,r&&(N(e,!1),0===e.strm.avail_out))return A}return e.insert=0,t===f?(N(e,!0),0===e.strm.avail_out?O:B):e.last_lit&&(N(e,!1),0===e.strm.avail_out)?A:I}(n,t):3===n.strategy?function(e,t){for(var r,n,i,s,a=e.window;;){if(e.lookahead<=S){if(j(e),e.lookahead<=S&&t===l)return A;if(0===e.lookahead)break}if(e.match_length=0,e.lookahead>=x&&0e.lookahead&&(e.match_length=e.lookahead);}if(e.match_length>=x?(r=u._tr_tally(e,1,e.match_length-x),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(r=u._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),r&&(N(e,!1),0===e.strm.avail_out))return A}return e.insert=0,t===f?(N(e,!0),0===e.strm.avail_out?O:B):e.last_lit&&(N(e,!1),0===e.strm.avail_out)?A:I}(n,t):h[n.level].func(n,t);if(o!==O&&o!==B||(n.status=666),o===A||o===O)return 0===e.avail_out&&(n.last_flush=-1),m;if(o===I&&(1===t?u._tr_align(n):5!==t&&(u._tr_stored_block(n,0,0,!1),3===t&&(D(n.head),0===n.lookahead&&(n.strstart=0,n.block_start=0,n.insert=0))),F(e),0===e.avail_out))return n.last_flush=-1,m}return t!==f?m:n.wrap<=0?1:(2===n.wrap?(U(n,255&e.adler),U(n,e.adler>>8&255),U(n,e.adler>>16&255),U(n,e.adler>>24&255),U(n,255&e.total_in),U(n,e.total_in>>8&255),U(n,e.total_in>>16&255),U(n,e.total_in>>24&255)):(P(n,e.adler>>>16),P(n,65535&e.adler)),F(e),0=r.w_size&&(0===s&&(D(r.head),r.strstart=0,r.block_start=0,r.insert=0),u=new c.Buf8(r.w_size),c.arraySet(u,t,l-r.w_size,r.w_size,0),t=u,l=r.w_size),a=e.avail_in,o=e.next_in,h=e.input,e.avail_in=l,e.next_in=0,e.input=t,j(r);r.lookahead>=x;){for(n=r.strstart,i=r.lookahead-(x-1);r.ins_h=(r.ins_h<>>=y=v>>>24,p-=y,0===(y=v>>>16&255))C[s++]=65535&v;else {if(!(16&y)){if(0==(64&y)){v=m[(65535&v)+(d&(1<>>=y,p-=y),p<15&&(d+=z[n++]<>>=y=v>>>24,p-=y,!(16&(y=v>>>16&255))){if(0==(64&y)){v=_[(65535&v)+(d&(1<>>=y,p-=y,(y=s-a)>3,d&=(1<<(p-=w<<3))-1,e.next_in=n,e.next_out=s,e.avail_in=n>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24)}function s(){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 I.Buf16(320),this.work=new I.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0;}function a(e){var t;return e&&e.state?(t=e.state,e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=P,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new I.Buf32(n),t.distcode=t.distdyn=new I.Buf32(i),t.sane=1,t.back=-1,N):U}function o(e){var t;return e&&e.state?((t=e.state).wsize=0,t.whave=0,t.wnext=0,a(e)):U}function h(e,t){var r,n;return e&&e.state?(n=e.state,t<0?(r=0,t=-t):(r=1+(t>>4),t<48&&(t&=15)),t&&(t<8||15=s.wsize?(I.arraySet(s.window,t,r-s.wsize,s.wsize,0),s.wnext=0,s.whave=s.wsize):(n<(i=s.wsize-s.wnext)&&(i=n),I.arraySet(s.window,t,r-n,i,s.wnext),(n-=i)?(I.arraySet(s.window,t,r-n,n,0),s.wnext=n,s.whave=s.wsize):(s.wnext+=i,s.wnext===s.wsize&&(s.wnext=0),s.whave>>8&255,r.check=B(r.check,E,2,0),l=u=0,r.mode=2;break}if(r.flags=0,r.head&&(r.head.done=!1),!(1&r.wrap)||(((255&u)<<8)+(u>>8))%31){e.msg="incorrect header check",r.mode=30;break}if(8!=(15&u)){e.msg="unknown compression method",r.mode=30;break}if(l-=4,k=8+(15&(u>>>=4)),0===r.wbits)r.wbits=k;else if(k>r.wbits){e.msg="invalid window size",r.mode=30;break}r.dmax=1<>8&1),512&r.flags&&(E[0]=255&u,E[1]=u>>>8&255,r.check=B(r.check,E,2,0)),l=u=0,r.mode=3;case 3:for(;l<32;){if(0===o)break e;o--,u+=n[s++]<>>8&255,E[2]=u>>>16&255,E[3]=u>>>24&255,r.check=B(r.check,E,4,0)),l=u=0,r.mode=4;case 4:for(;l<16;){if(0===o)break e;o--,u+=n[s++]<>8),512&r.flags&&(E[0]=255&u,E[1]=u>>>8&255,r.check=B(r.check,E,2,0)),l=u=0,r.mode=5;case 5:if(1024&r.flags){for(;l<16;){if(0===o)break e;o--,u+=n[s++]<>>8&255,r.check=B(r.check,E,2,0)),l=u=0;}else r.head&&(r.head.extra=null);r.mode=6;case 6:if(1024&r.flags&&(o<(d=r.length)&&(d=o),d&&(r.head&&(k=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Array(r.head.extra_len)),I.arraySet(r.head.extra,n,s,d,k)),512&r.flags&&(r.check=B(r.check,n,d,s)),o-=d,s+=d,r.length-=d),r.length))break e;r.length=0,r.mode=7;case 7:if(2048&r.flags){if(0===o)break e;for(d=0;k=n[s+d++],r.head&&k&&r.length<65536&&(r.head.name+=String.fromCharCode(k)),k&&d>9&1,r.head.done=!0),e.adler=r.check=0,r.mode=12;break;case 10:for(;l<32;){if(0===o)break e;o--,u+=n[s++]<>>=7&l,l-=7&l,r.mode=27;break}for(;l<3;){if(0===o)break e;o--,u+=n[s++]<>>=1)){case 0:r.mode=14;break;case 1:if(j(r),r.mode=20,6!==t)break;u>>>=2,l-=2;break e;case 2:r.mode=17;break;case 3:e.msg="invalid block type",r.mode=30;}u>>>=2,l-=2;break;case 14:for(u>>>=7&l,l-=7&l;l<32;){if(0===o)break e;o--,u+=n[s++]<>>16^65535)){e.msg="invalid stored block lengths",r.mode=30;break}if(r.length=65535&u,l=u=0,r.mode=15,6===t)break e;case 15:r.mode=16;case 16:if(d=r.length){if(o>>=5,l-=5,r.ndist=1+(31&u),u>>>=5,l-=5,r.ncode=4+(15&u),u>>>=4,l-=4,286>>=3,l-=3;}for(;r.have<19;)r.lens[A[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,S={bits:r.lenbits},x=T(0,r.lens,0,19,r.lencode,0,r.work,S),r.lenbits=S.bits,x){e.msg="invalid code lengths set",r.mode=30;break}r.have=0,r.mode=19;case 19:for(;r.have>>16&255,b=65535&C,!((_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>>=_,l-=_,r.lens[r.have++]=b;else {if(16===b){for(z=_+2;l>>=_,l-=_,0===r.have){e.msg="invalid bit length repeat",r.mode=30;break}k=r.lens[r.have-1],d=3+(3&u),u>>>=2,l-=2;}else if(17===b){for(z=_+3;l>>=_)),u>>>=3,l-=3;}else {for(z=_+7;l>>=_)),u>>>=7,l-=7;}if(r.have+d>r.nlen+r.ndist){e.msg="invalid bit length repeat",r.mode=30;break}for(;d--;)r.lens[r.have++]=k;}}if(30===r.mode)break;if(0===r.lens[256]){e.msg="invalid code -- missing end-of-block",r.mode=30;break}if(r.lenbits=9,S={bits:r.lenbits},x=T(D,r.lens,0,r.nlen,r.lencode,0,r.work,S),r.lenbits=S.bits,x){e.msg="invalid literal/lengths set",r.mode=30;break}if(r.distbits=6,r.distcode=r.distdyn,S={bits:r.distbits},x=T(F,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,S),r.distbits=S.bits,x){e.msg="invalid distances set",r.mode=30;break}if(r.mode=20,6===t)break e;case 20:r.mode=21;case 21:if(6<=o&&258<=h){e.next_out=a,e.avail_out=h,e.next_in=s,e.avail_in=o,r.hold=u,r.bits=l,R(e,c),a=e.next_out,i=e.output,h=e.avail_out,s=e.next_in,n=e.input,o=e.avail_in,u=r.hold,l=r.bits,12===r.mode&&(r.back=-1);break}for(r.back=0;g=(C=r.lencode[u&(1<>>16&255,b=65535&C,!((_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>v)])>>>16&255,b=65535&C,!(v+(_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>>=v,l-=v,r.back+=v;}if(u>>>=_,l-=_,r.back+=_,r.length=b,0===g){r.mode=26;break}if(32&g){r.back=-1,r.mode=12;break}if(64&g){e.msg="invalid literal/length code",r.mode=30;break}r.extra=15&g,r.mode=22;case 22:if(r.extra){for(z=r.extra;l>>=r.extra,l-=r.extra,r.back+=r.extra;}r.was=r.length,r.mode=23;case 23:for(;g=(C=r.distcode[u&(1<>>16&255,b=65535&C,!((_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>v)])>>>16&255,b=65535&C,!(v+(_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>>=v,l-=v,r.back+=v;}if(u>>>=_,l-=_,r.back+=_,64&g){e.msg="invalid distance code",r.mode=30;break}r.offset=b,r.extra=15&g,r.mode=24;case 24:if(r.extra){for(z=r.extra;l>>=r.extra,l-=r.extra,r.back+=r.extra;}if(r.offset>r.dmax){e.msg="invalid distance too far back",r.mode=30;break}r.mode=25;case 25:if(0===h)break e;if(d=c-h,r.offset>d){if((d=r.offset-d)>r.whave&&r.sane){e.msg="invalid distance too far back",r.mode=30;break}p=d>r.wnext?(d-=r.wnext,r.wsize-d):r.wnext-d,d>r.length&&(d=r.length),m=r.window;}else m=i,p=a-r.offset,d=r.length;for(hd?(m=R[T+a[v]],A[I+a[v]]):(m=96,0),h=1<>S)+(u-=h)]=p<<24|m<<16|_|0,0!==u;);for(h=1<>=1;if(0!==h?(E&=h-1,E+=h):E=0,v++,0==--O[b]){if(b===w)break;b=t[r+a[v]];}if(k>>7)]}function U(e,t){e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255;}function P(e,t,r){e.bi_valid>d-r?(e.bi_buf|=t<>d-e.bi_valid,e.bi_valid+=r-d):(e.bi_buf|=t<>>=1,r<<=1,0<--t;);return r>>>1}function Z(e,t,r){var n,i,s=new Array(g+1),a=0;for(n=1;n<=g;n++)s[n]=a=a+r[n-1]<<1;for(i=0;i<=t;i++){var o=e[2*i+1];0!==o&&(e[2*i]=j(s[o]++,o));}}function W(e){var t;for(t=0;t>1;1<=r;r--)G(e,s,r);for(i=h;r=e.heap[1],e.heap[1]=e.heap[e.heap_len--],G(e,s,1),n=e.heap[1],e.heap[--e.heap_max]=r,e.heap[--e.heap_max]=n,s[2*i]=s[2*r]+s[2*n],e.depth[i]=(e.depth[r]>=e.depth[n]?e.depth[r]:e.depth[n])+1,s[2*r+1]=s[2*n+1]=i,e.heap[1]=i++,G(e,s,1),2<=e.heap_len;);e.heap[--e.heap_max]=e.heap[1],function(e,t){var r,n,i,s,a,o,h=t.dyn_tree,u=t.max_code,l=t.stat_desc.static_tree,f=t.stat_desc.has_stree,c=t.stat_desc.extra_bits,d=t.stat_desc.extra_base,p=t.stat_desc.max_length,m=0;for(s=0;s<=g;s++)e.bl_count[s]=0;for(h[2*e.heap[e.heap_max]+1]=0,r=e.heap_max+1;r<_;r++)p<(s=h[2*h[2*(n=e.heap[r])+1]+1]+1)&&(s=p,m++),h[2*n+1]=s,u>=7;n>>=1)if(1&r&&0!==e.dyn_ltree[2*t])return o;if(0!==e.dyn_ltree[18]||0!==e.dyn_ltree[20]||0!==e.dyn_ltree[26])return h;for(t=32;t>>3,(s=e.static_len+3+7>>>3)<=i&&(i=s)):i=s=r+5,r+4<=i&&-1!==t?J(e,t,r,n):4===e.strategy||s===i?(P(e,2+(n?1:0),3),K(e,z,C)):(P(e,4+(n?1:0),3),function(e,t,r,n){var i;for(P(e,t-257,5),P(e,r-1,5),P(e,n-4,4),i=0;i>>8&255,e.pending_buf[e.d_buf+2*e.last_lit+1]=255&t,e.pending_buf[e.l_buf+e.last_lit]=255&r,e.last_lit++,0===t?e.dyn_ltree[2*r]++:(e.matches++,t--,e.dyn_ltree[2*(A[r]+u+1)]++,e.dyn_dtree[2*N(t)]++),e.last_lit===e.lit_bufsize-1},r._tr_align=function(e){P(e,2,3),L(e,m,z),function(e){16===e.bi_valid?(U(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):8<=e.bi_valid&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8);}(e);};},{"../utils/common":41}],53:[function(e,t,r){t.exports=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0;};},{}],54:[function(e,t,r){(function(e){!function(r,n){if(!r.setImmediate){var i,s,t,a,o=1,h={},u=!1,l=r.document,e=Object.getPrototypeOf&&Object.getPrototypeOf(r);e=e&&e.setTimeout?e:r,i="[object process]"==={}.toString.call(r.process)?function(e){browser$1.nextTick(function(){c(e);});}:function(){if(r.postMessage&&!r.importScripts){var e=!0,t=r.onmessage;return r.onmessage=function(){e=!1;},r.postMessage("","*"),r.onmessage=t,e}}()?(a="setImmediate$"+Math.random()+"$",r.addEventListener?r.addEventListener("message",d,!1):r.attachEvent("onmessage",d),function(e){r.postMessage(a+e,"*");}):r.MessageChannel?((t=new MessageChannel).port1.onmessage=function(e){c(e.data);},function(e){t.port2.postMessage(e);}):l&&"onreadystatechange"in l.createElement("script")?(s=l.documentElement,function(e){var t=l.createElement("script");t.onreadystatechange=function(){c(e),t.onreadystatechange=null,s.removeChild(t),t=null;},s.appendChild(t);}):function(e){setTimeout(c,0,e);},e.setImmediate=function(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),r=0;r { - const zip = new JSZip(); - await zip.loadAsync(buffer); - const files = zip.file(/.+/); - const out = {}; - await Promise.all(files.map(async (a) => { - let result; - if (a.name.slice(-3).toLowerCase() === 'shp' || a.name.slice(-3).toLowerCase() === 'dbf') { - result = await a.async('nodebuffer'); - } else { - result = await a.async('text'); - } - out[a.name] = result; - })); - return out; - }; - - const URL$1 = globalThis.URL; - - var combine$1 = (base, type) => { - if (!type) { - return base; - } - const url = new URL$1(base); - url.pathname = `${url.pathname}.${type}`; - return url.href; - }; - - function binaryAjax$1(_url, type) { - return new Promise(function (resolve, reject) { - const url = combine$1(_url, type); - const ajax = new XMLHttpRequest(); - ajax.open('GET', url, true); - if (type !== 'prj' && type !== 'cpg') { - ajax.responseType = 'arraybuffer'; - } - ajax.addEventListener('load', function () { - if (ajax.status > 399) { - if (type === 'prj' || type === 'cpg') { - return resolve(false); - } else { - return reject(new Error(ajax.status)); - } - } - if (type !== 'prj' && type !== 'cpg') { - return resolve(Buffer.from(ajax.response)); - } else { - return resolve(ajax.response); - } - }, false); - ajax.send(); - }); - } - - async function binaryAjax(_url, type) { - if (!globalThis.fetch) { - return binaryAjax$1(_url, type); - } - const url = combine$1(_url, type); - const isOptionalTxt = type === 'prj' || type === 'cpg'; - try { - const resp = await fetch(url); - if (resp.status > 399) { - throw new Error(resp.statusText); - } - if (isOptionalTxt) { - return resp.text(); - } - const parsed = await resp.arrayBuffer(); - return Buffer.from(parsed); - } catch (e) { - console.log('ERROR', e, type); - if (isOptionalTxt || type === 'dbf') { - return false; - } - throw e; - } - } - - function isClockWise(array) { - let sum = 0; - let i = 1; - const len = array.length; - let prev, cur; - const bbox = [array[0][0], array[0][1], array[0][0], array[0][1]]; - while (i < len) { - prev = cur || array[0]; - cur = array[i]; - sum += ((cur[0] - prev[0]) * (cur[1] + prev[1])); - i++; - if (cur[0] < bbox[0]) { - bbox[0] = cur[0]; - } - if (cur[1] < bbox[1]) { - bbox[1] = cur[1]; - } - if (cur[0] > bbox[2]) { - bbox[2] = cur[0]; - } - if (cur[1] > bbox[3]) { - bbox[3] = cur[1]; - } - } - return { - ring: array, - clockWise: sum > 0, - bbox, - children: [] - } - - } - - function contains(outer, inner) { - if (outer.bbox[0] > inner.bbox[0]) { - return false; - } - if (outer.bbox[1] > inner.bbox[1]) { - return false; - } - if (outer.bbox[2] < inner.bbox[2]) { - return false; - } - if (outer.bbox[3] < inner.bbox[3]) { - return false; - } - return true; - } - - function handleRings(rings) { - const outers = []; - const inners = []; - for (const ring of rings) { - const proccessed = isClockWise(ring); - if (proccessed.clockWise) { - outers.push(proccessed); - } else { - inners.push(proccessed); - } - } - // this is an optimization, - // but it would also put in weird bad rings that would otherwise get left out - // if (outers.length === 1) { - // const out = [outers[0].ring] - // for (const inner of inners) { - // out.push(inner.ring); - - // } - // return [out]; - // } - for (const inner of inners) { - for (const outer of outers) { - if (contains(outer, inner)) { - outer.children.push(inner.ring); - break; - } - } - } - const out = []; - for (const outer of outers) { - out.push([outer.ring].concat(outer.children)); - } - return out; - } - ParseShp.prototype.parsePoint = function (data) { - return { - type: 'Point', - coordinates: this.parseCoord(data, 0) - }; + ParseShp.prototype.parsePoint = function (data) { + return { + type: 'Point', + coordinates: this.parseCoord(data, 0) + }; }; ParseShp.prototype.parseZPoint = function (data) { const pointXY = this.parsePoint(data); - pointXY.coordinates.push(data.readDoubleLE(16)); + pointXY.coordinates.push(data.getFloat64(16, true)); return pointXY; }; ParseShp.prototype.parsePointArray = function (data, offset, num) { @@ -9793,7 +7529,7 @@ ParseShp.prototype.parseZPointArray = function (data, zOffset, num, coordinates) { let i = 0; while (i < num) { - coordinates[i].push(data.readDoubleLE(zOffset)); + coordinates[i].push(data.getFloat64(zOffset, true)); i++; zOffset += 8; } @@ -9811,7 +7547,7 @@ if (done === num) { nextNum = tot; } else { - nextNum = data.readInt32LE(partOffset); + nextNum = data.getInt32(partOffset, true); } pointNumber = nextNum - curNum; if (!pointNumber) { @@ -9833,7 +7569,7 @@ }; ParseShp.prototype.parseMultiPoint = function (data) { const out = {}; - const num = data.readInt32LE(32, true); + const num = data.getInt32(32, true); if (!num) { return null; } @@ -9862,7 +7598,7 @@ } let num; if (geoJson.type === 'Point') { - geoJson.coordinates.push(data.readDoubleLE(72)); + geoJson.coordinates.push(data.getFloat64(72, true)); return geoJson; } else { num = geoJson.coordinates.length; @@ -9873,7 +7609,7 @@ }; ParseShp.prototype.parsePolyline = function (data) { const out = {}; - const numParts = data.readInt32LE(32); + const numParts = data.getInt32(32, true); if (!numParts) { return null; } @@ -9885,7 +7621,7 @@ maxs[0], maxs[1] ]; - const num = data.readInt32LE(36); + const num = data.getInt32(36, true); let offset, partOffset; if (numParts === 1) { out.type = 'LineString'; @@ -9959,12 +7695,12 @@ function makeParseCoord(trans) { if (trans) { return function (data, offset) { - const args = [data.readDoubleLE(offset), data.readDoubleLE(offset + 8)]; + const args = [data.getFloat64(offset, true), data.getFloat64(offset + 8, true)]; return trans.inverse(args); }; } else { return function (data, offset) { - return [data.readDoubleLE(offset), data.readDoubleLE(offset + 8)]; + return [data.getFloat64(offset, true), data.getFloat64(offset + 8, true)]; }; } } @@ -9984,7 +7720,7 @@ num -= 20; } if (!(num in shpFuncObj)) { - throw new Error('I don\'t know that shp type'); + throw new Error(`I don't know shp type "${num}"`); } this.parseFunc = this[shpFuncObj[num]]; this.parseCoord = makeParseCoord(tran); @@ -9993,27 +7729,26 @@ return this.parseHeader().shpCode; }; ParseShp.prototype.parseHeader = function () { - const view = this.buffer.subarray(0, 100); + const view = this.buffer; return { - length: view.readInt32BE(6 << 2) << 1, - version: view.readInt32LE(7 << 2), - shpCode: view.readInt32LE(8 << 2), + length: view.getInt32(6 << 2) << 1, + version: view.getInt32(7 << 2, true), + shpCode: view.getInt32(8 << 2, true), bbox: [ - view.readDoubleLE(9 << 2), - view.readDoubleLE(11 << 2), - view.readDoubleLE(13 << 2), - view.readDoubleLE(15 << 2) + view.getFloat64(9 << 2, true), + view.getFloat64(11 << 2, true), + view.getFloat64(13 << 2, true), + view.getFloat64(15 << 2, true) ] }; }; ParseShp.prototype.getRows = function () { let offset = 100; - const olen = this.buffer.byteLength; - const len = olen - 8; + const len = this.buffer.byteLength - 8; const out = []; let current; while (offset <= len) { - current = this.getRow(offset, olen); + current = this.getRow(offset); if (!current) { break; } @@ -10027,11 +7762,9 @@ } return out; }; - ParseShp.prototype.getRow = function (offset, bufLen) { - const view = this.buffer.subarray(offset, offset + 12); - const len = view.readInt32BE(4) << 1; - const id = view.readInt32BE(0); - + ParseShp.prototype.getRow = function (offset) { + const id = this.buffer.getInt32(offset); + const len = this.buffer.getInt32(offset + 4) << 1; if (len === 0) { return { id: id, @@ -10040,3558 +7773,39 @@ }; } - if (offset + len + 8 > bufLen) { + if (offset + len + 8 > this.buffer.byteLength) { return; } - return { id: id, len: len, - data: this.buffer.subarray(offset + 12, offset + len + 8), - type: view.readInt32LE(8) + data: new DataView(this.buffer.buffer, this.buffer.byteOffset + offset + 12, len - 4), + type: this.buffer.getInt32(offset + 8, true) }; }; function parseShp (buffer, trans) { return new ParseShp(buffer, trans).rows; } - var encoding = {exports: {}}; - - (function (module) { - // This is free and unencumbered software released into the public domain. - // See LICENSE.md for more information. - - /** - * @fileoverview Global |this| required for resolving indexes in node. - * @suppress {globalThis} - */ - (function(global) { - - // If we're in node require encoding-indexes and attach it to the global. - if (module.exports && - !global["encoding-indexes"]) ; - - // - // Utilities - // - - /** - * @param {number} a The number to test. - * @param {number} min The minimum value in the range, inclusive. - * @param {number} max The maximum value in the range, inclusive. - * @return {boolean} True if a >= min and a <= max. - */ - function inRange(a, min, max) { - return min <= a && a <= max; - } - - /** - * @param {!Array.<*>} array The array to check. - * @param {*} item The item to look for in the array. - * @return {boolean} True if the item appears in the array. - */ - function includes(array, item) { - return array.indexOf(item) !== -1; - } - - var floor = Math.floor; - - /** - * @param {*} o - * @return {Object} - */ - function ToDictionary(o) { - if (o === undefined) return {}; - if (o === Object(o)) return o; - throw TypeError('Could not convert argument to dictionary'); - } - - /** - * @param {string} string Input string of UTF-16 code units. - * @return {!Array.} Code points. - */ - function stringToCodePoints(string) { - // https://heycam.github.io/webidl/#dfn-obtain-unicode - - // 1. Let S be the DOMString value. - var s = String(string); - - // 2. Let n be the length of S. - var n = s.length; - - // 3. Initialize i to 0. - var i = 0; - - // 4. Initialize U to be an empty sequence of Unicode characters. - var u = []; - - // 5. While i < n: - while (i < n) { - - // 1. Let c be the code unit in S at index i. - var c = s.charCodeAt(i); - - // 2. Depending on the value of c: - - // c < 0xD800 or c > 0xDFFF - if (c < 0xD800 || c > 0xDFFF) { - // Append to U the Unicode character with code point c. - u.push(c); - } - - // 0xDC00 ≤ c ≤ 0xDFFF - else if (0xDC00 <= c && c <= 0xDFFF) { - // Append to U a U+FFFD REPLACEMENT CHARACTER. - u.push(0xFFFD); - } - - // 0xD800 ≤ c ≤ 0xDBFF - else if (0xD800 <= c && c <= 0xDBFF) { - // 1. If i = n−1, then append to U a U+FFFD REPLACEMENT - // CHARACTER. - if (i === n - 1) { - u.push(0xFFFD); - } - // 2. Otherwise, i < n−1: - else { - // 1. Let d be the code unit in S at index i+1. - var d = s.charCodeAt(i + 1); - - // 2. If 0xDC00 ≤ d ≤ 0xDFFF, then: - if (0xDC00 <= d && d <= 0xDFFF) { - // 1. Let a be c & 0x3FF. - var a = c & 0x3FF; - - // 2. Let b be d & 0x3FF. - var b = d & 0x3FF; - - // 3. Append to U the Unicode character with code point - // 2^16+2^10*a+b. - u.push(0x10000 + (a << 10) + b); - - // 4. Set i to i+1. - i += 1; - } - - // 3. Otherwise, d < 0xDC00 or d > 0xDFFF. Append to U a - // U+FFFD REPLACEMENT CHARACTER. - else { - u.push(0xFFFD); - } - } - } - - // 3. Set i to i+1. - i += 1; - } - - // 6. Return U. - return u; - } - - /** - * @param {!Array.} code_points Array of code points. - * @return {string} string String of UTF-16 code units. - */ - function codePointsToString(code_points) { - var s = ''; - for (var i = 0; i < code_points.length; ++i) { - var cp = code_points[i]; - if (cp <= 0xFFFF) { - s += String.fromCharCode(cp); - } else { - cp -= 0x10000; - s += String.fromCharCode((cp >> 10) + 0xD800, - (cp & 0x3FF) + 0xDC00); - } - } - return s; - } - - - // - // Implementation of Encoding specification - // https://encoding.spec.whatwg.org/ - // - - // - // 4. Terminology - // - - /** - * An ASCII byte is a byte in the range 0x00 to 0x7F, inclusive. - * @param {number} a The number to test. - * @return {boolean} True if a is in the range 0x00 to 0x7F, inclusive. - */ - function isASCIIByte(a) { - return 0x00 <= a && a <= 0x7F; - } - - /** - * An ASCII code point is a code point in the range U+0000 to - * U+007F, inclusive. - */ - var isASCIICodePoint = isASCIIByte; - - - /** - * End-of-stream is a special token that signifies no more tokens - * are in the stream. - * @const - */ var end_of_stream = -1; - - /** - * A stream represents an ordered sequence of tokens. - * - * @constructor - * @param {!(Array.|Uint8Array)} tokens Array of tokens that provide - * the stream. - */ - function Stream(tokens) { - /** @type {!Array.} */ - this.tokens = [].slice.call(tokens); - // Reversed as push/pop is more efficient than shift/unshift. - this.tokens.reverse(); - } - - Stream.prototype = { - /** - * @return {boolean} True if end-of-stream has been hit. - */ - endOfStream: function() { - return !this.tokens.length; - }, - - /** - * When a token is read from a stream, the first token in the - * stream must be returned and subsequently removed, and - * end-of-stream must be returned otherwise. - * - * @return {number} Get the next token from the stream, or - * end_of_stream. - */ - read: function() { - if (!this.tokens.length) - return end_of_stream; - return this.tokens.pop(); - }, - - /** - * When one or more tokens are prepended to a stream, those tokens - * must be inserted, in given order, before the first token in the - * stream. - * - * @param {(number|!Array.)} token The token(s) to prepend to the - * stream. - */ - prepend: function(token) { - if (Array.isArray(token)) { - var tokens = /**@type {!Array.}*/(token); - while (tokens.length) - this.tokens.push(tokens.pop()); - } else { - this.tokens.push(token); - } - }, - - /** - * When one or more tokens are pushed to a stream, those tokens - * must be inserted, in given order, after the last token in the - * stream. - * - * @param {(number|!Array.)} token The tokens(s) to push to the - * stream. - */ - push: function(token) { - if (Array.isArray(token)) { - var tokens = /**@type {!Array.}*/(token); - while (tokens.length) - this.tokens.unshift(tokens.shift()); - } else { - this.tokens.unshift(token); - } - } - }; - - // - // 5. Encodings - // - - // 5.1 Encoders and decoders - - /** @const */ - var finished = -1; - - /** - * @param {boolean} fatal If true, decoding errors raise an exception. - * @param {number=} opt_code_point Override the standard fallback code point. - * @return {number} The code point to insert on a decoding error. - */ - function decoderError(fatal, opt_code_point) { - if (fatal) - throw TypeError('Decoder error'); - return opt_code_point || 0xFFFD; - } - - /** - * @param {number} code_point The code point that could not be encoded. - * @return {number} Always throws, no value is actually returned. - */ - function encoderError(code_point) { - throw TypeError('The code point ' + code_point + ' could not be encoded.'); - } - - // 5.2 Names and labels - - // TODO: Define @typedef for Encoding: {name:string,labels:Array.} - // https://github.com/google/closure-compiler/issues/247 - - /** - * @param {string} label The encoding label. - * @return {?{name:string,labels:Array.}} - */ - function getEncoding(label) { - // 1. Remove any leading and trailing ASCII whitespace from label. - label = String(label).trim().toLowerCase(); - - // 2. If label is an ASCII case-insensitive match for any of the - // labels listed in the table below, return the corresponding - // encoding, and failure otherwise. - if (Object.prototype.hasOwnProperty.call(label_to_encoding, label)) { - return label_to_encoding[label]; - } - return null; - } - - /** - * Encodings table: https://encoding.spec.whatwg.org/encodings.json - * @const - * @type {!Array.<{ - * heading: string, - * encodings: Array.<{name:string,labels:Array.}> - * }>} - */ - var encodings = [ - { - "encodings": [ - { - "labels": [ - "unicode-1-1-utf-8", - "utf-8", - "utf8" - ], - "name": "UTF-8" - } - ], - "heading": "The Encoding" - }, - { - "encodings": [ - { - "labels": [ - "866", - "cp866", - "csibm866", - "ibm866" - ], - "name": "IBM866" - }, - { - "labels": [ - "csisolatin2", - "iso-8859-2", - "iso-ir-101", - "iso8859-2", - "iso88592", - "iso_8859-2", - "iso_8859-2:1987", - "l2", - "latin2" - ], - "name": "ISO-8859-2" - }, - { - "labels": [ - "csisolatin3", - "iso-8859-3", - "iso-ir-109", - "iso8859-3", - "iso88593", - "iso_8859-3", - "iso_8859-3:1988", - "l3", - "latin3" - ], - "name": "ISO-8859-3" - }, - { - "labels": [ - "csisolatin4", - "iso-8859-4", - "iso-ir-110", - "iso8859-4", - "iso88594", - "iso_8859-4", - "iso_8859-4:1988", - "l4", - "latin4" - ], - "name": "ISO-8859-4" - }, - { - "labels": [ - "csisolatincyrillic", - "cyrillic", - "iso-8859-5", - "iso-ir-144", - "iso8859-5", - "iso88595", - "iso_8859-5", - "iso_8859-5:1988" - ], - "name": "ISO-8859-5" - }, - { - "labels": [ - "arabic", - "asmo-708", - "csiso88596e", - "csiso88596i", - "csisolatinarabic", - "ecma-114", - "iso-8859-6", - "iso-8859-6-e", - "iso-8859-6-i", - "iso-ir-127", - "iso8859-6", - "iso88596", - "iso_8859-6", - "iso_8859-6:1987" - ], - "name": "ISO-8859-6" - }, - { - "labels": [ - "csisolatingreek", - "ecma-118", - "elot_928", - "greek", - "greek8", - "iso-8859-7", - "iso-ir-126", - "iso8859-7", - "iso88597", - "iso_8859-7", - "iso_8859-7:1987", - "sun_eu_greek" - ], - "name": "ISO-8859-7" - }, - { - "labels": [ - "csiso88598e", - "csisolatinhebrew", - "hebrew", - "iso-8859-8", - "iso-8859-8-e", - "iso-ir-138", - "iso8859-8", - "iso88598", - "iso_8859-8", - "iso_8859-8:1988", - "visual" - ], - "name": "ISO-8859-8" - }, - { - "labels": [ - "csiso88598i", - "iso-8859-8-i", - "logical" - ], - "name": "ISO-8859-8-I" - }, - { - "labels": [ - "csisolatin6", - "iso-8859-10", - "iso-ir-157", - "iso8859-10", - "iso885910", - "l6", - "latin6" - ], - "name": "ISO-8859-10" - }, - { - "labels": [ - "iso-8859-13", - "iso8859-13", - "iso885913" - ], - "name": "ISO-8859-13" - }, - { - "labels": [ - "iso-8859-14", - "iso8859-14", - "iso885914" - ], - "name": "ISO-8859-14" - }, - { - "labels": [ - "csisolatin9", - "iso-8859-15", - "iso8859-15", - "iso885915", - "iso_8859-15", - "l9" - ], - "name": "ISO-8859-15" - }, - { - "labels": [ - "iso-8859-16" - ], - "name": "ISO-8859-16" - }, - { - "labels": [ - "cskoi8r", - "koi", - "koi8", - "koi8-r", - "koi8_r" - ], - "name": "KOI8-R" - }, - { - "labels": [ - "koi8-ru", - "koi8-u" - ], - "name": "KOI8-U" - }, - { - "labels": [ - "csmacintosh", - "mac", - "macintosh", - "x-mac-roman" - ], - "name": "macintosh" - }, - { - "labels": [ - "dos-874", - "iso-8859-11", - "iso8859-11", - "iso885911", - "tis-620", - "windows-874" - ], - "name": "windows-874" - }, - { - "labels": [ - "cp1250", - "windows-1250", - "x-cp1250" - ], - "name": "windows-1250" - }, - { - "labels": [ - "cp1251", - "windows-1251", - "x-cp1251" - ], - "name": "windows-1251" - }, - { - "labels": [ - "ansi_x3.4-1968", - "ascii", - "cp1252", - "cp819", - "csisolatin1", - "ibm819", - "iso-8859-1", - "iso-ir-100", - "iso8859-1", - "iso88591", - "iso_8859-1", - "iso_8859-1:1987", - "l1", - "latin1", - "us-ascii", - "windows-1252", - "x-cp1252" - ], - "name": "windows-1252" - }, - { - "labels": [ - "cp1253", - "windows-1253", - "x-cp1253" - ], - "name": "windows-1253" - }, - { - "labels": [ - "cp1254", - "csisolatin5", - "iso-8859-9", - "iso-ir-148", - "iso8859-9", - "iso88599", - "iso_8859-9", - "iso_8859-9:1989", - "l5", - "latin5", - "windows-1254", - "x-cp1254" - ], - "name": "windows-1254" - }, - { - "labels": [ - "cp1255", - "windows-1255", - "x-cp1255" - ], - "name": "windows-1255" - }, - { - "labels": [ - "cp1256", - "windows-1256", - "x-cp1256" - ], - "name": "windows-1256" - }, - { - "labels": [ - "cp1257", - "windows-1257", - "x-cp1257" - ], - "name": "windows-1257" - }, - { - "labels": [ - "cp1258", - "windows-1258", - "x-cp1258" - ], - "name": "windows-1258" - }, - { - "labels": [ - "x-mac-cyrillic", - "x-mac-ukrainian" - ], - "name": "x-mac-cyrillic" - } - ], - "heading": "Legacy single-byte encodings" - }, - { - "encodings": [ - { - "labels": [ - "chinese", - "csgb2312", - "csiso58gb231280", - "gb2312", - "gb_2312", - "gb_2312-80", - "gbk", - "iso-ir-58", - "x-gbk" - ], - "name": "GBK" - }, - { - "labels": [ - "gb18030" - ], - "name": "gb18030" - } - ], - "heading": "Legacy multi-byte Chinese (simplified) encodings" - }, - { - "encodings": [ - { - "labels": [ - "big5", - "big5-hkscs", - "cn-big5", - "csbig5", - "x-x-big5" - ], - "name": "Big5" - } - ], - "heading": "Legacy multi-byte Chinese (traditional) encodings" - }, - { - "encodings": [ - { - "labels": [ - "cseucpkdfmtjapanese", - "euc-jp", - "x-euc-jp" - ], - "name": "EUC-JP" - }, - { - "labels": [ - "csiso2022jp", - "iso-2022-jp" - ], - "name": "ISO-2022-JP" - }, - { - "labels": [ - "csshiftjis", - "ms932", - "ms_kanji", - "shift-jis", - "shift_jis", - "sjis", - "windows-31j", - "x-sjis" - ], - "name": "Shift_JIS" - } - ], - "heading": "Legacy multi-byte Japanese encodings" - }, - { - "encodings": [ - { - "labels": [ - "cseuckr", - "csksc56011987", - "euc-kr", - "iso-ir-149", - "korean", - "ks_c_5601-1987", - "ks_c_5601-1989", - "ksc5601", - "ksc_5601", - "windows-949" - ], - "name": "EUC-KR" - } - ], - "heading": "Legacy multi-byte Korean encodings" - }, - { - "encodings": [ - { - "labels": [ - "csiso2022kr", - "hz-gb-2312", - "iso-2022-cn", - "iso-2022-cn-ext", - "iso-2022-kr" - ], - "name": "replacement" - }, - { - "labels": [ - "utf-16be" - ], - "name": "UTF-16BE" - }, - { - "labels": [ - "utf-16", - "utf-16le" - ], - "name": "UTF-16LE" - }, - { - "labels": [ - "x-user-defined" - ], - "name": "x-user-defined" - } - ], - "heading": "Legacy miscellaneous encodings" - } - ]; - - // Label to encoding registry. - /** @type {Object.}>} */ - var label_to_encoding = {}; - encodings.forEach(function(category) { - category.encodings.forEach(function(encoding) { - encoding.labels.forEach(function(label) { - label_to_encoding[label] = encoding; - }); - }); - }); - - // Registry of of encoder/decoder factories, by encoding name. - /** @type {Object.} */ - var encoders = {}; - /** @type {Object.} */ - var decoders = {}; - - // - // 6. Indexes - // - - /** - * @param {number} pointer The |pointer| to search for. - * @param {(!Array.|undefined)} index The |index| to search within. - * @return {?number} The code point corresponding to |pointer| in |index|, - * or null if |code point| is not in |index|. - */ - function indexCodePointFor(pointer, index) { - if (!index) return null; - return index[pointer] || null; - } - - /** - * @param {number} code_point The |code point| to search for. - * @param {!Array.} index The |index| to search within. - * @return {?number} The first pointer corresponding to |code point| in - * |index|, or null if |code point| is not in |index|. - */ - function indexPointerFor(code_point, index) { - var pointer = index.indexOf(code_point); - return pointer === -1 ? null : pointer; - } - - /** - * @param {string} name Name of the index. - * @return {(!Array.|!Array.>)} - * */ - function index(name) { - if (!('encoding-indexes' in global)) { - throw Error("Indexes missing." + - " Did you forget to include encoding-indexes.js first?"); - } - return global['encoding-indexes'][name]; - } - - /** - * @param {number} pointer The |pointer| to search for in the gb18030 index. - * @return {?number} The code point corresponding to |pointer| in |index|, - * or null if |code point| is not in the gb18030 index. - */ - function indexGB18030RangesCodePointFor(pointer) { - // 1. If pointer is greater than 39419 and less than 189000, or - // pointer is greater than 1237575, return null. - if ((pointer > 39419 && pointer < 189000) || (pointer > 1237575)) - return null; - - // 2. If pointer is 7457, return code point U+E7C7. - if (pointer === 7457) return 0xE7C7; - - // 3. Let offset be the last pointer in index gb18030 ranges that - // is equal to or less than pointer and let code point offset be - // its corresponding code point. - var offset = 0; - var code_point_offset = 0; - var idx = index('gb18030-ranges'); - var i; - for (i = 0; i < idx.length; ++i) { - /** @type {!Array.} */ - var entry = idx[i]; - if (entry[0] <= pointer) { - offset = entry[0]; - code_point_offset = entry[1]; - } else { - break; - } - } - - // 4. Return a code point whose value is code point offset + - // pointer − offset. - return code_point_offset + pointer - offset; - } - - /** - * @param {number} code_point The |code point| to locate in the gb18030 index. - * @return {number} The first pointer corresponding to |code point| in the - * gb18030 index. - */ - function indexGB18030RangesPointerFor(code_point) { - // 1. If code point is U+E7C7, return pointer 7457. - if (code_point === 0xE7C7) return 7457; - - // 2. Let offset be the last code point in index gb18030 ranges - // that is equal to or less than code point and let pointer offset - // be its corresponding pointer. - var offset = 0; - var pointer_offset = 0; - var idx = index('gb18030-ranges'); - var i; - for (i = 0; i < idx.length; ++i) { - /** @type {!Array.} */ - var entry = idx[i]; - if (entry[1] <= code_point) { - offset = entry[1]; - pointer_offset = entry[0]; - } else { - break; - } - } - - // 3. Return a pointer whose value is pointer offset + code point - // − offset. - return pointer_offset + code_point - offset; - } - - /** - * @param {number} code_point The |code_point| to search for in the Shift_JIS - * index. - * @return {?number} The code point corresponding to |pointer| in |index|, - * or null if |code point| is not in the Shift_JIS index. - */ - function indexShiftJISPointerFor(code_point) { - // 1. Let index be index jis0208 excluding all entries whose - // pointer is in the range 8272 to 8835, inclusive. - shift_jis_index = shift_jis_index || - index('jis0208').map(function(code_point, pointer) { - return inRange(pointer, 8272, 8835) ? null : code_point; - }); - var index_ = shift_jis_index; - - // 2. Return the index pointer for code point in index. - return index_.indexOf(code_point); - } - var shift_jis_index; - - /** - * @param {number} code_point The |code_point| to search for in the big5 - * index. - * @return {?number} The code point corresponding to |pointer| in |index|, - * or null if |code point| is not in the big5 index. - */ - function indexBig5PointerFor(code_point) { - // 1. Let index be index Big5 excluding all entries whose pointer - big5_index_no_hkscs = big5_index_no_hkscs || - index('big5').map(function(code_point, pointer) { - return (pointer < (0xA1 - 0x81) * 157) ? null : code_point; - }); - var index_ = big5_index_no_hkscs; - - // 2. If code point is U+2550, U+255E, U+2561, U+256A, U+5341, or - // U+5345, return the last pointer corresponding to code point in - // index. - if (code_point === 0x2550 || code_point === 0x255E || - code_point === 0x2561 || code_point === 0x256A || - code_point === 0x5341 || code_point === 0x5345) { - return index_.lastIndexOf(code_point); - } - - // 3. Return the index pointer for code point in index. - return indexPointerFor(code_point, index_); - } - var big5_index_no_hkscs; - - // - // 8. API - // - - /** @const */ var DEFAULT_ENCODING = 'utf-8'; - - // 8.1 Interface TextDecoder - - /** - * @constructor - * @param {string=} label The label of the encoding; - * defaults to 'utf-8'. - * @param {Object=} options - */ - function TextDecoder(label, options) { - // Web IDL conventions - if (!(this instanceof TextDecoder)) - throw TypeError('Called as a function. Did you forget \'new\'?'); - label = label !== undefined ? String(label) : DEFAULT_ENCODING; - options = ToDictionary(options); - - // A TextDecoder object has an associated encoding, decoder, - // stream, ignore BOM flag (initially unset), BOM seen flag - // (initially unset), error mode (initially replacement), and do - // not flush flag (initially unset). - - /** @private */ - this._encoding = null; - /** @private @type {?Decoder} */ - this._decoder = null; - /** @private @type {boolean} */ - this._ignoreBOM = false; - /** @private @type {boolean} */ - this._BOMseen = false; - /** @private @type {string} */ - this._error_mode = 'replacement'; - /** @private @type {boolean} */ - this._do_not_flush = false; - - - // 1. Let encoding be the result of getting an encoding from - // label. - var encoding = getEncoding(label); - - // 2. If encoding is failure or replacement, throw a RangeError. - if (encoding === null || encoding.name === 'replacement') - throw RangeError('Unknown encoding: ' + label); - if (!decoders[encoding.name]) { - throw Error('Decoder not present.' + - ' Did you forget to include encoding-indexes.js first?'); - } - - // 3. Let dec be a new TextDecoder object. - var dec = this; - - // 4. Set dec's encoding to encoding. - dec._encoding = encoding; - - // 5. If options's fatal member is true, set dec's error mode to - // fatal. - if (Boolean(options['fatal'])) - dec._error_mode = 'fatal'; - - // 6. If options's ignoreBOM member is true, set dec's ignore BOM - // flag. - if (Boolean(options['ignoreBOM'])) - dec._ignoreBOM = true; - - // For pre-ES5 runtimes: - if (!Object.defineProperty) { - this.encoding = dec._encoding.name.toLowerCase(); - this.fatal = dec._error_mode === 'fatal'; - this.ignoreBOM = dec._ignoreBOM; - } - - // 7. Return dec. - return dec; - } - - if (Object.defineProperty) { - // The encoding attribute's getter must return encoding's name. - Object.defineProperty(TextDecoder.prototype, 'encoding', { - /** @this {TextDecoder} */ - get: function() { return this._encoding.name.toLowerCase(); } - }); - - // The fatal attribute's getter must return true if error mode - // is fatal, and false otherwise. - Object.defineProperty(TextDecoder.prototype, 'fatal', { - /** @this {TextDecoder} */ - get: function() { return this._error_mode === 'fatal'; } - }); - - // The ignoreBOM attribute's getter must return true if ignore - // BOM flag is set, and false otherwise. - Object.defineProperty(TextDecoder.prototype, 'ignoreBOM', { - /** @this {TextDecoder} */ - get: function() { return this._ignoreBOM; } - }); - } - - /** - * @param {BufferSource=} input The buffer of bytes to decode. - * @param {Object=} options - * @return {string} The decoded string. - */ - TextDecoder.prototype.decode = function decode(input, options) { - var bytes; - if (typeof input === 'object' && input instanceof ArrayBuffer) { - bytes = new Uint8Array(input); - } else if (typeof input === 'object' && 'buffer' in input && - input.buffer instanceof ArrayBuffer) { - bytes = new Uint8Array(input.buffer, - input.byteOffset, - input.byteLength); - } else { - bytes = new Uint8Array(0); - } - - options = ToDictionary(options); - - // 1. If the do not flush flag is unset, set decoder to a new - // encoding's decoder, set stream to a new stream, and unset the - // BOM seen flag. - if (!this._do_not_flush) { - this._decoder = decoders[this._encoding.name]({ - fatal: this._error_mode === 'fatal'}); - this._BOMseen = false; - } - - // 2. If options's stream is true, set the do not flush flag, and - // unset the do not flush flag otherwise. - this._do_not_flush = Boolean(options['stream']); - - // 3. If input is given, push a copy of input to stream. - // TODO: Align with spec algorithm - maintain stream on instance. - var input_stream = new Stream(bytes); - - // 4. Let output be a new stream. - var output = []; - - /** @type {?(number|!Array.)} */ - var result; - - // 5. While true: - while (true) { - // 1. Let token be the result of reading from stream. - var token = input_stream.read(); - - // 2. If token is end-of-stream and the do not flush flag is - // set, return output, serialized. - // TODO: Align with spec algorithm. - if (token === end_of_stream) - break; - - // 3. Otherwise, run these subsubsteps: - - // 1. Let result be the result of processing token for decoder, - // stream, output, and error mode. - result = this._decoder.handler(input_stream, token); - - // 2. If result is finished, return output, serialized. - if (result === finished) - break; - - if (result !== null) { - if (Array.isArray(result)) - output.push.apply(output, /**@type {!Array.}*/(result)); - else - output.push(result); - } - - // 3. Otherwise, if result is error, throw a TypeError. - // (Thrown in handler) - - // 4. Otherwise, do nothing. - } - // TODO: Align with spec algorithm. - if (!this._do_not_flush) { - do { - result = this._decoder.handler(input_stream, input_stream.read()); - if (result === finished) - break; - if (result === null) - continue; - if (Array.isArray(result)) - output.push.apply(output, /**@type {!Array.}*/(result)); - else - output.push(result); - } while (!input_stream.endOfStream()); - this._decoder = null; - } - - // A TextDecoder object also has an associated serialize stream - // algorithm... - /** - * @param {!Array.} stream - * @return {string} - * @this {TextDecoder} - */ - function serializeStream(stream) { - // 1. Let token be the result of reading from stream. - // (Done in-place on array, rather than as a stream) - - // 2. If encoding is UTF-8, UTF-16BE, or UTF-16LE, and ignore - // BOM flag and BOM seen flag are unset, run these subsubsteps: - if (includes(['UTF-8', 'UTF-16LE', 'UTF-16BE'], this._encoding.name) && - !this._ignoreBOM && !this._BOMseen) { - if (stream.length > 0 && stream[0] === 0xFEFF) { - // 1. If token is U+FEFF, set BOM seen flag. - this._BOMseen = true; - stream.shift(); - } else if (stream.length > 0) { - // 2. Otherwise, if token is not end-of-stream, set BOM seen - // flag and append token to stream. - this._BOMseen = true; - } else ; - } - // 4. Otherwise, return output. - return codePointsToString(stream); - } - - return serializeStream.call(this, output); - }; - - // 8.2 Interface TextEncoder - - /** - * @constructor - * @param {string=} label The label of the encoding. NONSTANDARD. - * @param {Object=} options NONSTANDARD. - */ - function TextEncoder(label, options) { - // Web IDL conventions - if (!(this instanceof TextEncoder)) - throw TypeError('Called as a function. Did you forget \'new\'?'); - options = ToDictionary(options); - - // A TextEncoder object has an associated encoding and encoder. - - /** @private */ - this._encoding = null; - /** @private @type {?Encoder} */ - this._encoder = null; - - // Non-standard - /** @private @type {boolean} */ - this._do_not_flush = false; - /** @private @type {string} */ - this._fatal = Boolean(options['fatal']) ? 'fatal' : 'replacement'; - - // 1. Let enc be a new TextEncoder object. - var enc = this; - - // 2. Set enc's encoding to UTF-8's encoder. - if (Boolean(options['NONSTANDARD_allowLegacyEncoding'])) { - // NONSTANDARD behavior. - label = label !== undefined ? String(label) : DEFAULT_ENCODING; - var encoding = getEncoding(label); - if (encoding === null || encoding.name === 'replacement') - throw RangeError('Unknown encoding: ' + label); - if (!encoders[encoding.name]) { - throw Error('Encoder not present.' + - ' Did you forget to include encoding-indexes.js first?'); - } - enc._encoding = encoding; - } else { - // Standard behavior. - enc._encoding = getEncoding('utf-8'); - - if (label !== undefined && 'console' in global) { - console.warn('TextEncoder constructor called with encoding label, ' - + 'which is ignored.'); - } - } - - // For pre-ES5 runtimes: - if (!Object.defineProperty) - this.encoding = enc._encoding.name.toLowerCase(); - - // 3. Return enc. - return enc; - } - - if (Object.defineProperty) { - // The encoding attribute's getter must return encoding's name. - Object.defineProperty(TextEncoder.prototype, 'encoding', { - /** @this {TextEncoder} */ - get: function() { return this._encoding.name.toLowerCase(); } - }); - } - - /** - * @param {string=} opt_string The string to encode. - * @param {Object=} options - * @return {!Uint8Array} Encoded bytes, as a Uint8Array. - */ - TextEncoder.prototype.encode = function encode(opt_string, options) { - opt_string = opt_string === undefined ? '' : String(opt_string); - options = ToDictionary(options); - - // NOTE: This option is nonstandard. None of the encodings - // permitted for encoding (i.e. UTF-8, UTF-16) are stateful when - // the input is a USVString so streaming is not necessary. - if (!this._do_not_flush) - this._encoder = encoders[this._encoding.name]({ - fatal: this._fatal === 'fatal'}); - this._do_not_flush = Boolean(options['stream']); - - // 1. Convert input to a stream. - var input = new Stream(stringToCodePoints(opt_string)); - - // 2. Let output be a new stream - var output = []; - - /** @type {?(number|!Array.)} */ - var result; - // 3. While true, run these substeps: - while (true) { - // 1. Let token be the result of reading from input. - var token = input.read(); - if (token === end_of_stream) - break; - // 2. Let result be the result of processing token for encoder, - // input, output. - result = this._encoder.handler(input, token); - if (result === finished) - break; - if (Array.isArray(result)) - output.push.apply(output, /**@type {!Array.}*/(result)); - else - output.push(result); - } - // TODO: Align with spec algorithm. - if (!this._do_not_flush) { - while (true) { - result = this._encoder.handler(input, input.read()); - if (result === finished) - break; - if (Array.isArray(result)) - output.push.apply(output, /**@type {!Array.}*/(result)); - else - output.push(result); - } - this._encoder = null; - } - // 3. If result is finished, convert output into a byte sequence, - // and then return a Uint8Array object wrapping an ArrayBuffer - // containing output. - return new Uint8Array(output); - }; - - - // - // 9. The encoding - // - - // 9.1 utf-8 - - // 9.1.1 utf-8 decoder - /** - * @constructor - * @implements {Decoder} - * @param {{fatal: boolean}} options - */ - function UTF8Decoder(options) { - var fatal = options.fatal; - - // utf-8's decoder's has an associated utf-8 code point, utf-8 - // bytes seen, and utf-8 bytes needed (all initially 0), a utf-8 - // lower boundary (initially 0x80), and a utf-8 upper boundary - // (initially 0xBF). - var /** @type {number} */ utf8_code_point = 0, - /** @type {number} */ utf8_bytes_seen = 0, - /** @type {number} */ utf8_bytes_needed = 0, - /** @type {number} */ utf8_lower_boundary = 0x80, - /** @type {number} */ utf8_upper_boundary = 0xBF; - - /** - * @param {Stream} stream The stream of bytes being decoded. - * @param {number} bite The next byte read from the stream. - * @return {?(number|!Array.)} The next code point(s) - * decoded, or null if not enough data exists in the input - * stream to decode a complete code point. - */ - this.handler = function(stream, bite) { - // 1. If byte is end-of-stream and utf-8 bytes needed is not 0, - // set utf-8 bytes needed to 0 and return error. - if (bite === end_of_stream && utf8_bytes_needed !== 0) { - utf8_bytes_needed = 0; - return decoderError(fatal); - } - - // 2. If byte is end-of-stream, return finished. - if (bite === end_of_stream) - return finished; - - // 3. If utf-8 bytes needed is 0, based on byte: - if (utf8_bytes_needed === 0) { - - // 0x00 to 0x7F - if (inRange(bite, 0x00, 0x7F)) { - // Return a code point whose value is byte. - return bite; - } - - // 0xC2 to 0xDF - else if (inRange(bite, 0xC2, 0xDF)) { - // 1. Set utf-8 bytes needed to 1. - utf8_bytes_needed = 1; - - // 2. Set UTF-8 code point to byte & 0x1F. - utf8_code_point = bite & 0x1F; - } - - // 0xE0 to 0xEF - else if (inRange(bite, 0xE0, 0xEF)) { - // 1. If byte is 0xE0, set utf-8 lower boundary to 0xA0. - if (bite === 0xE0) - utf8_lower_boundary = 0xA0; - // 2. If byte is 0xED, set utf-8 upper boundary to 0x9F. - if (bite === 0xED) - utf8_upper_boundary = 0x9F; - // 3. Set utf-8 bytes needed to 2. - utf8_bytes_needed = 2; - // 4. Set UTF-8 code point to byte & 0xF. - utf8_code_point = bite & 0xF; - } - - // 0xF0 to 0xF4 - else if (inRange(bite, 0xF0, 0xF4)) { - // 1. If byte is 0xF0, set utf-8 lower boundary to 0x90. - if (bite === 0xF0) - utf8_lower_boundary = 0x90; - // 2. If byte is 0xF4, set utf-8 upper boundary to 0x8F. - if (bite === 0xF4) - utf8_upper_boundary = 0x8F; - // 3. Set utf-8 bytes needed to 3. - utf8_bytes_needed = 3; - // 4. Set UTF-8 code point to byte & 0x7. - utf8_code_point = bite & 0x7; - } - - // Otherwise - else { - // Return error. - return decoderError(fatal); - } - - // Return continue. - return null; - } - - // 4. If byte is not in the range utf-8 lower boundary to utf-8 - // upper boundary, inclusive, run these substeps: - if (!inRange(bite, utf8_lower_boundary, utf8_upper_boundary)) { - - // 1. Set utf-8 code point, utf-8 bytes needed, and utf-8 - // bytes seen to 0, set utf-8 lower boundary to 0x80, and set - // utf-8 upper boundary to 0xBF. - utf8_code_point = utf8_bytes_needed = utf8_bytes_seen = 0; - utf8_lower_boundary = 0x80; - utf8_upper_boundary = 0xBF; - - // 2. Prepend byte to stream. - stream.prepend(bite); - - // 3. Return error. - return decoderError(fatal); - } - - // 5. Set utf-8 lower boundary to 0x80 and utf-8 upper boundary - // to 0xBF. - utf8_lower_boundary = 0x80; - utf8_upper_boundary = 0xBF; - - // 6. Set UTF-8 code point to (UTF-8 code point << 6) | (byte & - // 0x3F) - utf8_code_point = (utf8_code_point << 6) | (bite & 0x3F); - - // 7. Increase utf-8 bytes seen by one. - utf8_bytes_seen += 1; - - // 8. If utf-8 bytes seen is not equal to utf-8 bytes needed, - // continue. - if (utf8_bytes_seen !== utf8_bytes_needed) - return null; - - // 9. Let code point be utf-8 code point. - var code_point = utf8_code_point; - - // 10. Set utf-8 code point, utf-8 bytes needed, and utf-8 bytes - // seen to 0. - utf8_code_point = utf8_bytes_needed = utf8_bytes_seen = 0; - - // 11. Return a code point whose value is code point. - return code_point; - }; - } - - // 9.1.2 utf-8 encoder - /** - * @constructor - * @implements {Encoder} - * @param {{fatal: boolean}} options - */ - function UTF8Encoder(options) { - options.fatal; - /** - * @param {Stream} stream Input stream. - * @param {number} code_point Next code point read from the stream. - * @return {(number|!Array.)} Byte(s) to emit. - */ - this.handler = function(stream, code_point) { - // 1. If code point is end-of-stream, return finished. - if (code_point === end_of_stream) - return finished; - - // 2. If code point is an ASCII code point, return a byte whose - // value is code point. - if (isASCIICodePoint(code_point)) - return code_point; - - // 3. Set count and offset based on the range code point is in: - var count, offset; - // U+0080 to U+07FF, inclusive: - if (inRange(code_point, 0x0080, 0x07FF)) { - // 1 and 0xC0 - count = 1; - offset = 0xC0; - } - // U+0800 to U+FFFF, inclusive: - else if (inRange(code_point, 0x0800, 0xFFFF)) { - // 2 and 0xE0 - count = 2; - offset = 0xE0; - } - // U+10000 to U+10FFFF, inclusive: - else if (inRange(code_point, 0x10000, 0x10FFFF)) { - // 3 and 0xF0 - count = 3; - offset = 0xF0; - } - - // 4. Let bytes be a byte sequence whose first byte is (code - // point >> (6 × count)) + offset. - var bytes = [(code_point >> (6 * count)) + offset]; - - // 5. Run these substeps while count is greater than 0: - while (count > 0) { - - // 1. Set temp to code point >> (6 × (count − 1)). - var temp = code_point >> (6 * (count - 1)); - - // 2. Append to bytes 0x80 | (temp & 0x3F). - bytes.push(0x80 | (temp & 0x3F)); - - // 3. Decrease count by one. - count -= 1; - } - - // 6. Return bytes bytes, in order. - return bytes; - }; - } - - /** @param {{fatal: boolean}} options */ - encoders['UTF-8'] = function(options) { - return new UTF8Encoder(options); - }; - /** @param {{fatal: boolean}} options */ - decoders['UTF-8'] = function(options) { - return new UTF8Decoder(options); - }; - - // - // 10. Legacy single-byte encodings - // - - // 10.1 single-byte decoder - /** - * @constructor - * @implements {Decoder} - * @param {!Array.} index The encoding index. - * @param {{fatal: boolean}} options - */ - function SingleByteDecoder(index, options) { - var fatal = options.fatal; - /** - * @param {Stream} stream The stream of bytes being decoded. - * @param {number} bite The next byte read from the stream. - * @return {?(number|!Array.)} The next code point(s) - * decoded, or null if not enough data exists in the input - * stream to decode a complete code point. - */ - this.handler = function(stream, bite) { - // 1. If byte is end-of-stream, return finished. - if (bite === end_of_stream) - return finished; - - // 2. If byte is an ASCII byte, return a code point whose value - // is byte. - if (isASCIIByte(bite)) - return bite; - - // 3. Let code point be the index code point for byte − 0x80 in - // index single-byte. - var code_point = index[bite - 0x80]; - - // 4. If code point is null, return error. - if (code_point === null) - return decoderError(fatal); - - // 5. Return a code point whose value is code point. - return code_point; - }; - } - - // 10.2 single-byte encoder - /** - * @constructor - * @implements {Encoder} - * @param {!Array.} index The encoding index. - * @param {{fatal: boolean}} options - */ - function SingleByteEncoder(index, options) { - options.fatal; - /** - * @param {Stream} stream Input stream. - * @param {number} code_point Next code point read from the stream. - * @return {(number|!Array.)} Byte(s) to emit. - */ - this.handler = function(stream, code_point) { - // 1. If code point is end-of-stream, return finished. - if (code_point === end_of_stream) - return finished; - - // 2. If code point is an ASCII code point, return a byte whose - // value is code point. - if (isASCIICodePoint(code_point)) - return code_point; - - // 3. Let pointer be the index pointer for code point in index - // single-byte. - var pointer = indexPointerFor(code_point, index); - - // 4. If pointer is null, return error with code point. - if (pointer === null) - encoderError(code_point); - - // 5. Return a byte whose value is pointer + 0x80. - return pointer + 0x80; - }; - } - - (function() { - if (!('encoding-indexes' in global)) - return; - encodings.forEach(function(category) { - if (category.heading !== 'Legacy single-byte encodings') - return; - category.encodings.forEach(function(encoding) { - var name = encoding.name; - var idx = index(name.toLowerCase()); - /** @param {{fatal: boolean}} options */ - decoders[name] = function(options) { - return new SingleByteDecoder(idx, options); - }; - /** @param {{fatal: boolean}} options */ - encoders[name] = function(options) { - return new SingleByteEncoder(idx, options); - }; - }); - }); - }()); - - // - // 11. Legacy multi-byte Chinese (simplified) encodings - // - - // 11.1 gbk - - // 11.1.1 gbk decoder - // gbk's decoder is gb18030's decoder. - /** @param {{fatal: boolean}} options */ - decoders['GBK'] = function(options) { - return new GB18030Decoder(options); - }; - - // 11.1.2 gbk encoder - // gbk's encoder is gb18030's encoder with its gbk flag set. - /** @param {{fatal: boolean}} options */ - encoders['GBK'] = function(options) { - return new GB18030Encoder(options, true); - }; - - // 11.2 gb18030 - - // 11.2.1 gb18030 decoder - /** - * @constructor - * @implements {Decoder} - * @param {{fatal: boolean}} options - */ - function GB18030Decoder(options) { - var fatal = options.fatal; - // gb18030's decoder has an associated gb18030 first, gb18030 - // second, and gb18030 third (all initially 0x00). - var /** @type {number} */ gb18030_first = 0x00, - /** @type {number} */ gb18030_second = 0x00, - /** @type {number} */ gb18030_third = 0x00; - /** - * @param {Stream} stream The stream of bytes being decoded. - * @param {number} bite The next byte read from the stream. - * @return {?(number|!Array.)} The next code point(s) - * decoded, or null if not enough data exists in the input - * stream to decode a complete code point. - */ - this.handler = function(stream, bite) { - // 1. If byte is end-of-stream and gb18030 first, gb18030 - // second, and gb18030 third are 0x00, return finished. - if (bite === end_of_stream && gb18030_first === 0x00 && - gb18030_second === 0x00 && gb18030_third === 0x00) { - return finished; - } - // 2. If byte is end-of-stream, and gb18030 first, gb18030 - // second, or gb18030 third is not 0x00, set gb18030 first, - // gb18030 second, and gb18030 third to 0x00, and return error. - if (bite === end_of_stream && - (gb18030_first !== 0x00 || gb18030_second !== 0x00 || - gb18030_third !== 0x00)) { - gb18030_first = 0x00; - gb18030_second = 0x00; - gb18030_third = 0x00; - decoderError(fatal); - } - var code_point; - // 3. If gb18030 third is not 0x00, run these substeps: - if (gb18030_third !== 0x00) { - // 1. Let code point be null. - code_point = null; - // 2. If byte is in the range 0x30 to 0x39, inclusive, set - // code point to the index gb18030 ranges code point for - // (((gb18030 first − 0x81) × 10 + gb18030 second − 0x30) × - // 126 + gb18030 third − 0x81) × 10 + byte − 0x30. - if (inRange(bite, 0x30, 0x39)) { - code_point = indexGB18030RangesCodePointFor( - (((gb18030_first - 0x81) * 10 + gb18030_second - 0x30) * 126 + - gb18030_third - 0x81) * 10 + bite - 0x30); - } - - // 3. Let buffer be a byte sequence consisting of gb18030 - // second, gb18030 third, and byte, in order. - var buffer = [gb18030_second, gb18030_third, bite]; - - // 4. Set gb18030 first, gb18030 second, and gb18030 third to - // 0x00. - gb18030_first = 0x00; - gb18030_second = 0x00; - gb18030_third = 0x00; - - // 5. If code point is null, prepend buffer to stream and - // return error. - if (code_point === null) { - stream.prepend(buffer); - return decoderError(fatal); - } - - // 6. Return a code point whose value is code point. - return code_point; - } - - // 4. If gb18030 second is not 0x00, run these substeps: - if (gb18030_second !== 0x00) { - - // 1. If byte is in the range 0x81 to 0xFE, inclusive, set - // gb18030 third to byte and return continue. - if (inRange(bite, 0x81, 0xFE)) { - gb18030_third = bite; - return null; - } - - // 2. Prepend gb18030 second followed by byte to stream, set - // gb18030 first and gb18030 second to 0x00, and return error. - stream.prepend([gb18030_second, bite]); - gb18030_first = 0x00; - gb18030_second = 0x00; - return decoderError(fatal); - } - - // 5. If gb18030 first is not 0x00, run these substeps: - if (gb18030_first !== 0x00) { - - // 1. If byte is in the range 0x30 to 0x39, inclusive, set - // gb18030 second to byte and return continue. - if (inRange(bite, 0x30, 0x39)) { - gb18030_second = bite; - return null; - } - - // 2. Let lead be gb18030 first, let pointer be null, and set - // gb18030 first to 0x00. - var lead = gb18030_first; - var pointer = null; - gb18030_first = 0x00; - - // 3. Let offset be 0x40 if byte is less than 0x7F and 0x41 - // otherwise. - var offset = bite < 0x7F ? 0x40 : 0x41; - - // 4. If byte is in the range 0x40 to 0x7E, inclusive, or 0x80 - // to 0xFE, inclusive, set pointer to (lead − 0x81) × 190 + - // (byte − offset). - if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0x80, 0xFE)) - pointer = (lead - 0x81) * 190 + (bite - offset); - - // 5. Let code point be null if pointer is null and the index - // code point for pointer in index gb18030 otherwise. - code_point = pointer === null ? null : - indexCodePointFor(pointer, index('gb18030')); - - // 6. If code point is null and byte is an ASCII byte, prepend - // byte to stream. - if (code_point === null && isASCIIByte(bite)) - stream.prepend(bite); - - // 7. If code point is null, return error. - if (code_point === null) - return decoderError(fatal); - - // 8. Return a code point whose value is code point. - return code_point; - } - - // 6. If byte is an ASCII byte, return a code point whose value - // is byte. - if (isASCIIByte(bite)) - return bite; - - // 7. If byte is 0x80, return code point U+20AC. - if (bite === 0x80) - return 0x20AC; - - // 8. If byte is in the range 0x81 to 0xFE, inclusive, set - // gb18030 first to byte and return continue. - if (inRange(bite, 0x81, 0xFE)) { - gb18030_first = bite; - return null; - } - - // 9. Return error. - return decoderError(fatal); - }; - } - - // 11.2.2 gb18030 encoder - /** - * @constructor - * @implements {Encoder} - * @param {{fatal: boolean}} options - * @param {boolean=} gbk_flag - */ - function GB18030Encoder(options, gbk_flag) { - options.fatal; - // gb18030's decoder has an associated gbk flag (initially unset). - /** - * @param {Stream} stream Input stream. - * @param {number} code_point Next code point read from the stream. - * @return {(number|!Array.)} Byte(s) to emit. - */ - this.handler = function(stream, code_point) { - // 1. If code point is end-of-stream, return finished. - if (code_point === end_of_stream) - return finished; - - // 2. If code point is an ASCII code point, return a byte whose - // value is code point. - if (isASCIICodePoint(code_point)) - return code_point; - - // 3. If code point is U+E5E5, return error with code point. - if (code_point === 0xE5E5) - return encoderError(code_point); - - // 4. If the gbk flag is set and code point is U+20AC, return - // byte 0x80. - if (gbk_flag && code_point === 0x20AC) - return 0x80; - - // 5. Let pointer be the index pointer for code point in index - // gb18030. - var pointer = indexPointerFor(code_point, index('gb18030')); - - // 6. If pointer is not null, run these substeps: - if (pointer !== null) { - - // 1. Let lead be floor(pointer / 190) + 0x81. - var lead = floor(pointer / 190) + 0x81; - - // 2. Let trail be pointer % 190. - var trail = pointer % 190; - - // 3. Let offset be 0x40 if trail is less than 0x3F and 0x41 otherwise. - var offset = trail < 0x3F ? 0x40 : 0x41; - - // 4. Return two bytes whose values are lead and trail + offset. - return [lead, trail + offset]; - } - - // 7. If gbk flag is set, return error with code point. - if (gbk_flag) - return encoderError(code_point); - - // 8. Set pointer to the index gb18030 ranges pointer for code - // point. - pointer = indexGB18030RangesPointerFor(code_point); - - // 9. Let byte1 be floor(pointer / 10 / 126 / 10). - var byte1 = floor(pointer / 10 / 126 / 10); - - // 10. Set pointer to pointer − byte1 × 10 × 126 × 10. - pointer = pointer - byte1 * 10 * 126 * 10; - - // 11. Let byte2 be floor(pointer / 10 / 126). - var byte2 = floor(pointer / 10 / 126); - - // 12. Set pointer to pointer − byte2 × 10 × 126. - pointer = pointer - byte2 * 10 * 126; - - // 13. Let byte3 be floor(pointer / 10). - var byte3 = floor(pointer / 10); - - // 14. Let byte4 be pointer − byte3 × 10. - var byte4 = pointer - byte3 * 10; - - // 15. Return four bytes whose values are byte1 + 0x81, byte2 + - // 0x30, byte3 + 0x81, byte4 + 0x30. - return [byte1 + 0x81, - byte2 + 0x30, - byte3 + 0x81, - byte4 + 0x30]; - }; - } - - /** @param {{fatal: boolean}} options */ - encoders['gb18030'] = function(options) { - return new GB18030Encoder(options); - }; - /** @param {{fatal: boolean}} options */ - decoders['gb18030'] = function(options) { - return new GB18030Decoder(options); - }; - - - // - // 12. Legacy multi-byte Chinese (traditional) encodings - // - - // 12.1 Big5 - - // 12.1.1 Big5 decoder - /** - * @constructor - * @implements {Decoder} - * @param {{fatal: boolean}} options - */ - function Big5Decoder(options) { - var fatal = options.fatal; - // Big5's decoder has an associated Big5 lead (initially 0x00). - var /** @type {number} */ Big5_lead = 0x00; - - /** - * @param {Stream} stream The stream of bytes being decoded. - * @param {number} bite The next byte read from the stream. - * @return {?(number|!Array.)} The next code point(s) - * decoded, or null if not enough data exists in the input - * stream to decode a complete code point. - */ - this.handler = function(stream, bite) { - // 1. If byte is end-of-stream and Big5 lead is not 0x00, set - // Big5 lead to 0x00 and return error. - if (bite === end_of_stream && Big5_lead !== 0x00) { - Big5_lead = 0x00; - return decoderError(fatal); - } - - // 2. If byte is end-of-stream and Big5 lead is 0x00, return - // finished. - if (bite === end_of_stream && Big5_lead === 0x00) - return finished; - - // 3. If Big5 lead is not 0x00, let lead be Big5 lead, let - // pointer be null, set Big5 lead to 0x00, and then run these - // substeps: - if (Big5_lead !== 0x00) { - var lead = Big5_lead; - var pointer = null; - Big5_lead = 0x00; - - // 1. Let offset be 0x40 if byte is less than 0x7F and 0x62 - // otherwise. - var offset = bite < 0x7F ? 0x40 : 0x62; - - // 2. If byte is in the range 0x40 to 0x7E, inclusive, or 0xA1 - // to 0xFE, inclusive, set pointer to (lead − 0x81) × 157 + - // (byte − offset). - if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0xA1, 0xFE)) - pointer = (lead - 0x81) * 157 + (bite - offset); - - // 3. If there is a row in the table below whose first column - // is pointer, return the two code points listed in its second - // column - // Pointer | Code points - // --------+-------------- - // 1133 | U+00CA U+0304 - // 1135 | U+00CA U+030C - // 1164 | U+00EA U+0304 - // 1166 | U+00EA U+030C - switch (pointer) { - case 1133: return [0x00CA, 0x0304]; - case 1135: return [0x00CA, 0x030C]; - case 1164: return [0x00EA, 0x0304]; - case 1166: return [0x00EA, 0x030C]; - } - - // 4. Let code point be null if pointer is null and the index - // code point for pointer in index Big5 otherwise. - var code_point = (pointer === null) ? null : - indexCodePointFor(pointer, index('big5')); - - // 5. If code point is null and byte is an ASCII byte, prepend - // byte to stream. - if (code_point === null && isASCIIByte(bite)) - stream.prepend(bite); - - // 6. If code point is null, return error. - if (code_point === null) - return decoderError(fatal); - - // 7. Return a code point whose value is code point. - return code_point; - } - - // 4. If byte is an ASCII byte, return a code point whose value - // is byte. - if (isASCIIByte(bite)) - return bite; - - // 5. If byte is in the range 0x81 to 0xFE, inclusive, set Big5 - // lead to byte and return continue. - if (inRange(bite, 0x81, 0xFE)) { - Big5_lead = bite; - return null; - } - - // 6. Return error. - return decoderError(fatal); - }; - } - - // 12.1.2 Big5 encoder - /** - * @constructor - * @implements {Encoder} - * @param {{fatal: boolean}} options - */ - function Big5Encoder(options) { - options.fatal; - /** - * @param {Stream} stream Input stream. - * @param {number} code_point Next code point read from the stream. - * @return {(number|!Array.)} Byte(s) to emit. - */ - this.handler = function(stream, code_point) { - // 1. If code point is end-of-stream, return finished. - if (code_point === end_of_stream) - return finished; - - // 2. If code point is an ASCII code point, return a byte whose - // value is code point. - if (isASCIICodePoint(code_point)) - return code_point; - - // 3. Let pointer be the index Big5 pointer for code point. - var pointer = indexBig5PointerFor(code_point); - - // 4. If pointer is null, return error with code point. - if (pointer === null) - return encoderError(code_point); - - // 5. Let lead be floor(pointer / 157) + 0x81. - var lead = floor(pointer / 157) + 0x81; - - // 6. If lead is less than 0xA1, return error with code point. - if (lead < 0xA1) - return encoderError(code_point); - - // 7. Let trail be pointer % 157. - var trail = pointer % 157; - - // 8. Let offset be 0x40 if trail is less than 0x3F and 0x62 - // otherwise. - var offset = trail < 0x3F ? 0x40 : 0x62; - - // Return two bytes whose values are lead and trail + offset. - return [lead, trail + offset]; - }; - } - - /** @param {{fatal: boolean}} options */ - encoders['Big5'] = function(options) { - return new Big5Encoder(options); - }; - /** @param {{fatal: boolean}} options */ - decoders['Big5'] = function(options) { - return new Big5Decoder(options); - }; - - - // - // 13. Legacy multi-byte Japanese encodings - // - - // 13.1 euc-jp - - // 13.1.1 euc-jp decoder - /** - * @constructor - * @implements {Decoder} - * @param {{fatal: boolean}} options - */ - function EUCJPDecoder(options) { - var fatal = options.fatal; - - // euc-jp's decoder has an associated euc-jp jis0212 flag - // (initially unset) and euc-jp lead (initially 0x00). - var /** @type {boolean} */ eucjp_jis0212_flag = false, - /** @type {number} */ eucjp_lead = 0x00; - - /** - * @param {Stream} stream The stream of bytes being decoded. - * @param {number} bite The next byte read from the stream. - * @return {?(number|!Array.)} The next code point(s) - * decoded, or null if not enough data exists in the input - * stream to decode a complete code point. - */ - this.handler = function(stream, bite) { - // 1. If byte is end-of-stream and euc-jp lead is not 0x00, set - // euc-jp lead to 0x00, and return error. - if (bite === end_of_stream && eucjp_lead !== 0x00) { - eucjp_lead = 0x00; - return decoderError(fatal); - } - - // 2. If byte is end-of-stream and euc-jp lead is 0x00, return - // finished. - if (bite === end_of_stream && eucjp_lead === 0x00) - return finished; - - // 3. If euc-jp lead is 0x8E and byte is in the range 0xA1 to - // 0xDF, inclusive, set euc-jp lead to 0x00 and return a code - // point whose value is 0xFF61 − 0xA1 + byte. - if (eucjp_lead === 0x8E && inRange(bite, 0xA1, 0xDF)) { - eucjp_lead = 0x00; - return 0xFF61 - 0xA1 + bite; - } - - // 4. If euc-jp lead is 0x8F and byte is in the range 0xA1 to - // 0xFE, inclusive, set the euc-jp jis0212 flag, set euc-jp lead - // to byte, and return continue. - if (eucjp_lead === 0x8F && inRange(bite, 0xA1, 0xFE)) { - eucjp_jis0212_flag = true; - eucjp_lead = bite; - return null; - } - - // 5. If euc-jp lead is not 0x00, let lead be euc-jp lead, set - // euc-jp lead to 0x00, and run these substeps: - if (eucjp_lead !== 0x00) { - var lead = eucjp_lead; - eucjp_lead = 0x00; - - // 1. Let code point be null. - var code_point = null; - - // 2. If lead and byte are both in the range 0xA1 to 0xFE, - // inclusive, set code point to the index code point for (lead - // − 0xA1) × 94 + byte − 0xA1 in index jis0208 if the euc-jp - // jis0212 flag is unset and in index jis0212 otherwise. - if (inRange(lead, 0xA1, 0xFE) && inRange(bite, 0xA1, 0xFE)) { - code_point = indexCodePointFor( - (lead - 0xA1) * 94 + (bite - 0xA1), - index(!eucjp_jis0212_flag ? 'jis0208' : 'jis0212')); - } - - // 3. Unset the euc-jp jis0212 flag. - eucjp_jis0212_flag = false; - - // 4. If byte is not in the range 0xA1 to 0xFE, inclusive, - // prepend byte to stream. - if (!inRange(bite, 0xA1, 0xFE)) - stream.prepend(bite); - - // 5. If code point is null, return error. - if (code_point === null) - return decoderError(fatal); - - // 6. Return a code point whose value is code point. - return code_point; - } - - // 6. If byte is an ASCII byte, return a code point whose value - // is byte. - if (isASCIIByte(bite)) - return bite; - - // 7. If byte is 0x8E, 0x8F, or in the range 0xA1 to 0xFE, - // inclusive, set euc-jp lead to byte and return continue. - if (bite === 0x8E || bite === 0x8F || inRange(bite, 0xA1, 0xFE)) { - eucjp_lead = bite; - return null; - } - - // 8. Return error. - return decoderError(fatal); - }; - } - - // 13.1.2 euc-jp encoder - /** - * @constructor - * @implements {Encoder} - * @param {{fatal: boolean}} options - */ - function EUCJPEncoder(options) { - options.fatal; - /** - * @param {Stream} stream Input stream. - * @param {number} code_point Next code point read from the stream. - * @return {(number|!Array.)} Byte(s) to emit. - */ - this.handler = function(stream, code_point) { - // 1. If code point is end-of-stream, return finished. - if (code_point === end_of_stream) - return finished; - - // 2. If code point is an ASCII code point, return a byte whose - // value is code point. - if (isASCIICodePoint(code_point)) - return code_point; - - // 3. If code point is U+00A5, return byte 0x5C. - if (code_point === 0x00A5) - return 0x5C; - - // 4. If code point is U+203E, return byte 0x7E. - if (code_point === 0x203E) - return 0x7E; - - // 5. If code point is in the range U+FF61 to U+FF9F, inclusive, - // return two bytes whose values are 0x8E and code point − - // 0xFF61 + 0xA1. - if (inRange(code_point, 0xFF61, 0xFF9F)) - return [0x8E, code_point - 0xFF61 + 0xA1]; - - // 6. If code point is U+2212, set it to U+FF0D. - if (code_point === 0x2212) - code_point = 0xFF0D; - - // 7. Let pointer be the index pointer for code point in index - // jis0208. - var pointer = indexPointerFor(code_point, index('jis0208')); - - // 8. If pointer is null, return error with code point. - if (pointer === null) - return encoderError(code_point); - - // 9. Let lead be floor(pointer / 94) + 0xA1. - var lead = floor(pointer / 94) + 0xA1; - - // 10. Let trail be pointer % 94 + 0xA1. - var trail = pointer % 94 + 0xA1; - - // 11. Return two bytes whose values are lead and trail. - return [lead, trail]; - }; - } - - /** @param {{fatal: boolean}} options */ - encoders['EUC-JP'] = function(options) { - return new EUCJPEncoder(options); - }; - /** @param {{fatal: boolean}} options */ - decoders['EUC-JP'] = function(options) { - return new EUCJPDecoder(options); - }; - - // 13.2 iso-2022-jp - - // 13.2.1 iso-2022-jp decoder - /** - * @constructor - * @implements {Decoder} - * @param {{fatal: boolean}} options - */ - function ISO2022JPDecoder(options) { - var fatal = options.fatal; - /** @enum */ - var states = { - ASCII: 0, - Roman: 1, - Katakana: 2, - LeadByte: 3, - TrailByte: 4, - EscapeStart: 5, - Escape: 6 - }; - // iso-2022-jp's decoder has an associated iso-2022-jp decoder - // state (initially ASCII), iso-2022-jp decoder output state - // (initially ASCII), iso-2022-jp lead (initially 0x00), and - // iso-2022-jp output flag (initially unset). - var /** @type {number} */ iso2022jp_decoder_state = states.ASCII, - /** @type {number} */ iso2022jp_decoder_output_state = states.ASCII, - /** @type {number} */ iso2022jp_lead = 0x00, - /** @type {boolean} */ iso2022jp_output_flag = false; - /** - * @param {Stream} stream The stream of bytes being decoded. - * @param {number} bite The next byte read from the stream. - * @return {?(number|!Array.)} The next code point(s) - * decoded, or null if not enough data exists in the input - * stream to decode a complete code point. - */ - this.handler = function(stream, bite) { - // switching on iso-2022-jp decoder state: - switch (iso2022jp_decoder_state) { - default: - case states.ASCII: - // ASCII - // Based on byte: - - // 0x1B - if (bite === 0x1B) { - // Set iso-2022-jp decoder state to escape start and return - // continue. - iso2022jp_decoder_state = states.EscapeStart; - return null; - } - - // 0x00 to 0x7F, excluding 0x0E, 0x0F, and 0x1B - if (inRange(bite, 0x00, 0x7F) && bite !== 0x0E - && bite !== 0x0F && bite !== 0x1B) { - // Unset the iso-2022-jp output flag and return a code point - // whose value is byte. - iso2022jp_output_flag = false; - return bite; - } - - // end-of-stream - if (bite === end_of_stream) { - // Return finished. - return finished; - } - - // Otherwise - // Unset the iso-2022-jp output flag and return error. - iso2022jp_output_flag = false; - return decoderError(fatal); - - case states.Roman: - // Roman - // Based on byte: - - // 0x1B - if (bite === 0x1B) { - // Set iso-2022-jp decoder state to escape start and return - // continue. - iso2022jp_decoder_state = states.EscapeStart; - return null; - } - - // 0x5C - if (bite === 0x5C) { - // Unset the iso-2022-jp output flag and return code point - // U+00A5. - iso2022jp_output_flag = false; - return 0x00A5; - } - - // 0x7E - if (bite === 0x7E) { - // Unset the iso-2022-jp output flag and return code point - // U+203E. - iso2022jp_output_flag = false; - return 0x203E; - } - - // 0x00 to 0x7F, excluding 0x0E, 0x0F, 0x1B, 0x5C, and 0x7E - if (inRange(bite, 0x00, 0x7F) && bite !== 0x0E && bite !== 0x0F - && bite !== 0x1B && bite !== 0x5C && bite !== 0x7E) { - // Unset the iso-2022-jp output flag and return a code point - // whose value is byte. - iso2022jp_output_flag = false; - return bite; - } - - // end-of-stream - if (bite === end_of_stream) { - // Return finished. - return finished; - } - - // Otherwise - // Unset the iso-2022-jp output flag and return error. - iso2022jp_output_flag = false; - return decoderError(fatal); - - case states.Katakana: - // Katakana - // Based on byte: - - // 0x1B - if (bite === 0x1B) { - // Set iso-2022-jp decoder state to escape start and return - // continue. - iso2022jp_decoder_state = states.EscapeStart; - return null; - } - - // 0x21 to 0x5F - if (inRange(bite, 0x21, 0x5F)) { - // Unset the iso-2022-jp output flag and return a code point - // whose value is 0xFF61 − 0x21 + byte. - iso2022jp_output_flag = false; - return 0xFF61 - 0x21 + bite; - } - - // end-of-stream - if (bite === end_of_stream) { - // Return finished. - return finished; - } - - // Otherwise - // Unset the iso-2022-jp output flag and return error. - iso2022jp_output_flag = false; - return decoderError(fatal); - - case states.LeadByte: - // Lead byte - // Based on byte: - - // 0x1B - if (bite === 0x1B) { - // Set iso-2022-jp decoder state to escape start and return - // continue. - iso2022jp_decoder_state = states.EscapeStart; - return null; - } - - // 0x21 to 0x7E - if (inRange(bite, 0x21, 0x7E)) { - // Unset the iso-2022-jp output flag, set iso-2022-jp lead - // to byte, iso-2022-jp decoder state to trail byte, and - // return continue. - iso2022jp_output_flag = false; - iso2022jp_lead = bite; - iso2022jp_decoder_state = states.TrailByte; - return null; - } - - // end-of-stream - if (bite === end_of_stream) { - // Return finished. - return finished; - } - - // Otherwise - // Unset the iso-2022-jp output flag and return error. - iso2022jp_output_flag = false; - return decoderError(fatal); - - case states.TrailByte: - // Trail byte - // Based on byte: - - // 0x1B - if (bite === 0x1B) { - // Set iso-2022-jp decoder state to escape start and return - // continue. - iso2022jp_decoder_state = states.EscapeStart; - return decoderError(fatal); - } - - // 0x21 to 0x7E - if (inRange(bite, 0x21, 0x7E)) { - // 1. Set the iso-2022-jp decoder state to lead byte. - iso2022jp_decoder_state = states.LeadByte; - - // 2. Let pointer be (iso-2022-jp lead − 0x21) × 94 + byte − 0x21. - var pointer = (iso2022jp_lead - 0x21) * 94 + bite - 0x21; - - // 3. Let code point be the index code point for pointer in - // index jis0208. - var code_point = indexCodePointFor(pointer, index('jis0208')); - - // 4. If code point is null, return error. - if (code_point === null) - return decoderError(fatal); - - // 5. Return a code point whose value is code point. - return code_point; - } - - // end-of-stream - if (bite === end_of_stream) { - // Set the iso-2022-jp decoder state to lead byte, prepend - // byte to stream, and return error. - iso2022jp_decoder_state = states.LeadByte; - stream.prepend(bite); - return decoderError(fatal); - } - - // Otherwise - // Set iso-2022-jp decoder state to lead byte and return - // error. - iso2022jp_decoder_state = states.LeadByte; - return decoderError(fatal); - - case states.EscapeStart: - // Escape start - - // 1. If byte is either 0x24 or 0x28, set iso-2022-jp lead to - // byte, iso-2022-jp decoder state to escape, and return - // continue. - if (bite === 0x24 || bite === 0x28) { - iso2022jp_lead = bite; - iso2022jp_decoder_state = states.Escape; - return null; - } - - // 2. Prepend byte to stream. - stream.prepend(bite); - - // 3. Unset the iso-2022-jp output flag, set iso-2022-jp - // decoder state to iso-2022-jp decoder output state, and - // return error. - iso2022jp_output_flag = false; - iso2022jp_decoder_state = iso2022jp_decoder_output_state; - return decoderError(fatal); - - case states.Escape: - // Escape - - // 1. Let lead be iso-2022-jp lead and set iso-2022-jp lead to - // 0x00. - var lead = iso2022jp_lead; - iso2022jp_lead = 0x00; - - // 2. Let state be null. - var state = null; - - // 3. If lead is 0x28 and byte is 0x42, set state to ASCII. - if (lead === 0x28 && bite === 0x42) - state = states.ASCII; - - // 4. If lead is 0x28 and byte is 0x4A, set state to Roman. - if (lead === 0x28 && bite === 0x4A) - state = states.Roman; - - // 5. If lead is 0x28 and byte is 0x49, set state to Katakana. - if (lead === 0x28 && bite === 0x49) - state = states.Katakana; - - // 6. If lead is 0x24 and byte is either 0x40 or 0x42, set - // state to lead byte. - if (lead === 0x24 && (bite === 0x40 || bite === 0x42)) - state = states.LeadByte; - - // 7. If state is non-null, run these substeps: - if (state !== null) { - // 1. Set iso-2022-jp decoder state and iso-2022-jp decoder - // output state to states. - iso2022jp_decoder_state = iso2022jp_decoder_state = state; - - // 2. Let output flag be the iso-2022-jp output flag. - var output_flag = iso2022jp_output_flag; - - // 3. Set the iso-2022-jp output flag. - iso2022jp_output_flag = true; - - // 4. Return continue, if output flag is unset, and error - // otherwise. - return !output_flag ? null : decoderError(fatal); - } - - // 8. Prepend lead and byte to stream. - stream.prepend([lead, bite]); - - // 9. Unset the iso-2022-jp output flag, set iso-2022-jp - // decoder state to iso-2022-jp decoder output state and - // return error. - iso2022jp_output_flag = false; - iso2022jp_decoder_state = iso2022jp_decoder_output_state; - return decoderError(fatal); - } - }; - } - - // 13.2.2 iso-2022-jp encoder - /** - * @constructor - * @implements {Encoder} - * @param {{fatal: boolean}} options - */ - function ISO2022JPEncoder(options) { - options.fatal; - // iso-2022-jp's encoder has an associated iso-2022-jp encoder - // state which is one of ASCII, Roman, and jis0208 (initially - // ASCII). - /** @enum */ - var states = { - ASCII: 0, - Roman: 1, - jis0208: 2 - }; - var /** @type {number} */ iso2022jp_state = states.ASCII; - /** - * @param {Stream} stream Input stream. - * @param {number} code_point Next code point read from the stream. - * @return {(number|!Array.)} Byte(s) to emit. - */ - this.handler = function(stream, code_point) { - // 1. If code point is end-of-stream and iso-2022-jp encoder - // state is not ASCII, prepend code point to stream, set - // iso-2022-jp encoder state to ASCII, and return three bytes - // 0x1B 0x28 0x42. - if (code_point === end_of_stream && - iso2022jp_state !== states.ASCII) { - stream.prepend(code_point); - iso2022jp_state = states.ASCII; - return [0x1B, 0x28, 0x42]; - } - - // 2. If code point is end-of-stream and iso-2022-jp encoder - // state is ASCII, return finished. - if (code_point === end_of_stream && iso2022jp_state === states.ASCII) - return finished; - - // 3. If ISO-2022-JP encoder state is ASCII or Roman, and code - // point is U+000E, U+000F, or U+001B, return error with U+FFFD. - if ((iso2022jp_state === states.ASCII || - iso2022jp_state === states.Roman) && - (code_point === 0x000E || code_point === 0x000F || - code_point === 0x001B)) { - return encoderError(0xFFFD); - } - - // 4. If iso-2022-jp encoder state is ASCII and code point is an - // ASCII code point, return a byte whose value is code point. - if (iso2022jp_state === states.ASCII && - isASCIICodePoint(code_point)) - return code_point; - - // 5. If iso-2022-jp encoder state is Roman and code point is an - // ASCII code point, excluding U+005C and U+007E, or is U+00A5 - // or U+203E, run these substeps: - if (iso2022jp_state === states.Roman && - ((isASCIICodePoint(code_point) && - code_point !== 0x005C && code_point !== 0x007E) || - (code_point == 0x00A5 || code_point == 0x203E))) { - - // 1. If code point is an ASCII code point, return a byte - // whose value is code point. - if (isASCIICodePoint(code_point)) - return code_point; - - // 2. If code point is U+00A5, return byte 0x5C. - if (code_point === 0x00A5) - return 0x5C; - - // 3. If code point is U+203E, return byte 0x7E. - if (code_point === 0x203E) - return 0x7E; - } - - // 6. If code point is an ASCII code point, and iso-2022-jp - // encoder state is not ASCII, prepend code point to stream, set - // iso-2022-jp encoder state to ASCII, and return three bytes - // 0x1B 0x28 0x42. - if (isASCIICodePoint(code_point) && - iso2022jp_state !== states.ASCII) { - stream.prepend(code_point); - iso2022jp_state = states.ASCII; - return [0x1B, 0x28, 0x42]; - } - - // 7. If code point is either U+00A5 or U+203E, and iso-2022-jp - // encoder state is not Roman, prepend code point to stream, set - // iso-2022-jp encoder state to Roman, and return three bytes - // 0x1B 0x28 0x4A. - if ((code_point === 0x00A5 || code_point === 0x203E) && - iso2022jp_state !== states.Roman) { - stream.prepend(code_point); - iso2022jp_state = states.Roman; - return [0x1B, 0x28, 0x4A]; - } - - // 8. If code point is U+2212, set it to U+FF0D. - if (code_point === 0x2212) - code_point = 0xFF0D; - - // 9. Let pointer be the index pointer for code point in index - // jis0208. - var pointer = indexPointerFor(code_point, index('jis0208')); - - // 10. If pointer is null, return error with code point. - if (pointer === null) - return encoderError(code_point); - - // 11. If iso-2022-jp encoder state is not jis0208, prepend code - // point to stream, set iso-2022-jp encoder state to jis0208, - // and return three bytes 0x1B 0x24 0x42. - if (iso2022jp_state !== states.jis0208) { - stream.prepend(code_point); - iso2022jp_state = states.jis0208; - return [0x1B, 0x24, 0x42]; - } - - // 12. Let lead be floor(pointer / 94) + 0x21. - var lead = floor(pointer / 94) + 0x21; - - // 13. Let trail be pointer % 94 + 0x21. - var trail = pointer % 94 + 0x21; - - // 14. Return two bytes whose values are lead and trail. - return [lead, trail]; - }; - } - - /** @param {{fatal: boolean}} options */ - encoders['ISO-2022-JP'] = function(options) { - return new ISO2022JPEncoder(options); - }; - /** @param {{fatal: boolean}} options */ - decoders['ISO-2022-JP'] = function(options) { - return new ISO2022JPDecoder(options); - }; - - // 13.3 Shift_JIS - - // 13.3.1 Shift_JIS decoder - /** - * @constructor - * @implements {Decoder} - * @param {{fatal: boolean}} options - */ - function ShiftJISDecoder(options) { - var fatal = options.fatal; - // Shift_JIS's decoder has an associated Shift_JIS lead (initially - // 0x00). - var /** @type {number} */ Shift_JIS_lead = 0x00; - /** - * @param {Stream} stream The stream of bytes being decoded. - * @param {number} bite The next byte read from the stream. - * @return {?(number|!Array.)} The next code point(s) - * decoded, or null if not enough data exists in the input - * stream to decode a complete code point. - */ - this.handler = function(stream, bite) { - // 1. If byte is end-of-stream and Shift_JIS lead is not 0x00, - // set Shift_JIS lead to 0x00 and return error. - if (bite === end_of_stream && Shift_JIS_lead !== 0x00) { - Shift_JIS_lead = 0x00; - return decoderError(fatal); - } - - // 2. If byte is end-of-stream and Shift_JIS lead is 0x00, - // return finished. - if (bite === end_of_stream && Shift_JIS_lead === 0x00) - return finished; - - // 3. If Shift_JIS lead is not 0x00, let lead be Shift_JIS lead, - // let pointer be null, set Shift_JIS lead to 0x00, and then run - // these substeps: - if (Shift_JIS_lead !== 0x00) { - var lead = Shift_JIS_lead; - var pointer = null; - Shift_JIS_lead = 0x00; - - // 1. Let offset be 0x40, if byte is less than 0x7F, and 0x41 - // otherwise. - var offset = (bite < 0x7F) ? 0x40 : 0x41; - - // 2. Let lead offset be 0x81, if lead is less than 0xA0, and - // 0xC1 otherwise. - var lead_offset = (lead < 0xA0) ? 0x81 : 0xC1; - - // 3. If byte is in the range 0x40 to 0x7E, inclusive, or 0x80 - // to 0xFC, inclusive, set pointer to (lead − lead offset) × - // 188 + byte − offset. - if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0x80, 0xFC)) - pointer = (lead - lead_offset) * 188 + bite - offset; - - // 4. If pointer is in the range 8836 to 10715, inclusive, - // return a code point whose value is 0xE000 − 8836 + pointer. - if (inRange(pointer, 8836, 10715)) - return 0xE000 - 8836 + pointer; - - // 5. Let code point be null, if pointer is null, and the - // index code point for pointer in index jis0208 otherwise. - var code_point = (pointer === null) ? null : - indexCodePointFor(pointer, index('jis0208')); - - // 6. If code point is null and byte is an ASCII byte, prepend - // byte to stream. - if (code_point === null && isASCIIByte(bite)) - stream.prepend(bite); - - // 7. If code point is null, return error. - if (code_point === null) - return decoderError(fatal); - - // 8. Return a code point whose value is code point. - return code_point; - } - - // 4. If byte is an ASCII byte or 0x80, return a code point - // whose value is byte. - if (isASCIIByte(bite) || bite === 0x80) - return bite; - - // 5. If byte is in the range 0xA1 to 0xDF, inclusive, return a - // code point whose value is 0xFF61 − 0xA1 + byte. - if (inRange(bite, 0xA1, 0xDF)) - return 0xFF61 - 0xA1 + bite; - - // 6. If byte is in the range 0x81 to 0x9F, inclusive, or 0xE0 - // to 0xFC, inclusive, set Shift_JIS lead to byte and return - // continue. - if (inRange(bite, 0x81, 0x9F) || inRange(bite, 0xE0, 0xFC)) { - Shift_JIS_lead = bite; - return null; - } - - // 7. Return error. - return decoderError(fatal); - }; - } - - // 13.3.2 Shift_JIS encoder - /** - * @constructor - * @implements {Encoder} - * @param {{fatal: boolean}} options - */ - function ShiftJISEncoder(options) { - options.fatal; - /** - * @param {Stream} stream Input stream. - * @param {number} code_point Next code point read from the stream. - * @return {(number|!Array.)} Byte(s) to emit. - */ - this.handler = function(stream, code_point) { - // 1. If code point is end-of-stream, return finished. - if (code_point === end_of_stream) - return finished; - - // 2. If code point is an ASCII code point or U+0080, return a - // byte whose value is code point. - if (isASCIICodePoint(code_point) || code_point === 0x0080) - return code_point; - - // 3. If code point is U+00A5, return byte 0x5C. - if (code_point === 0x00A5) - return 0x5C; - - // 4. If code point is U+203E, return byte 0x7E. - if (code_point === 0x203E) - return 0x7E; - - // 5. If code point is in the range U+FF61 to U+FF9F, inclusive, - // return a byte whose value is code point − 0xFF61 + 0xA1. - if (inRange(code_point, 0xFF61, 0xFF9F)) - return code_point - 0xFF61 + 0xA1; - - // 6. If code point is U+2212, set it to U+FF0D. - if (code_point === 0x2212) - code_point = 0xFF0D; - - // 7. Let pointer be the index Shift_JIS pointer for code point. - var pointer = indexShiftJISPointerFor(code_point); - - // 8. If pointer is null, return error with code point. - if (pointer === null) - return encoderError(code_point); - - // 9. Let lead be floor(pointer / 188). - var lead = floor(pointer / 188); - - // 10. Let lead offset be 0x81, if lead is less than 0x1F, and - // 0xC1 otherwise. - var lead_offset = (lead < 0x1F) ? 0x81 : 0xC1; - - // 11. Let trail be pointer % 188. - var trail = pointer % 188; - - // 12. Let offset be 0x40, if trail is less than 0x3F, and 0x41 - // otherwise. - var offset = (trail < 0x3F) ? 0x40 : 0x41; - - // 13. Return two bytes whose values are lead + lead offset and - // trail + offset. - return [lead + lead_offset, trail + offset]; - }; - } - - /** @param {{fatal: boolean}} options */ - encoders['Shift_JIS'] = function(options) { - return new ShiftJISEncoder(options); - }; - /** @param {{fatal: boolean}} options */ - decoders['Shift_JIS'] = function(options) { - return new ShiftJISDecoder(options); - }; - - // - // 14. Legacy multi-byte Korean encodings - // - - // 14.1 euc-kr - - // 14.1.1 euc-kr decoder - /** - * @constructor - * @implements {Decoder} - * @param {{fatal: boolean}} options - */ - function EUCKRDecoder(options) { - var fatal = options.fatal; - - // euc-kr's decoder has an associated euc-kr lead (initially 0x00). - var /** @type {number} */ euckr_lead = 0x00; - /** - * @param {Stream} stream The stream of bytes being decoded. - * @param {number} bite The next byte read from the stream. - * @return {?(number|!Array.)} The next code point(s) - * decoded, or null if not enough data exists in the input - * stream to decode a complete code point. - */ - this.handler = function(stream, bite) { - // 1. If byte is end-of-stream and euc-kr lead is not 0x00, set - // euc-kr lead to 0x00 and return error. - if (bite === end_of_stream && euckr_lead !== 0) { - euckr_lead = 0x00; - return decoderError(fatal); - } - - // 2. If byte is end-of-stream and euc-kr lead is 0x00, return - // finished. - if (bite === end_of_stream && euckr_lead === 0) - return finished; - - // 3. If euc-kr lead is not 0x00, let lead be euc-kr lead, let - // pointer be null, set euc-kr lead to 0x00, and then run these - // substeps: - if (euckr_lead !== 0x00) { - var lead = euckr_lead; - var pointer = null; - euckr_lead = 0x00; - - // 1. If byte is in the range 0x41 to 0xFE, inclusive, set - // pointer to (lead − 0x81) × 190 + (byte − 0x41). - if (inRange(bite, 0x41, 0xFE)) - pointer = (lead - 0x81) * 190 + (bite - 0x41); - - // 2. Let code point be null, if pointer is null, and the - // index code point for pointer in index euc-kr otherwise. - var code_point = (pointer === null) - ? null : indexCodePointFor(pointer, index('euc-kr')); - - // 3. If code point is null and byte is an ASCII byte, prepend - // byte to stream. - if (pointer === null && isASCIIByte(bite)) - stream.prepend(bite); - - // 4. If code point is null, return error. - if (code_point === null) - return decoderError(fatal); - - // 5. Return a code point whose value is code point. - return code_point; - } - - // 4. If byte is an ASCII byte, return a code point whose value - // is byte. - if (isASCIIByte(bite)) - return bite; - - // 5. If byte is in the range 0x81 to 0xFE, inclusive, set - // euc-kr lead to byte and return continue. - if (inRange(bite, 0x81, 0xFE)) { - euckr_lead = bite; - return null; - } - - // 6. Return error. - return decoderError(fatal); - }; - } - - // 14.1.2 euc-kr encoder - /** - * @constructor - * @implements {Encoder} - * @param {{fatal: boolean}} options - */ - function EUCKREncoder(options) { - options.fatal; - /** - * @param {Stream} stream Input stream. - * @param {number} code_point Next code point read from the stream. - * @return {(number|!Array.)} Byte(s) to emit. - */ - this.handler = function(stream, code_point) { - // 1. If code point is end-of-stream, return finished. - if (code_point === end_of_stream) - return finished; - - // 2. If code point is an ASCII code point, return a byte whose - // value is code point. - if (isASCIICodePoint(code_point)) - return code_point; - - // 3. Let pointer be the index pointer for code point in index - // euc-kr. - var pointer = indexPointerFor(code_point, index('euc-kr')); - - // 4. If pointer is null, return error with code point. - if (pointer === null) - return encoderError(code_point); - - // 5. Let lead be floor(pointer / 190) + 0x81. - var lead = floor(pointer / 190) + 0x81; - - // 6. Let trail be pointer % 190 + 0x41. - var trail = (pointer % 190) + 0x41; - - // 7. Return two bytes whose values are lead and trail. - return [lead, trail]; - }; - } - - /** @param {{fatal: boolean}} options */ - encoders['EUC-KR'] = function(options) { - return new EUCKREncoder(options); - }; - /** @param {{fatal: boolean}} options */ - decoders['EUC-KR'] = function(options) { - return new EUCKRDecoder(options); - }; - - - // - // 15. Legacy miscellaneous encodings - // - - // 15.1 replacement - - // Not needed - API throws RangeError - - // 15.2 Common infrastructure for utf-16be and utf-16le - - /** - * @param {number} code_unit - * @param {boolean} utf16be - * @return {!Array.} bytes - */ - function convertCodeUnitToBytes(code_unit, utf16be) { - // 1. Let byte1 be code unit >> 8. - var byte1 = code_unit >> 8; - - // 2. Let byte2 be code unit & 0x00FF. - var byte2 = code_unit & 0x00FF; - - // 3. Then return the bytes in order: - // utf-16be flag is set: byte1, then byte2. - if (utf16be) - return [byte1, byte2]; - // utf-16be flag is unset: byte2, then byte1. - return [byte2, byte1]; - } - - // 15.2.1 shared utf-16 decoder - /** - * @constructor - * @implements {Decoder} - * @param {boolean} utf16_be True if big-endian, false if little-endian. - * @param {{fatal: boolean}} options - */ - function UTF16Decoder(utf16_be, options) { - var fatal = options.fatal; - var /** @type {?number} */ utf16_lead_byte = null, - /** @type {?number} */ utf16_lead_surrogate = null; - /** - * @param {Stream} stream The stream of bytes being decoded. - * @param {number} bite The next byte read from the stream. - * @return {?(number|!Array.)} The next code point(s) - * decoded, or null if not enough data exists in the input - * stream to decode a complete code point. - */ - this.handler = function(stream, bite) { - // 1. If byte is end-of-stream and either utf-16 lead byte or - // utf-16 lead surrogate is not null, set utf-16 lead byte and - // utf-16 lead surrogate to null, and return error. - if (bite === end_of_stream && (utf16_lead_byte !== null || - utf16_lead_surrogate !== null)) { - return decoderError(fatal); - } - - // 2. If byte is end-of-stream and utf-16 lead byte and utf-16 - // lead surrogate are null, return finished. - if (bite === end_of_stream && utf16_lead_byte === null && - utf16_lead_surrogate === null) { - return finished; - } - - // 3. If utf-16 lead byte is null, set utf-16 lead byte to byte - // and return continue. - if (utf16_lead_byte === null) { - utf16_lead_byte = bite; - return null; - } - - // 4. Let code unit be the result of: - var code_unit; - if (utf16_be) { - // utf-16be decoder flag is set - // (utf-16 lead byte << 8) + byte. - code_unit = (utf16_lead_byte << 8) + bite; - } else { - // utf-16be decoder flag is unset - // (byte << 8) + utf-16 lead byte. - code_unit = (bite << 8) + utf16_lead_byte; - } - // Then set utf-16 lead byte to null. - utf16_lead_byte = null; - - // 5. If utf-16 lead surrogate is not null, let lead surrogate - // be utf-16 lead surrogate, set utf-16 lead surrogate to null, - // and then run these substeps: - if (utf16_lead_surrogate !== null) { - var lead_surrogate = utf16_lead_surrogate; - utf16_lead_surrogate = null; - - // 1. If code unit is in the range U+DC00 to U+DFFF, - // inclusive, return a code point whose value is 0x10000 + - // ((lead surrogate − 0xD800) << 10) + (code unit − 0xDC00). - if (inRange(code_unit, 0xDC00, 0xDFFF)) { - return 0x10000 + (lead_surrogate - 0xD800) * 0x400 + - (code_unit - 0xDC00); - } - - // 2. Prepend the sequence resulting of converting code unit - // to bytes using utf-16be decoder flag to stream and return - // error. - stream.prepend(convertCodeUnitToBytes(code_unit, utf16_be)); - return decoderError(fatal); - } - - // 6. If code unit is in the range U+D800 to U+DBFF, inclusive, - // set utf-16 lead surrogate to code unit and return continue. - if (inRange(code_unit, 0xD800, 0xDBFF)) { - utf16_lead_surrogate = code_unit; - return null; - } - - // 7. If code unit is in the range U+DC00 to U+DFFF, inclusive, - // return error. - if (inRange(code_unit, 0xDC00, 0xDFFF)) - return decoderError(fatal); - - // 8. Return code point code unit. - return code_unit; - }; - } - - // 15.2.2 shared utf-16 encoder - /** - * @constructor - * @implements {Encoder} - * @param {boolean} utf16_be True if big-endian, false if little-endian. - * @param {{fatal: boolean}} options - */ - function UTF16Encoder(utf16_be, options) { - options.fatal; - /** - * @param {Stream} stream Input stream. - * @param {number} code_point Next code point read from the stream. - * @return {(number|!Array.)} Byte(s) to emit. - */ - this.handler = function(stream, code_point) { - // 1. If code point is end-of-stream, return finished. - if (code_point === end_of_stream) - return finished; - - // 2. If code point is in the range U+0000 to U+FFFF, inclusive, - // return the sequence resulting of converting code point to - // bytes using utf-16be encoder flag. - if (inRange(code_point, 0x0000, 0xFFFF)) - return convertCodeUnitToBytes(code_point, utf16_be); - - // 3. Let lead be ((code point − 0x10000) >> 10) + 0xD800, - // converted to bytes using utf-16be encoder flag. - var lead = convertCodeUnitToBytes( - ((code_point - 0x10000) >> 10) + 0xD800, utf16_be); - - // 4. Let trail be ((code point − 0x10000) & 0x3FF) + 0xDC00, - // converted to bytes using utf-16be encoder flag. - var trail = convertCodeUnitToBytes( - ((code_point - 0x10000) & 0x3FF) + 0xDC00, utf16_be); - - // 5. Return a byte sequence of lead followed by trail. - return lead.concat(trail); - }; - } - - // 15.3 utf-16be - // 15.3.1 utf-16be decoder - /** @param {{fatal: boolean}} options */ - encoders['UTF-16BE'] = function(options) { - return new UTF16Encoder(true, options); - }; - // 15.3.2 utf-16be encoder - /** @param {{fatal: boolean}} options */ - decoders['UTF-16BE'] = function(options) { - return new UTF16Decoder(true, options); - }; - - // 15.4 utf-16le - // 15.4.1 utf-16le decoder - /** @param {{fatal: boolean}} options */ - encoders['UTF-16LE'] = function(options) { - return new UTF16Encoder(false, options); - }; - // 15.4.2 utf-16le encoder - /** @param {{fatal: boolean}} options */ - decoders['UTF-16LE'] = function(options) { - return new UTF16Decoder(false, options); - }; - - // 15.5 x-user-defined - - // 15.5.1 x-user-defined decoder - /** - * @constructor - * @implements {Decoder} - * @param {{fatal: boolean}} options - */ - function XUserDefinedDecoder(options) { - options.fatal; - /** - * @param {Stream} stream The stream of bytes being decoded. - * @param {number} bite The next byte read from the stream. - * @return {?(number|!Array.)} The next code point(s) - * decoded, or null if not enough data exists in the input - * stream to decode a complete code point. - */ - this.handler = function(stream, bite) { - // 1. If byte is end-of-stream, return finished. - if (bite === end_of_stream) - return finished; - - // 2. If byte is an ASCII byte, return a code point whose value - // is byte. - if (isASCIIByte(bite)) - return bite; - - // 3. Return a code point whose value is 0xF780 + byte − 0x80. - return 0xF780 + bite - 0x80; - }; - } - - // 15.5.2 x-user-defined encoder - /** - * @constructor - * @implements {Encoder} - * @param {{fatal: boolean}} options - */ - function XUserDefinedEncoder(options) { - options.fatal; - /** - * @param {Stream} stream Input stream. - * @param {number} code_point Next code point read from the stream. - * @return {(number|!Array.)} Byte(s) to emit. - */ - this.handler = function(stream, code_point) { - // 1.If code point is end-of-stream, return finished. - if (code_point === end_of_stream) - return finished; - - // 2. If code point is an ASCII code point, return a byte whose - // value is code point. - if (isASCIICodePoint(code_point)) - return code_point; - - // 3. If code point is in the range U+F780 to U+F7FF, inclusive, - // return a byte whose value is code point − 0xF780 + 0x80. - if (inRange(code_point, 0xF780, 0xF7FF)) - return code_point - 0xF780 + 0x80; - - // 4. Return error with code point. - return encoderError(code_point); - }; - } - - /** @param {{fatal: boolean}} options */ - encoders['x-user-defined'] = function(options) { - return new XUserDefinedEncoder(options); - }; - /** @param {{fatal: boolean}} options */ - decoders['x-user-defined'] = function(options) { - return new XUserDefinedDecoder(options); - }; - - if (!global['TextEncoder']) - global['TextEncoder'] = TextEncoder; - if (!global['TextDecoder']) - global['TextDecoder'] = TextDecoder; - - if (module.exports) { - module.exports = { - TextEncoder: global['TextEncoder'], - TextDecoder: global['TextDecoder'], - EncodingIndexes: global["encoding-indexes"] - }; - } - - // For strict environments where `this` inside the global scope - // is `undefined`, take a pure object instead - }(commonjsGlobal || {})); - } (encoding)); - - // Copyright Joyent, Inc. and other Node contributors. - // - // Permission is hereby granted, free of charge, to any person obtaining a - // copy of this software and associated documentation files (the - // "Software"), to deal in the Software without restriction, including - // without limitation the rights to use, copy, modify, merge, publish, - // distribute, sublicense, and/or sell copies of the Software, and to permit - // persons to whom the Software is furnished to do so, subject to the - // following conditions: - // - // The above copyright notice and this permission notice shall be included - // in all copies or substantial portions of the Software. - // - // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - // USE OR OTHER DEALINGS IN THE SOFTWARE. - - var isBufferEncoding = Buffer.isEncoding - || function(encoding) { - switch (encoding && encoding.toLowerCase()) { - case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': case 'raw': return true; - default: return false; - } - }; - - - function assertEncoding(encoding) { - if (encoding && !isBufferEncoding(encoding)) { - throw new Error('Unknown encoding: ' + encoding); - } - } - - // StringDecoder provides an interface for efficiently splitting a series of - // buffers into a series of JS strings without breaking apart multi-byte - // characters. CESU-8 is handled as part of the UTF-8 encoding. - // - // @TODO Handling all encodings inside a single object makes it very difficult - // to reason about this code, so it should be split up in the future. - // @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code - // points as used by CESU-8. - function StringDecoder$1(encoding) { - this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, ''); - assertEncoding(encoding); - switch (this.encoding) { - case 'utf8': - // CESU-8 represents each of Surrogate Pair by 3-bytes - this.surrogateSize = 3; - break; - case 'ucs2': - case 'utf16le': - // UTF-16 represents each of Surrogate Pair by 2-bytes - this.surrogateSize = 2; - this.detectIncompleteChar = utf16DetectIncompleteChar; - break; - case 'base64': - // Base-64 stores 3 bytes in 4 chars, and pads the remainder. - this.surrogateSize = 3; - this.detectIncompleteChar = base64DetectIncompleteChar; - break; - default: - this.write = passThroughWrite; - return; - } - - // Enough space to store all bytes of a single character. UTF-8 needs 4 - // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate). - this.charBuffer = new Buffer(6); - // Number of bytes received for the current incomplete multi-byte character. - this.charReceived = 0; - // Number of bytes expected for the current incomplete multi-byte character. - this.charLength = 0; - } - - // write decodes the given buffer and returns it as JS string that is - // guaranteed to not contain any partial multi-byte characters. Any partial - // character found at the end of the buffer is buffered up, and will be - // returned when calling write again with the remaining bytes. - // - // Note: Converting a Buffer containing an orphan surrogate to a String - // currently works, but converting a String to a Buffer (via `new Buffer`, or - // Buffer#write) will replace incomplete surrogates with the unicode - // replacement character. See https://codereview.chromium.org/121173009/ . - StringDecoder$1.prototype.write = function(buffer) { - var charStr = ''; - // if our last write ended with an incomplete multibyte character - while (this.charLength) { - // determine how many remaining bytes this buffer has to offer for this char - var available = (buffer.length >= this.charLength - this.charReceived) ? - this.charLength - this.charReceived : - buffer.length; - - // add the new bytes to the char buffer - buffer.copy(this.charBuffer, this.charReceived, 0, available); - this.charReceived += available; - - if (this.charReceived < this.charLength) { - // still not enough chars in this buffer? wait for more ... - return ''; - } - - // remove bytes belonging to the current character from the buffer - buffer = buffer.slice(available, buffer.length); - - // get the character that was split - charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding); - - // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character - var charCode = charStr.charCodeAt(charStr.length - 1); - if (charCode >= 0xD800 && charCode <= 0xDBFF) { - this.charLength += this.surrogateSize; - charStr = ''; - continue; - } - this.charReceived = this.charLength = 0; - - // if there are no more bytes in this buffer, just emit our char - if (buffer.length === 0) { - return charStr; - } - break; - } - - // determine and set charLength / charReceived - this.detectIncompleteChar(buffer); - - var end = buffer.length; - if (this.charLength) { - // buffer the incomplete character bytes we got - buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end); - end -= this.charReceived; - } - - charStr += buffer.toString(this.encoding, 0, end); - - var end = charStr.length - 1; - var charCode = charStr.charCodeAt(end); - // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character - if (charCode >= 0xD800 && charCode <= 0xDBFF) { - var size = this.surrogateSize; - this.charLength += size; - this.charReceived += size; - this.charBuffer.copy(this.charBuffer, size, 0, size); - buffer.copy(this.charBuffer, 0, 0, size); - return charStr.substring(0, end); - } - - // or just emit the charStr - return charStr; - }; - - // detectIncompleteChar determines if there is an incomplete UTF-8 character at - // the end of the given buffer. If so, it sets this.charLength to the byte - // length that character, and sets this.charReceived to the number of bytes - // that are available for this character. - StringDecoder$1.prototype.detectIncompleteChar = function(buffer) { - // determine how many bytes we have to check at the end of this buffer - var i = (buffer.length >= 3) ? 3 : buffer.length; - - // Figure out if one of the last i bytes of our buffer announces an - // incomplete char. - for (; i > 0; i--) { - var c = buffer[buffer.length - i]; - - // See http://en.wikipedia.org/wiki/UTF-8#Description - - // 110XXXXX - if (i == 1 && c >> 5 == 0x06) { - this.charLength = 2; - break; - } - - // 1110XXXX - if (i <= 2 && c >> 4 == 0x0E) { - this.charLength = 3; - break; - } - - // 11110XXX - if (i <= 3 && c >> 3 == 0x1E) { - this.charLength = 4; - break; - } - } - this.charReceived = i; - }; - - StringDecoder$1.prototype.end = function(buffer) { - var res = ''; - if (buffer && buffer.length) - res = this.write(buffer); - - if (this.charReceived) { - var cr = this.charReceived; - var buf = this.charBuffer; - var enc = this.encoding; - res += buf.slice(0, cr).toString(enc); - } - - return res; - }; - - function passThroughWrite(buffer) { - return buffer.toString(this.encoding); - } - - function utf16DetectIncompleteChar(buffer) { - this.charReceived = buffer.length % 2; - this.charLength = this.charReceived ? 2 : 0; - } - - function base64DetectIncompleteChar(buffer) { - this.charReceived = buffer.length % 3; - this.charLength = this.charReceived ? 3 : 0; - } - - var stringDecoder = /*#__PURE__*/Object.freeze({ - __proto__: null, - StringDecoder: StringDecoder$1 - }); - - var require$$1 = /*@__PURE__*/getAugmentedNamespace(stringDecoder); - - var StringDecoder = require$$1.StringDecoder; - function defaultDecoder(data) { - var decoder = new StringDecoder(); - var out = decoder.write(data) + decoder.end(); - return out.replace(/\0/g, '').trim(); - } - var decoderBrowser = createDecoder$1; var regex = /^(?:ANSI\s)?(\d+)$/m; - function createDecoder$1(encoding, second) { + function createDecoder(encoding, second) { if (!encoding) { - return defaultDecoder; + return browserDecoder; } try { new TextDecoder(encoding.trim()); - } catch(e) { + } catch (e) { var match = regex.exec(encoding); if (match && !second) { - return createDecoder$1('windows-' + match[1], true); + return createDecoder('windows-' + match[1], true); } else { - return defaultDecoder; + encoding = undefined; + return browserDecoder; } } return browserDecoder; function browserDecoder(buffer) { - var decoder = new TextDecoder(encoding); + var decoder = new TextDecoder(encoding ? encoding : undefined); var out = decoder.decode(buffer, { stream: true }) + decoder.decode(); @@ -13599,13 +7813,12 @@ } } - var createDecoder = decoderBrowser; function dbfHeader(data) { var out = {}; - out.lastUpdated = new Date(data.readUInt8(1) + 1900, data.readUInt8(2), data.readUInt8(3)); - out.records = data.readUInt32LE(4); - out.headerLen = data.readUInt16LE(8); - out.recLen = data.readUInt16LE(10); + out.lastUpdated = new Date(data.getUint8(1) + 1900, data.getUint8(2), data.getUint8(3)); + out.records = data.getUint32(4, true); + out.headerLen = data.getUint16(8, true); + out.recLen = data.getUint16(10, true); return out; } @@ -13614,12 +7827,12 @@ var offset = 32; while (offset < headerLen) { out.push({ - name: decoder(data.slice(offset, offset + 11)), - dataType: String.fromCharCode(data.readUInt8(offset + 11)), - len: data.readUInt8(offset + 16), - decimal: data.readUInt8(offset + 17) + name: decoder(new Uint8Array(data.buffer.slice(data.byteOffset + offset, data.byteOffset + offset + 11))), + dataType: String.fromCharCode(data.getUint8(offset + 11)), + len: data.getUint8(offset + 16), + decimal: data.getUint8(offset + 17) }); - if (data.readUInt8(offset + 32) === 13) { + if (data.getUint8(offset + 32) === 13) { break; } else { offset += 32; @@ -13629,7 +7842,8 @@ } function rowFuncs(buffer, offset, len, type, decoder) { - var data = buffer.slice(offset, offset + len); + const data = new Uint8Array(buffer.buffer.slice(buffer.byteOffset + offset, buffer.byteOffset + offset + len)); + var textData = decoder(data); switch (type) { case 'N': @@ -13663,7 +7877,7 @@ return out; } - var parsedbf = function(buffer, encoding) { + function parseDbf (buffer, encoding) { var decoder = createDecoder(encoding); var header = dbfHeader(buffer); var rowHeaders = dbfRowHeader(buffer, header.headerLen - 1, decoder); @@ -13678,34 +7892,58 @@ records--; } return out; - }; - - var parseDbf = /*@__PURE__*/getDefaultExportFromCjs(parsedbf); + } const URL = globalThis.URL; - - function toBuffer(b) { + const toUitn8Arr = b => { if (!b) { throw new Error('forgot to pass buffer'); } - if (Buffer.isBuffer(b)) { - return b; - } if (isArrayBuffer(b)) { - return Buffer.from(b); + return new Uint8Array(b); } if (isArrayBuffer(b.buffer)) { if (b.BYTES_PER_ELEMENT === 1) { - return Buffer.from(b); + return b; } - return Buffer.from(b.buffer); + return new Uint8Array(b.buffer, b.byteOffset, b.byteLength); } - } + throw new Error('invalid buffer like object') + }; + const txtDecoder = new TextDecoder(); + const toString$1 = (possibleString) => { + if (!possibleString) { + return; + } + if (typeof possibleString === 'string') { + return possibleString; + } + if (isArrayBuffer(possibleString) || ArrayBuffer.isView(possibleString) || isDataView(possibleString)) { + return txtDecoder.decode(possibleString); + } + }; + const toDataView = b => { + if (!b) { + throw new Error('forgot to pass buffer'); + } + if (isDataView(b)) { + return b; + } + if (isArrayBuffer(b)) { + return new DataView(b); + } + if (isArrayBuffer(b.buffer)) { + return new DataView(b.buffer, b.byteOffset, b.byteLength); + } + throw new Error('invalid buffer like object') + }; function isArrayBuffer(subject) { return subject instanceof globalThis.ArrayBuffer || Object.prototype.toString.call(subject) === '[object ArrayBuffer]'; } - + function isDataView(subject) { + return subject instanceof globalThis.DataView || Object.prototype.toString.call(subject) === '[object DataView]' + } const combine = function ([shp, dbf]) { const out = {}; @@ -13728,7 +7966,7 @@ }; const parseZip = async function (buffer, whiteList) { let key; - buffer = toBuffer(buffer); + buffer = toUitn8Arr(buffer); const zip = await unzip(buffer); const names = []; whiteList = whiteList || []; @@ -13807,19 +8045,54 @@ const url = new URL(base, globalThis?.document?.location); return url.pathname.slice(-4).toLowerCase() === suffix; }; + const fromObject = ({ shp, dbf, cpg, prj }) => { + const things = [ + _parseShp(shp, prj) + ]; + if (dbf) { + things.push(_parseDbf(dbf, cpg)); + } + return combine(things); + }; const getShapefile = async function (base, whiteList) { if (typeof base !== 'string') { - return parseZip(base); + if (isArrayBuffer(base) || ArrayBuffer.isView(base) || isDataView(base)) { + return parseZip(base); + } + if (base.shp) { + return fromObject(base); + } + throw new TypeError('must be a string, some sort of Buffer, or an object with at least a .shp property') } if (checkSuffix(base, '.zip')) { return getZip(base, whiteList); } + if (checkSuffix(base, '.shp')) { + base = base.slice(0, -4); + } const results = await Promise.all([ handleShp(base), handleDbf(base) ]); return combine(results); }; + const _parseShp = function (shp, prj) { + shp = toDataView(shp); + prj = toString$1(prj); + if (typeof prj === 'string') { + try { + prj = proj4(prj); + } catch (e) { + prj = false; + } + } + return parseShp(shp, prj); + }; + const _parseDbf = function (dbf, cpg) { + dbf = toDataView(dbf); + cpg = toString$1(cpg); + return parseDbf(dbf, cpg); + }; var __defProp = Object.defineProperty; var __getOwnPropNames = Object.getOwnPropertyNames; @@ -14378,7 +8651,7 @@ // node_modules/loupe/lib/promise.js var getPromiseValue = /* @__PURE__ */ __name(() => "Promise{\u2026}", "getPromiseValue"); try { - const { getPromiseDetails, kPending, kRejected } = browser$1.binding("util"); + const { getPromiseDetails, kPending, kRejected } = process.binding("util"); if (Array.isArray(getPromiseDetails(Promise.resolve()))) { getPromiseValue = /* @__PURE__ */ __name((value, options) => { const [state, innerValue] = getPromiseDetails(value); @@ -18078,7 +12351,7 @@ const should = should$1(); use(chaiAsPromised); - + const get = url => fetch(url).then(resp => resp.arrayBuffer()); describe('Shp', function () { describe('park and rides not zipped', function () { const pandr = getShapefile('http://localhost:3000/files/pandr'); @@ -18092,6 +12365,36 @@ return pandr.then(function (a) { return a.features; }).should.eventually.have.length(80); }); }); + describe('park and rides not zipped but with suffix', function () { + const pandr = getShapefile('http://localhost:3000/files/pandr.shp'); + it('should have the right keys', function () { + return pandr.should.eventually.contain.keys('type', 'features'); + }); + it('should be the right type', function () { + return pandr.should.eventually.have.property('type', 'FeatureCollection'); + }); + it('should have the right number of features', function () { + return pandr.then(function (a) { return a.features; }).should.eventually.have.length(80); + }); + }); + describe('park and rides not zipped but loaded individually', async function () { + const pandr = Promise.all([ + get('http://localhost:3000/files/pandr.shp'), + get('http://localhost:3000/files/pandr.dbf'), + get('http://localhost:3000/files/pandr.prj') + ]).then(([shapefile, dbf, prj]) => getShapefile({ + shp: shapefile, dbf, prj + })); + it('should have the right keys', function () { + return pandr.should.eventually.contain.keys('type', 'features'); + }); + it('should be the right type', function () { + return pandr.should.eventually.have.property('type', 'FeatureCollection'); + }); + it('should have the right number of features', function () { + return pandr.then(function (a) { return a.features; }).should.eventually.have.length(80); + }); + }); describe('park and rides zipped', function () { const pandr = getShapefile('http://localhost:3000/files/pandr.zip').catch(e => console.log('ERR', e)); it('should have the right keys', function () { @@ -18321,6 +12624,24 @@ 'Hněvošický háj' ]); }); + it('should work for codepage individually', function () { + return Promise.all([ + get('http://localhost:3000/test/data/codepage.shp'), + get('http://localhost:3000/test/data/codepage.dbf'), + get('http://localhost:3000/test/data/codepage.prj'), + get('http://localhost:3000/test/data/codepage.cpg') + ]).then(([shapefile, dbf, prj, cpg]) => getShapefile({ + shp: shapefile, dbf, prj, cpg + })).then(function (item) { + item.should.contain.keys('type', 'features'); + return item.features.map(function (feature) { + return feature.properties.field; + }); + }).should.eventually.deep.equal([ + '??', + 'Hněvošický háj' + ]); + }); it('should work for a stupid code page', function () { return getShapefile('http://localhost:3000/test/data/htmlcpg').then(function (item) { item.should.contain.keys('type', 'features');