@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,18 +1,16 @@
1
- // @flow
2
-
3
- import {isValue} from '../values.js';
4
- import type {Type} from '../types.js';
5
- import {BooleanType} from '../types.js';
6
- import type {Expression, SerializedExpression} from '../expression.js';
7
- import type ParsingContext from '../parsing_context.js';
8
- import type EvaluationContext from '../evaluation_context.js';
1
+ import {isValue} from '../values';
2
+ import type {Type} from '../types';
3
+ import {BooleanType} from '../types';
4
+ import type {Expression, SerializedExpression} from '../expression';
5
+ import type ParsingContext from '../parsing_context';
6
+ import type EvaluationContext from '../evaluation_context';
9
7
  import type Point from '@mapbox/point-geometry';
10
- import type {GeoJSON, GeoJSONPosition, GeoJSONPolygon, GeoJSONMultiPolygon} from '@mapbox/geojson-types';
11
- import type {CanonicalTileID} from '../../../source/tile_id.js';
12
- import {updateBBox, boxWithinBox, pointWithinPolygon, segmentIntersectSegment} from '../../util/geometry_util.js';
13
- import type {BBox} from '../../util/geometry_util.js';
8
+ import type {CanonicalTileID} from '../../types/tile_id';
14
9
 
15
- type GeoJSONPolygons =| GeoJSONPolygon | GeoJSONMultiPolygon;
10
+ import {updateBBox, boxWithinBox, pointWithinPolygon, segmentIntersectSegment} from '../../util/geometry_util';
11
+ import type {BBox} from '../../util/geometry_util';
12
+
13
+ type GeoJSONPolygons = GeoJSON.Polygon | GeoJSON.MultiPolygon;
16
14
 
17
15
  const EXTENT = 8192;
18
16
 
@@ -24,21 +22,21 @@ function mercatorYfromLat(lat: number) {
24
22
  return (180 - (180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + lat * Math.PI / 360)))) / 360;
25
23
  }
26
24
 
27
- function getTileCoordinates(p: GeoJSONPosition, canonical: CanonicalTileID) {
25
+ function getTileCoordinates(p: GeoJSON.Position, canonical: CanonicalTileID) {
28
26
  const x = mercatorXfromLng(p[0]);
29
27
  const y = mercatorYfromLat(p[1]);
30
28
  const tilesAtZoom = Math.pow(2, canonical.z);
31
29
  return [Math.round(x * tilesAtZoom * EXTENT), Math.round(y * tilesAtZoom * EXTENT)];
32
30
  }
33
31
 
34
- function pointWithinPolygons(point: GeoJSONPosition, polygons: Array<Array<Array<GeoJSONPosition>>>) {
32
+ function pointWithinPolygons(point: GeoJSON.Position, polygons: Array<Array<Array<GeoJSON.Position>>>) {
35
33
  for (let i = 0; i < polygons.length; i++) {
36
34
  if (pointWithinPolygon(point, polygons[i])) return true;
37
35
  }
38
36
  return false;
39
37
  }
40
38
 
41
- function lineIntersectPolygon(p1: GeoJSONPosition, p2: GeoJSONPosition, polygon: Array<Array<GeoJSONPosition>>) {
39
+ function lineIntersectPolygon(p1: GeoJSON.Position, p2: GeoJSON.Position, polygon: Array<Array<GeoJSON.Position>>) {
42
40
  for (const ring of polygon) {
43
41
  // loop through every edge of the ring
44
42
  for (let j = 0, len = ring.length, k = len - 1; j < len; k = j++) {
@@ -52,7 +50,7 @@ function lineIntersectPolygon(p1: GeoJSONPosition, p2: GeoJSONPosition, polygon:
52
50
  return false;
53
51
  }
54
52
 
55
- function lineStringWithinPolygon(line: Array<GeoJSONPosition>, polygon: Array<Array<GeoJSONPosition>>) {
53
+ function lineStringWithinPolygon(line: Array<GeoJSON.Position>, polygon: Array<Array<GeoJSON.Position>>) {
56
54
  // First, check if geometry points of line segments are all inside polygon
57
55
  for (let i = 0; i < line.length; ++i) {
58
56
  if (!pointWithinPolygon(line[i], polygon)) {
@@ -69,14 +67,14 @@ function lineStringWithinPolygon(line: Array<GeoJSONPosition>, polygon: Array<Ar
69
67
  return true;
70
68
  }
71
69
 
72
- function lineStringWithinPolygons(line: Array<GeoJSONPosition>, polygons: Array<Array<Array<GeoJSONPosition>>>) {
70
+ function lineStringWithinPolygons(line: Array<GeoJSON.Position>, polygons: Array<Array<Array<GeoJSON.Position>>>) {
73
71
  for (let i = 0; i < polygons.length; i++) {
74
72
  if (lineStringWithinPolygon(line, polygons[i])) return true;
75
73
  }
76
74
  return false;
77
75
  }
78
76
 
79
- function getTilePolygon(coordinates: Array<Array<GeoJSONPosition>>, bbox: BBox, canonical: CanonicalTileID) {
77
+ function getTilePolygon(coordinates: Array<Array<GeoJSON.Position>>, bbox: BBox, canonical: CanonicalTileID) {
80
78
  const polygon = [];
81
79
  for (let i = 0; i < coordinates.length; i++) {
82
80
  const ring = [];
@@ -90,7 +88,7 @@ function getTilePolygon(coordinates: Array<Array<GeoJSONPosition>>, bbox: BBox,
90
88
  return polygon;
91
89
  }
92
90
 
93
- function getTilePolygons(coordinates: Array<Array<Array<GeoJSONPosition>>>, bbox: BBox, canonical: CanonicalTileID) {
91
+ function getTilePolygons(coordinates: Array<Array<Array<GeoJSON.Position>>>, bbox: BBox, canonical: CanonicalTileID) {
94
92
  const polygons = [];
95
93
  for (let i = 0; i < coordinates.length; i++) {
96
94
  const polygon = getTilePolygon(coordinates[i], bbox, canonical);
@@ -99,7 +97,7 @@ function getTilePolygons(coordinates: Array<Array<Array<GeoJSONPosition>>>, bbox
99
97
  return polygons;
100
98
  }
101
99
 
102
- function updatePoint(p: GeoJSONPosition, bbox: BBox, polyBBox: Array<number>, worldSize: number) {
100
+ function updatePoint(p: GeoJSON.Position, bbox: BBox, polyBBox: Array<number>, worldSize: number) {
103
101
  if (p[0] < polyBBox[0] || p[0] > polyBBox[2]) {
104
102
  const halfWorldSize = worldSize * 0.5;
105
103
  let shift = (p[0] - polyBBox[0] > halfWorldSize) ? -worldSize : (polyBBox[0] - p[0] > halfWorldSize) ? worldSize : 0;
@@ -116,7 +114,7 @@ function resetBBox(bbox: BBox) {
116
114
  bbox[2] = bbox[3] = -Infinity;
117
115
  }
118
116
 
119
- function getTilePoints(geometry: ?Array<Array<Point>>, pointBBox: BBox, polyBBox: Array<number>, canonical: CanonicalTileID) {
117
+ function getTilePoints(geometry: Array<Array<Point>> | null | undefined, pointBBox: BBox, polyBBox: Array<number>, canonical: CanonicalTileID) {
120
118
  const worldSize = Math.pow(2, canonical.z) * EXTENT;
121
119
  const shifts = [canonical.x * EXTENT, canonical.y * EXTENT];
122
120
  const tilePoints = [];
@@ -131,15 +129,15 @@ function getTilePoints(geometry: ?Array<Array<Point>>, pointBBox: BBox, polyBBox
131
129
  return tilePoints;
132
130
  }
133
131
 
134
- function getTileLines(geometry: ?Array<Array<Point>>, lineBBox: BBox, polyBBox: Array<number>, canonical: CanonicalTileID) {
132
+ function getTileLines(geometry: Array<Array<Point>> | null | undefined, lineBBox: BBox, polyBBox: Array<number>, canonical: CanonicalTileID) {
135
133
  const worldSize = Math.pow(2, canonical.z) * EXTENT;
136
134
  const shifts = [canonical.x * EXTENT, canonical.y * EXTENT];
137
- const tileLines: Array<Array<GeoJSONPosition>> = [];
135
+ const tileLines: Array<Array<GeoJSON.Position>> = [];
138
136
  if (!geometry) return tileLines;
139
137
  for (const line of geometry) {
140
138
  const tileLine = [];
141
139
  for (const point of line) {
142
- const p: GeoJSONPosition = [point.x + shifts[0], point.y + shifts[1]];
140
+ const p: GeoJSON.Position = [point.x + shifts[0], point.y + shifts[1]];
143
141
  updateBBox(lineBBox, p);
144
142
  tileLine.push(p);
145
143
  }
@@ -166,8 +164,11 @@ function pointsWithinPolygons(ctx: EvaluationContext, polygonGeometry: GeoJSONPo
166
164
  }
167
165
 
168
166
  if (polygonGeometry.type === 'Polygon') {
167
+ // @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
169
168
  const tilePolygon = getTilePolygon(polygonGeometry.coordinates, polyBBox, canonical);
169
+ // @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
170
170
  const tilePoints = getTilePoints(ctx.geometry(), pointBBox, polyBBox, canonical);
171
+ // @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
171
172
  if (!boxWithinBox(pointBBox, polyBBox)) return false;
172
173
 
173
174
  for (const point of tilePoints) {
@@ -175,8 +176,11 @@ function pointsWithinPolygons(ctx: EvaluationContext, polygonGeometry: GeoJSONPo
175
176
  }
176
177
  }
177
178
  if (polygonGeometry.type === 'MultiPolygon') {
179
+ // @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
178
180
  const tilePolygons = getTilePolygons(polygonGeometry.coordinates, polyBBox, canonical);
181
+ // @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
179
182
  const tilePoints = getTilePoints(ctx.geometry(), pointBBox, polyBBox, canonical);
183
+ // @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
180
184
  if (!boxWithinBox(pointBBox, polyBBox)) return false;
181
185
 
182
186
  for (const point of tilePoints) {
@@ -197,8 +201,11 @@ function linesWithinPolygons(ctx: EvaluationContext, polygonGeometry: GeoJSONPol
197
201
  }
198
202
 
199
203
  if (polygonGeometry.type === 'Polygon') {
204
+ // @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
200
205
  const tilePolygon = getTilePolygon(polygonGeometry.coordinates, polyBBox, canonical);
206
+ // @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
201
207
  const tileLines = getTileLines(ctx.geometry(), lineBBox, polyBBox, canonical);
208
+ // @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
202
209
  if (!boxWithinBox(lineBBox, polyBBox)) return false;
203
210
 
204
211
  for (const line of tileLines) {
@@ -206,8 +213,11 @@ function linesWithinPolygons(ctx: EvaluationContext, polygonGeometry: GeoJSONPol
206
213
  }
207
214
  }
208
215
  if (polygonGeometry.type === 'MultiPolygon') {
216
+ // @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
209
217
  const tilePolygons = getTilePolygons(polygonGeometry.coordinates, polyBBox, canonical);
218
+ // @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
210
219
  const tileLines = getTileLines(ctx.geometry(), lineBBox, polyBBox, canonical);
220
+ // @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
211
221
  if (!boxWithinBox(lineBBox, polyBBox)) return false;
212
222
 
213
223
  for (const line of tileLines) {
@@ -219,20 +229,21 @@ function linesWithinPolygons(ctx: EvaluationContext, polygonGeometry: GeoJSONPol
219
229
 
220
230
  class Within implements Expression {
221
231
  type: Type;
222
- geojson: GeoJSON
232
+ geojson: GeoJSON.GeoJSON;
223
233
  geometries: GeoJSONPolygons;
224
234
 
225
- constructor(geojson: GeoJSON, geometries: GeoJSONPolygons) {
235
+ constructor(geojson: GeoJSON.GeoJSON, geometries: GeoJSONPolygons) {
226
236
  this.type = BooleanType;
227
237
  this.geojson = geojson;
228
238
  this.geometries = geometries;
229
239
  }
230
240
 
231
- static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?Within {
241
+ static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Within | null | undefined {
232
242
  if (args.length !== 2)
243
+ // @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Within'.
233
244
  return context.error(`'within' expression requires exactly one argument, but found ${args.length - 1} instead.`);
234
245
  if (isValue(args[1])) {
235
- const geojson = (args[1]: Object);
246
+ const geojson = (args[1] as any);
236
247
  if (geojson.type === 'FeatureCollection') {
237
248
  for (let i = 0; i < geojson.features.length; ++i) {
238
249
  const type = geojson.features[i].geometry.type;
@@ -249,6 +260,7 @@ class Within implements Expression {
249
260
  return new Within(geojson, geojson);
250
261
  }
251
262
  }
263
+ // @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Within'.
252
264
  return context.error(`'within' expression requires valid geojson object that contains polygon geometry type.`);
253
265
  }
254
266
 
@@ -1,32 +1,32 @@
1
- // @flow
2
-
3
- import {Color} from './values.js';
1
+ import {Color} from './values';
4
2
 
5
3
  import type Point from '@mapbox/point-geometry';
6
- import type {FormattedSection} from './types/formatted.js';
7
- import type {GlobalProperties, Feature, FeatureState} from './index.js';
8
- import type {CanonicalTileID} from '../../source/tile_id.js';
9
- import type {FeatureDistanceData} from '../feature_filter/index.js';
10
- import type {ConfigOptions, ConfigOptionValue} from '../../style/properties.js';
4
+ import type {FormattedSection} from './types/formatted';
5
+ import type {GlobalProperties, Feature, FeatureState} from './index';
6
+ import type {CanonicalTileID} from '../types/tile_id';
7
+ import type {FeatureDistanceData} from '../feature_filter/index';
8
+ import type {ConfigOptions, ConfigOptionValue} from '../types/config_options';
11
9
 
12
10
  const geometryTypes = ['Unknown', 'Point', 'LineString', 'Polygon'];
13
11
 
14
12
  class EvaluationContext {
15
13
  globals: GlobalProperties;
16
- feature: ?Feature;
17
- featureState: ?FeatureState;
18
- formattedSection: ?FormattedSection;
19
- availableImages: ?Array<string>;
14
+ feature: Feature | null | undefined;
15
+ featureState: FeatureState | null | undefined;
16
+ formattedSection: FormattedSection | null | undefined;
17
+ availableImages: Array<string> | null | undefined;
20
18
  canonical: null | CanonicalTileID;
21
- featureTileCoord: ?Point;
22
- featureDistanceData: ?FeatureDistanceData;
23
- scope: ?string;
24
- options: ?ConfigOptions;
19
+ featureTileCoord: Point | null | undefined;
20
+ featureDistanceData: FeatureDistanceData | null | undefined;
21
+ scope: string | null | undefined;
22
+ options: ConfigOptions | null | undefined;
25
23
 
26
- _parseColorCache: {[_: string]: ?Color};
24
+ _parseColorCache: {
25
+ [_: string]: Color | null | undefined;
26
+ };
27
27
 
28
- constructor(scope: ?string, options: ?ConfigOptions) {
29
- this.globals = (null: any);
28
+ constructor(scope?: string | null, options?: ConfigOptions | null) {
29
+ this.globals = (null as any);
30
30
  this.feature = null;
31
31
  this.featureState = null;
32
32
  this.formattedSection = null;
@@ -47,7 +47,7 @@ class EvaluationContext {
47
47
  return this.feature ? typeof this.feature.type === 'number' ? geometryTypes[this.feature.type] : this.feature.type : null;
48
48
  }
49
49
 
50
- geometry(): ?Array<Array<Point>> {
50
+ geometry(): Array<Array<Point>> | null | undefined {
51
51
  return this.feature && 'geometry' in this.feature ? this.feature.geometry : null;
52
52
  }
53
53
 
@@ -55,7 +55,9 @@ class EvaluationContext {
55
55
  return this.canonical;
56
56
  }
57
57
 
58
- properties(): {[string]: any} {
58
+ properties(): {
59
+ [key: string]: any;
60
+ } {
59
61
  return (this.feature && this.feature.properties) || {};
60
62
  }
61
63
 
@@ -86,15 +88,16 @@ class EvaluationContext {
86
88
  return 0;
87
89
  }
88
90
 
89
- parseColor(input: string): ?Color {
91
+ parseColor(input: string): Color | null | undefined {
90
92
  let cached = this._parseColorCache[input];
91
93
  if (!cached) {
94
+ // @ts-expect-error - TS2322 - Type 'void | Color' is not assignable to type 'Color'. | TS2322 - Type 'void | Color' is not assignable to type 'Color'.
92
95
  cached = this._parseColorCache[input] = Color.parse(input);
93
96
  }
94
97
  return cached;
95
98
  }
96
99
 
97
- getConfig(id: string): ?ConfigOptionValue {
100
+ getConfig(id: string): ConfigOptionValue | null | undefined {
98
101
  return this.options ? this.options.get(id) : null;
99
102
  }
100
103
  }
@@ -0,0 +1,29 @@
1
+ import type {Type} from './types';
2
+ import type ParsingContext from './parsing_context';
3
+ import type EvaluationContext from './evaluation_context';
4
+
5
+ export type SerializedExpression = Array<unknown> | Array<string> | string | number | boolean | null;
6
+
7
+ export interface Expression {
8
+ readonly type: Type;
9
+ value?: any;
10
+ evaluate(ctx: EvaluationContext): any;
11
+ eachChild(fn: (arg1: Expression) => void): void;
12
+ /**
13
+ * Statically analyze the expression, attempting to enumerate possible outputs. Returns
14
+ * false if the complete set of outputs is statically undecidable, otherwise true.
15
+ */
16
+ outputDefined(): boolean;
17
+ serialize(): SerializedExpression;
18
+ }
19
+
20
+ export type ExpressionParser = (args: ReadonlyArray<unknown>, context: ParsingContext) => Expression | void;
21
+
22
+ export type ExpressionRegistration = {
23
+ new(...args: any[]): Expression;
24
+ readonly parse: ExpressionParser;
25
+ };
26
+
27
+ export type ExpressionRegistry = {
28
+ [_: string]: ExpressionRegistration;
29
+ };