@behavioral-agentic-design-system/core 0.37.0 → 0.39.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 -4
- package/scripts/a11y-lint.cjs +8 -2
- package/scripts/a11y-ratchet.mjs +172 -0
- package/scripts/accent-as-text.mjs +274 -0
- package/scripts/bads-doctor.mjs +2 -1
- package/scripts/check-stories.mjs +265 -52
- package/scripts/contrast.mjs +44 -0
- package/scripts/health-report.mjs +211 -122
- package/scripts/lint-slop.mjs +44 -2
- package/scripts/oklch-to-hex.cjs +7 -1
- package/scripts/ratchet.mjs +326 -0
- package/scripts/slop-rules.mjs +156 -0
- package/scripts/token-nearest.mjs +333 -0
- package/scripts/wcag-audit.cjs +59 -8
- package/src/app/preview/components/page.tsx +363 -0
- package/src/components/Foundations/Typography.stories.tsx +82 -21
- package/src/components/ui/accordion.tsx +67 -5
- package/src/components/ui/alert.tsx +20 -7
- package/src/components/ui/avatar.tsx +18 -4
- package/src/components/ui/breadcrumb.tsx +47 -0
- package/src/components/ui/checkbox-card.tsx +48 -8
- package/src/components/ui/checkbox.tsx +17 -8
- package/src/components/ui/format-date.tsx +107 -0
- package/src/components/ui/progress.tsx +6 -5
- package/src/components/ui/sparkline.tsx +198 -0
- package/src/components/ui/tag.tsx +17 -1
- package/src/components/ui/tags-input.tsx +84 -11
- package/src/components/ui/toggle-group.tsx +13 -0
- package/src/components/ui/week-picker.tsx +463 -0
- package/src/data/docs-index.ts +12 -0
- package/src/lib/theme-editor.ts +7 -1
- package/src/stories/Accordion.stories.tsx +59 -1
- package/src/stories/ActionBar.stories.tsx +1 -1
- package/src/stories/Affix.stories.tsx +1 -1
- package/src/stories/AiBadge.stories.tsx +1 -1
- package/src/stories/Alert.stories.tsx +36 -1
- package/src/stories/AlertDialog.stories.tsx +1 -1
- package/src/stories/Anchor.stories.tsx +1 -1
- package/src/stories/AngleSlider.stories.tsx +1 -1
- package/src/stories/AspectRatio.stories.tsx +1 -1
- package/src/stories/Autocomplete.stories.tsx +1 -1
- package/src/stories/Avatar.stories.tsx +41 -1
- package/src/stories/Badge.stories.tsx +1 -1
- package/src/stories/Blockquote.stories.tsx +1 -1
- package/src/stories/BottomNavigation.stories.tsx +1 -1
- package/src/stories/Breadcrumb.stories.tsx +38 -5
- package/src/stories/Burger.stories.tsx +1 -1
- package/src/stories/Button.stories.tsx +9 -1
- package/src/stories/ButtonGroup.stories.tsx +1 -1
- package/src/stories/Calendar.stories.tsx +1 -1
- package/src/stories/Card.stories.tsx +1 -1
- package/src/stories/Carousel.stories.tsx +1 -1
- package/src/stories/Cascader.stories.tsx +1 -1
- package/src/stories/Chart.stories.tsx +1 -1
- package/src/stories/ChatBubble.stories.tsx +1 -1
- package/src/stories/ChatMarker.stories.tsx +1 -1
- package/src/stories/Checkbox.stories.tsx +36 -5
- package/src/stories/CheckboxCard.stories.tsx +37 -2
- package/src/stories/CheckboxGroup.stories.tsx +1 -1
- package/src/stories/Chip.stories.tsx +1 -1
- package/src/stories/CircularProgress.stories.tsx +17 -1
- package/src/stories/Clipboard.stories.tsx +1 -1
- package/src/stories/CloseButton.stories.tsx +1 -1
- package/src/stories/Code.stories.tsx +1 -1
- package/src/stories/Collapsible.stories.tsx +1 -1
- package/src/stories/ColorPicker.stories.tsx +1 -1
- package/src/stories/ColorSwatch.stories.tsx +1 -1
- package/src/stories/Combobox.stories.tsx +1 -1
- package/src/stories/Command.stories.tsx +1 -1
- package/src/stories/Container.stories.tsx +1 -1
- package/src/stories/ContextMenu.stories.tsx +1 -1
- package/src/stories/CopyButton.stories.tsx +9 -1
- package/src/stories/DataList.stories.tsx +1 -1
- package/src/stories/DataTable.stories.tsx +1 -1
- package/src/stories/DateField.stories.tsx +1 -1
- package/src/stories/DatePicker.stories.tsx +1 -1
- package/src/stories/DateRangePicker.stories.tsx +1 -1
- package/src/stories/Dialog.stories.tsx +1 -1
- package/src/stories/Drawer.stories.tsx +1 -1
- package/src/stories/DropdownMenu.stories.tsx +1 -1
- package/src/stories/Editable.stories.tsx +1 -1
- package/src/stories/EmptyState.stories.tsx +1 -1
- package/src/stories/Field.stories.tsx +1 -1
- package/src/stories/Fieldset.stories.tsx +1 -1
- package/src/stories/FileButton.stories.tsx +1 -1
- package/src/stories/FileUpload.stories.tsx +1 -1
- package/src/stories/FloatLabel.stories.tsx +1 -1
- package/src/stories/FloatingActionButton.stories.tsx +1 -1
- package/src/stories/FloatingIndicator.stories.tsx +1 -1
- package/src/stories/FloatingPanel.stories.tsx +9 -1
- package/src/stories/FocusTrap.stories.tsx +1 -1
- package/src/stories/FormatByte.stories.tsx +1 -1
- package/src/stories/FormatDate.stories.tsx +174 -0
- package/src/stories/FormatNumber.stories.tsx +1 -1
- package/src/stories/Highlight.stories.tsx +1 -1
- package/src/stories/HoverCard.stories.tsx +1 -1
- package/src/stories/Image.stories.tsx +1 -1
- package/src/stories/Indicator.stories.tsx +17 -1
- package/src/stories/Input.stories.tsx +1 -1
- package/src/stories/InputClearButton.stories.tsx +1 -1
- package/src/stories/InputGroup.stories.tsx +1 -1
- package/src/stories/Kbd.stories.tsx +1 -1
- package/src/stories/KeyboardShortcut.stories.tsx +1 -1
- package/src/stories/Label.stories.tsx +1 -1
- package/src/stories/Link.stories.tsx +1 -1
- package/src/stories/List.stories.tsx +1 -1
- package/src/stories/Listbox.stories.tsx +1 -1
- package/src/stories/LoadingDots.stories.tsx +1 -1
- package/src/stories/LoadingOverlay.stories.tsx +1 -1
- package/src/stories/Mark.stories.tsx +1 -1
- package/src/stories/Marquee.stories.tsx +1 -1
- package/src/stories/Masonry.stories.tsx +1 -1
- package/src/stories/Menubar.stories.tsx +1 -1
- package/src/stories/Meter.stories.tsx +1 -1
- package/src/stories/MonthPicker.stories.tsx +1 -1
- package/src/stories/MotionToggle.stories.tsx +1 -1
- package/src/stories/MultiSelect.stories.tsx +1 -1
- package/src/stories/NativeSelect.stories.tsx +1 -1
- package/src/stories/NavLink.stories.tsx +1 -1
- package/src/stories/NavigationMenu.stories.tsx +1 -1
- package/src/stories/NavigationRail.stories.tsx +9 -1
- package/src/stories/Notification.stories.tsx +1 -1
- package/src/stories/NumberInput.stories.tsx +1 -1
- package/src/stories/Overlay.stories.tsx +1 -1
- package/src/stories/Pagination.stories.tsx +1 -1
- package/src/stories/PasswordInput.stories.tsx +1 -1
- package/src/stories/PinInput.stories.tsx +1 -1
- package/src/stories/Popover.stories.tsx +1 -1
- package/src/stories/Progress.stories.tsx +11 -1
- package/src/stories/Prose.stories.tsx +1 -1
- package/src/stories/QrCode.stories.tsx +1 -1
- package/src/stories/Questionnaire.stories.tsx +1 -1
- package/src/stories/RadioGroup.stories.tsx +1 -1
- package/src/stories/RatingGroup.stories.tsx +1 -1
- package/src/stories/Resizable.stories.tsx +1 -1
- package/src/stories/Result.stories.tsx +1 -1
- package/src/stories/Reveal.stories.tsx +1 -1
- package/src/stories/RollingNumber.stories.tsx +1 -1
- package/src/stories/ScrollArea.stories.tsx +1 -1
- package/src/stories/SearchInput.stories.tsx +1 -1
- package/src/stories/SegmentedControl.stories.tsx +1 -1
- package/src/stories/Select.stories.tsx +1 -1
- package/src/stories/Separator.stories.tsx +1 -1
- package/src/stories/Sheet.stories.tsx +1 -1
- package/src/stories/Sidebar.stories.tsx +1 -1
- package/src/stories/SignaturePad.stories.tsx +1 -1
- package/src/stories/SimpleGrid.stories.tsx +1 -1
- package/src/stories/Skeleton.stories.tsx +1 -1
- package/src/stories/SkeletonTable.stories.tsx +1 -1
- package/src/stories/SkipLink.stories.tsx +1 -1
- package/src/stories/Slider.stories.tsx +1 -1
- package/src/stories/Sonner.stories.tsx +1 -1
- package/src/stories/Sparkline.stories.tsx +208 -0
- package/src/stories/Spinner.stories.tsx +9 -1
- package/src/stories/Spoiler.stories.tsx +1 -1
- package/src/stories/Squircle.stories.tsx +1 -1
- package/src/stories/Stack.stories.tsx +1 -1
- package/src/stories/StatusBadge.stories.tsx +1 -1
- package/src/stories/Stepper.stories.tsx +1 -1
- package/src/stories/Switch.stories.tsx +1 -1
- package/src/stories/Table.stories.tsx +1 -1
- package/src/stories/Tabs.stories.tsx +1 -1
- package/src/stories/Tag.stories.tsx +23 -1
- package/src/stories/TagsInput.stories.tsx +46 -1
- package/src/stories/Text.stories.tsx +1 -1
- package/src/stories/Textarea.stories.tsx +1 -1
- package/src/stories/ThemeIcon.stories.tsx +1 -1
- package/src/stories/TimePicker.stories.tsx +1 -1
- package/src/stories/Timeline.stories.tsx +9 -1
- package/src/stories/Timer.stories.tsx +1 -1
- package/src/stories/Toggle.stories.tsx +1 -1
- package/src/stories/ToggleGroup.stories.tsx +21 -1
- package/src/stories/ToggleTip.stories.tsx +1 -1
- package/src/stories/Toolbar.stories.tsx +1 -1
- package/src/stories/Tooltip.stories.tsx +1 -1
- package/src/stories/Tour.stories.tsx +1 -1
- package/src/stories/TransferList.stories.tsx +1 -1
- package/src/stories/TreeSelect.stories.tsx +1 -1
- package/src/stories/TreeView.stories.tsx +1 -1
- package/src/stories/TypingIndicator.stories.tsx +1 -1
- package/src/stories/VisuallyHidden.stories.tsx +1 -1
- package/src/stories/Watermark.stories.tsx +1 -1
- package/src/stories/WeekPicker.stories.tsx +90 -0
- package/src/stories/WordRotate.stories.tsx +1 -1
- package/src/stories/YearPicker.stories.tsx +1 -1
- package/src/stories/story-groups.json +199 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@behavioral-agentic-design-system/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.0",
|
|
4
4
|
"description": "BADS core — tokens, shadcn/ui components, and the BADS template shell (app routes, customize tab, theme hooks). Forks consume this and re-export, keeping client repos to ~30 lines of glue.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Matthew Stephens <work@matthewstephens.com> (https://github.com/matthewlarn)",
|
|
@@ -33,10 +33,12 @@
|
|
|
33
33
|
"files": [
|
|
34
34
|
"src",
|
|
35
35
|
"scripts",
|
|
36
|
-
"README.md"
|
|
36
|
+
"README.md",
|
|
37
|
+
"!scripts/**/*.test.mjs"
|
|
37
38
|
],
|
|
38
39
|
"bin": {
|
|
39
40
|
"bads-a11y-lint": "scripts/a11y-lint.cjs",
|
|
41
|
+
"bads-a11y-ratchet": "scripts/a11y-ratchet.mjs",
|
|
40
42
|
"bads-build-fonts": "scripts/build-fonts.cjs",
|
|
41
43
|
"bads-build-tokens": "scripts/build-tokens.cjs",
|
|
42
44
|
"bads-check-stories": "scripts/check-stories.mjs",
|
|
@@ -45,9 +47,11 @@
|
|
|
45
47
|
"bads-fix-stories": "scripts/fix-stories.mjs",
|
|
46
48
|
"bads-generate-stories": "scripts/generate-stories.cjs",
|
|
47
49
|
"bads-health-report": "scripts/health-report.mjs",
|
|
50
|
+
"bads-lint-accent-text": "scripts/accent-as-text.mjs",
|
|
48
51
|
"bads-lint-ethics": "scripts/lint-ethics-contract.mjs",
|
|
49
52
|
"bads-lint-slop": "scripts/lint-slop.mjs",
|
|
50
53
|
"bads-lint-token-intent": "scripts/lint-token-intent.mjs",
|
|
54
|
+
"bads-token-nearest": "scripts/token-nearest.mjs",
|
|
51
55
|
"bads-oklch-to-hex": "scripts/oklch-to-hex.cjs",
|
|
52
56
|
"bads-size-audit": "scripts/size-audit.cjs",
|
|
53
57
|
"bads-sync": "scripts/bads-sync.mjs",
|
|
@@ -113,7 +117,7 @@
|
|
|
113
117
|
},
|
|
114
118
|
"dependencies": {
|
|
115
119
|
"@radix-ui/react-alert-dialog": "^1.1.23",
|
|
116
|
-
"@xmldom/xmldom": "^0.9.
|
|
120
|
+
"@xmldom/xmldom": "^0.9.12",
|
|
117
121
|
"cheerio": "^1.0.0",
|
|
118
122
|
"class-variance-authority": "^0.7.0",
|
|
119
123
|
"clsx": "^2.1.0",
|
|
@@ -257,6 +261,6 @@
|
|
|
257
261
|
}
|
|
258
262
|
},
|
|
259
263
|
"devDependencies": {
|
|
260
|
-
"@types/react-dom": "^19.2.
|
|
264
|
+
"@types/react-dom": "^19.2.7"
|
|
261
265
|
}
|
|
262
266
|
}
|
package/scripts/a11y-lint.cjs
CHANGED
|
@@ -173,13 +173,19 @@ for (const file of files) {
|
|
|
173
173
|
'Inline pixel font size. Use a text-* utility or rem-based value so 200% zoom still works.');
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
+
// Same escape hatch as the named-step check below. A vendored component that ships
|
|
177
|
+
// text-[11px] is in exactly the position the named-step comment describes, and before
|
|
178
|
+
// this the two paths disagreed: `text-xs` could be excused and `text-[11px]` could not,
|
|
179
|
+
// so a fork mirroring a client's real UI had no way to record the deviation.
|
|
180
|
+
const allowSmallText = /\/\/\s*allow-small-text/.test(line)
|
|
181
|
+
|| (i > 0 && /allow-small-text/.test(lines[i - 1]));
|
|
176
182
|
let match;
|
|
177
183
|
ARBITRARY_TEXT_PX.lastIndex = 0;
|
|
178
184
|
while ((match = ARBITRARY_TEXT_PX.exec(line))) {
|
|
179
185
|
const px = parseInt(match[1], 10);
|
|
180
|
-
if (px < TEXT_FLOOR_PX) {
|
|
186
|
+
if (px < TEXT_FLOOR_PX && !allowSmallText) {
|
|
181
187
|
flag(file, lineNum, '1.4.4', 'tiny-text',
|
|
182
|
-
`text-[${px}px] is below the ${TEXT_FLOOR_PX}px AAA accessibility floor. Use ${TS.smallestCompliant} or larger.`);
|
|
188
|
+
`text-[${px}px] is below the ${TEXT_FLOOR_PX}px AAA accessibility floor. Use ${TS.smallestCompliant} or larger, or add "// allow-small-text" above if a vendored component forces it.`);
|
|
183
189
|
}
|
|
184
190
|
}
|
|
185
191
|
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* a11y-ratchet — the first consumer of packages/core/scripts/ratchet.mjs.
|
|
4
|
+
*
|
|
5
|
+
* Runs `a11y-lint` over the repo, counts findings per file for ONE rule, and
|
|
6
|
+
* hands them to the ratchet: listed files may stay in violation but may not get
|
|
7
|
+
* worse, and nothing new may join the list.
|
|
8
|
+
*
|
|
9
|
+
* The default rule is `tiny-text`, the sub-14px AAA type floor, because that is
|
|
10
|
+
* the rule the two-mode world could not land. A fork mirroring a dense product
|
|
11
|
+
* ships 10 and 11px text across most of its surfaces. Strict mode fails several
|
|
12
|
+
* hundred files on day one and gets turned off; warn mode prints several
|
|
13
|
+
* hundred lines and gets ignored. Neither mode ever makes the NEXT screen legal,
|
|
14
|
+
* which is the only thing that was actually being asked.
|
|
15
|
+
*
|
|
16
|
+
* Under a ratchet the existing screens are recorded once and left alone, and
|
|
17
|
+
* screen 301 fails. The list can only shrink from there.
|
|
18
|
+
*
|
|
19
|
+
* a11y-lint has no machine-readable output and exports nothing, so this parses
|
|
20
|
+
* its printed report — the same thing a11y-lint's own tests do. The parser is
|
|
21
|
+
* deliberately strict about the shape it expects and reports a file it cannot
|
|
22
|
+
* read as unmeasured rather than as clean, because "we did not look" and
|
|
23
|
+
* "nothing there" must never render the same way.
|
|
24
|
+
*
|
|
25
|
+
* Run:
|
|
26
|
+
* pnpm ratchet:a11y # check (exit 1 on growth or a new entry)
|
|
27
|
+
* pnpm ratchet:a11y --warn # advisory, always exit 0
|
|
28
|
+
* pnpm ratchet:a11y:init # record today's violations as the baseline
|
|
29
|
+
* npx bads-a11y-ratchet app/shell --rule contrast-text --base main
|
|
30
|
+
*
|
|
31
|
+
* The baseline lives in .bads-ratchet.json at the repo root and is meant to be
|
|
32
|
+
* committed and reviewed. Shrinking it is the work; growing it is the thing the
|
|
33
|
+
* gate exists to prevent.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
import fs from "node:fs";
|
|
37
|
+
import path from "node:path";
|
|
38
|
+
import { fileURLToPath } from "node:url";
|
|
39
|
+
import { execFileSync } from "node:child_process";
|
|
40
|
+
import {
|
|
41
|
+
readBaseline,
|
|
42
|
+
writeBaseline,
|
|
43
|
+
runRatchet,
|
|
44
|
+
BASELINE_FILE,
|
|
45
|
+
SCHEMA_VERSION,
|
|
46
|
+
} from "./ratchet.mjs";
|
|
47
|
+
|
|
48
|
+
const ROOT = process.cwd();
|
|
49
|
+
// The lint is resolved relative to THIS file, not to cwd, so a fork running the
|
|
50
|
+
// packaged bin from its own repo root still finds it.
|
|
51
|
+
const A11Y_LINT = path.join(path.dirname(fileURLToPath(import.meta.url)), "a11y-lint.cjs");
|
|
52
|
+
const argv = process.argv.slice(2);
|
|
53
|
+
const flag = (name, fallback) => {
|
|
54
|
+
const i = argv.indexOf(`--${name}`);
|
|
55
|
+
return i >= 0 && argv[i + 1] && !argv[i + 1].startsWith("--") ? argv[i + 1] : fallback;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const RULE = flag("rule", "tiny-text");
|
|
59
|
+
const BASE_REF = flag("base", "origin/main");
|
|
60
|
+
const INIT = argv.includes("--init");
|
|
61
|
+
const ADVISORY = argv.includes("--warn");
|
|
62
|
+
const RULE_ID = `a11y:${RULE}`;
|
|
63
|
+
|
|
64
|
+
// Positional args override the defaults, so a fork points it at its own tree
|
|
65
|
+
// (`npx bads-a11y-ratchet app/_content app/shell`) the way size-audit does.
|
|
66
|
+
const argRoots = argv.filter((a, i) => !a.startsWith("--") && !argv[i - 1]?.startsWith("--"));
|
|
67
|
+
const SCAN_ROOTS = argRoots.length
|
|
68
|
+
? argRoots
|
|
69
|
+
: ["app", "components", "packages/core/src/components", "packages/core/src/app"];
|
|
70
|
+
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
// Measurement
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
|
|
75
|
+
function scanFiles() {
|
|
76
|
+
const out = [];
|
|
77
|
+
const walk = (dir) => {
|
|
78
|
+
if (!fs.existsSync(dir)) return;
|
|
79
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
80
|
+
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
81
|
+
const full = path.join(dir, entry.name);
|
|
82
|
+
if (entry.isDirectory()) walk(full);
|
|
83
|
+
else if (/\.tsx$/.test(entry.name) && !/\.stories\.tsx$/.test(entry.name)) out.push(full);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
for (const r of SCAN_ROOTS) walk(path.join(ROOT, r));
|
|
87
|
+
return out.map((f) => path.relative(ROOT, f));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* `{ relativePath: count }` for one a11y-lint rule.
|
|
92
|
+
*
|
|
93
|
+
* Every scanned file gets an entry, zero included. A missing key means "not
|
|
94
|
+
* measured" to the ratchet, so a file that is genuinely clean must say 0 out
|
|
95
|
+
* loud rather than being absent.
|
|
96
|
+
*/
|
|
97
|
+
function measure(files) {
|
|
98
|
+
const counts = Object.fromEntries(files.map((f) => [f, 0]));
|
|
99
|
+
if (!files.length) return counts;
|
|
100
|
+
|
|
101
|
+
let stdout = "";
|
|
102
|
+
try {
|
|
103
|
+
stdout = execFileSync(
|
|
104
|
+
process.execPath,
|
|
105
|
+
[A11Y_LINT, ...files],
|
|
106
|
+
{ cwd: ROOT, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], maxBuffer: 32 * 1024 * 1024 },
|
|
107
|
+
);
|
|
108
|
+
} catch (err) {
|
|
109
|
+
// a11y-lint exits 1 when it finds anything, which is the normal path here.
|
|
110
|
+
if (err.stdout === undefined) throw err;
|
|
111
|
+
stdout = err.stdout;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let currentFile = null;
|
|
115
|
+
for (const raw of stdout.split("\n")) {
|
|
116
|
+
if (!raw.trim()) continue;
|
|
117
|
+
if (!/^\s/.test(raw)) {
|
|
118
|
+
// a bare, unindented line is a file header (or the trailing summary)
|
|
119
|
+
currentFile = /^\d+ issues?/.test(raw) ? null : raw.trim();
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const finding = raw.match(/^\s+L(\d+)\s+\[SC [\d.]+ ([\w-]+)\]/);
|
|
123
|
+
if (!finding || !currentFile) continue;
|
|
124
|
+
if (finding[2] !== RULE) continue;
|
|
125
|
+
counts[currentFile] = (counts[currentFile] ?? 0) + 1;
|
|
126
|
+
}
|
|
127
|
+
return counts;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ---------------------------------------------------------------------------
|
|
131
|
+
// Run
|
|
132
|
+
// ---------------------------------------------------------------------------
|
|
133
|
+
|
|
134
|
+
const files = scanFiles();
|
|
135
|
+
const current = measure(files);
|
|
136
|
+
|
|
137
|
+
if (INIT) {
|
|
138
|
+
const withViolations = Object.fromEntries(
|
|
139
|
+
Object.entries(current).filter(([, n]) => n > 0),
|
|
140
|
+
);
|
|
141
|
+
const baseline = readBaseline(ROOT);
|
|
142
|
+
baseline.version = SCHEMA_VERSION;
|
|
143
|
+
baseline.rules = baseline.rules ?? {};
|
|
144
|
+
baseline.rules[RULE_ID] = {
|
|
145
|
+
recordedAt: new Date().toISOString().slice(0, 10),
|
|
146
|
+
note: `a11y-lint rule "${RULE}". Shrink-only: an entry may be removed once its file is clean, and nothing may be added. See docs/roadmap-closedloop-import.md item 3.`,
|
|
147
|
+
files: withViolations,
|
|
148
|
+
};
|
|
149
|
+
writeBaseline(baseline, ROOT);
|
|
150
|
+
const n = Object.keys(withViolations).length;
|
|
151
|
+
console.log(
|
|
152
|
+
`ratchet [${RULE_ID}]: recorded ${n} file(s) with violations into ${BASELINE_FILE}.`,
|
|
153
|
+
);
|
|
154
|
+
console.log(
|
|
155
|
+
n === 0
|
|
156
|
+
? " Nothing is in violation, so the rule can go straight to strict instead."
|
|
157
|
+
: " Commit this file. From here the list may only shrink.",
|
|
158
|
+
);
|
|
159
|
+
process.exit(0);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const { report, exitCode } = runRatchet({
|
|
163
|
+
ruleId: RULE_ID,
|
|
164
|
+
current,
|
|
165
|
+
root: ROOT,
|
|
166
|
+
baseRef: BASE_REF,
|
|
167
|
+
advisory: ADVISORY,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
console.log(report);
|
|
171
|
+
if (ADVISORY && exitCode === 0) console.log("(advisory — exit 0)");
|
|
172
|
+
process.exit(exitCode);
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* lint-accent-as-text. Text takes the -foreground token; the bare accent
|
|
4
|
+
* token is for fills and borders.
|
|
5
|
+
*
|
|
6
|
+
* Swapping a hardcoded text-orange-700 to text-warning looks like the right
|
|
7
|
+
* semantic move and is a contrast regression. The bare --warning, --info and
|
|
8
|
+
* --success tokens are high-lightness accents that land well below the text
|
|
9
|
+
* floor on a card, while the raw scale they replaced cleared it.
|
|
10
|
+
*
|
|
11
|
+
* --destructive is the documented exception. --destructive-foreground is white,
|
|
12
|
+
* meant for text on a filled destructive surface, so it is invisible on a card.
|
|
13
|
+
* Error text sits on the accent by design.
|
|
14
|
+
*
|
|
15
|
+
* The failing set is DERIVED from this fork's own tokens, not hardcoded, the
|
|
16
|
+
* same way .type-scale.json drives the type floor. A token that fails in light
|
|
17
|
+
* and clears in dark is still flagged, because the light rendering is real.
|
|
18
|
+
*
|
|
19
|
+
* This lint reports what it could not check. A gate that silently examines
|
|
20
|
+
* nothing is worse than one that fails.
|
|
21
|
+
*
|
|
22
|
+
* Known limitation: the lint assumes the flagged text sits on one of
|
|
23
|
+
* SURFACES (card, background, popover). A line that sets its own opaque
|
|
24
|
+
* background puts the text on a different, unmeasured pair, and a ratio
|
|
25
|
+
* reported against SURFACES is not necessarily what actually renders there.
|
|
26
|
+
* The only case handled is the exact inversion, bg-<token>-foreground on the
|
|
27
|
+
* same line (see scanSource), because that pairing is unambiguous. Any other
|
|
28
|
+
* opaque background override is not detected and may still produce a
|
|
29
|
+
* confidently-wrong ratio.
|
|
30
|
+
*
|
|
31
|
+
* Run:
|
|
32
|
+
* node scripts/lint-accent-as-text.mjs report, exit 1 on findings
|
|
33
|
+
* node scripts/lint-accent-as-text.mjs --warn report, exit 0 (advisory)
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
import { execFileSync } from "node:child_process";
|
|
37
|
+
import { readFileSync, readdirSync, existsSync, realpathSync } from "node:fs";
|
|
38
|
+
import { join, relative } from "node:path";
|
|
39
|
+
import { fileURLToPath } from "node:url";
|
|
40
|
+
import { contrastFromHex } from "./contrast.mjs";
|
|
41
|
+
|
|
42
|
+
const ROOT = process.cwd();
|
|
43
|
+
const SCAN_ROOTS = ["app", "components", "packages/core/src/components"];
|
|
44
|
+
const SURFACES = ["card", "background", "popover"];
|
|
45
|
+
const EXEMPT = ["destructive"];
|
|
46
|
+
const TEXT_FLOOR = 4.5; // AA normal. The AAA 7:1 floor would flag nearly every accent.
|
|
47
|
+
const CSS_FILES = [
|
|
48
|
+
"styles/globals.css",
|
|
49
|
+
"styles/client-extras.css",
|
|
50
|
+
"packages/core/src/styles.css",
|
|
51
|
+
].map((rel) => join(ROOT, rel));
|
|
52
|
+
|
|
53
|
+
/** Resolved hex per token per mode, harvested from `bads-wcag-audit --json`. */
|
|
54
|
+
export function collectTokenHexes(auditJson) {
|
|
55
|
+
const hexes = { light: {}, dark: {} };
|
|
56
|
+
for (const row of auditJson.results || []) {
|
|
57
|
+
const mode = row.mode === "dark" ? "dark" : "light";
|
|
58
|
+
if (row.fgKey && row.fgHex) hexes[mode][row.fgKey] ??= row.fgHex;
|
|
59
|
+
if (row.bgKey && row.bgHex) hexes[mode][row.bgKey] ??= row.bgHex;
|
|
60
|
+
}
|
|
61
|
+
return hexes;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Token names having a --<token>-foreground declaration.
|
|
66
|
+
*
|
|
67
|
+
* Needed because warning, info, success and ai all declare a twin in globals.css
|
|
68
|
+
* while no audited PAIRS entry references it, so the twin never reaches the
|
|
69
|
+
* audit's resolved set. Reading CSS directly is the only way to see them.
|
|
70
|
+
*/
|
|
71
|
+
export function readDeclaredTwins(cssFiles) {
|
|
72
|
+
const twins = new Set();
|
|
73
|
+
for (const file of cssFiles) {
|
|
74
|
+
if (!existsSync(file)) continue;
|
|
75
|
+
for (const m of readFileSync(file, "utf8").matchAll(/--([a-z0-9-]+)-foreground\s*:/g)) {
|
|
76
|
+
twins.add(m[1]);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return twins;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Accent tokens that fail the text floor on a surface, per mode. */
|
|
83
|
+
export function findFailingAccents(hexes, { floor, surfaces, exempt, twins }) {
|
|
84
|
+
const failing = [];
|
|
85
|
+
for (const mode of ["light", "dark"]) {
|
|
86
|
+
const tokens = hexes[mode] || {};
|
|
87
|
+
for (const token of Object.keys(tokens)) {
|
|
88
|
+
// A -foreground token is already the readable half of a pair.
|
|
89
|
+
if (token.endsWith("-foreground")) continue;
|
|
90
|
+
// A token is an accent only if it has a -foreground twin to point at.
|
|
91
|
+
if (!tokens[`${token}-foreground`] && !twins.has(token)) continue;
|
|
92
|
+
if (exempt.includes(token)) continue;
|
|
93
|
+
// Never measure a surface against itself.
|
|
94
|
+
if (surfaces.includes(token)) continue;
|
|
95
|
+
for (const surface of surfaces) {
|
|
96
|
+
const surfaceHex = tokens[surface];
|
|
97
|
+
if (!surfaceHex) continue;
|
|
98
|
+
const ratio = contrastFromHex(tokens[token], surfaceHex);
|
|
99
|
+
if (ratio < floor) failing.push({ token, mode, surface, ratio });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return failing;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* .stories.tsx, .test.tsx(x) and .spec.tsx(x) are excluded. A story rendering
|
|
108
|
+
* a token swatch (or a test fixture asserting one) is documentation, not
|
|
109
|
+
* product UI -- a11y-lint.cjs carries the same isStory concept for the same
|
|
110
|
+
* reason. This also resolves a known limitation logged against this lint in
|
|
111
|
+
* the fork and never fixed there.
|
|
112
|
+
*/
|
|
113
|
+
export function walk(dir, out = []) {
|
|
114
|
+
if (!existsSync(dir)) return out;
|
|
115
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
116
|
+
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
117
|
+
const full = join(dir, entry.name);
|
|
118
|
+
if (entry.isDirectory()) {
|
|
119
|
+
walk(full, out);
|
|
120
|
+
} else if (/\.tsx?$/.test(entry.name) && !/\.(stories|test|spec)\.tsx?$/.test(entry.name)) {
|
|
121
|
+
out.push(full);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Whether an escape comment on `line` excuses `token`.
|
|
129
|
+
*
|
|
130
|
+
* Two rules, both of which exist because the obvious version of this is a
|
|
131
|
+
* silent-suppression bug. The comment must NAME the token
|
|
132
|
+
* (`// allow-accent-text warning: <reason>`), so excusing one token on a line
|
|
133
|
+
* does not also silence a different failing token on that same line. And the
|
|
134
|
+
* marker must sit inside a comment, so the literal phrase appearing in a string
|
|
135
|
+
* or a doc reference cannot switch the gate off.
|
|
136
|
+
*/
|
|
137
|
+
function excusedBy(line, token) {
|
|
138
|
+
if (!line) return false;
|
|
139
|
+
const marker = new RegExp(`allow-accent-text\\s+${token}(?![\\w-])`);
|
|
140
|
+
const match = marker.exec(line);
|
|
141
|
+
if (!match) return false;
|
|
142
|
+
const before = line.slice(0, match.index);
|
|
143
|
+
return before.includes("//") || before.includes("/*");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Source sites using a failing accent as a text color. */
|
|
147
|
+
export function scanSource(files, failing) {
|
|
148
|
+
const byToken = new Map();
|
|
149
|
+
for (const f of failing) {
|
|
150
|
+
if (!byToken.has(f.token)) byToken.set(f.token, []);
|
|
151
|
+
byToken.get(f.token).push(f);
|
|
152
|
+
}
|
|
153
|
+
const hits = [];
|
|
154
|
+
for (const file of files) {
|
|
155
|
+
let src;
|
|
156
|
+
try { src = readFileSync(file, "utf8"); } catch { continue; }
|
|
157
|
+
const lines = src.split("\n");
|
|
158
|
+
for (let i = 0; i < lines.length; i++) {
|
|
159
|
+
const line = lines[i];
|
|
160
|
+
for (const [token, modes] of byToken) {
|
|
161
|
+
// text-<token> but not text-<token>-foreground, and not bg-/border-/fill-.
|
|
162
|
+
// The token must not be followed by another class segment. \b is satisfied by
|
|
163
|
+
// a hyphen, so `text-sidebar` used to match inside
|
|
164
|
+
// `text-sidebar-accent-foreground`. Excluding [\w-] also subsumes the old
|
|
165
|
+
// (?!-foreground) guard, since -foreground is just one such segment.
|
|
166
|
+
const re = new RegExp(`\\btext-${token}(?![\\w-])`);
|
|
167
|
+
if (!re.test(line)) continue;
|
|
168
|
+
// The surface is explicitly overridden on this same line, by the exact
|
|
169
|
+
// inversion of the pair under test (bg-<token>-foreground) -- e.g. a
|
|
170
|
+
// "<token> FG" swatch rendering bg-secondary-foreground text-secondary
|
|
171
|
+
// to show what --secondary looks like as text. The lint cannot know
|
|
172
|
+
// what this text actually sits on there, so it must not claim a
|
|
173
|
+
// ratio it did not measure. Deliberately narrow: NOT any bg- on the
|
|
174
|
+
// line. bg-warning/10 text-warning is a low-opacity tint over the
|
|
175
|
+
// real surface, where measuring against --card is still approximately
|
|
176
|
+
// right, so that stays flagged.
|
|
177
|
+
if (new RegExp(`\\bbg-${token}-foreground(?![\\w-])`).test(line)) continue;
|
|
178
|
+
// Per token, not per line. A hatch naming one token leaves the rest live.
|
|
179
|
+
if (excusedBy(line, token) || excusedBy(lines[i - 1], token)) continue;
|
|
180
|
+
const worst = modes.reduce((a, b) => (a.ratio <= b.ratio ? a : b));
|
|
181
|
+
hits.push({
|
|
182
|
+
file,
|
|
183
|
+
line: i + 1,
|
|
184
|
+
token,
|
|
185
|
+
message:
|
|
186
|
+
`text-${token} is the bare accent token. It measures ${worst.ratio}:1 on ` +
|
|
187
|
+
`--${worst.surface} in ${worst.mode} mode, below the ${TEXT_FLOOR}:1 text floor. ` +
|
|
188
|
+
`Use text-${token}-foreground for the label and keep bg-${token}/10 for the fill. ` +
|
|
189
|
+
`Add "// allow-accent-text ${token}: <reason>" above to bypass this one token.`,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return hits;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function main() {
|
|
198
|
+
const advisory = process.argv.includes("--warn");
|
|
199
|
+
let audit;
|
|
200
|
+
try {
|
|
201
|
+
const auditScript = fileURLToPath(new URL("./wcag-audit.cjs", import.meta.url));
|
|
202
|
+
const raw = execFileSync(process.execPath, [auditScript, "--json"], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
|
|
203
|
+
audit = JSON.parse(raw.slice(raw.indexOf("{"), raw.lastIndexOf("}") + 1));
|
|
204
|
+
} catch (err) {
|
|
205
|
+
console.error(`lint-accent-as-text: could not read wcag:audit --json (${err.message}).`);
|
|
206
|
+
if (err.stderr) console.error(String(err.stderr).trim());
|
|
207
|
+
console.log("NOT CHECKED: 0 files examined, because the token audit could not be read.");
|
|
208
|
+
process.exitCode = advisory ? 0 : 1;
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const hexes = collectTokenHexes(audit);
|
|
213
|
+
const twins = readDeclaredTwins(CSS_FILES);
|
|
214
|
+
const failing = findFailingAccents(hexes, {
|
|
215
|
+
floor: TEXT_FLOOR,
|
|
216
|
+
surfaces: SURFACES,
|
|
217
|
+
exempt: EXEMPT,
|
|
218
|
+
twins,
|
|
219
|
+
});
|
|
220
|
+
const files = SCAN_ROOTS.flatMap((r) => walk(join(ROOT, r)));
|
|
221
|
+
const hits = scanSource(files, failing);
|
|
222
|
+
|
|
223
|
+
// Report coverage before findings, so a green run is never mistaken for
|
|
224
|
+
// coverage it does not have.
|
|
225
|
+
console.log(
|
|
226
|
+
`lint-accent-as-text: ${files.length} file(s) scanned, ` +
|
|
227
|
+
`${failing.length} failing accent/surface/mode combination(s) derived from this fork's tokens, ` +
|
|
228
|
+
`${EXEMPT.length} exempt (${EXEMPT.join(", ")}).`,
|
|
229
|
+
);
|
|
230
|
+
if (files.length === 0) {
|
|
231
|
+
console.log(`NOT CHECKED: no files matched ${SCAN_ROOTS.join(", ")}.`);
|
|
232
|
+
process.exitCode = advisory ? 0 : 1;
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if (failing.length === 0) {
|
|
236
|
+
console.log("No accent token fails the text floor in this fork. Nothing to flag.");
|
|
237
|
+
process.exitCode = 0;
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (hits.length === 0) {
|
|
242
|
+
console.log("✓ lint-accent-as-text: no bare accent token used as a text color.");
|
|
243
|
+
process.exitCode = 0;
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const grouped = hits.reduce((acc, h) => {
|
|
247
|
+
(acc[h.file] ||= []).push(h);
|
|
248
|
+
return acc;
|
|
249
|
+
}, {});
|
|
250
|
+
for (const file of Object.keys(grouped).sort()) {
|
|
251
|
+
console.log(`\n${relative(ROOT, file)}`);
|
|
252
|
+
for (const h of grouped[file]) console.log(` L${h.line} ${h.message}`);
|
|
253
|
+
}
|
|
254
|
+
console.log(`\n${hits.length} issue(s) across ${Object.keys(grouped).length} file(s).`);
|
|
255
|
+
process.exitCode = advisory ? 0 : 1;
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Node resolves import.meta.url through any symlink in the module's own
|
|
260
|
+
// path, but process.argv[1] is left exactly as invoked. The shipped bin
|
|
261
|
+
// (bads-lint-accent-text) is a symlink into node_modules/.bin, so a naive
|
|
262
|
+
// `import.meta.url === file://${process.argv[1]}` check never matches
|
|
263
|
+
// there and main() silently never runs. Resolve both sides to the same
|
|
264
|
+
// real, absolute path before comparing.
|
|
265
|
+
function isMainModule() {
|
|
266
|
+
if (!process.argv[1]) return false;
|
|
267
|
+
try {
|
|
268
|
+
return import.meta.url === `file://${realpathSync(process.argv[1])}`;
|
|
269
|
+
} catch {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (isMainModule()) main();
|
package/scripts/bads-doctor.mjs
CHANGED
|
@@ -91,7 +91,8 @@ Runs, in order:
|
|
|
91
91
|
check-stories Storybook coverage rule, full-repo audit (--all)
|
|
92
92
|
size-audit CTA size contract, rule BADS-2 (text-xs CTAs without the escape hatch)
|
|
93
93
|
lint-token-intent [advisory] status-token/copy mismatches + muted-on-heading (BADS-INTENT-1/2)
|
|
94
|
-
lint-slop [advisory] AI-slop visual tics — gradients, springy hovers, oversized shadows
|
|
94
|
+
lint-slop [advisory] AI-slop visual tics — gradients, springy hovers, oversized shadows,
|
|
95
|
+
icon pucks, blobs, three-up grids, centered-everything (BADS-SLOP-1..14)
|
|
95
96
|
lint-ethics [advisory] registry ethicsContract completeness (data-entry primitives, retention, consent)
|
|
96
97
|
|
|
97
98
|
[advisory] checks report findings in the table but never fail the doctor run or its exit code —
|