@monoes/monomindcli 2.15.6 → 2.16.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 (304) hide show
  1. package/.claude/helpers/build-skill-registry.cjs +23 -2
  2. package/.claude/helpers/handlers/route-handler.cjs +89 -3
  3. package/.claude/helpers/handlers/session-restore-handler.cjs +1 -1
  4. package/.claude/helpers/jev-picker.cjs +499 -0
  5. package/.claude/helpers/redact-secrets.cjs +69 -0
  6. package/.claude/skills/mastermind-agent-select/SKILL.md +28 -0
  7. package/dist/src/catalog/blueprints.d.ts +39 -0
  8. package/dist/src/catalog/blueprints.d.ts.map +1 -0
  9. package/dist/src/catalog/blueprints.js +78 -0
  10. package/dist/src/catalog/blueprints.js.map +1 -0
  11. package/dist/src/catalog/digest.d.ts +16 -0
  12. package/dist/src/catalog/digest.d.ts.map +1 -0
  13. package/dist/src/catalog/digest.js +62 -0
  14. package/dist/src/catalog/digest.js.map +1 -0
  15. package/dist/src/catalog/frontmatter.d.ts +23 -0
  16. package/dist/src/catalog/frontmatter.d.ts.map +1 -0
  17. package/dist/src/catalog/frontmatter.js +80 -0
  18. package/dist/src/catalog/frontmatter.js.map +1 -0
  19. package/dist/src/catalog/lifecycle.d.ts +31 -0
  20. package/dist/src/catalog/lifecycle.d.ts.map +1 -0
  21. package/dist/src/catalog/lifecycle.js +78 -0
  22. package/dist/src/catalog/lifecycle.js.map +1 -0
  23. package/dist/src/catalog/projection.d.ts +57 -0
  24. package/dist/src/catalog/projection.d.ts.map +1 -0
  25. package/dist/src/catalog/projection.js +272 -0
  26. package/dist/src/catalog/projection.js.map +1 -0
  27. package/dist/src/catalog/scan.d.ts +37 -0
  28. package/dist/src/catalog/scan.d.ts.map +1 -0
  29. package/dist/src/catalog/scan.js +214 -0
  30. package/dist/src/catalog/scan.js.map +1 -0
  31. package/dist/src/catalog/snapshot.d.ts +62 -0
  32. package/dist/src/catalog/snapshot.d.ts.map +1 -0
  33. package/dist/src/catalog/snapshot.js +183 -0
  34. package/dist/src/catalog/snapshot.js.map +1 -0
  35. package/dist/src/catalog/stage.d.ts +26 -0
  36. package/dist/src/catalog/stage.d.ts.map +1 -0
  37. package/dist/src/catalog/stage.js +316 -0
  38. package/dist/src/catalog/stage.js.map +1 -0
  39. package/dist/src/catalog/state.d.ts +23 -0
  40. package/dist/src/catalog/state.d.ts.map +1 -0
  41. package/dist/src/catalog/state.js +102 -0
  42. package/dist/src/catalog/state.js.map +1 -0
  43. package/dist/src/catalog/types.d.ts +289 -0
  44. package/dist/src/catalog/types.d.ts.map +1 -0
  45. package/dist/src/catalog/types.js +118 -0
  46. package/dist/src/catalog/types.js.map +1 -0
  47. package/dist/src/commands/catalog.d.ts +14 -0
  48. package/dist/src/commands/catalog.d.ts.map +1 -0
  49. package/dist/src/commands/catalog.js +392 -0
  50. package/dist/src/commands/catalog.js.map +1 -0
  51. package/dist/src/commands/doctor-catalog-checks.d.ts +3 -0
  52. package/dist/src/commands/doctor-catalog-checks.d.ts.map +1 -0
  53. package/dist/src/commands/doctor-catalog-checks.js +69 -0
  54. package/dist/src/commands/doctor-catalog-checks.js.map +1 -0
  55. package/dist/src/commands/doctor-decision-checks.d.ts +10 -0
  56. package/dist/src/commands/doctor-decision-checks.d.ts.map +1 -0
  57. package/dist/src/commands/doctor-decision-checks.js +82 -0
  58. package/dist/src/commands/doctor-decision-checks.js.map +1 -0
  59. package/dist/src/commands/doctor.d.ts.map +1 -1
  60. package/dist/src/commands/doctor.js +9 -1
  61. package/dist/src/commands/doctor.js.map +1 -1
  62. package/dist/src/commands/index.d.ts +2 -2
  63. package/dist/src/commands/index.d.ts.map +1 -1
  64. package/dist/src/commands/index.js +4 -1
  65. package/dist/src/commands/index.js.map +1 -1
  66. package/dist/src/commands/org-observe.d.ts.map +1 -1
  67. package/dist/src/commands/org-observe.js +7 -1
  68. package/dist/src/commands/org-observe.js.map +1 -1
  69. package/dist/src/commands/org-skills.d.ts.map +1 -1
  70. package/dist/src/commands/org-skills.js +14 -4
  71. package/dist/src/commands/org-skills.js.map +1 -1
  72. package/dist/src/commands/org.d.ts.map +1 -1
  73. package/dist/src/commands/org.js +8 -1
  74. package/dist/src/commands/org.js.map +1 -1
  75. package/dist/src/commands/pick.d.ts +4 -0
  76. package/dist/src/commands/pick.d.ts.map +1 -0
  77. package/dist/src/commands/pick.js +77 -0
  78. package/dist/src/commands/pick.js.map +1 -0
  79. package/dist/src/commands/route.js +1 -1
  80. package/dist/src/commands/route.js.map +1 -1
  81. package/dist/src/decision/catalogs.d.ts +20 -0
  82. package/dist/src/decision/catalogs.d.ts.map +1 -0
  83. package/dist/src/decision/catalogs.js +64 -0
  84. package/dist/src/decision/catalogs.js.map +1 -0
  85. package/dist/src/decision/jev.d.ts +85 -0
  86. package/dist/src/decision/jev.d.ts.map +1 -0
  87. package/dist/src/decision/jev.js +72 -0
  88. package/dist/src/decision/jev.js.map +1 -0
  89. package/dist/src/decision/picks.d.ts +50 -0
  90. package/dist/src/decision/picks.d.ts.map +1 -0
  91. package/dist/src/decision/picks.js +100 -0
  92. package/dist/src/decision/picks.js.map +1 -0
  93. package/dist/src/init/helpers-generator.d.ts.map +1 -1
  94. package/dist/src/init/helpers-generator.js +7 -0
  95. package/dist/src/init/helpers-generator.js.map +1 -1
  96. package/dist/src/orgrt/checkpoint-ops.d.ts.map +1 -1
  97. package/dist/src/orgrt/checkpoint-ops.js +6 -1
  98. package/dist/src/orgrt/checkpoint-ops.js.map +1 -1
  99. package/dist/src/orgrt/completion-gate.d.ts +15 -0
  100. package/dist/src/orgrt/completion-gate.d.ts.map +1 -1
  101. package/dist/src/orgrt/completion-gate.js +59 -3
  102. package/dist/src/orgrt/completion-gate.js.map +1 -1
  103. package/dist/src/orgrt/daemon.d.ts +18 -1
  104. package/dist/src/orgrt/daemon.d.ts.map +1 -1
  105. package/dist/src/orgrt/daemon.js +33 -3
  106. package/dist/src/orgrt/daemon.js.map +1 -1
  107. package/dist/src/orgrt/decisions.d.ts +24 -0
  108. package/dist/src/orgrt/decisions.d.ts.map +1 -1
  109. package/dist/src/orgrt/decisions.js +164 -18
  110. package/dist/src/orgrt/decisions.js.map +1 -1
  111. package/dist/src/orgrt/review-packet.d.ts +1 -1
  112. package/dist/src/orgrt/review-packet.d.ts.map +1 -1
  113. package/dist/src/orgrt/review-packet.js +2 -2
  114. package/dist/src/orgrt/review-packet.js.map +1 -1
  115. package/dist/src/orgrt/session.d.ts +9 -0
  116. package/dist/src/orgrt/session.d.ts.map +1 -1
  117. package/dist/src/orgrt/session.js +24 -2
  118. package/dist/src/orgrt/session.js.map +1 -1
  119. package/dist/src/orgrt/skill-library.d.ts +10 -1
  120. package/dist/src/orgrt/skill-library.d.ts.map +1 -1
  121. package/dist/src/orgrt/skill-library.js +53 -4
  122. package/dist/src/orgrt/skill-library.js.map +1 -1
  123. package/dist/src/orgrt/task-dag.d.ts +3 -0
  124. package/dist/src/orgrt/task-dag.d.ts.map +1 -1
  125. package/dist/src/orgrt/task-dag.js +6 -0
  126. package/dist/src/orgrt/task-dag.js.map +1 -1
  127. package/dist/src/orgrt/types.d.ts +2 -0
  128. package/dist/src/orgrt/types.d.ts.map +1 -1
  129. package/dist/src/orgrt/types.js +4 -0
  130. package/dist/src/orgrt/types.js.map +1 -1
  131. package/dist/src/platform-adapters/mutation.d.ts +34 -0
  132. package/dist/src/platform-adapters/mutation.d.ts.map +1 -0
  133. package/dist/src/platform-adapters/mutation.js +188 -0
  134. package/dist/src/platform-adapters/mutation.js.map +1 -0
  135. package/dist/src/platform-adapters/operations.d.ts +7 -1
  136. package/dist/src/platform-adapters/operations.d.ts.map +1 -1
  137. package/dist/src/platform-adapters/operations.js +18 -76
  138. package/dist/src/platform-adapters/operations.js.map +1 -1
  139. package/dist/src/routing/jev-step.d.ts +17 -0
  140. package/dist/src/routing/jev-step.d.ts.map +1 -0
  141. package/dist/src/routing/jev-step.js +27 -0
  142. package/dist/src/routing/jev-step.js.map +1 -0
  143. package/dist/src/routing/route-layer-factory.d.ts.map +1 -1
  144. package/dist/src/routing/route-layer-factory.js +16 -1
  145. package/dist/src/routing/route-layer-factory.js.map +1 -1
  146. package/dist/src/utils/redaction.d.ts.map +1 -1
  147. package/dist/src/utils/redaction.js +19 -4
  148. package/dist/src/utils/redaction.js.map +1 -1
  149. package/dist/tsconfig.tsbuildinfo +1 -1
  150. package/package.json +4 -4
  151. package/.claude/skills/monodesign/SKILL.md +0 -257
  152. package/.claude/skills/monodesign/adapt.md +0 -53
  153. package/.claude/skills/monodesign/agents/monodesign-asset-producer.md +0 -100
  154. package/.claude/skills/monodesign/agents/monodesign-manual-edit-applier.md +0 -103
  155. package/.claude/skills/monodesign/animate.md +0 -65
  156. package/.claude/skills/monodesign/audit.md +0 -89
  157. package/.claude/skills/monodesign/bolder.md +0 -50
  158. package/.claude/skills/monodesign/clarify.md +0 -64
  159. package/.claude/skills/monodesign/colorize.md +0 -68
  160. package/.claude/skills/monodesign/craft.md +0 -51
  161. package/.claude/skills/monodesign/critique.md +0 -66
  162. package/.claude/skills/monodesign/delight.md +0 -47
  163. package/.claude/skills/monodesign/distill.md +0 -56
  164. package/.claude/skills/monodesign/document.md +0 -83
  165. package/.claude/skills/monodesign/extract.md +0 -74
  166. package/.claude/skills/monodesign/harden.md +0 -65
  167. package/.claude/skills/monodesign/init.md +0 -30
  168. package/.claude/skills/monodesign/layout.md +0 -36
  169. package/.claude/skills/monodesign/live.md +0 -34
  170. package/.claude/skills/monodesign/onboard.md +0 -50
  171. package/.claude/skills/monodesign/optimize.md +0 -64
  172. package/.claude/skills/monodesign/overdrive.md +0 -56
  173. package/.claude/skills/monodesign/polish.md +0 -68
  174. package/.claude/skills/monodesign/quieter.md +0 -57
  175. package/.claude/skills/monodesign/reference/adapt.md +0 -312
  176. package/.claude/skills/monodesign/reference/adapt.native.md +0 -58
  177. package/.claude/skills/monodesign/reference/android.md +0 -40
  178. package/.claude/skills/monodesign/reference/animate.md +0 -203
  179. package/.claude/skills/monodesign/reference/antipatterns-catalog.md +0 -410
  180. package/.claude/skills/monodesign/reference/audit.md +0 -135
  181. package/.claude/skills/monodesign/reference/audit.native.md +0 -139
  182. package/.claude/skills/monodesign/reference/bolder.md +0 -120
  183. package/.claude/skills/monodesign/reference/brand-workflow.md +0 -180
  184. package/.claude/skills/monodesign/reference/brand.md +0 -108
  185. package/.claude/skills/monodesign/reference/clarify.md +0 -288
  186. package/.claude/skills/monodesign/reference/codex.md +0 -105
  187. package/.claude/skills/monodesign/reference/cognitive-load.md +0 -106
  188. package/.claude/skills/monodesign/reference/color-and-contrast.md +0 -105
  189. package/.claude/skills/monodesign/reference/colorize.md +0 -257
  190. package/.claude/skills/monodesign/reference/component-specs.md +0 -260
  191. package/.claude/skills/monodesign/reference/component-states.md +0 -274
  192. package/.claude/skills/monodesign/reference/component-system.md +0 -358
  193. package/.claude/skills/monodesign/reference/copy-formulas.md +0 -160
  194. package/.claude/skills/monodesign/reference/craft.md +0 -123
  195. package/.claude/skills/monodesign/reference/critique.md +0 -780
  196. package/.claude/skills/monodesign/reference/delight.md +0 -302
  197. package/.claude/skills/monodesign/reference/design-principles.md +0 -246
  198. package/.claude/skills/monodesign/reference/distill.md +0 -111
  199. package/.claude/skills/monodesign/reference/document.md +0 -429
  200. package/.claude/skills/monodesign/reference/extract.md +0 -69
  201. package/.claude/skills/monodesign/reference/harden.md +0 -347
  202. package/.claude/skills/monodesign/reference/heuristics-scoring.md +0 -234
  203. package/.claude/skills/monodesign/reference/hooks.md +0 -92
  204. package/.claude/skills/monodesign/reference/image-prompts.md +0 -130
  205. package/.claude/skills/monodesign/reference/init.md +0 -221
  206. package/.claude/skills/monodesign/reference/interaction-design.md +0 -189
  207. package/.claude/skills/monodesign/reference/ios.md +0 -45
  208. package/.claude/skills/monodesign/reference/layout.md +0 -185
  209. package/.claude/skills/monodesign/reference/live.md +0 -710
  210. package/.claude/skills/monodesign/reference/motion-design.md +0 -109
  211. package/.claude/skills/monodesign/reference/onboard.md +0 -234
  212. package/.claude/skills/monodesign/reference/optimize.md +0 -258
  213. package/.claude/skills/monodesign/reference/overdrive.md +0 -130
  214. package/.claude/skills/monodesign/reference/personas.md +0 -179
  215. package/.claude/skills/monodesign/reference/polish.md +0 -241
  216. package/.claude/skills/monodesign/reference/pre-delivery-checklist.md +0 -108
  217. package/.claude/skills/monodesign/reference/product.md +0 -60
  218. package/.claude/skills/monodesign/reference/quieter.md +0 -99
  219. package/.claude/skills/monodesign/reference/responsive-design.md +0 -114
  220. package/.claude/skills/monodesign/reference/shape.md +0 -165
  221. package/.claude/skills/monodesign/reference/spatial-design.md +0 -100
  222. package/.claude/skills/monodesign/reference/teach.md +0 -10
  223. package/.claude/skills/monodesign/reference/token-architecture.md +0 -222
  224. package/.claude/skills/monodesign/reference/typeset.md +0 -301
  225. package/.claude/skills/monodesign/reference/typography.md +0 -159
  226. package/.claude/skills/monodesign/reference/ux-research.md +0 -143
  227. package/.claude/skills/monodesign/reference/ux-rules.md +0 -211
  228. package/.claude/skills/monodesign/reference/ux-writing.md +0 -107
  229. package/.claude/skills/monodesign/scripts/command-metadata.json +0 -94
  230. package/.claude/skills/monodesign/scripts/context-signals.mjs +0 -260
  231. package/.claude/skills/monodesign/scripts/context.mjs +0 -1065
  232. package/.claude/skills/monodesign/scripts/critique-storage.mjs +0 -416
  233. package/.claude/skills/monodesign/scripts/detect-csp.mjs +0 -193
  234. package/.claude/skills/monodesign/scripts/detect.mjs +0 -33
  235. package/.claude/skills/monodesign/scripts/detector/browser/injected/index.mjs +0 -1960
  236. package/.claude/skills/monodesign/scripts/detector/cli/main.mjs +0 -321
  237. package/.claude/skills/monodesign/scripts/detector/design-system.mjs +0 -814
  238. package/.claude/skills/monodesign/scripts/detector/detect-antipatterns-browser.js +0 -5628
  239. package/.claude/skills/monodesign/scripts/detector/detect-antipatterns.mjs +0 -50
  240. package/.claude/skills/monodesign/scripts/detector/engines/browser/detect-url.mjs +0 -259
  241. package/.claude/skills/monodesign/scripts/detector/engines/browser/drivers.mjs +0 -339
  242. package/.claude/skills/monodesign/scripts/detector/engines/regex/detect-text.mjs +0 -636
  243. package/.claude/skills/monodesign/scripts/detector/engines/static-html/css-cascade.mjs +0 -1016
  244. package/.claude/skills/monodesign/scripts/detector/engines/static-html/detect-html.mjs +0 -253
  245. package/.claude/skills/monodesign/scripts/detector/engines/visual/screenshot-contrast.mjs +0 -198
  246. package/.claude/skills/monodesign/scripts/detector/findings.mjs +0 -12
  247. package/.claude/skills/monodesign/scripts/detector/fix/css-regions.mjs +0 -181
  248. package/.claude/skills/monodesign/scripts/detector/fix/fixers.mjs +0 -373
  249. package/.claude/skills/monodesign/scripts/detector/fix/index.mjs +0 -426
  250. package/.claude/skills/monodesign/scripts/detector/node/file-system.mjs +0 -198
  251. package/.claude/skills/monodesign/scripts/detector/profile/profiler.mjs +0 -166
  252. package/.claude/skills/monodesign/scripts/detector/registry/antipatterns.mjs +0 -563
  253. package/.claude/skills/monodesign/scripts/detector/rules/checks.mjs +0 -3024
  254. package/.claude/skills/monodesign/scripts/detector/shared/color.mjs +0 -124
  255. package/.claude/skills/monodesign/scripts/detector/shared/constants.mjs +0 -101
  256. package/.claude/skills/monodesign/scripts/detector/shared/fonts.mjs +0 -30
  257. package/.claude/skills/monodesign/scripts/detector/shared/inline-ignores.mjs +0 -148
  258. package/.claude/skills/monodesign/scripts/detector/shared/page.mjs +0 -7
  259. package/.claude/skills/monodesign/scripts/hook-admin.mjs +0 -694
  260. package/.claude/skills/monodesign/scripts/hook-before-edit.mjs +0 -516
  261. package/.claude/skills/monodesign/scripts/hook-lib.mjs +0 -1785
  262. package/.claude/skills/monodesign/scripts/hook.mjs +0 -61
  263. package/.claude/skills/monodesign/scripts/lib/design-parser.mjs +0 -809
  264. package/.claude/skills/monodesign/scripts/lib/is-generated.mjs +0 -69
  265. package/.claude/skills/monodesign/scripts/lib/monodesign-config.mjs +0 -640
  266. package/.claude/skills/monodesign/scripts/lib/monodesign-paths.mjs +0 -129
  267. package/.claude/skills/monodesign/scripts/lib/provider.mjs +0 -4
  268. package/.claude/skills/monodesign/scripts/lib/target-args.mjs +0 -42
  269. package/.claude/skills/monodesign/scripts/live/browser-script-parts.mjs +0 -50
  270. package/.claude/skills/monodesign/scripts/live/completion.mjs +0 -19
  271. package/.claude/skills/monodesign/scripts/live/event-validation.mjs +0 -137
  272. package/.claude/skills/monodesign/scripts/live/insert-ui.mjs +0 -458
  273. package/.claude/skills/monodesign/scripts/live/manual-apply.mjs +0 -939
  274. package/.claude/skills/monodesign/scripts/live/manual-edit-routes.mjs +0 -357
  275. package/.claude/skills/monodesign/scripts/live/manual-edits-buffer.mjs +0 -152
  276. package/.claude/skills/monodesign/scripts/live/session-store.mjs +0 -293
  277. package/.claude/skills/monodesign/scripts/live/svelte-component.mjs +0 -826
  278. package/.claude/skills/monodesign/scripts/live/sveltekit-adapter.mjs +0 -279
  279. package/.claude/skills/monodesign/scripts/live/ui-core.mjs +0 -180
  280. package/.claude/skills/monodesign/scripts/live/vocabulary.mjs +0 -36
  281. package/.claude/skills/monodesign/scripts/live-accept.mjs +0 -812
  282. package/.claude/skills/monodesign/scripts/live-browser-dom.js +0 -147
  283. package/.claude/skills/monodesign/scripts/live-browser-session.js +0 -124
  284. package/.claude/skills/monodesign/scripts/live-browser.js +0 -11213
  285. package/.claude/skills/monodesign/scripts/live-commit-manual-edits.mjs +0 -1241
  286. package/.claude/skills/monodesign/scripts/live-complete.mjs +0 -75
  287. package/.claude/skills/monodesign/scripts/live-copy-edit-agent.mjs +0 -683
  288. package/.claude/skills/monodesign/scripts/live-discard-manual-edits.mjs +0 -51
  289. package/.claude/skills/monodesign/scripts/live-inject.mjs +0 -596
  290. package/.claude/skills/monodesign/scripts/live-insert.mjs +0 -272
  291. package/.claude/skills/monodesign/scripts/live-manual-edit-evidence.mjs +0 -363
  292. package/.claude/skills/monodesign/scripts/live-poll.mjs +0 -384
  293. package/.claude/skills/monodesign/scripts/live-resume.mjs +0 -94
  294. package/.claude/skills/monodesign/scripts/live-server.mjs +0 -1210
  295. package/.claude/skills/monodesign/scripts/live-status.mjs +0 -61
  296. package/.claude/skills/monodesign/scripts/live-target.mjs +0 -30
  297. package/.claude/skills/monodesign/scripts/live-wrap.mjs +0 -884
  298. package/.claude/skills/monodesign/scripts/live.mjs +0 -297
  299. package/.claude/skills/monodesign/scripts/modern-screenshot.umd.js +0 -14
  300. package/.claude/skills/monodesign/scripts/palette.mjs +0 -635
  301. package/.claude/skills/monodesign/scripts/pin.mjs +0 -221
  302. package/.claude/skills/monodesign/shape.md +0 -71
  303. package/.claude/skills/monodesign/teach.md +0 -18
  304. package/.claude/skills/monodesign/typeset.md +0 -59
@@ -1,814 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
-
4
- import { finding } from './findings.mjs';
5
- import { GENERIC_FONTS } from './shared/constants.mjs';
6
- import { parseAnyColor, resolveLengthPx } from './rules/checks.mjs';
7
-
8
- const DESIGN_NAMES = ['DESIGN.md', 'Design.md', 'design.md'];
9
- const FALLBACK_DIRS = ['.agents/context', 'docs'];
10
- const COLOR_CHANNEL_TOLERANCE = 6;
11
- const RADIUS_TOLERANCE_PX = 0.5;
12
- const FONT_SIZE_TOLERANCE_PX = 0.5;
13
- const FONT_SIZE_LITERAL_RE = /^-?[\d.]+(?:px|rem)$/;
14
-
15
- const CSS_COLOR_RE = /#[0-9a-f]{3,8}\b|rgba?\([^)]+\)|oklch\([^)]+\)|hsla?\([^)]+\)/gi;
16
- const FONT_DECL_RE = /font-family\s*:\s*([^;}\n]+)/gi;
17
- const FONT_JS_RE = /fontFamily\s*[:=]\s*["'`]([^"'`]+)["'`]/g;
18
- const GOOGLE_FONT_RE = /fonts\.googleapis\.com\/css2?\?[^"'\s)<>]*/gi;
19
- const BORDER_RADIUS_RE = /border-radius\s*:\s*([^;}\n]+)/gi;
20
- const BORDER_RADIUS_JS_RE = /borderRadius\s*[:=]\s*["'`]([^"'`]+)["'`]/g;
21
- const FONT_SIZE_DECL_RE = /font-size\s*:\s*([^;}\n]+)/gi;
22
- const FONT_SIZE_JS_RE = /fontSize\s*[:=]\s*["'`]([^"'`]+)["'`]/g;
23
- const TAILWIND_FONT_SIZE_RE = /\btext-\[(-?[\d.]+(?:px|rem))\]/g;
24
- const STATIC_DESIGN_SKIP_TAGS = new Set(['head', 'title', 'meta', 'link', 'style', 'script', 'noscript', 'template', 'source']);
25
-
26
- function firstExisting(dir, names) {
27
- for (const name of names) {
28
- const abs = path.join(dir, name);
29
- if (fs.existsSync(abs)) return abs;
30
- }
31
- return null;
32
- }
33
-
34
- function resolveDesignMdPath(cwd = process.cwd()) {
35
- const root = firstExisting(cwd, DESIGN_NAMES);
36
- if (root) return { path: root, contextDir: cwd };
37
-
38
- for (const rel of FALLBACK_DIRS) {
39
- const dir = path.resolve(cwd, rel);
40
- const found = firstExisting(dir, DESIGN_NAMES);
41
- if (found) return { path: found, contextDir: dir };
42
- }
43
-
44
- return null;
45
- }
46
-
47
- function resolveDesignSidecarPath(cwd = process.cwd(), contextDir = cwd) {
48
- const candidates = [
49
- path.join(cwd, '.monodesign', 'design.json'),
50
- path.join(cwd, 'DESIGN.json'),
51
- path.join(contextDir, 'DESIGN.json'),
52
- ];
53
- return candidates.find((candidate, index) =>
54
- candidates.indexOf(candidate) === index && fs.existsSync(candidate)
55
- ) || null;
56
- }
57
-
58
- function parseFrontmatter(md) {
59
- const lines = String(md || '').split(/\r?\n/);
60
- if (lines[0]?.trim() !== '---') return null;
61
- let end = -1;
62
- for (let i = 1; i < lines.length; i++) {
63
- if (lines[i].trim() === '---') { end = i; break; }
64
- }
65
- if (end === -1) return null;
66
- try {
67
- return parseYamlSubset(lines.slice(1, end).join('\n'));
68
- } catch {
69
- return null;
70
- }
71
- }
72
-
73
- function parseYamlSubset(yaml) {
74
- const root = {};
75
- const stack = [{ indent: -1, obj: root }];
76
-
77
- for (const raw of String(yaml || '').split(/\r?\n/)) {
78
- if (!raw.trim() || /^\s*#/.test(raw)) continue;
79
- const indent = raw.match(/^\s*/)[0].length;
80
- const content = raw.slice(indent);
81
- const colonIdx = findTopLevelColon(content);
82
- if (colonIdx === -1) continue;
83
-
84
- while (stack.length > 1 && stack[stack.length - 1].indent >= indent) stack.pop();
85
-
86
- const key = unquoteYamlKey(content.slice(0, colonIdx).trim());
87
- const rest = stripInlineYamlComment(content.slice(colonIdx + 1).trim());
88
- const parent = stack[stack.length - 1].obj;
89
-
90
- if (rest === '') {
91
- const obj = {};
92
- parent[key] = obj;
93
- stack.push({ indent, obj });
94
- } else {
95
- parent[key] = parseScalar(rest);
96
- }
97
- }
98
-
99
- return root;
100
- }
101
-
102
- function findTopLevelColon(s) {
103
- let inQuote = null;
104
- for (let i = 0; i < s.length; i++) {
105
- const ch = s[i];
106
- if (inQuote) {
107
- if (ch === inQuote && s[i - 1] !== '\\') inQuote = null;
108
- } else if (ch === '"' || ch === "'") {
109
- inQuote = ch;
110
- } else if (ch === ':') {
111
- return i;
112
- }
113
- }
114
- return -1;
115
- }
116
-
117
- function unquoteYamlKey(key) {
118
- if ((key.startsWith('"') && key.endsWith('"')) || (key.startsWith("'") && key.endsWith("'"))) {
119
- return key.slice(1, -1);
120
- }
121
- return key;
122
- }
123
-
124
- function stripInlineYamlComment(s) {
125
- let inQuote = null;
126
- for (let i = 0; i < s.length; i++) {
127
- const ch = s[i];
128
- if (inQuote) {
129
- if (ch === inQuote && s[i - 1] !== '\\') inQuote = null;
130
- } else if (ch === '"' || ch === "'") {
131
- inQuote = ch;
132
- } else if (ch === '#' && i > 0 && /\s/.test(s[i - 1])) {
133
- return s.slice(0, i).trimEnd();
134
- }
135
- }
136
- return s;
137
- }
138
-
139
- function parseScalar(raw) {
140
- const s = raw.trim();
141
- if ((s.startsWith('"') && s.endsWith('"')) || (s.startsWith("'") && s.endsWith("'"))) {
142
- return s.slice(1, -1);
143
- }
144
- if (s === 'true') return true;
145
- if (s === 'false') return false;
146
- if (s === 'null' || s === '~') return null;
147
- if (/^-?\d+$/.test(s)) return Number(s);
148
- if (/^-?\d*\.\d+$/.test(s)) return Number(s);
149
- return s;
150
- }
151
-
152
- function safeReadJson(filePath) {
153
- if (!filePath) return null;
154
- try {
155
- return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
156
- } catch {
157
- return null;
158
- }
159
- }
160
-
161
- function normalizeFontName(value) {
162
- return String(value || '')
163
- .trim()
164
- .replace(/\s*!important\s*$/i, '')
165
- .trim()
166
- .replace(/^["']|["']$/g, '')
167
- .replace(/\+/g, ' ')
168
- .replace(/\s+/g, ' ')
169
- .toLowerCase();
170
- }
171
-
172
- function splitFontStack(stack) {
173
- return String(stack || '')
174
- .replace(/\s*!important\s*$/i, '')
175
- .split(',')
176
- .map(normalizeFontName)
177
- .filter(Boolean);
178
- }
179
-
180
- function primaryFont(stack) {
181
- if (!stack || /var\(/i.test(stack) || !isLiteralFontStack(stack)) return '';
182
- return splitFontStack(stack).find(font => !GENERIC_FONTS.has(font)) || '';
183
- }
184
-
185
- function isLiteralFontStack(stack) {
186
- const text = String(stack || '');
187
- return !/[$`{}]|\s\+\s|\|\|/.test(text);
188
- }
189
-
190
- function cssColorLabel(raw) {
191
- return String(raw || '').trim().replace(/\s+/g, ' ');
192
- }
193
-
194
- function colorKey(color) {
195
- if (!color) return '';
196
- return `${color.r},${color.g},${color.b}`;
197
- }
198
-
199
- function colorsClose(a, b) {
200
- if (!a || !b) return false;
201
- return Math.max(
202
- Math.abs(a.r - b.r),
203
- Math.abs(a.g - b.g),
204
- Math.abs(a.b - b.b),
205
- ) <= COLOR_CHANNEL_TOLERANCE;
206
- }
207
-
208
- function hslToRgb(H, S, L, alpha = 1) {
209
- const h = (((H % 360) + 360) % 360) / 360;
210
- const s = Math.max(0, Math.min(1, S));
211
- const l = Math.max(0, Math.min(1, L));
212
- const hue2rgb = (p, q, t) => {
213
- if (t < 0) t += 1;
214
- if (t > 1) t -= 1;
215
- if (t < 1 / 6) return p + (q - p) * 6 * t;
216
- if (t < 1 / 2) return q;
217
- if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
218
- return p;
219
- };
220
- const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
221
- const p = 2 * l - q;
222
- return {
223
- r: Math.round(hue2rgb(p, q, h + 1 / 3) * 255),
224
- g: Math.round(hue2rgb(p, q, h) * 255),
225
- b: Math.round(hue2rgb(p, q, h - 1 / 3) * 255),
226
- a: alpha,
227
- };
228
- }
229
-
230
- function parseDesignColor(value) {
231
- const text = String(value || '').trim();
232
- const parsed = parseAnyColor(text);
233
- if (parsed) return parsed;
234
- const hsl = text.match(/hsla?\(\s*([-\d.]+)(?:deg)?\s*,?\s*([\d.]+)%\s*,?\s*([\d.]+)%(?:\s*[,/]\s*([\d.]+))?\s*\)/i);
235
- if (hsl) {
236
- return hslToRgb(
237
- parseFloat(hsl[1]),
238
- parseFloat(hsl[2]) / 100,
239
- parseFloat(hsl[3]) / 100,
240
- hsl[4] !== undefined ? parseFloat(hsl[4]) : 1,
241
- );
242
- }
243
- return null;
244
- }
245
-
246
- function addDesignColor(out, value, label) {
247
- const parsed = parseDesignColor(value);
248
- if (!parsed) return;
249
- const key = colorKey(parsed);
250
- if (!out.allowedColorKeys.has(key)) {
251
- out.allowedColorKeys.set(key, { color: parsed, labels: [] });
252
- }
253
- out.allowedColorKeys.get(key).labels.push(label || cssColorLabel(value));
254
- }
255
-
256
- function addColorObject(out, colors, prefix = 'colors') {
257
- if (!colors || typeof colors !== 'object') return;
258
- for (const [name, value] of Object.entries(colors)) {
259
- if (typeof value === 'string') {
260
- addDesignColor(out, value, `${prefix}.${name}`);
261
- }
262
- }
263
- }
264
-
265
- function addSidecarColors(out, sidecar) {
266
- const colorMeta = sidecar?.extensions?.colorMeta;
267
- if (!colorMeta || typeof colorMeta !== 'object') return;
268
-
269
- for (const [name, meta] of Object.entries(colorMeta)) {
270
- if (!meta || typeof meta !== 'object') continue;
271
- if (typeof meta.canonical === 'string') addDesignColor(out, meta.canonical, `sidecar.${name}`);
272
- if (Array.isArray(meta.tonalRamp)) {
273
- for (const [index, value] of meta.tonalRamp.entries()) {
274
- if (typeof value === 'string') addDesignColor(out, value, `sidecar.${name}.tonalRamp[${index}]`);
275
- }
276
- }
277
- }
278
- }
279
-
280
- function addTypographyFonts(out, typography) {
281
- if (!typography || typeof typography !== 'object') return;
282
- for (const role of Object.values(typography)) {
283
- if (!role || typeof role !== 'object') continue;
284
- if (typeof role.fontFamily !== 'string') continue;
285
- for (const font of splitFontStack(role.fontFamily)) {
286
- if (!GENERIC_FONTS.has(font)) out.allowedFonts.add(font);
287
- }
288
- }
289
- }
290
-
291
- function addTypographySizes(out, typography) {
292
- if (!typography || typeof typography !== 'object') return;
293
- for (const role of Object.values(typography)) {
294
- if (!role || typeof role !== 'object') continue;
295
- const raw = String(role.fontSize ?? '').trim().toLowerCase();
296
- if (!FONT_SIZE_LITERAL_RE.test(raw)) continue;
297
- const px = resolveLengthPx(raw, 16);
298
- if (px == null || !Number.isFinite(px) || px <= 0) continue;
299
- out.allowedFontSizes.push({ value: raw, px });
300
- }
301
- }
302
-
303
- function addRoundedScale(out, rounded) {
304
- if (!rounded || typeof rounded !== 'object') return;
305
- for (const [rawName, value] of Object.entries(rounded)) {
306
- const name = unquoteYamlKey(rawName).toLowerCase();
307
- addRoundedToken(out, name, value);
308
- }
309
- }
310
-
311
- function addRoundedToken(out, name, value) {
312
- if (typeof value !== 'string' && typeof value !== 'number') return;
313
- const raw = String(value).trim();
314
- if (!raw || /var\(/i.test(raw) || raw.includes('%')) return;
315
- const px = resolveLengthPx(raw, 16);
316
- if (px == null || !Number.isFinite(px)) return;
317
- out.allowedRadii.push({ name, value: raw, px });
318
- if (/(^|\.)(full|pill|round|rounded-full)$/.test(name)) out.hasPillRadius = true;
319
- }
320
-
321
- function addSidecarRadii(out, sidecar) {
322
- const roundedMeta = sidecar?.extensions?.roundedMeta;
323
- if (!roundedMeta || typeof roundedMeta !== 'object') return;
324
-
325
- for (const [rawName, meta] of Object.entries(roundedMeta)) {
326
- const name = unquoteYamlKey(rawName).toLowerCase();
327
- if (typeof meta === 'string' || typeof meta === 'number') {
328
- addRoundedToken(out, `sidecar.${name}`, meta);
329
- continue;
330
- }
331
- if (!meta || typeof meta !== 'object') continue;
332
- for (const key of ['canonical', 'value']) {
333
- if (typeof meta[key] === 'string' || typeof meta[key] === 'number') {
334
- addRoundedToken(out, `sidecar.${name}.${key}`, meta[key]);
335
- }
336
- }
337
- for (const key of ['values', 'aliases']) {
338
- if (!Array.isArray(meta[key])) continue;
339
- for (const [index, value] of meta[key].entries()) {
340
- addRoundedToken(out, `sidecar.${name}.${key}[${index}]`, value);
341
- }
342
- }
343
- if (/^(full|pill|round|rounded-full)$/.test(name) || /^(full|pill|round)$/i.test(String(meta.role || ''))) {
344
- out.hasPillRadius = true;
345
- }
346
- }
347
- }
348
-
349
- function normalizeDesignSystem(input = {}) {
350
- const frontmatter = input.frontmatter || {};
351
- const sidecar = input.sidecar || null;
352
- const out = {
353
- present: true,
354
- sourcePath: input.sourcePath || null,
355
- sidecarPath: input.sidecarPath || null,
356
- mdNewerThanJson: input.mdNewerThanJson === true,
357
- allowedFonts: new Set(),
358
- allowedColorKeys: new Map(),
359
- allowedRadii: [],
360
- allowedFontSizes: [],
361
- hasPillRadius: false,
362
- };
363
-
364
- addTypographyFonts(out, frontmatter.typography);
365
- addTypographySizes(out, frontmatter.typography);
366
- addColorObject(out, frontmatter.colors);
367
- addSidecarColors(out, sidecar);
368
- addRoundedScale(out, frontmatter.rounded);
369
- addSidecarRadii(out, sidecar);
370
-
371
- out.hasFonts = out.allowedFonts.size > 0;
372
- out.hasColors = out.allowedColorKeys.size > 0;
373
- out.hasRadii = out.allowedRadii.length > 0;
374
- out.hasFontSizes = out.allowedFontSizes.length > 0;
375
- return out;
376
- }
377
-
378
- function loadDesignSystemForCwd(cwd = process.cwd()) {
379
- const md = resolveDesignMdPath(cwd);
380
- if (!md) return null;
381
-
382
- let frontmatter = null;
383
- let mdStat = null;
384
- try {
385
- mdStat = fs.statSync(md.path);
386
- frontmatter = parseFrontmatter(fs.readFileSync(md.path, 'utf-8'));
387
- } catch {
388
- return null;
389
- }
390
- if (!frontmatter || typeof frontmatter !== 'object') return null;
391
-
392
- const sidecarPath = resolveDesignSidecarPath(cwd, md.contextDir);
393
- const sidecar = safeReadJson(sidecarPath);
394
- let sidecarStat = null;
395
- try {
396
- if (sidecarPath) sidecarStat = fs.statSync(sidecarPath);
397
- } catch {
398
- sidecarStat = null;
399
- }
400
-
401
- return normalizeDesignSystem({
402
- frontmatter,
403
- sidecar,
404
- sourcePath: md.path,
405
- sidecarPath,
406
- mdNewerThanJson: !!(mdStat && sidecarStat && mdStat.mtimeMs > sidecarStat.mtimeMs + 1000),
407
- });
408
- }
409
-
410
- function isAllowedFont(font, designSystem) {
411
- if (!font || GENERIC_FONTS.has(font)) return true;
412
- if (!designSystem?.hasFonts) return true;
413
- return designSystem.allowedFonts.has(font);
414
- }
415
-
416
- function isAllowedColorRaw(raw, designSystem) {
417
- if (!designSystem?.hasColors) return true;
418
- const text = String(raw || '').trim().toLowerCase();
419
- if (!text || text === 'transparent' || text === 'currentcolor' || text === 'inherit' || text === 'initial') return true;
420
- if (text.includes('var(')) return true;
421
- const parsed = parseDesignColor(text);
422
- if (!parsed) return true;
423
- if ((parsed.a ?? 1) <= 0.05) return true;
424
- for (const entry of designSystem.allowedColorKeys.values()) {
425
- if (colorsClose(parsed, entry.color)) return true;
426
- }
427
- return false;
428
- }
429
-
430
- function isAllowedRadiusRaw(raw, designSystem) {
431
- if (!designSystem?.hasRadii) return true;
432
- const text = String(raw || '').trim().toLowerCase();
433
- if (!text || text === '0' || text === 'none' || text === 'initial' || text === 'inherit') return true;
434
- if (text.includes('var(') || text.includes('%')) return true;
435
- const px = resolveLengthPx(text, 16);
436
- if (px == null || !Number.isFinite(px) || px <= RADIUS_TOLERANCE_PX) return true;
437
- if (designSystem.hasPillRadius && px >= 99) return true;
438
- return designSystem.allowedRadii.some(entry => Math.abs(entry.px - px) <= RADIUS_TOLERANCE_PX);
439
- }
440
-
441
- function isAllowedFontSizeRaw(raw, designSystem) {
442
- if (!designSystem?.hasFontSizes) return true;
443
- const text = String(raw || '').trim().toLowerCase().replace(/\s*!important\s*$/, '');
444
- if (!FONT_SIZE_LITERAL_RE.test(text)) return true;
445
- const px = resolveLengthPx(text, 16);
446
- if (px == null || !Number.isFinite(px) || px <= 0) return true;
447
- return designSystem.allowedFontSizes.some(
448
- entry => Math.abs(entry.px - px) <= FONT_SIZE_TOLERANCE_PX,
449
- );
450
- }
451
-
452
- function lineLooksCommented(line) {
453
- const trimmed = String(line || '').trim();
454
- return trimmed.startsWith('//') || trimmed.startsWith('/*') || trimmed.startsWith('*') || trimmed.startsWith('<!--');
455
- }
456
-
457
- function isProbablyColorLiteral(line, match) {
458
- const raw = match?.[0] || '';
459
- const index = match.index ?? -1;
460
- if (index < 0) return false;
461
- if (isInsideCssAttributeSelector(line, index)) return false;
462
-
463
- const before = line.slice(0, index);
464
- const after = line.slice(index + raw.length);
465
-
466
- if (raw.startsWith('#')) {
467
- if (before.endsWith('&')) return false; // HTML numeric entity, e.g. &#8596;
468
-
469
- const prevNonSpace = before.match(/\S(?=\s*$)/)?.[0] || '';
470
- const nextNonSpace = after.match(/^\s*(\S)/)?.[1] || '';
471
- if (prevNonSpace === '>' && nextNonSpace === '<') return false; // plain text, e.g. PR #155
472
- }
473
-
474
- const styleContext = /(?:^|[{\s;"'`(,])(?:color|background(?:-color|-image)?|border(?:-(?:top|right|bottom|left))?(?:-color)?|outline(?:-color)?|box-shadow|text-shadow|fill|stroke)\s*:\s*[^;{}"'`]*/i.test(before);
475
- const cssFunctionContext = /(?:linear-gradient|radial-gradient|conic-gradient|color-mix)\([^)]*$/i.test(before);
476
- const jsColorKeyContext = /(?:^|[,{]\s*)(?:color|background|backgroundColor|borderColor|outlineColor|fill|stroke|boxShadow|textShadow)\s*[:=]\s*["'`]?[^"'`,}]*/i.test(before);
477
-
478
- return styleContext || cssFunctionContext || jsColorKeyContext;
479
- }
480
-
481
- function isInsideCssAttributeSelector(line, index) {
482
- if (index < 0) return false;
483
- const before = line.slice(0, index);
484
- const lastOpen = before.lastIndexOf('[');
485
- if (lastOpen === -1) return false;
486
- const lastClose = before.lastIndexOf(']');
487
- if (lastClose > lastOpen) return false;
488
- const after = line.slice(index);
489
- const close = after.indexOf(']');
490
- const block = after.indexOf('{');
491
- return close !== -1 && (block === -1 || close < block);
492
- }
493
-
494
- function makeDesignFinding(id, filePath, snippet, line = 0, extras = {}) {
495
- return { ...finding(id, filePath, snippet, line), ...extras };
496
- }
497
-
498
- function decodeGoogleFamily(value) {
499
- const family = String(value || '').split(':')[0].replace(/\+/g, ' ');
500
- try {
501
- return decodeURIComponent(family);
502
- } catch {
503
- return family;
504
- }
505
- }
506
-
507
- function checkFontStack(stack, filePath, line, designSystem, context) {
508
- const primary = primaryFont(stack);
509
- if (!primary || isAllowedFont(primary, designSystem)) return [];
510
- const display = primary.replace(/\b\w/g, ch => ch.toUpperCase());
511
- return [makeDesignFinding(
512
- 'design-system-font',
513
- filePath,
514
- `${context}: ${display} is not declared in DESIGN.md typography`,
515
- line,
516
- { ignoreValue: display },
517
- )];
518
- }
519
-
520
- function extractRadiusTokens(value) {
521
- return String(value || '')
522
- .replace(/\s*\/\s*/g, ' ')
523
- .split(/\s+/)
524
- .map(token => token.trim())
525
- .filter(Boolean);
526
- }
527
-
528
- function checkRadiusValue(value, filePath, line, designSystem, context) {
529
- const findings = [];
530
- for (const token of extractRadiusTokens(value)) {
531
- if (isAllowedRadiusRaw(token, designSystem)) continue;
532
- findings.push(makeDesignFinding(
533
- 'design-system-radius',
534
- filePath,
535
- `${context}: ${token} is outside the DESIGN.md rounded scale`,
536
- line,
537
- { ignoreValue: token },
538
- ));
539
- }
540
- return findings;
541
- }
542
-
543
- function checkFontSizeValue(value, filePath, line, designSystem, context) {
544
- const token = String(value || '').trim();
545
- if (isAllowedFontSizeRaw(token, designSystem)) return [];
546
- return [makeDesignFinding(
547
- 'design-system-font-size',
548
- filePath,
549
- `${context}: ${token} is off the DESIGN.md type ramp`,
550
- line,
551
- { ignoreValue: token },
552
- )];
553
- }
554
-
555
- function checkSourceDesignSystem(content, filePath, options = {}) {
556
- const designSystem = options.designSystem;
557
- if (!designSystem?.present) return [];
558
-
559
- const findings = [];
560
- const lines = String(content || '').split('\n');
561
- for (let i = 0; i < lines.length; i++) {
562
- const line = lines[i];
563
- const lineNum = i + 1;
564
- if (lineLooksCommented(line)) continue;
565
-
566
- if (designSystem.hasFonts) {
567
- for (const match of line.matchAll(FONT_DECL_RE)) {
568
- findings.push(...checkFontStack(match[1], filePath, lineNum, designSystem, 'font-family'));
569
- }
570
- for (const match of line.matchAll(FONT_JS_RE)) {
571
- findings.push(...checkFontStack(match[1], filePath, lineNum, designSystem, 'fontFamily'));
572
- }
573
- for (const match of line.matchAll(GOOGLE_FONT_RE)) {
574
- const url = match[0];
575
- for (const familyMatch of url.matchAll(/[?&]family=([^&]+)/g)) {
576
- const font = normalizeFontName(decodeGoogleFamily(familyMatch[1]));
577
- if (!font || isAllowedFont(font, designSystem)) continue;
578
- const display = decodeGoogleFamily(familyMatch[1]);
579
- findings.push(makeDesignFinding(
580
- 'design-system-font',
581
- filePath,
582
- `Google Fonts: ${display} is not declared in DESIGN.md typography`,
583
- lineNum,
584
- { ignoreValue: display },
585
- ));
586
- }
587
- }
588
- }
589
-
590
- if (designSystem.hasColors) {
591
- for (const match of line.matchAll(CSS_COLOR_RE)) {
592
- if (!isProbablyColorLiteral(line, match)) continue;
593
- const raw = cssColorLabel(match[0]);
594
- if (isAllowedColorRaw(raw, designSystem)) continue;
595
- findings.push(makeDesignFinding(
596
- 'design-system-color',
597
- filePath,
598
- `Undocumented color ${raw} is outside DESIGN.md colors`,
599
- lineNum,
600
- { ignoreValue: raw },
601
- ));
602
- }
603
- }
604
-
605
- if (designSystem.hasRadii) {
606
- for (const match of line.matchAll(BORDER_RADIUS_RE)) {
607
- findings.push(...checkRadiusValue(match[1], filePath, lineNum, designSystem, 'border-radius'));
608
- }
609
- for (const match of line.matchAll(BORDER_RADIUS_JS_RE)) {
610
- findings.push(...checkRadiusValue(match[1], filePath, lineNum, designSystem, 'borderRadius'));
611
- }
612
- }
613
-
614
- if (designSystem.hasFontSizes) {
615
- for (const match of line.matchAll(FONT_SIZE_DECL_RE)) {
616
- findings.push(...checkFontSizeValue(match[1], filePath, lineNum, designSystem, 'font-size'));
617
- }
618
- for (const match of line.matchAll(FONT_SIZE_JS_RE)) {
619
- findings.push(...checkFontSizeValue(match[1], filePath, lineNum, designSystem, 'fontSize'));
620
- }
621
- for (const match of line.matchAll(TAILWIND_FONT_SIZE_RE)) {
622
- findings.push(...checkFontSizeValue(match[1], filePath, lineNum, designSystem, 'text-[…] class'));
623
- }
624
- }
625
- }
626
-
627
- return dedupeDesignFindings(findings);
628
- }
629
-
630
- function hasDirectText(el) {
631
- return Array.from(el.childNodes || []).some(node => node.nodeType === 3 && node.textContent.trim().length > 0);
632
- }
633
-
634
- function sampleText(el) {
635
- const text = String(el.textContent || '').replace(/\s+/g, ' ').trim();
636
- return text ? ` "${text.slice(0, 40)}"` : '';
637
- }
638
-
639
- // Font-size design-system checks are source-scan-only (see checkSourceDesignSystem).
640
- // Computed font-size cascades and clamp() ramps resolve to off-ramp px in the browser.
641
- function collectStaticDesignSystemFindings(document, window, filePath, designSystem) {
642
- if (!designSystem?.present) return [];
643
- const findings = [];
644
- const seenFonts = new Set();
645
- const seenColors = new Set();
646
- const seenRadii = new Set();
647
-
648
- for (const el of document.querySelectorAll('*')) {
649
- if (shouldSkipStaticDesignElement(el, window)) continue;
650
- const tag = el.tagName?.toLowerCase?.() || 'unknown';
651
- const style = window.getComputedStyle(el);
652
-
653
- if (designSystem.hasFonts && hasDirectText(el)) {
654
- const font = primaryFont(style.fontFamily || '');
655
- if (font && !seenFonts.has(font) && !isAllowedFont(font, designSystem)) {
656
- seenFonts.add(font);
657
- findings.push(makeDesignFinding(
658
- 'design-system-font',
659
- filePath,
660
- `${tag}${sampleText(el)} uses ${font}; not declared in DESIGN.md typography`,
661
- 0,
662
- { ignoreValue: font },
663
- ));
664
- }
665
- }
666
-
667
- if (designSystem.hasColors) {
668
- const colorChecks = [];
669
- if (hasDirectText(el)) colorChecks.push(['text color', style.color]);
670
- if (!isTransparentCss(style.backgroundColor)) colorChecks.push(['background', style.backgroundColor]);
671
- for (const side of ['Top', 'Right', 'Bottom', 'Left']) {
672
- if ((parseFloat(style[`border${side}Width`]) || 0) > 0) {
673
- colorChecks.push([`border-${side.toLowerCase()}`, style[`border${side}Color`]]);
674
- }
675
- }
676
- if ((parseFloat(style.outlineWidth) || 0) > 0) colorChecks.push(['outline', style.outlineColor]);
677
-
678
- for (const [kind, raw] of colorChecks) {
679
- const label = cssColorLabel(raw);
680
- if (isAllowedColorRaw(label, designSystem)) continue;
681
- const key = `${kind}:${label}`;
682
- if (seenColors.has(key)) continue;
683
- seenColors.add(key);
684
- findings.push(makeDesignFinding(
685
- 'design-system-color',
686
- filePath,
687
- `${kind} ${label} on ${tag}${sampleText(el)} is outside DESIGN.md colors`,
688
- 0,
689
- { ignoreValue: label },
690
- ));
691
- }
692
- }
693
-
694
- if (designSystem.hasRadii) {
695
- const rawRadius = String(style.borderRadius || '').trim();
696
- if (!rawRadius) continue;
697
- for (const token of extractRadiusTokens(rawRadius)) {
698
- if (isAllowedRadiusRaw(token, designSystem)) continue;
699
- if (seenRadii.has(token)) continue;
700
- seenRadii.add(token);
701
- findings.push(makeDesignFinding(
702
- 'design-system-radius',
703
- filePath,
704
- `border-radius ${token} on ${tag}${sampleText(el)} is outside the DESIGN.md rounded scale`,
705
- 0,
706
- { ignoreValue: token },
707
- ));
708
- }
709
- }
710
- }
711
-
712
- return findings;
713
- }
714
-
715
- function shouldSkipStaticDesignElement(el, window) {
716
- const tag = el.tagName?.toLowerCase?.() || '';
717
- if (STATIC_DESIGN_SKIP_TAGS.has(tag)) return true;
718
-
719
- let current = el;
720
- while (current) {
721
- if (current.getAttribute?.('hidden') !== null || current.getAttribute?.('aria-hidden') === 'true') return true;
722
- const style = window.getComputedStyle(current);
723
- const display = String(style.display || '').toLowerCase();
724
- const visibility = String(style.visibility || '').toLowerCase();
725
- if (display === 'none' || visibility === 'hidden' || visibility === 'collapse') return true;
726
- current = current.parentElement;
727
- }
728
- return false;
729
- }
730
-
731
- function isTransparentCss(value) {
732
- const text = String(value || '').trim().toLowerCase();
733
- if (!text || text === 'transparent') return true;
734
- const parsed = parseDesignColor(text);
735
- return parsed ? (parsed.a ?? 1) <= 0.05 : false;
736
- }
737
-
738
- function canonicalDesignFindingKey(item) {
739
- if (!item?.antipattern?.startsWith?.('design-system-')) return null;
740
- const value = item.ignoreValue || item.value || '';
741
- if (item.antipattern === 'design-system-font') {
742
- const context = /google fonts/i.test(item.snippet || '') ? 'google-font' : 'font';
743
- const font = normalizeFontName(value);
744
- return font ? `${item.antipattern}:${context}:${font}` : null;
745
- }
746
- if (item.antipattern === 'design-system-color') {
747
- const parsed = parseDesignColor(value);
748
- if (parsed) return `${item.antipattern}:color:${colorKey(parsed)}`;
749
- const label = cssColorLabel(value).toLowerCase();
750
- return label ? `${item.antipattern}:color:${label}` : null;
751
- }
752
- if (item.antipattern === 'design-system-radius') {
753
- const px = resolveLengthPx(String(value || '').trim(), 16);
754
- if (px != null && Number.isFinite(px)) return `${item.antipattern}:radius:${Math.round(px * 100) / 100}`;
755
- const label = String(value || '').trim().toLowerCase();
756
- return label ? `${item.antipattern}:radius:${label}` : null;
757
- }
758
- if (item.antipattern === 'design-system-font-size') {
759
- const px = resolveLengthPx(String(value || '').trim(), 16);
760
- if (px != null && Number.isFinite(px)) return `${item.antipattern}:font-size:${Math.round(px * 100) / 100}`;
761
- const label = String(value || '').trim().toLowerCase();
762
- return label ? `${item.antipattern}:font-size:${label}` : null;
763
- }
764
- return null;
765
- }
766
-
767
- function mergeDesignSystemFindings(...groups) {
768
- const out = [];
769
- const seen = new Map();
770
- for (const group of groups) {
771
- for (const item of group || []) {
772
- const key = canonicalDesignFindingKey(item);
773
- if (key) {
774
- if (seen.has(key)) {
775
- const existing = out[seen.get(key)];
776
- if ((existing.line || 0) <= 0 && (item.line || 0) > 0) existing.line = item.line;
777
- continue;
778
- }
779
- seen.set(key, out.length);
780
- }
781
- out.push(item);
782
- }
783
- }
784
- return out;
785
- }
786
-
787
- function dedupeDesignFindings(findings) {
788
- const out = [];
789
- const seen = new Set();
790
- for (const item of findings) {
791
- const key = [
792
- item.antipattern,
793
- item.line || 0,
794
- normalizeFontName(item.ignoreValue || item.snippet || ''),
795
- ].join('\0');
796
- if (seen.has(key)) continue;
797
- seen.add(key);
798
- out.push(item);
799
- }
800
- return out;
801
- }
802
-
803
- export {
804
- parseFrontmatter,
805
- normalizeDesignSystem,
806
- loadDesignSystemForCwd,
807
- isAllowedFont,
808
- isAllowedColorRaw,
809
- isAllowedRadiusRaw,
810
- isAllowedFontSizeRaw,
811
- checkSourceDesignSystem,
812
- collectStaticDesignSystemFindings,
813
- mergeDesignSystemFindings,
814
- };