@tenphi/glaze 1.5.0 → 2.0.1

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.cts CHANGED
@@ -1698,7 +1698,11 @@ declare function okhslToOkhst(c: {
1698
1698
  };
1699
1699
  /**
1700
1700
  * Edge adapter: a resolved variant stores canonical tone `t` (0–1). Convert
1701
- * it to the OKHSL `{ h, s, l }` the formatters and luminance pipeline expect.
1701
+ * it to the OKHSL `{ h, s, l }` the formatters and luminance pipeline expect —
1702
+ * `s` and `l` on the same 0–1 factor scale, so `const { h, s, l } =
1703
+ * variantToOkhsl(v)` destructures straight into `formatOkhsl` / `formatRgb` /
1704
+ * `okhslToLinearSrgb` with no rescaling. `alpha` stays on the variant; use
1705
+ * `glaze.format(v, format)` for a string that carries it.
1702
1706
  */
1703
1707
  declare function variantToOkhsl(v: {
1704
1708
  h: number;
@@ -1753,6 +1757,7 @@ declare function relativeLuminanceFromLinearRgb(rgb: [number, number, number]):
1753
1757
  declare function contrastRatioFromLuminance(yA: number, yB: number): number;
1754
1758
  /**
1755
1759
  * Convert OKHSL to gamma-encoded sRGB (clamped to 0–1).
1760
+ * h: 0–360, s: 0–1, l: 0–1. Returns [r, g, b] with each channel 0–1.
1756
1761
  */
1757
1762
  declare function okhslToSrgb(h: number, s: number, l: number, pastel?: boolean): [number, number, number];
1758
1763
  /**
@@ -1799,12 +1804,12 @@ declare function parseHexAlpha(hex: string): {
1799
1804
  } | null;
1800
1805
  /**
1801
1806
  * Format OKHSL values as a CSS `okhsl(H S% L%)` string.
1802
- * h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
1807
+ * h: 0–360, s: 0–1, l: 0–1 (factor scale, as returned by every converter).
1803
1808
  */
1804
1809
  declare function formatOkhsl(h: number, s: number, l: number, pastel?: boolean): string;
1805
1810
  /**
1806
1811
  * Format OKHST values as a CSS `okhst(H S% T%)` string.
1807
- * h: 0–360, s: 0–100, t: 0–100 (percentage scale for s and t).
1812
+ * h: 0–360, s: 0–1, t: 0–1 (factor scale, matching `ResolvedColorVariant`).
1808
1813
  *
1809
1814
  * Pastel recompute matches `formatOkhsl`: convert via OKLab so external
1810
1815
  * parsers that only understand non-pastel OKHST render identically.
@@ -1813,17 +1818,17 @@ declare function formatOkhst(h: number, s: number, t: number, pastel?: boolean):
1813
1818
  /**
1814
1819
  * Format OKHSL values as a CSS `rgb(R G B)` string.
1815
1820
  * Uses 2 decimal places to avoid 8-bit quantization contrast loss.
1816
- * h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
1821
+ * h: 0–360, s: 0–1, l: 0–1 (factor scale, as returned by every converter).
1817
1822
  */
1818
1823
  declare function formatRgb(h: number, s: number, l: number, pastel?: boolean): string;
1819
1824
  /**
1820
1825
  * Format OKHSL values as a CSS `hsl(H S% L%)` string.
1821
- * h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
1826
+ * h: 0–360, s: 0–1, l: 0–1 (factor scale, as returned by every converter).
1822
1827
  */
1823
1828
  declare function formatHsl(h: number, s: number, l: number, pastel?: boolean): string;
1824
1829
  /**
1825
1830
  * Format OKHSL values as a CSS `oklch(L C H)` string.
1826
- * h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
1831
+ * h: 0–360, s: 0–1, l: 0–1 (factor scale, as returned by every converter).
1827
1832
  */
1828
1833
  declare function formatOklch(h: number, s: number, l: number, pastel?: boolean): string;
1829
1834
  /**
package/dist/index.d.mts CHANGED
@@ -1698,7 +1698,11 @@ declare function okhslToOkhst(c: {
1698
1698
  };
1699
1699
  /**
1700
1700
  * Edge adapter: a resolved variant stores canonical tone `t` (0–1). Convert
1701
- * it to the OKHSL `{ h, s, l }` the formatters and luminance pipeline expect.
1701
+ * it to the OKHSL `{ h, s, l }` the formatters and luminance pipeline expect —
1702
+ * `s` and `l` on the same 0–1 factor scale, so `const { h, s, l } =
1703
+ * variantToOkhsl(v)` destructures straight into `formatOkhsl` / `formatRgb` /
1704
+ * `okhslToLinearSrgb` with no rescaling. `alpha` stays on the variant; use
1705
+ * `glaze.format(v, format)` for a string that carries it.
1702
1706
  */
1703
1707
  declare function variantToOkhsl(v: {
1704
1708
  h: number;
@@ -1753,6 +1757,7 @@ declare function relativeLuminanceFromLinearRgb(rgb: [number, number, number]):
1753
1757
  declare function contrastRatioFromLuminance(yA: number, yB: number): number;
1754
1758
  /**
1755
1759
  * Convert OKHSL to gamma-encoded sRGB (clamped to 0–1).
1760
+ * h: 0–360, s: 0–1, l: 0–1. Returns [r, g, b] with each channel 0–1.
1756
1761
  */
1757
1762
  declare function okhslToSrgb(h: number, s: number, l: number, pastel?: boolean): [number, number, number];
1758
1763
  /**
@@ -1799,12 +1804,12 @@ declare function parseHexAlpha(hex: string): {
1799
1804
  } | null;
1800
1805
  /**
1801
1806
  * Format OKHSL values as a CSS `okhsl(H S% L%)` string.
1802
- * h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
1807
+ * h: 0–360, s: 0–1, l: 0–1 (factor scale, as returned by every converter).
1803
1808
  */
1804
1809
  declare function formatOkhsl(h: number, s: number, l: number, pastel?: boolean): string;
1805
1810
  /**
1806
1811
  * Format OKHST values as a CSS `okhst(H S% T%)` string.
1807
- * h: 0–360, s: 0–100, t: 0–100 (percentage scale for s and t).
1812
+ * h: 0–360, s: 0–1, t: 0–1 (factor scale, matching `ResolvedColorVariant`).
1808
1813
  *
1809
1814
  * Pastel recompute matches `formatOkhsl`: convert via OKLab so external
1810
1815
  * parsers that only understand non-pastel OKHST render identically.
@@ -1813,17 +1818,17 @@ declare function formatOkhst(h: number, s: number, t: number, pastel?: boolean):
1813
1818
  /**
1814
1819
  * Format OKHSL values as a CSS `rgb(R G B)` string.
1815
1820
  * Uses 2 decimal places to avoid 8-bit quantization contrast loss.
1816
- * h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
1821
+ * h: 0–360, s: 0–1, l: 0–1 (factor scale, as returned by every converter).
1817
1822
  */
1818
1823
  declare function formatRgb(h: number, s: number, l: number, pastel?: boolean): string;
1819
1824
  /**
1820
1825
  * Format OKHSL values as a CSS `hsl(H S% L%)` string.
1821
- * h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
1826
+ * h: 0–360, s: 0–1, l: 0–1 (factor scale, as returned by every converter).
1822
1827
  */
1823
1828
  declare function formatHsl(h: number, s: number, l: number, pastel?: boolean): string;
1824
1829
  /**
1825
1830
  * Format OKHSL values as a CSS `oklch(L C H)` string.
1826
- * h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
1831
+ * h: 0–360, s: 0–1, l: 0–1 (factor scale, as returned by every converter).
1827
1832
  */
1828
1833
  declare function formatOklch(h: number, s: number, l: number, pastel?: boolean): string;
1829
1834
  /**
package/dist/index.mjs CHANGED
@@ -370,6 +370,7 @@ const sRGBGammaToLinear = (val) => {
370
370
  };
371
371
  /**
372
372
  * Convert OKHSL to gamma-encoded sRGB (clamped to 0–1).
373
+ * h: 0–360, s: 0–1, l: 0–1. Returns [r, g, b] with each channel 0–1.
373
374
  */
374
375
  function okhslToSrgb(h, s, l, pastel = false) {
375
376
  const lin = okhslToLinearSrgb(h, s, l, pastel);
@@ -579,47 +580,72 @@ function fmt$1(value, decimals) {
579
580
  return parseFloat(value.toFixed(decimals)).toString();
580
581
  }
581
582
  /**
583
+ * Every `format*` writer takes `s` / `l` / `t` on the **0–1 factor scale** —
584
+ * the same scale every producer in the library hands back (`resolve()`,
585
+ * `variantToOkhsl`, `srgbToOkhsl`, `oklabToOkhsl`, `okhslToOklab`,
586
+ * `okhslToSrgb`). The percentages are an output detail: the writers multiply
587
+ * by 100 themselves when the CSS syntax asks for a percentage.
588
+ *
589
+ * Before 2.0 the writers took 0–100 while everything producing those values
590
+ * returned 0–1, so the obvious composition was off by 100x and failed
591
+ * silently — `0.7` is a legal percentage, so the result was a valid CSS string
592
+ * naming a near-black color. A value above 1 can only be that old
593
+ * percentage-scale input, so warn about it loudly rather than emit a wrong
594
+ * color quietly.
595
+ */
596
+ const scaleWarnCache = /* @__PURE__ */ new Set();
597
+ function warnPercentScale(fn, ...values) {
598
+ if (!values.some((v) => v > 1.000001)) return;
599
+ if (!scaleWarnCache.has(fn)) {
600
+ scaleWarnCache.add(fn);
601
+ console.warn(`glaze: ${fn}() got a value above 1 — it takes the 0-1 factors every Glaze producer returns (resolve(), variantToOkhsl, srgbToOkhsl), not 0-100 percentages. Divide by 100, or drop the "* 100" left over from the pre-2.0 signature.`);
602
+ }
603
+ }
604
+ /**
582
605
  * Format OKHSL values as a CSS `okhsl(H S% L%)` string.
583
- * h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
606
+ * h: 0–360, s: 0–1, l: 0–1 (factor scale, as returned by every converter).
584
607
  */
585
608
  function formatOkhsl(h, s, l, pastel = false) {
609
+ warnPercentScale("formatOkhsl", s, l);
586
610
  let outS = s;
587
- if (pastel) outS = oklabToOkhsl(okhslToOklab(h, s / 100, l / 100, true), false)[1] * 100;
588
- return `okhsl(${fmt$1(h, 2)} ${fmt$1(outS, 2)}% ${fmt$1(l, 2)}%)`;
611
+ if (pastel) outS = oklabToOkhsl(okhslToOklab(h, s, l, true), false)[1];
612
+ return `okhsl(${fmt$1(h, 2)} ${fmt$1(outS * 100, 2)}% ${fmt$1(l * 100, 2)}%)`;
589
613
  }
590
614
  /**
591
615
  * Format OKHST values as a CSS `okhst(H S% T%)` string.
592
- * h: 0–360, s: 0–100, t: 0–100 (percentage scale for s and t).
616
+ * h: 0–360, s: 0–1, t: 0–1 (factor scale, matching `ResolvedColorVariant`).
593
617
  *
594
618
  * Pastel recompute matches `formatOkhsl`: convert via OKLab so external
595
619
  * parsers that only understand non-pastel OKHST render identically.
596
620
  */
597
621
  function formatOkhst(h, s, t, pastel = false) {
622
+ warnPercentScale("formatOkhst", s, t);
598
623
  let outS = s;
599
624
  if (pastel) {
600
625
  const REF_EPS = .05;
601
626
  const den = Math.log(1 + REF_EPS) - Math.log(REF_EPS);
602
- const y = Math.exp(t / 100 * den + Math.log(REF_EPS)) - REF_EPS;
603
- const l = toe(Math.cbrt(Math.max(0, y)));
604
- outS = oklabToOkhsl(okhslToOklab(h, s / 100, l, true), false)[1] * 100;
627
+ const y = Math.exp(t * den + Math.log(REF_EPS)) - REF_EPS;
628
+ outS = oklabToOkhsl(okhslToOklab(h, s, toe(Math.cbrt(Math.max(0, y))), true), false)[1];
605
629
  }
606
- return `okhst(${fmt$1(h, 2)} ${fmt$1(outS, 2)}% ${fmt$1(t, 2)}%)`;
630
+ return `okhst(${fmt$1(h, 2)} ${fmt$1(outS * 100, 2)}% ${fmt$1(t * 100, 2)}%)`;
607
631
  }
608
632
  /**
609
633
  * Format OKHSL values as a CSS `rgb(R G B)` string.
610
634
  * Uses 2 decimal places to avoid 8-bit quantization contrast loss.
611
- * h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
635
+ * h: 0–360, s: 0–1, l: 0–1 (factor scale, as returned by every converter).
612
636
  */
613
637
  function formatRgb(h, s, l, pastel = false) {
614
- const [r, g, b] = okhslToSrgb(h, s / 100, l / 100, pastel);
638
+ warnPercentScale("formatRgb", s, l);
639
+ const [r, g, b] = okhslToSrgb(h, s, l, pastel);
615
640
  return `rgb(${parseFloat((r * 255).toFixed(2))} ${parseFloat((g * 255).toFixed(2))} ${parseFloat((b * 255).toFixed(2))})`;
616
641
  }
617
642
  /**
618
643
  * Format OKHSL values as a CSS `hsl(H S% L%)` string.
619
- * h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
644
+ * h: 0–360, s: 0–1, l: 0–1 (factor scale, as returned by every converter).
620
645
  */
621
646
  function formatHsl(h, s, l, pastel = false) {
622
- const [r, g, b] = okhslToSrgb(h, s / 100, l / 100, pastel);
647
+ warnPercentScale("formatHsl", s, l);
648
+ const [r, g, b] = okhslToSrgb(h, s, l, pastel);
623
649
  const max = Math.max(r, g, b);
624
650
  const min = Math.min(r, g, b);
625
651
  const delta = max - min;
@@ -636,10 +662,11 @@ function formatHsl(h, s, l, pastel = false) {
636
662
  }
637
663
  /**
638
664
  * Format OKHSL values as a CSS `oklch(L C H)` string.
639
- * h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
665
+ * h: 0–360, s: 0–1, l: 0–1 (factor scale, as returned by every converter).
640
666
  */
641
667
  function formatOklch(h, s, l, pastel = false) {
642
- const [L, C, hh] = okhslToOklch(h, s / 100, l / 100, pastel);
668
+ warnPercentScale("formatOklch", s, l);
669
+ const [L, C, hh] = okhslToOklch(h, s, l, pastel);
643
670
  return `oklch(${fmt$1(L, 4)} ${fmt$1(C, 4)} ${fmt$1(hh, 2)})`;
644
671
  }
645
672
  /**
@@ -1117,7 +1144,11 @@ function okhslToOkhst(c) {
1117
1144
  }
1118
1145
  /**
1119
1146
  * Edge adapter: a resolved variant stores canonical tone `t` (0–1). Convert
1120
- * it to the OKHSL `{ h, s, l }` the formatters and luminance pipeline expect.
1147
+ * it to the OKHSL `{ h, s, l }` the formatters and luminance pipeline expect —
1148
+ * `s` and `l` on the same 0–1 factor scale, so `const { h, s, l } =
1149
+ * variantToOkhsl(v)` destructures straight into `formatOkhsl` / `formatRgb` /
1150
+ * `okhslToLinearSrgb` with no rescaling. `alpha` stays on the variant; use
1151
+ * `glaze.format(v, format)` for a string that carries it.
1121
1152
  */
1122
1153
  function variantToOkhsl(v) {
1123
1154
  return {
@@ -3024,10 +3055,10 @@ function fmt(value, decimals) {
3024
3055
  function formatVariant(v, format = "oklch", pastel = false) {
3025
3056
  const effectivePastel = v.pastel ?? pastel;
3026
3057
  let base;
3027
- if (format === "okhst") base = formatOkhst(v.h, v.s * 100, v.t * 100, effectivePastel);
3058
+ if (format === "okhst") base = formatOkhst(v.h, v.s, v.t, effectivePastel);
3028
3059
  else {
3029
3060
  const { l } = variantToOkhsl(v);
3030
- base = formatters[format](v.h, v.s * 100, l * 100, effectivePastel);
3061
+ base = formatters[format](v.h, v.s, l, effectivePastel);
3031
3062
  }
3032
3063
  if (v.alpha >= 1) return base;
3033
3064
  const closing = base.lastIndexOf(")");
@@ -3043,7 +3074,7 @@ function formatVariantHue(v, plan, pastel = false) {
3043
3074
  const [L, C] = okhslToOklch(v.h, v.s, l, effectivePastel);
3044
3075
  let base;
3045
3076
  if (plan.inline) if (v.s <= 1e-6) base = `oklch(${fmt(L, 4)} 0 0)`;
3046
- else base = formatOklch(v.h, v.s * 100, l * 100, effectivePastel);
3077
+ else base = formatOklch(v.h, v.s, l, effectivePastel);
3047
3078
  else base = `oklch(${fmt(L, 4)} ${fmt(C, 4)} ${plan.hueVar})`;
3048
3079
  if (v.alpha >= 1) return base;
3049
3080
  const closing = base.lastIndexOf(")");