// @bun
var{defineProperty:Q,getOwnPropertyNames:Y,getOwnPropertyDescriptor:Z}=Object,_=Object.prototype.hasOwnProperty;function $(q){return this[q]}var j=(q)=>{var z=(V??=new WeakMap).get(q),D;if(z)return z;if(z=Q({},"__esModule",{value:!0}),q&&typeof q==="object"||typeof q==="function"){for(var H of Y(q))if(!_.call(z,H))Q(z,H,{get:$.bind(q,H),enumerable:!(D=Z(q,H))||D.enumerable})}return V.set(q,z),z},V;var x=(q)=>q;function C(q,z){this[q]=x.bind(null,z)}var w=(q,z)=>{for(var D in z)Q(q,D,{get:z[D],enumerable:!0,configurable:!0,set:C.bind(z,D)})};var f=(q,z)=>()=>(q&&(z=q(q=0)),z);var b=import.meta.require;var R=new Map;function W(q="local"){if(q==="memory"||typeof localStorage>"u")return{getItem:(z)=>R.get(z)??null,setItem:(z,D)=>R.set(z,D),removeItem:(z)=>R.delete(z)};return q==="local"?localStorage:sessionStorage}function E(q,z){let{state:D,getters:H={},actions:K={},persist:J}=z,B=typeof D==="function"?D():{...D},L=new Set;if(J){let I=J===!0?{storage:"local",key:`stx:${q}`}:J,A=W(I.storage),G=I.key||`stx:${q}`;try{let M=A.getItem(G);if(M)B={...B,...JSON.parse(M)}}catch{}}let N=()=>{if(!J)return;let I=J===!0?{storage:"local",key:`stx:${q}`}:J,A=W(I.storage),G=I.key||`stx:${q}`;A.setItem(G,JSON.stringify(B))},O=(I)=>{for(let A of L)try{A(B,I)}catch(G){console.error(`[stx:${q}] Subscriber error:`,G)}},X=typeof D==="function"?D():{...D},P=new Proxy({},{get(I,A){if(A==="$state")return{...B};if(A==="$id")return q;if(A==="$subscribe")return(G)=>{return L.add(G),()=>L.delete(G)};if(A==="$reset")return()=>{let G=B;B={...X},N(),O(G)};if(A==="$patch")return(G)=>{let M=B;if(typeof G==="function"){let U={...B};G(U),B=U}else B={...B,...G};N(),O(M)};if(A in H)return H[A](B);if(A in K)return(...G)=>K[A].apply(P,G);if(A in B)return B[A];return},set(I,A,G){if(A.startsWith("$"))return!1;let M=B;return B={...B,[A]:G},N(),O(M),!0},has(I,A){return A.startsWith("$")||A in H||A in K||A in B}});if(typeof window<"u")window.__STX_STORES__=window.__STX_STORES__||{},window.__STX_STORES__[q]=P;return P}function F(q){if(typeof window>"u")return;let z=window;z.__STX_STORES__=z.__STX_STORES__||{};for(let[D,H]of Object.entries(q))z.__STX_STORES__[D]=H;window.dispatchEvent(new CustomEvent("stx:stores-ready",{detail:Object.keys(q)}))}function T(q){if(typeof window>"u")return;return window.__STX_STORES__?.[q]}function h(q,z=5000){return new Promise((D,H)=>{let K=T(q);if(K){D(K);return}let J=Date.now(),B=()=>{let L=T(q);if(L)D(L);else if(Date.now()-J>z)H(Error(`Store "${q}" not found after ${z}ms`));else requestAnimationFrame(B)};B()})}if(typeof window<"u")window.STX={...window.STX,defineStore:E,registerStores:F,getStore:T,waitForStore:h};export{h as waitForStore,F as registerStores,T as getStore,E as defineStore};
