@behavioral-agentic-design-system/core 0.22.0 → 0.24.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.22.0",
3
+ "version": "0.24.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": "MIT",
6
6
  "author": "Matthew Stephens <work@matthewstephens.com> (https://github.com/matthewlarn)",
@@ -44,7 +44,8 @@
44
44
  "bads-check-stories": "scripts/check-stories.mjs",
45
45
  "bads-fix-stories": "scripts/fix-stories.mjs",
46
46
  "bads-generate-stories": "scripts/generate-stories.cjs",
47
- "bads-oklch-to-hex": "scripts/oklch-to-hex.cjs"
47
+ "bads-oklch-to-hex": "scripts/oklch-to-hex.cjs",
48
+ "bads-size-audit": "scripts/size-audit.cjs"
48
49
  },
49
50
  "exports": {
50
51
  ".": "./src/index.ts",
@@ -111,7 +112,8 @@
111
112
  "clsx": "^2.1.0",
112
113
  "react-markdown": "^10.1.0",
113
114
  "remark-gfm": "^4.0.1",
114
- "tailwind-merge": "^3.0.0"
115
+ "tailwind-merge": "^3.0.0",
116
+ "uqr": "^0.1.3"
115
117
  },
116
118
  "peerDependencies": {
117
119
  "@radix-ui/react-accordion": "*",
@@ -121,11 +123,11 @@
121
123
  "@radix-ui/react-collapsible": "*",
122
124
  "@radix-ui/react-context-menu": "*",
123
125
  "@radix-ui/react-dialog": "*",
124
- "@radix-ui/react-navigation-menu": "*",
125
126
  "@radix-ui/react-dropdown-menu": "*",
126
127
  "@radix-ui/react-hover-card": "*",
127
128
  "@radix-ui/react-label": "*",
128
129
  "@radix-ui/react-menubar": "*",
130
+ "@radix-ui/react-navigation-menu": "*",
129
131
  "@radix-ui/react-popover": "*",
130
132
  "@radix-ui/react-progress": "*",
131
133
  "@radix-ui/react-radio-group": "*",
@@ -0,0 +1,147 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * size-audit — flag raw `<button>` CTAs at text-xs without the escape
4
+ * hatch. Companion to `a11y-lint.js`. Wired via `pnpm size-audit`.
5
+ *
6
+ * Why a separate script: a11y-lint already catches text-[<14>px] (sub-
7
+ * 14px floor) but text-xs IS 14px in BADS' scale, so it passes a11y.
8
+ * The size-audit rule is *brand consistency*, not accessibility: every
9
+ * CTA across a BADS-derived consumer should be the same size, and the
10
+ * default size is text-sm (16px). text-xs on a clickable CTA is a
11
+ * brand regression even though it clears AAA.
12
+ *
13
+ * Scan scope:
14
+ * app/ — BADS showcase + preview surfaces
15
+ * components/ — BADS shared component compositions
16
+ * packages/core/src/components/ — BADS primitives
17
+ *
18
+ * Client forks adapt the SCAN_ROOTS to their own tree (typical:
19
+ * app/_content/, app/<shell>/, app/<prototype>/).
20
+ *
21
+ * Detection: line contains BOTH `text-xs` AND a className for a
22
+ * `<button>` opening tag in the same line OR within 8 lines after.
23
+ * The escape hatch is `// allow-text-xs-cta` on the line above the
24
+ * button.
25
+ *
26
+ * Run:
27
+ * pnpm size-audit # report violations, exit 1 on fail
28
+ * pnpm size-audit:warn # report but exit 0 (advisory)
29
+ * node scripts/size-audit.js path/to.tsx # scan a specific file
30
+ *
31
+ * Rule code: BADS-2. (BADS-1 = raw <button> not using BADS Button.)
32
+ */
33
+
34
+ 'use strict';
35
+
36
+ const fs = require('fs');
37
+ const path = require('path');
38
+
39
+ // Packaged as the `bads-size-audit` bin: runs against the CONSUMER repo
40
+ // (cwd), so prototype repos and client forks get the CTA size contract
41
+ // without copying the script. Pass scan roots as positional args
42
+ // (`bads-size-audit app components`) or rely on the defaults below.
43
+ const ROOT = process.cwd();
44
+ const advisory = process.argv.includes('--warn');
45
+ const argPaths = process.argv.slice(2).filter((a) => !a.startsWith('--'));
46
+ const argRoots = argPaths.filter((p) => fs.existsSync(p) && fs.statSync(p).isDirectory());
47
+ const explicitPaths = argPaths.filter((p) => !argRoots.includes(p));
48
+
49
+ const SCAN_ROOTS = argRoots.length
50
+ ? argRoots
51
+ : ['app', 'components', 'src'].filter((r) => fs.existsSync(path.join(ROOT, r)));
52
+
53
+ function walk(dir, out = []) {
54
+ if (!fs.existsSync(dir)) return out;
55
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
56
+ if (entry.name.startsWith('.') || entry.name === 'node_modules') continue;
57
+ const full = path.join(dir, entry.name);
58
+ if (entry.isDirectory()) {
59
+ walk(full, out);
60
+ } else if (/\.tsx?$/.test(entry.name)) {
61
+ out.push(full);
62
+ }
63
+ }
64
+ return out;
65
+ }
66
+
67
+ const files = explicitPaths.length
68
+ ? explicitPaths.map((p) => path.resolve(p))
69
+ : SCAN_ROOTS.flatMap((r) => walk(path.join(ROOT, r)));
70
+
71
+ const issues = [];
72
+
73
+ function flag(file, line, rule, message) {
74
+ issues.push({ file: path.relative(ROOT, file), line, rule, message });
75
+ }
76
+
77
+ const BUTTON_OPEN = /<button\b/;
78
+ const TEXT_XS = /\btext-xs\b/;
79
+ const ESCAPE_HATCH = /allow-text-xs-cta/;
80
+
81
+ for (const file of files) {
82
+ let src;
83
+ try { src = fs.readFileSync(file, 'utf8'); } catch { continue; }
84
+ if (file.endsWith('.test.ts') || file.endsWith('.spec.ts')) continue;
85
+ if (file.endsWith('.stories.tsx')) continue;
86
+ if (src.startsWith('/* GENERATED')) continue;
87
+ // The BADS Button primitive itself defines text-xs for the `xs` size
88
+ // variant — that's legitimate. The rule applies to consumers, not the
89
+ // primitive's own definition.
90
+ if (file.endsWith('/components/ui/button.tsx')) continue;
91
+ if (file.endsWith('/components/ui/toggle.tsx')) continue;
92
+
93
+ const lines = src.split('\n');
94
+
95
+ for (let i = 0; i < lines.length; i++) {
96
+ if (!BUTTON_OPEN.test(lines[i])) continue;
97
+
98
+ let foundTextXs = false;
99
+ let classLine = -1;
100
+ for (let j = i; j < Math.min(i + 8, lines.length); j++) {
101
+ if (TEXT_XS.test(lines[j])) {
102
+ foundTextXs = true;
103
+ classLine = j;
104
+ break;
105
+ }
106
+ if (/^[^"']*>/.test(lines[j].replace(/className=\{[^}]*\}/, ''))) {
107
+ if (j > i) break;
108
+ }
109
+ }
110
+ if (!foundTextXs) continue;
111
+
112
+ let escaped = false;
113
+ for (let k = i - 1; k >= Math.max(0, i - 3); k--) {
114
+ if (ESCAPE_HATCH.test(lines[k])) {
115
+ escaped = true;
116
+ break;
117
+ }
118
+ }
119
+ if (escaped) continue;
120
+
121
+ flag(file, classLine + 1, 'BADS-2',
122
+ `Raw <button> with text-xs is below the CTA size contract (text-sm / 16px). Bump to text-sm, or add "// allow-text-xs-cta" on the line above the <button> with a reason (see prompts/cta-size-contract.md).`);
123
+ }
124
+ }
125
+
126
+ if (issues.length === 0) {
127
+ console.log('✓ size-audit: every CTA reads at text-sm. No size divergence.');
128
+ process.exit(0);
129
+ }
130
+
131
+ const grouped = issues.reduce((acc, it) => {
132
+ (acc[it.file] = acc[it.file] || []).push(it);
133
+ return acc;
134
+ }, {});
135
+
136
+ for (const file of Object.keys(grouped).sort()) {
137
+ console.log(`\n${file}`);
138
+ for (const it of grouped[file]) {
139
+ const tag = `[${it.rule}]`;
140
+ console.log(` L${it.line} ${tag.padEnd(10)} ${it.message}`);
141
+ }
142
+ }
143
+
144
+ console.log(
145
+ `\n${issues.length} CTA size violation${issues.length === 1 ? '' : 's'} across ${Object.keys(grouped).length} file${Object.keys(grouped).length === 1 ? '' : 's'}.`,
146
+ );
147
+ process.exit(advisory ? 0 : 1);
@@ -33,7 +33,6 @@ const ALLOWED_ROOT_MD = new Set([
33
33
  "DESIGN_SYSTEM_STACK.md",
34
34
  "ENGINEERING.md",
35
35
  "MIGRATION_UNRENAME.md",
36
- "PROPOSAL-bads-as-libraries.md",
37
36
  "SECURITY.md",
38
37
  "STORYBOOK_RULE.md",
39
38
  "V0_SYSTEM.md",
@@ -70,11 +70,36 @@ const sourceSerif = Source_Serif_4({
70
70
  variable: "--font-source-serif",
71
71
  });
72
72
 
73
- // Title and description derive from brand.config so each fork's tab title and
74
- // open-graph metadata reflects its own identity without overriding this file.
73
+ // Title, description, and social/canonical metadata all derive from
74
+ // brand.config so each fork reflects its own identity without overriding this
75
+ // file. `url` (optional) drives metadataBase + canonical + the OG url;
76
+ // `description` (optional) is the meta/OG copy, falling back to the tagline.
77
+ // Read defensively so forks that predate these fields still build.
78
+ const siteTitle = brand.tagline ? `${brand.name} — ${brand.tagline}` : brand.name;
79
+ const siteDescription =
80
+ (brand as { description?: string }).description ??
81
+ brand.tagline ??
82
+ "Interactive design system and component dashboard";
83
+ const siteUrl = (brand as { url?: string }).url;
84
+
75
85
  export const metadata: Metadata = {
76
- title: brand.tagline ? `${brand.name} — ${brand.tagline}` : brand.name,
77
- description: brand.tagline ?? "Interactive design system and component dashboard",
86
+ ...(siteUrl ? { metadataBase: new URL(siteUrl) } : {}),
87
+ title: siteTitle,
88
+ description: siteDescription,
89
+ applicationName: brand.name,
90
+ openGraph: {
91
+ title: siteTitle,
92
+ description: siteDescription,
93
+ siteName: brand.name,
94
+ type: "website",
95
+ ...(siteUrl ? { url: siteUrl } : {}),
96
+ },
97
+ twitter: {
98
+ card: "summary_large_image",
99
+ title: siteTitle,
100
+ description: siteDescription,
101
+ },
102
+ ...(siteUrl ? { alternates: { canonical: siteUrl } } : {}),
78
103
  };
79
104
 
80
105
  export default function RootLayout({
@@ -0,0 +1,103 @@
1
+ import { ImageResponse } from "next/og";
2
+ import { brand } from "@/brand.config";
3
+
4
+ // Branded social-preview card (Open Graph + Twitter), derived entirely from
5
+ // brand.config so every fork gets its own image with zero per-fork code. A
6
+ // consumer surfaces it by re-exporting this route from its own app/ dir:
7
+ //
8
+ // // app/opengraph-image.tsx
9
+ // export { default, size, contentType, alt } from
10
+ // "@behavioral-agentic-design-system/core/app/opengraph-image";
11
+ //
12
+ // Kept font-free on purpose: it uses next/og's built-in font so the build
13
+ // never depends on a network font fetch (satori also can't read the woff2
14
+ // files @core ships). Hierarchy comes from size + color, not weight.
15
+
16
+ export const size = { width: 1200, height: 630 };
17
+ export const contentType = "image/png";
18
+ export const alt = brand.tagline
19
+ ? `${brand.name} — ${brand.tagline}`
20
+ : brand.name;
21
+
22
+ export default function OpengraphImage() {
23
+ // Default brand color if the fork hasn't pinned one (BADS ships colors: []).
24
+ // #025fff doubles as BADS' own audited primary, so both look intentional.
25
+ const accent =
26
+ (brand.colors?.[0]?.primary as string | undefined) ?? "#025fff";
27
+ const description =
28
+ (brand as { description?: string }).description ?? brand.tagline ?? "";
29
+
30
+ return new ImageResponse(
31
+ (
32
+ <div
33
+ style={{
34
+ height: "100%",
35
+ width: "100%",
36
+ display: "flex",
37
+ flexDirection: "column",
38
+ justifyContent: "space-between",
39
+ background: "#0a0b0d",
40
+ color: "#ffffff",
41
+ padding: "88px",
42
+ fontFamily: "sans-serif",
43
+ }}
44
+ >
45
+ <div style={{ display: "flex", alignItems: "center", gap: "22px" }}>
46
+ <div
47
+ style={{
48
+ width: "56px",
49
+ height: "56px",
50
+ borderRadius: "16px",
51
+ background: accent,
52
+ }}
53
+ />
54
+ <div
55
+ style={{
56
+ fontSize: "28px",
57
+ letterSpacing: "0.28em",
58
+ color: "#8b95a7",
59
+ textTransform: "uppercase",
60
+ }}
61
+ >
62
+ Design System
63
+ </div>
64
+ </div>
65
+
66
+ <div
67
+ style={{
68
+ display: "flex",
69
+ flexDirection: "column",
70
+ gap: "28px",
71
+ }}
72
+ >
73
+ <div style={{ fontSize: "116px", lineHeight: 1, color: "#ffffff" }}>
74
+ {brand.name}
75
+ </div>
76
+ {description ? (
77
+ <div
78
+ style={{
79
+ fontSize: "40px",
80
+ lineHeight: 1.3,
81
+ color: "#b7c0cf",
82
+ maxWidth: "940px",
83
+ }}
84
+ >
85
+ {description}
86
+ </div>
87
+ ) : null}
88
+ </div>
89
+
90
+ <div
91
+ style={{
92
+ display: "flex",
93
+ height: "12px",
94
+ width: "100%",
95
+ borderRadius: "999px",
96
+ background: accent,
97
+ }}
98
+ />
99
+ </div>
100
+ ),
101
+ { ...size },
102
+ );
103
+ }