@mapbox/mapbox-gl-style-spec 13.24.0-alpha.2 → 13.24.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/.eslintrc +10 -0
  2. package/CHANGELOG.md +15 -3
  3. package/bin/gl-style-composite.js +25 -0
  4. package/bin/gl-style-format.js +30 -0
  5. package/bin/gl-style-migrate.js +25 -0
  6. package/bin/{gl-style-validate → gl-style-validate.js} +19 -12
  7. package/build/.gitkeep +0 -0
  8. package/deref.js +8 -7
  9. package/diff.js +11 -6
  10. package/dist/index.cjs +55 -76
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.es.js +55 -76
  13. package/dist/index.es.js.map +1 -1
  14. package/empty.js +9 -28
  15. package/expression/compound_expression.js +2 -2
  16. package/expression/definitions/assertion.js +3 -3
  17. package/expression/definitions/at.js +5 -5
  18. package/expression/definitions/case.js +4 -4
  19. package/expression/definitions/coalesce.js +11 -9
  20. package/expression/definitions/coercion.js +3 -3
  21. package/expression/definitions/collator.js +4 -4
  22. package/expression/definitions/comparison.js +22 -22
  23. package/expression/definitions/format.js +4 -4
  24. package/expression/definitions/image.js +4 -4
  25. package/expression/definitions/in.js +6 -6
  26. package/expression/definitions/index_of.js +5 -5
  27. package/expression/definitions/interpolate.js +6 -5
  28. package/expression/definitions/length.js +5 -5
  29. package/expression/definitions/let.js +5 -5
  30. package/expression/definitions/literal.js +5 -5
  31. package/expression/definitions/match.js +4 -4
  32. package/expression/definitions/number_format.js +4 -4
  33. package/expression/definitions/slice.js +5 -5
  34. package/expression/definitions/step.js +4 -4
  35. package/expression/definitions/var.js +4 -4
  36. package/expression/definitions/within.js +16 -8
  37. package/expression/evaluation_context.js +9 -9
  38. package/expression/expression.js +1 -1
  39. package/expression/index.js +7 -7
  40. package/expression/is_constant.js +3 -3
  41. package/expression/parsing_context.js +1 -1
  42. package/expression/runtime_error.js +1 -1
  43. package/expression/scope.js +1 -1
  44. package/expression/stops.js +1 -1
  45. package/expression/values.js +1 -1
  46. package/feature_filter/convert.js +1 -1
  47. package/feature_filter/index.js +2 -2
  48. package/flow-typed/gl-matrix.js +103 -0
  49. package/flow-typed/grid-index.js +13 -0
  50. package/flow-typed/pbf.js +2 -1
  51. package/flow-typed/point-geometry.js +4 -2
  52. package/flow-typed/potpack.js +1 -0
  53. package/flow-typed/tiny-sdf.js +31 -0
  54. package/flow-typed/vector-tile.js +1 -0
  55. package/function/convert.js +4 -4
  56. package/group_by_layout.js +8 -10
  57. package/migrate/expressions.js +1 -1
  58. package/package.json +9 -7
  59. package/reference/latest.js +4 -0
  60. package/reference/v8.json +1 -4
  61. package/style-spec.js +6 -3
  62. package/test.js +31 -0
  63. package/types.js +1 -1
  64. package/util/color_spaces.js +2 -2
  65. package/util/extend.js +1 -1
  66. package/util/interpolate.js +2 -2
  67. package/util/ref_properties.js +1 -1
  68. package/util/unbundle_jsonlint.js +1 -1
  69. package/validate/validate.js +13 -3
  70. package/validate/validate_array.js +10 -2
  71. package/validate/validate_boolean.js +4 -1
  72. package/validate/validate_color.js +4 -1
  73. package/validate/validate_enum.js +4 -1
  74. package/validate/validate_expression.js +5 -2
  75. package/validate/validate_filter.js +12 -4
  76. package/validate/validate_fog.js +4 -1
  77. package/validate/validate_formatted.js +5 -1
  78. package/validate/validate_function.js +24 -15
  79. package/validate/validate_glyphs_url.js +4 -1
  80. package/validate/validate_image.js +5 -1
  81. package/validate/validate_layer.js +15 -2
  82. package/validate/validate_layout_property.js +5 -1
  83. package/validate/validate_light.js +4 -1
  84. package/validate/validate_number.js +8 -1
  85. package/validate/validate_object.js +12 -2
  86. package/validate/validate_paint_property.js +5 -1
  87. package/validate/validate_projection.js +5 -1
  88. package/validate/validate_property.js +9 -1
  89. package/validate/validate_source.js +4 -1
  90. package/validate/validate_string.js +4 -1
  91. package/validate/validate_terrain.js +5 -2
  92. package/validate_mapbox_api_supported.js +8 -6
  93. package/validate_style.js +14 -9
  94. package/validate_style.min.js +32 -47
  95. package/bin/gl-style-composite +0 -9
  96. package/bin/gl-style-format +0 -22
  97. package/bin/gl-style-migrate +0 -9
  98. package/declass.js +0 -42
  99. package/validate/latest.js +0 -11
  100. package/validate/validate_constants.js +0 -13
@@ -6,7 +6,7 @@ import Formatted from '../types/formatted.js';
6
6
 
7
7
  import type {Type} from '../types.js';
8
8
  import type {Value} from '../values.js';
9
- import type {Expression} from '../expression.js';
9
+ import type {Expression, SerializedExpression} from '../expression.js';
10
10
  import type ParsingContext from '../parsing_context.js';
11
11
 
12
12
  class Literal implements Expression {
@@ -18,7 +18,7 @@ class Literal implements Expression {
18
18
  this.value = value;
19
19
  }
20
20
 
21
- static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
21
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): void | Literal {
22
22
  if (args.length !== 2)
23
23
  return context.error(`'literal' expression requires exactly one argument, but found ${args.length - 1} instead.`);
24
24
 
@@ -43,17 +43,17 @@ class Literal implements Expression {
43
43
  return new Literal(type, value);
44
44
  }
45
45
 
46
- evaluate() {
46
+ evaluate(): Value {
47
47
  return this.value;
48
48
  }
49
49
 
50
50
  eachChild() {}
51
51
 
52
- outputDefined() {
52
+ outputDefined(): boolean {
53
53
  return true;
54
54
  }
55
55
 
56
- serialize(): Array<mixed> {
56
+ serialize(): SerializedExpression {
57
57
  if (this.type.kind === 'array' || this.type.kind === 'object') {
58
58
  return ["literal", this.value];
59
59
  } else if (this.value instanceof Color) {
@@ -5,7 +5,7 @@ import assert from 'assert';
5
5
  import {typeOf} from '../values.js';
6
6
  import {ValueType, type Type} from '../types.js';
7
7
 
8
- import type {Expression} from '../expression.js';
8
+ import type {Expression, SerializedExpression} from '../expression.js';
9
9
  import type ParsingContext from '../parsing_context.js';
10
10
  import type EvaluationContext from '../evaluation_context.js';
11
11
 
@@ -30,7 +30,7 @@ class Match implements Expression {
30
30
  this.otherwise = otherwise;
31
31
  }
32
32
 
33
- static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
33
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?Match {
34
34
  if (args.length < 5)
35
35
  return context.error(`Expected at least 4 arguments, but found only ${args.length - 1}.`);
36
36
  if (args.length % 2 !== 1)
@@ -99,7 +99,7 @@ class Match implements Expression {
99
99
  return new Match((inputType: any), (outputType: any), input, cases, outputs, otherwise);
100
100
  }
101
101
 
102
- evaluate(ctx: EvaluationContext) {
102
+ evaluate(ctx: EvaluationContext): any {
103
103
  const input = (this.input.evaluate(ctx): any);
104
104
  const output = (typeOf(input) === this.inputType && this.outputs[this.cases[input]]) || this.otherwise;
105
105
  return output.evaluate(ctx);
@@ -115,7 +115,7 @@ class Match implements Expression {
115
115
  return this.outputs.every(out => out.outputDefined()) && this.otherwise.outputDefined();
116
116
  }
117
117
 
118
- serialize(): Array<mixed> {
118
+ serialize(): SerializedExpression {
119
119
  const serialized = ["match", this.input.serialize()];
120
120
 
121
121
  // Sort so serialization has an arbitrary defined order, even though
@@ -2,7 +2,7 @@
2
2
 
3
3
  import {StringType, NumberType} from '../types.js';
4
4
 
5
- import type {Expression} from '../expression.js';
5
+ import type {Expression, SerializedExpression} from '../expression.js';
6
6
  import type EvaluationContext from '../evaluation_context.js';
7
7
  import type ParsingContext from '../parsing_context.js';
8
8
  import type {Type} from '../types.js';
@@ -93,7 +93,7 @@ export default class NumberFormat implements Expression {
93
93
  return new NumberFormat(number, locale, currency, minFractionDigits, maxFractionDigits);
94
94
  }
95
95
 
96
- evaluate(ctx: EvaluationContext) {
96
+ evaluate(ctx: EvaluationContext): string {
97
97
  return new Intl.NumberFormat(this.locale ? this.locale.evaluate(ctx) : [],
98
98
  {
99
99
  style: this.currency ? "currency" : "decimal",
@@ -119,11 +119,11 @@ export default class NumberFormat implements Expression {
119
119
  }
120
120
  }
121
121
 
122
- outputDefined() {
122
+ outputDefined(): boolean {
123
123
  return false;
124
124
  }
125
125
 
126
- serialize() {
126
+ serialize(): SerializedExpression {
127
127
  const options = {};
128
128
  if (this.locale) {
129
129
  options['locale'] = this.locale.serialize();
@@ -4,7 +4,7 @@ import {ValueType, NumberType, StringType, array, toString, isValidType, isValid
4
4
  import RuntimeError from '../runtime_error.js';
5
5
  import {typeOf} from '../values.js';
6
6
 
7
- import type {Expression} from '../expression.js';
7
+ import type {Expression, SerializedExpression} from '../expression.js';
8
8
  import type ParsingContext from '../parsing_context.js';
9
9
  import type EvaluationContext from '../evaluation_context.js';
10
10
  import type {Type} from '../types.js';
@@ -23,7 +23,7 @@ class Slice implements Expression {
23
23
 
24
24
  }
25
25
 
26
- static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
26
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?Slice {
27
27
  if (args.length <= 2 || args.length >= 5) {
28
28
  return context.error(`Expected 3 or 4 arguments, but found ${args.length - 1} instead.`);
29
29
  }
@@ -46,7 +46,7 @@ class Slice implements Expression {
46
46
  }
47
47
  }
48
48
 
49
- evaluate(ctx: EvaluationContext) {
49
+ evaluate(ctx: EvaluationContext): any {
50
50
  const input = (this.input.evaluate(ctx): any);
51
51
  const beginIndex = (this.beginIndex.evaluate(ctx): number);
52
52
 
@@ -70,11 +70,11 @@ class Slice implements Expression {
70
70
  }
71
71
  }
72
72
 
73
- outputDefined() {
73
+ outputDefined(): boolean {
74
74
  return false;
75
75
  }
76
76
 
77
- serialize() {
77
+ serialize(): SerializedExpression {
78
78
  if (this.endIndex != null && this.endIndex !== undefined) {
79
79
  const endIndex = this.endIndex.serialize();
80
80
  return ["slice", this.input.serialize(), this.beginIndex.serialize(), endIndex];
@@ -5,7 +5,7 @@ import {NumberType} from '../types.js';
5
5
  import {findStopLessThanOrEqualTo} from '../stops.js';
6
6
 
7
7
  import type {Stops} from '../stops.js';
8
- import type {Expression} from '../expression.js';
8
+ import type {Expression, SerializedExpression} from '../expression.js';
9
9
  import type ParsingContext from '../parsing_context.js';
10
10
  import type EvaluationContext from '../evaluation_context.js';
11
11
  import type {Type} from '../types.js';
@@ -29,7 +29,7 @@ class Step implements Expression {
29
29
  }
30
30
  }
31
31
 
32
- static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
32
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?Step {
33
33
  if (args.length - 1 < 4) {
34
34
  return context.error(`Expected at least 4 arguments, but found only ${args.length - 1}.`);
35
35
  }
@@ -72,7 +72,7 @@ class Step implements Expression {
72
72
  return new Step(outputType, input, stops);
73
73
  }
74
74
 
75
- evaluate(ctx: EvaluationContext) {
75
+ evaluate(ctx: EvaluationContext): any {
76
76
  const labels = this.labels;
77
77
  const outputs = this.outputs;
78
78
 
@@ -105,7 +105,7 @@ class Step implements Expression {
105
105
  return this.outputs.every(out => out.outputDefined());
106
106
  }
107
107
 
108
- serialize() {
108
+ serialize(): SerializedExpression {
109
109
  const serialized = ["step", this.input.serialize()];
110
110
  for (let i = 0; i < this.labels.length; i++) {
111
111
  if (i > 0) {
@@ -16,7 +16,7 @@ class Var implements Expression {
16
16
  this.boundExpression = boundExpression;
17
17
  }
18
18
 
19
- static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
19
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): void | Var {
20
20
  if (args.length !== 2 || typeof args[1] !== 'string')
21
21
  return context.error(`'var' expression requires exactly one string literal argument.`);
22
22
 
@@ -28,17 +28,17 @@ class Var implements Expression {
28
28
  return new Var(name, context.scope.get(name));
29
29
  }
30
30
 
31
- evaluate(ctx: EvaluationContext) {
31
+ evaluate(ctx: EvaluationContext): any {
32
32
  return this.boundExpression.evaluate(ctx);
33
33
  }
34
34
 
35
35
  eachChild() {}
36
36
 
37
- outputDefined() {
37
+ outputDefined(): boolean {
38
38
  return false;
39
39
  }
40
40
 
41
- serialize() {
41
+ serialize(): Array<string> {
42
42
  return ["var", this.name];
43
43
  }
44
44
  }
@@ -3,7 +3,7 @@
3
3
  import {isValue} from '../values.js';
4
4
  import type {Type} from '../types.js';
5
5
  import {BooleanType} from '../types.js';
6
- import type {Expression} from '../expression.js';
6
+ import type {Expression, SerializedExpression} from '../expression.js';
7
7
  import type ParsingContext from '../parsing_context.js';
8
8
  import type EvaluationContext from '../evaluation_context.js';
9
9
  import type {GeoJSON, GeoJSONPolygon, GeoJSONMultiPolygon} from '@mapbox/geojson-types';
@@ -148,7 +148,7 @@ function lineStringWithinPolygons(line, polygons) {
148
148
  return false;
149
149
  }
150
150
 
151
- function getTilePolygon(coordinates, bbox, canonical) {
151
+ function getTilePolygon(coordinates, bbox: BBox, canonical: CanonicalTileID) {
152
152
  const polygon = [];
153
153
  for (let i = 0; i < coordinates.length; i++) {
154
154
  const ring = [];
@@ -162,7 +162,7 @@ function getTilePolygon(coordinates, bbox, canonical) {
162
162
  return polygon;
163
163
  }
164
164
 
165
- function getTilePolygons(coordinates, bbox, canonical) {
165
+ function getTilePolygons(coordinates, bbox, canonical: CanonicalTileID) {
166
166
  const polygons = [];
167
167
  for (let i = 0; i < coordinates.length; i++) {
168
168
  const polygon = getTilePolygon(coordinates[i], bbox, canonical);
@@ -188,10 +188,11 @@ function resetBBox(bbox) {
188
188
  bbox[2] = bbox[3] = -Infinity;
189
189
  }
190
190
 
191
- function getTilePoints(geometry, pointBBox, polyBBox, canonical) {
191
+ function getTilePoints(geometry, pointBBox, polyBBox, canonical: CanonicalTileID) {
192
192
  const worldSize = Math.pow(2, canonical.z) * EXTENT;
193
193
  const shifts = [canonical.x * EXTENT, canonical.y * EXTENT];
194
194
  const tilePoints = [];
195
+ if (!geometry) return tilePoints;
195
196
  for (const points of geometry) {
196
197
  for (const point of points) {
197
198
  const p = [point.x + shifts[0], point.y + shifts[1]];
@@ -202,10 +203,11 @@ function getTilePoints(geometry, pointBBox, polyBBox, canonical) {
202
203
  return tilePoints;
203
204
  }
204
205
 
205
- function getTileLines(geometry, lineBBox, polyBBox, canonical) {
206
+ function getTileLines(geometry, lineBBox, polyBBox, canonical: CanonicalTileID) {
206
207
  const worldSize = Math.pow(2, canonical.z) * EXTENT;
207
208
  const shifts = [canonical.x * EXTENT, canonical.y * EXTENT];
208
209
  const tileLines = [];
210
+ if (!geometry) return tileLines;
209
211
  for (const line of geometry) {
210
212
  const tileLine = [];
211
213
  for (const point of line) {
@@ -231,6 +233,9 @@ function pointsWithinPolygons(ctx: EvaluationContext, polygonGeometry: GeoJSONPo
231
233
  const polyBBox = [Infinity, Infinity, -Infinity, -Infinity];
232
234
 
233
235
  const canonical = ctx.canonicalID();
236
+ if (!canonical) {
237
+ return false;
238
+ }
234
239
 
235
240
  if (polygonGeometry.type === 'Polygon') {
236
241
  const tilePolygon = getTilePolygon(polygonGeometry.coordinates, polyBBox, canonical);
@@ -259,6 +264,9 @@ function linesWithinPolygons(ctx: EvaluationContext, polygonGeometry: GeoJSONPol
259
264
  const polyBBox = [Infinity, Infinity, -Infinity, -Infinity];
260
265
 
261
266
  const canonical = ctx.canonicalID();
267
+ if (!canonical) {
268
+ return false;
269
+ }
262
270
 
263
271
  if (polygonGeometry.type === 'Polygon') {
264
272
  const tilePolygon = getTilePolygon(polygonGeometry.coordinates, polyBBox, canonical);
@@ -292,7 +300,7 @@ class Within implements Expression {
292
300
  this.geometries = geometries;
293
301
  }
294
302
 
295
- static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
303
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?Within {
296
304
  if (args.length !== 2)
297
305
  return context.error(`'within' expression requires exactly one argument, but found ${args.length - 1} instead.`);
298
306
  if (isValue(args[1])) {
@@ -316,7 +324,7 @@ class Within implements Expression {
316
324
  return context.error(`'within' expression requires valid geojson object that contains polygon geometry type.`);
317
325
  }
318
326
 
319
- evaluate(ctx: EvaluationContext) {
327
+ evaluate(ctx: EvaluationContext): boolean {
320
328
  if (ctx.geometry() != null && ctx.canonicalID() != null) {
321
329
  if (ctx.geometryType() === 'Point') {
322
330
  return pointsWithinPolygons(ctx, this.geometries);
@@ -333,7 +341,7 @@ class Within implements Expression {
333
341
  return true;
334
342
  }
335
343
 
336
- serialize(): Array<mixed> {
344
+ serialize(): SerializedExpression {
337
345
  return ["within", this.geojson];
338
346
  }
339
347
 
@@ -16,7 +16,7 @@ class EvaluationContext {
16
16
  featureState: ?FeatureState;
17
17
  formattedSection: ?FormattedSection;
18
18
  availableImages: ?Array<string>;
19
- canonical: ?CanonicalTileID;
19
+ canonical: null | CanonicalTileID;
20
20
  featureTileCoord: ?Point;
21
21
  featureDistanceData: ?FeatureDistanceData;
22
22
 
@@ -34,27 +34,27 @@ class EvaluationContext {
34
34
  this.featureDistanceData = null;
35
35
  }
36
36
 
37
- id() {
38
- return this.feature && 'id' in this.feature ? this.feature.id : null;
37
+ id(): number | null {
38
+ return this.feature && 'id' in this.feature && this.feature.id ? this.feature.id : null;
39
39
  }
40
40
 
41
- geometryType() {
41
+ geometryType(): null | string {
42
42
  return this.feature ? typeof this.feature.type === 'number' ? geometryTypes[this.feature.type] : this.feature.type : null;
43
43
  }
44
44
 
45
- geometry() {
45
+ geometry(): ?Array<Array<Point>> {
46
46
  return this.feature && 'geometry' in this.feature ? this.feature.geometry : null;
47
47
  }
48
48
 
49
- canonicalID() {
49
+ canonicalID(): null | CanonicalTileID {
50
50
  return this.canonical;
51
51
  }
52
52
 
53
- properties() {
54
- return this.feature && this.feature.properties || {};
53
+ properties(): {[string]: any} {
54
+ return (this.feature && this.feature.properties) || {};
55
55
  }
56
56
 
57
- distanceFromCenter() {
57
+ distanceFromCenter(): number {
58
58
  if (this.featureTileCoord && this.featureDistanceData) {
59
59
 
60
60
  const c = this.featureDistanceData.center;
@@ -4,7 +4,7 @@ import type {Type} from './types.js';
4
4
  import type ParsingContext from './parsing_context.js';
5
5
  import type EvaluationContext from './evaluation_context.js';
6
6
 
7
- type SerializedExpression = Array<mixed> | string | number | boolean | null;
7
+ export type SerializedExpression = Array<mixed> | Array<string> | string | number | boolean | null;
8
8
 
9
9
  export interface Expression {
10
10
  +type: Type;
@@ -31,7 +31,7 @@ import type {FeatureDistanceData} from '../feature_filter/index.js';
31
31
 
32
32
  export type Feature = {
33
33
  +type: 1 | 2 | 3 | 'Unknown' | 'Point' | 'MultiPoint' | 'LineString' | 'MultiLineString' | 'Polygon' | 'MultiPolygon',
34
- +id?: any,
34
+ +id?: number | null,
35
35
  +properties: {[_: string]: any},
36
36
  +patterns?: {[_: string]: {"min": string, "mid": string, "max": string}},
37
37
  +geometry?: Array<Array<Point>>
@@ -69,7 +69,7 @@ export class StyleExpression {
69
69
  this._evaluator.globals = globals;
70
70
  this._evaluator.feature = feature;
71
71
  this._evaluator.featureState = featureState;
72
- this._evaluator.canonical = canonical;
72
+ this._evaluator.canonical = canonical || null;
73
73
  this._evaluator.availableImages = availableImages || null;
74
74
  this._evaluator.formattedSection = formattedSection;
75
75
  this._evaluator.featureTileCoord = featureTileCoord || null;
@@ -82,7 +82,7 @@ export class StyleExpression {
82
82
  this._evaluator.globals = globals;
83
83
  this._evaluator.feature = feature || null;
84
84
  this._evaluator.featureState = featureState || null;
85
- this._evaluator.canonical = canonical;
85
+ this._evaluator.canonical = canonical || null;
86
86
  this._evaluator.availableImages = availableImages || null;
87
87
  this._evaluator.formattedSection = formattedSection || null;
88
88
  this._evaluator.featureTileCoord = featureTileCoord || null;
@@ -110,7 +110,7 @@ export class StyleExpression {
110
110
  }
111
111
  }
112
112
 
113
- export function isExpression(expression: mixed) {
113
+ export function isExpression(expression: mixed): boolean {
114
114
  return Array.isArray(expression) && expression.length > 0 &&
115
115
  typeof expression[0] === 'string' && expression[0] in definitions;
116
116
  }
@@ -286,11 +286,11 @@ export class StylePropertyFunction<T> {
286
286
  extend(this, createFunction(this._parameters, this._specification));
287
287
  }
288
288
 
289
- static deserialize(serialized: {_parameters: PropertyValueSpecification<T>, _specification: StylePropertySpecification}) {
290
- return ((new StylePropertyFunction(serialized._parameters, serialized._specification)): StylePropertyFunction<T>);
289
+ static deserialize(serialized: {_parameters: PropertyValueSpecification<T>, _specification: StylePropertySpecification}): StylePropertyFunction<T> {
290
+ return new StylePropertyFunction(serialized._parameters, serialized._specification);
291
291
  }
292
292
 
293
- static serialize(input: StylePropertyFunction<T>) {
293
+ static serialize(input: StylePropertyFunction<T>): {_parameters: PropertyValueSpecification<T>, _specification: StylePropertySpecification} {
294
294
  return {
295
295
  _parameters: input._parameters,
296
296
  _specification: input._specification
@@ -4,7 +4,7 @@ import CompoundExpression from './compound_expression.js';
4
4
  import Within from './definitions/within.js';
5
5
  import type {Expression} from './expression.js';
6
6
 
7
- function isFeatureConstant(e: Expression) {
7
+ function isFeatureConstant(e: Expression): boolean {
8
8
  if (e instanceof CompoundExpression) {
9
9
  if (e.name === 'get' && e.args.length === 1) {
10
10
  return false;
@@ -34,7 +34,7 @@ function isFeatureConstant(e: Expression) {
34
34
  return result;
35
35
  }
36
36
 
37
- function isStateConstant(e: Expression) {
37
+ function isStateConstant(e: Expression): boolean {
38
38
  if (e instanceof CompoundExpression) {
39
39
  if (e.name === 'feature-state') {
40
40
  return false;
@@ -47,7 +47,7 @@ function isStateConstant(e: Expression) {
47
47
  return result;
48
48
  }
49
49
 
50
- function isGlobalPropertyConstant(e: Expression, properties: Array<string>) {
50
+ function isGlobalPropertyConstant(e: Expression, properties: Array<string>): boolean {
51
51
  if (e instanceof CompoundExpression && properties.indexOf(e.name) >= 0) { return false; }
52
52
  let result = true;
53
53
  e.eachChild((arg) => {
@@ -155,7 +155,7 @@ class ParsingContext {
155
155
  * parsing, is copied by reference rather than cloned.
156
156
  * @private
157
157
  */
158
- concat(index: number, expectedType?: ?Type, bindings?: Array<[string, Expression]>) {
158
+ concat(index: number, expectedType?: ?Type, bindings?: Array<[string, Expression]>): ParsingContext {
159
159
  const path = typeof index === 'number' ? this.path.concat(index) : this.path;
160
160
  const scope = bindings ? this.scope.concat(bindings) : this.scope;
161
161
  return new ParsingContext(
@@ -9,7 +9,7 @@ class RuntimeError {
9
9
  this.message = message;
10
10
  }
11
11
 
12
- toJSON() {
12
+ toJSON(): string {
13
13
  return this.message;
14
14
  }
15
15
  }
@@ -17,7 +17,7 @@ class Scope {
17
17
  }
18
18
  }
19
19
 
20
- concat(bindings: Array<[string, Expression]>) {
20
+ concat(bindings: Array<[string, Expression]>): Scope {
21
21
  return new Scope(this, bindings);
22
22
  }
23
23
 
@@ -10,7 +10,7 @@ export type Stops = Array<[number, Expression]>;
10
10
  * Returns the index of the last stop <= input, or 0 if it doesn't exist.
11
11
  * @private
12
12
  */
13
- export function findStopLessThanOrEqualTo(stops: Array<number>, input: number) {
13
+ export function findStopLessThanOrEqualTo(stops: Array<number>, input: number): number {
14
14
  const lastIndex = stops.length - 1;
15
15
  let lowerIndex = 0;
16
16
  let upperIndex = lastIndex;
@@ -107,7 +107,7 @@ export function typeOf(value: Value): Type {
107
107
  }
108
108
  }
109
109
 
110
- export function toString(value: Value) {
110
+ export function toString(value: Value): string {
111
111
  const type = typeof value;
112
112
  if (value === null) {
113
113
  return '';
@@ -94,7 +94,7 @@ function _convertFilter(filter: FilterSpecification, expectedTypes: ExpectedType
94
94
  const children = (filter: 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.slice(1)), {})];
97
+ return ['!', _convertFilter(['any'].concat((filter: any).slice(1)), {})];
98
98
  } else if (op === 'in') {
99
99
  converted = convertInOp((filter[1]: any), filter.slice(2));
100
100
  } else if (op === '!in') {
@@ -9,13 +9,13 @@ import type {CanonicalTileID} from '../../source/tile_id.js';
9
9
  import type Point from '@mapbox/point-geometry';
10
10
 
11
11
  export type FeatureDistanceData = {bearing: [number, number], center: [number, number], scale: number};
12
- type FilterExpression = (globalProperties: GlobalProperties, feature: Feature, canonical?: CanonicalTileID, featureTileCoord?: Point, featureDistanceData?: FeatureDistanceData) => boolean;
12
+ export type FilterExpression = (globalProperties: GlobalProperties, feature: Feature, canonical?: CanonicalTileID, featureTileCoord?: Point, featureDistanceData?: FeatureDistanceData) => boolean;
13
13
  export type FeatureFilter = {filter: FilterExpression, dynamicFilter?: FilterExpression, needGeometry: boolean, needFeature: boolean};
14
14
 
15
15
  export default createFilter;
16
16
  export {isExpressionFilter, isDynamicFilter, extractStaticFilter};
17
17
 
18
- function isExpressionFilter(filter: any) {
18
+ function isExpressionFilter(filter: any): boolean {
19
19
  if (filter === true || filter === false) {
20
20
  return true;
21
21
  }
@@ -0,0 +1,103 @@
1
+ // @flow
2
+ type VecType = Array<number> | Float32Array | Float64Array;
3
+
4
+ declare module "gl-matrix" {
5
+ declare type Vec2 = VecType;
6
+ declare type Vec3 = VecType;
7
+ declare type Vec4 = VecType;
8
+ declare type Quat = VecType;
9
+ declare type Mat2 = VecType;
10
+ declare type Mat3 = VecType;
11
+ declare type Mat4 = VecType;
12
+
13
+ declare var vec2: {
14
+ exactEquals(Vec2, Vec2): boolean
15
+ };
16
+
17
+ declare var vec3: {
18
+ create(): Float32Array,
19
+ fromValues(number, number, number): Float32Array,
20
+ length(Vec3): number,
21
+ len(Vec3): number,
22
+ squaredLength(Vec3): number,
23
+ dot(Vec3, Vec3): number,
24
+ equals(Vec3, Vec3): boolean,
25
+ exactEquals(Vec3, Vec3): boolean,
26
+
27
+ clone<T: Vec3>(T): T,
28
+ normalize<T: Vec3>(T, Vec3): T,
29
+ add<T: Vec3>(T, Vec3, Vec3): T,
30
+ sub<T: Vec3>(T, Vec3, Vec3): T,
31
+ subtract<T: Vec3>(T, Vec3, Vec3): T,
32
+ cross<T: Vec3>(T, Vec3, Vec3): T,
33
+ negate<T: Vec3>(T, Vec3): T,
34
+ scale<T: Vec3>(T, Vec3, number): T,
35
+ scaleAndAdd<T: Vec3>(T, Vec3, Vec3, number): T,
36
+ multiply<T: Vec3>(T, Vec3, Vec3): T,
37
+ mul<T: Vec3>(T, Vec3, Vec3): T,
38
+ div<T: Vec3>(T, Vec3, Vec3): T,
39
+ min<T: Vec3>(T, Vec3, Vec3): T,
40
+ max<T: Vec3>(T, Vec3, Vec3): T,
41
+ lerp<T: Vec3>(T, Vec3, Vec3, number): T,
42
+ transformQuat<T: Vec3>(T, Vec3, Quat): T,
43
+ transformMat3<T: Vec3>(T, Vec3, Mat3): T,
44
+ transformMat4<T: Vec3>(T, Vec3, Mat4): T
45
+ };
46
+
47
+ declare var vec4: {
48
+ scale<T: Vec4>(T, Vec4, number): T,
49
+ mul<T: Vec4>(T, Vec4, Vec4): T,
50
+ transformMat4<T: Vec4>(T, Vec4, Mat4): T
51
+ };
52
+
53
+ declare var mat2: {
54
+ create(): Float32Array,
55
+ rotate<T: Mat2>(T, Mat2, number): T,
56
+ invert<T: Mat2>(T, Mat2): T,
57
+ scale<T: Mat2>(T, Mat2, Vec2): T
58
+ };
59
+
60
+ declare var mat3: {
61
+ create(): Float32Array,
62
+
63
+ fromMat4<T: Mat3>(T, Mat4): T,
64
+ fromRotation<T: Mat3>(T, number): T,
65
+ mul<T: Mat3>(T, Mat3, Mat3): T,
66
+ multiply<T: Mat3>(T, Mat3, Mat3): T,
67
+ adjoint<T: Mat3>(T, Mat3): T,
68
+ transpose<T: Mat3>(T, Mat3): T
69
+ };
70
+
71
+ declare var mat4: {
72
+ create(): Float32Array,
73
+
74
+ fromScaling<T: Mat4>(T, Vec3): T,
75
+ fromQuat<T: Mat4>(T, Quat): T,
76
+ ortho<T: Mat4>(T, number, number, number, number, number, number): T,
77
+ perspective<T: Mat4>(T, number, number, number, number): T,
78
+ identity<T: Mat4>(T): T,
79
+ scale<T: Mat4>(T, Mat4, Vec3): T,
80
+ mul<T: Mat4>(T, Mat4, Mat4): T,
81
+ multiply<T: Mat4>(T, Mat4, Mat4): T,
82
+ rotateX<T: Mat4>(T, Mat4, number): T,
83
+ rotateY<T: Mat4>(T, Mat4, number): T,
84
+ rotateZ<T: Mat4>(T, Mat4, number): T,
85
+ translate<T: Mat4>(T, Mat4, Vec3): T,
86
+ invert<T: Mat4>(T, Mat4): T,
87
+ copy<T: Mat4>(T, Mat4): T,
88
+ clone<T: Mat4>(T): T
89
+ };
90
+
91
+ declare var quat: {
92
+ create(): Float32Array,
93
+ length(Quat): number,
94
+ exactEquals(Quat, Quat): boolean,
95
+
96
+ normalize<T: Quat>(T, Quat): T,
97
+ conjugate<T: Quat>(T, Quat): T,
98
+ identity<T: Quat>(T): T,
99
+ rotateX<T: Quat>(T, Quat, number): T,
100
+ rotateY<T: Quat>(T, Quat, number): T,
101
+ rotateZ<T: Quat>(T, Quat, number): T
102
+ }
103
+ }
@@ -0,0 +1,13 @@
1
+ // @flow strict
2
+ declare module 'grid-index' {
3
+ declare class GridIndex {
4
+ constructor(extent: number, n: number, padding: number): GridIndex;
5
+ constructor(data: ArrayBuffer): GridIndex;
6
+
7
+ insert(key: number, x1: number, y1: number, x2: number, y2: number): void;
8
+ query(x1: number, y1: number, x2: number, y2: number, intersectionText?: (number, number, number, number) => boolean): Array<number>;
9
+ toArrayBuffer(): ArrayBuffer;
10
+ }
11
+
12
+ declare export default Class<GridIndex>;
13
+ }
package/flow-typed/pbf.js CHANGED
@@ -1,3 +1,4 @@
1
+ // @flow
1
2
  declare module "pbf" {
2
3
  declare type ReadFunction<T> = (tag: number, result: T, pbf: Pbf) => void;
3
4
 
@@ -21,5 +22,5 @@ declare module "pbf" {
21
22
  readBytes(): Uint8Array;
22
23
  }
23
24
 
24
- declare module.exports: typeof Pbf
25
+ declare export default Class<Pbf>;
25
26
  }