@versatiles/style 5.2.0 → 5.2.2

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 (42) hide show
  1. package/dist/color/abstract.d.ts +3 -2
  2. package/dist/color/hsl.d.ts +2 -1
  3. package/dist/color/hsl.js +8 -6
  4. package/dist/color/hsv.d.ts +2 -1
  5. package/dist/color/hsv.js +7 -0
  6. package/dist/color/index.d.ts +4 -1
  7. package/dist/color/index.js +0 -1
  8. package/dist/color/random.js +18 -12
  9. package/dist/color/rgb.d.ts +2 -1
  10. package/dist/color/rgb.js +7 -0
  11. package/dist/guess_style/guess_style.d.ts +8 -5
  12. package/dist/guess_style/guess_style.js +39 -104
  13. package/dist/guess_style/index.d.ts +2 -2
  14. package/dist/guess_style/index.js +1 -1
  15. package/dist/index.d.ts +9 -4
  16. package/dist/index.js +3 -3
  17. package/dist/lib/utils.js +1 -1
  18. package/dist/shortbread/template.d.ts +4 -2
  19. package/dist/shortbread/template.js +308 -309
  20. package/dist/style_builder/decorator.js +1 -1
  21. package/dist/style_builder/recolor.d.ts +1 -1
  22. package/dist/style_builder/recolor.js +1 -1
  23. package/dist/style_builder/style_builder.d.ts +4 -4
  24. package/dist/style_builder/style_builder.js +2 -2
  25. package/dist/style_builder/types.d.ts +4 -6
  26. package/dist/styles/colorful.d.ts +1 -1
  27. package/dist/styles/colorful.js +1 -1
  28. package/dist/styles/empty.d.ts +1 -1
  29. package/dist/styles/empty.js +1 -1
  30. package/dist/styles/index.d.ts +3 -5
  31. package/dist/styles/neutrino.d.ts +1 -1
  32. package/dist/styles/neutrino.js +1 -1
  33. package/dist/types/index.d.ts +2 -2
  34. package/dist/types/maplibre.d.ts +2 -16
  35. package/dist/types/tilejson.d.ts +5 -10
  36. package/dist/types/tilejson.js +21 -38
  37. package/package.json +1 -2
  38. package/LICENSE +0 -21
  39. package/dist/browser.d.ts +0 -6
  40. package/dist/browser.js +0 -4
  41. package/dist/guess_style/types.d.ts +0 -23
  42. package/dist/guess_style/types.js +0 -1
@@ -1,15 +1,13 @@
1
- import type Color from '../color/index.js';
2
- import type StyleBuilder from './style_builder.js';
1
+ import type { Color } from '../color/index.js';
2
+ import type { StyleBuilder } from './style_builder.js';
3
3
  import type { RecolorOptions } from './recolor.js';
4
+ import { SpriteSpecification } from '@maplibre/maplibre-gl-style-spec';
4
5
  /** Represents language suffixes used in map styles. */
5
6
  export type Language = 'de' | 'en' | null;
6
7
  export interface StyleBuilderOptions<T extends StyleBuilder<T>> {
7
8
  baseUrl?: string;
8
9
  glyphs?: string;
9
- sprite?: string | {
10
- id: string;
11
- url: string;
12
- }[];
10
+ sprite?: SpriteSpecification;
13
11
  tiles?: string[];
14
12
  hideLabels?: boolean;
15
13
  language?: Language;
@@ -1,4 +1,4 @@
1
- import StyleBuilder from '../style_builder/style_builder.js';
1
+ import { StyleBuilder } from '../style_builder/style_builder.js';
2
2
  import type { StyleRules, StyleRulesOptions } from '../style_builder/types.js';
3
3
  export default class Colorful extends StyleBuilder<Colorful> {
4
4
  readonly name: string;
@@ -1,4 +1,4 @@
1
- import StyleBuilder from '../style_builder/style_builder.js';
1
+ import { StyleBuilder } from '../style_builder/style_builder.js';
2
2
  export default class Colorful extends StyleBuilder {
3
3
  name = 'Colorful';
4
4
  defaultFonts = {
@@ -1,4 +1,4 @@
1
- import StyleBuilder from '../style_builder/style_builder.js';
1
+ import { StyleBuilder } from '../style_builder/style_builder.js';
2
2
  import type { StyleRules, StyleRulesOptions } from '../style_builder/types.js';
3
3
  export default class Empty extends StyleBuilder<Empty> {
4
4
  readonly name: string;
@@ -1,4 +1,4 @@
1
- import StyleBuilder from '../style_builder/style_builder.js';
1
+ import { StyleBuilder } from '../style_builder/style_builder.js';
2
2
  export default class Empty extends StyleBuilder {
3
3
  name = 'Empty';
4
4
  defaultFonts = {
@@ -1,8 +1,6 @@
1
- import type StyleBuilder from '../style_builder/style_builder.js';
1
+ import type { StyleBuilder } from '../style_builder/style_builder.js';
2
2
  import type { StyleBuilderOptions } from '../style_builder/types.js';
3
- import type { MaplibreStyle } from '../types/maplibre.js';
4
- import type { RecolorOptions } from '../style_builder/recolor.js';
5
- export type { MaplibreStyle, RecolorOptions };
3
+ import { StyleSpecification } from '@maplibre/maplibre-gl-style-spec';
6
4
  import Colorful from './colorful.js';
7
5
  import Eclipse from './eclipse.js';
8
6
  import Graybeard from './graybeard.js';
@@ -14,7 +12,7 @@ export type GraybeardOptions = StyleBuilderOptions<Graybeard>;
14
12
  export type NeutrinoOptions = StyleBuilderOptions<Neutrino>;
15
13
  export type EmptyOptions = StyleBuilderOptions<Empty>;
16
14
  export type SomeOptions = ColorfulOptions | EclipseOptions | EmptyOptions | GraybeardOptions | NeutrinoOptions;
17
- type MakeStyle<T extends StyleBuilder<T>, O extends StyleBuilderOptions<T>> = ((options?: O) => MaplibreStyle) & {
15
+ export type MakeStyle<T extends StyleBuilder<T>, O extends StyleBuilderOptions<T>> = ((options?: O) => StyleSpecification) & {
18
16
  getOptions: () => O;
19
17
  };
20
18
  export type ColorfulBuilder = MakeStyle<Colorful, ColorfulOptions>;
@@ -1,4 +1,4 @@
1
- import StyleBuilder from '../style_builder/style_builder.js';
1
+ import { StyleBuilder } from '../style_builder/style_builder.js';
2
2
  import type { StyleRules, StyleRulesOptions } from '../style_builder/types.js';
3
3
  export default class Neutrino extends StyleBuilder<Neutrino> {
4
4
  readonly name: string;
@@ -1,4 +1,4 @@
1
- import StyleBuilder from '../style_builder/style_builder.js';
1
+ import { StyleBuilder } from '../style_builder/style_builder.js';
2
2
  export default class Neutrino extends StyleBuilder {
3
3
  name = 'Neutrino';
4
4
  defaultFonts = {
@@ -1,5 +1,5 @@
1
- export type { MaplibreStyle, MaplibreStyleVector, MaplibreLayerDefinition, MaplibreLayer } from './maplibre.js';
1
+ export type { MaplibreLayerDefinition, MaplibreLayer } from './maplibre.js';
2
2
  export type { VectorLayer } from './vector_layer.js';
3
3
  export { isTileJSONSpecification } from './tilejson.js';
4
- export type { TileJSONSpecification, TileJSONSpecificationBasic, TileJSONSpecificationRaster, TileJSONSpecificationVector } from './tilejson.js';
4
+ export type { TileJSONSpecification, TileJSONSpecificationRaster, TileJSONSpecificationVector } from './tilejson.js';
5
5
  export { isVectorLayers } from './vector_layer.js';
@@ -1,19 +1,5 @@
1
- import type { BackgroundLayerSpecification, FillLayerSpecification, FilterSpecification, LineLayerSpecification, StyleSpecification, SymbolLayerSpecification } from '@maplibre/maplibre-gl-style-spec';
2
- import type { TileJSONSpecificationRaster, TileJSONSpecificationVector } from './tilejson.js';
3
- /** Type for Maplibre styles specifically designed for raster sources. */
4
- export type MaplibreStyleRaster = Omit<StyleSpecification, 'sources'> & {
5
- 'sources': {
6
- [_: string]: TileJSONSpecificationRaster;
7
- };
8
- };
9
- /** Type for Maplibre styles specifically designed for vector sources. */
10
- export type MaplibreStyleVector = Omit<StyleSpecification, 'sources'> & {
11
- 'sources': {
12
- [_: string]: TileJSONSpecificationVector;
13
- };
14
- };
15
- /** Represents a Maplibre style, which can be either raster or vector. */
16
- export type MaplibreStyle = MaplibreStyleRaster | MaplibreStyleVector;
1
+ import type { BackgroundLayerSpecification, FillLayerSpecification, FilterSpecification, LineLayerSpecification, SymbolLayerSpecification } from '@maplibre/maplibre-gl-style-spec';
2
+ export type { StyleSpecification } from '@maplibre/maplibre-gl-style-spec';
17
3
  /** Type for Maplibre layers, including background, fill, line, and symbol specifications. */
18
4
  export type MaplibreLayer = BackgroundLayerSpecification | FillLayerSpecification | LineLayerSpecification | SymbolLayerSpecification;
19
5
  /** Defines the structure of Maplibre layer definitions, omitting the 'source' property for fill, line, and symbol specifications. */
@@ -1,7 +1,7 @@
1
1
  import type { VectorLayer } from './vector_layer.js';
2
2
  /** Basic structure for TileJSON specification, applicable to both raster and vector types. */
3
- export interface TileJSONSpecificationBasic {
4
- tilejson: '3.0.0';
3
+ export interface TileJSONSpecificationRaster {
4
+ tilejson?: '3.0.0';
5
5
  tiles: string[];
6
6
  attribution?: string;
7
7
  bounds?: [number, number, number, number];
@@ -16,16 +16,10 @@ export interface TileJSONSpecificationBasic {
16
16
  name?: string;
17
17
  scheme?: 'tms' | 'xyz';
18
18
  template?: string;
19
- }
20
- /** Structure for TileJSON specification of raster type, specifying raster-specific properties. */
21
- export interface TileJSONSpecificationRaster extends TileJSONSpecificationBasic {
22
- type: 'raster';
23
- format: 'avif' | 'jpg' | 'png' | 'webp';
19
+ version?: string;
24
20
  }
25
21
  /** Structure for TileJSON specification of vector type, specifying vector-specific properties. */
26
- export interface TileJSONSpecificationVector extends TileJSONSpecificationBasic {
27
- type: 'vector';
28
- format: 'pbf';
22
+ export interface TileJSONSpecificationVector extends TileJSONSpecificationRaster {
29
23
  vector_layers: VectorLayer[];
30
24
  }
31
25
  /** Represents a TileJSON specification, which can be either raster or vector. */
@@ -35,3 +29,4 @@ export type TileJSONSpecification = TileJSONSpecificationRaster | TileJSONSpecif
35
29
  * Throws errors if the object does not conform to the expected structure or types.
36
30
  */
37
31
  export declare function isTileJSONSpecification(spec: unknown): spec is TileJSONSpecification;
32
+ export declare function isRasterTileJSONSpecification(spec: unknown): spec is TileJSONSpecificationRaster;
@@ -1,4 +1,3 @@
1
- import { isVectorLayers } from './vector_layer.js';
2
1
  /**
3
2
  * Checks if an object adheres to the TileJSON specification.
4
3
  * Throws errors if the object does not conform to the expected structure or types.
@@ -9,13 +8,13 @@ export function isTileJSONSpecification(spec) {
9
8
  }
10
9
  const obj = spec;
11
10
  // Common property validation
12
- if (obj.tilejson !== '3.0.0') {
11
+ if (obj.data != null && obj.tilejson !== '3.0.0') {
13
12
  throw Error('spec.tilejson must be "3.0.0"');
14
13
  }
15
- if (obj.attribution !== undefined && typeof obj.attribution !== 'string') {
14
+ if (obj.attribution != null && typeof obj.attribution !== 'string') {
16
15
  throw Error('spec.attribution must be a string if present');
17
16
  }
18
- if (obj.bounds !== undefined) {
17
+ if (obj.bounds != null) {
19
18
  if (!Array.isArray(obj.bounds) || obj.bounds.length !== 4 || obj.bounds.some(num => typeof num !== 'number')) {
20
19
  throw Error('spec.bounds must be an array of four numbers if present');
21
20
  }
@@ -33,7 +32,7 @@ export function isTileJSONSpecification(spec) {
33
32
  if (a[1] > a[3])
34
33
  throw Error('spec.bounds[1] must be smaller than spec.bounds[3]');
35
34
  }
36
- if (obj.center !== undefined) {
35
+ if (obj.center != null) {
37
36
  if (!Array.isArray(obj.center) || obj.center.length !== 2 || obj.center.some(num => typeof num !== 'number')) {
38
37
  throw Error('spec.center must be an array of two numbers if present');
39
38
  }
@@ -43,61 +42,45 @@ export function isTileJSONSpecification(spec) {
43
42
  if (a[1] < -90 || a[1] > 90)
44
43
  throw Error('spec.center[1] must be between -90 and 90');
45
44
  }
46
- if (obj.data !== undefined && (!Array.isArray(obj.data) || obj.data.some(url => typeof url !== 'string'))) {
45
+ if (obj.data != null && (!Array.isArray(obj.data) || obj.data.some(url => typeof url !== 'string'))) {
47
46
  throw Error('spec.data must be an array of strings if present');
48
47
  }
49
- if (obj.description !== undefined && typeof obj.description !== 'string') {
48
+ if (obj.description != null && typeof obj.description !== 'string') {
50
49
  throw Error('spec.description must be a string if present');
51
50
  }
52
- if (obj.fillzoom !== undefined && (typeof obj.fillzoom !== 'number' || (obj.fillzoom < 0))) {
51
+ if (obj.fillzoom != null && (typeof obj.fillzoom !== 'number' || (obj.fillzoom < 0))) {
53
52
  throw Error('spec.fillzoom must be a positive integer if present');
54
53
  }
55
- if (obj.grids !== undefined && (!Array.isArray(obj.grids) || obj.grids.some(url => typeof url !== 'string'))) {
54
+ if (obj.grids != null && (!Array.isArray(obj.grids) || obj.grids.some(url => typeof url !== 'string'))) {
56
55
  throw Error('spec.grids must be an array of strings if present');
57
56
  }
58
- if (obj.legend !== undefined && typeof obj.legend !== 'string') {
57
+ if (obj.legend != null && typeof obj.legend !== 'string') {
59
58
  throw Error('spec.legend must be a string if present');
60
59
  }
61
- if (obj.minzoom !== undefined && (typeof obj.minzoom !== 'number' || (obj.minzoom < 0))) {
60
+ if (obj.minzoom != null && (typeof obj.minzoom !== 'number' || (obj.minzoom < 0))) {
62
61
  throw Error('spec.minzoom must be a positive integer if present');
63
62
  }
64
- if (obj.maxzoom !== undefined && (typeof obj.maxzoom !== 'number' || (obj.maxzoom < 0))) {
63
+ if (obj.maxzoom != null && (typeof obj.maxzoom !== 'number' || (obj.maxzoom < 0))) {
65
64
  throw Error('spec.maxzoom must be a positive integer if present');
66
65
  }
67
- if (obj.name !== undefined && typeof obj.name !== 'string') {
66
+ if (obj.name != null && typeof obj.name !== 'string') {
68
67
  throw Error('spec.name must be a string if present');
69
68
  }
70
- if (obj.scheme !== undefined && obj.scheme !== 'xyz' && obj.scheme !== 'tms') {
69
+ if (obj.scheme != null && obj.scheme !== 'xyz' && obj.scheme !== 'tms') {
71
70
  throw Error('spec.scheme must be "tms" or "xyz" if present');
72
71
  }
73
- if (obj.template !== undefined && typeof obj.template !== 'string') {
72
+ if (obj.template != null && typeof obj.template !== 'string') {
74
73
  throw Error('spec.template must be a string if present');
75
74
  }
76
75
  if (!Array.isArray(obj.tiles) || obj.tiles.length === 0 || obj.tiles.some(url => typeof url !== 'string')) {
77
76
  throw Error('spec.tiles must be an array of strings');
78
77
  }
79
- if (typeof obj.format !== 'string') {
80
- throw Error('spec.format must be a string');
81
- }
82
- if (obj.type === 'raster') {
83
- if (!['avif', 'jpg', 'png', 'webp'].includes(obj.format)) {
84
- throw Error('spec.format must be "avif", "jpg", "png", or "webp" for raster sources');
85
- }
86
- }
87
- else if (obj.type === 'vector') {
88
- if (obj.format !== 'pbf') {
89
- throw Error('spec.format must be "pbf" for vector sources');
90
- }
91
- try {
92
- if (!isVectorLayers(obj.vector_layers))
93
- throw Error('spec.vector_layers is invalid');
94
- }
95
- catch (error) {
96
- throw Error('spec.vector_layers is invalid: ' + String((error instanceof Error) ? error.message : error));
97
- }
98
- }
99
- else {
100
- throw Error('spec.type must be "raster" or "vector"');
101
- }
78
+ return true;
79
+ }
80
+ export function isRasterTileJSONSpecification(spec) {
81
+ if (!isTileJSONSpecification(spec))
82
+ return false;
83
+ if (('vector_layers' in spec) && (spec.vector_layers != null))
84
+ return false;
102
85
  return true;
103
86
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versatiles/style",
3
- "version": "5.2.0",
3
+ "version": "5.2.2",
4
4
  "description": "Generate StyleJSON for MapLibre",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -49,7 +49,6 @@
49
49
  "@types/tar-stream": "^3.1.3",
50
50
  "@typescript-eslint/eslint-plugin": "^8.20.0",
51
51
  "@typescript-eslint/parser": "^8.20.0",
52
- "@versatiles/container": "^1.2.3",
53
52
  "@versatiles/release-tool": "^1.2.6",
54
53
  "bin-pack": "^1.0.2",
55
54
  "eslint": "^9.18.0",
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 VersaTiles
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/dist/browser.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export type * from './styles/index.js';
2
- export * from './styles/index.js';
3
- export * as styles from './styles/index.js';
4
- export type { GuessStyleOptions } from './guess_style/index.js';
5
- export { guessStyle } from './guess_style/index.js';
6
- export { Color } from './color/index.js';
package/dist/browser.js DELETED
@@ -1,4 +0,0 @@
1
- export * from './styles/index.js';
2
- export * as styles from './styles/index.js';
3
- export { guessStyle } from './guess_style/index.js';
4
- export { Color } from './color/index.js';
@@ -1,23 +0,0 @@
1
- export interface GuessContainerOptions {
2
- tiles: string[];
3
- attribution?: string;
4
- baseUrl?: string;
5
- bounds?: [number, number, number, number];
6
- center?: [number, number];
7
- description?: string;
8
- fillzoom?: number;
9
- glyphs?: string;
10
- grids?: string[];
11
- legend?: string;
12
- maxzoom?: number;
13
- minzoom?: number;
14
- name?: string;
15
- scheme?: 'tms' | 'xyz';
16
- sprite?: string;
17
- template?: string;
18
- }
19
- /** Options for creating TileJSON, extending the basic specification with format and optional vector layers. */
20
- export interface GuessStyleOptions extends GuessContainerOptions {
21
- format: 'avif' | 'jpg' | 'pbf' | 'png' | 'webp';
22
- vectorLayers?: unknown[];
23
- }
@@ -1 +0,0 @@
1
- export {};