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,13 +0,0 @@
1
- function clone(obj) {
2
- return JSON.parse(JSON.stringify(obj));
3
- }
4
- function noop() {
5
- }
6
- function hasOwn(obj, key) {
7
- return Object.hasOwn(obj, key);
8
- }
9
- export {
10
- clone,
11
- hasOwn,
12
- noop
13
- };
@@ -1,99 +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 streams_exports = {};
20
- __export(streams_exports, {
21
- ProgressStream: () => ProgressStream,
22
- readableFromAsync: () => readableFromAsync,
23
- writeStreamFromAsync: () => writeStreamFromAsync
24
- });
25
- module.exports = __toCommonJS(streams_exports);
26
- function readableFromAsync(iterable) {
27
- if (typeof ReadableStream.from === "function") {
28
- return ReadableStream.from(iterable);
29
- }
30
- const iterator = iterable[Symbol.asyncIterator]();
31
- return new ReadableStream({
32
- async pull(controller) {
33
- const { value, done } = await iterator.next();
34
- if (done) {
35
- controller.close();
36
- } else {
37
- controller.enqueue(value);
38
- }
39
- },
40
- async cancel(reason) {
41
- await iterator.return?.(reason);
42
- }
43
- });
44
- }
45
- function writeStreamFromAsync(fn, { concurrency = 16 } = {}) {
46
- const pending = /* @__PURE__ */ new Set();
47
- return new WritableStream(
48
- {
49
- write(chunk) {
50
- const p = fn(...chunk);
51
- pending.add(p);
52
- p.finally(() => pending.delete(p));
53
- if (pending.size >= concurrency) {
54
- return Promise.race(pending);
55
- }
56
- },
57
- async close() {
58
- await Promise.all(pending);
59
- }
60
- },
61
- new CountQueuingStrategy({ highWaterMark: concurrency })
62
- );
63
- }
64
- class ProgressStream {
65
- #byteLength = 0;
66
- #ts;
67
- /**
68
- * @param {{ onprogress?: ProgressCallback }} [opts]
69
- */
70
- constructor({ onprogress } = {}) {
71
- const self = this;
72
- this.#ts = new TransformStream({
73
- transform(chunk, controller) {
74
- self.#byteLength += chunk.byteLength;
75
- onprogress?.({
76
- totalBytes: self.#byteLength,
77
- chunkBytes: chunk.byteLength
78
- });
79
- controller.enqueue(chunk);
80
- }
81
- });
82
- }
83
- get readable() {
84
- return this.#ts.readable;
85
- }
86
- get writable() {
87
- return this.#ts.writable;
88
- }
89
- /** Total bytes that have passed through this stream */
90
- get byteLength() {
91
- return this.#byteLength;
92
- }
93
- }
94
- // Annotate the CommonJS export names for ESM import in node:
95
- 0 && (module.exports = {
96
- ProgressStream,
97
- readableFromAsync,
98
- writeStreamFromAsync
99
- });
@@ -1,49 +0,0 @@
1
- import * as stream_web from 'stream/web';
2
-
3
- /**
4
- * Create a ReadableStream from an async iterable. Uses the native
5
- * `ReadableStream.from()` when available (Node 20+), otherwise falls back to a
6
- * manual approach for Node 18 compatibility.
7
- *
8
- * @template T
9
- * @param {AsyncIterable<T>} iterable
10
- * @returns {ReadableStream<T>}
11
- */
12
- declare function readableFromAsync<T>(iterable: AsyncIterable<T>): ReadableStream<T>;
13
- /**
14
- * Create a writable stream from an async function. Default concurrency is 16 -
15
- * this is the number of parallel functions that will be pending before
16
- * backpressure is applied on the stream.
17
- *
18
- * @template {(...args: any[]) => Promise<void>} T
19
- * @param {T} fn
20
- * @returns {WritableStream}
21
- */
22
- declare function writeStreamFromAsync<T extends (...args: any[]) => Promise<void>>(fn: T, { concurrency }?: {
23
- concurrency?: number | undefined;
24
- }): WritableStream;
25
- /** @typedef {(opts: { totalBytes: number, chunkBytes: number }) => void} ProgressCallback */
26
- /**
27
- * A web TransformStream that counts the bytes passing through it. Pass an
28
- * optional `onprogress` callback that will be called with the accumulated
29
- * total byte count and the chunk byte count after each chunk.
30
- */
31
- declare class ProgressStream {
32
- /**
33
- * @param {{ onprogress?: ProgressCallback }} [opts]
34
- */
35
- constructor({ onprogress }?: {
36
- onprogress?: ProgressCallback;
37
- });
38
- get readable(): stream_web.ReadableStream<any>;
39
- get writable(): stream_web.WritableStream<any>;
40
- /** Total bytes that have passed through this stream */
41
- get byteLength(): number;
42
- #private;
43
- }
44
- type ProgressCallback = (opts: {
45
- totalBytes: number;
46
- chunkBytes: number;
47
- }) => void;
48
-
49
- export { type ProgressCallback, ProgressStream, readableFromAsync, writeStreamFromAsync };
@@ -1,73 +0,0 @@
1
- function readableFromAsync(iterable) {
2
- if (typeof ReadableStream.from === "function") {
3
- return ReadableStream.from(iterable);
4
- }
5
- const iterator = iterable[Symbol.asyncIterator]();
6
- return new ReadableStream({
7
- async pull(controller) {
8
- const { value, done } = await iterator.next();
9
- if (done) {
10
- controller.close();
11
- } else {
12
- controller.enqueue(value);
13
- }
14
- },
15
- async cancel(reason) {
16
- await iterator.return?.(reason);
17
- }
18
- });
19
- }
20
- function writeStreamFromAsync(fn, { concurrency = 16 } = {}) {
21
- const pending = /* @__PURE__ */ new Set();
22
- return new WritableStream(
23
- {
24
- write(chunk) {
25
- const p = fn(...chunk);
26
- pending.add(p);
27
- p.finally(() => pending.delete(p));
28
- if (pending.size >= concurrency) {
29
- return Promise.race(pending);
30
- }
31
- },
32
- async close() {
33
- await Promise.all(pending);
34
- }
35
- },
36
- new CountQueuingStrategy({ highWaterMark: concurrency })
37
- );
38
- }
39
- class ProgressStream {
40
- #byteLength = 0;
41
- #ts;
42
- /**
43
- * @param {{ onprogress?: ProgressCallback }} [opts]
44
- */
45
- constructor({ onprogress } = {}) {
46
- const self = this;
47
- this.#ts = new TransformStream({
48
- transform(chunk, controller) {
49
- self.#byteLength += chunk.byteLength;
50
- onprogress?.({
51
- totalBytes: self.#byteLength,
52
- chunkBytes: chunk.byteLength
53
- });
54
- controller.enqueue(chunk);
55
- }
56
- });
57
- }
58
- get readable() {
59
- return this.#ts.readable;
60
- }
61
- get writable() {
62
- return this.#ts.writable;
63
- }
64
- /** Total bytes that have passed through this stream */
65
- get byteLength() {
66
- return this.#byteLength;
67
- }
68
- }
69
- export {
70
- ProgressStream,
71
- readableFromAsync,
72
- writeStreamFromAsync
73
- };
@@ -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,66 +0,0 @@
1
- import { BBox } from './geo.cjs';
2
- import { I as InlinedSource } from '../types-qfyJk4ot.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 'type-fest';
7
-
8
- /** @import {StyleSpecification, ExpressionSpecification, ValidationError} from '@maplibre/maplibre-gl-style-spec' */
9
- /**
10
- * For a given style, replace all font stacks (`text-field` properties) with the
11
- * provided fonts. If no matching font is found, the first font in the stack is
12
- * used.
13
- *
14
- * *Modifies the input style object*
15
- *
16
- * @param {StyleSpecification} style
17
- * @param {string[]} fonts
18
- */
19
- declare function replaceFontStacks(style: StyleSpecification, fonts: string[]): StyleSpecification;
20
- /**
21
- * From given style layers, create a new style by calling the provided callback
22
- * function on every font stack defined in the style.
23
- *
24
- * @param {StyleSpecification['layers']} layers
25
- * @param {(fontStack: string[]) => string[]} callbackFn
26
- * @returns {StyleSpecification['layers']}
27
- */
28
- declare function mapFontStacks(layers: StyleSpecification["layers"], callbackFn: (fontStack: string[]) => string[]): StyleSpecification["layers"];
29
- /**
30
- * @typedef {object} TileJSONPartial
31
- * @property {string[]} tiles
32
- * @property {string} [description]
33
- * @property {string} [attribution]
34
- * @property {object[]} [vector_layers]
35
- * @property {import('./geo.js').BBox} [bounds]
36
- * @property {number} [maxzoom]
37
- * @property {number} [minzoom]
38
- */
39
- /**
40
- *
41
- * @param {unknown} tilejson
42
- * @returns {asserts tilejson is TileJSONPartial}
43
- */
44
- declare function assertTileJSON(tilejson: unknown): asserts tilejson is TileJSONPartial;
45
- /**
46
- * Check whether a source is already inlined (e.g. does not reference a TileJSON or GeoJSON url)
47
- *
48
- * @param {import('@maplibre/maplibre-gl-style-spec').SourceSpecification} source
49
- * @returns {source is import('../types.js').InlinedSource}
50
- */
51
- declare function isInlinedSource(source: _maplibre_maplibre_gl_style_spec.SourceSpecification): source is InlinedSource;
52
- declare const validateStyle: {
53
- (style: unknown): style is StyleSpecification;
54
- errors: ValidationError[];
55
- };
56
- type TileJSONPartial = {
57
- tiles: string[];
58
- description?: string | undefined;
59
- attribution?: string | undefined;
60
- vector_layers?: object[] | undefined;
61
- bounds?: BBox | undefined;
62
- maxzoom?: number | undefined;
63
- minzoom?: number | undefined;
64
- };
65
-
66
- 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
- };
@@ -1,124 +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 templates_exports = {};
20
- __export(templates_exports, {
21
- FONTS_FOLDER: () => FONTS_FOLDER,
22
- FORMAT_VERSION: () => FORMAT_VERSION,
23
- GLYPH_URI: () => GLYPH_URI,
24
- SOURCES_FOLDER: () => SOURCES_FOLDER,
25
- STYLE_FILE: () => STYLE_FILE,
26
- URI_BASE: () => URI_BASE,
27
- URI_SCHEME: () => URI_SCHEME,
28
- VERSION_FILE: () => VERSION_FILE,
29
- getContentType: () => getContentType,
30
- getGlyphFilename: () => getGlyphFilename,
31
- getResourceType: () => getResourceType,
32
- getSpriteFilename: () => getSpriteFilename,
33
- getSpriteUri: () => getSpriteUri,
34
- getTileFilename: () => getTileFilename,
35
- getTileUri: () => getTileUri,
36
- replaceVariables: () => replaceVariables
37
- });
38
- module.exports = __toCommonJS(templates_exports);
39
- const URI_SCHEME = "smp";
40
- const URI_BASE = URI_SCHEME + "://maps.v1/";
41
- const VERSION_FILE = "VERSION";
42
- const FORMAT_VERSION = "1.0";
43
- const STYLE_FILE = "style.json";
44
- const SOURCES_FOLDER = "s";
45
- const SPRITES_FOLDER = "sprites";
46
- const FONTS_FOLDER = "fonts";
47
- const TILE_FILE = SOURCES_FOLDER + "/{sourceId}/{z}/{x}/{y}{ext}";
48
- const SPRITE_FILE = SPRITES_FOLDER + "/{id}/sprite{pixelRatio}{ext}";
49
- const GLYPH_FILE = FONTS_FOLDER + "/{fontstack}/{range}.pbf.gz";
50
- const GLYPH_URI = URI_BASE + GLYPH_FILE;
51
- const pathToResouceType = (
52
- /** @type {const} */
53
- {
54
- [TILE_FILE.split("/")[0] + "/"]: "tile",
55
- [SPRITE_FILE.split("/")[0] + "/"]: "sprite",
56
- [GLYPH_FILE.split("/")[0] + "/"]: "glyph"
57
- }
58
- );
59
- function getResourceType(path) {
60
- if (path === "style.json") return "style";
61
- for (const [prefix, type] of Object.entries(pathToResouceType)) {
62
- if (path.startsWith(prefix)) return type;
63
- }
64
- throw new Error(`Unknown resource type for path: ${path}`);
65
- }
66
- function getContentType(path) {
67
- if (path.endsWith(".json")) return "application/json; charset=utf-8";
68
- if (path.endsWith(".pbf.gz") || path.endsWith(".pbf"))
69
- return "application/x-protobuf";
70
- if (path.endsWith(".png")) return "image/png";
71
- if (path.endsWith(".jpg")) return "image/jpeg";
72
- if (path.endsWith(".webp")) return "image/webp";
73
- if (path.endsWith(".mvt.gz") || path.endsWith(".mvt"))
74
- return "application/vnd.mapbox-vector-tile";
75
- throw new Error(`Unknown content type for path: ${path}`);
76
- }
77
- function getTileFilename({ sourceId, z, x, y, format }) {
78
- const ext = "." + format + (format === "mvt" ? ".gz" : "");
79
- return replaceVariables(TILE_FILE, { sourceId, z, x, y, ext });
80
- }
81
- function getSpriteFilename({ id, pixelRatio, ext }) {
82
- return replaceVariables(SPRITE_FILE, {
83
- id,
84
- pixelRatio: getPixelRatioString(pixelRatio),
85
- ext
86
- });
87
- }
88
- function getGlyphFilename({ fontstack, range }) {
89
- return replaceVariables(GLYPH_FILE, { fontstack, range });
90
- }
91
- function getSpriteUri(id = "default") {
92
- return URI_BASE + replaceVariables(SPRITE_FILE, { id, pixelRatio: "", ext: "" });
93
- }
94
- function getTileUri({ sourceId, format }) {
95
- const ext = "." + format + (format === "mvt" ? ".gz" : "");
96
- return URI_BASE + TILE_FILE.replace("{sourceId}", sourceId).replace("{ext}", ext);
97
- }
98
- function getPixelRatioString(pixelRatio) {
99
- return pixelRatio === 1 ? "" : `@${pixelRatio}x`;
100
- }
101
- function replaceVariables(template, variables) {
102
- return template.replace(/{(.*?)}/g, (match, varName) => {
103
- return varName in variables ? String(variables[varName]) : match;
104
- });
105
- }
106
- // Annotate the CommonJS export names for ESM import in node:
107
- 0 && (module.exports = {
108
- FONTS_FOLDER,
109
- FORMAT_VERSION,
110
- GLYPH_URI,
111
- SOURCES_FOLDER,
112
- STYLE_FILE,
113
- URI_BASE,
114
- URI_SCHEME,
115
- VERSION_FILE,
116
- getContentType,
117
- getGlyphFilename,
118
- getResourceType,
119
- getSpriteFilename,
120
- getSpriteUri,
121
- getTileFilename,
122
- getTileUri,
123
- replaceVariables
124
- });