@mapbox/mapbox-gl-style-spec 14.12.0-beta.1 → 14.12.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/composite.ts +2 -0
- package/deref.ts +5 -5
- package/diff.ts +18 -20
- package/dist/index.cjs +143 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +41 -7
- package/dist/index.es.js +143 -13
- package/dist/index.es.js.map +1 -1
- package/error/validation_error.ts +1 -3
- package/expression/definitions/assertion.ts +2 -1
- package/expression/definitions/at.ts +1 -1
- package/expression/definitions/at_interpolated.ts +1 -1
- package/expression/definitions/case.ts +3 -1
- package/expression/definitions/coalesce.ts +1 -0
- package/expression/definitions/coercion.ts +3 -1
- package/expression/definitions/collator.ts +2 -1
- package/expression/definitions/comparison.ts +15 -1
- package/expression/definitions/config.ts +3 -0
- package/expression/definitions/distance.ts +6 -4
- package/expression/definitions/format.ts +1 -1
- package/expression/definitions/index.ts +21 -0
- package/expression/definitions/index_of.ts +1 -0
- package/expression/definitions/interpolate.ts +5 -1
- package/expression/definitions/let.ts +1 -0
- package/expression/definitions/literal.ts +2 -2
- package/expression/definitions/match.ts +3 -1
- package/expression/definitions/number_format.ts +3 -4
- package/expression/definitions/slice.ts +1 -0
- package/expression/definitions/step.ts +1 -0
- package/expression/definitions/var.ts +1 -0
- package/expression/definitions/within.ts +6 -2
- package/expression/expression.ts +3 -0
- package/expression/index.ts +17 -3
- package/expression/types/image_variant.ts +2 -2
- package/expression/types.ts +1 -0
- package/feature_filter/convert.ts +13 -6
- package/feature_filter/index.ts +16 -0
- package/format.ts +1 -0
- package/function/convert.ts +5 -1
- package/function/index.ts +28 -0
- package/group_by_layout.ts +17 -8
- package/migrate/expressions.ts +2 -2
- package/migrate/v8.ts +9 -0
- package/migrate/v9.ts +1 -0
- package/migrate.ts +1 -0
- package/package.json +1 -1
- package/read_style.ts +1 -0
- package/reference/latest.ts +1 -0
- package/reference/v8.json +116 -11
- package/types.ts +12 -1
- package/union-to-intersection.ts +1 -0
- package/util/extend.ts +1 -0
- package/util/geometry_util.ts +7 -8
- package/validate/validate.ts +6 -0
- package/validate/validate_array.ts +2 -0
- package/validate/validate_enum.ts +1 -0
- package/validate/validate_expression.ts +4 -0
- package/validate/validate_filter.ts +4 -2
- package/validate/validate_fog.ts +3 -0
- package/validate/validate_function.ts +7 -2
- package/validate/validate_iconset.ts +1 -0
- package/validate/validate_layer.ts +1 -0
- package/validate/validate_light.ts +3 -0
- package/validate/validate_lights.ts +6 -0
- package/validate/validate_model.ts +4 -0
- package/validate/validate_object.ts +2 -2
- package/validate/validate_projection.ts +1 -0
- package/validate/validate_property.ts +4 -0
- package/validate/validate_rain.ts +3 -0
- package/validate/validate_snow.ts +3 -0
- package/validate/validate_source.ts +8 -6
- package/validate/validate_terrain.ts +4 -0
- package/validate_mapbox_api_supported.ts +30 -19
- package/validate_style.ts +1 -0
- package/visit.ts +3 -1
|
@@ -5,9 +5,7 @@ export default class ValidationError {
|
|
|
5
5
|
identifier: string | null | undefined;
|
|
6
6
|
line: number | null | undefined;
|
|
7
7
|
|
|
8
|
-
constructor(key: string | null | undefined, value: {
|
|
9
|
-
__line__: number;
|
|
10
|
-
} | null | undefined, message: string, identifier?: string | null) {
|
|
8
|
+
constructor(key: string | null | undefined, value: (string | number | boolean) & {__line__?: number} | null | undefined, message: string, identifier?: string | null) {
|
|
11
9
|
this.message = (key ? `${key}: ` : '') + message;
|
|
12
10
|
if (identifier) this.identifier = identifier;
|
|
13
11
|
|
|
@@ -40,7 +40,7 @@ class Assertion implements Expression {
|
|
|
40
40
|
let i = 1;
|
|
41
41
|
let type;
|
|
42
42
|
|
|
43
|
-
const name
|
|
43
|
+
const name = args[0] as string;
|
|
44
44
|
if (name === 'array') {
|
|
45
45
|
let itemType;
|
|
46
46
|
if (args.length > 2) {
|
|
@@ -82,6 +82,7 @@ class Assertion implements Expression {
|
|
|
82
82
|
return new Assertion(type, parsed);
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
85
86
|
evaluate(ctx: EvaluationContext): any {
|
|
86
87
|
for (let i = 0; i < this.args.length; i++) {
|
|
87
88
|
const value = this.args[i].evaluate(ctx);
|
|
@@ -50,9 +50,10 @@ class Case implements Expression {
|
|
|
50
50
|
if (!otherwise) return null;
|
|
51
51
|
|
|
52
52
|
assert(outputType);
|
|
53
|
-
return new Case(
|
|
53
|
+
return new Case(outputType, branches, otherwise);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
57
|
evaluate(ctx: EvaluationContext): any {
|
|
57
58
|
for (const [test, expression] of this.branches) {
|
|
58
59
|
if (test.evaluate(ctx)) {
|
|
@@ -71,6 +72,7 @@ class Case implements Expression {
|
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
outputDefined(): boolean {
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
74
76
|
return this.branches.every(([_, out]: [any, any]) => out.outputDefined()) && this.otherwise.outputDefined();
|
|
75
77
|
}
|
|
76
78
|
|
|
@@ -40,7 +40,7 @@ class Coercion implements Expression {
|
|
|
40
40
|
if (args.length < 2)
|
|
41
41
|
return context.error(`Expected at least one argument.`);
|
|
42
42
|
|
|
43
|
-
const name
|
|
43
|
+
const name = args[0] as string;
|
|
44
44
|
const parsed = [];
|
|
45
45
|
let type: Type | ArrayType = NullType;
|
|
46
46
|
if (name === 'to-array') {
|
|
@@ -93,6 +93,7 @@ class Coercion implements Expression {
|
|
|
93
93
|
return new Coercion(type, parsed);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
96
97
|
evaluate(ctx: EvaluationContext): any {
|
|
97
98
|
if (this.type.kind === 'boolean') {
|
|
98
99
|
return Boolean(this.args[0].evaluate(ctx));
|
|
@@ -136,6 +137,7 @@ class Coercion implements Expression {
|
|
|
136
137
|
} else if (this.type.kind === 'resolvedImage') {
|
|
137
138
|
return ResolvedImage.build(valueToString(this.args[0].evaluate(ctx)));
|
|
138
139
|
} else if (this.type.kind === 'array') {
|
|
140
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
139
141
|
return this.args.map(arg => { return arg.evaluate(ctx); });
|
|
140
142
|
} else {
|
|
141
143
|
return valueToString(this.args[0].evaluate(ctx));
|
|
@@ -24,7 +24,7 @@ export default class CollatorExpression implements Expression {
|
|
|
24
24
|
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
25
25
|
return context.error(`Expected one argument.`);
|
|
26
26
|
|
|
27
|
-
const options =
|
|
27
|
+
const options = args[1];
|
|
28
28
|
if (typeof options !== "object" || Array.isArray(options))
|
|
29
29
|
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
30
30
|
return context.error(`Collator options argument must be an object.`);
|
|
@@ -69,6 +69,7 @@ export default class CollatorExpression implements Expression {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
serialize(): SerializedExpression {
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
72
73
|
const options: Record<string, any> = {};
|
|
73
74
|
options['case-sensitive'] = this.caseSensitive.serialize();
|
|
74
75
|
options['diacritic-sensitive'] = this.diacriticSensitive.serialize();
|
|
@@ -26,18 +26,30 @@ function isComparableType(op: ComparisonOperator, type: Type) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
30
|
function eq(ctx: EvaluationContext, a: any, b: any): boolean { return a === b; }
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
32
|
function neq(ctx: EvaluationContext, a: any, b: any): boolean { return a !== b; }
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
34
|
function lt(ctx: EvaluationContext, a: any, b: any): boolean { return a < b; }
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
36
|
function gt(ctx: EvaluationContext, a: any, b: any): boolean { return a > b; }
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
38
|
function lteq(ctx: EvaluationContext, a: any, b: any): boolean { return a <= b; }
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
40
|
function gteq(ctx: EvaluationContext, a: any, b: any): boolean { return a >= b; }
|
|
35
41
|
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
43
|
function eqCollate(ctx: EvaluationContext, a: any, b: any, c: any): boolean { return c.compare(a, b) === 0; }
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
45
|
function neqCollate(ctx: EvaluationContext, a: any, b: any, c: any): boolean { return !eqCollate(ctx, a, b, c); }
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
47
|
function ltCollate(ctx: EvaluationContext, a: any, b: any, c: any): boolean { return c.compare(a, b) < 0; }
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
49
|
function gtCollate(ctx: EvaluationContext, a: any, b: any, c: any): boolean { return c.compare(a, b) > 0; }
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
51
|
function lteqCollate(ctx: EvaluationContext, a: any, b: any, c: any): boolean { return c.compare(a, b) <= 0; }
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
53
|
function gteqCollate(ctx: EvaluationContext, a: any, b: any, c: any): boolean { return c.compare(a, b) >= 0; }
|
|
42
54
|
|
|
43
55
|
/**
|
|
@@ -59,7 +71,9 @@ function gteqCollate(ctx: EvaluationContext, a: any, b: any, c: any): boolean {
|
|
|
59
71
|
*/
|
|
60
72
|
function makeComparison(
|
|
61
73
|
op: ComparisonOperator,
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
62
75
|
compareBasic: (arg1: EvaluationContext, arg2?: any, arg3?: any) => boolean,
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
63
77
|
compareWithCollator: (arg1: EvaluationContext, arg2?: any, arg3?: any, arg4?: any) => boolean,
|
|
64
78
|
): ExpressionRegistration {
|
|
65
79
|
const isOrderComparison = op !== '==' && op !== '!=';
|
|
@@ -83,7 +97,7 @@ function makeComparison(
|
|
|
83
97
|
if (args.length !== 3 && args.length !== 4)
|
|
84
98
|
return context.error(`Expected two or three arguments.`);
|
|
85
99
|
|
|
86
|
-
const op
|
|
100
|
+
const op = args[0] as ComparisonOperator;
|
|
87
101
|
|
|
88
102
|
let lhs = context.parse(args[1], 1, ValueType);
|
|
89
103
|
if (!lhs) return null;
|
|
@@ -9,6 +9,7 @@ import type {Expression, SerializedExpression} from '../expression';
|
|
|
9
9
|
import type ParsingContext from '../parsing_context';
|
|
10
10
|
import type EvaluationContext from '../evaluation_context';
|
|
11
11
|
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
13
|
function coerceValue(type: string, value: any): any {
|
|
13
14
|
switch (type) {
|
|
14
15
|
case 'string': return valueToString(value);
|
|
@@ -74,6 +75,7 @@ class Config implements Expression {
|
|
|
74
75
|
return new Config(type, valueToString(configKey.value));
|
|
75
76
|
}
|
|
76
77
|
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
79
|
evaluate(ctx: EvaluationContext): any {
|
|
78
80
|
const FQIDSeparator = '\u001F';
|
|
79
81
|
const configKey = [this.key, this.scope, ctx.scope].filter(Boolean).join(FQIDSeparator);
|
|
@@ -101,6 +103,7 @@ class Config implements Expression {
|
|
|
101
103
|
if (typeof result === 'number') {
|
|
102
104
|
result = clampToAllowedNumber(result, minValue, maxValue, stepValue);
|
|
103
105
|
} else if (Array.isArray(result)) {
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
104
107
|
result = result.map((item) => (typeof item === 'number' ? clampToAllowedNumber(item, minValue, maxValue, stepValue) : item));
|
|
105
108
|
}
|
|
106
109
|
}
|
|
@@ -147,6 +147,7 @@ function getLngLatPoints(coordinates: Array<Point>, canonical: CanonicalTileID)
|
|
|
147
147
|
for (let i = 0; i < coordinates.length; ++i) {
|
|
148
148
|
coords.push(getLngLatPoint(coordinates[i], canonical));
|
|
149
149
|
}
|
|
150
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
150
151
|
return coords;
|
|
151
152
|
}
|
|
152
153
|
|
|
@@ -275,6 +276,7 @@ function polygonToPolygonDistance(polygon1: Array<Array<[number, number]>>, poly
|
|
|
275
276
|
return dist;
|
|
276
277
|
}
|
|
277
278
|
|
|
279
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
278
280
|
function updateQueue(distQueue: any, miniDist: number, ruler: CheapRuler, pointSet1: Array<[number, number]>, pointSet2: Array<[number, number]>, r1: IndexRange | null, r2: IndexRange | null) {
|
|
279
281
|
if (r1 === null || r2 === null) return;
|
|
280
282
|
const tempDist = bboxToBBoxDistance(getBBox(pointSet1, r1), getBBox(pointSet2, r2), ruler);
|
|
@@ -527,19 +529,19 @@ class Distance implements Expression {
|
|
|
527
529
|
return context.error(`'distance' expression requires either one argument, but found ' ${args.length - 1} instead.`);
|
|
528
530
|
}
|
|
529
531
|
if (isValue(args[1])) {
|
|
530
|
-
const geojson =
|
|
532
|
+
const geojson = args[1] as GeoJSON.GeoJSON;
|
|
531
533
|
if (geojson.type === 'FeatureCollection') {
|
|
532
534
|
for (let i = 0; i < geojson.features.length; ++i) {
|
|
533
535
|
if (isTypeValid(geojson.features[i].geometry.type)) {
|
|
534
|
-
return new Distance(geojson, geojson.features[i].geometry);
|
|
536
|
+
return new Distance(geojson, geojson.features[i].geometry as DistanceGeometry);
|
|
535
537
|
}
|
|
536
538
|
}
|
|
537
539
|
} else if (geojson.type === 'Feature') {
|
|
538
540
|
if (isTypeValid(geojson.geometry.type)) {
|
|
539
|
-
return new Distance(geojson, geojson.geometry);
|
|
541
|
+
return new Distance(geojson, geojson.geometry as DistanceGeometry);
|
|
540
542
|
}
|
|
541
543
|
} else if (isTypeValid(geojson.type)) {
|
|
542
|
-
return new Distance(geojson, geojson);
|
|
544
|
+
return new Distance(geojson, geojson as DistanceGeometry);
|
|
543
545
|
}
|
|
544
546
|
}
|
|
545
547
|
return context.error(
|
|
@@ -46,7 +46,7 @@ export default class FormatExpression implements Expression {
|
|
|
46
46
|
const sections: Array<FormattedSectionExpression> = [];
|
|
47
47
|
let nextTokenMayBeObject = false;
|
|
48
48
|
for (let i = 1; i <= args.length - 1; ++i) {
|
|
49
|
-
const arg =
|
|
49
|
+
const arg = args[i];
|
|
50
50
|
|
|
51
51
|
if (nextTokenMayBeObject && typeof arg === "object" && !Array.isArray(arg)) {
|
|
52
52
|
nextTokenMayBeObject = false;
|
|
@@ -121,6 +121,7 @@ function hsla(ctx: EvaluationContext, [h, s, l, a]: Expression[]) {
|
|
|
121
121
|
function has(
|
|
122
122
|
key: string,
|
|
123
123
|
obj: {
|
|
124
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
124
125
|
[key: string]: any;
|
|
125
126
|
},
|
|
126
127
|
): boolean {
|
|
@@ -128,13 +129,17 @@ function has(
|
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
function get(key: string, obj: {
|
|
132
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
131
133
|
[key: string]: any;
|
|
132
134
|
}) {
|
|
133
135
|
const v = obj[key];
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
134
137
|
return typeof v === 'undefined' ? null : v;
|
|
135
138
|
}
|
|
136
139
|
|
|
140
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
137
141
|
function binarySearch(v: any, a: {
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
138
143
|
[key: number]: any;
|
|
139
144
|
}, i: number, j: number) {
|
|
140
145
|
while (i <= j) {
|
|
@@ -181,6 +186,7 @@ CompoundExpression.register(expressions, {
|
|
|
181
186
|
array(NumberType, 4),
|
|
182
187
|
[ColorType],
|
|
183
188
|
(ctx, [v]) => {
|
|
189
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
184
190
|
return v.evaluate(ctx).toRenderColor(null).toArray();
|
|
185
191
|
}
|
|
186
192
|
],
|
|
@@ -188,6 +194,7 @@ CompoundExpression.register(expressions, {
|
|
|
188
194
|
array(NumberType, 4),
|
|
189
195
|
[ColorType],
|
|
190
196
|
(ctx, [v]) => {
|
|
197
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
191
198
|
return v.evaluate(ctx).toRenderColor(null).toHslaArray();
|
|
192
199
|
}
|
|
193
200
|
],
|
|
@@ -228,9 +235,11 @@ CompoundExpression.register(expressions, {
|
|
|
228
235
|
overloads: [
|
|
229
236
|
[
|
|
230
237
|
[StringType],
|
|
238
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
231
239
|
(ctx, [key]) => get(key.evaluate(ctx), ctx.properties())
|
|
232
240
|
], [
|
|
233
241
|
[StringType, ObjectType],
|
|
242
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
234
243
|
(ctx, [key, obj]) => get(key.evaluate(ctx), obj.evaluate(ctx))
|
|
235
244
|
]
|
|
236
245
|
]
|
|
@@ -238,6 +247,7 @@ CompoundExpression.register(expressions, {
|
|
|
238
247
|
'feature-state': [
|
|
239
248
|
ValueType,
|
|
240
249
|
[StringType],
|
|
250
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
241
251
|
(ctx, [key]) => get(key.evaluate(ctx), ctx.featureState || {})
|
|
242
252
|
],
|
|
243
253
|
'properties': [
|
|
@@ -422,11 +432,13 @@ CompoundExpression.register(expressions, {
|
|
|
422
432
|
'min': [
|
|
423
433
|
NumberType,
|
|
424
434
|
varargs(NumberType),
|
|
435
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
425
436
|
(ctx, args) => Math.min(...args.map(arg => arg.evaluate(ctx)))
|
|
426
437
|
],
|
|
427
438
|
'max': [
|
|
428
439
|
NumberType,
|
|
429
440
|
varargs(NumberType),
|
|
441
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
430
442
|
(ctx, args) => Math.max(...args.map(arg => arg.evaluate(ctx)))
|
|
431
443
|
],
|
|
432
444
|
'abs': [
|
|
@@ -579,6 +591,7 @@ CompoundExpression.register(expressions, {
|
|
|
579
591
|
overloads: [
|
|
580
592
|
[
|
|
581
593
|
[BooleanType, BooleanType],
|
|
594
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
582
595
|
(ctx, [a, b]) => a.evaluate(ctx) && b.evaluate(ctx)
|
|
583
596
|
],
|
|
584
597
|
[
|
|
@@ -598,6 +611,7 @@ CompoundExpression.register(expressions, {
|
|
|
598
611
|
overloads: [
|
|
599
612
|
[
|
|
600
613
|
[BooleanType, BooleanType],
|
|
614
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
601
615
|
(ctx, [a, b]) => a.evaluate(ctx) || b.evaluate(ctx)
|
|
602
616
|
],
|
|
603
617
|
[
|
|
@@ -632,11 +646,13 @@ CompoundExpression.register(expressions, {
|
|
|
632
646
|
'upcase': [
|
|
633
647
|
StringType,
|
|
634
648
|
[StringType],
|
|
649
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
635
650
|
(ctx, [s]) => s.evaluate(ctx).toUpperCase()
|
|
636
651
|
],
|
|
637
652
|
'downcase': [
|
|
638
653
|
StringType,
|
|
639
654
|
[StringType],
|
|
655
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
640
656
|
(ctx, [s]) => s.evaluate(ctx).toLowerCase()
|
|
641
657
|
],
|
|
642
658
|
'concat': [
|
|
@@ -647,17 +663,21 @@ CompoundExpression.register(expressions, {
|
|
|
647
663
|
'resolved-locale': [
|
|
648
664
|
StringType,
|
|
649
665
|
[CollatorType],
|
|
666
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
650
667
|
(ctx, [collator]) => collator.evaluate(ctx).resolvedLocale()
|
|
651
668
|
],
|
|
652
669
|
'random': [
|
|
653
670
|
NumberType,
|
|
654
671
|
[NumberType, NumberType, ValueType],
|
|
655
672
|
(ctx, args) => {
|
|
673
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
656
674
|
const [min, max, seed] = args.map(arg => arg.evaluate(ctx));
|
|
657
675
|
if (min > max) {
|
|
676
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
658
677
|
return min;
|
|
659
678
|
}
|
|
660
679
|
if (min === max) {
|
|
680
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
661
681
|
return min;
|
|
662
682
|
}
|
|
663
683
|
let seedVal;
|
|
@@ -669,6 +689,7 @@ CompoundExpression.register(expressions, {
|
|
|
669
689
|
throw new RuntimeError(`Invalid seed input: ${seed}`);
|
|
670
690
|
}
|
|
671
691
|
const random = mulberry32(seedVal)();
|
|
692
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
672
693
|
return min + random * (max - min);
|
|
673
694
|
}
|
|
674
695
|
],
|
|
@@ -157,16 +157,19 @@ class Interpolate implements Expression {
|
|
|
157
157
|
const outputs = this.outputs;
|
|
158
158
|
|
|
159
159
|
if (labels.length === 1) {
|
|
160
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
160
161
|
return outputs[0].evaluate(ctx);
|
|
161
162
|
}
|
|
162
163
|
|
|
163
164
|
const value = (this.input.evaluate(ctx) as number);
|
|
164
165
|
if (value <= labels[0]) {
|
|
166
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
165
167
|
return outputs[0].evaluate(ctx);
|
|
166
168
|
}
|
|
167
169
|
|
|
168
170
|
const stopCount = labels.length;
|
|
169
171
|
if (value >= labels[stopCount - 1]) {
|
|
172
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
170
173
|
return outputs[stopCount - 1].evaluate(ctx);
|
|
171
174
|
}
|
|
172
175
|
|
|
@@ -179,7 +182,8 @@ class Interpolate implements Expression {
|
|
|
179
182
|
const outputUpper = outputs[index + 1].evaluate(ctx);
|
|
180
183
|
|
|
181
184
|
if (this.operator === 'interpolate') {
|
|
182
|
-
|
|
185
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
186
|
+
return interpolate[this.type.kind.toLowerCase()](outputLower, outputUpper, t);
|
|
183
187
|
} else if (this.operator === 'interpolate-hcl') {
|
|
184
188
|
return hcl.reverse(hcl.interpolate(hcl.forward(outputLower), hcl.forward(outputUpper), t));
|
|
185
189
|
} else {
|
|
@@ -23,7 +23,7 @@ class Literal implements Expression {
|
|
|
23
23
|
if (!isValue(args[1]))
|
|
24
24
|
return context.error(`invalid value`);
|
|
25
25
|
|
|
26
|
-
const value =
|
|
26
|
+
const value = args[1] as Value;
|
|
27
27
|
let type = typeOf(value);
|
|
28
28
|
|
|
29
29
|
// special case: infer the item type if possible for zero-length arrays
|
|
@@ -67,7 +67,7 @@ class Literal implements Expression {
|
|
|
67
67
|
typeof this.value === 'string' ||
|
|
68
68
|
typeof this.value === 'number' ||
|
|
69
69
|
typeof this.value === 'boolean');
|
|
70
|
-
return this.value as
|
|
70
|
+
return this.value as SerializedExpression;
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
}
|
|
@@ -39,6 +39,7 @@ class Match implements Expression {
|
|
|
39
39
|
if (context.expectedType && context.expectedType.kind !== 'value') {
|
|
40
40
|
outputType = context.expectedType;
|
|
41
41
|
}
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
43
|
const cases: Record<string, any> = {};
|
|
43
44
|
const outputs = [];
|
|
44
45
|
for (let i = 2; i < args.length - 1; i += 2) {
|
|
@@ -94,9 +95,10 @@ class Match implements Expression {
|
|
|
94
95
|
return null;
|
|
95
96
|
}
|
|
96
97
|
|
|
97
|
-
return new Match(
|
|
98
|
+
return new Match(inputType, outputType, input, cases, outputs, otherwise);
|
|
98
99
|
}
|
|
99
100
|
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
100
102
|
evaluate(ctx: EvaluationContext): any {
|
|
101
103
|
const input = (this.input.evaluate(ctx));
|
|
102
104
|
const output = (typeOf(input) === this.inputType && this.outputs[this.cases[input]]) || this.otherwise;
|
|
@@ -29,17 +29,15 @@ export default class NumberFormat implements Expression {
|
|
|
29
29
|
this.maxFractionDigits = maxFractionDigits;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Expression |
|
|
32
|
+
static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Expression | void {
|
|
33
33
|
if (args.length !== 3)
|
|
34
|
-
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
35
34
|
return context.error(`Expected two arguments.`);
|
|
36
35
|
|
|
37
36
|
const number = context.parse(args[1], 1, NumberType);
|
|
38
37
|
if (!number) return null;
|
|
39
38
|
|
|
40
|
-
const options =
|
|
39
|
+
const options = args[2];
|
|
41
40
|
if (typeof options !== "object" || Array.isArray(options))
|
|
42
|
-
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
43
41
|
return context.error(`NumberFormat options argument must be an object.`);
|
|
44
42
|
|
|
45
43
|
let locale = null;
|
|
@@ -113,6 +111,7 @@ export default class NumberFormat implements Expression {
|
|
|
113
111
|
}
|
|
114
112
|
|
|
115
113
|
serialize(): SerializedExpression {
|
|
114
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
116
115
|
const options: Record<string, any> = {};
|
|
117
116
|
if (this.locale) {
|
|
118
117
|
options['locale'] = this.locale.serialize();
|
|
@@ -54,6 +54,7 @@ class Slice implements Expression {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
58
|
evaluate(ctx: EvaluationContext): any {
|
|
58
59
|
const input = (this.input.evaluate(ctx));
|
|
59
60
|
const beginIndex = (this.beginIndex.evaluate(ctx) as number);
|
|
@@ -85,6 +85,7 @@ function getTilePolygon(coordinates: Array<Array<GeoJSON.Position>>, bbox: BBox,
|
|
|
85
85
|
}
|
|
86
86
|
polygon.push(ring);
|
|
87
87
|
}
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
88
89
|
return polygon;
|
|
89
90
|
}
|
|
90
91
|
|
|
@@ -94,6 +95,7 @@ function getTilePolygons(coordinates: Array<Array<Array<GeoJSON.Position>>>, bbo
|
|
|
94
95
|
const polygon = getTilePolygon(coordinates[i], bbox, canonical);
|
|
95
96
|
polygons.push(polygon);
|
|
96
97
|
}
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
97
99
|
return polygons;
|
|
98
100
|
}
|
|
99
101
|
|
|
@@ -118,6 +120,7 @@ function getTilePoints(geometry: Array<Array<Point>> | null | undefined, pointBB
|
|
|
118
120
|
const worldSize = Math.pow(2, canonical.z) * EXTENT;
|
|
119
121
|
const shifts = [canonical.x * EXTENT, canonical.y * EXTENT];
|
|
120
122
|
const tilePoints = [];
|
|
123
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
121
124
|
if (!geometry) return tilePoints;
|
|
122
125
|
for (const points of geometry) {
|
|
123
126
|
for (const point of points) {
|
|
@@ -126,6 +129,7 @@ function getTilePoints(geometry: Array<Array<Point>> | null | undefined, pointBB
|
|
|
126
129
|
tilePoints.push(p);
|
|
127
130
|
}
|
|
128
131
|
}
|
|
132
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
129
133
|
return tilePoints;
|
|
130
134
|
}
|
|
131
135
|
|
|
@@ -230,12 +234,12 @@ class Within implements Expression {
|
|
|
230
234
|
if (args.length !== 2)
|
|
231
235
|
return context.error(`'within' expression requires exactly one argument, but found ${args.length - 1} instead.`);
|
|
232
236
|
if (isValue(args[1])) {
|
|
233
|
-
const geojson =
|
|
237
|
+
const geojson = args[1] as GeoJSON.GeoJSON;
|
|
234
238
|
if (geojson.type === 'FeatureCollection') {
|
|
235
239
|
for (let i = 0; i < geojson.features.length; ++i) {
|
|
236
240
|
const type = geojson.features[i].geometry.type;
|
|
237
241
|
if (type === 'Polygon' || type === 'MultiPolygon') {
|
|
238
|
-
return new Within(geojson, geojson.features[i].geometry);
|
|
242
|
+
return new Within(geojson, geojson.features[i].geometry as GeoJSONPolygons);
|
|
239
243
|
}
|
|
240
244
|
}
|
|
241
245
|
} else if (geojson.type === 'Feature') {
|
package/expression/expression.ts
CHANGED
|
@@ -6,7 +6,9 @@ export type SerializedExpression = Array<unknown> | Array<string> | string | num
|
|
|
6
6
|
|
|
7
7
|
export interface Expression {
|
|
8
8
|
readonly type: Type;
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
10
|
value?: any;
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
12
|
evaluate: (ctx: EvaluationContext) => any;
|
|
11
13
|
eachChild: (fn: (arg1: Expression) => void) => void;
|
|
12
14
|
/**
|
|
@@ -20,6 +22,7 @@ export interface Expression {
|
|
|
20
22
|
export type ExpressionParser = (args: ReadonlyArray<unknown>, context: ParsingContext) => Expression | void;
|
|
21
23
|
|
|
22
24
|
export type ExpressionRegistration = {
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
26
|
new(...args: any[]): Expression;
|
|
24
27
|
readonly parse: ExpressionParser;
|
|
25
28
|
_classRegistryKey?: string;
|