styled-map-package 4.1.0 → 5.0.0-pre.1

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 (238) hide show
  1. package/README.md +47 -7
  2. package/bin/smp-download.js +27 -151
  3. package/bin/smp-mbtiles.js +12 -7
  4. package/bin/smp-view.js +32 -54
  5. package/lib/commands/download.js +188 -0
  6. package/lib/commands/mbtiles.js +21 -0
  7. package/lib/commands/view.js +57 -0
  8. package/lib/reporters.js +92 -0
  9. package/package.json +9 -181
  10. package/LICENSE.md +0 -7
  11. package/dist/download.cjs +0 -101
  12. package/dist/download.d.cts +0 -65
  13. package/dist/download.d.ts +0 -65
  14. package/dist/download.js +0 -77
  15. package/dist/from-mbtiles.cjs +0 -91
  16. package/dist/from-mbtiles.d.cts +0 -17
  17. package/dist/from-mbtiles.d.ts +0 -17
  18. package/dist/from-mbtiles.js +0 -57
  19. package/dist/index.cjs +0 -49
  20. package/dist/index.d.cts +0 -27
  21. package/dist/index.d.ts +0 -27
  22. package/dist/index.js +0 -18
  23. package/dist/reader-watch.cjs +0 -135
  24. package/dist/reader-watch.d.cts +0 -24
  25. package/dist/reader-watch.d.ts +0 -24
  26. package/dist/reader-watch.js +0 -101
  27. package/dist/reader.cjs +0 -168
  28. package/dist/reader.d.cts +0 -62
  29. package/dist/reader.d.ts +0 -62
  30. package/dist/reader.js +0 -139
  31. package/dist/reporters.cjs +0 -122
  32. package/dist/reporters.d.cts +0 -10
  33. package/dist/reporters.d.ts +0 -10
  34. package/dist/reporters.js +0 -88
  35. package/dist/server.cjs +0 -78
  36. package/dist/server.d.cts +0 -48
  37. package/dist/server.d.ts +0 -48
  38. package/dist/server.js +0 -54
  39. package/dist/style-downloader.cjs +0 -312
  40. package/dist/style-downloader.d.cts +0 -120
  41. package/dist/style-downloader.d.ts +0 -120
  42. package/dist/style-downloader.js +0 -288
  43. package/dist/tile-downloader.cjs +0 -158
  44. package/dist/tile-downloader.d.cts +0 -84
  45. package/dist/tile-downloader.d.ts +0 -84
  46. package/dist/tile-downloader.js +0 -126
  47. package/dist/types-yLQy3AKR.d.cts +0 -192
  48. package/dist/types-yLQy3AKR.d.ts +0 -192
  49. package/dist/utils/errors.cjs +0 -41
  50. package/dist/utils/errors.d.cts +0 -18
  51. package/dist/utils/errors.d.ts +0 -18
  52. package/dist/utils/errors.js +0 -16
  53. package/dist/utils/fetch.cjs +0 -96
  54. package/dist/utils/fetch.d.cts +0 -51
  55. package/dist/utils/fetch.d.ts +0 -51
  56. package/dist/utils/fetch.js +0 -62
  57. package/dist/utils/file-formats.cjs +0 -98
  58. package/dist/utils/file-formats.d.cts +0 -35
  59. package/dist/utils/file-formats.d.ts +0 -35
  60. package/dist/utils/file-formats.js +0 -62
  61. package/dist/utils/geo.cjs +0 -84
  62. package/dist/utils/geo.d.cts +0 -46
  63. package/dist/utils/geo.d.ts +0 -46
  64. package/dist/utils/geo.js +0 -56
  65. package/dist/utils/mapbox.cjs +0 -121
  66. package/dist/utils/mapbox.d.cts +0 -43
  67. package/dist/utils/mapbox.d.ts +0 -43
  68. package/dist/utils/mapbox.js +0 -91
  69. package/dist/utils/misc.cjs +0 -39
  70. package/dist/utils/misc.d.cts +0 -22
  71. package/dist/utils/misc.d.ts +0 -22
  72. package/dist/utils/misc.js +0 -13
  73. package/dist/utils/streams.cjs +0 -130
  74. package/dist/utils/streams.d.cts +0 -73
  75. package/dist/utils/streams.d.ts +0 -73
  76. package/dist/utils/streams.js +0 -103
  77. package/dist/utils/style.cjs +0 -126
  78. package/dist/utils/style.d.cts +0 -69
  79. package/dist/utils/style.d.ts +0 -69
  80. package/dist/utils/style.js +0 -98
  81. package/dist/utils/templates.cjs +0 -118
  82. package/dist/utils/templates.d.cts +0 -80
  83. package/dist/utils/templates.d.ts +0 -80
  84. package/dist/utils/templates.js +0 -81
  85. package/dist/writer.cjs +0 -449
  86. package/dist/writer.d.cts +0 -7
  87. package/dist/writer.d.ts +0 -7
  88. package/dist/writer.js +0 -424
  89. package/node_modules/@node-rs/crc32/LICENSE +0 -21
  90. package/node_modules/@node-rs/crc32/README.md +0 -61
  91. package/node_modules/@node-rs/crc32/browser.js +0 -1
  92. package/node_modules/@node-rs/crc32/index.d.ts +0 -5
  93. package/node_modules/@node-rs/crc32/index.js +0 -368
  94. package/node_modules/@node-rs/crc32/package.json +0 -97
  95. package/node_modules/@node-rs/crc32-linux-x64-gnu/README.md +0 -3
  96. package/node_modules/@node-rs/crc32-linux-x64-gnu/crc32.linux-x64-gnu.node +0 -0
  97. package/node_modules/@node-rs/crc32-linux-x64-gnu/package.json +0 -43
  98. package/node_modules/@node-rs/crc32-linux-x64-musl/README.md +0 -3
  99. package/node_modules/@node-rs/crc32-linux-x64-musl/crc32.linux-x64-musl.node +0 -0
  100. package/node_modules/@node-rs/crc32-linux-x64-musl/package.json +0 -43
  101. package/node_modules/define-data-property/.eslintrc +0 -24
  102. package/node_modules/define-data-property/.github/FUNDING.yml +0 -12
  103. package/node_modules/define-data-property/.nycrc +0 -13
  104. package/node_modules/define-data-property/CHANGELOG.md +0 -70
  105. package/node_modules/define-data-property/LICENSE +0 -21
  106. package/node_modules/define-data-property/README.md +0 -67
  107. package/node_modules/define-data-property/index.d.ts +0 -12
  108. package/node_modules/define-data-property/index.js +0 -56
  109. package/node_modules/define-data-property/package.json +0 -106
  110. package/node_modules/define-data-property/test/index.js +0 -392
  111. package/node_modules/define-data-property/tsconfig.json +0 -59
  112. package/node_modules/define-properties/.editorconfig +0 -13
  113. package/node_modules/define-properties/.eslintrc +0 -19
  114. package/node_modules/define-properties/.github/FUNDING.yml +0 -12
  115. package/node_modules/define-properties/.nycrc +0 -9
  116. package/node_modules/define-properties/CHANGELOG.md +0 -91
  117. package/node_modules/define-properties/LICENSE +0 -21
  118. package/node_modules/define-properties/README.md +0 -84
  119. package/node_modules/define-properties/index.js +0 -47
  120. package/node_modules/define-properties/package.json +0 -88
  121. package/node_modules/es-define-property/.eslintrc +0 -13
  122. package/node_modules/es-define-property/.github/FUNDING.yml +0 -12
  123. package/node_modules/es-define-property/.nycrc +0 -9
  124. package/node_modules/es-define-property/CHANGELOG.md +0 -29
  125. package/node_modules/es-define-property/LICENSE +0 -21
  126. package/node_modules/es-define-property/README.md +0 -49
  127. package/node_modules/es-define-property/index.d.ts +0 -3
  128. package/node_modules/es-define-property/index.js +0 -14
  129. package/node_modules/es-define-property/package.json +0 -81
  130. package/node_modules/es-define-property/test/index.js +0 -56
  131. package/node_modules/es-define-property/tsconfig.json +0 -10
  132. package/node_modules/es-errors/.eslintrc +0 -5
  133. package/node_modules/es-errors/.github/FUNDING.yml +0 -12
  134. package/node_modules/es-errors/CHANGELOG.md +0 -40
  135. package/node_modules/es-errors/LICENSE +0 -21
  136. package/node_modules/es-errors/README.md +0 -55
  137. package/node_modules/es-errors/eval.d.ts +0 -3
  138. package/node_modules/es-errors/eval.js +0 -4
  139. package/node_modules/es-errors/index.d.ts +0 -3
  140. package/node_modules/es-errors/index.js +0 -4
  141. package/node_modules/es-errors/package.json +0 -80
  142. package/node_modules/es-errors/range.d.ts +0 -3
  143. package/node_modules/es-errors/range.js +0 -4
  144. package/node_modules/es-errors/ref.d.ts +0 -3
  145. package/node_modules/es-errors/ref.js +0 -4
  146. package/node_modules/es-errors/syntax.d.ts +0 -3
  147. package/node_modules/es-errors/syntax.js +0 -4
  148. package/node_modules/es-errors/test/index.js +0 -19
  149. package/node_modules/es-errors/tsconfig.json +0 -49
  150. package/node_modules/es-errors/type.d.ts +0 -3
  151. package/node_modules/es-errors/type.js +0 -4
  152. package/node_modules/es-errors/uri.d.ts +0 -3
  153. package/node_modules/es-errors/uri.js +0 -4
  154. package/node_modules/globalthis/.eslintrc +0 -18
  155. package/node_modules/globalthis/.nycrc +0 -10
  156. package/node_modules/globalthis/CHANGELOG.md +0 -109
  157. package/node_modules/globalthis/LICENSE +0 -21
  158. package/node_modules/globalthis/README.md +0 -70
  159. package/node_modules/globalthis/auto.js +0 -3
  160. package/node_modules/globalthis/implementation.browser.js +0 -11
  161. package/node_modules/globalthis/implementation.js +0 -3
  162. package/node_modules/globalthis/index.js +0 -19
  163. package/node_modules/globalthis/package.json +0 -99
  164. package/node_modules/globalthis/polyfill.js +0 -10
  165. package/node_modules/globalthis/shim.js +0 -29
  166. package/node_modules/globalthis/test/implementation.js +0 -11
  167. package/node_modules/globalthis/test/index.js +0 -11
  168. package/node_modules/globalthis/test/native.js +0 -26
  169. package/node_modules/globalthis/test/shimmed.js +0 -29
  170. package/node_modules/globalthis/test/tests.js +0 -36
  171. package/node_modules/gopd/.eslintrc +0 -16
  172. package/node_modules/gopd/.github/FUNDING.yml +0 -12
  173. package/node_modules/gopd/CHANGELOG.md +0 -45
  174. package/node_modules/gopd/LICENSE +0 -21
  175. package/node_modules/gopd/README.md +0 -40
  176. package/node_modules/gopd/gOPD.d.ts +0 -1
  177. package/node_modules/gopd/gOPD.js +0 -4
  178. package/node_modules/gopd/index.d.ts +0 -5
  179. package/node_modules/gopd/index.js +0 -15
  180. package/node_modules/gopd/package.json +0 -77
  181. package/node_modules/gopd/test/index.js +0 -36
  182. package/node_modules/gopd/tsconfig.json +0 -9
  183. package/node_modules/has-property-descriptors/.eslintrc +0 -13
  184. package/node_modules/has-property-descriptors/.github/FUNDING.yml +0 -12
  185. package/node_modules/has-property-descriptors/.nycrc +0 -9
  186. package/node_modules/has-property-descriptors/CHANGELOG.md +0 -35
  187. package/node_modules/has-property-descriptors/LICENSE +0 -21
  188. package/node_modules/has-property-descriptors/README.md +0 -43
  189. package/node_modules/has-property-descriptors/index.js +0 -22
  190. package/node_modules/has-property-descriptors/package.json +0 -77
  191. package/node_modules/has-property-descriptors/test/index.js +0 -57
  192. package/node_modules/is-it-type/License +0 -19
  193. package/node_modules/is-it-type/README.md +0 -102
  194. package/node_modules/is-it-type/changelog.md +0 -239
  195. package/node_modules/is-it-type/dist/cjs/is-it-type.js +0 -173
  196. package/node_modules/is-it-type/dist/cjs/is-it-type.js.map +0 -1
  197. package/node_modules/is-it-type/dist/cjs/is-it-type.min.js +0 -2
  198. package/node_modules/is-it-type/dist/cjs/is-it-type.min.js.map +0 -1
  199. package/node_modules/is-it-type/dist/esm/is-it-type.js +0 -143
  200. package/node_modules/is-it-type/dist/esm/is-it-type.js.map +0 -1
  201. package/node_modules/is-it-type/dist/esm/is-it-type.min.js +0 -2
  202. package/node_modules/is-it-type/dist/esm/is-it-type.min.js.map +0 -1
  203. package/node_modules/is-it-type/dist/esm/package.json +0 -3
  204. package/node_modules/is-it-type/dist/umd/is-it-type.js +0 -450
  205. package/node_modules/is-it-type/dist/umd/is-it-type.js.map +0 -1
  206. package/node_modules/is-it-type/dist/umd/is-it-type.min.js +0 -2
  207. package/node_modules/is-it-type/dist/umd/is-it-type.min.js.map +0 -1
  208. package/node_modules/is-it-type/es/index.js +0 -8
  209. package/node_modules/is-it-type/es/package.json +0 -3
  210. package/node_modules/is-it-type/index.js +0 -10
  211. package/node_modules/is-it-type/package.json +0 -87
  212. package/node_modules/is-it-type/src/index.js +0 -169
  213. package/node_modules/object-keys/.editorconfig +0 -13
  214. package/node_modules/object-keys/.eslintrc +0 -17
  215. package/node_modules/object-keys/.travis.yml +0 -277
  216. package/node_modules/object-keys/CHANGELOG.md +0 -232
  217. package/node_modules/object-keys/LICENSE +0 -21
  218. package/node_modules/object-keys/README.md +0 -76
  219. package/node_modules/object-keys/implementation.js +0 -122
  220. package/node_modules/object-keys/index.js +0 -32
  221. package/node_modules/object-keys/isArguments.js +0 -17
  222. package/node_modules/object-keys/package.json +0 -88
  223. package/node_modules/object-keys/test/index.js +0 -5
  224. package/node_modules/simple-invariant/License +0 -19
  225. package/node_modules/simple-invariant/README.md +0 -64
  226. package/node_modules/simple-invariant/changelog.md +0 -31
  227. package/node_modules/simple-invariant/index.js +0 -19
  228. package/node_modules/simple-invariant/package.json +0 -50
  229. package/node_modules/yauzl-promise/License +0 -19
  230. package/node_modules/yauzl-promise/README.md +0 -440
  231. package/node_modules/yauzl-promise/index.js +0 -10
  232. package/node_modules/yauzl-promise/lib/entry.js +0 -312
  233. package/node_modules/yauzl-promise/lib/index.js +0 -160
  234. package/node_modules/yauzl-promise/lib/reader.js +0 -289
  235. package/node_modules/yauzl-promise/lib/shared.js +0 -20
  236. package/node_modules/yauzl-promise/lib/utils.js +0 -105
  237. package/node_modules/yauzl-promise/lib/zip.js +0 -1224
  238. package/node_modules/yauzl-promise/package.json +0 -56
package/dist/reader.cjs DELETED
@@ -1,168 +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.catch(import_misc.noop);
149
- if (!zip) return;
150
- await zip.close();
151
- })();
152
- return this.#closePromise;
153
- }
154
- }
155
- function getUrl(smpUri, baseUrl) {
156
- if (!smpUri.startsWith(import_templates.URI_BASE)) {
157
- throw new Error(`Invalid SMP URI: ${smpUri}`);
158
- }
159
- if (typeof baseUrl !== "string") return smpUri;
160
- if (!baseUrl.endsWith("/")) {
161
- baseUrl += "/";
162
- }
163
- return smpUri.replace(import_templates.URI_BASE, baseUrl);
164
- }
165
- // Annotate the CommonJS export names for ESM import in node:
166
- 0 && (module.exports = {
167
- Reader
168
- });
package/dist/reader.d.cts DELETED
@@ -1,62 +0,0 @@
1
- import * as stream from 'stream';
2
- import { a as SMPStyle } from './types-yLQy3AKR.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-yLQy3AKR.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,139 +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.catch(noop);
121
- if (!zip) return;
122
- await zip.close();
123
- })();
124
- return this.#closePromise;
125
- }
126
- }
127
- function getUrl(smpUri, baseUrl) {
128
- if (!smpUri.startsWith(URI_BASE)) {
129
- throw new Error(`Invalid SMP URI: ${smpUri}`);
130
- }
131
- if (typeof baseUrl !== "string") return smpUri;
132
- if (!baseUrl.endsWith("/")) {
133
- baseUrl += "/";
134
- }
135
- return smpUri.replace(URI_BASE, baseUrl);
136
- }
137
- export {
138
- Reader
139
- };
@@ -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 };
package/dist/reporters.js DELETED
@@ -1,88 +0,0 @@
1
- import chalk, { chalkStderr } from "chalk";
2
- import logSymbols from "log-symbols";
3
- import ora from "ora";
4
- import prettyBytes from "pretty-bytes";
5
- import prettyMilliseconds from "pretty-ms";
6
- import { Writable } from "readable-stream";
7
- chalk.level = chalkStderr.level;
8
- const TASKS = (
9
- /** @type {const} */
10
- [
11
- "style",
12
- "sprites",
13
- "tiles",
14
- "glyphs",
15
- "output"
16
- ]
17
- );
18
- const TASK_LABEL = (
19
- /** @type {const} */
20
- {
21
- style: "Downloading Map Style",
22
- sprites: "Downloading Sprites",
23
- tiles: "Downloading Tiles",
24
- glyphs: "Downloading Glyphs",
25
- output: "Writing Styled Map Package"
26
- }
27
- );
28
- const TASK_SUFFIX = (
29
- /** @type {{ [K in (typeof TASKS)[number]]: (progress: import('./download.js').DownloadProgress[K]) => string }} */
30
- {
31
- style: () => "",
32
- sprites: ({ downloaded }) => `${downloaded}`,
33
- tiles: ({ total, skipped, totalBytes, downloaded }) => {
34
- const formattedTotal = total.toLocaleString();
35
- const formattedCompleted = (downloaded + skipped).toLocaleString().padStart(formattedTotal.length);
36
- return `${formattedCompleted}/${formattedTotal} (${prettyBytes(totalBytes)})`;
37
- },
38
- glyphs: ({ total, downloaded, totalBytes }) => `${downloaded}/${total} (${prettyBytes(totalBytes)})`,
39
- output: ({ totalBytes }) => `${prettyBytes(totalBytes)}`
40
- }
41
- );
42
- function ttyReporter() {
43
- let stats;
44
- let current = 0;
45
- let spinner;
46
- return new Writable({
47
- objectMode: true,
48
- // @ts-ignore - missing type def
49
- construct(cb) {
50
- process.stderr.write("\n");
51
- spinner = ora(TASK_LABEL[TASKS[current]]).start();
52
- cb();
53
- },
54
- /** @param {ArrayLike<{ chunk: import('./download.js').DownloadProgress, encoding: string }>} chunks */
55
- writev(chunks, cb) {
56
- stats = chunks[chunks.length - 1].chunk;
57
- while (current < TASKS.length && stats[TASKS[current]].done) {
58
- spinner.suffixText = chalk.dim(
59
- TASK_SUFFIX[TASKS[current]](
60
- // @ts-ignore - too complicated for TS
61
- stats[TASKS[current]]
62
- )
63
- );
64
- spinner.succeed();
65
- if (++current < TASKS.length) {
66
- spinner = ora(TASK_LABEL[TASKS[current]]).start();
67
- }
68
- }
69
- if (current < TASKS.length) {
70
- spinner.suffixText = chalk.dim(
71
- TASK_SUFFIX[TASKS[current]](
72
- // @ts-ignore - too complicated for TS
73
- stats[TASKS[current]]
74
- )
75
- );
76
- } else {
77
- process.stderr.write(
78
- `${chalk.green(logSymbols.success)} Completed in ${prettyMilliseconds(stats.elapsedMs)}
79
- `
80
- );
81
- }
82
- cb();
83
- }
84
- });
85
- }
86
- export {
87
- ttyReporter
88
- };