@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,13 +1,8 @@
1
1
  #!/usr/bin/env node
2
-
3
- // @flow
4
2
  /* eslint-disable no-process-exit */
5
3
 
6
4
  import fs from 'fs';
7
5
  import minimist from 'minimist';
8
-
9
- /* eslint import/no-unresolved: [error, { ignore: ['^@mapbox/mapbox-gl-style-spec$'] }] */
10
- /* $FlowFixMe[cannot-resolve-module] */
11
6
  import {format, composite} from '@mapbox/mapbox-gl-style-spec';
12
7
 
13
8
  const argv = minimist(process.argv.slice(2));
@@ -1,13 +1,8 @@
1
1
  #!/usr/bin/env node
2
-
3
- // @flow
4
2
  /* eslint-disable no-process-exit */
5
3
 
6
4
  import fs from 'fs';
7
5
  import minimist from 'minimist';
8
-
9
- /* eslint import/no-unresolved: [error, { ignore: ['^@mapbox/mapbox-gl-style-spec$'] }] */
10
- /* $FlowFixMe[cannot-resolve-module] */
11
6
  import {format} from '@mapbox/mapbox-gl-style-spec';
12
7
 
13
8
  const argv = minimist(process.argv.slice(2));
@@ -1,13 +1,8 @@
1
1
  #!/usr/bin/env node
2
-
3
- // @flow
4
2
  /* eslint-disable no-process-exit */
5
3
 
6
4
  import fs from 'fs';
7
5
  import minimist from 'minimist';
8
-
9
- /* eslint import/no-unresolved: [error, { ignore: ['^@mapbox/mapbox-gl-style-spec$'] }] */
10
- /* $FlowFixMe[cannot-resolve-module] */
11
6
  import {format, migrate} from '@mapbox/mapbox-gl-style-spec';
12
7
 
13
8
  const argv = minimist(process.argv.slice(2));
@@ -1,13 +1,8 @@
1
1
  #!/usr/bin/env node
2
-
3
- // @flow
4
2
  /* eslint-disable no-process-exit */
5
3
 
6
4
  import rw from 'rw';
7
5
  import minimist from 'minimist';
8
-
9
- /* eslint import/no-unresolved: [error, { ignore: ['^@mapbox/mapbox-gl-style-spec$'] }] */
10
- /* $FlowFixMe[cannot-resolve-module] */
11
6
  import {validate, validateMapboxApiSupported} from '@mapbox/mapbox-gl-style-spec';
12
7
 
13
8
  const argv = minimist(process.argv.slice(2), {
@@ -1,4 +1,4 @@
1
- // @noflow
1
+ // @ts-nocheck
2
2
 
3
3
  export default function (style) {
4
4
  const styleIDs = [];
@@ -1,5 +1,3 @@
1
- // @flow
2
-
3
1
  /**
4
2
  * The maximum value of a coordinate in the internal tile coordinate system. Coordinates of
5
3
  * all source features normalized to this extent upon load.
@@ -1,11 +1,9 @@
1
- // @flow
1
+ import refProperties from './util/ref_properties';
2
2
 
3
- import refProperties from './util/ref_properties.js';
4
-
5
- import type {LayerSpecification} from './types.js';
3
+ import type {LayerSpecification} from './types';
6
4
 
7
5
  function deref(layer: LayerSpecification, parent: LayerSpecification): LayerSpecification {
8
- const result = {};
6
+ const result: Record<string, any> = {};
9
7
 
10
8
  for (const k in layer) {
11
9
  if (k !== 'ref') {
@@ -15,11 +13,11 @@ function deref(layer: LayerSpecification, parent: LayerSpecification): LayerSpec
15
13
 
16
14
  refProperties.forEach((k) => {
17
15
  if (k in parent) {
18
- result[k] = (parent: any)[k];
16
+ result[k] = (parent as any)[k];
19
17
  }
20
18
  });
21
19
 
22
- return ((result: any): LayerSpecification);
20
+ return result as LayerSpecification;
23
21
  }
24
22
 
25
23
  /**
@@ -38,14 +36,14 @@ function deref(layer: LayerSpecification, parent: LayerSpecification): LayerSpec
38
36
  export default function derefLayers(layers: Array<LayerSpecification>): Array<LayerSpecification> {
39
37
  layers = layers.slice();
40
38
 
41
- const map: Object = Object.create(null);
39
+ const map: any = Object.create(null);
42
40
  for (let i = 0; i < layers.length; i++) {
43
41
  map[layers[i].id] = layers[i];
44
42
  }
45
43
 
46
44
  for (let i = 0; i < layers.length; i++) {
47
45
  if ('ref' in layers[i]) {
48
- layers[i] = deref(layers[i], map[(layers[i]: any).ref]);
46
+ layers[i] = deref(layers[i], map[(layers[i] as any).ref]);
49
47
  }
50
48
  }
51
49
 
@@ -1,17 +1,19 @@
1
- // @flow
1
+ import isEqual from './util/deep_equal';
2
2
 
3
- import isEqual from './util/deep_equal.js';
3
+ import type {StyleSpecification, ImportSpecification, SourceSpecification, LayerSpecification} from './types';
4
4
 
5
- import type {StyleSpecification, ImportSpecification, SourceSpecification, LayerSpecification} from './types.js';
6
-
7
- type Sources = { [string]: SourceSpecification };
5
+ type Sources = {
6
+ [key: string]: SourceSpecification;
7
+ };
8
8
 
9
9
  type Command = {
10
10
  command: string;
11
11
  args: Array<any>;
12
12
  };
13
13
 
14
- export const operations: {[_: string]: string} = {
14
+ export const operations: {
15
+ [_: string]: string;
16
+ } = {
15
17
 
16
18
  /*
17
19
  * { command: 'setStyle', args: [stylesheet] }
@@ -158,12 +160,16 @@ function addSource(sourceId: string, after: Sources, commands: Array<Command>) {
158
160
  commands.push({command: operations.addSource, args: [sourceId, after[sourceId]]});
159
161
  }
160
162
 
161
- function removeSource(sourceId: string, commands: Array<Command>, sourcesRemoved: {[string]: true}) {
163
+ function removeSource(sourceId: string, commands: Array<Command>, sourcesRemoved: {
164
+ [key: string]: true;
165
+ }) {
162
166
  commands.push({command: operations.removeSource, args: [sourceId]});
163
167
  sourcesRemoved[sourceId] = true;
164
168
  }
165
169
 
166
- function updateSource(sourceId: string, after: Sources, commands: Array<Command>, sourcesRemoved: {[string]: true}) {
170
+ function updateSource(sourceId: string, after: Sources, commands: Array<Command>, sourcesRemoved: {
171
+ [key: string]: true;
172
+ }) {
167
173
  removeSource(sourceId, commands, sourcesRemoved);
168
174
  addSource(sourceId, after, commands);
169
175
  }
@@ -185,7 +191,9 @@ function canUpdateGeoJSON(before: Sources, after: Sources, sourceId: string) {
185
191
  return true;
186
192
  }
187
193
 
188
- function diffSources(before: Sources, after: Sources, commands: Array<Command>, sourcesRemoved: {[string]: true}) {
194
+ function diffSources(before: Sources, after: Sources, commands: Array<Command>, sourcesRemoved: {
195
+ [key: string]: true;
196
+ }) {
189
197
  before = before || {};
190
198
  after = after || {};
191
199
 
@@ -216,7 +224,7 @@ function diffSources(before: Sources, after: Sources, commands: Array<Command>,
216
224
  }
217
225
  }
218
226
 
219
- function diffLayerPropertyChanges(before: any, after: any, commands: Array<Command>, layerId: string, klass: ?string, command: string) {
227
+ function diffLayerPropertyChanges(before: any, after: any, commands: Array<Command>, layerId: string, klass: string | null | undefined, command: string) {
220
228
  before = before || {};
221
229
  after = after || {};
222
230
 
@@ -236,11 +244,22 @@ function diffLayerPropertyChanges(before: any, after: any, commands: Array<Comma
236
244
  }
237
245
  }
238
246
 
239
- function pluckId<T: {id: string}>(item: T): string {
247
+ function pluckId<T extends {
248
+ id: string;
249
+ }>(item: T): string {
240
250
  return item.id;
241
251
  }
242
252
 
243
- function indexById<T: {id: string}>(group: {[string]: T}, item: T): {[id: string]: T} {
253
+ function indexById<T extends {
254
+ id: string;
255
+ }>(
256
+ group: {
257
+ [key: string]: T;
258
+ },
259
+ item: T,
260
+ ): {
261
+ [id: string]: T;
262
+ } {
244
263
  group[item.id] = item;
245
264
  return group;
246
265
  }
@@ -254,14 +273,14 @@ function diffLayers(before: Array<LayerSpecification>, after: Array<LayerSpecifi
254
273
  const afterOrder = after.map(pluckId);
255
274
 
256
275
  // index of layer by id
257
- const beforeIndex = before.reduce(indexById, {});
258
- const afterIndex = after.reduce(indexById, {});
276
+ const beforeIndex = before.reduce<Record<string, any>>(indexById, {});
277
+ const afterIndex = after.reduce<Record<string, any>>(indexById, {});
259
278
 
260
279
  // track order of layers as if they have been mutated
261
280
  const tracker = beforeOrder.slice();
262
281
 
263
282
  // layers that have been added do not need to be diffed
264
- const clean: Object = Object.create(null);
283
+ const clean: any = Object.create(null);
265
284
 
266
285
  let i, d, layerId, beforeLayer: LayerSpecification, afterLayer: LayerSpecification, insertBeforeLayerId, prop;
267
286
 
@@ -311,7 +330,6 @@ function diffLayers(before: Array<LayerSpecification>, after: Array<LayerSpecifi
311
330
 
312
331
  // If source, source-layer, or type have changes, then remove the layer
313
332
  // and add it back 'from scratch'.
314
- // $FlowFixMe[prop-missing] - there is no `source-layer` in background and sky layers
315
333
  if (!isEqual(beforeLayer.source, afterLayer.source) || !isEqual(beforeLayer['source-layer'], afterLayer['source-layer']) || !isEqual(beforeLayer.type, afterLayer.type)) {
316
334
  commands.push({command: operations.removeLayer, args: [layerId]});
317
335
  // we add the layer back at the same position it was already in, so
@@ -358,7 +376,7 @@ function diffLayers(before: Array<LayerSpecification>, after: Array<LayerSpecifi
358
376
  }
359
377
  }
360
378
 
361
- export function diffImports(before: Array<ImportSpecification> = [], after: Array<ImportSpecification> = [], commands: Array<Command>) {
379
+ export function diffImports(before: Array<ImportSpecification> | null | undefined = [], after: Array<ImportSpecification> | null | undefined = [], commands: Array<Command>) {
362
380
  before = before || [];
363
381
  after = after || [];
364
382
 
@@ -367,8 +385,8 @@ export function diffImports(before: Array<ImportSpecification> = [], after: Arra
367
385
  const afterOrder = after.map(pluckId);
368
386
 
369
387
  // index imports by id
370
- const beforeIndex = before.reduce(indexById, {});
371
- const afterIndex = after.reduce(indexById, {});
388
+ const beforeIndex = before.reduce<Record<string, any>>(indexById, {});
389
+ const afterIndex = after.reduce<Record<string, any>>(indexById, {});
372
390
 
373
391
  // track order of imports as if they have been mutated
374
392
  const tracker = beforeOrder.slice();
@@ -486,11 +504,16 @@ export default function diffStyles(before: StyleSpecification, after: StyleSpeci
486
504
  if (!isEqual(before.camera, after.camera)) {
487
505
  commands.push({command: operations.setCamera, args: [after.camera]});
488
506
  }
507
+ if (!isEqual(before["color-theme"], after["color-theme"])) {
508
+ // Update this to setColorTheme after
509
+ // https://mapbox.atlassian.net/browse/GLJS-842 is implemented
510
+ return [{command: operations.setStyle, args: [after]}];
511
+ }
489
512
 
490
513
  // Handle changes to `sources`
491
514
  // If a source is to be removed, we also--before the removeSource
492
515
  // command--need to remove all the style layers that depend on it.
493
- const sourcesRemoved = {};
516
+ const sourcesRemoved: Record<string, any> = {};
494
517
 
495
518
  // First collect the {add,remove}Source commands
496
519
  const removeOrAddSourceCommands = [];
@@ -531,7 +554,7 @@ export default function diffStyles(before: StyleSpecification, after: StyleSpeci
531
554
 
532
555
  // Handle changes to `layers`
533
556
  diffLayers(beforeLayers, after.layers, commands);
534
- } catch (e) {
557
+ } catch (e: any) {
535
558
  // fall back to setStyle
536
559
  console.warn('Unable to compute style diff:', e);
537
560
  commands = [{command: operations.setStyle, args: [after]}];