@tileflow/core 0.1.0-alpha.28 → 0.1.0-alpha.29

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/build.js CHANGED
@@ -1,6 +1,50 @@
1
1
  // src/cartography/streets.ts
2
2
  import { validateStyleMin } from "@maplibre/maplibre-gl-style-spec";
3
3
 
4
+ // src/atmosphere.ts
5
+ var tileflowAtmosphereMetadataKey = "tileflow:atmosphere";
6
+
7
+ // src/atmosphere-compile.ts
8
+ import { Color } from "@maplibre/maplibre-gl-style-spec";
9
+ var defaults = {
10
+ skyColor: "#07152b",
11
+ horizonColor: "#83b9f4",
12
+ fogColor: "#bad2eb",
13
+ spaceColor: "#030916",
14
+ starIntensity: 0.6,
15
+ starParallax: 0.4
16
+ };
17
+ function resolveTileflowAtmosphere(value) {
18
+ if (!value) return void 0;
19
+ const options = { ...defaults, ...value === true ? {} : value };
20
+ const normalize = (input) => {
21
+ const color2 = typeof input === "string" ? Color.parse(input) : void 0;
22
+ if (!color2 || color2.a !== 1)
23
+ throw new Error("Atmosphere colors must resolve to opaque colors.");
24
+ return `#${[color2.r, color2.g, color2.b].map(
25
+ (channel) => Math.round(channel * 255).toString(16).padStart(2, "0")
26
+ ).join("")}`;
27
+ };
28
+ return {
29
+ ...options,
30
+ skyColor: normalize(options.skyColor),
31
+ horizonColor: normalize(options.horizonColor),
32
+ fogColor: normalize(options.fogColor),
33
+ spaceColor: normalize(options.spaceColor)
34
+ };
35
+ }
36
+ function compileTileflowSky(options) {
37
+ return {
38
+ "sky-color": options.skyColor,
39
+ "horizon-color": options.horizonColor,
40
+ "fog-color": options.fogColor,
41
+ "sky-horizon-blend": 0.12,
42
+ "horizon-fog-blend": 0.5,
43
+ "fog-ground-blend": 0.1,
44
+ "atmosphere-blend": ["interpolate", ["linear"], ["zoom"], 0, 0.55, 3, 0.45, 5, 0.2, 7, 0]
45
+ };
46
+ }
47
+
4
48
  // src/data/world-generation.ts
5
49
  var tileflowWorldGeneration = "v1";
6
50
 
@@ -1967,7 +2011,7 @@ function tileflowRoadClassFilter(fields, roadClass) {
1967
2011
  }
1968
2012
 
1969
2013
  // src/modules/roads/index.ts
1970
- var defaults = {
2014
+ var defaults2 = {
1971
2015
  detail: "streets",
1972
2016
  disabledClasses: [],
1973
2017
  enabled: true,
@@ -2024,15 +2068,15 @@ function roads(options = {}) {
2024
2068
  }
2025
2069
  function resolveRoads(request) {
2026
2070
  return {
2027
- detail: request?.detail ?? defaults.detail,
2071
+ detail: request?.detail ?? defaults2.detail,
2028
2072
  disabledClasses: Object.entries(request?.classes ?? {}).filter(([, style]) => style?.enabled === false).map(([roadClass]) => roadClass),
2029
- enabled: request?.enabled ?? defaults.enabled,
2073
+ enabled: request?.enabled ?? defaults2.enabled,
2030
2074
  explicitClasses: Object.entries(request?.classes ?? {}).filter(([, style]) => style?.enabled !== false).map(([roadClass]) => roadClass),
2031
- extras: { paths: request?.extras?.paths ?? defaults.extras.paths },
2032
- hierarchy: request?.hierarchy ?? defaults.hierarchy,
2033
- oneWayMarkers: request?.oneWayMarkers ?? defaults.oneWayMarkers,
2034
- outline: request?.outline ?? defaults.outline,
2035
- weight: request?.weight ?? defaults.weight,
2075
+ extras: { paths: request?.extras?.paths ?? defaults2.extras.paths },
2076
+ hierarchy: request?.hierarchy ?? defaults2.hierarchy,
2077
+ oneWayMarkers: request?.oneWayMarkers ?? defaults2.oneWayMarkers,
2078
+ outline: request?.outline ?? defaults2.outline,
2079
+ weight: request?.weight ?? defaults2.weight,
2036
2080
  ...request?.widthScale ? {
2037
2081
  widthScale: {
2038
2082
  ...defaultRoadWidthScale,
@@ -2073,7 +2117,7 @@ function cloneJson8(value) {
2073
2117
  }
2074
2118
 
2075
2119
  // src/modules/labels/index.ts
2076
- var defaults2 = {
2120
+ var defaults3 = {
2077
2121
  aerodromeCodes: "iata",
2078
2122
  collisionPriority: "balanced",
2079
2123
  language: "auto",
@@ -2088,15 +2132,15 @@ function labels(options = {}) {
2088
2132
  }
2089
2133
  function resolveLabels(request) {
2090
2134
  return {
2091
- aerodromeCodes: request?.aerodromeCodes ?? defaults2.aerodromeCodes,
2092
- collisionPriority: request?.collisionPriority ?? defaults2.collisionPriority,
2093
- language: request?.language ?? defaults2.language,
2094
- junctions: request?.junctions ?? defaults2.junctions,
2095
- places: request?.places ?? defaults2.places,
2135
+ aerodromeCodes: request?.aerodromeCodes ?? defaults3.aerodromeCodes,
2136
+ collisionPriority: request?.collisionPriority ?? defaults3.collisionPriority,
2137
+ language: request?.language ?? defaults3.language,
2138
+ junctions: request?.junctions ?? defaults3.junctions,
2139
+ places: request?.places ?? defaults3.places,
2096
2140
  ...request?.roadClasses ? { roadClasses: [...request.roadClasses] } : {},
2097
- roads: request?.roads ?? defaults2.roads,
2098
- shields: request?.shields ?? defaults2.shields,
2099
- water: request?.water ?? defaults2.water
2141
+ roads: request?.roads ?? defaults3.roads,
2142
+ shields: request?.shields ?? defaults3.shields,
2143
+ water: request?.water ?? defaults3.water
2100
2144
  };
2101
2145
  }
2102
2146
  function visibleRoadLabelClasses(detail, roads2, explicitClasses) {
@@ -2163,7 +2207,7 @@ function compileLabels(request, roadRequest, context) {
2163
2207
  const { colors } = context;
2164
2208
  const rankField = context.data.schema.fields.rank;
2165
2209
  const capitalField = context.data.schema.fields.capital;
2166
- const defaults3 = {
2210
+ const defaults4 = {
2167
2211
  places: {
2168
2212
  continent: symbolStyle(context, "places", {
2169
2213
  minZoom: 0,
@@ -2312,7 +2356,7 @@ function compileLabels(request, roadRequest, context) {
2312
2356
  })
2313
2357
  };
2314
2358
  const styles = mergeTileflowDesign(
2315
- defaults3,
2359
+ defaults4,
2316
2360
  request?.styles
2317
2361
  );
2318
2362
  const result = [];
@@ -3779,7 +3823,7 @@ function compilePoi(request, context, language = "auto") {
3779
3823
  const categoryDensity = requestedCategoryStyle?.density ?? semantics.density;
3780
3824
  const { density: _density, ...categoryStyle } = requestedCategoryStyle ?? {};
3781
3825
  const categoryColor = semantics.color === "category" ? context.colors.poi[category] ?? context.colors.poi.label : context.colors.poi.label;
3782
- const defaults3 = {
3826
+ const defaults4 = {
3783
3827
  icon: {
3784
3828
  optional: !semantics.placement.coupleIconAndLabel,
3785
3829
  padding: semantics.placement.iconPadding,
@@ -3798,7 +3842,7 @@ function compilePoi(request, context, language = "auto") {
3798
3842
  ]) : 12
3799
3843
  })
3800
3844
  };
3801
- let style = mergeTileflowDesign(defaults3, categoryStyle);
3845
+ let style = mergeTileflowDesign(defaults4, categoryStyle);
3802
3846
  const markerStyle = style.marker ? resolveMarkerStyle(style) : void 0;
3803
3847
  const showText = semantics.labels && style.text.visible !== false;
3804
3848
  const showIcon = semantics.icons && style.icon.visible !== false;
@@ -4700,12 +4744,12 @@ var ThemeValueResolver = class {
4700
4744
  }
4701
4745
  return result;
4702
4746
  }
4703
- #resolveTypographyStyle(style, path, defaults3) {
4747
+ #resolveTypographyStyle(style, path, defaults4) {
4704
4748
  const resolved = this.resolveTree(style ?? {}, path);
4705
- const font = resolved.font ?? defaults3.font;
4749
+ const font = resolved.font ?? defaults4.font;
4706
4750
  if (typeof font !== "string" || !font) throw themeTypeError(`${path}.font`, "font", font);
4707
4751
  assertFontName(font, `${path}.font`);
4708
- const fallbacks = resolved.fallbacks ?? defaults3.fallbacks;
4752
+ const fallbacks = resolved.fallbacks ?? defaults4.fallbacks;
4709
4753
  if (fallbacks !== void 0 && (!Array.isArray(fallbacks) || fallbacks.some((entry) => typeof entry !== "string" || !entry))) {
4710
4754
  throw themeTypeError(`${path}.fallbacks`, "font array", fallbacks);
4711
4755
  }
@@ -4721,9 +4765,9 @@ var ThemeValueResolver = class {
4721
4765
  seen.add(fallback);
4722
4766
  }
4723
4767
  }
4724
- const letterSpacing = resolved.letterSpacing ?? defaults3.letterSpacing;
4768
+ const letterSpacing = resolved.letterSpacing ?? defaults4.letterSpacing;
4725
4769
  if (letterSpacing !== void 0) assertFiniteNumber(letterSpacing, `${path}.letterSpacing`);
4726
- const transform = resolved.transform ?? defaults3.transform;
4770
+ const transform = resolved.transform ?? defaults4.transform;
4727
4771
  if (transform !== void 0 && !["lowercase", "none", "uppercase"].includes(String(transform))) {
4728
4772
  throw themeTypeError(`${path}.transform`, "text transform", transform);
4729
4773
  }
@@ -5254,8 +5298,8 @@ var defaultColors = {
5254
5298
  textMuted: "#727B84",
5255
5299
  textHalo: "#FFFFFF"
5256
5300
  };
5257
- function resolveColors(overrides = {}, defaults3 = defaultColors, moduleOverrides = {}, moduleDefaults = {}) {
5258
- const defaultInput = defaults3;
5301
+ function resolveColors(overrides = {}, defaults4 = defaultColors, moduleOverrides = {}, moduleDefaults = {}) {
5302
+ const defaultInput = defaults4;
5259
5303
  const overrideInput = overrides;
5260
5304
  const defaultModules = moduleDefaults;
5261
5305
  const overrideModules = moduleOverrides;
@@ -5603,32 +5647,32 @@ function textFont(typography, domain) {
5603
5647
  const style = domain ? typography[domain] : typography;
5604
5648
  return [style.font, ...style.fallbacks ?? []];
5605
5649
  }
5606
- function resolveBaseColors(overrides, defaults3) {
5607
- const background = overrides.background ?? defaults3.background ?? defaultColors.background;
5608
- const land2 = overrides.land ?? defaults3.land ?? defaultColors.land;
5609
- const water2 = overrides.water ?? defaults3.water ?? defaultColors.water;
5610
- const park = overrides.park ?? defaults3.park ?? defaultColors.park;
5611
- const road = overrides.road ?? defaults3.road ?? defaultColors.road;
5612
- const text = overrides.text ?? defaults3.text ?? defaultColors.text;
5613
- const textMuted = overrides.textMuted ?? defaults3.textMuted ?? mix(text, background, 0.42);
5614
- const textHalo = overrides.textHalo ?? defaults3.textHalo ?? background;
5650
+ function resolveBaseColors(overrides, defaults4) {
5651
+ const background = overrides.background ?? defaults4.background ?? defaultColors.background;
5652
+ const land2 = overrides.land ?? defaults4.land ?? defaultColors.land;
5653
+ const water2 = overrides.water ?? defaults4.water ?? defaultColors.water;
5654
+ const park = overrides.park ?? defaults4.park ?? defaultColors.park;
5655
+ const road = overrides.road ?? defaults4.road ?? defaultColors.road;
5656
+ const text = overrides.text ?? defaults4.text ?? defaultColors.text;
5657
+ const textMuted = overrides.textMuted ?? defaults4.textMuted ?? mix(text, background, 0.42);
5658
+ const textHalo = overrides.textHalo ?? defaults4.textHalo ?? background;
5615
5659
  return {
5616
5660
  background,
5617
- boundary: overrides.boundary ?? defaults3.boundary ?? mix(text, background, 0.72),
5618
- building: overrides.building ?? defaults3.building ?? mix(land2, text, 0.08),
5661
+ boundary: overrides.boundary ?? defaults4.boundary ?? mix(text, background, 0.72),
5662
+ building: overrides.building ?? defaults4.building ?? mix(land2, text, 0.08),
5619
5663
  land: land2,
5620
5664
  park,
5621
5665
  road,
5622
- roadMajor: overrides.roadMajor ?? defaults3.roadMajor ?? mix(road, textMuted, 0.16),
5666
+ roadMajor: overrides.roadMajor ?? defaults4.roadMajor ?? mix(road, textMuted, 0.16),
5623
5667
  text,
5624
5668
  textHalo,
5625
5669
  textMuted,
5626
5670
  water: water2
5627
5671
  };
5628
5672
  }
5629
- function resolveGroup(defaults3, themeDefaults, overrides) {
5673
+ function resolveGroup(defaults4, themeDefaults, overrides) {
5630
5674
  return {
5631
- ...defaults3,
5675
+ ...defaults4,
5632
5676
  ...themeDefaults,
5633
5677
  ...overrides
5634
5678
  };
@@ -5752,13 +5796,13 @@ function compileRoads(request, context) {
5752
5796
  const semantics = resolveRoads(request);
5753
5797
  const visible = new Set(visibleRoadClasses(semantics));
5754
5798
  const metrics = roadStyleMetrics(semantics);
5755
- const defaults3 = defaultClassStyles(context, metrics, semantics);
5799
+ const defaults4 = defaultClassStyles(context, metrics, semantics);
5756
5800
  const contributions = [];
5757
5801
  const { sourceId: source, schema } = context.data;
5758
5802
  for (const [classIndex, roadClass] of roadClassOrder.entries()) {
5759
5803
  if (!visible.has(roadClass) || request?.classes?.[roadClass]?.enabled === false) continue;
5760
5804
  const classConfig = mergeTileflowDesign(
5761
- defaults3[roadClass],
5805
+ defaults4[roadClass],
5762
5806
  Object.fromEntries(
5763
5807
  ["tunnel", "surface", "bridge"].map((structure) => [
5764
5808
  structure,
@@ -8068,6 +8112,7 @@ function isPlainRecord2(value) {
8068
8112
  }
8069
8113
 
8070
8114
  // src/resolved-map-schema.ts
8115
+ import { Color as Color2 } from "@maplibre/maplibre-gl-style-spec";
8071
8116
  import { z as z5 } from "zod";
8072
8117
 
8073
8118
  // src/cartography/data-expression.ts
@@ -11598,6 +11643,24 @@ var terrainSchema = z5.union([
11598
11643
  url: z5.string().trim().min(1).optional()
11599
11644
  }).strict()
11600
11645
  ]);
11646
+ var atmosphereColorLiteralSchema = z5.string().refine((value) => Color2.parse(value)?.a === 1, "Expected an opaque color");
11647
+ var atmosphereColorSchema = z5.union([
11648
+ atmosphereColorLiteralSchema,
11649
+ fixedStringSchema.extend({ value: atmosphereColorLiteralSchema }),
11650
+ themeTokenReferenceSchema.extend({ category: z5.literal("color") }),
11651
+ themeColorOperationSchema
11652
+ ]);
11653
+ var atmosphereSchema = z5.union([
11654
+ z5.boolean(),
11655
+ z5.object({
11656
+ skyColor: atmosphereColorSchema.optional(),
11657
+ horizonColor: atmosphereColorSchema.optional(),
11658
+ fogColor: atmosphereColorSchema.optional(),
11659
+ spaceColor: atmosphereColorSchema.optional(),
11660
+ starIntensity: z5.number().finite().min(0).max(1).optional(),
11661
+ starParallax: z5.number().finite().min(0).max(1).optional()
11662
+ }).strict()
11663
+ ]);
11601
11664
  var viewSchema = z5.object({
11602
11665
  bearing: z5.number().finite().min(-180).max(180).optional(),
11603
11666
  center: z5.tuple([z5.number().finite().min(-180).max(180), z5.number().finite().min(-90).max(90)]).optional(),
@@ -11630,6 +11693,7 @@ var themesSchema = z5.record(tileflowThemeNameSchema, tileflowThemeSchema).super
11630
11693
  }).describe("tileflow-themes");
11631
11694
  var systemThemesSchema = z5.object({ dark: tileflowThemeNameSchema, light: tileflowThemeNameSchema }).strict();
11632
11695
  var resolvedTileflowMapSchema = z5.object({
11696
+ atmosphere: atmosphereSchema.optional(),
11633
11697
  data: dataSchema.optional(),
11634
11698
  defaultTheme: tileflowThemeNameSchema,
11635
11699
  fonts: fontDirectoriesSchema.optional(),
@@ -11655,6 +11719,13 @@ var resolvedTileflowMapSchema = z5.object({
11655
11719
  path: ["fonts"]
11656
11720
  });
11657
11721
  }
11722
+ if (map.atmosphere && map.projection !== "globe") {
11723
+ context.addIssue({
11724
+ code: "custom",
11725
+ message: "Atmosphere requires globe projection",
11726
+ path: ["atmosphere"]
11727
+ });
11728
+ }
11658
11729
  if (!Object.hasOwn(map.themes, map.defaultTheme)) {
11659
11730
  context.addIssue({
11660
11731
  code: "custom",
@@ -12095,7 +12166,7 @@ function cloneJson22(value) {
12095
12166
  }
12096
12167
 
12097
12168
  // src/icon-appearance.ts
12098
- import { Color } from "@maplibre/maplibre-gl-style-spec";
12169
+ import { Color as Color3 } from "@maplibre/maplibre-gl-style-spec";
12099
12170
  import { z as z7 } from "zod";
12100
12171
 
12101
12172
  // src/icon-layout.ts
@@ -12153,7 +12224,7 @@ function assertTileflowIconLayoutBounds(layout, width, height) {
12153
12224
  }
12154
12225
 
12155
12226
  // src/icon-appearance.ts
12156
- var color = z7.string().max(128).refine((value) => Color.parse(value) !== void 0, "Expected a MapLibre color");
12227
+ var color = z7.string().max(128).refine((value) => Color3.parse(value) !== void 0, "Expected a MapLibre color");
12157
12228
  var tileflowIconAppearanceSchema = z7.object({
12158
12229
  representation: z7.literal("sdf"),
12159
12230
  defaults: z7.object({
@@ -13634,7 +13705,9 @@ function compileSemanticStyleInternal(input, options, inspect, onReport) {
13634
13705
  layers
13635
13706
  })
13636
13707
  );
13708
+ const atmosphere = resolveTileflowAtmosphere(config.atmosphere);
13637
13709
  const style = {
13710
+ ...atmosphere ? { sky: compileTileflowSky(atmosphere) } : {},
13638
13711
  version: 8,
13639
13712
  name: config.name ?? "Streets",
13640
13713
  ...glyphs ? { glyphs } : {},
@@ -13652,6 +13725,7 @@ function compileSemanticStyleInternal(input, options, inspect, onReport) {
13652
13725
  "tileflow:compilerVersion": tileflowSemanticCompilerIdentity.version,
13653
13726
  ...mapMetadata.lineage && mapMetadata.lineage.length > 1 ? { "tileflow:extends": mapMetadata.lineage.slice(1) } : {}
13654
13727
  } : {},
13728
+ ...atmosphere ? { [tileflowAtmosphereMetadataKey]: { version: 1, ...atmosphere } } : {},
13655
13729
  "tileflow:theme": selected.name,
13656
13730
  "tileflow:colorScheme": resolvedTheme.colorScheme,
13657
13731
  "tileflow:data": data.identity,
@@ -14341,6 +14415,7 @@ var TileflowMapResolutionError = class extends Error {
14341
14415
  }
14342
14416
  };
14343
14417
  var tileflowMapMergeStrategies = {
14418
+ atmosphere: "atomic",
14344
14419
  data: "atomic",
14345
14420
  defaultTheme: "atomic",
14346
14421
  extends: "lineage",