@tenphi/glaze 0.18.0 → 1.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/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  <h1 align="center">Glaze</h1>
6
6
 
7
7
  <p align="center">
8
- OKHST-based color theme generator with WCAG contrast solving
8
+ OKHST-based color theme generator with WCAG and APCA contrast solving
9
9
  </p>
10
10
 
11
11
  <p align="center">
@@ -16,18 +16,25 @@
16
16
 
17
17
  ---
18
18
 
19
- Glaze generates robust **light**, **dark**, and **high-contrast** color schemes from a single hue/saturation seed. WCAG contrast is preserved via explicit dependency declarations — no hidden role math, no magic multipliers.
19
+ Glaze generates **light**, **dark**, and **high-contrast** color schemes from a
20
+ single hue/saturation seed. Relationships stay explicit: colors either define
21
+ an absolute tone or depend on a named base through a tone delta and an optional
22
+ contrast floor.
20
23
 
21
24
  ## Features
22
25
 
23
- - **OKHST color space** — OKHSL with a contrast-uniform **tone** axis (equal tone steps give equal contrast). See [`docs/okhst.md`](docs/okhst.md).
26
+ - **OKHST color space** — OKHSL with a contrast-shaped **tone** axis. Equal
27
+ steps give equal WCAG contrast for neutrals and a useful approximation for
28
+ chromatic colors. See [OKHST in Glaze](docs/okhst.md) and the
29
+ [full OKHST specification](https://github.com/tenphi/okhst).
24
30
  - **WCAG 2 + APCA contrast solving** — automatic tone adjustment to meet a WCAG ratio or APCA Lc floor
25
31
  - **Unified dark mode** — one tone space for light, dark, and high-contrast; dark is a single `100 − t` inversion, no fitted curve
26
32
  - **Mix colors** — blend two colors with OKHSL or sRGB interpolation, opaque or transparent, with optional contrast solving
27
33
  - **Shadow colors** — OKHSL-native shadow computation with automatic alpha, fg/bg tinting, and per-scheme adaptation
28
34
  - **Light + Dark + High-Contrast** — all schemes from one definition
29
35
  - **Per-color hue override** — absolute or relative hue shifts within a theme
30
- - **Multi-format output** — `okhsl`, `rgb`, `hsl`, `oklch` with modern CSS space syntax
36
+ - **Multi-format output** — native `rgb`, `hsl`, and `oklch`, plus
37
+ [Tasty](https://tasty.style)-compatible `okhsl` and `okhst`
31
38
  - **CSS custom properties export** — ready-to-use `--var: value;` declarations per scheme
32
39
  - **W3C DTCG export** — spec-conformant `.tokens.json` (2025.10) for Figma, Tokens Studio, Style Dictionary, and every DTCG tool
33
40
  - **W3C DTCG Resolver-Module export** — opt-in single-document `dtcgResolver()` (sets + a `scheme` modifier with a context per variant) for resolver tools such as Dispersa
@@ -57,43 +64,90 @@ yarn add @tenphi/glaze
57
64
  ```ts
58
65
  import { glaze } from '@tenphi/glaze';
59
66
 
60
- const primary = glaze(280, 80);
61
-
62
- primary.colors({
63
- surface: { tone: 97, saturation: 0.75 },
64
- text: { base: 'surface', tone: '-52', contrast: 'AAA' },
65
- border: { base: 'surface', tone: ['-7', '-20'], contrast: 'AA-large' },
66
- 'accent-fill': { tone: 52, mode: 'fixed' },
67
- 'accent-text': { base: 'accent-fill', tone: 'max', mode: 'fixed' },
68
- 'shadow-md': { type: 'shadow', bg: 'surface', fg: 'text', intensity: 10 },
67
+ glaze.configure({
68
+ modes: { dark: true, highContrast: true },
69
69
  });
70
70
 
71
- const danger = primary.extend({ hue: 23 });
72
- const success = primary.extend({ hue: 157 });
71
+ const defaultTheme = glaze(280, 80);
72
+
73
+ defaultTheme.colors({
74
+ surface: { tone: 97, saturation: 0.15 },
75
+ 'surface-text': {
76
+ base: 'surface',
77
+ tone: '-1',
78
+ contrast: { apca: ['content', 'body'] },
79
+ },
80
+ border: {
81
+ base: 'surface',
82
+ tone: ['-8', '-16'],
83
+ inherit: false,
84
+ },
85
+ 'accent-surface': { tone: 52, mode: 'fixed' },
86
+ 'accent-surface-text': {
87
+ base: 'accent-surface',
88
+ tone: '+1',
89
+ contrast: 'AA',
90
+ mode: 'fixed',
91
+ },
92
+ });
73
93
 
74
- const palette = glaze.palette(
75
- { primary, danger, success },
76
- { primary: 'primary' },
77
- );
94
+ const dangerTheme = defaultTheme.extend({ hue: 23 });
95
+ const palette = glaze.palette({ default: defaultTheme, danger: dangerTheme });
78
96
 
79
- const tokens = palette.tokens();
80
- // → { light: { 'primary-surface': 'okhsl(...)', 'surface': 'okhsl(...)', ... },
81
- // dark: { 'primary-surface': 'okhsl(...)', 'surface': 'okhsl(...)', ... } }
97
+ const tokens = palette.tokens({
98
+ prefix: { default: '', danger: 'danger-' },
99
+ });
100
+ // → {
101
+ // light: { surface: 'oklch(...)', 'danger-surface': 'oklch(...)', ... },
102
+ // dark: { surface: 'oklch(...)', 'danger-surface': 'oklch(...)', ... },
103
+ // lightContrast: { ... },
104
+ // darkContrast: { ... },
105
+ // }
82
106
  ```
83
107
 
84
108
  ## Concepts at a glance
85
109
 
86
- 1. **Theme = one hue/saturation seed.** Status themes are siblings created via `extend()` — they inherit every color definition and only swap the seed.
87
- 2. **Every color is explicit.** A color is either a *root* (absolute `tone`, or `'max'`/`'min'` for an extreme) or *dependent* (`base` + relative offset and/or `contrast`). No implicit roles.
88
- 3. **Tone is contrast-uniform.** `tone` (0–100) replaces OKHSL lightness: equal tone steps give equal WCAG contrast, so ramps are even by construction. See [`docs/okhst.md`](docs/okhst.md).
89
- 4. **`contrast` is a floor, not a target.** A bare number/preset is WCAG; `{ wcag }` / `{ apca }` selects the metric. The solver only shifts a color's tone when the requested position fails the requested floor.
90
- 5. **Light, dark, and high-contrast come from one definition.** `mode` (`auto` / `fixed` / `static`) picks how each color adapts; `tone` / `contrast` / `intensity` / `value` accept an optional `[normal, hc]` pair for explicit high-contrast tuning.
110
+ 1. **A theme has one hue/saturation seed.** Create status themes with
111
+ `extend()` so they inherit the same relationships while changing hue.
112
+ 2. **A color is a root or a dependency.** Roots use an absolute `tone` or
113
+ `'max'`/`'min'`. Dependent colors name a `base` and may use a signed
114
+ **tone delta** such as `'-8'` plus a `contrast` floor.
115
+ 3. **Tone is an authoring axis, not a contrast guarantee.** Equal tone deltas
116
+ are exact WCAG steps for neutrals. Chromatic colors can drift in rendered
117
+ luminance, so Glaze measures contrast floors against the resolved colors.
118
+ 4. **`contrast` is a floor.** A bare number or preset means WCAG;
119
+ `{ wcag }` and `{ apca }` select the metric explicitly. The solver preserves
120
+ the requested tone whenever it already passes.
121
+ 5. **Each color chooses its dark adaptation.** `mode: 'auto'` uses dark tone
122
+ inversion (`100 - t`), `fixed` keeps the authored side of the tone scale,
123
+ and `static` skips scheme adaptation.
124
+ 6. **Tone windows bound ordinary schemes.** `lightTone` and `darkTone`
125
+ configure the light/dark render ranges. High-contrast variants use the full
126
+ range. Values that accept `[normal, highContrast]` pairs can tighten
127
+ deliberately in HC.
128
+
129
+ In Glaze, a **scheme variant** is one of `light`, `dark`, `lightContrast`, or
130
+ `darkContrast`. Export `modes` choose which variants are included; [Tasty](https://tasty.style)
131
+ `states` choose how those variants are activated in an application.
132
+
133
+ ## Choosing an output
134
+
135
+ - `tasty()` returns [Tasty](https://tasty.style) `#token` bindings, including its custom `okhsl()` or
136
+ `okhst()` serialization.
137
+ - `tokens()` and `json()` return JavaScript data and default to native
138
+ `oklch()` values.
139
+ - `css()` returns custom-property declarations.
140
+ - `dtcg()` / `dtcgResolver()` target design-token tooling.
141
+ - `tailwind()` emits a Tailwind CSS v4 theme.
91
142
 
92
143
  ## Documentation
93
144
 
94
- - [`docs/api.md`](docs/api.md) full API reference (every method, every option).
95
- - [`docs/methodology.md`](docs/methodology.md) palette design methodology for building from scratch.
96
- - [`docs/migration.md`](docs/migration.md) wiring tokens into your app and migrating off a legacy color system.
145
+ - Start with [the methodology](docs/methodology.md) to design a palette.
146
+ - Use [migration and integration](docs/migration.md) to wire it into an
147
+ application or replace an existing color system.
148
+ - Keep the [API reference](docs/api.md) nearby for every method and option.
149
+ - Read [OKHST in Glaze](docs/okhst.md) for the product-level color model, or
150
+ the [full OKHST specification](https://github.com/tenphi/okhst) for its math.
97
151
  - [`AGENTS.md`](AGENTS.md) — source-tree orientation for contributors.
98
152
 
99
153
  ## License
package/dist/index.cjs CHANGED
@@ -690,8 +690,8 @@ function defaultConfig() {
690
690
  },
691
691
  darkDesaturation: .1,
692
692
  states: {
693
- dark: "@dark",
694
- highContrast: "@high-contrast"
693
+ dark: "@media(prefers-color-scheme: dark)",
694
+ highContrast: "@media(prefers-contrast: more)"
695
695
  },
696
696
  modes: {
697
697
  dark: true,