@behavioral-agentic-design-system/core 0.3.2 → 0.4.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@behavioral-agentic-design-system/core",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "description": "BADS core — tokens, shadcn/ui components, and the BADS template shell (app routes, customize tab, theme hooks). Forks consume this and re-export, keeping client repos to ~30 lines of glue.",
5
5
  "license": "ISC",
6
6
  "type": "module",
@@ -209,9 +209,12 @@ const themeInline = `@theme inline {
209
209
  --color-sidebar-border: var(--sidebar-border);
210
210
  --color-sidebar-ring: var(--sidebar-ring);
211
211
 
212
- --font-sans: var(--font-sans);
213
- --font-mono: var(--font-mono);
214
- --font-serif: var(--font-serif);
212
+ /* font-sans/serif/mono intentionally NOT mapped here. Tailwind v4
213
+ compiles @theme inline self-references into a :root rule of the
214
+ same shape, which collides with the unlayered :root that sets the
215
+ actual font stack and resolves to an empty circular reference. The
216
+ :root above already defines --font-sans, and Tailwind picks it up
217
+ for the font-sans utility automatically. */
215
218
 
216
219
  --radius-sm: calc(var(--radius) - 4px);
217
220
  --radius-md: calc(var(--radius) - 2px);
@@ -469,9 +472,14 @@ const appCss = `${banner}
469
472
  * shows up. next/font's preloaded vars come second as a self-hosted
470
473
  * fallback for forks that haven't loaded their own woff2 yet — keeps
471
474
  * the showcase styled even before fonts.css resolves. */
472
- --font-sans: ${fontSans}, var(--font-atkinson), 'Atkinson Hyperlegible', ui-sans-serif, sans-serif, system-ui;
473
- --font-serif: ${fontSerif}, var(--font-source-serif), 'Source Serif 4', Georgia, ui-serif, serif;
474
- --font-mono: ${fontMono}, var(--font-jetbrains), 'JetBrains Mono', ui-monospace, monospace;
475
+ /* var() fallbacks (second arg) are required: when next/font isn't running
476
+ (Storybook, plain HTML test harness), --font-atkinson et al. are
477
+ undefined, and a bare var() reference invalidates the entire
478
+ custom-property value at computed-value time, leaving --font-sans
479
+ empty and text falling through to browser default ("Times"). */
480
+ --font-sans: ${fontSans}, var(--font-atkinson, 'Atkinson Hyperlegible'), 'Atkinson Hyperlegible', ui-sans-serif, sans-serif, system-ui;
481
+ --font-serif: ${fontSerif}, var(--font-source-serif, 'Source Serif 4'), 'Source Serif 4', Georgia, ui-serif, serif;
482
+ --font-mono: ${fontMono}, var(--font-jetbrains, 'JetBrains Mono'), 'JetBrains Mono', ui-monospace, monospace;
475
483
  --font-size-scale: 1;
476
484
 
477
485
  ${lightVars}
@@ -1,4 +1,6 @@
1
1
  import type { Metadata } from "next";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
2
4
  import { Atkinson_Hyperlegible, Inter, JetBrains_Mono, Lora, Source_Serif_4 } from "next/font/google";
3
5
  import "@/styles/globals.css";
4
6
  import { brand } from "@/brand.config";
@@ -14,6 +16,28 @@ const brandSansMap = Object.fromEntries(
14
16
  brand.fonts.map((f) => [f.id, f.stack]),
15
17
  );
16
18
 
19
+ // Resolve the fork's slug at module load (server-side). Source priority:
20
+ // 1. .client-identity.json `slug` field (set by scripts/rename.mjs)
21
+ // 2. literal "bads" — upstream BADS itself, or unrenamed fresh forks
22
+ // Injected into the inline boot script as window.__BADS_SLUG__ so client
23
+ // hooks can derive their localStorage prefix without each one re-reading
24
+ // the filesystem (impossible in browser anyway).
25
+ function resolveSlug(): string {
26
+ try {
27
+ const raw = fs.readFileSync(
28
+ path.join(process.cwd(), ".client-identity.json"),
29
+ "utf8",
30
+ );
31
+ const ci = JSON.parse(raw) as { slug?: unknown };
32
+ if (typeof ci.slug === "string" && ci.slug.length > 0) return ci.slug;
33
+ } catch {
34
+ // file missing or unreadable — upstream BADS path
35
+ }
36
+ return "bads";
37
+ }
38
+ const slug = resolveSlug();
39
+ const slugUpper = slug.toUpperCase();
40
+
17
41
  // next/font self-hosts these and emits preload links automatically, so the
18
42
  // browser has the woff2 in hand before first paint — kills FOUT on the
19
43
  // showcase app. The published @import in packages/core/src/styles.css stays
@@ -45,9 +69,11 @@ const sourceSerif = Source_Serif_4({
45
69
  variable: "--font-source-serif",
46
70
  });
47
71
 
72
+ // Title and description derive from brand.config so each fork's tab title and
73
+ // open-graph metadata reflects its own identity without overriding this file.
48
74
  export const metadata: Metadata = {
49
- title: "BADS Design System",
50
- description: "Interactive design system and component dashboard",
75
+ title: brand.tagline ? `${brand.name} — ${brand.tagline}` : brand.name,
76
+ description: brand.tagline ?? "Interactive design system and component dashboard",
51
77
  };
52
78
 
53
79
  export default function RootLayout({
@@ -84,6 +110,23 @@ export default function RootLayout({
84
110
  __html: `
85
111
  (function() {
86
112
  try {
113
+ // Set the slug as a global so the storage helper in @core/lib/storage
114
+ // resolves the prefix consistently in every hook on this page. This
115
+ // line must run BEFORE the Next.js bundle parses any module that
116
+ // calls storageKey(), which is why it lives in the inline <head>.
117
+ window.__BADS_SLUG__ = ${JSON.stringify(slug)};
118
+ var P = ${JSON.stringify(slugUpper)};
119
+ function k(suffix) {
120
+ var newKey = P + "." + suffix;
121
+ var fresh = localStorage.getItem(newKey);
122
+ if (fresh !== null) return fresh;
123
+ var legacy = localStorage.getItem("BADS." + suffix);
124
+ if (legacy !== null && P !== "BADS") {
125
+ try { localStorage.setItem(newKey, legacy); localStorage.removeItem("BADS." + suffix); } catch (e) {}
126
+ return legacy;
127
+ }
128
+ return null;
129
+ }
87
130
  // Reference next/font's preloaded variables (--font-atkinson etc.)
88
131
  // first so the browser uses the already-fetched woff2 from the
89
132
  // very first paint. Fall back to system-ui if next/font hasn't
@@ -116,13 +159,13 @@ export default function RootLayout({
116
159
  "text-3xl": 4
117
160
  };
118
161
  var s = document.documentElement.style;
119
- var sans = localStorage.getItem("BADS.sansFont");
162
+ var sans = k("sansFont");
120
163
  if (sans && SANS[sans]) s.setProperty("--font-sans", SANS[sans]);
121
- var serif = localStorage.getItem("BADS.serifFont");
164
+ var serif = k("serifFont");
122
165
  if (serif && SERIF[serif]) s.setProperty("--font-serif", SERIF[serif]);
123
- var mono = localStorage.getItem("BADS.monoFont");
166
+ var mono = k("monoFont");
124
167
  if (mono && MONO[mono]) s.setProperty("--font-mono", MONO[mono]);
125
- var dc = localStorage.getItem("BADS.designControls");
168
+ var dc = k("designControls");
126
169
  if (dc) {
127
170
  try {
128
171
  var d = JSON.parse(dc);
@@ -132,7 +175,7 @@ export default function RootLayout({
132
175
  if (typeof d.shadowOpacity === "number") s.setProperty("--shadow-opacity", d.shadowOpacity.toFixed(2));
133
176
  } catch (e) {}
134
177
  }
135
- var ts = localStorage.getItem("BADS.typeScale");
178
+ var ts = k("typeScale");
136
179
  var base = 18;
137
180
  var ratio = 1.125;
138
181
  if (ts) {
@@ -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;
@@ -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 : {};
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Storage-key helper. Replaces the hardcoded "BADS." prefix that every
3
+ * shell hook used pre-0.4.0.
4
+ *
5
+ * Why this exists
6
+ * ----------------
7
+ * Before 0.4.0, every hook had `const STORAGE_KEY = "BADS.sansFont"` (and
8
+ * similar) inlined. `scripts/rename.mjs` rewrote those strings at fork time
9
+ * so a renamed fork stored data under "<SLUG_UPPER>.sansFont" instead.
10
+ *
11
+ * Once @core started shipping the hooks via npm (0.3.0), rename.mjs could no
12
+ * longer reach the hook source — it lives in node_modules, not the consumer
13
+ * tree. Forks ended up reading "BADS.sansFont" from localStorage even though
14
+ * their saved customizations were under "<SLUG_UPPER>.sansFont", silently
15
+ * losing every Customize-tab edit they had made.
16
+ *
17
+ * Fix: derive the prefix at runtime from the fork's slug, which the layout
18
+ * exposes on `window.__BADS_SLUG__` (server-rendered from
19
+ * `.client-identity.json` or — for upstream BADS — defaulted to "bads").
20
+ *
21
+ * Module evaluation happens after the inline `<head>` script has set the
22
+ * global, so reading at top level is safe during client hydration. Server
23
+ * evaluations land on "BADS." but never reach localStorage, so the
24
+ * server-side value is harmless.
25
+ */
26
+
27
+ declare global {
28
+ interface Window {
29
+ __BADS_SLUG__?: string;
30
+ }
31
+ }
32
+
33
+ function getPrefix(): string {
34
+ if (typeof window !== "undefined" && typeof window.__BADS_SLUG__ === "string" && window.__BADS_SLUG__) {
35
+ return window.__BADS_SLUG__.toUpperCase();
36
+ }
37
+ return "BADS";
38
+ }
39
+
40
+ export function storageKey(suffix: string): string {
41
+ return `${getPrefix()}.${suffix}`;
42
+ }
43
+
44
+ const MIGRATED = new Set<string>();
45
+
46
+ /**
47
+ * Reads localStorage at the prefixed key. If empty, looks under the legacy
48
+ * "BADS.<suffix>" key one time per suffix per session — if found, copies the
49
+ * value to the new key and removes the old one. Returns the resolved string
50
+ * or null.
51
+ *
52
+ * Use this in place of `localStorage.getItem(STORAGE_KEY)` inside hook
53
+ * `useEffect` blocks so renamed forks pick up data they wrote pre-0.4.0
54
+ * (back when the hook source was workspace-forked and rename.mjs had
55
+ * written "<SLUG>." into the source). After one read, the data is on the
56
+ * new key and the old key is gone — subsequent reads skip the migration.
57
+ */
58
+ export function readMigrated(suffix: string): string | null {
59
+ if (typeof window === "undefined") return null;
60
+ const newKey = storageKey(suffix);
61
+ const fresh = window.localStorage.getItem(newKey);
62
+ if (fresh !== null) return fresh;
63
+ if (MIGRATED.has(suffix)) return null;
64
+ MIGRATED.add(suffix);
65
+ const legacyKey = `BADS.${suffix}`;
66
+ if (legacyKey === newKey) return null;
67
+ const legacy = window.localStorage.getItem(legacyKey);
68
+ if (legacy === null) return null;
69
+ try {
70
+ window.localStorage.setItem(newKey, legacy);
71
+ window.localStorage.removeItem(legacyKey);
72
+ } catch {
73
+ // Quota or privacy mode — return the value but leave both keys intact.
74
+ }
75
+ return legacy;
76
+ }
@@ -1,7 +1,16 @@
1
1
  import tokens from "../tokens.json";
2
-
3
- export const THEME_EDITOR_STORAGE_KEY = "BADS.themeEditorState";
4
- export const THEME_EDITOR_STYLE_ID = "bads-live-theme-editor";
2
+ import { storageKey, readMigrated } from "@behavioral-agentic-design-system/core/lib/storage";
3
+
4
+ // Both keys derive from the runtime slug so a renamed fork uses
5
+ // "<SLUG>.themeEditorState" / "<slug>-live-theme-editor" without rename.mjs
6
+ // having to rewrite hook source. The legacy "BADS." key gets migrated on
7
+ // first read via readMigrated() inside readStoredThemeEditorState.
8
+ export const THEME_EDITOR_STORAGE_KEY = storageKey("themeEditorState");
9
+ const slugForStyleId =
10
+ typeof window !== "undefined" && typeof window.__BADS_SLUG__ === "string" && window.__BADS_SLUG__
11
+ ? window.__BADS_SLUG__
12
+ : "bads";
13
+ export const THEME_EDITOR_STYLE_ID = `${slugForStyleId}-live-theme-editor`;
5
14
 
6
15
  export type ThemeEditorMode = "light" | "dark";
7
16
 
@@ -105,7 +114,7 @@ export function readStoredThemeEditorState(): ThemeEditorState {
105
114
  if (typeof window === "undefined") return DEFAULT_THEME_EDITOR_STATE;
106
115
 
107
116
  try {
108
- const raw = window.localStorage.getItem(THEME_EDITOR_STORAGE_KEY);
117
+ const raw = readMigrated("themeEditorState");
109
118
  if (!raw) return DEFAULT_THEME_EDITOR_STATE;
110
119
 
111
120
  const parsed = JSON.parse(raw);
package/src/styles.css CHANGED
@@ -171,9 +171,12 @@
171
171
  --color-sidebar-border: var(--sidebar-border);
172
172
  --color-sidebar-ring: var(--sidebar-ring);
173
173
 
174
- --font-sans: var(--font-sans);
175
- --font-mono: var(--font-mono);
176
- --font-serif: var(--font-serif);
174
+ /* font-sans/serif/mono intentionally NOT mapped here. Tailwind v4
175
+ compiles @theme inline self-references into a :root rule of the
176
+ same shape, which collides with the unlayered :root that sets the
177
+ actual font stack and resolves to an empty circular reference. The
178
+ :root above already defines --font-sans, and Tailwind picks it up
179
+ for the font-sans utility automatically. */
177
180
 
178
181
  --radius-sm: calc(var(--radius) - 4px);
179
182
  --radius-md: calc(var(--radius) - 2px);