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,101 +0,0 @@
1
- import { once } from "events";
2
- import fs from "node:fs";
3
- import fsPromises from "node:fs/promises";
4
- import { Reader } from "./reader.js";
5
- import { ENOENT, isFileNotThereError } from "./utils/errors.js";
6
- import { noop } from "./utils/misc.js";
7
- class ReaderWatch {
8
- /** @type {Reader | undefined} */
9
- #reader;
10
- /** @type {Reader | undefined} */
11
- #maybeReader;
12
- /** @type {Promise<Reader> | undefined} */
13
- #readerOpeningPromise;
14
- #filepath;
15
- /** @type {fs.FSWatcher | undefined} */
16
- #watch;
17
- /**
18
- * @param {string} filepath
19
- */
20
- constructor(filepath) {
21
- this.#filepath = filepath;
22
- this.#tryToWatchFile();
23
- this.#get().catch(noop);
24
- }
25
- #tryToWatchFile() {
26
- if (this.#watch) return;
27
- try {
28
- this.#watch = fs.watch(this.#filepath, { persistent: false }, () => {
29
- this.#reader?.close().catch(noop);
30
- this.#reader = void 0;
31
- this.#maybeReader = void 0;
32
- this.#readerOpeningPromise = void 0;
33
- this.#watch?.close();
34
- this.#watch = void 0;
35
- }).on("error", noop);
36
- } catch (error) {
37
- if (isFileNotThereError(error)) {
38
- } else {
39
- throw error;
40
- }
41
- }
42
- }
43
- async #get() {
44
- if (isWin() && (this.#reader || this.#readerOpeningPromise)) {
45
- try {
46
- await fsPromises.stat(this.#filepath);
47
- } catch {
48
- this.#watch?.close();
49
- this.#watch = void 0;
50
- this.#reader?.close().catch(noop);
51
- this.#reader = void 0;
52
- this.#maybeReader = void 0;
53
- this.#readerOpeningPromise = void 0;
54
- }
55
- }
56
- this.#tryToWatchFile();
57
- if (this.#reader) return this.#reader;
58
- if (this.#readerOpeningPromise) return this.#readerOpeningPromise;
59
- this.#maybeReader = new Reader(this.#filepath);
60
- this.#readerOpeningPromise = this.#maybeReader.opened().then(() => {
61
- if (!this.#maybeReader) {
62
- throw new ENOENT(this.#filepath);
63
- }
64
- this.#reader = this.#maybeReader;
65
- return this.#reader;
66
- }).finally(() => {
67
- this.#maybeReader = void 0;
68
- this.#readerOpeningPromise = void 0;
69
- });
70
- return this.#readerOpeningPromise;
71
- }
72
- /** @type {Reader['opened']} */
73
- async opened() {
74
- const reader = await this.#get();
75
- return reader.opened();
76
- }
77
- /** @type {Reader['getStyle']} */
78
- async getStyle(baseUrl = null) {
79
- const reader = await this.#get();
80
- return reader.getStyle(baseUrl);
81
- }
82
- /** @type {Reader['getResource']} */
83
- async getResource(path) {
84
- const reader = await this.#get();
85
- return reader.getResource(path);
86
- }
87
- async close() {
88
- const reader = await this.#get();
89
- if (this.#watch) {
90
- this.#watch.close();
91
- await once(this.#watch, "close");
92
- }
93
- await reader.close();
94
- }
95
- }
96
- function isWin() {
97
- return process.platform === "win32";
98
- }
99
- export {
100
- ReaderWatch
101
- };
package/dist/reader.cjs DELETED
@@ -1,167 +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 reader_exports = {};
30
- __export(reader_exports, {
31
- Reader: () => Reader
32
- });
33
- module.exports = __toCommonJS(reader_exports);
34
- var import_into_stream = __toESM(require("into-stream"), 1);
35
- var import_yauzl_promise = require("yauzl-promise");
36
- var import_consumers = require("node:stream/consumers");
37
- var import_errors = require('./utils/errors.cjs');
38
- var import_misc = require('./utils/misc.cjs');
39
- var import_style = require('./utils/style.cjs');
40
- var import_templates = require('./utils/templates.cjs');
41
- class Reader {
42
- /** @type {Promise<import('yauzl-promise').ZipFile>} */
43
- #zipPromise;
44
- #entriesPromise;
45
- /** @type {undefined | Promise<void>} */
46
- #closePromise;
47
- /**
48
- * @param {string | import('yauzl-promise').ZipFile} filepathOrZip Path to styled map package (`.styledmap`) file, or an instance of yauzl ZipFile
49
- */
50
- constructor(filepathOrZip) {
51
- const zipPromise = this.#zipPromise = typeof filepathOrZip === "string" ? (0, import_yauzl_promise.open)(filepathOrZip) : Promise.resolve(filepathOrZip);
52
- zipPromise.catch(import_misc.noop);
53
- this.#entriesPromise = (async () => {
54
- const entries = /* @__PURE__ */ new Map();
55
- if (this.#closePromise) return entries;
56
- const zip = await zipPromise;
57
- if (this.#closePromise) return entries;
58
- for await (const entry of zip) {
59
- if (this.#closePromise) return entries;
60
- entries.set(entry.filename, entry);
61
- }
62
- return entries;
63
- })();
64
- this.#entriesPromise.catch(import_misc.noop);
65
- }
66
- /**
67
- * Resolves when the styled map package has been opened and the entries have
68
- * been read. Throws any error that occurred during opening.
69
- */
70
- async opened() {
71
- await this.#entriesPromise;
72
- }
73
- /**
74
- * Get the style JSON from the styled map package. The URLs in the style JSON
75
- * will be transformed to use the provided base URL.
76
- *
77
- * @param {string | null} [baseUrl] Base URL where you plan to serve the resources in this styled map package, e.g. `http://localhost:3000/maps/styleA`
78
- * @returns {Promise<import('./types.js').SMPStyle>}
79
- */
80
- async getStyle(baseUrl = null) {
81
- const styleEntry = (await this.#entriesPromise).get(import_templates.STYLE_FILE);
82
- if (!styleEntry) throw new import_errors.ENOENT(import_templates.STYLE_FILE);
83
- const stream = await styleEntry.openReadStream();
84
- const style = await (0, import_consumers.json)(stream);
85
- if (!(0, import_style.validateStyle)(style)) {
86
- throw new AggregateError(import_style.validateStyle.errors, "Invalid style");
87
- }
88
- if (typeof style.glyphs === "string") {
89
- style.glyphs = getUrl(style.glyphs, baseUrl);
90
- }
91
- if (typeof style.sprite === "string") {
92
- style.sprite = getUrl(style.sprite, baseUrl);
93
- } else if (Array.isArray(style.sprite)) {
94
- style.sprite = style.sprite.map(({ id, url }) => {
95
- return { id, url: getUrl(url, baseUrl) };
96
- });
97
- }
98
- for (const source of Object.values(style.sources)) {
99
- if ("tiles" in source && source.tiles) {
100
- source.tiles = source.tiles.map((tile) => getUrl(tile, baseUrl));
101
- }
102
- }
103
- return (
104
- /** @type {import('./types.js').SMPStyle} */
105
- style
106
- );
107
- }
108
- /**
109
- * Get a resource from the styled map package. The path should be relative to
110
- * the root of the package.
111
- *
112
- * @param {string} path
113
- * @returns {Promise<Resource>}
114
- */
115
- async getResource(path) {
116
- if (path[0] === "/") path = path.slice(1);
117
- if (path === import_templates.STYLE_FILE) {
118
- const styleJSON = JSON.stringify(await this.getStyle());
119
- return {
120
- contentType: "application/json; charset=utf-8",
121
- contentLength: Buffer.byteLength(styleJSON, "utf8"),
122
- resourceType: "style",
123
- stream: (0, import_into_stream.default)(styleJSON)
124
- };
125
- }
126
- const entry = (await this.#entriesPromise).get(path);
127
- if (!entry) throw new import_errors.ENOENT(path);
128
- const resourceType = (0, import_templates.getResourceType)(path);
129
- const contentType = (0, import_templates.getContentType)(path);
130
- const stream = await entry.openReadStream();
131
- const resource = {
132
- resourceType,
133
- contentType,
134
- contentLength: entry.uncompressedSize,
135
- stream
136
- };
137
- if (path.endsWith(".gz")) {
138
- resource.contentEncoding = "gzip";
139
- }
140
- return resource;
141
- }
142
- /**
143
- * Close the styled map package file (should be called after reading the file to avoid memory leaks)
144
- */
145
- async close() {
146
- if (this.#closePromise) return this.#closePromise;
147
- this.#closePromise = (async () => {
148
- const zip = await this.#zipPromise;
149
- await zip.close();
150
- })();
151
- return this.#closePromise;
152
- }
153
- }
154
- function getUrl(smpUri, baseUrl) {
155
- if (!smpUri.startsWith(import_templates.URI_BASE)) {
156
- throw new Error(`Invalid SMP URI: ${smpUri}`);
157
- }
158
- if (typeof baseUrl !== "string") return smpUri;
159
- if (!baseUrl.endsWith("/")) {
160
- baseUrl += "/";
161
- }
162
- return smpUri.replace(import_templates.URI_BASE, baseUrl);
163
- }
164
- // Annotate the CommonJS export names for ESM import in node:
165
- 0 && (module.exports = {
166
- Reader
167
- });
package/dist/reader.d.cts DELETED
@@ -1,62 +0,0 @@
1
- import * as stream from 'stream';
2
- import { a as SMPStyle } from './types-B4Xn1F9K.cjs';
3
- import * as yauzl_promise from 'yauzl-promise';
4
- import '@maplibre/maplibre-gl-style-spec';
5
- import 'geojson';
6
- import 'type-fest';
7
- import 'readable-stream';
8
- import 'events';
9
-
10
- /**
11
- * @typedef {object} Resource
12
- * @property {string} resourceType
13
- * @property {string} contentType
14
- * @property {number} contentLength
15
- * @property {import('stream').Readable} stream
16
- * @property {'gzip'} [contentEncoding]
17
- */
18
- /**
19
- * A low-level reader for styled map packages. Returns resources in the package
20
- * as readable streams, for serving over HTTP for example.
21
- */
22
- declare class Reader {
23
- /**
24
- * @param {string | import('yauzl-promise').ZipFile} filepathOrZip Path to styled map package (`.styledmap`) file, or an instance of yauzl ZipFile
25
- */
26
- constructor(filepathOrZip: string | yauzl_promise.ZipFile);
27
- /**
28
- * Resolves when the styled map package has been opened and the entries have
29
- * been read. Throws any error that occurred during opening.
30
- */
31
- opened(): Promise<void>;
32
- /**
33
- * Get the style JSON from the styled map package. The URLs in the style JSON
34
- * will be transformed to use the provided base URL.
35
- *
36
- * @param {string | null} [baseUrl] Base URL where you plan to serve the resources in this styled map package, e.g. `http://localhost:3000/maps/styleA`
37
- * @returns {Promise<import('./types.js').SMPStyle>}
38
- */
39
- getStyle(baseUrl?: string | null): Promise<SMPStyle>;
40
- /**
41
- * Get a resource from the styled map package. The path should be relative to
42
- * the root of the package.
43
- *
44
- * @param {string} path
45
- * @returns {Promise<Resource>}
46
- */
47
- getResource(path: string): Promise<Resource>;
48
- /**
49
- * Close the styled map package file (should be called after reading the file to avoid memory leaks)
50
- */
51
- close(): Promise<void>;
52
- #private;
53
- }
54
- type Resource = {
55
- resourceType: string;
56
- contentType: string;
57
- contentLength: number;
58
- stream: stream.Readable;
59
- contentEncoding?: "gzip" | undefined;
60
- };
61
-
62
- export { Reader, type Resource };
package/dist/reader.d.ts DELETED
@@ -1,62 +0,0 @@
1
- import * as stream from 'stream';
2
- import { a as SMPStyle } from './types-B4Xn1F9K.js';
3
- import * as yauzl_promise from 'yauzl-promise';
4
- import '@maplibre/maplibre-gl-style-spec';
5
- import 'geojson';
6
- import 'type-fest';
7
- import 'readable-stream';
8
- import 'events';
9
-
10
- /**
11
- * @typedef {object} Resource
12
- * @property {string} resourceType
13
- * @property {string} contentType
14
- * @property {number} contentLength
15
- * @property {import('stream').Readable} stream
16
- * @property {'gzip'} [contentEncoding]
17
- */
18
- /**
19
- * A low-level reader for styled map packages. Returns resources in the package
20
- * as readable streams, for serving over HTTP for example.
21
- */
22
- declare class Reader {
23
- /**
24
- * @param {string | import('yauzl-promise').ZipFile} filepathOrZip Path to styled map package (`.styledmap`) file, or an instance of yauzl ZipFile
25
- */
26
- constructor(filepathOrZip: string | yauzl_promise.ZipFile);
27
- /**
28
- * Resolves when the styled map package has been opened and the entries have
29
- * been read. Throws any error that occurred during opening.
30
- */
31
- opened(): Promise<void>;
32
- /**
33
- * Get the style JSON from the styled map package. The URLs in the style JSON
34
- * will be transformed to use the provided base URL.
35
- *
36
- * @param {string | null} [baseUrl] Base URL where you plan to serve the resources in this styled map package, e.g. `http://localhost:3000/maps/styleA`
37
- * @returns {Promise<import('./types.js').SMPStyle>}
38
- */
39
- getStyle(baseUrl?: string | null): Promise<SMPStyle>;
40
- /**
41
- * Get a resource from the styled map package. The path should be relative to
42
- * the root of the package.
43
- *
44
- * @param {string} path
45
- * @returns {Promise<Resource>}
46
- */
47
- getResource(path: string): Promise<Resource>;
48
- /**
49
- * Close the styled map package file (should be called after reading the file to avoid memory leaks)
50
- */
51
- close(): Promise<void>;
52
- #private;
53
- }
54
- type Resource = {
55
- resourceType: string;
56
- contentType: string;
57
- contentLength: number;
58
- stream: stream.Readable;
59
- contentEncoding?: "gzip" | undefined;
60
- };
61
-
62
- export { Reader, type Resource };
package/dist/reader.js DELETED
@@ -1,138 +0,0 @@
1
- import intoStream from "into-stream";
2
- import { open } from "yauzl-promise";
3
- import { json } from "node:stream/consumers";
4
- import { ENOENT } from "./utils/errors.js";
5
- import { noop } from "./utils/misc.js";
6
- import { validateStyle } from "./utils/style.js";
7
- import {
8
- getContentType,
9
- getResourceType,
10
- STYLE_FILE,
11
- URI_BASE
12
- } from "./utils/templates.js";
13
- class Reader {
14
- /** @type {Promise<import('yauzl-promise').ZipFile>} */
15
- #zipPromise;
16
- #entriesPromise;
17
- /** @type {undefined | Promise<void>} */
18
- #closePromise;
19
- /**
20
- * @param {string | import('yauzl-promise').ZipFile} filepathOrZip Path to styled map package (`.styledmap`) file, or an instance of yauzl ZipFile
21
- */
22
- constructor(filepathOrZip) {
23
- const zipPromise = this.#zipPromise = typeof filepathOrZip === "string" ? open(filepathOrZip) : Promise.resolve(filepathOrZip);
24
- zipPromise.catch(noop);
25
- this.#entriesPromise = (async () => {
26
- const entries = /* @__PURE__ */ new Map();
27
- if (this.#closePromise) return entries;
28
- const zip = await zipPromise;
29
- if (this.#closePromise) return entries;
30
- for await (const entry of zip) {
31
- if (this.#closePromise) return entries;
32
- entries.set(entry.filename, entry);
33
- }
34
- return entries;
35
- })();
36
- this.#entriesPromise.catch(noop);
37
- }
38
- /**
39
- * Resolves when the styled map package has been opened and the entries have
40
- * been read. Throws any error that occurred during opening.
41
- */
42
- async opened() {
43
- await this.#entriesPromise;
44
- }
45
- /**
46
- * Get the style JSON from the styled map package. The URLs in the style JSON
47
- * will be transformed to use the provided base URL.
48
- *
49
- * @param {string | null} [baseUrl] Base URL where you plan to serve the resources in this styled map package, e.g. `http://localhost:3000/maps/styleA`
50
- * @returns {Promise<import('./types.js').SMPStyle>}
51
- */
52
- async getStyle(baseUrl = null) {
53
- const styleEntry = (await this.#entriesPromise).get(STYLE_FILE);
54
- if (!styleEntry) throw new ENOENT(STYLE_FILE);
55
- const stream = await styleEntry.openReadStream();
56
- const style = await json(stream);
57
- if (!validateStyle(style)) {
58
- throw new AggregateError(validateStyle.errors, "Invalid style");
59
- }
60
- if (typeof style.glyphs === "string") {
61
- style.glyphs = getUrl(style.glyphs, baseUrl);
62
- }
63
- if (typeof style.sprite === "string") {
64
- style.sprite = getUrl(style.sprite, baseUrl);
65
- } else if (Array.isArray(style.sprite)) {
66
- style.sprite = style.sprite.map(({ id, url }) => {
67
- return { id, url: getUrl(url, baseUrl) };
68
- });
69
- }
70
- for (const source of Object.values(style.sources)) {
71
- if ("tiles" in source && source.tiles) {
72
- source.tiles = source.tiles.map((tile) => getUrl(tile, baseUrl));
73
- }
74
- }
75
- return (
76
- /** @type {import('./types.js').SMPStyle} */
77
- style
78
- );
79
- }
80
- /**
81
- * Get a resource from the styled map package. The path should be relative to
82
- * the root of the package.
83
- *
84
- * @param {string} path
85
- * @returns {Promise<Resource>}
86
- */
87
- async getResource(path) {
88
- if (path[0] === "/") path = path.slice(1);
89
- if (path === STYLE_FILE) {
90
- const styleJSON = JSON.stringify(await this.getStyle());
91
- return {
92
- contentType: "application/json; charset=utf-8",
93
- contentLength: Buffer.byteLength(styleJSON, "utf8"),
94
- resourceType: "style",
95
- stream: intoStream(styleJSON)
96
- };
97
- }
98
- const entry = (await this.#entriesPromise).get(path);
99
- if (!entry) throw new ENOENT(path);
100
- const resourceType = getResourceType(path);
101
- const contentType = getContentType(path);
102
- const stream = await entry.openReadStream();
103
- const resource = {
104
- resourceType,
105
- contentType,
106
- contentLength: entry.uncompressedSize,
107
- stream
108
- };
109
- if (path.endsWith(".gz")) {
110
- resource.contentEncoding = "gzip";
111
- }
112
- return resource;
113
- }
114
- /**
115
- * Close the styled map package file (should be called after reading the file to avoid memory leaks)
116
- */
117
- async close() {
118
- if (this.#closePromise) return this.#closePromise;
119
- this.#closePromise = (async () => {
120
- const zip = await this.#zipPromise;
121
- await zip.close();
122
- })();
123
- return this.#closePromise;
124
- }
125
- }
126
- function getUrl(smpUri, baseUrl) {
127
- if (!smpUri.startsWith(URI_BASE)) {
128
- throw new Error(`Invalid SMP URI: ${smpUri}`);
129
- }
130
- if (typeof baseUrl !== "string") return smpUri;
131
- if (!baseUrl.endsWith("/")) {
132
- baseUrl += "/";
133
- }
134
- return smpUri.replace(URI_BASE, baseUrl);
135
- }
136
- export {
137
- Reader
138
- };
@@ -1,122 +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 reporters_exports = {};
30
- __export(reporters_exports, {
31
- ttyReporter: () => ttyReporter
32
- });
33
- module.exports = __toCommonJS(reporters_exports);
34
- var import_chalk = __toESM(require("chalk"), 1);
35
- var import_log_symbols = __toESM(require("log-symbols"), 1);
36
- var import_ora = __toESM(require("ora"), 1);
37
- var import_pretty_bytes = __toESM(require("pretty-bytes"), 1);
38
- var import_pretty_ms = __toESM(require("pretty-ms"), 1);
39
- var import_readable_stream = require("readable-stream");
40
- import_chalk.default.level = import_chalk.chalkStderr.level;
41
- const TASKS = (
42
- /** @type {const} */
43
- [
44
- "style",
45
- "sprites",
46
- "tiles",
47
- "glyphs",
48
- "output"
49
- ]
50
- );
51
- const TASK_LABEL = (
52
- /** @type {const} */
53
- {
54
- style: "Downloading Map Style",
55
- sprites: "Downloading Sprites",
56
- tiles: "Downloading Tiles",
57
- glyphs: "Downloading Glyphs",
58
- output: "Writing Styled Map Package"
59
- }
60
- );
61
- const TASK_SUFFIX = (
62
- /** @type {{ [K in (typeof TASKS)[number]]: (progress: import('./download.js').DownloadProgress[K]) => string }} */
63
- {
64
- style: () => "",
65
- sprites: ({ downloaded }) => `${downloaded}`,
66
- tiles: ({ total, skipped, totalBytes, downloaded }) => {
67
- const formattedTotal = total.toLocaleString();
68
- const formattedCompleted = (downloaded + skipped).toLocaleString().padStart(formattedTotal.length);
69
- return `${formattedCompleted}/${formattedTotal} (${(0, import_pretty_bytes.default)(totalBytes)})`;
70
- },
71
- glyphs: ({ total, downloaded, totalBytes }) => `${downloaded}/${total} (${(0, import_pretty_bytes.default)(totalBytes)})`,
72
- output: ({ totalBytes }) => `${(0, import_pretty_bytes.default)(totalBytes)}`
73
- }
74
- );
75
- function ttyReporter() {
76
- let stats;
77
- let current = 0;
78
- let spinner;
79
- return new import_readable_stream.Writable({
80
- objectMode: true,
81
- // @ts-ignore - missing type def
82
- construct(cb) {
83
- process.stderr.write("\n");
84
- spinner = (0, import_ora.default)(TASK_LABEL[TASKS[current]]).start();
85
- cb();
86
- },
87
- /** @param {ArrayLike<{ chunk: import('./download.js').DownloadProgress, encoding: string }>} chunks */
88
- writev(chunks, cb) {
89
- stats = chunks[chunks.length - 1].chunk;
90
- while (current < TASKS.length && stats[TASKS[current]].done) {
91
- spinner.suffixText = import_chalk.default.dim(
92
- TASK_SUFFIX[TASKS[current]](
93
- // @ts-ignore - too complicated for TS
94
- stats[TASKS[current]]
95
- )
96
- );
97
- spinner.succeed();
98
- if (++current < TASKS.length) {
99
- spinner = (0, import_ora.default)(TASK_LABEL[TASKS[current]]).start();
100
- }
101
- }
102
- if (current < TASKS.length) {
103
- spinner.suffixText = import_chalk.default.dim(
104
- TASK_SUFFIX[TASKS[current]](
105
- // @ts-ignore - too complicated for TS
106
- stats[TASKS[current]]
107
- )
108
- );
109
- } else {
110
- process.stderr.write(
111
- `${import_chalk.default.green(import_log_symbols.default.success)} Completed in ${(0, import_pretty_ms.default)(stats.elapsedMs)}
112
- `
113
- );
114
- }
115
- cb();
116
- }
117
- });
118
- }
119
- // Annotate the CommonJS export names for ESM import in node:
120
- 0 && (module.exports = {
121
- ttyReporter
122
- });
@@ -1,10 +0,0 @@
1
- import { Writable } from 'readable-stream';
2
-
3
- /**
4
- * A writable stream to reporting download progress to a TTY terminal. Write
5
- * progress messages to this stream for a pretty-printed progress task-list in
6
- * the terminal.
7
- */
8
- declare function ttyReporter(): Writable;
9
-
10
- export { ttyReporter };
@@ -1,10 +0,0 @@
1
- import { Writable } from 'readable-stream';
2
-
3
- /**
4
- * A writable stream to reporting download progress to a TTY terminal. Write
5
- * progress messages to this stream for a pretty-printed progress task-list in
6
- * the terminal.
7
- */
8
- declare function ttyReporter(): Writable;
9
-
10
- export { ttyReporter };