@tenphi/glaze 1.5.0 → 2.0.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/dist/index.cjs +49 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -6
- package/dist/index.d.mts +11 -6
- package/dist/index.mjs +49 -18
- package/dist/index.mjs.map +1 -1
- package/docs/api.md +38 -9
- package/docs/migration.md +36 -0
- package/package.json +1 -1
package/docs/api.md
CHANGED
|
@@ -1896,7 +1896,7 @@ import {
|
|
|
1896
1896
|
| Function | Description |
|
|
1897
1897
|
| ------------------------------------- | ------------------------------------------------------------------------ |
|
|
1898
1898
|
| `okhslToLinearSrgb(h, s, l)` | OKHSL (h: 0–360, s/l: 0–1) → linear sRGB tuple. |
|
|
1899
|
-
| `okhslToSrgb(h, s, l)` | OKHSL → gamma-encoded sRGB tuple (0–1 per channel).
|
|
1899
|
+
| `okhslToSrgb(h, s, l)` | OKHSL (h: 0–360, s/l: 0–1) → gamma-encoded sRGB tuple (0–1 per channel). |
|
|
1900
1900
|
| `okhslToOklab([h, s, l])` | OKHSL → OKLab `[L, a, b]`. |
|
|
1901
1901
|
| `oklabToOkhsl([L, a, b])` | OKLab → OKHSL. |
|
|
1902
1902
|
| `srgbToOkhsl([r, g, b])` | Gamma sRGB (0–1) → OKHSL. |
|
|
@@ -1909,15 +1909,44 @@ import {
|
|
|
1909
1909
|
|
|
1910
1910
|
### Format writers
|
|
1911
1911
|
|
|
1912
|
+
Every writer takes `h` on 0–360 and `s` / `l` / `t` on **0–1** — the scale every
|
|
1913
|
+
conversion above *returns*, and the scale `resolve()` stores in a
|
|
1914
|
+
`ResolvedColorVariant`. The percentages are an output detail: the writers scale
|
|
1915
|
+
by 100 themselves where the CSS syntax asks for one. (The one thing on a
|
|
1916
|
+
different scale is the pair of tone transfers below, `toTone` / `fromTone`,
|
|
1917
|
+
which speak the 0–100 tone axis the authoring API takes.)
|
|
1918
|
+
|
|
1912
1919
|
```ts
|
|
1913
|
-
import {
|
|
1920
|
+
import {
|
|
1921
|
+
formatOkhsl,
|
|
1922
|
+
formatOkhst,
|
|
1923
|
+
formatRgb,
|
|
1924
|
+
formatHsl,
|
|
1925
|
+
formatOklch,
|
|
1926
|
+
} from '@tenphi/glaze';
|
|
1914
1927
|
|
|
1915
|
-
formatOkhsl(280,
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1928
|
+
formatOkhsl(280, 0.6, 0.95); // 'okhsl(280 60% 95%)'
|
|
1929
|
+
formatOkhst(280, 0.6, 0.95); // 'okhst(280 60% 95%)'
|
|
1930
|
+
formatRgb(280, 0.6, 0.95); // 'rgb(238.45 239.95 251.1)'
|
|
1931
|
+
formatHsl(280, 0.6, 0.95); // 'hsl(232.92 61.87% 95.99%)'
|
|
1932
|
+
formatOklch(280, 0.6, 0.95); // 'oklch(0.9571 0.015 280)'
|
|
1919
1933
|
```
|
|
1920
1934
|
|
|
1935
|
+
So a producer composes with a writer directly, with nothing to rescale in
|
|
1936
|
+
between:
|
|
1937
|
+
|
|
1938
|
+
```ts
|
|
1939
|
+
const v = glaze.color('#7A4DBF').resolve().light;
|
|
1940
|
+
const { h, s, l } = variantToOkhsl(v);
|
|
1941
|
+
|
|
1942
|
+
formatOkhst(v.h, v.s, v.t); // 'okhst(298.52 70.41% 45.02%)'
|
|
1943
|
+
formatOkhsl(h, s, l); // 'okhsl(298.52 70.41% 45.27%)'
|
|
1944
|
+
formatRgb(h, s, l); // 'rgb(122 77 191)'
|
|
1945
|
+
```
|
|
1946
|
+
|
|
1947
|
+
A value above 1 can only be pre-2.0 percentage-scale input, so the writers
|
|
1948
|
+
`console.warn` about it once per writer rather than emit a wrong color quietly.
|
|
1949
|
+
|
|
1921
1950
|
To attach an alpha component, use `glaze.format(variant, format)` on a `ResolvedColorVariant` (which carries the `alpha` channel) instead of these raw writers.
|
|
1922
1951
|
|
|
1923
1952
|
### OKHST tone utilities
|
|
@@ -1937,12 +1966,12 @@ import {
|
|
|
1937
1966
|
|
|
1938
1967
|
| Function | Description |
|
|
1939
1968
|
| ------------------------------------------- | ------------------------------------------------------------------------- |
|
|
1940
|
-
| `toTone(l, eps?)` | OKHSL lightness (0–1) → tone (0–100). Defaults to `REF_EPS`.
|
|
1941
|
-
| `fromTone(t, eps?)` | Tone (0–100) → OKHSL lightness (0–1). Inverse of `toTone`.
|
|
1969
|
+
| `toTone(l, eps?)` | OKHSL lightness (0–1) → tone (**0–100**, the authoring scale — divide by 100 for `formatOkhst`). Defaults to `REF_EPS`. |
|
|
1970
|
+
| `fromTone(t, eps?)` | Tone (**0–100**) → OKHSL lightness (0–1). Inverse of `toTone`. |
|
|
1942
1971
|
| `toneFromY(y, eps?)` / `yFromTone(t, eps?)` | Same transfer in luminance space (0–1). |
|
|
1943
1972
|
| `okhstToOkhsl({ h, s, t })` | OKHST → OKHSL (`{ h, s, l }`). |
|
|
1944
1973
|
| `okhslToOkhst({ h, s, l })` | OKHSL → OKHST (`{ h, s, t }`). |
|
|
1945
|
-
| `variantToOkhsl(variant)` | `ResolvedColorVariant` (stores `t`) → `{ h, s, l
|
|
1974
|
+
| `variantToOkhsl(variant)` | `ResolvedColorVariant` (stores `t`) → `{ h, s, l }` for rendering (`alpha` stays on the variant). |
|
|
1946
1975
|
| `REF_EPS` | Reference epsilon (`0.05`) for the canonical tone axis. |
|
|
1947
1976
|
|
|
1948
1977
|
`ResolvedColorVariant` stores `{ h, s, t, alpha }` (tone, not lightness). Use
|
package/docs/migration.md
CHANGED
|
@@ -12,6 +12,7 @@ If you're starting from scratch, see [methodology.md](methodology.md) first —
|
|
|
12
12
|
- [Wiring exports into the app](#wiring-exports-into-the-app)
|
|
13
13
|
- [Prefix map strategies](#prefix-map-strategies)
|
|
14
14
|
- [Migrating an existing color system](#migrating-from-an-existing-color-system)
|
|
15
|
+
- [Upgrading Glaze](#upgrading-glaze)
|
|
15
16
|
- [Common pitfalls](#common-pitfalls)
|
|
16
17
|
|
|
17
18
|
## Choosing an export
|
|
@@ -296,6 +297,40 @@ Glaze gives you light/dark/HC for free, but only the light mode is matched again
|
|
|
296
297
|
|
|
297
298
|
After migration, mark every default-only token (borders, shadows, disabled chip, code highlighting, etc.) `inherit: false`. Colored sibling themes only need the accent + tinted-surface chain — flagging the rest cuts the emitted token set per theme dramatically.
|
|
298
299
|
|
|
300
|
+
## Upgrading Glaze
|
|
301
|
+
|
|
302
|
+
### 2.0 — `format*` takes 0–1
|
|
303
|
+
|
|
304
|
+
The `format*` writers (`formatOkhsl`, `formatOkhst`, `formatRgb`, `formatHsl`,
|
|
305
|
+
`formatOklch`) used to take `s` / `l` / `t` on a 0–100 percentage scale while
|
|
306
|
+
everything that *produces* those values — `resolve()`, `variantToOkhsl`,
|
|
307
|
+
`srgbToOkhsl`, `oklabToOkhsl`, `okhslToSrgb` — returns them on 0–1. Composing
|
|
308
|
+
the two, which is the obvious thing to do, was off by 100x and failed silently:
|
|
309
|
+
`0.7` is a legal percentage, so you got a valid CSS string naming the wrong
|
|
310
|
+
(near-black) color.
|
|
311
|
+
|
|
312
|
+
The writers now take the 0–1 factors, so the whole library speaks one scale.
|
|
313
|
+
Drop the `* 100`:
|
|
314
|
+
|
|
315
|
+
```diff
|
|
316
|
+
- formatOkhsl(v.h, v.s * 100, l * 100);
|
|
317
|
+
+ formatOkhsl(v.h, v.s, l);
|
|
318
|
+
|
|
319
|
+
- formatOkhst(v.h, v.s * 100, v.t * 100);
|
|
320
|
+
+ formatOkhst(v.h, v.s, v.t);
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
Nothing else moves: `h` was always 0–360, `alpha` was always 0–1, and every
|
|
324
|
+
export method (`css()` / `tokens()` / `json()` / `tasty()` / `dtcg()` /
|
|
325
|
+
`tailwind()` / `glaze.format()`) emits the same colors — they were compensating
|
|
326
|
+
internally. Dropping the redundant `×100 ÷100` round-trip shifts float noise by
|
|
327
|
+
an ULP, which shows up nowhere except the (meaningless) hue term of a
|
|
328
|
+
fully-desaturated `hsl()` string.
|
|
329
|
+
|
|
330
|
+
A leftover `* 100` is not silent any more: a value above 1 cannot be a factor,
|
|
331
|
+
so the writers `console.warn` once per writer and you get an obviously-broken
|
|
332
|
+
`7040.68%` instead of a plausible wrong color.
|
|
333
|
+
|
|
299
334
|
## Common pitfalls
|
|
300
335
|
|
|
301
336
|
| Symptom | Cause | Fix |
|
|
@@ -307,6 +342,7 @@ After migration, mark every default-only token (borders, shadows, disabled chip,
|
|
|
307
342
|
| A relative `tone` like `'+48'` lands on the _wrong_ (darker) side of its base. | Overshooting offsets now mirror to the other side of the base by default (`autoFlip` inherits `autoFlip`). | Set `autoFlip: false` on the color to clamp to the boundary instead, or use `tone: 'max'`/`'min'` to force the extreme. |
|
|
308
343
|
| `palette.tokens()` emits unexpected unprefixed names. | A `primary` was set on the palette (or per-call) and is duplicating the theme's tokens without prefix. | Pass `primary: false` to disable for that export, or rename `glaze.palette(themes, { primary })`. |
|
|
309
344
|
| `console.warn: token "foo" collides with theme "bar"`. | Two themes resolved to the same output key under your prefix config. | Adjust the prefix map so each token is unique, or accept the first-write-wins behavior. |
|
|
345
|
+
| `console.warn: formatOkhsl() got a value above 1`. | Pre-2.0 percentage-scale input to a `format*` writer (a leftover `* 100`). | Pass the 0–1 factors the converters return — see [2.0 — `format*` takes 0–1](#20--format-takes-01). |
|
|
310
346
|
| `console.warn: color "X" cannot meet contrast`. | The requested contrast target is physically unreachable for the color's hue/saturation against its base. | Lower the floor, change the base, or accept the closest passing variant. Use the `name` override on standalone colors to make the warning identifiable. |
|
|
311
347
|
|
|
312
348
|
## See also
|
package/package.json
CHANGED