@tenphi/cookbook 0.15.0 → 0.17.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 +25 -0
- package/dist/config.d.ts +2 -2
- package/dist/index.d.ts +2 -2
- package/docs/ai-agents.md +61 -0
- package/docs/architecture.md +91 -0
- package/docs/authoring.mdx +86 -0
- package/docs/cli.md +88 -0
- package/docs/configuration.md +587 -0
- package/docs/content-sources.md +178 -0
- package/docs/customization-rules.md +154 -0
- package/docs/deployment.md +95 -0
- package/docs/examples.md +101 -0
- package/docs/getting-started.md +134 -0
- package/docs/index.md +74 -0
- package/docs/migration.md +36 -0
- package/docs/starlight-comparison.md +124 -0
- package/docs/theme-and-components.md +745 -0
- package/docs/upstream/glaze/LICENSE +21 -0
- package/docs/upstream/glaze/README.md +156 -0
- package/docs/upstream/glaze/docs/api.md +2021 -0
- package/docs/upstream/glaze/docs/methodology.md +686 -0
- package/docs/upstream/glaze/docs/migration.md +351 -0
- package/docs/upstream/glaze/docs/okhst.md +207 -0
- package/docs/upstream/manifest.json +18 -0
- package/docs/upstream/tasty/LICENSE +21 -0
- package/docs/upstream/tasty/README.md +685 -0
- package/docs/upstream/tasty/docs/README.md +39 -0
- package/docs/upstream/tasty/docs/adoption.md +323 -0
- package/docs/upstream/tasty/docs/ai-agents.md +229 -0
- package/docs/upstream/tasty/docs/comparison.md +448 -0
- package/docs/upstream/tasty/docs/configuration.md +823 -0
- package/docs/upstream/tasty/docs/debug.md +335 -0
- package/docs/upstream/tasty/docs/design-system.md +455 -0
- package/docs/upstream/tasty/docs/dsl.md +1021 -0
- package/docs/upstream/tasty/docs/getting-started.md +238 -0
- package/docs/upstream/tasty/docs/injector.md +634 -0
- package/docs/upstream/tasty/docs/methodology.md +648 -0
- package/docs/upstream/tasty/docs/migration-v3.md +285 -0
- package/docs/upstream/tasty/docs/pipeline.md +749 -0
- package/docs/upstream/tasty/docs/plugins.md +353 -0
- package/docs/upstream/tasty/docs/react-api.md +681 -0
- package/docs/upstream/tasty/docs/runtime-benchmarks.md +351 -0
- package/docs/upstream/tasty/docs/ssr.md +610 -0
- package/docs/upstream/tasty/docs/styles.md +677 -0
- package/docs/upstream/tasty/docs/tasty-static.md +582 -0
- package/package.json +12 -7
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
# Migration & Integration
|
|
2
|
+
|
|
3
|
+
How to move an existing CSS, design-token, or application color system to
|
|
4
|
+
Glaze, then export the resulting palette in the shape your app and design tools
|
|
5
|
+
consume.
|
|
6
|
+
|
|
7
|
+
If you're starting from scratch, see [methodology.md](methodology.md) first — that's about *designing* the palette. This doc is about *consuming* it.
|
|
8
|
+
|
|
9
|
+
## Contents
|
|
10
|
+
|
|
11
|
+
* [Choosing an export](#choosing-an-export)
|
|
12
|
+
* [Wiring exports into the app](#wiring-exports-into-the-app)
|
|
13
|
+
* [Prefix map strategies](#prefix-map-strategies)
|
|
14
|
+
* [Migrating an existing color system](#migrating-from-an-existing-color-system)
|
|
15
|
+
* [Upgrading Glaze](#upgrading-glaze)
|
|
16
|
+
* [Common pitfalls](#common-pitfalls)
|
|
17
|
+
|
|
18
|
+
## Choosing an export
|
|
19
|
+
|
|
20
|
+
Glaze has two layers of “export”:
|
|
21
|
+
|
|
22
|
+
1. **Authoring snapshots** — `theme.export(override?)` / `token.export(override?)` / `palette.export(override?)`, restored with `glaze.themeFrom` / `colorFrom` / `paletteFrom`. These carry definitions, relations, and a config freeze taken at export time (`kind` + `version`). Live instances keep only a sparse local override; omitted global fields track `configure()` until export.
|
|
23
|
+
2. **Resolved output** — the seven shapes below. These are color strings / design-token documents for apps and tools, **not** restorable as authoring config.
|
|
24
|
+
|
|
25
|
+
Glaze emits the same resolved colors in seven shapes. Pick one based on your
|
|
26
|
+
renderer or tooling.
|
|
27
|
+
|
|
28
|
+
| Method | Output shape | Use it for |
|
|
29
|
+
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
30
|
+
| `palette.tasty(options?)` | `{ '#name': { '': value, '@media(prefers-color-scheme: dark)': value, '@media(prefers-contrast: more)': value } }` | The [Tasty](../../tasty/README.md) style system. Single object, state aliases keyed inside each token. |
|
|
31
|
+
| `palette.tokens(options?)` | `{ light: { name: value }, dark: { name: value }, ... }` | Most CSS-in-JS systems. Per-variant flat maps, easy to feed into a `:root { ... }` selector via your framework's globals. |
|
|
32
|
+
| `palette.css(options?)` | `{ light: '--name-color: rgb(...);', dark: '...', ... }` | Framework-free CSS / static stylesheets. Variant-grouped CSS custom property strings ready to wrap in `:root` and `prefers-color-scheme` queries. |
|
|
33
|
+
| `palette.json(options?)` | `{ themeName: { name: { light, dark, ... } } }` | Tooling, JSON pipelines. |
|
|
34
|
+
| `palette.dtcg(options?)` | `{ light: { name: { $type, $value } }, dark: { ... }, ... }` | W3C [DTCG 2025.10](https://www.designtokens.org/) `.tokens.json` — Figma, Tokens Studio, Style Dictionary, Terrazzo, Penpot. One document per scheme. |
|
|
35
|
+
| `palette.dtcgResolver(options?)` | `{ version, sets, modifiers, resolutionOrder }` | W3C DTCG **Resolver-Module** — a single document describing every scheme variant as `sets` + a `scheme` modifier with a context per variant. For resolver tools such as Dispersa. |
|
|
36
|
+
| `palette.tailwind(options?)` | `'@theme { --color-*: ... } .dark { ... } ...'` | Tailwind CSS v4. A single ready-to-paste `@theme` block plus dark / high-contrast overrides. |
|
|
37
|
+
|
|
38
|
+
`tasty()`, `tokens()`, `json()`, `dtcg()`, `dtcgResolver()`, and `tailwind()` accept `modes` (`{ dark, highContrast }`). `css()` always returns all four strings (`light`, `dark`, `lightContrast`, `darkContrast`). CSS-string exports accept `format` and default to `'oklch'` (`tokens`/`json`/`css`/`tailwind`/`tasty`; `'rgb'` and `'hsl'` also available). `'okhsl'` and `'okhst'` are supported only on [Tasty](../../tasty/README.md)-shaped exports (`tasty()`, standalone `token()` / `.tasty()`). `dtcg()` and `dtcgResolver()` ignore `format` and use `colorSpace` instead (`'srgb'` default, `'oklch'` opt-in). See [api.md → Palette](api.md#palette) for full options.
|
|
39
|
+
|
|
40
|
+
## Wiring exports into the app
|
|
41
|
+
|
|
42
|
+
### [Tasty](../../tasty/README.md)
|
|
43
|
+
|
|
44
|
+
Spread the result of `palette.tasty()` into a global style call:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import type { Styles } from '@tenphi/tasty';
|
|
48
|
+
import { useGlobalStyles } from '@tenphi/tasty';
|
|
49
|
+
import { tastyStatic } from '@tenphi/tasty/static';
|
|
50
|
+
|
|
51
|
+
export const PALETTE_TOKENS = palette.tasty({
|
|
52
|
+
/* prefix map */
|
|
53
|
+
}) as Styles;
|
|
54
|
+
|
|
55
|
+
// In your root component:
|
|
56
|
+
useGlobalStyles('body', PALETTE_TOKENS);
|
|
57
|
+
|
|
58
|
+
// Or, for zero-runtime builds:
|
|
59
|
+
tastyStatic('body', PALETTE_TOKENS);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
By default the dark / high-contrast variants are keyed by media-query states — `'@media(prefers-color-scheme: dark)'` and `'@media(prefers-contrast: more)'` — so the tokens react to the OS preference out of the box, with no extra [Tasty](../../tasty/README.md) setup.
|
|
63
|
+
|
|
64
|
+
If you'd rather drive the schemes from custom aliases (e.g. a manual toggle that also falls back to the OS preference), set your own [`glaze.configure({ states })`](api.md#configuration) and register what those states *mean*:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { setGlobalPredefinedStates } from '@tenphi/tasty';
|
|
68
|
+
|
|
69
|
+
// glaze.configure({ states: { dark: '@dark', highContrast: '@hc' } });
|
|
70
|
+
setGlobalPredefinedStates({
|
|
71
|
+
'@dark':
|
|
72
|
+
'@root(schema=dark) | (!@root(schema) & @media(prefers-color-scheme: dark))',
|
|
73
|
+
'@hc':
|
|
74
|
+
'@root(contrast=high) | (!@root(contrast) & @media(prefers-contrast: more))',
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The state names here must match the `states` you set in [`glaze.configure({ states })`](api.md#configuration).
|
|
79
|
+
|
|
80
|
+
You can also register the tokens as a [Tasty](../../tasty/README.md) recipe instead of spreading them globally:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { configure, tasty } from '@tenphi/tasty';
|
|
84
|
+
|
|
85
|
+
configure({ recipes: { 'theme-tokens': PALETTE_TOKENS } });
|
|
86
|
+
|
|
87
|
+
const Page = tasty({
|
|
88
|
+
styles: { recipe: 'theme-tokens', fill: '#surface', color: '#surface-text' },
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### CSS custom properties
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
const css = palette.css();
|
|
96
|
+
const stylesheet = `
|
|
97
|
+
:root { ${css.light} }
|
|
98
|
+
@media (prefers-color-scheme: dark) { :root { ${css.dark} } }
|
|
99
|
+
@media (prefers-contrast: more) { :root { ${css.lightContrast} } }
|
|
100
|
+
@media (prefers-color-scheme: dark) and (prefers-contrast: more) {
|
|
101
|
+
:root { ${css.darkContrast} }
|
|
102
|
+
}
|
|
103
|
+
`;
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Each property name is `--<prefix><name>-color` by default. Override the suffix:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
palette.css({ suffix: '' }); // → '--surface: rgb(...);'
|
|
110
|
+
palette.css({ format: 'oklch' }); // → '--surface-color: oklch(...);'
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Framework-agnostic JSON
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
const data = palette.json();
|
|
117
|
+
// → { primary: { surface: { light: 'oklch(...)', dark: 'oklch(...)' } }, ... }
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Feed into your tooling pipeline. Each color is grouped by theme name, then by token name, then by variant — no prefix logic to undo.
|
|
121
|
+
|
|
122
|
+
### W3C DTCG (`.tokens.json`)
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import { writeFileSync } from 'node:fs';
|
|
126
|
+
const dtcg = palette.dtcg();
|
|
127
|
+
|
|
128
|
+
writeFileSync('tokens.light.tokens.json', JSON.stringify(dtcg.light, null, 2));
|
|
129
|
+
if (dtcg.dark) {
|
|
130
|
+
writeFileSync('tokens.dark.tokens.json', JSON.stringify(dtcg.dark, null, 2));
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Each document is a spec-conformant token tree. One file per scheme is the most tool-compatible convention — Style Dictionary treats them as themes, Tokens Studio as sets, and Figma as variable modes. Use `colorSpace: 'oklch'` for wide-gamut, Glaze-native values (no `hex`); the default `'srgb'` emits components plus a `hex` hint that every reader understands. Feed the files straight into Style Dictionary v4+, Tokens Studio, or any DTCG-compatible tool — no Glaze-specific transform needed.
|
|
135
|
+
|
|
136
|
+
### W3C DTCG Resolver-Module (single document)
|
|
137
|
+
|
|
138
|
+
When you want **one file** describing every scheme variant — for a resolver tool such as [Dispersa](https://github.com/dispersa-core/dispersa) — use `dtcgResolver()` instead of `dtcg()`:
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
import { writeFileSync } from 'node:fs';
|
|
142
|
+
const resolver = palette.dtcgResolver({ modes: { highContrast: true } });
|
|
143
|
+
|
|
144
|
+
writeFileSync('resolver.json', JSON.stringify(resolver, null, 2));
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
The document places the light tokens in `sets.base.sources[0]` (the default context) and emits a single `scheme` modifier with a context per variant (`light` / `dark` / `lightContrast` / `darkContrast`). Each non-default context holds that variant's exact resolved tokens — Glaze resolves `darkContrast` independently, so the four-context shape keeps every value correct (two independent modifiers would compose additively and produce wrong dark + high-contrast values). Rename the set, modifier, or contexts via `setName` / `modifierName` / `contextNames` if your resolver expects different labels. Prefer `dtcg()` when you need maximum per-file tool compatibility; prefer `dtcgResolver()` when a resolver tool consumes the document for you.
|
|
148
|
+
|
|
149
|
+
### Tailwind CSS v4
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
const css = palette.tailwind();
|
|
153
|
+
// Write to your CSS entry, or paste into a `@import "tailwindcss"` stylesheet:
|
|
154
|
+
// @theme { --color-primary-surface: oklch(...); ... }
|
|
155
|
+
// .dark { --color-primary-surface: oklch(...); ... }
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
The `--color-*` namespace makes every color available as `bg-*` / `text-*` / `border-*`. Drive dark mode from the OS preference instead of a class with `darkSelector: '@media (prefers-color-scheme: dark)'` (it nests `:root` automatically). High-contrast overrides land under `.high-contrast` and `.dark.high-contrast` by default; both are omitted unless `modes.highContrast` is enabled.
|
|
159
|
+
|
|
160
|
+
## Prefix map strategies
|
|
161
|
+
|
|
162
|
+
`palette.tokens()` / `tasty()` / `css()` / `dtcg()` / `tailwind()` accept a `prefix` option:
|
|
163
|
+
|
|
164
|
+
| Value | Result |
|
|
165
|
+
| ------------------------ | -------------------------------------------------------------------------- |
|
|
166
|
+
| `true` (default) | Every theme prefixes its tokens with `<themeName>-`. |
|
|
167
|
+
| `false` | No prefixes. Colliding keys produce a `console.warn`; first-write wins. |
|
|
168
|
+
| `Record<string, string>` | Per-theme prefix overrides. Themes not listed fall back to `<themeName>-`. |
|
|
169
|
+
|
|
170
|
+
The most common production pattern: **default theme unprefixed, every other theme prefixed with its name**:
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
palette.tasty({
|
|
174
|
+
prefix: {
|
|
175
|
+
default: '',
|
|
176
|
+
primary: 'primary-',
|
|
177
|
+
success: 'success-',
|
|
178
|
+
danger: 'danger-',
|
|
179
|
+
warning: 'warning-',
|
|
180
|
+
note: 'note-',
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
This makes neutral tokens consume as `#surface`, `#border`, `#disabled-surface` (no theme namespace) while status colors live under `#danger-surface`, `#success-accent-text`, etc.
|
|
186
|
+
|
|
187
|
+
This explicit map is usually clearer for a neutral `default` theme. The
|
|
188
|
+
separate `primary` palette option below solves a different namespace problem:
|
|
189
|
+
it duplicates one named theme without a prefix while retaining that theme's
|
|
190
|
+
prefixed tokens.
|
|
191
|
+
|
|
192
|
+
### Alias themes for legacy names
|
|
193
|
+
|
|
194
|
+
Two aliases for the same theme instance produce identical token values under different prefixes — useful when you want to support a legacy token name without duplicating definitions:
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
const palette = glaze.palette({
|
|
198
|
+
default: defaultTheme,
|
|
199
|
+
primary: primaryTheme,
|
|
200
|
+
purple: primaryTheme, // legacy alias — same theme, different prefix
|
|
201
|
+
// ...
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
palette.tasty({
|
|
205
|
+
prefix: {
|
|
206
|
+
default: '',
|
|
207
|
+
primary: 'primary-',
|
|
208
|
+
purple: 'purple-', // emits #purple-surface alongside #primary-surface
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Both `#primary-surface` and `#purple-surface` resolve to the exact same color. Drop the alias when the legacy name is no longer referenced.
|
|
214
|
+
|
|
215
|
+
### `primary` (the unprefixed alias)
|
|
216
|
+
|
|
217
|
+
`glaze.palette(themes, { primary })` and the per-export `primary` option duplicate one theme's tokens *without* prefix on top of any prefix map. Equivalent to listing that theme twice with different prefixes; useful when the "primary" theme is conceptually distinct from `default` and you want both sets of unprefixed tokens.
|
|
218
|
+
|
|
219
|
+
```ts
|
|
220
|
+
const palette = glaze.palette({ brand, accent }, { primary: 'brand' });
|
|
221
|
+
palette.tokens();
|
|
222
|
+
// → { light: { 'brand-surface': '...', 'surface': '...', 'accent-surface': '...' } }
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Override per call: `palette.tokens({ primary: 'accent' })`, or disable with `palette.tokens({ primary: false })`.
|
|
226
|
+
|
|
227
|
+
## Migrating from an existing color system
|
|
228
|
+
|
|
229
|
+
The fastest path: **map first, design second**. Get every existing token name producing a Glaze-resolved color value (even if it's a rough first pass), wire the new palette in, then iterate on the resolved colors without touching component code.
|
|
230
|
+
|
|
231
|
+
### 1. Inventory the existing tokens
|
|
232
|
+
|
|
233
|
+
Walk your current color system and bucket every token into one of these categories:
|
|
234
|
+
|
|
235
|
+
* **Surfaces** — backgrounds, panels, cards, banners.
|
|
236
|
+
* **Surface text** — body text, headings, captions, labels.
|
|
237
|
+
* **Borders / dividers / focus rings** — neutral structural lines.
|
|
238
|
+
* **Brand fills** — solid CTA backgrounds, badges, status banners.
|
|
239
|
+
* **Brand foregrounds** — link text, status text, icon colors on neutral backgrounds.
|
|
240
|
+
* **Disabled** — disabled chip + label.
|
|
241
|
+
* **Shadows / overlays** — elevation, scrims.
|
|
242
|
+
* **One-off colors** — syntax highlighting, charts, illustrations.
|
|
243
|
+
|
|
244
|
+
Each bucket maps cleanly to one of the patterns in [methodology.md](methodology.md). The bucket determines the *shape* of the Glaze definition (root vs dependent, `mode: 'auto'` vs `'fixed'`, contrast-floor vs absolute tone), not the value.
|
|
245
|
+
|
|
246
|
+
### 2. Reproduce the existing values
|
|
247
|
+
|
|
248
|
+
Pick a Glaze definition shape that lands the new color *close to* the legacy hex in light mode. The methodology doc explains the shape per bucket; the API doc covers the levers (`tone`, `saturation`, `contrast`, `mode`, `hue`).
|
|
249
|
+
|
|
250
|
+
Two tactics that make matching easier:
|
|
251
|
+
|
|
252
|
+
* **Anchor strong text at the edge** instead of solving for `'AAA'`. The contrast solver stops at the floor (cr=7), which usually leaves text noticeably softer than a legacy hex like `#1a1a1a`. An absolute `tone: 2` (or wherever the legacy token sits) preserves the look.
|
|
253
|
+
* **Match the metric the old system actually used.** Numeric WCAG ratios are
|
|
254
|
+
useful when reproducing a measured legacy ratio. For new content roles,
|
|
255
|
+
prefer the APCA presets from the methodology. For low-stakes spacing, use a
|
|
256
|
+
tone delta instead of inventing a contrast target.
|
|
257
|
+
|
|
258
|
+
### 3. Keep the old token names
|
|
259
|
+
|
|
260
|
+
Use a custom `prefix` map (and theme aliases if needed) so the names your components already consume keep working:
|
|
261
|
+
|
|
262
|
+
```ts
|
|
263
|
+
// Old: components consume `#dark`, `#dark-02`, `#dark-03`.
|
|
264
|
+
// New: define them in Glaze, map the prefix so they emit unchanged.
|
|
265
|
+
|
|
266
|
+
defaultTheme.colors({
|
|
267
|
+
dark: { base: 'surface', tone: 2, saturation: 0.475 },
|
|
268
|
+
'dark-02': {
|
|
269
|
+
base: 'surface',
|
|
270
|
+
tone: '-1',
|
|
271
|
+
saturation: 0.375,
|
|
272
|
+
contrast: [9, 11],
|
|
273
|
+
},
|
|
274
|
+
'dark-03': {
|
|
275
|
+
base: 'surface',
|
|
276
|
+
tone: '-1',
|
|
277
|
+
saturation: 0.24,
|
|
278
|
+
contrast: [4.5, 5.5],
|
|
279
|
+
},
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
palette.tasty({ prefix: { default: '' } });
|
|
283
|
+
// → '#dark', '#dark-02', '#dark-03' — components don't change.
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Once consumers are off the legacy names, rename the Glaze tokens to match your conventions.
|
|
287
|
+
|
|
288
|
+
### 4. Verify dark mode and HC before promoting
|
|
289
|
+
|
|
290
|
+
Glaze gives you light/dark/HC for free, but only the light mode is matched against the legacy palette. Before promoting the migration:
|
|
291
|
+
|
|
292
|
+
* Spot-check every surface, text, accent, and disabled pair in dark mode. The tone inversion plus per-color `mode` choices may produce results that *look right* in light but feel off in dark (typical fix: switch a brand color to `mode: 'fixed'`, or anchor a foreground to `surface` instead of the brand fill — see [methodology.md](methodology.md)).
|
|
293
|
+
* If the legacy system had no high-contrast mode, audit the HC variants Glaze emits. Anywhere the resolved cr is too low or the color blows out, add an HC pair (`tone: ['-7', '-20']`, `contrast: [4.5, 7]`, etc.).
|
|
294
|
+
* Run real screens, not just the token grid. The interaction of multiple Glaze tokens against each other (text on chip, hover bg vs. fill, disabled label on disabled chip) is where mismatches show up.
|
|
295
|
+
|
|
296
|
+
### 5. Trim what `extend()` doesn't need
|
|
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.
|
|
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
|
+
|
|
334
|
+
## Common pitfalls
|
|
335
|
+
|
|
336
|
+
| Symptom | Cause | Fix |
|
|
337
|
+
| ------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
338
|
+
| Disabled state stops looking disabled in dark mode. | Alpha-tinted overlay on `surface-text` (which inverts), giving asymmetric perceived contrast. | Replace it with an adaptive color anchored to `surface`; use a tone delta for visual spacing or a contrast floor when required. See [Chips and disabled states](methodology.md#chips-and-disabled-states). |
|
|
339
|
+
| Brand color flips to its complement in dark mode. | Default `mode: 'auto'` inverts the tone. | Set `mode: 'fixed'` so the tone is remapped (not inverted). |
|
|
340
|
+
| Brand text washes out against the dark surface. | Foreground was anchored to `accent-surface` (the brand fill), so contrast was only enforced against that fill — not the actual surface. | Anchor `accent-text` etc. to `surface` with `mode: 'auto'`. |
|
|
341
|
+
| Tokens look right in light, broken in HC. | The HC pass bypasses the tone window — solver runs over the full `[0, 100]` range. | Add explicit `[normal, hc]` pairs to `tone` / `contrast` for the affected tokens. |
|
|
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. |
|
|
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 })`. |
|
|
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). |
|
|
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. |
|
|
347
|
+
|
|
348
|
+
## See also
|
|
349
|
+
|
|
350
|
+
* [methodology.md](methodology.md) — how to design the palette in the first place.
|
|
351
|
+
* [api.md](api.md) — full reference for every option mentioned here.
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# OKHST in Glaze
|
|
2
|
+
|
|
3
|
+
Glaze uses [OKHST](https://github.com/tenphi/okhst), an OKHSL-derived color
|
|
4
|
+
space with a tone axis for stable palette authoring. This page explains how
|
|
5
|
+
Glaze applies the model. The standalone repository is the canonical
|
|
6
|
+
specification for the transfer functions, derivation, and color-model
|
|
7
|
+
invariants.
|
|
8
|
+
|
|
9
|
+
For practical palette design, continue to [methodology.md](methodology.md). For
|
|
10
|
+
every related option and utility, see [api.md](api.md).
|
|
11
|
+
|
|
12
|
+
## What tone means
|
|
13
|
+
|
|
14
|
+
OKHST keeps OKHSL hue and saturation and replaces authored lightness with
|
|
15
|
+
**tone**:
|
|
16
|
+
|
|
17
|
+
| Space | Coordinates | Third coordinate |
|
|
18
|
+
| ----- | ----------- | -------------------- |
|
|
19
|
+
| OKHSL | `h, s, l` | Perceptual lightness |
|
|
20
|
+
| OKHST | `h, s, t` | Contrast-shaped tone |
|
|
21
|
+
|
|
22
|
+
Tone uses a `0–100` authoring scale. Its primary invariant is:
|
|
23
|
+
|
|
24
|
+
> The same tone maps to the same OKHSL lightness for every hue and saturation.
|
|
25
|
+
|
|
26
|
+
For neutral colors, equal tone differences produce equal WCAG contrast ratios.
|
|
27
|
+
For chromatic colors, they remain a useful progression but are not exact:
|
|
28
|
+
hue, saturation, and gamut mapping can change the final sRGB luminance.
|
|
29
|
+
|
|
30
|
+
This distinction informs two authoring rules:
|
|
31
|
+
|
|
32
|
+
* Use **tone deltas** for visual spacing within ramps and related UI colors.
|
|
33
|
+
* Use `contrast` when a rendered color must meet a measured WCAG or APCA floor.
|
|
34
|
+
|
|
35
|
+
## Tone vocabulary
|
|
36
|
+
|
|
37
|
+
### Absolute tone
|
|
38
|
+
|
|
39
|
+
A numeric `tone` places a color independently on the `0–100` authoring scale:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
surface: {
|
|
43
|
+
tone: 97;
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`'max'` and `'min'` select the corresponding end of the active scheme. With a
|
|
48
|
+
`base`, they instead preserve their distance from that base across schemes —
|
|
49
|
+
see [Scheme adaptation](#scheme-adaptation).
|
|
50
|
+
|
|
51
|
+
### Tone delta
|
|
52
|
+
|
|
53
|
+
A **tone delta** is the signed difference between a dependent color and its
|
|
54
|
+
base. It is authored as a string:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
border: { base: 'surface', tone: '-8' }
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Here, `-8` is the tone delta. The base is resolved separately for every scheme,
|
|
61
|
+
then the delta is applied to that resolved base. This keeps related colors
|
|
62
|
+
visually ordered across light, dark, and high-contrast variants.
|
|
63
|
+
|
|
64
|
+
### Tone window
|
|
65
|
+
|
|
66
|
+
A **tone window** is the scheme-specific render range configured by
|
|
67
|
+
`lightTone` or `darkTone`:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
glaze.configure({
|
|
71
|
+
lightTone: [10, 100],
|
|
72
|
+
darkTone: [15, 95],
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
In Glaze, `lo` and `hi` are OKHSL-lightness boundaries. Authored tone is
|
|
77
|
+
positioned within the corresponding tone interval, then converted back to
|
|
78
|
+
OKHSL lightness for rendering. The object form adds an advanced render
|
|
79
|
+
curvature:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
lightTone: { lo: 10, hi: 100, eps: 0.05 }
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Pass `false` to use the full range. High-contrast variants always bypass the
|
|
86
|
+
ordinary boundaries and use the full range.
|
|
87
|
+
|
|
88
|
+
A [manual contrast level](api.md#manual-contrast-level) generalizes that bypass
|
|
89
|
+
continuously: with `contrastLevel: L` (`f = L / 100`), each boundary moves toward
|
|
90
|
+
the full range instead of jumping to it —
|
|
91
|
+
|
|
92
|
+
```text
|
|
93
|
+
lo(f) = lo + (0 - lo) * f
|
|
94
|
+
hi(f) = hi + (100 - hi) * f
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
— so the light default walks `[10, 100] → [0, 100]` and the dark default
|
|
98
|
+
`[15, 95] → [0, 100]`. The render `eps` is not interpolated, and a `false` window
|
|
99
|
+
is already the full range and therefore level-invariant.
|
|
100
|
+
|
|
101
|
+
This continuous form applies to the normal variants only. High-contrast variants
|
|
102
|
+
are already at the full range, so the level does not widen them further — the
|
|
103
|
+
bypass above is what makes the high-contrast tier level-independent.
|
|
104
|
+
|
|
105
|
+
## Scheme adaptation
|
|
106
|
+
|
|
107
|
+
Each regular color has an adaptation `mode`:
|
|
108
|
+
|
|
109
|
+
| Mode | Light scheme | Dark scheme |
|
|
110
|
+
| ---------- | ------------------------------ | -------------------------------------------------------------------- |
|
|
111
|
+
| `'auto'` | Map into the light tone window | Apply dark tone inversion (`100 - t`), then map into the dark window |
|
|
112
|
+
| `'fixed'` | Map into the light tone window | Map into the dark window without inversion |
|
|
113
|
+
| `'static'` | Keep the authored tone | Keep the authored tone |
|
|
114
|
+
|
|
115
|
+
Use `auto` for surfaces and foregrounds that should exchange light/dark
|
|
116
|
+
positions. Use `fixed` for brand fills and inverse surfaces that should stay on
|
|
117
|
+
the same side of the scale. Reserve `static` for colors that must not adapt.
|
|
118
|
+
|
|
119
|
+
**Dark tone inversion** is different from `autoFlip`. Inversion is normal
|
|
120
|
+
scheme adaptation controlled by `mode`. `autoFlip` handles a different local
|
|
121
|
+
problem: it may reverse an overshooting tone delta or let the contrast solver
|
|
122
|
+
try the opposite side of a base.
|
|
123
|
+
|
|
124
|
+
The regular pipeline is:
|
|
125
|
+
|
|
126
|
+
```text
|
|
127
|
+
authored tone
|
|
128
|
+
-> choose the color's adaptation mode
|
|
129
|
+
-> invert for dark + auto
|
|
130
|
+
-> map through the active tone window
|
|
131
|
+
-> store canonical tone
|
|
132
|
+
-> convert to OKHSL at the rendering edge
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Dark schemes also apply `darkDesaturation` unless the color is `static`.
|
|
136
|
+
|
|
137
|
+
**Hue and saturation are authoring inputs, not part of the tone transfer.** The
|
|
138
|
+
tone axis is the only channel OKHST adapts across schemes; `h` and `s` pass
|
|
139
|
+
through verbatim, with `darkDesaturation` as the one automatic adjustment.
|
|
140
|
+
A theme (or a single color) can seed a different hue and saturation for the
|
|
141
|
+
dark schemes via `darkHue` / `darkSaturation` — see
|
|
142
|
+
[api.md](api.md#dark-seed-darkhue--darksaturation). Those pick the `h` and `s`
|
|
143
|
+
that enter the pipeline above; they never change how tone is transferred.
|
|
144
|
+
Authoring a dark saturation replaces the `darkDesaturation` step rather than
|
|
145
|
+
stacking with it, and `static` colors ignore both.
|
|
146
|
+
|
|
147
|
+
**Extremes with a base** take a different dark path. Because the light and dark
|
|
148
|
+
windows are asymmetric, running an extreme through the dark window compresses
|
|
149
|
+
the span between it and its base, which lowers contrast. For a color with both
|
|
150
|
+
`base` and `tone: 'max'` / `'min'`, Glaze measures the tone shift the light
|
|
151
|
+
scheme produced between the two, then replays it against the base's resolved
|
|
152
|
+
dark tone (mirrored under `auto`, same-signed under `fixed`). Only `[0, 100]`
|
|
153
|
+
clamping applies, so such a color may render past the `darkTone` boundary.
|
|
154
|
+
|
|
155
|
+
## Reference and render epsilon
|
|
156
|
+
|
|
157
|
+
`REF_EPS = 0.05` defines Glaze's canonical tone scale. It is used for OKHST
|
|
158
|
+
input, stored resolved tone, tone deltas, and contrast search.
|
|
159
|
+
|
|
160
|
+
An object tone window may supply another `eps` as a scheme-specific rendering
|
|
161
|
+
control. Glaze still converts the result back to the reference scale so tone
|
|
162
|
+
deltas and contrast calculations remain comparable between schemes. Most
|
|
163
|
+
palettes should use the default.
|
|
164
|
+
|
|
165
|
+
## Contrast verification
|
|
166
|
+
|
|
167
|
+
Tone provides an efficient starting point for contrast solving, but Glaze does
|
|
168
|
+
not assume a chromatic tone has the neutral color's luminance. For a color with
|
|
169
|
+
`base` and `contrast`, Glaze:
|
|
170
|
+
|
|
171
|
+
1. resolves both colors for the active scheme;
|
|
172
|
+
2. measures the requested WCAG ratio or APCA Lc;
|
|
173
|
+
3. searches tone when the requested position misses the floor; and
|
|
174
|
+
4. warns when the target is physically unreachable or rendered chroma drifts
|
|
175
|
+
below the expected result.
|
|
176
|
+
|
|
177
|
+
`contrast` is therefore a floor, not a replacement for tone relationships.
|
|
178
|
+
Detailed presets, HC promotion, polarity, and role inference are documented
|
|
179
|
+
under [`contrast`](api.md#contrast-floor) and [roles](api.md#roles).
|
|
180
|
+
|
|
181
|
+
## Input and output
|
|
182
|
+
|
|
183
|
+
Glaze accepts OKHST through:
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
glaze.color('okhst(152 95% 70%)');
|
|
187
|
+
glaze.color({ h: 152, s: 0.95, t: 0.7 });
|
|
188
|
+
glaze.color({ hue: 152, saturation: 95, tone: 70 });
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
There is no native CSS `okhst()` function. Native exports use `oklch`, `rgb`,
|
|
192
|
+
or `hsl`. [Tasty](../../tasty/README.md) integrations may request `format: 'okhst'` because it can
|
|
193
|
+
consume Glaze's custom serialization:
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
theme.tasty({ format: 'okhst' });
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Bringing existing colors into Glaze
|
|
200
|
+
|
|
201
|
+
When moving raw CSS colors or design tokens into Glaze, use `fromHex()`,
|
|
202
|
+
`fromRgb()`, or `glaze.color()` to preserve the source color while you establish
|
|
203
|
+
theme seeds and semantic relationships. Then replace one-off values with roots,
|
|
204
|
+
tone deltas, and contrast floors as appropriate.
|
|
205
|
+
|
|
206
|
+
See [migration.md](migration.md#migrating-from-an-existing-color-system) for
|
|
207
|
+
the implementation workflow.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"name": "@tenphi/tasty",
|
|
4
|
+
"version": "3.8.0",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": "https://github.com/tenphi/tasty",
|
|
7
|
+
"ref": "v3.8.0",
|
|
8
|
+
"directory": "upstream/tasty"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "@tenphi/glaze",
|
|
12
|
+
"version": "2.0.0",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": "https://github.com/tenphi/glaze",
|
|
15
|
+
"ref": "v2.0.0",
|
|
16
|
+
"directory": "upstream/glaze"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andrey Yamanov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|