mcp-figma-toolkit 1.0.7 → 1.0.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/plugin/plugin.js +20 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-figma-toolkit",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "MCP server that enables AI agents to manipulate Figma documents - create shapes, text, styles, components, variables, and more",
5
5
  "type": "module",
6
6
  "main": "dist/server.js",
package/plugin/plugin.js CHANGED
@@ -17,23 +17,22 @@ function reply(replyTo, result, error) {
17
17
  const page = () => figma.currentPage;
18
18
 
19
19
  // ---------- Utilities ----------
20
- function rgbToHex(r, g, b) {
21
- const toHex = (v) => Math.round(Math.min(1, Math.max(0, v)) * 255).toString(16).padStart(2, "0");
22
- return "#" + toHex(r) + toHex(g) + toHex(b);
23
- }
24
-
25
20
  function serializePaints(paints) {
26
- if (!paints || !Array.isArray(paints)) return [];
27
- return paints.map(p => {
28
- const base = { type: p.type, visible: p.visible !== false, opacity: p.opacity != null ? p.opacity : 1, blendMode: p.blendMode };
21
+ if (!paints || typeof paints.length !== "number") return [];
22
+ var arr = [];
23
+ for (var i = 0; i < paints.length; i++) { arr.push(paints[i]); }
24
+ return arr.map(function(p) {
25
+ var base = { type: p.type, visible: p.visible !== false, opacity: p.opacity != null ? p.opacity : 1, blendMode: p.blendMode };
29
26
  if (p.type === "SOLID" && p.color) {
30
- base.hex = rgbToHex(p.color.r, p.color.g, p.color.b);
31
- } else if (p.type && p.type.startsWith("GRADIENT_") && p.gradientStops) {
32
- base.gradientStops = p.gradientStops.map(s => ({
33
- position: s.position,
34
- hex: rgbToHex(s.color.r, s.color.g, s.color.b),
35
- opacity: s.color.a != null ? s.color.a : 1
36
- }));
27
+ base.hex = rgbToHex(p.color);
28
+ } else if (p.type && p.type.indexOf("GRADIENT") === 0 && p.gradientStops) {
29
+ base.gradientStops = p.gradientStops.map(function(s) {
30
+ return {
31
+ position: s.position,
32
+ hex: s.color ? rgbToHex(s.color) : null,
33
+ opacity: s.color && s.color.a != null ? s.color.a : 1
34
+ };
35
+ });
37
36
  } else if (p.type === "IMAGE") {
38
37
  base.scaleMode = p.scaleMode;
39
38
  base.imageHash = p.imageHash;
@@ -43,13 +42,15 @@ function serializePaints(paints) {
43
42
  }
44
43
 
45
44
  function serializeEffects(effects) {
46
- if (!effects || !Array.isArray(effects)) return [];
47
- return effects.map(e => {
48
- const base = { type: e.type, visible: e.visible !== false, radius: e.radius };
45
+ if (!effects || typeof effects.length !== "number") return [];
46
+ var arr = [];
47
+ for (var i = 0; i < effects.length; i++) { arr.push(effects[i]); }
48
+ return arr.map(function(e) {
49
+ var base = { type: e.type, visible: e.visible !== false, radius: e.radius };
49
50
  if (e.offset) base.offset = { x: e.offset.x, y: e.offset.y };
50
51
  if (e.spread !== undefined) base.spread = e.spread;
51
52
  if (e.color) {
52
- base.hex = rgbToHex(e.color.r, e.color.g, e.color.b);
53
+ base.hex = rgbToHex(e.color);
53
54
  base.opacity = e.color.a != null ? e.color.a : 1;
54
55
  }
55
56
  return base;