@behavioral-agentic-design-system/core 0.28.0 → 0.30.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.
- package/package.json +2 -2
- package/scripts/a11y-lint.cjs +78 -9
- package/scripts/build-tokens.cjs +273 -15
- package/scripts/wcag-audit.cjs +67 -11
- package/src/api/layers/file.ts +1 -0
- package/src/app/font-ready.tsx +6 -5
- package/src/app/layout.tsx +54 -3
- package/src/app/preview/components/page.tsx +5679 -3073
- package/src/app/preview/health/page.tsx +201 -0
- package/src/app/preview/layout.tsx +4 -1
- package/src/app/preview/showcase-filter.tsx +66 -0
- package/src/app/preview/tab-replay.tsx +63 -0
- package/src/app/shell.tsx +74 -18
- package/src/components/customize/save-bar.tsx +19 -6
- package/src/components/docs-tab.tsx +36 -24
- package/src/components/layers-tab.tsx +37 -5
- package/src/components/ui/alert.tsx +12 -0
- package/src/components/ui/badge.tsx +19 -0
- package/src/components/ui/button.tsx +10 -0
- package/src/components/ui/chat-marker.tsx +120 -0
- package/src/components/ui/checkbox.tsx +9 -1
- package/src/components/ui/close-button.tsx +71 -0
- package/src/components/ui/combobox.tsx +62 -3
- package/src/components/ui/container.tsx +65 -0
- package/src/components/ui/date-field.tsx +368 -0
- package/src/components/ui/drawer.tsx +334 -0
- package/src/components/ui/file-button.tsx +145 -0
- package/src/components/ui/floating-indicator.tsx +217 -0
- package/src/components/ui/format-byte.tsx +113 -0
- package/src/components/ui/index.ts +21 -0
- package/src/components/ui/input-clear-button.tsx +52 -0
- package/src/components/ui/input.tsx +39 -20
- package/src/components/ui/keyboard-shortcut.tsx +146 -0
- package/src/components/ui/loading-dots.tsx +99 -0
- package/src/components/ui/month-picker.tsx +296 -0
- package/src/components/ui/multi-select.tsx +35 -19
- package/src/components/ui/nav-link.tsx +200 -0
- package/src/components/ui/navigation-rail.tsx +256 -0
- package/src/components/ui/notification.tsx +20 -0
- package/src/components/ui/password-input.tsx +34 -1
- package/src/components/ui/progress.tsx +15 -1
- package/src/components/ui/prose.tsx +62 -0
- package/src/components/ui/questionnaire.tsx +334 -0
- package/src/components/ui/result.tsx +151 -0
- package/src/components/ui/rolling-number.tsx +1 -0
- package/src/components/ui/sidebar.tsx +5 -0
- package/src/components/ui/simple-grid.tsx +110 -0
- package/src/components/ui/skeleton.tsx +52 -3
- package/src/components/ui/squircle.tsx +274 -0
- package/src/components/ui/stack.tsx +105 -0
- package/src/components/ui/status-badge.tsx +93 -0
- package/src/components/ui/tabs.tsx +34 -7
- package/src/components/ui/tag.tsx +46 -5
- package/src/components/ui/textarea.tsx +5 -0
- package/src/components/ui/theme-icon.tsx +138 -0
- package/src/components/ui/timeline.tsx +27 -10
- package/src/components/ui/tooltip.tsx +12 -1
- package/src/components/ui/tree-select.tsx +386 -0
- package/src/components/ui/year-picker.tsx +307 -0
- package/src/data/docs-index.ts +12 -0
- package/src/hooks/use-global-primary-color.ts +57 -6
- package/src/lib/get-icon-color.ts +66 -0
- package/src/stories/Alert.stories.tsx +31 -1
- package/src/stories/Badge.stories.tsx +63 -6
- package/src/stories/Button.stories.tsx +3 -0
- package/src/stories/ChatMarker.stories.tsx +59 -0
- package/src/stories/Checkbox.stories.tsx +5 -0
- package/src/stories/CloseButton.stories.tsx +65 -0
- package/src/stories/Combobox.stories.tsx +74 -3
- package/src/stories/Container.stories.tsx +134 -0
- package/src/stories/DateField.stories.tsx +114 -0
- package/src/stories/Drawer.stories.tsx +211 -0
- package/src/stories/FileButton.stories.tsx +117 -0
- package/src/stories/FloatingIndicator.stories.tsx +343 -0
- package/src/stories/FormatByte.stories.tsx +142 -0
- package/src/stories/Input.stories.tsx +94 -0
- package/src/stories/InputClearButton.stories.tsx +53 -0
- package/src/stories/KeyboardShortcut.stories.tsx +87 -0
- package/src/stories/LoadingDots.stories.tsx +73 -0
- package/src/stories/MonthPicker.stories.tsx +99 -0
- package/src/stories/MultiSelect.stories.tsx +7 -1
- package/src/stories/NavLink.stories.tsx +213 -0
- package/src/stories/NavigationRail.stories.tsx +413 -0
- package/src/stories/Notification.stories.tsx +53 -0
- package/src/stories/PasswordInput.stories.tsx +21 -0
- package/src/stories/Progress.stories.tsx +38 -0
- package/src/stories/Prose.stories.tsx +232 -0
- package/src/stories/Questionnaire.stories.tsx +287 -0
- package/src/stories/Result.stories.tsx +145 -0
- package/src/stories/RollingNumber.stories.tsx +1 -1
- package/src/stories/Sidebar.stories.tsx +2 -0
- package/src/stories/SimpleGrid.stories.tsx +130 -0
- package/src/stories/Skeleton.stories.tsx +62 -1
- package/src/stories/Squircle.stories.tsx +127 -0
- package/src/stories/Stack.stories.tsx +140 -0
- package/src/stories/StatusBadge.stories.tsx +125 -0
- package/src/stories/Tabs.stories.tsx +56 -1
- package/src/stories/Tag.stories.tsx +31 -0
- package/src/stories/Textarea.stories.tsx +2 -0
- package/src/stories/ThemeIcon.stories.tsx +97 -0
- package/src/stories/Timeline.stories.tsx +69 -0
- package/src/stories/Tooltip.stories.tsx +18 -0
- package/src/stories/TreeSelect.stories.tsx +222 -0
- package/src/stories/YearPicker.stories.tsx +100 -0
- package/src/styles.css +289 -15
- package/src/tokens.json +96 -1
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { Badge } from "../../../components/ui/badge";
|
|
4
|
+
import { Card, CardContent, CardHeader, CardTitle } from "../../../components/ui/card";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* /preview/health — the self-healing layer's Observe surface (Phase A).
|
|
8
|
+
*
|
|
9
|
+
* One page of tiles rendered from the latest generated health report
|
|
10
|
+
* (ledgers/reports/health-<YYYY-MM>.json, produced by `pnpm health:report`)
|
|
11
|
+
* plus open drift-ledger rows. Server component: reads the fork's own files
|
|
12
|
+
* at request time, so every fork gets its own health view for free.
|
|
13
|
+
*
|
|
14
|
+
* The score is INFORMATIONAL — never a gate (Goodhart guard, see
|
|
15
|
+
* docs/specs/2026-08-21-self-healing-layer.md). Placement as a bare route
|
|
16
|
+
* (no shell tab) is deliberate: Sir hasn't picked tab-vs-home placement yet,
|
|
17
|
+
* and a URL-only surface is the reversible default.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
type HealthComponent = {
|
|
21
|
+
name: string;
|
|
22
|
+
score: number;
|
|
23
|
+
band: "healthy" | "watch" | "attention";
|
|
24
|
+
insufficientData: boolean;
|
|
25
|
+
dataPoints: number;
|
|
26
|
+
penalties: { source: string; points: number; why: string }[];
|
|
27
|
+
};
|
|
28
|
+
type HealthReport = {
|
|
29
|
+
generatedFor: string;
|
|
30
|
+
summary: {
|
|
31
|
+
components: number;
|
|
32
|
+
scored: number;
|
|
33
|
+
insufficientData: number;
|
|
34
|
+
avgScore: number | null;
|
|
35
|
+
bands: { healthy: number; watch: number; attention: number };
|
|
36
|
+
};
|
|
37
|
+
components: HealthComponent[];
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
function latestReport(): HealthReport | null {
|
|
41
|
+
const dir = path.join(process.cwd(), "ledgers", "reports");
|
|
42
|
+
if (!fs.existsSync(dir)) return null;
|
|
43
|
+
const file = fs
|
|
44
|
+
.readdirSync(dir)
|
|
45
|
+
.filter((f) => /^health-\d{4}-\d{2}\.json$/.test(f))
|
|
46
|
+
.sort()
|
|
47
|
+
.pop();
|
|
48
|
+
if (!file) return null;
|
|
49
|
+
try {
|
|
50
|
+
return JSON.parse(fs.readFileSync(path.join(dir, file), "utf8"));
|
|
51
|
+
} catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function openDrift(): { date: string; source: string; target: string; severity: string; signal: string }[] {
|
|
57
|
+
const p = path.join(process.cwd(), "ledgers", "drift.jsonl");
|
|
58
|
+
if (!fs.existsSync(p)) return [];
|
|
59
|
+
return fs
|
|
60
|
+
.readFileSync(p, "utf8")
|
|
61
|
+
.split("\n")
|
|
62
|
+
.filter(Boolean)
|
|
63
|
+
.map((l) => {
|
|
64
|
+
try {
|
|
65
|
+
return JSON.parse(l);
|
|
66
|
+
} catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
.filter((r): r is NonNullable<typeof r> => Boolean(r) && r.status === "open")
|
|
71
|
+
.slice(-20)
|
|
72
|
+
.reverse();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const BAND_STYLE: Record<string, string> = {
|
|
76
|
+
healthy: "text-success",
|
|
77
|
+
watch: "text-warning",
|
|
78
|
+
attention: "text-destructive",
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const dynamic = "force-dynamic";
|
|
82
|
+
|
|
83
|
+
export default function HealthPage() {
|
|
84
|
+
const report = latestReport();
|
|
85
|
+
const drift = openDrift();
|
|
86
|
+
|
|
87
|
+
if (!report) {
|
|
88
|
+
return (
|
|
89
|
+
<main className="mx-auto max-w-3xl p-8">
|
|
90
|
+
<h1 className="text-2xl font-semibold tracking-tight">System health</h1>
|
|
91
|
+
<p className="mt-4 text-sm text-muted-foreground">
|
|
92
|
+
No health report yet. Generate one with{" "}
|
|
93
|
+
<code className="font-mono text-foreground">pnpm health:report</code>, then reload.
|
|
94
|
+
</p>
|
|
95
|
+
</main>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const { summary } = report;
|
|
100
|
+
const flagged = report.components.filter((c) => !c.insufficientData && c.band !== "healthy");
|
|
101
|
+
const healthy = summary.bands.healthy;
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<main className="mx-auto max-w-6xl space-y-8 p-8">
|
|
105
|
+
<header className="space-y-1">
|
|
106
|
+
<h1 className="text-2xl font-semibold tracking-tight">System health</h1>
|
|
107
|
+
<p className="text-sm text-muted-foreground">
|
|
108
|
+
Generated {report.generatedFor} from the ledgers — informational, never a merge gate.
|
|
109
|
+
</p>
|
|
110
|
+
</header>
|
|
111
|
+
|
|
112
|
+
<section className="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
|
|
113
|
+
<Card>
|
|
114
|
+
<CardHeader className="pb-2">
|
|
115
|
+
<CardTitle className="text-sm text-muted-foreground">Average score</CardTitle>
|
|
116
|
+
</CardHeader>
|
|
117
|
+
<CardContent className="text-3xl font-semibold">{summary.avgScore ?? "–"}</CardContent>
|
|
118
|
+
</Card>
|
|
119
|
+
<Card>
|
|
120
|
+
<CardHeader className="pb-2">
|
|
121
|
+
<CardTitle className="text-sm text-muted-foreground">Healthy</CardTitle>
|
|
122
|
+
</CardHeader>
|
|
123
|
+
<CardContent className="text-3xl font-semibold text-success">{healthy}</CardContent>
|
|
124
|
+
</Card>
|
|
125
|
+
<Card>
|
|
126
|
+
<CardHeader className="pb-2">
|
|
127
|
+
<CardTitle className="text-sm text-muted-foreground">Watch / attention</CardTitle>
|
|
128
|
+
</CardHeader>
|
|
129
|
+
<CardContent className="text-3xl font-semibold">
|
|
130
|
+
<span className="text-warning">{summary.bands.watch}</span>
|
|
131
|
+
<span className="text-muted-foreground"> / </span>
|
|
132
|
+
<span className="text-destructive">{summary.bands.attention}</span>
|
|
133
|
+
</CardContent>
|
|
134
|
+
</Card>
|
|
135
|
+
<Card>
|
|
136
|
+
<CardHeader className="pb-2">
|
|
137
|
+
<CardTitle className="text-sm text-muted-foreground">Insufficient data</CardTitle>
|
|
138
|
+
</CardHeader>
|
|
139
|
+
<CardContent className="text-3xl font-semibold">{summary.insufficientData}</CardContent>
|
|
140
|
+
</Card>
|
|
141
|
+
</section>
|
|
142
|
+
|
|
143
|
+
<section className="space-y-3">
|
|
144
|
+
<h2 className="text-lg font-semibold">Needs attention ({flagged.length})</h2>
|
|
145
|
+
{flagged.length === 0 ? (
|
|
146
|
+
<p className="text-sm text-muted-foreground">Every scored component is in the healthy band.</p>
|
|
147
|
+
) : (
|
|
148
|
+
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
|
149
|
+
{flagged
|
|
150
|
+
.sort((a, b) => a.score - b.score)
|
|
151
|
+
.map((c) => (
|
|
152
|
+
<Card key={c.name} className="overflow-hidden">
|
|
153
|
+
<CardHeader className="flex flex-row items-center justify-between pb-2">
|
|
154
|
+
<CardTitle className="min-w-0 truncate text-base" title={c.name}>
|
|
155
|
+
{c.name}
|
|
156
|
+
</CardTitle>
|
|
157
|
+
<span className={`text-2xl font-semibold ${BAND_STYLE[c.band]}`}>{c.score}</span>
|
|
158
|
+
</CardHeader>
|
|
159
|
+
<CardContent>
|
|
160
|
+
<ul className="space-y-1">
|
|
161
|
+
{c.penalties.slice(0, 3).map((p, i) => (
|
|
162
|
+
<li key={i} className="text-sm text-muted-foreground">
|
|
163
|
+
<span className="font-mono text-xs">−{p.points}</span> {p.why}
|
|
164
|
+
</li>
|
|
165
|
+
))}
|
|
166
|
+
</ul>
|
|
167
|
+
</CardContent>
|
|
168
|
+
</Card>
|
|
169
|
+
))}
|
|
170
|
+
</div>
|
|
171
|
+
)}
|
|
172
|
+
</section>
|
|
173
|
+
|
|
174
|
+
<section className="space-y-3">
|
|
175
|
+
<h2 className="text-lg font-semibold">Open drift ({drift.length})</h2>
|
|
176
|
+
{drift.length === 0 ? (
|
|
177
|
+
<p className="text-sm text-muted-foreground">
|
|
178
|
+
Drift ledger is clear. Rows land here from the token-intent lint and month-over-month score drops.
|
|
179
|
+
</p>
|
|
180
|
+
) : (
|
|
181
|
+
<Card>
|
|
182
|
+
<CardContent className="divide-y divide-border p-0">
|
|
183
|
+
{drift.map((d, i) => (
|
|
184
|
+
<div key={i} className="flex items-start gap-3 p-4">
|
|
185
|
+
<Badge variant={d.severity === "high" ? "destructive" : "secondary"}>{d.source}</Badge>
|
|
186
|
+
<div className="min-w-0">
|
|
187
|
+
<p className="truncate text-sm font-medium" title={d.target}>
|
|
188
|
+
{d.target}
|
|
189
|
+
</p>
|
|
190
|
+
<p className="text-sm text-muted-foreground">{d.signal}</p>
|
|
191
|
+
</div>
|
|
192
|
+
<span className="ml-auto shrink-0 text-sm text-muted-foreground">{d.date}</span>
|
|
193
|
+
</div>
|
|
194
|
+
))}
|
|
195
|
+
</CardContent>
|
|
196
|
+
</Card>
|
|
197
|
+
)}
|
|
198
|
+
</section>
|
|
199
|
+
</main>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
@@ -2,12 +2,15 @@ import "@/styles/globals.css";
|
|
|
2
2
|
import { TooltipProvider } from "@behavioral-agentic-design-system/core/components/ui/tooltip";
|
|
3
3
|
import DarkModeClient from "./dark-mode-client";
|
|
4
4
|
import GlobalFontClient from "./global-font-client";
|
|
5
|
+
import { TabReplay } from "./tab-replay";
|
|
5
6
|
|
|
6
7
|
export default function PreviewLayout({ children }: { children: React.ReactNode }) {
|
|
7
8
|
return (
|
|
8
9
|
<TooltipProvider>
|
|
9
10
|
<GlobalFontClient />
|
|
10
|
-
<DarkModeClient>
|
|
11
|
+
<DarkModeClient>
|
|
12
|
+
<TabReplay>{children}</TabReplay>
|
|
13
|
+
</DarkModeClient>
|
|
11
14
|
</TooltipProvider>
|
|
12
15
|
);
|
|
13
16
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Lets a consuming fork decide which primitives its Components tab shows.
|
|
5
|
+
*
|
|
6
|
+
* The problem this solves is a release problem, not a rendering one. Core's Components tab renders
|
|
7
|
+
* every primitive core ships — 129 sections and growing nightly. Because forks import that page
|
|
8
|
+
* directly, publishing a release drops every newly-added component straight into every client's
|
|
9
|
+
* design system, unannounced. From the client's side a routine dependency bump looks like someone
|
|
10
|
+
* added thirty components to their product overnight, and the catalogue stops reading as a set of
|
|
11
|
+
* deliberate choices.
|
|
12
|
+
*
|
|
13
|
+
* Wrapping the page in a provider inverts that: the fork names what belongs in its system, and
|
|
14
|
+
* anything else core ships stays installed and importable but invisible until the fork asks for it.
|
|
15
|
+
* A component earns its place by being listed.
|
|
16
|
+
*
|
|
17
|
+
* import { ShowcaseFilterProvider } from "@behavioral-agentic-design-system/core/app/preview/showcase-filter";
|
|
18
|
+
* import CorePrimitives from "@behavioral-agentic-design-system/core/app/preview/components/page";
|
|
19
|
+
*
|
|
20
|
+
* <ShowcaseFilterProvider include={["buttons", "inputs", "form-controls"]}>
|
|
21
|
+
* <CorePrimitives />
|
|
22
|
+
* </ShowcaseFilterProvider>
|
|
23
|
+
*
|
|
24
|
+
* Ids are slugified section titles ("Form controls" → "form-controls"). Every section renders a
|
|
25
|
+
* `data-section-id` attribute, so the available ids can be read straight off the page in devtools
|
|
26
|
+
* rather than guessed from source.
|
|
27
|
+
*
|
|
28
|
+
* With no provider the value is "all", so this is backwards compatible: an existing fork that
|
|
29
|
+
* upgrades sees no change until it opts in.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import { createContext, useContext, type ReactNode } from "react";
|
|
33
|
+
|
|
34
|
+
export type ShowcaseInclude = readonly string[] | "all";
|
|
35
|
+
|
|
36
|
+
const ShowcaseFilterContext = createContext<ShowcaseInclude>("all");
|
|
37
|
+
|
|
38
|
+
/** Slugify a section title into its stable id. Shared so filtering and rendering cannot disagree. */
|
|
39
|
+
export function sectionId(title: string): string {
|
|
40
|
+
return title
|
|
41
|
+
.toLowerCase()
|
|
42
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
43
|
+
.replace(/(^-|-$)/g, "");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function ShowcaseFilterProvider({
|
|
47
|
+
include,
|
|
48
|
+
children,
|
|
49
|
+
}: {
|
|
50
|
+
/** Section ids to show, or "all". */
|
|
51
|
+
include: ShowcaseInclude;
|
|
52
|
+
children: ReactNode;
|
|
53
|
+
}) {
|
|
54
|
+
return (
|
|
55
|
+
<ShowcaseFilterContext.Provider value={include}>
|
|
56
|
+
{children}
|
|
57
|
+
</ShowcaseFilterContext.Provider>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Whether a section should render. True when no provider is mounted. */
|
|
62
|
+
export function useSectionVisible(id: string): boolean {
|
|
63
|
+
const include = useContext(ShowcaseFilterContext);
|
|
64
|
+
if (include === "all") return true;
|
|
65
|
+
return include.includes(id);
|
|
66
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Replays the tab's entrance animation every time the tab is (re-)activated.
|
|
5
|
+
*
|
|
6
|
+
* The preview tabs are sticky-mounted iframes (see shell.tsx / TabsPanels): a
|
|
7
|
+
* tab mounts once and stays in the DOM so switching back is instant. The side
|
|
8
|
+
* effect is that the charts inside animate exactly once — on that first mount,
|
|
9
|
+
* often while the tab is still hidden during preload — and never again. So on
|
|
10
|
+
* every subsequent visit the content just sits there, fully drawn, with no
|
|
11
|
+
* entrance.
|
|
12
|
+
*
|
|
13
|
+
* This wrapper watches the host tab's `data-state` (read from the parent
|
|
14
|
+
* TabsContent via `window.frameElement`, same-origin) and bumps a remount key
|
|
15
|
+
* each time the tab transitions inactive → active. Remounting the subtree makes
|
|
16
|
+
* every chart re-run its recharts entrance (and any mount-time motion), so the
|
|
17
|
+
* page animates in fresh each time you load the tab — including the first real
|
|
18
|
+
* view, which fixes the "animation finished during hidden preload" case too.
|
|
19
|
+
*
|
|
20
|
+
* Guards:
|
|
21
|
+
* - `prefers-reduced-motion: reduce` → never replays (no observer, no remount).
|
|
22
|
+
* - Direct visit (not inside a tab iframe) → renders once, no replay.
|
|
23
|
+
* - Only inactive → active transitions remount; leaving a tab does nothing.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import * as React from "react";
|
|
27
|
+
import { prefersReducedMotion } from "../../hooks/use-reduced-motion";
|
|
28
|
+
|
|
29
|
+
export function TabReplay({ children }: { children: React.ReactNode }) {
|
|
30
|
+
const [gen, setGen] = React.useState(0);
|
|
31
|
+
|
|
32
|
+
React.useEffect(() => {
|
|
33
|
+
if (prefersReducedMotion()) return;
|
|
34
|
+
|
|
35
|
+
let frameEl: Element | null = null;
|
|
36
|
+
try {
|
|
37
|
+
frameEl = window.frameElement;
|
|
38
|
+
} catch {
|
|
39
|
+
frameEl = null;
|
|
40
|
+
}
|
|
41
|
+
// Not inside the tab iframe (e.g. /preview/cards opened directly): mount
|
|
42
|
+
// once and let the charts animate normally — nothing to replay against.
|
|
43
|
+
if (!frameEl) return;
|
|
44
|
+
|
|
45
|
+
const panel = frameEl.closest('[data-slot="tabs-content"], [role="tabpanel"]');
|
|
46
|
+
if (!panel) return;
|
|
47
|
+
|
|
48
|
+
let wasActive = panel.getAttribute("data-state") === "active";
|
|
49
|
+
const obs = new MutationObserver(() => {
|
|
50
|
+
const active = panel.getAttribute("data-state") === "active";
|
|
51
|
+
// Remount only on the inactive → active edge so the entrance replays once
|
|
52
|
+
// per visit, not on every attribute mutation.
|
|
53
|
+
if (active && !wasActive) setGen((g) => g + 1);
|
|
54
|
+
wasActive = active;
|
|
55
|
+
});
|
|
56
|
+
obs.observe(panel, { attributes: true, attributeFilter: ["data-state"] });
|
|
57
|
+
return () => obs.disconnect();
|
|
58
|
+
}, []);
|
|
59
|
+
|
|
60
|
+
// A keyed fragment: changing the key remounts the whole subtree in a single
|
|
61
|
+
// React commit (no blank frame), so charts re-init and re-animate.
|
|
62
|
+
return <React.Fragment key={gen}>{children}</React.Fragment>;
|
|
63
|
+
}
|
package/src/app/shell.tsx
CHANGED
|
@@ -84,6 +84,16 @@ export function IframePreview({
|
|
|
84
84
|
}, [dark]);
|
|
85
85
|
|
|
86
86
|
useEffect(() => {
|
|
87
|
+
// Skip while hidden inside an inactive tab panel. This passive effect
|
|
88
|
+
// fires after first paint — mid view-transition — and retheming a heavy
|
|
89
|
+
// hidden document there stutters the dark/light iris wipe. The Shell's
|
|
90
|
+
// toggleDark converges every hidden iframe after the transition finishes,
|
|
91
|
+
// so nothing stays stale (see the retheme-strategy comment in toggleDark).
|
|
92
|
+
if (
|
|
93
|
+
iframeRef.current?.closest('[data-slot="tabs-content"]')?.getAttribute("data-state") ===
|
|
94
|
+
"inactive"
|
|
95
|
+
)
|
|
96
|
+
return;
|
|
87
97
|
syncDarkMode();
|
|
88
98
|
}, [syncDarkMode]);
|
|
89
99
|
|
|
@@ -364,40 +374,86 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
364
374
|
const prefersReduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
365
375
|
const supports = typeof document !== "undefined" && "startViewTransition" in document;
|
|
366
376
|
|
|
367
|
-
//
|
|
368
|
-
//
|
|
369
|
-
//
|
|
370
|
-
//
|
|
371
|
-
//
|
|
372
|
-
//
|
|
373
|
-
//
|
|
374
|
-
//
|
|
375
|
-
//
|
|
376
|
-
//
|
|
377
|
-
|
|
377
|
+
// Iframe retheme is split by visibility. Only iframes in the ACTIVE tab
|
|
378
|
+
// panel paint into the view-transition snapshot, so only they sync
|
|
379
|
+
// synchronously inside the callback. Hidden panels (opacity-0,
|
|
380
|
+
// sticky-mounted) are invisible for the whole wipe — their retheme is
|
|
381
|
+
// deferred to transition.finished, where the repaint is free because
|
|
382
|
+
// nothing on screen references those layers.
|
|
383
|
+
//
|
|
384
|
+
// History, because this code has flip-flopped: retheming hidden iframes
|
|
385
|
+
// via the per-IframePreview useEffect stuttered the wipe (passive effects
|
|
386
|
+
// fire after first paint, so the repaint landed mid-animation — fixed
|
|
387
|
+
// 8c9588c by syncing everything up front). Then the Components preview
|
|
388
|
+
// grew past 120 sections and the up-front sync itself started starving
|
|
389
|
+
// the wipe's first ~400ms of frames. Deferred-until-AFTER-the-transition
|
|
390
|
+
// is the only window where a heavy retheme can't steal wipe frames.
|
|
391
|
+
// IframePreview's own effect skips hidden panels for the same reason.
|
|
392
|
+
//
|
|
393
|
+
// The deferred pass reads the host classList instead of capturing `next`,
|
|
394
|
+
// so rapid double-toggles converge every iframe on whatever theme the
|
|
395
|
+
// host settled on. Known gap: switching tabs mid-wipe can show the old
|
|
396
|
+
// theme in the incoming panel until `finished` lands (≤ ~0.4s).
|
|
397
|
+
const inInactivePanel = (f: HTMLIFrameElement) =>
|
|
398
|
+
f.closest('[data-slot="tabs-content"]')?.getAttribute("data-state") === "inactive";
|
|
399
|
+
const syncIframe = (f: HTMLIFrameElement, isDark: boolean) => {
|
|
400
|
+
try {
|
|
401
|
+
f.contentDocument?.documentElement.classList.toggle("dark", isDark);
|
|
402
|
+
} catch {}
|
|
403
|
+
};
|
|
404
|
+
const syncVisibleIframes = () => {
|
|
378
405
|
document.querySelectorAll<HTMLIFrameElement>("iframe").forEach((f) => {
|
|
379
|
-
|
|
380
|
-
f.contentDocument?.documentElement.classList.toggle("dark", next);
|
|
381
|
-
} catch {}
|
|
406
|
+
if (!inInactivePanel(f)) syncIframe(f, next);
|
|
382
407
|
});
|
|
383
408
|
};
|
|
409
|
+
const syncAllIframesToHost = () => {
|
|
410
|
+
const isDark = root.classList.contains("dark");
|
|
411
|
+
document.querySelectorAll<HTMLIFrameElement>("iframe").forEach((f) => syncIframe(f, isDark));
|
|
412
|
+
};
|
|
384
413
|
const syncHost = () => {
|
|
385
414
|
root.classList.toggle("dark", next);
|
|
386
415
|
};
|
|
387
416
|
|
|
388
417
|
if (!supports || prefersReduce) {
|
|
389
418
|
syncHost();
|
|
390
|
-
|
|
419
|
+
syncAllIframesToHost();
|
|
391
420
|
setDark(next);
|
|
392
421
|
return;
|
|
393
422
|
}
|
|
394
423
|
root.style.setProperty("--x", `${event.clientX}px`);
|
|
395
424
|
root.style.setProperty("--y", `${event.clientY}px`);
|
|
396
|
-
|
|
425
|
+
// Exact wipe radius: distance from the click to the farthest viewport
|
|
426
|
+
// corner, +3%. The old blanket 150vmax always covered, but on wide
|
|
427
|
+
// screens it overshot the needed radius by ~40%, so the eased timeline
|
|
428
|
+
// spent its whole tail growing an invisible circle — the far side of the
|
|
429
|
+
// screen swept past in ~1 frame (12ms) and read as an end-of-wipe pop.
|
|
430
|
+
// With +3%, the farthest corner is covered right where ease-in-out's
|
|
431
|
+
// deceleration flattens (~t=0.9): the far-side crossing stretches to
|
|
432
|
+
// ~3-4 frames of visible, slowing sweep, and the last ~10% of the
|
|
433
|
+
// timeline is dropped-frame insurance before teardown. Keep the buffer
|
|
434
|
+
// small — every extra % here steals deceleration from the visible sweep
|
|
435
|
+
// (1.12 was tried first: crossing stayed a 2-frame blink).
|
|
436
|
+
// (See the theme-reveal comment in build-tokens.cjs.)
|
|
437
|
+
const radius = Math.hypot(
|
|
438
|
+
Math.max(event.clientX, window.innerWidth - event.clientX),
|
|
439
|
+
Math.max(event.clientY, window.innerHeight - event.clientY)
|
|
440
|
+
);
|
|
441
|
+
root.style.setProperty("--r", `${Math.ceil(radius * 1.03)}px`);
|
|
442
|
+
const transition = (document as Document & {
|
|
443
|
+
startViewTransition: (cb: () => void) => { finished: Promise<void> };
|
|
444
|
+
}).startViewTransition(() => {
|
|
397
445
|
syncHost();
|
|
398
|
-
|
|
446
|
+
syncVisibleIframes();
|
|
399
447
|
setDark(next);
|
|
400
448
|
});
|
|
449
|
+
// `finished` rejects when a newer transition skips this one — converge
|
|
450
|
+
// either way. Two rAFs past `finished` so the overlay-teardown frame
|
|
451
|
+
// paints before the hidden-iframe recalc lands: with the exact radius the
|
|
452
|
+
// teardown now coincides with the visually complete wipe, and a blocked
|
|
453
|
+
// teardown frame would hold the last animation frame on screen.
|
|
454
|
+
const convergeAfterTeardown = () =>
|
|
455
|
+
requestAnimationFrame(() => requestAnimationFrame(syncAllIframesToHost));
|
|
456
|
+
transition.finished.then(convergeAfterTeardown, convergeAfterTeardown);
|
|
401
457
|
};
|
|
402
458
|
|
|
403
459
|
const ctx: ShellTabContext = { dark, goToTab: selectTab };
|
|
@@ -588,7 +644,7 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
588
644
|
</TabsList>
|
|
589
645
|
</div>
|
|
590
646
|
|
|
591
|
-
<section id="main-content" tabIndex={-1} className="relative flex-1 min-h-0 w-full overflow-hidden">
|
|
647
|
+
<section id="main-content" tabIndex={-1} className="relative flex-1 min-h-0 w-full overflow-hidden scrollbar-gutter-stable">
|
|
592
648
|
<div className="absolute inset-x-4 top-1 bottom-4 isolate overflow-hidden rounded-lg">
|
|
593
649
|
<TabsPanels>
|
|
594
650
|
{tabs.map((tab) => {
|
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
readMigrated,
|
|
36
36
|
clearAllCustomization,
|
|
37
37
|
} from "@behavioral-agentic-design-system/core/lib/storage";
|
|
38
|
+
import { brand, type BrandDefaults } from "@/brand.config";
|
|
38
39
|
|
|
39
40
|
const STORAGE_KEYS = {
|
|
40
41
|
primaryColor: storageKey("primaryColor"),
|
|
@@ -83,10 +84,22 @@ type Snapshot = {
|
|
|
83
84
|
typeScale: TypeScale | null;
|
|
84
85
|
};
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
/**
|
|
88
|
+
* A fork's real shipped defaults (from brand.config → `defaults`) take priority
|
|
89
|
+
* over BADS' generic baseline. Without this, a fork whose bootstrapped theme
|
|
90
|
+
* differs from hyperlegible/georgia/jetbrains/blue/18·1.125 shows a permanent,
|
|
91
|
+
* un-clearable phantom diff count from first load — the counter compares live
|
|
92
|
+
* state against a baseline the fork never actually ships. `brand.defaults` is
|
|
93
|
+
* null on upstream BADS (its shipped defaults ARE these values), so this is a
|
|
94
|
+
* no-op here and only activates for forks that declare their own defaults.
|
|
95
|
+
*/
|
|
96
|
+
const FORK_DEFAULTS: BrandDefaults = brand.defaults ?? {};
|
|
97
|
+
const SANS_DEFAULT: SansFontKey = (FORK_DEFAULTS.sansFont as SansFontKey) ?? "hyperlegible";
|
|
98
|
+
const SERIF_DEFAULT: SerifFontKey = (FORK_DEFAULTS.serifFont as SerifFontKey) ?? "georgia";
|
|
99
|
+
const MONO_DEFAULT: MonoFontKey = (FORK_DEFAULTS.monoFont as MonoFontKey) ?? "jetbrains";
|
|
100
|
+
const PRIMARY_DEFAULT: PrimaryColorKey = (FORK_DEFAULTS.primaryColor as PrimaryColorKey) ?? "blue";
|
|
101
|
+
const TYPE_SCALE_BASE_DEFAULT = FORK_DEFAULTS.typeScale?.base ?? TYPE_SCALE_DEFAULTS.base;
|
|
102
|
+
const TYPE_SCALE_RATIO_DEFAULT = FORK_DEFAULTS.typeScale?.ratio ?? TYPE_SCALE_DEFAULTS.ratio;
|
|
90
103
|
|
|
91
104
|
function readSnapshot(): Snapshot {
|
|
92
105
|
if (typeof window === "undefined") {
|
|
@@ -147,8 +160,8 @@ function diffCount(s: Snapshot, saved: Snapshot | null): number {
|
|
|
147
160
|
if (s.serifFont && differs(s.serifFont, saved?.serifFont, SERIF_DEFAULT)) count++;
|
|
148
161
|
if (s.monoFont && differs(s.monoFont, saved?.monoFont, MONO_DEFAULT)) count++;
|
|
149
162
|
if (s.typeScale) {
|
|
150
|
-
const baseTarget = saved?.typeScale?.base ??
|
|
151
|
-
const ratioTarget = saved?.typeScale?.ratio ??
|
|
163
|
+
const baseTarget = saved?.typeScale?.base ?? TYPE_SCALE_BASE_DEFAULT;
|
|
164
|
+
const ratioTarget = saved?.typeScale?.ratio ?? TYPE_SCALE_RATIO_DEFAULT;
|
|
152
165
|
if (s.typeScale.base !== baseTarget) count++;
|
|
153
166
|
if (s.typeScale.ratio !== ratioTarget) count++;
|
|
154
167
|
}
|
|
@@ -192,11 +192,11 @@ export function DocsTab() {
|
|
|
192
192
|
};
|
|
193
193
|
|
|
194
194
|
return (
|
|
195
|
-
<div data-slot="docs-tab" className="size-full flex gap-0">
|
|
195
|
+
<div data-slot="docs-tab" className="size-full flex min-h-0 gap-0">
|
|
196
196
|
{/* Sidebar — collapsible groups, doc rows, search affordance. */}
|
|
197
197
|
<aside
|
|
198
198
|
data-slot="docs-sidebar"
|
|
199
|
-
className="hidden w-72 shrink-0 flex-col border-r border-border bg-card md:flex"
|
|
199
|
+
className="hidden h-full min-h-0 w-72 shrink-0 flex-col border-r border-border bg-card md:flex"
|
|
200
200
|
aria-label="Documentation index"
|
|
201
201
|
>
|
|
202
202
|
<div className="flex shrink-0 items-center justify-between gap-2 border-b border-border px-4 py-3">
|
|
@@ -228,7 +228,7 @@ export function DocsTab() {
|
|
|
228
228
|
className="h-9 text-sm"
|
|
229
229
|
/>
|
|
230
230
|
</div>
|
|
231
|
-
<nav className="min-h-0 flex-1 overflow-y-auto px-2 py-3" aria-label="Documentation groups">
|
|
231
|
+
<nav className="min-h-0 flex-1 overflow-y-auto overscroll-contain [-webkit-overflow-scrolling:touch] px-2 py-3" aria-label="Documentation groups">
|
|
232
232
|
{sidebarGroups.length === 0 ? (
|
|
233
233
|
<p className="px-2 py-4 text-xs text-muted-foreground">
|
|
234
234
|
No docs match this filter.
|
|
@@ -247,32 +247,44 @@ export function DocsTab() {
|
|
|
247
247
|
</aside>
|
|
248
248
|
|
|
249
249
|
{/* Reading pane (and mobile top-bar with Browse) */}
|
|
250
|
+
{/* Grid (not flex) column: `minmax(0,1fr)` on the body row is the reliable
|
|
251
|
+
cross-browser "header + scrolling body" pattern. Safari treats a flex
|
|
252
|
+
item's stretched height as indefinite and lets a `flex-1 overflow-auto`
|
|
253
|
+
child grow to its content instead of scrolling ("scrolls a little but
|
|
254
|
+
not all the way"); a grid `minmax(0,1fr)` track bounds the body to the
|
|
255
|
+
remaining space so it scrolls. Row 1 (auto) holds the header group; the
|
|
256
|
+
mobile bar collapses to nothing on desktop, so the scroller always sits
|
|
257
|
+
in row 2. gridTemplateRows is inline to sidestep any Tailwind
|
|
258
|
+
arbitrary-value comma issue. */}
|
|
250
259
|
<main
|
|
251
260
|
data-slot="docs-reading-pane"
|
|
252
|
-
className="
|
|
261
|
+
className="grid h-full min-h-0 min-w-0 flex-1 bg-background"
|
|
262
|
+
style={{ gridTemplateRows: "auto minmax(0, 1fr)" }}
|
|
253
263
|
aria-label="Documentation reader"
|
|
254
264
|
>
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
<
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
265
|
+
<div className="min-w-0">
|
|
266
|
+
{/* Mobile-only top bar with the Browse affordance. */}
|
|
267
|
+
<div className="flex shrink-0 items-center gap-2 border-b border-border bg-card px-4 py-3 md:hidden">
|
|
268
|
+
<BookOpen className="size-4 text-primary" strokeWidth={1.5} />
|
|
269
|
+
<span className="text-sm font-semibold">Docs</span>
|
|
270
|
+
<Badge variant="secondary" className="ml-1">
|
|
271
|
+
{DOCS_TOTAL}
|
|
272
|
+
</Badge>
|
|
273
|
+
<Button
|
|
274
|
+
variant="outline"
|
|
275
|
+
size="sm"
|
|
276
|
+
className="ml-auto h-9 gap-2 px-3"
|
|
277
|
+
onClick={() => setPaletteOpen(true)}
|
|
278
|
+
aria-label="Open docs search"
|
|
279
|
+
>
|
|
280
|
+
<Search className="size-3.5" strokeWidth={1.5} />
|
|
281
|
+
<span className="text-sm">Browse</span>
|
|
282
|
+
</Button>
|
|
283
|
+
</div>
|
|
273
284
|
|
|
274
|
-
|
|
275
|
-
|
|
285
|
+
<ReadingHeader activeEntry={activeEntry} activePath={activePath} />
|
|
286
|
+
</div>
|
|
287
|
+
<div className="min-h-0 overflow-y-auto overscroll-contain [-webkit-overflow-scrolling:touch] px-6 py-8 lg:px-10">
|
|
276
288
|
{loading ? (
|
|
277
289
|
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
|
278
290
|
<Loader2 className="size-4 animate-spin" strokeWidth={1.5} />
|