@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
@@ -4,7 +4,6 @@ import { HSL } from './hsl.js';
4
4
  import { HSV } from './hsv.js';
5
5
 
6
6
  describe('RGB Class', () => {
7
-
8
7
  it('constructor initializes values correctly with clamping', () => {
9
8
  const color = new RGB(300, -50, 500, 2);
10
9
  expect(color.asArray()).toStrictEqual([255, 0, 255, 1]);
@@ -46,8 +45,7 @@ describe('RGB Class', () => {
46
45
  it('asHSL converts RGB to HSL correctly', () => {
47
46
  const hsl = new RGB(255, 0, 0).asHSL();
48
47
  expect(hsl).toBeInstanceOf(HSL);
49
- expect(hsl.asArray().map(value => Math.round(value)))
50
- .toStrictEqual([0, 100, 50, 1]);
48
+ expect(hsl.asArray().map((value) => Math.round(value))).toStrictEqual([0, 100, 50, 1]);
51
49
 
52
50
  expect(RGB.parse('#000000').asHSL().round().asArray()).toStrictEqual([0, 0, 0, 1]);
53
51
  expect(RGB.parse('#FFFFFF').asHSL().round().asArray()).toStrictEqual([0, 0, 100, 1]);
@@ -68,8 +66,7 @@ describe('RGB Class', () => {
68
66
  it('asHSV converts RGB to HSV correctly', () => {
69
67
  const hsv = new RGB(255, 0, 0).asHSV();
70
68
  expect(hsv).toBeInstanceOf(HSV);
71
- expect(hsv.asArray().map(value => Math.round(value)))
72
- .toStrictEqual([0, 100, 100, 1]);
69
+ expect(hsv.asArray().map((value) => Math.round(value))).toStrictEqual([0, 100, 100, 1]);
73
70
 
74
71
  expect(RGB.parse('#000000').asHSV().round().asArray()).toStrictEqual([0, 0, 0, 1]);
75
72
  expect(RGB.parse('#FFFFFF').asHSV().round().asArray()).toStrictEqual([0, 0, 100, 1]);
@@ -95,14 +92,34 @@ describe('RGB Class', () => {
95
92
 
96
93
  it('handles black correctly', () => {
97
94
  const color = new RGB(0, 0, 0);
98
- expect(color.asHSL().asArray().map(value => Math.round(value))).toStrictEqual([0, 0, 0, 1]);
99
- expect(color.asHSV().asArray().map(value => Math.round(value))).toStrictEqual([0, 0, 0, 1]);
95
+ expect(
96
+ color
97
+ .asHSL()
98
+ .asArray()
99
+ .map((value) => Math.round(value))
100
+ ).toStrictEqual([0, 0, 0, 1]);
101
+ expect(
102
+ color
103
+ .asHSV()
104
+ .asArray()
105
+ .map((value) => Math.round(value))
106
+ ).toStrictEqual([0, 0, 0, 1]);
100
107
  });
101
108
 
102
109
  it('handles white correctly', () => {
103
110
  const color = new RGB(255, 255, 255);
104
- expect(color.asHSL().asArray().map(value => Math.round(value))).toStrictEqual([0, 0, 100, 1]);
105
- expect(color.asHSV().asArray().map(value => Math.round(value))).toStrictEqual([0, 0, 100, 1]);
111
+ expect(
112
+ color
113
+ .asHSL()
114
+ .asArray()
115
+ .map((value) => Math.round(value))
116
+ ).toStrictEqual([0, 0, 100, 1]);
117
+ expect(
118
+ color
119
+ .asHSV()
120
+ .asArray()
121
+ .map((value) => Math.round(value))
122
+ ).toStrictEqual([0, 0, 100, 1]);
106
123
  });
107
124
  });
108
125
 
@@ -132,62 +149,64 @@ describe('RGB Class', () => {
132
149
 
133
150
  describe('filter methods', () => {
134
151
  function pc(cb: (c: RGB) => RGB): [number, number, number, number] {
135
- return cb(new RGB(50, 150, 200, 0.8)).round().asArray();
152
+ return cb(new RGB(50, 150, 200, 0.8))
153
+ .round()
154
+ .asArray();
136
155
  }
137
156
 
138
157
  it('adjusts gamma correctly', () => {
139
- expect(pc(c => c.gamma(2.2))).toStrictEqual([7, 79, 149, 0.8]);
140
- expect(pc(c => c.gamma(0.001))).toStrictEqual([255, 255, 255, 0.8]);
141
- expect(pc(c => c.gamma(1000))).toStrictEqual([0, 0, 0, 0.8]);
158
+ expect(pc((c) => c.gamma(2.2))).toStrictEqual([7, 79, 149, 0.8]);
159
+ expect(pc((c) => c.gamma(0.001))).toStrictEqual([255, 255, 255, 0.8]);
160
+ expect(pc((c) => c.gamma(1000))).toStrictEqual([0, 0, 0, 0.8]);
142
161
  });
143
162
 
144
163
  it('inverts RGB values correctly', () => {
145
- expect(pc(c => c.invert())).toStrictEqual([205, 105, 55, 0.8]);
164
+ expect(pc((c) => c.invert())).toStrictEqual([205, 105, 55, 0.8]);
146
165
  });
147
166
 
148
167
  it('adjusts contrast correctly', () => {
149
- expect(pc(c => c.contrast(1.5))).toStrictEqual([11, 161, 236, 0.8]);
150
- expect(pc(c => c.contrast(1e6))).toStrictEqual([0, 255, 255, 0.8]);
151
- expect(pc(c => c.contrast(0))).toStrictEqual([128, 128, 128, 0.8]);
168
+ expect(pc((c) => c.contrast(1.5))).toStrictEqual([11, 161, 236, 0.8]);
169
+ expect(pc((c) => c.contrast(1e6))).toStrictEqual([0, 255, 255, 0.8]);
170
+ expect(pc((c) => c.contrast(0))).toStrictEqual([128, 128, 128, 0.8]);
152
171
  });
153
172
 
154
173
  it('increases brightness correctly', () => {
155
- expect(pc(c => c.brightness(0.5))).toStrictEqual([153, 203, 228, 0.8]);
156
- expect(pc(c => c.brightness(-0.5))).toStrictEqual([25, 75, 100, 0.8]);
157
- expect(pc(c => c.brightness(2))).toStrictEqual([255, 255, 255, 0.8]);
158
- expect(pc(c => c.brightness(-2))).toStrictEqual([0, 0, 0, 0.8]);
174
+ expect(pc((c) => c.brightness(0.5))).toStrictEqual([153, 203, 228, 0.8]);
175
+ expect(pc((c) => c.brightness(-0.5))).toStrictEqual([25, 75, 100, 0.8]);
176
+ expect(pc((c) => c.brightness(2))).toStrictEqual([255, 255, 255, 0.8]);
177
+ expect(pc((c) => c.brightness(-2))).toStrictEqual([0, 0, 0, 0.8]);
159
178
  });
160
179
 
161
180
  it('tints color correctly', () => {
162
181
  const tintColor = new RGB(255, 0, 0);
163
- expect(pc(c => c.tint(0.5, tintColor))).toStrictEqual([125, 100, 125, 0.8]);
164
- expect(pc(c => c.tint(1, tintColor))).toStrictEqual([200, 50, 50, 0.8]);
165
- expect(pc(c => c.tint(0, tintColor))).toStrictEqual([50, 150, 200, 0.8]);
182
+ expect(pc((c) => c.tint(0.5, tintColor))).toStrictEqual([125, 100, 125, 0.8]);
183
+ expect(pc((c) => c.tint(1, tintColor))).toStrictEqual([200, 50, 50, 0.8]);
184
+ expect(pc((c) => c.tint(0, tintColor))).toStrictEqual([50, 150, 200, 0.8]);
166
185
  });
167
186
 
168
187
  it('blends color correctly', () => {
169
188
  const blendColor = new RGB(255, 0, 0);
170
- expect(pc(c => c.blend(0.2, blendColor))).toStrictEqual([91, 120, 160, 0.8]);
171
- expect(pc(c => c.blend(0.5, blendColor))).toStrictEqual([153, 75, 100, 0.8]);
172
- expect(pc(c => c.blend(0.8, blendColor))).toStrictEqual([214, 30, 40, 0.8]);
173
- expect(pc(c => c.blend(1, blendColor))).toStrictEqual([255, 0, 0, 0.8]);
174
- expect(pc(c => c.blend(0, blendColor))).toStrictEqual([50, 150, 200, 0.8]);
189
+ expect(pc((c) => c.blend(0.2, blendColor))).toStrictEqual([91, 120, 160, 0.8]);
190
+ expect(pc((c) => c.blend(0.5, blendColor))).toStrictEqual([153, 75, 100, 0.8]);
191
+ expect(pc((c) => c.blend(0.8, blendColor))).toStrictEqual([214, 30, 40, 0.8]);
192
+ expect(pc((c) => c.blend(1, blendColor))).toStrictEqual([255, 0, 0, 0.8]);
193
+ expect(pc((c) => c.blend(0, blendColor))).toStrictEqual([50, 150, 200, 0.8]);
175
194
  });
176
195
 
177
196
  it('lightens the color correctly', () => {
178
- expect(pc(c => c.lighten(0.5))).toStrictEqual([153, 203, 228, 0.8]);
179
- expect(pc(c => c.lighten(2))).toStrictEqual([255, 255, 255, 0.8]);
197
+ expect(pc((c) => c.lighten(0.5))).toStrictEqual([153, 203, 228, 0.8]);
198
+ expect(pc((c) => c.lighten(2))).toStrictEqual([255, 255, 255, 0.8]);
180
199
  });
181
200
 
182
201
  it('darkens the color correctly', () => {
183
- expect(pc(c => c.darken(0.5))).toStrictEqual([25, 75, 100, 0.8]);
184
- expect(pc(c => c.darken(1))).toStrictEqual([0, 0, 0, 0.8]);
185
- expect(pc(c => c.darken(2))).toStrictEqual([0, 0, 0, 0.8]);
202
+ expect(pc((c) => c.darken(0.5))).toStrictEqual([25, 75, 100, 0.8]);
203
+ expect(pc((c) => c.darken(1))).toStrictEqual([0, 0, 0, 0.8]);
204
+ expect(pc((c) => c.darken(2))).toStrictEqual([0, 0, 0, 0.8]);
186
205
  });
187
206
 
188
207
  it('fades color correctly', () => {
189
- expect(pc(c => c.fade(0.5))).toStrictEqual([50, 150, 200, 0.4]);
190
- expect(pc(c => c.fade(1))).toStrictEqual([50, 150, 200, 0]);
208
+ expect(pc((c) => c.fade(0.5))).toStrictEqual([50, 150, 200, 0.4]);
209
+ expect(pc((c) => c.fade(1))).toStrictEqual([50, 150, 200, 0]);
191
210
 
192
211
  const fullyOpaque = new RGB(50, 150, 200, 1);
193
212
  expect(fullyOpaque.fade(0).asArray()).toStrictEqual([50, 150, 200, 1]);
package/src/color/rgb.ts CHANGED
@@ -5,7 +5,7 @@ import { clamp, formatFloat } from './utils.js';
5
5
 
6
6
  /**
7
7
  * Represents an RGB color with optional alpha transparency.
8
- *
8
+ *
9
9
  * @extends Color
10
10
  */
11
11
  export class RGB extends Color {
@@ -31,7 +31,7 @@ export class RGB extends Color {
31
31
 
32
32
  /**
33
33
  * Creates an instance of RGB.
34
- *
34
+ *
35
35
  * @param r - Red component (0-255).
36
36
  * @param g - Green component (0-255).
37
37
  * @param b - Blue component (0-255).
@@ -47,7 +47,7 @@ export class RGB extends Color {
47
47
 
48
48
  /**
49
49
  * Creates a clone of the current RGB color.
50
- *
50
+ *
51
51
  * @returns A new RGB instance with the same color values.
52
52
  */
53
53
  clone(): RGB {
@@ -56,7 +56,7 @@ export class RGB extends Color {
56
56
 
57
57
  /**
58
58
  * Returns the RGB color as an array.
59
- *
59
+ *
60
60
  * @returns An array containing the red, green, blue, and alpha components.
61
61
  */
62
62
  asArray(): [number, number, number, number] {
@@ -65,21 +65,16 @@ export class RGB extends Color {
65
65
 
66
66
  /**
67
67
  * Rounds the RGB color components to the nearest integer.
68
- *
68
+ *
69
69
  * @returns A new RGB instance with rounded color values.
70
70
  */
71
71
  round(): RGB {
72
- return new RGB(
73
- Math.round(this.r),
74
- Math.round(this.g),
75
- Math.round(this.b),
76
- Math.round(this.a * 1000) / 1000,
77
- );
72
+ return new RGB(Math.round(this.r), Math.round(this.g), Math.round(this.b), Math.round(this.a * 1000) / 1000);
78
73
  }
79
74
 
80
75
  /**
81
76
  * Returns the RGB color as a string.
82
- *
77
+ *
83
78
  * @returns A string representation of the RGB color in either `rgb` or `rgba` format.
84
79
  */
85
80
  asString(): string {
@@ -92,7 +87,7 @@ export class RGB extends Color {
92
87
 
93
88
  /**
94
89
  * Returns the RGB color as a hexadecimal string.
95
- *
90
+ *
96
91
  * @returns A string representation of the RGB color in hexadecimal format.
97
92
  */
98
93
  asHex(): string {
@@ -103,14 +98,16 @@ export class RGB extends Color {
103
98
  if (this.a === 1) {
104
99
  return `#${r}${g}${b}`.toUpperCase();
105
100
  } else {
106
- const a = Math.round(this.a * 255).toString(16).padStart(2, '0');
101
+ const a = Math.round(this.a * 255)
102
+ .toString(16)
103
+ .padStart(2, '0');
107
104
  return `#${r}${g}${b}${a}`.toUpperCase();
108
105
  }
109
106
  }
110
107
 
111
108
  /**
112
109
  * Converts the RGB color to an HSL color.
113
- *
110
+ *
114
111
  * @returns An HSL instance representing the same color.
115
112
  */
116
113
  asHSL(): HSL {
@@ -138,11 +135,11 @@ export class RGB extends Color {
138
135
  else s = delta / (2 - max - min);
139
136
 
140
137
  return new HSL(h, s * 100, l * 100, this.a);
141
- };
138
+ }
142
139
 
143
140
  /**
144
141
  * Converts the RGB color to an HSV color.
145
- *
142
+ *
146
143
  * @returns An HSV instance representing the same color.
147
144
  */
148
145
  asHSV(): HSV {
@@ -157,7 +154,7 @@ export class RGB extends Color {
157
154
  if (diff !== 0) {
158
155
  function diffc(c: number): number {
159
156
  return (v - c) / 6 / diff + 1 / 2;
160
- };
157
+ }
161
158
 
162
159
  s = diff / v;
163
160
  const rdif = diffc(r);
@@ -165,8 +162,8 @@ export class RGB extends Color {
165
162
  const bdif = diffc(b);
166
163
 
167
164
  if (r === v) h = bdif - gdif;
168
- else if (g === v) h = (1 / 3) + rdif - bdif;
169
- else if (b === v) h = (2 / 3) + gdif - rdif;
165
+ else if (g === v) h = 1 / 3 + rdif - bdif;
166
+ else if (b === v) h = 2 / 3 + gdif - rdif;
170
167
 
171
168
  if (h < 0) h += 1;
172
169
  else if (h > 1) h -= 1;
@@ -177,7 +174,7 @@ export class RGB extends Color {
177
174
 
178
175
  /**
179
176
  * Returns the RGB color.
180
- *
177
+ *
181
178
  * @returns The current RGB instance.
182
179
  */
183
180
  asRGB(): RGB {
@@ -186,7 +183,7 @@ export class RGB extends Color {
186
183
 
187
184
  /**
188
185
  * Returns the RGB color.
189
- *
186
+ *
190
187
  * @returns The current RGB instance.
191
188
  */
192
189
  toRGB(): RGB {
@@ -195,7 +192,7 @@ export class RGB extends Color {
195
192
 
196
193
  /**
197
194
  * Parses a string or Color instance into an RGB color.
198
- *
195
+ *
199
196
  * @param input - The input string or Color instance to parse.
200
197
  * @returns A new RGB instance representing the parsed color.
201
198
  * @throws Will throw an error if the input string is not a valid RGB color string.
@@ -203,7 +200,7 @@ export class RGB extends Color {
203
200
  static parse(input: string | Color): RGB {
204
201
  if (input instanceof Color) return input.asRGB();
205
202
 
206
- input = input.toLowerCase().replaceAll(/[^0-9a-z.#,()]/g, '')
203
+ input = input.toLowerCase().replaceAll(/[^0-9a-z.#,()]/g, '');
207
204
 
208
205
  let match;
209
206
 
@@ -249,7 +246,7 @@ export class RGB extends Color {
249
246
 
250
247
  /**
251
248
  * Adjusts the gamma of the RGB color.
252
- *
249
+ *
253
250
  * @param value - The gamma value to apply.
254
251
  * @returns A new RGB instance with the adjusted gamma.
255
252
  */
@@ -266,21 +263,16 @@ export class RGB extends Color {
266
263
 
267
264
  /**
268
265
  * Inverts the RGB color.
269
- *
266
+ *
270
267
  * @returns A new RGB instance with the inverted color values.
271
268
  */
272
269
  invert(): RGB {
273
- return new RGB(
274
- 255 - this.r,
275
- 255 - this.g,
276
- 255 - this.b,
277
- this.a
278
- );
270
+ return new RGB(255 - this.r, 255 - this.g, 255 - this.b, this.a);
279
271
  }
280
272
 
281
273
  /**
282
274
  * Adjusts the contrast of the RGB color.
283
- *
275
+ *
284
276
  * @param value - The contrast value to apply.
285
277
  * @returns A new RGB instance with the adjusted contrast.
286
278
  */
@@ -297,7 +289,7 @@ export class RGB extends Color {
297
289
 
298
290
  /**
299
291
  * Adjusts the brightness of the RGB color.
300
- *
292
+ *
301
293
  * @param value - The brightness value to apply.
302
294
  * @returns A new RGB instance with the adjusted brightness.
303
295
  */
@@ -305,18 +297,13 @@ export class RGB extends Color {
305
297
  if (value < -1) value = -1;
306
298
  if (value > 1) value = 1;
307
299
  const a = 1 - Math.abs(value);
308
- const b = (value < 0) ? 0 : 255 * value;
309
- return new RGB(
310
- this.r * a + b,
311
- this.g * a + b,
312
- this.b * a + b,
313
- this.a
314
- );
300
+ const b = value < 0 ? 0 : 255 * value;
301
+ return new RGB(this.r * a + b, this.g * a + b, this.b * a + b, this.a);
315
302
  }
316
303
 
317
304
  /**
318
305
  * Tints the RGB color with another color.
319
- *
306
+ *
320
307
  * @param value - The tint value to apply.
321
308
  * @param tintColor - The color to use for tinting.
322
309
  * @returns A new RGB instance with the applied tint.
@@ -330,12 +317,12 @@ export class RGB extends Color {
330
317
  this.g * (1 - value) + value * rgbNew.g,
331
318
  this.b * (1 - value) + value * rgbNew.b,
332
319
  this.a
333
- )
320
+ );
334
321
  }
335
322
 
336
323
  /**
337
324
  * Blends the RGB color with another color.
338
- *
325
+ *
339
326
  * @param value - The blend value to apply.
340
327
  * @param blendColor - The color to blend with.
341
328
  * @returns A new RGB instance with the blended color.
@@ -353,7 +340,7 @@ export class RGB extends Color {
353
340
 
354
341
  /**
355
342
  * Lightens the RGB color.
356
- *
343
+ *
357
344
  * @param ratio - The ratio to lighten the color by.
358
345
  * @returns A new RGB instance with the lightened color.
359
346
  */
@@ -368,7 +355,7 @@ export class RGB extends Color {
368
355
 
369
356
  /**
370
357
  * Darkens the RGB color.
371
- *
358
+ *
372
359
  * @param ratio - The ratio to darken the color by.
373
360
  * @returns A new RGB instance with the darkened color.
374
361
  */
@@ -383,11 +370,11 @@ export class RGB extends Color {
383
370
 
384
371
  /**
385
372
  * Fades the RGB color by reducing its alpha value.
386
- *
373
+ *
387
374
  * @param value - The fade value to apply.
388
375
  * @returns A new RGB instance with the faded color.
389
376
  */
390
377
  fade(value: number): RGB {
391
378
  return new RGB(this.r, this.g, this.b, this.a * (1 - value));
392
379
  }
393
- }
380
+ }
@@ -58,7 +58,7 @@ describe('formatFloat function', () => {
58
58
 
59
59
  it('handles trailing zeros correctly', () => {
60
60
  expect(formatFloat(0.000123, 6)).toBe('0.000123');
61
- expect(formatFloat(0.000100, 6)).toBe('0.0001');
61
+ expect(formatFloat(0.0001, 6)).toBe('0.0001');
62
62
  expect(formatFloat(10.0, 1)).toBe('10');
63
63
  });
64
64
 
@@ -79,9 +79,7 @@ describe('formatFloat function', () => {
79
79
  });
80
80
 
81
81
  it('handles no unnecessary decimal points', () => {
82
- expect(formatFloat(10.000, 3)).toBe('10');
83
- expect(formatFloat(10.010, 3)).toBe('10.01');
82
+ expect(formatFloat(10.0, 3)).toBe('10');
83
+ expect(formatFloat(10.01, 3)).toBe('10.01');
84
84
  });
85
- })
86
-
87
-
85
+ });
@@ -1,5 +1,3 @@
1
-
2
-
3
1
  export function clamp(value: number, min: number, max: number): number {
4
2
  if (value == null || isNaN(value)) return min;
5
3
  if (value < min) return min;
@@ -16,4 +14,4 @@ export function mod(value: number, max: number): number {
16
14
 
17
15
  export function formatFloat(num: number, precision: number): string {
18
16
  return num.toFixed(precision).replace(/0+$/, '').replace(/\.$/, '');
19
- }
17
+ }
@@ -10,52 +10,55 @@ describe('guessStyle', () => {
10
10
  const vectorLayersShortbread: VectorLayer[] = getShortbreadVectorLayers();
11
11
 
12
12
  it('should build raster styles', () => {
13
- expect(guessStyle({ tiles }))
14
- .toStrictEqual({
15
- version: 8,
16
- sources: { rasterSource: { tiles, type: 'raster' } },
17
- layers: [{ id: 'raster', source: 'rasterSource', type: 'raster' }],
18
- });
13
+ expect(guessStyle({ tiles })).toStrictEqual({
14
+ version: 8,
15
+ sources: { rasterSource: { tiles, type: 'raster' } },
16
+ layers: [{ id: 'raster', source: 'rasterSource', type: 'raster' }],
17
+ });
19
18
  });
20
19
 
21
20
  it('should build vector inspector styles', () => {
22
- expect(guessStyle({ tiles, vector_layers: vectorLayersSomething }))
23
- .toStrictEqual({
24
- version: 8,
25
- sources: { vectorSource: { tiles, type: 'vector' } },
26
- layers: [
27
- {
28
- id: 'background',
29
- type: 'background',
30
- paint: { 'background-color': '#fff' },
31
- },
32
- {
33
- id: 'vectorSource-geometry-fill',
34
- type: 'fill',
35
- source: 'vectorSource',
36
- 'source-layer': 'geometry',
37
- filter: ['==', '$type', 'Polygon'],
38
- paint: { 'fill-antialias': true, 'fill-color': 'hsla(7,57%,56%,0.6)', 'fill-opacity': 0.3, 'fill-outline-color': 'hsla(7,57%,56%,0.6)' },
39
- },
40
- {
41
- id: 'vectorSource-geometry-line',
42
- type: 'line',
43
- source: 'vectorSource',
44
- 'source-layer': 'geometry',
45
- filter: ['==', '$type', 'LineString'],
46
- layout: { 'line-cap': 'round', 'line-join': 'round' },
47
- paint: { 'line-color': 'hsla(7,57%,56%,0.6)' },
48
- },
49
- {
50
- id: 'vectorSource-geometry-circle',
51
- type: 'circle',
52
- source: 'vectorSource',
53
- 'source-layer': 'geometry',
54
- filter: ['==', '$type', 'Point'],
55
- paint: { 'circle-color': 'hsla(7,57%,56%,0.6)', 'circle-radius': 2 },
21
+ expect(guessStyle({ tiles, vector_layers: vectorLayersSomething })).toStrictEqual({
22
+ version: 8,
23
+ sources: { vectorSource: { tiles, type: 'vector' } },
24
+ layers: [
25
+ {
26
+ id: 'background',
27
+ type: 'background',
28
+ paint: { 'background-color': '#fff' },
29
+ },
30
+ {
31
+ id: 'vectorSource-geometry-fill',
32
+ type: 'fill',
33
+ source: 'vectorSource',
34
+ 'source-layer': 'geometry',
35
+ filter: ['==', '$type', 'Polygon'],
36
+ paint: {
37
+ 'fill-antialias': true,
38
+ 'fill-color': 'hsla(7,57%,56%,0.6)',
39
+ 'fill-opacity': 0.3,
40
+ 'fill-outline-color': 'hsla(7,57%,56%,0.6)',
56
41
  },
57
- ],
58
- });
42
+ },
43
+ {
44
+ id: 'vectorSource-geometry-line',
45
+ type: 'line',
46
+ source: 'vectorSource',
47
+ 'source-layer': 'geometry',
48
+ filter: ['==', '$type', 'LineString'],
49
+ layout: { 'line-cap': 'round', 'line-join': 'round' },
50
+ paint: { 'line-color': 'hsla(7,57%,56%,0.6)' },
51
+ },
52
+ {
53
+ id: 'vectorSource-geometry-circle',
54
+ type: 'circle',
55
+ source: 'vectorSource',
56
+ 'source-layer': 'geometry',
57
+ filter: ['==', '$type', 'Point'],
58
+ paint: { 'circle-color': 'hsla(7,57%,56%,0.6)', 'circle-radius': 2 },
59
+ },
60
+ ],
61
+ });
59
62
  });
60
63
 
61
64
  it('should build shortbread vector styles', () => {
@@ -115,7 +118,10 @@ describe('guessStyle', () => {
115
118
  describe('absolute tile urls override baseUrl', () => {
116
119
  cases.forEach(({ type, tilejson }) => {
117
120
  it(type, () => {
118
- const style = guessStyle({ ...tilejson, tiles: ['https://example1.org/tiles/{z}/{x}/{y}'] }, { baseUrl: 'https://example2.org/' });
121
+ const style = guessStyle(
122
+ { ...tilejson, tiles: ['https://example1.org/tiles/{z}/{x}/{y}'] },
123
+ { baseUrl: 'https://example2.org/' }
124
+ );
119
125
  const source = Object.values(style.sources)[0] as VectorSourceSpecification;
120
126
  expect(source.tiles).toEqual(['https://example1.org/tiles/{z}/{x}/{y}']);
121
127
  });