@mapbox/mapbox-gl-style-spec 13.24.0-alpha.3 → 13.24.0-alpha.6

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.
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable no-process-exit */
3
+ /* eslint import/no-unresolved: [error, { ignore: ['^@mapbox/mapbox-gl-style-spec$'] }] */
4
+
5
+ import fs from 'fs';
6
+ import minimist from 'minimist';
7
+ import {format, composite} from '@mapbox/mapbox-gl-style-spec';
8
+
9
+ const argv = minimist(process.argv.slice(2));
10
+
11
+ if (argv.help || argv.h || (!argv._.length && process.stdin.isTTY)) {
12
+ help();
13
+ process.exit(0);
14
+ }
15
+
16
+ console.log(format(composite(JSON.parse(fs.readFileSync(argv._[0])))));
17
+
18
+ function help() {
19
+ console.log('usage:');
20
+ console.log(' gl-style-composite style.json');
21
+ }
@@ -1,12 +1,16 @@
1
1
  #!/usr/bin/env node
2
+ /* eslint-disable no-process-exit */
3
+ /* eslint import/no-unresolved: [error, { ignore: ['^@mapbox/mapbox-gl-style-spec$'] }] */
2
4
 
5
+ import fs from 'fs';
6
+ import minimist from 'minimist';
7
+ import {format} from '@mapbox/mapbox-gl-style-spec';
3
8
 
4
- var fs = require('fs'),
5
- argv = require('minimist')(process.argv.slice(2)),
6
- format = require('../').format;
9
+ const argv = minimist(process.argv.slice(2));
7
10
 
8
11
  if (argv.help || argv.h || (!argv._.length && process.stdin.isTTY)) {
9
- return help();
12
+ help();
13
+ process.exit(0);
10
14
  }
11
15
 
12
16
  console.log(format(JSON.parse(fs.readFileSync(argv._[0])), argv.space));
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable no-process-exit */
3
+ /* eslint import/no-unresolved: [error, { ignore: ['^@mapbox/mapbox-gl-style-spec$'] }] */
4
+
5
+ import fs from 'fs';
6
+ import minimist from 'minimist';
7
+ import {format, migrate} from '@mapbox/mapbox-gl-style-spec';
8
+
9
+ const argv = minimist(process.argv.slice(2));
10
+
11
+ if (argv.help || argv.h || (!argv._.length && process.stdin.isTTY)) {
12
+ help();
13
+ process.exit(0);
14
+ }
15
+
16
+ console.log(format(migrate(JSON.parse(fs.readFileSync(argv._[0])))));
17
+
18
+ function help() {
19
+ console.log('usage:');
20
+ console.log(' gl-style-migrate source.json > destination.json');
21
+ }
@@ -1,25 +1,28 @@
1
1
  #!/usr/bin/env node
2
+ /* eslint-disable no-process-exit */
3
+ /* eslint import/no-unresolved: [error, { ignore: ['^@mapbox/mapbox-gl-style-spec$'] }] */
2
4
 
5
+ import rw from 'rw';
6
+ import minimist from 'minimist';
7
+ import {validate, validateMapboxApiSupported} from '@mapbox/mapbox-gl-style-spec';
3
8
 
4
- var argv = require('minimist')(process.argv.slice(2), {
5
- boolean: 'json',
6
- boolean: 'mapbox-api-supported'
7
- }),
8
- validate = require('../').validate,
9
- validateMapboxApiSupported = require('../').validateMapboxApiSupported
10
- rw = require('rw'),
11
- status = 0;
9
+ const argv = minimist(process.argv.slice(2), {
10
+ boolean: ['json', 'mapbox-api-supported'],
11
+ });
12
+
13
+ let status = 0;
12
14
 
13
15
  if (argv.help || argv.h || (!argv._.length && process.stdin.isTTY)) {
14
- return help();
16
+ help();
17
+ process.exit(status);
15
18
  }
16
19
 
17
20
  if (!argv._.length) {
18
21
  argv._.push('/dev/stdin');
19
22
  }
20
23
 
21
- argv._.forEach(function(file) {
22
- var errors;
24
+ argv._.forEach((file) => {
25
+ let errors = [];
23
26
  if (argv['mapbox-api-supported']) {
24
27
  errors = validateMapboxApiSupported(rw.readFileSync(file, 'utf8'));
25
28
  } else {
@@ -29,7 +32,7 @@ argv._.forEach(function(file) {
29
32
  if (argv.json) {
30
33
  process.stdout.write(JSON.stringify(errors, null, 2));
31
34
  } else {
32
- errors.forEach(function (e) {
35
+ errors.forEach((e) => {
33
36
  console.log('%s:%d: %s', file, e.line, e.message);
34
37
  });
35
38
  }
package/build/.gitkeep ADDED
File without changes
package/deref.js CHANGED
@@ -1,7 +1,10 @@
1
+ // @flow
1
2
 
2
3
  import refProperties from './util/ref_properties.js';
3
4
 
4
- function deref(layer, parent) {
5
+ import type {LayerSpecification} from './types.js';
6
+
7
+ function deref(layer: LayerSpecification, parent: LayerSpecification): LayerSpecification {
5
8
  const result = {};
6
9
 
7
10
  for (const k in layer) {
@@ -12,15 +15,13 @@ function deref(layer, parent) {
12
15
 
13
16
  refProperties.forEach((k) => {
14
17
  if (k in parent) {
15
- result[k] = parent[k];
18
+ result[k] = (parent: any)[k];
16
19
  }
17
20
  });
18
21
 
19
- return result;
22
+ return ((result: any): LayerSpecification);
20
23
  }
21
24
 
22
- export default derefLayers;
23
-
24
25
  /**
25
26
  * Given an array of layers, some of which may contain `ref` properties
26
27
  * whose value is the `id` of another property, return a new array where
@@ -34,7 +35,7 @@ export default derefLayers;
34
35
  * @param {Array<Layer>} layers
35
36
  * @returns {Array<Layer>}
36
37
  */
37
- function derefLayers(layers) {
38
+ export default function derefLayers(layers: Array<LayerSpecification>): Array<LayerSpecification> {
38
39
  layers = layers.slice();
39
40
 
40
41
  const map = Object.create(null);
@@ -44,7 +45,7 @@ function derefLayers(layers) {
44
45
 
45
46
  for (let i = 0; i < layers.length; i++) {
46
47
  if ('ref' in layers[i]) {
47
- layers[i] = deref(layers[i], map[layers[i].ref]);
48
+ layers[i] = deref(layers[i], map[(layers[i]: any).ref]);
48
49
  }
49
50
  }
50
51
 
package/diff.js CHANGED
@@ -1,7 +1,15 @@
1
+ // @flow
1
2
 
2
3
  import isEqual from './util/deep_equal.js';
3
4
 
4
- const operations = {
5
+ import type {StyleSpecification} from './types.js';
6
+
7
+ type Command = {
8
+ command: string;
9
+ args: Array<any>;
10
+ };
11
+
12
+ export const operations: {[_: string]: string} = {
5
13
 
6
14
  /*
7
15
  * { command: 'setStyle', args: [stylesheet] }
@@ -330,7 +338,7 @@ function diffLayers(before, after, commands) {
330
338
  * @param {*} after stylesheet to compare to
331
339
  * @returns Array list of changes
332
340
  */
333
- function diffStyles(before, after) {
341
+ export default function diffStyles(before: StyleSpecification, after: StyleSpecification): Array<Command> {
334
342
  if (!before) return [{command: operations.setStyle, args: [after]}];
335
343
 
336
344
  let commands = [];
@@ -388,7 +396,7 @@ function diffStyles(before, after) {
388
396
  const beforeLayers = [];
389
397
  if (before.layers) {
390
398
  before.layers.forEach((layer) => {
391
- if (sourcesRemoved[layer.source]) {
399
+ if (layer.source && sourcesRemoved[layer.source]) {
392
400
  commands.push({command: operations.removeLayer, args: [layer.id]});
393
401
  } else {
394
402
  beforeLayers.push(layer);
@@ -424,6 +432,3 @@ function diffStyles(before, after) {
424
432
 
425
433
  return commands;
426
434
  }
427
-
428
- export default diffStyles;
429
- export {operations};
package/dist/index.cjs CHANGED
@@ -10686,7 +10686,7 @@
10686
10686
  evaluate(ctx) {
10687
10687
  const needle = this.needle.evaluate(ctx);
10688
10688
  const haystack = this.haystack.evaluate(ctx);
10689
- if (!haystack)
10689
+ if (haystack == null)
10690
10690
  return false;
10691
10691
  if (!isValidNativeType(needle, [
10692
10692
  'boolean',
@@ -13619,7 +13619,7 @@ ${ JSON.stringify(filterExp, null, 2) }
13619
13619
  const beforeLayers = [];
13620
13620
  if (before.layers) {
13621
13621
  before.layers.forEach(layer => {
13622
- if (sourcesRemoved[layer.source]) {
13622
+ if (layer.source && sourcesRemoved[layer.source]) {
13623
13623
  commands.push({
13624
13624
  command: operations.removeLayer,
13625
13625
  args: [layer.id]
@@ -13677,16 +13677,6 @@ ${ JSON.stringify(filterExp, null, 2) }
13677
13677
  }
13678
13678
  }
13679
13679
 
13680
- function validateConstants(options) {
13681
- const key = options.key;
13682
- const constants = options.value;
13683
- if (constants) {
13684
- return [new ValidationError(key, constants, 'constants have been deprecated as of v8')];
13685
- } else {
13686
- return [];
13687
- }
13688
- }
13689
-
13690
13680
  function validateObject(options) {
13691
13681
  const key = options.key;
13692
13682
  const object = options.value;
@@ -14642,7 +14632,6 @@ ${ JSON.stringify(filterExp, null, 2) }
14642
14632
  'boolean': validateBoolean,
14643
14633
  'number': validateNumber,
14644
14634
  'color': validateColor,
14645
- 'constants': validateConstants,
14646
14635
  'enum': validateEnum,
14647
14636
  'filter': validateFilter,
14648
14637
  'function': validateFunction,
@@ -14688,9 +14677,8 @@ ${ JSON.stringify(filterExp, null, 2) }
14688
14677
  return errors;
14689
14678
  }
14690
14679
 
14691
- function validateStyleMin(style, styleSpec = v8) {
14692
- let errors = [];
14693
- errors = errors.concat(validate({
14680
+ function validateStyle(style, styleSpec = v8) {
14681
+ const errors = validate({
14694
14682
  key: '',
14695
14683
  value: style,
14696
14684
  valueSpec: styleSpec.$root,
@@ -14698,38 +14686,13 @@ ${ JSON.stringify(filterExp, null, 2) }
14698
14686
  style,
14699
14687
  objectElementValidators: {
14700
14688
  glyphs: validateGlyphsURL,
14701
- '*'() {
14702
- return [];
14703
- }
14689
+ '*': () => []
14704
14690
  }
14705
- }));
14706
- if (style.constants) {
14707
- errors = errors.concat(validateConstants({
14708
- key: 'constants',
14709
- value: style.constants,
14710
- style,
14711
- styleSpec
14712
- }));
14713
- }
14691
+ });
14714
14692
  return sortErrors(errors);
14715
14693
  }
14716
- validateStyleMin.source = wrapCleanErrors(validateSource);
14717
- validateStyleMin.light = wrapCleanErrors(validateLight);
14718
- validateStyleMin.terrain = wrapCleanErrors(validateTerrain);
14719
- validateStyleMin.fog = wrapCleanErrors(validateFog);
14720
- validateStyleMin.layer = wrapCleanErrors(validateLayer);
14721
- validateStyleMin.filter = wrapCleanErrors(validateFilter);
14722
- validateStyleMin.paintProperty = wrapCleanErrors(validatePaintProperty);
14723
- validateStyleMin.layoutProperty = wrapCleanErrors(validateLayoutProperty);
14724
14694
  function sortErrors(errors) {
14725
- return [].concat(errors).sort((a, b) => {
14726
- return a.line - b.line;
14727
- });
14728
- }
14729
- function wrapCleanErrors(inner) {
14730
- return function (...args) {
14731
- return sortErrors(inner.apply(this, args));
14732
- };
14695
+ return errors.slice().sort((a, b) => a.line - b.line);
14733
14696
  }
14734
14697
 
14735
14698
  /* parser generated by jison 0.4.15 */
@@ -15402,14 +15365,14 @@ ${ JSON.stringify(filterExp, null, 2) }
15402
15365
  return style;
15403
15366
  }
15404
15367
 
15405
- function validateStyle(style, styleSpec = v8) {
15368
+ function validateStyle$1(style, styleSpec = v8) {
15406
15369
  let s = style;
15407
15370
  try {
15408
15371
  s = readStyle(s);
15409
15372
  } catch (e) {
15410
15373
  return [e];
15411
15374
  }
15412
- return validateStyleMin(s, styleSpec);
15375
+ return validateStyle(s, styleSpec);
15413
15376
  }
15414
15377
 
15415
15378
  const SUPPORTED_SPEC_VERSION = 8;
@@ -15518,7 +15481,7 @@ ${ JSON.stringify(filterExp, null, 2) }
15518
15481
  } catch (e) {
15519
15482
  return [e];
15520
15483
  }
15521
- let errors = validateStyleMin(s, v8).concat(getRootErrors(s, Object.keys(v8.$root)));
15484
+ let errors = validateStyle(s, v8).concat(getRootErrors(s, Object.keys(v8.$root)));
15522
15485
  if (s.sources) {
15523
15486
  errors = errors.concat(getSourcesErrors(s.sources));
15524
15487
  }
@@ -15546,8 +15509,6 @@ ${ JSON.stringify(filterExp, null, 2) }
15546
15509
  eachLayer,
15547
15510
  eachProperty
15548
15511
  };
15549
- validateStyle.parsed = validateStyle;
15550
- validateStyle.latest = validateStyle;
15551
15512
 
15552
15513
  exports.Color = Color;
15553
15514
  exports.ParsingError = ParsingError$1;
@@ -15563,7 +15524,7 @@ ${ JSON.stringify(filterExp, null, 2) }
15563
15524
  exports.latest = v8;
15564
15525
  exports.migrate = migrate;
15565
15526
  exports.v8 = v8;
15566
- exports.validate = validateStyle;
15527
+ exports.validate = validateStyle$1;
15567
15528
  exports.validateMapboxApiSupported = validateMapboxApiSupported;
15568
15529
  exports.visit = visit;
15569
15530