()
| 87 | |
| 88 | // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: theme initialization handles many CSS variable mappings |
| 89 | export const initEditorTheme = () => { |
| 90 | if (typeof window === "undefined") { |
| 91 | return; // Skip during SSR |
| 92 | } |
| 93 | |
| 94 | const savedTheme = localStorage.getItem("editorTheme"); |
| 95 | |
| 96 | if (savedTheme) { |
| 97 | // Apply saved theme variables |
| 98 | if (savedTheme in DEFAULT_THEMES) { |
| 99 | // For default themes |
| 100 | const themeConfig = |
| 101 | DEFAULT_THEMES[savedTheme as keyof typeof DEFAULT_THEMES]; |
| 102 | setCSSVariables(themeConfig.variables); |
| 103 | setCSSVariables({ "--status-bar-text": "#fff" }); |
| 104 | |
| 105 | // Set document classes for dark mode |
| 106 | if (savedTheme === "vs-dark") { |
| 107 | document.documentElement.classList.add("dark"); |
| 108 | document.documentElement.classList.remove("light"); |
| 109 | } else { |
| 110 | document.documentElement.classList.remove("dark"); |
| 111 | document.documentElement.classList.add("light"); |
| 112 | } |
| 113 | } else { |
| 114 | // For custom themes |
| 115 | try { |
| 116 | // eslint-disable-next-line @typescript-eslint/no-require-imports |
| 117 | const themeData = require( |
| 118 | `monaco-themes/themes/${themeList[savedTheme as keyof typeof themeList]}.json` |
| 119 | ); |
| 120 | |
| 121 | // Set document classes for dark mode |
| 122 | if (themeData.base === "vs-dark") { |
| 123 | document.documentElement.classList.add("dark"); |
| 124 | document.documentElement.classList.remove("light"); |
| 125 | } else { |
| 126 | document.documentElement.classList.remove("dark"); |
| 127 | document.documentElement.classList.add("light"); |
| 128 | } |
| 129 | |
| 130 | setCSSVariables({ |
| 131 | "--toolbar-bg-primary": themeData.colors[ |
| 132 | "editor.selectionBackground" |
| 133 | ].slice(0, 7), |
| 134 | "--toolbar-bg-secondary": themeData.colors[ |
| 135 | "editor.selectionBackground" |
| 136 | ].slice(0, 7), |
| 137 | "--toolbar-foreground": themeData.colors["editor.foreground"].slice( |
| 138 | 0, |
| 139 | 7 |
| 140 | ), |
| 141 | "--toolbar-accent": themeData.colors["editorCursor.foreground"].slice( |
| 142 | 0, |
| 143 | 7 |
| 144 | ), |
| 145 | "--panel-text-accent": themeData.colors["editor.background"].slice( |
| 146 | 0, |
no test coverage detected