@tenphi/glaze 0.0.0-snapshot.78261ef → 0.0.0-snapshot.7b8c12f
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 +85 -1096
- package/dist/index.cjs +3058 -852
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1165 -113
- package/dist/index.d.mts +1165 -113
- package/dist/index.mjs +3027 -852
- package/dist/index.mjs.map +1 -1
- package/docs/api.md +1683 -0
- package/docs/methodology.md +636 -0
- package/docs/migration.md +315 -0
- package/docs/okhst.md +170 -0
- package/package.json +9 -9
|
@@ -0,0 +1,315 @@
|
|
|
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
|
+
- [Common pitfalls](#common-pitfalls)
|
|
16
|
+
|
|
17
|
+
## Choosing an export
|
|
18
|
+
|
|
19
|
+
Glaze has two layers of “export”:
|
|
20
|
+
|
|
21
|
+
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.
|
|
22
|
+
2. **Resolved output** — the seven shapes below. These are color strings / design-token documents for apps and tools, **not** restorable as authoring config.
|
|
23
|
+
|
|
24
|
+
Glaze emits the same resolved colors in seven shapes. Pick one based on your
|
|
25
|
+
renderer or tooling.
|
|
26
|
+
|
|
27
|
+
| Method | Output shape | Use it for |
|
|
28
|
+
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
29
|
+
| `palette.tasty(options?)` | `{ '#name': { '': value, '@media(prefers-color-scheme: dark)': value, '@media(prefers-contrast: more)': value } }` | The [Tasty](https://tasty.style) style system. Single object, state aliases keyed inside each token. |
|
|
30
|
+
| `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. |
|
|
31
|
+
| `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. |
|
|
32
|
+
| `palette.json(options?)` | `{ themeName: { name: { light, dark, ... } } }` | Tooling, JSON pipelines. |
|
|
33
|
+
| `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. |
|
|
34
|
+
| `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. |
|
|
35
|
+
| `palette.tailwind(options?)` | `'@theme { --color-*: ... } .dark { ... } ...'` | Tailwind CSS v4. A single ready-to-paste `@theme` block plus dark / high-contrast overrides. |
|
|
36
|
+
|
|
37
|
+
`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](https://tasty.style)-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.
|
|
38
|
+
|
|
39
|
+
## Wiring exports into the app
|
|
40
|
+
|
|
41
|
+
### [Tasty](https://tasty.style)
|
|
42
|
+
|
|
43
|
+
Spread the result of `palette.tasty()` into a global style call:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import type { Styles } from '@tenphi/tasty';
|
|
47
|
+
import { useGlobalStyles } from '@tenphi/tasty';
|
|
48
|
+
import { tastyStatic } from '@tenphi/tasty/static';
|
|
49
|
+
|
|
50
|
+
export const PALETTE_TOKENS = palette.tasty({
|
|
51
|
+
/* prefix map */
|
|
52
|
+
}) as Styles;
|
|
53
|
+
|
|
54
|
+
// In your root component:
|
|
55
|
+
useGlobalStyles('body', PALETTE_TOKENS);
|
|
56
|
+
|
|
57
|
+
// Or, for zero-runtime builds:
|
|
58
|
+
tastyStatic('body', PALETTE_TOKENS);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
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](https://tasty.style) setup.
|
|
62
|
+
|
|
63
|
+
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_:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { setGlobalPredefinedStates } from '@tenphi/tasty';
|
|
67
|
+
|
|
68
|
+
// glaze.configure({ states: { dark: '@dark', highContrast: '@hc' } });
|
|
69
|
+
setGlobalPredefinedStates({
|
|
70
|
+
'@dark':
|
|
71
|
+
'@root(schema=dark) | (!@root(schema) & @media(prefers-color-scheme: dark))',
|
|
72
|
+
'@hc':
|
|
73
|
+
'@root(contrast=high) | (!@root(contrast) & @media(prefers-contrast: more))',
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The state names here must match the `states` you set in [`glaze.configure({ states })`](api.md#configuration).
|
|
78
|
+
|
|
79
|
+
You can also register the tokens as a [Tasty](https://tasty.style) recipe instead of spreading them globally:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import { configure, tasty } from '@tenphi/tasty';
|
|
83
|
+
|
|
84
|
+
configure({ recipes: { 'theme-tokens': PALETTE_TOKENS } });
|
|
85
|
+
|
|
86
|
+
const Page = tasty({
|
|
87
|
+
styles: { recipe: 'theme-tokens', fill: '#surface', color: '#surface-text' },
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### CSS custom properties
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
const css = palette.css();
|
|
95
|
+
const stylesheet = `
|
|
96
|
+
:root { ${css.light} }
|
|
97
|
+
@media (prefers-color-scheme: dark) { :root { ${css.dark} } }
|
|
98
|
+
@media (prefers-contrast: more) { :root { ${css.lightContrast} } }
|
|
99
|
+
@media (prefers-color-scheme: dark) and (prefers-contrast: more) {
|
|
100
|
+
:root { ${css.darkContrast} }
|
|
101
|
+
}
|
|
102
|
+
`;
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Each property name is `--<prefix><name>-color` by default. Override the suffix:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
palette.css({ suffix: '' }); // → '--surface: rgb(...);'
|
|
109
|
+
palette.css({ format: 'oklch' }); // → '--surface-color: oklch(...);'
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Framework-agnostic JSON
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
const data = palette.json();
|
|
116
|
+
// → { primary: { surface: { light: 'oklch(...)', dark: 'oklch(...)' } }, ... }
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Feed into your tooling pipeline. Each color is grouped by theme name, then by token name, then by variant — no prefix logic to undo.
|
|
120
|
+
|
|
121
|
+
### W3C DTCG (`.tokens.json`)
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
import { writeFileSync } from 'node:fs';
|
|
125
|
+
const dtcg = palette.dtcg();
|
|
126
|
+
|
|
127
|
+
writeFileSync('tokens.light.tokens.json', JSON.stringify(dtcg.light, null, 2));
|
|
128
|
+
if (dtcg.dark) {
|
|
129
|
+
writeFileSync('tokens.dark.tokens.json', JSON.stringify(dtcg.dark, null, 2));
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
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.
|
|
134
|
+
|
|
135
|
+
### W3C DTCG Resolver-Module (single document)
|
|
136
|
+
|
|
137
|
+
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()`:
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
import { writeFileSync } from 'node:fs';
|
|
141
|
+
const resolver = palette.dtcgResolver({ modes: { highContrast: true } });
|
|
142
|
+
|
|
143
|
+
writeFileSync('resolver.json', JSON.stringify(resolver, null, 2));
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
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.
|
|
147
|
+
|
|
148
|
+
### Tailwind CSS v4
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
const css = palette.tailwind();
|
|
152
|
+
// Write to your CSS entry, or paste into a `@import "tailwindcss"` stylesheet:
|
|
153
|
+
// @theme { --color-primary-surface: oklch(...); ... }
|
|
154
|
+
// .dark { --color-primary-surface: oklch(...); ... }
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
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.
|
|
158
|
+
|
|
159
|
+
## Prefix map strategies
|
|
160
|
+
|
|
161
|
+
`palette.tokens()` / `tasty()` / `css()` / `dtcg()` / `tailwind()` accept a `prefix` option:
|
|
162
|
+
|
|
163
|
+
| Value | Result |
|
|
164
|
+
| ------------------------ | -------------------------------------------------------------------------- |
|
|
165
|
+
| `true` (default) | Every theme prefixes its tokens with `<themeName>-`. |
|
|
166
|
+
| `false` | No prefixes. Colliding keys produce a `console.warn`; first-write wins. |
|
|
167
|
+
| `Record<string, string>` | Per-theme prefix overrides. Themes not listed fall back to `<themeName>-`. |
|
|
168
|
+
|
|
169
|
+
The most common production pattern: **default theme unprefixed, every other theme prefixed with its name**:
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
palette.tasty({
|
|
173
|
+
prefix: {
|
|
174
|
+
default: '',
|
|
175
|
+
primary: 'primary-',
|
|
176
|
+
success: 'success-',
|
|
177
|
+
danger: 'danger-',
|
|
178
|
+
warning: 'warning-',
|
|
179
|
+
note: 'note-',
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
This makes neutral tokens consume as `#surface`, `#border`, `#disabled-surface` (no theme namespace) while status colors live under `#danger-surface`, `#success-accent-text`, etc.
|
|
185
|
+
|
|
186
|
+
This explicit map is usually clearer for a neutral `default` theme. The
|
|
187
|
+
separate `primary` palette option below solves a different namespace problem:
|
|
188
|
+
it duplicates one named theme without a prefix while retaining that theme's
|
|
189
|
+
prefixed tokens.
|
|
190
|
+
|
|
191
|
+
### Alias themes for legacy names
|
|
192
|
+
|
|
193
|
+
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:
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
const palette = glaze.palette({
|
|
197
|
+
default: defaultTheme,
|
|
198
|
+
primary: primaryTheme,
|
|
199
|
+
purple: primaryTheme, // legacy alias — same theme, different prefix
|
|
200
|
+
// ...
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
palette.tasty({
|
|
204
|
+
prefix: {
|
|
205
|
+
default: '',
|
|
206
|
+
primary: 'primary-',
|
|
207
|
+
purple: 'purple-', // emits #purple-surface alongside #primary-surface
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Both `#primary-surface` and `#purple-surface` resolve to the exact same color. Drop the alias when the legacy name is no longer referenced.
|
|
213
|
+
|
|
214
|
+
### `primary` (the unprefixed alias)
|
|
215
|
+
|
|
216
|
+
`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.
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
const palette = glaze.palette({ brand, accent }, { primary: 'brand' });
|
|
220
|
+
palette.tokens();
|
|
221
|
+
// → { light: { 'brand-surface': '...', 'surface': '...', 'accent-surface': '...' } }
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Override per call: `palette.tokens({ primary: 'accent' })`, or disable with `palette.tokens({ primary: false })`.
|
|
225
|
+
|
|
226
|
+
## Migrating from an existing color system
|
|
227
|
+
|
|
228
|
+
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.
|
|
229
|
+
|
|
230
|
+
### 1. Inventory the existing tokens
|
|
231
|
+
|
|
232
|
+
Walk your current color system and bucket every token into one of these categories:
|
|
233
|
+
|
|
234
|
+
- **Surfaces** — backgrounds, panels, cards, banners.
|
|
235
|
+
- **Surface text** — body text, headings, captions, labels.
|
|
236
|
+
- **Borders / dividers / focus rings** — neutral structural lines.
|
|
237
|
+
- **Brand fills** — solid CTA backgrounds, badges, status banners.
|
|
238
|
+
- **Brand foregrounds** — link text, status text, icon colors on neutral backgrounds.
|
|
239
|
+
- **Disabled** — disabled chip + label.
|
|
240
|
+
- **Shadows / overlays** — elevation, scrims.
|
|
241
|
+
- **One-off colors** — syntax highlighting, charts, illustrations.
|
|
242
|
+
|
|
243
|
+
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.
|
|
244
|
+
|
|
245
|
+
### 2. Reproduce the existing values
|
|
246
|
+
|
|
247
|
+
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`).
|
|
248
|
+
|
|
249
|
+
Two tactics that make matching easier:
|
|
250
|
+
|
|
251
|
+
- **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.
|
|
252
|
+
- **Match the metric the old system actually used.** Numeric WCAG ratios are
|
|
253
|
+
useful when reproducing a measured legacy ratio. For new content roles,
|
|
254
|
+
prefer the APCA presets from the methodology. For low-stakes spacing, use a
|
|
255
|
+
tone delta instead of inventing a contrast target.
|
|
256
|
+
|
|
257
|
+
### 3. Keep the old token names
|
|
258
|
+
|
|
259
|
+
Use a custom `prefix` map (and theme aliases if needed) so the names your components already consume keep working:
|
|
260
|
+
|
|
261
|
+
```ts
|
|
262
|
+
// Old: components consume `#dark`, `#dark-02`, `#dark-03`.
|
|
263
|
+
// New: define them in Glaze, map the prefix so they emit unchanged.
|
|
264
|
+
|
|
265
|
+
defaultTheme.colors({
|
|
266
|
+
dark: { base: 'surface', tone: 2, saturation: 0.475 },
|
|
267
|
+
'dark-02': {
|
|
268
|
+
base: 'surface',
|
|
269
|
+
tone: '-1',
|
|
270
|
+
saturation: 0.375,
|
|
271
|
+
contrast: [9, 11],
|
|
272
|
+
},
|
|
273
|
+
'dark-03': {
|
|
274
|
+
base: 'surface',
|
|
275
|
+
tone: '-1',
|
|
276
|
+
saturation: 0.24,
|
|
277
|
+
contrast: [4.5, 5.5],
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
palette.tasty({ prefix: { default: '' } });
|
|
282
|
+
// → '#dark', '#dark-02', '#dark-03' — components don't change.
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
Once consumers are off the legacy names, rename the Glaze tokens to match your conventions.
|
|
286
|
+
|
|
287
|
+
### 4. Verify dark mode and HC before promoting
|
|
288
|
+
|
|
289
|
+
Glaze gives you light/dark/HC for free, but only the light mode is matched against the legacy palette. Before promoting the migration:
|
|
290
|
+
|
|
291
|
+
- 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)).
|
|
292
|
+
- 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.).
|
|
293
|
+
- 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.
|
|
294
|
+
|
|
295
|
+
### 5. Trim what `extend()` doesn't need
|
|
296
|
+
|
|
297
|
+
After migration, mark every default-only token (borders, shadows, disabled chip, code highlighting, etc.) `inherit: false`. Colored sibling themes only need the accent + tinted-surface chain — flagging the rest cuts the emitted token set per theme dramatically.
|
|
298
|
+
|
|
299
|
+
## Common pitfalls
|
|
300
|
+
|
|
301
|
+
| Symptom | Cause | Fix |
|
|
302
|
+
| ------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
303
|
+
| 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). |
|
|
304
|
+
| 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). |
|
|
305
|
+
| 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'`. |
|
|
306
|
+
| 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. |
|
|
307
|
+
| A relative `tone` like `'+48'` lands on the _wrong_ (darker) side of its base. | Overshooting offsets now mirror to the other side of the base by default (`autoFlip` inherits `autoFlip`). | Set `autoFlip: false` on the color to clamp to the boundary instead, or use `tone: 'max'`/`'min'` to force the extreme. |
|
|
308
|
+
| `palette.tokens()` emits unexpected unprefixed names. | A `primary` was set on the palette (or per-call) and is duplicating the theme's tokens without prefix. | Pass `primary: false` to disable for that export, or rename `glaze.palette(themes, { primary })`. |
|
|
309
|
+
| `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. |
|
|
310
|
+
| `console.warn: color "X" cannot meet contrast`. | The requested contrast target is physically unreachable for the color's hue/saturation against its base. | Lower the floor, change the base, or accept the closest passing variant. Use the `name` override on standalone colors to make the warning identifiable. |
|
|
311
|
+
|
|
312
|
+
## See also
|
|
313
|
+
|
|
314
|
+
- [methodology.md](methodology.md) — how to design the palette in the first place.
|
|
315
|
+
- [api.md](api.md) — full reference for every option mentioned here.
|
package/docs/okhst.md
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
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.
|
|
48
|
+
|
|
49
|
+
### Tone delta
|
|
50
|
+
|
|
51
|
+
A **tone delta** is the signed difference between a dependent color and its
|
|
52
|
+
base. It is authored as a string:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
border: { base: 'surface', tone: '-8' }
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Here, `-8` is the tone delta. The base is resolved separately for every scheme,
|
|
59
|
+
then the delta is applied to that resolved base. This keeps related colors
|
|
60
|
+
visually ordered across light, dark, and high-contrast variants.
|
|
61
|
+
|
|
62
|
+
### Tone window
|
|
63
|
+
|
|
64
|
+
A **tone window** is the scheme-specific render range configured by
|
|
65
|
+
`lightTone` or `darkTone`:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
glaze.configure({
|
|
69
|
+
lightTone: [10, 100],
|
|
70
|
+
darkTone: [15, 95],
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
In Glaze, `lo` and `hi` are OKHSL-lightness boundaries. Authored tone is
|
|
75
|
+
positioned within the corresponding tone interval, then converted back to
|
|
76
|
+
OKHSL lightness for rendering. The object form adds an advanced render
|
|
77
|
+
curvature:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
lightTone: { lo: 10, hi: 100, eps: 0.05 }
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Pass `false` to use the full range. High-contrast variants always bypass the
|
|
84
|
+
ordinary boundaries and use the full range.
|
|
85
|
+
|
|
86
|
+
## Scheme adaptation
|
|
87
|
+
|
|
88
|
+
Each regular color has an adaptation `mode`:
|
|
89
|
+
|
|
90
|
+
| Mode | Light scheme | Dark scheme |
|
|
91
|
+
| ---------- | ------------------------------ | -------------------------------------------------------------------- |
|
|
92
|
+
| `'auto'` | Map into the light tone window | Apply dark tone inversion (`100 - t`), then map into the dark window |
|
|
93
|
+
| `'fixed'` | Map into the light tone window | Map into the dark window without inversion |
|
|
94
|
+
| `'static'` | Keep the authored tone | Keep the authored tone |
|
|
95
|
+
|
|
96
|
+
Use `auto` for surfaces and foregrounds that should exchange light/dark
|
|
97
|
+
positions. Use `fixed` for brand fills and inverse surfaces that should stay on
|
|
98
|
+
the same side of the scale. Reserve `static` for colors that must not adapt.
|
|
99
|
+
|
|
100
|
+
**Dark tone inversion** is different from `autoFlip`. Inversion is normal
|
|
101
|
+
scheme adaptation controlled by `mode`. `autoFlip` handles a different local
|
|
102
|
+
problem: it may reverse an overshooting tone delta or let the contrast solver
|
|
103
|
+
try the opposite side of a base.
|
|
104
|
+
|
|
105
|
+
The regular pipeline is:
|
|
106
|
+
|
|
107
|
+
```text
|
|
108
|
+
authored tone
|
|
109
|
+
-> choose the color's adaptation mode
|
|
110
|
+
-> invert for dark + auto
|
|
111
|
+
-> map through the active tone window
|
|
112
|
+
-> store canonical tone
|
|
113
|
+
-> convert to OKHSL at the rendering edge
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Dark schemes also apply `darkDesaturation` unless the color is `static`.
|
|
117
|
+
|
|
118
|
+
## Reference and render epsilon
|
|
119
|
+
|
|
120
|
+
`REF_EPS = 0.05` defines Glaze's canonical tone scale. It is used for OKHST
|
|
121
|
+
input, stored resolved tone, tone deltas, and contrast search.
|
|
122
|
+
|
|
123
|
+
An object tone window may supply another `eps` as a scheme-specific rendering
|
|
124
|
+
control. Glaze still converts the result back to the reference scale so tone
|
|
125
|
+
deltas and contrast calculations remain comparable between schemes. Most
|
|
126
|
+
palettes should use the default.
|
|
127
|
+
|
|
128
|
+
## Contrast verification
|
|
129
|
+
|
|
130
|
+
Tone provides an efficient starting point for contrast solving, but Glaze does
|
|
131
|
+
not assume a chromatic tone has the neutral color's luminance. For a color with
|
|
132
|
+
`base` and `contrast`, Glaze:
|
|
133
|
+
|
|
134
|
+
1. resolves both colors for the active scheme;
|
|
135
|
+
2. measures the requested WCAG ratio or APCA Lc;
|
|
136
|
+
3. searches tone when the requested position misses the floor; and
|
|
137
|
+
4. warns when the target is physically unreachable or rendered chroma drifts
|
|
138
|
+
below the expected result.
|
|
139
|
+
|
|
140
|
+
`contrast` is therefore a floor, not a replacement for tone relationships.
|
|
141
|
+
Detailed presets, HC promotion, polarity, and role inference are documented
|
|
142
|
+
under [`contrast`](api.md#contrast-floor) and [roles](api.md#roles).
|
|
143
|
+
|
|
144
|
+
## Input and output
|
|
145
|
+
|
|
146
|
+
Glaze accepts OKHST through:
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
glaze.color('okhst(152 95% 70%)');
|
|
150
|
+
glaze.color({ h: 152, s: 0.95, t: 0.7 });
|
|
151
|
+
glaze.color({ hue: 152, saturation: 95, tone: 70 });
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
There is no native CSS `okhst()` function. Native exports use `oklch`, `rgb`,
|
|
155
|
+
or `hsl`. [Tasty](https://tasty.style) integrations may request `format: 'okhst'` because it can
|
|
156
|
+
consume Glaze's custom serialization:
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
theme.tasty({ format: 'okhst' });
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Bringing existing colors into Glaze
|
|
163
|
+
|
|
164
|
+
When moving raw CSS colors or design tokens into Glaze, use `fromHex()`,
|
|
165
|
+
`fromRgb()`, or `glaze.color()` to preserve the source color while you establish
|
|
166
|
+
theme seeds and semantic relationships. Then replace one-off values with roots,
|
|
167
|
+
tone deltas, and contrast floors as appropriate.
|
|
168
|
+
|
|
169
|
+
See [migration.md](migration.md#migrating-from-an-existing-color-system) for
|
|
170
|
+
the implementation workflow.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tenphi/glaze",
|
|
3
|
-
"version": "0.0.0-snapshot.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.0-snapshot.7b8c12f",
|
|
4
|
+
"description": "OKHST-based color theme generator with WCAG contrast solving for light, dark, and high-contrast schemes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.mjs",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
|
-
"dist"
|
|
22
|
+
"dist",
|
|
23
|
+
"docs"
|
|
23
24
|
],
|
|
24
25
|
"sideEffects": false,
|
|
25
26
|
"engines": {
|
|
@@ -27,6 +28,8 @@
|
|
|
27
28
|
},
|
|
28
29
|
"scripts": {
|
|
29
30
|
"build": "tsdown",
|
|
31
|
+
"playground": "vite playground",
|
|
32
|
+
"build:playground": "vite build playground",
|
|
30
33
|
"test": "vitest run",
|
|
31
34
|
"test:watch": "vitest",
|
|
32
35
|
"test:coverage": "vitest run --coverage",
|
|
@@ -47,6 +50,7 @@
|
|
|
47
50
|
"keywords": [
|
|
48
51
|
"color",
|
|
49
52
|
"theme",
|
|
53
|
+
"okhst",
|
|
50
54
|
"okhsl",
|
|
51
55
|
"contrast",
|
|
52
56
|
"wcag",
|
|
@@ -71,12 +75,8 @@
|
|
|
71
75
|
"tsdown": "^0.20.3",
|
|
72
76
|
"typescript": "^5.9.3",
|
|
73
77
|
"typescript-eslint": "^8.56.0",
|
|
78
|
+
"vite": "^8.0.16",
|
|
74
79
|
"vitest": "^4.0.18"
|
|
75
80
|
},
|
|
76
|
-
"
|
|
77
|
-
"onlyBuiltDependencies": [
|
|
78
|
-
"esbuild"
|
|
79
|
-
]
|
|
80
|
-
},
|
|
81
|
-
"packageManager": "pnpm@10.29.3"
|
|
81
|
+
"packageManager": "pnpm@11.0.8"
|
|
82
82
|
}
|