Socket
Socket
Sign inDemoInstall

next-themes

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-themes - npm Package Compare versions

Comparing version 0.1.2-beta.0 to 0.2.0-beta.0

1

dist/index.d.ts

@@ -5,1 +5,2 @@ import React from 'react';

export declare const ThemeProvider: React.FC<ThemeProviderProps>;
export declare const Theme: React.FC<ThemeProviderProps>;

2

dist/index.js

@@ -1,1 +0,1 @@

function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=e(require("next/script")),n=require("react"),r=e(n);const a=["light","dark"],s="(prefers-color-scheme: dark)",o="undefined"==typeof window,c=n.createContext({setTheme:e=>{},themes:[]}),l=n.memo(({forcedTheme:e,storageKey:n,attribute:o,enableSystem:c,enableColorScheme:l,defaultTheme:i,value:m,attrs:d,nonce:u})=>{const h="system"===i,f="class"===o?`var d=document.documentElement.classList;d.remove(${d.map(e=>`'${e}'`).join(",")});`:`var d=document.documentElement;var n='${o}';var s = 'setAttribute';`,y=l?a.includes(i)&&i?`if(e==='light'||e==='dark'||!e)d.style.colorScheme=e||'${i}'`:"if(e==='light'||e==='dark')d.style.colorScheme=e":"",v=(e,t=!1,n=!0)=>{const r=m?m[e]:e,s=t?e+"|| ''":`'${r}'`;let c="";return l&&n&&!t&&a.includes(e)&&(c+=`d.style.colorScheme = '${e}';`),"class"===o?c+=t||r?`d.add(${s})`:"null":r&&(c+=`d[s](n, ${s})`),c},$=e?`!function(){${f}${v(e)}}()`:c?`!function(){try {${f}var e=localStorage.getItem('${n}');if("system"===e||(!e&&${h})){var t="${s}",m=window.matchMedia(t);if(m.media!==t||m.matches){${v("dark")}}else{${v("light")}}}else if(e){${m?`var x=${JSON.stringify(m)};`:""}${v(m?"x[e]":"e",!0)}}${h?"":"else{"+v(i,!1,!1)+"}"}${y}}catch(e){}}()`:`!function(){try{${f}var e=localStorage.getItem("${n}");if(e){${m?`var x=${JSON.stringify(m)};`:""}${v(m?"x[e]":"e",!0)}}else{${v(i,!1,!1)};}${y}}catch(t){}}();`;return r.createElement(t,{id:"next-themes-script","data-script":"",strategy:"beforeInteractive",nonce:u},$)},()=>!0),i=(e,t)=>{if(o)return;let n;try{n=localStorage.getItem(e)||void 0}catch(e){}return n||t},m=e=>(e||(e=window.matchMedia(s)),e.matches?"dark":"light");exports.ThemeProvider=({forcedTheme:e,disableTransitionOnChange:t=!1,enableSystem:o=!0,enableColorScheme:d=!0,storageKey:u="theme",themes:h=["light","dark"],defaultTheme:f=(o?"system":"light"),attribute:y="data-theme",value:v,children:$,nonce:g})=>{const[b,p]=n.useState(()=>i(u,f)),[S,T]=n.useState(()=>i(u)),w=v?Object.values(v):h,C=n.useCallback(e=>{let n=e;"system"===e&&o&&(n=m());const r=v?v[n]:n,s=t?(()=>{const e=document.createElement("style");return e.appendChild(document.createTextNode("*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}")),document.head.appendChild(e),()=>{window.getComputedStyle(document.body),setTimeout(()=>{document.head.removeChild(e)},1)}})():null,c=document.documentElement;if("class"===y?(c.classList.remove(...w),r&&c.classList.add(r)):r?c.setAttribute(y,r):c.removeAttribute(y),d){const e=a.includes(f)?f:null,t=a.includes(n)?n:e;c.style.colorScheme=t}null==s||s()},[]),k=n.useCallback(e=>{p(e);try{localStorage.setItem(u,e)}catch(e){}},[e]),E=n.useCallback(t=>{const n=m(t);T(n),"system"===b&&o&&!e&&C("system")},[b,e]);return n.useEffect(()=>{const e=window.matchMedia(s);return e.addListener(E),E(e),()=>e.removeListener(E)},[E]),n.useEffect(()=>{const e=e=>{e.key===u&&k(e.newValue||f)};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[k]),n.useEffect(()=>{C(null!=e?e:b)},[e,b]),r.createElement(c.Provider,{value:{theme:b,setTheme:k,forcedTheme:e,resolvedTheme:"system"===b?S:b,themes:o?[...h,"system"]:h,systemTheme:o?S:void 0}},r.createElement(l,{forcedTheme:e,disableTransitionOnChange:t,enableSystem:o,enableColorScheme:d,storageKey:u,themes:h,defaultTheme:f,attribute:y,value:v,children:$,attrs:w,nonce:g}),$)},exports.useTheme=()=>n.useContext(c);
var e,t=require("react"),n=(e=t)&&"object"==typeof e&&"default"in e?e.default:e;const r=["light","dark"],a="(prefers-color-scheme: dark)",o="undefined"==typeof window,s=t.createContext(void 0),l={setTheme:e=>{},themes:[]},m=({forcedTheme:e,disableTransitionOnChange:o=!1,enableSystem:l=!0,enableColorScheme:m=!0,storageKey:h="theme",themes:f=["light","dark"],defaultTheme:y=(l?"system":"light"),attribute:v="data-theme",value:$,children:g,nonce:b})=>{const[S,T]=t.useState(()=>i(h,y)),[p,w]=t.useState(()=>i(h)),C=$?Object.values($):f,E=t.useCallback(e=>{let t=e;if(!t)return;"system"===e&&l&&(t=u());const n=$?$[t]:t,a=o?d():null,s=document.documentElement;if("class"===v?(s.classList.remove(...C),n&&s.classList.add(n)):n?s.setAttribute(v,n):s.removeAttribute(v),m){const e=r.includes(y)?y:null,n=r.includes(t)?t:e;s.style.colorScheme=n}null==a||a()},[]),k=t.useCallback(e=>{T(e);try{localStorage.setItem(h,e)}catch(e){}},[e]),x=t.useCallback(t=>{const n=u(t);w(n),"system"===S&&l&&!e&&E("system")},[S,e]);return t.useEffect(()=>{const e=window.matchMedia(a);return e.addListener(x),x(e),()=>e.removeListener(x)},[x]),t.useEffect(()=>{const e=e=>{e.key===h&&k(e.newValue||y)};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[k]),t.useEffect(()=>{E(null!=e?e:S)},[e,S]),n.createElement(s.Provider,{value:{theme:S,setTheme:k,forcedTheme:e,resolvedTheme:"system"===S?p:S,themes:l?[...f,"system"]:f,systemTheme:l?p:void 0}},n.createElement(c,{forcedTheme:e,disableTransitionOnChange:o,enableSystem:l,enableColorScheme:m,storageKey:h,themes:f,defaultTheme:y,attribute:v,value:$,children:g,attrs:C,nonce:b}),g)},c=t.memo(({forcedTheme:e,storageKey:t,attribute:o,enableSystem:s,enableColorScheme:l,defaultTheme:m,value:c,attrs:i,nonce:d})=>{const u="system"===m,h="class"===o?`var d=document.documentElement.classList;d.remove(${i.map(e=>`'${e}'`).join(",")});`:`var d=document.documentElement;var n='${o}';var s = 'setAttribute';`,f=l?r.includes(m)&&m?`if(e==='light'||e==='dark'||!e)d.style.colorScheme=e||'${m}'`:"if(e==='light'||e==='dark')d.style.colorScheme=e":"",y=(e,t=!1,n=!0)=>{const a=c?c[e]:e,s=t?e+"|| ''":`'${a}'`;let m="";return l&&n&&!t&&r.includes(e)&&(m+=`d.style.colorScheme = '${e}';`),"class"===o?m+=t||a?`d.add(${s})`:"null":a&&(m+=`d[s](n, ${s})`),m},v=e?`!function(){${h}${y(e)}}()`:s?`!function(){try {${h}var e=localStorage.getItem('${t}');if("system"===e||(!e&&${u})){var t="${a}",m=window.matchMedia(t);if(m.media!==t||m.matches){${y("dark")}}else{${y("light")}}}else if(e){${c?`var x=${JSON.stringify(c)};`:""}${y(c?"x[e]":"e",!0)}}${u?"":"else{"+y(m,!1,!1)+"}"}${f}}catch(e){}}()`:`!function(){try{${h}var e=localStorage.getItem("${t}");if(e){${c?`var x=${JSON.stringify(c)};`:""}${y(c?"x[e]":"e",!0)}}else{${y(m,!1,!1)};}${f}}catch(t){}}();`;return n.createElement("script",{nonce:d,dangerouslySetInnerHTML:{__html:v}})},()=>!0),i=(e,t)=>{if(o)return;let n;try{n=localStorage.getItem(e)||void 0}catch(e){}return n||t},d=()=>{const e=document.createElement("style");return e.appendChild(document.createTextNode("*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}")),document.head.appendChild(e),()=>{window.getComputedStyle(document.body),setTimeout(()=>{document.head.removeChild(e)},1)}},u=e=>(e||(e=window.matchMedia(a)),e.matches?"dark":"light");exports.Theme=m,exports.ThemeProvider=e=>t.useContext(s)?n.createElement(t.Fragment,null,e.children):n.createElement(m,e),exports.useTheme=()=>{var e;return null!==(e=t.useContext(s))&&void 0!==e?e:l};

@@ -1,1 +0,1 @@

import e from"next/script";import t,{useContext as n,useState as r,useCallback as o,useEffect as a,memo as s,createContext as i}from"react";const m=["light","dark"],l="(prefers-color-scheme: dark)",c="undefined"==typeof window,d=i({setTheme:e=>{},themes:[]}),h=()=>n(d),u=({forcedTheme:e,disableTransitionOnChange:n=!1,enableSystem:s=!0,enableColorScheme:i=!0,storageKey:c="theme",themes:h=["light","dark"],defaultTheme:u=(s?"system":"light"),attribute:g="data-theme",value:p,children:b,nonce:S})=>{const[w,T]=r(()=>$(c,u)),[k,C]=r(()=>$(c)),E=p?Object.values(p):h,x=o(e=>{let t=e;"system"===e&&s&&(t=f());const r=p?p[t]:t,o=n?v():null,a=document.documentElement;if("class"===g?(a.classList.remove(...E),r&&a.classList.add(r)):r?a.setAttribute(g,r):a.removeAttribute(g),i){const e=m.includes(u)?u:null,n=m.includes(t)?t:e;a.style.colorScheme=n}null==o||o()},[]),L=o(e=>{T(e);try{localStorage.setItem(c,e)}catch(e){}},[e]),I=o(t=>{const n=f(t);C(n),"system"===w&&s&&!e&&x("system")},[w,e]);return a(()=>{const e=window.matchMedia(l);return e.addListener(I),I(e),()=>e.removeListener(I)},[I]),a(()=>{const e=e=>{e.key===c&&L(e.newValue||u)};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[L]),a(()=>{x(null!=e?e:w)},[e,w]),t.createElement(d.Provider,{value:{theme:w,setTheme:L,forcedTheme:e,resolvedTheme:"system"===w?k:w,themes:s?[...h,"system"]:h,systemTheme:s?k:void 0}},t.createElement(y,{forcedTheme:e,disableTransitionOnChange:n,enableSystem:s,enableColorScheme:i,storageKey:c,themes:h,defaultTheme:u,attribute:g,value:p,children:b,attrs:E,nonce:S}),b)},y=s(({forcedTheme:n,storageKey:r,attribute:o,enableSystem:a,enableColorScheme:s,defaultTheme:i,value:c,attrs:d,nonce:h})=>{const u="system"===i,y="class"===o?`var d=document.documentElement.classList;d.remove(${d.map(e=>`'${e}'`).join(",")});`:`var d=document.documentElement;var n='${o}';var s = 'setAttribute';`,$=s?m.includes(i)&&i?`if(e==='light'||e==='dark'||!e)d.style.colorScheme=e||'${i}'`:"if(e==='light'||e==='dark')d.style.colorScheme=e":"",v=(e,t=!1,n=!0)=>{const r=c?c[e]:e,a=t?e+"|| ''":`'${r}'`;let i="";return s&&n&&!t&&m.includes(e)&&(i+=`d.style.colorScheme = '${e}';`),"class"===o?i+=t||r?`d.add(${a})`:"null":r&&(i+=`d[s](n, ${a})`),i},f=n?`!function(){${y}${v(n)}}()`:a?`!function(){try {${y}var e=localStorage.getItem('${r}');if("system"===e||(!e&&${u})){var t="${l}",m=window.matchMedia(t);if(m.media!==t||m.matches){${v("dark")}}else{${v("light")}}}else if(e){${c?`var x=${JSON.stringify(c)};`:""}${v(c?"x[e]":"e",!0)}}${u?"":"else{"+v(i,!1,!1)+"}"}${$}}catch(e){}}()`:`!function(){try{${y}var e=localStorage.getItem("${r}");if(e){${c?`var x=${JSON.stringify(c)};`:""}${v(c?"x[e]":"e",!0)}}else{${v(i,!1,!1)};}${$}}catch(t){}}();`;return t.createElement(e,{id:"next-themes-script","data-script":"",strategy:"beforeInteractive",nonce:h},f)},()=>!0),$=(e,t)=>{if(c)return;let n;try{n=localStorage.getItem(e)||void 0}catch(e){}return n||t},v=()=>{const e=document.createElement("style");return e.appendChild(document.createTextNode("*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}")),document.head.appendChild(e),()=>{window.getComputedStyle(document.body),setTimeout(()=>{document.head.removeChild(e)},1)}},f=e=>(e||(e=window.matchMedia(l)),e.matches?"dark":"light");export{u as ThemeProvider,h as useTheme};
import e,{useContext as t,Fragment as n,useState as r,useCallback as o,useEffect as a,memo as s,createContext as l}from"react";const m=["light","dark"],i="(prefers-color-scheme: dark)",c="undefined"==typeof window,d=l(void 0),u={setTheme:e=>{},themes:[]},h=()=>{var e;return null!==(e=t(d))&&void 0!==e?e:u},y=r=>t(d)?e.createElement(n,null,r.children):e.createElement(v,r),v=({forcedTheme:t,disableTransitionOnChange:n=!1,enableSystem:s=!0,enableColorScheme:l=!0,storageKey:c="theme",themes:u=["light","dark"],defaultTheme:h=(s?"system":"light"),attribute:y="data-theme",value:v,children:b,nonce:p})=>{const[w,T]=r(()=>f(c,h)),[E,k]=r(()=>f(c)),C=v?Object.values(v):u,L=o(e=>{let t=e;if(!t)return;"system"===e&&s&&(t=S());const r=v?v[t]:t,o=n?g():null,a=document.documentElement;if("class"===y?(a.classList.remove(...C),r&&a.classList.add(r)):r?a.setAttribute(y,r):a.removeAttribute(y),l){const e=m.includes(h)?h:null,n=m.includes(t)?t:e;a.style.colorScheme=n}null==o||o()},[]),x=o(e=>{T(e);try{localStorage.setItem(c,e)}catch(e){}},[t]),I=o(e=>{const n=S(e);k(n),"system"===w&&s&&!t&&L("system")},[w,t]);return a(()=>{const e=window.matchMedia(i);return e.addListener(I),I(e),()=>e.removeListener(I)},[I]),a(()=>{const e=e=>{e.key===c&&x(e.newValue||h)};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[x]),a(()=>{L(null!=t?t:w)},[t,w]),e.createElement(d.Provider,{value:{theme:w,setTheme:x,forcedTheme:t,resolvedTheme:"system"===w?E:w,themes:s?[...u,"system"]:u,systemTheme:s?E:void 0}},e.createElement($,{forcedTheme:t,disableTransitionOnChange:n,enableSystem:s,enableColorScheme:l,storageKey:c,themes:u,defaultTheme:h,attribute:y,value:v,children:b,attrs:C,nonce:p}),b)},$=s(({forcedTheme:t,storageKey:n,attribute:r,enableSystem:o,enableColorScheme:a,defaultTheme:s,value:l,attrs:c,nonce:d})=>{const u="system"===s,h="class"===r?`var d=document.documentElement.classList;d.remove(${c.map(e=>`'${e}'`).join(",")});`:`var d=document.documentElement;var n='${r}';var s = 'setAttribute';`,y=a?m.includes(s)&&s?`if(e==='light'||e==='dark'||!e)d.style.colorScheme=e||'${s}'`:"if(e==='light'||e==='dark')d.style.colorScheme=e":"",v=(e,t=!1,n=!0)=>{const o=l?l[e]:e,s=t?e+"|| ''":`'${o}'`;let i="";return a&&n&&!t&&m.includes(e)&&(i+=`d.style.colorScheme = '${e}';`),"class"===r?i+=t||o?`d.add(${s})`:"null":o&&(i+=`d[s](n, ${s})`),i},$=t?`!function(){${h}${v(t)}}()`:o?`!function(){try {${h}var e=localStorage.getItem('${n}');if("system"===e||(!e&&${u})){var t="${i}",m=window.matchMedia(t);if(m.media!==t||m.matches){${v("dark")}}else{${v("light")}}}else if(e){${l?`var x=${JSON.stringify(l)};`:""}${v(l?"x[e]":"e",!0)}}${u?"":"else{"+v(s,!1,!1)+"}"}${y}}catch(e){}}()`:`!function(){try{${h}var e=localStorage.getItem("${n}");if(e){${l?`var x=${JSON.stringify(l)};`:""}${v(l?"x[e]":"e",!0)}}else{${v(s,!1,!1)};}${y}}catch(t){}}();`;return e.createElement("script",{nonce:d,dangerouslySetInnerHTML:{__html:$}})},()=>!0),f=(e,t)=>{if(c)return;let n;try{n=localStorage.getItem(e)||void 0}catch(e){}return n||t},g=()=>{const e=document.createElement("style");return e.appendChild(document.createTextNode("*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}")),document.head.appendChild(e),()=>{window.getComputedStyle(document.body),setTimeout(()=>{document.head.removeChild(e)},1)}},S=e=>(e||(e=window.matchMedia(i)),e.matches?"dark":"light");export{v as Theme,y as ThemeProvider,h as useTheme};

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("next/script"),require("react")):"function"==typeof define&&define.amd?define(["exports","next/script","react"],t):t((e=e||self).nextThemes={},e.NextScript,e.react)}(this,function(e,t,n){t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t;var r="default"in n?n.default:n;const a=["light","dark"],s="(prefers-color-scheme: dark)",o="undefined"==typeof window,c=n.createContext({setTheme:e=>{},themes:[]}),i=n.memo(({forcedTheme:e,storageKey:n,attribute:o,enableSystem:c,enableColorScheme:i,defaultTheme:l,value:m,attrs:d,nonce:u})=>{const h="system"===l,f="class"===o?`var d=document.documentElement.classList;d.remove(${d.map(e=>`'${e}'`).join(",")});`:`var d=document.documentElement;var n='${o}';var s = 'setAttribute';`,y=i?a.includes(l)&&l?`if(e==='light'||e==='dark'||!e)d.style.colorScheme=e||'${l}'`:"if(e==='light'||e==='dark')d.style.colorScheme=e":"",v=(e,t=!1,n=!0)=>{const r=m?m[e]:e,s=t?e+"|| ''":`'${r}'`;let c="";return i&&n&&!t&&a.includes(e)&&(c+=`d.style.colorScheme = '${e}';`),"class"===o?c+=t||r?`d.add(${s})`:"null":r&&(c+=`d[s](n, ${s})`),c},$=e?`!function(){${f}${v(e)}}()`:c?`!function(){try {${f}var e=localStorage.getItem('${n}');if("system"===e||(!e&&${h})){var t="${s}",m=window.matchMedia(t);if(m.media!==t||m.matches){${v("dark")}}else{${v("light")}}}else if(e){${m?`var x=${JSON.stringify(m)};`:""}${v(m?"x[e]":"e",!0)}}${h?"":"else{"+v(l,!1,!1)+"}"}${y}}catch(e){}}()`:`!function(){try{${f}var e=localStorage.getItem("${n}");if(e){${m?`var x=${JSON.stringify(m)};`:""}${v(m?"x[e]":"e",!0)}}else{${v(l,!1,!1)};}${y}}catch(t){}}();`;return r.createElement(t,{id:"next-themes-script","data-script":"",strategy:"beforeInteractive",nonce:u},$)},()=>!0),l=(e,t)=>{if(o)return;let n;try{n=localStorage.getItem(e)||void 0}catch(e){}return n||t},m=e=>(e||(e=window.matchMedia(s)),e.matches?"dark":"light");e.ThemeProvider=({forcedTheme:e,disableTransitionOnChange:t=!1,enableSystem:o=!0,enableColorScheme:d=!0,storageKey:u="theme",themes:h=["light","dark"],defaultTheme:f=(o?"system":"light"),attribute:y="data-theme",value:v,children:$,nonce:p})=>{const[g,b]=n.useState(()=>l(u,f)),[S,T]=n.useState(()=>l(u)),w=v?Object.values(v):h,x=n.useCallback(e=>{let n=e;"system"===e&&o&&(n=m());const r=v?v[n]:n,s=t?(()=>{const e=document.createElement("style");return e.appendChild(document.createTextNode("*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}")),document.head.appendChild(e),()=>{window.getComputedStyle(document.body),setTimeout(()=>{document.head.removeChild(e)},1)}})():null,c=document.documentElement;if("class"===y?(c.classList.remove(...w),r&&c.classList.add(r)):r?c.setAttribute(y,r):c.removeAttribute(y),d){const e=a.includes(f)?f:null,t=a.includes(n)?n:e;c.style.colorScheme=t}null==s||s()},[]),C=n.useCallback(e=>{b(e);try{localStorage.setItem(u,e)}catch(e){}},[e]),k=n.useCallback(t=>{const n=m(t);T(n),"system"===g&&o&&!e&&x("system")},[g,e]);return n.useEffect(()=>{const e=window.matchMedia(s);return e.addListener(k),k(e),()=>e.removeListener(k)},[k]),n.useEffect(()=>{const e=e=>{e.key===u&&C(e.newValue||f)};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[C]),n.useEffect(()=>{x(null!=e?e:g)},[e,g]),r.createElement(c.Provider,{value:{theme:g,setTheme:C,forcedTheme:e,resolvedTheme:"system"===g?S:g,themes:o?[...h,"system"]:h,systemTheme:o?S:void 0}},r.createElement(i,{forcedTheme:e,disableTransitionOnChange:t,enableSystem:o,enableColorScheme:d,storageKey:u,themes:h,defaultTheme:f,attribute:y,value:v,children:$,attrs:w,nonce:p}),$)},e.useTheme=()=>n.useContext(c)});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e=e||self).nextThemes={},e.react)}(this,function(e,t){var n="default"in t?t.default:t;const r=["light","dark"],o="(prefers-color-scheme: dark)",a="undefined"==typeof window,s=t.createContext(void 0),l={setTheme:e=>{},themes:[]},i=({forcedTheme:e,disableTransitionOnChange:a=!1,enableSystem:l=!0,enableColorScheme:i=!0,storageKey:h="theme",themes:f=["light","dark"],defaultTheme:y=(l?"system":"light"),attribute:v="data-theme",value:$,children:g,nonce:b})=>{const[p,S]=t.useState(()=>m(h,y)),[T,w]=t.useState(()=>m(h)),C=$?Object.values($):f,E=t.useCallback(e=>{let t=e;if(!t)return;"system"===e&&l&&(t=u());const n=$?$[t]:t,o=a?d():null,s=document.documentElement;if("class"===v?(s.classList.remove(...C),n&&s.classList.add(n)):n?s.setAttribute(v,n):s.removeAttribute(v),i){const e=r.includes(y)?y:null,n=r.includes(t)?t:e;s.style.colorScheme=n}null==o||o()},[]),k=t.useCallback(e=>{S(e);try{localStorage.setItem(h,e)}catch(e){}},[e]),x=t.useCallback(t=>{const n=u(t);w(n),"system"===p&&l&&!e&&E("system")},[p,e]);return t.useEffect(()=>{const e=window.matchMedia(o);return e.addListener(x),x(e),()=>e.removeListener(x)},[x]),t.useEffect(()=>{const e=e=>{e.key===h&&k(e.newValue||y)};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[k]),t.useEffect(()=>{E(null!=e?e:p)},[e,p]),n.createElement(s.Provider,{value:{theme:p,setTheme:k,forcedTheme:e,resolvedTheme:"system"===p?T:p,themes:l?[...f,"system"]:f,systemTheme:l?T:void 0}},n.createElement(c,{forcedTheme:e,disableTransitionOnChange:a,enableSystem:l,enableColorScheme:i,storageKey:h,themes:f,defaultTheme:y,attribute:v,value:$,children:g,attrs:C,nonce:b}),g)},c=t.memo(({forcedTheme:e,storageKey:t,attribute:a,enableSystem:s,enableColorScheme:l,defaultTheme:i,value:c,attrs:m,nonce:d})=>{const u="system"===i,h="class"===a?`var d=document.documentElement.classList;d.remove(${m.map(e=>`'${e}'`).join(",")});`:`var d=document.documentElement;var n='${a}';var s = 'setAttribute';`,f=l?r.includes(i)&&i?`if(e==='light'||e==='dark'||!e)d.style.colorScheme=e||'${i}'`:"if(e==='light'||e==='dark')d.style.colorScheme=e":"",y=(e,t=!1,n=!0)=>{const o=c?c[e]:e,s=t?e+"|| ''":`'${o}'`;let i="";return l&&n&&!t&&r.includes(e)&&(i+=`d.style.colorScheme = '${e}';`),"class"===a?i+=t||o?`d.add(${s})`:"null":o&&(i+=`d[s](n, ${s})`),i},v=e?`!function(){${h}${y(e)}}()`:s?`!function(){try {${h}var e=localStorage.getItem('${t}');if("system"===e||(!e&&${u})){var t="${o}",m=window.matchMedia(t);if(m.media!==t||m.matches){${y("dark")}}else{${y("light")}}}else if(e){${c?`var x=${JSON.stringify(c)};`:""}${y(c?"x[e]":"e",!0)}}${u?"":"else{"+y(i,!1,!1)+"}"}${f}}catch(e){}}()`:`!function(){try{${h}var e=localStorage.getItem("${t}");if(e){${c?`var x=${JSON.stringify(c)};`:""}${y(c?"x[e]":"e",!0)}}else{${y(i,!1,!1)};}${f}}catch(t){}}();`;return n.createElement("script",{nonce:d,dangerouslySetInnerHTML:{__html:v}})},()=>!0),m=(e,t)=>{if(a)return;let n;try{n=localStorage.getItem(e)||void 0}catch(e){}return n||t},d=()=>{const e=document.createElement("style");return e.appendChild(document.createTextNode("*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}")),document.head.appendChild(e),()=>{window.getComputedStyle(document.body),setTimeout(()=>{document.head.removeChild(e)},1)}},u=e=>(e||(e=window.matchMedia(o)),e.matches?"dark":"light");e.Theme=i,e.ThemeProvider=e=>t.useContext(s)?n.createElement(t.Fragment,null,e.children):n.createElement(i,e),e.useTheme=()=>{var e;return null!==(e=t.useContext(s))&&void 0!==e?e:l}});
{
"name": "next-themes",
"version": "0.1.2-beta.0",
"version": "0.2.0-beta.0",
"main": "./dist/index.js",

@@ -5,0 +5,0 @@ "module": "./dist/index.modern.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc