An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Adapt mind map text to dark canvas colors https://github.com/siyuan-note/siyuan/issues/20800
Daniel62b3bc5b481b
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.syindex d5ea78a7fe..d7586a3a78 100644--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy@@ -8,7 +8,7 @@"title": "Formatting elements","title-img": "background-color:#269;background-image: linear-gradient(white 2px, transparent 2px),linear-gradient(90deg, white 2px, transparent 2px),linear-gradient(rgba(255,255,255,.3) 1px, transparent 1px),linear-gradient(90deg, rgba(255,255,255,.3) 1px, transparent 1px);background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;background-position:-2px -2px, -2px -2px, -1px -1px, -1px -1px;","type": "doc",- "updated": "20261024194010"+ "updated": "20261024195223"},"Children": [{@@ -2052,7 +2052,7 @@"HeadingLevel": 2,"Properties": {"id": "20210104091509-v1x69oc",- "updated": "20261024194010"+ "updated": "20261024195223"},"Children": [{@@ -2503,7 +2503,7 @@"Type": "NodeHeading","Properties": {"id": "20261024161816-kuq9j6z",- "updated": "20261024174551"+ "updated": "20261024195223"},"Children": [{@@ -2605,7 +2605,7 @@"Type": "NodeParagraph","Properties": {"id": "20261022102848-11epv5y",- "updated": "20261024174551"+ "updated": "20261024195223"},"Children": [{@@ -2637,7 +2637,7 @@},{"Type": "NodeText",- "Data": " to choose from 47 color themes for the current map. Root and first-level nodes use colored backgrounds with white text; deeper nodes use transparent backgrounds with black text. Branch lines inherit their first-level color and use a consistent width. In orthogonal and rounded styles, overlapping root trunk segments are painted in node order, with later branches covering earlier ones."+ "Data": " to choose from 47 color themes for the current map. Root and first-level nodes use colored backgrounds with white text; deeper nodes use transparent backgrounds, with black or white text chosen automatically for the canvas color. Branch lines inherit their first-level color and use a consistent width. In orthogonal and rounded styles, overlapping root trunk segments are painted in node order, with later branches covering earlier ones."}]},diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.syindex f7ee4e46ac..7bde58cb6c 100644--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy@@ -8,7 +8,7 @@"title": "排版元素","title-img": "background-color: hsl(2, 57%, 40%);background-image: repeating-linear-gradient(transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(270deg, transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(125deg, transparent, transparent 2px, rgba(0,0,0,.2) 2px, rgba(0,0,0,.2) 3px, transparent 3px, transparent 5px, rgba(0,0,0,.2) 5px);","type": "doc",- "updated": "20261024194010"+ "updated": "20261024195223"},"Children": [{@@ -2055,7 +2055,7 @@"HeadingLevel": 2,"Properties": {"id": "20210104091228-wdpx6ev",- "updated": "20261024194010"+ "updated": "20261024195223"},"Children": [{@@ -2403,7 +2403,7 @@"Type": "NodeHeading","Properties": {"id": "20261024161816-ucbq2tw",- "updated": "20261024174551"+ "updated": "20261024195223"},"Children": [{@@ -2491,7 +2491,7 @@"Type": "NodeParagraph","Properties": {"id": "20261022102848-idam1p2",- "updated": "20261024174551"+ "updated": "20261024195223"},"Children": [{@@ -2523,7 +2523,7 @@},{"Type": "NodeText",- "Data": " 中为当前导图选择 47 种配色主题。根节点和一级节点使用色卡背景及白色文字,二级及后续节点使用透明背景及黑色文字。后代连线继承所属一级分支的颜色,各层级连线粗细一致。折线和圆角折线的根节点主干按节点顺序叠加绘制,后绘制的分支颜色覆盖重叠部分。"+ "Data": " 中为当前导图选择 47 种配色主题。根节点和一级节点使用色卡背景及白色文字,二级及后续节点使用透明背景,并根据画布颜色自动选择黑色或白色文字。后代连线继承所属一级分支的颜色,各层级连线粗细一致。折线和圆角折线的根节点主干按节点顺序叠加绘制,后绘制的分支颜色覆盖重叠部分。"}]},diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.syindex 19e05bce7c..6481e919bd 100644--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy@@ -8,7 +8,7 @@"title": "排版元素","title-img": "background-color: hsl(2, 57%, 40%);background-image: repeating-linear-gradient(transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(270deg, transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(125deg, transparent, transparent 2px, rgba(0,0,0,.2) 2px, rgba(0,0,0,.2) 3px, transparent 3px, transparent 5px, rgba(0,0,0,.2) 5px);","type": "doc",- "updated": "20261024194010"+ "updated": "20261024195223"},"Children": [{@@ -2053,7 +2053,7 @@"HeadingLevel": 2,"Properties": {"id": "20211226122008-731sqd6",- "updated": "20261024194010"+ "updated": "20261024195223"},"Children": [{@@ -2401,7 +2401,7 @@"Type": "NodeHeading","Properties": {"id": "20261024161816-ia87ag4",- "updated": "20261024174551"+ "updated": "20261024195223"},"Children": [{@@ -2489,7 +2489,7 @@"Type": "NodeParagraph","Properties": {"id": "20261022102848-dz75ii8",- "updated": "20261024174551"+ "updated": "20261024195223"},"Children": [{@@ -2521,7 +2521,7 @@},{"Type": "NodeText",- "Data": " 中為目前心智圖選擇 47 種配色主題。根節點和一級節點使用色卡背景及白色文字,二級及後續節點使用透明背景及黑色文字。後代連線繼承所屬一級分支的顏色,各層級連線粗細一致。折線和圓角折線的根節點主幹依節點順序疊加繪製,後繪製的分支顏色覆蓋重疊部分。"+ "Data": " 中為目前心智圖選擇 47 種配色主題。根節點和一級節點使用色卡背景及白色文字,二級及後續節點使用透明背景,並依畫布顏色自動選擇黑色或白色文字。後代連線繼承所屬一級分支的顏色,各層級連線粗細一致。折線和圓角折線的根節點主幹依節點順序疊加繪製,後繪製的分支顏色覆蓋重疊部分。"}]},diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.syindex 5f357940b6..be17d9649f 100644--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy@@ -9,7 +9,7 @@"title": "書式要素","title-img": "background-color:#269;background-image: linear-gradient(white 2px, transparent 2px),linear-gradient(90deg, white 2px, transparent 2px),linear-gradient(rgba(255,255,255,.3) 1px, transparent 1px),linear-gradient(90deg, rgba(255,255,255,.3) 1px, transparent 1px);background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;background-position:-2px -2px, -2px -2px, -1px -1px, -1px -1px;","type": "doc",- "updated": "20261024194010"+ "updated": "20261024195223"},"Children": [{@@ -2177,7 +2177,7 @@"Properties": {"ID": "20240530101000-ch5e4vh","id": "20240530101000-1ev7xub",- "updated": "20261024194010"+ "updated": "20261024195223"},"Children": [{@@ -2604,7 +2604,7 @@"Type": "NodeHeading","Properties": {"id": "20261024161816-fjkvky7",- "updated": "20261024174551"+ "updated": "20261024195223"},"Children": [{@@ -2702,7 +2702,7 @@"Type": "NodeParagraph","Properties": {"id": "20261022102848-sbqeaum",- "updated": "20261024174551"+ "updated": "20261024195223"},"Children": [{@@ -2730,7 +2730,7 @@},{"Type": "NodeText",- "Data": " で、現在のマップに 47 種類の配色テーマを選択できます。ルートと第 1 階層のノードは色付きの背景に白い文字を使い、第 2 階層以降は透明な背景に黒い文字を使います。子孫の接続線は所属する第 1 階層の色を継承し、すべての階層で同じ太さを使います。直角と角丸の接続線では、ルートの幹線をノード順に重ねて描画し、後のブランチの色で重なる部分を上書きします。"+ "Data": " で、現在のマップに 47 種類の配色テーマを選択できます。ルートと第 1 階層のノードは色付きの背景に白い文字を使い、第 2 階層以降は透明な背景を使い、キャンバスの色に応じて黒または白の文字を自動で選びます。子孫の接続線は所属する第 1 階層の色を継承し、すべての階層で同じ太さを使います。直角と角丸の接続線では、ルートの幹線をノード順に重ねて描画し、後のブランチの色で重なる部分を上書きします。"}]},diff --git a/app/src/protyle/render/listMindmap/appearance.test.ts b/app/src/protyle/render/listMindmap/appearance.test.tsindex c21e26b098..f92ef6011c 100644--- a/app/src/protyle/render/listMindmap/appearance.test.ts+++ b/app/src/protyle/render/listMindmap/appearance.test.ts@@ -41,7 +41,7 @@ test("appearance validates optional colors and rejects unsupported formats", ()}});-test("all 47 reference palettes remain selectable after reload with their fixed level foregrounds", () => {+test("all 47 reference palettes retain white filled nodes and adapt transparent node text to the canvas", () => {assert.equal(LIST_MINDMAP_PALETTES.length, 47);assert.equal(new Set(LIST_MINDMAP_PALETTES.map(preset => preset.id)).size, 47);assert.equal(new Set(LIST_MINDMAP_PALETTES.map(preset => JSON.stringify(preset.colors))).size, 47);@@ -64,13 +64,23 @@ test("all 47 reference palettes remain selectable after reload with their fixedassert.equal(model.metadata.appearance.backgroundColor, "#ffffff");assert.equal(model.metadata.nodes.a.textColor, "red");for (const canvas of ["#ffffff", "#1e1e1e", ...LIST_MINDMAP_CANVAS_COLORS]) {+ delete model.metadata.appearance.backgroundColor;+ const before = JSON.stringify(model.metadata);const styles = resolveListMindmapColors(model, canvas);- assert.deepEqual(["root", "a", "a1"].map(id => styles.get(id).textColor), ["#ffffff", "#ffffff", "#000000"]);+ assert.deepEqual(["root", "a", "a1"].map(id => styles.get(id).textColor),+ ["#ffffff", "#ffffff", canvas === "#1e1e1e" ? "#ffffff" : "#000000"]);assert.deepEqual(["root", "a", "a1"].map(id => styles.get(id).backgroundColor),[preset.rootColor, preset.colors[0], "transparent"]);assert.deepEqual(["root", "a", "a1"].map(id => styles.get(id).lineWidth), [1.5, 1.5, 1.5]);assert.equal(styles.get("a1").lineColor, preset.colors[0]);+ assert.equal(JSON.stringify(model.metadata), before, "canvas adaptation never rewrites saved colors");+ model.metadata.appearance.backgroundColor = "";+ assert.deepEqual(resolveListMindmapColors(model, canvas), styles, "default canvas follows the application");+ model.metadata.appearance.backgroundColor = canvas;+ assert.deepEqual(resolveListMindmapColors(model, canvas === "#1e1e1e" ? "#ffffff" : "#1e1e1e"), styles,+ "explicit canvas colors take precedence over the application theme");}+ model.metadata.appearance.backgroundColor = "#ffffff";}});@@ -432,6 +442,8 @@ const contrastCases = async (source: string, css: string, legacyPresets: typeof}}}+ const deepQuote = quote.cloneNode(true) as HTMLElement;+ deepNode.contentBlocks.push(deepQuote);for (const preset of api.LIST_MINDMAP_PALETTES) {model.metadata.appearance = {version: 1, palette: preset.colors, rootColor: preset.rootColor, nodeStyle: "branch"};model.metadata.connectorStyle = "rounded";@@ -449,7 +461,12 @@ const contrastCases = async (source: string, css: string, legacyPresets: typeof}const deep = view.nodeElements.get(deepNode.id);check.equal(getComputedStyle(deep).backgroundColor, "rgba(0, 0, 0, 0)");- check.equal(getComputedStyle(deep).color, "rgb(0, 0, 0)");+ const foreground = background === "#1e1e1e" ? "rgb(255, 255, 255)" : "rgb(0, 0, 0)";+ check.equal(getComputedStyle(deep).color, foreground,+ "transparent node text contrasts with the current canvas in editing and print views");+ check.equal(getComputedStyle(deep.querySelector(".bq .p")).color, foreground);+ check.equal(getComputedStyle(deep.querySelector(".bq span")).color, "rgb(194, 65, 12)",+ "deep inline colors remain authoritative");check.equal(getComputedStyle(view.getContentHost(emptyNode.id), "::before").color, "rgb(255, 255, 255)");check.equal(getComputedStyle(view.nodeElements.get(quoteNode.id).querySelector(".bq .p")).color,"rgb(255, 255, 255)");@@ -461,6 +478,16 @@ const contrastCases = async (source: string, css: string, legacyPresets: typeofcheck.ok(widths.length > 0 && widths.every(width => width === 1.5),"new reference themes use the same width for every hierarchy line");check.ok(lines.includes(computedColor(preset.colors[0])), "reference swatch values reach the canvas unchanged");+ for (const savedBackground of ["#ffffff", "#1e1e1e"]) {+ model.metadata.appearance.backgroundColor = savedBackground;+ const before = JSON.stringify(model.metadata);+ view.update(model);+ check.equal(getComputedStyle(view.nodeElements.get(deepNode.id)).color,+ savedBackground === "#1e1e1e" ? "rgb(255, 255, 255)" : "rgb(0, 0, 0)",+ "explicit canvas color controls the foreground regardless of application mode");+ check.equal(JSON.stringify(model.metadata), before);+ }+ delete model.metadata.appearance.backgroundColor;}}}@@ -525,21 +552,40 @@ const contrastCases = async (source: string, css: string, legacyPresets: typeofhost.style.removeProperty("--b3-mindmap-line-width");view.options.printLayout = false;view.readOnly = false;- view.update(model);- view.setEditing(deepNode.id);- const editorHost = view.getContentHost(deepNode.id);- const editorContent = document.createElement("div");- editorContent.textContent = "Unsaved editor content";- editorHost.replaceChildren(editorContent);- const metadataBeforeThemeChange = JSON.stringify(model.metadata);- document.documentElement.style.setProperty("--b3-theme-background", "#ffffff");- await new Promise(resolve => setTimeout(resolve, 0));- check.equal(getComputedStyle(view.nodeElements.get(deepNode.id)).color,- computedColor(api.resolveListMindmapColors(model, "#ffffff").get(deepNode.id).textColor),- "application theme changes refresh layered foregrounds without a document reload");- check.equal(editorHost.firstElementChild, editorContent, "theme changes preserve the active editor DOM");- check.equal(view.editingId, deepNode.id);- check.equal(JSON.stringify(model.metadata), metadataBeforeThemeChange);+ for (const nodeStyle of ["layered", "branch"]) {+ model.metadata.appearance.nodeStyle = nodeStyle;+ view.update(model);+ view.setEditing(deepNode.id);+ const editorHost = view.getContentHost(deepNode.id);+ const editorContent = document.createElement("div");+ editorContent.className = "protyle-wysiwyg protyle-wysiwyg--empty";+ editorContent.setAttribute("placeholder", "Enter text");+ editorHost.replaceChildren(editorContent);+ const metadataBeforeThemeChange = JSON.stringify(model.metadata);+ for (const background of ["#ffffff", "#1e1e1e", "#ffffff"]) {+ document.documentElement.style.setProperty("--b3-theme-background", background);+ await new Promise(resolve => setTimeout(resolve, 0));+ const foreground = nodeStyle === "branch" ?+ (background === "#1e1e1e" ? "rgb(255, 255, 255)" : "rgb(0, 0, 0)") :+ computedColor(api.resolveListMindmapColors(model, background).get(deepNode.id).textColor);+ check.equal(getComputedStyle(view.nodeElements.get(deepNode.id)).color, foreground,+ `${nodeStyle} text adapts to application theme changes without a document reload`);+ check.equal(getComputedStyle(editorContent, "::before").color, foreground,+ "the active editor placeholder follows the adapted text color");+ check.equal(editorHost.firstElementChild, editorContent, "theme changes preserve the active editor DOM");+ check.equal(view.editingId, deepNode.id);+ check.equal(JSON.stringify(model.metadata), metadataBeforeThemeChange);+ }+ view.setEditing(undefined);+ for (const style of [{textColor: "#ff00ff"}, {backgroundColor: "#1e1e1e"}]) {+ model.metadata.nodes[deepNode.id] = style;+ view.update(model);+ check.equal(getComputedStyle(view.nodeElements.get(deepNode.id)).color,+ style.textColor ? "rgb(255, 0, 255)" : "rgb(255, 255, 255)",+ "manual text colors and solid backgrounds take precedence over canvas adaptation");+ }+ delete model.metadata.nodes[deepNode.id];+ }model.metadata.appearance.palette = [];view.update(model);view.nodeElements.forEach((element: HTMLElement) => {diff --git a/app/src/protyle/render/listMindmap/appearance.ts b/app/src/protyle/render/listMindmap/appearance.tsindex 03cb4b1b32..13e459acf1 100644--- a/app/src/protyle/render/listMindmap/appearance.ts+++ b/app/src/protyle/render/listMindmap/appearance.ts@@ -212,7 +212,7 @@ export const resolveListMindmapColors = (model: ListMindmapModel, canvasColor?:const {node, color, level} = pending.pop();if (appearance.nodeStyle === "branch") {result.set(node.id, {backgroundColor: level < 2 ? color : "transparent",- textColor: level < 2 ? "#ffffff" : "#000000", lineColor: color,+ textColor: level < 2 ? "#ffffff" : getMindmapTextColor(background), lineColor: color,fontSize: level === 0 ? 20 : level === 1 ? 16 : 14, bold: level < 2, lineWidth: 1.5});} else if (appearance.nodeStyle === "layered") {result.set(node.id, {backgroundColor: "transparent",diff --git a/app/src/protyle/render/listMindmap/view.ts b/app/src/protyle/render/listMindmap/view.tsindex a8a7774d00..4d81c41401 100644--- a/app/src/protyle/render/listMindmap/view.ts+++ b/app/src/protyle/render/listMindmap/view.ts@@ -280,7 +280,7 @@ export class ListMindmapView {["pointerdown", "keydown"].forEach(type =>this.listen(options.host, type, () => this.stopFoldAnimation?.(), {capture: true}));const refreshTheme = () => {- if (this.model.metadata.appearance?.nodeStyle === "layered") {+ if (this.model.metadata.appearance?.nodeStyle) {this.updateColors();}this.refreshLayout();