|
| 1 | +// Color Management System for NoteKeeper |
| 2 | +const colorManager = { |
| 3 | + // Default themes (original) |
| 4 | + defaults: { |
| 5 | + light: { |
| 6 | + name: 'Default Light', |
| 7 | + bg: '#ffffff', |
| 8 | + fg: '#1a1a1a', |
| 9 | + accent: '#27ae60', |
| 10 | + border: '#e0e0e0', |
| 11 | + subtle: '#666', |
| 12 | + shadow: 'rgba(0, 0, 0, 0.1)' |
| 13 | + }, |
| 14 | + dark: { |
| 15 | + name: 'Default Dark', |
| 16 | + bg: '#111111', |
| 17 | + fg: '#f0f0f0', |
| 18 | + accent: '#27ae60', |
| 19 | + border: '#333333', |
| 20 | + subtle: '#888', |
| 21 | + shadow: 'rgba(0, 0, 0, 0.5)' |
| 22 | + } |
| 23 | + }, |
| 24 | + |
| 25 | + // Catppuccin-inspired color presets |
| 26 | + catppuccin: { |
| 27 | + latte: { |
| 28 | + name: 'Catppuccin Latte', |
| 29 | + bg: '#eff1f5', |
| 30 | + fg: '#4c4f69', |
| 31 | + accent: '#1e66f5', |
| 32 | + border: '#dce0e8', |
| 33 | + subtle: '#8c8fa1', |
| 34 | + shadow: 'rgba(220, 224, 232, 0.5)' |
| 35 | + }, |
| 36 | + frappe: { |
| 37 | + name: 'Catppuccin Frappé', |
| 38 | + bg: '#303446', |
| 39 | + fg: '#c6d0f5', |
| 40 | + accent: '#8caaee', |
| 41 | + border: '#51576d', |
| 42 | + subtle: '#838ba7', |
| 43 | + shadow: 'rgba(30, 32, 48, 0.5)' |
| 44 | + } |
| 45 | + }, |
| 46 | + |
| 47 | + // Initialize color system |
| 48 | + init() { |
| 49 | + const savedTheme = localStorage.getItem('notekeeper-theme') || 'default'; |
| 50 | + this.applyTheme(savedTheme); |
| 51 | + }, |
| 52 | + |
| 53 | + // Apply theme colors |
| 54 | + applyTheme(themeName) { |
| 55 | + let theme; |
| 56 | + let isDarkMode = false; |
| 57 | + |
| 58 | + // Handle theme selection |
| 59 | + if (themeName === 'default') { |
| 60 | + // Use original light/dark toggle behavior |
| 61 | + const currentMode = localStorage.getItem('theme') || 'light'; |
| 62 | + theme = this.defaults[currentMode]; |
| 63 | + isDarkMode = currentMode === 'dark'; |
| 64 | + } else if (themeName === 'catppuccin') { |
| 65 | + // Use Catppuccin behavior |
| 66 | + const currentVariant = localStorage.getItem('catppuccin-variant') || 'latte'; |
| 67 | + theme = this.catppuccin[currentVariant]; |
| 68 | + isDarkMode = currentVariant === 'frappe'; |
| 69 | + } else { |
| 70 | + // Direct theme selection |
| 71 | + if (themeName.startsWith('catppuccin-')) { |
| 72 | + const catppuccinVariant = themeName.replace('catppuccin-', ''); |
| 73 | + theme = this.catppuccin[catppuccinVariant]; |
| 74 | + isDarkMode = catppuccinVariant === 'frappe'; |
| 75 | + } else { |
| 76 | + theme = this.defaults[themeName]; |
| 77 | + isDarkMode = themeName === 'dark'; |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + if (!theme) return; |
| 82 | + |
| 83 | + // Apply colors to CSS custom properties |
| 84 | + Object.entries(theme).forEach(([key, value]) => { |
| 85 | + if (key !== 'name') { |
| 86 | + document.documentElement.style.setProperty(`--user-${key}`, value); |
| 87 | + } |
| 88 | + }); |
| 89 | + |
| 90 | + // Update theme attribute for existing CSS |
| 91 | + document.documentElement.setAttribute('data-theme', isDarkMode ? 'dark' : 'light'); |
| 92 | + |
| 93 | + // Save preference |
| 94 | + localStorage.setItem('notekeeper-theme', themeName); |
| 95 | + |
| 96 | + // Update theme toggle aria-label |
| 97 | + const themeToggle = document.getElementById('theme-toggle'); |
| 98 | + if (themeToggle) { |
| 99 | + const nextTheme = this.getNextTheme(themeName); |
| 100 | + const isNextDark = nextTheme === 'dark' || nextTheme === 'frappe'; |
| 101 | + themeToggle.setAttribute('aria-label', `Switch to ${isNextDark ? 'light' : 'dark'} theme`); |
| 102 | + } |
| 103 | + }, |
| 104 | + |
| 105 | + // Toggle between themes |
| 106 | + toggleTheme() { |
| 107 | + const currentTheme = localStorage.getItem('notekeeper-theme') || 'default'; |
| 108 | + |
| 109 | + if (currentTheme === 'default') { |
| 110 | + // Toggle light/dark in default mode |
| 111 | + const currentMode = localStorage.getItem('theme') || 'light'; |
| 112 | + const nextMode = currentMode === 'light' ? 'dark' : 'light'; |
| 113 | + localStorage.setItem('theme', nextMode); |
| 114 | + this.applyTheme('default'); |
| 115 | + } else if (currentTheme === 'catppuccin') { |
| 116 | + // Toggle latte/frappe in catppuccin mode |
| 117 | + const currentVariant = localStorage.getItem('catppuccin-variant') || 'latte'; |
| 118 | + const nextVariant = currentVariant === 'latte' ? 'frappe' : 'latte'; |
| 119 | + localStorage.setItem('catppuccin-variant', nextVariant); |
| 120 | + this.applyTheme('catppuccin'); |
| 121 | + } else { |
| 122 | + // Direct theme selection - toggle between default themes |
| 123 | + const nextTheme = currentTheme === 'light' ? 'dark' : 'light'; |
| 124 | + localStorage.setItem('notekeeper-theme', nextTheme); |
| 125 | + localStorage.setItem('theme', nextTheme); |
| 126 | + this.applyTheme('default'); |
| 127 | + } |
| 128 | + }, |
| 129 | + |
| 130 | + // Get next theme for aria-label (informational only) |
| 131 | + getNextTheme(currentTheme) { |
| 132 | + if (currentTheme === 'default') { |
| 133 | + const currentMode = localStorage.getItem('theme') || 'light'; |
| 134 | + return currentMode === 'light' ? 'dark' : 'light'; |
| 135 | + } else if (currentTheme === 'catppuccin') { |
| 136 | + const currentVariant = localStorage.getItem('catppuccin-variant') || 'latte'; |
| 137 | + return currentVariant === 'latte' ? 'frappe' : 'latte'; |
| 138 | + } |
| 139 | + return currentTheme === 'light' ? 'dark' : 'light'; |
| 140 | + }, |
| 141 | + |
| 142 | + // Get current theme |
| 143 | + getCurrentTheme() { |
| 144 | + return localStorage.getItem('notekeeper-theme') || 'default'; |
| 145 | + } |
| 146 | +}; |
| 147 | + |
| 148 | +// Initialize on DOM load |
| 149 | +document.addEventListener('DOMContentLoaded', () => { |
| 150 | + colorManager.init(); |
| 151 | +}); |
0 commit comments