styled-map-package 2.2.0 → 3.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 +2 -2
  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 +37 -0
  30. package/dist/server.d.ts +37 -0
  31. package/dist/server.js +45 -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 +87 -33
  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,103 @@
1
+ import { Readable, Writable, Transform } from "readable-stream";
2
+ function writeStreamFromAsync(fn, { concurrency = 16 } = {}) {
3
+ return new Writable({
4
+ highWaterMark: concurrency,
5
+ objectMode: true,
6
+ write(chunk, encoding, callback) {
7
+ fn.apply(null, chunk).then(() => callback(), callback);
8
+ }
9
+ });
10
+ }
11
+ function fromWebReadableStream(readableStream, options = {}) {
12
+ if (!isWebReadableStream(readableStream)) {
13
+ throw new Error("First argument must be a ReadableStream");
14
+ }
15
+ const { highWaterMark, encoding, objectMode = false, signal } = options;
16
+ if (encoding !== void 0 && !Buffer.isEncoding(encoding))
17
+ throw new Error("Invalid encoding");
18
+ const reader = readableStream.getReader();
19
+ let closed = false;
20
+ const readable = new Readable({
21
+ objectMode,
22
+ highWaterMark,
23
+ encoding,
24
+ // @ts-ignore
25
+ signal,
26
+ read() {
27
+ reader.read().then(
28
+ (chunk) => {
29
+ if (chunk.done) {
30
+ readable.push(null);
31
+ } else {
32
+ readable.push(chunk.value);
33
+ }
34
+ },
35
+ (error) => readable.destroy(error)
36
+ );
37
+ },
38
+ destroy(error, callback) {
39
+ function done() {
40
+ try {
41
+ callback(error);
42
+ } catch (error2) {
43
+ process.nextTick(() => {
44
+ throw error2;
45
+ });
46
+ }
47
+ }
48
+ if (!closed) {
49
+ reader.cancel(error).then(done, done);
50
+ return;
51
+ }
52
+ done();
53
+ }
54
+ });
55
+ reader.closed.then(
56
+ () => {
57
+ closed = true;
58
+ },
59
+ (error) => {
60
+ closed = true;
61
+ readable.destroy(error);
62
+ }
63
+ );
64
+ return readable;
65
+ }
66
+ function isWebReadableStream(obj) {
67
+ return !!(typeof obj === "object" && obj !== null && "pipeThrough" in obj && typeof obj.pipeThrough === "function" && "getReader" in obj && typeof obj.getReader === "function" && "cancel" in obj && typeof obj.cancel === "function");
68
+ }
69
+ class ProgressStream extends Transform {
70
+ #onprogress;
71
+ #byteLength = 0;
72
+ /**
73
+ * @param {ProgressStreamOptions} [opts]
74
+ */
75
+ constructor({ onprogress, ...opts } = {}) {
76
+ super(opts);
77
+ this.#onprogress = onprogress;
78
+ }
79
+ /** Total bytes that have passed through this stream */
80
+ get byteLength() {
81
+ return this.#byteLength;
82
+ }
83
+ /**
84
+ * @override
85
+ * @param {Buffer | Uint8Array} chunk
86
+ * @param {Parameters<Transform['_transform']>[1]} encoding
87
+ * @param {Parameters<Transform['_transform']>[2]} callback
88
+ */
89
+ _transform(chunk, encoding, callback) {
90
+ this.#byteLength += chunk.length;
91
+ this.#onprogress?.({
92
+ totalBytes: this.#byteLength,
93
+ chunkBytes: chunk.length
94
+ });
95
+ callback(null, chunk);
96
+ }
97
+ }
98
+ export {
99
+ ProgressStream,
100
+ fromWebReadableStream,
101
+ isWebReadableStream,
102
+ writeStreamFromAsync
103
+ };
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var style_exports = {};
20
+ __export(style_exports, {
21
+ assertTileJSON: () => assertTileJSON,
22
+ isInlinedSource: () => isInlinedSource,
23
+ mapFontStacks: () => mapFontStacks,
24
+ replaceFontStacks: () => replaceFontStacks,
25
+ validateStyle: () => validateStyle
26
+ });
27
+ module.exports = __toCommonJS(style_exports);
28
+ var import_maplibre_gl_style_spec = require("@maplibre/maplibre-gl-style-spec");
29
+ function replaceFontStacks(style, fonts) {
30
+ const mappedLayers = mapFontStacks(style.layers, (fontStack) => {
31
+ let match;
32
+ for (const font of fontStack) {
33
+ if (fonts.includes(font)) {
34
+ match = font;
35
+ break;
36
+ }
37
+ }
38
+ return [match || fonts[0]];
39
+ });
40
+ style.layers = mappedLayers;
41
+ return style;
42
+ }
43
+ function mapFontStacks(layers, callbackFn) {
44
+ return layers.map((layer) => {
45
+ if (layer.type !== "symbol" || !layer.layout || !layer.layout["text-font"])
46
+ return layer;
47
+ const textFont = layer.layout["text-font"];
48
+ let mappedValue;
49
+ if (isExpression(textFont)) {
50
+ mappedValue = mapArrayExpressionValue(textFont, callbackFn);
51
+ } else if (Array.isArray(textFont)) {
52
+ mappedValue = callbackFn(textFont);
53
+ } else {
54
+ console.warn(
55
+ "Deprecated function definitions are not supported, font stack has not been transformed."
56
+ );
57
+ console.dir(textFont, { depth: null });
58
+ return layer;
59
+ }
60
+ return {
61
+ ...layer,
62
+ layout: {
63
+ ...layer.layout,
64
+ "text-font": mappedValue
65
+ }
66
+ };
67
+ });
68
+ }
69
+ function isExpression(value) {
70
+ return Array.isArray(value) && value.length > 0 && typeof value[0] === "string" && value[0] in import_maplibre_gl_style_spec.expressions;
71
+ }
72
+ function mapArrayExpressionValue(expression, callbackFn) {
73
+ if (expression[0] === "literal" && Array.isArray(expression[1])) {
74
+ return ["literal", callbackFn(expression[1])];
75
+ } else {
76
+ return [
77
+ expression[0],
78
+ ...expression.slice(1).map(
79
+ // @ts-ignore
80
+ (x) => {
81
+ if (isExpression(x)) {
82
+ return mapArrayExpressionValue(x, callbackFn);
83
+ } else {
84
+ return x;
85
+ }
86
+ }
87
+ )
88
+ ];
89
+ }
90
+ }
91
+ function assertTileJSON(tilejson) {
92
+ if (typeof tilejson !== "object" || tilejson === null) {
93
+ throw new Error("Invalid TileJSON");
94
+ }
95
+ if (!("tiles" in tilejson) || !Array.isArray(tilejson.tiles) || tilejson.tiles.length === 0 || tilejson.tiles.some((tile) => typeof tile !== "string")) {
96
+ throw new Error("Invalid TileJSON: missing or invalid tiles property");
97
+ }
98
+ }
99
+ const validateStyle = (
100
+ /** @type {{ (style: unknown): style is StyleSpecification, errors: ValidationError[] }} */
101
+ (style) => {
102
+ validateStyle.errors = (0, import_maplibre_gl_style_spec.validateStyleMin)(
103
+ /** @type {StyleSpecification} */
104
+ style
105
+ );
106
+ if (validateStyle.errors.length) return false;
107
+ return true;
108
+ }
109
+ );
110
+ function isInlinedSource(source) {
111
+ if (source.type === "geojson") {
112
+ return typeof source.data === "object";
113
+ } else if (source.type === "vector" || source.type === "raster" || source.type === "raster-dem") {
114
+ return "tiles" in source;
115
+ } else {
116
+ return true;
117
+ }
118
+ }
119
+ // Annotate the CommonJS export names for ESM import in node:
120
+ 0 && (module.exports = {
121
+ assertTileJSON,
122
+ isInlinedSource,
123
+ mapFontStacks,
124
+ replaceFontStacks,
125
+ validateStyle
126
+ });
@@ -0,0 +1,69 @@
1
+ import { BBox } from './geo.cjs';
2
+ import { I as InlinedSource } from '../types-B4Xn1F9K.cjs';
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 'stream';
7
+ import 'type-fest';
8
+ import 'readable-stream';
9
+ import 'events';
10
+
11
+ /** @import {StyleSpecification, ExpressionSpecification, ValidationError} from '@maplibre/maplibre-gl-style-spec' */
12
+ /**
13
+ * For a given style, replace all font stacks (`text-field` properties) with the
14
+ * provided fonts. If no matching font is found, the first font in the stack is
15
+ * used.
16
+ *
17
+ * *Modifies the input style object*
18
+ *
19
+ * @param {StyleSpecification} style
20
+ * @param {string[]} fonts
21
+ */
22
+ declare function replaceFontStacks(style: StyleSpecification, fonts: string[]): StyleSpecification;
23
+ /**
24
+ * From given style layers, create a new style by calling the provided callback
25
+ * function on every font stack defined in the style.
26
+ *
27
+ * @param {StyleSpecification['layers']} layers
28
+ * @param {(fontStack: string[]) => string[]} callbackFn
29
+ * @returns {StyleSpecification['layers']}
30
+ */
31
+ declare function mapFontStacks(layers: StyleSpecification["layers"], callbackFn: (fontStack: string[]) => string[]): StyleSpecification["layers"];
32
+ /**
33
+ * @typedef {object} TileJSONPartial
34
+ * @property {string[]} tiles
35
+ * @property {string} [description]
36
+ * @property {string} [attribution]
37
+ * @property {object[]} [vector_layers]
38
+ * @property {import('./geo.js').BBox} [bounds]
39
+ * @property {number} [maxzoom]
40
+ * @property {number} [minzoom]
41
+ */
42
+ /**
43
+ *
44
+ * @param {unknown} tilejson
45
+ * @returns {asserts tilejson is TileJSONPartial}
46
+ */
47
+ declare function assertTileJSON(tilejson: unknown): asserts tilejson is TileJSONPartial;
48
+ /**
49
+ * Check whether a source is already inlined (e.g. does not reference a TileJSON or GeoJSON url)
50
+ *
51
+ * @param {import('@maplibre/maplibre-gl-style-spec').SourceSpecification} source
52
+ * @returns {source is import('../types.js').InlinedSource}
53
+ */
54
+ declare function isInlinedSource(source: _maplibre_maplibre_gl_style_spec.SourceSpecification): source is InlinedSource;
55
+ declare const validateStyle: {
56
+ (style: unknown): style is StyleSpecification;
57
+ errors: ValidationError[];
58
+ };
59
+ type TileJSONPartial = {
60
+ tiles: string[];
61
+ description?: string | undefined;
62
+ attribution?: string | undefined;
63
+ vector_layers?: object[] | undefined;
64
+ bounds?: BBox | undefined;
65
+ maxzoom?: number | undefined;
66
+ minzoom?: number | undefined;
67
+ };
68
+
69
+ export { type TileJSONPartial, assertTileJSON, isInlinedSource, mapFontStacks, replaceFontStacks, validateStyle };
@@ -1,3 +1,13 @@
1
+ import { BBox } from './geo.js';
2
+ import { I as InlinedSource } from '../types-B4Xn1F9K.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 'stream';
7
+ import 'type-fest';
8
+ import 'readable-stream';
9
+ import 'events';
10
+
1
11
  /** @import {StyleSpecification, ExpressionSpecification, ValidationError} from '@maplibre/maplibre-gl-style-spec' */
2
12
  /**
3
13
  * For a given style, replace all font stacks (`text-field` properties) with the
@@ -9,7 +19,7 @@
9
19
  * @param {StyleSpecification} style
10
20
  * @param {string[]} fonts
11
21
  */
12
- export function replaceFontStacks(style: StyleSpecification, fonts: string[]): StyleSpecification;
22
+ declare function replaceFontStacks(style: StyleSpecification, fonts: string[]): StyleSpecification;
13
23
  /**
14
24
  * From given style layers, create a new style by calling the provided callback
15
25
  * function on every font stack defined in the style.
@@ -18,7 +28,7 @@ export function replaceFontStacks(style: StyleSpecification, fonts: string[]): S
18
28
  * @param {(fontStack: string[]) => string[]} callbackFn
19
29
  * @returns {StyleSpecification['layers']}
20
30
  */
21
- export function mapFontStacks(layers: StyleSpecification["layers"], callbackFn: (fontStack: string[]) => string[]): StyleSpecification["layers"];
31
+ declare function mapFontStacks(layers: StyleSpecification["layers"], callbackFn: (fontStack: string[]) => string[]): StyleSpecification["layers"];
22
32
  /**
23
33
  * @typedef {object} TileJSONPartial
24
34
  * @property {string[]} tiles
@@ -34,26 +44,26 @@ export function mapFontStacks(layers: StyleSpecification["layers"], callbackFn:
34
44
  * @param {unknown} tilejson
35
45
  * @returns {asserts tilejson is TileJSONPartial}
36
46
  */
37
- export function assertTileJSON(tilejson: unknown): asserts tilejson is TileJSONPartial;
47
+ declare function assertTileJSON(tilejson: unknown): asserts tilejson is TileJSONPartial;
38
48
  /**
39
49
  * Check whether a source is already inlined (e.g. does not reference a TileJSON or GeoJSON url)
40
50
  *
41
51
  * @param {import('@maplibre/maplibre-gl-style-spec').SourceSpecification} source
42
52
  * @returns {source is import('../types.js').InlinedSource}
43
53
  */
44
- export function isInlinedSource(source: import("@maplibre/maplibre-gl-style-spec").SourceSpecification): source is import("../types.js").InlinedSource;
45
- export const validateStyle: {
54
+ declare function isInlinedSource(source: _maplibre_maplibre_gl_style_spec.SourceSpecification): source is InlinedSource;
55
+ declare const validateStyle: {
46
56
  (style: unknown): style is StyleSpecification;
47
57
  errors: ValidationError[];
48
58
  };
49
- export type TileJSONPartial = {
59
+ type TileJSONPartial = {
50
60
  tiles: string[];
51
61
  description?: string | undefined;
52
62
  attribution?: string | undefined;
53
63
  vector_layers?: object[] | undefined;
54
- bounds?: import("./geo.js").BBox | undefined;
64
+ bounds?: BBox | undefined;
55
65
  maxzoom?: number | undefined;
56
66
  minzoom?: number | undefined;
57
67
  };
58
- import type { StyleSpecification } from '@maplibre/maplibre-gl-style-spec';
59
- import type { ValidationError } from '@maplibre/maplibre-gl-style-spec';
68
+
69
+ export { type TileJSONPartial, assertTileJSON, isInlinedSource, mapFontStacks, replaceFontStacks, validateStyle };
@@ -0,0 +1,98 @@
1
+ import { expressions, validateStyleMin } from "@maplibre/maplibre-gl-style-spec";
2
+ function replaceFontStacks(style, fonts) {
3
+ const mappedLayers = mapFontStacks(style.layers, (fontStack) => {
4
+ let match;
5
+ for (const font of fontStack) {
6
+ if (fonts.includes(font)) {
7
+ match = font;
8
+ break;
9
+ }
10
+ }
11
+ return [match || fonts[0]];
12
+ });
13
+ style.layers = mappedLayers;
14
+ return style;
15
+ }
16
+ function mapFontStacks(layers, callbackFn) {
17
+ return layers.map((layer) => {
18
+ if (layer.type !== "symbol" || !layer.layout || !layer.layout["text-font"])
19
+ return layer;
20
+ const textFont = layer.layout["text-font"];
21
+ let mappedValue;
22
+ if (isExpression(textFont)) {
23
+ mappedValue = mapArrayExpressionValue(textFont, callbackFn);
24
+ } else if (Array.isArray(textFont)) {
25
+ mappedValue = callbackFn(textFont);
26
+ } else {
27
+ console.warn(
28
+ "Deprecated function definitions are not supported, font stack has not been transformed."
29
+ );
30
+ console.dir(textFont, { depth: null });
31
+ return layer;
32
+ }
33
+ return {
34
+ ...layer,
35
+ layout: {
36
+ ...layer.layout,
37
+ "text-font": mappedValue
38
+ }
39
+ };
40
+ });
41
+ }
42
+ function isExpression(value) {
43
+ return Array.isArray(value) && value.length > 0 && typeof value[0] === "string" && value[0] in expressions;
44
+ }
45
+ function mapArrayExpressionValue(expression, callbackFn) {
46
+ if (expression[0] === "literal" && Array.isArray(expression[1])) {
47
+ return ["literal", callbackFn(expression[1])];
48
+ } else {
49
+ return [
50
+ expression[0],
51
+ ...expression.slice(1).map(
52
+ // @ts-ignore
53
+ (x) => {
54
+ if (isExpression(x)) {
55
+ return mapArrayExpressionValue(x, callbackFn);
56
+ } else {
57
+ return x;
58
+ }
59
+ }
60
+ )
61
+ ];
62
+ }
63
+ }
64
+ function assertTileJSON(tilejson) {
65
+ if (typeof tilejson !== "object" || tilejson === null) {
66
+ throw new Error("Invalid TileJSON");
67
+ }
68
+ if (!("tiles" in tilejson) || !Array.isArray(tilejson.tiles) || tilejson.tiles.length === 0 || tilejson.tiles.some((tile) => typeof tile !== "string")) {
69
+ throw new Error("Invalid TileJSON: missing or invalid tiles property");
70
+ }
71
+ }
72
+ const validateStyle = (
73
+ /** @type {{ (style: unknown): style is StyleSpecification, errors: ValidationError[] }} */
74
+ (style) => {
75
+ validateStyle.errors = validateStyleMin(
76
+ /** @type {StyleSpecification} */
77
+ style
78
+ );
79
+ if (validateStyle.errors.length) return false;
80
+ return true;
81
+ }
82
+ );
83
+ function isInlinedSource(source) {
84
+ if (source.type === "geojson") {
85
+ return typeof source.data === "object";
86
+ } else if (source.type === "vector" || source.type === "raster" || source.type === "raster-dem") {
87
+ return "tiles" in source;
88
+ } else {
89
+ return true;
90
+ }
91
+ }
92
+ export {
93
+ assertTileJSON,
94
+ isInlinedSource,
95
+ mapFontStacks,
96
+ replaceFontStacks,
97
+ validateStyle
98
+ };
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var templates_exports = {};
20
+ __export(templates_exports, {
21
+ GLYPH_URI: () => GLYPH_URI,
22
+ STYLE_FILE: () => STYLE_FILE,
23
+ URI_BASE: () => URI_BASE,
24
+ URI_SCHEME: () => URI_SCHEME,
25
+ getContentType: () => getContentType,
26
+ getGlyphFilename: () => getGlyphFilename,
27
+ getResourceType: () => getResourceType,
28
+ getSpriteFilename: () => getSpriteFilename,
29
+ getSpriteUri: () => getSpriteUri,
30
+ getTileFilename: () => getTileFilename,
31
+ getTileUri: () => getTileUri,
32
+ replaceVariables: () => replaceVariables
33
+ });
34
+ module.exports = __toCommonJS(templates_exports);
35
+ const URI_SCHEME = "smp";
36
+ const URI_BASE = URI_SCHEME + "://maps.v1/";
37
+ const STYLE_FILE = "style.json";
38
+ const SOURCES_FOLDER = "s";
39
+ const SPRITES_FOLDER = "sprites";
40
+ const FONTS_FOLDER = "fonts";
41
+ const TILE_FILE = SOURCES_FOLDER + "/{sourceId}/{z}/{x}/{y}{ext}";
42
+ const SPRITE_FILE = SPRITES_FOLDER + "/{id}/sprite{pixelRatio}{ext}";
43
+ const GLYPH_FILE = FONTS_FOLDER + "/{fontstack}/{range}.pbf.gz";
44
+ const GLYPH_URI = URI_BASE + GLYPH_FILE;
45
+ const pathToResouceType = (
46
+ /** @type {const} */
47
+ {
48
+ [TILE_FILE.split("/")[0] + "/"]: "tile",
49
+ [SPRITE_FILE.split("/")[0] + "/"]: "sprite",
50
+ [GLYPH_FILE.split("/")[0] + "/"]: "glyph"
51
+ }
52
+ );
53
+ function getResourceType(path) {
54
+ if (path === "style.json") return "style";
55
+ for (const [prefix, type] of Object.entries(pathToResouceType)) {
56
+ if (path.startsWith(prefix)) return type;
57
+ }
58
+ throw new Error(`Unknown resource type for path: ${path}`);
59
+ }
60
+ function getContentType(path) {
61
+ if (path.endsWith(".json")) return "application/json; charset=utf-8";
62
+ if (path.endsWith(".pbf.gz") || path.endsWith(".pbf"))
63
+ return "application/x-protobuf";
64
+ if (path.endsWith(".png")) return "image/png";
65
+ if (path.endsWith(".jpg")) return "image/jpeg";
66
+ if (path.endsWith(".webp")) return "image/webp";
67
+ if (path.endsWith(".mvt.gz") || path.endsWith(".mvt"))
68
+ return "application/vnd.mapbox-vector-tile";
69
+ throw new Error(`Unknown content type for path: ${path}`);
70
+ }
71
+ function getTileFilename({ sourceId, z, x, y, format }) {
72
+ const ext = "." + format + (format === "mvt" ? ".gz" : "");
73
+ return replaceVariables(TILE_FILE, { sourceId, z, x, y, ext });
74
+ }
75
+ function getSpriteFilename({ id, pixelRatio, ext }) {
76
+ return replaceVariables(SPRITE_FILE, {
77
+ id,
78
+ pixelRatio: getPixelRatioString(pixelRatio),
79
+ ext
80
+ });
81
+ }
82
+ function getGlyphFilename({ fontstack, range }) {
83
+ return replaceVariables(GLYPH_FILE, { fontstack, range });
84
+ }
85
+ function getSpriteUri(id = "default") {
86
+ return URI_BASE + replaceVariables(SPRITE_FILE, { id, pixelRatio: "", ext: "" });
87
+ }
88
+ function getTileUri({ sourceId, format }) {
89
+ const ext = "." + format + (format === "mvt" ? ".gz" : "");
90
+ return URI_BASE + TILE_FILE.replace("{sourceId}", sourceId).replace("{ext}", ext);
91
+ }
92
+ function getPixelRatioString(pixelRatio) {
93
+ return pixelRatio === 1 ? "" : `@${pixelRatio}x`;
94
+ }
95
+ function replaceVariables(template, variables) {
96
+ return template.replace(/{(.*?)}/g, (match, varName) => {
97
+ return varName in variables ? String(variables[varName]) : match;
98
+ });
99
+ }
100
+ // Annotate the CommonJS export names for ESM import in node:
101
+ 0 && (module.exports = {
102
+ GLYPH_URI,
103
+ STYLE_FILE,
104
+ URI_BASE,
105
+ URI_SCHEME,
106
+ getContentType,
107
+ getGlyphFilename,
108
+ getResourceType,
109
+ getSpriteFilename,
110
+ getSpriteUri,
111
+ getTileFilename,
112
+ getTileUri,
113
+ replaceVariables
114
+ });
@@ -0,0 +1,78 @@
1
+ import * as type_fest from 'type-fest';
2
+ import { T as TileInfo, d as GlyphRange, c as TileFormat } from '../types-B4Xn1F9K.cjs';
3
+ import '@maplibre/maplibre-gl-style-spec';
4
+ import 'geojson';
5
+ import 'stream';
6
+ import 'readable-stream';
7
+ import 'events';
8
+
9
+ /**
10
+ * @param {string} path
11
+ * @returns
12
+ */
13
+ declare function getResourceType(path: string): "sprite" | "style" | "tile" | "glyph";
14
+ /**
15
+ * Determine the content type of a file based on its extension.
16
+ *
17
+ * @param {string} path
18
+ */
19
+ declare function getContentType(path: string): "application/json; charset=utf-8" | "application/x-protobuf" | "image/png" | "image/jpeg" | "image/webp" | "application/vnd.mapbox-vector-tile";
20
+ /**
21
+ * Get the filename for a tile, given the TileInfo
22
+ *
23
+ * @param {import("type-fest").SetRequired<import("../writer.js").TileInfo, 'format'>} tileInfo
24
+ * @returns
25
+ */
26
+ declare function getTileFilename({ sourceId, z, x, y, format }: type_fest.SetRequired<TileInfo, "format">): string;
27
+ /**
28
+ * Get a filename for a sprite file, given the sprite id, pixel ratio and extension
29
+ *
30
+ * @param {{ id: string, pixelRatio: number, ext: '.json' | '.png'}} spriteInfo
31
+ */
32
+ declare function getSpriteFilename({ id, pixelRatio, ext }: {
33
+ id: string;
34
+ pixelRatio: number;
35
+ ext: ".json" | ".png";
36
+ }): string;
37
+ /**
38
+ * Get the filename for a glyph file, given the fontstack and range
39
+ *
40
+ * @param {object} options
41
+ * @param {string} options.fontstack
42
+ * @param {import("../writer.js").GlyphRange} options.range
43
+ */
44
+ declare function getGlyphFilename({ fontstack, range }: {
45
+ fontstack: string;
46
+ range: GlyphRange;
47
+ }): string;
48
+ /**
49
+ * Get the URI template for the sprites in the style
50
+ */
51
+ declare function getSpriteUri(id?: string): string;
52
+ /**
53
+ * Get the URI template for tiles in the style
54
+ *
55
+ * @param {object} opts
56
+ * @param {string} opts.sourceId
57
+ * @param {import("../writer.js").TileFormat} opts.format
58
+ * @returns
59
+ */
60
+ declare function getTileUri({ sourceId, format }: {
61
+ sourceId: string;
62
+ format: TileFormat;
63
+ }): string;
64
+ /**
65
+ * Replaces variables in a string with values provided in an object. Variables
66
+ * in the string are denoted by curly braces, e.g., {variableName}.
67
+ *
68
+ * @param {string} template - The string containing variables wrapped in curly braces.
69
+ * @param {Record<string, string | number>} variables - An object where the keys correspond to variable names and values correspond to the replacement values.
70
+ * @returns {string} The string with the variables replaced by their corresponding values.
71
+ */
72
+ declare function replaceVariables(template: string, variables: Record<string, string | number>): string;
73
+ declare const URI_SCHEME: "smp";
74
+ declare const URI_BASE: string;
75
+ declare const STYLE_FILE: "style.json";
76
+ declare const GLYPH_URI: string;
77
+
78
+ export { GLYPH_URI, STYLE_FILE, URI_BASE, URI_SCHEME, getContentType, getGlyphFilename, getResourceType, getSpriteFilename, getSpriteUri, getTileFilename, getTileUri, replaceVariables };