@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.
Files changed (314) hide show
  1. package/package.json +38 -8
  2. package/scripts/a11y-lint.cjs +101 -14
  3. package/scripts/bads-sync.mjs +1 -1
  4. package/scripts/build-tokens.cjs +122 -7
  5. package/scripts/check-dark-contrast.mjs +204 -0
  6. package/scripts/check-flush-edges.mjs +245 -0
  7. package/scripts/check-spec.mjs +73 -0
  8. package/scripts/deal-directions.mjs +186 -0
  9. package/scripts/design-system-advisory/README.md +239 -0
  10. package/scripts/design-system-advisory/check-copy-punctuation.mjs +44 -0
  11. package/scripts/design-system-advisory/check-even-padding.mjs +35 -0
  12. package/scripts/design-system-advisory/check-hand-built-button.mjs +46 -0
  13. package/scripts/design-system-advisory/check-html-nesting.mjs +51 -0
  14. package/scripts/design-system-advisory/check-icon-sizing.mjs +79 -0
  15. package/scripts/design-system-advisory/check-label-case.mjs +92 -0
  16. package/scripts/design-system-advisory/check-native-form-controls.mjs +53 -0
  17. package/scripts/design-system-advisory/check-radius.mjs +56 -0
  18. package/scripts/design-system-advisory/check-raw-values.mjs +61 -0
  19. package/scripts/design-system-advisory/check-small-text.mjs +72 -0
  20. package/scripts/design-system-advisory/check-tap-target.mjs +70 -0
  21. package/scripts/design-system-advisory/defaults.mjs +90 -0
  22. package/scripts/design-system-advisory/fixtures/clean.tsx.fixture +12 -0
  23. package/scripts/design-system-advisory/fixtures/violations.tsx.fixture +19 -0
  24. package/scripts/design-system-advisory/lib.mjs +255 -0
  25. package/scripts/design-system-advisory/run.mjs +189 -0
  26. package/scripts/design-system-advisory/workflow.yml +82 -0
  27. package/scripts/health-report.mjs +20 -14
  28. package/scripts/lib/copy-strings.mjs +146 -0
  29. package/scripts/lib/counted-lint.mjs +100 -0
  30. package/scripts/lib/dark-contrast.mjs +120 -0
  31. package/scripts/lib/flush-edges.mjs +294 -0
  32. package/scripts/lib/lab-lint.mjs +62 -0
  33. package/scripts/lib/marketing-library.mjs +129 -0
  34. package/scripts/lib/mount-page.mjs +25 -0
  35. package/scripts/lib/on-system.mjs +249 -0
  36. package/scripts/lib/random.mjs +22 -0
  37. package/scripts/lib/source-scan.mjs +173 -0
  38. package/scripts/lib/spec-parse.d.mts +25 -0
  39. package/scripts/lib/spec-parse.mjs +188 -0
  40. package/scripts/lib/tells.mjs +366 -0
  41. package/scripts/lint-arbitrary-tokens.mjs +47 -0
  42. package/scripts/lint-component-token-refs.mjs +63 -0
  43. package/scripts/lint-content-hierarchy.mjs +114 -0
  44. package/scripts/lint-control-baseline.mjs +72 -0
  45. package/scripts/lint-copy-punctuation.mjs +60 -0
  46. package/scripts/lint-css-vars.mjs +175 -0
  47. package/scripts/lint-even-padding.mjs +58 -0
  48. package/scripts/lint-html-nesting.mjs +116 -0
  49. package/scripts/lint-label-case.mjs +219 -0
  50. package/scripts/lint-live-ctas.mjs +138 -0
  51. package/scripts/lint-microanimation.mjs +2 -2
  52. package/scripts/lint-proximity.mjs +181 -0
  53. package/scripts/lint-slop.mjs +1 -1
  54. package/scripts/lint-spacing-scale.mjs +78 -0
  55. package/scripts/lint-target-size.cjs +132 -0
  56. package/scripts/lint-token-primitives.mjs +307 -0
  57. package/scripts/on-system-score.mjs +95 -0
  58. package/scripts/size-audit.cjs +2 -2
  59. package/scripts/slop-rules.mjs +1 -1
  60. package/scripts/source-images.mjs +180 -0
  61. package/scripts/ux-tells.mjs +80 -0
  62. package/scripts/wcag-audit.cjs +25 -4
  63. package/src/api/brand-colors.ts +3 -0
  64. package/src/api/brand-fonts.ts +3 -0
  65. package/src/api/brand-mark.ts +6 -1
  66. package/src/api/dev-write-guard.ts +53 -0
  67. package/src/api/layers/file.ts +9 -4
  68. package/src/api/onboarding-extract.ts +85 -30
  69. package/src/api/onboarding.ts +3 -0
  70. package/src/api/save-tokens.ts +3 -0
  71. package/src/api/site-auth.ts +14 -2
  72. package/src/app/layout.tsx +6 -0
  73. package/src/app/preview/canvas/page.tsx +12 -0
  74. package/src/app/preview/components/page.tsx +828 -14
  75. package/src/app/preview/sticker-sheet/page.tsx +329 -0
  76. package/src/app/preview/sticker-sheet/specimens.tsx +296 -0
  77. package/src/app/preview/studio/blank-screen.tsx +143 -0
  78. package/src/app/preview/studio/page.tsx +7 -0
  79. package/src/app/shell.tsx +164 -47
  80. package/src/components/Foundations/Colors.stories.tsx +119 -8
  81. package/src/components/canvas/canvas.tsx +458 -0
  82. package/src/components/canvas/layout.ts +72 -0
  83. package/src/components/canvas/parse-canvas.ts +32 -0
  84. package/src/components/canvas/sample.ts +90 -0
  85. package/src/components/canvas/spec-frame.tsx +43 -0
  86. package/src/components/canvas/types.ts +33 -0
  87. package/src/components/docs-tab.tsx +7 -7
  88. package/src/components/home-recent.tsx +73 -0
  89. package/src/components/home-tab.tsx +19 -14
  90. package/src/components/layers-tab.tsx +2 -2
  91. package/src/components/markdown-preview.tsx +60 -12
  92. package/src/components/onboarding-wizard.tsx +1 -1
  93. package/src/components/studio/control-panel.tsx +299 -0
  94. package/src/components/studio/control-row.tsx +77 -0
  95. package/src/components/studio/preview-frame.tsx +165 -0
  96. package/src/components/studio/preview-pane.tsx +247 -0
  97. package/src/components/studio/studio.tsx +133 -128
  98. package/src/components/studio/types.ts +218 -0
  99. package/src/components/studio/use-studio-tweaks.ts +128 -0
  100. package/src/components/studio/use-studio-view-state.ts +72 -0
  101. package/src/components/ui/autocomplete.tsx +1 -1
  102. package/src/components/ui/avatar.tsx +4 -0
  103. package/src/components/ui/chart.tsx +134 -42
  104. package/src/components/ui/checkbox-group.tsx +1 -1
  105. package/src/components/ui/checkbox.tsx +1 -1
  106. package/src/components/ui/color-picker.tsx +20 -4
  107. package/src/components/ui/combobox.tsx +1 -0
  108. package/src/components/ui/command.tsx +1 -1
  109. package/src/components/ui/data-table.tsx +64 -3
  110. package/src/components/ui/date-field.tsx +1 -1
  111. package/src/components/ui/date-picker.tsx +2 -0
  112. package/src/components/ui/date-range-picker.tsx +4 -0
  113. package/src/components/ui/editable.tsx +1 -0
  114. package/src/components/ui/faceted-filter.tsx +187 -0
  115. package/src/components/ui/file-upload.tsx +21 -2
  116. package/src/components/ui/gauge-chart.tsx +18 -4
  117. package/src/components/ui/heatmap.tsx +3 -1
  118. package/src/components/ui/inline-edit.tsx +175 -0
  119. package/src/components/ui/input-group.tsx +5 -2
  120. package/src/components/ui/month-picker.tsx +1 -1
  121. package/src/components/ui/multi-select.tsx +1 -0
  122. package/src/components/ui/number-input.tsx +28 -5
  123. package/src/components/ui/otp-input.tsx +208 -0
  124. package/src/components/ui/phone-input.tsx +274 -0
  125. package/src/components/ui/radio-group.tsx +2 -2
  126. package/src/components/ui/search-input.tsx +1 -1
  127. package/src/components/ui/sparkline.tsx +33 -4
  128. package/src/components/ui/spinner.tsx +23 -4
  129. package/src/components/ui/table.tsx +9 -0
  130. package/src/components/ui/tags-input.tsx +1 -1
  131. package/src/components/ui/timer.tsx +1 -0
  132. package/src/components/ui/transfer-list.tsx +13 -26
  133. package/src/components/ui/week-picker.tsx +1 -13
  134. package/src/components/ui/year-picker.tsx +1 -1
  135. package/src/data/component-added.json +966 -0
  136. package/src/data/docs-index.ts +35 -2
  137. package/src/data/history.json +161 -161
  138. package/src/data/sticker-sheet.json +9244 -0
  139. package/src/docs-trace-globs.json +1 -0
  140. package/src/hooks/use-global-mono-font.ts +1 -0
  141. package/src/hooks/use-global-primary-color.ts +1 -0
  142. package/src/hooks/use-global-sans-font.ts +1 -0
  143. package/src/hooks/use-global-serif-font.ts +1 -0
  144. package/src/hooks/use-global-type-scale.ts +17 -2
  145. package/src/hooks/use-mobile.ts +2 -0
  146. package/src/hooks/use-sync-type-scale.ts +7 -11
  147. package/src/lib/chart-motion.ts +41 -0
  148. package/src/lib/get-icon-color.ts +1 -1
  149. package/src/lib/spec-parse.ts +4 -0
  150. package/src/lib/svg-sanitize.ts +19 -9
  151. package/src/stories/Accordion.stories.tsx +7 -0
  152. package/src/stories/ActionBar.stories.tsx +5 -0
  153. package/src/stories/Affix.stories.tsx +4 -0
  154. package/src/stories/AiBadge.stories.tsx +9 -7
  155. package/src/stories/Alert.stories.tsx +13 -0
  156. package/src/stories/AlertDialog.stories.tsx +4 -0
  157. package/src/stories/Anchor.stories.tsx +5 -0
  158. package/src/stories/AngleSlider.stories.tsx +6 -3
  159. package/src/stories/AspectRatio.stories.tsx +4 -0
  160. package/src/stories/Autocomplete.stories.tsx +8 -0
  161. package/src/stories/Avatar.stories.tsx +10 -0
  162. package/src/stories/Badge.stories.tsx +14 -6
  163. package/src/stories/Blockquote.stories.tsx +6 -0
  164. package/src/stories/BottomNavigation.stories.tsx +4 -0
  165. package/src/stories/Breadcrumb.stories.tsx +3 -0
  166. package/src/stories/Burger.stories.tsx +1 -0
  167. package/src/stories/Button.stories.tsx +24 -0
  168. package/src/stories/ButtonGroup.stories.tsx +9 -0
  169. package/src/stories/Calendar.stories.tsx +3 -0
  170. package/src/stories/Canvas.stories.tsx +45 -0
  171. package/src/stories/Card.stories.tsx +4 -0
  172. package/src/stories/Carousel.stories.tsx +6 -0
  173. package/src/stories/Cascader.stories.tsx +4 -0
  174. package/src/stories/Chart.stories.tsx +46 -1
  175. package/src/stories/ChatBubble.stories.tsx +8 -2
  176. package/src/stories/ChatMarker.stories.tsx +1 -0
  177. package/src/stories/Checkbox.stories.tsx +40 -0
  178. package/src/stories/CheckboxCard.stories.tsx +8 -0
  179. package/src/stories/CheckboxGroup.stories.tsx +19 -0
  180. package/src/stories/Chip.stories.tsx +10 -19
  181. package/src/stories/CircularProgress.stories.tsx +13 -27
  182. package/src/stories/Clipboard.stories.tsx +6 -0
  183. package/src/stories/CloseButton.stories.tsx +6 -4
  184. package/src/stories/Code.stories.tsx +8 -1
  185. package/src/stories/Collapsible.stories.tsx +2 -0
  186. package/src/stories/ColorPicker.stories.tsx +46 -0
  187. package/src/stories/ColorSwatch.stories.tsx +1 -0
  188. package/src/stories/Combobox.stories.tsx +9 -0
  189. package/src/stories/Command.stories.tsx +2 -0
  190. package/src/stories/Container.stories.tsx +8 -0
  191. package/src/stories/ContextMenu.stories.tsx +9 -0
  192. package/src/stories/CopyButton.stories.tsx +12 -36
  193. package/src/stories/DataList.stories.tsx +8 -0
  194. package/src/stories/DataTable.stories.tsx +39 -0
  195. package/src/stories/DateField.stories.tsx +28 -0
  196. package/src/stories/DatePicker.stories.tsx +34 -0
  197. package/src/stories/DateRangePicker.stories.tsx +32 -0
  198. package/src/stories/Dialog.stories.tsx +8 -0
  199. package/src/stories/Drawer.stories.tsx +6 -0
  200. package/src/stories/DropdownMenu.stories.tsx +2 -0
  201. package/src/stories/Editable.stories.tsx +12 -0
  202. package/src/stories/EmptyState.stories.tsx +9 -0
  203. package/src/stories/FacetedFilter.stories.tsx +197 -0
  204. package/src/stories/Field.stories.tsx +7 -0
  205. package/src/stories/Fieldset.stories.tsx +8 -0
  206. package/src/stories/FileButton.stories.tsx +4 -0
  207. package/src/stories/FileUpload.stories.tsx +16 -17
  208. package/src/stories/FloatLabel.stories.tsx +3 -8
  209. package/src/stories/FloatingActionButton.stories.tsx +10 -0
  210. package/src/stories/FloatingIndicator.stories.tsx +4 -0
  211. package/src/stories/FloatingPanel.stories.tsx +6 -0
  212. package/src/stories/FocusTrap.stories.tsx +5 -0
  213. package/src/stories/FormatByte.stories.tsx +6 -0
  214. package/src/stories/FormatDate.stories.tsx +8 -0
  215. package/src/stories/FormatNumber.stories.tsx +9 -0
  216. package/src/stories/GaugeChart.stories.tsx +9 -3
  217. package/src/stories/Heatmap.stories.tsx +11 -0
  218. package/src/stories/Highlight.stories.tsx +6 -0
  219. package/src/stories/HoverCard.stories.tsx +4 -0
  220. package/src/stories/Image.stories.tsx +9 -0
  221. package/src/stories/Indicator.stories.tsx +19 -0
  222. package/src/stories/InlineEdit.stories.tsx +106 -0
  223. package/src/stories/Input.stories.tsx +7 -0
  224. package/src/stories/InputClearButton.stories.tsx +3 -0
  225. package/src/stories/InputGroup.stories.tsx +40 -0
  226. package/src/stories/Kbd.stories.tsx +7 -1
  227. package/src/stories/KeyboardShortcut.stories.tsx +2 -0
  228. package/src/stories/Label.stories.tsx +2 -0
  229. package/src/stories/Link.stories.tsx +9 -0
  230. package/src/stories/List.stories.tsx +8 -0
  231. package/src/stories/Listbox.stories.tsx +1 -0
  232. package/src/stories/LoadingDots.stories.tsx +5 -3
  233. package/src/stories/LoadingOverlay.stories.tsx +5 -1
  234. package/src/stories/Mark.stories.tsx +5 -0
  235. package/src/stories/MarkdownPreview.stories.tsx +53 -0
  236. package/src/stories/Marquee.stories.tsx +4 -0
  237. package/src/stories/Masonry.stories.tsx +5 -0
  238. package/src/stories/Menubar.stories.tsx +3 -0
  239. package/src/stories/Meter.stories.tsx +11 -17
  240. package/src/stories/MonthPicker.stories.tsx +26 -1
  241. package/src/stories/MotionToggle.stories.tsx +1 -0
  242. package/src/stories/MultiSelect.stories.tsx +9 -0
  243. package/src/stories/NativeSelect.stories.tsx +1 -0
  244. package/src/stories/NavLink.stories.tsx +7 -0
  245. package/src/stories/NavigationMenu.stories.tsx +5 -0
  246. package/src/stories/NavigationRail.stories.tsx +10 -0
  247. package/src/stories/Notification.stories.tsx +13 -34
  248. package/src/stories/NumberInput.stories.tsx +33 -1
  249. package/src/stories/OtpInput.stories.tsx +110 -0
  250. package/src/stories/Overlay.stories.tsx +5 -1
  251. package/src/stories/Pagination.stories.tsx +8 -0
  252. package/src/stories/PasswordInput.stories.tsx +2 -0
  253. package/src/stories/PhoneInput.stories.tsx +127 -0
  254. package/src/stories/PinInput.stories.tsx +9 -2
  255. package/src/stories/Popover.stories.tsx +2 -0
  256. package/src/stories/Progress.stories.tsx +6 -1
  257. package/src/stories/Prose.stories.tsx +8 -0
  258. package/src/stories/QrCode.stories.tsx +2 -0
  259. package/src/stories/Questionnaire.stories.tsx +7 -0
  260. package/src/stories/RadioGroup.stories.tsx +40 -0
  261. package/src/stories/RatingGroup.stories.tsx +8 -4
  262. package/src/stories/Resizable.stories.tsx +4 -2
  263. package/src/stories/Result.stories.tsx +3 -0
  264. package/src/stories/Reveal.stories.tsx +2 -0
  265. package/src/stories/RollingNumber.stories.tsx +5 -0
  266. package/src/stories/ScrollArea.stories.tsx +3 -1
  267. package/src/stories/SearchInput.stories.tsx +10 -6
  268. package/src/stories/SegmentedControl.stories.tsx +11 -0
  269. package/src/stories/Select.stories.tsx +7 -0
  270. package/src/stories/Separator.stories.tsx +6 -0
  271. package/src/stories/Sheet.stories.tsx +5 -0
  272. package/src/stories/Sidebar.stories.tsx +40 -1
  273. package/src/stories/SimpleGrid.stories.tsx +5 -0
  274. package/src/stories/Skeleton.stories.tsx +8 -0
  275. package/src/stories/SkeletonTable.stories.tsx +6 -5
  276. package/src/stories/SkipLink.stories.tsx +3 -0
  277. package/src/stories/Slider.stories.tsx +2 -1
  278. package/src/stories/Sonner.stories.tsx +7 -0
  279. package/src/stories/Sparkline.stories.tsx +14 -1
  280. package/src/stories/Spinner.stories.tsx +20 -10
  281. package/src/stories/Spoiler.stories.tsx +5 -0
  282. package/src/stories/Squircle.stories.tsx +7 -0
  283. package/src/stories/Stack.stories.tsx +7 -0
  284. package/src/stories/StatusBadge.stories.tsx +12 -6
  285. package/src/stories/Stepper.stories.tsx +5 -0
  286. package/src/stories/Switch.stories.tsx +4 -0
  287. package/src/stories/Table.stories.tsx +10 -1
  288. package/src/stories/Tabs.stories.tsx +8 -0
  289. package/src/stories/Tag.stories.tsx +13 -5
  290. package/src/stories/TagsInput.stories.tsx +15 -0
  291. package/src/stories/Text.stories.tsx +12 -0
  292. package/src/stories/Textarea.stories.tsx +9 -0
  293. package/src/stories/ThemeIcon.stories.tsx +6 -3
  294. package/src/stories/TimePicker.stories.tsx +2 -0
  295. package/src/stories/Timeline.stories.tsx +12 -0
  296. package/src/stories/Timer.stories.tsx +30 -0
  297. package/src/stories/Toggle.stories.tsx +7 -5
  298. package/src/stories/ToggleGroup.stories.tsx +5 -0
  299. package/src/stories/ToggleTip.stories.tsx +4 -0
  300. package/src/stories/Toolbar.stories.tsx +6 -0
  301. package/src/stories/Tooltip.stories.tsx +3 -0
  302. package/src/stories/Tour.stories.tsx +3 -0
  303. package/src/stories/TransferList.stories.tsx +7 -0
  304. package/src/stories/TreeSelect.stories.tsx +4 -0
  305. package/src/stories/TreeView.stories.tsx +5 -0
  306. package/src/stories/TypingIndicator.stories.tsx +4 -0
  307. package/src/stories/VisuallyHidden.stories.tsx +3 -0
  308. package/src/stories/Watermark.stories.tsx +6 -0
  309. package/src/stories/WeekPicker.stories.tsx +25 -1
  310. package/src/stories/WordRotate.stories.tsx +5 -0
  311. package/src/stories/YearPicker.stories.tsx +26 -11
  312. package/src/stories/story-groups.json +22 -16
  313. package/src/styles.css +50 -2
  314. package/src/tokens.json +86 -58
@@ -0,0 +1,186 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * deal-directions — deal three starting directions for a Path B build, so the
4
+ * agent chooses among them instead of inventing the category default.
5
+ *
6
+ * Why a script: asked to invent a look, a model returns the safest shape for the
7
+ * category every time. design-exploration step 3.7 already says to pick a named
8
+ * macrostructure and diversify against the fork's last three; this makes the
9
+ * draw mechanical. The idea of dealing a few researched directions, rather than
10
+ * asking for one, is from Leonxlnx/taste-skill (MIT); the pool, the exclusion
11
+ * rule and the ledger memory are BADS's own (prompts/macrostructures.md,
12
+ * ledgers/prototypes.jsonl).
13
+ *
14
+ * What it deals: three macrostructures with a visual register and an interaction
15
+ * paradigm each. The three differ on every axis, so they meet the "differ on at
16
+ * least two axes" rule by construction. It skips the fork's last three
17
+ * macrostructures (ledger `macrostructure` field) and flags the two safest
18
+ * shapes, which need a written reason if chosen.
19
+ *
20
+ * Marketing, with the composition library present (disciplines/marketing/library/), deals
21
+ * full directions from it, and then a direction sheet: a hero and a section per role.
22
+ * Product surfaces, and marketing without the library, deal macrostructures.
23
+ *
24
+ * Usage (from the repo root):
25
+ * bads-deal-directions --surface product [--seed 42] [--count 3] [--json]
26
+ * bads-deal-directions --surface marketing --sector restaurant --tone warm
27
+ * bads-deal-directions --surface marketing --direction <id> --sections intro,features,proof,cta
28
+ * bads-deal-directions --surface marketing --direction <id> --alternatives features
29
+ * bads-deal-directions --list sectors|tones|roles|directions
30
+ *
31
+ * Same seed, same ledger, same deal. Without --seed the deal is random.
32
+ * It never writes anything. Record the direction you choose on the prototype's
33
+ * ledgers/prototypes.jsonl row, as `macrostructure`.
34
+ */
35
+ import fs from "node:fs";
36
+ import path from "node:path";
37
+ import { fileURLToPath } from "node:url";
38
+ import { rng, shuffle } from "./lib/random.mjs";
39
+
40
+ export const REGISTERS = ["editorial-magazine", "pro-tool-terminal", "brutalist", "consumer-playful", "motion-led", "retro", "art-direction-led"];
41
+ export const PARADIGMS = { product: ["click-driven", "keyboard-first", "voice", "gesture", "scroll-driven", "command-palette"], marketing: ["click-driven", "scroll-driven", "keyboard-first", "gesture"] };
42
+ // The two shapes a model reaches for unprompted. Allowed, but only with a written reason.
43
+ export const SAFE_DEFAULTS = ["Dashboard-of-tiles", "Split master–detail"];
44
+
45
+ export { rng, shuffle };
46
+
47
+ /** Macrostructures named in prompts/macrostructures.md, by surface. */
48
+ export function parseMacrostructures(md) {
49
+ const out = { product: [], marketing: [] };
50
+ let into = null;
51
+ let current = null;
52
+ const flush = () => { if (current) out[into].push({ name: current.name, note: current.text.replace(/\s+/g, " ").trim() }); current = null; };
53
+ for (const line of md.replace(/\r\n/g, "\n").split("\n")) {
54
+ if (/^##\s+Product/i.test(line)) { flush(); into = "product"; continue; }
55
+ if (/^##\s+Marketing/i.test(line)) { flush(); into = "marketing"; continue; }
56
+ if (/^##\s+/.test(line) || /^---\s*$/.test(line)) { flush(); into = /^##\s+/.test(line) ? null : into; continue; }
57
+ if (!into) continue;
58
+ const m = line.match(/^-\s+\*\*(.+?)\*\*\s*(?:—|-)?\s*(.*)$/);
59
+ if (m) { flush(); current = { name: m[1].trim(), text: m[2] }; } else if (current && /^\s+\S/.test(line)) current.text += " " + line.trim();
60
+ }
61
+ flush();
62
+ return out;
63
+ }
64
+
65
+ /** The newest `n` non-empty values of one ledger field, oldest first. Malformed rows are skipped. */
66
+ export function recentField(jsonl, field, n = 3) {
67
+ const rows = [];
68
+ for (const line of jsonl.split("\n")) {
69
+ if (!line.trim()) continue;
70
+ try { rows.push(JSON.parse(line)); } catch { /* skip a malformed row */ }
71
+ }
72
+ return rows.map((r) => r[field]).filter(Boolean).slice(-n);
73
+ }
74
+
75
+ /** The macrostructures used by this fork's recent builds, newest last. */
76
+ export const recentMacrostructures = (jsonl, n = 3) => recentField(jsonl, "macrostructure", n);
77
+
78
+ const norm = (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
79
+
80
+ /** Deal `count` directions. Pure: pass the pool, the exclusions and a random source. */
81
+ export function deal({ pool, exclude = [], surface, count = 3, random = Math.random }) {
82
+ const skip = new Set(exclude.map(norm));
83
+ let candidates = pool.filter((m) => !skip.has(norm(m.name)));
84
+ const excluded = pool.length - candidates.length;
85
+ // If the exclusions leave too few, say so and relax rather than returning short.
86
+ let relaxed = false;
87
+ if (candidates.length < count) { candidates = pool; relaxed = true; }
88
+ const picks = shuffle(candidates, random).slice(0, count);
89
+ const registers = shuffle(REGISTERS, random);
90
+ const paradigms = shuffle(PARADIGMS[surface] || PARADIGMS.product, random);
91
+ const directions = picks.map((m, i) => ({
92
+ macrostructure: m.name,
93
+ register: registers[i % registers.length],
94
+ paradigm: paradigms[i % paradigms.length],
95
+ note: m.note,
96
+ safeDefault: SAFE_DEFAULTS.some((s) => norm(s) === norm(m.name)),
97
+ }));
98
+ return { surface, excluded, relaxed, directions };
99
+ }
100
+
101
+ export function format(result, recent) {
102
+ const lines = [];
103
+ lines.push(`Dealt ${result.directions.length} directions for a ${result.surface} surface.`);
104
+ lines.push(recent.length ? `Skipped this fork's last ${recent.length}: ${recent.join(", ")}.` : "No macrostructure recorded in ledgers/prototypes.jsonl yet, so nothing is skipped.");
105
+ if (result.relaxed) lines.push("The pool is too small to skip them all, so a recent one may appear. Say why in the sketch.");
106
+ lines.push("");
107
+ result.directions.forEach((d, i) => {
108
+ lines.push(`${i + 1}. ${d.macrostructure} · ${d.register} · ${d.paradigm}`);
109
+ if (d.note) lines.push(` ${d.note.length > 240 ? d.note.slice(0, 237) + "…" : d.note}`);
110
+ if (d.safeDefault) lines.push(" ⚠ A safe default. Choose it only with a written reason.");
111
+ });
112
+ lines.push("");
113
+ lines.push("Hold each against the subject inventory (prompts/subject-inventory.md): which can carry something only this client has? Choose one, write why in one line, then sketch within it. Redraw only for a reason you can state, such as a brand constraint, and record the redraw.");
114
+ return lines.join("\n");
115
+ }
116
+
117
+ /** Parse a comma list flag. */
118
+ const list = (v) => (v ? String(v).split(",").map((x) => x.trim()).filter(Boolean) : []);
119
+
120
+ async function main(argv) {
121
+ const arg = (name, fallback) => { const i = argv.indexOf(name); return i >= 0 ? argv[i + 1] : fallback; };
122
+ const root = process.cwd();
123
+ const json = argv.includes("--json");
124
+ const seed = arg("--seed");
125
+ const random = seed !== undefined ? rng(Number(seed)) : Math.random;
126
+ const { loadLibrary, vocab, dealDirections, dealSheet, alternatives, formatDirections, formatSheet } = await import("./lib/marketing-library.mjs");
127
+ const lib = loadLibrary(root);
128
+
129
+ const listing = arg("--list");
130
+ if (listing) {
131
+ if (!lib) { console.error("deal-directions: no marketing library here. Run it from the repo root."); return 2; }
132
+ const v = vocab(lib);
133
+ const out = listing === "directions" ? lib.directions.map((d) => `${d.id} ${d.name}`) : v[listing];
134
+ if (!out) { console.error("usage: --list sectors|tones|roles|directions"); return 2; }
135
+ console.log(out.join("\n"));
136
+ return 0;
137
+ }
138
+
139
+ const surface = arg("--surface");
140
+ if (!["marketing", "product"].includes(surface)) {
141
+ console.error("usage: deal-directions --surface marketing|product [--seed N] [--json]\n marketing: [--sector S] [--tone T] [--have product-photo,product-ui] [--software]\n [--direction ID --sections intro,features,proof,cta | --alternatives ROLE]\n list: --list sectors|tones|roles|directions");
142
+ return 2;
143
+ }
144
+
145
+ // Marketing with the library present: deal full directions and sheets. Otherwise the macrostructure deal.
146
+ if (surface === "marketing" && lib && !argv.includes("--macrostructures")) {
147
+ const have = list(arg("--have")), software = argv.includes("--software");
148
+ const direction = arg("--direction");
149
+ try {
150
+ if (direction && arg("--alternatives")) {
151
+ const alts = alternatives(lib, { direction, role: arg("--alternatives"), have, software });
152
+ console.log(json ? JSON.stringify(alts, null, 2) : alts.map((x) => `${x.id} ${x.name} (${x.shape})`).join("\n") || "none");
153
+ return 0;
154
+ }
155
+ if (direction) {
156
+ const roles = list(arg("--sections"));
157
+ if (!roles.length) { console.error("--direction needs --sections, e.g. --sections intro,features,proof,cta. Roles: " + vocab(lib).roles.join(", ")); return 2; }
158
+ const bad = roles.filter((r) => !vocab(lib).roles.includes(r));
159
+ if (bad.length) { console.error(`unknown role: ${bad.join(", ")}. Roles: ${vocab(lib).roles.join(", ")}`); return 2; }
160
+ const sheet = dealSheet(lib, { direction, roles, have, software, random });
161
+ console.log(json ? JSON.stringify(sheet, null, 2) : formatSheet(sheet));
162
+ return 0;
163
+ }
164
+ const sector = arg("--sector"), tone = arg("--tone");
165
+ const v = vocab(lib);
166
+ if (sector && !v.sectors.includes(sector)) { console.error(`unknown sector "${sector}". Sectors: ${v.sectors.join(", ")}`); return 2; }
167
+ if (tone && !v.tones.includes(tone)) { console.error(`unknown tone "${tone}". Tones: ${v.tones.join(", ")}`); return 2; }
168
+ const ledger = path.join(root, "ledgers/prototypes.jsonl");
169
+ const recent = fs.existsSync(ledger) ? recentField(fs.readFileSync(ledger, "utf8"), "libraryDirection", 3) : [];
170
+ const result = dealDirections(lib, { sector, tone, have, software, exclude: recent, count: Number(arg("--options", 3)), random });
171
+ console.log(json ? JSON.stringify(result, null, 2) : formatDirections(result, { sector, tone }));
172
+ return 0;
173
+ } catch (e) { console.error(`deal-directions: ${e.message}`); return 2; }
174
+ }
175
+
176
+ const mdPath = path.join(root, "prompts/macrostructures.md");
177
+ if (!fs.existsSync(mdPath)) { console.error(`deal-directions: ${path.relative(root, mdPath)} not found. Run it from the repo root.`); return 2; }
178
+ const pool = parseMacrostructures(fs.readFileSync(mdPath, "utf8"))[surface];
179
+ const ledger = path.join(root, "ledgers/prototypes.jsonl");
180
+ const recent = fs.existsSync(ledger) ? recentMacrostructures(fs.readFileSync(ledger, "utf8")) : [];
181
+ const result = deal({ pool, exclude: recent, surface, count: Number(arg("--count", 3)), random });
182
+ console.log(json ? JSON.stringify({ ...result, skipped: recent }, null, 2) : format(result, recent));
183
+ return 0;
184
+ }
185
+
186
+ if (process.argv[1] && fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) process.exit(await main(process.argv.slice(2)));
@@ -0,0 +1,239 @@
1
+ # Design system checks (advisory)
2
+
3
+ These checks run on every pull request and report on the lines the pull request adds. They never block a merge. Existing code is never flagged, so you can install them on a large codebase on day one.
4
+
5
+ The kit ships in `@behavioral-agentic-design-system/core` as the `bads-ds-advisory` command. It imports only Node built-ins.
6
+
7
+ ## Install it in your repo
8
+
9
+ 1. Add the package as a dependency of your repo root:
10
+
11
+ ```bash
12
+ pnpm add -D @behavioral-agentic-design-system/core
13
+ ```
14
+
15
+ 1. Copy the workflow into your repo:
16
+
17
+ ```bash
18
+ cp node_modules/@behavioral-agentic-design-system/core/scripts/design-system-advisory/workflow.yml \
19
+ .github/workflows/design-system-advisory.yml
20
+ ```
21
+
22
+ The workflow installs your dependencies so that `npx bads-ds-advisory` finds the installed command. If your repo has its own install command, replace the **Install dependencies** step with it.
23
+
24
+ 1. Point the checks at your code. Add a `designSystemAdvisory` key to `.bads-lint.json` at your repo root. Create the file if it does not exist. For example:
25
+
26
+ ```json
27
+ {
28
+ "designSystemAdvisory": {
29
+ "include": ["^(apps/[^/]+/src|packages/ui/src)/.+\\.(tsx|jsx|ts)$"],
30
+ "atomsPath": "packages/ui/src/atoms/",
31
+ "components": {
32
+ "Select": { "name": "Dropdown", "importPath": "@acme/ui/atoms/dropdown" }
33
+ },
34
+ "checks": {
35
+ "label-case": { "properNouns": ["Acme Cloud"] },
36
+ "icon-sizing": { "iconDirs": ["packages/ui/src/icons"] }
37
+ },
38
+ "rulesDoc": "docs/design-system.md",
39
+ "readmePath": "docs/design-system-checks.md"
40
+ }
41
+ }
42
+ ```
43
+
44
+ 1. To confirm the setup, run the checks on your branch:
45
+
46
+ ```bash
47
+ npx bads-ds-advisory
48
+ ```
49
+
50
+ ## The checks
51
+
52
+ | Check | ID | Flags | Exempt a line with |
53
+ | --- | --- | --- | --- |
54
+ | Small text | `small-text` | A named class under the floor (Tailwind's `text-xs` is 12px), `text-[Npx]` or `text-[Nrem]` under the floor, inline `fontSize` under the floor | `type-scale-ok: <who chose this size and why>` |
55
+ | Raw values | `raw-values` | `bg-[#1d4ed8]`, `text-[rgb(...)]`, inline `color: "#f00"`, arbitrary sizes such as `w-[437px]` or `p-[1.5rem]` | `raw-value-ok: <why>` |
56
+ | Tap target | `tap-target` | A fixed `h-`, `w-` or `size-` class under 44px (`h-8`, `size-6`) on a button or a tag with `onClick`. `min-h-11 min-w-11` clears it | `tap-target-ok: <why>` |
57
+ | Hand-built button | `hand-built-button` | A native `<button>` with its own fill and rounded corners, which is the design system's `Button` drawn by hand | `hand-built-ok: <why>` |
58
+ | Native form control | `native-form-control` | A native `<input>`, `<select>` or `<textarea>`, which is a design-system control drawn by hand. Hidden and file inputs pass | `native-control-ok: <why>` |
59
+ | Uneven padding | `even-padding` | `px-N` and `py-M` with different values on one line | `uneven-padding-ok: <why>` |
60
+ | Title Case label | `label-case` | Title Case in button text and in `label`, `cta`, `title`, `ctaLabel` and `buttonText` props | `label-case-ok: <why>` |
61
+ | Copy punctuation | `copy-punctuation` | An em dash, three typed periods, or a typed `\uXXXX` in JSX text | `copy-ok: <why>` |
62
+ | Corner radius | `radius` | A button with words that is `rounded-full`, and `rounded-[var(--...)]` | `radius-ok: <role>` |
63
+ | Icon size class ignored | `icon-sizing` | `size-N`, `h-N` or `w-N` on an icon component that never reads `className` | `icon-size-ok: <why>` |
64
+ | Block inside a paragraph | `html-nesting` | A `<div>`, list, heading or other block inside a native `<p>` | `html-nesting-ok: <why>` |
65
+
66
+ Each check also explains itself in the comment at the top of its own `check-*.mjs` file.
67
+
68
+ 14px is a soft floor for new text. Avoid smaller text wherever you can. If a person chooses a smaller size, build it and flag it with the marker, naming who chose it and why.
69
+
70
+ ## Settings
71
+
72
+ The checks read their settings from the `designSystemAdvisory` key of `.bads-lint.json` at the repo root. To read another file, pass `--config=<file>`. `.bads-lint.json` is the same file that `bads-lint-target-size` reads for `minTargetPx`.
73
+
74
+ Flags win over the file, and the file wins over the defaults. Objects merge key by key. An array in the file replaces the default array, so a custom `include` does not keep the default paths. The one exception is `checks["label-case"].properNouns`, which adds to the built-in list.
75
+
76
+ | Setting | Default | What it does |
77
+ | --- | --- | --- |
78
+ | `include` | `["^(app\|components\|packages/core/src)/.+\\.(tsx\|jsx\|ts)$"]` | Regular expressions for the repo-relative paths to scan |
79
+ | `exclude` | Tests, specs, stories, mocks, e2e, snapshots, generated code, `.d.ts` | Regular expressions for paths to skip, even when they match `include` |
80
+ | `baseRef` | `"origin/main"` | The branch a run compares with when you pass no `--base` |
81
+ | `components` | The BADS primitives: `Button`, `Input`, `Textarea`, `NativeSelect`, `Checkbox`, `RadioGroup` under `@behavioral-agentic-design-system/core/components/ui/` | What a hand-built control is replaced with. Keys are `Button`, `Input`, `TextArea`, `Select`, `Checkbox` and `Radio`. Each value is `{ "name", "importPath" }` |
82
+ | `componentRoots` | `[{ "dir": "packages/core/src/components/ui", "importPrefix": "@behavioral-agentic-design-system/core/components/ui", "layer": "ui" }]` | The folders `listComponents()` reads |
83
+ | `atomsPath` | `"packages/core/src/components/ui/"` | A regular expression for the folder that holds the real controls. `native-form-control` skips it |
84
+ | `rulesDoc` | `null` | The rules document the PR comment names. `null` leaves it out |
85
+ | `readmePath` | This file, under `node_modules` | The page the PR comment points to for reproducing a run |
86
+ | `checks.<id>` | On | `false` switches a check off. An object changes that check's settings |
87
+ | `checks.small-text.floorPx` | `14` | The text size floor in px |
88
+ | `checks.small-text.namedSizes` | `{ "text-xs": 12 }` | Named text classes and their size in px. Set your theme's real value. BADS sets `text-xs` to 14 |
89
+ | `checks.small-text.suggest` | `"text-sm"` | The class the fix suggests |
90
+ | `checks.tap-target.minPx` | The top-level `minTargetPx` in `.bads-lint.json`, then `44` | The tap target floor in px |
91
+ | `checks.tap-target.unitPx` | `4` | Pixels per spacing unit. The unit floor is `minPx / unitPx`, so 44px is `h-11` |
92
+ | `checks.label-case.properNouns` | `[]` | Proper nouns to add to the built-in list (months, days, `I`, `US`, `USA` and large brands such as Google, Apple, Stripe, PayPal, Visa and Mastercard). A noun of several words passes only as the whole phrase |
93
+ | `checks.label-case.properNounsFile` | `"label-case-nouns.json"` | A JSON file of the form `{ "properNouns": [...] }`. `bads-lint-label-case` reads the same file |
94
+ | `checks.label-case.props` | `["label", "cta", "title", "ctaLabel", "buttonText"]` | Prop and key names that hold a label |
95
+ | `checks.raw-values.tokenExamples` | `"bg-background or text-destructive"` | The token classes the fix names |
96
+ | `checks.raw-values.opacityExample` | `"bg-foreground/50"` | The opacity modifier example the fix names |
97
+ | `checks.radius.buttonRadius` | `` "`rounded-md`, the radius `Button` uses" `` | The radius the fix suggests for a button with words |
98
+ | `checks.radius.utilities` | The `rounded` utilities | The classes the fix suggests in place of a radius variable |
99
+ | `checks.icon-sizing.iconDirs` | `[]` | Folders of icon components. With none, the check reports nothing |
100
+
101
+ To change a setting for one run, use a flag:
102
+
103
+ | Flag | What it does |
104
+ | --- | --- |
105
+ | `--include=<regex>`, `--exclude=<regex>` | Replace the scope. Repeat the flag for more than one pattern |
106
+ | `--off=<check-id>` | Switch a check off. Repeatable |
107
+ | `--base-ref=<ref>` | Compare with another branch |
108
+ | `--set=<dotted.path>=<value>` | Set any setting. The value is read as JSON, or as text when it is not JSON. For example, `--set=checks.small-text.floorPx=16` |
109
+ | `--config=<file>` | Read the settings from another file |
110
+
111
+ ## Exempt a line
112
+
113
+ To exempt a line, put the marker in a comment on the same line or the line above. The marker needs a reason after a colon. A bare marker does nothing.
114
+
115
+ ```tsx
116
+ {/* type-scale-ok: hint under a field, the designer chose 12px */}
117
+ <p className="text-xs">...</p>
118
+ ```
119
+
120
+ Keep the comment on one line directly above the line you exempt. A comment that your formatter splits over three lines (`{`, the comment, `}`) sits two lines above the element and does not count.
121
+
122
+ The check looks for the marker name anywhere on the line or the line above, not only inside a comment. Text on the same line that contains the marker name and a reason, such as `<p>type-scale-ok: x</p>`, also exempts the line. Do not rely on this.
123
+
124
+ ## What it scans
125
+
126
+ - Only lines **added** in the pull request. Existing code is never flagged.
127
+ - Files that match `include` and no `exclude`.
128
+ - Skipped on purpose: media query variants (`min-[640px]:`), border widths, percentages, `calc()` and `var()` values.
129
+
130
+ It is a line pattern match, not a parser. It misses values built at run time and can flag a value that is fine. A false positive is useful feedback. See [Report a false positive or a miss](#report-a-false-positive-or-a-miss).
131
+
132
+ ## Test it locally
133
+
134
+ You need Node 20 or later. Run the commands from the repo root. In BADS, the kit is at `packages/core/scripts/design-system-advisory/`. In a client repo, it is under `node_modules/@behavioral-agentic-design-system/core/scripts/design-system-advisory/`.
135
+
136
+ ### Run the unit tests
137
+
138
+ In BADS:
139
+
140
+ ```bash
141
+ node --test packages/core/scripts/design-system-advisory/advisory.test.mjs
142
+ ```
143
+
144
+ `pnpm test:scripts` runs the same tests with the other script tests.
145
+
146
+ ### Run it on the fixtures
147
+
148
+ ```bash
149
+ node packages/core/scripts/design-system-advisory/run.mjs \
150
+ --file=packages/core/scripts/design-system-advisory/fixtures/violations.tsx.fixture
151
+ ```
152
+
153
+ The run reads your `.bads-lint.json`, so the count depends on your settings. With the default settings, expect 11 findings (5 small text, 6 raw values) and `exit code is 0`. With BADS's own `.bads-lint.json`, where `text-xs` is 14px, expect 9. The two lines marked `OK` in the fixture produce nothing, which shows that the markers work.
154
+
155
+ ```bash
156
+ node packages/core/scripts/design-system-advisory/run.mjs \
157
+ --file=packages/core/scripts/design-system-advisory/fixtures/clean.tsx.fixture
158
+ ```
159
+
160
+ Expected: `No findings in 1 scanned file(s).`
161
+
162
+ ### Run it the way a pull request does
163
+
164
+ 1. On a throwaway branch, add a violation to a file in scope:
165
+
166
+ ```tsx
167
+ <p className="text-[11px] bg-[#1d4ed8] w-[437px]">test</p>
168
+ ```
169
+
170
+ 1. Commit it, then run the checks against `main`:
171
+
172
+ ```bash
173
+ pnpm check:ds-advisory
174
+ ```
175
+
176
+ Expected: three findings, each with the file, the line you added, and a fix. Nothing else in the file is reported. Run `echo $?` and check that it prints `0`.
177
+
178
+ 1. Change the line to `text-sm bg-background w-12` and run again. Expected: no findings.
179
+
180
+ Other options:
181
+
182
+ ```bash
183
+ pnpm check:ds-advisory -- --format=markdown # the PR comment text
184
+ pnpm check:ds-advisory -- --format=github # the annotation lines
185
+ pnpm check:ds-advisory -- --base=<sha> --head=<sha>
186
+ pnpm check:ds-advisory -- --strict # exit 1 on findings, to see what blocking would look like
187
+ ```
188
+
189
+ ## Test it in CI
190
+
191
+ 1. Push your scratch branch and open a **draft** pull request. Do not merge it.
192
+ 1. The **Design system checks (advisory)** job runs.
193
+ 1. Confirm each of these:
194
+ - The job finishes. An orange warning icon rather than a red cross is expected.
195
+ - On the **Files changed** tab, a warning annotation sits on each line you added, and only on those lines.
196
+ - The pull request has one comment that starts with "Design system checks (advisory)" and has a table of findings.
197
+ - When you push a fix commit, the same comment updates (no new comment appears) and says no findings.
198
+ - Merging is not blocked. The job is not a required check.
199
+ 1. Close the pull request and delete the branch.
200
+
201
+ ## What good looks like
202
+
203
+ - Every finding is on a line the pull request added.
204
+ - The fix text tells you what to do without reading anything else.
205
+ - Nothing flagged is something you would defend writing.
206
+
207
+ ## Report a false positive or a miss
208
+
209
+ Open an issue on the BADS repo. Include the line of code, what the check said, and what it should have said. Each report improves the pattern or becomes a test case in `advisory.test.mjs`.
210
+
211
+ ## Move a check to blocking
212
+
213
+ To make the checks block a merge, remove `continue-on-error` from the job, pass `--strict`, and add the job to your required checks. Wait until the advisory run has a low false-positive rate and the owning team agrees.
214
+
215
+ ## Files
216
+
217
+ | File | Purpose |
218
+ | --- | --- |
219
+ | `run.mjs` | Entry point (`bads-ds-advisory`). Reads the settings and the diff, runs the checks, and prints the report |
220
+ | `lib.mjs` | Settings, diff parsing, scope rules, marker handling, and `listComponents()` |
221
+ | `defaults.mjs` | The default settings and the built-in proper nouns |
222
+ | `check-*.mjs` | One check each |
223
+ | `fixtures/` | One file that violates and one that passes |
224
+ | `advisory.test.mjs` | Unit tests (`node:test`) |
225
+ | `workflow.yml` | The workflow a client copies into `.github/workflows/` |
226
+
227
+ ## Add a check
228
+
229
+ Every `check-*.mjs` in this folder loads automatically. There is nothing to register. Export an object with these fields:
230
+
231
+ | Field | What it is |
232
+ | --- | --- |
233
+ | `id`, `title` | The short name, and the heading used in the PR comment |
234
+ | `marker` | The comment text that exempts a line, for example `raw-value-ok` |
235
+ | `order` | Optional. Lower runs and reports first. The default is 100 |
236
+ | `scanLine(text, settings)` | For a rule one line can show. Returns hits |
237
+ | `scanFile({ file, lines, text, settings })` | For a rule that needs more than one line. `lines` are the lines the pull request added, and `text` is the whole file or `null`. Return hits that carry a `line` |
238
+
239
+ `settings` is the check's own entry under `checks.<id>`, merged over its defaults, with the whole run's settings under `$all`. Put a new check's defaults in `defaults.mjs`. A hit is `{ found, message, fix }`. Hits on lines the pull request did not add are dropped. Add unit tests to `advisory.test.mjs` and a row to the table in [The checks](#the-checks).
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Copy punctuation. Flags an em dash, three typed periods and a typed `\uXXXX` in JSX text.
3
+ *
4
+ * A person reads this text. Use a comma, a period or parentheses instead of an em dash.
5
+ * Use the ellipsis character `…`, not `...`. Use the character itself, not its escape code.
6
+ * An en dash is right for a range. A spread (`...rest`) is not copy and passes.
7
+ *
8
+ * Mark text only the team reads with `copy-ok: <why>` on the line or the line above.
9
+ */
10
+ const EM_DASH = /\u2014/;
11
+ const THREE_DOTS = /(?<=[\w"'`!?)])\.\.\.(?=["'`<\s}]|$)/;
12
+ const TYPED_ESCAPE = />[^<{]*\\u[0-9a-fA-F]{4}/;
13
+
14
+ export const copyPunctuation = {
15
+ id: "copy-punctuation",
16
+ title: "Copy punctuation",
17
+ marker: "copy-ok",
18
+ order: 70,
19
+ scanLine(text) {
20
+ const hits = [];
21
+ if (EM_DASH.test(text)) {
22
+ hits.push({
23
+ found: "—",
24
+ message: "An em dash does not survive being read aloud.",
25
+ fix: "Use a comma, a period or parentheses. An en dash `–` is right for a range. If only the team reads this string, flag it with `copy-ok: <why>`.",
26
+ });
27
+ }
28
+ if (THREE_DOTS.test(text)) {
29
+ hits.push({
30
+ found: "...",
31
+ message: "Three typed periods are not the ellipsis character.",
32
+ fix: "Use `…`. If only the team reads this string, flag it with `copy-ok: <why>`.",
33
+ });
34
+ }
35
+ if (TYPED_ESCAPE.test(text)) {
36
+ hits.push({
37
+ found: "\\u",
38
+ message: "A typed escape code in JSX text renders exactly as typed.",
39
+ fix: "Write the character itself, or put the string in braces: `{\"\\u2019\"}`.",
40
+ });
41
+ }
42
+ return hits;
43
+ },
44
+ };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Even padding. Flags `px-N` paired with a different `py-N` on one line.
3
+ *
4
+ * Padding is the same on every side unless a person chose otherwise and said why.
5
+ * `px-3 py-1` is two values picked one at a time. Grow the smaller side to match and use `p-3`.
6
+ * This check reads one line. It does not see padding split across lines or built by `cn()`.
7
+ *
8
+ * Mark an intended exception with `uneven-padding-ok: <why>` on the line or the line above.
9
+ */
10
+ const PAD = /(?<![\w-])((?:[a-z0-9-]+:)*)p([xy])-(\d+(?:\.\d+)?|\[[^\]\s]+\])(?![\w./[-])/g;
11
+
12
+ export const evenPadding = {
13
+ id: "even-padding",
14
+ title: "Uneven padding",
15
+ marker: "uneven-padding-ok",
16
+ order: 50,
17
+ scanLine(text) {
18
+ const seen = new Map();
19
+ for (const m of text.matchAll(PAD)) {
20
+ const entry = seen.get(m[1]) ?? {};
21
+ entry[m[2]] = m[3];
22
+ seen.set(m[1], entry);
23
+ }
24
+ const hits = [];
25
+ for (const [variant, { x, y }] of seen) {
26
+ if (x === undefined || y === undefined || x === y) continue;
27
+ hits.push({
28
+ found: `${variant}px-${x} ${variant}py-${y}`,
29
+ message: `Padding is ${x} beside and ${y} above. Nobody said why.`,
30
+ fix: `Grow the smaller side to match and use \`${variant}p-${Number(x) > Number(y) || Number.isNaN(Number(y)) ? x : y}\`. If a person chose uneven padding, flag it with \`uneven-padding-ok: <why>\`.`,
31
+ });
32
+ }
33
+ return hits;
34
+ },
35
+ };
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Hand-built button. Flags a native `button` that is drawn as a filled, rounded button.
3
+ *
4
+ * The design system ships `Button`. It has the right sizes, states, focus ring and tap target. A
5
+ * `button` with its own fill and rounded corners is a second copy that drifts from it. A `button`
6
+ * with no fill, such as a text link or an icon button, is fine.
7
+ *
8
+ * Settings: `components.Button` (`{ name, importPath }`), the component the fix names.
9
+ *
10
+ * Mark an intended exception with `hand-built-ok: <why>` on the line or the line above.
11
+ */
12
+ import { settingsFor } from "./lib.mjs";
13
+
14
+ const ID = "hand-built-button";
15
+ const LOOK_AHEAD = 8;
16
+ const FILLED = /(?<![\w-])bg-(?!transparent\b|none\b)[a-z]/;
17
+ const ROUNDED = /(?<![\w-])rounded(?!-full\b)(?![\w-]*-none)/;
18
+
19
+ export const handBuiltButton = {
20
+ id: ID,
21
+ title: "Hand-built button",
22
+ marker: "hand-built-ok",
23
+ order: 30,
24
+ scanFile({ lines, text, settings }) {
25
+ if (text === null) return [];
26
+ const { name, importPath } = settingsFor(settings, ID).$all.components.Button;
27
+ const all = text.split("\n");
28
+ const hits = [];
29
+ for (const { n, text: line } of lines) {
30
+ if (!/<button\b/.test(line)) continue;
31
+ const opening = [];
32
+ for (let i = n - 1; i < Math.min(all.length, n - 1 + LOOK_AHEAD); i++) {
33
+ opening.push(all[i]);
34
+ if (/>\s*$/.test(all[i]) && !/=>\s*$/.test(all[i])) break;
35
+ }
36
+ if (!FILLED.test(opening.join("\n")) || !ROUNDED.test(opening.join("\n"))) continue;
37
+ hits.push({
38
+ line: n,
39
+ found: "<button>",
40
+ message: `A native button with its own fill and rounded corners is a hand-built copy of \`${name}\`.`,
41
+ fix: `Use \`${name}\` from \`${importPath}\`. If the design system has no variant you need, flag it with \`hand-built-ok: <why>\`.`,
42
+ });
43
+ }
44
+ return hits;
45
+ },
46
+ };
@@ -0,0 +1,51 @@
1
+ /**
2
+ * HTML nesting. Flags a block element inside a native `<p>`.
3
+ *
4
+ * A `<p>` holds phrasing content only. A `<div>`, `<p>`, list, heading, `<section>`, `<article>`,
5
+ * `<hr>` or `<table>` inside it throws React hydration error #418 in the browser while the build passes.
6
+ * This check reads source, so it sees native tags only. A component that renders a `<div>` on its
7
+ * own, such as `Separator`, is not seen. Look at the rendered HTML for those.
8
+ *
9
+ * Mark an intended exception with `html-nesting-ok: <why>` on the line or the line above.
10
+ */
11
+ const BLOCK = /<(div|ul|ol|li|section|article|hr|table|h[1-6])(?=[\s/>])/g;
12
+ const OPEN_P = /<p(?=[\s>])/g;
13
+
14
+ export const htmlNesting = {
15
+ id: "html-nesting",
16
+ title: "Block inside a paragraph",
17
+ marker: "html-nesting-ok",
18
+ order: 100,
19
+ scanFile({ lines, text }) {
20
+ if (text === null) return [];
21
+ const added = new Set(lines.map((l) => l.n));
22
+ const all = text.split("\n");
23
+ const hits = [];
24
+ let depth = 0;
25
+ for (let i = 0; i < all.length; i++) {
26
+ const line = all[i];
27
+ const events = [];
28
+ for (const m of line.matchAll(OPEN_P)) events.push({ at: m.index, kind: "open" });
29
+ for (const m of line.matchAll(/<\/p>/g)) events.push({ at: m.index, kind: "close" });
30
+ for (const m of line.matchAll(BLOCK)) events.push({ at: m.index, kind: "block", tag: m[1] });
31
+ events.sort((a, b) => a.at - b.at);
32
+ for (const e of events) {
33
+ if (e.kind === "open") {
34
+ if (depth > 0 && added.has(i + 1)) hits.push(nested(i + 1, "p"));
35
+ depth++;
36
+ } else if (e.kind === "close") depth = Math.max(0, depth - 1);
37
+ else if (depth > 0 && added.has(i + 1)) hits.push(nested(i + 1, e.tag));
38
+ }
39
+ }
40
+ return hits;
41
+ },
42
+ };
43
+
44
+ function nested(line, tag) {
45
+ return {
46
+ line,
47
+ found: `<${tag}>`,
48
+ message: `A \`<${tag}>\` inside a \`<p>\` is invalid HTML. React reports hydration error #418.`,
49
+ fix: "Change the outer `<p>` to a `<div>`, or move the block out of it. If it is deliberate, flag it with `html-nesting-ok: <why>`.",
50
+ };
51
+ }