styled-map-package-api 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 (71) hide show
  1. package/dist/download.cjs +100 -0
  2. package/dist/download.d.cts +64 -0
  3. package/dist/download.d.ts +64 -0
  4. package/dist/download.js +76 -0
  5. package/dist/from-mbtiles.cjs +81 -0
  6. package/dist/from-mbtiles.d.cts +10 -0
  7. package/dist/from-mbtiles.d.ts +10 -0
  8. package/dist/from-mbtiles.js +57 -0
  9. package/dist/index.cjs +46 -0
  10. package/dist/index.d.cts +25 -0
  11. package/dist/index.d.ts +25 -0
  12. package/dist/index.js +16 -0
  13. package/dist/reader.cjs +287 -0
  14. package/dist/reader.d.cts +68 -0
  15. package/dist/reader.d.ts +68 -0
  16. package/dist/reader.js +259 -0
  17. package/dist/server.cjs +73 -0
  18. package/dist/server.d.cts +46 -0
  19. package/dist/server.d.ts +46 -0
  20. package/dist/server.js +49 -0
  21. package/dist/style-downloader.cjs +314 -0
  22. package/dist/style-downloader.d.cts +119 -0
  23. package/dist/style-downloader.d.ts +119 -0
  24. package/dist/style-downloader.js +290 -0
  25. package/dist/tile-downloader.cjs +156 -0
  26. package/dist/tile-downloader.d.cts +83 -0
  27. package/dist/tile-downloader.d.ts +83 -0
  28. package/dist/tile-downloader.js +124 -0
  29. package/dist/types-CJq90eOB.d.cts +184 -0
  30. package/dist/types-CJq90eOB.d.ts +184 -0
  31. package/dist/utils/errors.cjs +41 -0
  32. package/dist/utils/errors.d.cts +18 -0
  33. package/dist/utils/errors.d.ts +18 -0
  34. package/dist/utils/errors.js +16 -0
  35. package/dist/utils/fetch.cjs +97 -0
  36. package/dist/utils/fetch.d.cts +50 -0
  37. package/dist/utils/fetch.d.ts +50 -0
  38. package/dist/utils/fetch.js +63 -0
  39. package/dist/utils/file-formats.cjs +96 -0
  40. package/dist/utils/file-formats.d.cts +33 -0
  41. package/dist/utils/file-formats.d.ts +33 -0
  42. package/dist/utils/file-formats.js +70 -0
  43. package/dist/utils/geo.cjs +84 -0
  44. package/dist/utils/geo.d.cts +46 -0
  45. package/dist/utils/geo.d.ts +46 -0
  46. package/dist/utils/geo.js +56 -0
  47. package/dist/utils/mapbox.cjs +121 -0
  48. package/dist/utils/mapbox.d.cts +43 -0
  49. package/dist/utils/mapbox.d.ts +43 -0
  50. package/dist/utils/mapbox.js +91 -0
  51. package/dist/utils/misc.cjs +39 -0
  52. package/dist/utils/misc.d.cts +22 -0
  53. package/dist/utils/misc.d.ts +22 -0
  54. package/dist/utils/misc.js +13 -0
  55. package/dist/utils/streams.cjs +99 -0
  56. package/dist/utils/streams.d.cts +49 -0
  57. package/dist/utils/streams.d.ts +49 -0
  58. package/dist/utils/streams.js +73 -0
  59. package/dist/utils/style.cjs +126 -0
  60. package/dist/utils/style.d.cts +67 -0
  61. package/dist/utils/style.d.ts +67 -0
  62. package/dist/utils/style.js +98 -0
  63. package/dist/utils/templates.cjs +124 -0
  64. package/dist/utils/templates.d.cts +80 -0
  65. package/dist/utils/templates.d.ts +80 -0
  66. package/dist/utils/templates.js +85 -0
  67. package/dist/writer.cjs +465 -0
  68. package/dist/writer.d.cts +5 -0
  69. package/dist/writer.d.ts +5 -0
  70. package/dist/writer.js +452 -0
  71. package/package.json +161 -0
@@ -0,0 +1,73 @@
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
+ };
@@ -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,67 @@
1
+ import { BBox } from './geo.cjs';
2
+ import { I as InlinedSource } from '../types-CJq90eOB.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
+ import 'events';
8
+
9
+ /** @import {StyleSpecification, ExpressionSpecification, ValidationError} from '@maplibre/maplibre-gl-style-spec' */
10
+ /**
11
+ * For a given style, replace all font stacks (`text-field` properties) with the
12
+ * provided fonts. If no matching font is found, the first font in the stack is
13
+ * used.
14
+ *
15
+ * *Modifies the input style object*
16
+ *
17
+ * @param {StyleSpecification} style
18
+ * @param {string[]} fonts
19
+ */
20
+ declare function replaceFontStacks(style: StyleSpecification, fonts: string[]): StyleSpecification;
21
+ /**
22
+ * From given style layers, create a new style by calling the provided callback
23
+ * function on every font stack defined in the style.
24
+ *
25
+ * @param {StyleSpecification['layers']} layers
26
+ * @param {(fontStack: string[]) => string[]} callbackFn
27
+ * @returns {StyleSpecification['layers']}
28
+ */
29
+ declare function mapFontStacks(layers: StyleSpecification["layers"], callbackFn: (fontStack: string[]) => string[]): StyleSpecification["layers"];
30
+ /**
31
+ * @typedef {object} TileJSONPartial
32
+ * @property {string[]} tiles
33
+ * @property {string} [description]
34
+ * @property {string} [attribution]
35
+ * @property {object[]} [vector_layers]
36
+ * @property {import('./geo.js').BBox} [bounds]
37
+ * @property {number} [maxzoom]
38
+ * @property {number} [minzoom]
39
+ */
40
+ /**
41
+ *
42
+ * @param {unknown} tilejson
43
+ * @returns {asserts tilejson is TileJSONPartial}
44
+ */
45
+ declare function assertTileJSON(tilejson: unknown): asserts tilejson is TileJSONPartial;
46
+ /**
47
+ * Check whether a source is already inlined (e.g. does not reference a TileJSON or GeoJSON url)
48
+ *
49
+ * @param {import('@maplibre/maplibre-gl-style-spec').SourceSpecification} source
50
+ * @returns {source is import('../types.js').InlinedSource}
51
+ */
52
+ declare function isInlinedSource(source: _maplibre_maplibre_gl_style_spec.SourceSpecification): source is InlinedSource;
53
+ declare const validateStyle: {
54
+ (style: unknown): style is StyleSpecification;
55
+ errors: ValidationError[];
56
+ };
57
+ type TileJSONPartial = {
58
+ tiles: string[];
59
+ description?: string | undefined;
60
+ attribution?: string | undefined;
61
+ vector_layers?: object[] | undefined;
62
+ bounds?: BBox | undefined;
63
+ maxzoom?: number | undefined;
64
+ minzoom?: number | undefined;
65
+ };
66
+
67
+ export { type TileJSONPartial, assertTileJSON, isInlinedSource, mapFontStacks, replaceFontStacks, validateStyle };
@@ -0,0 +1,67 @@
1
+ import { BBox } from './geo.js';
2
+ import { I as InlinedSource } from '../types-CJq90eOB.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
+ import 'events';
8
+
9
+ /** @import {StyleSpecification, ExpressionSpecification, ValidationError} from '@maplibre/maplibre-gl-style-spec' */
10
+ /**
11
+ * For a given style, replace all font stacks (`text-field` properties) with the
12
+ * provided fonts. If no matching font is found, the first font in the stack is
13
+ * used.
14
+ *
15
+ * *Modifies the input style object*
16
+ *
17
+ * @param {StyleSpecification} style
18
+ * @param {string[]} fonts
19
+ */
20
+ declare function replaceFontStacks(style: StyleSpecification, fonts: string[]): StyleSpecification;
21
+ /**
22
+ * From given style layers, create a new style by calling the provided callback
23
+ * function on every font stack defined in the style.
24
+ *
25
+ * @param {StyleSpecification['layers']} layers
26
+ * @param {(fontStack: string[]) => string[]} callbackFn
27
+ * @returns {StyleSpecification['layers']}
28
+ */
29
+ declare function mapFontStacks(layers: StyleSpecification["layers"], callbackFn: (fontStack: string[]) => string[]): StyleSpecification["layers"];
30
+ /**
31
+ * @typedef {object} TileJSONPartial
32
+ * @property {string[]} tiles
33
+ * @property {string} [description]
34
+ * @property {string} [attribution]
35
+ * @property {object[]} [vector_layers]
36
+ * @property {import('./geo.js').BBox} [bounds]
37
+ * @property {number} [maxzoom]
38
+ * @property {number} [minzoom]
39
+ */
40
+ /**
41
+ *
42
+ * @param {unknown} tilejson
43
+ * @returns {asserts tilejson is TileJSONPartial}
44
+ */
45
+ declare function assertTileJSON(tilejson: unknown): asserts tilejson is TileJSONPartial;
46
+ /**
47
+ * Check whether a source is already inlined (e.g. does not reference a TileJSON or GeoJSON url)
48
+ *
49
+ * @param {import('@maplibre/maplibre-gl-style-spec').SourceSpecification} source
50
+ * @returns {source is import('../types.js').InlinedSource}
51
+ */
52
+ declare function isInlinedSource(source: _maplibre_maplibre_gl_style_spec.SourceSpecification): source is InlinedSource;
53
+ declare const validateStyle: {
54
+ (style: unknown): style is StyleSpecification;
55
+ errors: ValidationError[];
56
+ };
57
+ type TileJSONPartial = {
58
+ tiles: string[];
59
+ description?: string | undefined;
60
+ attribution?: string | undefined;
61
+ vector_layers?: object[] | undefined;
62
+ bounds?: BBox | undefined;
63
+ maxzoom?: number | undefined;
64
+ minzoom?: number | undefined;
65
+ };
66
+
67
+ 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,124 @@
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
+ });
@@ -0,0 +1,80 @@
1
+ import * as type_fest from 'type-fest';
2
+ import { d as GlyphRange, T as TileInfo, c as TileFormat } from '../types-CJq90eOB.cjs';
3
+ import '@maplibre/maplibre-gl-style-spec';
4
+ import 'geojson';
5
+ import 'events';
6
+
7
+ /**
8
+ * @param {string} path
9
+ * @returns
10
+ */
11
+ declare function getResourceType(path: string): "sprite" | "style" | "tile" | "glyph";
12
+ /**
13
+ * Determine the content type of a file based on its extension.
14
+ *
15
+ * @param {string} path
16
+ */
17
+ declare function getContentType(path: string): "application/json; charset=utf-8" | "application/x-protobuf" | "image/png" | "image/jpeg" | "image/webp" | "application/vnd.mapbox-vector-tile";
18
+ /**
19
+ * Get the filename for a tile, given the TileInfo
20
+ *
21
+ * @param {import("type-fest").SetRequired<import("../writer.js").TileInfo, 'format'>} tileInfo
22
+ * @returns
23
+ */
24
+ declare function getTileFilename({ sourceId, z, x, y, format }: type_fest.SetRequired<TileInfo, "format">): string;
25
+ /**
26
+ * Get a filename for a sprite file, given the sprite id, pixel ratio and extension
27
+ *
28
+ * @param {{ id: string, pixelRatio: number, ext: '.json' | '.png'}} spriteInfo
29
+ */
30
+ declare function getSpriteFilename({ id, pixelRatio, ext }: {
31
+ id: string;
32
+ pixelRatio: number;
33
+ ext: ".json" | ".png";
34
+ }): string;
35
+ /**
36
+ * Get the filename for a glyph file, given the fontstack and range
37
+ *
38
+ * @param {object} options
39
+ * @param {string} options.fontstack
40
+ * @param {import("../writer.js").GlyphRange} options.range
41
+ */
42
+ declare function getGlyphFilename({ fontstack, range }: {
43
+ fontstack: string;
44
+ range: GlyphRange;
45
+ }): string;
46
+ /**
47
+ * Get the URI template for the sprites in the style
48
+ */
49
+ declare function getSpriteUri(id?: string): string;
50
+ /**
51
+ * Get the URI template for tiles in the style
52
+ *
53
+ * @param {object} opts
54
+ * @param {string} opts.sourceId
55
+ * @param {import("../writer.js").TileFormat} opts.format
56
+ * @returns
57
+ */
58
+ declare function getTileUri({ sourceId, format }: {
59
+ sourceId: string;
60
+ format: TileFormat;
61
+ }): string;
62
+ /**
63
+ * Replaces variables in a string with values provided in an object. Variables
64
+ * in the string are denoted by curly braces, e.g., {variableName}.
65
+ *
66
+ * @param {string} template - The string containing variables wrapped in curly braces.
67
+ * @param {Record<string, string | number>} variables - An object where the keys correspond to variable names and values correspond to the replacement values.
68
+ * @returns {string} The string with the variables replaced by their corresponding values.
69
+ */
70
+ declare function replaceVariables(template: string, variables: Record<string, string | number>): string;
71
+ declare const URI_SCHEME: "smp";
72
+ declare const URI_BASE: string;
73
+ declare const VERSION_FILE: "VERSION";
74
+ declare const FORMAT_VERSION: "1.0";
75
+ declare const STYLE_FILE: "style.json";
76
+ declare const SOURCES_FOLDER: "s";
77
+ declare const FONTS_FOLDER: "fonts";
78
+ declare const GLYPH_URI: string;
79
+
80
+ 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 };