@tenphi/glaze 0.6.1 → 0.6.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/README.md CHANGED
@@ -618,7 +618,7 @@ Modes control how colors adapt across schemes:
618
618
 
619
619
  ### Lightness
620
620
 
621
- Root color lightness is mapped linearly within the configured `lightLightness` window:
621
+ Absolute lightness values (both root colors and dependent colors with absolute lightness) are mapped linearly within the configured `lightLightness` window:
622
622
 
623
623
  ```ts
624
624
  const [lo, hi] = lightLightness; // default: [10, 100]
package/dist/index.cjs CHANGED
@@ -433,12 +433,13 @@ function formatOkhsl(h, s, l) {
433
433
  return `okhsl(${fmt$1(h, 2)} ${fmt$1(s, 2)}% ${fmt$1(l, 2)}%)`;
434
434
  }
435
435
  /**
436
- * Format OKHSL values as a CSS `rgb(R G B)` string with rounded integer values.
436
+ * Format OKHSL values as a CSS `rgb(R G B)` string.
437
+ * Uses 2 decimal places to avoid 8-bit quantization contrast loss.
437
438
  * h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
438
439
  */
439
440
  function formatRgb(h, s, l) {
440
441
  const [r, g, b] = okhslToSrgb(h, s / 100, l / 100);
441
- return `rgb(${Math.round(r * 255)} ${Math.round(g * 255)} ${Math.round(b * 255)})`;
442
+ return `rgb(${parseFloat((r * 255).toFixed(2))} ${parseFloat((g * 255).toFixed(2))} ${parseFloat((b * 255).toFixed(2))})`;
442
443
  }
443
444
  /**
444
445
  * Format OKHSL values as a CSS `hsl(H S% L%)` string.
@@ -619,7 +620,7 @@ function coarseScan(h, s, lo, hi, yBase, target, epsilon, maxIter) {
619
620
  function findLightnessForContrast(options) {
620
621
  const { hue, saturation, preferredLightness, baseLinearRgb, contrast: contrastInput, lightnessRange = [0, 1], epsilon = 1e-4, maxIterations = 14 } = options;
621
622
  const target = resolveMinContrast(contrastInput);
622
- const searchTarget = target + .02;
623
+ const searchTarget = target * 1.005;
623
624
  const yBase = gamutClampedLuminance(baseLinearRgb);
624
625
  const crPref = contrastRatioFromLuminance(cachedLuminance(hue, saturation, preferredLightness), yBase);
625
626
  if (crPref >= searchTarget) return {
@@ -743,7 +744,7 @@ function searchMixBranch(lo, hi, yBase, target, epsilon, maxIter, preferred, lum
743
744
  function findValueForMixContrast(options) {
744
745
  const { preferredValue, baseLinearRgb, contrast: contrastInput, luminanceAtValue, epsilon = 1e-4, maxIterations = 20 } = options;
745
746
  const target = resolveMinContrast(contrastInput);
746
- const searchTarget = target + .02;
747
+ const searchTarget = target * 1.005;
747
748
  const yBase = gamutClampedLuminance(baseLinearRgb);
748
749
  const crPref = contrastRatioFromLuminance(luminanceAtValue(preferredValue), yBase);
749
750
  if (crPref >= searchTarget) return {
@@ -975,6 +976,11 @@ function mapSaturationDark(s, mode) {
975
976
  if (mode === "static") return s;
976
977
  return s * (1 - globalConfig.darkDesaturation);
977
978
  }
979
+ function schemeLightnessRange(isDark, mode) {
980
+ if (mode === "static") return [0, 1];
981
+ const [lo, hi] = isDark ? globalConfig.darkLightness : globalConfig.lightLightness;
982
+ return [lo / 100, hi / 100];
983
+ }
978
984
  function clamp(v, min, max) {
979
985
  return Math.max(min, Math.min(max, v));
980
986
  }
@@ -1035,20 +1041,22 @@ function resolveDependentColor(name, def, ctx, isHighContrast, isDark, effective
1035
1041
  if (isDark && mode === "auto") delta = -delta;
1036
1042
  preferredL = clamp(baseL + delta, 0, 100);
1037
1043
  } else if (isDark) preferredL = mapLightnessDark(parsed.value, mode);
1038
- else preferredL = clamp(parsed.value, 0, 100);
1044
+ else preferredL = mapLightnessLight(parsed.value, mode);
1039
1045
  }
1040
1046
  const rawContrast = def.contrast;
1041
1047
  if (rawContrast !== void 0) {
1042
1048
  const minCr = isHighContrast ? pairHC(rawContrast) : pairNormal(rawContrast);
1043
1049
  const effectiveSat = isDark ? mapSaturationDark(satFactor * ctx.saturation / 100, mode) : satFactor * ctx.saturation / 100;
1044
1050
  const baseLinearRgb = okhslToLinearSrgb(baseVariant.h, baseVariant.s, baseVariant.l);
1051
+ const lightnessRange = schemeLightnessRange(isDark, mode);
1045
1052
  return {
1046
1053
  l: findLightnessForContrast({
1047
1054
  hue: effectiveHue,
1048
1055
  saturation: effectiveSat,
1049
- preferredLightness: preferredL / 100,
1056
+ preferredLightness: clamp(preferredL / 100, lightnessRange[0], lightnessRange[1]),
1050
1057
  baseLinearRgb,
1051
- contrast: minCr
1058
+ contrast: minCr,
1059
+ lightnessRange
1052
1060
  }).lightness * 100,
1053
1061
  satFactor
1054
1062
  };