@versatiles/style 4.1.2 → 4.2.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 +50 -26
- package/dist/browser.d.ts +4 -0
- package/dist/browser.js +2 -0
- package/dist/guess_style/guess_style.d.ts +5 -0
- package/dist/{lib → guess_style}/guess_style.js +43 -13
- package/dist/guess_style/index.d.ts +2 -0
- package/dist/guess_style/index.js +1 -0
- package/dist/guess_style/types.d.ts +23 -0
- package/dist/guess_style/types.js +1 -0
- package/dist/index.d.ts +5 -11
- package/dist/index.js +2 -15
- package/dist/shortbread/index.d.ts +2 -0
- package/dist/shortbread/index.js +2 -0
- package/dist/shortbread/layers.d.ts +5 -0
- package/dist/{lib/shortbread → shortbread}/layers.js +16 -15
- package/dist/shortbread/template.d.ts +2 -0
- package/dist/{lib/shortbread → shortbread}/template.js +1 -1
- package/dist/{lib → style_builder}/decorator.d.ts +2 -1
- package/dist/{lib → style_builder}/decorator.js +2 -2
- package/dist/style_builder/index.d.ts +1 -0
- package/dist/style_builder/index.js +1 -0
- package/dist/style_builder/recolor.d.ts +22 -0
- package/dist/style_builder/style_builder.d.ts +14 -0
- package/dist/{lib/build_style.js → style_builder/style_builder.js} +6 -7
- package/dist/style_builder/types.d.ts +49 -0
- package/dist/style_builder/types.js +1 -0
- package/dist/{style → styles}/colorful.d.ts +2 -2
- package/dist/{style → styles}/colorful.js +1 -1
- package/dist/{style → styles}/graybeard.d.ts +1 -1
- package/dist/{style → styles}/graybeard.js +1 -1
- package/dist/styles/index.d.ts +9 -0
- package/dist/styles/index.js +12 -0
- package/dist/{style → styles}/neutrino.d.ts +2 -2
- package/dist/{style → styles}/neutrino.js +1 -1
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.js +2 -0
- package/dist/types/maplibre.d.ts +22 -0
- package/dist/types/maplibre.js +1 -0
- package/dist/types/tilejson.d.ts +37 -0
- package/dist/types/tilejson.js +103 -0
- package/dist/types/vector_layer.d.ts +14 -0
- package/dist/types/vector_layer.js +50 -0
- package/package.json +7 -6
- package/dist/lib/build_style.d.ts +0 -12
- package/dist/lib/guess_style.d.ts +0 -2
- package/dist/lib/recolor.d.ts +0 -4
- package/dist/lib/shortbread/layers.d.ts +0 -4
- package/dist/lib/shortbread/template.d.ts +0 -2
- package/dist/lib/types.d.ts +0 -145
- package/dist/lib/types.js +0 -97
- /package/dist/{lib → guess_style}/random_color.d.ts +0 -0
- /package/dist/{lib → guess_style}/random_color.js +0 -0
- /package/dist/{lib/shortbread → shortbread}/properties.d.ts +0 -0
- /package/dist/{lib/shortbread → shortbread}/properties.js +0 -0
- /package/dist/{lib → style_builder}/recolor.js +0 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { StyleBuilderOptions } from '../style_builder/types';
|
|
2
|
+
import type { MaplibreStyle } from '../types/maplibre';
|
|
3
|
+
export type { StyleBuilderOptions, MaplibreStyle };
|
|
4
|
+
import Colorful from './colorful';
|
|
5
|
+
import Graybeard from './graybeard';
|
|
6
|
+
import Neutrino from './neutrino';
|
|
7
|
+
export declare function colorful(options?: StyleBuilderOptions<Colorful>): MaplibreStyle;
|
|
8
|
+
export declare function graybeard(options?: StyleBuilderOptions<Graybeard>): MaplibreStyle;
|
|
9
|
+
export declare function neutrino(options?: StyleBuilderOptions<Neutrino>): MaplibreStyle;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Colorful from './colorful';
|
|
2
|
+
import Graybeard from './graybeard';
|
|
3
|
+
import Neutrino from './neutrino';
|
|
4
|
+
export function colorful(options) {
|
|
5
|
+
return new Colorful().build(options);
|
|
6
|
+
}
|
|
7
|
+
export function graybeard(options) {
|
|
8
|
+
return new Graybeard().build(options);
|
|
9
|
+
}
|
|
10
|
+
export function neutrino(options) {
|
|
11
|
+
return new Neutrino().build(options);
|
|
12
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import StyleBuilder from '../
|
|
2
|
-
import type { StyleRules, StyleRulesOptions } from '../
|
|
1
|
+
import StyleBuilder from '../style_builder/style_builder';
|
|
2
|
+
import type { StyleRules, StyleRulesOptions } from '../style_builder/types';
|
|
3
3
|
export default class Neutrino extends StyleBuilder<Neutrino> {
|
|
4
4
|
readonly name: string;
|
|
5
5
|
defaultFonts: {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { MaplibreStyle, MaplibreStyleVector, MaplibreLayerDefinition, MaplibreLayer } from './maplibre';
|
|
2
|
+
export type { VectorLayer } from './vector_layer';
|
|
3
|
+
export { isTileJSONSpecification } from './tilejson';
|
|
4
|
+
export type { TileJSONSpecification, TileJSONSpecificationBasic, TileJSONSpecificationRaster, TileJSONSpecificationVector } from './tilejson';
|
|
5
|
+
export { isVectorLayers } from './vector_layer';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { BackgroundLayerSpecification, FillLayerSpecification, FilterSpecification, LineLayerSpecification, StyleSpecification, SymbolLayerSpecification } from '@maplibre/maplibre-gl-style-spec';
|
|
2
|
+
import type { TileJSONSpecificationRaster, TileJSONSpecificationVector } from './tilejson';
|
|
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;
|
|
17
|
+
/** Type for Maplibre layers, including background, fill, line, and symbol specifications. */
|
|
18
|
+
export type MaplibreLayer = BackgroundLayerSpecification | FillLayerSpecification | LineLayerSpecification | SymbolLayerSpecification;
|
|
19
|
+
/** Defines the structure of Maplibre layer definitions, omitting the 'source' property for fill, line, and symbol specifications. */
|
|
20
|
+
export type MaplibreLayerDefinition = BackgroundLayerSpecification | Omit<FillLayerSpecification, 'source'> | Omit<LineLayerSpecification, 'source'> | Omit<SymbolLayerSpecification, 'source'>;
|
|
21
|
+
/** Represents a filter specification in Maplibre styles. */
|
|
22
|
+
export type MaplibreFilter = FilterSpecification;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { VectorLayer } from './vector_layer';
|
|
2
|
+
/** Basic structure for TileJSON specification, applicable to both raster and vector types. */
|
|
3
|
+
export interface TileJSONSpecificationBasic {
|
|
4
|
+
tilejson: '3.0.0';
|
|
5
|
+
tiles: string[];
|
|
6
|
+
attribution?: string;
|
|
7
|
+
bounds?: [number, number, number, number];
|
|
8
|
+
center?: [number, number];
|
|
9
|
+
data?: string[];
|
|
10
|
+
description?: string;
|
|
11
|
+
fillzoom?: number;
|
|
12
|
+
grids?: string[];
|
|
13
|
+
legend?: string;
|
|
14
|
+
maxzoom?: number;
|
|
15
|
+
minzoom?: number;
|
|
16
|
+
name?: string;
|
|
17
|
+
scheme?: 'tms' | 'xyz';
|
|
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';
|
|
24
|
+
}
|
|
25
|
+
/** Structure for TileJSON specification of vector type, specifying vector-specific properties. */
|
|
26
|
+
export interface TileJSONSpecificationVector extends TileJSONSpecificationBasic {
|
|
27
|
+
type: 'vector';
|
|
28
|
+
format: 'pbf';
|
|
29
|
+
vector_layers: VectorLayer[];
|
|
30
|
+
}
|
|
31
|
+
/** Represents a TileJSON specification, which can be either raster or vector. */
|
|
32
|
+
export type TileJSONSpecification = TileJSONSpecificationRaster | TileJSONSpecificationVector;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if an object adheres to the TileJSON specification.
|
|
35
|
+
* Throws errors if the object does not conform to the expected structure or types.
|
|
36
|
+
*/
|
|
37
|
+
export declare function isTileJSONSpecification(spec: unknown): spec is TileJSONSpecification;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { isVectorLayers } from './vector_layer';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if an object adheres to the TileJSON specification.
|
|
4
|
+
* Throws errors if the object does not conform to the expected structure or types.
|
|
5
|
+
*/
|
|
6
|
+
export function isTileJSONSpecification(spec) {
|
|
7
|
+
if (typeof spec !== 'object' || spec === null) {
|
|
8
|
+
throw Error('spec must be an object');
|
|
9
|
+
}
|
|
10
|
+
const obj = spec;
|
|
11
|
+
// Common property validation
|
|
12
|
+
if (obj.tilejson !== '3.0.0') {
|
|
13
|
+
throw Error('spec.tilejson must be "3.0.0"');
|
|
14
|
+
}
|
|
15
|
+
if (obj.attribution !== undefined && typeof obj.attribution !== 'string') {
|
|
16
|
+
throw Error('spec.attribution must be a string if present');
|
|
17
|
+
}
|
|
18
|
+
if (obj.bounds !== undefined) {
|
|
19
|
+
if (!Array.isArray(obj.bounds) || obj.bounds.length !== 4 || obj.bounds.some(num => typeof num !== 'number')) {
|
|
20
|
+
throw Error('spec.bounds must be an array of four numbers if present');
|
|
21
|
+
}
|
|
22
|
+
const a = obj.bounds;
|
|
23
|
+
if (a[0] < -180 || a[0] > 180)
|
|
24
|
+
throw Error('spec.bounds[0] must be between -180 and 180');
|
|
25
|
+
if (a[1] < -90 || a[1] > 90)
|
|
26
|
+
throw Error('spec.bounds[1] must be between -90 and 90');
|
|
27
|
+
if (a[2] < -180 || a[2] > 180)
|
|
28
|
+
throw Error('spec.bounds[2] must be between -180 and 180');
|
|
29
|
+
if (a[3] < -90 || a[3] > 90)
|
|
30
|
+
throw Error('spec.bounds[3] must be between -90 and 90');
|
|
31
|
+
if (a[0] > a[2])
|
|
32
|
+
throw Error('spec.bounds[0] must be smaller than spec.bounds[2]');
|
|
33
|
+
if (a[1] > a[3])
|
|
34
|
+
throw Error('spec.bounds[1] must be smaller than spec.bounds[3]');
|
|
35
|
+
}
|
|
36
|
+
if (obj.center !== undefined) {
|
|
37
|
+
if (!Array.isArray(obj.center) || obj.center.length !== 2 || obj.center.some(num => typeof num !== 'number')) {
|
|
38
|
+
throw Error('spec.center must be an array of two numbers if present');
|
|
39
|
+
}
|
|
40
|
+
const a = obj.center;
|
|
41
|
+
if (a[0] < -180 || a[0] > 180)
|
|
42
|
+
throw Error('spec.center[0] must be between -180 and 180');
|
|
43
|
+
if (a[1] < -90 || a[1] > 90)
|
|
44
|
+
throw Error('spec.center[1] must be between -90 and 90');
|
|
45
|
+
}
|
|
46
|
+
if (obj.data !== undefined && (!Array.isArray(obj.data) || obj.data.some(url => typeof url !== 'string'))) {
|
|
47
|
+
throw Error('spec.data must be an array of strings if present');
|
|
48
|
+
}
|
|
49
|
+
if (obj.description !== undefined && typeof obj.description !== 'string') {
|
|
50
|
+
throw Error('spec.description must be a string if present');
|
|
51
|
+
}
|
|
52
|
+
if (obj.fillzoom !== undefined && (typeof obj.fillzoom !== 'number' || (obj.fillzoom < 0))) {
|
|
53
|
+
throw Error('spec.fillzoom must be a positive integer if present');
|
|
54
|
+
}
|
|
55
|
+
if (obj.grids !== undefined && (!Array.isArray(obj.grids) || obj.grids.some(url => typeof url !== 'string'))) {
|
|
56
|
+
throw Error('spec.grids must be an array of strings if present');
|
|
57
|
+
}
|
|
58
|
+
if (obj.legend !== undefined && typeof obj.legend !== 'string') {
|
|
59
|
+
throw Error('spec.legend must be a string if present');
|
|
60
|
+
}
|
|
61
|
+
if (obj.minzoom !== undefined && (typeof obj.minzoom !== 'number' || (obj.minzoom < 0))) {
|
|
62
|
+
throw Error('spec.minzoom must be a positive integer if present');
|
|
63
|
+
}
|
|
64
|
+
if (obj.maxzoom !== undefined && (typeof obj.maxzoom !== 'number' || (obj.maxzoom < 0))) {
|
|
65
|
+
throw Error('spec.maxzoom must be a positive integer if present');
|
|
66
|
+
}
|
|
67
|
+
if (obj.name !== undefined && typeof obj.name !== 'string') {
|
|
68
|
+
throw Error('spec.name must be a string if present');
|
|
69
|
+
}
|
|
70
|
+
if (obj.scheme !== undefined && obj.scheme !== 'xyz' && obj.scheme !== 'tms') {
|
|
71
|
+
throw Error('spec.scheme must be "tms" or "xyz" if present');
|
|
72
|
+
}
|
|
73
|
+
if (obj.template !== undefined && typeof obj.template !== 'string') {
|
|
74
|
+
throw Error('spec.template must be a string if present');
|
|
75
|
+
}
|
|
76
|
+
if (!Array.isArray(obj.tiles) || obj.tiles.length === 0 || obj.tiles.some(url => typeof url !== 'string')) {
|
|
77
|
+
throw Error('spec.tiles must be an array of strings');
|
|
78
|
+
}
|
|
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
|
+
}
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Represents the structure of a vector layer in a TileJSON specification. */
|
|
2
|
+
export interface VectorLayer {
|
|
3
|
+
id: string;
|
|
4
|
+
fields: Record<string, 'Boolean' | 'Number' | 'String'>;
|
|
5
|
+
description?: string;
|
|
6
|
+
minzoom?: number;
|
|
7
|
+
maxzoom?: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Verifies if an object conforms to the VectorLayer structure.
|
|
11
|
+
* Throws errors for any deviations from the expected structure or types.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isVectorLayer(layer: unknown): layer is VectorLayer;
|
|
14
|
+
export declare function isVectorLayers(layers: unknown): layers is VectorLayer[];
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verifies if an object conforms to the VectorLayer structure.
|
|
3
|
+
* Throws errors for any deviations from the expected structure or types.
|
|
4
|
+
*/
|
|
5
|
+
export function isVectorLayer(layer) {
|
|
6
|
+
if (typeof layer !== 'object' || layer === null) {
|
|
7
|
+
throw new Error('Layer must be a non-null object');
|
|
8
|
+
}
|
|
9
|
+
const obj = layer;
|
|
10
|
+
if (typeof obj.id !== 'string') {
|
|
11
|
+
throw new Error('Layer.id must be a string');
|
|
12
|
+
}
|
|
13
|
+
if (typeof obj.fields !== 'object' || obj.fields === null) {
|
|
14
|
+
throw new Error('Layer.fields must be a non-null object');
|
|
15
|
+
}
|
|
16
|
+
if (Object.values(obj.fields).some(type => !['Boolean', 'Number', 'String'].includes(type))) {
|
|
17
|
+
throw new Error('Layer.fields values must be one of \'Boolean\', \'Number\', or \'String\'');
|
|
18
|
+
}
|
|
19
|
+
if ('description' in obj && typeof obj.description !== 'string') {
|
|
20
|
+
throw new Error('Layer.description must be a string if present');
|
|
21
|
+
}
|
|
22
|
+
if ('minzoom' in obj && (typeof obj.minzoom !== 'number' || obj.minzoom < 0)) {
|
|
23
|
+
throw new Error('Layer.minzoom must be a non-negative number if present');
|
|
24
|
+
}
|
|
25
|
+
if ('maxzoom' in obj && (typeof obj.maxzoom !== 'number' || obj.maxzoom < 0)) {
|
|
26
|
+
throw new Error('Layer.maxzoom must be a non-negative number if present');
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
export function isVectorLayers(layers) {
|
|
31
|
+
if (!Array.isArray(layers)) {
|
|
32
|
+
throw new Error('Expected an array of layers');
|
|
33
|
+
}
|
|
34
|
+
if (layers.length === 0) {
|
|
35
|
+
throw new Error('Array of layers cannot be empty');
|
|
36
|
+
}
|
|
37
|
+
layers.forEach((layer, index) => {
|
|
38
|
+
try {
|
|
39
|
+
if (!isVectorLayer(layer)) {
|
|
40
|
+
throw new Error(`Layer[${index}] is invalid`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
// Assuming `isVectorLayer` throws an error with a meaningful message, you can rethrow it
|
|
45
|
+
// Alternatively, customize the error message or handle the error as needed
|
|
46
|
+
throw new Error(`Layer[${index}] at invalid: ${String((error instanceof Error) ? error.message : error)}`);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return true;
|
|
50
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versatiles/style",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Generate StyleJSON for MapLibre",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -46,14 +46,15 @@
|
|
|
46
46
|
"@types/brace-expansion": "^1.1.2",
|
|
47
47
|
"@types/inquirer": "^9.0.7",
|
|
48
48
|
"@types/jest": "^29.5.12",
|
|
49
|
-
"@types/node": "^20.11.
|
|
49
|
+
"@types/node": "^20.11.20",
|
|
50
50
|
"@types/tar-stream": "^3.1.3",
|
|
51
|
-
"@typescript-eslint/eslint-plugin": "^7.0.
|
|
52
|
-
"@typescript-eslint/parser": "^7.0.
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "^7.0.2",
|
|
52
|
+
"@typescript-eslint/parser": "^7.0.2",
|
|
53
|
+
"@versatiles/container": "^1.2.0",
|
|
53
54
|
"@versatiles/release-tool": "^1.2.2",
|
|
54
55
|
"bin-pack": "^1.0.2",
|
|
55
|
-
"eslint": "^8.
|
|
56
|
-
"inquirer": "^9.2.
|
|
56
|
+
"eslint": "^8.57.0",
|
|
57
|
+
"inquirer": "^9.2.15",
|
|
57
58
|
"jest": "^29.7.0",
|
|
58
59
|
"jest-environment-jsdom": "^29.7.0",
|
|
59
60
|
"jest-ts-webcompat-resolver": "^1.0.0",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import Color from 'color';
|
|
2
|
-
import type { MaplibreStyle, StyleRules, StyleRulesOptions, StylemakerColorStrings, StylemakerColors, StylemakerFontStrings, StylemakerOptions } from './types.js';
|
|
3
|
-
export default abstract class StyleBuilder<Subclass extends StyleBuilder<Subclass>> {
|
|
4
|
-
#private;
|
|
5
|
-
abstract readonly name: string;
|
|
6
|
-
abstract readonly defaultColors: StylemakerColorStrings<Subclass>;
|
|
7
|
-
abstract readonly defaultFonts: StylemakerFontStrings<Subclass>;
|
|
8
|
-
build(options?: StylemakerOptions<Subclass>): MaplibreStyle;
|
|
9
|
-
getColors(colors: StylemakerColorStrings<Subclass>): StylemakerColors<Subclass>;
|
|
10
|
-
protected transformDefaultColors(callback: (color: Color) => Color): void;
|
|
11
|
-
protected abstract getStyleRules(options: StyleRulesOptions<Subclass>): StyleRules;
|
|
12
|
-
}
|
package/dist/lib/recolor.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { RecolorOptions, StylemakerColors } from './types.js';
|
|
2
|
-
import type StyleBuilder from './build_style.ts';
|
|
3
|
-
export declare function getDefaultRecolorFlags(): RecolorOptions;
|
|
4
|
-
export declare function recolor<Subclass extends StyleBuilder<Subclass>>(colors: StylemakerColors<Subclass>, opt?: RecolorOptions): void;
|
package/dist/lib/types.d.ts
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import type { BackgroundLayerSpecification, FillLayerSpecification, FilterSpecification, LineLayerSpecification, StyleSpecification, SymbolLayerSpecification } from '@maplibre/maplibre-gl-style-spec';
|
|
2
|
-
import type Color from 'color';
|
|
3
|
-
import type StyleBuilder from './build_style.ts';
|
|
4
|
-
/** Represents the available tile formats. */
|
|
5
|
-
export type TileFormat = 'avif' | 'bin' | 'geojson' | 'jpg' | 'json' | 'pbf' | 'png' | 'svg' | 'topojson' | 'webp';
|
|
6
|
-
/** Type for Maplibre layers, including background, fill, line, and symbol specifications. */
|
|
7
|
-
export type MaplibreLayer = BackgroundLayerSpecification | FillLayerSpecification | LineLayerSpecification | SymbolLayerSpecification;
|
|
8
|
-
/** Defines the structure of Maplibre layer definitions, omitting the 'source' property for fill, line, and symbol specifications. */
|
|
9
|
-
export type MaplibreLayerDefinition = BackgroundLayerSpecification | Omit<FillLayerSpecification, 'source'> | Omit<LineLayerSpecification, 'source'> | Omit<SymbolLayerSpecification, 'source'>;
|
|
10
|
-
/** Represents a filter specification in Maplibre styles. */
|
|
11
|
-
export type MaplibreFilter = FilterSpecification;
|
|
12
|
-
/** Represents the structure of a vector layer in a TileJSON specification. */
|
|
13
|
-
export interface VectorLayer {
|
|
14
|
-
id: string;
|
|
15
|
-
fields: Record<string, 'Boolean' | 'Number' | 'String'>;
|
|
16
|
-
description?: string;
|
|
17
|
-
minzoom?: number;
|
|
18
|
-
maxzoom?: number;
|
|
19
|
-
}
|
|
20
|
-
/** Basic structure for TileJSON specification, applicable to both raster and vector types. */
|
|
21
|
-
export interface TileJSONSpecificationBasic {
|
|
22
|
-
tilejson?: '3.0.0';
|
|
23
|
-
attribution?: string;
|
|
24
|
-
tiles: string[];
|
|
25
|
-
scheme?: 'tms' | 'xyz';
|
|
26
|
-
bounds?: [number, number, number, number];
|
|
27
|
-
center?: [number, number];
|
|
28
|
-
description?: string;
|
|
29
|
-
fillzoom?: number;
|
|
30
|
-
grids?: string[];
|
|
31
|
-
legend?: string;
|
|
32
|
-
minzoom?: number;
|
|
33
|
-
maxzoom?: number;
|
|
34
|
-
name?: string;
|
|
35
|
-
template?: string;
|
|
36
|
-
}
|
|
37
|
-
/** Structure for TileJSON specification of raster type, specifying raster-specific properties. */
|
|
38
|
-
export interface TileJSONSpecificationRaster extends TileJSONSpecificationBasic {
|
|
39
|
-
type: 'raster';
|
|
40
|
-
format: 'avif' | 'jpg' | 'png' | 'webp';
|
|
41
|
-
}
|
|
42
|
-
/** Structure for TileJSON specification of vector type, specifying vector-specific properties. */
|
|
43
|
-
export interface TileJSONSpecificationVector extends TileJSONSpecificationBasic {
|
|
44
|
-
type: 'vector';
|
|
45
|
-
format: 'pbf';
|
|
46
|
-
vector_layers: VectorLayer[];
|
|
47
|
-
}
|
|
48
|
-
/** Represents a TileJSON specification, which can be either raster or vector. */
|
|
49
|
-
export type TileJSONSpecification = TileJSONSpecificationRaster | TileJSONSpecificationVector;
|
|
50
|
-
/** Options for creating TileJSON, extending the basic specification with format and optional vector layers. */
|
|
51
|
-
export interface TileJSONOption extends TileJSONSpecificationBasic {
|
|
52
|
-
format: 'avif' | 'jpg' | 'pbf' | 'png' | 'webp';
|
|
53
|
-
vectorLayers?: VectorLayer[];
|
|
54
|
-
baseUrl?: string;
|
|
55
|
-
glyphs?: string;
|
|
56
|
-
sprite?: string;
|
|
57
|
-
}
|
|
58
|
-
/** Type for Maplibre styles specifically designed for raster sources. */
|
|
59
|
-
export type MaplibreStyleRaster = Omit<StyleSpecification, 'sources'> & {
|
|
60
|
-
'sources': {
|
|
61
|
-
[_: string]: TileJSONSpecificationRaster;
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
/** Type for Maplibre styles specifically designed for vector sources. */
|
|
65
|
-
export type MaplibreStyleVector = Omit<StyleSpecification, 'sources'> & {
|
|
66
|
-
'sources': {
|
|
67
|
-
[_: string]: TileJSONSpecificationVector;
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
/** Represents a Maplibre style, which can be either raster or vector. */
|
|
71
|
-
export type MaplibreStyle = MaplibreStyleRaster | MaplibreStyleVector;
|
|
72
|
-
/** Defines the value type for a style rule. */
|
|
73
|
-
export type StyleRuleValue = boolean | number | object | string;
|
|
74
|
-
/** Defines the structure of a style rule, which is a record of properties to style values. */
|
|
75
|
-
export type StyleRule = Record<string, StyleRuleValue | undefined>;
|
|
76
|
-
/** Defines the structure of style rules, which is a record of selectors to style rules. */
|
|
77
|
-
export type StyleRules = Record<string, StyleRule | undefined>;
|
|
78
|
-
/** Represents language suffixes used in map styles. */
|
|
79
|
-
export type LanguageSuffix = '_de' | '_en' | '';
|
|
80
|
-
/** Defines the keys for color properties in a style builder. */
|
|
81
|
-
export type StylemakerColorKeys<T extends StyleBuilder<T>> = keyof T['defaultColors'];
|
|
82
|
-
/** Defines the keys for font properties in a style builder. */
|
|
83
|
-
export type StylemakerFontKeys<T extends StyleBuilder<T>> = keyof T['defaultFonts'];
|
|
84
|
-
/** Records string values for color properties in a style builder. */
|
|
85
|
-
export type StylemakerColorStrings<T extends StyleBuilder<T>> = Record<StylemakerColorKeys<T>, string>;
|
|
86
|
-
/** Records string values for font properties in a style builder. */
|
|
87
|
-
export type StylemakerFontStrings<T extends StyleBuilder<T>> = Record<StylemakerFontKeys<T>, string>;
|
|
88
|
-
/** Records Color objects for color properties in a style builder. */
|
|
89
|
-
export type StylemakerColors<T extends StyleBuilder<T>> = Record<StylemakerColorKeys<T>, Color>;
|
|
90
|
-
/** Records string values for font properties in a style builder. */
|
|
91
|
-
export type StylemakerFonts<T extends StyleBuilder<T>> = Record<StylemakerFontKeys<T>, string>;
|
|
92
|
-
/** Defines options for style rules in a style builder. */
|
|
93
|
-
export interface StyleRulesOptions<T extends StyleBuilder<T>> {
|
|
94
|
-
colors: StylemakerColors<T>;
|
|
95
|
-
fonts: StylemakerFontStrings<T>;
|
|
96
|
-
languageSuffix: string;
|
|
97
|
-
}
|
|
98
|
-
export interface RecolorOptions {
|
|
99
|
-
/** If true, inverts the colors. */
|
|
100
|
-
invert?: boolean;
|
|
101
|
-
/** The degree to rotate the hue of the color (in degrees). */
|
|
102
|
-
rotate?: number;
|
|
103
|
-
/** Adjusts the saturation level of the color. Positive values increase saturation, negative values decrease it. */
|
|
104
|
-
saturate?: number;
|
|
105
|
-
/** Adjusts the gamma of the color. Affects the brightness in a non-linear manner. */
|
|
106
|
-
gamma?: number;
|
|
107
|
-
/** Adjusts the contrast of the color. Higher values produce more contrast. */
|
|
108
|
-
contrast?: number;
|
|
109
|
-
/** Adjusts the brightness of the color. Positive values make it brighter, negative values make it darker. */
|
|
110
|
-
brightness?: number;
|
|
111
|
-
/** Specifies the intensity of the tinting effect. Ranges from 0 (no effect) to 1 (full effect). */
|
|
112
|
-
tint?: number;
|
|
113
|
-
/** Specifies the color used for tinting, in a string format (e.g., '#FF0000'). */
|
|
114
|
-
tintColor?: string;
|
|
115
|
-
}
|
|
116
|
-
export interface StylemakerOptions<T extends StyleBuilder<T>> {
|
|
117
|
-
/** The base URL for loading external resources like tiles, sprites, and fonts. */
|
|
118
|
-
baseUrl?: string;
|
|
119
|
-
/** The URL template for loading font glyphs, formatted with `{fontstack}` and `{range}` placeholders. */
|
|
120
|
-
glyphs?: string;
|
|
121
|
-
/** The URL for loading sprite images and metadata. */
|
|
122
|
-
sprite?: string;
|
|
123
|
-
/** An array of URL templates for loading map tiles, with `{z}`, `{x}`, and `{y}` placeholders. */
|
|
124
|
-
tiles?: string[];
|
|
125
|
-
/** If true, hides all map labels. */
|
|
126
|
-
hideLabels?: boolean;
|
|
127
|
-
/** Suffix to append to language-specific resources, such as `"-en"` for English. */
|
|
128
|
-
languageSuffix?: LanguageSuffix;
|
|
129
|
-
/** An object specifying overrides for default color values, keyed by the color names. */
|
|
130
|
-
colors?: Partial<StylemakerColorStrings<T>>;
|
|
131
|
-
/** An object specifying overrides for default font names, keyed by the font names. */
|
|
132
|
-
fonts?: Partial<StylemakerFontStrings<T>>;
|
|
133
|
-
/** Options for color adjustments and transformations applied to the entire style. */
|
|
134
|
-
recolor?: RecolorOptions;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Checks if an object adheres to the TileJSON specification.
|
|
138
|
-
* Throws errors if the object does not conform to the expected structure or types.
|
|
139
|
-
*/
|
|
140
|
-
export declare function isTileJSONSpecification(obj: unknown): obj is TileJSONSpecification;
|
|
141
|
-
/**
|
|
142
|
-
* Validates if an object conforms to the VectorLayer structure.
|
|
143
|
-
* Throws errors for any deviations from the expected structure or types.
|
|
144
|
-
*/
|
|
145
|
-
export declare function validateVectorLayer(obj: unknown): boolean;
|
package/dist/lib/types.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
|
|
2
|
-
/**
|
|
3
|
-
* Checks if an object adheres to the TileJSON specification.
|
|
4
|
-
* Throws errors if the object does not conform to the expected structure or types.
|
|
5
|
-
*/
|
|
6
|
-
export function isTileJSONSpecification(obj) {
|
|
7
|
-
if (typeof obj !== 'object' || obj === null) {
|
|
8
|
-
throw Error('spec must be an object');
|
|
9
|
-
}
|
|
10
|
-
const spec = obj;
|
|
11
|
-
// Common property validation
|
|
12
|
-
if (typeof spec.tilejson !== 'undefined' && spec.tilejson !== '3.0.0') {
|
|
13
|
-
throw Error('spec.tilejson must be "3.0.0" if present');
|
|
14
|
-
}
|
|
15
|
-
if (typeof spec.attribution !== 'undefined' && typeof spec.attribution !== 'string') {
|
|
16
|
-
throw Error('spec.attribution must be a string if present');
|
|
17
|
-
}
|
|
18
|
-
if (typeof spec.scheme !== 'undefined' && !['tms', 'xyz'].includes(spec.scheme)) {
|
|
19
|
-
throw Error('spec.scheme must be "tms" or "xyz" if present');
|
|
20
|
-
}
|
|
21
|
-
if (typeof spec.bounds !== 'undefined' && (!Array.isArray(spec.bounds) || spec.bounds.length !== 4 || spec.bounds.some(num => typeof num !== 'number'))) {
|
|
22
|
-
throw Error('spec.bounds must be an array of four numbers if present');
|
|
23
|
-
}
|
|
24
|
-
if (typeof spec.center !== 'undefined' && (!Array.isArray(spec.center) || spec.center.length !== 2 || spec.center.some(num => typeof num !== 'number'))) {
|
|
25
|
-
throw Error('spec.center must be an array of two numbers if present');
|
|
26
|
-
}
|
|
27
|
-
if (typeof spec.description !== 'undefined' && typeof spec.description !== 'string') {
|
|
28
|
-
throw Error('spec.description must be a string if present');
|
|
29
|
-
}
|
|
30
|
-
if (typeof spec.fillzoom !== 'undefined' && typeof spec.fillzoom !== 'number') {
|
|
31
|
-
throw Error('spec.fillzoom must be a number if present');
|
|
32
|
-
}
|
|
33
|
-
if (typeof spec.grids !== 'undefined' && (!Array.isArray(spec.grids) || spec.grids.some(url => typeof url !== 'string'))) {
|
|
34
|
-
throw Error('spec.grids must be an array of strings if present');
|
|
35
|
-
}
|
|
36
|
-
if (typeof spec.legend !== 'undefined' && typeof spec.legend !== 'string') {
|
|
37
|
-
throw Error('spec.legend must be a string if present');
|
|
38
|
-
}
|
|
39
|
-
if (typeof spec.minzoom !== 'undefined' && typeof spec.minzoom !== 'number') {
|
|
40
|
-
throw Error('spec.minzoom must be a number if present');
|
|
41
|
-
}
|
|
42
|
-
if (typeof spec.maxzoom !== 'undefined' && typeof spec.maxzoom !== 'number') {
|
|
43
|
-
throw Error('spec.maxzoom must be a number if present');
|
|
44
|
-
}
|
|
45
|
-
if (typeof spec.name !== 'undefined' && typeof spec.name !== 'string') {
|
|
46
|
-
throw Error('spec.name must be a string if present');
|
|
47
|
-
}
|
|
48
|
-
if (typeof spec.template !== 'undefined' && typeof spec.template !== 'string') {
|
|
49
|
-
throw Error('spec.template must be a string if present');
|
|
50
|
-
}
|
|
51
|
-
if (!Array.isArray(spec.tiles) || spec.tiles.length === 0 || spec.tiles.some(url => typeof url !== 'string')) {
|
|
52
|
-
throw Error('spec.tiles must be an array of strings');
|
|
53
|
-
}
|
|
54
|
-
if (spec.type === 'raster') {
|
|
55
|
-
if (!['avif', 'jpg', 'png', 'webp'].includes(spec.format)) {
|
|
56
|
-
throw Error('spec.format must be "avif", "jpg", "png", or "webp"');
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
else if (spec.type === 'vector') {
|
|
60
|
-
if (spec.format !== 'pbf') {
|
|
61
|
-
throw Error('spec.format must be "pbf"');
|
|
62
|
-
}
|
|
63
|
-
if (!Array.isArray(spec.vector_layers) || spec.vector_layers.length === 0 || spec.vector_layers.some(layer => !validateVectorLayer(layer))) {
|
|
64
|
-
throw Error('spec.vector_layers must be an array of VectorLayer');
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
throw Error('spec.type must be "raster" or "vector"');
|
|
69
|
-
}
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Validates if an object conforms to the VectorLayer structure.
|
|
74
|
-
* Throws errors for any deviations from the expected structure or types.
|
|
75
|
-
*/
|
|
76
|
-
export function validateVectorLayer(obj) {
|
|
77
|
-
if (typeof obj !== 'object' || obj === null) {
|
|
78
|
-
throw Error('layer must be an object');
|
|
79
|
-
}
|
|
80
|
-
const layer = obj;
|
|
81
|
-
if (typeof layer.id !== 'string') {
|
|
82
|
-
throw Error('layer.id must be a string');
|
|
83
|
-
}
|
|
84
|
-
if (typeof layer.fields !== 'object' || layer.fields === null || Object.values(layer.fields).some(type => !['Boolean', 'Number', 'String'].includes(type))) {
|
|
85
|
-
throw Error('layer.fields must be an object with values "Boolean", "Number", or "String"');
|
|
86
|
-
}
|
|
87
|
-
if (typeof layer.description !== 'undefined' && typeof layer.description !== 'string') {
|
|
88
|
-
throw Error('layer.description must be a string if present');
|
|
89
|
-
}
|
|
90
|
-
if (typeof layer.minzoom !== 'undefined' && (typeof layer.minzoom !== 'number' || layer.minzoom < 0)) {
|
|
91
|
-
throw Error('layer.minzoom must be a non-negative number if present');
|
|
92
|
-
}
|
|
93
|
-
if (typeof layer.maxzoom !== 'undefined' && (typeof layer.maxzoom !== 'number' || layer.maxzoom < 0)) {
|
|
94
|
-
throw Error('layer.maxzoom must be a non-negative number if present');
|
|
95
|
-
}
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|