@behavioral-agentic-design-system/core 0.47.0 → 0.49.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 (214) hide show
  1. package/package.json +1 -1
  2. package/scripts/build-tokens.cjs +24 -3
  3. package/scripts/ux-smoke.mjs +5 -1
  4. package/src/api/save-tokens.ts +170 -24
  5. package/src/app/layout.tsx +12 -1
  6. package/src/app/preview/components/page.tsx +114 -18
  7. package/src/app/preview/global-font-client.tsx +2 -0
  8. package/src/app/providers.tsx +2 -0
  9. package/src/app/shell.tsx +50 -156
  10. package/src/components/customize/brand-mark-section.tsx +65 -95
  11. package/src/components/customize/font-pickers.tsx +25 -2
  12. package/src/components/customize/save-bar.tsx +120 -7
  13. package/src/components/customize/theme-io.tsx +62 -21
  14. package/src/components/customize-tab.tsx +3 -1
  15. package/src/components/home-recent.tsx +58 -25
  16. package/src/components/motion/reveal.tsx +168 -12
  17. package/src/components/studio/control-panel.tsx +98 -19
  18. package/src/components/studio/import-theme-dialog.tsx +167 -0
  19. package/src/components/studio/tokens-panel.tsx +215 -0
  20. package/src/components/studio/types.ts +5 -2
  21. package/src/components/studio/use-studio-tweaks.ts +36 -4
  22. package/src/components/studio/use-token-edits.ts +160 -0
  23. package/src/components/ui/number-field.tsx +390 -0
  24. package/src/components/ui/toggle-tip.tsx +38 -29
  25. package/src/data/component-added.json +4 -0
  26. package/src/data/component-stories.json +1214 -0
  27. package/src/data/docs-index.ts +7 -2
  28. package/src/data/hidden-views.ts +22 -0
  29. package/src/data/history.json +51 -51
  30. package/src/data/sticker-sheet.json +1918 -1808
  31. package/src/fonts/Figtree-OFL.txt +93 -0
  32. package/src/fonts/figtree-latin-ext-wght-normal.woff2 +0 -0
  33. package/src/fonts/figtree-latin-wght-italic.woff2 +0 -0
  34. package/src/fonts/figtree-latin-wght-normal.woff2 +0 -0
  35. package/src/fonts-cdn.css +3 -1
  36. package/src/fonts.css +44 -0
  37. package/src/hooks/use-global-heading-font.ts +104 -0
  38. package/src/hooks/use-global-sans-font.ts +8 -3
  39. package/src/hooks/use-global-theme.ts +2 -2
  40. package/src/hooks/use-token-overrides.ts +62 -14
  41. package/src/lib/css-color.ts +42 -0
  42. package/src/lib/storybook-url.ts +28 -0
  43. package/src/lib/theme-editor.ts +7 -1
  44. package/src/lib/theme-import.ts +99 -0
  45. package/src/lib/theme-transition.ts +93 -0
  46. package/src/lib/token-list.ts +133 -0
  47. package/src/lib/token-value.ts +31 -0
  48. package/src/stories/Accordion.stories.tsx +1 -1
  49. package/src/stories/Affix.stories.tsx +1 -1
  50. package/src/stories/AiBadge.stories.tsx +1 -1
  51. package/src/stories/Alert.stories.tsx +1 -1
  52. package/src/stories/AlertDialog.stories.tsx +1 -1
  53. package/src/stories/AngleSlider.stories.tsx +1 -1
  54. package/src/stories/AnnouncementBar.stories.tsx +2 -2
  55. package/src/stories/AspectRatio.stories.tsx +1 -1
  56. package/src/stories/Attachment.stories.tsx +1 -1
  57. package/src/stories/Autocomplete.stories.tsx +1 -1
  58. package/src/stories/Avatar.stories.tsx +1 -1
  59. package/src/stories/Badge.stories.tsx +1 -1
  60. package/src/stories/Blockquote.stories.tsx +1 -1
  61. package/src/stories/Burger.stories.tsx +1 -1
  62. package/src/stories/Button.stories.tsx +1 -1
  63. package/src/stories/ButtonGroup.stories.tsx +1 -1
  64. package/src/stories/Calendar.stories.tsx +1 -1
  65. package/src/stories/Callout.stories.tsx +1 -1
  66. package/src/stories/Canvas.stories.tsx +1 -1
  67. package/src/stories/Card.stories.tsx +1 -1
  68. package/src/stories/Carousel.stories.tsx +1 -1
  69. package/src/stories/Cascader.stories.tsx +1 -1
  70. package/src/stories/Chart.stories.tsx +1 -1
  71. package/src/stories/ChatBubble.stories.tsx +1 -1
  72. package/src/stories/ChatMarker.stories.tsx +1 -1
  73. package/src/stories/Checkbox.stories.tsx +1 -1
  74. package/src/stories/CheckboxCard.stories.tsx +1 -1
  75. package/src/stories/CheckboxGroup.stories.tsx +2 -1
  76. package/src/stories/Chip.stories.tsx +1 -1
  77. package/src/stories/CircularProgress.stories.tsx +1 -1
  78. package/src/stories/Clipboard.stories.tsx +1 -1
  79. package/src/stories/CloseButton.stories.tsx +1 -1
  80. package/src/stories/Code.stories.tsx +1 -1
  81. package/src/stories/Collapsible.stories.tsx +1 -1
  82. package/src/stories/ColorPicker.stories.tsx +1 -1
  83. package/src/stories/ColorSwatch.stories.tsx +1 -1
  84. package/src/stories/Combobox.stories.tsx +1 -1
  85. package/src/stories/Container.stories.tsx +1 -1
  86. package/src/stories/ContextMenu.stories.tsx +1 -1
  87. package/src/stories/CopyButton.stories.tsx +1 -1
  88. package/src/stories/DataList.stories.tsx +1 -1
  89. package/src/stories/DataTable.stories.tsx +1 -1
  90. package/src/stories/DateField.stories.tsx +1 -1
  91. package/src/stories/DatePicker.stories.tsx +1 -1
  92. package/src/stories/DateRangePicker.stories.tsx +1 -1
  93. package/src/stories/Dialog.stories.tsx +1 -1
  94. package/src/stories/Drawer.stories.tsx +1 -1
  95. package/src/stories/DropdownMenu.stories.tsx +1 -1
  96. package/src/stories/Editable.stories.tsx +1 -1
  97. package/src/stories/EmptyState.stories.tsx +1 -1
  98. package/src/stories/FacetedFilter.stories.tsx +1 -1
  99. package/src/stories/Field.stories.tsx +1 -1
  100. package/src/stories/Fieldset.stories.tsx +1 -1
  101. package/src/stories/FileButton.stories.tsx +1 -1
  102. package/src/stories/FileUpload.stories.tsx +1 -1
  103. package/src/stories/FloatLabel.stories.tsx +1 -1
  104. package/src/stories/FloatingActionButton.stories.tsx +1 -1
  105. package/src/stories/FloatingIndicator.stories.tsx +1 -1
  106. package/src/stories/FloatingPanel.stories.tsx +1 -1
  107. package/src/stories/FocusTrap.stories.tsx +1 -1
  108. package/src/stories/FormatByte.stories.tsx +1 -1
  109. package/src/stories/FormatDate.stories.tsx +1 -1
  110. package/src/stories/FormatNumber.stories.tsx +1 -1
  111. package/src/stories/FormatRelativeTime.stories.tsx +1 -1
  112. package/src/stories/GaugeChart.stories.tsx +1 -1
  113. package/src/stories/Grid.stories.tsx +1 -1
  114. package/src/stories/Heatmap.stories.tsx +1 -1
  115. package/src/stories/Highlight.stories.tsx +1 -1
  116. package/src/stories/HoverCard.stories.tsx +1 -1
  117. package/src/stories/Icon.stories.tsx +1 -1
  118. package/src/stories/Image.stories.tsx +1 -1
  119. package/src/stories/Indicator.stories.tsx +1 -1
  120. package/src/stories/InfiniteScroll.stories.tsx +1 -1
  121. package/src/stories/InlineEdit.stories.tsx +1 -1
  122. package/src/stories/Input.stories.tsx +1 -1
  123. package/src/stories/InputClearButton.stories.tsx +1 -1
  124. package/src/stories/InputGroup.stories.tsx +1 -1
  125. package/src/stories/JsonInput.stories.tsx +1 -1
  126. package/src/stories/Kbd.stories.tsx +1 -1
  127. package/src/stories/KeyboardShortcut.stories.tsx +1 -1
  128. package/src/stories/Label.stories.tsx +1 -1
  129. package/src/stories/List.stories.tsx +1 -1
  130. package/src/stories/Listbox.stories.tsx +1 -1
  131. package/src/stories/LoadingDots.stories.tsx +1 -1
  132. package/src/stories/LoadingOverlay.stories.tsx +1 -1
  133. package/src/stories/Mark.stories.tsx +1 -1
  134. package/src/stories/MarkdownPreview.stories.tsx +1 -1
  135. package/src/stories/Marquee.stories.tsx +1 -1
  136. package/src/stories/Masonry.stories.tsx +1 -1
  137. package/src/stories/Meter.stories.tsx +1 -1
  138. package/src/stories/MonthPicker.stories.tsx +1 -1
  139. package/src/stories/MotionToggle.stories.tsx +1 -1
  140. package/src/stories/MultiSelect.stories.tsx +1 -1
  141. package/src/stories/NativeSelect.stories.tsx +1 -1
  142. package/src/stories/NavigationProgress.stories.tsx +1 -1
  143. package/src/stories/Notification.stories.tsx +1 -1
  144. package/src/stories/NumberField.stories.tsx +214 -0
  145. package/src/stories/NumberInput.stories.tsx +1 -1
  146. package/src/stories/OtpInput.stories.tsx +1 -1
  147. package/src/stories/Overlay.stories.tsx +1 -1
  148. package/src/stories/PageHeader.stories.tsx +1 -1
  149. package/src/stories/PasswordInput.stories.tsx +1 -1
  150. package/src/stories/PasswordStrengthInput.stories.tsx +1 -1
  151. package/src/stories/PhoneInput.stories.tsx +1 -1
  152. package/src/stories/Pill.stories.tsx +1 -1
  153. package/src/stories/PinInput.stories.tsx +1 -1
  154. package/src/stories/Popover.stories.tsx +1 -1
  155. package/src/stories/Portal.stories.tsx +1 -1
  156. package/src/stories/Presence.stories.tsx +1 -1
  157. package/src/stories/Progress.stories.tsx +1 -1
  158. package/src/stories/ProgressStack.stories.tsx +1 -1
  159. package/src/stories/Prose.stories.tsx +1 -1
  160. package/src/stories/QrCode.stories.tsx +1 -1
  161. package/src/stories/Questionnaire.stories.tsx +1 -1
  162. package/src/stories/RadioGroup.stories.tsx +1 -1
  163. package/src/stories/RatingGroup.stories.tsx +1 -1
  164. package/src/stories/Resizable.stories.tsx +1 -1
  165. package/src/stories/Result.stories.tsx +1 -1
  166. package/src/stories/Reveal.stories.tsx +1 -1
  167. package/src/stories/RollingNumber.stories.tsx +1 -1
  168. package/src/stories/ScrollArea.stories.tsx +1 -1
  169. package/src/stories/ScrollProgress.stories.tsx +1 -1
  170. package/src/stories/SearchInput.stories.tsx +1 -1
  171. package/src/stories/SegmentedControl.stories.tsx +1 -1
  172. package/src/stories/Select.stories.tsx +1 -1
  173. package/src/stories/Separator.stories.tsx +1 -1
  174. package/src/stories/Sheet.stories.tsx +1 -1
  175. package/src/stories/SignaturePad.stories.tsx +1 -1
  176. package/src/stories/SimpleGrid.stories.tsx +1 -1
  177. package/src/stories/Skeleton.stories.tsx +1 -1
  178. package/src/stories/SkeletonTable.stories.tsx +1 -1
  179. package/src/stories/Slider.stories.tsx +1 -1
  180. package/src/stories/Snackbar.stories.tsx +1 -1
  181. package/src/stories/Sonner.stories.tsx +1 -1
  182. package/src/stories/SortableList.stories.tsx +1 -1
  183. package/src/stories/Sparkline.stories.tsx +1 -1
  184. package/src/stories/Spinner.stories.tsx +1 -1
  185. package/src/stories/Spoiler.stories.tsx +1 -1
  186. package/src/stories/Squircle.stories.tsx +1 -1
  187. package/src/stories/Stack.stories.tsx +1 -1
  188. package/src/stories/StatusBadge.stories.tsx +1 -1
  189. package/src/stories/Switch.stories.tsx +1 -1
  190. package/src/stories/Table.stories.tsx +1 -1
  191. package/src/stories/Tag.stories.tsx +1 -1
  192. package/src/stories/TagsInput.stories.tsx +1 -1
  193. package/src/stories/Text.stories.tsx +1 -1
  194. package/src/stories/Textarea.stories.tsx +1 -1
  195. package/src/stories/ThemeIcon.stories.tsx +1 -1
  196. package/src/stories/TimePicker.stories.tsx +1 -1
  197. package/src/stories/Timeline.stories.tsx +1 -1
  198. package/src/stories/Timer.stories.tsx +1 -1
  199. package/src/stories/Toggle.stories.tsx +1 -1
  200. package/src/stories/ToggleGroup.stories.tsx +1 -1
  201. package/src/stories/ToggleTip.stories.tsx +106 -1
  202. package/src/stories/Tooltip.stories.tsx +56 -1
  203. package/src/stories/TransferList.stories.tsx +1 -1
  204. package/src/stories/TreeSelect.stories.tsx +1 -1
  205. package/src/stories/TypingIndicator.stories.tsx +1 -1
  206. package/src/stories/VisuallyHidden.stories.tsx +1 -1
  207. package/src/stories/Watermark.stories.tsx +1 -1
  208. package/src/stories/WeekPicker.stories.tsx +1 -1
  209. package/src/stories/WordRotate.stories.tsx +1 -1
  210. package/src/stories/YearPicker.stories.tsx +1 -1
  211. package/src/stories/story-groups.json +216 -223
  212. package/src/styles.css +20 -3
  213. package/src/tokens.default.json +6 -1
  214. package/src/tokens.json +7 -2
@@ -0,0 +1,215 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { RotateCcw, Upload } from "lucide-react";
5
+ import { Button } from "@behavioral-agentic-design-system/core/components/ui/button";
6
+ import { Input } from "@behavioral-agentic-design-system/core/components/ui/input";
7
+ import { NativeSelect } from "@behavioral-agentic-design-system/core/components/ui/native-select";
8
+ import { Popover, PopoverContent, PopoverTrigger } from "@behavioral-agentic-design-system/core/components/ui/popover";
9
+ import { ColorPicker } from "@behavioral-agentic-design-system/core/components/ui/color-picker";
10
+ import { Badge } from "@behavioral-agentic-design-system/core/components/ui/badge";
11
+ import { SegmentedControl, SegmentedControlItem } from "@behavioral-agentic-design-system/core/components/ui/segmented-control";
12
+ import type { ValueCheck } from "@behavioral-agentic-design-system/core/lib/token-value";
13
+ import { cssColorToHex } from "@behavioral-agentic-design-system/core/lib/css-color";
14
+ import {
15
+ PRIMITIVE_COLORS, PRIMITIVE_ROWS, SEMANTIC_ROWS, groupRows, tokenCount, type TokenRow, type TokenTier,
16
+ } from "@behavioral-agentic-design-system/core/lib/token-list";
17
+ import type { Mode, TokenEdits } from "./use-token-edits";
18
+ import { ImportThemeDialog } from "./import-theme-dialog";
19
+
20
+ const EASINGS = PRIMITIVE_ROWS.filter((r) => r.kind === "easing");
21
+ const ALIAS_PREFIX = "var(--primitive-";
22
+ const aliasKeyOf = (value: string) => /^var\(--primitive-([a-z0-9-]+)\)$/.exec(value.trim())?.[1] ?? null;
23
+ const PALETTE_HEX = [...new Set(PRIMITIVE_COLORS.map((r) => r.value.toUpperCase()))];
24
+
25
+ /** Commit on blur or Enter, so typing a half-finished value never paints the preview. */
26
+ function ValueInput({ id, label, value, onCommit, mono = true }: { id: string; label: string; value: string; onCommit: (v: string) => void; mono?: boolean }) {
27
+ const [draft, setDraft] = React.useState(value);
28
+ React.useEffect(() => setDraft(value), [value]);
29
+ const commit = () => {
30
+ const v = draft.trim();
31
+ if (v && v !== value) onCommit(v);
32
+ else setDraft(value);
33
+ };
34
+ return (
35
+ <Input
36
+ id={id}
37
+ aria-label={label}
38
+ value={draft}
39
+ size="xl"
40
+ spellCheck={false}
41
+ className={mono ? "min-w-0 font-mono text-xs" : "min-w-0"}
42
+ onChange={(e) => setDraft(e.target.value)}
43
+ onBlur={commit}
44
+ onKeyDown={(e) => {
45
+ if (e.key === "Enter") commit();
46
+ if (e.key === "Escape") setDraft(value);
47
+ }}
48
+ />
49
+ );
50
+ }
51
+
52
+ function Swatch({ value }: { value: string }) {
53
+ return <span aria-hidden="true" className="size-6 shrink-0 rounded-md border border-border" style={{ background: value }} />;
54
+ }
55
+
56
+ /** One value's control, chosen by the token's kind. */
57
+ function ValueControl(props: { row: TokenRow; mode: Mode; edits: TokenEdits; label: string }) {
58
+ const [error, setError] = React.useState<string | null>(null);
59
+ return (
60
+ <div className="flex min-w-0 flex-col gap-1">
61
+ <ValueControlBody {...props} onResult={(r) => setError(r.ok ? null : r.reason)} />
62
+ <p role="alert" className="text-xs text-destructive empty:sr-only">{error}</p>
63
+ </div>
64
+ );
65
+ }
66
+
67
+ function ValueControlBody({ row, mode, edits, label, onResult }: { row: TokenRow; mode: Mode; edits: TokenEdits; label: string; onResult: (r: ValueCheck) => void }) {
68
+ const id = React.useId();
69
+ const value = edits.valueOf(row, mode);
70
+ const { editable, note, options } = edits.editability(row, mode);
71
+ const set = (v: string) => onResult(edits.setValue(row, mode, v));
72
+
73
+ if (!editable) {
74
+ return (
75
+ <div className="flex min-w-0 items-center gap-2">
76
+ {row.kind === "color" && !row.alias && <Swatch value={value} />}
77
+ <code className="min-w-0 break-words text-xs text-foreground">{value}</code>
78
+ {note && <span className="text-xs text-muted-foreground">{note}</span>}
79
+ </div>
80
+ );
81
+ }
82
+ if (options) {
83
+ return (
84
+ <NativeSelect id={id} aria-label={label} size="xl" value={value} onChange={(e) => set(e.target.value)}>
85
+ {options.map((o) => <option key={o.value} value={o.value}>{o.label}</option>)}
86
+ </NativeSelect>
87
+ );
88
+ }
89
+ if (row.kind === "easing") {
90
+ const known = EASINGS.some((e) => e.value === value);
91
+ return (
92
+ <NativeSelect id={id} aria-label={label} size="xl" value={value} onChange={(e) => set(e.target.value)}>
93
+ {!known && <option value={value}>{value}</option>}
94
+ {EASINGS.map((e) => <option key={e.id} value={e.value}>{`${e.name}: ${e.value}`}</option>)}
95
+ </NativeSelect>
96
+ );
97
+ }
98
+ if (row.kind === "color") {
99
+ const alias = aliasKeyOf(value);
100
+ const hex = cssColorToHex(alias ? (PRIMITIVE_COLORS.find((p) => p.cssVar === `--primitive-${alias}`)?.value ?? value) : value) ?? "transparent";
101
+ return (
102
+ <div className="flex min-w-0 flex-col gap-2">
103
+ <div className="flex min-w-0 items-center gap-2">
104
+ <Popover>
105
+ <PopoverTrigger asChild>
106
+ <Button type="button" variant="outline" size="icon-xl" aria-label={`Pick ${label}`} className="shrink-0">
107
+ <Swatch value={value} />
108
+ </Button>
109
+ </PopoverTrigger>
110
+ <PopoverContent className="w-72" align="start">
111
+ <ColorPicker aria-label={label} value={hex} swatches={PALETTE_HEX} allowCustom wheel onValueChange={set} />
112
+ </PopoverContent>
113
+ </Popover>
114
+ <div className="min-w-0 flex-1">
115
+ <ValueInput id={id} label={`${label} value`} value={value} onCommit={set} />
116
+ </div>
117
+ </div>
118
+ {row.tier === "semantic" && (
119
+ <NativeSelect
120
+ aria-label={`${label} alias`}
121
+ size="xl"
122
+ value={alias ?? "custom"}
123
+ onChange={(e) => (e.target.value === "custom" ? set(hex) : set(`${ALIAS_PREFIX}${e.target.value})`))}
124
+ >
125
+ <option value="custom">Custom value</option>
126
+ {PRIMITIVE_COLORS.map((p) => {
127
+ const key = p.cssVar!.replace("--primitive-", "");
128
+ return <option key={p.id} value={key}>{`Alias ${p.name.replace(".", " ")}`}</option>;
129
+ })}
130
+ </NativeSelect>
131
+ )}
132
+ </div>
133
+ );
134
+ }
135
+ return <ValueInput id={id} label={label} value={value} onCommit={set} />;
136
+ }
137
+
138
+ function TokenRowView({ row, edits }: { row: TokenRow; edits: TokenEdits }) {
139
+ const modes: Mode[] = row.dark !== undefined ? ["light", "dark"] : ["light"];
140
+ const edited = modes.some((m) => !edits.isDefault(row, m));
141
+ const alias = row.tier === "semantic" && row.kind !== "color" ? row.alias : undefined;
142
+ return (
143
+ <li data-slot="token-row" data-token={row.id} className="flex min-w-0 flex-col gap-2 border-b border-border py-3 last:border-b-0">
144
+ <div className="flex min-w-0 items-center justify-between gap-2">
145
+ <span className="min-w-0 truncate font-mono text-xs font-medium text-foreground" title={row.path}>{row.name}</span>
146
+ <div className="flex shrink-0 items-center gap-1">
147
+ {row.kind === "color" && row.tier === "primitive" ? null : <Badge variant="outline" size="sm">{row.kind}</Badge>}
148
+ {edited && (
149
+ <Button
150
+ type="button" variant="ghost" size="icon-xl" aria-label={`Reset ${row.name}`} className="-my-3"
151
+ onClick={() => modes.forEach((m) => edits.reset(row, m))}
152
+ >
153
+ <RotateCcw strokeWidth={1.5} aria-hidden="true" />
154
+ </Button>
155
+ )}
156
+ </div>
157
+ </div>
158
+ {alias && <p className="text-xs text-muted-foreground">Aliases <code>{alias}</code></p>}
159
+ {modes.map((m) => (
160
+ <div key={m} className="flex min-w-0 flex-col gap-1">
161
+ {modes.length > 1 && <span className="text-xs text-muted-foreground">{m === "light" ? "Light" : "Dark"}</span>}
162
+ <ValueControl row={row} mode={m} edits={edits} label={`${row.name}${modes.length > 1 ? ` ${m}` : ""}`} />
163
+ </div>
164
+ ))}
165
+ </li>
166
+ );
167
+ }
168
+
169
+ /**
170
+ * The All tokens tab: every token in tokens.json, one row each, switchable between the primitive and semantic
171
+ * layers. Editing goes through useTokenEdits, which shares state with the Tweak tab.
172
+ */
173
+ export function TokensPanel({ edits }: { edits: TokenEdits }) {
174
+ const [tier, setTier] = React.useState<TokenTier>("primitive");
175
+ const [query, setQuery] = React.useState("");
176
+ const rows = tier === "primitive" ? PRIMITIVE_ROWS : SEMANTIC_ROWS;
177
+ const q = query.trim().toLowerCase();
178
+ const shown = q ? rows.filter((r) => `${r.name} ${r.group} ${r.value} ${r.dark ?? ""}`.toLowerCase().includes(q)) : rows;
179
+ const groups = groupRows(shown);
180
+
181
+ return (
182
+ <div data-slot="tokens-panel" className="flex min-w-0 flex-col gap-4">
183
+ <SegmentedControl label="Token layer" value={tier} onValueChange={(v) => setTier(v as TokenTier)}>
184
+ <SegmentedControlItem value="primitive">{`Primitive ${tokenCount(PRIMITIVE_ROWS)}`}</SegmentedControlItem>
185
+ <SegmentedControlItem value="semantic">{`Semantic ${tokenCount(SEMANTIC_ROWS)}`}</SegmentedControlItem>
186
+ </SegmentedControl>
187
+ <div className="flex min-w-0 items-start justify-between gap-2">
188
+ <p className="min-w-0 text-xs text-muted-foreground">
189
+ {tier === "primitive"
190
+ ? "The raw values everything is built from. A semantic color can alias any palette color."
191
+ : "What each value means in the product. Colors have a light and a dark value."}
192
+ </p>
193
+ <ImportThemeDialog edits={edits}>
194
+ <Button type="button" variant="ghost" size="xl" className="-mt-2 shrink-0 gap-1.5">
195
+ <Upload className="size-3.5" strokeWidth={1.5} aria-hidden="true" />
196
+ Import theme
197
+ </Button>
198
+ </ImportThemeDialog>
199
+ </div>
200
+ <Input
201
+ type="search" size="xl" aria-label="Filter tokens" placeholder="Filter by name or value" value={query}
202
+ onChange={(e) => setQuery(e.target.value)}
203
+ />
204
+ {groups.length === 0 && <p className="text-sm text-muted-foreground">No tokens match.</p>}
205
+ {groups.map((g) => (
206
+ <section key={g.title} aria-label={g.title} className="flex min-w-0 flex-col">
207
+ <h3 className="text-sm font-semibold text-foreground">{`${g.title} ${tokenCount(g.rows)}`}</h3>
208
+ <ul className="flex min-w-0 flex-col">
209
+ {g.rows.map((r) => <TokenRowView key={r.id} row={r} edits={edits} />)}
210
+ </ul>
211
+ </section>
212
+ ))}
213
+ </div>
214
+ );
215
+ }
@@ -151,7 +151,10 @@ export function clampTypeScale(scale: TypeScale): TypeScale {
151
151
  /** Every tweakable value Studio exposes, flattened into one typed object. */
152
152
  export interface StudioTweaks {
153
153
  primaryColor: string; // option key from useGlobalPrimaryColor
154
- sansFont: string; // key of SANS_FONT_OPTIONS
154
+ headingFont: string; // key of HEADING_FONT_OPTIONS
155
+ sansFont: string; // key of SANS_FONT_OPTIONS (the body font)
156
+ serifFont: string; // key of SERIF_FONT_OPTIONS
157
+ monoFont: string; // key of MONO_FONT_OPTIONS
155
158
  typeBase: number; // px
156
159
  typeRatio: number;
157
160
  letterSpacing: number; // em
@@ -164,7 +167,7 @@ export type StudioTweakKey = keyof StudioTweaks;
164
167
 
165
168
  /** Numeric tweak metadata. Ranges and defaults are imported, never retyped. */
166
169
  export const NUMERIC_TWEAKS: Record<
167
- Exclude<StudioTweakKey, "primaryColor" | "sansFont">,
170
+ Exclude<StudioTweakKey, "primaryColor" | "sansFont" | "headingFont" | "serifFont" | "monoFont">,
168
171
  {
169
172
  label: string;
170
173
  group: "type" | "shape" | "space";
@@ -11,6 +11,13 @@ import {
11
11
  SANS_FONT_OPTIONS,
12
12
  useGlobalSansFont,
13
13
  } from "@behavioral-agentic-design-system/core/hooks/use-global-sans-font";
14
+ import {
15
+ DEFAULT_HEADING_FONT,
16
+ HEADING_FONT_OPTIONS,
17
+ useGlobalHeadingFont,
18
+ } from "@behavioral-agentic-design-system/core/hooks/use-global-heading-font";
19
+ import { SERIF_FONT_OPTIONS, useGlobalSerifFont } from "@behavioral-agentic-design-system/core/hooks/use-global-serif-font";
20
+ import { MONO_FONT_OPTIONS, useGlobalMonoFont } from "@behavioral-agentic-design-system/core/hooks/use-global-mono-font";
14
21
  import { useGlobalTypeScale } from "@behavioral-agentic-design-system/core/hooks/use-global-type-scale";
15
22
  import { useGlobalDesignControls } from "@behavioral-agentic-design-system/core/hooks/use-global-design-controls";
16
23
  import {
@@ -22,10 +29,16 @@ import {
22
29
 
23
30
  const PRIMARY_DEFAULT = DEFAULT_PRIMARY_COLOR;
24
31
  const SANS_DEFAULT = DEFAULT_SANS_FONT;
32
+ const HEADING_DEFAULT = DEFAULT_HEADING_FONT;
33
+ const SERIF_DEFAULT = "georgia";
34
+ const MONO_DEFAULT = "jetbrains";
25
35
 
26
36
  const DEFAULTS: StudioTweaks = {
27
37
  primaryColor: PRIMARY_DEFAULT,
38
+ headingFont: HEADING_DEFAULT,
28
39
  sansFont: SANS_DEFAULT,
40
+ serifFont: SERIF_DEFAULT,
41
+ monoFont: MONO_DEFAULT,
29
42
  typeBase: NUMERIC_TWEAKS.typeBase.default,
30
43
  typeRatio: NUMERIC_TWEAKS.typeRatio.default,
31
44
  letterSpacing: NUMERIC_TWEAKS.letterSpacing.default,
@@ -43,16 +56,22 @@ export function useStudioTweaks() {
43
56
  // Order matters: useTokenOverrides' mount effect runs applyThemeEditorState,
44
57
  // which clears inline radius/spacing/fonts/colors. It must mount first so
45
58
  // the other hooks' mount effects re-apply their values afterwards.
46
- useTokenOverrides();
59
+ const { clear: clearOverrides } = useTokenOverrides();
47
60
  const { color, setColor, options, addCustomSilent } = useGlobalPrimaryColor();
48
61
  const { font, setFont } = useGlobalSansFont();
62
+ const { font: headingFont, setFont: setHeadingFont } = useGlobalHeadingFont();
63
+ const { font: serifFont, setFont: setSerifFont } = useGlobalSerifFont();
64
+ const { font: monoFont, setFont: setMonoFont } = useGlobalMonoFont();
49
65
  const { scale, setScale, reset: resetScale } = useGlobalTypeScale();
50
66
  const { controls, setControl, reset: resetControls } = useGlobalDesignControls();
51
67
 
52
68
  const tweaks: StudioTweaks = useMemo(
53
69
  () => ({
54
70
  primaryColor: color,
71
+ headingFont,
55
72
  sansFont: font,
73
+ serifFont,
74
+ monoFont,
56
75
  typeBase: scale.base,
57
76
  typeRatio: scale.ratio,
58
77
  letterSpacing: controls.letterSpacing,
@@ -60,7 +79,7 @@ export function useStudioTweaks() {
60
79
  shadowOpacity: controls.shadowOpacity,
61
80
  spacing: controls.spacing,
62
81
  }),
63
- [color, font, scale.base, scale.ratio, controls],
82
+ [color, font, headingFont, serifFont, monoFont, scale.base, scale.ratio, controls],
64
83
  );
65
84
 
66
85
  const set = useCallback(
@@ -69,6 +88,15 @@ export function useStudioTweaks() {
69
88
  case "primaryColor":
70
89
  setColor(value as string);
71
90
  break;
91
+ case "headingFont":
92
+ if ((value as string) in HEADING_FONT_OPTIONS) setHeadingFont(value as string);
93
+ break;
94
+ case "serifFont":
95
+ if ((value as string) in SERIF_FONT_OPTIONS) setSerifFont(value as string);
96
+ break;
97
+ case "monoFont":
98
+ if ((value as string) in MONO_FONT_OPTIONS) setMonoFont(value as string);
99
+ break;
72
100
  case "sansFont":
73
101
  if ((value as string) in SANS_FONT_OPTIONS) setFont(value as string);
74
102
  break;
@@ -86,7 +114,7 @@ export function useStudioTweaks() {
86
114
  setControl(key, value as number);
87
115
  }
88
116
  },
89
- [setColor, setFont, setScale, setControl, scale.base, scale.ratio],
117
+ [setColor, setFont, setHeadingFont, setSerifFont, setMonoFont, setScale, setControl, scale.base, scale.ratio],
90
118
  );
91
119
 
92
120
  const reset = useCallback(
@@ -98,8 +126,12 @@ export function useStudioTweaks() {
98
126
  resetControls();
99
127
  resetScale();
100
128
  setFont(SANS_DEFAULT);
129
+ setHeadingFont(HEADING_DEFAULT);
130
+ setSerifFont(SERIF_DEFAULT);
131
+ setMonoFont(MONO_DEFAULT);
132
+ clearOverrides();
101
133
  setColor(PRIMARY_DEFAULT);
102
- }, [resetControls, resetScale, setFont, setColor]);
134
+ }, [resetControls, resetScale, setFont, setHeadingFont, setSerifFont, setMonoFont, clearOverrides, setColor]);
103
135
 
104
136
  const isDefault = useCallback(
105
137
  (key: StudioTweakKey) => tweaks[key] === DEFAULTS[key],
@@ -0,0 +1,160 @@
1
+ "use client";
2
+
3
+ import { useMemo } from "react";
4
+ import { DARK_PREFIX, useTokenOverrides } from "@behavioral-agentic-design-system/core/hooks/use-token-overrides";
5
+ import { SANS_FONT_OPTIONS } from "@behavioral-agentic-design-system/core/hooks/use-global-sans-font";
6
+ import { HEADING_FONT_OPTIONS } from "@behavioral-agentic-design-system/core/hooks/use-global-heading-font";
7
+ import { SERIF_FONT_OPTIONS } from "@behavioral-agentic-design-system/core/hooks/use-global-serif-font";
8
+ import { MONO_FONT_OPTIONS } from "@behavioral-agentic-design-system/core/hooks/use-global-mono-font";
9
+ import type { useStudioTweaks } from "./use-studio-tweaks";
10
+ import { cssColorToHex } from "@behavioral-agentic-design-system/core/lib/css-color";
11
+ import { checkTokenValue, type ValueCheck } from "@behavioral-agentic-design-system/core/lib/token-value";
12
+ import type { TokenRow } from "@behavioral-agentic-design-system/core/lib/token-list";
13
+
14
+ export type StudioTweaksApi = ReturnType<typeof useStudioTweaks>;
15
+
16
+ export type Mode = "light" | "dark";
17
+
18
+ export interface Editability {
19
+ editable: boolean;
20
+ /** Why a row is read-only, or where its control lives. */
21
+ note?: string;
22
+ /** For font rows: the choices. */
23
+ options?: { value: string; label: string }[];
24
+ }
25
+
26
+ const READ_ONLY_PRIMITIVE_SECTIONS = new Set([
27
+ "fontSize", "fontWeight", "lineHeight", "spacing", "breakpoint", "chart", "fontVariationSettings", "cornerSmoothing",
28
+ ]);
29
+
30
+ /**
31
+ * One place that reads and writes a token's value for the Studio's list.
32
+ *
33
+ * Tokens that already have a Tweak control (brand color, radius, shadow strength, the four fonts) read and write
34
+ * through the SAME hooks the Tweak tab uses, so the two never disagree. Every other editable token is written to
35
+ * the shared override sheet (use-token-overrides): `--x` for light or the single value, `dark:--x` for dark.
36
+ */
37
+ export function useTokenEdits(studio: StudioTweaksApi) {
38
+ const { overrides, updateOverride, remove, clear } = useTokenOverrides();
39
+ const { tweaks, set: setTweak, reset: resetTweak, isDefault: isTweakDefault, primaryOptions, addCustomColor } = studio;
40
+
41
+ const FONT_SLOTS = {
42
+ sans: { key: "sansFont", opts: SANS_FONT_OPTIONS },
43
+ heading: { key: "headingFont", opts: HEADING_FONT_OPTIONS },
44
+ serif: { key: "serifFont", opts: SERIF_FONT_OPTIONS },
45
+ mono: { key: "monoFont", opts: MONO_FONT_OPTIONS },
46
+ } as const;
47
+ const fontHooks = useMemo(() => FONT_SLOTS, []); // eslint-disable-line react-hooks/exhaustive-deps
48
+
49
+ const keyOf = (row: TokenRow, mode: Mode) => (row.cssVar ? (mode === "dark" ? `${DARK_PREFIX}${row.cssVar}` : row.cssVar) : null);
50
+ const fontSlot = (row: TokenRow) => /^fontFamily\.(sans|heading|serif|mono)$/.exec(row.path)?.[1] as keyof typeof FONT_SLOTS | undefined;
51
+ const isTheme = (row: TokenRow) => row.tier === "semantic" && row.path.startsWith("theme.");
52
+ const isPrimary = (row: TokenRow, mode: Mode) => isTheme(row) && row.name === "primary" && mode === "light";
53
+
54
+ const editability = (row: TokenRow, mode: Mode): Editability => {
55
+ const slot = fontSlot(row);
56
+ if (slot) {
57
+ return { editable: true, options: Object.entries(fontHooks[slot].opts).map(([value, o]) => ({ value, label: o.label })) };
58
+ }
59
+ if (isTheme(row)) {
60
+ if (row.name === "primary") {
61
+ return mode === "light"
62
+ ? { editable: true, note: "Same as Brand color in Tweak." }
63
+ : { editable: false, note: "Follows Brand color in both modes." };
64
+ }
65
+ if (row.name === "primary-foreground") return { editable: false, note: "Derived from Brand color." };
66
+ return { editable: true };
67
+ }
68
+ if (row.path === "borderRadius.lg" || row.path === "shadow.opacity") return { editable: true, note: "Same as the control in Tweak." };
69
+ if (row.tier === "semantic") return { editable: false, note: row.alias ? undefined : "Defined in tokens.json." };
70
+ const section = row.path.split(".")[0];
71
+ if (READ_ONLY_PRIMITIVE_SECTIONS.has(section)) {
72
+ return { editable: false, note: section === "fontSize" ? "Set with Base size and Scale ratio in Tweak." : "Defined in tokens.json." };
73
+ }
74
+ return row.cssVar ? { editable: true } : { editable: false, note: "No CSS variable." };
75
+ };
76
+
77
+ const valueOf = (row: TokenRow, mode: Mode): string => {
78
+ const slot = fontSlot(row);
79
+ if (slot) return tweaks[FONT_SLOTS[slot].key];
80
+ if (isTheme(row) && row.name === "primary" && mode === "light") return primaryOptions[tweaks.primaryColor]?.primary ?? row.value;
81
+ if (isTheme(row) && row.name === "primary-foreground") return primaryOptions[tweaks.primaryColor]?.primaryForeground ?? row.value;
82
+ if (row.path === "borderRadius.lg") return `${tweaks.radius}rem`;
83
+ if (row.path === "shadow.opacity") return String(tweaks.shadowOpacity);
84
+ const key = keyOf(row, mode);
85
+ const base = mode === "dark" && row.dark !== undefined ? row.dark : row.value;
86
+ return (key && overrides[key]) || base;
87
+ };
88
+
89
+ const isDefault = (row: TokenRow, mode: Mode): boolean => {
90
+ const slot = fontSlot(row);
91
+ if (slot) return isTweakDefault(FONT_SLOTS[slot].key);
92
+ if (isPrimary(row, mode)) return isTweakDefault("primaryColor");
93
+ if (row.path === "borderRadius.lg") return isTweakDefault("radius");
94
+ if (row.path === "shadow.opacity") return isTweakDefault("shadowOpacity");
95
+ const key = keyOf(row, mode);
96
+ return !key || !(key in overrides);
97
+ };
98
+
99
+ /** Writes a value, or says why it was refused. Nothing unchecked reaches the style sheet or tokens.json. */
100
+ const setValue = (row: TokenRow, mode: Mode, raw: string): ValueCheck => {
101
+ const slot = fontSlot(row);
102
+ if (slot) {
103
+ // A font row takes an option key, never free text.
104
+ if (!(raw in FONT_SLOTS[slot].opts)) return { ok: false, reason: "Not one of the listed fonts" };
105
+ setTweak(FONT_SLOTS[slot].key, raw);
106
+ return { ok: true, value: raw };
107
+ }
108
+ const checked = checkTokenValue(raw, row.kind);
109
+ if (!checked.ok) return checked;
110
+ const value = checked.value;
111
+ // A row that aliases its own variable would loop forever once saved (build:tokens stops on the cycle).
112
+ const target = /^var\(\s*(--[A-Za-z0-9_-]+)/.exec(value)?.[1];
113
+ if (target && row.cssVar && target === row.cssVar) return { ok: false, reason: "A token cannot point at itself" };
114
+ if (isPrimary(row, mode)) {
115
+ const hex = cssColorToHex(value);
116
+ if (!hex) return { ok: false, reason: "Brand color needs a plain color value" };
117
+ addCustomColor(hex);
118
+ return checked;
119
+ }
120
+ if (row.path === "borderRadius.lg") {
121
+ const n = parseFloat(value);
122
+ if (!Number.isFinite(n)) return { ok: false, reason: "Not a number" };
123
+ setTweak("radius", /px\s*$/.test(value) ? n / 16 : n);
124
+ return checked;
125
+ }
126
+ if (row.path === "shadow.opacity") {
127
+ const n = parseFloat(value);
128
+ if (!Number.isFinite(n)) return { ok: false, reason: "Not a number" };
129
+ setTweak("shadowOpacity", Math.min(0.5, Math.max(0, n)));
130
+ return checked;
131
+ }
132
+ const key = keyOf(row, mode);
133
+ if (!key) return { ok: false, reason: "No CSS variable" };
134
+ updateOverride(key, value);
135
+ return checked;
136
+ };
137
+
138
+ const reset = (row: TokenRow, mode: Mode) => {
139
+ const slot = fontSlot(row);
140
+ if (slot) return resetTweak(FONT_SLOTS[slot].key);
141
+ if (isPrimary(row, mode)) return resetTweak("primaryColor");
142
+ if (row.path === "borderRadius.lg") return resetTweak("radius");
143
+ if (row.path === "shadow.opacity") return resetTweak("shadowOpacity");
144
+ const key = keyOf(row, mode);
145
+ if (key) remove(key);
146
+ };
147
+
148
+ return {
149
+ overrides,
150
+ editedCount: Object.keys(overrides).length,
151
+ editability,
152
+ valueOf,
153
+ isDefault,
154
+ setValue,
155
+ reset,
156
+ clearOverrides: clear,
157
+ };
158
+ }
159
+
160
+ export type TokenEdits = ReturnType<typeof useTokenEdits>;