@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,30 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
import {ResolvedImageType, StringType} from '../types';
|
|
2
|
+
import ResolvedImage from '../types/resolved_image';
|
|
2
3
|
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import type {
|
|
7
|
-
import type EvaluationContext from '../evaluation_context.js';
|
|
8
|
-
import type ParsingContext from '../parsing_context.js';
|
|
9
|
-
import type {Type} from '../types.js';
|
|
4
|
+
import type {Expression, SerializedExpression} from '../expression';
|
|
5
|
+
import type EvaluationContext from '../evaluation_context';
|
|
6
|
+
import type ParsingContext from '../parsing_context';
|
|
7
|
+
import type {Type} from '../types';
|
|
10
8
|
|
|
11
9
|
export default class ImageExpression implements Expression {
|
|
12
10
|
type: Type;
|
|
13
11
|
inputPrimary: Expression;
|
|
14
|
-
inputSecondary:
|
|
12
|
+
inputSecondary: Expression | null | undefined;
|
|
15
13
|
|
|
16
|
-
constructor(inputPrimary: Expression, inputSecondary
|
|
14
|
+
constructor(inputPrimary: Expression, inputSecondary?: Expression | null) {
|
|
17
15
|
this.type = ResolvedImageType;
|
|
18
16
|
this.inputPrimary = inputPrimary;
|
|
19
17
|
this.inputSecondary = inputSecondary;
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
static parse(args:
|
|
20
|
+
static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Expression | null | undefined {
|
|
23
21
|
if (args.length < 2) {
|
|
22
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
24
23
|
return context.error(`Expected two or more arguments.`);
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
const namePrimary = context.parse(args[1], 1, StringType);
|
|
27
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
28
28
|
if (!namePrimary) return context.error(`No image name provided.`);
|
|
29
29
|
|
|
30
30
|
if (args.length === 2) {
|
|
@@ -32,6 +32,7 @@ export default class ImageExpression implements Expression {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const nameSecondary = context.parse(args[2], 1, StringType);
|
|
35
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
35
36
|
if (!nameSecondary) return context.error(`Secondary image variant is not a string.`);
|
|
36
37
|
|
|
37
38
|
return new ImageExpression(namePrimary, nameSecondary);
|
|
@@ -64,7 +65,6 @@ export default class ImageExpression implements Expression {
|
|
|
64
65
|
|
|
65
66
|
serialize(): SerializedExpression {
|
|
66
67
|
if (this.inputSecondary) {
|
|
67
|
-
// $FlowIgnore
|
|
68
68
|
return ["image", this.inputPrimary.serialize(), this.inputSecondary.serialize()];
|
|
69
69
|
}
|
|
70
70
|
return ["image", this.inputPrimary.serialize()];
|
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import {
|
|
2
|
+
BooleanType,
|
|
3
|
+
StringType,
|
|
4
|
+
ValueType,
|
|
5
|
+
NullType,
|
|
6
|
+
toString,
|
|
7
|
+
NumberType,
|
|
8
|
+
isValidType,
|
|
9
|
+
isValidNativeType,
|
|
10
|
+
} from '../types';
|
|
11
|
+
import RuntimeError from '../runtime_error';
|
|
12
|
+
import {typeOf} from '../values';
|
|
13
|
+
|
|
14
|
+
import type {Expression, SerializedExpression} from '../expression';
|
|
15
|
+
import type ParsingContext from '../parsing_context';
|
|
16
|
+
import type EvaluationContext from '../evaluation_context';
|
|
17
|
+
import type {Type} from '../types';
|
|
11
18
|
|
|
12
19
|
class In implements Expression {
|
|
13
20
|
type: Type;
|
|
@@ -20,8 +27,9 @@ class In implements Expression {
|
|
|
20
27
|
this.haystack = haystack;
|
|
21
28
|
}
|
|
22
29
|
|
|
23
|
-
static parse(args:
|
|
30
|
+
static parse(args: ReadonlyArray<unknown>, context: ParsingContext): In | null | undefined {
|
|
24
31
|
if (args.length !== 3) {
|
|
32
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'In'.
|
|
25
33
|
return context.error(`Expected 2 arguments, but found ${args.length - 1} instead.`);
|
|
26
34
|
}
|
|
27
35
|
|
|
@@ -32,6 +40,7 @@ class In implements Expression {
|
|
|
32
40
|
if (!needle || !haystack) return null;
|
|
33
41
|
|
|
34
42
|
if (!isValidType(needle.type, [BooleanType, StringType, NumberType, NullType, ValueType])) {
|
|
43
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'In'.
|
|
35
44
|
return context.error(`Expected first argument to be of type boolean, string, number or null, but found ${toString(needle.type)} instead`);
|
|
36
45
|
}
|
|
37
46
|
|
|
@@ -39,8 +48,8 @@ class In implements Expression {
|
|
|
39
48
|
}
|
|
40
49
|
|
|
41
50
|
evaluate(ctx: EvaluationContext): boolean {
|
|
42
|
-
const needle = (this.needle.evaluate(ctx)
|
|
43
|
-
const haystack = (this.haystack.evaluate(ctx)
|
|
51
|
+
const needle = (this.needle.evaluate(ctx));
|
|
52
|
+
const haystack = (this.haystack.evaluate(ctx));
|
|
44
53
|
|
|
45
54
|
if (haystack == null) return false;
|
|
46
55
|
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import {
|
|
4
|
-
type Type,
|
|
5
2
|
NumberType,
|
|
6
3
|
StringType,
|
|
7
4
|
BooleanType,
|
|
@@ -11,26 +8,26 @@ import {
|
|
|
11
8
|
ErrorType,
|
|
12
9
|
CollatorType,
|
|
13
10
|
array,
|
|
14
|
-
toString as typeToString
|
|
15
|
-
} from '../types
|
|
11
|
+
toString as typeToString,
|
|
12
|
+
} from '../types';
|
|
16
13
|
|
|
17
|
-
import {typeOf, Color, validateRGBA, validateHSLA, toString as valueToString} from '../values
|
|
18
|
-
import CompoundExpression from '../compound_expression
|
|
19
|
-
import RuntimeError from '../runtime_error
|
|
20
|
-
import Let from './let
|
|
21
|
-
import Var from './var
|
|
22
|
-
import Literal from './literal
|
|
23
|
-
import Assertion from './assertion
|
|
24
|
-
import Coercion from './coercion
|
|
25
|
-
import At from './at
|
|
26
|
-
import In from './in
|
|
27
|
-
import IndexOf from './index_of
|
|
28
|
-
import Match from './match
|
|
29
|
-
import Case from './case
|
|
30
|
-
import Slice from './slice
|
|
31
|
-
import Step from './step
|
|
32
|
-
import Interpolate from './interpolate
|
|
33
|
-
import Coalesce from './coalesce
|
|
14
|
+
import {typeOf, Color, validateRGBA, validateHSLA, toString as valueToString} from '../values';
|
|
15
|
+
import CompoundExpression from '../compound_expression';
|
|
16
|
+
import RuntimeError from '../runtime_error';
|
|
17
|
+
import Let from './let';
|
|
18
|
+
import Var from './var';
|
|
19
|
+
import Literal from './literal';
|
|
20
|
+
import Assertion from './assertion';
|
|
21
|
+
import Coercion from './coercion';
|
|
22
|
+
import At from './at';
|
|
23
|
+
import In from './in';
|
|
24
|
+
import IndexOf from './index_of';
|
|
25
|
+
import Match from './match';
|
|
26
|
+
import Case from './case';
|
|
27
|
+
import Slice from './slice';
|
|
28
|
+
import Step from './step';
|
|
29
|
+
import Interpolate from './interpolate';
|
|
30
|
+
import Coalesce from './coalesce';
|
|
34
31
|
import {
|
|
35
32
|
Equals,
|
|
36
33
|
NotEquals,
|
|
@@ -38,20 +35,21 @@ import {
|
|
|
38
35
|
GreaterThan,
|
|
39
36
|
LessThanOrEqual,
|
|
40
37
|
GreaterThanOrEqual
|
|
41
|
-
} from './comparison
|
|
42
|
-
import CollatorExpression from './collator
|
|
43
|
-
import NumberFormat from './number_format
|
|
44
|
-
import FormatExpression from './format
|
|
45
|
-
import ImageExpression from './image
|
|
46
|
-
import Length from './length
|
|
47
|
-
import Within from './within
|
|
48
|
-
import Config from './config
|
|
49
|
-
import Distance from './distance
|
|
50
|
-
import {mulberry32} from '../../util/random
|
|
38
|
+
} from './comparison';
|
|
39
|
+
import CollatorExpression from './collator';
|
|
40
|
+
import NumberFormat from './number_format';
|
|
41
|
+
import FormatExpression from './format';
|
|
42
|
+
import ImageExpression from './image';
|
|
43
|
+
import Length from './length';
|
|
44
|
+
import Within from './within';
|
|
45
|
+
import Config from './config';
|
|
46
|
+
import Distance from './distance';
|
|
47
|
+
import {mulberry32} from '../../util/random';
|
|
51
48
|
|
|
52
|
-
import type
|
|
53
|
-
import type
|
|
54
|
-
import type {
|
|
49
|
+
import type {Type} from '../types';
|
|
50
|
+
import type EvaluationContext from '../evaluation_context';
|
|
51
|
+
import type {Varargs} from '../compound_expression';
|
|
52
|
+
import type {Expression, ExpressionRegistry} from '../expression';
|
|
55
53
|
|
|
56
54
|
const expressions: ExpressionRegistry = {
|
|
57
55
|
// special forms
|
|
@@ -61,94 +59,83 @@ const expressions: ExpressionRegistry = {
|
|
|
61
59
|
'<': LessThan,
|
|
62
60
|
'>=': GreaterThanOrEqual,
|
|
63
61
|
'<=': LessThanOrEqual,
|
|
64
|
-
// $FlowFixMe[method-unbinding]
|
|
65
62
|
'array': Assertion,
|
|
66
|
-
// $FlowFixMe[method-unbinding]
|
|
67
63
|
'at': At,
|
|
68
64
|
'boolean': Assertion,
|
|
69
|
-
// $FlowFixMe[method-unbinding]
|
|
70
65
|
'case': Case,
|
|
71
|
-
// $FlowFixMe[method-unbinding]
|
|
72
66
|
'coalesce': Coalesce,
|
|
73
|
-
// $FlowFixMe[method-unbinding]
|
|
74
67
|
'collator': CollatorExpression,
|
|
75
|
-
// $FlowFixMe[method-unbinding]
|
|
76
68
|
'format': FormatExpression,
|
|
77
|
-
// $FlowFixMe[method-unbinding]
|
|
78
69
|
'image': ImageExpression,
|
|
79
|
-
// $FlowFixMe[method-unbinding]
|
|
80
70
|
'in': In,
|
|
81
|
-
// $FlowFixMe[method-unbinding]
|
|
82
71
|
'index-of': IndexOf,
|
|
83
|
-
// $FlowFixMe[method-unbinding]
|
|
84
72
|
'interpolate': Interpolate,
|
|
85
73
|
'interpolate-hcl': Interpolate,
|
|
86
74
|
'interpolate-lab': Interpolate,
|
|
87
|
-
// $FlowFixMe[method-unbinding]
|
|
88
75
|
'length': Length,
|
|
89
|
-
// $FlowFixMe[method-unbinding]
|
|
90
76
|
'let': Let,
|
|
91
|
-
// $FlowFixMe[method-unbinding]
|
|
92
77
|
'literal': Literal,
|
|
93
|
-
// $FlowFixMe[method-unbinding]
|
|
94
78
|
'match': Match,
|
|
95
79
|
'number': Assertion,
|
|
96
|
-
// $FlowFixMe[method-unbinding]
|
|
97
80
|
'number-format': NumberFormat,
|
|
98
81
|
'object': Assertion,
|
|
99
|
-
// $FlowFixMe[method-unbinding]
|
|
100
82
|
'slice': Slice,
|
|
101
|
-
// $FlowFixMe[method-unbinding]
|
|
102
83
|
'step': Step,
|
|
103
84
|
'string': Assertion,
|
|
104
|
-
// $FlowFixMe[method-unbinding]
|
|
105
85
|
'to-boolean': Coercion,
|
|
106
86
|
'to-color': Coercion,
|
|
107
87
|
'to-number': Coercion,
|
|
108
88
|
'to-string': Coercion,
|
|
109
|
-
// $FlowFixMe[method-unbinding]
|
|
110
89
|
'var': Var,
|
|
111
|
-
// $FlowFixMe[method-unbinding]
|
|
112
90
|
'within': Within,
|
|
113
|
-
// $FlowFixMe[method-unbinding]
|
|
114
91
|
'distance': Distance,
|
|
115
|
-
// $FlowFixMe[method-unbinding]
|
|
116
92
|
'config': Config
|
|
117
93
|
};
|
|
118
94
|
|
|
119
|
-
function rgba(ctx: EvaluationContext, [r, g, b, a]:
|
|
95
|
+
function rgba(ctx: EvaluationContext, [r, g, b, a]: Expression[]) {
|
|
120
96
|
r = r.evaluate(ctx);
|
|
121
97
|
g = g.evaluate(ctx);
|
|
122
98
|
b = b.evaluate(ctx);
|
|
123
99
|
const alpha = a ? a.evaluate(ctx) : 1;
|
|
124
100
|
const error = validateRGBA(r, g, b, alpha);
|
|
125
101
|
if (error) throw new RuntimeError(error);
|
|
102
|
+
// @ts-expect-error
|
|
126
103
|
return new Color(r / 255 * alpha, g / 255 * alpha, b / 255 * alpha, alpha);
|
|
127
104
|
}
|
|
128
105
|
|
|
129
|
-
function hsla(ctx: EvaluationContext, [h, s, l, a]:
|
|
106
|
+
function hsla(ctx: EvaluationContext, [h, s, l, a]: Expression[]) {
|
|
130
107
|
h = h.evaluate(ctx);
|
|
131
108
|
s = s.evaluate(ctx);
|
|
132
109
|
l = l.evaluate(ctx);
|
|
133
110
|
const alpha = a ? a.evaluate(ctx) : 1;
|
|
134
111
|
const error = validateHSLA(h, s, l, alpha);
|
|
135
112
|
if (error) throw new RuntimeError(error);
|
|
113
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
136
114
|
const colorFunction = `hsla(${h}, ${s}%, ${l}%, ${alpha})`;
|
|
137
115
|
const color = Color.parse(colorFunction);
|
|
138
116
|
if (!color) throw new RuntimeError(`Failed to parse HSLA color: ${colorFunction}`);
|
|
139
117
|
return color;
|
|
140
118
|
}
|
|
141
119
|
|
|
142
|
-
function has(
|
|
120
|
+
function has(
|
|
121
|
+
key: string,
|
|
122
|
+
obj: {
|
|
123
|
+
[key: string]: any;
|
|
124
|
+
},
|
|
125
|
+
): boolean {
|
|
143
126
|
return key in obj;
|
|
144
127
|
}
|
|
145
128
|
|
|
146
|
-
function get(key: string, obj: {
|
|
129
|
+
function get(key: string, obj: {
|
|
130
|
+
[key: string]: any;
|
|
131
|
+
}) {
|
|
147
132
|
const v = obj[key];
|
|
148
133
|
return typeof v === 'undefined' ? null : v;
|
|
149
134
|
}
|
|
150
135
|
|
|
151
|
-
function binarySearch(v: any, a: {
|
|
136
|
+
function binarySearch(v: any, a: {
|
|
137
|
+
[key: number]: any;
|
|
138
|
+
}, i: number, j: number) {
|
|
152
139
|
while (i <= j) {
|
|
153
140
|
const m = (i + j) >> 1;
|
|
154
141
|
if (a[m] === v)
|
|
@@ -193,7 +180,7 @@ CompoundExpression.register(expressions, {
|
|
|
193
180
|
array(NumberType, 4),
|
|
194
181
|
[ColorType],
|
|
195
182
|
(ctx, [v]) => {
|
|
196
|
-
return v.evaluate(ctx).toArray();
|
|
183
|
+
return v.evaluate(ctx).toRenderColor(null).toArray();
|
|
197
184
|
}
|
|
198
185
|
],
|
|
199
186
|
'rgb': [
|
|
@@ -463,24 +450,24 @@ CompoundExpression.register(expressions, {
|
|
|
463
450
|
'filter-==': [
|
|
464
451
|
BooleanType,
|
|
465
452
|
[StringType, ValueType],
|
|
466
|
-
(ctx, [k, v]) => ctx.properties()[(k
|
|
453
|
+
(ctx, [k, v]) => ctx.properties()[(k).value] === (v).value
|
|
467
454
|
],
|
|
468
455
|
'filter-id-==': [
|
|
469
456
|
BooleanType,
|
|
470
457
|
[ValueType],
|
|
471
|
-
(ctx, [v]) => ctx.id() === (v
|
|
458
|
+
(ctx, [v]) => ctx.id() === (v).value
|
|
472
459
|
],
|
|
473
460
|
'filter-type-==': [
|
|
474
461
|
BooleanType,
|
|
475
462
|
[StringType],
|
|
476
|
-
(ctx, [v]) => ctx.geometryType() === (v
|
|
463
|
+
(ctx, [v]) => ctx.geometryType() === (v).value
|
|
477
464
|
],
|
|
478
465
|
'filter-<': [
|
|
479
466
|
BooleanType,
|
|
480
467
|
[StringType, ValueType],
|
|
481
468
|
(ctx, [k, v]) => {
|
|
482
|
-
const a = ctx.properties()[(k
|
|
483
|
-
const b = (v
|
|
469
|
+
const a = ctx.properties()[(k).value];
|
|
470
|
+
const b = (v).value;
|
|
484
471
|
return typeof a === typeof b && a < b;
|
|
485
472
|
}
|
|
486
473
|
],
|
|
@@ -489,7 +476,7 @@ CompoundExpression.register(expressions, {
|
|
|
489
476
|
[ValueType],
|
|
490
477
|
(ctx, [v]) => {
|
|
491
478
|
const a = ctx.id();
|
|
492
|
-
const b = (v
|
|
479
|
+
const b = (v).value;
|
|
493
480
|
return typeof a === typeof b && a < b;
|
|
494
481
|
}
|
|
495
482
|
],
|
|
@@ -497,8 +484,8 @@ CompoundExpression.register(expressions, {
|
|
|
497
484
|
BooleanType,
|
|
498
485
|
[StringType, ValueType],
|
|
499
486
|
(ctx, [k, v]) => {
|
|
500
|
-
const a = ctx.properties()[(k
|
|
501
|
-
const b = (v
|
|
487
|
+
const a = ctx.properties()[(k).value];
|
|
488
|
+
const b = (v).value;
|
|
502
489
|
return typeof a === typeof b && a > b;
|
|
503
490
|
}
|
|
504
491
|
],
|
|
@@ -507,7 +494,7 @@ CompoundExpression.register(expressions, {
|
|
|
507
494
|
[ValueType],
|
|
508
495
|
(ctx, [v]) => {
|
|
509
496
|
const a = ctx.id();
|
|
510
|
-
const b = (v
|
|
497
|
+
const b = (v).value;
|
|
511
498
|
return typeof a === typeof b && a > b;
|
|
512
499
|
}
|
|
513
500
|
],
|
|
@@ -515,8 +502,8 @@ CompoundExpression.register(expressions, {
|
|
|
515
502
|
BooleanType,
|
|
516
503
|
[StringType, ValueType],
|
|
517
504
|
(ctx, [k, v]) => {
|
|
518
|
-
const a = ctx.properties()[(k
|
|
519
|
-
const b = (v
|
|
505
|
+
const a = ctx.properties()[(k).value];
|
|
506
|
+
const b = (v).value;
|
|
520
507
|
return typeof a === typeof b && a <= b;
|
|
521
508
|
}
|
|
522
509
|
],
|
|
@@ -525,7 +512,7 @@ CompoundExpression.register(expressions, {
|
|
|
525
512
|
[ValueType],
|
|
526
513
|
(ctx, [v]) => {
|
|
527
514
|
const a = ctx.id();
|
|
528
|
-
const b = (v
|
|
515
|
+
const b = (v).value;
|
|
529
516
|
return typeof a === typeof b && a <= b;
|
|
530
517
|
}
|
|
531
518
|
],
|
|
@@ -533,8 +520,8 @@ CompoundExpression.register(expressions, {
|
|
|
533
520
|
BooleanType,
|
|
534
521
|
[StringType, ValueType],
|
|
535
522
|
(ctx, [k, v]) => {
|
|
536
|
-
const a = ctx.properties()[(k
|
|
537
|
-
const b = (v
|
|
523
|
+
const a = ctx.properties()[(k).value];
|
|
524
|
+
const b = (v).value;
|
|
538
525
|
return typeof a === typeof b && a >= b;
|
|
539
526
|
}
|
|
540
527
|
],
|
|
@@ -543,14 +530,14 @@ CompoundExpression.register(expressions, {
|
|
|
543
530
|
[ValueType],
|
|
544
531
|
(ctx, [v]) => {
|
|
545
532
|
const a = ctx.id();
|
|
546
|
-
const b = (v
|
|
533
|
+
const b = (v).value;
|
|
547
534
|
return typeof a === typeof b && a >= b;
|
|
548
535
|
}
|
|
549
536
|
],
|
|
550
537
|
'filter-has': [
|
|
551
538
|
BooleanType,
|
|
552
539
|
[ValueType],
|
|
553
|
-
(ctx, [k]) => (k
|
|
540
|
+
(ctx, [k]) => (k).value in ctx.properties()
|
|
554
541
|
],
|
|
555
542
|
'filter-has-id': [
|
|
556
543
|
BooleanType,
|
|
@@ -560,24 +547,24 @@ CompoundExpression.register(expressions, {
|
|
|
560
547
|
'filter-type-in': [
|
|
561
548
|
BooleanType,
|
|
562
549
|
[array(StringType)],
|
|
563
|
-
(ctx, [v]) => (v
|
|
550
|
+
(ctx, [v]) => (v).value.indexOf(ctx.geometryType()) >= 0
|
|
564
551
|
],
|
|
565
552
|
'filter-id-in': [
|
|
566
553
|
BooleanType,
|
|
567
554
|
[array(ValueType)],
|
|
568
|
-
(ctx, [v]) => (v
|
|
555
|
+
(ctx, [v]) => (v).value.indexOf(ctx.id()) >= 0
|
|
569
556
|
],
|
|
570
557
|
'filter-in-small': [
|
|
571
558
|
BooleanType,
|
|
572
559
|
[StringType, array(ValueType)],
|
|
573
560
|
// assumes v is an array literal
|
|
574
|
-
(ctx, [k, v]) => (v
|
|
561
|
+
(ctx, [k, v]) => (v).value.indexOf(ctx.properties()[(k).value]) >= 0
|
|
575
562
|
],
|
|
576
563
|
'filter-in-large': [
|
|
577
564
|
BooleanType,
|
|
578
565
|
[StringType, array(ValueType)],
|
|
579
566
|
// assumes v is a array literal with values sorted in ascending order and of a single type
|
|
580
|
-
(ctx, [k, v]) => binarySearch(ctx.properties()[(k
|
|
567
|
+
(ctx, [k, v]) => binarySearch(ctx.properties()[(k).value], (v).value, 0, (v).value.length - 1)
|
|
581
568
|
],
|
|
582
569
|
'all': {
|
|
583
570
|
type: BooleanType,
|
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import {
|
|
2
|
+
BooleanType,
|
|
3
|
+
StringType,
|
|
4
|
+
ValueType,
|
|
5
|
+
NullType,
|
|
6
|
+
toString,
|
|
7
|
+
NumberType,
|
|
8
|
+
isValidType,
|
|
9
|
+
isValidNativeType,
|
|
10
|
+
} from '../types';
|
|
11
|
+
import RuntimeError from '../runtime_error';
|
|
12
|
+
import {typeOf} from '../values';
|
|
13
|
+
|
|
14
|
+
import type {Expression, SerializedExpression} from '../expression';
|
|
15
|
+
import type ParsingContext from '../parsing_context';
|
|
16
|
+
import type EvaluationContext from '../evaluation_context';
|
|
17
|
+
import type {Type} from '../types';
|
|
11
18
|
|
|
12
19
|
class IndexOf implements Expression {
|
|
13
20
|
type: Type;
|
|
14
21
|
needle: Expression;
|
|
15
22
|
haystack: Expression;
|
|
16
|
-
fromIndex:
|
|
23
|
+
fromIndex: Expression | null | undefined;
|
|
17
24
|
|
|
18
25
|
constructor(needle: Expression, haystack: Expression, fromIndex?: Expression) {
|
|
19
26
|
this.type = NumberType;
|
|
@@ -22,8 +29,9 @@ class IndexOf implements Expression {
|
|
|
22
29
|
this.fromIndex = fromIndex;
|
|
23
30
|
}
|
|
24
31
|
|
|
25
|
-
static parse(args:
|
|
32
|
+
static parse(args: ReadonlyArray<unknown>, context: ParsingContext): IndexOf | null | undefined {
|
|
26
33
|
if (args.length <= 2 || args.length >= 5) {
|
|
34
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'IndexOf'.
|
|
27
35
|
return context.error(`Expected 3 or 4 arguments, but found ${args.length - 1} instead.`);
|
|
28
36
|
}
|
|
29
37
|
|
|
@@ -33,6 +41,7 @@ class IndexOf implements Expression {
|
|
|
33
41
|
|
|
34
42
|
if (!needle || !haystack) return null;
|
|
35
43
|
if (!isValidType(needle.type, [BooleanType, StringType, NumberType, NullType, ValueType])) {
|
|
44
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'IndexOf'.
|
|
36
45
|
return context.error(`Expected first argument to be of type boolean, string, number or null, but found ${toString(needle.type)} instead`);
|
|
37
46
|
}
|
|
38
47
|
|
|
@@ -46,8 +55,8 @@ class IndexOf implements Expression {
|
|
|
46
55
|
}
|
|
47
56
|
|
|
48
57
|
evaluate(ctx: EvaluationContext): any {
|
|
49
|
-
const needle = (this.needle.evaluate(ctx)
|
|
50
|
-
const haystack = (this.haystack.evaluate(ctx)
|
|
58
|
+
const needle = (this.needle.evaluate(ctx));
|
|
59
|
+
const haystack = (this.haystack.evaluate(ctx));
|
|
51
60
|
|
|
52
61
|
if (!isValidNativeType(needle, ['boolean', 'string', 'number', 'null'])) {
|
|
53
62
|
throw new RuntimeError(`Expected first argument to be of type boolean, string, number or null, but found ${toString(typeOf(needle))} instead.`);
|
|
@@ -58,7 +67,7 @@ class IndexOf implements Expression {
|
|
|
58
67
|
}
|
|
59
68
|
|
|
60
69
|
if (this.fromIndex) {
|
|
61
|
-
const fromIndex = (this.fromIndex.evaluate(ctx)
|
|
70
|
+
const fromIndex = (this.fromIndex.evaluate(ctx) as number);
|
|
62
71
|
return haystack.indexOf(needle, fromIndex);
|
|
63
72
|
}
|
|
64
73
|
|