still self referencing

This commit is contained in:
2026-02-05 01:43:10 -05:00
parent ea9ab4d3f9
commit 9fa52d71ca
13 changed files with 263 additions and 141 deletions

View File

@@ -3,9 +3,13 @@
* Handles dynamic theme switching by updating CSS custom properties
*/
import { RGBA } from "@opentui/core"
import { RGBA, type TerminalColors } from "@opentui/core"
import type { ThemeColors } from "../types/settings"
import type { ColorValue } from "../types/theme-schema"
import type { ColorValue, ThemeJson } from "../types/theme-schema"
import { THEME_JSON } from "../constants/themes"
import { getCustomThemes } from "./custom-themes"
import { resolveTheme as resolveThemeJson } from "./theme-resolver"
import { generateSystemTheme } from "./system-theme"
const toCss = (value: ColorValue | RGBA) => {
if (value instanceof RGBA) {
@@ -60,3 +64,32 @@ export function setThemeAttribute(themeName: string) {
const root = document.documentElement
root.setAttribute("data-theme", themeName)
}
export async function loadThemes() {
return await getCustomThemes()
}
export async function loadTheme(name: string) {
const themes = await loadThemes()
return themes[name]
}
export function resolveTheme(theme: ThemeJson, mode: "dark" | "light") {
return resolveThemeJson(theme, mode)
}
export function resolveTerminalTheme(
themes: Record<string, ThemeJson>,
name: string,
mode: "dark" | "light",
system?: TerminalColors
) {
if (name === "system" && system) {
return resolveThemeJson(generateSystemTheme(system, mode), mode)
}
const theme = themes[name] ?? themes.opencode
if (!theme) {
return resolveThemeJson(THEME_JSON.opencode, mode)
}
return resolveThemeJson(theme, mode)
}