@cognitap/radiant 0.0.3 → 0.0.5

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.
Files changed (118) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/README.md +28 -15
  3. package/dist/library/Card.d.ts.map +1 -1
  4. package/dist/library/Card.js +8 -6
  5. package/dist/library/Card.js.map +1 -1
  6. package/dist/library/Checkbox.js +2 -2
  7. package/dist/library/Checkbox.js.map +1 -1
  8. package/dist/library/Collapsible.d.ts.map +1 -1
  9. package/dist/library/Collapsible.js +5 -4
  10. package/dist/library/Collapsible.js.map +1 -1
  11. package/dist/library/Dialog.d.ts.map +1 -1
  12. package/dist/library/Dialog.js +8 -6
  13. package/dist/library/Dialog.js.map +1 -1
  14. package/dist/library/Field.js +4 -4
  15. package/dist/library/Field.js.map +1 -1
  16. package/dist/library/Input.d.ts.map +1 -1
  17. package/dist/library/Input.js +4 -3
  18. package/dist/library/Input.js.map +1 -1
  19. package/dist/library/Link.d.ts.map +1 -1
  20. package/dist/library/Link.js +0 -1
  21. package/dist/library/Link.js.map +1 -1
  22. package/dist/library/RadioGroup.js +2 -2
  23. package/dist/library/RadioGroup.js.map +1 -1
  24. package/dist/library/ThemeScope.js +1 -1
  25. package/dist/library/ThemeScope.js.map +1 -1
  26. package/dist/library/actionStyles.js +2 -2
  27. package/dist/library/actionStyles.js.map +1 -1
  28. package/dist/library/cn.d.ts +2 -1
  29. package/dist/library/cn.d.ts.map +1 -1
  30. package/dist/library/cn.js +22 -1
  31. package/dist/library/cn.js.map +1 -1
  32. package/dist/library/color/colorFamilies.d.ts +3 -0
  33. package/dist/library/color/colorFamilies.d.ts.map +1 -0
  34. package/dist/library/color/colorFamilies.js +20 -0
  35. package/dist/library/color/colorFamilies.js.map +1 -0
  36. package/dist/library/color/generateColorWall.d.ts +54 -0
  37. package/dist/library/color/generateColorWall.d.ts.map +1 -0
  38. package/dist/library/color/generateColorWall.js +231 -0
  39. package/dist/library/color/generateColorWall.js.map +1 -0
  40. package/dist/library/color/index.d.ts +5 -0
  41. package/dist/library/color/index.d.ts.map +1 -0
  42. package/dist/library/color/index.js +3 -0
  43. package/dist/library/color/index.js.map +1 -0
  44. package/dist/library/color/oklch.d.ts +17 -0
  45. package/dist/library/color/oklch.d.ts.map +1 -0
  46. package/dist/library/color/oklch.js +79 -0
  47. package/dist/library/color/oklch.js.map +1 -0
  48. package/dist/library/color/recommendColorPalette.d.ts +65 -0
  49. package/dist/library/color/recommendColorPalette.d.ts.map +1 -0
  50. package/dist/library/color/recommendColorPalette.js +263 -0
  51. package/dist/library/color/recommendColorPalette.js.map +1 -0
  52. package/dist/library/index.d.ts +10 -2
  53. package/dist/library/index.d.ts.map +1 -1
  54. package/dist/library/index.js +5 -1
  55. package/dist/library/index.js.map +1 -1
  56. package/dist/library/styles.css +1 -1
  57. package/dist/library/themes/defineTheme.d.ts.map +1 -1
  58. package/dist/library/themes/defineTheme.js +5 -1
  59. package/dist/library/themes/defineTheme.js.map +1 -1
  60. package/dist/library/themes/index.d.ts +4 -0
  61. package/dist/library/themes/index.d.ts.map +1 -1
  62. package/dist/library/themes/index.js +2 -0
  63. package/dist/library/themes/index.js.map +1 -1
  64. package/dist/library/themes/themeDocument.d.ts +16 -0
  65. package/dist/library/themes/themeDocument.d.ts.map +1 -0
  66. package/dist/library/themes/themeDocument.js +332 -0
  67. package/dist/library/themes/themeDocument.js.map +1 -0
  68. package/dist/library/themes/themeDocumentTypes.d.ts +80 -0
  69. package/dist/library/themes/themeDocumentTypes.d.ts.map +1 -0
  70. package/dist/library/themes/themeDocumentTypes.js +2 -0
  71. package/dist/library/themes/themeDocumentTypes.js.map +1 -0
  72. package/dist/library/themes/tokens.d.ts +7 -0
  73. package/dist/library/themes/tokens.d.ts.map +1 -1
  74. package/dist/library/themes/tokens.js +99 -0
  75. package/dist/library/themes/tokens.js.map +1 -1
  76. package/dist/library/themes/updateThemeAppearance.d.ts +29 -0
  77. package/dist/library/themes/updateThemeAppearance.d.ts.map +1 -0
  78. package/dist/library/themes/updateThemeAppearance.js +138 -0
  79. package/dist/library/themes/updateThemeAppearance.js.map +1 -0
  80. package/dist/library/typography/index.d.ts +72 -0
  81. package/dist/library/typography/index.d.ts.map +1 -0
  82. package/dist/library/typography/index.js +160 -0
  83. package/dist/library/typography/index.js.map +1 -0
  84. package/dist/library/typography/types.d.ts +78 -0
  85. package/dist/library/typography/types.d.ts.map +1 -0
  86. package/dist/library/typography/types.js +2 -0
  87. package/dist/library/typography/types.js.map +1 -0
  88. package/docs/system.md +20 -0
  89. package/docs/theming.md +616 -0
  90. package/package.json +17 -5
  91. package/src/Card.tsx +8 -6
  92. package/src/Checkbox.tsx +2 -2
  93. package/src/Collapsible.tsx +5 -4
  94. package/src/Dialog.tsx +8 -6
  95. package/src/Field.tsx +4 -4
  96. package/src/Input.tsx +4 -3
  97. package/src/Link.tsx +0 -1
  98. package/src/RadioGroup.tsx +2 -2
  99. package/src/ThemeScope.tsx +1 -1
  100. package/src/actionStyles.ts +2 -2
  101. package/src/cn.ts +25 -1
  102. package/src/color/colorFamilies.ts +19 -0
  103. package/src/color/generateColorWall.ts +358 -0
  104. package/src/color/index.ts +11 -0
  105. package/src/color/oklch.ts +95 -0
  106. package/src/color/recommendColorPalette.ts +375 -0
  107. package/src/index.ts +40 -0
  108. package/src/styles.css +1 -0
  109. package/src/themes/baseline.css +131 -0
  110. package/src/themes/defineTheme.ts +5 -1
  111. package/src/themes/index.ts +25 -0
  112. package/src/themes/themeDocument.ts +370 -0
  113. package/src/themes/themeDocumentTypes.ts +88 -0
  114. package/src/themes/tokens.ts +137 -0
  115. package/src/themes/updateThemeAppearance.ts +172 -0
  116. package/src/typography/index.ts +199 -0
  117. package/src/typography/types.ts +92 -0
  118. package/src/typography.css +336 -0
@@ -0,0 +1,375 @@
1
+ import type { SharedTokens } from '../themes/tokens.js'
2
+ import { freezeTree } from '../themes/tokens.js'
3
+ import { parseThemeDocument } from '../themes/themeDocument.js'
4
+ import type { ThemeColorSection, ThemePalette } from '../themes/themeDocumentTypes.js'
5
+ import type { ColorWall } from './generateColorWall.js'
6
+ import { colorFamilies } from './colorFamilies.js'
7
+ import { hueDifference, measureHex } from './oklch.js'
8
+
9
+ export type WorkingPaletteRole =
10
+ | 'primary'
11
+ | 'support'
12
+ | 'neutral'
13
+ | 'success'
14
+ | 'warning'
15
+ | 'danger'
16
+ type Mode = 'light' | 'dark'
17
+ type Colors = Readonly<SharedTokens['color']>
18
+ export type PaletteModeColors = Colors & { readonly canvas: string }
19
+ export interface ColorPaletteOptions {
20
+ readonly version?: 1
21
+ /** Existing wall palette IDs; originals and swatches are never rewritten. */
22
+ readonly working?: Readonly<Partial<Record<WorkingPaletteRole, string>>>
23
+ /** Explicit opaque sRGB overrides are retained, even when contrast fails. */
24
+ readonly modes?: {
25
+ readonly light?: Partial<PaletteModeColors>
26
+ readonly dark?: Partial<PaletteModeColors>
27
+ }
28
+ }
29
+ export interface PaletteColorPair {
30
+ readonly background: string
31
+ readonly foreground: string
32
+ }
33
+ export interface PaletteContrastCheck {
34
+ readonly mode: Mode
35
+ readonly foregroundRole: string
36
+ readonly backgroundRole: string
37
+ readonly foreground: string
38
+ readonly background: string
39
+ readonly ratio: number
40
+ /** null marks an inactive-control exception, not a passing contrast requirement. */
41
+ readonly minimum: 3 | 4.5 | null
42
+ readonly pass: boolean | null
43
+ readonly message: string
44
+ }
45
+ export interface ColorPalette {
46
+ readonly version: 1
47
+ readonly working: Readonly<
48
+ Record<
49
+ WorkingPaletteRole,
50
+ {
51
+ readonly paletteId: string
52
+ readonly light: PaletteColorPair
53
+ readonly dark: PaletteColorPair
54
+ }
55
+ >
56
+ >
57
+ readonly color: ThemeColorSection & {
58
+ readonly modes: { readonly light: Colors; readonly dark: Colors }
59
+ }
60
+ readonly surface: {
61
+ readonly modes: {
62
+ readonly light: { readonly canvas: string }
63
+ readonly dark: { readonly canvas: string }
64
+ }
65
+ }
66
+ readonly checks: readonly PaletteContrastCheck[]
67
+ readonly pass: boolean
68
+ }
69
+ const workingRoles = ['primary', 'support', 'neutral', 'success', 'warning', 'danger'] as const
70
+ const colorRoles = [
71
+ 'surface',
72
+ 'foreground',
73
+ 'mutedForeground',
74
+ 'border',
75
+ 'placeholder',
76
+ 'disabledBackground',
77
+ 'disabledBorder',
78
+ 'invalid',
79
+ 'focus',
80
+ 'accent',
81
+ 'accentForeground',
82
+ 'neutral',
83
+ 'neutralForeground',
84
+ 'warning',
85
+ 'warningForeground',
86
+ 'danger',
87
+ 'dangerForeground'
88
+ ] as const
89
+ const modes = ['light', 'dark'] as const
90
+ const hex = /^#[0-9a-f]{6}$/i
91
+ function object(value: unknown, path: string): asserts value is object {
92
+ if (!value || typeof value !== 'object' || Array.isArray(value))
93
+ throw new TypeError(`${path} must be an object.`)
94
+ }
95
+ function keys(value: object, allowed: readonly string[], path: string) {
96
+ for (const key of Object.keys(value))
97
+ if (!allowed.includes(key)) throw new TypeError(`Unknown ${path}.${key}.`)
98
+ }
99
+ function opaque(value: unknown, path: string): asserts value is string {
100
+ if (typeof value !== 'string' || !hex.test(value))
101
+ throw new TypeError(`${path} must be an opaque six-digit sRGB hex color.`)
102
+ }
103
+ function luminance(value: string) {
104
+ const [r, g, b] = [1, 3, 5]
105
+ .map(i => parseInt(value.slice(i, i + 2), 16) / 255)
106
+ .map(n => (n <= 0.04045 ? n / 12.92 : ((n + 0.055) / 1.055) ** 2.4))
107
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b
108
+ }
109
+ function contrast(a: string, b: string) {
110
+ const x = luminance(a),
111
+ y = luminance(b)
112
+ return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05)
113
+ }
114
+ const swatches = (palette: ThemePalette) => palette.swatches.map(s => s.value)
115
+ function choose(
116
+ values: readonly string[],
117
+ backgrounds: readonly string[],
118
+ minimum: number,
119
+ target: number
120
+ ): string {
121
+ const score = (value: string) => Math.min(...backgrounds.map(bg => contrast(value, bg)))
122
+ const valid = values.filter(value => score(value) >= minimum)
123
+ return valid.length
124
+ ? valid.reduce((a, b) =>
125
+ Math.abs(measureHex(a).L - target) <= Math.abs(measureHex(b).L - target) ? a : b
126
+ )
127
+ : values.reduce((a, b) => (score(a) >= score(b) ? a : b))
128
+ }
129
+ function pair(
130
+ values: readonly string[],
131
+ inks: readonly string[],
132
+ backgrounds: readonly string[],
133
+ target: number,
134
+ boundary: boolean,
135
+ fixedBackground?: string,
136
+ fixedForeground?: string,
137
+ source?: ReturnType<typeof measureHex>
138
+ ): PaletteColorPair {
139
+ const candidates = fixedBackground === undefined ? values : [fixedBackground]
140
+ const foregrounds = fixedForeground === undefined ? inks : [fixedForeground]
141
+ const ink = (background: string) =>
142
+ foregrounds.reduce((a, b) => (contrast(a, background) >= contrast(b, background) ? a : b))
143
+ const acceptable = candidates.filter(
144
+ bg =>
145
+ contrast(ink(bg), bg) >= 4.5 &&
146
+ (!boundary || backgrounds.every(surface => contrast(bg, surface) >= 3))
147
+ )
148
+ const pool = acceptable.length ? acceptable : candidates
149
+ // Perceptual distance includes both lightness and the chromatic axes. A caller's
150
+ // explicit working-family choice still bounds the candidate pool.
151
+ const distance = (value: string) => {
152
+ const color = measureHex(value)
153
+ if (!source) return Math.abs(color.L - target)
154
+ const radians = Math.PI / 180
155
+ return Math.hypot(
156
+ color.L - source.L,
157
+ color.C * Math.cos(color.h * radians) - source.C * Math.cos(source.h * radians),
158
+ color.C * Math.sin(color.h * radians) - source.C * Math.sin(source.h * radians)
159
+ )
160
+ }
161
+ const background = pool.reduce((a, b) => (distance(a) <= distance(b) ? a : b))
162
+ return { background, foreground: ink(background) }
163
+ }
164
+
165
+ /** Recommend a six-family working set and audit actual opaque semantic pairs. */
166
+ export function recommendColorPalette(
167
+ wall: ColorWall,
168
+ options: ColorPaletteOptions = {}
169
+ ): ColorPalette {
170
+ object(wall, 'colorWall')
171
+ object(wall.color, 'colorWall.color')
172
+ object(wall.input, 'colorWall.input')
173
+ if (wall.input.version !== 1) throw new TypeError('colorWall.input.version must be 1.')
174
+ if (wall.color.brand?.gamut !== 'srgb')
175
+ throw new TypeError('colorWall.color.brand.gamut must be srgb for semantic mapping version 1.')
176
+ const parsed = parseThemeDocument({
177
+ kind: 'radiant-theme-sections',
178
+ version: 1,
179
+ sections: { color: wall.color }
180
+ })
181
+ const color = parsed.sections.color!
182
+ if (!color.brand || !color.palettes?.length)
183
+ throw new TypeError('colorWall.color requires an original brand and populated palettes.')
184
+ opaque(color.brand.value, 'colorWall.color.brand.value')
185
+ for (const palette of color.palettes) {
186
+ const stops = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950]
187
+ if (
188
+ palette.swatches.length !== stops.length ||
189
+ palette.swatches.some((s, i) => s.stop !== stops[i])
190
+ )
191
+ throw new TypeError(
192
+ `colorWall.${palette.id} must contain the eleven ordered generator stops (50–950).`
193
+ )
194
+ for (const swatch of palette.swatches)
195
+ opaque(swatch.value, `colorWall.${palette.id}.${swatch.stop}`)
196
+ }
197
+ object(options, 'colorPalette')
198
+ keys(options, ['version', 'working', 'modes'], 'colorPalette')
199
+ if (options.version !== undefined && options.version !== 1)
200
+ throw new TypeError('Unsupported colorPalette.version; expected 1.')
201
+ if (options.working !== undefined) {
202
+ object(options.working, 'colorPalette.working')
203
+ keys(options.working, workingRoles, 'colorPalette.working')
204
+ for (const [role, id] of Object.entries(options.working))
205
+ if (id !== undefined && typeof id !== 'string')
206
+ throw new TypeError(`colorPalette.working.${role} must be a palette ID.`)
207
+ }
208
+ if (options.modes !== undefined) {
209
+ object(options.modes, 'colorPalette.modes')
210
+ keys(options.modes, modes, 'colorPalette.modes')
211
+ }
212
+ for (const mode of modes)
213
+ if (options.modes?.[mode] !== undefined) {
214
+ object(options.modes[mode], `colorPalette.modes.${mode}`)
215
+ keys(options.modes[mode], [...colorRoles, 'canvas'], `colorPalette.modes.${mode}`)
216
+ for (const [key, value] of Object.entries(options.modes[mode]))
217
+ if (value !== undefined) opaque(value, `colorPalette.modes.${mode}.${key}`)
218
+ }
219
+ function palette(id: string): ThemePalette {
220
+ const found = color.palettes!.find(p => p.id === id)
221
+ if (!found)
222
+ throw new TypeError(
223
+ `Unknown working palette ID: ${String(id)}. Choose one of: ${color.palettes!.map(p => p.id).join(', ')}.`
224
+ )
225
+ return found
226
+ }
227
+ const primary = palette(options.working?.primary ?? 'brand')
228
+ if (!Number.isFinite(wall.input.neutralHue) || !Number.isFinite(wall.input.hueAlignment))
229
+ throw new TypeError('colorWall.input must contain finite neutralHue and hueAlignment controls.')
230
+ const source = measureHex(color.brand.value)
231
+ const sourceHue = source.C < 0.02 ? wall.input.neutralHue : source.h
232
+ const nearest = colorFamilies.reduce((a, b) =>
233
+ Math.abs(hueDifference(sourceHue, a[1])) < Math.abs(hueDifference(sourceHue, b[1])) ? a : b
234
+ )
235
+ const rotation = hueDifference(sourceHue, nearest[1]) * wall.input.hueAlignment
236
+ function hueOf(p: ThemePalette) {
237
+ const sample = measureHex(p.swatches[Math.floor(p.swatches.length / 2)].value)
238
+ const nominal = colorFamilies.find(([name]) => name.toLowerCase() === p.id)
239
+ return sample.C >= 0.02 ? sample.h : nominal ? nominal[1] + rotation : sourceHue
240
+ }
241
+ const hue = hueOf(primary)
242
+ const supporting = color.palettes.filter(
243
+ p => p.id !== 'brand' && p.id !== 'neutral' && p.id !== primary.id
244
+ )
245
+ if (!supporting.length) throw new TypeError('colorWall requires supporting hue families.')
246
+ const support = supporting.reduce((a, b) => {
247
+ return Math.abs(hueDifference(hueOf(a), hue + 150)) <=
248
+ Math.abs(hueDifference(hueOf(b), hue + 150))
249
+ ? a
250
+ : b
251
+ })
252
+ const selected = {
253
+ primary: primary.id,
254
+ support: support.id,
255
+ neutral: 'neutral',
256
+ success: 'emerald',
257
+ warning: 'amber',
258
+ danger: 'red',
259
+ ...Object.fromEntries(
260
+ Object.entries(options.working ?? {}).filter(([, value]) => value !== undefined)
261
+ )
262
+ }
263
+ for (const id of Object.values(selected)) palette(id)
264
+ const working = {} as Record<
265
+ WorkingPaletteRole,
266
+ { paletteId: string; light: PaletteColorPair; dark: PaletteColorPair }
267
+ >
268
+ for (const role of workingRoles)
269
+ working[role] = {
270
+ paletteId: selected[role],
271
+ light: { background: '', foreground: '' },
272
+ dark: { background: '', foreground: '' }
273
+ }
274
+ const mapped = {} as Record<Mode, SharedTokens['color']>
275
+ const canvases = {} as Record<Mode, { canvas: string }>
276
+ const checks: PaletteContrastCheck[] = []
277
+ for (const mode of modes) {
278
+ const light = mode === 'light',
279
+ override = options.modes?.[mode] ?? {}
280
+ const neutrals = swatches(palette(selected.neutral))
281
+ const canvas = override.canvas ?? neutrals[light ? 0 : neutrals.length - 1]
282
+ const surface = override.surface ?? neutrals[light ? 1 : neutrals.length - 2]
283
+ const backgrounds = [canvas, surface]
284
+ const inks = [...neutrals, '#000000', '#FFFFFF']
285
+ const foreground = override.foreground ?? choose(inks, backgrounds, 7, light ? 0.21 : 0.985)
286
+ const muted = override.mutedForeground ?? choose(inks, backgrounds, 4.5, light ? 0.48 : 0.75)
287
+ const fills: Record<WorkingPaletteRole, [string | undefined, string | undefined]> = {
288
+ primary: [override.accent, override.accentForeground],
289
+ neutral: [override.neutral, override.neutralForeground],
290
+ warning: [override.warning, override.warningForeground],
291
+ danger: [override.danger, override.dangerForeground],
292
+ support: [undefined, undefined],
293
+ success: [undefined, undefined]
294
+ }
295
+ for (const role of workingRoles) {
296
+ working[role][mode] = pair(
297
+ swatches(palette(selected[role])),
298
+ inks,
299
+ backgrounds,
300
+ role === 'neutral' ? (light ? 0.93 : 0.43) : light ? 0.62 : 0.75,
301
+ role === 'primary',
302
+ ...fills[role],
303
+ role === 'primary' ? source : undefined
304
+ )
305
+ }
306
+ const colors: SharedTokens['color'] = {
307
+ surface,
308
+ foreground,
309
+ mutedForeground: muted,
310
+ placeholder: override.placeholder ?? muted,
311
+ border: override.border ?? choose(neutrals, backgrounds, 3, light ? 0.65 : 0.6),
312
+ focus: override.focus ?? choose(swatches(primary), backgrounds, 3, light ? 0.55 : 0.75),
313
+ invalid:
314
+ override.invalid ??
315
+ choose(swatches(palette(selected.danger)), backgrounds, 4.5, light ? 0.5 : 0.75),
316
+ disabledBackground: override.disabledBackground ?? neutrals[light ? 2 : neutrals.length - 3],
317
+ disabledBorder: override.disabledBorder ?? neutrals[light ? 3 : neutrals.length - 4],
318
+ accent: working.primary[mode].background,
319
+ accentForeground: working.primary[mode].foreground,
320
+ neutral: working.neutral[mode].background,
321
+ neutralForeground: working.neutral[mode].foreground,
322
+ warning: working.warning[mode].background,
323
+ warningForeground: working.warning[mode].foreground,
324
+ danger: working.danger[mode].background,
325
+ dangerForeground: working.danger[mode].foreground
326
+ }
327
+ mapped[mode] = colors
328
+ canvases[mode] = { canvas }
329
+ const values: Record<string, string> = {
330
+ ...colors,
331
+ canvas,
332
+ support: working.support[mode].background,
333
+ supportForeground: working.support[mode].foreground,
334
+ success: working.success[mode].background,
335
+ successForeground: working.success[mode].foreground
336
+ }
337
+ function check(fg: string, bg: string, minimum: 3 | 4.5 | null) {
338
+ const ratio = contrast(values[fg], values[bg]),
339
+ pass = minimum === null ? null : ratio >= minimum
340
+ checks.push({
341
+ mode,
342
+ foregroundRole: fg,
343
+ backgroundRole: bg,
344
+ foreground: values[fg],
345
+ background: values[bg],
346
+ ratio,
347
+ minimum,
348
+ pass,
349
+ message:
350
+ minimum === null
351
+ ? 'Inactive controls are exempt from minimum contrast; this token-pair ratio excludes component opacity/effects.'
352
+ : pass
353
+ ? ''
354
+ : `${fg} is ${ratio.toFixed(3)}:1 against ${bg}; requires ${minimum}:1 without rounding. Select another ${fg} shade or adjust ${bg}, then recheck the complete mode. The original brand and wall remain unchanged.`
355
+ })
356
+ }
357
+ for (const background of ['canvas', 'surface']) {
358
+ for (const foreground of ['foreground', 'mutedForeground', 'placeholder', 'invalid'])
359
+ check(foreground, background, 4.5)
360
+ for (const foreground of ['border', 'focus', 'accent']) check(foreground, background, 3)
361
+ }
362
+ for (const tone of ['accent', 'neutral', 'warning', 'danger', 'support', 'success'])
363
+ check(tone + 'Foreground', tone, 4.5)
364
+ check('mutedForeground', 'disabledBackground', null)
365
+ check('disabledBorder', 'surface', null)
366
+ }
367
+ return freezeTree({
368
+ version: 1 as const,
369
+ working,
370
+ color: { ...color, modes: mapped },
371
+ surface: { modes: canvases },
372
+ checks,
373
+ pass: checks.every(c => c.pass !== false)
374
+ })
375
+ }
package/src/index.ts CHANGED
@@ -68,6 +68,7 @@ export type {
68
68
  } from './Card.js'
69
69
  export {
70
70
  defineTheme,
71
+ updateThemeAppearance,
71
72
  themes,
72
73
  radiant,
73
74
  defaultTheme,
@@ -80,6 +81,8 @@ export {
80
81
  } from './themes/index.js'
81
82
  export type {
82
83
  SharedTokens,
84
+ ThemeAppearanceSettings,
85
+ ThemeGeometrySettings,
83
86
  Theme,
84
87
  ThemeComponentOverrides,
85
88
  ThemeDefinition,
@@ -91,4 +94,41 @@ export type {
91
94
  export { ThemeScope } from './ThemeScope.js'
92
95
  export type { ThemeScopeProps } from './ThemeScope.js'
93
96
  export type { ButtonProps, ButtonRenderProps, ButtonVariant } from './Button.js'
97
+ export { generateTypography, typographyPresets, typographyRoles } from './typography/index.js'
98
+ export type * from './typography/types.js'
94
99
  export type { ControlSize, Tone } from './presentation.js'
100
+
101
+ export {
102
+ defineThemeDocument,
103
+ parseThemeDocument,
104
+ compileThemeDocument,
105
+ updateThemeDocument,
106
+ exportThemeSections,
107
+ themeDocumentFromDefinition
108
+ } from './themes/index.js'
109
+ export type {
110
+ ThemeDocument,
111
+ ThemeSectionExport,
112
+ ThemeSections,
113
+ ThemeSectionName,
114
+ ThemeSection,
115
+ ThemeColorSection,
116
+ ThemeColorStop,
117
+ ThemeBrandSource,
118
+ ThemePalette,
119
+ ThemeTypographySection,
120
+ ThemeFontAxis,
121
+ ThemeFontMetadata
122
+ } from './themes/index.js'
123
+
124
+ export { generateColorWall, colorCalibrationPresets } from './color/index.js'
125
+ export type { ColorWall, ColorWallInput, ColorCalibrationPreset } from './color/index.js'
126
+ export { recommendColorPalette } from './color/index.js'
127
+ export type {
128
+ ColorPalette,
129
+ ColorPaletteOptions,
130
+ PaletteModeColors,
131
+ PaletteColorPair,
132
+ PaletteContrastCheck,
133
+ WorkingPaletteRole
134
+ } from './color/index.js'
package/src/styles.css CHANGED
@@ -1,4 +1,5 @@
1
1
  @import './themes/baseline.css';
2
+ @import './typography.css';
2
3
 
3
4
  @source '.';
4
5
  @source not './**/*.stories.*';
@@ -32,6 +32,137 @@
32
32
  --rad-color-danger: var(--_rad-light, oklch(0.56 0.19 25)) var(--_rad-dark, oklch(0.72 0.17 25));
33
33
  --rad-color-danger-foreground: var(--_rad-light, oklch(0.99 0 0))
34
34
  var(--_rad-dark, oklch(0.2 0.04 25));
35
+ --rad-typography-roles-prose-title-family: var(--rad-typography-family);
36
+ --rad-typography-roles-prose-title-size: 2.44140625rem;
37
+ --rad-typography-roles-prose-title-fluid-size: clamp(
38
+ 2.44140625rem,
39
+ calc(1.41143799rem + 4.29153442cqi),
40
+ 3.81469727rem
41
+ );
42
+ --rad-typography-roles-prose-title-weight: 600;
43
+ --rad-typography-roles-prose-title-line-height: 1.12;
44
+ --rad-typography-roles-prose-title-letter-spacing: -0.025em;
45
+ --rad-typography-roles-prose-title-measure: 22ch;
46
+ --rad-typography-roles-prose-heading-family: var(--rad-typography-family);
47
+ --rad-typography-roles-prose-heading-size: 1.5625rem;
48
+ --rad-typography-roles-prose-heading-fluid-size: clamp(
49
+ 1.5625rem,
50
+ calc(1.26953125rem + 1.22070313cqi),
51
+ 1.953125rem
52
+ );
53
+ --rad-typography-roles-prose-heading-weight: 600;
54
+ --rad-typography-roles-prose-heading-line-height: 1.25;
55
+ --rad-typography-roles-prose-heading-letter-spacing: -0.015em;
56
+ --rad-typography-roles-prose-heading-measure: 30ch;
57
+ --rad-typography-roles-prose-subheading-family: var(--rad-typography-family);
58
+ --rad-typography-roles-prose-subheading-size: 1.375rem;
59
+ --rad-typography-roles-prose-subheading-fluid-size: clamp(
60
+ 1.375rem,
61
+ calc(1.234375rem + 0.5859375cqi),
62
+ 1.5625rem
63
+ );
64
+ --rad-typography-roles-prose-subheading-weight: 600;
65
+ --rad-typography-roles-prose-subheading-line-height: 1.3;
66
+ --rad-typography-roles-prose-subheading-letter-spacing: -0.01em;
67
+ --rad-typography-roles-prose-subheading-measure: 36ch;
68
+ --rad-typography-roles-prose-body-family: var(--rad-typography-family);
69
+ --rad-typography-roles-prose-body-size: 1.25rem;
70
+ --rad-typography-roles-prose-body-fluid-size: 1.25rem;
71
+ --rad-typography-roles-prose-body-weight: 400;
72
+ --rad-typography-roles-prose-body-line-height: 1.6;
73
+ --rad-typography-roles-prose-body-letter-spacing: 0em;
74
+ --rad-typography-roles-prose-body-measure: 64ch;
75
+ --rad-typography-roles-prose-lead-family: var(--rad-typography-family);
76
+ --rad-typography-roles-prose-lead-size: 1.40625rem;
77
+ --rad-typography-roles-prose-lead-fluid-size: 1.40625rem;
78
+ --rad-typography-roles-prose-lead-weight: 400;
79
+ --rad-typography-roles-prose-lead-line-height: 1.5;
80
+ --rad-typography-roles-prose-lead-letter-spacing: 0em;
81
+ --rad-typography-roles-prose-lead-measure: 55ch;
82
+ --rad-typography-roles-prose-small-family: var(--rad-typography-family);
83
+ --rad-typography-roles-prose-small-size: 1rem;
84
+ --rad-typography-roles-prose-small-fluid-size: 1rem;
85
+ --rad-typography-roles-prose-small-weight: 400;
86
+ --rad-typography-roles-prose-small-line-height: 1.5;
87
+ --rad-typography-roles-prose-small-letter-spacing: 0em;
88
+ --rad-typography-roles-prose-small-measure: 64ch;
89
+ --rad-typography-roles-prose-quote-family: var(--rad-typography-family);
90
+ --rad-typography-roles-prose-quote-size: 1.5625rem;
91
+ --rad-typography-roles-prose-quote-fluid-size: 1.5625rem;
92
+ --rad-typography-roles-prose-quote-weight: 400;
93
+ --rad-typography-roles-prose-quote-line-height: 1.4;
94
+ --rad-typography-roles-prose-quote-letter-spacing: -0.01em;
95
+ --rad-typography-roles-prose-quote-measure: 64ch;
96
+ --rad-typography-roles-ui-title-family: var(--rad-typography-family);
97
+ --rad-typography-roles-ui-title-size: var(--rad-typography-heading-size);
98
+ --rad-typography-roles-ui-title-fluid-size: var(--rad-typography-heading-size);
99
+ --rad-typography-roles-ui-title-weight: var(--rad-typography-heading-weight);
100
+ --rad-typography-roles-ui-title-line-height: 1.3;
101
+ --rad-typography-roles-ui-title-letter-spacing: var(--rad-typography-letter-spacing);
102
+ --rad-typography-roles-ui-title-measure: none;
103
+ --rad-typography-roles-ui-body-family: var(--rad-typography-family);
104
+ --rad-typography-roles-ui-body-size: var(--rad-typography-body-size);
105
+ --rad-typography-roles-ui-body-fluid-size: var(--rad-typography-body-size);
106
+ --rad-typography-roles-ui-body-weight: var(--rad-typography-body-weight);
107
+ --rad-typography-roles-ui-body-line-height: 1.5;
108
+ --rad-typography-roles-ui-body-letter-spacing: var(--rad-typography-letter-spacing);
109
+ --rad-typography-roles-ui-body-measure: none;
110
+ --rad-typography-roles-ui-label-family: var(--rad-typography-family);
111
+ --rad-typography-roles-ui-label-size: var(--rad-typography-body-size);
112
+ --rad-typography-roles-ui-label-fluid-size: var(--rad-typography-body-size);
113
+ --rad-typography-roles-ui-label-weight: var(--rad-typography-label-weight);
114
+ --rad-typography-roles-ui-label-line-height: 1.4;
115
+ --rad-typography-roles-ui-label-letter-spacing: var(--rad-typography-letter-spacing);
116
+ --rad-typography-roles-ui-label-measure: none;
117
+ --rad-typography-roles-ui-supporting-family: var(--rad-typography-family);
118
+ --rad-typography-roles-ui-supporting-size: var(--rad-typography-small-size);
119
+ --rad-typography-roles-ui-supporting-fluid-size: var(--rad-typography-small-size);
120
+ --rad-typography-roles-ui-supporting-weight: var(--rad-typography-body-weight);
121
+ --rad-typography-roles-ui-supporting-line-height: 1.5;
122
+ --rad-typography-roles-ui-supporting-letter-spacing: var(--rad-typography-letter-spacing);
123
+ --rad-typography-roles-ui-supporting-measure: none;
124
+ --rad-typography-roles-ui-caption-family: var(--rad-typography-family);
125
+ --rad-typography-roles-ui-caption-size: 0.875rem;
126
+ --rad-typography-roles-ui-caption-fluid-size: 0.875rem;
127
+ --rad-typography-roles-ui-caption-weight: 400;
128
+ --rad-typography-roles-ui-caption-line-height: 1.5;
129
+ --rad-typography-roles-ui-caption-letter-spacing: 0em;
130
+ --rad-typography-roles-ui-caption-measure: none;
131
+ --rad-typography-roles-ui-metric-family: var(--rad-typography-family);
132
+ --rad-typography-roles-ui-metric-size: 2rem;
133
+ --rad-typography-roles-ui-metric-fluid-size: 2rem;
134
+ --rad-typography-roles-ui-metric-weight: 600;
135
+ --rad-typography-roles-ui-metric-line-height: 1.15;
136
+ --rad-typography-roles-ui-metric-letter-spacing: -0.03em;
137
+ --rad-typography-roles-ui-metric-measure: none;
138
+ --rad-typography-roles-ui-eyebrow-family: var(--rad-typography-family);
139
+ --rad-typography-roles-ui-eyebrow-size: 0.75rem;
140
+ --rad-typography-roles-ui-eyebrow-fluid-size: 0.75rem;
141
+ --rad-typography-roles-ui-eyebrow-weight: 600;
142
+ --rad-typography-roles-ui-eyebrow-line-height: 1.4;
143
+ --rad-typography-roles-ui-eyebrow-letter-spacing: 0.1em;
144
+ --rad-typography-roles-ui-eyebrow-measure: none;
145
+ --rad-typography-roles-display-family: var(--rad-typography-family);
146
+ --rad-typography-roles-display-size: 2.44140625rem;
147
+ --rad-typography-roles-display-fluid-size: clamp(
148
+ 2.44140625rem,
149
+ calc(0.69618225rem + 7.27176666cqi),
150
+ 4.76837158rem
151
+ );
152
+ --rad-typography-roles-display-weight: 600;
153
+ --rad-typography-roles-display-line-height: 1.06;
154
+ --rad-typography-roles-display-letter-spacing: -0.035em;
155
+ --rad-typography-roles-display-measure: 18ch;
156
+ --rad-typography-roles-code-family: ui-monospace, monospace;
157
+ --rad-typography-roles-code-size: 0.875rem;
158
+ --rad-typography-roles-code-fluid-size: 0.875rem;
159
+ --rad-typography-roles-code-weight: 400;
160
+ --rad-typography-roles-code-line-height: 1.65;
161
+ --rad-typography-roles-code-letter-spacing: 0em;
162
+ --rad-typography-roles-code-measure: 80ch;
163
+ --rad-typography-flow-paragraph: 1.25em;
164
+ --rad-typography-flow-heading-before: 2em;
165
+ --rad-typography-flow-heading-after: 0.625em;
35
166
  --rad-typography-family: system-ui, sans-serif;
36
167
  --rad-typography-body-size: 0.875rem;
37
168
  --rad-typography-small-size: 0.8125rem;
@@ -75,7 +75,11 @@ function validateTokens(value: unknown, baseline: object, path: string) {
75
75
  } else {
76
76
  validateScalar(
77
77
  item,
78
- key === 'disabledOpacity' ? 'opacity' : key.endsWith('Weight') ? 'weight' : 'css',
78
+ key === 'disabledOpacity'
79
+ ? 'opacity'
80
+ : key.endsWith('Weight') || key === 'weight'
81
+ ? 'weight'
82
+ : 'css',
79
83
  `${path}.${key}`
80
84
  )
81
85
  }
@@ -19,6 +19,8 @@ export type {
19
19
  ThemeTokens
20
20
  } from './types.js'
21
21
  export { defineTheme } from './defineTheme.js'
22
+ export { updateThemeAppearance } from './updateThemeAppearance.js'
23
+ export type { ThemeAppearanceSettings, ThemeGeometrySettings } from './updateThemeAppearance.js'
22
24
  export { radiant, defaultTheme, soft, expressive, glass, sharp, jelly, ticket }
23
25
 
24
26
  export const themes: readonly Theme[] = Object.freeze([
@@ -31,3 +33,26 @@ export const themes: readonly Theme[] = Object.freeze([
31
33
  jelly,
32
34
  ticket
33
35
  ])
36
+
37
+ export {
38
+ defineThemeDocument,
39
+ parseThemeDocument,
40
+ compileThemeDocument,
41
+ updateThemeDocument,
42
+ exportThemeSections,
43
+ themeDocumentFromDefinition
44
+ } from './themeDocument.js'
45
+ export type {
46
+ ThemeDocument,
47
+ ThemeSectionExport,
48
+ ThemeSections,
49
+ ThemeSectionName,
50
+ ThemeSection,
51
+ ThemeColorSection,
52
+ ThemeColorStop,
53
+ ThemeBrandSource,
54
+ ThemePalette,
55
+ ThemeTypographySection,
56
+ ThemeFontAxis,
57
+ ThemeFontMetadata
58
+ } from './themeDocument.js'