@behavioral-agentic-design-system/core 0.39.1 → 0.42.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/README.md +2 -0
- package/package.json +26 -5
- package/scripts/a11y-lint.cjs +88 -8
- package/scripts/bads-components.mjs +118 -0
- package/scripts/build-tokens.cjs +133 -12
- package/scripts/check-stories.mjs +1 -1
- package/scripts/health-report.mjs +16 -2
- package/scripts/lint-component-source.mjs +100 -0
- package/scripts/lint-microanimation.mjs +267 -0
- package/scripts/lint-slop.mjs +25 -1
- 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 +121 -6
- package/src/api/layers/file.ts +1 -0
- package/src/app/opengraph-image.tsx +5 -0
- package/src/app/preview/components/page.tsx +2237 -2
- package/src/app/shell.tsx +17 -16
- package/src/components/Foundations/Motion.stories.tsx +1 -0
- package/src/components/customize/brand-mark-section.tsx +4 -2
- package/src/components/customize/design-controls.tsx +17 -2
- 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/studio/studio.tsx +153 -0
- package/src/components/ui/accordion.tsx +7 -0
- package/src/components/ui/alert.tsx +1 -0
- package/src/components/ui/anchor.tsx +37 -3
- package/src/components/ui/announcement-bar.tsx +256 -0
- package/src/components/ui/attachment.tsx +211 -0
- package/src/components/ui/badge.tsx +1 -0
- package/src/components/ui/callout.tsx +218 -0
- package/src/components/ui/chart.tsx +5 -14
- package/src/components/ui/code.tsx +1 -1
- package/src/components/ui/color-picker.tsx +2 -2
- package/src/components/ui/format-relative-time.tsx +139 -0
- package/src/components/ui/gauge-chart.tsx +238 -0
- package/src/components/ui/grid.tsx +255 -0
- package/src/components/ui/heatmap.tsx +256 -0
- package/src/components/ui/icon.tsx +108 -0
- package/src/components/ui/index.ts +17 -0
- package/src/components/ui/infinite-scroll.tsx +103 -0
- package/src/components/ui/json-input.tsx +351 -0
- package/src/components/ui/navigation-progress.tsx +281 -0
- package/src/components/ui/number-input.tsx +1 -4
- package/src/components/ui/page-header.tsx +63 -0
- package/src/components/ui/password-input.tsx +2 -1
- package/src/components/ui/password-strength-input.tsx +288 -0
- package/src/components/ui/pill.tsx +140 -0
- package/src/components/ui/popover.tsx +27 -4
- 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/scroll-progress.tsx +100 -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/snackbar.tsx +393 -0
- package/src/components/ui/sortable-list.tsx +342 -0
- package/src/components/ui/sparkline.tsx +2 -14
- package/src/components/ui/squircle.tsx +1 -1
- package/src/components/ui/table.tsx +1 -1
- package/src/components/ui/textarea.tsx +28 -1
- package/src/components/ui/tour.tsx +1 -3
- package/src/data/docs-index.ts +25 -0
- package/src/hooks/use-reduced-motion.ts +6 -0
- package/src/lib/clamp.ts +2 -0
- package/src/stories/Accordion.stories.tsx +59 -0
- package/src/stories/Alert.stories.tsx +3 -1
- package/src/stories/Anchor.stories.tsx +54 -0
- package/src/stories/AnnouncementBar.stories.tsx +261 -0
- package/src/stories/Attachment.stories.tsx +189 -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 +8 -0
- package/src/stories/Code.stories.tsx +1 -0
- package/src/stories/ColorPicker.stories.tsx +24 -0
- package/src/stories/FormatRelativeTime.stories.tsx +116 -0
- package/src/stories/GaugeChart.stories.tsx +163 -0
- package/src/stories/Grid.stories.tsx +197 -0
- package/src/stories/Heatmap.stories.tsx +172 -0
- package/src/stories/Icon.stories.tsx +175 -0
- package/src/stories/InfiniteScroll.stories.tsx +225 -0
- package/src/stories/JsonInput.stories.tsx +212 -0
- package/src/stories/MultiSelect.stories.tsx +1 -1
- package/src/stories/NavigationProgress.stories.tsx +159 -0
- package/src/stories/NumberInput.stories.tsx +1 -0
- package/src/stories/PageHeader.stories.tsx +102 -0
- package/src/stories/PasswordInput.stories.tsx +4 -0
- package/src/stories/PasswordStrengthInput.stories.tsx +211 -0
- package/src/stories/Pill.stories.tsx +201 -0
- package/src/stories/Popover.stories.tsx +29 -1
- package/src/stories/Portal.stories.tsx +191 -0
- package/src/stories/Presence.stories.tsx +228 -0
- package/src/stories/ProgressStack.stories.tsx +287 -0
- package/src/stories/ScrollProgress.stories.tsx +117 -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/Snackbar.stories.tsx +315 -0
- package/src/stories/SortableList.stories.tsx +263 -0
- package/src/stories/Sparkline.stories.tsx +3 -0
- package/src/stories/Squircle.stories.tsx +1 -0
- package/src/stories/Table.stories.tsx +1 -0
- package/src/stories/Textarea.stories.tsx +18 -0
- package/src/stories/Tour.stories.tsx +1 -0
- package/src/stories/story-groups.json +26 -6
- package/src/styles.css +133 -12
- package/LICENSE +0 -21
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* lint-component-source — when the client owns the components, stop new code
|
|
4
|
+
* importing BADS primitives.
|
|
5
|
+
*
|
|
6
|
+
* This is the enforcement half of the sourceOfTruth switch. The agent rules in
|
|
7
|
+
* CLAUDE.md are framing and drift; this is the ratchet.
|
|
8
|
+
*
|
|
9
|
+
* It scans `sourceOfTruth.scanRoots` (default ["app"], from
|
|
10
|
+
* source-of-truth.cjs's DEFAULTS). It deliberately does NOT default to
|
|
11
|
+
* scanning `components/`: upstream ships ~127 files there that import core
|
|
12
|
+
* UI, and a fork is a clone of upstream, so scanning it wholesale would flag
|
|
13
|
+
* the whole template library on day one and the lint would get bypassed
|
|
14
|
+
* rather than obeyed. A fork names its own authored directories.
|
|
15
|
+
*
|
|
16
|
+
* File discovery is delegated to ./lib/scan-roots.cjs — the same
|
|
17
|
+
* resolveScanFiles()/guardEmptyScan() pair a11y-lint.cjs, size-audit.cjs, and
|
|
18
|
+
* lint-slop.mjs use. That module exists precisely because a hand-rolled walk
|
|
19
|
+
* over a fixed root list silently reports "clean" when none of its roots
|
|
20
|
+
* exist on disk (0 files read, 0 findings, exit 0) — indistinguishable from a
|
|
21
|
+
* real pass. guardEmptyScan() is what turns that into a loud failure instead.
|
|
22
|
+
* scanRoots here comes from the fork's own sourceOfTruth block, not the
|
|
23
|
+
* module's built-in default list, so it's passed in explicitly.
|
|
24
|
+
*
|
|
25
|
+
* Escape hatch: `// allow-bads-component <reason>` on the line above the
|
|
26
|
+
* import.
|
|
27
|
+
*
|
|
28
|
+
* Run:
|
|
29
|
+
* node lint-component-source.mjs # exit 1 on findings
|
|
30
|
+
* node lint-component-source.mjs --warn # advisory, exit 0
|
|
31
|
+
*/
|
|
32
|
+
import { readFileSync } from "node:fs";
|
|
33
|
+
import { relative } from "node:path";
|
|
34
|
+
import { createRequire } from "node:module";
|
|
35
|
+
|
|
36
|
+
const require = createRequire(import.meta.url);
|
|
37
|
+
const { readSourceOfTruth } = require("./source-of-truth.cjs");
|
|
38
|
+
// scan-roots.cjs is CommonJS (shared with the .cjs bins); the default import
|
|
39
|
+
// is Node's CJS→ESM interop and always carries the full module.exports
|
|
40
|
+
// object, unlike named imports off an arbitrary CJS module. Mirrors how
|
|
41
|
+
// lint-slop.mjs consumes the same module.
|
|
42
|
+
import scanRootsLib from "./lib/scan-roots.cjs";
|
|
43
|
+
const { resolveScanFiles, guardEmptyScan } = scanRootsLib;
|
|
44
|
+
|
|
45
|
+
const ROOT = process.cwd();
|
|
46
|
+
const warn = process.argv.includes("--warn");
|
|
47
|
+
|
|
48
|
+
// The package name never changes on rename, so this specifier is literal —
|
|
49
|
+
// never a @<slug>/ placeholder.
|
|
50
|
+
const BADS_UI = /from\s+["']@behavioral-agentic-design-system\/core\/components\/ui\/[^"']*["']/;
|
|
51
|
+
const ESCAPE = /\/\/\s*allow-bads-component\s+\S/;
|
|
52
|
+
|
|
53
|
+
const sot = readSourceOfTruth(ROOT);
|
|
54
|
+
|
|
55
|
+
if (sot.components !== "client") {
|
|
56
|
+
console.log("OK lint-component-source: BADS owns components here, nothing to check.");
|
|
57
|
+
process.exit(0);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// scanRoots is the fork's own sourceOfTruth.scanRoots (default ["app"]), not
|
|
61
|
+
// scan-roots.cjs's built-in DEFAULT_SCAN_ROOTS list — the switch owns this
|
|
62
|
+
// scope, the shared module only owns the walk + false-green guard.
|
|
63
|
+
const scan = resolveScanFiles({
|
|
64
|
+
root: ROOT,
|
|
65
|
+
argv: process.argv.slice(2),
|
|
66
|
+
scanRoots: sot.scanRoots,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const findings = [];
|
|
70
|
+
for (const file of scan.files) {
|
|
71
|
+
const lines = readFileSync(file, "utf8").split("\n");
|
|
72
|
+
lines.forEach((line, i) => {
|
|
73
|
+
if (!BADS_UI.test(line)) return;
|
|
74
|
+
if (i > 0 && ESCAPE.test(lines[i - 1])) return;
|
|
75
|
+
findings.push({ file: relative(ROOT, file), line: i + 1, text: line.trim() });
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (findings.length === 0) {
|
|
80
|
+
// Must run before any success message prints: this is the guard against
|
|
81
|
+
// the false-green the 2026-09-14 plan revision exists to prevent. It exits
|
|
82
|
+
// the process (non-zero, listing what it looked for) when none of
|
|
83
|
+
// sot.scanRoots exist on disk, rather than letting the line below claim a
|
|
84
|
+
// clean scan over zero files read.
|
|
85
|
+
if (guardEmptyScan(scan, "lint-component-source")) {
|
|
86
|
+
/* exited */
|
|
87
|
+
}
|
|
88
|
+
console.log(`OK lint-component-source: no BADS component imports under ${sot.scanRoots.join(", ")}.`);
|
|
89
|
+
process.exit(0);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const label = warn ? "WARN" : "FAIL";
|
|
93
|
+
console.error(`${label} lint-component-source: ${findings.length} BADS component import(s) in a client-owned fork.`);
|
|
94
|
+
console.error(` This fork's components come from ${sot.clientLibrary}.`);
|
|
95
|
+
for (const f of findings) {
|
|
96
|
+
console.error(` ${f.file}:${f.line}`);
|
|
97
|
+
console.error(` ${f.text}`);
|
|
98
|
+
}
|
|
99
|
+
console.error(` escape: add "// allow-bads-component <reason>" on the line above.`);
|
|
100
|
+
process.exit(warn ? 0 : 1);
|
|
@@ -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/lint-slop.mjs
CHANGED
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
* pnpm lint:slop # report, exit 1 on any finding
|
|
69
69
|
* pnpm lint:slop:warn # report, exit 0 (advisory; used in the a11y umbrella)
|
|
70
70
|
* node packages/core/scripts/lint-slop.mjs path/to.tsx # scan a specific file
|
|
71
|
+
* node packages/core/scripts/lint-slop.mjs path/to/dir # scan every file under a directory
|
|
71
72
|
*/
|
|
72
73
|
|
|
73
74
|
import fs from "node:fs";
|
|
@@ -91,10 +92,20 @@ const advisory = process.argv.includes("--warn");
|
|
|
91
92
|
// a11y-lint.cjs, size-audit.cjs, a11y-ratchet.mjs and lint-token-intent.mjs
|
|
92
93
|
// used to each keep a drifted copy of the same root list. Set
|
|
93
94
|
// BADS_LINT_ROOTS to point this at a non-standard tree.
|
|
95
|
+
//
|
|
96
|
+
// allowDirArgs: without this, a directory positional argument fell into
|
|
97
|
+
// resolveScanFiles' "explicit path" branch, went straight to fs.readFileSync,
|
|
98
|
+
// threw EISDIR, and the per-file try/catch below silently swallowed it —
|
|
99
|
+
// `node lint-slop.mjs <directory>` reported clean having read zero files.
|
|
100
|
+
// Same bug, same fix, as a11y-lint.cjs (found 2026-09-15 from a real consumer
|
|
101
|
+
// fork run scanning a11y-lint specifically; lint-slop shared the identical
|
|
102
|
+
// scan-roots call shape so it carried the same gap even though nobody had
|
|
103
|
+
// hit it yet).
|
|
94
104
|
const scan = resolveScanFiles({
|
|
95
105
|
root: ROOT,
|
|
96
106
|
argv: process.argv.slice(2),
|
|
97
107
|
excludeStories: true,
|
|
108
|
+
allowDirArgs: true,
|
|
98
109
|
});
|
|
99
110
|
|
|
100
111
|
function fileList() {
|
|
@@ -102,12 +113,14 @@ function fileList() {
|
|
|
102
113
|
}
|
|
103
114
|
|
|
104
115
|
const findings = [];
|
|
116
|
+
const unreadableExplicitPaths = [];
|
|
105
117
|
|
|
106
118
|
for (const file of fileList()) {
|
|
107
119
|
let src;
|
|
108
120
|
try {
|
|
109
121
|
src = fs.readFileSync(file, "utf8");
|
|
110
|
-
} catch {
|
|
122
|
+
} catch (err) {
|
|
123
|
+
if (scan.mode === "explicit") unreadableExplicitPaths.push({ file, message: err.message });
|
|
111
124
|
continue;
|
|
112
125
|
}
|
|
113
126
|
const lines = src.split("\n");
|
|
@@ -171,6 +184,17 @@ for (const file of fileList()) {
|
|
|
171
184
|
}
|
|
172
185
|
}
|
|
173
186
|
|
|
187
|
+
if (unreadableExplicitPaths.length) {
|
|
188
|
+
console.error(
|
|
189
|
+
`lint-slop: ${unreadableExplicitPaths.length} path argument${unreadableExplicitPaths.length === 1 ? "" : "s"} ` +
|
|
190
|
+
`could not be read — nothing under ${unreadableExplicitPaths.length === 1 ? "it was" : "them was"} scanned:\n\n` +
|
|
191
|
+
unreadableExplicitPaths.map((p) => ` ${p.file} — ${p.message}`).join("\n") +
|
|
192
|
+
`\n\nA directory argument is walked automatically now — this means the path doesn't exist, ` +
|
|
193
|
+
`isn't readable, or is neither a file nor a directory.`
|
|
194
|
+
);
|
|
195
|
+
process.exit(1);
|
|
196
|
+
}
|
|
197
|
+
|
|
174
198
|
if (findings.length === 0) {
|
|
175
199
|
if (guardEmptyScan(scan, "lint-slop")) { /* exited */ }
|
|
176
200
|
console.log(
|
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;
|