@behavioral-agentic-design-system/core 0.6.0 → 0.8.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 (64) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +35 -6
  3. package/scripts/bads-sync.mjs +1 -1
  4. package/scripts/build-fonts.cjs +15 -8
  5. package/scripts/build-tokens.cjs +139 -23
  6. package/src/api/brand-fonts.ts +27 -6
  7. package/src/api/layers/file.ts +4 -3
  8. package/src/api/layers.ts +41 -12
  9. package/src/api/onboarding-extract.ts +435 -0
  10. package/src/api/onboarding.ts +82 -0
  11. package/src/api/site-auth.ts +50 -0
  12. package/src/app/font-ready.tsx +1 -1
  13. package/src/app/layout.tsx +9 -3
  14. package/src/app/preview/components/page.tsx +78 -1
  15. package/src/app/preview/icons/page.tsx +5 -0
  16. package/src/app/shell.tsx +90 -23
  17. package/src/app/site-login/page.tsx +82 -0
  18. package/src/brand-fonts.css +5 -0
  19. package/src/components/Foundations/Colors.stories.tsx +10 -1
  20. package/src/components/Foundations/Motion.stories.tsx +66 -0
  21. package/src/components/customize/letter-spacing.tsx +3 -2
  22. package/src/components/customize/type-scale.tsx +3 -2
  23. package/src/components/customize-tab.tsx +11 -7
  24. package/src/components/home-tab.tsx +498 -235
  25. package/src/components/layers-tab.tsx +313 -10
  26. package/src/components/onboarding-wizard.tsx +1421 -0
  27. package/src/components/ui/alert.tsx +2 -2
  28. package/src/components/ui/bottom-sheet.tsx +124 -0
  29. package/src/components/ui/button.tsx +1 -1
  30. package/src/components/ui/chart.tsx +115 -14
  31. package/src/components/ui/checkbox.tsx +3 -2
  32. package/src/components/ui/dialog.tsx +7 -4
  33. package/src/components/ui/dropdown-menu.tsx +4 -0
  34. package/src/components/ui/index.ts +1 -0
  35. package/src/components/ui/popover.tsx +6 -0
  36. package/src/components/ui/radio-group.tsx +4 -3
  37. package/src/components/ui/scroll-area.tsx +5 -0
  38. package/src/components/ui/select.tsx +4 -0
  39. package/src/components/ui/sheet.tsx +8 -1
  40. package/src/components/ui/slider.tsx +22 -7
  41. package/src/components/ui/switch.tsx +3 -3
  42. package/src/components/ui/tabs.tsx +6 -0
  43. package/src/components/ui/tooltip.tsx +4 -0
  44. package/src/fonts/HyperlegibleSans-Bold.woff2 +0 -0
  45. package/src/fonts/HyperlegibleSans-BoldItalic.woff2 +0 -0
  46. package/src/fonts/HyperlegibleSans-Italic.woff2 +0 -0
  47. package/src/fonts/HyperlegibleSans-Medium.woff2 +0 -0
  48. package/src/fonts/HyperlegibleSans-MediumItalic.woff2 +0 -0
  49. package/src/fonts/HyperlegibleSans-Regular.woff2 +0 -0
  50. package/src/fonts/InterVariable-Italic.woff2 +0 -0
  51. package/src/fonts/InterVariable.woff2 +0 -0
  52. package/src/fonts.css +99 -0
  53. package/src/hooks/use-global-primary-color.ts +114 -68
  54. package/src/hooks/use-global-serif-font.ts +1 -1
  55. package/src/hooks/use-portal-theme-class.tsx +90 -0
  56. package/src/lib/storage.ts +2 -2
  57. package/src/styles.css +151 -61
  58. package/src/tokens.default.json +4 -4
  59. package/src/tokens.json +159 -162
  60. package/src/app/preview/login/page.tsx +0 -5
  61. package/src/app/preview/mail/page.tsx +0 -4
  62. package/src/app/preview/pricing/page.tsx +0 -4
  63. package/src/components/admin-menu.stories.tsx +0 -68
  64. package/src/components/admin-menu.tsx +0 -59
@@ -0,0 +1,435 @@
1
+ import { NextResponse } from "next/server";
2
+ import { load, type CheerioAPI } from "cheerio";
3
+
4
+ const FETCH_TIMEOUT_MS = 12_000;
5
+ const USER_AGENT =
6
+ "Mozilla/5.0 (compatible; BADS-Onboarding/1.0; +https://github.com/dazzag24/behavioral-agentic-design-system)";
7
+
8
+ export type ExtractedColor = {
9
+ value: string;
10
+ count: number;
11
+ source: "css" | "inline" | "meta";
12
+ };
13
+
14
+ export type ExtractedFont = {
15
+ family: string;
16
+ source: "google-fonts" | "css" | "inline";
17
+ url?: string;
18
+ };
19
+
20
+ export type ExtractedLogo = {
21
+ kind: "svg" | "image";
22
+ url?: string;
23
+ svg?: string;
24
+ width?: number;
25
+ height?: number;
26
+ };
27
+
28
+ export type ExtractResult = {
29
+ url: string;
30
+ finalUrl: string;
31
+ title: string | null;
32
+ siteName: string | null;
33
+ description: string | null;
34
+ headline: string | null;
35
+ subhead: string | null;
36
+ ctas: string[];
37
+ colors: ExtractedColor[];
38
+ fonts: ExtractedFont[];
39
+ logo: ExtractedLogo | null;
40
+ themeColor: string | null;
41
+ warnings: string[];
42
+ };
43
+
44
+ function normalizeUrl(input: string): string | null {
45
+ const trimmed = input.trim();
46
+ if (!trimmed) return null;
47
+ const withProtocol = /^https?:\/\//i.test(trimmed) ? trimmed : `https://${trimmed}`;
48
+ try {
49
+ const u = new URL(withProtocol);
50
+ if (u.protocol !== "https:" && u.protocol !== "http:") return null;
51
+ return u.toString();
52
+ } catch {
53
+ return null;
54
+ }
55
+ }
56
+
57
+ async function fetchHtml(url: string): Promise<{ html: string; finalUrl: string }> {
58
+ const controller = new AbortController();
59
+ const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
60
+ try {
61
+ const res = await fetch(url, {
62
+ headers: {
63
+ "User-Agent": USER_AGENT,
64
+ Accept: "text/html,application/xhtml+xml",
65
+ "Accept-Language": "en-US,en;q=0.9",
66
+ },
67
+ redirect: "follow",
68
+ signal: controller.signal,
69
+ });
70
+ if (!res.ok) {
71
+ throw new Error(`Fetch failed: ${res.status} ${res.statusText}`);
72
+ }
73
+ const html = await res.text();
74
+ return { html, finalUrl: res.url || url };
75
+ } finally {
76
+ clearTimeout(timer);
77
+ }
78
+ }
79
+
80
+ const MAX_STYLESHEETS = 6;
81
+ const MAX_STYLESHEET_BYTES = 800_000;
82
+
83
+ async function fetchStylesheet(url: string): Promise<string | null> {
84
+ try {
85
+ const controller = new AbortController();
86
+ const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
87
+ const res = await fetch(url, {
88
+ headers: { "User-Agent": USER_AGENT, Accept: "text/css,*/*;q=0.1" },
89
+ signal: controller.signal,
90
+ });
91
+ clearTimeout(timer);
92
+ if (!res.ok) return null;
93
+ const ct = res.headers.get("content-type") ?? "";
94
+ // Many CDNs serve CSS with text/plain or no header; trust the fetch worked.
95
+ if (ct && !ct.includes("css") && !ct.includes("text")) return null;
96
+ const text = await res.text();
97
+ if (text.length > MAX_STYLESHEET_BYTES) return text.slice(0, MAX_STYLESHEET_BYTES);
98
+ return text;
99
+ } catch {
100
+ return null;
101
+ }
102
+ }
103
+
104
+ async function collectExternalCss($: CheerioAPI, baseUrl: string): Promise<string> {
105
+ const urls: string[] = [];
106
+ $('link[rel="stylesheet"][href], link[rel*="stylesheet"][href]').each((_, el) => {
107
+ const href = $(el).attr("href");
108
+ if (!href) return;
109
+ try {
110
+ urls.push(new URL(href, baseUrl).toString());
111
+ } catch {}
112
+ });
113
+ if (!urls.length) return "";
114
+ const limited = urls.slice(0, MAX_STYLESHEETS);
115
+ const results = await Promise.all(limited.map((u) => fetchStylesheet(u)));
116
+ return results.filter((r): r is string => Boolean(r)).join("\n");
117
+ }
118
+
119
+ const COLOR_RE =
120
+ /#[0-9a-f]{3,8}\b|rgba?\([^)]+\)|hsla?\([^)]+\)|oklch\([^)]+\)|oklab\([^)]+\)/gi;
121
+
122
+ const NEUTRAL_GRAYS = new Set([
123
+ "#000",
124
+ "#000000",
125
+ "#fff",
126
+ "#ffffff",
127
+ "#fafafa",
128
+ "#f5f5f5",
129
+ "#eaeaea",
130
+ "#e5e5e5",
131
+ "#d4d4d4",
132
+ "#a3a3a3",
133
+ "#737373",
134
+ "#525252",
135
+ "#404040",
136
+ "#262626",
137
+ "#171717",
138
+ "#0a0a0a",
139
+ ]);
140
+
141
+ function normalizeColor(value: string): string {
142
+ const v = value.trim().toLowerCase();
143
+ // Expand short hex (#abc → #aabbcc) for consistent counting
144
+ if (/^#[0-9a-f]{3}$/.test(v)) {
145
+ return `#${v[1]}${v[1]}${v[2]}${v[2]}${v[3]}${v[3]}`;
146
+ }
147
+ return v;
148
+ }
149
+
150
+ function isInterestingColor(value: string): boolean {
151
+ const v = normalizeColor(value);
152
+ if (NEUTRAL_GRAYS.has(v)) return false;
153
+ // Pure transparent
154
+ if (/^rgba?\([^)]*,\s*0(\.0+)?\s*\)$/.test(v)) return false;
155
+ // Hex8 with alpha < 0x40 (shadow-tier transparency)
156
+ if (/^#[0-9a-f]{6}([0-3][0-9a-f])$/.test(v)) return false;
157
+ // Modern hex shorthand #abcd → 4-digit form with low alpha (#xxx0–#xxx5)
158
+ if (/^#[0-9a-f]{3}[0-5]$/.test(v)) return false;
159
+ // rgba/hsla with alpha < 0.3 — usually shadows or hairline borders
160
+ const alphaMatch = /^(rgba|hsla)\([^)]*,\s*(0?\.\d+|0)\s*\)$/i.exec(v);
161
+ if (alphaMatch) {
162
+ const a = parseFloat(alphaMatch[2]);
163
+ if (a < 0.3) return false;
164
+ }
165
+ return true;
166
+ }
167
+
168
+ function extractColors($: CheerioAPI, externalCss: string): ExtractedColor[] {
169
+ const counts = new Map<string, ExtractedColor>();
170
+ const bump = (raw: string, source: ExtractedColor["source"]) => {
171
+ if (!isInterestingColor(raw)) return;
172
+ const key = normalizeColor(raw);
173
+ const existing = counts.get(key);
174
+ if (existing) {
175
+ existing.count += 1;
176
+ } else {
177
+ counts.set(key, { value: key, count: 1, source });
178
+ }
179
+ };
180
+
181
+ $("style").each((_, el) => {
182
+ const css = $(el).text();
183
+ css.match(COLOR_RE)?.forEach((m) => bump(m, "css"));
184
+ });
185
+
186
+ if (externalCss) {
187
+ externalCss.match(COLOR_RE)?.forEach((m) => bump(m, "css"));
188
+ }
189
+
190
+ $("[style]").each((_, el) => {
191
+ const style = $(el).attr("style") ?? "";
192
+ style.match(COLOR_RE)?.forEach((m) => bump(m, "inline"));
193
+ });
194
+
195
+ const themeColor = $('meta[name="theme-color"]').attr("content");
196
+ if (themeColor) bump(themeColor, "meta");
197
+
198
+ return Array.from(counts.values()).sort((a, b) => b.count - a.count);
199
+ }
200
+
201
+ const FONT_FAMILY_RE = /font-family\s*:\s*([^;}"]+)/gi;
202
+ const GOOGLE_FONTS_FAMILY_RE = /family=([^&"]+)/gi;
203
+
204
+ function cleanFontStack(stack: string): string {
205
+ return stack
206
+ .replace(/!important/i, "")
207
+ .split(",")[0]
208
+ .trim()
209
+ .replace(/^["']|["']$/g, "")
210
+ .replace(/\+/g, " ");
211
+ }
212
+
213
+ function extractFonts($: CheerioAPI, externalCss: string): ExtractedFont[] {
214
+ const seen = new Map<string, ExtractedFont>();
215
+ const add = (family: string, source: ExtractedFont["source"], url?: string) => {
216
+ const cleaned = cleanFontStack(family);
217
+ if (!cleaned || cleaned.length > 80) return;
218
+ if (/^(serif|sans-serif|monospace|system-ui|inherit|initial|unset|cursive|fantasy|ui-sans-serif|ui-serif|ui-monospace|ui-rounded)$/i.test(cleaned)) return;
219
+ // Skip CSS custom-property references — they're not real font names
220
+ if (/^var\(/.test(cleaned)) return;
221
+ // Skip vendor-prefixed system fonts (-apple-system, -webkit-system, etc.)
222
+ if (/^-[a-z]+-/.test(cleaned)) return;
223
+ const key = cleaned.toLowerCase();
224
+ if (!seen.has(key)) seen.set(key, { family: cleaned, source, url });
225
+ };
226
+
227
+ // Google Fonts links
228
+ $('link[rel="stylesheet"][href*="fonts.googleapis.com"], link[href*="fonts.googleapis.com"]').each(
229
+ (_, el) => {
230
+ const href = $(el).attr("href") ?? "";
231
+ const families = href.matchAll(GOOGLE_FONTS_FAMILY_RE);
232
+ for (const match of families) {
233
+ const family = match[1].split(":")[0];
234
+ add(family, "google-fonts", href);
235
+ }
236
+ },
237
+ );
238
+
239
+ // CSS font-family declarations (inline <style>)
240
+ $("style").each((_, el) => {
241
+ const css = $(el).text();
242
+ const matches = css.matchAll(FONT_FAMILY_RE);
243
+ for (const match of matches) {
244
+ add(match[1], "css");
245
+ }
246
+ });
247
+
248
+ // External stylesheets
249
+ if (externalCss) {
250
+ const matches = externalCss.matchAll(FONT_FAMILY_RE);
251
+ for (const match of matches) {
252
+ add(match[1], "css");
253
+ }
254
+ }
255
+
256
+ // Inline font-family
257
+ $("[style*='font-family']").each((_, el) => {
258
+ const style = $(el).attr("style") ?? "";
259
+ const matches = style.matchAll(FONT_FAMILY_RE);
260
+ for (const match of matches) {
261
+ add(match[1], "inline");
262
+ }
263
+ });
264
+
265
+ return Array.from(seen.values());
266
+ }
267
+
268
+ async function fetchSvg(url: string): Promise<string | null> {
269
+ try {
270
+ const controller = new AbortController();
271
+ const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
272
+ const res = await fetch(url, {
273
+ headers: { "User-Agent": USER_AGENT },
274
+ signal: controller.signal,
275
+ });
276
+ clearTimeout(timer);
277
+ if (!res.ok) return null;
278
+ const ct = res.headers.get("content-type") ?? "";
279
+ if (!ct.includes("svg")) return null;
280
+ const text = await res.text();
281
+ if (text.length > 64 * 1024) return null;
282
+ return text;
283
+ } catch {
284
+ return null;
285
+ }
286
+ }
287
+
288
+ async function extractLogo($: CheerioAPI, baseUrl: string): Promise<ExtractedLogo | null> {
289
+ // Inline header SVG — scan the first <header> for a small SVG that looks like a logo
290
+ const headerSvg = $("header svg, nav svg").first();
291
+ if (headerSvg.length) {
292
+ const html = $.html(headerSvg);
293
+ if (html && html.length < 16 * 1024) {
294
+ return { kind: "svg", svg: html };
295
+ }
296
+ }
297
+
298
+ // Header <img> — first <img> inside <header> or <nav>
299
+ const headerImg = $("header img, nav img").first();
300
+ if (headerImg.length) {
301
+ const src = headerImg.attr("src");
302
+ if (src) {
303
+ try {
304
+ const abs = new URL(src, baseUrl).toString();
305
+ if (abs.endsWith(".svg")) {
306
+ const svg = await fetchSvg(abs);
307
+ if (svg) return { kind: "svg", svg };
308
+ }
309
+ return { kind: "image", url: abs };
310
+ } catch {}
311
+ }
312
+ }
313
+
314
+ // Apple touch icon (usually higher quality than favicon)
315
+ const apple = $('link[rel="apple-touch-icon"]').attr("href");
316
+ if (apple) {
317
+ try {
318
+ return { kind: "image", url: new URL(apple, baseUrl).toString() };
319
+ } catch {}
320
+ }
321
+
322
+ // og:image
323
+ const og = $('meta[property="og:image"]').attr("content");
324
+ if (og) {
325
+ try {
326
+ return { kind: "image", url: new URL(og, baseUrl).toString() };
327
+ } catch {}
328
+ }
329
+
330
+ // Favicon
331
+ const icon = $('link[rel~="icon"]').attr("href");
332
+ if (icon) {
333
+ try {
334
+ return { kind: "image", url: new URL(icon, baseUrl).toString() };
335
+ } catch {}
336
+ }
337
+
338
+ return null;
339
+ }
340
+
341
+ function extractCopy($: CheerioAPI): {
342
+ title: string | null;
343
+ siteName: string | null;
344
+ description: string | null;
345
+ headline: string | null;
346
+ subhead: string | null;
347
+ ctas: string[];
348
+ } {
349
+ const title = $("title").first().text().trim() || null;
350
+ const siteName = $('meta[property="og:site_name"]').attr("content")?.trim() || null;
351
+ const description =
352
+ $('meta[name="description"]').attr("content")?.trim() ||
353
+ $('meta[property="og:description"]').attr("content")?.trim() ||
354
+ null;
355
+ const headline = $("h1").first().text().trim().replace(/\s+/g, " ") || null;
356
+ const subhead = $("h2").first().text().trim().replace(/\s+/g, " ") || null;
357
+
358
+ const ctas: string[] = [];
359
+ const ctaSeen = new Set<string>();
360
+ $("a[role='button'], button, a.btn, a[class*='button'], a[class*='cta']").each((_, el) => {
361
+ if (ctas.length >= 8) return;
362
+ const text = $(el).text().trim().replace(/\s+/g, " ");
363
+ if (text && text.length < 40 && !ctaSeen.has(text.toLowerCase())) {
364
+ ctaSeen.add(text.toLowerCase());
365
+ ctas.push(text);
366
+ }
367
+ });
368
+
369
+ return { title, siteName, description, headline, subhead, ctas };
370
+ }
371
+
372
+ export async function POST(request: Request) {
373
+ let payload: { url?: string };
374
+ try {
375
+ payload = (await request.json()) as { url?: string };
376
+ } catch {
377
+ return NextResponse.json({ ok: false, error: "Invalid JSON" }, { status: 400 });
378
+ }
379
+
380
+ const url = normalizeUrl(payload.url ?? "");
381
+ if (!url) {
382
+ return NextResponse.json(
383
+ { ok: false, error: "Provide a valid http(s) URL." },
384
+ { status: 400 },
385
+ );
386
+ }
387
+
388
+ let html: string;
389
+ let finalUrl: string;
390
+ try {
391
+ const fetched = await fetchHtml(url);
392
+ html = fetched.html;
393
+ finalUrl = fetched.finalUrl;
394
+ } catch (error) {
395
+ const message = error instanceof Error ? error.message : "Failed to fetch the URL";
396
+ return NextResponse.json({ ok: false, error: message }, { status: 502 });
397
+ }
398
+
399
+ const $ = load(html);
400
+ const warnings: string[] = [];
401
+
402
+ // Fetch external stylesheets in parallel with the logo lookup so we can
403
+ // extract colors/fonts even when the page doesn't inline its CSS.
404
+ const [externalCss, logo] = await Promise.all([
405
+ collectExternalCss($, finalUrl).catch(() => ""),
406
+ extractLogo($, finalUrl).catch(() => null),
407
+ ]);
408
+
409
+ const copy = extractCopy($);
410
+ const colors = extractColors($, externalCss).slice(0, 12);
411
+ const fonts = extractFonts($, externalCss).slice(0, 8);
412
+ const themeColor = $('meta[name="theme-color"]').attr("content")?.trim() || null;
413
+
414
+ if (!colors.length) warnings.push("No colors detected — the site may use external stylesheets.");
415
+ if (!fonts.length) warnings.push("No fonts detected — the site may use external font hosts.");
416
+ if (!logo) warnings.push("No logo detected — fall back to manual upload.");
417
+
418
+ const result: ExtractResult = {
419
+ url,
420
+ finalUrl,
421
+ title: copy.title,
422
+ siteName: copy.siteName,
423
+ description: copy.description,
424
+ headline: copy.headline,
425
+ subhead: copy.subhead,
426
+ ctas: copy.ctas,
427
+ colors,
428
+ fonts,
429
+ logo,
430
+ themeColor,
431
+ warnings,
432
+ };
433
+
434
+ return NextResponse.json({ ok: true, result });
435
+ }
@@ -0,0 +1,82 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { NextResponse } from "next/server";
4
+
5
+ const ONBOARDING_PATH = path.join(process.cwd(), "onboarding-brief.json");
6
+
7
+ type SavePayload = {
8
+ draft?: unknown;
9
+ brief?: string;
10
+ agentPrompt?: string;
11
+ };
12
+
13
+ function isReasonableText(value: unknown) {
14
+ return typeof value === "string" && value.length <= 200_000;
15
+ }
16
+
17
+ export async function GET() {
18
+ if (process.env.NODE_ENV !== "development") {
19
+ return NextResponse.json({ ok: false, error: "dev-only" }, { status: 403 });
20
+ }
21
+
22
+ try {
23
+ const raw = await fs.readFile(ONBOARDING_PATH, "utf8");
24
+ return NextResponse.json({ ok: true, file: JSON.parse(raw) });
25
+ } catch (error) {
26
+ const code = (error as NodeJS.ErrnoException).code;
27
+ if (code === "ENOENT") {
28
+ return NextResponse.json({ ok: true, file: null });
29
+ }
30
+ return NextResponse.json(
31
+ { ok: false, error: (error as Error).message },
32
+ { status: 500 },
33
+ );
34
+ }
35
+ }
36
+
37
+ export async function POST(request: Request) {
38
+ if (process.env.NODE_ENV !== "development") {
39
+ return NextResponse.json({ ok: false, error: "dev-only" }, { status: 403 });
40
+ }
41
+
42
+ let payload: SavePayload;
43
+ try {
44
+ payload = (await request.json()) as SavePayload;
45
+ } catch {
46
+ return NextResponse.json({ ok: false, error: "Invalid JSON" }, { status: 400 });
47
+ }
48
+
49
+ if (!isReasonableText(payload.brief)) {
50
+ return NextResponse.json(
51
+ { ok: false, error: "Missing or oversized onboarding brief" },
52
+ { status: 400 },
53
+ );
54
+ }
55
+
56
+ if (payload.agentPrompt !== undefined && !isReasonableText(payload.agentPrompt)) {
57
+ return NextResponse.json(
58
+ { ok: false, error: "Oversized agent prompt" },
59
+ { status: 400 },
60
+ );
61
+ }
62
+
63
+ const file = {
64
+ $comment:
65
+ "Generated by the BADS in-app onboarding wizard. Review before using as setup input.",
66
+ savedAt: new Date().toISOString(),
67
+ draft: payload.draft ?? null,
68
+ brief: payload.brief,
69
+ agentPrompt: payload.agentPrompt ?? "",
70
+ };
71
+
72
+ try {
73
+ await fs.writeFile(ONBOARDING_PATH, JSON.stringify(file, null, 2) + "\n", "utf8");
74
+ } catch (error) {
75
+ return NextResponse.json(
76
+ { ok: false, error: (error as Error).message },
77
+ { status: 500 },
78
+ );
79
+ }
80
+
81
+ return NextResponse.json({ ok: true, path: "onboarding-brief.json" });
82
+ }
@@ -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
+ }
@@ -27,7 +27,7 @@ export function FontReady() {
27
27
 
28
28
  let alreadyReady = false;
29
29
  try {
30
- alreadyReady = document.fonts.check("1em 'Season'");
30
+ alreadyReady = document.fonts.check("1em 'Hyperlegible Sans'");
31
31
  } catch {
32
32
  // fonts.check throws if the font name is unknown — treat as not ready.
33
33
  }
@@ -93,9 +93,16 @@ export default function RootLayout({
93
93
  <head>
94
94
  <link
95
95
  rel="preload"
96
- href="/fonts/SeasonCollectionVF-TRIAL.ttf"
96
+ href="/fonts/HyperlegibleSans-Regular.woff2"
97
97
  as="font"
98
- type="font/ttf"
98
+ type="font/woff2"
99
+ crossOrigin=""
100
+ />
101
+ <link
102
+ rel="preload"
103
+ href="/fonts/HyperlegibleSans-Bold.woff2"
104
+ as="font"
105
+ type="font/woff2"
99
106
  crossOrigin=""
100
107
  />
101
108
  <script
@@ -131,7 +138,6 @@ export default function RootLayout({
131
138
  system: "ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif"
132
139
  }, ${JSON.stringify(brandSansMap)});
133
140
  var SERIF = {
134
- "season-serif": "'Season Serif', 'Season', ui-serif, Georgia, serif",
135
141
  georgia: "Georgia, ui-serif, serif",
136
142
  lora: "var(--font-lora), 'Lora', Georgia, ui-serif, serif",
137
143
  "source-serif": "var(--font-source-serif), 'Source Serif 4', Georgia, ui-serif, serif",