@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.
Files changed (102) hide show
  1. package/dist/index.d.ts +274 -14
  2. package/dist/index.js +3650 -11
  3. package/dist/index.js.map +1 -0
  4. package/package.json +8 -7
  5. package/src/color/abstract.ts +83 -0
  6. package/src/color/hsl.test.ts +182 -0
  7. package/src/color/hsl.ts +122 -0
  8. package/src/color/hsv.test.ts +174 -0
  9. package/src/color/hsv.ts +100 -0
  10. package/src/color/index.test.ts +119 -0
  11. package/src/color/index.ts +38 -0
  12. package/src/color/random.test.ts +35 -0
  13. package/src/color/random.ts +165 -0
  14. package/src/color/rgb.test.ts +227 -0
  15. package/src/color/rgb.ts +248 -0
  16. package/src/color/utils.test.ts +86 -0
  17. package/src/color/utils.ts +13 -0
  18. package/src/guess_style/guess_style.test.ts +134 -0
  19. package/src/guess_style/guess_style.ts +166 -0
  20. package/{dist/guess_style/index.d.ts → src/guess_style/index.ts} +1 -0
  21. package/src/index.test.ts +77 -0
  22. package/src/index.ts +18 -0
  23. package/src/lib/utils.test.ts +197 -0
  24. package/src/lib/utils.ts +134 -0
  25. package/{dist/shortbread/index.d.ts → src/shortbread/index.ts} +1 -0
  26. package/src/shortbread/layers.test.ts +36 -0
  27. package/src/shortbread/layers.ts +564 -0
  28. package/src/shortbread/properties.test.ts +44 -0
  29. package/src/shortbread/properties.ts +142 -0
  30. package/src/shortbread/template.test.ts +43 -0
  31. package/src/shortbread/template.ts +343 -0
  32. package/src/style_builder/decorator.test.ts +67 -0
  33. package/src/style_builder/decorator.ts +135 -0
  34. package/src/style_builder/recolor.test.ts +306 -0
  35. package/src/style_builder/recolor.ts +110 -0
  36. package/src/style_builder/style_builder.test.ts +103 -0
  37. package/src/style_builder/style_builder.ts +134 -0
  38. package/src/style_builder/types.ts +141 -0
  39. package/src/styles/LICENSE.md +41 -0
  40. package/src/styles/colorful.ts +1041 -0
  41. package/src/styles/eclipse.ts +11 -0
  42. package/{dist/styles/empty.d.ts → src/styles/empty.ts} +7 -3
  43. package/src/styles/graybeard.ts +11 -0
  44. package/src/styles/index.ts +33 -0
  45. package/src/styles/neutrino.ts +429 -0
  46. package/{dist/types/index.d.ts → src/types/index.ts} +1 -0
  47. package/{dist/types/maplibre.d.ts → src/types/maplibre.ts} +3 -0
  48. package/src/types/tilejson.test.ts +94 -0
  49. package/src/types/tilejson.ts +125 -0
  50. package/src/types/vector_layer.test.ts +64 -0
  51. package/src/types/vector_layer.ts +69 -0
  52. package/dist/color/abstract.d.ts +0 -34
  53. package/dist/color/abstract.js +0 -53
  54. package/dist/color/hsl.d.ts +0 -23
  55. package/dist/color/hsl.js +0 -98
  56. package/dist/color/hsv.d.ts +0 -20
  57. package/dist/color/hsv.js +0 -100
  58. package/dist/color/index.d.ts +0 -6
  59. package/dist/color/index.js +0 -29
  60. package/dist/color/random.d.ts +0 -9
  61. package/dist/color/random.js +0 -134
  62. package/dist/color/rgb.d.ts +0 -28
  63. package/dist/color/rgb.js +0 -195
  64. package/dist/color/utils.d.ts +0 -3
  65. package/dist/color/utils.js +0 -10
  66. package/dist/guess_style/guess_style.d.ts +0 -8
  67. package/dist/guess_style/guess_style.js +0 -147
  68. package/dist/guess_style/index.js +0 -2
  69. package/dist/lib/utils.d.ts +0 -6
  70. package/dist/lib/utils.js +0 -126
  71. package/dist/shortbread/index.js +0 -3
  72. package/dist/shortbread/layers.d.ts +0 -5
  73. package/dist/shortbread/layers.js +0 -521
  74. package/dist/shortbread/properties.d.ts +0 -7
  75. package/dist/shortbread/properties.js +0 -125
  76. package/dist/shortbread/template.d.ts +0 -4
  77. package/dist/shortbread/template.js +0 -339
  78. package/dist/style_builder/decorator.d.ts +0 -4
  79. package/dist/style_builder/decorator.js +0 -127
  80. package/dist/style_builder/recolor.d.ts +0 -22
  81. package/dist/style_builder/recolor.js +0 -89
  82. package/dist/style_builder/style_builder.d.ts +0 -15
  83. package/dist/style_builder/style_builder.js +0 -106
  84. package/dist/style_builder/types.d.ts +0 -122
  85. package/dist/style_builder/types.js +0 -3
  86. package/dist/styles/colorful.d.ts +0 -11
  87. package/dist/styles/colorful.js +0 -956
  88. package/dist/styles/eclipse.d.ts +0 -5
  89. package/dist/styles/eclipse.js +0 -9
  90. package/dist/styles/empty.js +0 -8
  91. package/dist/styles/graybeard.d.ts +0 -5
  92. package/dist/styles/graybeard.js +0 -9
  93. package/dist/styles/index.d.ts +0 -11
  94. package/dist/styles/index.js +0 -20
  95. package/dist/styles/neutrino.d.ts +0 -11
  96. package/dist/styles/neutrino.js +0 -401
  97. package/dist/types/index.js +0 -3
  98. package/dist/types/maplibre.js +0 -2
  99. package/dist/types/tilejson.d.ts +0 -32
  100. package/dist/types/tilejson.js +0 -87
  101. package/dist/types/vector_layer.d.ts +0 -14
  102. package/dist/types/vector_layer.js +0 -51
@@ -1,106 +0,0 @@
1
- import { Color } from '../color/index.js';
2
- import { getShortbreadTemplate, getShortbreadLayers } from '../shortbread/index.js';
3
- import { decorate } from './decorator.js';
4
- import { CachedRecolor, getDefaultRecolorFlags } from './recolor.js';
5
- import { basename, deepClone, resolveUrl } from '../lib/utils.js';
6
- // StyleBuilder class definition
7
- export class StyleBuilder {
8
- #sourceName = 'versatiles-shortbread';
9
- build(options) {
10
- options ??= {};
11
- const baseUrl = options.baseUrl ?? globalThis?.document?.location?.origin ?? 'https://tiles.versatiles.org';
12
- const glyphs = options.glyphs ?? '/assets/glyphs/{fontstack}/{range}.pbf';
13
- const sprite = options.sprite ?? [{ id: 'basics', url: '/assets/sprites/basics/sprites' }];
14
- const tiles = options.tiles ?? ['/tiles/osm/{z}/{x}/{y}'];
15
- const hideLabels = options.hideLabels ?? false;
16
- const language = options.language ?? null;
17
- const recolorOptions = options.recolor ?? getDefaultRecolorFlags();
18
- const colors = this.getColors(this.defaultColors);
19
- if (options.colors) {
20
- let key;
21
- for (key in options.colors) {
22
- const value = options.colors[key];
23
- if (value != null)
24
- colors[key] = Color.parse(value);
25
- }
26
- }
27
- const fonts = deepClone(this.defaultFonts);
28
- if (options.fonts) {
29
- let key;
30
- for (key in options.fonts) {
31
- const fontName = options.fonts[key];
32
- if (fontName != null)
33
- fonts[key] = fontName;
34
- }
35
- }
36
- // get empty shortbread style
37
- const style = getShortbreadTemplate();
38
- const styleRuleOptions = {
39
- colors,
40
- fonts,
41
- language,
42
- };
43
- // get layer style rules from child class
44
- const layerStyleRules = this.getStyleRules(styleRuleOptions);
45
- // get shortbread layers
46
- const layerDefinitions = getShortbreadLayers({ language });
47
- let layers = layerDefinitions.map(layer => {
48
- switch (layer.type) {
49
- case 'background':
50
- return layer;
51
- case 'fill':
52
- case 'line':
53
- case 'symbol':
54
- return {
55
- source: this.#sourceName,
56
- ...layer,
57
- };
58
- }
59
- throw Error('unknown layer type');
60
- });
61
- // apply layer rules
62
- layers = decorate(layers, layerStyleRules, new CachedRecolor(recolorOptions));
63
- // hide labels, if wanted
64
- if (hideLabels)
65
- layers = layers.filter(l => l.type !== 'symbol');
66
- style.layers = layers;
67
- style.name = 'versatiles-' + this.name.toLowerCase();
68
- style.glyphs = resolveUrl(baseUrl, glyphs);
69
- if (typeof sprite == 'string') {
70
- style.sprite = [{ id: basename(sprite), url: resolveUrl(baseUrl, sprite) }];
71
- }
72
- else {
73
- style.sprite = sprite.map(({ id, url }) => ({ id, url: resolveUrl(baseUrl, url) }));
74
- }
75
- const source = style.sources[this.#sourceName];
76
- if ('tiles' in source)
77
- source.tiles = tiles.map(url => resolveUrl(baseUrl, url));
78
- return style;
79
- }
80
- getColors(colors) {
81
- const entriesString = Object.entries(colors);
82
- const result = Object.fromEntries(entriesString.map(([key, value]) => [key, Color.parse(value)]));
83
- return result;
84
- }
85
- getDefaultOptions() {
86
- return {
87
- baseUrl: '',
88
- glyphs: '',
89
- sprite: '',
90
- tiles: [],
91
- hideLabels: false,
92
- language: undefined,
93
- colors: deepClone(this.defaultColors),
94
- fonts: deepClone(this.defaultFonts),
95
- recolor: getDefaultRecolorFlags(),
96
- };
97
- }
98
- transformDefaultColors(callback) {
99
- const colors = this.getColors(this.defaultColors);
100
- let key;
101
- for (key in colors) {
102
- this.defaultColors[key] = callback(colors[key]);
103
- }
104
- }
105
- }
106
- //# sourceMappingURL=style_builder.js.map
@@ -1,122 +0,0 @@
1
- import type { Color } from '../color/index.js';
2
- import type { RecolorOptions } from './recolor.js';
3
- import { SpriteSpecification } from '@maplibre/maplibre-gl-style-spec';
4
- /** Represents language suffixes used in map styles. */
5
- export type Language = 'de' | 'en' | null;
6
- /** Options for configuring a style builder. */
7
- export interface StyleBuilderOptions {
8
- /**
9
- * The base URL for loading external resources like tiles, sprites, and fonts.
10
- * Default: document.location.origin (in the browser), or 'https://tiles.versatiles.org'
11
- */
12
- baseUrl?: string;
13
- /**
14
- * The URL template for loading font glyphs, formatted with '{fontstack}' and '{range}' placeholders.
15
- * Default: '/assets/glyphs/{fontstack}/{range}.pbf'
16
- */
17
- glyphs?: string;
18
- /**
19
- * The URL for loading sprite images and metadata.
20
- * Default: [{ id: 'basics', url: '/assets/sprites/basics/sprites' }]
21
- */
22
- sprite?: SpriteSpecification;
23
- /**
24
- * An array of URL templates for loading map tiles, using '{z}', '{x}', and '{y}' placeholders.
25
- * Default: ['/tiles/osm/{z}/{x}/{y}']
26
- */
27
- tiles?: string[];
28
- /**
29
- * If set to true, hides all map labels.
30
- * Default: false
31
- */
32
- hideLabels?: boolean;
33
- /**
34
- * Set the language ('en', 'de') of all map labels.
35
- * A null value means that the language of the country in which the label is drawn will be used.
36
- * Default: null
37
- */
38
- language?: Language;
39
- /**
40
- * An object specifying overrides for default color values, keyed by the color names.
41
- */
42
- colors?: Partial<StyleBuilderColors>;
43
- /**
44
- * An object specifying overrides for default font names, keyed by the font names.
45
- */
46
- fonts?: Partial<StyleBuilderFonts>;
47
- /**
48
- * Options for color adjustments and transformations applied to the entire style.
49
- */
50
- recolor?: RecolorOptions;
51
- }
52
- /** Records string values for color properties in a style builder. */
53
- export interface StyleBuilderColors {
54
- agriculture: Color | string;
55
- boundary: Color | string;
56
- building: Color | string;
57
- buildingbg: Color | string;
58
- burial: Color | string;
59
- commercial: Color | string;
60
- construction: Color | string;
61
- cycle: Color | string;
62
- danger: Color | string;
63
- disputed: Color | string;
64
- education: Color | string;
65
- foot: Color | string;
66
- glacier: Color | string;
67
- grass: Color | string;
68
- hospital: Color | string;
69
- industrial: Color | string;
70
- label: Color | string;
71
- labelHalo: Color | string;
72
- land: Color | string;
73
- leisure: Color | string;
74
- motorway: Color | string;
75
- motorwaybg: Color | string;
76
- park: Color | string;
77
- parking: Color | string;
78
- poi: Color | string;
79
- prison: Color | string;
80
- rail: Color | string;
81
- residential: Color | string;
82
- rock: Color | string;
83
- sand: Color | string;
84
- shield: Color | string;
85
- street: Color | string;
86
- streetbg: Color | string;
87
- subway: Color | string;
88
- symbol: Color | string;
89
- trunk: Color | string;
90
- trunkbg: Color | string;
91
- waste: Color | string;
92
- water: Color | string;
93
- wetland: Color | string;
94
- wood: Color | string;
95
- }
96
- export type StyleBuilderColorsEnsured = Record<keyof StyleBuilderColors, Color>;
97
- /** Records string values for font properties in a style builder. */
98
- export type StyleBuilderFonts = {
99
- regular: string;
100
- bold: string;
101
- };
102
- /** Defines options for style rules in a style builder. */
103
- export interface StyleRulesOptions {
104
- /**
105
- * The set of colors used in the style builder.
106
- */
107
- colors: StyleBuilderColorsEnsured;
108
- /**
109
- * The set of fonts used in the style builder.
110
- */
111
- fonts: StyleBuilderFonts;
112
- /**
113
- * The language used for map labels.
114
- */
115
- language: Language;
116
- }
117
- /** Defines the value type for a style rule. */
118
- export type StyleRuleValue = boolean | number | object | string;
119
- /** Defines the structure of a style rule, which is a record of properties to style values. */
120
- export type StyleRule = Record<string, StyleRuleValue | undefined>;
121
- /** Defines the structure of style rules, which is a record of selectors to style rules. */
122
- export type StyleRules = Record<string, StyleRule | undefined>;
@@ -1,3 +0,0 @@
1
- ;
2
- export {};
3
- //# sourceMappingURL=types.js.map
@@ -1,11 +0,0 @@
1
- import { StyleBuilder } from '../style_builder/style_builder.js';
2
- import type { StyleBuilderColors, StyleRules, StyleRulesOptions } from '../style_builder/types.js';
3
- export default class Colorful extends StyleBuilder {
4
- readonly name: string;
5
- defaultFonts: {
6
- regular: string;
7
- bold: string;
8
- };
9
- defaultColors: StyleBuilderColors;
10
- protected getStyleRules(options: StyleRulesOptions): StyleRules;
11
- }