@behavioral-agentic-design-system/core 0.2.1 → 0.3.1

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 (49) hide show
  1. package/package.json +37 -4
  2. package/scripts/bads-sync.mjs +81 -0
  3. package/scripts/build-tokens.cjs +487 -0
  4. package/src/api/bads-update-check.ts +151 -0
  5. package/src/api/brand-colors.ts +180 -0
  6. package/src/api/layers/file.ts +71 -0
  7. package/src/api/layers.ts +49 -0
  8. package/src/api/save-tokens.ts +280 -0
  9. package/src/app/font-ready.tsx +51 -0
  10. package/src/app/layout.tsx +152 -0
  11. package/src/app/page.tsx +267 -0
  12. package/src/app/preview/cards/page.tsx +8 -0
  13. package/src/app/preview/components/page.tsx +232 -0
  14. package/src/app/preview/dark-mode-client.tsx +24 -0
  15. package/src/app/preview/dashboard/page.tsx +4 -0
  16. package/src/app/preview/global-font-client.tsx +36 -0
  17. package/src/app/preview/layout.tsx +13 -0
  18. package/src/app/preview/mail/page.tsx +4 -0
  19. package/src/app/preview/pricing/page.tsx +4 -0
  20. package/src/app/preview/typography/page.tsx +11 -0
  21. package/src/app/providers.tsx +49 -0
  22. package/src/components/Foundations/Colors.stories.tsx +85 -0
  23. package/src/components/Foundations/Motion.stories.tsx +169 -0
  24. package/src/components/Foundations/Radius.stories.tsx +36 -0
  25. package/src/components/Foundations/Shadows.stories.tsx +30 -0
  26. package/src/components/Foundations/Spacing.stories.tsx +35 -0
  27. package/src/components/Foundations/Typography.stories.tsx +68 -0
  28. package/src/components/bads-update-banner.tsx +120 -0
  29. package/src/components/customize/design-controls.tsx +165 -0
  30. package/src/components/customize/font-pickers.tsx +118 -0
  31. package/src/components/customize/letter-spacing.tsx +105 -0
  32. package/src/components/customize/save-bar.tsx +379 -0
  33. package/src/components/customize/theme-io.tsx +245 -0
  34. package/src/components/customize/type-scale.tsx +134 -0
  35. package/src/components/customize-tab.tsx +502 -0
  36. package/src/components/home-tab.tsx +1227 -0
  37. package/src/components/layers-tab.tsx +225 -0
  38. package/src/components/ui/alert.tsx +5 -1
  39. package/src/hooks/use-global-design-controls.ts +117 -0
  40. package/src/hooks/use-global-mono-font.ts +73 -0
  41. package/src/hooks/use-global-primary-color.ts +544 -0
  42. package/src/hooks/use-global-sans-font.ts +98 -0
  43. package/src/hooks/use-global-serif-font.ts +77 -0
  44. package/src/hooks/use-global-theme.ts +259 -0
  45. package/src/hooks/use-global-type-scale.ts +141 -0
  46. package/src/hooks/use-sync-type-scale.ts +51 -0
  47. package/src/hooks/use-token-overrides.ts +98 -0
  48. package/src/styles.css +40 -6
  49. package/src/tokens.json +86 -5
package/package.json CHANGED
@@ -1,14 +1,23 @@
1
1
  {
2
2
  "name": "@behavioral-agentic-design-system/core",
3
- "version": "0.2.1",
4
- "description": "BADS core — tokens and base shadcn/ui components for the Behavioral Agentic Design System.",
3
+ "version": "0.3.1",
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",
7
- "sideEffects": false,
7
+ "sideEffects": [
8
+ "**/*.css",
9
+ "./src/app/**",
10
+ "./src/app/preview/**"
11
+ ],
8
12
  "files": [
9
13
  "src",
14
+ "scripts",
10
15
  "README.md"
11
16
  ],
17
+ "bin": {
18
+ "bads-build-tokens": "scripts/build-tokens.cjs",
19
+ "bads-sync": "scripts/bads-sync.mjs"
20
+ },
12
21
  "exports": {
13
22
  ".": "./src/index.ts",
14
23
  "./package.json": "./package.json",
@@ -18,7 +27,31 @@
18
27
  "./lib/*": "./src/lib/*.ts",
19
28
  "./hooks/*": "./src/hooks/*.ts",
20
29
  "./components/ui": "./src/components/ui/index.ts",
21
- "./components/ui/*": "./src/components/ui/*.tsx"
30
+ "./components/ui/*": "./src/components/ui/*.tsx",
31
+ "./components/customize-tab": "./src/components/customize-tab.tsx",
32
+ "./components/home-tab": "./src/components/home-tab.tsx",
33
+ "./components/layers-tab": "./src/components/layers-tab.tsx",
34
+ "./components/bads-update-banner": "./src/components/bads-update-banner.tsx",
35
+ "./components/customize/*": "./src/components/customize/*.tsx",
36
+ "./components/Foundations/*": "./src/components/Foundations/*.tsx",
37
+ "./app/page": "./src/app/page.tsx",
38
+ "./app/layout": "./src/app/layout.tsx",
39
+ "./app/providers": "./src/app/providers.tsx",
40
+ "./app/font-ready": "./src/app/font-ready.tsx",
41
+ "./app/preview/layout": "./src/app/preview/layout.tsx",
42
+ "./app/preview/dark-mode-client": "./src/app/preview/dark-mode-client.tsx",
43
+ "./app/preview/global-font-client": "./src/app/preview/global-font-client.tsx",
44
+ "./app/preview/cards/page": "./src/app/preview/cards/page.tsx",
45
+ "./app/preview/components/page": "./src/app/preview/components/page.tsx",
46
+ "./app/preview/dashboard/page": "./src/app/preview/dashboard/page.tsx",
47
+ "./app/preview/mail/page": "./src/app/preview/mail/page.tsx",
48
+ "./app/preview/pricing/page": "./src/app/preview/pricing/page.tsx",
49
+ "./app/preview/typography/page": "./src/app/preview/typography/page.tsx",
50
+ "./api/bads-update-check": "./src/api/bads-update-check.ts",
51
+ "./api/layers": "./src/api/layers.ts",
52
+ "./api/layers/file": "./src/api/layers/file.ts",
53
+ "./api/save-tokens": "./src/api/save-tokens.ts",
54
+ "./api/brand-colors": "./src/api/brand-colors.ts"
22
55
  },
23
56
  "publishConfig": {
24
57
  "access": "public"
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * bads:sync — pull the latest BADS package into a client fork.
4
+ *
5
+ * As of @core 0.3.0 the template shell (app routes, customize tab, theme
6
+ * hooks, build-tokens) ships in the package itself. Client forks become
7
+ * thin re-exports, so a sync is now nothing more than:
8
+ *
9
+ * pnpm update @behavioral-agentic-design-system/core --latest
10
+ * pnpm build:tokens
11
+ *
12
+ * Usage (from a client fork):
13
+ *
14
+ * pnpm bads:sync # update to latest
15
+ * pnpm bads:sync --check # dry-run, prints what would change
16
+ * pnpm bads:sync --version=0.3.0 # pin a specific version
17
+ *
18
+ * What it does NOT touch:
19
+ * - brand.config.ts, brand-colors.json, packages/core/src/tokens.json
20
+ * - styles/client-extras.css (your local CSS additions)
21
+ * - layer-1-brand-voice/, layer-2-ethics-responsibility/, layer-6-patterns-and-rules/
22
+ * - public/logos/, CLAUDE.md
23
+ */
24
+
25
+ import { execSync } from 'node:child_process';
26
+ import { existsSync, readFileSync } from 'node:fs';
27
+ import { resolve } from 'node:path';
28
+
29
+ const ROOT = process.cwd();
30
+
31
+ const args = process.argv.slice(2);
32
+ const dryRun = args.includes('--check');
33
+ const versionArg = args.find((a) => a.startsWith('--version='));
34
+ const pinnedVersion = versionArg ? versionArg.split('=')[1] : null;
35
+
36
+ function run(cmd) {
37
+ if (dryRun) {
38
+ console.log(`[dry-run] ${cmd}`);
39
+ return '';
40
+ }
41
+ return execSync(cmd, { cwd: ROOT, stdio: 'inherit' });
42
+ }
43
+
44
+ function read(file) {
45
+ return existsSync(file) ? readFileSync(file, 'utf8') : '';
46
+ }
47
+
48
+ function detectUpstream() {
49
+ const pkg = JSON.parse(read(resolve(ROOT, 'package.json')) || '{}');
50
+ const isUpstreamName = pkg.name === 'behavioral-agentic-design-system';
51
+ const hasClientIdentity = existsSync(resolve(ROOT, '.client-identity.json'));
52
+ return isUpstreamName && !hasClientIdentity;
53
+ }
54
+
55
+ function main() {
56
+ console.log('▸ bads:sync');
57
+
58
+ if (detectUpstream()) {
59
+ console.log('this is upstream BADS itself — nothing to sync.');
60
+ console.log('(client forks have a .client-identity.json or a renamed package.json)');
61
+ process.exit(0);
62
+ }
63
+
64
+ if (pinnedVersion) {
65
+ console.log(`▸ pinning @behavioral-agentic-design-system/core to ${pinnedVersion}`);
66
+ run(`pnpm add @behavioral-agentic-design-system/core@${pinnedVersion}`);
67
+ } else {
68
+ console.log('▸ updating @behavioral-agentic-design-system/core to latest');
69
+ run('pnpm update @behavioral-agentic-design-system/core --latest');
70
+ }
71
+
72
+ console.log('▸ regenerating tokens');
73
+ run('pnpm build:tokens');
74
+
75
+ console.log('\n✓ bads:sync complete');
76
+ console.log('next:');
77
+ console.log(' - run `pnpm dev` and walk the preview routes');
78
+ console.log(' - if anything looks off, check the BADS CHANGELOG');
79
+ }
80
+
81
+ main();
@@ -0,0 +1,487 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Build CSS files from tokens.json.
4
+ *
5
+ * tokens.json → packages/core/src/styles.css (published, consumer-facing)
6
+ * → styles/globals.css (preview app)
7
+ *
8
+ * tokens.json is the source of truth. Edit values there, then run:
9
+ *
10
+ * pnpm build:tokens
11
+ *
12
+ * Both files get the same theme block — light + dark modes, the @theme inline
13
+ * mapping for Tailwind v4, and the accessibility-floor text-* scale.
14
+ *
15
+ * Differences:
16
+ * - styles.css imports Atkinson Hyperlegible from Google Fonts (zero setup
17
+ * for consumers). globals.css does not — the preview app self-hosts
18
+ * Hyperlegible Sans via fonts.css.
19
+ * - globals.css has the additional `@import "tailwindcss"` and `@import
20
+ * "tw-animate-css"` lines so the dev preview works standalone. Consumers
21
+ * write those imports themselves and then import styles.css after.
22
+ */
23
+
24
+ const fs = require('fs');
25
+ const path = require('path');
26
+
27
+ // Run-from-consumer model: this script ships in @core's bin and is invoked
28
+ // from a consumer repo's CWD (via `pnpm build:tokens` → `bads-build-tokens`).
29
+ // Source-of-truth tokens.json and the generated CSS files live in the
30
+ // consumer's tree, not the package's node_modules copy. Resolving paths from
31
+ // process.cwd() means the same script works for upstream BADS (CWD = repo
32
+ // root) and for client forks alike.
33
+ const ROOT = process.cwd();
34
+ const TOKENS = path.join(ROOT, 'packages/core/src/tokens.json');
35
+ const PKG_CSS = path.join(ROOT, 'packages/core/src/styles.css');
36
+ const APP_CSS = path.join(ROOT, 'styles/globals.css');
37
+ const CLIENT_EXTRAS = path.join(ROOT, 'styles/client-extras.css');
38
+
39
+ // Client-extras: optional file in client forks for global rules that must
40
+ // survive every regen (e.g. .lucide { stroke-width: 1.5 }, button cursor,
41
+ // brand-font @import lines). Inlined into the preview-app globals.css ONLY,
42
+ // never the published package — the npm package stays canonical.
43
+ function readClientExtras() {
44
+ if (!fs.existsSync(CLIENT_EXTRAS)) return '';
45
+ const body = fs.readFileSync(CLIENT_EXTRAS, 'utf8').trim();
46
+ if (!body) return '';
47
+ return `\n/* ---- styles/client-extras.css (inlined by build-tokens) ---- */\n${body}\n`;
48
+ }
49
+
50
+ const clientExtras = readClientExtras();
51
+
52
+ const tokens = JSON.parse(fs.readFileSync(TOKENS, 'utf8'));
53
+
54
+ if (!tokens.theme || !tokens.theme.light || !tokens.theme.dark) {
55
+ console.error('tokens.json is missing theme.light / theme.dark — aborting.');
56
+ process.exit(1);
57
+ }
58
+
59
+ function emitVars(modeTokens) {
60
+ return Object.entries(modeTokens)
61
+ .map(([name, token]) => ` --${name}: ${token.$value};`)
62
+ .join('\n');
63
+ }
64
+
65
+ const lightVars = emitVars(tokens.theme.light);
66
+ const darkVars = emitVars(tokens.theme.dark);
67
+ const fontSans = tokens.fontFamily.sans.$value;
68
+ const fontMono = tokens.fontFamily.mono.$value;
69
+ const fontSerif = tokens.fontFamily.serif.$value;
70
+ const radius = tokens.borderRadius?.lg?.$value ?? '0.625rem';
71
+ const spacing = tokens.theme?.light?.spacing?.$value ?? '0.25rem';
72
+
73
+ // Animation token layer. Components use `transition-[var(--duration-base)]`
74
+ // and `ease-[var(--ease-out)]` (or motion-* utility names — see @theme
75
+ // inline below). Sourced from tokens.json so designer / token edits
76
+ // propagate without code change.
77
+ const dur = (k, fallback) => tokens.duration?.[k]?.$value ?? fallback;
78
+ const easing = (k, fallback) => tokens.easing?.[k]?.$value ?? fallback;
79
+ const durationFast = dur('fast', '150ms');
80
+ const durationBase = dur('base', '200ms');
81
+ const durationSlow = dur('slow', '300ms');
82
+ const easeIn = easing('ease-in', 'cubic-bezier(0.4, 0, 1, 1)');
83
+ const easeOut = easing('ease-out', 'cubic-bezier(0, 0, 0.2, 1)');
84
+ const easeInOut = easing('ease-in-out', 'cubic-bezier(0.4, 0, 0.2, 1)');
85
+ const easeSpring = easing('ease-spring', 'cubic-bezier(0.34, 1.56, 0.64, 1)');
86
+
87
+ const fontSize = (key, fallback) => tokens.fontSize?.[key]?.$value ?? fallback;
88
+ const textXs = fontSize('xs', '14px');
89
+ const textSm = fontSize('sm', '16px');
90
+ const textBase = fontSize('base', '18px');
91
+ const textLg = fontSize('lg', '20px');
92
+ const textXl = fontSize('xl', '24px');
93
+ const text2xl = fontSize('2xl', '28px');
94
+ const text3xl = fontSize('3xl', '32px');
95
+ // Marketing tier — display sizes for landing pages, hero blocks, and
96
+ // editorial layouts. Always emitted; Tailwind only generates the utilities
97
+ // that get used, so unused tiers cost nothing in the bundle.
98
+ const text4xl = fontSize('4xl', '36px');
99
+ const text5xl = fontSize('5xl', '48px');
100
+ const text6xl = fontSize('6xl', '60px');
101
+ const text7xl = fontSize('7xl', '72px');
102
+ const text8xl = fontSize('8xl', '96px');
103
+
104
+ const banner = `/* GENERATED FROM tokens.json — DO NOT EDIT BY HAND.
105
+ * Run \`pnpm build:tokens\` after changing tokens.json. */`;
106
+
107
+ // Shadow tokens, fully sourced from tokens.json so Sir's edits to the base
108
+ // opacity or per-level multipliers propagate without touching this script.
109
+ // - shadow.opacity: the base alpha (also overridable at runtime
110
+ // via documentElement.style.--shadow-opacity from
111
+ // the Customize tab's slider)
112
+ // - shadow.opacityMultiplier.{level}: per-level scaling on top of base,
113
+ // so 2xs/xs sit at 0.5× and 2xl sits at 2.5×
114
+ // for the elevation rhythm.
115
+ const shadowOpacity = tokens.shadow?.opacity?.$value ?? '0.10';
116
+ const shadowMul = (lvl, fallback) =>
117
+ tokens.shadow?.opacityMultiplier?.[lvl]?.$value ?? fallback;
118
+ const shadowAlpha = (lvl) =>
119
+ shadowMul(lvl, '1') === '1.0' || shadowMul(lvl, '1') === '1'
120
+ ? `var(--shadow-opacity)`
121
+ : `calc(var(--shadow-opacity) * ${shadowMul(lvl, '1')})`;
122
+ const shadowBlock = ` --shadow-opacity: ${shadowOpacity};
123
+ --shadow-2xs: 0 1px 3px 0px hsl(0 0% 0% / ${shadowAlpha('2xs')});
124
+ --shadow-xs: 0 1px 3px 0px hsl(0 0% 0% / ${shadowAlpha('xs')});
125
+ --shadow-sm: 0 1px 3px 0px hsl(0 0% 0% / ${shadowAlpha('sm')}), 0 1px 2px -1px hsl(0 0% 0% / ${shadowAlpha('sm')});
126
+ --shadow: 0 1px 3px 0px hsl(0 0% 0% / ${shadowAlpha('md')}), 0 1px 2px -1px hsl(0 0% 0% / ${shadowAlpha('md')});
127
+ --shadow-md: 0 1px 3px 0px hsl(0 0% 0% / ${shadowAlpha('md')}), 0 2px 4px -1px hsl(0 0% 0% / ${shadowAlpha('md')});
128
+ --shadow-lg: 0 1px 3px 0px hsl(0 0% 0% / ${shadowAlpha('lg')}), 0 4px 6px -1px hsl(0 0% 0% / ${shadowAlpha('lg')});
129
+ --shadow-xl: 0 1px 3px 0px hsl(0 0% 0% / ${shadowAlpha('xl')}), 0 8px 10px -1px hsl(0 0% 0% / ${shadowAlpha('xl')});
130
+ --shadow-2xl: 0 1px 3px 0px hsl(0 0% 0% / ${shadowAlpha('2xl')});`;
131
+
132
+ // Animation tokens emitted into :root from tokens.json. Components reference
133
+ // var(--duration-*) and var(--ease-*) so Sir's edits in tokens.json (or any
134
+ // future runtime override on documentElement) propagate without touching
135
+ // component source. The @theme inline block below maps these onto Tailwind's
136
+ // duration-* and ease-* utility names so classnames work too.
137
+ const motionBlock = ` --duration-fast: ${durationFast};
138
+ --duration-base: ${durationBase};
139
+ --duration-slow: ${durationSlow};
140
+ --ease-in: ${easeIn};
141
+ --ease-out: ${easeOut};
142
+ --ease-in-out: ${easeInOut};
143
+ --ease-spring: ${easeSpring};`;
144
+
145
+ // Chart palette derives from --primary by default so all data viz tracks the
146
+ // brand color picker. Each chart-N reads --primary's hue and rotates around
147
+ // it (35° steps) for multi-series distinguishability. --chart-lightness sets
148
+ // the absolute L per mode so dark backgrounds get readable lighter charts
149
+ // regardless of how dark the brand color is.
150
+ //
151
+ // Override mechanism (in priority order, last wins):
152
+ // 1. tokens.json theme.light/dark.chart-N → emitted into :root / .dark
153
+ // first, gets overridden by the derivation below.
154
+ // 2. This derivation block (default): chart-N = oklch(from --primary ...).
155
+ // 3. Per-token override via documentElement.style.--chart-N (Customize tab
156
+ // or any client code) — wins because inline styles beat :root.
157
+ //
158
+ // Uses CSS Color 5 relative-color syntax: Chrome 119+, Safari 18+, Firefox 128+.
159
+ // Lightness, hue rotations, and chroma damping all sourced from
160
+ // tokens.json's chart section so they're tunable without code change.
161
+ const chartLightnessLight = tokens.chart?.lightness?.light?.$value ?? '0.58';
162
+ const chartLightnessDark = tokens.chart?.lightness?.dark?.$value ?? '0.78';
163
+ const chartHue = (n, fallback) =>
164
+ tokens.chart?.hueRotation?.[`step${n}`]?.$value ?? fallback;
165
+ const chartChroma2 = tokens.chart?.chroma2Damping?.$value ?? '0.65';
166
+ const chartDerivationLight = ` /* Chart palette — derives from --primary so brand changes propagate.
167
+ Override individual --chart-N inline (documentElement.style) to opt out. */
168
+ --chart-lightness: ${chartLightnessLight};
169
+ --chart-1: oklch(from var(--primary) var(--chart-lightness) c calc(h + ${chartHue(1, '0')}));
170
+ --chart-2: oklch(from var(--primary) var(--chart-lightness) calc(c * ${chartChroma2}) calc(h + ${chartHue(2, '35')}));
171
+ --chart-3: oklch(from var(--primary) var(--chart-lightness) c calc(h + ${chartHue(3, '70')}));
172
+ --chart-4: oklch(from var(--primary) var(--chart-lightness) c calc(h + ${chartHue(4, '105')}));
173
+ --chart-5: oklch(from var(--primary) var(--chart-lightness) c calc(h + ${chartHue(5, '140')}));`;
174
+
175
+ const chartDerivationDark = ` /* Lift lightness on dark backgrounds so charts stay readable. */
176
+ --chart-lightness: ${chartLightnessDark};`;
177
+
178
+ const themeInline = `@theme inline {
179
+ --color-background: var(--background);
180
+ --color-foreground: var(--foreground);
181
+ --color-card: var(--card);
182
+ --color-card-foreground: var(--card-foreground);
183
+ --color-popover: var(--popover);
184
+ --color-popover-foreground: var(--popover-foreground);
185
+ --color-primary: var(--primary);
186
+ --color-primary-foreground: var(--primary-foreground);
187
+ --color-secondary: var(--secondary);
188
+ --color-secondary-foreground: var(--secondary-foreground);
189
+ --color-muted: var(--muted);
190
+ --color-muted-foreground: var(--muted-foreground);
191
+ --color-accent: var(--accent);
192
+ --color-accent-foreground: var(--accent-foreground);
193
+ --color-destructive: var(--destructive);
194
+ --color-destructive-foreground: var(--destructive-foreground);
195
+ --color-border: var(--border);
196
+ --color-input: var(--input);
197
+ --color-ring: var(--ring);
198
+ --color-chart-1: var(--chart-1);
199
+ --color-chart-2: var(--chart-2);
200
+ --color-chart-3: var(--chart-3);
201
+ --color-chart-4: var(--chart-4);
202
+ --color-chart-5: var(--chart-5);
203
+ --color-sidebar: var(--sidebar);
204
+ --color-sidebar-foreground: var(--sidebar-foreground);
205
+ --color-sidebar-primary: var(--sidebar-primary);
206
+ --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
207
+ --color-sidebar-accent: var(--sidebar-accent);
208
+ --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
209
+ --color-sidebar-border: var(--sidebar-border);
210
+ --color-sidebar-ring: var(--sidebar-ring);
211
+
212
+ --font-sans: var(--font-sans);
213
+ --font-mono: var(--font-mono);
214
+ --font-serif: var(--font-serif);
215
+
216
+ --radius-sm: calc(var(--radius) - 4px);
217
+ --radius-md: calc(var(--radius) - 2px);
218
+ --radius-lg: var(--radius);
219
+ --radius-xl: calc(var(--radius) + 4px);
220
+
221
+ /* Map Tailwind's shadow-* utilities through to the :root --shadow-* tokens
222
+ so the Customize tab's Shadow Opacity slider takes effect. Without this
223
+ mapping, shadow-sm / shadow-md / shadow-lg etc. resolve to Tailwind's
224
+ built-in box-shadow values and ignore --shadow-opacity entirely. */
225
+ --shadow-2xs: var(--shadow-2xs);
226
+ --shadow-xs: var(--shadow-xs);
227
+ --shadow-sm: var(--shadow-sm);
228
+ --shadow: var(--shadow);
229
+ --shadow-md: var(--shadow-md);
230
+ --shadow-lg: var(--shadow-lg);
231
+ --shadow-xl: var(--shadow-xl);
232
+ --shadow-2xl: var(--shadow-2xl);
233
+
234
+ /* Animation token layer. Sourced from tokens.json (duration / easing).
235
+ Components use these via Tailwind utilities — duration-base,
236
+ ease-spring, etc. — or the raw var(--duration-base) / var(--ease-out)
237
+ when classnames don't fit. Single source of truth for motion. */
238
+ --duration-fast: var(--duration-fast);
239
+ --duration-base: var(--duration-base);
240
+ --duration-slow: var(--duration-slow);
241
+ --ease-in: var(--ease-in);
242
+ --ease-out: var(--ease-out);
243
+ --ease-in-out: var(--ease-in-out);
244
+ --ease-spring: var(--ease-spring);
245
+
246
+ /* Accessibility floor — minimum 14px for text-xs (vs Tailwind's 12px default).
247
+ Font sizes are dynamically computed by useGlobalTypeScale hook and set as
248
+ --text-xs-size, --text-sm-size, etc. These are then scaled by --font-size-scale
249
+ (1 = 100%, 0.8 = 80%, etc) so the Customize tab slider affects all text. */
250
+ --text-xs: calc(var(--text-xs-size, ${textXs}) * var(--font-size-scale, 1));
251
+ --text-sm: calc(var(--text-sm-size, ${textSm}) * var(--font-size-scale, 1));
252
+ --text-base: calc(var(--text-base-size, ${textBase}) * var(--font-size-scale, 1));
253
+ --text-lg: calc(var(--text-lg-size, ${textLg}) * var(--font-size-scale, 1));
254
+ --text-xl: calc(var(--text-xl-size, ${textXl}) * var(--font-size-scale, 1));
255
+ --text-2xl: calc(var(--text-2xl-size, ${text2xl}) * var(--font-size-scale, 1));
256
+ --text-3xl: calc(var(--text-3xl-size, ${text3xl}) * var(--font-size-scale, 1));
257
+
258
+ /* Marketing tier — display sizes for landing pages, hero blocks, editorial.
259
+ Tailwind only emits utilities that get used, so a non-marketing fork pays
260
+ nothing for these. line-height drops to 1.1 at scale to keep big type
261
+ readable; tracking tightens slightly to compensate for optical loosening. */
262
+ --text-4xl: calc(${text4xl} * var(--font-size-scale, 1));
263
+ --text-5xl: calc(${text5xl} * var(--font-size-scale, 1));
264
+ --text-6xl: calc(${text6xl} * var(--font-size-scale, 1));
265
+ --text-7xl: calc(${text7xl} * var(--font-size-scale, 1));
266
+ --text-8xl: calc(${text8xl} * var(--font-size-scale, 1));
267
+ --text-4xl--line-height: 1.15;
268
+ --text-5xl--line-height: 1.10;
269
+ --text-6xl--line-height: 1.05;
270
+ --text-7xl--line-height: 1.02;
271
+ --text-8xl--line-height: 1.00;
272
+ --text-4xl--letter-spacing: -0.015em;
273
+ --text-5xl--letter-spacing: -0.020em;
274
+ --text-6xl--letter-spacing: -0.025em;
275
+ --text-7xl--letter-spacing: -0.030em;
276
+ --text-8xl--letter-spacing: -0.035em;
277
+
278
+ /* Tracking — every Tailwind tracking-* utility folds in the runtime
279
+ --tracking-offset offset, so the Customize tab slider moves the
280
+ entire app (headlines included), not just unstyled text. */
281
+ --tracking-tighter: calc(-0.05em + var(--tracking-offset, 0em));
282
+ --tracking-tight: calc(-0.025em + var(--tracking-offset, 0em));
283
+ --tracking-normal: var(--tracking-offset, 0em);
284
+ --tracking-wide: calc(0.025em + var(--tracking-offset, 0em));
285
+ --tracking-wider: calc(0.05em + var(--tracking-offset, 0em));
286
+ --tracking-widest: calc(0.1em + var(--tracking-offset, 0em));
287
+ }`;
288
+
289
+ const baseLayer = `@layer base {
290
+ * {
291
+ @apply border-border outline-ring/50;
292
+ }
293
+ body {
294
+ @apply bg-background text-foreground;
295
+ -webkit-font-smoothing: antialiased;
296
+ -moz-osx-font-smoothing: grayscale;
297
+ /* WCAG AAA 1.4.8 Visual Presentation: body line-height ≥ 1.5. */
298
+ line-height: 1.5;
299
+ /* WCAG AAA 1.4.8: avoid full-justified body — uneven word spacing
300
+ hurts readability. Components opt-in to justify only when needed. */
301
+ text-align: start;
302
+ /* Fade body in once fonts are ready. The boot script in app/layout.tsx
303
+ toggles .fonts-loading / .fonts-loaded on <html>. Cached loads bypass
304
+ the gate entirely (instant paint); first uncached loads briefly hide
305
+ body until document.fonts.ready resolves, then fade in. Eliminates
306
+ the FOUT "jump" as web fonts swap in over system-ui fallback. */
307
+ opacity: 1;
308
+ transition: opacity 200ms ease-out;
309
+ }
310
+ html.fonts-loading body {
311
+ opacity: 0;
312
+ }
313
+ /* Reduced-motion: never animate the fade — show body immediately when
314
+ the gate releases. Honors SC 2.3.3. */
315
+ @media (prefers-reduced-motion: reduce) {
316
+ body { transition: none; }
317
+ }
318
+ /* WCAG AAA 1.4.8: paragraph spacing ≥ 1.5× line-height inside running
319
+ text. Scope to <p> only — UI primitives stay tight. Last-child has
320
+ no trailing margin so containers don't get extra padding. */
321
+ p:not(:last-child) {
322
+ margin-bottom: 1.5em;
323
+ }
324
+ /* WCAG AAA 2.4.13 Focus Appearance: focus indicator must be ≥ 2 CSS
325
+ pixels thick AND have ≥ 3:1 contrast against adjacent colors. The
326
+ --ring token is luminance-tuned for 3:1 against every surface in
327
+ the system. Always show a 2px offset so the ring isn't visually
328
+ obscured by the component's own border. */
329
+ :focus-visible {
330
+ outline-offset: 2px;
331
+ }
332
+ /* WCAG AAA 2.3.3 Animation from Interactions: respect the user's
333
+ reduced-motion preference globally. Components with essential
334
+ motion (loading spinners, progress bars) opt back in via
335
+ \`motion-safe:\` Tailwind utilities or scoped @media queries. */
336
+ @media (prefers-reduced-motion: reduce) {
337
+ *,
338
+ *::before,
339
+ *::after {
340
+ animation-duration: 0.01ms !important;
341
+ animation-iteration-count: 1 !important;
342
+ transition-duration: 0.01ms !important;
343
+ scroll-behavior: auto !important;
344
+ }
345
+ }
346
+ }
347
+
348
+ /* Global tracking offset — the Letter Spacing slider in the Customize
349
+ tab writes --tracking-offset on documentElement (via use-global-design-
350
+ controls). Both the @theme inline tracking-* tokens AND this body rule
351
+ fold it in, so every element retracks live: utilities-styled elements
352
+ via the Tailwind classes, unstyled text via inheritance from body. */
353
+ html, body {
354
+ letter-spacing: var(--tracking-offset, 0em);
355
+ }
356
+
357
+ /* Theme toggle: iris reveal via View Transitions API. The click coords are
358
+ written to --x / --y on <html> before startViewTransition fires (see
359
+ app/page.tsx toggleDark). */
360
+ ::view-transition-old(root),
361
+ ::view-transition-new(root) {
362
+ animation: none;
363
+ mix-blend-mode: normal;
364
+ }
365
+ ::view-transition-old(root) { z-index: 0; }
366
+ ::view-transition-new(root) { z-index: 1; }
367
+
368
+ @keyframes theme-reveal {
369
+ from {
370
+ clip-path: circle(0% at var(--x, 50%) var(--y, 50%));
371
+ opacity: 0.7;
372
+ }
373
+ to {
374
+ clip-path: circle(150% at var(--x, 50%) var(--y, 50%));
375
+ opacity: 1;
376
+ }
377
+ }
378
+
379
+ ::view-transition-new(root) {
380
+ animation: theme-reveal 0.4s ease-in-out forwards;
381
+ }
382
+
383
+ @media (prefers-reduced-motion: reduce) {
384
+ ::view-transition-new(root) { animation: none; }
385
+ }`;
386
+
387
+ // ---- packages/core/src/styles.css (consumer-facing) ----------------------
388
+
389
+ const pkgCss = `${banner}
390
+
391
+ /* @behavioral-agentic-design-system/core — single-file theme import.
392
+ *
393
+ * Usage in your app's global stylesheet:
394
+ * @import "tailwindcss";
395
+ * @import "tw-animate-css";
396
+ * @import "@behavioral-agentic-design-system/core/styles.css";
397
+ *
398
+ * Atkinson Hyperlegible loaded from Google Fonts; zero font setup required.
399
+ * Override any token by re-declaring it after this @import.
400
+ */
401
+
402
+ @import url('https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:wght@400;700&display=swap');
403
+
404
+ @custom-variant dark (&:is(.dark *));
405
+
406
+ :root {
407
+ --font-sans: 'Atkinson Hyperlegible', ui-sans-serif, sans-serif, system-ui;
408
+ --font-mono: ${fontMono};
409
+ --font-serif: ${fontSerif};
410
+ --font-size-scale: 1;
411
+
412
+ ${lightVars}
413
+
414
+ --radius: ${radius};
415
+ ${shadowBlock}
416
+ ${motionBlock}
417
+ --spacing: ${spacing};
418
+
419
+ ${chartDerivationLight}
420
+ }
421
+
422
+ .dark {
423
+ ${darkVars}
424
+
425
+ ${chartDerivationDark}
426
+ }
427
+
428
+ ${themeInline}
429
+
430
+ ${baseLayer}
431
+ `;
432
+
433
+ fs.writeFileSync(PKG_CSS, pkgCss);
434
+ console.log(`✓ wrote ${path.relative(ROOT, PKG_CSS)}`);
435
+
436
+ // ---- styles/globals.css (preview app) ------------------------------------
437
+
438
+ // Note: Google Fonts @imports are intentionally NOT emitted for the preview app.
439
+ // app/layout.tsx loads Atkinson Hyperlegible / Inter / Lora / Source Serif 4 /
440
+ // JetBrains Mono via next/font/google, which self-hosts and preloads the woff2
441
+ // to eliminate FOUT. The npm package (packages/core/src/styles.css) keeps its
442
+ // @import so consumers without next/font still get the canonical theme.
443
+ const appCss = `${banner}
444
+
445
+ @import "../fonts.css";
446
+ @import "tailwindcss";
447
+ @import "tw-animate-css";
448
+
449
+ @custom-variant dark (&:is(.dark *));
450
+
451
+ :root {
452
+ /* Showcase app: lead with next/font's preloaded vars so the browser uses
453
+ * the self-hosted woff2 set up in app/layout.tsx — kills FOUT. The literal
454
+ * family names from tokens.json remain as fallbacks. */
455
+ --font-sans: var(--font-atkinson), ${fontSans};
456
+ --font-serif: var(--font-source-serif), ${fontSerif};
457
+ --font-mono: var(--font-jetbrains), ${fontMono};
458
+ --font-size-scale: 1;
459
+
460
+ ${lightVars}
461
+
462
+ --radius: ${radius};
463
+ ${shadowBlock}
464
+ ${motionBlock}
465
+ --spacing: ${spacing};
466
+
467
+ ${chartDerivationLight}
468
+ }
469
+
470
+ .dark {
471
+ ${darkVars}
472
+
473
+ ${chartDerivationDark}
474
+ }
475
+
476
+ ${themeInline}
477
+
478
+ ${baseLayer}
479
+
480
+ * {
481
+ color-scheme: light dark;
482
+ border-color: var(--color-border);
483
+ }
484
+ ${clientExtras}`;
485
+
486
+ fs.writeFileSync(APP_CSS, appCss);
487
+ console.log(`✓ wrote ${path.relative(ROOT, APP_CSS)}${clientExtras ? ' (with client-extras)' : ''}`);