@behavioral-agentic-design-system/core 0.40.0 → 0.45.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 (148) hide show
  1. package/README.md +2 -0
  2. package/package.json +41 -9
  3. package/scripts/a11y-lint.cjs +66 -3
  4. package/scripts/check-spec.mjs +73 -0
  5. package/scripts/deal-directions.mjs +186 -0
  6. package/scripts/health-report.mjs +23 -3
  7. package/scripts/lib/counted-lint.mjs +100 -0
  8. package/scripts/lib/marketing-library.mjs +129 -0
  9. package/scripts/lib/on-system.mjs +249 -0
  10. package/scripts/lib/random.mjs +22 -0
  11. package/scripts/lib/spec-parse.d.mts +25 -0
  12. package/scripts/lib/spec-parse.mjs +188 -0
  13. package/scripts/lib/tells.mjs +128 -0
  14. package/scripts/lint-css-vars.mjs +175 -0
  15. package/scripts/lint-html-nesting.mjs +116 -0
  16. package/scripts/lint-live-ctas.mjs +138 -0
  17. package/scripts/lint-slop.mjs +25 -1
  18. package/scripts/on-system-score.mjs +95 -0
  19. package/scripts/slop-rules.mjs +1 -1
  20. package/scripts/source-images.mjs +180 -0
  21. package/scripts/ux-tells.mjs +78 -0
  22. package/scripts/wcag-audit.cjs +72 -5
  23. package/src/api/brand-colors.ts +3 -0
  24. package/src/api/brand-fonts.ts +3 -0
  25. package/src/api/brand-mark.ts +6 -1
  26. package/src/api/dev-write-guard.ts +53 -0
  27. package/src/api/layers/file.ts +7 -4
  28. package/src/api/onboarding-extract.ts +85 -30
  29. package/src/api/onboarding.ts +3 -0
  30. package/src/api/save-tokens.ts +3 -0
  31. package/src/app/layout.tsx +6 -0
  32. package/src/app/opengraph-image.tsx +5 -0
  33. package/src/app/preview/canvas/page.tsx +12 -0
  34. package/src/app/preview/components/page.tsx +2003 -2
  35. package/src/app/preview/studio/blank-screen.tsx +143 -0
  36. package/src/app/preview/studio/page.tsx +7 -0
  37. package/src/app/shell.tsx +168 -49
  38. package/src/components/Foundations/Motion.stories.tsx +1 -0
  39. package/src/components/canvas/canvas.tsx +458 -0
  40. package/src/components/canvas/layout.ts +72 -0
  41. package/src/components/canvas/parse-canvas.ts +32 -0
  42. package/src/components/canvas/sample.ts +90 -0
  43. package/src/components/canvas/spec-frame.tsx +43 -0
  44. package/src/components/canvas/types.ts +33 -0
  45. package/src/components/customize/design-controls.tsx +16 -1
  46. package/src/components/docs-tab.tsx +7 -7
  47. package/src/components/home-recent.tsx +73 -0
  48. package/src/components/home-tab.tsx +13 -13
  49. package/src/components/layers-tab.tsx +2 -2
  50. package/src/components/markdown-preview.tsx +60 -12
  51. package/src/components/studio/control-panel.tsx +299 -0
  52. package/src/components/studio/control-row.tsx +77 -0
  53. package/src/components/studio/preview-frame.tsx +165 -0
  54. package/src/components/studio/preview-pane.tsx +247 -0
  55. package/src/components/studio/studio.tsx +158 -0
  56. package/src/components/studio/types.ts +218 -0
  57. package/src/components/studio/use-studio-tweaks.ts +128 -0
  58. package/src/components/studio/use-studio-view-state.ts +72 -0
  59. package/src/components/ui/anchor.tsx +37 -3
  60. package/src/components/ui/attachment.tsx +211 -0
  61. package/src/components/ui/autocomplete.tsx +1 -1
  62. package/src/components/ui/chart.tsx +3 -0
  63. package/src/components/ui/code.tsx +1 -1
  64. package/src/components/ui/color-picker.tsx +21 -5
  65. package/src/components/ui/data-table.tsx +64 -3
  66. package/src/components/ui/date-field.tsx +1 -1
  67. package/src/components/ui/editable.tsx +1 -0
  68. package/src/components/ui/faceted-filter.tsx +187 -0
  69. package/src/components/ui/gauge-chart.tsx +252 -0
  70. package/src/components/ui/heatmap.tsx +256 -0
  71. package/src/components/ui/index.ts +9 -0
  72. package/src/components/ui/infinite-scroll.tsx +103 -0
  73. package/src/components/ui/inline-edit.tsx +175 -0
  74. package/src/components/ui/json-input.tsx +351 -0
  75. package/src/components/ui/month-picker.tsx +1 -1
  76. package/src/components/ui/navigation-progress.tsx +281 -0
  77. package/src/components/ui/number-input.tsx +27 -7
  78. package/src/components/ui/otp-input.tsx +208 -0
  79. package/src/components/ui/password-input.tsx +2 -1
  80. package/src/components/ui/password-strength-input.tsx +288 -0
  81. package/src/components/ui/phone-input.tsx +274 -0
  82. package/src/components/ui/pill.tsx +140 -0
  83. package/src/components/ui/popover.tsx +27 -4
  84. package/src/components/ui/scroll-progress.tsx +100 -0
  85. package/src/components/ui/search-input.tsx +1 -1
  86. package/src/components/ui/snackbar.tsx +393 -0
  87. package/src/components/ui/sortable-list.tsx +342 -0
  88. package/src/components/ui/squircle.tsx +1 -1
  89. package/src/components/ui/table.tsx +1 -1
  90. package/src/components/ui/tags-input.tsx +1 -1
  91. package/src/components/ui/timer.tsx +1 -0
  92. package/src/components/ui/tour.tsx +1 -3
  93. package/src/components/ui/transfer-list.tsx +13 -26
  94. package/src/components/ui/week-picker.tsx +1 -1
  95. package/src/components/ui/year-picker.tsx +1 -1
  96. package/src/data/component-added.json +958 -0
  97. package/src/data/docs-index.ts +36 -0
  98. package/src/hooks/use-global-mono-font.ts +1 -0
  99. package/src/hooks/use-global-primary-color.ts +1 -0
  100. package/src/hooks/use-global-sans-font.ts +1 -0
  101. package/src/hooks/use-global-serif-font.ts +1 -0
  102. package/src/hooks/use-global-type-scale.ts +17 -2
  103. package/src/hooks/use-mobile.ts +2 -0
  104. package/src/hooks/use-sync-type-scale.ts +7 -11
  105. package/src/lib/clamp.ts +2 -0
  106. package/src/lib/spec-parse.ts +4 -0
  107. package/src/lib/svg-sanitize.ts +19 -9
  108. package/src/stories/Anchor.stories.tsx +54 -0
  109. package/src/stories/Attachment.stories.tsx +189 -0
  110. package/src/stories/Autocomplete.stories.tsx +2 -0
  111. package/src/stories/Canvas.stories.tsx +45 -0
  112. package/src/stories/Chart.stories.tsx +4 -0
  113. package/src/stories/Code.stories.tsx +1 -0
  114. package/src/stories/ColorPicker.stories.tsx +41 -0
  115. package/src/stories/DataTable.stories.tsx +30 -0
  116. package/src/stories/DateField.stories.tsx +21 -0
  117. package/src/stories/Editable.stories.tsx +2 -0
  118. package/src/stories/FacetedFilter.stories.tsx +197 -0
  119. package/src/stories/GaugeChart.stories.tsx +169 -0
  120. package/src/stories/Heatmap.stories.tsx +172 -0
  121. package/src/stories/InfiniteScroll.stories.tsx +225 -0
  122. package/src/stories/InlineEdit.stories.tsx +106 -0
  123. package/src/stories/JsonInput.stories.tsx +212 -0
  124. package/src/stories/MarkdownPreview.stories.tsx +53 -0
  125. package/src/stories/MonthPicker.stories.tsx +21 -0
  126. package/src/stories/NavigationProgress.stories.tsx +159 -0
  127. package/src/stories/NumberInput.stories.tsx +26 -0
  128. package/src/stories/OtpInput.stories.tsx +110 -0
  129. package/src/stories/PasswordInput.stories.tsx +4 -0
  130. package/src/stories/PasswordStrengthInput.stories.tsx +211 -0
  131. package/src/stories/PhoneInput.stories.tsx +127 -0
  132. package/src/stories/Pill.stories.tsx +201 -0
  133. package/src/stories/Popover.stories.tsx +29 -1
  134. package/src/stories/Portal.stories.tsx +3 -1
  135. package/src/stories/ScrollProgress.stories.tsx +117 -0
  136. package/src/stories/SearchInput.stories.tsx +2 -0
  137. package/src/stories/Snackbar.stories.tsx +315 -0
  138. package/src/stories/SortableList.stories.tsx +263 -0
  139. package/src/stories/Squircle.stories.tsx +1 -0
  140. package/src/stories/Table.stories.tsx +1 -0
  141. package/src/stories/TagsInput.stories.tsx +2 -0
  142. package/src/stories/Timer.stories.tsx +26 -0
  143. package/src/stories/Tour.stories.tsx +1 -0
  144. package/src/stories/TransferList.stories.tsx +4 -0
  145. package/src/stories/WeekPicker.stories.tsx +21 -0
  146. package/src/stories/YearPicker.stories.tsx +21 -0
  147. package/src/stories/story-groups.json +33 -16
  148. package/src/tokens.json +82 -54
@@ -0,0 +1,128 @@
1
+ "use client";
2
+
3
+ import { useCallback, useMemo } from "react";
4
+ import { useTokenOverrides } from "@behavioral-agentic-design-system/core/hooks/use-token-overrides";
5
+ import {
6
+ DEFAULT_PRIMARY_COLOR,
7
+ useGlobalPrimaryColor,
8
+ } from "@behavioral-agentic-design-system/core/hooks/use-global-primary-color";
9
+ import {
10
+ DEFAULT_SANS_FONT,
11
+ SANS_FONT_OPTIONS,
12
+ useGlobalSansFont,
13
+ } from "@behavioral-agentic-design-system/core/hooks/use-global-sans-font";
14
+ import { useGlobalTypeScale } from "@behavioral-agentic-design-system/core/hooks/use-global-type-scale";
15
+ import { useGlobalDesignControls } from "@behavioral-agentic-design-system/core/hooks/use-global-design-controls";
16
+ import {
17
+ NUMERIC_TWEAKS,
18
+ clampTypeScale,
19
+ type StudioTweakKey,
20
+ type StudioTweaks,
21
+ } from "./types";
22
+
23
+ const PRIMARY_DEFAULT = DEFAULT_PRIMARY_COLOR;
24
+ const SANS_DEFAULT = DEFAULT_SANS_FONT;
25
+
26
+ const DEFAULTS: StudioTweaks = {
27
+ primaryColor: PRIMARY_DEFAULT,
28
+ sansFont: SANS_DEFAULT,
29
+ typeBase: NUMERIC_TWEAKS.typeBase.default,
30
+ typeRatio: NUMERIC_TWEAKS.typeRatio.default,
31
+ letterSpacing: NUMERIC_TWEAKS.letterSpacing.default,
32
+ radius: NUMERIC_TWEAKS.radius.default,
33
+ shadowOpacity: NUMERIC_TWEAKS.shadowOpacity.default,
34
+ spacing: NUMERIC_TWEAKS.spacing.default,
35
+ };
36
+
37
+ /**
38
+ * Studio tweaks: a typed facade over the four existing global hooks. Adds no
39
+ * state of its own, so values stay in the shipped localStorage + storage-event
40
+ * contract that every preview iframe already listens to.
41
+ */
42
+ export function useStudioTweaks() {
43
+ // Order matters: useTokenOverrides' mount effect runs applyThemeEditorState,
44
+ // which clears inline radius/spacing/fonts/colors. It must mount first so
45
+ // the other hooks' mount effects re-apply their values afterwards.
46
+ useTokenOverrides();
47
+ const { color, setColor, options, addCustomSilent } = useGlobalPrimaryColor();
48
+ const { font, setFont } = useGlobalSansFont();
49
+ const { scale, setScale, reset: resetScale } = useGlobalTypeScale();
50
+ const { controls, setControl, reset: resetControls } = useGlobalDesignControls();
51
+
52
+ const tweaks: StudioTweaks = useMemo(
53
+ () => ({
54
+ primaryColor: color,
55
+ sansFont: font,
56
+ typeBase: scale.base,
57
+ typeRatio: scale.ratio,
58
+ letterSpacing: controls.letterSpacing,
59
+ radius: controls.radius,
60
+ shadowOpacity: controls.shadowOpacity,
61
+ spacing: controls.spacing,
62
+ }),
63
+ [color, font, scale.base, scale.ratio, controls],
64
+ );
65
+
66
+ const set = useCallback(
67
+ <K extends StudioTweakKey>(key: K, value: StudioTweaks[K]) => {
68
+ switch (key) {
69
+ case "primaryColor":
70
+ setColor(value as string);
71
+ break;
72
+ case "sansFont":
73
+ if ((value as string) in SANS_FONT_OPTIONS) setFont(value as string);
74
+ break;
75
+ case "typeBase":
76
+ case "typeRatio": {
77
+ const next = clampTypeScale({
78
+ base: key === "typeBase" ? (value as number) : scale.base,
79
+ ratio: key === "typeRatio" ? (value as number) : scale.ratio,
80
+ });
81
+ if (next.base !== scale.base) setScale("base", next.base);
82
+ if (next.ratio !== scale.ratio) setScale("ratio", next.ratio);
83
+ break;
84
+ }
85
+ default:
86
+ setControl(key, value as number);
87
+ }
88
+ },
89
+ [setColor, setFont, setScale, setControl, scale.base, scale.ratio],
90
+ );
91
+
92
+ const reset = useCallback(
93
+ (key: StudioTweakKey) => set(key, DEFAULTS[key]),
94
+ [set],
95
+ );
96
+
97
+ const resetAll = useCallback(() => {
98
+ resetControls();
99
+ resetScale();
100
+ setFont(SANS_DEFAULT);
101
+ setColor(PRIMARY_DEFAULT);
102
+ }, [resetControls, resetScale, setFont, setColor]);
103
+
104
+ const isDefault = useCallback(
105
+ (key: StudioTweakKey) => tweaks[key] === DEFAULTS[key],
106
+ [tweaks],
107
+ );
108
+
109
+ const addCustomColor = useCallback(
110
+ (hex: string): string | null => {
111
+ const id = addCustomSilent(hex);
112
+ if (id) setColor(id);
113
+ return id;
114
+ },
115
+ [addCustomSilent, setColor],
116
+ );
117
+
118
+ return {
119
+ tweaks,
120
+ defaults: DEFAULTS,
121
+ set,
122
+ reset,
123
+ resetAll,
124
+ isDefault,
125
+ primaryOptions: options,
126
+ addCustomColor,
127
+ };
128
+ }
@@ -0,0 +1,72 @@
1
+ "use client";
2
+
3
+ import { useCallback, useEffect, useRef, useState } from "react";
4
+ import {
5
+ STUDIO_SUBJECTS,
6
+ STUDIO_VIEW_DEFAULTS,
7
+ parseStudioViewState,
8
+ writeStudioViewState,
9
+ type StudioViewState,
10
+ } from "./types";
11
+
12
+ const URL_DEBOUNCE_MS = 150;
13
+
14
+ /**
15
+ * Studio view state (subject, viewport, theme, panel mode, collapsed) mirrored
16
+ * into the URL. Initial render returns the defaults so server and client agree;
17
+ * a mount effect reads window.location.search once. Writes use replaceState,
18
+ * never pushState, and spread the existing history.state so the shell's
19
+ * `shellTab` entry survives.
20
+ */
21
+ export function useStudioViewState() {
22
+ const [state, setState] = useState<StudioViewState>(STUDIO_VIEW_DEFAULTS);
23
+ const latest = useRef<StudioViewState>(STUDIO_VIEW_DEFAULTS);
24
+ const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
25
+ const dirty = useRef(false);
26
+
27
+ useEffect(() => {
28
+ const parsed = parseStudioViewState(new URLSearchParams(window.location.search));
29
+ latest.current = parsed;
30
+ setState(parsed);
31
+ }, []);
32
+
33
+ useEffect(
34
+ () => () => {
35
+ if (timer.current) clearTimeout(timer.current);
36
+ },
37
+ [],
38
+ );
39
+
40
+ const set = useCallback(
41
+ <K extends keyof StudioViewState>(key: K, value: StudioViewState[K]) => {
42
+ const next = { ...latest.current, [key]: value };
43
+ latest.current = next;
44
+ dirty.current = true;
45
+ setState(next);
46
+ if (timer.current) clearTimeout(timer.current);
47
+ timer.current = setTimeout(() => {
48
+ timer.current = null;
49
+ if (typeof window === "undefined") return;
50
+ const url = new URL(window.location.href);
51
+ writeStudioViewState(url.searchParams, latest.current);
52
+ window.history.replaceState({ ...window.history.state }, "", url);
53
+ }, URL_DEBOUNCE_MS);
54
+ },
55
+ [],
56
+ );
57
+
58
+ // The mount effect above reads the URL once, so a Studio that is already mounted (the shell keeps visited tabs
59
+ // alive) never sees a link that points it at another subject. Home's "Recently added" sends this event, the
60
+ // same pairing the Docs tab uses with "bads:docs:navigate".
61
+ useEffect(() => {
62
+ const onSubject = (event: Event) => {
63
+ const subject = (event as CustomEvent<unknown>).detail;
64
+ const match = STUDIO_SUBJECTS.find((s) => s.value === subject);
65
+ if (match) set("subject", match.value);
66
+ };
67
+ window.addEventListener("bads:studio:subject", onSubject);
68
+ return () => window.removeEventListener("bads:studio:subject", onSubject);
69
+ }, [set]);
70
+
71
+ return { state, set };
72
+ }
@@ -19,6 +19,15 @@ interface AnchorProps extends React.ComponentProps<"nav"> {
19
19
  label?: string
20
20
  /** Offset in px from the top of the viewport for IntersectionObserver rootMargin. Default 0. */
21
21
  offset?: number
22
+ /**
23
+ * Controlled active item. When provided, the component highlights this id
24
+ * instead of its own scroll-spy result; the observer keeps running and
25
+ * reports what it sees through `onActiveChange`, so the consumer can mirror
26
+ * it into a URL hash, a store, or a sibling surface. Omit for uncontrolled.
27
+ */
28
+ activeId?: string | null
29
+ /** Fires whenever the scroll-spy resolves a new visible section. */
30
+ onActiveChange?: (id: string) => void
22
31
  }
23
32
 
24
33
  // Each depth level adds pl-3 of indentation. Clamped at depth 2.
@@ -31,15 +40,35 @@ const DEPTH_PADDING = ["pl-3", "pl-6", "pl-9"] as const
31
40
  *
32
41
  * Distinct from NavigationMenu (multi-page) and Breadcrumb (path hierarchy).
33
42
  * Cross-system references: Mantine TableOfContents, Ant Design Anchor.
43
+ * This IS BADS's table-of-contents primitive — the name follows Ant Design,
44
+ * and the registry lists `TableOfContents` as an alias so the candidate
45
+ * pre-screen doesn't re-propose it (ledgers/component-builds.jsonl,
46
+ * 2026-08-21 and 2026-09-15).
47
+ *
48
+ * Uncontrolled by default. Pass `activeId` (+ `onActiveChange`) to control
49
+ * the highlight — e.g. to drive it from the URL hash or a shared store.
34
50
  */
35
51
  function Anchor({
36
52
  items,
37
53
  label = "On this page",
38
54
  offset = 0,
55
+ activeId: activeIdProp,
56
+ onActiveChange,
39
57
  className,
40
58
  ...props
41
59
  }: AnchorProps) {
42
- const [activeId, setActiveId] = React.useState<string | null>(null)
60
+ const [internalActiveId, setInternalActiveId] = React.useState<
61
+ string | null
62
+ >(null)
63
+ const isControlled = activeIdProp !== undefined
64
+ const activeId = isControlled ? activeIdProp : internalActiveId
65
+
66
+ // Latest-callback ref so the observer effect doesn't re-subscribe every
67
+ // render when the consumer passes an inline arrow for onActiveChange.
68
+ const onActiveChangeRef = React.useRef(onActiveChange)
69
+ React.useEffect(() => {
70
+ onActiveChangeRef.current = onActiveChange
71
+ }, [onActiveChange])
43
72
 
44
73
  // Key the effect off the id list (not array identity) so consumers can
45
74
  // inline `items` without tearing the observer down on every render.
@@ -62,7 +91,12 @@ function Anchor({
62
91
  // is visible wins. Keep the previous active id while nothing is
63
92
  // visible (e.g. mid-jump between long sections).
64
93
  const first = ids.find((id) => visible.has(id))
65
- if (first) setActiveId(first)
94
+ if (first) {
95
+ // Uncontrolled: own the highlight. Controlled: only report; the
96
+ // consumer decides whether to mirror it back through `activeId`.
97
+ if (!isControlled) setInternalActiveId(first)
98
+ onActiveChangeRef.current?.(first)
99
+ }
66
100
  },
67
101
  { rootMargin: `${-offset}px 0px 0px 0px`, threshold: 0 }
68
102
  )
@@ -73,7 +107,7 @@ function Anchor({
73
107
  }
74
108
 
75
109
  return () => observer.disconnect()
76
- }, [idKey, offset])
110
+ }, [idKey, offset, isControlled])
77
111
 
78
112
  return (
79
113
  <nav
@@ -0,0 +1,211 @@
1
+ "use client"
2
+
3
+ /**
4
+ * Attachment — pre-send file chip for a chat composer.
5
+ *
6
+ * Appears inside the composer input area after a user picks a file and
7
+ * before the message is sent: file-type icon, truncated file name, formatted
8
+ * size, and a remove control. Pairs with ChatInput (the composer) and
9
+ * FileButton (the picker). It is the third leg of the attach flow — pick
10
+ * (FileButton) → review (Attachment) → send (ChatInput).
11
+ *
12
+ * Sources: shadcn/ui July 2026 chat release (Attachment); Mantine FileButton
13
+ * + Pill attachment pattern. Convention: Slack, Linear, and Intercom composer
14
+ * chips.
15
+ *
16
+ * NOT a drop zone (FileUpload) and NOT a post-send file card in the
17
+ * conversation (FileCard). Attachment is the chip the user can still back out
18
+ * of.
19
+ *
20
+ * Composition (bucket C): CloseButton for the remove control (inherits
21
+ * Button's focus ring, disabled handling, and 1.5-stroke X) and FormatByte
22
+ * for the size (SI scale, exact byte count on title). No new tokens.
23
+ *
24
+ * Accessibility:
25
+ * - root is role="group" with aria-label "Attached file: <name>" so a screen
26
+ * reader hears the chip as one unit before reaching the remove button
27
+ * - remove button is a 44px CloseButton (size="icon-xl", SC 2.5.5 Enhanced)
28
+ * with aria-label "Remove <name>" — the chip is a flow-changing control
29
+ * inside a composer, so the dense-chrome 36px exception does not apply
30
+ * - file name truncates (min-w-0 truncate) and rides the title attribute so
31
+ * the full string is recoverable on hover; the group's aria-label carries
32
+ * it for assistive tech
33
+ *
34
+ * Motion (spec §4c): remove-button hover is transition-colors driven by
35
+ * --duration-fast / --ease-out. No entrance or exit animation — the chip
36
+ * mounts and unmounts with the composer's own layout; animating removal
37
+ * would delay the user's undo-the-mistake action.
38
+ */
39
+
40
+ import * as React from "react"
41
+ import {
42
+ File,
43
+ FileArchive,
44
+ FileAudio,
45
+ FileCode,
46
+ FileImage,
47
+ FileText,
48
+ FileVideo,
49
+ type LucideIcon,
50
+ } from "lucide-react"
51
+
52
+ import { cn } from "../../lib/utils"
53
+ import { CloseButton } from "./close-button"
54
+ import { FormatByte } from "./format-byte"
55
+
56
+ const CODE_MIME = new Set([
57
+ "application/json",
58
+ "application/javascript",
59
+ "application/typescript",
60
+ "application/xml",
61
+ "application/x-sh",
62
+ "application/x-yaml",
63
+ "text/javascript",
64
+ "text/typescript",
65
+ "text/css",
66
+ "text/html",
67
+ "text/xml",
68
+ "text/markdown",
69
+ "text/x-python",
70
+ "text/x-java-source",
71
+ "text/x-c",
72
+ "text/yaml",
73
+ ])
74
+
75
+ const ARCHIVE_MIME = new Set([
76
+ "application/zip",
77
+ "application/x-zip-compressed",
78
+ "application/gzip",
79
+ "application/x-gzip",
80
+ "application/x-tar",
81
+ "application/x-7z-compressed",
82
+ "application/x-rar-compressed",
83
+ "application/vnd.rar",
84
+ "application/x-bzip2",
85
+ ])
86
+
87
+ const CODE_EXT = new Set([
88
+ "js", "jsx", "ts", "tsx", "mjs", "cjs", "json", "css", "scss", "html",
89
+ "xml", "yml", "yaml", "md", "py", "rb", "go", "rs", "java", "kt", "swift",
90
+ "c", "h", "cpp", "cs", "sh", "sql", "toml",
91
+ ])
92
+
93
+ const ARCHIVE_EXT = new Set(["zip", "gz", "tgz", "tar", "7z", "rar", "bz2"])
94
+ const IMAGE_EXT = new Set(["png", "jpg", "jpeg", "gif", "webp", "svg", "avif", "heic"])
95
+ const TEXT_EXT = new Set(["pdf", "txt", "doc", "docx", "rtf", "csv", "odt"])
96
+ const AUDIO_EXT = new Set(["mp3", "wav", "m4a", "ogg", "flac", "aac"])
97
+ const VIDEO_EXT = new Set(["mp4", "mov", "webm", "mkv", "avi"])
98
+
99
+ /**
100
+ * Picks the lucide glyph for a file. MIME type wins (it is what
101
+ * `File.type` reports); the extension is the fallback when the browser gives
102
+ * an empty or generic type (`application/octet-stream` is common on Windows
103
+ * for anything it does not recognize).
104
+ */
105
+ function iconForFile(fileName: string, fileType?: string): LucideIcon {
106
+ const mime = (fileType ?? "").toLowerCase()
107
+
108
+ if (mime.startsWith("image/")) return FileImage
109
+ if (mime.startsWith("audio/")) return FileAudio
110
+ if (mime.startsWith("video/")) return FileVideo
111
+ if (CODE_MIME.has(mime)) return FileCode
112
+ if (ARCHIVE_MIME.has(mime)) return FileArchive
113
+ if (mime === "application/pdf" || mime.startsWith("text/")) return FileText
114
+ if (mime.startsWith("application/vnd.") || mime === "application/msword")
115
+ return FileText
116
+
117
+ const dot = fileName.lastIndexOf(".")
118
+ const ext = dot >= 0 ? fileName.slice(dot + 1).toLowerCase() : ""
119
+ if (IMAGE_EXT.has(ext)) return FileImage
120
+ if (AUDIO_EXT.has(ext)) return FileAudio
121
+ if (VIDEO_EXT.has(ext)) return FileVideo
122
+ if (CODE_EXT.has(ext)) return FileCode
123
+ if (ARCHIVE_EXT.has(ext)) return FileArchive
124
+ if (TEXT_EXT.has(ext)) return FileText
125
+
126
+ return File
127
+ }
128
+
129
+ export interface AttachmentProps
130
+ extends Omit<React.ComponentProps<"div">, "children"> {
131
+ /** The file's name, shown truncated; the full value rides `title` and the group's aria-label. */
132
+ fileName: string
133
+ /** Size in bytes. Rendered via FormatByte (SI scale: 42.7 KB, 1.5 MB). Omit to hide. */
134
+ fileSize?: number
135
+ /** MIME type (`File.type`) used to pick the icon. Falls back to the file extension. */
136
+ fileType?: string
137
+ /**
138
+ * Called when the user activates the remove control. When absent the
139
+ * remove button is not rendered — the chip becomes read-only.
140
+ */
141
+ onRemove?: () => void
142
+ /** Dims the chip and disables the remove control (for example while the message is sending). */
143
+ disabled?: boolean
144
+ }
145
+
146
+ function Attachment({
147
+ fileName,
148
+ fileSize,
149
+ fileType,
150
+ onRemove,
151
+ disabled = false,
152
+ className,
153
+ ...props
154
+ }: AttachmentProps) {
155
+ const Icon = iconForFile(fileName, fileType)
156
+
157
+ return (
158
+ <div
159
+ role="group"
160
+ aria-label={`Attached file: ${fileName}`}
161
+ aria-disabled={disabled || undefined}
162
+ data-slot="attachment"
163
+ data-disabled={disabled || undefined}
164
+ className={cn(
165
+ "inline-flex min-h-11 max-w-xs min-w-0 items-center gap-2 overflow-hidden rounded-lg border bg-muted/50 py-1 pl-3 text-foreground",
166
+ onRemove ? "pr-1" : "pr-3",
167
+ disabled && "opacity-50",
168
+ className
169
+ )}
170
+ {...props}
171
+ >
172
+ <Icon
173
+ strokeWidth={1.5}
174
+ aria-hidden="true"
175
+ className="size-5 shrink-0 text-muted-foreground"
176
+ />
177
+ <span className="flex min-w-0 flex-1 flex-col leading-tight">
178
+ <span
179
+ data-slot="attachment-name"
180
+ className="min-w-0 truncate text-sm font-medium"
181
+ title={fileName}
182
+ >
183
+ {fileName}
184
+ </span>
185
+ {typeof fileSize === "number" && (
186
+ <FormatByte
187
+ data-slot="attachment-size"
188
+ value={fileSize}
189
+ className="text-xs text-muted-foreground"
190
+ />
191
+ )}
192
+ </span>
193
+ {onRemove && (
194
+ <CloseButton
195
+ data-slot="attachment-remove"
196
+ size="icon-xl"
197
+ aria-label={`Remove ${fileName}`}
198
+ disabled={disabled}
199
+ onClick={onRemove}
200
+ className="-my-1"
201
+ style={{
202
+ transitionDuration: "var(--duration-fast)",
203
+ transitionTimingFunction: "var(--ease-out)",
204
+ }}
205
+ />
206
+ )}
207
+ </div>
208
+ )
209
+ }
210
+
211
+ export { Attachment }
@@ -108,7 +108,7 @@ export function Autocomplete({
108
108
  }
109
109
  return;
110
110
  }
111
- if (e.key === "Enter") {
111
+ if (e.key === "Enter" && !e.nativeEvent.isComposing) {
112
112
  // Free-text contract: only intercept Enter when an option is
113
113
  // highlighted. Otherwise the typed text stands and the event falls
114
114
  // through (form submit keeps working).
@@ -183,6 +183,9 @@ const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
183
183
  }
184
184
 
185
185
  return (
186
+ // allow-inline-style: generates N custom-property writes scoped to a
187
+ // runtime [data-chart=${id}] selector — no static class can express
188
+ // per-instance generated CSS, and the values written ARE tokens.
186
189
  <style
187
190
  dangerouslySetInnerHTML={{
188
191
  __html: `
@@ -10,7 +10,7 @@ const codeVariants = cva("font-mono text-muted-foreground bg-muted", {
10
10
  variant: {
11
11
  inline: "inline rounded px-[0.3em] py-[0.1em] text-xs",
12
12
  block:
13
- "block w-full rounded-md border border-border px-3 py-2.5 text-sm leading-relaxed overflow-x-auto scrollbar-thin scrollbar-thumb-border scrollbar-track-transparent whitespace-pre outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",
13
+ "block w-full rounded-md border border-border px-3 py-2.5 text-sm leading-relaxed overflow-x-auto [scrollbar-width:thin] [scrollbar-color:theme(colors.border)_transparent] whitespace-pre outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",
14
14
  },
15
15
  size: {
16
16
  sm: "",
@@ -10,7 +10,7 @@ import { Button } from "./button";
10
10
  /* Helpers */
11
11
  /* -------------------------------------------------------------------------- */
12
12
 
13
- const clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v));
13
+ import { clamp } from "../../lib/clamp";
14
14
 
15
15
  function hexToRgb(hex: string): [number, number, number] | null {
16
16
  if (!isValidHex(hex)) return null;
@@ -350,7 +350,20 @@ export function ColorPicker({
350
350
  // Colors the user has added through the wheel, appended after the presets.
351
351
  const [addedSwatches, setAddedSwatches] = React.useState<string[]>([]);
352
352
  const allSwatches = React.useMemo(
353
- () => [...swatches, ...addedSwatches.filter((c) => !swatches.includes(c))],
353
+ () => {
354
+ // Case-insensitive: a controlled parent may hand the same color back
355
+ // as "#3B82F6" while the wheel drafted "#3b82f6", which listed it twice.
356
+ const seen = new Set(swatches.map((c) => c.toLowerCase()));
357
+ return [
358
+ ...swatches,
359
+ ...addedSwatches.filter((c) => {
360
+ const key = c.toLowerCase();
361
+ if (seen.has(key)) return false;
362
+ seen.add(key);
363
+ return true;
364
+ }),
365
+ ];
366
+ },
354
367
  [swatches, addedSwatches]
355
368
  );
356
369
 
@@ -429,14 +442,17 @@ export function ColorPicker({
429
442
 
430
443
  const addColor = () => {
431
444
  if (disabled || !isValidHex(draft)) return;
432
- if (!allSwatches.includes(draft)) setAddedSwatches((prev) => [...prev, draft]);
445
+ if (!allSwatches.some((c) => c.toLowerCase() === draft.toLowerCase()))
446
+ setAddedSwatches((prev) => [...prev, draft]);
433
447
  commit(draft);
434
448
  if (!swatches.includes(draft)) setCustomInput("");
435
449
  onAddSwatch?.(draft);
436
450
  setWheelOpen(false);
437
451
  };
438
452
 
439
- const selectedSwatchIdx = allSwatches.indexOf(value);
453
+ const selectedSwatchIdx = allSwatches.findIndex(
454
+ (c) => c.toLowerCase() === (value ?? "").toLowerCase()
455
+ );
440
456
 
441
457
  return (
442
458
  <div className={cn("space-y-3", className)}>
@@ -450,7 +466,7 @@ export function ColorPicker({
450
466
  className="flex flex-wrap gap-1.5"
451
467
  >
452
468
  {allSwatches.map((swatch, i) => {
453
- const isSelected = value === swatch;
469
+ const isSelected = (value ?? "").toLowerCase() === swatch.toLowerCase();
454
470
  const isRovingFocus = selectedSwatchIdx >= 0 ? isSelected : i === 0;
455
471
  return (
456
472
  <button