UNPKG

protomaps-leaflet

Version:

Vector tile rendering and labeling for [Leaflet](https://github.com/Leaflet/Leaflet).

1,489 lines (1,479 loc) 195 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __pow = Math.pow; var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __async = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { step2(generator.next(value)); } catch (e) { reject(e); } }; var rejected = (value) => { try { step2(generator.throw(value)); } catch (e) { reject(e); } }; var step2 = (x2) => x2.done ? resolve(x2.value) : Promise.resolve(x2.value).then(fulfilled, rejected); step2((generator = generator.apply(__this, __arguments)).next()); }); }; // node_modules/@mapbox/point-geometry/index.js var require_point_geometry = __commonJS({ "node_modules/@mapbox/point-geometry/index.js"(exports, module) { "use strict"; module.exports = Point9; function Point9(x2, y) { this.x = x2; this.y = y; } Point9.prototype = { clone: function() { return new Point9(this.x, this.y); }, add: function(p) { return this.clone()._add(p); }, sub: function(p) { return this.clone()._sub(p); }, multByPoint: function(p) { return this.clone()._multByPoint(p); }, divByPoint: function(p) { return this.clone()._divByPoint(p); }, mult: function(k) { return this.clone()._mult(k); }, div: function(k) { return this.clone()._div(k); }, rotate: function(a) { return this.clone()._rotate(a); }, rotateAround: function(a, p) { return this.clone()._rotateAround(a, p); }, matMult: function(m) { return this.clone()._matMult(m); }, unit: function() { return this.clone()._unit(); }, perp: function() { return this.clone()._perp(); }, round: function() { return this.clone()._round(); }, mag: function() { return Math.sqrt(this.x * this.x + this.y * this.y); }, equals: function(other) { return this.x === other.x && this.y === other.y; }, dist: function(p) { return Math.sqrt(this.distSqr(p)); }, distSqr: function(p) { var dx = p.x - this.x, dy = p.y - this.y; return dx * dx + dy * dy; }, angle: function() { return Math.atan2(this.y, this.x); }, angleTo: function(b) { return Math.atan2(this.y - b.y, this.x - b.x); }, angleWith: function(b) { return this.angleWithSep(b.x, b.y); }, angleWithSep: function(x2, y) { return Math.atan2( this.x * y - this.y * x2, this.x * x2 + this.y * y ); }, _matMult: function(m) { var x2 = m[0] * this.x + m[1] * this.y, y = m[2] * this.x + m[3] * this.y; this.x = x2; this.y = y; return this; }, _add: function(p) { this.x += p.x; this.y += p.y; return this; }, _sub: function(p) { this.x -= p.x; this.y -= p.y; return this; }, _mult: function(k) { this.x *= k; this.y *= k; return this; }, _div: function(k) { this.x /= k; this.y /= k; return this; }, _multByPoint: function(p) { this.x *= p.x; this.y *= p.y; return this; }, _divByPoint: function(p) { this.x /= p.x; this.y /= p.y; return this; }, _unit: function() { this._div(this.mag()); return this; }, _perp: function() { var y = this.y; this.y = this.x; this.x = -y; return this; }, _rotate: function(angle) { var cos = Math.cos(angle), sin = Math.sin(angle), x2 = cos * this.x - sin * this.y, y = sin * this.x + cos * this.y; this.x = x2; this.y = y; return this; }, _rotateAround: function(angle, p) { var cos = Math.cos(angle), sin = Math.sin(angle), x2 = p.x + cos * (this.x - p.x) - sin * (this.y - p.y), y = p.y + sin * (this.x - p.x) + cos * (this.y - p.y); this.x = x2; this.y = y; return this; }, _round: function() { this.x = Math.round(this.x); this.y = Math.round(this.y); return this; } }; Point9.convert = function(a) { if (a instanceof Point9) { return a; } if (Array.isArray(a)) { return new Point9(a[0], a[1]); } return a; }; } }); // node_modules/@mapbox/unitbezier/index.js var require_unitbezier = __commonJS({ "node_modules/@mapbox/unitbezier/index.js"(exports, module) { module.exports = UnitBezier2; function UnitBezier2(p1x, p1y, p2x, p2y) { this.cx = 3 * p1x; this.bx = 3 * (p2x - p1x) - this.cx; this.ax = 1 - this.cx - this.bx; this.cy = 3 * p1y; this.by = 3 * (p2y - p1y) - this.cy; this.ay = 1 - this.cy - this.by; this.p1x = p1x; this.p1y = p2y; this.p2x = p2x; this.p2y = p2y; } UnitBezier2.prototype.sampleCurveX = function(t) { return ((this.ax * t + this.bx) * t + this.cx) * t; }; UnitBezier2.prototype.sampleCurveY = function(t) { return ((this.ay * t + this.by) * t + this.cy) * t; }; UnitBezier2.prototype.sampleCurveDerivativeX = function(t) { return (3 * this.ax * t + 2 * this.bx) * t + this.cx; }; UnitBezier2.prototype.solveCurveX = function(x2, epsilon) { if (typeof epsilon === "undefined") epsilon = 1e-6; var t0, t1, t2, x22, i2; for (t2 = x2, i2 = 0; i2 < 8; i2++) { x22 = this.sampleCurveX(t2) - x2; if (Math.abs(x22) < epsilon) return t2; var d2 = this.sampleCurveDerivativeX(t2); if (Math.abs(d2) < 1e-6) break; t2 = t2 - x22 / d2; } t0 = 0; t1 = 1; t2 = x2; if (t2 < t0) return t0; if (t2 > t1) return t1; while (t0 < t1) { x22 = this.sampleCurveX(t2); if (Math.abs(x22 - x2) < epsilon) return t2; if (x2 > x22) { t0 = t2; } else { t1 = t2; } t2 = (t1 - t0) * 0.5 + t0; } return t2; }; UnitBezier2.prototype.solve = function(x2, epsilon) { return this.sampleCurveY(this.solveCurveX(x2, epsilon)); }; } }); // node_modules/@mapbox/vector-tile/lib/vectortilefeature.js var require_vectortilefeature = __commonJS({ "node_modules/@mapbox/vector-tile/lib/vectortilefeature.js"(exports, module) { "use strict"; var Point9 = require_point_geometry(); module.exports = VectorTileFeature; function VectorTileFeature(pbf, end, extent, keys, values) { this.properties = {}; this.extent = extent; this.type = 0; this._pbf = pbf; this._geometry = -1; this._keys = keys; this._values = values; pbf.readFields(readFeature, this, end); } function readFeature(tag, feature, pbf) { if (tag == 1) feature.id = pbf.readVarint(); else if (tag == 2) readTag(pbf, feature); else if (tag == 3) feature.type = pbf.readVarint(); else if (tag == 4) feature._geometry = pbf.pos; } function readTag(pbf, feature) { var end = pbf.readVarint() + pbf.pos; while (pbf.pos < end) { var key = feature._keys[pbf.readVarint()], value = feature._values[pbf.readVarint()]; feature.properties[key] = value; } } VectorTileFeature.types = ["Unknown", "Point", "LineString", "Polygon"]; VectorTileFeature.prototype.loadGeometry = function() { var pbf = this._pbf; pbf.pos = this._geometry; var end = pbf.readVarint() + pbf.pos, cmd = 1, length = 0, x2 = 0, y = 0, lines = [], line; while (pbf.pos < end) { if (length <= 0) { var cmdLen = pbf.readVarint(); cmd = cmdLen & 7; length = cmdLen >> 3; } length--; if (cmd === 1 || cmd === 2) { x2 += pbf.readSVarint(); y += pbf.readSVarint(); if (cmd === 1) { if (line) lines.push(line); line = []; } line.push(new Point9(x2, y)); } else if (cmd === 7) { if (line) { line.push(line[0].clone()); } } else { throw new Error("unknown command " + cmd); } } if (line) lines.push(line); return lines; }; VectorTileFeature.prototype.bbox = function() { var pbf = this._pbf; pbf.pos = this._geometry; var end = pbf.readVarint() + pbf.pos, cmd = 1, length = 0, x2 = 0, y = 0, x1 = Infinity, x22 = -Infinity, y1 = Infinity, y2 = -Infinity; while (pbf.pos < end) { if (length <= 0) { var cmdLen = pbf.readVarint(); cmd = cmdLen & 7; length = cmdLen >> 3; } length--; if (cmd === 1 || cmd === 2) { x2 += pbf.readSVarint(); y += pbf.readSVarint(); if (x2 < x1) x1 = x2; if (x2 > x22) x22 = x2; if (y < y1) y1 = y; if (y > y2) y2 = y; } else if (cmd !== 7) { throw new Error("unknown command " + cmd); } } return [x1, y1, x22, y2]; }; VectorTileFeature.prototype.toGeoJSON = function(x2, y, z) { var size = this.extent * Math.pow(2, z), x0 = this.extent * x2, y0 = this.extent * y, coords = this.loadGeometry(), type = VectorTileFeature.types[this.type], i2, j; function project2(line) { for (var j2 = 0; j2 < line.length; j2++) { var p = line[j2], y2 = 180 - (p.y + y0) * 360 / size; line[j2] = [ (p.x + x0) * 360 / size - 180, 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90 ]; } } switch (this.type) { case 1: var points = []; for (i2 = 0; i2 < coords.length; i2++) { points[i2] = coords[i2][0]; } coords = points; project2(coords); break; case 2: for (i2 = 0; i2 < coords.length; i2++) { project2(coords[i2]); } break; case 3: coords = classifyRings(coords); for (i2 = 0; i2 < coords.length; i2++) { for (j = 0; j < coords[i2].length; j++) { project2(coords[i2][j]); } } break; } if (coords.length === 1) { coords = coords[0]; } else { type = "Multi" + type; } var result = { type: "Feature", geometry: { type, coordinates: coords }, properties: this.properties }; if ("id" in this) { result.id = this.id; } return result; }; function classifyRings(rings) { var len = rings.length; if (len <= 1) return [rings]; var polygons = [], polygon, ccw; for (var i2 = 0; i2 < len; i2++) { var area = signedArea(rings[i2]); if (area === 0) continue; if (ccw === void 0) ccw = area < 0; if (ccw === area < 0) { if (polygon) polygons.push(polygon); polygon = [rings[i2]]; } else { polygon.push(rings[i2]); } } if (polygon) polygons.push(polygon); return polygons; } function signedArea(ring) { var sum = 0; for (var i2 = 0, len = ring.length, j = len - 1, p1, p2; i2 < len; j = i2++) { p1 = ring[i2]; p2 = ring[j]; sum += (p2.x - p1.x) * (p1.y + p2.y); } return sum; } } }); // node_modules/@mapbox/vector-tile/lib/vectortilelayer.js var require_vectortilelayer = __commonJS({ "node_modules/@mapbox/vector-tile/lib/vectortilelayer.js"(exports, module) { "use strict"; var VectorTileFeature = require_vectortilefeature(); module.exports = VectorTileLayer; function VectorTileLayer(pbf, end) { this.version = 1; this.name = null; this.extent = 4096; this.length = 0; this._pbf = pbf; this._keys = []; this._values = []; this._features = []; pbf.readFields(readLayer, this, end); this.length = this._features.length; } function readLayer(tag, layer, pbf) { if (tag === 15) layer.version = pbf.readVarint(); else if (tag === 1) layer.name = pbf.readString(); else if (tag === 5) layer.extent = pbf.readVarint(); else if (tag === 2) layer._features.push(pbf.pos); else if (tag === 3) layer._keys.push(pbf.readString()); else if (tag === 4) layer._values.push(readValueMessage(pbf)); } function readValueMessage(pbf) { var value = null, end = pbf.readVarint() + pbf.pos; while (pbf.pos < end) { var tag = pbf.readVarint() >> 3; value = tag === 1 ? pbf.readString() : tag === 2 ? pbf.readFloat() : tag === 3 ? pbf.readDouble() : tag === 4 ? pbf.readVarint64() : tag === 5 ? pbf.readVarint() : tag === 6 ? pbf.readSVarint() : tag === 7 ? pbf.readBoolean() : null; } return value; } VectorTileLayer.prototype.feature = function(i2) { if (i2 < 0 || i2 >= this._features.length) throw new Error("feature index out of bounds"); this._pbf.pos = this._features[i2]; var end = this._pbf.readVarint() + this._pbf.pos; return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values); }; } }); // node_modules/@mapbox/vector-tile/lib/vectortile.js var require_vectortile = __commonJS({ "node_modules/@mapbox/vector-tile/lib/vectortile.js"(exports, module) { "use strict"; var VectorTileLayer = require_vectortilelayer(); module.exports = VectorTile2; function VectorTile2(pbf, end) { this.layers = pbf.readFields(readTile, {}, end); } function readTile(tag, layers, pbf) { if (tag === 3) { var layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos); if (layer.length) layers[layer.name] = layer; } } } }); // node_modules/@mapbox/vector-tile/index.js var require_vector_tile = __commonJS({ "node_modules/@mapbox/vector-tile/index.js"(exports, module) { module.exports.VectorTile = require_vectortile(); module.exports.VectorTileFeature = require_vectortilefeature(); module.exports.VectorTileLayer = require_vectortilelayer(); } }); // node_modules/ieee754/index.js var require_ieee754 = __commonJS({ "node_modules/ieee754/index.js"(exports) { exports.read = function(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 i2 = isLE ? nBytes - 1 : 0; var d = isLE ? -1 : 1; var s = buffer[offset + i2]; i2 += d; e = s & (1 << -nBits) - 1; s >>= -nBits; nBits += eLen; for (; nBits > 0; e = e * 256 + buffer[offset + i2], i2 += d, nBits -= 8) { } m = e & (1 << -nBits) - 1; e >>= -nBits; nBits += mLen; for (; nBits > 0; m = m * 256 + buffer[offset + i2], i2 += 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; } return (s ? -1 : 1) * m * Math.pow(2, e - mLen); }; exports.write = function(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 i2 = 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; } else { value += rt * Math.pow(2, 1 - eBias); } if (value * c >= 2) { e++; c /= 2; } 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; } } for (; mLen >= 8; buffer[offset + i2] = m & 255, i2 += d, m /= 256, mLen -= 8) { } e = e << mLen | m; eLen += mLen; for (; eLen > 0; buffer[offset + i2] = e & 255, i2 += d, e /= 256, eLen -= 8) { } buffer[offset + i2 - d] |= s * 128; }; } }); // node_modules/pbf/index.js var require_pbf = __commonJS({ "node_modules/pbf/index.js"(exports, module) { "use strict"; module.exports = Pbf; var ieee754 = require_ieee754(); function Pbf(buf) { this.buf = ArrayBuffer.isView && ArrayBuffer.isView(buf) ? buf : new Uint8Array(buf || 0); this.pos = 0; this.type = 0; this.length = this.buf.length; } Pbf.Varint = 0; Pbf.Fixed64 = 1; Pbf.Bytes = 2; Pbf.Fixed32 = 5; var SHIFT_LEFT_32 = (1 << 16) * (1 << 16); var SHIFT_RIGHT_32 = 1 / SHIFT_LEFT_32; var TEXT_DECODER_MIN_LENGTH = 12; var utf8TextDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder("utf8"); Pbf.prototype = { destroy: function() { this.buf = null; }, readFields: function(readField, result, end) { end = end || this.length; while (this.pos < end) { var val = this.readVarint(), tag = val >> 3, startPos = this.pos; this.type = val & 7; readField(tag, result, this); if (this.pos === startPos) this.skip(val); } return result; }, readMessage: function(readField, result) { return this.readFields(readField, result, this.readVarint() + this.pos); }, readFixed32: function() { var val = readUInt32(this.buf, this.pos); this.pos += 4; return val; }, readSFixed32: function() { var val = readInt32(this.buf, this.pos); this.pos += 4; return val; }, readFixed64: function() { var val = readUInt32(this.buf, this.pos) + readUInt32(this.buf, this.pos + 4) * SHIFT_LEFT_32; this.pos += 8; return val; }, readSFixed64: function() { var val = readUInt32(this.buf, this.pos) + readInt32(this.buf, this.pos + 4) * SHIFT_LEFT_32; this.pos += 8; return val; }, readFloat: function() { var val = ieee754.read(this.buf, this.pos, true, 23, 4); this.pos += 4; return val; }, readDouble: function() { var val = ieee754.read(this.buf, this.pos, true, 52, 8); this.pos += 8; return val; }, readVarint: function(isSigned) { var buf = this.buf, val, b; b = buf[this.pos++]; val = b & 127; if (b < 128) return val; b = buf[this.pos++]; val |= (b & 127) << 7; if (b < 128) return val; b = buf[this.pos++]; val |= (b & 127) << 14; if (b < 128) return val; b = buf[this.pos++]; val |= (b & 127) << 21; if (b < 128) return val; b = buf[this.pos]; val |= (b & 15) << 28; return readVarintRemainder2(val, isSigned, this); }, readVarint64: function() { return this.readVarint(true); }, readSVarint: function() { var num = this.readVarint(); return num % 2 === 1 ? (num + 1) / -2 : num / 2; }, readBoolean: function() { return Boolean(this.readVarint()); }, readString: function() { var end = this.readVarint() + this.pos; var pos = this.pos; this.pos = end; if (end - pos >= TEXT_DECODER_MIN_LENGTH && utf8TextDecoder) { return readUtf8TextDecoder(this.buf, pos, end); } return readUtf8(this.buf, pos, end); }, readBytes: function() { var end = this.readVarint() + this.pos, buffer = this.buf.subarray(this.pos, end); this.pos = end; return buffer; }, readPackedVarint: function(arr2, isSigned) { if (this.type !== Pbf.Bytes) return arr2.push(this.readVarint(isSigned)); var end = readPackedEnd(this); arr2 = arr2 || []; while (this.pos < end) arr2.push(this.readVarint(isSigned)); return arr2; }, readPackedSVarint: function(arr2) { if (this.type !== Pbf.Bytes) return arr2.push(this.readSVarint()); var end = readPackedEnd(this); arr2 = arr2 || []; while (this.pos < end) arr2.push(this.readSVarint()); return arr2; }, readPackedBoolean: function(arr2) { if (this.type !== Pbf.Bytes) return arr2.push(this.readBoolean()); var end = readPackedEnd(this); arr2 = arr2 || []; while (this.pos < end) arr2.push(this.readBoolean()); return arr2; }, readPackedFloat: function(arr2) { if (this.type !== Pbf.Bytes) return arr2.push(this.readFloat()); var end = readPackedEnd(this); arr2 = arr2 || []; while (this.pos < end) arr2.push(this.readFloat()); return arr2; }, readPackedDouble: function(arr2) { if (this.type !== Pbf.Bytes) return arr2.push(this.readDouble()); var end = readPackedEnd(this); arr2 = arr2 || []; while (this.pos < end) arr2.push(this.readDouble()); return arr2; }, readPackedFixed32: function(arr2) { if (this.type !== Pbf.Bytes) return arr2.push(this.readFixed32()); var end = readPackedEnd(this); arr2 = arr2 || []; while (this.pos < end) arr2.push(this.readFixed32()); return arr2; }, readPackedSFixed32: function(arr2) { if (this.type !== Pbf.Bytes) return arr2.push(this.readSFixed32()); var end = readPackedEnd(this); arr2 = arr2 || []; while (this.pos < end) arr2.push(this.readSFixed32()); return arr2; }, readPackedFixed64: function(arr2) { if (this.type !== Pbf.Bytes) return arr2.push(this.readFixed64()); var end = readPackedEnd(this); arr2 = arr2 || []; while (this.pos < end) arr2.push(this.readFixed64()); return arr2; }, readPackedSFixed64: function(arr2) { if (this.type !== Pbf.Bytes) return arr2.push(this.readSFixed64()); var end = readPackedEnd(this); arr2 = arr2 || []; while (this.pos < end) arr2.push(this.readSFixed64()); return arr2; }, skip: function(val) { var type = val & 7; if (type === Pbf.Varint) while (this.buf[this.pos++] > 127) { } else if (type === Pbf.Bytes) this.pos = this.readVarint() + this.pos; else if (type === Pbf.Fixed32) this.pos += 4; else if (type === Pbf.Fixed64) this.pos += 8; else throw new Error("Unimplemented type: " + type); }, writeTag: function(tag, type) { this.writeVarint(tag << 3 | type); }, realloc: function(min) { var length = this.length || 16; while (length < this.pos + min) length *= 2; if (length !== this.length) { var buf = new Uint8Array(length); buf.set(this.buf); this.buf = buf; this.length = length; } }, finish: function() { this.length = this.pos; this.pos = 0; return this.buf.subarray(0, this.length); }, writeFixed32: function(val) { this.realloc(4); writeInt32(this.buf, val, this.pos); this.pos += 4; }, writeSFixed32: function(val) { this.realloc(4); writeInt32(this.buf, val, this.pos); this.pos += 4; }, writeFixed64: function(val) { this.realloc(8); writeInt32(this.buf, val & -1, this.pos); writeInt32(this.buf, Math.floor(val * SHIFT_RIGHT_32), this.pos + 4); this.pos += 8; }, writeSFixed64: function(val) { this.realloc(8); writeInt32(this.buf, val & -1, this.pos); writeInt32(this.buf, Math.floor(val * SHIFT_RIGHT_32), this.pos + 4); this.pos += 8; }, writeVarint: function(val) { val = +val || 0; if (val > 268435455 || val < 0) { writeBigVarint(val, this); return; } this.realloc(4); this.buf[this.pos++] = val & 127 | (val > 127 ? 128 : 0); if (val <= 127) return; this.buf[this.pos++] = (val >>>= 7) & 127 | (val > 127 ? 128 : 0); if (val <= 127) return; this.buf[this.pos++] = (val >>>= 7) & 127 | (val > 127 ? 128 : 0); if (val <= 127) return; this.buf[this.pos++] = val >>> 7 & 127; }, writeSVarint: function(val) { this.writeVarint(val < 0 ? -val * 2 - 1 : val * 2); }, writeBoolean: function(val) { this.writeVarint(Boolean(val)); }, writeString: function(str) { str = String(str); this.realloc(str.length * 4); this.pos++; var startPos = this.pos; this.pos = writeUtf8(this.buf, str, this.pos); var len = this.pos - startPos; if (len >= 128) makeRoomForExtraLength(startPos, len, this); this.pos = startPos - 1; this.writeVarint(len); this.pos += len; }, writeFloat: function(val) { this.realloc(4); ieee754.write(this.buf, val, this.pos, true, 23, 4); this.pos += 4; }, writeDouble: function(val) { this.realloc(8); ieee754.write(this.buf, val, this.pos, true, 52, 8); this.pos += 8; }, writeBytes: function(buffer) { var len = buffer.length; this.writeVarint(len); this.realloc(len); for (var i2 = 0; i2 < len; i2++) this.buf[this.pos++] = buffer[i2]; }, writeRawMessage: function(fn, obj) { this.pos++; var startPos = this.pos; fn(obj, this); var len = this.pos - startPos; if (len >= 128) makeRoomForExtraLength(startPos, len, this); this.pos = startPos - 1; this.writeVarint(len); this.pos += len; }, writeMessage: function(tag, fn, obj) { this.writeTag(tag, Pbf.Bytes); this.writeRawMessage(fn, obj); }, writePackedVarint: function(tag, arr2) { if (arr2.length) this.writeMessage(tag, writePackedVarint, arr2); }, writePackedSVarint: function(tag, arr2) { if (arr2.length) this.writeMessage(tag, writePackedSVarint, arr2); }, writePackedBoolean: function(tag, arr2) { if (arr2.length) this.writeMessage(tag, writePackedBoolean, arr2); }, writePackedFloat: function(tag, arr2) { if (arr2.length) this.writeMessage(tag, writePackedFloat, arr2); }, writePackedDouble: function(tag, arr2) { if (arr2.length) this.writeMessage(tag, writePackedDouble, arr2); }, writePackedFixed32: function(tag, arr2) { if (arr2.length) this.writeMessage(tag, writePackedFixed32, arr2); }, writePackedSFixed32: function(tag, arr2) { if (arr2.length) this.writeMessage(tag, writePackedSFixed32, arr2); }, writePackedFixed64: function(tag, arr2) { if (arr2.length) this.writeMessage(tag, writePackedFixed64, arr2); }, writePackedSFixed64: function(tag, arr2) { if (arr2.length) this.writeMessage(tag, writePackedSFixed64, arr2); }, writeBytesField: function(tag, buffer) { this.writeTag(tag, Pbf.Bytes); this.writeBytes(buffer); }, writeFixed32Field: function(tag, val) { this.writeTag(tag, Pbf.Fixed32); this.writeFixed32(val); }, writeSFixed32Field: function(tag, val) { this.writeTag(tag, Pbf.Fixed32); this.writeSFixed32(val); }, writeFixed64Field: function(tag, val) { this.writeTag(tag, Pbf.Fixed64); this.writeFixed64(val); }, writeSFixed64Field: function(tag, val) { this.writeTag(tag, Pbf.Fixed64); this.writeSFixed64(val); }, writeVarintField: function(tag, val) { this.writeTag(tag, Pbf.Varint); this.writeVarint(val); }, writeSVarintField: function(tag, val) { this.writeTag(tag, Pbf.Varint); this.writeSVarint(val); }, writeStringField: function(tag, str) { this.writeTag(tag, Pbf.Bytes); this.writeString(str); }, writeFloatField: function(tag, val) { this.writeTag(tag, Pbf.Fixed32); this.writeFloat(val); }, writeDoubleField: function(tag, val) { this.writeTag(tag, Pbf.Fixed64); this.writeDouble(val); }, writeBooleanField: function(tag, val) { this.writeVarintField(tag, Boolean(val)); } }; function readVarintRemainder2(l, s, p) { var buf = p.buf, h, b; b = buf[p.pos++]; h = (b & 112) >> 4; if (b < 128) return toNum2(l, h, s); b = buf[p.pos++]; h |= (b & 127) << 3; if (b < 128) return toNum2(l, h, s); b = buf[p.pos++]; h |= (b & 127) << 10; if (b < 128) return toNum2(l, h, s); b = buf[p.pos++]; h |= (b & 127) << 17; if (b < 128) return toNum2(l, h, s); b = buf[p.pos++]; h |= (b & 127) << 24; if (b < 128) return toNum2(l, h, s); b = buf[p.pos++]; h |= (b & 1) << 31; if (b < 128) return toNum2(l, h, s); throw new Error("Expected varint not more than 10 bytes"); } function readPackedEnd(pbf) { return pbf.type === Pbf.Bytes ? pbf.readVarint() + pbf.pos : pbf.pos + 1; } function toNum2(low, high, isSigned) { if (isSigned) { return high * 4294967296 + (low >>> 0); } return (high >>> 0) * 4294967296 + (low >>> 0); } function writeBigVarint(val, pbf) { var low, high; if (val >= 0) { low = val % 4294967296 | 0; high = val / 4294967296 | 0; } else { low = ~(-val % 4294967296); high = ~(-val / 4294967296); if (low ^ 4294967295) { low = low + 1 | 0; } else { low = 0; high = high + 1 | 0; } } if (val >= 18446744073709552e3 || val < -18446744073709552e3) { throw new Error("Given varint doesn't fit into 10 bytes"); } pbf.realloc(10); writeBigVarintLow(low, high, pbf); writeBigVarintHigh(high, pbf); } function writeBigVarintLow(low, high, pbf) { pbf.buf[pbf.pos++] = low & 127 | 128; low >>>= 7; pbf.buf[pbf.pos++] = low & 127 | 128; low >>>= 7; pbf.buf[pbf.pos++] = low & 127 | 128; low >>>= 7; pbf.buf[pbf.pos++] = low & 127 | 128; low >>>= 7; pbf.buf[pbf.pos] = low & 127; } function writeBigVarintHigh(high, pbf) { var lsb = (high & 7) << 4; pbf.buf[pbf.pos++] |= lsb | ((high >>>= 3) ? 128 : 0); if (!high) return; pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0); if (!high) return; pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0); if (!high) return; pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0); if (!high) return; pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0); if (!high) return; pbf.buf[pbf.pos++] = high & 127; } function makeRoomForExtraLength(startPos, len, pbf) { var extraLen = len <= 16383 ? 1 : len <= 2097151 ? 2 : len <= 268435455 ? 3 : Math.floor(Math.log(len) / (Math.LN2 * 7)); pbf.realloc(extraLen); for (var i2 = pbf.pos - 1; i2 >= startPos; i2--) pbf.buf[i2 + extraLen] = pbf.buf[i2]; } function writePackedVarint(arr2, pbf) { for (var i2 = 0; i2 < arr2.length; i2++) pbf.writeVarint(arr2[i2]); } function writePackedSVarint(arr2, pbf) { for (var i2 = 0; i2 < arr2.length; i2++) pbf.writeSVarint(arr2[i2]); } function writePackedFloat(arr2, pbf) { for (var i2 = 0; i2 < arr2.length; i2++) pbf.writeFloat(arr2[i2]); } function writePackedDouble(arr2, pbf) { for (var i2 = 0; i2 < arr2.length; i2++) pbf.writeDouble(arr2[i2]); } function writePackedBoolean(arr2, pbf) { for (var i2 = 0; i2 < arr2.length; i2++) pbf.writeBoolean(arr2[i2]); } function writePackedFixed32(arr2, pbf) { for (var i2 = 0; i2 < arr2.length; i2++) pbf.writeFixed32(arr2[i2]); } function writePackedSFixed32(arr2, pbf) { for (var i2 = 0; i2 < arr2.length; i2++) pbf.writeSFixed32(arr2[i2]); } function writePackedFixed64(arr2, pbf) { for (var i2 = 0; i2 < arr2.length; i2++) pbf.writeFixed64(arr2[i2]); } function writePackedSFixed64(arr2, pbf) { for (var i2 = 0; i2 < arr2.length; i2++) pbf.writeSFixed64(arr2[i2]); } function readUInt32(buf, pos) { return (buf[pos] | buf[pos + 1] << 8 | buf[pos + 2] << 16) + buf[pos + 3] * 16777216; } function writeInt32(buf, val, pos) { buf[pos] = val; buf[pos + 1] = val >>> 8; buf[pos + 2] = val >>> 16; buf[pos + 3] = val >>> 24; } function readInt32(buf, pos) { return (buf[pos] | buf[pos + 1] << 8 | buf[pos + 2] << 16) + (buf[pos + 3] << 24); } function readUtf8(buf, pos, end) { var str = ""; var i2 = pos; while (i2 < end) { var b0 = buf[i2]; var c = null; var bytesPerSequence = b0 > 239 ? 4 : b0 > 223 ? 3 : b0 > 191 ? 2 : 1; if (i2 + bytesPerSequence > end) break; var b1, b2, b3; if (bytesPerSequence === 1) { if (b0 < 128) { c = b0; } } else if (bytesPerSequence === 2) { b1 = buf[i2 + 1]; if ((b1 & 192) === 128) { c = (b0 & 31) << 6 | b1 & 63; if (c <= 127) { c = null; } } } else if (bytesPerSequence === 3) { b1 = buf[i2 + 1]; b2 = buf[i2 + 2]; if ((b1 & 192) === 128 && (b2 & 192) === 128) { c = (b0 & 15) << 12 | (b1 & 63) << 6 | b2 & 63; if (c <= 2047 || c >= 55296 && c <= 57343) { c = null; } } } else if (bytesPerSequence === 4) { b1 = buf[i2 + 1]; b2 = buf[i2 + 2]; b3 = buf[i2 + 3]; if ((b1 & 192) === 128 && (b2 & 192) === 128 && (b3 & 192) === 128) { c = (b0 & 15) << 18 | (b1 & 63) << 12 | (b2 & 63) << 6 | b3 & 63; if (c <= 65535 || c >= 1114112) { c = null; } } } if (c === null) { c = 65533; bytesPerSequence = 1; } else if (c > 65535) { c -= 65536; str += String.fromCharCode(c >>> 10 & 1023 | 55296); c = 56320 | c & 1023; } str += String.fromCharCode(c); i2 += bytesPerSequence; } return str; } function readUtf8TextDecoder(buf, pos, end) { return utf8TextDecoder.decode(buf.subarray(pos, end)); } function writeUtf8(buf, str, pos) { for (var i2 = 0, c, lead; i2 < str.length; i2++) { c = str.charCodeAt(i2); if (c > 55295 && c < 57344) { if (lead) { if (c < 56320) { buf[pos++] = 239; buf[pos++] = 191; buf[pos++] = 189; lead = c; continue; } else { c = lead - 55296 << 10 | c - 56320 | 65536; lead = null; } } else { if (c > 56319 || i2 + 1 === str.length) { buf[pos++] = 239; buf[pos++] = 191; buf[pos++] = 189; } else { lead = c; } continue; } } else if (lead) { buf[pos++] = 239; buf[pos++] = 191; buf[pos++] = 189; lead = null; } if (c < 128) { buf[pos++] = c; } else { if (c < 2048) { buf[pos++] = c >> 6 | 192; } else { if (c < 65536) { buf[pos++] = c >> 12 | 224; } else { buf[pos++] = c >> 18 | 240; buf[pos++] = c >> 12 & 63 | 128; } buf[pos++] = c >> 6 & 63 | 128; } buf[pos++] = c & 63 | 128; } } return pos; } } }); // node_modules/rbush/rbush.min.js var require_rbush_min = __commonJS({ "node_modules/rbush/rbush.min.js"(exports, module) { !function(t, i2) { "object" == typeof exports && "undefined" != typeof module ? module.exports = i2() : "function" == typeof define && define.amd ? define(i2) : (t = t || self).RBush = i2(); }(exports, function() { "use strict"; function t(t2, r3, e2, a2, h2) { !function t3(n2, r4, e3, a3, h3) { for (; a3 > e3; ) { if (a3 - e3 > 600) { var o2 = a3 - e3 + 1, s2 = r4 - e3 + 1, l2 = Math.log(o2), f2 = 0.5 * Math.exp(2 * l2 / 3), u2 = 0.5 * Math.sqrt(l2 * f2 * (o2 - f2) / o2) * (s2 - o2 / 2 < 0 ? -1 : 1), m2 = Math.max(e3, Math.floor(r4 - s2 * f2 / o2 + u2)), c2 = Math.min(a3, Math.floor(r4 + (o2 - s2) * f2 / o2 + u2)); t3(n2, r4, m2, c2, h3); } var p2 = n2[r4], d2 = e3, x2 = a3; for (i2(n2, e3, r4), h3(n2[a3], p2) > 0 && i2(n2, e3, a3); d2 < x2; ) { for (i2(n2, d2, x2), d2++, x2--; h3(n2[d2], p2) < 0; ) d2++; for (; h3(n2[x2], p2) > 0; ) x2--; } 0 === h3(n2[e3], p2) ? i2(n2, e3, x2) : i2(n2, ++x2, a3), x2 <= r4 && (e3 = x2 + 1), r4 <= x2 && (a3 = x2 - 1); } }(t2, r3, e2 || 0, a2 || t2.length - 1, h2 || n); } function i2(t2, i3, n2) { var r3 = t2[i3]; t2[i3] = t2[n2], t2[n2] = r3; } function n(t2, i3) { return t2 < i3 ? -1 : t2 > i3 ? 1 : 0; } var r2 = function(t2) { void 0 === t2 && (t2 = 9), this._maxEntries = Math.max(4, t2), this._minEntries = Math.max(2, Math.ceil(0.4 * this._maxEntries)), this.clear(); }; function e(t2, i3, n2) { if (!n2) return i3.indexOf(t2); for (var r3 = 0; r3 < i3.length; r3++) if (n2(t2, i3[r3])) return r3; return -1; } function a(t2, i3) { h(t2, 0, t2.children.length, i3, t2); } function h(t2, i3, n2, r3, e2) { e2 || (e2 = p(null)), e2.minX = 1 / 0, e2.minY = 1 / 0, e2.maxX = -1 / 0, e2.maxY = -1 / 0; for (var a2 = i3; a2 < n2; a2++) { var h2 = t2.children[a2]; o(e2, t2.leaf ? r3(h2) : h2); } return e2; } function o(t2, i3) { return t2.minX = Math.min(t2.minX, i3.minX), t2.minY = Math.min(t2.minY, i3.minY), t2.maxX = Math.max(t2.maxX, i3.maxX), t2.maxY = Math.max(t2.maxY, i3.maxY), t2; } function s(t2, i3) { return t2.minX - i3.minX; } function l(t2, i3) { return t2.minY - i3.minY; } function f(t2) { return (t2.maxX - t2.minX) * (t2.maxY - t2.minY); } function u(t2) { return t2.maxX - t2.minX + (t2.maxY - t2.minY); } function m(t2, i3) { return t2.minX <= i3.minX && t2.minY <= i3.minY && i3.maxX <= t2.maxX && i3.maxY <= t2.maxY; } function c(t2, i3) { return i3.minX <= t2.maxX && i3.minY <= t2.maxY && i3.maxX >= t2.minX && i3.maxY >= t2.minY; } function p(t2) { return { children: t2, height: 1, leaf: true, minX: 1 / 0, minY: 1 / 0, maxX: -1 / 0, maxY: -1 / 0 }; } function d(i3, n2, r3, e2, a2) { for (var h2 = [n2, r3]; h2.length; ) if (!((r3 = h2.pop()) - (n2 = h2.pop()) <= e2)) { var o2 = n2 + Math.ceil((r3 - n2) / e2 / 2) * e2; t(i3, o2, n2, r3, a2), h2.push(n2, o2, o2, r3); } } return r2.prototype.all = function() { return this._all(this.data, []); }, r2.prototype.search = function(t2) { var i3 = this.data, n2 = []; if (!c(t2, i3)) return n2; for (var r3 = this.toBBox, e2 = []; i3; ) { for (var a2 = 0; a2 < i3.children.length; a2++) { var h2 = i3.children[a2], o2 = i3.leaf ? r3(h2) : h2; c(t2, o2) && (i3.leaf ? n2.push(h2) : m(t2, o2) ? this._all(h2, n2) : e2.push(h2)); } i3 = e2.pop(); } return n2; }, r2.prototype.collides = function(t2) { var i3 = this.data; if (!c(t2, i3)) return false; for (var n2 = []; i3; ) { for (var r3 = 0; r3 < i3.children.length; r3++) { var e2 = i3.children[r3], a2 = i3.leaf ? this.toBBox(e2) : e2; if (c(t2, a2)) { if (i3.leaf || m(t2, a2)) return true; n2.push(e2); } } i3 = n2.pop(); } return false; }, r2.prototype.load = function(t2) { if (!t2 || !t2.length) return this; if (t2.length < this._minEntries) { for (var i3 = 0; i3 < t2.length; i3++) this.insert(t2[i3]); return this; } var n2 = this._build(t2.slice(), 0, t2.length - 1, 0); if (this.data.children.length) if (this.data.height === n2.height) this._splitRoot(this.data, n2); else { if (this.data.height < n2.height) { var r3 = this.data; this.data = n2, n2 = r3; } this._insert(n2, this.data.height - n2.height - 1, true); } else this.data = n2; return this; }, r2.prototype.insert = function(t2) { return t2 && this._insert(t2, this.data.height - 1), this; }, r2.prototype.clear = function() { return this.data = p([]), this; }, r2.prototype.remove = function(t2, i3) { if (!t2) return this; for (var n2, r3, a2, h2 = this.data, o2 = this.toBBox(t2), s2 = [], l2 = []; h2 || s2.length; ) { if (h2 || (h2 = s2.pop(), r3 = s2[s2.length - 1], n2 = l2.pop(), a2 = true), h2.leaf) { var f2 = e(t2, h2.children, i3); if (-1 !== f2) return h2.children.splice(f2, 1), s2.push(h2), this._condense(s2), this; } a2 || h2.leaf || !m(h2, o2) ? r3 ? (n2++, h2 = r3.children[n2], a2 = false) : h2 = null : (s2.push(h2), l2.push(n2), n2 = 0, r3 = h2, h2 = h2.children[0]); } return this; }, r2.prototype.toBBox = function(t2) { return t2; }, r2.prototype.compareMinX = function(t2, i3) { return t2.minX - i3.minX; }, r2.prototype.compareMinY = function(t2, i3) { return t2.minY - i3.minY; }, r2.prototype.toJSON = function() { return this.data; }, r2.prototype.fromJSON = function(t2) { return this.data = t2, this; }, r2.prototype._all = function(t2, i3) { for (var n2 = []; t2; ) t2.leaf ? i3.push.apply(i3, t2.children) : n2.push.apply(n2, t2.children), t2 = n2.pop(); return i3; }, r2.prototype._build = function(t2, i3, n2, r3) { var e2, h2 = n2 - i3 + 1, o2 = this._maxEntries; if (h2 <= o2) return a(e2 = p(t2.slice(i3, n2 + 1)), this.toBBox), e2; r3 || (r3 = Math.ceil(Math.log(h2) / Math.log(o2)), o2 = Math.ceil(h2 / Math.pow(o2, r3 - 1))), (e2 = p([])).leaf = false, e2.height = r3; var s2 = Math.ceil(h2 / o2), l2 = s2 * Math.ceil(Math.sqrt(o2)); d(t2, i3, n2, l2, this.compareMinX); for (var f2 = i3; f2 <= n2; f2 += l2) { var u2 = Math.min(f2 + l2 - 1, n2); d(t2, f2, u2, s2, this.compareMinY); for (var m2 = f2; m2 <= u2; m2 += s2) { var c2 = Math.min(m2 + s2 - 1, u2); e2.children.push(this._build(t2, m2, c2, r3 - 1)); } } return a(e2, this.toBBox), e2; }, r2.prototype._chooseSubtree = function(t2, i3, n2, r3) { for (; r3.push(i3), !i3.leaf && r3.length - 1 !== n2; ) { for (var e2 = 1 / 0, a2 = 1 / 0, h2 = void 0, o2 = 0; o2 < i3.children.length; o2++) { var s2 = i3.children[o2], l2 = f(s2), u2 = (m2 = t2, c2 = s2, (Math.max(c2.maxX, m2.maxX) - Math.min(c2.minX, m2.minX)) * (Math.max(c2.maxY, m2.maxY) - Math.min(c2.minY, m2.minY)) - l2); u2 < a2 ? (a2 = u2, e2 = l2 < e2 ? l2 : e2, h2 = s2) : u2 === a2 && l2 < e2 && (e2 = l2, h2 = s2); } i3 = h2 || i3.children[0]; } var m2, c2; return i3; }, r2.prototype._insert = function(t2, i3, n2) { var r3 = n2 ? t2 : this.toBBox(t2), e2 = [], a2 = this._chooseSubtree(r3, this.data, i3, e2); for (a2.children.push(t2), o(a2, r3); i3 >= 0 && e2[i3].children.length > this._maxEntries; ) this._split(e2, i3), i3--; this._adjustParentBBoxes(r3, e2, i3); }, r2.prototype._split = function(t2, i3) { var n2 = t2[i3], r3 = n2.children.length, e2 = this._minEntries; this._chooseSplitAxis(n2, e2, r3); var h2 = this._chooseSplitIndex(n2, e2, r3), o2 = p(n2.children.splice(h2, n2.children.length - h2)); o2.height = n2.height, o2.leaf = n2.leaf, a(n2, this.toBBox), a(o2, this.toBBox), i3 ? t2[i3 - 1].children.push(o2) : this._splitRoot(n2, o2); }, r2.prototype._splitRoot = function(t2, i3) { this.data = p([t2, i3]), this.data.height = t2.height + 1, this.data.leaf = false, a(this.data, this.toBBox); }, r2.prototype._chooseSplitIndex = function(t2, i3, n2) { for (var r3, e2, a2, o2, s2, l2, u2, m2 = 1 / 0, c2 = 1 / 0, p2 = i3; p2 <= n2 - i3; p2++) { var d2 = h(t2, 0, p2, this.toBBox), x2 = h(t2, p2, n2, this.toBBox), v = (e2 = d2, a2 = x2, o2 = void 0, s2 = void 0, l2 = void 0, u2 = void 0, o2 = Math.max(e2.minX, a2.minX), s2 = Math.max(e2.minY, a2.minY), l2 = Math.min(e2.maxX, a2.maxX), u2 = Math.min(e2.maxY, a2.maxY), Math.max(0, l2 - o2) * Math.max(0, u2 - s2)), M = f(d2) + f(x2); v < m2 ? (m2 = v, r3 = p2, c2 = M < c2 ? M : c2) : v === m2 && M < c2 && (c2 = M, r3 = p2); } return r3 || n2 - i3; }, r2.prototype._chooseSplitAxis = function(t2, i3, n2) { var r3 = t2.leaf ? this.compareMinX : s, e2 = t2.leaf ? this.compareMinY : l; this._allDistMargin(t2, i3, n2, r3) < this._allDistMargin(t2, i3, n2, e2) && t2.children.sort(r3); }, r2.prototype._allDistMargin = function(t2, i3, n2, r3) { t2.children.sort(r3); for (var e2 = this.toBBox, a2 = h(t2, 0, i3, e2), s2 = h(t2, n2 - i3, n2, e2), l2 = u(a2) + u(s2), f2 = i3; f2 < n2 - i3; f2++) { var m2 = t2.children[f2]; o(a2, t2.leaf ? e2(m2) : m2), l2 += u(a2); } for (var c2 = n2 - i3 - 1; c2 >= i3; c2--) { var p2 = t2.children[c2]; o(s2, t2.leaf ? e2(p2) : p2), l2 += u(s2); } return l2; }, r2.prototype._adjustParentBBoxes = function(t2, i3, n2) { for (var r3 = n2; r3 >= 0; r3--) o(i3[r3], t2); }, r2.prototype._condense = function(t2) { for (var i3 = t2.length - 1, n2 = void 0; i3 >= 0; i3--) 0 === t2[i3].children.length ? i3 > 0 ? (n2 = t2[i3 - 1].children).splice(n2.indexOf(t2[i3]), 1) : this.clear() : a(t2[i3], this.toBBox); }, r2; });