@@ -2,6 +2,7 @@ module.exports = {
22 init : ( ) => {
33 const codeToRunOnClient = `
44 (function() {
5+ window.__onThemeChange = function() {};
56 function getInitialColorMode() {
67 const persistedColorPreference = window.localStorage.getItem('nightwind-mode');
78 const hasPersistedPreference = typeof persistedColorPreference === 'string';
@@ -15,12 +16,13 @@ module.exports = {
1516 }
1617 return 'light';
1718 }
19+ window.__theme = getInitialColorMode();
1820 getInitialColorMode() == 'light' ? document.documentElement.classList.remove('dark') : document.documentElement.classList.add('dark');
1921 })()
2022 ` ;
2123 return codeToRunOnClient ;
2224 } ,
23-
25+
2426 beforeTransition : ( ) => {
2527 const doc = document . documentElement ;
2628 const onTransitionDone = ( ) => {
@@ -38,12 +40,16 @@ module.exports = {
3840 if ( ! document . documentElement . classList . contains ( 'dark' ) ) {
3941 document . documentElement . classList . add ( 'dark' ) ;
4042 window . localStorage . setItem ( 'nightwind-mode' , 'dark' ) ;
43+ window . __theme = 'dark' ;
44+ window . __onThemeChange ( ) ;
4145 } else {
4246 document . documentElement . classList . remove ( 'dark' ) ;
4347 window . localStorage . setItem ( 'nightwind-mode' , 'light' ) ;
48+ window . __theme = 'light' ;
49+ window . __onThemeChange ( ) ;
4450 }
4551 } ,
46-
52+
4753 enable : ( dark ) => {
4854 const mode = dark ? "dark" : "light" ;
4955 const opposite = dark ? "light" : "dark" ;
@@ -55,6 +61,8 @@ module.exports = {
5561 }
5662 document . documentElement . classList . add ( mode ) ;
5763 window . localStorage . setItem ( 'nightwind-mode' , mode ) ;
64+ window . __theme = mode ;
65+ window . __onThemeChange ( ) ;
5866 } ,
5967
6068 // Old
0 commit comments