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