- Updated the app to support light and dark themes with appropriate CSS classes. - Enhanced PWA configuration with manifest details and caching strategies. - Improved the chat UI with dynamic theme adjustments for various components. - Added new meta tags for better mobile web app experience. - Refactored environment variables to include new Anthropic token. - Updated package dependencies for better compatibility and performance. Made-with: Cursor
34 lines
919 B
TypeScript
34 lines
919 B
TypeScript
import { ref, computed } from 'vue'
|
|
|
|
type ThemeName = 'dark' | 'light'
|
|
|
|
const currentTheme = ref<ThemeName>('dark')
|
|
|
|
export function useTheme() {
|
|
const isDark = computed(() => currentTheme.value === 'dark')
|
|
|
|
const setTheme = (theme: ThemeName) => {
|
|
currentTheme.value = theme
|
|
localStorage.setItem('aiui-theme', theme)
|
|
document.documentElement.classList.toggle('dark', theme === 'dark')
|
|
document.documentElement.classList.toggle('light', theme === 'light')
|
|
}
|
|
|
|
const toggleTheme = () => {
|
|
setTheme(isDark.value ? 'light' : 'dark')
|
|
}
|
|
|
|
const initTheme = () => {
|
|
const saved = localStorage.getItem('aiui-theme') as ThemeName | null
|
|
if (saved) {
|
|
setTheme(saved)
|
|
} else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
|
setTheme('dark')
|
|
} else {
|
|
setTheme('light')
|
|
}
|
|
}
|
|
|
|
return { currentTheme, isDark, setTheme, toggleTheme, initTheme }
|
|
}
|