iflow-engine-base 4.0.15 → 4.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,717 @@
1
+ var w = Uint8Array, I = Uint16Array, Fe = Int32Array, ve = new w([
2
+ 0,
3
+ 0,
4
+ 0,
5
+ 0,
6
+ 0,
7
+ 0,
8
+ 0,
9
+ 0,
10
+ 1,
11
+ 1,
12
+ 1,
13
+ 1,
14
+ 2,
15
+ 2,
16
+ 2,
17
+ 2,
18
+ 3,
19
+ 3,
20
+ 3,
21
+ 3,
22
+ 4,
23
+ 4,
24
+ 4,
25
+ 4,
26
+ 5,
27
+ 5,
28
+ 5,
29
+ 5,
30
+ 0,
31
+ /* unused */
32
+ 0,
33
+ 0,
34
+ /* impossible */
35
+ 0
36
+ ]), me = new w([
37
+ 0,
38
+ 0,
39
+ 0,
40
+ 0,
41
+ 1,
42
+ 1,
43
+ 2,
44
+ 2,
45
+ 3,
46
+ 3,
47
+ 4,
48
+ 4,
49
+ 5,
50
+ 5,
51
+ 6,
52
+ 6,
53
+ 7,
54
+ 7,
55
+ 8,
56
+ 8,
57
+ 9,
58
+ 9,
59
+ 10,
60
+ 10,
61
+ 11,
62
+ 11,
63
+ 12,
64
+ 12,
65
+ 13,
66
+ 13,
67
+ /* unused */
68
+ 0,
69
+ 0
70
+ ]), Pe = new w([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), ye = function(r, e) {
71
+ for (var t = new I(31), i = 0; i < 31; ++i)
72
+ t[i] = e += 1 << r[i - 1];
73
+ for (var n = new Fe(t[30]), i = 1; i < 30; ++i)
74
+ for (var a = t[i]; a < t[i + 1]; ++a)
75
+ n[a] = a - t[i] << 5 | i;
76
+ return { b: t, r: n };
77
+ }, pe = ye(ve, 2), we = pe.b, Re = pe.r;
78
+ we[28] = 258, Re[258] = 28;
79
+ var $e = ye(me, 0), Be = $e.b, q = new I(32768);
80
+ for (var g = 0; g < 32768; ++g) {
81
+ var M = (g & 43690) >> 1 | (g & 21845) << 1;
82
+ M = (M & 52428) >> 2 | (M & 13107) << 2, M = (M & 61680) >> 4 | (M & 3855) << 4, q[g] = ((M & 65280) >> 8 | (M & 255) << 8) >> 1;
83
+ }
84
+ var Z = (function(r, e, t) {
85
+ for (var i = r.length, n = 0, a = new I(e); n < i; ++n)
86
+ r[n] && ++a[r[n] - 1];
87
+ var s = new I(e);
88
+ for (n = 1; n < e; ++n)
89
+ s[n] = s[n - 1] + a[n - 1] << 1;
90
+ var o;
91
+ if (t) {
92
+ o = new I(1 << e);
93
+ var c = 15 - e;
94
+ for (n = 0; n < i; ++n)
95
+ if (r[n])
96
+ for (var h = n << 4 | r[n], f = e - r[n], l = s[r[n] - 1]++ << f, u = l | (1 << f) - 1; l <= u; ++l)
97
+ o[q[l] >> c] = h;
98
+ } else
99
+ for (o = new I(i), n = 0; n < i; ++n)
100
+ r[n] && (o[n] = q[s[r[n] - 1]++] >> 15 - r[n]);
101
+ return o;
102
+ }), k = new w(288);
103
+ for (var g = 0; g < 144; ++g)
104
+ k[g] = 8;
105
+ for (var g = 144; g < 256; ++g)
106
+ k[g] = 9;
107
+ for (var g = 256; g < 280; ++g)
108
+ k[g] = 7;
109
+ for (var g = 280; g < 288; ++g)
110
+ k[g] = 8;
111
+ var be = new w(32);
112
+ for (var g = 0; g < 32; ++g)
113
+ be[g] = 5;
114
+ var Ke = /* @__PURE__ */ Z(k, 9, 1), je = /* @__PURE__ */ Z(be, 5, 1), J = function(r) {
115
+ for (var e = r[0], t = 1; t < r.length; ++t)
116
+ r[t] > e && (e = r[t]);
117
+ return e;
118
+ }, T = function(r, e, t) {
119
+ var i = e / 8 | 0;
120
+ return (r[i] | r[i + 1] << 8) >> (e & 7) & t;
121
+ }, G = function(r, e) {
122
+ var t = e / 8 | 0;
123
+ return (r[t] | r[t + 1] << 8 | r[t + 2] << 16) >> (e & 7);
124
+ }, We = function(r) {
125
+ return (r + 7) / 8 | 0;
126
+ }, _e = function(r, e, t) {
127
+ return (t == null || t > r.length) && (t = r.length), new w(r.subarray(e, t));
128
+ }, Ne = [
129
+ "unexpected EOF",
130
+ "invalid block type",
131
+ "invalid length/literal",
132
+ "invalid distance",
133
+ "stream finished",
134
+ "no stream handler",
135
+ ,
136
+ // determined by compression function
137
+ "no callback",
138
+ "invalid UTF-8 data",
139
+ "extra field too long",
140
+ "date not in range 1980-2099",
141
+ "filename too long",
142
+ "stream finishing",
143
+ "invalid zip data"
144
+ // determined by unknown compression method
145
+ ], p = function(r, e, t) {
146
+ var i = new Error(e || Ne[r]);
147
+ if (i.code = r, Error.captureStackTrace && Error.captureStackTrace(i, p), !t)
148
+ throw i;
149
+ return i;
150
+ }, X = function(r, e, t, i) {
151
+ var n = r.length, a = 0;
152
+ if (!n || e.f && !e.l)
153
+ return t || new w(0);
154
+ var s = !t, o = s || e.i != 2, c = e.i;
155
+ s && (t = new w(n * 3));
156
+ var h = function(ue) {
157
+ var fe = t.length;
158
+ if (ue > fe) {
159
+ var de = new w(Math.max(fe * 2, ue));
160
+ de.set(t), t = de;
161
+ }
162
+ }, f = e.f || 0, l = e.p || 0, u = e.b || 0, y = e.l, C = e.d, v = e.m, A = e.n, R = n * 8;
163
+ do {
164
+ if (!y) {
165
+ f = T(r, l, 1);
166
+ var $ = T(r, l + 1, 3);
167
+ if (l += 3, $)
168
+ if ($ == 1)
169
+ y = Ke, C = je, v = 9, A = 5;
170
+ else if ($ == 2) {
171
+ var j = T(r, l, 31) + 257, ie = T(r, l + 10, 15) + 4, ne = j + T(r, l + 5, 31) + 1;
172
+ l += 14;
173
+ for (var S = new w(ne), W = new w(19), b = 0; b < ie; ++b)
174
+ W[Pe[b]] = T(r, l + b * 3, 7);
175
+ l += ie * 3;
176
+ for (var ae = J(W), Ie = (1 << ae) - 1, Se = Z(W, ae, 1), b = 0; b < ne; ) {
177
+ var se = Se[T(r, l, Ie)];
178
+ l += se & 15;
179
+ var U = se >> 4;
180
+ if (U < 16)
181
+ S[b++] = U;
182
+ else {
183
+ var z = 0, F = 0;
184
+ for (U == 16 ? (F = 3 + T(r, l, 3), l += 2, z = S[b - 1]) : U == 17 ? (F = 3 + T(r, l, 7), l += 3) : U == 18 && (F = 11 + T(r, l, 127), l += 7); F--; )
185
+ S[b++] = z;
186
+ }
187
+ }
188
+ var oe = S.subarray(0, j), E = S.subarray(j);
189
+ v = J(oe), A = J(E), y = Z(oe, v, 1), C = Z(E, A, 1);
190
+ } else
191
+ p(1);
192
+ else {
193
+ var U = We(l) + 4, B = r[U - 4] | r[U - 3] << 8, K = U + B;
194
+ if (K > n) {
195
+ c && p(0);
196
+ break;
197
+ }
198
+ o && h(u + B), t.set(r.subarray(U, K), u), e.b = u += B, e.p = l = K * 8, e.f = f;
199
+ continue;
200
+ }
201
+ if (l > R) {
202
+ c && p(0);
203
+ break;
204
+ }
205
+ }
206
+ o && h(u + 131072);
207
+ for (var Oe = (1 << v) - 1, Ze = (1 << A) - 1, _ = l; ; _ = l) {
208
+ var z = y[G(r, l) & Oe], D = z >> 4;
209
+ if (l += z & 15, l > R) {
210
+ c && p(0);
211
+ break;
212
+ }
213
+ if (z || p(2), D < 256)
214
+ t[u++] = D;
215
+ else if (D == 256) {
216
+ _ = l, y = null;
217
+ break;
218
+ } else {
219
+ var le = D - 254;
220
+ if (D > 264) {
221
+ var b = D - 257, O = ve[b];
222
+ le = T(r, l, (1 << O) - 1) + we[b], l += O;
223
+ }
224
+ var N = C[G(r, l) & Ze], V = N >> 4;
225
+ N || p(3), l += N & 15;
226
+ var E = Be[V];
227
+ if (V > 3) {
228
+ var O = me[V];
229
+ E += G(r, l) & (1 << O) - 1, l += O;
230
+ }
231
+ if (l > R) {
232
+ c && p(0);
233
+ break;
234
+ }
235
+ o && h(u + 131072);
236
+ var ce = u + le;
237
+ if (u < E) {
238
+ var he = a - E, ke = Math.min(E, ce);
239
+ for (he + u < 0 && p(3); u < ke; ++u)
240
+ t[u] = i[he + u];
241
+ }
242
+ for (; u < ce; ++u)
243
+ t[u] = t[u - E];
244
+ }
245
+ }
246
+ e.l = y, e.p = _, e.b = u, e.f = f, y && (f = 1, e.m = v, e.d = C, e.n = A);
247
+ } while (!f);
248
+ return u != t.length && s ? _e(t, 0, u) : t.subarray(0, u);
249
+ }, Ve = /* @__PURE__ */ new w(0), Je = function(r) {
250
+ (r[0] != 31 || r[1] != 139 || r[2] != 8) && p(6, "invalid gzip data");
251
+ var e = r[3], t = 10;
252
+ e & 4 && (t += (r[10] | r[11] << 8) + 2);
253
+ for (var i = (e >> 3 & 1) + (e >> 4 & 1); i > 0; i -= !r[t++])
254
+ ;
255
+ return t + (e & 2);
256
+ }, Ge = function(r) {
257
+ var e = r.length;
258
+ return (r[e - 4] | r[e - 3] << 8 | r[e - 2] << 16 | r[e - 1] << 24) >>> 0;
259
+ }, qe = function(r, e) {
260
+ return ((r[0] & 15) != 8 || r[0] >> 4 > 7 || (r[0] << 8 | r[1]) % 31) && p(6, "invalid zlib data"), (r[1] >> 5 & 1) == 1 && p(6, "invalid zlib data: " + (r[1] & 32 ? "need" : "unexpected") + " dictionary"), (r[1] >> 3 & 4) + 2;
261
+ };
262
+ function Qe(r, e) {
263
+ return X(r, { i: 2 }, e, e);
264
+ }
265
+ function Xe(r, e) {
266
+ var t = Je(r);
267
+ return t + 8 > r.length && p(6, "invalid gzip data"), X(r.subarray(t, -8), { i: 2 }, new w(Ge(r)), e);
268
+ }
269
+ function Ye(r, e) {
270
+ return X(r.subarray(qe(r), -4), { i: 2 }, e, e);
271
+ }
272
+ function et(r, e) {
273
+ return r[0] == 31 && r[1] == 139 && r[2] == 8 ? Xe(r, e) : (r[0] & 15) != 8 || r[0] >> 4 > 7 || (r[0] << 8 | r[1]) % 31 ? Qe(r, e) : Ye(r, e);
274
+ }
275
+ var tt = typeof TextDecoder < "u" && /* @__PURE__ */ new TextDecoder(), rt = 0;
276
+ try {
277
+ tt.decode(Ve, { stream: !0 }), rt = 1;
278
+ } catch {
279
+ }
280
+ var it = Object.defineProperty, nt = Math.pow, d = (r, e) => it(r, "name", { value: e, configurable: !0 }), m = (r, e, t) => new Promise((i, n) => {
281
+ var a = (c) => {
282
+ try {
283
+ o(t.next(c));
284
+ } catch (h) {
285
+ n(h);
286
+ }
287
+ }, s = (c) => {
288
+ try {
289
+ o(t.throw(c));
290
+ } catch (h) {
291
+ n(h);
292
+ }
293
+ }, o = (c) => c.done ? i(c.value) : Promise.resolve(c.value).then(a, s);
294
+ o((t = t.apply(r, e)).next());
295
+ });
296
+ d((r, e) => {
297
+ let t = !1, i = "", n = L.GridLayer.extend({ createTile: d((a, s) => {
298
+ let o = document.createElement("img"), c = new AbortController(), h = c.signal;
299
+ return o.cancel = () => {
300
+ c.abort();
301
+ }, t || (r.getHeader().then((f) => {
302
+ f.tileType === 1 || f.tileType === 6 ? console.error("Error: archive contains vector tiles, but leafletRasterLayer is for displaying raster tiles. See https://github.com/protomaps/PMTiles/tree/main/js for details.") : f.tileType === 2 ? i = "image/png" : f.tileType === 3 ? i = "image/jpeg" : f.tileType === 4 ? i = "image/webp" : f.tileType === 5 && (i = "image/avif");
303
+ }), t = !0), r.getZxy(a.z, a.x, a.y, h).then((f) => {
304
+ if (f) {
305
+ let l = new Blob([f.data], { type: i }), u = window.URL.createObjectURL(l);
306
+ o.src = u;
307
+ } else o.style.display = "none";
308
+ o.cancel = void 0, s(void 0, o);
309
+ }).catch((f) => {
310
+ if (f.name !== "AbortError") throw f;
311
+ }), o;
312
+ }, "createTile"), _removeTile: d(function(a) {
313
+ let s = this._tiles[a];
314
+ s && (s.el.cancel && s.el.cancel(), s.el.src && window.URL.revokeObjectURL(s.el.src), s.el.width = 0, s.el.height = 0, s.el.deleted = !0, L.DomUtil.remove(s.el), delete this._tiles[a], this.fire("tileunload", { tile: s.el, coords: this._keyToTileCoords(a) }));
315
+ }, "_removeTile") });
316
+ return new n(e);
317
+ }, "leafletRasterLayer");
318
+ var at = d((r) => (e, t) => {
319
+ if (t instanceof AbortController) return r(e, t);
320
+ let i = new AbortController();
321
+ return r(e, i).then((n) => t(void 0, n.data, n.cacheControl || "", n.expires || ""), (n) => t(n)).catch((n) => t(n)), { cancel: d(() => i.abort(), "cancel") };
322
+ }, "v3compat"), st = class {
323
+ constructor(e) {
324
+ this.tilev4 = d((t, i) => m(this, null, function* () {
325
+ if (t.type === "json") {
326
+ let y = t.url.substr(10), C = this.tiles.get(y);
327
+ if (C || (C = new ge(y), this.tiles.set(y, C)), this.metadata) {
328
+ let A = yield C.getTileJson(t.url);
329
+ return i.signal.throwIfAborted(), { data: A };
330
+ }
331
+ let v = yield C.getHeader();
332
+ return i.signal.throwIfAborted(), (v.minLon >= v.maxLon || v.minLat >= v.maxLat) && console.error(`Bounds of PMTiles archive ${v.minLon},${v.minLat},${v.maxLon},${v.maxLat} are not valid.`), { data: { tiles: [`${t.url}/{z}/{x}/{y}`], minzoom: v.minZoom, maxzoom: v.maxZoom, bounds: [v.minLon, v.minLat, v.maxLon, v.maxLat] } };
333
+ }
334
+ let n = new RegExp(/pmtiles:\/\/(.+)\/(\d+)\/(\d+)\/(\d+)/), a = t.url.match(n);
335
+ if (!a) throw new Error("Invalid PMTiles protocol URL");
336
+ let s = a[1], o = this.tiles.get(s);
337
+ o || (o = new ge(s), this.tiles.set(s, o));
338
+ let c = a[2], h = a[3], f = a[4], l = yield o?.getZxy(+c, +h, +f, i.signal);
339
+ if (i.signal.throwIfAborted(), l) return { data: new Uint8Array(l.data), cacheControl: l.cacheControl, expires: l.expires };
340
+ let u = yield o.getHeader();
341
+ if (u.tileType === 1 || u.tileType === 6) {
342
+ if (this.errorOnMissingTile) throw new Error("Tile not found.");
343
+ return { data: new Uint8Array() };
344
+ }
345
+ return { data: null };
346
+ }), "tilev4"), this.tile = at(this.tilev4), this.tiles = /* @__PURE__ */ new Map(), this.metadata = e?.metadata || !1, this.errorOnMissingTile = e?.errorOnMissingTile || !1;
347
+ }
348
+ add(e) {
349
+ this.tiles.set(e.source.getKey(), e);
350
+ }
351
+ get(e) {
352
+ return this.tiles.get(e);
353
+ }
354
+ };
355
+ d(st, "Protocol");
356
+ function xe(r, e) {
357
+ return (e >>> 0) * 4294967296 + (r >>> 0);
358
+ }
359
+ d(xe, "toNum");
360
+ function Te(r, e) {
361
+ let t = e.buf, i = t[e.pos++], n = (i & 112) >> 4;
362
+ if (i < 128 || (i = t[e.pos++], n |= (i & 127) << 3, i < 128) || (i = t[e.pos++], n |= (i & 127) << 10, i < 128) || (i = t[e.pos++], n |= (i & 127) << 17, i < 128) || (i = t[e.pos++], n |= (i & 127) << 24, i < 128) || (i = t[e.pos++], n |= (i & 1) << 31, i < 128)) return xe(r, n);
363
+ throw new Error("Expected varint not more than 10 bytes");
364
+ }
365
+ d(Te, "readVarintRemainder");
366
+ function H(r) {
367
+ let e = r.buf, t = e[r.pos++], i = t & 127;
368
+ return t < 128 || (t = e[r.pos++], i |= (t & 127) << 7, t < 128) || (t = e[r.pos++], i |= (t & 127) << 14, t < 128) || (t = e[r.pos++], i |= (t & 127) << 21, t < 128) ? i : (t = e[r.pos], i |= (t & 15) << 28, Te(i, r));
369
+ }
370
+ d(H, "readVarint");
371
+ function Y(r, e, t, i, n) {
372
+ return n === 0 ? i !== 0 ? [r - 1 - t, r - 1 - e] : [t, e] : [e, t];
373
+ }
374
+ d(Y, "rotate");
375
+ function Ce(r, e, t) {
376
+ if (r > 26) throw new Error("Tile zoom level exceeds max safe number limit (26)");
377
+ if (e >= 1 << r || t >= 1 << r) throw new Error("tile x/y outside zoom level bounds");
378
+ let i = ((1 << r) * (1 << r) - 1) / 3, n = r - 1, [a, s] = [e, t];
379
+ for (let o = 1 << n; o > 0; o >>= 1) {
380
+ let c = a & o, h = s & o;
381
+ i += (3 * c ^ h) * (1 << n), [a, s] = Y(o, a, s, c, h), n--;
382
+ }
383
+ return i;
384
+ }
385
+ d(Ce, "zxyToTileId");
386
+ function Le(r) {
387
+ let e = 3 * r + 1;
388
+ return e < 4294967296 ? 31 - Math.clz32(e) : 63 - Math.clz32(e / 4294967296);
389
+ }
390
+ d(Le, "tileIdToZ");
391
+ function ot(r) {
392
+ let e = Le(r) >> 1;
393
+ if (e > 26) throw new Error("Tile zoom level exceeds max safe number limit (26)");
394
+ let t = ((1 << e) * (1 << e) - 1) / 3, i = r - t, n = 0, a = 0, s = 1 << e;
395
+ for (let o = 1; o < s; o <<= 1) {
396
+ let c = o & i / 2, h = o & (i ^ c);
397
+ [n, a] = Y(o, n, a, c, h), i = i / 2, n += c, a += h;
398
+ }
399
+ return [e, n, a];
400
+ }
401
+ d(ot, "tileIdToZxy");
402
+ var lt = ((r) => (r[r.Unknown = 0] = "Unknown", r[r.None = 1] = "None", r[r.Gzip = 2] = "Gzip", r[r.Brotli = 3] = "Brotli", r[r.Zstd = 4] = "Zstd", r))(lt || {});
403
+ function P(r, e) {
404
+ return m(this, null, function* () {
405
+ if (e === 1 || e === 0) return r;
406
+ if (e === 2) {
407
+ if (typeof globalThis.DecompressionStream > "u") return et(new Uint8Array(r));
408
+ let t = new Response(r).body;
409
+ if (!t) throw new Error("Failed to read response stream");
410
+ let i = t.pipeThrough(new globalThis.DecompressionStream("gzip"));
411
+ return new Response(i).arrayBuffer();
412
+ }
413
+ throw new Error("Compression method not supported");
414
+ });
415
+ }
416
+ d(P, "defaultDecompress");
417
+ var ct = ((r) => (r[r.Unknown = 0] = "Unknown", r[r.Mvt = 1] = "Mvt", r[r.Png = 2] = "Png", r[r.Jpeg = 3] = "Jpeg", r[r.Webp = 4] = "Webp", r[r.Avif = 5] = "Avif", r[r.Mlt = 6] = "Mlt", r))(ct || {});
418
+ function Ue(r) {
419
+ return r === 1 ? ".mvt" : r === 2 ? ".png" : r === 3 ? ".jpg" : r === 4 ? ".webp" : r === 5 ? ".avif" : r === 6 ? ".mlt" : "";
420
+ }
421
+ d(Ue, "tileTypeExt");
422
+ var ht = 127;
423
+ function Ee(r, e) {
424
+ let t = 0, i = r.length - 1;
425
+ for (; t <= i; ) {
426
+ let n = i + t >> 1, a = e - r[n].tileId;
427
+ if (a > 0) t = n + 1;
428
+ else if (a < 0) i = n - 1;
429
+ else return r[n];
430
+ }
431
+ return i >= 0 && (r[i].runLength === 0 || e - r[i].tileId < r[i].runLength) ? r[i] : null;
432
+ }
433
+ d(Ee, "findTile");
434
+ var ut = class {
435
+ constructor(e) {
436
+ this.file = e;
437
+ }
438
+ getKey() {
439
+ return this.file.name;
440
+ }
441
+ getBytes(e, t) {
442
+ return m(this, null, function* () {
443
+ return { data: yield this.file.slice(e, e + t).arrayBuffer() };
444
+ });
445
+ }
446
+ };
447
+ d(ut, "FileSource");
448
+ var Me = class {
449
+ constructor(e, t = new Headers(), i = void 0) {
450
+ var n, a;
451
+ this.url = e, this.customHeaders = t, this.credentials = i, this.mustReload = !1;
452
+ let s = "";
453
+ "navigator" in globalThis && (s = (a = (n = globalThis.navigator) == null ? void 0 : n.userAgent) != null ? a : "");
454
+ let o = s.indexOf("Windows") > -1, c = /Chrome|Chromium|Edg|OPR|Brave/.test(s);
455
+ this.chromeWindowsNoCache = !1, o && c && (this.chromeWindowsNoCache = !0);
456
+ }
457
+ getKey() {
458
+ return this.url;
459
+ }
460
+ setHeaders(e) {
461
+ this.customHeaders = e;
462
+ }
463
+ getBytes(e, t, i, n) {
464
+ return m(this, null, function* () {
465
+ let a, s;
466
+ i ? s = i : (a = new AbortController(), s = a.signal);
467
+ let o = new Headers(this.customHeaders);
468
+ o.set("range", `bytes=${e}-${e + t - 1}`);
469
+ let c;
470
+ this.mustReload ? c = "reload" : this.chromeWindowsNoCache && (c = "no-store");
471
+ let h = yield fetch(this.url, { signal: s, cache: c, headers: o, credentials: this.credentials });
472
+ if (e === 0 && h.status === 416) {
473
+ let u = h.headers.get("Content-Range");
474
+ if (!u || !u.startsWith("bytes */")) throw new Error("Missing content-length on 416 response");
475
+ let y = +u.substr(8);
476
+ o.set("range", `bytes=0-${y - 1}`), h = yield fetch(this.url, { signal: s, cache: "reload", headers: o, credentials: this.credentials });
477
+ }
478
+ let f = h.headers.get("Etag");
479
+ if (f != null && f.startsWith("W/") && (f = null), h.status === 416 || n && f && f !== n) throw this.mustReload = !0, new Q(`Server returned non-matching ETag ${n} after one retry. Check browser extensions and servers for issues that may affect correct ETag headers.`);
480
+ if (h.status >= 300) throw new Error(`Bad response code: ${h.status}`);
481
+ let l = h.headers.get("Content-Length");
482
+ if (h.status === 200 && (!l || +l > t)) throw a && a.abort(), new Error("Server returned no content-length header or content-length exceeding request. Check that your storage backend supports HTTP Byte Serving.");
483
+ return { data: yield h.arrayBuffer(), etag: f || void 0, cacheControl: h.headers.get("Cache-Control") || void 0, expires: h.headers.get("Expires") || void 0 };
484
+ });
485
+ }
486
+ };
487
+ d(Me, "FetchSource");
488
+ var ft = Me;
489
+ function x(r, e) {
490
+ let t = r.getUint32(e + 4, !0), i = r.getUint32(e + 0, !0);
491
+ return t * nt(2, 32) + i;
492
+ }
493
+ d(x, "getUint64");
494
+ function Ae(r, e) {
495
+ let t = new DataView(r), i = t.getUint8(7);
496
+ if (i > 3) throw new Error(`Archive is spec version ${i} but this library supports up to spec version 3`);
497
+ return { specVersion: i, rootDirectoryOffset: x(t, 8), rootDirectoryLength: x(t, 16), jsonMetadataOffset: x(t, 24), jsonMetadataLength: x(t, 32), leafDirectoryOffset: x(t, 40), leafDirectoryLength: x(t, 48), tileDataOffset: x(t, 56), tileDataLength: x(t, 64), numAddressedTiles: x(t, 72), numTileEntries: x(t, 80), numTileContents: x(t, 88), clustered: t.getUint8(96) === 1, internalCompression: t.getUint8(97), tileCompression: t.getUint8(98), tileType: t.getUint8(99), minZoom: t.getUint8(100), maxZoom: t.getUint8(101), minLon: t.getInt32(102, !0) / 1e7, minLat: t.getInt32(106, !0) / 1e7, maxLon: t.getInt32(110, !0) / 1e7, maxLat: t.getInt32(114, !0) / 1e7, centerZoom: t.getUint8(118), centerLon: t.getInt32(119, !0) / 1e7, centerLat: t.getInt32(123, !0) / 1e7, etag: e };
498
+ }
499
+ d(Ae, "bytesToHeader");
500
+ function ee(r) {
501
+ let e = { buf: new Uint8Array(r), pos: 0 }, t = H(e), i = [], n = 0;
502
+ for (let a = 0; a < t; a++) {
503
+ let s = H(e);
504
+ i.push({ tileId: n + s, offset: 0, length: 0, runLength: 1 }), n += s;
505
+ }
506
+ for (let a = 0; a < t; a++) i[a].runLength = H(e);
507
+ for (let a = 0; a < t; a++) i[a].length = H(e);
508
+ for (let a = 0; a < t; a++) {
509
+ let s = H(e);
510
+ s === 0 && a > 0 ? i[a].offset = i[a - 1].offset + i[a - 1].length : i[a].offset = s - 1;
511
+ }
512
+ return i;
513
+ }
514
+ d(ee, "deserializeIndex");
515
+ var ze = class extends Error {
516
+ };
517
+ d(ze, "EtagMismatch");
518
+ var Q = ze;
519
+ function te(r, e) {
520
+ return m(this, null, function* () {
521
+ let t = yield r.getBytes(0, 16384);
522
+ if (new DataView(t.data).getUint16(0, !0) !== 19792) throw new Error("Wrong magic number for PMTiles archive");
523
+ let i = t.data.slice(0, ht), n = Ae(i, t.etag), a = t.data.slice(n.rootDirectoryOffset, n.rootDirectoryOffset + n.rootDirectoryLength), s = `${r.getKey()}|${n.etag || ""}|${n.rootDirectoryOffset}|${n.rootDirectoryLength}`, o = ee(yield e(a, n.internalCompression));
524
+ return [n, [s, o.length, o]];
525
+ });
526
+ }
527
+ d(te, "getHeaderAndRoot");
528
+ function re(r, e, t, i, n, a) {
529
+ return m(this, null, function* () {
530
+ let s = yield r.getBytes(t, i, a, n.etag), o = yield e(s.data, n.internalCompression), c = ee(o);
531
+ if (c.length === 0) throw new Error("Empty directory is invalid");
532
+ return c;
533
+ });
534
+ }
535
+ d(re, "getDirectory");
536
+ var dt = class {
537
+ constructor(e = 100, t = !0, i = P) {
538
+ this.cache = /* @__PURE__ */ new Map(), this.maxCacheEntries = e, this.counter = 1, this.decompress = i;
539
+ }
540
+ getHeader(e) {
541
+ return m(this, null, function* () {
542
+ let t = e.getKey(), i = this.cache.get(t);
543
+ if (i) return i.lastUsed = this.counter++, i.data;
544
+ let n = yield te(e, this.decompress);
545
+ return n[1] && this.cache.set(n[1][0], { lastUsed: this.counter++, data: n[1][2] }), this.cache.set(t, { lastUsed: this.counter++, data: n[0] }), this.prune(), n[0];
546
+ });
547
+ }
548
+ getDirectory(e, t, i, n, a) {
549
+ return m(this, null, function* () {
550
+ let s = `${e.getKey()}|${n.etag || ""}|${t}|${i}`, o = this.cache.get(s);
551
+ if (o) return o.lastUsed = this.counter++, o.data;
552
+ let c = yield re(e, this.decompress, t, i, n, a);
553
+ return this.cache.set(s, { lastUsed: this.counter++, data: c }), this.prune(), c;
554
+ });
555
+ }
556
+ prune() {
557
+ if (this.cache.size > this.maxCacheEntries) {
558
+ let e = 1 / 0, t;
559
+ this.cache.forEach((i, n) => {
560
+ i.lastUsed < e && (e = i.lastUsed, t = n);
561
+ }), t && this.cache.delete(t);
562
+ }
563
+ }
564
+ invalidate(e) {
565
+ return m(this, null, function* () {
566
+ this.cache.delete(e.getKey());
567
+ });
568
+ }
569
+ };
570
+ d(dt, "ResolvedValueCache");
571
+ var De = class {
572
+ constructor(e = 100, t = !0, i = P) {
573
+ this.cache = /* @__PURE__ */ new Map(), this.invalidations = /* @__PURE__ */ new Map(), this.pendingFetches = /* @__PURE__ */ new Map(), this.maxCacheEntries = e, this.counter = 1, this.decompress = i;
574
+ }
575
+ getHeader(e) {
576
+ return m(this, null, function* () {
577
+ let t = e.getKey(), i = this.cache.get(t);
578
+ if (i) return i.lastUsed = this.counter++, yield i.data;
579
+ let n = new Promise((a, s) => {
580
+ te(e, this.decompress).then((o) => {
581
+ o[1] && this.cache.set(o[1][0], { lastUsed: this.counter++, data: Promise.resolve(o[1][2]) }), a(o[0]), this.prune();
582
+ }).catch((o) => {
583
+ s(o);
584
+ });
585
+ });
586
+ return this.cache.set(t, { lastUsed: this.counter++, data: n }), n;
587
+ });
588
+ }
589
+ trackSignal(e, t, i) {
590
+ t.refs++, i.addEventListener("abort", () => {
591
+ --t.refs <= 0 && this.pendingFetches.get(e) === t && (t.controller.abort(), this.cache.delete(e), this.pendingFetches.delete(e));
592
+ }, { once: !0 });
593
+ }
594
+ getDirectory(e, t, i, n, a) {
595
+ return m(this, null, function* () {
596
+ let s = `${e.getKey()}|${n.etag || ""}|${t}|${i}`, o = this.cache.get(s);
597
+ if (o) {
598
+ o.lastUsed = this.counter++;
599
+ let l = this.pendingFetches.get(s);
600
+ return l && this.trackSignal(s, l, a ?? new AbortController().signal), yield o.data;
601
+ }
602
+ let c = new AbortController(), h = { controller: c, refs: 0 };
603
+ this.trackSignal(s, h, a ?? new AbortController().signal), this.pendingFetches.set(s, h);
604
+ let f = new Promise((l, u) => {
605
+ re(e, this.decompress, t, i, n, c.signal).then((y) => {
606
+ this.pendingFetches.delete(s), l(y), this.prune();
607
+ }).catch((y) => {
608
+ u(y);
609
+ });
610
+ });
611
+ return this.cache.set(s, { lastUsed: this.counter++, data: f }), f;
612
+ });
613
+ }
614
+ prune() {
615
+ if (this.cache.size >= this.maxCacheEntries) {
616
+ let e = 1 / 0, t;
617
+ this.cache.forEach((i, n) => {
618
+ i.lastUsed < e && (e = i.lastUsed, t = n);
619
+ }), t && this.cache.delete(t);
620
+ }
621
+ }
622
+ invalidate(e) {
623
+ return m(this, null, function* () {
624
+ let t = e.getKey();
625
+ if (this.invalidations.get(t)) return yield this.invalidations.get(t);
626
+ this.cache.delete(e.getKey());
627
+ let i = new Promise((n, a) => {
628
+ this.getHeader(e).then((s) => {
629
+ n(), this.invalidations.delete(t);
630
+ }).catch((s) => {
631
+ a(s);
632
+ });
633
+ });
634
+ this.invalidations.set(t, i);
635
+ });
636
+ }
637
+ };
638
+ d(De, "SharedPromiseCache");
639
+ var gt = De, He = class {
640
+ constructor(e, t, i) {
641
+ typeof e == "string" ? this.source = new ft(e) : this.source = e, i ? this.decompress = i : this.decompress = P, t ? this.cache = t : this.cache = new gt();
642
+ }
643
+ getHeader() {
644
+ return m(this, null, function* () {
645
+ return yield this.cache.getHeader(this.source);
646
+ });
647
+ }
648
+ getZxyAttempt(e, t, i, n) {
649
+ return m(this, null, function* () {
650
+ let a = Ce(e, t, i), s = yield this.cache.getHeader(this.source);
651
+ if (n?.throwIfAborted(), e < s.minZoom || e > s.maxZoom) return;
652
+ let o = s.rootDirectoryOffset, c = s.rootDirectoryLength;
653
+ for (let h = 0; h <= 3; h++) {
654
+ let f = yield this.cache.getDirectory(this.source, o, c, s, n);
655
+ n?.throwIfAborted();
656
+ let l = Ee(f, a);
657
+ if (l) {
658
+ if (l.runLength > 0) {
659
+ let u = yield this.source.getBytes(s.tileDataOffset + l.offset, l.length, n, s.etag);
660
+ return { data: yield this.decompress(u.data, s.tileCompression), cacheControl: u.cacheControl, expires: u.expires };
661
+ }
662
+ o = s.leafDirectoryOffset + l.offset, c = l.length;
663
+ } else return;
664
+ }
665
+ throw new Error("Maximum directory depth exceeded");
666
+ });
667
+ }
668
+ getZxy(e, t, i, n) {
669
+ return m(this, null, function* () {
670
+ try {
671
+ return yield this.getZxyAttempt(e, t, i, n);
672
+ } catch (a) {
673
+ if (a instanceof Q) return this.cache.invalidate(this.source), yield this.getZxyAttempt(e, t, i, n);
674
+ throw a;
675
+ }
676
+ });
677
+ }
678
+ getMetadataAttempt() {
679
+ return m(this, null, function* () {
680
+ let e = yield this.cache.getHeader(this.source), t = yield this.source.getBytes(e.jsonMetadataOffset, e.jsonMetadataLength, void 0, e.etag), i = yield this.decompress(t.data, e.internalCompression), n = new TextDecoder("utf-8");
681
+ return JSON.parse(n.decode(i));
682
+ });
683
+ }
684
+ getMetadata() {
685
+ return m(this, null, function* () {
686
+ try {
687
+ return yield this.getMetadataAttempt();
688
+ } catch (e) {
689
+ if (e instanceof Q) return this.cache.invalidate(this.source), yield this.getMetadataAttempt();
690
+ throw e;
691
+ }
692
+ });
693
+ }
694
+ getTileJson(e) {
695
+ return m(this, null, function* () {
696
+ let t = yield this.getHeader(), i = yield this.getMetadata(), n = Ue(t.tileType);
697
+ return { tilejson: "3.0.0", scheme: "xyz", tiles: [`${e}/{z}/{x}/{y}${n}`], vector_layers: i.vector_layers, attribution: i.attribution, description: i.description, name: i.name, version: i.version, bounds: [t.minLon, t.minLat, t.maxLon, t.maxLat], center: [t.centerLon, t.centerLat, t.centerZoom], minzoom: t.minZoom, maxzoom: t.maxZoom };
698
+ });
699
+ }
700
+ };
701
+ d(He, "PMTiles");
702
+ var ge = He;
703
+ export {
704
+ lt as Compression,
705
+ Q as EtagMismatch,
706
+ ft as FetchSource,
707
+ ge as PMTiles,
708
+ gt as SharedPromiseCache,
709
+ ct as TileType,
710
+ Ae as bytesToHeader,
711
+ Ee as findTile,
712
+ x as getUint64,
713
+ H as readVarint,
714
+ ot as tileIdToZxy,
715
+ Ue as tileTypeExt,
716
+ Ce as zxyToTileId
717
+ };