@versatiles/style 5.2.5 → 5.2.7
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/dist/index.d.ts +274 -14
- package/dist/index.js +3650 -11
- package/dist/index.js.map +1 -0
- package/package.json +8 -7
- package/src/color/abstract.ts +83 -0
- package/src/color/hsl.test.ts +182 -0
- package/src/color/hsl.ts +122 -0
- package/src/color/hsv.test.ts +174 -0
- package/src/color/hsv.ts +100 -0
- package/src/color/index.test.ts +119 -0
- package/src/color/index.ts +38 -0
- package/src/color/random.test.ts +35 -0
- package/src/color/random.ts +165 -0
- package/src/color/rgb.test.ts +227 -0
- package/src/color/rgb.ts +248 -0
- package/src/color/utils.test.ts +86 -0
- package/src/color/utils.ts +13 -0
- package/src/guess_style/guess_style.test.ts +134 -0
- package/src/guess_style/guess_style.ts +166 -0
- package/{dist/guess_style/index.d.ts → src/guess_style/index.ts} +1 -0
- package/src/index.test.ts +77 -0
- package/src/index.ts +18 -0
- package/src/lib/utils.test.ts +197 -0
- package/src/lib/utils.ts +134 -0
- package/{dist/shortbread/index.d.ts → src/shortbread/index.ts} +1 -0
- package/src/shortbread/layers.test.ts +36 -0
- package/src/shortbread/layers.ts +564 -0
- package/src/shortbread/properties.test.ts +44 -0
- package/src/shortbread/properties.ts +142 -0
- package/src/shortbread/template.test.ts +43 -0
- package/src/shortbread/template.ts +343 -0
- package/src/style_builder/decorator.test.ts +67 -0
- package/src/style_builder/decorator.ts +135 -0
- package/src/style_builder/recolor.test.ts +306 -0
- package/src/style_builder/recolor.ts +110 -0
- package/src/style_builder/style_builder.test.ts +103 -0
- package/src/style_builder/style_builder.ts +134 -0
- package/src/style_builder/types.ts +141 -0
- package/src/styles/LICENSE.md +41 -0
- package/src/styles/colorful.ts +1041 -0
- package/src/styles/eclipse.ts +11 -0
- package/{dist/styles/empty.d.ts → src/styles/empty.ts} +7 -3
- package/src/styles/graybeard.ts +11 -0
- package/src/styles/index.ts +33 -0
- package/src/styles/neutrino.ts +429 -0
- package/{dist/types/index.d.ts → src/types/index.ts} +1 -0
- package/{dist/types/maplibre.d.ts → src/types/maplibre.ts} +3 -0
- package/src/types/tilejson.test.ts +94 -0
- package/src/types/tilejson.ts +125 -0
- package/src/types/vector_layer.test.ts +64 -0
- package/src/types/vector_layer.ts +69 -0
- package/dist/color/abstract.d.ts +0 -34
- package/dist/color/abstract.js +0 -53
- package/dist/color/hsl.d.ts +0 -23
- package/dist/color/hsl.js +0 -98
- package/dist/color/hsv.d.ts +0 -20
- package/dist/color/hsv.js +0 -100
- package/dist/color/index.d.ts +0 -6
- package/dist/color/index.js +0 -29
- package/dist/color/random.d.ts +0 -9
- package/dist/color/random.js +0 -134
- package/dist/color/rgb.d.ts +0 -28
- package/dist/color/rgb.js +0 -195
- package/dist/color/utils.d.ts +0 -3
- package/dist/color/utils.js +0 -10
- package/dist/guess_style/guess_style.d.ts +0 -8
- package/dist/guess_style/guess_style.js +0 -147
- package/dist/guess_style/index.js +0 -2
- package/dist/lib/utils.d.ts +0 -6
- package/dist/lib/utils.js +0 -126
- package/dist/shortbread/index.js +0 -3
- package/dist/shortbread/layers.d.ts +0 -5
- package/dist/shortbread/layers.js +0 -521
- package/dist/shortbread/properties.d.ts +0 -7
- package/dist/shortbread/properties.js +0 -125
- package/dist/shortbread/template.d.ts +0 -4
- package/dist/shortbread/template.js +0 -339
- package/dist/style_builder/decorator.d.ts +0 -4
- package/dist/style_builder/decorator.js +0 -127
- package/dist/style_builder/recolor.d.ts +0 -22
- package/dist/style_builder/recolor.js +0 -89
- package/dist/style_builder/style_builder.d.ts +0 -15
- package/dist/style_builder/style_builder.js +0 -106
- package/dist/style_builder/types.d.ts +0 -122
- package/dist/style_builder/types.js +0 -3
- package/dist/styles/colorful.d.ts +0 -11
- package/dist/styles/colorful.js +0 -956
- package/dist/styles/eclipse.d.ts +0 -5
- package/dist/styles/eclipse.js +0 -9
- package/dist/styles/empty.js +0 -8
- package/dist/styles/graybeard.d.ts +0 -5
- package/dist/styles/graybeard.js +0 -9
- package/dist/styles/index.d.ts +0 -11
- package/dist/styles/index.js +0 -20
- package/dist/styles/neutrino.d.ts +0 -11
- package/dist/styles/neutrino.js +0 -401
- package/dist/types/index.js +0 -3
- package/dist/types/maplibre.js +0 -2
- package/dist/types/tilejson.d.ts +0 -32
- package/dist/types/tilejson.js +0 -87
- package/dist/types/vector_layer.d.ts +0 -14
- package/dist/types/vector_layer.js +0 -51
|
@@ -1,339 +0,0 @@
|
|
|
1
|
-
const maxzoom = 14;
|
|
2
|
-
export function getShortbreadTemplate() {
|
|
3
|
-
return {
|
|
4
|
-
version: 8,
|
|
5
|
-
name: 'versatiles',
|
|
6
|
-
metadata: {
|
|
7
|
-
license: 'https://creativecommons.org/publicdomain/zero/1.0/',
|
|
8
|
-
},
|
|
9
|
-
glyphs: 'https://tiles.versatiles.org/assets/glyphs/{fontstack}/{range}.pbf',
|
|
10
|
-
sprite: [{ id: 'basics', url: 'https://tiles.versatiles.org/assets/sprites/basics/sprites' }],
|
|
11
|
-
sources: {
|
|
12
|
-
'versatiles-shortbread': {
|
|
13
|
-
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
|
|
14
|
-
tiles: [
|
|
15
|
-
'https://tiles.versatiles.org/tiles/osm/{z}/{x}/{y}',
|
|
16
|
-
],
|
|
17
|
-
type: 'vector',
|
|
18
|
-
scheme: 'xyz',
|
|
19
|
-
bounds: [
|
|
20
|
-
-180,
|
|
21
|
-
-85.0511287798066,
|
|
22
|
-
180,
|
|
23
|
-
85.0511287798066,
|
|
24
|
-
],
|
|
25
|
-
minzoom: 0,
|
|
26
|
-
maxzoom
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
layers: [],
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
export function getShortbreadVectorLayers() {
|
|
33
|
-
return [
|
|
34
|
-
{
|
|
35
|
-
id: 'place_labels',
|
|
36
|
-
fields: {
|
|
37
|
-
kind: 'String',
|
|
38
|
-
name: 'String',
|
|
39
|
-
name_de: 'String',
|
|
40
|
-
name_en: 'String',
|
|
41
|
-
population: 'Number',
|
|
42
|
-
},
|
|
43
|
-
minzoom: 3,
|
|
44
|
-
maxzoom,
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
id: 'boundaries',
|
|
48
|
-
fields: {
|
|
49
|
-
admin_level: 'Number',
|
|
50
|
-
coastline: 'Boolean',
|
|
51
|
-
disputed: 'Boolean',
|
|
52
|
-
maritime: 'Boolean',
|
|
53
|
-
},
|
|
54
|
-
minzoom: 0,
|
|
55
|
-
maxzoom,
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
id: 'boundary_labels',
|
|
59
|
-
fields: {
|
|
60
|
-
admin_level: 'Number',
|
|
61
|
-
land_area: 'Number',
|
|
62
|
-
name: 'String',
|
|
63
|
-
name_de: 'String',
|
|
64
|
-
name_en: 'String',
|
|
65
|
-
name_single: 'String',
|
|
66
|
-
way_area: 'Number',
|
|
67
|
-
},
|
|
68
|
-
minzoom: 2,
|
|
69
|
-
maxzoom,
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
id: 'addresses',
|
|
73
|
-
fields: {
|
|
74
|
-
housename: 'String',
|
|
75
|
-
housenumber: 'String',
|
|
76
|
-
},
|
|
77
|
-
minzoom: 14,
|
|
78
|
-
maxzoom,
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
id: 'water_lines',
|
|
82
|
-
fields: {
|
|
83
|
-
bridge: 'Boolean',
|
|
84
|
-
kind: 'String',
|
|
85
|
-
tunnel: 'Boolean',
|
|
86
|
-
},
|
|
87
|
-
minzoom: 4,
|
|
88
|
-
maxzoom,
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
id: 'water_lines_labels',
|
|
92
|
-
fields: {
|
|
93
|
-
bridge: 'Boolean',
|
|
94
|
-
kind: 'String',
|
|
95
|
-
name: 'String',
|
|
96
|
-
name_de: 'String',
|
|
97
|
-
name_en: 'String',
|
|
98
|
-
tunnel: 'Boolean',
|
|
99
|
-
},
|
|
100
|
-
minzoom: 4,
|
|
101
|
-
maxzoom,
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
id: 'dam_lines',
|
|
105
|
-
fields: {
|
|
106
|
-
kind: 'String',
|
|
107
|
-
},
|
|
108
|
-
minzoom: 12,
|
|
109
|
-
maxzoom,
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
id: 'dam_polygons',
|
|
113
|
-
fields: {
|
|
114
|
-
kind: 'String',
|
|
115
|
-
},
|
|
116
|
-
minzoom: 12,
|
|
117
|
-
maxzoom,
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
id: 'pier_lines',
|
|
121
|
-
fields: {
|
|
122
|
-
kind: 'String',
|
|
123
|
-
},
|
|
124
|
-
minzoom: 12,
|
|
125
|
-
maxzoom,
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
id: 'pier_polygons',
|
|
129
|
-
fields: {
|
|
130
|
-
kind: 'String',
|
|
131
|
-
},
|
|
132
|
-
minzoom: 12,
|
|
133
|
-
maxzoom,
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
id: 'bridges',
|
|
137
|
-
fields: {
|
|
138
|
-
kind: 'String',
|
|
139
|
-
},
|
|
140
|
-
minzoom: 12,
|
|
141
|
-
maxzoom,
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
id: 'street_polygons',
|
|
145
|
-
fields: {
|
|
146
|
-
bridge: 'Boolean',
|
|
147
|
-
kind: 'String',
|
|
148
|
-
rail: 'Boolean',
|
|
149
|
-
service: 'String',
|
|
150
|
-
surface: 'String',
|
|
151
|
-
tunnel: 'Boolean',
|
|
152
|
-
},
|
|
153
|
-
minzoom: 11,
|
|
154
|
-
maxzoom,
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
id: 'streets_polygons_labels',
|
|
158
|
-
fields: {
|
|
159
|
-
kind: 'String',
|
|
160
|
-
name: 'String',
|
|
161
|
-
name_de: 'String',
|
|
162
|
-
name_en: 'String',
|
|
163
|
-
},
|
|
164
|
-
minzoom: 14,
|
|
165
|
-
maxzoom,
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
id: 'ferries',
|
|
169
|
-
fields: {
|
|
170
|
-
kind: 'String',
|
|
171
|
-
name: 'String',
|
|
172
|
-
name_de: 'String',
|
|
173
|
-
name_en: 'String',
|
|
174
|
-
},
|
|
175
|
-
minzoom: 8,
|
|
176
|
-
maxzoom,
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
id: 'streets',
|
|
180
|
-
fields: {
|
|
181
|
-
bicycle: 'String',
|
|
182
|
-
bridge: 'Boolean',
|
|
183
|
-
horse: 'String',
|
|
184
|
-
kind: 'String',
|
|
185
|
-
link: 'Boolean',
|
|
186
|
-
oneway: 'Boolean',
|
|
187
|
-
oneway_reverse: 'Boolean',
|
|
188
|
-
rail: 'Boolean',
|
|
189
|
-
service: 'String',
|
|
190
|
-
surface: 'String',
|
|
191
|
-
tracktype: 'String',
|
|
192
|
-
tunnel: 'Boolean',
|
|
193
|
-
},
|
|
194
|
-
minzoom: 5,
|
|
195
|
-
maxzoom,
|
|
196
|
-
},
|
|
197
|
-
{
|
|
198
|
-
id: 'street_labels',
|
|
199
|
-
fields: {
|
|
200
|
-
kind: 'String',
|
|
201
|
-
name: 'String',
|
|
202
|
-
name_de: 'String',
|
|
203
|
-
name_en: 'String',
|
|
204
|
-
ref: 'String',
|
|
205
|
-
ref_cols: 'Number',
|
|
206
|
-
ref_rows: 'Number',
|
|
207
|
-
tunnel: 'Boolean',
|
|
208
|
-
},
|
|
209
|
-
minzoom: 10,
|
|
210
|
-
maxzoom,
|
|
211
|
-
},
|
|
212
|
-
{
|
|
213
|
-
id: 'street_labels_points',
|
|
214
|
-
fields: {
|
|
215
|
-
kind: 'String',
|
|
216
|
-
name: 'String',
|
|
217
|
-
name_de: 'String',
|
|
218
|
-
name_en: 'String',
|
|
219
|
-
ref: 'String',
|
|
220
|
-
},
|
|
221
|
-
minzoom: 12,
|
|
222
|
-
maxzoom,
|
|
223
|
-
},
|
|
224
|
-
{
|
|
225
|
-
id: 'aerialways',
|
|
226
|
-
fields: {
|
|
227
|
-
kind: 'String',
|
|
228
|
-
},
|
|
229
|
-
minzoom: 12,
|
|
230
|
-
maxzoom,
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
id: 'public_transport',
|
|
234
|
-
fields: {
|
|
235
|
-
iata: 'String',
|
|
236
|
-
kind: 'String',
|
|
237
|
-
name: 'String',
|
|
238
|
-
name_de: 'String',
|
|
239
|
-
name_en: 'String',
|
|
240
|
-
station: 'String',
|
|
241
|
-
},
|
|
242
|
-
minzoom: 11,
|
|
243
|
-
maxzoom,
|
|
244
|
-
},
|
|
245
|
-
{
|
|
246
|
-
id: 'buildings',
|
|
247
|
-
fields: {
|
|
248
|
-
amenity: 'String',
|
|
249
|
-
dummy: 'Number',
|
|
250
|
-
name: 'String',
|
|
251
|
-
name_de: 'String',
|
|
252
|
-
name_en: 'String',
|
|
253
|
-
},
|
|
254
|
-
minzoom: 14,
|
|
255
|
-
maxzoom,
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
id: 'water_polygons',
|
|
259
|
-
fields: {
|
|
260
|
-
kind: 'String',
|
|
261
|
-
way_area: 'Number',
|
|
262
|
-
},
|
|
263
|
-
minzoom: 4,
|
|
264
|
-
maxzoom,
|
|
265
|
-
},
|
|
266
|
-
{
|
|
267
|
-
id: 'ocean',
|
|
268
|
-
fields: {
|
|
269
|
-
x: 'Number',
|
|
270
|
-
y: 'Number',
|
|
271
|
-
},
|
|
272
|
-
minzoom: 0,
|
|
273
|
-
maxzoom,
|
|
274
|
-
},
|
|
275
|
-
{
|
|
276
|
-
id: 'water_polygons_labels',
|
|
277
|
-
fields: {
|
|
278
|
-
kind: 'String',
|
|
279
|
-
name: 'String',
|
|
280
|
-
name_de: 'String',
|
|
281
|
-
name_en: 'String',
|
|
282
|
-
way_area: 'Number',
|
|
283
|
-
},
|
|
284
|
-
minzoom: 14,
|
|
285
|
-
maxzoom,
|
|
286
|
-
},
|
|
287
|
-
{
|
|
288
|
-
id: 'land',
|
|
289
|
-
fields: {
|
|
290
|
-
kind: 'String',
|
|
291
|
-
},
|
|
292
|
-
minzoom: 7,
|
|
293
|
-
maxzoom,
|
|
294
|
-
},
|
|
295
|
-
{
|
|
296
|
-
id: 'sites',
|
|
297
|
-
fields: {
|
|
298
|
-
amenity: 'String',
|
|
299
|
-
kind: 'String',
|
|
300
|
-
name: 'String',
|
|
301
|
-
name_de: 'String',
|
|
302
|
-
name_en: 'String',
|
|
303
|
-
},
|
|
304
|
-
minzoom: 14,
|
|
305
|
-
maxzoom,
|
|
306
|
-
},
|
|
307
|
-
{
|
|
308
|
-
id: 'pois',
|
|
309
|
-
fields: {
|
|
310
|
-
amenity: 'String',
|
|
311
|
-
atm: 'Boolean',
|
|
312
|
-
cuisine: 'String',
|
|
313
|
-
denomination: 'String',
|
|
314
|
-
emergency: 'String',
|
|
315
|
-
highway: 'String',
|
|
316
|
-
historic: 'String',
|
|
317
|
-
information: 'String',
|
|
318
|
-
leisure: 'String',
|
|
319
|
-
man_made: 'String',
|
|
320
|
-
name: 'String',
|
|
321
|
-
name_de: 'String',
|
|
322
|
-
name_en: 'String',
|
|
323
|
-
'recycling:clothes': 'Boolean',
|
|
324
|
-
'recycling:glass_bottles': 'Boolean',
|
|
325
|
-
'recycling:paper': 'Boolean',
|
|
326
|
-
'recycling:scrap_metal': 'Boolean',
|
|
327
|
-
religion: 'String',
|
|
328
|
-
shop: 'String',
|
|
329
|
-
sport: 'String',
|
|
330
|
-
tourism: 'String',
|
|
331
|
-
'tower:type': 'String',
|
|
332
|
-
vending: 'String',
|
|
333
|
-
},
|
|
334
|
-
minzoom: 14,
|
|
335
|
-
maxzoom,
|
|
336
|
-
},
|
|
337
|
-
];
|
|
338
|
-
}
|
|
339
|
-
//# sourceMappingURL=template.js.map
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { MaplibreLayer } from '../types/index.js';
|
|
2
|
-
import type { StyleRules } from './types.js';
|
|
3
|
-
import type { CachedRecolor } from './recolor.js';
|
|
4
|
-
export declare function decorate(layers: MaplibreLayer[], rules: StyleRules, recolor: CachedRecolor): MaplibreLayer[];
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { Color } from '../color/index.js';
|
|
2
|
-
import expandBraces from 'brace-expansion';
|
|
3
|
-
import maplibreProperties from '../shortbread/properties.js';
|
|
4
|
-
import { deepMerge } from '../lib/utils.js';
|
|
5
|
-
export function decorate(layers, rules, recolor) {
|
|
6
|
-
const layerIds = layers.map(l => l.id);
|
|
7
|
-
const layerIdSet = new Set(layerIds);
|
|
8
|
-
// Initialize a new map to hold final styles for layers
|
|
9
|
-
const layerStyles = new Map();
|
|
10
|
-
// Iterate through the generated layer style rules
|
|
11
|
-
Object.entries(rules).forEach(([idDef, layerStyle]) => {
|
|
12
|
-
if (layerStyle == null)
|
|
13
|
-
return;
|
|
14
|
-
// Expand any braces in IDs and filter them through a RegExp if necessary
|
|
15
|
-
const ids = expandBraces(idDef).flatMap(id => {
|
|
16
|
-
if (!id.includes('*'))
|
|
17
|
-
return id;
|
|
18
|
-
const regExpString = id.replace(/[^a-z_:-]/g, c => {
|
|
19
|
-
if (c === '*')
|
|
20
|
-
return '[a-z_-]*';
|
|
21
|
-
throw new Error('unknown char to process. Do not know how to make a RegExp from: ' + JSON.stringify(c));
|
|
22
|
-
});
|
|
23
|
-
const regExp = new RegExp(`^${regExpString}$`, 'i');
|
|
24
|
-
return layerIds.filter(layerId => regExp.test(layerId));
|
|
25
|
-
});
|
|
26
|
-
ids.forEach(id => {
|
|
27
|
-
if (!layerIdSet.has(id))
|
|
28
|
-
return;
|
|
29
|
-
layerStyles.set(id, deepMerge(layerStyles.get(id) ?? {}, layerStyle));
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
// Deep clone the original layers and apply styles
|
|
33
|
-
return layers.flatMap(layer => {
|
|
34
|
-
// Get the id and style of the layer
|
|
35
|
-
const layerStyle = layerStyles.get(layer.id);
|
|
36
|
-
// Don't export layers that have no style
|
|
37
|
-
if (!layerStyle)
|
|
38
|
-
return [];
|
|
39
|
-
processStyling(layer, layerStyle);
|
|
40
|
-
return [layer];
|
|
41
|
-
});
|
|
42
|
-
// Function to process each style attribute for the layer
|
|
43
|
-
function processStyling(layer, styleRule) {
|
|
44
|
-
for (const [ruleKeyCamelCase, ruleValue] of Object.entries(styleRule)) {
|
|
45
|
-
if (ruleValue == null)
|
|
46
|
-
continue;
|
|
47
|
-
// CamelCase to not-camel-case
|
|
48
|
-
const ruleKey = ruleKeyCamelCase.replace(/[A-Z]/g, c => '-' + c.toLowerCase());
|
|
49
|
-
const propertyDefs = maplibreProperties.get(layer.type + '/' + ruleKey);
|
|
50
|
-
if (!propertyDefs)
|
|
51
|
-
continue;
|
|
52
|
-
propertyDefs.forEach(propertyDef => {
|
|
53
|
-
const { key } = propertyDef;
|
|
54
|
-
let value = ruleValue;
|
|
55
|
-
switch (propertyDef.valueType) {
|
|
56
|
-
case 'color':
|
|
57
|
-
value = processExpression(value, processColor);
|
|
58
|
-
break;
|
|
59
|
-
case 'fonts':
|
|
60
|
-
value = processExpression(value, processFont);
|
|
61
|
-
break;
|
|
62
|
-
case 'resolvedImage':
|
|
63
|
-
case 'formatted':
|
|
64
|
-
case 'array':
|
|
65
|
-
case 'boolean':
|
|
66
|
-
case 'enum':
|
|
67
|
-
case 'number':
|
|
68
|
-
value = processExpression(value);
|
|
69
|
-
break;
|
|
70
|
-
default: throw new Error(`unknown propertyDef.valueType "${propertyDef.valueType}" for key "${key}"`);
|
|
71
|
-
}
|
|
72
|
-
switch (propertyDef.parent) {
|
|
73
|
-
case 'layer':
|
|
74
|
-
// @ts-expect-error: too complex to handle
|
|
75
|
-
layer[key] = value;
|
|
76
|
-
break;
|
|
77
|
-
case 'layout':
|
|
78
|
-
if (!layer.layout)
|
|
79
|
-
layer.layout = {};
|
|
80
|
-
// @ts-expect-error: too complex to handle
|
|
81
|
-
layer.layout[key] = value;
|
|
82
|
-
break;
|
|
83
|
-
case 'paint':
|
|
84
|
-
if (!layer.paint)
|
|
85
|
-
layer.paint = {};
|
|
86
|
-
// @ts-expect-error: too complex to handle
|
|
87
|
-
layer.paint[key] = value;
|
|
88
|
-
break;
|
|
89
|
-
default:
|
|
90
|
-
throw new Error(`unknown parent "${propertyDef.parent}" for key "${key}"`);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
function processColor(value) {
|
|
95
|
-
if (typeof value === 'string')
|
|
96
|
-
value = Color.parse(value);
|
|
97
|
-
if (value instanceof Color) {
|
|
98
|
-
const color = recolor.do(value);
|
|
99
|
-
return color.asString();
|
|
100
|
-
}
|
|
101
|
-
throw new Error(`unknown color type "${typeof value}"`);
|
|
102
|
-
}
|
|
103
|
-
function processFont(value) {
|
|
104
|
-
if (typeof value === 'string')
|
|
105
|
-
return [value];
|
|
106
|
-
throw new Error(`unknown font type "${typeof value}"`);
|
|
107
|
-
}
|
|
108
|
-
function processExpression(value, cbValue) {
|
|
109
|
-
if (typeof value === 'object') {
|
|
110
|
-
if (value instanceof Color)
|
|
111
|
-
return processColor(value);
|
|
112
|
-
if (!Array.isArray(value)) {
|
|
113
|
-
return processZoomStops(value, cbValue);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return cbValue ? cbValue(value) : value;
|
|
117
|
-
}
|
|
118
|
-
function processZoomStops(obj, cbValue) {
|
|
119
|
-
return {
|
|
120
|
-
stops: Object.entries(obj)
|
|
121
|
-
.map(([z, v]) => [parseInt(z, 10), cbValue ? cbValue(v) : v])
|
|
122
|
-
.sort((a, b) => a[0] - b[0]),
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
//# sourceMappingURL=decorator.js.map
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Color } from '../color/index.js';
|
|
2
|
-
export interface RecolorOptions {
|
|
3
|
-
invertBrightness?: boolean;
|
|
4
|
-
rotate?: number;
|
|
5
|
-
saturate?: number;
|
|
6
|
-
gamma?: number;
|
|
7
|
-
contrast?: number;
|
|
8
|
-
brightness?: number;
|
|
9
|
-
tint?: number;
|
|
10
|
-
tintColor?: string;
|
|
11
|
-
}
|
|
12
|
-
export declare function getDefaultRecolorFlags(): RecolorOptions;
|
|
13
|
-
export declare function recolorObject(colors: Record<string, Color>, opt?: RecolorOptions): void;
|
|
14
|
-
export declare function recolorArray(colors: Color[], opt?: RecolorOptions): void;
|
|
15
|
-
export declare class CachedRecolor {
|
|
16
|
-
private readonly skip;
|
|
17
|
-
private readonly opt?;
|
|
18
|
-
private readonly cache;
|
|
19
|
-
constructor(opt?: RecolorOptions);
|
|
20
|
-
do(color: Color): Color;
|
|
21
|
-
}
|
|
22
|
-
export declare function recolor(color: Color, opt?: RecolorOptions): Color;
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { Color } from '../color/index.js';
|
|
2
|
-
export function getDefaultRecolorFlags() {
|
|
3
|
-
return {
|
|
4
|
-
invertBrightness: false,
|
|
5
|
-
rotate: 0,
|
|
6
|
-
saturate: 0,
|
|
7
|
-
gamma: 1,
|
|
8
|
-
contrast: 1,
|
|
9
|
-
brightness: 0,
|
|
10
|
-
tint: 0,
|
|
11
|
-
tintColor: '#FF0000',
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
function isValidRecolorOptions(opt) {
|
|
15
|
-
if (!opt)
|
|
16
|
-
return false;
|
|
17
|
-
if ((opt.invertBrightness != null) && opt.invertBrightness)
|
|
18
|
-
return true;
|
|
19
|
-
if ((opt.rotate != null) && (opt.rotate !== 0))
|
|
20
|
-
return true;
|
|
21
|
-
if ((opt.saturate != null) && (opt.saturate !== 0))
|
|
22
|
-
return true;
|
|
23
|
-
if ((opt.gamma != null) && (opt.gamma !== 1))
|
|
24
|
-
return true;
|
|
25
|
-
if ((opt.contrast != null) && (opt.contrast !== 1))
|
|
26
|
-
return true;
|
|
27
|
-
if ((opt.brightness != null) && (opt.brightness !== 0))
|
|
28
|
-
return true;
|
|
29
|
-
if ((opt.tint != null) && (opt.tint !== 0))
|
|
30
|
-
return true;
|
|
31
|
-
if ((opt.tintColor != null) && (opt.tintColor !== '#FF0000'))
|
|
32
|
-
return true;
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
export function recolorObject(colors, opt) {
|
|
36
|
-
if (!isValidRecolorOptions(opt))
|
|
37
|
-
return;
|
|
38
|
-
for (const [k, c] of Object.entries(colors)) {
|
|
39
|
-
colors[k] = recolor(c, opt);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
export function recolorArray(colors, opt) {
|
|
43
|
-
if (!isValidRecolorOptions(opt))
|
|
44
|
-
return;
|
|
45
|
-
for (let i = 0; i < colors.length; i++) {
|
|
46
|
-
colors[i] = recolor(colors[i], opt);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
export class CachedRecolor {
|
|
50
|
-
skip;
|
|
51
|
-
opt;
|
|
52
|
-
cache;
|
|
53
|
-
constructor(opt) {
|
|
54
|
-
this.skip = !isValidRecolorOptions(opt);
|
|
55
|
-
this.cache = new Map();
|
|
56
|
-
this.opt = opt;
|
|
57
|
-
}
|
|
58
|
-
do(color) {
|
|
59
|
-
if (this.skip)
|
|
60
|
-
return color;
|
|
61
|
-
const key = color.asHex();
|
|
62
|
-
const result = this.cache.get(key);
|
|
63
|
-
if (result)
|
|
64
|
-
return result;
|
|
65
|
-
color = recolor(color, this.opt);
|
|
66
|
-
this.cache.set(key, color);
|
|
67
|
-
return color;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
export function recolor(color, opt) {
|
|
71
|
-
if (!isValidRecolorOptions(opt))
|
|
72
|
-
return color;
|
|
73
|
-
if (opt.invertBrightness ?? false)
|
|
74
|
-
color = color.invertLuminosity();
|
|
75
|
-
if ((opt.rotate !== undefined) && (opt.rotate !== 0))
|
|
76
|
-
color = color.rotateHue(opt.rotate);
|
|
77
|
-
if ((opt.saturate !== undefined) && (opt.saturate !== 0))
|
|
78
|
-
color = color.saturate(opt.saturate);
|
|
79
|
-
if ((opt.gamma !== undefined) && (opt.gamma !== 1))
|
|
80
|
-
color = color.gamma(opt.gamma);
|
|
81
|
-
if ((opt.contrast !== undefined) && (opt.contrast !== 1))
|
|
82
|
-
color = color.contrast(opt.contrast);
|
|
83
|
-
if ((opt.brightness !== undefined) && (opt.brightness !== 0))
|
|
84
|
-
color = color.brightness(opt.brightness);
|
|
85
|
-
if ((opt.tint !== undefined) && (opt.tintColor !== undefined) && (opt.tint !== 0))
|
|
86
|
-
color = color.tint(opt.tint, Color.parse(opt.tintColor));
|
|
87
|
-
return color;
|
|
88
|
-
}
|
|
89
|
-
//# sourceMappingURL=recolor.js.map
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Color } from '../color/index.js';
|
|
2
|
-
import type { StyleSpecification } from '../types/maplibre.js';
|
|
3
|
-
import type { StyleBuilderColors, StyleBuilderColorsEnsured, StyleBuilderFonts, StyleBuilderOptions } from './types.js';
|
|
4
|
-
import type { StyleRules, StyleRulesOptions } from './types.js';
|
|
5
|
-
export declare abstract class StyleBuilder {
|
|
6
|
-
#private;
|
|
7
|
-
abstract readonly name: string;
|
|
8
|
-
abstract readonly defaultColors: StyleBuilderColors;
|
|
9
|
-
abstract readonly defaultFonts: StyleBuilderFonts;
|
|
10
|
-
build(options?: StyleBuilderOptions): StyleSpecification;
|
|
11
|
-
getColors(colors: StyleBuilderColors): StyleBuilderColorsEnsured;
|
|
12
|
-
getDefaultOptions(): StyleBuilderOptions;
|
|
13
|
-
protected transformDefaultColors(callback: (color: Color) => Color): void;
|
|
14
|
-
protected abstract getStyleRules(options: StyleRulesOptions): StyleRules;
|
|
15
|
-
}
|