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.2.0-beta.0 to 0.2.0-beta.1

dist/index.modern.mjs

2

dist/index.d.ts
import React from 'react';
import { ThemeProviderProps, UseThemeProps } from './types';
import type { UseThemeProps, ThemeProviderProps } from './types';
export declare const useTheme: () => UseThemeProps;
export declare const ThemeProvider: React.FC<ThemeProviderProps>;
export declare const Theme: React.FC<ThemeProviderProps>;

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

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

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

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};
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";import i from"next/script";const m=["light","dark"],c="(prefers-color-scheme: dark)",d="undefined"==typeof window,u=/*#__PURE__*/l(void 0),h={setTheme:e=>{},themes:[]},y=()=>{var e;return null!==(e=t(u))&&void 0!==e?e:h},v=r=>t(u)?/*#__PURE__*/e.createElement(n,null,r.children):/*#__PURE__*/e.createElement($,r),$=({forcedTheme:t,disableTransitionOnChange:n=!1,enableSystem:s=!0,enableColorScheme:l=!0,storageKey:i="theme",themes:d=["light","dark"],defaultTheme:h=(s?"system":"light"),attribute:y="data-theme",value:v,children:$,nonce:S})=>{const[w,T]=r(()=>g(i,h)),[E,k]=r(()=>g(i)),C=v?Object.values(v):d,x=o(e=>{let t=e;if(!t)return;"system"===e&&s&&(t=p());const r=v?v[t]:t,o=n?b():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()},[]),L=o(e=>{T(e);try{localStorage.setItem(i,e)}catch(e){}},[t]),I=o(e=>{const n=p(e);k(n),"system"===w&&s&&!t&&x("system")},[w,t]);return a(()=>{const e=window.matchMedia(c);return e.addListener(I),I(e),()=>e.removeListener(I)},[I]),a(()=>{const e=e=>{e.key===i&&L(e.newValue||h)};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[L]),a(()=>{x(null!=t?t:w)},[t,w]),/*#__PURE__*/e.createElement(u.Provider,{value:{theme:w,setTheme:L,forcedTheme:t,resolvedTheme:"system"===w?E:w,themes:s?[...d,"system"]:d,systemTheme:s?E:void 0}},/*#__PURE__*/e.createElement(f,{forcedTheme:t,disableTransitionOnChange:n,enableSystem:s,enableColorScheme:l,storageKey:i,themes:d,defaultTheme:h,attribute:y,value:v,children:$,attrs:C,nonce:S}),$)},f=/*#__PURE__*/s(({forcedTheme:t,storageKey:n,attribute:r,enableSystem:o,enableColorScheme:a,defaultTheme:s,value:l,attrs:d,nonce:u})=>{const h="system"===s,y="class"===r?`var d=document.documentElement,c=d.classList;c.remove(${d.map(e=>`'${e}'`).join(",")});`:`var d=document.documentElement,n='${r}',s='setAttribute';`,v=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":"",$=(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?`c.add(${s})`:"null":o&&(i+=`d[s](n,${s})`),i},f=t?`!function(){${y}${$(t)}}()`:o?`!function(){try{${y}var e=localStorage.getItem('${n}');if("system"===e||(!e&&${h})){var t="${c}",m=window.matchMedia(t);if(m.media!==t||m.matches){${$("dark")}}else{${$("light")}}}else if(e){${l?`var x=${JSON.stringify(l)};`:""}${$(l?"x[e]":"e",!0)}}${h?"":"else{"+$(s,!1,!1)+"}"}${v}}catch(e){}}()`:`!function(){try{${y}var e=localStorage.getItem("${n}");if(e){${l?`var x=${JSON.stringify(l)};`:""}${$(l?"x[e]":"e",!0)}}else{${$(s,!1,!1)};}${v}}catch(t){}}();`;return console.log("next/script"),/*#__PURE__*/e.createElement(i,{nonce:u,dangerouslySetInnerHTML:{__html:f},strategy:"beforeInteractive"})},()=>!0),g=(e,t)=>{if(d)return;let n;try{n=localStorage.getItem(e)||void 0}catch(e){}return n||t},b=()=>{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)}},p=e=>(e||(e=window.matchMedia(c)),e.matches?"dark":"light");export{$ as Theme,v as ThemeProvider,y as useTheme};

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

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

@@ -19,3 +19,3 @@ "source": "./src/index.tsx",

"peerDependencies": {
"next": ">=11.1.1",
"next": "*",
"react": "*",

@@ -37,3 +37,3 @@ "react-dom": "*"

"jest": "^26.6.3",
"microbundle": "^0.12.3",
"microbundle": "^0.15.0",
"prettier": "^2.2.1",

@@ -40,0 +40,0 @@ "react": "^17.0.1",

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