@tileflow/core 0.1.0-alpha.2 → 0.1.0-alpha.4
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/index.d.ts +11 -5
- package/dist/index.js +26 -8
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ type TileflowTheme = 'standard' | 'light' | 'dark' | 'minimal' | 'osm-bright-2';
|
|
|
6
6
|
type TileflowBuildings = 'hidden' | 'flat' | '3d';
|
|
7
7
|
type TileflowTerrainMode = 'none' | 'hillshade' | '3d';
|
|
8
8
|
type TileflowTerrainEncoding = 'mapbox' | 'terrarium';
|
|
9
|
-
type
|
|
9
|
+
type TileflowThemeName = 'light' | 'dark';
|
|
10
|
+
type TileflowThemeMode = TileflowThemeName;
|
|
10
11
|
type TileflowColors = {
|
|
11
12
|
canvas: string;
|
|
12
13
|
land: string;
|
|
@@ -28,9 +29,13 @@ type TileflowTypography = {
|
|
|
28
29
|
font?: string;
|
|
29
30
|
weight?: TileflowFontWeight;
|
|
30
31
|
};
|
|
32
|
+
type TileflowFonts = {
|
|
33
|
+
body?: string;
|
|
34
|
+
labels?: string;
|
|
35
|
+
};
|
|
31
36
|
type TileflowThemeConfig = {
|
|
32
|
-
mode?: TileflowThemeMode;
|
|
33
37
|
colors?: TileflowColorConfig;
|
|
38
|
+
fonts?: TileflowFonts;
|
|
34
39
|
typography?: TileflowTypography;
|
|
35
40
|
};
|
|
36
41
|
type TileflowSourceLayers = {
|
|
@@ -118,13 +123,14 @@ type TileflowTilesetConfig = {
|
|
|
118
123
|
attribution?: string;
|
|
119
124
|
sourceLayers?: TileflowSourceLayers;
|
|
120
125
|
};
|
|
126
|
+
type TileflowProjectThemes = Partial<Record<TileflowThemeName, TileflowThemeConfig>>;
|
|
121
127
|
type TileflowProjectConfig = {
|
|
122
|
-
themes?:
|
|
128
|
+
themes?: TileflowProjectThemes;
|
|
123
129
|
tilesets?: Record<string, TileflowTilesetConfig>;
|
|
124
130
|
maps: Record<string, TileflowMapConfig>;
|
|
125
131
|
};
|
|
126
132
|
type TileflowStyleOptions = {
|
|
127
|
-
themes?:
|
|
133
|
+
themes?: TileflowProjectThemes;
|
|
128
134
|
tileBaseUrl?: string;
|
|
129
135
|
tileset?: string;
|
|
130
136
|
};
|
|
@@ -169,4 +175,4 @@ declare function osm(options?: TileflowOsmBasemapOptions): TileflowOsmBasemapCon
|
|
|
169
175
|
|
|
170
176
|
declare function roads(options?: TileflowRoadsModuleOptions): TileflowRoadsModuleConfig;
|
|
171
177
|
|
|
172
|
-
export { type MapLibreStyle, type TileflowBasemapConfig, type TileflowBuildings, type TileflowColorConfig, type TileflowColors, type TileflowConfig, type TileflowDensity, type TileflowFontWeight, type TileflowLabels, type TileflowManifest, type TileflowMapConfig, type TileflowModuleConfig, type TileflowOsmBasemapConfig, type TileflowOsmBasemapOptions, type TileflowPoi, type TileflowProjectConfig, type TileflowRoads, type TileflowRoadsModuleConfig, type TileflowRoadsModuleOptions, type TileflowRoadsModulePreset, type TileflowSourceLayers, type TileflowStyleOptions, type TileflowTerrain, type TileflowTerrainConfig, type TileflowTerrainEncoding, type TileflowTerrainMode, type TileflowTheme, type TileflowThemeConfig, type TileflowThemeMode, type TileflowTiles, type TileflowTilesetConfig, type TileflowTypography, type TileflowViewConfig, type ValidationMessage, type ValidationResult, createManifest, createStyle, createStyleFromProject, defineTileflow, getDefaultColors, osm, roads, validateConfig };
|
|
178
|
+
export { type MapLibreStyle, type TileflowBasemapConfig, type TileflowBuildings, type TileflowColorConfig, type TileflowColors, type TileflowConfig, type TileflowDensity, type TileflowFontWeight, type TileflowFonts, type TileflowLabels, type TileflowManifest, type TileflowMapConfig, type TileflowModuleConfig, type TileflowOsmBasemapConfig, type TileflowOsmBasemapOptions, type TileflowPoi, type TileflowProjectConfig, type TileflowProjectThemes, type TileflowRoads, type TileflowRoadsModuleConfig, type TileflowRoadsModuleOptions, type TileflowRoadsModulePreset, type TileflowSourceLayers, type TileflowStyleOptions, type TileflowTerrain, type TileflowTerrainConfig, type TileflowTerrainEncoding, type TileflowTerrainMode, type TileflowTheme, type TileflowThemeConfig, type TileflowThemeMode, type TileflowThemeName, type TileflowTiles, type TileflowTilesetConfig, type TileflowTypography, type TileflowViewConfig, type ValidationMessage, type ValidationResult, createManifest, createStyle, createStyleFromProject, defineTileflow, getDefaultColors, osm, roads, validateConfig };
|
package/dist/index.js
CHANGED
|
@@ -2591,11 +2591,15 @@ var typographySchema = z.object({
|
|
|
2591
2591
|
font: z.string().trim().min(1).optional(),
|
|
2592
2592
|
weight: z.enum(["regular", "medium", "semibold", "bold"]).optional()
|
|
2593
2593
|
});
|
|
2594
|
+
var fontsSchema = z.object({
|
|
2595
|
+
body: z.string().trim().min(1).optional(),
|
|
2596
|
+
labels: z.string().trim().min(1).optional()
|
|
2597
|
+
}).strict();
|
|
2594
2598
|
var themeConfigSchema = z.object({
|
|
2595
|
-
mode: z.enum(["light", "dark"]).optional(),
|
|
2596
2599
|
colors: colorConfigSchema.optional(),
|
|
2600
|
+
fonts: fontsSchema.optional(),
|
|
2597
2601
|
typography: typographySchema.optional()
|
|
2598
|
-
});
|
|
2602
|
+
}).strict();
|
|
2599
2603
|
var sourceLayersSchema = z.object({
|
|
2600
2604
|
landuse: z.string().optional(),
|
|
2601
2605
|
park: z.string().optional(),
|
|
@@ -2673,7 +2677,10 @@ var tilesetConfigSchema = z.object({
|
|
|
2673
2677
|
sourceLayers: sourceLayersSchema.optional()
|
|
2674
2678
|
});
|
|
2675
2679
|
var projectConfigSchema = z.object({
|
|
2676
|
-
themes: z.
|
|
2680
|
+
themes: z.object({
|
|
2681
|
+
light: themeConfigSchema.optional(),
|
|
2682
|
+
dark: themeConfigSchema.optional()
|
|
2683
|
+
}).strict().optional(),
|
|
2677
2684
|
tilesets: z.record(z.string(), tilesetConfigSchema).optional(),
|
|
2678
2685
|
maps: z.record(z.string(), configSchema).refine((maps) => {
|
|
2679
2686
|
return Object.keys(maps).length > 0;
|
|
@@ -2974,6 +2981,7 @@ function createStyleFromProject(projectConfig, mapName, options = {}) {
|
|
|
2974
2981
|
const resolvedTileset = tilesetConfig?.id ?? tilesetName ?? defaultTileset;
|
|
2975
2982
|
const baseBasemap = config.basemap ?? osm();
|
|
2976
2983
|
const { sourceLayers: tileSourceLayers, ...tileOptions } = config.tiles ?? {};
|
|
2984
|
+
const resolvedBasemapSourceLayers = baseBasemap.sourceLayers || tilesetConfig?.sourceLayers ? resolveSourceLayers(baseBasemap.sourceLayers, tilesetConfig?.sourceLayers) : void 0;
|
|
2977
2985
|
const resolvedTileSourceLayers = baseBasemap.sourceLayers || !tileSourceLayers ? void 0 : resolveSourceLayers(tileSourceLayers, tilesetConfig?.sourceLayers);
|
|
2978
2986
|
return createStyle(
|
|
2979
2987
|
{
|
|
@@ -2983,7 +2991,7 @@ function createStyleFromProject(projectConfig, mapName, options = {}) {
|
|
|
2983
2991
|
...baseBasemap,
|
|
2984
2992
|
tileset: resolvedTileset,
|
|
2985
2993
|
attribution: baseBasemap.attribution ?? tilesetConfig?.attribution,
|
|
2986
|
-
sourceLayers:
|
|
2994
|
+
...resolvedBasemapSourceLayers ? { sourceLayers: resolvedBasemapSourceLayers } : {}
|
|
2987
2995
|
},
|
|
2988
2996
|
tiles: {
|
|
2989
2997
|
...tileOptions,
|
|
@@ -3021,7 +3029,7 @@ function resolveTheme(theme, projectThemes) {
|
|
|
3021
3029
|
return resolveLegacyTheme("light");
|
|
3022
3030
|
}
|
|
3023
3031
|
if (typeof theme === "string") {
|
|
3024
|
-
const projectTheme = projectThemes?.[theme];
|
|
3032
|
+
const projectTheme = isProjectThemeName(theme) ? projectThemes?.[theme] : void 0;
|
|
3025
3033
|
if (projectTheme) {
|
|
3026
3034
|
return resolveThemeConfig(theme, projectTheme);
|
|
3027
3035
|
}
|
|
@@ -3045,22 +3053,32 @@ function resolveLegacyTheme(theme) {
|
|
|
3045
3053
|
}
|
|
3046
3054
|
function resolveThemeConfig(name, theme) {
|
|
3047
3055
|
const colors = normalizeColorAliases(theme.colors);
|
|
3048
|
-
const
|
|
3056
|
+
const themeName = isProjectThemeName(name) ? name : "light";
|
|
3057
|
+
const preset = themePresets[themeName];
|
|
3049
3058
|
return {
|
|
3050
3059
|
colors: {
|
|
3051
3060
|
...preset.colors,
|
|
3052
3061
|
...colors
|
|
3053
3062
|
},
|
|
3054
3063
|
custom: true,
|
|
3055
|
-
mode:
|
|
3064
|
+
mode: themeName,
|
|
3056
3065
|
name,
|
|
3057
3066
|
preset,
|
|
3058
|
-
typography: resolveTypography(theme
|
|
3067
|
+
typography: resolveTypography(resolveThemeTypography(theme), defaultTypography)
|
|
3059
3068
|
};
|
|
3060
3069
|
}
|
|
3061
3070
|
function isLegacyTheme(value) {
|
|
3062
3071
|
return value in themePresets;
|
|
3063
3072
|
}
|
|
3073
|
+
function isProjectThemeName(value) {
|
|
3074
|
+
return value === "light" || value === "dark";
|
|
3075
|
+
}
|
|
3076
|
+
function resolveThemeTypography(theme) {
|
|
3077
|
+
return {
|
|
3078
|
+
...theme.typography,
|
|
3079
|
+
font: theme.typography?.font ?? theme.fonts?.labels ?? theme.fonts?.body
|
|
3080
|
+
};
|
|
3081
|
+
}
|
|
3064
3082
|
function normalizeColorAliases(colors) {
|
|
3065
3083
|
if (!colors) {
|
|
3066
3084
|
return {};
|