styled-map-package-api 5.0.0-pre.2 → 5.0.0-pre.4

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 (94) hide show
  1. package/README.md +94 -0
  2. package/dist/download.d.ts +11 -21
  3. package/dist/fallbacks.d.ts +32 -0
  4. package/dist/from-mbtiles.d.ts +1 -3
  5. package/dist/index.d.ts +11 -24
  6. package/dist/reader.d.ts +28 -12
  7. package/dist/server.d.ts +23 -14
  8. package/dist/style-downloader.d.ts +13 -19
  9. package/dist/tile-downloader.d.ts +13 -23
  10. package/dist/types.d.ts +61 -0
  11. package/dist/utils/errors.d.ts +2 -4
  12. package/dist/utils/fetch.d.ts +3 -8
  13. package/dist/utils/file-formats.d.ts +3 -10
  14. package/dist/utils/geo.d.ts +17 -9
  15. package/dist/utils/mapbox.d.ts +8 -10
  16. package/dist/utils/misc.d.ts +3 -5
  17. package/dist/utils/streams.d.ts +6 -10
  18. package/dist/utils/style.d.ts +27 -16
  19. package/dist/utils/templates.d.ts +30 -25
  20. package/dist/validator.d.ts +66 -0
  21. package/dist/writer.d.ts +157 -4
  22. package/lib/download.js +125 -0
  23. package/lib/fallbacks.js +157 -0
  24. package/lib/from-mbtiles.js +131 -0
  25. package/lib/index.js +12 -0
  26. package/lib/reader.js +360 -0
  27. package/lib/server.js +222 -0
  28. package/lib/style-downloader.js +369 -0
  29. package/lib/tile-downloader.js +189 -0
  30. package/lib/types.ts +99 -0
  31. package/lib/utils/errors.js +24 -0
  32. package/lib/utils/fetch.js +104 -0
  33. package/lib/utils/file-formats.js +92 -0
  34. package/lib/utils/geo.js +97 -0
  35. package/lib/utils/mapbox.js +155 -0
  36. package/{dist/utils/misc.d.cts → lib/utils/misc.js} +9 -5
  37. package/lib/utils/streams.js +101 -0
  38. package/lib/utils/style.js +206 -0
  39. package/lib/utils/templates.js +165 -0
  40. package/lib/validator.js +789 -0
  41. package/lib/writer.js +652 -0
  42. package/package.json +30 -78
  43. package/dist/download.cjs +0 -100
  44. package/dist/download.d.cts +0 -63
  45. package/dist/download.js +0 -76
  46. package/dist/from-mbtiles.cjs +0 -108
  47. package/dist/from-mbtiles.d.cts +0 -14
  48. package/dist/from-mbtiles.js +0 -84
  49. package/dist/index.cjs +0 -46
  50. package/dist/index.d.cts +0 -24
  51. package/dist/index.js +0 -16
  52. package/dist/reader.cjs +0 -287
  53. package/dist/reader.d.cts +0 -67
  54. package/dist/reader.js +0 -259
  55. package/dist/server.cjs +0 -73
  56. package/dist/server.d.cts +0 -45
  57. package/dist/server.js +0 -49
  58. package/dist/style-downloader.cjs +0 -314
  59. package/dist/style-downloader.d.cts +0 -118
  60. package/dist/style-downloader.js +0 -290
  61. package/dist/tile-downloader.cjs +0 -156
  62. package/dist/tile-downloader.d.cts +0 -82
  63. package/dist/tile-downloader.js +0 -124
  64. package/dist/types-qfyJk4ot.d.cts +0 -200
  65. package/dist/types-qfyJk4ot.d.ts +0 -200
  66. package/dist/utils/errors.cjs +0 -41
  67. package/dist/utils/errors.d.cts +0 -18
  68. package/dist/utils/errors.js +0 -16
  69. package/dist/utils/fetch.cjs +0 -97
  70. package/dist/utils/fetch.d.cts +0 -50
  71. package/dist/utils/fetch.js +0 -63
  72. package/dist/utils/file-formats.cjs +0 -96
  73. package/dist/utils/file-formats.d.cts +0 -32
  74. package/dist/utils/file-formats.js +0 -70
  75. package/dist/utils/geo.cjs +0 -84
  76. package/dist/utils/geo.d.cts +0 -46
  77. package/dist/utils/geo.js +0 -56
  78. package/dist/utils/mapbox.cjs +0 -121
  79. package/dist/utils/mapbox.d.cts +0 -43
  80. package/dist/utils/mapbox.js +0 -91
  81. package/dist/utils/misc.cjs +0 -39
  82. package/dist/utils/misc.js +0 -13
  83. package/dist/utils/streams.cjs +0 -99
  84. package/dist/utils/streams.d.cts +0 -49
  85. package/dist/utils/streams.js +0 -73
  86. package/dist/utils/style.cjs +0 -126
  87. package/dist/utils/style.d.cts +0 -66
  88. package/dist/utils/style.js +0 -98
  89. package/dist/utils/templates.cjs +0 -124
  90. package/dist/utils/templates.d.cts +0 -79
  91. package/dist/utils/templates.js +0 -85
  92. package/dist/writer.cjs +0 -539
  93. package/dist/writer.d.cts +0 -4
  94. package/dist/writer.js +0 -516
@@ -1,8 +1,3 @@
1
- import { c as TileFormat } from '../types-qfyJk4ot.js';
2
- import '@maplibre/maplibre-gl-style-spec';
3
- import 'geojson';
4
- import 'type-fest';
5
-
6
1
  /**
7
2
  * For a given buffer, determine the tile format based on the magic bytes.
8
3
  * Will throw for unknown file types.
@@ -11,7 +6,7 @@ import 'type-fest';
11
6
  * @param {Buffer | Uint8Array} buf
12
7
  * @returns {import("../writer.js").TileFormat}
13
8
  */
14
- declare function getTileFormatFromBuffer(buf: Buffer | Uint8Array): TileFormat;
9
+ export function getTileFormatFromBuffer(buf: Buffer | Uint8Array): import("../writer.js").TileFormat;
15
10
  /**
16
11
  * Determine the tile format from a readable stream from the magic bytes at the
17
12
  * start of the file. Used if data is served without a content-type header.
@@ -20,13 +15,11 @@ declare function getTileFormatFromBuffer(buf: Buffer | Uint8Array): TileFormat;
20
15
  * @param {ReadableStream<Uint8Array>} tileData Web ReadableStream
21
16
  * @returns {Promise<[import("../writer.js").TileFormat, ReadableStream<Uint8Array>]>}
22
17
  */
23
- declare function getTileFormatFromStream(tileData: ReadableStream<Uint8Array>): Promise<[TileFormat, ReadableStream<Uint8Array>]>;
18
+ export function getTileFormatFromStream(tileData: ReadableStream<Uint8Array>): Promise<[import("../writer.js").TileFormat, ReadableStream<Uint8Array>]>;
24
19
  /**
25
20
  * Get the tile format from a MIME type. Throws for unsupported types.
26
21
  *
27
22
  * @param {string} mimeType
28
23
  * @returns {import("../writer.js").TileFormat}
29
24
  */
30
- declare function getFormatFromMimeType(mimeType: string): TileFormat;
31
-
32
- export { getFormatFromMimeType, getTileFormatFromBuffer, getTileFormatFromStream };
25
+ export function getFormatFromMimeType(mimeType: string): import("../writer.js").TileFormat;
@@ -7,7 +7,7 @@
7
7
  * @param {{ x: number, y: number, z: number }} tile
8
8
  * @returns {BBox} Bounding Box [w, s, e, n]
9
9
  */
10
- declare function tileToBBox({ x, y, z }: {
10
+ export function tileToBBox({ x, y, z }: {
11
11
  x: number;
12
12
  y: number;
13
13
  z: number;
@@ -15,7 +15,7 @@ declare function tileToBBox({ x, y, z }: {
15
15
  /**
16
16
  * @param {{ x: number, y: number, z: number }} tile
17
17
  */
18
- declare function getQuadkey({ x, y, z }: {
18
+ export function getQuadkey({ x, y, z }: {
19
19
  x: number;
20
20
  y: number;
21
21
  z: number;
@@ -26,7 +26,7 @@ declare function getQuadkey({ x, y, z }: {
26
26
  * @param {string[]} urls
27
27
  * @param {{ x: number, y: number, z: number, scheme?: 'xyz' | 'tms' }} opts
28
28
  */
29
- declare function getTileUrl(urls: string[], { x, y, z, scheme }: {
29
+ export function getTileUrl(urls: string[], { x, y, z, scheme }: {
30
30
  x: number;
31
31
  y: number;
32
32
  z: number;
@@ -35,12 +35,20 @@ declare function getTileUrl(urls: string[], { x, y, z, scheme }: {
35
35
  /**
36
36
  * Returns a bbox that is the smallest bounding box that contains all the input bboxes.
37
37
  *
38
- * @param {[BBox, ...BBox[]]} bboxes
38
+ * @param {[Readonly<BBox>, ...Readonly<BBox>[]]} bboxes
39
39
  * @returns {BBox} Bounding Box [w, s, e, n]
40
40
  */
41
- declare function unionBBox(bboxes: [BBox, ...BBox[]]): BBox;
41
+ export function unionBBox(bboxes: [Readonly<BBox>, ...Readonly<BBox>[]]): BBox;
42
+ /**
43
+ * Convert a TMS Y coordinate to an XYZ Y coordinate.
44
+ *
45
+ * @param {{ y: number, z: number }} tile
46
+ * @returns {number} The XYZ Y coordinate
47
+ */
48
+ export function tmsToXyzY({ y, z }: {
49
+ y: number;
50
+ z: number;
51
+ }): number;
42
52
  /** Spherical Mercator max bounds, rounded to 6 decimal places */
43
- declare const MAX_BOUNDS: BBox;
44
- type BBox = [number, number, number, number];
45
-
46
- export { type BBox, MAX_BOUNDS, getQuadkey, getTileUrl, tileToBBox, unionBBox };
53
+ export const MAX_BOUNDS: BBox;
54
+ export type BBox = [number, number, number, number];
@@ -1,43 +1,41 @@
1
1
  /** @param {string} url */
2
- declare function isMapboxURL(url: string): boolean;
2
+ export function isMapboxURL(url: string): boolean;
3
3
  /**
4
4
  * @param {string} url
5
5
  * @param {string} [accessToken]
6
6
  */
7
- declare function normalizeStyleURL(url: string, accessToken?: string): string;
7
+ export function normalizeStyleURL(url: string, accessToken?: string): string;
8
8
  /**
9
9
  * @param {string} url
10
10
  * @param {string} [accessToken]
11
11
  */
12
- declare function normalizeGlyphsURL(url: string, accessToken?: string): string;
12
+ export function normalizeGlyphsURL(url: string, accessToken?: string): string;
13
13
  /**
14
14
  * @param {string} url
15
15
  * @param {string} [accessToken]
16
16
  */
17
- declare function normalizeSourceURL(url: string, accessToken?: string): string;
17
+ export function normalizeSourceURL(url: string, accessToken?: string): string;
18
18
  /**
19
19
  * @param {string} url
20
20
  * @param {'' | '@2x'} format
21
21
  * @param {'.png' | '.json'} extension
22
22
  * @param {string} [accessToken]
23
23
  */
24
- declare function normalizeSpriteURL(url: string, format: "" | "@2x", extension: ".png" | ".json", accessToken?: string): string;
24
+ export function normalizeSpriteURL(url: string, format: "" | "@2x", extension: ".png" | ".json", accessToken?: string): string;
25
25
  /**
26
26
  * @param {any} tileURL
27
27
  * @param {string} sourceURL
28
28
  * @param {256 | 512} [tileSize]
29
29
  * @param {{ devicePixelRatio?: number; supportsWebp?: boolean; }} [opts]
30
30
  */
31
- declare function normalizeTileURL(tileURL: any, sourceURL: string, tileSize?: 256 | 512, { devicePixelRatio, supportsWebp }?: {
31
+ export function normalizeTileURL(tileURL: any, sourceURL: string, tileSize?: 256 | 512, { devicePixelRatio, supportsWebp }?: {
32
32
  devicePixelRatio?: number;
33
33
  supportsWebp?: boolean;
34
34
  }): any;
35
- declare const API_URL: "https://api.mapbox.com";
36
- type URLObject = {
35
+ export const API_URL: "https://api.mapbox.com";
36
+ export type URLObject = {
37
37
  protocol: string;
38
38
  authority: string;
39
39
  path: string;
40
40
  params: string[];
41
41
  };
42
-
43
- export { API_URL, type URLObject, isMapboxURL, normalizeGlyphsURL, normalizeSourceURL, normalizeSpriteURL, normalizeStyleURL, normalizeTileURL };
@@ -7,8 +7,8 @@
7
7
  * @param {T} obj
8
8
  * @returns {T}
9
9
  */
10
- declare function clone<T>(obj: T): T;
11
- declare function noop(): void;
10
+ export function clone<T>(obj: T): T;
11
+ export function noop(): void;
12
12
  /**
13
13
  * Like `Object.hasOwn`, but refines the type of `key`.
14
14
  *
@@ -17,6 +17,4 @@ declare function noop(): void;
17
17
  * @param {string} key
18
18
  * @returns {key is (keyof T)}
19
19
  */
20
- declare function hasOwn<T extends Record<string, unknown>>(obj: T, key: string): key is (keyof T);
21
-
22
- export { clone, hasOwn, noop };
20
+ export function hasOwn<T extends Record<string, unknown>>(obj: T, key: string): key is (keyof T);
@@ -1,5 +1,3 @@
1
- import * as stream_web from 'stream/web';
2
-
3
1
  /**
4
2
  * Create a ReadableStream from an async iterable. Uses the native
5
3
  * `ReadableStream.from()` when available (Node 20+), otherwise falls back to a
@@ -9,7 +7,7 @@ import * as stream_web from 'stream/web';
9
7
  * @param {AsyncIterable<T>} iterable
10
8
  * @returns {ReadableStream<T>}
11
9
  */
12
- declare function readableFromAsync<T>(iterable: AsyncIterable<T>): ReadableStream<T>;
10
+ export function readableFromAsync<T>(iterable: AsyncIterable<T>): ReadableStream<T>;
13
11
  /**
14
12
  * Create a writable stream from an async function. Default concurrency is 16 -
15
13
  * this is the number of parallel functions that will be pending before
@@ -19,7 +17,7 @@ declare function readableFromAsync<T>(iterable: AsyncIterable<T>): ReadableStrea
19
17
  * @param {T} fn
20
18
  * @returns {WritableStream}
21
19
  */
22
- declare function writeStreamFromAsync<T extends (...args: any[]) => Promise<void>>(fn: T, { concurrency }?: {
20
+ export function writeStreamFromAsync<T extends (...args: any[]) => Promise<void>>(fn: T, { concurrency }?: {
23
21
  concurrency?: number | undefined;
24
22
  }): WritableStream;
25
23
  /** @typedef {(opts: { totalBytes: number, chunkBytes: number }) => void} ProgressCallback */
@@ -28,22 +26,20 @@ declare function writeStreamFromAsync<T extends (...args: any[]) => Promise<void
28
26
  * optional `onprogress` callback that will be called with the accumulated
29
27
  * total byte count and the chunk byte count after each chunk.
30
28
  */
31
- declare class ProgressStream {
29
+ export class ProgressStream {
32
30
  /**
33
31
  * @param {{ onprogress?: ProgressCallback }} [opts]
34
32
  */
35
33
  constructor({ onprogress }?: {
36
34
  onprogress?: ProgressCallback;
37
35
  });
38
- get readable(): stream_web.ReadableStream<any>;
39
- get writable(): stream_web.WritableStream<any>;
36
+ get readable(): ReadableStream<any>;
37
+ get writable(): WritableStream<any>;
40
38
  /** Total bytes that have passed through this stream */
41
39
  get byteLength(): number;
42
40
  #private;
43
41
  }
44
- type ProgressCallback = (opts: {
42
+ export type ProgressCallback = (opts: {
45
43
  totalBytes: number;
46
44
  chunkBytes: number;
47
45
  }) => void;
48
-
49
- export { type ProgressCallback, ProgressStream, readableFromAsync, writeStreamFromAsync };
@@ -1,10 +1,3 @@
1
- import { BBox } from './geo.js';
2
- import { I as InlinedSource } from '../types-qfyJk4ot.js';
3
- import * as _maplibre_maplibre_gl_style_spec from '@maplibre/maplibre-gl-style-spec';
4
- import { StyleSpecification, ValidationError } from '@maplibre/maplibre-gl-style-spec';
5
- import 'geojson';
6
- import 'type-fest';
7
-
8
1
  /** @import {StyleSpecification, ExpressionSpecification, ValidationError} from '@maplibre/maplibre-gl-style-spec' */
9
2
  /**
10
3
  * For a given style, replace all font stacks (`text-field` properties) with the
@@ -16,7 +9,7 @@ import 'type-fest';
16
9
  * @param {StyleSpecification} style
17
10
  * @param {string[]} fonts
18
11
  */
19
- declare function replaceFontStacks(style: StyleSpecification, fonts: string[]): StyleSpecification;
12
+ export function replaceFontStacks(style: StyleSpecification, fonts: string[]): StyleSpecification;
20
13
  /**
21
14
  * From given style layers, create a new style by calling the provided callback
22
15
  * function on every font stack defined in the style.
@@ -25,7 +18,14 @@ declare function replaceFontStacks(style: StyleSpecification, fonts: string[]):
25
18
  * @param {(fontStack: string[]) => string[]} callbackFn
26
19
  * @returns {StyleSpecification['layers']}
27
20
  */
28
- declare function mapFontStacks(layers: StyleSpecification["layers"], callbackFn: (fontStack: string[]) => string[]): StyleSpecification["layers"];
21
+ export function mapFontStacks(layers: StyleSpecification["layers"], callbackFn: (fontStack: string[]) => string[]): StyleSpecification["layers"];
22
+ /**
23
+ * Check whether a PBF glyph range (identified by its start codepoint) is
24
+ * rendered client-side by MapLibre GL and does not need a server-side PBF file.
25
+ * @param {number} rangeStart
26
+ * @returns {boolean}
27
+ */
28
+ export function isLocallyRenderedRange(rangeStart: number): boolean;
29
29
  /**
30
30
  * @typedef {object} TileJSONPartial
31
31
  * @property {string[]} tiles
@@ -41,26 +41,37 @@ declare function mapFontStacks(layers: StyleSpecification["layers"], callbackFn:
41
41
  * @param {unknown} tilejson
42
42
  * @returns {asserts tilejson is TileJSONPartial}
43
43
  */
44
- declare function assertTileJSON(tilejson: unknown): asserts tilejson is TileJSONPartial;
44
+ export function assertTileJSON(tilejson: unknown): asserts tilejson is TileJSONPartial;
45
45
  /**
46
46
  * Check whether a source is already inlined (e.g. does not reference a TileJSON or GeoJSON url)
47
47
  *
48
48
  * @param {import('@maplibre/maplibre-gl-style-spec').SourceSpecification} source
49
49
  * @returns {source is import('../types.js').InlinedSource}
50
50
  */
51
- declare function isInlinedSource(source: _maplibre_maplibre_gl_style_spec.SourceSpecification): source is InlinedSource;
52
- declare const validateStyle: {
51
+ export function isInlinedSource(source: import("@maplibre/maplibre-gl-style-spec").SourceSpecification): source is import("../types.js").InlinedSource;
52
+ /**
53
+ * PBF glyph ranges rendered client-side by MapLibre GL via
54
+ * `localIdeographFontFamily` (enabled by default as 'sans-serif'). SMP files
55
+ * do not need to include glyph data for these ranges. Each entry is a
56
+ * half-open interval [start, end) of PBF range start codepoints.
57
+ *
58
+ * Based on `codePointUsesLocalIdeographFontFamily()` in MapLibre GL JS.
59
+ * Only ranges where the ENTIRE 256-codepoint PBF range is locally rendered
60
+ * are listed here; partially-local ranges are conservatively kept as required.
61
+ */
62
+ export const LOCAL_GLYPH_RANGES: number[][];
63
+ export const validateStyle: {
53
64
  (style: unknown): style is StyleSpecification;
54
65
  errors: ValidationError[];
55
66
  };
56
- type TileJSONPartial = {
67
+ export type TileJSONPartial = {
57
68
  tiles: string[];
58
69
  description?: string | undefined;
59
70
  attribution?: string | undefined;
60
71
  vector_layers?: object[] | undefined;
61
- bounds?: BBox | undefined;
72
+ bounds?: import("./geo.js").BBox | undefined;
62
73
  maxzoom?: number | undefined;
63
74
  minzoom?: number | undefined;
64
75
  };
65
-
66
- export { type TileJSONPartial, assertTileJSON, isInlinedSource, mapFontStacks, replaceFontStacks, validateStyle };
76
+ import type { StyleSpecification } from '@maplibre/maplibre-gl-style-spec';
77
+ import type { ValidationError } from '@maplibre/maplibre-gl-style-spec';
@@ -1,32 +1,27 @@
1
- import * as type_fest from 'type-fest';
2
- import { d as GlyphRange, T as TileInfo, c as TileFormat } from '../types-qfyJk4ot.js';
3
- import '@maplibre/maplibre-gl-style-spec';
4
- import 'geojson';
5
-
6
1
  /**
7
2
  * @param {string} path
8
3
  * @returns
9
4
  */
10
- declare function getResourceType(path: string): "sprite" | "style" | "tile" | "glyph";
5
+ export function getResourceType(path: string): "sprite" | "tile" | "glyph" | "style";
11
6
  /**
12
7
  * Determine the content type of a file based on its extension.
13
8
  *
14
9
  * @param {string} path
15
10
  */
16
- declare function getContentType(path: string): "application/json; charset=utf-8" | "application/x-protobuf" | "image/png" | "image/jpeg" | "image/webp" | "application/vnd.mapbox-vector-tile";
11
+ export function getContentType(path: string): "application/json; charset=utf-8" | "application/x-protobuf" | "image/png" | "image/jpeg" | "image/webp" | "application/vnd.mapbox-vector-tile";
17
12
  /**
18
13
  * Get the filename for a tile, given the TileInfo
19
14
  *
20
15
  * @param {import("type-fest").SetRequired<import("../writer.js").TileInfo, 'format'>} tileInfo
21
16
  * @returns
22
17
  */
23
- declare function getTileFilename({ sourceId, z, x, y, format }: type_fest.SetRequired<TileInfo, "format">): string;
18
+ export function getTileFilename({ sourceId, z, x, y, format }: import("type-fest").SetRequired<import("../writer.js").TileInfo, "format">): string;
24
19
  /**
25
20
  * Get a filename for a sprite file, given the sprite id, pixel ratio and extension
26
21
  *
27
22
  * @param {{ id: string, pixelRatio: number, ext: '.json' | '.png'}} spriteInfo
28
23
  */
29
- declare function getSpriteFilename({ id, pixelRatio, ext }: {
24
+ export function getSpriteFilename({ id, pixelRatio, ext }: {
30
25
  id: string;
31
26
  pixelRatio: number;
32
27
  ext: ".json" | ".png";
@@ -38,14 +33,14 @@ declare function getSpriteFilename({ id, pixelRatio, ext }: {
38
33
  * @param {string} options.fontstack
39
34
  * @param {import("../writer.js").GlyphRange} options.range
40
35
  */
41
- declare function getGlyphFilename({ fontstack, range }: {
36
+ export function getGlyphFilename({ fontstack, range }: {
42
37
  fontstack: string;
43
- range: GlyphRange;
38
+ range: import("../writer.js").GlyphRange;
44
39
  }): string;
45
40
  /**
46
41
  * Get the URI template for the sprites in the style
47
42
  */
48
- declare function getSpriteUri(id?: string): string;
43
+ export function getSpriteUri(id?: string): string;
49
44
  /**
50
45
  * Get the URI template for tiles in the style
51
46
  *
@@ -54,9 +49,9 @@ declare function getSpriteUri(id?: string): string;
54
49
  * @param {import("../writer.js").TileFormat} opts.format
55
50
  * @returns
56
51
  */
57
- declare function getTileUri({ sourceId, format }: {
52
+ export function getTileUri({ sourceId, format }: {
58
53
  sourceId: string;
59
- format: TileFormat;
54
+ format: import("../writer.js").TileFormat;
60
55
  }): string;
61
56
  /**
62
57
  * Replaces variables in a string with values provided in an object. Variables
@@ -66,14 +61,24 @@ declare function getTileUri({ sourceId, format }: {
66
61
  * @param {Record<string, string | number>} variables - An object where the keys correspond to variable names and values correspond to the replacement values.
67
62
  * @returns {string} The string with the variables replaced by their corresponding values.
68
63
  */
69
- declare function replaceVariables(template: string, variables: Record<string, string | number>): string;
70
- declare const URI_SCHEME: "smp";
71
- declare const URI_BASE: string;
72
- declare const VERSION_FILE: "VERSION";
73
- declare const FORMAT_VERSION: "1.0";
74
- declare const STYLE_FILE: "style.json";
75
- declare const SOURCES_FOLDER: "s";
76
- declare const FONTS_FOLDER: "fonts";
77
- declare const GLYPH_URI: string;
78
-
79
- export { FONTS_FOLDER, FORMAT_VERSION, GLYPH_URI, SOURCES_FOLDER, STYLE_FILE, URI_BASE, URI_SCHEME, VERSION_FILE, getContentType, getGlyphFilename, getResourceType, getSpriteFilename, getSpriteUri, getTileFilename, getTileUri, replaceVariables };
64
+ export function replaceVariables(template: string, variables: Record<string, string | number>): string;
65
+ /**
66
+ * Inverse of {@link replaceVariables}. Converts a template string into a RegExp
67
+ * that captures the placeholder values. Only placeholders present in the
68
+ * `placeholders` map become named capture groups; unknown placeholders are
69
+ * treated as literal text and escaped.
70
+ *
71
+ * @param {string} template - The template string with `{name}` placeholders.
72
+ * @param {Record<string, string>} placeholders - Map of placeholder
73
+ * name → regex pattern (e.g. `{ z: '\\d+' }`).
74
+ * @returns {RegExp} A RegExp with named capture groups for each known placeholder.
75
+ */
76
+ export function templateToRegex(template: string, placeholders: Record<string, string>): RegExp;
77
+ export const URI_SCHEME: "smp";
78
+ export const URI_BASE: string;
79
+ export const VERSION_FILE: "VERSION";
80
+ export const FORMAT_VERSION: "1.0";
81
+ export const STYLE_FILE: "style.json";
82
+ export const SOURCES_FOLDER: "s";
83
+ export const FONTS_FOLDER: "fonts";
84
+ export const GLYPH_URI: string;
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Validate a Styled Map Package file against the SMP specification.
3
+ *
4
+ * Returns a list of issues, each with a `kind` ('error' or 'warning'), a
5
+ * `severity` ('fatal', 'rendering', or 'spec'), and a stable `type` string
6
+ * for programmatic filtering. Use `result.valid` to check spec compliance
7
+ * and `result.usable` to check whether the file can be opened by the reader.
8
+ *
9
+ * @param {string | import('@gmaclennan/zip-reader').ZipReader} source Path to the .smp file, or a ZipReader instance
10
+ * @param {ValidateOptions} [options]
11
+ * @returns {Promise<ValidationResult>}
12
+ */
13
+ export function validate(source: string | import("@gmaclennan/zip-reader").ZipReader, options?: ValidateOptions): Promise<ValidationResult>;
14
+ export type IssueFn = ReturnType<typeof createIssue>;
15
+ export type ValidationIssue = {
16
+ /**
17
+ * - error = spec MUST violation; warning = SHOULD/RECOMMENDED
18
+ */
19
+ kind: "error" | "warning";
20
+ /**
21
+ * - Practical impact:
22
+ * fatal = reader will fail to open; rendering = map renders with visible
23
+ * issues; spec = non-compliance that doesn't affect practical use
24
+ */
25
+ severity: "fatal" | "rendering" | "spec";
26
+ /**
27
+ * - Stable identifier for programmatic matching
28
+ */
29
+ type: string;
30
+ /**
31
+ * - Human-readable description
32
+ */
33
+ message: string;
34
+ /**
35
+ * - Location context (e.g. 'sources.test.tiles', 'VERSION')
36
+ */
37
+ path?: string | undefined;
38
+ };
39
+ export type ValidationResult = {
40
+ /**
41
+ * - true when there are no errors (warnings are acceptable)
42
+ */
43
+ valid: boolean;
44
+ /**
45
+ * - true when there are no fatal issues (the file can be opened)
46
+ */
47
+ usable: boolean;
48
+ /**
49
+ * - all issues found
50
+ */
51
+ issues: ValidationIssue[];
52
+ };
53
+ export type ValidateOptions = {
54
+ /**
55
+ * Maximum number of ZIP entries to
56
+ * process before aborting. Default matches the Reader default (~a global z9
57
+ * tileset).
58
+ */
59
+ maxEntries?: number | undefined;
60
+ };
61
+ /**
62
+ * @param {ValidationIssue[]} issues
63
+ * @param {'error' | 'warning'} kind
64
+ */
65
+ declare function createIssue(issues: ValidationIssue[], kind: "error" | "warning"): (type: string, message: string, path?: string) => number;
66
+ export {};
package/dist/writer.d.ts CHANGED
@@ -1,4 +1,157 @@
1
- export { G as GlyphInfo, d as GlyphRange, e as SUPPORTED_SOURCE_TYPES, f as Source, g as SourceInfo, c as TileFormat, T as TileInfo, W as Writer, h as WriterOptions } from './types-qfyJk4ot.js';
2
- import '@maplibre/maplibre-gl-style-spec';
3
- import 'geojson';
4
- import 'type-fest';
1
+ /** @typedef {string | Uint8Array | ReadableStream } Source */
2
+ /** @typedef {`${number}-${number}`} GlyphRange */
3
+ /** @typedef {'png' | 'mvt' | 'jpg' | 'webp'} TileFormat */
4
+ /**
5
+ * @typedef {object} SourceInfo
6
+ * @property {import('./types.js').SMPSource} source
7
+ * @property {string} encodedSourceId
8
+ * @property {TileFormat} [format]
9
+ */
10
+ /**
11
+ * @typedef {object} TileInfo
12
+ * @property {number} z Zoom level
13
+ * @property {number} x Tile column (XYZ scheme)
14
+ * @property {number} y Tile row (XYZ scheme, origin at top-left). If your source uses TMS, convert with {@link import('./utils/geo.js').tmsToXyzY} before passing.
15
+ * @property {string} sourceId
16
+ * @property {TileFormat} [format]
17
+ */
18
+ /**
19
+ * @typedef {object} GlyphInfo
20
+ * @property {string} font
21
+ * @property {GlyphRange} range
22
+ */
23
+ /** @import { StyleSpecification } from '@maplibre/maplibre-gl-style-spec' */
24
+ /** @import { InputSource, SMPSource } from './types.js' */
25
+ export const SUPPORTED_SOURCE_TYPES: readonly ["raster", "vector", "geojson"];
26
+ /**
27
+ * @typedef {object} WriterOptions
28
+ * @property {boolean} [dedupe] When true, duplicate tiles (with identical
29
+ * content) are stored only once in the archive. Additional entries in the
30
+ * central directory point to the same data. This reduces file size for
31
+ * tilesets with many repeated tiles (e.g. ocean tiles).
32
+ */
33
+ /**
34
+ * Write a styled map package to a stream. Stream `writer.outputStream` to a
35
+ * destination, e.g. `fs.createWriteStream('my-map.styledmap')`. You must call
36
+ * `witer.finish()` and then wait for your writable stream to `finish` before
37
+ * using the output.
38
+ */
39
+ export class Writer {
40
+ static SUPPORTED_SOURCE_TYPES: readonly ["raster", "vector", "geojson"];
41
+ /**
42
+ * @param {any} style A v7 or v8 MapLibre style. v7 styles will be migrated to
43
+ * v8. (There are currently no typescript declarations for v7 styles, hence
44
+ * this is typed as `any` and validated internally)
45
+ * @param {WriterOptions} [options]
46
+ */
47
+ constructor(style: any, { dedupe }?: WriterOptions);
48
+ /**
49
+ * @returns {ReadableStream<Uint8Array>} Readable stream of the styled map package
50
+ */
51
+ get outputStream(): ReadableStream<Uint8Array>;
52
+ /**
53
+ * Abort the output stream with an error. Call this if an error occurs during
54
+ * writing to propagate the error to consumers of `outputStream`.
55
+ *
56
+ * @param {Error} reason
57
+ */
58
+ abort(reason: Error): void;
59
+ /**
60
+ * Add a tile to the styled map package. Coordinates must use the XYZ scheme
61
+ * (origin at top-left / north-west). If your tiles use TMS coordinates,
62
+ * convert the Y value first with `tmsToXyzY({ y, z })` from `utils/geo.js`.
63
+ *
64
+ * @param {Source} tileData
65
+ * @param {TileInfo} opts
66
+ */
67
+ addTile(tileData: Source, { z, x, y, sourceId, format }: TileInfo): Promise<void>;
68
+ /**
69
+ * Create a write stream for adding tiles to the styled map package
70
+ *
71
+ * @param {object} opts
72
+ * @param {number} [opts.concurrency=16] The number of concurrent writes
73
+ *
74
+ * @returns
75
+ */
76
+ createTileWriteStream({ concurrency }?: {
77
+ concurrency?: number | undefined;
78
+ }): WritableStream<any>;
79
+ /**
80
+ * Add a sprite to the styled map package
81
+ *
82
+ * @param {object} options
83
+ * @param {Source} options.json
84
+ * @param {Source} options.png
85
+ * @param {number} [options.pixelRatio]
86
+ * @param {string} [options.id='default']
87
+ * @returns {Promise<void>}
88
+ */
89
+ addSprite({ json, png, pixelRatio, id }: {
90
+ json: Source;
91
+ png: Source;
92
+ pixelRatio?: number | undefined;
93
+ id?: string | undefined;
94
+ }): Promise<void>;
95
+ /**
96
+ * Add glyphs to the styled map package
97
+ *
98
+ * @param {Source} glyphData
99
+ * @param {GlyphInfo} glyphInfo
100
+ * @returns {Promise<void>}
101
+ */
102
+ addGlyphs(glyphData: Source, { font: fontName, range }: GlyphInfo): Promise<void>;
103
+ /**
104
+ * Create a write stream for adding glyphs to the styled map package
105
+ *
106
+ * @param {object} opts
107
+ * @param {number} [opts.concurrency=16] The number of concurrent writes
108
+ * @returns
109
+ */
110
+ createGlyphWriteStream({ concurrency }?: {
111
+ concurrency?: number | undefined;
112
+ }): WritableStream<any>;
113
+ /**
114
+ * Finalize the styled map package and write the style to the archive.
115
+ * This method must be called to complete the archive.
116
+ * You must wait for your destination write stream to 'finish' before using the output.
117
+ */
118
+ finish(): Promise<void>;
119
+ #private;
120
+ }
121
+ export type Source = string | Uint8Array | ReadableStream;
122
+ export type GlyphRange = `${number}-${number}`;
123
+ export type TileFormat = "png" | "mvt" | "jpg" | "webp";
124
+ export type SourceInfo = {
125
+ source: import("./types.js").SMPSource;
126
+ encodedSourceId: string;
127
+ format?: TileFormat | undefined;
128
+ };
129
+ export type TileInfo = {
130
+ /**
131
+ * Zoom level
132
+ */
133
+ z: number;
134
+ /**
135
+ * Tile column (XYZ scheme)
136
+ */
137
+ x: number;
138
+ /**
139
+ * Tile row (XYZ scheme, origin at top-left). If your source uses TMS, convert with {@link import ('./utils/geo.js').tmsToXyzY} before passing.
140
+ */
141
+ y: number;
142
+ sourceId: string;
143
+ format?: TileFormat | undefined;
144
+ };
145
+ export type GlyphInfo = {
146
+ font: string;
147
+ range: GlyphRange;
148
+ };
149
+ export type WriterOptions = {
150
+ /**
151
+ * When true, duplicate tiles (with identical
152
+ * content) are stored only once in the archive. Additional entries in the
153
+ * central directory point to the same data. This reduces file size for
154
+ * tilesets with many repeated tiles (e.g. ocean tiles).
155
+ */
156
+ dedupe?: boolean | undefined;
157
+ };