@behavioral-agentic-design-system/core 0.5.0 → 0.6.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 (42) hide show
  1. package/package.json +15 -8
  2. package/scripts/build-fonts.cjs +90 -0
  3. package/scripts/build-tokens.cjs +84 -8
  4. package/src/api/brand-fonts.ts +280 -0
  5. package/src/api/brand-mark.ts +146 -0
  6. package/src/api/layers/file.ts +4 -2
  7. package/src/api/layers.ts +23 -1
  8. package/src/app/font-ready.tsx +1 -1
  9. package/src/app/layout.tsx +3 -9
  10. package/src/app/preview/cards/page.tsx +1 -1
  11. package/src/app/preview/login/page.tsx +5 -0
  12. package/src/app/shell.tsx +90 -29
  13. package/src/components/admin-menu.stories.tsx +68 -0
  14. package/src/components/admin-menu.tsx +59 -0
  15. package/src/components/brand-mark.tsx +64 -0
  16. package/src/components/customize/brand-mark-section.tsx +265 -0
  17. package/src/components/customize/font-pickers.tsx +293 -0
  18. package/src/components/customize/save-bar.tsx +11 -5
  19. package/src/components/customize-tab.tsx +329 -24
  20. package/src/components/dev-identity-badge.tsx +92 -0
  21. package/src/components/home-tab.tsx +1022 -374
  22. package/src/components/layers-tab.tsx +38 -9
  23. package/src/components/ui/alert.tsx +10 -2
  24. package/src/components/ui/button.tsx +1 -1
  25. package/src/components/ui/calendar.tsx +1 -1
  26. package/src/components/ui/chart.tsx +13 -3
  27. package/src/components/ui/checkbox.tsx +1 -1
  28. package/src/components/ui/radio-group.tsx +1 -1
  29. package/src/components/ui/sidebar.tsx +6 -1
  30. package/src/components/ui/sonner.tsx +18 -0
  31. package/src/components/ui/switch.tsx +7 -1
  32. package/src/components/ui/tabs.tsx +1 -1
  33. package/src/hooks/use-global-brand-mark.ts +64 -0
  34. package/src/hooks/use-global-mono-font.ts +13 -3
  35. package/src/hooks/use-global-primary-color.ts +145 -8
  36. package/src/hooks/use-global-sans-font.ts +5 -3
  37. package/src/hooks/use-global-serif-font.ts +14 -4
  38. package/src/lib/storage.ts +31 -2
  39. package/src/lib/svg-sanitize.ts +272 -0
  40. package/src/styles.css +76 -46
  41. package/src/tokens.default.json +4 -4
  42. package/src/tokens.json +172 -78
@@ -0,0 +1,265 @@
1
+ "use client";
2
+
3
+ import { useEffect, useRef, useState } from "react";
4
+ import { Upload, RotateCcw, Sparkles, AlertCircle, Check } from "lucide-react";
5
+ import { Button } from "@behavioral-agentic-design-system/core/components/ui/button";
6
+ import { Textarea } from "@behavioral-agentic-design-system/core/components/ui/textarea";
7
+ import { brand } from "@/brand.config";
8
+ import {
9
+ clearGlobalBrandMarkSvg,
10
+ setGlobalBrandMarkSvg,
11
+ } from "@behavioral-agentic-design-system/core/hooks/use-global-brand-mark";
12
+
13
+ type ApiResponse = {
14
+ ok: boolean;
15
+ svg?: string | null;
16
+ original?: string | null;
17
+ monotone?: boolean;
18
+ colorCount?: number;
19
+ error?: string;
20
+ };
21
+
22
+ /**
23
+ * Brand Mark editor. Paste SVG markup OR upload a .svg file. Saving POSTs to
24
+ * /api/brand-mark which sanitizes and (if monotone) rewrites colors to
25
+ * currentColor. On success, we publish the saved SVG to the live brand-mark
26
+ * store so the shell header and any other BrandMark surfaces update without a
27
+ * manual reload.
28
+ */
29
+ export function BrandMarkSection() {
30
+ const initialOriginal = brand.logo?.original ?? "";
31
+ const initialSvg = brand.logo?.svg ?? null;
32
+ const [draft, setDraft] = useState(initialOriginal);
33
+ const [savedSvg, setSavedSvg] = useState<string | null>(initialSvg);
34
+ const [status, setStatus] = useState<
35
+ | { kind: "idle" }
36
+ | { kind: "saving" }
37
+ | { kind: "success"; monotone: boolean; colorCount: number }
38
+ | { kind: "error"; message: string }
39
+ >({ kind: "idle" });
40
+ const fileInputRef = useRef<HTMLInputElement>(null);
41
+
42
+ // Re-sync draft when brand.config refreshes via HMR (e.g. someone edited
43
+ // brand-mark.json directly).
44
+ useEffect(() => {
45
+ setDraft(brand.logo?.original ?? "");
46
+ setSavedSvg(brand.logo?.svg ?? null);
47
+ }, []);
48
+
49
+ const handleFile = async (file: File | null) => {
50
+ if (!file) return;
51
+ if (!file.name.toLowerCase().endsWith(".svg") && file.type !== "image/svg+xml") {
52
+ setStatus({ kind: "error", message: "Pick an .svg file" });
53
+ return;
54
+ }
55
+ if (file.size > 200_000) {
56
+ setStatus({ kind: "error", message: "SVG exceeds 200KB cap" });
57
+ return;
58
+ }
59
+ const text = await file.text();
60
+ setDraft(text);
61
+ setStatus({ kind: "idle" });
62
+ };
63
+
64
+ const handleSave = async () => {
65
+ const svg = draft.trim();
66
+ if (!svg) {
67
+ setStatus({ kind: "error", message: "Paste or upload an SVG first" });
68
+ return;
69
+ }
70
+ setStatus({ kind: "saving" });
71
+ try {
72
+ const res = await fetch("/api/brand-mark", {
73
+ method: "POST",
74
+ headers: { "Content-Type": "application/json" },
75
+ body: JSON.stringify({ svg }),
76
+ });
77
+ const data = (await res.json()) as ApiResponse;
78
+ if (!data.ok) {
79
+ setStatus({ kind: "error", message: data.error ?? "Save failed" });
80
+ return;
81
+ }
82
+ setSavedSvg(data.svg ?? null);
83
+ setGlobalBrandMarkSvg(data.svg ?? null);
84
+ setStatus({
85
+ kind: "success",
86
+ monotone: Boolean(data.monotone),
87
+ colorCount: data.colorCount ?? 0,
88
+ });
89
+ } catch (err) {
90
+ setStatus({ kind: "error", message: (err as Error).message });
91
+ }
92
+ };
93
+
94
+ const handleReset = async () => {
95
+ setStatus({ kind: "saving" });
96
+ try {
97
+ const res = await fetch("/api/brand-mark", { method: "DELETE" });
98
+ const data = (await res.json()) as ApiResponse;
99
+ if (!data.ok) {
100
+ setStatus({ kind: "error", message: data.error ?? "Reset failed" });
101
+ return;
102
+ }
103
+ setSavedSvg(null);
104
+ setDraft("");
105
+ clearGlobalBrandMarkSvg();
106
+ if (fileInputRef.current) fileInputRef.current.value = "";
107
+ setStatus({ kind: "idle" });
108
+ } catch (err) {
109
+ setStatus({ kind: "error", message: (err as Error).message });
110
+ }
111
+ };
112
+
113
+ // Live preview source — prefer the user's draft if it parses as SVG
114
+ // (gives instant feedback before save), else fall back to the saved svg.
115
+ const previewSvg = (() => {
116
+ const d = draft.trim();
117
+ if (d && /^<svg[\s>]/i.test(d)) return d;
118
+ return savedSvg;
119
+ })();
120
+
121
+ return (
122
+ <section>
123
+ <div className="flex items-center justify-between mb-2">
124
+ <h2 className="text-2xl font-semibold tracking-tight">Brand Mark</h2>
125
+ {savedSvg && (
126
+ <Button variant="outline" size="sm" onClick={handleReset} className="text-xs">
127
+ <RotateCcw className="h-3 w-3 mr-1.5" strokeWidth={1.5} />
128
+ Reset
129
+ </Button>
130
+ )}
131
+ </div>
132
+ <p className="text-sm text-muted-foreground mb-8 max-w-prose">
133
+ Paste SVG markup or upload an <code className="font-mono text-xs">.svg</code> file.
134
+ Monotone marks (one color throughout) get rewritten to{" "}
135
+ <code className="font-mono text-xs">currentColor</code> so the logo adopts the
136
+ surrounding text color. Multi-color marks are preserved exactly. Saves to{" "}
137
+ <code className="font-mono text-xs">brand-mark.json</code>.
138
+ </p>
139
+
140
+ <div className="grid gap-6 lg:grid-cols-2">
141
+ {/* Inputs column */}
142
+ <div className="flex flex-col gap-4">
143
+ <div className="flex flex-col gap-2">
144
+ <label htmlFor="brand-mark-paste" className="text-sm font-medium">
145
+ SVG markup
146
+ </label>
147
+ <Textarea
148
+ id="brand-mark-paste"
149
+ value={draft}
150
+ onChange={(e) => {
151
+ setDraft(e.target.value);
152
+ if (status.kind === "error" || status.kind === "success") {
153
+ setStatus({ kind: "idle" });
154
+ }
155
+ }}
156
+ placeholder='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">…</svg>'
157
+ className="min-h-[180px] font-mono text-xs"
158
+ />
159
+ </div>
160
+
161
+ <div className="flex flex-col gap-2">
162
+ <span className="text-sm font-medium">or upload</span>
163
+ <div className="flex items-center gap-2">
164
+ <input
165
+ ref={fileInputRef}
166
+ type="file"
167
+ accept=".svg,image/svg+xml"
168
+ onChange={(e) => handleFile(e.target.files?.[0] ?? null)}
169
+ className="hidden"
170
+ id="brand-mark-file"
171
+ />
172
+ <Button
173
+ type="button"
174
+ variant="outline"
175
+ size="sm"
176
+ onClick={() => fileInputRef.current?.click()}
177
+ >
178
+ <Upload className="h-3.5 w-3.5 mr-1.5" strokeWidth={1.5} />
179
+ Choose .svg file
180
+ </Button>
181
+ <span className="text-xs text-muted-foreground">200KB max</span>
182
+ </div>
183
+ </div>
184
+
185
+ <div className="flex items-center gap-3 pt-2">
186
+ <Button onClick={handleSave} disabled={status.kind === "saving" || !draft.trim()}>
187
+ {status.kind === "saving" ? "Saving…" : "Save to brand"}
188
+ </Button>
189
+ {status.kind === "success" && (
190
+ <span className="inline-flex items-center gap-1.5 text-sm text-emerald-700 dark:text-emerald-400">
191
+ <Check className="h-4 w-4" strokeWidth={1.5} />
192
+ Saved.{" "}
193
+ {status.monotone
194
+ ? "Monotone — adopts theme color."
195
+ : `${status.colorCount} colors preserved.`}
196
+ </span>
197
+ )}
198
+ {status.kind === "error" && (
199
+ <span className="inline-flex items-center gap-1.5 text-sm text-destructive">
200
+ <AlertCircle className="h-4 w-4" strokeWidth={1.5} />
201
+ {status.message}
202
+ </span>
203
+ )}
204
+ </div>
205
+ </div>
206
+
207
+ {/* Preview column */}
208
+ <div className="flex flex-col gap-4">
209
+ <span className="text-sm font-medium">Preview</span>
210
+ <div className="grid grid-cols-2 gap-3">
211
+ <PreviewTile mode="light" svg={previewSvg} />
212
+ <PreviewTile mode="dark" svg={previewSvg} />
213
+ </div>
214
+ <p className="text-xs text-muted-foreground">
215
+ Header renders at 20px. Login screens and storybook use larger sizes — the
216
+ mark scales with the surrounding type.
217
+ </p>
218
+ </div>
219
+ </div>
220
+ </section>
221
+ );
222
+ }
223
+
224
+ function PreviewTile({ mode, svg }: { mode: "light" | "dark"; svg: string | null }) {
225
+ const isLight = mode === "light";
226
+ return (
227
+ <div
228
+ className={`flex flex-col items-center justify-center gap-4 rounded-lg border p-6 ${
229
+ isLight ? "bg-white text-zinc-900" : "bg-zinc-950 text-zinc-50"
230
+ }`}
231
+ >
232
+ <div className="flex items-center gap-4">
233
+ {/* 32px size — matches header rhythm */}
234
+ <Mark size={32} svg={svg} />
235
+ {/* 96px size — login/branded surfaces */}
236
+ <Mark size={96} svg={svg} />
237
+ </div>
238
+ <span className="text-xs text-muted-foreground">{isLight ? "Light" : "Dark"}</span>
239
+ </div>
240
+ );
241
+ }
242
+
243
+ function Mark({ size, svg }: { size: number; svg: string | null }) {
244
+ if (svg) {
245
+ return (
246
+ <span
247
+ role="img"
248
+ aria-label="Brand mark preview"
249
+ className="inline-flex items-center justify-center [&>svg]:h-full [&>svg]:w-full"
250
+ style={{ width: size, height: size }}
251
+ dangerouslySetInnerHTML={{ __html: svg }}
252
+ />
253
+ );
254
+ }
255
+ return (
256
+ <span
257
+ role="img"
258
+ aria-label="Default sparkles fallback"
259
+ className="inline-flex items-center justify-center"
260
+ style={{ width: size, height: size }}
261
+ >
262
+ <Sparkles width={size * 0.55} height={size * 0.55} strokeWidth={1.5} />
263
+ </span>
264
+ );
265
+ }
@@ -1,5 +1,7 @@
1
1
  "use client";
2
2
 
3
+ import { useRef, useState } from "react";
4
+ import { Plus, Upload, AlertCircle } from "lucide-react";
3
5
  import {
4
6
  SANS_FONT_OPTIONS,
5
7
  useGlobalSansFont,
@@ -15,19 +17,306 @@ import {
15
17
  useGlobalMonoFont,
16
18
  type MonoFontKey,
17
19
  } from "@behavioral-agentic-design-system/core/hooks/use-global-mono-font";
20
+ import { Button } from "@behavioral-agentic-design-system/core/components/ui/button";
21
+ import { Input } from "@behavioral-agentic-design-system/core/components/ui/input";
22
+ import {
23
+ Popover,
24
+ PopoverContent,
25
+ PopoverTrigger,
26
+ } from "@behavioral-agentic-design-system/core/components/ui/popover";
18
27
 
19
28
  type FontOption = { label: string; stack: string };
29
+ type FontKind = "sans" | "serif" | "mono";
30
+
31
+ function inferLabel(name: string): string {
32
+ return name
33
+ .replace(/\.(woff2?|ttf|otf)$/i, "")
34
+ .replace(/[-_](thin|extralight|light|regular|medium|semibold|bold|extrabold|black|italic|oblique|\d{3})/gi, "")
35
+ .replace(/[-_]+/g, " ")
36
+ .trim();
37
+ }
38
+
39
+ function inferWeight(name: string): number {
40
+ const lower = name.toLowerCase();
41
+ if (/(thin|hairline|100)/.test(lower)) return 100;
42
+ if (/(extralight|ultralight|200)/.test(lower)) return 200;
43
+ if (/(light|300)/.test(lower)) return 300;
44
+ if (/(medium|500)/.test(lower)) return 500;
45
+ if (/(semibold|demibold|600)/.test(lower)) return 600;
46
+ if (/(extrabold|ultrabold|800)/.test(lower)) return 800;
47
+ if (/(black|heavy|900)/.test(lower)) return 900;
48
+ if (/(bold|700)/.test(lower)) return 700;
49
+ return 400;
50
+ }
51
+
52
+ function inferStyle(name: string): "normal" | "italic" {
53
+ return /italic|oblique/i.test(name) ? "italic" : "normal";
54
+ }
55
+
56
+ function inferId(label: string, kind: FontKind): string {
57
+ const slug = label
58
+ .toLowerCase()
59
+ .replace(/[^a-z0-9]+/g, "-")
60
+ .replace(/^-|-$/g, "");
61
+ return slug ? `${slug}-${kind}` : `custom-${kind}-${Date.now()}`;
62
+ }
63
+
64
+ function defaultStack(label: string, kind: FontKind): string {
65
+ const fallback =
66
+ kind === "sans"
67
+ ? "ui-sans-serif, sans-serif, system-ui"
68
+ : kind === "serif"
69
+ ? "ui-serif, Georgia, serif"
70
+ : "ui-monospace, SFMono-Regular, monospace";
71
+ return `'${label.replace(/'/g, "\\'")}', ${fallback}`;
72
+ }
73
+
74
+ type FileMeta = { weight: number; style: "normal" | "italic" };
75
+
76
+ function AddFontTile({ kind }: { kind: FontKind }) {
77
+ const [open, setOpen] = useState(false);
78
+ const [files, setFiles] = useState<File[]>([]);
79
+ const [meta, setMeta] = useState<FileMeta[]>([]);
80
+ const [label, setLabel] = useState("");
81
+ const [stack, setStack] = useState("");
82
+ const [error, setError] = useState<string | null>(null);
83
+ const [saving, setSaving] = useState(false);
84
+ const fileInputRef = useRef<HTMLInputElement>(null);
85
+
86
+ const reset = () => {
87
+ setFiles([]);
88
+ setMeta([]);
89
+ setLabel("");
90
+ setStack("");
91
+ setError(null);
92
+ setSaving(false);
93
+ if (fileInputRef.current) fileInputRef.current.value = "";
94
+ };
95
+
96
+ const handleFiles = (list: FileList | null) => {
97
+ if (!list) return;
98
+ const arr = Array.from(list).filter((f) => /\.(woff2?|woff)$/i.test(f.name));
99
+ if (arr.length === 0) {
100
+ setError("Pick .woff2 or .woff files (convert ttf/otf first)");
101
+ return;
102
+ }
103
+ setFiles(arr);
104
+ setMeta(arr.map((f) => ({ weight: inferWeight(f.name), style: inferStyle(f.name) })));
105
+ if (!label) {
106
+ const guess = inferLabel(arr[0].name);
107
+ setLabel(guess);
108
+ setStack(defaultStack(guess, kind));
109
+ }
110
+ setError(null);
111
+ };
112
+
113
+ const handleSave = async () => {
114
+ if (files.length === 0) {
115
+ setError("Upload at least one file");
116
+ return;
117
+ }
118
+ if (!label.trim() || !stack.trim()) {
119
+ setError("Need a label and stack");
120
+ return;
121
+ }
122
+ setSaving(true);
123
+ setError(null);
124
+ const form = new FormData();
125
+ const id = inferId(label, kind);
126
+ form.set("id", id);
127
+ form.set("label", label.trim());
128
+ form.set("stack", stack.trim());
129
+ form.set("kind", kind);
130
+ files.forEach((f, i) => {
131
+ form.append("files", f);
132
+ form.append("weights", String(meta[i]?.weight ?? 400));
133
+ form.append("styles", meta[i]?.style ?? "normal");
134
+ });
135
+ try {
136
+ const res = await fetch("/api/brand-fonts", { method: "POST", body: form });
137
+ const data = await res.json();
138
+ if (!data.ok) {
139
+ setError(data.error ?? "Save failed");
140
+ setSaving(false);
141
+ return;
142
+ }
143
+ reset();
144
+ setOpen(false);
145
+ } catch (err) {
146
+ setError((err as Error).message);
147
+ setSaving(false);
148
+ }
149
+ };
150
+
151
+ return (
152
+ <Popover
153
+ open={open}
154
+ onOpenChange={(next) => {
155
+ setOpen(next);
156
+ if (!next) setError(null);
157
+ }}
158
+ >
159
+ <PopoverTrigger asChild>
160
+ <button
161
+ type="button"
162
+ className="group flex flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border p-4 transition-all hover:border-foreground/40 min-h-[7.5rem]"
163
+ aria-label={`Add custom ${kind} font`}
164
+ >
165
+ <div className="flex h-10 w-10 items-center justify-center rounded-full border border-dashed border-border text-muted-foreground group-hover:text-foreground">
166
+ <Plus className="h-5 w-5" strokeWidth={1.5} />
167
+ </div>
168
+ <span className="text-sm font-medium text-muted-foreground group-hover:text-foreground leading-tight">
169
+ Add font
170
+ </span>
171
+ </button>
172
+ </PopoverTrigger>
173
+ <PopoverContent className="w-[380px] p-4" align="start">
174
+ <div className="flex flex-col gap-3">
175
+ <div>
176
+ <p className="text-sm font-medium">Add {kind} font</p>
177
+ <p className="text-xs text-muted-foreground mt-0.5">
178
+ Upload .woff2 or .woff files. One per weight/style.
179
+ </p>
180
+ </div>
181
+
182
+ <div className="flex items-center gap-2">
183
+ <input
184
+ ref={fileInputRef}
185
+ type="file"
186
+ accept=".woff2,.woff,font/woff2,font/woff"
187
+ multiple
188
+ onChange={(e) => handleFiles(e.target.files)}
189
+ className="hidden"
190
+ />
191
+ <Button
192
+ type="button"
193
+ variant="outline"
194
+ size="sm"
195
+ onClick={() => fileInputRef.current?.click()}
196
+ >
197
+ <Upload className="h-3.5 w-3.5 mr-1.5" strokeWidth={1.5} />
198
+ {files.length > 0 ? `${files.length} file${files.length > 1 ? "s" : ""}` : "Choose files"}
199
+ </Button>
200
+ </div>
201
+
202
+ {files.length > 0 && (
203
+ <div className="flex flex-col gap-1.5 max-h-44 overflow-auto rounded-md border border-border p-2">
204
+ {files.map((f, i) => (
205
+ <div key={f.name} className="flex items-center gap-2 text-xs">
206
+ <span className="flex-1 truncate font-mono text-muted-foreground" title={f.name}>
207
+ {f.name}
208
+ </span>
209
+ <Input
210
+ type="number"
211
+ value={meta[i]?.weight ?? 400}
212
+ onChange={(e) => {
213
+ const w = parseInt(e.target.value, 10);
214
+ setMeta((prev) => {
215
+ const next = [...prev];
216
+ next[i] = { ...next[i], weight: Number.isFinite(w) ? w : 400 };
217
+ return next;
218
+ });
219
+ }}
220
+ className="h-7 w-16 text-xs"
221
+ min={100}
222
+ max={900}
223
+ step={100}
224
+ />
225
+ <select
226
+ value={meta[i]?.style ?? "normal"}
227
+ onChange={(e) =>
228
+ setMeta((prev) => {
229
+ const next = [...prev];
230
+ next[i] = {
231
+ ...next[i],
232
+ style: e.target.value === "italic" ? "italic" : "normal",
233
+ };
234
+ return next;
235
+ })
236
+ }
237
+ className="h-7 rounded-md border border-input bg-background px-2 text-xs"
238
+ >
239
+ <option value="normal">normal</option>
240
+ <option value="italic">italic</option>
241
+ </select>
242
+ </div>
243
+ ))}
244
+ </div>
245
+ )}
246
+
247
+ <div className="flex flex-col gap-1.5">
248
+ <label htmlFor="brand-font-label" className="text-xs font-medium">
249
+ Label
250
+ </label>
251
+ <Input
252
+ id="brand-font-label"
253
+ value={label}
254
+ onChange={(e) => {
255
+ setLabel(e.target.value);
256
+ if (!stack || stack === defaultStack(label, kind)) {
257
+ setStack(defaultStack(e.target.value, kind));
258
+ }
259
+ }}
260
+ placeholder="Acme Sans"
261
+ className="h-9"
262
+ />
263
+ </div>
264
+
265
+ <div className="flex flex-col gap-1.5">
266
+ <label htmlFor="brand-font-stack" className="text-xs font-medium">
267
+ Family stack
268
+ </label>
269
+ <Input
270
+ id="brand-font-stack"
271
+ value={stack}
272
+ onChange={(e) => setStack(e.target.value)}
273
+ placeholder="'Acme Sans', ui-sans-serif, sans-serif"
274
+ className="h-9 font-mono text-xs"
275
+ />
276
+ </div>
277
+
278
+ {error && (
279
+ <div className="flex items-start gap-1.5 text-xs text-destructive">
280
+ <AlertCircle className="h-3.5 w-3.5 mt-0.5 flex-shrink-0" strokeWidth={1.5} />
281
+ <span>{error}</span>
282
+ </div>
283
+ )}
284
+
285
+ <div className="flex justify-end gap-2 pt-1">
286
+ <Button
287
+ type="button"
288
+ variant="ghost"
289
+ size="sm"
290
+ onClick={() => {
291
+ reset();
292
+ setOpen(false);
293
+ }}
294
+ >
295
+ Cancel
296
+ </Button>
297
+ <Button type="button" size="sm" onClick={handleSave} disabled={saving}>
298
+ {saving ? "Saving…" : "Save to brand"}
299
+ </Button>
300
+ </div>
301
+ </div>
302
+ </PopoverContent>
303
+ </Popover>
304
+ );
305
+ }
20
306
 
21
307
  function FontCardGrid<K extends string>({
22
308
  options,
23
309
  active,
24
310
  onSelect,
25
311
  sample = "Aa",
312
+ kind,
26
313
  }: {
27
314
  options: Record<K, FontOption>;
28
315
  active: K;
29
316
  onSelect: (key: K) => void;
30
317
  sample?: string;
318
+ /** When set, an "Add font" tile is appended to the grid for self-hosted uploads. */
319
+ kind?: FontKind;
31
320
  }) {
32
321
  const keys = Object.keys(options) as K[];
33
322
  return (
@@ -59,6 +348,7 @@ function FontCardGrid<K extends string>({
59
348
  </button>
60
349
  );
61
350
  })}
351
+ {kind && <AddFontTile kind={kind} />}
62
352
  </div>
63
353
  );
64
354
  }
@@ -75,6 +365,7 @@ export function SansFontPicker() {
75
365
  options={SANS_FONT_OPTIONS}
76
366
  active={font}
77
367
  onSelect={setFont}
368
+ kind="sans"
78
369
  />
79
370
  </div>
80
371
  );
@@ -93,6 +384,7 @@ export function SerifFontPicker() {
93
384
  options={SERIF_FONT_OPTIONS}
94
385
  active={font}
95
386
  onSelect={setFont}
387
+ kind="serif"
96
388
  />
97
389
  </div>
98
390
  );
@@ -112,6 +404,7 @@ export function MonoFontPicker() {
112
404
  active={font}
113
405
  onSelect={setFont}
114
406
  sample="</>"
407
+ kind="mono"
115
408
  />
116
409
  </div>
117
410
  );
@@ -30,7 +30,11 @@ 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";
33
+ import {
34
+ storageKey,
35
+ readMigrated,
36
+ clearAllCustomization,
37
+ } from "@behavioral-agentic-design-system/core/lib/storage";
34
38
 
35
39
  const STORAGE_KEYS = {
36
40
  primaryColor: storageKey("primaryColor"),
@@ -314,10 +318,12 @@ export function SaveBar() {
314
318
 
315
319
  const handleResetAll = useCallback(() => {
316
320
  if (typeof window === "undefined") return;
317
- Object.values(STORAGE_KEYS).forEach((key) => window.localStorage.removeItem(key));
318
- // Reset also clears the saved-snapshot baseline so the bar fully matches
319
- // the hardcoded defaults again.
320
- window.localStorage.removeItem(SAVED_SNAPSHOT_KEY);
321
+ // Wipe every "<PREFIX>.*" key (default keep: light/dark theme — it's a
322
+ // UI preference, not a tokens.json customization). Using the prefix
323
+ // sweep means new customize hooks auto-reset; no STORAGE_KEYS list to
324
+ // remember. Saved-snapshot baseline is included so the bar fully
325
+ // matches hardcoded defaults again.
326
+ clearAllCustomization();
321
327
  // Trigger a reload so all hooks pick up defaults cleanly.
322
328
  window.location.reload();
323
329
  }, []);