@@ -77,7 +77,7 @@ function cacheThemeVariants(theme: DesktopTheme, themeId: string) {
7777
7878export const { use : useTheme , provider : ThemeProvider } = createSimpleContext ( {
7979 name : "Theme" ,
80- init : ( props : { defaultTheme ?: string } ) => {
80+ init : ( props : { defaultTheme ?: string ; onThemeApplied ?: ( theme : DesktopTheme , mode : "light" | "dark" ) => void } ) => {
8181 const [ store , setStore ] = createStore ( {
8282 themes : DEFAULT_THEMES as Record < string , DesktopTheme > ,
8383 themeId : normalize ( props . defaultTheme ) ?? "oc-2" ,
@@ -119,10 +119,15 @@ export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({
119119 }
120120 } )
121121
122+ const applyTheme = ( theme : DesktopTheme , themeId : string , mode : "light" | "dark" ) => {
123+ applyThemeCss ( theme , themeId , mode )
124+ props . onThemeApplied ?.( theme , mode )
125+ }
126+
122127 createEffect ( ( ) => {
123128 const theme = store . themes [ store . themeId ]
124129 if ( theme ) {
125- applyThemeCss ( theme , store . themeId , store . mode )
130+ applyTheme ( theme , store . themeId , store . mode )
126131 }
127132 } )
128133
@@ -171,15 +176,15 @@ export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({
171176 ? getSystemMode ( )
172177 : store . previewScheme
173178 : store . mode
174- applyThemeCss ( theme , next , previewMode )
179+ applyTheme ( theme , next , previewMode )
175180 } ,
176181 previewColorScheme : ( scheme : ColorScheme ) => {
177182 setStore ( "previewScheme" , scheme )
178183 const previewMode = scheme === "system" ? getSystemMode ( ) : scheme
179184 const id = store . previewThemeId ?? store . themeId
180185 const theme = store . themes [ id ]
181186 if ( theme ) {
182- applyThemeCss ( theme , id , previewMode )
187+ applyTheme ( theme , id , previewMode )
183188 }
184189 } ,
185190 commitPreview : ( ) => {
@@ -197,7 +202,7 @@ export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({
197202 setStore ( "previewScheme" , null )
198203 const theme = store . themes [ store . themeId ]
199204 if ( theme ) {
200- applyThemeCss ( theme , store . themeId , store . mode )
205+ applyTheme ( theme , store . themeId , store . mode )
201206 }
202207 } ,
203208 }
0 commit comments