UNPKG

ol-pmtiles

Version:

PMTiles sources for OpenLayers

1,450 lines (1,433 loc) 386 kB
"use strict"; var olpmtiles = (() => { var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b2) => { for (var prop in b2 || (b2 = {})) if (__hasOwnProp.call(b2, prop)) __defNormalProp(a, prop, b2[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b2)) { if (__propIsEnum.call(b2, prop)) __defNormalProp(a, prop, b2[prop]); } return a; }; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; 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( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var __async = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { step(generator.next(value)); } catch (e) { reject(e); } }; var rejected = (value) => { try { step(generator.throw(value)); } catch (e) { reject(e); } }; var step = (x2) => x2.done ? resolve(x2.value) : Promise.resolve(x2.value).then(fulfilled, rejected); step((generator = generator.apply(__this, __arguments)).next()); }); }; // node_modules/ieee754/index.js var require_ieee754 = __commonJS({ "node_modules/ieee754/index.js"(exports) { "use strict"; exports.read = function(buffer2, offset, isLE, mLen, nBytes) { var e, m2; 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 = buffer2[offset + i]; i += d; e = s & (1 << -nBits) - 1; s >>= -nBits; nBits += eLen; for (; nBits > 0; e = e * 256 + buffer2[offset + i], i += d, nBits -= 8) { } m2 = e & (1 << -nBits) - 1; e >>= -nBits; nBits += mLen; for (; nBits > 0; m2 = m2 * 256 + buffer2[offset + i], i += d, nBits -= 8) { } if (e === 0) { e = 1 - eBias; } else if (e === eMax) { return m2 ? NaN : (s ? -1 : 1) * Infinity; } else { m2 = m2 + Math.pow(2, mLen); e = e - eBias; } return (s ? -1 : 1) * m2 * Math.pow(2, e - mLen); }; exports.write = function(buffer2, value, offset, isLE, mLen, nBytes) { var e, m2, 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) { m2 = 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) { m2 = 0; e = eMax; } else if (e + eBias >= 1) { m2 = (value * c - 1) * Math.pow(2, mLen); e = e + eBias; } else { m2 = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); e = 0; } } for (; mLen >= 8; buffer2[offset + i] = m2 & 255, i += d, m2 /= 256, mLen -= 8) { } e = e << mLen | m2; eLen += mLen; for (; eLen > 0; buffer2[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) { } buffer2[offset + i - 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; } __name(Pbf, "Pbf"); 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: /* @__PURE__ */ __name(function() { this.buf = null; }, "destroy"), // === READING ================================================================= readFields: /* @__PURE__ */ __name(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; }, "readFields"), readMessage: /* @__PURE__ */ __name(function(readField, result) { return this.readFields(readField, result, this.readVarint() + this.pos); }, "readMessage"), readFixed32: /* @__PURE__ */ __name(function() { var val = readUInt32(this.buf, this.pos); this.pos += 4; return val; }, "readFixed32"), readSFixed32: /* @__PURE__ */ __name(function() { var val = readInt32(this.buf, this.pos); this.pos += 4; return val; }, "readSFixed32"), // 64-bit int handling is based on github.com/dpw/node-buffer-more-ints (MIT-licensed) readFixed64: /* @__PURE__ */ __name(function() { var val = readUInt32(this.buf, this.pos) + readUInt32(this.buf, this.pos + 4) * SHIFT_LEFT_32; this.pos += 8; return val; }, "readFixed64"), readSFixed64: /* @__PURE__ */ __name(function() { var val = readUInt32(this.buf, this.pos) + readInt32(this.buf, this.pos + 4) * SHIFT_LEFT_32; this.pos += 8; return val; }, "readSFixed64"), readFloat: /* @__PURE__ */ __name(function() { var val = ieee754.read(this.buf, this.pos, true, 23, 4); this.pos += 4; return val; }, "readFloat"), readDouble: /* @__PURE__ */ __name(function() { var val = ieee754.read(this.buf, this.pos, true, 52, 8); this.pos += 8; return val; }, "readDouble"), readVarint: /* @__PURE__ */ __name(function(isSigned) { var buf = this.buf, val, b2; b2 = buf[this.pos++]; val = b2 & 127; if (b2 < 128) return val; b2 = buf[this.pos++]; val |= (b2 & 127) << 7; if (b2 < 128) return val; b2 = buf[this.pos++]; val |= (b2 & 127) << 14; if (b2 < 128) return val; b2 = buf[this.pos++]; val |= (b2 & 127) << 21; if (b2 < 128) return val; b2 = buf[this.pos]; val |= (b2 & 15) << 28; return readVarintRemainder(val, isSigned, this); }, "readVarint"), readVarint64: /* @__PURE__ */ __name(function() { return this.readVarint(true); }, "readVarint64"), readSVarint: /* @__PURE__ */ __name(function() { var num = this.readVarint(); return num % 2 === 1 ? (num + 1) / -2 : num / 2; }, "readSVarint"), readBoolean: /* @__PURE__ */ __name(function() { return Boolean(this.readVarint()); }, "readBoolean"), readString: /* @__PURE__ */ __name(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); }, "readString"), readBytes: /* @__PURE__ */ __name(function() { var end = this.readVarint() + this.pos, buffer2 = this.buf.subarray(this.pos, end); this.pos = end; return buffer2; }, "readBytes"), // verbose for performance reasons; doesn't affect gzipped size readPackedVarint: /* @__PURE__ */ __name(function(arr, isSigned) { if (this.type !== Pbf.Bytes) return arr.push(this.readVarint(isSigned)); var end = readPackedEnd(this); arr = arr || []; while (this.pos < end) arr.push(this.readVarint(isSigned)); return arr; }, "readPackedVarint"), readPackedSVarint: /* @__PURE__ */ __name(function(arr) { if (this.type !== Pbf.Bytes) return arr.push(this.readSVarint()); var end = readPackedEnd(this); arr = arr || []; while (this.pos < end) arr.push(this.readSVarint()); return arr; }, "readPackedSVarint"), readPackedBoolean: /* @__PURE__ */ __name(function(arr) { if (this.type !== Pbf.Bytes) return arr.push(this.readBoolean()); var end = readPackedEnd(this); arr = arr || []; while (this.pos < end) arr.push(this.readBoolean()); return arr; }, "readPackedBoolean"), readPackedFloat: /* @__PURE__ */ __name(function(arr) { if (this.type !== Pbf.Bytes) return arr.push(this.readFloat()); var end = readPackedEnd(this); arr = arr || []; while (this.pos < end) arr.push(this.readFloat()); return arr; }, "readPackedFloat"), readPackedDouble: /* @__PURE__ */ __name(function(arr) { if (this.type !== Pbf.Bytes) return arr.push(this.readDouble()); var end = readPackedEnd(this); arr = arr || []; while (this.pos < end) arr.push(this.readDouble()); return arr; }, "readPackedDouble"), readPackedFixed32: /* @__PURE__ */ __name(function(arr) { if (this.type !== Pbf.Bytes) return arr.push(this.readFixed32()); var end = readPackedEnd(this); arr = arr || []; while (this.pos < end) arr.push(this.readFixed32()); return arr; }, "readPackedFixed32"), readPackedSFixed32: /* @__PURE__ */ __name(function(arr) { if (this.type !== Pbf.Bytes) return arr.push(this.readSFixed32()); var end = readPackedEnd(this); arr = arr || []; while (this.pos < end) arr.push(this.readSFixed32()); return arr; }, "readPackedSFixed32"), readPackedFixed64: /* @__PURE__ */ __name(function(arr) { if (this.type !== Pbf.Bytes) return arr.push(this.readFixed64()); var end = readPackedEnd(this); arr = arr || []; while (this.pos < end) arr.push(this.readFixed64()); return arr; }, "readPackedFixed64"), readPackedSFixed64: /* @__PURE__ */ __name(function(arr) { if (this.type !== Pbf.Bytes) return arr.push(this.readSFixed64()); var end = readPackedEnd(this); arr = arr || []; while (this.pos < end) arr.push(this.readSFixed64()); return arr; }, "readPackedSFixed64"), skip: /* @__PURE__ */ __name(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); }, "skip"), // === WRITING ================================================================= writeTag: /* @__PURE__ */ __name(function(tag, type) { this.writeVarint(tag << 3 | type); }, "writeTag"), realloc: /* @__PURE__ */ __name(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; } }, "realloc"), finish: /* @__PURE__ */ __name(function() { this.length = this.pos; this.pos = 0; return this.buf.subarray(0, this.length); }, "finish"), writeFixed32: /* @__PURE__ */ __name(function(val) { this.realloc(4); writeInt32(this.buf, val, this.pos); this.pos += 4; }, "writeFixed32"), writeSFixed32: /* @__PURE__ */ __name(function(val) { this.realloc(4); writeInt32(this.buf, val, this.pos); this.pos += 4; }, "writeSFixed32"), writeFixed64: /* @__PURE__ */ __name(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; }, "writeFixed64"), writeSFixed64: /* @__PURE__ */ __name(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"), writeVarint: /* @__PURE__ */ __name(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; }, "writeVarint"), writeSVarint: /* @__PURE__ */ __name(function(val) { this.writeVarint(val < 0 ? -val * 2 - 1 : val * 2); }, "writeSVarint"), writeBoolean: /* @__PURE__ */ __name(function(val) { this.writeVarint(Boolean(val)); }, "writeBoolean"), writeString: /* @__PURE__ */ __name(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; }, "writeString"), writeFloat: /* @__PURE__ */ __name(function(val) { this.realloc(4); ieee754.write(this.buf, val, this.pos, true, 23, 4); this.pos += 4; }, "writeFloat"), writeDouble: /* @__PURE__ */ __name(function(val) { this.realloc(8); ieee754.write(this.buf, val, this.pos, true, 52, 8); this.pos += 8; }, "writeDouble"), writeBytes: /* @__PURE__ */ __name(function(buffer2) { var len = buffer2.length; this.writeVarint(len); this.realloc(len); for (var i = 0; i < len; i++) this.buf[this.pos++] = buffer2[i]; }, "writeBytes"), writeRawMessage: /* @__PURE__ */ __name(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; }, "writeRawMessage"), writeMessage: /* @__PURE__ */ __name(function(tag, fn, obj) { this.writeTag(tag, Pbf.Bytes); this.writeRawMessage(fn, obj); }, "writeMessage"), writePackedVarint: /* @__PURE__ */ __name(function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedVarint, arr); }, "writePackedVarint"), writePackedSVarint: /* @__PURE__ */ __name(function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedSVarint, arr); }, "writePackedSVarint"), writePackedBoolean: /* @__PURE__ */ __name(function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedBoolean, arr); }, "writePackedBoolean"), writePackedFloat: /* @__PURE__ */ __name(function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedFloat, arr); }, "writePackedFloat"), writePackedDouble: /* @__PURE__ */ __name(function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedDouble, arr); }, "writePackedDouble"), writePackedFixed32: /* @__PURE__ */ __name(function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedFixed32, arr); }, "writePackedFixed32"), writePackedSFixed32: /* @__PURE__ */ __name(function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedSFixed32, arr); }, "writePackedSFixed32"), writePackedFixed64: /* @__PURE__ */ __name(function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedFixed64, arr); }, "writePackedFixed64"), writePackedSFixed64: /* @__PURE__ */ __name(function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedSFixed64, arr); }, "writePackedSFixed64"), writeBytesField: /* @__PURE__ */ __name(function(tag, buffer2) { this.writeTag(tag, Pbf.Bytes); this.writeBytes(buffer2); }, "writeBytesField"), writeFixed32Field: /* @__PURE__ */ __name(function(tag, val) { this.writeTag(tag, Pbf.Fixed32); this.writeFixed32(val); }, "writeFixed32Field"), writeSFixed32Field: /* @__PURE__ */ __name(function(tag, val) { this.writeTag(tag, Pbf.Fixed32); this.writeSFixed32(val); }, "writeSFixed32Field"), writeFixed64Field: /* @__PURE__ */ __name(function(tag, val) { this.writeTag(tag, Pbf.Fixed64); this.writeFixed64(val); }, "writeFixed64Field"), writeSFixed64Field: /* @__PURE__ */ __name(function(tag, val) { this.writeTag(tag, Pbf.Fixed64); this.writeSFixed64(val); }, "writeSFixed64Field"), writeVarintField: /* @__PURE__ */ __name(function(tag, val) { this.writeTag(tag, Pbf.Varint); this.writeVarint(val); }, "writeVarintField"), writeSVarintField: /* @__PURE__ */ __name(function(tag, val) { this.writeTag(tag, Pbf.Varint); this.writeSVarint(val); }, "writeSVarintField"), writeStringField: /* @__PURE__ */ __name(function(tag, str) { this.writeTag(tag, Pbf.Bytes); this.writeString(str); }, "writeStringField"), writeFloatField: /* @__PURE__ */ __name(function(tag, val) { this.writeTag(tag, Pbf.Fixed32); this.writeFloat(val); }, "writeFloatField"), writeDoubleField: /* @__PURE__ */ __name(function(tag, val) { this.writeTag(tag, Pbf.Fixed64); this.writeDouble(val); }, "writeDoubleField"), writeBooleanField: /* @__PURE__ */ __name(function(tag, val) { this.writeVarintField(tag, Boolean(val)); }, "writeBooleanField") }; function readVarintRemainder(l2, s, p) { var buf = p.buf, h, b2; b2 = buf[p.pos++]; h = (b2 & 112) >> 4; if (b2 < 128) return toNum(l2, h, s); b2 = buf[p.pos++]; h |= (b2 & 127) << 3; if (b2 < 128) return toNum(l2, h, s); b2 = buf[p.pos++]; h |= (b2 & 127) << 10; if (b2 < 128) return toNum(l2, h, s); b2 = buf[p.pos++]; h |= (b2 & 127) << 17; if (b2 < 128) return toNum(l2, h, s); b2 = buf[p.pos++]; h |= (b2 & 127) << 24; if (b2 < 128) return toNum(l2, h, s); b2 = buf[p.pos++]; h |= (b2 & 1) << 31; if (b2 < 128) return toNum(l2, h, s); throw new Error("Expected varint not more than 10 bytes"); } __name(readVarintRemainder, "readVarintRemainder"); function readPackedEnd(pbf) { return pbf.type === Pbf.Bytes ? pbf.readVarint() + pbf.pos : pbf.pos + 1; } __name(readPackedEnd, "readPackedEnd"); function toNum(low, high, isSigned) { if (isSigned) { return high * 4294967296 + (low >>> 0); } return (high >>> 0) * 4294967296 + (low >>> 0); } __name(toNum, "toNum"); 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); } __name(writeBigVarint, "writeBigVarint"); 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; } __name(writeBigVarintLow, "writeBigVarintLow"); 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; } __name(writeBigVarintHigh, "writeBigVarintHigh"); 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 i = pbf.pos - 1; i >= startPos; i--) pbf.buf[i + extraLen] = pbf.buf[i]; } __name(makeRoomForExtraLength, "makeRoomForExtraLength"); function writePackedVarint(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeVarint(arr[i]); } __name(writePackedVarint, "writePackedVarint"); function writePackedSVarint(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeSVarint(arr[i]); } __name(writePackedSVarint, "writePackedSVarint"); function writePackedFloat(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeFloat(arr[i]); } __name(writePackedFloat, "writePackedFloat"); function writePackedDouble(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeDouble(arr[i]); } __name(writePackedDouble, "writePackedDouble"); function writePackedBoolean(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeBoolean(arr[i]); } __name(writePackedBoolean, "writePackedBoolean"); function writePackedFixed32(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeFixed32(arr[i]); } __name(writePackedFixed32, "writePackedFixed32"); function writePackedSFixed32(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeSFixed32(arr[i]); } __name(writePackedSFixed32, "writePackedSFixed32"); function writePackedFixed64(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeFixed64(arr[i]); } __name(writePackedFixed64, "writePackedFixed64"); function writePackedSFixed64(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeSFixed64(arr[i]); } __name(writePackedSFixed64, "writePackedSFixed64"); function readUInt32(buf, pos) { return (buf[pos] | buf[pos + 1] << 8 | buf[pos + 2] << 16) + buf[pos + 3] * 16777216; } __name(readUInt32, "readUInt32"); function writeInt32(buf, val, pos) { buf[pos] = val; buf[pos + 1] = val >>> 8; buf[pos + 2] = val >>> 16; buf[pos + 3] = val >>> 24; } __name(writeInt32, "writeInt32"); function readInt32(buf, pos) { return (buf[pos] | buf[pos + 1] << 8 | buf[pos + 2] << 16) + (buf[pos + 3] << 24); } __name(readInt32, "readInt32"); function readUtf8(buf, pos, end) { var str = ""; var i = pos; while (i < end) { var b0 = buf[i]; var c = null; var bytesPerSequence = b0 > 239 ? 4 : b0 > 223 ? 3 : b0 > 191 ? 2 : 1; if (i + bytesPerSequence > end) break; var b1, b2, b3; if (bytesPerSequence === 1) { if (b0 < 128) { c = b0; } } else if (bytesPerSequence === 2) { b1 = buf[i + 1]; if ((b1 & 192) === 128) { c = (b0 & 31) << 6 | b1 & 63; if (c <= 127) { c = null; } } } else if (bytesPerSequence === 3) { b1 = buf[i + 1]; b2 = buf[i + 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[i + 1]; b2 = buf[i + 2]; b3 = buf[i + 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); i += bytesPerSequence; } return str; } __name(readUtf8, "readUtf8"); function readUtf8TextDecoder(buf, pos, end) { return utf8TextDecoder.decode(buf.subarray(pos, end)); } __name(readUtf8TextDecoder, "readUtf8TextDecoder"); function writeUtf8(buf, str, pos) { for (var i = 0, c, lead; i < str.length; i++) { c = str.charCodeAt(i); 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 || i + 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; } __name(writeUtf8, "writeUtf8"); } }); // src/index.ts var src_exports = {}; __export(src_exports, { PMTilesRasterSource: () => PMTilesRasterSource, PMTilesVectorSource: () => PMTilesVectorSource }); // node_modules/ol/Disposable.js var _Disposable = class _Disposable { constructor() { this.disposed = false; } /** * Clean up. */ dispose() { if (!this.disposed) { this.disposed = true; this.disposeInternal(); } } /** * Extension point for disposable objects. * @protected */ disposeInternal() { } }; __name(_Disposable, "Disposable"); var Disposable = _Disposable; var Disposable_default = Disposable; // node_modules/ol/events/Event.js var _BaseEvent = class _BaseEvent { /** * @param {string} type Type. */ constructor(type) { this.propagationStopped; this.defaultPrevented; this.type = type; this.target = null; } /** * Prevent default. This means that no emulated `click`, `singleclick` or `doubleclick` events * will be fired. * @api */ preventDefault() { this.defaultPrevented = true; } /** * Stop event propagation. * @api */ stopPropagation() { this.propagationStopped = true; } }; __name(_BaseEvent, "BaseEvent"); var BaseEvent = _BaseEvent; var Event_default = BaseEvent; // node_modules/ol/array.js function binarySearch(haystack, needle, comparator) { let mid, cmp; comparator = comparator || ascending; let low = 0; let high = haystack.length; let found = false; while (low < high) { mid = low + (high - low >> 1); cmp = +comparator(haystack[mid], needle); if (cmp < 0) { low = mid + 1; } else { high = mid; found = !cmp; } } return found ? low : ~low; } __name(binarySearch, "binarySearch"); function ascending(a, b2) { return a > b2 ? 1 : a < b2 ? -1 : 0; } __name(ascending, "ascending"); function linearFindNearest(arr, target, direction) { if (arr[0] <= target) { return 0; } const n = arr.length; if (target <= arr[n - 1]) { return n - 1; } if (typeof direction === "function") { for (let i = 1; i < n; ++i) { const candidate = arr[i]; if (candidate === target) { return i; } if (candidate < target) { if (direction(target, arr[i - 1], candidate) > 0) { return i - 1; } return i; } } return n - 1; } if (direction > 0) { for (let i = 1; i < n; ++i) { if (arr[i] < target) { return i - 1; } } return n - 1; } if (direction < 0) { for (let i = 1; i < n; ++i) { if (arr[i] <= target) { return i; } } return n - 1; } for (let i = 1; i < n; ++i) { if (arr[i] == target) { return i; } if (arr[i] < target) { if (arr[i - 1] - target < target - arr[i]) { return i - 1; } return i; } } return n - 1; } __name(linearFindNearest, "linearFindNearest"); function extend(arr, data) { const extension = Array.isArray(data) ? data : [data]; const length = extension.length; for (let i = 0; i < length; i++) { arr[arr.length] = extension[i]; } } __name(extend, "extend"); function equals(arr1, arr2) { const len1 = arr1.length; if (len1 !== arr2.length) { return false; } for (let i = 0; i < len1; i++) { if (arr1[i] !== arr2[i]) { return false; } } return true; } __name(equals, "equals"); function isSorted(arr, func, strict) { const compare = func || ascending; return arr.every(function(currentVal, index) { if (index === 0) { return true; } const res = compare(arr[index - 1], currentVal); return !(res > 0 || strict && res === 0); }); } __name(isSorted, "isSorted"); // node_modules/ol/functions.js function VOID() { } __name(VOID, "VOID"); function memoizeOne(fn) { let called = false; let lastResult; let lastArgs; let lastThis; return function() { const nextArgs = Array.prototype.slice.call(arguments); if (!called || this !== lastThis || !equals(nextArgs, lastArgs)) { called = true; lastThis = this; lastArgs = nextArgs; lastResult = fn.apply(this, arguments); } return lastResult; }; } __name(memoizeOne, "memoizeOne"); function toPromise(getter) { function promiseGetter() { let value; try { value = getter(); } catch (err2) { return Promise.reject(err2); } if (value instanceof Promise) { return value; } return Promise.resolve(value); } __name(promiseGetter, "promiseGetter"); return promiseGetter(); } __name(toPromise, "toPromise"); // node_modules/ol/obj.js function clear(object) { for (const property in object) { delete object[property]; } } __name(clear, "clear"); function isEmpty(object) { let property; for (property in object) { return false; } return !property; } __name(isEmpty, "isEmpty"); // node_modules/ol/events/Target.js var _Target = class _Target extends Disposable_default { /** * @param {*} [target] Default event target for dispatched events. */ constructor(target) { super(); this.eventTarget_ = target; this.pendingRemovals_ = null; this.dispatching_ = null; this.listeners_ = null; } /** * @param {string} type Type. * @param {import("../events.js").Listener} listener Listener. */ addEventListener(type, listener) { if (!type || !listener) { return; } const listeners = this.listeners_ || (this.listeners_ = {}); const listenersForType = listeners[type] || (listeners[type] = []); if (!listenersForType.includes(listener)) { listenersForType.push(listener); } } /** * Dispatches an event and calls all listeners listening for events * of this type. The event parameter can either be a string or an * Object with a `type` property. * * @param {import("./Event.js").default|string} event Event object. * @return {boolean|undefined} `false` if anyone called preventDefault on the * event object or if any of the listeners returned false. * @api */ dispatchEvent(event) { const isString = typeof event === "string"; const type = isString ? event : event.type; const listeners = this.listeners_ && this.listeners_[type]; if (!listeners) { return; } const evt = isString ? new Event_default(event) : ( /** @type {Event} */ event ); if (!evt.target) { evt.target = this.eventTarget_ || this; } const dispatching = this.dispatching_ || (this.dispatching_ = {}); const pendingRemovals = this.pendingRemovals_ || (this.pendingRemovals_ = {}); if (!(type in dispatching)) { dispatching[type] = 0; pendingRemovals[type] = 0; } ++dispatching[type]; let propagate; for (let i = 0, ii = listeners.length; i < ii; ++i) { if ("handleEvent" in listeners[i]) { propagate = /** @type {import("../events.js").ListenerObject} */ listeners[i].handleEvent(evt); } else { propagate = /** @type {import("../events.js").ListenerFunction} */ listeners[i].call(this, evt); } if (propagate === false || evt.propagationStopped) { propagate = false; break; } } if (--dispatching[type] === 0) { let pr = pendingRemovals[type]; delete pendingRemovals[type]; while (pr--) { this.removeEventListener(type, VOID); } delete dispatching[type]; } return propagate; } /** * Clean up. */ disposeInternal() { this.listeners_ && clear(this.listeners_); } /** * Get the listeners for a specified event type. Listeners are returned in the * order that they will be called in. * * @param {string} type Type. * @return {Array<import("../events.js").Listener>|undefined} Listeners. */ getListeners(type) { return this.listeners_ && this.listeners_[type] || void 0; } /** * @param {string} [type] Type. If not provided, * `true` will be returned if this event target has any listeners. * @return {boolean} Has listeners. */ hasListener(type) { if (!this.listeners_) { return false; } return type ? type in this.listeners_ : Object.keys(this.listeners_).length > 0; } /** * @param {string} type Type. * @param {import("../events.js").Listener} listener Listener. */ removeEventListener(type, listener) { if (!this.listeners_) { return; } const listeners = this.listeners_[type]; if (!listeners) { return; } const index = listeners.indexOf(listener); if (index !== -1) { if (this.pendingRemovals_ && type in this.pendingRemovals_) { listeners[index] = VOID; ++this.pendingRemovals_[type]; } else { listeners.splice(index, 1); if (listeners.length === 0) { delete this.listeners_[type]; } } } } }; __name(_Target, "Target"); var Target = _Target; var Target_default = Target; // node_modules/ol/events/EventType.js var EventType_default = { /** * Generic change event. Triggered when the revision counter is increased. * @event module:ol/events/Event~BaseEvent#change * @api */ CHANGE: "change", /** * Generic error event. Triggered when an error occurs. * @event module:ol/events/Event~BaseEvent#error * @api */ ERROR: "error", BLUR: "blur", CLEAR: "clear", CONTEXTMENU: "contextmenu", CLICK: "click", DBLCLICK: "dblclick", DRAGENTER: "dragenter", DRAGOVER: "dragover", DROP: "drop", FOCUS: "focus", KEYDOWN: "keydown", KEYPRESS: "keypress", LOAD: "load", RESIZE: "resize", TOUCHMOVE: "touchmove", WHEEL: "wheel" }; // node_modules/ol/TileState.js var TileState_default = { IDLE: 0, LOADING: 1, LOADED: 2, /** * Indicates that tile loading failed * @type {number} */ ERROR: 3, EMPTY: 4 }; // node_modules/ol/util.js function abstract() { throw new Error("Unimplemented abstract method."); } __name(abstract, "abstract"); var uidCounter_ = 0; function getUid(obj) { return obj.ol_uid || (obj.ol_uid = String(++uidCounter_)); } __name(getUid, "getUid"); // node_modules/ol/easing.js function easeIn(t) { return Math.pow(t, 3); } __name(easeIn, "easeIn"); // node_modules/ol/Tile.js var _Tile = class _Tile extends Target_default { /** * @param {import("./tilecoord.js").TileCoord} tileCoord Tile coordinate. * @param {import("./TileState.js").default} state State. * @param {Options} [options] Tile options. */ constructor(tileCoord, state, options) { super(); options = options ? options : {}; this.tileCoord = tileCoord; this.state = state; this.interimTile = null; this.key = ""; this.transition_ = options.transition === void 0 ? 250 : options.transition; this.transitionStarts_ = {}; this.interpolate = !!options.interpolate; } /** * @protected */ changed() { this.dispatchEvent(EventType_default.CHANGE); } /** * Called by the tile cache when the tile is removed from the cache due to expiry */ release() { if (this.state === TileState_default.ERROR) { this.setState(TileState_default.EMPTY); } } /** * @return {string} Key. */ getKey() { return this.key + "/" + this.tileCoord; } /** * Get the interim tile most suitable for rendering using the chain of interim * tiles. This corresponds to the most recent tile that has been loaded, if no * such tile exists, the original tile is returned. * @return {!Tile} Best tile for rendering. */ getInterimTile() { let tile = this.interimTile; if (!tile) { return this; } do { if (tile.getState() == TileState_default.LOADED) { this.transition_ = 0; return tile; } tile = tile.interimTile; } while (tile); return this; } /** * Goes through the chain of interim tiles and discards sections of the chain * that are no longer relevant. */ refreshInterimChain() { let tile = this.interimTile; if (!tile) { return; } let prev = this; do { if (tile.getState() == TileState_default.LOADED) { tile.interimTile = null; break; } if (tile.getState() == TileState_default.LOADING) { prev = tile; } else if (tile.getState() == TileState_default.IDLE) { prev.interimTile = tile.interimTile; } else { prev = tile; } tile = prev.interimTile; } while (tile); } /** * Get the tile coordinate for this tile. * @return {import("./tilecoord.js").TileCoord} The tile coordinate. * @api */ getTileCoord() { return this.tileCoord; } /** * @return {import("./TileState.js").default} State. */ getState() { return this.state; } /** * Sets the state of this tile. If you write your own {@link module:ol/Tile~LoadFunction tileLoadFunction} , * it is important to set the state correctly to {@link module:ol/TileState~ERROR} * when the tile cannot be loaded. Otherwise the tile cannot be removed from * the tile queue and will block other requests. * @param {import("./TileState.js").default} state State. * @api */ setState(state) { if (this.state !== TileState_default.ERROR && this.state > state) { throw new Error("Tile load sequence violation"); } this.state = state; this.changed(); } /** * Load the image or retry if loading previously failed. * Loading is taken care of by the tile queue, and calling this method is * only needed for preloading or for reloading in case of an error. * @abstract * @api */ load() { abstract(); } /** * Get the alpha value for rendering. * @param {string} id An id for the renderer. * @param {number} time The render frame time. * @return {number} A number between 0 and 1. */ getAlpha(id, time) { if (!this.transition_) { return 1; } let start = this.transitionStarts_[id]; if (!start) { start = time; this.transitionStarts_[id] = start; } else if (start === -1) { return 1; } const delta = time - start + 1e3 / 60; if (delta >= this.transition_) { return 1; } return easeIn(delta / this.transition_); } /** * Determine if a tile is in an alpha transition. A tile is considered in * transition if tile.getAlpha() has not yet been called or has been called * and returned 1. * @param {string} id An id for the renderer. * @return {boolean} The tile is in transition. */ inTransition(id) { if (!this.transition_) { return false; } return this.transitionStarts_[id] !== -1; } /** * Mark a transition as complete. * @param {string} id An id for the renderer. */ endTransition(id) { if (this.transition_) { this.transitionStarts_[id] = -1; } } }; __name(_Tile, "Tile"); var Tile = _Tile; var Tile_default = Tile; // node_modules/ol/has.js var ua = typeof navigator !== "undefined" && typeof navigator.userAgent !== "undefined" ? navigator.userAgent.toLowerCase() : ""; var FIREFOX = ua.includes("firefox"); var SAFARI = ua.includes("safari") && !ua.includes("chrom"); var SAFARI_BUG_237906 = SAFARI && (ua.includes("version/15.4") || /cpu (os|iphone os) 15_4 like mac os x/.test(ua)); var WEBKIT = ua.includes("webkit") && !ua.includes("edge"); var MAC = ua.includes("macintosh"); var WORKER_OFFSCREEN_CANVAS = typeof WorkerGlobalScope !== "undefined" && typeof OffscreenCanvas !== "undefined" && self instanceof WorkerGlobalScope; var IMAGE_DECODE = typeof Image !== "undefined" && Image.prototype.decode; var PASSIVE_EVENT_LISTENERS = function() { let passive = false; try { const options = Object.defineProperty({}, "passive", { get: /* @__PURE__ */ __name(function() { passive = true; }, "get") }); window.addEventListener("_", null, options); window.removeEventListener("_", null, options); } catch (error) { } return passive; }(); // node_modules/ol/dom.js function createCanvasContext2D(width, height, canvasPool3, settings) { let canvas; if (canvasPool3 && canvasPool3.length) { canvas = /** @type {HTMLCanvasElement} */ canvasPool3.shift(); } else if (WORKER_OFFSCREEN_CANVAS) { canvas = new OffscreenCanvas(width || 300, height || 300); } else { canvas = document.createElement("canvas"); } if (width) { canvas.width = width; } if (height) { canvas.height = height; } return ( /** @type {CanvasRenderingContext2D} */ canvas.getContext("2d", settings) ); } __name(createCanvasContext2D, "createCanvasContext2D"); function releaseCanvas(context) { const canvas = context.canvas; canvas.width = 1; canvas.height = 1; context.clearRect(0, 0, 1, 1); } __name(releaseCanvas, "releaseCanvas"); // node_modules/ol/DataTile.js function asImageLike(data) { return data instanceof Image || data instanceof HTMLCanvasElement || data instanceof HTMLVideoElement || data instanceof ImageBitmap ? data : null; } __name(asImageLike, "asImageLike"); function asArrayLike(data) { return data instanceof Uint8Array || data instanceof Uint8ClampedArray || data instanceof Float32Array || data instanceof DataView ? data : null; } __name(asArrayLike, "asArrayLike"); var sharedContext = null; function toArray(image) { if (!sharedContext) { sharedContext = createCanvasContext2D( image.width, image.height, void 0, { willReadFrequently: true } ); } const canvas = sharedContext.canvas; const width = image.width; if (canvas.width !== width) { canvas.width = width; } const height = image.height; if (canvas.height !== height) { canvas.height = height; } sharedContext.clearRect(0, 0, width, height); sharedContext.d