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
@@ -1,6 +1,7 @@
1
1
  import {createFunction} from './index';
2
2
  import Color from '../util/color';
3
3
  import Formatted from '../expression/types/formatted';
4
+ import Padding from '../util/padding';
4
5
 
5
6
  describe('binary search', () => {
6
7
  test('will eventually terminate.', () => {
@@ -235,6 +236,19 @@ describe('exponential function', () => {
235
236
  expect(params).toEqual(paramsCopy);
236
237
  });
237
238
 
239
+ test('padding', () => {
240
+ const f = createFunction({
241
+ type: 'exponential',
242
+ stops: [[1, 2], [11, [2, 5, 2, 7]]]
243
+ }, {
244
+ type: 'padding'
245
+ }).evaluate;
246
+
247
+ expect(f({zoom: 0}, undefined)).toEqual(new Padding([2, 2, 2, 2]));
248
+ expect(f({zoom: 5}, undefined)).toEqual(new Padding([2, 3.2, 2, 4]));
249
+ expect(f({zoom: 11}, undefined)).toEqual(new Padding([2, 5, 2, 7]));
250
+ });
251
+
238
252
  test('property present', () => {
239
253
  const f = createFunction({
240
254
  property: 'foo',
@@ -532,11 +546,24 @@ describe('interval function', () => {
532
546
  }).evaluate;
533
547
 
534
548
  expect(f({zoom: 0}, undefined)).toEqual(new Color(1, 0, 0, 1));
535
- expect(f({zoom: 0}, undefined)).toEqual(new Color(1, 0, 0, 1));
549
+ expect(f({zoom: 10}, undefined)).toEqual(new Color(1, 0, 0, 1));
536
550
  expect(f({zoom: 11}, undefined)).toEqual(new Color(0, 0, 1, 1));
537
551
 
538
552
  });
539
553
 
554
+ test('padding', () => {
555
+ const f = createFunction({
556
+ type: 'interval',
557
+ stops: [[1, 2], [11, 4]]
558
+ }, {
559
+ type: 'padding'
560
+ }).evaluate;
561
+
562
+ expect(f({zoom: 0}, undefined)).toEqual(new Padding([2, 2, 2, 2]));
563
+ expect(f({zoom: 10}, undefined)).toEqual(new Padding([2, 2, 2, 2]));
564
+ expect(f({zoom: 11}, undefined)).toEqual(new Padding([4, 4, 4, 4]));
565
+ });
566
+
540
567
  test('property present', () => {
541
568
  const f = createFunction({
542
569
  property: 'foo',
@@ -746,6 +773,47 @@ describe('categorical function', () => {
746
773
 
747
774
  });
748
775
 
776
+ test('padding', () => {
777
+ const f = createFunction({
778
+ property: 'foo',
779
+ type: 'categorical',
780
+ stops: [[0, 2], [1, 4]]
781
+ }, {
782
+ type: 'padding'
783
+ }).evaluate;
784
+
785
+ expect(f({zoom: 0}, {properties: {foo: 0}})).toEqual(new Padding([2, 2, 2, 2]));
786
+ expect(f({zoom: 1}, {properties: {foo: 1}})).toEqual(new Padding([4, 4, 4, 4]));
787
+ });
788
+
789
+ test('padding function default', () => {
790
+ const f = createFunction({
791
+ property: 'foo',
792
+ type: 'categorical',
793
+ stops: [[0, 2], [1, 4]],
794
+ default: 6
795
+ }, {
796
+ type: 'padding'
797
+ }).evaluate;
798
+
799
+ expect(f({zoom: 0}, {properties: {}})).toEqual(new Padding([6, 6, 6, 6]));
800
+ expect(f({zoom: 0}, {properties: {foo: 3}})).toEqual(new Padding([6, 6, 6, 6]));
801
+ });
802
+
803
+ test('padding spec default', () => {
804
+ const f = createFunction({
805
+ property: 'foo',
806
+ type: 'categorical',
807
+ stops: [[0, 2], [1, 4]]
808
+ }, {
809
+ type: 'padding',
810
+ default: 6
811
+ }).evaluate;
812
+
813
+ expect(f({zoom: 0}, {properties: {}})).toEqual(new Padding([6, 6, 6, 6]));
814
+ expect(f({zoom: 0}, {properties: {foo: 3}})).toEqual(new Padding([6, 6, 6, 6]));
815
+ });
816
+
749
817
  test('boolean', () => {
750
818
  const f = createFunction({
751
819
  property: 'foo',
@@ -853,6 +921,54 @@ describe('identity function', () => {
853
921
 
854
922
  });
855
923
 
924
+ test('padding', () => {
925
+ const f = createFunction({
926
+ property: 'foo',
927
+ type: 'identity'
928
+ }, {
929
+ type: 'padding'
930
+ }).evaluate;
931
+
932
+ expect(f({zoom: 0}, {properties: {foo: 3}})).toEqual(new Padding([3, 3, 3, 3]));
933
+ expect(f({zoom: 1}, {properties: {foo: [3, 4]}})).toEqual(new Padding([3, 4, 3, 4]));
934
+ });
935
+
936
+ test('padding function default', () => {
937
+ const f = createFunction({
938
+ property: 'foo',
939
+ type: 'identity',
940
+ default: [1, 2, 3, 4]
941
+ }, {
942
+ type: 'padding'
943
+ }).evaluate;
944
+
945
+ expect(f({zoom: 0}, {properties: {}})).toEqual(new Padding([1, 2, 3, 4]));
946
+ });
947
+
948
+ test('padding spec default', () => {
949
+ const f = createFunction({
950
+ property: 'foo',
951
+ type: 'identity'
952
+ }, {
953
+ type: 'padding',
954
+ default: [1, 2, 3, 4]
955
+ }).evaluate;
956
+
957
+ expect(f({zoom: 0}, {properties: {}})).toEqual(new Padding([1, 2, 3, 4]));
958
+ });
959
+
960
+ test('padding invalid', () => {
961
+ const f = createFunction({
962
+ property: 'foo',
963
+ type: 'identity'
964
+ }, {
965
+ type: 'padding',
966
+ default: [1, 2, 3, 4]
967
+ }).evaluate;
968
+
969
+ expect(f({zoom: 0}, {properties: {foo: 'invalid'}})).toEqual(new Padding([1, 2, 3, 4]));
970
+ });
971
+
856
972
  test('property type mismatch, function default', () => {
857
973
  const f = createFunction({
858
974
  property: 'foo',
@@ -9,6 +9,7 @@ import Formatted from '../expression/types/formatted';
9
9
  import ResolvedImage from '../expression/types/resolved_image';
10
10
  import {supportsInterpolation} from '../util/properties';
11
11
  import {findStopLessThanOrEqualTo} from '../expression/stops';
12
+ import Padding from '../util/padding';
12
13
 
13
14
  export function isFunction(value) {
14
15
  return typeof value === 'object' && value !== null && !Array.isArray(value);
@@ -25,19 +26,21 @@ export function createFunction(parameters, propertySpec) {
25
26
  const zoomDependent = zoomAndFeatureDependent || !featureDependent;
26
27
  const type = parameters.type || (supportsInterpolation(propertySpec) ? 'exponential' : 'interval');
27
28
 
28
- if (isColor) {
29
+ if (isColor || propertySpec.type === 'padding') {
30
+ const parseFn = isColor ? Color.parse : Padding.parse;
31
+
29
32
  parameters = extend({}, parameters);
30
33
 
31
34
  if (parameters.stops) {
32
35
  parameters.stops = parameters.stops.map((stop) => {
33
- return [stop[0], Color.parse(stop[1])];
36
+ return [stop[0], parseFn(stop[1])];
34
37
  });
35
38
  }
36
39
 
37
40
  if (parameters.default) {
38
- parameters.default = Color.parse(parameters.default);
41
+ parameters.default = parseFn(parameters.default);
39
42
  } else {
40
- parameters.default = Color.parse(propertySpec.default);
43
+ parameters.default = parseFn(propertySpec.default);
41
44
  }
42
45
  }
43
46
 
@@ -198,14 +201,23 @@ function evaluateExponentialFunction(parameters, propertySpec, input) {
198
201
  }
199
202
 
200
203
  function evaluateIdentityFunction(parameters, propertySpec, input) {
201
- if (propertySpec.type === 'color') {
202
- input = Color.parse(input);
203
- } else if (propertySpec.type === 'formatted') {
204
- input = Formatted.fromString(input.toString());
205
- } else if (propertySpec.type === 'resolvedImage') {
206
- input = ResolvedImage.fromString(input.toString());
207
- } else if (getType(input) !== propertySpec.type && (propertySpec.type !== 'enum' || !propertySpec.values[input])) {
208
- input = undefined;
204
+ switch (propertySpec.type) {
205
+ case 'color':
206
+ input = Color.parse(input);
207
+ break;
208
+ case 'formatted':
209
+ input = Formatted.fromString(input.toString());
210
+ break;
211
+ case 'resolvedImage':
212
+ input = ResolvedImage.fromString(input.toString());
213
+ break;
214
+ case 'padding':
215
+ input = Padding.parse(input);
216
+ break;
217
+ default:
218
+ if (getType(input) !== propertySpec.type && (propertySpec.type !== 'enum' || !propertySpec.values[input])) {
219
+ input = undefined;
220
+ }
209
221
  }
210
222
  return coalesce(input, parameters.default, propertySpec.default);
211
223
  }
@@ -10,12 +10,12 @@ import type {FilterSpecification, LayerSpecification, StyleSpecification} from '
10
10
  * this will convert (a) "stop" functions, and (b) legacy filters to their
11
11
  * expression equivalents.
12
12
  */
13
- export default function(style: StyleSpecification) {
13
+ export default function expressions(style: StyleSpecification) {
14
14
  const converted = [];
15
15
 
16
16
  eachLayer(style, (layer: LayerSpecification & { filter?: FilterSpecification }) => {
17
17
  if (layer.filter) {
18
- layer.filter = (convertFilter(layer.filter) as any);
18
+ layer.filter = convertFilter(layer.filter);
19
19
  }
20
20
  });
21
21
 
@@ -1,3 +1,5 @@
1
+ // @ts-nocheck
2
+
1
3
  import migrate from './v8';
2
4
 
3
5
  describe('migrate v8', () => {
@@ -1,8 +1,9 @@
1
1
 
2
2
  import URL from 'url';
3
3
  import {eachSource, eachLayer, eachProperty} from '../visit';
4
+ import type {LayerSpecification, StyleSpecification} from '../types.g';
4
5
 
5
- function eachLayout(layer, callback) {
6
+ function eachLayout(layer: LayerSpecification, callback: (_: LayerSpecification['layout'], __: string) => void) {
6
7
  for (const k in layer) {
7
8
  if (k.indexOf('layout') === 0) {
8
9
  callback(layer[k], k);
@@ -10,7 +11,7 @@ function eachLayout(layer, callback) {
10
11
  }
11
12
  }
12
13
 
13
- function eachPaint(layer, callback) {
14
+ function eachPaint(layer: LayerSpecification, callback: (_: LayerSpecification['paint'], __: string) => void) {
14
15
  for (const k in layer) {
15
16
  if (k.indexOf('paint') === 0) {
16
17
  callback(layer[k], k);
@@ -18,9 +19,9 @@ function eachPaint(layer, callback) {
18
19
  }
19
20
  }
20
21
 
21
- function resolveConstant(style, value) {
22
+ function resolveConstant(style: StyleSpecification, value: any) {
22
23
  if (typeof value === 'string' && value[0] === '@') {
23
- return resolveConstant(style, style.constants[value]);
24
+ return resolveConstant(style, (style as any).constants[value]);
24
25
  } else {
25
26
  return value;
26
27
  }
@@ -30,11 +31,11 @@ function isFunction(value) {
30
31
  return Array.isArray(value.stops);
31
32
  }
32
33
 
33
- function renameProperty(obj, from, to) {
34
+ function renameProperty(obj: Object, from: string, to: string) {
34
35
  obj[to] = obj[from]; delete obj[from];
35
36
  }
36
37
 
37
- export default function(style) {
38
+ export default function migrateV8(style: StyleSpecification) {
38
39
  style.version = 8;
39
40
 
40
41
  // Rename properties, reverse coordinates in source and layers
@@ -81,7 +82,7 @@ export default function(style) {
81
82
 
82
83
  property.set(value);
83
84
  });
84
- delete style.constants;
85
+ delete style['constants'];
85
86
 
86
87
  eachLayer(style, (layer) => {
87
88
  // get rid of text-max-size, icon-max-size
@@ -1,3 +1,5 @@
1
+ // @ts-nocheck
2
+
1
3
  import migrate from './v9';
2
4
 
3
5
  describe('migrate v9', () => {
@@ -5,7 +7,7 @@ describe('migrate v9', () => {
5
7
  const input = {
6
8
  version: 8,
7
9
  sources: {
8
- a: {type: 'vector', tiles: [ 'http://dev/null' ]}
10
+ a: {type: 'vector', tiles: ['http://dev/null']}
9
11
  },
10
12
  layers: [{
11
13
  id: 'parent',
@@ -21,7 +23,7 @@ describe('migrate v9', () => {
21
23
  expect(migrate(input)).toEqual({
22
24
  version: 9,
23
25
  sources: {
24
- a: {type: 'vector', tiles: [ 'http://dev/null' ]}
26
+ a: {type: 'vector', tiles: ['http://dev/null']}
25
27
  },
26
28
  layers: [{
27
29
  id: 'parent',
@@ -42,7 +44,7 @@ describe('migrate v9', () => {
42
44
  const input = {
43
45
  version: 8,
44
46
  sources: {
45
- a: {type: 'vector', tiles: [ 'http://dev/null' ]}
47
+ a: {type: 'vector', tiles: ['http://dev/null']}
46
48
  },
47
49
  layers: [{
48
50
  id: 'a',
@@ -61,7 +63,7 @@ describe('migrate v9', () => {
61
63
  expect(migrate(input)).toEqual({
62
64
  version: 9,
63
65
  sources: {
64
- a: {type: 'vector', tiles: [ 'http://dev/null' ]}
66
+ a: {type: 'vector', tiles: ['http://dev/null']}
65
67
  },
66
68
  layers: [{
67
69
  id: 'a',
@@ -1,5 +1,6 @@
1
1
 
2
2
  import deref from '../deref';
3
+ import type {StyleSpecification} from '../types.g';
3
4
 
4
5
  function eachLayer(style, callback) {
5
6
  for (const k in style.layers) {
@@ -7,8 +8,8 @@ function eachLayer(style, callback) {
7
8
  }
8
9
  }
9
10
 
10
- export default function(style) {
11
- style.version = 9;
11
+ export default function migrateV9(style: StyleSpecification): StyleSpecification {
12
+ (style.version as any) = 9;
12
13
 
13
14
  // remove user-specified refs
14
15
  style.layers = deref(style.layers);
@@ -1,3 +1,5 @@
1
+ // @ts-nocheck
2
+
1
3
  import migrate from './migrate';
2
4
  import * as spec from './style-spec';
3
5
  import v8 from './reference/v8.json';
@@ -102,7 +104,7 @@ describe('migrate', () => {
102
104
  });
103
105
  expect(migrated.layers[0].layout['icon-image']).toEqual([
104
106
  'match',
105
- ['get', 'type' ],
107
+ ['get', 'type'],
106
108
  'park',
107
109
  'some-icon',
108
110
  ''
@@ -1,24 +1,25 @@
1
1
 
2
2
  import migrateToV8 from './migrate/v8';
3
3
  import migrateToExpressions from './migrate/expressions';
4
+ import type {StyleSpecification} from './types.g';
4
5
 
5
6
  /**
6
7
  * Migrate a Mapbox GL Style to the latest version.
7
8
  *
8
9
  * @private
9
10
  * @alias migrate
10
- * @param {object} style a Mapbox GL Style
11
- * @returns {Object} a migrated style
11
+ * @param {StyleSpecification} style a MapLibre GL Style
12
+ * @returns {StyleSpecification} a migrated style
12
13
  * @example
13
14
  * var fs = require('fs');
14
15
  * var migrate = require('maplibre-gl-style-spec').migrate;
15
16
  * var style = fs.readFileSync('./style.json', 'utf8');
16
17
  * fs.writeFileSync('./style.json', JSON.stringify(migrate(style)));
17
18
  */
18
- export default function(style) {
19
+ export default function migrate(style: StyleSpecification): StyleSpecification {
19
20
  let migrated = false;
20
21
 
21
- if (style.version === 7) {
22
+ if (style.version as any === 7) {
22
23
  style = migrateToV8(style);
23
24
  migrated = true;
24
25
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@maplibre/maplibre-gl-style-spec",
3
3
  "description": "a specification for maplibre gl styles",
4
- "version": "16.0.0",
4
+ "version": "16.1.0",
5
5
  "author": "MapLibre",
6
6
  "keywords": [
7
7
  "mapbox",
@@ -1,7 +1,8 @@
1
1
  import ParsingError from './error/parsing_error';
2
2
  import jsonlint from '@mapbox/jsonlint-lines-primitives';
3
+ import type {StyleSpecification} from './types.g';
3
4
 
4
- export default function readStyle(style) {
5
+ export default function readStyle(style: StyleSpecification | string | Buffer): StyleSpecification {
5
6
  if (style instanceof String || typeof style === 'string' || style instanceof Buffer) {
6
7
  try {
7
8
  return jsonlint.parse(style.toString());
@@ -1,3 +1,3 @@
1
1
 
2
- import spec from './v8.json';
2
+ import spec from './v8.json' assert {type: 'json'};
3
3
  export default spec;
@@ -1466,11 +1466,10 @@
1466
1466
  "property-type": "data-driven"
1467
1467
  },
1468
1468
  "icon-padding": {
1469
- "type": "number",
1470
- "default": 2,
1471
- "minimum": 0,
1469
+ "type": "padding",
1470
+ "default": [2],
1472
1471
  "units": "pixels",
1473
- "doc": "Size of the additional area around the icon bounding box used for detecting symbol collisions.",
1472
+ "doc": "Size of additional area round the icon bounding box used for detecting symbol collisions. Values are declared using CSS margin shorthand syntax: a single value applies to all four sides; two values apply to [top/bottom, left/right]; three values apply to [top, left/right, bottom]; four values apply to [top, right, bottom, left]. For backwards compatibility, a single bare number is accepted, and treated the same as a one-element array - padding applied to all sides.",
1474
1473
  "requires": [
1475
1474
  "icon-image"
1476
1475
  ],
@@ -1480,15 +1479,19 @@
1480
1479
  "android": "2.0.1",
1481
1480
  "ios": "2.0.0",
1482
1481
  "macos": "0.1.0"
1482
+ },
1483
+ "data-driven styling": {
1484
+ "js": "2.2.0"
1483
1485
  }
1484
1486
  },
1485
1487
  "expression": {
1486
1488
  "interpolated": true,
1487
1489
  "parameters": [
1488
- "zoom"
1490
+ "zoom",
1491
+ "feature"
1489
1492
  ]
1490
1493
  },
1491
- "property-type": "data-constant"
1494
+ "property-type": "data-driven"
1492
1495
  },
1493
1496
  "icon-keep-upright": {
1494
1497
  "type": "boolean",
@@ -67,7 +67,8 @@ function validSchema(k, v, obj, ref, version, kind) {
67
67
  'property-type',
68
68
  'formatted',
69
69
  'resolvedImage',
70
- 'promoteId'
70
+ 'promoteId',
71
+ 'padding'
71
72
  ]);
72
73
  const keys = [
73
74
  'default',
@@ -55,6 +55,12 @@ export type StylePropertySpecification = {
55
55
  length?: number;
56
56
  transition: boolean;
57
57
  default?: Array<string>;
58
+ } | {
59
+ type: 'padding';
60
+ 'property-type': ExpressionType;
61
+ expression?: ExpressionSpecification;
62
+ transition: boolean;
63
+ default?: number | Array<number>;
58
64
  };
59
65
 
60
66
  import v8 from './reference/v8.json';
@@ -71,6 +77,7 @@ import featureFilter, {isExpressionFilter} from './feature_filter';
71
77
 
72
78
  import convertFilter from './feature_filter/convert';
73
79
  import Color from './util/color';
80
+ import Padding from './util/padding';
74
81
  import {createFunction, isFunction} from './function';
75
82
  import convertFunction from './function/convert';
76
83
  import {eachSource, eachLayer, eachProperty} from './visit';
@@ -111,6 +118,7 @@ export {
111
118
  featureFilter,
112
119
  convertFilter,
113
120
  Color,
121
+ Padding,
114
122
  styleFunction as function,
115
123
  validate,
116
124
  visit