@mapbox/mapbox-gl-style-spec 13.24.0-alpha.6 → 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 (72) hide show
  1. package/.eslintrc +10 -0
  2. package/CHANGELOG.md +10 -4
  3. package/bin/gl-style-composite.js +6 -2
  4. package/bin/gl-style-format.js +6 -2
  5. package/bin/gl-style-migrate.js +6 -2
  6. package/bin/gl-style-validate.js +5 -1
  7. package/dist/index.cjs +41 -23
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.es.js +41 -23
  10. package/dist/index.es.js.map +1 -1
  11. package/expression/compound_expression.js +2 -2
  12. package/expression/definitions/assertion.js +3 -3
  13. package/expression/definitions/at.js +5 -5
  14. package/expression/definitions/case.js +4 -4
  15. package/expression/definitions/coalesce.js +4 -4
  16. package/expression/definitions/coercion.js +3 -3
  17. package/expression/definitions/collator.js +4 -4
  18. package/expression/definitions/comparison.js +22 -22
  19. package/expression/definitions/format.js +4 -4
  20. package/expression/definitions/image.js +4 -4
  21. package/expression/definitions/in.js +5 -5
  22. package/expression/definitions/index_of.js +5 -5
  23. package/expression/definitions/interpolate.js +6 -5
  24. package/expression/definitions/length.js +5 -5
  25. package/expression/definitions/let.js +5 -5
  26. package/expression/definitions/literal.js +5 -5
  27. package/expression/definitions/match.js +4 -4
  28. package/expression/definitions/number_format.js +4 -4
  29. package/expression/definitions/slice.js +5 -5
  30. package/expression/definitions/step.js +4 -4
  31. package/expression/definitions/var.js +4 -4
  32. package/expression/definitions/within.js +16 -8
  33. package/expression/evaluation_context.js +8 -8
  34. package/expression/expression.js +1 -1
  35. package/expression/index.js +4 -4
  36. package/expression/is_constant.js +3 -3
  37. package/expression/parsing_context.js +1 -1
  38. package/expression/runtime_error.js +1 -1
  39. package/expression/scope.js +1 -1
  40. package/expression/stops.js +1 -1
  41. package/expression/values.js +1 -1
  42. package/feature_filter/index.js +1 -1
  43. package/function/convert.js +4 -4
  44. package/migrate/expressions.js +1 -1
  45. package/package.json +1 -1
  46. package/reference/latest.js +4 -0
  47. package/reference/v8.json +1 -4
  48. package/types.js +1 -1
  49. package/validate/validate.js +13 -1
  50. package/validate/validate_array.js +10 -2
  51. package/validate/validate_boolean.js +4 -1
  52. package/validate/validate_color.js +4 -1
  53. package/validate/validate_enum.js +4 -1
  54. package/validate/validate_expression.js +5 -2
  55. package/validate/validate_filter.js +12 -4
  56. package/validate/validate_fog.js +4 -1
  57. package/validate/validate_formatted.js +5 -1
  58. package/validate/validate_function.js +24 -15
  59. package/validate/validate_glyphs_url.js +4 -1
  60. package/validate/validate_image.js +5 -1
  61. package/validate/validate_layer.js +15 -2
  62. package/validate/validate_layout_property.js +5 -1
  63. package/validate/validate_light.js +4 -1
  64. package/validate/validate_number.js +8 -1
  65. package/validate/validate_object.js +12 -2
  66. package/validate/validate_paint_property.js +5 -1
  67. package/validate/validate_projection.js +5 -1
  68. package/validate/validate_property.js +9 -1
  69. package/validate/validate_source.js +4 -1
  70. package/validate/validate_string.js +4 -1
  71. package/validate/validate_terrain.js +5 -2
  72. package/validate_style.min.js +1 -1
@@ -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() {
53
+ properties(): {[string]: any} {
54
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
  }
@@ -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 '';
@@ -15,7 +15,7 @@ export type FeatureFilter = {filter: FilterExpression, dynamicFilter?: FilterExp
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
  }
@@ -1,15 +1,15 @@
1
1
  // @flow
2
2
 
3
3
  import assert from 'assert';
4
- import type {StylePropertySpecification} from '../style-spec.js';
5
4
 
6
- export default convertFunction;
5
+ import type {StylePropertySpecification} from '../style-spec.js';
6
+ import type {ExpressionSpecification} from '../types.js';
7
7
 
8
8
  function convertLiteral(value) {
9
9
  return typeof value === 'object' ? ['literal', value] : value;
10
10
  }
11
11
 
12
- function convertFunction(parameters: any, propertySpec: StylePropertySpecification) {
12
+ export default function convertFunction(parameters: any, propertySpec: StylePropertySpecification): ExpressionSpecification {
13
13
  let stops = parameters.stops;
14
14
  if (!stops) {
15
15
  // identity function
@@ -244,7 +244,7 @@ function getFunctionType(parameters, propertySpec) {
244
244
  }
245
245
 
246
246
  // "String with {name} token" => ["concat", "String with ", ["get", "name"], " token"]
247
- export function convertTokenString(s: string) {
247
+ export function convertTokenString(s: string): string | ExpressionSpecification {
248
248
  const result = ['concat'];
249
249
  const re = /{([^{}]+)}/g;
250
250
  let pos = 0;
@@ -15,7 +15,7 @@ import type {StyleSpecification} from '../types.js';
15
15
  * this will convert (a) "stop" functions, and (b) legacy filters to their
16
16
  * expression equivalents.
17
17
  */
18
- export default function(style: StyleSpecification) {
18
+ export default function(style: StyleSpecification): StyleSpecification {
19
19
  const converted = [];
20
20
 
21
21
  eachLayer(style, (layer) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mapbox/mapbox-gl-style-spec",
3
3
  "description": "a specification for mapbox gl styles",
4
- "version": "13.24.0-alpha.6",
4
+ "version": "13.24.0-beta.1",
5
5
  "author": "Mapbox",
6
6
  "keywords": [
7
7
  "mapbox",
@@ -1,3 +1,7 @@
1
+ // @flow
1
2
 
2
3
  import spec from './v8.json';
4
+
5
+ export type StyleReference = typeof spec;
6
+
3
7
  export default spec;
package/reference/v8.json CHANGED
@@ -96,7 +96,7 @@
96
96
  },
97
97
  "projection": {
98
98
  "type": "projection",
99
- "doc": "The projection the map should be rendered in. Supported projections are Albers, Equal Earth, Equirectangular (WGS84), Lambert conformal conic, Mercator, Natural Earth, Globe, and Winkel Tripel. Terrain, fog, sky and CustomLayerInterface are not supported for projections other than mercator.",
99
+ "doc": "The projection the map should be rendered in. Supported projections are Albers, Equal Earth, Equirectangular (WGS84), Lambert conformal conic, Mercator, Natural Earth, and Winkel Tripel. Terrain, fog, sky and CustomLayerInterface are not supported for projections other than mercator.",
100
100
  "example": {
101
101
  "name": "albers",
102
102
  "center": [-154, 50],
@@ -3991,9 +3991,6 @@
3991
3991
  },
3992
3992
  "winkelTripel": {
3993
3993
  "doc": "A Winkel Tripel projection."
3994
- },
3995
- "globe": {
3996
- "doc": "A globe projection."
3997
3994
  }
3998
3995
  },
3999
3996
  "default": "mercator",
package/types.js CHANGED
@@ -95,7 +95,7 @@ export type FogSpecification = {|
95
95
  |}
96
96
 
97
97
  export type ProjectionSpecification = {|
98
- "name": "albers" | "equalEarth" | "equirectangular" | "lambertConformalConic" | "mercator" | "naturalEarth" | "winkelTripel" | "globe",
98
+ "name": "albers" | "equalEarth" | "equirectangular" | "lambertConformalConic" | "mercator" | "naturalEarth" | "winkelTripel",
99
99
  "center"?: [number, number],
100
100
  "parallels"?: [number, number]
101
101
  |}
@@ -1,3 +1,4 @@
1
+ // @flow
1
2
 
2
3
  import extend from '../util/extend.js';
3
4
  import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint.js';
@@ -23,6 +24,10 @@ import validateFormatted from './validate_formatted.js';
23
24
  import validateImage from './validate_image.js';
24
25
  import validateProjection from './validate_projection.js';
25
26
 
27
+ import type {StyleReference} from '../reference/latest.js';
28
+ import type {StyleSpecification} from '../types.js';
29
+ import type ValidationError from '../error/validation_error.js';
30
+
26
31
  const VALIDATORS = {
27
32
  '*'() {
28
33
  return [];
@@ -55,8 +60,15 @@ const VALIDATORS = {
55
60
  // scalar value.
56
61
  // - valueSpec: current spec being evaluated. Tracks value.
57
62
  // - styleSpec: current full spec being evaluated.
63
+ export type ValidationOptions = {
64
+ key: string;
65
+ value: Object;
66
+ valueSpec: Object;
67
+ style: $Shape<StyleSpecification>;
68
+ styleSpec: StyleReference;
69
+ }
58
70
 
59
- export default function validate(options) {
71
+ export default function validate(options: ValidationOptions): Array<ValidationError> {
60
72
  const value = options.value;
61
73
  const valueSpec = options.valueSpec;
62
74
  const styleSpec = options.styleSpec;
@@ -1,9 +1,16 @@
1
+ // @flow
1
2
 
2
3
  import getType from '../util/get_type.js';
3
4
  import validate from './validate.js';
4
5
  import ValidationError from '../error/validation_error.js';
5
6
 
6
- export default function validateArray(options) {
7
+ import type {ValidationOptions} from './validate.js';
8
+
9
+ type Options = ValidationOptions & {
10
+ arrayElementValidator: Function;
11
+ };
12
+
13
+ export default function validateArray(options: Options): Array<ValidationError> {
7
14
  const array = options.value;
8
15
  const arraySpec = options.valueSpec;
9
16
  const style = options.style;
@@ -27,7 +34,8 @@ export default function validateArray(options) {
27
34
  "type": arraySpec.value,
28
35
  "values": arraySpec.values,
29
36
  "minimum": arraySpec.minimum,
30
- "maximum": arraySpec.maximum
37
+ "maximum": arraySpec.maximum,
38
+ function: undefined
31
39
  };
32
40
 
33
41
  if (styleSpec.$version < 7) {
@@ -1,8 +1,11 @@
1
+ // @flow
1
2
 
2
3
  import getType from '../util/get_type.js';
3
4
  import ValidationError from '../error/validation_error.js';
4
5
 
5
- export default function validateBoolean(options) {
6
+ import type {ValidationOptions} from './validate.js';
7
+
8
+ export default function validateBoolean(options: ValidationOptions): Array<ValidationError> {
6
9
  const value = options.value;
7
10
  const key = options.key;
8
11
  const type = getType(value);
@@ -1,9 +1,12 @@
1
+ // @flow
1
2
 
2
3
  import ValidationError from '../error/validation_error.js';
3
4
  import getType from '../util/get_type.js';
4
5
  import {parseCSSColor} from 'csscolorparser';
5
6
 
6
- export default function validateColor(options) {
7
+ import type {ValidationOptions} from './validate.js';
8
+
9
+ export default function validateColor(options: ValidationOptions): Array<ValidationError> {
7
10
  const key = options.key;
8
11
  const value = options.value;
9
12
  const type = getType(value);
@@ -1,8 +1,11 @@
1
+ // @flow
1
2
 
2
3
  import ValidationError from '../error/validation_error.js';
3
4
  import {unbundle} from '../util/unbundle_jsonlint.js';
4
5
 
5
- export default function validateEnum(options) {
6
+ import type {ValidationOptions} from './validate.js';
7
+
8
+ export default function validateEnum(options: ValidationOptions): Array<ValidationError> {
6
9
  const key = options.key;
7
10
  const value = options.value;
8
11
  const valueSpec = options.valueSpec;
@@ -52,8 +52,11 @@ export function disallowedFilterParameters(e: Expression, options: any): Array<V
52
52
  'pitch',
53
53
  'distance-from-center'
54
54
  ]);
55
- for (const param of options.valueSpec.expression.parameters) {
56
- disallowedParameters.delete(param);
55
+
56
+ if (options.valueSpec && options.valueSpec.expression) {
57
+ for (const param of options.valueSpec.expression.parameters) {
58
+ disallowedParameters.delete(param);
59
+ }
57
60
  }
58
61
 
59
62
  if (disallowedParameters.size === 0) {
@@ -1,3 +1,4 @@
1
+ // @flow
1
2
 
2
3
  import ValidationError from '../error/validation_error.js';
3
4
  import validateExpression from './validate_expression.js';
@@ -7,13 +8,20 @@ import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint.js';
7
8
  import extend from '../util/extend.js';
8
9
  import {isExpressionFilter} from '../feature_filter/index.js';
9
10
 
10
- export default function validateFilter(options) {
11
+ import type {ValidationOptions} from './validate.js';
12
+
13
+ type Options = ValidationOptions & {
14
+ layerType: string;
15
+ }
16
+
17
+ export default function validateFilter(options: Options): Array<ValidationError> {
11
18
  if (isExpressionFilter(deepUnbundle(options.value))) {
12
- const layerType = deepUnbundle(options.layerType);
19
+ // We default to a layerType of `fill` because that points to a non-dynamic filter definition within the style-spec.
20
+ const layerType = options.layerType || 'fill';
21
+
13
22
  return validateExpression(extend({}, options, {
14
23
  expressionContext: 'filter',
15
- // We default to a layerType of `fill` because that points to a non-dynamic filter definition within the style-spec.
16
- valueSpec: options.styleSpec[`filter_${layerType || 'fill'}`]
24
+ valueSpec: options.styleSpec[`filter_${layerType}`]
17
25
  }));
18
26
  } else {
19
27
  return validateNonExpressionFilter(options);