mirror of
https://github.com/fmhy/edit.git
synced 2026-01-13 07:21:08 +11:00
blocked nine vicious
This commit is contained in:
parent
e3143271a6
commit
0d926839c5
1 changed files with 34 additions and 16 deletions
|
|
@ -27,7 +27,7 @@ export class ThemeHandler {
|
||||||
private state = ref<ThemeState>({
|
private state = ref<ThemeState>({
|
||||||
currentTheme: 'color-swarm',
|
currentTheme: 'color-swarm',
|
||||||
currentMode: 'light' as DisplayMode,
|
currentMode: 'light' as DisplayMode,
|
||||||
theme: themeRegistry['color-swarm']
|
theme: (Object.values(themeRegistry)[0] || null) as Theme
|
||||||
})
|
})
|
||||||
private amoledEnabled = ref(false)
|
private amoledEnabled = ref(false)
|
||||||
|
|
||||||
|
|
@ -39,13 +39,19 @@ export class ThemeHandler {
|
||||||
if (typeof window === 'undefined') return
|
if (typeof window === 'undefined') return
|
||||||
|
|
||||||
// Load saved preferences
|
// Load saved preferences
|
||||||
const savedTheme = localStorage.getItem(STORAGE_KEY_THEME) || 'swarm'
|
const savedTheme = localStorage.getItem(STORAGE_KEY_THEME) || 'color-swarm'
|
||||||
const savedMode = localStorage.getItem(STORAGE_KEY_MODE) as DisplayMode | null
|
const savedMode = localStorage.getItem(STORAGE_KEY_MODE) as DisplayMode | null
|
||||||
const savedAmoled = localStorage.getItem(STORAGE_KEY_AMOLED) === 'true'
|
const savedAmoled = localStorage.getItem(STORAGE_KEY_AMOLED) === 'true'
|
||||||
|
|
||||||
if (themeRegistry[savedTheme]) {
|
if (themeRegistry[savedTheme]) {
|
||||||
this.state.value.currentTheme = savedTheme
|
this.state.value.currentTheme = savedTheme
|
||||||
this.state.value.theme = themeRegistry[savedTheme]
|
this.state.value.theme = themeRegistry[savedTheme]
|
||||||
|
} else {
|
||||||
|
const firstCustomTheme = Object.keys(themeRegistry)[0]
|
||||||
|
if (firstCustomTheme) {
|
||||||
|
this.state.value.currentTheme = firstCustomTheme
|
||||||
|
this.state.value.theme = themeRegistry[firstCustomTheme]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set amoled preference
|
// Set amoled preference
|
||||||
|
|
@ -78,6 +84,12 @@ export class ThemeHandler {
|
||||||
if (typeof document === 'undefined') return
|
if (typeof document === 'undefined') return
|
||||||
|
|
||||||
const { currentMode, theme } = this.state.value
|
const { currentMode, theme } = this.state.value
|
||||||
|
|
||||||
|
if (!theme || !theme.modes || !theme.modes[currentMode]) {
|
||||||
|
this.applyDOMClasses(currentMode)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const modeColors = theme.modes[currentMode]
|
const modeColors = theme.modes[currentMode]
|
||||||
|
|
||||||
this.applyDOMClasses(currentMode)
|
this.applyDOMClasses(currentMode)
|
||||||
|
|
@ -262,18 +274,17 @@ export class ThemeHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public setTheme(themeName: string) {
|
public setTheme(themeName: string) {
|
||||||
if (!themeRegistry[themeName]) {
|
// Check if it's a custom theme in registry
|
||||||
console.warn(`Theme "${themeName}" not found. Using catppuccin theme.`)
|
if (themeRegistry[themeName]) {
|
||||||
themeName = 'catppuccin'
|
this.state.value.currentTheme = themeName
|
||||||
|
this.state.value.theme = themeRegistry[themeName]
|
||||||
|
localStorage.setItem(STORAGE_KEY_THEME, themeName)
|
||||||
|
this.applyTheme()
|
||||||
|
this.ensureColorPickerColors()
|
||||||
|
} else {
|
||||||
|
this.state.value.currentTheme = themeName
|
||||||
|
localStorage.setItem(STORAGE_KEY_THEME, themeName)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state.value.currentTheme = themeName
|
|
||||||
this.state.value.theme = themeRegistry[themeName]
|
|
||||||
localStorage.setItem(STORAGE_KEY_THEME, themeName)
|
|
||||||
this.applyTheme()
|
|
||||||
|
|
||||||
// Force re-apply ColorPicker colors if theme doesn't specify brand colors
|
|
||||||
this.ensureColorPickerColors()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public setMode(mode: DisplayMode) {
|
public setMode(mode: DisplayMode) {
|
||||||
|
|
@ -312,7 +323,14 @@ export class ThemeHandler {
|
||||||
private ensureColorPickerColors() {
|
private ensureColorPickerColors() {
|
||||||
// If theme doesn't specify brand colors, force ColorPicker to reapply its selection
|
// If theme doesn't specify brand colors, force ColorPicker to reapply its selection
|
||||||
const currentMode = this.state.value.currentMode
|
const currentMode = this.state.value.currentMode
|
||||||
const modeColors = this.state.value.theme.modes[currentMode]
|
const theme = this.state.value.theme
|
||||||
|
|
||||||
|
// Skip if theme doesn't have modes (preset theme)
|
||||||
|
if (!theme || !theme.modes || !theme.modes[currentMode]) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const modeColors = theme.modes[currentMode]
|
||||||
|
|
||||||
if (!modeColors.brand || !modeColors.brand[1]) {
|
if (!modeColors.brand || !modeColors.brand[1]) {
|
||||||
// Trigger a custom event that ColorPicker can listen to
|
// Trigger a custom event that ColorPicker can listen to
|
||||||
|
|
@ -335,7 +353,7 @@ export class ThemeHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public getCurrentTheme() {
|
public getCurrentTheme() {
|
||||||
return this.state.value.theme
|
return this.state.value.theme || ({} as Theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
public getAvailableThemes() {
|
public getAvailableThemes() {
|
||||||
|
|
@ -390,4 +408,4 @@ export function useTheme() {
|
||||||
toggleAmoled: () => handler.toggleAmoled(),
|
toggleAmoled: () => handler.toggleAmoled(),
|
||||||
state
|
state
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue