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