figma-console-mcp 1.40.6 → 1.40.8

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.
@@ -355,6 +355,16 @@ export function visibilityNote(node) {
355
355
  return prop ? `hidden — shown when ${prop} = true` : "hidden";
356
356
  return prop ? `toggled by ${prop}` : "";
357
357
  }
358
+ /** The component an instance is made from — its component SET's name for a variant */
359
+ export function componentNameOf(instance, lookup = {}) {
360
+ const comp = lookup.components?.[instance?.componentId];
361
+ if (comp?.componentSetId) {
362
+ const setName = lookup.componentSets?.[comp.componentSetId]?.name;
363
+ if (setName)
364
+ return setName;
365
+ }
366
+ return comp?.name ?? instance?.name ?? "instance";
367
+ }
358
368
  /** "Tab Item (Is Selected=True)" — an instance, qualified by its variant */
359
369
  export function describeInstance(node) {
360
370
  const variantProps = Object.entries(node?.componentProperties ?? {})
@@ -549,7 +559,9 @@ ancestorHidden = false,
549
559
  /** Property that shows the nearest hidden ancestor, when one does */
550
560
  ancestorShownWhen = null,
551
561
  /** Nearest nested instance ("Tab Item (Is Selected=True)") */
552
- owner = null) {
562
+ owner = null,
563
+ /** Component that nearest nested instance is made from ("Tab Item") */
564
+ ownerComponent = null) {
553
565
  if (depth > maxDepth)
554
566
  return;
555
567
  const isText = node.type === "TEXT";
@@ -558,7 +570,15 @@ owner = null) {
558
570
  // and, when a boolean property reveals them, with the property that does.
559
571
  const hiddenHere = node.visible === false;
560
572
  const hidden = ancestorHidden || hiddenHere;
561
- const shownWhen = hiddenHere ? visibilityProperty(node) : ancestorShownWhen;
573
+ // A layer inside a nested instance is controlled by THAT component's property,
574
+ // not this one's: "Avatar's notification", never a bare "notification" that
575
+ // reads as if the documented component had it.
576
+ const ownProp = hiddenHere ? visibilityProperty(node) : null;
577
+ // Named by the COMPONENT, not the instance: every tab's "Is Focused" is the Tab
578
+ // Item's property, so "Tab 1" and "Tab 2" must not split it into two facts.
579
+ const shownWhen = ownProp
580
+ ? (ownerComponent ? `${ownerComponent}'s ${ownProp}` : ownProp)
581
+ : hiddenHere ? null : ancestorShownWhen;
562
582
  // Icons are reported once, at the outermost instance — everything beneath it
563
583
  // (vectors, nested instances) is that icon's artwork, not a separate icon.
564
584
  if (insideIcon === null) {
@@ -572,8 +592,10 @@ owner = null) {
572
592
  const varId = paint.boundVariables?.color?.id;
573
593
  return {
574
594
  hex: value,
575
- // The variant root's own name is "Size=lg, State=hover" — not a layer name
576
- nodeName: depth === 0 ? "" : node.name || "",
595
+ // The variant root's own name is "Size=lg, State=hover" — not a layer name.
596
+ // A paint on a nested INSTANCE (a tab's underline) names the instance with its
597
+ // variant, so the selected tab's stroke reads as the selected tab's.
598
+ nodeName: depth === 0 ? "" : node.type === "INSTANCE" ? describeInstance(node) : node.name || "",
577
599
  variableId: varId,
578
600
  variableName: varId ? ctx.varNameMap.get(varId) : undefined,
579
601
  ...(hidden ? { hidden: true } : {}),
@@ -639,7 +661,8 @@ owner = null) {
639
661
  // Recurse into children
640
662
  if (node.children && Array.isArray(node.children)) {
641
663
  for (const child of node.children) {
642
- walkVariantNode(child, data, ctx, depth + 1, maxDepth, insideIcon, hidden, shownWhen, node.type === "INSTANCE" && depth > 0 ? describeInstance(node) : owner);
664
+ const isNestedInstance = node.type === "INSTANCE" && depth > 0;
665
+ walkVariantNode(child, data, ctx, depth + 1, maxDepth, insideIcon, hidden, shownWhen, isNestedInstance ? describeInstance(node) : owner, isNestedInstance ? componentNameOf(node, ctx.lookup) : ownerComponent);
643
666
  }
644
667
  }
645
668
  }
@@ -943,6 +966,10 @@ function collectSpacingTokens(node, varNameMap = new Map()) {
943
966
  { key: "counterAxisSpacing", label: "Row gap (wrap)" },
944
967
  { key: "cornerRadius", label: "Border radius" },
945
968
  { key: "strokeWeight", label: "Border width" },
969
+ { key: "minWidth", label: "Min width" },
970
+ { key: "maxWidth", label: "Max width" },
971
+ { key: "minHeight", label: "Min height" },
972
+ { key: "maxHeight", label: "Max height" },
946
973
  ];
947
974
  for (const { key, label } of spacingProps) {
948
975
  let value = node[key];
@@ -1047,6 +1074,10 @@ const SPACING_COMPARISON_PROPS = [
1047
1074
  { key: "counterAxisSpacing", label: "Row gap (wrap)" },
1048
1075
  { key: "cornerRadius", label: "Border radius" },
1049
1076
  { key: "strokeWeight", label: "Border width" },
1077
+ { key: "minWidth", label: "Min width" },
1078
+ { key: "maxWidth", label: "Max width" },
1079
+ { key: "minHeight", label: "Min height" },
1080
+ { key: "maxHeight", label: "Max height" },
1050
1081
  ];
1051
1082
  /** Cap on variant names spelled out in a single note, so 100-variant sets stay readable */
1052
1083
  const MAX_NAMED_VARIANTS = 5;
@@ -1380,7 +1411,7 @@ function compareVisual(node, codeSpec, discrepancies) {
1380
1411
  }
1381
1412
  }
1382
1413
  }
1383
- function compareSpacing(node, codeSpec, discrepancies) {
1414
+ export function compareSpacing(node, codeSpec, discrepancies) {
1384
1415
  const cs = codeSpec.spacing;
1385
1416
  if (!cs)
1386
1417
  return;
@@ -1436,6 +1467,65 @@ function compareSpacing(node, codeSpec, discrepancies) {
1436
1467
  });
1437
1468
  }
1438
1469
  }
1470
+ // Min/max size constraints. The code spec accepted these but they were never
1471
+ // compared, so a component whose Figma frame had a 320px min-width passed
1472
+ // parity against code with none.
1473
+ for (const key of ["minWidth", "maxWidth", "minHeight", "maxHeight"]) {
1474
+ const dVal = typeof node?.[key] === "number" ? node[key] : undefined;
1475
+ const raw = cs[key];
1476
+ const parsed = typeof raw === "string" ? parseFloat(raw) : raw;
1477
+ // Only px can be compared; a non-px length ("20rem") is reported as-is.
1478
+ const cVal = typeof parsed === "number" && !isNaN(parsed)
1479
+ && !(typeof raw === "string" && /[a-z%]/i.test(raw.replace(/px\s*$/i, "")))
1480
+ ? parsed : undefined;
1481
+ const cUnparsed = raw !== undefined && cVal === undefined ? String(raw) : undefined;
1482
+ const css = key.replace(/[A-Z]/, (c) => `-${c.toLowerCase()}`);
1483
+ if (dVal !== undefined && cUnparsed !== undefined) {
1484
+ discrepancies.push({
1485
+ category: "spacing",
1486
+ property: key,
1487
+ severity: "info",
1488
+ designValue: dVal,
1489
+ codeValue: cUnparsed,
1490
+ message: `${css} is ${dVal}px in Figma and ${cUnparsed} in code; not compared (non-px unit)`,
1491
+ });
1492
+ }
1493
+ else if (dVal !== undefined && cVal !== undefined) {
1494
+ if (!numericClose(dVal, cVal, 1)) {
1495
+ discrepancies.push({
1496
+ category: "spacing",
1497
+ property: key,
1498
+ // Same weight as a padding mismatch: a wrong min/max breaks layout.
1499
+ severity: "major",
1500
+ designValue: dVal,
1501
+ codeValue: cVal,
1502
+ message: `${css} mismatch: design=${dVal}px, code=${cVal}px`,
1503
+ suggestion: `Set ${css}: ${dVal}px`,
1504
+ });
1505
+ }
1506
+ }
1507
+ else if (dVal !== undefined) {
1508
+ discrepancies.push({
1509
+ category: "spacing",
1510
+ property: key,
1511
+ severity: "minor",
1512
+ designValue: dVal,
1513
+ codeValue: null,
1514
+ message: `${css} is ${dVal}px in Figma but not set in code`,
1515
+ suggestion: `Add ${css}: ${dVal}px`,
1516
+ });
1517
+ }
1518
+ else if (cVal !== undefined || cUnparsed !== undefined) {
1519
+ discrepancies.push({
1520
+ category: "spacing",
1521
+ property: key,
1522
+ severity: "info",
1523
+ designValue: null,
1524
+ codeValue: cVal ?? cUnparsed ?? null,
1525
+ message: `${css} is ${cVal !== undefined ? `${cVal}px` : cUnparsed} in code but not set in Figma`,
1526
+ });
1527
+ }
1528
+ }
1439
1529
  }
1440
1530
  function compareTypography(node, codeSpec, discrepancies) {
1441
1531
  const ct = codeSpec.typography;
@@ -2526,61 +2616,94 @@ setNode) {
2526
2616
  lines.push("");
2527
2617
  lines.push("| Element | Figma Variable | Value |");
2528
2618
  lines.push("|---------|---------------|-------|");
2529
- for (const vd of variantData) {
2530
- // Same naming as the Variant Matrix: every property value, whatever the
2531
- // properties are called ("Variant=Secondary, Appearance=Critical" → "Secondary / Critical").
2532
- const displayName = cleanVariantName(vd.variantName);
2533
- // Section header for this variant
2534
- lines.push(`| **${displayName}** | | |`);
2535
- const tokenCell = (c) => {
2536
- const varName = c.variableName || (c.variableId ? varNameMap.get(c.variableId) : undefined);
2537
- return varName ? `\`${varName}\`` : "—";
2538
- };
2539
- // Multi-path icons and repeated shapes would otherwise emit identical rows
2540
- const emitted = new Set();
2541
- // Text layers are often auto-named after their content ("Lorem ipsum dolor…")
2542
- const short = (name) => (name.length > 40 ? `${name.slice(0, 40)}…` : name);
2543
- const pushRow = (label, c) => {
2544
- const visibility = !c.hidden ? "" : c.shownWhen ? ` _(hidden — shown when ${c.shownWhen} = true)_` : " _(hidden layer)_";
2545
- const row = `| ${label}${visibility} | ${tokenCell(c)} | ${c.hex} |`;
2546
- if (emitted.has(row))
2619
+ const tokenCell = (c) => {
2620
+ const varName = c.variableName || (c.variableId ? varNameMap.get(c.variableId) : undefined);
2621
+ return varName ? `\`${varName}\`` : "—";
2622
+ };
2623
+ // Text layers are often auto-named after their content ("Lorem ipsum dolor…")
2624
+ const short = (name) => (name.length > 40 ? `${name.slice(0, 40)}…` : name);
2625
+ const rowText = (r, withVisibility) => {
2626
+ const visibility = !withVisibility ? ""
2627
+ : r.shownWhen ? ` _(hidden — shown when ${r.shownWhen} = true)_`
2628
+ : r.plainHidden ? " _(hidden layer)_" : "";
2629
+ return `| ${r.label}${visibility} | ${r.token} | ${r.value} |`;
2630
+ };
2631
+ // Pass 1 — each variant's rows
2632
+ const perVariant = variantData.map((vd) => {
2633
+ const rows = [];
2634
+ const seen = new Set(); // multi-path icons / repeated shapes → one row
2635
+ const add = (label, c) => {
2636
+ const r = { label, token: tokenCell(c), value: c.hex, ...(c.hidden && c.shownWhen ? { shownWhen: c.shownWhen } : {}), ...(c.hidden && !c.shownWhen ? { plainHidden: true } : {}) };
2637
+ const key = rowText(r, true);
2638
+ if (seen.has(key))
2547
2639
  return;
2548
- emitted.add(row);
2549
- lines.push(row);
2640
+ seen.add(key);
2641
+ rows.push(r);
2642
+ };
2643
+ // Same-named layers with DIFFERENT colors (a selected and an unselected tab's
2644
+ // Label) are told apart by the nested instance they live in
2645
+ const qualify = (list) => {
2646
+ const byName = new Map();
2647
+ for (const e of list) {
2648
+ if (!byName.has(e.nodeName))
2649
+ byName.set(e.nodeName, new Set());
2650
+ byName.get(e.nodeName).add(`${e.hex}|${e.variableName ?? ""}`);
2651
+ }
2652
+ return (e) => ((byName.get(e.nodeName)?.size ?? 0) > 1 && e.owner ? ` in ${e.owner}` : "");
2550
2653
  };
2551
2654
  // Background — the variant's own surface only. Say so when there isn't one.
2552
2655
  const bgLabel = vd.backgroundLayer ? `Background (${vd.backgroundLayer})` : "Background";
2553
- if (vd.fills.length === 0) {
2554
- lines.push("| Background | — | none (transparent) |");
2555
- }
2656
+ if (vd.fills.length === 0)
2657
+ rows.push({ label: "Background", token: "—", value: "none (transparent)" });
2556
2658
  for (const fill of vd.fills)
2557
- pushRow(bgLabel, fill);
2659
+ add(bgLabel, fill);
2558
2660
  // Fills on inner layers — reported under the layer's name, never as a background
2661
+ const fillQ = qualify(vd.descendantFills);
2559
2662
  for (const fill of vd.descendantFills)
2560
- pushRow(`Fill (${fill.nodeName})`, fill);
2561
- // Icon artwork colors
2663
+ add(`Fill (${fill.nodeName}${fillQ(fill)})`, fill);
2562
2664
  for (const c of vd.iconColors)
2563
- pushRow(c.iconLabel ? `Icon (${c.iconLabel})` : "Icon", c);
2564
- // Text colors
2565
- // Same-named text layers with DIFFERENT colors (a selected and an unselected
2566
- // tab's Label) are told apart by the nested instance they live in
2567
- const colorsByName = new Map();
2568
- for (const t of vd.textColors) {
2569
- if (!colorsByName.has(t.nodeName))
2570
- colorsByName.set(t.nodeName, new Set());
2571
- colorsByName.get(t.nodeName).add(`${t.hex}|${t.variableName ?? ""}`);
2572
- }
2573
- for (const text of vd.textColors) {
2574
- const ambiguous = (colorsByName.get(text.nodeName)?.size ?? 0) > 1 && text.owner;
2575
- pushRow(`Text (${short(text.nodeName)}${ambiguous ? ` in ${text.owner}` : ""})`, text);
2576
- }
2577
- // Strokes — through the same writer, so a visible underline and a hidden
2578
- // focus ring sharing one color don't print as two indistinguishable rows
2665
+ add(c.iconLabel ? `Icon (${c.iconLabel})` : "Icon", c);
2666
+ const textQ = qualify(vd.textColors);
2667
+ for (const text of vd.textColors)
2668
+ add(`Text (${short(text.nodeName)}${textQ(text)})`, text);
2669
+ // Strokes go through the same writer, so a visible underline and a hidden focus
2670
+ // ring sharing one color don't print as two indistinguishable rows
2671
+ const strokeQ = qualify(vd.strokes);
2579
2672
  for (const stroke of vd.strokes)
2580
- pushRow(stroke.nodeName ? `Stroke (${stroke.nodeName})` : "Stroke", stroke);
2673
+ add(stroke.nodeName ? `Stroke (${stroke.nodeName}${strokeQ(stroke)})` : "Stroke", stroke);
2581
2674
  // Shadows, blurs, opacity — dropping them would imply the component is flat
2582
2675
  for (const fx of vd.effects)
2583
- pushRow(fx.nodeName ? `Effect (${fx.nodeName})` : "Effect", fx);
2676
+ add(fx.nodeName ? `Effect (${fx.nodeName})` : "Effect", fx);
2677
+ return { name: cleanVariantName(vd.variantName), rows };
2678
+ });
2679
+ // Pass 2 — a layer a boolean property reveals, identical in EVERY variant, is a
2680
+ // fact about the property, not about each variant: print it once, under the
2681
+ // property. If it differs between variants, it stays with each variant.
2682
+ const hoisted = new Map();
2683
+ const hoistedKeys = new Set();
2684
+ if (perVariant.length > 1) {
2685
+ for (const r of perVariant[0].rows) {
2686
+ if (!r.shownWhen)
2687
+ continue;
2688
+ const key = rowText(r, true);
2689
+ if (!perVariant.every((pv) => pv.rows.some((x) => rowText(x, true) === key)))
2690
+ continue;
2691
+ hoistedKeys.add(key);
2692
+ if (!hoisted.has(r.shownWhen))
2693
+ hoisted.set(r.shownWhen, []);
2694
+ hoisted.get(r.shownWhen).push(r);
2695
+ }
2696
+ }
2697
+ for (const pv of perVariant) {
2698
+ lines.push(`| **${pv.name}** | | |`);
2699
+ for (const r of pv.rows)
2700
+ if (!hoistedKeys.has(rowText(r, true)))
2701
+ lines.push(rowText(r, true));
2702
+ }
2703
+ for (const [prop, rows] of hoisted) {
2704
+ lines.push(`| **When ${prop} = true** _(every variant; hidden otherwise)_ | | |`);
2705
+ for (const r of rows)
2706
+ lines.push(rowText(r, false));
2584
2707
  }
2585
2708
  lines.push("");
2586
2709
  }
@@ -3199,10 +3322,10 @@ const codeSpecSchema = z.object({
3199
3322
  gap: z.number().optional(),
3200
3323
  width: z.union([z.number(), z.string()]).optional(),
3201
3324
  height: z.union([z.number(), z.string()]).optional(),
3202
- minWidth: z.number().optional(),
3203
- minHeight: z.number().optional(),
3204
- maxWidth: z.number().optional(),
3205
- maxHeight: z.number().optional(),
3325
+ minWidth: z.union([z.number(), z.string()]).optional().describe("px number or CSS length like '320px'"),
3326
+ minHeight: z.union([z.number(), z.string()]).optional(),
3327
+ maxWidth: z.union([z.number(), z.string()]).optional(),
3328
+ maxHeight: z.union([z.number(), z.string()]).optional(),
3206
3329
  layoutDirection: z.enum(["horizontal", "vertical"]).optional(),
3207
3330
  }).optional().describe("Spacing and layout properties from code"),
3208
3331
  typography: z.object({