@deck.gl-community/basemap-layers 9.3.0-beta.2

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 (62) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +14 -0
  3. package/dist/atmosphere-layer.d.ts +11 -0
  4. package/dist/atmosphere-layer.d.ts.map +1 -0
  5. package/dist/atmosphere-layer.js +15 -0
  6. package/dist/atmosphere-layer.js.map +1 -0
  7. package/dist/basemap-layer.d.ts +67 -0
  8. package/dist/basemap-layer.d.ts.map +1 -0
  9. package/dist/basemap-layer.js +115 -0
  10. package/dist/basemap-layer.js.map +1 -0
  11. package/dist/globe-layers.d.ts +22 -0
  12. package/dist/globe-layers.d.ts.map +1 -0
  13. package/dist/globe-layers.js +451 -0
  14. package/dist/globe-layers.js.map +1 -0
  15. package/dist/index.cjs +947 -0
  16. package/dist/index.cjs.map +7 -0
  17. package/dist/index.d.ts +4 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +4 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/map-style-loader.d.ts +49 -0
  22. package/dist/map-style-loader.d.ts.map +1 -0
  23. package/dist/map-style-loader.js +35 -0
  24. package/dist/map-style-loader.js.map +1 -0
  25. package/dist/map-style-schema.d.ts +71 -0
  26. package/dist/map-style-schema.d.ts.map +1 -0
  27. package/dist/map-style-schema.js +45 -0
  28. package/dist/map-style-schema.js.map +1 -0
  29. package/dist/map-style.cjs +250 -0
  30. package/dist/map-style.cjs.map +7 -0
  31. package/dist/map-style.d.ts +7 -0
  32. package/dist/map-style.d.ts.map +1 -0
  33. package/dist/map-style.js +6 -0
  34. package/dist/map-style.js.map +1 -0
  35. package/dist/mapbox-style.d.ts +41 -0
  36. package/dist/mapbox-style.d.ts.map +1 -0
  37. package/dist/mapbox-style.js +113 -0
  38. package/dist/mapbox-style.js.map +1 -0
  39. package/dist/mvt-label-layer.d.ts +8142 -0
  40. package/dist/mvt-label-layer.d.ts.map +1 -0
  41. package/dist/mvt-label-layer.js +175 -0
  42. package/dist/mvt-label-layer.js.map +1 -0
  43. package/dist/style-resolver.d.ts +88 -0
  44. package/dist/style-resolver.d.ts.map +1 -0
  45. package/dist/style-resolver.js +63 -0
  46. package/dist/style-resolver.js.map +1 -0
  47. package/dist/util.d.ts +21 -0
  48. package/dist/util.d.ts.map +1 -0
  49. package/dist/util.js +18 -0
  50. package/dist/util.js.map +1 -0
  51. package/package.json +60 -0
  52. package/src/atmosphere-layer.ts +15 -0
  53. package/src/basemap-layer.ts +183 -0
  54. package/src/globe-layers.ts +780 -0
  55. package/src/index.ts +3 -0
  56. package/src/map-style-loader.ts +52 -0
  57. package/src/map-style-schema.ts +54 -0
  58. package/src/map-style.ts +18 -0
  59. package/src/mapbox-style.ts +196 -0
  60. package/src/mvt-label-layer.ts +269 -0
  61. package/src/style-resolver.ts +173 -0
  62. package/src/util.ts +38 -0
@@ -0,0 +1,250 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // dist/map-style.js
20
+ var map_style_exports = {};
21
+ __export(map_style_exports, {
22
+ BasemapSourceSchema: () => BasemapSourceSchema,
23
+ BasemapStyleLayerSchema: () => BasemapStyleLayerSchema,
24
+ BasemapStyleSchema: () => BasemapStyleSchema,
25
+ MapStyleLoader: () => MapStyleLoader,
26
+ ResolvedBasemapStyleSchema: () => ResolvedBasemapStyleSchema,
27
+ filterFeatures: () => filterFeatures,
28
+ findFeaturesStyledByLayer: () => findFeaturesStyledByLayer,
29
+ parseProperties: () => parseProperties,
30
+ resolveBasemapStyle: () => resolveBasemapStyle
31
+ });
32
+ module.exports = __toCommonJS(map_style_exports);
33
+
34
+ // dist/mapbox-style.js
35
+ var import_mapbox_gl_style_spec = require("@mapbox/mapbox-gl-style-spec");
36
+ var GEOM_TYPES = {
37
+ Point: 1,
38
+ MultiPoint: 1,
39
+ LineString: 2,
40
+ MultiLineString: 2,
41
+ Polygon: 3,
42
+ MultiPolygon: 3
43
+ };
44
+ function filterFeatures({ features, filter, globalProperties = {} }) {
45
+ if (!features || features.length === 0) {
46
+ return [];
47
+ }
48
+ const filterFn = (0, import_mapbox_gl_style_spec.featureFilter)(filter).filter;
49
+ return features.filter((feature) => {
50
+ var _a;
51
+ if (![1, 2, 3].includes(Number(feature.type))) {
52
+ feature.type = GEOM_TYPES[((_a = feature.geometry) == null ? void 0 : _a.type) || ""] ?? feature.type;
53
+ }
54
+ return filterFn(globalProperties, feature);
55
+ });
56
+ }
57
+ function findFeaturesStyledByLayer({ features, layer, globalProperties }) {
58
+ var _a;
59
+ const sourceLayerFeatures = (_a = features[layer.source || ""]) == null ? void 0 : _a[layer["source-layer"] || ""];
60
+ if (!sourceLayerFeatures) {
61
+ return [];
62
+ }
63
+ if (layer.filter && layer.filter.length > 0) {
64
+ return filterFeatures({
65
+ features: sourceLayerFeatures,
66
+ filter: layer.filter,
67
+ globalProperties
68
+ });
69
+ }
70
+ return [];
71
+ }
72
+ function parseProperties(layer, globalProperties) {
73
+ const layerProperties = [];
74
+ visitProperties(layer, { paint: true }, (property) => {
75
+ layerProperties.push(parseProperty(property, globalProperties));
76
+ });
77
+ return layerProperties;
78
+ }
79
+ function visitProperties(layer, options, callback) {
80
+ function inner(targetLayer, propertyType) {
81
+ const properties = targetLayer[propertyType];
82
+ if (!properties) {
83
+ return;
84
+ }
85
+ Object.keys(properties).forEach((key) => {
86
+ callback({
87
+ layer: targetLayer,
88
+ path: [targetLayer.id, propertyType, key],
89
+ key,
90
+ value: properties[key],
91
+ reference: getPropertyReference(key),
92
+ set(value) {
93
+ properties[key] = value;
94
+ }
95
+ });
96
+ });
97
+ }
98
+ if (options.paint) {
99
+ inner(layer, "paint");
100
+ }
101
+ if (options.layout) {
102
+ inner(layer, "layout");
103
+ }
104
+ }
105
+ function getPropertyReference(propertyName) {
106
+ for (let i = 0; i < import_mapbox_gl_style_spec.latest.layout.length; i++) {
107
+ for (const key in import_mapbox_gl_style_spec.latest[import_mapbox_gl_style_spec.latest.layout[i]]) {
108
+ if (key === propertyName) {
109
+ return import_mapbox_gl_style_spec.latest[import_mapbox_gl_style_spec.latest.layout[i]][key];
110
+ }
111
+ }
112
+ }
113
+ for (let i = 0; i < import_mapbox_gl_style_spec.latest.paint.length; i++) {
114
+ for (const key in import_mapbox_gl_style_spec.latest[import_mapbox_gl_style_spec.latest.paint[i]]) {
115
+ if (key === propertyName) {
116
+ return import_mapbox_gl_style_spec.latest[import_mapbox_gl_style_spec.latest.paint[i]][key];
117
+ }
118
+ }
119
+ }
120
+ return null;
121
+ }
122
+ function parseProperty(property, globalProperties) {
123
+ const exp = import_mapbox_gl_style_spec.expression.normalizePropertyExpression(property.value, property.reference);
124
+ const result = exp.evaluate(globalProperties);
125
+ if (result instanceof import_mapbox_gl_style_spec.Color) {
126
+ return { [property.key]: result.toArray() };
127
+ }
128
+ return { [property.key]: result };
129
+ }
130
+
131
+ // dist/map-style-schema.js
132
+ var import_zod = require("zod");
133
+ var BasemapSourceSchema = import_zod.z.object({
134
+ type: import_zod.z.string().optional(),
135
+ url: import_zod.z.string().optional(),
136
+ tiles: import_zod.z.array(import_zod.z.string()).optional(),
137
+ minzoom: import_zod.z.number().optional(),
138
+ maxzoom: import_zod.z.number().optional(),
139
+ tileSize: import_zod.z.number().optional()
140
+ }).catchall(import_zod.z.unknown());
141
+ var BasemapStyleLayerSchema = import_zod.z.object({
142
+ id: import_zod.z.string(),
143
+ type: import_zod.z.string(),
144
+ source: import_zod.z.string().optional(),
145
+ "source-layer": import_zod.z.string().optional(),
146
+ minzoom: import_zod.z.number().optional(),
147
+ maxzoom: import_zod.z.number().optional(),
148
+ filter: import_zod.z.array(import_zod.z.unknown()).optional(),
149
+ paint: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional(),
150
+ layout: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional()
151
+ }).catchall(import_zod.z.unknown());
152
+ var BasemapStyleSchema = import_zod.z.object({
153
+ version: import_zod.z.number().optional(),
154
+ metadata: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional(),
155
+ sources: import_zod.z.record(import_zod.z.string(), BasemapSourceSchema).optional(),
156
+ layers: import_zod.z.array(BasemapStyleLayerSchema).optional()
157
+ }).catchall(import_zod.z.unknown());
158
+ var ResolvedBasemapStyleSchema = import_zod.z.object({
159
+ version: import_zod.z.number().optional(),
160
+ metadata: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional(),
161
+ sources: import_zod.z.record(import_zod.z.string(), BasemapSourceSchema),
162
+ layers: import_zod.z.array(BasemapStyleLayerSchema)
163
+ }).catchall(import_zod.z.unknown());
164
+
165
+ // dist/style-resolver.js
166
+ function normalizeUrl(url, baseUrl) {
167
+ if (!url) {
168
+ return url;
169
+ }
170
+ try {
171
+ return decodeURI(new URL(url, baseUrl).toString());
172
+ } catch {
173
+ return url;
174
+ }
175
+ }
176
+ function normalizeTiles(tiles, baseUrl) {
177
+ return Array.isArray(tiles) ? tiles.map((tile) => normalizeUrl(tile, baseUrl) || tile) : tiles;
178
+ }
179
+ async function fetchJson(url, loadOptions) {
180
+ const fetchFn = (loadOptions == null ? void 0 : loadOptions.fetch) || fetch;
181
+ const response = await fetchFn(url, loadOptions == null ? void 0 : loadOptions.fetchOptions);
182
+ if (!response.ok) {
183
+ throw new Error(`Failed to load basemap resource: ${url} (${response.status})`);
184
+ }
185
+ return await response.json();
186
+ }
187
+ async function resolveSource(source, baseUrl, loadOptions) {
188
+ if (!source) {
189
+ return source;
190
+ }
191
+ const resolvedSource = { ...source };
192
+ let sourceBaseUrl = baseUrl;
193
+ if (resolvedSource.url) {
194
+ const tileJsonUrl = normalizeUrl(resolvedSource.url, baseUrl);
195
+ const tileJson = await fetchJson(tileJsonUrl || resolvedSource.url, loadOptions);
196
+ Object.assign(resolvedSource, tileJson);
197
+ resolvedSource.url = tileJsonUrl;
198
+ sourceBaseUrl = tileJsonUrl;
199
+ }
200
+ if (resolvedSource.tiles) {
201
+ resolvedSource.tiles = normalizeTiles(resolvedSource.tiles, sourceBaseUrl);
202
+ }
203
+ return resolvedSource;
204
+ }
205
+ async function resolveBasemapStyle(style, loadOptions) {
206
+ const styleDefinition = BasemapStyleSchema.parse(typeof style === "string" ? await fetchJson(style, loadOptions) : structuredClone(style));
207
+ const baseUrl = typeof style === "string" ? style : loadOptions == null ? void 0 : loadOptions.baseUrl;
208
+ const resolvedSources = {};
209
+ await Promise.all(Object.entries(styleDefinition.sources || {}).map(async ([sourceId, source]) => {
210
+ resolvedSources[sourceId] = await resolveSource(source, baseUrl, loadOptions) || {};
211
+ }));
212
+ return ResolvedBasemapStyleSchema.parse({
213
+ ...styleDefinition,
214
+ sources: resolvedSources,
215
+ layers: [...styleDefinition.layers || []]
216
+ });
217
+ }
218
+
219
+ // dist/map-style-loader.js
220
+ var VERSION = true ? "9.3.0-beta.2" : "latest";
221
+ function getMapStyleLoadOptions(options, context) {
222
+ var _a, _b;
223
+ return {
224
+ ...options == null ? void 0 : options.mapStyle,
225
+ baseUrl: ((_a = options == null ? void 0 : options.mapStyle) == null ? void 0 : _a.baseUrl) || (context == null ? void 0 : context.url) || (context == null ? void 0 : context.baseUrl),
226
+ fetch: ((_b = options == null ? void 0 : options.mapStyle) == null ? void 0 : _b.fetch) || (context == null ? void 0 : context.fetch)
227
+ };
228
+ }
229
+ var MapStyleLoader = {
230
+ dataType: null,
231
+ batchType: null,
232
+ name: "Map Style",
233
+ id: "map-style",
234
+ module: "basemap-layers",
235
+ version: VERSION,
236
+ worker: false,
237
+ extensions: ["json"],
238
+ mimeTypes: ["application/json", "application/vnd.mapbox.style+json"],
239
+ text: true,
240
+ options: {
241
+ mapStyle: {}
242
+ },
243
+ parse: async (data, options, context) => {
244
+ const text = typeof data === "string" ? data : new TextDecoder().decode(data);
245
+ const style = JSON.parse(text);
246
+ const resolved = await resolveBasemapStyle(style, getMapStyleLoadOptions(options, context));
247
+ return ResolvedBasemapStyleSchema.parse(resolved);
248
+ }
249
+ };
250
+ //# sourceMappingURL=map-style.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/map-style.ts", "../src/mapbox-style.ts", "../src/map-style-schema.ts", "../src/style-resolver.ts", "../src/map-style-loader.ts"],
4
+ "sourcesContent": ["/** Map-style helpers exported from `@deck.gl-community/basemap-layers/map-style`. */\nexport {filterFeatures, findFeaturesStyledByLayer, parseProperties} from './mapbox-style';\nexport {\n BasemapSourceSchema,\n BasemapStyleLayerSchema,\n BasemapStyleSchema,\n ResolvedBasemapStyleSchema\n} from './map-style-schema';\nexport {MapStyleLoader} from './map-style-loader';\nexport type {MapStyleLoaderOptions} from './map-style-loader';\nexport {\n resolveBasemapStyle,\n type BasemapLoadOptions,\n type BasemapSource,\n type BasemapStyle,\n type BasemapStyleLayer,\n type ResolvedBasemapStyle\n} from './style-resolver';\n", "import {Color, expression, featureFilter, latest as Reference} from '@mapbox/mapbox-gl-style-spec';\n\ntype GlobalProperties = {\n zoom?: number;\n [key: string]: unknown;\n};\n\ntype GeometryLike = {\n type: string;\n};\n\ntype FeatureLike = {\n type?: number | string;\n geometry?: GeometryLike;\n properties?: Record<string, unknown>;\n};\n\ntype FilterFeaturesOptions = {\n features: FeatureLike[];\n filter: unknown[];\n globalProperties?: GlobalProperties;\n};\n\ntype FindFeaturesStyledByLayerOptions = {\n features: Record<string, Record<string, FeatureLike[]>>;\n layer: {\n source?: string;\n 'source-layer'?: string;\n filter?: unknown[];\n };\n globalProperties?: GlobalProperties;\n};\n\ntype PropertyReference = Record<string, unknown> | null;\n\ntype VisitedProperty = {\n layer: Record<string, any>;\n path: string[];\n key: string;\n value: unknown;\n reference: PropertyReference;\n set: (value: unknown) => void;\n};\n\ntype VisitOptions = {\n paint?: boolean;\n layout?: boolean;\n};\n\nconst GEOM_TYPES: Record<string, number> = {\n Point: 1,\n MultiPoint: 1,\n LineString: 2,\n MultiLineString: 2,\n Polygon: 3,\n MultiPolygon: 3\n};\n\n/**\n * Applies a Mapbox style-spec filter expression to a set of features.\n */\nexport function filterFeatures({\n features,\n filter,\n globalProperties = {}\n}: FilterFeaturesOptions): FeatureLike[] {\n if (!features || features.length === 0) {\n return [];\n }\n\n const filterFn = featureFilter(filter).filter;\n\n return features.filter((feature) => {\n if (![1, 2, 3].includes(Number(feature.type))) {\n feature.type = GEOM_TYPES[feature.geometry?.type || ''] ?? feature.type;\n }\n\n return filterFn(globalProperties, feature);\n });\n}\n\n/**\n * Finds the source-layer features that participate in a particular style layer\n * and applies the layer's filter expression when present.\n */\nexport function findFeaturesStyledByLayer({\n features,\n layer,\n globalProperties\n}: FindFeaturesStyledByLayerOptions): FeatureLike[] {\n const sourceLayerFeatures = features[layer.source || '']?.[layer['source-layer'] || ''];\n if (!sourceLayerFeatures) {\n return [];\n }\n\n if (layer.filter && layer.filter.length > 0) {\n return filterFeatures({\n features: sourceLayerFeatures,\n filter: layer.filter,\n globalProperties\n });\n }\n\n return [];\n}\n\n/**\n * Evaluates paint properties for a style layer at the requested zoom.\n */\nexport function parseProperties(\n layer: Record<string, any>,\n globalProperties: GlobalProperties\n): Array<Record<string, unknown>> {\n const layerProperties: Array<Record<string, unknown>> = [];\n visitProperties(layer, {paint: true}, (property) => {\n layerProperties.push(parseProperty(property, globalProperties));\n });\n\n return layerProperties;\n}\n\n/**\n * Walks layout and paint properties for a style layer.\n */\nfunction visitProperties(\n layer: Record<string, any>,\n options: VisitOptions,\n callback: (property: VisitedProperty) => void\n): void {\n function inner(targetLayer: Record<string, any>, propertyType: 'paint' | 'layout') {\n const properties = targetLayer[propertyType];\n if (!properties) {\n return;\n }\n\n Object.keys(properties).forEach((key) => {\n callback({\n layer: targetLayer,\n path: [targetLayer.id, propertyType, key],\n key,\n value: properties[key],\n reference: getPropertyReference(key),\n set(value) {\n properties[key] = value;\n }\n });\n });\n }\n\n if (options.paint) {\n inner(layer, 'paint');\n }\n if (options.layout) {\n inner(layer, 'layout');\n }\n}\n\n/**\n * Resolves the style-spec reference metadata for a property name.\n */\nfunction getPropertyReference(propertyName: string): PropertyReference {\n for (let i = 0; i < Reference.layout.length; i++) {\n for (const key in Reference[Reference.layout[i]]) {\n if (key === propertyName) {\n return Reference[Reference.layout[i]][key] as PropertyReference;\n }\n }\n }\n\n for (let i = 0; i < Reference.paint.length; i++) {\n for (const key in Reference[Reference.paint[i]]) {\n if (key === propertyName) {\n return Reference[Reference.paint[i]][key] as PropertyReference;\n }\n }\n }\n\n return null;\n}\n\n/**\n * Evaluates a single style property expression.\n */\nfunction parseProperty(\n property: VisitedProperty,\n globalProperties: GlobalProperties\n): Record<string, unknown> {\n const exp = expression.normalizePropertyExpression(property.value, property.reference as any);\n const result = exp.evaluate(globalProperties);\n\n if (result instanceof Color) {\n return {[property.key]: result.toArray()};\n }\n\n return {[property.key]: result};\n}\n", "import {z} from 'zod';\nimport type {\n BasemapSource,\n BasemapStyle,\n BasemapStyleLayer,\n ResolvedBasemapStyle\n} from './style-resolver';\n\n/** Zod schema for a basemap source entry. */\nexport const BasemapSourceSchema = z\n .object({\n type: z.string().optional(),\n url: z.string().optional(),\n tiles: z.array(z.string()).optional(),\n minzoom: z.number().optional(),\n maxzoom: z.number().optional(),\n tileSize: z.number().optional()\n })\n .catchall(z.unknown()) satisfies z.ZodType<BasemapSource>;\n\n/** Zod schema for a basemap style layer entry. */\nexport const BasemapStyleLayerSchema = z\n .object({\n id: z.string(),\n type: z.string(),\n source: z.string().optional(),\n 'source-layer': z.string().optional(),\n minzoom: z.number().optional(),\n maxzoom: z.number().optional(),\n filter: z.array(z.unknown()).optional(),\n paint: z.record(z.string(), z.unknown()).optional(),\n layout: z.record(z.string(), z.unknown()).optional()\n })\n .catchall(z.unknown()) satisfies z.ZodType<BasemapStyleLayer>;\n\n/** Zod schema for a MapLibre / Mapbox style document. */\nexport const BasemapStyleSchema = z\n .object({\n version: z.number().optional(),\n metadata: z.record(z.string(), z.unknown()).optional(),\n sources: z.record(z.string(), BasemapSourceSchema).optional(),\n layers: z.array(BasemapStyleLayerSchema).optional()\n })\n .catchall(z.unknown()) satisfies z.ZodType<BasemapStyle>;\n\n/** Zod schema for a fully resolved basemap style document. */\nexport const ResolvedBasemapStyleSchema = z\n .object({\n version: z.number().optional(),\n metadata: z.record(z.string(), z.unknown()).optional(),\n sources: z.record(z.string(), BasemapSourceSchema),\n layers: z.array(BasemapStyleLayerSchema)\n })\n .catchall(z.unknown()) satisfies z.ZodType<ResolvedBasemapStyle>;\n", "import {BasemapStyleSchema, ResolvedBasemapStyleSchema} from './map-style-schema';\n\n/**\n * A basemap source entry from a style document.\n */\nexport type BasemapSource = {\n /** Source kind such as `vector` or `raster`. */\n type?: string;\n /** Optional TileJSON URL used to resolve the source metadata. */\n url?: string;\n /** Inline tile templates for the source. */\n tiles?: string[];\n /** Minimum source zoom, when supplied by the style or TileJSON. */\n minzoom?: number;\n /** Maximum source zoom, when supplied by the style or TileJSON. */\n maxzoom?: number;\n /** Tile size in pixels. */\n tileSize?: number;\n /** Additional source properties are preserved verbatim. */\n [key: string]: unknown;\n};\n\n/**\n * A style layer entry used by the basemap runtime.\n */\nexport type BasemapStyleLayer = {\n /** Unique layer identifier. */\n id: string;\n /** Style layer type such as `background`, `fill`, `line`, `symbol`, or `raster`. */\n type: string;\n /** Referenced source identifier. */\n source?: string;\n /** Referenced vector source-layer identifier. */\n 'source-layer'?: string;\n /** Optional minimum zoom. */\n minzoom?: number;\n /** Optional maximum zoom. */\n maxzoom?: number;\n /** Optional style-spec filter expression. */\n filter?: unknown[];\n /** Paint properties from the source style layer. */\n paint?: Record<string, unknown>;\n /** Layout properties from the source style layer. */\n layout?: Record<string, unknown>;\n /** Additional layer properties are preserved verbatim. */\n [key: string]: unknown;\n};\n\n/**\n * A MapLibre or Mapbox style document consumed by the basemap runtime.\n */\nexport type BasemapStyle = {\n /** Style-spec version number. */\n version?: number;\n /** Optional style metadata bag. */\n metadata?: Record<string, unknown>;\n /** Named source definitions used by the style. */\n sources?: Record<string, BasemapSource>;\n /** Ordered list of style layers. */\n layers?: BasemapStyleLayer[];\n /** Additional style properties are preserved verbatim. */\n [key: string]: unknown;\n};\n\n/**\n * A style document after all sources have been normalized and TileJSON-backed\n * sources have been resolved.\n */\nexport type ResolvedBasemapStyle = BasemapStyle & {\n /** Fully resolved source definitions. */\n sources: Record<string, BasemapSource>;\n /** Style layers copied into a mutable array. */\n layers: BasemapStyleLayer[];\n};\n\n/**\n * Load options accepted by {@link resolveBasemapStyle}.\n */\nexport type BasemapLoadOptions = {\n /** Base URL used to resolve relative source or tile URLs for in-memory styles. */\n baseUrl?: string;\n /** Optional custom fetch implementation. */\n fetch?: typeof fetch;\n /** Optional init object passed to the selected fetch implementation. */\n fetchOptions?: RequestInit;\n /** Additional loader options are accepted for forward compatibility. */\n [key: string]: unknown;\n} | null;\n\n/** Resolves a possibly relative URL against the provided base URL. */\nfunction normalizeUrl(url: string | undefined, baseUrl?: string) {\n if (!url) {\n return url;\n }\n\n try {\n return decodeURI(new URL(url, baseUrl).toString());\n } catch {\n return url;\n }\n}\n\n/** Resolves all tile templates in a source against the source base URL. */\nfunction normalizeTiles(tiles: string[] | undefined, baseUrl?: string) {\n return Array.isArray(tiles) ? tiles.map((tile) => normalizeUrl(tile, baseUrl) || tile) : tiles;\n}\n\n/** Fetches and parses a JSON resource. */\nasync function fetchJson(url: string, loadOptions?: BasemapLoadOptions) {\n const fetchFn = loadOptions?.fetch || fetch;\n const response = await fetchFn(url, loadOptions?.fetchOptions);\n\n if (!response.ok) {\n throw new Error(`Failed to load basemap resource: ${url} (${response.status})`);\n }\n\n return await response.json();\n}\n\n/** Resolves a single source, including optional TileJSON indirection. */\nasync function resolveSource(\n source: BasemapSource | undefined,\n baseUrl: string | undefined,\n loadOptions?: BasemapLoadOptions\n) {\n if (!source) {\n return source;\n }\n\n const resolvedSource: BasemapSource = {...source};\n let sourceBaseUrl = baseUrl;\n\n if (resolvedSource.url) {\n const tileJsonUrl = normalizeUrl(resolvedSource.url, baseUrl);\n const tileJson = await fetchJson(tileJsonUrl || resolvedSource.url, loadOptions);\n Object.assign(resolvedSource, tileJson);\n resolvedSource.url = tileJsonUrl;\n sourceBaseUrl = tileJsonUrl;\n }\n\n if (resolvedSource.tiles) {\n resolvedSource.tiles = normalizeTiles(resolvedSource.tiles, sourceBaseUrl);\n }\n\n return resolvedSource;\n}\n\n/**\n * Resolves a basemap style input into a style object whose sources contain\n * directly consumable tile templates and source metadata.\n */\nexport async function resolveBasemapStyle(\n style: string | BasemapStyle,\n loadOptions?: BasemapLoadOptions\n): Promise<ResolvedBasemapStyle> {\n const styleDefinition = BasemapStyleSchema.parse(\n typeof style === 'string' ? await fetchJson(style, loadOptions) : structuredClone(style)\n );\n const baseUrl = typeof style === 'string' ? style : loadOptions?.baseUrl;\n const resolvedSources: Record<string, BasemapSource> = {};\n\n await Promise.all(\n Object.entries(styleDefinition.sources || {}).map(async ([sourceId, source]) => {\n resolvedSources[sourceId] = (await resolveSource(source, baseUrl, loadOptions)) || {};\n })\n );\n\n return ResolvedBasemapStyleSchema.parse({\n ...styleDefinition,\n sources: resolvedSources,\n layers: [...(styleDefinition.layers || [])]\n });\n}\n", "import type {LoaderContext, LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';\nimport {ResolvedBasemapStyleSchema} from './map-style-schema';\nimport {resolveBasemapStyle} from './style-resolver';\nimport type {BasemapLoadOptions, BasemapStyle, ResolvedBasemapStyle} from './style-resolver';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n/** Namespaced loaders.gl options for {@link MapStyleLoader}. */\nexport type MapStyleLoaderOptions = LoaderOptions & {\n mapStyle?: NonNullable<BasemapLoadOptions>;\n};\n\nfunction getMapStyleLoadOptions(\n options?: MapStyleLoaderOptions,\n context?: LoaderContext\n): NonNullable<BasemapLoadOptions> {\n return {\n ...options?.mapStyle,\n baseUrl: options?.mapStyle?.baseUrl || context?.url || context?.baseUrl,\n fetch: options?.mapStyle?.fetch || (context?.fetch as typeof fetch | undefined)\n };\n}\n\n/** loaders.gl-compatible loader that resolves and validates map-style documents. */\nexport const MapStyleLoader = {\n dataType: null as unknown as ResolvedBasemapStyle,\n batchType: null as never,\n\n name: 'Map Style',\n id: 'map-style',\n module: 'basemap-layers',\n version: VERSION,\n worker: false,\n extensions: ['json'],\n mimeTypes: ['application/json', 'application/vnd.mapbox.style+json'],\n text: true,\n options: {\n mapStyle: {}\n },\n parse: async (\n data: ArrayBuffer | string,\n options?: MapStyleLoaderOptions,\n context?: LoaderContext\n ) => {\n const text = typeof data === 'string' ? data : new TextDecoder().decode(data);\n const style = JSON.parse(text) as BasemapStyle;\n const resolved = await resolveBasemapStyle(style, getMapStyleLoadOptions(options, context));\n return ResolvedBasemapStyleSchema.parse(resolved);\n }\n} as const satisfies LoaderWithParser<ResolvedBasemapStyle, never, MapStyleLoaderOptions>;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;ACAA,kCAAoE;AAiDpE,IAAM,aAAqC;EACzC,OAAO;EACP,YAAY;EACZ,YAAY;EACZ,iBAAiB;EACjB,SAAS;EACT,cAAc;;AAMV,SAAU,eAAe,EAC7B,UACA,QACA,mB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AS,WAAW,KAAM,CAAA;EACrF,CAAC,CAAC;AAGJ,SAAO,2BAA2B,MAAM;IACtC,GAAG;IACH,SAAS;IACT,QAAQ,CAAC,GAAI,gBAAgB,UAAU,CAAA,CAAG;GAC3C;AACH;;;ACrKA,IAAM,UAAU,OAAoC,iBAAe;AAOnE,SAAS,uBACP,SACA,SAAuB;AAfzB;AAiBE,SAAO;IACL,GAAG,mCAAS;IACZ,WAAS,wCAAS,aAAT,mBAAmB,aAAW,mCAAS,SAAO,mCAAS;IAChE,SAAO,wCAAS,aAAT,mBAAmB,WAAU,mCAAS;;AAEjD;AAGO,IAAM,iBAAiB;EAC5B,UAAU;EACV,WAAW;EAEX,MAAM;EACN,IAAI;EACJ,QAAQ;EACR,SAAS;EACT,QAAQ;EACR,YAAY,CAAC,MAAM;EACnB,WAAW,CAAC,oBAAoB,mCAAmC;EACnE,MAAM;EACN,SAAS;IACP,UAAU,CAAA;;EAEZ,OAAO,OACL,MACA,SACA,YACE;AACF,UAAM,OAAO,OAAO,SAAS,WAAW,OAAO,IAAI,YAAW,EAAG,OAAO,IAAI;AAC5E,UAAM,QAAQ,KAAK,MAAM,IAAI;AAC7B,UAAM,WAAW,MAAM,oBAAoB,OAAO,uBAAuB,SAAS,OAAO,CAAC;AAC1F,WAAO,2BAA2B,MAAM,QAAQ;EAClD;;",
6
+ "names": ["Reference"]
7
+ }
@@ -0,0 +1,7 @@
1
+ /** Map-style helpers exported from `@deck.gl-community/basemap-layers/map-style`. */
2
+ export { filterFeatures, findFeaturesStyledByLayer, parseProperties } from "./mapbox-style.js";
3
+ export { BasemapSourceSchema, BasemapStyleLayerSchema, BasemapStyleSchema, ResolvedBasemapStyleSchema } from "./map-style-schema.js";
4
+ export { MapStyleLoader } from "./map-style-loader.js";
5
+ export type { MapStyleLoaderOptions } from "./map-style-loader.js";
6
+ export { resolveBasemapStyle, type BasemapLoadOptions, type BasemapSource, type BasemapStyle, type BasemapStyleLayer, type ResolvedBasemapStyle } from "./style-resolver.js";
7
+ //# sourceMappingURL=map-style.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-style.d.ts","sourceRoot":"","sources":["../src/map-style.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,OAAO,EAAC,cAAc,EAAE,yBAAyB,EAAE,eAAe,EAAC,0BAAuB;AAC1F,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,kBAAkB,EAClB,0BAA0B,EAC3B,8BAA2B;AAC5B,OAAO,EAAC,cAAc,EAAC,8BAA2B;AAClD,YAAY,EAAC,qBAAqB,EAAC,8BAA2B;AAC9D,OAAO,EACL,mBAAmB,EACnB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EAC1B,4BAAyB"}
@@ -0,0 +1,6 @@
1
+ /** Map-style helpers exported from `@deck.gl-community/basemap-layers/map-style`. */
2
+ export { filterFeatures, findFeaturesStyledByLayer, parseProperties } from "./mapbox-style.js";
3
+ export { BasemapSourceSchema, BasemapStyleLayerSchema, BasemapStyleSchema, ResolvedBasemapStyleSchema } from "./map-style-schema.js";
4
+ export { MapStyleLoader } from "./map-style-loader.js";
5
+ export { resolveBasemapStyle } from "./style-resolver.js";
6
+ //# sourceMappingURL=map-style.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-style.js","sourceRoot":"","sources":["../src/map-style.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,OAAO,EAAC,cAAc,EAAE,yBAAyB,EAAE,eAAe,EAAC,0BAAuB;AAC1F,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,kBAAkB,EAClB,0BAA0B,EAC3B,8BAA2B;AAC5B,OAAO,EAAC,cAAc,EAAC,8BAA2B;AAElD,OAAO,EACL,mBAAmB,EAMpB,4BAAyB"}
@@ -0,0 +1,41 @@
1
+ type GlobalProperties = {
2
+ zoom?: number;
3
+ [key: string]: unknown;
4
+ };
5
+ type GeometryLike = {
6
+ type: string;
7
+ };
8
+ type FeatureLike = {
9
+ type?: number | string;
10
+ geometry?: GeometryLike;
11
+ properties?: Record<string, unknown>;
12
+ };
13
+ type FilterFeaturesOptions = {
14
+ features: FeatureLike[];
15
+ filter: unknown[];
16
+ globalProperties?: GlobalProperties;
17
+ };
18
+ type FindFeaturesStyledByLayerOptions = {
19
+ features: Record<string, Record<string, FeatureLike[]>>;
20
+ layer: {
21
+ source?: string;
22
+ 'source-layer'?: string;
23
+ filter?: unknown[];
24
+ };
25
+ globalProperties?: GlobalProperties;
26
+ };
27
+ /**
28
+ * Applies a Mapbox style-spec filter expression to a set of features.
29
+ */
30
+ export declare function filterFeatures({ features, filter, globalProperties }: FilterFeaturesOptions): FeatureLike[];
31
+ /**
32
+ * Finds the source-layer features that participate in a particular style layer
33
+ * and applies the layer's filter expression when present.
34
+ */
35
+ export declare function findFeaturesStyledByLayer({ features, layer, globalProperties }: FindFeaturesStyledByLayerOptions): FeatureLike[];
36
+ /**
37
+ * Evaluates paint properties for a style layer at the requested zoom.
38
+ */
39
+ export declare function parseProperties(layer: Record<string, any>, globalProperties: GlobalProperties): Array<Record<string, unknown>>;
40
+ export {};
41
+ //# sourceMappingURL=mapbox-style.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapbox-style.d.ts","sourceRoot":"","sources":["../src/mapbox-style.ts"],"names":[],"mappings":"AAEA,KAAK,gBAAgB,GAAG;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,KAAK,WAAW,GAAG;IACjB,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;CACrC,CAAC;AAEF,KAAK,gCAAgC,GAAG;IACtC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;IACxD,KAAK,EAAE;QACL,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;KACpB,CAAC;IACF,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;CACrC,CAAC;AA2BF;;GAEG;AACH,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,MAAM,EACN,gBAAqB,EACtB,EAAE,qBAAqB,GAAG,WAAW,EAAE,CAcvC;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,EACxC,QAAQ,EACR,KAAK,EACL,gBAAgB,EACjB,EAAE,gCAAgC,GAAG,WAAW,EAAE,CAelD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC1B,gBAAgB,EAAE,gBAAgB,GACjC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAOhC"}
@@ -0,0 +1,113 @@
1
+ import { Color, expression, featureFilter, latest as Reference } from '@mapbox/mapbox-gl-style-spec';
2
+ const GEOM_TYPES = {
3
+ Point: 1,
4
+ MultiPoint: 1,
5
+ LineString: 2,
6
+ MultiLineString: 2,
7
+ Polygon: 3,
8
+ MultiPolygon: 3
9
+ };
10
+ /**
11
+ * Applies a Mapbox style-spec filter expression to a set of features.
12
+ */
13
+ export function filterFeatures({ features, filter, globalProperties = {} }) {
14
+ if (!features || features.length === 0) {
15
+ return [];
16
+ }
17
+ const filterFn = featureFilter(filter).filter;
18
+ return features.filter((feature) => {
19
+ if (![1, 2, 3].includes(Number(feature.type))) {
20
+ feature.type = GEOM_TYPES[feature.geometry?.type || ''] ?? feature.type;
21
+ }
22
+ return filterFn(globalProperties, feature);
23
+ });
24
+ }
25
+ /**
26
+ * Finds the source-layer features that participate in a particular style layer
27
+ * and applies the layer's filter expression when present.
28
+ */
29
+ export function findFeaturesStyledByLayer({ features, layer, globalProperties }) {
30
+ const sourceLayerFeatures = features[layer.source || '']?.[layer['source-layer'] || ''];
31
+ if (!sourceLayerFeatures) {
32
+ return [];
33
+ }
34
+ if (layer.filter && layer.filter.length > 0) {
35
+ return filterFeatures({
36
+ features: sourceLayerFeatures,
37
+ filter: layer.filter,
38
+ globalProperties
39
+ });
40
+ }
41
+ return [];
42
+ }
43
+ /**
44
+ * Evaluates paint properties for a style layer at the requested zoom.
45
+ */
46
+ export function parseProperties(layer, globalProperties) {
47
+ const layerProperties = [];
48
+ visitProperties(layer, { paint: true }, (property) => {
49
+ layerProperties.push(parseProperty(property, globalProperties));
50
+ });
51
+ return layerProperties;
52
+ }
53
+ /**
54
+ * Walks layout and paint properties for a style layer.
55
+ */
56
+ function visitProperties(layer, options, callback) {
57
+ function inner(targetLayer, propertyType) {
58
+ const properties = targetLayer[propertyType];
59
+ if (!properties) {
60
+ return;
61
+ }
62
+ Object.keys(properties).forEach((key) => {
63
+ callback({
64
+ layer: targetLayer,
65
+ path: [targetLayer.id, propertyType, key],
66
+ key,
67
+ value: properties[key],
68
+ reference: getPropertyReference(key),
69
+ set(value) {
70
+ properties[key] = value;
71
+ }
72
+ });
73
+ });
74
+ }
75
+ if (options.paint) {
76
+ inner(layer, 'paint');
77
+ }
78
+ if (options.layout) {
79
+ inner(layer, 'layout');
80
+ }
81
+ }
82
+ /**
83
+ * Resolves the style-spec reference metadata for a property name.
84
+ */
85
+ function getPropertyReference(propertyName) {
86
+ for (let i = 0; i < Reference.layout.length; i++) {
87
+ for (const key in Reference[Reference.layout[i]]) {
88
+ if (key === propertyName) {
89
+ return Reference[Reference.layout[i]][key];
90
+ }
91
+ }
92
+ }
93
+ for (let i = 0; i < Reference.paint.length; i++) {
94
+ for (const key in Reference[Reference.paint[i]]) {
95
+ if (key === propertyName) {
96
+ return Reference[Reference.paint[i]][key];
97
+ }
98
+ }
99
+ }
100
+ return null;
101
+ }
102
+ /**
103
+ * Evaluates a single style property expression.
104
+ */
105
+ function parseProperty(property, globalProperties) {
106
+ const exp = expression.normalizePropertyExpression(property.value, property.reference);
107
+ const result = exp.evaluate(globalProperties);
108
+ if (result instanceof Color) {
109
+ return { [property.key]: result.toArray() };
110
+ }
111
+ return { [property.key]: result };
112
+ }
113
+ //# sourceMappingURL=mapbox-style.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapbox-style.js","sourceRoot":"","sources":["../src/mapbox-style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,IAAI,SAAS,EAAC,MAAM,8BAA8B,CAAC;AAiDnG,MAAM,UAAU,GAA2B;IACzC,KAAK,EAAE,CAAC;IACR,UAAU,EAAE,CAAC;IACb,UAAU,EAAE,CAAC;IACb,eAAe,EAAE,CAAC;IAClB,OAAO,EAAE,CAAC;IACV,YAAY,EAAE,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,EAC7B,QAAQ,EACR,MAAM,EACN,gBAAgB,GAAG,EAAE,EACC;IACtB,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC;IAE9C,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;QACjC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,C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