@tenphi/glaze 0.7.0 → 0.8.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
@@ -194,6 +194,8 @@ A single value applies to both modes. All control is local and explicit.
194
194
  'muted': { base: 'surface', lightness: ['-35', '-50'], contrast: ['AA-large', 'AA'] }
195
195
  ```
196
196
 
197
+ **Full lightness spectrum in HC mode:** In high-contrast variants, the `lightLightness` and `darkLightness` window constraints are bypassed entirely. Colors can reach the full 0–100 lightness range, maximizing perceivable contrast. Normal (non-HC) variants continue to use the configured windows.
198
+
197
199
  ## Theme Color Management
198
200
 
199
201
  ### Adding Colors
@@ -601,7 +603,7 @@ Modes control how colors adapt across schemes:
601
603
 
602
604
  ```ts
603
605
  // Light: surface L=97, text lightness='-52' → L=45 (dark text on light bg)
604
- // Dark: surface inverts to L≈14, sign flips → L=14+52=66
606
+ // Dark: surface inverts to L≈20 (Möbius curve), sign flips → L=20+52=72
605
607
  // contrast solver may push further (light text on dark bg)
606
608
  ```
607
609
 
@@ -625,7 +627,7 @@ const [lo, hi] = lightLightness; // default: [10, 100]
625
627
  const mappedL = (lightness * (hi - lo)) / 100 + lo;
626
628
  ```
627
629
 
628
- Both `auto` and `fixed` modes use the same linear formula. `static` mode bypasses the mapping entirely.
630
+ Both `auto` and `fixed` modes use the same linear formula. `static` mode and high-contrast variants bypass the mapping entirely (identity: `mappedL = l`).
629
631
 
630
632
  | Color | Raw L | Mapped L (default [10, 100]) |
631
633
  |---|---|---|
@@ -637,24 +639,29 @@ Both `auto` and `fixed` modes use the same linear formula. `static` mode bypasse
637
639
 
638
640
  ### Lightness
639
641
 
640
- **`auto`** — inverted within the configured window:
642
+ **`auto`** — inverted with a Möbius transformation within the configured window:
641
643
 
642
644
  ```ts
643
645
  const [lo, hi] = darkLightness; // default: [15, 95]
644
- const invertedL = ((100 - lightness) * (hi - lo)) / 100 + lo;
646
+ const t = (100 - lightness) / 100;
647
+ const invertedL = lo + (hi - lo) * t / (t + darkCurve * (1 - t)); // darkCurve default: 0.5
645
648
  ```
646
649
 
647
- **`fixed`**mapped without inversion:
650
+ The `darkCurve` parameter (default `0.5`, range 0–1) controls how much the dark-mode inversion expands lightness deltas. Lower values produce stronger expansion; `1` gives linear (legacy) behavior. Unlike a power curve, the Möbius transformation provides **proportional expansion** small and large deltas are scaled by similar ratios, preserving the visual hierarchy of the light theme.
651
+
652
+ **`fixed`** — mapped without inversion (not affected by `darkCurve`):
648
653
 
649
654
  ```ts
650
655
  const mappedL = (lightness * (hi - lo)) / 100 + lo;
651
656
  ```
652
657
 
653
- | Color | Light L | Auto (inverted) | Fixed (mapped) |
654
- |---|---|---|---|
655
- | surface (L=97) | 97 | 17.4 | 92.6 |
656
- | accent-fill (L=52) | 52 | 53.4 | 56.6 |
657
- | accent-text (L=100) | 100 | 15 | 95 |
658
+ | Color | Light L | Auto (curve=0.5) | Auto (curve=1, linear) | Fixed (mapped) |
659
+ |---|---|---|---|---|
660
+ | surface (L=97) | 97 | 19.7 | 17.4 | 92.6 |
661
+ | accent-fill (L=52) | 52 | 66.9 | 53.4 | 56.6 |
662
+ | accent-text (L=100) | 100 | 15 | 15 | 95 |
663
+
664
+ In high-contrast variants, the `darkLightness` window is bypassed. Auto uses the same Möbius curve over the full [0, 100] range. Fixed uses identity (`L`). This allows HC colors to reach the full 0–100 range.
658
665
 
659
666
  ### Saturation
660
667
 
@@ -904,9 +911,10 @@ Resolution priority (highest first):
904
911
 
905
912
  ```ts
906
913
  glaze.configure({
907
- lightLightness: [10, 100], // Light scheme lightness window [lo, hi]
908
- darkLightness: [15, 95], // Dark scheme lightness window [lo, hi]
914
+ lightLightness: [10, 100], // Light scheme lightness window [lo, hi] (bypassed in HC)
915
+ darkLightness: [15, 95], // Dark scheme lightness window [lo, hi] (bypassed in HC)
909
916
  darkDesaturation: 0.1, // Saturation reduction in dark scheme (0–1)
917
+ darkCurve: 0.5, // Möbius beta for dark auto-inversion (0–1, lower = more expansion)
910
918
  states: {
911
919
  dark: '@dark', // State alias for dark mode tokens
912
920
  highContrast: '@high-contrast',
package/dist/index.cjs CHANGED
@@ -814,6 +814,7 @@ let globalConfig = {
814
814
  lightLightness: [10, 100],
815
815
  darkLightness: [15, 95],
816
816
  darkDesaturation: .1,
817
+ darkCurve: .5,
817
818
  states: {
818
819
  dark: "@dark",
819
820
  highContrast: "@high-contrast"
@@ -961,23 +962,42 @@ function topoSort(defs) {
961
962
  for (const name of Object.keys(defs)) visit(name);
962
963
  return result;
963
964
  }
964
- function mapLightnessLight(l, mode) {
965
- if (mode === "static") return l;
965
+ function mapLightnessLight(l, mode, isHighContrast) {
966
+ if (mode === "static" || isHighContrast) return l;
966
967
  const [lo, hi] = globalConfig.lightLightness;
967
968
  return l * (hi - lo) / 100 + lo;
968
969
  }
969
- function mapLightnessDark(l, mode) {
970
+ function mobiusCurve(t, beta) {
971
+ if (beta >= 1) return t;
972
+ return t / (t + beta * (1 - t));
973
+ }
974
+ function mapLightnessDark(l, mode, isHighContrast) {
970
975
  if (mode === "static") return l;
971
- const [lo, hi] = globalConfig.darkLightness;
972
- if (mode === "fixed") return l * (hi - lo) / 100 + lo;
973
- return (100 - l) * (hi - lo) / 100 + lo;
976
+ const beta = globalConfig.darkCurve;
977
+ if (isHighContrast) {
978
+ if (mode === "fixed") return l;
979
+ return 100 * mobiusCurve((100 - l) / 100, beta);
980
+ }
981
+ const [darkLo, darkHi] = globalConfig.darkLightness;
982
+ if (mode === "fixed") return l * (darkHi - darkLo) / 100 + darkLo;
983
+ const [lightLo, lightHi] = globalConfig.lightLightness;
984
+ const t = (lightHi - (l * (lightHi - lightLo) / 100 + lightLo)) / (lightHi - lightLo);
985
+ return darkLo + (darkHi - darkLo) * mobiusCurve(t, beta);
986
+ }
987
+ function lightMappedToDark(lightL, isHighContrast) {
988
+ const beta = globalConfig.darkCurve;
989
+ if (isHighContrast) return 100 * mobiusCurve((100 - lightL) / 100, beta);
990
+ const [lightLo, lightHi] = globalConfig.lightLightness;
991
+ const [darkLo, darkHi] = globalConfig.darkLightness;
992
+ const t = (lightHi - clamp(lightL, lightLo, lightHi)) / (lightHi - lightLo);
993
+ return darkLo + (darkHi - darkLo) * mobiusCurve(t, beta);
974
994
  }
975
995
  function mapSaturationDark(s, mode) {
976
996
  if (mode === "static") return s;
977
997
  return s * (1 - globalConfig.darkDesaturation);
978
998
  }
979
- function schemeLightnessRange(isDark, mode) {
980
- if (mode === "static") return [0, 1];
999
+ function schemeLightnessRange(isDark, mode, isHighContrast) {
1000
+ if (mode === "static" || isHighContrast) return [0, 1];
981
1001
  const [lo, hi] = isDark ? globalConfig.darkLightness : globalConfig.lightLightness;
982
1002
  return [lo / 100, hi / 100];
983
1003
  }
@@ -1037,26 +1057,26 @@ function resolveDependentColor(name, def, ctx, isHighContrast, isDark, effective
1037
1057
  else {
1038
1058
  const parsed = parseRelativeOrAbsolute(isHighContrast ? pairHC(rawLightness) : pairNormal(rawLightness));
1039
1059
  if (parsed.relative) {
1040
- let delta = parsed.value;
1041
- if (isDark && mode === "auto") delta = -delta;
1042
- preferredL = clamp(baseL + delta, 0, 100);
1043
- } else if (isDark) preferredL = mapLightnessDark(parsed.value, mode);
1044
- else preferredL = mapLightnessLight(parsed.value, mode);
1060
+ const delta = parsed.value;
1061
+ if (isDark && mode === "auto") preferredL = lightMappedToDark(clamp(getSchemeVariant(baseResolved, false, isHighContrast).l * 100 + delta, 0, 100), isHighContrast);
1062
+ else preferredL = clamp(baseL + delta, 0, 100);
1063
+ } else if (isDark) preferredL = mapLightnessDark(parsed.value, mode, isHighContrast);
1064
+ else preferredL = mapLightnessLight(parsed.value, mode, isHighContrast);
1045
1065
  }
1046
1066
  const rawContrast = def.contrast;
1047
1067
  if (rawContrast !== void 0) {
1048
1068
  const minCr = isHighContrast ? pairHC(rawContrast) : pairNormal(rawContrast);
1049
1069
  const effectiveSat = isDark ? mapSaturationDark(satFactor * ctx.saturation / 100, mode) : satFactor * ctx.saturation / 100;
1050
1070
  const baseLinearRgb = okhslToLinearSrgb(baseVariant.h, baseVariant.s, baseVariant.l);
1051
- const lightnessRange = schemeLightnessRange(isDark, mode);
1071
+ const windowRange = schemeLightnessRange(isDark, mode, isHighContrast);
1052
1072
  return {
1053
1073
  l: findLightnessForContrast({
1054
1074
  hue: effectiveHue,
1055
1075
  saturation: effectiveSat,
1056
- preferredLightness: clamp(preferredL / 100, lightnessRange[0], lightnessRange[1]),
1076
+ preferredLightness: clamp(preferredL / 100, windowRange[0], windowRange[1]),
1057
1077
  baseLinearRgb,
1058
1078
  contrast: minCr,
1059
- lightnessRange
1079
+ lightnessRange: [0, 1]
1060
1080
  }).lightness * 100,
1061
1081
  satFactor
1062
1082
  };
@@ -1093,13 +1113,13 @@ function resolveColorForScheme(name, def, ctx, isDark, isHighContrast) {
1093
1113
  let finalL;
1094
1114
  let finalSat;
1095
1115
  if (isDark && isRoot) {
1096
- finalL = mapLightnessDark(lightL, mode);
1116
+ finalL = mapLightnessDark(lightL, mode, isHighContrast);
1097
1117
  finalSat = mapSaturationDark(satFactor * ctx.saturation / 100, mode);
1098
1118
  } else if (isDark && !isRoot) {
1099
1119
  finalL = lightL;
1100
1120
  finalSat = mapSaturationDark(satFactor * ctx.saturation / 100, mode);
1101
1121
  } else if (isRoot) {
1102
- finalL = mapLightnessLight(lightL, mode);
1122
+ finalL = mapLightnessLight(lightL, mode, isHighContrast);
1103
1123
  finalSat = satFactor * ctx.saturation / 100;
1104
1124
  } else {
1105
1125
  finalL = lightL;
@@ -1565,6 +1585,7 @@ glaze.configure = function configure(config) {
1565
1585
  lightLightness: config.lightLightness ?? globalConfig.lightLightness,
1566
1586
  darkLightness: config.darkLightness ?? globalConfig.darkLightness,
1567
1587
  darkDesaturation: config.darkDesaturation ?? globalConfig.darkDesaturation,
1588
+ darkCurve: config.darkCurve ?? globalConfig.darkCurve,
1568
1589
  states: {
1569
1590
  dark: config.states?.dark ?? globalConfig.states.dark,
1570
1591
  highContrast: config.states?.highContrast ?? globalConfig.states.highContrast
@@ -1664,6 +1685,7 @@ glaze.resetConfig = function resetConfig() {
1664
1685
  lightLightness: [10, 100],
1665
1686
  darkLightness: [15, 95],
1666
1687
  darkDesaturation: .1,
1688
+ darkCurve: .5,
1667
1689
  states: {
1668
1690
  dark: "@dark",
1669
1691
  highContrast: "@high-contrast"