text: 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};
  