@mapbox/mapbox-gl-style-spec 14.15.0 → 14.16.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/dist/index.cjs +81 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +128 -34
- package/dist/index.es.js +81 -25
- package/dist/index.es.js.map +1 -1
- package/expression/definitions/index.ts +13 -0
- package/expression/expression_dependencies.ts +33 -0
- package/expression/index.ts +16 -5
- package/expression/is_constant.ts +1 -14
- package/package.json +1 -1
- package/reference/v8.json +18 -6
- package/style-spec.ts +187 -74
- package/validate/validate.ts +2 -8
- package/validate/validate_array.ts +5 -4
- package/validate/validate_enum.ts +2 -7
- package/validate/validate_expression.ts +1 -1
- package/validate/validate_layer.ts +1 -1
- package/validate/validate_number.ts +2 -4
- package/validate/validate_source.ts +1 -3
|
@@ -266,6 +266,19 @@ CompoundExpression.register(expressions, {
|
|
|
266
266
|
[],
|
|
267
267
|
(ctx) => ctx.globals.worldview || ""
|
|
268
268
|
],
|
|
269
|
+
'is-active-floor': [
|
|
270
|
+
BooleanType,
|
|
271
|
+
varargs(StringType),
|
|
272
|
+
(ctx, args) => {
|
|
273
|
+
const hasActiveFloors = ctx.globals.activeFloors && ctx.globals.activeFloors.size > 0;
|
|
274
|
+
if (!hasActiveFloors) { return false; }
|
|
275
|
+
const floorIds: Set<string> = ctx.globals.activeFloors;
|
|
276
|
+
return args.some(arg => {
|
|
277
|
+
const value = arg.evaluate(ctx) as string;
|
|
278
|
+
return floorIds.has(value);
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
],
|
|
269
282
|
'id': [
|
|
270
283
|
ValueType,
|
|
271
284
|
[],
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import CompoundExpression from "./compound_expression";
|
|
2
|
+
import Config from "./definitions/config";
|
|
3
|
+
|
|
4
|
+
import type {Expression} from "./expression";
|
|
5
|
+
|
|
6
|
+
function getConfigDependencies(e: Expression): Set<string> {
|
|
7
|
+
if (e instanceof Config) {
|
|
8
|
+
const singleConfig = new Set([e.key]);
|
|
9
|
+
return singleConfig;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let result = new Set<string>();
|
|
13
|
+
e.eachChild(arg => {
|
|
14
|
+
result = new Set([...result, ...getConfigDependencies(arg)]);
|
|
15
|
+
});
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function isIndoorDependent(e: Expression): boolean {
|
|
20
|
+
if (e instanceof CompoundExpression && e.name === 'is-active-floor') {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let result = false;
|
|
25
|
+
e.eachChild(arg => {
|
|
26
|
+
if (!result && isIndoorDependent(arg)) {
|
|
27
|
+
result = true;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export {getConfigDependencies, isIndoorDependent};
|
package/expression/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ import Coalesce from './definitions/coalesce';
|
|
|
9
9
|
import Let from './definitions/let';
|
|
10
10
|
import definitions from './definitions/index';
|
|
11
11
|
import * as isConstant from './is_constant';
|
|
12
|
+
import * as expressionDependencies from './expression_dependencies';
|
|
12
13
|
import RuntimeError from './runtime_error';
|
|
13
14
|
import {success, error} from '../util/result';
|
|
14
15
|
import {
|
|
@@ -60,16 +61,17 @@ export interface GlobalProperties {
|
|
|
60
61
|
accumulated?: Value;
|
|
61
62
|
brightness?: number;
|
|
62
63
|
worldview?: string;
|
|
64
|
+
activeFloors?: Set<string>;
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
export class StyleExpression {
|
|
66
68
|
expression: Expression;
|
|
67
|
-
|
|
68
69
|
_evaluator: EvaluationContext;
|
|
69
70
|
_defaultValue: Value;
|
|
70
71
|
_warningHistory: {[key: string]: boolean};
|
|
71
72
|
_enumValues?: {[_: string]: unknown};
|
|
72
73
|
configDependencies: Set<string>;
|
|
74
|
+
isIndoorDependent: boolean;
|
|
73
75
|
|
|
74
76
|
constructor(expression: Expression, propertySpec?: StylePropertySpecification, scope?: string, options?: ConfigOptions, iconImageUseTheme?: string) {
|
|
75
77
|
this.expression = expression;
|
|
@@ -77,7 +79,8 @@ export class StyleExpression {
|
|
|
77
79
|
this._evaluator = new EvaluationContext(scope, options, iconImageUseTheme);
|
|
78
80
|
this._defaultValue = propertySpec ? getDefaultValue(propertySpec) : null;
|
|
79
81
|
this._enumValues = propertySpec && propertySpec.type === 'enum' ? propertySpec.values : null;
|
|
80
|
-
this.configDependencies =
|
|
82
|
+
this.configDependencies = expressionDependencies.getConfigDependencies(expression);
|
|
83
|
+
this.isIndoorDependent = expressionDependencies.isIndoorDependent(expression);
|
|
81
84
|
}
|
|
82
85
|
|
|
83
86
|
evaluateWithoutErrorHandling(
|
|
@@ -124,7 +127,6 @@ export class StyleExpression {
|
|
|
124
127
|
this._evaluator.featureTileCoord = featureTileCoord || null;
|
|
125
128
|
this._evaluator.featureDistanceData = featureDistanceData || null;
|
|
126
129
|
this._evaluator.iconImageUseTheme = iconImageUseTheme || null;
|
|
127
|
-
|
|
128
130
|
try {
|
|
129
131
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
130
132
|
const val = this.expression.evaluate(this._evaluator);
|
|
@@ -190,6 +192,7 @@ export class ZoomConstantExpression<Kind extends EvaluationKind> {
|
|
|
190
192
|
kind: Kind;
|
|
191
193
|
isStateDependent: boolean;
|
|
192
194
|
configDependencies: Set<string>;
|
|
195
|
+
isIndoorDependent: boolean;
|
|
193
196
|
_styleExpression: StyleExpression;
|
|
194
197
|
isLightConstant: boolean | null | undefined;
|
|
195
198
|
isLineProgressConstant: boolean | null | undefined;
|
|
@@ -200,7 +203,8 @@ export class ZoomConstantExpression<Kind extends EvaluationKind> {
|
|
|
200
203
|
this.isLightConstant = isLightConstant;
|
|
201
204
|
this.isLineProgressConstant = isLineProgressConstant;
|
|
202
205
|
this.isStateDependent = kind !== ('constant' as EvaluationKind) && !isConstant.isStateConstant(expression.expression);
|
|
203
|
-
this.configDependencies =
|
|
206
|
+
this.configDependencies = expressionDependencies.getConfigDependencies(expression.expression);
|
|
207
|
+
this.isIndoorDependent = expressionDependencies.isIndoorDependent(expression.expression);
|
|
204
208
|
}
|
|
205
209
|
|
|
206
210
|
evaluateWithoutErrorHandling(
|
|
@@ -233,6 +237,7 @@ export class ZoomDependentExpression<Kind extends EvaluationKind> {
|
|
|
233
237
|
kind: Kind;
|
|
234
238
|
zoomStops: Array<number>;
|
|
235
239
|
isStateDependent: boolean;
|
|
240
|
+
isIndoorDependent: boolean;
|
|
236
241
|
isLightConstant: boolean | null | undefined;
|
|
237
242
|
isLineProgressConstant: boolean | null | undefined;
|
|
238
243
|
configDependencies: Set<string>;
|
|
@@ -245,9 +250,10 @@ export class ZoomDependentExpression<Kind extends EvaluationKind> {
|
|
|
245
250
|
this.zoomStops = zoomStops;
|
|
246
251
|
this._styleExpression = expression;
|
|
247
252
|
this.isStateDependent = kind !== ('camera' as EvaluationKind) && !isConstant.isStateConstant(expression.expression);
|
|
253
|
+
this.isIndoorDependent = expressionDependencies.isIndoorDependent(expression.expression);
|
|
248
254
|
this.isLightConstant = isLightConstant;
|
|
249
255
|
this.isLineProgressConstant = isLineProgressConstant;
|
|
250
|
-
this.configDependencies =
|
|
256
|
+
this.configDependencies = expressionDependencies.getConfigDependencies(expression.expression);
|
|
251
257
|
this.interpolationType = interpolationType;
|
|
252
258
|
}
|
|
253
259
|
|
|
@@ -287,6 +293,7 @@ export class ZoomDependentExpression<Kind extends EvaluationKind> {
|
|
|
287
293
|
export type ConstantExpression = {
|
|
288
294
|
kind: 'constant';
|
|
289
295
|
configDependencies: Set<string>;
|
|
296
|
+
isIndoorDependent: boolean;
|
|
290
297
|
readonly evaluate: <T = unknown>(
|
|
291
298
|
globals: GlobalProperties,
|
|
292
299
|
feature?: Feature,
|
|
@@ -301,6 +308,7 @@ export type ConstantExpression = {
|
|
|
301
308
|
export type SourceExpression = {
|
|
302
309
|
kind: 'source';
|
|
303
310
|
isStateDependent: boolean;
|
|
311
|
+
isIndoorDependent: boolean;
|
|
304
312
|
isLightConstant: boolean | null | undefined;
|
|
305
313
|
isLineProgressConstant: boolean | null | undefined;
|
|
306
314
|
configDependencies: Set<string>;
|
|
@@ -317,6 +325,7 @@ export type SourceExpression = {
|
|
|
317
325
|
export type CameraExpression = {
|
|
318
326
|
kind: 'camera';
|
|
319
327
|
isStateDependent: boolean;
|
|
328
|
+
isIndoorDependent: boolean;
|
|
320
329
|
configDependencies: Set<string>;
|
|
321
330
|
readonly evaluate: <T = unknown>(
|
|
322
331
|
globals: GlobalProperties,
|
|
@@ -333,6 +342,7 @@ export type CameraExpression = {
|
|
|
333
342
|
export interface CompositeExpression {
|
|
334
343
|
kind: 'composite';
|
|
335
344
|
isStateDependent: boolean;
|
|
345
|
+
isIndoorDependent: boolean;
|
|
336
346
|
isLightConstant: boolean | null | undefined;
|
|
337
347
|
isLineProgressConstant: boolean | null | undefined;
|
|
338
348
|
configDependencies: Set<string>;
|
|
@@ -484,6 +494,7 @@ export function normalizePropertyExpression<T>(
|
|
|
484
494
|
return {
|
|
485
495
|
kind: 'constant',
|
|
486
496
|
configDependencies: new Set(),
|
|
497
|
+
isIndoorDependent: false,
|
|
487
498
|
evaluate: () => constant
|
|
488
499
|
} as ConstantExpression;
|
|
489
500
|
}
|
|
@@ -56,19 +56,6 @@ function isStateConstant(e: Expression): boolean {
|
|
|
56
56
|
return result;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
function getConfigDependencies(e: Expression): Set<string> {
|
|
60
|
-
if (e instanceof Config) {
|
|
61
|
-
const singleConfig = new Set([e.key]);
|
|
62
|
-
return singleConfig;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
let result = new Set<string>();
|
|
66
|
-
e.eachChild(arg => {
|
|
67
|
-
result = new Set([...result, ...getConfigDependencies(arg)]);
|
|
68
|
-
});
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
59
|
function isGlobalPropertyConstant(e: Expression, properties: Array<string>): boolean {
|
|
73
60
|
if (e instanceof CompoundExpression && properties.indexOf(e.name) >= 0) { return false; }
|
|
74
61
|
let result = true;
|
|
@@ -78,4 +65,4 @@ function isGlobalPropertyConstant(e: Expression, properties: Array<string>): boo
|
|
|
78
65
|
return result;
|
|
79
66
|
}
|
|
80
67
|
|
|
81
|
-
export {isFeatureConstant, isGlobalPropertyConstant, isStateConstant
|
|
68
|
+
export {isFeatureConstant, isGlobalPropertyConstant, isStateConstant};
|
package/package.json
CHANGED
package/reference/v8.json
CHANGED
|
@@ -3137,9 +3137,9 @@
|
|
|
3137
3137
|
0.8,
|
|
3138
3138
|
2
|
|
3139
3139
|
],
|
|
3140
|
-
"doc": "
|
|
3141
|
-
"minimum": 0.1,
|
|
3142
|
-
"maximum": 10,
|
|
3140
|
+
"doc": "Limits the possible scaling range for `icon-size`, `icon-halo-width`, `icon-halo-blur` properties to be within [min-scale, max-scale]",
|
|
3141
|
+
"minimum": [0.1, 0.1],
|
|
3142
|
+
"maximum": [10, 10],
|
|
3143
3143
|
"experimental": true,
|
|
3144
3144
|
"private": true,
|
|
3145
3145
|
"expression": {
|
|
@@ -3653,9 +3653,9 @@
|
|
|
3653
3653
|
0.8,
|
|
3654
3654
|
2
|
|
3655
3655
|
],
|
|
3656
|
-
"doc": "
|
|
3657
|
-
"minimum": 0.1,
|
|
3658
|
-
"maximum": 10,
|
|
3656
|
+
"doc": "Limits the possible scaling range for `text-size`, `text-halo-width`, `text-halo-blur` properties to be within [min-scale, max-scale]",
|
|
3657
|
+
"minimum": [0.1, 0.1],
|
|
3658
|
+
"maximum": [10, 10],
|
|
3659
3659
|
"experimental": true,
|
|
3660
3660
|
"private": true,
|
|
3661
3661
|
"expression": {
|
|
@@ -5746,6 +5746,18 @@
|
|
|
5746
5746
|
}
|
|
5747
5747
|
}
|
|
5748
5748
|
},
|
|
5749
|
+
"is-active-floor": {
|
|
5750
|
+
"doc": "Experimental. Returns `true` if the input floor id belongs to one of the active indoor floors, `false` otherwise. In case of array of strings, returns `true` if any of the input floor ids belongs to one of the active indoor floors, `false` otherwise. Only supported in filters.",
|
|
5751
|
+
"group": "Indoor",
|
|
5752
|
+
"experimental": true,
|
|
5753
|
+
"sdk-support": {
|
|
5754
|
+
"basic functionality": {
|
|
5755
|
+
"js": "3.16.0",
|
|
5756
|
+
"android": "11.16.0",
|
|
5757
|
+
"ios": "11.16.0"
|
|
5758
|
+
}
|
|
5759
|
+
}
|
|
5760
|
+
},
|
|
5749
5761
|
"random": {
|
|
5750
5762
|
"doc": "Returns a random value in the specified range (first two input numbers) based on a supplied seed (third input). The seed can be an expression or a constant number or string value.",
|
|
5751
5763
|
"group": "Math",
|
package/style-spec.ts
CHANGED
|
@@ -1,77 +1,3 @@
|
|
|
1
|
-
type ExpressionType = 'data-driven' | 'color-ramp' | 'data-constant' | 'constant';
|
|
2
|
-
type ExpressionParameters = Array<'zoom' | 'feature' | 'feature-state' | 'heatmap-density' | 'line-progress' | 'raster-value' | 'sky-radial-progress' | 'pitch' | 'distance-from-center' | 'measure-light' | 'raster-particle-speed'>;
|
|
3
|
-
|
|
4
|
-
export type ExpressionSpecification = {
|
|
5
|
-
interpolated: boolean,
|
|
6
|
-
parameters?: ExpressionParameters,
|
|
7
|
-
relaxZoomRestriction?: boolean
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type StylePropertySpecification = {
|
|
11
|
-
type: 'number',
|
|
12
|
-
'property-type': ExpressionType,
|
|
13
|
-
expression?: ExpressionSpecification,
|
|
14
|
-
transition?: boolean,
|
|
15
|
-
default?: number,
|
|
16
|
-
tokens: never
|
|
17
|
-
} | {
|
|
18
|
-
type: 'string',
|
|
19
|
-
'property-type': ExpressionType,
|
|
20
|
-
expression?: ExpressionSpecification,
|
|
21
|
-
transition?: boolean,
|
|
22
|
-
default?: string,
|
|
23
|
-
tokens?: boolean
|
|
24
|
-
} | {
|
|
25
|
-
type: 'boolean',
|
|
26
|
-
'property-type': ExpressionType,
|
|
27
|
-
expression?: ExpressionSpecification,
|
|
28
|
-
transition?: boolean,
|
|
29
|
-
overridable?: boolean,
|
|
30
|
-
default?: boolean,
|
|
31
|
-
tokens?: never
|
|
32
|
-
} | {
|
|
33
|
-
type: 'enum',
|
|
34
|
-
'property-type': ExpressionType,
|
|
35
|
-
expression?: ExpressionSpecification,
|
|
36
|
-
values: {[_: string]: unknown},
|
|
37
|
-
transition?: boolean,
|
|
38
|
-
default?: string,
|
|
39
|
-
tokens: never
|
|
40
|
-
} | {
|
|
41
|
-
type: 'color',
|
|
42
|
-
'property-type': ExpressionType,
|
|
43
|
-
expression?: ExpressionSpecification,
|
|
44
|
-
transition?: boolean,
|
|
45
|
-
default?: string,
|
|
46
|
-
tokens: never,
|
|
47
|
-
overridable: boolean
|
|
48
|
-
} | {
|
|
49
|
-
type: 'array',
|
|
50
|
-
value: 'number',
|
|
51
|
-
'property-type': ExpressionType,
|
|
52
|
-
expression?: ExpressionSpecification,
|
|
53
|
-
length?: number,
|
|
54
|
-
transition?: boolean,
|
|
55
|
-
default?: Array<number>,
|
|
56
|
-
tokens: never
|
|
57
|
-
} | {
|
|
58
|
-
type: 'array',
|
|
59
|
-
value: 'string',
|
|
60
|
-
'property-type': ExpressionType,
|
|
61
|
-
expression?: ExpressionSpecification,
|
|
62
|
-
length?: number,
|
|
63
|
-
transition?: boolean,
|
|
64
|
-
default?: Array<string>,
|
|
65
|
-
tokens: never
|
|
66
|
-
} | {
|
|
67
|
-
type: 'resolvedImage',
|
|
68
|
-
'property-type': ExpressionType,
|
|
69
|
-
expression?: ExpressionSpecification,
|
|
70
|
-
transition?: boolean,
|
|
71
|
-
default?: string,
|
|
72
|
-
tokens: never
|
|
73
|
-
};
|
|
74
|
-
|
|
75
1
|
import v8 from './reference/v8.json';
|
|
76
2
|
import latest from './reference/latest';
|
|
77
3
|
import format from './format';
|
|
@@ -91,6 +17,193 @@ import {eachSource, eachLayer, eachProperty} from './visit';
|
|
|
91
17
|
import validate from './validate_style';
|
|
92
18
|
import validateMapboxApiSupported from './validate_mapbox_api_supported';
|
|
93
19
|
|
|
20
|
+
type ExpressionType = 'data-driven' | 'color-ramp' | 'data-constant' | 'constant';
|
|
21
|
+
|
|
22
|
+
type ExpressionParameter =
|
|
23
|
+
| 'zoom'
|
|
24
|
+
| 'pitch'
|
|
25
|
+
| 'feature'
|
|
26
|
+
| 'raster-value'
|
|
27
|
+
| 'feature-state'
|
|
28
|
+
| 'line-progress'
|
|
29
|
+
| 'measure-light'
|
|
30
|
+
| 'heatmap-density'
|
|
31
|
+
| 'sky-radial-progress'
|
|
32
|
+
| 'distance-from-center'
|
|
33
|
+
| 'raster-particle-speed';
|
|
34
|
+
|
|
35
|
+
export type ExpressionSpecification = {
|
|
36
|
+
interpolated: boolean,
|
|
37
|
+
parameters?: ExpressionParameter[],
|
|
38
|
+
relaxZoomRestriction?: boolean
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type ArrayPropertySpecification =
|
|
42
|
+
{
|
|
43
|
+
type: 'array';
|
|
44
|
+
'property-type': ExpressionType;
|
|
45
|
+
value: 'enum';
|
|
46
|
+
expression?: ExpressionSpecification,
|
|
47
|
+
transition?: boolean,
|
|
48
|
+
default?: string[],
|
|
49
|
+
length?: number,
|
|
50
|
+
values?: {[_: string]: unknown},
|
|
51
|
+
experimental?: boolean,
|
|
52
|
+
private?: boolean,
|
|
53
|
+
requires?: unknown,
|
|
54
|
+
appearance?: boolean,
|
|
55
|
+
tokens?: never,
|
|
56
|
+
minimum?: never,
|
|
57
|
+
maximum?: never,
|
|
58
|
+
} | {
|
|
59
|
+
type: 'array';
|
|
60
|
+
'property-type': ExpressionType;
|
|
61
|
+
value: 'number';
|
|
62
|
+
expression?: ExpressionSpecification;
|
|
63
|
+
transition?: boolean;
|
|
64
|
+
default?: number[];
|
|
65
|
+
minimum?: number;
|
|
66
|
+
maximum?: number;
|
|
67
|
+
length?: number;
|
|
68
|
+
period?: number;
|
|
69
|
+
units?: string;
|
|
70
|
+
experimental?: boolean;
|
|
71
|
+
private?: boolean;
|
|
72
|
+
requires?: unknown;
|
|
73
|
+
appearance?: boolean;
|
|
74
|
+
tokens?: never;
|
|
75
|
+
values?: never;
|
|
76
|
+
} | {
|
|
77
|
+
type: 'array';
|
|
78
|
+
'property-type': ExpressionType;
|
|
79
|
+
value: 'string';
|
|
80
|
+
expression?: ExpressionSpecification;
|
|
81
|
+
transition?: boolean;
|
|
82
|
+
default?: string[];
|
|
83
|
+
length?: number;
|
|
84
|
+
experimental?: boolean;
|
|
85
|
+
private?: boolean;
|
|
86
|
+
requires?: unknown;
|
|
87
|
+
appearance?: boolean;
|
|
88
|
+
tokens?: never;
|
|
89
|
+
minimum?: never;
|
|
90
|
+
maximum?: never;
|
|
91
|
+
values?: never;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export type BooleanPropertySpecification = {
|
|
95
|
+
type: 'boolean';
|
|
96
|
+
'property-type': ExpressionType;
|
|
97
|
+
expression?: ExpressionSpecification;
|
|
98
|
+
transition?: boolean;
|
|
99
|
+
default?: boolean;
|
|
100
|
+
overridable?: boolean;
|
|
101
|
+
experimental?: boolean;
|
|
102
|
+
private?: boolean;
|
|
103
|
+
requires?: unknown;
|
|
104
|
+
appearance?: boolean;
|
|
105
|
+
tokens?: never;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export type ColorPropertySpecification = {
|
|
109
|
+
type: 'color';
|
|
110
|
+
'property-type': ExpressionType;
|
|
111
|
+
expression?: ExpressionSpecification;
|
|
112
|
+
transition?: boolean;
|
|
113
|
+
default?: string;
|
|
114
|
+
'use-theme'?: boolean;
|
|
115
|
+
overridable?: boolean;
|
|
116
|
+
experimental?: boolean;
|
|
117
|
+
private?: boolean;
|
|
118
|
+
requires?: unknown;
|
|
119
|
+
appearance?: boolean;
|
|
120
|
+
tokens?: never;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export type EnumPropertySpecification = {
|
|
124
|
+
type: 'enum';
|
|
125
|
+
'property-type': ExpressionType;
|
|
126
|
+
expression?: ExpressionSpecification;
|
|
127
|
+
transition?: boolean;
|
|
128
|
+
default?: string;
|
|
129
|
+
values?: {[_: string]: unknown};
|
|
130
|
+
experimental?: boolean;
|
|
131
|
+
private?: boolean;
|
|
132
|
+
requires?: unknown;
|
|
133
|
+
appearance?: boolean;
|
|
134
|
+
tokens?: never;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export type FormattedPropertySpecification = {
|
|
138
|
+
type: 'formatted';
|
|
139
|
+
'property-type': ExpressionType;
|
|
140
|
+
expression?: ExpressionSpecification;
|
|
141
|
+
transition?: boolean;
|
|
142
|
+
default?: string;
|
|
143
|
+
tokens?: boolean;
|
|
144
|
+
experimental?: boolean;
|
|
145
|
+
private?: boolean;
|
|
146
|
+
requires?: unknown;
|
|
147
|
+
appearance?: boolean;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export type NumberPropertySpecification = {
|
|
151
|
+
type: 'number';
|
|
152
|
+
'property-type': ExpressionType;
|
|
153
|
+
expression?: ExpressionSpecification;
|
|
154
|
+
transition?: boolean;
|
|
155
|
+
default?: number;
|
|
156
|
+
minimum?: number;
|
|
157
|
+
maximum?: number;
|
|
158
|
+
period?: number;
|
|
159
|
+
units?: string;
|
|
160
|
+
experimental?: boolean;
|
|
161
|
+
private?: boolean;
|
|
162
|
+
requires?: unknown;
|
|
163
|
+
appearance?: boolean;
|
|
164
|
+
tokens?: never;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
export type ResolvedImagePropertySpecification = {
|
|
168
|
+
type: 'resolvedImage';
|
|
169
|
+
'property-type': ExpressionType;
|
|
170
|
+
expression?: ExpressionSpecification;
|
|
171
|
+
transition?: boolean;
|
|
172
|
+
default?: string;
|
|
173
|
+
tokens?: boolean;
|
|
174
|
+
'use-theme'?: boolean;
|
|
175
|
+
experimental?: boolean;
|
|
176
|
+
private?: boolean;
|
|
177
|
+
requires?: unknown;
|
|
178
|
+
appearance?: boolean;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
export type StringPropertySpecification = {
|
|
182
|
+
type: 'string';
|
|
183
|
+
'property-type': ExpressionType;
|
|
184
|
+
expression?: ExpressionSpecification;
|
|
185
|
+
transition?: boolean;
|
|
186
|
+
default?: string;
|
|
187
|
+
tokens?: boolean;
|
|
188
|
+
experimental?: boolean;
|
|
189
|
+
private?: boolean;
|
|
190
|
+
requires?: unknown;
|
|
191
|
+
appearance?: boolean;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* A style property specification is used to describe a value of some style property reference in the v8.json
|
|
196
|
+
*/
|
|
197
|
+
export type StylePropertySpecification =
|
|
198
|
+
| ArrayPropertySpecification
|
|
199
|
+
| BooleanPropertySpecification
|
|
200
|
+
| ColorPropertySpecification
|
|
201
|
+
| EnumPropertySpecification
|
|
202
|
+
| FormattedPropertySpecification
|
|
203
|
+
| NumberPropertySpecification
|
|
204
|
+
| ResolvedImagePropertySpecification
|
|
205
|
+
| StringPropertySpecification;
|
|
206
|
+
|
|
94
207
|
const expression = {
|
|
95
208
|
StyleExpression,
|
|
96
209
|
isExpression,
|
package/validate/validate.ts
CHANGED
|
@@ -28,6 +28,7 @@ import type ValidationError from '../error/validation_error';
|
|
|
28
28
|
import type {StyleReference} from '../reference/latest';
|
|
29
29
|
import type {StyleSpecification} from '../types';
|
|
30
30
|
import type {FunctionValidatorOptions} from './validate_function';
|
|
31
|
+
import type {StylePropertySpecification} from '../style-spec';
|
|
31
32
|
import type {ExpressionValidatorOptions} from './validate_expression';
|
|
32
33
|
|
|
33
34
|
const VALIDATORS: Record<string, (...args: unknown[]) => ValidationError[]> = {
|
|
@@ -72,14 +73,7 @@ export type ValidatorOptions = {
|
|
|
72
73
|
/**
|
|
73
74
|
* Current spec being evaluated. Tracks value.
|
|
74
75
|
*/
|
|
75
|
-
valueSpec?:
|
|
76
|
-
type?: string;
|
|
77
|
-
expression?: {
|
|
78
|
-
interpolated?: boolean;
|
|
79
|
-
parameters?: Array<'zoom' | 'feature'>;
|
|
80
|
-
};
|
|
81
|
-
'property-type'?: 'data-driven';
|
|
82
|
-
};
|
|
76
|
+
valueSpec?: Partial<StylePropertySpecification>;
|
|
83
77
|
|
|
84
78
|
/**
|
|
85
79
|
* Current full spec being evaluated.
|
|
@@ -4,10 +4,11 @@ import ValidationError from '../error/validation_error';
|
|
|
4
4
|
|
|
5
5
|
import type {StyleReference} from '../reference/latest';
|
|
6
6
|
import type {StyleSpecification} from '../types';
|
|
7
|
+
import type {ArrayPropertySpecification} from '../style-spec';
|
|
7
8
|
|
|
8
9
|
type ArraySpec = {
|
|
9
10
|
value?: unknown;
|
|
10
|
-
values?: unknown[];
|
|
11
|
+
values?: unknown[] | {[_: string]: unknown};
|
|
11
12
|
length?: number;
|
|
12
13
|
minimum?: number;
|
|
13
14
|
maximum?: number;
|
|
@@ -16,7 +17,7 @@ type ArraySpec = {
|
|
|
16
17
|
|
|
17
18
|
type ArrayElementSpec<T = unknown> = {
|
|
18
19
|
type: string;
|
|
19
|
-
values: T[];
|
|
20
|
+
values: T[] | {[_: string]: unknown};
|
|
20
21
|
minimum: number;
|
|
21
22
|
maximum: number;
|
|
22
23
|
function: unknown;
|
|
@@ -25,7 +26,7 @@ type ArrayElementSpec<T = unknown> = {
|
|
|
25
26
|
type ArrayValidatorOptions<T = unknown> = {
|
|
26
27
|
key: string;
|
|
27
28
|
value: T;
|
|
28
|
-
valueSpec: ArraySpec;
|
|
29
|
+
valueSpec: ArrayPropertySpecification | ArraySpec;
|
|
29
30
|
style: Partial<StyleSpecification>;
|
|
30
31
|
styleSpec: StyleReference;
|
|
31
32
|
arrayElementValidator: (...args: unknown[]) => ValidationError[];
|
|
@@ -60,7 +61,7 @@ export default function validateArray(options: ArrayValidatorOptions): Validatio
|
|
|
60
61
|
};
|
|
61
62
|
|
|
62
63
|
if (styleSpec.$version < 7) {
|
|
63
|
-
arrayElementSpec.function = arraySpec.function;
|
|
64
|
+
arrayElementSpec.function = (arraySpec as ArraySpec).function;
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
if (isObject(arraySpec.value)) {
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import ValidationError from '../error/validation_error';
|
|
2
2
|
import {unbundle} from '../util/unbundle_jsonlint';
|
|
3
3
|
|
|
4
|
-
import type {
|
|
5
|
-
import type {StyleSpecification} from '../types';
|
|
4
|
+
import type {EnumPropertySpecification} from '../style-spec';
|
|
6
5
|
|
|
7
6
|
type EnumValidatorOptions = {
|
|
8
7
|
key: string;
|
|
9
8
|
value: unknown;
|
|
10
|
-
valueSpec
|
|
11
|
-
values: unknown[];
|
|
12
|
-
};
|
|
13
|
-
style?: Partial<StyleSpecification>;
|
|
14
|
-
styleSpec?: StyleReference;
|
|
9
|
+
valueSpec: EnumPropertySpecification | {values: unknown[] | {[_: string]: unknown}};
|
|
15
10
|
};
|
|
16
11
|
|
|
17
12
|
export default function validateEnum(options: EnumValidatorOptions): ValidationError[] {
|
|
@@ -4,7 +4,7 @@ import {deepUnbundle} from '../util/unbundle_jsonlint';
|
|
|
4
4
|
import {isStateConstant, isGlobalPropertyConstant, isFeatureConstant} from '../expression/is_constant';
|
|
5
5
|
import CompoundExpression from '../expression/compound_expression';
|
|
6
6
|
|
|
7
|
-
import type {StylePropertySpecification} from '
|
|
7
|
+
import type {StylePropertySpecification} from '../style-spec';
|
|
8
8
|
import type {Expression} from '../expression/expression';
|
|
9
9
|
import type {StyleReference} from '../reference/latest';
|
|
10
10
|
import type {StyleSpecification} from '../types';
|
|
@@ -163,7 +163,7 @@ export default function validateLayer(options: LayerValidatorOptions): Validatio
|
|
|
163
163
|
const validationErrors = validateArray({
|
|
164
164
|
key: options.key,
|
|
165
165
|
value: options.value,
|
|
166
|
-
|
|
166
|
+
|
|
167
167
|
valueSpec: options.valueSpec,
|
|
168
168
|
style: options.style,
|
|
169
169
|
styleSpec: options.styleSpec,
|
|
@@ -3,14 +3,12 @@ import ValidationError from '../error/validation_error';
|
|
|
3
3
|
|
|
4
4
|
import type {StyleReference} from '../reference/latest';
|
|
5
5
|
import type {StyleSpecification} from '../types';
|
|
6
|
+
import type {NumberPropertySpecification} from '../style-spec';
|
|
6
7
|
|
|
7
8
|
type NumberValidatorOptions = {
|
|
8
9
|
key: string;
|
|
9
10
|
value: unknown;
|
|
10
|
-
valueSpec:
|
|
11
|
-
minimum?: number;
|
|
12
|
-
maximum?: number
|
|
13
|
-
};
|
|
11
|
+
valueSpec: NumberPropertySpecification;
|
|
14
12
|
style: Partial<StyleSpecification>;
|
|
15
13
|
styleSpec: StyleReference;
|
|
16
14
|
arrayIndex: number;
|
|
@@ -129,9 +129,7 @@ export default function validateSource(options: SourceValidatorOptions): Validat
|
|
|
129
129
|
return validateEnum({
|
|
130
130
|
key: `${key}.type`,
|
|
131
131
|
value: (value as {type: unknown}).type,
|
|
132
|
-
valueSpec: {values: getSourceTypeValues(styleSpec)}
|
|
133
|
-
style,
|
|
134
|
-
styleSpec
|
|
132
|
+
valueSpec: {values: getSourceTypeValues(styleSpec)}
|
|
135
133
|
});
|
|
136
134
|
}
|
|
137
135
|
}
|