跳转到内容
pstack 中文学习站

渲染状态图

更新于 2026-10-28

用 npm 包 pele@1.9.0 渲染每个要展示的 .mmd 文件,并把 SVG 交给用户。只在仓库外安装一次 Pele。每个 SVG 与对应的 .mmd 文件放在同一目录,文件名相同。API 见 https://pele.run/api。调用 render 时传入选项 { limit: 1_000_000, outputLimit: 8_000_000, maxEdges: 10_000 }。Pele 的默认限制无法处理 500 个状态的图。Pele 抛出 PeleError 时,把 Mermaid 文本和错误都展示给用户。

Pele 忽略 Mermaid 的 theme 和 themeVariables。请在 .pele 上设置 --pele-* CSS 变量。变量列表见 https://pele.run/theming。命令会给每个状态加上所属分组的颜色类,例如 class sN teal。它会给每个错误状态加上 class sN breaks 或 class sN mayBreak,给通往 bug 的最短路径上的每个状态加上 class sN bugPath,给 PROPERTY 反例中无限重复的每个状态加上 class sN repeats。Pele 会把这些类加到状态节点上。用 CSS 为这些类设置颜色。

.mmd 文件包含 breaks 和 mayBreak 的 classDef 行,因此任意 Mermaid 查看器都能显示错误标记。文件没有分组颜色、bugPath 或 repeats 的 classDef。Pele 会把每条 classDef 颜色写成节点的 style 属性,而 style 属性优先于普通 CSS 规则。因此下面的错误标记规则使用 !important。没有它时,深色主题仍会显示浅色标记。错误标记会设置填充色和文字颜色;bugPath 和 repeats 会设置边框。把标记规则放在分组颜色之后,确保标记盖在分组颜色上方。

以下颜色只是建议,也是旧版 skill 使用的颜色。把它们放进每个 SVG 开头的 <style> 元素。每个 SVG 会根据查看器的浅色或深色设置切换颜色。

.pele {
--pele-bg: #ffffff;
--pele-fg: #1c1c1c;
--pele-muted: #656565;
--pele-line: #808080;
--pele-surface: #fcfcfc;
--pele-surface-alt: #f1f1f1;
--pele-border: #c9c9c9;
}
.pele .blue rect { fill: #c3e0ff; }
.pele .orange rect { fill: #f0d3bf; }
.pele .purple rect { fill: #e3d5ff; }
.pele .yellow rect { fill: #f0dcbf; }
.pele .teal rect { fill: #bfe3df; }
.pele .tan rect { fill: #e5d9ce; }
.pele .pink rect { fill: #ffcbe6; }
.pele .breaks rect {
fill: #ffecee !important;
stroke: #e72e3b !important;
stroke-width: 2.5px !important;
}
.pele .breaks text {
fill: #cd2834 !important;
}
.pele .mayBreak rect {
fill: #fff3e6 !important;
stroke: #e8730c !important;
stroke-width: 2.5px !important;
}
.pele .mayBreak text {
fill: #b85a06 !important;
}
.pele .bugPath rect {
stroke: #1680f3 !important;
stroke-width: 2.5px !important;
}
.pele .repeats rect {
stroke: #9b35d6 !important;
stroke-width: 2.5px !important;
stroke-dasharray: 6 3;
}
@media (prefers-color-scheme: dark) {
.pele {
--pele-bg: #1f1f1f;
--pele-fg: #f5f5f5;
--pele-muted: #acacac;
--pele-line: #939393;
--pele-surface: #121212;
--pele-surface-alt: #2c2c2c;
--pele-border: #4e4e4e;
}
.pele .blue rect { fill: #1b3857; }
.pele .orange rect { fill: #573117; }
.pele .purple rect { fill: #3c2e57; }
.pele .yellow rect { fill: #573d17; }
.pele .teal rect { fill: #174641; }
.pele .tan rect { fill: #3d3127; }
.pele .pink rect { fill: #57233e; }
.pele .breaks rect {
fill: #2e2021 !important;
stroke: #cf2b35 !important;
}
.pele .breaks text {
fill: #ff6463 !important;
}
.pele .mayBreak rect {
fill: #2e2619 !important;
stroke: #d0700f !important;
}
.pele .mayBreak text {
fill: #ffa257 !important;
}
.pele .bugPath rect {
stroke: #116dd2 !important;
}
.pele .repeats rect {
stroke: #9a3fcf !important;
}
}

感谢阅读

关注站长 liu xu,pstack 有新译文和笔记会第一时间发。

公众号「出发向未来」的二维码
公众号「出发向未来」