Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

feat(diagram): redesign mind map color palettes and adaptive contrast

tianma-ifcc32f2f1bd7a
diff --git a/apps/web/src/lib/diagram-theme.test.mjs b/apps/web/src/lib/diagram-theme.test.mjs
index 83cecbc7..7fa6d0b3 100644
--- a/apps/web/src/lib/diagram-theme.test.mjs
+++ b/apps/web/src/lib/diagram-theme.test.mjs
@@ -35,7 +35,7 @@ describe("diagram appearance palettes", () => {
test("keeps the ten selectable color schemes distinct from forest green", () => {
expect(Object.keys(DIAGRAM_THEME_PALETTES)).toEqual(expect.arrayContaining([
- "brand", "mint", "wa", "island", "rose", "sun", "cosmos", "tea", "naive", "macaron",
+ "brand", "cosmos", "dune", "slate", "prism", "sunrise", "marine", "blossom", "mint", "macaron",
]));
expect(resolveDiagramPalette("mint", "light").topicFill).not.toBe(resolveDiagramPalette("brand", "light").topicFill);
expect(resolveDiagramPalette("ocean", "light")).toEqual(resolveDiagramPalette("brand", "light"));
diff --git a/docs/visual-diagram-notes.md b/docs/visual-diagram-notes.md
index 663e520a..4292490d 100644
--- a/docs/visual-diagram-notes.md
+++ b/docs/visual-diagram-notes.md
@@ -16,7 +16,9 @@ This abstraction provides three immediate benefits:
- Visual, layout, or rendering-library changes do not require migrating the note's meaning.
- Data can be validated before rendering, rejecting dangling edges, invalid containment, and unsupported node types.
-The original mind-map and flowchart notes already use IR v1. Architecture diagrams use IR v2, adding semantic components, system boundaries, connection types, and bidirectional relationships.
+The persisted document uses `schemaVersion` to distinguish formats: `1` for mind maps and flowcharts, `2` for architecture diagrams, which add semantic components, system boundaries, connection types, and bidirectional relationships. The Markdown envelope comment is always `edgeever-diagram-v1` and does not change with `schemaVersion`.
+
+MCP and the compile path use a separate semantic graph without coordinates. The server then generates sizes, coordinates, and edge identities into the persisted document. The agent protocol does not carry X6 or canvas state.
## IR and rendering-engine decoupling
@@ -35,13 +37,13 @@ The IR should contain stable business semantics and necessary layout facts, such
## Current data model
-A node contains `id`, `label`, `x`, `y`, `width`, `height`, and `shape`; a node inside a system boundary also has `parentId`. An edge contains `source` and `target`, with optional `label`, `kind`, and `bidirectional` fields.
+The persisted IR is a `DiagramDocument` with `schemaVersion`, `kind` (`mind-map` / `flowchart` / `architecture`), optional `theme`, and, for mind maps, optional `structure`. A node contains `id`, `label`, `x`, `y`, `width`, `height`, and `shape`; optional `parentId` (mind-map topic hierarchy, or containment inside an architecture boundary) and `resourceIcon` (architecture resource appearance). An edge has required `id`, `source`, and `target`, with optional `label`, `kind`, and `bidirectional` fields.
A diagram is stored as portable Markdown. Its body contains a Mermaid fallback, while a trailing `edgeever-diagram-v1` comment carries the Base64URL-encoded JSON IR. The IR is the source of truth for lossless editing. The Mermaid fence is a projection, not the live canvas: first-party clients, including public share, parse the IR and draw with AntV X6. The fence remains so the note stays readable as ordinary Markdown outside EdgeEver, and when the IR comment fails to parse.
User-authored ` ```mermaid ` code blocks in ordinary rich-text notes are a separate product feature. They do not use this IR and are not visual-diagram notes.
-IR parsing and validation live in [`packages/shared/src/diagram.ts`](../packages/shared/src/diagram.ts), so Web, Android, and iOS do not maintain competing interpretations of the format.
+Parsing and validation live in [`packages/shared/src/diagram.ts`](../packages/shared/src/diagram.ts). Semantic-graph compilation and automatic layout live in [`packages/shared/src/diagram-layout.ts`](../packages/shared/src/diagram-layout.ts). The read-only X6 adapter is [`packages/shared/src/diagram-view.ts`](../packages/shared/src/diagram-view.ts) (`diagramDocumentToX6Cells`), reused by Android, iOS, and public share. The Web / desktop editor consumes the same IR but has its own interactive node mapping.
## Why AntV X6
@@ -49,7 +51,7 @@ Visual diagram notes need an editable canvas: selection, dragging, zooming, conn
The IR answers “what does this diagram mean?”; the X6 adapter answers “how do we draw it and let the user edit it?” X6 internals, coordinate conventions, and view instances therefore stay out of the persisted format. Adopting a second engine for one diagram type would also import another state manager, coordinate system, interaction model, and data format, leaving two canvases to maintain.
-Android and iOS read-only viewers reuse the same X6 adapter (`diagramDocumentToX6Cells` plus a non-interactive `Graph`). First-party canvases no longer split between X6 on Web and Mermaid on mobile. Mermaid remains the portable envelope, the renderer for embedded rich-text diagrams, and the fallback when IR parsing fails.
+Android and iOS read-only viewers, and public share, reuse the same X6 adapter (`diagramDocumentToX6Cells` plus a non-interactive `Graph`). The Web / desktop editor uses the same IR and engine with an interactive mapping of its own. First-party canvases no longer split between X6 on Web and Mermaid on mobile. Mermaid remains the portable envelope, the renderer for embedded rich-text diagrams, and the fallback when IR parsing fails.
This does not mean rendering every node as the same X6 rectangle. X6 is only the underlying engine; icons, SVG markup, shapes, ports, colors, boundaries, and connection semantics are customized by EdgeEver per diagram type.
@@ -73,32 +75,35 @@ An early mobile viewer used the Mermaid fence because AntV X6 was not yet wrappe
- Diagram semantics belong to the IR; the rendering engine is not the data source.
- First-party canvases render visual diagram notes from IR through X6. Embedded ` ```mermaid ` blocks in ordinary rich-text notes stay on Mermaid. The persisted Mermaid fence on a visual diagram note is only a portable envelope and a degraded fallback, not the live canvas.
- Architecture components must communicate their purpose visually; names are supplementary.
-- A system boundary is a containment relationship, not a normal connectable business node.
+- `parentId` is containment: topic hierarchy on a mind map, a system boundary on an architecture diagram. A system boundary is not a normal connectable business node.
+- `theme` and a mind map's `structure` are presentation choices on the document, not engine-private state.
- Web and native apps consume the same persisted data rather than platform-specific diagram copies.
-- New versions should keep old diagrams readable, with format evolution managed explicitly through `schemaVersion`.
+- New versions should keep old diagrams readable. Format evolution is managed through `schemaVersion`; the envelope comment stays `edgeever-diagram-v1`.
- Native apps remain read-only until a touch editor can safely read and write the same IR.
## MCP and AI-generated diagrams
-For MCP and AI, the IR is a positive capability and the foundation of a stable tool protocol. An AI can work with semantic IR instead of producing X6 internals, SVG, or an entire Mermaid document. It can therefore perform a local request such as “add a Redis cache between the API and database” while preserving the user's other nodes and layout decisions.
+For MCP and AI, the semantic graph is the stable tool protocol. An AI can work with it instead of producing X6 internals, SVG, or an entire Mermaid document. It can therefore perform a local request such as “add a Redis cache between the API and database” while preserving the user's other nodes and layout decisions.
+
+There are three diagram MCP tools:
-The `create_diagram_memo` MCP tool accepts this semantic creation IR: node identities, labels, semantic types, containment, and connections. EdgeEver generates edge identities, node dimensions, coordinates, deterministic layout, and architecture boundary geometry before compiling the result into the persisted `DiagramDocument`. An optional layout direction is a hint rather than authored geometry. Tool results likewise return only the semantic graph instead of the encoded persistence payload.
+- `create_diagram_memo` accepts a semantic graph: node identities, labels, types, containment, and connections, plus optional `theme`, `structure`, and `layout.direction`. The server generates edge identities, node dimensions, coordinates, deterministic layout, and architecture boundary geometry, then compiles a persisted `DiagramDocument`. Layout direction is a compile hint and is not stored on the document. Results return the semantic graph, not the encoded persistence payload.
+- `get_diagram` returns only the semantic graph and memo revision by default, without coordinates or dimensions; node geometry is included only when `includeLayout` is true.
+- `update_diagram` accepts incremental operations on that one tool: `add_node`, `update_node`, `remove_node`, `add_edge`, `update_edge`, and `remove_edge`. It uses `expectedRevision` to prevent concurrent overwrites and supports `dryRun` previews. The default `reflow=preserve` keeps unaffected authored layout; `reflow=all` is only for an explicit full relayout. Moving a node into a boundary or changing mind-map hierarchy is `update_node` with `parentId`, not a separate MCP tool.
-`get_diagram` returns only the semantic graph and memo revision by default, without coordinates or dimensions; node geometry is included only when `includeLayout` is explicitly set. `update_diagram` accepts incremental operations that add, update, or remove nodes and edges, uses `expectedRevision` to prevent concurrent overwrites, supports `dryRun` previews, and preserves unaffected authored layout by default. The generic `update_memo` tool cannot replace diagram content, preventing callers from bypassing diagram validation.
+The generic `update_memo` tool cannot replace diagram content. There is no `replace_diagram_ir`, and no standalone validate or apply-layout tool: validation happens when the server applies operations, and layout is controlled by `reflow`.
-MCP exposes small, explicit operations for reading a diagram, adding or updating a node, connecting components, moving a node into a boundary, validating changes, and applying layout instead of a high-risk `replace_diagram_ir`. The recommended flow is:
+The recommended flow is:
```text
-Read IR
+get_diagram
→ AI produces incremental operations
- → server validates types, references, and containment
- → produce a change preview
- → user confirms
- → apply operations and deterministic layout
- → save a new revision
+ → optional dryRun preview
+ → update_diagram (preserve layout by default)
+ → server validates types, references, and containment, then writes a new revision
```
-To reduce model context and accidental changes, the IR can evolve toward separate semantic, layout, and presentation concerns. AI should modify semantics by default, with deterministic layout algorithms handling coordinates. Layout or presentation should change only when the user explicitly requests it.
+AI should modify semantics by default, with deterministic layout handling coordinates. Use `reflow=all` or change `theme` / `structure` only when the user explicitly wants a full relayout or a presentation change.
An IR can still become a liability if it mirrors X6 too closely, lacks useful semantics, changes versions frequently, or lets AI overwrite a whole diagram without validation. The schema should therefore remain small, stable, versioned, validated, and friendly to incremental operations.
@@ -106,4 +111,4 @@ An IR can still become a liability if it mirrors X6 too closely, lacks useful se
Full native editing should continue to use the same IR and separately address touch selection, dragging, connections, zooming, keyboard avoidance, and large-diagram performance. Whether that editor uses X6 in a WebView or a native canvas should be decided through prototypes and performance testing without changing the persisted format.
-HTML / print / WeChat copy of a visual diagram note still go through the generic rich-text pipeline when that pipeline is used, because those actions currently snapshot TipTap HTML rather than the X6 canvas. Align those exports with a read-only X6 snapshot before considering any change to the Markdown envelope.
+HTML / print / WeChat copy of a visual diagram note still go through the generic rich-text pipeline when that pipeline is used, because those actions currently snapshot TipTap HTML rather than the X6 canvas. Native share-as-image has the same gap. Align those exports with a read-only X6 snapshot before considering any change to the Markdown envelope. PNG / SVG export from the diagram editor already comes from X6.
diff --git a/docs/visual-diagram-notes.zh-CN.md b/docs/visual-diagram-notes.zh-CN.md
index da0dd767..a8384984 100644
--- a/docs/visual-diagram-notes.zh-CN.md
+++ b/docs/visual-diagram-notes.zh-CN.md
@@ -16,7 +16,9 @@ IR(Intermediate Representation,中间表示)是图表的结构化事实来
- 更换外观、布局或渲染库时,不需要迁移笔记的业务含义。
- 数据可以先验证再渲染,避免悬空连线、非法父子关系和错误节点类型进入编辑器。
-原有思维导图和流程图已经使用 IR v1;架构图在此基础上使用 IR v2,增加语义组件、系统边界、连线类型和双向关系。
+持久化文档用 `schemaVersion` 区分格式:思维导图和流程图为 `1`,架构图为 `2`,后者增加语义组件、系统边界、连线类型和双向关系。Markdown 信封注释名始终是 `edgeever-diagram-v1`,不随 `schemaVersion` 改名。
+
+MCP 与编译路径另有一层不含坐标的语义图;服务端再生成尺寸、坐标和连线标识,写入持久化文档。Agent 协议不携带 X6 或画布状态。
## IR 与绘图引擎解耦
@@ -35,13 +37,13 @@ IR 中应保存稳定的业务语义和必要布局,例如“这是数据库
## 当前数据模型
-节点包含 `id`、`label`、`x`、`y`、`width`、`height`、`shape`,位于系统边界中的节点还包含 `parentId`。连线包含 `source`、`target`,并可携带 `label`、`kind` 和 `bidirectional`。
+持久化 IR 是 `DiagramDocument`,包含 `schemaVersion`、`kind`(`mind-map` / `flowchart` / `architecture`)、可选 `theme`,思维导图还可带 `structure`。节点包含 `id`、`label`、`x`、`y`、`width`、`height`、`shape`;可选 `parentId`(思维导图的主题层级,或架构图中位于系统边界内)和 `resourceIcon`(架构图资源外观)。连线包含必填的 `id`、`source`、`target`,并可携带 `label`、`kind` 和 `bidirectional`。
图表保存为一份可移植 Markdown:正文包含 Mermaid 降级视图,末尾的 `edgeever-diagram-v1` 注释保存 Base64URL 编码的 JSON IR。IR 是无损编辑的事实来源。Mermaid fence 是投影,不是实时画布:自有客户端(含公开分享)解析 IR 后由 AntV X6 绘制。保留 fence 是为了让笔记在 EdgeEver 之外的普通 Markdown 中仍可读,以及 IR 注释解析失败时仍能降级显示。
普通富文本笔记里用户手写的 ` ```mermaid ` 代码块是独立功能,不走这套 IR,也不是可视化图表笔记。
-IR 的实现和校验集中在 [`packages/shared/src/diagram.ts`](../packages/shared/src/diagram.ts),避免 Web、Android 和 iOS 各自解释一套格式。
+解析和校验集中在 [`packages/shared/src/diagram.ts`](../packages/shared/src/diagram.ts)。语义图编译与自动布局在 [`packages/shared/src/diagram-layout.ts`](../packages/shared/src/diagram-layout.ts)。只读画布的 X6 适配器在 [`packages/shared/src/diagram-view.ts`](../packages/shared/src/diagram-view.ts)(`diagramDocumentToX6Cells`),供 Android、iOS 与公开分享复用;Web / 桌面编辑器使用同一 IR,但有自己的可交互节点映射。
## 为什么使用 AntV X6
@@ -49,7 +51,7 @@ IR 的实现和校验集中在 [`packages/shared/src/diagram.ts`](../packages/sh
IR 负责回答“这张图表达什么”,X6 适配器负责回答“当前如何把它画出来并让用户改”。因此不把 X6 内部状态、坐标约定或视图实例写进持久化格式。如果为某一类图表另选引擎,会同时引入另一套状态管理、坐标体系、交互约定和数据格式,并让两套画布长期并存。
-Android 与 iOS 的只读查看也复用同一套 X6 适配器(`diagramDocumentToX6Cells` 加不可交互的 `Graph`)。自有客户端画布不再按「Web 用 X6、移动端用 Mermaid」分轨。Mermaid 仍用于可移植信封、富文本嵌入图表,以及 IR 解析失败时的降级。
+Android、iOS 的只读查看和公开分享复用同一套 X6 适配器(`diagramDocumentToX6Cells` 加不可交互的 `Graph`)。Web / 桌面编辑器走同一 IR 和同一引擎,但使用可交互的编辑器映射。自有客户端画布不再按「Web 用 X6、移动端用 Mermaid」分轨。Mermaid 仍用于可移植信封、富文本嵌入图表,以及 IR 解析失败时的降级。
这并不意味着把所有节点画成同一种 X6 矩形。X6 只是底层引擎;图标、SVG 标记、形状、端口、配色、边界和连线语义均由 EdgeEver 按图表类型定制。
@@ -73,37 +75,40 @@ Android 与 iOS 的只读查看也复用同一套 X6 适配器(`diagramDocumen
- 图表语义由 IR 决定,渲染引擎不是数据源。
- 自有客户端画布由 IR 经 X6 绘制图形笔记。普通富文本里的 ` ```mermaid ` 代码块仍走 Mermaid。图形笔记里持久化的 Mermaid fence 只是可移植信封和降级路径,不是实时画布。
- 架构组件必须“看外观就知道用途”,名称只是补充。
-- 系统边界是容器关系,不是可连线的普通业务节点。
+- `parentId` 表示包含关系:思维导图是主题层级,架构图是系统边界;系统边界不是可连线的普通业务节点。
+- `theme` 与思维导图的 `structure` 属于文档上的呈现选择,不是引擎私有状态。
- Web 与原生 App 使用同一份持久化数据,不维护平台专属图表副本。
-- 新版本优先保持旧图可读;格式演进通过 `schemaVersion` 明确管理。
+- 新版本优先保持旧图可读;格式演进通过 `schemaVersion` 明确管理,信封注释名保持 `edgeever-diagram-v1`。
- 在原生触控编辑器能够安全读写同一 IR 之前,App 保持只读。
## MCP 与 AI 生成图表
-对于 MCP 和 AI,IR 是正向能力,也是稳定的工具协议基础。AI 面向语义化 IR 工作,不必生成 X6 内部配置、SVG 或整张 Mermaid 源码,因此可以理解和执行“在 API 与数据库之间增加 Redis 缓存”这类局部修改,同时保留用户已经调整好的其他节点和布局。
+对于 MCP 和 AI,语义图是稳定的工具协议:Agent 不必生成 X6 内部配置、SVG 或整张 Mermaid 源码,因此可以理解和执行“在 API 与数据库之间增加 Redis 缓存”这类局部修改,同时保留用户已经调整好的其他节点和布局。
+
+当前图表 MCP 工具只有三个:
-`create_diagram_memo` MCP 工具接收这层语义创建 IR:节点标识、名称、语义类型、容器关系与连接关系。EdgeEver 会生成连线标识、节点尺寸、坐标、确定性布局和架构边界几何信息,再编译为持久化 `DiagramDocument`。可选的布局方向只是提示,不是由 Agent 编排的几何数据。工具结果也只返回语义图,不返回编码后的持久化载荷。
+- `create_diagram_memo` 接收语义图:节点标识、名称、类型、容器关系与连接关系,以及可选的 `theme`、`structure` 和 `layout.direction`。服务端生成连线标识、节点尺寸、坐标、确定性布局和架构边界几何,再编译为持久化 `DiagramDocument`。布局方向只是编译提示,不写入持久化文档。返回语义图,不返回编码后的持久化载荷。
+- `get_diagram` 默认只返回语义图和笔记 revision,不含坐标与尺寸;只有 `includeLayout` 为 true 时才附带节点几何。
+- `update_diagram` 在同一工具上接收增量操作 `add_node` / `update_node` / `remove_node` / `add_edge` / `update_edge` / `remove_edge`。用 `expectedRevision` 防止并发覆盖,支持 `dryRun` 预览。默认 `reflow=preserve`,保留未受影响节点的已有布局;仅在明确要求整图重排时使用 `reflow=all`。移入系统边界或调整思维导图层级,是 `update_node` 的 `parentId`,不是单独的 MCP 工具。
-`get_diagram` 默认只返回语义图和笔记 revision,不包含坐标与尺寸;只有明确设置 `includeLayout` 时才附带节点几何信息。`update_diagram` 接收增加、更新、删除节点或连线的增量操作,使用 `expectedRevision` 防止并发覆盖,支持 `dryRun` 预览,并默认保留未受影响节点的已有布局。通用的 `update_memo` 不允许直接覆盖图表正文,避免绕过图表校验。
+通用的 `update_memo` 不允许直接覆盖图表正文。没有 `replace_diagram_ir`,也没有独立的校验或自动布局工具:校验发生在服务端应用操作时,布局由 `reflow` 控制。
-MCP 暴露小而明确的操作,包括读取图表、增加或更新节点、连接组件、移动到系统边界、校验变更和应用布局,而不是提供高风险的 `replace_diagram_ir`。推荐流程是:
+推荐流程是:
```text
-读取 IR
+get_diagram
→ AI 生成增量操作
- → 服务端校验类型、引用和容器关系
- → 生成变更预览
- → 用户确认
- → 应用操作并自动布局
- → 保存为新的历史版本
+ → 可选 dryRun 预览
+ → update_diagram(默认保留布局)
+ → 服务端校验类型、引用和容器关系后写入新版本
```
-为了降低模型上下文和误修改风险,后续可将 IR 的关注点进一步分为语义层、布局层和呈现层。AI 默认修改语义层,确定性的布局算法负责坐标;只有用户明确要求调整位置或外观时,才修改布局层或呈现层。
+AI 默认改语义层;确定性布局算法负责坐标。只有用户明确要求整图重排或调整外观时,才使用 `reflow=all` 或修改 `theme` / `structure`。
-IR 也可能产生负担:如果格式过度贴近 X6、语义过少、版本频繁变化,或者允许 AI 不经校验地覆盖整张图,它就会成为新的耦合点。因此,Schema 应保持小而稳定、可版本化、可校验,并支持增量操作。
+Schema 应保持小而稳定、可版本化、可校验,并继续走增量操作。如果格式过度贴近 X6、语义过少、版本频繁变化,或允许不经校验地覆盖整张图,IR 就会变成新的耦合点。
## 后续演进方向
如果要实现原生 App 完整编辑,应继续复用同一 IR,并单独设计触控选择、拖拽、连线、缩放、键盘避让和大图性能。是否复用 X6 WebView 或开发原生画布,应通过原型和性能测试决定,而不应改变已保存的数据格式。
-图形笔记的 HTML / 打印 / 微信复制若走通用富文本管道,仍会快照 TipTap HTML 而不是 X6 画布。应先让这些导出与只读 X6 快照对齐,再考虑改动 Markdown 信封。
+图形笔记的 HTML / 打印 / 微信复制若走通用富文本管道,仍会快照 TipTap HTML 而不是 X6 画布。原生端的图片分享同样如此。应先让这些导出与只读 X6 快照对齐,再考虑改动 Markdown 信封。图表编辑器里的 PNG / SVG 导出已经直接来自 X6。
diff --git a/packages/shared/src/diagram-palette.ts b/packages/shared/src/diagram-palette.ts
index 68905926..4cfb1340 100644
--- a/packages/shared/src/diagram-palette.ts
+++ b/packages/shared/src/diagram-palette.ts
@@ -9,25 +9,117 @@ export type DiagramColorStrip = {
colors: readonly [string, string, string, string, string, string];
};
-export const DIAGRAM_COLOR_STRIPS: Record<
- "brand" | "mint" | "wa" | "island" | "rose" | "sun" | "cosmos" | "tea" | "macaron" | "naive",
- DiagramColorStrip
+type DiagramThemeDefinition = {
+ id: Exclude<ReturnType<typeof resolveDiagramTheme>, never>;
+ group: "vivid" | "classic";
+ colors: readonly [string, string, string, string, string, string];
+ lightCanvas: string;
+ darkCanvas: string;
+ accent: string;
+};
+
+export const DIAGRAM_THEME_DEFINITIONS: Record<
+ "brand" | "cosmos" | "dune" | "slate" | "prism" | "sunrise" | "marine" | "blossom" | "mint" | "macaron",
+ DiagramThemeDefinition
> = {
- brand: { id: "brand", group: "classic", colors: ["#E7F6EF", "#9FDBC4", "#16A06E", "#12845B", "#0F5C42", "#173B2E"] },
- sun: { id: "sun", group: "vivid", colors: ["#F7E27A", "#C6F07A", "#FFFFFF", "#C084FC", "#60A5FA", "#1F2937"] },
- wa: { id: "wa", group: "vivid", colors: ["#FFFFFF", "#FFB4A2", "#FF8A4C", "#7DD3FC", "#3B82F6", "#1E3A8A"] },
- island: { id: "island", group: "classic", colors: ["#F3D5C4", "#D4A276", "#B08968", "#A3A882", "#7D8B69", "#4A5D4E"] },
- rose: { id: "rose", group: "vivid", colors: ["#FDE8EF", "#F8C1D4", "#F48FB1", "#EC407A", "#C2185B", "#7A1040"] },
- mint: { id: "mint", group: "vivid", colors: ["#FFFFFF", "#A5F3FC", "#5EEAD4", "#2DD4BF", "#0F9B8E", "#115E59"] },
- cosmos: { id: "cosmos", group: "classic", colors: ["#D6DCE5", "#8BBAD4", "#4D86B0", "#1E4E7A", "#163A5F", "#0B1F33"] },
- tea: { id: "tea", group: "classic", colors: ["#D8E2C8", "#B4C49A", "#7A9A58", "#4F7A3C", "#2F5D32", "#1A3C24"] },
- naive: { id: "naive", group: "vivid", colors: ["#F8C8D4", "#E45A7C", "#8BB4F0", "#4F6FCF", "#F5EED8", "#2D2A32"] },
- macaron: { id: "macaron", group: "vivid", colors: ["#D4B896", "#F5B89A", "#B8D4C8", "#F0EDE4", "#F2E39A", "#4A4A4A"] },
+ brand: {
+ id: "brand",
+ group: "classic",
+ colors: ["#16A06E", "#059669", "#0D9488", "#10B981", "#047857", "#065F46"],
+ lightCanvas: "#F8FAF9",
+ darkCanvas: "#101311",
+ accent: "#16A06E",
+ },
+ cosmos: {
+ id: "cosmos",
+ group: "classic",
+ colors: ["#2563EB", "#0284C7", "#4F46E5", "#0D9488", "#3B82F6", "#1D4ED8"],
+ lightCanvas: "#F8FAFC",
+ darkCanvas: "#0F1318",
+ accent: "#2563EB",
+ },
+ dune: {
+ id: "dune",
+ group: "classic",
+ colors: ["#C2410C", "#D97706", "#B45309", "#A16207", "#78350F", "#9A3412"],
+ lightCanvas: "#FAF8F5",
+ darkCanvas: "#151311",
+ accent: "#B45309",
+ },
+ slate: {
+ id: "slate",
+ group: "classic",
+ colors: ["#475569", "#52525B", "#4B5563", "#334155", "#64748B", "#1E293B"],
+ lightCanvas: "#F8F9FA",
+ darkCanvas: "#121416",
+ accent: "#475569",
+ },
+ prism: {
+ id: "prism",
+ group: "vivid",
+ colors: ["#E11D48", "#EA580C", "#D97706", "#059669", "#2563EB", "#7C3AED"],
+ lightCanvas: "#FAFAFA",
+ darkCanvas: "#111215",
+ accent: "#6366F1",
+ },
+ sunrise: {
+ id: "sunrise",
+ group: "vivid",
+ colors: ["#E11D48", "#F97316", "#F59E0B", "#D97706", "#DC2626", "#EA580C"],
+ lightCanvas: "#FFFDF7",
+ darkCanvas: "#16130E",
+ accent: "#EA580C",
+ },
+ marine: {
+ id: "marine",
+ group: "vivid",
+ colors: ["#0284C7", "#06B6D4", "#0D9488", "#2563EB", "#0891B2", "#1D4ED8"],
+ lightCanvas: "#F5FAFD",
+ darkCanvas: "#0C1318",
+ accent: "#0284C7",
+ },
+ blossom: {
+ id: "blossom",
+ group: "vivid",
+ colors: ["#DB2777", "#C026D3", "#9333EA", "#E11D48", "#BE185D", "#7C3AED"],
+ lightCanvas: "#FDF8FA",
+ darkCanvas: "#160F14",
+ accent: "#DB2777",
+ },
+ mint: {
+ id: "mint",
+ group: "vivid",
+ colors: ["#0D9488", "#059669", "#10B981", "#0891B2", "#16A34A", "#047857"],
+ lightCanvas: "#F5FAF8",
+ darkCanvas: "#0D1512",
+ accent: "#0D9488",
+ },
+ macaron: {
+ id: "macaron",
+ group: "vivid",
+ colors: ["#EC4899", "#FB923C", "#EAB308", "#10B981", "#38BDF8", "#8B5CF6"],
+ lightCanvas: "#FAF9F8",
+ darkCanvas: "#131316",
+ accent: "#EC4899",
+ },
};
+export const DIAGRAM_COLOR_STRIPS: Record<
+ "brand" | "cosmos" | "dune" | "slate" | "prism" | "sunrise" | "marine" | "blossom" | "mint" | "macaron",
+ DiagramColorStrip
+> = Object.fromEntries(
+ Object.entries(DIAGRAM_THEME_DEFINITIONS).map(([id, def]) => [
+ id,
+ { id: def.id, group: def.group, colors: def.colors },
+ ]),
+) as Record<
+ "brand" | "cosmos" | "dune" | "slate" | "prism" | "sunrise" | "marine" | "blossom" | "mint" | "macaron",
+ DiagramColorStrip
+>;
+
export const DIAGRAM_THEME_GROUPS = {
- vivid: ["sun", "wa", "rose", "mint", "naive", "macaron"],
- classic: ["brand", "island", "tea", "cosmos"],
+ vivid: ["prism", "sunrise", "marine", "blossom", "mint", "macaron"],
+ classic: ["brand", "cosmos", "dune", "slate"],
} as const;
const hexToRgb = (hex: string) => {
@@ -57,33 +149,39 @@ const luminance = (hex: string) => {
return r * 0.2126 + g * 0.7152 + b * 0.0722;
};
-const readableText = (fill: string) => (luminance(fill) > 0.32 ? "#1C1917" : "#FFFCF8");
+const readableText = (fill: string) => (luminance(fill) > 0.35 ? "#1C1917" : "#FFFCF8");
export const diagramThemeSwatches = (theme?: DiagramTheme) =>
DIAGRAM_COLOR_STRIPS[resolveDiagramTheme(theme)].colors;
export const diagramThemeUsesBranchColors = (theme?: DiagramTheme) => resolveDiagramTheme(theme) !== "brand";
+const resolveBranchEdge = (color: string, appearance: DiagramAppearance) => {
+ const lum = luminance(color);
+ if (appearance === "dark") {
+ return lum < 0.22 ? mix(color, "#FFFFFF", Math.max(0.35, (0.30 - lum) * 1.6)) : color;
+ }
+ return lum > 0.26 ? mix(color, "#18181B", Math.max(0.24, (lum - 0.20) * 0.9)) : color;
+};
+
export const buildDiagramBranchTints = (theme: DiagramTheme | undefined, appearance: DiagramAppearance) => {
const colors = diagramThemeSwatches(theme);
return colors.map((color) => {
- const fill = appearance === "dark" ? mix(color, "#101418", 0.55) : mix(color, "#FFFFFF", luminance(color) > 0.82 ? 0.08 : 0.72);
+ const edge = resolveBranchEdge(color, appearance);
+ const fill = appearance === "dark" ? mix(color, "#121518", 0.72) : mix(color, "#FFFFFF", 0.84);
return {
fill,
- stroke: appearance === "dark" ? mix(color, "#FFFFFF", 0.18) : mix(color, "#1C1917", 0.22),
+ stroke: appearance === "dark" ? mix(edge, "#FFFFFF", 0.15) : mix(edge, "#1C1917", 0.12),
text: readableText(fill),
- edge: color === "#FFFFFF" ? colors[2] : color,
+ edge,
};
});
};
export const buildDiagramPalette = (theme: DiagramTheme | undefined, appearance: DiagramAppearance) => {
const resolved = resolveDiagramTheme(theme);
- const strip = DIAGRAM_COLOR_STRIPS[resolved];
- const colors = strip.colors;
- const accent = colors.find((color) => luminance(color) < 0.55 && luminance(color) > 0.08) ?? colors[2];
- const deepest = colors[colors.length - 1];
- const lightest = colors[0];
+ const def = DIAGRAM_THEME_DEFINITIONS[resolved];
+ const accent = def.accent;
if (resolved === "brand") {
if (appearance === "dark") {
return {
@@ -111,27 +209,29 @@ export const buildDiagramPalette = (theme: DiagramTheme | undefined, appearance:
};
}
if (appearance === "dark") {
+ const edge = resolveBranchEdge(accent, "dark");
return {
- topicFill: mix(deepest, "#0B0D0C", 0.2),
- topicText: "#F8FAFC",
- nodeFill: mix(deepest, "#101418", 0.45),
+ topicFill: accent,
+ topicText: readableText(accent),
+ nodeFill: mix(accent, "#101418", 0.78),
nodeText: "#E8EEF2",
- nodeStroke: mix(accent, "#101418", 0.55),
- topicStroke: mix(accent, "#FFFFFF", 0.28),
- mindMapEdge: accent,
- flowEdge: mix(accent, "#FFFFFF", 0.12),
- canvas: "#101311",
+ nodeStroke: mix(edge, "#FFFFFF", 0.15),
+ topicStroke: mix(accent, "#FFFFFF", 0.25),
+ mindMapEdge: edge,
+ flowEdge: mix(accent, "#FFFFFF", 0.15),
+ canvas: def.darkCanvas,
};
}
+ const edge = resolveBranchEdge(accent, "light");
return {
topicFill: accent,
topicText: readableText(accent),
- nodeFill: mix(lightest, "#FFFFFF", luminance(lightest) > 0.9 ? 0.2 : 0.55),
- nodeText: mix(deepest, "#1C1917", 0.15),
- nodeStroke: mix(accent, "#FFFFFF", 0.62),
- topicStroke: mix(accent, "#1C1917", 0.18),
- mindMapEdge: accent,
- flowEdge: mix(accent, "#1C1917", 0.12),
- canvas: mix(lightest, "#FFFFFF", 0.72),
+ nodeFill: mix(accent, "#FFFFFF", 0.88),
+ nodeText: mix(def.colors[def.colors.length - 1], "#1C1917", 0.35),
+ nodeStroke: mix(edge, "#FFFFFF", 0.50),
+ topicStroke: mix(accent, "#1C1917", 0.15),
+ mindMapEdge: edge,
+ flowEdge: mix(accent, "#1C1917", 0.15),
+ canvas: def.lightCanvas,
};
};
diff --git a/packages/shared/src/diagram.ts b/packages/shared/src/diagram.ts
index 2ec6287f..5a23fb91 100644
--- a/packages/shared/src/diagram.ts
+++ b/packages/shared/src/diagram.ts
@@ -26,11 +26,12 @@ export type DiagramNodeShape =
| "boundary";
export type DiagramEdgeKind = "dependency" | "request" | "async" | "data";
export const DIAGRAM_SELECTABLE_THEMES = [
- "brand", "sun", "wa", "island", "rose", "mint", "cosmos", "tea", "naive", "macaron",
+ "brand", "cosmos", "dune", "slate", "prism", "sunrise", "marine", "blossom", "mint", "macaron",
] as const;
export const DIAGRAM_THEMES = [
"brand", "ocean", "ink", "classic", "sky", "sunset", "violet", "rose", "sand", "slate", "aurora", "mono",
"sun", "wa", "island", "mint", "cosmos", "tea", "naive", "macaron", "paper",
+ "dune", "prism", "sunrise", "marine", "blossom",
] as const;
export type DiagramTheme = (typeof DIAGRAM_THEMES)[number];
export const DIAGRAM_SELECTABLE_STRUCTURES = [
@@ -57,15 +58,24 @@ export type DiagramStructure = (typeof DIAGRAM_STRUCTURES)[number];
const THEME_ALIASES: Partial<Record<DiagramTheme, typeof DIAGRAM_SELECTABLE_THEMES[number]>> = {
ocean: "brand",
ink: "brand",
- classic: "sun",
+ paper: "brand",
+ classic: "sunrise",
+ sunset: "sunrise",
+ sun: "sunrise",
+ wa: "marine",
+ island: "dune",
+ sand: "dune",
+ tea: "slate",
+ mono: "slate",
+ slate: "slate",
sky: "cosmos",
- sunset: "sun",
- violet: "rose",
- sand: "island",
- slate: "cosmos",
+ cosmos: "cosmos",
+ rose: "blossom",
+ violet: "blossom",
aurora: "mint",
- mono: "cosmos",
- paper: "brand",
+ naive: "prism",
+ mint: "mint",
+ macaron: "macaron",
};
export const resolveDiagramTheme = (theme?: DiagramTheme): typeof DIAGRAM_SELECTABLE_THEMES[number] => {
diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.ts
index 99cf0948..309314d0 100644
--- a/packages/shared/src/i18n/en-US.ts
+++ b/packages/shared/src/i18n/en-US.ts
@@ -367,17 +367,23 @@ export const enUS = {
themeGroupVivid: "Bright",
themeGroupClassic: "Quiet",
themeBrand: "Forest",
+ themeCosmos: "Cosmos",
+ themeDune: "Dune",
+ themeSlate: "Slate",
+ themePrism: "Prism",
+ themeSunrise: "Sunrise",
+ themeMarine: "Marine",
+ themeBlossom: "Blossom",
+ themeMint: "Mint",
+ themeMacaron: "Macaron",
themeInk: "Ink",
themePaper: "Paper",
themeSun: "Gleam",
themeWa: "Tide",
themeIsland: "Clay",
themeRose: "Blush",
- themeMint: "Brook",
- themeCosmos: "Night",
themeTea: "Sprout",
themeNaive: "Fizz",
- themeMacaron: "Pastel",
structure: "Shape",
structureGroupMap: "Mind map",
structureGroupLogic: "Logic chart",
diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.ts
index cf0635db..3bb7a71d 100644
--- a/packages/shared/src/i18n/zh-CN.ts
+++ b/packages/shared/src/i18n/zh-CN.ts
@@ -367,17 +367,23 @@ export const zhCN = {
themeGroupVivid: "鲜亮",
themeGroupClassic: "沉静",
themeBrand: "森绿",
+ themeCosmos: "夜航",
+ themeDune: "砂丘",
+ themeSlate: "玄砚",
+ themePrism: "光谱",
+ themeSunrise: "晨曦",
+ themeMarine: "海潮",
+ themeBlossom: "暮樱",
+ themeMint: "泠泉",
+ themeMacaron: "柔糖",
themeInk: "墨色",
themePaper: "纸色",
themeSun: "晴穗",
themeWa: "潮汐",
themeIsland: "陶岸",
themeRose: "绯雾",
- themeMint: "泠泉",
- themeCosmos: "夜航",
themeTea: "青芽",
themeNaive: "糖纸",
- themeMacaron: "软糖",
structure: "形状",
structureGroupMap: "思维导图",
structureGroupLogic: "逻辑图",