@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,133 @@
1
+ import { PARTS, type PartDefinition } from "../catalog/parts.js";
2
+ import type { ModelRow, RowEffect, ScreenModel } from "./types.js";
3
+
4
+ const ROW_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*(?:\.[a-z0-9]+(?:-[a-z0-9]+)*)+$/;
5
+ const REGION = /^[a-z]+(?:-[a-z]+)*$/;
6
+
7
+ export type ModelIssue =
8
+ | { code: "invalid-id"; rowId: string }
9
+ | { code: "duplicate-id"; rowId: string }
10
+ | { code: "unknown-part"; rowId: string; part: string }
11
+ | { code: "empty-label"; rowId: string }
12
+ | { code: "open-target-missing"; rowId: string; target: string }
13
+ | { code: "section-without-rows"; rowId: string }
14
+ | { code: "duplicate-anchor"; rowId: string; anchor: string }
15
+ | { code: "invalid-region"; rowId: string; region: string }
16
+ | { code: "hosts-without-slot"; rowId: string };
17
+
18
+ export interface FlatRow {
19
+ row: ModelRow;
20
+ depth: number;
21
+ parentId: string | undefined;
22
+ }
23
+
24
+ /** Every row in document order, with its depth and parent. */
25
+ export function flattenModel(model: ScreenModel): FlatRow[] {
26
+ const rows: FlatRow[] = [];
27
+ const visit = (
28
+ list: readonly ModelRow[],
29
+ depth: number,
30
+ parentId: string | undefined,
31
+ ) => {
32
+ for (const row of list) {
33
+ rows.push({ row, depth, parentId });
34
+ if (row.rows) visit(row.rows, depth + 1, row.id);
35
+ }
36
+ };
37
+ visit(model.rows, 0, undefined);
38
+ return rows;
39
+ }
40
+
41
+ function partNames(parts: readonly PartDefinition[]): Set<string> {
42
+ const names = new Set<string>();
43
+ for (const part of parts) {
44
+ names.add(part.name);
45
+ for (const sub of part.subParts) names.add(`${part.name}.${sub}`);
46
+ }
47
+ return names;
48
+ }
49
+
50
+ /**
51
+ * Every structural problem in a model. An empty list means both part sets can
52
+ * draw it and the equivalence check can join their rows.
53
+ */
54
+ export function validateModel(
55
+ model: ScreenModel,
56
+ parts: readonly PartDefinition[] = PARTS,
57
+ ): ModelIssue[] {
58
+ const issues: ModelIssue[] = [];
59
+ const known = partNames(parts);
60
+ const flat = flattenModel(model);
61
+ const ids = new Set<string>();
62
+ const anchors = new Set<string>();
63
+ for (const { row } of flat) {
64
+ if (row.anchor !== undefined) {
65
+ if (anchors.has(row.anchor)) {
66
+ issues.push({
67
+ code: "duplicate-anchor",
68
+ rowId: row.id,
69
+ anchor: row.anchor,
70
+ });
71
+ }
72
+ anchors.add(row.anchor);
73
+ }
74
+ if (!ROW_ID.test(row.id))
75
+ issues.push({ code: "invalid-id", rowId: row.id });
76
+ if (ids.has(row.id)) issues.push({ code: "duplicate-id", rowId: row.id });
77
+ ids.add(row.id);
78
+ if (!known.has(row.part)) {
79
+ issues.push({ code: "unknown-part", rowId: row.id, part: row.part });
80
+ }
81
+ if (row.label.trim() === "") {
82
+ issues.push({ code: "empty-label", rowId: row.id });
83
+ }
84
+ for (const [region, slot] of Object.entries(row.regions ?? {})) {
85
+ if (!REGION.test(region) || slot.trim() === "") {
86
+ issues.push({ code: "invalid-region", rowId: row.id, region });
87
+ }
88
+ }
89
+ const holdsContent =
90
+ row.slot !== undefined || Object.keys(row.regions ?? {}).length > 0;
91
+ if (row.hosts !== undefined && row.hosts.length > 0 && !holdsContent) {
92
+ issues.push({ code: "hosts-without-slot", rowId: row.id });
93
+ }
94
+ if (row.kind === "section" && (row.rows?.length ?? 0) === 0) {
95
+ issues.push({ code: "section-without-rows", rowId: row.id });
96
+ }
97
+ }
98
+ for (const { row } of flat) {
99
+ const target = openTarget(row.effect);
100
+ if (target !== undefined && !ids.has(target)) {
101
+ issues.push({ code: "open-target-missing", rowId: row.id, target });
102
+ }
103
+ }
104
+ return issues;
105
+ }
106
+
107
+ function openTarget(effect: RowEffect | undefined): string | undefined {
108
+ return effect?.kind === "open" ? effect.target : undefined;
109
+ }
110
+
111
+ export class InvalidModelError extends Error {
112
+ constructor(
113
+ readonly modelId: string,
114
+ readonly issues: readonly ModelIssue[],
115
+ ) {
116
+ super(
117
+ `Screen model ${modelId} is invalid: ${issues
118
+ .map((issue) => `${issue.code} (${issue.rowId})`)
119
+ .join(", ")}`,
120
+ );
121
+ this.name = "InvalidModelError";
122
+ }
123
+ }
124
+
125
+ /** The model itself, or an InvalidModelError listing every issue. */
126
+ export function assertValidModel<Model extends ScreenModel>(
127
+ model: Model,
128
+ parts: readonly PartDefinition[] = PARTS,
129
+ ): Model {
130
+ const issues = validateModel(model, parts);
131
+ if (issues.length > 0) throw new InvalidModelError(model.id, issues);
132
+ return model;
133
+ }
@@ -0,0 +1,105 @@
1
+ /**
2
+ * The color tints a person can pick (`data-appearance` on the root, set by
3
+ * core's change-appearance action), as overrides of a theme's own values.
4
+ * The Agent-Native theme ignores them.
5
+ */
6
+ export const APPEARANCES = {
7
+ warm: {
8
+ light: {
9
+ background: "35 30% 97%",
10
+ "sidebar-background": "35 28% 95%",
11
+ accent: "30 35% 92%",
12
+ muted: "35 25% 94%",
13
+ primary: "25 65% 45%",
14
+ ring: "25 55% 50%",
15
+ },
16
+ dark: {
17
+ background: "28 14% 7%",
18
+ "sidebar-background": "28 14% 5%",
19
+ accent: "28 12% 14%",
20
+ muted: "28 10% 12%",
21
+ primary: "30 65% 65%",
22
+ ring: "30 55% 55%",
23
+ },
24
+ },
25
+ ocean: {
26
+ light: {
27
+ background: "210 35% 97%",
28
+ "sidebar-background": "210 32% 95%",
29
+ accent: "200 40% 92%",
30
+ muted: "210 28% 94%",
31
+ primary: "205 70% 42%",
32
+ ring: "205 60% 50%",
33
+ },
34
+ dark: {
35
+ background: "215 25% 8%",
36
+ "sidebar-background": "215 28% 6%",
37
+ accent: "215 22% 15%",
38
+ muted: "215 20% 12%",
39
+ primary: "200 75% 65%",
40
+ ring: "200 65% 55%",
41
+ },
42
+ },
43
+ forest: {
44
+ light: {
45
+ background: "130 22% 97%",
46
+ "sidebar-background": "130 20% 95%",
47
+ accent: "135 28% 92%",
48
+ muted: "130 18% 94%",
49
+ primary: "145 55% 35%",
50
+ ring: "145 45% 45%",
51
+ },
52
+ dark: {
53
+ background: "140 14% 7%",
54
+ "sidebar-background": "140 14% 5%",
55
+ accent: "140 12% 14%",
56
+ muted: "140 10% 12%",
57
+ primary: "145 50% 60%",
58
+ ring: "145 40% 50%",
59
+ },
60
+ },
61
+ rose: {
62
+ light: {
63
+ background: "340 35% 98%",
64
+ "sidebar-background": "340 32% 96%",
65
+ accent: "345 40% 93%",
66
+ muted: "340 28% 95%",
67
+ primary: "345 60% 50%",
68
+ ring: "345 50% 55%",
69
+ },
70
+ dark: {
71
+ background: "340 14% 8%",
72
+ "sidebar-background": "340 14% 6%",
73
+ accent: "340 14% 15%",
74
+ muted: "340 12% 12%",
75
+ primary: "345 65% 65%",
76
+ ring: "345 55% 55%",
77
+ },
78
+ },
79
+ slate: {
80
+ light: {
81
+ background: "215 16% 96%",
82
+ "sidebar-background": "215 14% 94%",
83
+ accent: "215 18% 91%",
84
+ muted: "215 14% 93%",
85
+ primary: "215 25% 25%",
86
+ ring: "215 20% 40%",
87
+ },
88
+ dark: {
89
+ background: "215 14% 8%",
90
+ "sidebar-background": "215 14% 6%",
91
+ accent: "215 12% 14%",
92
+ muted: "215 10% 12%",
93
+ primary: "215 15% 75%",
94
+ ring: "215 12% 60%",
95
+ },
96
+ },
97
+ } as const satisfies Readonly<
98
+ Record<
99
+ string,
100
+ {
101
+ light: Readonly<Record<string, string>>;
102
+ dark: Readonly<Record<string, string>>;
103
+ }
104
+ >
105
+ >;
@@ -0,0 +1,27 @@
1
+ import { createPalette, DEFAULT_PALETTE_INPUT } from "../tokens/palette.js";
2
+ import {
3
+ FOCUS_RING_TOKENS,
4
+ STANDARD_ROLES,
5
+ STANDARD_SHAPE_TOKENS,
6
+ } from "../tokens/roles.js";
7
+ import type { ThemeDefinition } from "./types.js";
8
+
9
+ const scales = createPalette(DEFAULT_PALETTE_INPUT);
10
+
11
+ /**
12
+ * The Agent-Native baseline: 24px controls on the 16/20/24/32 ramp, roles
13
+ * mapped straight onto the generated Radix scales, density and radius live.
14
+ * A preview of the look the `agent-native` theme moves to; apps do not pick
15
+ * it yet. Its shadcn values are written from the default scales.
16
+ */
17
+ export const baselineTheme: ThemeDefinition = {
18
+ name: "baseline",
19
+ label: "Baseline",
20
+ isDefault: false,
21
+ base: { ...STANDARD_ROLES, ...scales.light.legacy },
22
+ dark: { ...STANDARD_ROLES, ...scales.dark.legacy },
23
+ light: { ...STANDARD_ROLES, ...scales.light.legacy },
24
+ tokens: { ...FOCUS_RING_TOKENS, ...STANDARD_SHAPE_TOKENS },
25
+ palette: { light: scales.light, dark: scales.dark },
26
+ readsScales: true,
27
+ };
@@ -0,0 +1,85 @@
1
+ import { tokenThemeValues } from "../tokens/source.js";
2
+ import { baselineTheme } from "./baseline.js";
3
+ import { shadcnTheme, themeProperties } from "./shadcn.js";
4
+ import type { ThemeDefinition } from "./types.js";
5
+
6
+ export { APPEARANCES } from "./appearances.js";
7
+ export { SHADCN_SLOTS, shadcn, shadcnTheme } from "./shadcn.js";
8
+ export type { ThemeDefinition, ThemeValues } from "./types.js";
9
+ export { baselineTheme };
10
+
11
+ const AGENT_NATIVE_EXTRAS = {
12
+ base: {
13
+ "font-sans": '"Inter Variable", "Inter", sans-serif',
14
+ "font-wordmark": '"Geist Variable", "Geist", sans-serif',
15
+ "radius-xl": "0.75rem",
16
+ "shadow-composer":
17
+ "0 8px 15px hsl(var(--agent-native-shadow-color) / 0.06)",
18
+ "agent-kit-composer-radius": "0.75rem",
19
+ "agent-kit-composer-elevation": "var(--shadow-composer)",
20
+ },
21
+ dark: {
22
+ "shadow-composer": "0 8px 30px hsl(var(--background) / 0.22)",
23
+ "agent-kit-composer-elevation": "var(--shadow-composer)",
24
+ },
25
+ };
26
+
27
+ const agentNativeTokens = tokenThemeValues("agent-native", "light");
28
+
29
+ /** The umbrella look every app can switch to; applied with no `data-app-theme`. */
30
+ export const agentNativeTheme: ThemeDefinition = {
31
+ ...shadcnTheme({
32
+ name: "agent-native",
33
+ label: "Agent-Native",
34
+ isDefault: true,
35
+ values: agentNativeTokens,
36
+ }),
37
+ scopedOnly: {
38
+ base: themeProperties(
39
+ "agent-native",
40
+ AGENT_NATIVE_EXTRAS.base,
41
+ agentNativeTokens.base,
42
+ ),
43
+ dark: themeProperties("agent-native", AGENT_NATIVE_EXTRAS.dark, {
44
+ ...agentNativeTokens.base,
45
+ ...agentNativeTokens.dark,
46
+ }),
47
+ },
48
+ };
49
+
50
+ const APPS: ReadonlyArray<readonly [string, string, "light" | "dark"]> = [
51
+ ["analytics", "Analytics", "dark"],
52
+ ["assets", "Assets", "light"],
53
+ ["brain", "Brain", "light"],
54
+ ["calendar", "Calendar", "light"],
55
+ ["chat", "Chat", "light"],
56
+ ["clips", "Clips", "light"],
57
+ ["content", "Content", "light"],
58
+ ["crm", "CRM", "light"],
59
+ ["design", "Design", "light"],
60
+ ["desktop", "Desktop", "light"],
61
+ ["dispatch", "Dispatch", "light"],
62
+ ["docs", "Docs", "light"],
63
+ ["factory", "Factory", "light"],
64
+ ["forms", "Forms", "light"],
65
+ ["mail", "Mail", "light"],
66
+ ["plan", "Plan", "light"],
67
+ ["slides", "Slides", "dark"],
68
+ ["tasks", "Tasks", "light"],
69
+ ];
70
+
71
+ /** One theme per app, named for the app; their values are their token files. */
72
+ export const APP_THEMES: readonly ThemeDefinition[] = APPS.map(
73
+ ([name, label, appearance]) =>
74
+ shadcnTheme({ name, label, values: tokenThemeValues(name, appearance) }),
75
+ );
76
+
77
+ export const THEMES: readonly ThemeDefinition[] = [
78
+ agentNativeTheme,
79
+ ...APP_THEMES,
80
+ baselineTheme,
81
+ ];
82
+
83
+ export function getTheme(name: string): ThemeDefinition | undefined {
84
+ return THEMES.find((theme) => theme.name === name);
85
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * A reference to a palette slot, resolved to the theme's own value when the
3
+ * theme is built. Tailwind compiles `bg-primary/90` to this color-mix, not to
4
+ * an hsl alpha; the two paint alike but resolve to different computed colors.
5
+ */
6
+ export const shadcn = (name: string, alpha?: number) =>
7
+ alpha === undefined
8
+ ? `hsl(var(--${name}))`
9
+ : `color-mix(in oklab, hsl(var(--${name})) ${Math.round(alpha * 100)}%, transparent)`;
@@ -0,0 +1,239 @@
1
+ import Color from "colorjs.io";
2
+
3
+ import { TAILWIND_SHADOWS } from "../tokens/base.js";
4
+ import { createPalette, type PaletteInput } from "../tokens/palette.js";
5
+ import type { TokenMap } from "../tokens/primitives.js";
6
+ import { FOCUS_RING_TOKENS, STANDARD_ROLES } from "../tokens/roles.js";
7
+ import { shadcn } from "./reference.js";
8
+ import type { ThemeDefinition, ThemeValues } from "./types.js";
9
+
10
+ export { shadcn };
11
+
12
+ /**
13
+ * The shadcn slots a palette theme fills. Themes write them out one way for
14
+ * components not yet migrated; nothing in the design system reads them.
15
+ */
16
+ export const SHADCN_SLOTS = [
17
+ "background",
18
+ "foreground",
19
+ "card",
20
+ "card-foreground",
21
+ "popover",
22
+ "popover-foreground",
23
+ "primary",
24
+ "primary-foreground",
25
+ "secondary",
26
+ "secondary-foreground",
27
+ "muted",
28
+ "muted-foreground",
29
+ "accent",
30
+ "accent-foreground",
31
+ "destructive",
32
+ "destructive-foreground",
33
+ "border",
34
+ "input",
35
+ "ring",
36
+ "radius",
37
+ "sidebar-background",
38
+ "sidebar-foreground",
39
+ "sidebar-primary",
40
+ "sidebar-primary-foreground",
41
+ "sidebar-accent",
42
+ "sidebar-accent-foreground",
43
+ "sidebar-border",
44
+ "sidebar-ring",
45
+ ] as const;
46
+
47
+ const SLOTS: ReadonlySet<string> = new Set(SHADCN_SLOTS);
48
+
49
+ const REFERENCE = /var\(--([a-z0-9-]+)(?:,\s*var\(--([a-z0-9-]+)\))?\)/g;
50
+
51
+ const own = (slot: string) => `--theme-${slot}`;
52
+
53
+ function resolve(
54
+ themeName: string,
55
+ tokens: TokenMap,
56
+ values: Readonly<Record<string, string>>,
57
+ ): TokenMap {
58
+ const resolved: TokenMap = {};
59
+ for (const [key, expression] of Object.entries(tokens)) {
60
+ resolved[key as `--${string}`] = expression.replace(
61
+ REFERENCE,
62
+ (match, name: string, fallback: string | undefined) => {
63
+ if (!SLOTS.has(name)) return match;
64
+ const slot =
65
+ name in values
66
+ ? name
67
+ : fallback !== undefined && fallback in values
68
+ ? fallback
69
+ : undefined;
70
+ if (slot === undefined) {
71
+ throw new Error(
72
+ `Theme ${themeName} has no "${name}" for ${key}; add it to the theme's values`,
73
+ );
74
+ }
75
+ return `var(${own(slot)})`;
76
+ },
77
+ );
78
+ }
79
+ return resolved;
80
+ }
81
+
82
+ const SHADCN_ROLES: TokenMap = {
83
+ ...STANDARD_ROLES,
84
+
85
+ "--surface-app": shadcn("background"),
86
+ "--surface-nav": "hsl(var(--sidebar-background, var(--background)))",
87
+ "--surface-canvas": shadcn("background"),
88
+ "--surface-raised": shadcn("popover"),
89
+ "--surface-sunken": shadcn("muted"),
90
+ "--surface-overlay": shadcn("background", 0.45),
91
+ "--surface-inverse": shadcn("foreground"),
92
+
93
+ "--fg-default": shadcn("foreground"),
94
+ "--fg-muted":
95
+ "color-mix(in oklab, hsl(var(--muted-foreground)) 80%, hsl(var(--foreground)))",
96
+ "--fg-subtle": shadcn("muted-foreground"),
97
+ "--fg-disabled": shadcn("muted-foreground"),
98
+ "--fg-on-brand": shadcn("primary-foreground"),
99
+ "--fg-on-danger": shadcn("destructive-foreground"),
100
+ "--fg-brand": "var(--brand-text)",
101
+ "--fg-danger":
102
+ "color-mix(in oklab, hsl(var(--destructive)) 60%, hsl(var(--foreground)))",
103
+ "--fg-inverse": shadcn("background"),
104
+
105
+ "--line-default": shadcn("border"),
106
+ "--line-subtle": shadcn("border"),
107
+ "--line-strong": shadcn("input"),
108
+ "--line-focus": shadcn("ring"),
109
+
110
+ "--fill-hover": shadcn("accent"),
111
+ "--fill-pressed": shadcn("accent"),
112
+ "--fill-selected": shadcn("accent"),
113
+ "--fill-neutral": shadcn("secondary"),
114
+ "--fill-neutral-hover": shadcn("secondary", 0.8),
115
+ "--fill-field": shadcn("background"),
116
+ "--fill-brand": shadcn("primary"),
117
+ "--fill-brand-hover": shadcn("primary", 0.9),
118
+ "--fill-brand-subtle": shadcn("primary", 0.1),
119
+ "--fill-danger": "color-mix(in oklab, hsl(var(--destructive)) 74%, black)",
120
+ "--fill-danger-hover":
121
+ "color-mix(in oklab, hsl(var(--destructive)) 66%, black)",
122
+ "--fill-danger-subtle": shadcn("destructive", 0.1),
123
+
124
+ "--shadow-1": TAILWIND_SHADOWS.xs,
125
+ "--shadow-2": TAILWIND_SHADOWS.sm,
126
+ "--shadow-3": TAILWIND_SHADOWS.md,
127
+ "--shadow-4": TAILWIND_SHADOWS.lg,
128
+ "--shadow-5": TAILWIND_SHADOWS.xl,
129
+ "--shadow-6": TAILWIND_SHADOWS["2xl"],
130
+ };
131
+
132
+ const SHADCN_TOKENS: TokenMap = {
133
+ ...FOCUS_RING_TOKENS,
134
+ "--shape-control": "calc(var(--radius) - 2px)",
135
+ "--shape-popup": "calc(var(--radius) - 2px)",
136
+ "--shape-card": "calc(var(--radius) + 4px)",
137
+ "--shape-panel": "var(--radius)",
138
+ "--shape-dialog": "var(--radius)",
139
+ "--shape-pill": "var(--radius-full)",
140
+ };
141
+
142
+ function declarations(
143
+ themeName: string,
144
+ values: Readonly<Record<string, string>>,
145
+ ): TokenMap {
146
+ const tokens: TokenMap = {};
147
+ for (const [name, value] of Object.entries(values)) {
148
+ if (SLOTS.has(name)) {
149
+ tokens[own(name) as `--${string}`] = value;
150
+ tokens[`--${name}`] = `var(${own(name)})`;
151
+ } else {
152
+ tokens[`--${name}`] = value;
153
+ }
154
+ }
155
+ return resolve(themeName, tokens, values);
156
+ }
157
+
158
+ /**
159
+ * Properties a theme sets beyond its slots (`font-sans`, `shadow-composer`),
160
+ * with slot references resolved to the theme's own values.
161
+ */
162
+ export function themeProperties(
163
+ themeName: string,
164
+ properties: Readonly<Record<string, string>>,
165
+ values: Readonly<Record<string, string>>,
166
+ ): TokenMap {
167
+ const tokens: TokenMap = {};
168
+ for (const [name, value] of Object.entries(properties)) {
169
+ tokens[`--${name}`] = value;
170
+ }
171
+ return resolve(themeName, tokens, values);
172
+ }
173
+
174
+ function themePalette(
175
+ name: string,
176
+ light: Readonly<Record<string, string>>,
177
+ dark: Readonly<Record<string, string>>,
178
+ ): ThemeDefinition["palette"] {
179
+ const color = (values: Readonly<Record<string, string>>, slot: string) => {
180
+ const value = values[slot];
181
+ if (value === undefined) throw new Error(`Theme ${name} has no "${slot}"`);
182
+ const channels = /^(-?[\d.]+) ([\d.]+)% ([\d.]+)%$/.exec(value.trim());
183
+ if (!channels) {
184
+ throw new Error(`Theme ${name}'s "${slot}" is not an H S% L% triplet`);
185
+ }
186
+ const [, hue, saturation, lightness] = channels.map(Number);
187
+ return new Color("hsl", [hue ?? 0, saturation ?? 0, lightness ?? 0])
188
+ .to("srgb")
189
+ .toString({ format: "hex" });
190
+ };
191
+ const input = (values: Readonly<Record<string, string>>): PaletteInput => ({
192
+ brand: color(values, "primary"),
193
+ gray: color(values, "muted-foreground"),
194
+ background: {
195
+ light: color(light, "background"),
196
+ dark: color(dark, "background"),
197
+ },
198
+ status: { danger: color(values, "destructive") },
199
+ });
200
+ return {
201
+ light: createPalette(input(light)).light,
202
+ dark: createPalette(input(dark)).dark,
203
+ };
204
+ }
205
+
206
+ export function shadcnTheme({
207
+ name,
208
+ label,
209
+ isDefault = false,
210
+ values,
211
+ }: {
212
+ name: string;
213
+ label: string;
214
+ isDefault?: boolean;
215
+ values: ThemeValues;
216
+ }): ThemeDefinition {
217
+ const dark = { ...values.base, ...values.dark };
218
+ const light = { ...values.base, ...values.light };
219
+ return {
220
+ name,
221
+ label,
222
+ isDefault,
223
+ base: {
224
+ ...resolve(name, SHADCN_ROLES, values.base),
225
+ ...declarations(name, values.base),
226
+ },
227
+ dark: {
228
+ ...resolve(name, SHADCN_ROLES, dark),
229
+ ...declarations(name, dark),
230
+ },
231
+ light: {
232
+ ...resolve(name, SHADCN_ROLES, light),
233
+ ...declarations(name, light),
234
+ },
235
+ tokens: resolve(name, SHADCN_TOKENS, values.base),
236
+ palette: themePalette(name, light, dark),
237
+ readsScales: false,
238
+ };
239
+ }
@@ -0,0 +1,53 @@
1
+ import type { AppearanceTokens } from "../tokens/palette.js";
2
+ import type { TokenMap } from "../tokens/primitives.js";
3
+
4
+ /**
5
+ * A theme's own values, keyed by custom property name without the leading
6
+ * dashes: the shadcn slots (`primary`, `border`, `radius`, as HSL triplets or
7
+ * lengths) and any other value the theme sets (`font-sans`). `base` applies at
8
+ * the theme root; `dark` and `light` override it under `.dark` and `.light`.
9
+ */
10
+ export interface ThemeValues {
11
+ base: Readonly<Record<string, string>>;
12
+ dark?: Readonly<Record<string, string>>;
13
+ light?: Readonly<Record<string, string>>;
14
+ }
15
+
16
+ /**
17
+ * One theme: everything an app picks with `data-app-theme` (palette, type, shape
18
+ * and part sizes). Each section is written to CSS as is; none of it reads a
19
+ * variable an app defines.
20
+ */
21
+ export interface ThemeDefinition {
22
+ /** The `data-app-theme` value: an app's name, or `agent-native`. */
23
+ name: string;
24
+ label: string;
25
+ /** Applied with no `data-app-theme` attribute. Exactly one theme is the default. */
26
+ isDefault: boolean;
27
+ /** Roles and values at the theme root, in its default appearance. */
28
+ base: TokenMap;
29
+ /** Under `.dark`: a complete set, so a dark subtree of a light page resolves alone. */
30
+ dark: TokenMap;
31
+ /** Under `.light`: a complete set, likewise. */
32
+ light: TokenMap;
33
+ /**
34
+ * The theme's own color scales in each appearance, generated from its
35
+ * colors, so a part's `--accent-*` and `--gray-*` steps are this theme's
36
+ * wherever its attribute applies.
37
+ */
38
+ palette: { light: AppearanceTokens; dark: AppearanceTokens };
39
+ /** Appearance-independent values (sizes, shapes), set once at the theme root. */
40
+ tokens: TokenMap;
41
+ /**
42
+ * The roles read the color scales, so they are re-declared wherever the
43
+ * scales change (`.light`, `.dark`, `[data-palette]`).
44
+ */
45
+ readsScales: boolean;
46
+ /**
47
+ * Values written only inside this theme's own scope. They override toolkit
48
+ * and Tailwind defaults (the sans font, the composer's radius), so they
49
+ * never apply without the attribute and no other theme resets them: a
50
+ * reset to `initial` would erase those defaults, not restore them.
51
+ */
52
+ scopedOnly?: { base: TokenMap; dark: TokenMap };
53
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `values[index]`, or a RangeError. Token tables are fixed-length; a missing
3
+ * step is a bug, and returning undefined would print "undefinedpx" into CSS.
4
+ */
5
+ export function at<T>(values: ArrayLike<T>, index: number): T {
6
+ const value = values[index];
7
+ if (value === undefined) {
8
+ throw new RangeError(
9
+ `Index ${index} is out of range for a table of ${values.length}`,
10
+ );
11
+ }
12
+ return value;
13
+ }