@monoes/monodesign 1.2.20 → 1.2.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/cli/engine/cli/main.mjs +21 -1
- package/cli/engine/design-system-checks.mjs +381 -0
- package/cli/engine/design-system-parse.mjs +433 -0
- package/cli/engine/design-system.mjs +20 -736
- package/cli/engine/detect-antipatterns-browser.js +28 -5
- package/cli/engine/detect-antipatterns.mjs +1 -0
- package/cli/engine/engines/regex/detect-text-matchers.mjs +371 -0
- package/cli/engine/engines/regex/detect-text-run.mjs +186 -0
- package/cli/engine/engines/regex/detect-text.mjs +11 -523
- package/cli/engine/engines/static-html/css-cascade-color.mjs +219 -0
- package/cli/engine/engines/static-html/css-cascade-static-data.mjs +138 -0
- package/cli/engine/engines/static-html/css-cascade-static-dom.mjs +132 -0
- package/cli/engine/engines/static-html/css-cascade-static-parse.mjs +393 -0
- package/cli/engine/engines/static-html/css-cascade.mjs +24 -837
- package/cli/engine/engines/static-html/detect-html.mjs +6 -1
- package/cli/engine/findings-group.mjs +94 -0
- package/cli/engine/fix/index.mjs +1 -26
- package/cli/engine/fix/unified-diff.mjs +107 -0
- package/cli/engine/rules/checks-background.mjs +17 -3
- package/cli/engine/rules/checks-element.mjs +2 -0
- package/cli/engine/rules/checks-pure.mjs +9 -2
- package/cli/lib/monodesign-config-consent.mjs +93 -0
- package/cli/lib/monodesign-config-core.mjs +37 -0
- package/cli/lib/monodesign-config-detection.mjs +133 -0
- package/cli/lib/monodesign-config-filter.mjs +198 -0
- package/cli/lib/monodesign-config-ignore-value.mjs +212 -0
- package/cli/lib/monodesign-config.mjs +21 -623
- package/package.json +2 -2
- package/skill/scripts/context-fields.mjs +65 -0
- package/skill/scripts/context-resolve.mjs +425 -0
- package/skill/scripts/context-update.mjs +151 -0
- package/skill/scripts/context-utils.mjs +68 -0
- package/skill/scripts/context-workspace.mjs +245 -0
- package/skill/scripts/context.mjs +17 -891
- package/skill/scripts/hook-admin-config.mjs +152 -0
- package/skill/scripts/hook-admin-ignore.mjs +131 -0
- package/skill/scripts/hook-admin-manifest.mjs +292 -0
- package/skill/scripts/hook-admin.mjs +8 -541
- package/skill/scripts/hook-lib-cache.mjs +145 -0
- package/skill/scripts/hook-lib-config.mjs +292 -0
- package/skill/scripts/hook-lib-detector.mjs +72 -0
- package/skill/scripts/hook-lib-events.mjs +182 -0
- package/skill/scripts/hook-lib-findings.mjs +201 -0
- package/skill/scripts/hook-lib-ignore.mjs +205 -0
- package/skill/scripts/hook-lib-render.mjs +273 -0
- package/skill/scripts/hook-lib-run.mjs +281 -0
- package/skill/scripts/hook-lib-scan-targets.mjs +128 -0
- package/skill/scripts/hook-lib.mjs +71 -1747
- package/skill/scripts/lib/design-parser-colors.mjs +182 -0
- package/skill/scripts/lib/design-parser-extract.mjs +333 -0
- package/skill/scripts/lib/design-parser-sections.mjs +214 -0
- package/skill/scripts/lib/design-parser-yaml.mjs +135 -0
- package/skill/scripts/lib/design-parser.mjs +10 -783
- package/skill/scripts/live/manual-apply-chunk.mjs +151 -0
- package/skill/scripts/live/manual-apply-compact.mjs +122 -0
- package/skill/scripts/live/manual-apply-evidence.mjs +115 -0
- package/skill/scripts/live/manual-apply-log.mjs +179 -0
- package/skill/scripts/live/manual-apply-transaction.mjs +122 -0
- package/skill/scripts/live/manual-apply.mjs +65 -640
- package/skill/scripts/live/svelte-component-accept.mjs +248 -0
- package/skill/scripts/live/svelte-component-css.mjs +230 -0
- package/skill/scripts/live/svelte-component-markup.mjs +104 -0
- package/skill/scripts/live/svelte-component-scaffold.mjs +118 -0
- package/skill/scripts/live/svelte-component-session.mjs +158 -0
- package/skill/scripts/live/svelte-component.mjs +32 -792
- package/skill/scripts/live-accept-mutate.mjs +152 -0
- package/skill/scripts/live-accept-parse.mjs +370 -0
- package/skill/scripts/live-accept-scrub.mjs +59 -0
- package/skill/scripts/live-accept-search.mjs +58 -0
- package/skill/scripts/live-accept.mjs +15 -631
- package/skill/scripts/live-commit-manual-edits-paths.mjs +27 -0
- package/skill/scripts/live-commit-manual-edits-repair.mjs +166 -0
- package/skill/scripts/live-commit-manual-edits-rollback.mjs +231 -0
- package/skill/scripts/live-commit-manual-edits-utils.mjs +167 -0
- package/skill/scripts/live-commit-manual-edits-verify.mjs +356 -0
- package/skill/scripts/live-commit-manual-edits.mjs +24 -881
- package/skill/scripts/live-copy-edit-agent.mjs +16 -551
- package/skill/scripts/live-copy-edit-compact.mjs +137 -0
- package/skill/scripts/live-copy-edit-post-apply.mjs +175 -0
- package/skill/scripts/live-copy-edit-runners.mjs +297 -0
- package/skill/scripts/live-inject-csp.mjs +132 -0
- package/skill/scripts/live-inject-files.mjs +229 -0
- package/skill/scripts/live-inject-tag.mjs +114 -0
- package/skill/scripts/live-inject.mjs +13 -440
- package/skill/scripts/live-server-poll.mjs +232 -0
- package/skill/scripts/live-server-routes.mjs +449 -0
- package/skill/scripts/live-server-state.mjs +361 -0
- package/skill/scripts/live-server.mjs +10 -946
- package/skill/scripts/live-wrap-css.mjs +132 -0
- package/skill/scripts/live-wrap-manual-edit.mjs +153 -0
- package/skill/scripts/live-wrap-search.mjs +247 -0
- package/skill/scripts/live-wrap.mjs +21 -484
- package/skill/scripts/palette-seeds.mjs +401 -0
- package/skill/scripts/palette.mjs +1 -395
package/README.md
CHANGED
|
@@ -81,7 +81,7 @@ console.log(radius.lg); // 12px
|
|
|
81
81
|
|
|
82
82
|
## Antipattern Detection (51 Rules)
|
|
83
83
|
|
|
84
|
-
Source: [`cli/engine/registry/antipatterns.mjs`](packages/@monoes/monodesign/cli/engine/registry/antipatterns.mjs)
|
|
84
|
+
Source: [`cli/engine/registry/antipatterns.mjs`](packages/@monoes/monodesign/cli/engine/registry/antipatterns.mjs) (entry point, re-exports from `antipatterns-slop.mjs`, `antipatterns-quality.mjs` and `antipatterns-provider.mjs`) — 51 entries.
|
|
85
85
|
|
|
86
86
|
### Rule Categories
|
|
87
87
|
|
|
@@ -178,7 +178,7 @@ Manage via `monomind design ignores` or `/monodesign hooks <on|off|status|ignore
|
|
|
178
178
|
|
|
179
179
|
## Design System Consistency
|
|
180
180
|
|
|
181
|
-
Source: [`cli/engine/design-system.mjs`](packages/@monoes/monodesign/cli/engine/design-system.mjs)
|
|
181
|
+
Source: [`cli/engine/design-system.mjs`](packages/@monoes/monodesign/cli/engine/design-system.mjs) (entry point, split across `design-system-parse.mjs` and `design-system-checks.mjs`)
|
|
182
182
|
|
|
183
183
|
Parses `DESIGN.md` / `.monodesign/design.json` to enforce consistency rules (`design-system-font`, `design-system-color`, `design-system-radius`, `design-system-font-size`). The skill writes `DESIGN.md`; the detector reads it for drift detection.
|
|
184
184
|
|
package/cli/engine/cli/main.mjs
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
isPortListening,
|
|
19
19
|
walkDir,
|
|
20
20
|
} from '../node/file-system.mjs';
|
|
21
|
+
import { formatGroupedFindings } from '../findings-group.mjs';
|
|
21
22
|
|
|
22
23
|
// ---------------------------------------------------------------------------
|
|
23
24
|
// Output formatting
|
|
@@ -92,6 +93,12 @@ Scan files or URLs for UI anti-patterns and design quality issues.
|
|
|
92
93
|
Options:
|
|
93
94
|
--json Output results as JSON
|
|
94
95
|
--quiet In text mode, only print the final findings count
|
|
96
|
+
--no-group In text mode, list every occurrence instead of one line
|
|
97
|
+
per unique (rule, snippet) with a count
|
|
98
|
+
--include-unverified
|
|
99
|
+
Also report contrast checks the static analyser cannot
|
|
100
|
+
verify (translucent colours, overlays, gradients, SVG
|
|
101
|
+
text); hidden by default
|
|
95
102
|
--gpt Also report GPT-specific provider tells (off by default)
|
|
96
103
|
--gemini Also report Gemini-specific provider tells (off by default)
|
|
97
104
|
--scope <name> Only report rules in the given design domain
|
|
@@ -138,6 +145,8 @@ async function detectCli() {
|
|
|
138
145
|
const jsonMode = args.includes('--json');
|
|
139
146
|
const quietMode = args.includes('--quiet');
|
|
140
147
|
const helpMode = args.includes('--help');
|
|
148
|
+
const groupMode = !args.includes('--no-group');
|
|
149
|
+
const includeUnverified = args.includes('--include-unverified');
|
|
141
150
|
// --fast (regex-only) is deprecated: since the jsdom removal, the static
|
|
142
151
|
// HTML/CSS analysis is fast and covers every rule, so the regex-only path
|
|
143
152
|
// only loses coverage for no real speed win. Accept the flag for back-compat
|
|
@@ -187,7 +196,8 @@ async function detectCli() {
|
|
|
187
196
|
// apply by default. `--no-config` (raw scan) and the dedicated
|
|
188
197
|
// `--no-inline-ignores` both turn them off.
|
|
189
198
|
const inlineIgnoresEnabled = configEnabled && !args.includes('--no-inline-ignores');
|
|
190
|
-
|
|
199
|
+
// Always collect unverified contrast checks so the hidden count can be shown.
|
|
200
|
+
const scanOptions = { providers, inlineIgnores: inlineIgnoresEnabled, includeUnverified: true };
|
|
191
201
|
if (designSystem) scanOptions.designSystem = designSystem;
|
|
192
202
|
const targets = args.filter(a => !a.startsWith('--'));
|
|
193
203
|
|
|
@@ -307,10 +317,20 @@ async function detectCli() {
|
|
|
307
317
|
|
|
308
318
|
allFindings = filterDetectionFindings(allFindings, detectionConfig);
|
|
309
319
|
allFindings = filterByScopes(allFindings, scopes);
|
|
320
|
+
const unverifiedCount = includeUnverified ? 0 : allFindings.filter(f => f.unverified).length;
|
|
321
|
+
if (!includeUnverified) allFindings = allFindings.filter(f => !f.unverified);
|
|
322
|
+
if (unverifiedCount > 0 && !jsonMode && !quietMode) {
|
|
323
|
+
process.stderr.write(
|
|
324
|
+
`${unverifiedCount} contrast check${unverifiedCount === 1 ? '' : 's'} could not be verified statically ` +
|
|
325
|
+
`(translucent colours, overlays, gradients or SVG text) and ${unverifiedCount === 1 ? 'is' : 'are'} hidden. ` +
|
|
326
|
+
`Pass --include-unverified to list them, or scan the page URL for a browser-rendered check.\n`,
|
|
327
|
+
);
|
|
328
|
+
}
|
|
310
329
|
|
|
311
330
|
if (allFindings.length > 0) {
|
|
312
331
|
if (jsonMode) process.stdout.write(`${formatFindings(allFindings, true)}\n`);
|
|
313
332
|
else if (quietMode) process.stderr.write(`${formatFindingSummary(allFindings.length)}\n`);
|
|
333
|
+
else if (groupMode) process.stderr.write(`${formatGroupedFindings(allFindings)}\n`);
|
|
314
334
|
else process.stderr.write(`${formatFindings(allFindings, false)}\n`);
|
|
315
335
|
process.exit(2);
|
|
316
336
|
}
|
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
// Design-system enforcement: is-this-value-allowed checks, regex source
|
|
2
|
+
// scanning, and static-DOM (computed style) findings collection. Split out
|
|
3
|
+
// of design-system.mjs (file-size sweep — pure move, no behaviour change).
|
|
4
|
+
|
|
5
|
+
import { finding } from './findings.mjs';
|
|
6
|
+
import { GENERIC_FONTS } from './shared/constants.mjs';
|
|
7
|
+
import { resolveLengthPx } from './rules/checks.mjs';
|
|
8
|
+
import {
|
|
9
|
+
primaryFont,
|
|
10
|
+
colorsClose,
|
|
11
|
+
parseDesignColor,
|
|
12
|
+
cssColorLabel,
|
|
13
|
+
normalizeFontName,
|
|
14
|
+
FONT_SIZE_LITERAL_RE,
|
|
15
|
+
} from './design-system-parse.mjs';
|
|
16
|
+
import { dedupeDesignFindings } from './design-system.mjs';
|
|
17
|
+
|
|
18
|
+
const RADIUS_TOLERANCE_PX = 0.5;
|
|
19
|
+
const FONT_SIZE_TOLERANCE_PX = 0.5;
|
|
20
|
+
|
|
21
|
+
const CSS_COLOR_RE = /#[0-9a-f]{3,8}\b|rgba?\([^)]+\)|oklch\([^)]+\)|hsla?\([^)]+\)/gi;
|
|
22
|
+
const FONT_DECL_RE = /font-family\s*:\s*([^;}\n]+)/gi;
|
|
23
|
+
const FONT_JS_RE = /fontFamily\s*[:=]\s*["'`]([^"'`]+)["'`]/g;
|
|
24
|
+
const GOOGLE_FONT_RE = /fonts\.googleapis\.com\/css2?\?[^"'\s)<>]*/gi;
|
|
25
|
+
const BORDER_RADIUS_RE = /border-radius\s*:\s*([^;}\n]+)/gi;
|
|
26
|
+
const BORDER_RADIUS_JS_RE = /borderRadius\s*[:=]\s*["'`]([^"'`]+)["'`]/g;
|
|
27
|
+
const FONT_SIZE_DECL_RE = /font-size\s*:\s*([^;}\n]+)/gi;
|
|
28
|
+
const FONT_SIZE_JS_RE = /fontSize\s*[:=]\s*["'`]([^"'`]+)["'`]/g;
|
|
29
|
+
const TAILWIND_FONT_SIZE_RE = /\btext-\[(-?[\d.]+(?:px|rem))\]/g;
|
|
30
|
+
const STATIC_DESIGN_SKIP_TAGS = new Set(['head', 'title', 'meta', 'link', 'style', 'script', 'noscript', 'template', 'source']);
|
|
31
|
+
|
|
32
|
+
function isAllowedFont(font, designSystem) {
|
|
33
|
+
if (!font || GENERIC_FONTS.has(font)) return true;
|
|
34
|
+
if (!designSystem?.hasFonts) return true;
|
|
35
|
+
return designSystem.allowedFonts.has(font);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function isAllowedColorRaw(raw, designSystem) {
|
|
39
|
+
if (!designSystem?.hasColors) return true;
|
|
40
|
+
const text = String(raw || '').trim().toLowerCase();
|
|
41
|
+
if (!text || text === 'transparent' || text === 'currentcolor' || text === 'inherit' || text === 'initial') return true;
|
|
42
|
+
if (text.includes('var(')) return true;
|
|
43
|
+
const parsed = parseDesignColor(text);
|
|
44
|
+
if (!parsed) return true;
|
|
45
|
+
if ((parsed.a ?? 1) <= 0.05) return true;
|
|
46
|
+
for (const entry of designSystem.allowedColorKeys.values()) {
|
|
47
|
+
if (colorsClose(parsed, entry.color)) return true;
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function isAllowedRadiusRaw(raw, designSystem) {
|
|
53
|
+
if (!designSystem?.hasRadii) return true;
|
|
54
|
+
const text = String(raw || '').trim().toLowerCase();
|
|
55
|
+
if (!text || text === '0' || text === 'none' || text === 'initial' || text === 'inherit') return true;
|
|
56
|
+
if (text.includes('var(') || text.includes('%')) return true;
|
|
57
|
+
const px = resolveLengthPx(text, 16);
|
|
58
|
+
if (px == null || !Number.isFinite(px) || px <= RADIUS_TOLERANCE_PX) return true;
|
|
59
|
+
if (designSystem.hasPillRadius && px >= 99) return true;
|
|
60
|
+
return designSystem.allowedRadii.some(entry => Math.abs(entry.px - px) <= RADIUS_TOLERANCE_PX);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function isAllowedFontSizeRaw(raw, designSystem) {
|
|
64
|
+
if (!designSystem?.hasFontSizes) return true;
|
|
65
|
+
const text = String(raw || '').trim().toLowerCase().replace(/\s*!important\s*$/, '');
|
|
66
|
+
if (!FONT_SIZE_LITERAL_RE.test(text)) return true;
|
|
67
|
+
const px = resolveLengthPx(text, 16);
|
|
68
|
+
if (px == null || !Number.isFinite(px) || px <= 0) return true;
|
|
69
|
+
return designSystem.allowedFontSizes.some(
|
|
70
|
+
entry => Math.abs(entry.px - px) <= FONT_SIZE_TOLERANCE_PX,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function lineLooksCommented(line) {
|
|
75
|
+
const trimmed = String(line || '').trim();
|
|
76
|
+
return trimmed.startsWith('//') || trimmed.startsWith('/*') || trimmed.startsWith('*') || trimmed.startsWith('<!--');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function isProbablyColorLiteral(line, match) {
|
|
80
|
+
const raw = match?.[0] || '';
|
|
81
|
+
const index = match.index ?? -1;
|
|
82
|
+
if (index < 0) return false;
|
|
83
|
+
if (isInsideCssAttributeSelector(line, index)) return false;
|
|
84
|
+
|
|
85
|
+
const before = line.slice(0, index);
|
|
86
|
+
const after = line.slice(index + raw.length);
|
|
87
|
+
|
|
88
|
+
if (raw.startsWith('#')) {
|
|
89
|
+
if (before.endsWith('&')) return false; // HTML numeric entity, e.g. ↔
|
|
90
|
+
|
|
91
|
+
const prevNonSpace = before.match(/\S(?=\s*$)/)?.[0] || '';
|
|
92
|
+
const nextNonSpace = after.match(/^\s*(\S)/)?.[1] || '';
|
|
93
|
+
if (prevNonSpace === '>' && nextNonSpace === '<') return false; // plain text, e.g. PR #155
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
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);
|
|
97
|
+
const cssFunctionContext = /(?:linear-gradient|radial-gradient|conic-gradient|color-mix)\([^)]*$/i.test(before);
|
|
98
|
+
const jsColorKeyContext = /(?:^|[,{]\s*)(?:color|background|backgroundColor|borderColor|outlineColor|fill|stroke|boxShadow|textShadow)\s*[:=]\s*["'`]?[^"'`,}]*/i.test(before);
|
|
99
|
+
|
|
100
|
+
return styleContext || cssFunctionContext || jsColorKeyContext;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function isInsideCssAttributeSelector(line, index) {
|
|
104
|
+
if (index < 0) return false;
|
|
105
|
+
const before = line.slice(0, index);
|
|
106
|
+
const lastOpen = before.lastIndexOf('[');
|
|
107
|
+
if (lastOpen === -1) return false;
|
|
108
|
+
const lastClose = before.lastIndexOf(']');
|
|
109
|
+
if (lastClose > lastOpen) return false;
|
|
110
|
+
const after = line.slice(index);
|
|
111
|
+
const close = after.indexOf(']');
|
|
112
|
+
const block = after.indexOf('{');
|
|
113
|
+
return close !== -1 && (block === -1 || close < block);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function makeDesignFinding(id, filePath, snippet, line = 0, extras = {}) {
|
|
117
|
+
return { ...finding(id, filePath, snippet, line), ...extras };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function decodeGoogleFamily(value) {
|
|
121
|
+
const family = String(value || '').split(':')[0].replace(/\+/g, ' ');
|
|
122
|
+
try {
|
|
123
|
+
return decodeURIComponent(family);
|
|
124
|
+
} catch {
|
|
125
|
+
return family;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function checkFontStack(stack, filePath, line, designSystem, context) {
|
|
130
|
+
const primary = primaryFont(stack);
|
|
131
|
+
if (!primary || isAllowedFont(primary, designSystem)) return [];
|
|
132
|
+
const display = primary.replace(/\b\w/g, ch => ch.toUpperCase());
|
|
133
|
+
return [makeDesignFinding(
|
|
134
|
+
'design-system-font',
|
|
135
|
+
filePath,
|
|
136
|
+
`${context}: ${display} is not declared in DESIGN.md typography`,
|
|
137
|
+
line,
|
|
138
|
+
{ ignoreValue: display },
|
|
139
|
+
)];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function extractRadiusTokens(value) {
|
|
143
|
+
return String(value || '')
|
|
144
|
+
.replace(/\s*\/\s*/g, ' ')
|
|
145
|
+
.split(/\s+/)
|
|
146
|
+
.map(token => token.trim())
|
|
147
|
+
.filter(Boolean);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function checkRadiusValue(value, filePath, line, designSystem, context) {
|
|
151
|
+
const findings = [];
|
|
152
|
+
for (const token of extractRadiusTokens(value)) {
|
|
153
|
+
if (isAllowedRadiusRaw(token, designSystem)) continue;
|
|
154
|
+
findings.push(makeDesignFinding(
|
|
155
|
+
'design-system-radius',
|
|
156
|
+
filePath,
|
|
157
|
+
`${context}: ${token} is outside the DESIGN.md rounded scale`,
|
|
158
|
+
line,
|
|
159
|
+
{ ignoreValue: token },
|
|
160
|
+
));
|
|
161
|
+
}
|
|
162
|
+
return findings;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function checkFontSizeValue(value, filePath, line, designSystem, context) {
|
|
166
|
+
const token = String(value || '').trim();
|
|
167
|
+
if (isAllowedFontSizeRaw(token, designSystem)) return [];
|
|
168
|
+
return [makeDesignFinding(
|
|
169
|
+
'design-system-font-size',
|
|
170
|
+
filePath,
|
|
171
|
+
`${context}: ${token} is off the DESIGN.md type ramp`,
|
|
172
|
+
line,
|
|
173
|
+
{ ignoreValue: token },
|
|
174
|
+
)];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function checkSourceDesignSystem(content, filePath, options = {}) {
|
|
178
|
+
const designSystem = options.designSystem;
|
|
179
|
+
if (!designSystem?.present) return [];
|
|
180
|
+
|
|
181
|
+
const findings = [];
|
|
182
|
+
const lines = String(content || '').split('\n');
|
|
183
|
+
for (let i = 0; i < lines.length; i++) {
|
|
184
|
+
const line = lines[i];
|
|
185
|
+
const lineNum = i + 1;
|
|
186
|
+
if (lineLooksCommented(line)) continue;
|
|
187
|
+
|
|
188
|
+
if (designSystem.hasFonts) {
|
|
189
|
+
for (const match of line.matchAll(FONT_DECL_RE)) {
|
|
190
|
+
findings.push(...checkFontStack(match[1], filePath, lineNum, designSystem, 'font-family'));
|
|
191
|
+
}
|
|
192
|
+
for (const match of line.matchAll(FONT_JS_RE)) {
|
|
193
|
+
findings.push(...checkFontStack(match[1], filePath, lineNum, designSystem, 'fontFamily'));
|
|
194
|
+
}
|
|
195
|
+
for (const match of line.matchAll(GOOGLE_FONT_RE)) {
|
|
196
|
+
const url = match[0];
|
|
197
|
+
for (const familyMatch of url.matchAll(/[?&]family=([^&]+)/g)) {
|
|
198
|
+
const font = normalizeFontName(decodeGoogleFamily(familyMatch[1]));
|
|
199
|
+
if (!font || isAllowedFont(font, designSystem)) continue;
|
|
200
|
+
const display = decodeGoogleFamily(familyMatch[1]);
|
|
201
|
+
findings.push(makeDesignFinding(
|
|
202
|
+
'design-system-font',
|
|
203
|
+
filePath,
|
|
204
|
+
`Google Fonts: ${display} is not declared in DESIGN.md typography`,
|
|
205
|
+
lineNum,
|
|
206
|
+
{ ignoreValue: display },
|
|
207
|
+
));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (designSystem.hasColors) {
|
|
213
|
+
for (const match of line.matchAll(CSS_COLOR_RE)) {
|
|
214
|
+
if (!isProbablyColorLiteral(line, match)) continue;
|
|
215
|
+
const raw = cssColorLabel(match[0]);
|
|
216
|
+
if (isAllowedColorRaw(raw, designSystem)) continue;
|
|
217
|
+
findings.push(makeDesignFinding(
|
|
218
|
+
'design-system-color',
|
|
219
|
+
filePath,
|
|
220
|
+
`Undocumented color ${raw} is outside DESIGN.md colors`,
|
|
221
|
+
lineNum,
|
|
222
|
+
{ ignoreValue: raw },
|
|
223
|
+
));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (designSystem.hasRadii) {
|
|
228
|
+
for (const match of line.matchAll(BORDER_RADIUS_RE)) {
|
|
229
|
+
findings.push(...checkRadiusValue(match[1], filePath, lineNum, designSystem, 'border-radius'));
|
|
230
|
+
}
|
|
231
|
+
for (const match of line.matchAll(BORDER_RADIUS_JS_RE)) {
|
|
232
|
+
findings.push(...checkRadiusValue(match[1], filePath, lineNum, designSystem, 'borderRadius'));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (designSystem.hasFontSizes) {
|
|
237
|
+
for (const match of line.matchAll(FONT_SIZE_DECL_RE)) {
|
|
238
|
+
findings.push(...checkFontSizeValue(match[1], filePath, lineNum, designSystem, 'font-size'));
|
|
239
|
+
}
|
|
240
|
+
for (const match of line.matchAll(FONT_SIZE_JS_RE)) {
|
|
241
|
+
findings.push(...checkFontSizeValue(match[1], filePath, lineNum, designSystem, 'fontSize'));
|
|
242
|
+
}
|
|
243
|
+
for (const match of line.matchAll(TAILWIND_FONT_SIZE_RE)) {
|
|
244
|
+
findings.push(...checkFontSizeValue(match[1], filePath, lineNum, designSystem, 'text-[…] class'));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return dedupeDesignFindings(findings);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function hasDirectText(el) {
|
|
253
|
+
return Array.from(el.childNodes || []).some(node => node.nodeType === 3 && node.textContent.trim().length > 0);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function sampleText(el) {
|
|
257
|
+
const text = String(el.textContent || '').replace(/\s+/g, ' ').trim();
|
|
258
|
+
return text ? ` "${text.slice(0, 40)}"` : '';
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Font-size design-system checks are source-scan-only (see checkSourceDesignSystem).
|
|
262
|
+
// Computed font-size cascades and clamp() ramps resolve to off-ramp px in the browser.
|
|
263
|
+
function collectStaticDesignSystemFindings(document, window, filePath, designSystem) {
|
|
264
|
+
if (!designSystem?.present) return [];
|
|
265
|
+
const findings = [];
|
|
266
|
+
const seenFonts = new Set();
|
|
267
|
+
const seenColors = new Set();
|
|
268
|
+
const seenRadii = new Set();
|
|
269
|
+
|
|
270
|
+
for (const el of document.querySelectorAll('*')) {
|
|
271
|
+
if (shouldSkipStaticDesignElement(el, window)) continue;
|
|
272
|
+
const tag = el.tagName?.toLowerCase?.() || 'unknown';
|
|
273
|
+
const style = window.getComputedStyle(el);
|
|
274
|
+
|
|
275
|
+
if (designSystem.hasFonts && hasDirectText(el)) {
|
|
276
|
+
const font = primaryFont(style.fontFamily || '');
|
|
277
|
+
if (font && !seenFonts.has(font) && !isAllowedFont(font, designSystem)) {
|
|
278
|
+
seenFonts.add(font);
|
|
279
|
+
findings.push(makeDesignFinding(
|
|
280
|
+
'design-system-font',
|
|
281
|
+
filePath,
|
|
282
|
+
`${tag}${sampleText(el)} uses ${font}; not declared in DESIGN.md typography`,
|
|
283
|
+
0,
|
|
284
|
+
{ ignoreValue: font },
|
|
285
|
+
));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (designSystem.hasColors) {
|
|
290
|
+
const colorChecks = [];
|
|
291
|
+
if (hasDirectText(el)) colorChecks.push(['text color', style.color]);
|
|
292
|
+
if (!isTransparentCss(style.backgroundColor)) colorChecks.push(['background', style.backgroundColor]);
|
|
293
|
+
for (const side of ['Top', 'Right', 'Bottom', 'Left']) {
|
|
294
|
+
if ((parseFloat(style[`border${side}Width`]) || 0) > 0) {
|
|
295
|
+
colorChecks.push([`border-${side.toLowerCase()}`, style[`border${side}Color`]]);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
if ((parseFloat(style.outlineWidth) || 0) > 0) colorChecks.push(['outline', style.outlineColor]);
|
|
299
|
+
|
|
300
|
+
for (const [kind, raw] of colorChecks) {
|
|
301
|
+
const label = cssColorLabel(raw);
|
|
302
|
+
if (isAllowedColorRaw(label, designSystem)) continue;
|
|
303
|
+
const key = `${kind}:${label}`;
|
|
304
|
+
if (seenColors.has(key)) continue;
|
|
305
|
+
seenColors.add(key);
|
|
306
|
+
findings.push(makeDesignFinding(
|
|
307
|
+
'design-system-color',
|
|
308
|
+
filePath,
|
|
309
|
+
`${kind} ${label} on ${tag}${sampleText(el)} is outside DESIGN.md colors`,
|
|
310
|
+
0,
|
|
311
|
+
{ ignoreValue: label },
|
|
312
|
+
));
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (designSystem.hasRadii) {
|
|
317
|
+
const rawRadius = String(style.borderRadius || '').trim();
|
|
318
|
+
if (!rawRadius) continue;
|
|
319
|
+
for (const token of extractRadiusTokens(rawRadius)) {
|
|
320
|
+
if (isAllowedRadiusRaw(token, designSystem)) continue;
|
|
321
|
+
if (seenRadii.has(token)) continue;
|
|
322
|
+
seenRadii.add(token);
|
|
323
|
+
findings.push(makeDesignFinding(
|
|
324
|
+
'design-system-radius',
|
|
325
|
+
filePath,
|
|
326
|
+
`border-radius ${token} on ${tag}${sampleText(el)} is outside the DESIGN.md rounded scale`,
|
|
327
|
+
0,
|
|
328
|
+
{ ignoreValue: token },
|
|
329
|
+
));
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return findings;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function shouldSkipStaticDesignElement(el, window) {
|
|
338
|
+
const tag = el.tagName?.toLowerCase?.() || '';
|
|
339
|
+
if (STATIC_DESIGN_SKIP_TAGS.has(tag)) return true;
|
|
340
|
+
|
|
341
|
+
let current = el;
|
|
342
|
+
while (current) {
|
|
343
|
+
if (current.getAttribute?.('hidden') !== null || current.getAttribute?.('aria-hidden') === 'true') return true;
|
|
344
|
+
const style = window.getComputedStyle(current);
|
|
345
|
+
const display = String(style.display || '').toLowerCase();
|
|
346
|
+
const visibility = String(style.visibility || '').toLowerCase();
|
|
347
|
+
if (display === 'none' || visibility === 'hidden' || visibility === 'collapse') return true;
|
|
348
|
+
current = current.parentElement;
|
|
349
|
+
}
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function isTransparentCss(value) {
|
|
354
|
+
const text = String(value || '').trim().toLowerCase();
|
|
355
|
+
if (!text || text === 'transparent') return true;
|
|
356
|
+
const parsed = parseDesignColor(text);
|
|
357
|
+
return parsed ? (parsed.a ?? 1) <= 0.05 : false;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
export {
|
|
362
|
+
isAllowedFont,
|
|
363
|
+
isAllowedColorRaw,
|
|
364
|
+
isAllowedRadiusRaw,
|
|
365
|
+
isAllowedFontSizeRaw,
|
|
366
|
+
lineLooksCommented,
|
|
367
|
+
isProbablyColorLiteral,
|
|
368
|
+
isInsideCssAttributeSelector,
|
|
369
|
+
makeDesignFinding,
|
|
370
|
+
decodeGoogleFamily,
|
|
371
|
+
checkFontStack,
|
|
372
|
+
extractRadiusTokens,
|
|
373
|
+
checkRadiusValue,
|
|
374
|
+
checkFontSizeValue,
|
|
375
|
+
checkSourceDesignSystem,
|
|
376
|
+
hasDirectText,
|
|
377
|
+
sampleText,
|
|
378
|
+
collectStaticDesignSystemFindings,
|
|
379
|
+
shouldSkipStaticDesignElement,
|
|
380
|
+
isTransparentCss,
|
|
381
|
+
};
|