@versatiles/style 5.6.0 → 5.8.0
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.
- package/README.MD +44 -38
- package/dist/index.d.ts +461 -75
- package/dist/index.js +651 -176
- package/dist/index.js.map +1 -1
- package/package.json +35 -33
- package/src/color/abstract.ts +142 -27
- package/src/color/hsl.test.ts +21 -20
- package/src/color/hsl.ts +88 -5
- package/src/color/hsv.test.ts +19 -18
- package/src/color/hsv.ts +78 -5
- package/src/color/index.test.ts +12 -30
- package/src/color/index.ts +0 -3
- package/src/color/random.test.ts +26 -4
- package/src/color/rgb.test.ts +25 -24
- package/src/color/rgb.ts +142 -8
- package/src/color/utils.test.ts +16 -15
- package/src/guess_style/guess_style.test.ts +1 -1
- package/src/guess_style/guess_style.ts +42 -2
- package/src/index.test.ts +43 -16
- package/src/index.ts +88 -3
- package/src/lib/utils.test.ts +1 -0
- package/src/lib/utils.ts +3 -6
- package/src/shortbread/layers.test.ts +1 -0
- package/src/shortbread/properties.test.ts +1 -0
- package/src/shortbread/template.test.ts +1 -0
- package/src/style_builder/decorator.test.ts +1 -0
- package/src/style_builder/recolor.test.ts +1 -0
- package/src/style_builder/recolor.ts +10 -10
- package/src/style_builder/style_builder.test.ts +1 -1
- package/src/style_builder/style_builder.ts +9 -11
- package/src/style_builder/types.ts +23 -58
- package/src/styles/index.ts +2 -0
- package/src/styles/shadow.ts +11 -0
- package/src/types/tilejson.test.ts +1 -2
- package/src/types/vector_layer.test.ts +1 -0
package/src/lib/utils.ts
CHANGED
|
@@ -15,13 +15,11 @@ export function deepClone<T>(obj: T): T {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
if (isSimpleObject(obj)) {
|
|
18
|
-
|
|
19
|
-
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, deepClone(value)]));
|
|
18
|
+
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, deepClone(value)])) as T;
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
if (obj instanceof Array) {
|
|
23
|
-
|
|
24
|
-
return obj.map((e: unknown) => deepClone(e));
|
|
22
|
+
return obj.map((e: unknown) => deepClone(e)) as T;
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
if (obj instanceof Color) {
|
|
@@ -87,8 +85,7 @@ export function deepMerge<T extends object>(source0: T, ...sources: Partial<T>[]
|
|
|
87
85
|
}
|
|
88
86
|
|
|
89
87
|
if (sourceValue instanceof Color) {
|
|
90
|
-
|
|
91
|
-
target[key] = sourceValue.clone();
|
|
88
|
+
target[key] = sourceValue.clone() as T[typeof key];
|
|
92
89
|
continue;
|
|
93
90
|
}
|
|
94
91
|
|
|
@@ -22,22 +22,22 @@ import { Color } from '../color/index.js';
|
|
|
22
22
|
*
|
|
23
23
|
* ```typescript
|
|
24
24
|
* const style = VersaTilesStyle.colorful({
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
25
|
+
* recolor: {
|
|
26
|
+
* rotate: 180,
|
|
27
|
+
* saturate: 0.5,
|
|
28
|
+
* brightness: 0.2,
|
|
29
|
+
* }
|
|
30
30
|
* };
|
|
31
31
|
* ```
|
|
32
32
|
*
|
|
33
33
|
* If you want do make you map simply brighter or darker, you can use the `blend` option:
|
|
34
34
|
* ```typescript
|
|
35
35
|
* const style = VersaTilesStyle.colorful({
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
36
|
+
* recolor: {
|
|
37
|
+
* blend: 0.5,
|
|
38
|
+
* blendColor: '#000000', // to blend all colors with black
|
|
39
|
+
* // or blendColor: '#FFFFFF', // to blend all colors with white
|
|
40
|
+
* }
|
|
41
41
|
* };
|
|
42
42
|
* ```
|
|
43
43
|
*
|
|
@@ -4,7 +4,7 @@ import { decorate } from './decorator.js';
|
|
|
4
4
|
import { CachedRecolor, getDefaultRecolorFlags } from './recolor.js';
|
|
5
5
|
import { basename, deepClone, resolveUrl } from '../lib/utils.js';
|
|
6
6
|
import type { MaplibreLayer, MaplibreLayerDefinition, StyleSpecification } from '../types/maplibre.js';
|
|
7
|
-
import
|
|
7
|
+
import { styleBuilderColorKeys, type StyleBuilderColors, type StyleBuilderFonts, type StyleBuilderOptions } from './types.js';
|
|
8
8
|
import type { StyleRules, StyleRulesOptions } from './types.js';
|
|
9
9
|
import { SpriteSpecification } from '@maplibre/maplibre-gl-style-spec';
|
|
10
10
|
|
|
@@ -21,10 +21,9 @@ export abstract class StyleBuilder {
|
|
|
21
21
|
public abstract readonly defaultFonts: StyleBuilderFonts;
|
|
22
22
|
|
|
23
23
|
public build(options?: StyleBuilderOptions): StyleSpecification {
|
|
24
|
-
|
|
25
24
|
options ??= {};
|
|
26
25
|
|
|
27
|
-
|
|
26
|
+
// @ts-expect-error globalThis may be undefined in some environments
|
|
28
27
|
const baseUrl = options.baseUrl ?? globalThis?.document?.location?.origin ?? 'https://tiles.versatiles.org';
|
|
29
28
|
const glyphs = options.glyphs ?? '/assets/glyphs/{fontstack}/{range}.pbf';
|
|
30
29
|
|
|
@@ -37,7 +36,7 @@ export abstract class StyleBuilder {
|
|
|
37
36
|
|
|
38
37
|
const colors = this.getColors(this.defaultColors);
|
|
39
38
|
if (options.colors) {
|
|
40
|
-
let key: keyof
|
|
39
|
+
let key: keyof StyleBuilderColors;
|
|
41
40
|
for (key in options.colors) {
|
|
42
41
|
const value = options.colors[key];
|
|
43
42
|
if (value != null) colors[key] = Color.parse(value);
|
|
@@ -104,9 +103,9 @@ export abstract class StyleBuilder {
|
|
|
104
103
|
return style;
|
|
105
104
|
}
|
|
106
105
|
|
|
107
|
-
public getColors(colors: StyleBuilderColors):
|
|
106
|
+
public getColors(colors: StyleBuilderColors): StyleBuilderColors<Color> {
|
|
108
107
|
const entriesString = Object.entries(colors) as [keyof StyleBuilderColors, string | Color][];
|
|
109
|
-
const result = Object.fromEntries(entriesString.map(([key, value]) => [key, Color.parse(value)])) as
|
|
108
|
+
const result = Object.fromEntries(entriesString.map(([key, value]) => [key, Color.parse(value)])) as StyleBuilderColors<Color>;
|
|
110
109
|
return result;
|
|
111
110
|
}
|
|
112
111
|
|
|
@@ -114,9 +113,9 @@ export abstract class StyleBuilder {
|
|
|
114
113
|
return {
|
|
115
114
|
baseUrl: '',
|
|
116
115
|
bounds: [
|
|
117
|
-
-180,
|
|
118
|
-
-85.0511287798066,
|
|
119
|
-
180,
|
|
116
|
+
-180,
|
|
117
|
+
-85.0511287798066,
|
|
118
|
+
180,
|
|
120
119
|
85.0511287798066
|
|
121
120
|
],
|
|
122
121
|
glyphs: '',
|
|
@@ -132,8 +131,7 @@ export abstract class StyleBuilder {
|
|
|
132
131
|
|
|
133
132
|
protected transformDefaultColors(callback: (color: Color) => Color): void {
|
|
134
133
|
const colors = this.getColors(this.defaultColors);
|
|
135
|
-
|
|
136
|
-
for (key in colors) {
|
|
134
|
+
for (const key of styleBuilderColorKeys) {
|
|
137
135
|
this.defaultColors[key] = callback(colors[key]);
|
|
138
136
|
}
|
|
139
137
|
}
|
|
@@ -5,113 +5,78 @@ import { SpriteSpecification } from '@maplibre/maplibre-gl-style-spec';
|
|
|
5
5
|
/** Represents language suffixes used in map styles. */
|
|
6
6
|
export type Language = 'de' | 'en' | null;
|
|
7
7
|
|
|
8
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Options for configuring the style builder.
|
|
10
|
+
*/
|
|
9
11
|
export interface StyleBuilderOptions {
|
|
10
12
|
/**
|
|
11
13
|
* The base URL for loading external resources like tiles, sprites, and fonts.
|
|
12
|
-
*
|
|
14
|
+
* @default document.location.origin (in the browser), or 'https://tiles.versatiles.org'
|
|
13
15
|
*/
|
|
14
16
|
baseUrl?: string;
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
/**
|
|
19
|
+
* The bounding box for the map, formatted as [sw.lng, sw.lat, ne.lng, ne.lat].
|
|
20
|
+
* @default [-180, -85.0511287798066, 180, 85.0511287798066]
|
|
21
|
+
*/
|
|
22
|
+
bounds?: [number, number, number, number];
|
|
21
23
|
|
|
22
24
|
/**
|
|
23
25
|
* The URL template for loading font glyphs, formatted with '{fontstack}' and '{range}' placeholders.
|
|
24
|
-
*
|
|
26
|
+
* @default '/assets/glyphs/{fontstack}/{range}.pbf'
|
|
25
27
|
*/
|
|
26
28
|
glyphs?: string;
|
|
27
29
|
|
|
28
30
|
/**
|
|
29
31
|
* The URL for loading sprite images and metadata.
|
|
30
|
-
*
|
|
32
|
+
* @default [{ id: 'basics', url: '/assets/sprites/basics/sprites' }]
|
|
31
33
|
*/
|
|
32
34
|
sprite?: SpriteSpecification;
|
|
33
35
|
|
|
34
36
|
/**
|
|
35
37
|
* An array of URL templates for loading map tiles, using '{z}', '{x}', and '{y}' placeholders.
|
|
36
|
-
*
|
|
38
|
+
* @default ['/tiles/osm/{z}/{x}/{y}']
|
|
37
39
|
*/
|
|
38
40
|
tiles?: string[];
|
|
39
41
|
|
|
40
42
|
/**
|
|
41
43
|
* If set to true, hides all map labels.
|
|
42
|
-
*
|
|
44
|
+
* @default false
|
|
43
45
|
*/
|
|
44
46
|
hideLabels?: boolean;
|
|
45
47
|
|
|
46
48
|
/**
|
|
47
49
|
* Set the language ('en', 'de') of all map labels.
|
|
48
50
|
* A null value means that the language of the country in which the label is drawn will be used.
|
|
49
|
-
*
|
|
51
|
+
* See also: {@link Language}
|
|
52
|
+
* @default null
|
|
50
53
|
*/
|
|
51
54
|
language?: Language;
|
|
52
55
|
|
|
53
56
|
/**
|
|
54
57
|
* An object specifying overrides for default color values, keyed by the color names.
|
|
58
|
+
* See also: {@link StyleBuilderColors}
|
|
55
59
|
*/
|
|
56
60
|
colors?: Partial<StyleBuilderColors>;
|
|
57
61
|
|
|
58
62
|
/**
|
|
59
63
|
* An object specifying overrides for default font names, keyed by the font names.
|
|
64
|
+
* See also: {@link StyleBuilderFonts}
|
|
60
65
|
*/
|
|
61
66
|
fonts?: Partial<StyleBuilderFonts>;
|
|
62
67
|
|
|
63
68
|
/**
|
|
64
69
|
* Options for color adjustments and transformations applied to the entire style.
|
|
70
|
+
* See also: {@link RecolorOptions}
|
|
65
71
|
*/
|
|
66
72
|
recolor?: RecolorOptions;
|
|
67
73
|
}
|
|
68
74
|
|
|
69
|
-
|
|
70
|
-
export
|
|
71
|
-
agriculture: Color | string;
|
|
72
|
-
boundary: Color | string;
|
|
73
|
-
building: Color | string;
|
|
74
|
-
buildingbg: Color | string;
|
|
75
|
-
burial: Color | string;
|
|
76
|
-
commercial: Color | string;
|
|
77
|
-
construction: Color | string;
|
|
78
|
-
cycle: Color | string;
|
|
79
|
-
danger: Color | string;
|
|
80
|
-
disputed: Color | string;
|
|
81
|
-
education: Color | string;
|
|
82
|
-
foot: Color | string;
|
|
83
|
-
glacier: Color | string;
|
|
84
|
-
grass: Color | string;
|
|
85
|
-
hospital: Color | string;
|
|
86
|
-
industrial: Color | string;
|
|
87
|
-
label: Color | string;
|
|
88
|
-
labelHalo: Color | string;
|
|
89
|
-
land: Color | string;
|
|
90
|
-
leisure: Color | string;
|
|
91
|
-
motorway: Color | string;
|
|
92
|
-
motorwaybg: Color | string;
|
|
93
|
-
park: Color | string;
|
|
94
|
-
parking: Color | string;
|
|
95
|
-
poi: Color | string;
|
|
96
|
-
prison: Color | string;
|
|
97
|
-
rail: Color | string;
|
|
98
|
-
residential: Color | string;
|
|
99
|
-
rock: Color | string;
|
|
100
|
-
sand: Color | string;
|
|
101
|
-
shield: Color | string;
|
|
102
|
-
street: Color | string;
|
|
103
|
-
streetbg: Color | string;
|
|
104
|
-
subway: Color | string;
|
|
105
|
-
symbol: Color | string;
|
|
106
|
-
trunk: Color | string;
|
|
107
|
-
trunkbg: Color | string;
|
|
108
|
-
waste: Color | string;
|
|
109
|
-
water: Color | string;
|
|
110
|
-
wetland: Color | string;
|
|
111
|
-
wood: Color | string;
|
|
112
|
-
};
|
|
75
|
+
export type StyleBuilderColorKey = 'agriculture' | 'boundary' | 'building' | 'buildingbg' | 'burial' | 'commercial' | 'construction' | 'cycle' | 'danger' | 'disputed' | 'education' | 'foot' | 'glacier' | 'grass' | 'hospital' | 'industrial' | 'label' | 'labelHalo' | 'land' | 'leisure' | 'motorway' | 'motorwaybg' | 'park' | 'parking' | 'poi' | 'prison' | 'rail' | 'residential' | 'rock' | 'sand' | 'shield' | 'street' | 'streetbg' | 'subway' | 'symbol' | 'trunk' | 'trunkbg' | 'waste' | 'water' | 'wetland' | 'wood';
|
|
76
|
+
export const styleBuilderColorKeys: StyleBuilderColorKey[] = ['agriculture', 'boundary', 'building', 'buildingbg', 'burial', 'commercial', 'construction', 'cycle', 'danger', 'disputed', 'education', 'foot', 'glacier', 'grass', 'hospital', 'industrial', 'label', 'labelHalo', 'land', 'leisure', 'motorway', 'motorwaybg', 'park', 'parking', 'poi', 'prison', 'rail', 'residential', 'rock', 'sand', 'shield', 'street', 'streetbg', 'subway', 'symbol', 'trunk', 'trunkbg', 'waste', 'water', 'wetland', 'wood'] as const;
|
|
113
77
|
|
|
114
|
-
|
|
78
|
+
/** Records string values for color properties in a style builder. */
|
|
79
|
+
export type StyleBuilderColors<T = Color | string> = Record<StyleBuilderColorKey, T>;
|
|
115
80
|
|
|
116
81
|
/** Records string values for font properties in a style builder. */
|
|
117
82
|
export type StyleBuilderFonts = {
|
|
@@ -124,7 +89,7 @@ export interface StyleRulesOptions {
|
|
|
124
89
|
/**
|
|
125
90
|
* The set of colors used in the style builder.
|
|
126
91
|
*/
|
|
127
|
-
colors:
|
|
92
|
+
colors: StyleBuilderColors<Color>;
|
|
128
93
|
|
|
129
94
|
/**
|
|
130
95
|
* The set of fonts used in the style builder.
|
package/src/styles/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { StyleSpecification } from '@maplibre/maplibre-gl-style-spec';
|
|
|
8
8
|
import Colorful from './colorful.js';
|
|
9
9
|
import Eclipse from './eclipse.js';
|
|
10
10
|
import Graybeard from './graybeard.js';
|
|
11
|
+
import Shadow from './shadow.js';
|
|
11
12
|
import Neutrino from './neutrino.js';
|
|
12
13
|
import Empty from './empty.js';
|
|
13
14
|
|
|
@@ -29,5 +30,6 @@ function getStyleBuilder(styleBuilder: new () => StyleBuilder): StyleBuilderFunc
|
|
|
29
30
|
export const colorful = getStyleBuilder(Colorful);
|
|
30
31
|
export const eclipse = getStyleBuilder(Eclipse);
|
|
31
32
|
export const graybeard = getStyleBuilder(Graybeard);
|
|
33
|
+
export const shadow = getStyleBuilder(Shadow);
|
|
32
34
|
export const neutrino = getStyleBuilder(Neutrino);
|
|
33
35
|
export const empty = getStyleBuilder(Empty);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Colorful from './colorful.js';
|
|
2
|
+
|
|
3
|
+
export default class Shadow extends Colorful {
|
|
4
|
+
public readonly name: string = 'Shadow';
|
|
5
|
+
|
|
6
|
+
public constructor() {
|
|
7
|
+
super();
|
|
8
|
+
|
|
9
|
+
this.transformDefaultColors(color => color.saturate(-1).invert().brightness(0.2));
|
|
10
|
+
}
|
|
11
|
+
}
|