@versatiles/style 5.8.3 → 5.8.4

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 (54) hide show
  1. package/README.md +14 -14
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +570 -338
  4. package/dist/index.js.map +1 -1
  5. package/package.json +12 -7
  6. package/src/color/abstract.ts +1 -1
  7. package/src/color/hsl.test.ts +10 -16
  8. package/src/color/hsl.ts +11 -15
  9. package/src/color/hsv.test.ts +4 -10
  10. package/src/color/hsv.ts +38 -22
  11. package/src/color/index.test.ts +2 -4
  12. package/src/color/index.ts +1 -1
  13. package/src/color/random.test.ts +1 -1
  14. package/src/color/random.ts +127 -25
  15. package/src/color/rgb.test.ts +55 -36
  16. package/src/color/rgb.ts +35 -48
  17. package/src/color/utils.test.ts +4 -6
  18. package/src/color/utils.ts +1 -3
  19. package/src/guess_style/guess_style.test.ts +49 -43
  20. package/src/guess_style/guess_style.ts +64 -21
  21. package/src/guess_style/index.ts +0 -1
  22. package/src/index.test.ts +34 -7
  23. package/src/index.ts +29 -19
  24. package/src/lib/utils.test.ts +2 -2
  25. package/src/lib/utils.ts +2 -1
  26. package/src/shortbread/index.ts +0 -1
  27. package/src/shortbread/layers.test.ts +15 -1
  28. package/src/shortbread/layers.ts +204 -199
  29. package/src/shortbread/properties.test.ts +3 -4
  30. package/src/shortbread/properties.ts +18 -4
  31. package/src/shortbread/template.test.ts +7 -2
  32. package/src/shortbread/template.ts +7 -14
  33. package/src/style_builder/decorator.test.ts +4 -4
  34. package/src/style_builder/decorator.ts +29 -21
  35. package/src/style_builder/recolor.test.ts +6 -31
  36. package/src/style_builder/recolor.ts +20 -20
  37. package/src/style_builder/style_builder.test.ts +50 -13
  38. package/src/style_builder/style_builder.ts +29 -31
  39. package/src/style_builder/types.ts +85 -2
  40. package/src/styles/LICENSE.md +15 -15
  41. package/src/styles/colorful.test.ts +91 -0
  42. package/src/styles/colorful.ts +229 -122
  43. package/src/styles/eclipse.ts +1 -1
  44. package/src/styles/empty.ts +1 -1
  45. package/src/styles/graybeard.ts +2 -2
  46. package/src/styles/index.ts +0 -3
  47. package/src/styles/neutrino.ts +14 -16
  48. package/src/styles/shadow.ts +2 -2
  49. package/src/types/index.ts +0 -1
  50. package/src/types/maplibre.ts +17 -3
  51. package/src/types/tilejson.test.ts +8 -5
  52. package/src/types/tilejson.ts +13 -13
  53. package/src/types/vector_layer.test.ts +4 -1
  54. package/src/types/vector_layer.ts +7 -7
@@ -1,4 +1,4 @@
1
- import { describe, expect, it } from 'vitest';
1
+ import { describe, expect, it } from 'vitest';
2
2
  import { isTileJSONSpecification } from './tilejson.js';
3
3
 
4
4
  describe('isTileJSONSpecification', () => {
@@ -30,7 +30,9 @@ describe('isTileJSONSpecification', () => {
30
30
  });
31
31
 
32
32
  it('should throw an error if the tiles property is missing', () => {
33
- expect(() => isTileJSONSpecification({ ...validRasterSpec, tiles: undefined })).toThrow('spec.tiles must be an array of strings');
33
+ expect(() => isTileJSONSpecification({ ...validRasterSpec, tiles: undefined })).toThrow(
34
+ 'spec.tiles must be an array of strings'
35
+ );
34
36
  });
35
37
 
36
38
  it('should throw an error if the bounds property is invalid', () => {
@@ -73,7 +75,7 @@ describe('isTileJSONSpecification', () => {
73
75
  ['name', 'a string if present', 'valid', 1],
74
76
  ['scheme', '"tms" or "xyz" if present', 'xyz', 'invalid', 1],
75
77
  ['template', 'a string if present', 'valid', 1],
76
- ].forEach(test => {
78
+ ].forEach((test) => {
77
79
  const key = test[0] as string;
78
80
  const errorMessage = test[1] as string;
79
81
  const values = test.slice(2) as unknown[];
@@ -83,8 +85,9 @@ describe('isTileJSONSpecification', () => {
83
85
  if (i === 0) {
84
86
  expect(isTileJSONSpecification({ ...validVectorSpec, [key]: value })).toBe(true);
85
87
  } else {
86
- expect(() => isTileJSONSpecification({ ...validVectorSpec, [key]: value }))
87
- .toThrow(`spec.${key} must be ${errorMessage}`);
88
+ expect(() => isTileJSONSpecification({ ...validVectorSpec, [key]: value })).toThrow(
89
+ `spec.${key} must be ${errorMessage}`
90
+ );
88
91
  }
89
92
  }
90
93
  });
@@ -29,10 +29,10 @@ export interface TileJSONSpecificationVector extends TileJSONSpecificationRaster
29
29
  /** Represents a TileJSON specification, which can be either raster or vector. */
30
30
  export type TileJSONSpecification = TileJSONSpecificationRaster | TileJSONSpecificationVector;
31
31
 
32
- /**
33
- * Checks if an object adheres to the TileJSON specification.
34
- * Throws errors if the object does not conform to the expected structure or types.
35
- */
32
+ /**
33
+ * Checks if an object adheres to the TileJSON specification.
34
+ * Throws errors if the object does not conform to the expected structure or types.
35
+ */
36
36
  export function isTileJSONSpecification(spec: unknown): spec is TileJSONSpecification {
37
37
  if (typeof spec !== 'object' || spec === null) {
38
38
  throw Error('spec must be an object');
@@ -50,7 +50,7 @@ export function isTileJSONSpecification(spec: unknown): spec is TileJSONSpecific
50
50
  }
51
51
 
52
52
  if (obj.bounds != null) {
53
- if (!Array.isArray(obj.bounds) || obj.bounds.length !== 4 || obj.bounds.some(num => typeof num !== 'number')) {
53
+ if (!Array.isArray(obj.bounds) || obj.bounds.length !== 4 || obj.bounds.some((num) => typeof num !== 'number')) {
54
54
  throw Error('spec.bounds must be an array of four numbers if present');
55
55
  }
56
56
  const a = obj.bounds as [number, number, number, number];
@@ -63,7 +63,7 @@ export function isTileJSONSpecification(spec: unknown): spec is TileJSONSpecific
63
63
  }
64
64
 
65
65
  if (obj.center != null) {
66
- if (!Array.isArray(obj.center) || obj.center.length !== 2 || obj.center.some(num => typeof num !== 'number')) {
66
+ if (!Array.isArray(obj.center) || obj.center.length !== 2 || obj.center.some((num) => typeof num !== 'number')) {
67
67
  throw Error('spec.center must be an array of two numbers if present');
68
68
  }
69
69
  const a = obj.center as [number, number];
@@ -71,7 +71,7 @@ export function isTileJSONSpecification(spec: unknown): spec is TileJSONSpecific
71
71
  if (a[1] < -90 || a[1] > 90) throw Error('spec.center[1] must be between -90 and 90');
72
72
  }
73
73
 
74
- if (obj.data != null && (!Array.isArray(obj.data) || obj.data.some(url => typeof url !== 'string'))) {
74
+ if (obj.data != null && (!Array.isArray(obj.data) || obj.data.some((url) => typeof url !== 'string'))) {
75
75
  throw Error('spec.data must be an array of strings if present');
76
76
  }
77
77
 
@@ -79,11 +79,11 @@ export function isTileJSONSpecification(spec: unknown): spec is TileJSONSpecific
79
79
  throw Error('spec.description must be a string if present');
80
80
  }
81
81
 
82
- if (obj.fillzoom != null && (typeof obj.fillzoom !== 'number' || (obj.fillzoom < 0))) {
82
+ if (obj.fillzoom != null && (typeof obj.fillzoom !== 'number' || obj.fillzoom < 0)) {
83
83
  throw Error('spec.fillzoom must be a positive integer if present');
84
84
  }
85
85
 
86
- if (obj.grids != null && (!Array.isArray(obj.grids) || obj.grids.some(url => typeof url !== 'string'))) {
86
+ if (obj.grids != null && (!Array.isArray(obj.grids) || obj.grids.some((url) => typeof url !== 'string'))) {
87
87
  throw Error('spec.grids must be an array of strings if present');
88
88
  }
89
89
 
@@ -91,11 +91,11 @@ export function isTileJSONSpecification(spec: unknown): spec is TileJSONSpecific
91
91
  throw Error('spec.legend must be a string if present');
92
92
  }
93
93
 
94
- if (obj.minzoom != null && (typeof obj.minzoom !== 'number' || (obj.minzoom < 0))) {
94
+ if (obj.minzoom != null && (typeof obj.minzoom !== 'number' || obj.minzoom < 0)) {
95
95
  throw Error('spec.minzoom must be a positive integer if present');
96
96
  }
97
97
 
98
- if (obj.maxzoom != null && (typeof obj.maxzoom !== 'number' || (obj.maxzoom < 0))) {
98
+ if (obj.maxzoom != null && (typeof obj.maxzoom !== 'number' || obj.maxzoom < 0)) {
99
99
  throw Error('spec.maxzoom must be a positive integer if present');
100
100
  }
101
101
 
@@ -111,7 +111,7 @@ export function isTileJSONSpecification(spec: unknown): spec is TileJSONSpecific
111
111
  throw Error('spec.template must be a string if present');
112
112
  }
113
113
 
114
- if (!Array.isArray(obj.tiles) || obj.tiles.length === 0 || obj.tiles.some(url => typeof url !== 'string')) {
114
+ if (!Array.isArray(obj.tiles) || obj.tiles.length === 0 || obj.tiles.some((url) => typeof url !== 'string')) {
115
115
  throw Error('spec.tiles must be an array of strings');
116
116
  }
117
117
 
@@ -120,6 +120,6 @@ export function isTileJSONSpecification(spec: unknown): spec is TileJSONSpecific
120
120
 
121
121
  export function isRasterTileJSONSpecification(spec: unknown): spec is TileJSONSpecificationRaster {
122
122
  if (!isTileJSONSpecification(spec)) return false;
123
- if (('vector_layers' in spec) && (spec.vector_layers != null)) return false;
123
+ if ('vector_layers' in spec && spec.vector_layers != null) return false;
124
124
  return true;
125
125
  }
@@ -20,7 +20,10 @@ describe('isVectorLayer', () => {
20
20
 
21
21
  it('should throw an error for invalid fields', () => {
22
22
  verifyError({ id: 'test', fields: null }, 'Layer.fields must be a non-null object');
23
- verifyError({ id: 'test', fields: { field1: 'InvalidType' } }, 'Layer.fields values must be one of \'Boolean\', \'Number\', or \'String\'');
23
+ verifyError(
24
+ { id: 'test', fields: { field1: 'InvalidType' } },
25
+ "Layer.fields values must be one of 'Boolean', 'Number', or 'String'"
26
+ );
24
27
  });
25
28
 
26
29
  it('should throw an error for invalid optional properties', () => {
@@ -7,10 +7,10 @@ export interface VectorLayer {
7
7
  maxzoom?: number;
8
8
  }
9
9
 
10
- /**
11
- * Verifies if an object conforms to the VectorLayer structure.
12
- * Throws errors for any deviations from the expected structure or types.
13
- */
10
+ /**
11
+ * Verifies if an object conforms to the VectorLayer structure.
12
+ * Throws errors for any deviations from the expected structure or types.
13
+ */
14
14
  export function isVectorLayer(layer: unknown): layer is VectorLayer {
15
15
  if (typeof layer !== 'object' || layer === null) {
16
16
  throw new Error('Layer must be a non-null object');
@@ -25,8 +25,8 @@ export function isVectorLayer(layer: unknown): layer is VectorLayer {
25
25
  if (typeof obj.fields !== 'object' || obj.fields === null) {
26
26
  throw new Error('Layer.fields must be a non-null object');
27
27
  }
28
- if (Object.values(obj.fields).some(type => !['Boolean', 'Number', 'String'].includes(type as string))) {
29
- throw new Error('Layer.fields values must be one of \'Boolean\', \'Number\', or \'String\'');
28
+ if (Object.values(obj.fields).some((type) => !['Boolean', 'Number', 'String'].includes(type as string))) {
29
+ throw new Error("Layer.fields values must be one of 'Boolean', 'Number', or 'String'");
30
30
  }
31
31
 
32
32
  if ('description' in obj && typeof obj.description !== 'string') {
@@ -61,7 +61,7 @@ export function isVectorLayers(layers: unknown): layers is VectorLayer[] {
61
61
  } catch (error) {
62
62
  // Assuming `isVectorLayer` throws an error with a meaningful message, you can rethrow it
63
63
  // Alternatively, customize the error message or handle the error as needed
64
- throw new Error(`Layer[${index}] at invalid: ${String((error instanceof Error) ? error.message : error)}`);
64
+ throw new Error(`Layer[${index}] at invalid: ${String(error instanceof Error ? error.message : error)}`);
65
65
  }
66
66
  });
67
67