Skip to content

Commit

Permalink
remove formatting from
Browse files Browse the repository at this point in the history
  • Loading branch information
yxshv committed Jun 21, 2023
1 parent a0490f4 commit 8991a71
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const colorSchemes = ['light', 'dark']
const MEDIA = '(prefers-color-scheme: dark)'
const isServer = typeof window === 'undefined'
const ThemeContext = createContext<UseThemeProps | undefined>(undefined)
const defaultContext: UseThemeProps = { setTheme: _ => { }, themes: [] }
const defaultContext: UseThemeProps = { setTheme: _ => {}, themes: [] }

export const useTheme = () => useContext(ThemeContext) ?? defaultContext

Expand Down Expand Up @@ -255,17 +255,20 @@ const ThemeScript = memo(
if (enableSystem) {
return `!function(){try{${optimization}var e=localStorage.getItem('${storageKey}');if('system'===e||(!e&&${defaultSystem})){var t='${MEDIA}',m=window.matchMedia(t);if(m.media!==t||m.matches){${updateDOM(
'dark'
)}}else{${updateDOM('light')}}}else if(e){${value ? `var x=${JSON.stringify(value)};` : ''
}${updateDOM(value ? `x[e]` : 'e', true)}}${!defaultSystem ? `else{` + updateDOM(defaultTheme, false, false) + '}' : ''
}${fallbackColorScheme}}catch(e){}}()`
)}}else{${updateDOM('light')}}}else if(e){${
value ? `var x=${JSON.stringify(value)};` : ''
}${updateDOM(value ? `x[e]` : 'e', true)}}${
!defaultSystem ? `else{` + updateDOM(defaultTheme, false, false) + '}' : ''
}${fallbackColorScheme}}catch(e){}}()`
}

return `!function(){try{${optimization}var e=localStorage.getItem('${storageKey}');if(e){${value ? `var x=${JSON.stringify(value)};` : ''
}${updateDOM(value ? `x[e]` : 'e', true)}}else{${updateDOM(
defaultTheme,
false,
false
)};}${fallbackColorScheme}}catch(t){}}();`
return `!function(){try{${optimization}var e=localStorage.getItem('${storageKey}');if(e){${
value ? `var x=${JSON.stringify(value)};` : ''
}${updateDOM(value ? `x[e]` : 'e', true)}}else{${updateDOM(
defaultTheme,
false,
false
)};}${fallbackColorScheme}}catch(t){}}();`
})()

return <script nonce={nonce} dangerouslySetInnerHTML={{ __html: scriptSrc }} />
Expand Down Expand Up @@ -297,7 +300,7 @@ const disableAnimation = () => {

return () => {
// Force restyle
; (() => window.getComputedStyle(document.body))()
;(() => window.getComputedStyle(document.body))()

// Wait for next tick before removing
setTimeout(() => {
Expand Down

0 comments on commit 8991a71

Please sign in to comment.