@mapbox/mapbox-gl-style-spec 13.28.0 → 14.0.0-beta.2

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 (60) hide show
  1. package/LICENSE.txt +47 -0
  2. package/README.md +7 -0
  3. package/data/extent.js +18 -0
  4. package/deref.js +1 -1
  5. package/diff.js +36 -15
  6. package/dist/index.cjs +5839 -2015
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.es.js +5837 -2011
  9. package/dist/index.es.js.map +1 -1
  10. package/expression/compound_expression.js +2 -1
  11. package/expression/definitions/assertion.js +2 -2
  12. package/expression/definitions/coercion.js +54 -15
  13. package/expression/definitions/comparison.js +2 -0
  14. package/expression/definitions/distance.js +597 -0
  15. package/expression/definitions/format.js +2 -2
  16. package/expression/definitions/image.js +34 -14
  17. package/expression/definitions/index.js +122 -8
  18. package/expression/definitions/interpolate.js +1 -1
  19. package/expression/definitions/match.js +2 -2
  20. package/expression/definitions/within.js +21 -92
  21. package/expression/evaluation_context.js +12 -1
  22. package/expression/index.js +74 -43
  23. package/expression/is_constant.js +19 -1
  24. package/expression/parsing_context.js +20 -16
  25. package/expression/types/formatted.js +2 -2
  26. package/expression/types/resolved_image.js +19 -8
  27. package/expression/types.js +2 -1
  28. package/expression/values.js +25 -0
  29. package/feature_filter/convert.js +1 -1
  30. package/feature_filter/index.js +4 -4
  31. package/flow-typed/cheap-ruler.js +25 -0
  32. package/flow-typed/geojson.js +8 -7
  33. package/flow-typed/gl-matrix.js +4 -2
  34. package/flow-typed/kdbush.js +9 -0
  35. package/function/convert.js +23 -12
  36. package/group_by_layout.js +2 -2
  37. package/migrate/expressions.js +3 -0
  38. package/package.json +6 -3
  39. package/reference/v8.json +1771 -114
  40. package/style-spec.js +4 -3
  41. package/types.js +190 -24
  42. package/util/color.js +31 -0
  43. package/util/geometry_util.js +145 -0
  44. package/util/properties.js +10 -2
  45. package/util/random.js +12 -0
  46. package/validate/validate.js +17 -7
  47. package/validate/validate_array.js +1 -1
  48. package/validate/validate_filter.js +4 -12
  49. package/validate/validate_function.js +2 -2
  50. package/validate/validate_import.js +31 -0
  51. package/validate/validate_layer.js +3 -2
  52. package/validate/validate_lights.js +84 -0
  53. package/validate/validate_model.js +38 -0
  54. package/validate/validate_property.js +18 -4
  55. package/validate/validate_source.js +3 -2
  56. package/validate/validate_style.js +29 -0
  57. package/validate_mapbox_api_supported.js +55 -11
  58. package/validate_style.js +4 -0
  59. package/validate_style.min.js +11 -19
  60. package/visit.js +3 -2
@@ -72,7 +72,7 @@ class CompoundExpression implements Expression {
72
72
  for (const [params, evaluate] of overloads) {
73
73
  // Use a fresh context for each attempted signature so that, if
74
74
  // we eventually succeed, we haven't polluted `context.errors`.
75
- signatureContext = new ParsingContext(context.registry, context.path, null, context.scope);
75
+ signatureContext = new ParsingContext(context.registry, context.path, null, context.scope, undefined, context.options);
76
76
 
77
77
  // First parse all the args, potentially coercing to the
78
78
  // types expected by this overload.
@@ -146,6 +146,7 @@ class CompoundExpression implements Expression {
146
146
  assert(!CompoundExpression.definitions);
147
147
  CompoundExpression.definitions = definitions;
148
148
  for (const name in definitions) {
149
+ // $FlowFixMe[method-unbinding]
149
150
  registry[name] = CompoundExpression;
150
151
  }
151
152
  }
@@ -56,7 +56,7 @@ class Assertion implements Expression {
56
56
  itemType = ValueType;
57
57
  }
58
58
 
59
- let N;
59
+ let N: ?number;
60
60
  if (args.length > 3) {
61
61
  if (args[2] !== null &&
62
62
  (typeof args[2] !== 'number' ||
@@ -65,7 +65,7 @@ class Assertion implements Expression {
65
65
  ) {
66
66
  return context.error('The length argument to "array" must be a positive integer literal', 2);
67
67
  }
68
- N = args[2];
68
+ N = ((args[2]: any): number);
69
69
  i++;
70
70
  }
71
71
 
@@ -2,8 +2,8 @@
2
2
 
3
3
  import assert from 'assert';
4
4
 
5
- import {BooleanType, ColorType, NumberType, StringType, ValueType} from '../types.js';
6
- import {Color, toString as valueToString, validateRGBA} from '../values.js';
5
+ import {BooleanType, ColorType, NumberType, StringType, ValueType, array, NullType} from '../types.js';
6
+ import {Color, isValue, toString as valueToString, typeOf, validateRGBA} from '../values.js';
7
7
  import RuntimeError from '../runtime_error.js';
8
8
  import Formatted from '../types/formatted.js';
9
9
  import FormatExpression from '../definitions/format.js';
@@ -13,7 +13,8 @@ import ResolvedImage from '../types/resolved_image.js';
13
13
  import type {Expression, SerializedExpression} from '../expression.js';
14
14
  import type ParsingContext from '../parsing_context.js';
15
15
  import type EvaluationContext from '../evaluation_context.js';
16
- import type {Type} from '../types.js';
16
+ import type {Type, ArrayType} from '../types.js';
17
+ import getType from '../../util/get_type.js';
17
18
 
18
19
  const types = {
19
20
  'to-boolean': BooleanType,
@@ -30,7 +31,7 @@ const types = {
30
31
  * @private
31
32
  */
32
33
  class Coercion implements Expression {
33
- type: Type;
34
+ type: Type | ArrayType;
34
35
  args: Array<Expression>;
35
36
 
36
37
  constructor(type: Type, args: Array<Expression>) {
@@ -43,24 +44,60 @@ class Coercion implements Expression {
43
44
  return context.error(`Expected at least one argument.`);
44
45
 
45
46
  const name: string = (args[0]: any);
46
- assert(types[name], name);
47
+ const parsed = [];
48
+ let type: Type | ArrayType = NullType;
49
+ if (name === 'to-array') {
50
+ if (!Array.isArray(args[1])) {
51
+ return null;
52
+ }
53
+ const arrayLength = args[1].length;
54
+ if (context.expectedType) {
55
+ if (context.expectedType.kind === 'array') {
56
+ type = array(context.expectedType.itemType, arrayLength);
57
+ } else {
58
+ return context.error(`Expected ${context.expectedType.kind} but found array.`);
59
+ }
60
+ } else if (arrayLength > 0 && isValue(args[1][0])) {
61
+ const value = (args[1][0]: any);
62
+ type = array(typeOf(value), arrayLength);
63
+ } else {
64
+ return null;
65
+ }
66
+ for (let i = 0; i < arrayLength; i++) {
67
+ // $FlowIgnore
68
+ const member = args[1][i];
69
+ let parsedMember;
70
+ if (getType(member) === 'array') {
71
+ parsedMember = context.parse(member, undefined, type.itemType);
72
+ } else {
73
+ const memberType = getType(member);
74
+ if (memberType !== type.itemType.kind) {
75
+ return context.error(`Expected ${type.itemType.kind} but found ${memberType}.`);
76
+ }
77
+ parsedMember = context.registry['literal'].parse(['literal', member === undefined ? null : member], context);
78
+ }
79
+ if (!parsedMember) return null;
80
+ parsed.push(parsedMember);
81
+ }
82
+ } else {
83
+ assert(types[name], name);
47
84
 
48
- if ((name === 'to-boolean' || name === 'to-string') && args.length !== 2)
49
- return context.error(`Expected one argument.`);
85
+ if ((name === 'to-boolean' || name === 'to-string') && args.length !== 2)
86
+ return context.error(`Expected one argument.`);
50
87
 
51
- const type = types[name];
88
+ type = types[name];
52
89
 
53
- const parsed = [];
54
- for (let i = 1; i < args.length; i++) {
55
- const input = context.parse(args[i], i, ValueType);
56
- if (!input) return null;
57
- parsed.push(input);
90
+ for (let i = 1; i < args.length; i++) {
91
+ const input = context.parse(args[i], i, ValueType);
92
+ if (!input) return null;
93
+ parsed.push(input);
94
+ }
58
95
  }
59
96
 
60
97
  return new Coercion(type, parsed);
61
98
  }
62
99
 
63
- evaluate(ctx: EvaluationContext): null | boolean | number | string | Color | Formatted | ResolvedImage {
100
+ evaluate(ctx: EvaluationContext): any {
64
101
  if (this.type.kind === 'boolean') {
65
102
  return Boolean(this.args[0].evaluate(ctx));
66
103
  } else if (this.type.kind === 'color') {
@@ -102,6 +139,8 @@ class Coercion implements Expression {
102
139
  return Formatted.fromString(valueToString(this.args[0].evaluate(ctx)));
103
140
  } else if (this.type.kind === 'resolvedImage') {
104
141
  return ResolvedImage.fromString(valueToString(this.args[0].evaluate(ctx)));
142
+ } else if (this.type.kind === 'array') {
143
+ return this.args.map(arg => { return arg.evaluate(ctx); });
105
144
  } else {
106
145
  return valueToString(this.args[0].evaluate(ctx));
107
146
  }
@@ -124,7 +163,7 @@ class Coercion implements Expression {
124
163
  return new ImageExpression(this.args[0]).serialize();
125
164
  }
126
165
 
127
- const serialized = [`to-${this.type.kind}`];
166
+ const serialized: Array<mixed> = this.type.kind === 'array' ? [] : [`to-${this.type.kind}`];
128
167
  this.eachChild(child => { serialized.push(child.serialize()); });
129
168
  return serialized;
130
169
  }
@@ -62,6 +62,7 @@ function gteqCollate(ctx: EvaluationContext, a: any, b: any, c: any): boolean {
62
62
  function makeComparison(op: ComparisonOperator, compareBasic: (EvaluationContext, any, any) => boolean, compareWithCollator: (EvaluationContext, any, any, any) => boolean): ExpressionRegistration {
63
63
  const isOrderComparison = op !== '==' && op !== '!=';
64
64
 
65
+ // $FlowFixMe[method-unbinding]
65
66
  return class Comparison implements Expression {
66
67
  type: Type;
67
68
  lhs: Expression;
@@ -77,6 +78,7 @@ function makeComparison(op: ComparisonOperator, compareBasic: (EvaluationContext
77
78
  this.hasUntypedArgument = lhs.type.kind === 'value' || rhs.type.kind === 'value';
78
79
  }
79
80
 
81
+ // $FlowFixMe[method-unbinding]
80
82
  static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?Expression {
81
83
  if (args.length !== 3 && args.length !== 4)
82
84
  return context.error(`Expected two or three arguments.`);