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

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
  }
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-beta.2",
4
4
  "description": "a specification for mapbox gl styles",
5
5
  "author": "Mapbox",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
package/reference/v8.json CHANGED
@@ -4101,7 +4101,7 @@
4101
4101
  }
4102
4102
  },
4103
4103
  "config": {
4104
- "doc": "Retrieves the configuration value for the given option.",
4104
+ "doc": "Retrieves the configuration value for the given option. Returns null if the requested option is missing.",
4105
4105
  "group": "Lookup",
4106
4106
  "sdk-support": {
4107
4107
  "basic functionality": {
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};
@@ -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
- }