nextjs-darkmode-lite
Version:
Unleash the Power of React Server Components! Use dark/light mode on your site with confidence, without losing any advantages of React Server Components
2 lines (1 loc) • 613 B
JavaScript
var f=(c,d,i)=>{var a;let[n,e]=["system","dark"];window.u=(t,l)=>{let m=t===n?l:t,o=document,s=document.documentElement,r=o.createElement("style");r.textContent=`*,*:after,*:before{transition:${d.split(";")[0]} !important;}`,r.setAttribute("nonce",i),o.head.appendChild(r),m===e?s.classList.add(e):s.classList.remove(e),[["sm",l],["rm",m],["m",t]].forEach(([h,S])=>s.setAttribute(`data-${h}`,S)),localStorage.setItem(c,t),getComputedStyle(o.body),setTimeout(()=>o.head.removeChild(r),1)},window.q=matchMedia(`(prefers-color-scheme: ${e})`),u((a=localStorage.getItem(c))!=null?a:n,q.matches?e:"")};export{f as a};