@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,26 +1,18 @@
1
- // @flow
2
-
3
1
  import assert from 'assert';
4
2
 
5
- import type {StylePropertySpecification} from '../style-spec.js';
6
- import type {ExpressionSpecification} from '../types.js';
7
-
8
- type Stop = [{zoom: number, value: string | number | boolean}, mixed];
9
-
10
- type FunctionParameters = {
11
- stops: Array<Stop>;
12
- base: number;
13
- property: string;
14
- type: 'identity' | 'exponential' | 'interval' | 'categorical';
15
- colorSpace: 'rgb' | 'lab' | 'hcl';
16
- default: mixed;
17
- };
3
+ import type {StylePropertySpecification} from '../style-spec';
4
+ import type {
5
+ FunctionSpecification,
6
+ PropertyFunctionStop,
7
+ ZoomAndPropertyFunctionStop,
8
+ ExpressionSpecification,
9
+ } from '../types';
18
10
 
19
- function convertLiteral(value: mixed) {
11
+ function convertLiteral(value: unknown) {
20
12
  return typeof value === 'object' ? ['literal', value] : value;
21
13
  }
22
14
 
23
- export default function convertFunction(parameters: FunctionParameters, propertySpec: StylePropertySpecification): ExpressionSpecification {
15
+ export default function convertFunction<T>(parameters: FunctionSpecification<T>, propertySpec: StylePropertySpecification): ExpressionSpecification {
24
16
  let stops = parameters.stops;
25
17
  if (!stops) {
26
18
  // identity function
@@ -36,19 +28,19 @@ export default function convertFunction(parameters: FunctionParameters, property
36
28
  return [stop[0], convertTokenString(stop[1])];
37
29
  }
38
30
  return [stop[0], convertLiteral(stop[1])];
39
- });
31
+ }) as FunctionSpecification<T>['stops'];
40
32
 
41
33
  if (zoomAndFeatureDependent) {
42
- return convertZoomAndPropertyFunction(parameters, propertySpec, stops);
34
+ return convertZoomAndPropertyFunction(parameters, propertySpec, stops as Array<ZoomAndPropertyFunctionStop<T>>);
43
35
  } else if (zoomDependent) {
44
- return convertZoomFunction(parameters, propertySpec, stops);
36
+ return convertZoomFunction(parameters, propertySpec, stops as PropertyFunctionStop<T>[]);
45
37
  } else {
46
- return convertPropertyFunction(parameters, propertySpec, stops);
38
+ return convertPropertyFunction(parameters, propertySpec, stops as PropertyFunctionStop<T>[]);
47
39
  }
48
40
  }
49
41
 
50
- function convertIdentityFunction(parameters: FunctionParameters, propertySpec: StylePropertySpecification): Array<mixed> {
51
- const get = ['get', parameters.property];
42
+ function convertIdentityFunction<T>(parameters: FunctionSpecification<T>, propertySpec: StylePropertySpecification): ExpressionSpecification {
43
+ const get: ExpressionSpecification = ['get', parameters.property];
52
44
 
53
45
  if (parameters.default === undefined) {
54
46
  // By default, expressions for string-valued properties get coerced. To preserve
@@ -63,7 +55,7 @@ function convertIdentityFunction(parameters: FunctionParameters, propertySpec: S
63
55
  parameters.default
64
56
  ];
65
57
  } else {
66
- const expression = [propertySpec.type === 'color' ? 'to-color' : propertySpec.type, get, convertLiteral(parameters.default)];
58
+ const expression: ExpressionSpecification = [propertySpec.type === 'color' ? 'to-color' : propertySpec.type, get, convertLiteral(parameters.default)];
67
59
  if (propertySpec.type === 'array') {
68
60
  expression.splice(1, 0, propertySpec.value, propertySpec.length || null);
69
61
  }
@@ -71,7 +63,7 @@ function convertIdentityFunction(parameters: FunctionParameters, propertySpec: S
71
63
  }
72
64
  }
73
65
 
74
- function getInterpolateOperator(parameters: FunctionParameters) {
66
+ function getInterpolateOperator<T>(parameters: FunctionSpecification<T>) {
75
67
  switch (parameters.colorSpace) {
76
68
  case 'hcl': return 'interpolate-hcl';
77
69
  case 'lab': return 'interpolate-lab';
@@ -79,9 +71,13 @@ function getInterpolateOperator(parameters: FunctionParameters) {
79
71
  }
80
72
  }
81
73
 
82
- function convertZoomAndPropertyFunction(parameters: FunctionParameters, propertySpec: StylePropertySpecification, stops: Array<Stop>) {
83
- const featureFunctionParameters = {};
84
- const featureFunctionStops = {};
74
+ function convertZoomAndPropertyFunction<T>(
75
+ parameters: FunctionSpecification<T>,
76
+ propertySpec: StylePropertySpecification,
77
+ stops: Array<ZoomAndPropertyFunctionStop<T>>,
78
+ ): ExpressionSpecification {
79
+ const featureFunctionParameters: Record<string, any> = {};
80
+ const featureFunctionStops: Record<string, any> = {};
85
81
  const zoomStops = [];
86
82
  for (let s = 0; s < stops.length; s++) {
87
83
  const stop = stops[s];
@@ -103,9 +99,9 @@ function convertZoomAndPropertyFunction(parameters: FunctionParameters, property
103
99
  // function is determined directly from the style property specification
104
100
  // for which it's being used: linear for interpolatable properties, step
105
101
  // otherwise.
106
- const functionType = getFunctionType({}, propertySpec);
102
+ const functionType = getFunctionType({} as FunctionSpecification<unknown>, propertySpec);
107
103
  if (functionType === 'exponential') {
108
- const expression = [getInterpolateOperator(parameters), ['linear'], ['zoom']];
104
+ const expression: ExpressionSpecification = [getInterpolateOperator(parameters), ['linear'], ['zoom']];
109
105
 
110
106
  for (const z of zoomStops) {
111
107
  const output = convertPropertyFunction(featureFunctionParameters[z], propertySpec, featureFunctionStops[z]);
@@ -114,7 +110,7 @@ function convertZoomAndPropertyFunction(parameters: FunctionParameters, property
114
110
 
115
111
  return expression;
116
112
  } else {
117
- const expression = ['step', ['zoom']];
113
+ const expression: ExpressionSpecification = ['step', ['zoom']];
118
114
 
119
115
  for (const z of zoomStops) {
120
116
  const output = convertPropertyFunction(featureFunctionParameters[z], propertySpec, featureFunctionStops[z]);
@@ -127,12 +123,12 @@ function convertZoomAndPropertyFunction(parameters: FunctionParameters, property
127
123
  }
128
124
  }
129
125
 
130
- function coalesce(a: mixed, b: mixed) {
126
+ function coalesce(a: unknown, b: unknown) {
131
127
  if (a !== undefined) return a;
132
128
  if (b !== undefined) return b;
133
129
  }
134
130
 
135
- function getFallback(parameters: FunctionParameters, propertySpec: StylePropertySpecification) {
131
+ function getFallback<T>(parameters: FunctionSpecification<T>, propertySpec: StylePropertySpecification) {
136
132
  const defaultValue = convertLiteral(coalesce(parameters.default, propertySpec.default));
137
133
 
138
134
  /*
@@ -147,12 +143,16 @@ function getFallback(parameters: FunctionParameters, propertySpec: StyleProperty
147
143
  return defaultValue;
148
144
  }
149
145
 
150
- function convertPropertyFunction(parameters: FunctionParameters, propertySpec: StylePropertySpecification, stops: Array<Stop>) {
146
+ function convertPropertyFunction<T>(
147
+ parameters: FunctionSpecification<T>,
148
+ propertySpec: StylePropertySpecification,
149
+ stops: Array<PropertyFunctionStop<T>>,
150
+ ): ExpressionSpecification {
151
151
  const type = getFunctionType(parameters, propertySpec);
152
- const get = ['get', parameters.property];
152
+ const get: ExpressionSpecification = ['get', parameters.property];
153
153
  if (type === 'categorical' && typeof stops[0][0] === 'boolean') {
154
154
  assert(parameters.stops.length > 0 && parameters.stops.length <= 2);
155
- const expression = ['case'];
155
+ const expression: ExpressionSpecification = ['case'];
156
156
  for (const stop of stops) {
157
157
  expression.push(['==', get, stop[0]], stop[1]);
158
158
  }
@@ -160,14 +160,14 @@ function convertPropertyFunction(parameters: FunctionParameters, propertySpec: S
160
160
  expression.push(getFallback(parameters, propertySpec));
161
161
  return expression;
162
162
  } else if (type === 'categorical') {
163
- const expression = ['match', get];
163
+ const expression: ExpressionSpecification = ['match', get];
164
164
  for (const stop of stops) {
165
165
  appendStopPair(expression, stop[0], stop[1], false);
166
166
  }
167
167
  expression.push(getFallback(parameters, propertySpec));
168
168
  return expression;
169
169
  } else if (type === 'interval') {
170
- const expression = ['step', ['number', get]];
170
+ const expression: ExpressionSpecification = ['step', ['number', get]];
171
171
  for (const stop of stops) {
172
172
  appendStopPair(expression, stop[0], stop[1], true);
173
173
  }
@@ -180,7 +180,7 @@ function convertPropertyFunction(parameters: FunctionParameters, propertySpec: S
180
180
  ];
181
181
  } else if (type === 'exponential') {
182
182
  const base = parameters.base !== undefined ? parameters.base : 1;
183
- const expression = [
183
+ const expression: ExpressionSpecification = [
184
184
  getInterpolateOperator(parameters),
185
185
  base === 1 ? ["linear"] : ["exponential", base],
186
186
  ["number", get]
@@ -200,7 +200,7 @@ function convertPropertyFunction(parameters: FunctionParameters, propertySpec: S
200
200
  }
201
201
  }
202
202
 
203
- function convertZoomFunction(parameters: FunctionParameters, propertySpec: StylePropertySpecification, stops: Array<Stop>, input: Array<string> = ['zoom']) {
203
+ function convertZoomFunction<T>(parameters: FunctionSpecification<T>, propertySpec: StylePropertySpecification, stops: Array<PropertyFunctionStop<T>>, input: Array<string> = ['zoom']) {
204
204
  const type = getFunctionType(parameters, propertySpec);
205
205
  let expression;
206
206
  let isStep = false;
@@ -232,7 +232,7 @@ function fixupDegenerateStepCurve(expression: ExpressionSpecification) {
232
232
  }
233
233
  }
234
234
 
235
- function appendStopPair(curve: ExpressionSpecification, input: mixed, output: mixed, isStep: boolean) {
235
+ function appendStopPair(curve: ExpressionSpecification, input: unknown, output: unknown, isStep: boolean) {
236
236
  // Skip duplicate stop values. They were not validated for functions, but they are for expressions.
237
237
  // https://github.com/mapbox/mapbox-gl-js/issues/4107
238
238
  if (curve.length > 3 && input === curve[curve.length - 2]) {
@@ -245,18 +245,18 @@ function appendStopPair(curve: ExpressionSpecification, input: mixed, output: mi
245
245
  curve.push(output);
246
246
  }
247
247
 
248
- function getFunctionType(parameters: FunctionParameters, propertySpec: StylePropertySpecification): string {
248
+ function getFunctionType<T>(parameters: FunctionSpecification<T>, propertySpec: StylePropertySpecification): string {
249
249
  if (parameters.type) {
250
250
  return parameters.type;
251
251
  } else {
252
252
  assert(propertySpec.expression);
253
- return (propertySpec.expression: any).interpolated ? 'exponential' : 'interval';
253
+ return (propertySpec.expression as any).interpolated ? 'exponential' : 'interval';
254
254
  }
255
255
  }
256
256
 
257
257
  // "String with {name} token" => ["concat", "String with ", ["get", "name"], " token"]
258
258
  export function convertTokenString(s: string): string | ExpressionSpecification {
259
- const result = ['concat'];
259
+ const result: ExpressionSpecification = ['concat'];
260
260
  const re = /{([^{}]+)}/g;
261
261
  let pos = 0;
262
262
  for (let match = re.exec(s); match !== null; match = re.exec(s)) {
@@ -1,15 +1,15 @@
1
- // @noflow
1
+ // @ts-nocheck
2
2
 
3
- import * as colorSpaces from '../util/color_spaces.js';
4
- import Color from '../util/color.js';
5
- import extend from '../util/extend.js';
6
- import getType from '../util/get_type.js';
7
- import * as interpolate from '../util/interpolate.js';
8
- import Interpolate from '../expression/definitions/interpolate.js';
9
- import Formatted from '../expression/types/formatted.js';
10
- import ResolvedImage from '../expression/types/resolved_image.js';
11
- import {supportsInterpolation} from '../util/properties.js';
12
- import {findStopLessThanOrEqualTo} from '../expression/stops.js';
3
+ import * as colorSpaces from '../util/color_spaces';
4
+ import Color from '../util/color';
5
+ import extend from '../util/extend';
6
+ import getType from '../util/get_type';
7
+ import * as interpolate from '../util/interpolate';
8
+ import Interpolate from '../expression/definitions/interpolate';
9
+ import Formatted from '../expression/types/formatted';
10
+ import ResolvedImage from '../expression/types/resolved_image';
11
+ import {supportsInterpolation} from '../util/properties';
12
+ import {findStopLessThanOrEqualTo} from '../expression/stops';
13
13
 
14
14
  export function isFunction(value) {
15
15
  return typeof value === 'object' && value !== null && !Array.isArray(value);
@@ -72,7 +72,7 @@ export function createFunction(parameters, propertySpec) {
72
72
  }
73
73
 
74
74
  if (zoomAndFeatureDependent) {
75
- const featureFunctions = {};
75
+ const featureFunctions: Record<string, any> = {};
76
76
  const zoomStops = [];
77
77
  for (let s = 0; s < parameters.stops.length; s++) {
78
78
  const stop = parameters.stops[s];
@@ -1,8 +1,6 @@
1
- // @flow
1
+ import type {LayerSpecification} from './types';
2
2
 
3
- import type {LayerSpecification} from './types.js';
4
-
5
- import refProperties from './util/ref_properties.js';
3
+ import refProperties from './util/ref_properties';
6
4
 
7
5
  function stringify(obj: any) {
8
6
  if (typeof obj === 'number' || typeof obj === 'boolean' || typeof obj === 'string' || obj === undefined || obj === null)
@@ -18,7 +16,7 @@ function stringify(obj: any) {
18
16
 
19
17
  let str = '{';
20
18
  for (const key of Object.keys(obj).sort()) {
21
- str += `${key}:${stringify((obj: any)[key])},`;
19
+ str += `${key}:${stringify((obj)[key])},`;
22
20
  }
23
21
  return `${str}}`;
24
22
  }
@@ -26,7 +24,7 @@ function stringify(obj: any) {
26
24
  function getKey(layer: LayerSpecification) {
27
25
  let key = '';
28
26
  for (const k of refProperties) {
29
- key += `/${stringify((layer: any)[k])}`;
27
+ key += `/${stringify((layer as any)[k])}`;
30
28
  }
31
29
  return key;
32
30
  }
@@ -46,8 +44,13 @@ function getKey(layer: LayerSpecification) {
46
44
  * @param {Object} [cachedKeys] - an object to keep already calculated keys.
47
45
  * @returns {Array<Array<Layer>>}
48
46
  */
49
- export default function groupByLayout(layers: Array<LayerSpecification>, cachedKeys: {[id: string]: string}): Array<Array<LayerSpecification>> {
50
- const groups = {};
47
+ export default function groupByLayout(
48
+ layers: Array<LayerSpecification>,
49
+ cachedKeys: {
50
+ [id: string]: string;
51
+ },
52
+ ): Array<Array<LayerSpecification>> {
53
+ const groups: Record<string, any> = {};
51
54
 
52
55
  for (let i = 0; i < layers.length; i++) {
53
56
 
@@ -1,14 +1,9 @@
1
- // @flow
1
+ import {eachLayer, eachProperty} from '../visit';
2
+ import {isExpression} from '../expression/index';
3
+ import convertFunction, {convertTokenString} from '../function/convert';
4
+ import convertFilter from '../feature_filter/convert';
2
5
 
3
- import {
4
- eachLayer,
5
- eachProperty
6
- } from '../visit.js';
7
- import {isExpression} from '../expression/index.js';
8
- import convertFunction, {convertTokenString} from '../function/convert.js';
9
- import convertFilter from '../feature_filter/convert.js';
10
-
11
- import type {StyleSpecification} from '../types.js';
6
+ import type {StyleSpecification, FunctionSpecification} from '../types';
12
7
 
13
8
  /**
14
9
  * Migrate the given style object in place to use expressions. Specifically,
@@ -20,17 +15,14 @@ export default function(style: StyleSpecification): StyleSpecification {
20
15
 
21
16
  eachLayer(style, (layer) => {
22
17
  if (layer.filter) {
23
- layer.filter = (convertFilter(layer.filter): any);
18
+ layer.filter = (convertFilter(layer.filter) as any);
24
19
  }
25
20
  });
26
21
 
27
22
  eachProperty(style, {paint: true, layout: true}, ({path, value, reference, set}) => {
28
23
  if (isExpression(value)) return;
29
24
  if (typeof value === 'object' && !Array.isArray(value)) {
30
- // $FlowFixMe[prop-missing]
31
- // $FlowFixMe[incompatible-call]
32
- // $FlowFixMe[incompatible-variance]
33
- set(convertFunction(value, reference));
25
+ set(convertFunction(value as FunctionSpecification<unknown>, reference));
34
26
  converted.push(path.join('.'));
35
27
  } else if (reference.tokens && typeof value === 'string') {
36
28
  set(convertTokenString(value));
@@ -39,4 +31,3 @@ export default function(style: StyleSpecification): StyleSpecification {
39
31
 
40
32
  return style;
41
33
  }
42
-
@@ -1,5 +1,5 @@
1
- // @noflow
2
- import {eachSource, eachLayer, eachProperty} from '../visit.js';
1
+ // @ts-nocheck
2
+ import {eachSource, eachLayer, eachProperty} from '../visit';
3
3
 
4
4
  function eachLayout(layer, callback) {
5
5
  for (const k in layer) {
@@ -1,5 +1,5 @@
1
- // @noflow
2
- import deref from '../deref.js';
1
+ // @ts-nocheck
2
+ import deref from '../deref';
3
3
 
4
4
  function eachLayer(style, callback) {
5
5
  for (const k in style.layers) {
@@ -1,7 +1,7 @@
1
- // @noflow
1
+ // @ts-nocheck
2
2
 
3
- import migrateToV8 from './migrate/v8.js';
4
- import migrateToExpressions from './migrate/expressions.js';
3
+ import migrateToV8 from './migrate/v8';
4
+ import migrateToExpressions from './migrate/expressions';
5
5
 
6
6
  /**
7
7
  * Migrate a Mapbox GL Style to the latest version.
package/package.json CHANGED
@@ -1,17 +1,23 @@
1
1
  {
2
2
  "name": "@mapbox/mapbox-gl-style-spec",
3
+ "version": "14.5.0",
3
4
  "description": "a specification for mapbox gl styles",
4
- "version": "14.4.0",
5
5
  "author": "Mapbox",
6
+ "license": "SEE LICENSE IN LICENSE.txt",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git@github.com:mapbox/mapbox-gl-js.git"
10
+ },
6
11
  "keywords": [
7
12
  "mapbox",
8
13
  "mapbox-gl",
9
14
  "mapbox-gl-js"
10
15
  ],
11
- "license": "SEE LICENSE IN LICENSE.txt",
12
16
  "main": "./dist/index.cjs",
13
17
  "module": "./dist/index.es.js",
18
+ "types": "./dist/index.d.ts",
14
19
  "type": "module",
20
+ "sideEffects": false,
15
21
  "exports": {
16
22
  ".": {
17
23
  "require": "./dist/index.cjs",
@@ -24,14 +30,11 @@
24
30
  "scripts": {
25
31
  "pretest": "npm run build",
26
32
  "test": "node ./test.js",
27
- "copy-flow-typed": "cp -R ../../flow-typed .",
28
- "build": "../../node_modules/.bin/rollup -c && ../../node_modules/.bin/rollup -c --environment esm",
29
- "prepublishOnly": "npm run copy-flow-typed && npm run build",
30
- "postpublish": "rm -r flow-typed dist/index.cjs"
31
- },
32
- "repository": {
33
- "type": "git",
34
- "url": "git@github.com:mapbox/mapbox-gl-js.git"
33
+ "build": "npm run build-spec && npm run build-dts",
34
+ "build-dts": "dts-bundle-generator --no-banner --export-referenced-types=false -o ./dist/index.d.ts ./style-spec.ts",
35
+ "build-spec": "rollup -c && rollup -c --environment esm",
36
+ "prepublishOnly": "npm run build",
37
+ "postpublish": "rm dist/index.cjs dist/index.d.ts"
35
38
  },
36
39
  "bin": {
37
40
  "gl-style-migrate": "./bin/gl-style-migrate.js",
@@ -42,15 +45,13 @@
42
45
  "dependencies": {
43
46
  "@mapbox/jsonlint-lines-primitives": "~2.0.2",
44
47
  "@mapbox/point-geometry": "^0.1.0",
45
- "@mapbox/unitbezier": "^0.0.0",
48
+ "@mapbox/unitbezier": "^0.0.1",
49
+ "cheap-ruler": "^4.0.0",
46
50
  "csscolorparser": "~1.0.2",
47
- "json-stringify-pretty-compact": "^2.0.0",
51
+ "json-stringify-pretty-compact": "^4.0.0",
48
52
  "minimist": "^1.2.6",
49
- "rw": "^1.3.3",
50
- "sort-object": "^0.3.2",
51
53
  "quickselect": "^2.0.0",
52
- "tinyqueue": "^2.0.3",
53
- "cheap-ruler": "^3.0.1"
54
- },
55
- "sideEffects": false
54
+ "rw": "^1.3.3",
55
+ "tinyqueue": "^2.0.3"
56
+ }
56
57
  }
@@ -1,13 +1,14 @@
1
- // @noflow
1
+ // @ts-nocheck
2
2
 
3
- import ParsingError from './error/parsing_error.js';
3
+ import ParsingError from './error/parsing_error';
4
4
  import jsonlint from '@mapbox/jsonlint-lines-primitives';
5
5
 
6
6
  export default function readStyle(style) {
7
- if (style instanceof String || typeof style === 'string' || style instanceof Buffer) {
7
+ if (style instanceof String || typeof style === 'string' || ArrayBuffer.isView(style)) {
8
8
  try {
9
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
9
10
  return jsonlint.parse(style.toString());
10
- } catch (e) {
11
+ } catch (e: any) {
11
12
  throw new ParsingError(e);
12
13
  }
13
14
  }
@@ -0,0 +1,5 @@
1
+ import spec from './v8.json';
2
+
3
+ export type StyleReference = Record<any, any>;
4
+
5
+ export default spec as StyleReference;