@tenphi/glaze 0.0.0-snapshot.f3bb46b → 0.0.0-snapshot.f404191

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
- OKHSL-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,22 +16,35 @@
16
16
 
17
17
  ---
18
18
 
19
- Glaze generates robust **light**, **dark**, and **high-contrast** color schemes from a single hue/saturation seed. It preserves WCAG contrast ratios for UI color pairs 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
- - **OKHSL color space** — perceptually uniform hue and saturation
24
- - **WCAG 2 contrast solving** — automatic lightness adjustment to meet AA/AAA targets
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 [Tone and OKHST](docs/okhst.mdx) and the
29
+ [full OKHST specification](https://github.com/tenphi/okhst).
30
+ - **WCAG 2 + APCA contrast solving** — automatic tone adjustment to meet a WCAG ratio or APCA Lc floor
31
+ - **Unified dark mode** — one tone space for light, dark, and high-contrast; dark is a single `100 − t` inversion, no fitted curve
25
32
  - **Mix colors** — blend two colors with OKHSL or sRGB interpolation, opaque or transparent, with optional contrast solving
26
- - **Shadow colors** — OKHSL-native shadow computation with automatic alpha, fg/bg tinting, and per-scheme adaptation
33
+ - **Shadows and glows** — translucent overlays whose opacity is solved per surface, so `intensity` is an exact tone step wherever the surface has room for it (a step past black or white is pinned and warns), with object-aware strength
34
+ - **HDR glows** — set `glowTuning.headroom` and a glow whose step passes white also gets an exact HDR value: `color(srgb-linear …)` in CSS, an exposure in DTCG for native apps, exported when you turn on `modes.hdr`
27
35
  - **Light + Dark + High-Contrast** — all schemes from one definition
36
+ - **Manual contrast level** — put your normal palette on a `0–100` slider between itself and the high-contrast one; every level in between is solved, not approximated, and the high-contrast tier stays available on top
28
37
  - **Per-color hue override** — absolute or relative hue shifts within a theme
29
- - **Multi-format output** — `okhsl`, `rgb`, `hsl`, `oklch` with modern CSS space syntax
38
+ - **Multi-format output** — native `rgb`, `hsl`, and `oklch`, plus
39
+ [Tasty](https://tasty.style)-compatible `okhsl` and `okhst`
30
40
  - **CSS custom properties export** — ready-to-use `--var: value;` declarations per scheme
31
- - **Import/Export** — serialize and restore theme configurations
41
+ - **W3C DTCG export** — spec-conformant `.tokens.json` (2025.10) for Figma, Tokens Studio, Style Dictionary, and every DTCG tool
42
+ - **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
43
+ - **Tailwind CSS v4 export** — `@theme` block + dark / high-contrast overrides
44
+ - **Import/Export** — serialize and restore themes, color tokens, and entire palettes as JSON
32
45
  - **Create from hex/RGB** — start from an existing brand color
33
46
  - **Zero dependencies** — pure math, runs anywhere (Node.js, browser, edge)
34
- - **Tree-shakeable ESM + CJS** — dual-format package
47
+ - **ESM + CJS** — dual-format package
35
48
  - **TypeScript-first** — full type definitions included
36
49
 
37
50
  ## Installation
@@ -53,1112 +66,112 @@ yarn add @tenphi/glaze
53
66
  ```ts
54
67
  import { glaze } from '@tenphi/glaze';
55
68
 
56
- // Create a theme from a hue (0–360) and saturation (0–100)
57
- const primary = glaze(280, 80);
58
-
59
- // Define colors with explicit lightness and contrast relationships
60
- primary.colors({
61
- surface: { lightness: 97, saturation: 0.75 },
62
- text: { base: 'surface', lightness: '-52', contrast: 'AAA' },
63
- border: { base: 'surface', lightness: ['-7', '-20'], contrast: 'AA-large' },
64
- 'accent-fill': { lightness: 52, mode: 'fixed' },
65
- 'accent-text': { base: 'accent-fill', lightness: '+48', contrast: 'AA', mode: 'fixed' },
66
- });
67
-
68
- // Create status themes by rotating the hue
69
- const danger = primary.extend({ hue: 23 });
70
- const success = primary.extend({ hue: 157 });
71
-
72
- // Compose into a palette and export
73
- const palette = glaze.palette({ primary, danger, success }, { primary: 'primary' });
74
- const tokens = palette.tokens();
75
- // → { light: { 'primary-surface': 'okhsl(...)', 'surface': 'okhsl(...)', ... }, dark: { ... } }
76
- ```
77
-
78
- ## Core Concepts
79
-
80
- ### One Theme = One Hue Family
81
-
82
- A single `glaze` theme is tied to one hue/saturation seed. Status colors (danger, success, warning) are derived via `extend`, which inherits all color definitions and replaces the seed.
83
-
84
- Individual colors can override the hue via the `hue` prop (see [Per-Color Hue Override](#per-color-hue-override)), but the primary purpose of a theme is to scope colors with the same hue.
85
-
86
- ### Color Definitions
87
-
88
- Every color is defined explicitly. No implicit roles — every value is stated.
89
-
90
- #### Root Colors (explicit position)
91
-
92
- ```ts
93
- primary.colors({
94
- surface: { lightness: 97, saturation: 0.75 },
95
- border: { lightness: 90, saturation: 0.20 },
96
- });
97
- ```
98
-
99
- - `lightness` — lightness in the light scheme (0–100)
100
- - `saturation` — saturation factor applied to the seed saturation (0–1, default: `1`)
101
-
102
- #### Dependent Colors (relative to base)
103
-
104
- ```ts
105
- primary.colors({
106
- surface: { lightness: 97, saturation: 0.75 },
107
- text: { base: 'surface', lightness: '-52', contrast: 'AAA' },
108
- });
109
- ```
110
-
111
- - `base` — name of another color in the same theme
112
- - `lightness` — position of this color (see [Lightness Values](#lightness-values))
113
- - `contrast` — ensures the WCAG contrast ratio meets a target floor against the base
114
-
115
- ### Lightness Values
116
-
117
- The `lightness` prop accepts two forms:
118
-
119
- | Form | Example | Meaning |
120
- |---|---|---|
121
- | Number (absolute) | `lightness: 45` | Absolute lightness 0–100 |
122
- | String (relative) | `lightness: '-52'` | Relative to base color's lightness |
123
-
124
- **Absolute lightness** on a dependent color (with `base`) positions the color independently. In dark mode, it is dark-mapped on its own. The `contrast` WCAG solver acts as a safety net.
125
-
126
- **Relative lightness** applies a signed delta to the base color's resolved lightness. In dark mode with `auto` adaptation, the sign flips automatically.
127
-
128
- ```ts
129
- // Relative: 97 - 52 = 45 in light mode
130
- 'text': { base: 'surface', lightness: '-52' }
131
-
132
- // Absolute: lightness 45 in light mode, dark-mapped independently
133
- 'text': { base: 'surface', lightness: 45 }
134
- ```
135
-
136
- A dependent color with `base` but no `lightness` inherits the base's lightness (equivalent to a delta of 0).
137
-
138
- ### Per-Color Hue Override
139
-
140
- Individual colors can override the theme's hue. The `hue` prop accepts:
141
-
142
- | Form | Example | Meaning |
143
- |---|---|---|
144
- | Number (absolute) | `hue: 120` | Absolute hue 0–360 |
145
- | String (relative) | `hue: '+20'` | Relative to the **theme seed** hue |
146
-
147
- **Important:** Relative hue is always relative to the **theme seed hue**, not to a base color's hue.
148
-
149
- ```ts
150
- const theme = glaze(280, 80);
151
- theme.colors({
152
- surface: { lightness: 97 },
153
- // Gradient end — slight hue shift from seed (280 + 20 = 300)
154
- gradientEnd: { lightness: 90, hue: '+20' },
155
- // Entirely different hue
156
- warning: { lightness: 60, hue: 40 },
157
- });
158
- ```
159
-
160
- ### contrast (WCAG Floor)
161
-
162
- Ensures the WCAG contrast ratio meets a target floor. Accepts a numeric ratio or a preset string:
163
-
164
- ```ts
165
- type MinContrast = number | 'AA' | 'AAA' | 'AA-large' | 'AAA-large';
166
- ```
167
-
168
- | Preset | Ratio |
169
- |---|---|
170
- | `'AA'` | 4.5 |
171
- | `'AAA'` | 7 |
172
- | `'AA-large'` | 3 |
173
- | `'AAA-large'` | 4.5 |
174
-
175
- You can also pass any numeric ratio directly (e.g., `contrast: 4.5`, `contrast: 7`, `contrast: 11`).
176
-
177
- The constraint is applied independently for each scheme. If the `lightness` already satisfies the floor, it's kept. Otherwise, the solver adjusts lightness until the target is met.
178
-
179
- ### High-Contrast via Array Values
180
-
181
- `lightness` and `contrast` accept a `[normal, high-contrast]` pair:
182
-
183
- ```ts
184
- 'border': { base: 'surface', lightness: ['-7', '-20'], contrast: 'AA-large' }
185
- // ↑ ↑
186
- // normal high-contrast
187
- ```
188
-
189
- A single value applies to both modes. All control is local and explicit.
190
-
191
- ```ts
192
- 'text': { base: 'surface', lightness: '-52', contrast: 'AAA' }
193
- 'border': { base: 'surface', lightness: ['-7', '-20'], contrast: 'AA-large' }
194
- 'muted': { base: 'surface', lightness: ['-35', '-50'], contrast: ['AA-large', 'AA'] }
195
- ```
196
-
197
- **Full lightness spectrum in HC mode:** In high-contrast variants, the `lightLightness` and `darkLightness` window constraints are bypassed entirely. Colors can reach the full 0–100 lightness range, maximizing perceivable contrast. Normal (non-HC) variants continue to use the configured windows.
198
-
199
- ## Theme Color Management
200
-
201
- ### Adding Colors
202
-
203
- `.colors(defs)` performs an **additive merge** — it adds new colors and overwrites existing ones by name, but does not remove other colors:
204
-
205
- ```ts
206
- const theme = glaze(280, 80);
207
- theme.colors({ surface: { lightness: 97 } });
208
- theme.colors({ text: { lightness: 30 } });
209
- // Both 'surface' and 'text' are now defined
210
- ```
211
-
212
- ### Single Color Getter/Setter
213
-
214
- `.color(name)` returns the definition, `.color(name, def)` sets it:
215
-
216
- ```ts
217
- theme.color('surface', { lightness: 97, saturation: 0.75 }); // set
218
- const def = theme.color('surface'); // get → { lightness: 97, saturation: 0.75 }
219
- ```
220
-
221
- ### Removing Colors
222
-
223
- `.remove(name)` or `.remove([name1, name2])` deletes color definitions:
224
-
225
- ```ts
226
- theme.remove('surface');
227
- theme.remove(['text', 'border']);
228
- ```
229
-
230
- ### Introspection
231
-
232
- ```ts
233
- theme.has('surface'); // → true/false
234
- theme.list(); // → ['surface', 'text', 'border', ...]
235
- ```
236
-
237
- ### Clearing All Colors
238
-
239
- ```ts
240
- theme.reset(); // removes all color definitions
241
- ```
242
-
243
- ## Import / Export
244
-
245
- Serialize a theme's configuration (hue, saturation, color definitions) to a plain JSON-safe object, and restore it later:
246
-
247
- ```ts
248
- // Export
249
- const snapshot = theme.export();
250
- // → { hue: 280, saturation: 80, colors: { surface: { lightness: 97, saturation: 0.75 }, ... } }
251
-
252
- const jsonString = JSON.stringify(snapshot);
253
-
254
- // Import
255
- const restored = glaze.from(JSON.parse(jsonString));
256
- // restored is a fully functional GlazeTheme
257
- ```
258
-
259
- The export contains only the configuration — not resolved color values. Resolved values are recomputed on demand.
260
-
261
- ## Standalone Color Token
262
-
263
- Create a single color token without a full theme:
264
-
265
- ```ts
266
- const accent = glaze.color({ hue: 280, saturation: 80, lightness: 52, mode: 'fixed' });
267
-
268
- accent.resolve(); // → ResolvedColor with light/dark/lightContrast/darkContrast
269
- accent.token(); // → { '': 'okhsl(...)', '@dark': 'okhsl(...)' } (tasty format)
270
- accent.tasty(); // → { '': 'okhsl(...)', '@dark': 'okhsl(...)' } (same as token)
271
- accent.json(); // → { light: 'okhsl(...)', dark: 'okhsl(...)' }
272
- ```
273
-
274
- Standalone colors are always root colors (no `base`/`contrast`).
275
-
276
- ## From Existing Colors
277
-
278
- Create a theme from an existing brand color by extracting its OKHSL hue and saturation:
279
-
280
- ```ts
281
- // From hex
282
- const brand = glaze.fromHex('#7a4dbf');
283
-
284
- // From RGB (0–255)
285
- const brand = glaze.fromRgb(122, 77, 191);
286
- ```
287
-
288
- The resulting theme has the extracted hue and saturation. Add colors as usual:
289
-
290
- ```ts
291
- brand.colors({
292
- surface: { lightness: 97, saturation: 0.75 },
293
- text: { base: 'surface', lightness: '-52', contrast: 'AAA' },
294
- });
295
- ```
296
-
297
- ## Shadow Colors
298
-
299
- Shadow colors are colors with computed alpha. Instead of a parallel shadow system, they extend the existing color pipeline. All math is done natively in OKHSL.
300
-
301
- ### Defining Shadow Colors
302
-
303
- Shadow colors use `type: 'shadow'` and reference a `bg` (background) color and optionally an `fg` (foreground) color for tinting and intensity modulation:
304
-
305
- ```ts
306
- theme.colors({
307
- surface: { lightness: 95 },
308
- text: { base: 'surface', lightness: '-52', contrast: 'AAA' },
309
-
310
- 'shadow-sm': { type: 'shadow', bg: 'surface', fg: 'text', intensity: 5 },
311
- 'shadow-md': { type: 'shadow', bg: 'surface', fg: 'text', intensity: 10 },
312
- 'shadow-lg': { type: 'shadow', bg: 'surface', fg: 'text', intensity: 20 },
313
- });
314
- ```
315
-
316
- Shadow colors are included in all output methods (`tokens()`, `tasty()`, `css()`, `json()`) alongside regular colors:
317
-
318
- ```ts
319
- theme.tokens({ format: 'oklch' });
320
- // light: { 'shadow-md': 'oklch(0.15 0.009 282 / 0.1)', ... }
321
- // dark: { 'shadow-md': 'oklch(0.06 0.004 0 / 0.49)', ... }
322
- ```
323
-
324
- ### How Shadows Work
325
-
326
- The shadow algorithm computes a dark, low-saturation pigment color and an alpha value that produces the desired visual intensity:
327
-
328
- 1. **Contrast weight** — when `fg` is provided, shadow strength scales with `|l_bg - l_fg|`. Dark text on a light background produces a strong shadow; near-background-lightness elements produce barely visible shadows.
329
- 2. **Pigment color** — hue blended between fg and bg, low saturation, dark lightness.
330
- 3. **Alpha** — computed via a `tanh` curve that saturates smoothly toward `alphaMax` (default 0.6), ensuring well-separated shadow levels even on dark backgrounds.
331
-
332
- ### Achromatic Shadows
333
-
334
- Omit `fg` for a pure achromatic shadow at full user-specified intensity:
335
-
336
- ```ts
337
- theme.colors({
338
- 'drop-shadow': { type: 'shadow', bg: 'surface', intensity: 12 },
339
- });
340
- ```
341
-
342
- ### High-Contrast Intensity
343
-
344
- `intensity` supports `[normal, highContrast]` pairs:
345
-
346
- ```ts
347
- theme.colors({
348
- 'shadow-card': { type: 'shadow', bg: 'surface', fg: 'text', intensity: [10, 20] },
349
- });
350
- ```
351
-
352
- ### Fixed Opacity (Regular Colors)
353
-
354
- For a simple fixed-alpha color (no shadow algorithm), use `opacity` on a regular color:
355
-
356
- ```ts
357
- theme.colors({
358
- overlay: { lightness: 0, opacity: 0.5 },
359
- });
360
- // → 'oklch(0 0 0 / 0.5)'
361
- ```
362
-
363
- ### Shadow Tuning
364
-
365
- Fine-tune shadow behavior per-color or globally:
366
-
367
- ```ts
368
- // Per-color tuning
369
- theme.colors({
370
- 'shadow-soft': {
371
- type: 'shadow', bg: 'surface', intensity: 10,
372
- tuning: { alphaMax: 0.3, saturationFactor: 0.1 },
373
- },
374
- });
375
-
376
- // Global tuning
377
69
  glaze.configure({
378
- shadowTuning: { alphaMax: 0.5, bgHueBlend: 0.3 },
379
- });
380
- ```
381
-
382
- Available tuning parameters:
383
-
384
- | Parameter | Default | Description |
385
- |---|---|---|
386
- | `saturationFactor` | 0.18 | Fraction of fg saturation kept in pigment |
387
- | `maxSaturation` | 0.25 | Upper clamp on pigment saturation |
388
- | `lightnessFactor` | 0.25 | Multiplier for bg lightness to pigment lightness |
389
- | `lightnessBounds` | [0.05, 0.20] | Clamp range for pigment lightness |
390
- | `minGapTarget` | 0.05 | Target minimum gap between pigment and bg lightness |
391
- | `alphaMax` | 0.6 | Asymptotic maximum alpha |
392
- | `bgHueBlend` | 0.2 | Blend weight pulling pigment hue toward bg hue |
393
-
394
- ### Standalone Shadow Computation
395
-
396
- Compute a shadow outside of a theme:
397
-
398
- ```ts
399
- const v = glaze.shadow({
400
- bg: '#f0eef5',
401
- fg: '#1a1a2e',
402
- intensity: 10,
403
- });
404
- // → { h: 280, s: 0.14, l: 0.2, alpha: 0.1 }
405
-
406
- const css = glaze.format(v, 'oklch');
407
- // → 'oklch(0.15 0.014 280 / 0.1)'
408
- ```
409
-
410
- ### Consuming in CSS
411
-
412
- ```css
413
- .card {
414
- box-shadow: 0 2px 6px var(--shadow-sm-color),
415
- 0 8px 24px var(--shadow-md-color);
416
- }
417
- ```
418
-
419
- ## Mix Colors
420
-
421
- Mix colors blend two existing colors together. Use them for hover overlays, tints, shades, and any derived color that sits between two reference colors.
422
-
423
- ### Opaque Mix
424
-
425
- Produces a solid color by interpolating between `base` and `target`:
426
-
427
- ```ts
428
- theme.colors({
429
- surface: { lightness: 95 },
430
- accent: { lightness: 30 },
431
-
432
- // 30% of the way from surface toward accent
433
- tint: { type: 'mix', base: 'surface', target: 'accent', value: 30 },
70
+ modes: { dark: true, highContrast: true },
434
71
  });
435
- ```
436
-
437
- - `value` — mix ratio 0–100 (0 = pure base, 100 = pure target)
438
- - The result is a fully opaque color (alpha = 1)
439
- - Adapts to light/dark/HC schemes automatically via the resolved base and target
440
-
441
- ### Transparent Mix
442
-
443
- Produces the target color with a controlled opacity — useful for hover overlays:
444
-
445
- ```ts
446
- theme.colors({
447
- surface: { lightness: 95 },
448
- black: { lightness: 0, saturation: 0 },
449
-
450
- hover: {
451
- type: 'mix',
452
- base: 'surface',
453
- target: 'black',
454
- value: 8,
455
- blend: 'transparent',
456
- },
457
- });
458
- // hover → target color (black) with alpha = 0.08
459
- ```
460
-
461
- The output color has `h`, `s`, `l` from the target and `alpha = value / 100`.
462
-
463
- ### Blend Space
464
-
465
- By default, opaque mixing interpolates in OKHSL (perceptually uniform, consistent with Glaze's model). Use `space: 'srgb'` for linear sRGB interpolation, which matches browser compositing:
466
-
467
- ```ts
468
- theme.colors({
469
- surface: { lightness: 95 },
470
- accent: { lightness: 30 },
471
-
472
- // sRGB blend — matches what the browser would render
473
- hover: { type: 'mix', base: 'surface', target: 'accent', value: 20, space: 'srgb' },
474
- });
475
- ```
476
72
 
477
- | Space | Behavior | Best for |
478
- |---|---|---|
479
- | `'okhsl'` (default) | Perceptually uniform OKHSL interpolation | Design token derivation |
480
- | `'srgb'` | Linear sRGB channel interpolation | Matching browser compositing |
481
-
482
- The `space` option only affects opaque blending. Transparent blending always composites in linear sRGB (matching browser alpha compositing).
483
-
484
- ### Contrast Solving
485
-
486
- Mix colors support the same `contrast` prop as regular colors. The solver adjusts the mix ratio (opaque) or opacity (transparent) to meet the WCAG target:
73
+ const theme = glaze(280, 80);
487
74
 
488
- ```ts
489
75
  theme.colors({
490
- surface: { lightness: 95 },
491
- accent: { lightness: 30 },
492
-
493
- // Ensure the mixed color has at least AA contrast against surface
494
- tint: {
495
- type: 'mix',
496
- base: 'surface',
497
- target: 'accent',
498
- value: 10,
499
- contrast: 'AA',
500
- },
501
-
502
- // Ensure the transparent overlay has at least 3:1 contrast
503
- overlay: {
504
- type: 'mix',
76
+ surface: { tone: 97, saturation: 0.15 },
77
+ 'surface-text': {
505
78
  base: 'surface',
506
- target: 'accent',
507
- value: 5,
508
- blend: 'transparent',
509
- contrast: 3,
79
+ tone: '-1',
80
+ saturation: 0.4,
81
+ contrast: { apca: ['content', 'body'] },
510
82
  },
511
- });
512
- ```
513
-
514
- ### High-Contrast Pairs
515
-
516
- Both `value` and `contrast` support `[normal, highContrast]` pairs:
517
-
518
- ```ts
519
- theme.colors({
520
- surface: { lightness: 95 },
521
- accent: { lightness: 30 },
522
-
523
- tint: {
524
- type: 'mix',
83
+ border: {
525
84
  base: 'surface',
526
- target: 'accent',
527
- value: [20, 40], // stronger mix in high-contrast mode
528
- contrast: [3, 'AAA'], // stricter contrast in high-contrast mode
85
+ tone: ['-8', '-16'],
86
+ saturation: 0.2,
87
+ inherit: false,
529
88
  },
530
- });
531
- ```
532
-
533
- ### Achromatic Colors
534
-
535
- When mixing with achromatic colors (saturation near zero, e.g., white or black) in `okhsl` space, the hue comes from whichever color has saturation. This prevents meaningless hue artifacts and matches CSS `color-mix()` "missing component" behavior. For purely achromatic mixes, prefer `space: 'srgb'` where hue is irrelevant.
536
-
537
- ### Mix Chaining
538
-
539
- Mix colors can reference other mix colors, enabling multi-step derivations:
540
-
541
- ```ts
542
- theme.colors({
543
- white: { lightness: 100, saturation: 0 },
544
- black: { lightness: 0, saturation: 0 },
545
- gray: { type: 'mix', base: 'white', target: 'black', value: 50, space: 'srgb' },
546
- lightGray: { type: 'mix', base: 'white', target: 'gray', value: 50, space: 'srgb' },
547
- });
548
- ```
549
-
550
- Mix colors cannot reference shadow colors (same restriction as regular dependent colors).
551
-
552
- ## Output Formats
553
-
554
- Control the color format in exports with the `format` option:
555
-
556
- ```ts
557
- // Default: OKHSL
558
- theme.tokens(); // → 'okhsl(280 60% 97%)'
559
-
560
- // RGB (modern space syntax, rounded integers)
561
- theme.tokens({ format: 'rgb' }); // → 'rgb(244 240 250)'
562
-
563
- // HSL (modern space syntax)
564
- theme.tokens({ format: 'hsl' }); // → 'hsl(270.5 45.2% 95.8%)'
565
-
566
- // OKLCH
567
- theme.tokens({ format: 'oklch' }); // → 'oklch(0.965 0.0123 280)'
568
- ```
569
-
570
- The `format` option works on all export methods: `theme.tokens()`, `theme.tasty()`, `theme.json()`, `theme.css()`, `palette.tokens()`, `palette.tasty()`, `palette.json()`, `palette.css()`, and standalone `glaze.color().token()` / `.tasty()` / `.json()`.
571
-
572
- Colors with `alpha < 1` (shadow colors, or regular colors with `opacity`) include an alpha component:
573
-
574
- ```ts
575
- // → 'oklch(0.15 0.009 282 / 0.1)'
576
- // → 'rgb(34 28 42 / 0.1)'
577
- ```
578
-
579
- Available formats:
580
-
581
- | Format | Output (alpha = 1) | Output (alpha < 1) | Notes |
582
- |---|---|---|---|
583
- | `'okhsl'` (default) | `okhsl(H S% L%)` | `okhsl(H S% L% / A)` | Native format, not a CSS function |
584
- | `'rgb'` | `rgb(R G B)` | `rgb(R G B / A)` | Rounded integers, space syntax |
585
- | `'hsl'` | `hsl(H S% L%)` | `hsl(H S% L% / A)` | Modern space syntax |
586
- | `'oklch'` | `oklch(L C H)` | `oklch(L C H / A)` | OKLab-based LCH |
587
-
588
- All numeric output strips trailing zeros for cleaner CSS (e.g., `95` not `95.0`).
589
-
590
- ## Adaptation Modes
591
-
592
- Modes control how colors adapt across schemes:
593
-
594
- | Mode | Behavior |
595
- |---|---|
596
- | `'auto'` (default) | Full adaptation. Light ↔ dark inversion. High-contrast boost. |
597
- | `'fixed'` | Color stays recognizable. Only safety corrections. For brand buttons, CTAs. |
598
- | `'static'` | No adaptation. Same value in every scheme. |
599
-
600
- ### How Relative Lightness Adapts
601
-
602
- **`auto` mode** — relative lightness sign flips in dark scheme:
603
-
604
- ```ts
605
- // Light: surface L=97, text lightness='-52' → L=45 (dark text on light bg)
606
- // Dark: surface inverts to L≈20 (Möbius curve), sign flips → L=20+52=72
607
- // contrast solver may push further (light text on dark bg)
608
- ```
609
-
610
- **`fixed` mode** — lightness is mapped (not inverted), relative sign preserved:
611
-
612
- ```ts
613
- // Light: accent-fill L=52, accent-text lightness='+48' → L=100 (white on brand)
614
- // Dark: accent-fill maps to L≈51.6, sign preserved → L≈99.6
615
- ```
616
-
617
- **`static` mode** — no adaptation, same value in every scheme.
618
-
619
- ## Light Scheme Mapping
620
-
621
- ### Lightness
622
-
623
- Absolute lightness values (both root colors and dependent colors with absolute lightness) are mapped linearly within the configured `lightLightness` window:
624
-
625
- ```ts
626
- const [lo, hi] = lightLightness; // default: [10, 100]
627
- const mappedL = (lightness * (hi - lo)) / 100 + lo;
628
- ```
629
-
630
- Both `auto` and `fixed` modes use the same linear formula. `static` mode and high-contrast variants bypass the mapping entirely (identity: `mappedL = l`).
631
-
632
- | Color | Raw L | Mapped L (default [10, 100]) |
633
- |---|---|---|
634
- | surface (L=97) | 97 | 97.3 |
635
- | accent-fill (L=52) | 52 | 56.8 |
636
- | near-black (L=0) | 0 | 10 |
637
-
638
- ## Dark Scheme Mapping
639
-
640
- ### Lightness
641
-
642
- **`auto`** — inverted with a Möbius transformation within the configured window:
643
-
644
- ```ts
645
- const [lo, hi] = darkLightness; // default: [15, 95]
646
- const t = (100 - lightness) / 100;
647
- const invertedL = lo + (hi - lo) * t / (t + darkCurve * (1 - t)); // darkCurve default: 0.5
648
- ```
649
-
650
- The `darkCurve` parameter (default `0.5`, range 0–1) controls how much the dark-mode inversion expands lightness deltas. Lower values produce stronger expansion; `1` gives linear (legacy) behavior. Accepts a `[normal, highContrast]` pair for separate HC tuning (e.g. `darkCurve: [0.5, 0.3]`); a single number applies to both. Unlike a power curve, the Möbius transformation provides **proportional expansion** — small and large deltas are scaled by similar ratios, preserving the visual hierarchy of the light theme.
651
-
652
- **`fixed`** — mapped without inversion (not affected by `darkCurve`):
653
-
654
- ```ts
655
- const mappedL = (lightness * (hi - lo)) / 100 + lo;
656
- ```
657
-
658
- | Color | Light L | Auto (curve=0.5) | Auto (curve=1, linear) | Fixed (mapped) |
659
- |---|---|---|---|---|
660
- | surface (L=97) | 97 | 19.7 | 17.4 | 92.6 |
661
- | accent-fill (L=52) | 52 | 66.9 | 53.4 | 56.6 |
662
- | accent-text (L=100) | 100 | 15 | 15 | 95 |
663
-
664
- In high-contrast variants, the `darkLightness` window is bypassed — auto uses the Möbius curve over the full [0, 100] range, and fixed uses identity (`L`). To use a different curve shape for HC, pass a `[normal, hc]` pair to `darkCurve` (e.g. `darkCurve: [0.5, 0.3]`).
665
-
666
- ### Saturation
667
-
668
- `darkDesaturation` reduces saturation for all colors in dark scheme:
669
-
670
- ```ts
671
- S_dark = S_light * (1 - darkDesaturation) // default: 0.1
672
- ```
673
-
674
- ## Inherited Themes (`extend`)
675
-
676
- `extend` creates a new theme inheriting all color definitions, replacing the hue and/or saturation seed:
677
-
678
- ```ts
679
- const primary = glaze(280, 80);
680
- primary.colors({ /* ... */ });
681
-
682
- const danger = primary.extend({ hue: 23 });
683
- const success = primary.extend({ hue: 157 });
684
- const warning = primary.extend({ hue: 84 });
685
- ```
686
-
687
- Override individual colors (additive merge):
688
-
689
- ```ts
690
- const danger = primary.extend({
691
- hue: 23,
692
- colors: { 'accent-fill': { lightness: 48, mode: 'fixed' } },
693
- });
694
- ```
695
-
696
- ## Palette Composition
697
-
698
- Combine multiple themes into a single palette:
699
-
700
- ```ts
701
- const palette = glaze.palette({ primary, danger, success, warning });
702
- ```
703
-
704
- Optionally designate a primary theme at creation time:
705
-
706
- ```ts
707
- const palette = glaze.palette(
708
- { primary, danger, success, warning },
709
- { primary: 'primary' },
710
- );
711
- ```
712
-
713
- ### Prefix Behavior
714
-
715
- Palette export methods (`tokens()`, `tasty()`, `css()`) default to `prefix: true` — all tokens are automatically prefixed with the theme name to avoid collisions:
716
-
717
- ```ts
718
- const tokens = palette.tokens();
719
- // → {
720
- // light: { 'primary-surface': 'okhsl(...)', 'danger-surface': 'okhsl(...)' },
721
- // dark: { 'primary-surface': 'okhsl(...)', 'danger-surface': 'okhsl(...)' },
722
- // }
723
- ```
724
-
725
- Custom prefix mapping:
726
-
727
- ```ts
728
- palette.tokens({ prefix: { primary: 'brand-', danger: 'error-' } });
729
- ```
730
-
731
- To disable prefixing entirely, pass `prefix: false` explicitly.
732
-
733
- ### Collision Detection
734
-
735
- When two themes produce the same output key (via `prefix: false`, custom prefix maps, or primary unprefixed aliases), the first-written value wins and a `console.warn` is emitted:
736
-
737
- ```ts
738
- const palette = glaze.palette({ a, b });
739
- palette.tokens({ prefix: false });
740
- // ⚠ glaze: token "surface" from theme "b" collides with theme "a" — skipping.
741
- ```
742
-
743
- ### Primary Theme
744
-
745
- The primary theme's tokens are duplicated without prefix, providing convenient short aliases alongside the prefixed versions. Set at palette creation to apply to all exports automatically:
746
-
747
- ```ts
748
- const palette = glaze.palette(
749
- { primary, danger, success },
750
- { primary: 'primary' },
751
- );
752
- const tokens = palette.tokens();
753
- // → {
754
- // light: {
755
- // 'primary-surface': 'okhsl(...)', // prefixed (all themes)
756
- // 'danger-surface': 'okhsl(...)',
757
- // 'success-surface': 'okhsl(...)',
758
- // 'surface': 'okhsl(...)', // unprefixed alias (primary only)
759
- // },
760
- // }
761
- ```
762
-
763
- Override or disable per-export:
764
-
765
- ```ts
766
- palette.tokens({ primary: 'danger' }); // use danger as primary for this call
767
- palette.tokens({ primary: false }); // no primary for this call
768
- ```
769
-
770
- The `primary` option works on `tokens()`, `tasty()`, and `css()`. It combines with any prefix mode — when using a custom prefix map, primary tokens are still duplicated without prefix:
771
-
772
- ```ts
773
- palette.tokens({ prefix: { primary: 'p-', danger: 'd-' } });
774
- // → 'p-surface' + 'surface' (alias from palette-level primary) + 'd-surface'
775
- ```
776
-
777
- An error is thrown if the primary name doesn't match any theme in the palette.
778
-
779
- ### Tasty Export (for [Tasty](https://cube-ui-kit.vercel.app/?path=/docs/tasty-documentation--docs) style system)
780
-
781
- The `tasty()` method exports tokens in the [Tasty](https://cube-ui-kit.vercel.app/?path=/docs/tasty-documentation--docs) style-to-state binding format — `#name` color token keys with state aliases (`''`, `@dark`, etc.):
782
-
783
- ```ts
784
- const palette = glaze.palette(
785
- { primary, danger, success },
786
- { primary: 'primary' },
787
- );
788
- const tastyTokens = palette.tasty();
789
- // → {
790
- // '#primary-surface': { '': 'okhsl(...)', '@dark': 'okhsl(...)' },
791
- // '#danger-surface': { '': 'okhsl(...)', '@dark': 'okhsl(...)' },
792
- // '#surface': { '': 'okhsl(...)', '@dark': 'okhsl(...)' }, // alias
793
- // }
794
- ```
795
-
796
- Apply as global styles to make color tokens available app-wide:
797
-
798
- ```ts
799
- import { useGlobalStyles } from '@cube-dev/ui-kit';
800
-
801
- // In your root component
802
- useGlobalStyles('body', tastyTokens);
803
- ```
804
-
805
- For zero-runtime builds, use `tastyStatic` to generate the CSS at build time:
806
-
807
- ```ts
808
- import { tastyStatic } from '@cube-dev/ui-kit';
809
-
810
- tastyStatic('body', tastyTokens);
811
- ```
812
-
813
- Alternatively, register as a recipe via `configure()`:
814
-
815
- ```ts
816
- import { configure, tasty } from '@cube-dev/ui-kit';
817
-
818
- configure({
819
- recipes: {
820
- 'all-themes': tastyTokens,
821
- },
822
- });
823
-
824
- const Page = tasty({
825
- styles: {
826
- recipe: 'all-themes',
827
- fill: '#primary-surface',
828
- color: '#primary-text',
89
+ 'accent-surface-text': { tone: 100, mode: 'fixed' },
90
+ 'accent-surface': {
91
+ base: 'accent-surface-text',
92
+ tone: '-1',
93
+ contrast: 'AA',
94
+ mode: 'fixed',
829
95
  },
830
96
  });
831
- ```
832
97
 
833
- Or spread directly into component styles:
98
+ const danger = theme.extend({ hue: 23 });
99
+ const palette = glaze.palette({ default: theme, danger });
834
100
 
835
- ```ts
836
- const Card = tasty({
837
- styles: {
838
- ...tastyTokens,
839
- fill: '#primary-surface',
840
- color: '#primary-text',
841
- },
101
+ const tokens = palette.tokens({
102
+ prefix: { default: '', danger: 'danger-' },
842
103
  });
843
- ```
844
-
845
- Custom prefix mapping:
846
-
847
- ```ts
848
- palette.tasty({ prefix: { primary: 'brand-', danger: 'error-' } });
849
- ```
850
-
851
- Custom state aliases:
852
-
853
- ```ts
854
- palette.tasty({ states: { dark: '@dark', highContrast: '@hc' } });
855
- ```
856
-
857
- ### JSON Export (Framework-Agnostic)
858
-
859
- JSON export groups by theme name (no prefix needed):
860
-
861
- ```ts
862
- const data = palette.json();
863
104
  // → {
864
- // primary: { surface: { light: 'okhsl(...)', dark: 'okhsl(...)' } },
865
- // danger: { surface: { light: 'okhsl(...)', dark: 'okhsl(...)' } },
105
+ // light: { surface: 'oklch(...)', 'danger-surface': 'oklch(...)', ... },
106
+ // dark: { ... },
107
+ // lightContrast: { ... },
108
+ // darkContrast: { ... },
866
109
  // }
867
110
  ```
868
111
 
869
- ### CSS Export
870
-
871
- Export as CSS custom property declarations, grouped by scheme variant. Each variant is a string of `--name-color: value;` lines that you can wrap in your own selectors and media queries.
872
-
873
- ```ts
874
- const css = theme.css();
875
- // css.light → "--surface-color: rgb(...);\n--text-color: rgb(...);"
876
- // css.dark → "--surface-color: rgb(...);\n--text-color: rgb(...);"
877
- // css.lightContrast → "--surface-color: rgb(...);\n--text-color: rgb(...);"
878
- // css.darkContrast → "--surface-color: rgb(...);\n--text-color: rgb(...);"
879
- ```
880
-
881
- Use in a stylesheet:
882
-
883
- ```ts
884
- const palette = glaze.palette(
885
- { primary, danger, success },
886
- { primary: 'primary' },
887
- );
888
- const css = palette.css();
889
-
890
- const stylesheet = `
891
- :root { ${css.light} }
892
- @media (prefers-color-scheme: dark) {
893
- :root { ${css.dark} }
894
- }
895
- `;
896
- ```
897
-
898
- Options:
899
-
900
- | Option | Default | Description |
901
- |---|---|---|
902
- | `format` | `'rgb'` | Color format (`'rgb'`, `'hsl'`, `'okhsl'`, `'oklch'`) |
903
- | `suffix` | `'-color'` | Suffix appended to each CSS property name |
904
- | `prefix` | `true` (palette) | (palette only) `true` uses `"<themeName>-"`, or provide a custom map |
905
- | `primary` | inherited | (palette only) Override or disable (`false`) the palette-level primary for this call |
906
-
907
- ```ts
908
- // Custom suffix
909
- theme.css({ suffix: '' });
910
- // → "--surface: rgb(...);"
911
-
912
- // Custom format
913
- theme.css({ format: 'hsl' });
914
- // → "--surface-color: hsl(...);"
915
-
916
- // Palette with primary (inherited from palette creation)
917
- palette.css();
918
- // → "--primary-surface-color: rgb(...);\n--surface-color: rgb(...);\n--danger-surface-color: rgb(...);"
919
- ```
920
-
921
- ## Output Modes
922
-
923
- Control which scheme variants appear in exports:
924
-
925
- ```ts
926
- // Light only
927
- palette.tokens({ modes: { dark: false, highContrast: false } });
928
- // → { light: { ... } }
929
-
930
- // Light + dark (default)
931
- palette.tokens({ modes: { highContrast: false } });
932
- // → { light: { ... }, dark: { ... } }
933
-
934
- // All four variants
935
- palette.tokens({ modes: { dark: true, highContrast: true } });
936
- // → { light: { ... }, dark: { ... }, lightContrast: { ... }, darkContrast: { ... } }
937
- ```
938
-
939
- The `modes` option works the same way on `tokens()`, `tasty()`, `json()`, and `css()`.
940
-
941
- Resolution priority (highest first):
942
-
943
- 1. `tokens({ modes })` / `tasty({ modes })` / `json({ modes })` / `css({ ... })` — per-call override
944
- 2. `glaze.configure({ modes })` — global config
945
- 3. Built-in default: `{ dark: true, highContrast: false }`
946
-
947
- ## Configuration
948
-
949
- ```ts
950
- glaze.configure({
951
- lightLightness: [10, 100], // Light scheme lightness window [lo, hi] (bypassed in HC)
952
- darkLightness: [15, 95], // Dark scheme lightness window [lo, hi] (bypassed in HC)
953
- darkDesaturation: 0.1, // Saturation reduction in dark scheme (0–1)
954
- darkCurve: 0.5, // Möbius beta for dark auto-inversion (0–1); or [normal, hc] pair
955
- states: {
956
- dark: '@dark', // State alias for dark mode tokens
957
- highContrast: '@high-contrast',
958
- },
959
- modes: {
960
- dark: true, // Include dark variants in exports
961
- highContrast: false, // Include high-contrast variants
962
- },
963
- shadowTuning: { // Default tuning for all shadow colors
964
- alphaMax: 0.6,
965
- bgHueBlend: 0.2,
966
- },
967
- });
968
- ```
969
-
970
- ## Color Definition Shape
971
-
972
- `ColorDef` is a discriminated union of regular colors, shadow colors, and mix colors:
973
-
974
- ```ts
975
- type ColorDef = RegularColorDef | ShadowColorDef | MixColorDef;
976
-
977
- interface RegularColorDef {
978
- lightness?: HCPair<number | RelativeValue>;
979
- saturation?: number;
980
- hue?: number | RelativeValue;
981
- base?: string;
982
- contrast?: HCPair<MinContrast>;
983
- mode?: 'auto' | 'fixed' | 'static';
984
- opacity?: number; // fixed alpha (0–1)
985
- }
986
-
987
- interface ShadowColorDef {
988
- type: 'shadow';
989
- bg: string; // background color name (non-shadow)
990
- fg?: string; // foreground color name (non-shadow)
991
- intensity: HCPair<number>; // 0–100
992
- tuning?: ShadowTuning;
993
- }
994
-
995
- interface MixColorDef {
996
- type: 'mix';
997
- base: string; // "from" color name
998
- target: string; // "to" color name
999
- value: HCPair<number>; // 0–100 (mix ratio or opacity)
1000
- blend?: 'opaque' | 'transparent'; // default: 'opaque'
1001
- space?: 'okhsl' | 'srgb'; // default: 'okhsl'
1002
- contrast?: HCPair<MinContrast>;
1003
- }
1004
- ```
1005
-
1006
- A root color must have absolute `lightness` (a number). A dependent color must have `base`. Relative `lightness` (a string) requires `base`. Shadow colors use `type: 'shadow'` and must reference a non-shadow `bg` color. Mix colors use `type: 'mix'` and must reference two non-shadow colors.
1007
-
1008
- ## Validation
1009
-
1010
- | Condition | Behavior |
1011
- |---|---|
1012
- | `contrast` without `base` | Validation error |
1013
- | Relative `lightness` without `base` | Validation error |
1014
- | `lightness` resolves outside 0–100 | Clamp silently |
1015
- | `saturation` outside 0–1 | Clamp silently |
1016
- | Circular `base` references | Validation error |
1017
- | `base` references non-existent name | Validation error |
1018
- | Shadow `bg` references non-existent color | Validation error |
1019
- | Shadow `fg` references non-existent color | Validation error |
1020
- | Shadow `bg` references another shadow color | Validation error |
1021
- | Shadow `fg` references another shadow color | Validation error |
1022
- | Regular color `base` references a shadow color | Validation error |
1023
- | Shadow `intensity` outside 0–100 | Clamp silently |
1024
- | `contrast` + `opacity` combined | Warning |
1025
- | Mix `base` references non-existent color | Validation error |
1026
- | Mix `target` references non-existent color | Validation error |
1027
- | Mix `base` references a shadow color | Validation error |
1028
- | Mix `target` references a shadow color | Validation error |
1029
- | Mix `value` outside 0–100 | Clamp silently |
1030
- | Circular references involving mix colors | Validation error |
1031
-
1032
- ## Advanced: Color Math Utilities
1033
-
1034
- Glaze re-exports its internal color math for advanced use:
1035
-
1036
- ```ts
1037
- import {
1038
- okhslToLinearSrgb,
1039
- okhslToSrgb,
1040
- okhslToOklab,
1041
- srgbToOkhsl,
1042
- parseHex,
1043
- relativeLuminanceFromLinearRgb,
1044
- contrastRatioFromLuminance,
1045
- formatOkhsl,
1046
- formatRgb,
1047
- formatHsl,
1048
- formatOklch,
1049
- findLightnessForContrast,
1050
- resolveMinContrast,
1051
- } from '@tenphi/glaze';
1052
- ```
1053
-
1054
- ## Full Example
1055
-
1056
- ```ts
1057
- import { glaze } from '@tenphi/glaze';
1058
-
1059
- const primary = glaze(280, 80);
1060
-
1061
- primary.colors({
1062
- surface: { lightness: 97, saturation: 0.75 },
1063
- text: { base: 'surface', lightness: '-52', contrast: 'AAA' },
1064
- border: { base: 'surface', lightness: ['-7', '-20'], contrast: 'AA-large' },
1065
- bg: { lightness: 97, saturation: 0.75 },
1066
- icon: { lightness: 60, saturation: 0.94 },
1067
- 'accent-fill': { lightness: 52, mode: 'fixed' },
1068
- 'accent-text': { base: 'accent-fill', lightness: '+48', contrast: 'AA', mode: 'fixed' },
1069
- disabled: { lightness: 81, saturation: 0.4 },
1070
-
1071
- // Shadow colors — computed alpha, automatic dark-mode adaptation
1072
- 'shadow-sm': { type: 'shadow', bg: 'surface', fg: 'text', intensity: 5 },
1073
- 'shadow-md': { type: 'shadow', bg: 'surface', fg: 'text', intensity: 10 },
1074
- 'shadow-lg': { type: 'shadow', bg: 'surface', fg: 'text', intensity: 20 },
1075
-
1076
- // Mix colors — hover overlays and tints
1077
- 'hover': { type: 'mix', base: 'surface', target: 'accent-fill', value: 8, blend: 'transparent' },
1078
- 'tint': { type: 'mix', base: 'surface', target: 'accent-fill', value: 20 },
1079
-
1080
- // Fixed-alpha overlay
1081
- overlay: { lightness: 0, opacity: 0.5 },
1082
- });
1083
-
1084
- const danger = primary.extend({ hue: 23 });
1085
- const success = primary.extend({ hue: 157 });
1086
- const warning = primary.extend({ hue: 84 });
1087
- const note = primary.extend({ hue: 302 });
1088
-
1089
- const palette = glaze.palette(
1090
- { primary, danger, success, warning, note },
1091
- { primary: 'primary' },
1092
- );
1093
-
1094
- // Export as flat token map grouped by variant (prefix defaults to true)
1095
- const tokens = palette.tokens();
1096
- // tokens.light → { 'primary-surface': '...', 'surface': '...', 'danger-surface': '...' }
1097
-
1098
- // Export as tasty style-to-state bindings (for Tasty style system)
1099
- const tastyTokens = palette.tasty();
1100
-
1101
- // Export as CSS custom properties (rgb format by default)
1102
- const css = palette.css();
1103
- // css.light → "--primary-surface-color: rgb(...);\n--surface-color: rgb(...);\n--danger-surface-color: rgb(...);"
1104
-
1105
- // Standalone shadow computation
1106
- const v = glaze.shadow({ bg: '#f0eef5', fg: '#1a1a2e', intensity: 10 });
1107
- const shadowCss = glaze.format(v, 'oklch');
1108
- // → 'oklch(0.15 0.014 280 / 0.1)'
1109
-
1110
- // Save and restore a theme
1111
- const snapshot = primary.export();
1112
- const restored = glaze.from(snapshot);
1113
-
1114
- // Create from an existing brand color
1115
- const brand = glaze.fromHex('#7a4dbf');
1116
- brand.colors({ surface: { lightness: 97 }, text: { base: 'surface', lightness: '-52' } });
1117
- ```
1118
-
1119
- ## API Reference
1120
-
1121
- ### Theme Creation
1122
-
1123
- | Method | Description |
1124
- |---|---|
1125
- | `glaze(hue, saturation?)` | Create a theme from hue (0–360) and saturation (0–100) |
1126
- | `glaze({ hue, saturation })` | Create a theme from an options object |
1127
- | `glaze.from(data)` | Create a theme from an exported configuration |
1128
- | `glaze.fromHex(hex)` | Create a theme from a hex color (`#rgb` or `#rrggbb`) |
1129
- | `glaze.fromRgb(r, g, b)` | Create a theme from RGB values (0–255) |
1130
- | `glaze.color(input)` | Create a standalone color token |
1131
- | `glaze.shadow(input)` | Compute a standalone shadow color (returns `ResolvedColorVariant`) |
1132
- | `glaze.format(variant, format?)` | Format any `ResolvedColorVariant` as a CSS string |
1133
-
1134
- ### Theme Methods
1135
-
1136
- | Method | Description |
1137
- |---|---|
1138
- | `theme.colors(defs)` | Add/replace colors (additive merge) |
1139
- | `theme.color(name)` | Get a color definition |
1140
- | `theme.color(name, def)` | Set a single color definition |
1141
- | `theme.remove(names)` | Remove one or more colors |
1142
- | `theme.has(name)` | Check if a color is defined |
1143
- | `theme.list()` | List all defined color names |
1144
- | `theme.reset()` | Clear all color definitions |
1145
- | `theme.export()` | Export configuration as JSON-safe object |
1146
- | `theme.extend(options)` | Create a child theme |
1147
- | `theme.resolve()` | Resolve all colors |
1148
- | `theme.tokens(options?)` | Export as flat token map grouped by variant |
1149
- | `theme.tasty(options?)` | Export as [Tasty](https://cube-ui-kit.vercel.app/?path=/docs/tasty-documentation--docs) style-to-state bindings |
1150
- | `theme.json(options?)` | Export as plain JSON |
1151
- | `theme.css(options?)` | Export as CSS custom property declarations |
1152
-
1153
- ### Global Configuration
1154
-
1155
- | Method | Description |
1156
- |---|---|
1157
- | `glaze.configure(config)` | Set global configuration |
1158
- | `glaze.palette(themes, options?)` | Compose themes into a palette (options: `{ primary? }`) |
1159
- | `glaze.getConfig()` | Get current global config |
1160
- | `glaze.resetConfig()` | Reset to defaults |
112
+ The accent fill is solved against its white label, not the reverse: the fill
113
+ darkens until the pair meets `'AA'`, or `'AAA'` in high contrast, where a bare
114
+ `'AA'` rises a tier.
115
+
116
+ ## Concepts at a glance
117
+
118
+ 1. **A theme has one hue/saturation seed.** Create status themes with
119
+ `extend()` so they inherit the same relationships while changing hue.
120
+ 2. **A color is a root or a dependent.** Roots use an absolute `tone` or
121
+ `'max'`/`'min'`. Dependent colors name a `base` and may use a signed
122
+ **tone delta** such as `'-8'` plus a `contrast` floor.
123
+ 3. **Tone is an authoring axis, not a contrast guarantee.** Equal tone deltas
124
+ are exact WCAG steps for neutrals. Chromatic colors can drift in rendered
125
+ luminance, so Glaze measures contrast floors against the resolved colors.
126
+ 4. **`contrast` is a floor.** A bare number or preset means WCAG;
127
+ `{ wcag }` and `{ apca }` select the metric explicitly. The solver keeps
128
+ the requested tone whenever it already clears the floor with a small
129
+ margin (1% over a WCAG ratio, 0.5 Lc over an APCA target).
130
+ 5. **Each color chooses its dark adaptation.** `mode: 'auto'` uses dark tone
131
+ inversion (`100 - t`), `fixed` keeps the authored side of the tone scale,
132
+ and `static` skips scheme adaptation.
133
+ 6. **Tone windows bound ordinary schemes.** `lightTone` and `darkTone`
134
+ configure the light and dark tone windows. High-contrast variants use the
135
+ full range. Values that accept `[normal, highContrast]` pairs can tighten
136
+ deliberately in HC.
137
+
138
+ In Glaze, a **scheme variant** is one of `light`, `dark`, `lightContrast`, or
139
+ `darkContrast`. Export `modes` choose which variants are included; [Tasty](https://tasty.style)
140
+ `states` choose how those variants are activated in an application.
141
+
142
+ ## Choosing an output
143
+
144
+ - `tasty()` returns [Tasty](https://tasty.style) `#token` bindings, including its custom `okhsl()` or
145
+ `okhst()` serialization.
146
+ - `tokens()` and `json()` return JavaScript data and default to native
147
+ `oklch()` values.
148
+ - `css()` returns custom-property declarations.
149
+ - `dtcg()` / `dtcgResolver()` target design-token tooling.
150
+ - `tailwind()` emits a Tailwind CSS v4 theme.
151
+
152
+ ## Documentation
153
+
154
+ The full documentation, with live examples that follow your light / dark and
155
+ contrast preferences, is at [glaze.tenphi.me](https://glaze.tenphi.me). The
156
+ same pages live in [`docs/`](docs):
157
+
158
+ - [Getting started](docs/getting-started.mdx) — install, build a first theme,
159
+ and export it.
160
+ - Concepts: [light, dark, and high contrast](docs/schemes.mdx),
161
+ [contrast solving](docs/contrast.mdx),
162
+ [shadows and glows](docs/shadows-and-glows.mdx),
163
+ [mixes and transparency](docs/mixes.mdx), and the color model under them,
164
+ [tone and OKHST](docs/okhst.mdx).
165
+ - Guides: [designing a palette](docs/methodology.mdx),
166
+ [exporting and integration](docs/exporting.mdx), and
167
+ [migration and upgrading](docs/migration.md) (including Glaze 2 → 3).
168
+ - The [API reference](docs/reference/index.md) for every method, option, and
169
+ type.
170
+ - Explore the tone axis in the [interactive playground](https://glaze.tenphi.me/playground/),
171
+ or read the [full OKHST specification](https://github.com/tenphi/okhst) for
172
+ its math.
173
+ - [`AGENTS.md`](https://github.com/tenphi/glaze/blob/main/AGENTS.md) — source-tree orientation for contributors.
1161
174
 
1162
175
  ## License
1163
176
 
1164
- [MIT](LICENSE)
177
+ [MIT](https://github.com/tenphi/glaze/blob/main/LICENSE)