Untitled

 avatar
unknown
plain_text
a month ago
1.7 kB
2
Indexable
// Plugin para Figma: Conexión visual entre frames
figma.showUI(__html__, { width: 300, height: 200 });

figma.ui.onmessage = async (msg) => {
  if (msg.type === 'create-connection') {
    const { startId, endId, color, arrowType } = msg;
    const startNode = figma.getNodeById(startId);
    const endNode = figma.getNodeById(endId);
    
    if (startNode && endNode) {
      const line = figma.createVector();
      
      line.vectorNetwork = {
        vertices: [
          { x: startNode.x + startNode.width / 2, y: startNode.y + startNode.height / 2 },
          { x: endNode.x + endNode.width / 2, y: endNode.y + endNode.height / 2 }
        ],
        segments: [{ start: 0, end: 1 }]
      };
      
      line.strokes = [{ type: 'SOLID', color: hexToRgb(color) }];
      line.strokeWeight = 2;
      line.name = 'Flow Connector';
      figma.currentPage.appendChild(line);
      
      if (arrowType === 'arrow') {
        addArrowHead(line);
      } else if (arrowType === 'dot') {
        addDot(line);
      }
    }
  }
};

function hexToRgb(hex) {
  const bigint = parseInt(hex.slice(1), 16);
  return { r: (bigint >> 16) & 255 / 255, g: (bigint >> 8) & 255 / 255, b: bigint & 255 / 255 };
}

function addArrowHead(line) {
  const arrow = figma.createPolygon();
  arrow.pointCount = 3;
  arrow.resize(10, 10);
  arrow.x = line.vectorNetwork.vertices[1].x;
  arrow.y = line.vectorNetwork.vertices[1].y;
  arrow.fills = line.strokes;
  figma.currentPage.appendChild(arrow);
}

function addDot(line) {
  const dot = figma.createEllipse();
  dot.resize(8, 8);
  dot.x = line.vectorNetwork.vertices[1].x - 4;
  dot.y = line.vectorNetwork.vertices[1].y - 4;
  dot.fills = line.strokes;
  figma.currentPage.appendChild(dot);
}
Editor is loading...
Leave a Comment