@mapbox/mapbox-gl-style-spec 14.35.0-rc.1 → 14.36.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +145 -162
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +11 -6
- package/dist/index.es.js +145 -162
- package/dist/index.es.js.map +1 -1
- package/expression/definitions/assertion.ts +1 -2
- package/expression/definitions/case.ts +1 -2
- package/expression/definitions/coalesce.ts +2 -4
- package/expression/definitions/coercion.ts +5 -10
- package/expression/definitions/comparison.ts +14 -25
- package/expression/definitions/config.ts +1 -2
- package/expression/definitions/distance.ts +1 -0
- package/expression/definitions/index.ts +12 -21
- package/expression/definitions/interpolate.ts +1 -2
- package/expression/definitions/let.ts +1 -2
- package/expression/definitions/match.ts +2 -4
- package/expression/definitions/number_format.ts +1 -2
- package/expression/definitions/slice.ts +1 -2
- package/expression/definitions/step.ts +1 -2
- package/expression/definitions/var.ts +1 -2
- package/expression/definitions/within.ts +1 -0
- package/expression/expression.ts +5 -0
- package/expression/is_constant.ts +1 -12
- package/feature_filter/convert.ts +2 -4
- package/feature_filter/index.ts +14 -35
- package/package.json +1 -1
- package/reference/v8.json +3 -3
- package/validate/validate_expression.ts +1 -7
- package/validate/validate_source.ts +1 -2
- package/validate_mapbox_api_supported.ts +1 -1
- package/validate_style.ts +1 -1
|
@@ -82,8 +82,7 @@ class Assertion implements Expression {
|
|
|
82
82
|
return new Assertion(type, parsed);
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
evaluate(ctx: EvaluationContext): any {
|
|
85
|
+
evaluate(ctx: EvaluationContext): unknown {
|
|
87
86
|
for (let i = 0; i < this.args.length; i++) {
|
|
88
87
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
89
88
|
const value = this.args[i]!.evaluate(ctx);
|
|
@@ -55,8 +55,7 @@ class Case implements Expression {
|
|
|
55
55
|
return new Case(outputType, branches, otherwise);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
evaluate(ctx: EvaluationContext): any {
|
|
58
|
+
evaluate(ctx: EvaluationContext): unknown {
|
|
60
59
|
for (const [test, expression] of this.branches) {
|
|
61
60
|
if (test.evaluate(ctx)) {
|
|
62
61
|
return expression.evaluate(ctx);
|
|
@@ -49,14 +49,12 @@ class Coalesce implements Expression {
|
|
|
49
49
|
new Coalesce(outputType, parsedArgs);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
let result = null;
|
|
52
|
+
evaluate(ctx: EvaluationContext): unknown {
|
|
53
|
+
let result: unknown = null;
|
|
55
54
|
let argCount = 0;
|
|
56
55
|
let firstImage: ResolvedImage | undefined;
|
|
57
56
|
for (const arg of this.args) {
|
|
58
57
|
argCount++;
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
60
58
|
result = arg.evaluate(ctx);
|
|
61
59
|
// we need to keep track of the first requested image in a coalesce statement
|
|
62
60
|
// if coalesce can't find a valid image, we return the first image so styleimagemissing can fire
|
|
@@ -63,8 +63,7 @@ class Coercion implements Expression {
|
|
|
63
63
|
return null;
|
|
64
64
|
}
|
|
65
65
|
for (let i = 0; i < arrayLength; i++) {
|
|
66
|
-
|
|
67
|
-
const member = args[1][i];
|
|
66
|
+
const member: unknown = args[1][i];
|
|
68
67
|
let parsedMember: Expression | null | void;
|
|
69
68
|
if (Array.isArray(member)) {
|
|
70
69
|
parsedMember = context.parse(member, undefined, type.itemType);
|
|
@@ -96,16 +95,13 @@ class Coercion implements Expression {
|
|
|
96
95
|
return new Coercion(type, parsed);
|
|
97
96
|
}
|
|
98
97
|
|
|
99
|
-
|
|
100
|
-
evaluate(ctx: EvaluationContext): any {
|
|
98
|
+
evaluate(ctx: EvaluationContext): unknown {
|
|
101
99
|
if (this.type.kind === 'boolean') {
|
|
102
100
|
return Boolean(this.args[0]!.evaluate(ctx));
|
|
103
101
|
} else if (this.type.kind === 'color') {
|
|
104
|
-
|
|
105
|
-
let
|
|
106
|
-
let error!: string | null;
|
|
102
|
+
let input: unknown;
|
|
103
|
+
let error: string | null = null;
|
|
107
104
|
for (const arg of this.args) {
|
|
108
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
109
105
|
input = arg.evaluate(ctx);
|
|
110
106
|
error = null;
|
|
111
107
|
if (input instanceof Color) {
|
|
@@ -127,9 +123,8 @@ class Coercion implements Expression {
|
|
|
127
123
|
}
|
|
128
124
|
throw new RuntimeError(error || `Could not parse color from value '${typeof input === 'string' ? input : String(JSON.stringify(input))}'`);
|
|
129
125
|
} else if (this.type.kind === 'number') {
|
|
130
|
-
let value = null;
|
|
126
|
+
let value: unknown = null;
|
|
131
127
|
for (const arg of this.args) {
|
|
132
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
133
128
|
value = arg.evaluate(ctx);
|
|
134
129
|
if (value === null) return 0;
|
|
135
130
|
const num = Number(value);
|
|
@@ -7,6 +7,7 @@ import type {Expression, SerializedExpression, ExpressionRegistration} from '../
|
|
|
7
7
|
import type EvaluationContext from '../evaluation_context';
|
|
8
8
|
import type ParsingContext from '../parsing_context';
|
|
9
9
|
import type {Type} from '../types';
|
|
10
|
+
import type Collator from '../types/collator';
|
|
10
11
|
|
|
11
12
|
type ComparisonOperator = '==' | '!=' | '<' | '>' | '<=' | '>=';
|
|
12
13
|
|
|
@@ -26,31 +27,19 @@ function isComparableType(op: ComparisonOperator, type: Type) {
|
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
function
|
|
37
|
-
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
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
|
|
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, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
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, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
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, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
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, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
53
|
-
function gteqCollate(ctx: EvaluationContext, a: any, b: any, c: any): boolean { return c.compare(a, b) >= 0; }
|
|
30
|
+
function eq(ctx: EvaluationContext, a: unknown, b: unknown): boolean { return a === b; }
|
|
31
|
+
function neq(ctx: EvaluationContext, a: unknown, b: unknown): boolean { return a !== b; }
|
|
32
|
+
function lt(ctx: EvaluationContext, a: string | number, b: string | number): boolean { return a < b; }
|
|
33
|
+
function gt(ctx: EvaluationContext, a: string | number, b: string | number): boolean { return a > b; }
|
|
34
|
+
function lteq(ctx: EvaluationContext, a: string | number, b: string | number): boolean { return a <= b; }
|
|
35
|
+
function gteq(ctx: EvaluationContext, a: string | number, b: string | number): boolean { return a >= b; }
|
|
36
|
+
|
|
37
|
+
function eqCollate(ctx: EvaluationContext, a: string, b: string, c: Collator): boolean { return c.compare(a, b) === 0; }
|
|
38
|
+
function neqCollate(ctx: EvaluationContext, a: string, b: string, c: Collator): boolean { return !eqCollate(ctx, a, b, c); }
|
|
39
|
+
function ltCollate(ctx: EvaluationContext, a: string, b: string, c: Collator): boolean { return c.compare(a, b) < 0; }
|
|
40
|
+
function gtCollate(ctx: EvaluationContext, a: string, b: string, c: Collator): boolean { return c.compare(a, b) > 0; }
|
|
41
|
+
function lteqCollate(ctx: EvaluationContext, a: string, b: string, c: Collator): boolean { return c.compare(a, b) <= 0; }
|
|
42
|
+
function gteqCollate(ctx: EvaluationContext, a: string, b: string, c: Collator): boolean { return c.compare(a, b) >= 0; }
|
|
54
43
|
|
|
55
44
|
/**
|
|
56
45
|
* Special form for comparison operators, implementing the signatures:
|
|
@@ -102,8 +102,7 @@ class Config implements Expression {
|
|
|
102
102
|
return new Config(type, configKeyValue, configScopeValue, featureConstant);
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
evaluate(ctx: EvaluationContext): any {
|
|
105
|
+
evaluate(ctx: EvaluationContext): unknown {
|
|
107
106
|
const fqid = makeConfigFQID(this.key, this.scope, ctx.scope);
|
|
108
107
|
const config = ctx.getConfig(fqid);
|
|
109
108
|
if (!config) return null;
|
|
@@ -623,6 +623,7 @@ function extractDistanceGeometry(value: unknown): Array<DistanceGeometry> | null
|
|
|
623
623
|
class Distance implements Expression {
|
|
624
624
|
type: Type;
|
|
625
625
|
geojson: Expression;
|
|
626
|
+
readonly featureConstant = false;
|
|
626
627
|
|
|
627
628
|
constructor(geojson: Expression) {
|
|
628
629
|
this.type = NumberType;
|
|
@@ -95,32 +95,23 @@ const expressions: ExpressionRegistry = Object.assign(Object.create(null) as Exp
|
|
|
95
95
|
});
|
|
96
96
|
|
|
97
97
|
function rgba(ctx: EvaluationContext, [r, g, b, a]: Expression[]) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
b = b!.evaluate(ctx);
|
|
104
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
105
|
-
const alpha = a ? a.evaluate(ctx) : 1;
|
|
106
|
-
const error = validateRGBA(r, g, b, alpha);
|
|
98
|
+
const red: unknown = r!.evaluate(ctx);
|
|
99
|
+
const green: unknown = g!.evaluate(ctx);
|
|
100
|
+
const blue: unknown = b!.evaluate(ctx);
|
|
101
|
+
const alpha: unknown = a ? a.evaluate(ctx) : 1;
|
|
102
|
+
const error = validateRGBA(red, green, blue, alpha);
|
|
107
103
|
if (error) throw new RuntimeError(error);
|
|
108
|
-
|
|
109
|
-
return new Color(r as unknown as number / 255, g as unknown as number / 255, b as unknown as number / 255, alpha);
|
|
104
|
+
return new Color(red as number / 255, green as number / 255, blue as number / 255, alpha as number);
|
|
110
105
|
}
|
|
111
106
|
|
|
112
107
|
function hsla(ctx: EvaluationContext, [h, s, l, a]: Expression[]) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
l = l!.evaluate(ctx);
|
|
119
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
120
|
-
const alpha = a ? a.evaluate(ctx) : 1;
|
|
121
|
-
const error = validateHSLA(h, s, l, alpha);
|
|
108
|
+
const hValue: unknown = h!.evaluate(ctx);
|
|
109
|
+
const sValue: unknown = s!.evaluate(ctx);
|
|
110
|
+
const lValue: unknown = l!.evaluate(ctx);
|
|
111
|
+
const alpha: unknown = a ? a.evaluate(ctx) : 1;
|
|
112
|
+
const error = validateHSLA(hValue, sValue, lValue, alpha);
|
|
122
113
|
if (error) throw new RuntimeError(error);
|
|
123
|
-
const hue = (
|
|
114
|
+
const hue = (hValue as number) % 360 / 360, sat = (sValue as number) / 100, lum = (lValue as number) / 100;
|
|
124
115
|
const m2 = lum <= 0.5 ? lum * (sat + 1) : lum + sat - lum * sat;
|
|
125
116
|
const m1 = lum * 2 - m2;
|
|
126
117
|
return new Color(hueToByte(m1, m2, hue + 1 / 3), hueToByte(m1, m2, hue), hueToByte(m1, m2, hue - 1 / 3), alpha as number);
|
|
@@ -73,8 +73,7 @@ class Interpolate implements Expression {
|
|
|
73
73
|
if (interpolation[0] === 'linear') {
|
|
74
74
|
interpolation = {name: 'linear'};
|
|
75
75
|
} else if (interpolation[0] === 'exponential') {
|
|
76
|
-
|
|
77
|
-
const base = interpolation[1];
|
|
76
|
+
const base: unknown = interpolation[1];
|
|
78
77
|
if (typeof base !== 'number')
|
|
79
78
|
return context.error(`Exponential interpolation requires a numeric base.`, 1, 1);
|
|
80
79
|
interpolation = {
|
|
@@ -16,8 +16,7 @@ class Let implements Expression {
|
|
|
16
16
|
this.result = result;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
evaluate(ctx: EvaluationContext): any {
|
|
19
|
+
evaluate(ctx: EvaluationContext): unknown {
|
|
21
20
|
return this.result.evaluate(ctx);
|
|
22
21
|
}
|
|
23
22
|
|
|
@@ -39,8 +39,7 @@ class Match implements Expression {
|
|
|
39
39
|
if (context.expectedType && context.expectedType.kind !== 'value') {
|
|
40
40
|
outputType = context.expectedType;
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
const cases: Record<string, any> = {};
|
|
42
|
+
const cases: Cases = {};
|
|
44
43
|
const outputs = [];
|
|
45
44
|
for (let i = 2; i < args.length - 1; i += 2) {
|
|
46
45
|
let labels = args[i];
|
|
@@ -97,8 +96,7 @@ class Match implements Expression {
|
|
|
97
96
|
return new Match(inputType, outputType, input, cases, outputs, otherwise);
|
|
98
97
|
}
|
|
99
98
|
|
|
100
|
-
|
|
101
|
-
evaluate(ctx: EvaluationContext): any {
|
|
99
|
+
evaluate(ctx: EvaluationContext): unknown {
|
|
102
100
|
const input = (this.input.evaluate(ctx)) as number | string;
|
|
103
101
|
const output = (typeEquals(typeOf(input), this.inputType) && this.outputs[this.cases[input]!]) || this.otherwise;
|
|
104
102
|
return output.evaluate(ctx);
|
|
@@ -119,8 +119,7 @@ export default class NumberFormat implements Expression {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
serialize(): SerializedExpression {
|
|
122
|
-
|
|
123
|
-
const options: Record<string, any> = {};
|
|
122
|
+
const options: Record<string, SerializedExpression> = {};
|
|
124
123
|
if (this.locale) {
|
|
125
124
|
options['locale'] = this.locale.serialize();
|
|
126
125
|
}
|
|
@@ -54,8 +54,7 @@ class Slice implements Expression {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
evaluate(ctx: EvaluationContext): any {
|
|
57
|
+
evaluate(ctx: EvaluationContext): unknown {
|
|
59
58
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
60
59
|
const input = (this.input.evaluate(ctx));
|
|
61
60
|
const beginIndex = (this.beginIndex.evaluate(ctx) as number);
|
|
@@ -69,8 +69,7 @@ class Step implements Expression {
|
|
|
69
69
|
return new Step(outputType!, input, stops);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
evaluate(ctx: EvaluationContext): any {
|
|
72
|
+
evaluate(ctx: EvaluationContext): unknown {
|
|
74
73
|
const labels = this.labels;
|
|
75
74
|
const outputs = this.outputs;
|
|
76
75
|
|
|
@@ -26,8 +26,7 @@ class Var implements Expression {
|
|
|
26
26
|
return new Var(name, context.scope.get(name));
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
evaluate(ctx: EvaluationContext): any {
|
|
29
|
+
evaluate(ctx: EvaluationContext): unknown {
|
|
31
30
|
return this.boundExpression.evaluate(ctx);
|
|
32
31
|
}
|
|
33
32
|
|
|
@@ -215,6 +215,7 @@ class Within implements Expression {
|
|
|
215
215
|
type: Type;
|
|
216
216
|
geojson: GeoJSON.GeoJSON;
|
|
217
217
|
geometries: GeoJSONPolygons;
|
|
218
|
+
readonly featureConstant = false;
|
|
218
219
|
|
|
219
220
|
constructor(geojson: GeoJSON.GeoJSON, geometries: GeoJSONPolygons) {
|
|
220
221
|
this.type = BooleanType;
|
package/expression/expression.ts
CHANGED
|
@@ -8,6 +8,11 @@ export interface Expression {
|
|
|
8
8
|
readonly type: Type;
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
10
|
value?: any;
|
|
11
|
+
/**
|
|
12
|
+
* Set by expressions whose feature-dependence can't be derived from their children
|
|
13
|
+
* (e.g. `within`, `distance`, `config`); `isFeatureConstant` returns it without recursing.
|
|
14
|
+
*/
|
|
15
|
+
readonly featureConstant?: boolean;
|
|
11
16
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
17
|
evaluate: (ctx: EvaluationContext) => any;
|
|
13
18
|
eachChild: (fn: (arg1: Expression) => void) => void;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
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
2
|
|
|
6
3
|
import type {Expression} from './expression';
|
|
7
4
|
|
|
@@ -24,15 +21,7 @@ function isFeatureConstant(e: Expression): boolean {
|
|
|
24
21
|
}
|
|
25
22
|
}
|
|
26
23
|
|
|
27
|
-
if (e
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (e instanceof Distance) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (e instanceof Config) {
|
|
24
|
+
if (e.featureConstant !== undefined) {
|
|
36
25
|
return e.featureConstant;
|
|
37
26
|
}
|
|
38
27
|
|
|
@@ -85,8 +85,7 @@ function _convertFilter(filter: FilterSpecification, expectedTypes: ExpectedType
|
|
|
85
85
|
converted = convertComparisonOp(property, value, op, expectedTypes);
|
|
86
86
|
} else if (op === 'any') {
|
|
87
87
|
const children = filter.slice(1).map(f => {
|
|
88
|
-
|
|
89
|
-
const types: Record<string, any> = {};
|
|
88
|
+
const types: ExpectedTypes = {};
|
|
90
89
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
91
90
|
const child = _convertFilter(f, types);
|
|
92
91
|
|
|
@@ -139,8 +138,7 @@ function runtimeTypeChecks(expectedTypes: ExpectedTypes): true | unknown[] {
|
|
|
139
138
|
return (['all'] as unknown[]).concat(conditions);
|
|
140
139
|
}
|
|
141
140
|
|
|
142
|
-
|
|
143
|
-
function convertComparisonOp(property: string, value: any, op: string, expectedTypes?: ExpectedTypes | null): unknown {
|
|
141
|
+
function convertComparisonOp(property: string, value: unknown, op: string, expectedTypes?: ExpectedTypes | null): unknown {
|
|
144
142
|
let get: unknown[];
|
|
145
143
|
if (property === '$type') {
|
|
146
144
|
return [op, ['geometry-type'], value];
|
package/feature_filter/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type Point from '@mapbox/point-geometry';
|
|
|
8
8
|
import type {CanonicalTileID} from '../types/tile_id';
|
|
9
9
|
import type {GlobalProperties, Feature} from '../expression/index';
|
|
10
10
|
import type {FilterSpecification, ExpressionSpecification} from '../types';
|
|
11
|
+
import type {StylePropertySpecification} from '../style-spec';
|
|
11
12
|
import type {ConfigOptions} from '../types/config_options';
|
|
12
13
|
|
|
13
14
|
export type FeatureDistanceData = {
|
|
@@ -96,9 +97,8 @@ function createFilter(filter?: FilterSpecification, scope: string = "", options:
|
|
|
96
97
|
|
|
97
98
|
const filterExp = (filter as string[] | string | boolean);
|
|
98
99
|
|
|
99
|
-
let staticFilter = true;
|
|
100
|
+
let staticFilter: unknown = true;
|
|
100
101
|
try {
|
|
101
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
102
102
|
staticFilter = extractStaticFilter(filterExp);
|
|
103
103
|
} catch (e) {
|
|
104
104
|
console.warn(
|
|
@@ -113,12 +113,11 @@ ${JSON.stringify(filterExp, null, 2)}
|
|
|
113
113
|
|
|
114
114
|
// Compile the static component of the filter
|
|
115
115
|
let filterFunc: PropertyDescriptor['value'] = null;
|
|
116
|
-
let filterSpec = null;
|
|
116
|
+
let filterSpec: StylePropertySpecification | null = null;
|
|
117
117
|
if (layerType !== 'background' && layerType !== 'sky' && layerType !== 'slot') {
|
|
118
118
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
119
119
|
filterSpec = latest[`filter_${layerType}`];
|
|
120
120
|
assert(filterSpec);
|
|
121
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
122
121
|
const compiledStaticFilter = createExpression(staticFilter, filterSpec, scope, options);
|
|
123
122
|
|
|
124
123
|
if (compiledStaticFilter.result === 'error') {
|
|
@@ -131,10 +130,9 @@ ${JSON.stringify(filterExp, null, 2)}
|
|
|
131
130
|
|
|
132
131
|
// If the static component is not equal to the entire filter then we have a dynamic component
|
|
133
132
|
// Compile the dynamic component separately
|
|
134
|
-
let dynamicFilterFunc:
|
|
133
|
+
let dynamicFilterFunc: FilterExpression | null = null;
|
|
135
134
|
let needFeature = null;
|
|
136
135
|
if (staticFilter !== filterExp) {
|
|
137
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
138
136
|
const compiledDynamicFilter = createExpression(filterExp, filterSpec, scope, options);
|
|
139
137
|
|
|
140
138
|
if (compiledDynamicFilter.result === 'error') {
|
|
@@ -152,15 +150,13 @@ ${JSON.stringify(filterExp, null, 2)}
|
|
|
152
150
|
return {
|
|
153
151
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
154
152
|
filter: filterFunc,
|
|
155
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
156
153
|
dynamicFilter: dynamicFilterFunc ? dynamicFilterFunc : undefined,
|
|
157
154
|
needGeometry,
|
|
158
155
|
needFeature: !!needFeature
|
|
159
156
|
};
|
|
160
157
|
}
|
|
161
158
|
|
|
162
|
-
|
|
163
|
-
function extractStaticFilter(filter: unknown | unknown[]): any {
|
|
159
|
+
function extractStaticFilter(filter: unknown): unknown {
|
|
164
160
|
if (!isDynamicFilter(filter)) {
|
|
165
161
|
return filter;
|
|
166
162
|
}
|
|
@@ -177,18 +173,15 @@ function extractStaticFilter(filter: unknown | unknown[]): any {
|
|
|
177
173
|
return result;
|
|
178
174
|
}
|
|
179
175
|
|
|
180
|
-
|
|
181
|
-
function collapseDynamicBooleanExpressions(expression: any): any {
|
|
176
|
+
function collapseDynamicBooleanExpressions(expression: unknown): unknown {
|
|
182
177
|
if (!Array.isArray(expression)) {
|
|
183
178
|
return expression;
|
|
184
179
|
}
|
|
185
180
|
|
|
186
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
187
181
|
const collapsed = collapsedExpression(expression);
|
|
188
182
|
if (collapsed === true) {
|
|
189
183
|
return collapsed;
|
|
190
184
|
} else {
|
|
191
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
192
185
|
return collapsed.map((subExpression: unknown) => collapseDynamicBooleanExpressions(subExpression));
|
|
193
186
|
}
|
|
194
187
|
}
|
|
@@ -236,20 +229,17 @@ function unionDynamicBranches(filter: unknown[]) {
|
|
|
236
229
|
}
|
|
237
230
|
}
|
|
238
231
|
|
|
239
|
-
|
|
240
|
-
function isDynamicFilter(filter: any): boolean {
|
|
232
|
+
function isDynamicFilter(filter: unknown): boolean {
|
|
241
233
|
// Base Cases
|
|
242
234
|
if (!Array.isArray(filter)) {
|
|
243
235
|
return false;
|
|
244
236
|
}
|
|
245
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
246
237
|
if (isRootExpressionDynamic(filter[0])) {
|
|
247
238
|
return true;
|
|
248
239
|
}
|
|
249
240
|
|
|
250
241
|
for (let i = 1; i < filter.length; i++) {
|
|
251
|
-
|
|
252
|
-
const child = filter[i];
|
|
242
|
+
const child: unknown = filter[i];
|
|
253
243
|
if (isDynamicFilter(child)) {
|
|
254
244
|
return true;
|
|
255
245
|
}
|
|
@@ -258,12 +248,12 @@ function isDynamicFilter(filter: any): boolean {
|
|
|
258
248
|
return false;
|
|
259
249
|
}
|
|
260
250
|
|
|
261
|
-
function isRootExpressionDynamic(expression:
|
|
251
|
+
function isRootExpressionDynamic(expression: unknown): boolean {
|
|
262
252
|
return expression === 'pitch' ||
|
|
263
253
|
expression === 'distance-from-center';
|
|
264
254
|
}
|
|
265
255
|
|
|
266
|
-
const dynamicConditionExpressions: ReadonlySet<
|
|
256
|
+
const dynamicConditionExpressions: ReadonlySet<unknown> = new Set([
|
|
267
257
|
'in',
|
|
268
258
|
'==',
|
|
269
259
|
'!=',
|
|
@@ -274,14 +264,10 @@ const dynamicConditionExpressions: ReadonlySet<string> = new Set([
|
|
|
274
264
|
'to-boolean'
|
|
275
265
|
]);
|
|
276
266
|
|
|
277
|
-
|
|
278
|
-
function collapsedExpression(expression: any): any {
|
|
279
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
|
|
267
|
+
function collapsedExpression(expression: unknown[]): true | unknown[] {
|
|
280
268
|
if (dynamicConditionExpressions.has(expression[0])) {
|
|
281
269
|
|
|
282
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
283
270
|
for (let i = 1; i < expression.length; i++) {
|
|
284
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
285
271
|
const param = expression[i];
|
|
286
272
|
if (isDynamicFilter(param)) {
|
|
287
273
|
return true;
|
|
@@ -296,12 +282,10 @@ function compare(a: number, b: number) {
|
|
|
296
282
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
297
283
|
}
|
|
298
284
|
|
|
299
|
-
|
|
300
|
-
function geometryNeeded(filter: Array<any> | boolean) {
|
|
285
|
+
function geometryNeeded(filter: unknown) {
|
|
301
286
|
if (!Array.isArray(filter)) return false;
|
|
302
287
|
if (filter[0] === 'within' || filter[0] === 'distance') return true;
|
|
303
288
|
for (let index = 1; index < filter.length; index++) {
|
|
304
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
305
289
|
if (geometryNeeded(filter[index])) return true;
|
|
306
290
|
}
|
|
307
291
|
return false;
|
|
@@ -310,8 +294,7 @@ function geometryNeeded(filter: Array<any> | boolean) {
|
|
|
310
294
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
311
295
|
function convertFilter(filter?: Array<any> | null): unknown {
|
|
312
296
|
if (!filter) return true;
|
|
313
|
-
|
|
314
|
-
const op = filter[0];
|
|
297
|
+
const op: unknown = filter[0];
|
|
315
298
|
if (filter.length <= 1) return (op !== 'any');
|
|
316
299
|
const converted =
|
|
317
300
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
@@ -339,17 +322,13 @@ function convertFilter(filter?: Array<any> | null): unknown {
|
|
|
339
322
|
return converted;
|
|
340
323
|
}
|
|
341
324
|
|
|
342
|
-
|
|
343
|
-
function convertComparisonOp(property: string, value: any, op: string) {
|
|
325
|
+
function convertComparisonOp(property: string, value: unknown, op: string) {
|
|
344
326
|
switch (property) {
|
|
345
327
|
case '$type':
|
|
346
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
347
328
|
return [`filter-type-${op}`, value];
|
|
348
329
|
case '$id':
|
|
349
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
350
330
|
return [`filter-id-${op}`, value];
|
|
351
331
|
default:
|
|
352
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
353
332
|
return [`filter-${op}`, property, value];
|
|
354
333
|
}
|
|
355
334
|
}
|
package/package.json
CHANGED
package/reference/v8.json
CHANGED
|
@@ -3053,13 +3053,13 @@
|
|
|
3053
3053
|
"type": "enum",
|
|
3054
3054
|
"values": {
|
|
3055
3055
|
"auto": {
|
|
3056
|
-
"doc": "Sorts symbols by `symbol-sort-key` if set. Otherwise, sorts symbols by their y-position relative to the viewport if `icon-allow-overlap
|
|
3056
|
+
"doc": "Behaves as `source`, if `symbol-sort-key` is set. Otherwise behaves as `viewport-y`. I.e.: Sorts symbols by `symbol-sort-key` if `symbol-sort-key` is set. Otherwise, sorts symbols by their y-position relative to the viewport if any of the following is set to `true`: `icon-allow-overlap`, `text-allow-overlap`, `icon-ignore-placement`, `text-ignore-placement`. Or else, no sorting is applied; symbols are rendered in the same order as the source data."
|
|
3057
3057
|
},
|
|
3058
3058
|
"viewport-y": {
|
|
3059
|
-
"doc": "Sorts symbols by their y-position relative to the viewport if any of the following is set to `true`: `icon-allow-overlap`, `text-allow-overlap`, `icon-ignore-placement`, `text-ignore-placement`."
|
|
3059
|
+
"doc": "Sorts symbols by their y-position relative to the viewport if any of the following is set to `true`: `icon-allow-overlap`, `text-allow-overlap`, `icon-ignore-placement`, `text-ignore-placement`. Otherwise, no sorting is applied; symbols are rendered in the same order as the source data."
|
|
3060
3060
|
},
|
|
3061
3061
|
"source": {
|
|
3062
|
-
"doc": "Sorts symbols by `symbol-sort-key` if set. Otherwise, no sorting is applied; symbols are rendered in the same order as the source data."
|
|
3062
|
+
"doc": "Sorts symbols by `symbol-sort-key` if `symbol-sort-key` is set. Otherwise, no sorting is applied; symbols are rendered in the same order as the source data."
|
|
3063
3063
|
}
|
|
3064
3064
|
},
|
|
3065
3065
|
"default": "auto",
|
|
@@ -29,36 +29,30 @@ export default function validateExpression(options: ExpressionValidatorOptions):
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
32
|
-
const expressionObj = (expression.value as any).expression || (expression.value as any)._styleExpression.expression;
|
|
32
|
+
const expressionObj: Expression = (expression.value as any).expression || (expression.value as any)._styleExpression.expression;
|
|
33
33
|
|
|
34
34
|
if (options.expressionContext === 'property' && (options.propertyKey === 'text-font') &&
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
36
35
|
!expressionObj.outputDefined()) {
|
|
37
36
|
return [new ValidationError(options.key, options.value, `Invalid data expression for "${options.propertyKey}". Output values must be contained as literals within the expression.`)];
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
if (options.expressionContext === 'property' && options.propertyType === 'layout' &&
|
|
41
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
42
40
|
(!isStateConstant(expressionObj))) {
|
|
43
41
|
return [new ValidationError(options.key, options.value, '"feature-state" data expressions are not supported with layout properties.')];
|
|
44
42
|
}
|
|
45
43
|
|
|
46
44
|
if (options.expressionContext === 'filter') {
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
48
45
|
return disallowedFilterParameters(expressionObj, options);
|
|
49
46
|
}
|
|
50
47
|
|
|
51
48
|
if (options.expressionContext === 'appearance') {
|
|
52
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
53
49
|
return checkDisallowedAppearancesParameters(expressionObj, options);
|
|
54
50
|
}
|
|
55
51
|
|
|
56
52
|
if (options.expressionContext && options.expressionContext.indexOf('cluster') === 0) {
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
58
53
|
if (!isGlobalPropertyConstant(expressionObj, ['zoom', 'feature-state'])) {
|
|
59
54
|
return [new ValidationError(options.key, options.value, '"zoom" and "feature-state" expressions are not supported with cluster properties.')];
|
|
60
55
|
}
|
|
61
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
62
56
|
if (options.expressionContext === 'cluster-initial' && !isFeatureConstant(expressionObj)) {
|
|
63
57
|
return [new ValidationError(options.key, options.value, 'Feature data expressions are not supported with initial expression part of cluster properties.')];
|
|
64
58
|
}
|
|
@@ -84,8 +84,7 @@ export default function validateSource(options: SourceValidatorOptions): Validat
|
|
|
84
84
|
|
|
85
85
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
86
86
|
const [operator, mapExpr] = propValue;
|
|
87
|
-
|
|
88
|
-
const reduceExpr = typeof operator === 'string' ? [operator, ['accumulated'], ['get', prop]] : operator;
|
|
87
|
+
const reduceExpr: unknown = typeof operator === 'string' ? [operator, ['accumulated'], ['get', prop]] : operator;
|
|
89
88
|
|
|
90
89
|
errors.push(...validateExpression({
|
|
91
90
|
key: `${key}.${prop}.map`,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {validateStyle} from './validate_style.min';
|
|
2
|
-
import
|
|
2
|
+
import v8 from './reference/v8.json';
|
|
3
3
|
import readStyle from './read_style';
|
|
4
4
|
import ValidationError from './error/validation_error';
|
|
5
5
|
import {isString, isBoolean} from './util/get_type';
|
package/validate_style.ts
CHANGED