@mapbox/mapbox-gl-style-spec 14.11.0-beta.2 → 14.12.0-beta.1

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 (47) hide show
  1. package/diff.ts +47 -11
  2. package/dist/index.cjs +687 -30
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.ts +186 -13
  5. package/dist/index.es.js +687 -30
  6. package/dist/index.es.js.map +1 -1
  7. package/expression/compound_expression.ts +1 -1
  8. package/expression/definitions/coalesce.ts +2 -2
  9. package/expression/definitions/config.ts +1 -1
  10. package/expression/definitions/image.ts +1 -11
  11. package/expression/definitions/index.ts +3 -2
  12. package/expression/definitions/interpolate.ts +3 -3
  13. package/expression/definitions/match.ts +1 -1
  14. package/expression/definitions/step.ts +1 -1
  15. package/expression/evaluation_context.ts +3 -5
  16. package/expression/index.ts +4 -8
  17. package/expression/parsing_context.ts +1 -1
  18. package/expression/types/image_id.ts +6 -8
  19. package/expression/types.ts +1 -1
  20. package/expression/values.ts +1 -3
  21. package/feature_filter/index.ts +1 -1
  22. package/function/index.ts +3 -3
  23. package/migrate/expressions.ts +1 -1
  24. package/migrate/v8.ts +1 -1
  25. package/migrate/v9.ts +1 -1
  26. package/migrate.ts +1 -1
  27. package/package.json +1 -1
  28. package/read_style.ts +4 -6
  29. package/reference/v8.json +313 -0
  30. package/test.js +2 -5
  31. package/types.ts +195 -0
  32. package/util/extend.ts +1 -1
  33. package/util/geometry_util.ts +19 -2
  34. package/util/interpolate.ts +4 -0
  35. package/validate/validate_fog.ts +1 -1
  36. package/validate/validate_glyphs_url.ts +1 -1
  37. package/validate/validate_layer.ts +2 -2
  38. package/validate/validate_light.ts +1 -1
  39. package/validate/validate_lights.ts +1 -1
  40. package/validate/validate_property.ts +1 -1
  41. package/validate/validate_source.ts +2 -4
  42. package/validate/validate_style.ts +2 -1
  43. package/validate/validate_terrain.ts +1 -1
  44. package/validate_mapbox_api_supported.ts +1 -1
  45. package/validate_style.min.ts +17 -15
  46. package/validate_style.ts +3 -3
  47. package/visit.ts +1 -1
@@ -73,7 +73,7 @@ class CompoundExpression implements Expression {
73
73
 
74
74
  const overloadParams = [];
75
75
 
76
- let signatureContext: ParsingContext = (null as any);
76
+ let signatureContext: ParsingContext = null;
77
77
 
78
78
  let overloadIndex = -1;
79
79
 
@@ -21,7 +21,7 @@ class Coalesce implements Expression {
21
21
  // @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Coalesce'.
22
22
  return context.error("Expectected at least one argument.");
23
23
  }
24
- let outputType: Type = (null as any);
24
+ let outputType: Type = null;
25
25
  const expectedType = context.expectedType;
26
26
  if (expectedType && expectedType.kind !== 'value') {
27
27
  outputType = expectedType;
@@ -46,7 +46,7 @@ class Coalesce implements Expression {
46
46
 
47
47
  return needsAnnotation ?
48
48
  new Coalesce(ValueType, parsedArgs) :
49
- new Coalesce((outputType as any), parsedArgs);
49
+ new Coalesce(outputType, parsedArgs);
50
50
  }
51
51
 
52
52
  evaluate(ctx: EvaluationContext): any {
@@ -101,7 +101,7 @@ class Config implements Expression {
101
101
  if (typeof result === 'number') {
102
102
  result = clampToAllowedNumber(result, minValue, maxValue, stepValue);
103
103
  } else if (Array.isArray(result)) {
104
- result = result.map((item) => typeof item === 'number' ? clampToAllowedNumber(item, minValue, maxValue, stepValue) : item);
104
+ result = result.map((item) => (typeof item === 'number' ? clampToAllowedNumber(item, minValue, maxValue, stepValue) : item));
105
105
  }
106
106
  }
107
107
 
@@ -167,17 +167,7 @@ export default class ImageExpression implements Expression {
167
167
  for (const key in params) {
168
168
  if (params[key]) {
169
169
  try {
170
- const color = params[key].evaluate(ctx);
171
- const msg = `Ignoring image parameter "${key}" with semi-transparent color ${color.toString()}`;
172
-
173
- if (color.a !== 1) {
174
- if (!this._imageWarnHistory[msg]) {
175
- console.warn(msg);
176
- this._imageWarnHistory[msg] = true;
177
- }
178
- continue;
179
- }
180
- result[key] = color;
170
+ result[key] = params[key].evaluate(ctx);
181
171
  } catch (err) {
182
172
  continue;
183
173
  }
@@ -47,6 +47,7 @@ import Distance from './distance';
47
47
  import {mulberry32} from '../../util/random';
48
48
 
49
49
  import type {Type} from '../types';
50
+ import type {Value} from '../values';
50
51
  import type EvaluationContext from '../evaluation_context';
51
52
  import type {Varargs} from '../compound_expression';
52
53
  import type {Expression, ExpressionRegistry} from '../expression';
@@ -242,7 +243,7 @@ CompoundExpression.register(expressions, {
242
243
  'properties': [
243
244
  ObjectType,
244
245
  [],
245
- (ctx) => ctx.properties()
246
+ (ctx) => ctx.properties() as Value
246
247
  ],
247
248
  'geometry-type': [
248
249
  StringType,
@@ -302,7 +303,7 @@ CompoundExpression.register(expressions, {
302
303
  'accumulated': [
303
304
  ValueType,
304
305
  [],
305
- (ctx) => ctx.globals.accumulated === undefined ? null : ctx.globals.accumulated
306
+ (ctx) => (ctx.globals.accumulated === undefined ? null : ctx.globals.accumulated)
306
307
  ],
307
308
  '+': [
308
309
  NumberType,
@@ -91,7 +91,7 @@ class Interpolate implements Expression {
91
91
 
92
92
  interpolation = {
93
93
  name: 'cubic-bezier',
94
- controlPoints: (controlPoints as any)
94
+ controlPoints
95
95
  };
96
96
  } else {
97
97
  return context.error(`Unknown interpolation type ${String(interpolation[0])}`, 1, 0);
@@ -110,7 +110,7 @@ class Interpolate implements Expression {
110
110
 
111
111
  const stops: Stops = [];
112
112
 
113
- let outputType: Type = (null as any);
113
+ let outputType: Type = null;
114
114
  if (operator === 'interpolate-hcl' || operator === 'interpolate-lab') {
115
115
  outputType = ColorType;
116
116
  } else if (context.expectedType && context.expectedType.kind !== 'value') {
@@ -179,7 +179,7 @@ class Interpolate implements Expression {
179
179
  const outputUpper = outputs[index + 1].evaluate(ctx);
180
180
 
181
181
  if (this.operator === 'interpolate') {
182
- return (interpolate[this.type.kind.toLowerCase()] as any)(outputLower, outputUpper, t); // eslint-disable-line import/namespace
182
+ return (interpolate[this.type.kind.toLowerCase()] as any)(outputLower, outputUpper, t);
183
183
  } else if (this.operator === 'interpolate-hcl') {
184
184
  return hcl.reverse(hcl.interpolate(hcl.forward(outputLower), hcl.forward(outputUpper), t));
185
185
  } else {
@@ -138,7 +138,7 @@ class Match implements Expression {
138
138
  }
139
139
  }
140
140
 
141
- const coerceLabel = (label: number | string) => this.inputType.kind === 'number' ? Number(label) : label;
141
+ const coerceLabel = (label: number | string) => (this.inputType.kind === 'number' ? Number(label) : label);
142
142
 
143
143
  for (const [outputIndex, labels] of groupedByOutput) {
144
144
  if (labels.length === 1) {
@@ -40,7 +40,7 @@ class Step implements Expression {
40
40
 
41
41
  const stops: Stops = [];
42
42
 
43
- let outputType: Type = (null as any);
43
+ let outputType: Type = null;
44
44
  if (context.expectedType && context.expectedType.kind !== 'value') {
45
45
  outputType = context.expectedType;
46
46
  }
@@ -27,7 +27,7 @@ class EvaluationContext {
27
27
  };
28
28
 
29
29
  constructor(scope?: string | null, options?: ConfigOptions | null) {
30
- this.globals = (null as any);
30
+ this.globals = null;
31
31
  this.feature = null;
32
32
  this.featureState = null;
33
33
  this.formattedSection = null;
@@ -40,7 +40,7 @@ class EvaluationContext {
40
40
  this.options = options;
41
41
  }
42
42
 
43
- id(): number | null {
43
+ id(): string | number | null {
44
44
  return this.feature && this.feature.id !== undefined ? this.feature.id : null;
45
45
  }
46
46
 
@@ -56,9 +56,7 @@ class EvaluationContext {
56
56
  return this.canonical;
57
57
  }
58
58
 
59
- properties(): {
60
- [key: string]: any;
61
- } {
59
+ properties(): {readonly [key: string]: unknown} {
62
60
  return (this.feature && this.feature.properties) || {};
63
61
  }
64
62
 
@@ -39,13 +39,9 @@ import type {ImageId} from './types/image_id';
39
39
 
40
40
  export interface Feature {
41
41
  readonly type: 0 | 1 | 2 | 3 | 'Unknown' | 'Point' | 'LineString' | 'Polygon';
42
- readonly id?: number | null;
43
- readonly properties: {
44
- [_: string]: any;
45
- };
46
- readonly patterns?: {
47
- [_: string]: string;
48
- };
42
+ readonly id?: string | number | null;
43
+ readonly properties: Record<PropertyKey, unknown>;
44
+ readonly patterns?: Record<PropertyKey, string>;
49
45
  readonly geometry?: Array<Array<Point>>;
50
46
  }
51
47
 
@@ -135,7 +131,7 @@ export class StyleExpression {
135
131
  throw new RuntimeError(`Expected value to be one of ${Object.keys(this._enumValues).map(v => JSON.stringify(v)).join(', ')}, but found ${JSON.stringify(val)} instead.`);
136
132
  }
137
133
  return val;
138
- } catch (e: any) {
134
+ } catch (e) {
139
135
  if (!this._warningHistory[e.message]) {
140
136
  this._warningHistory[e.message] = true;
141
137
  if (typeof console !== 'undefined') {
@@ -157,7 +157,7 @@ class ParsingContext {
157
157
  const ec = new EvaluationContext(this._scope, this.options);
158
158
  try {
159
159
  parsed = new Literal(parsed.type, parsed.evaluate(ec));
160
- } catch (e: any) {
160
+ } catch (e) {
161
161
  this.error(e.message);
162
162
  return null;
163
163
  }
@@ -1,5 +1,7 @@
1
1
  import type {Brand} from '../../types/brand';
2
2
 
3
+ const separator = '\u001F';
4
+
3
5
  export type ImageIdSpec = {
4
6
  name: string;
5
7
  iconsetId?: string;
@@ -35,16 +37,12 @@ export class ImageId {
35
37
  }
36
38
 
37
39
  static toString(id: ImageId | ImageIdSpec): StringifiedImageId {
38
- return JSON.stringify({name: id.name, iconsetId: id.iconsetId}) as StringifiedImageId;
40
+ return (id.iconsetId ? `${id.name}${separator}${id.iconsetId}` : id.name) as StringifiedImageId;
39
41
  }
40
42
 
41
43
  static parse(str: StringifiedImageId): ImageId | null {
42
- try {
43
- const {name, iconsetId} = JSON.parse(str);
44
- return new ImageId({name, iconsetId});
45
- } catch (e) {
46
- return null;
47
- }
44
+ const [name, iconsetId] = str.split(separator);
45
+ return new ImageId({name, iconsetId});
48
46
  }
49
47
 
50
48
  static isEqual(a: ImageId | ImageIdSpec, b: ImageId | ImageIdSpec): boolean {
@@ -52,7 +50,7 @@ export class ImageId {
52
50
  }
53
51
 
54
52
  toString(): StringifiedImageId {
55
- return JSON.stringify({name: this.name, iconsetId: this.iconsetId}) as StringifiedImageId;
53
+ return ImageId.toString(this);
56
54
  }
57
55
 
58
56
  serialize(): ImageIdSpec {
@@ -34,7 +34,7 @@ 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 | // eslint-disable-line no-use-before-define
37
+ export type Type = NullTypeT | NumberTypeT | StringTypeT | BooleanTypeT | ColorTypeT | ObjectTypeT | ValueTypeT |
38
38
  ArrayType | ErrorTypeT | CollatorTypeT | FormattedTypeT | ResolvedImageTypeT;
39
39
 
40
40
  export type ArrayType = {
@@ -51,9 +51,7 @@ export function validateHSLA(h: unknown, s: unknown, l: unknown, a?: unknown): s
51
51
  return null;
52
52
  }
53
53
 
54
- export type Value = null | string | boolean | number | Color | Collator | Formatted | ResolvedImage | ReadonlyArray<Value> | {
55
- readonly [key: string]: Value;
56
- };
54
+ export type Value = null | string | boolean | number | Color | Collator | Formatted | ResolvedImage | ReadonlyArray<Value> | {readonly [key: string]: Value};
57
55
 
58
56
  export function isValue(mixed: unknown): boolean {
59
57
  if (mixed === null) {
@@ -99,7 +99,7 @@ function createFilter(filter?: FilterSpecification, scope: string = "", options:
99
99
  let staticFilter = true;
100
100
  try {
101
101
  staticFilter = extractStaticFilter(filterExp);
102
- } catch (e: any) {
102
+ } catch (e) {
103
103
  console.warn(
104
104
  `Failed to extract static filter. Filter will continue working, but at higher memory usage and slower framerate.
105
105
  This is most likely a bug, please report this via https://github.com/mapbox/mapbox-gl-js/issues/new?assignees=&labels=&template=Bug_report.md
package/function/index.ts CHANGED
@@ -43,7 +43,7 @@ export function createFunction(parameters, propertySpec) {
43
43
  }
44
44
  }
45
45
 
46
- if (parameters.colorSpace && parameters.colorSpace !== 'rgb' && !colorSpaces[parameters.colorSpace]) { // eslint-disable-line import/namespace
46
+ if (parameters.colorSpace && parameters.colorSpace !== 'rgb' && !colorSpaces[parameters.colorSpace]) {
47
47
  throw new Error(`Unknown color space: ${parameters.colorSpace}`);
48
48
  }
49
49
 
@@ -175,10 +175,10 @@ function evaluateExponentialFunction(parameters, propertySpec, input) {
175
175
 
176
176
  const outputLower = parameters.stops[index][1];
177
177
  const outputUpper = parameters.stops[index + 1][1];
178
- let interp = interpolate[propertySpec.type] || identityFunction; // eslint-disable-line import/namespace
178
+ let interp = interpolate[propertySpec.type] || identityFunction;
179
179
 
180
180
  if (parameters.colorSpace && parameters.colorSpace !== 'rgb') {
181
- const colorspace = colorSpaces[parameters.colorSpace]; // eslint-disable-line import/namespace
181
+ const colorspace = colorSpaces[parameters.colorSpace];
182
182
  interp = (a, b) => colorspace.reverse(colorspace.interpolate(colorspace.forward(a), colorspace.forward(b), t));
183
183
  }
184
184
 
@@ -10,7 +10,7 @@ import type {StyleSpecification, FunctionSpecification} from '../types';
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): StyleSpecification {
13
+ export default function (style: StyleSpecification): StyleSpecification {
14
14
  const converted = [];
15
15
 
16
16
  eachLayer(style, (layer) => {
package/migrate/v8.ts CHANGED
@@ -34,7 +34,7 @@ function renameProperty(obj, from, to) {
34
34
  obj[to] = obj[from]; delete obj[from];
35
35
  }
36
36
 
37
- export default function(style) {
37
+ export default function (style) {
38
38
  style.version = 8;
39
39
 
40
40
  // Rename properties, reverse coordinates in source and layers
package/migrate/v9.ts CHANGED
@@ -8,7 +8,7 @@ function eachLayer(style, callback) {
8
8
  }
9
9
  }
10
10
 
11
- export default function(style) {
11
+ export default function (style) {
12
12
  style.version = 9;
13
13
 
14
14
  // remove user-specified refs
package/migrate.ts CHANGED
@@ -17,7 +17,7 @@ import migrateToExpressions from './migrate/expressions';
17
17
  * var style = fs.readFileSync('./style.json', 'utf8');
18
18
  * fs.writeFileSync('./style.json', JSON.stringify(migrate(style)));
19
19
  */
20
- export default function(style) {
20
+ export default function (style) {
21
21
  let migrated = false;
22
22
 
23
23
  if (style.version === 7) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapbox/mapbox-gl-style-spec",
3
- "version": "14.11.0-beta.2",
3
+ "version": "14.12.0-beta.1",
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
@@ -1,15 +1,13 @@
1
- /* eslint-disable @typescript-eslint/ban-ts-comment */
2
- // @ts-nocheck
3
-
4
1
  import ParsingError from './error/parsing_error';
5
2
  import jsonlint from '@mapbox/jsonlint-lines-primitives';
6
3
 
7
- export default function readStyle(style) {
4
+ import type {StyleSpecification} from './types';
5
+
6
+ export default function readStyle(style: string | Buffer | StyleSpecification): StyleSpecification {
8
7
  if (style instanceof String || typeof style === 'string' || ArrayBuffer.isView(style)) {
9
8
  try {
10
- // eslint-disable-next-line @typescript-eslint/no-base-to-string
11
9
  return jsonlint.parse(style.toString());
12
- } catch (e: any) {
10
+ } catch (e) {
13
11
  throw new ParsingError(e);
14
12
  }
15
13
  }