@mapbox/mapbox-gl-style-spec 14.4.0 → 14.5.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/bin/gl-style-composite.js +0 -5
- package/bin/gl-style-format.js +0 -5
- package/bin/gl-style-migrate.js +0 -5
- package/bin/gl-style-validate.js +0 -5
- package/{composite.js → composite.ts} +1 -1
- package/data/{extent.js → extent.ts} +0 -2
- package/{deref.js → deref.ts} +7 -9
- package/{diff.js → diff.ts} +44 -21
- package/dist/index.cjs +794 -1226
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1746 -0
- package/dist/index.es.js +794 -1226
- package/dist/index.es.js.map +1 -1
- package/{empty.js → empty.ts} +1 -2
- package/error/{parsing_error.js → parsing_error.ts} +0 -2
- package/error/{validation_error.js → validation_error.ts} +5 -5
- package/expression/{compound_expression.js → compound_expression.ts} +29 -19
- package/expression/definitions/{assertion.js → assertion.ts} +16 -13
- package/expression/definitions/{at.js → at.ts} +12 -13
- package/expression/definitions/{case.js → case.ts} +12 -11
- package/expression/definitions/{coalesce.js → coalesce.ts} +11 -11
- package/expression/definitions/{coercion.js → coercion.ts} +21 -20
- package/expression/definitions/{collator.js → collator.ts} +11 -11
- package/expression/definitions/{comparison.js → comparison.ts} +30 -24
- package/expression/definitions/{config.js → config.ts} +16 -16
- package/expression/definitions/{distance.js → distance.ts} +60 -52
- package/expression/definitions/{format.js → format.ts} +26 -15
- package/expression/definitions/{image.js → image.ts} +12 -12
- package/expression/definitions/{in.js → in.ts} +22 -13
- package/expression/definitions/{index.js → index.ts} +70 -83
- package/expression/definitions/{index_of.js → index_of.ts} +24 -15
- package/expression/definitions/{interpolate.js → interpolate.ts} +44 -25
- package/expression/definitions/{length.js → length.ts} +11 -10
- package/expression/definitions/{let.js → let.ts} +10 -7
- package/expression/definitions/{literal.js → literal.ts} +11 -12
- package/expression/definitions/{match.js → match.ts} +25 -15
- package/expression/definitions/{number_format.js → number_format.ts} +10 -10
- package/expression/definitions/{slice.js → slice.ts} +23 -15
- package/expression/definitions/{step.js → step.ts} +14 -12
- package/expression/definitions/{var.js → var.ts} +5 -7
- package/expression/definitions/{within.js → within.ts} +41 -29
- package/expression/{evaluation_context.js → evaluation_context.ts} +26 -23
- package/expression/expression.ts +29 -0
- package/expression/{index.js → index.ts} +208 -110
- package/expression/{is_constant.js → is_constant.ts} +5 -7
- package/expression/{parsing_context.js → parsing_context.ts} +47 -34
- package/expression/{parsing_error.js → parsing_error.ts} +0 -2
- package/expression/{runtime_error.js → runtime_error.ts} +0 -2
- package/expression/{scope.js → scope.ts} +5 -5
- package/expression/{stops.js → stops.ts} +2 -4
- package/expression/types/{collator.js → collator.ts} +1 -3
- package/expression/types/{formatted.js → formatted.ts} +8 -7
- package/expression/types/{resolved_image.js → resolved_image.ts} +5 -7
- package/expression/{types.js → types.ts} +53 -45
- package/expression/{values.js → values.ts} +12 -12
- package/feature_filter/{convert.js → convert.ts} +19 -18
- package/feature_filter/{index.js → index.ts} +39 -21
- package/{format.js → format.ts} +3 -3
- package/function/{convert.js → convert.ts} +44 -44
- package/function/{index.js → index.ts} +12 -12
- package/{group_by_layout.js → group_by_layout.ts} +11 -8
- package/migrate/{expressions.js → expressions.ts} +7 -16
- package/migrate/{v8.js → v8.ts} +2 -2
- package/migrate/{v9.js → v9.ts} +2 -2
- package/{migrate.js → migrate.ts} +3 -3
- package/package.json +19 -18
- package/{read_style.js → read_style.ts} +5 -4
- package/reference/latest.ts +5 -0
- package/reference/v8.json +264 -7
- package/rollup.config.js +6 -24
- package/{style-spec.js → style-spec.ts} +41 -36
- package/test.js +3 -2
- package/types/config_options.ts +13 -0
- package/types/lut.ts +7 -0
- package/types/tile_id.ts +5 -0
- package/{types.js → types.ts} +527 -165
- package/util/{color.js → color.ts} +89 -3
- package/util/{color_spaces.js → color_spaces.ts} +12 -14
- package/util/{deep_equal.js → deep_equal.ts} +1 -3
- package/util/{extend.js → extend.ts} +1 -3
- package/util/{geometry_util.js → geometry_util.ts} +23 -11
- package/util/{get_type.js → get_type.ts} +1 -3
- package/util/{interpolate.js → interpolate.ts} +1 -3
- package/util/{properties.js → properties.ts} +5 -4
- package/util/{random.js → random.ts} +0 -2
- package/util/{ref_properties.js → ref_properties.ts} +0 -1
- package/util/{result.js → result.ts} +7 -5
- package/util/{unbundle_jsonlint.js → unbundle_jsonlint.ts} +5 -5
- package/validate/{validate.js → validate.ts} +33 -35
- package/validate/{validate_array.js → validate_array.ts} +5 -7
- package/validate/{validate_boolean.js → validate_boolean.ts} +3 -5
- package/validate/{validate_color.js → validate_color.ts} +3 -5
- package/validate/{validate_enum.js → validate_enum.ts} +4 -5
- package/validate/{validate_expression.js → validate_expression.ts} +7 -9
- package/validate/{validate_filter.js → validate_filter.ts} +16 -12
- package/validate/{validate_fog.js → validate_fog.ts} +4 -6
- package/validate/validate_formatted.ts +13 -0
- package/validate/{validate_function.js → validate_function.ts} +14 -16
- package/validate/{validate_glyphs_url.js → validate_glyphs_url.ts} +3 -5
- package/validate/validate_image.ts +13 -0
- package/validate/{validate_import.js → validate_import.ts} +6 -8
- package/validate/{validate_layer.js → validate_layer.ts} +17 -15
- package/validate/{validate_layout_property.js → validate_layout_property.ts} +3 -5
- package/validate/{validate_light.js → validate_light.ts} +4 -6
- package/validate/{validate_lights.js → validate_lights.ts} +7 -9
- package/validate/{validate_model.js → validate_model.ts} +4 -6
- package/validate/{validate_number.js → validate_number.ts} +4 -6
- package/validate/{validate_object.js → validate_object.ts} +5 -8
- package/validate/{validate_paint_property.js → validate_paint_property.ts} +3 -5
- package/validate/{validate_projection.js → validate_projection.ts} +4 -6
- package/validate/{validate_property.js → validate_property.ts} +15 -15
- package/validate/{validate_source.js → validate_source.ts} +16 -13
- package/validate/validate_string.ts +16 -0
- package/validate/validate_style.ts +33 -0
- package/validate/{validate_terrain.js → validate_terrain.ts} +5 -7
- package/{validate_mapbox_api_supported.js → validate_mapbox_api_supported.ts} +22 -18
- package/{validate_style.min.js → validate_style.min.ts} +20 -21
- package/{validate_style.js → validate_style.ts} +9 -9
- package/{visit.js → visit.ts} +22 -17
- package/.eslintrc +0 -10
- package/expression/expression.js +0 -28
- package/flow-typed/cheap-ruler.js +0 -25
- package/flow-typed/geojson.js +0 -44
- package/flow-typed/gl-matrix.js +0 -119
- package/flow-typed/gl.js +0 -5
- package/flow-typed/intl.js +0 -58
- package/flow-typed/kdbush.js +0 -9
- package/flow-typed/mapbox-gl-supported.js +0 -16
- package/flow-typed/mapbox-unitbezier.js +0 -14
- package/flow-typed/offscreen-canvas.js +0 -9
- package/flow-typed/pbf.js +0 -26
- package/flow-typed/point-geometry.js +0 -46
- package/flow-typed/potpack.js +0 -13
- package/flow-typed/tiny-sdf.js +0 -31
- package/flow-typed/tracked_parameters_proxy.js +0 -82
- package/flow-typed/vector-tile.js +0 -49
- package/flow-typed/webgl2.js +0 -41
- package/reference/latest.js +0 -7
- package/validate/validate_formatted.js +0 -15
- package/validate/validate_image.js +0 -15
- package/validate/validate_string.js +0 -18
- package/validate/validate_style.js +0 -29
|
@@ -1,61 +1,65 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import assert from 'assert';
|
|
4
2
|
|
|
5
|
-
import extend from '../util/extend
|
|
6
|
-
import ParsingError from './parsing_error
|
|
7
|
-
import ParsingContext from './parsing_context
|
|
8
|
-
import EvaluationContext from './evaluation_context
|
|
9
|
-
import CompoundExpression from './compound_expression
|
|
10
|
-
import Step from './definitions/step
|
|
11
|
-
import Interpolate from './definitions/interpolate
|
|
12
|
-
import Coalesce from './definitions/coalesce
|
|
13
|
-
import Let from './definitions/let
|
|
14
|
-
import definitions from './definitions/index
|
|
15
|
-
import * as isConstant from './is_constant
|
|
16
|
-
import RuntimeError from './runtime_error
|
|
17
|
-
import {success, error} from '../util/result
|
|
3
|
+
import extend from '../util/extend';
|
|
4
|
+
import ParsingError from './parsing_error';
|
|
5
|
+
import ParsingContext from './parsing_context';
|
|
6
|
+
import EvaluationContext from './evaluation_context';
|
|
7
|
+
import CompoundExpression from './compound_expression';
|
|
8
|
+
import Step from './definitions/step';
|
|
9
|
+
import Interpolate from './definitions/interpolate';
|
|
10
|
+
import Coalesce from './definitions/coalesce';
|
|
11
|
+
import Let from './definitions/let';
|
|
12
|
+
import definitions from './definitions/index';
|
|
13
|
+
import * as isConstant from './is_constant';
|
|
14
|
+
import RuntimeError from './runtime_error';
|
|
15
|
+
import {success, error} from '../util/result';
|
|
18
16
|
import {
|
|
19
17
|
supportsPropertyExpression,
|
|
20
18
|
supportsZoomExpression,
|
|
21
19
|
supportsLightExpression,
|
|
22
20
|
supportsInterpolation
|
|
23
|
-
} from '../util/properties
|
|
24
|
-
|
|
25
|
-
import type {Type, EvaluationKind} from './types
|
|
26
|
-
import type {Value} from './values
|
|
27
|
-
import type {Expression} from './expression
|
|
28
|
-
import type {StylePropertySpecification} from '../style-spec
|
|
29
|
-
import type {Result} from '../util/result
|
|
30
|
-
import type {InterpolationType} from './definitions/interpolate
|
|
31
|
-
import type {PropertyValueSpecification} from '../types
|
|
32
|
-
import type {FormattedSection} from './types/formatted
|
|
21
|
+
} from '../util/properties';
|
|
22
|
+
|
|
23
|
+
import type {Type, EvaluationKind} from './types';
|
|
24
|
+
import type {Value} from './values';
|
|
25
|
+
import type {Expression} from './expression';
|
|
26
|
+
import type {StylePropertySpecification} from '../style-spec';
|
|
27
|
+
import type {Result} from '../util/result';
|
|
28
|
+
import type {InterpolationType} from './definitions/interpolate';
|
|
29
|
+
import type {PropertyValueSpecification} from '../types';
|
|
30
|
+
import type {FormattedSection} from './types/formatted';
|
|
33
31
|
import type Point from '@mapbox/point-geometry';
|
|
34
|
-
import type {CanonicalTileID} from '
|
|
35
|
-
import type {FeatureDistanceData} from '../feature_filter/index
|
|
36
|
-
import type {ConfigOptions} from '
|
|
32
|
+
import type {CanonicalTileID} from '../types/tile_id';
|
|
33
|
+
import type {FeatureDistanceData} from '../feature_filter/index';
|
|
34
|
+
import type {ConfigOptions} from '../types/config_options';
|
|
37
35
|
|
|
38
36
|
export interface Feature {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
readonly type: 1 | 2 | 3 | 'Unknown' | 'Point' | 'LineString' | 'Polygon';
|
|
38
|
+
readonly id?: number | null;
|
|
39
|
+
readonly properties: {
|
|
40
|
+
[_: string]: any;
|
|
41
|
+
};
|
|
42
|
+
readonly patterns?: {
|
|
43
|
+
[_: string]: string;
|
|
44
|
+
};
|
|
45
|
+
readonly geometry?: Array<Array<Point>>;
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
export type FeatureState = {
|
|
48
|
+
export type FeatureState = {
|
|
49
|
+
[_: string]: any;
|
|
50
|
+
};
|
|
47
51
|
|
|
48
52
|
export interface GlobalProperties {
|
|
49
|
-
zoom: number
|
|
50
|
-
pitch?: number
|
|
51
|
-
heatmapDensity?: number
|
|
52
|
-
lineProgress?: number
|
|
53
|
-
rasterValue?: number
|
|
54
|
-
rasterParticleSpeed?: number
|
|
55
|
-
skyRadialProgress?: number
|
|
56
|
-
|
|
57
|
-
accumulated?: Value
|
|
58
|
-
brightness?: number
|
|
53
|
+
zoom: number;
|
|
54
|
+
pitch?: number;
|
|
55
|
+
heatmapDensity?: number;
|
|
56
|
+
lineProgress?: number;
|
|
57
|
+
rasterValue?: number;
|
|
58
|
+
rasterParticleSpeed?: number;
|
|
59
|
+
skyRadialProgress?: number;
|
|
60
|
+
readonly isSupportedScript?: (_: string) => boolean;
|
|
61
|
+
accumulated?: Value;
|
|
62
|
+
brightness?: number;
|
|
59
63
|
}
|
|
60
64
|
|
|
61
65
|
export class StyleExpression {
|
|
@@ -64,9 +68,9 @@ export class StyleExpression {
|
|
|
64
68
|
_evaluator: EvaluationContext;
|
|
65
69
|
_defaultValue: Value;
|
|
66
70
|
_warningHistory: {[key: string]: boolean};
|
|
67
|
-
_enumValues
|
|
71
|
+
_enumValues?: {[_: string]: unknown};
|
|
68
72
|
|
|
69
|
-
constructor(expression: Expression, propertySpec
|
|
73
|
+
constructor(expression: Expression, propertySpec?: StylePropertySpecification, scope?: string, options?: ConfigOptions) {
|
|
70
74
|
this.expression = expression;
|
|
71
75
|
this._warningHistory = {};
|
|
72
76
|
this._evaluator = new EvaluationContext(scope, options);
|
|
@@ -74,7 +78,16 @@ export class StyleExpression {
|
|
|
74
78
|
this._enumValues = propertySpec && propertySpec.type === 'enum' ? propertySpec.values : null;
|
|
75
79
|
}
|
|
76
80
|
|
|
77
|
-
evaluateWithoutErrorHandling(
|
|
81
|
+
evaluateWithoutErrorHandling(
|
|
82
|
+
globals: GlobalProperties,
|
|
83
|
+
feature?: Feature,
|
|
84
|
+
featureState?: FeatureState,
|
|
85
|
+
canonical?: CanonicalTileID,
|
|
86
|
+
availableImages?: Array<string>,
|
|
87
|
+
formattedSection?: FormattedSection,
|
|
88
|
+
featureTileCoord?: Point,
|
|
89
|
+
featureDistanceData?: FeatureDistanceData,
|
|
90
|
+
): any {
|
|
78
91
|
this._evaluator.globals = globals;
|
|
79
92
|
this._evaluator.feature = feature;
|
|
80
93
|
this._evaluator.featureState = featureState;
|
|
@@ -87,7 +100,16 @@ export class StyleExpression {
|
|
|
87
100
|
return this.expression.evaluate(this._evaluator);
|
|
88
101
|
}
|
|
89
102
|
|
|
90
|
-
evaluate(
|
|
103
|
+
evaluate(
|
|
104
|
+
globals: GlobalProperties,
|
|
105
|
+
feature?: Feature,
|
|
106
|
+
featureState?: FeatureState,
|
|
107
|
+
canonical?: CanonicalTileID,
|
|
108
|
+
availableImages?: Array<string>,
|
|
109
|
+
formattedSection?: FormattedSection,
|
|
110
|
+
featureTileCoord?: Point,
|
|
111
|
+
featureDistanceData?: FeatureDistanceData,
|
|
112
|
+
): any {
|
|
91
113
|
this._evaluator.globals = globals;
|
|
92
114
|
this._evaluator.feature = feature || null;
|
|
93
115
|
this._evaluator.featureState = featureState || null;
|
|
@@ -107,7 +129,7 @@ export class StyleExpression {
|
|
|
107
129
|
throw new RuntimeError(`Expected value to be one of ${Object.keys(this._enumValues).map(v => JSON.stringify(v)).join(', ')}, but found ${JSON.stringify(val)} instead.`);
|
|
108
130
|
}
|
|
109
131
|
return val;
|
|
110
|
-
} catch (e) {
|
|
132
|
+
} catch (e: any) {
|
|
111
133
|
if (!this._warningHistory[e.message]) {
|
|
112
134
|
this._warningHistory[e.message] = true;
|
|
113
135
|
if (typeof console !== 'undefined') {
|
|
@@ -119,7 +141,7 @@ export class StyleExpression {
|
|
|
119
141
|
}
|
|
120
142
|
}
|
|
121
143
|
|
|
122
|
-
export function isExpression(expression:
|
|
144
|
+
export function isExpression(expression: unknown): boolean {
|
|
123
145
|
return Array.isArray(expression) && expression.length > 0 &&
|
|
124
146
|
typeof expression[0] === 'string' && expression[0] in definitions;
|
|
125
147
|
}
|
|
@@ -133,7 +155,12 @@ export function isExpression(expression: mixed): boolean {
|
|
|
133
155
|
*
|
|
134
156
|
* @private
|
|
135
157
|
*/
|
|
136
|
-
export function createExpression(
|
|
158
|
+
export function createExpression(
|
|
159
|
+
expression: unknown,
|
|
160
|
+
propertySpec?: StylePropertySpecification | null,
|
|
161
|
+
scope?: string | null,
|
|
162
|
+
options?: ConfigOptions | null,
|
|
163
|
+
): Result<StyleExpression, Array<ParsingError>> {
|
|
137
164
|
const parser = new ParsingContext(definitions, [], propertySpec ? getExpectedType(propertySpec) : undefined, undefined, undefined, scope, options);
|
|
138
165
|
|
|
139
166
|
// For string-valued properties, coerce to string at the top level rather than asserting.
|
|
@@ -148,55 +175,83 @@ export function createExpression(expression: mixed, propertySpec: ?StyleProperty
|
|
|
148
175
|
return success(new StyleExpression(parsed, propertySpec, scope, options));
|
|
149
176
|
}
|
|
150
177
|
|
|
151
|
-
export class ZoomConstantExpression<Kind
|
|
178
|
+
export class ZoomConstantExpression<Kind extends EvaluationKind> {
|
|
152
179
|
kind: Kind;
|
|
153
180
|
isStateDependent: boolean;
|
|
154
181
|
isConfigDependent: boolean;
|
|
155
182
|
_styleExpression: StyleExpression;
|
|
156
|
-
isLightConstant:
|
|
183
|
+
isLightConstant: boolean | null | undefined;
|
|
157
184
|
|
|
158
|
-
constructor(kind: Kind, expression: StyleExpression, isLightConstant
|
|
185
|
+
constructor(kind: Kind, expression: StyleExpression, isLightConstant?: boolean | null) {
|
|
159
186
|
this.kind = kind;
|
|
160
187
|
this._styleExpression = expression;
|
|
161
188
|
this.isLightConstant = isLightConstant;
|
|
162
|
-
this.isStateDependent = kind !== ('constant'
|
|
189
|
+
this.isStateDependent = kind !== ('constant' as EvaluationKind) && !isConstant.isStateConstant(expression.expression);
|
|
163
190
|
this.isConfigDependent = !isConstant.isConfigConstant(expression.expression);
|
|
164
191
|
}
|
|
165
192
|
|
|
166
|
-
evaluateWithoutErrorHandling(
|
|
193
|
+
evaluateWithoutErrorHandling(
|
|
194
|
+
globals: GlobalProperties,
|
|
195
|
+
feature?: Feature,
|
|
196
|
+
featureState?: FeatureState,
|
|
197
|
+
canonical?: CanonicalTileID,
|
|
198
|
+
availableImages?: Array<string>,
|
|
199
|
+
formattedSection?: FormattedSection,
|
|
200
|
+
): any {
|
|
167
201
|
return this._styleExpression.evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection);
|
|
168
202
|
}
|
|
169
203
|
|
|
170
|
-
evaluate(
|
|
204
|
+
evaluate(
|
|
205
|
+
globals: GlobalProperties,
|
|
206
|
+
feature?: Feature,
|
|
207
|
+
featureState?: FeatureState,
|
|
208
|
+
canonical?: CanonicalTileID,
|
|
209
|
+
availableImages?: Array<string>,
|
|
210
|
+
formattedSection?: FormattedSection,
|
|
211
|
+
): any {
|
|
171
212
|
return this._styleExpression.evaluate(globals, feature, featureState, canonical, availableImages, formattedSection);
|
|
172
213
|
}
|
|
173
214
|
}
|
|
174
215
|
|
|
175
|
-
export class ZoomDependentExpression<Kind
|
|
216
|
+
export class ZoomDependentExpression<Kind extends EvaluationKind> {
|
|
176
217
|
kind: Kind;
|
|
177
218
|
zoomStops: Array<number>;
|
|
178
219
|
isStateDependent: boolean;
|
|
179
|
-
isLightConstant:
|
|
220
|
+
isLightConstant: boolean | null | undefined;
|
|
180
221
|
isConfigDependent: boolean;
|
|
181
222
|
|
|
182
223
|
_styleExpression: StyleExpression;
|
|
183
|
-
interpolationType:
|
|
224
|
+
interpolationType: InterpolationType | null | undefined;
|
|
184
225
|
|
|
185
|
-
constructor(kind: Kind, expression: StyleExpression, zoomStops: Array<number>, interpolationType?: InterpolationType, isLightConstant
|
|
226
|
+
constructor(kind: Kind, expression: StyleExpression, zoomStops: Array<number>, interpolationType?: InterpolationType, isLightConstant?: boolean | null) {
|
|
186
227
|
this.kind = kind;
|
|
187
228
|
this.zoomStops = zoomStops;
|
|
188
229
|
this._styleExpression = expression;
|
|
189
|
-
this.isStateDependent = kind !== ('camera'
|
|
230
|
+
this.isStateDependent = kind !== ('camera' as EvaluationKind) && !isConstant.isStateConstant(expression.expression);
|
|
190
231
|
this.isLightConstant = isLightConstant;
|
|
191
232
|
this.isConfigDependent = !isConstant.isConfigConstant(expression.expression);
|
|
192
233
|
this.interpolationType = interpolationType;
|
|
193
234
|
}
|
|
194
235
|
|
|
195
|
-
evaluateWithoutErrorHandling(
|
|
236
|
+
evaluateWithoutErrorHandling(
|
|
237
|
+
globals: GlobalProperties,
|
|
238
|
+
feature?: Feature,
|
|
239
|
+
featureState?: FeatureState,
|
|
240
|
+
canonical?: CanonicalTileID,
|
|
241
|
+
availableImages?: Array<string>,
|
|
242
|
+
formattedSection?: FormattedSection,
|
|
243
|
+
): any {
|
|
196
244
|
return this._styleExpression.evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection);
|
|
197
245
|
}
|
|
198
246
|
|
|
199
|
-
evaluate(
|
|
247
|
+
evaluate(
|
|
248
|
+
globals: GlobalProperties,
|
|
249
|
+
feature?: Feature,
|
|
250
|
+
featureState?: FeatureState,
|
|
251
|
+
canonical?: CanonicalTileID,
|
|
252
|
+
availableImages?: Array<string>,
|
|
253
|
+
formattedSection?: FormattedSection,
|
|
254
|
+
): any {
|
|
200
255
|
return this._styleExpression.evaluate(globals, feature, featureState, canonical, availableImages, formattedSection);
|
|
201
256
|
}
|
|
202
257
|
|
|
@@ -209,53 +264,83 @@ export class ZoomDependentExpression<Kind: EvaluationKind> {
|
|
|
209
264
|
}
|
|
210
265
|
}
|
|
211
266
|
|
|
212
|
-
export type ConstantExpression =
|
|
213
|
-
kind: 'constant'
|
|
214
|
-
isConfigDependent: boolean
|
|
215
|
-
|
|
216
|
-
|
|
267
|
+
export type ConstantExpression = {
|
|
268
|
+
kind: 'constant';
|
|
269
|
+
isConfigDependent: boolean;
|
|
270
|
+
readonly evaluate: (
|
|
271
|
+
globals: GlobalProperties,
|
|
272
|
+
feature?: Feature,
|
|
273
|
+
featureState?: FeatureState,
|
|
274
|
+
canonical?: CanonicalTileID,
|
|
275
|
+
availableImages?: Array<string>,
|
|
276
|
+
) => any;
|
|
277
|
+
};
|
|
217
278
|
|
|
218
|
-
export type SourceExpression =
|
|
219
|
-
kind: 'source'
|
|
220
|
-
isStateDependent: boolean
|
|
221
|
-
isLightConstant:
|
|
222
|
-
isConfigDependent: boolean
|
|
223
|
-
|
|
279
|
+
export type SourceExpression = {
|
|
280
|
+
kind: 'source';
|
|
281
|
+
isStateDependent: boolean;
|
|
282
|
+
isLightConstant: boolean | null | undefined;
|
|
283
|
+
isConfigDependent: boolean;
|
|
284
|
+
readonly evaluate: (
|
|
285
|
+
globals: GlobalProperties,
|
|
286
|
+
feature?: Feature,
|
|
287
|
+
featureState?: FeatureState,
|
|
288
|
+
canonical?: CanonicalTileID,
|
|
289
|
+
availableImages?: Array<string>,
|
|
290
|
+
formattedSection?: FormattedSection,
|
|
291
|
+
) => any;
|
|
224
292
|
};
|
|
225
293
|
|
|
226
|
-
export type CameraExpression =
|
|
227
|
-
kind: 'camera'
|
|
228
|
-
isStateDependent: boolean
|
|
229
|
-
isConfigDependent: boolean
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
294
|
+
export type CameraExpression = {
|
|
295
|
+
kind: 'camera';
|
|
296
|
+
isStateDependent: boolean;
|
|
297
|
+
isConfigDependent: boolean;
|
|
298
|
+
readonly evaluate: (
|
|
299
|
+
globals: GlobalProperties,
|
|
300
|
+
feature?: Feature,
|
|
301
|
+
featureState?: FeatureState,
|
|
302
|
+
canonical?: CanonicalTileID,
|
|
303
|
+
availableImages?: Array<string>,
|
|
304
|
+
) => any;
|
|
305
|
+
readonly interpolationFactor: (input: number, lower: number, upper: number) => number;
|
|
306
|
+
zoomStops: Array<number>;
|
|
307
|
+
interpolationType: InterpolationType | null | undefined;
|
|
234
308
|
};
|
|
235
309
|
|
|
236
310
|
export interface CompositeExpression {
|
|
237
311
|
kind: 'composite';
|
|
238
312
|
isStateDependent: boolean;
|
|
239
|
-
isLightConstant:
|
|
313
|
+
isLightConstant: boolean | null | undefined;
|
|
240
314
|
isConfigDependent: boolean;
|
|
241
|
-
|
|
242
|
-
|
|
315
|
+
readonly evaluate: (
|
|
316
|
+
globals: GlobalProperties,
|
|
317
|
+
feature?: Feature,
|
|
318
|
+
featureState?: FeatureState,
|
|
319
|
+
canonical?: CanonicalTileID,
|
|
320
|
+
availableImages?: Array<string>,
|
|
321
|
+
formattedSection?: FormattedSection,
|
|
322
|
+
) => any;
|
|
323
|
+
readonly interpolationFactor: (input: number, lower: number, upper: number) => number;
|
|
243
324
|
zoomStops: Array<number>;
|
|
244
|
-
interpolationType:
|
|
325
|
+
interpolationType: InterpolationType | null | undefined;
|
|
245
326
|
}
|
|
246
327
|
|
|
247
|
-
export type StylePropertyExpression =
|
|
248
|
-
| ConstantExpression
|
|
249
|
-
| SourceExpression
|
|
250
|
-
| CameraExpression
|
|
251
|
-
| CompositeExpression;
|
|
328
|
+
export type StylePropertyExpression = ConstantExpression | SourceExpression | CameraExpression | CompositeExpression;
|
|
252
329
|
|
|
253
|
-
export function createPropertyExpression(
|
|
330
|
+
export function createPropertyExpression(
|
|
331
|
+
expression: unknown,
|
|
332
|
+
propertySpec: StylePropertySpecification,
|
|
333
|
+
scope?: string | null,
|
|
334
|
+
options?: ConfigOptions | null,
|
|
335
|
+
): Result<StylePropertyExpression, Array<ParsingError>> {
|
|
254
336
|
expression = createExpression(expression, propertySpec, scope, options);
|
|
337
|
+
// @ts-expect-error - TS2339 - Property 'result' does not exist on type 'unknown'.
|
|
255
338
|
if (expression.result === 'error') {
|
|
339
|
+
// @ts-expect-error - TS2322 - Type 'unknown' is not assignable to type 'Result<StylePropertyExpression, ParsingError[]>'.
|
|
256
340
|
return expression;
|
|
257
341
|
}
|
|
258
342
|
|
|
343
|
+
// @ts-expect-error - TS2339 - Property 'value' does not exist on type 'unknown'.
|
|
259
344
|
const parsed = expression.value.expression;
|
|
260
345
|
|
|
261
346
|
const isFeatureConstant = isConstant.isFeatureConstant(parsed);
|
|
@@ -285,23 +370,23 @@ export function createPropertyExpression(expression: mixed, propertySpec: StyleP
|
|
|
285
370
|
|
|
286
371
|
if (!zoomCurve) {
|
|
287
372
|
return success(isFeatureConstant ?
|
|
288
|
-
|
|
289
|
-
(new ZoomConstantExpression('constant', expression.value, isLightConstant)
|
|
290
|
-
|
|
291
|
-
(new ZoomConstantExpression('source', expression.value, isLightConstant)
|
|
373
|
+
// @ts-expect-error - TS2339 - Property 'value' does not exist on type 'unknown'.
|
|
374
|
+
(new ZoomConstantExpression('constant', expression.value, isLightConstant) as ConstantExpression) :
|
|
375
|
+
// @ts-expect-error - TS2339 - Property 'value' does not exist on type 'unknown'.
|
|
376
|
+
(new ZoomConstantExpression('source', expression.value, isLightConstant) as SourceExpression));
|
|
292
377
|
}
|
|
293
378
|
|
|
294
379
|
const interpolationType = zoomCurve instanceof Interpolate ? zoomCurve.interpolation : undefined;
|
|
295
380
|
|
|
296
381
|
return success(isFeatureConstant ?
|
|
297
|
-
|
|
298
|
-
(new ZoomDependentExpression('camera', expression.value, zoomCurve.labels, interpolationType, isLightConstant)
|
|
299
|
-
|
|
300
|
-
(new ZoomDependentExpression('composite', expression.value, zoomCurve.labels, interpolationType, isLightConstant)
|
|
382
|
+
// @ts-expect-error - TS2339 - Property 'value' does not exist on type 'unknown'.
|
|
383
|
+
(new ZoomDependentExpression('camera', expression.value, zoomCurve.labels, interpolationType, isLightConstant) as CameraExpression) :
|
|
384
|
+
// @ts-expect-error - TS2339 - Property 'value' does not exist on type 'unknown'.
|
|
385
|
+
(new ZoomDependentExpression('composite', expression.value, zoomCurve.labels, interpolationType, isLightConstant) as CompositeExpression));
|
|
301
386
|
}
|
|
302
387
|
|
|
303
|
-
import {isFunction, createFunction} from '../function/index
|
|
304
|
-
import {Color} from './values
|
|
388
|
+
import {isFunction, createFunction} from '../function/index';
|
|
389
|
+
import {Color} from './values';
|
|
305
390
|
|
|
306
391
|
// serialization wrapper for old-style stop functions normalized to the
|
|
307
392
|
// expression interface
|
|
@@ -311,8 +396,8 @@ export class StylePropertyFunction<T> {
|
|
|
311
396
|
|
|
312
397
|
kind: EvaluationKind;
|
|
313
398
|
evaluate: (globals: GlobalProperties, feature?: Feature) => any;
|
|
314
|
-
interpolationFactor:
|
|
315
|
-
zoomStops:
|
|
399
|
+
interpolationFactor: (input: number, lower: number, upper: number) => number | null | undefined;
|
|
400
|
+
zoomStops: Array<number> | null | undefined;
|
|
316
401
|
|
|
317
402
|
constructor(parameters: PropertyValueSpecification<T>, specification: StylePropertySpecification) {
|
|
318
403
|
this._parameters = parameters;
|
|
@@ -320,11 +405,19 @@ export class StylePropertyFunction<T> {
|
|
|
320
405
|
extend(this, createFunction(this._parameters, this._specification));
|
|
321
406
|
}
|
|
322
407
|
|
|
323
|
-
static deserialize
|
|
408
|
+
static deserialize<T>(
|
|
409
|
+
serialized: {
|
|
410
|
+
_parameters: PropertyValueSpecification<T>;
|
|
411
|
+
_specification: StylePropertySpecification;
|
|
412
|
+
},
|
|
413
|
+
): StylePropertyFunction<T> {
|
|
324
414
|
return new StylePropertyFunction(serialized._parameters, serialized._specification);
|
|
325
415
|
}
|
|
326
416
|
|
|
327
|
-
static serialize(input: StylePropertyFunction<T>): {
|
|
417
|
+
static serialize<T>(input: StylePropertyFunction<T>): {
|
|
418
|
+
_parameters: PropertyValueSpecification<T>;
|
|
419
|
+
_specification: StylePropertySpecification;
|
|
420
|
+
} {
|
|
328
421
|
return {
|
|
329
422
|
_parameters: input._parameters,
|
|
330
423
|
_specification: input._specification
|
|
@@ -332,9 +425,14 @@ export class StylePropertyFunction<T> {
|
|
|
332
425
|
}
|
|
333
426
|
}
|
|
334
427
|
|
|
335
|
-
export function normalizePropertyExpression<T>(
|
|
428
|
+
export function normalizePropertyExpression<T>(
|
|
429
|
+
value: PropertyValueSpecification<T>,
|
|
430
|
+
specification: StylePropertySpecification,
|
|
431
|
+
scope?: string | null,
|
|
432
|
+
options?: ConfigOptions | null,
|
|
433
|
+
): StylePropertyExpression {
|
|
336
434
|
if (isFunction(value)) {
|
|
337
|
-
return
|
|
435
|
+
return new StylePropertyFunction(value, specification) as any;
|
|
338
436
|
|
|
339
437
|
} else if (isExpression(value) || (Array.isArray(value) && value.length > 0)) {
|
|
340
438
|
const expression = createPropertyExpression(value, specification, scope, options);
|
|
@@ -396,7 +494,7 @@ function findZoomCurve(expression: Expression): Step | Interpolate | ParsingErro
|
|
|
396
494
|
return result;
|
|
397
495
|
}
|
|
398
496
|
|
|
399
|
-
import {ColorType, StringType, NumberType, BooleanType, ValueType, FormattedType, ResolvedImageType, array} from './types
|
|
497
|
+
import {ColorType, StringType, NumberType, BooleanType, ValueType, FormattedType, ResolvedImageType, array} from './types';
|
|
400
498
|
|
|
401
499
|
function getExpectedType(spec: StylePropertySpecification): Type {
|
|
402
500
|
const types = {
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import Config from './definitions/config.js';
|
|
7
|
-
import type {Expression} from './expression.js';
|
|
1
|
+
import CompoundExpression from './compound_expression';
|
|
2
|
+
import Within from './definitions/within';
|
|
3
|
+
import Distance from './definitions/distance';
|
|
4
|
+
import Config from './definitions/config';
|
|
5
|
+
import type {Expression} from './expression';
|
|
8
6
|
|
|
9
7
|
function isFeatureConstant(e: Expression): boolean {
|
|
10
8
|
if (e instanceof CompoundExpression) {
|
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
import
|
|
17
|
-
|
|
18
|
-
import type {
|
|
19
|
-
import type {Type} from './types.js';
|
|
20
|
-
import type {ConfigOptions} from '../../style/properties.js';
|
|
1
|
+
import Scope from './scope';
|
|
2
|
+
import {checkSubtype} from './types';
|
|
3
|
+
import ParsingError from './parsing_error';
|
|
4
|
+
import Literal from './definitions/literal';
|
|
5
|
+
import Assertion from './definitions/assertion';
|
|
6
|
+
import Coercion from './definitions/coercion';
|
|
7
|
+
import EvaluationContext from './evaluation_context';
|
|
8
|
+
import CompoundExpression from './compound_expression';
|
|
9
|
+
import CollatorExpression from './definitions/collator';
|
|
10
|
+
import Within from './definitions/within';
|
|
11
|
+
import Distance from './definitions/distance';
|
|
12
|
+
import Config from './definitions/config';
|
|
13
|
+
import {isGlobalPropertyConstant, isFeatureConstant} from './is_constant';
|
|
14
|
+
import Var from './definitions/var';
|
|
15
|
+
|
|
16
|
+
import type {Expression, ExpressionRegistry} from './expression';
|
|
17
|
+
import type {Type} from './types';
|
|
18
|
+
import type {ConfigOptions} from '../types/config_options';
|
|
21
19
|
|
|
22
20
|
/**
|
|
23
21
|
* State associated parsing at a given point in an expression tree.
|
|
@@ -29,23 +27,23 @@ class ParsingContext {
|
|
|
29
27
|
key: string;
|
|
30
28
|
scope: Scope;
|
|
31
29
|
errors: Array<ParsingError>;
|
|
32
|
-
_scope:
|
|
33
|
-
options:
|
|
30
|
+
_scope: string | null | undefined;
|
|
31
|
+
options: ConfigOptions | null | undefined;
|
|
34
32
|
|
|
35
33
|
// The expected type of this expression. Provided only to allow Expression
|
|
36
34
|
// implementations to infer argument types: Expression#parse() need not
|
|
37
35
|
// check that the output type of the parsed expression matches
|
|
38
36
|
// `expectedType`.
|
|
39
|
-
expectedType:
|
|
37
|
+
expectedType: Type | null | undefined;
|
|
40
38
|
|
|
41
39
|
constructor(
|
|
42
40
|
registry: ExpressionRegistry,
|
|
43
41
|
path: Array<number> = [],
|
|
44
|
-
expectedType
|
|
42
|
+
expectedType?: Type | null,
|
|
45
43
|
scope: Scope = new Scope(),
|
|
46
44
|
errors: Array<ParsingError> = [],
|
|
47
|
-
_scope
|
|
48
|
-
options?:
|
|
45
|
+
_scope?: string | null,
|
|
46
|
+
options?: ConfigOptions | null
|
|
49
47
|
) {
|
|
50
48
|
this.registry = registry;
|
|
51
49
|
this.path = path;
|
|
@@ -65,19 +63,26 @@ class ParsingContext {
|
|
|
65
63
|
* @private
|
|
66
64
|
*/
|
|
67
65
|
parse(
|
|
68
|
-
expr:
|
|
66
|
+
expr: unknown,
|
|
69
67
|
index?: number,
|
|
70
|
-
expectedType?:
|
|
68
|
+
expectedType?: Type | null,
|
|
71
69
|
bindings?: Array<[string, Expression]>,
|
|
72
|
-
options: {
|
|
73
|
-
|
|
70
|
+
options: {
|
|
71
|
+
typeAnnotation?: 'assert' | 'coerce' | 'omit';
|
|
72
|
+
} = {},
|
|
73
|
+
): Expression | null | undefined {
|
|
74
74
|
if (index || expectedType) {
|
|
75
75
|
return this.concat(index, expectedType, bindings)._parse(expr, options);
|
|
76
76
|
}
|
|
77
77
|
return this._parse(expr, options);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
_parse(
|
|
80
|
+
_parse(
|
|
81
|
+
expr: unknown,
|
|
82
|
+
options: {
|
|
83
|
+
typeAnnotation?: 'assert' | 'coerce' | 'omit';
|
|
84
|
+
},
|
|
85
|
+
): Expression | null | undefined {
|
|
81
86
|
if (expr === null || typeof expr === 'string' || typeof expr === 'boolean' || typeof expr === 'number') {
|
|
82
87
|
expr = ['literal', expr];
|
|
83
88
|
}
|
|
@@ -94,6 +99,7 @@ class ParsingContext {
|
|
|
94
99
|
|
|
95
100
|
if (Array.isArray(expr)) {
|
|
96
101
|
if (expr.length === 0) {
|
|
102
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
97
103
|
return this.error(`Expected an array with at least one element. If you wanted a literal array, use ["literal", []].`);
|
|
98
104
|
}
|
|
99
105
|
|
|
@@ -131,7 +137,7 @@ class ParsingContext {
|
|
|
131
137
|
const ec = new EvaluationContext(this._scope, this.options);
|
|
132
138
|
try {
|
|
133
139
|
parsed = new Literal(parsed.type, parsed.evaluate(ec));
|
|
134
|
-
} catch (e) {
|
|
140
|
+
} catch (e: any) {
|
|
135
141
|
this.error(e.message);
|
|
136
142
|
return null;
|
|
137
143
|
}
|
|
@@ -143,10 +149,13 @@ class ParsingContext {
|
|
|
143
149
|
// Try to parse as array
|
|
144
150
|
return Coercion.parse(['to-array', expr], this);
|
|
145
151
|
} else if (typeof expr === 'undefined') {
|
|
152
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
146
153
|
return this.error(`'undefined' value invalid. Use null instead.`);
|
|
147
154
|
} else if (typeof expr === 'object') {
|
|
155
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
148
156
|
return this.error(`Bare objects invalid. Use ["literal", {...}] instead.`);
|
|
149
157
|
} else {
|
|
158
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
150
159
|
return this.error(`Expected an array, but found ${typeof expr} instead.`);
|
|
151
160
|
}
|
|
152
161
|
}
|
|
@@ -159,7 +168,11 @@ class ParsingContext {
|
|
|
159
168
|
* parsing, is copied by reference rather than cloned.
|
|
160
169
|
* @private
|
|
161
170
|
*/
|
|
162
|
-
concat(
|
|
171
|
+
concat(
|
|
172
|
+
index?: number | null,
|
|
173
|
+
expectedType?: Type | null,
|
|
174
|
+
bindings?: Array<[string, Expression]>,
|
|
175
|
+
): ParsingContext {
|
|
163
176
|
const path = typeof index === 'number' ? this.path.concat(index) : this.path;
|
|
164
177
|
const scope = bindings ? this.scope.concat(bindings) : this.scope;
|
|
165
178
|
return new ParsingContext(
|
|
@@ -189,7 +202,7 @@ class ParsingContext {
|
|
|
189
202
|
* Returns null if `t` is a subtype of `expected`; otherwise returns an
|
|
190
203
|
* error message and also pushes it to `this.errors`.
|
|
191
204
|
*/
|
|
192
|
-
checkSubtype(expected: Type, t: Type):
|
|
205
|
+
checkSubtype(expected: Type, t: Type): string | null | undefined {
|
|
193
206
|
const error = checkSubtype(expected, t);
|
|
194
207
|
if (error) this.error(error);
|
|
195
208
|
return error;
|