@behavioral-agentic-design-system/core 0.45.0 → 0.48.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 +17 -3
- package/scripts/a11y-lint.cjs +78 -15
- package/scripts/bads-sync.mjs +1 -1
- package/scripts/build-tokens.cjs +122 -7
- package/scripts/check-dark-contrast.mjs +204 -0
- package/scripts/check-flush-edges.mjs +245 -0
- package/scripts/design-system-advisory/README.md +239 -0
- package/scripts/design-system-advisory/check-copy-punctuation.mjs +44 -0
- package/scripts/design-system-advisory/check-even-padding.mjs +35 -0
- package/scripts/design-system-advisory/check-hand-built-button.mjs +46 -0
- package/scripts/design-system-advisory/check-html-nesting.mjs +51 -0
- package/scripts/design-system-advisory/check-icon-sizing.mjs +79 -0
- package/scripts/design-system-advisory/check-label-case.mjs +92 -0
- package/scripts/design-system-advisory/check-native-form-controls.mjs +53 -0
- package/scripts/design-system-advisory/check-radius.mjs +56 -0
- package/scripts/design-system-advisory/check-raw-values.mjs +61 -0
- package/scripts/design-system-advisory/check-small-text.mjs +72 -0
- package/scripts/design-system-advisory/check-tap-target.mjs +70 -0
- package/scripts/design-system-advisory/defaults.mjs +90 -0
- package/scripts/design-system-advisory/fixtures/clean.tsx.fixture +12 -0
- package/scripts/design-system-advisory/fixtures/violations.tsx.fixture +19 -0
- package/scripts/design-system-advisory/lib.mjs +255 -0
- package/scripts/design-system-advisory/run.mjs +189 -0
- package/scripts/design-system-advisory/workflow.yml +82 -0
- package/scripts/lib/copy-strings.mjs +146 -0
- package/scripts/lib/dark-contrast.mjs +120 -0
- package/scripts/lib/flush-edges.mjs +294 -0
- package/scripts/lib/lab-lint.mjs +62 -0
- package/scripts/lib/mount-page.mjs +25 -0
- package/scripts/lib/source-scan.mjs +173 -0
- package/scripts/lib/tells.mjs +240 -2
- package/scripts/lint-arbitrary-tokens.mjs +47 -0
- package/scripts/lint-component-token-refs.mjs +63 -0
- package/scripts/lint-content-hierarchy.mjs +114 -0
- package/scripts/lint-control-baseline.mjs +72 -0
- package/scripts/lint-copy-punctuation.mjs +60 -0
- package/scripts/lint-even-padding.mjs +58 -0
- package/scripts/lint-label-case.mjs +219 -0
- package/scripts/lint-microanimation.mjs +2 -2
- package/scripts/lint-proximity.mjs +181 -0
- package/scripts/lint-slop.mjs +1 -1
- package/scripts/lint-spacing-scale.mjs +78 -0
- package/scripts/lint-target-size.cjs +132 -0
- package/scripts/lint-token-primitives.mjs +307 -0
- package/scripts/size-audit.cjs +2 -2
- package/scripts/ux-tells.mjs +8 -6
- package/scripts/wcag-audit.cjs +25 -4
- package/src/api/layers/file.ts +2 -0
- package/src/api/site-auth.ts +14 -2
- package/src/app/preview/components/page.tsx +183 -14
- package/src/app/preview/sticker-sheet/page.tsx +329 -0
- package/src/app/preview/sticker-sheet/specimens.tsx +296 -0
- package/src/app/shell.tsx +4 -3
- package/src/components/Foundations/Colors.stories.tsx +119 -8
- package/src/components/home-tab.tsx +6 -1
- package/src/components/onboarding-wizard.tsx +1 -1
- package/src/components/ui/avatar.tsx +4 -0
- package/src/components/ui/chart.tsx +134 -42
- package/src/components/ui/checkbox-group.tsx +1 -1
- package/src/components/ui/checkbox.tsx +1 -1
- package/src/components/ui/combobox.tsx +1 -0
- package/src/components/ui/command.tsx +1 -1
- package/src/components/ui/date-picker.tsx +2 -0
- package/src/components/ui/date-range-picker.tsx +4 -0
- package/src/components/ui/file-upload.tsx +21 -2
- package/src/components/ui/heatmap.tsx +3 -1
- package/src/components/ui/input-group.tsx +5 -2
- package/src/components/ui/multi-select.tsx +1 -0
- package/src/components/ui/number-field.tsx +390 -0
- package/src/components/ui/radio-group.tsx +2 -2
- package/src/components/ui/sparkline.tsx +33 -4
- package/src/components/ui/spinner.tsx +23 -4
- package/src/components/ui/table.tsx +9 -0
- package/src/components/ui/week-picker.tsx +0 -12
- package/src/data/component-added.json +12 -0
- package/src/data/docs-index.ts +22 -1
- package/src/data/history.json +162 -162
- package/src/data/sticker-sheet.json +9297 -0
- package/src/docs-trace-globs.json +1 -0
- package/src/lib/chart-motion.ts +41 -0
- package/src/lib/get-icon-color.ts +1 -1
- package/src/stories/Accordion.stories.tsx +7 -0
- package/src/stories/ActionBar.stories.tsx +5 -0
- package/src/stories/Affix.stories.tsx +4 -0
- package/src/stories/AiBadge.stories.tsx +9 -7
- package/src/stories/Alert.stories.tsx +13 -0
- package/src/stories/AlertDialog.stories.tsx +4 -0
- package/src/stories/Anchor.stories.tsx +5 -0
- package/src/stories/AngleSlider.stories.tsx +6 -3
- package/src/stories/AspectRatio.stories.tsx +4 -0
- package/src/stories/Autocomplete.stories.tsx +6 -0
- package/src/stories/Avatar.stories.tsx +10 -0
- package/src/stories/Badge.stories.tsx +14 -6
- package/src/stories/Blockquote.stories.tsx +6 -0
- package/src/stories/BottomNavigation.stories.tsx +4 -0
- package/src/stories/Breadcrumb.stories.tsx +3 -0
- package/src/stories/Burger.stories.tsx +1 -0
- package/src/stories/Button.stories.tsx +24 -0
- package/src/stories/ButtonGroup.stories.tsx +9 -0
- package/src/stories/Calendar.stories.tsx +3 -0
- package/src/stories/Card.stories.tsx +4 -0
- package/src/stories/Carousel.stories.tsx +6 -0
- package/src/stories/Cascader.stories.tsx +4 -0
- package/src/stories/Chart.stories.tsx +46 -1
- package/src/stories/ChatBubble.stories.tsx +8 -2
- package/src/stories/ChatMarker.stories.tsx +1 -0
- package/src/stories/Checkbox.stories.tsx +40 -0
- package/src/stories/CheckboxCard.stories.tsx +8 -0
- package/src/stories/CheckboxGroup.stories.tsx +20 -0
- package/src/stories/Chip.stories.tsx +10 -19
- package/src/stories/CircularProgress.stories.tsx +13 -27
- package/src/stories/Clipboard.stories.tsx +6 -0
- package/src/stories/CloseButton.stories.tsx +6 -4
- package/src/stories/Code.stories.tsx +8 -1
- package/src/stories/Collapsible.stories.tsx +2 -0
- package/src/stories/ColorPicker.stories.tsx +6 -0
- package/src/stories/ColorSwatch.stories.tsx +1 -0
- package/src/stories/Combobox.stories.tsx +9 -0
- package/src/stories/Command.stories.tsx +2 -0
- package/src/stories/Container.stories.tsx +8 -0
- package/src/stories/ContextMenu.stories.tsx +9 -0
- package/src/stories/CopyButton.stories.tsx +12 -36
- package/src/stories/DataList.stories.tsx +8 -0
- package/src/stories/DataTable.stories.tsx +9 -0
- package/src/stories/DateField.stories.tsx +7 -0
- package/src/stories/DatePicker.stories.tsx +34 -0
- package/src/stories/DateRangePicker.stories.tsx +32 -0
- package/src/stories/Dialog.stories.tsx +8 -0
- package/src/stories/Drawer.stories.tsx +6 -0
- package/src/stories/DropdownMenu.stories.tsx +2 -0
- package/src/stories/Editable.stories.tsx +10 -0
- package/src/stories/EmptyState.stories.tsx +9 -0
- package/src/stories/Field.stories.tsx +7 -0
- package/src/stories/Fieldset.stories.tsx +8 -0
- package/src/stories/FileButton.stories.tsx +4 -0
- package/src/stories/FileUpload.stories.tsx +16 -17
- package/src/stories/FloatLabel.stories.tsx +3 -8
- package/src/stories/FloatingActionButton.stories.tsx +10 -0
- package/src/stories/FloatingIndicator.stories.tsx +4 -0
- package/src/stories/FloatingPanel.stories.tsx +6 -0
- package/src/stories/FocusTrap.stories.tsx +5 -0
- package/src/stories/FormatByte.stories.tsx +6 -0
- package/src/stories/FormatDate.stories.tsx +8 -0
- package/src/stories/FormatNumber.stories.tsx +9 -0
- package/src/stories/Heatmap.stories.tsx +11 -0
- package/src/stories/Highlight.stories.tsx +6 -0
- package/src/stories/HoverCard.stories.tsx +4 -0
- package/src/stories/Image.stories.tsx +9 -0
- package/src/stories/Indicator.stories.tsx +19 -0
- package/src/stories/Input.stories.tsx +7 -0
- package/src/stories/InputClearButton.stories.tsx +3 -0
- package/src/stories/InputGroup.stories.tsx +40 -0
- package/src/stories/Kbd.stories.tsx +7 -1
- package/src/stories/KeyboardShortcut.stories.tsx +2 -0
- package/src/stories/Label.stories.tsx +2 -0
- package/src/stories/Link.stories.tsx +9 -0
- package/src/stories/List.stories.tsx +8 -0
- package/src/stories/Listbox.stories.tsx +1 -0
- package/src/stories/LoadingDots.stories.tsx +5 -3
- package/src/stories/LoadingOverlay.stories.tsx +5 -1
- package/src/stories/Mark.stories.tsx +5 -0
- package/src/stories/Marquee.stories.tsx +4 -0
- package/src/stories/Masonry.stories.tsx +5 -0
- package/src/stories/Menubar.stories.tsx +3 -0
- package/src/stories/Meter.stories.tsx +11 -17
- package/src/stories/MonthPicker.stories.tsx +5 -1
- package/src/stories/MotionToggle.stories.tsx +1 -0
- package/src/stories/MultiSelect.stories.tsx +9 -0
- package/src/stories/NativeSelect.stories.tsx +1 -0
- package/src/stories/NavLink.stories.tsx +7 -0
- package/src/stories/NavigationMenu.stories.tsx +5 -0
- package/src/stories/NavigationRail.stories.tsx +10 -0
- package/src/stories/Notification.stories.tsx +13 -34
- package/src/stories/NumberField.stories.tsx +214 -0
- package/src/stories/NumberInput.stories.tsx +8 -1
- package/src/stories/Overlay.stories.tsx +5 -1
- package/src/stories/Pagination.stories.tsx +8 -0
- package/src/stories/PasswordInput.stories.tsx +2 -0
- package/src/stories/PinInput.stories.tsx +9 -2
- package/src/stories/Popover.stories.tsx +2 -0
- package/src/stories/Progress.stories.tsx +6 -1
- package/src/stories/Prose.stories.tsx +8 -0
- package/src/stories/QrCode.stories.tsx +2 -0
- package/src/stories/Questionnaire.stories.tsx +7 -0
- package/src/stories/RadioGroup.stories.tsx +40 -0
- package/src/stories/RatingGroup.stories.tsx +8 -4
- package/src/stories/Resizable.stories.tsx +4 -2
- package/src/stories/Result.stories.tsx +3 -0
- package/src/stories/Reveal.stories.tsx +2 -0
- package/src/stories/RollingNumber.stories.tsx +5 -0
- package/src/stories/ScrollArea.stories.tsx +3 -1
- package/src/stories/SearchInput.stories.tsx +8 -6
- package/src/stories/SegmentedControl.stories.tsx +11 -0
- package/src/stories/Select.stories.tsx +7 -0
- package/src/stories/Separator.stories.tsx +6 -0
- package/src/stories/Sheet.stories.tsx +5 -0
- package/src/stories/Sidebar.stories.tsx +40 -1
- package/src/stories/SimpleGrid.stories.tsx +5 -0
- package/src/stories/Skeleton.stories.tsx +8 -0
- package/src/stories/SkeletonTable.stories.tsx +6 -5
- package/src/stories/SkipLink.stories.tsx +3 -0
- package/src/stories/Slider.stories.tsx +2 -1
- package/src/stories/Sonner.stories.tsx +7 -0
- package/src/stories/Sparkline.stories.tsx +14 -1
- package/src/stories/Spinner.stories.tsx +20 -10
- package/src/stories/Spoiler.stories.tsx +5 -0
- package/src/stories/Squircle.stories.tsx +7 -0
- package/src/stories/Stack.stories.tsx +7 -0
- package/src/stories/StatusBadge.stories.tsx +12 -6
- package/src/stories/Stepper.stories.tsx +5 -0
- package/src/stories/Switch.stories.tsx +4 -0
- package/src/stories/Table.stories.tsx +10 -1
- package/src/stories/Tabs.stories.tsx +8 -0
- package/src/stories/Tag.stories.tsx +13 -5
- package/src/stories/TagsInput.stories.tsx +13 -0
- package/src/stories/Text.stories.tsx +12 -0
- package/src/stories/Textarea.stories.tsx +9 -0
- package/src/stories/ThemeIcon.stories.tsx +6 -3
- package/src/stories/TimePicker.stories.tsx +2 -0
- package/src/stories/Timeline.stories.tsx +12 -0
- package/src/stories/Timer.stories.tsx +4 -0
- package/src/stories/Toggle.stories.tsx +7 -5
- package/src/stories/ToggleGroup.stories.tsx +5 -0
- package/src/stories/ToggleTip.stories.tsx +4 -0
- package/src/stories/Toolbar.stories.tsx +6 -0
- package/src/stories/Tooltip.stories.tsx +3 -0
- package/src/stories/Tour.stories.tsx +3 -0
- package/src/stories/TransferList.stories.tsx +3 -0
- package/src/stories/TreeSelect.stories.tsx +4 -0
- package/src/stories/TreeView.stories.tsx +5 -0
- package/src/stories/TypingIndicator.stories.tsx +4 -0
- package/src/stories/VisuallyHidden.stories.tsx +3 -0
- package/src/stories/Watermark.stories.tsx +6 -0
- package/src/stories/WeekPicker.stories.tsx +4 -1
- package/src/stories/WordRotate.stories.tsx +5 -0
- package/src/stories/YearPicker.stories.tsx +5 -11
- package/src/stories/story-groups.json +2 -1
- package/src/styles.css +50 -2
- package/src/tokens.json +4 -4
- package/LICENSE +0 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@behavioral-agentic-design-system/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.48.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)",
|
|
@@ -41,12 +41,15 @@
|
|
|
41
41
|
"bads-a11y-ratchet": "scripts/a11y-ratchet.mjs",
|
|
42
42
|
"bads-build-fonts": "scripts/build-fonts.cjs",
|
|
43
43
|
"bads-build-tokens": "scripts/build-tokens.cjs",
|
|
44
|
+
"bads-check-dark-contrast": "scripts/check-dark-contrast.mjs",
|
|
45
|
+
"bads-check-flush-edges": "scripts/check-flush-edges.mjs",
|
|
44
46
|
"bads-check-spec": "scripts/check-spec.mjs",
|
|
45
47
|
"bads-check-stories": "scripts/check-stories.mjs",
|
|
46
48
|
"bads-check-sync": "scripts/check-sync.mjs",
|
|
47
49
|
"bads-components": "scripts/bads-components.mjs",
|
|
48
50
|
"bads-deal-directions": "scripts/deal-directions.mjs",
|
|
49
51
|
"bads-doctor": "scripts/bads-doctor.mjs",
|
|
52
|
+
"bads-ds-advisory": "scripts/design-system-advisory/run.mjs",
|
|
50
53
|
"bads-fix-stories": "scripts/fix-stories.mjs",
|
|
51
54
|
"bads-generate-stories": "scripts/generate-stories.cjs",
|
|
52
55
|
"bads-health-report": "scripts/health-report.mjs",
|
|
@@ -56,9 +59,19 @@
|
|
|
56
59
|
"bads-lint-ethics": "scripts/lint-ethics-contract.mjs",
|
|
57
60
|
"bads-lint-html-nesting": "scripts/lint-html-nesting.mjs",
|
|
58
61
|
"bads-lint-live-ctas": "scripts/lint-live-ctas.mjs",
|
|
62
|
+
"bads-lint-arbitrary-tokens": "scripts/lint-arbitrary-tokens.mjs",
|
|
63
|
+
"bads-lint-content-hierarchy": "scripts/lint-content-hierarchy.mjs",
|
|
64
|
+
"bads-lint-control-baseline": "scripts/lint-control-baseline.mjs",
|
|
65
|
+
"bads-lint-copy-punctuation": "scripts/lint-copy-punctuation.mjs",
|
|
66
|
+
"bads-lint-even-padding": "scripts/lint-even-padding.mjs",
|
|
67
|
+
"bads-lint-label-case": "scripts/lint-label-case.mjs",
|
|
68
|
+
"bads-lint-proximity": "scripts/lint-proximity.mjs",
|
|
69
|
+
"bads-lint-spacing-scale": "scripts/lint-spacing-scale.mjs",
|
|
59
70
|
"bads-lint-microanimation": "./scripts/lint-microanimation.mjs",
|
|
60
71
|
"bads-lint-slop": "scripts/lint-slop.mjs",
|
|
72
|
+
"bads-lint-target-size": "scripts/lint-target-size.cjs",
|
|
61
73
|
"bads-lint-token-intent": "scripts/lint-token-intent.mjs",
|
|
74
|
+
"bads-lint-token-primitives": "scripts/lint-token-primitives.mjs",
|
|
62
75
|
"bads-oklch-to-hex": "scripts/oklch-to-hex.cjs",
|
|
63
76
|
"bads-on-system": "scripts/on-system-score.mjs",
|
|
64
77
|
"bads-size-audit": "scripts/size-audit.cjs",
|
|
@@ -112,6 +125,7 @@
|
|
|
112
125
|
"./app/preview/global-font-client": "./src/app/preview/global-font-client.tsx",
|
|
113
126
|
"./app/preview/cards/page": "./src/app/preview/cards/page.tsx",
|
|
114
127
|
"./app/preview/components/page": "./src/app/preview/components/page.tsx",
|
|
128
|
+
"./app/preview/sticker-sheet/page": "./src/app/preview/sticker-sheet/page.tsx",
|
|
115
129
|
"./app/preview/dashboard/page": "./src/app/preview/dashboard/page.tsx",
|
|
116
130
|
"./app/preview/mail/page": "./src/app/preview/mail/page.tsx",
|
|
117
131
|
"./app/preview/pricing/page": "./src/app/preview/pricing/page.tsx",
|
|
@@ -134,7 +148,7 @@
|
|
|
134
148
|
"access": "public"
|
|
135
149
|
},
|
|
136
150
|
"dependencies": {
|
|
137
|
-
"@radix-ui/react-alert-dialog": "^1.1
|
|
151
|
+
"@radix-ui/react-alert-dialog": "^1.2.1",
|
|
138
152
|
"@xmldom/xmldom": "^0.9.12",
|
|
139
153
|
"@xyflow/react": "12.12.0",
|
|
140
154
|
"cheerio": "^1.0.0",
|
|
@@ -300,4 +314,4 @@
|
|
|
300
314
|
"devDependencies": {
|
|
301
315
|
"@types/react-dom": "^19.3.0"
|
|
302
316
|
}
|
|
303
|
-
}
|
|
317
|
+
}
|
package/scripts/a11y-lint.cjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Scans .tsx and .stories.tsx files under app/, components/, and packages/core/,
|
|
6
6
|
* and flags common AAA-blocking patterns. Complements:
|
|
7
7
|
* - scripts/wcag-audit.js (token contrast)
|
|
8
|
-
* -
|
|
8
|
+
* - lint-target-size.cjs (touch-target sizes, `bads-lint-target-size`)
|
|
9
9
|
* - scripts/lint-tokens.js (token usage)
|
|
10
10
|
*
|
|
11
11
|
* Checks (each tied to a WCAG SC):
|
|
@@ -62,7 +62,7 @@ const advisory = process.argv.includes('--warn');
|
|
|
62
62
|
// "client") downgrades the AAA and house-opinion rules below to warnings —
|
|
63
63
|
// still reported, never silently dropped — while every Level A rule keeps
|
|
64
64
|
// blocking. See docs/superpowers/specs/2026-09-10-client-owned-components-design.md
|
|
65
|
-
// → "Accessibility floor: flag, do not enforce" and
|
|
65
|
+
// → "Accessibility floor: flag, do not enforce" and AGENTS.md → Accessibility
|
|
66
66
|
// Floor. readSourceOfTruth() never throws and defaults to "bads" when there's
|
|
67
67
|
// no identity file, so upstream BADS and every fork that hasn't opted in see
|
|
68
68
|
// zero behaviour change.
|
|
@@ -90,6 +90,64 @@ function flag(file, line, sc, rule, message) {
|
|
|
90
90
|
issues.push({ file: path.relative(ROOT, file), line, sc, rule, message });
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
// ---- comment stripping --------------------------------------------------
|
|
94
|
+
//
|
|
95
|
+
// Every rule below is a line-wise regex. Before 2026-11-09 they ran over the raw
|
|
96
|
+
// file, comments included, so a comment that NAMED a problem failed the build:
|
|
97
|
+
// a note recording a measured contrast value tripped hex-literal, and a doc
|
|
98
|
+
// comment that said "img" tripped image-no-alt. Writers then reworded true notes
|
|
99
|
+
// to get past the gate. So the rules now run on a copy of the file where each
|
|
100
|
+
// comment is replaced by spaces. Newlines stay, so line numbers do not move.
|
|
101
|
+
//
|
|
102
|
+
// The allow-* escape hatches ARE comments. They are still read from the raw
|
|
103
|
+
// line, never from the stripped one.
|
|
104
|
+
//
|
|
105
|
+
// Strings are kept as they are: a hex inside a string is a real style value.
|
|
106
|
+
// A `//` directly after `:` is a URL ("https://…" in JSX text), not a comment.
|
|
107
|
+
// Single and double quotes do not cross a newline (JS strings cannot), so an
|
|
108
|
+
// apostrophe in JSX text ("Don't") can confuse at most one line, and the
|
|
109
|
+
// mistake is always in the safe direction: a comment left in, never code
|
|
110
|
+
// removed.
|
|
111
|
+
function stripComments(src) {
|
|
112
|
+
let out = '';
|
|
113
|
+
let i = 0;
|
|
114
|
+
const n = src.length;
|
|
115
|
+
const blank = (s) => s.replace(/[^\n]/g, ' ');
|
|
116
|
+
while (i < n) {
|
|
117
|
+
const c = src[i];
|
|
118
|
+
const next = src[i + 1];
|
|
119
|
+
if (c === '"' || c === "'" || c === '`') {
|
|
120
|
+
let j = i + 1;
|
|
121
|
+
while (j < n) {
|
|
122
|
+
if (src[j] === '\\') { j += 2; continue; }
|
|
123
|
+
if (src[j] === c) { j++; break; }
|
|
124
|
+
if (src[j] === '\n' && c !== '`') break;
|
|
125
|
+
j++;
|
|
126
|
+
}
|
|
127
|
+
out += src.slice(i, j);
|
|
128
|
+
i = j;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (c === '/' && next === '*') {
|
|
132
|
+
const end = src.indexOf('*/', i + 2);
|
|
133
|
+
const j = end === -1 ? n : end + 2;
|
|
134
|
+
out += blank(src.slice(i, j));
|
|
135
|
+
i = j;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (c === '/' && next === '/' && src[i - 1] !== ':') {
|
|
139
|
+
let j = src.indexOf('\n', i);
|
|
140
|
+
if (j === -1) j = n;
|
|
141
|
+
out += blank(src.slice(i, j));
|
|
142
|
+
i = j;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
out += c;
|
|
146
|
+
i++;
|
|
147
|
+
}
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
|
|
93
151
|
// ---- per-line scans -----------------------------------------------------
|
|
94
152
|
|
|
95
153
|
const HARDCODED_HEX = /(?:bg-|text-|border-|fill-|stroke-|from-|to-|via-|shadow-|ring-)\[#[0-9A-Fa-f]{3,8}\]|(?<!\$value":\s")#[0-9A-Fa-f]{6}(?![A-Fa-f0-9"])/;
|
|
@@ -207,9 +265,14 @@ for (const file of files) {
|
|
|
207
265
|
|
|
208
266
|
const TS = scaleFor(file);
|
|
209
267
|
|
|
268
|
+
// `lines` is the raw file, read only for allow-* hatches. `line` is the same
|
|
269
|
+
// line with its comments blanked, and every rule tests that.
|
|
270
|
+
const code = stripComments(src);
|
|
210
271
|
const lines = src.split('\n');
|
|
272
|
+
const codeLines = code.split('\n');
|
|
211
273
|
for (let i = 0; i < lines.length; i++) {
|
|
212
|
-
const
|
|
274
|
+
const raw = lines[i];
|
|
275
|
+
const line = codeLines[i];
|
|
213
276
|
const lineNum = i + 1;
|
|
214
277
|
|
|
215
278
|
// Escape hatch, same convention as allow-small-text below: same line or
|
|
@@ -219,9 +282,9 @@ for (const file of files) {
|
|
|
219
282
|
// literal TEXT CONTENT describing a color (e.g. the Customize tab's own
|
|
220
283
|
// "#171717 · selected" picker label) is data, not an uncontrolled style
|
|
221
284
|
// decision — the thing SC 1.4.6 actually cares about.
|
|
222
|
-
const allowHex = /\/\/\s*allow-hex-literal/.test(
|
|
285
|
+
const allowHex = /\/\/\s*allow-hex-literal/.test(raw)
|
|
223
286
|
|| (i > 0 && /allow-hex-literal/.test(lines[i - 1]));
|
|
224
|
-
const allowInlinePx = /\/\/\s*allow-inline-px-font/.test(
|
|
287
|
+
const allowInlinePx = /\/\/\s*allow-inline-px-font/.test(raw)
|
|
225
288
|
|| (i > 0 && /allow-inline-px-font/.test(lines[i - 1]));
|
|
226
289
|
|
|
227
290
|
if (HARDCODED_HEX.test(line) && !skipTokenRules && !allowHex) {
|
|
@@ -238,7 +301,7 @@ for (const file of files) {
|
|
|
238
301
|
// text-[11px] is in exactly the position the named-step comment describes, and before
|
|
239
302
|
// this the two paths disagreed: `text-xs` could be excused and `text-[11px]` could not,
|
|
240
303
|
// so a fork mirroring a client's real UI had no way to record the deviation.
|
|
241
|
-
const allowSmallText = /\/\/\s*allow-small-text/.test(
|
|
304
|
+
const allowSmallText = /\/\/\s*allow-small-text/.test(raw)
|
|
242
305
|
|| (i > 0 && /allow-small-text/.test(lines[i - 1]));
|
|
243
306
|
let match;
|
|
244
307
|
ARBITRARY_TEXT_PX.lastIndex = 0;
|
|
@@ -254,7 +317,7 @@ for (const file of files) {
|
|
|
254
317
|
// weight-floor one: some vendored components legitimately ship a smaller step, and that
|
|
255
318
|
// belongs in an upstream finding rather than a local edit.
|
|
256
319
|
if (TS.namedBelowFloor && TS.namedBelowFloor.test(line)
|
|
257
|
-
&& !/\/\/\s*allow-small-text/.test(
|
|
320
|
+
&& !/\/\/\s*allow-small-text/.test(raw)
|
|
258
321
|
&& !(i > 0 && /allow-small-text/.test(lines[i - 1]))) {
|
|
259
322
|
const step = TS.namedBelowFloor.exec(line)[1];
|
|
260
323
|
flag(file, lineNum, '1.4.4', 'tiny-text',
|
|
@@ -263,7 +326,7 @@ for (const file of files) {
|
|
|
263
326
|
|
|
264
327
|
// BADS-WEIGHT — small text (text-xs/text-sm, <18px) must be font-medium (500) or heavier.
|
|
265
328
|
if (TS.smallTextLightWeight && TS.smallTextLightWeight.test(line)
|
|
266
|
-
&& !/\/\/\s*allow-font-normal-small/.test(
|
|
329
|
+
&& !/\/\/\s*allow-font-normal-small/.test(raw)
|
|
267
330
|
&& !(i > 0 && /allow-font-normal-small/.test(lines[i - 1]))) {
|
|
268
331
|
flag(file, lineNum, 'BADS-WEIGHT', 'small-text-light-weight',
|
|
269
332
|
`font-normal (or lighter) on a step below ${WEIGHT_FLOOR_PX}px (${TS.smallStepsDesc}). Weight floor: font-medium (500) minimum. Add "// allow-font-normal-small" above to intentionally bypass.`);
|
|
@@ -281,9 +344,9 @@ for (const file of files) {
|
|
|
281
344
|
const ARIA_LIVE_ATTR = /\baria-live\s*=|\brole\s*=\s*["'](?:status|alert|log)["']/;
|
|
282
345
|
const JSX_CONDITIONAL = /\{[^}]*&&|\?[^:]*<[A-Z]/;
|
|
283
346
|
if (ARIA_LIVE_ATTR.test(line)) {
|
|
284
|
-
const prevLine = i > 0 ?
|
|
347
|
+
const prevLine = i > 0 ? codeLines[i - 1] : '';
|
|
285
348
|
const inConditional = JSX_CONDITIONAL.test(line) || JSX_CONDITIONAL.test(prevLine);
|
|
286
|
-
const allowed = /\/\/\s*allow-conditional-aria-live/.test(
|
|
349
|
+
const allowed = /\/\/\s*allow-conditional-aria-live/.test(raw)
|
|
287
350
|
|| (i > 0 && /allow-conditional-aria-live/.test(lines[i - 1]));
|
|
288
351
|
if (inConditional && !allowed) {
|
|
289
352
|
flag(file, lineNum, 'BADS-LIVE', 'conditional-aria-live',
|
|
@@ -353,12 +416,12 @@ for (const file of files) {
|
|
|
353
416
|
// Escape hatch: `// allow-handrolled-chart` anywhere in the file, with a
|
|
354
417
|
// reason (e.g. a bespoke draw-in hero recharts can't express).
|
|
355
418
|
if (!file.endsWith('.stories.tsx')
|
|
356
|
-
&& /<svg[\s>]/.test(
|
|
357
|
-
&& (
|
|
358
|
-
&& /<(?:path|polyline|line)[\s>]/.test(
|
|
359
|
-
&& !/components\/ui\/chart|ChartContainer|from\s+['"]recharts['"]/.test(
|
|
419
|
+
&& /<svg[\s>]/.test(code)
|
|
420
|
+
&& (code.match(/<text[\s>]/g) || []).length >= 2
|
|
421
|
+
&& /<(?:path|polyline|line)[\s>]/.test(code)
|
|
422
|
+
&& !/components\/ui\/chart|ChartContainer|from\s+['"]recharts['"]/.test(code)
|
|
360
423
|
&& !/allow-handrolled-chart/.test(src)) {
|
|
361
|
-
const svgLine =
|
|
424
|
+
const svgLine = codeLines.findIndex((l) => /<svg[\s>]/.test(l)) + 1;
|
|
362
425
|
flag(file, svgLine || 1, 'BADS-CHART', 'handrolled-chart',
|
|
363
426
|
'Hand-rolled chart SVG (data series + 2+ hand-placed <text> labels). Use the BADS Chart primitive — ChartContainer from "@<slug>/core/components/ui/chart". Recharts handles axis tick spacing and label collision/thinning that hand-placed <text> labels get wrong. Escape hatch: add "// allow-handrolled-chart" in the file with a reason.');
|
|
364
427
|
}
|
package/scripts/bads-sync.mjs
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* - brand.config.ts, brand-colors.json, packages/core/src/tokens.json
|
|
20
20
|
* - styles/client-extras.css (your local CSS additions)
|
|
21
21
|
* - layer-1-foundation/, layer-2-ethics-responsibility/, layer-6-patterns-and-rules/
|
|
22
|
-
* - public/logos/, CLAUDE.md
|
|
22
|
+
* - public/logos/, CLAUDE.md (AGENTS.md and docs/agent-rules/ are not pulled either: they ship by git merge or the plugin)
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
import { execSync } from 'node:child_process';
|
package/scripts/build-tokens.cjs
CHANGED
|
@@ -120,6 +120,41 @@ const darkVars = emitVars(tokens.theme.dark);
|
|
|
120
120
|
const fontSans = tokens.fontFamily.sans.$value;
|
|
121
121
|
const fontMono = tokens.fontFamily.mono.$value;
|
|
122
122
|
const fontSerif = tokens.fontFamily.serif.$value;
|
|
123
|
+
|
|
124
|
+
// One font stack from several pieces, each family once, in the order it first
|
|
125
|
+
// appears. The token value is joined to a fixed fallback tail below, so a fork
|
|
126
|
+
// whose token already ends in "ui-sans-serif, system-ui, sans-serif" got every
|
|
127
|
+
// family twice: ten entries, four repeats (FF-BADS UPSTREAM-FINDINGS 80). The
|
|
128
|
+
// browser stops at the first family it can use, so this changes nothing on
|
|
129
|
+
// screen; it makes the stack readable, which is how a fallback gets reviewed.
|
|
130
|
+
// Names compare without quotes and without case. A var(--x, 'Name') entry is
|
|
131
|
+
// never merged with a plain 'Name': the var resolves to a different face
|
|
132
|
+
// (next/font's self-hosted copy), so the two are not the same family.
|
|
133
|
+
function fontStack(...parts) {
|
|
134
|
+
const out = [];
|
|
135
|
+
const seen = new Set();
|
|
136
|
+
for (const part of parts) {
|
|
137
|
+
let depth = 0;
|
|
138
|
+
let cur = '';
|
|
139
|
+
const entries = [];
|
|
140
|
+
for (const ch of String(part)) {
|
|
141
|
+
if (ch === '(') depth++;
|
|
142
|
+
if (ch === ')') depth--;
|
|
143
|
+
if (ch === ',' && depth === 0) { entries.push(cur); cur = ''; continue; }
|
|
144
|
+
cur += ch;
|
|
145
|
+
}
|
|
146
|
+
entries.push(cur);
|
|
147
|
+
for (const raw of entries) {
|
|
148
|
+
const entry = raw.trim();
|
|
149
|
+
if (!entry) continue;
|
|
150
|
+
const key = entry.replace(/\s+/g, ' ').replace(/^['"]|['"]$/g, '').toLowerCase();
|
|
151
|
+
if (seen.has(key)) continue;
|
|
152
|
+
seen.add(key);
|
|
153
|
+
out.push(entry);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return out.join(', ');
|
|
157
|
+
}
|
|
123
158
|
// Variable-font axis settings, applied to html so the whole tree inherits
|
|
124
159
|
// them. Only meaningful when the active sans is a variable font (Inter
|
|
125
160
|
// Variable ships as the default). Forks tune type here without code change.
|
|
@@ -684,6 +719,22 @@ const baseLayer = `@layer base {
|
|
|
684
719
|
[aria-disabled="true"] {
|
|
685
720
|
cursor: not-allowed;
|
|
686
721
|
}
|
|
722
|
+
/* text-wrap: balance distributes line length evenly across all lines of
|
|
723
|
+
a heading, preventing the awkward single-word last line (widow) that
|
|
724
|
+
most headings produce at responsive widths. Supported Chrome 114+,
|
|
725
|
+
Firefox 121+, Safari 17.5+ (Baseline 2024). Falls back to normal wrap
|
|
726
|
+
with no visual regression in older engines. */
|
|
727
|
+
h1, h2, h3, h4, h5, h6 {
|
|
728
|
+
text-wrap: balance;
|
|
729
|
+
}
|
|
730
|
+
/* text-wrap: pretty prevents orphaned last words on paragraphs by
|
|
731
|
+
considering the last four lines when breaking. Supported Chrome 117+,
|
|
732
|
+
Firefox 130+ (Baseline 2025). Falls back to normal wrap — no adverse
|
|
733
|
+
effect. Performance overhead is negligible on typical paragraph lengths
|
|
734
|
+
(the engine short-circuits for < 4 lines). */
|
|
735
|
+
p {
|
|
736
|
+
text-wrap: pretty;
|
|
737
|
+
}
|
|
687
738
|
}
|
|
688
739
|
|
|
689
740
|
/* Global tracking offset — the Letter Spacing slider in the Customize
|
|
@@ -722,7 +773,7 @@ html, body {
|
|
|
722
773
|
hard edge at full opacity.
|
|
723
774
|
|
|
724
775
|
Forks with sticky chrome (a sidebar / top bar that stays put while the page
|
|
725
|
-
scrolls): see
|
|
776
|
+
scrolls): see docs/agent-rules/theme-transition-and-sticky-chrome.md -> "Theme transition and sticky chrome" before
|
|
726
777
|
naming any chrome. NEVER give a backdrop-filter element a view-transition-
|
|
727
778
|
name (its snapshot has no backdrop to sample and rasterizes as an opaque
|
|
728
779
|
white flash). */
|
|
@@ -1301,15 +1352,47 @@ const pkgCss = `${banner}
|
|
|
1301
1352
|
|
|
1302
1353
|
@custom-variant dark (&:is(.dark *));
|
|
1303
1354
|
|
|
1355
|
+
/* Sticker-sheet state pinning. Each variant keeps Tailwind's real behavior
|
|
1356
|
+
(hover stays behind the (hover: hover) media guard) and ALSO matches a
|
|
1357
|
+
data-pin attribute, so the sticker sheet can freeze hover, focus and
|
|
1358
|
+
pressed on a specimen without touching the component. Live interaction is
|
|
1359
|
+
unchanged because the real selectors are still there. */
|
|
1360
|
+
@custom-variant hover {
|
|
1361
|
+
&:is([data-pin~="hover"]) {
|
|
1362
|
+
@slot;
|
|
1363
|
+
}
|
|
1364
|
+
@media (hover: hover) {
|
|
1365
|
+
&:hover {
|
|
1366
|
+
@slot;
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
@custom-variant focus-visible {
|
|
1371
|
+
&:is([data-pin~="focus"]) {
|
|
1372
|
+
@slot;
|
|
1373
|
+
}
|
|
1374
|
+
&:focus-visible {
|
|
1375
|
+
@slot;
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
@custom-variant active {
|
|
1379
|
+
&:is([data-pin~="pressed"]) {
|
|
1380
|
+
@slot;
|
|
1381
|
+
}
|
|
1382
|
+
&:active {
|
|
1383
|
+
@slot;
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1304
1387
|
:root {
|
|
1305
1388
|
color-scheme: light dark;
|
|
1306
1389
|
|
|
1307
1390
|
/* Brand sans from tokens.json leads. Atkinson Hyperlegible (loaded via the
|
|
1308
1391
|
Google Fonts @import above) is the canonical fallback so unbranded
|
|
1309
1392
|
consumers still get a high-legibility face out of the box. */
|
|
1310
|
-
--font-sans: ${fontSans
|
|
1311
|
-
--font-mono: ${fontMono};
|
|
1312
|
-
--font-serif: ${fontSerif};
|
|
1393
|
+
--font-sans: ${fontStack(fontSans, "'Atkinson Hyperlegible', ui-sans-serif, sans-serif, system-ui")};
|
|
1394
|
+
--font-mono: ${fontStack(fontMono)};
|
|
1395
|
+
--font-serif: ${fontStack(fontSerif)};
|
|
1313
1396
|
--font-variation-settings: ${fontVariationSettings};
|
|
1314
1397
|
--font-size-scale: 1;
|
|
1315
1398
|
|
|
@@ -1411,6 +1494,38 @@ const appCss = `${banner}
|
|
|
1411
1494
|
|
|
1412
1495
|
@custom-variant dark (&:is(.dark *));
|
|
1413
1496
|
|
|
1497
|
+
/* Sticker-sheet state pinning. Each variant keeps Tailwind's real behavior
|
|
1498
|
+
(hover stays behind the (hover: hover) media guard) and ALSO matches a
|
|
1499
|
+
data-pin attribute, so the sticker sheet can freeze hover, focus and
|
|
1500
|
+
pressed on a specimen without touching the component. Live interaction is
|
|
1501
|
+
unchanged because the real selectors are still there. */
|
|
1502
|
+
@custom-variant hover {
|
|
1503
|
+
&:is([data-pin~="hover"]) {
|
|
1504
|
+
@slot;
|
|
1505
|
+
}
|
|
1506
|
+
@media (hover: hover) {
|
|
1507
|
+
&:hover {
|
|
1508
|
+
@slot;
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
@custom-variant focus-visible {
|
|
1513
|
+
&:is([data-pin~="focus"]) {
|
|
1514
|
+
@slot;
|
|
1515
|
+
}
|
|
1516
|
+
&:focus-visible {
|
|
1517
|
+
@slot;
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
@custom-variant active {
|
|
1521
|
+
&:is([data-pin~="pressed"]) {
|
|
1522
|
+
@slot;
|
|
1523
|
+
}
|
|
1524
|
+
&:active {
|
|
1525
|
+
@slot;
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1414
1529
|
:root {
|
|
1415
1530
|
/* Brand fonts from tokens.json lead so the picker selection actually
|
|
1416
1531
|
* shows up. next/font's preloaded vars come second as a self-hosted
|
|
@@ -1421,9 +1536,9 @@ const appCss = `${banner}
|
|
|
1421
1536
|
undefined, and a bare var() reference invalidates the entire
|
|
1422
1537
|
custom-property value at computed-value time, leaving --font-sans
|
|
1423
1538
|
empty and text falling through to browser default ("Times"). */
|
|
1424
|
-
--font-sans: ${fontSans
|
|
1425
|
-
--font-serif: ${fontSerif
|
|
1426
|
-
--font-mono: ${fontMono
|
|
1539
|
+
--font-sans: ${fontStack(fontSans, "var(--font-inter, 'Inter'), var(--font-atkinson, 'Atkinson Hyperlegible'), 'Atkinson Hyperlegible', ui-sans-serif, sans-serif, system-ui")};
|
|
1540
|
+
--font-serif: ${fontStack(fontSerif, "var(--font-source-serif, 'Source Serif 4'), 'Source Serif 4', Georgia, ui-serif, serif")};
|
|
1541
|
+
--font-mono: ${fontStack(fontMono, "var(--font-jetbrains, 'JetBrains Mono'), 'JetBrains Mono', ui-monospace, monospace")};
|
|
1427
1542
|
--font-variation-settings: ${fontVariationSettings};
|
|
1428
1543
|
--font-size-scale: 1;
|
|
1429
1544
|
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* check:dark-contrast (bin: bads-check-dark-contrast) — every page, in dark mode, measured in a real browser: text that
|
|
4
|
+
* cannot be read on what is actually painted behind it fails.
|
|
5
|
+
*
|
|
6
|
+
* WHY THIS EXISTS
|
|
7
|
+
*
|
|
8
|
+
* In a client's prototypes, with dark mode on, a whole sign-up journey was near-white text on a white card, and a
|
|
9
|
+
* calendar had near-black names on its blue bars. Every gate passed: a token-pair audit checks the pairs the theme
|
|
10
|
+
* declares, and a static read of the built HTML sees light values only. The cause was a pair nobody declared, a
|
|
11
|
+
* hard-coded white fill under a theme-aware text token. Only the painted page shows it, so this measures the painted
|
|
12
|
+
* page, on every route, in dark. The in-page measure is lib/dark-contrast.mjs.
|
|
13
|
+
*
|
|
14
|
+
* WHAT IT DOES
|
|
15
|
+
*
|
|
16
|
+
* Opens each route on a running site in dark mode, at each viewport width, scrolls it so deferred blocks mount,
|
|
17
|
+
* proves the page really is dark, and measures every visible text node under the scope against its painted backdrop.
|
|
18
|
+
*
|
|
19
|
+
* SETTINGS. Each one is a flag, or a key under "darkContrast" in bads-checks.config.json (or the file --config names).
|
|
20
|
+
* A flag wins over the file, and the file wins over the default.
|
|
21
|
+
*
|
|
22
|
+
* base --base the running site http://localhost:3000
|
|
23
|
+
* routes --routes a,b the paths to open ["/"]
|
|
24
|
+
* scope --scope a CSS selector of what to measure the whole body
|
|
25
|
+
* viewports --viewports widths, in CSS px [1440, 393]
|
|
26
|
+
* darkQuery --dark-query a query added to each URL, as k=v none
|
|
27
|
+
* darkStorage localStorage entries set before load {}
|
|
28
|
+
* darkClass --dark-class a class put on <html> after load "dark"
|
|
29
|
+
* ("" leaves <html> alone, for a site that reads only the query or storage)
|
|
30
|
+
* darkProof --dark-proof a selector that must match once dark ".dark"
|
|
31
|
+
* normal --normal least ratio for normal text 4.5 (WCAG AA)
|
|
32
|
+
* large --large least ratio for large text 3
|
|
33
|
+
* largeSize, largeBoldSize when text is large, in px 24, and 18.66 at weight 700
|
|
34
|
+
* frameAttr --frame-attr the attribute naming a design "data-frame-id"
|
|
35
|
+
* lazySelector --lazy placeholders that must all mount "[data-lazy-skeleton]" ("" skips the scroll)
|
|
36
|
+
* known --known a JSON file of known findings none
|
|
37
|
+
*
|
|
38
|
+
* KNOWN FINDINGS. { "known": [{ "route": "/x", "frame": "(page)", "text": "Start of the text", "reason": "a sentence" }] }.
|
|
39
|
+
* An entry nothing matches any more fails a full run, so the list only shrinks.
|
|
40
|
+
*
|
|
41
|
+
* A route that will not load, a page that does not turn dark, or a page where nothing could be measured FAILS. A check
|
|
42
|
+
* that passes over nothing is how the defect it exists for ships.
|
|
43
|
+
*
|
|
44
|
+
* Usage:
|
|
45
|
+
* bads-check-dark-contrast --base http://localhost:3000 --routes /,/pricing
|
|
46
|
+
* bads-check-dark-contrast --route /pricing
|
|
47
|
+
*/
|
|
48
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
49
|
+
import { resolve } from "node:path";
|
|
50
|
+
import { DEFAULTS, measureTextContrast } from "./lib/dark-contrast.mjs";
|
|
51
|
+
import { mountEverything } from "./lib/mount-page.mjs";
|
|
52
|
+
|
|
53
|
+
const argv = process.argv.slice(2);
|
|
54
|
+
const flag = (name) => (argv.includes(name) ? argv[argv.indexOf(name) + 1] : undefined);
|
|
55
|
+
const list = (v) => (v === undefined ? undefined : String(v).split(",").map((s) => s.trim()).filter(Boolean));
|
|
56
|
+
|
|
57
|
+
const configPath = resolve(flag("--config") ?? "bads-checks.config.json");
|
|
58
|
+
let fileSettings = {};
|
|
59
|
+
if (existsSync(configPath)) {
|
|
60
|
+
try {
|
|
61
|
+
fileSettings = JSON.parse(readFileSync(configPath, "utf8")).darkContrast ?? {};
|
|
62
|
+
} catch (e) {
|
|
63
|
+
console.error(`✗ dark-contrast check: ${configPath} is not valid JSON (${e.message}).`);
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
} else if (flag("--config")) {
|
|
67
|
+
console.error(`✗ dark-contrast check: no settings file at ${configPath}.`);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
const pick = (key, fromFlag, fallback) => fromFlag ?? fileSettings[key] ?? fallback;
|
|
71
|
+
const single = flag("--route");
|
|
72
|
+
const s = {
|
|
73
|
+
base: String(pick("base", flag("--base"), "http://localhost:3000")).replace(/\/$/, ""),
|
|
74
|
+
routes: single ? [single] : pick("routes", list(flag("--routes")), ["/"]),
|
|
75
|
+
scope: pick("scope", flag("--scope"), null),
|
|
76
|
+
viewports: pick("viewports", list(flag("--viewports"))?.map(Number), [1440, 393]),
|
|
77
|
+
darkQuery: pick("darkQuery", flag("--dark-query"), null),
|
|
78
|
+
darkStorage: pick("darkStorage", undefined, {}),
|
|
79
|
+
darkClass: pick("darkClass", flag("--dark-class"), "dark"),
|
|
80
|
+
darkProof: pick("darkProof", flag("--dark-proof"), ".dark"),
|
|
81
|
+
normal: Number(pick("normal", flag("--normal"), DEFAULTS.normal)),
|
|
82
|
+
large: Number(pick("large", flag("--large"), DEFAULTS.large)),
|
|
83
|
+
largeSize: Number(pick("largeSize", undefined, DEFAULTS.largeSize)),
|
|
84
|
+
largeBoldSize: Number(pick("largeBoldSize", undefined, DEFAULTS.largeBoldSize)),
|
|
85
|
+
frameAttr: pick("frameAttr", flag("--frame-attr"), DEFAULTS.frameAttr),
|
|
86
|
+
lazySelector: pick("lazySelector", flag("--lazy"), "[data-lazy-skeleton]"),
|
|
87
|
+
known: pick("known", flag("--known"), null),
|
|
88
|
+
};
|
|
89
|
+
const bad = [];
|
|
90
|
+
if (!Array.isArray(s.routes) || !s.routes.length) bad.push("routes must name at least one path");
|
|
91
|
+
for (const k of ["normal", "large", "largeSize", "largeBoldSize"]) if (!Number.isFinite(s[k]) || s[k] <= 0) bad.push(`${k} must be a positive number, not ${s[k]}`);
|
|
92
|
+
if (s.normal < 3 || s.large < 3) bad.push("normal and large must be 3:1 or more: under that no WCAG level is met");
|
|
93
|
+
if (!s.viewports.length || s.viewports.some((w) => !Number.isFinite(w) || w < 200)) bad.push(`viewports must be widths of 200px or more, not ${s.viewports}`);
|
|
94
|
+
if (!s.darkProof) bad.push("darkProof must be a selector: without it a light page would be measured and called dark");
|
|
95
|
+
if (s.darkQuery && !/^[^=&]+=[^&]*$/.test(s.darkQuery)) bad.push(`darkQuery must be one key=value pair, not ${s.darkQuery}`);
|
|
96
|
+
if (bad.length) {
|
|
97
|
+
console.error(`✗ dark-contrast check: bad settings.\n${bad.map((p) => ` ${p}`).join("\n")}`);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const failures = [];
|
|
102
|
+
let known = [];
|
|
103
|
+
if (s.known) {
|
|
104
|
+
try {
|
|
105
|
+
known = JSON.parse(readFileSync(resolve(s.known), "utf8")).known ?? [];
|
|
106
|
+
} catch (e) {
|
|
107
|
+
console.error(`✗ dark-contrast check: cannot read the known findings in ${s.known} (${e.message}).`);
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
for (const k of known) if (!k.route || !k.frame || !k.text || !k.reason || k.reason.length < 20) failures.push(`${s.known}: an entry needs route, frame, text and a reason of a sentence: ${JSON.stringify(k)}`);
|
|
111
|
+
}
|
|
112
|
+
const used = new Set();
|
|
113
|
+
|
|
114
|
+
let chromium;
|
|
115
|
+
try {
|
|
116
|
+
({ chromium } = await import("playwright"));
|
|
117
|
+
} catch {
|
|
118
|
+
console.error("✗ dark-contrast check: playwright is not installed. Install it (pnpm add -D playwright).");
|
|
119
|
+
process.exit(1);
|
|
120
|
+
}
|
|
121
|
+
let browser;
|
|
122
|
+
try {
|
|
123
|
+
browser = await chromium.launch();
|
|
124
|
+
} catch (e) {
|
|
125
|
+
console.error("✗ dark-contrast check: no Chromium to drive. Run `pnpm exec playwright install chromium`.");
|
|
126
|
+
console.error(` ${String(e.message).split("\n")[0]}`);
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const options = { scope: s.scope, normal: s.normal, large: s.large, largeSize: s.largeSize, largeBoldSize: s.largeBoldSize, frameAttr: s.frameAttr };
|
|
131
|
+
const totals = { measured: 0, onImage: 0, disabled: 0, pages: 0 };
|
|
132
|
+
const lines = new Set();
|
|
133
|
+
for (const width of s.viewports) {
|
|
134
|
+
const ctx = await browser.newContext({ viewport: { width, height: 900 }, colorScheme: "dark", reducedMotion: "reduce" });
|
|
135
|
+
await ctx.addInitScript((entries) => {
|
|
136
|
+
try {
|
|
137
|
+
for (const [k, v] of Object.entries(entries)) localStorage.setItem(k, v);
|
|
138
|
+
} catch {}
|
|
139
|
+
}, s.darkStorage);
|
|
140
|
+
const page = await ctx.newPage();
|
|
141
|
+
page.setDefaultTimeout(30000);
|
|
142
|
+
for (const route of s.routes) {
|
|
143
|
+
try {
|
|
144
|
+
const url = new URL(s.base + route);
|
|
145
|
+
if (s.darkQuery) {
|
|
146
|
+
const [k, v] = s.darkQuery.split("=");
|
|
147
|
+
url.searchParams.set(k, v);
|
|
148
|
+
}
|
|
149
|
+
const res = await page.goto(url.toString(), { waitUntil: "load", timeout: 120000 });
|
|
150
|
+
if (!res || res.status() >= 400) throw new Error(`HTTP ${res?.status() ?? "no response"}`);
|
|
151
|
+
await page.waitForLoadState("networkidle", { timeout: 15000 }).catch(() => {});
|
|
152
|
+
if (s.darkClass) await page.evaluate((c) => document.documentElement.classList.add(c), s.darkClass);
|
|
153
|
+
await page.waitForTimeout(1200);
|
|
154
|
+
if (s.lazySelector !== "") {
|
|
155
|
+
const unmounted = await mountEverything(page, { lazySelector: s.lazySelector });
|
|
156
|
+
if (unmounted > 0) throw new Error(`${unmounted} deferred block(s) never mounted (${s.lazySelector}), so they could not be measured`);
|
|
157
|
+
}
|
|
158
|
+
if (s.darkClass) await page.evaluate((c) => document.documentElement.classList.add(c), s.darkClass);
|
|
159
|
+
/* `content-visibility: auto` skips style for whatever is off screen, so a section below the fold can still hold
|
|
160
|
+
its light-mode colours, mid-way through the theme change, when the measure reads it. A person scrolling there
|
|
161
|
+
sees it finished. Every element is made visible to the renderer before measuring, so the measure reads what a
|
|
162
|
+
person would see on arriving. */
|
|
163
|
+
await page.addStyleTag({ content: "*, *::before, *::after { content-visibility: visible !important; }" });
|
|
164
|
+
await page.waitForTimeout(600);
|
|
165
|
+
/* Checked immediately before measuring: without it "no failures in dark" and "never entered dark" read the same. */
|
|
166
|
+
if (!(await page.evaluate((sel) => !!document.querySelector(sel), s.darkProof))) throw new Error(`the page did not turn dark (nothing matches ${s.darkProof})`);
|
|
167
|
+
const r = await page.evaluate(`(${measureTextContrast})(${JSON.stringify(options)})`);
|
|
168
|
+
if (r.measured === 0) throw new Error(`no text measured${s.scope ? ` inside ${s.scope}` : ""}`);
|
|
169
|
+
totals.pages++;
|
|
170
|
+
totals.measured += r.measured;
|
|
171
|
+
totals.onImage += r.onImage;
|
|
172
|
+
totals.disabled += r.disabled;
|
|
173
|
+
for (const f of r.fails) {
|
|
174
|
+
const k = known.find((x) => x.route === route && x.frame === f.frame && f.text.startsWith(x.text));
|
|
175
|
+
if (k) {
|
|
176
|
+
used.add(k);
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
const line = `${route} ${f.frame}: "${f.text}" ${f.fg} on ${f.bg} = ${f.ratio.toFixed(2)}:1 (needs ${f.floor}:1)`;
|
|
180
|
+
if (!lines.has(line)) failures.push(`${line} at ${width}px`);
|
|
181
|
+
lines.add(line);
|
|
182
|
+
}
|
|
183
|
+
} catch (e) {
|
|
184
|
+
failures.push(`${route} at ${width}px: could not measure: ${String(e.message).split("\n")[0]}`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
await ctx.close();
|
|
188
|
+
}
|
|
189
|
+
await browser.close();
|
|
190
|
+
if (!single) for (const k of known) if (!used.has(k)) failures.push(`${s.known}: nothing matches ${k.route} / ${k.frame} / "${k.text}" any more. Remove the entry.`);
|
|
191
|
+
|
|
192
|
+
if (failures.length) {
|
|
193
|
+
console.error(`\n✗ dark-contrast check: ${failures.length} problem(s) in dark mode across ${s.routes.length} route(s).\n`);
|
|
194
|
+
for (const f of failures.slice(0, 200)) console.error(` ${f}`);
|
|
195
|
+
if (failures.length > 200) console.error(` … and ${failures.length - 200} more`);
|
|
196
|
+
console.error(
|
|
197
|
+
"\n A surface and the text on it are a pair. A hard-coded fill (bg-white, a neutral step) stays light while theme" +
|
|
198
|
+
"\n tokens on it turn light too. Use a surface token, or give the fill a dark value.",
|
|
199
|
+
);
|
|
200
|
+
process.exit(1);
|
|
201
|
+
}
|
|
202
|
+
console.log(
|
|
203
|
+
`✓ dark-contrast check: ${totals.measured} text(s) on ${totals.pages} page(s) (${s.routes.length} route(s) at ${s.viewports.join(" and ")}px) in dark, all at ${s.normal}:1 (${s.large}:1 large) or more; ${totals.onImage} over an image and ${totals.disabled} disabled not measured.`,
|
|
204
|
+
);
|