figme-mcp 1.1.2 → 1.2.0

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.
@@ -10,7 +10,9 @@
10
10
  * and recorded in the report.
11
11
  */
12
12
  import type { CacheEntry } from '../cache.js';
13
+ import type { NodeChange } from '../fig/parse.js';
13
14
  import { type TreeNode } from '../model/tree.js';
15
+ import { type OverrideRecords, type PropAssignments } from './instance.js';
14
16
  import { type Box } from './matrix.js';
15
17
  import { ReportBuilder } from './report.js';
16
18
  export declare const DEFAULT_MAX_NODES = 20000;
@@ -25,6 +27,11 @@ export declare const VISIT_FACTOR = 12;
25
27
  export declare const HARD_MAX_VISITS = 400000;
26
28
  /** A render whose SVG exceeds this is refused rather than handed to the rasterizer. */
27
29
  export declare const MAX_SVG_BYTES: number;
30
+ /**
31
+ * Per-corner radii in SVG order: top-left, top-right, bottom-right, bottom-left. With independent
32
+ * corners a corner the record does not write is square, not the uniform radius (F24).
33
+ */
34
+ export declare function cornerRadii(node: NodeChange): [number, number, number, number];
28
35
  /** A stop that must abort the whole render rather than being isolated to one node. */
29
36
  export declare class RenderBudgetError extends Error {
30
37
  }
@@ -35,11 +42,24 @@ export interface NodeBox {
35
42
  readonly name?: string;
36
43
  readonly box: Box;
37
44
  }
45
+ /**
46
+ * The instance a layer is drawn inside of, when the root is a layer of an instance rather than a
47
+ * stored node (model/scene.ts): the records and property values of the expansion it belongs to.
48
+ */
49
+ export interface ExportContext {
50
+ readonly records: OverrideRecords;
51
+ readonly props: PropAssignments;
52
+ /** Def-id scope, unique to the instance, so its ids never collide with the symbol's own. */
53
+ readonly scope: string;
54
+ /** Symbols already being expanded around the root, for the recursion guard. */
55
+ readonly active: Iterable<string>;
56
+ }
38
57
  export interface ExportOptions {
39
58
  readonly maxNodes?: number;
40
59
  readonly collectBoxes?: boolean;
41
60
  /** CSS colour painted behind everything; omitted for a transparent render. */
42
61
  readonly background?: string;
62
+ readonly context?: ExportContext;
43
63
  }
44
64
  export interface ExportResult {
45
65
  readonly svg: string;
@@ -35,17 +35,20 @@ const RECTANGULAR = new Set([
35
35
  'SECTION',
36
36
  'GROUP',
37
37
  ]);
38
- /** Per-corner radii in SVG order: top-left, top-right, bottom-right, bottom-left. */
39
- function cornerRadii(node) {
38
+ /**
39
+ * Per-corner radii in SVG order: top-left, top-right, bottom-right, bottom-left. With independent
40
+ * corners a corner the record does not write is square, not the uniform radius (F24).
41
+ */
42
+ export function cornerRadii(node) {
40
43
  const uniform = num(node, 'cornerRadius') ?? 0;
41
44
  if (bool(node, 'rectangleCornerRadiiIndependent') !== true) {
42
45
  return [uniform, uniform, uniform, uniform];
43
46
  }
44
47
  return [
45
- num(node, 'rectangleTopLeftCornerRadius') ?? uniform,
46
- num(node, 'rectangleTopRightCornerRadius') ?? uniform,
47
- num(node, 'rectangleBottomRightCornerRadius') ?? uniform,
48
- num(node, 'rectangleBottomLeftCornerRadius') ?? uniform,
48
+ num(node, 'rectangleTopLeftCornerRadius') ?? 0,
49
+ num(node, 'rectangleTopRightCornerRadius') ?? 0,
50
+ num(node, 'rectangleBottomRightCornerRadius') ?? 0,
51
+ num(node, 'rectangleBottomLeftCornerRadius') ?? 0,
49
52
  ];
50
53
  }
51
54
  /** A stop that must abort the whole render rather than being isolated to one node. */
@@ -83,6 +86,14 @@ class Exporter {
83
86
  this.maxVisits = Math.min(maxNodes * VISIT_FACTOR, HARD_MAX_VISITS);
84
87
  this.collectBoxes = opts.collectBoxes === true;
85
88
  this.background = opts.background;
89
+ if (opts.context) {
90
+ // A layer of an instance: start inside that instance, exactly as emitInstance would.
91
+ this.frame = opts.context.records;
92
+ this.props = opts.context.props;
93
+ this.defScope = opts.context.scope;
94
+ for (const symbol of opts.context.active)
95
+ this.activeSymbols.add(symbol);
96
+ }
86
97
  }
87
98
  blob(index) {
88
99
  if (index === undefined)
@@ -1,4 +1,5 @@
1
1
  import { canonicalGuid, guidNotFound } from '../model/tree.js';
2
+ import { isSublayerId, resolveScene } from '../model/scene.js';
2
3
  import { str } from '../model/access.js';
3
4
  import { pageBackground } from './color.js';
4
5
  import { DEFAULT_MAX_NODES, HARD_MAX_NODES, MAX_SVG_BYTES, exportSubtree, } from './export.js';
@@ -9,16 +10,33 @@ export const DEFAULT_MAX_SIZE = 1568;
9
10
  export const HARD_MAX_SIZE = 4096;
10
11
  function resolveRoot(entry, guid) {
11
12
  const key = canonicalGuid(guid);
13
+ if (isSublayerId(key)) {
14
+ // A layer inside an instance: draw its component layer inside that instance's expansion.
15
+ const scene = resolveScene(entry.index, key);
16
+ if (!scene)
17
+ throw new Error(guidNotFound(guid, key));
18
+ const level = scene.level;
19
+ return {
20
+ root: scene.source,
21
+ scene,
22
+ context: level && {
23
+ records: level.instance.records,
24
+ props: level.instance.props,
25
+ scope: `${[level.root, ...level.path].join('~')}~`,
26
+ active: level.active,
27
+ },
28
+ };
29
+ }
12
30
  const t = entry.index.node(key);
13
31
  if (!t)
14
32
  throw new Error(guidNotFound(guid, key));
15
33
  if (nodeType(t.node) === 'DOCUMENT') {
16
34
  throw new Error('cannot render the DOCUMENT node — render a page or a node inside one');
17
35
  }
18
- return t;
36
+ return { root: t };
19
37
  }
20
38
  export async function renderNode(entry, guid, opts = {}) {
21
- const root = resolveRoot(entry, guid);
39
+ const { root, scene, context } = resolveRoot(entry, guid);
22
40
  const maxNodes = Math.min(opts.maxNodes ?? DEFAULT_MAX_NODES, HARD_MAX_NODES);
23
41
  const range = entry.index.subtreeRange(root);
24
42
  const subtreeSize = range.end - range.start;
@@ -26,12 +44,14 @@ export async function renderNode(entry, guid, opts = {}) {
26
44
  throw new Error(`node ${guid} covers ${subtreeSize} nodes, above maxNodes (${maxNodes}); ` +
27
45
  'render a smaller node or raise maxNodes');
28
46
  }
29
- const background = opts.background === 'page' ? pageBackground(root) : undefined;
47
+ // A layer of an instance sits on the instance's page, not on its component's.
48
+ const background = opts.background === 'page' ? pageBackground(scene ?? root) : undefined;
30
49
  const startedExport = performance.now();
31
50
  const exported = exportSubtree(entry, root, {
32
51
  maxNodes,
33
52
  collectBoxes: opts.collectBoxes,
34
53
  background,
54
+ context,
35
55
  });
36
56
  const renderMs = performance.now() - startedExport;
37
57
  if (exported.svg.length > MAX_SVG_BYTES) {
@@ -67,8 +87,9 @@ export async function renderNode(entry, guid, opts = {}) {
67
87
  rasterizerMissing = true;
68
88
  }
69
89
  }
90
+ const shown = scene ?? root;
70
91
  const report = exported.report.finish({
71
- root: { guid: root.key, name: str(root.node, 'name'), type: nodeType(root.node) },
92
+ root: { guid: shown.key, name: str(shown.node, 'name'), type: nodeType(shown.node) },
72
93
  bounds,
73
94
  width,
74
95
  height,
@@ -2,25 +2,19 @@
2
2
  * Colour and effect styles (plan F19).
3
3
  *
4
4
  * A node that references a local style — `styleIdForFill`, `styleIdForStrokeFill`,
5
- * `styleIdForEffect` — draws the STYLE's current paints or effects. The copy cached on the node
6
- * beside the reference is what the node looked like when it was last touched, and it can be
7
- * stale (1 779 nodes and 1 064 override records in the sample disagree with their style) or
8
- * missing altogether (3 905 override records and 265 text-run entries carry only the reference).
9
- * Measured on the sample's card icon: Figma's export is #333333, the "Black" style, while the
10
- * override's cached paint says #F18D00.
5
+ * `styleIdForEffect` — draws the STYLE's current paints or effects, not the copy cached beside
6
+ * the reference. Measured on the sample's card icon: Figma's export is #333333, the "Black"
7
+ * style, while the override's cached paint says #F18D00.
11
8
  *
12
- * A style that is not in the file (a library style) cannot be followed, and neither can the
13
- * "no style" sentinel a detached override writes; both leave the cached copy in charge.
9
+ * The resolution itself lives in `model/styles.ts`, shared with the inspection tools so a colour
10
+ * never differs between the picture and the numbers; it is re-exported here for the exporter.
11
+ * The exporter resolves colour and effect styles only: text styles change no pixel, because the
12
+ * glyph outlines are baked (F5).
14
13
  */
15
14
  import type { KiwiObject } from '../fig/kiwi.js';
16
15
  import type { NodeChange } from '../fig/parse.js';
17
16
  import type { FileIndex } from '../model/index.js';
18
- /** The paints of a local colour style, or undefined when the reference cannot be followed. */
19
- export declare function stylePaints(index: FileIndex, ref: unknown): KiwiObject[] | undefined;
20
- /** The effects of a local effect style, or undefined when the reference cannot be followed. */
21
- export declare function styleEffects(index: FileIndex, ref: unknown): KiwiObject[] | undefined;
22
- /** The node with every style reference it carries resolved to the style's live value. */
23
- export declare function applyStyles(index: FileIndex, node: NodeChange): NodeChange;
17
+ export { applyStyles, styleEffects, stylePaints } from '../model/styles.js';
24
18
  /**
25
19
  * §4.7.5 — a `Path.styleID`, or the run style of a glyph, selects an entry of the node's
26
20
  * `styleOverrideTable`, which carries only the fields that differ from the node's own. An entry
@@ -1,43 +1,6 @@
1
- import { guidKey } from '../model/tree.js';
2
- import { num, obj, objArr, str } from '../model/access.js';
3
- function styleNode(index, ref, styleType) {
4
- if (!ref || typeof ref !== 'object')
5
- return undefined;
6
- const r = ref;
7
- const local = guidKey(obj(r, 'guid'));
8
- const t = index.resolveAssetRef(r) ?? (local ? index.node(local) : undefined);
9
- return t && str(t.node, 'styleType') === styleType ? t : undefined;
10
- }
11
- /** The paints of a local colour style, or undefined when the reference cannot be followed. */
12
- export function stylePaints(index, ref) {
13
- const t = styleNode(index, ref, 'FILL');
14
- if (!t || !Array.isArray(t.node['fillPaints']))
15
- return undefined;
16
- return objArr(t.node, 'fillPaints');
17
- }
18
- /** The effects of a local effect style, or undefined when the reference cannot be followed. */
19
- export function styleEffects(index, ref) {
20
- const t = styleNode(index, ref, 'EFFECT');
21
- if (!t || !Array.isArray(t.node['effects']))
22
- return undefined;
23
- return objArr(t.node, 'effects');
24
- }
25
- /** The node with every style reference it carries resolved to the style's live value. */
26
- export function applyStyles(index, node) {
27
- const fill = stylePaints(index, node['styleIdForFill']);
28
- const stroke = stylePaints(index, node['styleIdForStrokeFill']);
29
- const effects = styleEffects(index, node['styleIdForEffect']);
30
- if (!fill && !stroke && !effects)
31
- return node;
32
- const out = { ...node };
33
- if (fill)
34
- out['fillPaints'] = fill;
35
- if (stroke)
36
- out['strokePaints'] = stroke;
37
- if (effects)
38
- out['effects'] = effects;
39
- return out;
40
- }
1
+ import { num, obj, objArr } from '../model/access.js';
2
+ import { stylePaints } from '../model/styles.js';
3
+ export { applyStyles, styleEffects, stylePaints } from '../model/styles.js';
41
4
  /**
42
5
  * §4.7.5 — a `Path.styleID`, or the run style of a glyph, selects an entry of the node's
43
6
  * `styleOverrideTable`, which carries only the fields that differ from the node's own. An entry
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "figme-mcp",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "mcpName": "io.github.ntson9p/figme-mcp",
5
5
  "private": false,
6
6
  "description": "MCP server that reads local Figma .fig files, fully offline",
@@ -49,8 +49,8 @@
49
49
  "visual:update": "node scripts/visual.mjs --update"
50
50
  },
51
51
  "dependencies": {
52
- "@modelcontextprotocol/sdk": "^1.30.0",
53
- "zod": "^4.5.4"
52
+ "@modelcontextprotocol/sdk": "^1.32.2",
53
+ "zod": "^4.6.7"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/node": "^26.4.0",