@tenphi/glaze 0.0.0-snapshot.c3d484c → 0.0.0-snapshot.c61bbdf

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