@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,25 @@
|
|
|
1
|
+
export const REQUIRED_HEADINGS: string[]
|
|
2
|
+
export function slugify(text: string): string
|
|
3
|
+
export function parseFrontMatter(source: string): { data: Record<string, string>; body: string }
|
|
4
|
+
export interface SpecHeading { level: number; title: string; slug: string; line: number }
|
|
5
|
+
export function parseHeadings(body: string): SpecHeading[]
|
|
6
|
+
export function sectionText(body: string, title: string): string | null
|
|
7
|
+
export function parseTable(text: string): Record<string, string>[]
|
|
8
|
+
export interface InventoryRow {
|
|
9
|
+
element: string
|
|
10
|
+
source: string
|
|
11
|
+
built: "yes" | "deferred" | "dropped" | "unmarked"
|
|
12
|
+
notes: string
|
|
13
|
+
view: string | null
|
|
14
|
+
approvedBy: string | null
|
|
15
|
+
approvedOn: string | null
|
|
16
|
+
}
|
|
17
|
+
export interface SpecAnalysis {
|
|
18
|
+
frontMatter: Record<string, string>
|
|
19
|
+
headings: SpecHeading[]
|
|
20
|
+
inventory: InventoryRow[]
|
|
21
|
+
questions: { text: string; owner: string | null }[]
|
|
22
|
+
problems: string[]
|
|
23
|
+
}
|
|
24
|
+
export function analyzeSpec(source: string): SpecAnalysis
|
|
25
|
+
export function linkInventoryViews(body: string): string
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prototype spec parser. One source for the rules that read `spec.md`:
|
|
3
|
+
* the `bads-check-spec` gate (Node) and the canvas Spec frame (React, through
|
|
4
|
+
* `src/lib/spec-parse.ts`). Plain ESM with no dependencies so both can import it.
|
|
5
|
+
*
|
|
6
|
+
* A spec is markdown with a small front matter block and fixed `##` headings.
|
|
7
|
+
* See templates/prototype-repo/spec.template.md.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export const REQUIRED_HEADINGS = [
|
|
11
|
+
"Audience and problem",
|
|
12
|
+
"What it does",
|
|
13
|
+
"Element inventory",
|
|
14
|
+
"States",
|
|
15
|
+
"Decisions",
|
|
16
|
+
"Open questions",
|
|
17
|
+
"Out of scope",
|
|
18
|
+
"Handoff",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
const BUILT_VALUES = new Set(["yes", "deferred", "dropped"])
|
|
22
|
+
const APPROVER = /approved by\s+([^\s<][^\n]*?)\s+on\s+(\d{4}-\d{2}-\d{2})/i
|
|
23
|
+
const PLACEHOLDER = /<[A-Za-z][^>\n]*>/
|
|
24
|
+
|
|
25
|
+
/** Heading text to an anchor id. GitHub-style: lowercase, words joined by hyphens. */
|
|
26
|
+
export function slugify(text) {
|
|
27
|
+
return String(text)
|
|
28
|
+
.toLowerCase()
|
|
29
|
+
.replace(/[`*_~]/g, "")
|
|
30
|
+
.replace(/[^a-z0-9\s-]/g, "")
|
|
31
|
+
.trim()
|
|
32
|
+
.replace(/\s+/g, "-")
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Split a leading `---` block into key/value pairs. Values are plain strings. */
|
|
36
|
+
export function parseFrontMatter(source) {
|
|
37
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/.exec(source)
|
|
38
|
+
if (!match) return { data: {}, body: source }
|
|
39
|
+
const data = {}
|
|
40
|
+
for (const line of match[1].split(/\r?\n/)) {
|
|
41
|
+
const kv = /^([A-Za-z][\w-]*)\s*:\s*(.*)$/.exec(line)
|
|
42
|
+
if (kv) data[kv[1]] = kv[2].trim()
|
|
43
|
+
}
|
|
44
|
+
return { data, body: source.slice(match[0].length) }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function stripComments(text) {
|
|
48
|
+
return text.replace(/<!--[\s\S]*?-->/g, "")
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Level 1 to 6 headings outside code fences, in order. */
|
|
52
|
+
export function parseHeadings(body) {
|
|
53
|
+
const out = []
|
|
54
|
+
let fenced = false
|
|
55
|
+
body.split(/\r?\n/).forEach((line, index) => {
|
|
56
|
+
if (/^\s*```/.test(line)) fenced = !fenced
|
|
57
|
+
if (fenced) return
|
|
58
|
+
const m = /^(#{1,6})\s+(.+?)\s*#*\s*$/.exec(line)
|
|
59
|
+
if (m) out.push({ level: m[1].length, title: m[2], slug: slugify(m[2]), line: index })
|
|
60
|
+
})
|
|
61
|
+
return out
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The text under a `##` heading, up to the next `##` or `#`. Null when absent. */
|
|
65
|
+
export function sectionText(body, title) {
|
|
66
|
+
const lines = body.split(/\r?\n/)
|
|
67
|
+
const heads = parseHeadings(body).filter((h) => h.level <= 2)
|
|
68
|
+
const at = heads.findIndex((h) => h.level === 2 && h.title.toLowerCase() === title.toLowerCase())
|
|
69
|
+
if (at === -1) return null
|
|
70
|
+
const end = heads[at + 1] ? heads[at + 1].line : lines.length
|
|
71
|
+
return lines.slice(heads[at].line + 1, end).join("\n")
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** GitHub-flavored table to rows of objects keyed by lowercase header. */
|
|
75
|
+
export function parseTable(text) {
|
|
76
|
+
const rows = text
|
|
77
|
+
.split(/\r?\n/)
|
|
78
|
+
.filter((l) => l.trim().startsWith("|"))
|
|
79
|
+
.map((l) => l.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").map((c) => c.trim()))
|
|
80
|
+
if (rows.length < 2) return []
|
|
81
|
+
const header = rows[0].map((h) => h.toLowerCase())
|
|
82
|
+
return rows
|
|
83
|
+
.slice(2)
|
|
84
|
+
.map((cells) => Object.fromEntries(header.map((h, i) => [h, cells[i] ?? ""])))
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function bullets(text) {
|
|
88
|
+
return text
|
|
89
|
+
.split(/\r?\n/)
|
|
90
|
+
.map((l) => /^\s*[-*]\s+(.*)$/.exec(l))
|
|
91
|
+
.filter(Boolean)
|
|
92
|
+
.map((m) => m[1].trim())
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Read a spec and report what is wrong with it. `problems` lists every defect;
|
|
97
|
+
* the gate treats them as errors only for a prototype at review or later.
|
|
98
|
+
*/
|
|
99
|
+
export function analyzeSpec(source) {
|
|
100
|
+
const { data, body: raw } = parseFrontMatter(source)
|
|
101
|
+
const body = stripComments(raw)
|
|
102
|
+
const problems = []
|
|
103
|
+
|
|
104
|
+
for (const key of ["prototype", "path"]) {
|
|
105
|
+
if (!data[key]) problems.push(`front matter is missing \`${key}\``)
|
|
106
|
+
else if (PLACEHOLDER.test(data[key])) problems.push(`front matter \`${key}\` is still a placeholder`)
|
|
107
|
+
}
|
|
108
|
+
if (data.path && !["A", "B"].includes(data.path)) problems.push("front matter `path` must be A or B")
|
|
109
|
+
|
|
110
|
+
const headings = parseHeadings(body)
|
|
111
|
+
for (const title of REQUIRED_HEADINGS) {
|
|
112
|
+
if (!headings.some((h) => h.level === 2 && h.title.toLowerCase() === title.toLowerCase())) {
|
|
113
|
+
problems.push(`missing the \`## ${title}\` section`)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const inventoryText = sectionText(body, "Element inventory") ?? ""
|
|
118
|
+
const inventory = parseTable(inventoryText).map((row) => {
|
|
119
|
+
const built = (row.built ?? "").toLowerCase()
|
|
120
|
+
const approver = APPROVER.exec(row.notes ?? "")
|
|
121
|
+
return {
|
|
122
|
+
element: row.element ?? "",
|
|
123
|
+
source: row.source ?? "",
|
|
124
|
+
built: BUILT_VALUES.has(built) ? built : "unmarked",
|
|
125
|
+
notes: row.notes ?? "",
|
|
126
|
+
view: row.view || null,
|
|
127
|
+
approvedBy: approver ? approver[1] : null,
|
|
128
|
+
approvedOn: approver ? approver[2] : null,
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
if (inventory.length === 0 && sectionText(body, "Element inventory") !== null) {
|
|
132
|
+
problems.push("the element inventory has no rows")
|
|
133
|
+
}
|
|
134
|
+
for (const row of inventory) {
|
|
135
|
+
const label = row.element || "(blank element)"
|
|
136
|
+
if (row.built === "unmarked") problems.push(`inventory row "${label}" is not marked yes, deferred, or dropped`)
|
|
137
|
+
if ((row.built === "deferred" || row.built === "dropped") && !row.approvedBy) {
|
|
138
|
+
problems.push(`inventory row "${label}" is ${row.built} but names no approver ("Approved by <name> on YYYY-MM-DD")`)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const questionsText = sectionText(body, "Open questions") ?? ""
|
|
143
|
+
const questions = bullets(questionsText)
|
|
144
|
+
.filter((q) => !/^none\.?$/i.test(q))
|
|
145
|
+
.map((q) => {
|
|
146
|
+
const m = /^([^:<][^:]{0,40}):\s+(\S.*)$/.exec(q)
|
|
147
|
+
return { text: q, owner: m ? m[1].trim() : null }
|
|
148
|
+
})
|
|
149
|
+
for (const q of questions) {
|
|
150
|
+
if (!q.owner) problems.push(`open question has no owner: "${q.text}"`)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return { frontMatter: data, headings, inventory, questions, problems }
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Turn each name in the inventory's `View` column into a `frame:` link, so the
|
|
158
|
+
* rendered Spec frame can pan the canvas to that frame. Leaves every other part of
|
|
159
|
+
* the markdown untouched. Rows with an empty View cell stay plain.
|
|
160
|
+
*/
|
|
161
|
+
export function linkInventoryViews(body) {
|
|
162
|
+
const lines = body.split(/\r?\n/)
|
|
163
|
+
const heads = parseHeadings(body).filter((h) => h.level <= 2)
|
|
164
|
+
const at = heads.findIndex((h) => h.level === 2 && h.title.toLowerCase() === "element inventory")
|
|
165
|
+
if (at === -1) return body
|
|
166
|
+
const end = heads[at + 1] ? heads[at + 1].line : lines.length
|
|
167
|
+
let viewCol = -1
|
|
168
|
+
let seenSeparator = false
|
|
169
|
+
for (let i = heads[at].line + 1; i < end; i++) {
|
|
170
|
+
const line = lines[i]
|
|
171
|
+
if (!line.trim().startsWith("|")) continue
|
|
172
|
+
const cells = line.trim().replace(/^\|/, "").replace(/\|$/, "").split("|")
|
|
173
|
+
if (viewCol === -1 && !seenSeparator) {
|
|
174
|
+
viewCol = cells.findIndex((c) => c.trim().toLowerCase() === "view")
|
|
175
|
+
continue
|
|
176
|
+
}
|
|
177
|
+
if (!seenSeparator) {
|
|
178
|
+
seenSeparator = true
|
|
179
|
+
continue
|
|
180
|
+
}
|
|
181
|
+
if (viewCol === -1 || viewCol >= cells.length) continue
|
|
182
|
+
const name = cells[viewCol].trim()
|
|
183
|
+
if (!name || name.startsWith("[")) continue
|
|
184
|
+
cells[viewCol] = ` [${name}](frame:${name}) `
|
|
185
|
+
lines[i] = "|" + cells.join("|") + "|"
|
|
186
|
+
}
|
|
187
|
+
return lines.join("\n")
|
|
188
|
+
}
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rendered "tells": the signals that a page was generated, read from computed
|
|
3
|
+
* styles in a real browser at several widths. lint-slop reads source text; this
|
|
4
|
+
* reads what paints, so it sees classes composed at runtime and the effect of the
|
|
5
|
+
* cascade. The registry's shape (dated, banned or warned) and the idea of
|
|
6
|
+
* checking the rendered page at several widths are from Leonxlnx/taste-skill (MIT);
|
|
7
|
+
* the rules are chosen to fit BADS's own registers and real-content rule.
|
|
8
|
+
*
|
|
9
|
+
* The four LAYOUT tells (BADS-TELL-12 to 15) adapt measurements from the render tier of nutlope/hallmark
|
|
10
|
+
* (MIT, gates 71, 72, 73 and 49): a heading nearer what precedes it than what it heads, text crowding the edge
|
|
11
|
+
* of its box, text painted under another element, and a button label that wraps or is clipped. BADS already
|
|
12
|
+
* wrote three of those as rules with no lint behind them (proximity-and-grouping, even-padding, and the
|
|
13
|
+
* label-fit rule that docs/agent-rules/button-label-fit.md said could not be linted). Thresholds are Hallmark's, kept until they are
|
|
14
|
+
* re-measured against BADS's own pages. All four start as `warned`.
|
|
15
|
+
*
|
|
16
|
+
* Two parts, kept apart so the logic is testable without a browser:
|
|
17
|
+
* probe() runs INSIDE the page and returns plain facts. Self-contained.
|
|
18
|
+
* classify() turns those facts into findings. Pure.
|
|
19
|
+
*
|
|
20
|
+
* What it does not flag, by design: eyebrow labels (sanctioned by the CTA size
|
|
21
|
+
* contract), editorial serif emphasis, and the terminal register. They are
|
|
22
|
+
* chosen design in BADS, as lint-slop's header explains.
|
|
23
|
+
*/
|
|
24
|
+
import { SLOP_EMOJI } from "../slop-rules.mjs";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 320 is WCAG 1.4.10 Reflow (AA, so inside BADS's AAA floor): the width a 1280px window reaches at 400% zoom. Agents
|
|
28
|
+
* and screenshot pipelines default to about 390px, so 320 is the state that goes unrendered. The horizontal-overflow
|
|
29
|
+
* tell runs at every width, so adding 320 here is what makes it a reflow check.
|
|
30
|
+
*/
|
|
31
|
+
export const WIDTHS = [320, 375, 768, 1280];
|
|
32
|
+
|
|
33
|
+
/** code, name, status (banned fails the run; warned is reported), and why. */
|
|
34
|
+
export const TELLS = [
|
|
35
|
+
{ code: "BADS-TELL-1", name: "gradient-text", status: "banned", why: "Gradient-filled headline text. Carries no information. Use a solid foreground token." },
|
|
36
|
+
{ code: "BADS-TELL-2", name: "indigo-violet-gradient", status: "banned", why: "An indigo or violet gradient on a large surface or a button. The default machine palette." },
|
|
37
|
+
{ code: "BADS-TELL-3", name: "glass-panels", status: "warned", why: "Two or more translucent panels with backdrop blur. Use opaque surfaces one tone step from the ground." },
|
|
38
|
+
{ code: "BADS-TELL-4", name: "glow", status: "warned", why: "A box-shadow with a blur of 40px or more. Use a tone step, or no shadow." },
|
|
39
|
+
{ code: "BADS-TELL-5", name: "three-up-icon-cards", status: "warned", why: "Three equal cards in a row, each with a small icon and a heading. The stock feature row." },
|
|
40
|
+
{ code: "BADS-TELL-6", name: "pill-above-headline", status: "warned", why: "A small pill badge directly above the page headline ('New', 'Beta'). Say it in the supporting sentence." },
|
|
41
|
+
{ code: "BADS-TELL-7", name: "decorative-emoji", status: "banned", why: "Decorative emoji in page copy. Use words or a real picture." },
|
|
42
|
+
{ code: "BADS-TELL-8", name: "pulsing-status-dot", status: "warned", why: "A small dot that pulses forever with no live state behind it." },
|
|
43
|
+
{ code: "BADS-TELL-9", name: "placeholder-copy", status: "banned", why: "Placeholder text (Lorem ipsum, Jane Doe, Acme Inc., 555 numbers). The real-content rule: pull from content/personas/<brand>.json." },
|
|
44
|
+
{ code: "BADS-TELL-10", name: "placeholder-image", status: "banned", why: "An image from a placeholder service. Show the real product or a real picture of the client's world (bads-source-images)." },
|
|
45
|
+
{ code: "BADS-TELL-11", name: "horizontal-overflow", status: "banned", why: "The page scrolls sideways at this width. Fix the layout, not the rhythm." },
|
|
46
|
+
{ code: "BADS-TELL-12", name: "crowded-heading", status: "warned", why: "Two or more headings sit nearer the content above them than the content they head. Space above a heading should be at least twice the space below it (layer-6 proximity-and-grouping)." },
|
|
47
|
+
{ code: "BADS-TELL-13", name: "cramped-box", status: "warned", why: "Text sits closer to the edge of its filled or bordered box than max(8px, 0.5em) at the sides or max(4px, 0.3em) above and below (layer-6 even-padding)." },
|
|
48
|
+
{ code: "BADS-TELL-14", name: "covered-text", status: "warned", why: "Text is painted under another element, so part of it cannot be read or clicked. Give it its own space (corrections #001)." },
|
|
49
|
+
{ code: "BADS-TELL-15", name: "wrapped-button-label", status: "warned", why: "A button label wraps to a second line or is clipped at this width. The label does not fit its container: shorten it, widen the button, or accept the wrap for a dynamic label (CLAUDE.md, Button label fit)." },
|
|
50
|
+
{ code: "BADS-TELL-16", name: "zoom-blocked", status: "banned", why: "The viewport meta tag stops people zooming (user-scalable=no, or maximum-scale below 2). Zoom is how a low-vision user reaches the 320px reflow state, and blocking it fails WCAG 1.4.4 and 1.4.10." },
|
|
51
|
+
{ code: "BADS-TELL-17", name: "unreachable-scroll-region", status: "warned", why: "A region that scrolls sideways cannot be reached by keyboard, or has no role and name. Give it tabindex=0, role=region and an aria-label so a keyboard or screen reader user can find and scroll it (WCAG 1.4.10 table pattern)." },
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
/** Runs in the browser. Returns plain, serializable facts. Must not reference anything outside itself. */
|
|
55
|
+
export function probe() {
|
|
56
|
+
const MAX = 4000;
|
|
57
|
+
const facts = { gradientText: [], gradients: [], glass: [], glow: [], cards: [], pills: [], emoji: [], pulse: [], copy: [], images: [], overflow: null };
|
|
58
|
+
const px = (v) => parseFloat(v) || 0;
|
|
59
|
+
const label = (el) => (el.tagName.toLowerCase() + (el.id ? "#" + el.id : "") + (typeof el.className === "string" && el.className.trim() ? "." + el.className.trim().split(/\s+/).slice(0, 2).join(".") : "")).slice(0, 80);
|
|
60
|
+
const canvas = document.createElement("canvas");
|
|
61
|
+
canvas.width = canvas.height = 1;
|
|
62
|
+
const cx = canvas.getContext("2d", { willReadFrequently: true });
|
|
63
|
+
const toRgb = (css) => { try { cx.clearRect(0, 0, 1, 1); cx.fillStyle = "#000"; cx.fillStyle = css; cx.fillRect(0, 0, 1, 1); const d = cx.getImageData(0, 0, 1, 1).data; return [d[0], d[1], d[2], d[3] / 255]; } catch { return null; } };
|
|
64
|
+
const hsl = ([r, g, b]) => { r /= 255; g /= 255; b /= 255; const mx = Math.max(r, g, b), mn = Math.min(r, g, b), l = (mx + mn) / 2, d = mx - mn; if (!d) return [0, 0, l]; const s = d / (1 - Math.abs(2 * l - 1)); const h = mx === r ? ((g - b) / d) % 6 : mx === g ? (b - r) / d + 2 : (r - g) / d + 4; return [(h * 60 + 360) % 360, s, l]; };
|
|
65
|
+
const COLOR = /(?:rgba?|hsla?|oklch|oklab|lab|lch|color)\([^)]*\)/g;
|
|
66
|
+
const vw = innerWidth, vh = innerHeight;
|
|
67
|
+
const els = [...document.body.querySelectorAll("*")].slice(0, MAX);
|
|
68
|
+
const visible = (el, r, cs) => r.width > 0 && r.height > 0 && cs.visibility !== "hidden" && cs.display !== "none" && cs.opacity !== "0";
|
|
69
|
+
|
|
70
|
+
for (const el of els) {
|
|
71
|
+
const cs = getComputedStyle(el), r = el.getBoundingClientRect();
|
|
72
|
+
if (!visible(el, r, cs)) continue;
|
|
73
|
+
if (/text/.test(cs.webkitBackgroundClip || cs.backgroundClip) && /gradient/.test(cs.backgroundImage) && (cs.webkitTextFillColor === "rgba(0, 0, 0, 0)" || cs.color === "rgba(0, 0, 0, 0)") && el.textContent.trim()) facts.gradientText.push({ el: label(el), text: el.textContent.trim().slice(0, 40) });
|
|
74
|
+
if (/gradient/.test(cs.backgroundImage) && !/text/.test(cs.webkitBackgroundClip || cs.backgroundClip)) {
|
|
75
|
+
const area = (r.width * r.height) / (vw * vh), isButton = el.matches("button, a, [role=button]");
|
|
76
|
+
if (area > 0.15 || isButton) {
|
|
77
|
+
const stops = (cs.backgroundImage.match(COLOR) || []).map(toRgb).filter((c) => c && c[3] > 0.3).map(hsl);
|
|
78
|
+
const violet = stops.filter(([h, s, l]) => h >= 235 && h <= 300 && s >= 0.4 && l > 0.15 && l < 0.85);
|
|
79
|
+
if (violet.length >= 2 || (violet.length >= 1 && stops.length <= 2 && violet.length === stops.length)) facts.gradients.push({ el: label(el), stops: stops.length });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (/blur/.test(cs.backdropFilter || cs.webkitBackdropFilter || "")) { const bg = toRgb(cs.backgroundColor); if (bg && bg[3] > 0 && bg[3] < 0.95) facts.glass.push({ el: label(el) }); }
|
|
83
|
+
for (const sh of (cs.boxShadow || "").split(/,(?![^(]*\))/)) { const nums = (sh.replace(COLOR, "").match(/-?\d*\.?\d+px/g) || []).map(px); if (nums.length >= 3 && nums[2] >= 40 && sh.trim() !== "none") { facts.glow.push({ el: label(el), blur: nums[2] }); break; } }
|
|
84
|
+
if (cs.animationName !== "none" && cs.animationIterationCount === "infinite" && r.width <= 14 && r.height <= 14 && px(cs.borderTopLeftRadius) >= r.width / 2 - 1) facts.pulse.push({ el: label(el) });
|
|
85
|
+
if (el.tagName === "IMG" && /picsum\.photos|placehold\.|placeholder\.com|dummyimage|lorempixel|via\.placeholder|placekitten|loremflickr/i.test(el.currentSrc || el.src)) facts.images.push({ el: label(el), src: (el.currentSrc || el.src).slice(0, 80) });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Three equal cards, each with a small icon and a heading.
|
|
89
|
+
for (const parent of els) {
|
|
90
|
+
const kids = [...parent.children].filter((k) => { const r = k.getBoundingClientRect(); return r.width > 80 && r.height > 60; });
|
|
91
|
+
if (kids.length !== 3) continue;
|
|
92
|
+
const rs = kids.map((k) => k.getBoundingClientRect());
|
|
93
|
+
if (!(Math.abs(rs[0].width - rs[1].width) < 3 && Math.abs(rs[1].width - rs[2].width) < 3 && Math.abs(rs[0].top - rs[2].top) < 3)) continue;
|
|
94
|
+
const small = (k) => [...k.querySelectorAll("svg, img")].some((i) => { const b = i.getBoundingClientRect(); return b.width > 0 && b.width <= 64 && b.height <= 64; });
|
|
95
|
+
if (kids.every((k) => small(k) && k.querySelector("h2, h3, h4, strong"))) facts.cards.push({ el: label(parent) });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// A small pill directly before the first h1.
|
|
99
|
+
const h1 = document.querySelector("h1");
|
|
100
|
+
if (h1) for (let el = h1.previousElementSibling; el; el = null) { const cs = getComputedStyle(el), r = el.getBoundingClientRect(); if (r.height > 0 && r.height <= 36 && px(cs.fontSize) <= 14 && px(cs.borderTopLeftRadius) >= r.height / 2 - 1 && el.textContent.trim().length <= 24) facts.pills.push({ text: el.textContent.trim() }); }
|
|
101
|
+
|
|
102
|
+
const text = document.body.innerText || "";
|
|
103
|
+
const emo = text.match(new RegExp(EMOJI_SOURCE, "gu"));
|
|
104
|
+
if (emo) facts.emoji = [...new Set(emo)];
|
|
105
|
+
const ph = text.match(/lorem ipsum|dolor sit amet|\bjane doe\b|\bjohn doe\b|acme inc|123 main st|555[-. ]?555/gi);
|
|
106
|
+
if (ph) facts.copy = [...new Set(ph.map((s) => s.toLowerCase()))];
|
|
107
|
+
facts.overflow = { scrollWidth: document.documentElement.scrollWidth, innerWidth: vw };
|
|
108
|
+
// The viewport meta tag must not block zoom: ACT rule b4f0c3, and the precondition for testing reflow at all.
|
|
109
|
+
const vp = document.querySelector('meta[name="viewport" i]');
|
|
110
|
+
if (vp) {
|
|
111
|
+
const c = vp.getAttribute("content") || "";
|
|
112
|
+
const scalable = /user-scalable\s*=\s*(no|0)\b/i.test(c);
|
|
113
|
+
const max = /maximum-scale\s*=\s*([\d.]+)/i.exec(c);
|
|
114
|
+
if (scalable || (max && parseFloat(max[1]) < 2)) facts.zoom = { content: c };
|
|
115
|
+
}
|
|
116
|
+
return facts;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Runs in the browser. The four layout tells (12 to 15). Async because covered text needs to scroll the page and
|
|
121
|
+
* sample what is painted at each text position. Self-contained like probe(), and it puts the scroll back.
|
|
122
|
+
*/
|
|
123
|
+
export async function probeLayout() {
|
|
124
|
+
const MAX = 4000;
|
|
125
|
+
const out = { crowded: [], cramped: [], covered: [], wrapped: [] };
|
|
126
|
+
const px = (v) => parseFloat(v) || 0;
|
|
127
|
+
const name = (el) => el.tagName.toLowerCase() + (typeof el.className === "string" && el.className.trim() ? "." + el.className.trim().split(/\s+/)[0] : "");
|
|
128
|
+
const clear = (c) => !c || c === "transparent" || /^rgba\(\s*0,\s*0,\s*0,\s*0\s*\)$/.test(c);
|
|
129
|
+
const vis = (el) => { const cs = getComputedStyle(el); if (cs.display === "none" || cs.visibility === "hidden" || px(cs.opacity) === 0) return false; const r = el.getBoundingClientRect(); return r.width > 3 && r.height > 3; };
|
|
130
|
+
const els = [...document.body.querySelectorAll("*")].slice(0, MAX);
|
|
131
|
+
const sx = scrollX, sy = scrollY;
|
|
132
|
+
const page = (r) => ({ left: r.left + sx, right: r.right + sx, top: r.top + sy, bottom: r.bottom + sy });
|
|
133
|
+
|
|
134
|
+
// 12. Crowded heading: more space below a heading than above it means it reads as belonging to what precedes it.
|
|
135
|
+
const boxes = [];
|
|
136
|
+
for (const el of els) {
|
|
137
|
+
if (!vis(el)) continue;
|
|
138
|
+
// A heading heads content. A button or link below it is an action, so it does not set the heading's spacing.
|
|
139
|
+
if (el.closest("button, a, [role='button'], input, select, textarea")) continue;
|
|
140
|
+
const media = /^(IMG|SVG|VIDEO|CANVAS|PICTURE)$/i.test(el.tagName);
|
|
141
|
+
if (!media && ![...el.childNodes].some((n) => n.nodeType === 3 && n.textContent.trim())) continue;
|
|
142
|
+
boxes.push({ el, ...page(el.getBoundingClientRect()) });
|
|
143
|
+
}
|
|
144
|
+
const overlapX = (a, b) => Math.min(a.right, b.right) - Math.max(a.left, b.left) > 8;
|
|
145
|
+
for (const h of document.querySelectorAll("h2, h3, h4")) {
|
|
146
|
+
if (!vis(h) || !(h.innerText || "").trim() || h.closest("nav, footer, table, header")) continue;
|
|
147
|
+
// A card title sits inside a small filled box; its spacing is the card's, not the page's.
|
|
148
|
+
let small = false;
|
|
149
|
+
for (let p = h.parentElement; p && p !== document.body; p = p.parentElement) {
|
|
150
|
+
const cs = getComputedStyle(p);
|
|
151
|
+
if (!clear(cs.backgroundColor) || px(cs.borderTopWidth) > 0 || cs.boxShadow !== "none") { small = p.getBoundingClientRect().height < 200; break; }
|
|
152
|
+
}
|
|
153
|
+
if (small) continue;
|
|
154
|
+
const hb = page(h.getBoundingClientRect());
|
|
155
|
+
// What a heading heads is inside its own block: the nearest section, article, list item, or filled/bordered box.
|
|
156
|
+
// Without this, a heading with nothing under it reached into the next card.
|
|
157
|
+
let scope = document.body;
|
|
158
|
+
for (let p = h.parentElement; p && p !== document.body; p = p.parentElement) {
|
|
159
|
+
const cs = getComputedStyle(p);
|
|
160
|
+
if (/^(SECTION|ARTICLE|LI|ASIDE|FIGURE)$/.test(p.tagName) || !clear(cs.backgroundColor) || px(cs.borderTopWidth) > 0 || cs.boxShadow !== "none") { scope = p; break; }
|
|
161
|
+
}
|
|
162
|
+
let above = null, below = null;
|
|
163
|
+
for (const b of boxes) {
|
|
164
|
+
if (h.contains(b.el) || b.el.contains(h) || !overlapX(b, hb)) continue;
|
|
165
|
+
if (b.bottom <= hb.top + 1 && (!above || b.bottom > above.bottom)) above = b;
|
|
166
|
+
if (b.top >= hb.bottom - 1 && scope.contains(b.el) && (!below || b.top < below.top)) below = b;
|
|
167
|
+
}
|
|
168
|
+
if (!above || !below) continue;
|
|
169
|
+
const up = hb.top - above.bottom, down = below.top - hb.bottom;
|
|
170
|
+
if (down < 6 || down > 160) continue;
|
|
171
|
+
if (up < 0.75 * down && down - up >= 12) out.crowded.push({ el: name(h), text: (h.innerText || "").trim().slice(0, 18), up: Math.round(up), down: Math.round(down) });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// 13. Cramped box: text closer to the edge of its filled or bordered box than the even-padding floor.
|
|
175
|
+
for (const el of els) {
|
|
176
|
+
const r = el.getBoundingClientRect();
|
|
177
|
+
if (r.width <= 100 || r.height <= 30 || r.width > innerWidth * 0.9) continue;
|
|
178
|
+
const cs = getComputedStyle(el);
|
|
179
|
+
if (cs.display === "inline" || /auto|scroll/.test(cs.overflowX + cs.overflowY) || !vis(el)) continue;
|
|
180
|
+
const bw = ["Top", "Right", "Bottom", "Left"].map((k) => px(cs["border" + k + "Width"]));
|
|
181
|
+
const inked = (k) => bw[k] >= 1 && !clear(cs["border" + ["Top", "Right", "Bottom", "Left"][k] + "Color"]);
|
|
182
|
+
let under = "rgb(255, 255, 255)";
|
|
183
|
+
for (let p = el.parentElement; p; p = p.parentElement) { const c = getComputedStyle(p).backgroundColor; if (!clear(c)) { under = c; break; } }
|
|
184
|
+
const filled = !clear(cs.backgroundColor) && cs.backgroundColor !== under;
|
|
185
|
+
if (!filled && !(inked(1) && inked(3))) continue;
|
|
186
|
+
let L = Infinity, T = Infinity, R = -Infinity, B = -Infinity, fs = px(cs.fontSize) || 16;
|
|
187
|
+
const walk = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);
|
|
188
|
+
for (let t = walk.nextNode(); t; t = walk.nextNode()) {
|
|
189
|
+
const host = t.parentElement;
|
|
190
|
+
if (!t.textContent.trim() || !host || host.closest("svg") || !vis(host)) continue;
|
|
191
|
+
let nested = false;
|
|
192
|
+
for (let p = host; p && p !== el; p = p.parentElement) {
|
|
193
|
+
const ps = getComputedStyle(p);
|
|
194
|
+
if (/absolute|fixed/.test(ps.position) || (!clear(ps.backgroundColor) && ps.backgroundColor !== cs.backgroundColor) || (px(ps.borderTopWidth) >= 1 && px(ps.borderLeftWidth) >= 1)) { nested = true; break; }
|
|
195
|
+
}
|
|
196
|
+
if (nested) continue;
|
|
197
|
+
const rg = document.createRange(); rg.selectNodeContents(t);
|
|
198
|
+
const hf = px(getComputedStyle(host).fontSize) || 16, trim = hf >= 40 ? 0.2 * hf : 0;
|
|
199
|
+
for (const q of rg.getClientRects()) { if (!q.width || !q.height) continue; L = Math.min(L, q.left); T = Math.min(T, q.top + trim); R = Math.max(R, q.right); B = Math.max(B, q.bottom - trim); fs = hf; }
|
|
200
|
+
}
|
|
201
|
+
if (L === Infinity) continue;
|
|
202
|
+
const side = Math.max(8, Math.min(0.5 * fs, 24)) - 0.5, end = Math.max(4, Math.min(0.3 * fs, 12)) - 0.5;
|
|
203
|
+
const inset = { left: L - (r.left + bw[3]), right: r.right - bw[1] - R, top: T - (r.top + bw[0]), bottom: r.bottom - bw[2] - B };
|
|
204
|
+
// A negative inset means the text sits OUTSIDE the box (an overflowing or scrolling container), which is an
|
|
205
|
+
// overflow matter and not a padding one; only text inside the box but too close counts.
|
|
206
|
+
const short = Object.entries(inset).filter(([k, v]) => v >= 0 && v < (k === "left" || k === "right" ? side : end));
|
|
207
|
+
if (short.length) out.cramped.push({ el: name(el), sides: short.map(([k, v]) => k + " " + Math.round(v) + "px").join(", ") });
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// 14. Covered text: sample what is painted at the middle of each text run, scrolling through the page.
|
|
211
|
+
const pinned = (el) => { for (let p = el; p && p !== document.body; p = p.parentElement) if (/fixed|sticky/.test(getComputedStyle(p).position)) return true; return false; };
|
|
212
|
+
const unseen = (el) => { const cs = getComputedStyle(el); return px(cs.opacity) < 0.05 || (clear(cs.backgroundColor) && cs.backgroundImage === "none" && !(el.innerText || "").trim() && !/^(IMG|SVG|CANVAS|VIDEO|PICTURE)$/i.test(el.tagName) && !el.querySelector("img, svg, canvas, video")); };
|
|
213
|
+
// Text scrolled or clipped out of its own container is hidden, not covered: whatever the point lands on is the
|
|
214
|
+
// next thing on the page.
|
|
215
|
+
const clippedAt = (host, x, y) => {
|
|
216
|
+
for (let p = host; p && p !== document.body; p = p.parentElement) {
|
|
217
|
+
const ps = getComputedStyle(p);
|
|
218
|
+
if (/auto|scroll|hidden|clip/.test(ps.overflowX + ps.overflowY)) { const b = p.getBoundingClientRect(); if (x < b.left || x > b.right || y < b.top || y > b.bottom) return true; }
|
|
219
|
+
}
|
|
220
|
+
return false;
|
|
221
|
+
};
|
|
222
|
+
const paints = (el) => { const cs = getComputedStyle(el); return !clear(cs.backgroundColor) || cs.backgroundImage !== "none" || /^(IMG|SVG|CANVAS|VIDEO|PICTURE)$/i.test(el.tagName) || [...el.childNodes].some((n) => n.nodeType === 3 && n.textContent.trim()); };
|
|
223
|
+
const runs = [];
|
|
224
|
+
const tw = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
|
|
225
|
+
for (let t = tw.nextNode(); t && runs.length < 1500; t = tw.nextNode()) {
|
|
226
|
+
const host = t.parentElement;
|
|
227
|
+
if (!t.textContent.trim() || !host || host.closest("script, style, noscript, svg, [aria-hidden='true'], nav, header, dialog, [popover], [role='menu'], details:not([open]), [hidden]")) continue;
|
|
228
|
+
if (vis(host) && !pinned(host)) runs.push({ t, host });
|
|
229
|
+
}
|
|
230
|
+
const H = document.documentElement.scrollHeight;
|
|
231
|
+
for (let y = 0; y < H && out.covered.length < 3; y += Math.max(200, innerHeight - 100)) {
|
|
232
|
+
window.scrollTo(0, y);
|
|
233
|
+
await new Promise((res) => requestAnimationFrame(() => requestAnimationFrame(res)));
|
|
234
|
+
for (const { t, host } of runs) {
|
|
235
|
+
if (out.covered.length >= 3) break;
|
|
236
|
+
const rg = document.createRange(); rg.selectNodeContents(t);
|
|
237
|
+
for (const q of rg.getClientRects()) {
|
|
238
|
+
if (q.width < 6 || q.height < 6) continue;
|
|
239
|
+
const cx = q.left + q.width / 2, cy = q.top + q.height / 2;
|
|
240
|
+
if (cy < 0 || cy >= innerHeight || cx < 0 || cx >= innerWidth) continue;
|
|
241
|
+
const ghost = getComputedStyle(host).pointerEvents === "none";
|
|
242
|
+
if (ghost) host.style.setProperty("pointer-events", "auto", "important");
|
|
243
|
+
const top = document.elementFromPoint(cx, cy);
|
|
244
|
+
if (ghost) host.style.removeProperty("pointer-events");
|
|
245
|
+
if (!top || top === host || host.contains(top) || top.contains(host) || pinned(top) || unseen(top)) continue;
|
|
246
|
+
if (clippedAt(host, cx, cy)) continue;
|
|
247
|
+
// A transparent wrapper (a calendar's nav row, a click-catching layer) sits over text without painting
|
|
248
|
+
// anything there. It is covering only if something it contains paints at that point.
|
|
249
|
+
if (!paints(top)) {
|
|
250
|
+
let hit = false;
|
|
251
|
+
for (const d of top.querySelectorAll("*")) {
|
|
252
|
+
if (!paints(d)) continue;
|
|
253
|
+
const b = d.getBoundingClientRect();
|
|
254
|
+
if (cx >= b.left && cx <= b.right && cy >= b.top && cy <= b.bottom) { hit = true; break; }
|
|
255
|
+
}
|
|
256
|
+
if (!hit) continue;
|
|
257
|
+
}
|
|
258
|
+
// elementFromPoint can return an element whose own box does not contain the point (a pseudo-element or an
|
|
259
|
+
// overflowing child). Count it only if it paints something there.
|
|
260
|
+
const tr = top.getBoundingClientRect();
|
|
261
|
+
if (!(cx >= tr.left && cx <= tr.right && cy >= tr.top && cy <= tr.bottom)) {
|
|
262
|
+
const bare = (ps) => /^(none|normal)$/.test(ps.content) || (clear(ps.backgroundColor) && ps.backgroundImage === "none");
|
|
263
|
+
if (bare(getComputedStyle(top, "::after")) && bare(getComputedStyle(top, "::before"))) continue;
|
|
264
|
+
}
|
|
265
|
+
out.covered.push({ el: name(top), text: t.textContent.trim().slice(0, 16) });
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
window.scrollTo(sx, sy);
|
|
271
|
+
|
|
272
|
+
// 17. A region that scrolls sideways must be reachable by keyboard and have a role and a name. Content that
|
|
273
|
+
// needs two-dimensional layout may scroll (a table, a code block), but only inside a region a person can find.
|
|
274
|
+
out.regions = [];
|
|
275
|
+
for (const el of els) {
|
|
276
|
+
if (el === document.body || el === document.documentElement || !vis(el)) continue;
|
|
277
|
+
const cs = getComputedStyle(el);
|
|
278
|
+
if (!/auto|scroll/.test(cs.overflowX) || el.scrollWidth <= el.clientWidth + 1) continue;
|
|
279
|
+
const focusable = el.tabIndex >= 0 || !!el.querySelector("a[href], button, input, select, textarea, [tabindex]:not([tabindex='-1'])");
|
|
280
|
+
const named = !!(el.getAttribute("aria-label") || el.getAttribute("aria-labelledby"));
|
|
281
|
+
const role = el.getAttribute("role");
|
|
282
|
+
const missing = [];
|
|
283
|
+
if (!focusable) missing.push("keyboard focus (tabindex=0)");
|
|
284
|
+
// Any real role is enough (a tab list, a toolbar, a table); a bare div needs role=region. Every one needs a name.
|
|
285
|
+
const hasRole = role && !/^(none|presentation)$/i.test(role);
|
|
286
|
+
if (!hasRole) missing.push("role=region and a name");
|
|
287
|
+
else if (!named) missing.push("a name (aria-label)");
|
|
288
|
+
if (missing.length) out.regions.push({ el: name(el), missing: [...new Set(missing)].join(" and ") });
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// 15. Wrapped or clipped button label: a control whose label does not fit its container.
|
|
292
|
+
for (const el of els) {
|
|
293
|
+
const isButton = el.tagName === "BUTTON" || el.getAttribute("role") === "button" || (el.tagName === "A" && /\bbtn\b|\bbutton\b/i.test(typeof el.className === "string" ? el.className : ""));
|
|
294
|
+
if (!isButton || !vis(el)) continue;
|
|
295
|
+
const text = (el.textContent || "").trim();
|
|
296
|
+
// A label is short and flows inline. A role=button that holds paragraphs, a heading or a list (a dropzone, a
|
|
297
|
+
// card that opens) is a surface, and wrapping is what its text is supposed to do.
|
|
298
|
+
if (!text || text.length > 60) continue;
|
|
299
|
+
if ([...el.querySelectorAll("*")].some((d) => !d.closest("svg") && /^(block|flex|grid|list-item|table)$/.test(getComputedStyle(d).display))) continue;
|
|
300
|
+
const cs = getComputedStyle(el);
|
|
301
|
+
const lh = px(cs.lineHeight) || px(cs.fontSize) * 1.4;
|
|
302
|
+
const tops = [];
|
|
303
|
+
const walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);
|
|
304
|
+
for (let n = walker.nextNode(); n; n = walker.nextNode()) {
|
|
305
|
+
const host = n.parentElement;
|
|
306
|
+
if (!n.textContent.trim() || !host || host.closest("svg") || host.closest("[aria-hidden='true'], .sr-only")) continue;
|
|
307
|
+
const rg = document.createRange(); rg.selectNodeContents(n);
|
|
308
|
+
for (const q of rg.getClientRects()) if (q.width > 0 && q.height > 0) tops.push(q.top);
|
|
309
|
+
}
|
|
310
|
+
tops.sort((a, b) => a - b);
|
|
311
|
+
let lines = tops.length ? 1 : 0;
|
|
312
|
+
for (let i = 1; i < tops.length; i++) if (tops[i] - tops[i - 1] > lh * 0.6) lines++;
|
|
313
|
+
const clipped = /hidden|clip/.test(cs.overflowX) && el.scrollWidth > el.clientWidth + 1;
|
|
314
|
+
if (lines > 1 || clipped) out.wrapped.push({ el: name(el), text: text.slice(0, 32), lines, clipped });
|
|
315
|
+
}
|
|
316
|
+
return out;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// probe() is serialized into the page, so it can't import SLOP_EMOJI. The source is
|
|
320
|
+
// injected before serializing (see probeSource), keeping one definition of the set.
|
|
321
|
+
/** The source of probe() with the emoji set inlined, ready for page.evaluate. */
|
|
322
|
+
export function probeSource() {
|
|
323
|
+
return `(() => { const EMOJI_SOURCE = ${JSON.stringify(SLOP_EMOJI.source)}; return (${probe.toString()})(); })()`;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** The source of probeLayout(), ready for page.evaluate (it returns a promise). */
|
|
327
|
+
export function probeLayoutSource() {
|
|
328
|
+
return `(${probeLayout.toString()})()`;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/** Turn one width's facts into findings. Pure. */
|
|
332
|
+
export function classify(facts, width) {
|
|
333
|
+
const out = [];
|
|
334
|
+
const add = (name, detail) => { const t = TELLS.find((x) => x.name === name); out.push({ code: t.code, name, status: t.status, width, detail, why: t.why }); };
|
|
335
|
+
for (const g of facts.gradientText || []) add("gradient-text", `${g.el}: "${g.text}"`);
|
|
336
|
+
for (const g of facts.gradients || []) add("indigo-violet-gradient", g.el);
|
|
337
|
+
if ((facts.glass || []).length >= 2) add("glass-panels", `${facts.glass.length} panels, e.g. ${facts.glass[0].el}`);
|
|
338
|
+
for (const g of (facts.glow || []).slice(0, 3)) add("glow", `${g.el}: ${g.blur}px blur`);
|
|
339
|
+
for (const c of facts.cards || []) add("three-up-icon-cards", c.el);
|
|
340
|
+
for (const p of facts.pills || []) add("pill-above-headline", `"${p.text}"`);
|
|
341
|
+
if ((facts.emoji || []).length) add("decorative-emoji", facts.emoji.join(" "));
|
|
342
|
+
for (const p of (facts.pulse || []).slice(0, 3)) add("pulsing-status-dot", p.el);
|
|
343
|
+
if ((facts.copy || []).length) add("placeholder-copy", facts.copy.join(", "));
|
|
344
|
+
for (const i of facts.images || []) add("placeholder-image", `${i.el}: ${i.src}`);
|
|
345
|
+
// Layout tells. One crowded heading is a judgment call; two on a page is a pattern (Hallmark's threshold).
|
|
346
|
+
if ((facts.crowded || []).length >= 2) add("crowded-heading", facts.crowded.slice(0, 2).map((c) => `${c.el} "${c.text}" ${c.up}px above, ${c.down}px below`).join("; "));
|
|
347
|
+
for (const c of (facts.cramped || []).slice(0, 3)) add("cramped-box", `${c.el}: ${c.sides}`);
|
|
348
|
+
for (const c of (facts.covered || []).slice(0, 3)) add("covered-text", `${c.el} over "${c.text}"`);
|
|
349
|
+
for (const w of (facts.wrapped || []).slice(0, 3)) add("wrapped-button-label", `${w.el} "${w.text}"${w.clipped ? " clipped" : ""}${w.lines > 1 ? ` on ${w.lines} lines` : ""}`);
|
|
350
|
+
if (facts.zoom) add("zoom-blocked", `viewport content "${facts.zoom.content}"`);
|
|
351
|
+
for (const r of (facts.regions || []).slice(0, 3)) add("unreachable-scroll-region", `${r.el} scrolls sideways without ${r.missing}`);
|
|
352
|
+
const o = facts.overflow;
|
|
353
|
+
if (o && o.scrollWidth > o.innerWidth + 1) add("horizontal-overflow", `${o.scrollWidth}px wide in a ${o.innerWidth}px window`);
|
|
354
|
+
return out;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/** Findings from every width, with a tell seen at several widths shown once. */
|
|
358
|
+
export function merge(perWidth) {
|
|
359
|
+
const seen = new Map();
|
|
360
|
+
for (const f of perWidth.flat()) {
|
|
361
|
+
const key = `${f.code}|${f.detail}`;
|
|
362
|
+
if (seen.has(key)) { if (!seen.get(key).widths.includes(f.width)) seen.get(key).widths.push(f.width); }
|
|
363
|
+
else seen.set(key, { ...f, widths: [f.width] });
|
|
364
|
+
}
|
|
365
|
+
return [...seen.values()].map(({ width, ...rest }) => rest);
|
|
366
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* lint-arbitrary-tokens: `rounded-[--radius-pill]` and friends.
|
|
4
|
+
*
|
|
5
|
+
* In Tailwind v4 a square-bracket arbitrary value is emitted verbatim, so `rounded-[--radius-pill]`
|
|
6
|
+
* compiles to `border-radius: --radius-pill`, which is not valid CSS: a bare custom-property NAME is
|
|
7
|
+
* not a value. The browser drops the declaration and the element renders with no radius at all.
|
|
8
|
+
* Nothing errors. The class exists, the build passes, the rule is in the stylesheet, and the element
|
|
9
|
+
* is simply square. lint-unknown-classes passes it (the class compiles) and lint-css-vars passes it
|
|
10
|
+
* (there is no var() to resolve), so this shape needs its own check.
|
|
11
|
+
*
|
|
12
|
+
* The correct spellings are `rounded-[var(--radius-pill)]` or Tailwind v4's shorthand
|
|
13
|
+
* `rounded-(--radius-pill)`. This lint requires the explicit `var(...)` form, because it reads
|
|
14
|
+
* correctly to someone who does not know the shorthand exists.
|
|
15
|
+
*
|
|
16
|
+
* node packages/core/scripts/lint-arbitrary-tokens.mjs [--warn | --init | --ratchet] [paths]
|
|
17
|
+
*/
|
|
18
|
+
import { codeAndClasses } from "./lib/source-scan.mjs";
|
|
19
|
+
import { runLint } from "./lib/lab-lint.mjs";
|
|
20
|
+
import { isMain } from "./lib/counted-lint.mjs";
|
|
21
|
+
|
|
22
|
+
/** A utility ending in -[--token]: brackets wrapping a bare custom property. */
|
|
23
|
+
const BAD = /[a-z][a-z-]*-\[--[a-z0-9-]+\]/gi;
|
|
24
|
+
|
|
25
|
+
export function findBareTokens(src) {
|
|
26
|
+
const findings = [];
|
|
27
|
+
codeAndClasses(src)
|
|
28
|
+
.split("\n")
|
|
29
|
+
.forEach((line, i) => {
|
|
30
|
+
for (const m of line.matchAll(BAD)) {
|
|
31
|
+
const token = m[0].slice(m[0].indexOf("[") + 1, -1);
|
|
32
|
+
findings.push({ line: i + 1, text: `${m[0]} -> ${m[0].replace(`[${token}]`, `[var(${token})]`)}` });
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return findings;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (isMain(import.meta.url)) {
|
|
39
|
+
process.exit(
|
|
40
|
+
runLint({
|
|
41
|
+
ruleId: "arbitrary-tokens",
|
|
42
|
+
bin: "bads-lint-arbitrary-tokens",
|
|
43
|
+
detect: (src) => findBareTokens(src),
|
|
44
|
+
fix: "A bracketed bare custom property compiles to invalid CSS and the style silently does not apply. Wrap it: `[var(--token)]`.",
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
}
|