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 mindmap summary styles https://github.com/siyuan-note/siyuan/issues/19747
Daniel4eaa78ea0dff
diff --git a/app/appearance/themes/daylight/theme.css b/app/appearance/themes/daylight/theme.cssindex ef040ff3c0..9f87306ffc 100644--- a/app/appearance/themes/daylight/theme.css+++ b/app/appearance/themes/daylight/theme.css@@ -77,6 +77,12 @@--b3-mindmap-relation-selected-color: initial;--b3-mindmap-relation-selected-width: auto;+ /* 思维导图概要线:线宽使用正数或 px,选中线宽为 auto 时在普通线宽上增加 1,打印使用普通样式 */+ --b3-mindmap-summary-color: var(--b3-border-color);+ --b3-mindmap-summary-width: 1.5;+ --b3-mindmap-summary-selected-color: var(--b3-theme-primary);+ --b3-mindmap-summary-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 66d77e42c0..4448b13ea5 100644--- a/app/appearance/themes/midnight/theme.css+++ b/app/appearance/themes/midnight/theme.css@@ -76,6 +76,12 @@--b3-mindmap-relation-selected-color: initial;--b3-mindmap-relation-selected-width: auto;+ /* 思维导图概要线:线宽使用正数或 px,选中线宽为 auto 时在普通线宽上增加 1,打印使用普通样式 */+ --b3-mindmap-summary-color: var(--b3-border-color);+ --b3-mindmap-summary-width: 1.5;+ --b3-mindmap-summary-selected-color: var(--b3-theme-primary);+ --b3-mindmap-summary-selected-width: auto;+/* 菜单 */--b3-menu-background: var(--b3-theme-background);--b3-menu-icon-color: rgba(255, 255, 255, .7);diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.tsindex 544f6db963..a2388298ee 100644--- a/app/src/protyle/render/listMindmap/model.test.ts+++ b/app/src/protyle/render/listMindmap/model.test.ts@@ -2921,6 +2921,52 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,check.ok(summaryLabel.textContent.startsWith("<script>"));check.equal(summaryLabel.querySelector("script"), null);const savedSummary = api.readListMindmap(summaryList).metadata.summaries[0];+ const summaryContext = summaryHost.querySelector("canvas").getContext("2d");+ const setSummaryTheme = (property: string, value: string) =>+ summaryHost.style.setProperty(`--b3-mindmap-summary-${property}`, value);+ const checkSummaryStyle = (color: string, width: number) => {+ summaryView.draw();+ check.equal(summaryContext.strokeStyle, color);+ check.equal(summaryContext.lineWidth, width);+ };+ summaryHost.style.setProperty("--b3-border-color", "#123456");+ summaryHost.style.setProperty("--b3-theme-primary", "#abcdef");+ summaryView.selectedSummary = undefined;+ checkSummaryStyle("#123456", 1.5);+ summaryView.selectedSummary = "summary";+ checkSummaryStyle("#abcdef", 2.5);+ setSummaryTheme("color", "var(--b3-theme-primary)");+ setSummaryTheme("width", "3px");+ summaryView.selectedSummary = undefined;+ checkSummaryStyle("#abcdef", 3);+ summaryView.model.metadata.summaries[0].color = "#445566";+ checkSummaryStyle("#445566", 3);+ summaryView.selectedSummary = "summary";+ checkSummaryStyle("#abcdef", 4);+ setSummaryTheme("selected-color", "#778899");+ setSummaryTheme("selected-width", "6");+ checkSummaryStyle("#778899", 6);+ summaryView.options.printLayout = true;+ checkSummaryStyle("#445566", 3);+ summaryView.options.printLayout = false;+ summaryView.printTransform = {scale: 1, offsetX: 0, offsetY: 0};+ checkSummaryStyle("#445566", 3);+ summaryView.printTransform = undefined;+ setSummaryTheme("selected-color", "invalid-color");+ for (const width of ["auto", "0", "-2", "Infinity", "2em", "3px-invalid"]) {+ setSummaryTheme("selected-width", width);+ checkSummaryStyle("#abcdef", 4);+ }+ delete summaryView.model.metadata.summaries[0].color;+ summaryView.selectedSummary = undefined;+ setSummaryTheme("color", "invalid-color");+ setSummaryTheme("width", "-1");+ checkSummaryStyle("#123456", 1.5);+ ["color", "width", "selected-color", "selected-width"].forEach(property =>+ summaryHost.style.removeProperty(`--b3-mindmap-summary-${property}`));+ summaryHost.style.removeProperty("--b3-border-color");+ summaryHost.style.removeProperty("--b3-theme-primary");+ summaryView.draw();const originalIDs = ids(summaryList);api.retagMindmapBranch(summaryList, true);const plain = api.convertListMindmapToList(summaryList, "UL2OL", lute);diff --git a/app/src/protyle/render/listMindmap/view.ts b/app/src/protyle/render/listMindmap/view.tsindex 6f1f5a1042..335e942de3 100644--- a/app/src/protyle/render/listMindmap/view.ts+++ b/app/src/protyle/render/listMindmap/view.ts@@ -1017,7 +1017,8 @@ export class ListMindmapView {input.select();}- private drawSummaries(context: CanvasRenderingContext2D, resolveColor: (color: string) => string, primary: string) {+ private drawSummaries(context: CanvasRenderingContext2D,+ resolveStyle: (color: string, selected: boolean) => {color: string, width: number}) {(this.model.metadata.summaries || []).forEach(summary => {const position = this.summaryPositions.get(summary.id);const element = this.summaryElements.get(summary.id);@@ -1037,8 +1038,9 @@ export class ListMindmapView {path.moveTo(x, (top + bottom) / 2);path.lineTo(labelX - 6, (top + bottom) / 2);const selected = this.selectedSummary === summary.id && !this.printTransform && !this.options.printLayout;- context.strokeStyle = selected ? primary : resolveColor(summary.color);- context.lineWidth = selected ? 2.5 : 1.5;+ const style = resolveStyle(summary.color, selected);+ context.strokeStyle = style.color;+ context.lineWidth = style.width;context.setLineDash([]);context.stroke(path);this.linePaths.push({id: summary.id, relation: false, summary: true, path});@@ -1377,7 +1379,7 @@ 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 readLineStyles = (type: "line" | "relation") => ["", "hover-", "selected-"].map(state => {+ const readLineStyles = (type: "line" | "relation" | "summary", states = ["", "hover-", "selected-"]) => states.map(state => {const prefix = `--b3-mindmap-${type}-${state}`;const width = Number(theme.getPropertyValue(`${prefix}width`).trim().replace(/px$/, ""));return {@@ -1387,6 +1389,7 @@ export class ListMindmapView {});const lineStyles = readLineStyles("line");const relationStyles = readLineStyles("relation");+ const summaryStyles = readLineStyles("summary", ["", "selected-"]);const colors = new Map<string, string>();const resolveColor = (value: string, fallback: string) => {const key = `${fallback}\n${value || ""}`;@@ -1476,7 +1479,14 @@ export class ListMindmapView {}});this.drawRelationPreview(context, resolveColor(relationStyles[0].color, primary), relationStyles[0].width || 1.5);- this.drawSummaries(context, color => resolveColor(color, defaultLine), primary);+ this.drawSummaries(context, (color, selected) => {+ const baseWidth = summaryStyles[0].width || 1.5;+ return {+ color: selected ? resolveColor(summaryStyles[1].color, primary) :+ resolveColor(color, resolveColor(summaryStyles[0].color, defaultLine)),+ width: selected ? summaryStyles[1].width ?? baseWidth + 1 : baseWidth,+ };+ });this.renderRouteControls();}