styled-map-package 4.0.1 → 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 (85) hide show
  1. package/bin/smp-download.js +10 -6
  2. package/bin/smp-mbtiles.js +5 -7
  3. package/bin/smp-view.js +34 -26
  4. package/lib/reporters.js +92 -0
  5. package/package.json +8 -187
  6. package/LICENSE.md +0 -7
  7. package/README.md +0 -28
  8. package/dist/download.cjs +0 -101
  9. package/dist/download.d.cts +0 -65
  10. package/dist/download.d.ts +0 -65
  11. package/dist/download.js +0 -77
  12. package/dist/from-mbtiles.cjs +0 -91
  13. package/dist/from-mbtiles.d.cts +0 -17
  14. package/dist/from-mbtiles.d.ts +0 -17
  15. package/dist/from-mbtiles.js +0 -57
  16. package/dist/index.cjs +0 -49
  17. package/dist/index.d.cts +0 -27
  18. package/dist/index.d.ts +0 -27
  19. package/dist/index.js +0 -18
  20. package/dist/reader-watch.cjs +0 -135
  21. package/dist/reader-watch.d.cts +0 -24
  22. package/dist/reader-watch.d.ts +0 -24
  23. package/dist/reader-watch.js +0 -101
  24. package/dist/reader.cjs +0 -167
  25. package/dist/reader.d.cts +0 -62
  26. package/dist/reader.d.ts +0 -62
  27. package/dist/reader.js +0 -138
  28. package/dist/reporters.cjs +0 -122
  29. package/dist/reporters.d.cts +0 -10
  30. package/dist/reporters.d.ts +0 -10
  31. package/dist/reporters.js +0 -88
  32. package/dist/server.cjs +0 -78
  33. package/dist/server.d.cts +0 -48
  34. package/dist/server.d.ts +0 -48
  35. package/dist/server.js +0 -54
  36. package/dist/style-downloader.cjs +0 -312
  37. package/dist/style-downloader.d.cts +0 -120
  38. package/dist/style-downloader.d.ts +0 -120
  39. package/dist/style-downloader.js +0 -288
  40. package/dist/tile-downloader.cjs +0 -158
  41. package/dist/tile-downloader.d.cts +0 -84
  42. package/dist/tile-downloader.d.ts +0 -84
  43. package/dist/tile-downloader.js +0 -126
  44. package/dist/types-B4Xn1F9K.d.cts +0 -189
  45. package/dist/types-B4Xn1F9K.d.ts +0 -189
  46. package/dist/utils/errors.cjs +0 -41
  47. package/dist/utils/errors.d.cts +0 -18
  48. package/dist/utils/errors.d.ts +0 -18
  49. package/dist/utils/errors.js +0 -16
  50. package/dist/utils/fetch.cjs +0 -96
  51. package/dist/utils/fetch.d.cts +0 -51
  52. package/dist/utils/fetch.d.ts +0 -51
  53. package/dist/utils/fetch.js +0 -62
  54. package/dist/utils/file-formats.cjs +0 -98
  55. package/dist/utils/file-formats.d.cts +0 -35
  56. package/dist/utils/file-formats.d.ts +0 -35
  57. package/dist/utils/file-formats.js +0 -62
  58. package/dist/utils/geo.cjs +0 -84
  59. package/dist/utils/geo.d.cts +0 -46
  60. package/dist/utils/geo.d.ts +0 -46
  61. package/dist/utils/geo.js +0 -56
  62. package/dist/utils/mapbox.cjs +0 -121
  63. package/dist/utils/mapbox.d.cts +0 -43
  64. package/dist/utils/mapbox.d.ts +0 -43
  65. package/dist/utils/mapbox.js +0 -91
  66. package/dist/utils/misc.cjs +0 -39
  67. package/dist/utils/misc.d.cts +0 -22
  68. package/dist/utils/misc.d.ts +0 -22
  69. package/dist/utils/misc.js +0 -13
  70. package/dist/utils/streams.cjs +0 -130
  71. package/dist/utils/streams.d.cts +0 -73
  72. package/dist/utils/streams.d.ts +0 -73
  73. package/dist/utils/streams.js +0 -103
  74. package/dist/utils/style.cjs +0 -126
  75. package/dist/utils/style.d.cts +0 -69
  76. package/dist/utils/style.d.ts +0 -69
  77. package/dist/utils/style.js +0 -98
  78. package/dist/utils/templates.cjs +0 -114
  79. package/dist/utils/templates.d.cts +0 -78
  80. package/dist/utils/templates.d.ts +0 -78
  81. package/dist/utils/templates.js +0 -79
  82. package/dist/writer.cjs +0 -401
  83. package/dist/writer.d.cts +0 -7
  84. package/dist/writer.d.ts +0 -7
  85. package/dist/writer.js +0 -374
@@ -1,41 +0,0 @@
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 errors_exports = {};
20
- __export(errors_exports, {
21
- ENOENT: () => ENOENT,
22
- isFileNotThereError: () => isFileNotThereError
23
- });
24
- module.exports = __toCommonJS(errors_exports);
25
- class ENOENT extends Error {
26
- code = "ENOENT";
27
- /** @param {string} path */
28
- constructor(path) {
29
- const message = `ENOENT: no such file or directory, open '${path}'`;
30
- super(message);
31
- this.path = path;
32
- }
33
- }
34
- function isFileNotThereError(error) {
35
- return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "EPERM");
36
- }
37
- // Annotate the CommonJS export names for ESM import in node:
38
- 0 && (module.exports = {
39
- ENOENT,
40
- isFileNotThereError
41
- });
@@ -1,18 +0,0 @@
1
- /**
2
- * Returns true if the error if because a file is not found. On Windows, some
3
- * operations like fs.watch() throw an EPERM error rather than ENOENT.
4
- *
5
- * @param {unknown} error
6
- * @returns {error is Error & { code: 'ENOENT' | 'EPERM' }}
7
- */
8
- declare function isFileNotThereError(error: unknown): error is Error & {
9
- code: "ENOENT" | "EPERM";
10
- };
11
- declare class ENOENT extends Error {
12
- /** @param {string} path */
13
- constructor(path: string);
14
- code: string;
15
- path: string;
16
- }
17
-
18
- export { ENOENT, isFileNotThereError };
@@ -1,18 +0,0 @@
1
- /**
2
- * Returns true if the error if because a file is not found. On Windows, some
3
- * operations like fs.watch() throw an EPERM error rather than ENOENT.
4
- *
5
- * @param {unknown} error
6
- * @returns {error is Error & { code: 'ENOENT' | 'EPERM' }}
7
- */
8
- declare function isFileNotThereError(error: unknown): error is Error & {
9
- code: "ENOENT" | "EPERM";
10
- };
11
- declare class ENOENT extends Error {
12
- /** @param {string} path */
13
- constructor(path: string);
14
- code: string;
15
- path: string;
16
- }
17
-
18
- export { ENOENT, isFileNotThereError };
@@ -1,16 +0,0 @@
1
- class ENOENT extends Error {
2
- code = "ENOENT";
3
- /** @param {string} path */
4
- constructor(path) {
5
- const message = `ENOENT: no such file or directory, open '${path}'`;
6
- super(message);
7
- this.path = path;
8
- }
9
- }
10
- function isFileNotThereError(error) {
11
- return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "EPERM");
12
- }
13
- export {
14
- ENOENT,
15
- isFileNotThereError
16
- };
@@ -1,96 +0,0 @@
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_event = require("p-event");
36
- var import_p_limit = __toESM(require("p-limit"), 1);
37
- var import_streams = require('./streams.cjs');
38
- class FetchQueue {
39
- /** @type {import('p-limit').LimitFunction} */
40
- #limit;
41
- /** @param {number} concurrency */
42
- constructor(concurrency) {
43
- this.#limit = (0, import_p_limit.default)(concurrency);
44
- }
45
- get activeCount() {
46
- return this.#limit.activeCount;
47
- }
48
- /**
49
- * Fetch a URL, limiting the number of concurrent downloads. Resolves with a
50
- * `DownloadResponse`, which is a parsed from the Fetch `Response` objects,
51
- * with `body` as a Node readable stream, and the MIME type and content length
52
- * of the response.
53
- *
54
- * NB: The response body stream must be consumed to the end, otherwise the
55
- * queue will never be emptied.
56
- *
57
- * @param {string} url
58
- * @param {{ onprogress?: import('./streams.js').ProgressCallback }} opts
59
- * @returns {Promise<DownloadResponse>}
60
- */
61
- fetch(url, { onprogress } = {}) {
62
- return new Promise((resolveResponse, rejectResponse) => {
63
- this.#limit(fetchStream, {
64
- url,
65
- onresponse: resolveResponse,
66
- onerror: rejectResponse,
67
- onprogress
68
- });
69
- });
70
- }
71
- }
72
- async function fetchStream({ url, onresponse, onerror, onprogress }) {
73
- try {
74
- const response = await (0, import_ky.default)(url, { retry: 3 });
75
- if (!response.body) {
76
- throw new Error("No body in response");
77
- }
78
- const body = (0, import_streams.fromWebReadableStream)(response.body);
79
- const contentType = response.headers.get("content-type");
80
- const mimeType = typeof contentType === "string" ? contentType.split(";")[0] : null;
81
- const contentLengthHeader = response.headers.get("content-length");
82
- const contentLength = contentLengthHeader === null ? null : parseInt(contentLengthHeader, 10);
83
- onresponse({
84
- body: onprogress ? body.pipe(new import_streams.ProgressStream({ onprogress })) : body,
85
- mimeType,
86
- contentLength
87
- });
88
- await (0, import_p_event.pEvent)(body, "end");
89
- } catch (err) {
90
- onerror(err instanceof Error ? err : new Error("Unknown error"));
91
- }
92
- }
93
- // Annotate the CommonJS export names for ESM import in node:
94
- 0 && (module.exports = {
95
- FetchQueue
96
- });
@@ -1,51 +0,0 @@
1
- import * as stream from 'stream';
2
- import { ProgressCallback } from './streams.cjs';
3
- import 'readable-stream';
4
-
5
- /**
6
- * @typedef {object} DownloadResponse
7
- * @property {import('stream').Readable} body Node ReadableStream of the response body
8
- * @property {string | null} mimeType Content mime-type (from http content-type header)
9
- * @property {number | null} contentLength Content length in bytes (from http content-length header)
10
- */
11
- /**
12
- * A wrapper for fetch that limits the number of concurrent downloads.
13
- */
14
- declare class FetchQueue {
15
- /** @param {number} concurrency */
16
- constructor(concurrency: number);
17
- get activeCount(): number;
18
- /**
19
- * Fetch a URL, limiting the number of concurrent downloads. Resolves with a
20
- * `DownloadResponse`, which is a parsed from the Fetch `Response` objects,
21
- * with `body` as a Node readable stream, and the MIME type and content length
22
- * of the response.
23
- *
24
- * NB: The response body stream must be consumed to the end, otherwise the
25
- * queue will never be emptied.
26
- *
27
- * @param {string} url
28
- * @param {{ onprogress?: import('./streams.js').ProgressCallback }} opts
29
- * @returns {Promise<DownloadResponse>}
30
- */
31
- fetch(url: string, { onprogress }?: {
32
- onprogress?: ProgressCallback;
33
- }): Promise<DownloadResponse>;
34
- #private;
35
- }
36
- type DownloadResponse = {
37
- /**
38
- * Node ReadableStream of the response body
39
- */
40
- body: stream.Readable;
41
- /**
42
- * Content mime-type (from http content-type header)
43
- */
44
- mimeType: string | null;
45
- /**
46
- * Content length in bytes (from http content-length header)
47
- */
48
- contentLength: number | null;
49
- };
50
-
51
- export { type DownloadResponse, FetchQueue };
@@ -1,51 +0,0 @@
1
- import * as stream from 'stream';
2
- import { ProgressCallback } from './streams.js';
3
- import 'readable-stream';
4
-
5
- /**
6
- * @typedef {object} DownloadResponse
7
- * @property {import('stream').Readable} body Node ReadableStream of the response body
8
- * @property {string | null} mimeType Content mime-type (from http content-type header)
9
- * @property {number | null} contentLength Content length in bytes (from http content-length header)
10
- */
11
- /**
12
- * A wrapper for fetch that limits the number of concurrent downloads.
13
- */
14
- declare class FetchQueue {
15
- /** @param {number} concurrency */
16
- constructor(concurrency: number);
17
- get activeCount(): number;
18
- /**
19
- * Fetch a URL, limiting the number of concurrent downloads. Resolves with a
20
- * `DownloadResponse`, which is a parsed from the Fetch `Response` objects,
21
- * with `body` as a Node readable stream, and the MIME type and content length
22
- * of the response.
23
- *
24
- * NB: The response body stream must be consumed to the end, otherwise the
25
- * queue will never be emptied.
26
- *
27
- * @param {string} url
28
- * @param {{ onprogress?: import('./streams.js').ProgressCallback }} opts
29
- * @returns {Promise<DownloadResponse>}
30
- */
31
- fetch(url: string, { onprogress }?: {
32
- onprogress?: ProgressCallback;
33
- }): Promise<DownloadResponse>;
34
- #private;
35
- }
36
- type DownloadResponse = {
37
- /**
38
- * Node ReadableStream of the response body
39
- */
40
- body: stream.Readable;
41
- /**
42
- * Content mime-type (from http content-type header)
43
- */
44
- mimeType: string | null;
45
- /**
46
- * Content length in bytes (from http content-length header)
47
- */
48
- contentLength: number | null;
49
- };
50
-
51
- export { type DownloadResponse, FetchQueue };
@@ -1,62 +0,0 @@
1
- import ky from "ky";
2
- import { pEvent } from "p-event";
3
- import pLimit from "p-limit";
4
- import { fromWebReadableStream, ProgressStream } from "./streams.js";
5
- class FetchQueue {
6
- /** @type {import('p-limit').LimitFunction} */
7
- #limit;
8
- /** @param {number} concurrency */
9
- constructor(concurrency) {
10
- this.#limit = pLimit(concurrency);
11
- }
12
- get activeCount() {
13
- return this.#limit.activeCount;
14
- }
15
- /**
16
- * Fetch a URL, limiting the number of concurrent downloads. Resolves with a
17
- * `DownloadResponse`, which is a parsed from the Fetch `Response` objects,
18
- * with `body` as a Node readable stream, and the MIME type and content length
19
- * of the response.
20
- *
21
- * NB: The response body stream must be consumed to the end, otherwise the
22
- * queue will never be emptied.
23
- *
24
- * @param {string} url
25
- * @param {{ onprogress?: import('./streams.js').ProgressCallback }} opts
26
- * @returns {Promise<DownloadResponse>}
27
- */
28
- fetch(url, { onprogress } = {}) {
29
- return new Promise((resolveResponse, rejectResponse) => {
30
- this.#limit(fetchStream, {
31
- url,
32
- onresponse: resolveResponse,
33
- onerror: rejectResponse,
34
- onprogress
35
- });
36
- });
37
- }
38
- }
39
- async function fetchStream({ url, onresponse, onerror, onprogress }) {
40
- try {
41
- const response = await ky(url, { retry: 3 });
42
- if (!response.body) {
43
- throw new Error("No body in response");
44
- }
45
- const body = fromWebReadableStream(response.body);
46
- const contentType = response.headers.get("content-type");
47
- const mimeType = typeof contentType === "string" ? contentType.split(";")[0] : null;
48
- const contentLengthHeader = response.headers.get("content-length");
49
- const contentLength = contentLengthHeader === null ? null : parseInt(contentLengthHeader, 10);
50
- onresponse({
51
- body: onprogress ? body.pipe(new ProgressStream({ onprogress })) : body,
52
- mimeType,
53
- contentLength
54
- });
55
- await pEvent(body, "end");
56
- } catch (err) {
57
- onerror(err instanceof Error ? err : new Error("Unknown error"));
58
- }
59
- }
60
- export {
61
- FetchQueue
62
- };
@@ -1,98 +0,0 @@
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 file_formats_exports = {};
30
- __export(file_formats_exports, {
31
- getFormatFromMimeType: () => getFormatFromMimeType,
32
- getTileFormatFromBuffer: () => getTileFormatFromBuffer,
33
- getTileFormatFromStream: () => getTileFormatFromStream
34
- });
35
- module.exports = __toCommonJS(file_formats_exports);
36
- var import_buffer_peek_stream = __toESM(require("buffer-peek-stream"), 1);
37
- var import_misc = require('./misc.cjs');
38
- const peek = import_buffer_peek_stream.default.promise;
39
- const MAGIC_BYTES = (
40
- /** @type {const} */
41
- {
42
- png: [137, 80, 78, 71, 13, 10, 26, 10],
43
- jpg: [255, 216, 255],
44
- // eslint-disable-next-line no-sparse-arrays
45
- webp: [82, 73, 70, 70, , , , , 87, 69, 66, 80],
46
- // Include the compression-type byte, which is always 0x08 (DEFLATE) for gzip
47
- gz: [31, 139, 8]
48
- }
49
- );
50
- const MIME_TYPES = (
51
- /** @type {const} */
52
- {
53
- "image/png": "png",
54
- "image/jpeg": "jpg",
55
- "image/webp": "webp"
56
- }
57
- );
58
- const magicByteMap = /* @__PURE__ */ new Map();
59
- for (const [ext, bytes] of Object.entries(MAGIC_BYTES)) {
60
- magicByteMap.set(
61
- bytes[0],
62
- // @ts-ignore
63
- ext
64
- );
65
- }
66
- function getTileFormatFromBuffer(buf) {
67
- const ext = magicByteMap.get(buf[0]);
68
- if (!ext) {
69
- throw new Error("Unknown file type");
70
- }
71
- const sig = MAGIC_BYTES[ext];
72
- for (let i = 1; i < sig.length; i++) {
73
- if (typeof sig[i] !== "undefined" && sig[i] !== buf[i]) {
74
- throw new Error("Unknown file type");
75
- }
76
- }
77
- if (ext === "gz") {
78
- return "mvt";
79
- }
80
- return ext;
81
- }
82
- async function getTileFormatFromStream(tileData) {
83
- const [peekedData, outputStream] = await peek(tileData, 16 * 1024);
84
- tileData = outputStream;
85
- const format = getTileFormatFromBuffer(peekedData);
86
- return [format, outputStream];
87
- }
88
- function getFormatFromMimeType(mimeType) {
89
- if (mimeType.startsWith("application/")) return "mvt";
90
- if ((0, import_misc.hasOwn)(MIME_TYPES, mimeType)) return MIME_TYPES[mimeType];
91
- throw new Error("Unsupported MIME type " + mimeType);
92
- }
93
- // Annotate the CommonJS export names for ESM import in node:
94
- 0 && (module.exports = {
95
- getFormatFromMimeType,
96
- getTileFormatFromBuffer,
97
- getTileFormatFromStream
98
- });
@@ -1,35 +0,0 @@
1
- import * as stream from 'stream';
2
- import { c as TileFormat } from '../types-B4Xn1F9K.cjs';
3
- import '@maplibre/maplibre-gl-style-spec';
4
- import 'geojson';
5
- import 'type-fest';
6
- import 'readable-stream';
7
- import 'events';
8
-
9
- /**
10
- * For a given buffer, determine the tile format based on the magic bytes.
11
- * Will throw for unknown file types.
12
- * Smaller and faster version of magic-bytes.js due to the limited use case.
13
- *
14
- * @param {Buffer | Uint8Array} buf
15
- * @returns {import("../writer.js").TileFormat}
16
- */
17
- declare function getTileFormatFromBuffer(buf: Buffer | Uint8Array): TileFormat;
18
- /**
19
- * Determine the tile format from either a readable stream, buffer or Uint8Array
20
- * from the magic bytes at the start of the file. Used if data is served without
21
- * a content-type header.
22
- *
23
- * @param {import('stream').Readable} tileData
24
- * @returns {Promise<[import("../writer.js").TileFormat, import('stream').Readable]>}
25
- */
26
- declare function getTileFormatFromStream(tileData: stream.Readable): Promise<[TileFormat, stream.Readable]>;
27
- /**
28
- * Get the tile format from a MIME type. Throws for unsupported types.
29
- *
30
- * @param {string} mimeType
31
- * @returns {import("../writer.js").TileFormat}
32
- */
33
- declare function getFormatFromMimeType(mimeType: string): TileFormat;
34
-
35
- export { getFormatFromMimeType, getTileFormatFromBuffer, getTileFormatFromStream };
@@ -1,35 +0,0 @@
1
- import * as stream from 'stream';
2
- import { c as TileFormat } from '../types-B4Xn1F9K.js';
3
- import '@maplibre/maplibre-gl-style-spec';
4
- import 'geojson';
5
- import 'type-fest';
6
- import 'readable-stream';
7
- import 'events';
8
-
9
- /**
10
- * For a given buffer, determine the tile format based on the magic bytes.
11
- * Will throw for unknown file types.
12
- * Smaller and faster version of magic-bytes.js due to the limited use case.
13
- *
14
- * @param {Buffer | Uint8Array} buf
15
- * @returns {import("../writer.js").TileFormat}
16
- */
17
- declare function getTileFormatFromBuffer(buf: Buffer | Uint8Array): TileFormat;
18
- /**
19
- * Determine the tile format from either a readable stream, buffer or Uint8Array
20
- * from the magic bytes at the start of the file. Used if data is served without
21
- * a content-type header.
22
- *
23
- * @param {import('stream').Readable} tileData
24
- * @returns {Promise<[import("../writer.js").TileFormat, import('stream').Readable]>}
25
- */
26
- declare function getTileFormatFromStream(tileData: stream.Readable): Promise<[TileFormat, stream.Readable]>;
27
- /**
28
- * Get the tile format from a MIME type. Throws for unsupported types.
29
- *
30
- * @param {string} mimeType
31
- * @returns {import("../writer.js").TileFormat}
32
- */
33
- declare function getFormatFromMimeType(mimeType: string): TileFormat;
34
-
35
- export { getFormatFromMimeType, getTileFormatFromBuffer, getTileFormatFromStream };
@@ -1,62 +0,0 @@
1
- import BufferPeerStream from "buffer-peek-stream";
2
- import { hasOwn } from "./misc.js";
3
- const peek = BufferPeerStream.promise;
4
- const MAGIC_BYTES = (
5
- /** @type {const} */
6
- {
7
- png: [137, 80, 78, 71, 13, 10, 26, 10],
8
- jpg: [255, 216, 255],
9
- // eslint-disable-next-line no-sparse-arrays
10
- webp: [82, 73, 70, 70, , , , , 87, 69, 66, 80],
11
- // Include the compression-type byte, which is always 0x08 (DEFLATE) for gzip
12
- gz: [31, 139, 8]
13
- }
14
- );
15
- const MIME_TYPES = (
16
- /** @type {const} */
17
- {
18
- "image/png": "png",
19
- "image/jpeg": "jpg",
20
- "image/webp": "webp"
21
- }
22
- );
23
- const magicByteMap = /* @__PURE__ */ new Map();
24
- for (const [ext, bytes] of Object.entries(MAGIC_BYTES)) {
25
- magicByteMap.set(
26
- bytes[0],
27
- // @ts-ignore
28
- ext
29
- );
30
- }
31
- function getTileFormatFromBuffer(buf) {
32
- const ext = magicByteMap.get(buf[0]);
33
- if (!ext) {
34
- throw new Error("Unknown file type");
35
- }
36
- const sig = MAGIC_BYTES[ext];
37
- for (let i = 1; i < sig.length; i++) {
38
- if (typeof sig[i] !== "undefined" && sig[i] !== buf[i]) {
39
- throw new Error("Unknown file type");
40
- }
41
- }
42
- if (ext === "gz") {
43
- return "mvt";
44
- }
45
- return ext;
46
- }
47
- async function getTileFormatFromStream(tileData) {
48
- const [peekedData, outputStream] = await peek(tileData, 16 * 1024);
49
- tileData = outputStream;
50
- const format = getTileFormatFromBuffer(peekedData);
51
- return [format, outputStream];
52
- }
53
- function getFormatFromMimeType(mimeType) {
54
- if (mimeType.startsWith("application/")) return "mvt";
55
- if (hasOwn(MIME_TYPES, mimeType)) return MIME_TYPES[mimeType];
56
- throw new Error("Unsupported MIME type " + mimeType);
57
- }
58
- export {
59
- getFormatFromMimeType,
60
- getTileFormatFromBuffer,
61
- getTileFormatFromStream
62
- };
@@ -1,84 +0,0 @@
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
- });