UNPKG

react18-themes

Version:

Unleash the Power of React Server Components! Use multiple themes on your site with confidence, without losing any advantages of React Server Components.

2 lines (1 loc) 1.26 kB
import{a as y}from"./chunk-SSFUGXUP.mjs";import{a as h,b as U,c as v}from"./chunk-OAYIFZXE.mjs";import{a as w,b as P,c as O}from"./chunk-QW5I2FBF.mjs";import{memo as R,useEffect as p}from"react";import{jsx as L}from"react/jsx-runtime";var F,d,a,C,D,k=R(({k:t,n:e="",s:o,t:l,c:i})=>(typeof m!="undefined"&&([F,d,a,C,D]=[m,u,r,f,g]),L("script",{suppressHydrationWarning:!0,dangerouslySetInnerHTML:{__html:`(${y.toString()})(${JSON.stringify([t,h,o,l,i]).slice(1,-1)})`},nonce:e})),()=>!0),I=(t="none")=>{let e=document.createElement("style");return e.textContent=`transition: ${t.split(";")[0]} !important;`,document.head.appendChild(e),()=>{getComputedStyle(document.body),setTimeout(()=>document.head.removeChild(e),1)}},b=({forcedTheme:t,forcedColorScheme:e,targetSelector:o,themeTransition:l,styles:i,nonce:E})=>{let c=o||`#${w}`;typeof window!="undefined"&&!window.m&&y(c,h,i,t,e);let[s,T]=U(o),[S]=v(o);return p(()=>{F.addEventListener("change",()=>T(n=>({...n,s:F.matches?O:P}))),addEventListener("storage",n=>{n.key===c&&T(M=>({...M,...JSON.parse(n.newValue||"{}")}))})},[]),p(()=>{let n=I(l);d(a(s)),n(),localStorage.setItem(c,JSON.stringify(s))},[s]),p(()=>{C(t,e),d(a(s))},[e,t]),p(()=>{D(S.f,S.fc),d(a(s))},[S]),L(k,{k:c,n:E,s:i,t,c:e})};export{b as a};