@@ -72,33 +72,44 @@ export function useAccentColor() {
7272 const { settings } = useSettings ( )
7373 const colorMode = useColorMode ( )
7474
75- const accentColors = computed ( ( ) =>
76- Object . entries ( ACCENT_COLORS [ colorMode . value as 'light' | 'dark' ] ) . map ( ( [ id , value ] ) => ( {
75+ const accentColors = computed ( ( ) => {
76+ const mode = ( colorMode . value || 'dark' ) as 'light' | 'dark'
77+ const colors = ACCENT_COLORS [ mode ]
78+
79+ return Object . entries ( colors ) . map ( ( [ id , value ] ) => ( {
7780 id : id as AccentColorId ,
7881 name : id ,
7982 value,
80- } ) ) ,
81- )
82-
83- const currentAccentColor = computed ( ( ) => {
84- const id = settings . value . accentColorId
85- const theme = colorMode . value as 'light' | 'dark'
86- return id ? ACCENT_COLORS [ theme ] [ id ] : null
83+ } ) )
8784 } )
8885
89- // Simple client-side check
86+ function setAccentColor ( id : AccentColorId | null ) {
87+ const mode = ( colorMode . value || 'dark' ) as 'light' | 'dark'
88+ const color = id ? ACCENT_COLORS [ mode ] [ id ] : null
89+
90+ if ( color ) {
91+ document . documentElement . style . setProperty ( '--accent-color' , color )
92+ } else {
93+ document . documentElement . style . removeProperty ( '--accent-color' )
94+ }
95+
96+ settings . value . accentColorId = id
97+ }
98+
99+ // Apply color on mount and when theme changes
90100 if ( process . client ) {
91- watchEffect ( ( ) => {
92- if ( currentAccentColor . value ) {
93- document . documentElement . style . setProperty ( '--accent-color' , currentAccentColor . value )
94- } else {
95- document . documentElement . style . removeProperty ( '--accent-color' )
96- }
101+ onMounted ( ( ) => {
102+ const id = settings . value . accentColorId
103+ if ( id ) setAccentColor ( id )
97104 } )
98- }
99105
100- function setAccentColor ( id : AccentColorId | null ) {
101- settings . value . accentColorId = id
106+ watch (
107+ ( ) => colorMode . value ,
108+ ( ) => {
109+ const id = settings . value . accentColorId
110+ if ( id ) setAccentColor ( id )
111+ } ,
112+ )
102113 }
103114
104115 return {
0 commit comments