|
| 1 | +# Design Document |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The dynamic theming system will extract color values from the existing style.css file and create a modular theme architecture. The system will use CSS custom properties (CSS variables) to enable runtime theme switching without page reloads. The architecture will consist of theme definition files, a theme manager service, and a user interface for theme selection. |
| 6 | + |
| 7 | +## Architecture |
| 8 | + |
| 9 | +### Theme Structure |
| 10 | +- **Theme Files**: CSS files containing CSS custom property definitions for each theme |
| 11 | +- **Base Variables**: Core CSS custom properties that all themes implement |
| 12 | +- **Theme Manager**: TypeScript service that handles theme loading and switching |
| 13 | +- **Theme UI**: Interface component for theme selection and preview |
| 14 | + |
| 15 | +### File Organization |
| 16 | +``` |
| 17 | +public/assets/themes/ |
| 18 | +├── base-variables.css # Base CSS custom properties structure |
| 19 | +├── default.css # Default theme extracted from current colors |
| 20 | +└── [future-themes].css # Additional themes (e.g., dark.css, light.css) |
| 21 | +
|
| 22 | +src/lib/ |
| 23 | +└── theme-manager.ts # Theme management service |
| 24 | +
|
| 25 | +src/modals/ |
| 26 | +└── theme-selector.ts # Theme selection modal |
| 27 | +``` |
| 28 | + |
| 29 | +## Components and Interfaces |
| 30 | + |
| 31 | +### Theme CSS Structure |
| 32 | +Each theme CSS file will define the same set of CSS custom properties: |
| 33 | +```css |
| 34 | +/* Example: default.css */ |
| 35 | +:root { |
| 36 | + /* Background colors */ |
| 37 | + --color-body-background: #eee; |
| 38 | + --color-outliner-background: #fff; |
| 39 | + --color-modal-background: #fff; |
| 40 | + |
| 41 | + /* Text colors */ |
| 42 | + --color-primary-text: #222; |
| 43 | + --color-secondary-text: #aaa; |
| 44 | + --color-link: #098bd9; |
| 45 | + --color-link-visited: #b26be4; |
| 46 | + |
| 47 | + /* Interactive states */ |
| 48 | + --color-cursor-background: #000; |
| 49 | + --color-cursor-text: #fff; |
| 50 | + --color-selected-background: #000; |
| 51 | + --color-selected-text: #fff; |
| 52 | + |
| 53 | + /* UI elements */ |
| 54 | + --color-border: #ddd; |
| 55 | + --color-button-background: #eee; |
| 56 | + --color-button-hover: #f4f4f4; |
| 57 | + |
| 58 | + /* Specialized elements */ |
| 59 | + --color-date-header-background: #547883; |
| 60 | + --color-table-header-background: #666; |
| 61 | + --color-strikethrough: #808080; |
| 62 | + --color-code-background: #eee; |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +### Theme Metadata Structure |
| 67 | +Theme metadata will be embedded in CSS file headers using comments: |
| 68 | +```css |
| 69 | +/* |
| 70 | +name: Default Theme |
| 71 | +author: Original Author |
| 72 | +version: 1.0.0 |
| 73 | +description: The original color scheme extracted from style.css |
| 74 | +*/ |
| 75 | + |
| 76 | +:root { |
| 77 | + /* CSS custom properties... */ |
| 78 | +} |
| 79 | +``` |
| 80 | + |
| 81 | +### Theme Metadata Interface |
| 82 | +```typescript |
| 83 | +interface ThemeInfo { |
| 84 | + name: string; |
| 85 | + author?: string; |
| 86 | + version?: string; |
| 87 | + description?: string; |
| 88 | + filename: string; |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +### Theme Manager Service |
| 93 | +```typescript |
| 94 | +class ThemeManager { |
| 95 | + private currentTheme: string; |
| 96 | + private availableThemes: ThemeInfo[]; |
| 97 | + private currentThemeLink: HTMLLinkElement | null; |
| 98 | + |
| 99 | + async loadTheme(themeName: string): Promise<void> |
| 100 | + async switchTheme(themeName: string): Promise<void> |
| 101 | + getCurrentTheme(): string |
| 102 | + getAvailableThemes(): ThemeInfo[] |
| 103 | + private loadThemeCSS(filename: string): Promise<void> |
| 104 | + private removeCurrentTheme(): void |
| 105 | + private parseThemeMetadata(cssContent: string): ThemeInfo |
| 106 | + private discoverAvailableThemes(): Promise<ThemeInfo[]> |
| 107 | + private persistThemePreference(themeName: string): void |
| 108 | + private loadThemePreference(): string |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +## Data Models |
| 113 | + |
| 114 | +### Theme Storage |
| 115 | +- **Location**: `public/assets/themes/` directory |
| 116 | +- **Format**: CSS files with CSS custom property definitions |
| 117 | +- **Naming**: `{theme-name}.css` (e.g., `default.css`, `dark.css`) |
| 118 | + |
| 119 | +### Theme Loading Mechanism |
| 120 | +- **Dynamic Loading**: Themes loaded by injecting `<link>` elements into document head |
| 121 | +- **Theme Switching**: Remove previous theme link and add new theme link |
| 122 | +- **CSS Cascade**: Theme CSS custom properties override base styles automatically |
| 123 | +- **Metadata Parsing**: Fetch theme CSS files to extract metadata from header comments |
| 124 | +- **Theme Discovery**: Scan themes directory for available CSS files and parse their metadata |
| 125 | + |
| 126 | +### Theme Persistence |
| 127 | +- **Storage**: localStorage |
| 128 | +- **Key**: `outliner-theme-preference` |
| 129 | +- **Value**: Theme name string |
| 130 | + |
| 131 | +## Error Handling |
| 132 | + |
| 133 | +### Theme Loading Failures |
| 134 | +- **Fallback**: Always fall back to default theme if requested theme fails to load |
| 135 | +- **CSS Load Detection**: Monitor link element load/error events |
| 136 | +- **User Feedback**: Display error messages for failed theme operations |
| 137 | + |
| 138 | +### Missing Theme Files |
| 139 | +- **Detection**: Handle CSS file 404 errors gracefully |
| 140 | +- **Recovery**: Provide list of available themes if requested theme is missing |
| 141 | +- **Logging**: Log theme-related errors for debugging |
| 142 | + |
| 143 | +### CSS Variable Support |
| 144 | +- **Browser Compatibility**: Detect CSS custom property support |
| 145 | +- **Graceful Degradation**: Fall back to static CSS if variables not supported |
| 146 | +- **Progressive Enhancement**: Enhance experience for modern browsers |
| 147 | + |
| 148 | +## Testing Strategy |
| 149 | + |
| 150 | +### Unit Tests |
| 151 | +- **Theme Manager**: Test theme loading, switching, and persistence |
| 152 | +- **CSS Loading**: Test dynamic CSS file loading and error handling |
| 153 | +- **Theme Detection**: Test available theme discovery |
| 154 | + |
| 155 | +### Integration Tests |
| 156 | +- **Theme Switching**: Test complete theme switching workflow |
| 157 | +- **UI Integration**: Test theme selector modal functionality |
| 158 | +- **Persistence**: Test theme preference saving and loading |
| 159 | + |
| 160 | +### Visual Testing |
| 161 | +- **Theme Consistency**: Verify all UI elements update correctly with theme changes |
| 162 | +- **Color Contrast**: Ensure accessibility standards are met for all themes |
| 163 | +- **Interactive States**: Test hover, selected, and cursor states across themes |
| 164 | + |
| 165 | +### Browser Compatibility |
| 166 | +- **CSS Variables**: Test in browsers with and without CSS custom property support |
| 167 | +- **Theme Persistence**: Test localStorage functionality across browsers |
| 168 | +- **Performance**: Measure theme switching performance impact |
0 commit comments