@behavioral-agentic-design-system/core 0.3.2 → 0.5.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.
@@ -0,0 +1,293 @@
1
+ "use client";
2
+
3
+ import { useState, useEffect, useRef, useCallback } from "react";
4
+ import { Tabs, TabsContent, TabsList, TabsPanels, TabsTrigger } from "@behavioral-agentic-design-system/core/components/ui/tabs";
5
+ import { ScrollArea, ScrollBar } from "@behavioral-agentic-design-system/core/components/ui/scroll-area";
6
+ import { Badge } from "@behavioral-agentic-design-system/core/components/ui/badge";
7
+ import { Button } from "@behavioral-agentic-design-system/core/components/ui/button";
8
+ import { Sparkles, Sun, Moon, BookOpen } from "lucide-react";
9
+ import { brand } from "@/brand.config";
10
+ import { CustomizeTab } from "@behavioral-agentic-design-system/core/components/customize-tab";
11
+ import { LayersTab } from "@behavioral-agentic-design-system/core/components/layers-tab";
12
+ import { HomeTab } from "@behavioral-agentic-design-system/core/components/home-tab";
13
+
14
+ /**
15
+ * Iframe-hosted preview surface. Listens for the parent's dark-mode state and
16
+ * mirrors it into its own document, so cross-fading tabs that hold iframes
17
+ * doesn't capture stale theming. Exported because most fork-supplied tabs
18
+ * will want to render an iframe of their own preview routes.
19
+ */
20
+ export function IframePreview({
21
+ src,
22
+ minWidth,
23
+ dark,
24
+ }: {
25
+ src: string;
26
+ minWidth?: string;
27
+ dark: boolean;
28
+ }) {
29
+ const iframeRef = useRef<HTMLIFrameElement>(null);
30
+ // Capture the initial src once on mount. After load, dark mode is applied via
31
+ // class toggle (syncDarkMode) — recomputing src on every dark change would
32
+ // reload the iframe and cause a flicker during the theme transition.
33
+ const initialSrcRef = useRef(`${src}${dark ? "?dark=1" : ""}`);
34
+ // Iframe is visually hidden until its document fires `load`. Otherwise the
35
+ // user sees a brief flash of unstyled content (HTML paints before CSS+fonts
36
+ // arrive). Once loaded, fade the iframe in over 250ms — the parent tab fade
37
+ // is also running, so cumulatively the first-click feels like a single
38
+ // smooth transition.
39
+ const [loaded, setLoaded] = useState(false);
40
+
41
+ const syncDarkMode = useCallback(() => {
42
+ try {
43
+ iframeRef.current?.contentDocument?.documentElement.classList.toggle("dark", dark);
44
+ } catch {}
45
+ }, [dark]);
46
+
47
+ useEffect(() => {
48
+ syncDarkMode();
49
+ }, [syncDarkMode]);
50
+
51
+ return (
52
+ <div className="size-full relative">
53
+ <ScrollArea className="size-full">
54
+ <div style={{ minWidth: minWidth || "100%" }} className="h-full">
55
+ <iframe
56
+ ref={iframeRef}
57
+ src={initialSrcRef.current}
58
+ onLoad={() => {
59
+ syncDarkMode();
60
+ setLoaded(true);
61
+ }}
62
+ className="w-full border-0 transition-opacity duration-300 ease-out"
63
+ style={{
64
+ height: "100vh",
65
+ minHeight: "800px",
66
+ opacity: loaded ? 1 : 0,
67
+ }}
68
+ />
69
+ </div>
70
+ {minWidth && <ScrollBar orientation="horizontal" />}
71
+ </ScrollArea>
72
+ </div>
73
+ );
74
+ }
75
+
76
+ /**
77
+ * Runtime context handed to each tab's render function. `dark` mirrors the
78
+ * Shell's host dark-mode state so iframe-hosted tabs can sync the iframe's
79
+ * `<html>` class without prop-drilling through the tab list.
80
+ */
81
+ export type ShellTabContext = {
82
+ dark: boolean;
83
+ };
84
+
85
+ /**
86
+ * One tab in the Shell. `render` is called once per first-visit and stays
87
+ * mounted afterwards (sticky-mount + cross-fade — see TabsPanels).
88
+ *
89
+ * `hidden: "md"` collapses the tab on screens below md breakpoint. Useful for
90
+ * dense iframe tabs (Dashboard, Mail) that don't read well on mobile.
91
+ */
92
+ export type ShellTab = {
93
+ value: string;
94
+ label: string;
95
+ hidden?: "md";
96
+ render: (ctx: ShellTabContext) => React.ReactNode;
97
+ };
98
+
99
+ export type ShellProps = {
100
+ tabs: ShellTab[];
101
+ /** Optional initial tab value. Defaults to the first tab. */
102
+ defaultTab?: string;
103
+ };
104
+
105
+ /**
106
+ * The canonical BADS preview tabs. Forks pass these directly when they want
107
+ * the default shape, or compose their own list (or splice into this one) when
108
+ * they need custom surfaces alongside the built-ins.
109
+ */
110
+ export const DEFAULT_TABS: ShellTab[] = [
111
+ { value: "home", label: "Home", render: () => <HomeTab /> },
112
+ { value: "components", label: "Components", render: ({ dark }) => <IframePreview dark={dark} src="/preview/components" /> },
113
+ { value: "cards", label: "Cards", render: ({ dark }) => <IframePreview dark={dark} src="/preview/cards" /> },
114
+ { value: "dashboard", label: "Dashboard", hidden: "md", render: ({ dark }) => <IframePreview dark={dark} src="/preview/dashboard" minWidth="1400px" /> },
115
+ { value: "mail", label: "Mail", hidden: "md", render: ({ dark }) => <IframePreview dark={dark} src="/preview/mail" minWidth="1300px" /> },
116
+ { value: "pricing", label: "Pricing", render: ({ dark }) => <IframePreview dark={dark} src="/preview/pricing" /> },
117
+ { value: "layers", label: "Layers", render: () => <LayersTab /> },
118
+ { value: "colors", label: "Customize", render: () => <CustomizeTab /> },
119
+ ];
120
+
121
+ /**
122
+ * The BADS preview shell — header (brand + Storybook + dark toggle) plus a
123
+ * sticky-mount cross-fade tab bar. Pass any `tabs` array to override the
124
+ * default surfaces; pass `DEFAULT_TABS` to keep the canonical layout.
125
+ *
126
+ * Forks that just want the default shell don't need to import this directly —
127
+ * they can re-export `@behavioral-agentic-design-system/core/app/page`. Use
128
+ * Shell directly when you need custom tabs (e.g. Pool, Meet, Athletes for a
129
+ * swim-club brand).
130
+ */
131
+ export function Shell({ tabs, defaultTab }: ShellProps) {
132
+ const initialTab = defaultTab ?? tabs[0]?.value ?? "home";
133
+ const [activeTab, setActiveTab] = useState(initialTab);
134
+ const [dark, setDark] = useState(false);
135
+ // Sticky-mount: once a tab has been viewed, keep it mounted forever so the
136
+ // iframe (or React tree) doesn't cold-load on every switch. TabsPanels
137
+ // cross-fades between mounted siblings, so subsequent switches are instant
138
+ // and flash-free. Only the first visit to a tab pays the load cost.
139
+ const [seen, setSeen] = useState<Set<string>>(() => new Set([initialTab]));
140
+ useEffect(() => {
141
+ setSeen((prev) => (prev.has(activeTab) ? prev : new Set(prev).add(activeTab)));
142
+ }, [activeTab]);
143
+
144
+ // Background preload: after the active tab has fully painted and idled,
145
+ // mount every other tab so they load silently while the user is reading
146
+ // the home tab. By the time someone clicks any other tab, its iframe is
147
+ // already loaded + styled — the tab switch becomes an instant cross-fade,
148
+ // no FOUC, no spinner. Uses requestIdleCallback when available so we don't
149
+ // compete with the home tab's first paint; falls back to a 1500ms
150
+ // setTimeout in Safari.
151
+ useEffect(() => {
152
+ const preloadAll = () => {
153
+ setSeen((prev) => {
154
+ const next = new Set(prev);
155
+ tabs.forEach((t) => next.add(t.value));
156
+ return next;
157
+ });
158
+ };
159
+ type RIC = (cb: () => void, opts?: { timeout?: number }) => number;
160
+ const w = window as Window & { requestIdleCallback?: RIC; cancelIdleCallback?: (id: number) => void };
161
+ if (w.requestIdleCallback) {
162
+ const id = w.requestIdleCallback(preloadAll, { timeout: 2500 });
163
+ return () => w.cancelIdleCallback?.(id);
164
+ }
165
+ const id = window.setTimeout(preloadAll, 1500);
166
+ return () => window.clearTimeout(id);
167
+ }, [tabs]);
168
+
169
+ useEffect(() => {
170
+ document.documentElement.classList.toggle("dark", dark);
171
+ }, [dark]);
172
+
173
+ const toggleDark = (event: React.MouseEvent) => {
174
+ const next = !dark;
175
+ const root = document.documentElement;
176
+ const prefersReduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
177
+ const supports = typeof document !== "undefined" && "startViewTransition" in document;
178
+
179
+ // Sync every iframe preview's dark class right now so its DOM matches the
180
+ // new theme at the same instant the parent does — otherwise the iframe lags
181
+ // behind React's useEffect and the transition captures stale iframe content.
182
+ const syncIframes = () => {
183
+ document.querySelectorAll("iframe").forEach((f) => {
184
+ try {
185
+ f.contentDocument?.documentElement.classList.toggle("dark", next);
186
+ } catch {}
187
+ });
188
+ };
189
+ const syncHost = () => {
190
+ root.classList.toggle("dark", next);
191
+ };
192
+
193
+ if (!supports || prefersReduce) {
194
+ syncHost();
195
+ syncIframes();
196
+ setDark(next);
197
+ return;
198
+ }
199
+ root.style.setProperty("--x", `${event.clientX}px`);
200
+ root.style.setProperty("--y", `${event.clientY}px`);
201
+ (document as Document & { startViewTransition: (cb: () => void) => void }).startViewTransition(() => {
202
+ syncHost();
203
+ syncIframes();
204
+ setDark(next);
205
+ });
206
+ };
207
+
208
+ const ctx: ShellTabContext = { dark };
209
+
210
+ return (
211
+ <div className="min-h-screen bg-background flex flex-col">
212
+ <header className="border-b bg-card shrink-0">
213
+ <div className="flex h-14 items-center px-6">
214
+ <div className="flex items-center gap-2">
215
+ <div
216
+ className="h-8 w-8 rounded-lg flex items-center justify-center bg-primary"
217
+ >
218
+ <Sparkles className="h-4 w-4 text-primary-foreground" />
219
+ </div>
220
+ <span className="text-lg font-semibold">{brand.name}</span>
221
+ <Badge variant="outline" className="ml-2 text-xs">{brand.tagline}</Badge>
222
+ </div>
223
+ <div className="ml-auto flex items-center gap-2">
224
+ <Button
225
+ asChild
226
+ variant="ghost"
227
+ size="sm"
228
+ className="group h-8 gap-1.5 border border-foreground/30 hover:!bg-foreground hover:!text-background hover:border-foreground"
229
+ title="Open Storybook (requires `pnpm dev` or `pnpm storybook` to be running on :6006)"
230
+ >
231
+ <a href="http://localhost:6006" target="_blank" rel="noreferrer" aria-label="Open Storybook in a new tab">
232
+ <BookOpen className="h-4 w-4 transition-all group-hover:scale-110" strokeWidth={1.5} />
233
+ <span className="text-xs font-medium">Storybook</span>
234
+ </a>
235
+ </Button>
236
+ <Button
237
+ variant="ghost"
238
+ size="icon"
239
+ onClick={toggleDark}
240
+ className="group size-8 border border-foreground/30 hover:!bg-foreground hover:!text-background hover:border-foreground"
241
+ aria-label={dark ? "Switch to light mode" : "Switch to dark mode"}
242
+ >
243
+ {dark ? (
244
+ <Sun className="h-4 w-4 transition-all group-hover:scale-110" />
245
+ ) : (
246
+ <Moon className="h-4 w-4 transition-all group-hover:scale-110" />
247
+ )}
248
+ </Button>
249
+ </div>
250
+ </div>
251
+ </header>
252
+
253
+ <Tabs
254
+ value={activeTab}
255
+ onValueChange={setActiveTab}
256
+ // Slower cross-fade between mounted panels — 260ms feels deliberate
257
+ // without dragging. Read by the duration utility on TabsPanels.
258
+ style={{ "--tabs-fade-duration": "260ms" } as React.CSSProperties}
259
+ className="flex-1 flex flex-col overflow-hidden"
260
+ >
261
+ <div className="mt-2 mb-1 flex w-full items-center px-4">
262
+ <TabsList className="bg-background text-muted-foreground inline-flex w-fit items-center justify-center rounded-full px-0">
263
+ {tabs.map((tab) => (
264
+ <TabsTrigger
265
+ key={tab.value}
266
+ value={tab.value}
267
+ className={`items-center justify-center rounded-full px-3 py-1.5 text-sm font-medium whitespace-nowrap transition-all data-[state=active]:bg-primary data-[state=active]:text-primary-foreground data-[state=active]:shadow-sm ${
268
+ tab.hidden === "md" ? "hidden md:inline-flex" : "inline-flex"
269
+ }`}
270
+ >
271
+ {tab.label}
272
+ </TabsTrigger>
273
+ ))}
274
+ </TabsList>
275
+ </div>
276
+
277
+ <section className="relative flex-1 min-h-0 w-full overflow-hidden">
278
+ <div className="absolute inset-x-4 top-1 bottom-4 isolate overflow-hidden rounded-lg">
279
+ <TabsPanels>
280
+ {tabs.map((tab) =>
281
+ seen.has(tab.value) ? (
282
+ <TabsContent key={tab.value} value={tab.value} forceMount>
283
+ {tab.render(ctx)}
284
+ </TabsContent>
285
+ ) : null,
286
+ )}
287
+ </TabsPanels>
288
+ </div>
289
+ </section>
290
+ </Tabs>
291
+ </div>
292
+ );
293
+ }
@@ -3,6 +3,7 @@
3
3
  import { useEffect, useState } from "react";
4
4
  import { ExternalLink, X, Sparkles } from "lucide-react";
5
5
  import { Button } from "@behavioral-agentic-design-system/core/components/ui/button";
6
+ import { storageKey, readMigrated } from "@behavioral-agentic-design-system/core/lib/storage";
6
7
 
7
8
  type CheckResult =
8
9
  | { ok: true; upstream?: true; skip?: string }
@@ -20,7 +21,7 @@ type CheckResult =
20
21
  }
21
22
  | { ok: true; error: string };
22
23
 
23
- const DISMISS_KEY = "BADS.updateDismissedFor";
24
+ const DISMISS_KEY = storageKey("updateDismissedFor");
24
25
 
25
26
  export function BadsUpdateBanner() {
26
27
  const [data, setData] = useState<CheckResult | null>(null);
@@ -28,7 +29,7 @@ export function BadsUpdateBanner() {
28
29
 
29
30
  useEffect(() => {
30
31
  try {
31
- setDismissedFor(window.localStorage.getItem(DISMISS_KEY));
32
+ setDismissedFor(readMigrated("updateDismissedFor"));
32
33
  } catch {}
33
34
  fetch("/api/bads-update-check")
34
35
  .then((r) => r.json())
@@ -30,13 +30,15 @@ import {
30
30
  } from "@behavioral-agentic-design-system/core/hooks/use-global-design-controls";
31
31
  import { Save, Check, AlertCircle, RotateCcw } from "lucide-react";
32
32
 
33
+ import { storageKey, readMigrated } from "@behavioral-agentic-design-system/core/lib/storage";
34
+
33
35
  const STORAGE_KEYS = {
34
- primaryColor: "BADS.primaryColor",
35
- sansFont: "BADS.sansFont",
36
- serifFont: "BADS.serifFont",
37
- monoFont: "BADS.monoFont",
38
- designControls: "BADS.designControls",
39
- typeScale: "BADS.typeScale",
36
+ primaryColor: storageKey("primaryColor"),
37
+ sansFont: storageKey("sansFont"),
38
+ serifFont: storageKey("serifFont"),
39
+ monoFont: storageKey("monoFont"),
40
+ designControls: storageKey("designControls"),
41
+ typeScale: storageKey("typeScale"),
40
42
  } as const;
41
43
 
42
44
  /**
@@ -45,7 +47,7 @@ const STORAGE_KEYS = {
45
47
  * (rather than the hardcoded defaults) so the "X customizations" counter
46
48
  * reflects changes *since the last save*, not changes *since first load*.
47
49
  */
48
- const SAVED_SNAPSHOT_KEY = "BADS.savedSnapshot";
50
+ const SAVED_SNAPSHOT_KEY = storageKey("savedSnapshot");
49
51
 
50
52
  /**
51
53
  * Custom brand colors persist in localStorage under this key (managed by
@@ -54,12 +56,12 @@ const SAVED_SNAPSHOT_KEY = "BADS.savedSnapshot";
54
56
  * color and hitting Save actually writes that color to tokens.json — without
55
57
  * it the active-color lookup would miss for any non-built-in id.
56
58
  */
57
- const CUSTOMS_KEY = "BADS.customPrimaryColors";
59
+ const CUSTOMS_KEY = storageKey("customPrimaryColors");
58
60
 
59
61
  function readCustomPrimaryColors(): Record<string, PrimaryColorOption> {
60
62
  if (typeof window === "undefined") return {};
61
63
  try {
62
- const raw = window.localStorage.getItem(CUSTOMS_KEY);
64
+ const raw = readMigrated("customPrimaryColors");
63
65
  if (!raw) return {};
64
66
  const parsed = JSON.parse(raw) as Record<string, PrimaryColorOption>;
65
67
  return parsed && typeof parsed === "object" ? parsed : {};
@@ -115,7 +117,7 @@ function readSnapshot(): Snapshot {
115
117
 
116
118
  function readSavedSnapshot(): Snapshot | null {
117
119
  if (typeof window === "undefined") return null;
118
- const raw = window.localStorage.getItem(SAVED_SNAPSHOT_KEY);
120
+ const raw = readMigrated("savedSnapshot");
119
121
  if (!raw) return null;
120
122
  try {
121
123
  return JSON.parse(raw) as Snapshot;
@@ -466,8 +466,8 @@ function ColorPalette() {
466
466
  </ColorSection>
467
467
 
468
468
  <ColorSection title="Charts">
469
- <ColorSwatch name="Chart 1" className="bg-chart-1" textClassName="text-neutral-900" variable="--chart-1" />
470
- <ColorSwatch name="Chart 2" className="bg-chart-2" textClassName="text-neutral-900" variable="--chart-2" />
469
+ <ColorSwatch name="Chart 1" className="bg-chart-1" textClassName="text-white" variable="--chart-1" />
470
+ <ColorSwatch name="Chart 2" className="bg-chart-2" textClassName="text-white" variable="--chart-2" />
471
471
  <ColorSwatch name="Chart 3" className="bg-chart-3" textClassName="text-white" variable="--chart-3" />
472
472
  <ColorSwatch name="Chart 4" className="bg-chart-4" textClassName="text-white" variable="--chart-4" />
473
473
  <ColorSwatch name="Chart 5" className="bg-chart-5" textClassName="text-white" variable="--chart-5" />
@@ -27,7 +27,9 @@ export const DESIGN_CONTROL_RANGES = {
27
27
  shadowOpacity: { min: 0, max: 0.5, step: 0.01, unit: "" },
28
28
  } as const;
29
29
 
30
- const STORAGE_KEY = "BADS.designControls";
30
+ import { storageKey, readMigrated } from "@behavioral-agentic-design-system/core/lib/storage";
31
+
32
+ const STORAGE_KEY = storageKey("designControls");
31
33
 
32
34
  function applyControls(controls: DesignControls) {
33
35
  if (typeof document === "undefined") return;
@@ -46,7 +48,7 @@ function applyControls(controls: DesignControls) {
46
48
 
47
49
  function readStored(): DesignControls {
48
50
  if (typeof window === "undefined") return DESIGN_CONTROL_DEFAULTS;
49
- const raw = window.localStorage.getItem(STORAGE_KEY);
51
+ const raw = readMigrated("designControls");
50
52
  if (!raw) return DESIGN_CONTROL_DEFAULTS;
51
53
  try {
52
54
  const parsed = JSON.parse(raw);
@@ -23,7 +23,9 @@ export const MONO_FONT_OPTIONS = {
23
23
 
24
24
  export type MonoFontKey = keyof typeof MONO_FONT_OPTIONS;
25
25
 
26
- const STORAGE_KEY = "BADS.monoFont";
26
+ import { storageKey, readMigrated } from "@behavioral-agentic-design-system/core/lib/storage";
27
+
28
+ const STORAGE_KEY = storageKey("monoFont");
27
29
  const DEFAULT: MonoFontKey = "jetbrains";
28
30
 
29
31
  function isValidKey(value: string | null): value is MonoFontKey {
@@ -43,7 +45,7 @@ export function useGlobalMonoFont() {
43
45
 
44
46
  useEffect(() => {
45
47
  if (typeof window === "undefined") return;
46
- const stored = window.localStorage.getItem(STORAGE_KEY);
48
+ const stored = readMigrated("monoFont");
47
49
  const next = isValidKey(stored) ? stored : DEFAULT;
48
50
  setFontState(next);
49
51
  applyFont(next);
@@ -148,8 +148,10 @@ export const BUILTIN_PRIMARY_COLORS: Record<string, PrimaryColorOption> = {
148
148
  neutral: SHADCN_NEUTRAL,
149
149
  };
150
150
 
151
- const COLOR_KEY = "BADS.primaryColor";
152
- const CUSTOMS_KEY = "BADS.customPrimaryColors";
151
+ import { storageKey, readMigrated } from "@behavioral-agentic-design-system/core/lib/storage";
152
+
153
+ const COLOR_KEY = storageKey("primaryColor");
154
+ const CUSTOMS_KEY = storageKey("customPrimaryColors");
153
155
  // First brand color (if any) wins as the default; otherwise fall back to shadcn neutral.
154
156
  const DEFAULT = brand.colors[0]?.id ?? "neutral";
155
157
 
@@ -184,7 +186,7 @@ function buildCustom(hex: string, label?: string): PrimaryColorOption {
184
186
  function readCustoms(): Record<string, PrimaryColorOption> {
185
187
  if (typeof window === "undefined") return {};
186
188
  try {
187
- const raw = window.localStorage.getItem(CUSTOMS_KEY);
189
+ const raw = readMigrated("customPrimaryColors");
188
190
  if (!raw) return {};
189
191
  const parsed = JSON.parse(raw) as Record<string, PrimaryColorOption>;
190
192
  if (!parsed || typeof parsed !== "object") return {};
@@ -213,7 +215,7 @@ function readCustoms(): Record<string, PrimaryColorOption> {
213
215
 
214
216
  function readColorKey(): string {
215
217
  if (typeof window === "undefined") return DEFAULT;
216
- return window.localStorage.getItem(COLOR_KEY) || DEFAULT;
218
+ return readMigrated("primaryColor") || DEFAULT;
217
219
  }
218
220
 
219
221
  function clearPrimaryColor() {
@@ -289,6 +291,15 @@ let bootstrapped = false;
289
291
  function bootstrap() {
290
292
  if (bootstrapped || typeof window === "undefined") return;
291
293
  bootstrapped = true;
294
+
295
+ // Fresh fork detection: if brand.colors is empty, clear any persisted
296
+ // custom colors from prior dev sessions. Ensures new forks always start
297
+ // with neutral (#1F1F1F) instead of inheriting dev-session customizations.
298
+ if (brand.colors.length === 0) {
299
+ window.localStorage.removeItem(CUSTOMS_KEY);
300
+ window.localStorage.removeItem(COLOR_KEY);
301
+ }
302
+
292
303
  const customs = readCustoms();
293
304
  const merged = { ...BUILTIN_PRIMARY_COLORS, ...customs };
294
305
  const stored = readColorKey();
@@ -40,7 +40,9 @@ export const SANS_FONT_OPTIONS: Record<string, SansFontOption> = {
40
40
 
41
41
  export type SansFontKey = string;
42
42
 
43
- const STORAGE_KEY = "BADS.sansFont";
43
+ import { storageKey, readMigrated } from "@behavioral-agentic-design-system/core/lib/storage";
44
+
45
+ const STORAGE_KEY = storageKey("sansFont");
44
46
  // First brand font (if any) wins as the default; otherwise Hyperlegible.
45
47
  const DEFAULT: SansFontKey = brand.fonts[0]?.id ?? "hyperlegible";
46
48
 
@@ -67,7 +69,7 @@ export function useGlobalSansFont() {
67
69
 
68
70
  useEffect(() => {
69
71
  if (typeof window === "undefined") return;
70
- const stored = window.localStorage.getItem(STORAGE_KEY);
72
+ const stored = readMigrated("sansFont");
71
73
  const next = isValidKey(stored) ? stored : DEFAULT;
72
74
  setFontState(next);
73
75
  applyFont(next);
@@ -23,7 +23,9 @@ export const SERIF_FONT_OPTIONS = {
23
23
 
24
24
  export type SerifFontKey = keyof typeof SERIF_FONT_OPTIONS;
25
25
 
26
- const STORAGE_KEY = "BADS.serifFont";
26
+ import { storageKey, readMigrated } from "@behavioral-agentic-design-system/core/lib/storage";
27
+
28
+ const STORAGE_KEY = storageKey("serifFont");
27
29
  const DEFAULT: SerifFontKey = "georgia";
28
30
 
29
31
  function isValidKey(value: string | null): value is SerifFontKey {
@@ -47,7 +49,7 @@ export function useGlobalSerifFont() {
47
49
 
48
50
  useEffect(() => {
49
51
  if (typeof window === "undefined") return;
50
- const stored = window.localStorage.getItem(STORAGE_KEY);
52
+ const stored = readMigrated("serifFont");
51
53
  const next = isValidKey(stored) ? stored : DEFAULT;
52
54
  setFontState(next);
53
55
  applyFont(next);
@@ -51,7 +51,9 @@ export type ThemePayload = {
51
51
  dark: ThemeVars;
52
52
  };
53
53
 
54
- const STORAGE_KEY = "BADS.theme";
54
+ import { storageKey, readMigrated } from "@behavioral-agentic-design-system/core/lib/storage";
55
+
56
+ const STORAGE_KEY = storageKey("theme");
55
57
 
56
58
  function isDarkMode(): boolean {
57
59
  if (typeof document === "undefined") return false;
@@ -168,7 +170,7 @@ export function exportThemeCss(): string {
168
170
 
169
171
  function readStored(): ThemePayload | null {
170
172
  if (typeof window === "undefined") return null;
171
- const raw = window.localStorage.getItem(STORAGE_KEY);
173
+ const raw = readMigrated("theme");
172
174
  if (!raw) return null;
173
175
  try {
174
176
  const parsed = JSON.parse(raw);
@@ -29,7 +29,9 @@ export const RATIO_PRESETS = [
29
29
  { value: 1.333, label: "Perfect Fourth" },
30
30
  ] as const;
31
31
 
32
- const STORAGE_KEY = "BADS.typeScale";
32
+ import { storageKey, readMigrated } from "@behavioral-agentic-design-system/core/lib/storage";
33
+
34
+ const STORAGE_KEY = storageKey("typeScale");
33
35
 
34
36
  /** The Tailwind text-* utilities this design system exposes, mapped to their
35
37
  * step offset from base. Steps are exponents on the ratio. */
@@ -67,7 +69,7 @@ function applyScale(scale: TypeScale) {
67
69
 
68
70
  function readStored(): TypeScale {
69
71
  if (typeof window === "undefined") return TYPE_SCALE_DEFAULTS;
70
- const raw = window.localStorage.getItem(STORAGE_KEY);
72
+ const raw = readMigrated("typeScale");
71
73
  if (!raw) return TYPE_SCALE_DEFAULTS;
72
74
  try {
73
75
  const parsed = JSON.parse(raw);
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { useLayoutEffect } from "react";
4
4
  import { TYPE_SCALE_DEFAULTS } from "./use-global-type-scale";
5
+ import { readMigrated } from "@behavioral-agentic-design-system/core/lib/storage";
5
6
 
6
7
  const STEPS = {
7
8
  "text-xs": -2,
@@ -22,7 +23,7 @@ function applyTypeScale() {
22
23
 
23
24
  // Try to read from localStorage, fall back to defaults
24
25
  try {
25
- const stored = localStorage.getItem("BADS.typeScale");
26
+ const stored = readMigrated("typeScale");
26
27
  if (stored) {
27
28
  const parsed = JSON.parse(stored);
28
29
  if (typeof parsed.base === "number") base = parsed.base;
@@ -7,14 +7,16 @@ import {
7
7
  THEME_EDITOR_STORAGE_KEY,
8
8
  } from "@behavioral-agentic-design-system/core/lib/theme-editor";
9
9
 
10
- const STORAGE_KEY = "BADS.tokenOverrides";
10
+ import { storageKey, readMigrated } from "@behavioral-agentic-design-system/core/lib/storage";
11
+
12
+ const STORAGE_KEY = storageKey("tokenOverrides");
11
13
 
12
14
  type Overrides = Record<string, string>;
13
15
 
14
16
  function read(): Overrides {
15
17
  if (typeof window === "undefined") return {};
16
18
  try {
17
- const raw = window.localStorage.getItem(STORAGE_KEY);
19
+ const raw = readMigrated("tokenOverrides");
18
20
  if (!raw) return {};
19
21
  const parsed = JSON.parse(raw) as Overrides;
20
22
  return parsed && typeof parsed === "object" ? parsed : {};