UNPKG

nextjs-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.39 kB
"use strict";var d=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var D=(o,e)=>{for(var r in e)d(o,r,{get:e[r],enumerable:!0})},u=(o,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of a(e))!x.call(o,s)&&s!==r&&d(o,s,{get:()=>e[s],enumerable:!(t=v(e,s))||t.enumerable});return o};var R=o=>u(d({},"__esModule",{value:!0}),o);var E={};D(E,{useTheme:()=>F});module.exports=R(E);var C=require("r18gs");var f="nth",T="light",i="dark",n="system";var k={t:"",d:i,l:T,c:n,s:T},p="undefined",y=o=>{let e=o!=null?o:"#"+f;return(0,C.useRGS)(e,()=>{let r=typeof m!==p&&localStorage.getItem(e);return r?{...JSON.parse(r),s:m.matches?i:T}:k})};var g=[n,i,T],S,F=o=>{let[e,r]=y(o);!S&&typeof window!=p&&(S=window.r);let t=h=>c=>r(l=>({...l,[h]:c})),s={theme:e.t,darkTheme:e.d,lightTheme:e.l,colorSchemePref:e.c,systemColorScheme:e.s,resolvedColorScheme:e.c===n||e.c===""?e.s:e.c,resolvedTheme:e.t,setTheme:t("t"),setDarkTheme:t("d"),setLightTheme:t("l"),setThemeSet:({darkTheme:h,lightTheme:c})=>r(l=>({...l,d:h,l:c})),setColorSchemePref:t("c"),toggleColorScheme(h){let c=g.indexOf(e.c),l=g.length;(c===-1||h&&c===l-1)&&(c=0),t("c")(g[(c+1)%l])},setForcedColorScheme:t("fc"),setForcedTheme:t("f")};if(S){let h=S(e);s.resolvedColorScheme=h[0],s.resolvedTheme=h[1]}return s};0&&(module.exports={useTheme});