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,84 +0,0 @@
1
- import { T as TileInfo$1 } from './types-B4Xn1F9K.cjs';
2
- import * as stream from 'stream';
3
- import { BBox } from './utils/geo.cjs';
4
- import { FetchQueue } from './utils/fetch.cjs';
5
- import '@maplibre/maplibre-gl-style-spec';
6
- import 'geojson';
7
- import 'type-fest';
8
- import 'readable-stream';
9
- import 'events';
10
- import './utils/streams.cjs';
11
-
12
- /** @typedef {Omit<import('./writer.js').TileInfo, 'sourceId'>} TileInfo */
13
- /**
14
- * @typedef {object} TileDownloadStats
15
- * @property {number} total
16
- * @property {number} downloaded
17
- * @property {number} skipped
18
- * @property {number} totalBytes
19
- */
20
- /**
21
- * Download tiles from a list of tile URLs within a bounding box and zoom range.
22
- * Returns an async generator of tile data as readable streams and tile info objects.
23
- *
24
- * @param {object} opts
25
- * @param {string[]} opts.tileUrls Array of tile URL templates. Use `{x}`, `{y}`, `{z}` placeholders, and optional `{scheme}` placeholder which can be `xyz` or `tms`.
26
- * @param {import('./utils/geo.js').BBox} opts.bounds Bounding box of the area to download
27
- * @param {number} opts.maxzoom Maximum zoom level to download
28
- * @param {(progress: TileDownloadStats) => void} [opts.onprogress] Callback to report download progress
29
- * @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.
30
- * @param {import('./utils/geo.js').BBox} [opts.sourceBounds=MAX_BOUNDS] Bounding box of source data.
31
- * @param {boolean} [opts.boundsBuffer=false] Buffer the bounds by one tile at each zoom level to ensure no tiles are missed at the edges. With this set to false, in most instances the map will appear incomplete when viewed because the downloaded tiles at lower zoom levels will not cover the map view area.
32
- * @param {number} [opts.minzoom=0] Minimum zoom level to download (for most cases this should be left as `0` - the size overhead is minimal, because each zoom level has 4x as many tiles)
33
- * @param {number} [opts.concurrency=8] Number of concurrent downloads (ignored if `fetchQueue` is provided)
34
- * @param {FetchQueue} [opts.fetchQueue=new FetchQueue(concurrency)] Optional fetch queue to use for downloading tiles
35
- * @param {'xyz' | 'tms'} [opts.scheme='xyz'] Tile scheme to use for tile URLs
36
- * @returns {AsyncGenerator<[import('stream').Readable, TileInfo]> & { readonly skipped: Array<TileInfo & { error?: Error }>, readonly stats: TileDownloadStats }}
37
- */
38
- declare function downloadTiles({ tileUrls, bounds, maxzoom, onprogress, trackErrors, sourceBounds, boundsBuffer, minzoom, concurrency, fetchQueue, scheme, }: {
39
- tileUrls: string[];
40
- bounds: BBox;
41
- maxzoom: number;
42
- onprogress?: ((progress: TileDownloadStats) => void) | undefined;
43
- trackErrors?: boolean | undefined;
44
- sourceBounds?: BBox | undefined;
45
- boundsBuffer?: boolean | undefined;
46
- minzoom?: number | undefined;
47
- concurrency?: number | undefined;
48
- fetchQueue?: FetchQueue | undefined;
49
- scheme?: "xyz" | "tms" | undefined;
50
- }): AsyncGenerator<[stream.Readable, TileInfo]> & {
51
- readonly skipped: Array<TileInfo & {
52
- error?: Error;
53
- }>;
54
- readonly stats: TileDownloadStats;
55
- };
56
- /**
57
- *
58
- * @param {object} opts
59
- * @param {import('./utils/geo.js').BBox} [opts.bounds]
60
- * @param {import('./utils/geo.js').BBox} [opts.sourceBounds]
61
- * @param {boolean} [opts.boundsBuffer]
62
- * @param {number} [opts.minzoom]
63
- * @param {number} opts.maxzoom
64
- */
65
- declare function tileIterator({ bounds, minzoom, maxzoom, sourceBounds, boundsBuffer, }: {
66
- bounds?: BBox | undefined;
67
- sourceBounds?: BBox | undefined;
68
- boundsBuffer?: boolean | undefined;
69
- minzoom?: number | undefined;
70
- maxzoom: number;
71
- }): Generator<{
72
- x: number;
73
- y: number;
74
- z: number;
75
- }, void, unknown>;
76
- type TileInfo = Omit<TileInfo$1, "sourceId">;
77
- type TileDownloadStats = {
78
- total: number;
79
- downloaded: number;
80
- skipped: number;
81
- totalBytes: number;
82
- };
83
-
84
- export { type TileDownloadStats, type TileInfo, downloadTiles, tileIterator };
@@ -1,84 +0,0 @@
1
- import { T as TileInfo$1 } from './types-B4Xn1F9K.js';
2
- import * as stream from 'stream';
3
- import { BBox } from './utils/geo.js';
4
- import { FetchQueue } from './utils/fetch.js';
5
- import '@maplibre/maplibre-gl-style-spec';
6
- import 'geojson';
7
- import 'type-fest';
8
- import 'readable-stream';
9
- import 'events';
10
- import './utils/streams.js';
11
-
12
- /** @typedef {Omit<import('./writer.js').TileInfo, 'sourceId'>} TileInfo */
13
- /**
14
- * @typedef {object} TileDownloadStats
15
- * @property {number} total
16
- * @property {number} downloaded
17
- * @property {number} skipped
18
- * @property {number} totalBytes
19
- */
20
- /**
21
- * Download tiles from a list of tile URLs within a bounding box and zoom range.
22
- * Returns an async generator of tile data as readable streams and tile info objects.
23
- *
24
- * @param {object} opts
25
- * @param {string[]} opts.tileUrls Array of tile URL templates. Use `{x}`, `{y}`, `{z}` placeholders, and optional `{scheme}` placeholder which can be `xyz` or `tms`.
26
- * @param {import('./utils/geo.js').BBox} opts.bounds Bounding box of the area to download
27
- * @param {number} opts.maxzoom Maximum zoom level to download
28
- * @param {(progress: TileDownloadStats) => void} [opts.onprogress] Callback to report download progress
29
- * @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.
30
- * @param {import('./utils/geo.js').BBox} [opts.sourceBounds=MAX_BOUNDS] Bounding box of source data.
31
- * @param {boolean} [opts.boundsBuffer=false] Buffer the bounds by one tile at each zoom level to ensure no tiles are missed at the edges. With this set to false, in most instances the map will appear incomplete when viewed because the downloaded tiles at lower zoom levels will not cover the map view area.
32
- * @param {number} [opts.minzoom=0] Minimum zoom level to download (for most cases this should be left as `0` - the size overhead is minimal, because each zoom level has 4x as many tiles)
33
- * @param {number} [opts.concurrency=8] Number of concurrent downloads (ignored if `fetchQueue` is provided)
34
- * @param {FetchQueue} [opts.fetchQueue=new FetchQueue(concurrency)] Optional fetch queue to use for downloading tiles
35
- * @param {'xyz' | 'tms'} [opts.scheme='xyz'] Tile scheme to use for tile URLs
36
- * @returns {AsyncGenerator<[import('stream').Readable, TileInfo]> & { readonly skipped: Array<TileInfo & { error?: Error }>, readonly stats: TileDownloadStats }}
37
- */
38
- declare function downloadTiles({ tileUrls, bounds, maxzoom, onprogress, trackErrors, sourceBounds, boundsBuffer, minzoom, concurrency, fetchQueue, scheme, }: {
39
- tileUrls: string[];
40
- bounds: BBox;
41
- maxzoom: number;
42
- onprogress?: ((progress: TileDownloadStats) => void) | undefined;
43
- trackErrors?: boolean | undefined;
44
- sourceBounds?: BBox | undefined;
45
- boundsBuffer?: boolean | undefined;
46
- minzoom?: number | undefined;
47
- concurrency?: number | undefined;
48
- fetchQueue?: FetchQueue | undefined;
49
- scheme?: "xyz" | "tms" | undefined;
50
- }): AsyncGenerator<[stream.Readable, TileInfo]> & {
51
- readonly skipped: Array<TileInfo & {
52
- error?: Error;
53
- }>;
54
- readonly stats: TileDownloadStats;
55
- };
56
- /**
57
- *
58
- * @param {object} opts
59
- * @param {import('./utils/geo.js').BBox} [opts.bounds]
60
- * @param {import('./utils/geo.js').BBox} [opts.sourceBounds]
61
- * @param {boolean} [opts.boundsBuffer]
62
- * @param {number} [opts.minzoom]
63
- * @param {number} opts.maxzoom
64
- */
65
- declare function tileIterator({ bounds, minzoom, maxzoom, sourceBounds, boundsBuffer, }: {
66
- bounds?: BBox | undefined;
67
- sourceBounds?: BBox | undefined;
68
- boundsBuffer?: boolean | undefined;
69
- minzoom?: number | undefined;
70
- maxzoom: number;
71
- }): Generator<{
72
- x: number;
73
- y: number;
74
- z: number;
75
- }, void, unknown>;
76
- type TileInfo = Omit<TileInfo$1, "sourceId">;
77
- type TileDownloadStats = {
78
- total: number;
79
- downloaded: number;
80
- skipped: number;
81
- totalBytes: number;
82
- };
83
-
84
- export { type TileDownloadStats, type TileInfo, downloadTiles, tileIterator };
@@ -1,126 +0,0 @@
1
- import SphericalMercator from "@mapbox/sphericalmercator";
2
- import Queue from "yocto-queue";
3
- import zlib from "zlib";
4
- import { FetchQueue } from "./utils/fetch.js";
5
- import {
6
- getFormatFromMimeType,
7
- getTileFormatFromStream
8
- } from "./utils/file-formats.js";
9
- import { getTileUrl, MAX_BOUNDS } from "./utils/geo.js";
10
- import { noop } from "./utils/misc.js";
11
- function downloadTiles({
12
- tileUrls,
13
- bounds,
14
- maxzoom,
15
- onprogress = noop,
16
- trackErrors = false,
17
- sourceBounds = MAX_BOUNDS,
18
- boundsBuffer = false,
19
- minzoom = 0,
20
- concurrency = 8,
21
- fetchQueue = new FetchQueue(concurrency),
22
- scheme = "xyz"
23
- }) {
24
- const skipped = [];
25
- let completed = 0;
26
- let stats = {
27
- total: 0,
28
- downloaded: 0,
29
- skipped: 0,
30
- totalBytes: 0
31
- };
32
- function onDownloadProgress({ chunkBytes }) {
33
- stats.totalBytes += chunkBytes;
34
- onprogress(stats);
35
- }
36
- function onDownloadError(error, tileInfo) {
37
- if (trackErrors) {
38
- skipped.push({ ...tileInfo, error });
39
- } else {
40
- skipped.push(tileInfo);
41
- }
42
- onprogress(stats);
43
- }
44
- function onDownloadComplete() {
45
- stats.downloaded = ++completed - skipped.length;
46
- stats.skipped = skipped.length;
47
- onprogress(stats);
48
- }
49
- const tiles = async function* () {
50
- const queue = new Queue();
51
- const tiles2 = tileIterator({
52
- bounds,
53
- minzoom,
54
- maxzoom,
55
- sourceBounds,
56
- boundsBuffer
57
- });
58
- for (const { x, y, z } of tiles2) {
59
- const tileURL = getTileUrl(tileUrls, { x, y, z, scheme });
60
- const tileInfo = { z, x, y };
61
- const result = fetchQueue.fetch(tileURL, { onprogress: onDownloadProgress }).catch((err) => onDownloadError(err, tileInfo));
62
- queue.enqueue([result, tileInfo]);
63
- }
64
- stats.total = queue.size;
65
- if (onprogress) onprogress(stats);
66
- for (const [result, tileInfo] of queue) {
67
- const downloadResponse = await result.catch(noop);
68
- if (!downloadResponse) continue;
69
- let { body, mimeType } = downloadResponse;
70
- body.on("end", onDownloadComplete);
71
- body.on("error", (err) => onDownloadError(err, tileInfo));
72
- let format;
73
- if (mimeType) {
74
- format = getFormatFromMimeType(mimeType);
75
- } else {
76
- ;
77
- [format, body] = await getTileFormatFromStream(body);
78
- }
79
- let stream = body;
80
- if (format === "mvt") {
81
- const gzipStream = zlib.createGzip();
82
- stream = body.pipe(gzipStream);
83
- stream.on("error", (err) => gzipStream.destroy(err));
84
- }
85
- yield [stream, { ...tileInfo, format }];
86
- }
87
- }();
88
- Object.defineProperty(tiles, "skipped", {
89
- get() {
90
- return skipped;
91
- }
92
- });
93
- Object.defineProperty(tiles, "stats", {
94
- get() {
95
- return stats;
96
- }
97
- });
98
- return tiles;
99
- }
100
- function* tileIterator({
101
- bounds = [...MAX_BOUNDS],
102
- minzoom = 0,
103
- maxzoom,
104
- sourceBounds,
105
- boundsBuffer = false
106
- }) {
107
- const sm = new SphericalMercator({ size: 256 });
108
- for (let z = minzoom; z <= maxzoom; z++) {
109
- let { minX, minY, maxX, maxY } = sm.xyz([...bounds], z);
110
- let sourceXYBounds = sourceBounds ? sm.xyz([...sourceBounds], z) : { minX, minY, maxX, maxY };
111
- const buffer = boundsBuffer ? 1 : 0;
112
- minX = Math.max(0, minX - buffer, sourceXYBounds.minX);
113
- minY = Math.max(0, minY - buffer, sourceXYBounds.minY);
114
- maxX = Math.min(Math.pow(2, z) - 1, maxX + buffer, sourceXYBounds.maxX);
115
- maxY = Math.min(Math.pow(2, z) - 1, maxY + buffer, sourceXYBounds.maxY);
116
- for (let x = minX; x <= maxX; x++) {
117
- for (let y = minY; y <= maxY; y++) {
118
- yield { x, y, z };
119
- }
120
- }
121
- }
122
- }
123
- export {
124
- downloadTiles,
125
- tileIterator
126
- };
@@ -1,189 +0,0 @@
1
- import { SourceSpecification, GeoJSONSourceSpecification, VectorSourceSpecification, RasterSourceSpecification, RasterDEMSourceSpecification, StyleSpecification } from '@maplibre/maplibre-gl-style-spec';
2
- import { GeoJSON, BBox } from 'geojson';
3
- import * as stream from 'stream';
4
- import { Readable } from 'stream';
5
- import { SetRequired } from 'type-fest';
6
- import * as readable_stream from 'readable-stream';
7
- import { EventEmitter } from 'events';
8
-
9
- /** @typedef {string | Buffer | Uint8Array | import('stream').Readable } Source */
10
- /** @typedef {string | Buffer | import('stream').Readable} SourceInternal */
11
- /** @typedef {`${number}-${number}`} GlyphRange */
12
- /** @typedef {'png' | 'mvt' | 'jpg' | 'webp'} TileFormat */
13
- /**
14
- * @typedef {object} SourceInfo
15
- * @property {import('./types.js').SMPSource} source
16
- * @property {string} encodedSourceId
17
- * @property {TileFormat} [format]
18
- */
19
- /**
20
- * @typedef {object} TileInfo
21
- * @property {number} z
22
- * @property {number} x
23
- * @property {number} y
24
- * @property {string} sourceId
25
- * @property {TileFormat} [format]
26
- */
27
- /**
28
- * @typedef {object} GlyphInfo
29
- * @property {string} font
30
- * @property {GlyphRange} range
31
- */
32
- /** @import { StyleSpecification } from '@maplibre/maplibre-gl-style-spec' */
33
- /** @import { InputSource, SMPSource } from './types.js' */
34
- declare const SUPPORTED_SOURCE_TYPES: readonly ["raster", "vector", "geojson"];
35
- /**
36
- * Write a styled map package to a stream. Stream `writer.outputStream` to a
37
- * destination, e.g. `fs.createWriteStream('my-map.styledmap')`. You must call
38
- * `witer.finish()` and then wait for your writable stream to `finish` before
39
- * using the output.
40
- */
41
- declare class Writer extends EventEmitter<[never]> {
42
- static SUPPORTED_SOURCE_TYPES: readonly ["raster", "vector", "geojson"];
43
- /**
44
- * @param {any} style A v7 or v8 MapLibre style. v7 styles will be migrated to
45
- * v8. (There are currently no typescript declarations for v7 styles, hence
46
- * this is typed as `any` and validated internally)
47
- * @param {object} opts
48
- * @param {number} [opts.highWaterMark=1048576] The maximum number of bytes to buffer during write
49
- */
50
- constructor(style: any, { highWaterMark }?: {
51
- highWaterMark?: number | undefined;
52
- });
53
- /**
54
- * @returns {import('stream').Readable} Readable stream of the styled map package
55
- */
56
- get outputStream(): stream.Readable;
57
- /**
58
- * Add a tile to the styled map package
59
- *
60
- * @param {Source} tileData
61
- * @param {TileInfo} opts
62
- */
63
- addTile(tileData: Source, { z, x, y, sourceId, format }: TileInfo): Promise<void>;
64
- /**
65
- * Create a write stream for adding tiles to the styled map package
66
- *
67
- * @param {object} opts
68
- * @param {number} [opts.concurrency=16] The number of concurrent writes
69
- *
70
- * @returns
71
- */
72
- createTileWriteStream({ concurrency }?: {
73
- concurrency?: number | undefined;
74
- }): readable_stream.Writable;
75
- /**
76
- * Add a sprite to the styled map package
77
- *
78
- * @param {object} options
79
- * @param {Source} options.json
80
- * @param {Source} options.png
81
- * @param {number} [options.pixelRatio]
82
- * @param {string} [options.id='default']
83
- * @returns {Promise<void>}
84
- */
85
- addSprite({ json, png, pixelRatio, id }: {
86
- json: Source;
87
- png: Source;
88
- pixelRatio?: number | undefined;
89
- id?: string | undefined;
90
- }): Promise<void>;
91
- /**
92
- * Add glyphs to the styled map package
93
- *
94
- * @param {Source} glyphData
95
- * @param {GlyphInfo} glyphInfo
96
- * @returns {Promise<void>}
97
- */
98
- addGlyphs(glyphData: Source, { font: fontName, range }: GlyphInfo): Promise<void>;
99
- /**
100
- * Create a write stream for adding glyphs to the styled map package
101
- *
102
- * @param {object} opts
103
- * @param {number} [opts.concurrency=16] The number of concurrent writes
104
- * @returns
105
- */
106
- createGlyphWriteStream({ concurrency }?: {
107
- concurrency?: number | undefined;
108
- }): readable_stream.Writable;
109
- /**
110
- * Finalize the styled map package and write the style to the archive.
111
- * This method must be called to complete the archive.
112
- * You must wait for your destination write stream to 'finish' before using the output.
113
- */
114
- finish(): void;
115
- #private;
116
- }
117
- type Source = string | Buffer | Uint8Array | stream.Readable;
118
- type SourceInternal = string | Buffer | stream.Readable;
119
- type GlyphRange = `${number}-${number}`;
120
- type TileFormat = "png" | "mvt" | "jpg" | "webp";
121
- type SourceInfo = {
122
- source: SMPSource;
123
- encodedSourceId: string;
124
- format?: TileFormat | undefined;
125
- };
126
- type TileInfo = {
127
- z: number;
128
- x: number;
129
- y: number;
130
- sourceId: string;
131
- format?: TileFormat | undefined;
132
- };
133
- type GlyphInfo = {
134
- font: string;
135
- range: GlyphRange;
136
- };
137
-
138
- type TransformInlinedSource<T extends SourceSpecification> = T extends GeoJSONSourceSpecification ? OmitUnion<T, 'data'> & {
139
- data: GeoJSON;
140
- } : T extends VectorSourceSpecification | RasterSourceSpecification | RasterDEMSourceSpecification ? SetRequired<OmitUnion<T, 'url'>, 'tiles'> : T;
141
- /**
142
- * This is a slightly stricter version of SourceSpecification that requires
143
- * sources to be inlined (e.g. no urls to TileJSON or GeoJSON files).
144
- */
145
- type InlinedSource = TransformInlinedSource<SourceSpecification>;
146
- type SupportedInlinedSource = Extract<InlinedSource, {
147
- type: (typeof SUPPORTED_SOURCE_TYPES)[number];
148
- }>;
149
- /**
150
- * This is a slightly stricter version of StyleSpecification that requires
151
- * sources to be inlined (e.g. no urls to TileJSON or GeoJSON files).
152
- */
153
- type StyleInlinedSources = Omit<StyleSpecification, 'sources'> & {
154
- sources: {
155
- [_: string]: InlinedSource;
156
- };
157
- };
158
- type SMPSource = TransformSMPInputSource<SupportedInlinedSource>;
159
- /**
160
- * This is a slightly stricter version of StyleSpecification that is provided in
161
- * a Styled Map Package. Tile sources must have tile URLs inlined (they cannot
162
- * refer to a TileJSON url), and they must have bounds, minzoom, and maxzoom.
163
- * GeoJSON sources must have inlined GeoJSON (not a URL to a GeoJSON file).
164
- */
165
- type SMPStyle = TransformSMPStyle<StyleSpecification>;
166
- type TransformSMPInputSource<T extends SupportedInlinedSource> = T extends GeoJSONSourceSpecification ? T & {
167
- data: {
168
- bbox: BBox;
169
- };
170
- } : T extends RasterSourceSpecification | VectorSourceSpecification ? SetRequired<T, 'bounds' | 'minzoom' | 'maxzoom'> : T;
171
- type TransformSMPStyle<T extends StyleSpecification> = Omit<T, 'sources'> & {
172
- metadata: {
173
- 'smp:bounds': [number, number, number, number];
174
- 'smp:maxzoom': 0;
175
- 'smp:sourceFolders': {
176
- [_: string]: string;
177
- };
178
- };
179
- sources: {
180
- [_: string]: SMPSource;
181
- };
182
- };
183
- interface DownloadStream extends Readable {
184
- iterator(...args: Parameters<Readable['iterator']>): AsyncIterableIterator<Buffer>;
185
- [Symbol.asyncIterator](): AsyncIterableIterator<Buffer>;
186
- }
187
- type OmitUnion<T, K extends keyof any> = T extends unknown ? Omit<T, K> : never;
188
-
189
- export { type DownloadStream as D, type GlyphInfo as G, type InlinedSource as I, type SMPSource as S, type TileInfo as T, Writer as W, type SMPStyle as a, type StyleInlinedSources as b, type TileFormat as c, type GlyphRange as d, SUPPORTED_SOURCE_TYPES as e, type Source as f, type SourceInternal as g, type SourceInfo as h };
@@ -1,189 +0,0 @@
1
- import { SourceSpecification, GeoJSONSourceSpecification, VectorSourceSpecification, RasterSourceSpecification, RasterDEMSourceSpecification, StyleSpecification } from '@maplibre/maplibre-gl-style-spec';
2
- import { GeoJSON, BBox } from 'geojson';
3
- import * as stream from 'stream';
4
- import { Readable } from 'stream';
5
- import { SetRequired } from 'type-fest';
6
- import * as readable_stream from 'readable-stream';
7
- import { EventEmitter } from 'events';
8
-
9
- /** @typedef {string | Buffer | Uint8Array | import('stream').Readable } Source */
10
- /** @typedef {string | Buffer | import('stream').Readable} SourceInternal */
11
- /** @typedef {`${number}-${number}`} GlyphRange */
12
- /** @typedef {'png' | 'mvt' | 'jpg' | 'webp'} TileFormat */
13
- /**
14
- * @typedef {object} SourceInfo
15
- * @property {import('./types.js').SMPSource} source
16
- * @property {string} encodedSourceId
17
- * @property {TileFormat} [format]
18
- */
19
- /**
20
- * @typedef {object} TileInfo
21
- * @property {number} z
22
- * @property {number} x
23
- * @property {number} y
24
- * @property {string} sourceId
25
- * @property {TileFormat} [format]
26
- */
27
- /**
28
- * @typedef {object} GlyphInfo
29
- * @property {string} font
30
- * @property {GlyphRange} range
31
- */
32
- /** @import { StyleSpecification } from '@maplibre/maplibre-gl-style-spec' */
33
- /** @import { InputSource, SMPSource } from './types.js' */
34
- declare const SUPPORTED_SOURCE_TYPES: readonly ["raster", "vector", "geojson"];
35
- /**
36
- * Write a styled map package to a stream. Stream `writer.outputStream` to a
37
- * destination, e.g. `fs.createWriteStream('my-map.styledmap')`. You must call
38
- * `witer.finish()` and then wait for your writable stream to `finish` before
39
- * using the output.
40
- */
41
- declare class Writer extends EventEmitter<[never]> {
42
- static SUPPORTED_SOURCE_TYPES: readonly ["raster", "vector", "geojson"];
43
- /**
44
- * @param {any} style A v7 or v8 MapLibre style. v7 styles will be migrated to
45
- * v8. (There are currently no typescript declarations for v7 styles, hence
46
- * this is typed as `any` and validated internally)
47
- * @param {object} opts
48
- * @param {number} [opts.highWaterMark=1048576] The maximum number of bytes to buffer during write
49
- */
50
- constructor(style: any, { highWaterMark }?: {
51
- highWaterMark?: number | undefined;
52
- });
53
- /**
54
- * @returns {import('stream').Readable} Readable stream of the styled map package
55
- */
56
- get outputStream(): stream.Readable;
57
- /**
58
- * Add a tile to the styled map package
59
- *
60
- * @param {Source} tileData
61
- * @param {TileInfo} opts
62
- */
63
- addTile(tileData: Source, { z, x, y, sourceId, format }: TileInfo): Promise<void>;
64
- /**
65
- * Create a write stream for adding tiles to the styled map package
66
- *
67
- * @param {object} opts
68
- * @param {number} [opts.concurrency=16] The number of concurrent writes
69
- *
70
- * @returns
71
- */
72
- createTileWriteStream({ concurrency }?: {
73
- concurrency?: number | undefined;
74
- }): readable_stream.Writable;
75
- /**
76
- * Add a sprite to the styled map package
77
- *
78
- * @param {object} options
79
- * @param {Source} options.json
80
- * @param {Source} options.png
81
- * @param {number} [options.pixelRatio]
82
- * @param {string} [options.id='default']
83
- * @returns {Promise<void>}
84
- */
85
- addSprite({ json, png, pixelRatio, id }: {
86
- json: Source;
87
- png: Source;
88
- pixelRatio?: number | undefined;
89
- id?: string | undefined;
90
- }): Promise<void>;
91
- /**
92
- * Add glyphs to the styled map package
93
- *
94
- * @param {Source} glyphData
95
- * @param {GlyphInfo} glyphInfo
96
- * @returns {Promise<void>}
97
- */
98
- addGlyphs(glyphData: Source, { font: fontName, range }: GlyphInfo): Promise<void>;
99
- /**
100
- * Create a write stream for adding glyphs to the styled map package
101
- *
102
- * @param {object} opts
103
- * @param {number} [opts.concurrency=16] The number of concurrent writes
104
- * @returns
105
- */
106
- createGlyphWriteStream({ concurrency }?: {
107
- concurrency?: number | undefined;
108
- }): readable_stream.Writable;
109
- /**
110
- * Finalize the styled map package and write the style to the archive.
111
- * This method must be called to complete the archive.
112
- * You must wait for your destination write stream to 'finish' before using the output.
113
- */
114
- finish(): void;
115
- #private;
116
- }
117
- type Source = string | Buffer | Uint8Array | stream.Readable;
118
- type SourceInternal = string | Buffer | stream.Readable;
119
- type GlyphRange = `${number}-${number}`;
120
- type TileFormat = "png" | "mvt" | "jpg" | "webp";
121
- type SourceInfo = {
122
- source: SMPSource;
123
- encodedSourceId: string;
124
- format?: TileFormat | undefined;
125
- };
126
- type TileInfo = {
127
- z: number;
128
- x: number;
129
- y: number;
130
- sourceId: string;
131
- format?: TileFormat | undefined;
132
- };
133
- type GlyphInfo = {
134
- font: string;
135
- range: GlyphRange;
136
- };
137
-
138
- type TransformInlinedSource<T extends SourceSpecification> = T extends GeoJSONSourceSpecification ? OmitUnion<T, 'data'> & {
139
- data: GeoJSON;
140
- } : T extends VectorSourceSpecification | RasterSourceSpecification | RasterDEMSourceSpecification ? SetRequired<OmitUnion<T, 'url'>, 'tiles'> : T;
141
- /**
142
- * This is a slightly stricter version of SourceSpecification that requires
143
- * sources to be inlined (e.g. no urls to TileJSON or GeoJSON files).
144
- */
145
- type InlinedSource = TransformInlinedSource<SourceSpecification>;
146
- type SupportedInlinedSource = Extract<InlinedSource, {
147
- type: (typeof SUPPORTED_SOURCE_TYPES)[number];
148
- }>;
149
- /**
150
- * This is a slightly stricter version of StyleSpecification that requires
151
- * sources to be inlined (e.g. no urls to TileJSON or GeoJSON files).
152
- */
153
- type StyleInlinedSources = Omit<StyleSpecification, 'sources'> & {
154
- sources: {
155
- [_: string]: InlinedSource;
156
- };
157
- };
158
- type SMPSource = TransformSMPInputSource<SupportedInlinedSource>;
159
- /**
160
- * This is a slightly stricter version of StyleSpecification that is provided in
161
- * a Styled Map Package. Tile sources must have tile URLs inlined (they cannot
162
- * refer to a TileJSON url), and they must have bounds, minzoom, and maxzoom.
163
- * GeoJSON sources must have inlined GeoJSON (not a URL to a GeoJSON file).
164
- */
165
- type SMPStyle = TransformSMPStyle<StyleSpecification>;
166
- type TransformSMPInputSource<T extends SupportedInlinedSource> = T extends GeoJSONSourceSpecification ? T & {
167
- data: {
168
- bbox: BBox;
169
- };
170
- } : T extends RasterSourceSpecification | VectorSourceSpecification ? SetRequired<T, 'bounds' | 'minzoom' | 'maxzoom'> : T;
171
- type TransformSMPStyle<T extends StyleSpecification> = Omit<T, 'sources'> & {
172
- metadata: {
173
- 'smp:bounds': [number, number, number, number];
174
- 'smp:maxzoom': 0;
175
- 'smp:sourceFolders': {
176
- [_: string]: string;
177
- };
178
- };
179
- sources: {
180
- [_: string]: SMPSource;
181
- };
182
- };
183
- interface DownloadStream extends Readable {
184
- iterator(...args: Parameters<Readable['iterator']>): AsyncIterableIterator<Buffer>;
185
- [Symbol.asyncIterator](): AsyncIterableIterator<Buffer>;
186
- }
187
- type OmitUnion<T, K extends keyof any> = T extends unknown ? Omit<T, K> : never;
188
-
189
- export { type DownloadStream as D, type GlyphInfo as G, type InlinedSource as I, type SMPSource as S, type TileInfo as T, Writer as W, type SMPStyle as a, type StyleInlinedSources as b, type TileFormat as c, type GlyphRange as d, SUPPORTED_SOURCE_TYPES as e, type Source as f, type SourceInternal as g, type SourceInfo as h };