@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,14 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type {Expression} from './expression.js';
|
|
1
|
+
import type {Expression} from './expression';
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* Tracks `let` bindings during expression parsing.
|
|
7
5
|
* @private
|
|
8
6
|
*/
|
|
9
7
|
class Scope {
|
|
10
|
-
parent:
|
|
11
|
-
bindings: {
|
|
8
|
+
parent: Scope | null | undefined;
|
|
9
|
+
bindings: {
|
|
10
|
+
[_: string]: Expression;
|
|
11
|
+
};
|
|
12
12
|
constructor(parent?: Scope, bindings: Array<[string, Expression]> = []) {
|
|
13
13
|
this.parent = parent;
|
|
14
14
|
this.bindings = {};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
export default class Collator {
|
|
4
2
|
locale: string | null;
|
|
5
3
|
sensitivity: 'base' | 'accent' | 'case' | 'variant';
|
|
6
|
-
collator: Intl
|
|
4
|
+
collator: Intl.Collator;
|
|
7
5
|
|
|
8
6
|
constructor(caseSensitive: boolean, diacriticSensitive: boolean, locale: string | null) {
|
|
9
7
|
if (caseSensitive)
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import type
|
|
3
|
-
import type ResolvedImage from '../types/resolved_image.js';
|
|
1
|
+
import type Color from '../../util/color';
|
|
2
|
+
import type ResolvedImage from '../types/resolved_image';
|
|
4
3
|
|
|
5
4
|
export class FormattedSection {
|
|
6
5
|
text: string;
|
|
@@ -49,15 +48,17 @@ export default class Formatted {
|
|
|
49
48
|
return this.sections.map(section => section.text).join('');
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
serialize(): Array<
|
|
53
|
-
const serialized: Array<
|
|
51
|
+
serialize(): Array<unknown> {
|
|
52
|
+
const serialized: Array<unknown> = ["format"];
|
|
54
53
|
for (const section of this.sections) {
|
|
55
54
|
if (section.image) {
|
|
56
55
|
serialized.push(["image", section.image.namePrimary]);
|
|
57
56
|
continue;
|
|
58
57
|
}
|
|
59
58
|
serialized.push(section.text);
|
|
60
|
-
const options: {
|
|
59
|
+
const options: {
|
|
60
|
+
[key: string]: unknown;
|
|
61
|
+
} = {};
|
|
61
62
|
if (section.fontStack) {
|
|
62
63
|
options["text-font"] = ["literal", section.fontStack.split(',')];
|
|
63
64
|
}
|
|
@@ -65,7 +66,7 @@ export default class Formatted {
|
|
|
65
66
|
options["font-scale"] = section.scale;
|
|
66
67
|
}
|
|
67
68
|
if (section.textColor) {
|
|
68
|
-
options["text-color"] = (["rgba"]
|
|
69
|
+
options["text-color"] = (["rgba"] as Array<unknown>).concat(section.textColor.toRenderColor(null).toArray());
|
|
69
70
|
}
|
|
70
71
|
serialized.push(options);
|
|
71
72
|
}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
export type ResolvedImageOptions = {
|
|
4
|
-
namePrimary: string
|
|
5
|
-
nameSecondary:
|
|
6
|
-
available: boolean
|
|
2
|
+
namePrimary: string;
|
|
3
|
+
nameSecondary: string | null | undefined;
|
|
4
|
+
available: boolean;
|
|
7
5
|
};
|
|
8
6
|
|
|
9
7
|
export default class ResolvedImage {
|
|
10
8
|
namePrimary: string;
|
|
11
|
-
nameSecondary:
|
|
9
|
+
nameSecondary: string | null | undefined;
|
|
12
10
|
available: boolean;
|
|
13
11
|
|
|
14
12
|
constructor(options: ResolvedImageOptions) {
|
|
@@ -26,7 +24,7 @@ export default class ResolvedImage {
|
|
|
26
24
|
return this.namePrimary;
|
|
27
25
|
}
|
|
28
26
|
|
|
29
|
-
static fromString(namePrimary: string, nameSecondary
|
|
27
|
+
static fromString(namePrimary: string, nameSecondary?: string | null): ResolvedImage | null {
|
|
30
28
|
if (!namePrimary) return null; // treat empty values as no image
|
|
31
29
|
return new ResolvedImage({namePrimary, nameSecondary, available: false});
|
|
32
30
|
}
|
|
@@ -1,55 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export type NumberTypeT = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export type
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export type
|
|
1
|
+
export type NullTypeT = {
|
|
2
|
+
kind: 'null';
|
|
3
|
+
};
|
|
4
|
+
export type NumberTypeT = {
|
|
5
|
+
kind: 'number';
|
|
6
|
+
};
|
|
7
|
+
export type StringTypeT = {
|
|
8
|
+
kind: 'string';
|
|
9
|
+
};
|
|
10
|
+
export type BooleanTypeT = {
|
|
11
|
+
kind: 'boolean';
|
|
12
|
+
};
|
|
13
|
+
export type ColorTypeT = {
|
|
14
|
+
kind: 'color';
|
|
15
|
+
};
|
|
16
|
+
export type ObjectTypeT = {
|
|
17
|
+
kind: 'object';
|
|
18
|
+
};
|
|
19
|
+
export type ValueTypeT = {
|
|
20
|
+
kind: 'value';
|
|
21
|
+
};
|
|
22
|
+
export type ErrorTypeT = {
|
|
23
|
+
kind: 'error';
|
|
24
|
+
};
|
|
25
|
+
export type CollatorTypeT = {
|
|
26
|
+
kind: 'collator';
|
|
27
|
+
};
|
|
28
|
+
export type FormattedTypeT = {
|
|
29
|
+
kind: 'formatted';
|
|
30
|
+
};
|
|
31
|
+
export type ResolvedImageTypeT = {
|
|
32
|
+
kind: 'resolvedImage';
|
|
33
|
+
};
|
|
14
34
|
|
|
15
35
|
export type EvaluationKind = 'constant' | 'source' | 'camera' | 'composite';
|
|
16
36
|
|
|
17
|
-
export type Type =
|
|
18
|
-
|
|
19
|
-
NumberTypeT |
|
|
20
|
-
StringTypeT |
|
|
21
|
-
BooleanTypeT |
|
|
22
|
-
ColorTypeT |
|
|
23
|
-
ObjectTypeT |
|
|
24
|
-
ValueTypeT |
|
|
25
|
-
ArrayType | // eslint-disable-line no-use-before-define
|
|
26
|
-
ErrorTypeT |
|
|
27
|
-
CollatorTypeT |
|
|
28
|
-
FormattedTypeT |
|
|
29
|
-
ResolvedImageTypeT |
|
|
30
|
-
ArrayType;
|
|
37
|
+
export type Type = NullTypeT | NumberTypeT | StringTypeT | BooleanTypeT | ColorTypeT | ObjectTypeT | ValueTypeT | // eslint-disable-line no-use-before-define
|
|
38
|
+
ArrayType | ErrorTypeT | CollatorTypeT | FormattedTypeT | ResolvedImageTypeT;
|
|
31
39
|
|
|
32
40
|
export type ArrayType = {
|
|
33
|
-
kind: 'array'
|
|
34
|
-
itemType: Type
|
|
35
|
-
N:
|
|
36
|
-
}
|
|
41
|
+
kind: 'array';
|
|
42
|
+
itemType: Type;
|
|
43
|
+
N: number | null | undefined;
|
|
44
|
+
};
|
|
37
45
|
|
|
38
|
-
export type NativeType = 'number' | 'string' | 'boolean' | 'null' | 'array' | 'object'
|
|
46
|
+
export type NativeType = 'number' | 'string' | 'boolean' | 'null' | 'array' | 'object';
|
|
39
47
|
|
|
40
|
-
export const NullType = {kind: 'null'};
|
|
41
|
-
export const NumberType = {kind: 'number'};
|
|
42
|
-
export const StringType = {kind: 'string'};
|
|
43
|
-
export const BooleanType = {kind: 'boolean'};
|
|
44
|
-
export const ColorType = {kind: 'color'};
|
|
45
|
-
export const ObjectType = {kind: 'object'};
|
|
46
|
-
export const ValueType = {kind: 'value'};
|
|
47
|
-
export const ErrorType = {kind: 'error'};
|
|
48
|
-
export const CollatorType = {kind: 'collator'};
|
|
49
|
-
export const FormattedType = {kind: 'formatted'};
|
|
50
|
-
export const ResolvedImageType = {kind: 'resolvedImage'};
|
|
48
|
+
export const NullType = {kind: 'null'} as const;
|
|
49
|
+
export const NumberType = {kind: 'number'} as const;
|
|
50
|
+
export const StringType = {kind: 'string'} as const;
|
|
51
|
+
export const BooleanType = {kind: 'boolean'} as const;
|
|
52
|
+
export const ColorType = {kind: 'color'} as const;
|
|
53
|
+
export const ObjectType = {kind: 'object'} as const;
|
|
54
|
+
export const ValueType = {kind: 'value'} as const;
|
|
55
|
+
export const ErrorType = {kind: 'error'} as const;
|
|
56
|
+
export const CollatorType = {kind: 'collator'} as const;
|
|
57
|
+
export const FormattedType = {kind: 'formatted'} as const;
|
|
58
|
+
export const ResolvedImageType = {kind: 'resolvedImage'} as const;
|
|
51
59
|
|
|
52
|
-
export function array(itemType: Type, N
|
|
60
|
+
export function array(itemType: Type, N?: number | null): ArrayType {
|
|
53
61
|
return {
|
|
54
62
|
kind: 'array',
|
|
55
63
|
itemType,
|
|
@@ -85,7 +93,7 @@ const valueMemberTypes = [
|
|
|
85
93
|
* error message.
|
|
86
94
|
* @private
|
|
87
95
|
*/
|
|
88
|
-
export function checkSubtype(expected: Type, t: Type):
|
|
96
|
+
export function checkSubtype(expected: Type, t: Type): string | null | undefined {
|
|
89
97
|
if (t.kind === 'error') {
|
|
90
98
|
// Error is a subtype of every type
|
|
91
99
|
return null;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import assert from 'assert';
|
|
4
2
|
|
|
5
|
-
import Color from '../util/color
|
|
6
|
-
import Collator from './types/collator
|
|
7
|
-
import Formatted from './types/formatted
|
|
8
|
-
import ResolvedImage from './types/resolved_image
|
|
9
|
-
import {NullType, NumberType, StringType, BooleanType, ColorType, ObjectType, ValueType, CollatorType, FormattedType, ResolvedImageType, array} from './types
|
|
3
|
+
import Color from '../util/color';
|
|
4
|
+
import Collator from './types/collator';
|
|
5
|
+
import Formatted from './types/formatted';
|
|
6
|
+
import ResolvedImage from './types/resolved_image';
|
|
7
|
+
import {NullType, NumberType, StringType, BooleanType, ColorType, ObjectType, ValueType, CollatorType, FormattedType, ResolvedImageType, array} from './types';
|
|
10
8
|
|
|
11
|
-
import type {Type} from './types
|
|
9
|
+
import type {Type} from './types';
|
|
12
10
|
|
|
13
|
-
export function validateRGBA(r:
|
|
11
|
+
export function validateRGBA(r: unknown, g: unknown, b: unknown, a?: unknown): string | null {
|
|
14
12
|
if (!(
|
|
15
13
|
typeof r === 'number' && r >= 0 && r <= 255 &&
|
|
16
14
|
typeof g === 'number' && g >= 0 && g <= 255 &&
|
|
@@ -29,7 +27,7 @@ export function validateRGBA(r: mixed, g: mixed, b: mixed, a?: mixed): string |
|
|
|
29
27
|
return null;
|
|
30
28
|
}
|
|
31
29
|
|
|
32
|
-
export function validateHSLA(h:
|
|
30
|
+
export function validateHSLA(h: unknown, s: unknown, l: unknown, a?: unknown): string | null {
|
|
33
31
|
if (!(
|
|
34
32
|
typeof h === 'number' && h >= 0 && h <= 360
|
|
35
33
|
)) {
|
|
@@ -54,9 +52,11 @@ export function validateHSLA(h: mixed, s: mixed, l: mixed, a?: mixed): string |
|
|
|
54
52
|
return null;
|
|
55
53
|
}
|
|
56
54
|
|
|
57
|
-
export type Value = null | string | boolean | number | Color | Collator | Formatted | ResolvedImage |
|
|
55
|
+
export type Value = null | string | boolean | number | Color | Collator | Formatted | ResolvedImage | ReadonlyArray<Value> | {
|
|
56
|
+
readonly [key: string]: Value;
|
|
57
|
+
};
|
|
58
58
|
|
|
59
|
-
export function isValue(mixed:
|
|
59
|
+
export function isValue(mixed: unknown): boolean {
|
|
60
60
|
if (mixed === null) {
|
|
61
61
|
return true;
|
|
62
62
|
} else if (typeof mixed === 'string') {
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import {isExpressionFilter} from './index';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import type {FilterSpecification} from '../types';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
type ExpectedTypes = {
|
|
6
|
+
[_: string]: 'string' | 'number' | 'boolean';
|
|
7
|
+
};
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Convert the given legacy filter to (the JSON representation of) an
|
|
11
11
|
* equivalent expression
|
|
12
12
|
* @private
|
|
13
13
|
*/
|
|
14
|
-
export default function convertFilter(filter: FilterSpecification):
|
|
14
|
+
export default function convertFilter(filter: FilterSpecification): unknown {
|
|
15
15
|
return _convertFilter(filter, {});
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -63,7 +63,7 @@ export default function convertFilter(filter: FilterSpecification): mixed {
|
|
|
63
63
|
* false (legacy filter semantics) are equivalent: they cause the filter to
|
|
64
64
|
* produce a `false` result.
|
|
65
65
|
*/
|
|
66
|
-
function _convertFilter(filter: FilterSpecification, expectedTypes: ExpectedTypes):
|
|
66
|
+
function _convertFilter(filter: FilterSpecification, expectedTypes: ExpectedTypes): unknown {
|
|
67
67
|
if (isExpressionFilter(filter)) { return filter; }
|
|
68
68
|
|
|
69
69
|
if (!filter) return true;
|
|
@@ -80,29 +80,29 @@ function _convertFilter(filter: FilterSpecification, expectedTypes: ExpectedType
|
|
|
80
80
|
op === '<=' ||
|
|
81
81
|
op === '>='
|
|
82
82
|
) {
|
|
83
|
-
const [, property, value] = (filter
|
|
83
|
+
const [, property, value] = (filter as any);
|
|
84
84
|
converted = convertComparisonOp(property, value, op, expectedTypes);
|
|
85
85
|
} else if (op === 'any') {
|
|
86
|
-
const children = (filter
|
|
87
|
-
const types = {};
|
|
86
|
+
const children = (filter as any).slice(1).map(f => {
|
|
87
|
+
const types: Record<string, any> = {};
|
|
88
88
|
const child = _convertFilter(f, types);
|
|
89
89
|
const typechecks = runtimeTypeChecks(types);
|
|
90
90
|
return typechecks === true ? child : ['case', typechecks, child, false];
|
|
91
91
|
});
|
|
92
92
|
return ['any'].concat(children);
|
|
93
93
|
} else if (op === 'all') {
|
|
94
|
-
const children = (filter
|
|
94
|
+
const children = (filter as any).slice(1).map(f => _convertFilter(f, expectedTypes));
|
|
95
95
|
return children.length > 1 ? ['all'].concat(children) : [].concat(...children);
|
|
96
96
|
} else if (op === 'none') {
|
|
97
|
-
return ['!', _convertFilter(['any'].concat((filter
|
|
97
|
+
return ['!', _convertFilter(['any'].concat((filter as any).slice(1)), {})];
|
|
98
98
|
} else if (op === 'in') {
|
|
99
|
-
converted = convertInOp((filter[1]
|
|
99
|
+
converted = convertInOp((filter[1] as any), filter.slice(2));
|
|
100
100
|
} else if (op === '!in') {
|
|
101
|
-
converted = convertInOp((filter[1]
|
|
101
|
+
converted = convertInOp((filter[1] as any), filter.slice(2), true);
|
|
102
102
|
} else if (op === 'has') {
|
|
103
|
-
converted = convertHasOp((filter[1]
|
|
103
|
+
converted = convertHasOp((filter[1] as any));
|
|
104
104
|
} else if (op === '!has') {
|
|
105
|
-
converted = ['!', convertHasOp((filter[1]
|
|
105
|
+
converted = ['!', convertHasOp((filter[1] as any))];
|
|
106
106
|
} else {
|
|
107
107
|
converted = true;
|
|
108
108
|
}
|
|
@@ -129,7 +129,7 @@ function runtimeTypeChecks(expectedTypes: ExpectedTypes) {
|
|
|
129
129
|
return ['all'].concat(conditions);
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
function convertComparisonOp(property: string, value: any, op: string, expectedTypes
|
|
132
|
+
function convertComparisonOp(property: string, value: any, op: string, expectedTypes?: ExpectedTypes | null) {
|
|
133
133
|
let get;
|
|
134
134
|
if (property === '$type') {
|
|
135
135
|
return [op, ['geometry-type'], value];
|
|
@@ -140,7 +140,7 @@ function convertComparisonOp(property: string, value: any, op: string, expectedT
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
if (expectedTypes && value !== null) {
|
|
143
|
-
const type = ((typeof value)
|
|
143
|
+
const type = ((typeof value) as any);
|
|
144
144
|
expectedTypes[property] = type;
|
|
145
145
|
}
|
|
146
146
|
|
|
@@ -193,6 +193,7 @@ function convertInOp(property: string, values: Array<any>, negate: boolean = fal
|
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
return [ negate ? 'all' : 'any' ].concat(
|
|
196
|
+
// @ts-expect-error - TS2769 - No overload matches this call.
|
|
196
197
|
values.map(v => [negate ? '!=' : '==', get, v])
|
|
197
198
|
);
|
|
198
199
|
}
|
|
@@ -1,21 +1,36 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import {createExpression} from '../expression/index.js';
|
|
4
|
-
import {isFeatureConstant} from '../expression/is_constant.js';
|
|
5
|
-
import {deepUnbundle} from '../util/unbundle_jsonlint.js';
|
|
6
|
-
import latest from '../reference/latest.js';
|
|
7
|
-
import type {GlobalProperties, Feature} from '../expression/index.js';
|
|
8
|
-
import type {CanonicalTileID} from '../../source/tile_id.js';
|
|
9
1
|
import type Point from '@mapbox/point-geometry';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
import latest from '../reference/latest';
|
|
3
|
+
|
|
4
|
+
import {deepUnbundle} from '../util/unbundle_jsonlint';
|
|
5
|
+
import {createExpression} from '../expression/index';
|
|
6
|
+
import {isFeatureConstant} from '../expression/is_constant';
|
|
7
|
+
import type {CanonicalTileID} from '../types/tile_id';
|
|
8
|
+
import type {GlobalProperties, Feature} from '../expression/index';
|
|
9
|
+
import type {FilterSpecification, ExpressionSpecification} from '../types';
|
|
10
|
+
|
|
11
|
+
export type FeatureDistanceData = {
|
|
12
|
+
bearing: [number, number];
|
|
13
|
+
center: [number, number];
|
|
14
|
+
scale: number;
|
|
15
|
+
};
|
|
16
|
+
export type FilterExpression = (
|
|
17
|
+
globalProperties: GlobalProperties,
|
|
18
|
+
feature: Feature,
|
|
19
|
+
canonical?: CanonicalTileID,
|
|
20
|
+
featureTileCoord?: Point,
|
|
21
|
+
featureDistanceData?: FeatureDistanceData,
|
|
22
|
+
) => boolean;
|
|
23
|
+
export type FeatureFilter = {
|
|
24
|
+
filter: FilterExpression;
|
|
25
|
+
dynamicFilter?: FilterExpression;
|
|
26
|
+
needGeometry: boolean;
|
|
27
|
+
needFeature: boolean;
|
|
28
|
+
};
|
|
14
29
|
|
|
15
30
|
export default createFilter;
|
|
16
31
|
export {isExpressionFilter, isDynamicFilter, extractStaticFilter};
|
|
17
32
|
|
|
18
|
-
function isExpressionFilter(filter:
|
|
33
|
+
function isExpressionFilter(filter: unknown): boolean {
|
|
19
34
|
if (filter === true || filter === false) {
|
|
20
35
|
return true;
|
|
21
36
|
}
|
|
@@ -67,21 +82,21 @@ function isExpressionFilter(filter: any): boolean {
|
|
|
67
82
|
* @param {string} layerType the type of the layer this filter will be applied to.
|
|
68
83
|
* @returns {Function} filter-evaluating function
|
|
69
84
|
*/
|
|
70
|
-
function createFilter(filter
|
|
85
|
+
function createFilter(filter?: FilterSpecification | ExpressionSpecification, layerType: string = 'fill'): FeatureFilter {
|
|
71
86
|
if (filter === null || filter === undefined) {
|
|
72
87
|
return {filter: () => true, needGeometry: false, needFeature: false};
|
|
73
88
|
}
|
|
74
89
|
|
|
75
90
|
if (!isExpressionFilter(filter)) {
|
|
76
|
-
|
|
77
|
-
filter = convertFilter(filter);
|
|
91
|
+
filter = convertFilter(filter) as ExpressionSpecification;
|
|
78
92
|
}
|
|
79
|
-
|
|
93
|
+
|
|
94
|
+
const filterExp = (filter as string[] | string | boolean);
|
|
80
95
|
|
|
81
96
|
let staticFilter = true;
|
|
82
97
|
try {
|
|
83
98
|
staticFilter = extractStaticFilter(filterExp);
|
|
84
|
-
} catch (e) {
|
|
99
|
+
} catch (e: any) {
|
|
85
100
|
console.warn(
|
|
86
101
|
`Failed to extract static filter. Filter will continue working, but at higher memory usage and slower framerate.
|
|
87
102
|
This is most likely a bug, please report this via https://github.com/mapbox/mapbox-gl-js/issues/new?assignees=&labels=&template=Bug_report.md
|
|
@@ -118,7 +133,7 @@ ${JSON.stringify(filterExp, null, 2)}
|
|
|
118
133
|
}
|
|
119
134
|
}
|
|
120
135
|
|
|
121
|
-
filterFunc = (
|
|
136
|
+
filterFunc = (filterFunc as FilterExpression);
|
|
122
137
|
const needGeometry = geometryNeeded(staticFilter);
|
|
123
138
|
|
|
124
139
|
return {
|
|
@@ -267,7 +282,7 @@ function geometryNeeded(filter: Array<any> | boolean) {
|
|
|
267
282
|
return false;
|
|
268
283
|
}
|
|
269
284
|
|
|
270
|
-
function convertFilter(filter
|
|
285
|
+
function convertFilter(filter?: Array<any> | null): unknown {
|
|
271
286
|
if (!filter) return true;
|
|
272
287
|
const op = filter[0];
|
|
273
288
|
if (filter.length <= 1) return (op !== 'any');
|
|
@@ -279,7 +294,9 @@ function convertFilter(filter: ?Array<any>): mixed {
|
|
|
279
294
|
op === '<=' ||
|
|
280
295
|
op === '>=' ? convertComparisonOp(filter[1], filter[2], op) :
|
|
281
296
|
op === 'any' ? convertDisjunctionOp(filter.slice(1)) :
|
|
297
|
+
// @ts-expect-error - TS2769 - No overload matches this call.
|
|
282
298
|
op === 'all' ? ['all'].concat(filter.slice(1).map(convertFilter)) :
|
|
299
|
+
// @ts-expect-error - TS2769 - No overload matches this call.
|
|
283
300
|
op === 'none' ? ['all'].concat(filter.slice(1).map(convertFilter).map(convertNegation)) :
|
|
284
301
|
op === 'in' ? convertInOp(filter[1], filter.slice(2)) :
|
|
285
302
|
op === '!in' ? convertNegation(convertInOp(filter[1], filter.slice(2))) :
|
|
@@ -301,6 +318,7 @@ function convertComparisonOp(property: string, value: any, op: string) {
|
|
|
301
318
|
}
|
|
302
319
|
|
|
303
320
|
function convertDisjunctionOp(filters: Array<Array<any>>) {
|
|
321
|
+
// @ts-expect-error - TS2769 - No overload matches this call.
|
|
304
322
|
return ['any'].concat(filters.map(convertFilter));
|
|
305
323
|
}
|
|
306
324
|
|
|
@@ -331,6 +349,6 @@ function convertHasOp(property: string) {
|
|
|
331
349
|
}
|
|
332
350
|
}
|
|
333
351
|
|
|
334
|
-
function convertNegation(filter:
|
|
352
|
+
function convertNegation(filter: unknown) {
|
|
335
353
|
return ['!', filter];
|
|
336
354
|
}
|
package/{format.js → format.ts}
RENAMED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
// @
|
|
1
|
+
// @ts-nocheck
|
|
2
2
|
|
|
3
|
-
import reference from './reference/latest
|
|
3
|
+
import reference from './reference/latest';
|
|
4
4
|
import stringifyPretty from 'json-stringify-pretty-compact';
|
|
5
5
|
|
|
6
6
|
function sortKeysBy(obj, reference) {
|
|
7
|
-
const result = {};
|
|
7
|
+
const result: Record<string, any> = {};
|
|
8
8
|
for (const key in reference) {
|
|
9
9
|
if (obj[key] !== undefined) {
|
|
10
10
|
result[key] = obj[key];
|