|
1 | | -import { type ExpressiveCodeEngineConfig } from '@expressive-code/core'; |
| 1 | +import { type ExpressiveCodeEngineConfig, type ExpressiveCodeTheme, type StyleValueOrValues, type UnresolvedStyleValue } from '@expressive-code/core'; |
| 2 | +import { type Settings } from 'src/settings/Settings'; |
2 | 3 |
|
3 | | -export const EC_THEME: ExpressiveCodeEngineConfig['styleOverrides'] = { |
4 | | - borderColor: 'var(--shiki-code-block-border-color)', |
5 | | - borderRadius: 'var(--shiki-code-block-border-radius)', |
6 | | - borderWidth: 'var(--shiki-code-block-border-width)', |
7 | | - codeBackground: 'var(--shiki-code-background)', |
8 | | - codeFontFamily: 'var(--font-monospace)', |
9 | | - codeFontSize: 'var(--code-size)', |
10 | | - codeFontWeight: 'var(--font-normal)', |
11 | | - codeForeground: 'var(--shiki-code-normal)', |
12 | | - codeLineHeight: 'var(--line-height-normal)', |
13 | | - codePaddingBlock: 'var(--size-4-3)', |
14 | | - codePaddingInline: 'var(--size-4-4)', |
15 | | - codeSelectionBackground: 'var(--text-selection)', |
16 | | - focusBorder: 'var(--background-modifier-border)', |
17 | | - scrollbarThumbColor: 'var(--scrollbar-thumb-bg)', |
18 | | - scrollbarThumbHoverColor: 'var(--scrollbar-active-thumb-bg)', |
19 | | - uiFontFamily: 'var(--font-interface)', |
20 | | - uiFontSize: 'var(--font-text-size)', |
21 | | - uiFontWeight: 'var(--font-normal)', |
22 | | - uiLineHeight: 'var(--line-height-normal)', |
23 | | - uiPaddingBlock: 'var(--size-4-2)', |
24 | | - uiPaddingInline: 'var(--size-4-4)', |
25 | | - uiSelectionBackground: 'var(--text-selection)', |
26 | | - uiSelectionForeground: 'var(--text-normal)', |
27 | | - gutterBorderColor: 'var(--shiki-gutter-border-color)', |
28 | | - gutterBorderWidth: 'var(--shiki-gutter-border-width)', |
29 | | - gutterForeground: 'var(--shiki-gutter-text-color)', |
30 | | - gutterHighlightForeground: 'var(--shiki-gutter-text-color-highlight)', |
31 | | - textMarkers: { |
32 | | - delBackground: 'var(--shiki-highlight-red-background)', |
33 | | - delBorderColor: 'var(--shiki-highlight-red)', |
34 | | - delDiffIndicatorColor: 'rgba(var(--shiki-highlight-red-rgb), 1)', |
35 | | - inlineMarkerBorderWidth: 'var(--border-width)', |
36 | | - insBackground: 'var(--shiki-highlight-green-background)', |
37 | | - insBorderColor: 'var(--shiki-highlight-green)', |
38 | | - insDiffIndicatorColor: 'rgba(var(--shiki-highlight-green-rgb), 1)', |
39 | | - lineDiffIndicatorMarginLeft: '0.3rem', |
40 | | - lineMarkerAccentMargin: '0rem', |
41 | | - lineMarkerAccentWidth: '0.15rem', |
42 | | - lineMarkerLabelColor: 'white', |
43 | | - lineMarkerLabelPaddingInline: '0.2rem', |
44 | | - markBackground: 'var(--shiki-highlight-neutral-background)', |
45 | | - markBorderColor: 'var(--shiki-highlight-neutral)', |
46 | | - }, |
47 | | - frames: { |
48 | | - editorActiveTabBackground: 'var(--shiki-code-background)', |
49 | | - editorActiveTabBorderColor: 'transparent', |
50 | | - editorActiveTabForeground: 'var(--text-normal)', |
51 | | - editorActiveTabIndicatorBottomColor: 'transparent', |
52 | | - editorActiveTabIndicatorHeight: '2px', |
53 | | - editorActiveTabIndicatorTopColor: 'var(--shiki-highlight-neutral)', |
54 | | - editorBackground: 'var(--shiki-code-background)', |
55 | | - editorTabBarBackground: 'var(--color-primary)', |
56 | | - editorTabBarBorderBottomColor: 'transparent', |
57 | | - editorTabBarBorderColor: 'transparent', |
58 | | - editorTabBorderRadius: 'var(--shiki-code-border-radius)', |
59 | | - editorTabsMarginBlockStart: '0', |
60 | | - editorTabsMarginInlineStart: '0', |
61 | | - frameBoxShadowCssValue: 'none', |
62 | | - inlineButtonBackground: 'var(--background-modifier-hover)', |
63 | | - inlineButtonBackgroundActiveOpacity: '1', |
64 | | - inlineButtonBackgroundHoverOrFocusOpacity: '1', |
65 | | - inlineButtonBackgroundIdleOpacity: '0', |
66 | | - inlineButtonBorder: 'var(--shiki-code-border-color)', |
67 | | - inlineButtonBorderOpacity: '1', |
68 | | - inlineButtonForeground: 'var(--text-normal)', |
69 | | - shadowColor: 'transparent', |
70 | | - terminalBackground: 'var(--shiki-code-background)', |
71 | | - terminalTitlebarBackground: 'var(--shiki-code-background)', |
72 | | - terminalTitlebarBorderBottomColor: 'transparent', |
73 | | - terminalTitlebarDotsForeground: 'var(--shiki-terminal-dots-color)', |
74 | | - terminalTitlebarDotsOpacity: '1', |
75 | | - terminalTitlebarForeground: 'var(--text-normal)', |
76 | | - tooltipSuccessBackground: 'var(--shiki-tooltip-background)', |
77 | | - tooltipSuccessForeground: 'var(--shiki-tooltip-text-color)', |
78 | | - }, |
79 | | -}; |
| 4 | +export function getECTheme(settings: Settings): ExpressiveCodeEngineConfig['styleOverrides'] { |
| 5 | + const useThemeColors = settings.preferThemeColors && settings.theme !== 'obsidian-theme'; |
| 6 | + |
| 7 | + const backgroundColor: UnresolvedStyleValue = ({ theme }: { theme: ExpressiveCodeTheme }): StyleValueOrValues => |
| 8 | + useThemeColors ? theme.colors['editor.background'] ?? 'var(--shiki-code-background)' : 'var(--shiki-code-background)'; |
| 9 | + const foregroundColor: UnresolvedStyleValue = ({ theme }: { theme: ExpressiveCodeTheme }): StyleValueOrValues => |
| 10 | + theme.colors['editor.foreground'] ?? 'var(--shiki-code-normal)'; |
| 11 | + |
| 12 | + const gutterBorderColor: UnresolvedStyleValue = ({ theme }: { theme: ExpressiveCodeTheme }): StyleValueOrValues => |
| 13 | + useThemeColors ? theme.colors['editorLineNumber.foreground'] ?? 'var(--shiki-gutter-border-color)' : 'var(--shiki-gutter-border-color)'; |
| 14 | + const gutterTextColor: UnresolvedStyleValue = ({ theme }: { theme: ExpressiveCodeTheme }): StyleValueOrValues => |
| 15 | + useThemeColors ? theme.colors['editorLineNumber.foreground'] ?? 'var(--shiki-gutter-text-color)' : 'var(--shiki-gutter-text-color)'; |
| 16 | + const gutterTextActiveColor: UnresolvedStyleValue = ({ theme }: { theme: ExpressiveCodeTheme }): StyleValueOrValues => |
| 17 | + useThemeColors |
| 18 | + ? (theme.colors['editorLineNumber.activeForeground'] || theme.colors['editorLineNumber.foreground']) ?? 'var(--shiki-gutter-text-color-highlight)' |
| 19 | + : 'var(--shiki-gutter-text-color-highlight)'; |
| 20 | + |
| 21 | + return { |
| 22 | + borderColor: 'var(--shiki-code-block-border-color)', |
| 23 | + borderRadius: 'var(--shiki-code-block-border-radius)', |
| 24 | + borderWidth: 'var(--shiki-code-block-border-width)', |
| 25 | + codeBackground: backgroundColor, |
| 26 | + codeFontFamily: 'var(--font-monospace)', |
| 27 | + codeFontSize: 'var(--code-size)', |
| 28 | + codeFontWeight: 'var(--font-normal)', |
| 29 | + codeForeground: foregroundColor, |
| 30 | + codeLineHeight: 'var(--line-height-normal)', |
| 31 | + codePaddingBlock: 'var(--size-4-3)', |
| 32 | + codePaddingInline: 'var(--size-4-4)', |
| 33 | + codeSelectionBackground: 'var(--text-selection)', |
| 34 | + focusBorder: 'var(--background-modifier-border)', |
| 35 | + scrollbarThumbColor: 'var(--scrollbar-thumb-bg)', |
| 36 | + scrollbarThumbHoverColor: 'var(--scrollbar-active-thumb-bg)', |
| 37 | + uiFontFamily: 'var(--font-interface)', |
| 38 | + uiFontSize: 'var(--font-text-size)', |
| 39 | + uiFontWeight: 'var(--font-normal)', |
| 40 | + uiLineHeight: 'var(--line-height-normal)', |
| 41 | + uiPaddingBlock: 'var(--size-4-2)', |
| 42 | + uiPaddingInline: 'var(--size-4-4)', |
| 43 | + uiSelectionBackground: 'var(--text-selection)', |
| 44 | + uiSelectionForeground: 'var(--text-normal)', |
| 45 | + gutterBorderColor: gutterBorderColor, |
| 46 | + gutterBorderWidth: 'var(--shiki-gutter-border-width)', |
| 47 | + gutterForeground: gutterTextColor, |
| 48 | + gutterHighlightForeground: gutterTextActiveColor, |
| 49 | + textMarkers: { |
| 50 | + delBackground: 'var(--shiki-highlight-red-background)', |
| 51 | + delBorderColor: 'var(--shiki-highlight-red)', |
| 52 | + delDiffIndicatorColor: 'rgba(var(--shiki-highlight-red-rgb), 1)', |
| 53 | + inlineMarkerBorderWidth: 'var(--border-width)', |
| 54 | + insBackground: 'var(--shiki-highlight-green-background)', |
| 55 | + insBorderColor: 'var(--shiki-highlight-green)', |
| 56 | + insDiffIndicatorColor: 'rgba(var(--shiki-highlight-green-rgb), 1)', |
| 57 | + lineDiffIndicatorMarginLeft: '0.3rem', |
| 58 | + lineMarkerAccentMargin: '0rem', |
| 59 | + lineMarkerAccentWidth: '0.15rem', |
| 60 | + lineMarkerLabelColor: 'white', |
| 61 | + lineMarkerLabelPaddingInline: '0.2rem', |
| 62 | + markBackground: 'var(--shiki-highlight-neutral-background)', |
| 63 | + markBorderColor: 'var(--shiki-highlight-neutral)', |
| 64 | + }, |
| 65 | + frames: { |
| 66 | + editorActiveTabBackground: backgroundColor, |
| 67 | + editorActiveTabBorderColor: 'transparent', |
| 68 | + editorActiveTabForeground: 'var(--text-normal)', |
| 69 | + editorActiveTabIndicatorBottomColor: 'transparent', |
| 70 | + editorActiveTabIndicatorHeight: 'var(--shiki-active-tab-border-width)', |
| 71 | + editorActiveTabIndicatorTopColor: 'var(--shiki-active-tab-border-color)', |
| 72 | + editorBackground: backgroundColor, |
| 73 | + editorTabBarBackground: 'var(--color-primary)', |
| 74 | + editorTabBarBorderBottomColor: 'transparent', |
| 75 | + editorTabBarBorderColor: 'transparent', |
| 76 | + editorTabBorderRadius: 'var(--shiki-code-border-radius)', |
| 77 | + editorTabsMarginBlockStart: '0', |
| 78 | + editorTabsMarginInlineStart: '0', |
| 79 | + frameBoxShadowCssValue: 'none', |
| 80 | + inlineButtonBackground: 'var(--background-modifier-hover)', |
| 81 | + inlineButtonBackgroundActiveOpacity: '1', |
| 82 | + inlineButtonBackgroundHoverOrFocusOpacity: '1', |
| 83 | + inlineButtonBackgroundIdleOpacity: '0', |
| 84 | + inlineButtonBorder: 'var(--shiki-code-border-color)', |
| 85 | + inlineButtonBorderOpacity: '1', |
| 86 | + inlineButtonForeground: 'var(--text-normal)', |
| 87 | + shadowColor: 'transparent', |
| 88 | + terminalBackground: backgroundColor, |
| 89 | + terminalTitlebarBackground: backgroundColor, |
| 90 | + terminalTitlebarBorderBottomColor: 'transparent', |
| 91 | + terminalTitlebarDotsForeground: 'var(--shiki-terminal-dots-color)', |
| 92 | + terminalTitlebarDotsOpacity: '1', |
| 93 | + terminalTitlebarForeground: 'var(--text-normal)', |
| 94 | + tooltipSuccessBackground: 'var(--shiki-tooltip-background)', |
| 95 | + tooltipSuccessForeground: 'var(--shiki-tooltip-text-color)', |
| 96 | + }, |
| 97 | + }; |
| 98 | +} |
0 commit comments