File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,6 +4,9 @@ import { useEventListener } from '@vueuse/core'
44const route = useRoute ()
55const router = useRouter ()
66
7+ // Initialize accent color before hydration to prevent flash
8+ initAccentOnPrehydrate ()
9+
710const isHomepage = computed (() => route .path === ' /' )
811
912useHead ({
Original file line number Diff line number Diff line change @@ -80,3 +80,27 @@ export function useAccentColor() {
8080 setAccentColor,
8181 }
8282}
83+
84+ /**
85+ * Applies accent color before hydration to prevent flash of default color.
86+ * Call this from app.vue to ensure accent color is applied on every page.
87+ */
88+ export function initAccentOnPrehydrate ( ) {
89+ // Callback is stringified by Nuxt - external variables won't be available.
90+ // Colors must be hardcoded since ACCENT_COLORS can't be referenced.
91+ onPrehydrate ( ( ) => {
92+ const colors : Record < AccentColorId , string > = {
93+ rose : '#e9aeba' ,
94+ amber : '#fbbf24' ,
95+ emerald : '#34d399' ,
96+ sky : '#38bdf8' ,
97+ violet : '#a78bfa' ,
98+ coral : '#fb7185' ,
99+ }
100+ const settings = JSON . parse ( localStorage . getItem ( 'npmx-settings' ) || '{}' )
101+ const color = settings . accentColorId ? colors [ settings . accentColorId as AccentColorId ] : null
102+ if ( color ) {
103+ document . documentElement . style . setProperty ( '--accent-color' , color )
104+ }
105+ } )
106+ }
Original file line number Diff line number Diff line change 1- import { ACCENT_COLORS } from './shared/utils/constants'
2-
3- const accentInitScript = `(function(){var s=JSON.parse(localStorage.getItem('npmx-settings'));if(s&&s.accentColorId){document.documentElement.style.setProperty('--accent-color',${ JSON . stringify ( ACCENT_COLORS ) } [s.accentColorId])}})()`
4-
51export default defineNuxtConfig ( {
62 modules : [
73 function ( _ , nuxt ) {
@@ -50,11 +46,6 @@ export default defineNuxtConfig({
5046 href : '/opensearch.xml' ,
5147 } ,
5248 ] ,
53- script : [
54- {
55- innerHTML : accentInitScript ,
56- } ,
57- ] ,
5849 } ,
5950 } ,
6051
You can’t perform that action at this time.
0 commit comments