An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: Support CSS variables for list mindmap connector styles https://github.com/siyuan-note/siyuan/issues/19747
Daniel1c634c195bf7
diff --git a/app/appearance/themes/daylight/theme.css b/app/appearance/themes/daylight/theme.cssindex aca35b1d83..e5c5963ab2 100644--- a/app/appearance/themes/daylight/theme.css+++ b/app/appearance/themes/daylight/theme.css@@ -60,6 +60,15 @@--b3-list-hover: rgba(0, 0, 0, .075);--b3-list-icon-hover: rgba(33, 34, 36, .1);+ /* 列表脑图父子连线:线宽使用正数或 px,表示缩放前的像素值;节点自定义样式优先于普通状态 */+ --b3-list-mindmap-line-color: var(--b3-border-color);+ --b3-list-mindmap-line-width: 1.5;+ /* 选中状态优先于悬停状态;initial 沿用普通配色,auto 根据普通线宽和缩放加粗 */+ --b3-list-mindmap-line-hover-color: initial;+ --b3-list-mindmap-line-hover-width: auto;+ --b3-list-mindmap-line-selected-color: initial;+ --b3-list-mindmap-line-selected-width: auto;+/* 菜单 */--b3-menu-background: var(--b3-theme-background);--b3-menu-icon-color: rgba(0, 0, 0, .6);diff --git a/app/appearance/themes/midnight/theme.css b/app/appearance/themes/midnight/theme.cssindex 8c3fec5dc7..7d40914a3c 100644--- a/app/appearance/themes/midnight/theme.css+++ b/app/appearance/themes/midnight/theme.css@@ -59,6 +59,15 @@--b3-list-hover: rgba(255, 255, 255, .10);--b3-list-icon-hover: rgba(201, 209, 217, .1);+ /* 列表脑图父子连线:线宽使用正数或 px,表示缩放前的像素值;节点自定义样式优先于普通状态 */+ --b3-list-mindmap-line-color: var(--b3-border-color);+ --b3-list-mindmap-line-width: 1.5;+ /* 选中状态优先于悬停状态;initial 沿用普通配色,auto 根据普通线宽和缩放加粗 */+ --b3-list-mindmap-line-hover-color: initial;+ --b3-list-mindmap-line-hover-width: auto;+ --b3-list-mindmap-line-selected-color: initial;+ --b3-list-mindmap-line-selected-width: auto;+/* 菜单 */--b3-menu-background: var(--b3-theme-background);--b3-menu-icon-color: rgba(255, 255, 255, .7);diff --git a/app/src/assets/scss/protyle/_list-mindmap.scss b/app/src/assets/scss/protyle/_list-mindmap.scssindex 906016ae0f..32160745db 100644--- a/app/src/assets/scss/protyle/_list-mindmap.scss+++ b/app/src/assets/scss/protyle/_list-mindmap.scss@@ -561,15 +561,15 @@&__node:not(.list-mindmap__node--root) {> .list-mindmap__fold {- top: calc(100% - 8px);+ top: calc(100% - 6px);}> .list-mindmap__add-child {- top: calc(100% - 8px);+ top: calc(100% - 6px);}> .list-mindmap__add-bridge {- bottom: -12px;+ bottom: -14px;// 补齐右下角斜向移出的路径,避免鼠标先落到连线上而收起操作按钮。&::before {@@ -578,7 +578,7 @@right: 100%;bottom: 0;width: 12px;- height: 12px;+ height: 14px;}}}diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.tsindex 9729c2c39c..1952033893 100644--- a/app/src/protyle/render/listMindmap/model.test.ts+++ b/app/src/protyle/render/listMindmap/model.test.ts@@ -1138,6 +1138,84 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,view.update(model);check.equal(nodeElement(beta).style.backgroundColor, "", "default removes the node color override");check.equal(nodeElement(beta).style.color, "", "default removes the node text color override");+ await settle();+ const lineContext = host.querySelector("canvas").getContext("2d");+ const themedEdge = view.edges[view.edges.length - 1].to;+ const originalRootStyle = model.metadata.nodes[model.root.id];+ const originalEdgeStyle = model.metadata.nodes[themedEdge];+ const originalScale = view.scale;+ const themedProperties = ["color", "width", "hover-color", "hover-width", "selected-color", "selected-width"];+ const setLineTheme = (property: string, value: string) =>+ host.style.setProperty(`--b3-list-mindmap-line-${property}`, value);+ const checkLine = (color: string, width: number) => {+ view.draw();+ check.equal(lineContext.strokeStyle, color);+ check.equal(lineContext.lineWidth, width);+ };+ model.metadata.nodes[model.root.id] = {};+ model.metadata.nodes[themedEdge] = {};+ view.clearSelection();+ view.setHoveredLine();+ host.style.setProperty("--b3-border-color", "#314159");+ view.scale = 0.5;+ checkLine("#314159", 1.5);+ view.setHoveredLine(`edge:${themedEdge}`);+ checkLine("#314159", 4.5);+ view.selectedEdge = themedEdge;+ checkLine("#314159", 5.5);+ view.setHoveredLine();+ checkLine("#314159", 2.5);+ view.clearSelection();+ setLineTheme("color", "var(--b3-font-background1)");+ setLineTheme("width", "2px");+ checkLine("#334455", 2);+ setLineTheme("hover-color", "#445566");+ setLineTheme("hover-width", "4");+ setLineTheme("selected-color", "#778899");+ setLineTheme("selected-width", "6px");+ view.setHoveredLine(`edge:${themedEdge}`);+ checkLine("#445566", 4);+ view.selectedEdge = themedEdge;+ checkLine("#778899", 6);+ view.setHoveredLine();+ checkLine("#778899", 6);+ view.clearSelection();+ model.metadata.nodes[model.root.id] = {lineColor: "#aabbcc", lineWidth: 3};+ checkLine("#aabbcc", 3);+ model.metadata.nodes[themedEdge] = {lineColor: "#112233", lineWidth: 5};+ checkLine("#112233", 5);+ view.setHoveredLine(`edge:${themedEdge}`);+ checkLine("#445566", 4);+ setLineTheme("hover-color", "invalid-color");+ for (const width of ["auto", "0", "-2", "Infinity", "2em", "3px-invalid"]) {+ setLineTheme("hover-width", width);+ checkLine("#112233", 8);+ }+ view.selectedEdge = themedEdge;+ setLineTheme("selected-color", "initial");+ setLineTheme("selected-width", "auto");+ checkLine("#112233", 9);+ view.clearSelection();+ view.setHoveredLine();+ model.metadata.nodes[model.root.id] = {};+ model.metadata.nodes[themedEdge] = {};+ setLineTheme("color", "invalid-color");+ setLineTheme("width", "-1");+ checkLine("#314159", 1.5);+ view.scale = originalScale;+ model.metadata.nodes[model.root.id] = originalRootStyle;+ model.metadata.nodes[themedEdge] = originalEdgeStyle;+ themedProperties.forEach(property => host.style.removeProperty(`--b3-list-mindmap-line-${property}`));+ host.style.removeProperty("--b3-border-color");+ view.draw();+ const themedNodeBounds = nodeElement(themedEdge).getBoundingClientRect();+ const themedPosition = view.positions.get(themedEdge);+ const underlineY = viewport.getBoundingClientRect().top + view.offsetY ++ (themedPosition.y + themedPosition.height) * view.scale;+ check.ok(Math.abs(underlineY - themedNodeBounds.bottom - 3 * view.scale) < 0.1,+ "node backgrounds leave a gap above their underline");+ check.ok(Math.abs(centerPoint(addChildButton(themedEdge)).y - underlineY) <= view.scale + 1,+ "node controls remain aligned with the underline");host.style.setProperty("--b3-font-background1", "#123456");model.metadata.nodes[model.root.id] = {lineColor: "var(--b3-font-background1)"};view.update(model);diff --git a/app/src/protyle/render/listMindmap/view.ts b/app/src/protyle/render/listMindmap/view.tsindex b33b99b606..478179785e 100644--- a/app/src/protyle/render/listMindmap/view.ts+++ b/app/src/protyle/render/listMindmap/view.ts@@ -757,7 +757,7 @@ export class ListMindmapView {element.hidden = !position;if (position) {element.style.left = `${position.x}px`;- element.style.top = `${position.y - 1}px`;+ element.style.top = `${position.y - (id === this.model.root.id ? 1 : 3)}px`;}});// 编辑、折叠或调整路径时固定操作节点,避免整棵树随布局边界跳动。@@ -1102,9 +1102,16 @@ export class ListMindmapView {const theme = getComputedStyle(this.options.host);const defaultLine = theme.getPropertyValue("--b3-border-color").trim() || "#a8adb5";const primary = theme.getPropertyValue("--b3-theme-primary").trim() || "#3574f0";+ const lineStyles = ["", "hover-", "selected-"].map(state => {+ const width = Number(theme.getPropertyValue(`--b3-list-mindmap-line-${state}width`).trim().replace(/px$/, ""));+ return {+ color: theme.getPropertyValue(`--b3-list-mindmap-line-${state}color`).trim(),+ width: Number.isFinite(width) && width > 0 ? width : undefined,+ };+ });const colors = new Map<string, string>();const resolveColor = (value: string, fallback: string) => {- const key = value || fallback;+ const key = `${fallback}\n${value || ""}`;if (!colors.has(key)) {this.colorProbe.style.color = fallback;if (value) {@@ -1132,9 +1139,14 @@ export class ListMindmapView {path.lineTo(to.x + to.width, endY);this.linePaths.push({id: edge.to, relation: false, path});context.beginPath();- context.strokeStyle = resolveColor(style.lineColor, defaultLine);- context.lineWidth = (style.lineWidth || 1.5) + (this.selectedEdge === edge.to ? 1 : 0) +- (this.hoveredLine === `edge:${edge.to}` ? 1.5 / this.scale : 0);+ const selected = this.selectedEdge === edge.to;+ const hovered = this.hoveredLine === `edge:${edge.to}`;+ const baseColor = resolveColor(style.lineColor, resolveColor(lineStyles[0].color, defaultLine));+ const baseWidth = style.lineWidth || lineStyles[0].width || 1.5;+ // 选中状态优先于悬停状态,未配置状态样式时保留节点配色和随缩放调整的加粗效果。+ const stateStyle = selected ? lineStyles[2] : hovered ? lineStyles[1] : undefined;+ context.strokeStyle = resolveColor(stateStyle?.color, baseColor);+ context.lineWidth = stateStyle?.width ?? baseWidth + (selected ? 1 : 0) + (hovered ? 1.5 / this.scale : 0);context.setLineDash(style.lineDash ? [6, 4] : []);context.stroke(path);});