@mapbox/mapbox-gl-style-spec 13.24.0-alpha.1 → 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.
Files changed (44) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/bin/gl-style-composite.js +21 -0
  3. package/bin/{gl-style-format → gl-style-format.js} +8 -4
  4. package/bin/gl-style-migrate.js +21 -0
  5. package/bin/{gl-style-validate → gl-style-validate.js} +15 -12
  6. package/build/.gitkeep +0 -0
  7. package/deref.js +8 -7
  8. package/diff.js +11 -6
  9. package/dist/index.cjs +15 -54
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.es.js +15 -54
  12. package/dist/index.es.js.map +1 -1
  13. package/empty.js +9 -28
  14. package/expression/definitions/coalesce.js +7 -5
  15. package/expression/definitions/in.js +1 -1
  16. package/expression/evaluation_context.js +1 -1
  17. package/expression/index.js +3 -3
  18. package/feature_filter/convert.js +1 -1
  19. package/feature_filter/index.js +1 -1
  20. package/flow-typed/gl-matrix.js +103 -0
  21. package/flow-typed/grid-index.js +13 -0
  22. package/flow-typed/pbf.js +2 -1
  23. package/flow-typed/point-geometry.js +4 -2
  24. package/flow-typed/potpack.js +1 -0
  25. package/flow-typed/tiny-sdf.js +31 -0
  26. package/flow-typed/vector-tile.js +1 -0
  27. package/group_by_layout.js +8 -10
  28. package/package.json +9 -7
  29. package/style-spec.js +6 -3
  30. package/test.js +31 -0
  31. package/util/color_spaces.js +2 -2
  32. package/util/extend.js +1 -1
  33. package/util/interpolate.js +2 -2
  34. package/util/ref_properties.js +1 -1
  35. package/util/unbundle_jsonlint.js +1 -1
  36. package/validate/validate.js +0 -2
  37. package/validate_mapbox_api_supported.js +8 -6
  38. package/validate_style.js +14 -9
  39. package/validate_style.min.js +32 -47
  40. package/bin/gl-style-composite +0 -9
  41. package/bin/gl-style-migrate +0 -9
  42. package/declass.js +0 -42
  43. package/validate/latest.js +0 -11
  44. package/validate/validate_constants.js +0 -13
@@ -1,17 +1,26 @@
1
-
2
- import validateConstants from './validate/validate_constants.js';
1
+ // @flow
3
2
  import validate from './validate/validate.js';
4
3
  import latestStyleSpec from './reference/latest.js';
5
4
  import validateGlyphsURL from './validate/validate_glyphs_url.js';
6
5
 
7
- import validateSource from './validate/validate_source.js';
8
- import validateLight from './validate/validate_light.js';
9
- import validateTerrain from './validate/validate_terrain.js';
10
- import validateFog from './validate/validate_fog.js';
11
- import validateLayer from './validate/validate_layer.js';
12
- import validateFilter from './validate/validate_filter.js';
13
- import validatePaintProperty from './validate/validate_paint_property.js';
14
- import validateLayoutProperty from './validate/validate_layout_property.js';
6
+ import _validateSource from './validate/validate_source.js';
7
+ import _validateLight from './validate/validate_light.js';
8
+ import _validateTerrain from './validate/validate_terrain.js';
9
+ import _validateFog from './validate/validate_fog.js';
10
+ import _validateLayer from './validate/validate_layer.js';
11
+ import _validateFilter from './validate/validate_filter.js';
12
+ import _validatePaintProperty from './validate/validate_paint_property.js';
13
+ import _validateLayoutProperty from './validate/validate_layout_property.js';
14
+
15
+ import type {StyleSpecification} from './types.js';
16
+
17
+ export type ValidationError = {
18
+ message: string;
19
+ identifier?: ?string;
20
+ line?: ?number;
21
+ };
22
+ export type ValidationErrors = $ReadOnlyArray<ValidationError>;
23
+ export type Validator = (Object) => ValidationErrors;
15
24
 
16
25
  /**
17
26
  * Validate a Mapbox GL style against the style specification. This entrypoint,
@@ -28,11 +37,9 @@ import validateLayoutProperty from './validate/validate_layout_property.js';
28
37
  * var validate = require('mapbox-gl-style-spec/lib/validate_style.min');
29
38
  * var errors = validate(style);
30
39
  */
31
- function validateStyleMin(style, styleSpec = latestStyleSpec) {
40
+ export function validateStyle(style: StyleSpecification, styleSpec: Object = latestStyleSpec): ValidationErrors {
32
41
 
33
- let errors = [];
34
-
35
- errors = errors.concat(validate({
42
+ const errors = validate({
36
43
  key: '',
37
44
  value: style,
38
45
  valueSpec: styleSpec.$root,
@@ -40,43 +47,21 @@ function validateStyleMin(style, styleSpec = latestStyleSpec) {
40
47
  style,
41
48
  objectElementValidators: {
42
49
  glyphs: validateGlyphsURL,
43
- '*'() {
44
- return [];
45
- }
50
+ '*': () => []
46
51
  }
47
- }));
48
-
49
- if (style.constants) {
50
- errors = errors.concat(validateConstants({
51
- key: 'constants',
52
- value: style.constants,
53
- style,
54
- styleSpec
55
- }));
56
- }
57
-
52
+ });
58
53
  return sortErrors(errors);
59
54
  }
60
55
 
61
- validateStyleMin.source = wrapCleanErrors(validateSource);
62
- validateStyleMin.light = wrapCleanErrors(validateLight);
63
- validateStyleMin.terrain = wrapCleanErrors(validateTerrain);
64
- validateStyleMin.fog = wrapCleanErrors(validateFog);
65
- validateStyleMin.layer = wrapCleanErrors(validateLayer);
66
- validateStyleMin.filter = wrapCleanErrors(validateFilter);
67
- validateStyleMin.paintProperty = wrapCleanErrors(validatePaintProperty);
68
- validateStyleMin.layoutProperty = wrapCleanErrors(validateLayoutProperty);
56
+ export const validateSource: Validator = opts => sortErrors(_validateSource(opts));
57
+ export const validateLight: Validator = opts => sortErrors(_validateLight(opts));
58
+ export const validateTerrain: Validator = opts => sortErrors(_validateTerrain(opts));
59
+ export const validateFog: Validator = opts => sortErrors(_validateFog(opts));
60
+ export const validateLayer: Validator = opts => sortErrors(_validateLayer(opts));
61
+ export const validateFilter: Validator = opts => sortErrors(_validateFilter(opts));
62
+ export const validatePaintProperty: Validator = opts => sortErrors(_validatePaintProperty(opts));
63
+ export const validateLayoutProperty: Validator = opts => sortErrors(_validateLayoutProperty(opts));
69
64
 
70
65
  function sortErrors(errors) {
71
- return [].concat(errors).sort((a, b) => {
72
- return a.line - b.line;
73
- });
66
+ return errors.slice().sort((a, b) => a.line - b.line);
74
67
  }
75
-
76
- function wrapCleanErrors(inner) {
77
- return function(...args) {
78
- return sortErrors(inner.apply(this, args));
79
- };
80
- }
81
-
82
- export default validateStyleMin;
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
-
4
- var fs = require('fs'),
5
- argv = require('minimist')(process.argv.slice(2)),
6
- format = require('../').format,
7
- composite = require('../').composite;
8
-
9
- console.log(format(composite(JSON.parse(fs.readFileSync(argv._[0])))));
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
-
4
- var fs = require('fs'),
5
- argv = require('minimist')(process.argv.slice(2)),
6
- format = require('../').format,
7
- migrate = require('../').migrate;
8
-
9
- console.log(format(migrate(JSON.parse(fs.readFileSync(argv._[0])))));
package/declass.js DELETED
@@ -1,42 +0,0 @@
1
-
2
- import extend from './util/extend.js';
3
-
4
- export default declassStyle;
5
-
6
- /**
7
- * Returns a new style with the given 'paint classes' merged into each layer's
8
- * main `paint` definiton, and with all `paint.*` properties removed.
9
- *
10
- * @private
11
- * @param {Object} style A style JSON object.
12
- * @param {Array<string>} classes An array of paint classes to apply, in order.
13
- *
14
- * @example
15
- * var declass = require('mapbox-gl-style-spec/lib/declass')
16
- * var baseStyle = { ... style with a 'paint.night' property in some layers ... }
17
- * var nightStyle = declass(baseStyle, ['night'])
18
- * // nightStyle now has each layer's `paint.night` properties merged in to the
19
- * // main `paint` property.
20
- */
21
- function declassStyle(style, classes) {
22
- return extend({}, style, {
23
- layers: style.layers.map((layer) => {
24
- const result = classes.reduce(declassLayer, layer);
25
-
26
- // strip away all `paint.CLASS` definitions
27
- for (const key in result) {
28
- if (/paint\..*/.test(key)) {
29
- delete result[key];
30
- }
31
- }
32
-
33
- return result;
34
- })
35
- });
36
- }
37
-
38
- function declassLayer(layer, klass) {
39
- return extend({}, layer, {
40
- paint: extend({}, layer.paint, layer[`paint.${klass}`])
41
- });
42
- }
@@ -1,11 +0,0 @@
1
-
2
- import validateStyle from '../validate_style.min.js';
3
-
4
- /*
5
- * Validate a style against the latest specification. This method is optimized
6
- * to keep its bundle size small by refraining from requiring jslint or old
7
- * style spec versions.
8
- * @see validateStyleMin
9
- * @deprecated This file exists for backwards compatibility and will be dropped in the next minor release.
10
- */
11
- export default validateStyle;
@@ -1,13 +0,0 @@
1
-
2
- import ValidationError from '../error/validation_error.js';
3
-
4
- export default function validateConstants(options) {
5
- const key = options.key;
6
- const constants = options.value;
7
-
8
- if (constants) {
9
- return [new ValidationError(key, constants, 'constants have been deprecated as of v8')];
10
- } else {
11
- return [];
12
- }
13
- }