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,312 @@
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 style_downloader_exports = {};
30
+ __export(style_downloader_exports, {
31
+ StyleDownloader: () => StyleDownloader
32
+ });
33
+ module.exports = __toCommonJS(style_downloader_exports);
34
+ var import_check_geojson = require("@placemarkio/check-geojson");
35
+ var import_filter_obj = require("filter-obj");
36
+ var import_ky = __toESM(require("ky"), 1);
37
+ var import_yocto_queue = __toESM(require("yocto-queue"), 1);
38
+ var import_zlib = __toESM(require("zlib"), 1);
39
+ var import_tile_downloader = require('./tile-downloader.cjs');
40
+ var import_fetch = require('./utils/fetch.cjs');
41
+ var import_mapbox = require('./utils/mapbox.cjs');
42
+ var import_misc = require('./utils/misc.cjs');
43
+ var import_style = require('./utils/style.cjs');
44
+ class StyleDownloader {
45
+ /** @type {null | string} */
46
+ #styleURL = null;
47
+ /** @type {null | StyleSpecification} */
48
+ #inputStyle = null;
49
+ /** @type {FetchQueue} */
50
+ #fetchQueue;
51
+ #mapboxAccessToken;
52
+ /**
53
+ * @param {string | StyleSpecification} style A url to a style JSON file or a style object
54
+ * @param {object} [opts]
55
+ * @param {number} [opts.concurrency=8]
56
+ * @param {string} [opts.mapboxAccessToken] Downloading a style from Mapbox requires an access token
57
+ */
58
+ constructor(style, { concurrency = 8, mapboxAccessToken } = {}) {
59
+ if (typeof style === "string") {
60
+ const { searchParams } = new URL(style);
61
+ this.#mapboxAccessToken = searchParams.get("access_token") || mapboxAccessToken;
62
+ this.#styleURL = (0, import_mapbox.normalizeStyleURL)(style, this.#mapboxAccessToken);
63
+ } else if ((0, import_style.validateStyle)(style)) {
64
+ this.#inputStyle = (0, import_misc.clone)(style);
65
+ } else {
66
+ throw new AggregateError(import_style.validateStyle.errors, "Invalid style");
67
+ }
68
+ this.#fetchQueue = new import_fetch.FetchQueue(concurrency);
69
+ }
70
+ /**
71
+ * Number of active downloads.
72
+ */
73
+ get active() {
74
+ return this.#fetchQueue.activeCount;
75
+ }
76
+ /**
77
+ * Download the style JSON for this style and inline the sources
78
+ *
79
+ * @returns {Promise<StyleInlinedSources>}
80
+ */
81
+ async getStyle() {
82
+ if (!this.#inputStyle && this.#styleURL) {
83
+ const downloadedStyle = await (0, import_ky.default)(this.#styleURL).json();
84
+ if (!(0, import_style.validateStyle)(downloadedStyle)) {
85
+ throw new AggregateError(
86
+ import_style.validateStyle.errors,
87
+ "Invalid style: " + this.#styleURL
88
+ );
89
+ }
90
+ this.#inputStyle = downloadedStyle;
91
+ } else if (!this.#inputStyle) {
92
+ throw new Error("Unexpected state: no style or style URL provided");
93
+ }
94
+ const inlinedSources = {};
95
+ for (const [sourceId, source] of Object.entries(this.#inputStyle.sources)) {
96
+ inlinedSources[sourceId] = await this.#getInlinedSource(source);
97
+ }
98
+ return {
99
+ ...this.#inputStyle,
100
+ sources: inlinedSources
101
+ };
102
+ }
103
+ /**
104
+ * @param {SourceSpecification} source
105
+ * @returns {Promise<InlinedSource>}
106
+ */
107
+ async #getInlinedSource(source) {
108
+ if ((0, import_style.isInlinedSource)(source)) {
109
+ return source;
110
+ }
111
+ if (source.type === "raster" || source.type === "vector" || source.type === "raster-dem") {
112
+ if (!source.url) {
113
+ throw new Error("Source is missing both url and tiles properties");
114
+ }
115
+ const sourceUrl = (0, import_mapbox.normalizeSourceURL)(source.url, this.#mapboxAccessToken);
116
+ const tilejson = await (0, import_ky.default)(sourceUrl).json();
117
+ (0, import_style.assertTileJSON)(tilejson);
118
+ return {
119
+ ...source,
120
+ ...(0, import_filter_obj.includeKeys)(tilejson, [
121
+ "bounds",
122
+ "maxzoom",
123
+ "minzoom",
124
+ "tiles",
125
+ "description",
126
+ "attribution",
127
+ "vector_layers"
128
+ ])
129
+ };
130
+ } else if (source.type === "geojson") {
131
+ if (typeof source.data !== "string") {
132
+ throw new Error("Unexpected data property for GeoJson source");
133
+ }
134
+ const geojsonUrl = (0, import_mapbox.normalizeSourceURL)(
135
+ source.data,
136
+ this.#mapboxAccessToken
137
+ );
138
+ const data = (0, import_check_geojson.check)(await (0, import_ky.default)(geojsonUrl).text());
139
+ return {
140
+ ...source,
141
+ data
142
+ };
143
+ }
144
+ return source;
145
+ }
146
+ /**
147
+ * Download the sprite PNGs and JSON files for this style. Returns an async
148
+ * generator of json and png readable streams, and the sprite id and pixel
149
+ * ratio. Downloads pixel ratios `1` and `2`.
150
+ *
151
+ * @returns {AsyncGenerator<{ json: import('stream').Readable, png: import('stream').Readable, id: string, pixelRatio: number }>}
152
+ */
153
+ async *getSprites() {
154
+ const style = await this.getStyle();
155
+ if (!style.sprite) return;
156
+ const accessToken = this.#mapboxAccessToken;
157
+ const spriteDefs = Array.isArray(style.sprite) ? style.sprite : [{ id: "default", url: style.sprite }];
158
+ for (const { id, url } of spriteDefs) {
159
+ for (const pixelRatio of [1, 2]) {
160
+ const format = pixelRatio === 1 ? "" : "@2x";
161
+ const jsonUrl = (0, import_mapbox.normalizeSpriteURL)(url, format, ".json", accessToken);
162
+ const pngUrl = (0, import_mapbox.normalizeSpriteURL)(url, format, ".png", accessToken);
163
+ const [{ body: json }, { body: png }] = await Promise.all([
164
+ this.#fetchQueue.fetch(jsonUrl),
165
+ this.#fetchQueue.fetch(pngUrl)
166
+ ]);
167
+ yield { json, png, id, pixelRatio };
168
+ }
169
+ }
170
+ }
171
+ /**
172
+ * Download all the glyphs for the fonts used in this style. When font stacks
173
+ * are used in the style.json (e.g. lists of prefered fonts like with CSS),
174
+ * then the first font in the stack is downloaded. Defaults to downloading all
175
+ * UTF character ranges, which may be overkill for some styles. TODO: add more
176
+ * options here.
177
+ *
178
+ * Returns an async generator of readable streams of glyph data and glyph info
179
+ * objects.
180
+ *
181
+ * @param {object} opts
182
+ * @param {(progress: GlyphDownloadStats) => void} [opts.onprogress]
183
+ * @returns {AsyncGenerator<[import('stream').Readable, GlyphInfo]>}
184
+ */
185
+ async *getGlyphs({ onprogress = import_misc.noop } = {}) {
186
+ const style = await this.getStyle();
187
+ if (!style.glyphs) return;
188
+ let completed = 0;
189
+ let stats = {
190
+ total: 0,
191
+ downloaded: 0,
192
+ totalBytes: 0
193
+ };
194
+ function onDownloadProgress({ chunkBytes }) {
195
+ stats.totalBytes += chunkBytes;
196
+ onprogress(stats);
197
+ }
198
+ function onDownloadComplete() {
199
+ stats.downloaded = ++completed;
200
+ onprogress(stats);
201
+ }
202
+ const queue = new import_yocto_queue.default();
203
+ const fontStacks = /* @__PURE__ */ new Map();
204
+ (0, import_style.mapFontStacks)(style.layers, (fontStack) => {
205
+ fontStacks.set(fontStack[0], fontStack.join(","));
206
+ return [];
207
+ });
208
+ const glyphUrl = (0, import_mapbox.normalizeGlyphsURL)(style.glyphs, this.#mapboxAccessToken);
209
+ for (const [font, fontStack] of fontStacks.entries()) {
210
+ for (let i = 0; i < Math.pow(2, 16); i += 256) {
211
+ const range = `${i}-${i + 255}`;
212
+ const url = glyphUrl.replace("{fontstack}", fontStack).replace("{range}", range);
213
+ const result = this.#fetchQueue.fetch(url, { onprogress: onDownloadProgress }).catch(import_misc.noop);
214
+ queue.enqueue([result, { font, range }]);
215
+ }
216
+ }
217
+ stats.total = queue.size;
218
+ if (onprogress) onprogress(stats);
219
+ for (const [result, glyphInfo] of queue) {
220
+ const downloadResponse = await result.catch(import_misc.noop);
221
+ if (!downloadResponse) continue;
222
+ const { body } = downloadResponse;
223
+ const gzipper = import_zlib.default.createGzip();
224
+ body.on("error", (err) => gzipper.destroy(err));
225
+ body.on("end", onDownloadComplete);
226
+ yield [body.pipe(gzipper), glyphInfo];
227
+ }
228
+ }
229
+ /**
230
+ * Get all the tiles for this style within the given bounds and zoom range.
231
+ * Returns an async generator of readable streams of tile data and tile info
232
+ * objects.
233
+ *
234
+ * The returned iterator also has a `skipped` property which is an
235
+ * array of tiles which could not be downloaded, and a `stats` property which
236
+ * is an object with the total number of tiles, downloaded tiles, and total
237
+ * bytes downloaded.
238
+ *
239
+ * @param {object} opts
240
+ * @param {import('./utils/geo.js').BBox} opts.bounds
241
+ * @param {number} opts.maxzoom
242
+ * @param {(progress: TileDownloadStats) => void} [opts.onprogress]
243
+ * @param {boolean} [opts.trackErrors=false] Include errors in the returned array of skipped tiles - this has memory overhead so should only be used for debugging.
244
+ * @returns {AsyncGenerator<[import('stream').Readable, TileInfo]> & { readonly skipped: Array<TileInfo & { error?: Error }>, readonly stats: TileDownloadStats }}
245
+ */
246
+ getTiles({ bounds, maxzoom, onprogress = import_misc.noop, trackErrors = false }) {
247
+ const _this = this;
248
+ const skipped = [];
249
+ let stats = {
250
+ total: 0,
251
+ downloaded: 0,
252
+ skipped: 0,
253
+ totalBytes: 0
254
+ };
255
+ const tiles = async function* () {
256
+ const inlinedStyle = await _this.getStyle();
257
+ for await (const [sourceId, source] of Object.entries(
258
+ inlinedStyle.sources
259
+ )) {
260
+ if (source.type !== "raster" && source.type !== "vector") {
261
+ continue;
262
+ }
263
+ const statsBaseline = { ...stats };
264
+ const sourceTiles = (0, import_tile_downloader.downloadTiles)({
265
+ tileUrls: source.tiles,
266
+ bounds,
267
+ maxzoom: Math.min(maxzoom, source.maxzoom || maxzoom),
268
+ minzoom: source.minzoom,
269
+ sourceBounds: source.bounds,
270
+ boundsBuffer: true,
271
+ scheme: source.scheme,
272
+ fetchQueue: _this.#fetchQueue,
273
+ onprogress: (sourceStats) => {
274
+ stats = addStats(statsBaseline, sourceStats);
275
+ onprogress(stats);
276
+ },
277
+ trackErrors
278
+ });
279
+ for await (const [tileDataStream, tileInfo] of sourceTiles) {
280
+ yield [tileDataStream, { ...tileInfo, sourceId }];
281
+ }
282
+ Array.prototype.push.apply(
283
+ skipped,
284
+ sourceTiles.skipped.map((tile) => ({ ...tile, sourceId }))
285
+ );
286
+ }
287
+ }();
288
+ Object.defineProperty(tiles, "skipped", {
289
+ get() {
290
+ return skipped;
291
+ }
292
+ });
293
+ Object.defineProperty(tiles, "stats", {
294
+ get() {
295
+ return stats;
296
+ }
297
+ });
298
+ return tiles;
299
+ }
300
+ }
301
+ function addStats(statsA, statsB) {
302
+ return {
303
+ total: statsA.total + statsB.total,
304
+ downloaded: statsA.downloaded + statsB.downloaded,
305
+ skipped: statsA.skipped + statsB.skipped,
306
+ totalBytes: statsA.totalBytes + statsB.totalBytes
307
+ };
308
+ }
309
+ // Annotate the CommonJS export names for ESM import in node:
310
+ 0 && (module.exports = {
311
+ StyleDownloader
312
+ });
@@ -0,0 +1,120 @@
1
+ import * as ky from 'ky';
2
+ import { BBox } from './utils/geo.cjs';
3
+ import * as stream from 'stream';
4
+ import { b as StyleInlinedSources, G as GlyphInfo, T as TileInfo } from './types-B4Xn1F9K.cjs';
5
+ import { TileDownloadStats } from './tile-downloader.cjs';
6
+ import { StyleSpecification } from '@maplibre/maplibre-gl-style-spec';
7
+ import 'geojson';
8
+ import 'type-fest';
9
+ import 'readable-stream';
10
+ import 'events';
11
+ import './utils/fetch.cjs';
12
+ import './utils/streams.cjs';
13
+
14
+ /** @import { SourceSpecification, StyleSpecification } from '@maplibre/maplibre-gl-style-spec' */
15
+ /** @import { TileInfo, GlyphInfo, GlyphRange } from './writer.js' */
16
+ /** @import { TileDownloadStats } from './tile-downloader.js' */
17
+ /** @import { StyleInlinedSources, InlinedSource } from './types.js'*/
18
+ /** @typedef { import('ky').ResponsePromise & { body: ReadableStream<Uint8Array> } } ResponsePromise */
19
+ /** @import { DownloadResponse } from './utils/fetch.js' */
20
+ /**
21
+ * @typedef {object} GlyphDownloadStats
22
+ * @property {number} total
23
+ * @property {number} downloaded
24
+ * @property {number} totalBytes
25
+ */
26
+ /**
27
+ * Download a style and its resources for offline use. Please check the terms of
28
+ * service of the map provider you are using before downloading any resources.
29
+ */
30
+ declare class StyleDownloader {
31
+ /**
32
+ * @param {string | StyleSpecification} style A url to a style JSON file or a style object
33
+ * @param {object} [opts]
34
+ * @param {number} [opts.concurrency=8]
35
+ * @param {string} [opts.mapboxAccessToken] Downloading a style from Mapbox requires an access token
36
+ */
37
+ constructor(style: string | StyleSpecification, { concurrency, mapboxAccessToken }?: {
38
+ concurrency?: number | undefined;
39
+ mapboxAccessToken?: string | undefined;
40
+ });
41
+ /**
42
+ * Number of active downloads.
43
+ */
44
+ get active(): number;
45
+ /**
46
+ * Download the style JSON for this style and inline the sources
47
+ *
48
+ * @returns {Promise<StyleInlinedSources>}
49
+ */
50
+ getStyle(): Promise<StyleInlinedSources>;
51
+ /**
52
+ * Download the sprite PNGs and JSON files for this style. Returns an async
53
+ * generator of json and png readable streams, and the sprite id and pixel
54
+ * ratio. Downloads pixel ratios `1` and `2`.
55
+ *
56
+ * @returns {AsyncGenerator<{ json: import('stream').Readable, png: import('stream').Readable, id: string, pixelRatio: number }>}
57
+ */
58
+ getSprites(): AsyncGenerator<{
59
+ json: stream.Readable;
60
+ png: stream.Readable;
61
+ id: string;
62
+ pixelRatio: number;
63
+ }>;
64
+ /**
65
+ * Download all the glyphs for the fonts used in this style. When font stacks
66
+ * are used in the style.json (e.g. lists of prefered fonts like with CSS),
67
+ * then the first font in the stack is downloaded. Defaults to downloading all
68
+ * UTF character ranges, which may be overkill for some styles. TODO: add more
69
+ * options here.
70
+ *
71
+ * Returns an async generator of readable streams of glyph data and glyph info
72
+ * objects.
73
+ *
74
+ * @param {object} opts
75
+ * @param {(progress: GlyphDownloadStats) => void} [opts.onprogress]
76
+ * @returns {AsyncGenerator<[import('stream').Readable, GlyphInfo]>}
77
+ */
78
+ getGlyphs({ onprogress }?: {
79
+ onprogress?: ((progress: GlyphDownloadStats) => void) | undefined;
80
+ }): AsyncGenerator<[stream.Readable, GlyphInfo]>;
81
+ /**
82
+ * Get all the tiles for this style within the given bounds and zoom range.
83
+ * Returns an async generator of readable streams of tile data and tile info
84
+ * objects.
85
+ *
86
+ * The returned iterator also has a `skipped` property which is an
87
+ * array of tiles which could not be downloaded, and a `stats` property which
88
+ * is an object with the total number of tiles, downloaded tiles, and total
89
+ * bytes downloaded.
90
+ *
91
+ * @param {object} opts
92
+ * @param {import('./utils/geo.js').BBox} opts.bounds
93
+ * @param {number} opts.maxzoom
94
+ * @param {(progress: TileDownloadStats) => void} [opts.onprogress]
95
+ * @param {boolean} [opts.trackErrors=false] Include errors in the returned array of skipped tiles - this has memory overhead so should only be used for debugging.
96
+ * @returns {AsyncGenerator<[import('stream').Readable, TileInfo]> & { readonly skipped: Array<TileInfo & { error?: Error }>, readonly stats: TileDownloadStats }}
97
+ */
98
+ getTiles({ bounds, maxzoom, onprogress, trackErrors }: {
99
+ bounds: BBox;
100
+ maxzoom: number;
101
+ onprogress?: ((progress: TileDownloadStats) => void) | undefined;
102
+ trackErrors?: boolean | undefined;
103
+ }): AsyncGenerator<[stream.Readable, TileInfo]> & {
104
+ readonly skipped: Array<TileInfo & {
105
+ error?: Error;
106
+ }>;
107
+ readonly stats: TileDownloadStats;
108
+ };
109
+ #private;
110
+ }
111
+ type ResponsePromise = ky.ResponsePromise & {
112
+ body: ReadableStream<Uint8Array>;
113
+ };
114
+ type GlyphDownloadStats = {
115
+ total: number;
116
+ downloaded: number;
117
+ totalBytes: number;
118
+ };
119
+
120
+ export { type GlyphDownloadStats, type ResponsePromise, StyleDownloader };
@@ -1,3 +1,16 @@
1
+ import * as ky from 'ky';
2
+ import { BBox } from './utils/geo.js';
3
+ import * as stream from 'stream';
4
+ import { b as StyleInlinedSources, G as GlyphInfo, T as TileInfo } from './types-B4Xn1F9K.js';
5
+ import { TileDownloadStats } from './tile-downloader.js';
6
+ import { StyleSpecification } from '@maplibre/maplibre-gl-style-spec';
7
+ import 'geojson';
8
+ import 'type-fest';
9
+ import 'readable-stream';
10
+ import 'events';
11
+ import './utils/fetch.js';
12
+ import './utils/streams.js';
13
+
1
14
  /** @import { SourceSpecification, StyleSpecification } from '@maplibre/maplibre-gl-style-spec' */
2
15
  /** @import { TileInfo, GlyphInfo, GlyphRange } from './writer.js' */
3
16
  /** @import { TileDownloadStats } from './tile-downloader.js' */
@@ -14,7 +27,7 @@
14
27
  * Download a style and its resources for offline use. Please check the terms of
15
28
  * service of the map provider you are using before downloading any resources.
16
29
  */
17
- export default class StyleDownloader {
30
+ declare class StyleDownloader {
18
31
  /**
19
32
  * @param {string | StyleSpecification} style A url to a style JSON file or a style object
20
33
  * @param {object} [opts]
@@ -43,8 +56,8 @@ export default class StyleDownloader {
43
56
  * @returns {AsyncGenerator<{ json: import('stream').Readable, png: import('stream').Readable, id: string, pixelRatio: number }>}
44
57
  */
45
58
  getSprites(): AsyncGenerator<{
46
- json: import("stream").Readable;
47
- png: import("stream").Readable;
59
+ json: stream.Readable;
60
+ png: stream.Readable;
48
61
  id: string;
49
62
  pixelRatio: number;
50
63
  }>;
@@ -64,7 +77,7 @@ export default class StyleDownloader {
64
77
  */
65
78
  getGlyphs({ onprogress }?: {
66
79
  onprogress?: ((progress: GlyphDownloadStats) => void) | undefined;
67
- }): AsyncGenerator<[import("stream").Readable, GlyphInfo]>;
80
+ }): AsyncGenerator<[stream.Readable, GlyphInfo]>;
68
81
  /**
69
82
  * Get all the tiles for this style within the given bounds and zoom range.
70
83
  * Returns an async generator of readable streams of tile data and tile info
@@ -83,11 +96,11 @@ export default class StyleDownloader {
83
96
  * @returns {AsyncGenerator<[import('stream').Readable, TileInfo]> & { readonly skipped: Array<TileInfo & { error?: Error }>, readonly stats: TileDownloadStats }}
84
97
  */
85
98
  getTiles({ bounds, maxzoom, onprogress, trackErrors }: {
86
- bounds: import("./utils/geo.js").BBox;
99
+ bounds: BBox;
87
100
  maxzoom: number;
88
101
  onprogress?: ((progress: TileDownloadStats) => void) | undefined;
89
102
  trackErrors?: boolean | undefined;
90
- }): AsyncGenerator<[import("stream").Readable, TileInfo]> & {
103
+ }): AsyncGenerator<[stream.Readable, TileInfo]> & {
91
104
  readonly skipped: Array<TileInfo & {
92
105
  error?: Error;
93
106
  }>;
@@ -95,16 +108,13 @@ export default class StyleDownloader {
95
108
  };
96
109
  #private;
97
110
  }
98
- export type ResponsePromise = import("ky").ResponsePromise & {
111
+ type ResponsePromise = ky.ResponsePromise & {
99
112
  body: ReadableStream<Uint8Array>;
100
113
  };
101
- export type GlyphDownloadStats = {
114
+ type GlyphDownloadStats = {
102
115
  total: number;
103
116
  downloaded: number;
104
117
  totalBytes: number;
105
118
  };
106
- import type { StyleInlinedSources } from './types.js';
107
- import type { GlyphInfo } from './writer.js';
108
- import type { TileDownloadStats } from './tile-downloader.js';
109
- import type { TileInfo } from './writer.js';
110
- import type { StyleSpecification } from '@maplibre/maplibre-gl-style-spec';
119
+
120
+ export { type GlyphDownloadStats, type ResponsePromise, StyleDownloader };