// @bun
var{defineProperty:X,getOwnPropertyNames:P,getOwnPropertyDescriptor:b}=Object,B=Object.prototype.hasOwnProperty;function T(E){return this[E]}var M=(E)=>{var A=(x??=new WeakMap).get(E),F;if(A)return A;if(A=X({},"__esModule",{value:!0}),E&&typeof E==="object"||typeof E==="function"){for(var I of P(E))if(!B.call(A,I))X(A,I,{get:T.bind(E,I),enumerable:!(F=b(E,I))||F.enumerable})}return x.set(E,A),A},x;var w=(E)=>E;function C(E,A){this[E]=w.bind(null,A)}var S=(E,A)=>{for(var F in A)X(E,F,{get:A[F],enumerable:!0,configurable:!0,set:C.bind(A,F)})};var k=(E,A)=>()=>(E&&(A=E(E=0)),A);var y=import.meta.require;function D(E={}){let{storageKey:A="stx-color-mode",initialMode:F="auto",darkClass:I="dark",attribute:Y,disableTransitions:Z=!0}=E,J=F,G="light",L=new Set,U=[],N=typeof window<"u";function _(){if(!N)return"light";return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function $(z){return z==="auto"?_():z}function V(z){if(!N)return;let H=document.documentElement;if(Z)H.style.setProperty("transition","none","important");if(Y)H.setAttribute(Y,z);else if(z==="dark")H.classList.add(I);else H.classList.remove(I);if(Z)H.offsetHeight,H.style.removeProperty("transition")}function h(z){if(!N)return;try{localStorage.setItem(A,z)}catch{}}function q(){if(!N)return null;try{let z=localStorage.getItem(A);if(z==="light"||z==="dark"||z==="auto")return z}catch{}return null}function W(z){J=z,G=$(z),V(G),h(z),L.forEach((H)=>H(G,J))}let K=q();if(W(K??F),N){let z=window.matchMedia("(prefers-color-scheme: dark)"),H=()=>{if(J==="auto")G=_(),V(G),L.forEach((R)=>R(G,J))};z.addEventListener("change",H),U.push(()=>z.removeEventListener("change",H));let j=(R)=>{if(R.key!==A)return;let Q=R.newValue;if(Q==="light"||Q==="dark"||Q==="auto")J=Q,G=$(Q),V(G),L.forEach((O)=>O(G,J))};window.addEventListener("storage",j),U.push(()=>window.removeEventListener("storage",j))}if(typeof globalThis.onDestroy==="function")globalThis.onDestroy(()=>{U.forEach((z)=>z()),L.clear()});return{get mode(){return G},get preference(){return J},get isDark(){return G==="dark"},set(z){W(z)},toggle(){W(G==="dark"?"light":"dark")},subscribe(z){return L.add(z),()=>{L.delete(z)}}}}function g(E={}){let A=D(E);return{get isDark(){return A.isDark},toggle(){A.toggle()},set(F){A.set(F?"dark":"light")},subscribe(F){return A.subscribe((I)=>F(I==="dark"))}}}export{g as useDark,D as useColorMode};
