// @bun
var{defineProperty:Q,getOwnPropertyNames:F,getOwnPropertyDescriptor:G}=Object,U=Object.prototype.hasOwnProperty;function h(j){return this[j]}var D=(j)=>{var q=(X??=new WeakMap).get(j),B;if(q)return q;if(q=Q({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var I of F(j))if(!U.call(q,I))Q(q,I,{get:h.bind(j,I),enumerable:!(B=G(j,I))||B.enumerable})}return X.set(j,q),q},X;var O=(j)=>j;function T(j,q){this[j]=O.bind(null,q)}var m=(j,q)=>{for(var B in q)Q(j,B,{get:q[B],enumerable:!0,configurable:!0,set:T.bind(q,B)})};var z=(j,q)=>()=>(j&&(q=j(j=0)),q);var S=import.meta.require;var C={read:(j)=>{try{return JSON.parse(j)}catch{return j}},write:(j)=>{return JSON.stringify(j)}};function Y(j,q,B={}){let{storage:I="local",serializer:L=C,mergeDefaults:Z=!1,listenToStorageChanges:_=!0}=B,M=new Set,R=typeof window<"u",K=()=>{if(!R)return null;return I==="session"?sessionStorage:localStorage},$=()=>{let A=K();if(!A)return q;try{let E=A.getItem(j);if(E===null)return q;let H=L.read(E);if(Z&&typeof q==="object"&&q!==null)return{...q,...H};return H}catch{return q}},x=(A)=>{let E=K();if(!E)return;try{if(A===null||A===void 0)E.removeItem(j);else E.setItem(j,L.write(A))}catch(H){console.warn(`[useStorage] Failed to write key "${j}":`,H)}},J=$(),N=(A,E)=>{for(let H of M)try{H(A,E)}catch(P){console.error("[useStorage] Subscriber error:",P)}};if(R&&_){let A=(H)=>{if(H.key===j&&H.storageArea===K()){let P=J;J=H.newValue?L.read(H.newValue):q,N(J,P)}};window.addEventListener("storage",A);let E=globalThis.onDestroy;if(typeof E==="function")E(()=>window.removeEventListener("storage",A))}let W={get value(){return J},set value(A){let E=J;J=A,x(A),N(A,E)},get:()=>J,set:(A)=>{W.value=A},remove:()=>{let A=K();if(A){A.removeItem(j);let E=J;J=q,N(q,E)}},subscribe:(A)=>{return M.add(A),A(J,void 0),()=>M.delete(A)}};return W}function b(j,q,B){return Y(j,q,{...B,storage:"local"})}function g(j,q,B){return Y(j,q,{...B,storage:"session"})}function p(j="local"){if(typeof window>"u")return;(j==="session"?sessionStorage:localStorage).clear()}function d(j="local"){if(typeof window>"u")return[];let q=j==="session"?sessionStorage:localStorage;return Object.keys(q)}function k(j="local"){if(typeof window>"u")return 0;let q=j==="session"?sessionStorage:localStorage,B=0;for(let I in q)if(Object.prototype.hasOwnProperty.call(q,I))B+=(I.length+(q.getItem(I)?.length||0))*2;return B}export{Y as useStorage,g as useSessionStorage,b as useLocalStorage,k as getStorageSize,d as getStorageKeys,p as clearStorage};
