Skip to content

Commit

Permalink
simplify/minify script.ts (#264)
Browse files Browse the repository at this point in the history
* simplify/minify script.ts

* Update script.ts

---------

Co-authored-by: paco <34928425+pacocoursey@users.noreply.github.com>
  • Loading branch information
Dimitri POSTOLOV and pacocoursey authored Mar 13, 2024
1 parent 0459751 commit 19e5225
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions next-themes/src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ export const script = (
enableColorScheme
) => {
const el = document.documentElement
const media = `(prefers-color-scheme: dark)`
const systemThemes = ['light', 'dark']
const isClass = attribute === 'class'
const classes =
isClass && !!value
? themes.map(t => {
return value[t] || t
})
isClass && value
? themes.map(t => value[t] || t)
: themes

function updateDOM(theme: string) {
Expand All @@ -37,19 +34,17 @@ export const script = (
}

function getSystemTheme() {
return window.matchMedia(media).matches ? 'dark' : 'light'
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
}

;(function () {
if (forcedTheme) {
updateDOM(forcedTheme)
} else {
try {
const e = localStorage.getItem(storageKey)
const themeName = e || defaultTheme
const isSystem = enableSystem && themeName === 'system' ? true : false

const theme = isSystem ? getSystemTheme() : e || defaultTheme
const themeName = localStorage.getItem(storageKey) || defaultTheme
const isSystem = enableSystem && themeName === 'system'
const theme = isSystem ? getSystemTheme() : themeName
updateDOM(theme)
} catch (e) {
//
Expand Down

0 comments on commit 19e5225

Please sign in to comment.