@agent-native/design-system 0.0.0-stage → 0.229.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +78 -2
  3. package/THIRD_PARTY_NOTICES.md +58 -0
  4. package/css/appearances.css +91 -0
  5. package/css/main.css +174 -0
  6. package/css/parts/accordion.css +104 -0
  7. package/css/parts/alert-dialog.css +159 -0
  8. package/css/parts/app-shell.css +45 -0
  9. package/css/parts/aspect-ratio.css +20 -0
  10. package/css/parts/autocomplete.css +366 -0
  11. package/css/parts/avatar.css +108 -0
  12. package/css/parts/badge.css +100 -0
  13. package/css/parts/blockquote.css +23 -0
  14. package/css/parts/button.css +238 -0
  15. package/css/parts/callout.css +108 -0
  16. package/css/parts/card.css +144 -0
  17. package/css/parts/checkbox-cards.css +59 -0
  18. package/css/parts/checkbox-group.css +20 -0
  19. package/css/parts/checkbox.css +127 -0
  20. package/css/parts/code.css +194 -0
  21. package/css/parts/collapsible.css +40 -0
  22. package/css/parts/combobox.css +171 -0
  23. package/css/parts/context-menu.css +18 -0
  24. package/css/parts/data-list.css +130 -0
  25. package/css/parts/dialog.css +251 -0
  26. package/css/parts/drawer.css +289 -0
  27. package/css/parts/em.css +16 -0
  28. package/css/parts/field.css +55 -0
  29. package/css/parts/fieldset.css +34 -0
  30. package/css/parts/form.css +18 -0
  31. package/css/parts/heading.css +25 -0
  32. package/css/parts/icon-button.css +30 -0
  33. package/css/parts/input.css +206 -0
  34. package/css/parts/inset.css +90 -0
  35. package/css/parts/item.css +208 -0
  36. package/css/parts/kbd.css +126 -0
  37. package/css/parts/link.css +99 -0
  38. package/css/parts/menu.css +342 -0
  39. package/css/parts/menubar.css +71 -0
  40. package/css/parts/meter.css +112 -0
  41. package/css/parts/navigation-menu.css +199 -0
  42. package/css/parts/number-field.css +124 -0
  43. package/css/parts/otp-field.css +137 -0
  44. package/css/parts/page-header.css +45 -0
  45. package/css/parts/popover.css +149 -0
  46. package/css/parts/preview-card.css +116 -0
  47. package/css/parts/progress.css +159 -0
  48. package/css/parts/quote.css +18 -0
  49. package/css/parts/radio-cards.css +188 -0
  50. package/css/parts/radio-group.css +124 -0
  51. package/css/parts/scroll-area.css +95 -0
  52. package/css/parts/segmented-control.css +191 -0
  53. package/css/parts/select.css +378 -0
  54. package/css/parts/separator.css +48 -0
  55. package/css/parts/sidebar.css +211 -0
  56. package/css/parts/skeleton.css +65 -0
  57. package/css/parts/slider.css +156 -0
  58. package/css/parts/spinner.css +52 -0
  59. package/css/parts/strong.css +15 -0
  60. package/css/parts/switch.css +138 -0
  61. package/css/parts/tab-nav.css +48 -0
  62. package/css/parts/table.css +177 -0
  63. package/css/parts/tabs.css +214 -0
  64. package/css/parts/text-area.css +140 -0
  65. package/css/parts/text.css +245 -0
  66. package/css/parts/toast.css +302 -0
  67. package/css/parts/toggle-group.css +25 -0
  68. package/css/parts/toggle.css +181 -0
  69. package/css/parts/toolbar.css +133 -0
  70. package/css/parts/tooltip.css +61 -0
  71. package/css/parts/visually-hidden.css +21 -0
  72. package/css/styles.css +73 -0
  73. package/css/themes/agent-native.css +2321 -0
  74. package/css/themes/analytics.css +1159 -0
  75. package/css/themes/assets.css +1159 -0
  76. package/css/themes/baseline.css +1107 -0
  77. package/css/themes/brain.css +1159 -0
  78. package/css/themes/calendar.css +1159 -0
  79. package/css/themes/chat.css +1159 -0
  80. package/css/themes/clips.css +1159 -0
  81. package/css/themes/content.css +1159 -0
  82. package/css/themes/crm.css +1159 -0
  83. package/css/themes/design.css +1159 -0
  84. package/css/themes/desktop.css +1159 -0
  85. package/css/themes/dispatch.css +1159 -0
  86. package/css/themes/docs.css +1159 -0
  87. package/css/themes/factory.css +1159 -0
  88. package/css/themes/forms.css +1159 -0
  89. package/css/themes/mail.css +1159 -0
  90. package/css/themes/plan.css +1159 -0
  91. package/css/themes/slides.css +1159 -0
  92. package/css/themes/tasks.css +1159 -0
  93. package/css/tokens.css +1249 -0
  94. package/package.json +67 -4
  95. package/src/catalog/components/alert-dialog.ts +9 -0
  96. package/src/catalog/components/aspect-ratio.ts +6 -0
  97. package/src/catalog/components/autocomplete.ts +23 -0
  98. package/src/catalog/components/avatar.ts +16 -0
  99. package/src/catalog/components/badge.ts +19 -0
  100. package/src/catalog/components/blockquote.ts +10 -0
  101. package/src/catalog/components/button.ts +24 -0
  102. package/src/catalog/components/callout.ts +17 -0
  103. package/src/catalog/components/card.ts +10 -0
  104. package/src/catalog/components/checkbox-cards.ts +14 -0
  105. package/src/catalog/components/checkbox-group.ts +13 -0
  106. package/src/catalog/components/checkbox.ts +13 -0
  107. package/src/catalog/components/code.ts +22 -0
  108. package/src/catalog/components/combobox.ts +23 -0
  109. package/src/catalog/components/context-menu.ts +20 -0
  110. package/src/catalog/components/data-list.ts +14 -0
  111. package/src/catalog/components/dialog.ts +9 -0
  112. package/src/catalog/components/drawer.ts +9 -0
  113. package/src/catalog/components/em.ts +7 -0
  114. package/src/catalog/components/heading.ts +11 -0
  115. package/src/catalog/components/index.ts +54 -0
  116. package/src/catalog/components/input.ts +23 -0
  117. package/src/catalog/components/inset.ts +15 -0
  118. package/src/catalog/components/item.ts +21 -0
  119. package/src/catalog/components/kbd.ts +9 -0
  120. package/src/catalog/components/link.ts +19 -0
  121. package/src/catalog/components/menu.ts +20 -0
  122. package/src/catalog/components/menubar.ts +20 -0
  123. package/src/catalog/components/meter.ts +19 -0
  124. package/src/catalog/components/number-field.ts +10 -0
  125. package/src/catalog/components/otp-field.ts +9 -0
  126. package/src/catalog/components/popover.ts +9 -0
  127. package/src/catalog/components/preview-card.ts +9 -0
  128. package/src/catalog/components/progress.ts +24 -0
  129. package/src/catalog/components/quote.ts +7 -0
  130. package/src/catalog/components/radio-cards.ts +14 -0
  131. package/src/catalog/components/radio-group.ts +13 -0
  132. package/src/catalog/components/scroll-area.ts +15 -0
  133. package/src/catalog/components/segmented-control.ts +8 -0
  134. package/src/catalog/components/select.ts +26 -0
  135. package/src/catalog/components/separator.ts +14 -0
  136. package/src/catalog/components/skeleton.ts +8 -0
  137. package/src/catalog/components/slider.ts +19 -0
  138. package/src/catalog/components/spinner.ts +15 -0
  139. package/src/catalog/components/strong.ts +7 -0
  140. package/src/catalog/components/switch.ts +19 -0
  141. package/src/catalog/components/tab-nav.ts +18 -0
  142. package/src/catalog/components/table.ts +34 -0
  143. package/src/catalog/components/tabs.ts +18 -0
  144. package/src/catalog/components/text-area.ts +24 -0
  145. package/src/catalog/components/text.ts +11 -0
  146. package/src/catalog/components/toast.ts +12 -0
  147. package/src/catalog/components/toggle-group.ts +17 -0
  148. package/src/catalog/components/toggle.ts +17 -0
  149. package/src/catalog/components/toolbar.ts +6 -0
  150. package/src/catalog/index.ts +4 -0
  151. package/src/catalog/parts.ts +915 -0
  152. package/src/catalog/prop-types-source.ts +93 -0
  153. package/src/catalog/prop-types.generated.ts +1402 -0
  154. package/src/catalog/props.ts +225 -0
  155. package/src/css.ts +318 -0
  156. package/src/generated-css.ts +21 -0
  157. package/src/index.ts +8 -0
  158. package/src/model/compare.ts +127 -0
  159. package/src/model/dom.ts +253 -0
  160. package/src/model/ids.ts +25 -0
  161. package/src/model/index.ts +6 -0
  162. package/src/model/styles.ts +254 -0
  163. package/src/model/types.ts +97 -0
  164. package/src/model/validate.ts +133 -0
  165. package/src/themes/appearances.ts +105 -0
  166. package/src/themes/baseline.ts +27 -0
  167. package/src/themes/index.ts +85 -0
  168. package/src/themes/reference.ts +9 -0
  169. package/src/themes/shadcn.ts +239 -0
  170. package/src/themes/types.ts +53 -0
  171. package/src/tokens/at.ts +13 -0
  172. package/src/tokens/base.ts +48 -0
  173. package/src/tokens/color/bezier.ts +111 -0
  174. package/src/tokens/color/index.ts +2 -0
  175. package/src/tokens/color/radix-generator.ts +516 -0
  176. package/src/tokens/dtcg.ts +298 -0
  177. package/src/tokens/files/foundations.tokens.json +318 -0
  178. package/src/tokens/files/palette.tokens.json +58 -0
  179. package/src/tokens/files/themes/agent-native.dark.tokens.json +405 -0
  180. package/src/tokens/files/themes/agent-native.light.tokens.json +405 -0
  181. package/src/tokens/files/themes/analytics.dark.tokens.json +391 -0
  182. package/src/tokens/files/themes/analytics.light.tokens.json +391 -0
  183. package/src/tokens/files/themes/assets.dark.tokens.json +391 -0
  184. package/src/tokens/files/themes/assets.light.tokens.json +391 -0
  185. package/src/tokens/files/themes/brain.dark.tokens.json +391 -0
  186. package/src/tokens/files/themes/brain.light.tokens.json +391 -0
  187. package/src/tokens/files/themes/calendar.dark.tokens.json +391 -0
  188. package/src/tokens/files/themes/calendar.light.tokens.json +391 -0
  189. package/src/tokens/files/themes/chat.dark.tokens.json +391 -0
  190. package/src/tokens/files/themes/chat.light.tokens.json +391 -0
  191. package/src/tokens/files/themes/clips.dark.tokens.json +391 -0
  192. package/src/tokens/files/themes/clips.light.tokens.json +391 -0
  193. package/src/tokens/files/themes/content.dark.tokens.json +391 -0
  194. package/src/tokens/files/themes/content.light.tokens.json +391 -0
  195. package/src/tokens/files/themes/crm.dark.tokens.json +391 -0
  196. package/src/tokens/files/themes/crm.light.tokens.json +391 -0
  197. package/src/tokens/files/themes/design.dark.tokens.json +391 -0
  198. package/src/tokens/files/themes/design.light.tokens.json +391 -0
  199. package/src/tokens/files/themes/desktop.dark.tokens.json +391 -0
  200. package/src/tokens/files/themes/desktop.light.tokens.json +391 -0
  201. package/src/tokens/files/themes/dispatch.dark.tokens.json +391 -0
  202. package/src/tokens/files/themes/dispatch.light.tokens.json +391 -0
  203. package/src/tokens/files/themes/docs.dark.tokens.json +391 -0
  204. package/src/tokens/files/themes/docs.light.tokens.json +391 -0
  205. package/src/tokens/files/themes/factory.dark.tokens.json +391 -0
  206. package/src/tokens/files/themes/factory.light.tokens.json +391 -0
  207. package/src/tokens/files/themes/forms.dark.tokens.json +391 -0
  208. package/src/tokens/files/themes/forms.light.tokens.json +391 -0
  209. package/src/tokens/files/themes/mail.dark.tokens.json +391 -0
  210. package/src/tokens/files/themes/mail.light.tokens.json +391 -0
  211. package/src/tokens/files/themes/plan.dark.tokens.json +391 -0
  212. package/src/tokens/files/themes/plan.light.tokens.json +391 -0
  213. package/src/tokens/files/themes/slides.dark.tokens.json +391 -0
  214. package/src/tokens/files/themes/slides.light.tokens.json +391 -0
  215. package/src/tokens/files/themes/tasks.dark.tokens.json +391 -0
  216. package/src/tokens/files/themes/tasks.light.tokens.json +391 -0
  217. package/src/tokens/palette.ts +354 -0
  218. package/src/tokens/primitives.ts +84 -0
  219. package/src/tokens/roles.ts +269 -0
  220. package/src/tokens/round-trip.ts +277 -0
  221. package/src/tokens/source.ts +302 -0
  222. package/tsconfig.json +26 -0
@@ -0,0 +1,354 @@
1
+ import * as RadixColors from "@radix-ui/colors";
2
+ import Color from "colorjs.io";
3
+
4
+ import { at } from "./at.js";
5
+ import { BASE_BY_APPEARANCE } from "./base.js";
6
+ import {
7
+ type Appearance,
8
+ generateRadixColors,
9
+ RADIX_SCALE_NAMES,
10
+ type RadixColorsOutput,
11
+ type RadixScaleName,
12
+ type Scale12,
13
+ } from "./color/radix-generator.js";
14
+ import type { TokenMap } from "./primitives.js";
15
+ import { PALETTE_DEFAULTS } from "./source.js";
16
+
17
+ export type StatusRole = "danger" | "warning" | "success" | "info";
18
+ export const STATUS_ROLES: readonly StatusRole[] = [
19
+ "danger",
20
+ "warning",
21
+ "success",
22
+ "info",
23
+ ];
24
+
25
+ export interface PaletteInput {
26
+ /** Any CSS color. Becomes the 12-step `--brand-*` scale. */
27
+ brand: string;
28
+ /** Any CSS color whose hue and chroma tint the `--gray-*` scale. */
29
+ gray?: string;
30
+ /** Page background per appearance. */
31
+ background?: Partial<Record<Appearance, string>>;
32
+ /** A Radix scale name (`"tomato"`) or any CSS color, per status role. */
33
+ status?: Partial<Record<StatusRole, RadixScaleName | string>>;
34
+ }
35
+
36
+ export interface ResolvedPaletteInput {
37
+ brand: string;
38
+ gray: string;
39
+ background: Record<Appearance, string>;
40
+ status: Record<StatusRole, string>;
41
+ }
42
+
43
+ export interface AppearanceTokens {
44
+ /** sRGB values every browser can paint. */
45
+ srgb: TokenMap;
46
+ /** Display-P3 overrides, applied only on wide-gamut screens. */
47
+ p3: TokenMap;
48
+ /** shadcn HSL triplets (`--primary: 240 5% 26%`) for unmigrated code. */
49
+ legacy: TokenMap;
50
+ }
51
+
52
+ export interface Palette {
53
+ input: ResolvedPaletteInput;
54
+ light: AppearanceTokens;
55
+ dark: AppearanceTokens;
56
+ }
57
+
58
+ /** From `files/palette.tokens.json`. */
59
+ export const DEFAULT_PALETTE_INPUT: ResolvedPaletteInput = PALETTE_DEFAULTS;
60
+
61
+ const radixPalettes = RadixColors as unknown as Record<
62
+ string,
63
+ Record<string, string>
64
+ >;
65
+
66
+ function isRadixScaleName(value: string): value is RadixScaleName {
67
+ return (RADIX_SCALE_NAMES as readonly string[]).includes(value);
68
+ }
69
+
70
+ function statusSeed(value: string): string {
71
+ if (!isRadixScaleName(value)) return value;
72
+ const seed = radixPalettes[value]?.[`${value}9`];
73
+ if (!seed) throw new Error(`Missing Radix step 9 for ${value}`);
74
+ return seed;
75
+ }
76
+
77
+ export function resolvePaletteInput(input: PaletteInput): ResolvedPaletteInput {
78
+ return {
79
+ brand: input.brand,
80
+ gray: input.gray ?? DEFAULT_PALETTE_INPUT.gray,
81
+ background: {
82
+ light: input.background?.light ?? DEFAULT_PALETTE_INPUT.background.light,
83
+ dark: input.background?.dark ?? DEFAULT_PALETTE_INPUT.background.dark,
84
+ },
85
+ status: {
86
+ danger: input.status?.danger ?? DEFAULT_PALETTE_INPUT.status.danger,
87
+ warning: input.status?.warning ?? DEFAULT_PALETTE_INPUT.status.warning,
88
+ success: input.status?.success ?? DEFAULT_PALETTE_INPUT.status.success,
89
+ info: input.status?.info ?? DEFAULT_PALETTE_INPUT.status.info,
90
+ },
91
+ };
92
+ }
93
+
94
+ /**
95
+ * Every color primitive for a brand, in both appearances: the brand, gray and
96
+ * status scales (12 solid + 12 alpha steps each, plus contrast, surface,
97
+ * indicator and track), the base surfaces, and the legacy shadcn triplets.
98
+ * Throws on an unparseable color rather than falling back to a default.
99
+ */
100
+ export function createPalette(input: PaletteInput): Palette {
101
+ const resolved = resolvePaletteInput(input);
102
+ return {
103
+ input: resolved,
104
+ light: appearanceTokens(resolved, "light"),
105
+ dark: appearanceTokens(resolved, "dark"),
106
+ };
107
+ }
108
+
109
+ function appearanceTokens(
110
+ input: ResolvedPaletteInput,
111
+ appearance: Appearance,
112
+ ): AppearanceTokens {
113
+ const background = input.background[appearance];
114
+ const brand = generateRadixColors({
115
+ appearance,
116
+ accent: input.brand,
117
+ gray: input.gray,
118
+ background,
119
+ });
120
+ const srgb: TokenMap = {};
121
+ const p3: TokenMap = {};
122
+
123
+ writeScale(srgb, p3, "gray", {
124
+ solid: brand.grayScale,
125
+ alpha: brand.grayScaleAlpha,
126
+ solidP3: brand.grayScaleWideGamut,
127
+ alphaP3: brand.grayScaleAlphaWideGamut,
128
+ contrast: "#ffffff",
129
+ surface: brand.graySurface,
130
+ surfaceP3: brand.graySurfaceWideGamut,
131
+ background: brand.background,
132
+ });
133
+ writeAccent(srgb, p3, "brand", brand);
134
+
135
+ const statusScales = {} as Record<StatusRole, RadixColorsOutput>;
136
+ for (const role of STATUS_ROLES) {
137
+ statusScales[role] = generateRadixColors({
138
+ appearance,
139
+ accent: statusSeed(input.status[role]),
140
+ gray: input.gray,
141
+ background,
142
+ });
143
+ writeAccent(srgb, p3, role, statusScales[role]);
144
+ }
145
+
146
+ const base = BASE_BY_APPEARANCE[appearance];
147
+ srgb["--base-background"] = brand.background;
148
+ srgb["--base-panel"] =
149
+ appearance === "light" ? brand.background : brand.grayScale[1];
150
+ srgb["--base-field"] = base.field;
151
+ srgb["--base-overlay"] = base.overlay;
152
+ base.shadowTint.forEach((value, index) => {
153
+ srgb[`--shadow-tint-a${index + 1}`] = value;
154
+ });
155
+
156
+ return {
157
+ srgb,
158
+ p3,
159
+ legacy: legacyTriplets(
160
+ brand,
161
+ srgb["--base-panel"],
162
+ statusScales.danger,
163
+ statusScales.success,
164
+ ),
165
+ };
166
+ }
167
+
168
+ interface ScaleSource {
169
+ solid: Scale12;
170
+ alpha: Scale12;
171
+ solidP3: Scale12;
172
+ alphaP3: Scale12;
173
+ contrast: string;
174
+ surface: string;
175
+ surfaceP3: string;
176
+ background: string;
177
+ }
178
+
179
+ function writeScale(
180
+ srgb: TokenMap,
181
+ p3: TokenMap,
182
+ name: string,
183
+ source: ScaleSource,
184
+ ) {
185
+ source.solid.forEach((value, index) => {
186
+ srgb[`--${name}-${index + 1}`] = value;
187
+ p3[`--${name}-${index + 1}`] = at(source.solidP3, index);
188
+ });
189
+ source.alpha.forEach((value, index) => {
190
+ srgb[`--${name}-a${index + 1}`] = value;
191
+ p3[`--${name}-a${index + 1}`] = at(source.alphaP3, index);
192
+ });
193
+ srgb[`--${name}-contrast`] = source.contrast;
194
+ srgb[`--${name}-surface`] = source.surface;
195
+ p3[`--${name}-surface`] = source.surfaceP3;
196
+ writeReadableSteps(srgb, name, source);
197
+ }
198
+
199
+ const TEXT_CONTRAST = 4.5;
200
+
201
+ function stepsNearest(from: number): number[] {
202
+ return Array.from({ length: 12 }, (_, index) => index + 1).sort(
203
+ (a, b) => Math.abs(a - from) - Math.abs(b - from) || b - a,
204
+ );
205
+ }
206
+
207
+ function readableStep(
208
+ scale: Scale12,
209
+ from: number,
210
+ against: readonly string[],
211
+ what: string,
212
+ ): number {
213
+ const step = stepsNearest(from).find((candidate) =>
214
+ against.every(
215
+ (background) =>
216
+ new Color(at(scale, candidate - 1)).contrast(background, "WCAG21") >=
217
+ TEXT_CONTRAST,
218
+ ),
219
+ );
220
+ if (step === undefined) {
221
+ throw new Error(`No step of this scale holds ${TEXT_CONTRAST}:1 ${what}`);
222
+ }
223
+ return step;
224
+ }
225
+
226
+ function readableTextMix(
227
+ source: ScaleSource,
228
+ backgrounds: readonly string[],
229
+ ): number {
230
+ const eleven = new Color(at(source.solid, 10));
231
+ const twelve = new Color(at(source.solid, 11));
232
+ for (let percent = 0; percent <= 100; percent += 5) {
233
+ const text = eleven.mix(twelve, percent / 100, { space: "oklab" });
234
+ if (
235
+ backgrounds.every(
236
+ (background) => text.contrast(background, "WCAG21") >= TEXT_CONTRAST,
237
+ )
238
+ ) {
239
+ return percent;
240
+ }
241
+ }
242
+ throw new Error(
243
+ `Neither step 11 nor 12 holds ${TEXT_CONTRAST}:1 on its tints`,
244
+ );
245
+ }
246
+
247
+ function over(alpha: string, background: string): string {
248
+ const top = new Color(alpha).to("srgb");
249
+ const bottom = new Color(background).to("srgb");
250
+ const a = top.alpha;
251
+ const coords = top.coords.map(
252
+ (value, index) => (value ?? 0) * a + (bottom.coords[index] ?? 0) * (1 - a),
253
+ ) as [number, number, number];
254
+ return new Color("srgb", coords).toString({ format: "hex" });
255
+ }
256
+
257
+ function writeReadableSteps(srgb: TokenMap, name: string, source: ScaleSource) {
258
+ const solid = readableStep(
259
+ source.solid,
260
+ 9,
261
+ [source.contrast],
262
+ `under ${source.contrast} text`,
263
+ );
264
+ const text = readableTextMix(source, [
265
+ source.background,
266
+ over(at(source.alpha, 2), source.background),
267
+ over(at(source.alpha, 3), source.background),
268
+ ]);
269
+ const toward = new Color(source.contrast).luminance > 0.5 ? "black" : "white";
270
+ srgb[`--${name}-solid`] = `var(--${name}-${solid})`;
271
+ srgb[`--${name}-solid-hover`] =
272
+ `color-mix(in oklab, var(--${name}-${solid}) 88%, ${toward})`;
273
+ srgb[`--${name}-text`] =
274
+ text === 0
275
+ ? `var(--${name}-11)`
276
+ : `color-mix(in oklab, var(--${name}-11), var(--${name}-12) ${text}%)`;
277
+ }
278
+
279
+ function writeAccent(
280
+ srgb: TokenMap,
281
+ p3: TokenMap,
282
+ name: string,
283
+ colors: RadixColorsOutput,
284
+ ) {
285
+ writeScale(srgb, p3, name, {
286
+ solid: colors.accentScale,
287
+ alpha: colors.accentScaleAlpha,
288
+ solidP3: colors.accentScaleWideGamut,
289
+ alphaP3: colors.accentScaleAlphaWideGamut,
290
+ contrast: colors.accentContrast,
291
+ surface: colors.accentSurface,
292
+ surfaceP3: colors.accentSurfaceWideGamut,
293
+ background: colors.background,
294
+ });
295
+ srgb[`--${name}-indicator`] = colors.accentScale[8];
296
+ srgb[`--${name}-track`] = colors.accentScale[8];
297
+ p3[`--${name}-indicator`] = colors.accentScaleWideGamut[8];
298
+ p3[`--${name}-track`] = colors.accentScaleWideGamut[8];
299
+ }
300
+
301
+ const toHsl = (value: string) => new Color(value).to("hsl");
302
+
303
+ function round(value: number): string {
304
+ return Number(value.toFixed(3)).toString();
305
+ }
306
+
307
+ /** `H S% L%`, the format shadcn variables are consumed in (`hsl(var(--x) / a)`). */
308
+ export function toHslTriplet(value: string): string {
309
+ const [hue, saturation, lightness] = toHsl(value).coords;
310
+ return `${round(hue ?? 0)} ${round(saturation ?? 0)}% ${round(lightness ?? 0)}%`;
311
+ }
312
+
313
+ function legacyTriplets(
314
+ colors: RadixColorsOutput,
315
+ panel: string,
316
+ danger: RadixColorsOutput,
317
+ success: RadixColorsOutput,
318
+ ): TokenMap {
319
+ const gray = (step: number) => at(colors.grayScale, step - 1);
320
+ const brand = (step: number) => at(colors.accentScale, step - 1);
321
+ const values: TokenMap = {
322
+ "--background": colors.background,
323
+ "--foreground": gray(12),
324
+ "--card": panel,
325
+ "--card-foreground": gray(12),
326
+ "--popover": panel,
327
+ "--popover-foreground": gray(12),
328
+ "--primary": brand(9),
329
+ "--primary-foreground": colors.accentContrast,
330
+ "--secondary": gray(3),
331
+ "--secondary-foreground": gray(12),
332
+ "--muted": gray(3),
333
+ "--muted-foreground": gray(11),
334
+ "--accent": gray(3),
335
+ "--accent-foreground": gray(12),
336
+ "--destructive": danger.accentScale[8],
337
+ "--destructive-foreground": danger.accentContrast,
338
+ "--border": gray(6),
339
+ "--input": gray(7),
340
+ "--ring": brand(8),
341
+ "--sidebar-background": gray(2),
342
+ "--sidebar-foreground": gray(11),
343
+ "--sidebar-primary": brand(9),
344
+ "--sidebar-primary-foreground": colors.accentContrast,
345
+ "--sidebar-accent": gray(4),
346
+ "--sidebar-accent-foreground": gray(12),
347
+ "--sidebar-border": gray(6),
348
+ "--sidebar-ring": brand(8),
349
+ "--success": success.accentScale[8],
350
+ };
351
+ return Object.fromEntries(
352
+ Object.entries(values).map(([name, value]) => [name, toHslTriplet(value)]),
353
+ ) as TokenMap;
354
+ }
@@ -0,0 +1,84 @@
1
+ import { FOUNDATIONS, type TypeStep } from "./source.js";
2
+
3
+ export type { TypeStep };
4
+
5
+ export type TokenName = `--${string}`;
6
+ export type TokenMap = Record<TokenName, string>;
7
+
8
+ /**
9
+ * Control heights for xs, sm, md, lg. The same at every density: with a
10
+ * 16px floor there is no smaller step, so shifting the scale for compact would
11
+ * make two sizes identical. Density varies spacing instead. 28 and 36 are
12
+ * deliberately absent.
13
+ */
14
+ export const CONTROL_HEIGHTS: readonly number[] = FOUNDATIONS.controlHeights;
15
+
16
+ /** Glyph size per control size; the inset is (height - glyph) / 2. */
17
+ export const CONTROL_ICON_SIZES: readonly number[] =
18
+ FOUNDATIONS.controlIconSizes;
19
+
20
+ /** `--size-1..8` for boxes that are not controls: avatars, thumbnails, rows. */
21
+ export const SIZE_RAMP: readonly number[] = FOUNDATIONS.sizeRamp;
22
+
23
+ /** Multiplied by `--radius-factor` into `--radius-1..6`. */
24
+ export const RADIUS_STEPS: readonly number[] = FOUNDATIONS.radiusSteps;
25
+
26
+ /** The type scale's steps, `--font-size-0..9` and their line heights and letter spacings. */
27
+ export const TYPE_RAMP: readonly TypeStep[] = FOUNDATIONS.typeRamp;
28
+
29
+ export const FONT_WEIGHTS: Readonly<Record<string, number>> =
30
+ FOUNDATIONS.fontWeights;
31
+
32
+ export const FONT_FAMILIES: Readonly<Record<string, string>> =
33
+ FOUNDATIONS.fontFamilies;
34
+
35
+ export const MOTION = {
36
+ "--duration-1": "100ms",
37
+ "--duration-2": "150ms",
38
+ "--duration-3": "250ms",
39
+ "--duration-4": "400ms",
40
+ "--ease-standard": "cubic-bezier(0.4, 0, 0.2, 1)",
41
+ "--ease-enter": "cubic-bezier(0, 0, 0.2, 1)",
42
+ "--ease-exit": "cubic-bezier(0.4, 0, 1, 1)",
43
+ } as const satisfies TokenMap;
44
+
45
+ /** Toolkit's stacking order: a menu opened from a dialog sits above it. */
46
+ export const LAYERS = {
47
+ "--layer-drawer-backdrop": "250",
48
+ "--layer-drawer": "250",
49
+ "--layer-dialog-backdrop": "270",
50
+ "--layer-dialog": "280",
51
+ "--layer-drawer-over-dialog-backdrop": "284",
52
+ "--layer-drawer-over-dialog": "285",
53
+ "--layer-popup": "290",
54
+ "--layer-alert-dialog-backdrop": "340",
55
+ "--layer-alert-dialog": "350",
56
+ "--layer-toast": "400",
57
+ "--layer-tooltip": "500",
58
+ } as const satisfies TokenMap;
59
+
60
+ const px = (value: number) => `${value}px`;
61
+
62
+ export function staticPrimitives(): TokenMap {
63
+ const tokens: TokenMap = {};
64
+ SIZE_RAMP.forEach((value, index) => {
65
+ tokens[`--size-${index + 1}`] = px(value);
66
+ });
67
+ RADIUS_STEPS.forEach((value, index) => {
68
+ tokens[`--radius-${index + 1}`] =
69
+ `calc(${px(value)} * var(--radius-factor))`;
70
+ });
71
+ tokens["--radius-full"] = "9999px";
72
+ for (const { step, size, lineHeight, letterSpacing } of TYPE_RAMP) {
73
+ tokens[`--font-size-${step}`] = px(size);
74
+ tokens[`--line-height-${step}`] = px(lineHeight);
75
+ tokens[`--letter-spacing-${step}`] = letterSpacing;
76
+ }
77
+ for (const [name, weight] of Object.entries(FONT_WEIGHTS)) {
78
+ tokens[`--font-weight-${name}`] = String(weight);
79
+ }
80
+ for (const [name, family] of Object.entries(FONT_FAMILIES)) {
81
+ tokens[`--font-family-${name}`] = family;
82
+ }
83
+ return { ...tokens, ...MOTION, ...LAYERS };
84
+ }
@@ -0,0 +1,269 @@
1
+ import { at } from "./at.js";
2
+ import {
3
+ CONTROL_HEIGHTS,
4
+ CONTROL_ICON_SIZES,
5
+ type TokenMap,
6
+ type TokenName,
7
+ } from "./primitives.js";
8
+
9
+ /**
10
+ * Semantic roles: what a value is for. Components and themes read these.
11
+ * Each role is listed with its standard mapping onto the primitive scales;
12
+ * the app themes map the same names onto their own values instead.
13
+ */
14
+
15
+ export const ROLE_GROUPS = {
16
+ surface: [
17
+ "--surface-app",
18
+ "--surface-nav",
19
+ "--surface-canvas",
20
+ "--surface-raised",
21
+ "--surface-sunken",
22
+ "--surface-overlay",
23
+ "--surface-inverse",
24
+ ],
25
+ text: [
26
+ "--fg-default",
27
+ "--fg-muted",
28
+ "--fg-subtle",
29
+ "--fg-disabled",
30
+ "--fg-on-brand",
31
+ "--fg-on-danger",
32
+ "--fg-brand",
33
+ "--fg-danger",
34
+ "--fg-inverse",
35
+ ],
36
+ line: ["--line-default", "--line-subtle", "--line-strong", "--line-focus"],
37
+ fill: [
38
+ "--fill-hover",
39
+ "--fill-pressed",
40
+ "--fill-selected",
41
+ "--fill-neutral",
42
+ "--fill-neutral-hover",
43
+ "--fill-field",
44
+ "--fill-brand",
45
+ "--fill-brand-hover",
46
+ "--fill-brand-subtle",
47
+ "--fill-danger",
48
+ "--fill-danger-hover",
49
+ "--fill-danger-subtle",
50
+ ],
51
+ status: (["danger", "warning", "success", "info"] as const).flatMap(
52
+ (status) =>
53
+ (["solid", "subtle", "fg", "line"] as const).map(
54
+ (kind) => `--status-${status}-${kind}` as const,
55
+ ),
56
+ ),
57
+ elevation: [
58
+ "--shadow-1",
59
+ "--shadow-2",
60
+ "--shadow-3",
61
+ "--shadow-4",
62
+ "--shadow-5",
63
+ "--shadow-6",
64
+ ],
65
+ gradient: ["--gradient-brand", "--gradient-surface", "--gradient-glow"],
66
+ } as const satisfies Record<string, readonly TokenName[]>;
67
+
68
+ export type RoleToken = (typeof ROLE_GROUPS)[keyof typeof ROLE_GROUPS][number];
69
+
70
+ /**
71
+ * Shape roles do not depend on appearance, so themes declare them once at the
72
+ * theme root (`ThemeDefinition.tokens`), where a `data-radius` preset can
73
+ * override them for a subtree.
74
+ */
75
+ export const SHAPE_TOKEN_NAMES = [
76
+ "--shape-control",
77
+ "--shape-popup",
78
+ "--shape-card",
79
+ "--shape-panel",
80
+ "--shape-dialog",
81
+ "--shape-pill",
82
+ ] as const;
83
+
84
+ export type ShapeToken = (typeof SHAPE_TOKEN_NAMES)[number];
85
+
86
+ export const STANDARD_SHAPE_TOKENS: Record<ShapeToken, string> = {
87
+ "--shape-control": "var(--radius-3)",
88
+ "--shape-popup": "var(--radius-4)",
89
+ "--shape-card": "var(--radius-5)",
90
+ "--shape-panel": "var(--radius-5)",
91
+ "--shape-dialog": "var(--radius-6)",
92
+ "--shape-pill": "var(--radius-full)",
93
+ };
94
+
95
+ export const FOCUS_RING_TOKENS: TokenMap = {
96
+ "--focus-ring-width": "2px",
97
+ "--focus-ring-offset": "2px",
98
+ };
99
+
100
+ /** Standard role mapping onto the generated scales, shared by both appearances. */
101
+ export const STANDARD_ROLES: Record<RoleToken, string> = {
102
+ "--surface-app": "var(--gray-2)",
103
+ "--surface-nav": "var(--gray-2)",
104
+ "--surface-canvas": "var(--base-background)",
105
+ "--surface-raised": "var(--base-panel)",
106
+ "--surface-sunken": "var(--gray-3)",
107
+ "--surface-overlay": "var(--base-overlay)",
108
+ "--surface-inverse": "var(--gray-12)",
109
+
110
+ "--fg-default": "var(--gray-12)",
111
+ "--fg-muted": "var(--gray-11)",
112
+ "--fg-subtle": "var(--gray-a10)",
113
+ "--fg-disabled": "var(--gray-a8)",
114
+ "--fg-on-brand": "var(--brand-contrast)",
115
+ "--fg-on-danger": "var(--danger-contrast)",
116
+ "--fg-brand": "var(--brand-text)",
117
+ "--fg-danger": "var(--danger-text)",
118
+ "--fg-inverse": "var(--gray-1)",
119
+
120
+ "--line-default": "var(--gray-a6)",
121
+ "--line-subtle": "var(--gray-a5)",
122
+ "--line-strong": "var(--gray-a7)",
123
+ "--line-focus": "var(--brand-8)",
124
+
125
+ "--fill-hover": "var(--gray-a3)",
126
+ "--fill-pressed": "var(--gray-a4)",
127
+ "--fill-selected": "var(--brand-a3)",
128
+ "--fill-neutral": "var(--gray-a3)",
129
+ "--fill-neutral-hover": "var(--gray-a4)",
130
+ "--fill-field": "var(--base-field)",
131
+ "--fill-brand": "var(--brand-9)",
132
+ "--fill-brand-hover": "var(--brand-10)",
133
+ "--fill-brand-subtle": "var(--brand-a3)",
134
+ "--fill-danger": "var(--danger-9)",
135
+ "--fill-danger-hover": "var(--danger-10)",
136
+ "--fill-danger-subtle": "var(--danger-a3)",
137
+
138
+ "--status-danger-solid": "var(--danger-9)",
139
+ "--status-danger-subtle": "var(--danger-a3)",
140
+ "--status-danger-fg": "var(--danger-text)",
141
+ "--status-danger-line": "var(--danger-a6)",
142
+ "--status-warning-solid": "var(--warning-9)",
143
+ "--status-warning-subtle": "var(--warning-a3)",
144
+ "--status-warning-fg": "var(--warning-text)",
145
+ "--status-warning-line": "var(--warning-a6)",
146
+ "--status-success-solid": "var(--success-9)",
147
+ "--status-success-subtle": "var(--success-a3)",
148
+ "--status-success-fg": "var(--success-text)",
149
+ "--status-success-line": "var(--success-a6)",
150
+ "--status-info-solid": "var(--info-9)",
151
+ "--status-info-subtle": "var(--info-a3)",
152
+ "--status-info-fg": "var(--info-text)",
153
+ "--status-info-line": "var(--info-a6)",
154
+
155
+ "--shadow-1": "inset 0 0 0 1px var(--gray-a5)",
156
+ "--shadow-2":
157
+ "0 0 0 1px var(--gray-a3), 0 1px 1px 0 var(--shadow-tint-a1), 0 2px 1px -1px var(--shadow-tint-a2)",
158
+ "--shadow-3":
159
+ "0 0 0 1px var(--gray-a3), 0 2px 3px -2px var(--shadow-tint-a2), 0 3px 12px -4px var(--shadow-tint-a3)",
160
+ "--shadow-4":
161
+ "0 0 0 1px var(--gray-a3), 0 8px 40px var(--shadow-tint-a1), 0 12px 32px -16px var(--shadow-tint-a3)",
162
+ "--shadow-5":
163
+ "0 0 0 1px var(--gray-a3), 0 12px 60px var(--shadow-tint-a3), 0 12px 32px -16px var(--shadow-tint-a5)",
164
+ "--shadow-6":
165
+ "0 0 0 1px var(--gray-a3), 0 12px 60px var(--shadow-tint-a3), 0 16px 64px var(--shadow-tint-a2), 0 16px 36px -20px var(--shadow-tint-a7)",
166
+
167
+ "--gradient-brand":
168
+ "linear-gradient(135deg, var(--brand-8), var(--brand-10))",
169
+ "--gradient-surface":
170
+ "linear-gradient(180deg, var(--base-background), var(--gray-2))",
171
+ "--gradient-glow":
172
+ "radial-gradient(120% 80% at 50% 0%, var(--brand-a4), transparent 70%)",
173
+ };
174
+
175
+ export type Density = "compact" | "default" | "comfortable";
176
+ export const DENSITIES: readonly Density[] = [
177
+ "compact",
178
+ "default",
179
+ "comfortable",
180
+ ];
181
+
182
+ /** Control sizes, numbered as Radix numbers them: heights of 16, 20, 24 and 32px. */
183
+ export const CONTROL_SIZES = ["1", "2", "3", "4"] as const;
184
+ export type ControlSize = (typeof CONTROL_SIZES)[number];
185
+
186
+ const CONTROL_TEXT_STEPS: Readonly<Record<ControlSize, number>> = {
187
+ "1": 1,
188
+ "2": 1,
189
+ "3": 1,
190
+ "4": 1,
191
+ };
192
+
193
+ type Four = readonly [number, number, number, number];
194
+ type Nine = readonly [
195
+ number,
196
+ number,
197
+ number,
198
+ number,
199
+ number,
200
+ number,
201
+ number,
202
+ number,
203
+ number,
204
+ ];
205
+
206
+ const DENSITY_SCALES: Record<
207
+ Density,
208
+ { padding: Four; gap: number; space: Nine }
209
+ > = {
210
+ compact: {
211
+ padding: [4, 4, 4, 8],
212
+ gap: 4,
213
+ space: [4, 8, 12, 16, 20, 24, 32, 40, 48],
214
+ },
215
+ default: {
216
+ padding: [4, 4, 8, 12],
217
+ gap: 4,
218
+ space: [4, 8, 12, 16, 24, 32, 40, 48, 64],
219
+ },
220
+ comfortable: {
221
+ padding: [8, 8, 12, 16],
222
+ gap: 8,
223
+ space: [8, 12, 16, 24, 32, 40, 48, 64, 80],
224
+ },
225
+ };
226
+
227
+ export function densityTokens(density: Density): TokenMap {
228
+ const scale = DENSITY_SCALES[density];
229
+ const tokens: TokenMap = { "--density": density };
230
+ scale.space.forEach((value, index) => {
231
+ tokens[`--space-${index + 1}`] = `${value}px`;
232
+ });
233
+ CONTROL_SIZES.forEach((size, index) => {
234
+ tokens[`--control-height-${size}`] = `${at(CONTROL_HEIGHTS, index)}px`;
235
+ tokens[`--control-padding-x-${size}`] = `${at(scale.padding, index)}px`;
236
+ tokens[`--control-icon-size-${size}`] =
237
+ `${at(CONTROL_ICON_SIZES, index)}px`;
238
+ });
239
+ tokens["--control-gap"] = `${scale.gap}px`;
240
+ tokens["--control-font-size"] = "var(--font-size-1)";
241
+ tokens["--control-line-height"] = "var(--line-height-1)";
242
+ for (const size of CONTROL_SIZES) {
243
+ const step = CONTROL_TEXT_STEPS[size];
244
+ tokens[`--control-font-size-${size}`] = `var(--font-size-${step})`;
245
+ tokens[`--control-line-height-${size}`] = `var(--line-height-${step})`;
246
+ }
247
+ return tokens;
248
+ }
249
+
250
+ export type RadiusPreset = "none" | "small" | "medium" | "large" | "full";
251
+ export const RADIUS_PRESETS: readonly RadiusPreset[] = [
252
+ "none",
253
+ "small",
254
+ "medium",
255
+ "large",
256
+ "full",
257
+ ];
258
+
259
+ export function radiusTokens(preset: RadiusPreset): TokenMap {
260
+ const factor = { none: 0, small: 0.75, medium: 1, large: 1.5, full: 1.5 }[
261
+ preset
262
+ ];
263
+ const tokens: TokenMap = { "--radius-factor": String(factor) };
264
+ if (preset === "full") {
265
+ tokens["--shape-control"] = "var(--radius-full)";
266
+ tokens["--shape-pill"] = "var(--radius-full)";
267
+ }
268
+ return tokens;
269
+ }