@getchomp/mcp 0.0.0-stage → 0.2.42
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 +15 -2
- package/dist/conventionsReference.d.ts +84 -0
- package/dist/conventionsReference.js +313 -0
- package/dist/designSystem/astScanner.d.ts +153 -0
- package/dist/designSystem/astScanner.js +2014 -0
- package/dist/designSystem/baseline.d.ts +65 -0
- package/dist/designSystem/baseline.js +136 -0
- package/dist/designSystem/color.d.ts +35 -0
- package/dist/designSystem/color.js +265 -0
- package/dist/designSystem/config.d.ts +183 -0
- package/dist/designSystem/config.js +469 -0
- package/dist/designSystem/contrast.d.ts +55 -0
- package/dist/designSystem/contrast.js +377 -0
- package/dist/designSystem/cssParser.d.ts +63 -0
- package/dist/designSystem/cssParser.js +469 -0
- package/dist/designSystem/merges.d.ts +57 -0
- package/dist/designSystem/merges.js +94 -0
- package/dist/designSystem/preprocessors.d.ts +46 -0
- package/dist/designSystem/preprocessors.js +1108 -0
- package/dist/designSystem/presentation.d.ts +45 -0
- package/dist/designSystem/presentation.js +796 -0
- package/dist/designSystem/styleVectors.d.ts +27 -0
- package/dist/designSystem/styleVectors.js +484 -0
- package/dist/designSystem/tokens.d.ts +39 -0
- package/dist/designSystem/tokens.js +409 -0
- package/dist/designSystem/topology.d.ts +64 -0
- package/dist/designSystem/topology.js +254 -0
- package/dist/designSystem/types.d.ts +857 -0
- package/dist/designSystem/types.js +113 -0
- package/dist/designSystem/typography.d.ts +25 -0
- package/dist/designSystem/typography.js +244 -0
- package/dist/designSystem/uiShapes.d.ts +74 -0
- package/dist/designSystem/uiShapes.js +285 -0
- package/dist/designSystem/valueClusters.d.ts +76 -0
- package/dist/designSystem/valueClusters.js +281 -0
- package/dist/designSystemPlugin.d.ts +321 -0
- package/dist/designSystemPlugin.js +4730 -0
- package/dist/enrichNodesPlugin.d.ts +160 -0
- package/dist/enrichNodesPlugin.js +957 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +1298 -0
- package/dist/intelligence.d.ts +502 -0
- package/dist/intelligence.js +3058 -0
- package/dist/pluginRunner.d.ts +364 -0
- package/dist/pluginRunner.js +1096 -0
- package/dist/plugins/design-system/index.d.ts +14 -0
- package/dist/plugins/design-system/index.js +241 -0
- package/dist/plugins/enrich-nodes/index.d.ts +388 -0
- package/dist/plugins/enrich-nodes/index.js +697 -0
- package/dist/plugins/index.d.ts +15 -0
- package/dist/plugins/index.js +20 -0
- package/dist/plugins/local-shims/index.d.ts +121 -0
- package/dist/plugins/local-shims/index.js +237 -0
- package/dist/shimsPlugin.d.ts +134 -0
- package/dist/shimsPlugin.js +1392 -0
- package/package.json +38 -3
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* packages/mcp/src/designSystem/types.ts
|
|
3
|
+
*
|
|
4
|
+
* Canonical types & framework-agnostic UI role conventions for `L1_DESIGN_SYSTEM`.
|
|
5
|
+
* Leaf module in the `designSystem/` DAG (zero back-edges to `designSystemPlugin.ts`).
|
|
6
|
+
*/
|
|
7
|
+
export const UI_ROLE_CONVENTIONS = [
|
|
8
|
+
{
|
|
9
|
+
id: "nextjs.route",
|
|
10
|
+
framework: "Next.js",
|
|
11
|
+
role: "ROUTE",
|
|
12
|
+
entityTypes: ["NEXTJS_PAGE"],
|
|
13
|
+
patternIdPrefixes: ["nextjs.page", "nextjs.app-page", "nextjs.pages-page"],
|
|
14
|
+
filePathPatterns: [
|
|
15
|
+
/(?:^|\/)app\/(?:.*\/)?page\.(?:tsx|jsx|ts|js)$/i,
|
|
16
|
+
/(?:^|\/)pages\/(?!_app|_document|api\/).+\.(?:tsx|jsx|ts|js)$/i,
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: "nextjs.template",
|
|
21
|
+
framework: "Next.js",
|
|
22
|
+
role: "TEMPLATE",
|
|
23
|
+
entityTypes: ["NEXTJS_LAYOUT"],
|
|
24
|
+
patternIdPrefixes: ["nextjs.layout", "nextjs.template"],
|
|
25
|
+
filePathPatterns: [
|
|
26
|
+
/(?:^|\/)app\/(?:.*\/)?(?:layout|template)\.(?:tsx|jsx|ts|js)$/i,
|
|
27
|
+
/(?:^|\/)pages\/(?:_app|_document)\.(?:tsx|jsx|ts|js)$/i,
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: "remix-react-router.route",
|
|
32
|
+
framework: "Remix / React Router",
|
|
33
|
+
role: "ROUTE",
|
|
34
|
+
entityTypes: ["REMIX_ROUTE", "REACT_ROUTER_ROUTE", "ROUTE_MODULE"],
|
|
35
|
+
patternIdPrefixes: ["remix.route", "react-router.route"],
|
|
36
|
+
filePathPatterns: [
|
|
37
|
+
/(?:^|\/)routes\/[^/]+\.(?:tsx|jsx|ts|js)$/i,
|
|
38
|
+
/(?:^|\/)routes\/.+\/route\.(?:tsx|jsx|ts|js)$/i,
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: "astro-svelte-vue.route",
|
|
43
|
+
framework: "Astro / SvelteKit / Nuxt",
|
|
44
|
+
role: "ROUTE",
|
|
45
|
+
entityTypes: ["ASTRO_PAGE", "SVELTEKIT_PAGE", "NUXT_PAGE", "VUE_PAGE"],
|
|
46
|
+
patternIdPrefixes: ["astro.page", "sveltekit.page", "nuxt.page", "vue.page"],
|
|
47
|
+
filePathPatterns: [
|
|
48
|
+
/(?:^|\/)routes\/(?:.*\/)?\+page\.(?:svelte|ts|js)$/i,
|
|
49
|
+
/(?:^|\/)pages\/.+\.(?:astro|vue|svelte)$/i,
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: "astro-svelte-vue.template",
|
|
54
|
+
framework: "Astro / SvelteKit / Nuxt",
|
|
55
|
+
role: "TEMPLATE",
|
|
56
|
+
entityTypes: ["ASTRO_LAYOUT", "SVELTEKIT_LAYOUT", "NUXT_LAYOUT"],
|
|
57
|
+
patternIdPrefixes: ["astro.layout", "sveltekit.layout", "nuxt.layout"],
|
|
58
|
+
filePathPatterns: [
|
|
59
|
+
/(?:^|\/)routes\/(?:.*\/)?\+layout\.(?:svelte|ts|js)$/i,
|
|
60
|
+
/(?:^|\/)layouts\/.+\.(?:astro|vue|svelte|tsx|jsx)$/i,
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: "generic-spa.route",
|
|
65
|
+
framework: "Generic SPA / Views",
|
|
66
|
+
role: "ROUTE",
|
|
67
|
+
entityTypes: ["ROUTE", "SCREEN", "PAGE", "VIEW_SCREEN"],
|
|
68
|
+
patternIdPrefixes: ["spa.route", "spa.screen", "swiftui.screen"],
|
|
69
|
+
filePathPatterns: [
|
|
70
|
+
/(?:^|\/)(?:screens|views|pages)\/[^/]+(?:Page|Screen|View|Route)\.(?:tsx|jsx|vue|svelte|swift)$/i,
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: "generic-ui.template",
|
|
75
|
+
framework: "Generic UI",
|
|
76
|
+
role: "TEMPLATE",
|
|
77
|
+
entityTypes: ["LAYOUT", "TEMPLATE", "APP_SHELL"],
|
|
78
|
+
patternIdPrefixes: ["ui.layout", "ui.template"],
|
|
79
|
+
filePathPatterns: [
|
|
80
|
+
/(?:^|\/)(?:templates|shells|layouts)\/[^/]+\.(?:tsx|jsx|vue|svelte)$/i,
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: "atomic-dir.atom",
|
|
85
|
+
framework: "Atomic Design Convention",
|
|
86
|
+
role: "ATOM",
|
|
87
|
+
entityTypes: ["UI_ATOM", "UI_PRIMITIVE"],
|
|
88
|
+
patternIdPrefixes: ["ui.atom", "ui.primitive"],
|
|
89
|
+
filePathPatterns: [
|
|
90
|
+
/(?:^|\/)(?:atoms|primitives|components\/ui|ui\/primitives)\/[^/]+\.(?:tsx|jsx|vue|svelte)$/i,
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: "atomic-dir.molecule",
|
|
95
|
+
framework: "Atomic Design Convention",
|
|
96
|
+
role: "MOLECULE",
|
|
97
|
+
entityTypes: ["UI_MOLECULE"],
|
|
98
|
+
patternIdPrefixes: ["ui.molecule"],
|
|
99
|
+
filePathPatterns: [
|
|
100
|
+
/(?:^|\/)molecules\/[^/]+\.(?:tsx|jsx|vue|svelte)$/i,
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
id: "atomic-dir.organism",
|
|
105
|
+
framework: "Atomic Design Convention",
|
|
106
|
+
role: "ORGANISM",
|
|
107
|
+
entityTypes: ["UI_ORGANISM"],
|
|
108
|
+
patternIdPrefixes: ["ui.organism"],
|
|
109
|
+
filePathPatterns: [
|
|
110
|
+
/(?:^|\/)(?:organisms|features|widgets)\/[^/]+\.(?:tsx|jsx|vue|svelte)$/i,
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* packages/mcp/src/designSystem/typography.ts
|
|
3
|
+
*
|
|
4
|
+
* Composite Typography 6-tuple extraction (`fontFamily`, `fontSize`, `fontWeight`,
|
|
5
|
+
* `lineHeight`, `letterSpacing`, `textTransform`), inferred role drift clustering
|
|
6
|
+
* across CSS + Tailwind utilities, and contextual CSS override detection (descendant
|
|
7
|
+
* heading overrides and cross-block BEM overrides).
|
|
8
|
+
*/
|
|
9
|
+
import type { TailwindTypographyUsageGroup } from "./astScanner.js";
|
|
10
|
+
import type { ParsedCssRule } from "./cssParser.js";
|
|
11
|
+
import { type TokenLookupMaps } from "./styleVectors.js";
|
|
12
|
+
import type { CompositeTypeTuple, ContextualStyleOverrideFinding, TypographyRoleCluster } from "./types.js";
|
|
13
|
+
export interface TypographyExtractionResult {
|
|
14
|
+
typographyTuples: CompositeTypeTuple[];
|
|
15
|
+
typographyRoleClusters: TypographyRoleCluster[];
|
|
16
|
+
contextualStyleOverrides: ContextualStyleOverrideFinding[];
|
|
17
|
+
}
|
|
18
|
+
export declare function analyzeTypographyAndContextualOverrides(params: {
|
|
19
|
+
styleRules: readonly ParsedCssRule[];
|
|
20
|
+
tailwindGroups: ReadonlyArray<{
|
|
21
|
+
componentName: string;
|
|
22
|
+
group: TailwindTypographyUsageGroup;
|
|
23
|
+
}>;
|
|
24
|
+
tokenMaps: TokenLookupMaps;
|
|
25
|
+
}): TypographyExtractionResult;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* packages/mcp/src/designSystem/typography.ts
|
|
3
|
+
*
|
|
4
|
+
* Composite Typography 6-tuple extraction (`fontFamily`, `fontSize`, `fontWeight`,
|
|
5
|
+
* `lineHeight`, `letterSpacing`, `textTransform`), inferred role drift clustering
|
|
6
|
+
* across CSS + Tailwind utilities, and contextual CSS override detection (descendant
|
|
7
|
+
* heading overrides and cross-block BEM overrides).
|
|
8
|
+
*/
|
|
9
|
+
import { extractStyleVectorFromClassesAndInline, extractStyleVectorFromCssRule, } from "./styleVectors.js";
|
|
10
|
+
import { parseCssLengthToPx } from "./valueClusters.js";
|
|
11
|
+
const TYPOGRAPHY_PROPS = new Set([
|
|
12
|
+
"font-family",
|
|
13
|
+
"font-size",
|
|
14
|
+
"font-weight",
|
|
15
|
+
"line-height",
|
|
16
|
+
"letter-spacing",
|
|
17
|
+
"text-transform",
|
|
18
|
+
]);
|
|
19
|
+
function inferTypographyRole(tuple, headingTags) {
|
|
20
|
+
const famLower = tuple.fontFamily.toLowerCase();
|
|
21
|
+
const wt = Number(tuple.fontWeight);
|
|
22
|
+
const px = tuple.fontSizePx;
|
|
23
|
+
if (headingTags && headingTags.length > 0)
|
|
24
|
+
return "heading";
|
|
25
|
+
if (famLower !== "(unset)" &&
|
|
26
|
+
/\b(?:mono|monospace|jetbrains|fira|consolas|menlo|sfmono)\b/.test(famLower)) {
|
|
27
|
+
return "code-mono";
|
|
28
|
+
}
|
|
29
|
+
if (tuple.textTransform === "uppercase") {
|
|
30
|
+
return "label-eyebrow";
|
|
31
|
+
}
|
|
32
|
+
if (px !== undefined && (px >= 16 || (px >= 14.5 && Number.isFinite(wt) && wt >= 600))) {
|
|
33
|
+
if ((!headingTags || headingTags.length === 0) &&
|
|
34
|
+
tuple.fontFamily === "(inherit)" &&
|
|
35
|
+
tuple.fontWeight === "(inherit)" &&
|
|
36
|
+
tuple.lineHeight === "1") {
|
|
37
|
+
return "other";
|
|
38
|
+
}
|
|
39
|
+
return "heading";
|
|
40
|
+
}
|
|
41
|
+
if (px !== undefined && px <= 11.5) {
|
|
42
|
+
return "micro-badge";
|
|
43
|
+
}
|
|
44
|
+
if (px !== undefined && px > 11.5 && px < 16) {
|
|
45
|
+
return "body";
|
|
46
|
+
}
|
|
47
|
+
return "other";
|
|
48
|
+
}
|
|
49
|
+
function buildCompositeSignature(t) {
|
|
50
|
+
return [
|
|
51
|
+
t.fontFamily,
|
|
52
|
+
t.fontSize,
|
|
53
|
+
t.fontWeight,
|
|
54
|
+
t.lineHeight,
|
|
55
|
+
t.letterSpacing,
|
|
56
|
+
t.textTransform,
|
|
57
|
+
].join(" | ");
|
|
58
|
+
}
|
|
59
|
+
export function analyzeTypographyAndContextualOverrides(params) {
|
|
60
|
+
const tupleMap = new Map();
|
|
61
|
+
const recordTuple = (raw, occ, headingTags) => {
|
|
62
|
+
const fontFamily = raw.fontFamily?.trim() || "(inherit)";
|
|
63
|
+
const fontSize = raw.fontSize?.trim() || "(inherit)";
|
|
64
|
+
const fontWeight = raw.fontWeight?.trim() || "(inherit)";
|
|
65
|
+
const lineHeight = raw.lineHeight?.trim() || "(inherit)";
|
|
66
|
+
const letterSpacing = raw.letterSpacing?.trim() || "(inherit)";
|
|
67
|
+
const textTransform = raw.textTransform?.trim() || "none";
|
|
68
|
+
const parsedSize = fontSize !== "(inherit)" ? parseCssLengthToPx(fontSize) : null;
|
|
69
|
+
const fontSizePx = parsedSize ? Math.round(parsedSize.px * 100) / 100 : undefined;
|
|
70
|
+
const signature = buildCompositeSignature({
|
|
71
|
+
fontFamily,
|
|
72
|
+
fontSize,
|
|
73
|
+
fontWeight,
|
|
74
|
+
lineHeight,
|
|
75
|
+
letterSpacing,
|
|
76
|
+
textTransform,
|
|
77
|
+
});
|
|
78
|
+
let existing = tupleMap.get(signature);
|
|
79
|
+
if (!existing) {
|
|
80
|
+
const inferredRole = inferTypographyRole({
|
|
81
|
+
fontFamily,
|
|
82
|
+
fontSize,
|
|
83
|
+
fontSizePx,
|
|
84
|
+
fontWeight,
|
|
85
|
+
lineHeight,
|
|
86
|
+
letterSpacing,
|
|
87
|
+
textTransform,
|
|
88
|
+
}, headingTags);
|
|
89
|
+
existing = {
|
|
90
|
+
signature,
|
|
91
|
+
fontFamily,
|
|
92
|
+
fontSize,
|
|
93
|
+
...(fontSizePx !== undefined ? { fontSizePx } : {}),
|
|
94
|
+
fontWeight,
|
|
95
|
+
lineHeight,
|
|
96
|
+
letterSpacing,
|
|
97
|
+
textTransform,
|
|
98
|
+
inferredRole,
|
|
99
|
+
occurrenceCount: 0,
|
|
100
|
+
occurrences: [],
|
|
101
|
+
};
|
|
102
|
+
tupleMap.set(signature, existing);
|
|
103
|
+
}
|
|
104
|
+
existing.occurrenceCount++;
|
|
105
|
+
existing.occurrences.push(occ);
|
|
106
|
+
};
|
|
107
|
+
// 1. Extract composite tuples from CSS style rules declaring >= 2 typography properties
|
|
108
|
+
for (const rule of params.styleRules) {
|
|
109
|
+
let typoPropCount = 0;
|
|
110
|
+
for (const d of rule.declarations) {
|
|
111
|
+
if (TYPOGRAPHY_PROPS.has(d.prop))
|
|
112
|
+
typoPropCount++;
|
|
113
|
+
}
|
|
114
|
+
if (typoPropCount < 2)
|
|
115
|
+
continue;
|
|
116
|
+
const vec = extractStyleVectorFromCssRule(rule, params.tokenMaps);
|
|
117
|
+
recordTuple(vec, {
|
|
118
|
+
source: "css",
|
|
119
|
+
symbol: rule.selector,
|
|
120
|
+
filePath: rule.filePath,
|
|
121
|
+
lineNumber: rule.lineNumber,
|
|
122
|
+
}, rule.headingTagsTargeted);
|
|
123
|
+
}
|
|
124
|
+
// 2. Extract composite tuples from TSX/Tailwind typography utility combinations
|
|
125
|
+
for (const { componentName, group } of params.tailwindGroups) {
|
|
126
|
+
const vec = extractStyleVectorFromClassesAndInline(group.classes, {}, params.tokenMaps);
|
|
127
|
+
const definedAxes = [
|
|
128
|
+
vec.fontFamily,
|
|
129
|
+
vec.fontSize,
|
|
130
|
+
vec.fontWeight,
|
|
131
|
+
vec.lineHeight,
|
|
132
|
+
vec.letterSpacing,
|
|
133
|
+
vec.textTransform,
|
|
134
|
+
].filter(Boolean).length;
|
|
135
|
+
if (definedAxes < 2)
|
|
136
|
+
continue;
|
|
137
|
+
recordTuple(vec, {
|
|
138
|
+
source: "tailwind",
|
|
139
|
+
symbol: `${componentName} (${group.classes.join(" ")})`,
|
|
140
|
+
filePath: group.filePath,
|
|
141
|
+
lineNumber: group.lineNumber,
|
|
142
|
+
snippet: group.snippet,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
const typographyTuples = [...tupleMap.values()].sort((a, b) => b.occurrenceCount - a.occurrenceCount || a.signature.localeCompare(b.signature));
|
|
146
|
+
// 3. Group into TypographyRoleClusters where >= 2 distinct tuples share an inferred role
|
|
147
|
+
const byRole = new Map();
|
|
148
|
+
for (const t of typographyTuples) {
|
|
149
|
+
if (t.inferredRole === "other")
|
|
150
|
+
continue;
|
|
151
|
+
let arr = byRole.get(t.inferredRole);
|
|
152
|
+
if (!arr) {
|
|
153
|
+
arr = [];
|
|
154
|
+
byRole.set(t.inferredRole, arr);
|
|
155
|
+
}
|
|
156
|
+
arr.push(t);
|
|
157
|
+
}
|
|
158
|
+
const typographyRoleClusters = [];
|
|
159
|
+
for (const [role, tuples] of byRole.entries()) {
|
|
160
|
+
if (tuples.length < 2)
|
|
161
|
+
continue;
|
|
162
|
+
typographyRoleClusters.push({
|
|
163
|
+
role,
|
|
164
|
+
tupleCount: tuples.length,
|
|
165
|
+
tuples,
|
|
166
|
+
recommendation: `Consolidate ${tuples.length} distinct '${role}' composite typography combinations into a single semantic text role class or component.`,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
typographyRoleClusters.sort((a, b) => b.tupleCount - a.tupleCount);
|
|
170
|
+
// 4. Contextual CSS Override Detection
|
|
171
|
+
const contextualStyleOverrides = [];
|
|
172
|
+
const OVERRIDE_SENSITIVE_PROPS = new Set([
|
|
173
|
+
"font-family",
|
|
174
|
+
"font-size",
|
|
175
|
+
"font-weight",
|
|
176
|
+
"line-height",
|
|
177
|
+
"letter-spacing",
|
|
178
|
+
"text-transform",
|
|
179
|
+
"margin",
|
|
180
|
+
"margin-top",
|
|
181
|
+
"margin-bottom",
|
|
182
|
+
"padding",
|
|
183
|
+
"background",
|
|
184
|
+
"background-color",
|
|
185
|
+
"color",
|
|
186
|
+
]);
|
|
187
|
+
const BLOCK_BEM_CLASS_RE = /\.([a-zA-Z_][a-zA-Z0-9_-]*)/g;
|
|
188
|
+
const STATE_PREFIX_RE = /^(?:is|has)-/;
|
|
189
|
+
for (const rule of params.styleRules) {
|
|
190
|
+
if (!rule.isMultiSegment)
|
|
191
|
+
continue;
|
|
192
|
+
const overrideProps = rule.declarations
|
|
193
|
+
.map((d) => d.prop)
|
|
194
|
+
.filter((p) => OVERRIDE_SENSITIVE_PROPS.has(p));
|
|
195
|
+
if (overrideProps.length === 0)
|
|
196
|
+
continue;
|
|
197
|
+
if (rule.headingTagsTargeted && rule.headingTagsTargeted.length > 0) {
|
|
198
|
+
contextualStyleOverrides.push({
|
|
199
|
+
kind: "descendant-heading-override",
|
|
200
|
+
selector: rule.selector,
|
|
201
|
+
filePath: rule.filePath,
|
|
202
|
+
lineNumber: rule.lineNumber,
|
|
203
|
+
properties: [...new Set(overrideProps)],
|
|
204
|
+
detail: `Contextual descendant selector '${rule.selector}' overrides heading (${rule.headingTagsTargeted.join(", ")}) styling (${[...new Set(overrideProps)].join(", ")}) inside a container instead of using a canonical heading class/atom.`,
|
|
205
|
+
});
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
// Check cross-block BEM override (`.blockA .blockB` or `.blockA .blockB__elem` where blockA !== blockB)
|
|
209
|
+
for (const part of rule.selectorParts ?? [rule.selector]) {
|
|
210
|
+
const cleaned = part.replace(/\[[^\]]+\]/g, "").trim();
|
|
211
|
+
const segments = cleaned.split(/\s*[>+~ ]\s*/).filter(Boolean);
|
|
212
|
+
if (segments.length < 2)
|
|
213
|
+
continue;
|
|
214
|
+
const rootClasses = [...(segments[0].matchAll(BLOCK_BEM_CLASS_RE))]
|
|
215
|
+
.map((m) => m[1])
|
|
216
|
+
.filter((c) => !STATE_PREFIX_RE.test(c));
|
|
217
|
+
const leafClasses = [...(segments[segments.length - 1].matchAll(BLOCK_BEM_CLASS_RE))].map((m) => m[1]);
|
|
218
|
+
if (rootClasses.length === 0 || leafClasses.length === 0)
|
|
219
|
+
continue;
|
|
220
|
+
const rootBlock = rootClasses[0].split("__")[0].split("--")[0];
|
|
221
|
+
const leafBlock = leafClasses[0].split("__")[0].split("--")[0];
|
|
222
|
+
if (rootBlock &&
|
|
223
|
+
leafBlock &&
|
|
224
|
+
rootBlock !== leafBlock &&
|
|
225
|
+
!rootBlock.startsWith(leafBlock) &&
|
|
226
|
+
!leafBlock.startsWith(rootBlock)) {
|
|
227
|
+
contextualStyleOverrides.push({
|
|
228
|
+
kind: "cross-block-bem-override",
|
|
229
|
+
selector: rule.selector,
|
|
230
|
+
filePath: rule.filePath,
|
|
231
|
+
lineNumber: rule.lineNumber,
|
|
232
|
+
properties: [...new Set(overrideProps)],
|
|
233
|
+
detail: `Cross-block selector '${rule.selector}' overrides '.${leafBlock}' styles from inside '.${rootBlock}' (${[...new Set(overrideProps)].join(", ")}).`,
|
|
234
|
+
});
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
typographyTuples,
|
|
241
|
+
typographyRoleClusters,
|
|
242
|
+
contextualStyleOverrides,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* packages/mcp/src/designSystem/uiShapes.ts
|
|
3
|
+
*
|
|
4
|
+
* Authorized atom ownership checks, sibling atom overlap detection, and
|
|
5
|
+
* stateful UI shape detection (`Tabs`, `SegmentedControl`, `BadgePill`)
|
|
6
|
+
* with anti-double-counting absorption of inner raw `<button>` hits.
|
|
7
|
+
*/
|
|
8
|
+
import type { ScannedComponentBucket } from "./astScanner.js";
|
|
9
|
+
import type { AtomDefinition } from "./config.js";
|
|
10
|
+
import type { ParsedCssRule } from "./cssParser.js";
|
|
11
|
+
import { type TokenLookupMaps } from "./styleVectors.js";
|
|
12
|
+
import type { AtomicTier, SiblingAtomOverlapFinding, UnextractedUiShapeFinding } from "./types.js";
|
|
13
|
+
export declare function doesComponentNameMatchAtom(componentName: string, atomTarget: string): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Determines whether a component is an **authorized owner** of a raw DOM primitive (`atomTarget`).
|
|
16
|
+
* Placing a multi-element wrapper (like a labeled trigger slot, stepper, or drawer row) inside
|
|
17
|
+
* an `atoms/` file no longer blanket-exempts it from atom reuse audits.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isAuthorizedAtomOwner(params: {
|
|
20
|
+
componentName: string;
|
|
21
|
+
atomicTier: AtomicTier;
|
|
22
|
+
atomTarget: string;
|
|
23
|
+
jsxDomElementCount: number;
|
|
24
|
+
jsxCustomComponentCount: number;
|
|
25
|
+
canonicalAtomsByTarget: ReadonlyMap<string, string>;
|
|
26
|
+
}): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Picks the canonical shared component name for each `atomTarget` across the repo
|
|
29
|
+
* (prefers exact name match, then `ATOM` tier with highest in-degree / lowest DOM bloat).
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveCanonicalAtomsByTarget(profiles: ReadonlyArray<{
|
|
32
|
+
name: string;
|
|
33
|
+
label: string;
|
|
34
|
+
entityId: string;
|
|
35
|
+
atomicTier: AtomicTier;
|
|
36
|
+
usageCount: number;
|
|
37
|
+
filePath: string;
|
|
38
|
+
domTags: ReadonlySet<string>;
|
|
39
|
+
jsxDomElementCount: number;
|
|
40
|
+
}>, atomCatalog: readonly AtomDefinition[]): Map<string, {
|
|
41
|
+
name: string;
|
|
42
|
+
label: string;
|
|
43
|
+
entityId: string;
|
|
44
|
+
filePath: string;
|
|
45
|
+
}>;
|
|
46
|
+
export interface UiShapesAuditInput {
|
|
47
|
+
entityId: string;
|
|
48
|
+
name: string;
|
|
49
|
+
label: string;
|
|
50
|
+
filePath: string;
|
|
51
|
+
lineNumber?: number;
|
|
52
|
+
atomicTier: AtomicTier;
|
|
53
|
+
usageCount: number;
|
|
54
|
+
bucket: ScannedComponentBucket;
|
|
55
|
+
}
|
|
56
|
+
export interface UiShapesAuditResult {
|
|
57
|
+
/** Component entityId -> set of rawDomPrimitives array indices suppressed because they live inside an extracted shape candidate. */
|
|
58
|
+
suppressedRawDomIndicesByEntity: Map<string, Set<number>>;
|
|
59
|
+
unextractedShapesByEntity: Map<string, UnextractedUiShapeFinding[]>;
|
|
60
|
+
siblingAtomOverlapsByEntity: Map<string, SiblingAtomOverlapFinding[]>;
|
|
61
|
+
allUnextractedShapes: UnextractedUiShapeFinding[];
|
|
62
|
+
allSiblingAtomOverlaps: SiblingAtomOverlapFinding[];
|
|
63
|
+
}
|
|
64
|
+
export declare function analyzeUiShapesAndSiblingOverlaps(params: {
|
|
65
|
+
components: readonly UiShapesAuditInput[];
|
|
66
|
+
canonicalAtomsByTarget: ReadonlyMap<string, {
|
|
67
|
+
name: string;
|
|
68
|
+
label: string;
|
|
69
|
+
entityId: string;
|
|
70
|
+
filePath: string;
|
|
71
|
+
}>;
|
|
72
|
+
cssRulesByClass: ReadonlyMap<string, ParsedCssRule[]>;
|
|
73
|
+
tokenMaps: TokenLookupMaps;
|
|
74
|
+
}): UiShapesAuditResult;
|