@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.
Files changed (56) hide show
  1. package/README.md +15 -2
  2. package/dist/conventionsReference.d.ts +84 -0
  3. package/dist/conventionsReference.js +313 -0
  4. package/dist/designSystem/astScanner.d.ts +153 -0
  5. package/dist/designSystem/astScanner.js +2014 -0
  6. package/dist/designSystem/baseline.d.ts +65 -0
  7. package/dist/designSystem/baseline.js +136 -0
  8. package/dist/designSystem/color.d.ts +35 -0
  9. package/dist/designSystem/color.js +265 -0
  10. package/dist/designSystem/config.d.ts +183 -0
  11. package/dist/designSystem/config.js +469 -0
  12. package/dist/designSystem/contrast.d.ts +55 -0
  13. package/dist/designSystem/contrast.js +377 -0
  14. package/dist/designSystem/cssParser.d.ts +63 -0
  15. package/dist/designSystem/cssParser.js +469 -0
  16. package/dist/designSystem/merges.d.ts +57 -0
  17. package/dist/designSystem/merges.js +94 -0
  18. package/dist/designSystem/preprocessors.d.ts +46 -0
  19. package/dist/designSystem/preprocessors.js +1108 -0
  20. package/dist/designSystem/presentation.d.ts +45 -0
  21. package/dist/designSystem/presentation.js +796 -0
  22. package/dist/designSystem/styleVectors.d.ts +27 -0
  23. package/dist/designSystem/styleVectors.js +484 -0
  24. package/dist/designSystem/tokens.d.ts +39 -0
  25. package/dist/designSystem/tokens.js +409 -0
  26. package/dist/designSystem/topology.d.ts +64 -0
  27. package/dist/designSystem/topology.js +254 -0
  28. package/dist/designSystem/types.d.ts +857 -0
  29. package/dist/designSystem/types.js +113 -0
  30. package/dist/designSystem/typography.d.ts +25 -0
  31. package/dist/designSystem/typography.js +244 -0
  32. package/dist/designSystem/uiShapes.d.ts +74 -0
  33. package/dist/designSystem/uiShapes.js +285 -0
  34. package/dist/designSystem/valueClusters.d.ts +76 -0
  35. package/dist/designSystem/valueClusters.js +281 -0
  36. package/dist/designSystemPlugin.d.ts +321 -0
  37. package/dist/designSystemPlugin.js +4730 -0
  38. package/dist/enrichNodesPlugin.d.ts +160 -0
  39. package/dist/enrichNodesPlugin.js +957 -0
  40. package/dist/index.d.ts +65 -0
  41. package/dist/index.js +1298 -0
  42. package/dist/intelligence.d.ts +502 -0
  43. package/dist/intelligence.js +3058 -0
  44. package/dist/pluginRunner.d.ts +364 -0
  45. package/dist/pluginRunner.js +1096 -0
  46. package/dist/plugins/design-system/index.d.ts +14 -0
  47. package/dist/plugins/design-system/index.js +241 -0
  48. package/dist/plugins/enrich-nodes/index.d.ts +388 -0
  49. package/dist/plugins/enrich-nodes/index.js +697 -0
  50. package/dist/plugins/index.d.ts +15 -0
  51. package/dist/plugins/index.js +20 -0
  52. package/dist/plugins/local-shims/index.d.ts +121 -0
  53. package/dist/plugins/local-shims/index.js +237 -0
  54. package/dist/shimsPlugin.d.ts +134 -0
  55. package/dist/shimsPlugin.js +1392 -0
  56. package/package.json +38 -3
@@ -0,0 +1,27 @@
1
+ /**
2
+ * packages/mcp/src/designSystem/styleVectors.ts
3
+ *
4
+ * Resolves normalized 16-dimension `StylePropertyVector` shapes from CSS declarations,
5
+ * Tailwind v4 utility classes, and JSX inline styles so similar components, UI shapes,
6
+ * and composite typography can be compared structurally across styling conventions.
7
+ */
8
+ import type { ElementStyleSnapshot } from "./astScanner.js";
9
+ import type { ParsedCssRule } from "./cssParser.js";
10
+ import type { CssTokenDeclaration, StylePropertyVector, StyleVectorDelta } from "./types.js";
11
+ export interface TokenLookupMaps {
12
+ root: Map<string, CssTokenDeclaration>;
13
+ dark: Map<string, CssTokenDeclaration>;
14
+ light: Map<string, CssTokenDeclaration>;
15
+ bridge: Map<string, CssTokenDeclaration>;
16
+ }
17
+ export declare function buildTokenLookupMaps(decls: CssTokenDeclaration[]): TokenLookupMaps;
18
+ export declare function resolveCssValue(raw: string, maps: TokenLookupMaps): string;
19
+ export declare function normalizePaddingValues(raw: string, maps: TokenLookupMaps): {
20
+ paddingX?: string;
21
+ paddingY?: string;
22
+ };
23
+ export declare function extractStyleVectorFromCssRule(rule: ParsedCssRule, maps: TokenLookupMaps): Partial<StylePropertyVector>;
24
+ export declare function normalizeFontWeight(raw: string): string;
25
+ export declare function extractStyleVectorFromClassesAndInline(classes: readonly string[], inlineStyle: Record<string, string>, maps: TokenLookupMaps): Partial<StylePropertyVector>;
26
+ export declare function resolveComponentStyleVector(snapshots: readonly ElementStyleSnapshot[], cssRulesByClass: ReadonlyMap<string, ParsedCssRule[]>, maps: TokenLookupMaps): StylePropertyVector | undefined;
27
+ export declare function computeStyleVectorDeltas(left: StylePropertyVector | undefined, right: StylePropertyVector | undefined): StyleVectorDelta[];
@@ -0,0 +1,484 @@
1
+ /**
2
+ * packages/mcp/src/designSystem/styleVectors.ts
3
+ *
4
+ * Resolves normalized 16-dimension `StylePropertyVector` shapes from CSS declarations,
5
+ * Tailwind v4 utility classes, and JSX inline styles so similar components, UI shapes,
6
+ * and composite typography can be compared structurally across styling conventions.
7
+ */
8
+ import { substituteVars } from "./contrast.js";
9
+ import { parseCssLengthToPx } from "./valueClusters.js";
10
+ export function buildTokenLookupMaps(decls) {
11
+ const root = new Map();
12
+ const dark = new Map();
13
+ const light = new Map();
14
+ const bridge = new Map();
15
+ for (const d of decls) {
16
+ if (d.scope === "scoped")
17
+ continue;
18
+ if (d.themeContext === "root")
19
+ root.set(d.name, d);
20
+ else if (d.themeContext === "dark")
21
+ dark.set(d.name, d);
22
+ else if (d.themeContext === "light")
23
+ light.set(d.name, d);
24
+ else if (d.themeContext === "theme-bridge")
25
+ bridge.set(d.name, d);
26
+ }
27
+ return { root, dark, light, bridge };
28
+ }
29
+ export function resolveCssValue(raw, maps) {
30
+ const trimmed = raw.trim().replace(/\s*!important$/i, "").trim();
31
+ if (!trimmed.includes("var(")) {
32
+ return evaluateSimpleCalcs(trimmed);
33
+ }
34
+ const primaryMap = maps.dark.size > 0 ? maps.dark : maps.root;
35
+ const sub = substituteVars(trimmed, primaryMap, maps.root, maps.bridge);
36
+ if (sub === null)
37
+ return trimmed;
38
+ return evaluateSimpleCalcs(sub);
39
+ }
40
+ /** Evaluates simple 2-term `calc(A + B)` or `calc(A - B)` expressions when both terms convert to px. */
41
+ function evaluateSimpleCalcs(expr) {
42
+ return expr
43
+ .trim()
44
+ .replace(/calc\(\s*([^\s()+-]+)\s*([+-])\s*([^\s()]+)\s*\)/gi, (full, lhs, op, rhs) => {
45
+ const a = parseCssLengthToPx(lhs);
46
+ const b = parseCssLengthToPx(rhs);
47
+ if (!a || !b)
48
+ return full;
49
+ const res = op === "+" ? a.px + b.px : a.px - b.px;
50
+ return `${Math.round(res * 100) / 100}px`;
51
+ });
52
+ }
53
+ function normalizeLengthString(raw) {
54
+ const trimmed = raw.trim();
55
+ const parsed = parseCssLengthToPx(trimmed);
56
+ if (!parsed)
57
+ return trimmed;
58
+ const px = Math.round(parsed.px * 100) / 100;
59
+ return `${px}px`;
60
+ }
61
+ export function normalizePaddingValues(raw, maps) {
62
+ const resolved = resolveCssValue(raw, maps);
63
+ const parts = resolved.split(/\s+/).filter(Boolean);
64
+ if (parts.length === 1) {
65
+ const v = normalizeLengthString(parts[0]);
66
+ return { paddingX: v, paddingY: v };
67
+ }
68
+ if (parts.length === 2) {
69
+ return {
70
+ paddingY: normalizeLengthString(parts[0]),
71
+ paddingX: normalizeLengthString(parts[1]),
72
+ };
73
+ }
74
+ if (parts.length === 3) {
75
+ return {
76
+ paddingY: `${normalizeLengthString(parts[0])}/${normalizeLengthString(parts[2])}`,
77
+ paddingX: normalizeLengthString(parts[1]),
78
+ };
79
+ }
80
+ if (parts.length >= 4) {
81
+ const top = normalizeLengthString(parts[0]);
82
+ const right = normalizeLengthString(parts[1]);
83
+ const bottom = normalizeLengthString(parts[2]);
84
+ const left = normalizeLengthString(parts[3]);
85
+ return {
86
+ paddingY: top === bottom ? top : `${top}/${bottom}`,
87
+ paddingX: right === left ? right : `${left}/${right}`,
88
+ };
89
+ }
90
+ return {};
91
+ }
92
+ export function extractStyleVectorFromCssRule(rule, maps) {
93
+ const vec = {};
94
+ let padTop;
95
+ let padBottom;
96
+ let padLeft;
97
+ let padRight;
98
+ for (const decl of rule.declarations) {
99
+ const val = resolveCssValue(decl.value, maps);
100
+ switch (decl.prop) {
101
+ case "height":
102
+ vec.height = normalizeLengthString(val);
103
+ break;
104
+ case "min-height":
105
+ vec.minHeight = normalizeLengthString(val);
106
+ break;
107
+ case "gap":
108
+ vec.gap = normalizeLengthString(val);
109
+ break;
110
+ case "padding": {
111
+ const { paddingX, paddingY } = normalizePaddingValues(decl.value, maps);
112
+ if (paddingX)
113
+ vec.paddingX = paddingX;
114
+ if (paddingY)
115
+ vec.paddingY = paddingY;
116
+ break;
117
+ }
118
+ case "padding-inline":
119
+ vec.paddingX = normalizeLengthString(val);
120
+ break;
121
+ case "padding-block":
122
+ vec.paddingY = normalizeLengthString(val);
123
+ break;
124
+ case "padding-left":
125
+ padLeft = normalizeLengthString(val);
126
+ break;
127
+ case "padding-right":
128
+ padRight = normalizeLengthString(val);
129
+ break;
130
+ case "padding-top":
131
+ padTop = normalizeLengthString(val);
132
+ break;
133
+ case "padding-bottom":
134
+ padBottom = normalizeLengthString(val);
135
+ break;
136
+ case "font-family":
137
+ vec.fontFamily = val.replace(/\s+/g, " ");
138
+ break;
139
+ case "font-size":
140
+ vec.fontSize = normalizeLengthString(val);
141
+ break;
142
+ case "font-weight":
143
+ vec.fontWeight = normalizeFontWeight(val);
144
+ break;
145
+ case "line-height":
146
+ vec.lineHeight = val.endsWith("px") || val.endsWith("rem") ? normalizeLengthString(val) : val;
147
+ break;
148
+ case "letter-spacing":
149
+ vec.letterSpacing = normalizeLengthString(val);
150
+ break;
151
+ case "text-transform":
152
+ vec.textTransform = val.toLowerCase();
153
+ break;
154
+ case "border-radius":
155
+ vec.borderRadius = normalizeLengthString(val);
156
+ break;
157
+ case "border-width":
158
+ vec.borderWidth = normalizeLengthString(val);
159
+ break;
160
+ case "border-color":
161
+ vec.borderColor = decl.value.trim();
162
+ break;
163
+ case "border": {
164
+ if (val === "none" || val === "0") {
165
+ vec.borderWidth = "0px";
166
+ }
167
+ else {
168
+ const m = /^(0|\d*\.?\d+(?:px|rem))\s+\S+(?:\s+(.+))?$/.exec(val);
169
+ if (m) {
170
+ vec.borderWidth = normalizeLengthString(m[1]);
171
+ if (m[2])
172
+ vec.borderColor = m[2].trim();
173
+ }
174
+ }
175
+ break;
176
+ }
177
+ case "background":
178
+ case "background-color":
179
+ if (!val.includes("gradient(")) {
180
+ vec.background = decl.value.trim();
181
+ }
182
+ break;
183
+ case "color":
184
+ vec.textColor = decl.value.trim();
185
+ break;
186
+ }
187
+ }
188
+ if (padLeft || padRight) {
189
+ vec.paddingX = padLeft && padRight && padLeft !== padRight ? `${padLeft}/${padRight}` : (padLeft ?? padRight);
190
+ }
191
+ if (padTop || padBottom) {
192
+ vec.paddingY = padTop && padBottom && padTop !== padBottom ? `${padTop}/${padBottom}` : (padTop ?? padBottom);
193
+ }
194
+ return vec;
195
+ }
196
+ const TW_FONT_SIZES = {
197
+ "2xs": "10px",
198
+ xs: "12px",
199
+ sm: "14px",
200
+ base: "16px",
201
+ lg: "18px",
202
+ xl: "20px",
203
+ "2xl": "24px",
204
+ "3xl": "30px",
205
+ };
206
+ const TW_FONT_WEIGHTS = {
207
+ thin: "100",
208
+ extralight: "200",
209
+ light: "300",
210
+ normal: "400",
211
+ medium: "500",
212
+ semibold: "600",
213
+ bold: "700",
214
+ extrabold: "800",
215
+ black: "900",
216
+ };
217
+ const TW_RADIUS = {
218
+ "rounded-none": "0px",
219
+ "rounded-xs": "2px",
220
+ "rounded-sm": "2px",
221
+ rounded: "4px",
222
+ "rounded-md": "6px",
223
+ "rounded-lg": "8px",
224
+ "rounded-xl": "12px",
225
+ "rounded-full": "9999px",
226
+ };
227
+ const TW_TRACKING = {
228
+ tighter: "-0.05em",
229
+ tight: "-0.025em",
230
+ normal: "0em",
231
+ wide: "0.025em",
232
+ wider: "0.05em",
233
+ widest: "0.1em",
234
+ };
235
+ const TW_LEADING = {
236
+ none: "1",
237
+ tight: "1.25",
238
+ snug: "1.375",
239
+ normal: "1.5",
240
+ relaxed: "1.625",
241
+ loose: "2",
242
+ };
243
+ export function normalizeFontWeight(raw) {
244
+ const lower = raw.trim().toLowerCase();
245
+ return TW_FONT_WEIGHTS[lower] ?? lower;
246
+ }
247
+ function twStepToPx(step) {
248
+ const n = Number(step);
249
+ if (!Number.isFinite(n))
250
+ return null;
251
+ return `${Math.round(n * 4 * 100) / 100}px`;
252
+ }
253
+ export function extractStyleVectorFromClassesAndInline(classes, inlineStyle, maps) {
254
+ const vec = {};
255
+ for (const rawCls of classes) {
256
+ // Only base (non-hover/state) utilities define resting geometry & typography
257
+ if (rawCls.includes(":") && !rawCls.startsWith("["))
258
+ continue;
259
+ const cls = rawCls;
260
+ const bracketMatch = /^([a-z-]+)-\[([^\]]+)\]$/.exec(cls);
261
+ if (bracketMatch) {
262
+ const prefix = bracketMatch[1];
263
+ const payload = resolveCssValue(bracketMatch[2].replace(/_/g, " "), maps);
264
+ if (prefix === "h")
265
+ vec.height = normalizeLengthString(payload);
266
+ else if (prefix === "min-h")
267
+ vec.minHeight = normalizeLengthString(payload);
268
+ else if (prefix === "px")
269
+ vec.paddingX = normalizeLengthString(payload);
270
+ else if (prefix === "py")
271
+ vec.paddingY = normalizeLengthString(payload);
272
+ else if (prefix === "p") {
273
+ vec.paddingX = normalizeLengthString(payload);
274
+ vec.paddingY = normalizeLengthString(payload);
275
+ }
276
+ else if (prefix === "gap")
277
+ vec.gap = normalizeLengthString(payload);
278
+ else if (prefix === "text") {
279
+ if (/px|rem|em|clamp/.test(payload))
280
+ vec.fontSize = normalizeLengthString(payload);
281
+ else
282
+ vec.textColor = payload;
283
+ }
284
+ else if (prefix === "leading")
285
+ vec.lineHeight = payload;
286
+ else if (prefix === "tracking")
287
+ vec.letterSpacing = payload;
288
+ else if (prefix === "rounded")
289
+ vec.borderRadius = normalizeLengthString(payload);
290
+ else if (prefix === "bg")
291
+ vec.background = payload;
292
+ else if (prefix === "font")
293
+ vec.fontWeight = normalizeFontWeight(payload);
294
+ continue;
295
+ }
296
+ if (cls.startsWith("h-")) {
297
+ const px = twStepToPx(cls.slice(2));
298
+ if (px)
299
+ vec.height = px;
300
+ }
301
+ else if (cls.startsWith("min-h-")) {
302
+ const px = twStepToPx(cls.slice(6));
303
+ if (px)
304
+ vec.minHeight = px;
305
+ }
306
+ else if (cls.startsWith("px-")) {
307
+ const px = twStepToPx(cls.slice(3));
308
+ if (px)
309
+ vec.paddingX = px;
310
+ }
311
+ else if (cls.startsWith("py-")) {
312
+ const px = twStepToPx(cls.slice(3));
313
+ if (px)
314
+ vec.paddingY = px;
315
+ }
316
+ else if (cls.startsWith("p-")) {
317
+ const px = twStepToPx(cls.slice(2));
318
+ if (px) {
319
+ vec.paddingX = px;
320
+ vec.paddingY = px;
321
+ }
322
+ }
323
+ else if (cls.startsWith("gap-")) {
324
+ const px = twStepToPx(cls.slice(4));
325
+ if (px)
326
+ vec.gap = px;
327
+ }
328
+ else if (cls.startsWith("font-")) {
329
+ const slug = cls.slice(5);
330
+ if (TW_FONT_WEIGHTS[slug]) {
331
+ vec.fontWeight = TW_FONT_WEIGHTS[slug];
332
+ }
333
+ else if (maps.bridge.has(`--font-${slug}`)) {
334
+ vec.fontFamily = resolveCssValue(maps.bridge.get(`--font-${slug}`).value, maps);
335
+ }
336
+ else {
337
+ vec.fontFamily = slug;
338
+ }
339
+ }
340
+ else if (cls.startsWith("text-")) {
341
+ const slug = cls.slice(5);
342
+ const bridgeText = maps.bridge.get(`--text-${slug}`);
343
+ if (bridgeText) {
344
+ vec.fontSize = normalizeLengthString(resolveCssValue(bridgeText.value, maps));
345
+ }
346
+ else if (TW_FONT_SIZES[slug]) {
347
+ vec.fontSize = TW_FONT_SIZES[slug];
348
+ }
349
+ else if (!/^(?:left|center|right|justify|start|end|wrap|nowrap|ellipsis|clip)$/.test(slug)) {
350
+ vec.textColor = `var(--color-${slug})`;
351
+ }
352
+ }
353
+ else if (cls.startsWith("leading-")) {
354
+ const slug = cls.slice(8);
355
+ if (TW_LEADING[slug])
356
+ vec.lineHeight = TW_LEADING[slug];
357
+ else if (maps.bridge.has(`--leading-${slug}`)) {
358
+ vec.lineHeight = resolveCssValue(maps.bridge.get(`--leading-${slug}`).value, maps);
359
+ }
360
+ else if (/^\d+(?:\.\d+)?$/.test(slug)) {
361
+ vec.lineHeight = twStepToPx(slug) ?? slug;
362
+ }
363
+ }
364
+ else if (cls.startsWith("tracking-")) {
365
+ const slug = cls.slice(9);
366
+ vec.letterSpacing = TW_TRACKING[slug] ?? (maps.bridge.has(`--tracking-${slug}`)
367
+ ? resolveCssValue(maps.bridge.get(`--tracking-${slug}`).value, maps)
368
+ : slug);
369
+ }
370
+ else if (cls === "uppercase" || cls === "lowercase" || cls === "capitalize" || cls === "normal-case") {
371
+ vec.textTransform = cls === "normal-case" ? "none" : cls;
372
+ }
373
+ else if (TW_RADIUS[cls]) {
374
+ vec.borderRadius = TW_RADIUS[cls];
375
+ }
376
+ else if (cls === "border") {
377
+ vec.borderWidth = "1px";
378
+ }
379
+ else if (cls === "border-0") {
380
+ vec.borderWidth = "0px";
381
+ }
382
+ else if (cls === "border-2") {
383
+ vec.borderWidth = "2px";
384
+ }
385
+ else if (cls.startsWith("border-") && !/^(?:t|r|b|l|x|y|s|e|collapse|separate|solid|dashed|dotted|double|none)/.test(cls.slice(7))) {
386
+ vec.borderColor = `var(--color-${cls.slice(7)})`;
387
+ }
388
+ else if (cls.startsWith("bg-") && !/^(?:clip-|origin-|gradient-|linear-|radial-|none|auto|cover|contain|center|transparent)/.test(cls.slice(3))) {
389
+ vec.background = `var(--color-${cls.slice(3)})`;
390
+ }
391
+ }
392
+ // Inline styles override class defaults
393
+ if (inlineStyle.height)
394
+ vec.height = normalizeLengthString(inlineStyle.height);
395
+ if (inlineStyle.minHeight)
396
+ vec.minHeight = normalizeLengthString(inlineStyle.minHeight);
397
+ if (inlineStyle.gap)
398
+ vec.gap = normalizeLengthString(inlineStyle.gap);
399
+ if (inlineStyle.fontFamily)
400
+ vec.fontFamily = inlineStyle.fontFamily;
401
+ if (inlineStyle.fontSize)
402
+ vec.fontSize = normalizeLengthString(inlineStyle.fontSize);
403
+ if (inlineStyle.fontWeight)
404
+ vec.fontWeight = normalizeFontWeight(inlineStyle.fontWeight);
405
+ if (inlineStyle.lineHeight)
406
+ vec.lineHeight = inlineStyle.lineHeight;
407
+ if (inlineStyle.letterSpacing)
408
+ vec.letterSpacing = inlineStyle.letterSpacing;
409
+ if (inlineStyle.textTransform)
410
+ vec.textTransform = inlineStyle.textTransform;
411
+ if (inlineStyle.borderRadius)
412
+ vec.borderRadius = normalizeLengthString(inlineStyle.borderRadius);
413
+ if (inlineStyle.backgroundColor ?? inlineStyle.background) {
414
+ vec.background = inlineStyle.backgroundColor ?? inlineStyle.background;
415
+ }
416
+ if (inlineStyle.color)
417
+ vec.textColor = inlineStyle.color;
418
+ return vec;
419
+ }
420
+ export function resolveComponentStyleVector(snapshots, cssRulesByClass, maps) {
421
+ if (snapshots.length === 0)
422
+ return undefined;
423
+ // Prefer primary control element (button/input/select/root) snapshot
424
+ const preferred = snapshots.find((s) => s.tag === "button" || s.tag === "input" || s.tag === "select" || s.role === "button") ??
425
+ snapshots[0];
426
+ const merged = {};
427
+ for (const cls of preferred.classes) {
428
+ for (const rule of cssRulesByClass.get(cls) ?? []) {
429
+ Object.assign(merged, extractStyleVectorFromCssRule(rule, maps));
430
+ }
431
+ }
432
+ Object.assign(merged, extractStyleVectorFromClassesAndInline(preferred.classes, preferred.inlineStyle, maps));
433
+ return Object.keys(merged).length >= 2 ? merged : undefined;
434
+ }
435
+ const STYLE_VECTOR_KEYS = [
436
+ "height",
437
+ "minHeight",
438
+ "paddingX",
439
+ "paddingY",
440
+ "gap",
441
+ "fontFamily",
442
+ "fontSize",
443
+ "fontWeight",
444
+ "lineHeight",
445
+ "letterSpacing",
446
+ "textTransform",
447
+ "borderRadius",
448
+ "borderWidth",
449
+ "borderColor",
450
+ "background",
451
+ "textColor",
452
+ ];
453
+ function normalizeDeltaVal(prop, v) {
454
+ const s = v.trim().toLowerCase();
455
+ if (/^(?:height|minHeight|paddingX|paddingY|gap|fontSize|borderRadius|borderWidth)$/.test(prop)) {
456
+ return normalizeLengthString(s);
457
+ }
458
+ return s.replace(/\s+/g, " ");
459
+ }
460
+ export function computeStyleVectorDeltas(left, right) {
461
+ if (!left || !right)
462
+ return [];
463
+ const deltas = [];
464
+ for (const prop of STYLE_VECTOR_KEYS) {
465
+ const lv = left[prop];
466
+ const rv = right[prop];
467
+ if (lv === undefined && rv === undefined)
468
+ continue;
469
+ const normL = lv !== undefined ? normalizeDeltaVal(prop, lv) : "(unset)";
470
+ const normR = rv !== undefined ? normalizeDeltaVal(prop, rv) : "(unset)";
471
+ if (normL !== normR) {
472
+ // Only report unset-vs-set for core geometry/border dimensions where divergence matters
473
+ if ((lv === undefined || rv === undefined) && !/^(?:height|minHeight|paddingX|paddingY|borderRadius|borderWidth|fontSize|fontWeight)$/.test(prop)) {
474
+ continue;
475
+ }
476
+ deltas.push({
477
+ property: prop,
478
+ leftValue: lv ?? "(unset)",
479
+ rightValue: rv ?? "(unset)",
480
+ });
481
+ }
482
+ }
483
+ return deltas;
484
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * packages/mcp/src/designSystem/tokens.ts
3
+ *
4
+ * Derives token tiers (primitive → semantic → component) from the *reference graph* of the
5
+ * repo's own CSS custom properties instead of from naming conventions:
6
+ *
7
+ * - a literal (non-aliased) token → primitive (or semantic when it is re-declared per theme)
8
+ * - an alias of primitives only → semantic
9
+ * - an alias involving a semantic/component token, or a token declared in a scoped
10
+ * selector (`.card { --card-bg }`) → component
11
+ *
12
+ * Explicit `designSystem.tokens.tiers` regexes always win. `@theme` bridge tokens stay
13
+ * "semantic" (they are the Tailwind v4 theme surface).
14
+ */
15
+ import { type DesignSystemConfig } from "./config.js";
16
+ import type { CssTokenDeclaration, ThemeSymmetryFinding, TokenTier, UnbackedSemanticTokenDiagnostic } from "./types.js";
17
+ export type TokenTierSource = "config" | "derived" | "scoped" | "theme-bridge";
18
+ export interface DerivedTier {
19
+ tier: TokenTier;
20
+ source: TokenTierSource;
21
+ }
22
+ export declare function isScaleStepTokenName(name: string): boolean;
23
+ export declare function deriveTokenTiers(decls: CssTokenDeclaration[], tiers: DesignSystemConfig["tokens"]["tiers"]): Map<string, DerivedTier>;
24
+ export interface TokenLineageSummary {
25
+ lineageRoleByName: Map<string, "scale-primitive" | "semantic-role" | "component-slot" | "framework-bridge">;
26
+ backingByName: Map<string, "backed" | "unbacked-literal" | "primitive-scale">;
27
+ unbackedSemanticTokens: UnbackedSemanticTokenDiagnostic[];
28
+ themeSymmetryIssues: ThemeSymmetryFinding[];
29
+ }
30
+ export declare function analyzeTokenLineageAndSymmetry(decls: CssTokenDeclaration[], tiersByName: Map<string, DerivedTier>): TokenLineageSummary;
31
+ /**
32
+ * Computes the transitive closure of tokens reachable from actual consumer roots
33
+ * (CSS style rules, active Tailwind utilities, TS/JSX/canvas references) without
34
+ * seeding from `:root` / `[data-theme]` / `@theme` token declarations themselves.
35
+ */
36
+ export declare function computeLiveReferencedTokens(consumerRootNames: Iterable<string>, allTokenDecls: CssTokenDeclaration[]): {
37
+ liveTokens: Set<string>;
38
+ directlyReferencedTokens: Set<string>;
39
+ };