next-themes
Advanced tools
Comparing version 0.2.1 to 0.3.0-beta.1
@@ -1,4 +0,7 @@ | ||
import React from 'react'; | ||
import type { UseThemeProps, ThemeProviderProps } from './types'; | ||
export declare const useTheme: () => UseThemeProps; | ||
export declare const ThemeProvider: React.FC<ThemeProviderProps>; | ||
import * as React from 'react'; | ||
import { UseThemeProps, ThemeProviderProps } from './types.js'; | ||
declare const useTheme: () => UseThemeProps; | ||
declare const ThemeProvider: (props: ThemeProviderProps) => string | number | boolean | Iterable<React.ReactNode> | React.JSX.Element; | ||
export { ThemeProvider, useTheme }; |
@@ -1,1 +0,1 @@ | ||
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=["light","dark"],m=({forcedTheme:t,disableTransitionOnChange:o=!1,enableSystem:l=!0,enableColorScheme:m=!0,storageKey:f="theme",themes:y=c,defaultTheme:v=(l?"system":"light"),attribute:$="data-theme",value:g,children:b,nonce:S})=>{const[T,p]=e.useState(()=>d(f,v)),[w,C]=e.useState(()=>d(f)),E=g?Object.values(g):y,k=e.useCallback(e=>{let t=e;if(!t)return;"system"===e&&l&&(t=h());const n=g?g[t]:t,a=o?u():null,s=document.documentElement;if("class"===$?(s.classList.remove(...E),n&&s.classList.add(n)):n?s.setAttribute($,n):s.removeAttribute($),m){const e=r.includes(v)?v:null,n=r.includes(t)?t:e;s.style.colorScheme=n}null==a||a()},[]),x=e.useCallback(e=>{p(e);try{localStorage.setItem(f,e)}catch(e){}},[t]),L=e.useCallback(e=>{const n=h(e);C(n),"system"===T&&l&&!t&&k("system")},[T,t]);e.useEffect(()=>{const e=window.matchMedia(a);return e.addListener(L),L(e),()=>e.removeListener(L)},[L]),e.useEffect(()=>{const e=e=>{e.key===f&&x(e.newValue||v)};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[x]),e.useEffect(()=>{k(null!=t?t:T)},[t,T]);const I=e.useMemo(()=>({theme:T,setTheme:x,forcedTheme:t,resolvedTheme:"system"===T?w:T,themes:l?[...y,"system"]:y,systemTheme:l?w:void 0}),[T,x,t,w,l,y]);/*#__PURE__*/return n.default.createElement(s.Provider,{value:I},/*#__PURE__*/n.default.createElement(i,{forcedTheme:t,disableTransitionOnChange:o,enableSystem:l,enableColorScheme:m,storageKey:f,themes:y,defaultTheme:v,attribute:$,value:g,children:b,attrs:E,nonce:S}),b)},i=/*#__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),d=(e,t)=>{if(o)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(a)),e.matches?"dark":"light");exports.ThemeProvider=t=>e.useContext(s)?/*#__PURE__*/n.default.createElement(e.Fragment,null,t.children):/*#__PURE__*/n.default.createElement(m,t),exports.useTheme=()=>{var t;return null!==(t=e.useContext(s))&&void 0!==t?t:l}; | ||
"use client";var N=Object.create;var P=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var z=(e,n)=>{for(var s in n)P(e,s,{get:n[s],enumerable:!0})},T=(e,n,s,u)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of U(n))!j.call(e,r)&&r!==s&&P(e,r,{get:()=>n[r],enumerable:!(u=O(n,r))||u.enumerable});return e};var J=(e,n,s)=>(s=e!=null?N(_(e)):{},T(n||!e||!e.__esModule?P(s,"default",{value:e,enumerable:!0}):s,e)),V=e=>T(P({},"__esModule",{value:!0}),e);var Y={};z(Y,{ThemeProvider:()=>B,useTheme:()=>q});module.exports=V(Y);var t=J(require("react")),C=["light","dark"],L="(prefers-color-scheme: dark)",H=typeof window=="undefined",M=t.createContext(void 0),b={setTheme:e=>{},themes:[]},q=()=>{var e;return(e=t.useContext(M))!=null?e:b},B=e=>t.useContext(M)?e.children:t.createElement(G,{...e}),F=["light","dark"],G=({forcedTheme:e,disableTransitionOnChange:n=!1,enableSystem:s=!0,enableColorScheme:u=!0,storageKey:r="theme",themes:a=F,defaultTheme:c=s?"system":"light",attribute:g="data-theme",value:p,children:k,nonce:w})=>{let[d,l]=t.useState(()=>I(r,c)),[S,m]=t.useState(()=>I(r)),f=p?Object.values(p):a,R=t.useCallback(o=>{let i=o;if(!i)return;o==="system"&&s&&(i=A());let y=p?p[i]:i,E=n?X():null,x=document.documentElement;if(g==="class"?(x.classList.remove(...f),y&&x.classList.add(y)):y?x.setAttribute(g,y):x.removeAttribute(g),u){let Q=C.includes(c)?c:null,D=C.includes(i)?i:Q;x.style.colorScheme=D}E==null||E()},[]),h=t.useCallback(o=>{let i=typeof o=="function"?o(o):o;l(i);try{localStorage.setItem(r,i)}catch(y){}},[e]),$=t.useCallback(o=>{let i=A(o);m(i),d==="system"&&s&&!e&&R("system")},[d,e]);t.useEffect(()=>{let o=window.matchMedia(L);return o.addListener($),$(o),()=>o.removeListener($)},[$]),t.useEffect(()=>{let o=i=>{if(i.key!==r)return;let y=i.newValue||c;h(y)};return window.addEventListener("storage",o),()=>window.removeEventListener("storage",o)},[h]),t.useEffect(()=>{R(e!=null?e:d)},[e,d]);let v=t.useMemo(()=>({theme:d,setTheme:h,forcedTheme:e,resolvedTheme:d==="system"?S:d,themes:s?[...a,"system"]:a,systemTheme:s?S:void 0}),[d,h,e,S,s,a]);return t.createElement(M.Provider,{value:v},t.createElement(W,{forcedTheme:e,disableTransitionOnChange:n,enableSystem:s,enableColorScheme:u,storageKey:r,themes:a,defaultTheme:c,attribute:g,value:p,children:k,attrs:f,nonce:w}),k)},W=t.memo(({forcedTheme:e,storageKey:n,attribute:s,enableSystem:u,enableColorScheme:r,defaultTheme:a,value:c,attrs:g,nonce:p})=>{let k=a==="system",w=s==="class"?`var d=document.documentElement,c=d.classList;${`c.remove(${g.map(f=>`'${f}'`).join(",")})`};`:`var d=document.documentElement,n='${s}',s='setAttribute';`,d=r?(C.includes(a)?a:null)?`if(e==='light'||e==='dark'||!e)d.style.colorScheme=e||'${a}'`:"if(e==='light'||e==='dark')d.style.colorScheme=e":"",l=(m,f=!1,R=!0)=>{let h=c?c[m]:m,$=f?m+"|| ''":`'${h}'`,v="";return r&&R&&!f&&C.includes(m)&&(v+=`d.style.colorScheme = '${m}';`),s==="class"?f||h?v+=`c.add(${$})`:v+="null":h&&(v+=`d[s](n,${$})`),v},S=e?`!function(){${w}${l(e)}}()`:u?`!function(){try{${w}var e=localStorage.getItem('${n}');if('system'===e||(!e&&${k})){var t='${L}',m=window.matchMedia(t);if(m.media!==t||m.matches){${l("dark")}}else{${l("light")}}}else if(e){${c?`var x=${JSON.stringify(c)};`:""}${l(c?"x[e]":"e",!0)}}${k?"":"else{"+l(a,!1,!1)+"}"}${d}}catch(e){}}()`:`!function(){try{${w}var e=localStorage.getItem('${n}');if(e){${c?`var x=${JSON.stringify(c)};`:""}${l(c?"x[e]":"e",!0)}}else{${l(a,!1,!1)};}${d}}catch(t){}}();`;return t.createElement("script",{nonce:p,dangerouslySetInnerHTML:{__html:S}})}),I=(e,n)=>{if(H)return;let s;try{s=localStorage.getItem(e)||void 0}catch(u){}return s||n},X=()=>{let 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)}},A=e=>(e||(e=window.matchMedia(L)),e.matches?"dark":"light");0&&(module.exports={ThemeProvider,useTheme}); |
@@ -1,42 +0,45 @@ | ||
/// <reference types="react" /> | ||
import * as React from 'react'; | ||
interface ValueObject { | ||
[themeName: string]: string; | ||
} | ||
export interface UseThemeProps { | ||
interface UseThemeProps { | ||
/** List of all available theme names */ | ||
themes: string[]; | ||
/** Forced theme name for the current page */ | ||
forcedTheme?: string; | ||
forcedTheme?: string | undefined; | ||
/** Update the theme */ | ||
setTheme: (theme: string) => void; | ||
setTheme: React.Dispatch<React.SetStateAction<string>>; | ||
/** Active theme name */ | ||
theme?: string; | ||
theme?: string | undefined; | ||
/** If `enableSystem` is true and the active theme is "system", this returns whether the system preference resolved to "dark" or "light". Otherwise, identical to `theme` */ | ||
resolvedTheme?: string; | ||
resolvedTheme?: string | undefined; | ||
/** If enableSystem is true, returns the System theme preference ("dark" or "light"), regardless what the active theme is */ | ||
systemTheme?: 'dark' | 'light'; | ||
systemTheme?: 'dark' | 'light' | undefined; | ||
} | ||
export interface ThemeProviderProps { | ||
interface ThemeProviderProps { | ||
/** List of all available theme names */ | ||
themes?: string[]; | ||
themes?: string[] | undefined; | ||
/** Forced theme name for the current page */ | ||
forcedTheme?: string; | ||
forcedTheme?: string | undefined; | ||
/** Whether to switch between dark and light themes based on prefers-color-scheme */ | ||
enableSystem?: boolean; | ||
enableSystem?: boolean | undefined; | ||
/** Disable all CSS transitions when switching themes */ | ||
disableTransitionOnChange?: boolean; | ||
disableTransitionOnChange?: boolean | undefined; | ||
/** Whether to indicate to browsers which color scheme is used (dark or light) for built-in UI like inputs and buttons */ | ||
enableColorScheme?: boolean; | ||
enableColorScheme?: boolean | undefined; | ||
/** Key used to store theme setting in localStorage */ | ||
storageKey?: string; | ||
storageKey?: string | undefined; | ||
/** Default theme name (for v0.0.12 and lower the default was light). If `enableSystem` is false, the default theme is light */ | ||
defaultTheme?: string; | ||
defaultTheme?: string | undefined; | ||
/** HTML attribute modified based on the active theme. Accepts `class` and `data-*` (meaning any data attribute, `data-mode`, `data-color`, etc.) */ | ||
attribute?: string | 'class'; | ||
attribute?: string | 'class' | undefined; | ||
/** Mapping of theme name to HTML attribute value. Object where key is the theme name and value is the attribute value */ | ||
value?: ValueObject; | ||
value?: ValueObject | undefined; | ||
/** Nonce string to pass to the inline script for CSP headers */ | ||
nonce?: string; | ||
children?: React.ReactNode; | ||
nonce?: string | undefined; | ||
/** React children */ | ||
children: React.ReactNode; | ||
} | ||
export {}; | ||
export type { ThemeProviderProps, UseThemeProps }; |
{ | ||
"name": "next-themes", | ||
"version": "0.2.1", | ||
"version": "0.3.0-beta.1", | ||
"license": "MIT", | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.module.js", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"source": "./src/index.tsx", | ||
"license": "MIT", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"prepublish": "yarn build", | ||
"build": "microbundle --jsx React.createElement --compress --no-sourcemap", | ||
"test": "jest __tests__", | ||
"test:e2e": "yarn playwright test" | ||
}, | ||
"dependencies": {}, | ||
"peerDependencies": { | ||
"next": "*", | ||
"react": "*", | ||
"react-dom": "*" | ||
"react": "^16.8 || ^17 || ^18", | ||
"react-dom": "^16.8 || ^17 || ^18" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.13.10", | ||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.14.5", | ||
"@babel/plugin-proposal-optional-chaining": "^7.11.0", | ||
"@babel/preset-env": "^7.13.10", | ||
"@babel/preset-react": "^7.12.13", | ||
"@babel/preset-typescript": "^7.13.0", | ||
"@playwright/test": "^1.21.1", | ||
"@testing-library/react": "^11.2.5", | ||
"@types/jest": "^26.0.21", | ||
"@types/next": "^9.0.0", | ||
"@types/react": "^16.9.53", | ||
"babel-jest": "^26.6.3", | ||
"jest": "^26.6.3", | ||
"microbundle": "^0.15.0", | ||
"prettier": "^2.2.1", | ||
"react": "^17.0.1", | ||
"react-dom": "^17.0.1", | ||
"typescript": "^4.0.3" | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
}, | ||
@@ -48,9 +23,8 @@ "repository": { | ||
}, | ||
"prettier": { | ||
"semi": false, | ||
"singleQuote": true, | ||
"trailingComma": "none", | ||
"arrowParens": "avoid", | ||
"printWidth": 100 | ||
"scripts": { | ||
"prepublish": "pnpm build", | ||
"build": "tsup src", | ||
"dev": "tsup src --watch", | ||
"test": "vitest run __tests__" | ||
} | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
2
2
10
18219
98
1
0
1