@tenphi/glaze 0.0.0-snapshot.d38eee5 → 0.0.0-snapshot.d79cac8

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,488 @@
1
+ ---
2
+ title: Getting started
3
+ description: Install Glaze, build a first theme step by step, and export it.
4
+ ---
5
+
6
+ import { Callout, Card, CodeGroup } from '@tenphi/cookbook/components';
7
+ import Example from '../docs-site/components/Example.astro';
8
+ import Swatches from '../docs-site/components/Swatches.tsx';
9
+ import UiPreview from '../docs-site/components/UiPreview.tsx';
10
+ import CardGrid from '../docs-site/components/home/CardGrid.tsx';
11
+ import ContrastSamples from '../docs-site/components/home/ContrastSamples.tsx';
12
+
13
+ This guide builds a small, complete theme — a surface, text, an accent, a
14
+ border, and a card shadow — and exports it as CSS. Every example renders live in
15
+ the scheme you're viewing, so switch the site's appearance to dark or high
16
+ contrast as you go.
17
+
18
+ ## Install
19
+
20
+ <CodeGroup
21
+ label="Install Glaze"
22
+ items={[
23
+ { label: 'pnpm', language: 'shell', code: 'pnpm add @tenphi/glaze' },
24
+ { label: 'npm', language: 'shell', code: 'npm install @tenphi/glaze' },
25
+ { label: 'yarn', language: 'shell', code: 'yarn add @tenphi/glaze' },
26
+ ]}
27
+ />
28
+
29
+ Glaze has no runtime dependencies. It ships ESM and CommonJS builds with type
30
+ definitions and runs in Node.js 20+, browsers, and edge runtimes.
31
+
32
+ ## Build a theme
33
+
34
+ ### 1. Seed and surface
35
+
36
+ A theme starts from a seed: a hue (0–360) and a saturation (0–100). Colors are
37
+ then defined on the **tone** scale, where 0 is black and 100 is white and equal
38
+ steps give equal contrast for neutrals (see [Tone and OKHST](./okhst.mdx)). The
39
+ page surface is a **root** color: it places itself with an absolute tone.
40
+
41
+ <Example hue={280} saturation={80} colors={{ surface: { tone: 97, saturation: 0.15 } }} />
42
+
43
+ A color's `saturation` is a factor of the seed: `0.15` is 15% of 80. It
44
+ defaults to `1`, the full seed saturation.
45
+
46
+ Each swatch prints the tone the current scheme renders. Ordinary light and dark
47
+ schemes fit tones into a window, so tone 97 renders as 97.1 in light; dark mode
48
+ inverts the scale, so the surface turns dark. High-contrast schemes use the
49
+ full range. [Light, dark, and high contrast](./schemes.mdx) covers the details.
50
+
51
+ ### 2. Text with a contrast floor
52
+
53
+ Text is a **dependent** color: it names a `base` and a signed **tone delta**
54
+ from it. `'-1'` means one tone darker than the surface — unreadable on its own.
55
+ The `contrast` floor fixes that: Glaze moves the color away from its base until
56
+ the WCAG ratio passes (`'AA'` is 4.5:1, `'AAA'` is 7:1), and stops at the floor
57
+ or just past it.
58
+
59
+ ```ts
60
+ theme.colors({
61
+ 'surface-text': {
62
+ base: 'surface',
63
+ tone: '-1',
64
+ saturation: 0.4,
65
+ contrast: 'AAA',
66
+ },
67
+ 'surface-text-soft': {
68
+ base: 'surface',
69
+ tone: '-1',
70
+ saturation: 0.3,
71
+ contrast: 'AA',
72
+ },
73
+ });
74
+ ```
75
+
76
+ <ContrastSamples
77
+ hue={280}
78
+ saturation={80}
79
+ colors={{
80
+ surface: { tone: 97, saturation: 0.15 },
81
+ 'surface-text': {
82
+ base: 'surface',
83
+ tone: '-1',
84
+ saturation: 0.4,
85
+ contrast: 'AAA',
86
+ },
87
+ 'surface-text-soft': {
88
+ base: 'surface',
89
+ tone: '-1',
90
+ saturation: 0.3,
91
+ contrast: 'AA',
92
+ },
93
+ }}
94
+ samples={[
95
+ { fg: 'surface-text', bg: 'surface', note: "contrast: 'AAA'" },
96
+ { fg: 'surface-text-soft', bg: 'surface', note: "contrast: 'AA'" },
97
+ ]}
98
+ caption="Each tile measures the resolved text against the surface in the scheme you're viewing."
99
+ />
100
+
101
+ `theme.colors()` merges: it adds new colors and replaces existing ones by name,
102
+ so a theme can grow over several calls.
103
+
104
+ The delta follows its base into every scheme. In dark mode the scale inverts, so
105
+ one tone darker becomes about 0.87 tones lighter (the dark window is a little
106
+ narrower than the full scale) and the text turns light. In high contrast,
107
+ `'AA'` rises to `'AAA'`, so both colors meet 7:1. For APCA instead of WCAG,
108
+ write the floor as `{ apca: 'body' }` — see
109
+ [Contrast solving](./contrast.mdx).
110
+
111
+ ### 3. An accent that keeps its contrast
112
+
113
+ A primary button needs a fill and a label that read well together in every
114
+ scheme. Pin the label, then solve the fill against it:
115
+
116
+ ```ts
117
+ theme.colors({
118
+ 'accent-surface-text': { tone: 100, mode: 'fixed' },
119
+ 'accent-surface': {
120
+ base: 'accent-surface-text',
121
+ tone: '-1',
122
+ contrast: 'AA',
123
+ mode: 'fixed',
124
+ },
125
+ 'accent-text': { base: 'surface', tone: '-1', contrast: 'AA' },
126
+ });
127
+ ```
128
+
129
+ <ContrastSamples
130
+ hue={280}
131
+ saturation={80}
132
+ colors={{
133
+ surface: { tone: 97, saturation: 0.15 },
134
+ 'accent-surface-text': { tone: 100, mode: 'fixed' },
135
+ 'accent-surface': {
136
+ base: 'accent-surface-text',
137
+ tone: '-1',
138
+ contrast: 'AA',
139
+ mode: 'fixed',
140
+ },
141
+ 'accent-text': { base: 'surface', tone: '-1', contrast: 'AA' },
142
+ }}
143
+ samples={[
144
+ { fg: 'accent-surface-text', bg: 'accent-surface', note: 'button label on fill' },
145
+ { fg: 'accent-text', bg: 'surface', note: 'link on the surface' },
146
+ ]}
147
+ />
148
+
149
+ - The label sits at tone 100: white in light and high contrast, and near-white
150
+ (tone 95.9) in dark, where the dark tone window caps it. The fill starts one
151
+ tone below the label and moves down until the pair clears 4.5:1, landing
152
+ just past the floor at about 4.55:1 (the solver keeps a 1% margin). Because
153
+ the fill depends on the label, the pair passes in every scheme — in high
154
+ contrast the fill darkens further, until the pair clears 7:1.
155
+ - `mode: 'fixed'` keeps both colors on their authored side of the tone scale in
156
+ dark mode, so the button stays a saturated fill with a light label. The
157
+ default, `mode: 'auto'`, inverts.
158
+ - `accent-text` is a link color for the page. It uses the full seed saturation
159
+ and the same `'AA'` floor as the soft text.
160
+
161
+ ### 4. A border with a high-contrast pair
162
+
163
+ ```ts
164
+ theme.colors({
165
+ border: {
166
+ base: 'surface',
167
+ tone: ['-8', '-16'],
168
+ saturation: 0.2,
169
+ },
170
+ });
171
+ ```
172
+
173
+ <Swatches
174
+ hue={280}
175
+ saturation={80}
176
+ colors={{
177
+ surface: { tone: 97, saturation: 0.15 },
178
+ border: { base: 'surface', tone: ['-8', '-16'], saturation: 0.2 },
179
+ }}
180
+ />
181
+
182
+ Many values accept a `[normal, highContrast]` pair. The border sits 8 tones
183
+ from the surface in light, about 7 in dark (the dark tone window scales relative
184
+ steps down a little), and exactly 16 in both high-contrast schemes. It has no
185
+ contrast floor: a border is a visible step, not text.
186
+
187
+ ### 5. A card shadow
188
+
189
+ ```ts
190
+ theme.colors({
191
+ 'card-shadow': {
192
+ type: 'shadow',
193
+ bg: 'surface',
194
+ intensity: 8,
195
+ },
196
+ });
197
+ ```
198
+
199
+ A `shadow` is a translucent overlay, black by default, whose opacity Glaze
200
+ solves so that once the browser composites it over `bg`, the surface lands
201
+ exactly `intensity` tones darker, in every scheme where it has room for the
202
+ step. `bg` is the surface the shadow falls on. Add `fg` — the element casting
203
+ the shadow — and a darker object casts a deeper shadow.
204
+
205
+ That completes the theme. Here it is on a small product card, in the scheme
206
+ you're viewing:
207
+
208
+ <UiPreview
209
+ hue={280}
210
+ saturation={80}
211
+ colors={{
212
+ surface: { tone: 97, saturation: 0.15 },
213
+ 'surface-text': {
214
+ base: 'surface',
215
+ tone: '-1',
216
+ saturation: 0.4,
217
+ contrast: 'AAA',
218
+ },
219
+ 'surface-text-soft': {
220
+ base: 'surface',
221
+ tone: '-1',
222
+ saturation: 0.3,
223
+ contrast: 'AA',
224
+ },
225
+ 'accent-surface-text': { tone: 100, mode: 'fixed' },
226
+ 'accent-surface': {
227
+ base: 'accent-surface-text',
228
+ tone: '-1',
229
+ contrast: 'AA',
230
+ mode: 'fixed',
231
+ },
232
+ 'accent-text': { base: 'surface', tone: '-1', contrast: 'AA' },
233
+ border: { base: 'surface', tone: ['-8', '-16'], saturation: 0.2 },
234
+ 'card-shadow': { type: 'shadow', bg: 'surface', intensity: 8 },
235
+ }}
236
+ roles={{
237
+ page: 'surface',
238
+ card: 'surface',
239
+ border: 'border',
240
+ text: 'surface-text',
241
+ textSoft: 'surface-text-soft',
242
+ link: 'accent-text',
243
+ accent: 'accent-surface',
244
+ accentLabel: 'accent-surface-text',
245
+ shadow: 'card-shadow',
246
+ }}
247
+ />
248
+
249
+ <Callout kind="note" title="The shadow in dark high contrast">
250
+ The dark high-contrast surface renders at tone 3, which leaves room for only
251
+ 3 tones of shadow. Glaze uses the strongest shadow it can — opaque black —
252
+ and logs a one-time console warning; on a surface that is already black, the
253
+ shadow would be transparent. Dark interfaces usually show elevation with a
254
+ `glow`, the lightening mirror of a shadow; see
255
+ [Shadows and glows](./shadows-and-glows.mdx).
256
+ </Callout>
257
+
258
+ ## See all four schemes
259
+
260
+ Glaze resolves every color in four **scheme variants**: `light`, `dark`,
261
+ `lightContrast`, and `darkContrast`. Here is the whole theme in one place, with
262
+ each scheme on its own background:
263
+
264
+ <Example
265
+ hue={280}
266
+ saturation={80}
267
+ visual="schemes"
268
+ colors={{
269
+ surface: { tone: 97, saturation: 0.15 },
270
+ 'surface-text': {
271
+ base: 'surface',
272
+ tone: '-1',
273
+ saturation: 0.4,
274
+ contrast: 'AAA',
275
+ },
276
+ 'surface-text-soft': {
277
+ base: 'surface',
278
+ tone: '-1',
279
+ saturation: 0.3,
280
+ contrast: 'AA',
281
+ },
282
+ 'accent-surface-text': { tone: 100, mode: 'fixed' },
283
+ 'accent-surface': {
284
+ base: 'accent-surface-text',
285
+ tone: '-1',
286
+ contrast: 'AA',
287
+ mode: 'fixed',
288
+ },
289
+ 'accent-text': { base: 'surface', tone: '-1', contrast: 'AA' },
290
+ border: { base: 'surface', tone: ['-8', '-16'], saturation: 0.2 },
291
+ 'card-shadow': { type: 'shadow', bg: 'surface', intensity: 8 },
292
+ }}
293
+ roles={{
294
+ page: 'surface',
295
+ card: 'surface',
296
+ border: 'border',
297
+ text: 'surface-text',
298
+ textSoft: 'surface-text-soft',
299
+ link: 'accent-text',
300
+ accent: 'accent-surface',
301
+ accentLabel: 'accent-surface-text',
302
+ shadow: 'card-shadow',
303
+ }}
304
+ />
305
+
306
+ `css()` always returns all four variants. The other output methods include
307
+ `light` and `dark` by default; turn on the high-contrast variants once for the
308
+ whole app:
309
+
310
+ ```ts
311
+ glaze.configure({
312
+ modes: { dark: true, highContrast: true },
313
+ });
314
+ ```
315
+
316
+ or for one call, with `theme.tokens({ modes: { highContrast: true } })`.
317
+
318
+ ## Export it
319
+
320
+ Output methods resolve the theme and return the colors in the shape your stack
321
+ consumes. Colors are native `oklch()` by default; pass `format: 'rgb'` or
322
+ `'hsl'` for other notations.
323
+
324
+ ### CSS custom properties
325
+
326
+ `theme.css()` returns one block of declarations per scheme variant. Each color
327
+ becomes a `--<name>-color` property (pass `suffix: ''` to drop `-color`). Wrap
328
+ the blocks in the selectors that switch your schemes — here, the light block on
329
+ `:root` and the dark block in a media query:
330
+
331
+ <Example
332
+ hue={280}
333
+ saturation={80}
334
+ visual="none"
335
+ output="css"
336
+ label="styles.ts"
337
+ colors={{
338
+ surface: { tone: 97, saturation: 0.15 },
339
+ 'surface-text': {
340
+ base: 'surface',
341
+ tone: '-1',
342
+ saturation: 0.4,
343
+ contrast: 'AAA',
344
+ },
345
+ 'surface-text-soft': {
346
+ base: 'surface',
347
+ tone: '-1',
348
+ saturation: 0.3,
349
+ contrast: 'AA',
350
+ },
351
+ 'accent-surface-text': { tone: 100, mode: 'fixed' },
352
+ 'accent-surface': {
353
+ base: 'accent-surface-text',
354
+ tone: '-1',
355
+ contrast: 'AA',
356
+ mode: 'fixed',
357
+ },
358
+ 'accent-text': { base: 'surface', tone: '-1', contrast: 'AA' },
359
+ border: { base: 'surface', tone: ['-8', '-16'], saturation: 0.2 },
360
+ 'card-shadow': { type: 'shadow', bg: 'surface', intensity: 8 },
361
+ }}
362
+ code={[
363
+ "const css = theme.css({ format: 'rgb' });",
364
+ '',
365
+ 'const stylesheet = `',
366
+ ':root {',
367
+ '${css.light}',
368
+ '}',
369
+ '',
370
+ '@media (prefers-color-scheme: dark) {',
371
+ ' :root {',
372
+ '${css.dark}',
373
+ ' }',
374
+ '}`;',
375
+ ].join('\n')}
376
+ />
377
+
378
+ Components then read the variables, for example
379
+ `background: var(--surface-color)`.
380
+
381
+ ### Other formats
382
+
383
+ Each export is one call:
384
+
385
+ ```ts
386
+ theme.tokens(); // scheme → color → value
387
+ theme.json(); // color → scheme → value
388
+ theme.tasty(); // Tasty '#color' tokens with state maps
389
+ theme.tailwind(); // Tailwind CSS v4 @theme block + overrides
390
+ theme.dtcg(); // one W3C DTCG token tree per scheme
391
+ theme.dtcgResolver(); // one DTCG Resolver-Module document
392
+ ```
393
+
394
+ - `tokens()` and `json()` return plain JavaScript data, grouped by scheme or by
395
+ color.
396
+ - `tasty()` returns [Tasty](https://tasty.style) `#token` bindings keyed by
397
+ state, and also accepts Tasty's own `okhsl` and `okhst` formats.
398
+ - `tailwind()` returns a Tailwind CSS v4 `@theme` block plus scheme overrides,
399
+ so `bg-surface` and `text-surface-text` work out of the box.
400
+ - `dtcg()` returns one W3C design-token tree per scheme for Figma, Tokens
401
+ Studio, Style Dictionary, and other DTCG tools; `dtcgResolver()` puts every
402
+ scheme in one document.
403
+
404
+ To save the definitions themselves rather than resolved colors, call
405
+ `theme.export()` and restore the snapshot with `glaze.themeFrom()`.
406
+ [Exporting and integration](./exporting.mdx) covers choosing an export, wiring
407
+ it into your app, and multi-theme palettes;
408
+ [Output formats](./reference/output.md) lists every option.
409
+
410
+ ## One color without a theme
411
+
412
+ When you need a single adaptive color, or a pair with a contrast floor, skip the
413
+ theme and use `glaze.color()`:
414
+
415
+ ```ts
416
+ import { glaze } from '@tenphi/glaze';
417
+
418
+ const surface = glaze.color('#f6f5fa');
419
+ const brandText = glaze.color({
420
+ from: '#7a4dbf',
421
+ base: surface,
422
+ contrast: 'AA',
423
+ });
424
+
425
+ brandText.css({ name: 'brand-text' });
426
+ // → {
427
+ // light: '--brand-text-color: oklch(0.5276 0.172 298.52);',
428
+ // dark: '--brand-text-color: oklch(0.6588 0.1367 298.52);',
429
+ // lightContrast: '…',
430
+ // darkContrast: '…',
431
+ // }
432
+ ```
433
+
434
+ The light variant reproduces `#7a4dbf` exactly because it already passes 4.5:1
435
+ on that surface. The dark and high-contrast variants adapt, and the floor holds
436
+ in each of them. See [Color tokens](./reference/color-tokens.md).
437
+
438
+ ## Concepts at a glance
439
+
440
+ 1. **A theme has one hue and saturation seed**, optionally with a separate pair
441
+ for the dark schemes ([dark seed](./schemes.mdx#dark-seed)). Status themes
442
+ come from `extend()`: they inherit the same relationships with a different
443
+ hue. See [Designing a palette](./methodology.mdx).
444
+ 2. **A color is a root or a dependent.** Roots use an absolute `tone` or the
445
+ scheme extremes `'max'` / `'min'`. Dependents name a `base` and may use a
446
+ signed tone delta such as `'-8'` plus a `contrast` floor.
447
+ 3. **Tone is an authoring axis, not a contrast guarantee.** Equal tone deltas
448
+ are exact WCAG steps for neutrals. Chromatic colors can drift in rendered
449
+ luminance, so Glaze measures contrast floors against the resolved colors.
450
+ See [Tone and OKHST](./okhst.mdx).
451
+ 4. **`contrast` is a floor.** A bare number or preset means WCAG; `{ wcag }`
452
+ and `{ apca }` pick the metric explicitly. The solver keeps the requested
453
+ tone whenever it already passes with a small margin (1% over a WCAG ratio,
454
+ 0.5 Lc over an APCA target). See [Contrast solving](./contrast.mdx).
455
+ 5. **Each color chooses its dark adaptation.** `mode: 'auto'` inverts tone
456
+ (`100 − t`), `'fixed'` keeps the authored side of the scale, and `'static'`
457
+ skips scheme adaptation. See
458
+ [Light, dark, and high contrast](./schemes.mdx).
459
+ 6. **Tone windows bound the ordinary schemes.** `lightTone` and `darkTone` set
460
+ the light and dark tone windows; high-contrast variants use the full range.
461
+ Values that accept `[normal, highContrast]` pairs can tighten deliberately in
462
+ high contrast.
463
+
464
+ Output `modes` choose which scheme variants an export includes. In Tasty, the
465
+ `states` option chooses how those variants are activated in your app.
466
+
467
+ ## Next steps
468
+
469
+ <CardGrid>
470
+ <Card title="Design a palette" href="/methodology">
471
+ Surface ladders, accents, disabled states, effects, and status themes,
472
+ built up step by step.
473
+ </Card>
474
+ <Card title="Export and integrate" href="/exporting">
475
+ Pick an export shape and wire it into CSS, Tailwind, Tasty, JSON, or
476
+ design-token tools.
477
+ </Card>
478
+ <Card title="Concepts" href="/schemes">
479
+ How schemes, contrast floors, shadows and glows, and mixes work, down to
480
+ the tone model under them.
481
+ </Card>
482
+ <Card title="API reference" href="/reference">
483
+ Every function, method, option, and type.
484
+ </Card>
485
+ </CardGrid>
486
+
487
+ To explore the tone axis interactively, open the
488
+ [playground](https://glaze.tenphi.me/playground/).