styled-map-package 2.2.1 → 4.0.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 (107) hide show
  1. package/bin/smp-download.js +3 -3
  2. package/bin/smp-mbtiles.js +1 -1
  3. package/bin/smp-view.js +15 -4
  4. package/dist/download.cjs +101 -0
  5. package/dist/download.d.cts +65 -0
  6. package/dist/{lib/download.d.ts → download.d.ts} +22 -6
  7. package/dist/download.js +77 -0
  8. package/dist/from-mbtiles.cjs +91 -0
  9. package/dist/from-mbtiles.d.cts +17 -0
  10. package/dist/from-mbtiles.d.ts +17 -0
  11. package/dist/from-mbtiles.js +57 -0
  12. package/dist/index.cjs +49 -0
  13. package/dist/index.d.cts +27 -0
  14. package/dist/index.d.ts +27 -0
  15. package/dist/index.js +18 -0
  16. package/dist/reader-watch.cjs +135 -0
  17. package/dist/reader-watch.d.cts +24 -0
  18. package/dist/reader-watch.d.ts +24 -0
  19. package/dist/reader-watch.js +101 -0
  20. package/dist/reader.cjs +167 -0
  21. package/dist/reader.d.cts +62 -0
  22. package/dist/{lib/reader.d.ts → reader.d.ts} +16 -5
  23. package/dist/reader.js +138 -0
  24. package/dist/reporters.cjs +122 -0
  25. package/dist/reporters.d.cts +10 -0
  26. package/dist/{lib/reporters.d.ts → reporters.d.ts} +5 -2
  27. package/dist/reporters.js +88 -0
  28. package/dist/server.cjs +79 -0
  29. package/dist/server.d.cts +48 -0
  30. package/dist/server.d.ts +48 -0
  31. package/dist/server.js +55 -0
  32. package/dist/style-downloader.cjs +312 -0
  33. package/dist/style-downloader.d.cts +120 -0
  34. package/dist/{lib/style-downloader.d.ts → style-downloader.d.ts} +23 -13
  35. package/dist/style-downloader.js +288 -0
  36. package/dist/tile-downloader.cjs +158 -0
  37. package/dist/tile-downloader.d.cts +84 -0
  38. package/dist/{lib/tile-downloader.d.ts → tile-downloader.d.ts} +22 -10
  39. package/dist/tile-downloader.js +126 -0
  40. package/dist/{lib/writer.d.ts → types-B4Xn1F9K.d.cts} +74 -14
  41. package/dist/types-B4Xn1F9K.d.ts +189 -0
  42. package/dist/utils/errors.cjs +41 -0
  43. package/dist/utils/errors.d.cts +18 -0
  44. package/dist/{lib/utils → utils}/errors.d.ts +4 -2
  45. package/dist/utils/errors.js +16 -0
  46. package/dist/utils/fetch.cjs +96 -0
  47. package/dist/utils/fetch.d.cts +51 -0
  48. package/dist/{lib/utils → utils}/fetch.d.ts +10 -4
  49. package/dist/utils/fetch.js +62 -0
  50. package/dist/utils/file-formats.cjs +98 -0
  51. package/dist/utils/file-formats.d.cts +35 -0
  52. package/dist/{lib/utils → utils}/file-formats.d.ts +13 -3
  53. package/dist/utils/file-formats.js +62 -0
  54. package/dist/utils/geo.cjs +84 -0
  55. package/dist/utils/geo.d.cts +46 -0
  56. package/dist/{lib/utils → utils}/geo.d.ts +8 -6
  57. package/dist/utils/geo.js +56 -0
  58. package/dist/utils/mapbox.cjs +121 -0
  59. package/dist/utils/mapbox.d.cts +43 -0
  60. package/dist/utils/mapbox.d.ts +43 -0
  61. package/dist/utils/mapbox.js +91 -0
  62. package/dist/utils/misc.cjs +39 -0
  63. package/{lib/utils/misc.js → dist/utils/misc.d.cts} +5 -9
  64. package/dist/{lib/utils → utils}/misc.d.ts +5 -3
  65. package/dist/utils/misc.js +13 -0
  66. package/dist/utils/streams.cjs +130 -0
  67. package/dist/utils/streams.d.cts +73 -0
  68. package/dist/{lib/utils → utils}/streams.d.ts +14 -10
  69. package/dist/utils/streams.js +103 -0
  70. package/dist/utils/style.cjs +126 -0
  71. package/dist/utils/style.d.cts +69 -0
  72. package/dist/{lib/utils → utils}/style.d.ts +19 -9
  73. package/dist/utils/style.js +98 -0
  74. package/dist/utils/templates.cjs +114 -0
  75. package/dist/utils/templates.d.cts +78 -0
  76. package/dist/{lib/utils → utils}/templates.d.ts +24 -14
  77. package/dist/utils/templates.js +79 -0
  78. package/dist/writer.cjs +401 -0
  79. package/dist/writer.d.cts +7 -0
  80. package/dist/writer.d.ts +7 -0
  81. package/dist/writer.js +374 -0
  82. package/package.json +107 -41
  83. package/dist/lib/from-mbtiles.d.ts +0 -13
  84. package/dist/lib/index.d.ts +0 -10
  85. package/dist/lib/reader-watch.d.ts +0 -13
  86. package/dist/lib/server.d.ts +0 -15
  87. package/dist/lib/types.d.ts +0 -64
  88. package/dist/lib/utils/mapbox.d.ts +0 -41
  89. package/lib/download.js +0 -114
  90. package/lib/from-mbtiles.js +0 -83
  91. package/lib/index.js +0 -11
  92. package/lib/reader-watch.js +0 -133
  93. package/lib/reader.js +0 -165
  94. package/lib/reporters.js +0 -92
  95. package/lib/server.js +0 -81
  96. package/lib/style-downloader.js +0 -363
  97. package/lib/tile-downloader.js +0 -188
  98. package/lib/types.ts +0 -104
  99. package/lib/utils/errors.js +0 -24
  100. package/lib/utils/fetch.js +0 -100
  101. package/lib/utils/file-formats.js +0 -85
  102. package/lib/utils/geo.js +0 -87
  103. package/lib/utils/mapbox.js +0 -155
  104. package/lib/utils/streams.js +0 -165
  105. package/lib/utils/style.js +0 -174
  106. package/lib/utils/templates.js +0 -136
  107. package/lib/writer.js +0 -478
@@ -0,0 +1,135 @@
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_watch_exports = {};
30
+ __export(reader_watch_exports, {
31
+ ReaderWatch: () => ReaderWatch
32
+ });
33
+ module.exports = __toCommonJS(reader_watch_exports);
34
+ var import_events = require("events");
35
+ var import_node_fs = __toESM(require("node:fs"), 1);
36
+ var import_promises = __toESM(require("node:fs/promises"), 1);
37
+ var import_reader = require('./reader.cjs');
38
+ var import_errors = require('./utils/errors.cjs');
39
+ var import_misc = require('./utils/misc.cjs');
40
+ class ReaderWatch {
41
+ /** @type {Reader | undefined} */
42
+ #reader;
43
+ /** @type {Reader | undefined} */
44
+ #maybeReader;
45
+ /** @type {Promise<Reader> | undefined} */
46
+ #readerOpeningPromise;
47
+ #filepath;
48
+ /** @type {fs.FSWatcher | undefined} */
49
+ #watch;
50
+ /**
51
+ * @param {string} filepath
52
+ */
53
+ constructor(filepath) {
54
+ this.#filepath = filepath;
55
+ this.#tryToWatchFile();
56
+ this.#get().catch(import_misc.noop);
57
+ }
58
+ #tryToWatchFile() {
59
+ if (this.#watch) return;
60
+ try {
61
+ this.#watch = import_node_fs.default.watch(this.#filepath, { persistent: false }, () => {
62
+ this.#reader?.close().catch(import_misc.noop);
63
+ this.#reader = void 0;
64
+ this.#maybeReader = void 0;
65
+ this.#readerOpeningPromise = void 0;
66
+ this.#watch?.close();
67
+ this.#watch = void 0;
68
+ }).on("error", import_misc.noop);
69
+ } catch (error) {
70
+ if ((0, import_errors.isFileNotThereError)(error)) {
71
+ } else {
72
+ throw error;
73
+ }
74
+ }
75
+ }
76
+ async #get() {
77
+ if (isWin() && (this.#reader || this.#readerOpeningPromise)) {
78
+ try {
79
+ await import_promises.default.stat(this.#filepath);
80
+ } catch {
81
+ this.#watch?.close();
82
+ this.#watch = void 0;
83
+ this.#reader?.close().catch(import_misc.noop);
84
+ this.#reader = void 0;
85
+ this.#maybeReader = void 0;
86
+ this.#readerOpeningPromise = void 0;
87
+ }
88
+ }
89
+ this.#tryToWatchFile();
90
+ if (this.#reader) return this.#reader;
91
+ if (this.#readerOpeningPromise) return this.#readerOpeningPromise;
92
+ this.#maybeReader = new import_reader.Reader(this.#filepath);
93
+ this.#readerOpeningPromise = this.#maybeReader.opened().then(() => {
94
+ if (!this.#maybeReader) {
95
+ throw new import_errors.ENOENT(this.#filepath);
96
+ }
97
+ this.#reader = this.#maybeReader;
98
+ return this.#reader;
99
+ }).finally(() => {
100
+ this.#maybeReader = void 0;
101
+ this.#readerOpeningPromise = void 0;
102
+ });
103
+ return this.#readerOpeningPromise;
104
+ }
105
+ /** @type {Reader['opened']} */
106
+ async opened() {
107
+ const reader = await this.#get();
108
+ return reader.opened();
109
+ }
110
+ /** @type {Reader['getStyle']} */
111
+ async getStyle(baseUrl = null) {
112
+ const reader = await this.#get();
113
+ return reader.getStyle(baseUrl);
114
+ }
115
+ /** @type {Reader['getResource']} */
116
+ async getResource(path) {
117
+ const reader = await this.#get();
118
+ return reader.getResource(path);
119
+ }
120
+ async close() {
121
+ const reader = await this.#get();
122
+ if (this.#watch) {
123
+ this.#watch.close();
124
+ await (0, import_events.once)(this.#watch, "close");
125
+ }
126
+ await reader.close();
127
+ }
128
+ }
129
+ function isWin() {
130
+ return process.platform === "win32";
131
+ }
132
+ // Annotate the CommonJS export names for ESM import in node:
133
+ 0 && (module.exports = {
134
+ ReaderWatch
135
+ });
@@ -0,0 +1,24 @@
1
+ import { a as SMPStyle } from './types-B4Xn1F9K.cjs';
2
+ import { Reader } from './reader.cjs';
3
+ import '@maplibre/maplibre-gl-style-spec';
4
+ import 'geojson';
5
+ import 'stream';
6
+ import 'type-fest';
7
+ import 'readable-stream';
8
+ import 'events';
9
+ import 'yauzl-promise';
10
+
11
+ /** @implements {Pick<Reader, keyof Reader>} */
12
+ declare class ReaderWatch implements Pick<Reader, keyof Reader> {
13
+ /**
14
+ * @param {string} filepath
15
+ */
16
+ constructor(filepath: string);
17
+ opened(): Promise<void>;
18
+ getStyle(baseUrl?: string | null): Promise<SMPStyle>;
19
+ getResource(path: string): Promise<Resource>;
20
+ close(): Promise<void>;
21
+ #private;
22
+ }
23
+
24
+ export { ReaderWatch };
@@ -0,0 +1,24 @@
1
+ import { a as SMPStyle } from './types-B4Xn1F9K.js';
2
+ import { Reader } from './reader.js';
3
+ import '@maplibre/maplibre-gl-style-spec';
4
+ import 'geojson';
5
+ import 'stream';
6
+ import 'type-fest';
7
+ import 'readable-stream';
8
+ import 'events';
9
+ import 'yauzl-promise';
10
+
11
+ /** @implements {Pick<Reader, keyof Reader>} */
12
+ declare class ReaderWatch implements Pick<Reader, keyof Reader> {
13
+ /**
14
+ * @param {string} filepath
15
+ */
16
+ constructor(filepath: string);
17
+ opened(): Promise<void>;
18
+ getStyle(baseUrl?: string | null): Promise<SMPStyle>;
19
+ getResource(path: string): Promise<Resource>;
20
+ close(): Promise<void>;
21
+ #private;
22
+ }
23
+
24
+ export { ReaderWatch };
@@ -0,0 +1,101 @@
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
+ };
@@ -0,0 +1,167 @@
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
+ });
@@ -0,0 +1,62 @@
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 };
@@ -1,3 +1,12 @@
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
+
1
10
  /**
2
11
  * @typedef {object} Resource
3
12
  * @property {string} resourceType
@@ -10,11 +19,11 @@
10
19
  * A low-level reader for styled map packages. Returns resources in the package
11
20
  * as readable streams, for serving over HTTP for example.
12
21
  */
13
- export default class Reader {
22
+ declare class Reader {
14
23
  /**
15
24
  * @param {string | import('yauzl-promise').ZipFile} filepathOrZip Path to styled map package (`.styledmap`) file, or an instance of yauzl ZipFile
16
25
  */
17
- constructor(filepathOrZip: string | import("yauzl-promise").ZipFile);
26
+ constructor(filepathOrZip: string | yauzl_promise.ZipFile);
18
27
  /**
19
28
  * Resolves when the styled map package has been opened and the entries have
20
29
  * been read. Throws any error that occurred during opening.
@@ -27,7 +36,7 @@ export default class Reader {
27
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`
28
37
  * @returns {Promise<import('./types.js').SMPStyle>}
29
38
  */
30
- getStyle(baseUrl?: string | null): Promise<import("./types.js").SMPStyle>;
39
+ getStyle(baseUrl?: string | null): Promise<SMPStyle>;
31
40
  /**
32
41
  * Get a resource from the styled map package. The path should be relative to
33
42
  * the root of the package.
@@ -42,10 +51,12 @@ export default class Reader {
42
51
  close(): Promise<void>;
43
52
  #private;
44
53
  }
45
- export type Resource = {
54
+ type Resource = {
46
55
  resourceType: string;
47
56
  contentType: string;
48
57
  contentLength: number;
49
- stream: import("stream").Readable;
58
+ stream: stream.Readable;
50
59
  contentEncoding?: "gzip" | undefined;
51
60
  };
61
+
62
+ export { Reader, type Resource };