@versatiles/style 4.3.0 → 4.4.1

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
@@ -1,6 +1,7 @@
1
1
  [![NPM Version](https://img.shields.io/npm/v/%40versatiles%2Fstyle)](https://www.npmjs.com/package/@versatiles/style)
2
2
  [![Code Coverage](https://codecov.io/gh/versatiles-org/versatiles-style/branch/main/graph/badge.svg?token=IDHAI13M0K)](https://codecov.io/gh/versatiles-org/versatiles-style)
3
3
  [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/versatiles-org/versatiles-style/ci.yml)](https://github.com/versatiles-org/versatiles-style/actions/workflows/ci.yml)
4
+ [![GitHub Downloads (all assets, all releases)](https://img.shields.io/github/downloads/versatiles-org/versatiles-style/total)](https://github.com/versatiles-org/versatiles-style/releases/latest)
4
5
 
5
6
  # VersaTiles Style
6
7
 
@@ -46,12 +47,12 @@ Use it in:
46
47
  colors: { label: '#222' },
47
48
  recolor: { gamma: 0.5 }
48
49
  });
49
-
50
- const map = new maplibregl.Map({
51
- container: 'map',
52
- style
53
- });
54
- <script>
50
+
51
+ const map = new maplibregl.Map({
52
+ container: 'map',
53
+ style
54
+ });
55
+ </script>
55
56
  ```
56
57
 
57
58
  # Create styles in the backend (Node.js)
@@ -191,5 +192,5 @@ Iconsets can be defined in [`scripts/config-sprites.ts`](./scripts/config-sprite
191
192
 
192
193
  # Licenses
193
194
 
194
- * Sourcecode: [Unlicense](./UNLICENSE.md)
195
+ * Sourcecode: [Unlicense](./LICENSE.md)
195
196
  * Iconsets and rendered Spritemaps: [CC0 1.0 Universal](./icons/LICENSE.md)
@@ -90,9 +90,12 @@ export async function guessStyleFromContainer(container, options) {
90
90
  }
91
91
  let vectorLayers;
92
92
  if (typeof metadata === 'string') {
93
- const t = JSON.parse(metadata);
94
- if (('vector_layers' in t) && Array.isArray(t.vector_layers))
95
- vectorLayers = t.vector_layers;
93
+ try {
94
+ const t = JSON.parse(metadata);
95
+ if (('vector_layers' in t) && Array.isArray(t.vector_layers))
96
+ vectorLayers = t.vector_layers;
97
+ }
98
+ catch (e) { }
96
99
  }
97
100
  const guessStyleOptions = {
98
101
  ...options,
@@ -1,7 +1,7 @@
1
1
  import Color from 'color';
2
2
  export interface RecolorOptions {
3
3
  /** If true, inverts the colors. */
4
- invert?: boolean;
4
+ invertBrightness?: boolean;
5
5
  /** The degree to rotate the hue of the color (in degrees). */
6
6
  rotate?: number;
7
7
  /** Adjusts the saturation level of the color. Positive values increase saturation, negative values decrease it. */
@@ -1,7 +1,7 @@
1
1
  import Color from 'color';
2
2
  export function getDefaultRecolorFlags() {
3
3
  return {
4
- invert: false,
4
+ invertBrightness: false,
5
5
  rotate: 0,
6
6
  saturate: 0,
7
7
  gamma: 1,
@@ -14,7 +14,7 @@ export function getDefaultRecolorFlags() {
14
14
  function isValidRecolorOptions(opt) {
15
15
  if (!opt)
16
16
  return false;
17
- if ((opt.invert != null) && opt.invert)
17
+ if ((opt.invertBrightness != null) && opt.invertBrightness)
18
18
  return true;
19
19
  if ((opt.rotate != null) && (opt.rotate !== 0))
20
20
  return true;
@@ -63,8 +63,8 @@ export class CachedRecolor {
63
63
  export function recolor(color, opt) {
64
64
  if (!isValidRecolorOptions(opt))
65
65
  return color;
66
- if (opt.invert ?? false)
67
- color = color.negate();
66
+ if (opt.invertBrightness ?? false)
67
+ color = invert(color);
68
68
  if ((opt.rotate !== undefined) && (opt.rotate !== 0))
69
69
  color = color.rotate(opt.rotate);
70
70
  if ((opt.saturate !== undefined) && (opt.saturate !== 0))
@@ -78,6 +78,10 @@ export function recolor(color, opt) {
78
78
  if ((opt.tint !== undefined) && (opt.tintColor !== undefined) && (opt.tint !== 0))
79
79
  color = tint(color, opt.tint, Color(opt.tintColor));
80
80
  return color;
81
+ function invert(c) {
82
+ c = c.hsl();
83
+ return c.lightness(100 - c.lightness()).rgb();
84
+ }
81
85
  function gamma(c, value) {
82
86
  if (value < 1e-3)
83
87
  value = 1e-3;
@@ -48,8 +48,8 @@ export default class StyleBuilder {
48
48
  case 'line':
49
49
  case 'symbol':
50
50
  return {
51
- ...layer,
52
51
  source: this.#sourceName,
52
+ ...layer,
53
53
  };
54
54
  }
55
55
  throw Error('unknown layer type');
@@ -0,0 +1,5 @@
1
+ import Colorful from './colorful.js';
2
+ export default class Eclipse extends Colorful {
3
+ readonly name: string;
4
+ constructor();
5
+ }
@@ -0,0 +1,11 @@
1
+ import Colorful from './colorful.js';
2
+ export default class Eclipse extends Colorful {
3
+ name = 'Eclipse';
4
+ constructor() {
5
+ super();
6
+ this.transformDefaultColors(color => {
7
+ color = color.hsl();
8
+ return color.lightness(100 - color.lightness()).rgb();
9
+ });
10
+ }
11
+ }
@@ -0,0 +1,11 @@
1
+ import StyleBuilder from '../style_builder/style_builder.js';
2
+ import type { StyleRules, StyleRulesOptions } from '../style_builder/types.js';
3
+ export default class Empty extends StyleBuilder<Empty> {
4
+ readonly name: string;
5
+ defaultFonts: {
6
+ regular: string;
7
+ bold: string;
8
+ };
9
+ defaultColors: {};
10
+ protected getStyleRules(options: StyleRulesOptions<Empty>): StyleRules;
11
+ }
@@ -0,0 +1,13 @@
1
+ import StyleBuilder from '../style_builder/style_builder.js';
2
+ export default class Empty extends StyleBuilder {
3
+ name = 'Empty';
4
+ defaultFonts = {
5
+ regular: 'noto_sans_regular',
6
+ bold: 'noto_sans_bold',
7
+ };
8
+ defaultColors = {};
9
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
10
+ getStyleRules(options) {
11
+ return {};
12
+ }
13
+ }
@@ -4,19 +4,27 @@ import type { MaplibreStyle } from '../types/maplibre.js';
4
4
  import type { RecolorOptions } from '../style_builder/recolor.js';
5
5
  export type { MaplibreStyle, RecolorOptions };
6
6
  import Colorful from './colorful.js';
7
+ import Eclipse from './eclipse.js';
7
8
  import Graybeard from './graybeard.js';
8
9
  import Neutrino from './neutrino.js';
10
+ import Empty from './empty.js';
9
11
  export type ColorfulOptions = StyleBuilderOptions<Colorful>;
12
+ export type EclipseOptions = StyleBuilderOptions<Eclipse>;
10
13
  export type GraybeardOptions = StyleBuilderOptions<Graybeard>;
11
14
  export type NeutrinoOptions = StyleBuilderOptions<Neutrino>;
12
- export type SomeOptions = ColorfulOptions | GraybeardOptions | NeutrinoOptions;
15
+ export type EmptyOptions = StyleBuilderOptions<Empty>;
16
+ export type SomeOptions = ColorfulOptions | EclipseOptions | EmptyOptions | GraybeardOptions | NeutrinoOptions;
13
17
  type MakeStyle<T extends StyleBuilder<T>, O extends StyleBuilderOptions<T>> = ((options?: O) => MaplibreStyle) & {
14
18
  getOptions: () => O;
15
19
  };
16
20
  export type ColorfulBuilder = MakeStyle<Colorful, ColorfulOptions>;
21
+ export type EclipseBuilder = MakeStyle<Eclipse, EclipseOptions>;
17
22
  export type GraybeardBuilder = MakeStyle<Graybeard, GraybeardOptions>;
18
23
  export type NeutrinoBuilder = MakeStyle<Neutrino, NeutrinoOptions>;
19
- export type SomeBuilder = ColorfulBuilder | GraybeardBuilder | NeutrinoBuilder;
24
+ export type EmptyBuilder = MakeStyle<Empty, EmptyOptions>;
25
+ export type SomeBuilder = ColorfulBuilder | EclipseBuilder | EmptyBuilder | GraybeardBuilder | NeutrinoBuilder;
20
26
  export declare const colorful: ColorfulBuilder;
27
+ export declare const eclipse: EclipseBuilder;
21
28
  export declare const graybeard: GraybeardBuilder;
22
29
  export declare const neutrino: NeutrinoBuilder;
30
+ export declare const empty: EmptyBuilder;
@@ -1,13 +1,19 @@
1
+ // import styles
1
2
  import Colorful from './colorful.js';
3
+ import Eclipse from './eclipse.js';
2
4
  import Graybeard from './graybeard.js';
3
5
  import Neutrino from './neutrino.js';
4
- function makeStyle(styleBuilder) {
6
+ import Empty from './empty.js';
7
+ function getStyleBuilder(styleBuilder) {
5
8
  const fn = function (options) {
6
9
  return new styleBuilder().build(options);
7
10
  };
8
11
  fn.getOptions = () => new styleBuilder().getDefaultOptions();
9
12
  return fn;
10
13
  }
11
- export const colorful = makeStyle(Colorful);
12
- export const graybeard = makeStyle(Graybeard);
13
- export const neutrino = makeStyle(Neutrino);
14
+ // generate style builders
15
+ export const colorful = getStyleBuilder(Colorful);
16
+ export const eclipse = getStyleBuilder(Eclipse);
17
+ export const graybeard = getStyleBuilder(Graybeard);
18
+ export const neutrino = getStyleBuilder(Neutrino);
19
+ export const empty = getStyleBuilder(Empty);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versatiles/style",
3
- "version": "4.3.0",
3
+ "version": "4.4.1",
4
4
  "description": "Generate StyleJSON for MapLibre",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -14,6 +14,7 @@
14
14
  "// dev": "????",
15
15
  "// doc": "vrt ts2md src/index.ts tsconfig.node.json | vrt insertmd README.md '# API'",
16
16
  "lint": "eslint --color .",
17
+ "prepack": "npm run build",
17
18
  "release": "npx vrt release-npm",
18
19
  "test": "npm run test-typescript",
19
20
  "test-coverage": "NODE_OPTIONS=--experimental-vm-modules jest --coverage",
@@ -37,8 +38,8 @@
37
38
  "dist/**/*.d.ts"
38
39
  ],
39
40
  "devDependencies": {
40
- "@maplibre/maplibre-gl-style-spec": "^20.1.1",
41
- "@rollup/plugin-commonjs": "^25.0.7",
41
+ "@maplibre/maplibre-gl-style-spec": "^20.3.0",
42
+ "@rollup/plugin-commonjs": "^26.0.1",
42
43
  "@rollup/plugin-node-resolve": "^15.2.3",
43
44
  "@rollup/plugin-terser": "^0.4.4",
44
45
  "@rollup/plugin-typescript": "^11.1.6",
@@ -46,26 +47,26 @@
46
47
  "@types/brace-expansion": "^1.1.2",
47
48
  "@types/inquirer": "^9.0.7",
48
49
  "@types/jest": "^29.5.12",
49
- "@types/node": "^20.11.24",
50
+ "@types/node": "^20.14.2",
50
51
  "@types/tar-stream": "^3.1.3",
51
- "@typescript-eslint/eslint-plugin": "^7.1.0",
52
- "@typescript-eslint/parser": "^7.1.0",
52
+ "@typescript-eslint/eslint-plugin": "^7.12.0",
53
+ "@typescript-eslint/parser": "^7.12.0",
53
54
  "@versatiles/container": "^1.2.1",
54
- "@versatiles/release-tool": "^1.2.2",
55
+ "@versatiles/release-tool": "^1.2.3",
55
56
  "bin-pack": "^1.0.2",
56
- "eslint": "^8.57.0",
57
- "inquirer": "^9.2.15",
57
+ "eslint": "^8.56.0",
58
+ "inquirer": "^9.2.23",
58
59
  "jest": "^29.7.0",
59
60
  "jest-environment-jsdom": "^29.7.0",
60
61
  "jest-ts-webcompat-resolver": "^1.0.0",
61
- "npm-check-updates": "^16.14.15",
62
- "rollup": "^4.12.0",
63
- "rollup-plugin-dts": "^6.1.0",
64
- "sharp": "^0.33.2",
62
+ "npm-check-updates": "^16.14.20",
63
+ "rollup": "^4.18.0",
64
+ "rollup-plugin-dts": "^6.1.1",
65
+ "sharp": "^0.33.4",
65
66
  "tar-stream": "^3.1.7",
66
- "ts-jest": "^29.1.2",
67
+ "ts-jest": "^29.1.4",
67
68
  "ts-node": "^10.9.2",
68
- "tsx": "^4.7.1",
69
- "typescript": "^5.3.3"
69
+ "tsx": "^4.12.0",
70
+ "typescript": "^5.4.5"
70
71
  }
71
72
  }