@tenphi/glaze 2.0.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,635 @@
1
+ ---
2
+ title: Exporting and integration
3
+ description: Choose an export shape for your renderer or design tool, then wire Glaze tokens into Tasty, CSS, JSON, DTCG, or Tailwind.
4
+ ---
5
+
6
+ import CssExample from '../docs-site/components/exporting/CssExample.astro';
7
+ import PrefixDemo from '../docs-site/components/exporting/PrefixDemo.astro';
8
+
9
+ Glaze resolves every color once and emits the result in whatever shape your
10
+ app or design tool reads. This page helps you pick a shape, wire it in, and
11
+ name tokens across a multi-theme palette. If you are still designing the
12
+ palette itself, start with [Designing a palette](./methodology.mdx); every
13
+ option mentioned here is listed in full in the
14
+ [Output formats](./reference/output.md) and
15
+ [Palettes](./reference/palette.md) references.
16
+
17
+ ## Snapshots and resolved output
18
+
19
+ Glaze has two kinds of "export", and they are not interchangeable:
20
+
21
+ | Kind | Methods | What it carries | Restore with |
22
+ | --- | --- | --- | --- |
23
+ | Authoring snapshot | `theme.export()`, `token.export()`, `palette.export()` | Seeds, color definitions and their relations, the effective config frozen at export time, plus `kind` and `version` | `glaze.themeFrom`, `glaze.colorFrom`, `glaze.paletteFrom` |
24
+ | Resolved output | `tasty`, `tokens`, `css`, `json`, `dtcg`, `dtcgResolver`, `tailwind` | Color strings or design-token documents for apps and tools | Nothing: it is not authoring config |
25
+
26
+ ```ts
27
+ import { glaze } from '@tenphi/glaze';
28
+
29
+ // Persist the authoring graph and rebuild it later.
30
+ const snapshot = theme.export();
31
+ // → { kind: 'theme', version: 2, hue, saturation, colors, config }
32
+ const restored = glaze.themeFrom(JSON.parse(JSON.stringify(snapshot)));
33
+
34
+ // Emit colors for the app.
35
+ const css = theme.css();
36
+ ```
37
+
38
+ A live theme, token, or palette keeps only the config fields you set on it;
39
+ the rest track `glaze.configure()` until you export, when the effective resolve
40
+ settings are frozen into the snapshot. A global `contrastLevel` is not frozen
41
+ (it is a live preference, like `modes` and `states`); see the
42
+ [merge rules](./reference/configuration.md#merge-rules). Use snapshots to store
43
+ or ship the palette definition (a theme editor, a config file, a server), and
44
+ resolved output for everything that paints pixels. Snapshot versioning and the
45
+ `kind` / `version` checks are covered in the
46
+ [reference overview](./reference/index.md#authoring-snapshots-and-versioning).
47
+
48
+ ## Choosing an export
49
+
50
+ Every method below exists on a theme and on a palette, and emits the same
51
+ resolved colors. Pick the one your renderer or tooling reads.
52
+
53
+ | Method | Output shape | Use it for |
54
+ | --- | --- | --- |
55
+ | `palette.tasty()` | `{ '#name': { '': value, [state]: value } }` | The [Tasty](https://tasty.style) style system. One object; the scheme states are keyed inside each token. |
56
+ | `palette.tokens()` | `{ light: { name: value }, dark: { name: value }, ... }` | Most CSS-in-JS systems. Flat maps per scheme, easy to feed into a `:root` rule through your framework's globals. |
57
+ | `palette.css()` | `{ light: '--name-color: ...;', dark: '...', lightContrast: '...', darkContrast: '...' }` | Framework-free CSS and static stylesheets. CSS custom-property declarations per scheme, ready to wrap in `:root` and media queries. |
58
+ | `palette.json()` | `{ themeName: { name: { light, dark, ... } } }` | Tooling and JSON pipelines. |
59
+ | `palette.dtcg()` | `{ light: { name: { $type, $value } }, dark: { ... }, ... }` | W3C [DTCG 2025.10](https://www.designtokens.org/) `.tokens.json` files for Figma, Tokens Studio, Style Dictionary, Terrazzo, and Penpot. One document per scheme. |
60
+ | `palette.dtcgResolver()` | `{ version, sets, modifiers, resolutionOrder }` | The W3C DTCG **Resolver Module**: one document that describes every scheme as `sets` plus a `scheme` modifier with a context per scheme. For resolver tools such as Dispersa. |
61
+ | `palette.tailwind()` | `'@theme { --color-*: ... } .dark { ... } ...'` | Tailwind CSS v4. One ready-to-paste `@theme` block plus dark and high-contrast overrides. |
62
+
63
+ A few options cut across the shapes:
64
+
65
+ - **Schemes.** `tasty()`, `tokens()`, `json()`, `dtcg()`, `dtcgResolver()`, and
66
+ `tailwind()` take `modes: { dark, highContrast }` to choose which schemes
67
+ they emit; by default you get light and dark. `css()` takes no `modes` and
68
+ always returns all four strings. See [Light, dark, and high contrast](./schemes.mdx) for what each
69
+ scheme is.
70
+ - **Color format.** The CSS-string exports take `format`: `'oklch'` (the
71
+ default), `'rgb'`, or `'hsl'`. `'okhsl'` and `'okhst'` are not CSS color
72
+ spaces, so only the Tasty-shaped exports accept them (`tasty()`, and a
73
+ standalone color's `token()` / `tasty()`); `tokens()`, `json()`, `css()`, and
74
+ `tailwind()` throw.
75
+ - **DTCG color space.** `dtcg()` and `dtcgResolver()` emit structured
76
+ `$value` objects, not CSS strings, so they ignore `format`. Use `colorSpace`
77
+ instead: `'srgb'` (the default) or `'oklch'`.
78
+ - **HDR.** `modes: { hdr: true }` (`css({ hdr: true })` for `css()`) adds the
79
+ values of [HDR glows](./hdr.mdx) next to the SDR ones. It is off by
80
+ default; see [Output is opt-in](./hdr.mdx#output-is-opt-in).
81
+
82
+ Here is one theme and the CSS custom properties `theme.css()` emits for it.
83
+ Switch to the Output tab to see the declarations, wrapped the way the
84
+ [CSS custom properties](#css-custom-properties) section below wires them:
85
+
86
+ <CssExample
87
+ hue={280}
88
+ saturation={80}
89
+ colors={{
90
+ surface: { tone: 100, saturation: 0.11 },
91
+ 'surface-text': { base: 'surface', tone: 2, saturation: 0.475 },
92
+ border: { base: 'surface', tone: ['-10', '-20'], saturation: 0.175 },
93
+ 'accent-surface-text': { tone: 100, mode: 'fixed' },
94
+ 'accent-surface': {
95
+ base: 'accent-surface-text',
96
+ tone: '-1',
97
+ contrast: { apca: ['content', 'body'] },
98
+ mode: 'fixed',
99
+ },
100
+ 'accent-text': {
101
+ base: 'surface',
102
+ tone: '-1',
103
+ saturation: 1,
104
+ contrast: { apca: ['content', 'body'] },
105
+ },
106
+ }}
107
+ after={"const css = theme.css({ format: 'rgb' });\n// css.light → :root, css.dark → (prefers-color-scheme: dark)"}
108
+ caption="Each color and the rgb() value css() emits for it, in the scheme you are viewing. The Output tab lists the light and dark declarations."
109
+ />
110
+
111
+ ## Wiring exports into the app
112
+
113
+ The examples below export a palette; a single theme has the same methods, and
114
+ `prefix` / `primary` only matter for palettes. The values shown are real output
115
+ for the `default` + `danger` palette from
116
+ [Prefix map strategies](#prefix-map-strategies).
117
+
118
+ ### Tasty
119
+
120
+ `tasty()` returns [Tasty](https://tasty.style) color tokens: `#name` keys whose
121
+ values are state maps. Register them as global tokens:
122
+
123
+ ```ts
124
+ import { configure } from '@tenphi/tasty';
125
+
126
+ configure({ tokens: palette.tasty({ prefix: { default: '' } }) });
127
+ ```
128
+
129
+ Or spread them into a global style call:
130
+
131
+ ```ts
132
+ import type { Styles } from '@tenphi/tasty';
133
+ import { useGlobalStyles } from '@tenphi/tasty';
134
+ import { tastyStatic } from '@tenphi/tasty/static';
135
+
136
+ export const PALETTE_TOKENS = palette.tasty({
137
+ prefix: { default: '' },
138
+ }) as Styles;
139
+
140
+ // In your root component:
141
+ useGlobalStyles('body', PALETTE_TOKENS);
142
+
143
+ // Or, for zero-runtime builds:
144
+ tastyStatic('body', PALETTE_TOKENS);
145
+ ```
146
+
147
+ By default the dark and high-contrast variants are keyed by media-query states,
148
+ so the tokens follow the OS preference with no extra Tasty setup:
149
+
150
+ ```ts
151
+ palette.tasty({ prefix: { default: '' } })['#surface'];
152
+ // → {
153
+ // '': 'oklch(1 0 0)',
154
+ // '@media(prefers-color-scheme: dark)': 'oklch(0.2534 0.0081 280)',
155
+ // }
156
+ ```
157
+
158
+ To drive the schemes from your own state aliases instead (for example a manual
159
+ toggle that falls back to the OS preference), set
160
+ [`glaze.configure({ states })`](./reference/output.md#state-aliases) and register
161
+ what those states mean in Tasty:
162
+
163
+ ```ts
164
+ import { setGlobalPredefinedStates } from '@tenphi/tasty';
165
+
166
+ glaze.configure({ states: { dark: '@dark', highContrast: '@hc' } });
167
+
168
+ setGlobalPredefinedStates({
169
+ '@dark':
170
+ '@root(schema=dark) | ' +
171
+ '(!@root(schema) & @media(prefers-color-scheme: dark))',
172
+ '@hc':
173
+ '@root(contrast=high) | ' +
174
+ '(!@root(contrast) & @media(prefers-contrast: more))',
175
+ });
176
+ ```
177
+
178
+ The state names must match the `states` you set in `glaze.configure()`. To
179
+ override them for one export only, pass `states` to the call:
180
+ `palette.tasty({ states: { dark: '@dark', highContrast: '@hc' } })`. With
181
+ `modes: { highContrast: true }` each token then carries four keys: `''`,
182
+ `'@dark'`, `'@hc'`, and `'@dark & @hc'`.
183
+
184
+ You can also register the tokens as a Tasty recipe instead of spreading them
185
+ globally:
186
+
187
+ ```ts
188
+ import { configure, tasty } from '@tenphi/tasty';
189
+
190
+ configure({
191
+ recipes: { 'theme-tokens': palette.tasty({ prefix: { default: '' } }) },
192
+ });
193
+
194
+ const Page = tasty({
195
+ styles: {
196
+ recipe: 'theme-tokens',
197
+ fill: '#surface',
198
+ color: '#surface-text',
199
+ },
200
+ });
201
+ ```
202
+
203
+ ### CSS custom properties
204
+
205
+ `css()` returns one string of declarations per scheme. Wrap them in the rules
206
+ that select each scheme:
207
+
208
+ ```ts
209
+ const css = palette.css({ prefix: { default: '' } });
210
+ const stylesheet = `
211
+ :root { ${css.light} }
212
+ @media (prefers-color-scheme: dark) { :root { ${css.dark} } }
213
+ @media (prefers-contrast: more) { :root { ${css.lightContrast} } }
214
+ @media (prefers-color-scheme: dark) and (prefers-contrast: more) {
215
+ :root { ${css.darkContrast} }
216
+ }
217
+ `;
218
+ ```
219
+
220
+ Keep that order: the dark high-contrast block comes last so it wins over both
221
+ the dark and the light high-contrast blocks.
222
+
223
+ Each property is named `--<prefix><name>-color` by default. Change the suffix
224
+ or the color format per call:
225
+
226
+ ```ts
227
+ palette.css({ prefix: { default: '' }, suffix: '' });
228
+ // → '--surface: oklch(1 0 0);'
229
+ palette.css({ prefix: { default: '' }, format: 'rgb' });
230
+ // → '--surface-color: rgb(255 255 255);'
231
+ ```
232
+
233
+ ### JSON
234
+
235
+ ```ts
236
+ const data = palette.json();
237
+ // → {
238
+ // default: {
239
+ // surface: {
240
+ // light: 'oklch(1 0 0)',
241
+ // dark: 'oklch(0.2534 0.0081 280)',
242
+ // },
243
+ // ...
244
+ // },
245
+ // danger: {
246
+ // surface: {
247
+ // light: 'oklch(0.9602 0.0148 23)',
248
+ // dark: 'oklch(0.287 0.065 23)',
249
+ // },
250
+ // ...
251
+ // },
252
+ // }
253
+ ```
254
+
255
+ Each color is grouped by theme name, then token name, then scheme, so there is
256
+ no prefix logic to undo: `json()` takes only `modes` and `format`. It has no
257
+ `prefix` option and does not emit the `primary` alias.
258
+
259
+ ### W3C DTCG
260
+
261
+ `dtcg()` returns one [Design Tokens](https://www.designtokens.org/) document
262
+ per scheme. Write each to its own file:
263
+
264
+ ```ts
265
+ import { writeFileSync } from 'node:fs';
266
+
267
+ const dtcg = palette.dtcg({ prefix: { default: '' } });
268
+
269
+ writeFileSync('light.tokens.json', JSON.stringify(dtcg.light, null, 2));
270
+ if (dtcg.dark) {
271
+ writeFileSync('dark.tokens.json', JSON.stringify(dtcg.dark, null, 2));
272
+ }
273
+ ```
274
+
275
+ Each document is a spec-conformant token tree:
276
+
277
+ ```json
278
+ {
279
+ "surface-text": {
280
+ "$type": "color",
281
+ "$value": {
282
+ "colorSpace": "srgb",
283
+ "components": [0.096174, 0.101248, 0.179183],
284
+ "hex": "#191a2e"
285
+ }
286
+ }
287
+ }
288
+ ```
289
+
290
+ One file per scheme is the most tool-compatible convention: Style Dictionary
291
+ treats the files as themes, Tokens Studio as sets, and Figma as variable modes.
292
+ Feed them straight into Style Dictionary v4+, Tokens Studio, or any
293
+ DTCG-compatible tool; no Glaze-specific transform is needed.
294
+
295
+ - The default `colorSpace: 'srgb'` emits gamma sRGB components in 0–1 plus a
296
+ `hex` hint that every reader understands.
297
+ - `colorSpace: 'oklch'` emits `[L, C, H]` components and no `hex`: wide-gamut,
298
+ Glaze-native values.
299
+ - Translucent colors (shadows, glows, transparent mixes, `opacity`) carry an
300
+ `alpha` field; opaque ones omit it.
301
+ - A scheme you didn't ask for is `undefined`, hence the `if (dtcg.dark)` check.
302
+
303
+ ### W3C DTCG Resolver Module
304
+
305
+ When you want **one file** that describes every scheme, for a resolver tool
306
+ such as [Dispersa](https://github.com/dispersa-core/dispersa), use
307
+ `dtcgResolver()` instead of `dtcg()`:
308
+
309
+ ```ts
310
+ import { writeFileSync } from 'node:fs';
311
+
312
+ const resolver = palette.dtcgResolver({ modes: { highContrast: true } });
313
+
314
+ writeFileSync('resolver.json', JSON.stringify(resolver, null, 2));
315
+ ```
316
+
317
+ ```ts
318
+ // → {
319
+ // version: '2025.10',
320
+ // sets: { base: { sources: [ /* light tokens */ ] } },
321
+ // modifiers: {
322
+ // scheme: {
323
+ // default: 'light',
324
+ // contexts: {
325
+ // light: [],
326
+ // dark: [ /* dark tokens */ ],
327
+ // lightContrast: [ /* light high-contrast tokens */ ],
328
+ // darkContrast: [ /* dark high-contrast tokens */ ],
329
+ // },
330
+ // },
331
+ // },
332
+ // resolutionOrder: [
333
+ // { $ref: '#/sets/base' },
334
+ // { $ref: '#/modifiers/scheme' },
335
+ // ],
336
+ // }
337
+ ```
338
+
339
+ The light tokens are the base set (`sets.base.sources[0]`) and the modifier's
340
+ default context, so the `light` context is empty. Every other context holds
341
+ that scheme's exact resolved tokens. Glaze resolves `darkContrast`
342
+ independently, which is why it gets its own context: two independent modifiers
343
+ (dark, high contrast) would compose additively and produce wrong dark
344
+ high-contrast values.
345
+
346
+ Rename the set, the modifier, or the contexts with `setName`, `modifierName`,
347
+ and `contextNames` if your resolver expects other labels. Prefer `dtcg()` for
348
+ the widest per-file tool support, and `dtcgResolver()` when a resolver tool
349
+ consumes the document for you.
350
+
351
+ ### Tailwind CSS v4
352
+
353
+ ```ts
354
+ const css = palette.tailwind({ prefix: { default: '' } });
355
+ // Write it to your CSS entry, next to `@import "tailwindcss";`
356
+ ```
357
+
358
+ ```css
359
+ @theme {
360
+ --color-surface: oklch(1 0 0);
361
+ --color-surface-text: oklch(0.2263 0.0385 280);
362
+ /* ... */
363
+ }
364
+
365
+ .dark {
366
+ --color-surface: oklch(0.2534 0.0081 280);
367
+ --color-surface-text: oklch(0.9394 0.0137 280);
368
+ /* ... */
369
+ }
370
+ ```
371
+
372
+ The `--color-*` namespace makes every color available as `bg-*`, `text-*`,
373
+ `border-*`, and the other color utilities. Change it with `namespace` (for
374
+ example `namespace: ''` emits `--surface`); it is separate from the palette's
375
+ theme `prefix`.
376
+
377
+ To follow the OS preference instead of a class, pass a media query as
378
+ `darkSelector`; Glaze nests `:root` inside it:
379
+
380
+ ```ts
381
+ palette.tailwind({
382
+ prefix: { default: '' },
383
+ darkSelector: '@media (prefers-color-scheme: dark)',
384
+ });
385
+ // @media (prefers-color-scheme: dark) {
386
+ // :root {
387
+ // --color-surface: oklch(0.2534 0.0081 280);
388
+ // ...
389
+ // }
390
+ // }
391
+ ```
392
+
393
+ High-contrast overrides are omitted unless `modes.highContrast` is on. They
394
+ land under `.high-contrast` and `.dark.high-contrast` (both classes on the same
395
+ element) by default; change the class with `highContrastSelector`, which also
396
+ accepts a media query such as `'@media (prefers-contrast: more)'`.
397
+
398
+ ## Prefix map strategies
399
+
400
+ When a palette merges several themes into one namespace, the `prefix` option
401
+ decides how each theme's tokens are named. It applies to `tokens()`, `tasty()`,
402
+ `css()`, `dtcg()`, `dtcgResolver()`, and `tailwind()` (`json()` groups by theme
403
+ instead):
404
+
405
+ | Value | Result |
406
+ | --- | --- |
407
+ | `true` (default) | Every theme prefixes its tokens with `<themeName>-`. |
408
+ | `false` | No prefixes. Colliding names warn and the first theme wins; see [Collisions](#collisions). |
409
+ | `Record<string, string>` | Per-theme prefixes. Themes not listed fall back to `<themeName>-`. |
410
+
411
+ Below, one palette exported three ways. Each column lists the names
412
+ `palette.tokens()` actually returns for that call:
413
+
414
+ <PrefixDemo
415
+ themes={{
416
+ default: {
417
+ hue: 280,
418
+ saturation: 80,
419
+ colors: {
420
+ surface: { tone: 100, saturation: 0.11 },
421
+ 'surface-text': {
422
+ base: 'surface',
423
+ tone: 2,
424
+ saturation: 0.475,
425
+ inherit: false,
426
+ },
427
+ 'accent-text': {
428
+ base: 'surface',
429
+ tone: '-1',
430
+ saturation: 1,
431
+ contrast: { apca: ['content', 'body'] },
432
+ },
433
+ },
434
+ },
435
+ danger: {
436
+ extends: 'default',
437
+ hue: 23,
438
+ colors: { surface: { tone: 96, saturation: 0.8 } },
439
+ },
440
+ }}
441
+ calls={[{}, { prefix: { default: '' } }, { primary: 'default' }]}
442
+ caption="Same palette, three prefix settings. surface-text is inherit: false, so the danger theme doesn't emit it."
443
+ />
444
+
445
+ The most common production pattern is a **default theme without a prefix and
446
+ every other theme prefixed with its name**:
447
+
448
+ ```ts
449
+ palette.tasty({
450
+ prefix: {
451
+ default: '',
452
+ primary: 'primary-',
453
+ success: 'success-',
454
+ danger: 'danger-',
455
+ warning: 'warning-',
456
+ note: 'note-',
457
+ },
458
+ });
459
+ ```
460
+
461
+ Neutral tokens are then consumed as `#surface`, `#border`, and
462
+ `#disabled-surface` (no theme namespace), while status colors live under
463
+ `#danger-surface`, `#success-accent-text`, and so on. Listing every theme
464
+ spells the namespace out; since unlisted themes fall back to `<themeName>-`,
465
+ `{ default: '' }` alone emits the same names.
466
+
467
+ An explicit map like this is usually the clearest choice for a palette with a
468
+ neutral `default` theme. The separate [`primary`](#the-primary-alias) option
469
+ solves a different problem: it duplicates one named theme without a prefix
470
+ while keeping that theme's prefixed tokens too.
471
+
472
+ ### Alias themes for legacy names
473
+
474
+ Register the same theme instance under two palette names to get identical
475
+ token values under two prefixes. This supports a legacy token name without
476
+ duplicating any definitions:
477
+
478
+ ```ts
479
+ const palette = glaze.palette({
480
+ default: defaultTheme,
481
+ primary: primaryTheme,
482
+ purple: primaryTheme, // legacy alias: same theme, different prefix
483
+ });
484
+
485
+ palette.tasty({
486
+ prefix: {
487
+ default: '',
488
+ primary: 'primary-',
489
+ purple: 'purple-', // emits #purple-surface alongside #primary-surface
490
+ },
491
+ });
492
+ ```
493
+
494
+ Both `#primary-surface` and `#purple-surface` resolve to exactly the same
495
+ color. Drop the alias once nothing references the legacy name.
496
+
497
+ <PrefixDemo
498
+ themes={{
499
+ default: {
500
+ hue: 280,
501
+ saturation: 80,
502
+ colors: {
503
+ surface: { tone: 100, saturation: 0.11 },
504
+ 'accent-text': {
505
+ base: 'surface',
506
+ tone: '-1',
507
+ saturation: 1,
508
+ contrast: { apca: ['content', 'body'] },
509
+ },
510
+ },
511
+ },
512
+ primary: {
513
+ extends: 'default',
514
+ colors: { surface: { tone: 96, saturation: 0.8 } },
515
+ },
516
+ purple: { alias: 'primary' },
517
+ }}
518
+ calls={[
519
+ { prefix: { default: '', primary: 'primary-', purple: 'purple-' } },
520
+ ]}
521
+ caption="The purple- names repeat the primary- colors exactly: both come from one theme instance."
522
+ />
523
+
524
+ ### The `primary` alias
525
+
526
+ `glaze.palette(themes, { primary })`, and the per-export `primary` option,
527
+ duplicate one theme's tokens **without** a prefix on top of whatever the prefix
528
+ setting produces. It is equivalent to listing that theme twice with different
529
+ prefixes, and it is useful when the primary theme is conceptually distinct
530
+ from `default` and you want its tokens both namespaced and short.
531
+
532
+ ```ts
533
+ const palette = glaze.palette({ brand, accent }, { primary: 'brand' });
534
+
535
+ palette.tokens();
536
+ // → {
537
+ // light: {
538
+ // 'brand-surface': '...',
539
+ // surface: '...',
540
+ // 'accent-surface': '...',
541
+ // ...
542
+ // },
543
+ // ...
544
+ // }
545
+ ```
546
+
547
+ Override it per call with `palette.tokens({ primary: 'accent' })`, or turn it
548
+ off with `palette.tokens({ primary: false })`. A `primary` that names no theme
549
+ in the palette throws.
550
+
551
+ ### Collisions
552
+
553
+ When two themes produce the same output name, whether through `prefix: false`,
554
+ a prefix map that gives two themes the same prefix, or a `primary` alias that
555
+ lands on names another theme already emits unprefixed, the **first-written
556
+ value wins** and Glaze warns about the rest:
557
+
558
+ ```text
559
+ glaze: token "surface" from theme "danger" collides with theme
560
+ "default" — skipping.
561
+ ```
562
+
563
+ Themes are written in palette order. A frequent cause is combining
564
+ `prefix: { default: '' }` with `primary`: both emit unprefixed names, so the
565
+ primary's alias collides with the default theme
566
+ (`token "surface" from theme "danger (primary)" collides with theme "default"`).
567
+ Choose one of the two patterns for the namespace your components expect.
568
+
569
+ ## Hue channels with `splitHue`
570
+
571
+ `splitHue: true` emits each hue as its own custom property and references it
572
+ with `var()` inside the colors, so you can re-skin the palette at runtime by
573
+ changing a single number:
574
+
575
+ ```ts
576
+ const brand = glaze(240, 18, { pastel: true });
577
+
578
+ brand.colors({
579
+ surface: { tone: 97 },
580
+ accent: { tone: 55, hue: '+20', saturation: 1 },
581
+ });
582
+
583
+ brand.css({ splitHue: true, name: 'brand' }).light;
584
+ ```
585
+
586
+ ```css
587
+ --brand-hue: 240;
588
+ --accent-hue: calc(var(--brand-hue) + 20);
589
+ --surface-color: oklch(0.97 0.0025 var(--brand-hue));
590
+ --accent-color: oklch(0.6175 0.0189 var(--accent-hue));
591
+ ```
592
+
593
+ The colors are declared on `:root`, and a custom property resolves `var()` on
594
+ the element that declares it, so set the hue there:
595
+
596
+ ```ts
597
+ document.documentElement.style.setProperty('--brand-hue', '150');
598
+ ```
599
+
600
+ In practice:
601
+
602
+ - **Pastel only.** Every exported color must be pastel (`pastel: true` on the
603
+ theme, the token, or the color), so its chroma stays inside sRGB at any hue.
604
+ Otherwise the export throws and names the non-pastel colors.
605
+ - **`oklch` only.** The hue slot is native CSS `var()` only in `oklch()`; with
606
+ another `format` the export throws.
607
+ - **One name per hue variable.** A color that sets its own hue gets
608
+ `--<color>-hue`, so it can't share its name with the theme hue (`name`), or,
609
+ in an unprefixed palette, with another theme. `css()` value properties share
610
+ the namespace, so `suffix: '-hue'` (or `suffix: ''` with a color named
611
+ `*-hue`) collides too. The export throws and names both sides rather than
612
+ let one silently override the other. A color that is gray in light declares
613
+ no hue variable, so it is exempt.
614
+ - **Palettes name the hue after the theme.** `palette.css({ splitHue: true })`
615
+ emits `--brand-hue`, `--brand-accent-hue`, and so on for a theme named
616
+ `brand`; a `primary` alias references the same hue variables.
617
+ - **Dark hues re-declare the set.** When the theme or a color has a
618
+ [dark hue](./schemes.mdx#dark-seed), the dark block repeats every hue
619
+ variable the light block declares, with its dark value. A color that is
620
+ gray in light stays a literal `oklch()` in every scheme.
621
+ - **Tasty** gets the hue variables as `$brand-hue`-style keys from
622
+ `tasty({ splitHue: true })`.
623
+
624
+ `splitHue` is available on `css()` and `tasty()` for themes and palettes, and on
625
+ a standalone color's `css()`. The full rules, including which colors stay
626
+ inline, are in the
627
+ [Output formats](./reference/output.md#hue-channel-splitting-splithue) reference.
628
+
629
+ ## Next steps
630
+
631
+ - [Migration and upgrading](./migration.md): move an existing color system to
632
+ Glaze, keep its token names, and upgrade between major versions.
633
+ - [Output formats](./reference/output.md): every output method and option.
634
+ - [Palettes](./reference/palette.md): palette options, prefix
635
+ behavior, and primary aliases.