@behavioral-agentic-design-system/core 0.39.1 → 0.40.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 +8 -3
- package/scripts/a11y-lint.cjs +47 -6
- package/scripts/bads-components.mjs +118 -0
- package/scripts/build-tokens.cjs +133 -12
- package/scripts/check-stories.mjs +1 -1
- package/scripts/lint-component-source.mjs +100 -0
- package/scripts/lint-microanimation.mjs +267 -0
- package/scripts/size-audit.cjs +79 -0
- package/scripts/source-of-truth.cjs +58 -0
- package/scripts/ux-smoke.mjs +438 -0
- package/scripts/wcag-audit.cjs +49 -1
- package/src/api/layers/file.ts +1 -0
- package/src/app/preview/components/page.tsx +968 -0
- package/src/app/shell.tsx +11 -13
- package/src/components/customize/brand-mark-section.tsx +4 -2
- package/src/components/customize/design-controls.tsx +1 -1
- package/src/components/customize/discipline-section.tsx +3 -6
- package/src/components/customize/font-pickers.tsx +1 -1
- package/src/components/customize/letter-spacing.tsx +1 -1
- package/src/components/customize/save-bar.tsx +2 -2
- package/src/components/customize/theme-io.tsx +7 -7
- package/src/components/customize/type-scale.tsx +1 -1
- package/src/components/customize-tab.tsx +7 -4
- package/src/components/home-tab.tsx +3 -0
- package/src/components/ui/accordion.tsx +7 -0
- package/src/components/ui/alert.tsx +1 -0
- package/src/components/ui/announcement-bar.tsx +256 -0
- package/src/components/ui/badge.tsx +1 -0
- package/src/components/ui/callout.tsx +218 -0
- package/src/components/ui/chart.tsx +2 -14
- package/src/components/ui/color-picker.tsx +1 -1
- package/src/components/ui/format-relative-time.tsx +139 -0
- package/src/components/ui/grid.tsx +255 -0
- package/src/components/ui/icon.tsx +108 -0
- package/src/components/ui/index.ts +8 -0
- package/src/components/ui/page-header.tsx +63 -0
- package/src/components/ui/portal.tsx +111 -0
- package/src/components/ui/presence.tsx +172 -0
- package/src/components/ui/progress-stack.tsx +258 -0
- package/src/components/ui/select.tsx +89 -4
- package/src/components/ui/separator.tsx +1 -0
- package/src/components/ui/slider.tsx +83 -3
- package/src/components/ui/sparkline.tsx +2 -14
- package/src/components/ui/textarea.tsx +28 -1
- package/src/data/docs-index.ts +1 -0
- package/src/hooks/use-reduced-motion.ts +6 -0
- package/src/stories/Accordion.stories.tsx +59 -0
- package/src/stories/Alert.stories.tsx +3 -1
- package/src/stories/AnnouncementBar.stories.tsx +261 -0
- package/src/stories/Badge.stories.tsx +3 -0
- package/src/stories/Calendar.stories.tsx +1 -1
- package/src/stories/Callout.stories.tsx +219 -0
- package/src/stories/Chart.stories.tsx +4 -0
- package/src/stories/ColorPicker.stories.tsx +23 -0
- package/src/stories/FormatRelativeTime.stories.tsx +116 -0
- package/src/stories/Grid.stories.tsx +197 -0
- package/src/stories/Icon.stories.tsx +175 -0
- package/src/stories/MultiSelect.stories.tsx +1 -1
- package/src/stories/PageHeader.stories.tsx +102 -0
- package/src/stories/Portal.stories.tsx +189 -0
- package/src/stories/Presence.stories.tsx +228 -0
- package/src/stories/ProgressStack.stories.tsx +287 -0
- package/src/stories/Select.stories.tsx +25 -0
- package/src/stories/Separator.stories.tsx +3 -0
- package/src/stories/Slider.stories.tsx +54 -5
- package/src/stories/Sparkline.stories.tsx +3 -0
- package/src/stories/Textarea.stories.tsx +18 -0
- package/src/stories/story-groups.json +14 -5
- package/src/styles.css +133 -12
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// pnpm lint:microanimation — flags components that use hardcoded Tailwind
|
|
3
|
+
// motion utilities instead of BADS motion tokens.
|
|
4
|
+
//
|
|
5
|
+
// New components (per CLAUDE.md → Components & Registry → microanimation rule)
|
|
6
|
+
// must drive transitions from BADS motion tokens:
|
|
7
|
+
// duration-[var(--duration-fast|base|slow)]
|
|
8
|
+
// ease-[var(--ease-out|in|in-out|spring)]
|
|
9
|
+
//
|
|
10
|
+
// The Tailwind defaults (`duration-200`, `ease-out`, etc.) are anti-patterns
|
|
11
|
+
// here — they bypass the token surface, so a tone-shift in the motion system
|
|
12
|
+
// can't propagate to the components that use them.
|
|
13
|
+
//
|
|
14
|
+
// Advisory by default. `--strict` exits 1 on any violation (used in the
|
|
15
|
+
// Night Shift step 3b verification gates).
|
|
16
|
+
//
|
|
17
|
+
// Scope by default: the published primitive surface
|
|
18
|
+
// (`packages/core/src/components/ui/*.tsx`). Compositions and showcase code
|
|
19
|
+
// in `components/` and `app/` are not in scope — those are end-product
|
|
20
|
+
// surfaces where one-off `duration-200` is sometimes the right call.
|
|
21
|
+
//
|
|
22
|
+
// File-scoped runs: pass `.tsx` paths as positional args to scan only those.
|
|
23
|
+
// Used by the Night Shift step 3b gate so existing debt elsewhere doesn't
|
|
24
|
+
// block a clean new-component PR. Example:
|
|
25
|
+
//
|
|
26
|
+
// node scripts/lint-microanimation.mjs --strict \
|
|
27
|
+
// packages/core/src/components/ui/accordion.tsx
|
|
28
|
+
|
|
29
|
+
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
30
|
+
import { resolve, join, isAbsolute } from 'node:path';
|
|
31
|
+
import { fileURLToPath } from 'node:url';
|
|
32
|
+
|
|
33
|
+
// cwd-rooted so this works in a consumer repo. Rooting at __dirname would make
|
|
34
|
+
// it walk up to the design system and report a pass for files the caller never
|
|
35
|
+
// opened — see scripts/_upstream-only.mjs for the measured version of that bug.
|
|
36
|
+
const ROOT = process.cwd();
|
|
37
|
+
// First primitive directory that exists here. Upstream that is the package
|
|
38
|
+
// source; in a fork consuming @core from npm it is the local components dir.
|
|
39
|
+
const DEFAULT_SCAN_DIR = [
|
|
40
|
+
'packages/core/src/components/ui',
|
|
41
|
+
'components/ui',
|
|
42
|
+
'src/components/ui',
|
|
43
|
+
]
|
|
44
|
+
.map((d) => resolve(ROOT, d))
|
|
45
|
+
.find((d) => existsSync(d)) ?? resolve(ROOT, 'components');
|
|
46
|
+
|
|
47
|
+
const argv = process.argv.slice(2);
|
|
48
|
+
const STRICT = argv.includes('--strict');
|
|
49
|
+
const explicitFiles = argv
|
|
50
|
+
.filter((a) => !a.startsWith('--'))
|
|
51
|
+
.map((a) => (isAbsolute(a) ? a : resolve(process.cwd(), a)));
|
|
52
|
+
|
|
53
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
54
|
+
// rules
|
|
55
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
56
|
+
//
|
|
57
|
+
// Rules updated 2026-06-17 after the Accordion saga (5 PRs) surfaced the
|
|
58
|
+
// actual Tailwind v4 + BADS reality:
|
|
59
|
+
//
|
|
60
|
+
// 1. Tailwind v4 generates utility classes from these recognized theme
|
|
61
|
+
// namespaces ONLY: --color-*, --ease-*, --animate-*, --font-*,
|
|
62
|
+
// --text-*, --radius-*, --shadow-*, --spacing-*, --breakpoint-*, etc.
|
|
63
|
+
// It does NOT have a --duration-* namespace. So `duration-fast`,
|
|
64
|
+
// `duration-base`, `duration-slow` are SILENT FAILURES — they
|
|
65
|
+
// compile to nothing and the transition has no duration.
|
|
66
|
+
//
|
|
67
|
+
// 2. The arbitrary-value form `duration-[var(--duration-fast)]` SHOULD
|
|
68
|
+
// generate a utility but the Tailwind v4 scanner's pickup of these
|
|
69
|
+
// across @theme inline cascade is inconsistent. Treat as unreliable.
|
|
70
|
+
//
|
|
71
|
+
// 3. The correct token-driven pattern in this setup is inline `style`:
|
|
72
|
+
// style={{ transitionDuration: 'var(--duration-fast)',
|
|
73
|
+
// transitionTimingFunction: 'var(--ease-out)' }}
|
|
74
|
+
// CSS vars resolve at runtime against :root, propagate from
|
|
75
|
+
// tokens.json via `pnpm build:tokens`. Bulletproof.
|
|
76
|
+
//
|
|
77
|
+
// 4. For keyframe animations (accordion-down, drawer-slide, etc.),
|
|
78
|
+
// define them in packages/core/scripts/build-tokens.cjs and apply
|
|
79
|
+
// via direct CSS selectors on data-slot + data-state. NOT via
|
|
80
|
+
// @theme inline --animate-* tokens (also unreliable v4 generation).
|
|
81
|
+
//
|
|
82
|
+
// 5. Tailwind stock utilities that DO work:
|
|
83
|
+
// - duration-{75|100|150|200|...} — numeric durations, work but
|
|
84
|
+
// bypass the token surface. Advisory warning only (--strict
|
|
85
|
+
// doesn't fail) since the values happen to match BADS tokens 1:1.
|
|
86
|
+
// - ease-out, ease-spring, ease-in, ease-in-out, ease-linear —
|
|
87
|
+
// Tailwind v4 recognizes --ease-* namespace, these are token-
|
|
88
|
+
// driven via the @theme inline declarations.
|
|
89
|
+
// - transition-colors, transition-transform, transition-opacity,
|
|
90
|
+
// transition-all — property utilities, no duration baked in.
|
|
91
|
+
//
|
|
92
|
+
// What this lint flags now (in --strict, fails CI):
|
|
93
|
+
// - duration-fast | duration-base | duration-slow (silent failure)
|
|
94
|
+
// - duration-[var(--duration-*)] (unreliable v4 scanner pickup)
|
|
95
|
+
// - inline transitionDuration: "<literal-ms>" (hardcoded ms, not token)
|
|
96
|
+
// - inline transitionTimingFunction: "<literal-bezier-or-name>" (hardcoded)
|
|
97
|
+
//
|
|
98
|
+
// What this lint warns on (advisory, doesn't fail --strict):
|
|
99
|
+
// - duration-{numeric} (works, but not token-driven — flag for awareness)
|
|
100
|
+
//
|
|
101
|
+
// What this lint PERMITS (canonical patterns):
|
|
102
|
+
// - inline style={{ transitionDuration: "var(--duration-*)", ... }}
|
|
103
|
+
// - ease-out, ease-spring, etc.
|
|
104
|
+
// - transition-colors, transition-transform, etc.
|
|
105
|
+
// - data-[state=open]:animate-<keyframe-name> for keyframe animations
|
|
106
|
+
// defined in build-tokens.cjs
|
|
107
|
+
|
|
108
|
+
const RULES = [
|
|
109
|
+
{
|
|
110
|
+
name: 'unreliable-tailwind-duration-token',
|
|
111
|
+
pattern: /(?<![\[\w-])(duration-(?:fast|base|slow))(?![\w-])/g,
|
|
112
|
+
severity: 'error',
|
|
113
|
+
why: 'Silent failure: Tailwind v4 does NOT auto-generate utilities from --duration-* theme tokens (only --ease-*, --animate-*, --color-*, etc.). This class compiles to nothing — the transition has no duration and snaps instead of animating.',
|
|
114
|
+
fix: 'Use inline style for the duration: style={{ transitionDuration: "var(--duration-fast)" }} (or --duration-base / --duration-slow). Keep the Tailwind class for the transition property (transition-colors, transition-transform, etc.).',
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: 'unreliable-arbitrary-duration-var',
|
|
118
|
+
pattern: /(?<![\[\w-])(duration-\[var\(--duration-(?:fast|base|slow)\)\])/g,
|
|
119
|
+
severity: 'error',
|
|
120
|
+
why: 'Unreliable: Tailwind v4 scanner pickup of arbitrary-value classes referencing @theme inline CSS vars is inconsistent across this setup. The Accordion saga (5 PRs) confirmed it does not reliably produce a CSS rule.',
|
|
121
|
+
fix: 'Use inline style: style={{ transitionDuration: "var(--duration-fast)" }}. Bulletproof — CSS vars resolve at runtime against :root.',
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: 'hardcoded-inline-transition-duration',
|
|
125
|
+
pattern: /(transitionDuration:\s*["'`](?!var\()[^"'`]+["'`])/g,
|
|
126
|
+
severity: 'error',
|
|
127
|
+
why: 'Inline transitionDuration with a literal value (ms or s). Bypasses the BADS motion token surface — changes to tokens.json will not propagate.',
|
|
128
|
+
fix: 'Use a token reference: transitionDuration: "var(--duration-fast)" (150ms typical), "var(--duration-base)" (200ms), or "var(--duration-slow)" (300ms).',
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: 'hardcoded-inline-transition-timing',
|
|
132
|
+
pattern: /(transitionTimingFunction:\s*["'`](?!var\()[^"'`]+["'`])/g,
|
|
133
|
+
severity: 'error',
|
|
134
|
+
why: 'Inline transitionTimingFunction with a literal value (bezier or stock name). Bypasses the BADS motion token surface.',
|
|
135
|
+
fix: 'Use a token reference: transitionTimingFunction: "var(--ease-out)" (most cases), "var(--ease-spring)" (contained overshoot — chevron flips, switch handles), "var(--ease-in)" (accelerate), or "var(--ease-in-out)" (symmetric). OR drop the inline style and use the Tailwind utility ease-out / ease-spring / etc. — those DO work via the v4 --ease-* namespace.',
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: 'tailwind-numeric-duration',
|
|
139
|
+
pattern: /(?<![\[\w-])(duration-(?:75|100|150|200|300|500|700|1000))(?![\w-])/g,
|
|
140
|
+
severity: 'warn',
|
|
141
|
+
why: 'Stock Tailwind numeric duration. Works (Tailwind generates this utility) but bypasses the BADS motion token surface — changes to tokens.json will not propagate. Acceptable when the value matches a token 1:1 and you want the Tailwind-class form for terseness; preferred is inline style with var(--duration-*).',
|
|
142
|
+
fix: 'Prefer style={{ transitionDuration: "var(--duration-base)" }} (200ms). If you keep duration-200, note that it works because Tailwind generates `transition-duration: 200ms` directly — but it will not pick up future token changes.',
|
|
143
|
+
},
|
|
144
|
+
];
|
|
145
|
+
|
|
146
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
147
|
+
// scan
|
|
148
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
149
|
+
|
|
150
|
+
function listTsxFiles(dir) {
|
|
151
|
+
let entries;
|
|
152
|
+
try {
|
|
153
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
154
|
+
} catch {
|
|
155
|
+
return [];
|
|
156
|
+
}
|
|
157
|
+
const out = [];
|
|
158
|
+
for (const e of entries) {
|
|
159
|
+
if (e.isFile() && e.name.endsWith('.tsx')) out.push(join(dir, e.name));
|
|
160
|
+
}
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Strip JS line + block comments so explanatory comments mentioning
|
|
165
|
+
// anti-pattern class names (e.g. "// `duration-fast` doesn't compile") don't
|
|
166
|
+
// trigger false positives. Replaces matched comment contents with spaces of
|
|
167
|
+
// the same length so line/col numbers in findings still align with the
|
|
168
|
+
// original source.
|
|
169
|
+
function stripComments(src) {
|
|
170
|
+
return src
|
|
171
|
+
.replace(/\/\*[\s\S]*?\*\//g, (m) => m.replace(/[^\n]/g, ' '))
|
|
172
|
+
.replace(/\/\/[^\n]*/g, (m) => ' '.repeat(m.length));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function scanFile(filePath) {
|
|
176
|
+
const body = readFileSync(filePath, 'utf8');
|
|
177
|
+
const stripped = stripComments(body);
|
|
178
|
+
const lines = body.split('\n');
|
|
179
|
+
const findings = [];
|
|
180
|
+
for (const rule of RULES) {
|
|
181
|
+
rule.pattern.lastIndex = 0;
|
|
182
|
+
let m;
|
|
183
|
+
while ((m = rule.pattern.exec(stripped)) !== null) {
|
|
184
|
+
// Compute line/col from match index.
|
|
185
|
+
const upto = body.slice(0, m.index);
|
|
186
|
+
const line = upto.split('\n').length;
|
|
187
|
+
const col = m.index - upto.lastIndexOf('\n');
|
|
188
|
+
findings.push({
|
|
189
|
+
file: filePath,
|
|
190
|
+
line,
|
|
191
|
+
col,
|
|
192
|
+
match: m[1],
|
|
193
|
+
rule: rule.name,
|
|
194
|
+
severity: rule.severity ?? 'error',
|
|
195
|
+
why: rule.why,
|
|
196
|
+
fix: rule.fix,
|
|
197
|
+
context: (lines[line - 1] ?? '').trim(),
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return findings;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
205
|
+
// main
|
|
206
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
207
|
+
|
|
208
|
+
function main() {
|
|
209
|
+
let files;
|
|
210
|
+
let scope;
|
|
211
|
+
if (explicitFiles.length > 0) {
|
|
212
|
+
files = explicitFiles.filter((p) => {
|
|
213
|
+
try {
|
|
214
|
+
return statSync(p).isFile() && p.endsWith('.tsx');
|
|
215
|
+
} catch {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
scope = `${files.length} explicitly-scoped file(s)`;
|
|
220
|
+
} else {
|
|
221
|
+
files = listTsxFiles(DEFAULT_SCAN_DIR);
|
|
222
|
+
scope = `${files.length} primitive(s) in packages/core/src/components/ui/`;
|
|
223
|
+
}
|
|
224
|
+
const allFindings = files.flatMap(scanFile);
|
|
225
|
+
|
|
226
|
+
console.log(`lint-microanimation — scanned ${scope}.`);
|
|
227
|
+
|
|
228
|
+
if (allFindings.length === 0) {
|
|
229
|
+
console.log(' every primitive drives motion from BADS tokens. clean.');
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Group by file for readable output.
|
|
234
|
+
const byFile = new Map();
|
|
235
|
+
for (const f of allFindings) {
|
|
236
|
+
if (!byFile.has(f.file)) byFile.set(f.file, []);
|
|
237
|
+
byFile.get(f.file).push(f);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const errorCount = allFindings.filter((f) => f.severity === 'error').length;
|
|
241
|
+
const warnCount = allFindings.filter((f) => f.severity === 'warn').length;
|
|
242
|
+
console.log(` flagged: ${errorCount} error(s), ${warnCount} warning(s) across ${byFile.size} file(s).`);
|
|
243
|
+
console.log('');
|
|
244
|
+
|
|
245
|
+
for (const [file, findings] of byFile) {
|
|
246
|
+
const rel = file.replace(ROOT + '/', '');
|
|
247
|
+
console.log(rel);
|
|
248
|
+
for (const f of findings) {
|
|
249
|
+
const badge = f.severity === 'error' ? 'ERROR ' : 'warn ';
|
|
250
|
+
console.log(` ${badge}${rel}:${f.line}:${f.col}`);
|
|
251
|
+
console.log(` rule: ${f.rule}`);
|
|
252
|
+
console.log(` match: ${f.match}`);
|
|
253
|
+
console.log(` why: ${f.why}`);
|
|
254
|
+
console.log(` fix: ${f.fix}`);
|
|
255
|
+
console.log(` line: ${f.context}`);
|
|
256
|
+
console.log('');
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
console.log('See CLAUDE.md → Components & Registry → microanimation rule for the full contract.');
|
|
261
|
+
|
|
262
|
+
// --strict fails ONLY on errors. Warnings are advisory (e.g. duration-200
|
|
263
|
+
// works but bypasses tokens — don't block a build on it).
|
|
264
|
+
if (STRICT && errorCount > 0) process.exit(1);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
main();
|
package/scripts/size-audit.cjs
CHANGED
|
@@ -61,6 +61,44 @@ const BUTTON_OPEN = /<button\b/;
|
|
|
61
61
|
const TEXT_XS = /\btext-xs\b/;
|
|
62
62
|
const ESCAPE_HATCH = /allow-text-xs-cta/;
|
|
63
63
|
|
|
64
|
+
// ── BADS-2b: a full-width <Button> below the 44px touch-target floor ─────────
|
|
65
|
+
//
|
|
66
|
+
// CLAUDE.md calls 44px non-negotiable (SC 2.5.5) and then documents Button's
|
|
67
|
+
// `default` (h-9, 36px) and `lg` (h-10, 40px) as exceptions reserved for dense
|
|
68
|
+
// NON-CTA chrome: toolbars, table row actions, dialog footers. Sir's call on
|
|
69
|
+
// 2026-09-11 was to keep those sizes and enforce the contract instead, because
|
|
70
|
+
// bumping the default reflows every button in every fork to fix a misuse that
|
|
71
|
+
// may not exist.
|
|
72
|
+
//
|
|
73
|
+
// So the question is how to tell a CTA from chrome, statically, without crying
|
|
74
|
+
// wolf — a false BLOCKER sends someone to fix a correct component and teaches
|
|
75
|
+
// people to bypass the gate (CLAUDE.md, "ask what a passing check measured").
|
|
76
|
+
//
|
|
77
|
+
// `w-full` is the signal with no honest counter-example. Dense chrome is never
|
|
78
|
+
// full-width: a toolbar button sits in a row of them, a table row action is
|
|
79
|
+
// icon-sized, a dialog footer button hugs its label. A button told to fill its
|
|
80
|
+
// container is the primary action of that container, which is exactly the
|
|
81
|
+
// flow-changing case the floor is for. It is also the shape corrections #011
|
|
82
|
+
// already documents as the trap ("a `w-full` button carrying a multi-word
|
|
83
|
+
// label").
|
|
84
|
+
//
|
|
85
|
+
// Deliberately NOT flagged, because each has a real counter-example:
|
|
86
|
+
// type="submit" — dialog footers submit, and they are sanctioned chrome
|
|
87
|
+
// CTA-sounding label — "Save" is a hero CTA on one screen, chrome on another
|
|
88
|
+
// inside a <form> — says nothing about the button's prominence
|
|
89
|
+
//
|
|
90
|
+
// Fix is `size="xl"` (h-11) or `size="2xl"` (h-12), or keep the default text
|
|
91
|
+
// register with `size="default" className="min-h-11 w-full"`. The escape is
|
|
92
|
+
// `// allow-small-cta <reason>` on the line above.
|
|
93
|
+
const BUTTON_COMPONENT_OPEN = /<Button\b/;
|
|
94
|
+
const W_FULL = /\bw-full\b/;
|
|
95
|
+
const HAS_MIN_H_11 = /\bmin-h-(?:11|12|\[(?:44|48)px\])\b/;
|
|
96
|
+
const SIZE_PROP = /\bsize=\{?["']([a-z0-9-]+)["']\}?/;
|
|
97
|
+
const SMALL_CTA_ESCAPE = /allow-small-cta/;
|
|
98
|
+
// Sizes at or above 44px. Anything else (including no size prop at all, which
|
|
99
|
+
// is `default` at 36px) is under the floor.
|
|
100
|
+
const COMPLIANT_SIZES = new Set(['xl', '2xl', 'icon-xl']);
|
|
101
|
+
|
|
64
102
|
for (const file of files) {
|
|
65
103
|
let src;
|
|
66
104
|
try { src = fs.readFileSync(file, 'utf8'); } catch { continue; }
|
|
@@ -104,6 +142,47 @@ for (const file of files) {
|
|
|
104
142
|
flag(file, classLine + 1, 'BADS-2',
|
|
105
143
|
`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).`);
|
|
106
144
|
}
|
|
145
|
+
|
|
146
|
+
// BADS-2b — <Button className="... w-full"> at a size under 44px.
|
|
147
|
+
for (let i = 0; i < lines.length; i++) {
|
|
148
|
+
if (!BUTTON_COMPONENT_OPEN.test(lines[i])) continue;
|
|
149
|
+
|
|
150
|
+
// Gather the opening tag: from `<Button` to the first `>` that closes it,
|
|
151
|
+
// capped so a malformed file cannot run away.
|
|
152
|
+
let tag = '';
|
|
153
|
+
let end = i;
|
|
154
|
+
for (let j = i; j < Math.min(i + 12, lines.length); j++) {
|
|
155
|
+
tag += lines[j] + '\n';
|
|
156
|
+
end = j;
|
|
157
|
+
if (/>/.test(lines[j].slice(lines[j].indexOf('<Button'))) && j > i) break;
|
|
158
|
+
if (j === i && /<Button[^>]*>/.test(lines[j])) break;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (!W_FULL.test(tag)) continue;
|
|
162
|
+
if (HAS_MIN_H_11.test(tag)) continue;
|
|
163
|
+
|
|
164
|
+
// A size passed as an expression (`size={size}`, `size={compact ? "sm" :
|
|
165
|
+
// "xl"}`) is unknowable from source, and a primitive forwarding its own
|
|
166
|
+
// size prop is the common shape. Guessing "default" there reported
|
|
167
|
+
// Combobox's trigger, which renders at whatever size its consumer asks
|
|
168
|
+
// for. Present-but-unquoted means skip, not assume.
|
|
169
|
+
const hasSizeProp = /\bsize=/.test(tag);
|
|
170
|
+
const m = tag.match(SIZE_PROP);
|
|
171
|
+
if (hasSizeProp && !m) continue;
|
|
172
|
+
const size = m ? m[1] : 'default';
|
|
173
|
+
if (COMPLIANT_SIZES.has(size)) continue;
|
|
174
|
+
|
|
175
|
+
let escaped = false;
|
|
176
|
+
for (let k = i - 1; k >= Math.max(0, i - 3); k--) {
|
|
177
|
+
if (SMALL_CTA_ESCAPE.test(lines[k])) { escaped = true; break; }
|
|
178
|
+
}
|
|
179
|
+
if (escaped) continue;
|
|
180
|
+
|
|
181
|
+
const px = size === 'lg' ? 40 : size === 'sm' ? 32 : 36;
|
|
182
|
+
flag(file, i + 1, 'BADS-2b',
|
|
183
|
+
`Full-width <Button size="${size}"> is ${px}px tall, under the 44px touch-target floor (SC 2.5.5). A w-full button is the primary action of its container, not dense chrome. Use size="xl", or size="${size}" className="min-h-11 w-full" to keep this text register. Escape with "// allow-small-cta <reason>" above it.`);
|
|
184
|
+
i = end;
|
|
185
|
+
}
|
|
107
186
|
}
|
|
108
187
|
|
|
109
188
|
if (issues.length === 0) {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* readSourceOfTruth — the single reader for `.client-identity.json`'s
|
|
4
|
+
* `sourceOfTruth` block.
|
|
5
|
+
*
|
|
6
|
+
* There is exactly one parser because several things need this value across
|
|
7
|
+
* three runtimes: node lints, `next.config.js` at build time, and React through
|
|
8
|
+
* an inlined env var. Separate copies drift, which is corrections.md #023.
|
|
9
|
+
*
|
|
10
|
+
* It NEVER throws. `next.config.js` calls it, so a malformed identity file that
|
|
11
|
+
* threw here would break every build in the fork rather than degrade to the
|
|
12
|
+
* safe default.
|
|
13
|
+
*
|
|
14
|
+
* It lives flat in `packages/core/scripts/` (not a `lib/` subdirectory) because
|
|
15
|
+
* `scripts/run-script-tests.mjs` reads that directory non-recursively, so a test
|
|
16
|
+
* beside a nested module would silently never run. It ships inside the package
|
|
17
|
+
* because forks receive `@core` over npm, and it needs the `./scripts/*` entry
|
|
18
|
+
* in the package `exports` map to be reachable by specifier.
|
|
19
|
+
*/
|
|
20
|
+
const { readFileSync } = require("node:fs");
|
|
21
|
+
const { join } = require("node:path");
|
|
22
|
+
|
|
23
|
+
const DEFAULTS = Object.freeze({
|
|
24
|
+
components: "bads",
|
|
25
|
+
clientLibrary: null,
|
|
26
|
+
clientDocs: null,
|
|
27
|
+
scanRoots: Object.freeze(["app"]),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
function defaults() {
|
|
31
|
+
return { ...DEFAULTS, scanRoots: [...DEFAULTS.scanRoots] };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function readSourceOfTruth(root = process.cwd()) {
|
|
35
|
+
let data;
|
|
36
|
+
try {
|
|
37
|
+
data = JSON.parse(readFileSync(join(root, ".client-identity.json"), "utf8"));
|
|
38
|
+
} catch {
|
|
39
|
+
return defaults();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const block = data && typeof data === "object" ? data.sourceOfTruth : null;
|
|
43
|
+
if (!block || typeof block !== "object" || Array.isArray(block)) return defaults();
|
|
44
|
+
|
|
45
|
+
const scanRoots = Array.isArray(block.scanRoots)
|
|
46
|
+
? block.scanRoots.filter((r) => typeof r === "string" && r.length > 0)
|
|
47
|
+
: [];
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
components: block.components === "client" ? "client" : "bads",
|
|
51
|
+
clientLibrary: typeof block.clientLibrary === "string" ? block.clientLibrary : null,
|
|
52
|
+
clientDocs: typeof block.clientDocs === "string" ? block.clientDocs : null,
|
|
53
|
+
scanRoots: scanRoots.length > 0 ? scanRoots : [...DEFAULTS.scanRoots],
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
exports.readSourceOfTruth = readSourceOfTruth;
|
|
58
|
+
exports.DEFAULTS = DEFAULTS;
|