@mapbox/mapbox-gl-style-spec 14.8.0 → 14.9.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.
@@ -13,14 +13,14 @@ export function validateRGBA(r: unknown, g: unknown, b: unknown, a?: unknown): s
13
13
  typeof g === 'number' && g >= 0 && g <= 255 &&
14
14
  typeof b === 'number' && b >= 0 && b <= 255
15
15
  )) {
16
- const value = typeof a === 'number' ? [r, g, b, a] : [r, g, b];
16
+ const value = (typeof a === 'number' ? [r, g, b, a] : [r, g, b]) as number[];
17
17
  return `Invalid rgba value [${value.join(', ')}]: 'r', 'g', and 'b' must be between 0 and 255.`;
18
18
  }
19
19
 
20
20
  if (!(
21
21
  typeof a === 'undefined' || (typeof a === 'number' && a >= 0 && a <= 1)
22
22
  )) {
23
- return `Invalid rgba value [${[r, g, b, a].join(', ')}]: 'a' must be between 0 and 1.`;
23
+ return `Invalid rgba value [${([r, g, b, a] as number[]).join(', ')}]: 'a' must be between 0 and 1.`;
24
24
  }
25
25
 
26
26
  return null;
@@ -30,7 +30,7 @@ export function validateHSLA(h: unknown, s: unknown, l: unknown, a?: unknown): s
30
30
  if (!(
31
31
  typeof h === 'number' && h >= 0 && h <= 360
32
32
  )) {
33
- const value = typeof a === 'number' ? [h, s, l, a] : [h, s, l];
33
+ const value = (typeof a === 'number' ? [h, s, l, a] : [h, s, l]) as number[];
34
34
  return `Invalid hsla value [${value.join(', ')}]: 'h' must be between 0 and 360.`;
35
35
  }
36
36
 
@@ -38,14 +38,14 @@ export function validateHSLA(h: unknown, s: unknown, l: unknown, a?: unknown): s
38
38
  typeof s === 'number' && s >= 0 && s <= 100 &&
39
39
  typeof l === 'number' && l >= 0 && l <= 100
40
40
  )) {
41
- const value = typeof a === 'number' ? [h, s, l, a] : [h, s, l];
41
+ const value = (typeof a === 'number' ? [h, s, l, a] : [h, s, l]) as number[];
42
42
  return `Invalid hsla value [${value.join(', ')}]: 's', and 'l' must be between 0 and 100.`;
43
43
  }
44
44
 
45
45
  if (!(
46
46
  typeof a === 'undefined' || (typeof a === 'number' && a >= 0 && a <= 1)
47
47
  )) {
48
- return `Invalid hsla value [${[h, s, l, a].join(', ')}]: 'a' must be between 0 and 1.`;
48
+ return `Invalid hsla value [${([h, s, l, a] as number[]).join(', ')}]: 'a' must be between 0 and 1.`;
49
49
  }
50
50
 
51
51
  return null;
@@ -136,8 +136,10 @@ export function toString(value: Value): string {
136
136
  if (value === null) {
137
137
  return '';
138
138
  } else if (type === 'string' || type === 'number' || type === 'boolean') {
139
- return String(value);
140
- } else if (value instanceof Color || value instanceof Formatted || value instanceof ResolvedImage) {
139
+ return String(value as string | number | boolean);
140
+ } else if (value instanceof Color) {
141
+ return value.toStringPremultipliedAlpha();
142
+ } else if (value instanceof Formatted || value instanceof ResolvedImage) {
141
143
  return value.toString();
142
144
  } else {
143
145
  return JSON.stringify(value);
@@ -22,6 +22,7 @@ export type FilterExpression = (
22
22
  featureTileCoord?: Point,
23
23
  featureDistanceData?: FeatureDistanceData,
24
24
  ) => boolean;
25
+
25
26
  export type FeatureFilter = {
26
27
  filter: FilterExpression;
27
28
  dynamicFilter?: FilterExpression;
package/function/index.ts CHANGED
@@ -204,7 +204,7 @@ function evaluateIdentityFunction(parameters, propertySpec, input) {
204
204
  } else if (propertySpec.type === 'formatted') {
205
205
  input = Formatted.fromString(input.toString());
206
206
  } else if (propertySpec.type === 'resolvedImage') {
207
- input = ResolvedImage.fromString(input.toString());
207
+ input = ResolvedImage.build(input.toString());
208
208
  } else if (getType(input) !== propertySpec.type && (propertySpec.type !== 'enum' || !propertySpec.values[input])) {
209
209
  input = undefined;
210
210
  }
@@ -29,6 +29,25 @@ function getKey(layer: LayerSpecification) {
29
29
  return key;
30
30
  }
31
31
 
32
+ function containsKey(obj: any, key: string) {
33
+ function recursiveSearch(item) {
34
+ if (typeof item === 'string' && item === key) {
35
+ return true;
36
+ }
37
+
38
+ if (Array.isArray(item)) {
39
+ return item.some(recursiveSearch);
40
+ }
41
+
42
+ if (item && typeof item === 'object') {
43
+ return Object.values(item).some(recursiveSearch);
44
+ }
45
+
46
+ return false;
47
+ }
48
+ return recursiveSearch(obj);
49
+ }
50
+
32
51
  /**
33
52
  * Given an array of layers, return an array of arrays of layers where all
34
53
  * layers in each group have identical layout-affecting properties. These
@@ -53,17 +72,30 @@ export default function groupByLayout(
53
72
  const groups: Record<string, any> = {};
54
73
 
55
74
  for (let i = 0; i < layers.length; i++) {
75
+ const layer = layers[i];
76
+ let k = cachedKeys && cachedKeys[layer.id];
77
+
78
+ if (!k) {
79
+ k = getKey(layer);
80
+ // The usage of "line-progress" inside "line-width" makes the property act like a layout property.
81
+ // We need to split it from the group to avoid conflicts in the bucket creation.
82
+ if (layer.type === 'line' && layer["paint"]) {
83
+ const lineWidth = layer["paint"]['line-width'];
84
+ if (containsKey(lineWidth, 'line-progress')) {
85
+ k += `/${stringify(layer["paint"]['line-width'])}`;
86
+ }
87
+ }
88
+ }
56
89
 
57
- const k = (cachedKeys && cachedKeys[layers[i].id]) || getKey(layers[i]);
58
90
  // update the cache if there is one
59
91
  if (cachedKeys)
60
- cachedKeys[layers[i].id] = k;
92
+ cachedKeys[layer.id] = k;
61
93
 
62
94
  let group = groups[k];
63
95
  if (!group) {
64
96
  group = groups[k] = [];
65
97
  }
66
- group.push(layers[i]);
98
+ group.push(layer);
67
99
  }
68
100
 
69
101
  const result = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapbox/mapbox-gl-style-spec",
3
- "version": "14.8.0",
3
+ "version": "14.9.0",
4
4
  "description": "a specification for mapbox gl styles",
5
5
  "author": "Mapbox",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",