maplibre-gl 2.2.0-pre.2 → 2.2.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 (169) hide show
  1. package/README.md +73 -8
  2. package/build/generate-debug-index-file.ts +19 -0
  3. package/build/generate-style-code.ts +6 -1
  4. package/build/generate-style-spec.ts +151 -35
  5. package/build/rollup_plugins.ts +4 -1
  6. package/dist/maplibre-gl-csp-worker.js +1 -1
  7. package/dist/maplibre-gl-csp-worker.js.map +1 -1
  8. package/dist/maplibre-gl-csp.js +1 -1
  9. package/dist/maplibre-gl-csp.js.map +1 -1
  10. package/dist/maplibre-gl-dev.js +1317 -4304
  11. package/dist/maplibre-gl.css +1 -1
  12. package/dist/maplibre-gl.d.ts +443 -145
  13. package/dist/maplibre-gl.js +4 -4
  14. package/dist/maplibre-gl.js.map +1 -1
  15. package/package.json +70 -67
  16. package/src/css/maplibre-gl.css +48 -32
  17. package/src/data/bucket/fill_bucket.test.ts +1 -0
  18. package/src/data/bucket/symbol_bucket.test.ts +2 -0
  19. package/src/data/bucket/symbol_bucket.ts +1 -1
  20. package/src/data/evaluation_feature.ts +1 -1
  21. package/src/data/program_configuration.ts +2 -2
  22. package/src/geo/transform.test.ts +34 -1
  23. package/src/geo/transform.ts +25 -15
  24. package/src/gl/vertex_buffer.ts +4 -4
  25. package/src/index.ts +1 -1
  26. package/src/render/draw_debug.ts +1 -1
  27. package/src/render/draw_symbol.test.ts +2 -23
  28. package/src/render/draw_terrain.ts +1 -1
  29. package/src/render/image_atlas.ts +1 -0
  30. package/src/render/image_manager.ts +1 -0
  31. package/src/render/program/debug_program.ts +1 -1
  32. package/src/render/render_to_texture.ts +3 -0
  33. package/src/render/terrain.test.ts +119 -17
  34. package/src/render/terrain.ts +39 -21
  35. package/src/shaders/README.md +2 -2
  36. package/src/shaders/shaders.ts +3 -1
  37. package/src/source/geojson_worker_source.test.ts +2 -2
  38. package/src/source/geojson_wrapper.test.ts +1 -1
  39. package/src/source/image_source.test.ts +8 -8
  40. package/src/source/image_source.ts +1 -1
  41. package/src/source/load_tilejson.ts +6 -1
  42. package/src/source/pixels_to_tile_units.ts +1 -1
  43. package/src/source/raster_tile_source.test.ts +1 -1
  44. package/src/source/source_cache.test.ts +12 -12
  45. package/src/source/source_cache.ts +1 -1
  46. package/src/source/terrain_source_cache.test.ts +17 -2
  47. package/src/source/terrain_source_cache.ts +16 -12
  48. package/src/source/vector_tile_source.test.ts +1 -1
  49. package/src/source/vector_tile_worker_source.test.ts +1 -1
  50. package/src/source/video_source.test.ts +2 -2
  51. package/src/style/light.test.ts +1 -1
  52. package/src/style/load_sprite.ts +1 -1
  53. package/src/style/parse_glyph_pbf.ts +1 -1
  54. package/src/style/style.test.ts +3 -3
  55. package/src/style/style.ts +2 -2
  56. package/src/style/style_layer/background_style_layer_properties.g.ts +1 -0
  57. package/src/style/style_layer/circle_style_layer_properties.g.ts +1 -0
  58. package/src/style/style_layer/fill_extrusion_style_layer_properties.g.ts +1 -0
  59. package/src/style/style_layer/fill_style_layer_properties.g.ts +1 -0
  60. package/src/style/style_layer/heatmap_style_layer_properties.g.ts +1 -0
  61. package/src/style/style_layer/hillshade_style_layer_properties.g.ts +1 -0
  62. package/src/style/style_layer/line_style_layer_properties.g.ts +1 -0
  63. package/src/style/style_layer/raster_style_layer_properties.g.ts +1 -0
  64. package/src/style/style_layer/symbol_style_layer.ts +16 -1
  65. package/src/style/style_layer/symbol_style_layer_properties.g.ts +4 -3
  66. package/src/style-spec/CHANGELOG.md +5 -0
  67. package/src/style-spec/composite.test.ts +2 -0
  68. package/src/style-spec/composite.ts +3 -2
  69. package/src/style-spec/diff.test.ts +3 -3
  70. package/src/style-spec/empty.ts +3 -2
  71. package/src/style-spec/expression/compound_expression.ts +0 -4
  72. package/src/style-spec/expression/definitions/assertion.ts +0 -18
  73. package/src/style-spec/expression/definitions/at.ts +0 -4
  74. package/src/style-spec/expression/definitions/case.ts +0 -6
  75. package/src/style-spec/expression/definitions/coalesce.ts +0 -6
  76. package/src/style-spec/expression/definitions/coercion.ts +13 -18
  77. package/src/style-spec/expression/definitions/collator.ts +0 -10
  78. package/src/style-spec/expression/definitions/comparison.ts +0 -6
  79. package/src/style-spec/expression/definitions/format.ts +0 -19
  80. package/src/style-spec/expression/definitions/image.ts +0 -4
  81. package/src/style-spec/expression/definitions/in.ts +0 -4
  82. package/src/style-spec/expression/definitions/index_of.ts +0 -8
  83. package/src/style-spec/expression/definitions/interpolate.ts +1 -25
  84. package/src/style-spec/expression/definitions/length.ts +0 -6
  85. package/src/style-spec/expression/definitions/let.ts +0 -9
  86. package/src/style-spec/expression/definitions/literal.ts +1 -23
  87. package/src/style-spec/expression/definitions/match.ts +0 -41
  88. package/src/style-spec/expression/definitions/number_format.ts +0 -17
  89. package/src/style-spec/expression/definitions/slice.ts +0 -8
  90. package/src/style-spec/expression/definitions/step.ts +0 -11
  91. package/src/style-spec/expression/definitions/var.ts +0 -4
  92. package/src/style-spec/expression/definitions/within.ts +0 -5
  93. package/src/style-spec/expression/expression.test.ts +1 -1
  94. package/src/style-spec/expression/expression.ts +3 -3
  95. package/src/style-spec/expression/index.ts +8 -2
  96. package/src/style-spec/expression/parsing_context.ts +2 -0
  97. package/src/style-spec/expression/types/formatted.ts +0 -23
  98. package/src/style-spec/expression/types/resolved_image.ts +0 -4
  99. package/src/style-spec/expression/types.ts +6 -1
  100. package/src/style-spec/expression/values.ts +9 -4
  101. package/src/style-spec/feature_filter/convert.ts +65 -65
  102. package/src/style-spec/feature_filter/feature_filter.test.ts +45 -4
  103. package/src/style-spec/feature_filter/index.ts +2 -1
  104. package/src/style-spec/function/index.test.ts +117 -1
  105. package/src/style-spec/function/index.ts +24 -12
  106. package/src/style-spec/migrate/expressions.ts +2 -2
  107. package/src/style-spec/migrate/v8.test.ts +2 -0
  108. package/src/style-spec/migrate/v8.ts +8 -7
  109. package/src/style-spec/migrate/v9.test.ts +6 -4
  110. package/src/style-spec/migrate/v9.ts +3 -2
  111. package/src/style-spec/migrate.test.ts +3 -1
  112. package/src/style-spec/migrate.ts +5 -4
  113. package/src/style-spec/package.json +1 -1
  114. package/src/style-spec/read_style.ts +2 -1
  115. package/src/style-spec/reference/latest.ts +1 -1
  116. package/src/style-spec/reference/v8.json +9 -6
  117. package/src/style-spec/style-spec.test.ts +2 -1
  118. package/src/style-spec/style-spec.ts +8 -0
  119. package/src/style-spec/types.g.ts +152 -36
  120. package/src/style-spec/util/extend.ts +1 -1
  121. package/src/style-spec/util/interpolate.test.ts +5 -0
  122. package/src/style-spec/util/interpolate.ts +12 -0
  123. package/src/style-spec/util/padding.test.ts +27 -0
  124. package/src/style-spec/util/padding.ts +64 -0
  125. package/src/style-spec/util/ref_properties.ts +2 -1
  126. package/src/style-spec/validate/validate.ts +3 -1
  127. package/src/style-spec/validate/validate_expression.ts +2 -1
  128. package/src/style-spec/validate/validate_function.ts +2 -2
  129. package/src/style-spec/validate/validate_glyphs_url.ts +1 -1
  130. package/src/style-spec/validate/validate_object.ts +2 -2
  131. package/src/style-spec/validate/validate_padding.test.ts +82 -0
  132. package/src/style-spec/validate/validate_padding.ts +36 -0
  133. package/src/style-spec/validate_style.min.ts +4 -3
  134. package/src/style-spec/validate_style.ts +4 -3
  135. package/src/symbol/check_max_angle.test.ts +5 -5
  136. package/src/symbol/collision_feature.test.ts +22 -5
  137. package/src/symbol/collision_feature.ts +7 -5
  138. package/src/symbol/collision_index.ts +1 -1
  139. package/src/symbol/get_anchors.test.ts +4 -4
  140. package/src/symbol/{mergelines.test.ts → merge_lines.test.ts} +1 -1
  141. package/src/symbol/{mergelines.ts → merge_lines.ts} +1 -1
  142. package/src/symbol/projection.ts +1 -1
  143. package/src/symbol/quads.test.ts +1 -1
  144. package/src/symbol/shaping.ts +10 -10
  145. package/src/symbol/symbol_layout.ts +5 -4
  146. package/src/symbol/symbol_style_layer.test.ts +1 -1
  147. package/src/symbol/transform_text.ts +3 -3
  148. package/src/ui/camera.test.ts +11 -11
  149. package/src/ui/control/geolocate_control.ts +1 -1
  150. package/src/ui/control/terrain_control.ts +4 -4
  151. package/src/ui/handler/cooperative_gestures.test.ts +167 -0
  152. package/src/ui/handler/drag_pan.test.ts +2 -1
  153. package/src/ui/handler/scroll_zoom.ts +7 -0
  154. package/src/ui/handler/touch_pan.ts +22 -2
  155. package/src/ui/handler/touch_zoom_rotate.ts +18 -1
  156. package/src/ui/handler_manager.ts +2 -2
  157. package/src/ui/map.test.ts +17 -17
  158. package/src/ui/map.ts +76 -8
  159. package/src/ui/map_events.test.ts +33 -32
  160. package/src/ui/popup.test.ts +2 -2
  161. package/src/util/ajax.test.ts +5 -5
  162. package/src/util/ajax.ts +1 -1
  163. package/src/util/classify_rings.test.ts +27 -27
  164. package/src/util/find_pole_of_inaccessibility.ts +1 -1
  165. package/src/util/primitives.ts +4 -4
  166. package/src/util/resolve_tokens.test.ts +1 -1
  167. package/src/util/smart_wrap.ts +1 -1
  168. package/src/util/tile_request_cache.test.ts +5 -5
  169. package/src/util/util.test.ts +5 -5
@@ -19,7 +19,7 @@ describe('VideoSource', () => {
19
19
  // Attribution File:Volcano Lava Sample.webm: U.S. Geological Survey (USGS), Public domain, via Wikimedia Commons
20
20
  const source = createSource({
21
21
  type: 'video',
22
- urls : [ 'cropped.mp4', 'https://upload.wikimedia.org/wikipedia/commons/2/22/Volcano_Lava_Sample.webm' ],
22
+ urls: ['cropped.mp4', 'https://upload.wikimedia.org/wikipedia/commons/2/22/Volcano_Lava_Sample.webm'],
23
23
  coordinates: [
24
24
  [-76.54, 39.18],
25
25
  [-76.52, 39.18],
@@ -50,7 +50,7 @@ describe('VideoSource', () => {
50
50
  const source = createSource({
51
51
  type: 'video',
52
52
  video: el,
53
- urls : [ 'cropped.mp4', 'https://upload.wikimedia.org/wikipedia/commons/2/22/Volcano_Lava_Sample.webm' ],
53
+ urls: ['cropped.mp4', 'https://upload.wikimedia.org/wikipedia/commons/2/22/Volcano_Lava_Sample.webm'],
54
54
  coordinates: [
55
55
  [-76.54, 39.18],
56
56
  [-76.52, 39.18],
@@ -77,7 +77,7 @@ describe('Light#setLight', () => {
77
77
  const light = new Light({});
78
78
 
79
79
  const lightSpy = jest.spyOn(light, '_validate');
80
- light.setLight({color: [999]}, {validate: false});
80
+ light.setLight({color: [999]} as any, {validate: false});
81
81
  light.updateTransitions({transition: false} as any as TransitionParameters);
82
82
  light.recalculate({zoom: 16, zoomHistory: {}, now: 10} as EvaluationParameters);
83
83
 
@@ -8,7 +8,7 @@ import type {RequestManager} from '../util/request_manager';
8
8
  import type {Callback} from '../types/callback';
9
9
  import type {Cancelable} from '../types/cancelable';
10
10
 
11
- export default function(
11
+ export default function loadSprite(
12
12
  baseURL: string,
13
13
  requestManager: RequestManager,
14
14
  pixelRatio: number,
@@ -35,7 +35,7 @@ function readGlyph(tag: number, glyph: any, pbf: Protobuf) {
35
35
  else if (tag === 7) glyph.advance = pbf.readVarint();
36
36
  }
37
37
 
38
- export default function(data: ArrayBuffer | Uint8Array): Array<StyleGlyph> {
38
+ export default function parseGlyphPbf(data: ArrayBuffer | Uint8Array): Array<StyleGlyph> {
39
39
  return new Protobuf(data).readFields(readFontstacks, []);
40
40
  }
41
41
 
@@ -883,7 +883,7 @@ describe('Style#addLayer', () => {
883
883
  'type': 'geojson',
884
884
  'data': {
885
885
  'type': 'Point',
886
- 'coordinates': [ 0, 0]
886
+ 'coordinates': [0, 0]
887
887
  }
888
888
  };
889
889
  const layer = {id: 'inline-source-layer', type: 'circle', source} as any as LayerSpecification;
@@ -1901,7 +1901,7 @@ describe('Style#queryRenderedFeatures', () => {
1901
1901
  errors++;
1902
1902
  }
1903
1903
  });
1904
- style.queryRenderedFeatures([{x: 0, y: 0}], {layers:'string'}, transform);
1904
+ style.queryRenderedFeatures([{x: 0, y: 0}], {layers: 'string'}, transform);
1905
1905
  expect(errors).toBe(1);
1906
1906
  });
1907
1907
 
@@ -1939,7 +1939,7 @@ describe('Style#queryRenderedFeatures', () => {
1939
1939
  jest.spyOn(style, 'fire').mockImplementation((event) => {
1940
1940
  if (event['error'] && event['error'].message.includes('does not exist in the map\'s style and cannot be queried for features.')) errors++;
1941
1941
  });
1942
- const results = style.queryRenderedFeatures([{x: 0, y: 0}], {layers:['merp']}, transform);
1942
+ const results = style.queryRenderedFeatures([{x: 0, y: 0}], {layers: ['merp']}, transform);
1943
1943
  expect(errors).toBe(1);
1944
1944
  expect(results).toHaveLength(0);
1945
1945
  });
@@ -441,7 +441,7 @@ class Style extends Evented {
441
441
  for (const sourceId in sourcesUsedBefore) {
442
442
  const sourceCache = this.sourceCaches[sourceId];
443
443
  if (sourcesUsedBefore[sourceId] !== sourceCache.used) {
444
- sourceCache.fire(new Event('data', {sourceDataType: 'visibility', dataType:'source', sourceId}));
444
+ sourceCache.fire(new Event('data', {sourceDataType: 'visibility', dataType: 'source', sourceId}));
445
445
  }
446
446
  }
447
447
 
@@ -663,7 +663,7 @@ class Style extends Evented {
663
663
  const sourceCache = this.sourceCaches[id];
664
664
  delete this.sourceCaches[id];
665
665
  delete this._updatedSources[id];
666
- sourceCache.fire(new Event('data', {sourceDataType: 'metadata', dataType:'source', sourceId: id}));
666
+ sourceCache.fire(new Event('data', {sourceDataType: 'metadata', dataType: 'source', sourceId: id}));
667
667
  sourceCache.setEventedParent(null);
668
668
  sourceCache.onRemove(this.map);
669
669
  this._changed = true;
@@ -15,6 +15,7 @@ import {
15
15
  } from '../properties';
16
16
 
17
17
  import type Color from '../../style-spec/util/color';
18
+ import type Padding from '../../style-spec/util/padding';
18
19
 
19
20
  import type Formatted from '../../style-spec/expression/types/formatted';
20
21
 
@@ -15,6 +15,7 @@ import {
15
15
  } from '../properties';
16
16
 
17
17
  import type Color from '../../style-spec/util/color';
18
+ import type Padding from '../../style-spec/util/padding';
18
19
 
19
20
  import type Formatted from '../../style-spec/expression/types/formatted';
20
21
 
@@ -15,6 +15,7 @@ import {
15
15
  } from '../properties';
16
16
 
17
17
  import type Color from '../../style-spec/util/color';
18
+ import type Padding from '../../style-spec/util/padding';
18
19
 
19
20
  import type Formatted from '../../style-spec/expression/types/formatted';
20
21
 
@@ -15,6 +15,7 @@ import {
15
15
  } from '../properties';
16
16
 
17
17
  import type Color from '../../style-spec/util/color';
18
+ import type Padding from '../../style-spec/util/padding';
18
19
 
19
20
  import type Formatted from '../../style-spec/expression/types/formatted';
20
21
 
@@ -15,6 +15,7 @@ import {
15
15
  } from '../properties';
16
16
 
17
17
  import type Color from '../../style-spec/util/color';
18
+ import type Padding from '../../style-spec/util/padding';
18
19
 
19
20
  import type Formatted from '../../style-spec/expression/types/formatted';
20
21
 
@@ -15,6 +15,7 @@ import {
15
15
  } from '../properties';
16
16
 
17
17
  import type Color from '../../style-spec/util/color';
18
+ import type Padding from '../../style-spec/util/padding';
18
19
 
19
20
  import type Formatted from '../../style-spec/expression/types/formatted';
20
21
 
@@ -15,6 +15,7 @@ import {
15
15
  } from '../properties';
16
16
 
17
17
  import type Color from '../../style-spec/util/color';
18
+ import type Padding from '../../style-spec/util/padding';
18
19
 
19
20
  import type Formatted from '../../style-spec/expression/types/formatted';
20
21
 
@@ -15,6 +15,7 @@ import {
15
15
  } from '../properties';
16
16
 
17
17
  import type Color from '../../style-spec/util/color';
18
+ import type Padding from '../../style-spec/util/padding';
18
19
 
19
20
  import type Formatted from '../../style-spec/expression/types/formatted';
20
21
 
@@ -1,7 +1,7 @@
1
1
  import StyleLayer from '../style_layer';
2
2
 
3
3
  import assert from 'assert';
4
- import SymbolBucket from '../../data/bucket/symbol_bucket';
4
+ import SymbolBucket, {SymbolFeature} from '../../data/bucket/symbol_bucket';
5
5
  import resolveTokens from '../../util/resolve_tokens';
6
6
  import properties, {SymbolLayoutPropsPossiblyEvaluated, SymbolPaintPropsPossiblyEvaluated} from './symbol_style_layer_properties.g';
7
7
 
@@ -204,4 +204,19 @@ export function getOverlapMode(layout: PossiblyEvaluated<SymbolLayoutProps, Symb
204
204
  return result;
205
205
  }
206
206
 
207
+ export type SymbolPadding = [number, number, number, number];
208
+
209
+ export function getIconPadding(layout: PossiblyEvaluated<SymbolLayoutProps, SymbolLayoutPropsPossiblyEvaluated>, feature: SymbolFeature, canonical: CanonicalTileID, pixelRatio = 1): SymbolPadding {
210
+ // Support text-padding in addition to icon-padding? Unclear how to apply asymmetric text-padding to the radius for collision circles.
211
+ const result = layout.get('icon-padding').evaluate(feature, {}, canonical);
212
+ const values = result && result.values;
213
+
214
+ return [
215
+ values[0] * pixelRatio,
216
+ values[1] * pixelRatio,
217
+ values[2] * pixelRatio,
218
+ values[3] * pixelRatio,
219
+ ];
220
+ }
221
+
207
222
  export default SymbolStyleLayer;
@@ -15,6 +15,7 @@ import {
15
15
  } from '../properties';
16
16
 
17
17
  import type Color from '../../style-spec/util/color';
18
+ import type Padding from '../../style-spec/util/padding';
18
19
 
19
20
  import type Formatted from '../../style-spec/expression/types/formatted';
20
21
 
@@ -41,7 +42,7 @@ export type SymbolLayoutProps = {
41
42
  "icon-text-fit-padding": DataConstantProperty<[number, number, number, number]>,
42
43
  "icon-image": DataDrivenProperty<ResolvedImage>,
43
44
  "icon-rotate": DataDrivenProperty<number>,
44
- "icon-padding": DataConstantProperty<number>,
45
+ "icon-padding": DataDrivenProperty<Padding>,
45
46
  "icon-keep-upright": DataConstantProperty<boolean>,
46
47
  "icon-offset": DataDrivenProperty<[number, number]>,
47
48
  "icon-anchor": DataDrivenProperty<"center" | "left" | "right" | "top" | "bottom" | "top-left" | "top-right" | "bottom-left" | "bottom-right">,
@@ -87,7 +88,7 @@ export type SymbolLayoutPropsPossiblyEvaluated = {
87
88
  "icon-text-fit-padding": [number, number, number, number],
88
89
  "icon-image": PossiblyEvaluatedPropertyValue<ResolvedImage>,
89
90
  "icon-rotate": PossiblyEvaluatedPropertyValue<number>,
90
- "icon-padding": number,
91
+ "icon-padding": PossiblyEvaluatedPropertyValue<Padding>,
91
92
  "icon-keep-upright": boolean,
92
93
  "icon-offset": PossiblyEvaluatedPropertyValue<[number, number]>,
93
94
  "icon-anchor": PossiblyEvaluatedPropertyValue<"center" | "left" | "right" | "top" | "bottom" | "top-left" | "top-right" | "bottom-left" | "bottom-right">,
@@ -133,7 +134,7 @@ const layout: Properties<SymbolLayoutProps> = new Properties({
133
134
  "icon-text-fit-padding": new DataConstantProperty(styleSpec["layout_symbol"]["icon-text-fit-padding"] as any as StylePropertySpecification),
134
135
  "icon-image": new DataDrivenProperty(styleSpec["layout_symbol"]["icon-image"] as any as StylePropertySpecification),
135
136
  "icon-rotate": new DataDrivenProperty(styleSpec["layout_symbol"]["icon-rotate"] as any as StylePropertySpecification),
136
- "icon-padding": new DataConstantProperty(styleSpec["layout_symbol"]["icon-padding"] as any as StylePropertySpecification),
137
+ "icon-padding": new DataDrivenProperty(styleSpec["layout_symbol"]["icon-padding"] as any as StylePropertySpecification),
137
138
  "icon-keep-upright": new DataConstantProperty(styleSpec["layout_symbol"]["icon-keep-upright"] as any as StylePropertySpecification),
138
139
  "icon-offset": new DataDrivenProperty(styleSpec["layout_symbol"]["icon-offset"] as any as StylePropertySpecification),
139
140
  "icon-anchor": new DataDrivenProperty(styleSpec["layout_symbol"]["icon-anchor"] as any as StylePropertySpecification),
@@ -1,3 +1,8 @@
1
+ ## 16.1.0
2
+
3
+ ### ✨ Features and improvements
4
+ * Update `icon-padding` symbol layout property to support asymmetric padding [#1289](https://github.com/maplibre/maplibre-gl-js/pull/1289)
5
+
1
6
  ## 16.0.0
2
7
 
3
8
  ### Breaking changes
@@ -1,3 +1,5 @@
1
+ // @ts-nocheck
2
+
1
3
  import composite from './composite';
2
4
 
3
5
  describe('composite', () => {
@@ -1,5 +1,6 @@
1
+ import type {StyleSpecification} from './types.g';
1
2
 
2
- export default function (style) {
3
+ export default function composite(style: StyleSpecification): StyleSpecification {
3
4
  const styleIDs = [];
4
5
  const sourceIDs = [];
5
6
  const compositedSourceLayers = [];
@@ -32,7 +33,7 @@ export default function (style) {
32
33
  'url': `mapbox://${compositeID}`
33
34
  };
34
35
 
35
- style.layers.forEach((layer) => {
36
+ style.layers.forEach((layer: any) => {
36
37
  if (styleIDs.indexOf(layer.source) >= 0) {
37
38
  layer.source = compositeID;
38
39
 
@@ -88,7 +88,7 @@ test('diff', () => {
88
88
  }, {
89
89
  layers: [{id: 'a', filter: ['==', 'foo', 'baz']}]
90
90
  })).toEqual([
91
- {command: 'setFilter', args: ['a', [ '==', 'foo', 'baz' ] ]}
91
+ {command: 'setFilter', args: ['a', ['==', 'foo', 'baz']]}
92
92
  ]);
93
93
 
94
94
  expect(diffStyles({
@@ -329,9 +329,9 @@ test('diff', () => {
329
329
  ]);
330
330
 
331
331
  expect(diffStyles({
332
- layers: [ {id: 'a', source: 'source-one'} ]
332
+ layers: [{id: 'a', source: 'source-one'}]
333
333
  }, {
334
- layers: [ {id: 'a', source: 'source-two'} ]
334
+ layers: [{id: 'a', source: 'source-two'}]
335
335
  })).toEqual([
336
336
  {command: 'removeLayer', args: ['a']},
337
337
  {command: 'addLayer', args: [{id: 'a', source: 'source-two'}, undefined]}
@@ -1,6 +1,7 @@
1
1
  import latest from './reference/latest';
2
+ import {StyleSpecification} from './types.g';
2
3
 
3
- export default function emptyStyle() {
4
+ export default function emptyStyle(): StyleSpecification {
4
5
  const style = {};
5
6
 
6
7
  const version = latest['$version'];
@@ -25,5 +26,5 @@ export default function emptyStyle() {
25
26
  }
26
27
  }
27
28
 
28
- return style;
29
+ return style as StyleSpecification;
29
30
  }
@@ -46,10 +46,6 @@ class CompoundExpression implements Expression {
46
46
  return false;
47
47
  }
48
48
 
49
- serialize(): Array<unknown> {
50
- return [this.name as unknown].concat(this.args.map(arg => arg.serialize()));
51
- }
52
-
53
49
  static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Expression {
54
50
  const op: string = (args[0] as any);
55
51
  const definition = CompoundExpression.definitions[op];
@@ -105,24 +105,6 @@ class Assertion implements Expression {
105
105
  outputDefined(): boolean {
106
106
  return this.args.every(arg => arg.outputDefined());
107
107
  }
108
-
109
- serialize(): Array<unknown> {
110
- const type = this.type;
111
- const serialized = [type.kind as unknown];
112
- if (type.kind === 'array') {
113
- const itemType = type.itemType;
114
- if (itemType.kind === 'string' ||
115
- itemType.kind === 'number' ||
116
- itemType.kind === 'boolean') {
117
- serialized.push(itemType.kind);
118
- const N = type.N;
119
- if (typeof N === 'number' || this.args.length > 1) {
120
- serialized.push(N);
121
- }
122
- }
123
- }
124
- return serialized.concat(this.args.map(arg => arg.serialize()));
125
- }
126
108
  }
127
109
 
128
110
  export default Assertion;
@@ -59,10 +59,6 @@ class At implements Expression {
59
59
  outputDefined() {
60
60
  return false;
61
61
  }
62
-
63
- serialize() {
64
- return ['at', this.index.serialize(), this.input.serialize()];
65
- }
66
62
  }
67
63
 
68
64
  export default At;
@@ -72,12 +72,6 @@ class Case implements Expression {
72
72
  outputDefined(): boolean {
73
73
  return this.branches.every(([_, out]) => out.outputDefined()) && this.otherwise.outputDefined();
74
74
  }
75
-
76
- serialize() {
77
- const serialized = ['case' as unknown];
78
- this.eachChild(child => { serialized.push(child.serialize()); });
79
- return serialized;
80
- }
81
75
  }
82
76
 
83
77
  export default Case;
@@ -80,12 +80,6 @@ class Coalesce implements Expression {
80
80
  outputDefined(): boolean {
81
81
  return this.args.every(arg => arg.outputDefined());
82
82
  }
83
-
84
- serialize() {
85
- const serialized = ['coalesce' as unknown];
86
- this.eachChild(child => { serialized.push(child.serialize()); });
87
- return serialized;
88
- }
89
83
  }
90
84
 
91
85
  export default Coalesce;
@@ -1,11 +1,9 @@
1
1
  import assert from 'assert';
2
2
 
3
3
  import {BooleanType, ColorType, NumberType, StringType, ValueType} from '../types';
4
- import {Color, toString as valueToString, validateRGBA} from '../values';
4
+ import {Color, Padding, toString as valueToString, validateRGBA} from '../values';
5
5
  import RuntimeError from '../runtime_error';
6
6
  import Formatted from '../types/formatted';
7
- import FormatExpression from '../definitions/format';
8
- import ImageExpression from '../definitions/image';
9
7
  import ResolvedImage from '../types/resolved_image';
10
8
 
11
9
  import type {Expression} from '../expression';
@@ -83,7 +81,18 @@ class Coercion implements Expression {
83
81
  }
84
82
  }
85
83
  }
86
- throw new RuntimeError(error || `Could not parse color from value '${typeof input === 'string' ? input : String(JSON.stringify(input))}'`);
84
+ throw new RuntimeError(error || `Could not parse color from value '${typeof input === 'string' ? input : JSON.stringify(input)}'`);
85
+ } else if (this.type.kind === 'padding') {
86
+ let input;
87
+ for (const arg of this.args) {
88
+ input = arg.evaluate(ctx);
89
+
90
+ const pad = Padding.parse(input);
91
+ if (pad) {
92
+ return pad;
93
+ }
94
+ }
95
+ throw new RuntimeError(`Could not parse padding from value '${typeof input === 'string' ? input : JSON.stringify(input)}'`);
87
96
  } else if (this.type.kind === 'number') {
88
97
  let value = null;
89
98
  for (const arg of this.args) {
@@ -112,20 +121,6 @@ class Coercion implements Expression {
112
121
  outputDefined(): boolean {
113
122
  return this.args.every(arg => arg.outputDefined());
114
123
  }
115
-
116
- serialize() {
117
- if (this.type.kind === 'formatted') {
118
- return new FormatExpression([{content: this.args[0], scale: null, font: null, textColor: null}]).serialize();
119
- }
120
-
121
- if (this.type.kind === 'resolvedImage') {
122
- return new ImageExpression(this.args[0]).serialize();
123
- }
124
-
125
- const serialized = [`to-${this.type.kind}` as unknown];
126
- this.eachChild(child => { serialized.push(child.serialize()); });
127
- return serialized;
128
- }
129
124
  }
130
125
 
131
126
  export default Coercion;
@@ -63,14 +63,4 @@ export default class CollatorExpression implements Expression {
63
63
  // possible outputs anyway, so we can get away with leaving this false for now.
64
64
  return false;
65
65
  }
66
-
67
- serialize() {
68
- const options = {};
69
- options['case-sensitive'] = this.caseSensitive.serialize();
70
- options['diacritic-sensitive'] = this.diacriticSensitive.serialize();
71
- if (this.locale) {
72
- options['locale'] = this.locale.serialize();
73
- }
74
- return ['collator', options];
75
- }
76
66
  }
@@ -165,12 +165,6 @@ function makeComparison(op: ComparisonOperator, compareBasic, compareWithCollato
165
165
  outputDefined(): boolean {
166
166
  return true;
167
167
  }
168
-
169
- serialize() {
170
- const serialized = [op as unknown];
171
- this.eachChild(child => { serialized.push(child.serialize()); });
172
- return serialized;
173
- }
174
168
  };
175
169
  }
176
170
 
@@ -128,23 +128,4 @@ export default class FormatExpression implements Expression {
128
128
  // Usually, this.text will be undefined anyway
129
129
  return false;
130
130
  }
131
-
132
- serialize() {
133
- const serialized = ['format'] as (string | {})[];
134
- for (const section of this.sections) {
135
- serialized.push(section.content.serialize());
136
- const options = {};
137
- if (section.scale) {
138
- options['font-scale'] = section.scale.serialize();
139
- }
140
- if (section.font) {
141
- options['text-font'] = section.font.serialize();
142
- }
143
- if (section.textColor) {
144
- options['text-color'] = section.textColor.serialize();
145
- }
146
- serialized.push(options);
147
- }
148
- return serialized;
149
- }
150
131
  }
@@ -43,8 +43,4 @@ export default class ImageExpression implements Expression {
43
43
  // The output of image is determined by the list of available images in the evaluation context
44
44
  return false;
45
45
  }
46
-
47
- serialize() {
48
- return ['image', this.input.serialize()];
49
- }
50
46
  }
@@ -70,10 +70,6 @@ class In implements Expression {
70
70
  outputDefined() {
71
71
  return true;
72
72
  }
73
-
74
- serialize() {
75
- return ['in', this.needle.serialize(), this.haystack.serialize()];
76
- }
77
73
  }
78
74
 
79
75
  export default In;
@@ -83,14 +83,6 @@ class IndexOf implements Expression {
83
83
  outputDefined() {
84
84
  return false;
85
85
  }
86
-
87
- serialize() {
88
- if (this.fromIndex != null && this.fromIndex !== undefined) {
89
- const fromIndex = this.fromIndex.serialize();
90
- return ['index-of', this.needle.serialize(), this.haystack.serialize(), fromIndex];
91
- }
92
- return ['index-of', this.needle.serialize(), this.haystack.serialize()];
93
- }
94
86
  }
95
87
 
96
88
  export default IndexOf;
@@ -135,6 +135,7 @@ class Interpolate implements Expression {
135
135
 
136
136
  if (outputType.kind !== 'number' &&
137
137
  outputType.kind !== 'color' &&
138
+ outputType.kind !== 'padding' &&
138
139
  !(
139
140
  outputType.kind === 'array' &&
140
141
  outputType.itemType.kind === 'number' &&
@@ -192,31 +193,6 @@ class Interpolate implements Expression {
192
193
  outputDefined(): boolean {
193
194
  return this.outputs.every(out => out.outputDefined());
194
195
  }
195
-
196
- serialize(): Array<unknown> {
197
- let interpolation;
198
- if (this.interpolation.name === 'linear') {
199
- interpolation = ['linear'];
200
- } else if (this.interpolation.name === 'exponential') {
201
- if (this.interpolation.base === 1) {
202
- interpolation = ['linear'];
203
- } else {
204
- interpolation = ['exponential', this.interpolation.base];
205
- }
206
- } else {
207
- interpolation = ['cubic-bezier' as unknown].concat(this.interpolation.controlPoints);
208
- }
209
-
210
- const serialized = [this.operator, interpolation, this.input.serialize()];
211
-
212
- for (let i = 0; i < this.labels.length; i++) {
213
- serialized.push(
214
- this.labels[i],
215
- this.outputs[i].serialize()
216
- );
217
- }
218
- return serialized;
219
- }
220
196
  }
221
197
 
222
198
  /**
@@ -48,12 +48,6 @@ class Length implements Expression {
48
48
  outputDefined() {
49
49
  return false;
50
50
  }
51
-
52
- serialize() {
53
- const serialized = ['length' as unknown];
54
- this.eachChild(child => { serialized.push(child.serialize()); });
55
- return serialized;
56
- }
57
51
  }
58
52
 
59
53
  export default Length;
@@ -56,15 +56,6 @@ class Let implements Expression {
56
56
  outputDefined() {
57
57
  return this.result.outputDefined();
58
58
  }
59
-
60
- serialize() {
61
- const serialized = ['let' as unknown];
62
- for (const [name, expr] of this.bindings) {
63
- serialized.push(name, expr.serialize());
64
- }
65
- serialized.push(this.result.serialize());
66
- return serialized;
67
- }
68
59
  }
69
60
 
70
61
  export default Let;
@@ -1,6 +1,4 @@
1
- import assert from 'assert';
2
- import {isValue, typeOf, Color} from '../values';
3
- import Formatted from '../types/formatted';
1
+ import {isValue, typeOf} from '../values';
4
2
 
5
3
  import type {Type} from '../types';
6
4
  import type {Value} from '../values';
@@ -50,26 +48,6 @@ class Literal implements Expression {
50
48
  outputDefined() {
51
49
  return true;
52
50
  }
53
-
54
- serialize(): Array<unknown> {
55
- if (this.type.kind === 'array' || this.type.kind === 'object') {
56
- return ['literal', this.value];
57
- } else if (this.value instanceof Color) {
58
- // Constant-folding can generate Literal expressions that you
59
- // couldn't actually generate with a "literal" expression,
60
- // so we have to implement an equivalent serialization here
61
- return ['rgba' as unknown].concat(this.value.toArray());
62
- } else if (this.value instanceof Formatted) {
63
- // Same as Color
64
- return this.value.serialize();
65
- } else {
66
- assert(this.value === null ||
67
- typeof this.value === 'string' ||
68
- typeof this.value === 'number' ||
69
- typeof this.value === 'boolean');
70
- return this.value as any;
71
- }
72
- }
73
51
  }
74
52
 
75
53
  export default Literal;