@versatiles/style 5.8.4 → 5.9.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.
Files changed (54) hide show
  1. package/README.md +24 -18
  2. package/dist/index.d.ts +20 -14
  3. package/dist/index.js +151 -83
  4. package/dist/index.js.map +1 -1
  5. package/package.json +17 -18
  6. package/src/color/abstract.ts +0 -202
  7. package/src/color/hsl.test.ts +0 -177
  8. package/src/color/hsl.ts +0 -201
  9. package/src/color/hsv.test.ts +0 -169
  10. package/src/color/hsv.ts +0 -189
  11. package/src/color/index.test.ts +0 -99
  12. package/src/color/index.ts +0 -35
  13. package/src/color/random.test.ts +0 -57
  14. package/src/color/random.ts +0 -267
  15. package/src/color/rgb.test.ts +0 -215
  16. package/src/color/rgb.ts +0 -380
  17. package/src/color/utils.test.ts +0 -85
  18. package/src/color/utils.ts +0 -17
  19. package/src/guess_style/guess_style.test.ts +0 -140
  20. package/src/guess_style/guess_style.ts +0 -249
  21. package/src/guess_style/index.ts +0 -2
  22. package/src/index.test.ts +0 -131
  23. package/src/index.ts +0 -113
  24. package/src/lib/utils.test.ts +0 -198
  25. package/src/lib/utils.ts +0 -132
  26. package/src/shortbread/index.ts +0 -2
  27. package/src/shortbread/layers.test.ts +0 -81
  28. package/src/shortbread/layers.ts +0 -602
  29. package/src/shortbread/properties.test.ts +0 -44
  30. package/src/shortbread/properties.ts +0 -156
  31. package/src/shortbread/template.test.ts +0 -49
  32. package/src/shortbread/template.ts +0 -336
  33. package/src/style_builder/decorator.test.ts +0 -68
  34. package/src/style_builder/decorator.ts +0 -143
  35. package/src/style_builder/recolor.test.ts +0 -328
  36. package/src/style_builder/recolor.ts +0 -237
  37. package/src/style_builder/style_builder.test.ts +0 -148
  38. package/src/style_builder/style_builder.ts +0 -138
  39. package/src/style_builder/types.ts +0 -195
  40. package/src/styles/LICENSE.md +0 -41
  41. package/src/styles/colorful.test.ts +0 -91
  42. package/src/styles/colorful.ts +0 -1177
  43. package/src/styles/eclipse.ts +0 -11
  44. package/src/styles/empty.ts +0 -10
  45. package/src/styles/graybeard.ts +0 -11
  46. package/src/styles/index.ts +0 -32
  47. package/src/styles/neutrino.ts +0 -427
  48. package/src/styles/shadow.ts +0 -11
  49. package/src/types/index.ts +0 -5
  50. package/src/types/maplibre.ts +0 -25
  51. package/src/types/tilejson.test.ts +0 -96
  52. package/src/types/tilejson.ts +0 -125
  53. package/src/types/vector_layer.test.ts +0 -68
  54. package/src/types/vector_layer.ts +0 -69
package/src/color/rgb.ts DELETED
@@ -1,380 +0,0 @@
1
- import { HSL } from './hsl.js';
2
- import { HSV } from './hsv.js';
3
- import { Color } from './abstract.js';
4
- import { clamp, formatFloat } from './utils.js';
5
-
6
- /**
7
- * Represents an RGB color with optional alpha transparency.
8
- *
9
- * @extends Color
10
- */
11
- export class RGB extends Color {
12
- /**
13
- * Red component (0-255).
14
- */
15
- readonly r;
16
-
17
- /**
18
- * Green component (0-255).
19
- */
20
- readonly g;
21
-
22
- /**
23
- * Blue component (0-255).
24
- */
25
- readonly b;
26
-
27
- /**
28
- * Alpha component (0-1).
29
- */
30
- readonly a;
31
-
32
- /**
33
- * Creates an instance of RGB.
34
- *
35
- * @param r - Red component (0-255).
36
- * @param g - Green component (0-255).
37
- * @param b - Blue component (0-255).
38
- * @param a - Alpha component (0-1), defaults to 1.
39
- */
40
- constructor(r: number, g: number, b: number, a: number = 1) {
41
- super();
42
- this.r = clamp(r, 0, 255);
43
- this.g = clamp(g, 0, 255);
44
- this.b = clamp(b, 0, 255);
45
- this.a = clamp(a, 0, 1);
46
- }
47
-
48
- /**
49
- * Creates a clone of the current RGB color.
50
- *
51
- * @returns A new RGB instance with the same color values.
52
- */
53
- clone(): RGB {
54
- return new RGB(this.r, this.g, this.b, this.a);
55
- }
56
-
57
- /**
58
- * Returns the RGB color as an array.
59
- *
60
- * @returns An array containing the red, green, blue, and alpha components.
61
- */
62
- asArray(): [number, number, number, number] {
63
- return [this.r, this.g, this.b, this.a];
64
- }
65
-
66
- /**
67
- * Rounds the RGB color components to the nearest integer.
68
- *
69
- * @returns A new RGB instance with rounded color values.
70
- */
71
- round(): RGB {
72
- return new RGB(Math.round(this.r), Math.round(this.g), Math.round(this.b), Math.round(this.a * 1000) / 1000);
73
- }
74
-
75
- /**
76
- * Returns the RGB color as a string.
77
- *
78
- * @returns A string representation of the RGB color in either `rgb` or `rgba` format.
79
- */
80
- asString(): string {
81
- if (this.a === 1) {
82
- return `rgb(${this.r.toFixed(0)},${this.g.toFixed(0)},${this.b.toFixed(0)})`;
83
- } else {
84
- return `rgba(${this.r.toFixed(0)},${this.g.toFixed(0)},${this.b.toFixed(0)},${formatFloat(this.a, 3)})`;
85
- }
86
- }
87
-
88
- /**
89
- * Returns the RGB color as a hexadecimal string.
90
- *
91
- * @returns A string representation of the RGB color in hexadecimal format.
92
- */
93
- asHex(): string {
94
- const r = Math.round(this.r).toString(16).padStart(2, '0');
95
- const g = Math.round(this.g).toString(16).padStart(2, '0');
96
- const b = Math.round(this.b).toString(16).padStart(2, '0');
97
-
98
- if (this.a === 1) {
99
- return `#${r}${g}${b}`.toUpperCase();
100
- } else {
101
- const a = Math.round(this.a * 255)
102
- .toString(16)
103
- .padStart(2, '0');
104
- return `#${r}${g}${b}${a}`.toUpperCase();
105
- }
106
- }
107
-
108
- /**
109
- * Converts the RGB color to an HSL color.
110
- *
111
- * @returns An HSL instance representing the same color.
112
- */
113
- asHSL(): HSL {
114
- const r = this.r / 255;
115
- const g = this.g / 255;
116
- const b = this.b / 255;
117
- const min = Math.min(r, g, b);
118
- const max = Math.max(r, g, b);
119
- const delta = max - min;
120
- let h = 0;
121
- let s = 0;
122
-
123
- if (max === min) h = 0;
124
- else if (r === max) h = (g - b) / delta;
125
- else if (g === max) h = 2 + (b - r) / delta;
126
- else if (b === max) h = 4 + (r - g) / delta;
127
-
128
- h = Math.min(h * 60, 360);
129
- if (h < 0) h += 360;
130
-
131
- const l = (min + max) / 2;
132
-
133
- if (max === min) s = 0;
134
- else if (l <= 0.5) s = delta / (max + min);
135
- else s = delta / (2 - max - min);
136
-
137
- return new HSL(h, s * 100, l * 100, this.a);
138
- }
139
-
140
- /**
141
- * Converts the RGB color to an HSV color.
142
- *
143
- * @returns An HSV instance representing the same color.
144
- */
145
- asHSV(): HSV {
146
- const r = this.r / 255;
147
- const g = this.g / 255;
148
- const b = this.b / 255;
149
- const v = Math.max(r, g, b);
150
- const diff = v - Math.min(r, g, b);
151
-
152
- let h = 0;
153
- let s = 0;
154
- if (diff !== 0) {
155
- function diffc(c: number): number {
156
- return (v - c) / 6 / diff + 1 / 2;
157
- }
158
-
159
- s = diff / v;
160
- const rdif = diffc(r);
161
- const gdif = diffc(g);
162
- const bdif = diffc(b);
163
-
164
- if (r === v) h = bdif - gdif;
165
- else if (g === v) h = 1 / 3 + rdif - bdif;
166
- else if (b === v) h = 2 / 3 + gdif - rdif;
167
-
168
- if (h < 0) h += 1;
169
- else if (h > 1) h -= 1;
170
- }
171
-
172
- return new HSV(h * 360, s * 100, v * 100, this.a);
173
- }
174
-
175
- /**
176
- * Returns the RGB color.
177
- *
178
- * @returns The current RGB instance.
179
- */
180
- asRGB(): RGB {
181
- return this.clone();
182
- }
183
-
184
- /**
185
- * Returns the RGB color.
186
- *
187
- * @returns The current RGB instance.
188
- */
189
- toRGB(): RGB {
190
- return this;
191
- }
192
-
193
- /**
194
- * Parses a string or Color instance into an RGB color.
195
- *
196
- * @param input - The input string or Color instance to parse.
197
- * @returns A new RGB instance representing the parsed color.
198
- * @throws Will throw an error if the input string is not a valid RGB color string.
199
- */
200
- static parse(input: string | Color): RGB {
201
- if (input instanceof Color) return input.asRGB();
202
-
203
- input = input.toLowerCase().replaceAll(/[^0-9a-z.#,()]/g, '');
204
-
205
- let match;
206
-
207
- match = input.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/);
208
- if (match) {
209
- const r = parseInt(match[1], 16);
210
- const g = parseInt(match[2], 16);
211
- const b = parseInt(match[3], 16);
212
- const a = match[4] ? parseInt(match[4], 16) / 255 : 1;
213
- return new RGB(r, g, b, a);
214
- }
215
-
216
- match = input.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/);
217
- if (match) {
218
- const r = parseInt(match[1], 16) * 17;
219
- const g = parseInt(match[2], 16) * 17;
220
- const b = parseInt(match[3], 16) * 17;
221
- const a = match[4] ? parseInt(match[4], 16) / 15 : 1;
222
- return new RGB(r, g, b, a);
223
- }
224
-
225
- input = input.trim().toLowerCase().replaceAll(' ', '');
226
-
227
- match = input.match(/^rgb\((\d+),(\d+),(\d+)\)$/);
228
- if (match) {
229
- const r = parseInt(match[1]);
230
- const g = parseInt(match[2]);
231
- const b = parseInt(match[3]);
232
- return new RGB(r, g, b);
233
- }
234
-
235
- match = input.match(/^rgba\((\d+),(\d+),(\d+),([.\d]+)\)$/);
236
- if (match) {
237
- const r = parseInt(match[1]);
238
- const g = parseInt(match[2]);
239
- const b = parseInt(match[3]);
240
- const a = parseFloat(match[4]);
241
- return new RGB(r, g, b, a);
242
- }
243
-
244
- throw new Error(`Invalid RGB color string: "${input}"`);
245
- }
246
-
247
- /**
248
- * Adjusts the gamma of the RGB color.
249
- *
250
- * @param value - The gamma value to apply.
251
- * @returns A new RGB instance with the adjusted gamma.
252
- */
253
- gamma(value: number): RGB {
254
- if (value < 1e-3) value = 1e-3;
255
- if (value > 1e3) value = 1e3;
256
- return new RGB(
257
- Math.pow(this.r / 255, value) * 255,
258
- Math.pow(this.g / 255, value) * 255,
259
- Math.pow(this.b / 255, value) * 255,
260
- this.a
261
- );
262
- }
263
-
264
- /**
265
- * Inverts the RGB color.
266
- *
267
- * @returns A new RGB instance with the inverted color values.
268
- */
269
- invert(): RGB {
270
- return new RGB(255 - this.r, 255 - this.g, 255 - this.b, this.a);
271
- }
272
-
273
- /**
274
- * Adjusts the contrast of the RGB color.
275
- *
276
- * @param value - The contrast value to apply.
277
- * @returns A new RGB instance with the adjusted contrast.
278
- */
279
- contrast(value: number): RGB {
280
- if (value < 0) value = 0;
281
- if (value > 1e6) value = 1e6;
282
- return new RGB(
283
- clamp((this.r - 127.5) * value + 127.5, 0, 255),
284
- clamp((this.g - 127.5) * value + 127.5, 0, 255),
285
- clamp((this.b - 127.5) * value + 127.5, 0, 255),
286
- this.a
287
- );
288
- }
289
-
290
- /**
291
- * Adjusts the brightness of the RGB color.
292
- *
293
- * @param value - The brightness value to apply.
294
- * @returns A new RGB instance with the adjusted brightness.
295
- */
296
- brightness(value: number): RGB {
297
- if (value < -1) value = -1;
298
- if (value > 1) value = 1;
299
- const a = 1 - Math.abs(value);
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);
302
- }
303
-
304
- /**
305
- * Tints the RGB color with another color.
306
- *
307
- * @param value - The tint value to apply.
308
- * @param tintColor - The color to use for tinting.
309
- * @returns A new RGB instance with the applied tint.
310
- */
311
- tint(value: number, tintColor: Color): RGB {
312
- if (value < 0) value = 0;
313
- if (value > 1) value = 1;
314
- const rgbNew = this.setHue(tintColor.asHSV().h).asRGB();
315
- return new RGB(
316
- this.r * (1 - value) + value * rgbNew.r,
317
- this.g * (1 - value) + value * rgbNew.g,
318
- this.b * (1 - value) + value * rgbNew.b,
319
- this.a
320
- );
321
- }
322
-
323
- /**
324
- * Blends the RGB color with another color.
325
- *
326
- * @param value - The blend value to apply.
327
- * @param blendColor - The color to blend with.
328
- * @returns A new RGB instance with the blended color.
329
- */
330
- blend(value: number, blendColor: Color): RGB {
331
- value = clamp(value ?? 0, 0, 1);
332
- const rgbNew = blendColor.asRGB();
333
- return new RGB(
334
- this.r * (1 - value) + value * rgbNew.r,
335
- this.g * (1 - value) + value * rgbNew.g,
336
- this.b * (1 - value) + value * rgbNew.b,
337
- this.a
338
- );
339
- }
340
-
341
- /**
342
- * Lightens the RGB color.
343
- *
344
- * @param ratio - The ratio to lighten the color by.
345
- * @returns A new RGB instance with the lightened color.
346
- */
347
- lighten(ratio: number): RGB {
348
- return new RGB(
349
- clamp(255 - (255 - this.r) * (1 - ratio), 0, 255),
350
- clamp(255 - (255 - this.g) * (1 - ratio), 0, 255),
351
- clamp(255 - (255 - this.b) * (1 - ratio), 0, 255),
352
- this.a
353
- );
354
- }
355
-
356
- /**
357
- * Darkens the RGB color.
358
- *
359
- * @param ratio - The ratio to darken the color by.
360
- * @returns A new RGB instance with the darkened color.
361
- */
362
- darken(ratio: number): RGB {
363
- return new RGB(
364
- clamp(this.r * (1 - ratio), 0, 255),
365
- clamp(this.g * (1 - ratio), 0, 255),
366
- clamp(this.b * (1 - ratio), 0, 255),
367
- this.a
368
- );
369
- }
370
-
371
- /**
372
- * Fades the RGB color by reducing its alpha value.
373
- *
374
- * @param value - The fade value to apply.
375
- * @returns A new RGB instance with the faded color.
376
- */
377
- fade(value: number): RGB {
378
- return new RGB(this.r, this.g, this.b, this.a * (1 - value));
379
- }
380
- }
@@ -1,85 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { clamp, formatFloat, mod } from './utils.js';
3
-
4
- describe('clamp function', () => {
5
- it('returns the number itself if within the range', () => {
6
- expect(clamp(5, 0, 10)).toBe(5);
7
- expect(clamp(0, -10, 10)).toBe(0);
8
- expect(clamp(-5, -10, 0)).toBe(-5);
9
- });
10
-
11
- it('returns the minimum value if number is below range', () => {
12
- expect(clamp(-5, 0, 10)).toBe(0);
13
- expect(clamp(-15, -10, 10)).toBe(-10);
14
- });
15
-
16
- it('returns the maximum value if number is above range', () => {
17
- expect(clamp(15, 0, 10)).toBe(10);
18
- expect(clamp(20, -10, 10)).toBe(10);
19
- });
20
-
21
- it('handles edge cases with boundaries', () => {
22
- expect(clamp(0, 0, 10)).toBe(0);
23
- expect(clamp(10, 0, 10)).toBe(10);
24
- });
25
- });
26
-
27
- describe('mod function', () => {
28
- it('returns the correct modulus for positive numbers', () => {
29
- expect(mod(10, 3)).toBe(1);
30
- expect(mod(15, 4)).toBe(3);
31
- });
32
-
33
- it('handles negative numbers correctly', () => {
34
- expect(mod(-10, 3)).toBe(2);
35
- expect(mod(-15, 4)).toBe(1);
36
- });
37
-
38
- it('returns 0 for numbers that are exact multiples of max', () => {
39
- expect(mod(9, 3)).toBe(0);
40
- expect(mod(20, 5)).toBe(0);
41
- });
42
-
43
- it('returns 0 for zero input with positive max', () => {
44
- expect(mod(0, 5)).toBe(0);
45
- });
46
-
47
- it('handles edge cases with 1 as max', () => {
48
- expect(mod(10, 1)).toBe(0);
49
- expect(mod(-10, 1)).toBe(0);
50
- });
51
- });
52
- describe('formatFloat function', () => {
53
- it('formats numbers with specified precision correctly', () => {
54
- expect(formatFloat(123.4567, 2)).toBe('123.46');
55
- expect(formatFloat(123.4, 2)).toBe('123.4');
56
- expect(formatFloat(123.0, 2)).toBe('123');
57
- });
58
-
59
- it('handles trailing zeros correctly', () => {
60
- expect(formatFloat(0.000123, 6)).toBe('0.000123');
61
- expect(formatFloat(0.0001, 6)).toBe('0.0001');
62
- expect(formatFloat(10.0, 1)).toBe('10');
63
- });
64
-
65
- it('handles edge cases with small numbers and high precision', () => {
66
- expect(formatFloat(0.0000001234, 10)).toBe('0.0000001234');
67
- expect(formatFloat(0.0000001234, 5)).toBe('0');
68
- });
69
-
70
- it('handles large numbers correctly', () => {
71
- expect(formatFloat(123456789.123456, 3)).toBe('123456789.123');
72
- expect(formatFloat(123456789.0, 5)).toBe('123456789');
73
- });
74
-
75
- it('handles zero and negative numbers correctly', () => {
76
- expect(formatFloat(0, 2)).toBe('0');
77
- expect(formatFloat(-123.456, 1)).toBe('-123.5');
78
- expect(formatFloat(-0.000123, 6)).toBe('-0.000123');
79
- });
80
-
81
- it('handles no unnecessary decimal points', () => {
82
- expect(formatFloat(10.0, 3)).toBe('10');
83
- expect(formatFloat(10.01, 3)).toBe('10.01');
84
- });
85
- });
@@ -1,17 +0,0 @@
1
- export function clamp(value: number, min: number, max: number): number {
2
- if (value == null || isNaN(value)) return min;
3
- if (value < min) return min;
4
- if (value > max) return max;
5
- return value;
6
- }
7
-
8
- export function mod(value: number, max: number): number {
9
- value = value % max;
10
- if (value < 0) value += max;
11
- if (value == 0) return 0;
12
- return value;
13
- }
14
-
15
- export function formatFloat(num: number, precision: number): string {
16
- return num.toFixed(precision).replace(/0+$/, '').replace(/\.$/, '');
17
- }
@@ -1,140 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import type { TileJSONSpecification, VectorLayer } from '../types/index.js';
3
- import { guessStyle } from './guess_style.js';
4
- import { getShortbreadVectorLayers } from '../shortbread/template.js';
5
- import { SourceSpecification, StyleSpecification, VectorSourceSpecification } from '@maplibre/maplibre-gl-style-spec';
6
-
7
- describe('guessStyle', () => {
8
- const tiles = ['https://example.com/tiles/{z}/{x}/{y}'];
9
- const vectorLayersSomething: VectorLayer[] = [{ id: 'geometry', fields: { label: 'String', height: 'Number' } }];
10
- const vectorLayersShortbread: VectorLayer[] = getShortbreadVectorLayers();
11
-
12
- it('should build raster styles', () => {
13
- expect(guessStyle({ tiles })).toStrictEqual({
14
- version: 8,
15
- sources: { rasterSource: { tiles, type: 'raster' } },
16
- layers: [{ id: 'raster', source: 'rasterSource', type: 'raster' }],
17
- });
18
- });
19
-
20
- it('should build vector inspector styles', () => {
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)',
41
- },
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
- });
62
- });
63
-
64
- it('should build shortbread vector styles', () => {
65
- const style = guessStyle({ tiles, vector_layers: vectorLayersShortbread }, { baseUrl: 'http://example.com' });
66
-
67
- expect(style.layers.length).toBe(309);
68
- style.layers = [];
69
-
70
- expect(style).toStrictEqual({
71
- glyphs: 'http://example.com/assets/glyphs/{fontstack}/{range}.pbf',
72
- metadata: {
73
- license: 'https://creativecommons.org/publicdomain/zero/1.0/',
74
- },
75
- name: 'versatiles-colorful',
76
- sprite: [{ id: 'basics', url: 'http://example.com/assets/sprites/basics/sprites' }],
77
- layers: [],
78
- sources: {
79
- 'versatiles-shortbread': {
80
- attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
81
- bounds: [-180, -85.0511287798066, 180, 85.0511287798066],
82
- maxzoom: 14,
83
- minzoom: 0,
84
- scheme: 'xyz',
85
- tiles,
86
- type: 'vector',
87
- },
88
- },
89
- version: 8,
90
- });
91
- });
92
-
93
- const cases: { type: string; tilejson: TileJSONSpecification }[] = [
94
- { type: 'image', tilejson: { tiles } },
95
- { type: 'inspector', tilejson: { tiles, vector_layers: vectorLayersSomething } },
96
- ];
97
-
98
- function getSource(style: StyleSpecification): SourceSpecification {
99
- return Object.values(style.sources)[0];
100
- }
101
-
102
- describe('minzoom sets minzoom', () => {
103
- cases.forEach(({ type, tilejson }) => {
104
- it(type, () => {
105
- expect(getSource(guessStyle({ ...tilejson, minzoom: 5 }))).toHaveProperty('minzoom', 5);
106
- });
107
- });
108
- });
109
-
110
- describe('maxzoom sets maxzoom', () => {
111
- cases.forEach(({ type, tilejson }) => {
112
- it(type, () => {
113
- expect(getSource(guessStyle({ ...tilejson, maxzoom: 5 }))).toHaveProperty('maxzoom', 5);
114
- });
115
- });
116
- });
117
-
118
- describe('absolute tile urls override baseUrl', () => {
119
- cases.forEach(({ type, tilejson }) => {
120
- it(type, () => {
121
- const style = guessStyle(
122
- { ...tilejson, tiles: ['https://example1.org/tiles/{z}/{x}/{y}'] },
123
- { baseUrl: 'https://example2.org/' }
124
- );
125
- const source = Object.values(style.sources)[0] as VectorSourceSpecification;
126
- expect(source.tiles).toEqual(['https://example1.org/tiles/{z}/{x}/{y}']);
127
- });
128
- });
129
- });
130
-
131
- describe('relative tile urls are resolved with baseUrl', () => {
132
- cases.forEach(({ type, tilejson }) => {
133
- it(type, () => {
134
- const style = guessStyle({ ...tilejson, tiles: ['./{z}/{x}/{y}'] }, { baseUrl: 'https://example2.org/tiles/' });
135
- const source = Object.values(style.sources)[0] as VectorSourceSpecification;
136
- expect(source.tiles).toEqual(['https://example2.org/tiles/{z}/{x}/{y}']);
137
- });
138
- });
139
- });
140
- });