@cognitap/radiant 0.0.2 → 0.0.4

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 (230) hide show
  1. package/CHANGELOG.md +357 -0
  2. package/README.md +944 -29
  3. package/dist/library/Accordion.d.ts +56 -0
  4. package/dist/library/Accordion.d.ts.map +1 -0
  5. package/dist/library/Accordion.js +89 -0
  6. package/dist/library/Accordion.js.map +1 -0
  7. package/dist/library/Button.d.ts +25 -3
  8. package/dist/library/Button.d.ts.map +1 -1
  9. package/dist/library/Button.js +31 -3
  10. package/dist/library/Button.js.map +1 -1
  11. package/dist/library/Card.d.ts +31 -0
  12. package/dist/library/Card.d.ts.map +1 -0
  13. package/dist/library/Card.js +69 -0
  14. package/dist/library/Card.js.map +1 -0
  15. package/dist/library/Checkbox.d.ts +13 -0
  16. package/dist/library/Checkbox.d.ts.map +1 -0
  17. package/dist/library/Checkbox.js +77 -0
  18. package/dist/library/Checkbox.js.map +1 -0
  19. package/dist/library/Collapsible.d.ts +32 -0
  20. package/dist/library/Collapsible.d.ts.map +1 -0
  21. package/dist/library/Collapsible.js +99 -0
  22. package/dist/library/Collapsible.js.map +1 -0
  23. package/dist/library/Dialog.d.ts +50 -0
  24. package/dist/library/Dialog.d.ts.map +1 -0
  25. package/dist/library/Dialog.js +215 -0
  26. package/dist/library/Dialog.js.map +1 -0
  27. package/dist/library/Field.d.ts +68 -0
  28. package/dist/library/Field.d.ts.map +1 -0
  29. package/dist/library/Field.js +114 -0
  30. package/dist/library/Field.js.map +1 -0
  31. package/dist/library/Input.d.ts +10 -0
  32. package/dist/library/Input.d.ts.map +1 -0
  33. package/dist/library/Input.js +51 -0
  34. package/dist/library/Input.js.map +1 -0
  35. package/dist/library/Link.d.ts +27 -0
  36. package/dist/library/Link.d.ts.map +1 -0
  37. package/dist/library/Link.js +50 -0
  38. package/dist/library/Link.js.map +1 -0
  39. package/dist/library/RadioGroup.d.ts +27 -0
  40. package/dist/library/RadioGroup.d.ts.map +1 -0
  41. package/dist/library/RadioGroup.js +103 -0
  42. package/dist/library/RadioGroup.js.map +1 -0
  43. package/dist/library/ThemeScope.d.ts +10 -0
  44. package/dist/library/ThemeScope.d.ts.map +1 -0
  45. package/dist/library/ThemeScope.js +41 -0
  46. package/dist/library/ThemeScope.js.map +1 -0
  47. package/dist/library/actionStyles.d.ts +11 -0
  48. package/dist/library/actionStyles.d.ts.map +1 -0
  49. package/dist/library/actionStyles.js +75 -0
  50. package/dist/library/actionStyles.js.map +1 -0
  51. package/dist/library/cn.d.ts +1 -2
  52. package/dist/library/cn.d.ts.map +1 -1
  53. package/dist/library/cn.js +1 -8
  54. package/dist/library/cn.js.map +1 -1
  55. package/dist/library/color/colorFamilies.d.ts +3 -0
  56. package/dist/library/color/colorFamilies.d.ts.map +1 -0
  57. package/dist/library/color/colorFamilies.js +20 -0
  58. package/dist/library/color/colorFamilies.js.map +1 -0
  59. package/dist/library/color/generateColorWall.d.ts +54 -0
  60. package/dist/library/color/generateColorWall.d.ts.map +1 -0
  61. package/dist/library/color/generateColorWall.js +231 -0
  62. package/dist/library/color/generateColorWall.js.map +1 -0
  63. package/dist/library/color/index.d.ts +5 -0
  64. package/dist/library/color/index.d.ts.map +1 -0
  65. package/dist/library/color/index.js +3 -0
  66. package/dist/library/color/index.js.map +1 -0
  67. package/dist/library/color/oklch.d.ts +17 -0
  68. package/dist/library/color/oklch.d.ts.map +1 -0
  69. package/dist/library/color/oklch.js +79 -0
  70. package/dist/library/color/oklch.js.map +1 -0
  71. package/dist/library/color/recommendColorPalette.d.ts +65 -0
  72. package/dist/library/color/recommendColorPalette.d.ts.map +1 -0
  73. package/dist/library/color/recommendColorPalette.js +263 -0
  74. package/dist/library/color/recommendColorPalette.js.map +1 -0
  75. package/dist/library/controlStyles.d.ts +5 -0
  76. package/dist/library/controlStyles.d.ts.map +1 -0
  77. package/dist/library/controlStyles.js +15 -0
  78. package/dist/library/controlStyles.js.map +1 -0
  79. package/dist/library/index.d.ts +30 -1
  80. package/dist/library/index.d.ts.map +1 -1
  81. package/dist/library/index.js +14 -0
  82. package/dist/library/index.js.map +1 -1
  83. package/dist/library/internal/events.d.ts +8 -0
  84. package/dist/library/internal/events.d.ts.map +1 -0
  85. package/dist/library/internal/events.js +13 -0
  86. package/dist/library/internal/events.js.map +1 -0
  87. package/dist/library/internal/ids.d.ts +3 -0
  88. package/dist/library/internal/ids.d.ts.map +1 -0
  89. package/dist/library/internal/ids.js +6 -0
  90. package/dist/library/internal/ids.js.map +1 -0
  91. package/dist/library/internal/selection.d.ts +5 -0
  92. package/dist/library/internal/selection.d.ts.map +1 -0
  93. package/dist/library/internal/selection.js +18 -0
  94. package/dist/library/internal/selection.js.map +1 -0
  95. package/dist/library/presentation.d.ts +18 -0
  96. package/dist/library/presentation.d.ts.map +1 -0
  97. package/dist/library/presentation.js +2 -0
  98. package/dist/library/presentation.js.map +1 -0
  99. package/dist/library/react/useComposedRefs.d.ts +4 -0
  100. package/dist/library/react/useComposedRefs.d.ts.map +1 -0
  101. package/dist/library/react/useComposedRefs.js +28 -0
  102. package/dist/library/react/useComposedRefs.js.map +1 -0
  103. package/dist/library/react/useControllableState.d.ts +16 -0
  104. package/dist/library/react/useControllableState.d.ts.map +1 -0
  105. package/dist/library/react/useControllableState.js +29 -0
  106. package/dist/library/react/useControllableState.js.map +1 -0
  107. package/dist/library/react/useNativeOwner.d.ts +17 -0
  108. package/dist/library/react/useNativeOwner.d.ts.map +1 -0
  109. package/dist/library/react/useNativeOwner.js +17 -0
  110. package/dist/library/react/useNativeOwner.js.map +1 -0
  111. package/dist/library/reset.css +1 -0
  112. package/dist/library/styles.css +2 -1
  113. package/dist/library/themes/components.d.ts +217 -0
  114. package/dist/library/themes/components.d.ts.map +1 -0
  115. package/dist/library/themes/components.js +229 -0
  116. package/dist/library/themes/components.js.map +1 -0
  117. package/dist/library/themes/default.d.ts +2 -0
  118. package/dist/library/themes/default.d.ts.map +1 -0
  119. package/dist/library/themes/default.js +4 -0
  120. package/dist/library/themes/default.js.map +1 -0
  121. package/dist/library/themes/defineTheme.d.ts +33 -0
  122. package/dist/library/themes/defineTheme.d.ts.map +1 -0
  123. package/dist/library/themes/defineTheme.js +98 -0
  124. package/dist/library/themes/defineTheme.js.map +1 -0
  125. package/dist/library/themes/expressive.d.ts +2 -0
  126. package/dist/library/themes/expressive.d.ts.map +1 -0
  127. package/dist/library/themes/expressive.js +132 -0
  128. package/dist/library/themes/expressive.js.map +1 -0
  129. package/dist/library/themes/glass.d.ts +2 -0
  130. package/dist/library/themes/glass.d.ts.map +1 -0
  131. package/dist/library/themes/glass.js +132 -0
  132. package/dist/library/themes/glass.js.map +1 -0
  133. package/dist/library/themes/index.d.ts +18 -0
  134. package/dist/library/themes/index.d.ts.map +1 -0
  135. package/dist/library/themes/index.js +23 -0
  136. package/dist/library/themes/index.js.map +1 -0
  137. package/dist/library/themes/jelly.d.ts +2 -0
  138. package/dist/library/themes/jelly.d.ts.map +1 -0
  139. package/dist/library/themes/jelly.js +130 -0
  140. package/dist/library/themes/jelly.js.map +1 -0
  141. package/dist/library/themes/preset-values.d.ts +4 -0
  142. package/dist/library/themes/preset-values.d.ts.map +1 -0
  143. package/dist/library/themes/preset-values.js +5 -0
  144. package/dist/library/themes/preset-values.js.map +1 -0
  145. package/dist/library/themes/radiant.d.ts +2 -0
  146. package/dist/library/themes/radiant.d.ts.map +1 -0
  147. package/dist/library/themes/radiant.js +129 -0
  148. package/dist/library/themes/radiant.js.map +1 -0
  149. package/dist/library/themes/sharp-3d.d.ts +2 -0
  150. package/dist/library/themes/sharp-3d.d.ts.map +1 -0
  151. package/dist/library/themes/sharp-3d.js +142 -0
  152. package/dist/library/themes/sharp-3d.js.map +1 -0
  153. package/dist/library/themes/soft-squircle.d.ts +2 -0
  154. package/dist/library/themes/soft-squircle.d.ts.map +1 -0
  155. package/dist/library/themes/soft-squircle.js +131 -0
  156. package/dist/library/themes/soft-squircle.js.map +1 -0
  157. package/dist/library/themes/themeDocument.d.ts +16 -0
  158. package/dist/library/themes/themeDocument.d.ts.map +1 -0
  159. package/dist/library/themes/themeDocument.js +307 -0
  160. package/dist/library/themes/themeDocument.js.map +1 -0
  161. package/dist/library/themes/themeDocumentTypes.d.ts +69 -0
  162. package/dist/library/themes/themeDocumentTypes.d.ts.map +1 -0
  163. package/dist/library/themes/themeDocumentTypes.js +2 -0
  164. package/dist/library/themes/themeDocumentTypes.js.map +1 -0
  165. package/dist/library/themes/ticket.d.ts +2 -0
  166. package/dist/library/themes/ticket.d.ts.map +1 -0
  167. package/dist/library/themes/ticket.js +141 -0
  168. package/dist/library/themes/ticket.js.map +1 -0
  169. package/dist/library/themes/tokens.d.ts +100 -0
  170. package/dist/library/themes/tokens.d.ts.map +1 -0
  171. package/dist/library/themes/tokens.js +171 -0
  172. package/dist/library/themes/tokens.js.map +1 -0
  173. package/dist/library/themes/types.d.ts +2 -0
  174. package/dist/library/themes/types.d.ts.map +1 -0
  175. package/dist/library/themes/types.js +2 -0
  176. package/dist/library/themes/types.js.map +1 -0
  177. package/dist/library/themes/updateThemeAppearance.d.ts +29 -0
  178. package/dist/library/themes/updateThemeAppearance.d.ts.map +1 -0
  179. package/dist/library/themes/updateThemeAppearance.js +138 -0
  180. package/dist/library/themes/updateThemeAppearance.js.map +1 -0
  181. package/docs/accessibility.md +189 -0
  182. package/docs/system.md +231 -0
  183. package/docs/theming.md +804 -0
  184. package/package.json +34 -10
  185. package/src/Accordion.tsx +235 -0
  186. package/src/Button.tsx +95 -15
  187. package/src/Card.tsx +143 -0
  188. package/src/Checkbox.tsx +189 -0
  189. package/src/Collapsible.tsx +193 -0
  190. package/src/Dialog.tsx +333 -0
  191. package/src/Field.tsx +293 -0
  192. package/src/Input.tsx +82 -0
  193. package/src/Link.tsx +95 -0
  194. package/src/RadioGroup.tsx +255 -0
  195. package/src/ThemeScope.tsx +64 -0
  196. package/src/actionStyles.ts +90 -0
  197. package/src/cn.ts +1 -10
  198. package/src/color/colorFamilies.ts +19 -0
  199. package/src/color/generateColorWall.ts +358 -0
  200. package/src/color/index.ts +11 -0
  201. package/src/color/oklch.ts +95 -0
  202. package/src/color/recommendColorPalette.ts +375 -0
  203. package/src/controlStyles.ts +19 -0
  204. package/src/index.ts +130 -1
  205. package/src/internal/events.ts +17 -0
  206. package/src/internal/ids.ts +5 -0
  207. package/src/internal/selection.ts +20 -0
  208. package/src/presentation.ts +12 -0
  209. package/src/react/useComposedRefs.ts +32 -0
  210. package/src/react/useControllableState.ts +50 -0
  211. package/src/react/useNativeOwner.ts +33 -0
  212. package/src/styles.css +2 -14
  213. package/src/themes/baseline.css +116 -0
  214. package/src/themes/components.ts +249 -0
  215. package/src/themes/default.ts +4 -0
  216. package/src/themes/defineTheme.ts +145 -0
  217. package/src/themes/expressive.ts +132 -0
  218. package/src/themes/glass.ts +135 -0
  219. package/src/themes/index.ts +57 -0
  220. package/src/themes/jelly.ts +130 -0
  221. package/src/themes/preset-values.ts +5 -0
  222. package/src/themes/radiant.ts +129 -0
  223. package/src/themes/sharp-3d.ts +142 -0
  224. package/src/themes/soft-squircle.ts +131 -0
  225. package/src/themes/themeDocument.ts +340 -0
  226. package/src/themes/themeDocumentTypes.ts +76 -0
  227. package/src/themes/ticket.ts +141 -0
  228. package/src/themes/tokens.ts +262 -0
  229. package/src/themes/types.ts +10 -0
  230. package/src/themes/updateThemeAppearance.ts +172 -0
@@ -0,0 +1,33 @@
1
+ 'use client'
2
+
3
+ import { useState } from 'react'
4
+
5
+ export type ValueOwner<Value> =
6
+ | { value: Value; defaultValue?: never }
7
+ | { value?: undefined; defaultValue?: Value }
8
+
9
+ export type CheckedOwner =
10
+ | { checked: boolean; defaultChecked?: never }
11
+ | { checked?: undefined; defaultChecked?: boolean }
12
+
13
+ /** Validate ownership without replacing React/browser state or reset behavior. */
14
+ export function useNativeOwner(
15
+ name: string,
16
+ value: unknown,
17
+ defaultValue: unknown,
18
+ enabled = true
19
+ ) {
20
+ const controlled = value !== undefined
21
+ const [owner] = useState(controlled)
22
+ if (enabled) {
23
+ if (value !== undefined && defaultValue !== undefined) {
24
+ throw new TypeError(`${name} accepts a controlled value or a default, not both.`)
25
+ }
26
+ if (owner !== controlled) {
27
+ throw new TypeError(
28
+ `${name} cannot switch between controlled and uncontrolled state. Remount with a new key.`
29
+ )
30
+ }
31
+ }
32
+ return controlled
33
+ }
package/src/styles.css CHANGED
@@ -1,17 +1,5 @@
1
+ @import './themes/baseline.css';
2
+
1
3
  @source '.';
2
4
  @source not './**/*.stories.*';
3
5
  @source not './**/*.test.*';
4
-
5
- @theme static {
6
- --color-background: #fff;
7
- --color-foreground: #0f172a;
8
- --color-border: #cbd5e1;
9
- --color-primary: #1e293b;
10
- --color-primary-hover: #0f172a;
11
- --color-primary-active: #020617;
12
- --color-primary-foreground: #fff;
13
- --color-disabled: #e2e8f0;
14
- --color-disabled-foreground: #475569;
15
- --color-focus: #2563eb;
16
- --radius-control: 0.5rem;
17
- }
@@ -0,0 +1,116 @@
1
+ /* Generated by scripts/generate-theme-css.mjs from src/themes/tokens.ts. */
2
+ /* Run pnpm theme:generate after editing shared defaults. */
3
+ :root,
4
+ :host {
5
+ --_rad-light: initial;
6
+ --_rad-dark: ;
7
+ --rad-color-surface: var(--_rad-light, oklch(1 0 0)) var(--_rad-dark, oklch(0.21 0.006 286));
8
+ --rad-color-foreground: var(--_rad-light, oklch(0.21 0.006 286))
9
+ var(--_rad-dark, oklch(0.985 0 0));
10
+ --rad-color-muted-foreground: var(--_rad-light, oklch(0.45 0.01 286))
11
+ var(--_rad-dark, oklch(0.75 0.01 286));
12
+ --rad-color-border: var(--_rad-light, oklch(0.885 0.005 286))
13
+ var(--_rad-dark, oklch(0.4 0.008 286));
14
+ --rad-color-placeholder: var(--_rad-light, oklch(0.5 0.01 286))
15
+ var(--_rad-dark, oklch(0.7 0.01 286));
16
+ --rad-color-disabled-background: var(--_rad-light, oklch(0.96 0.005 286))
17
+ var(--_rad-dark, oklch(0.26 0.006 286));
18
+ --rad-color-disabled-border: var(--_rad-light, oklch(0.88 0.005 286))
19
+ var(--_rad-dark, oklch(0.38 0.006 286));
20
+ --rad-color-invalid: var(--_rad-light, oklch(0.56 0.19 25)) var(--_rad-dark, oklch(0.75 0.16 25));
21
+ --rad-color-focus: var(--_rad-light, oklch(0.55 0.13 255)) var(--_rad-dark, oklch(0.75 0.13 255));
22
+ --rad-color-accent: var(--_rad-light, oklch(0.21 0.006 286))
23
+ var(--_rad-dark, oklch(0.92 0.005 286));
24
+ --rad-color-accent-foreground: var(--_rad-light, oklch(0.985 0 0))
25
+ var(--_rad-dark, oklch(0.21 0.006 286));
26
+ --rad-color-neutral: var(--_rad-light, oklch(0.955 0.004 286))
27
+ var(--_rad-dark, oklch(0.3 0.006 286));
28
+ --rad-color-neutral-foreground: var(--_rad-light, oklch(0.21 0.006 286))
29
+ var(--_rad-dark, oklch(0.985 0 0));
30
+ --rad-color-warning: oklch(0.8 0.14 78);
31
+ --rad-color-warning-foreground: oklch(0.3 0.07 55);
32
+ --rad-color-danger: var(--_rad-light, oklch(0.56 0.19 25)) var(--_rad-dark, oklch(0.72 0.17 25));
33
+ --rad-color-danger-foreground: var(--_rad-light, oklch(0.99 0 0))
34
+ var(--_rad-dark, oklch(0.2 0.04 25));
35
+ --rad-typography-family: system-ui, sans-serif;
36
+ --rad-typography-body-size: 0.875rem;
37
+ --rad-typography-small-size: 0.8125rem;
38
+ --rad-typography-heading-size: 1.125rem;
39
+ --rad-typography-body-weight: 400;
40
+ --rad-typography-label-weight: 550;
41
+ --rad-typography-heading-weight: 600;
42
+ --rad-typography-letter-spacing: -0.011em;
43
+ --rad-control-small-height: 2rem;
44
+ --rad-control-small-padding-inline: 0.75rem;
45
+ --rad-control-small-font-size: 0.8125rem;
46
+ --rad-control-small-indicator-size: 1rem;
47
+ --rad-control-medium-height: 2.5rem;
48
+ --rad-control-medium-padding-inline: 1rem;
49
+ --rad-control-medium-font-size: 0.875rem;
50
+ --rad-control-medium-indicator-size: 1.125rem;
51
+ --rad-control-large-height: 3rem;
52
+ --rad-control-large-padding-inline: 1.375rem;
53
+ --rad-control-large-font-size: 0.9375rem;
54
+ --rad-control-large-indicator-size: 1.25rem;
55
+ --rad-control-radius: 0.5rem;
56
+ --rad-control-corner-shape: round;
57
+ --rad-control-border-width: 1px;
58
+ --rad-control-border-style: solid;
59
+ --rad-surface-canvas: var(--_rad-light, oklch(1 0 0)) var(--_rad-dark, oklch(0.16 0.006 286));
60
+ --rad-surface-radius: 0.75rem;
61
+ --rad-surface-corner-shape: round;
62
+ --rad-surface-border-width: 1px;
63
+ --rad-surface-border-style: solid;
64
+ --rad-surface-padding: 1.5rem;
65
+ --rad-surface-gap: 1rem;
66
+ --rad-surface-shadow: var(--_rad-light, 0 1px 2px 0 rgb(0 0 0 / 0.06))
67
+ var(--_rad-dark, 0 1px 2px 0 rgb(0 0 0 / 0.25));
68
+ --rad-surface-overlay-shadow: var(--_rad-light, 0 24px 64px -16px rgb(0 0 0 / 0.3))
69
+ var(--_rad-dark, 0 24px 64px -16px rgb(0 0 0 / 0.6));
70
+ --rad-surface-backdrop: var(--_rad-light, rgb(0 0 0 / 0.45)) var(--_rad-dark, rgb(0 0 0 / 0.65));
71
+ --rad-focus-width: 2px;
72
+ --rad-focus-offset: 2px;
73
+ --rad-focus-style: solid;
74
+ --rad-motion-press-duration: 80ms;
75
+ --rad-motion-press-ease: cubic-bezier(0.3, 0, 0, 1);
76
+ --rad-motion-release-duration: 160ms;
77
+ --rad-motion-release-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
78
+ --rad-motion-color-duration: 150ms;
79
+ --rad-motion-disclosure-duration: 150ms;
80
+ --rad-spacing-label-gap: 0.5rem;
81
+ --rad-spacing-field-gap: 0.375rem;
82
+ --rad-spacing-group-gap: 0.75rem;
83
+ --rad-spacing-header-gap: 0.375rem;
84
+ --rad-spacing-footer-gap: 0.5rem;
85
+ --rad-state-disabled-opacity: 0.5;
86
+ }
87
+
88
+ @media (prefers-color-scheme: dark) {
89
+ :root,
90
+ :host {
91
+ --_rad-light: ;
92
+ --_rad-dark: initial;
93
+ }
94
+ }
95
+
96
+ [data-rad-mode='light'] {
97
+ --_rad-light: initial;
98
+ --_rad-dark: ;
99
+ }
100
+
101
+ [data-rad-mode='dark'] {
102
+ --_rad-light: ;
103
+ --_rad-dark: initial;
104
+ }
105
+
106
+ [data-rad-mode='system'] {
107
+ --_rad-light: initial;
108
+ --_rad-dark: ;
109
+ }
110
+
111
+ @media (prefers-color-scheme: dark) {
112
+ [data-rad-mode='system'] {
113
+ --_rad-light: ;
114
+ --_rad-dark: initial;
115
+ }
116
+ }
@@ -0,0 +1,249 @@
1
+ import { kebabCase } from './tokens.js'
2
+
3
+ /** Explicit component slots; omitted slots reset to CSS fallback semantics. */
4
+ export const componentRegistry = {
5
+ button: {
6
+ radius: 'css',
7
+ radiusPressed: 'css',
8
+ cornerShape: 'css',
9
+ cornerShapePressed: 'css',
10
+ height: 'css',
11
+ heightSmall: 'css',
12
+ heightLarge: 'css',
13
+ padding: 'css',
14
+ paddingSmall: 'css',
15
+ paddingLarge: 'css',
16
+ fontSize: 'css',
17
+ fontSizeSmall: 'css',
18
+ fontSizeLarge: 'css',
19
+ fontWeight: 'weight',
20
+ letterSpacing: 'css',
21
+ shadow: 'css',
22
+ shadowPressed: 'css',
23
+ highlight: 'opacity',
24
+ sheen: 'opacity',
25
+ glow: 'css',
26
+ backdrop: 'css',
27
+ stateColor: 'css',
28
+ hoverLayer: 'css',
29
+ pressLayer: 'css',
30
+ hoverLift: 'css',
31
+ pressScale: 'number',
32
+ pressShift: 'css',
33
+ pressShiftX: 'css',
34
+ borderWidth: 'css',
35
+ borderColor: 'css',
36
+ ghostShadow: 'css',
37
+ ghostShadowPressed: 'css',
38
+ focusColor: 'css',
39
+ fontFamily: 'css',
40
+ textTransform: 'css',
41
+ borderStyle: 'css',
42
+ focusWidth: 'css',
43
+ focusOffset: 'css',
44
+ focusStyle: 'css',
45
+ pressDuration: 'css',
46
+ pressEase: 'css',
47
+ releaseDuration: 'css',
48
+ releaseEase: 'css',
49
+ colorDuration: 'css',
50
+ disabledOpacity: 'opacity'
51
+ },
52
+ link: {
53
+ color: 'css',
54
+ hoverColor: 'css',
55
+ underlineOffset: 'css',
56
+ decorationThickness: 'css',
57
+ decorationThicknessHover: 'css',
58
+ colorDuration: 'css',
59
+ focusColor: 'css',
60
+ focusWidth: 'css',
61
+ focusOffset: 'css',
62
+ focusStyle: 'css'
63
+ },
64
+ field: {
65
+ gap: 'css',
66
+ labelColor: 'css',
67
+ labelSize: 'css',
68
+ labelWeight: 'weight',
69
+ descriptionColor: 'css',
70
+ descriptionSize: 'css',
71
+ errorColor: 'css',
72
+ errorSize: 'css',
73
+ requiredColor: 'css',
74
+ disabledOpacity: 'opacity'
75
+ },
76
+ input: {
77
+ height: 'css',
78
+ padding: 'css',
79
+ fontFamily: 'css',
80
+ fontSize: 'css',
81
+ fontWeight: 'weight',
82
+ color: 'css',
83
+ background: 'css',
84
+ borderWidth: 'css',
85
+ borderStyle: 'css',
86
+ borderColor: 'css',
87
+ radius: 'css',
88
+ cornerShape: 'css',
89
+ shadow: 'css',
90
+ placeholder: 'css',
91
+ invalidBorder: 'css',
92
+ disabledBackground: 'css',
93
+ focusColor: 'css',
94
+ focusWidth: 'css',
95
+ focusOffset: 'css',
96
+ focusStyle: 'css'
97
+ },
98
+ checkbox: {
99
+ size: 'css',
100
+ radius: 'css',
101
+ cornerShape: 'css',
102
+ borderWidth: 'css',
103
+ borderStyle: 'css',
104
+ borderColor: 'css',
105
+ background: 'css',
106
+ checkedBackground: 'css',
107
+ checkedBorder: 'css',
108
+ mark: 'css',
109
+ invalidBorder: 'css',
110
+ gap: 'css',
111
+ labelColor: 'css',
112
+ labelSize: 'css',
113
+ disabledBorder: 'css',
114
+ disabledBackground: 'css',
115
+ focusColor: 'css',
116
+ focusWidth: 'css',
117
+ focusOffset: 'css',
118
+ focusStyle: 'css'
119
+ },
120
+ radio: {
121
+ size: 'css',
122
+ radius: 'css',
123
+ cornerShape: 'css',
124
+ borderWidth: 'css',
125
+ borderStyle: 'css',
126
+ borderColor: 'css',
127
+ background: 'css',
128
+ checkedBackground: 'css',
129
+ checkedBorder: 'css',
130
+ mark: 'css',
131
+ invalidBorder: 'css',
132
+ labelGap: 'css',
133
+ labelColor: 'css',
134
+ labelSize: 'css',
135
+ disabledBorder: 'css',
136
+ disabledBackground: 'css',
137
+ focusColor: 'css',
138
+ focusWidth: 'css',
139
+ focusOffset: 'css',
140
+ focusStyle: 'css'
141
+ },
142
+ dialog: {
143
+ width: 'css',
144
+ padding: 'css',
145
+ gap: 'css',
146
+ radius: 'css',
147
+ cornerShape: 'css',
148
+ background: 'css',
149
+ color: 'css',
150
+ borderWidth: 'css',
151
+ borderStyle: 'css',
152
+ borderColor: 'css',
153
+ shadow: 'css',
154
+ backdrop: 'css',
155
+ backdropFilter: 'css',
156
+ titleSize: 'css',
157
+ titleWeight: 'weight',
158
+ descriptionColor: 'css',
159
+ descriptionSize: 'css',
160
+ focusColor: 'css',
161
+ focusWidth: 'css',
162
+ focusOffset: 'css',
163
+ focusStyle: 'css'
164
+ },
165
+ collapsible: {
166
+ radius: 'css',
167
+ cornerShape: 'css',
168
+ background: 'css',
169
+ color: 'css',
170
+ borderWidth: 'css',
171
+ borderStyle: 'css',
172
+ borderColor: 'css',
173
+ padding: 'css',
174
+ gap: 'css',
175
+ contentColor: 'css',
176
+ contentSize: 'css',
177
+ duration: 'css',
178
+ focusColor: 'css',
179
+ focusWidth: 'css',
180
+ focusOffset: 'css',
181
+ focusStyle: 'css'
182
+ },
183
+ accordion: {
184
+ gap: 'css'
185
+ },
186
+ card: {
187
+ radius: 'css',
188
+ cornerShape: 'css',
189
+ background: 'css',
190
+ color: 'css',
191
+ borderWidth: 'css',
192
+ borderStyle: 'css',
193
+ borderColor: 'css',
194
+ padding: 'css',
195
+ gap: 'css',
196
+ headerGap: 'css',
197
+ footerGap: 'css',
198
+ shadow: 'css',
199
+ titleSize: 'css',
200
+ titleWeight: 'weight',
201
+ descriptionColor: 'css',
202
+ descriptionSize: 'css'
203
+ },
204
+ radioGroup: { gap: 'css' }
205
+ } as const
206
+
207
+ type ValueKind = 'css' | 'weight' | 'number' | 'opacity'
208
+ type KindValue<T> = T extends 'css' ? string : T extends 'weight' ? string | number : number
209
+ export type ThemeComponentOverrides = {
210
+ readonly [F in keyof typeof componentRegistry]?: {
211
+ readonly [K in keyof (typeof componentRegistry)[F]]?: KindValue<
212
+ (typeof componentRegistry)[F][K]
213
+ >
214
+ }
215
+ }
216
+
217
+ export const componentVariables = Object.freeze(
218
+ Object.fromEntries(
219
+ Object.entries(componentRegistry).map(([family, keys]) => [
220
+ family,
221
+ Object.freeze(
222
+ Object.fromEntries(
223
+ Object.keys(keys).map(key => [key, `--rad-${kebabCase(family)}-${kebabCase(key)}`])
224
+ )
225
+ )
226
+ ])
227
+ )
228
+ ) as Readonly<Record<keyof typeof componentRegistry, Readonly<Record<string, `--rad-${string}`>>>>
229
+
230
+ export function componentValueKind(family: string, key: string): ValueKind | undefined {
231
+ if (!Object.hasOwn(componentRegistry, family)) return undefined
232
+ const keys = componentRegistry[family as keyof typeof componentRegistry]
233
+ return Object.hasOwn(keys, key) ? (keys as Record<string, ValueKind>)[key] : undefined
234
+ }
235
+
236
+ export function flattenComponents(overrides: ThemeComponentOverrides = {}, reset = false) {
237
+ const result: Record<`--rad-${string}`, string | number> = {}
238
+ for (const [family, variables] of Object.entries(componentVariables)) {
239
+ const values = overrides[family as keyof ThemeComponentOverrides] as
240
+ | Record<string, string | number | undefined>
241
+ | undefined
242
+ for (const [key, variable] of Object.entries(variables)) {
243
+ const value = values?.[key]
244
+ if (value !== undefined) result[variable] = value
245
+ else if (reset) result[variable] = 'initial'
246
+ }
247
+ }
248
+ return result
249
+ }
@@ -0,0 +1,4 @@
1
+ import { defineTheme } from './defineTheme.js'
2
+
3
+ // One neutral baseline, including dark mode, is maintained in the token registry.
4
+ export const defaultTheme = defineTheme({ id: 'default', name: 'Default' })
@@ -0,0 +1,145 @@
1
+ import type { CSSProperties } from 'react'
2
+ import {
3
+ flattenTokens,
4
+ freezeTree,
5
+ tokenDefaults,
6
+ type ThemeTokens,
7
+ type ThemeVariableValues
8
+ } from './tokens.js'
9
+ import {
10
+ componentRegistry,
11
+ componentValueKind,
12
+ flattenComponents,
13
+ type ThemeComponentOverrides
14
+ } from './components.js'
15
+
16
+ export type { SharedTokens, ThemeTokens } from './tokens.js'
17
+ export type { ThemeComponentOverrides } from './components.js'
18
+ export type ThemeMode = 'light' | 'dark' | 'system'
19
+ export type ThemeStyle = CSSProperties & {
20
+ [key: `--${string}`]: string | number | undefined
21
+ }
22
+ export interface ThemeLayer {
23
+ readonly tokens?: ThemeTokens
24
+ readonly components?: ThemeComponentOverrides
25
+ }
26
+ export interface ThemeDefinition extends ThemeLayer {
27
+ readonly id: string
28
+ readonly name: string
29
+ readonly modes?: { readonly light?: ThemeLayer; readonly dark?: ThemeLayer }
30
+ }
31
+
32
+ /** Resolved, immutable data. Safe to pass through server/client serialization. */
33
+ export interface Theme {
34
+ readonly id: string
35
+ readonly name: string
36
+ readonly modes: {
37
+ readonly light: Readonly<ThemeVariableValues>
38
+ readonly dark: Readonly<ThemeVariableValues>
39
+ }
40
+ }
41
+
42
+ function assertRecord(value: unknown, path: string): asserts value is Record<string, unknown> {
43
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) {
44
+ throw new TypeError(`${path} must be an object.`)
45
+ }
46
+ }
47
+
48
+ function assertKeys(value: Record<string, unknown>, allowed: object, path: string) {
49
+ for (const key of Object.keys(value)) {
50
+ if (!Object.hasOwn(allowed, key)) throw new TypeError(`Unknown theme key: ${path}.${key}`)
51
+ }
52
+ }
53
+
54
+ function validateScalar(
55
+ value: unknown,
56
+ kind: 'css' | 'weight' | 'number' | 'opacity',
57
+ path: string
58
+ ) {
59
+ if (value === undefined) return
60
+ if (typeof value === 'string' && (kind === 'css' || kind === 'weight') && value.trim()) return
61
+ if (typeof value === 'number' && kind !== 'css' && Number.isFinite(value)) {
62
+ if (kind !== 'opacity' || (value >= 0 && value <= 1)) return
63
+ }
64
+ throw new TypeError(`Invalid theme value at ${path}.`)
65
+ }
66
+
67
+ function validateTokens(value: unknown, baseline: object, path: string) {
68
+ assertRecord(value, path)
69
+ assertKeys(value, baseline, path)
70
+ for (const [key, item] of Object.entries(value)) {
71
+ if (item === undefined) continue
72
+ const defaultValue = (baseline as Record<string, unknown>)[key]
73
+ if (typeof defaultValue === 'object' && defaultValue !== null) {
74
+ validateTokens(item, defaultValue, `${path}.${key}`)
75
+ } else {
76
+ validateScalar(
77
+ item,
78
+ key === 'disabledOpacity' ? 'opacity' : key.endsWith('Weight') ? 'weight' : 'css',
79
+ `${path}.${key}`
80
+ )
81
+ }
82
+ }
83
+ }
84
+
85
+ function validateLayer(value: unknown, path: string) {
86
+ assertRecord(value, path)
87
+ assertKeys(value, { tokens: true, components: true }, path)
88
+ if (value.tokens !== undefined)
89
+ validateTokens(value.tokens, tokenDefaults.light, `${path}.tokens`)
90
+ if (value.components !== undefined) {
91
+ assertRecord(value.components, `${path}.components`)
92
+ assertKeys(value.components, componentRegistry, `${path}.components`)
93
+ for (const [family, overrides] of Object.entries(value.components)) {
94
+ if (overrides === undefined) continue
95
+ assertRecord(overrides, `${path}.components.${family}`)
96
+ for (const [key, item] of Object.entries(overrides)) {
97
+ const kind = componentValueKind(family, key)
98
+ if (!kind) throw new TypeError(`Unknown theme key: ${path}.components.${family}.${key}`)
99
+ validateScalar(item, kind, `${path}.components.${family}.${key}`)
100
+ }
101
+ }
102
+ }
103
+ }
104
+
105
+ /** Resolve defaults → common overrides → mode overrides, independently for each mode. */
106
+ export function defineTheme(definition: ThemeDefinition): Theme {
107
+ assertRecord(definition, 'theme')
108
+ assertKeys(
109
+ definition,
110
+ { id: true, name: true, tokens: true, components: true, modes: true },
111
+ 'theme'
112
+ )
113
+ if (typeof definition.id !== 'string' || !/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(definition.id)) {
114
+ throw new TypeError('Theme id must be a lowercase slug starting with a letter.')
115
+ }
116
+ if (typeof definition.name !== 'string' || !definition.name.trim()) {
117
+ throw new TypeError('Theme name must be a nonempty string.')
118
+ }
119
+ validateLayer({ tokens: definition.tokens, components: definition.components }, 'theme')
120
+ if (definition.modes !== undefined) {
121
+ assertRecord(definition.modes, 'theme.modes')
122
+ assertKeys(definition.modes, { light: true, dark: true }, 'theme.modes')
123
+ for (const mode of ['light', 'dark'] as const) {
124
+ if (definition.modes[mode] !== undefined)
125
+ validateLayer(definition.modes[mode], `theme.modes.${mode}`)
126
+ }
127
+ }
128
+ function resolve(mode: 'light' | 'dark'): ThemeVariableValues {
129
+ const layer = definition.modes?.[mode]
130
+ return {
131
+ ...flattenTokens(tokenDefaults[mode]),
132
+ ...flattenTokens(definition.tokens ?? {}),
133
+ ...flattenTokens(layer?.tokens ?? {}),
134
+ ...flattenComponents({}, true),
135
+ ...flattenComponents(definition.components),
136
+ ...flattenComponents(layer?.components)
137
+ }
138
+ }
139
+ const modes = { light: resolve('light'), dark: resolve('dark') }
140
+ return freezeTree({
141
+ id: definition.id,
142
+ name: definition.name,
143
+ modes
144
+ })
145
+ }
@@ -0,0 +1,132 @@
1
+ import { defineTheme } from './defineTheme.js'
2
+ import { spring } from './preset-values.js'
3
+
4
+ export const expressive = defineTheme({
5
+ id: 'expressive',
6
+ name: 'Expressive',
7
+ tokens: {
8
+ color: {
9
+ surface: '#ffffff',
10
+ foreground: '#402266',
11
+ mutedForeground: '#746084',
12
+ border: '#cbb6e0',
13
+ accent: '#6732b4',
14
+ accentForeground: '#ffffff',
15
+ neutral: '#eee4fa',
16
+ neutralForeground: '#452267',
17
+ warning: '#efc355',
18
+ warningForeground: '#44300c',
19
+ danger: '#b52c34',
20
+ dangerForeground: '#ffffff',
21
+ focus: '#6732b4',
22
+ placeholder: '#746084',
23
+ disabledBackground: '#eee4fa',
24
+ disabledBorder: '#cbb6e0',
25
+ invalid: '#b52c34'
26
+ },
27
+ typography: {
28
+ family: "'Poppins', system-ui, sans-serif",
29
+ bodySize: '1rem',
30
+ smallSize: '0.875rem',
31
+ headingSize: '1.25rem',
32
+ bodyWeight: 400,
33
+ labelWeight: 600,
34
+ headingWeight: 700,
35
+ letterSpacing: '0'
36
+ },
37
+ control: {
38
+ small: {
39
+ height: '2rem',
40
+ paddingInline: '0.75rem',
41
+ fontSize: '0.8125rem',
42
+ indicatorSize: '1rem'
43
+ },
44
+ medium: {
45
+ height: '3rem',
46
+ paddingInline: '1.5rem',
47
+ fontSize: '0.875rem',
48
+ indicatorSize: '1.125rem'
49
+ },
50
+ large: {
51
+ height: '3.25rem',
52
+ paddingInline: '1.5rem',
53
+ fontSize: '0.9375rem',
54
+ indicatorSize: '1.25rem'
55
+ },
56
+ radius: '1.5rem',
57
+ cornerShape: 'round',
58
+ borderWidth: '1px',
59
+ borderStyle: 'solid'
60
+ },
61
+ surface: {
62
+ canvas: '#f7f0ff',
63
+ radius: '1.5rem',
64
+ cornerShape: 'round',
65
+ borderWidth: '1px',
66
+ borderStyle: 'solid',
67
+ padding: '1.5rem',
68
+ gap: '1rem',
69
+ shadow: '0 1px 3px rgb(0 0 0 / 0.08)',
70
+ overlayShadow: '0 20px 60px rgb(0 0 0 / 0.22)',
71
+ backdrop: 'rgb(15 12 25 / 0.45)'
72
+ },
73
+ focus: {
74
+ width: '6px',
75
+ offset: '2px',
76
+ style: 'double'
77
+ },
78
+ motion: {
79
+ pressDuration: '450ms',
80
+ pressEase: spring,
81
+ releaseDuration: '450ms',
82
+ releaseEase: spring,
83
+ colorDuration: '150ms',
84
+ disclosureDuration: '180ms'
85
+ },
86
+ state: { disabledOpacity: 0.5 }
87
+ },
88
+ components: {
89
+ button: {
90
+ radiusPressed: '0.75rem',
91
+ sheen: 0,
92
+ glow: '0%',
93
+ hoverLift: '0px',
94
+ fontWeight: 600,
95
+ shadow: '0 0 #0000',
96
+ shadowPressed: '0 0 #0000',
97
+ highlight: 0,
98
+ pressScale: 0.98
99
+ }
100
+ },
101
+ modes: {
102
+ dark: {
103
+ tokens: {
104
+ color: {
105
+ surface: '#271c36',
106
+ foreground: '#f5eaff',
107
+ mutedForeground: '#c8b2dc',
108
+ border: '#806297',
109
+ accent: '#c4a0ff',
110
+ accentForeground: '#301253',
111
+ neutral: '#423055',
112
+ neutralForeground: '#f2e3ff',
113
+ warning: '#efc355',
114
+ warningForeground: '#352507',
115
+ danger: '#ff9298',
116
+ dangerForeground: '#3c111a',
117
+ focus: '#d1b4ff',
118
+ placeholder: '#c8b2dc',
119
+ disabledBackground: '#423055',
120
+ disabledBorder: '#806297',
121
+ invalid: '#ff9298'
122
+ },
123
+ surface: {
124
+ canvas: '#191122',
125
+ shadow: '0 1px 4px rgb(0 0 0 / 0.4)',
126
+ overlayShadow: '0 20px 60px rgb(0 0 0 / 0.65)',
127
+ backdrop: 'rgb(0 0 0 / 0.65)'
128
+ }
129
+ }
130
+ }
131
+ }
132
+ })