Repository navigation
fix(mermaid): resolve CSS theme colors before initialization - #279
Merged
wang-kaopu merged 2 commits intoOct 11, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
在 Whale Song 等皮肤下,语法正确的 Mermaid 图表会因为主题颜色包含
calc()而渲染失败,并被误报为图表语法错误。例如:Unsupported color format: "rgba(235, 242, 250, calc(.4 + 0 * .4))"getComputedStyle(document.body).getPropertyValue(...)返回的 CSS 自定义属性仍可能包含计算表达式。这个改动先通过临时 DOM 元素解析真实颜色,再将需要转换的现代 CSS 颜色转为 sRGB,使 Mermaid 初始化时接收到受支持的 RGB/RGBA。透明度和原有备用颜色保持有效,初始化期间缓存重复使用的主题颜色。中英文降级提示改为“渲染失败”。新增颜色回归测试,并同步现有渲染状态测试的提示文案。版本号、依赖声明、发布流程和 Mermaid 安全配置保持原样。
验证:
pnpm run check:TypeScript 检查、完整 Vitest 测试套件和 tsdown 构建通过;新增的 13 个颜色用例全部通过。calc()错误;修复分支的构建通过默认/Whale Song 明暗主题、不同透明度、现代颜色和无效 token 共 8 组用例,原始 17 节点图正常渲染。