mcpField
E
excalidraw

excalidraw

github.com/kv0906设计与 UI1850 次安装3 周前更新
代码仓库

关于 excalidraw

excalidraw 是用于生成 Excalidraw 兼容图表 JSON 的技能,面向需要创建流程图和结构图的用户。它提供网格布局、元素定位与文本居中等规范,并将结果保存为可打开的 .excalidraw.json 文件。

主要功能

  1. 01生成 Excalidraw 兼容 JSON
  2. 02提供网格布局与尺寸规范
  3. 03计算文本居中位置
  4. 04支持形状、文本和箭头
  5. 05提供流程图等布局模板

适用场景

  1. 01制作流程图或处理流程图
  2. 02绘制带分支的决策图
  3. 03生成带连接箭头的结构图

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/kv0906/cc-skills --skill excalidraw

安装后在 Claude Code 中输入/excalidraw确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

assets/
flowchart-template.excalidraw.json
references/
elements.md
processing-loop-template.md

详细介绍

Excalidraw 图表生成器

创建兼容 Excalidraw 的 JSON 图表。输出 .excalidraw.json 文件。

JSON 架构

{
  "type": "excalidraw",
  "version": 2,
  "source": "https://excalidraw.com",
  "elements": [],
  "appState": {
    "gridSize": null,
    "viewBackgroundColor": "#ffffff"
  },
  "files": {}
}

坐标系

  • 原点:左上角(0, 0)
  • X 轴:向右递增
  • Y 轴:向下递增
  • 单位:像素

基于网格的布局系统

使用 20px 网格进行对齐。标准位置:

GRID_UNIT = 20
COLUMN_WIDTH = 200    # Element + gap
ROW_HEIGHT = 150      # Element + gap

Position formula:
  x = START_X + (column * COLUMN_WIDTH)
  y = START_Y + (row * ROW_HEIGHT)

Recommended START_X = 50, START_Y = 100
标准元素尺寸
元素宽度高度用途
小框12060标签、简单步骤
标准框16080流程步骤
大框200100详细节点
宽框24080长文本
菱形100100决策点
圆形8080开始/结束节点
图标圆形9080带表情符号

文本居中公式

重要:要使文本在形状内居中:

text_x = shape_x + (shape_width - text_width) / 2
text_y = shape_y + (shape_height - text_height) / 2
文本尺寸参考
字号字符宽度行高用途
11~6px15px标签、注释
12~7px16px次要文本
14~8px18px正文
16~9px20px主要文本
18~10px24px标题
20~11px26px标题
28~16px35px图标/表情符号

估算 text_width:char_count * char_width 估算 text_height:line_count * line_height

居中示例
Shape: x=100, y=100, width=160, height=80
Text: "Process" (7 chars), fontSize=16

text_width = 7 * 9 = 63
text_height = 1 * 20 = 20
text_x = 100 + (160 - 63) / 2 = 148.5 ≈ 148
text_y = 100 + (80 - 20) / 2 = 130

元素类型

通用属性(所有元素必需)
{
  "id": "unique-id",
  "type": "rectangle",
  "x": 100,
  "y": 100,
  "width": 160,
  "height": 80,
  "strokeColor": "#1e1e1e",
  "backgroundColor": "transparent",
  "fillStyle": "solid",
  "strokeWidth": 2,
  "roughness": 1,
  "opacity": 100,
  "angle": 0,
  "seed": 100,
  "version": 1,
  "isDeleted": false,
  "boundElements": null,
  "link": null,
  "locked": false
}
特定类型属性

矩形:添加 "roundness": {"type": 3} 以使用圆角

文本:

{
  "type": "text",
  "text": "Content\nLine 2",
  "fontSize": 16,
  "fontFamily": 1,
  "textAlign": "center",
  "verticalAlign": "middle"
}
  • fontFamily:1=Virgil(手写),2=Helvetica,3=Cascadia(等宽)

箭头/线条:

{
  "type": "arrow",
  "points": [[0, 0], [100, 0]],
  "startArrowhead": null,
  "endArrowhead": "arrow"
}
  • 点相对于元素的 x,y 坐标
  • 箭头端点:null、"arrow"、"bar"、"dot"、"triangle"

箭头定位

水平箭头(从左到右)
From shape at (x1, y1, w1, h1) to shape at (x2, y2, w2, h2):

arrow_x = x1 + w1           # Right edge of source
arrow_y = y1 + h1/2         # Vertical center
gap = x2 - (x1 + w1)        # Space between shapes
points = [[0, 0], [gap, 0]]
垂直箭头(从上到下)
arrow_x = x1 + w1/2         # Horizontal center
arrow_y = y1 + h1           # Bottom edge of source
gap = y2 - (y1 + h1)
points = [[0, 0], [0, gap]]
对角线/曲线箭头
points = [[0, 0], [dx/2, dy], [dx, dy]]  # Curved path

配色方案

颜色描边背景用途
蓝色#1971c2#a5d8ff主要、信息
绿色#2f9e44#b2f2bb成功、开始
橙色#e8590c#ffc9c9警告、操作
红色#e03131#ffc9c9错误、结束
紫色#9c36b5#eebefa特殊、循环
黄色#f08c00#ffec99高亮
青绿色#099268#96f2d7次要
灰色#868e96#dee2e6中性、标签
黑色#1e1e1e-文本、边框

Z 顺序(元素数组顺序)

元素按数组顺序渲染。第一个在最底层,最后一个在最上层。

正确顺序:

  1. 背景形状(容器、框架)
  2. 连接线/箭头
  3. 前景形状(节点、框)
  4. 文本标签
  5. 图标/叠加层

布局模式

水平流程(从左到右)
COL_GAP = 60  # Gap between elements

Element 1: x=50,  y=100, w=160, h=80
Arrow 1:   x=210, y=140, points=[[0,0],[60,0]]
Element 2: x=270, y=100, w=160, h=80
Arrow 2:   x=430, y=140, points=[[0,0],[60,0]]
Element 3: x=490, y=100, w=160, h=80
垂直流程(从上到下)
ROW_GAP = 50

Element 1: x=100, y=50,  w=160, h=80
Arrow 1:   x=180, y=130, points=[[0,0],[0,50]]
Element 2: x=100, y=180, w=160, h=80
决策分支(菱形)
Diamond:    x=300, y=200, w=100, h=100
Center:     (350, 250)

Yes path (up-right):
  arrow_x=350, arrow_y=200
  points=[[0,0], [0,-50], [100,-50]]

No path (down-right):
  arrow_x=350, arrow_y=300
  points=[[0,0], [0,50], [100,50]]
反馈循环(返回箭头)
From bottom-right back to left:
  Start: (800, 400)
  points=[
    [0, 0],        # Start
    [0, 80],       # Down
    [-400, 80],    # Left
    [-400, -150]   # Up to target
  ]

完整节点示例

[
  {
    "id": "node1-box",
    "type": "rectangle",
    "x": 100, "y": 100, "width": 160, "height": 80,
    "strokeColor": "#1971c2",
    "backgroundColor": "#a5d8ff",
    "fillStyle": "solid",
    "strokeWidth": 2,
    "roughness": 1,
    "opacity": 100,
    "angle": 0,
    "seed": 100,
    "version": 1,
    "isDeleted": false,
    "boundElements": [{"id": "arrow1", "type": "arrow"}],
    "roundness": {"type": 3},
    "link": null,
    "locked": false
  },
  {
    "id": "node1-text",
    "type": "text",
    "x": 130, "y": 130,
    "width": 100, "height": 20,
    "text": "Process Step",
    "fontSize": 16,
    "fontFamily": 1,
    "textAlign": "center",
    "verticalAlign": "middle",
    "strokeColor": "#1e1e1e",
    "backgroundColor": "transparent",
    "fillStyle": "solid",
    "strokeWidth": 1,
    "roughness": 1,
    "opacity": 100,
    "angle": 0,
    "seed": 101,
    "version": 1,
    "isDeleted": false,
    "boundElements": null,
    "link": null,
    "locked": false
  }
]

定位检查清单

生成前:

  1. ☐ 定义网格:START_X、START_Y、COLUMN_WIDTH、ROW_HEIGHT
  2. ☐ 列出所有元素及其行/列位置
  3. ☐ 使用公式计算准确的 x,y 坐标
  4. ☐ 使用居中公式计算文本位置
  5. ☐ 计算箭头起点和相对端点
  6. ☐ 按正确的 Z 顺序排列元素
  7. ☐ 分配唯一 ID 和递增的种子值

模板

  • 基本流程图:assets/flowchart-template.excalidraw.json
  • 处理循环:references/processing-loop-template.md
  • 元素规格:references/elements.md

输出

  1. 保存为 .excalidraw.json
  2. 复制到 /mnt/user-data/outputs/
  3. 告诉用户:“在 excalidraw.com 打开 → 菜单 → 打开”

评论

支持 Markdown