styled-map-package-api 5.0.0-pre.0

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.
Files changed (71) hide show
  1. package/dist/download.cjs +100 -0
  2. package/dist/download.d.cts +64 -0
  3. package/dist/download.d.ts +64 -0
  4. package/dist/download.js +76 -0
  5. package/dist/from-mbtiles.cjs +81 -0
  6. package/dist/from-mbtiles.d.cts +10 -0
  7. package/dist/from-mbtiles.d.ts +10 -0
  8. package/dist/from-mbtiles.js +57 -0
  9. package/dist/index.cjs +46 -0
  10. package/dist/index.d.cts +25 -0
  11. package/dist/index.d.ts +25 -0
  12. package/dist/index.js +16 -0
  13. package/dist/reader.cjs +287 -0
  14. package/dist/reader.d.cts +68 -0
  15. package/dist/reader.d.ts +68 -0
  16. package/dist/reader.js +259 -0
  17. package/dist/server.cjs +73 -0
  18. package/dist/server.d.cts +46 -0
  19. package/dist/server.d.ts +46 -0
  20. package/dist/server.js +49 -0
  21. package/dist/style-downloader.cjs +314 -0
  22. package/dist/style-downloader.d.cts +119 -0
  23. package/dist/style-downloader.d.ts +119 -0
  24. package/dist/style-downloader.js +290 -0
  25. package/dist/tile-downloader.cjs +156 -0
  26. package/dist/tile-downloader.d.cts +83 -0
  27. package/dist/tile-downloader.d.ts +83 -0
  28. package/dist/tile-downloader.js +124 -0
  29. package/dist/types-CJq90eOB.d.cts +184 -0
  30. package/dist/types-CJq90eOB.d.ts +184 -0
  31. package/dist/utils/errors.cjs +41 -0
  32. package/dist/utils/errors.d.cts +18 -0
  33. package/dist/utils/errors.d.ts +18 -0
  34. package/dist/utils/errors.js +16 -0
  35. package/dist/utils/fetch.cjs +97 -0
  36. package/dist/utils/fetch.d.cts +50 -0
  37. package/dist/utils/fetch.d.ts +50 -0
  38. package/dist/utils/fetch.js +63 -0
  39. package/dist/utils/file-formats.cjs +96 -0
  40. package/dist/utils/file-formats.d.cts +33 -0
  41. package/dist/utils/file-formats.d.ts +33 -0
  42. package/dist/utils/file-formats.js +70 -0
  43. package/dist/utils/geo.cjs +84 -0
  44. package/dist/utils/geo.d.cts +46 -0
  45. package/dist/utils/geo.d.ts +46 -0
  46. package/dist/utils/geo.js +56 -0
  47. package/dist/utils/mapbox.cjs +121 -0
  48. package/dist/utils/mapbox.d.cts +43 -0
  49. package/dist/utils/mapbox.d.ts +43 -0
  50. package/dist/utils/mapbox.js +91 -0
  51. package/dist/utils/misc.cjs +39 -0
  52. package/dist/utils/misc.d.cts +22 -0
  53. package/dist/utils/misc.d.ts +22 -0
  54. package/dist/utils/misc.js +13 -0
  55. package/dist/utils/streams.cjs +99 -0
  56. package/dist/utils/streams.d.cts +49 -0
  57. package/dist/utils/streams.d.ts +49 -0
  58. package/dist/utils/streams.js +73 -0
  59. package/dist/utils/style.cjs +126 -0
  60. package/dist/utils/style.d.cts +67 -0
  61. package/dist/utils/style.d.ts +67 -0
  62. package/dist/utils/style.js +98 -0
  63. package/dist/utils/templates.cjs +124 -0
  64. package/dist/utils/templates.d.cts +80 -0
  65. package/dist/utils/templates.d.ts +80 -0
  66. package/dist/utils/templates.js +85 -0
  67. package/dist/writer.cjs +465 -0
  68. package/dist/writer.d.cts +5 -0
  69. package/dist/writer.d.ts +5 -0
  70. package/dist/writer.js +452 -0
  71. package/package.json +161 -0
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var fetch_exports = {};
30
+ __export(fetch_exports, {
31
+ FetchQueue: () => FetchQueue
32
+ });
33
+ module.exports = __toCommonJS(fetch_exports);
34
+ var import_ky = __toESM(require("ky"), 1);
35
+ var import_p_limit = __toESM(require("p-limit"), 1);
36
+ var import_streams = require('./streams.cjs');
37
+ class FetchQueue {
38
+ /** @type {import('p-limit').LimitFunction} */
39
+ #limit;
40
+ /** @param {number} concurrency */
41
+ constructor(concurrency) {
42
+ this.#limit = (0, import_p_limit.default)(concurrency);
43
+ }
44
+ get activeCount() {
45
+ return this.#limit.activeCount;
46
+ }
47
+ /**
48
+ * Fetch a URL, limiting the number of concurrent downloads. Resolves with a
49
+ * `DownloadResponse`, which is a parsed from the Fetch `Response` objects,
50
+ * with `body` as a web ReadableStream, and the MIME type and content length
51
+ * of the response.
52
+ *
53
+ * NB: The response body stream must be consumed to the end, otherwise the
54
+ * queue will never be emptied.
55
+ *
56
+ * @param {string} url
57
+ * @param {{ onprogress?: import('./streams.js').ProgressCallback }} opts
58
+ * @returns {Promise<DownloadResponse>}
59
+ */
60
+ fetch(url, { onprogress } = {}) {
61
+ return new Promise((resolveResponse, rejectResponse) => {
62
+ this.#limit(fetchStream, {
63
+ url,
64
+ onresponse: resolveResponse,
65
+ onerror: rejectResponse,
66
+ onprogress
67
+ });
68
+ });
69
+ }
70
+ }
71
+ async function fetchStream({ url, onresponse, onerror, onprogress }) {
72
+ try {
73
+ const response = await (0, import_ky.default)(url, { retry: 3 });
74
+ if (!response.body) {
75
+ throw new Error("No body in response");
76
+ }
77
+ const contentType = response.headers.get("content-type");
78
+ const mimeType = typeof contentType === "string" ? contentType.split(";")[0] : null;
79
+ const contentLengthHeader = response.headers.get("content-length");
80
+ const contentLength = contentLengthHeader === null ? null : parseInt(contentLengthHeader, 10);
81
+ const passthrough = new TransformStream();
82
+ const pipePromise = response.body.pipeTo(passthrough.writable);
83
+ let body = passthrough.readable;
84
+ if (onprogress) {
85
+ const progress = new import_streams.ProgressStream({ onprogress });
86
+ body = body.pipeThrough(progress);
87
+ }
88
+ onresponse({ body, mimeType, contentLength });
89
+ await pipePromise;
90
+ } catch (err) {
91
+ onerror(err instanceof Error ? err : new Error("Unknown error"));
92
+ }
93
+ }
94
+ // Annotate the CommonJS export names for ESM import in node:
95
+ 0 && (module.exports = {
96
+ FetchQueue
97
+ });
@@ -0,0 +1,50 @@
1
+ import { ProgressCallback } from './streams.cjs';
2
+ import 'stream/web';
3
+
4
+ /**
5
+ * @typedef {object} DownloadResponse
6
+ * @property {ReadableStream<Uint8Array>} body Web ReadableStream of the response body
7
+ * @property {string | null} mimeType Content mime-type (from http content-type header)
8
+ * @property {number | null} contentLength Content length in bytes (from http content-length header)
9
+ */
10
+ /**
11
+ * A wrapper for fetch that limits the number of concurrent downloads.
12
+ */
13
+ declare class FetchQueue {
14
+ /** @param {number} concurrency */
15
+ constructor(concurrency: number);
16
+ get activeCount(): number;
17
+ /**
18
+ * Fetch a URL, limiting the number of concurrent downloads. Resolves with a
19
+ * `DownloadResponse`, which is a parsed from the Fetch `Response` objects,
20
+ * with `body` as a web ReadableStream, and the MIME type and content length
21
+ * of the response.
22
+ *
23
+ * NB: The response body stream must be consumed to the end, otherwise the
24
+ * queue will never be emptied.
25
+ *
26
+ * @param {string} url
27
+ * @param {{ onprogress?: import('./streams.js').ProgressCallback }} opts
28
+ * @returns {Promise<DownloadResponse>}
29
+ */
30
+ fetch(url: string, { onprogress }?: {
31
+ onprogress?: ProgressCallback;
32
+ }): Promise<DownloadResponse>;
33
+ #private;
34
+ }
35
+ type DownloadResponse = {
36
+ /**
37
+ * Web ReadableStream of the response body
38
+ */
39
+ body: ReadableStream<Uint8Array>;
40
+ /**
41
+ * Content mime-type (from http content-type header)
42
+ */
43
+ mimeType: string | null;
44
+ /**
45
+ * Content length in bytes (from http content-length header)
46
+ */
47
+ contentLength: number | null;
48
+ };
49
+
50
+ export { type DownloadResponse, FetchQueue };
@@ -0,0 +1,50 @@
1
+ import { ProgressCallback } from './streams.js';
2
+ import 'stream/web';
3
+
4
+ /**
5
+ * @typedef {object} DownloadResponse
6
+ * @property {ReadableStream<Uint8Array>} body Web ReadableStream of the response body
7
+ * @property {string | null} mimeType Content mime-type (from http content-type header)
8
+ * @property {number | null} contentLength Content length in bytes (from http content-length header)
9
+ */
10
+ /**
11
+ * A wrapper for fetch that limits the number of concurrent downloads.
12
+ */
13
+ declare class FetchQueue {
14
+ /** @param {number} concurrency */
15
+ constructor(concurrency: number);
16
+ get activeCount(): number;
17
+ /**
18
+ * Fetch a URL, limiting the number of concurrent downloads. Resolves with a
19
+ * `DownloadResponse`, which is a parsed from the Fetch `Response` objects,
20
+ * with `body` as a web ReadableStream, and the MIME type and content length
21
+ * of the response.
22
+ *
23
+ * NB: The response body stream must be consumed to the end, otherwise the
24
+ * queue will never be emptied.
25
+ *
26
+ * @param {string} url
27
+ * @param {{ onprogress?: import('./streams.js').ProgressCallback }} opts
28
+ * @returns {Promise<DownloadResponse>}
29
+ */
30
+ fetch(url: string, { onprogress }?: {
31
+ onprogress?: ProgressCallback;
32
+ }): Promise<DownloadResponse>;
33
+ #private;
34
+ }
35
+ type DownloadResponse = {
36
+ /**
37
+ * Web ReadableStream of the response body
38
+ */
39
+ body: ReadableStream<Uint8Array>;
40
+ /**
41
+ * Content mime-type (from http content-type header)
42
+ */
43
+ mimeType: string | null;
44
+ /**
45
+ * Content length in bytes (from http content-length header)
46
+ */
47
+ contentLength: number | null;
48
+ };
49
+
50
+ export { type DownloadResponse, FetchQueue };
@@ -0,0 +1,63 @@
1
+ import ky from "ky";
2
+ import pLimit from "p-limit";
3
+ import { ProgressStream } from "./streams.js";
4
+ class FetchQueue {
5
+ /** @type {import('p-limit').LimitFunction} */
6
+ #limit;
7
+ /** @param {number} concurrency */
8
+ constructor(concurrency) {
9
+ this.#limit = pLimit(concurrency);
10
+ }
11
+ get activeCount() {
12
+ return this.#limit.activeCount;
13
+ }
14
+ /**
15
+ * Fetch a URL, limiting the number of concurrent downloads. Resolves with a
16
+ * `DownloadResponse`, which is a parsed from the Fetch `Response` objects,
17
+ * with `body` as a web ReadableStream, and the MIME type and content length
18
+ * of the response.
19
+ *
20
+ * NB: The response body stream must be consumed to the end, otherwise the
21
+ * queue will never be emptied.
22
+ *
23
+ * @param {string} url
24
+ * @param {{ onprogress?: import('./streams.js').ProgressCallback }} opts
25
+ * @returns {Promise<DownloadResponse>}
26
+ */
27
+ fetch(url, { onprogress } = {}) {
28
+ return new Promise((resolveResponse, rejectResponse) => {
29
+ this.#limit(fetchStream, {
30
+ url,
31
+ onresponse: resolveResponse,
32
+ onerror: rejectResponse,
33
+ onprogress
34
+ });
35
+ });
36
+ }
37
+ }
38
+ async function fetchStream({ url, onresponse, onerror, onprogress }) {
39
+ try {
40
+ const response = await ky(url, { retry: 3 });
41
+ if (!response.body) {
42
+ throw new Error("No body in response");
43
+ }
44
+ const contentType = response.headers.get("content-type");
45
+ const mimeType = typeof contentType === "string" ? contentType.split(";")[0] : null;
46
+ const contentLengthHeader = response.headers.get("content-length");
47
+ const contentLength = contentLengthHeader === null ? null : parseInt(contentLengthHeader, 10);
48
+ const passthrough = new TransformStream();
49
+ const pipePromise = response.body.pipeTo(passthrough.writable);
50
+ let body = passthrough.readable;
51
+ if (onprogress) {
52
+ const progress = new ProgressStream({ onprogress });
53
+ body = body.pipeThrough(progress);
54
+ }
55
+ onresponse({ body, mimeType, contentLength });
56
+ await pipePromise;
57
+ } catch (err) {
58
+ onerror(err instanceof Error ? err : new Error("Unknown error"));
59
+ }
60
+ }
61
+ export {
62
+ FetchQueue
63
+ };
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var file_formats_exports = {};
20
+ __export(file_formats_exports, {
21
+ getFormatFromMimeType: () => getFormatFromMimeType,
22
+ getTileFormatFromBuffer: () => getTileFormatFromBuffer,
23
+ getTileFormatFromStream: () => getTileFormatFromStream
24
+ });
25
+ module.exports = __toCommonJS(file_formats_exports);
26
+ var import_misc = require('./misc.cjs');
27
+ const MAGIC_BYTES = (
28
+ /** @type {const} */
29
+ {
30
+ png: [137, 80, 78, 71, 13, 10, 26, 10],
31
+ jpg: [255, 216, 255],
32
+ // eslint-disable-next-line no-sparse-arrays
33
+ webp: [82, 73, 70, 70, , , , , 87, 69, 66, 80],
34
+ // Include the compression-type byte, which is always 0x08 (DEFLATE) for gzip
35
+ gz: [31, 139, 8]
36
+ }
37
+ );
38
+ const MIME_TYPES = (
39
+ /** @type {const} */
40
+ {
41
+ "image/png": "png",
42
+ "image/jpeg": "jpg",
43
+ "image/webp": "webp"
44
+ }
45
+ );
46
+ const magicByteMap = /* @__PURE__ */ new Map();
47
+ for (const [ext, bytes] of Object.entries(MAGIC_BYTES)) {
48
+ magicByteMap.set(
49
+ bytes[0],
50
+ // @ts-ignore
51
+ ext
52
+ );
53
+ }
54
+ function getTileFormatFromBuffer(buf) {
55
+ const ext = magicByteMap.get(buf[0]);
56
+ if (!ext) {
57
+ throw new Error("Unknown file type");
58
+ }
59
+ const sig = MAGIC_BYTES[ext];
60
+ for (let i = 1; i < sig.length; i++) {
61
+ if (typeof sig[i] !== "undefined" && sig[i] !== buf[i]) {
62
+ throw new Error("Unknown file type");
63
+ }
64
+ }
65
+ if (ext === "gz") {
66
+ return "mvt";
67
+ }
68
+ return ext;
69
+ }
70
+ async function getTileFormatFromStream(tileData) {
71
+ const [stream1, stream2] = tileData.tee();
72
+ const reader = stream1.getReader();
73
+ let buffer = new Uint8Array(0);
74
+ while (buffer.length < 12) {
75
+ const { done, value } = await reader.read();
76
+ if (done) break;
77
+ const newBuffer = new Uint8Array(buffer.length + value.length);
78
+ newBuffer.set(buffer);
79
+ newBuffer.set(value, buffer.length);
80
+ buffer = newBuffer;
81
+ }
82
+ reader.cancel();
83
+ const format = getTileFormatFromBuffer(buffer);
84
+ return [format, stream2];
85
+ }
86
+ function getFormatFromMimeType(mimeType) {
87
+ if (mimeType.startsWith("application/")) return "mvt";
88
+ if ((0, import_misc.hasOwn)(MIME_TYPES, mimeType)) return MIME_TYPES[mimeType];
89
+ throw new Error("Unsupported MIME type " + mimeType);
90
+ }
91
+ // Annotate the CommonJS export names for ESM import in node:
92
+ 0 && (module.exports = {
93
+ getFormatFromMimeType,
94
+ getTileFormatFromBuffer,
95
+ getTileFormatFromStream
96
+ });
@@ -0,0 +1,33 @@
1
+ import { c as TileFormat } from '../types-CJq90eOB.cjs';
2
+ import '@maplibre/maplibre-gl-style-spec';
3
+ import 'geojson';
4
+ import 'type-fest';
5
+ import 'events';
6
+
7
+ /**
8
+ * For a given buffer, determine the tile format based on the magic bytes.
9
+ * Will throw for unknown file types.
10
+ * Smaller and faster version of magic-bytes.js due to the limited use case.
11
+ *
12
+ * @param {Buffer | Uint8Array} buf
13
+ * @returns {import("../writer.js").TileFormat}
14
+ */
15
+ declare function getTileFormatFromBuffer(buf: Buffer | Uint8Array): TileFormat;
16
+ /**
17
+ * Determine the tile format from a readable stream from the magic bytes at the
18
+ * start of the file. Used if data is served without a content-type header.
19
+ * Returns the format and a new readable stream that includes all original data.
20
+ *
21
+ * @param {ReadableStream<Uint8Array>} tileData Web ReadableStream
22
+ * @returns {Promise<[import("../writer.js").TileFormat, ReadableStream<Uint8Array>]>}
23
+ */
24
+ declare function getTileFormatFromStream(tileData: ReadableStream<Uint8Array>): Promise<[TileFormat, ReadableStream<Uint8Array>]>;
25
+ /**
26
+ * Get the tile format from a MIME type. Throws for unsupported types.
27
+ *
28
+ * @param {string} mimeType
29
+ * @returns {import("../writer.js").TileFormat}
30
+ */
31
+ declare function getFormatFromMimeType(mimeType: string): TileFormat;
32
+
33
+ export { getFormatFromMimeType, getTileFormatFromBuffer, getTileFormatFromStream };
@@ -0,0 +1,33 @@
1
+ import { c as TileFormat } from '../types-CJq90eOB.js';
2
+ import '@maplibre/maplibre-gl-style-spec';
3
+ import 'geojson';
4
+ import 'type-fest';
5
+ import 'events';
6
+
7
+ /**
8
+ * For a given buffer, determine the tile format based on the magic bytes.
9
+ * Will throw for unknown file types.
10
+ * Smaller and faster version of magic-bytes.js due to the limited use case.
11
+ *
12
+ * @param {Buffer | Uint8Array} buf
13
+ * @returns {import("../writer.js").TileFormat}
14
+ */
15
+ declare function getTileFormatFromBuffer(buf: Buffer | Uint8Array): TileFormat;
16
+ /**
17
+ * Determine the tile format from a readable stream from the magic bytes at the
18
+ * start of the file. Used if data is served without a content-type header.
19
+ * Returns the format and a new readable stream that includes all original data.
20
+ *
21
+ * @param {ReadableStream<Uint8Array>} tileData Web ReadableStream
22
+ * @returns {Promise<[import("../writer.js").TileFormat, ReadableStream<Uint8Array>]>}
23
+ */
24
+ declare function getTileFormatFromStream(tileData: ReadableStream<Uint8Array>): Promise<[TileFormat, ReadableStream<Uint8Array>]>;
25
+ /**
26
+ * Get the tile format from a MIME type. Throws for unsupported types.
27
+ *
28
+ * @param {string} mimeType
29
+ * @returns {import("../writer.js").TileFormat}
30
+ */
31
+ declare function getFormatFromMimeType(mimeType: string): TileFormat;
32
+
33
+ export { getFormatFromMimeType, getTileFormatFromBuffer, getTileFormatFromStream };
@@ -0,0 +1,70 @@
1
+ import { hasOwn } from "./misc.js";
2
+ const MAGIC_BYTES = (
3
+ /** @type {const} */
4
+ {
5
+ png: [137, 80, 78, 71, 13, 10, 26, 10],
6
+ jpg: [255, 216, 255],
7
+ // eslint-disable-next-line no-sparse-arrays
8
+ webp: [82, 73, 70, 70, , , , , 87, 69, 66, 80],
9
+ // Include the compression-type byte, which is always 0x08 (DEFLATE) for gzip
10
+ gz: [31, 139, 8]
11
+ }
12
+ );
13
+ const MIME_TYPES = (
14
+ /** @type {const} */
15
+ {
16
+ "image/png": "png",
17
+ "image/jpeg": "jpg",
18
+ "image/webp": "webp"
19
+ }
20
+ );
21
+ const magicByteMap = /* @__PURE__ */ new Map();
22
+ for (const [ext, bytes] of Object.entries(MAGIC_BYTES)) {
23
+ magicByteMap.set(
24
+ bytes[0],
25
+ // @ts-ignore
26
+ ext
27
+ );
28
+ }
29
+ function getTileFormatFromBuffer(buf) {
30
+ const ext = magicByteMap.get(buf[0]);
31
+ if (!ext) {
32
+ throw new Error("Unknown file type");
33
+ }
34
+ const sig = MAGIC_BYTES[ext];
35
+ for (let i = 1; i < sig.length; i++) {
36
+ if (typeof sig[i] !== "undefined" && sig[i] !== buf[i]) {
37
+ throw new Error("Unknown file type");
38
+ }
39
+ }
40
+ if (ext === "gz") {
41
+ return "mvt";
42
+ }
43
+ return ext;
44
+ }
45
+ async function getTileFormatFromStream(tileData) {
46
+ const [stream1, stream2] = tileData.tee();
47
+ const reader = stream1.getReader();
48
+ let buffer = new Uint8Array(0);
49
+ while (buffer.length < 12) {
50
+ const { done, value } = await reader.read();
51
+ if (done) break;
52
+ const newBuffer = new Uint8Array(buffer.length + value.length);
53
+ newBuffer.set(buffer);
54
+ newBuffer.set(value, buffer.length);
55
+ buffer = newBuffer;
56
+ }
57
+ reader.cancel();
58
+ const format = getTileFormatFromBuffer(buffer);
59
+ return [format, stream2];
60
+ }
61
+ function getFormatFromMimeType(mimeType) {
62
+ if (mimeType.startsWith("application/")) return "mvt";
63
+ if (hasOwn(MIME_TYPES, mimeType)) return MIME_TYPES[mimeType];
64
+ throw new Error("Unsupported MIME type " + mimeType);
65
+ }
66
+ export {
67
+ getFormatFromMimeType,
68
+ getTileFormatFromBuffer,
69
+ getTileFormatFromStream
70
+ };
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var geo_exports = {};
20
+ __export(geo_exports, {
21
+ MAX_BOUNDS: () => MAX_BOUNDS,
22
+ getQuadkey: () => getQuadkey,
23
+ getTileUrl: () => getTileUrl,
24
+ tileToBBox: () => tileToBBox,
25
+ unionBBox: () => unionBBox
26
+ });
27
+ module.exports = __toCommonJS(geo_exports);
28
+ const r2d = 180 / Math.PI;
29
+ const MAX_BOUNDS = (
30
+ /** @type {BBox} */
31
+ [
32
+ -180,
33
+ -85.051129,
34
+ 180,
35
+ 85.051129
36
+ ]
37
+ );
38
+ function tileToBBox({ x, y, z }) {
39
+ const e = tile2lon({ x: x + 1, z });
40
+ const w = tile2lon({ x, z });
41
+ const s = tile2lat({ y: y + 1, z });
42
+ const n = tile2lat({ y, z });
43
+ return [w, s, e, n];
44
+ }
45
+ function getQuadkey({ x, y, z }) {
46
+ let quadkey = "";
47
+ let mask;
48
+ for (let i = z; i > 0; i--) {
49
+ mask = 1 << i - 1;
50
+ quadkey += (x & mask ? 1 : 0) + (y & mask ? 2 : 0);
51
+ }
52
+ return quadkey;
53
+ }
54
+ function getTileUrl(urls, { x, y, z, scheme = "xyz" }) {
55
+ const bboxEspg3857 = tileToBBox({ x, y: Math.pow(2, z) - y - 1, z });
56
+ const quadkey = getQuadkey({ x, y, z });
57
+ return urls[(x + y) % urls.length].replace("{prefix}", (x % 16).toString(16) + (y % 16).toString(16)).replace(/{z}/g, String(z)).replace(/{x}/g, String(x)).replace(/{y}/g, String(scheme === "tms" ? Math.pow(2, z) - y - 1 : y)).replace("{quadkey}", quadkey).replace("{bbox-epsg-3857}", bboxEspg3857.join(","));
58
+ }
59
+ function unionBBox(bboxes) {
60
+ let [w, s, e, n] = bboxes[0];
61
+ for (let i = 1; i < bboxes.length; i++) {
62
+ const [w1, s1, e1, n1] = bboxes[i];
63
+ w = Math.min(w, w1);
64
+ s = Math.min(s, s1);
65
+ e = Math.max(e, e1);
66
+ n = Math.max(n, n1);
67
+ }
68
+ return [w, s, e, n];
69
+ }
70
+ function tile2lon({ x, z }) {
71
+ return x / Math.pow(2, z) * 360 - 180;
72
+ }
73
+ function tile2lat({ y, z }) {
74
+ const n = Math.PI - 2 * Math.PI * y / Math.pow(2, z);
75
+ return r2d * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
76
+ }
77
+ // Annotate the CommonJS export names for ESM import in node:
78
+ 0 && (module.exports = {
79
+ MAX_BOUNDS,
80
+ getQuadkey,
81
+ getTileUrl,
82
+ tileToBBox,
83
+ unionBBox
84
+ });
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @typedef {[number, number, number, number]} BBox
3
+ */
4
+ /**
5
+ * Return the bounding box for the given tile.
6
+ *
7
+ * @param {{ x: number, y: number, z: number }} tile
8
+ * @returns {BBox} Bounding Box [w, s, e, n]
9
+ */
10
+ declare function tileToBBox({ x, y, z }: {
11
+ x: number;
12
+ y: number;
13
+ z: number;
14
+ }): BBox;
15
+ /**
16
+ * @param {{ x: number, y: number, z: number }} tile
17
+ */
18
+ declare function getQuadkey({ x, y, z }: {
19
+ x: number;
20
+ y: number;
21
+ z: number;
22
+ }): string;
23
+ /**
24
+ * From an array of tile URL templates, get the URL for the given tile.
25
+ *
26
+ * @param {string[]} urls
27
+ * @param {{ x: number, y: number, z: number, scheme?: 'xyz' | 'tms' }} opts
28
+ */
29
+ declare function getTileUrl(urls: string[], { x, y, z, scheme }: {
30
+ x: number;
31
+ y: number;
32
+ z: number;
33
+ scheme?: "xyz" | "tms";
34
+ }): string;
35
+ /**
36
+ * Returns a bbox that is the smallest bounding box that contains all the input bboxes.
37
+ *
38
+ * @param {[BBox, ...BBox[]]} bboxes
39
+ * @returns {BBox} Bounding Box [w, s, e, n]
40
+ */
41
+ declare function unionBBox(bboxes: [BBox, ...BBox[]]): BBox;
42
+ /** Spherical Mercator max bounds, rounded to 6 decimal places */
43
+ declare const MAX_BOUNDS: BBox;
44
+ type BBox = [number, number, number, number];
45
+
46
+ export { type BBox, MAX_BOUNDS, getQuadkey, getTileUrl, tileToBBox, unionBBox };
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @typedef {[number, number, number, number]} BBox
3
+ */
4
+ /**
5
+ * Return the bounding box for the given tile.
6
+ *
7
+ * @param {{ x: number, y: number, z: number }} tile
8
+ * @returns {BBox} Bounding Box [w, s, e, n]
9
+ */
10
+ declare function tileToBBox({ x, y, z }: {
11
+ x: number;
12
+ y: number;
13
+ z: number;
14
+ }): BBox;
15
+ /**
16
+ * @param {{ x: number, y: number, z: number }} tile
17
+ */
18
+ declare function getQuadkey({ x, y, z }: {
19
+ x: number;
20
+ y: number;
21
+ z: number;
22
+ }): string;
23
+ /**
24
+ * From an array of tile URL templates, get the URL for the given tile.
25
+ *
26
+ * @param {string[]} urls
27
+ * @param {{ x: number, y: number, z: number, scheme?: 'xyz' | 'tms' }} opts
28
+ */
29
+ declare function getTileUrl(urls: string[], { x, y, z, scheme }: {
30
+ x: number;
31
+ y: number;
32
+ z: number;
33
+ scheme?: "xyz" | "tms";
34
+ }): string;
35
+ /**
36
+ * Returns a bbox that is the smallest bounding box that contains all the input bboxes.
37
+ *
38
+ * @param {[BBox, ...BBox[]]} bboxes
39
+ * @returns {BBox} Bounding Box [w, s, e, n]
40
+ */
41
+ declare function unionBBox(bboxes: [BBox, ...BBox[]]): BBox;
42
+ /** Spherical Mercator max bounds, rounded to 6 decimal places */
43
+ declare const MAX_BOUNDS: BBox;
44
+ type BBox = [number, number, number, number];
45
+
46
+ export { type BBox, MAX_BOUNDS, getQuadkey, getTileUrl, tileToBBox, unionBBox };