ts-maps 0.2.7 → 0.3.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.
- package/LICENSE.md +21 -0
- package/README.md +202 -141
- package/dist/core-map/assets/embedded-icons.d.ts +8 -0
- package/dist/core-map/control/AttributionControl.d.ts +12 -0
- package/dist/core-map/control/Control.d.ts +14 -0
- package/dist/core-map/control/LayersControl.d.ts +38 -0
- package/dist/core-map/control/ScaleControl.d.ts +14 -0
- package/dist/core-map/control/ZoomControl.d.ts +14 -0
- package/dist/core-map/control/index.d.ts +5 -0
- package/dist/core-map/core/Browser.d.ts +24 -0
- package/dist/core-map/core/Class.d.ts +12 -0
- package/dist/core-map/core/Events.d.ts +31 -0
- package/dist/core-map/core/Handler.d.ts +12 -0
- package/dist/core-map/core/Util.d.ts +24 -0
- package/dist/core-map/core/index.d.ts +7 -0
- package/dist/core-map/dom/Animation.d.ts +50 -0
- package/dist/core-map/dom/DomEvent.DoubleTap.d.ts +6 -0
- package/dist/core-map/dom/DomEvent.PointerEvents.d.ts +4 -0
- package/dist/core-map/dom/DomEvent.d.ts +15 -0
- package/dist/core-map/dom/DomUtil.d.ts +22 -0
- package/dist/core-map/dom/Draggable.d.ts +26 -0
- package/dist/core-map/dom/PosAnimation.d.ts +19 -0
- package/dist/core-map/dom/easing.d.ts +41 -0
- package/dist/core-map/dom/index.d.ts +8 -0
- package/dist/core-map/geo/LatLng.d.ts +18 -0
- package/dist/core-map/geo/LatLngBounds.d.ts +27 -0
- package/dist/core-map/geo/TerrainSource.d.ts +35 -0
- package/dist/core-map/geo/crs/CRS.d.ts +23 -0
- package/dist/core-map/geo/crs/EPSG3395.d.ts +7 -0
- package/dist/core-map/geo/crs/EPSG3857.d.ts +10 -0
- package/dist/core-map/geo/crs/EPSG4326.d.ts +7 -0
- package/dist/core-map/geo/crs/EarthCRS.d.ts +7 -0
- package/dist/core-map/geo/crs/SimpleCRS.d.ts +11 -0
- package/dist/core-map/geo/crs/index.d.ts +6 -0
- package/dist/core-map/geo/elevation.d.ts +23 -0
- package/dist/core-map/geo/index.d.ts +13 -0
- package/dist/core-map/geo/index.js +1204 -0
- package/dist/core-map/geo/projection/Projection.Globe.d.ts +30 -0
- package/dist/core-map/geo/projection/Projection.LonLat.d.ts +11 -0
- package/dist/core-map/geo/projection/Projection.Mercator.d.ts +6 -0
- package/dist/core-map/geo/projection/Projection.SphericalMercator.d.ts +6 -0
- package/dist/core-map/geo/projection/index.d.ts +5 -0
- package/dist/core-map/geo/terrainMesh.d.ts +21 -0
- package/dist/core-map/geometry/Bounds.d.ts +23 -0
- package/dist/core-map/geometry/LineUtil.d.ts +13 -0
- package/dist/core-map/geometry/Point.d.ts +35 -0
- package/dist/core-map/geometry/PolyUtil.d.ts +6 -0
- package/dist/core-map/geometry/RTree.d.ts +35 -0
- package/dist/core-map/geometry/Transformation.d.ts +12 -0
- package/dist/core-map/geometry/earcut.d.ts +17 -0
- package/dist/core-map/geometry/index.d.ts +10 -0
- package/dist/core-map/geometry/index.js +1586 -0
- package/dist/core-map/index.d.ts +59 -0
- package/dist/core-map/layer/BlanketOverlay.d.ts +24 -0
- package/dist/core-map/layer/DivOverlay.d.ts +40 -0
- package/dist/core-map/layer/FeatureGroup.d.ts +11 -0
- package/dist/core-map/layer/GeoJSON.d.ts +17 -0
- package/dist/core-map/layer/GeoJSONClusterSource.d.ts +54 -0
- package/dist/core-map/layer/HeatmapLayer.d.ts +40 -0
- package/dist/core-map/layer/ImageOverlay.d.ts +27 -0
- package/dist/core-map/layer/Layer.d.ts +18 -0
- package/dist/core-map/layer/LayerGroup.d.ts +16 -0
- package/dist/core-map/layer/Popup.d.ts +18 -0
- package/dist/core-map/layer/SVGOverlay.d.ts +4 -0
- package/dist/core-map/layer/Tooltip.d.ts +15 -0
- package/dist/core-map/layer/VideoOverlay.d.ts +4 -0
- package/dist/core-map/layer/index.d.ts +18 -0
- package/dist/core-map/layer/marker/DefaultIcon.d.ts +7 -0
- package/dist/core-map/layer/marker/DivIcon.d.ts +5 -0
- package/dist/core-map/layer/marker/Icon.d.ts +10 -0
- package/dist/core-map/layer/marker/Marker.Drag.d.ts +17 -0
- package/dist/core-map/layer/marker/Marker.d.ts +37 -0
- package/dist/core-map/layer/marker/index.d.ts +5 -0
- package/dist/core-map/layer/tile/GridLayer.d.ts +88 -0
- package/dist/core-map/layer/tile/RasterDEMLayer.d.ts +46 -0
- package/dist/core-map/layer/tile/TileLayer.d.ts +22 -0
- package/dist/core-map/layer/tile/VectorTileMapLayer.d.ts +145 -0
- package/dist/core-map/layer/tile/WMSTileLayer.d.ts +12 -0
- package/dist/core-map/layer/tile/index.d.ts +15 -0
- package/dist/core-map/layer/tile/urlTemplate.d.ts +17 -0
- package/dist/core-map/layer/vector/Canvas.d.ts +52 -0
- package/dist/core-map/layer/vector/Circle.d.ts +7 -0
- package/dist/core-map/layer/vector/CircleMarker.d.ts +22 -0
- package/dist/core-map/layer/vector/Path.d.ts +20 -0
- package/dist/core-map/layer/vector/Polygon.d.ts +13 -0
- package/dist/core-map/layer/vector/Polyline.d.ts +30 -0
- package/dist/core-map/layer/vector/Rectangle.d.ts +6 -0
- package/dist/core-map/layer/vector/Renderer.d.ts +12 -0
- package/dist/core-map/layer/vector/Renderer.getRenderer.d.ts +1 -0
- package/dist/core-map/layer/vector/SVG.d.ts +21 -0
- package/dist/core-map/layer/vector/index.d.ts +10 -0
- package/dist/core-map/map/Map.d.ts +353 -0
- package/dist/core-map/map/Style.d.ts +29 -0
- package/dist/core-map/map/handler/BoxZoomHandler.d.ts +23 -0
- package/dist/core-map/map/handler/DoubleClickZoomHandler.d.ts +6 -0
- package/dist/core-map/map/handler/DragHandler.d.ts +27 -0
- package/dist/core-map/map/handler/KeyboardHandler.d.ts +18 -0
- package/dist/core-map/map/handler/PinchZoomHandler.d.ts +20 -0
- package/dist/core-map/map/handler/ScrollWheelZoomHandler.d.ts +12 -0
- package/dist/core-map/map/handler/TapHoldHandler.d.ts +15 -0
- package/dist/core-map/map/handler/TwoFingerPitchHandler.d.ts +21 -0
- package/dist/core-map/map/handler/TwoFingerRotateHandler.d.ts +17 -0
- package/dist/core-map/map/index.d.ts +11 -0
- package/dist/core-map/mvt/VectorTile.d.ts +9 -0
- package/dist/core-map/mvt/VectorTileFeature.d.ts +59 -0
- package/dist/core-map/mvt/VectorTileLayer.d.ts +13 -0
- package/dist/core-map/proto/Pbf.d.ts +84 -0
- package/dist/core-map/renderer/webgl/GLContext.d.ts +22 -0
- package/dist/core-map/renderer/webgl/WebGLTileRenderer.d.ts +86 -0
- package/dist/core-map/renderer/webgl/index.d.ts +9 -0
- package/dist/core-map/renderer/webgl/mat4.d.ts +14 -0
- package/dist/core-map/services/index.d.ts +26 -0
- package/dist/core-map/services/index.js +1230 -0
- package/dist/core-map/services/providers/Google.d.ts +16 -0
- package/dist/core-map/services/providers/Mapbox.d.ts +26 -0
- package/dist/core-map/services/providers/Maptiler.d.ts +11 -0
- package/dist/core-map/services/providers/Nominatim.d.ts +11 -0
- package/dist/core-map/services/providers/OSRM.d.ts +20 -0
- package/dist/core-map/services/providers/Photon.d.ts +10 -0
- package/dist/core-map/services/providers/Valhalla.d.ts +20 -0
- package/dist/core-map/services/types.d.ts +84 -0
- package/dist/core-map/storage/TileCache.d.ts +40 -0
- package/dist/core-map/storage/cachedFetch.d.ts +13 -0
- package/dist/core-map/storage/defaultCache.d.ts +3 -0
- package/dist/core-map/storage/index.d.ts +13 -0
- package/dist/core-map/storage/index.js +283 -0
- package/dist/core-map/storage/offlineRegion.d.ts +26 -0
- package/dist/core-map/style-spec/diff.d.ts +17 -0
- package/dist/core-map/style-spec/expressions/Color.d.ts +16 -0
- package/dist/core-map/style-spec/expressions/compile.d.ts +4 -0
- package/dist/core-map/style-spec/expressions/errors.d.ts +8 -0
- package/dist/core-map/style-spec/expressions/index.d.ts +16 -0
- package/dist/core-map/style-spec/expressions/legacyFilter.d.ts +6 -0
- package/dist/core-map/style-spec/expressions/operators/conversion.d.ts +1 -0
- package/dist/core-map/style-spec/expressions/operators/interpolate.d.ts +14 -0
- package/dist/core-map/style-spec/expressions/operators/logical.d.ts +1 -0
- package/dist/core-map/style-spec/expressions/operators/lookup.d.ts +1 -0
- package/dist/core-map/style-spec/expressions/operators/math.d.ts +1 -0
- package/dist/core-map/style-spec/expressions/operators/string.d.ts +1 -0
- package/dist/core-map/style-spec/expressions/registry.d.ts +29 -0
- package/dist/core-map/style-spec/expressions/types.d.ts +48 -0
- package/dist/core-map/style-spec/expressions/validate.d.ts +13 -0
- package/dist/core-map/style-spec/index.d.ts +68 -0
- package/dist/core-map/style-spec/index.js +2529 -0
- package/dist/core-map/style-spec/schema.d.ts +381 -0
- package/dist/core-map/style-spec/types.d.ts +375 -0
- package/dist/core-map/style-spec/validate.d.ts +14 -0
- package/dist/core-map/symbols/CollisionIndex.d.ts +21 -0
- package/dist/core-map/symbols/GlyphAtlas.d.ts +38 -0
- package/dist/core-map/symbols/IconAtlas.d.ts +18 -0
- package/dist/core-map/symbols/index.d.ts +6 -0
- package/dist/core-map/symbols/index.js +501 -0
- package/dist/index.d.ts +2 -4
- package/dist/index.js +18414 -1857
- package/package.json +50 -58
- package/src/core-map/ts-maps.css +725 -0
- package/dist/components/base.d.ts +0 -17
- package/dist/components/concerns/interactable.d.ts +0 -1
- package/dist/components/line.d.ts +0 -29
- package/dist/components/marker.d.ts +0 -50
- package/dist/components/region.d.ts +0 -46
- package/dist/components/tooltip.d.ts +0 -22
- package/dist/core/apply-transform.d.ts +0 -7
- package/dist/core/coords-to-point.d.ts +0 -12
- package/dist/core/create-lines.d.ts +0 -2
- package/dist/core/create-markers.d.ts +0 -2
- package/dist/core/create-regions.d.ts +0 -2
- package/dist/core/create-series.d.ts +0 -3
- package/dist/core/get-inset-for-point.d.ts +0 -13
- package/dist/core/get-marker-position.d.ts +0 -6
- package/dist/core/index.d.ts +0 -1
- package/dist/core/reposition-labels.d.ts +0 -2
- package/dist/core/reposition-lines.d.ts +0 -2
- package/dist/core/reposition-markers.d.ts +0 -2
- package/dist/core/resize.d.ts +0 -3
- package/dist/core/set-focus.d.ts +0 -2
- package/dist/core/set-scale.d.ts +0 -2
- package/dist/core/setup-container-events.d.ts +0 -2
- package/dist/core/setup-container-touch-events.d.ts +0 -2
- package/dist/core/setup-element-events.d.ts +0 -2
- package/dist/core/setup-zoom-buttons.d.ts +0 -2
- package/dist/core/update-size.d.ts +0 -2
- package/dist/data-visualization.d.ts +0 -17
- package/dist/defaults/events.d.ts +0 -1
- package/dist/defaults/options.d.ts +0 -1
- package/dist/event-handler.d.ts +0 -1
- package/dist/legend.d.ts +0 -17
- package/dist/map.d.ts +0 -81
- package/dist/maps/brasil.d.ts +0 -2
- package/dist/maps/brasil.js +0 -7
- package/dist/maps/canada.d.ts +0 -2
- package/dist/maps/canada.js +0 -7
- package/dist/maps/iraq.d.ts +0 -2
- package/dist/maps/iraq.js +0 -84
- package/dist/maps/italy.d.ts +0 -2
- package/dist/maps/italy.js +0 -7
- package/dist/maps/russia.d.ts +0 -2
- package/dist/maps/russia.js +0 -366
- package/dist/maps/spain.d.ts +0 -2
- package/dist/maps/spain.js +0 -7
- package/dist/maps/us-aea-en.d.ts +0 -2
- package/dist/maps/us-aea-en.js +0 -7
- package/dist/maps/us-lcc-en.d.ts +0 -2
- package/dist/maps/us-lcc-en.js +0 -7
- package/dist/maps/us-merc-en.d.ts +0 -2
- package/dist/maps/us-merc-en.js +0 -7
- package/dist/maps/us-mill-en.d.ts +0 -2
- package/dist/maps/us-mill-en.js +0 -7
- package/dist/maps/world-merc.d.ts +0 -2
- package/dist/maps/world-merc.js +0 -7
- package/dist/maps/world.d.ts +0 -2
- package/dist/maps/world.js +0 -7
- package/dist/projection.d.ts +0 -1
- package/dist/scales/ordinal-scale.d.ts +0 -12
- package/dist/series.d.ts +0 -14
- package/dist/svg/base-element.d.ts +0 -19
- package/dist/svg/canvas-element.d.ts +0 -21
- package/dist/svg/image-element.d.ts +0 -12
- package/dist/svg/shape-element.d.ts +0 -19
- package/dist/svg/text-element.d.ts +0 -7
- package/dist/types.d.ts +0 -418
- package/dist/util/deep-merge.d.ts +0 -2
- package/dist/util/index.d.ts +0 -18
- package/dist/utils.d.ts +0 -87
- package/dist/vector-map.d.ts +0 -5
|
@@ -0,0 +1,2529 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
8
|
+
var __toCommonJS = (from) => {
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
10
|
+
if (entry)
|
|
11
|
+
return entry;
|
|
12
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
__moduleCache.set(from, entry);
|
|
22
|
+
return entry;
|
|
23
|
+
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
29
|
+
var __export = (target, all) => {
|
|
30
|
+
for (var name in all)
|
|
31
|
+
__defProp(target, name, {
|
|
32
|
+
get: all[name],
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
39
|
+
|
|
40
|
+
// src/core-map/style-spec/diff.ts
|
|
41
|
+
function deepEqual(a, b) {
|
|
42
|
+
if (a === b)
|
|
43
|
+
return true;
|
|
44
|
+
if (typeof a !== typeof b)
|
|
45
|
+
return false;
|
|
46
|
+
if (a === null || b === null)
|
|
47
|
+
return a === b;
|
|
48
|
+
if (Array.isArray(a)) {
|
|
49
|
+
if (!Array.isArray(b) || a.length !== b.length)
|
|
50
|
+
return false;
|
|
51
|
+
for (let i = 0;i < a.length; i++) {
|
|
52
|
+
if (!deepEqual(a[i], b[i]))
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
if (typeof a === "object" && typeof b === "object") {
|
|
58
|
+
const ao = a;
|
|
59
|
+
const bo = b;
|
|
60
|
+
const keysA = Object.keys(ao);
|
|
61
|
+
const keysB = Object.keys(bo);
|
|
62
|
+
if (keysA.length !== keysB.length)
|
|
63
|
+
return false;
|
|
64
|
+
for (const k of keysA) {
|
|
65
|
+
if (!Object.prototype.hasOwnProperty.call(bo, k))
|
|
66
|
+
return false;
|
|
67
|
+
if (!deepEqual(ao[k], bo[k]))
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
function fullReset(next) {
|
|
75
|
+
return { commands: [{ command: "setStyle", args: [next] }] };
|
|
76
|
+
}
|
|
77
|
+
function indexLayers(layers) {
|
|
78
|
+
const out = {};
|
|
79
|
+
for (const layer of layers)
|
|
80
|
+
out[layer.id] = layer;
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
function diffPaint(prev, next, commands) {
|
|
84
|
+
const prevPaint = prev.paint || {};
|
|
85
|
+
const nextPaint = next.paint || {};
|
|
86
|
+
for (const key of Object.keys(nextPaint)) {
|
|
87
|
+
if (!deepEqual(prevPaint[key], nextPaint[key]))
|
|
88
|
+
commands.push({ command: "setPaintProperty", args: [next.id, key, nextPaint[key]] });
|
|
89
|
+
}
|
|
90
|
+
for (const key of Object.keys(prevPaint)) {
|
|
91
|
+
if (!(key in nextPaint))
|
|
92
|
+
commands.push({ command: "setPaintProperty", args: [next.id, key, undefined] });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function diffLayout(prev, next, commands) {
|
|
96
|
+
const prevLayout = prev.layout || {};
|
|
97
|
+
const nextLayout = next.layout || {};
|
|
98
|
+
for (const key of Object.keys(nextLayout)) {
|
|
99
|
+
if (!deepEqual(prevLayout[key], nextLayout[key]))
|
|
100
|
+
commands.push({ command: "setLayoutProperty", args: [next.id, key, nextLayout[key]] });
|
|
101
|
+
}
|
|
102
|
+
for (const key of Object.keys(prevLayout)) {
|
|
103
|
+
if (!(key in nextLayout))
|
|
104
|
+
commands.push({ command: "setLayoutProperty", args: [next.id, key, undefined] });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function diffStyles(prev, next) {
|
|
108
|
+
if (prev.version !== next.version)
|
|
109
|
+
return fullReset(next);
|
|
110
|
+
if (!deepEqual(prev.sprite, next.sprite))
|
|
111
|
+
return fullReset(next);
|
|
112
|
+
if (prev.glyphs !== next.glyphs)
|
|
113
|
+
return fullReset(next);
|
|
114
|
+
const commands = [];
|
|
115
|
+
if (!deepEqual(prev.transition, next.transition) && next.transition !== undefined)
|
|
116
|
+
commands.push({ command: "setTransition", args: [next.transition] });
|
|
117
|
+
if (!deepEqual(prev.light, next.light) && next.light !== undefined)
|
|
118
|
+
commands.push({ command: "setLight", args: [next.light] });
|
|
119
|
+
const prevSources = prev.sources || {};
|
|
120
|
+
const nextSources = next.sources || {};
|
|
121
|
+
for (const id of Object.keys(prevSources)) {
|
|
122
|
+
if (!(id in nextSources)) {
|
|
123
|
+
commands.push({ command: "removeSource", args: [id] });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
for (const id of Object.keys(nextSources)) {
|
|
127
|
+
const p = prevSources[id];
|
|
128
|
+
const n = nextSources[id];
|
|
129
|
+
if (p === undefined) {
|
|
130
|
+
commands.push({ command: "addSource", args: [id, n] });
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (deepEqual(p, n))
|
|
134
|
+
continue;
|
|
135
|
+
if (p.type === "geojson" && n.type === "geojson") {
|
|
136
|
+
const pNoData = { ...p, data: undefined };
|
|
137
|
+
const nNoData = { ...n, data: undefined };
|
|
138
|
+
if (deepEqual(pNoData, nNoData)) {
|
|
139
|
+
commands.push({ command: "setSourceData", args: [id, n.data] });
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
commands.push({ command: "removeSource", args: [id] });
|
|
144
|
+
commands.push({ command: "addSource", args: [id, n] });
|
|
145
|
+
}
|
|
146
|
+
const prevLayers = prev.layers || [];
|
|
147
|
+
const nextLayers = next.layers || [];
|
|
148
|
+
const prevById = indexLayers(prevLayers);
|
|
149
|
+
const nextById = indexLayers(nextLayers);
|
|
150
|
+
for (const layer of prevLayers) {
|
|
151
|
+
if (!(layer.id in nextById))
|
|
152
|
+
commands.push({ command: "removeLayer", args: [layer.id] });
|
|
153
|
+
}
|
|
154
|
+
const prevOrder = prevLayers.filter((l) => (l.id in nextById)).map((l) => l.id);
|
|
155
|
+
const nextOrder = nextLayers.filter((l) => (l.id in prevById)).map((l) => l.id);
|
|
156
|
+
if (prevOrder.length !== nextOrder.length)
|
|
157
|
+
return fullReset(next);
|
|
158
|
+
for (let i = 0;i < prevOrder.length; i++) {
|
|
159
|
+
if (prevOrder[i] !== nextOrder[i])
|
|
160
|
+
return fullReset(next);
|
|
161
|
+
}
|
|
162
|
+
for (let i = 0;i < nextLayers.length; i++) {
|
|
163
|
+
const n = nextLayers[i];
|
|
164
|
+
const p = prevById[n.id];
|
|
165
|
+
if (p === undefined) {
|
|
166
|
+
let before;
|
|
167
|
+
for (let j = i + 1;j < nextLayers.length; j++) {
|
|
168
|
+
if (nextLayers[j].id in prevById) {
|
|
169
|
+
before = nextLayers[j].id;
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
commands.push({ command: "addLayer", args: [n, before] });
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
if (p.type !== n.type) {
|
|
177
|
+
commands.push({ command: "removeLayer", args: [n.id] });
|
|
178
|
+
let before;
|
|
179
|
+
for (let j = i + 1;j < nextLayers.length; j++) {
|
|
180
|
+
if (nextLayers[j].id in prevById && nextLayers[j].id !== n.id) {
|
|
181
|
+
before = nextLayers[j].id;
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
commands.push({ command: "addLayer", args: [n, before] });
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const pSource = p.source;
|
|
189
|
+
const nSource = n.source;
|
|
190
|
+
const pSourceLayer = p["source-layer"];
|
|
191
|
+
const nSourceLayer = n["source-layer"];
|
|
192
|
+
if (pSource !== nSource || pSourceLayer !== nSourceLayer) {
|
|
193
|
+
commands.push({ command: "removeLayer", args: [n.id] });
|
|
194
|
+
let before;
|
|
195
|
+
for (let j = i + 1;j < nextLayers.length; j++) {
|
|
196
|
+
if (nextLayers[j].id in prevById && nextLayers[j].id !== n.id) {
|
|
197
|
+
before = nextLayers[j].id;
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
commands.push({ command: "addLayer", args: [n, before] });
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
if (p.minzoom !== n.minzoom || p.maxzoom !== n.maxzoom)
|
|
205
|
+
commands.push({ command: "setLayerZoomRange", args: [n.id, n.minzoom, n.maxzoom] });
|
|
206
|
+
const pFilter = p.filter;
|
|
207
|
+
const nFilter = n.filter;
|
|
208
|
+
if (!deepEqual(pFilter, nFilter))
|
|
209
|
+
commands.push({ command: "setFilter", args: [n.id, nFilter] });
|
|
210
|
+
diffPaint(p, n, commands);
|
|
211
|
+
diffLayout(p, n, commands);
|
|
212
|
+
}
|
|
213
|
+
return { commands };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/core-map/style-spec/expressions/Color.ts
|
|
217
|
+
function clamp01(n) {
|
|
218
|
+
return n < 0 ? 0 : n > 1 ? 1 : n;
|
|
219
|
+
}
|
|
220
|
+
function clampByte(n) {
|
|
221
|
+
return n < 0 ? 0 : n > 255 ? 255 : n;
|
|
222
|
+
}
|
|
223
|
+
function hexDigit(ch) {
|
|
224
|
+
const c = ch.charCodeAt(0);
|
|
225
|
+
if (c >= 48 && c <= 57)
|
|
226
|
+
return c - 48;
|
|
227
|
+
if (c >= 97 && c <= 102)
|
|
228
|
+
return c - 87;
|
|
229
|
+
if (c >= 65 && c <= 70)
|
|
230
|
+
return c - 55;
|
|
231
|
+
return Number.NaN;
|
|
232
|
+
}
|
|
233
|
+
function parseHex(hex) {
|
|
234
|
+
const len = hex.length;
|
|
235
|
+
if (len === 3 || len === 4) {
|
|
236
|
+
const r = hexDigit(hex[0]);
|
|
237
|
+
const g = hexDigit(hex[1]);
|
|
238
|
+
const b = hexDigit(hex[2]);
|
|
239
|
+
const a = len === 4 ? hexDigit(hex[3]) : 15;
|
|
240
|
+
if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b) || Number.isNaN(a))
|
|
241
|
+
return null;
|
|
242
|
+
return [r * 17 / 255, g * 17 / 255, b * 17 / 255, a * 17 / 255];
|
|
243
|
+
}
|
|
244
|
+
if (len === 6 || len === 8) {
|
|
245
|
+
const r = hexDigit(hex[0]) << 4 | hexDigit(hex[1]);
|
|
246
|
+
const g = hexDigit(hex[2]) << 4 | hexDigit(hex[3]);
|
|
247
|
+
const b = hexDigit(hex[4]) << 4 | hexDigit(hex[5]);
|
|
248
|
+
const a = len === 8 ? hexDigit(hex[6]) << 4 | hexDigit(hex[7]) : 255;
|
|
249
|
+
if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b) || Number.isNaN(a))
|
|
250
|
+
return null;
|
|
251
|
+
return [r / 255, g / 255, b / 255, a / 255];
|
|
252
|
+
}
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
function parseRgbComponent(input) {
|
|
256
|
+
const s = input.trim();
|
|
257
|
+
if (s.endsWith("%")) {
|
|
258
|
+
const n2 = Number.parseFloat(s.slice(0, -1));
|
|
259
|
+
if (Number.isNaN(n2))
|
|
260
|
+
return Number.NaN;
|
|
261
|
+
return clamp01(n2 / 100);
|
|
262
|
+
}
|
|
263
|
+
const n = Number.parseFloat(s);
|
|
264
|
+
if (Number.isNaN(n))
|
|
265
|
+
return Number.NaN;
|
|
266
|
+
return clampByte(n) / 255;
|
|
267
|
+
}
|
|
268
|
+
function parseAlpha(input) {
|
|
269
|
+
const s = input.trim();
|
|
270
|
+
if (s.endsWith("%")) {
|
|
271
|
+
const n2 = Number.parseFloat(s.slice(0, -1));
|
|
272
|
+
if (Number.isNaN(n2))
|
|
273
|
+
return Number.NaN;
|
|
274
|
+
return clamp01(n2 / 100);
|
|
275
|
+
}
|
|
276
|
+
const n = Number.parseFloat(s);
|
|
277
|
+
if (Number.isNaN(n))
|
|
278
|
+
return Number.NaN;
|
|
279
|
+
return clamp01(n);
|
|
280
|
+
}
|
|
281
|
+
function hslToRgb(h, s, l) {
|
|
282
|
+
const hn = (h % 360 + 360) % 360;
|
|
283
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
284
|
+
const x = c * (1 - Math.abs(hn / 60 % 2 - 1));
|
|
285
|
+
const m = l - c / 2;
|
|
286
|
+
let r = 0;
|
|
287
|
+
let g = 0;
|
|
288
|
+
let b = 0;
|
|
289
|
+
if (hn < 60) {
|
|
290
|
+
r = c;
|
|
291
|
+
g = x;
|
|
292
|
+
b = 0;
|
|
293
|
+
} else if (hn < 120) {
|
|
294
|
+
r = x;
|
|
295
|
+
g = c;
|
|
296
|
+
b = 0;
|
|
297
|
+
} else if (hn < 180) {
|
|
298
|
+
r = 0;
|
|
299
|
+
g = c;
|
|
300
|
+
b = x;
|
|
301
|
+
} else if (hn < 240) {
|
|
302
|
+
r = 0;
|
|
303
|
+
g = x;
|
|
304
|
+
b = c;
|
|
305
|
+
} else if (hn < 300) {
|
|
306
|
+
r = x;
|
|
307
|
+
g = 0;
|
|
308
|
+
b = c;
|
|
309
|
+
} else {
|
|
310
|
+
r = c;
|
|
311
|
+
g = 0;
|
|
312
|
+
b = x;
|
|
313
|
+
}
|
|
314
|
+
return [clamp01(r + m), clamp01(g + m), clamp01(b + m)];
|
|
315
|
+
}
|
|
316
|
+
function splitArgs(body) {
|
|
317
|
+
if (body.includes(","))
|
|
318
|
+
return body.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
319
|
+
const slashIdx = body.indexOf("/");
|
|
320
|
+
const main = slashIdx >= 0 ? body.slice(0, slashIdx) : body;
|
|
321
|
+
const alpha = slashIdx >= 0 ? body.slice(slashIdx + 1) : "";
|
|
322
|
+
const parts = main.trim().split(/\s+/).filter((s) => s.length > 0);
|
|
323
|
+
if (alpha.trim().length > 0)
|
|
324
|
+
parts.push(alpha.trim());
|
|
325
|
+
return parts;
|
|
326
|
+
}
|
|
327
|
+
function parseColor(css) {
|
|
328
|
+
if (typeof css !== "string")
|
|
329
|
+
return null;
|
|
330
|
+
const s = css.trim().toLowerCase();
|
|
331
|
+
if (s.length === 0)
|
|
332
|
+
return null;
|
|
333
|
+
if (s.startsWith("#"))
|
|
334
|
+
return parseHex(s.slice(1));
|
|
335
|
+
const openIdx = s.indexOf("(");
|
|
336
|
+
if (openIdx > 0 && s.endsWith(")")) {
|
|
337
|
+
const fn = s.slice(0, openIdx);
|
|
338
|
+
const body = s.slice(openIdx + 1, -1);
|
|
339
|
+
const args = splitArgs(body);
|
|
340
|
+
if (fn === "rgb" || fn === "rgba") {
|
|
341
|
+
if (args.length < 3 || args.length > 4)
|
|
342
|
+
return null;
|
|
343
|
+
const r = parseRgbComponent(args[0]);
|
|
344
|
+
const g = parseRgbComponent(args[1]);
|
|
345
|
+
const b = parseRgbComponent(args[2]);
|
|
346
|
+
const a = args.length === 4 ? parseAlpha(args[3]) : 1;
|
|
347
|
+
if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b) || Number.isNaN(a))
|
|
348
|
+
return null;
|
|
349
|
+
return [r, g, b, a];
|
|
350
|
+
}
|
|
351
|
+
if (fn === "hsl" || fn === "hsla") {
|
|
352
|
+
if (args.length < 3 || args.length > 4)
|
|
353
|
+
return null;
|
|
354
|
+
const hRaw = args[0].trim();
|
|
355
|
+
const h = Number.parseFloat(hRaw.endsWith("deg") ? hRaw.slice(0, -3) : hRaw);
|
|
356
|
+
const sStr = args[1].trim();
|
|
357
|
+
const lStr = args[2].trim();
|
|
358
|
+
if (!sStr.endsWith("%") || !lStr.endsWith("%"))
|
|
359
|
+
return null;
|
|
360
|
+
const sat = Number.parseFloat(sStr.slice(0, -1)) / 100;
|
|
361
|
+
const lig = Number.parseFloat(lStr.slice(0, -1)) / 100;
|
|
362
|
+
if (Number.isNaN(h) || Number.isNaN(sat) || Number.isNaN(lig))
|
|
363
|
+
return null;
|
|
364
|
+
const [r, g, b] = hslToRgb(h, clamp01(sat), clamp01(lig));
|
|
365
|
+
const a = args.length === 4 ? parseAlpha(args[3]) : 1;
|
|
366
|
+
if (Number.isNaN(a))
|
|
367
|
+
return null;
|
|
368
|
+
return [r, g, b, a];
|
|
369
|
+
}
|
|
370
|
+
return null;
|
|
371
|
+
}
|
|
372
|
+
const named = NAMED_COLORS[s];
|
|
373
|
+
if (named !== undefined)
|
|
374
|
+
return parseColor(named);
|
|
375
|
+
return null;
|
|
376
|
+
}
|
|
377
|
+
function lerpColor(a, b, t) {
|
|
378
|
+
const u = t < 0 ? 0 : t > 1 ? 1 : t;
|
|
379
|
+
return [
|
|
380
|
+
a[0] + (b[0] - a[0]) * u,
|
|
381
|
+
a[1] + (b[1] - a[1]) * u,
|
|
382
|
+
a[2] + (b[2] - a[2]) * u,
|
|
383
|
+
a[3] + (b[3] - a[3]) * u
|
|
384
|
+
];
|
|
385
|
+
}
|
|
386
|
+
function formatColor(c) {
|
|
387
|
+
const r = Math.round(clamp01(c[0]) * 255);
|
|
388
|
+
const g = Math.round(clamp01(c[1]) * 255);
|
|
389
|
+
const b = Math.round(clamp01(c[2]) * 255);
|
|
390
|
+
const a = clamp01(c[3]);
|
|
391
|
+
const aStr = a === 1 ? "1" : String(Number(a.toFixed(4)));
|
|
392
|
+
return `rgba(${r},${g},${b},${aStr})`;
|
|
393
|
+
}
|
|
394
|
+
var NAMED_COLORS;
|
|
395
|
+
var init_Color = __esm(() => {
|
|
396
|
+
NAMED_COLORS = {
|
|
397
|
+
aliceblue: "#f0f8ff",
|
|
398
|
+
antiquewhite: "#faebd7",
|
|
399
|
+
aqua: "#00ffff",
|
|
400
|
+
aquamarine: "#7fffd4",
|
|
401
|
+
azure: "#f0ffff",
|
|
402
|
+
beige: "#f5f5dc",
|
|
403
|
+
bisque: "#ffe4c4",
|
|
404
|
+
black: "#000000",
|
|
405
|
+
blanchedalmond: "#ffebcd",
|
|
406
|
+
blue: "#0000ff",
|
|
407
|
+
blueviolet: "#8a2be2",
|
|
408
|
+
brown: "#a52a2a",
|
|
409
|
+
burlywood: "#deb887",
|
|
410
|
+
cadetblue: "#5f9ea0",
|
|
411
|
+
chartreuse: "#7fff00",
|
|
412
|
+
chocolate: "#d2691e",
|
|
413
|
+
coral: "#ff7f50",
|
|
414
|
+
cornflowerblue: "#6495ed",
|
|
415
|
+
cornsilk: "#fff8dc",
|
|
416
|
+
crimson: "#dc143c",
|
|
417
|
+
cyan: "#00ffff",
|
|
418
|
+
darkblue: "#00008b",
|
|
419
|
+
darkcyan: "#008b8b",
|
|
420
|
+
darkgoldenrod: "#b8860b",
|
|
421
|
+
darkgray: "#a9a9a9",
|
|
422
|
+
darkgreen: "#006400",
|
|
423
|
+
darkgrey: "#a9a9a9",
|
|
424
|
+
darkkhaki: "#bdb76b",
|
|
425
|
+
darkmagenta: "#8b008b",
|
|
426
|
+
darkolivegreen: "#556b2f",
|
|
427
|
+
darkorange: "#ff8c00",
|
|
428
|
+
darkorchid: "#9932cc",
|
|
429
|
+
darkred: "#8b0000",
|
|
430
|
+
darksalmon: "#e9967a",
|
|
431
|
+
darkseagreen: "#8fbc8f",
|
|
432
|
+
darkslateblue: "#483d8b",
|
|
433
|
+
darkslategray: "#2f4f4f",
|
|
434
|
+
darkslategrey: "#2f4f4f",
|
|
435
|
+
darkturquoise: "#00ced1",
|
|
436
|
+
darkviolet: "#9400d3",
|
|
437
|
+
deeppink: "#ff1493",
|
|
438
|
+
deepskyblue: "#00bfff",
|
|
439
|
+
dimgray: "#696969",
|
|
440
|
+
dimgrey: "#696969",
|
|
441
|
+
dodgerblue: "#1e90ff",
|
|
442
|
+
firebrick: "#b22222",
|
|
443
|
+
floralwhite: "#fffaf0",
|
|
444
|
+
forestgreen: "#228b22",
|
|
445
|
+
fuchsia: "#ff00ff",
|
|
446
|
+
gainsboro: "#dcdcdc",
|
|
447
|
+
ghostwhite: "#f8f8ff",
|
|
448
|
+
gold: "#ffd700",
|
|
449
|
+
goldenrod: "#daa520",
|
|
450
|
+
gray: "#808080",
|
|
451
|
+
green: "#008000",
|
|
452
|
+
greenyellow: "#adff2f",
|
|
453
|
+
grey: "#808080",
|
|
454
|
+
honeydew: "#f0fff0",
|
|
455
|
+
hotpink: "#ff69b4",
|
|
456
|
+
indianred: "#cd5c5c",
|
|
457
|
+
indigo: "#4b0082",
|
|
458
|
+
ivory: "#fffff0",
|
|
459
|
+
khaki: "#f0e68c",
|
|
460
|
+
lavender: "#e6e6fa",
|
|
461
|
+
lavenderblush: "#fff0f5",
|
|
462
|
+
lawngreen: "#7cfc00",
|
|
463
|
+
lemonchiffon: "#fffacd",
|
|
464
|
+
lightblue: "#add8e6",
|
|
465
|
+
lightcoral: "#f08080",
|
|
466
|
+
lightcyan: "#e0ffff",
|
|
467
|
+
lightgoldenrodyellow: "#fafad2",
|
|
468
|
+
lightgray: "#d3d3d3",
|
|
469
|
+
lightgreen: "#90ee90",
|
|
470
|
+
lightgrey: "#d3d3d3",
|
|
471
|
+
lightpink: "#ffb6c1",
|
|
472
|
+
lightsalmon: "#ffa07a",
|
|
473
|
+
lightseagreen: "#20b2aa",
|
|
474
|
+
lightskyblue: "#87cefa",
|
|
475
|
+
lightslategray: "#778899",
|
|
476
|
+
lightslategrey: "#778899",
|
|
477
|
+
lightsteelblue: "#b0c4de",
|
|
478
|
+
lightyellow: "#ffffe0",
|
|
479
|
+
lime: "#00ff00",
|
|
480
|
+
limegreen: "#32cd32",
|
|
481
|
+
linen: "#faf0e6",
|
|
482
|
+
magenta: "#ff00ff",
|
|
483
|
+
maroon: "#800000",
|
|
484
|
+
mediumaquamarine: "#66cdaa",
|
|
485
|
+
mediumblue: "#0000cd",
|
|
486
|
+
mediumorchid: "#ba55d3",
|
|
487
|
+
mediumpurple: "#9370db",
|
|
488
|
+
mediumseagreen: "#3cb371",
|
|
489
|
+
mediumslateblue: "#7b68ee",
|
|
490
|
+
mediumspringgreen: "#00fa9a",
|
|
491
|
+
mediumturquoise: "#48d1cc",
|
|
492
|
+
mediumvioletred: "#c71585",
|
|
493
|
+
midnightblue: "#191970",
|
|
494
|
+
mintcream: "#f5fffa",
|
|
495
|
+
mistyrose: "#ffe4e1",
|
|
496
|
+
moccasin: "#ffe4b5",
|
|
497
|
+
navajowhite: "#ffdead",
|
|
498
|
+
navy: "#000080",
|
|
499
|
+
oldlace: "#fdf5e6",
|
|
500
|
+
olive: "#808000",
|
|
501
|
+
olivedrab: "#6b8e23",
|
|
502
|
+
orange: "#ffa500",
|
|
503
|
+
orangered: "#ff4500",
|
|
504
|
+
orchid: "#da70d6",
|
|
505
|
+
palegoldenrod: "#eee8aa",
|
|
506
|
+
palegreen: "#98fb98",
|
|
507
|
+
paleturquoise: "#afeeee",
|
|
508
|
+
palevioletred: "#db7093",
|
|
509
|
+
papayawhip: "#ffefd5",
|
|
510
|
+
peachpuff: "#ffdab9",
|
|
511
|
+
peru: "#cd853f",
|
|
512
|
+
pink: "#ffc0cb",
|
|
513
|
+
plum: "#dda0dd",
|
|
514
|
+
powderblue: "#b0e0e6",
|
|
515
|
+
purple: "#800080",
|
|
516
|
+
rebeccapurple: "#663399",
|
|
517
|
+
red: "#ff0000",
|
|
518
|
+
rosybrown: "#bc8f8f",
|
|
519
|
+
royalblue: "#4169e1",
|
|
520
|
+
saddlebrown: "#8b4513",
|
|
521
|
+
salmon: "#fa8072",
|
|
522
|
+
sandybrown: "#f4a460",
|
|
523
|
+
seagreen: "#2e8b57",
|
|
524
|
+
seashell: "#fff5ee",
|
|
525
|
+
sienna: "#a0522d",
|
|
526
|
+
silver: "#c0c0c0",
|
|
527
|
+
skyblue: "#87ceeb",
|
|
528
|
+
steelblue: "#4682b4",
|
|
529
|
+
slateblue: "#6a5acd",
|
|
530
|
+
slategray: "#708090",
|
|
531
|
+
slategrey: "#708090",
|
|
532
|
+
snow: "#fffafa",
|
|
533
|
+
springgreen: "#00ff7f",
|
|
534
|
+
tan: "#d2b48c",
|
|
535
|
+
teal: "#008080",
|
|
536
|
+
thistle: "#d8bfd8",
|
|
537
|
+
tomato: "#ff6347",
|
|
538
|
+
transparent: "rgba(0,0,0,0)",
|
|
539
|
+
turquoise: "#40e0d0",
|
|
540
|
+
violet: "#ee82ee",
|
|
541
|
+
wheat: "#f5deb3",
|
|
542
|
+
white: "#ffffff",
|
|
543
|
+
whitesmoke: "#f5f5f5",
|
|
544
|
+
yellow: "#ffff00",
|
|
545
|
+
yellowgreen: "#9acd32"
|
|
546
|
+
};
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
// src/core-map/style-spec/expressions/errors.ts
|
|
550
|
+
var ExpressionError;
|
|
551
|
+
var init_errors = __esm(() => {
|
|
552
|
+
ExpressionError = class ExpressionError extends Error {
|
|
553
|
+
constructor(message, expression, path = []) {
|
|
554
|
+
const prefix = path.length > 0 ? `[${path.map((p) => JSON.stringify(p)).join("][")}] ` : "";
|
|
555
|
+
super(`${prefix}${message}`);
|
|
556
|
+
this.name = "ExpressionError";
|
|
557
|
+
this.expression = expression;
|
|
558
|
+
this.path = path.slice();
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
// src/core-map/style-spec/expressions/registry.ts
|
|
564
|
+
function registerOperator(name, fn) {
|
|
565
|
+
OPERATORS[name] = fn;
|
|
566
|
+
}
|
|
567
|
+
function getOperator(name) {
|
|
568
|
+
return OPERATORS[name];
|
|
569
|
+
}
|
|
570
|
+
function hasOperator(name) {
|
|
571
|
+
return Object.prototype.hasOwnProperty.call(OPERATORS, name);
|
|
572
|
+
}
|
|
573
|
+
var OPERATORS;
|
|
574
|
+
var init_registry = __esm(() => {
|
|
575
|
+
OPERATORS = {};
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
// src/core-map/style-spec/expressions/operators/conversion.ts
|
|
579
|
+
function mergeDeps(children) {
|
|
580
|
+
let z = false;
|
|
581
|
+
let f = false;
|
|
582
|
+
let s = false;
|
|
583
|
+
for (const c of children) {
|
|
584
|
+
if (c.dependsOnZoom)
|
|
585
|
+
z = true;
|
|
586
|
+
if (c.dependsOnFeature)
|
|
587
|
+
f = true;
|
|
588
|
+
if (c.dependsOnFeatureState)
|
|
589
|
+
s = true;
|
|
590
|
+
}
|
|
591
|
+
return { dependsOnZoom: z, dependsOnFeature: f, dependsOnFeatureState: s };
|
|
592
|
+
}
|
|
593
|
+
function registerConversionOps() {
|
|
594
|
+
registerOperator("to-string", (args, compile, path) => {
|
|
595
|
+
if (args.length !== 1)
|
|
596
|
+
throw new ExpressionError(`"to-string" expects 1 argument, got ${args.length}`, ["to-string", ...args], path);
|
|
597
|
+
const inner = compile(args[0], "value", path.concat(1));
|
|
598
|
+
return {
|
|
599
|
+
evaluate: (ctx) => {
|
|
600
|
+
const v = inner.evaluate(ctx);
|
|
601
|
+
if (v === null || v === undefined)
|
|
602
|
+
return "";
|
|
603
|
+
if (typeof v === "string")
|
|
604
|
+
return v;
|
|
605
|
+
if (typeof v === "number" || typeof v === "boolean")
|
|
606
|
+
return String(v);
|
|
607
|
+
try {
|
|
608
|
+
return JSON.stringify(v);
|
|
609
|
+
} catch {
|
|
610
|
+
return String(v);
|
|
611
|
+
}
|
|
612
|
+
},
|
|
613
|
+
returnType: "string",
|
|
614
|
+
...mergeDeps([inner])
|
|
615
|
+
};
|
|
616
|
+
});
|
|
617
|
+
registerOperator("to-number", (args, compile, path) => {
|
|
618
|
+
if (args.length < 1)
|
|
619
|
+
throw new ExpressionError('"to-number" expects at least 1 argument', ["to-number", ...args], path);
|
|
620
|
+
const children = args.map((a, i) => compile(a, "value", path.concat(i + 1)));
|
|
621
|
+
const expr = ["to-number", ...args];
|
|
622
|
+
return {
|
|
623
|
+
evaluate: (ctx) => {
|
|
624
|
+
for (let i = 0;i < children.length; i++) {
|
|
625
|
+
const v = children[i].evaluate(ctx);
|
|
626
|
+
if (v === null || v === undefined)
|
|
627
|
+
continue;
|
|
628
|
+
if (typeof v === "number") {
|
|
629
|
+
if (!Number.isNaN(v))
|
|
630
|
+
return v;
|
|
631
|
+
continue;
|
|
632
|
+
}
|
|
633
|
+
if (typeof v === "boolean")
|
|
634
|
+
return v ? 1 : 0;
|
|
635
|
+
if (typeof v === "string") {
|
|
636
|
+
const s = v.trim();
|
|
637
|
+
if (s.length === 0)
|
|
638
|
+
continue;
|
|
639
|
+
const n = Number(s);
|
|
640
|
+
if (!Number.isNaN(n))
|
|
641
|
+
return n;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
throw new ExpressionError('"to-number": could not convert any argument to a number', expr);
|
|
645
|
+
},
|
|
646
|
+
returnType: "number",
|
|
647
|
+
...mergeDeps(children)
|
|
648
|
+
};
|
|
649
|
+
});
|
|
650
|
+
registerOperator("to-boolean", (args, compile, path) => {
|
|
651
|
+
if (args.length !== 1)
|
|
652
|
+
throw new ExpressionError(`"to-boolean" expects 1 argument, got ${args.length}`, ["to-boolean", ...args], path);
|
|
653
|
+
const inner = compile(args[0], "value", path.concat(1));
|
|
654
|
+
return {
|
|
655
|
+
evaluate: (ctx) => {
|
|
656
|
+
const v = inner.evaluate(ctx);
|
|
657
|
+
if (v === null || v === undefined)
|
|
658
|
+
return false;
|
|
659
|
+
if (typeof v === "number")
|
|
660
|
+
return v !== 0 && !Number.isNaN(v);
|
|
661
|
+
if (typeof v === "string")
|
|
662
|
+
return v.length > 0;
|
|
663
|
+
if (typeof v === "boolean")
|
|
664
|
+
return v;
|
|
665
|
+
if (Array.isArray(v))
|
|
666
|
+
return v.length > 0;
|
|
667
|
+
if (typeof v === "object")
|
|
668
|
+
return true;
|
|
669
|
+
return Boolean(v);
|
|
670
|
+
},
|
|
671
|
+
returnType: "boolean",
|
|
672
|
+
...mergeDeps([inner])
|
|
673
|
+
};
|
|
674
|
+
});
|
|
675
|
+
registerOperator("to-rgba", (args, compile, path) => {
|
|
676
|
+
if (args.length !== 1)
|
|
677
|
+
throw new ExpressionError(`"to-rgba" expects 1 argument, got ${args.length}`, ["to-rgba", ...args], path);
|
|
678
|
+
const inner = compile(args[0], "color", path.concat(1));
|
|
679
|
+
const expr = ["to-rgba", ...args];
|
|
680
|
+
return {
|
|
681
|
+
evaluate: (ctx) => {
|
|
682
|
+
const v = inner.evaluate(ctx);
|
|
683
|
+
const rgba = coerceColor(v);
|
|
684
|
+
if (!rgba)
|
|
685
|
+
throw new ExpressionError(`"to-rgba": cannot convert ${String(v)} to a color`, expr);
|
|
686
|
+
return [
|
|
687
|
+
Math.round(rgba[0] * 255),
|
|
688
|
+
Math.round(rgba[1] * 255),
|
|
689
|
+
Math.round(rgba[2] * 255),
|
|
690
|
+
rgba[3]
|
|
691
|
+
];
|
|
692
|
+
},
|
|
693
|
+
returnType: "array",
|
|
694
|
+
...mergeDeps([inner])
|
|
695
|
+
};
|
|
696
|
+
});
|
|
697
|
+
registerOperator("to-color", (args, compile, path) => {
|
|
698
|
+
if (args.length < 1)
|
|
699
|
+
throw new ExpressionError('"to-color" expects at least 1 argument', ["to-color", ...args], path);
|
|
700
|
+
const children = args.map((a, i) => compile(a, "value", path.concat(i + 1)));
|
|
701
|
+
const expr = ["to-color", ...args];
|
|
702
|
+
return {
|
|
703
|
+
evaluate: (ctx) => {
|
|
704
|
+
for (let i = 0;i < children.length; i++) {
|
|
705
|
+
const v = children[i].evaluate(ctx);
|
|
706
|
+
const rgba = coerceColor(v);
|
|
707
|
+
if (rgba)
|
|
708
|
+
return formatRgba(rgba);
|
|
709
|
+
}
|
|
710
|
+
throw new ExpressionError('"to-color": could not convert any argument to a color', expr);
|
|
711
|
+
},
|
|
712
|
+
returnType: "color",
|
|
713
|
+
...mergeDeps(children)
|
|
714
|
+
};
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
function coerceColor(v) {
|
|
718
|
+
if (typeof v === "string")
|
|
719
|
+
return parseColor(v);
|
|
720
|
+
if (Array.isArray(v) && (v.length === 3 || v.length === 4)) {
|
|
721
|
+
const r = Number(v[0]);
|
|
722
|
+
const g = Number(v[1]);
|
|
723
|
+
const b = Number(v[2]);
|
|
724
|
+
const a = v.length === 4 ? Number(v[3]) : 1;
|
|
725
|
+
if ([r, g, b, a].some(Number.isNaN))
|
|
726
|
+
return null;
|
|
727
|
+
return [clamp012(r / 255), clamp012(g / 255), clamp012(b / 255), clamp012(a)];
|
|
728
|
+
}
|
|
729
|
+
return null;
|
|
730
|
+
}
|
|
731
|
+
function clamp012(n) {
|
|
732
|
+
return n < 0 ? 0 : n > 1 ? 1 : n;
|
|
733
|
+
}
|
|
734
|
+
function formatRgba(c) {
|
|
735
|
+
const r = Math.round(clamp012(c[0]) * 255);
|
|
736
|
+
const g = Math.round(clamp012(c[1]) * 255);
|
|
737
|
+
const b = Math.round(clamp012(c[2]) * 255);
|
|
738
|
+
const a = clamp012(c[3]);
|
|
739
|
+
return `rgba(${r},${g},${b},${a === 1 ? "1" : String(Number(a.toFixed(4)))})`;
|
|
740
|
+
}
|
|
741
|
+
var init_conversion = __esm(() => {
|
|
742
|
+
init_Color();
|
|
743
|
+
init_errors();
|
|
744
|
+
init_registry();
|
|
745
|
+
});
|
|
746
|
+
|
|
747
|
+
// src/core-map/style-spec/expressions/operators/interpolate.ts
|
|
748
|
+
function mergeDeps2(children) {
|
|
749
|
+
let z = false;
|
|
750
|
+
let f = false;
|
|
751
|
+
let s = false;
|
|
752
|
+
for (const c of children) {
|
|
753
|
+
if (c.dependsOnZoom)
|
|
754
|
+
z = true;
|
|
755
|
+
if (c.dependsOnFeature)
|
|
756
|
+
f = true;
|
|
757
|
+
if (c.dependsOnFeatureState)
|
|
758
|
+
s = true;
|
|
759
|
+
}
|
|
760
|
+
return { dependsOnZoom: z, dependsOnFeature: f, dependsOnFeatureState: s };
|
|
761
|
+
}
|
|
762
|
+
function findStop(stops, x) {
|
|
763
|
+
if (stops.length === 0 || x < stops[0])
|
|
764
|
+
return -1;
|
|
765
|
+
let lo = 0;
|
|
766
|
+
let hi = stops.length - 1;
|
|
767
|
+
while (lo < hi) {
|
|
768
|
+
const mid = lo + hi + 1 >> 1;
|
|
769
|
+
if (stops[mid] <= x)
|
|
770
|
+
lo = mid;
|
|
771
|
+
else
|
|
772
|
+
hi = mid - 1;
|
|
773
|
+
}
|
|
774
|
+
return lo;
|
|
775
|
+
}
|
|
776
|
+
function linearT(a, b, x) {
|
|
777
|
+
if (a === b)
|
|
778
|
+
return 0;
|
|
779
|
+
const t = (x - a) / (b - a);
|
|
780
|
+
return t < 0 ? 0 : t > 1 ? 1 : t;
|
|
781
|
+
}
|
|
782
|
+
function exponentialT(base, a, b, x) {
|
|
783
|
+
if (a === b)
|
|
784
|
+
return 0;
|
|
785
|
+
if (base === 1)
|
|
786
|
+
return linearT(a, b, x);
|
|
787
|
+
const diff = b - a;
|
|
788
|
+
const progress = x - a;
|
|
789
|
+
const t = (base ** progress - 1) / (base ** diff - 1);
|
|
790
|
+
return t < 0 ? 0 : t > 1 ? 1 : t;
|
|
791
|
+
}
|
|
792
|
+
function cubicBezierT(x1, y1, x2, y2) {
|
|
793
|
+
const cx = 3 * x1;
|
|
794
|
+
const bx = 3 * (x2 - x1) - cx;
|
|
795
|
+
const ax = 1 - cx - bx;
|
|
796
|
+
const cy = 3 * y1;
|
|
797
|
+
const by = 3 * (y2 - y1) - cy;
|
|
798
|
+
const ay = 1 - cy - by;
|
|
799
|
+
const sampleX = (t) => ((ax * t + bx) * t + cx) * t;
|
|
800
|
+
const sampleY = (t) => ((ay * t + by) * t + cy) * t;
|
|
801
|
+
const sampleDerivX = (t) => (3 * ax * t + 2 * bx) * t + cx;
|
|
802
|
+
return (u) => {
|
|
803
|
+
if (u <= 0)
|
|
804
|
+
return 0;
|
|
805
|
+
if (u >= 1)
|
|
806
|
+
return 1;
|
|
807
|
+
let t = u;
|
|
808
|
+
for (let i = 0;i < 8; i++) {
|
|
809
|
+
const x = sampleX(t) - u;
|
|
810
|
+
if (Math.abs(x) < 0.000001)
|
|
811
|
+
return sampleY(t);
|
|
812
|
+
const d = sampleDerivX(t);
|
|
813
|
+
if (Math.abs(d) < 0.000001)
|
|
814
|
+
break;
|
|
815
|
+
t -= x / d;
|
|
816
|
+
}
|
|
817
|
+
let lo = 0;
|
|
818
|
+
let hi = 1;
|
|
819
|
+
let tt = u;
|
|
820
|
+
for (let i = 0;i < 20; i++) {
|
|
821
|
+
const x = sampleX(tt) - u;
|
|
822
|
+
if (Math.abs(x) < 0.000001)
|
|
823
|
+
return sampleY(tt);
|
|
824
|
+
if (x > 0)
|
|
825
|
+
hi = tt;
|
|
826
|
+
else
|
|
827
|
+
lo = tt;
|
|
828
|
+
tt = (lo + hi) / 2;
|
|
829
|
+
}
|
|
830
|
+
return sampleY(tt);
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
function parseInterp(spec, path) {
|
|
834
|
+
if (!Array.isArray(spec) || spec.length === 0)
|
|
835
|
+
throw new ExpressionError('"interpolate": interpolation type required', spec, path);
|
|
836
|
+
const head = spec[0];
|
|
837
|
+
if (head === "linear")
|
|
838
|
+
return { kind: "linear" };
|
|
839
|
+
if (head === "exponential") {
|
|
840
|
+
const base = Number(spec[1]);
|
|
841
|
+
if (!Number.isFinite(base) || base <= 0)
|
|
842
|
+
throw new ExpressionError('"interpolate": exponential base must be a positive number', spec, path);
|
|
843
|
+
return { kind: "exponential", base };
|
|
844
|
+
}
|
|
845
|
+
if (head === "cubic-bezier") {
|
|
846
|
+
const x1 = Number(spec[1]);
|
|
847
|
+
const y1 = Number(spec[2]);
|
|
848
|
+
const x2 = Number(spec[3]);
|
|
849
|
+
const y2 = Number(spec[4]);
|
|
850
|
+
if ([x1, y1, x2, y2].some((n) => !Number.isFinite(n)))
|
|
851
|
+
throw new ExpressionError('"interpolate": cubic-bezier requires 4 numeric control points', spec, path);
|
|
852
|
+
return { kind: "cubic-bezier", bezier: cubicBezierT(x1, y1, x2, y2) };
|
|
853
|
+
}
|
|
854
|
+
throw new ExpressionError(`"interpolate": unknown interpolation type ${JSON.stringify(head)}`, spec, path);
|
|
855
|
+
}
|
|
856
|
+
function pickBlender(returnType) {
|
|
857
|
+
if (returnType === "number") {
|
|
858
|
+
return (a, b, t) => {
|
|
859
|
+
const av = Number(a);
|
|
860
|
+
const bv = Number(b);
|
|
861
|
+
return av + (bv - av) * t;
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
if (returnType === "color") {
|
|
865
|
+
return (a, b, t) => {
|
|
866
|
+
const ac = toRgba(a);
|
|
867
|
+
const bc = toRgba(b);
|
|
868
|
+
if (!ac || !bc)
|
|
869
|
+
return a;
|
|
870
|
+
return formatRgba2(lerpColor(ac, bc, t));
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
if (returnType === "string") {
|
|
874
|
+
return (a, b, t) => {
|
|
875
|
+
if (typeof a !== "string" || typeof b !== "string")
|
|
876
|
+
return t < 1 ? a : b;
|
|
877
|
+
const ac = toRgba(a);
|
|
878
|
+
const bc = toRgba(b);
|
|
879
|
+
if (!ac || !bc)
|
|
880
|
+
return t < 1 ? a : b;
|
|
881
|
+
return formatRgba2(lerpColor(ac, bc, t));
|
|
882
|
+
};
|
|
883
|
+
}
|
|
884
|
+
if (returnType === "array") {
|
|
885
|
+
return (a, b, t) => {
|
|
886
|
+
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length)
|
|
887
|
+
return a;
|
|
888
|
+
const out = new Array(a.length);
|
|
889
|
+
for (let i = 0;i < a.length; i++) {
|
|
890
|
+
const av = Number(a[i]);
|
|
891
|
+
const bv = Number(b[i]);
|
|
892
|
+
out[i] = av + (bv - av) * t;
|
|
893
|
+
}
|
|
894
|
+
return out;
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
return (a, _b, t) => t < 1 ? a : _b;
|
|
898
|
+
}
|
|
899
|
+
function toRgba(v) {
|
|
900
|
+
if (typeof v === "string")
|
|
901
|
+
return parseColor(v);
|
|
902
|
+
if (Array.isArray(v) && (v.length === 3 || v.length === 4)) {
|
|
903
|
+
const r = Number(v[0]) / 255;
|
|
904
|
+
const g = Number(v[1]) / 255;
|
|
905
|
+
const b = Number(v[2]) / 255;
|
|
906
|
+
const a = v.length === 4 ? Number(v[3]) : 1;
|
|
907
|
+
if ([r, g, b, a].some(Number.isNaN))
|
|
908
|
+
return null;
|
|
909
|
+
return [clamp013(r), clamp013(g), clamp013(b), clamp013(a)];
|
|
910
|
+
}
|
|
911
|
+
return null;
|
|
912
|
+
}
|
|
913
|
+
function clamp013(n) {
|
|
914
|
+
return n < 0 ? 0 : n > 1 ? 1 : n;
|
|
915
|
+
}
|
|
916
|
+
function formatRgba2(c) {
|
|
917
|
+
const r = Math.round(clamp013(c[0]) * 255);
|
|
918
|
+
const g = Math.round(clamp013(c[1]) * 255);
|
|
919
|
+
const b = Math.round(clamp013(c[2]) * 255);
|
|
920
|
+
const a = clamp013(c[3]);
|
|
921
|
+
return `rgba(${r},${g},${b},${a === 1 ? "1" : String(Number(a.toFixed(4)))})`;
|
|
922
|
+
}
|
|
923
|
+
function registerInterpolateOps() {
|
|
924
|
+
registerOperator("interpolate", (args, compile, path, expected) => {
|
|
925
|
+
if (args.length < 4 || args.length % 2 !== 0)
|
|
926
|
+
throw new ExpressionError(`"interpolate" expects interpolation, input, (stop, value)+ — got ${args.length} arguments`, ["interpolate", ...args], path);
|
|
927
|
+
const interp = parseInterp(args[0], path.concat(1));
|
|
928
|
+
const input = compile(args[1], "number", path.concat(2));
|
|
929
|
+
const stopExpected = expected === "value" ? "value" : expected;
|
|
930
|
+
const stopInputs = [];
|
|
931
|
+
const stopOutputs = [];
|
|
932
|
+
for (let i = 2;i < args.length; i += 2) {
|
|
933
|
+
const stopIn = args[i];
|
|
934
|
+
if (typeof stopIn !== "number")
|
|
935
|
+
throw new ExpressionError(`"interpolate": stop input at position ${i} must be a number literal`, ["interpolate", ...args], path.concat(i + 1));
|
|
936
|
+
stopInputs.push(stopIn);
|
|
937
|
+
stopOutputs.push(compile(args[i + 1], stopExpected, path.concat(i + 2)));
|
|
938
|
+
}
|
|
939
|
+
for (let i = 1;i < stopInputs.length; i++) {
|
|
940
|
+
if (stopInputs[i] <= stopInputs[i - 1])
|
|
941
|
+
throw new ExpressionError('"interpolate": stop inputs must be strictly increasing', ["interpolate", ...args], path);
|
|
942
|
+
}
|
|
943
|
+
const returnType = expected !== "value" ? expected : stopOutputs[0].returnType;
|
|
944
|
+
const blend = pickBlender(returnType);
|
|
945
|
+
const children = [input, ...stopOutputs];
|
|
946
|
+
return {
|
|
947
|
+
evaluate: (ctx) => {
|
|
948
|
+
const x = Number(input.evaluate(ctx));
|
|
949
|
+
if (!Number.isFinite(x))
|
|
950
|
+
return stopOutputs[0].evaluate(ctx);
|
|
951
|
+
const idx = findStop(stopInputs, x);
|
|
952
|
+
if (idx < 0)
|
|
953
|
+
return stopOutputs[0].evaluate(ctx);
|
|
954
|
+
if (idx >= stopInputs.length - 1)
|
|
955
|
+
return stopOutputs[stopOutputs.length - 1].evaluate(ctx);
|
|
956
|
+
const a = stopInputs[idx];
|
|
957
|
+
const b = stopInputs[idx + 1];
|
|
958
|
+
let t;
|
|
959
|
+
if (interp.kind === "linear")
|
|
960
|
+
t = linearT(a, b, x);
|
|
961
|
+
else if (interp.kind === "exponential")
|
|
962
|
+
t = exponentialT(interp.base, a, b, x);
|
|
963
|
+
else {
|
|
964
|
+
const u = linearT(a, b, x);
|
|
965
|
+
t = interp.bezier(u);
|
|
966
|
+
}
|
|
967
|
+
return blend(stopOutputs[idx].evaluate(ctx), stopOutputs[idx + 1].evaluate(ctx), t);
|
|
968
|
+
},
|
|
969
|
+
returnType,
|
|
970
|
+
...mergeDeps2(children)
|
|
971
|
+
};
|
|
972
|
+
});
|
|
973
|
+
registerOperator("step", (args, compile, path, expected) => {
|
|
974
|
+
if (args.length < 4 || args.length % 2 !== 0)
|
|
975
|
+
throw new ExpressionError(`"step" expects input, fallback, (stop, value)+ — got ${args.length} arguments`, ["step", ...args], path);
|
|
976
|
+
const input = compile(args[0], "number", path.concat(1));
|
|
977
|
+
const fallback = compile(args[1], expected, path.concat(2));
|
|
978
|
+
const stopInputs = [];
|
|
979
|
+
const stopOutputs = [];
|
|
980
|
+
for (let i = 2;i < args.length; i += 2) {
|
|
981
|
+
const stopIn = args[i];
|
|
982
|
+
if (typeof stopIn !== "number")
|
|
983
|
+
throw new ExpressionError(`"step": stop input at position ${i} must be a number literal`, ["step", ...args], path.concat(i + 1));
|
|
984
|
+
stopInputs.push(stopIn);
|
|
985
|
+
stopOutputs.push(compile(args[i + 1], expected, path.concat(i + 2)));
|
|
986
|
+
}
|
|
987
|
+
for (let i = 1;i < stopInputs.length; i++) {
|
|
988
|
+
if (stopInputs[i] <= stopInputs[i - 1])
|
|
989
|
+
throw new ExpressionError('"step": stop inputs must be strictly increasing', ["step", ...args], path);
|
|
990
|
+
}
|
|
991
|
+
const returnType = expected !== "value" ? expected : stopOutputs.length > 0 ? stopOutputs[0].returnType : fallback.returnType;
|
|
992
|
+
const children = [input, fallback, ...stopOutputs];
|
|
993
|
+
return {
|
|
994
|
+
evaluate: (ctx) => {
|
|
995
|
+
const x = Number(input.evaluate(ctx));
|
|
996
|
+
if (!Number.isFinite(x))
|
|
997
|
+
return fallback.evaluate(ctx);
|
|
998
|
+
const idx = findStop(stopInputs, x);
|
|
999
|
+
if (idx < 0)
|
|
1000
|
+
return fallback.evaluate(ctx);
|
|
1001
|
+
return stopOutputs[idx].evaluate(ctx);
|
|
1002
|
+
},
|
|
1003
|
+
returnType,
|
|
1004
|
+
...mergeDeps2(children)
|
|
1005
|
+
};
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
var init_interpolate = __esm(() => {
|
|
1009
|
+
init_Color();
|
|
1010
|
+
init_errors();
|
|
1011
|
+
init_registry();
|
|
1012
|
+
});
|
|
1013
|
+
|
|
1014
|
+
// src/core-map/style-spec/expressions/operators/logical.ts
|
|
1015
|
+
function mergeDeps3(children) {
|
|
1016
|
+
let z = false;
|
|
1017
|
+
let f = false;
|
|
1018
|
+
let s = false;
|
|
1019
|
+
for (const c of children) {
|
|
1020
|
+
if (c.dependsOnZoom)
|
|
1021
|
+
z = true;
|
|
1022
|
+
if (c.dependsOnFeature)
|
|
1023
|
+
f = true;
|
|
1024
|
+
if (c.dependsOnFeatureState)
|
|
1025
|
+
s = true;
|
|
1026
|
+
}
|
|
1027
|
+
return { dependsOnZoom: z, dependsOnFeature: f, dependsOnFeatureState: s };
|
|
1028
|
+
}
|
|
1029
|
+
function strictEq(a, b) {
|
|
1030
|
+
if (a === b)
|
|
1031
|
+
return true;
|
|
1032
|
+
return false;
|
|
1033
|
+
}
|
|
1034
|
+
function compare(a, b) {
|
|
1035
|
+
if (typeof a === "number" && typeof b === "number") {
|
|
1036
|
+
if (Number.isNaN(a) || Number.isNaN(b))
|
|
1037
|
+
return Number.NaN;
|
|
1038
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
1039
|
+
}
|
|
1040
|
+
if (typeof a === "string" && typeof b === "string")
|
|
1041
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
1042
|
+
return Number.NaN;
|
|
1043
|
+
}
|
|
1044
|
+
function registerLogicalOps() {
|
|
1045
|
+
registerOperator("!", (args, compile, path) => {
|
|
1046
|
+
if (args.length !== 1)
|
|
1047
|
+
throw new ExpressionError(`"!" expects 1 argument, got ${args.length}`, ["!", ...args], path);
|
|
1048
|
+
const inner = compile(args[0], "boolean", path.concat(1));
|
|
1049
|
+
return {
|
|
1050
|
+
evaluate: (ctx) => !inner.evaluate(ctx),
|
|
1051
|
+
returnType: "boolean",
|
|
1052
|
+
...mergeDeps3([inner])
|
|
1053
|
+
};
|
|
1054
|
+
});
|
|
1055
|
+
registerOperator("==", (args, compile, path) => {
|
|
1056
|
+
if (args.length !== 2)
|
|
1057
|
+
throw new ExpressionError(`"==" expects 2 arguments, got ${args.length}`, ["==", ...args], path);
|
|
1058
|
+
const a = compile(args[0], "value", path.concat(1));
|
|
1059
|
+
const b = compile(args[1], "value", path.concat(2));
|
|
1060
|
+
return {
|
|
1061
|
+
evaluate: (ctx) => strictEq(a.evaluate(ctx), b.evaluate(ctx)),
|
|
1062
|
+
returnType: "boolean",
|
|
1063
|
+
...mergeDeps3([a, b])
|
|
1064
|
+
};
|
|
1065
|
+
});
|
|
1066
|
+
registerOperator("!=", (args, compile, path) => {
|
|
1067
|
+
if (args.length !== 2)
|
|
1068
|
+
throw new ExpressionError(`"!=" expects 2 arguments, got ${args.length}`, ["!=", ...args], path);
|
|
1069
|
+
const a = compile(args[0], "value", path.concat(1));
|
|
1070
|
+
const b = compile(args[1], "value", path.concat(2));
|
|
1071
|
+
return {
|
|
1072
|
+
evaluate: (ctx) => !strictEq(a.evaluate(ctx), b.evaluate(ctx)),
|
|
1073
|
+
returnType: "boolean",
|
|
1074
|
+
...mergeDeps3([a, b])
|
|
1075
|
+
};
|
|
1076
|
+
});
|
|
1077
|
+
const comparator = (name) => {
|
|
1078
|
+
registerOperator(name, (args, compile, path) => {
|
|
1079
|
+
if (args.length !== 2)
|
|
1080
|
+
throw new ExpressionError(`"${name}" expects 2 arguments, got ${args.length}`, [name, ...args], path);
|
|
1081
|
+
const a = compile(args[0], "value", path.concat(1));
|
|
1082
|
+
const b = compile(args[1], "value", path.concat(2));
|
|
1083
|
+
return {
|
|
1084
|
+
evaluate: (ctx) => {
|
|
1085
|
+
const cmp = compare(a.evaluate(ctx), b.evaluate(ctx));
|
|
1086
|
+
if (Number.isNaN(cmp))
|
|
1087
|
+
return false;
|
|
1088
|
+
switch (name) {
|
|
1089
|
+
case "<":
|
|
1090
|
+
return cmp < 0;
|
|
1091
|
+
case "<=":
|
|
1092
|
+
return cmp <= 0;
|
|
1093
|
+
case ">":
|
|
1094
|
+
return cmp > 0;
|
|
1095
|
+
case ">=":
|
|
1096
|
+
return cmp >= 0;
|
|
1097
|
+
}
|
|
1098
|
+
},
|
|
1099
|
+
returnType: "boolean",
|
|
1100
|
+
...mergeDeps3([a, b])
|
|
1101
|
+
};
|
|
1102
|
+
});
|
|
1103
|
+
};
|
|
1104
|
+
comparator("<");
|
|
1105
|
+
comparator("<=");
|
|
1106
|
+
comparator(">");
|
|
1107
|
+
comparator(">=");
|
|
1108
|
+
registerOperator("all", (args, compile, path) => {
|
|
1109
|
+
const children = args.map((a, i) => compile(a, "boolean", path.concat(i + 1)));
|
|
1110
|
+
return {
|
|
1111
|
+
evaluate: (ctx) => {
|
|
1112
|
+
for (let i = 0;i < children.length; i++)
|
|
1113
|
+
if (!children[i].evaluate(ctx))
|
|
1114
|
+
return false;
|
|
1115
|
+
return true;
|
|
1116
|
+
},
|
|
1117
|
+
returnType: "boolean",
|
|
1118
|
+
...mergeDeps3(children)
|
|
1119
|
+
};
|
|
1120
|
+
});
|
|
1121
|
+
registerOperator("any", (args, compile, path) => {
|
|
1122
|
+
const children = args.map((a, i) => compile(a, "boolean", path.concat(i + 1)));
|
|
1123
|
+
return {
|
|
1124
|
+
evaluate: (ctx) => {
|
|
1125
|
+
for (let i = 0;i < children.length; i++)
|
|
1126
|
+
if (children[i].evaluate(ctx))
|
|
1127
|
+
return true;
|
|
1128
|
+
return false;
|
|
1129
|
+
},
|
|
1130
|
+
returnType: "boolean",
|
|
1131
|
+
...mergeDeps3(children)
|
|
1132
|
+
};
|
|
1133
|
+
});
|
|
1134
|
+
registerOperator("none", (args, compile, path) => {
|
|
1135
|
+
const children = args.map((a, i) => compile(a, "boolean", path.concat(i + 1)));
|
|
1136
|
+
return {
|
|
1137
|
+
evaluate: (ctx) => {
|
|
1138
|
+
for (let i = 0;i < children.length; i++)
|
|
1139
|
+
if (children[i].evaluate(ctx))
|
|
1140
|
+
return false;
|
|
1141
|
+
return true;
|
|
1142
|
+
},
|
|
1143
|
+
returnType: "boolean",
|
|
1144
|
+
...mergeDeps3(children)
|
|
1145
|
+
};
|
|
1146
|
+
});
|
|
1147
|
+
registerOperator("case", (args, compile, path, expected) => {
|
|
1148
|
+
if (args.length < 3 || args.length % 2 !== 1)
|
|
1149
|
+
throw new ExpressionError(`"case" expects an odd number of arguments >= 3 (cond, val, ..., fallback), got ${args.length}`, ["case", ...args], path);
|
|
1150
|
+
const branches = [];
|
|
1151
|
+
for (let i = 0;i < args.length - 1; i += 2) {
|
|
1152
|
+
branches.push({
|
|
1153
|
+
cond: compile(args[i], "boolean", path.concat(i + 1)),
|
|
1154
|
+
val: compile(args[i + 1], expected, path.concat(i + 2))
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
const fallback = compile(args[args.length - 1], expected, path.concat(args.length));
|
|
1158
|
+
const all = [fallback];
|
|
1159
|
+
for (const b of branches) {
|
|
1160
|
+
all.push(b.cond);
|
|
1161
|
+
all.push(b.val);
|
|
1162
|
+
}
|
|
1163
|
+
return {
|
|
1164
|
+
evaluate: (ctx) => {
|
|
1165
|
+
for (let i = 0;i < branches.length; i++) {
|
|
1166
|
+
const br = branches[i];
|
|
1167
|
+
if (br.cond.evaluate(ctx))
|
|
1168
|
+
return br.val.evaluate(ctx);
|
|
1169
|
+
}
|
|
1170
|
+
return fallback.evaluate(ctx);
|
|
1171
|
+
},
|
|
1172
|
+
returnType: expected,
|
|
1173
|
+
...mergeDeps3(all)
|
|
1174
|
+
};
|
|
1175
|
+
});
|
|
1176
|
+
registerOperator("match", (args, compile, path, expected) => {
|
|
1177
|
+
if (args.length < 4 || args.length % 2 !== 0)
|
|
1178
|
+
throw new ExpressionError(`"match" expects input, (label, value)+, fallback — got ${args.length} arguments`, ["match", ...args], path);
|
|
1179
|
+
const input = compile(args[0], "value", path.concat(1));
|
|
1180
|
+
const branches = [];
|
|
1181
|
+
for (let i = 1;i < args.length - 1; i += 2) {
|
|
1182
|
+
const label = args[i];
|
|
1183
|
+
const labels = Array.isArray(label) ? label : [label];
|
|
1184
|
+
for (const l of labels) {
|
|
1185
|
+
if (typeof l !== "string" && typeof l !== "number" && typeof l !== "boolean")
|
|
1186
|
+
throw new ExpressionError('"match" labels must be strings, numbers, or booleans', ["match", ...args], path.concat(i + 1));
|
|
1187
|
+
}
|
|
1188
|
+
branches.push({
|
|
1189
|
+
labels,
|
|
1190
|
+
val: compile(args[i + 1], expected, path.concat(i + 2))
|
|
1191
|
+
});
|
|
1192
|
+
}
|
|
1193
|
+
const fallback = compile(args[args.length - 1], expected, path.concat(args.length));
|
|
1194
|
+
const all = [input, fallback];
|
|
1195
|
+
for (const b of branches)
|
|
1196
|
+
all.push(b.val);
|
|
1197
|
+
return {
|
|
1198
|
+
evaluate: (ctx) => {
|
|
1199
|
+
const x = input.evaluate(ctx);
|
|
1200
|
+
for (let i = 0;i < branches.length; i++) {
|
|
1201
|
+
const br = branches[i];
|
|
1202
|
+
for (let j = 0;j < br.labels.length; j++) {
|
|
1203
|
+
if (strictEq(x, br.labels[j]))
|
|
1204
|
+
return br.val.evaluate(ctx);
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
return fallback.evaluate(ctx);
|
|
1208
|
+
},
|
|
1209
|
+
returnType: expected,
|
|
1210
|
+
...mergeDeps3(all)
|
|
1211
|
+
};
|
|
1212
|
+
});
|
|
1213
|
+
registerOperator("coalesce", (args, compile, path, expected) => {
|
|
1214
|
+
if (args.length === 0)
|
|
1215
|
+
throw new ExpressionError('"coalesce" expects at least 1 argument', ["coalesce"], path);
|
|
1216
|
+
const children = args.map((a, i) => compile(a, expected, path.concat(i + 1)));
|
|
1217
|
+
return {
|
|
1218
|
+
evaluate: (ctx) => {
|
|
1219
|
+
for (let i = 0;i < children.length; i++) {
|
|
1220
|
+
const v = children[i].evaluate(ctx);
|
|
1221
|
+
if (v !== null && v !== undefined)
|
|
1222
|
+
return v;
|
|
1223
|
+
}
|
|
1224
|
+
return null;
|
|
1225
|
+
},
|
|
1226
|
+
returnType: expected,
|
|
1227
|
+
...mergeDeps3(children)
|
|
1228
|
+
};
|
|
1229
|
+
});
|
|
1230
|
+
registerOperator("in", (args, compile, path) => {
|
|
1231
|
+
if (args.length < 1)
|
|
1232
|
+
throw new ExpressionError('"in" expects at least 1 argument', ["in", ...args], path);
|
|
1233
|
+
const input = compile(args[0], "value", path.concat(1));
|
|
1234
|
+
const haystack = args.slice(1);
|
|
1235
|
+
return {
|
|
1236
|
+
evaluate: (ctx) => {
|
|
1237
|
+
const x = input.evaluate(ctx);
|
|
1238
|
+
for (let i = 0;i < haystack.length; i++)
|
|
1239
|
+
if (strictEq(x, haystack[i]))
|
|
1240
|
+
return true;
|
|
1241
|
+
return false;
|
|
1242
|
+
},
|
|
1243
|
+
returnType: "boolean",
|
|
1244
|
+
...mergeDeps3([input])
|
|
1245
|
+
};
|
|
1246
|
+
});
|
|
1247
|
+
registerOperator("!in", (args, compile, path) => {
|
|
1248
|
+
if (args.length < 1)
|
|
1249
|
+
throw new ExpressionError('"!in" expects at least 1 argument', ["!in", ...args], path);
|
|
1250
|
+
const input = compile(args[0], "value", path.concat(1));
|
|
1251
|
+
const haystack = args.slice(1);
|
|
1252
|
+
return {
|
|
1253
|
+
evaluate: (ctx) => {
|
|
1254
|
+
const x = input.evaluate(ctx);
|
|
1255
|
+
for (let i = 0;i < haystack.length; i++)
|
|
1256
|
+
if (strictEq(x, haystack[i]))
|
|
1257
|
+
return false;
|
|
1258
|
+
return true;
|
|
1259
|
+
},
|
|
1260
|
+
returnType: "boolean",
|
|
1261
|
+
...mergeDeps3([input])
|
|
1262
|
+
};
|
|
1263
|
+
});
|
|
1264
|
+
registerOperator("!has", (args, _compile, path) => {
|
|
1265
|
+
if (args.length < 1 || args.length > 2)
|
|
1266
|
+
throw new ExpressionError(`"!has" expects 1 or 2 arguments, got ${args.length}`, ["!has", ...args], path);
|
|
1267
|
+
if (typeof args[0] !== "string")
|
|
1268
|
+
throw new ExpressionError('"!has" key must be a string literal', ["!has", ...args], path);
|
|
1269
|
+
const key = args[0];
|
|
1270
|
+
return {
|
|
1271
|
+
evaluate: (ctx) => {
|
|
1272
|
+
const props = ctx.feature ? ctx.feature.properties : undefined;
|
|
1273
|
+
return props ? !Object.prototype.hasOwnProperty.call(props, key) : true;
|
|
1274
|
+
},
|
|
1275
|
+
returnType: "boolean",
|
|
1276
|
+
dependsOnZoom: false,
|
|
1277
|
+
dependsOnFeature: true,
|
|
1278
|
+
dependsOnFeatureState: false
|
|
1279
|
+
};
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
var init_logical = __esm(() => {
|
|
1283
|
+
init_errors();
|
|
1284
|
+
init_registry();
|
|
1285
|
+
});
|
|
1286
|
+
|
|
1287
|
+
// src/core-map/style-spec/expressions/operators/lookup.ts
|
|
1288
|
+
function registerLookupOps() {
|
|
1289
|
+
registerOperator("literal", (args, _compile, path) => {
|
|
1290
|
+
if (args.length !== 1)
|
|
1291
|
+
throw new ExpressionError(`"literal" expects 1 argument, got ${args.length}`, ["literal", ...args], path);
|
|
1292
|
+
const value = args[0];
|
|
1293
|
+
return {
|
|
1294
|
+
evaluate: () => value,
|
|
1295
|
+
returnType: inferLiteralType(value),
|
|
1296
|
+
dependsOnZoom: false,
|
|
1297
|
+
dependsOnFeature: false,
|
|
1298
|
+
dependsOnFeatureState: false
|
|
1299
|
+
};
|
|
1300
|
+
});
|
|
1301
|
+
registerOperator("get", (args, compile, path) => {
|
|
1302
|
+
if (args.length < 1 || args.length > 2)
|
|
1303
|
+
throw new ExpressionError(`"get" expects 1 or 2 arguments, got ${args.length}`, ["get", ...args], path);
|
|
1304
|
+
if (typeof args[0] !== "string")
|
|
1305
|
+
throw new ExpressionError('"get" key must be a string literal', ["get", ...args], path);
|
|
1306
|
+
const key = args[0];
|
|
1307
|
+
if (args.length === 2) {
|
|
1308
|
+
const obj = compile(args[1], "value", path.concat(2));
|
|
1309
|
+
return {
|
|
1310
|
+
evaluate: (ctx) => {
|
|
1311
|
+
const o = obj.evaluate(ctx);
|
|
1312
|
+
if (o && typeof o === "object")
|
|
1313
|
+
return o[key];
|
|
1314
|
+
return;
|
|
1315
|
+
},
|
|
1316
|
+
returnType: "value",
|
|
1317
|
+
dependsOnZoom: obj.dependsOnZoom,
|
|
1318
|
+
dependsOnFeature: obj.dependsOnFeature,
|
|
1319
|
+
dependsOnFeatureState: obj.dependsOnFeatureState
|
|
1320
|
+
};
|
|
1321
|
+
}
|
|
1322
|
+
return {
|
|
1323
|
+
evaluate: (ctx) => {
|
|
1324
|
+
const props = ctx.feature ? ctx.feature.properties : undefined;
|
|
1325
|
+
return props ? props[key] : undefined;
|
|
1326
|
+
},
|
|
1327
|
+
returnType: "value",
|
|
1328
|
+
dependsOnZoom: false,
|
|
1329
|
+
dependsOnFeature: true,
|
|
1330
|
+
dependsOnFeatureState: false
|
|
1331
|
+
};
|
|
1332
|
+
});
|
|
1333
|
+
registerOperator("has", (args, compile, path) => {
|
|
1334
|
+
if (args.length < 1 || args.length > 2)
|
|
1335
|
+
throw new ExpressionError(`"has" expects 1 or 2 arguments, got ${args.length}`, ["has", ...args], path);
|
|
1336
|
+
if (typeof args[0] !== "string")
|
|
1337
|
+
throw new ExpressionError('"has" key must be a string literal', ["has", ...args], path);
|
|
1338
|
+
const key = args[0];
|
|
1339
|
+
if (args.length === 2) {
|
|
1340
|
+
const obj = compile(args[1], "value", path.concat(2));
|
|
1341
|
+
return {
|
|
1342
|
+
evaluate: (ctx) => {
|
|
1343
|
+
const o = obj.evaluate(ctx);
|
|
1344
|
+
if (o && typeof o === "object")
|
|
1345
|
+
return Object.prototype.hasOwnProperty.call(o, key);
|
|
1346
|
+
return false;
|
|
1347
|
+
},
|
|
1348
|
+
returnType: "boolean",
|
|
1349
|
+
dependsOnZoom: obj.dependsOnZoom,
|
|
1350
|
+
dependsOnFeature: obj.dependsOnFeature,
|
|
1351
|
+
dependsOnFeatureState: obj.dependsOnFeatureState
|
|
1352
|
+
};
|
|
1353
|
+
}
|
|
1354
|
+
return {
|
|
1355
|
+
evaluate: (ctx) => {
|
|
1356
|
+
const props = ctx.feature ? ctx.feature.properties : undefined;
|
|
1357
|
+
return props ? Object.prototype.hasOwnProperty.call(props, key) : false;
|
|
1358
|
+
},
|
|
1359
|
+
returnType: "boolean",
|
|
1360
|
+
dependsOnZoom: false,
|
|
1361
|
+
dependsOnFeature: true,
|
|
1362
|
+
dependsOnFeatureState: false
|
|
1363
|
+
};
|
|
1364
|
+
});
|
|
1365
|
+
registerOperator("at", (args, compile, path) => {
|
|
1366
|
+
if (args.length !== 2)
|
|
1367
|
+
throw new ExpressionError(`"at" expects 2 arguments, got ${args.length}`, ["at", ...args], path);
|
|
1368
|
+
const idx = compile(args[0], "number", path.concat(1));
|
|
1369
|
+
const arr = compile(args[1], "array", path.concat(2));
|
|
1370
|
+
return {
|
|
1371
|
+
evaluate: (ctx) => {
|
|
1372
|
+
const a = arr.evaluate(ctx);
|
|
1373
|
+
const i = idx.evaluate(ctx);
|
|
1374
|
+
if (!Array.isArray(a) || typeof i !== "number")
|
|
1375
|
+
return;
|
|
1376
|
+
if (i < 0 || i >= a.length || !Number.isFinite(i))
|
|
1377
|
+
return;
|
|
1378
|
+
return a[Math.floor(i)];
|
|
1379
|
+
},
|
|
1380
|
+
returnType: "value",
|
|
1381
|
+
dependsOnZoom: idx.dependsOnZoom || arr.dependsOnZoom,
|
|
1382
|
+
dependsOnFeature: idx.dependsOnFeature || arr.dependsOnFeature,
|
|
1383
|
+
dependsOnFeatureState: idx.dependsOnFeatureState || arr.dependsOnFeatureState
|
|
1384
|
+
};
|
|
1385
|
+
});
|
|
1386
|
+
registerOperator("length", (args, compile, path) => {
|
|
1387
|
+
if (args.length !== 1)
|
|
1388
|
+
throw new ExpressionError(`"length" expects 1 argument, got ${args.length}`, ["length", ...args], path);
|
|
1389
|
+
const inner = compile(args[0], "value", path.concat(1));
|
|
1390
|
+
return {
|
|
1391
|
+
evaluate: (ctx) => {
|
|
1392
|
+
const v = inner.evaluate(ctx);
|
|
1393
|
+
if (typeof v === "string" || Array.isArray(v))
|
|
1394
|
+
return v.length;
|
|
1395
|
+
return 0;
|
|
1396
|
+
},
|
|
1397
|
+
returnType: "number",
|
|
1398
|
+
dependsOnZoom: inner.dependsOnZoom,
|
|
1399
|
+
dependsOnFeature: inner.dependsOnFeature,
|
|
1400
|
+
dependsOnFeatureState: inner.dependsOnFeatureState
|
|
1401
|
+
};
|
|
1402
|
+
});
|
|
1403
|
+
registerOperator("properties", (args, _compile, path) => {
|
|
1404
|
+
if (args.length !== 0)
|
|
1405
|
+
throw new ExpressionError(`"properties" takes no arguments, got ${args.length}`, ["properties", ...args], path);
|
|
1406
|
+
return {
|
|
1407
|
+
evaluate: (ctx) => ctx.feature ? ctx.feature.properties : {},
|
|
1408
|
+
returnType: "value",
|
|
1409
|
+
dependsOnZoom: false,
|
|
1410
|
+
dependsOnFeature: true,
|
|
1411
|
+
dependsOnFeatureState: false
|
|
1412
|
+
};
|
|
1413
|
+
});
|
|
1414
|
+
registerOperator("geometry-type", (args, _compile, path) => {
|
|
1415
|
+
if (args.length !== 0)
|
|
1416
|
+
throw new ExpressionError(`"geometry-type" takes no arguments, got ${args.length}`, ["geometry-type", ...args], path);
|
|
1417
|
+
return {
|
|
1418
|
+
evaluate: (ctx) => {
|
|
1419
|
+
if (!ctx.feature)
|
|
1420
|
+
return "Unknown";
|
|
1421
|
+
switch (ctx.feature.type) {
|
|
1422
|
+
case 1:
|
|
1423
|
+
return "Point";
|
|
1424
|
+
case 2:
|
|
1425
|
+
return "LineString";
|
|
1426
|
+
case 3:
|
|
1427
|
+
return "Polygon";
|
|
1428
|
+
default:
|
|
1429
|
+
return "Unknown";
|
|
1430
|
+
}
|
|
1431
|
+
},
|
|
1432
|
+
returnType: "string",
|
|
1433
|
+
dependsOnZoom: false,
|
|
1434
|
+
dependsOnFeature: true,
|
|
1435
|
+
dependsOnFeatureState: false
|
|
1436
|
+
};
|
|
1437
|
+
});
|
|
1438
|
+
registerOperator("id", (args, _compile, path) => {
|
|
1439
|
+
if (args.length !== 0)
|
|
1440
|
+
throw new ExpressionError(`"id" takes no arguments, got ${args.length}`, ["id", ...args], path);
|
|
1441
|
+
return {
|
|
1442
|
+
evaluate: (ctx) => ctx.feature ? ctx.feature.id : undefined,
|
|
1443
|
+
returnType: "value",
|
|
1444
|
+
dependsOnZoom: false,
|
|
1445
|
+
dependsOnFeature: true,
|
|
1446
|
+
dependsOnFeatureState: false
|
|
1447
|
+
};
|
|
1448
|
+
});
|
|
1449
|
+
registerOperator("zoom", (args, _compile, path) => {
|
|
1450
|
+
if (args.length !== 0)
|
|
1451
|
+
throw new ExpressionError(`"zoom" takes no arguments, got ${args.length}`, ["zoom", ...args], path);
|
|
1452
|
+
return {
|
|
1453
|
+
evaluate: (ctx) => ctx.zoom,
|
|
1454
|
+
returnType: "number",
|
|
1455
|
+
dependsOnZoom: true,
|
|
1456
|
+
dependsOnFeature: false,
|
|
1457
|
+
dependsOnFeatureState: false
|
|
1458
|
+
};
|
|
1459
|
+
});
|
|
1460
|
+
registerOperator("line-progress", (args, _compile, path) => {
|
|
1461
|
+
if (args.length !== 0)
|
|
1462
|
+
throw new ExpressionError(`"line-progress" takes no arguments, got ${args.length}`, ["line-progress", ...args], path);
|
|
1463
|
+
return {
|
|
1464
|
+
evaluate: (ctx) => ctx.lineProgress ?? 0,
|
|
1465
|
+
returnType: "number",
|
|
1466
|
+
dependsOnZoom: false,
|
|
1467
|
+
dependsOnFeature: false,
|
|
1468
|
+
dependsOnFeatureState: false
|
|
1469
|
+
};
|
|
1470
|
+
});
|
|
1471
|
+
registerOperator("feature-state", (args, _compile, path) => {
|
|
1472
|
+
if (args.length !== 1)
|
|
1473
|
+
throw new ExpressionError(`"feature-state" expects 1 argument, got ${args.length}`, ["feature-state", ...args], path);
|
|
1474
|
+
if (typeof args[0] !== "string")
|
|
1475
|
+
throw new ExpressionError('"feature-state" key must be a string literal', ["feature-state", ...args], path);
|
|
1476
|
+
const key = args[0];
|
|
1477
|
+
return {
|
|
1478
|
+
evaluate: (ctx) => {
|
|
1479
|
+
const state = ctx.featureState;
|
|
1480
|
+
return state ? state[key] : undefined;
|
|
1481
|
+
},
|
|
1482
|
+
returnType: "value",
|
|
1483
|
+
dependsOnZoom: false,
|
|
1484
|
+
dependsOnFeature: false,
|
|
1485
|
+
dependsOnFeatureState: true
|
|
1486
|
+
};
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
1489
|
+
function inferLiteralType(value) {
|
|
1490
|
+
if (value === null)
|
|
1491
|
+
return "null";
|
|
1492
|
+
if (typeof value === "string")
|
|
1493
|
+
return "string";
|
|
1494
|
+
if (typeof value === "number")
|
|
1495
|
+
return "number";
|
|
1496
|
+
if (typeof value === "boolean")
|
|
1497
|
+
return "boolean";
|
|
1498
|
+
if (Array.isArray(value))
|
|
1499
|
+
return "array";
|
|
1500
|
+
return "value";
|
|
1501
|
+
}
|
|
1502
|
+
var init_lookup = __esm(() => {
|
|
1503
|
+
init_errors();
|
|
1504
|
+
init_registry();
|
|
1505
|
+
});
|
|
1506
|
+
|
|
1507
|
+
// src/core-map/style-spec/expressions/operators/math.ts
|
|
1508
|
+
function expectNumber(value, op, expr) {
|
|
1509
|
+
if (typeof value !== "number" || Number.isNaN(value))
|
|
1510
|
+
throw new ExpressionError(`"${op}": expected number, got ${String(value)}`, expr);
|
|
1511
|
+
return value;
|
|
1512
|
+
}
|
|
1513
|
+
function mergeDeps4(children) {
|
|
1514
|
+
let z = false;
|
|
1515
|
+
let f = false;
|
|
1516
|
+
let s = false;
|
|
1517
|
+
for (const c of children) {
|
|
1518
|
+
if (c.dependsOnZoom)
|
|
1519
|
+
z = true;
|
|
1520
|
+
if (c.dependsOnFeature)
|
|
1521
|
+
f = true;
|
|
1522
|
+
if (c.dependsOnFeatureState)
|
|
1523
|
+
s = true;
|
|
1524
|
+
}
|
|
1525
|
+
return { dependsOnZoom: z, dependsOnFeature: f, dependsOnFeatureState: s };
|
|
1526
|
+
}
|
|
1527
|
+
function registerMathOps() {
|
|
1528
|
+
registerOperator("+", (args, compile, path) => {
|
|
1529
|
+
const children = args.map((a, i) => compile(a, "number", path.concat(i + 1)));
|
|
1530
|
+
const expr = ["+", ...args];
|
|
1531
|
+
return {
|
|
1532
|
+
evaluate: (ctx) => {
|
|
1533
|
+
let acc = 0;
|
|
1534
|
+
for (let i = 0;i < children.length; i++)
|
|
1535
|
+
acc += expectNumber(children[i].evaluate(ctx), "+", expr);
|
|
1536
|
+
return acc;
|
|
1537
|
+
},
|
|
1538
|
+
returnType: "number",
|
|
1539
|
+
...mergeDeps4(children)
|
|
1540
|
+
};
|
|
1541
|
+
});
|
|
1542
|
+
registerOperator("*", (args, compile, path) => {
|
|
1543
|
+
const children = args.map((a, i) => compile(a, "number", path.concat(i + 1)));
|
|
1544
|
+
const expr = ["*", ...args];
|
|
1545
|
+
return {
|
|
1546
|
+
evaluate: (ctx) => {
|
|
1547
|
+
let acc = 1;
|
|
1548
|
+
for (let i = 0;i < children.length; i++)
|
|
1549
|
+
acc *= expectNumber(children[i].evaluate(ctx), "*", expr);
|
|
1550
|
+
return acc;
|
|
1551
|
+
},
|
|
1552
|
+
returnType: "number",
|
|
1553
|
+
...mergeDeps4(children)
|
|
1554
|
+
};
|
|
1555
|
+
});
|
|
1556
|
+
registerOperator("-", (args, compile, path) => {
|
|
1557
|
+
if (args.length !== 1 && args.length !== 2)
|
|
1558
|
+
throw new ExpressionError(`"-" expects 1 or 2 arguments, got ${args.length}`, ["-", ...args], path);
|
|
1559
|
+
const children = args.map((a2, i) => compile(a2, "number", path.concat(i + 1)));
|
|
1560
|
+
const expr = ["-", ...args];
|
|
1561
|
+
if (children.length === 1) {
|
|
1562
|
+
const a2 = children[0];
|
|
1563
|
+
return {
|
|
1564
|
+
evaluate: (ctx) => -expectNumber(a2.evaluate(ctx), "-", expr),
|
|
1565
|
+
returnType: "number",
|
|
1566
|
+
...mergeDeps4(children)
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
const a = children[0];
|
|
1570
|
+
const b = children[1];
|
|
1571
|
+
return {
|
|
1572
|
+
evaluate: (ctx) => expectNumber(a.evaluate(ctx), "-", expr) - expectNumber(b.evaluate(ctx), "-", expr),
|
|
1573
|
+
returnType: "number",
|
|
1574
|
+
...mergeDeps4(children)
|
|
1575
|
+
};
|
|
1576
|
+
});
|
|
1577
|
+
registerOperator("/", (args, compile, path) => {
|
|
1578
|
+
if (args.length !== 2)
|
|
1579
|
+
throw new ExpressionError(`"/" expects 2 arguments, got ${args.length}`, ["/", ...args], path);
|
|
1580
|
+
const a = compile(args[0], "number", path.concat(1));
|
|
1581
|
+
const b = compile(args[1], "number", path.concat(2));
|
|
1582
|
+
const expr = ["/", ...args];
|
|
1583
|
+
return {
|
|
1584
|
+
evaluate: (ctx) => {
|
|
1585
|
+
const av = expectNumber(a.evaluate(ctx), "/", expr);
|
|
1586
|
+
const bv = expectNumber(b.evaluate(ctx), "/", expr);
|
|
1587
|
+
if (bv === 0)
|
|
1588
|
+
throw new ExpressionError('"/": divide by zero', expr);
|
|
1589
|
+
return av / bv;
|
|
1590
|
+
},
|
|
1591
|
+
returnType: "number",
|
|
1592
|
+
...mergeDeps4([a, b])
|
|
1593
|
+
};
|
|
1594
|
+
});
|
|
1595
|
+
registerOperator("%", (args, compile, path) => {
|
|
1596
|
+
if (args.length !== 2)
|
|
1597
|
+
throw new ExpressionError(`"%" expects 2 arguments, got ${args.length}`, ["%", ...args], path);
|
|
1598
|
+
const a = compile(args[0], "number", path.concat(1));
|
|
1599
|
+
const b = compile(args[1], "number", path.concat(2));
|
|
1600
|
+
const expr = ["%", ...args];
|
|
1601
|
+
return {
|
|
1602
|
+
evaluate: (ctx) => {
|
|
1603
|
+
const av = expectNumber(a.evaluate(ctx), "%", expr);
|
|
1604
|
+
const bv = expectNumber(b.evaluate(ctx), "%", expr);
|
|
1605
|
+
if (bv === 0)
|
|
1606
|
+
throw new ExpressionError('"%": divide by zero', expr);
|
|
1607
|
+
return av % bv;
|
|
1608
|
+
},
|
|
1609
|
+
returnType: "number",
|
|
1610
|
+
...mergeDeps4([a, b])
|
|
1611
|
+
};
|
|
1612
|
+
});
|
|
1613
|
+
registerOperator("^", (args, compile, path) => {
|
|
1614
|
+
if (args.length !== 2)
|
|
1615
|
+
throw new ExpressionError(`"^" expects 2 arguments, got ${args.length}`, ["^", ...args], path);
|
|
1616
|
+
const a = compile(args[0], "number", path.concat(1));
|
|
1617
|
+
const b = compile(args[1], "number", path.concat(2));
|
|
1618
|
+
const expr = ["^", ...args];
|
|
1619
|
+
return {
|
|
1620
|
+
evaluate: (ctx) => expectNumber(a.evaluate(ctx), "^", expr) ** expectNumber(b.evaluate(ctx), "^", expr),
|
|
1621
|
+
returnType: "number",
|
|
1622
|
+
...mergeDeps4([a, b])
|
|
1623
|
+
};
|
|
1624
|
+
});
|
|
1625
|
+
registerOperator("min", (args, compile, path) => {
|
|
1626
|
+
if (args.length < 1)
|
|
1627
|
+
throw new ExpressionError('"min" expects at least 1 argument', ["min"], path);
|
|
1628
|
+
const children = args.map((a, i) => compile(a, "number", path.concat(i + 1)));
|
|
1629
|
+
const expr = ["min", ...args];
|
|
1630
|
+
return {
|
|
1631
|
+
evaluate: (ctx) => {
|
|
1632
|
+
let m = Infinity;
|
|
1633
|
+
for (let i = 0;i < children.length; i++) {
|
|
1634
|
+
const v = expectNumber(children[i].evaluate(ctx), "min", expr);
|
|
1635
|
+
if (v < m)
|
|
1636
|
+
m = v;
|
|
1637
|
+
}
|
|
1638
|
+
return m;
|
|
1639
|
+
},
|
|
1640
|
+
returnType: "number",
|
|
1641
|
+
...mergeDeps4(children)
|
|
1642
|
+
};
|
|
1643
|
+
});
|
|
1644
|
+
registerOperator("max", (args, compile, path) => {
|
|
1645
|
+
if (args.length < 1)
|
|
1646
|
+
throw new ExpressionError('"max" expects at least 1 argument', ["max"], path);
|
|
1647
|
+
const children = args.map((a, i) => compile(a, "number", path.concat(i + 1)));
|
|
1648
|
+
const expr = ["max", ...args];
|
|
1649
|
+
return {
|
|
1650
|
+
evaluate: (ctx) => {
|
|
1651
|
+
let m = -Infinity;
|
|
1652
|
+
for (let i = 0;i < children.length; i++) {
|
|
1653
|
+
const v = expectNumber(children[i].evaluate(ctx), "max", expr);
|
|
1654
|
+
if (v > m)
|
|
1655
|
+
m = v;
|
|
1656
|
+
}
|
|
1657
|
+
return m;
|
|
1658
|
+
},
|
|
1659
|
+
returnType: "number",
|
|
1660
|
+
...mergeDeps4(children)
|
|
1661
|
+
};
|
|
1662
|
+
});
|
|
1663
|
+
const unary = (name, fn, validate) => {
|
|
1664
|
+
registerOperator(name, (args, compile, path) => {
|
|
1665
|
+
if (args.length !== 1)
|
|
1666
|
+
throw new ExpressionError(`"${name}" expects 1 argument, got ${args.length}`, [name, ...args], path);
|
|
1667
|
+
const inner = compile(args[0], "number", path.concat(1));
|
|
1668
|
+
const expr = [name, ...args];
|
|
1669
|
+
return {
|
|
1670
|
+
evaluate: (ctx) => {
|
|
1671
|
+
const v = expectNumber(inner.evaluate(ctx), name, expr);
|
|
1672
|
+
if (validate)
|
|
1673
|
+
validate(v, expr);
|
|
1674
|
+
return fn(v);
|
|
1675
|
+
},
|
|
1676
|
+
returnType: "number",
|
|
1677
|
+
...mergeDeps4([inner])
|
|
1678
|
+
};
|
|
1679
|
+
});
|
|
1680
|
+
};
|
|
1681
|
+
unary("abs", Math.abs);
|
|
1682
|
+
unary("floor", Math.floor);
|
|
1683
|
+
unary("ceil", Math.ceil);
|
|
1684
|
+
unary("round", Math.round);
|
|
1685
|
+
unary("sqrt", Math.sqrt, (n, expr) => {
|
|
1686
|
+
if (n < 0)
|
|
1687
|
+
throw new ExpressionError('"sqrt": input must be non-negative', expr);
|
|
1688
|
+
});
|
|
1689
|
+
unary("ln", Math.log, (n, expr) => {
|
|
1690
|
+
if (n <= 0)
|
|
1691
|
+
throw new ExpressionError('"ln": input must be positive', expr);
|
|
1692
|
+
});
|
|
1693
|
+
unary("log10", Math.log10, (n, expr) => {
|
|
1694
|
+
if (n <= 0)
|
|
1695
|
+
throw new ExpressionError('"log10": input must be positive', expr);
|
|
1696
|
+
});
|
|
1697
|
+
unary("log2", Math.log2, (n, expr) => {
|
|
1698
|
+
if (n <= 0)
|
|
1699
|
+
throw new ExpressionError('"log2": input must be positive', expr);
|
|
1700
|
+
});
|
|
1701
|
+
registerOperator("e", (args, _compile, path) => {
|
|
1702
|
+
if (args.length !== 0)
|
|
1703
|
+
throw new ExpressionError(`"e" takes no arguments, got ${args.length}`, ["e", ...args], path);
|
|
1704
|
+
return {
|
|
1705
|
+
evaluate: () => Math.E,
|
|
1706
|
+
returnType: "number",
|
|
1707
|
+
dependsOnZoom: false,
|
|
1708
|
+
dependsOnFeature: false,
|
|
1709
|
+
dependsOnFeatureState: false
|
|
1710
|
+
};
|
|
1711
|
+
});
|
|
1712
|
+
registerOperator("pi", (args, _compile, path) => {
|
|
1713
|
+
if (args.length !== 0)
|
|
1714
|
+
throw new ExpressionError(`"pi" takes no arguments, got ${args.length}`, ["pi", ...args], path);
|
|
1715
|
+
return {
|
|
1716
|
+
evaluate: () => Math.PI,
|
|
1717
|
+
returnType: "number",
|
|
1718
|
+
dependsOnZoom: false,
|
|
1719
|
+
dependsOnFeature: false,
|
|
1720
|
+
dependsOnFeatureState: false
|
|
1721
|
+
};
|
|
1722
|
+
});
|
|
1723
|
+
registerOperator("rand", (args, compile, path) => {
|
|
1724
|
+
if (args.length < 2 || args.length > 3)
|
|
1725
|
+
throw new ExpressionError(`"rand" expects 2 or 3 arguments, got ${args.length}`, ["rand", ...args], path);
|
|
1726
|
+
const min = compile(args[0], "number", path.concat(1));
|
|
1727
|
+
const max = compile(args[1], "number", path.concat(2));
|
|
1728
|
+
const seed = args.length === 3 ? compile(args[2], "number", path.concat(3)) : null;
|
|
1729
|
+
const expr = ["rand", ...args];
|
|
1730
|
+
let state = 1;
|
|
1731
|
+
const nextSeeded = () => {
|
|
1732
|
+
state = state * 1664525 + 1013904223 >>> 0;
|
|
1733
|
+
return state / 4294967296;
|
|
1734
|
+
};
|
|
1735
|
+
const children = seed ? [min, max, seed] : [min, max];
|
|
1736
|
+
return {
|
|
1737
|
+
evaluate: (ctx) => {
|
|
1738
|
+
const a = expectNumber(min.evaluate(ctx), "rand", expr);
|
|
1739
|
+
const b = expectNumber(max.evaluate(ctx), "rand", expr);
|
|
1740
|
+
if (seed) {
|
|
1741
|
+
const s = expectNumber(seed.evaluate(ctx), "rand", expr);
|
|
1742
|
+
state = Math.floor(s) >>> 0 || 1;
|
|
1743
|
+
nextSeeded();
|
|
1744
|
+
return a + (b - a) * nextSeeded();
|
|
1745
|
+
}
|
|
1746
|
+
return a + (b - a) * Math.random();
|
|
1747
|
+
},
|
|
1748
|
+
returnType: "number",
|
|
1749
|
+
...mergeDeps4(children)
|
|
1750
|
+
};
|
|
1751
|
+
});
|
|
1752
|
+
}
|
|
1753
|
+
var init_math = __esm(() => {
|
|
1754
|
+
init_errors();
|
|
1755
|
+
init_registry();
|
|
1756
|
+
});
|
|
1757
|
+
|
|
1758
|
+
// src/core-map/style-spec/expressions/operators/string.ts
|
|
1759
|
+
function mergeDeps5(children) {
|
|
1760
|
+
let z = false;
|
|
1761
|
+
let f = false;
|
|
1762
|
+
let s = false;
|
|
1763
|
+
for (const c of children) {
|
|
1764
|
+
if (c.dependsOnZoom)
|
|
1765
|
+
z = true;
|
|
1766
|
+
if (c.dependsOnFeature)
|
|
1767
|
+
f = true;
|
|
1768
|
+
if (c.dependsOnFeatureState)
|
|
1769
|
+
s = true;
|
|
1770
|
+
}
|
|
1771
|
+
return { dependsOnZoom: z, dependsOnFeature: f, dependsOnFeatureState: s };
|
|
1772
|
+
}
|
|
1773
|
+
function toStr(v) {
|
|
1774
|
+
if (v === null || v === undefined)
|
|
1775
|
+
return "";
|
|
1776
|
+
if (typeof v === "string")
|
|
1777
|
+
return v;
|
|
1778
|
+
if (typeof v === "number" || typeof v === "boolean")
|
|
1779
|
+
return String(v);
|
|
1780
|
+
try {
|
|
1781
|
+
return JSON.stringify(v);
|
|
1782
|
+
} catch {
|
|
1783
|
+
return String(v);
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
function registerStringOps() {
|
|
1787
|
+
registerOperator("concat", (args, compile, path) => {
|
|
1788
|
+
const children = args.map((a, i) => compile(a, "value", path.concat(i + 1)));
|
|
1789
|
+
return {
|
|
1790
|
+
evaluate: (ctx) => {
|
|
1791
|
+
let out = "";
|
|
1792
|
+
for (let i = 0;i < children.length; i++)
|
|
1793
|
+
out += toStr(children[i].evaluate(ctx));
|
|
1794
|
+
return out;
|
|
1795
|
+
},
|
|
1796
|
+
returnType: "string",
|
|
1797
|
+
...mergeDeps5(children)
|
|
1798
|
+
};
|
|
1799
|
+
});
|
|
1800
|
+
registerOperator("downcase", (args, compile, path) => {
|
|
1801
|
+
if (args.length !== 1)
|
|
1802
|
+
throw new ExpressionError(`"downcase" expects 1 argument, got ${args.length}`, ["downcase", ...args], path);
|
|
1803
|
+
const inner = compile(args[0], "string", path.concat(1));
|
|
1804
|
+
return {
|
|
1805
|
+
evaluate: (ctx) => toStr(inner.evaluate(ctx)).toLowerCase(),
|
|
1806
|
+
returnType: "string",
|
|
1807
|
+
...mergeDeps5([inner])
|
|
1808
|
+
};
|
|
1809
|
+
});
|
|
1810
|
+
registerOperator("upcase", (args, compile, path) => {
|
|
1811
|
+
if (args.length !== 1)
|
|
1812
|
+
throw new ExpressionError(`"upcase" expects 1 argument, got ${args.length}`, ["upcase", ...args], path);
|
|
1813
|
+
const inner = compile(args[0], "string", path.concat(1));
|
|
1814
|
+
return {
|
|
1815
|
+
evaluate: (ctx) => toStr(inner.evaluate(ctx)).toUpperCase(),
|
|
1816
|
+
returnType: "string",
|
|
1817
|
+
...mergeDeps5([inner])
|
|
1818
|
+
};
|
|
1819
|
+
});
|
|
1820
|
+
registerOperator("resolved-locale", (args, _compile, path) => {
|
|
1821
|
+
if (args.length !== 0 && args.length !== 1)
|
|
1822
|
+
throw new ExpressionError(`"resolved-locale" expects 0 or 1 arguments, got ${args.length}`, ["resolved-locale", ...args], path);
|
|
1823
|
+
return {
|
|
1824
|
+
evaluate: () => "en",
|
|
1825
|
+
returnType: "string",
|
|
1826
|
+
dependsOnZoom: false,
|
|
1827
|
+
dependsOnFeature: false,
|
|
1828
|
+
dependsOnFeatureState: false
|
|
1829
|
+
};
|
|
1830
|
+
});
|
|
1831
|
+
}
|
|
1832
|
+
var init_string = __esm(() => {
|
|
1833
|
+
init_errors();
|
|
1834
|
+
init_registry();
|
|
1835
|
+
});
|
|
1836
|
+
|
|
1837
|
+
// src/core-map/style-spec/expressions/compile.ts
|
|
1838
|
+
function boot() {
|
|
1839
|
+
if (BOOTED)
|
|
1840
|
+
return;
|
|
1841
|
+
BOOTED = true;
|
|
1842
|
+
registerLookupOps();
|
|
1843
|
+
registerLogicalOps();
|
|
1844
|
+
registerMathOps();
|
|
1845
|
+
registerConversionOps();
|
|
1846
|
+
registerStringOps();
|
|
1847
|
+
registerInterpolateOps();
|
|
1848
|
+
}
|
|
1849
|
+
function compileLiteral(value, expected, path) {
|
|
1850
|
+
if (expected === "color") {
|
|
1851
|
+
if (typeof value !== "string")
|
|
1852
|
+
throw new ExpressionError(`expected color string, got ${typeof value}`, value, path);
|
|
1853
|
+
const rgba = parseColor(value);
|
|
1854
|
+
if (!rgba)
|
|
1855
|
+
throw new ExpressionError(`invalid color string ${JSON.stringify(value)}`, value, path);
|
|
1856
|
+
return {
|
|
1857
|
+
evaluate: () => value,
|
|
1858
|
+
returnType: "color",
|
|
1859
|
+
dependsOnZoom: false,
|
|
1860
|
+
dependsOnFeature: false,
|
|
1861
|
+
dependsOnFeatureState: false
|
|
1862
|
+
};
|
|
1863
|
+
}
|
|
1864
|
+
if (expected === "number") {
|
|
1865
|
+
if (typeof value !== "number" || Number.isNaN(value))
|
|
1866
|
+
throw new ExpressionError(`expected number, got ${String(value)}`, value, path);
|
|
1867
|
+
} else if (expected === "boolean") {
|
|
1868
|
+
if (typeof value !== "boolean")
|
|
1869
|
+
throw new ExpressionError(`expected boolean, got ${typeof value}`, value, path);
|
|
1870
|
+
} else if (expected === "string" || expected === "formatted" || expected === "resolvedImage") {
|
|
1871
|
+
if (typeof value !== "string")
|
|
1872
|
+
throw new ExpressionError(`expected string, got ${typeof value}`, value, path);
|
|
1873
|
+
}
|
|
1874
|
+
const returnType = value === null ? "null" : typeof value === "string" ? "string" : typeof value === "number" ? "number" : typeof value === "boolean" ? "boolean" : Array.isArray(value) ? "array" : "value";
|
|
1875
|
+
return {
|
|
1876
|
+
evaluate: () => value,
|
|
1877
|
+
returnType,
|
|
1878
|
+
dependsOnZoom: false,
|
|
1879
|
+
dependsOnFeature: false,
|
|
1880
|
+
dependsOnFeatureState: false
|
|
1881
|
+
};
|
|
1882
|
+
}
|
|
1883
|
+
function compile(expr, expectedType = "value", path = []) {
|
|
1884
|
+
boot();
|
|
1885
|
+
if (Array.isArray(expr)) {
|
|
1886
|
+
const head = expr[0];
|
|
1887
|
+
if (typeof head === "string") {
|
|
1888
|
+
const op = getOperator(head);
|
|
1889
|
+
if (op) {
|
|
1890
|
+
const args = expr.slice(1);
|
|
1891
|
+
return op(args, compile, path, expectedType);
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
return compileLiteral(expr, "array", path);
|
|
1895
|
+
}
|
|
1896
|
+
return compileLiteral(expr, expectedType, path);
|
|
1897
|
+
}
|
|
1898
|
+
var BOOTED = false;
|
|
1899
|
+
var init_compile = __esm(() => {
|
|
1900
|
+
init_Color();
|
|
1901
|
+
init_errors();
|
|
1902
|
+
init_conversion();
|
|
1903
|
+
init_interpolate();
|
|
1904
|
+
init_logical();
|
|
1905
|
+
init_lookup();
|
|
1906
|
+
init_math();
|
|
1907
|
+
init_string();
|
|
1908
|
+
init_registry();
|
|
1909
|
+
});
|
|
1910
|
+
|
|
1911
|
+
// src/core-map/style-spec/expressions/validate.ts
|
|
1912
|
+
function isExpression(value) {
|
|
1913
|
+
boot();
|
|
1914
|
+
if (!Array.isArray(value) || value.length === 0)
|
|
1915
|
+
return false;
|
|
1916
|
+
const head = value[0];
|
|
1917
|
+
return typeof head === "string" && hasOperator(head);
|
|
1918
|
+
}
|
|
1919
|
+
function validateExpression(value, expectedType) {
|
|
1920
|
+
const errors = [];
|
|
1921
|
+
try {
|
|
1922
|
+
compile(value, expectedType, []);
|
|
1923
|
+
} catch (err) {
|
|
1924
|
+
if (err instanceof ExpressionError)
|
|
1925
|
+
errors.push(err.message);
|
|
1926
|
+
else if (err instanceof Error)
|
|
1927
|
+
errors.push(err.message);
|
|
1928
|
+
else
|
|
1929
|
+
errors.push(String(err));
|
|
1930
|
+
}
|
|
1931
|
+
return errors;
|
|
1932
|
+
}
|
|
1933
|
+
var init_validate = __esm(() => {
|
|
1934
|
+
init_compile();
|
|
1935
|
+
init_errors();
|
|
1936
|
+
init_registry();
|
|
1937
|
+
});
|
|
1938
|
+
|
|
1939
|
+
// src/core-map/style-spec/expressions/legacyFilter.ts
|
|
1940
|
+
function isLegacyShape(filter) {
|
|
1941
|
+
if (filter.length === 0)
|
|
1942
|
+
return false;
|
|
1943
|
+
const head = filter[0];
|
|
1944
|
+
if (typeof head !== "string")
|
|
1945
|
+
return false;
|
|
1946
|
+
if (head === "has" || head === "!has" || head === "in" || head === "!in")
|
|
1947
|
+
return typeof filter[1] === "string";
|
|
1948
|
+
if (COMPARATORS.has(head))
|
|
1949
|
+
return typeof filter[1] === "string";
|
|
1950
|
+
if (COMBINATORS.has(head)) {
|
|
1951
|
+
for (let i = 1;i < filter.length; i++) {
|
|
1952
|
+
const child = filter[i];
|
|
1953
|
+
if (Array.isArray(child) && isLegacyShape(child))
|
|
1954
|
+
return true;
|
|
1955
|
+
}
|
|
1956
|
+
return false;
|
|
1957
|
+
}
|
|
1958
|
+
return false;
|
|
1959
|
+
}
|
|
1960
|
+
function convertSpecial(prop) {
|
|
1961
|
+
if (prop === "$type")
|
|
1962
|
+
return ["geometry-type"];
|
|
1963
|
+
if (prop === "$id")
|
|
1964
|
+
return ["id"];
|
|
1965
|
+
return ["get", prop];
|
|
1966
|
+
}
|
|
1967
|
+
function convertInner(filter) {
|
|
1968
|
+
const head = filter[0];
|
|
1969
|
+
if (typeof head !== "string")
|
|
1970
|
+
return filter;
|
|
1971
|
+
if (head === "has") {
|
|
1972
|
+
if (typeof filter[1] !== "string")
|
|
1973
|
+
return filter;
|
|
1974
|
+
return ["has", filter[1]];
|
|
1975
|
+
}
|
|
1976
|
+
if (head === "!has") {
|
|
1977
|
+
if (typeof filter[1] !== "string")
|
|
1978
|
+
return filter;
|
|
1979
|
+
return ["!has", filter[1]];
|
|
1980
|
+
}
|
|
1981
|
+
if (head === "in" || head === "!in") {
|
|
1982
|
+
if (typeof filter[1] !== "string")
|
|
1983
|
+
return filter;
|
|
1984
|
+
return [head, convertSpecial(filter[1]), ...filter.slice(2)];
|
|
1985
|
+
}
|
|
1986
|
+
if (COMPARATORS.has(head)) {
|
|
1987
|
+
if (typeof filter[1] !== "string")
|
|
1988
|
+
return filter;
|
|
1989
|
+
return [head, convertSpecial(filter[1]), filter[2]];
|
|
1990
|
+
}
|
|
1991
|
+
if (COMBINATORS.has(head)) {
|
|
1992
|
+
const converted = [head];
|
|
1993
|
+
for (let i = 1;i < filter.length; i++) {
|
|
1994
|
+
const child = filter[i];
|
|
1995
|
+
if (Array.isArray(child) && isLegacyShape(child))
|
|
1996
|
+
converted.push(convertInner(child));
|
|
1997
|
+
else
|
|
1998
|
+
converted.push(child);
|
|
1999
|
+
}
|
|
2000
|
+
return converted;
|
|
2001
|
+
}
|
|
2002
|
+
return filter;
|
|
2003
|
+
}
|
|
2004
|
+
function convertLegacyFilter(filter) {
|
|
2005
|
+
if (!Array.isArray(filter))
|
|
2006
|
+
return filter;
|
|
2007
|
+
if (!isLegacyShape(filter))
|
|
2008
|
+
return filter;
|
|
2009
|
+
return convertInner(filter);
|
|
2010
|
+
}
|
|
2011
|
+
var COMPARATORS, COMBINATORS;
|
|
2012
|
+
var init_legacyFilter = __esm(() => {
|
|
2013
|
+
COMPARATORS = new Set(["==", "!=", "<", "<=", ">", ">="]);
|
|
2014
|
+
COMBINATORS = new Set(["all", "any", "none"]);
|
|
2015
|
+
});
|
|
2016
|
+
|
|
2017
|
+
// src/core-map/style-spec/expressions/index.ts
|
|
2018
|
+
function evaluate(expr, ctx, expectedType = "value") {
|
|
2019
|
+
if (!isExpression(expr)) {
|
|
2020
|
+
if (Array.isArray(expr))
|
|
2021
|
+
return expr;
|
|
2022
|
+
return expr;
|
|
2023
|
+
}
|
|
2024
|
+
const compiled = compile(expr, expectedType, []);
|
|
2025
|
+
try {
|
|
2026
|
+
return compiled.evaluate(ctx);
|
|
2027
|
+
} catch (err) {
|
|
2028
|
+
if (err instanceof ExpressionError)
|
|
2029
|
+
throw err;
|
|
2030
|
+
if (err instanceof Error)
|
|
2031
|
+
throw new ExpressionError(err.message, expr);
|
|
2032
|
+
throw new ExpressionError(String(err), expr);
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
var init_expressions = __esm(() => {
|
|
2036
|
+
init_compile();
|
|
2037
|
+
init_errors();
|
|
2038
|
+
init_validate();
|
|
2039
|
+
init_Color();
|
|
2040
|
+
init_compile();
|
|
2041
|
+
init_errors();
|
|
2042
|
+
init_legacyFilter();
|
|
2043
|
+
init_validate();
|
|
2044
|
+
});
|
|
2045
|
+
|
|
2046
|
+
// src/core-map/style-spec/schema.ts
|
|
2047
|
+
var backgroundPaint, fillPaint, fillExtrusionPaint, linePaint, circlePaint, symbolPaint, rasterPaint, paintPropertySchemas, visibility, backgroundLayout, fillLayout, fillExtrusionLayout, lineLayout, circleLayout, symbolLayout, rasterLayout, layoutPropertySchemas, layerTypes, sourceTypes;
|
|
2048
|
+
var init_schema = __esm(() => {
|
|
2049
|
+
backgroundPaint = {
|
|
2050
|
+
"background-color": { type: "color", default: "#000000", transition: true, sdk: "gl" },
|
|
2051
|
+
"background-opacity": { type: "number", default: 1, minimum: 0, maximum: 1, transition: true, sdk: "gl" },
|
|
2052
|
+
"background-pattern": { type: "resolvedImage", transition: true, sdk: "gl" }
|
|
2053
|
+
};
|
|
2054
|
+
fillPaint = {
|
|
2055
|
+
"fill-antialias": { type: "boolean", default: true, sdk: "gl" },
|
|
2056
|
+
"fill-color": { type: "color", default: "#000000", transition: true, sdk: "gl" },
|
|
2057
|
+
"fill-opacity": { type: "number", default: 1, minimum: 0, maximum: 1, transition: true, sdk: "gl" },
|
|
2058
|
+
"fill-outline-color": { type: "color", transition: true, sdk: "gl" },
|
|
2059
|
+
"fill-pattern": { type: "resolvedImage", transition: true, sdk: "gl" },
|
|
2060
|
+
"fill-translate": { type: "array", length: 2, default: [0, 0], transition: true, sdk: "gl" },
|
|
2061
|
+
"fill-translate-anchor": { type: "enum", values: ["map", "viewport"], default: "map", sdk: "gl" }
|
|
2062
|
+
};
|
|
2063
|
+
fillExtrusionPaint = {
|
|
2064
|
+
"fill-extrusion-opacity": { type: "number", default: 1, minimum: 0, maximum: 1, transition: true, sdk: "gl" },
|
|
2065
|
+
"fill-extrusion-color": { type: "color", default: "#000000", transition: true, sdk: "gl" },
|
|
2066
|
+
"fill-extrusion-translate": { type: "array", length: 2, default: [0, 0], transition: true, sdk: "gl" },
|
|
2067
|
+
"fill-extrusion-translate-anchor": { type: "enum", values: ["map", "viewport"], default: "map", sdk: "gl" },
|
|
2068
|
+
"fill-extrusion-pattern": { type: "resolvedImage", transition: true, sdk: "gl" },
|
|
2069
|
+
"fill-extrusion-height": { type: "number", default: 0, minimum: 0, transition: true, sdk: "gl" },
|
|
2070
|
+
"fill-extrusion-base": { type: "number", default: 0, minimum: 0, transition: true, sdk: "gl" },
|
|
2071
|
+
"fill-extrusion-vertical-gradient": { type: "boolean", default: true, sdk: "gl" }
|
|
2072
|
+
};
|
|
2073
|
+
linePaint = {
|
|
2074
|
+
"line-opacity": { type: "number", default: 1, minimum: 0, maximum: 1, transition: true, sdk: "gl" },
|
|
2075
|
+
"line-color": { type: "color", default: "#000000", transition: true, sdk: "gl" },
|
|
2076
|
+
"line-translate": { type: "array", length: 2, default: [0, 0], transition: true, sdk: "gl" },
|
|
2077
|
+
"line-translate-anchor": { type: "enum", values: ["map", "viewport"], default: "map", sdk: "gl" },
|
|
2078
|
+
"line-width": { type: "number", default: 1, minimum: 0, transition: true, sdk: "gl" },
|
|
2079
|
+
"line-gap-width": { type: "number", default: 0, minimum: 0, transition: true, sdk: "gl" },
|
|
2080
|
+
"line-offset": { type: "number", default: 0, transition: true, sdk: "gl" },
|
|
2081
|
+
"line-blur": { type: "number", default: 0, minimum: 0, transition: true, sdk: "gl" },
|
|
2082
|
+
"line-dasharray": { type: "array", transition: true, sdk: "gl" },
|
|
2083
|
+
"line-pattern": { type: "resolvedImage", transition: true, sdk: "gl" },
|
|
2084
|
+
"line-gradient": { type: "color", sdk: "gl" }
|
|
2085
|
+
};
|
|
2086
|
+
circlePaint = {
|
|
2087
|
+
"circle-radius": { type: "number", default: 5, minimum: 0, transition: true, sdk: "gl" },
|
|
2088
|
+
"circle-color": { type: "color", default: "#000000", transition: true, sdk: "gl" },
|
|
2089
|
+
"circle-blur": { type: "number", default: 0, transition: true, sdk: "gl" },
|
|
2090
|
+
"circle-opacity": { type: "number", default: 1, minimum: 0, maximum: 1, transition: true, sdk: "gl" },
|
|
2091
|
+
"circle-translate": { type: "array", length: 2, default: [0, 0], transition: true, sdk: "gl" },
|
|
2092
|
+
"circle-translate-anchor": { type: "enum", values: ["map", "viewport"], default: "map", sdk: "gl" },
|
|
2093
|
+
"circle-pitch-scale": { type: "enum", values: ["map", "viewport"], default: "map", sdk: "gl" },
|
|
2094
|
+
"circle-pitch-alignment": { type: "enum", values: ["map", "viewport"], default: "viewport", sdk: "gl" },
|
|
2095
|
+
"circle-stroke-width": { type: "number", default: 0, minimum: 0, transition: true, sdk: "gl" },
|
|
2096
|
+
"circle-stroke-color": { type: "color", default: "#000000", transition: true, sdk: "gl" },
|
|
2097
|
+
"circle-stroke-opacity": { type: "number", default: 1, minimum: 0, maximum: 1, transition: true, sdk: "gl" }
|
|
2098
|
+
};
|
|
2099
|
+
symbolPaint = {
|
|
2100
|
+
"icon-opacity": { type: "number", default: 1, minimum: 0, maximum: 1, transition: true, sdk: "gl" },
|
|
2101
|
+
"icon-color": { type: "color", default: "#000000", transition: true, sdk: "gl" },
|
|
2102
|
+
"icon-halo-color": { type: "color", default: "rgba(0, 0, 0, 0)", transition: true, sdk: "gl" },
|
|
2103
|
+
"icon-halo-width": { type: "number", default: 0, minimum: 0, transition: true, sdk: "gl" },
|
|
2104
|
+
"icon-halo-blur": { type: "number", default: 0, minimum: 0, transition: true, sdk: "gl" },
|
|
2105
|
+
"icon-translate": { type: "array", length: 2, default: [0, 0], transition: true, sdk: "gl" },
|
|
2106
|
+
"icon-translate-anchor": { type: "enum", values: ["map", "viewport"], default: "map", sdk: "gl" },
|
|
2107
|
+
"text-opacity": { type: "number", default: 1, minimum: 0, maximum: 1, transition: true, sdk: "gl" },
|
|
2108
|
+
"text-color": { type: "color", default: "#000000", transition: true, sdk: "gl" },
|
|
2109
|
+
"text-halo-color": { type: "color", default: "rgba(0, 0, 0, 0)", transition: true, sdk: "gl" },
|
|
2110
|
+
"text-halo-width": { type: "number", default: 0, minimum: 0, transition: true, sdk: "gl" },
|
|
2111
|
+
"text-halo-blur": { type: "number", default: 0, minimum: 0, transition: true, sdk: "gl" },
|
|
2112
|
+
"text-translate": { type: "array", length: 2, default: [0, 0], transition: true, sdk: "gl" },
|
|
2113
|
+
"text-translate-anchor": { type: "enum", values: ["map", "viewport"], default: "map", sdk: "gl" }
|
|
2114
|
+
};
|
|
2115
|
+
rasterPaint = {
|
|
2116
|
+
"raster-opacity": { type: "number", default: 1, minimum: 0, maximum: 1, transition: true, sdk: "gl" },
|
|
2117
|
+
"raster-hue-rotate": { type: "number", default: 0, transition: true, sdk: "gl" },
|
|
2118
|
+
"raster-brightness-min": { type: "number", default: 0, minimum: 0, maximum: 1, transition: true, sdk: "gl" },
|
|
2119
|
+
"raster-brightness-max": { type: "number", default: 1, minimum: 0, maximum: 1, transition: true, sdk: "gl" },
|
|
2120
|
+
"raster-saturation": { type: "number", default: 0, minimum: -1, maximum: 1, transition: true, sdk: "gl" },
|
|
2121
|
+
"raster-contrast": { type: "number", default: 0, minimum: -1, maximum: 1, transition: true, sdk: "gl" },
|
|
2122
|
+
"raster-resampling": { type: "enum", values: ["linear", "nearest"], default: "linear", sdk: "gl" },
|
|
2123
|
+
"raster-fade-duration": { type: "number", default: 300, minimum: 0, sdk: "gl" }
|
|
2124
|
+
};
|
|
2125
|
+
paintPropertySchemas = {
|
|
2126
|
+
background: backgroundPaint,
|
|
2127
|
+
fill: fillPaint,
|
|
2128
|
+
"fill-extrusion": fillExtrusionPaint,
|
|
2129
|
+
line: linePaint,
|
|
2130
|
+
circle: circlePaint,
|
|
2131
|
+
symbol: symbolPaint,
|
|
2132
|
+
raster: rasterPaint
|
|
2133
|
+
};
|
|
2134
|
+
visibility = { type: "enum", values: ["visible", "none"], default: "visible", sdk: "gl" };
|
|
2135
|
+
backgroundLayout = {
|
|
2136
|
+
visibility
|
|
2137
|
+
};
|
|
2138
|
+
fillLayout = {
|
|
2139
|
+
visibility,
|
|
2140
|
+
"fill-sort-key": { type: "number", sdk: "gl" }
|
|
2141
|
+
};
|
|
2142
|
+
fillExtrusionLayout = {
|
|
2143
|
+
visibility
|
|
2144
|
+
};
|
|
2145
|
+
lineLayout = {
|
|
2146
|
+
visibility,
|
|
2147
|
+
"line-cap": { type: "enum", values: ["butt", "round", "square"], default: "butt", sdk: "gl" },
|
|
2148
|
+
"line-join": { type: "enum", values: ["bevel", "round", "miter"], default: "miter", sdk: "gl" },
|
|
2149
|
+
"line-miter-limit": { type: "number", default: 2, sdk: "gl" },
|
|
2150
|
+
"line-round-limit": { type: "number", default: 1.05, sdk: "gl" },
|
|
2151
|
+
"line-sort-key": { type: "number", sdk: "gl" }
|
|
2152
|
+
};
|
|
2153
|
+
circleLayout = {
|
|
2154
|
+
visibility,
|
|
2155
|
+
"circle-sort-key": { type: "number", sdk: "gl" }
|
|
2156
|
+
};
|
|
2157
|
+
symbolLayout = {
|
|
2158
|
+
visibility,
|
|
2159
|
+
"symbol-placement": { type: "enum", values: ["point", "line", "line-center"], default: "point", sdk: "gl" },
|
|
2160
|
+
"symbol-spacing": { type: "number", default: 250, minimum: 1, sdk: "gl" },
|
|
2161
|
+
"symbol-avoid-edges": { type: "boolean", default: false, sdk: "gl" },
|
|
2162
|
+
"symbol-sort-key": { type: "number", sdk: "gl" },
|
|
2163
|
+
"symbol-z-order": { type: "enum", values: ["auto", "viewport-y", "source"], default: "auto", sdk: "gl" },
|
|
2164
|
+
"icon-allow-overlap": { type: "boolean", default: false, sdk: "gl" },
|
|
2165
|
+
"icon-ignore-placement": { type: "boolean", default: false, sdk: "gl" },
|
|
2166
|
+
"icon-optional": { type: "boolean", default: false, sdk: "gl" },
|
|
2167
|
+
"icon-rotation-alignment": { type: "enum", values: ["map", "viewport", "auto"], default: "auto", sdk: "gl" },
|
|
2168
|
+
"icon-size": { type: "number", default: 1, minimum: 0, sdk: "gl" },
|
|
2169
|
+
"icon-text-fit": { type: "enum", values: ["none", "width", "height", "both"], default: "none", sdk: "gl" },
|
|
2170
|
+
"icon-text-fit-padding": { type: "array", length: 4, default: [0, 0, 0, 0], sdk: "gl" },
|
|
2171
|
+
"icon-image": { type: "resolvedImage", sdk: "gl" },
|
|
2172
|
+
"icon-rotate": { type: "number", default: 0, sdk: "gl" },
|
|
2173
|
+
"icon-padding": { type: "padding", default: 2, sdk: "gl" },
|
|
2174
|
+
"icon-keep-upright": { type: "boolean", default: false, sdk: "gl" },
|
|
2175
|
+
"icon-offset": { type: "array", length: 2, default: [0, 0], sdk: "gl" },
|
|
2176
|
+
"icon-anchor": {
|
|
2177
|
+
type: "enum",
|
|
2178
|
+
values: ["center", "left", "right", "top", "bottom", "top-left", "top-right", "bottom-left", "bottom-right"],
|
|
2179
|
+
default: "center",
|
|
2180
|
+
sdk: "gl"
|
|
2181
|
+
},
|
|
2182
|
+
"icon-pitch-alignment": { type: "enum", values: ["map", "viewport", "auto"], default: "auto", sdk: "gl" },
|
|
2183
|
+
"text-pitch-alignment": { type: "enum", values: ["map", "viewport", "auto"], default: "auto", sdk: "gl" },
|
|
2184
|
+
"text-rotation-alignment": { type: "enum", values: ["map", "viewport", "auto"], default: "auto", sdk: "gl" },
|
|
2185
|
+
"text-field": { type: "formatted", default: "", sdk: "gl" },
|
|
2186
|
+
"text-font": { type: "array", default: ["Open Sans Regular", "Arial Unicode MS Regular"], sdk: "gl" },
|
|
2187
|
+
"text-size": { type: "number", default: 16, minimum: 0, sdk: "gl" },
|
|
2188
|
+
"text-max-width": { type: "number", default: 10, minimum: 0, sdk: "gl" },
|
|
2189
|
+
"text-line-height": { type: "number", default: 1.2, sdk: "gl" },
|
|
2190
|
+
"text-letter-spacing": { type: "number", default: 0, sdk: "gl" },
|
|
2191
|
+
"text-justify": { type: "enum", values: ["auto", "left", "center", "right"], default: "center", sdk: "gl" },
|
|
2192
|
+
"text-radial-offset": { type: "number", default: 0, sdk: "gl" },
|
|
2193
|
+
"text-variable-anchor": { type: "array", sdk: "gl" },
|
|
2194
|
+
"text-anchor": {
|
|
2195
|
+
type: "enum",
|
|
2196
|
+
values: ["center", "left", "right", "top", "bottom", "top-left", "top-right", "bottom-left", "bottom-right"],
|
|
2197
|
+
default: "center",
|
|
2198
|
+
sdk: "gl"
|
|
2199
|
+
},
|
|
2200
|
+
"text-max-angle": { type: "number", default: 45, sdk: "gl" },
|
|
2201
|
+
"text-writing-mode": { type: "array", sdk: "gl" },
|
|
2202
|
+
"text-rotate": { type: "number", default: 0, sdk: "gl" },
|
|
2203
|
+
"text-padding": { type: "number", default: 2, minimum: 0, sdk: "gl" },
|
|
2204
|
+
"text-keep-upright": { type: "boolean", default: true, sdk: "gl" },
|
|
2205
|
+
"text-transform": { type: "enum", values: ["none", "uppercase", "lowercase"], default: "none", sdk: "gl" },
|
|
2206
|
+
"text-offset": { type: "array", length: 2, default: [0, 0], sdk: "gl" },
|
|
2207
|
+
"text-allow-overlap": { type: "boolean", default: false, sdk: "gl" },
|
|
2208
|
+
"text-ignore-placement": { type: "boolean", default: false, sdk: "gl" },
|
|
2209
|
+
"text-optional": { type: "boolean", default: false, sdk: "gl" }
|
|
2210
|
+
};
|
|
2211
|
+
rasterLayout = {
|
|
2212
|
+
visibility
|
|
2213
|
+
};
|
|
2214
|
+
layoutPropertySchemas = {
|
|
2215
|
+
background: backgroundLayout,
|
|
2216
|
+
fill: fillLayout,
|
|
2217
|
+
"fill-extrusion": fillExtrusionLayout,
|
|
2218
|
+
line: lineLayout,
|
|
2219
|
+
circle: circleLayout,
|
|
2220
|
+
symbol: symbolLayout,
|
|
2221
|
+
raster: rasterLayout
|
|
2222
|
+
};
|
|
2223
|
+
layerTypes = ["background", "fill", "fill-extrusion", "line", "circle", "symbol", "raster"];
|
|
2224
|
+
sourceTypes = ["vector", "raster", "raster-dem", "geojson"];
|
|
2225
|
+
});
|
|
2226
|
+
|
|
2227
|
+
// src/core-map/style-spec/validate.ts
|
|
2228
|
+
function pushError(errors, message, path) {
|
|
2229
|
+
errors.push({ message, path: path.slice() });
|
|
2230
|
+
}
|
|
2231
|
+
function isPlainObject(value) {
|
|
2232
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2233
|
+
}
|
|
2234
|
+
function expressionTypeFor(t) {
|
|
2235
|
+
switch (t) {
|
|
2236
|
+
case "color":
|
|
2237
|
+
return "color";
|
|
2238
|
+
case "number":
|
|
2239
|
+
return "number";
|
|
2240
|
+
case "string":
|
|
2241
|
+
return "string";
|
|
2242
|
+
case "boolean":
|
|
2243
|
+
return "boolean";
|
|
2244
|
+
case "array":
|
|
2245
|
+
return "array";
|
|
2246
|
+
case "enum":
|
|
2247
|
+
return "string";
|
|
2248
|
+
case "padding":
|
|
2249
|
+
return "value";
|
|
2250
|
+
case "formatted":
|
|
2251
|
+
return "formatted";
|
|
2252
|
+
case "resolvedImage":
|
|
2253
|
+
return "resolvedImage";
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
function matchesSchema(value, schema) {
|
|
2257
|
+
if (Array.isArray(value)) {
|
|
2258
|
+
if (isExpression(value)) {
|
|
2259
|
+
const errs = validateExpression(value, expressionTypeFor(schema.type));
|
|
2260
|
+
return errs.length === 0 ? true : errs;
|
|
2261
|
+
}
|
|
2262
|
+
if (schema.type === "array") {
|
|
2263
|
+
if (schema.length !== undefined && value.length !== schema.length)
|
|
2264
|
+
return false;
|
|
2265
|
+
return true;
|
|
2266
|
+
}
|
|
2267
|
+
if (schema.type === "padding") {
|
|
2268
|
+
return value.length === 2 || value.length === 4;
|
|
2269
|
+
}
|
|
2270
|
+
return false;
|
|
2271
|
+
}
|
|
2272
|
+
switch (schema.type) {
|
|
2273
|
+
case "color":
|
|
2274
|
+
return typeof value === "string";
|
|
2275
|
+
case "number":
|
|
2276
|
+
if (typeof value !== "number" || Number.isNaN(value))
|
|
2277
|
+
return false;
|
|
2278
|
+
if (schema.minimum !== undefined && value < schema.minimum)
|
|
2279
|
+
return false;
|
|
2280
|
+
if (schema.maximum !== undefined && value > schema.maximum)
|
|
2281
|
+
return false;
|
|
2282
|
+
return true;
|
|
2283
|
+
case "string":
|
|
2284
|
+
return typeof value === "string";
|
|
2285
|
+
case "boolean":
|
|
2286
|
+
return typeof value === "boolean";
|
|
2287
|
+
case "enum":
|
|
2288
|
+
return typeof value === "string" && (schema.values ? schema.values.includes(value) : true);
|
|
2289
|
+
case "padding":
|
|
2290
|
+
return typeof value === "number";
|
|
2291
|
+
case "formatted":
|
|
2292
|
+
return typeof value === "string";
|
|
2293
|
+
case "resolvedImage":
|
|
2294
|
+
return typeof value === "string";
|
|
2295
|
+
case "array":
|
|
2296
|
+
return false;
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
function validateProperty(schemas, layerType, kind, name, value, path) {
|
|
2300
|
+
const errors = [];
|
|
2301
|
+
const schema = schemas ? schemas[name] : undefined;
|
|
2302
|
+
if (!schema) {
|
|
2303
|
+
pushError(errors, `Unknown ${kind} property "${name}" for layer type "${layerType}"`, path);
|
|
2304
|
+
return errors;
|
|
2305
|
+
}
|
|
2306
|
+
const result = matchesSchema(value, schema);
|
|
2307
|
+
if (result === true)
|
|
2308
|
+
return errors;
|
|
2309
|
+
if (result === false) {
|
|
2310
|
+
pushError(errors, `Invalid value for ${kind} property "${name}" (expected ${describeSchema(schema)})`, path);
|
|
2311
|
+
return errors;
|
|
2312
|
+
}
|
|
2313
|
+
for (const message of result)
|
|
2314
|
+
pushError(errors, `Invalid expression for ${kind} property "${name}": ${message}`, path);
|
|
2315
|
+
return errors;
|
|
2316
|
+
}
|
|
2317
|
+
function describeSchema(schema) {
|
|
2318
|
+
if (schema.type === "enum" && schema.values)
|
|
2319
|
+
return `one of ${schema.values.map((v) => `"${v}"`).join(", ")}`;
|
|
2320
|
+
if (schema.type === "array" && schema.length !== undefined)
|
|
2321
|
+
return `array of length ${schema.length}`;
|
|
2322
|
+
return schema.type;
|
|
2323
|
+
}
|
|
2324
|
+
function validatePaintProperty(layerType, name, value) {
|
|
2325
|
+
const schemas = paintPropertySchemas[layerType];
|
|
2326
|
+
return validateProperty(schemas, layerType, "paint", name, value, ["paint", name]);
|
|
2327
|
+
}
|
|
2328
|
+
function validateLayoutProperty(layerType, name, value) {
|
|
2329
|
+
const schemas = layoutPropertySchemas[layerType];
|
|
2330
|
+
return validateProperty(schemas, layerType, "layout", name, value, ["layout", name]);
|
|
2331
|
+
}
|
|
2332
|
+
function validateSource(source, id) {
|
|
2333
|
+
const errors = [];
|
|
2334
|
+
const path = id !== undefined ? ["sources", id] : ["source"];
|
|
2335
|
+
if (!isPlainObject(source)) {
|
|
2336
|
+
pushError(errors, "Source must be an object", path);
|
|
2337
|
+
return errors;
|
|
2338
|
+
}
|
|
2339
|
+
const type = source.type;
|
|
2340
|
+
if (typeof type !== "string") {
|
|
2341
|
+
pushError(errors, 'Source is missing required "type" property', path.concat("type"));
|
|
2342
|
+
return errors;
|
|
2343
|
+
}
|
|
2344
|
+
if (!sourceTypes.includes(type)) {
|
|
2345
|
+
pushError(errors, `Unknown source type "${type}"`, path.concat("type"));
|
|
2346
|
+
return errors;
|
|
2347
|
+
}
|
|
2348
|
+
if (type === "vector" || type === "raster" || type === "raster-dem") {
|
|
2349
|
+
const hasUrl = typeof source.url === "string";
|
|
2350
|
+
const hasTiles = Array.isArray(source.tiles) && source.tiles.length > 0;
|
|
2351
|
+
if (!hasUrl && !hasTiles) {
|
|
2352
|
+
pushError(errors, `Source of type "${type}" must define either "url" or a non-empty "tiles" array`, path);
|
|
2353
|
+
}
|
|
2354
|
+
if (source.tiles !== undefined && !Array.isArray(source.tiles))
|
|
2355
|
+
pushError(errors, '"tiles" must be an array of URL templates', path.concat("tiles"));
|
|
2356
|
+
if (source.url !== undefined && typeof source.url !== "string")
|
|
2357
|
+
pushError(errors, '"url" must be a string', path.concat("url"));
|
|
2358
|
+
if (source.minzoom !== undefined && typeof source.minzoom !== "number")
|
|
2359
|
+
pushError(errors, '"minzoom" must be a number', path.concat("minzoom"));
|
|
2360
|
+
if (source.maxzoom !== undefined && typeof source.maxzoom !== "number")
|
|
2361
|
+
pushError(errors, '"maxzoom" must be a number', path.concat("maxzoom"));
|
|
2362
|
+
}
|
|
2363
|
+
if (type === "geojson") {
|
|
2364
|
+
if (source.data === undefined)
|
|
2365
|
+
pushError(errors, 'GeoJSON source is missing required "data" property', path.concat("data"));
|
|
2366
|
+
}
|
|
2367
|
+
return errors;
|
|
2368
|
+
}
|
|
2369
|
+
function validateLayer(layer, sources) {
|
|
2370
|
+
const errors = [];
|
|
2371
|
+
const path = ["layer"];
|
|
2372
|
+
if (!isPlainObject(layer)) {
|
|
2373
|
+
pushError(errors, "Layer must be an object", path);
|
|
2374
|
+
return errors;
|
|
2375
|
+
}
|
|
2376
|
+
if (typeof layer.id !== "string" || layer.id.length === 0)
|
|
2377
|
+
pushError(errors, 'Layer is missing required "id" property', path.concat("id"));
|
|
2378
|
+
const type = layer.type;
|
|
2379
|
+
if (typeof type !== "string") {
|
|
2380
|
+
pushError(errors, 'Layer is missing required "type" property', path.concat("type"));
|
|
2381
|
+
return errors;
|
|
2382
|
+
}
|
|
2383
|
+
if (!layerTypes.includes(type)) {
|
|
2384
|
+
pushError(errors, `Unknown layer type "${type}"`, path.concat("type"));
|
|
2385
|
+
return errors;
|
|
2386
|
+
}
|
|
2387
|
+
const layerType = type;
|
|
2388
|
+
if (layerType !== "background") {
|
|
2389
|
+
if (typeof layer.source !== "string") {
|
|
2390
|
+
pushError(errors, `Layer of type "${layerType}" is missing required "source" property`, path.concat("source"));
|
|
2391
|
+
} else if (sources && !(layer.source in sources)) {
|
|
2392
|
+
pushError(errors, `Layer references undefined source "${layer.source}"`, path.concat("source"));
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
if (layer.minzoom !== undefined && typeof layer.minzoom !== "number")
|
|
2396
|
+
pushError(errors, '"minzoom" must be a number', path.concat("minzoom"));
|
|
2397
|
+
if (layer.maxzoom !== undefined && typeof layer.maxzoom !== "number")
|
|
2398
|
+
pushError(errors, '"maxzoom" must be a number', path.concat("maxzoom"));
|
|
2399
|
+
const paint = layer.paint;
|
|
2400
|
+
if (paint !== undefined) {
|
|
2401
|
+
if (!isPlainObject(paint)) {
|
|
2402
|
+
pushError(errors, 'Layer "paint" must be an object', path.concat("paint"));
|
|
2403
|
+
} else {
|
|
2404
|
+
const schemas = paintPropertySchemas[layerType];
|
|
2405
|
+
for (const name of Object.keys(paint)) {
|
|
2406
|
+
const subErrors = validateProperty(schemas, layerType, "paint", name, paint[name], path.concat("paint", name));
|
|
2407
|
+
for (const e of subErrors)
|
|
2408
|
+
errors.push(e);
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
const layout = layer.layout;
|
|
2413
|
+
if (layout !== undefined) {
|
|
2414
|
+
if (!isPlainObject(layout)) {
|
|
2415
|
+
pushError(errors, 'Layer "layout" must be an object', path.concat("layout"));
|
|
2416
|
+
} else {
|
|
2417
|
+
const schemas = layoutPropertySchemas[layerType];
|
|
2418
|
+
for (const name of Object.keys(layout)) {
|
|
2419
|
+
const subErrors = validateProperty(schemas, layerType, "layout", name, layout[name], path.concat("layout", name));
|
|
2420
|
+
for (const e of subErrors)
|
|
2421
|
+
errors.push(e);
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2425
|
+
return errors;
|
|
2426
|
+
}
|
|
2427
|
+
function validateStyle(style) {
|
|
2428
|
+
const errors = [];
|
|
2429
|
+
if (!isPlainObject(style)) {
|
|
2430
|
+
pushError(errors, "Style must be an object", []);
|
|
2431
|
+
return errors;
|
|
2432
|
+
}
|
|
2433
|
+
if (style.version === undefined) {
|
|
2434
|
+
pushError(errors, 'Style is missing required "version" property', ["version"]);
|
|
2435
|
+
} else if (style.version !== 8) {
|
|
2436
|
+
pushError(errors, `Unsupported style version: ${String(style.version)} (expected 8)`, ["version"]);
|
|
2437
|
+
}
|
|
2438
|
+
const sources = style.sources;
|
|
2439
|
+
if (sources === undefined) {
|
|
2440
|
+
pushError(errors, 'Style is missing required "sources" property', ["sources"]);
|
|
2441
|
+
} else if (!isPlainObject(sources)) {
|
|
2442
|
+
pushError(errors, 'Style "sources" must be an object', ["sources"]);
|
|
2443
|
+
} else {
|
|
2444
|
+
for (const id of Object.keys(sources)) {
|
|
2445
|
+
const sourceErrors = validateSource(sources[id], id);
|
|
2446
|
+
for (const e of sourceErrors)
|
|
2447
|
+
errors.push(e);
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2450
|
+
const layers = style.layers;
|
|
2451
|
+
if (layers === undefined) {
|
|
2452
|
+
pushError(errors, 'Style is missing required "layers" property', ["layers"]);
|
|
2453
|
+
} else if (!Array.isArray(layers)) {
|
|
2454
|
+
pushError(errors, 'Style "layers" must be an array', ["layers"]);
|
|
2455
|
+
} else {
|
|
2456
|
+
const seenIds = new Set;
|
|
2457
|
+
const sourceMap = isPlainObject(sources) ? sources : undefined;
|
|
2458
|
+
for (let i = 0;i < layers.length; i++) {
|
|
2459
|
+
const layer = layers[i];
|
|
2460
|
+
const layerPath = ["layers", String(i)];
|
|
2461
|
+
if (!isPlainObject(layer)) {
|
|
2462
|
+
pushError(errors, "Layer must be an object", layerPath);
|
|
2463
|
+
continue;
|
|
2464
|
+
}
|
|
2465
|
+
if (typeof layer.id === "string") {
|
|
2466
|
+
if (seenIds.has(layer.id))
|
|
2467
|
+
pushError(errors, `Duplicate layer id "${layer.id}"`, layerPath.concat("id"));
|
|
2468
|
+
else
|
|
2469
|
+
seenIds.add(layer.id);
|
|
2470
|
+
}
|
|
2471
|
+
const subErrors = validateLayer(layer, sourceMap);
|
|
2472
|
+
for (const e of subErrors) {
|
|
2473
|
+
const relPath = e.path ? e.path.slice(1) : [];
|
|
2474
|
+
errors.push({ message: e.message, path: layerPath.concat(relPath) });
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
}
|
|
2478
|
+
if (style.name !== undefined && typeof style.name !== "string")
|
|
2479
|
+
pushError(errors, '"name" must be a string', ["name"]);
|
|
2480
|
+
if (style.zoom !== undefined && typeof style.zoom !== "number")
|
|
2481
|
+
pushError(errors, '"zoom" must be a number', ["zoom"]);
|
|
2482
|
+
if (style.bearing !== undefined && typeof style.bearing !== "number")
|
|
2483
|
+
pushError(errors, '"bearing" must be a number', ["bearing"]);
|
|
2484
|
+
if (style.pitch !== undefined && typeof style.pitch !== "number")
|
|
2485
|
+
pushError(errors, '"pitch" must be a number', ["pitch"]);
|
|
2486
|
+
if (style.center !== undefined) {
|
|
2487
|
+
const c = style.center;
|
|
2488
|
+
if (!Array.isArray(c) || c.length !== 2 || typeof c[0] !== "number" || typeof c[1] !== "number")
|
|
2489
|
+
pushError(errors, '"center" must be a [lng, lat] tuple', ["center"]);
|
|
2490
|
+
}
|
|
2491
|
+
if (style.glyphs !== undefined && typeof style.glyphs !== "string")
|
|
2492
|
+
pushError(errors, '"glyphs" must be a string template', ["glyphs"]);
|
|
2493
|
+
if (style.sprite !== undefined) {
|
|
2494
|
+
const s = style.sprite;
|
|
2495
|
+
if (typeof s !== "string" && !Array.isArray(s))
|
|
2496
|
+
pushError(errors, '"sprite" must be a string or an array of sprite sources', ["sprite"]);
|
|
2497
|
+
}
|
|
2498
|
+
return errors;
|
|
2499
|
+
}
|
|
2500
|
+
var init_validate2 = __esm(() => {
|
|
2501
|
+
init_expressions();
|
|
2502
|
+
init_schema();
|
|
2503
|
+
});
|
|
2504
|
+
|
|
2505
|
+
// src/core-map/style-spec/index.ts
|
|
2506
|
+
init_expressions();
|
|
2507
|
+
init_schema();
|
|
2508
|
+
init_validate2();
|
|
2509
|
+
export {
|
|
2510
|
+
validateStyle,
|
|
2511
|
+
validateSource,
|
|
2512
|
+
validatePaintProperty,
|
|
2513
|
+
validateLayoutProperty,
|
|
2514
|
+
validateLayer,
|
|
2515
|
+
validateExpression,
|
|
2516
|
+
sourceTypes,
|
|
2517
|
+
parseColor,
|
|
2518
|
+
paintPropertySchemas,
|
|
2519
|
+
lerpColor,
|
|
2520
|
+
layoutPropertySchemas,
|
|
2521
|
+
layerTypes,
|
|
2522
|
+
isExpression,
|
|
2523
|
+
formatColor,
|
|
2524
|
+
evaluate as evaluateExpression,
|
|
2525
|
+
diffStyles,
|
|
2526
|
+
convertLegacyFilter,
|
|
2527
|
+
compile as compileExpression,
|
|
2528
|
+
ExpressionError
|
|
2529
|
+
};
|