@behavioral-agentic-design-system/core 0.42.0 → 0.47.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 +38 -8
- package/scripts/a11y-lint.cjs +101 -14
- 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/check-spec.mjs +73 -0
- package/scripts/deal-directions.mjs +186 -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/health-report.mjs +20 -14
- package/scripts/lib/copy-strings.mjs +146 -0
- package/scripts/lib/counted-lint.mjs +100 -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/marketing-library.mjs +129 -0
- package/scripts/lib/mount-page.mjs +25 -0
- package/scripts/lib/on-system.mjs +249 -0
- package/scripts/lib/random.mjs +22 -0
- package/scripts/lib/source-scan.mjs +173 -0
- package/scripts/lib/spec-parse.d.mts +25 -0
- package/scripts/lib/spec-parse.mjs +188 -0
- package/scripts/lib/tells.mjs +366 -0
- 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-css-vars.mjs +175 -0
- package/scripts/lint-even-padding.mjs +58 -0
- package/scripts/lint-html-nesting.mjs +116 -0
- package/scripts/lint-label-case.mjs +219 -0
- package/scripts/lint-live-ctas.mjs +138 -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/on-system-score.mjs +95 -0
- package/scripts/size-audit.cjs +2 -2
- package/scripts/slop-rules.mjs +1 -1
- package/scripts/source-images.mjs +180 -0
- package/scripts/ux-tells.mjs +80 -0
- package/scripts/wcag-audit.cjs +25 -4
- package/src/api/brand-colors.ts +3 -0
- package/src/api/brand-fonts.ts +3 -0
- package/src/api/brand-mark.ts +6 -1
- package/src/api/dev-write-guard.ts +53 -0
- package/src/api/layers/file.ts +9 -4
- package/src/api/onboarding-extract.ts +85 -30
- package/src/api/onboarding.ts +3 -0
- package/src/api/save-tokens.ts +3 -0
- package/src/api/site-auth.ts +14 -2
- package/src/app/layout.tsx +6 -0
- package/src/app/preview/canvas/page.tsx +12 -0
- package/src/app/preview/components/page.tsx +828 -14
- package/src/app/preview/sticker-sheet/page.tsx +329 -0
- package/src/app/preview/sticker-sheet/specimens.tsx +296 -0
- package/src/app/preview/studio/blank-screen.tsx +143 -0
- package/src/app/preview/studio/page.tsx +7 -0
- package/src/app/shell.tsx +164 -47
- package/src/components/Foundations/Colors.stories.tsx +119 -8
- package/src/components/canvas/canvas.tsx +458 -0
- package/src/components/canvas/layout.ts +72 -0
- package/src/components/canvas/parse-canvas.ts +32 -0
- package/src/components/canvas/sample.ts +90 -0
- package/src/components/canvas/spec-frame.tsx +43 -0
- package/src/components/canvas/types.ts +33 -0
- package/src/components/docs-tab.tsx +7 -7
- package/src/components/home-recent.tsx +73 -0
- package/src/components/home-tab.tsx +19 -14
- package/src/components/layers-tab.tsx +2 -2
- package/src/components/markdown-preview.tsx +60 -12
- package/src/components/onboarding-wizard.tsx +1 -1
- package/src/components/studio/control-panel.tsx +299 -0
- package/src/components/studio/control-row.tsx +77 -0
- package/src/components/studio/preview-frame.tsx +165 -0
- package/src/components/studio/preview-pane.tsx +247 -0
- package/src/components/studio/studio.tsx +133 -128
- package/src/components/studio/types.ts +218 -0
- package/src/components/studio/use-studio-tweaks.ts +128 -0
- package/src/components/studio/use-studio-view-state.ts +72 -0
- package/src/components/ui/autocomplete.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/color-picker.tsx +20 -4
- package/src/components/ui/combobox.tsx +1 -0
- package/src/components/ui/command.tsx +1 -1
- package/src/components/ui/data-table.tsx +64 -3
- package/src/components/ui/date-field.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/editable.tsx +1 -0
- package/src/components/ui/faceted-filter.tsx +187 -0
- package/src/components/ui/file-upload.tsx +21 -2
- package/src/components/ui/gauge-chart.tsx +18 -4
- package/src/components/ui/heatmap.tsx +3 -1
- package/src/components/ui/inline-edit.tsx +175 -0
- package/src/components/ui/input-group.tsx +5 -2
- package/src/components/ui/month-picker.tsx +1 -1
- package/src/components/ui/multi-select.tsx +1 -0
- package/src/components/ui/number-input.tsx +28 -5
- package/src/components/ui/otp-input.tsx +208 -0
- package/src/components/ui/phone-input.tsx +274 -0
- package/src/components/ui/radio-group.tsx +2 -2
- package/src/components/ui/search-input.tsx +1 -1
- 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/tags-input.tsx +1 -1
- package/src/components/ui/timer.tsx +1 -0
- package/src/components/ui/transfer-list.tsx +13 -26
- package/src/components/ui/week-picker.tsx +1 -13
- package/src/components/ui/year-picker.tsx +1 -1
- package/src/data/component-added.json +966 -0
- package/src/data/docs-index.ts +35 -2
- package/src/data/history.json +161 -161
- package/src/data/sticker-sheet.json +9244 -0
- package/src/docs-trace-globs.json +1 -0
- package/src/hooks/use-global-mono-font.ts +1 -0
- package/src/hooks/use-global-primary-color.ts +1 -0
- package/src/hooks/use-global-sans-font.ts +1 -0
- package/src/hooks/use-global-serif-font.ts +1 -0
- package/src/hooks/use-global-type-scale.ts +17 -2
- package/src/hooks/use-mobile.ts +2 -0
- package/src/hooks/use-sync-type-scale.ts +7 -11
- package/src/lib/chart-motion.ts +41 -0
- package/src/lib/get-icon-color.ts +1 -1
- package/src/lib/spec-parse.ts +4 -0
- package/src/lib/svg-sanitize.ts +19 -9
- 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 +8 -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/Canvas.stories.tsx +45 -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 +19 -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 +46 -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 +39 -0
- package/src/stories/DateField.stories.tsx +28 -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 +12 -0
- package/src/stories/EmptyState.stories.tsx +9 -0
- package/src/stories/FacetedFilter.stories.tsx +197 -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/GaugeChart.stories.tsx +9 -3
- 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/InlineEdit.stories.tsx +106 -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/MarkdownPreview.stories.tsx +53 -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 +26 -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/NumberInput.stories.tsx +33 -1
- package/src/stories/OtpInput.stories.tsx +110 -0
- 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/PhoneInput.stories.tsx +127 -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 +10 -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 +15 -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 +30 -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 +7 -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 +25 -1
- package/src/stories/WordRotate.stories.tsx +5 -0
- package/src/stories/YearPicker.stories.tsx +26 -11
- package/src/stories/story-groups.json +22 -16
- package/src/styles.css +50 -2
- package/src/tokens.json +86 -58
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* lint-target-size — flag a control whose fixed size is under the touch-target floor.
|
|
4
|
+
*
|
|
5
|
+
* WCAG 2.5.5 (AAA) asks for 44 by 44 CSS px on anything a person presses. This reads the opening
|
|
6
|
+
* tag of a `button`, `Button`, `IconButton`, an element with `role="button"`, or any tag with
|
|
7
|
+
* `onClick`, and flags a fixed `h-`, `w-` or `size-` class under the floor. `min-h-11 min-w-11`
|
|
8
|
+
* on the same tag clears it. a11y-lint points here for touch-target sizes.
|
|
9
|
+
*
|
|
10
|
+
* It sees only sizes written as classes: `h-8`, `size-6`, `w-[32px]`. A size that a component
|
|
11
|
+
* prop sets (`size="sm"`) is not read, and neither is a size built at run time.
|
|
12
|
+
*
|
|
13
|
+
* The floor is 44px by default. Change it with `--min-px=48`, or with `"minTargetPx"` in
|
|
14
|
+
* `.bads-lint.json` at the repo root. The flag wins over the file.
|
|
15
|
+
*
|
|
16
|
+
* Mark an intended exception with `tap-target-ok: <why>` on the line or the line above. A marker
|
|
17
|
+
* with no reason does not count.
|
|
18
|
+
*
|
|
19
|
+
* Run:
|
|
20
|
+
* bads-lint-target-size # report, exit 1 on fail
|
|
21
|
+
* bads-lint-target-size --warn # report, exit 0 (advisory)
|
|
22
|
+
* bads-lint-target-size --min-px=48 # a different floor
|
|
23
|
+
* bads-lint-target-size path/to.tsx # one file, or a directory
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
'use strict';
|
|
27
|
+
|
|
28
|
+
const fs = require('fs');
|
|
29
|
+
const path = require('path');
|
|
30
|
+
const { resolveScanFiles, guardEmptyScan } = require('./lib/scan-roots.cjs');
|
|
31
|
+
|
|
32
|
+
const ROOT = process.cwd();
|
|
33
|
+
const advisory = process.argv.includes('--warn');
|
|
34
|
+
const DEFAULT_MIN_PX = 44;
|
|
35
|
+
const PX_PER_UNIT = 4;
|
|
36
|
+
const LOOK_BACK = 8;
|
|
37
|
+
|
|
38
|
+
function readMinPx() {
|
|
39
|
+
const flag = process.argv.find((a) => a.startsWith('--min-px='));
|
|
40
|
+
if (flag) {
|
|
41
|
+
const n = Number(flag.slice('--min-px='.length));
|
|
42
|
+
if (Number.isFinite(n) && n > 0) return n;
|
|
43
|
+
console.error(`lint-target-size: --min-px needs a positive number, got "${flag}".`);
|
|
44
|
+
process.exit(2);
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
const parsed = JSON.parse(fs.readFileSync(path.join(ROOT, '.bads-lint.json'), 'utf8'));
|
|
48
|
+
if (Number.isFinite(parsed.minTargetPx) && parsed.minTargetPx > 0) return parsed.minTargetPx;
|
|
49
|
+
} catch { /* no config file: the default stands */ }
|
|
50
|
+
return DEFAULT_MIN_PX;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const MIN_PX = readMinPx();
|
|
54
|
+
const MIN_UNITS = MIN_PX / PX_PER_UNIT;
|
|
55
|
+
|
|
56
|
+
// `h-8`, `size-6`, `w-[32px]`, `h-[2rem]`. A fraction (`w-1/2`), `h-full` or `h-screen` has no
|
|
57
|
+
// fixed size, so the pattern does not match it.
|
|
58
|
+
const FIXED_SIZE = /(?<![\w-])(?:h|w|size)-(?:(\d+(?:\.\d+)?)|\[(\d+(?:\.\d+)?)(px|rem)\])(?![\w./[-])/g;
|
|
59
|
+
const MIN_SIZE = /(?<![\w-])min-(?:h|w)-(?:(\d+(?:\.\d+)?)|\[(\d+(?:\.\d+)?)(px|rem)\])(?![\w./[-])/g;
|
|
60
|
+
const TAG_START = /<(button|Button|IconButton|[A-Za-z][\w.]*)\b/;
|
|
61
|
+
const MARKER = /tap-target-ok\s*:\s*[^\s*/}]/;
|
|
62
|
+
|
|
63
|
+
const toPx = (units, value, unit) => {
|
|
64
|
+
if (units !== undefined) return Number(units) * PX_PER_UNIT;
|
|
65
|
+
return unit === 'rem' ? Number(value) * 16 : Number(value);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
function openingTag(lines, index) {
|
|
69
|
+
for (let i = index; i >= Math.max(0, index - LOOK_BACK); i--) {
|
|
70
|
+
const start = lines[i].match(TAG_START);
|
|
71
|
+
if (!start) continue;
|
|
72
|
+
return { name: start[1], text: lines.slice(i, index + 1).join('\n') };
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const isControl = ({ name, text }) =>
|
|
78
|
+
/^(button|Button|IconButton)$/.test(name) || /\bonClick=/.test(text) || /\brole=["']button["']/.test(text);
|
|
79
|
+
|
|
80
|
+
const clearedByMinimum = (text) =>
|
|
81
|
+
[...text.matchAll(MIN_SIZE)].some((m) => toPx(m[1], m[2], m[3]) >= MIN_PX);
|
|
82
|
+
|
|
83
|
+
const scan = resolveScanFiles({ root: ROOT, argv: process.argv.slice(2), allowDirArgs: true, excludeStories: true });
|
|
84
|
+
const issues = [];
|
|
85
|
+
|
|
86
|
+
for (const file of scan.files) {
|
|
87
|
+
let src;
|
|
88
|
+
try {
|
|
89
|
+
src = fs.readFileSync(file, 'utf8');
|
|
90
|
+
} catch {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (src.startsWith('/* GENERATED')) continue;
|
|
94
|
+
if (file.includes('/e2e/') || /\.(spec|test)\.tsx?$/.test(file)) continue;
|
|
95
|
+
const lines = src.split('\n');
|
|
96
|
+
for (let i = 0; i < lines.length; i++) {
|
|
97
|
+
const line = lines[i];
|
|
98
|
+
if (/^\s*(\/\/|\/\*|\*)/.test(line)) continue;
|
|
99
|
+
const small = [...line.matchAll(FIXED_SIZE)].filter((m) => toPx(m[1], m[2], m[3]) < MIN_PX);
|
|
100
|
+
if (small.length === 0) continue;
|
|
101
|
+
if (MARKER.test(line) || (i > 0 && MARKER.test(lines[i - 1]))) continue;
|
|
102
|
+
const tag = openingTag(lines, i);
|
|
103
|
+
if (!tag || !isControl(tag) || clearedByMinimum(tag.text)) continue;
|
|
104
|
+
const m = small[0];
|
|
105
|
+
issues.push({
|
|
106
|
+
file: path.relative(ROOT, file),
|
|
107
|
+
line: i + 1,
|
|
108
|
+
message: `${m[0]} is ${toPx(m[1], m[2], m[3])}px on a control, under the ${MIN_PX}px touch-target floor. Add min-h-${MIN_UNITS} min-w-${MIN_UNITS}, or grow the hit area with padding. If a person chose a smaller size, add "tap-target-ok: <why>" on this line or the line above.`,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (issues.length === 0) {
|
|
114
|
+
if (guardEmptyScan(scan, 'lint-target-size')) { /* exited */ }
|
|
115
|
+
console.log(
|
|
116
|
+
scan.files.length
|
|
117
|
+
? `✓ lint-target-size: no control is fixed under ${MIN_PX}px.`
|
|
118
|
+
: '✓ lint-target-size: no control is fixed under the floor (0 files matched under existing scan roots).'
|
|
119
|
+
);
|
|
120
|
+
process.exit(0);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const grouped = issues.reduce((acc, it) => {
|
|
124
|
+
(acc[it.file] = acc[it.file] || []).push(it);
|
|
125
|
+
return acc;
|
|
126
|
+
}, {});
|
|
127
|
+
for (const file of Object.keys(grouped).sort()) {
|
|
128
|
+
console.log(`\n${file}`);
|
|
129
|
+
for (const it of grouped[file]) console.log(` L${it.line} [SC 2.5.5 target-size] ${it.message}`);
|
|
130
|
+
}
|
|
131
|
+
console.log(`\n${issues.length} issue${issues.length === 1 ? '' : 's'} across ${Object.keys(grouped).length} file${Object.keys(grouped).length === 1 ? '' : 's'}.`);
|
|
132
|
+
process.exit(advisory ? 0 : 1);
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* lint-token-primitives — every semantic color token should alias a primitive
|
|
4
|
+
* (a numbered ramp step like `--color-blue-500`, or a named palette literal
|
|
5
|
+
* like `--color-<brand-name>`), not carry its own hardcoded hex/rgb/oklch
|
|
6
|
+
* value. Checked separately for light and dark: a token can alias a primitive
|
|
7
|
+
* in one mode and still carry a raw literal in the other, so both need their
|
|
8
|
+
* own pass. A hardcoded semantic token means changing a color means hunting
|
|
9
|
+
* down every place that value got typed by hand, instead of moving one
|
|
10
|
+
* primitive and letting every alias follow it.
|
|
11
|
+
*
|
|
12
|
+
* SCOPE — read this before pointing it at a repo. This only has something to
|
|
13
|
+
* say about a Tailwind v4 CSS-first theme that has an actual ramp/primitive
|
|
14
|
+
* layer underneath its semantic tokens (numbered steps, or a named palette).
|
|
15
|
+
* BADS's own default scaffold (packages/core/src/styles.css) does NOT use
|
|
16
|
+
* that shape — it declares flat oklch/hex literals directly on
|
|
17
|
+
* semantic-looking names (`--primary`, `--destructive`, ...) with nothing
|
|
18
|
+
* underneath them, so every token there already IS a literal by design, not
|
|
19
|
+
* a drift defect. Run this against that file and it correctly reports "not
|
|
20
|
+
* applicable" rather than a wall of false positives. It is an opt-in check
|
|
21
|
+
* for forks that build (or are migrating toward) a real primitive ramp —
|
|
22
|
+
* not a rule the default scaffold itself follows.
|
|
23
|
+
*
|
|
24
|
+
* No existing BADS lint (lint-token-intent, lint-css-vars, lint-component-
|
|
25
|
+
* source, wcag-audit, ...) walks a color token's own var() alias chain to
|
|
26
|
+
* its termination. See BADS_UPSTREAM_CANDIDATES.md in the fork this shipped
|
|
27
|
+
* from for the incident that found the gap.
|
|
28
|
+
*
|
|
29
|
+
* Goes through the shared counted-lint tail (strict by default; --warn makes
|
|
30
|
+
* it advisory; --init records a baseline; --ratchet checks against it) — see
|
|
31
|
+
* lib/counted-lint.mjs. That machinery already covers "adopting this on an
|
|
32
|
+
* existing codebase with a backlog": run --init once, then --ratchet in CI.
|
|
33
|
+
*
|
|
34
|
+
* Usage:
|
|
35
|
+
* npx bads-lint-token-primitives
|
|
36
|
+
* --theme <path> theme file to check (default: first of
|
|
37
|
+
* src/styles/theme.css, styles/theme.css,
|
|
38
|
+
* app/globals.css, src/app/globals.css,
|
|
39
|
+
* styles/globals.css that exists)
|
|
40
|
+
* --dark-selector <sel> e.g. ".dark-mode", ".dark", '[data-theme="dark"]'
|
|
41
|
+
* (default: try .dark-mode, then .dark, then
|
|
42
|
+
* [data-theme="dark"] — first one actually
|
|
43
|
+
* present in the file wins; none found means no
|
|
44
|
+
* dark-specific declarations to check, which is
|
|
45
|
+
* a legitimate shape, not an error)
|
|
46
|
+
* --families a,b,c extra primitive RAMP family names on top of the
|
|
47
|
+
* built-in stock Tailwind v4 families (red, blue,
|
|
48
|
+
* rose, slate, ...) — e.g. a fork's own status-
|
|
49
|
+
* color ramp
|
|
50
|
+
* --names a,b,c extra single, non-numbered primitive names on
|
|
51
|
+
* top of the built-in white/black/transparent —
|
|
52
|
+
* e.g. a fork's own named brand palette
|
|
53
|
+
* --warn | --init | --ratchet see lib/counted-lint.mjs
|
|
54
|
+
*
|
|
55
|
+
* Escape hatch: `/* allow-literal-color: <reason> *\/` (a real CSS comment —
|
|
56
|
+
* `//` is not valid CSS and a parser would fold it into the declaration's own
|
|
57
|
+
* value) on the line directly above the declaration, in the SAME mode block
|
|
58
|
+
* as the violation it excuses. A light-mode escape hatch does not also excuse
|
|
59
|
+
* a hardcoded dark override of the same token.
|
|
60
|
+
*/
|
|
61
|
+
import fs from "node:fs";
|
|
62
|
+
import path from "node:path";
|
|
63
|
+
import { finishCountedLint, flagValue, isMain } from "./lib/counted-lint.mjs";
|
|
64
|
+
|
|
65
|
+
const THEME_CANDIDATES = ["src/styles/theme.css", "styles/theme.css", "app/globals.css", "src/app/globals.css", "styles/globals.css"];
|
|
66
|
+
const DARK_SELECTOR_CANDIDATES = [".dark-mode", ".dark", '[data-theme="dark"]'];
|
|
67
|
+
|
|
68
|
+
const STOCK_TAILWIND_FAMILIES = [
|
|
69
|
+
"slate",
|
|
70
|
+
"gray",
|
|
71
|
+
"zinc",
|
|
72
|
+
"neutral",
|
|
73
|
+
"stone",
|
|
74
|
+
"red",
|
|
75
|
+
"orange",
|
|
76
|
+
"amber",
|
|
77
|
+
"yellow",
|
|
78
|
+
"lime",
|
|
79
|
+
"green",
|
|
80
|
+
"emerald",
|
|
81
|
+
"teal",
|
|
82
|
+
"cyan",
|
|
83
|
+
"sky",
|
|
84
|
+
"blue",
|
|
85
|
+
"indigo",
|
|
86
|
+
"violet",
|
|
87
|
+
"purple",
|
|
88
|
+
"fuchsia",
|
|
89
|
+
"pink",
|
|
90
|
+
"rose",
|
|
91
|
+
// Common extensions, not stock Tailwind, but common enough across forks
|
|
92
|
+
// to ship as defaults rather than making every brand-ramp fork pass --families.
|
|
93
|
+
"brand",
|
|
94
|
+
"alpha",
|
|
95
|
+
];
|
|
96
|
+
const DEFAULT_NAMED_SINGLETONS = ["white", "black", "transparent"];
|
|
97
|
+
|
|
98
|
+
/** Finds the first `{ ... }` block whose selector matches `selector` as a real
|
|
99
|
+
* CSS rule — the selector text immediately followed (after whitespace/other
|
|
100
|
+
* selector text, never a brace) by `{`. Anchoring on the `{` is what keeps
|
|
101
|
+
* this from matching selector text sitting inside an unrelated at-rule, e.g.
|
|
102
|
+
* `@custom-variant dark (&:is(.dark *));` for a bare ".dark" search — that
|
|
103
|
+
* line has no `{` right after ".dark", so it's correctly skipped. A class
|
|
104
|
+
* selector also requires a non-word/non-hyphen boundary right after its own
|
|
105
|
+
* name, so searching for ".dark" does not match inside ".dark-mode" or
|
|
106
|
+
* ".darker-overlay" when those appear first in the file.
|
|
107
|
+
*/
|
|
108
|
+
export function findBlock(source, selector) {
|
|
109
|
+
const escaped = selector.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
110
|
+
const boundary = /^\.[\w-]+$/.test(selector) ? "(?![\\w-])" : "";
|
|
111
|
+
const re = new RegExp(`${escaped}${boundary}[^{};]*\\{`, "m");
|
|
112
|
+
const m = re.exec(source);
|
|
113
|
+
if (!m) return { block: "", braceStart: -1 };
|
|
114
|
+
const braceStart = m.index + m[0].length;
|
|
115
|
+
let depth = 1;
|
|
116
|
+
let i = braceStart;
|
|
117
|
+
while (depth > 0 && i < source.length) {
|
|
118
|
+
if (source[i] === "{") depth++;
|
|
119
|
+
else if (source[i] === "}") depth--;
|
|
120
|
+
i++;
|
|
121
|
+
}
|
|
122
|
+
return { block: source.slice(braceStart, i - 1), braceStart };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Declarations plus the source line number each one's `--name:` starts on,
|
|
126
|
+
* so a violation points at a real line and the escape-hatch lookup checks
|
|
127
|
+
* the line directly above THAT declaration. */
|
|
128
|
+
export function parseDeclarations(source, block, blockStart) {
|
|
129
|
+
const map = new Map();
|
|
130
|
+
const re = /--([a-zA-Z0-9_-]+)\s*:\s*([^;]+);/g;
|
|
131
|
+
let m;
|
|
132
|
+
while ((m = re.exec(block))) {
|
|
133
|
+
const lineNo = source.slice(0, blockStart + m.index).split("\n").length;
|
|
134
|
+
map.set(m[1], { value: m[2].trim(), line: lineNo });
|
|
135
|
+
}
|
|
136
|
+
return map;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function aliasOf(value) {
|
|
140
|
+
const m = /^var\(\s*--([a-zA-Z0-9_-]+)\s*\)$/.exec(value);
|
|
141
|
+
return m?.[1];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Builds the primitive-name predicate for one run: a numbered ramp step
|
|
145
|
+
* (`color-<family>-<step>`) in one of the stock-or-extra families, or a
|
|
146
|
+
* single named primitive (`color-<name>`) in the stock-or-extra names list. */
|
|
147
|
+
export function buildIsPrimitiveName(extraFamilies = [], extraNames = []) {
|
|
148
|
+
const families = [...STOCK_TAILWIND_FAMILIES, ...extraFamilies];
|
|
149
|
+
const names = new Set([...DEFAULT_NAMED_SINGLETONS, ...extraNames].map((n) => `color-${n}`));
|
|
150
|
+
const rampRe = new RegExp(`^color-(${families.join("|")})-[a-zA-Z0-9]+$`);
|
|
151
|
+
return (name) => rampRe.test(name) || names.has(name);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Walks the var() chain from `name` to termination for one mode, returning
|
|
155
|
+
* the classification and the chain of names visited. `lookup(name, mode)`
|
|
156
|
+
* is injected so the dark lookup's "fall back to light when unoverridden"
|
|
157
|
+
* rule (the same rule the real CSS cascade applies) lives with the caller,
|
|
158
|
+
* which owns both tables. Escape-hatch eligibility is decided against the
|
|
159
|
+
* STARTING name's own declaration in this mode, not wherever the chain
|
|
160
|
+
* happens to terminate. */
|
|
161
|
+
export function classify(startName, mode, { light, dark, lookup, isPrimitiveName }) {
|
|
162
|
+
const startDecl = mode === "dark" ? (dark.get(startName) ?? light.get(startName)) : light.get(startName);
|
|
163
|
+
let name = startName;
|
|
164
|
+
const seen = new Set();
|
|
165
|
+
while (true) {
|
|
166
|
+
if (seen.has(name)) return { kind: "cycle", chain: [...seen, name], startDecl };
|
|
167
|
+
seen.add(name);
|
|
168
|
+
const decl = lookup(name, mode);
|
|
169
|
+
if (decl === undefined) return { kind: "dead-end", chain: [...seen], startDecl };
|
|
170
|
+
const alias = aliasOf(decl.value);
|
|
171
|
+
if (!alias) {
|
|
172
|
+
return {
|
|
173
|
+
kind: isPrimitiveName(name) ? "primitive-literal" : "hardcoded-literal",
|
|
174
|
+
chain: [...seen],
|
|
175
|
+
value: decl.value,
|
|
176
|
+
startDecl,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
if (isPrimitiveName(alias)) return { kind: "resolves-to-primitive", chain: [...seen, alias], startDecl };
|
|
180
|
+
name = alias;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function run() {
|
|
185
|
+
const ROOT = process.cwd();
|
|
186
|
+
const argv = process.argv.slice(2);
|
|
187
|
+
|
|
188
|
+
const themeArg = flagValue(argv, "theme", null);
|
|
189
|
+
const themePath = themeArg
|
|
190
|
+
? path.join(ROOT, themeArg)
|
|
191
|
+
: THEME_CANDIDATES.map((p) => path.join(ROOT, p)).find((p) => fs.existsSync(p));
|
|
192
|
+
if (!themePath || !fs.existsSync(themePath)) {
|
|
193
|
+
console.error(
|
|
194
|
+
`bads-lint-token-primitives: no theme file found (looked for ${THEME_CANDIDATES.join(", ")}). Point at one with --theme <path>.`,
|
|
195
|
+
);
|
|
196
|
+
process.exit(1);
|
|
197
|
+
}
|
|
198
|
+
const relThemePath = path.relative(ROOT, themePath);
|
|
199
|
+
|
|
200
|
+
const RAW = fs.readFileSync(themePath, "utf8");
|
|
201
|
+
const RAW_LINES = RAW.split("\n");
|
|
202
|
+
const tailwindThemePath = path.join(ROOT, "node_modules/tailwindcss/theme.css");
|
|
203
|
+
const TW_RAW = fs.existsSync(tailwindThemePath) ? fs.readFileSync(tailwindThemePath, "utf8") : "";
|
|
204
|
+
|
|
205
|
+
const { block: rootBlock, braceStart: rootBraceStart } = findBlock(RAW, ":root");
|
|
206
|
+
const ROOT_DECLS = rootBraceStart === -1 ? new Map() : parseDeclarations(RAW, rootBlock, rootBraceStart);
|
|
207
|
+
const { block: themeBlock, braceStart: themeBraceStart } = findBlock(RAW, "@theme");
|
|
208
|
+
const THEME_DECLS = themeBraceStart === -1 ? new Map() : parseDeclarations(RAW, themeBlock, themeBraceStart);
|
|
209
|
+
// @theme's own declarations win on a name collision — in a split layout
|
|
210
|
+
// that's the Tailwind-exposed alias, which is the one that's actually
|
|
211
|
+
// semantic-shaped and worth checking.
|
|
212
|
+
const LIGHT = new Map([...ROOT_DECLS, ...THEME_DECLS]);
|
|
213
|
+
|
|
214
|
+
const darkSelectorArg = flagValue(argv, "dark-selector", null);
|
|
215
|
+
const darkCandidates = darkSelectorArg ? [darkSelectorArg] : DARK_SELECTOR_CANDIDATES;
|
|
216
|
+
let darkSelectorUsed = null;
|
|
217
|
+
let DARK = new Map();
|
|
218
|
+
for (const sel of darkCandidates) {
|
|
219
|
+
const { block, braceStart } = findBlock(RAW, sel);
|
|
220
|
+
if (braceStart !== -1) {
|
|
221
|
+
DARK = parseDeclarations(RAW, block, braceStart);
|
|
222
|
+
darkSelectorUsed = sel;
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const { block: twBlock, braceStart: twBraceStart } = findBlock(TW_RAW, "@theme");
|
|
228
|
+
const TAILWIND_RAW_LINES = TW_RAW.split("\n");
|
|
229
|
+
const TW_LIGHT = twBraceStart === -1 ? new Map() : parseDeclarations(TW_RAW, twBlock, twBraceStart);
|
|
230
|
+
|
|
231
|
+
function lookup(name, mode) {
|
|
232
|
+
if (mode === "dark") return DARK.get(name) ?? LIGHT.get(name) ?? TW_LIGHT.get(name);
|
|
233
|
+
return LIGHT.get(name) ?? TW_LIGHT.get(name);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const extraFamilies = (flagValue(argv, "families", "") || "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
237
|
+
const extraNames = (flagValue(argv, "names", "") || "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
238
|
+
const isPrimitiveName = buildIsPrimitiveName(extraFamilies, extraNames);
|
|
239
|
+
|
|
240
|
+
function hasEscapeHatch(decl) {
|
|
241
|
+
if (!decl || decl.line == null) return false;
|
|
242
|
+
const lines = decl.source === "tailwind" ? TAILWIND_RAW_LINES : RAW_LINES;
|
|
243
|
+
return (lines[decl.line - 2] || "").includes("allow-literal-color:");
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const colorNames = [...LIGHT.keys()].filter((n) => n.startsWith("color-"));
|
|
247
|
+
const primitiveNamesDeclared = colorNames.filter((n) => isPrimitiveName(n));
|
|
248
|
+
|
|
249
|
+
if (primitiveNamesDeclared.length === 0) {
|
|
250
|
+
console.log(
|
|
251
|
+
`bads-lint-token-primitives: not applicable — ${relThemePath} declares no --color-* primitive (no numbered ramp step, no named primitive matching ${[...STOCK_TAILWIND_FAMILIES, ...extraFamilies].length} known families / ${[...DEFAULT_NAMED_SINGLETONS, ...extraNames].length} known names). This check has nothing to say about a theme with no primitive layer underneath its tokens — see this file's SCOPE note. Pass --families/--names to extend the known lists if this fork does have one under different names.`,
|
|
252
|
+
);
|
|
253
|
+
process.exit(0);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const semanticNames = colorNames.filter((n) => !isPrimitiveName(n));
|
|
257
|
+
|
|
258
|
+
const violations = [];
|
|
259
|
+
let skipped = 0;
|
|
260
|
+
for (const name of semanticNames) {
|
|
261
|
+
for (const mode of ["light", "dark"]) {
|
|
262
|
+
const result = classify(name, mode, { light: LIGHT, dark: DARK, lookup, isPrimitiveName });
|
|
263
|
+
if (result.kind === "resolves-to-primitive" || result.kind === "primitive-literal") continue;
|
|
264
|
+
if (result.kind === "hardcoded-literal" && hasEscapeHatch(result.startDecl)) {
|
|
265
|
+
skipped++;
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
violations.push({ name, mode, ...result });
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// A primitive is a single fixed value, never a light/dark pair — giving it
|
|
273
|
+
// two secretly makes it behave like a semantic token, which is exactly the
|
|
274
|
+
// bug this file exists to catch one layer up. Only checked when a dark
|
|
275
|
+
// block was actually found.
|
|
276
|
+
if (darkSelectorUsed) {
|
|
277
|
+
for (const name of DARK.keys()) {
|
|
278
|
+
if (!name.startsWith("color-") || !isPrimitiveName(name)) continue;
|
|
279
|
+
const decl = DARK.get(name);
|
|
280
|
+
if (hasEscapeHatch(decl)) {
|
|
281
|
+
skipped++;
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
violations.push({ name, mode: "dark", kind: "primitive-redeclared-in-dark-mode", value: decl.value, chain: [name], startDecl: decl });
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const findings = violations.map((v) => ({
|
|
289
|
+
file: relThemePath,
|
|
290
|
+
line: v.startDecl?.line,
|
|
291
|
+
text: `--${v.name} [${v.mode}, ${v.kind}] ${v.value ?? ""} (chain: ${v.chain.join(" -> ")})`.trimEnd(),
|
|
292
|
+
}));
|
|
293
|
+
|
|
294
|
+
process.exit(
|
|
295
|
+
finishCountedLint({
|
|
296
|
+
ruleId: "token-primitives",
|
|
297
|
+
bin: "bads-lint-token-primitives",
|
|
298
|
+
findings,
|
|
299
|
+
scanned: [relThemePath],
|
|
300
|
+
fix: "Point the token at the real primitive it should alias (`var(--color-<family>-<step>)` or `var(--color-<name>)`) instead of a hardcoded hex/rgb/oklch value, or add `/* allow-literal-color: <reason> */` on the line above if the literal is deliberate.",
|
|
301
|
+
argv,
|
|
302
|
+
root: ROOT,
|
|
303
|
+
}),
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (isMain(import.meta.url)) run();
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* on-system-score: what share of your styling decisions use the design system.
|
|
4
|
+
*
|
|
5
|
+
* bads-on-system score the default roots (app, components, src)
|
|
6
|
+
* bads-on-system prototypes/foo score one folder or file
|
|
7
|
+
* bads-on-system --list also print every off-system decision with file:line
|
|
8
|
+
* bads-on-system --json machine-readable, for a dashboard or a CI summary
|
|
9
|
+
* bads-on-system --min 90 exit 1 when the overall score is below 90
|
|
10
|
+
*
|
|
11
|
+
* Counts color, spacing, type, radius and shadow. What counts as on or off, and what this cannot see, is written at
|
|
12
|
+
* the top of scripts/lib/on-system.mjs. It is a trend and a pointer to the files worth opening, not a verdict:
|
|
13
|
+
* informational by default, and only a gate if you pass --min. Escape hatch: `allow-off-system: <reason>` on the
|
|
14
|
+
* line, or the line above.
|
|
15
|
+
*
|
|
16
|
+
* It reads the source, so point it at product code (a screen, a prototype, an app folder), not at the design
|
|
17
|
+
* system's own primitives, which are where the tokens are applied in the first place.
|
|
18
|
+
*/
|
|
19
|
+
import fs from "node:fs";
|
|
20
|
+
import path from "node:path";
|
|
21
|
+
|
|
22
|
+
import scanRootsLib from "./lib/scan-roots.cjs";
|
|
23
|
+
import { CATEGORIES, addCounts, overall, percent, scoreSource } from "./lib/on-system.mjs";
|
|
24
|
+
|
|
25
|
+
const { resolveScanFiles, guardEmptyScan } = scanRootsLib;
|
|
26
|
+
|
|
27
|
+
const ROOT = process.cwd();
|
|
28
|
+
const argv = process.argv.slice(2);
|
|
29
|
+
const flag = (name) => argv.includes(name);
|
|
30
|
+
const valueOf = (name) => {
|
|
31
|
+
const i = argv.indexOf(name);
|
|
32
|
+
return i === -1 ? null : argv[i + 1];
|
|
33
|
+
};
|
|
34
|
+
const min = valueOf("--min") === null ? null : Number(valueOf("--min"));
|
|
35
|
+
const top = Number(valueOf("--top") ?? 5);
|
|
36
|
+
// A value after --min / --top is not a path.
|
|
37
|
+
const pathArgs = argv.filter((a, i) => !a.startsWith("--") && !["--min", "--top"].includes(argv[i - 1]));
|
|
38
|
+
|
|
39
|
+
const scan = resolveScanFiles({ root: ROOT, argv: pathArgs, excludeStories: true, allowDirArgs: true });
|
|
40
|
+
guardEmptyScan(scan, "on-system-score");
|
|
41
|
+
// UI files only: a server route or a data module is not a styling decision, and its color strings would read as one.
|
|
42
|
+
const files = scan.files.filter((f) => /\.(tsx|jsx)$/.test(f) && !/\.(test|spec)\./.test(f));
|
|
43
|
+
|
|
44
|
+
const total = Object.fromEntries(CATEGORIES.map((c) => [c, { on: 0, off: 0 }]));
|
|
45
|
+
const perFile = [];
|
|
46
|
+
for (const file of files) {
|
|
47
|
+
const { counts, offenders } = scoreSource(fs.readFileSync(file, "utf8"));
|
|
48
|
+
addCounts(total, counts);
|
|
49
|
+
const o = overall(counts);
|
|
50
|
+
if (o.on + o.off > 0) perFile.push({ file: path.relative(ROOT, file), ...o, offenders });
|
|
51
|
+
}
|
|
52
|
+
const all = overall(total);
|
|
53
|
+
|
|
54
|
+
if (flag("--json")) {
|
|
55
|
+
console.log(
|
|
56
|
+
JSON.stringify(
|
|
57
|
+
{
|
|
58
|
+
percent: all.percent,
|
|
59
|
+
decisions: all.on + all.off,
|
|
60
|
+
off: all.off,
|
|
61
|
+
categories: Object.fromEntries(CATEGORIES.map((c) => [c, { ...total[c], percent: percent(total[c]) }])),
|
|
62
|
+
files: perFile.map(({ file, percent: p, on, off, offenders }) => ({ file, percent: p, on, off, offenders })),
|
|
63
|
+
},
|
|
64
|
+
null,
|
|
65
|
+
2,
|
|
66
|
+
),
|
|
67
|
+
);
|
|
68
|
+
} else {
|
|
69
|
+
if (all.percent === null) {
|
|
70
|
+
console.log(`on-system: no styling decisions found in ${files.length} file(s).`);
|
|
71
|
+
process.exit(0);
|
|
72
|
+
}
|
|
73
|
+
const bar = (p) => (p === null ? " n/a" : `${String(p.toFixed(1)).padStart(5)}%`);
|
|
74
|
+
console.log(`On system: ${all.percent.toFixed(1)}% (${all.on.toLocaleString()} of ${(all.on + all.off).toLocaleString()} styling decisions, ${files.length} files)\n`);
|
|
75
|
+
for (const c of CATEGORIES) {
|
|
76
|
+
const t = total[c];
|
|
77
|
+
console.log(` ${c.padEnd(8)} ${bar(percent(t))} ${t.on}/${t.on + t.off}${t.off ? ` (${t.off} off)` : ""}`);
|
|
78
|
+
}
|
|
79
|
+
const worst = perFile.filter((f) => f.off > 0).sort((a, b) => b.off - a.off || a.percent - b.percent).slice(0, top);
|
|
80
|
+
if (worst.length) {
|
|
81
|
+
console.log(`\nMost off-system:`);
|
|
82
|
+
for (const f of worst) console.log(` ${f.file} ${f.percent.toFixed(1)}% (${f.off} off)`);
|
|
83
|
+
}
|
|
84
|
+
if (flag("--list")) {
|
|
85
|
+
console.log(`\nEvery off-system decision:`);
|
|
86
|
+
for (const f of perFile) for (const o of f.offenders) console.log(` ${f.file}:${o.line} [${o.category}] ${o.what}`);
|
|
87
|
+
} else if (all.off) {
|
|
88
|
+
console.log(`\nRun with --list to see each one.`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (min !== null && all.percent !== null && all.percent < min) {
|
|
93
|
+
console.error(`\n✗ on-system: ${all.percent.toFixed(1)}% is below the --min of ${min}%.`);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
package/scripts/size-audit.cjs
CHANGED
|
@@ -63,7 +63,7 @@ const ESCAPE_HATCH = /allow-text-xs-cta/;
|
|
|
63
63
|
|
|
64
64
|
// ── BADS-2b: a full-width <Button> below the 44px touch-target floor ─────────
|
|
65
65
|
//
|
|
66
|
-
//
|
|
66
|
+
// AGENTS.md calls 44px non-negotiable (SC 2.5.5) and then documents Button's
|
|
67
67
|
// `default` (h-9, 36px) and `lg` (h-10, 40px) as exceptions reserved for dense
|
|
68
68
|
// NON-CTA chrome: toolbars, table row actions, dialog footers. Sir's call on
|
|
69
69
|
// 2026-09-11 was to keep those sizes and enforce the contract instead, because
|
|
@@ -72,7 +72,7 @@ const ESCAPE_HATCH = /allow-text-xs-cta/;
|
|
|
72
72
|
//
|
|
73
73
|
// So the question is how to tell a CTA from chrome, statically, without crying
|
|
74
74
|
// wolf — a false BLOCKER sends someone to fix a correct component and teaches
|
|
75
|
-
// people to bypass the gate (
|
|
75
|
+
// people to bypass the gate (docs/agent-rules/ask-what-a-passing-check-measured.md).
|
|
76
76
|
//
|
|
77
77
|
// `w-full` is the signal with no honest counter-example. Dense chrome is never
|
|
78
78
|
// full-width: a toolbar button sits in a row of them, a table row action is
|
package/scripts/slop-rules.mjs
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* `test` is per-line, so a caller splits source on newlines and applies it.
|
|
25
25
|
*/
|
|
26
26
|
// Decorative-emoji set (BADS-SLOP-5). Lives here because only the rules use it.
|
|
27
|
-
const SLOP_EMOJI = /[\u{1F680}\u{2728}\u{26A1}\u{1F389}\u{1F525}\u{1F4A1}\u{1F3AF}\u{1F31F}\u{1F6A8}\u{1F4AA}\u{1F44B}\u{1F984}\u{1F4A5}\u{1F60D}]/u;
|
|
27
|
+
export const SLOP_EMOJI = /[\u{1F680}\u{2728}\u{26A1}\u{1F389}\u{1F525}\u{1F4A1}\u{1F3AF}\u{1F31F}\u{1F6A8}\u{1F4AA}\u{1F44B}\u{1F984}\u{1F4A5}\u{1F60D}]/u;
|
|
28
28
|
|
|
29
29
|
export const RULES = [
|
|
30
30
|
{
|