@mapbox/mapbox-gl-style-spec 14.11.0-beta.1 → 14.11.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.
@@ -1,80 +1,71 @@
1
- import {ImageIdWithOptions} from "./image_id_with_options";
1
+ import {ImageId} from './image_id';
2
+ import {ImageVariant} from './image_variant';
2
3
 
3
- import type Color from "../../util/color";
4
-
5
- export type RasterizationOptions = {
6
- params: Record<string, Color>;
7
- transform?: DOMMatrix;
8
- }
9
-
10
- export type ResolvedImageOptions = {
11
- namePrimary: string;
12
- optionsPrimary: RasterizationOptions | null | undefined;
13
- nameSecondary: string | null | undefined;
14
- optionsSecondary: RasterizationOptions | null | undefined;
15
- available: boolean;
16
- };
4
+ import type {ImageIdSpec} from './image_id';
5
+ import type {RasterizationOptions} from './image_variant';
17
6
 
18
7
  export default class ResolvedImage {
19
- namePrimary: string;
20
- optionsPrimary: RasterizationOptions | null | undefined;
21
- nameSecondary: string | null | undefined;
22
- optionsSecondary: RasterizationOptions | null | undefined;
8
+ primaryId: ImageId;
9
+ primaryOptions?: RasterizationOptions;
10
+ secondaryId?: ImageId;
11
+ secondaryOptions?: RasterizationOptions;
23
12
  available: boolean;
24
13
 
25
- constructor(options: ResolvedImageOptions) {
26
- this.namePrimary = options.namePrimary;
27
- if (options.nameSecondary) {
28
- this.nameSecondary = options.nameSecondary;
29
- }
30
- if (options.optionsPrimary) {
31
- this.optionsPrimary = options.optionsPrimary;
32
- }
33
- if (options.optionsSecondary) {
34
- this.optionsSecondary = options.optionsSecondary;
35
- }
36
- this.available = options.available;
14
+ constructor(
15
+ primaryId: string | ImageIdSpec,
16
+ primaryOptions?: RasterizationOptions,
17
+ secondaryId?: string | ImageIdSpec,
18
+ secondaryOptions?: RasterizationOptions,
19
+ available: boolean = false,
20
+ ) {
21
+ this.primaryId = ImageId.from(primaryId);
22
+ this.primaryOptions = primaryOptions;
23
+ if (secondaryId) this.secondaryId = ImageId.from(secondaryId);
24
+ this.secondaryOptions = secondaryOptions;
25
+ this.available = available;
37
26
  }
38
27
 
39
28
  toString(): string {
40
- if (this.namePrimary && this.nameSecondary) {
41
- return `[${this.namePrimary},${this.nameSecondary}]`;
29
+ if (this.primaryId && this.secondaryId) {
30
+ const primaryName = this.primaryId.name;
31
+ const secondaryName = this.secondaryId.name;
32
+ return `[${primaryName},${secondaryName}]`;
42
33
  }
43
34
 
44
- return this.namePrimary;
35
+ return this.primaryId.name;
36
+ }
37
+
38
+ hasPrimary(): boolean {
39
+ return !!this.primaryId;
45
40
  }
46
41
 
47
- getPrimary(): ImageIdWithOptions {
48
- return new ImageIdWithOptions(this.namePrimary, {
49
- params: this.optionsPrimary ? (this.optionsPrimary.params || {}) : {},
50
- });
42
+ getPrimary(): ImageVariant {
43
+ return new ImageVariant(this.primaryId, this.primaryOptions);
51
44
  }
52
45
 
53
- getSerializedPrimary(): string {
54
- return this.getPrimary().serialize();
46
+ hasSecondary(): boolean {
47
+ return !!this.secondaryId;
55
48
  }
56
49
 
57
- getSecondary(): ImageIdWithOptions | null {
58
- if (this.nameSecondary) {
59
- return new ImageIdWithOptions(this.nameSecondary, {
60
- params: this.optionsSecondary ? (this.optionsSecondary.params || {}) : {},
61
- });
50
+ getSecondary(): ImageVariant | null {
51
+ if (!this.secondaryId) {
52
+ return null;
62
53
  }
63
54
 
64
- return null;
55
+ return new ImageVariant(this.secondaryId, this.secondaryOptions);
65
56
  }
66
57
 
67
58
  static from(image: string | ResolvedImage): ResolvedImage {
68
- return typeof image === 'string' ? ResolvedImage.build(image) : image;
59
+ return typeof image === 'string' ? ResolvedImage.build({name: image}) : image;
69
60
  }
70
61
 
71
62
  static build(
72
- namePrimary: string,
73
- nameSecondary?: string | null,
74
- optionsPrimary?: RasterizationOptions | null,
75
- optionsSecondary?: RasterizationOptions | null
63
+ primaryId: string | ImageIdSpec,
64
+ secondaryId?: string | ImageIdSpec,
65
+ primaryOptions?: RasterizationOptions,
66
+ secondaryOptions?: RasterizationOptions
76
67
  ): ResolvedImage | null {
77
- if (!namePrimary) return null; // treat empty values as no image
78
- return new ResolvedImage({namePrimary, nameSecondary, optionsPrimary, optionsSecondary, available: false});
68
+ if (!primaryId || (typeof primaryId === 'object' && !('name' in primaryId))) return null; // treat empty values as no image
69
+ return new ResolvedImage(primaryId, primaryOptions, secondaryId, secondaryOptions);
79
70
  }
80
71
  }
@@ -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 = {
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapbox/mapbox-gl-style-spec",
3
- "version": "14.11.0-beta.1",
3
+ "version": "14.11.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
@@ -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
  }
package/reference/v8.json CHANGED
@@ -146,6 +146,7 @@
146
146
  "doc": "A collection of icon sets",
147
147
  "sdk-support": {
148
148
  "basic functionality": {
149
+ "js": "3.11.0",
149
150
  "android": "11.11.0",
150
151
  "ios": "11.11.0"
151
152
  }
@@ -4101,7 +4102,7 @@
4101
4102
  }
4102
4103
  },
4103
4104
  "config": {
4104
- "doc": "Retrieves the configuration value for the given option.",
4105
+ "doc": "Retrieves the configuration value for the given option. Returns null if the requested option is missing.",
4105
4106
  "group": "Lookup",
4106
4107
  "sdk-support": {
4107
4108
  "basic functionality": {
package/test.js CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env node
2
- /* eslint-disable no-process-exit */
3
2
 
4
3
  import fs from 'fs';
5
4
  import {execSync} from 'child_process';
package/types/brand.ts ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Defines nominal type of `U` based on type of `T`. Similar to Opaque types in Flow.
3
+ */
4
+ export type Brand<T, U> = T & {__brand: U};
@@ -18,3 +18,7 @@ export function array(from: Array<number>, to: Array<number>, t: number): Array<
18
18
  return number(d, to[i], t);
19
19
  });
20
20
  }
21
+
22
+ export function easeIn (x: number) {
23
+ return x * x * x * x * x;
24
+ }
@@ -3,6 +3,7 @@ import latestStyleSpec from '../reference/latest';
3
3
  import validateGlyphsURL from './validate_glyphs_url';
4
4
 
5
5
  import type ValidationError from '../error/validation_error';
6
+ import type {StyleReference} from '../reference/latest';
6
7
  import type {ValidationOptions} from './validate';
7
8
  import type {StyleSpecification} from '../types';
8
9
 
@@ -12,7 +13,7 @@ type StyleValidationOptions = {
12
13
 
13
14
  export default function validateStyle(
14
15
  style: StyleSpecification,
15
- styleSpec: any = latestStyleSpec,
16
+ styleSpec: StyleReference = latestStyleSpec,
16
17
  options: StyleValidationOptions = {},
17
18
  ): ValidationError[] {
18
19
  const errors = validate({
@@ -13,6 +13,7 @@ import _validatePaintProperty from './validate/validate_paint_property';
13
13
  import _validateLayoutProperty from './validate/validate_layout_property';
14
14
  import _validateModel from './validate/validate_model';
15
15
 
16
+ import type {StyleReference} from './reference/latest';
16
17
  import type {StyleSpecification} from './types';
17
18
 
18
19
  export type ValidationError = {
@@ -20,8 +21,9 @@ export type ValidationError = {
20
21
  identifier?: string | null | undefined;
21
22
  line?: number | null | undefined;
22
23
  };
24
+
23
25
  export type ValidationErrors = ReadonlyArray<ValidationError>;
24
- export type Validator = (arg1: any) => ValidationErrors;
26
+ export type Validator<T extends (...args: unknown[]) => unknown = (...args: unknown[]) => unknown> = (...args: Parameters<T>) => ValidationErrors;
25
27
 
26
28
  /**
27
29
  * Validate a Mapbox GL style against the style specification. This entrypoint,
@@ -38,24 +40,24 @@ export type Validator = (arg1: any) => ValidationErrors;
38
40
  * var validate = require('mapbox-gl-style-spec/lib/validate_style.min');
39
41
  * var errors = validate(style);
40
42
  */
41
- export function validateStyle(style: StyleSpecification, styleSpec: any = latestStyleSpec): ValidationErrors {
43
+ export function validateStyle(style: StyleSpecification, styleSpec: StyleReference = latestStyleSpec): ValidationErrors {
42
44
  const errors = _validateStyle(style, styleSpec);
43
45
  return sortErrors(errors);
44
46
  }
45
47
 
46
- export const validateSource: Validator = opts => sortErrors(_validateSource(opts));
47
- export const validateLight: Validator = opts => sortErrors(_validateLight(opts));
48
- export const validateLights: Validator = opts => sortErrors(_validateLights(opts));
49
- export const validateTerrain: Validator = opts => sortErrors(_validateTerrain(opts));
50
- export const validateFog: Validator = opts => sortErrors(_validateFog(opts));
51
- export const validateSnow: Validator = opts => sortErrors(_validateSnow(opts));
52
- export const validateRain: Validator = opts => sortErrors(_validateRain(opts));
53
- export const validateLayer: Validator = opts => sortErrors(_validateLayer(opts));
54
- export const validateFilter: Validator = opts => sortErrors(_validateFilter(opts));
55
- export const validatePaintProperty: Validator = opts => sortErrors(_validatePaintProperty(opts));
56
- export const validateLayoutProperty: Validator = opts => sortErrors(_validateLayoutProperty(opts));
57
- export const validateModel: Validator = opts => sortErrors(_validateModel(opts));
48
+ export const validateSource: Validator<typeof _validateSource> = opts => sortErrors(_validateSource(opts));
49
+ export const validateLight: Validator<typeof _validateLight> = opts => sortErrors(_validateLight(opts));
50
+ export const validateLights: Validator<typeof _validateLights> = opts => sortErrors(_validateLights(opts));
51
+ export const validateTerrain: Validator<typeof _validateTerrain> = opts => sortErrors(_validateTerrain(opts));
52
+ export const validateFog: Validator<typeof _validateFog> = opts => sortErrors(_validateFog(opts));
53
+ export const validateSnow: Validator<typeof _validateSnow> = opts => sortErrors(_validateSnow(opts));
54
+ export const validateRain: Validator<typeof _validateRain> = opts => sortErrors(_validateRain(opts));
55
+ export const validateLayer: Validator<typeof _validateLayer> = opts => sortErrors(_validateLayer(opts));
56
+ export const validateFilter: Validator<typeof _validateFilter> = opts => sortErrors(_validateFilter(opts));
57
+ export const validatePaintProperty: Validator<typeof _validatePaintProperty> = opts => sortErrors(_validatePaintProperty(opts));
58
+ export const validateLayoutProperty: Validator<typeof _validateLayoutProperty> = opts => sortErrors(_validateLayoutProperty(opts));
59
+ export const validateModel: Validator<typeof _validateModel> = opts => sortErrors(_validateModel(opts));
58
60
 
59
- function sortErrors(errors: ValidationErrors) {
61
+ function sortErrors(errors: ValidationErrors): ValidationErrors {
60
62
  return errors.slice().sort((a, b) => a.line && b.line ? a.line - b.line : 0);
61
63
  }
package/validate_style.ts CHANGED
@@ -2,6 +2,7 @@ import {validateStyle as validateStyleMin} from './validate_style.min';
2
2
  import {v8} from './style-spec';
3
3
  import readStyle from './read_style';
4
4
 
5
+ import type {StyleReference} from './reference/latest';
5
6
  import type {ValidationErrors} from './validate_style.min';
6
7
  import type {StyleSpecification} from './types';
7
8
 
@@ -21,16 +22,15 @@ import type {StyleSpecification} from './types';
21
22
  * var errors = validate(style);
22
23
  */
23
24
 
24
- export default function validateStyle(style: StyleSpecification | string | Buffer, styleSpec: any = v8): ValidationErrors {
25
+ export default function validateStyle(style: StyleSpecification | string | Buffer, styleSpec: StyleReference = v8): ValidationErrors {
25
26
  let s = style;
26
27
 
27
28
  try {
28
29
  s = readStyle(s);
29
- } catch (e: any) {
30
+ } catch (e) {
30
31
  return [e];
31
32
  }
32
33
 
33
- // @ts-expect-error - TS2345 - Argument of type 'string | StyleSpecification | Buffer' is not assignable to parameter of type 'StyleSpecification'.
34
34
  return validateStyleMin(s, styleSpec);
35
35
  }
36
36
 
@@ -1,58 +0,0 @@
1
- import type {RasterizationOptions} from "./resolved_image";
2
-
3
- export class ImageIdWithOptions {
4
- id: string;
5
- options: RasterizationOptions;
6
-
7
- constructor(id: string, options?: RasterizationOptions) {
8
- this.id = id;
9
- this.options = options || {params: {}};
10
-
11
- if (!this.options.transform) {
12
- this.options.transform = new DOMMatrix([1, 0, 0, 1, 0, 0]);
13
- } else {
14
- const {a, b, c, d, e, f} = this.options.transform;
15
- this.options.transform = new DOMMatrix([a, b, c, d, e, f]);
16
- }
17
- }
18
-
19
- static deserializeId(serialized: string): string {
20
- return JSON.parse(serialized).id;
21
- }
22
-
23
- static deserializeFromString(serialized: string): ImageIdWithOptions {
24
- const deserializedObject = JSON.parse(serialized);
25
- const options: RasterizationOptions = {params: deserializedObject.options.params};
26
-
27
- const {a, b, c, d, e, f} = deserializedObject.options.transform;
28
-
29
- options.transform = new DOMMatrix([a, b, c, d, e, f]);
30
-
31
- return new ImageIdWithOptions(deserializedObject.id, deserializedObject.options);
32
- }
33
-
34
- scaleSelf(factor: number): this {
35
- this.options.transform = this.options.transform.scale(factor);
36
- return this;
37
- }
38
-
39
- serialize(): string {
40
- const serialisedObject: Record<string, any> = {
41
- id: this.id,
42
- };
43
-
44
- if (this.options) {
45
- serialisedObject.options = this.options;
46
- }
47
-
48
- const {
49
- a, b, c, d, e, f,
50
- } = this.options.transform;
51
-
52
- serialisedObject.options.transform = {
53
- a, b, c, d, e, f,
54
- };
55
-
56
- return JSON.stringify(serialisedObject);
57
- }
58
- }