@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.
package/dist/index.cjs CHANGED
@@ -3923,7 +3923,7 @@
3923
3923
  }
3924
3924
  },
3925
3925
  config: {
3926
- doc: "Retrieves the configuration value for the given option.",
3926
+ doc: "Retrieves the configuration value for the given option. Returns null if the requested option is missing.",
3927
3927
  group: "Lookup",
3928
3928
  "sdk-support": {
3929
3929
  "basic functionality": {
@@ -12447,7 +12447,13 @@
12447
12447
  isEmpty() {
12448
12448
  if (this.sections.length === 0)
12449
12449
  return true;
12450
- return !this.sections.some(section => section.text.length !== 0 || section.image && section.image.namePrimary);
12450
+ return !this.sections.some(section => {
12451
+ if (section.text.length !== 0)
12452
+ return true;
12453
+ if (!section.image)
12454
+ return false;
12455
+ return section.image.hasPrimary();
12456
+ });
12451
12457
  }
12452
12458
  static factory(text) {
12453
12459
  if (text instanceof Formatted) {
@@ -12465,9 +12471,10 @@
12465
12471
  const serialized = ['format'];
12466
12472
  for (const section of this.sections) {
12467
12473
  if (section.image) {
12474
+ const primaryId = section.image.getPrimary().id.toString();
12468
12475
  serialized.push([
12469
12476
  'image',
12470
- section.image.namePrimary
12477
+ primaryId
12471
12478
  ]);
12472
12479
  continue;
12473
12480
  }
@@ -12491,11 +12498,57 @@
12491
12498
  }
12492
12499
  }
12493
12500
 
12494
- class ImageIdWithOptions {
12495
- constructor(id, options) {
12496
- this.id = id;
12497
- this.options = options || { params: {} };
12498
- if (!this.options.transform) {
12501
+ class ImageId {
12502
+ constructor(id) {
12503
+ if (typeof id === 'string') {
12504
+ this.name = id;
12505
+ } else {
12506
+ this.name = id.name;
12507
+ this.iconsetId = id.iconsetId;
12508
+ }
12509
+ }
12510
+ static from(id) {
12511
+ return new ImageId(id);
12512
+ }
12513
+ static toString(id) {
12514
+ return JSON.stringify({
12515
+ name: id.name,
12516
+ iconsetId: id.iconsetId
12517
+ });
12518
+ }
12519
+ static parse(str) {
12520
+ try {
12521
+ const {name, iconsetId} = JSON.parse(str);
12522
+ return new ImageId({
12523
+ name,
12524
+ iconsetId
12525
+ });
12526
+ } catch (e) {
12527
+ return null;
12528
+ }
12529
+ }
12530
+ static isEqual(a, b) {
12531
+ return a.name === b.name && a.iconsetId === b.iconsetId;
12532
+ }
12533
+ toString() {
12534
+ return JSON.stringify({
12535
+ name: this.name,
12536
+ iconsetId: this.iconsetId
12537
+ });
12538
+ }
12539
+ serialize() {
12540
+ return {
12541
+ name: this.name,
12542
+ iconsetId: this.iconsetId
12543
+ };
12544
+ }
12545
+ }
12546
+
12547
+ class ImageVariant {
12548
+ constructor(id, options = {}) {
12549
+ this.id = ImageId.from(id);
12550
+ this.options = Object.assign({}, options);
12551
+ if (!options.transform) {
12499
12552
  this.options.transform = new DOMMatrix([
12500
12553
  1,
12501
12554
  0,
@@ -12505,7 +12558,7 @@
12505
12558
  0
12506
12559
  ]);
12507
12560
  } else {
12508
- const {a, b, c, d, e, f} = this.options.transform;
12561
+ const {a, b, c, d, e, f} = options.transform;
12509
12562
  this.options.transform = new DOMMatrix([
12510
12563
  a,
12511
12564
  b,
@@ -12516,90 +12569,93 @@
12516
12569
  ]);
12517
12570
  }
12518
12571
  }
12519
- static deserializeId(serialized) {
12520
- return JSON.parse(serialized).id;
12572
+ toString() {
12573
+ const {a, b, c, d, e, f} = this.options.transform;
12574
+ const serialized = {
12575
+ name: this.id.name,
12576
+ iconsetId: this.id.iconsetId,
12577
+ params: this.options.params,
12578
+ transform: {
12579
+ a,
12580
+ b,
12581
+ c,
12582
+ d,
12583
+ e,
12584
+ f
12585
+ }
12586
+ };
12587
+ return JSON.stringify(serialized);
12521
12588
  }
12522
- static deserializeFromString(serialized) {
12523
- const deserializedObject = JSON.parse(serialized);
12524
- ({ params: deserializedObject.options.params });
12525
- const {a, b, c, d, e, f} = deserializedObject.options.transform;
12526
- new DOMMatrix([
12527
- a,
12528
- b,
12529
- c,
12530
- d,
12531
- e,
12532
- f
12533
- ]);
12534
- return new ImageIdWithOptions(deserializedObject.id, deserializedObject.options);
12589
+ static parse(str) {
12590
+ let name, iconsetId, params, transform;
12591
+ try {
12592
+ ({name, iconsetId, params, transform} = JSON.parse(str) || {});
12593
+ } catch (e2) {
12594
+ return null;
12595
+ }
12596
+ if (!name)
12597
+ return null;
12598
+ const {a, b, c, d, e, f} = transform || {};
12599
+ return new ImageVariant({
12600
+ name,
12601
+ iconsetId
12602
+ }, {
12603
+ params,
12604
+ transform: new DOMMatrix([
12605
+ a,
12606
+ b,
12607
+ c,
12608
+ d,
12609
+ e,
12610
+ f
12611
+ ])
12612
+ });
12535
12613
  }
12536
12614
  scaleSelf(factor) {
12537
- this.options.transform = this.options.transform.scale(factor);
12615
+ this.options.transform.scaleSelf(factor);
12538
12616
  return this;
12539
12617
  }
12540
- serialize() {
12541
- const serialisedObject = { id: this.id };
12542
- if (this.options) {
12543
- serialisedObject.options = this.options;
12544
- }
12545
- const {a, b, c, d, e, f} = this.options.transform;
12546
- serialisedObject.options.transform = {
12547
- a,
12548
- b,
12549
- c,
12550
- d,
12551
- e,
12552
- f
12553
- };
12554
- return JSON.stringify(serialisedObject);
12555
- }
12556
12618
  }
12557
12619
 
12558
12620
  class ResolvedImage {
12559
- constructor(options) {
12560
- this.namePrimary = options.namePrimary;
12561
- if (options.nameSecondary) {
12562
- this.nameSecondary = options.nameSecondary;
12563
- }
12564
- if (options.optionsPrimary) {
12565
- this.optionsPrimary = options.optionsPrimary;
12566
- }
12567
- if (options.optionsSecondary) {
12568
- this.optionsSecondary = options.optionsSecondary;
12569
- }
12570
- this.available = options.available;
12621
+ constructor(primaryId, primaryOptions, secondaryId, secondaryOptions, available = false) {
12622
+ this.primaryId = ImageId.from(primaryId);
12623
+ this.primaryOptions = primaryOptions;
12624
+ if (secondaryId)
12625
+ this.secondaryId = ImageId.from(secondaryId);
12626
+ this.secondaryOptions = secondaryOptions;
12627
+ this.available = available;
12571
12628
  }
12572
12629
  toString() {
12573
- if (this.namePrimary && this.nameSecondary) {
12574
- return `[${ this.namePrimary },${ this.nameSecondary }]`;
12630
+ if (this.primaryId && this.secondaryId) {
12631
+ const primaryName = this.primaryId.name;
12632
+ const secondaryName = this.secondaryId.name;
12633
+ return `[${ primaryName },${ secondaryName }]`;
12575
12634
  }
12576
- return this.namePrimary;
12635
+ return this.primaryId.name;
12636
+ }
12637
+ hasPrimary() {
12638
+ return !!this.primaryId;
12577
12639
  }
12578
12640
  getPrimary() {
12579
- return new ImageIdWithOptions(this.namePrimary, { params: this.optionsPrimary ? this.optionsPrimary.params || {} : {} });
12641
+ return new ImageVariant(this.primaryId, this.primaryOptions);
12580
12642
  }
12581
- getSerializedPrimary() {
12582
- return this.getPrimary().serialize();
12643
+ hasSecondary() {
12644
+ return !!this.secondaryId;
12583
12645
  }
12584
12646
  getSecondary() {
12585
- if (this.nameSecondary) {
12586
- return new ImageIdWithOptions(this.nameSecondary, { params: this.optionsSecondary ? this.optionsSecondary.params || {} : {} });
12647
+ if (!this.secondaryId) {
12648
+ return null;
12587
12649
  }
12588
- return null;
12650
+ return new ImageVariant(this.secondaryId, this.secondaryOptions);
12589
12651
  }
12590
12652
  static from(image) {
12591
- return typeof image === 'string' ? ResolvedImage.build(image) : image;
12653
+ return typeof image === 'string' ? ResolvedImage.build({ name: image }) : image;
12592
12654
  }
12593
- static build(namePrimary, nameSecondary, optionsPrimary, optionsSecondary) {
12594
- if (!namePrimary)
12655
+ static build(primaryId, secondaryId, primaryOptions, secondaryOptions) {
12656
+ if (!primaryId || typeof primaryId === 'object' && !('name' in primaryId))
12595
12657
  return null;
12596
- return new ResolvedImage({
12597
- namePrimary,
12598
- nameSecondary,
12599
- optionsPrimary,
12600
- optionsSecondary,
12601
- available: false
12602
- });
12658
+ return new ResolvedImage(primaryId, primaryOptions, secondaryId, secondaryOptions);
12603
12659
  }
12604
12660
  }
12605
12661
 
@@ -12993,19 +13049,22 @@
12993
13049
  }
12994
13050
 
12995
13051
  function isImageOptions(value) {
12996
- if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
12997
- return true;
12998
- }
12999
- return false;
13052
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
13000
13053
  }
13001
13054
  class ImageExpression {
13002
- constructor(inputPrimary, inputSecondary, inputPrimaryParams, inputSecondaryParams) {
13055
+ constructor(inputPrimary, inputSecondary, inputPrimaryOptions, inputSecondaryOptions) {
13003
13056
  this._imageWarnHistory = {};
13004
13057
  this.type = ResolvedImageType;
13005
- this.inputPrimary = inputPrimary;
13006
- this.inputSecondary = inputSecondary;
13007
- this.inputPrimaryParams = inputPrimaryParams;
13008
- this.inputSecondaryParams = inputSecondaryParams;
13058
+ this.namePrimary = inputPrimary;
13059
+ this.nameSecondary = inputSecondary;
13060
+ if (inputPrimaryOptions) {
13061
+ this.paramsPrimary = inputPrimaryOptions.params;
13062
+ this.iconsetIdPrimary = inputPrimaryOptions.iconset ? inputPrimaryOptions.iconset.id : void 0;
13063
+ }
13064
+ if (inputSecondaryOptions) {
13065
+ this.paramsSecondary = inputSecondaryOptions.params;
13066
+ this.iconsetIdSecondary = inputSecondaryOptions.iconset ? inputSecondaryOptions.iconset.id : void 0;
13067
+ }
13009
13068
  }
13010
13069
  static parse(args, context) {
13011
13070
  if (args.length < 2) {
@@ -13022,7 +13081,7 @@
13022
13081
  }
13023
13082
  imageExpression.push({
13024
13083
  image: imageName,
13025
- options: void 0
13084
+ options: {}
13026
13085
  });
13027
13086
  return true;
13028
13087
  }
@@ -13030,33 +13089,48 @@
13030
13089
  }
13031
13090
  function tryParseOptions() {
13032
13091
  if (nextArgId < args.length) {
13033
- if (!isImageOptions(args[nextArgId])) {
13092
+ const options = args[nextArgId];
13093
+ if (!isImageOptions(options)) {
13034
13094
  return true;
13035
13095
  }
13036
- const params = args[nextArgId].params;
13096
+ const params = options.params;
13097
+ const iconset = options.iconset;
13037
13098
  const optionsContext = context.concat(nextArgId);
13038
- if (!params) {
13099
+ if (!params && !iconset) {
13039
13100
  nextArgId++;
13040
13101
  return true;
13041
13102
  }
13042
- if (typeof params !== 'object' || params.constructor !== Object) {
13043
- optionsContext.error(`Image options "params" should be an object`);
13044
- return false;
13103
+ if (params) {
13104
+ if (typeof params !== 'object' || params.constructor !== Object) {
13105
+ optionsContext.error(`Image options "params" should be an object`);
13106
+ return false;
13107
+ }
13108
+ const parsedParams = {};
13109
+ const childContext = optionsContext.concat(void 0, 'params');
13110
+ for (const key in params) {
13111
+ if (!key) {
13112
+ childContext.error(`Image parameter name should be non-empty`);
13113
+ return false;
13114
+ }
13115
+ const value = childContext.concat(void 0, key).parse(params[key], void 0, ColorType, void 0, { typeAnnotation: 'coerce' });
13116
+ if (!value) {
13117
+ return false;
13118
+ }
13119
+ parsedParams[key] = value;
13120
+ }
13121
+ imageExpression[imageExpression.length - 1].options.params = parsedParams;
13045
13122
  }
13046
- const parsed = {};
13047
- const childContext = optionsContext.concat(void 0, 'params');
13048
- for (const key in params) {
13049
- if (!key) {
13050
- childContext.error(`Image parameter name should be non-empty`);
13123
+ if (iconset) {
13124
+ if (typeof iconset !== 'object' || iconset.constructor !== Object) {
13125
+ optionsContext.error(`Image options "iconset" should be an object`);
13051
13126
  return false;
13052
13127
  }
13053
- const value = childContext.concat(void 0, key).parse(params[key], void 0, ColorType, void 0, { typeAnnotation: 'coerce' });
13054
- if (!value) {
13128
+ if (!iconset.id) {
13129
+ optionsContext.error(`Image options "iconset" should have an "id" property`);
13055
13130
  return false;
13056
13131
  }
13057
- parsed[key] = value;
13132
+ imageExpression[imageExpression.length - 1].options.iconset = iconset;
13058
13133
  }
13059
- imageExpression[imageExpression.length - 1].options = parsed;
13060
13134
  nextArgId++;
13061
13135
  return true;
13062
13136
  }
@@ -13099,30 +13173,41 @@
13099
13173
  return { params: result };
13100
13174
  }
13101
13175
  evaluate(ctx) {
13102
- const value = ResolvedImage.build(this.inputPrimary.evaluate(ctx), this.inputSecondary ? this.inputSecondary.evaluate(ctx) : void 0, this.inputPrimaryParams ? this.evaluateParams(ctx, this.inputPrimaryParams) : void 0, this.inputSecondaryParams ? this.evaluateParams(ctx, this.inputSecondaryParams) : void 0);
13176
+ const primaryId = {
13177
+ name: this.namePrimary.evaluate(ctx),
13178
+ iconsetId: this.iconsetIdPrimary
13179
+ };
13180
+ const secondaryId = this.nameSecondary ? {
13181
+ name: this.nameSecondary.evaluate(ctx),
13182
+ iconsetId: this.iconsetIdSecondary
13183
+ } : void 0;
13184
+ const value = ResolvedImage.build(primaryId, secondaryId, this.paramsPrimary ? this.evaluateParams(ctx, this.paramsPrimary) : void 0, this.paramsSecondary ? this.evaluateParams(ctx, this.paramsSecondary) : void 0);
13103
13185
  if (value && ctx.availableImages) {
13104
- value.available = ctx.availableImages.indexOf(value.namePrimary) > -1;
13105
- if (value.nameSecondary && value.available && ctx.availableImages) {
13106
- value.available = ctx.availableImages.indexOf(value.nameSecondary) > -1;
13186
+ const primaryId2 = value.getPrimary().id;
13187
+ value.available = ctx.availableImages.some(id => ImageId.isEqual(id, primaryId2));
13188
+ if (value.available) {
13189
+ const secondaryId2 = value.getSecondary() ? value.getSecondary().id : null;
13190
+ if (secondaryId2)
13191
+ value.available = ctx.availableImages.some(id => ImageId.isEqual(id, secondaryId2));
13107
13192
  }
13108
13193
  }
13109
13194
  return value;
13110
13195
  }
13111
13196
  eachChild(fn) {
13112
- fn(this.inputPrimary);
13113
- if (this.inputPrimaryParams) {
13114
- for (const key in this.inputPrimaryParams) {
13115
- if (this.inputPrimaryParams[key]) {
13116
- fn(this.inputPrimaryParams[key]);
13197
+ fn(this.namePrimary);
13198
+ if (this.paramsPrimary) {
13199
+ for (const key in this.paramsPrimary) {
13200
+ if (this.paramsPrimary[key]) {
13201
+ fn(this.paramsPrimary[key]);
13117
13202
  }
13118
13203
  }
13119
13204
  }
13120
- if (this.inputSecondary) {
13121
- fn(this.inputSecondary);
13122
- if (this.inputSecondaryParams) {
13123
- for (const key in this.inputSecondaryParams) {
13124
- if (this.inputSecondaryParams[key]) {
13125
- fn(this.inputSecondaryParams[key]);
13205
+ if (this.nameSecondary) {
13206
+ fn(this.nameSecondary);
13207
+ if (this.paramsSecondary) {
13208
+ for (const key in this.paramsSecondary) {
13209
+ if (this.paramsSecondary[key]) {
13210
+ fn(this.paramsSecondary[key]);
13126
13211
  }
13127
13212
  }
13128
13213
  }
@@ -13131,31 +13216,37 @@
13131
13216
  outputDefined() {
13132
13217
  return false;
13133
13218
  }
13134
- serializeParams(params) {
13219
+ serializeOptions(params, iconsetId) {
13135
13220
  const result = {};
13221
+ if (iconsetId) {
13222
+ result.iconset = { id: iconsetId };
13223
+ }
13136
13224
  if (params) {
13225
+ result.params = {};
13137
13226
  for (const key in params) {
13138
13227
  if (params[key]) {
13139
- result[key] = params[key].serialize();
13228
+ result.params[key] = params[key].serialize();
13140
13229
  }
13141
13230
  }
13142
- } else {
13143
- return void 0;
13144
13231
  }
13145
- return { params: result };
13232
+ return Object.keys(result).length > 0 ? result : void 0;
13146
13233
  }
13147
13234
  serialize() {
13148
13235
  const serialized = [
13149
13236
  'image',
13150
- this.inputPrimary.serialize()
13237
+ this.namePrimary.serialize()
13151
13238
  ];
13152
- if (this.inputPrimaryParams) {
13153
- serialized.push(this.serializeParams(this.inputPrimaryParams));
13239
+ if (this.paramsPrimary || this.iconsetIdPrimary) {
13240
+ const options = this.serializeOptions(this.paramsPrimary, this.iconsetIdPrimary);
13241
+ if (options)
13242
+ serialized.push(options);
13154
13243
  }
13155
- if (this.inputSecondary) {
13156
- serialized.push(this.inputSecondary.serialize());
13157
- if (this.inputSecondaryParams) {
13158
- serialized.push(this.serializeParams(this.inputSecondaryParams));
13244
+ if (this.nameSecondary) {
13245
+ serialized.push(this.nameSecondary.serialize());
13246
+ if (this.paramsSecondary || this.iconsetIdSecondary) {
13247
+ const options = this.serializeOptions(this.paramsSecondary, this.iconsetIdSecondary);
13248
+ if (options)
13249
+ serialized.push(options);
13159
13250
  }
13160
13251
  }
13161
13252
  return serialized;