@versatiles/style 4.2.1 → 4.2.3

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/dist/browser.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type * from './styles';
2
- export * as styles from './styles';
3
- export type { GuessStyleOptions } from './guess_style';
4
- export { guessStyle } from './guess_style';
1
+ export type * from './styles/index.js';
2
+ export * as styles from './styles/index.js';
3
+ export type { GuessStyleOptions } from './guess_style/index.js';
4
+ export { guessStyle } from './guess_style/index.js';
package/dist/browser.js CHANGED
@@ -1,2 +1,2 @@
1
- export * as styles from './styles';
2
- export { guessStyle } from './guess_style';
1
+ export * as styles from './styles/index.js';
2
+ export { guessStyle } from './guess_style/index.js';
@@ -1,5 +1,5 @@
1
- import type { MaplibreStyle } from '../types';
1
+ import type { MaplibreStyle } from '../types/index.js';
2
2
  import type { Container } from '@versatiles/container';
3
- import type { GuessContainerOptions, GuessStyleOptions } from './types';
3
+ import type { GuessContainerOptions, GuessStyleOptions } from './types.js';
4
4
  export declare function guessStyle(opt: GuessStyleOptions): MaplibreStyle;
5
5
  export declare function guessStyleFromContainer(container: Container, options: GuessContainerOptions): Promise<MaplibreStyle>;
@@ -1,8 +1,8 @@
1
1
  /* eslint-disable @typescript-eslint/naming-convention */
2
- import { isTileJSONSpecification, isVectorLayers } from '../types';
3
- import { resolveUrl } from '../lib/utils';
4
- import randomColorGenerator from './random_color';
5
- import { colorful } from '../styles';
2
+ import { isTileJSONSpecification, isVectorLayers } from '../types/index.js';
3
+ import { resolveUrl } from '../lib/utils.js';
4
+ import randomColorGenerator from './random_color.js';
5
+ import { colorful } from '../styles/index.js';
6
6
  export function guessStyle(opt) {
7
7
  const { format } = opt;
8
8
  const tilejsonBasic = {
@@ -1,2 +1,2 @@
1
- export type { GuessStyleOptions, GuessContainerOptions } from './types';
2
- export { guessStyle, guessStyleFromContainer } from './guess_style';
1
+ export type { GuessStyleOptions, GuessContainerOptions } from './types.js';
2
+ export { guessStyle, guessStyleFromContainer } from './guess_style.js';
@@ -1 +1 @@
1
- export { guessStyle, guessStyleFromContainer } from './guess_style';
1
+ export { guessStyle, guessStyleFromContainer } from './guess_style.js';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export type * from './styles';
2
- export * as styles from './styles';
3
- export { guessStyle, guessStyleFromContainer } from './guess_style';
4
- export type { GuessStyleOptions, GuessContainerOptions } from './guess_style';
5
- export type { VectorLayer } from './types';
1
+ export type * from './styles/index.js';
2
+ export * as styles from './styles/index.js';
3
+ export { guessStyle, guessStyleFromContainer } from './guess_style/index.js';
4
+ export type { GuessStyleOptions, GuessContainerOptions } from './guess_style/index.js';
5
+ export type { VectorLayer } from './types/index.js';
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export * as styles from './styles';
2
- export { guessStyle, guessStyleFromContainer } from './guess_style';
1
+ export * as styles from './styles/index.js';
2
+ export { guessStyle, guessStyleFromContainer } from './guess_style/index.js';
@@ -1,2 +1,2 @@
1
- export { getShortbreadTemplate } from './template';
2
- export { getShortbreadLayers } from './layers';
1
+ export { getShortbreadTemplate } from './template.js';
2
+ export { getShortbreadLayers } from './layers.js';
@@ -1,2 +1,2 @@
1
- export { getShortbreadTemplate } from './template';
2
- export { getShortbreadLayers } from './layers';
1
+ export { getShortbreadTemplate } from './template.js';
2
+ export { getShortbreadLayers } from './layers.js';
@@ -1,5 +1,5 @@
1
- import type { LanguageSuffix } from '../style_builder';
2
- import type { MaplibreLayerDefinition } from '../types';
1
+ import type { LanguageSuffix } from '../style_builder/index.js';
2
+ import type { MaplibreLayerDefinition } from '../types/index.js';
3
3
  export declare function getShortbreadLayers(option: {
4
4
  readonly languageSuffix: LanguageSuffix;
5
5
  }): MaplibreLayerDefinition[];
@@ -1,2 +1,2 @@
1
- import type { MaplibreStyleVector } from '../types';
1
+ import type { MaplibreStyleVector } from '../types/index.js';
2
2
  export declare function getShortbreadTemplate(): MaplibreStyleVector;
@@ -1,3 +1,3 @@
1
- import type { MaplibreLayer } from '../types';
2
- import type { StyleRules } from './types';
1
+ import type { MaplibreLayer } from '../types/index.js';
2
+ import type { StyleRules } from './types.js';
3
3
  export declare function decorate(layers: MaplibreLayer[], rules: StyleRules): MaplibreLayer[];
@@ -1,7 +1,7 @@
1
1
  import Color from 'color';
2
2
  import expandBraces from 'brace-expansion';
3
- import maplibreProperties from '../shortbread/properties';
4
- import { deepMerge } from '../lib/utils';
3
+ import maplibreProperties from '../shortbread/properties.js';
4
+ import { deepMerge } from '../lib/utils.js';
5
5
  export function decorate(layers, rules) {
6
6
  const layerIds = layers.map(l => l.id);
7
7
  const layerIdSet = new Set(layerIds);
@@ -1 +1 @@
1
- export type { LanguageSuffix } from './types';
1
+ export type { LanguageSuffix } from './types.js';
@@ -1,5 +1,5 @@
1
- import type StyleBuilder from './style_builder';
2
- import type { StyleBuilderColors } from './types';
1
+ import type StyleBuilder from './style_builder.js';
2
+ import type { StyleBuilderColors } from './types.js';
3
3
  export interface RecolorOptions {
4
4
  /** If true, inverts the colors. */
5
5
  invert?: boolean;
@@ -1,7 +1,7 @@
1
1
  import Color from 'color';
2
- import type { MaplibreStyle } from '../types/maplibre';
3
- import type { StyleBuilderColorStrings, StyleBuilderColors, StyleBuilderFontStrings, StyleBuilderOptions } from './types';
4
- import type { StyleRules, StyleRulesOptions } from './types';
2
+ import type { MaplibreStyle } from '../types/maplibre.js';
3
+ import type { StyleBuilderColorStrings, StyleBuilderColors, StyleBuilderFontStrings, StyleBuilderOptions } from './types.js';
4
+ import type { StyleRules, StyleRulesOptions } from './types.js';
5
5
  export default abstract class StyleBuilder<Subclass extends StyleBuilder<Subclass>> {
6
6
  #private;
7
7
  abstract readonly name: string;
@@ -9,6 +9,7 @@ export default abstract class StyleBuilder<Subclass extends StyleBuilder<Subclas
9
9
  abstract readonly defaultFonts: StyleBuilderFontStrings<Subclass>;
10
10
  build(options?: StyleBuilderOptions<Subclass>): MaplibreStyle;
11
11
  getColors(colors: StyleBuilderColorStrings<Subclass>): StyleBuilderColors<Subclass>;
12
+ getDefaultOptions(): StyleBuilderOptions<Subclass>;
12
13
  protected transformDefaultColors(callback: (color: Color) => Color): void;
13
14
  protected abstract getStyleRules(options: StyleRulesOptions<Subclass>): StyleRules;
14
15
  }
@@ -1,8 +1,8 @@
1
1
  import Color from 'color';
2
- import { getShortbreadTemplate, getShortbreadLayers } from '../shortbread';
3
- import { decorate } from './decorator';
4
- import { getDefaultRecolorFlags, recolor } from './recolor';
5
- import { deepClone, resolveUrl } from '../lib/utils';
2
+ import { getShortbreadTemplate, getShortbreadLayers } from '../shortbread/index.js';
3
+ import { decorate } from './decorator.js';
4
+ import { getDefaultRecolorFlags, recolor } from './recolor.js';
5
+ import { deepClone, resolveUrl } from '../lib/utils.js';
6
6
  // StyleBuilder class definition
7
7
  export default class StyleBuilder {
8
8
  #sourceName = 'versatiles-shortbread';
@@ -23,7 +23,7 @@ export default class StyleBuilder {
23
23
  }
24
24
  // transform colors
25
25
  recolor(colors, recolorOptions);
26
- const fonts = deepClone(this.defaultColors);
26
+ const fonts = deepClone(this.defaultFonts);
27
27
  if (options.fonts) {
28
28
  for (const key in options.fonts) {
29
29
  const fontName = options.fonts[key];
@@ -35,7 +35,7 @@ export default class StyleBuilder {
35
35
  const style = getShortbreadTemplate();
36
36
  const styleRuleOptions = {
37
37
  colors,
38
- fonts: deepClone(this.defaultFonts),
38
+ fonts,
39
39
  languageSuffix,
40
40
  };
41
41
  // get layer style rules from child class
@@ -76,6 +76,19 @@ export default class StyleBuilder {
76
76
  const result = Object.fromEntries(entriesColor);
77
77
  return result;
78
78
  }
79
+ getDefaultOptions() {
80
+ return {
81
+ baseUrl: '',
82
+ glyphs: '',
83
+ sprite: '',
84
+ tiles: [],
85
+ hideLabels: false,
86
+ languageSuffix: undefined,
87
+ colors: deepClone(this.defaultColors),
88
+ fonts: deepClone(this.defaultFonts),
89
+ recolor: getDefaultRecolorFlags(),
90
+ };
91
+ }
79
92
  transformDefaultColors(callback) {
80
93
  const colors = this.getColors(this.defaultColors);
81
94
  for (const key in colors) {
@@ -1,6 +1,6 @@
1
1
  import type Color from 'color';
2
- import type StyleBuilder from './style_builder';
3
- import type { RecolorOptions } from './recolor';
2
+ import type StyleBuilder from './style_builder.js';
3
+ import type { RecolorOptions } from './recolor.js';
4
4
  /** Represents language suffixes used in map styles. */
5
5
  export type LanguageSuffix = 'de' | 'en' | undefined;
6
6
  export interface StyleBuilderOptions<T extends StyleBuilder<T>> {
@@ -1,5 +1,5 @@
1
- import StyleBuilder from '../style_builder/style_builder';
2
- import type { StyleRules, StyleRulesOptions } from '../style_builder/types';
1
+ import StyleBuilder from '../style_builder/style_builder.js';
2
+ import type { StyleRules, StyleRulesOptions } from '../style_builder/types.js';
3
3
  export default class Colorful extends StyleBuilder<Colorful> {
4
4
  readonly name: string;
5
5
  defaultFonts: {
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/naming-convention */
2
- import StyleBuilder from '../style_builder/style_builder';
2
+ import StyleBuilder from '../style_builder/style_builder.js';
3
3
  export default class Colorful extends StyleBuilder {
4
4
  name = 'Colorful';
5
5
  defaultFonts = {
@@ -1,4 +1,4 @@
1
- import Colorful from './colorful';
1
+ import Colorful from './colorful.js';
2
2
  export default class Graybeard extends Colorful {
3
3
  readonly name: string;
4
4
  constructor();
@@ -1,4 +1,4 @@
1
- import Colorful from './colorful';
1
+ import Colorful from './colorful.js';
2
2
  export default class Graybeard extends Colorful {
3
3
  name = 'Graybeard';
4
4
  constructor() {
@@ -1,9 +1,13 @@
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;
1
+ import type StyleBuilder from '../style_builder/style_builder.js';
2
+ import type { StyleBuilderOptions } from '../style_builder/types.js';
3
+ import type { MaplibreStyle } from '../types/maplibre.js';
4
+ export type { StyleBuilderOptions, MaplibreStyle, StyleBuilder };
5
+ import Colorful from './colorful.js';
6
+ import Graybeard from './graybeard.js';
7
+ import Neutrino from './neutrino.js';
8
+ type MakeStyle<T extends StyleBuilder<T>> = ((options?: StyleBuilderOptions<T>) => MaplibreStyle) & {
9
+ getOptions: () => StyleBuilderOptions<T>;
10
+ };
11
+ export declare const colorful: MakeStyle<Colorful>;
12
+ export declare const graybeard: MakeStyle<Graybeard>;
13
+ export declare const neutrino: MakeStyle<Neutrino>;
@@ -1,12 +1,13 @@
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);
1
+ import Colorful from './colorful.js';
2
+ import Graybeard from './graybeard.js';
3
+ import Neutrino from './neutrino.js';
4
+ function makeStyle(styleBuilder) {
5
+ const fn = function (options) {
6
+ return new styleBuilder().build(options);
7
+ };
8
+ fn.getOptions = () => new styleBuilder().getDefaultOptions();
9
+ return fn;
12
10
  }
11
+ export const colorful = makeStyle(Colorful);
12
+ export const graybeard = makeStyle(Graybeard);
13
+ export const neutrino = makeStyle(Neutrino);
@@ -1,5 +1,5 @@
1
- import StyleBuilder from '../style_builder/style_builder';
2
- import type { StyleRules, StyleRulesOptions } from '../style_builder/types';
1
+ import StyleBuilder from '../style_builder/style_builder.js';
2
+ import type { StyleRules, StyleRulesOptions } from '../style_builder/types.js';
3
3
  export default class Neutrino extends StyleBuilder<Neutrino> {
4
4
  readonly name: string;
5
5
  defaultFonts: {
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/naming-convention */
2
- import StyleBuilder from '../style_builder/style_builder';
2
+ import StyleBuilder from '../style_builder/style_builder.js';
3
3
  export default class Neutrino extends StyleBuilder {
4
4
  name = 'Neutrino';
5
5
  defaultFonts = {
@@ -1,5 +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';
1
+ export type { MaplibreStyle, MaplibreStyleVector, MaplibreLayerDefinition, MaplibreLayer } from './maplibre.js';
2
+ export type { VectorLayer } from './vector_layer.js';
3
+ export { isTileJSONSpecification } from './tilejson.js';
4
+ export type { TileJSONSpecification, TileJSONSpecificationBasic, TileJSONSpecificationRaster, TileJSONSpecificationVector } from './tilejson.js';
5
+ export { isVectorLayers } from './vector_layer.js';
@@ -1,2 +1,2 @@
1
- export { isTileJSONSpecification } from './tilejson';
2
- export { isVectorLayers } from './vector_layer';
1
+ export { isTileJSONSpecification } from './tilejson.js';
2
+ export { isVectorLayers } from './vector_layer.js';
@@ -1,5 +1,5 @@
1
1
  import type { BackgroundLayerSpecification, FillLayerSpecification, FilterSpecification, LineLayerSpecification, StyleSpecification, SymbolLayerSpecification } from '@maplibre/maplibre-gl-style-spec';
2
- import type { TileJSONSpecificationRaster, TileJSONSpecificationVector } from './tilejson';
2
+ import type { TileJSONSpecificationRaster, TileJSONSpecificationVector } from './tilejson.js';
3
3
  /** Type for Maplibre styles specifically designed for raster sources. */
4
4
  export type MaplibreStyleRaster = Omit<StyleSpecification, 'sources'> & {
5
5
  'sources': {
@@ -1,4 +1,4 @@
1
- import type { VectorLayer } from './vector_layer';
1
+ import type { VectorLayer } from './vector_layer.js';
2
2
  /** Basic structure for TileJSON specification, applicable to both raster and vector types. */
3
3
  export interface TileJSONSpecificationBasic {
4
4
  tilejson: '3.0.0';
@@ -1,4 +1,4 @@
1
- import { isVectorLayers } from './vector_layer';
1
+ import { isVectorLayers } from './vector_layer.js';
2
2
  /**
3
3
  * Checks if an object adheres to the TileJSON specification.
4
4
  * Throws errors if the object does not conform to the expected structure or types.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versatiles/style",
3
- "version": "4.2.1",
3
+ "version": "4.2.3",
4
4
  "description": "Generate StyleJSON for MapLibre",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -29,7 +29,7 @@
29
29
  "type": "module",
30
30
  "dependencies": {
31
31
  "@types/color": "^3.0.6",
32
- "brace-expansion": "^3.0.0",
32
+ "brace-expansion": "^4.0.0",
33
33
  "color": "^4.2.3"
34
34
  },
35
35
  "files": [
@@ -46,11 +46,11 @@
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.20",
49
+ "@types/node": "^20.11.24",
50
50
  "@types/tar-stream": "^3.1.3",
51
- "@typescript-eslint/eslint-plugin": "^7.0.2",
52
- "@typescript-eslint/parser": "^7.0.2",
53
- "@versatiles/container": "^1.2.0",
51
+ "@typescript-eslint/eslint-plugin": "^7.1.0",
52
+ "@typescript-eslint/parser": "^7.1.0",
53
+ "@versatiles/container": "^1.2.1",
54
54
  "@versatiles/release-tool": "^1.2.2",
55
55
  "bin-pack": "^1.0.2",
56
56
  "eslint": "^8.57.0",