11import type { ACCENT_COLORS } from '#shared/utils/constants'
22
3- type AccentColorId = keyof typeof ACCENT_COLORS
3+ type AccentColorId = keyof typeof ACCENT_COLORS . light // for both themes color names are same
44
55/**
66 * Initialize user preferences before hydration to prevent flash/layout shift.
@@ -14,13 +14,24 @@ export function initPreferencesOnPrehydrate() {
1414 // All constants must be hardcoded inside the callback.
1515 onPrehydrate ( ( ) => {
1616 // Accent colors - hardcoded since ACCENT_COLORS can't be referenced
17- const colors : Record < AccentColorId , string > = {
18- rose : 'oklch(0.797 0.084 11.056)' ,
19- amber : 'oklch(0.828 0.165 84.429)' ,
20- emerald : 'oklch(0.792 0.153 166.95)' ,
21- sky : 'oklch(0.787 0.128 230.318)' ,
22- violet : 'oklch(0.714 0.148 286.067)' ,
23- coral : 'oklch(0.704 0.177 14.75)' ,
17+
18+ const colors = {
19+ light : {
20+ coral : 'oklch(0.70 0.19 14.75)' ,
21+ amber : 'oklch(0.8 0.25 84.429)' ,
22+ emerald : 'oklch(0.70 0.17 166.95)' ,
23+ sky : 'oklch(0.70 0.15 230.318)' ,
24+ violet : 'oklch(0.70 0.17 286.067)' ,
25+ magenta : 'oklch(0.75 0.18 330)' ,
26+ } ,
27+ dark : {
28+ coral : 'oklch(0.704 0.177 14.75)' ,
29+ amber : 'oklch(0.828 0.165 84.429)' ,
30+ emerald : 'oklch(0.792 0.153 166.95)' ,
31+ sky : 'oklch(0.787 0.128 230.318)' ,
32+ violet : 'oklch(0.78 0.148 286.067)' ,
33+ magenta : 'oklch(0.78 0.15 330)' ,
34+ } ,
2435 }
2536
2637 // Valid package manager IDs
@@ -29,10 +40,13 @@ export function initPreferencesOnPrehydrate() {
2940 // Read settings from localStorage
3041 const settings = JSON . parse ( localStorage . getItem ( 'npmx-settings' ) || '{}' )
3142
32- // Apply accent color
33- const color = settings . accentColorId ? colors [ settings . accentColorId as AccentColorId ] : null
34- if ( color ) {
35- document . documentElement . style . setProperty ( '--accent-color' , color )
43+ // Determine theme (default to 'dark')
44+ const theme = document . documentElement . dataset . theme === 'light' ? 'light' : 'dark'
45+
46+ // Apply accent color based on theme
47+ const accentColorId = settings . accentColorId as AccentColorId | undefined
48+ if ( accentColorId && colors [ theme ] [ accentColorId ] ) {
49+ document . documentElement . style . setProperty ( '--accent-color' , colors [ theme ] [ accentColorId ] )
3650 }
3751
3852 // Apply background accent
0 commit comments