monomind 2.5.2 → 2.5.3
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 +1 -1
- package/package.json +1 -1
- package/packages/@monomind/cli/.claude/agents/github/repo-architect.md +3 -3
- package/packages/@monomind/cli/.claude/agents/github/sync-coordinator.md +2 -2
- package/packages/@monomind/cli/.claude/agents/specialists/integration-architect.md +4 -4
- package/packages/@monomind/cli/.claude/commands/github/repo-architect.md +4 -4
- package/packages/@monomind/cli/.claude/commands/github/sync-coordinator.md +2 -2
- package/packages/@monomind/cli/.claude/helpers/event-logger.cjs +2 -2
- package/packages/@monomind/cli/.claude/helpers/extras-registry.json +1 -1
- package/packages/@monomind/cli/.claude/helpers/handlers/agent-start-handler.cjs +2 -2
- package/packages/@monomind/cli/.claude/helpers/handlers/edit-handler.cjs +2 -2
- package/packages/@monomind/cli/.claude/helpers/handlers/gates-handler.cjs +1 -1
- package/packages/@monomind/cli/.claude/helpers/handlers/route-handler.cjs +1 -1
- package/packages/@monomind/cli/.claude/helpers/handlers/session-handler.cjs +1 -1
- package/packages/@monomind/cli/.claude/helpers/handlers/session-restore-handler.cjs +11 -11
- package/packages/@monomind/cli/.claude/helpers/handlers/task-handler.cjs +2 -2
- package/packages/@monomind/cli/.claude/helpers/hook-handler.cjs +8 -8
- package/packages/@monomind/cli/.claude/skills/mastermind-techport/SKILL.md +1 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/SKILL.md +2 -2
- package/packages/@monomind/cli/.claude/skills/monodesign/reference/antipatterns-catalog.md +47 -2
- package/packages/@monomind/cli/.claude/skills/monodesign/reference/critique.md +1 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/reference/live.md +0 -8
- package/packages/@monomind/cli/.claude/skills/monodesign/reference/polish.md +2 -2
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/context-signals.mjs +39 -6
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/context.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/critique-storage.mjs +175 -2
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detect-csp.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detect.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/browser/injected/index.mjs +25 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/cli/main.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/design-system.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/detect-antipatterns-browser.js +356 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/detect-antipatterns.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/engines/browser/detect-url.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/engines/browser/drivers.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/engines/regex/detect-text.mjs +63 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/engines/static-html/css-cascade.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/engines/static-html/detect-html.mjs +19 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/engines/visual/screenshot-contrast.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/findings.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/fix/css-regions.mjs +181 -0
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/fix/fixers.mjs +373 -0
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/fix/index.mjs +426 -0
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/node/file-system.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/profile/profiler.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/registry/antipatterns.mjs +49 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/rules/checks.mjs +292 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/shared/color.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/shared/constants.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/shared/fonts.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/shared/inline-ignores.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/shared/page.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/hook-admin.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/hook-before-edit.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/hook-lib.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/hook.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/lib/design-parser.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/lib/is-generated.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/lib/monodesign-config.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/lib/monodesign-paths.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/lib/provider.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/lib/target-args.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/browser-script-parts.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/completion.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/event-validation.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/insert-ui.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/manual-apply.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/manual-edit-routes.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/manual-edits-buffer.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/session-store.mjs +5 -2
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/svelte-component.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/sveltekit-adapter.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/ui-core.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/vocabulary.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-accept.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-browser-dom.js +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-browser-session.js +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-browser.js +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-commit-manual-edits.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-complete.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-copy-edit-agent.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-discard-manual-edits.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-inject.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-insert.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-manual-edit-evidence.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-poll.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-resume.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-server.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-status.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-target.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-wrap.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/modern-screenshot.umd.js +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/palette.mjs +0 -1
- package/packages/@monomind/cli/.claude/skills/monodesign/scripts/pin.mjs +0 -1
- package/packages/@monomind/cli/README.md +1 -1
- package/packages/@monomind/cli/dist/src/commands/design-detect.js +62 -1
- package/packages/@monomind/cli/dist/src/commands/design-palette.d.ts +0 -1
- package/packages/@monomind/cli/dist/src/commands/design-palette.js +0 -1
- package/packages/@monomind/cli/dist/src/commands/doctor-project-checks.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/commands/doctor-project-checks.js +1 -1
- package/packages/@monomind/cli/dist/src/commands/hooks-workers.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/commands/hooks-workers.js +8 -8
- package/packages/@monomind/cli/dist/src/commands/init.js +2 -2
- package/packages/@monomind/cli/dist/src/index.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/index.js +3 -3
- package/packages/@monomind/cli/dist/src/init/claudemd-generator.js +5 -5
- package/packages/@monomind/cli/dist/src/init/executor.js +3 -3
- package/packages/@monomind/cli/dist/src/knowledge/document-pipeline.js +3 -1
- package/packages/@monomind/cli/dist/src/mcp-server.js +2 -2
- package/packages/@monomind/cli/dist/src/mcp-tools/hooks-intelligence.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/mcp-tools/hooks-intelligence.js +1 -1
- package/packages/@monomind/cli/dist/src/mcp-tools/hooks-routing.js +2 -2
- package/packages/@monomind/cli/dist/src/mcp-tools/hooks-tools.js +1 -1
- package/packages/@monomind/cli/dist/src/memory/memory-kg.d.ts +5 -4
- package/packages/@monomind/cli/dist/src/memory/memory-kg.js +5 -4
- package/packages/@monomind/cli/dist/src/routing/embed-worker.js +1 -1
- package/packages/@monomind/cli/dist/src/routing/llm-caller.js +1 -1
- package/packages/@monomind/cli/dist/src/routing/route-layer-factory.js +1 -1
- package/packages/@monomind/cli/dist/src/ui/dashboard.html +22 -20
- package/packages/@monomind/cli/dist/src/update/checker.js +3 -3
- package/packages/@monomind/cli/package.json +5 -5
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS region extraction and declaration scanning for the auto-fix engine.
|
|
3
|
+
*
|
|
4
|
+
* Fixers never parse a full DOM — they operate on the raw source text of the
|
|
5
|
+
* "CSS-shaped" regions of a file:
|
|
6
|
+
* - whole file for .css/.scss/.sass/.less
|
|
7
|
+
* - <style> blocks and style="" attributes for HTML-family files
|
|
8
|
+
* - styled-components / emotion template literals for JS/TS files
|
|
9
|
+
*
|
|
10
|
+
* All offsets returned here are absolute within the original file content, so
|
|
11
|
+
* edits computed against a region can be applied directly to the file.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const CSS_EXTENSIONS = new Set(['.css', '.scss', '.sass', '.less']);
|
|
15
|
+
const HTML_FAMILY_EXTENSIONS = new Set(['.html', '.htm', '.vue', '.svelte', '.astro']);
|
|
16
|
+
const JS_EXTENSIONS = new Set(['.js', '.ts', '.jsx', '.tsx', '.mjs', '.cjs']);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A region of file content that can be scanned as CSS declarations.
|
|
20
|
+
* kind:
|
|
21
|
+
* 'css' — full stylesheet syntax (selectors + blocks)
|
|
22
|
+
* 'style-attr' — a bare declaration list from a style="" attribute;
|
|
23
|
+
* selectorHint carries the owning tag name
|
|
24
|
+
*/
|
|
25
|
+
function extractCssRegions(content, ext) {
|
|
26
|
+
ext = (ext || '').toLowerCase();
|
|
27
|
+
if (CSS_EXTENSIONS.has(ext)) {
|
|
28
|
+
return [{ start: 0, end: content.length, text: content, kind: 'css', selectorHint: null }];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const regions = [];
|
|
32
|
+
if (HTML_FAMILY_EXTENSIONS.has(ext)) {
|
|
33
|
+
const styleBlockRe = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
34
|
+
let m;
|
|
35
|
+
while ((m = styleBlockRe.exec(content)) !== null) {
|
|
36
|
+
const start = m.index + m[0].indexOf(m[1]);
|
|
37
|
+
regions.push({ start, end: start + m[1].length, text: m[1], kind: 'css', selectorHint: null });
|
|
38
|
+
}
|
|
39
|
+
const styleAttrRe = /<([a-zA-Z][\w-]*)\b[^>]*?\sstyle\s*=\s*("([^"]*)"|'([^']*)')/gi;
|
|
40
|
+
while ((m = styleAttrRe.exec(content)) !== null) {
|
|
41
|
+
const value = m[3] !== undefined ? m[3] : m[4];
|
|
42
|
+
if (!value) continue;
|
|
43
|
+
const start = m.index + m[0].length - value.length - 1; // inside the closing quote
|
|
44
|
+
regions.push({
|
|
45
|
+
start,
|
|
46
|
+
end: start + value.length,
|
|
47
|
+
text: value,
|
|
48
|
+
kind: 'style-attr',
|
|
49
|
+
selectorHint: m[1].toLowerCase(),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return regions;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (JS_EXTENSIONS.has(ext)) {
|
|
56
|
+
const cssInJsRe = /(?:styled(?:\.\w+|\([^)]+\))|css)\s*`([\s\S]*?)`/g;
|
|
57
|
+
let m;
|
|
58
|
+
while ((m = cssInJsRe.exec(content)) !== null) {
|
|
59
|
+
const start = m.index + m[0].indexOf('`') + 1;
|
|
60
|
+
regions.push({ start, end: start + m[1].length, text: m[1], kind: 'css', selectorHint: null });
|
|
61
|
+
}
|
|
62
|
+
return regions;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return regions;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Find every `prop: value` declaration in a CSS-shaped text. Returns local
|
|
70
|
+
* offsets (relative to the given text):
|
|
71
|
+
* { declStart, valueStart, valueEnd, value, terminator }
|
|
72
|
+
* `value` is the raw trimmed value text (may include !important).
|
|
73
|
+
* `terminator` is the index just past the trailing `;` when present,
|
|
74
|
+
* otherwise valueEnd.
|
|
75
|
+
*/
|
|
76
|
+
function findDeclarations(text, prop) {
|
|
77
|
+
const re = new RegExp(`(^|[{;])(\\s*)(${prop})\\s*:\\s*([^;{}]*)`, 'gi');
|
|
78
|
+
const results = [];
|
|
79
|
+
let m;
|
|
80
|
+
while ((m = re.exec(text)) !== null) {
|
|
81
|
+
const declStart = m.index + m[1].length + m[2].length;
|
|
82
|
+
const rawValue = m[4];
|
|
83
|
+
const trimmed = rawValue.replace(/\s+$/, '');
|
|
84
|
+
const valueStart = m.index + m[0].length - rawValue.length;
|
|
85
|
+
const valueEnd = valueStart + trimmed.length;
|
|
86
|
+
const terminator = text[m.index + m[0].length] === ';'
|
|
87
|
+
? m.index + m[0].length + 1
|
|
88
|
+
: valueEnd;
|
|
89
|
+
results.push({ declStart, valueStart, valueEnd, value: trimmed.trim(), terminator });
|
|
90
|
+
}
|
|
91
|
+
return results;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The enclosing `{ ... }` block for a declaration at `index`, with its
|
|
96
|
+
* selector text. For bare declaration lists (style attributes) there is no
|
|
97
|
+
* block — the whole text is the body and selector is null.
|
|
98
|
+
*/
|
|
99
|
+
function declBlockInfo(text, index) {
|
|
100
|
+
let i = index - 1;
|
|
101
|
+
let depth = 0;
|
|
102
|
+
while (i >= 0) {
|
|
103
|
+
const ch = text[i];
|
|
104
|
+
if (ch === '}') depth++;
|
|
105
|
+
else if (ch === '{') {
|
|
106
|
+
if (depth === 0) break;
|
|
107
|
+
depth--;
|
|
108
|
+
}
|
|
109
|
+
i--;
|
|
110
|
+
}
|
|
111
|
+
if (i < 0) {
|
|
112
|
+
return { bodyStart: 0, bodyEnd: text.length, body: text, selector: null };
|
|
113
|
+
}
|
|
114
|
+
const braceIdx = i;
|
|
115
|
+
let s = braceIdx - 1;
|
|
116
|
+
while (s >= 0 && !'};{'.includes(text[s])) s--;
|
|
117
|
+
const selector = text.slice(s + 1, braceIdx).trim();
|
|
118
|
+
let j = braceIdx + 1;
|
|
119
|
+
let d = 0;
|
|
120
|
+
while (j < text.length) {
|
|
121
|
+
const ch = text[j];
|
|
122
|
+
if (ch === '{') d++;
|
|
123
|
+
else if (ch === '}') {
|
|
124
|
+
if (d === 0) break;
|
|
125
|
+
d--;
|
|
126
|
+
}
|
|
127
|
+
j++;
|
|
128
|
+
}
|
|
129
|
+
return { bodyStart: braceIdx + 1, bodyEnd: j, body: text.slice(braceIdx + 1, j), selector };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Parse a single CSS length/number value, tolerating !important. */
|
|
133
|
+
function parseCssValue(raw) {
|
|
134
|
+
const important = /!\s*important/i.test(raw);
|
|
135
|
+
const cleaned = raw.replace(/!\s*important/i, '').trim();
|
|
136
|
+
const m = cleaned.match(/^(-?(?:\d+\.?\d*|\.\d+))([a-z%]*)$/i);
|
|
137
|
+
if (!m) return null;
|
|
138
|
+
return { num: parseFloat(m[1]), unit: (m[2] || '').toLowerCase(), important };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Resolve a block's font-size to px when statically computable, else null. */
|
|
142
|
+
function blockFontSizePx(body) {
|
|
143
|
+
const decls = findDeclarations(body, 'font-size');
|
|
144
|
+
if (decls.length === 0) return null;
|
|
145
|
+
const parsed = parseCssValue(decls[decls.length - 1].value);
|
|
146
|
+
if (!parsed) return null;
|
|
147
|
+
if (parsed.unit === 'px') return parsed.num;
|
|
148
|
+
if (parsed.unit === 'rem') return parsed.num * 16;
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Split a CSS value list on top-level commas (paren-aware, for cubic-bezier). */
|
|
153
|
+
function splitTopLevel(value) {
|
|
154
|
+
const parts = [];
|
|
155
|
+
let depth = 0;
|
|
156
|
+
let current = '';
|
|
157
|
+
for (const ch of value) {
|
|
158
|
+
if (ch === '(') depth++;
|
|
159
|
+
else if (ch === ')') depth--;
|
|
160
|
+
if (ch === ',' && depth === 0) {
|
|
161
|
+
parts.push(current.trim());
|
|
162
|
+
current = '';
|
|
163
|
+
} else {
|
|
164
|
+
current += ch;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (current.trim()) parts.push(current.trim());
|
|
168
|
+
return parts;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export {
|
|
172
|
+
CSS_EXTENSIONS,
|
|
173
|
+
HTML_FAMILY_EXTENSIONS,
|
|
174
|
+
JS_EXTENSIONS,
|
|
175
|
+
extractCssRegions,
|
|
176
|
+
findDeclarations,
|
|
177
|
+
declBlockInfo,
|
|
178
|
+
parseCssValue,
|
|
179
|
+
blockFontSizePx,
|
|
180
|
+
splitTopLevel,
|
|
181
|
+
};
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-rule auto-fixers for the monodesign detector.
|
|
3
|
+
*
|
|
4
|
+
* A fixer is pure: it takes file content (plus its extension) and returns a
|
|
5
|
+
* list of precise text edits `{ start, end, replacement, note }` — or an empty
|
|
6
|
+
* list when nothing in this file is safely rewritable. Only rules with a
|
|
7
|
+
* deterministic, idempotent codemod get a fixer; everything else is reported
|
|
8
|
+
* as skipped by the fix loop.
|
|
9
|
+
*
|
|
10
|
+
* Idempotency invariant: every rewrite lands the value on the safe side of
|
|
11
|
+
* the detector's threshold, so re-running a fixer on fixed output produces
|
|
12
|
+
* zero edits (the fix loop's convergence guarantee relies on this).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
extractCssRegions,
|
|
17
|
+
findDeclarations,
|
|
18
|
+
declBlockInfo,
|
|
19
|
+
parseCssValue,
|
|
20
|
+
blockFontSizePx,
|
|
21
|
+
splitTopLevel,
|
|
22
|
+
} from './css-regions.mjs';
|
|
23
|
+
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
// Shared helpers
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
|
|
28
|
+
function withImportant(value, important) {
|
|
29
|
+
return important ? `${value} !important` : value;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Walk each region and each `prop` declaration, calling cb with full context.
|
|
33
|
+
* cb may return one edit (region-local offsets) or null. */
|
|
34
|
+
function eachDeclaration(content, ext, prop, cb) {
|
|
35
|
+
const edits = [];
|
|
36
|
+
for (const region of extractCssRegions(content, ext)) {
|
|
37
|
+
for (const decl of findDeclarations(region.text, prop)) {
|
|
38
|
+
const block = declBlockInfo(region.text, decl.declStart);
|
|
39
|
+
const selector = block.selector !== null ? block.selector : region.selectorHint;
|
|
40
|
+
const edit = cb({ region, decl, block, selector });
|
|
41
|
+
if (edit) {
|
|
42
|
+
edits.push({
|
|
43
|
+
start: region.start + edit.start,
|
|
44
|
+
end: region.start + edit.end,
|
|
45
|
+
replacement: edit.replacement,
|
|
46
|
+
note: edit.note,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return edits;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Edit that removes a whole declaration, including its trailing `;` and any
|
|
55
|
+
* leading whitespace back to the previous boundary. Region-local offsets. */
|
|
56
|
+
function removeDeclaration(text, decl, note) {
|
|
57
|
+
let start = decl.declStart;
|
|
58
|
+
while (start > 0 && /\s/.test(text[start - 1])) start--;
|
|
59
|
+
return { start, end: decl.terminator, replacement: '', note };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const LAYOUT_PROP_RE = /^(?:(?:max|min)-)?(?:width|height)$|^padding(?:-(?:top|right|bottom|left))?$|^margin(?:-(?:top|right|bottom|left))?$/i;
|
|
63
|
+
|
|
64
|
+
const BODY_COPY_TAGS = new Set(['p', 'li', 'blockquote', 'dd']);
|
|
65
|
+
|
|
66
|
+
/** Does a selector list unambiguously target body copy? Every selector in the
|
|
67
|
+
* list must qualify — either its final element is a body-copy tag, or it
|
|
68
|
+
* carries a body-copy class name with no label/heading counter-signal. */
|
|
69
|
+
function selectorTargetsBodyCopy(selector) {
|
|
70
|
+
if (!selector) return false;
|
|
71
|
+
const parts = selector.split(',').map(s => s.trim()).filter(Boolean);
|
|
72
|
+
if (parts.length === 0) return false;
|
|
73
|
+
return parts.every(sel => {
|
|
74
|
+
const last = sel.split(/[\s>+~]+/).filter(Boolean).pop() || '';
|
|
75
|
+
if (/^(p|li|blockquote|dd)(?![\w-])/i.test(last)) return true;
|
|
76
|
+
const classes = last.match(/\.[\w-]+/g) || [];
|
|
77
|
+
return classes.some(c =>
|
|
78
|
+
/(body|paragraph|prose|copy|desc|text)/i.test(c) &&
|
|
79
|
+
!/(label|badge|button|nav|heading|title|caps|eyebrow|kicker|tag|chip)/i.test(c));
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
// Fixers
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
|
|
87
|
+
/** tight-leading — line-height computing below 1.3x font size → 1.5. */
|
|
88
|
+
function fixTightLeading(content, ext) {
|
|
89
|
+
return eachDeclaration(content, ext, 'line-height', ({ decl, block }) => {
|
|
90
|
+
const parsed = parseCssValue(decl.value);
|
|
91
|
+
if (!parsed) return null;
|
|
92
|
+
let ratio = null;
|
|
93
|
+
if (parsed.unit === '' ) ratio = parsed.num;
|
|
94
|
+
else if (parsed.unit === 'em') ratio = parsed.num;
|
|
95
|
+
else if (parsed.unit === '%') ratio = parsed.num / 100;
|
|
96
|
+
else if (parsed.unit === 'px') {
|
|
97
|
+
const fs = blockFontSizePx(block.body);
|
|
98
|
+
if (fs) ratio = parsed.num / fs;
|
|
99
|
+
}
|
|
100
|
+
if (ratio === null || ratio <= 0 || ratio >= 1.3) return null;
|
|
101
|
+
return {
|
|
102
|
+
start: decl.valueStart,
|
|
103
|
+
end: decl.valueEnd,
|
|
104
|
+
replacement: withImportant('1.5', parsed.important),
|
|
105
|
+
note: `line-height ${decl.value} -> 1.5`,
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** tiny-text — font-size below 12px → 12px (px / rem only; em is
|
|
111
|
+
* parent-relative and not statically computable). */
|
|
112
|
+
function fixTinyText(content, ext) {
|
|
113
|
+
return eachDeclaration(content, ext, 'font-size', ({ decl }) => {
|
|
114
|
+
const parsed = parseCssValue(decl.value);
|
|
115
|
+
if (!parsed) return null;
|
|
116
|
+
let replacement = null;
|
|
117
|
+
if (parsed.unit === 'px' && parsed.num > 0 && parsed.num < 12) replacement = '12px';
|
|
118
|
+
else if (parsed.unit === 'rem' && parsed.num > 0 && parsed.num < 0.75) replacement = '0.75rem';
|
|
119
|
+
if (!replacement) return null;
|
|
120
|
+
return {
|
|
121
|
+
start: decl.valueStart,
|
|
122
|
+
end: decl.valueEnd,
|
|
123
|
+
replacement: withImportant(replacement, parsed.important),
|
|
124
|
+
note: `font-size ${decl.value} -> ${replacement}`,
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** justified-text — text-align: justify without hyphenation → add
|
|
130
|
+
* `hyphens: auto` in the same declaration block (or rewrite a non-auto
|
|
131
|
+
* hyphens declaration already present). */
|
|
132
|
+
function fixJustifiedText(content, ext) {
|
|
133
|
+
return eachDeclaration(content, ext, 'text-align', ({ region, decl, block }) => {
|
|
134
|
+
if (!/^justify$/i.test(decl.value.replace(/!\s*important/i, '').trim())) return null;
|
|
135
|
+
const hyphens = findDeclarations(block.body, '(?:-webkit-)?hyphens');
|
|
136
|
+
const hasAuto = hyphens.some(h => /^auto$/i.test(h.value.replace(/!\s*important/i, '').trim()));
|
|
137
|
+
if (hasAuto) return null;
|
|
138
|
+
if (hyphens.length > 0) {
|
|
139
|
+
// A hyphens declaration exists but isn't auto — rewrite it.
|
|
140
|
+
const h = hyphens[hyphens.length - 1];
|
|
141
|
+
return {
|
|
142
|
+
start: block.bodyStart + h.valueStart,
|
|
143
|
+
end: block.bodyStart + h.valueEnd,
|
|
144
|
+
replacement: 'auto',
|
|
145
|
+
note: `hyphens ${h.value} -> auto (justified text)`,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
// Insert after the text-align declaration.
|
|
149
|
+
const afterSemi = region.text[decl.terminator - 1] === ';';
|
|
150
|
+
return afterSemi
|
|
151
|
+
? { start: decl.terminator, end: decl.terminator, replacement: ' hyphens: auto;', note: 'add hyphens: auto next to text-align: justify' }
|
|
152
|
+
: { start: decl.valueEnd, end: decl.valueEnd, replacement: '; hyphens: auto', note: 'add hyphens: auto next to text-align: justify' };
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** wide-tracking — letter-spacing above 0.05em on body text → clamp to
|
|
157
|
+
* 0.05em. Skips blocks that set uppercase (the detector exempts uppercase
|
|
158
|
+
* labels, where wide tracking is legitimate). */
|
|
159
|
+
function fixWideTracking(content, ext) {
|
|
160
|
+
return eachDeclaration(content, ext, 'letter-spacing', ({ decl, block }) => {
|
|
161
|
+
if (/text-transform\s*:\s*uppercase/i.test(block.body)) return null;
|
|
162
|
+
const parsed = parseCssValue(decl.value);
|
|
163
|
+
if (!parsed || parsed.num <= 0) return null;
|
|
164
|
+
let em = null;
|
|
165
|
+
if (parsed.unit === 'em') em = parsed.num;
|
|
166
|
+
else if (parsed.unit === 'px' || parsed.unit === 'rem') {
|
|
167
|
+
const fs = blockFontSizePx(block.body);
|
|
168
|
+
if (fs) em = (parsed.unit === 'px' ? parsed.num : parsed.num * 16) / fs;
|
|
169
|
+
}
|
|
170
|
+
if (em === null || em <= 0.05) return null;
|
|
171
|
+
return {
|
|
172
|
+
start: decl.valueStart,
|
|
173
|
+
end: decl.valueEnd,
|
|
174
|
+
replacement: withImportant('0.05em', parsed.important),
|
|
175
|
+
note: `letter-spacing ${decl.value} -> 0.05em`,
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** extreme-negative-tracking — letter-spacing at or below -0.05em → clamp to
|
|
181
|
+
* -0.04em (optical tightening territory, below the detector's floor). */
|
|
182
|
+
function fixExtremeNegativeTracking(content, ext) {
|
|
183
|
+
return eachDeclaration(content, ext, 'letter-spacing', ({ decl, block }) => {
|
|
184
|
+
const parsed = parseCssValue(decl.value);
|
|
185
|
+
if (!parsed || parsed.num >= 0) return null;
|
|
186
|
+
let em = null;
|
|
187
|
+
if (parsed.unit === 'em') em = parsed.num;
|
|
188
|
+
else if (parsed.unit === 'px' || parsed.unit === 'rem') {
|
|
189
|
+
const fs = blockFontSizePx(block.body);
|
|
190
|
+
if (fs) em = (parsed.unit === 'px' ? parsed.num : parsed.num * 16) / fs;
|
|
191
|
+
}
|
|
192
|
+
if (em === null || em > -0.05) return null;
|
|
193
|
+
return {
|
|
194
|
+
start: decl.valueStart,
|
|
195
|
+
end: decl.valueEnd,
|
|
196
|
+
replacement: withImportant('-0.04em', parsed.important),
|
|
197
|
+
note: `letter-spacing ${decl.value} -> -0.04em`,
|
|
198
|
+
};
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** layout-transition — drop width/height/padding/margin entries from
|
|
203
|
+
* transition lists (transform/opacity and everything else stay). Removes the
|
|
204
|
+
* declaration entirely when no entries survive. */
|
|
205
|
+
function fixLayoutTransition(content, ext) {
|
|
206
|
+
const edits = [];
|
|
207
|
+
for (const propName of ['transition', 'transition-property']) {
|
|
208
|
+
edits.push(...eachDeclaration(content, ext, propName, ({ region, decl }) => {
|
|
209
|
+
const important = /!\s*important/i.test(decl.value);
|
|
210
|
+
const value = decl.value.replace(/!\s*important/i, '').trim();
|
|
211
|
+
if (/\ball\b/i.test(value)) return null; // detector skips `all` too
|
|
212
|
+
const items = splitTopLevel(value);
|
|
213
|
+
const kept = items.filter(item => {
|
|
214
|
+
const prop = propName === 'transition-property'
|
|
215
|
+
? item.trim()
|
|
216
|
+
: (item.trim().split(/\s+/)[0] || '');
|
|
217
|
+
return !LAYOUT_PROP_RE.test(prop);
|
|
218
|
+
});
|
|
219
|
+
if (kept.length === items.length) return null;
|
|
220
|
+
if (kept.length === 0) {
|
|
221
|
+
return { ...removeDeclaration(region.text, decl, `remove ${propName} (all entries animated layout)`) };
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
start: decl.valueStart,
|
|
225
|
+
end: decl.valueEnd,
|
|
226
|
+
replacement: withImportant(kept.join(', '), important),
|
|
227
|
+
note: `${propName}: drop layout properties, keep ${kept.join(', ')}`,
|
|
228
|
+
};
|
|
229
|
+
}));
|
|
230
|
+
}
|
|
231
|
+
return edits;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** all-caps-body — remove text-transform: uppercase, but only where the
|
|
235
|
+
* selector unambiguously targets body copy (or the inline style sits on a
|
|
236
|
+
* body-copy tag). Anything selector-ambiguous is left for a human. */
|
|
237
|
+
function fixAllCapsBody(content, ext) {
|
|
238
|
+
return eachDeclaration(content, ext, 'text-transform', ({ region, decl, block, selector }) => {
|
|
239
|
+
if (!/^uppercase$/i.test(decl.value.replace(/!\s*important/i, '').trim())) return null;
|
|
240
|
+
const qualifies = block.selector !== null
|
|
241
|
+
? selectorTargetsBodyCopy(selector)
|
|
242
|
+
: BODY_COPY_TAGS.has(region.selectorHint || '');
|
|
243
|
+
if (!qualifies) return null;
|
|
244
|
+
return { ...removeDeclaration(region.text, decl, `remove text-transform: uppercase from ${selector || 'body copy'}`) };
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** skipped-heading — demote headings whose level skips past the previous
|
|
249
|
+
* heading (h1 -> h3 becomes h1 -> h2), walking the document in source order
|
|
250
|
+
* exactly like the detector does. Only the unambiguous "close the gap"
|
|
251
|
+
* demotion is applied; open and close tags are rewritten in pairs. */
|
|
252
|
+
function fixSkippedHeadings(content, ext) {
|
|
253
|
+
if (!['.html', '.htm', '.vue', '.svelte', '.astro'].includes((ext || '').toLowerCase())) return [];
|
|
254
|
+
const edits = [];
|
|
255
|
+
const tagRe = /<(\/?)h([1-6])\b/gi;
|
|
256
|
+
let prevLevel = 0;
|
|
257
|
+
let pending = null; // { origLevel, newLevel } awaiting the matching close tag
|
|
258
|
+
let m;
|
|
259
|
+
while ((m = tagRe.exec(content)) !== null) {
|
|
260
|
+
const isClose = m[1] === '/';
|
|
261
|
+
const level = parseInt(m[2], 10);
|
|
262
|
+
const digitIdx = m.index + m[0].length - 1;
|
|
263
|
+
if (isClose) {
|
|
264
|
+
if (pending && level === pending.origLevel) {
|
|
265
|
+
edits.push({
|
|
266
|
+
start: digitIdx,
|
|
267
|
+
end: digitIdx + 1,
|
|
268
|
+
replacement: String(pending.newLevel),
|
|
269
|
+
note: `</h${pending.origLevel}> -> </h${pending.newLevel}>`,
|
|
270
|
+
});
|
|
271
|
+
pending = null;
|
|
272
|
+
}
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
let newLevel = level;
|
|
276
|
+
if (prevLevel > 0 && level > prevLevel + 1) {
|
|
277
|
+
newLevel = prevLevel + 1;
|
|
278
|
+
edits.push({
|
|
279
|
+
start: digitIdx,
|
|
280
|
+
end: digitIdx + 1,
|
|
281
|
+
replacement: String(newLevel),
|
|
282
|
+
note: `<h${level}> -> <h${newLevel}> (closes gap after h${prevLevel})`,
|
|
283
|
+
});
|
|
284
|
+
pending = { origLevel: level, newLevel };
|
|
285
|
+
} else {
|
|
286
|
+
pending = null;
|
|
287
|
+
}
|
|
288
|
+
prevLevel = newLevel;
|
|
289
|
+
}
|
|
290
|
+
return edits;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// ---------------------------------------------------------------------------
|
|
294
|
+
// Registry
|
|
295
|
+
// ---------------------------------------------------------------------------
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Rules with a deterministic, safe, idempotent codemod.
|
|
299
|
+
* fix(content, ext) -> [{ start, end, replacement, note }]
|
|
300
|
+
*/
|
|
301
|
+
const FIXERS = {
|
|
302
|
+
'tight-leading': {
|
|
303
|
+
description: 'raise sub-1.3 line-height to 1.5',
|
|
304
|
+
fix: fixTightLeading,
|
|
305
|
+
},
|
|
306
|
+
'tiny-text': {
|
|
307
|
+
description: 'raise sub-12px font-size to the 12px minimum',
|
|
308
|
+
fix: fixTinyText,
|
|
309
|
+
},
|
|
310
|
+
'justified-text': {
|
|
311
|
+
description: 'add hyphens: auto next to text-align: justify',
|
|
312
|
+
fix: fixJustifiedText,
|
|
313
|
+
},
|
|
314
|
+
'wide-tracking': {
|
|
315
|
+
description: 'clamp body-text letter-spacing to 0.05em',
|
|
316
|
+
fix: fixWideTracking,
|
|
317
|
+
},
|
|
318
|
+
'extreme-negative-tracking': {
|
|
319
|
+
description: 'clamp crushed letter-spacing to -0.04em',
|
|
320
|
+
fix: fixExtremeNegativeTracking,
|
|
321
|
+
},
|
|
322
|
+
'layout-transition': {
|
|
323
|
+
description: 'drop width/height/padding/margin from transition lists',
|
|
324
|
+
fix: fixLayoutTransition,
|
|
325
|
+
},
|
|
326
|
+
'all-caps-body': {
|
|
327
|
+
description: 'remove text-transform: uppercase from body-copy selectors',
|
|
328
|
+
fix: fixAllCapsBody,
|
|
329
|
+
},
|
|
330
|
+
'skipped-heading': {
|
|
331
|
+
description: 'demote heading tags to close skipped levels',
|
|
332
|
+
fix: fixSkippedHeadings,
|
|
333
|
+
},
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Rules deliberately without a fixer, with the reason surfaced in reports.
|
|
338
|
+
* broken-image is the canonical example: choosing a real image (or deciding
|
|
339
|
+
* the tag should go) is a content decision — any deterministic rewrite
|
|
340
|
+
* (placeholder URL, removing the tag) would guess at intent, so it is not
|
|
341
|
+
* safely fixable.
|
|
342
|
+
*/
|
|
343
|
+
const UNFIXABLE_REASONS = {
|
|
344
|
+
'broken-image': 'not safely fixable: supplying a real image (or removing the tag) is a content decision, not a codemod',
|
|
345
|
+
'low-contrast': 'not safely fixable: picking replacement colors is a palette decision',
|
|
346
|
+
'overused-font': 'not safely fixable: choosing a replacement typeface is a brand decision',
|
|
347
|
+
'skipped-heading-ambiguous': 'heading structure too ambiguous to rewrite automatically',
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
function getFixer(ruleId) {
|
|
351
|
+
return FIXERS[ruleId] || null;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function fixableRuleIds() {
|
|
355
|
+
return Object.keys(FIXERS);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export {
|
|
359
|
+
FIXERS,
|
|
360
|
+
UNFIXABLE_REASONS,
|
|
361
|
+
getFixer,
|
|
362
|
+
fixableRuleIds,
|
|
363
|
+
// exported for direct unit testing
|
|
364
|
+
fixTightLeading,
|
|
365
|
+
fixTinyText,
|
|
366
|
+
fixJustifiedText,
|
|
367
|
+
fixWideTracking,
|
|
368
|
+
fixExtremeNegativeTracking,
|
|
369
|
+
fixLayoutTransition,
|
|
370
|
+
fixAllCapsBody,
|
|
371
|
+
fixSkippedHeadings,
|
|
372
|
+
selectorTargetsBodyCopy,
|
|
373
|
+
};
|