@versatiles/style 3.8.1 → 4.0.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 CHANGED
@@ -35,12 +35,18 @@ Use it in:
35
35
  <script src="maplibre-gl.js"></script>
36
36
  <script src="versatiles-style.js"></script>
37
37
  <script>
38
- const styleBuilder = new VersaTilesStyle.Colorful();
39
- styleBuilder.tilesUrl = ['tiles/{z}/{x}/{y}'];
38
+ const style = VersaTilesStyle.styles.graybeard({
39
+ tiles: ['https://???.org/tiles/osm/{z}/{x}/{y}'],
40
+ sprite: 'https://???.org/assets/styles/swr-bright/sprite',
41
+ glyphs: 'https://???.org/assets/fonts/{fontstack}/{range}.pbf',
42
+ languageSuffix: '_de',
43
+ colors: { label: '#222' },
44
+ recolor: { gamma: 0.5 }
45
+ });
40
46
 
41
47
  const map = new maplibregl.Map({
42
48
  container: 'map',
43
- style: styleBuilder.build()
49
+ style
44
50
  });
45
51
  <script>
46
52
  ```
@@ -56,9 +62,10 @@ npm install versatiles-style
56
62
  Use it in Node.js:
57
63
 
58
64
  ```javascript
59
- import { Colorful } from 'versatiles-style';
60
- let style = new Colorful();
61
- style.language = 'de';
65
+ import { styles } from 'versatiles-style';
66
+ let style = styles.colorful({
67
+ languageSuffix: '_en',
68
+ });
62
69
  writeFileSync('style.json', JSON.stringify(style.build()));
63
70
  ```
64
71
 
package/dist/index.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import type { MaplibreStyle, StylemakerOptions } from './lib/types.js';
2
+ export type { TileJSONSpecification, TileJSONSpecificationRaster, TileJSONSpecificationVector } from './lib/types.js';
2
3
  import Colorful from './style/colorful.js';
3
- export declare function colorful(options?: StylemakerOptions<Colorful>): MaplibreStyle;
4
4
  import Graybeard from './style/graybeard.js';
5
- export declare function graybeard(options?: StylemakerOptions<Graybeard>): MaplibreStyle;
6
5
  import Neutrino from './style/neutrino.js';
7
- export declare function neutrino(options?: StylemakerOptions<Neutrino>): MaplibreStyle;
8
- export type { TileJSONSpecification, TileJSONSpecificationRaster, TileJSONSpecificationVector } from './lib/types.js';
9
- export { default as guessStyle } from './lib/style_guesser.js';
6
+ export declare const styles: {
7
+ colorful: (options?: StylemakerOptions<Colorful>) => MaplibreStyle;
8
+ graybeard: (options?: StylemakerOptions<Graybeard>) => MaplibreStyle;
9
+ neutrino: (options?: StylemakerOptions<Neutrino>) => MaplibreStyle;
10
+ };
11
+ export { default as guessStyle } from './lib/guess_style.js';
package/dist/index.js CHANGED
@@ -1,13 +1,15 @@
1
1
  import Colorful from './style/colorful.js';
2
- export function colorful(options) {
3
- return new Colorful().build(options);
4
- }
5
2
  import Graybeard from './style/graybeard.js';
6
- export function graybeard(options) {
7
- return new Graybeard().build(options);
8
- }
9
3
  import Neutrino from './style/neutrino.js';
10
- export function neutrino(options) {
11
- return new Neutrino().build(options);
12
- }
13
- export { default as guessStyle } from './lib/style_guesser.js';
4
+ export const styles = {
5
+ colorful: function colorful(options) {
6
+ return new Colorful().build(options);
7
+ },
8
+ graybeard: function graybeard(options) {
9
+ return new Graybeard().build(options);
10
+ },
11
+ neutrino: function neutrino(options) {
12
+ return new Neutrino().build(options);
13
+ },
14
+ };
15
+ export { default as guessStyle } from './lib/guess_style.js';
@@ -1,17 +1,16 @@
1
1
  /* eslint-disable @typescript-eslint/naming-convention */
2
- import * as builders from './index.js';
3
- describe('Style Builders', () => {
4
- const styles = [
5
- { name: 'Colorful', builder: builders.colorful },
6
- { name: 'Graybeard', builder: builders.graybeard },
7
- { name: 'Neutrino', builder: builders.neutrino },
8
- ];
9
- styles.forEach(({ name, builder }) => {
2
+ import { guessStyle, styles } from './index.js';
3
+ describe('styles', () => {
4
+ it('should be all styles', () => {
5
+ expect(Array.from(Object.keys(styles)).sort())
6
+ .toStrictEqual(['colorful', 'graybeard', 'neutrino']);
7
+ });
8
+ Object.entries(styles).forEach(([name, builder]) => {
10
9
  it(`should create and test an instance of ${name}`, () => {
11
10
  expect(typeof builder).toBe('function');
12
11
  const style = builder({ baseUrl: 'https://example.org' });
13
12
  expect(JSON.stringify(style).length).toBeGreaterThan(50000);
14
- expect(style.name).toBe('versatiles-' + name.toLowerCase());
13
+ expect(style.name).toBe('versatiles-' + name);
15
14
  expect(style.glyphs).toBe('https://example.org/assets/fonts/{fontstack}/{range}.pbf');
16
15
  expect(style.sprite).toBe('https://example.org/assets/sprites/sprites');
17
16
  expect(Object.keys(style.sources).join(',')).toBe('versatiles-shortbread');
@@ -20,7 +19,7 @@ describe('Style Builders', () => {
20
19
  });
21
20
  });
22
21
  describe('Colorful', () => {
23
- const style = builders.colorful({
22
+ const style = styles.colorful({
24
23
  baseUrl: 'https://dev.null',
25
24
  colors: { commercial: '#f00' },
26
25
  });
@@ -38,7 +37,7 @@ describe('guessStyle', () => {
38
37
  const tiles = ['https://fancy.map/tiles/{z}/{x}/{y}'];
39
38
  const vectorLayers = [{ id: 'hallo', fields: { label: 'String' } }];
40
39
  it('should build raster styles', () => {
41
- const style = builders.guessStyle({
40
+ const style = guessStyle({
42
41
  tiles,
43
42
  format: 'png',
44
43
  });
@@ -49,7 +48,7 @@ describe('guessStyle', () => {
49
48
  });
50
49
  });
51
50
  it('should build vector styles', () => {
52
- const style = builders.guessStyle({
51
+ const style = guessStyle({
53
52
  tiles,
54
53
  format: 'pbf',
55
54
  vectorLayers,
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/naming-convention */
2
2
  import Color from 'color';
3
- import StyleBuilder from './style_builder.js';
3
+ import StyleBuilder from './build_style.js';
4
4
  // Mock class for abstract class StyleBuilder
5
5
  class MockStyleBuilder extends StyleBuilder {
6
6
  name = 'mock';
@@ -98,7 +98,7 @@ function processColor(value) {
98
98
  if (typeof value === 'string')
99
99
  value = Color(value);
100
100
  if (value instanceof Color) {
101
- value = (value.alpha() === 1) ? value.hex() : value.hexa();
101
+ value = (value.alpha() === 1) ? value.hex() : value.string();
102
102
  return value.toLowerCase();
103
103
  }
104
104
  throw new Error(`unknown color type "${typeof value}"`);
@@ -27,7 +27,7 @@ describe('decorate function', () => {
27
27
  expect(layer.layout).toHaveProperty('visibility', 'none');
28
28
  }
29
29
  if (layer.id === 'layer2') {
30
- expect(layer.paint).toHaveProperty('line-color', '#00ff0080');
30
+ expect(layer.paint).toHaveProperty('line-color', 'rgba(0, 255, 0, 0.5)');
31
31
  expect(layer.layout).toHaveProperty('visibility', 'visible');
32
32
  }
33
33
  });
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/naming-convention */
2
2
  import getTemplate from './shortbread/template.js';
3
- import guessStyle from './style_guesser.js';
3
+ import guessStyle from './guess_style.js';
4
4
  describe('guessStyle', () => {
5
5
  const tiles = ['https://example.com/tiles/{z}/{x}/{y}'];
6
6
  const vectorLayersSomething = [{ id: 'geometry', fields: { label: 'String', height: 'Number' } }];
@@ -121,4 +121,22 @@ describe('guessStyle', () => {
121
121
  });
122
122
  });
123
123
  });
124
+ describe('absolute tile urls override baseUrl', () => {
125
+ cases.forEach(({ type, options }) => {
126
+ it(type, () => {
127
+ const style = guessStyle({ ...options, tiles: ['https://example1.org/tiles/{z}/{x}/{y}'], baseUrl: 'https://example2.org/' });
128
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
129
+ expect(Object.values(style.sources)[0].tiles).toEqual(['https://example1.org/tiles/{z}/{x}/{y}']);
130
+ });
131
+ });
132
+ });
133
+ describe('relative tile urls are resolved with baseUrl', () => {
134
+ cases.forEach(({ type, options }) => {
135
+ it(type, () => {
136
+ const style = guessStyle({ ...options, tiles: ['./{z}/{x}/{y}'], baseUrl: 'https://example2.org/tiles/' });
137
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
138
+ expect(Object.values(style.sources)[0].tiles).toEqual(['https://example2.org/tiles/{z}/{x}/{y}']);
139
+ });
140
+ });
141
+ });
124
142
  });
@@ -1,4 +1,4 @@
1
1
  import type { RecolorOptions, StylemakerColors } from './types.js';
2
- import type StyleBuilder from './style_builder.ts';
2
+ import type StyleBuilder from './build_style.ts';
3
3
  export declare function getDefaultRecolorFlags(): RecolorOptions;
4
4
  export declare function recolor<Subclass extends StyleBuilder<Subclass>>(colors: StylemakerColors<Subclass>, opt?: RecolorOptions): void;
@@ -1,5 +1,5 @@
1
1
  import type { StyleRules, StyleRulesOptions } from './types.js';
2
- import StyleBuilder from './style_builder.js';
2
+ import StyleBuilder from './build_style.js';
3
3
  export default class TestStyle extends StyleBuilder<TestStyle> {
4
4
  readonly name: string;
5
5
  defaultFonts: {};
@@ -1,5 +1,5 @@
1
1
  import { getDefaultRecolorFlags, recolor } from './recolor.js';
2
- import StyleBuilder from './style_builder.js';
2
+ import StyleBuilder from './build_style.js';
3
3
  describe('colorTransformer', () => {
4
4
  describe('getDefaultRecolorFlags', () => {
5
5
  it('should return the default color transformer flags', () => {
@@ -1,6 +1,6 @@
1
1
  import type { BackgroundLayerSpecification, FillLayerSpecification, FilterSpecification, LineLayerSpecification, StyleSpecification, SymbolLayerSpecification } from '@maplibre/maplibre-gl-style-spec';
2
2
  import type Color from 'color';
3
- import type StyleBuilder from './style_builder.ts';
3
+ import type StyleBuilder from './build_style.ts';
4
4
  /** Represents the available tile formats. */
5
5
  export type TileFormat = 'avif' | 'bin' | 'geojson' | 'jpg' | 'json' | 'pbf' | 'png' | 'svg' | 'topojson' | 'webp';
6
6
  /** Type for Maplibre layers, including background, fill, line, and symbol specifications. */
@@ -1,4 +1,4 @@
1
- import StyleBuilder from '../lib/style_builder.js';
1
+ import StyleBuilder from '../lib/build_style.js';
2
2
  import type { StyleRules, StyleRulesOptions } from '../lib/types.js';
3
3
  export default class Colorful extends StyleBuilder<Colorful> {
4
4
  readonly name: string;
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/naming-convention */
2
- import StyleBuilder from '../lib/style_builder.js';
2
+ import StyleBuilder from '../lib/build_style.js';
3
3
  export default class Colorful extends StyleBuilder {
4
4
  name = 'Colorful';
5
5
  defaultFonts = {
@@ -1,4 +1,4 @@
1
- import StyleBuilder from '../lib/style_builder.js';
1
+ import StyleBuilder from '../lib/build_style.js';
2
2
  import type { StyleRules, StyleRulesOptions } from '../lib/types.js';
3
3
  export default class Neutrino extends StyleBuilder<Neutrino> {
4
4
  readonly name: string;
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/naming-convention */
2
- import StyleBuilder from '../lib/style_builder.js';
2
+ import StyleBuilder from '../lib/build_style.js';
3
3
  export default class Neutrino extends StyleBuilder {
4
4
  name = 'Neutrino';
5
5
  defaultFonts = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versatiles/style",
3
- "version": "3.8.1",
3
+ "version": "4.0.0",
4
4
  "description": "Generate StyleJSON for MapLibre",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,7 +12,7 @@
12
12
  "build-styles": "tsx scripts/build-styles.ts",
13
13
  "doc": "vrt ts2md src/index.ts tsconfig.node.json | vrt insertmd README.md '# API'",
14
14
  "lint": "npm run build-browser && eslint --color .",
15
- "release": "tsx scripts/release.ts",
15
+ "release": "npx vrt release-npm",
16
16
  "test": "npm run test-typescript && npm run test-node && npm run test-browser",
17
17
  "test-browser": "npm run build-browser && jest -c=jest.config.browser.ts",
18
18
  "test-coverage": "NODE_OPTIONS=--experimental-vm-modules jest -c=jest.config.coverage.ts",
@@ -37,29 +37,29 @@
37
37
  "dist/**/*.d.ts"
38
38
  ],
39
39
  "devDependencies": {
40
- "@maplibre/maplibre-gl-style-spec": "^19.3.3",
40
+ "@maplibre/maplibre-gl-style-spec": "^20.1.1",
41
41
  "@rollup/plugin-commonjs": "^25.0.7",
42
42
  "@rollup/plugin-node-resolve": "^15.2.3",
43
43
  "@rollup/plugin-terser": "^0.4.4",
44
- "@rollup/plugin-typescript": "^11.1.5",
44
+ "@rollup/plugin-typescript": "^11.1.6",
45
45
  "@types/brace-expansion": "^1.1.2",
46
46
  "@types/inquirer": "^9.0.7",
47
- "@types/jest": "^29.5.11",
48
- "@types/node": "^20.10.6",
49
- "@typescript-eslint/eslint-plugin": "^6.17.0",
50
- "@typescript-eslint/parser": "^6.17.0",
51
- "@versatiles/release-tool": "^1.0.3",
47
+ "@types/jest": "^29.5.12",
48
+ "@types/node": "^20.11.19",
49
+ "@typescript-eslint/eslint-plugin": "^7.0.1",
50
+ "@typescript-eslint/parser": "^7.0.1",
51
+ "@versatiles/release-tool": "^1.2.1",
52
52
  "eslint": "^8.56.0",
53
- "inquirer": "^9.2.12",
53
+ "inquirer": "^9.2.14",
54
54
  "jest": "^29.7.0",
55
55
  "jest-environment-jsdom": "^29.7.0",
56
56
  "jest-ts-webcompat-resolver": "^1.0.0",
57
- "npm-check-updates": "^16.14.12",
58
- "rollup": "^4.9.3",
57
+ "npm-check-updates": "^16.14.15",
58
+ "rollup": "^4.11.0",
59
59
  "rollup-plugin-dts": "^6.1.0",
60
- "ts-jest": "^29.1.1",
60
+ "ts-jest": "^29.1.2",
61
61
  "ts-node": "^10.9.2",
62
- "tsx": "^4.7.0",
62
+ "tsx": "^4.7.1",
63
63
  "typescript": "^5.3.3"
64
64
  }
65
65
  }
File without changes
File without changes