@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.
Files changed (142) hide show
  1. package/bin/gl-style-composite.js +0 -5
  2. package/bin/gl-style-format.js +0 -5
  3. package/bin/gl-style-migrate.js +0 -5
  4. package/bin/gl-style-validate.js +0 -5
  5. package/{composite.js → composite.ts} +1 -1
  6. package/data/{extent.js → extent.ts} +0 -2
  7. package/{deref.js → deref.ts} +7 -9
  8. package/{diff.js → diff.ts} +44 -21
  9. package/dist/index.cjs +794 -1226
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.ts +1746 -0
  12. package/dist/index.es.js +794 -1226
  13. package/dist/index.es.js.map +1 -1
  14. package/{empty.js → empty.ts} +1 -2
  15. package/error/{parsing_error.js → parsing_error.ts} +0 -2
  16. package/error/{validation_error.js → validation_error.ts} +5 -5
  17. package/expression/{compound_expression.js → compound_expression.ts} +29 -19
  18. package/expression/definitions/{assertion.js → assertion.ts} +16 -13
  19. package/expression/definitions/{at.js → at.ts} +12 -13
  20. package/expression/definitions/{case.js → case.ts} +12 -11
  21. package/expression/definitions/{coalesce.js → coalesce.ts} +11 -11
  22. package/expression/definitions/{coercion.js → coercion.ts} +21 -20
  23. package/expression/definitions/{collator.js → collator.ts} +11 -11
  24. package/expression/definitions/{comparison.js → comparison.ts} +30 -24
  25. package/expression/definitions/{config.js → config.ts} +16 -16
  26. package/expression/definitions/{distance.js → distance.ts} +60 -52
  27. package/expression/definitions/{format.js → format.ts} +26 -15
  28. package/expression/definitions/{image.js → image.ts} +12 -12
  29. package/expression/definitions/{in.js → in.ts} +22 -13
  30. package/expression/definitions/{index.js → index.ts} +70 -83
  31. package/expression/definitions/{index_of.js → index_of.ts} +24 -15
  32. package/expression/definitions/{interpolate.js → interpolate.ts} +44 -25
  33. package/expression/definitions/{length.js → length.ts} +11 -10
  34. package/expression/definitions/{let.js → let.ts} +10 -7
  35. package/expression/definitions/{literal.js → literal.ts} +11 -12
  36. package/expression/definitions/{match.js → match.ts} +25 -15
  37. package/expression/definitions/{number_format.js → number_format.ts} +10 -10
  38. package/expression/definitions/{slice.js → slice.ts} +23 -15
  39. package/expression/definitions/{step.js → step.ts} +14 -12
  40. package/expression/definitions/{var.js → var.ts} +5 -7
  41. package/expression/definitions/{within.js → within.ts} +41 -29
  42. package/expression/{evaluation_context.js → evaluation_context.ts} +26 -23
  43. package/expression/expression.ts +29 -0
  44. package/expression/{index.js → index.ts} +208 -110
  45. package/expression/{is_constant.js → is_constant.ts} +5 -7
  46. package/expression/{parsing_context.js → parsing_context.ts} +47 -34
  47. package/expression/{parsing_error.js → parsing_error.ts} +0 -2
  48. package/expression/{runtime_error.js → runtime_error.ts} +0 -2
  49. package/expression/{scope.js → scope.ts} +5 -5
  50. package/expression/{stops.js → stops.ts} +2 -4
  51. package/expression/types/{collator.js → collator.ts} +1 -3
  52. package/expression/types/{formatted.js → formatted.ts} +8 -7
  53. package/expression/types/{resolved_image.js → resolved_image.ts} +5 -7
  54. package/expression/{types.js → types.ts} +53 -45
  55. package/expression/{values.js → values.ts} +12 -12
  56. package/feature_filter/{convert.js → convert.ts} +19 -18
  57. package/feature_filter/{index.js → index.ts} +39 -21
  58. package/{format.js → format.ts} +3 -3
  59. package/function/{convert.js → convert.ts} +44 -44
  60. package/function/{index.js → index.ts} +12 -12
  61. package/{group_by_layout.js → group_by_layout.ts} +11 -8
  62. package/migrate/{expressions.js → expressions.ts} +7 -16
  63. package/migrate/{v8.js → v8.ts} +2 -2
  64. package/migrate/{v9.js → v9.ts} +2 -2
  65. package/{migrate.js → migrate.ts} +3 -3
  66. package/package.json +19 -18
  67. package/{read_style.js → read_style.ts} +5 -4
  68. package/reference/latest.ts +5 -0
  69. package/reference/v8.json +264 -7
  70. package/rollup.config.js +6 -24
  71. package/{style-spec.js → style-spec.ts} +41 -36
  72. package/test.js +3 -2
  73. package/types/config_options.ts +13 -0
  74. package/types/lut.ts +7 -0
  75. package/types/tile_id.ts +5 -0
  76. package/{types.js → types.ts} +527 -165
  77. package/util/{color.js → color.ts} +89 -3
  78. package/util/{color_spaces.js → color_spaces.ts} +12 -14
  79. package/util/{deep_equal.js → deep_equal.ts} +1 -3
  80. package/util/{extend.js → extend.ts} +1 -3
  81. package/util/{geometry_util.js → geometry_util.ts} +23 -11
  82. package/util/{get_type.js → get_type.ts} +1 -3
  83. package/util/{interpolate.js → interpolate.ts} +1 -3
  84. package/util/{properties.js → properties.ts} +5 -4
  85. package/util/{random.js → random.ts} +0 -2
  86. package/util/{ref_properties.js → ref_properties.ts} +0 -1
  87. package/util/{result.js → result.ts} +7 -5
  88. package/util/{unbundle_jsonlint.js → unbundle_jsonlint.ts} +5 -5
  89. package/validate/{validate.js → validate.ts} +33 -35
  90. package/validate/{validate_array.js → validate_array.ts} +5 -7
  91. package/validate/{validate_boolean.js → validate_boolean.ts} +3 -5
  92. package/validate/{validate_color.js → validate_color.ts} +3 -5
  93. package/validate/{validate_enum.js → validate_enum.ts} +4 -5
  94. package/validate/{validate_expression.js → validate_expression.ts} +7 -9
  95. package/validate/{validate_filter.js → validate_filter.ts} +16 -12
  96. package/validate/{validate_fog.js → validate_fog.ts} +4 -6
  97. package/validate/validate_formatted.ts +13 -0
  98. package/validate/{validate_function.js → validate_function.ts} +14 -16
  99. package/validate/{validate_glyphs_url.js → validate_glyphs_url.ts} +3 -5
  100. package/validate/validate_image.ts +13 -0
  101. package/validate/{validate_import.js → validate_import.ts} +6 -8
  102. package/validate/{validate_layer.js → validate_layer.ts} +17 -15
  103. package/validate/{validate_layout_property.js → validate_layout_property.ts} +3 -5
  104. package/validate/{validate_light.js → validate_light.ts} +4 -6
  105. package/validate/{validate_lights.js → validate_lights.ts} +7 -9
  106. package/validate/{validate_model.js → validate_model.ts} +4 -6
  107. package/validate/{validate_number.js → validate_number.ts} +4 -6
  108. package/validate/{validate_object.js → validate_object.ts} +5 -8
  109. package/validate/{validate_paint_property.js → validate_paint_property.ts} +3 -5
  110. package/validate/{validate_projection.js → validate_projection.ts} +4 -6
  111. package/validate/{validate_property.js → validate_property.ts} +15 -15
  112. package/validate/{validate_source.js → validate_source.ts} +16 -13
  113. package/validate/validate_string.ts +16 -0
  114. package/validate/validate_style.ts +33 -0
  115. package/validate/{validate_terrain.js → validate_terrain.ts} +5 -7
  116. package/{validate_mapbox_api_supported.js → validate_mapbox_api_supported.ts} +22 -18
  117. package/{validate_style.min.js → validate_style.min.ts} +20 -21
  118. package/{validate_style.js → validate_style.ts} +9 -9
  119. package/{visit.js → visit.ts} +22 -17
  120. package/.eslintrc +0 -10
  121. package/expression/expression.js +0 -28
  122. package/flow-typed/cheap-ruler.js +0 -25
  123. package/flow-typed/geojson.js +0 -44
  124. package/flow-typed/gl-matrix.js +0 -119
  125. package/flow-typed/gl.js +0 -5
  126. package/flow-typed/intl.js +0 -58
  127. package/flow-typed/kdbush.js +0 -9
  128. package/flow-typed/mapbox-gl-supported.js +0 -16
  129. package/flow-typed/mapbox-unitbezier.js +0 -14
  130. package/flow-typed/offscreen-canvas.js +0 -9
  131. package/flow-typed/pbf.js +0 -26
  132. package/flow-typed/point-geometry.js +0 -46
  133. package/flow-typed/potpack.js +0 -13
  134. package/flow-typed/tiny-sdf.js +0 -31
  135. package/flow-typed/tracked_parameters_proxy.js +0 -82
  136. package/flow-typed/vector-tile.js +0 -49
  137. package/flow-typed/webgl2.js +0 -41
  138. package/reference/latest.js +0 -7
  139. package/validate/validate_formatted.js +0 -15
  140. package/validate/validate_image.js +0 -15
  141. package/validate/validate_string.js +0 -18
  142. package/validate/validate_style.js +0 -29
@@ -1,6 +1,6 @@
1
- // @flow
2
-
3
1
  import {parseCSSColor} from 'csscolorparser';
2
+ import {number as lerp} from './interpolate';
3
+ import type {LUT} from '../types/lut';
4
4
 
5
5
  /**
6
6
  * An RGBA color value. Create instances from color strings using the static
@@ -73,10 +73,96 @@ class Color {
73
73
  * translucentGreen.toString(); // = "rgba(26,207,26,0.73)"
74
74
  */
75
75
  toString(): string {
76
- const [r, g, b, a] = this.toArray();
76
+ const [r, g, b, a] = this.a === 0 ? [0, 0, 0, 0] : [
77
+ this.r * 255 / this.a,
78
+ this.g * 255 / this.a,
79
+ this.b * 255 / this.a,
80
+ this.a
81
+ ];
77
82
  return `rgba(${Math.round(r)},${Math.round(g)},${Math.round(b)},${a})`;
78
83
  }
79
84
 
85
+ toRenderColor(lut: LUT | null): RenderColor {
86
+ const {r, g, b, a} = this;
87
+ return new RenderColor(lut, r, g, b, a);
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Renderable color created from a Color and an optional LUT value
93
+ */
94
+ export class RenderColor {
95
+ r: number;
96
+ g: number;
97
+ b: number;
98
+ a: number;
99
+
100
+ constructor(lut: LUT | null, r: number, g: number, b: number, a: number) {
101
+ if (!lut) {
102
+ this.r = r;
103
+ this.g = g;
104
+ this.b = b;
105
+ this.a = a;
106
+ } else {
107
+ const N = lut.image.height;
108
+ const N2 = N * N;
109
+ // Normalize to cube dimensions.
110
+ r = a === 0 ? 0 : (r / a) * (N - 1);
111
+ g = a === 0 ? 0 : (g / a) * (N - 1);
112
+ b = a === 0 ? 0 : (b / a) * (N - 1);
113
+
114
+ // Determine boundary values for the cube the color is in.
115
+ const r0 = Math.floor(r);
116
+ const g0 = Math.floor(g);
117
+ const b0 = Math.floor(b);
118
+ const r1 = Math.ceil(r);
119
+ const g1 = Math.ceil(g);
120
+ const b1 = Math.ceil(b);
121
+
122
+ // Determine weights within the cube.
123
+ const rw = r - r0;
124
+ const gw = g - g0;
125
+ const bw = b - b0;
126
+
127
+ const data = lut.image.data;
128
+ const i0 = (r0 + g0 * N2 + b0 * N) * 4;
129
+ const i1 = (r0 + g0 * N2 + b1 * N) * 4;
130
+ const i2 = (r0 + g1 * N2 + b0 * N) * 4;
131
+ const i3 = (r0 + g1 * N2 + b1 * N) * 4;
132
+ const i4 = (r1 + g0 * N2 + b0 * N) * 4;
133
+ const i5 = (r1 + g0 * N2 + b1 * N) * 4;
134
+ const i6 = (r1 + g1 * N2 + b0 * N) * 4;
135
+ const i7 = (r1 + g1 * N2 + b1 * N) * 4;
136
+ if (i0 < 0 || i7 >= data.length) {
137
+ throw new Error("out of range");
138
+ }
139
+
140
+ // Trilinear interpolation.
141
+ this.r = lerp(
142
+ lerp(
143
+ lerp(data[i0], data[i1], bw),
144
+ lerp(data[i2], data[i3], bw), gw),
145
+ lerp(
146
+ lerp(data[i4], data[i5], bw),
147
+ lerp(data[i6], data[i7], bw), gw), rw) / 255 * a;
148
+ this.g = lerp(
149
+ lerp(
150
+ lerp(data[i0 + 1], data[i1 + 1], bw),
151
+ lerp(data[i2 + 1], data[i3 + 1], bw), gw),
152
+ lerp(
153
+ lerp(data[i4 + 1], data[i5 + 1], bw),
154
+ lerp(data[i6 + 1], data[i7 + 1], bw), gw), rw) / 255 * a;
155
+ this.b = lerp(
156
+ lerp(
157
+ lerp(data[i0 + 2], data[i1 + 2], bw),
158
+ lerp(data[i2 + 2], data[i3 + 2], bw), gw),
159
+ lerp(
160
+ lerp(data[i4 + 2], data[i5 + 2], bw),
161
+ lerp(data[i6 + 2], data[i7 + 2], bw), gw), rw) / 255 * a;
162
+ this.a = a;
163
+ }
164
+ }
165
+
80
166
  /**
81
167
  * Returns an RGBA array of values representing the color, unpremultiplied by A.
82
168
  *
@@ -1,21 +1,19 @@
1
- // @flow
1
+ import Color from './color';
2
2
 
3
- import Color from './color.js';
4
-
5
- import {number as interpolateNumber} from './interpolate.js';
3
+ import {number as interpolateNumber} from './interpolate';
6
4
 
7
5
  type LABColor = {
8
- l: number,
9
- a: number,
10
- b: number,
11
- alpha: number
6
+ l: number;
7
+ a: number;
8
+ b: number;
9
+ alpha: number;
12
10
  };
13
11
 
14
12
  type HCLColor = {
15
- h: number,
16
- c: number,
17
- l: number,
18
- alpha: number
13
+ h: number;
14
+ c: number;
15
+ l: number;
16
+ alpha: number;
19
17
  };
20
18
 
21
19
  // Constants
@@ -130,10 +128,10 @@ export const lab = {
130
128
  forward: rgbToLab,
131
129
  reverse: labToRgb,
132
130
  interpolate: interpolateLab
133
- };
131
+ } as const;
134
132
 
135
133
  export const hcl = {
136
134
  forward: rgbToHcl,
137
135
  reverse: hclToRgb,
138
136
  interpolate: interpolateHcl
139
- };
137
+ } as const;
@@ -1,11 +1,9 @@
1
- // @flow
2
-
3
1
  /**
4
2
  * Deeply compares two object literals.
5
3
  *
6
4
  * @private
7
5
  */
8
- function deepEqual(a: ?mixed, b: ?mixed): boolean {
6
+ function deepEqual(a?: unknown | null, b?: unknown | null): boolean {
9
7
  if (Array.isArray(a)) {
10
8
  if (!Array.isArray(b) || a.length !== b.length) return false;
11
9
  for (let i = 0; i < a.length; i++) {
@@ -1,6 +1,4 @@
1
- // @flow
2
-
3
- export default function (output: any, ...inputs: Array<any>): any {
1
+ export default function(output: any, ...inputs: Array<any>): any {
4
2
  for (const input of inputs) {
5
3
  for (const k in input) {
6
4
  output[k] = input[k];
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import type Point from '@mapbox/point-geometry';
3
2
  import quickselect from 'quickselect';
4
3
 
@@ -22,7 +21,11 @@ function calculateSignedArea(ring: Array<Point>): number {
22
21
  return sum;
23
22
  }
24
23
 
25
- function compareAreas(a: {area: number}, b: {area: number}) {
24
+ function compareAreas(a: {
25
+ area: number;
26
+ }, b: {
27
+ area: number;
28
+ }) {
26
29
  return b.area - a.area;
27
30
  }
28
31
 
@@ -40,7 +43,7 @@ export function classifyRings(rings: Array<Array<Point>>, maxRings: number): Arr
40
43
  const area = calculateSignedArea(rings[i]);
41
44
  if (area === 0) continue;
42
45
 
43
- (rings[i]: any).area = Math.abs(area);
46
+ (rings[i] as any).area = Math.abs(area);
44
47
 
45
48
  if (ccw === undefined) ccw = area < 0;
46
49
 
@@ -49,7 +52,7 @@ export function classifyRings(rings: Array<Array<Point>>, maxRings: number): Arr
49
52
  polygon = [rings[i]];
50
53
 
51
54
  } else {
52
- (polygon: any).push(rings[i]);
55
+ (polygon).push(rings[i]);
53
56
  }
54
57
  }
55
58
  if (polygon) polygons.push(polygon);
@@ -67,7 +70,7 @@ export function classifyRings(rings: Array<Array<Point>>, maxRings: number): Arr
67
70
  return polygons;
68
71
  }
69
72
 
70
- export function updateBBox(bbox: BBox, coord: GeoJSONPosition) {
73
+ export function updateBBox(bbox: BBox, coord: GeoJSON.Position) {
71
74
  bbox[0] = Math.min(bbox[0], coord[0]);
72
75
  bbox[1] = Math.min(bbox[1], coord[1]);
73
76
  bbox[2] = Math.max(bbox[2], coord[0]);
@@ -82,7 +85,7 @@ export function boxWithinBox(bbox1: BBox, bbox2: BBox): boolean {
82
85
  return true;
83
86
  }
84
87
 
85
- function onBoundary(p: GeoJSONPosition, p1: GeoJSONPosition, p2: GeoJSONPosition) {
88
+ function onBoundary(p: GeoJSON.Position, p1: GeoJSON.Position, p2: GeoJSON.Position) {
86
89
  const x1 = p[0] - p1[0];
87
90
  const y1 = p[1] - p1[1];
88
91
  const x2 = p[0] - p2[0];
@@ -90,12 +93,16 @@ function onBoundary(p: GeoJSONPosition, p1: GeoJSONPosition, p2: GeoJSONPosition
90
93
  return (x1 * y2 - x2 * y1 === 0) && (x1 * x2 <= 0) && (y1 * y2 <= 0);
91
94
  }
92
95
 
93
- function rayIntersect(p: GeoJSONPosition, p1: GeoJSONPosition, p2: GeoJSONPosition) {
96
+ function rayIntersect(p: GeoJSON.Position, p1: GeoJSON.Position, p2: GeoJSON.Position) {
94
97
  return ((p1[1] > p[1]) !== (p2[1] > p[1])) && (p[0] < (p2[0] - p1[0]) * (p[1] - p1[1]) / (p2[1] - p1[1]) + p1[0]);
95
98
  }
96
99
 
97
100
  // ray casting algorithm for detecting if point is in polygon
98
- export function pointWithinPolygon(point: GeoJSONPosition, rings: Array<Array<GeoJSONPosition>>, trueOnBoundary: boolean = false): boolean {
101
+ export function pointWithinPolygon(
102
+ point: GeoJSON.Position,
103
+ rings: Array<Array<GeoJSON.Position>>,
104
+ trueOnBoundary: boolean = false,
105
+ ): boolean {
99
106
  let inside = false;
100
107
  for (let i = 0, len = rings.length; i < len; i++) {
101
108
  const ring = rings[i];
@@ -109,12 +116,12 @@ export function pointWithinPolygon(point: GeoJSONPosition, rings: Array<Array<Ge
109
116
  return inside;
110
117
  }
111
118
 
112
- function perp(v1: GeoJSONPosition, v2: GeoJSONPosition) {
119
+ function perp(v1: GeoJSON.Position, v2: GeoJSON.Position) {
113
120
  return v1[0] * v2[1] - v1[1] * v2[0];
114
121
  }
115
122
 
116
123
  // check if p1 and p2 are in different sides of line segment q1->q2
117
- function twoSided(p1: GeoJSONPosition, p2: GeoJSONPosition, q1: GeoJSONPosition, q2: GeoJSONPosition) {
124
+ function twoSided(p1: GeoJSON.Position, p2: GeoJSON.Position, q1: GeoJSON.Position, q2: GeoJSON.Position) {
118
125
  // q1->p1 (x1, y1), q1->p2 (x2, y2), q1->q2 (x3, y3)
119
126
  const x1 = p1[0] - q1[0];
120
127
  const y1 = p1[1] - q1[1];
@@ -128,7 +135,12 @@ function twoSided(p1: GeoJSONPosition, p2: GeoJSONPosition, q1: GeoJSONPosition,
128
135
  return false;
129
136
  }
130
137
  // a, b are end points for line segment1, c and d are end points for line segment2
131
- export function segmentIntersectSegment(a: GeoJSONPosition, b: GeoJSONPosition, c: GeoJSONPosition, d: GeoJSONPosition): boolean {
138
+ export function segmentIntersectSegment(
139
+ a: GeoJSON.Position,
140
+ b: GeoJSON.Position,
141
+ c: GeoJSON.Position,
142
+ d: GeoJSON.Position,
143
+ ): boolean {
132
144
  // check if two segments are parallel or not
133
145
  // precondition is end point a, b is inside polygon, if line a->b is
134
146
  // parallel to polygon edge c->d, then a->b won't intersect with c->d
@@ -1,6 +1,4 @@
1
- // @flow
2
-
3
- export default function getType(val: mixed): string {
1
+ export default function getType(val: unknown): string {
4
2
  if (val instanceof Number) {
5
3
  return 'number';
6
4
  } else if (val instanceof String) {
@@ -1,6 +1,4 @@
1
- // @flow
2
-
3
- import Color from './color.js';
1
+ import Color from './color';
4
2
 
5
3
  export function number(a: number, b: number, t: number): number {
6
4
  return (a * (1 - t)) + (b * t);
@@ -1,10 +1,11 @@
1
- // @flow
2
-
3
- import type {ExpressionSpecification, StylePropertySpecification} from '../style-spec.js';
1
+ import type {ExpressionSpecification, StylePropertySpecification} from '../style-spec';
4
2
 
5
3
  type ExpressionParameter = ExpressionSpecification['parameters'][number];
6
4
 
7
- function expressionHasParameter(expression: ?ExpressionSpecification, parameter: ExpressionParameter): boolean {
5
+ function expressionHasParameter(
6
+ expression: ExpressionSpecification | null | undefined,
7
+ parameter: ExpressionParameter,
8
+ ): boolean {
8
9
  return !!expression && !!expression.parameters && expression.parameters.indexOf(parameter) > -1;
9
10
  }
10
11
 
@@ -1,5 +1,3 @@
1
- // @flow
2
-
3
1
  // Seeded pseudo random generator function
4
2
  export function mulberry32(a: number): () => number {
5
3
  return function () {
@@ -1,2 +1 @@
1
- // @flow
2
1
  export default ['type', 'source', 'source-layer', 'minzoom', 'maxzoom', 'filter', 'layout'];
@@ -1,14 +1,16 @@
1
- // @flow
2
-
3
1
  /**
4
2
  * A type used for returning and propagating errors. The first element of the union
5
3
  * represents success and contains a value, and the second represents an error and
6
4
  * contains an error value.
7
5
  * @private
8
6
  */
9
- export type Result<T, E> =
10
- | {| result: 'success', value: T |}
11
- | {| result: 'error', value: E |};
7
+ export type Result<T, E> = {
8
+ result: 'success';
9
+ value: T;
10
+ } | {
11
+ result: 'error';
12
+ value: E;
13
+ };
12
14
 
13
15
  export function success<T, E>(value: T): Result<T, E> {
14
16
  return {result: 'success', value};
@@ -1,7 +1,5 @@
1
- // @flow
2
-
3
1
  // Turn jsonlint-lines-primitives objects into primitive objects
4
- export function unbundle(value: mixed): mixed {
2
+ export function unbundle(value: unknown): unknown {
5
3
  if (value instanceof Number || value instanceof String || value instanceof Boolean) {
6
4
  return value.valueOf();
7
5
  } else {
@@ -9,11 +7,13 @@ export function unbundle(value: mixed): mixed {
9
7
  }
10
8
  }
11
9
 
12
- export function deepUnbundle(value: mixed): mixed {
10
+ export function deepUnbundle(value: unknown): unknown {
13
11
  if (Array.isArray(value)) {
14
12
  return value.map(deepUnbundle);
15
13
  } else if (value instanceof Object && !(value instanceof Number || value instanceof String || value instanceof Boolean)) {
16
- const unbundledValue: { [key: string]: mixed } = {};
14
+ const unbundledValue: {
15
+ [key: string]: unknown;
16
+ } = {};
17
17
  for (const key in value) {
18
18
  unbundledValue[key] = deepUnbundle(value[key]);
19
19
  }
@@ -1,36 +1,34 @@
1
- // @flow
1
+ import extend from '../util/extend';
2
+ import ValidationError from '../error/validation_error';
3
+ import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint';
4
+ import {isExpression} from '../expression/index';
5
+ import {isFunction} from '../function/index';
2
6
 
3
- import extend from '../util/extend.js';
4
- import ValidationError from '../error/validation_error.js';
5
- import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint.js';
6
- import {isExpression} from '../expression/index.js';
7
- import {isFunction} from '../function/index.js';
7
+ import validateImport from './validate_import';
8
+ import validateFunction from './validate_function';
9
+ import validateExpression from './validate_expression';
10
+ import validateObject from './validate_object';
11
+ import validateArray from './validate_array';
12
+ import validateBoolean from './validate_boolean';
13
+ import validateNumber from './validate_number';
14
+ import validateColor from './validate_color';
15
+ import validateEnum from './validate_enum';
16
+ import validateFilter from './validate_filter';
17
+ import validateLayer from './validate_layer';
18
+ import validateSource from './validate_source';
19
+ import validateModel from './validate_model';
20
+ import validateLight from './validate_light';
21
+ import validateLights from './validate_lights';
22
+ import validateTerrain from './validate_terrain';
23
+ import validateFog from './validate_fog';
24
+ import validateString from './validate_string';
25
+ import validateFormatted from './validate_formatted';
26
+ import validateImage from './validate_image';
27
+ import validateProjection from './validate_projection';
8
28
 
9
- import validateImport from './validate_import.js';
10
- import validateFunction from './validate_function.js';
11
- import validateExpression from './validate_expression.js';
12
- import validateObject from './validate_object.js';
13
- import validateArray from './validate_array.js';
14
- import validateBoolean from './validate_boolean.js';
15
- import validateNumber from './validate_number.js';
16
- import validateColor from './validate_color.js';
17
- import validateEnum from './validate_enum.js';
18
- import validateFilter from './validate_filter.js';
19
- import validateLayer from './validate_layer.js';
20
- import validateSource from './validate_source.js';
21
- import validateModel from './validate_model.js';
22
- import validateLight from './validate_light.js';
23
- import validateLights from './validate_lights.js';
24
- import validateTerrain from './validate_terrain.js';
25
- import validateFog from './validate_fog.js';
26
- import validateString from './validate_string.js';
27
- import validateFormatted from './validate_formatted.js';
28
- import validateImage from './validate_image.js';
29
- import validateProjection from './validate_projection.js';
30
-
31
- import type {StyleReference} from '../reference/latest.js';
32
- import type {StyleSpecification} from '../types.js';
33
- import getType from '../util/get_type.js';
29
+ import type {StyleReference} from '../reference/latest';
30
+ import type {StyleSpecification} from '../types';
31
+ import getType from '../util/get_type';
34
32
 
35
33
  const VALIDATORS = {
36
34
  '*'() {
@@ -69,11 +67,11 @@ const VALIDATORS = {
69
67
  // - styleSpec: current full spec being evaluated.
70
68
  export type ValidationOptions = {
71
69
  key: string;
72
- value: Object;
73
- valueSpec: Object;
74
- style: $Shape<StyleSpecification>;
70
+ value: any;
71
+ valueSpec?: any;
72
+ style: Partial<StyleSpecification>;
75
73
  styleSpec: StyleReference;
76
- }
74
+ };
77
75
 
78
76
  export default function validate(options: ValidationOptions, arrayAsExpression: boolean = false): Array<ValidationError> {
79
77
  const value = options.value;
@@ -1,13 +1,11 @@
1
- // @flow
1
+ import getType from '../util/get_type';
2
+ import validate from './validate';
3
+ import ValidationError from '../error/validation_error';
2
4
 
3
- import getType from '../util/get_type.js';
4
- import validate from './validate.js';
5
- import ValidationError from '../error/validation_error.js';
6
-
7
- import type {ValidationOptions} from './validate.js';
5
+ import type {ValidationOptions} from './validate';
8
6
 
9
7
  type Options = ValidationOptions & {
10
- arrayElementValidator: Function;
8
+ arrayElementValidator: any;
11
9
  };
12
10
 
13
11
  export default function validateArray(options: Options): Array<ValidationError> {
@@ -1,9 +1,7 @@
1
- // @flow
1
+ import getType from '../util/get_type';
2
+ import ValidationError from '../error/validation_error';
2
3
 
3
- import getType from '../util/get_type.js';
4
- import ValidationError from '../error/validation_error.js';
5
-
6
- import type {ValidationOptions} from './validate.js';
4
+ import type {ValidationOptions} from './validate';
7
5
 
8
6
  export default function validateBoolean(options: ValidationOptions): Array<ValidationError> {
9
7
  const value = options.value;
@@ -1,10 +1,8 @@
1
- // @flow
2
-
3
- import ValidationError from '../error/validation_error.js';
4
- import getType from '../util/get_type.js';
1
+ import ValidationError from '../error/validation_error';
2
+ import getType from '../util/get_type';
5
3
  import {parseCSSColor} from 'csscolorparser';
6
4
 
7
- import type {ValidationOptions} from './validate.js';
5
+ import type {ValidationOptions} from './validate';
8
6
 
9
7
  export default function validateColor(options: ValidationOptions): Array<ValidationError> {
10
8
  const key = options.key;
@@ -1,9 +1,7 @@
1
- // @flow
1
+ import ValidationError from '../error/validation_error';
2
+ import {unbundle} from '../util/unbundle_jsonlint';
2
3
 
3
- import ValidationError from '../error/validation_error.js';
4
- import {unbundle} from '../util/unbundle_jsonlint.js';
5
-
6
- import type {ValidationOptions} from './validate.js';
4
+ import type {ValidationOptions} from './validate';
7
5
 
8
6
  export default function validateEnum(options: ValidationOptions): Array<ValidationError> {
9
7
  const key = options.key;
@@ -16,6 +14,7 @@ export default function validateEnum(options: ValidationOptions): Array<Validati
16
14
  errors.push(new ValidationError(key, value, `expected one of [${valueSpec.values.join(', ')}], ${JSON.stringify(value)} found`));
17
15
  }
18
16
  } else { // >=v8
17
+ // @ts-expect-error - TS2345 - Argument of type 'unknown' is not assignable to parameter of type 'string'.
19
18
  if (Object.keys(valueSpec.values).indexOf(unbundle(value)) === -1) {
20
19
  errors.push(new ValidationError(key, value, `expected one of [${Object.keys(valueSpec.values).join(', ')}], ${JSON.stringify(value)} found`));
21
20
  }
@@ -1,13 +1,11 @@
1
- // @flow
1
+ import ValidationError from '../error/validation_error';
2
2
 
3
- import ValidationError from '../error/validation_error.js';
3
+ import {createExpression, createPropertyExpression} from '../expression/index';
4
+ import {deepUnbundle} from '../util/unbundle_jsonlint';
5
+ import {isStateConstant, isGlobalPropertyConstant, isFeatureConstant} from '../expression/is_constant';
6
+ import CompoundExpression from '../expression/compound_expression';
4
7
 
5
- import {createExpression, createPropertyExpression} from '../expression/index.js';
6
- import {deepUnbundle} from '../util/unbundle_jsonlint.js';
7
- import {isStateConstant, isGlobalPropertyConstant, isFeatureConstant} from '../expression/is_constant.js';
8
- import CompoundExpression from '../expression/compound_expression.js';
9
-
10
- import type {Expression} from '../expression/expression.js';
8
+ import type {Expression} from '../expression/expression';
11
9
 
12
10
  export default function validateExpression(options: any): Array<ValidationError> {
13
11
  const expression = (options.expressionContext === 'property' ? createPropertyExpression : createExpression)(deepUnbundle(options.value), options.valueSpec);
@@ -17,7 +15,7 @@ export default function validateExpression(options: any): Array<ValidationError>
17
15
  });
18
16
  }
19
17
 
20
- const expressionObj = (expression.value: any).expression || (expression.value: any)._styleExpression.expression;
18
+ const expressionObj = (expression.value as any).expression || (expression.value as any)._styleExpression.expression;
21
19
 
22
20
  if (options.expressionContext === 'property' && (options.propertyKey === 'text-font') &&
23
21
  !expressionObj.outputDefined()) {
@@ -1,18 +1,20 @@
1
- // @flow
1
+ import ValidationError from '../error/validation_error';
2
+ import validateExpression from './validate_expression';
3
+ import validateEnum from './validate_enum';
4
+ import getType from '../util/get_type';
5
+ import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint';
6
+ import extend from '../util/extend';
7
+ import {isExpressionFilter} from '../feature_filter/index';
2
8
 
3
- import ValidationError from '../error/validation_error.js';
4
- import validateExpression from './validate_expression.js';
5
- import validateEnum from './validate_enum.js';
6
- import getType from '../util/get_type.js';
7
- import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint.js';
8
- import extend from '../util/extend.js';
9
- import {isExpressionFilter} from '../feature_filter/index.js';
10
-
11
- import type {ValidationOptions} from './validate.js';
9
+ import type {ValidationOptions} from './validate';
12
10
 
13
11
  type Options = ValidationOptions & {
14
12
  layerType?: string;
15
- }
13
+ object?: {
14
+ type?: string,
15
+ id?: string
16
+ }
17
+ };
16
18
 
17
19
  export default function validateFilter(options: Options): Array<ValidationError> {
18
20
  if (isExpressionFilter(deepUnbundle(options.value))) {
@@ -57,12 +59,14 @@ function validateNonExpressionFilter(options: Options) {
57
59
  case '<':
58
60
  case '<=':
59
61
  case '>':
62
+ // @ts-expect-error - falls through
60
63
  case '>=':
61
64
  if (value.length >= 2 && unbundle(value[1]) === '$type') {
62
65
  errors.push(new ValidationError(key, value, `"$type" cannot be use with operator "${value[0]}"`));
63
66
  }
64
67
  /* falls through */
65
68
  case '==':
69
+ // @ts-expect-error - falls through
66
70
  case '!=':
67
71
  if (value.length !== 3) {
68
72
  errors.push(new ValidationError(key, value, `filter array for operator "${value[0]}" must have 3 elements`));
@@ -101,7 +105,7 @@ function validateNonExpressionFilter(options: Options) {
101
105
  value: value[i],
102
106
  style: options.style,
103
107
  styleSpec: options.styleSpec
104
- }: any)));
108
+ } as any)));
105
109
  }
106
110
  break;
107
111
 
@@ -1,10 +1,8 @@
1
- // @flow
1
+ import {default as ValidationError, ValidationWarning} from '../error/validation_error';
2
+ import validate from './validate';
3
+ import getType from '../util/get_type';
2
4
 
3
- import {default as ValidationError, ValidationWarning} from '../error/validation_error.js';
4
- import validate from './validate.js';
5
- import getType from '../util/get_type.js';
6
-
7
- import type {ValidationOptions} from './validate.js';
5
+ import type {ValidationOptions} from './validate';
8
6
 
9
7
  export default function validateFog(options: ValidationOptions): Array<ValidationError> {
10
8
  const fog = options.value;
@@ -0,0 +1,13 @@
1
+ import validateExpression from './validate_expression';
2
+ import validateString from './validate_string';
3
+
4
+ import type {ValidationOptions} from './validate';
5
+ import type ValidationError from '../error/validation_error';
6
+
7
+ export default function validateFormatted(options: ValidationOptions): Array<ValidationError> {
8
+ if (validateString(options).length === 0) {
9
+ return [];
10
+ }
11
+
12
+ return validateExpression(options);
13
+ }