-
Notifications
You must be signed in to change notification settings - Fork 229
feat: Implement Color Palette Extensibility & Dynamic Theme Registry (#3334) #3510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| export interface ColorPalette { | ||
| primary: string; | ||
| secondary: string; | ||
| background: string; | ||
| text: string; | ||
| border?: string; | ||
| accent?: string; | ||
| } | ||
|
|
||
| export interface ThemeDefinition { | ||
| name: string; | ||
| palette: ColorPalette; | ||
| } | ||
|
|
||
| /** | ||
| * ThemeRegistryManager - Extensible Color Palette & Dynamic Theme Registry Subsystem (#3334). | ||
| */ | ||
| export class ThemeRegistryManager { | ||
| private themes: Map<string, ThemeDefinition> = new Map(); | ||
| private activeThemeName: string = 'default'; | ||
|
|
||
| constructor() { | ||
| this.registerTheme({ | ||
| name: 'default', | ||
| palette: { | ||
| primary: '#3b82f6', | ||
| secondary: '#64748b', | ||
| background: '#0f172a', | ||
| text: '#f8fafc', | ||
| border: '#334155', | ||
| accent: '#eab308', | ||
| }, | ||
| }); | ||
| } | ||
|
Comment on lines
+22
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Register the required built-in presets. The constructor registers only Register the four presets during initialization and add behavior tests for each preset. Based on PR objectives, these four presets are required defaults. 🤖 Prompt for AI Agents |
||
|
|
||
| registerTheme(theme: ThemeDefinition): void { | ||
| if (!theme || !theme.name) return; | ||
| this.themes.set(theme.name, theme); | ||
| } | ||
|
|
||
| setActiveTheme(name: string): boolean { | ||
| if (this.themes.has(name)) { | ||
| this.activeThemeName = name; | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| getActiveTheme(): ThemeDefinition { | ||
| return this.themes.get(this.activeThemeName) || Array.from(this.themes.values())[0]; | ||
| } | ||
|
|
||
| extendPalette(themeName: string, customPalette: Partial<ColorPalette>): void { | ||
| const existing = this.themes.get(themeName); | ||
| if (existing) { | ||
| existing.palette = { | ||
| ...existing.palette, | ||
| ...customPalette, | ||
| }; | ||
|
Comment on lines
+36
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Validate runtime theme data before storage or merge.
Validate required palette keys and color value formats before Based on PR objectives, 🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
|
|
||
| listThemes(): string[] { | ||
| return Array.from(this.themes.keys()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { describe, it, expect, beforeEach } from 'bun:test'; | ||
| import { ThemeRegistryManager } from '../src/theme/themeRegistry'; | ||
|
|
||
| describe('ThemeRegistryManager Unit Tests', () => { | ||
| let registry: ThemeRegistryManager; | ||
|
|
||
| beforeEach(() => { | ||
| registry = new ThemeRegistryManager(); | ||
| }); | ||
|
|
||
| it('should initialize with default theme', () => { | ||
| const active = registry.getActiveTheme(); | ||
| expect(active.name).toBe('default'); | ||
| expect(active.palette.primary).toBe('#3b82f6'); | ||
| }); | ||
|
|
||
| it('should register and switch to custom themes dynamically', () => { | ||
| registry.registerTheme({ | ||
| name: 'dracula', | ||
| palette: { | ||
| primary: '#bd93f9', | ||
| secondary: '#6272a4', | ||
| background: '#282a36', | ||
| text: '#f8f8f2', | ||
| }, | ||
| }); | ||
|
|
||
| expect(registry.listThemes()).toContain('dracula'); | ||
| const switched = registry.setActiveTheme('dracula'); | ||
| expect(switched).toBe(true); | ||
| expect(registry.getActiveTheme().palette.primary).toBe('#bd93f9'); | ||
| }); | ||
|
|
||
| it('should allow extending existing palette colors', () => { | ||
| registry.extendPalette('default', { primary: '#ff0000' }); | ||
| expect(registry.getActiveTheme().palette.primary).toBe('#ff0000'); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Add color-mode metadata and fallback resolution.
ColorPalettestores every color as an undifferentiatedstring. The manager cannot resolve RGB values to 256-color or ANSI 16-color values when terminal support is limited.Use a discriminated color value type and add a capability-aware resolver. Test RGB, indexed, and ANSI fallback behavior.
Based on PR objectives, the registry must support 16-color ANSI, 256-color, TrueColor, and non-TrueColor fallback behavior.
🤖 Prompt for AI Agents