@mapbox/mapbox-gl-style-spec 14.11.0 → 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.
package/diff.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import isEqual from './util/deep_equal';
2
2
 
3
- import type {StyleSpecification, ImportSpecification, SourceSpecification, LayerSpecification} from './types';
3
+ import type {StyleSpecification, ImportSpecification, SourceSpecification, LayerSpecification, IconsetsSpecification} from './types';
4
4
 
5
5
  type Sources = {
6
6
  [key: string]: SourceSpecification;
@@ -11,9 +11,7 @@ type Command = {
11
11
  args: Array<any>;
12
12
  };
13
13
 
14
- export const operations: {
15
- [_: string]: string;
16
- } = {
14
+ export const operations = {
17
15
 
18
16
  /*
19
17
  * { command: 'setStyle', args: [stylesheet] }
@@ -163,8 +161,18 @@ export const operations: {
163
161
  /**
164
162
  * { command: 'updateImport', args: [importId, importSpecification | styleUrl] }
165
163
  */
166
- updateImport: 'updateImport'
167
- };
164
+ updateImport: 'updateImport',
165
+
166
+ /*
167
+ * { command: 'addIconset', args: [iconsetId, IconsetSpecification] }
168
+ */
169
+ addIconset: 'addIconset',
170
+
171
+ /*
172
+ * { command: 'removeIconset', args: [iconsetId] }
173
+ */
174
+ removeIconset: 'removeIconset'
175
+ } as const;
168
176
 
169
177
  function addSource(sourceId: string, after: Sources, commands: Array<Command>) {
170
178
  commands.push({command: operations.addSource, args: [sourceId, after[sourceId]]});
@@ -201,9 +209,7 @@ function canUpdateGeoJSON(before: Sources, after: Sources, sourceId: string) {
201
209
  return true;
202
210
  }
203
211
 
204
- function diffSources(before: Sources, after: Sources, commands: Array<Command>, sourcesRemoved: {
205
- [key: string]: true;
206
- }) {
212
+ function diffSources(before: Sources, after: Sources, commands: Array<Command>, sourcesRemoved: {[key: string]: true}) {
207
213
  before = before || {};
208
214
  after = after || {};
209
215
 
@@ -446,6 +452,33 @@ export function diffImports(before: Array<ImportSpecification> | null | undefine
446
452
  }
447
453
  }
448
454
 
455
+ function diffIconsets(before: IconsetsSpecification, after: IconsetsSpecification, commands: Array<Command>) {
456
+ before = before || {};
457
+ after = after || {};
458
+
459
+ let iconsetId;
460
+
461
+ // look for iconsets to remove
462
+ for (iconsetId in before) {
463
+ if (!before.hasOwnProperty(iconsetId)) continue;
464
+ if (!after.hasOwnProperty(iconsetId)) {
465
+ commands.push({command: operations.removeIconset, args: [iconsetId]});
466
+ }
467
+ }
468
+
469
+ // look for iconsets to add/update
470
+ for (iconsetId in after) {
471
+ if (!after.hasOwnProperty(iconsetId)) continue;
472
+ const iconset = after[iconsetId];
473
+ if (!before.hasOwnProperty(iconsetId)) {
474
+ commands.push({command: operations.addIconset, args: [iconsetId, iconset]});
475
+ } else if (!isEqual(before[iconsetId], iconset)) {
476
+ commands.push({command: operations.removeIconset, args: [iconsetId]});
477
+ commands.push({command: operations.addIconset, args: [iconsetId, iconset]});
478
+ }
479
+ }
480
+ }
481
+
449
482
  /**
450
483
  * Diff two stylesheet
451
484
  *
@@ -520,6 +553,9 @@ export default function diffStyles(before: StyleSpecification, after: StyleSpeci
520
553
  if (!isEqual(before.camera, after.camera)) {
521
554
  commands.push({command: operations.setCamera, args: [after.camera]});
522
555
  }
556
+ if (!isEqual(before.iconsets, after.iconsets)) {
557
+ diffIconsets(before.iconsets, after.iconsets, commands);
558
+ }
523
559
  if (!isEqual(before["color-theme"], after["color-theme"])) {
524
560
  // Update this to setColorTheme after
525
561
  // https://mapbox.atlassian.net/browse/GLJS-842 is implemented
@@ -529,7 +565,7 @@ export default function diffStyles(before: StyleSpecification, after: StyleSpeci
529
565
  // Handle changes to `sources`
530
566
  // If a source is to be removed, we also--before the removeSource
531
567
  // command--need to remove all the style layers that depend on it.
532
- const sourcesRemoved: Record<string, any> = {};
568
+ const sourcesRemoved: Record<string, true> = {};
533
569
 
534
570
  // First collect the {add,remove}Source commands
535
571
  const removeOrAddSourceCommands = [];
@@ -570,7 +606,7 @@ export default function diffStyles(before: StyleSpecification, after: StyleSpeci
570
606
 
571
607
  // Handle changes to `layers`
572
608
  diffLayers(beforeLayers, after.layers, commands);
573
- } catch (e: any) {
609
+ } catch (e) {
574
610
  // fall back to setStyle
575
611
  console.warn('Unable to compute style diff:', e);
576
612
  commands = [{command: operations.setStyle, args: [after]}];