From f963a1969002368d19a40ec4dc66c451e6a86568 Mon Sep 17 00:00:00 2001 From: Darkings Date: Fri, 15 May 2026 17:41:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E9=99=A4=20Obsidian=20CSS=20=E5=AE=A1?= =?UTF-8?q?=E6=A0=B8=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/theme.css | 21 +++++-------------- scripts/generate-icon-theme.js | 7 ++----- scripts/verify-graph.js | 4 ++-- src/scss/_active-visual-overrides.scss | 11 +--------- .../components/_file-icons.generated.scss | 7 ++----- src/scss/plugins/_graph.scss | 4 ++-- stylelint.config.js | 1 + theme.css | 21 +++++-------------- 8 files changed, 20 insertions(+), 56 deletions(-) diff --git a/dist/theme.css b/dist/theme.css index a178d1b..9111590 100644 --- a/dist/theme.css +++ b/dist/theme.css @@ -507,7 +507,9 @@ a:hover, flex: 0 0 1rem; width: 1rem; margin-inline-end: 0.35rem; + --monokai-file-icon-color: #ffd866; color: var(--monokai-file-icon-color, var(--icon-color)); + content: "\e658"; font-family: "monokai-pro-icons"; font-size: 1rem; font-style: normal; @@ -519,11 +521,6 @@ a:hover, text-rendering: auto; } -.nav-file-title::before { - --monokai-file-icon-color: #ffd866; - content: "\e658"; -} - .nav-file-title[data-path$=".7z"]::before { --monokai-file-icon-color: #ffd866; content: "\e666"; @@ -1084,7 +1081,7 @@ body.is-mobile .workspace-ribbon { transform: translateX(0); } } -body.theme-dark { +.theme-dark .graph-view { --monokai-graph-background: #1e1f1c; --monokai-graph-panel: #2b2c26; --monokai-graph-line: rgb(120 220 232 / 42%); @@ -1096,7 +1093,7 @@ body.theme-dark { --monokai-graph-ring: rgb(102 217 239 / 28%); } -body.theme-light { +.theme-light .graph-view { --monokai-graph-background: #f5f0e6; --monokai-graph-panel: #f2ead8; --monokai-graph-line: rgb(20 116 138 / 42%); @@ -1369,8 +1366,7 @@ body { } /* stylelint-disable selector-class-pattern -- Obsidian 内部类名,不能改成 kebab-case。 */ -body.theme-dark, -body.theme-light { +body:is(.theme-dark, .theme-light) { --blockquote-background-color: transparent; --blockquote-border-thickness: 2px; --callout-padding: 1.25rem; @@ -1409,13 +1405,6 @@ body .markdown-source-view.mod-cm6 .HyperMD-quote .cm-formatting-quote { display: none; } -/* ===== Callout - CodeMirror 行容器(仅外层 spacing,无背景无竖线) ===== */ -body .markdown-source-view.mod-cm6 .cm-callout { - background-color: transparent; - border-inline-start: 0; - border-radius: 0; -} - /* ===== Callout 组件(阅读 + 编辑统一:背景 + 竖线 + 内间距) ===== */ body .markdown-preview-view.markdown-rendered .callout, body .markdown-rendered .callout, diff --git a/scripts/generate-icon-theme.js b/scripts/generate-icon-theme.js index 400636e..eda3710 100644 --- a/scripts/generate-icon-theme.js +++ b/scripts/generate-icon-theme.js @@ -175,7 +175,9 @@ const lines = [ ' flex: 0 0 1rem;', ' width: 1rem;', ' margin-inline-end: 0.35rem;', + ` --monokai-file-icon-color: ${defaultFileIcon.fontColor};`, ' color: var(--monokai-file-icon-color, var(--icon-color));', + ` content: "${cssContent(defaultFileIcon.fontCharacter)}";`, ' font-family: "monokai-pro-icons";', " font-size: 1rem;", " font-style: normal;", @@ -187,11 +189,6 @@ const lines = [ " text-rendering: auto;", "}", "", - ".nav-file-title::before {", - ` --monokai-file-icon-color: ${defaultFileIcon.fontColor};`, - ` content: "${cssContent(defaultFileIcon.fontCharacter)}";`, - "}", - "", ]; for (const [extension, iconId] of sortedEntries(obsidianFileExtensions)) { diff --git a/scripts/verify-graph.js b/scripts/verify-graph.js index 5f2b1f7..c073e7e 100644 --- a/scripts/verify-graph.js +++ b/scripts/verify-graph.js @@ -8,8 +8,8 @@ const checks = [ ["图谱颜色支持过渡", /\.graph-view[\s\S]*?transition:[\s\S]*?color 140ms ease/], ["图谱背景支持过渡", /\.graph-view[\s\S]*?background-color 180ms ease/], ["图谱使用 Monokai Pro 背景变量", /\.graph-view[\s\S]*?background-color:\s*var\(--monokai-graph-background\)/], - ["深色图谱背景对齐导航栏与标题栏", /body\.theme-dark[\s\S]*?--monokai-graph-background:\s*#1e1f1c/], - ["浅色图谱背景对齐导航栏与标题栏", /body\.theme-light[\s\S]*?--monokai-graph-background:\s*#f5f0e6/], + ["深色图谱背景对齐导航栏与标题栏", /\.theme-dark \.graph-view[\s\S]*?--monokai-graph-background:\s*#1e1f1c/], + ["浅色图谱背景对齐导航栏与标题栏", /\.theme-light \.graph-view[\s\S]*?--monokai-graph-background:\s*#f5f0e6/], ["图谱控制区使用 Monokai 面板变量", /\.graph-controls[\s\S]*?background-color:\s*var\(--monokai-graph-panel\)/], ["图谱高亮节点无光晕", (scss) => !/drop-shadow\(/.test(scss)], ["图谱容器无呼吸光晕伪元素", (scss) => !/\.workspace-leaf-content\[data-type="graph"\] \.view-content::before/.test(scss)], diff --git a/src/scss/_active-visual-overrides.scss b/src/scss/_active-visual-overrides.scss index 2be9daf..d9d1ee5 100644 --- a/src/scss/_active-visual-overrides.scss +++ b/src/scss/_active-visual-overrides.scss @@ -2,8 +2,7 @@ /* stylelint-disable selector-class-pattern -- Obsidian 内部类名,不能改成 kebab-case。 */ -body.theme-dark, -body.theme-light { +body:is(.theme-dark, .theme-light) { --blockquote-background-color: transparent; --blockquote-border-thickness: 2px; --callout-padding: 1.25rem; @@ -43,14 +42,6 @@ body .markdown-source-view.mod-cm6 .HyperMD-quote .cm-formatting-quote { display: none; } -/* ===== Callout - CodeMirror 行容器(仅外层 spacing,无背景无竖线) ===== */ - -body .markdown-source-view.mod-cm6 .cm-callout { - background-color: transparent; - border-inline-start: 0; - border-radius: 0; -} - /* ===== Callout 组件(阅读 + 编辑统一:背景 + 竖线 + 内间距) ===== */ body .markdown-preview-view.markdown-rendered .callout, diff --git a/src/scss/components/_file-icons.generated.scss b/src/scss/components/_file-icons.generated.scss index 56d594c..5e369d4 100644 --- a/src/scss/components/_file-icons.generated.scss +++ b/src/scss/components/_file-icons.generated.scss @@ -17,7 +17,9 @@ flex: 0 0 1rem; width: 1rem; margin-inline-end: 0.35rem; + --monokai-file-icon-color: #ffd866; color: var(--monokai-file-icon-color, var(--icon-color)); + content: "\e658"; font-family: "monokai-pro-icons"; font-size: 1rem; font-style: normal; @@ -29,11 +31,6 @@ text-rendering: auto; } -.nav-file-title::before { - --monokai-file-icon-color: #ffd866; - content: "\e658"; -} - .nav-file-title[data-path$=".7z"]::before { --monokai-file-icon-color: #ffd866; content: "\e666"; diff --git a/src/scss/plugins/_graph.scss b/src/scss/plugins/_graph.scss index ce2bf5a..27a9d77 100644 --- a/src/scss/plugins/_graph.scss +++ b/src/scss/plugins/_graph.scss @@ -34,7 +34,7 @@ } } -body.theme-dark { +.theme-dark .graph-view { --monokai-graph-background: #1e1f1c; --monokai-graph-panel: #2b2c26; --monokai-graph-line: rgb(120 220 232 / 42%); @@ -46,7 +46,7 @@ body.theme-dark { --monokai-graph-ring: rgb(102 217 239 / 28%); } -body.theme-light { +.theme-light .graph-view { --monokai-graph-background: #f5f0e6; --monokai-graph-panel: #f2ead8; --monokai-graph-line: rgb(20 116 138 / 42%); diff --git a/stylelint.config.js b/stylelint.config.js index 95b440b..6a3d21f 100644 --- a/stylelint.config.js +++ b/stylelint.config.js @@ -1,6 +1,7 @@ export default { extends: ["stylelint-config-standard-scss"], rules: { + "color-hex-length": "long", "declaration-no-important": true, "max-nesting-depth": 3, "selector-max-id": 0, diff --git a/theme.css b/theme.css index a178d1b..9111590 100644 --- a/theme.css +++ b/theme.css @@ -507,7 +507,9 @@ a:hover, flex: 0 0 1rem; width: 1rem; margin-inline-end: 0.35rem; + --monokai-file-icon-color: #ffd866; color: var(--monokai-file-icon-color, var(--icon-color)); + content: "\e658"; font-family: "monokai-pro-icons"; font-size: 1rem; font-style: normal; @@ -519,11 +521,6 @@ a:hover, text-rendering: auto; } -.nav-file-title::before { - --monokai-file-icon-color: #ffd866; - content: "\e658"; -} - .nav-file-title[data-path$=".7z"]::before { --monokai-file-icon-color: #ffd866; content: "\e666"; @@ -1084,7 +1081,7 @@ body.is-mobile .workspace-ribbon { transform: translateX(0); } } -body.theme-dark { +.theme-dark .graph-view { --monokai-graph-background: #1e1f1c; --monokai-graph-panel: #2b2c26; --monokai-graph-line: rgb(120 220 232 / 42%); @@ -1096,7 +1093,7 @@ body.theme-dark { --monokai-graph-ring: rgb(102 217 239 / 28%); } -body.theme-light { +.theme-light .graph-view { --monokai-graph-background: #f5f0e6; --monokai-graph-panel: #f2ead8; --monokai-graph-line: rgb(20 116 138 / 42%); @@ -1369,8 +1366,7 @@ body { } /* stylelint-disable selector-class-pattern -- Obsidian 内部类名,不能改成 kebab-case。 */ -body.theme-dark, -body.theme-light { +body:is(.theme-dark, .theme-light) { --blockquote-background-color: transparent; --blockquote-border-thickness: 2px; --callout-padding: 1.25rem; @@ -1409,13 +1405,6 @@ body .markdown-source-view.mod-cm6 .HyperMD-quote .cm-formatting-quote { display: none; } -/* ===== Callout - CodeMirror 行容器(仅外层 spacing,无背景无竖线) ===== */ -body .markdown-source-view.mod-cm6 .cm-callout { - background-color: transparent; - border-inline-start: 0; - border-radius: 0; -} - /* ===== Callout 组件(阅读 + 编辑统一:背景 + 竖线 + 内间距) ===== */ body .markdown-preview-view.markdown-rendered .callout, body .markdown-rendered .callout,