@behavioral-agentic-design-system/core 0.5.0 → 0.7.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 (61) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +39 -7
  3. package/scripts/bads-sync.mjs +1 -1
  4. package/scripts/build-fonts.cjs +97 -0
  5. package/scripts/build-tokens.cjs +202 -10
  6. package/src/api/brand-fonts.ts +301 -0
  7. package/src/api/brand-mark.ts +146 -0
  8. package/src/api/layers/file.ts +8 -5
  9. package/src/api/layers.ts +27 -4
  10. package/src/api/site-auth.ts +50 -0
  11. package/src/app/preview/cards/page.tsx +1 -1
  12. package/src/app/preview/components/page.tsx +78 -1
  13. package/src/app/preview/icons/page.tsx +5 -0
  14. package/src/app/shell.tsx +105 -39
  15. package/src/app/site-login/page.tsx +82 -0
  16. package/src/brand-fonts.css +5 -0
  17. package/src/components/Foundations/Motion.stories.tsx +66 -0
  18. package/src/components/brand-mark.tsx +64 -0
  19. package/src/components/customize/brand-mark-section.tsx +265 -0
  20. package/src/components/customize/font-pickers.tsx +293 -0
  21. package/src/components/customize/letter-spacing.tsx +3 -2
  22. package/src/components/customize/save-bar.tsx +11 -5
  23. package/src/components/customize/type-scale.tsx +3 -2
  24. package/src/components/customize-tab.tsx +330 -24
  25. package/src/components/dev-identity-badge.tsx +92 -0
  26. package/src/components/home-tab.tsx +1291 -380
  27. package/src/components/layers-tab.tsx +179 -12
  28. package/src/components/ui/alert.tsx +10 -2
  29. package/src/components/ui/bottom-sheet.tsx +124 -0
  30. package/src/components/ui/button.tsx +2 -2
  31. package/src/components/ui/calendar.tsx +1 -1
  32. package/src/components/ui/chart.tsx +118 -7
  33. package/src/components/ui/checkbox.tsx +3 -2
  34. package/src/components/ui/dialog.tsx +3 -3
  35. package/src/components/ui/index.ts +1 -0
  36. package/src/components/ui/radio-group.tsx +4 -3
  37. package/src/components/ui/sheet.tsx +1 -1
  38. package/src/components/ui/sidebar.tsx +6 -1
  39. package/src/components/ui/sonner.tsx +18 -0
  40. package/src/components/ui/switch.tsx +9 -3
  41. package/src/components/ui/tabs.tsx +7 -1
  42. package/src/fonts/HyperlegibleSans-Bold.woff2 +0 -0
  43. package/src/fonts/HyperlegibleSans-BoldItalic.woff2 +0 -0
  44. package/src/fonts/HyperlegibleSans-Italic.woff2 +0 -0
  45. package/src/fonts/HyperlegibleSans-Medium.woff2 +0 -0
  46. package/src/fonts/HyperlegibleSans-MediumItalic.woff2 +0 -0
  47. package/src/fonts/HyperlegibleSans-Regular.woff2 +0 -0
  48. package/src/fonts/InterVariable-Italic.woff2 +0 -0
  49. package/src/fonts/InterVariable.woff2 +0 -0
  50. package/src/fonts.css +99 -0
  51. package/src/hooks/use-global-brand-mark.ts +64 -0
  52. package/src/hooks/use-global-mono-font.ts +13 -3
  53. package/src/hooks/use-global-primary-color.ts +192 -9
  54. package/src/hooks/use-global-sans-font.ts +5 -3
  55. package/src/hooks/use-global-serif-font.ts +13 -3
  56. package/src/lib/storage.ts +29 -0
  57. package/src/lib/svg-sanitize.ts +272 -0
  58. package/src/styles.css +126 -6
  59. package/src/tokens.json +100 -9
  60. package/src/app/preview/mail/page.tsx +0 -4
  61. package/src/app/preview/pricing/page.tsx +0 -4
@@ -0,0 +1,301 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { spawn } from "node:child_process";
4
+ import { NextResponse } from "next/server";
5
+
6
+ const FONTS_PATH = path.join(process.cwd(), "brand-fonts.json");
7
+ // Canonical location — ships with the npm package via the `./fonts/*` export.
8
+ const PKG_FONTS = path.join(
9
+ process.cwd(),
10
+ "packages",
11
+ "core",
12
+ "src",
13
+ "fonts",
14
+ );
15
+ // Mirror — Next.js serves these at /fonts/<file> for the dev preview. Kept
16
+ // in sync with PKG_FONTS so the preview reflects uploads instantly without a
17
+ // symlink (symlinks complicate Windows + git in mixed-OS teams).
18
+ const PUBLIC_FONTS = path.join(process.cwd(), "public", "fonts");
19
+
20
+ type BrandFontFile = {
21
+ path: string;
22
+ weight: number | string;
23
+ style: "normal" | "italic";
24
+ format: "woff2" | "woff";
25
+ };
26
+
27
+ type BrandFontEntry = {
28
+ id: string;
29
+ label: string;
30
+ stack: string;
31
+ kind?: "sans" | "serif" | "mono";
32
+ files?: BrandFontFile[];
33
+ };
34
+
35
+ type FontsFile = {
36
+ $comment?: string;
37
+ fonts: BrandFontEntry[];
38
+ };
39
+
40
+ type JsonOp =
41
+ | { action: "rename"; id: string; label: string }
42
+ | { action: "remove"; id: string }
43
+ | { action: "reorder"; ids: string[] };
44
+
45
+ async function readFile(): Promise<FontsFile> {
46
+ const raw = await fs.readFile(FONTS_PATH, "utf8");
47
+ const parsed = JSON.parse(raw) as FontsFile;
48
+ if (!Array.isArray(parsed.fonts)) {
49
+ throw new Error("brand-fonts.json missing fonts array");
50
+ }
51
+ return parsed;
52
+ }
53
+
54
+ async function writeFile(file: FontsFile) {
55
+ await fs.writeFile(FONTS_PATH, JSON.stringify(file, null, 2) + "\n", "utf8");
56
+ }
57
+
58
+ function isValidId(id: string) {
59
+ return /^[a-z][a-z0-9-]{0,63}$/.test(id);
60
+ }
61
+
62
+ function rebuildFonts(): Promise<void> {
63
+ // Spawn `pnpm build:fonts` so the generated brand-fonts.css matches the
64
+ // updated brand-fonts.json. Non-blocking: we kick it off and resolve once
65
+ // it finishes so the UI's success response reflects the on-disk state.
66
+ return new Promise((resolve) => {
67
+ const child = spawn("pnpm", ["build:fonts"], { cwd: process.cwd() });
68
+ child.on("close", () => resolve());
69
+ child.on("error", () => resolve()); // log? no — just don't crash the route.
70
+ });
71
+ }
72
+
73
+ function parseWeight(raw: FormDataEntryValue | null, fallback = 400): number | string {
74
+ if (raw === null) return fallback;
75
+ const v = String(raw).trim();
76
+ if (!v) return fallback;
77
+ // Accept variable-font ranges like "100 900" verbatim.
78
+ if (/^\d+\s+\d+$/.test(v)) return v;
79
+ const n = Number(v);
80
+ return Number.isFinite(n) ? n : fallback;
81
+ }
82
+
83
+ function parseStyle(raw: FormDataEntryValue | null): "normal" | "italic" {
84
+ return String(raw ?? "normal").toLowerCase() === "italic" ? "italic" : "normal";
85
+ }
86
+
87
+ function fileExtFormat(name: string): "woff2" | "woff" | null {
88
+ const ext = name.toLowerCase().split(".").pop();
89
+ if (ext === "woff2") return "woff2";
90
+ if (ext === "woff") return "woff";
91
+ return null;
92
+ }
93
+
94
+ export async function GET() {
95
+ if (process.env.NODE_ENV !== "development") {
96
+ return NextResponse.json({ ok: false, error: "dev-only" }, { status: 403 });
97
+ }
98
+ try {
99
+ const file = await readFile();
100
+ return NextResponse.json({ ok: true, fonts: file.fonts });
101
+ } catch (err) {
102
+ return NextResponse.json(
103
+ { ok: false, error: (err as Error).message },
104
+ { status: 500 },
105
+ );
106
+ }
107
+ }
108
+
109
+ export async function POST(request: Request) {
110
+ if (process.env.NODE_ENV !== "development") {
111
+ return NextResponse.json({ ok: false, error: "dev-only" }, { status: 403 });
112
+ }
113
+
114
+ const contentType = request.headers.get("content-type") ?? "";
115
+
116
+ // ─── multipart upload: register a new self-hosted family ────────────────
117
+ if (contentType.includes("multipart/form-data")) {
118
+ let form: FormData;
119
+ try {
120
+ form = await request.formData();
121
+ } catch (err) {
122
+ return NextResponse.json(
123
+ { ok: false, error: `Invalid multipart: ${(err as Error).message}` },
124
+ { status: 400 },
125
+ );
126
+ }
127
+
128
+ const id = String(form.get("id") ?? "").trim();
129
+ const label = String(form.get("label") ?? "").trim();
130
+ const stack = String(form.get("stack") ?? "").trim();
131
+ const kindRaw = String(form.get("kind") ?? "sans").trim();
132
+ const kind: "sans" | "serif" | "mono" =
133
+ kindRaw === "serif" || kindRaw === "mono" ? kindRaw : "sans";
134
+ if (!isValidId(id) || !label || !stack) {
135
+ return NextResponse.json(
136
+ { ok: false, error: "Need id (lowercase slug), label, and stack" },
137
+ { status: 400 },
138
+ );
139
+ }
140
+
141
+ const files = form.getAll("files").filter((v): v is File => v instanceof File);
142
+ if (files.length === 0) {
143
+ return NextResponse.json(
144
+ { ok: false, error: "Upload at least one font file" },
145
+ { status: 400 },
146
+ );
147
+ }
148
+
149
+ // Each file's metadata comes in parallel arrays: weights[i], styles[i].
150
+ const weights = form.getAll("weights");
151
+ const styles = form.getAll("styles");
152
+
153
+ let existing: FontsFile;
154
+ try {
155
+ existing = await readFile();
156
+ } catch {
157
+ existing = { fonts: [] };
158
+ }
159
+
160
+ // Reject duplicate ids — UI should rename or remove first.
161
+ if (existing.fonts.some((f) => f.id === id)) {
162
+ return NextResponse.json(
163
+ { ok: false, error: `Font id "${id}" already exists` },
164
+ { status: 409 },
165
+ );
166
+ }
167
+
168
+ await fs.mkdir(PKG_FONTS, { recursive: true });
169
+ await fs.mkdir(PUBLIC_FONTS, { recursive: true });
170
+
171
+ const written: BrandFontFile[] = [];
172
+ for (let i = 0; i < files.length; i++) {
173
+ const f = files[i];
174
+ const format = fileExtFormat(f.name);
175
+ if (!format) {
176
+ return NextResponse.json(
177
+ { ok: false, error: `Unsupported file: ${f.name} (use woff2 or woff)` },
178
+ { status: 400 },
179
+ );
180
+ }
181
+ const weight = parseWeight(weights[i] ?? null);
182
+ const style = parseStyle(styles[i] ?? null);
183
+ // Stable deterministic filename so re-uploads overwrite the same path.
184
+ const out = `${id}-${String(weight).replace(/\s+/g, "_")}-${style}.${format}`;
185
+ const buf = Buffer.from(await f.arrayBuffer());
186
+ // Canonical write — this is the copy that ships in the npm tarball.
187
+ await fs.writeFile(path.join(PKG_FONTS, out), buf);
188
+ // Mirror for the dev preview's /fonts/<file> static-asset route.
189
+ await fs.writeFile(path.join(PUBLIC_FONTS, out), buf);
190
+ written.push({
191
+ path: `/fonts/${out}`,
192
+ weight,
193
+ style,
194
+ format,
195
+ });
196
+ }
197
+
198
+ const entry: BrandFontEntry = { id, label, stack, kind, files: written };
199
+ existing.fonts.push(entry);
200
+ await writeFile(existing);
201
+ await rebuildFonts();
202
+
203
+ return NextResponse.json({ ok: true, font: entry, fonts: existing.fonts });
204
+ }
205
+
206
+ // ─── JSON action: rename / remove / reorder ─────────────────────────────
207
+ let op: JsonOp;
208
+ try {
209
+ op = (await request.json()) as JsonOp;
210
+ } catch {
211
+ return NextResponse.json({ ok: false, error: "Invalid JSON" }, { status: 400 });
212
+ }
213
+
214
+ let file: FontsFile;
215
+ try {
216
+ file = await readFile();
217
+ } catch (err) {
218
+ return NextResponse.json(
219
+ { ok: false, error: `Could not read brand-fonts.json: ${(err as Error).message}` },
220
+ { status: 500 },
221
+ );
222
+ }
223
+
224
+ if (op.action === "rename") {
225
+ if (!op.id || !op.label?.trim()) {
226
+ return NextResponse.json(
227
+ { ok: false, error: "Need id and non-empty label" },
228
+ { status: 400 },
229
+ );
230
+ }
231
+ const target = file.fonts.find((f) => f.id === op.id);
232
+ if (!target) {
233
+ return NextResponse.json(
234
+ { ok: false, error: `No font with id ${op.id}` },
235
+ { status: 404 },
236
+ );
237
+ }
238
+ target.label = op.label.trim();
239
+ await writeFile(file);
240
+ await rebuildFonts();
241
+ return NextResponse.json({ ok: true, fonts: file.fonts, action: "rename" });
242
+ }
243
+
244
+ if (op.action === "remove") {
245
+ if (!op.id) {
246
+ return NextResponse.json({ ok: false, error: "Need id" }, { status: 400 });
247
+ }
248
+ const target = file.fonts.find((f) => f.id === op.id);
249
+ if (!target) {
250
+ return NextResponse.json(
251
+ { ok: false, error: `No font with id ${op.id}` },
252
+ { status: 404 },
253
+ );
254
+ }
255
+ // Best-effort delete the actual files too — never fatal. Removes from
256
+ // both the canonical (packages/core/src/fonts/) and mirror (public/fonts/)
257
+ // locations so the next `pnpm build` doesn't drag stale binaries along.
258
+ if (target.files) {
259
+ for (const f of target.files) {
260
+ const fileName = f.path.replace(/^\/fonts\//, "");
261
+ const pkgAbs = path.join(PKG_FONTS, fileName);
262
+ const publicAbs = path.join(PUBLIC_FONTS, fileName);
263
+ for (const p of [pkgAbs, publicAbs]) {
264
+ try {
265
+ await fs.unlink(p);
266
+ } catch {
267
+ // already gone
268
+ }
269
+ }
270
+ }
271
+ }
272
+ file.fonts = file.fonts.filter((f) => f.id !== op.id);
273
+ await writeFile(file);
274
+ await rebuildFonts();
275
+ return NextResponse.json({ ok: true, fonts: file.fonts, action: "remove" });
276
+ }
277
+
278
+ if (op.action === "reorder") {
279
+ if (!Array.isArray(op.ids)) {
280
+ return NextResponse.json({ ok: false, error: "Need ids array" }, { status: 400 });
281
+ }
282
+ const byId = new Map(file.fonts.map((f) => [f.id, f]));
283
+ const next: BrandFontEntry[] = [];
284
+ for (const id of op.ids) {
285
+ const entry = byId.get(id);
286
+ if (entry) next.push(entry);
287
+ }
288
+ for (const f of file.fonts) {
289
+ if (!op.ids.includes(f.id)) next.push(f);
290
+ }
291
+ file.fonts = next;
292
+ await writeFile(file);
293
+ await rebuildFonts();
294
+ return NextResponse.json({ ok: true, fonts: file.fonts, action: "reorder" });
295
+ }
296
+
297
+ return NextResponse.json(
298
+ { ok: false, error: `Unknown action: ${(op as { action?: string }).action}` },
299
+ { status: 400 },
300
+ );
301
+ }
@@ -0,0 +1,146 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { NextResponse } from "next/server";
4
+ import { sanitizeSvg } from "@behavioral-agentic-design-system/core/lib/svg-sanitize";
5
+
6
+ const MARK_PATH = path.join(process.cwd(), "brand-mark.json");
7
+ const PUBLIC_PATH = path.join(process.cwd(), "public", "brand-mark.svg");
8
+
9
+ type MarkFile = {
10
+ $comment?: string;
11
+ svg: string | null;
12
+ original: string | null;
13
+ };
14
+
15
+ async function readFile(): Promise<MarkFile> {
16
+ const raw = await fs.readFile(MARK_PATH, "utf8");
17
+ const parsed = JSON.parse(raw) as MarkFile;
18
+ return {
19
+ $comment: parsed.$comment,
20
+ svg: parsed.svg ?? null,
21
+ original: parsed.original ?? null,
22
+ };
23
+ }
24
+
25
+ async function writeFile(file: MarkFile) {
26
+ await fs.writeFile(MARK_PATH, JSON.stringify(file, null, 2) + "\n", "utf8");
27
+ }
28
+
29
+ async function writePublic(svg: string | null) {
30
+ if (svg === null) {
31
+ try {
32
+ await fs.unlink(PUBLIC_PATH);
33
+ } catch {
34
+ // already absent
35
+ }
36
+ return;
37
+ }
38
+ await fs.mkdir(path.dirname(PUBLIC_PATH), { recursive: true });
39
+ await fs.writeFile(PUBLIC_PATH, svg, "utf8");
40
+ }
41
+
42
+ export async function GET() {
43
+ if (process.env.NODE_ENV !== "development") {
44
+ return NextResponse.json({ ok: false, error: "dev-only" }, { status: 403 });
45
+ }
46
+ try {
47
+ const file = await readFile();
48
+ return NextResponse.json({ ok: true, svg: file.svg, original: file.original });
49
+ } catch (err) {
50
+ return NextResponse.json(
51
+ { ok: false, error: (err as Error).message },
52
+ { status: 500 },
53
+ );
54
+ }
55
+ }
56
+
57
+ export async function POST(request: Request) {
58
+ if (process.env.NODE_ENV !== "development") {
59
+ return NextResponse.json({ ok: false, error: "dev-only" }, { status: 403 });
60
+ }
61
+
62
+ let body: { svg?: string };
63
+ try {
64
+ body = (await request.json()) as { svg?: string };
65
+ } catch {
66
+ return NextResponse.json({ ok: false, error: "Invalid JSON" }, { status: 400 });
67
+ }
68
+
69
+ const original = (body.svg ?? "").trim();
70
+ if (!original) {
71
+ return NextResponse.json(
72
+ { ok: false, error: "Missing svg field" },
73
+ { status: 400 },
74
+ );
75
+ }
76
+ if (original.length > 200_000) {
77
+ return NextResponse.json(
78
+ { ok: false, error: "SVG exceeds 200KB cap" },
79
+ { status: 413 },
80
+ );
81
+ }
82
+
83
+ const result = sanitizeSvg(original);
84
+ if (!result.ok) {
85
+ return NextResponse.json({ ok: false, error: result.error }, { status: 400 });
86
+ }
87
+
88
+ let existing: MarkFile;
89
+ try {
90
+ existing = await readFile();
91
+ } catch {
92
+ existing = { svg: null, original: null };
93
+ }
94
+ const next: MarkFile = {
95
+ $comment: existing.$comment,
96
+ svg: result.svg,
97
+ original,
98
+ };
99
+
100
+ try {
101
+ await writeFile(next);
102
+ await writePublic(result.svg);
103
+ } catch (err) {
104
+ return NextResponse.json(
105
+ { ok: false, error: `Write failed: ${(err as Error).message}` },
106
+ { status: 500 },
107
+ );
108
+ }
109
+
110
+ return NextResponse.json({
111
+ ok: true,
112
+ svg: next.svg,
113
+ original: next.original,
114
+ monotone: result.monotone,
115
+ colorCount: result.colorCount,
116
+ });
117
+ }
118
+
119
+ export async function DELETE() {
120
+ if (process.env.NODE_ENV !== "development") {
121
+ return NextResponse.json({ ok: false, error: "dev-only" }, { status: 403 });
122
+ }
123
+
124
+ let existing: MarkFile;
125
+ try {
126
+ existing = await readFile();
127
+ } catch {
128
+ existing = { svg: null, original: null };
129
+ }
130
+ const cleared: MarkFile = {
131
+ $comment: existing.$comment,
132
+ svg: null,
133
+ original: null,
134
+ };
135
+ try {
136
+ await writeFile(cleared);
137
+ await writePublic(null);
138
+ } catch (err) {
139
+ return NextResponse.json(
140
+ { ok: false, error: `Write failed: ${(err as Error).message}` },
141
+ { status: 500 },
142
+ );
143
+ }
144
+
145
+ return NextResponse.json({ ok: true, svg: null, original: null });
146
+ }
@@ -7,16 +7,19 @@ const execAsync = promisify(exec);
7
7
  const ROOT = process.cwd();
8
8
 
9
9
  function isAllowed(rel: string) {
10
- // Only allow paths inside layer-*/ to prevent traversal abuse.
10
+ // Only allow paths inside layer-*/ or specific allowlisted files to prevent traversal abuse.
11
11
  const norm = path.normalize(rel);
12
12
  if (norm.startsWith("..") || path.isAbsolute(norm)) return false;
13
- return /^layer-[\w-]+\//.test(norm) && /\.(md|json)$/.test(norm);
13
+ const isLayerFile = /^layer-[\w-]+\//.test(norm) && /\.(md|json)$/.test(norm);
14
+ const isTokensFile = norm === "packages/core/src/tokens.json";
15
+ return isLayerFile || isTokensFile;
14
16
  }
15
17
 
16
18
  export async function GET(request: Request) {
17
- if (process.env.NODE_ENV !== "development") {
18
- return Response.json({ error: "dev-only" }, { status: 403 });
19
- }
19
+ // Public read: layer file contents are the open-source design system.
20
+ // Path is sanitized via isAllowed() so traversal can't escape the
21
+ // allowlist. POST below stays dev-only because Vercel's filesystem is
22
+ // read-only and writes would silently no-op there.
20
23
  const url = new URL(request.url);
21
24
  const rel = url.searchParams.get("path") ?? "";
22
25
  if (!isAllowed(rel)) {
package/src/api/layers.ts CHANGED
@@ -29,6 +29,17 @@ function listFiles(dir: string): string[] {
29
29
  return out;
30
30
  }
31
31
 
32
+ function sortLayerFiles(slug: string, files: string[]): string[] {
33
+ // Brand Voice: intro.md first, then framework.md, then others alphabetically
34
+ if (slug === "layer-1-foundation") {
35
+ const intro = files.find((f) => f.endsWith("intro.md"));
36
+ const framework = files.find((f) => f.endsWith("framework.md"));
37
+ const rest = files.filter((f) => !f.endsWith("intro.md") && !f.endsWith("framework.md")).sort();
38
+ return [intro, framework, ...rest].filter((f): f is string => f !== undefined);
39
+ }
40
+ return files.sort();
41
+ }
42
+
32
43
  function prettifyLayerName(slug: string) {
33
44
  // "layer-2-ethics-responsibility" → "2 · Ethics & Responsibility"
34
45
  const [, num, ...rest] = slug.split("-");
@@ -37,13 +48,25 @@ function prettifyLayerName(slug: string) {
37
48
  }
38
49
 
39
50
  export async function GET() {
40
- if (process.env.NODE_ENV !== "development") {
41
- return Response.json({ error: "dev-only" }, { status: 403 });
42
- }
51
+ // Public read: the layer file structure is the open-source design system
52
+ // itself, safe to expose. Writes (POST in layers/file.ts) stay dev-only
53
+ // because Vercel's serverless filesystem is read-only and we don't want
54
+ // saves to silently no-op in production.
43
55
  const layers = listLayers().map((slug) => ({
44
56
  slug,
45
57
  label: prettifyLayerName(slug),
46
- files: listFiles(path.join(ROOT, slug)).sort(),
58
+ files: sortLayerFiles(slug, listFiles(path.join(ROOT, slug))),
47
59
  }));
60
+
61
+ // Add tokens.json from Primitive Tokens layer (layer-3)
62
+ const foundationIndex = layers.findIndex((l) => l.slug === "layer-3-primitive-tokens");
63
+ if (foundationIndex !== -1) {
64
+ const tokensPath = path.join(ROOT, "packages/core/src/tokens.json");
65
+ if (fs.existsSync(tokensPath)) {
66
+ layers[foundationIndex].files.push("packages/core/src/tokens.json");
67
+ layers[foundationIndex].files = sortLayerFiles(layers[foundationIndex].slug, layers[foundationIndex].files);
68
+ }
69
+ }
70
+
48
71
  return Response.json({ layers });
49
72
  }
@@ -0,0 +1,50 @@
1
+ import { NextRequest, NextResponse } from "next/server";
2
+
3
+ // POST /api/site-auth handles the password submission from /site-login.
4
+ // Validates against SITE_PASSWORD and sets an httpOnly cookie containing
5
+ // the password value. The middleware (middleware.ts at the repo root)
6
+ // reads the cookie on every subsequent request. Returns a 303 redirect
7
+ // either back to the requested `next` path (success) or back to
8
+ // /site-login with ?error=1 (mismatch).
9
+
10
+ const COOKIE_NAME = "bads_site_auth";
11
+ const COOKIE_MAX_AGE_SECONDS = 60 * 60 * 24 * 30; // 30 days
12
+
13
+ export async function POST(req: NextRequest) {
14
+ const password = process.env.SITE_PASSWORD;
15
+ if (!password) {
16
+ return NextResponse.json(
17
+ { ok: false, error: "Site gate not configured" },
18
+ { status: 400 },
19
+ );
20
+ }
21
+
22
+ const form = await req.formData();
23
+ const submitted = String(form.get("password") || "");
24
+ const requestedNext = String(form.get("next") || "/");
25
+
26
+ if (submitted !== password) {
27
+ const url = new URL("/site-login", req.url);
28
+ url.searchParams.set("next", requestedNext);
29
+ url.searchParams.set("error", "1");
30
+ return NextResponse.redirect(url, 303);
31
+ }
32
+
33
+ const redirect = NextResponse.redirect(
34
+ new URL(sanitizeNext(requestedNext), req.url),
35
+ 303,
36
+ );
37
+ redirect.cookies.set(COOKIE_NAME, password, {
38
+ path: "/",
39
+ httpOnly: true,
40
+ sameSite: "lax",
41
+ secure: process.env.NODE_ENV === "production",
42
+ maxAge: COOKIE_MAX_AGE_SECONDS,
43
+ });
44
+ return redirect;
45
+ }
46
+
47
+ function sanitizeNext(next: string): string {
48
+ if (next.startsWith("/") && !next.startsWith("//")) return next;
49
+ return "/";
50
+ }
@@ -1,7 +1,7 @@
1
1
  import Cards from "@/components/examples/cards";
2
2
  export default function CardsPreview() {
3
3
  return (
4
- <div className="@container h-full w-full">
4
+ <div className="@container h-full w-full bg-muted">
5
5
  <Cards />
6
6
  </div>
7
7
  );
@@ -25,6 +25,16 @@ import {
25
25
  DialogTitle,
26
26
  DialogTrigger,
27
27
  } from "@behavioral-agentic-design-system/core/components/ui/dialog";
28
+ import {
29
+ BottomSheet,
30
+ BottomSheetClose,
31
+ BottomSheetContent,
32
+ BottomSheetDescription,
33
+ BottomSheetFooter,
34
+ BottomSheetHeader,
35
+ BottomSheetTitle,
36
+ BottomSheetTrigger,
37
+ } from "@behavioral-agentic-design-system/core/components/ui/bottom-sheet";
28
38
  import { Sparkles, Info } from "lucide-react";
29
39
 
30
40
  // Stable, deterministic data for ScrollArea — never use Math.random in
@@ -39,7 +49,7 @@ function Section({ title, children }: { title: string; children: React.ReactNode
39
49
  return (
40
50
  <section className="space-y-4">
41
51
  <h2 className="text-2xl font-semibold tracking-tight">{title}</h2>
42
- <div className="rounded-lg border bg-card p-6">{children}</div>
52
+ <Card className="p-6 shadow-none">{children}</Card>
43
53
  </section>
44
54
  );
45
55
  }
@@ -226,6 +236,73 @@ export default function ComponentsPreview() {
226
236
  </ul>
227
237
  </ScrollArea>
228
238
  </Section>
239
+
240
+ <Section title="BottomSheet">
241
+ <div className="flex flex-wrap gap-3">
242
+ {/* Default — grab handle + close button */}
243
+ <BottomSheet>
244
+ <BottomSheetTrigger asChild>
245
+ <Button variant="outline">Open</Button>
246
+ </BottomSheetTrigger>
247
+ <BottomSheetContent>
248
+ <BottomSheetHeader>
249
+ <BottomSheetTitle>Display density</BottomSheetTitle>
250
+ <BottomSheetDescription>
251
+ Choose how much information shows on each row.
252
+ </BottomSheetDescription>
253
+ </BottomSheetHeader>
254
+ </BottomSheetContent>
255
+ </BottomSheet>
256
+
257
+ {/* No handle variant */}
258
+ <BottomSheet>
259
+ <BottomSheetTrigger asChild>
260
+ <Button variant="outline">No handle</Button>
261
+ </BottomSheetTrigger>
262
+ <BottomSheetContent showHandle={false}>
263
+ <BottomSheetHeader>
264
+ <BottomSheetTitle>No grab handle</BottomSheetTitle>
265
+ <BottomSheetDescription>
266
+ Handle hidden via showHandle={"{false}"}.
267
+ </BottomSheetDescription>
268
+ </BottomSheetHeader>
269
+ </BottomSheetContent>
270
+ </BottomSheet>
271
+
272
+ {/* Realistic action sheet with a footer */}
273
+ <BottomSheet>
274
+ <BottomSheetTrigger asChild>
275
+ <Button>View settings</Button>
276
+ </BottomSheetTrigger>
277
+ <BottomSheetContent>
278
+ <BottomSheetHeader>
279
+ <BottomSheetTitle>View settings</BottomSheetTitle>
280
+ <BottomSheetDescription>
281
+ These apply to the Components board only.
282
+ </BottomSheetDescription>
283
+ </BottomSheetHeader>
284
+ <div className="flex flex-col gap-5 px-4 py-2">
285
+ <div className="flex items-center justify-between">
286
+ <Label htmlFor="density-group">Group by status</Label>
287
+ <Switch id="density-group" defaultChecked />
288
+ </div>
289
+ <div className="flex items-center justify-between">
290
+ <Label htmlFor="density-sub">Show sub-tasks</Label>
291
+ <Switch id="density-sub" />
292
+ </div>
293
+ </div>
294
+ <BottomSheetFooter className="flex-row justify-end gap-2">
295
+ <BottomSheetClose asChild>
296
+ <Button variant="ghost">Cancel</Button>
297
+ </BottomSheetClose>
298
+ <BottomSheetClose asChild>
299
+ <Button>Apply</Button>
300
+ </BottomSheetClose>
301
+ </BottomSheetFooter>
302
+ </BottomSheetContent>
303
+ </BottomSheet>
304
+ </div>
305
+ </Section>
229
306
  </div>
230
307
  </div>
231
308
  );
@@ -0,0 +1,5 @@
1
+ import IconsLibrary from "@/components/examples/icons/icons";
2
+
3
+ export default function IconsPreview() {
4
+ return <IconsLibrary />;
5
+ }