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,73 +0,0 @@
1
- import * as stream from 'stream';
2
- import * as readable_stream from 'readable-stream';
3
- import { Transform, TransformOptions } from 'readable-stream';
4
-
5
- /** @import { TransformOptions } from 'readable-stream' */
6
- /**
7
- * Create a writable stream from an async function. Default concurrecy is 16 -
8
- * this is the number of parallel functions that will be pending before
9
- * backpressure is applied on the stream.
10
- *
11
- * @template {(...args: any[]) => Promise<void>} T
12
- * @param {T} fn
13
- * @returns {import('readable-stream').Writable}
14
- */
15
- declare function writeStreamFromAsync<T extends (...args: any[]) => Promise<void>>(fn: T, { concurrency }?: {
16
- concurrency?: number | undefined;
17
- }): readable_stream.Writable;
18
- /**
19
- * From https://github.com/nodejs/node/blob/430c0269/lib/internal/webstreams/adapters.js#L509
20
- *
21
- * @param {ReadableStream} readableStream
22
- * @param {{
23
- * highWaterMark? : number,
24
- * encoding? : string,
25
- * objectMode? : boolean,
26
- * signal? : AbortSignal,
27
- * }} [options]
28
- * @returns {import('stream').Readable}
29
- */
30
- declare function fromWebReadableStream(readableStream: ReadableStream, options?: {
31
- highWaterMark?: number;
32
- encoding?: string;
33
- objectMode?: boolean;
34
- signal?: AbortSignal;
35
- }): stream.Readable;
36
- /**
37
- * @param {unknown} obj
38
- * @returns {obj is ReadableStream}
39
- */
40
- declare function isWebReadableStream(obj: unknown): obj is ReadableStream;
41
- /** @typedef {(opts: { totalBytes: number, chunkBytes: number }) => void} ProgressCallback */
42
- /** @typedef {TransformOptions & { onprogress?: ProgressCallback }} ProgressStreamOptions */
43
- /**
44
- * Passthrough stream that counts the bytes passing through it. Pass an optional
45
- * `onprogress` callback that will be called with the accumulated total byte
46
- * count and the chunk byte count after each chunk.
47
- * @extends {Transform}
48
- */
49
- declare class ProgressStream extends Transform {
50
- /**
51
- * @param {ProgressStreamOptions} [opts]
52
- */
53
- constructor({ onprogress, ...opts }?: ProgressStreamOptions);
54
- /** Total bytes that have passed through this stream */
55
- get byteLength(): number;
56
- /**
57
- * @override
58
- * @param {Buffer | Uint8Array} chunk
59
- * @param {Parameters<Transform['_transform']>[1]} encoding
60
- * @param {Parameters<Transform['_transform']>[2]} callback
61
- */
62
- override _transform(chunk: Buffer | Uint8Array, encoding: Parameters<Transform["_transform"]>[1], callback: Parameters<Transform["_transform"]>[2]): void;
63
- #private;
64
- }
65
- type ProgressCallback = (opts: {
66
- totalBytes: number;
67
- chunkBytes: number;
68
- }) => void;
69
- type ProgressStreamOptions = TransformOptions & {
70
- onprogress?: ProgressCallback;
71
- };
72
-
73
- export { type ProgressCallback, ProgressStream, type ProgressStreamOptions, fromWebReadableStream, isWebReadableStream, writeStreamFromAsync };
@@ -1,73 +0,0 @@
1
- import * as stream from 'stream';
2
- import * as readable_stream from 'readable-stream';
3
- import { Transform, TransformOptions } from 'readable-stream';
4
-
5
- /** @import { TransformOptions } from 'readable-stream' */
6
- /**
7
- * Create a writable stream from an async function. Default concurrecy is 16 -
8
- * this is the number of parallel functions that will be pending before
9
- * backpressure is applied on the stream.
10
- *
11
- * @template {(...args: any[]) => Promise<void>} T
12
- * @param {T} fn
13
- * @returns {import('readable-stream').Writable}
14
- */
15
- declare function writeStreamFromAsync<T extends (...args: any[]) => Promise<void>>(fn: T, { concurrency }?: {
16
- concurrency?: number | undefined;
17
- }): readable_stream.Writable;
18
- /**
19
- * From https://github.com/nodejs/node/blob/430c0269/lib/internal/webstreams/adapters.js#L509
20
- *
21
- * @param {ReadableStream} readableStream
22
- * @param {{
23
- * highWaterMark? : number,
24
- * encoding? : string,
25
- * objectMode? : boolean,
26
- * signal? : AbortSignal,
27
- * }} [options]
28
- * @returns {import('stream').Readable}
29
- */
30
- declare function fromWebReadableStream(readableStream: ReadableStream, options?: {
31
- highWaterMark?: number;
32
- encoding?: string;
33
- objectMode?: boolean;
34
- signal?: AbortSignal;
35
- }): stream.Readable;
36
- /**
37
- * @param {unknown} obj
38
- * @returns {obj is ReadableStream}
39
- */
40
- declare function isWebReadableStream(obj: unknown): obj is ReadableStream;
41
- /** @typedef {(opts: { totalBytes: number, chunkBytes: number }) => void} ProgressCallback */
42
- /** @typedef {TransformOptions & { onprogress?: ProgressCallback }} ProgressStreamOptions */
43
- /**
44
- * Passthrough stream that counts the bytes passing through it. Pass an optional
45
- * `onprogress` callback that will be called with the accumulated total byte
46
- * count and the chunk byte count after each chunk.
47
- * @extends {Transform}
48
- */
49
- declare class ProgressStream extends Transform {
50
- /**
51
- * @param {ProgressStreamOptions} [opts]
52
- */
53
- constructor({ onprogress, ...opts }?: ProgressStreamOptions);
54
- /** Total bytes that have passed through this stream */
55
- get byteLength(): number;
56
- /**
57
- * @override
58
- * @param {Buffer | Uint8Array} chunk
59
- * @param {Parameters<Transform['_transform']>[1]} encoding
60
- * @param {Parameters<Transform['_transform']>[2]} callback
61
- */
62
- override _transform(chunk: Buffer | Uint8Array, encoding: Parameters<Transform["_transform"]>[1], callback: Parameters<Transform["_transform"]>[2]): void;
63
- #private;
64
- }
65
- type ProgressCallback = (opts: {
66
- totalBytes: number;
67
- chunkBytes: number;
68
- }) => void;
69
- type ProgressStreamOptions = TransformOptions & {
70
- onprogress?: ProgressCallback;
71
- };
72
-
73
- export { type ProgressCallback, ProgressStream, type ProgressStreamOptions, fromWebReadableStream, isWebReadableStream, writeStreamFromAsync };
@@ -1,103 +0,0 @@
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
- };
@@ -1,126 +0,0 @@
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
- });
@@ -1,69 +0,0 @@
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,69 +0,0 @@
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
-
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,98 +0,0 @@
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
- };