1- import type { ACCENT_COLORS } from '#shared/utils/constants'
2-
3- type AccentColorId = keyof typeof ACCENT_COLORS . light // for both themes color names are same
4-
51/**
62 * Initialize user preferences before hydration to prevent flash/layout shift.
73 * This sets CSS custom properties and data attributes that CSS can use
@@ -13,40 +9,18 @@ export function initPreferencesOnPrehydrate() {
139 // Callback is stringified by Nuxt - external variables won't be available.
1410 // All constants must be hardcoded inside the callback.
1511 onPrehydrate ( ( ) => {
16- // Accent colors - hardcoded since ACCENT_COLORS can't be referenced
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- } ,
35- }
12+ // Valid accent color IDs (must match --swatch-* variables defined in main.css)
13+ const accentColorIds = new Set ( [ 'coral' , 'amber' , 'emerald' , 'sky' , 'violet' , 'magenta' ] )
3614
3715 // Valid package manager IDs
3816 const validPMs = new Set ( [ 'npm' , 'pnpm' , 'yarn' , 'bun' , 'deno' , 'vlt' ] )
3917
4018 // Read settings from localStorage
4119 const settings = JSON . parse ( localStorage . getItem ( 'npmx-settings' ) || '{}' )
4220
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 ] )
21+ const accentColorId = settings . accentColorId
22+ if ( accentColorId && accentColorIds . has ( accentColorId ) ) {
23+ document . documentElement . style . setProperty ( '--accent-color' , `var(--swatch-${ accentColorId } )` )
5024 }
5125
5226 // Apply background accent
0 commit comments