@behavioral-agentic-design-system/core 0.48.0 → 0.49.1-beta-20261119021055

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 (229) hide show
  1. package/package.json +2 -1
  2. package/scripts/bads.mjs +247 -0
  3. package/scripts/build-tokens.cjs +24 -3
  4. package/scripts/lib/connect/check.mjs +102 -0
  5. package/scripts/lib/connect/connect.mjs +411 -0
  6. package/scripts/lib/connect/edits.mjs +361 -0
  7. package/scripts/lib/connect/tools.mjs +170 -0
  8. package/scripts/lib/connect/update-check.mjs +29 -0
  9. package/scripts/lint-ethics-contract.mjs +19 -1
  10. package/scripts/ux-smoke.mjs +5 -1
  11. package/src/api/save-tokens.ts +170 -24
  12. package/src/app/layout.tsx +12 -1
  13. package/src/app/preview/components/page.tsx +25 -18
  14. package/src/app/preview/global-font-client.tsx +2 -0
  15. package/src/app/providers.tsx +2 -0
  16. package/src/app/shell.tsx +50 -156
  17. package/src/components/customize/brand-mark-section.tsx +65 -95
  18. package/src/components/customize/font-pickers.tsx +25 -2
  19. package/src/components/customize/save-bar.tsx +120 -7
  20. package/src/components/customize/theme-io.tsx +62 -21
  21. package/src/components/customize-tab.tsx +3 -5
  22. package/src/components/home-recent.tsx +58 -25
  23. package/src/components/motion/reveal.tsx +168 -12
  24. package/src/components/studio/control-panel.tsx +98 -19
  25. package/src/components/studio/import-theme-dialog.tsx +167 -0
  26. package/src/components/studio/tokens-panel.tsx +215 -0
  27. package/src/components/studio/types.ts +5 -2
  28. package/src/components/studio/use-studio-tweaks.ts +36 -4
  29. package/src/components/studio/use-token-edits.ts +160 -0
  30. package/src/components/ui/date-picker.tsx +1 -8
  31. package/src/components/ui/date-range-picker.tsx +1 -8
  32. package/src/components/ui/json-input.tsx +0 -1
  33. package/src/components/ui/navigation-progress.tsx +5 -8
  34. package/src/components/ui/segmented-control.tsx +1 -5
  35. package/src/components/ui/sortable-list.tsx +1 -1
  36. package/src/components/ui/toggle-tip.tsx +38 -29
  37. package/src/components/ui/tree-view.tsx +0 -2
  38. package/src/data/component-stories.json +1214 -0
  39. package/src/data/docs-index.ts +10 -2
  40. package/src/data/hidden-views.ts +22 -0
  41. package/src/data/history.json +38 -38
  42. package/src/data/sticker-sheet.json +1878 -1821
  43. package/src/fonts/Figtree-OFL.txt +93 -0
  44. package/src/fonts/figtree-latin-ext-wght-normal.woff2 +0 -0
  45. package/src/fonts/figtree-latin-wght-italic.woff2 +0 -0
  46. package/src/fonts/figtree-latin-wght-normal.woff2 +0 -0
  47. package/src/fonts-cdn.css +3 -1
  48. package/src/fonts.css +44 -0
  49. package/src/hooks/use-global-heading-font.ts +104 -0
  50. package/src/hooks/use-global-sans-font.ts +8 -3
  51. package/src/hooks/use-global-theme.ts +2 -2
  52. package/src/hooks/use-token-overrides.ts +62 -14
  53. package/src/lib/component-contract.ts +148 -0
  54. package/src/lib/css-color.ts +42 -0
  55. package/src/lib/format-date.ts +7 -0
  56. package/src/lib/storybook-url.ts +28 -0
  57. package/src/lib/theme-editor.ts +7 -1
  58. package/src/lib/theme-import.ts +99 -0
  59. package/src/lib/theme-transition.ts +93 -0
  60. package/src/lib/token-list.ts +133 -0
  61. package/src/lib/token-value.ts +31 -0
  62. package/src/stories/Accordion.stories.tsx +1 -1
  63. package/src/stories/Affix.stories.tsx +1 -1
  64. package/src/stories/AiBadge.stories.tsx +1 -1
  65. package/src/stories/Alert.stories.tsx +1 -1
  66. package/src/stories/AlertDialog.stories.tsx +1 -1
  67. package/src/stories/AngleSlider.stories.tsx +1 -1
  68. package/src/stories/AnnouncementBar.stories.tsx +2 -2
  69. package/src/stories/AspectRatio.stories.tsx +1 -1
  70. package/src/stories/Attachment.stories.tsx +1 -1
  71. package/src/stories/Autocomplete.stories.tsx +1 -1
  72. package/src/stories/Avatar.stories.tsx +1 -1
  73. package/src/stories/Badge.stories.tsx +1 -1
  74. package/src/stories/Blockquote.stories.tsx +1 -1
  75. package/src/stories/Burger.stories.tsx +1 -1
  76. package/src/stories/Button.stories.tsx +1 -1
  77. package/src/stories/ButtonGroup.stories.tsx +1 -1
  78. package/src/stories/Calendar.stories.tsx +1 -1
  79. package/src/stories/Callout.stories.tsx +1 -1
  80. package/src/stories/Canvas.stories.tsx +1 -1
  81. package/src/stories/Card.stories.tsx +1 -1
  82. package/src/stories/Carousel.stories.tsx +1 -1
  83. package/src/stories/Cascader.stories.tsx +1 -1
  84. package/src/stories/Chart.stories.tsx +1 -1
  85. package/src/stories/ChatBubble.stories.tsx +1 -1
  86. package/src/stories/ChatMarker.stories.tsx +1 -1
  87. package/src/stories/Checkbox.stories.tsx +1 -1
  88. package/src/stories/CheckboxCard.stories.tsx +1 -1
  89. package/src/stories/CheckboxGroup.stories.tsx +1 -1
  90. package/src/stories/Chip.stories.tsx +1 -1
  91. package/src/stories/CircularProgress.stories.tsx +1 -1
  92. package/src/stories/Clipboard.stories.tsx +1 -1
  93. package/src/stories/CloseButton.stories.tsx +1 -1
  94. package/src/stories/Code.stories.tsx +1 -1
  95. package/src/stories/Collapsible.stories.tsx +1 -1
  96. package/src/stories/ColorPicker.stories.tsx +1 -1
  97. package/src/stories/ColorSwatch.stories.tsx +1 -1
  98. package/src/stories/Combobox.stories.tsx +1 -1
  99. package/src/stories/Container.stories.tsx +1 -1
  100. package/src/stories/ContextMenu.stories.tsx +1 -1
  101. package/src/stories/CopyButton.stories.tsx +1 -1
  102. package/src/stories/DataList.stories.tsx +1 -1
  103. package/src/stories/DataTable.stories.tsx +1 -1
  104. package/src/stories/DateField.stories.tsx +1 -1
  105. package/src/stories/DatePicker.stories.tsx +1 -1
  106. package/src/stories/DateRangePicker.stories.tsx +1 -1
  107. package/src/stories/Dialog.stories.tsx +1 -1
  108. package/src/stories/Drawer.stories.tsx +1 -1
  109. package/src/stories/DropdownMenu.stories.tsx +1 -1
  110. package/src/stories/Editable.stories.tsx +1 -1
  111. package/src/stories/EmptyState.stories.tsx +1 -1
  112. package/src/stories/FacetedFilter.stories.tsx +1 -1
  113. package/src/stories/Field.stories.tsx +1 -1
  114. package/src/stories/Fieldset.stories.tsx +1 -1
  115. package/src/stories/FileButton.stories.tsx +1 -1
  116. package/src/stories/FileUpload.stories.tsx +1 -1
  117. package/src/stories/FloatLabel.stories.tsx +1 -1
  118. package/src/stories/FloatingActionButton.stories.tsx +1 -1
  119. package/src/stories/FloatingIndicator.stories.tsx +1 -1
  120. package/src/stories/FloatingPanel.stories.tsx +1 -1
  121. package/src/stories/FocusTrap.stories.tsx +1 -1
  122. package/src/stories/FormatByte.stories.tsx +1 -1
  123. package/src/stories/FormatDate.stories.tsx +1 -1
  124. package/src/stories/FormatNumber.stories.tsx +1 -1
  125. package/src/stories/FormatRelativeTime.stories.tsx +1 -1
  126. package/src/stories/GaugeChart.stories.tsx +1 -1
  127. package/src/stories/Grid.stories.tsx +1 -1
  128. package/src/stories/Heatmap.stories.tsx +1 -1
  129. package/src/stories/Highlight.stories.tsx +1 -1
  130. package/src/stories/HoverCard.stories.tsx +1 -1
  131. package/src/stories/Icon.stories.tsx +1 -1
  132. package/src/stories/Image.stories.tsx +1 -1
  133. package/src/stories/Indicator.stories.tsx +1 -1
  134. package/src/stories/InfiniteScroll.stories.tsx +1 -1
  135. package/src/stories/InlineEdit.stories.tsx +1 -1
  136. package/src/stories/Input.stories.tsx +1 -1
  137. package/src/stories/InputClearButton.stories.tsx +1 -1
  138. package/src/stories/InputGroup.stories.tsx +1 -1
  139. package/src/stories/JsonInput.stories.tsx +2 -2
  140. package/src/stories/Kbd.stories.tsx +1 -1
  141. package/src/stories/KeyboardShortcut.stories.tsx +1 -1
  142. package/src/stories/Label.stories.tsx +1 -1
  143. package/src/stories/List.stories.tsx +1 -1
  144. package/src/stories/Listbox.stories.tsx +1 -1
  145. package/src/stories/LoadingDots.stories.tsx +1 -1
  146. package/src/stories/LoadingOverlay.stories.tsx +1 -1
  147. package/src/stories/Mark.stories.tsx +1 -1
  148. package/src/stories/MarkdownPreview.stories.tsx +1 -1
  149. package/src/stories/Marquee.stories.tsx +1 -1
  150. package/src/stories/Masonry.stories.tsx +1 -1
  151. package/src/stories/Meter.stories.tsx +1 -1
  152. package/src/stories/MonthPicker.stories.tsx +1 -1
  153. package/src/stories/MotionToggle.stories.tsx +1 -1
  154. package/src/stories/MultiSelect.stories.tsx +1 -1
  155. package/src/stories/NativeSelect.stories.tsx +1 -1
  156. package/src/stories/NavigationProgress.stories.tsx +1 -1
  157. package/src/stories/Notification.stories.tsx +1 -1
  158. package/src/stories/NumberField.stories.tsx +1 -1
  159. package/src/stories/NumberInput.stories.tsx +1 -1
  160. package/src/stories/OtpInput.stories.tsx +1 -1
  161. package/src/stories/Overlay.stories.tsx +1 -1
  162. package/src/stories/PageHeader.stories.tsx +1 -1
  163. package/src/stories/PasswordInput.stories.tsx +1 -1
  164. package/src/stories/PasswordStrengthInput.stories.tsx +1 -1
  165. package/src/stories/PhoneInput.stories.tsx +1 -1
  166. package/src/stories/Pill.stories.tsx +1 -1
  167. package/src/stories/PinInput.stories.tsx +1 -1
  168. package/src/stories/Popover.stories.tsx +1 -1
  169. package/src/stories/Portal.stories.tsx +1 -1
  170. package/src/stories/Presence.stories.tsx +1 -1
  171. package/src/stories/Progress.stories.tsx +1 -1
  172. package/src/stories/ProgressStack.stories.tsx +1 -1
  173. package/src/stories/Prose.stories.tsx +1 -1
  174. package/src/stories/QrCode.stories.tsx +1 -1
  175. package/src/stories/Questionnaire.stories.tsx +1 -1
  176. package/src/stories/RadioGroup.stories.tsx +1 -1
  177. package/src/stories/RatingGroup.stories.tsx +1 -1
  178. package/src/stories/Resizable.stories.tsx +1 -1
  179. package/src/stories/Result.stories.tsx +1 -1
  180. package/src/stories/Reveal.stories.tsx +1 -1
  181. package/src/stories/RollingNumber.stories.tsx +1 -1
  182. package/src/stories/ScrollArea.stories.tsx +1 -1
  183. package/src/stories/ScrollProgress.stories.tsx +1 -1
  184. package/src/stories/SearchInput.stories.tsx +1 -1
  185. package/src/stories/SegmentedControl.stories.tsx +2 -2
  186. package/src/stories/Select.stories.tsx +1 -1
  187. package/src/stories/Separator.stories.tsx +1 -1
  188. package/src/stories/Sheet.stories.tsx +1 -1
  189. package/src/stories/SignaturePad.stories.tsx +1 -1
  190. package/src/stories/SimpleGrid.stories.tsx +1 -1
  191. package/src/stories/Skeleton.stories.tsx +1 -1
  192. package/src/stories/SkeletonTable.stories.tsx +1 -1
  193. package/src/stories/Slider.stories.tsx +1 -1
  194. package/src/stories/Snackbar.stories.tsx +1 -1
  195. package/src/stories/Sonner.stories.tsx +1 -1
  196. package/src/stories/SortableList.stories.tsx +2 -1
  197. package/src/stories/Sparkline.stories.tsx +1 -1
  198. package/src/stories/Spinner.stories.tsx +1 -1
  199. package/src/stories/Spoiler.stories.tsx +1 -1
  200. package/src/stories/Squircle.stories.tsx +1 -1
  201. package/src/stories/Stack.stories.tsx +1 -1
  202. package/src/stories/StatusBadge.stories.tsx +1 -1
  203. package/src/stories/Switch.stories.tsx +1 -1
  204. package/src/stories/Table.stories.tsx +1 -1
  205. package/src/stories/Tag.stories.tsx +1 -1
  206. package/src/stories/TagsInput.stories.tsx +1 -1
  207. package/src/stories/Text.stories.tsx +1 -1
  208. package/src/stories/Textarea.stories.tsx +1 -1
  209. package/src/stories/ThemeIcon.stories.tsx +1 -1
  210. package/src/stories/TimePicker.stories.tsx +1 -1
  211. package/src/stories/Timeline.stories.tsx +1 -1
  212. package/src/stories/Timer.stories.tsx +1 -1
  213. package/src/stories/Toggle.stories.tsx +1 -1
  214. package/src/stories/ToggleGroup.stories.tsx +1 -1
  215. package/src/stories/ToggleTip.stories.tsx +106 -1
  216. package/src/stories/Tooltip.stories.tsx +56 -1
  217. package/src/stories/TransferList.stories.tsx +1 -1
  218. package/src/stories/TreeSelect.stories.tsx +1 -1
  219. package/src/stories/TreeView.stories.tsx +1 -0
  220. package/src/stories/TypingIndicator.stories.tsx +1 -1
  221. package/src/stories/VisuallyHidden.stories.tsx +1 -1
  222. package/src/stories/Watermark.stories.tsx +1 -1
  223. package/src/stories/WeekPicker.stories.tsx +1 -1
  224. package/src/stories/WordRotate.stories.tsx +1 -1
  225. package/src/stories/YearPicker.stories.tsx +1 -1
  226. package/src/stories/story-groups.json +216 -224
  227. package/src/styles.css +20 -3
  228. package/src/tokens.default.json +6 -1
  229. package/src/tokens.json +7 -2
@@ -33,10 +33,13 @@ type SavePayload = {
33
33
  } | null;
34
34
  fonts?: {
35
35
  sans?: string;
36
+ heading?: string;
36
37
  serif?: string;
37
38
  mono?: string;
38
39
  } | null;
39
40
  fontSizes?: Record<string, number> | null;
41
+ /** Token-list edits keyed by tokens.json path, e.g. "theme.dark.background" or "color.primitive.blue.600". */
42
+ tokenValues?: Record<string, string> | null;
40
43
  radius?: number | null;
41
44
  reset?: boolean;
42
45
  };
@@ -62,25 +65,121 @@ function isValidHex(hex: string) {
62
65
  return /^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(hex.trim());
63
66
  }
64
67
 
68
+ const UNSAFE_SEGMENTS = new Set(["__proto__", "constructor", "prototype"]);
69
+
65
70
  function setLeaf(
66
71
  node: Record<string, unknown>,
67
72
  dotPath: string,
68
73
  mutator: (leaf: Record<string, unknown>) => void,
69
- ) {
74
+ ): boolean {
70
75
  const parts = dotPath.split(".");
76
+ // A path segment that names an Object.prototype slot would reach the shared prototype, not a token.
77
+ if (parts.some((p) => UNSAFE_SEGMENTS.has(p))) return false;
71
78
  let current: Record<string, unknown> = node;
72
79
  for (let i = 0; i < parts.length; i++) {
73
80
  const key = parts[i];
81
+ if (!Object.prototype.hasOwnProperty.call(current, key)) return false;
74
82
  const next = current[key];
75
83
  if (i === parts.length - 1) {
76
- if (next && typeof next === "object") {
84
+ // Only a token leaf (an object that already has its own $value) is written. A group such as color.primitive.blue
85
+ // is not: giving it a $value would make the whole scale read as one token.
86
+ if (next && typeof next === "object" && Object.prototype.hasOwnProperty.call(next, "$value")) {
77
87
  mutator(next as Record<string, unknown>);
88
+ return true;
78
89
  }
79
- return;
90
+ return false;
80
91
  }
81
- if (!next || typeof next !== "object") return;
92
+ if (!next || typeof next !== "object") return false;
82
93
  current = next as Record<string, unknown>;
83
94
  }
95
+ return false;
96
+ }
97
+
98
+ /**
99
+ * A token value ends up in tokens.json and then in the published styles.css, so one that could close a declaration
100
+ * or a rule is refused. Same text rules as lib/token-value.ts on the client (this copy is inlined because the
101
+ * route cannot import it, and the three regexes below are held identical to the client's by
102
+ * scripts/token-value-safety.test.mjs): a {color.primitive.<family>.<step>} alias, or plain text with none of
103
+ * ; { } < > @ \ or a control, format or line separator character, no url( / image-set( / src( / element( /
104
+ * cross-fade( / expression( / @import / comment markers / !important, at most 200 characters. A raw
105
+ * var(--primitive-x) is not accepted: styles.css does not declare those variables, so the alias has to be the
106
+ * {color.primitive.x.y} form that build-tokens resolves.
107
+ */
108
+ const SAFE_TEXT = /^[^;{}<>@\\\p{Cc}\p{Cf}\u2028\u2029]+$/u;
109
+ const BANNED = /(url|expression)\s*\(|\b(image-set|src|element|cross-fade)\s*\(|var\(\s*--primitive-|@import|\/\*|\*\/|!\s*important/i;
110
+ const ALIAS_FORM = /^\{color\.primitive\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\}$/;
111
+
112
+ function isSafeTokenValue(value: unknown): value is string {
113
+ if (typeof value !== "string") return false;
114
+ const v = value.trim();
115
+ if (!v || v.length > 200) return false;
116
+ if (ALIAS_FORM.test(v)) return true;
117
+ return SAFE_TEXT.test(v) && !BANNED.test(v);
118
+ }
119
+
120
+ /** A {color.primitive.x.y} alias has to point at a color leaf that exists in the parsed tokens tree (own keys only). */
121
+ function aliasResolves(tokens: Record<string, unknown>, alias: string): boolean {
122
+ if (!ALIAS_FORM.test(alias)) return false;
123
+ const parts = alias.slice(1, -1).split(".");
124
+ if (parts.some((p) => UNSAFE_SEGMENTS.has(p))) return false;
125
+ let current: unknown = tokens;
126
+ for (const part of parts) {
127
+ if (!current || typeof current !== "object" || !Object.prototype.hasOwnProperty.call(current, part)) return false;
128
+ current = (current as Record<string, unknown>)[part];
129
+ }
130
+ const leaf = current as Record<string, unknown> | null;
131
+ return !!leaf && typeof leaf === "object" && Object.prototype.hasOwnProperty.call(leaf, "$value") && leaf.$type === "color";
132
+ }
133
+
134
+ /** Safe text, and if it is an alias, an alias that resolves. */
135
+ function acceptValue(tokens: Record<string, unknown>, value: unknown): value is string {
136
+ if (!isSafeTokenValue(value)) return false;
137
+ const v = value.trim();
138
+ return !ALIAS_FORM.test(v) || aliasResolves(tokens, v);
139
+ }
140
+
141
+ /** Plain text only (font stacks): safe, and not an alias. */
142
+ function acceptText(value: unknown): value is string {
143
+ return isSafeTokenValue(value) && !ALIAS_FORM.test(value.trim());
144
+ }
145
+
146
+ /**
147
+ * Follows every {alias} in the tree the way build-tokens.cjs does (same depth cap of 8) and reports the ones that do
148
+ * not end at a value: a cycle, a self reference, a chain that is too deep, or a target that is missing. Keys are
149
+ * "<path>: <reason>". The route compares the tree before and after an edit, so aliases that were already broken
150
+ * (component tokens that point at color.semantic.*) do not block a save, but a new one does.
151
+ */
152
+ function aliasFailures(tokens: Record<string, unknown>): Set<string> {
153
+ const out = new Set<string>();
154
+ const chase = (start: string): string | null => {
155
+ let current: unknown = start;
156
+ const seen = new Set<string>();
157
+ for (let depth = 0; depth <= 8; depth++) {
158
+ const m = typeof current === "string" ? current.match(/^\{(.+)\}$/) : null;
159
+ if (!m) return null;
160
+ if (seen.has(current as string)) return "alias cycle";
161
+ seen.add(current as string);
162
+ let node: unknown = tokens;
163
+ for (const key of m[1].split(".")) {
164
+ if (!node || typeof node !== "object" || !Object.prototype.hasOwnProperty.call(node, key)) return "alias target missing";
165
+ node = (node as Record<string, unknown>)[key];
166
+ }
167
+ if (!node || typeof node !== "object" || !("$value" in node)) return "alias target missing";
168
+ current = (node as Record<string, unknown>).$value;
169
+ }
170
+ return "alias chain too deep";
171
+ };
172
+ const walk = (node: unknown, trail: string) => {
173
+ if (!node || typeof node !== "object") return;
174
+ const value = (node as Record<string, unknown>).$value;
175
+ if (typeof value === "string" && /^\{(.+)\}$/.test(value)) {
176
+ const reason = chase(value);
177
+ if (reason) out.add(`${trail}: ${reason}`);
178
+ }
179
+ for (const [key, child] of Object.entries(node)) if (key !== "$value") walk(child, trail ? `${trail}.${key}` : key);
180
+ };
181
+ walk(tokens, "");
182
+ return out;
84
183
  }
85
184
 
86
185
  export async function POST(request: Request) {
@@ -136,6 +235,10 @@ export async function POST(request: Request) {
136
235
  }
137
236
 
138
237
  const updates: string[] = [];
238
+ // Paths the request named that were not written: an unsafe value, an alias that does not resolve, or not a token leaf.
239
+ const rejected: { path: string; reason: string }[] = [];
240
+ const reject = (path: string, reason: string) => { rejected.push({ path, reason }); };
241
+ const aliasFailuresBefore = aliasFailures(tokens);
139
242
 
140
243
  if (payload.brandColor) {
141
244
  // Only write the primary to the LIGHT theme. Writing both to the same hex
@@ -144,22 +247,19 @@ export async function POST(request: Request) {
144
247
  // inverted primary (near-white surface, near-black text). If a designer
145
248
  // wants to override dark too, they can edit tokens.json directly or send
146
249
  // a separate payload (future: { brandColorDark: { ... } }).
250
+ // The client only ever sends a palette hex, so that is all that is accepted here.
147
251
  const { primary, primaryForeground } = payload.brandColor;
148
- setLeaf(tokens, "theme.light.primary", (leaf) => {
149
- leaf.$value = primary;
150
- updates.push("theme.light.primary");
151
- });
152
- setLeaf(tokens, "theme.light.primary-foreground", (leaf) => {
153
- leaf.$value = primaryForeground;
154
- updates.push("theme.light.primary-foreground");
155
- });
252
+ const brand: [string, unknown][] = [["theme.light.primary", primary]];
253
+ if (primaryForeground !== undefined) brand.push(["theme.light.primary-foreground", primaryForeground]);
254
+ for (const [path, value] of brand) {
255
+ if (typeof value !== "string" || !isValidHex(value)) {
256
+ reject(path, "not a hex color");
257
+ continue;
258
+ }
259
+ if (!setLeaf(tokens, path, (leaf) => { leaf.$value = value.trim(); updates.push(path); })) reject(path, "not a token in tokens.json");
260
+ }
156
261
  }
157
262
 
158
- // Promote the active custom color to a built-in entry in brand-colors.json
159
- // alongside the tokens.json write, so a Save fully persists the swatch
160
- // (everyone on the repo sees it as a picker option) and the system primary
161
- // in one round-trip. Validation matches /api/brand-colors so a malformed
162
- // entry is rejected without corrupting the file.
163
263
  let pinnedBuiltinId: string | null = null;
164
264
  if (payload.pinAsBuiltin) {
165
265
  const e = payload.pinAsBuiltin;
@@ -200,22 +300,56 @@ export async function POST(request: Request) {
200
300
  }
201
301
  }
202
302
 
303
+ if (payload.tokenValues) {
304
+ // Only paths into sections the Studio's list edits, and only leaves that already exist (setLeaf skips the rest).
305
+ const allowed = /^(theme\.(light|dark)|color\.primitive|borderRadius|shadow|duration|easing)\.[A-Za-z0-9_.-]+$/;
306
+ for (const [path, value] of Object.entries(payload.tokenValues)) {
307
+ if (!allowed.test(path)) {
308
+ reject(path, "not a path the Studio edits");
309
+ continue;
310
+ }
311
+ if (!acceptValue(tokens, value)) {
312
+ reject(path, ALIAS_FORM.test(String(value).trim()) ? "alias does not point at a palette color" : "value not accepted");
313
+ continue;
314
+ }
315
+ const v = value.trim();
316
+ let typeOk = true;
317
+ const written = setLeaf(tokens, path, (leaf) => {
318
+ // An alias is a color reference, so only a color token takes one.
319
+ if (ALIAS_FORM.test(v) && leaf.$type !== "color") {
320
+ typeOk = false;
321
+ return;
322
+ }
323
+ leaf.$value = v;
324
+ updates.push(path);
325
+ });
326
+ if (!written) reject(path, "not a token in tokens.json");
327
+ else if (!typeOk) reject(path, "only a color token can hold an alias");
328
+ }
329
+ }
330
+
203
331
  if (payload.fonts) {
204
- if (payload.fonts.sans) {
332
+ if (acceptText(payload.fonts.sans)) {
205
333
  setLeaf(tokens, "fontFamily.sans", (leaf) => {
206
- leaf.$value = payload.fonts!.sans;
334
+ leaf.$value = payload.fonts!.sans!.trim();
207
335
  updates.push("fontFamily.sans");
208
336
  });
209
337
  }
210
- if (payload.fonts.serif) {
338
+ if (acceptText(payload.fonts.heading)) {
339
+ setLeaf(tokens, "fontFamily.heading", (leaf) => {
340
+ leaf.$value = payload.fonts!.heading!.trim();
341
+ updates.push("fontFamily.heading");
342
+ });
343
+ }
344
+ if (acceptText(payload.fonts.serif)) {
211
345
  setLeaf(tokens, "fontFamily.serif", (leaf) => {
212
- leaf.$value = payload.fonts!.serif;
346
+ leaf.$value = payload.fonts!.serif!.trim();
213
347
  updates.push("fontFamily.serif");
214
348
  });
215
349
  }
216
- if (payload.fonts.mono) {
350
+ if (acceptText(payload.fonts.mono)) {
217
351
  setLeaf(tokens, "fontFamily.mono", (leaf) => {
218
- leaf.$value = payload.fonts!.mono;
352
+ leaf.$value = payload.fonts!.mono!.trim();
219
353
  updates.push("fontFamily.mono");
220
354
  });
221
355
  }
@@ -248,8 +382,18 @@ export async function POST(request: Request) {
248
382
  });
249
383
  }
250
384
 
385
+ // An alias that loops or runs too deep would make build:tokens throw on every later run, so a tree that gained
386
+ // one is not written.
387
+ const introduced = [...aliasFailures(tokens)].filter((f) => !aliasFailuresBefore.has(f));
388
+ if (introduced.length > 0) {
389
+ return NextResponse.json(
390
+ { ok: false, error: `Not saved, tokens.json was not changed: ${introduced.slice(0, 3).join("; ")}`, rejected },
391
+ { status: 400 },
392
+ );
393
+ }
394
+
251
395
  if (updates.length === 0) {
252
- return NextResponse.json({ ok: true, updates: [], note: "No changes to save." });
396
+ return NextResponse.json({ ok: true, updates: [], ...(rejected.length ? { rejected } : {}), note: "No changes to save." });
253
397
  }
254
398
 
255
399
  try {
@@ -268,6 +412,7 @@ export async function POST(request: Request) {
268
412
  return NextResponse.json({
269
413
  ok: true,
270
414
  updates,
415
+ ...(rejected.length ? { rejected } : {}),
271
416
  warning: `Saved tokens.json but build:tokens failed: ${(err as Error).message}`,
272
417
  pinnedBuiltinId,
273
418
  replaceCustomId: payload.pinAsBuiltin?.replaceCustomId ?? null,
@@ -277,6 +422,7 @@ export async function POST(request: Request) {
277
422
  return NextResponse.json({
278
423
  ok: true,
279
424
  updates,
425
+ ...(rejected.length ? { rejected } : {}),
280
426
  pinnedBuiltinId,
281
427
  replaceCustomId: payload.pinAsBuiltin?.replaceCustomId ?? null,
282
428
  });
@@ -209,11 +209,20 @@ export default function RootLayout({
209
209
  // very first paint. Fall back to system-ui if next/font hasn't
210
210
  // initialized yet.
211
211
  var SANS = Object.assign({
212
- hyperlegible: "'Hyperlegible Sans', ui-sans-serif, sans-serif, system-ui",
212
+ hyperlegible: "'Atkinson Hyperlegible Sans', 'Hyperlegible Sans', ui-sans-serif, sans-serif, system-ui",
213
+ figtree: "'Figtree', 'Atkinson Hyperlegible Sans', ui-sans-serif, sans-serif, system-ui",
213
214
  atkinson: "var(--font-atkinson), 'Atkinson Hyperlegible', ui-sans-serif, sans-serif, system-ui",
214
215
  inter: "var(--font-inter), 'Inter', ui-sans-serif, sans-serif, system-ui",
215
216
  system: "ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif"
216
217
  }, ${JSON.stringify(brandSansMap)});
218
+ var HEADING = Object.assign({
219
+ figtree: "'Figtree', 'Atkinson Hyperlegible Sans', 'Hyperlegible Sans', ui-sans-serif, sans-serif, system-ui",
220
+ hyperlegible: "'Atkinson Hyperlegible Sans', 'Hyperlegible Sans', ui-sans-serif, sans-serif, system-ui",
221
+ inter: "var(--font-inter, 'Inter'), 'Inter', ui-sans-serif, sans-serif, system-ui",
222
+ lora: "var(--font-lora, 'Lora'), 'Lora', Georgia, ui-serif, serif",
223
+ "source-serif": "var(--font-source-serif, 'Source Serif 4'), 'Source Serif 4', Georgia, ui-serif, serif",
224
+ system: "ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
225
+ }, ${JSON.stringify(brandSansMap)});
217
226
  var SERIF = {
218
227
  georgia: "Georgia, ui-serif, serif",
219
228
  lora: "var(--font-lora), 'Lora', Georgia, ui-serif, serif",
@@ -238,6 +247,8 @@ export default function RootLayout({
238
247
  var s = document.documentElement.style;
239
248
  var sans = k("sansFont");
240
249
  if (sans && SANS[sans]) s.setProperty("--font-sans", SANS[sans]);
250
+ var heading = k("headingFont");
251
+ if (heading && HEADING[heading]) s.setProperty("--font-heading", HEADING[heading]);
241
252
  var serif = k("serifFont");
242
253
  if (serif && SERIF[serif]) s.setProperty("--font-serif", SERIF[serif]);
243
254
  var mono = k("monoFont");
@@ -3,6 +3,7 @@
3
3
  // allow-slop:BADS-SLOP-13 Component gallery: the centered blocks are Stepper titles under their step icons, which is the correct centered pattern for that primitive, not a centered page.
4
4
  import { sectionId, useSectionVisible } from "@behavioral-agentic-design-system/core/app/preview/showcase-filter";
5
5
  import * as React from "react";
6
+ import { Reveal } from "@behavioral-agentic-design-system/core/components/motion/reveal";
6
7
  import {
7
8
  Pagination,
8
9
  PaginationContent,
@@ -544,21 +545,27 @@ function Section({ title, children }: { title: string; children: React.ReactNode
544
545
  const visible = useSectionVisible(id);
545
546
  if (!visible) return null;
546
547
  return (
547
- // content-visibility:auto lets the browser skip style/layout/paint for
548
- // sections outside the viewport. With 120+ sections (and growing
549
- // nightly), that skip is what keeps the dark/light retheme cheap enough
550
- // not to stutter the host's iris-wipe view transition when this tab is
551
- // active. contain-intrinsic-size 'auto 600px' holds a placeholder height
552
- // before first render (then remembers the real one) so the scrollbar
553
- // stays sane.
554
- <section
555
- id={id}
556
- data-section-id={id}
557
- className="scroll-mt-6 space-y-4 [content-visibility:auto] [contain-intrinsic-size:auto_600px]"
558
- >
559
- <h2 className="text-2xl font-semibold tracking-tight">{title}</h2>
560
- <Card className="p-6 shadow-none">{children}</Card>
561
- </section>
548
+ // Reveal fades each section up once as it scrolls into view (and does nothing
549
+ // for sections already on screen, under reduced motion, or without
550
+ // IntersectionObserver). It wraps the <section> rather than living inside it so
551
+ // the anchor target, scroll-mt and content-visibility below stay untouched.
552
+ <Reveal>
553
+ {/* content-visibility:auto lets the browser skip style/layout/paint for
554
+ sections outside the viewport. With 120+ sections (and growing
555
+ nightly), that skip is what keeps the dark/light retheme cheap enough
556
+ not to stutter the host's iris-wipe view transition when this tab is
557
+ active. contain-intrinsic-size 'auto 600px' holds a placeholder height
558
+ before first render (then remembers the real one) so the scrollbar
559
+ stays sane. */}
560
+ <section
561
+ id={id}
562
+ data-section-id={id}
563
+ className="scroll-mt-6 space-y-4 [content-visibility:auto] [contain-intrinsic-size:auto_600px]"
564
+ >
565
+ <h2 className="text-2xl font-semibold tracking-tight">{title}</h2>
566
+ <Card className="p-6 shadow-none">{children}</Card>
567
+ </section>
568
+ </Reveal>
562
569
  );
563
570
  }
564
571
 
@@ -13308,7 +13315,7 @@ function AnnouncementBarShowcase() {
13308
13315
  <p className="mb-3 text-xs font-medium text-muted-foreground">
13309
13316
  All five variants
13310
13317
  </p>
13311
- <div className="flex flex-col rounded-lg overflow-hidden border border-border">
13318
+ <div className="flex flex-col rounded-lg overflow-hidden border border-border [&>[data-slot=announcement-bar]:last-child]:border-b-0">
13312
13319
  <AnnouncementBar variant="default">
13313
13320
  BADS v2.4 — ProgressStack, Callout &amp; AnnouncementBar now available.
13314
13321
  </AnnouncementBar>
@@ -13330,7 +13337,7 @@ function AnnouncementBarShowcase() {
13330
13337
  <p className="mb-3 text-xs font-medium text-muted-foreground">
13331
13338
  With action link
13332
13339
  </p>
13333
- <div className="rounded-lg overflow-hidden border border-border">
13340
+ <div className="rounded-lg overflow-hidden border border-border [&>[data-slot=announcement-bar]:last-child]:border-b-0">
13334
13341
  <AnnouncementBar
13335
13342
  variant="default"
13336
13343
  action={
@@ -13350,7 +13357,7 @@ function AnnouncementBarShowcase() {
13350
13357
  <p className="mb-3 text-xs font-medium text-muted-foreground">
13351
13358
  Dismissible — with action + dismiss button
13352
13359
  </p>
13353
- <div className="rounded-lg overflow-hidden border border-border">
13360
+ <div className="rounded-lg overflow-hidden border border-border [&>[data-slot=announcement-bar]:last-child]:border-b-0">
13354
13361
  {!dismissed ? (
13355
13362
  <AnnouncementBar
13356
13363
  variant="info"
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  import { useGlobalSansFont } from "@behavioral-agentic-design-system/core/hooks/use-global-sans-font";
4
+ import { useGlobalHeadingFont } from "@behavioral-agentic-design-system/core/hooks/use-global-heading-font";
4
5
  import { useGlobalSerifFont } from "@behavioral-agentic-design-system/core/hooks/use-global-serif-font";
5
6
  import { useGlobalMonoFont } from "@behavioral-agentic-design-system/core/hooks/use-global-mono-font";
6
7
  import { useGlobalPrimaryColor } from "@behavioral-agentic-design-system/core/hooks/use-global-primary-color";
@@ -27,6 +28,7 @@ export default function GlobalFontClient() {
27
28
  useTokenOverrides();
28
29
  useSyncTypeScale();
29
30
  useGlobalSansFont();
31
+ useGlobalHeadingFont();
30
32
  useGlobalSerifFont();
31
33
  useGlobalMonoFont();
32
34
  useGlobalPrimaryColor();
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { TooltipProvider } from "@behavioral-agentic-design-system/core/components/ui/tooltip";
4
4
  import { useGlobalSansFont } from "@behavioral-agentic-design-system/core/hooks/use-global-sans-font";
5
+ import { useGlobalHeadingFont } from "@behavioral-agentic-design-system/core/hooks/use-global-heading-font";
5
6
  import { useGlobalSerifFont } from "@behavioral-agentic-design-system/core/hooks/use-global-serif-font";
6
7
  import { useGlobalMonoFont } from "@behavioral-agentic-design-system/core/hooks/use-global-mono-font";
7
8
  import { useGlobalPrimaryColor } from "@behavioral-agentic-design-system/core/hooks/use-global-primary-color";
@@ -31,6 +32,7 @@ function GlobalThemeSync() {
31
32
  useTokenOverrides();
32
33
  useSyncTypeScale();
33
34
  useGlobalSansFont();
35
+ useGlobalHeadingFont();
34
36
  useGlobalSerifFont();
35
37
  useGlobalMonoFont();
36
38
  useGlobalPrimaryColor();