渲染状态图
用 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。
对于 TLA+ 状态图(stateDiagram-v2),命令会给每个状态加上所属分组的颜色类,例如 class sN teal。它会给每个错误状态加上 class sN breaks 或 class sN mayBreak,给通往 bug 的最短路径上的每个状态加上 class sN bugPath,给 PROPERTY 反例中无限重复的每个状态加上 class sN repeats。.mmd 文件含有 breaks 和 mayBreak 的 classDef 行,但不含分组颜色、bugPath 或 repeats 的定义。
对于 Lean 4 证明图(flowchart TD),lemmas.mmd 和 proof.mmd 会为 target、goalRoot、subRoot、termRoot、closed、sorry、error、open、axiom、native、restsOn、doubtPath、folded、stub 和 note 输出 classDef 与 class 赋值。流程图节点会按形状渲染为 rect、polygon 或 circle,因此下面的 CSS 规则会匹配这三种元素。
Pele 会把每条 classDef 颜色写成节点的内联 style 属性,而它优先于普通 CSS 规则。因此下面的标记规则使用 !important,确保深色主题能覆盖浅色 classDef 颜色。把标记规则放在分组颜色之后,让标记显示在分组颜色上方。
把以下 <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;}.pele .target rect, .pele .target polygon, .pele .target circle { fill: #e8f2ff !important; stroke: #1680f3 !important; stroke-width: 2.5px !important;}.pele .target text { fill: #0d4ea6 !important; }.pele .goalRoot rect, .pele .goalRoot polygon, .pele .goalRoot circle { fill: #e8f2ff !important; stroke: #1680f3 !important; stroke-width: 2px !important;}.pele .goalRoot text { fill: #0d4ea6 !important; }.pele .subRoot rect, .pele .subRoot polygon, .pele .subRoot circle { fill: #eef2ff !important; stroke: #6366f1 !important; stroke-width: 2px !important;}.pele .subRoot text { fill: #3730a3 !important; }.pele .termRoot rect, .pele .termRoot polygon, .pele .termRoot circle { fill: #f0fdfa !important; stroke: #0d9488 !important; stroke-width: 2px !important;}.pele .termRoot text { fill: #115e59 !important; }.pele .closed rect, .pele .closed polygon, .pele .closed circle { fill: #e9f7ef !important; stroke: #229954 !important; stroke-width: 1.5px !important;}.pele .closed text { fill: #145a32 !important; }.pele .folded rect, .pele .folded polygon, .pele .folded circle { fill: #f3ecff !important; stroke: #8b5cf6 !important; stroke-width: 1.5px !important;}.pele .folded text { fill: #5b21b6 !important; }.pele .stub rect, .pele .stub polygon, .pele .stub circle { fill: #f4f4f5 !important; stroke: #71717a !important; stroke-width: 1.5px !important; stroke-dasharray: 5 3;}.pele .stub text { fill: #52525b !important; }.pele .note rect, .pele .note polygon, .pele .note circle { fill: #fafafa !important; stroke: #d4d4d8 !important; stroke-width: 1px !important;}.pele .note text { fill: #52525b !important; }.pele .doubtPath rect, .pele .doubtPath polygon, .pele .doubtPath circle { stroke: #e72e3b !important; stroke-width: 2.5px !important;}.pele .open rect, .pele .open polygon, .pele .open circle,.pele .axiom rect, .pele .axiom polygon, .pele .axiom circle,.pele .restsOn rect, .pele .restsOn polygon, .pele .restsOn circle { fill: #fff3e6 !important; stroke: #e8730c !important; stroke-width: 2.5px !important;}.pele .open text, .pele .axiom text, .pele .restsOn text { fill: #b85a06 !important;}.pele .sorry rect, .pele .sorry polygon, .pele .sorry circle,.pele .error rect, .pele .error polygon, .pele .error circle,.pele .native rect, .pele .native polygon, .pele .native circle { fill: #ffecee !important; stroke: #e72e3b !important; stroke-width: 2.5px !important;}.pele .sorry text, .pele .error text, .pele .native text { fill: #cd2834 !important;}@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; } .pele .target rect, .pele .target polygon, .pele .target circle { fill: #172d47 !important; stroke: #4c9aff !important; } .pele .target text { fill: #9cc9ff !important; } .pele .goalRoot rect, .pele .goalRoot polygon, .pele .goalRoot circle { fill: #172d47 !important; stroke: #4c9aff !important; } .pele .goalRoot text { fill: #9cc9ff !important; } .pele .subRoot rect, .pele .subRoot polygon, .pele .subRoot circle { fill: #1e1b4b !important; stroke: #818cf8 !important; } .pele .subRoot text { fill: #c7d2fe !important; } .pele .termRoot rect, .pele .termRoot polygon, .pele .termRoot circle { fill: #134e4a !important; stroke: #2dd4bf !important; } .pele .termRoot text { fill: #99f6e4 !important; } .pele .closed rect, .pele .closed polygon, .pele .closed circle { fill: #153323 !important; stroke: #34d399 !important; } .pele .closed text { fill: #86efac !important; } .pele .folded rect, .pele .folded polygon, .pele .folded circle { fill: #2c1f4a !important; stroke: #a78bfa !important; } .pele .folded text { fill: #ddd6fe !important; } .pele .stub rect, .pele .stub polygon, .pele .stub circle { fill: #27272a !important; stroke: #a1a1aa !important; } .pele .stub text { fill: #d4d4d8 !important; } .pele .note rect, .pele .note polygon, .pele .note circle { fill: #262626 !important; stroke: #52525b !important; } .pele .note text { fill: #d4d4d8 !important; } .pele .doubtPath rect, .pele .doubtPath polygon, .pele .doubtPath circle { stroke: #cf2b35 !important; } .pele .open rect, .pele .open polygon, .pele .open circle, .pele .axiom rect, .pele .axiom polygon, .pele .axiom circle, .pele .restsOn rect, .pele .restsOn polygon, .pele .restsOn circle { fill: #2e2619 !important; stroke: #d0700f !important; } .pele .open text, .pele .axiom text, .pele .restsOn text { fill: #ffa257 !important; } .pele .sorry rect, .pele .sorry polygon, .pele .sorry circle, .pele .error rect, .pele .error polygon, .pele .error circle, .pele .native rect, .pele .native polygon, .pele .native circle { fill: #2e2021 !important; stroke: #cf2b35 !important; } .pele .sorry text, .pele .error text, .pele .native text { fill: #ff6463 !important; }}