@mapbox/mapbox-gl-style-spec 14.8.0-beta.1 → 14.9.0-beta.1
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/diff.ts +16 -0
- package/dist/index.cjs +861 -153
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +171 -9
- package/dist/index.es.js +861 -153
- package/dist/index.es.js.map +1 -1
- package/expression/definitions/coercion.ts +1 -1
- package/expression/definitions/config.ts +1 -1
- package/expression/definitions/image.ts +184 -14
- package/expression/definitions/index.ts +7 -0
- package/expression/definitions/interpolate.ts +54 -13
- package/expression/expression.ts +1 -0
- package/expression/index.ts +23 -9
- package/expression/types/formatted.ts +1 -1
- package/expression/types/image_id_with_options.ts +54 -0
- package/expression/types/resolved_image.ts +49 -7
- package/expression/values.ts +9 -7
- package/feature_filter/index.ts +13 -7
- package/function/index.ts +1 -1
- package/group_by_layout.ts +35 -3
- package/package.json +1 -1
- package/reference/v8.json +407 -88
- package/types.ts +128 -9
- package/util/color.ts +62 -1
- package/util/properties.ts +4 -0
- package/validate/validate_fog.ts +10 -1
- package/validate/validate_function.ts +1 -1
- package/validate/validate_light.ts +10 -1
- package/validate/validate_lights.ts +11 -1
- package/validate/validate_property.ts +11 -0
- package/validate/validate_rain.ts +47 -0
- package/validate/validate_snow.ts +47 -0
- package/validate/validate_terrain.ts +11 -2
- package/validate_style.min.ts +4 -0
|
@@ -1,12 +1,25 @@
|
|
|
1
|
+
import {ImageIdWithOptions} from "./image_id_with_options";
|
|
2
|
+
|
|
3
|
+
import type Color from "../../util/color";
|
|
4
|
+
|
|
5
|
+
export type RasterizationOptions = {
|
|
6
|
+
params: Record<string, Color>;
|
|
7
|
+
transform?: DOMMatrix;
|
|
8
|
+
}
|
|
9
|
+
|
|
1
10
|
export type ResolvedImageOptions = {
|
|
2
11
|
namePrimary: string;
|
|
12
|
+
optionsPrimary: RasterizationOptions | null | undefined;
|
|
3
13
|
nameSecondary: string | null | undefined;
|
|
14
|
+
optionsSecondary: RasterizationOptions | null | undefined;
|
|
4
15
|
available: boolean;
|
|
5
16
|
};
|
|
6
17
|
|
|
7
18
|
export default class ResolvedImage {
|
|
8
19
|
namePrimary: string;
|
|
20
|
+
optionsPrimary: RasterizationOptions | null | undefined;
|
|
9
21
|
nameSecondary: string | null | undefined;
|
|
22
|
+
optionsSecondary: RasterizationOptions | null | undefined;
|
|
10
23
|
available: boolean;
|
|
11
24
|
|
|
12
25
|
constructor(options: ResolvedImageOptions) {
|
|
@@ -14,25 +27,54 @@ export default class ResolvedImage {
|
|
|
14
27
|
if (options.nameSecondary) {
|
|
15
28
|
this.nameSecondary = options.nameSecondary;
|
|
16
29
|
}
|
|
30
|
+
if (options.optionsPrimary) {
|
|
31
|
+
this.optionsPrimary = options.optionsPrimary;
|
|
32
|
+
}
|
|
33
|
+
if (options.optionsSecondary) {
|
|
34
|
+
this.optionsSecondary = options.optionsSecondary;
|
|
35
|
+
}
|
|
17
36
|
this.available = options.available;
|
|
18
37
|
}
|
|
19
38
|
|
|
20
39
|
toString(): string {
|
|
21
|
-
if (this.nameSecondary) {
|
|
40
|
+
if (this.namePrimary && this.nameSecondary) {
|
|
22
41
|
return `[${this.namePrimary},${this.nameSecondary}]`;
|
|
23
42
|
}
|
|
43
|
+
|
|
24
44
|
return this.namePrimary;
|
|
25
45
|
}
|
|
26
46
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
47
|
+
getPrimary(): ImageIdWithOptions {
|
|
48
|
+
return new ImageIdWithOptions(this.namePrimary, {
|
|
49
|
+
params: this.optionsPrimary ? (this.optionsPrimary.params || {}) : {},
|
|
50
|
+
});
|
|
30
51
|
}
|
|
31
52
|
|
|
32
|
-
|
|
53
|
+
getSerializedPrimary(): string {
|
|
54
|
+
return this.getPrimary().serialize();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
getSecondary(): ImageIdWithOptions | null {
|
|
33
58
|
if (this.nameSecondary) {
|
|
34
|
-
return
|
|
59
|
+
return new ImageIdWithOptions(this.nameSecondary, {
|
|
60
|
+
params: this.optionsSecondary ? (this.optionsSecondary.params || {}) : {},
|
|
61
|
+
});
|
|
35
62
|
}
|
|
36
|
-
|
|
63
|
+
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static from(image: string | ResolvedImage): ResolvedImage {
|
|
68
|
+
return typeof image === 'string' ? ResolvedImage.build(image) : image;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static build(
|
|
72
|
+
namePrimary: string,
|
|
73
|
+
nameSecondary?: string | null,
|
|
74
|
+
optionsPrimary?: RasterizationOptions | null,
|
|
75
|
+
optionsSecondary?: RasterizationOptions | null
|
|
76
|
+
): ResolvedImage | null {
|
|
77
|
+
if (!namePrimary) return null; // treat empty values as no image
|
|
78
|
+
return new ResolvedImage({namePrimary, nameSecondary, optionsPrimary, optionsSecondary, available: false});
|
|
37
79
|
}
|
|
38
80
|
}
|
package/expression/values.ts
CHANGED
|
@@ -13,14 +13,14 @@ export function validateRGBA(r: unknown, g: unknown, b: unknown, a?: unknown): s
|
|
|
13
13
|
typeof g === 'number' && g >= 0 && g <= 255 &&
|
|
14
14
|
typeof b === 'number' && b >= 0 && b <= 255
|
|
15
15
|
)) {
|
|
16
|
-
const value = typeof a === 'number' ? [r, g, b, a] : [r, g, b];
|
|
16
|
+
const value = (typeof a === 'number' ? [r, g, b, a] : [r, g, b]) as number[];
|
|
17
17
|
return `Invalid rgba value [${value.join(', ')}]: 'r', 'g', and 'b' must be between 0 and 255.`;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
if (!(
|
|
21
21
|
typeof a === 'undefined' || (typeof a === 'number' && a >= 0 && a <= 1)
|
|
22
22
|
)) {
|
|
23
|
-
return `Invalid rgba value [${[r, g, b, a].join(', ')}]: 'a' must be between 0 and 1.`;
|
|
23
|
+
return `Invalid rgba value [${([r, g, b, a] as number[]).join(', ')}]: 'a' must be between 0 and 1.`;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
return null;
|
|
@@ -30,7 +30,7 @@ export function validateHSLA(h: unknown, s: unknown, l: unknown, a?: unknown): s
|
|
|
30
30
|
if (!(
|
|
31
31
|
typeof h === 'number' && h >= 0 && h <= 360
|
|
32
32
|
)) {
|
|
33
|
-
const value = typeof a === 'number' ? [h, s, l, a] : [h, s, l];
|
|
33
|
+
const value = (typeof a === 'number' ? [h, s, l, a] : [h, s, l]) as number[];
|
|
34
34
|
return `Invalid hsla value [${value.join(', ')}]: 'h' must be between 0 and 360.`;
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -38,14 +38,14 @@ export function validateHSLA(h: unknown, s: unknown, l: unknown, a?: unknown): s
|
|
|
38
38
|
typeof s === 'number' && s >= 0 && s <= 100 &&
|
|
39
39
|
typeof l === 'number' && l >= 0 && l <= 100
|
|
40
40
|
)) {
|
|
41
|
-
const value = typeof a === 'number' ? [h, s, l, a] : [h, s, l];
|
|
41
|
+
const value = (typeof a === 'number' ? [h, s, l, a] : [h, s, l]) as number[];
|
|
42
42
|
return `Invalid hsla value [${value.join(', ')}]: 's', and 'l' must be between 0 and 100.`;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
if (!(
|
|
46
46
|
typeof a === 'undefined' || (typeof a === 'number' && a >= 0 && a <= 1)
|
|
47
47
|
)) {
|
|
48
|
-
return `Invalid hsla value [${[h, s, l, a].join(', ')}]: 'a' must be between 0 and 1.`;
|
|
48
|
+
return `Invalid hsla value [${([h, s, l, a] as number[]).join(', ')}]: 'a' must be between 0 and 1.`;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
return null;
|
|
@@ -136,8 +136,10 @@ export function toString(value: Value): string {
|
|
|
136
136
|
if (value === null) {
|
|
137
137
|
return '';
|
|
138
138
|
} else if (type === 'string' || type === 'number' || type === 'boolean') {
|
|
139
|
-
return String(value);
|
|
140
|
-
} else if (value instanceof Color
|
|
139
|
+
return String(value as string | number | boolean);
|
|
140
|
+
} else if (value instanceof Color) {
|
|
141
|
+
return value.toStringPremultipliedAlpha();
|
|
142
|
+
} else if (value instanceof Formatted || value instanceof ResolvedImage) {
|
|
141
143
|
return value.toString();
|
|
142
144
|
} else {
|
|
143
145
|
return JSON.stringify(value);
|
package/feature_filter/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import latest from '../reference/latest';
|
|
|
2
2
|
import {deepUnbundle} from '../util/unbundle_jsonlint';
|
|
3
3
|
import {createExpression} from '../expression/index';
|
|
4
4
|
import {isFeatureConstant} from '../expression/is_constant';
|
|
5
|
+
import assert from 'assert';
|
|
5
6
|
|
|
6
7
|
import type Point from '@mapbox/point-geometry';
|
|
7
8
|
import type {CanonicalTileID} from '../types/tile_id';
|
|
@@ -21,6 +22,7 @@ export type FilterExpression = (
|
|
|
21
22
|
featureTileCoord?: Point,
|
|
22
23
|
featureDistanceData?: FeatureDistanceData,
|
|
23
24
|
) => boolean;
|
|
25
|
+
|
|
24
26
|
export type FeatureFilter = {
|
|
25
27
|
filter: FilterExpression;
|
|
26
28
|
dynamicFilter?: FilterExpression;
|
|
@@ -109,14 +111,18 @@ ${JSON.stringify(filterExp, null, 2)}
|
|
|
109
111
|
}
|
|
110
112
|
|
|
111
113
|
// Compile the static component of the filter
|
|
112
|
-
const filterSpec = latest[`filter_${layerType}`];
|
|
113
|
-
const compiledStaticFilter = createExpression(staticFilter, filterSpec, scope, options);
|
|
114
|
-
|
|
115
114
|
let filterFunc = null;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
115
|
+
let filterSpec = null;
|
|
116
|
+
if (layerType !== 'background' && layerType !== 'sky' && layerType !== 'slot') {
|
|
117
|
+
filterSpec = latest[`filter_${layerType}`];
|
|
118
|
+
assert(filterSpec);
|
|
119
|
+
const compiledStaticFilter = createExpression(staticFilter, filterSpec, scope, options);
|
|
120
|
+
|
|
121
|
+
if (compiledStaticFilter.result === 'error') {
|
|
122
|
+
throw new Error(compiledStaticFilter.value.map(err => `${err.key}: ${err.message}`).join(', '));
|
|
123
|
+
} else {
|
|
124
|
+
filterFunc = (globalProperties: GlobalProperties, feature: Feature, canonical?: CanonicalTileID) => compiledStaticFilter.value.evaluate(globalProperties, feature, {}, canonical);
|
|
125
|
+
}
|
|
120
126
|
}
|
|
121
127
|
|
|
122
128
|
// If the static component is not equal to the entire filter then we have a dynamic component
|
package/function/index.ts
CHANGED
|
@@ -204,7 +204,7 @@ function evaluateIdentityFunction(parameters, propertySpec, input) {
|
|
|
204
204
|
} else if (propertySpec.type === 'formatted') {
|
|
205
205
|
input = Formatted.fromString(input.toString());
|
|
206
206
|
} else if (propertySpec.type === 'resolvedImage') {
|
|
207
|
-
input = ResolvedImage.
|
|
207
|
+
input = ResolvedImage.build(input.toString());
|
|
208
208
|
} else if (getType(input) !== propertySpec.type && (propertySpec.type !== 'enum' || !propertySpec.values[input])) {
|
|
209
209
|
input = undefined;
|
|
210
210
|
}
|
package/group_by_layout.ts
CHANGED
|
@@ -29,6 +29,25 @@ function getKey(layer: LayerSpecification) {
|
|
|
29
29
|
return key;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
function containsKey(obj: any, key: string) {
|
|
33
|
+
function recursiveSearch(item) {
|
|
34
|
+
if (typeof item === 'string' && item === key) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (Array.isArray(item)) {
|
|
39
|
+
return item.some(recursiveSearch);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (item && typeof item === 'object') {
|
|
43
|
+
return Object.values(item).some(recursiveSearch);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return recursiveSearch(obj);
|
|
49
|
+
}
|
|
50
|
+
|
|
32
51
|
/**
|
|
33
52
|
* Given an array of layers, return an array of arrays of layers where all
|
|
34
53
|
* layers in each group have identical layout-affecting properties. These
|
|
@@ -53,17 +72,30 @@ export default function groupByLayout(
|
|
|
53
72
|
const groups: Record<string, any> = {};
|
|
54
73
|
|
|
55
74
|
for (let i = 0; i < layers.length; i++) {
|
|
75
|
+
const layer = layers[i];
|
|
76
|
+
let k = cachedKeys && cachedKeys[layer.id];
|
|
77
|
+
|
|
78
|
+
if (!k) {
|
|
79
|
+
k = getKey(layer);
|
|
80
|
+
// The usage of "line-progress" inside "line-width" makes the property act like a layout property.
|
|
81
|
+
// We need to split it from the group to avoid conflicts in the bucket creation.
|
|
82
|
+
if (layer.type === 'line' && layer["paint"]) {
|
|
83
|
+
const lineWidth = layer["paint"]['line-width'];
|
|
84
|
+
if (containsKey(lineWidth, 'line-progress')) {
|
|
85
|
+
k += `/${stringify(layer["paint"]['line-width'])}`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
56
89
|
|
|
57
|
-
const k = (cachedKeys && cachedKeys[layers[i].id]) || getKey(layers[i]);
|
|
58
90
|
// update the cache if there is one
|
|
59
91
|
if (cachedKeys)
|
|
60
|
-
cachedKeys[
|
|
92
|
+
cachedKeys[layer.id] = k;
|
|
61
93
|
|
|
62
94
|
let group = groups[k];
|
|
63
95
|
if (!group) {
|
|
64
96
|
group = groups[k] = [];
|
|
65
97
|
}
|
|
66
|
-
group.push(
|
|
98
|
+
group.push(layer);
|
|
67
99
|
}
|
|
68
100
|
|
|
69
101
|
const result = [];
|