@mapbox/mapbox-gl-style-spec 14.14.0-beta.1 → 14.14.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 (43) hide show
  1. package/composite.ts +5 -8
  2. package/dist/index.cjs +31 -9
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.ts +37 -15
  5. package/dist/index.es.js +31 -9
  6. package/dist/index.es.js.map +1 -1
  7. package/expression/definitions/distance.ts +2 -3
  8. package/expression/definitions/image.ts +1 -1
  9. package/expression/definitions/index.ts +4 -20
  10. package/expression/definitions/interpolate.ts +6 -9
  11. package/expression/definitions/within.ts +14 -15
  12. package/expression/index.ts +2 -4
  13. package/expression/types/image_variant.ts +1 -1
  14. package/expression/types.ts +13 -2
  15. package/group_by_layout.ts +3 -6
  16. package/migrate.ts +6 -8
  17. package/package.json +1 -1
  18. package/read_style.ts +1 -2
  19. package/reference/v8.json +25 -0
  20. package/style-spec.ts +1 -1
  21. package/types.ts +92 -71
  22. package/util/geometry_util.ts +1 -2
  23. package/validate/validate.ts +5 -6
  24. package/validate/validate_array.ts +2 -2
  25. package/validate/validate_enum.ts +2 -2
  26. package/validate/validate_expression.ts +1 -2
  27. package/validate/validate_filter.ts +3 -4
  28. package/validate/validate_fog.ts +2 -5
  29. package/validate/validate_function.ts +6 -10
  30. package/validate/validate_iconset.ts +1 -2
  31. package/validate/validate_layer.ts +2 -3
  32. package/validate/validate_light.ts +1 -4
  33. package/validate/validate_lights.ts +2 -8
  34. package/validate/validate_model.ts +1 -4
  35. package/validate/validate_projection.ts +1 -2
  36. package/validate/validate_property.ts +2 -6
  37. package/validate/validate_rain.ts +1 -4
  38. package/validate/validate_snow.ts +1 -4
  39. package/validate/validate_source.ts +2 -3
  40. package/validate/validate_terrain.ts +1 -5
  41. package/validate_mapbox_api_supported.ts +2 -4
  42. package/validate_style.ts +1 -2
  43. package/visit.ts +3 -5
@@ -142,12 +142,11 @@ function getLngLatPoint(coord: Point, canonical: CanonicalTileID) {
142
142
  return [lngFromMercatorX(x), latFromMercatorY(y)];
143
143
  }
144
144
 
145
- function getLngLatPoints(coordinates: Array<Point>, canonical: CanonicalTileID) {
146
- const coords = [];
145
+ function getLngLatPoints(coordinates: Array<Point>, canonical: CanonicalTileID): number[][] {
146
+ const coords: number[][] = [];
147
147
  for (let i = 0; i < coordinates.length; ++i) {
148
148
  coords.push(getLngLatPoint(coordinates[i], canonical));
149
149
  }
150
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
151
150
  return coords;
152
151
  }
153
152
 
@@ -14,7 +14,7 @@ export type IconsetParams = {id: string};
14
14
  export type ImageOptions = {
15
15
  params?: ImageParams;
16
16
  iconset?: IconsetParams;
17
- }
17
+ };
18
18
 
19
19
  type SerializedImageOptions = {
20
20
  params?: Record<string, SerializedExpression>;
@@ -120,30 +120,16 @@ function hsla(ctx: EvaluationContext, [h, s, l, a]: Expression[]) {
120
120
  return color;
121
121
  }
122
122
 
123
- function has(
124
- key: string,
125
- obj: {
126
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
127
- [key: string]: any;
128
- },
129
- ): boolean {
123
+ function has<T extends object>(key: keyof T, obj: T): boolean {
130
124
  return key in obj;
131
125
  }
132
126
 
133
- function get(key: string, obj: {
134
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
135
- [key: string]: any;
136
- }) {
127
+ function get<T extends object>(key: keyof T, obj: T): T[keyof T] | null {
137
128
  const v = obj[key];
138
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
139
129
  return typeof v === 'undefined' ? null : v;
140
130
  }
141
131
 
142
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
143
- function binarySearch(v: any, a: {
144
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
145
- [key: number]: any;
146
- }, i: number, j: number) {
132
+ function binarySearch(v: unknown, a: Record<number, unknown>, i: number, j: number): boolean {
147
133
  while (i <= j) {
148
134
  const m = (i + j) >> 1;
149
135
  if (a[m] === v)
@@ -237,7 +223,6 @@ CompoundExpression.register(expressions, {
237
223
  overloads: [
238
224
  [
239
225
  [StringType],
240
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
241
226
  (ctx, [key]) => get(key.evaluate(ctx), ctx.properties())
242
227
  ], [
243
228
  [StringType, ObjectType],
@@ -249,8 +234,7 @@ CompoundExpression.register(expressions, {
249
234
  'feature-state': [
250
235
  ValueType,
251
236
  [StringType],
252
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
253
- (ctx, [key]) => get(key.evaluate(ctx), ctx.featureState || {})
237
+ (ctx, [key]) => get(key.evaluate(ctx), ctx.featureState || {}) as Value
254
238
  ],
255
239
  'properties': [
256
240
  ObjectType,
@@ -157,20 +157,17 @@ class Interpolate implements Expression {
157
157
  const outputs = this.outputs;
158
158
 
159
159
  if (labels.length === 1) {
160
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
161
- return outputs[0].evaluate(ctx);
160
+ return outputs[0].evaluate(ctx) as Color;
162
161
  }
163
162
 
164
- const value = (this.input.evaluate(ctx) as number);
163
+ const value: number = this.input.evaluate(ctx);
165
164
  if (value <= labels[0]) {
166
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
167
- return outputs[0].evaluate(ctx);
165
+ return outputs[0].evaluate(ctx) as Color;
168
166
  }
169
167
 
170
168
  const stopCount = labels.length;
171
169
  if (value >= labels[stopCount - 1]) {
172
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
173
- return outputs[stopCount - 1].evaluate(ctx);
170
+ return outputs[stopCount - 1].evaluate(ctx) as Color;
174
171
  }
175
172
 
176
173
  const index = findStopLessThanOrEqualTo(labels, value);
@@ -178,8 +175,8 @@ class Interpolate implements Expression {
178
175
  const upper = labels[index + 1];
179
176
  const t = Interpolate.interpolationFactor(this.interpolation, value, lower, upper);
180
177
 
181
- const outputLower = outputs[index].evaluate(ctx);
182
- const outputUpper = outputs[index + 1].evaluate(ctx);
178
+ const outputLower: Color = outputs[index].evaluate(ctx);
179
+ const outputUpper: Color = outputs[index + 1].evaluate(ctx);
183
180
 
184
181
  if (this.operator === 'interpolate') {
185
182
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return
@@ -2,11 +2,11 @@ import {isValue} from '../values';
2
2
  import {BooleanType} from '../types';
3
3
  import {updateBBox, boxWithinBox, pointWithinPolygon, segmentIntersectSegment} from '../../util/geometry_util';
4
4
 
5
+ import type Point from '@mapbox/point-geometry';
5
6
  import type {Type} from '../types';
6
7
  import type {Expression, SerializedExpression} from '../expression';
7
8
  import type ParsingContext from '../parsing_context';
8
9
  import type EvaluationContext from '../evaluation_context';
9
- import type Point from '@mapbox/point-geometry';
10
10
  import type {CanonicalTileID} from '../../types/tile_id';
11
11
  import type {BBox} from '../../util/geometry_util';
12
12
 
@@ -74,10 +74,10 @@ function lineStringWithinPolygons(line: Array<GeoJSON.Position>, polygons: Array
74
74
  return false;
75
75
  }
76
76
 
77
- function getTilePolygon(coordinates: Array<Array<GeoJSON.Position>>, bbox: BBox, canonical: CanonicalTileID) {
78
- const polygon = [];
77
+ function getTilePolygon(coordinates: Array<Array<GeoJSON.Position>>, bbox: BBox, canonical: CanonicalTileID): Array<Array<number[]>> {
78
+ const polygon: Array<Array<number[]>> = [];
79
79
  for (let i = 0; i < coordinates.length; i++) {
80
- const ring = [];
80
+ const ring: number[][] = [];
81
81
  for (let j = 0; j < coordinates[i].length; j++) {
82
82
  const coord = getTileCoordinates(coordinates[i][j], canonical);
83
83
  updateBBox(bbox, coord);
@@ -85,17 +85,17 @@ function getTilePolygon(coordinates: Array<Array<GeoJSON.Position>>, bbox: BBox,
85
85
  }
86
86
  polygon.push(ring);
87
87
  }
88
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
88
+
89
89
  return polygon;
90
90
  }
91
91
 
92
- function getTilePolygons(coordinates: Array<Array<Array<GeoJSON.Position>>>, bbox: BBox, canonical: CanonicalTileID) {
93
- const polygons = [];
92
+ function getTilePolygons(coordinates: Array<Array<Array<GeoJSON.Position>>>, bbox: BBox, canonical: CanonicalTileID): Array<Array<Array<number[]>>> {
93
+ const polygons: Array<Array<Array<number[]>>> = [];
94
94
  for (let i = 0; i < coordinates.length; i++) {
95
95
  const polygon = getTilePolygon(coordinates[i], bbox, canonical);
96
96
  polygons.push(polygon);
97
97
  }
98
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
98
+
99
99
  return polygons;
100
100
  }
101
101
 
@@ -116,11 +116,10 @@ function resetBBox(bbox: BBox) {
116
116
  bbox[2] = bbox[3] = -Infinity;
117
117
  }
118
118
 
119
- function getTilePoints(geometry: Array<Array<Point>> | null | undefined, pointBBox: BBox, polyBBox: Array<number>, canonical: CanonicalTileID) {
119
+ function getTilePoints(geometry: Array<Array<Point>> | null | undefined, pointBBox: BBox, polyBBox: Array<number>, canonical: CanonicalTileID): Array<number[]> {
120
120
  const worldSize = Math.pow(2, canonical.z) * EXTENT;
121
121
  const shifts = [canonical.x * EXTENT, canonical.y * EXTENT];
122
- const tilePoints = [];
123
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
122
+ const tilePoints: Array<number[]> = [];
124
123
  if (!geometry) return tilePoints;
125
124
  for (const points of geometry) {
126
125
  for (const point of points) {
@@ -129,11 +128,11 @@ function getTilePoints(geometry: Array<Array<Point>> | null | undefined, pointBB
129
128
  tilePoints.push(p);
130
129
  }
131
130
  }
132
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
131
+
133
132
  return tilePoints;
134
133
  }
135
134
 
136
- function getTileLines(geometry: Array<Array<Point>> | null | undefined, lineBBox: BBox, polyBBox: Array<number>, canonical: CanonicalTileID) {
135
+ function getTileLines(geometry: Array<Array<Point>> | null | undefined, lineBBox: BBox, polyBBox: Array<number>, canonical: CanonicalTileID): Array<Array<GeoJSON.Position>> {
137
136
  const worldSize = Math.pow(2, canonical.z) * EXTENT;
138
137
  const shifts = [canonical.x * EXTENT, canonical.y * EXTENT];
139
138
  const tileLines: Array<Array<GeoJSON.Position>> = [];
@@ -158,7 +157,7 @@ function getTileLines(geometry: Array<Array<Point>> | null | undefined, lineBBox
158
157
  return tileLines;
159
158
  }
160
159
 
161
- function pointsWithinPolygons(ctx: EvaluationContext, polygonGeometry: GeoJSONPolygons) {
160
+ function pointsWithinPolygons(ctx: EvaluationContext, polygonGeometry: GeoJSONPolygons): boolean {
162
161
  const pointBBox: BBox = [Infinity, Infinity, -Infinity, -Infinity];
163
162
  const polyBBox: BBox = [Infinity, Infinity, -Infinity, -Infinity];
164
163
 
@@ -189,7 +188,7 @@ function pointsWithinPolygons(ctx: EvaluationContext, polygonGeometry: GeoJSONPo
189
188
  return true;
190
189
  }
191
190
 
192
- function linesWithinPolygons(ctx: EvaluationContext, polygonGeometry: GeoJSONPolygons) {
191
+ function linesWithinPolygons(ctx: EvaluationContext, polygonGeometry: GeoJSONPolygons): boolean {
193
192
  const lineBBox: BBox = [Infinity, Infinity, -Infinity, -Infinity];
194
193
  const polyBBox: BBox = [Infinity, Infinity, -Infinity, -Infinity];
195
194
 
@@ -355,8 +355,7 @@ export function createPropertyExpression(
355
355
  ): Result<StylePropertyExpression, Array<ParsingError>> {
356
356
  expression = createExpression(expression, propertySpec, scope, options);
357
357
  if (expression.result === 'error') {
358
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
359
- return expression;
358
+ return expression as Result<StylePropertyExpression, Array<ParsingError>>;
360
359
  }
361
360
 
362
361
  const parsed = expression.value.expression;
@@ -476,7 +475,7 @@ export function normalizePropertyExpression<T>(
476
475
  // expression (collectively referred to as a "curve"). The curve may be wrapped in one or more "let" or
477
476
  // "coalesce" expressions.
478
477
  function findZoomCurve(expression: Expression): Step | Interpolate | ParsingError | null {
479
- let result = null;
478
+ let result: Step | Interpolate | ParsingError | null = null;
480
479
  if (expression instanceof Let) {
481
480
  result = findZoomCurve(expression.result);
482
481
 
@@ -508,7 +507,6 @@ function findZoomCurve(expression: Expression): Step | Interpolate | ParsingErro
508
507
  }
509
508
  });
510
509
 
511
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
512
510
  return result;
513
511
  }
514
512
 
@@ -19,7 +19,7 @@ export type StringifiedImageVariant = Brand<string, 'ImageVariant'>;
19
19
  export type RasterizationOptions = {
20
20
  params?: Record<string, Color>;
21
21
  transform?: DOMMatrix;
22
- }
22
+ };
23
23
 
24
24
  /**
25
25
  * `ImageVariant` is a component of {@link ResolvedImage}
@@ -34,8 +34,19 @@ export type ResolvedImageTypeT = {
34
34
 
35
35
  export type EvaluationKind = 'constant' | 'source' | 'camera' | 'composite';
36
36
 
37
- export type Type = NullTypeT | NumberTypeT | StringTypeT | BooleanTypeT | ColorTypeT | ObjectTypeT | ValueTypeT |
38
- ArrayType | ErrorTypeT | CollatorTypeT | FormattedTypeT | ResolvedImageTypeT;
37
+ export type Type =
38
+ | NullTypeT
39
+ | NumberTypeT
40
+ | StringTypeT
41
+ | BooleanTypeT
42
+ | ColorTypeT
43
+ | ObjectTypeT
44
+ | ValueTypeT
45
+ | ArrayType
46
+ | ErrorTypeT
47
+ | CollatorTypeT
48
+ | FormattedTypeT
49
+ | ResolvedImageTypeT;
39
50
 
40
51
  export type ArrayType = {
41
52
  kind: 'array';
@@ -2,8 +2,7 @@ import refProperties from './util/ref_properties';
2
2
 
3
3
  import type {LayerSpecification} from './types';
4
4
 
5
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
- function stringify(obj: any) {
5
+ function stringify(obj: unknown) {
7
6
  if (typeof obj === 'number' || typeof obj === 'boolean' || typeof obj === 'string' || obj === undefined || obj === null)
8
7
  return JSON.stringify(obj);
9
8
 
@@ -30,8 +29,7 @@ function getKey(layer: LayerSpecification) {
30
29
  return key;
31
30
  }
32
31
 
33
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
- function containsKey(obj: any, key: string) {
32
+ function containsKey(obj: unknown, key: string) {
35
33
  function recursiveSearch(item) {
36
34
  if (typeof item === 'string' && item === key) {
37
35
  return true;
@@ -106,12 +104,11 @@ export default function groupByLayout(
106
104
  group.push(layer);
107
105
  }
108
106
 
109
- const result = [];
107
+ const result: LayerSpecification[][] = [];
110
108
 
111
109
  for (const k in groups) {
112
110
  result.push(groups[k]);
113
111
  }
114
112
 
115
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
116
113
  return result;
117
114
  }
package/migrate.ts CHANGED
@@ -1,9 +1,8 @@
1
- /* eslint-disable @typescript-eslint/ban-ts-comment */
2
- // @ts-nocheck
3
-
4
1
  import migrateToV8 from './migrate/v8';
5
2
  import migrateToExpressions from './migrate/expressions';
6
3
 
4
+ import type {StyleSpecification} from './types';
5
+
7
6
  /**
8
7
  * Migrate a Mapbox GL Style to the latest version.
9
8
  *
@@ -17,7 +16,7 @@ import migrateToExpressions from './migrate/expressions';
17
16
  * var style = fs.readFileSync('./style.json', 'utf8');
18
17
  * fs.writeFileSync('./style.json', JSON.stringify(migrate(style)));
19
18
  */
20
- export default function (style) {
19
+ export default function (style: {version: 7} | StyleSpecification): StyleSpecification {
21
20
  let migrated = false;
22
21
 
23
22
  if (style.version === 7) {
@@ -26,14 +25,13 @@ export default function (style) {
26
25
  }
27
26
 
28
27
  if (style.version === 8) {
29
- migrated = migrateToExpressions(style);
28
+ style = migrateToExpressions(style);
30
29
  migrated = true;
31
30
  }
32
31
 
33
32
  if (!migrated) {
34
- throw new Error('cannot migrate from', style.version);
33
+ throw new Error(`Cannot migrate from ${style.version}`);
35
34
  }
36
35
 
37
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
38
- return style;
36
+ return style as StyleSpecification;
39
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapbox/mapbox-gl-style-spec",
3
- "version": "14.14.0-beta.1",
3
+ "version": "14.14.0",
4
4
  "description": "a specification for mapbox gl styles",
5
5
  "author": "Mapbox",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
package/read_style.ts CHANGED
@@ -6,8 +6,7 @@ import type {StyleSpecification} from './types';
6
6
  export default function readStyle(style: string | Buffer | StyleSpecification): StyleSpecification {
7
7
  if (style instanceof String || typeof style === 'string' || ArrayBuffer.isView(style)) {
8
8
  try {
9
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
10
- return jsonlint.parse(style.toString());
9
+ return jsonlint.parse(style.toString()) as StyleSpecification;
11
10
  } catch (e) {
12
11
  throw new ParsingError(e);
13
12
  }
package/reference/v8.json CHANGED
@@ -1553,6 +1553,27 @@
1553
1553
  "paint": {
1554
1554
  "type": "paint",
1555
1555
  "doc": "Default paint properties for this layer."
1556
+ },
1557
+ "appearances": {
1558
+ "type": "array",
1559
+ "value": "appearance",
1560
+ "supported-layer-types": ["symbol"],
1561
+ "private": true,
1562
+ "doc": "Conditional styling applied to layer features based on dynamic conditions. If multiple conditions are true, only the first matching appearance will be applied. Only properties marked with 'Can be used in appearances' are supported."
1563
+ }
1564
+ },
1565
+ "appearance": {
1566
+ "condition": {
1567
+ "type": "expression",
1568
+ "doc": "A boolean expression that determines when this appearance should be applied."
1569
+ },
1570
+ "name": {
1571
+ "type": "string",
1572
+ "doc": "Optional name for this appearance. Non-empty names should be unique within a layer."
1573
+ },
1574
+ "properties": {
1575
+ "type": "*",
1576
+ "doc": "Style properties to apply when the condition is met."
1556
1577
  }
1557
1578
  },
1558
1579
  "layout": [
@@ -2789,6 +2810,7 @@
2789
2810
  "minimum": 0,
2790
2811
  "units": "factor of the original icon size",
2791
2812
  "doc": "Scales the original size of the icon by the provided factor. The new pixel size of the image will be the original pixel size multiplied by `icon-size`. 1 is the original size; 3 triples the size of the image.",
2813
+ "appearance": true,
2792
2814
  "requires": [
2793
2815
  "icon-image"
2794
2816
  ],
@@ -2932,6 +2954,7 @@
2932
2954
  "type": "resolvedImage",
2933
2955
  "doc": "Name of image in sprite to use for drawing an image background.",
2934
2956
  "tokens": true,
2957
+ "appearance": true,
2935
2958
  "sdk-support": {
2936
2959
  "basic functionality": {
2937
2960
  "js": "0.10.0",
@@ -2959,6 +2982,7 @@
2959
2982
  "period": 360,
2960
2983
  "units": "degrees",
2961
2984
  "doc": "Rotates the icon clockwise.",
2985
+ "appearance": true,
2962
2986
  "requires": [
2963
2987
  "icon-image"
2964
2988
  ],
@@ -3047,6 +3071,7 @@
3047
3071
  0
3048
3072
  ],
3049
3073
  "doc": "Offset distance of icon from its anchor. Positive values indicate right and down, while negative values indicate left and up. Each component is multiplied by the value of `icon-size` to obtain the final offset in pixels. When combined with `icon-rotate` the offset will be as if the rotated direction was up.",
3074
+ "appearance": true,
3050
3075
  "requires": [
3051
3076
  "icon-image"
3052
3077
  ],
package/style-spec.ts CHANGED
@@ -5,7 +5,7 @@ export type ExpressionSpecification = {
5
5
  interpolated: boolean,
6
6
  parameters?: ExpressionParameters,
7
7
  relaxZoomRestriction?: boolean
8
- }
8
+ };
9
9
 
10
10
  export type StylePropertySpecification = {
11
11
  type: 'number',