// @bun
var{defineProperty:R,getOwnPropertyNames:Z,getOwnPropertyDescriptor:_}=Object,$=Object.prototype.hasOwnProperty;function q(j){return this[j]}var o=(j)=>{var z=(X??=new WeakMap).get(j),A;if(z)return z;if(z=R({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var F of Z(j))if(!$.call(z,F))R(z,F,{get:q.bind(j,F),enumerable:!(A=_(j,F))||A.enumerable})}return X.set(j,z),z},X;var O=(j)=>j;function x(j,z){this[j]=O.bind(null,z)}var k=(j,z)=>{for(var A in z)R(j,A,{get:z[A],enumerable:!0,configurable:!0,set:x.bind(z,A)})};var C=(j,z)=>()=>(j&&(z=j(j=0)),z);var E=import.meta.require;function w(j){let z=j,A=new Set,F=new Set,G=()=>{if(I)F.add(I);return z};return G.set=(H)=>{if(!Object.is(H,z)){let K=z;if(z=H,A.forEach((J)=>J(z,K)),M)F.forEach((J)=>P.add(J));else F.forEach((J)=>J())}},G.update=(H)=>{G.set(H(z))},G.subscribe=(H)=>{return A.add(H),()=>A.delete(H)},Object.defineProperty(G,"_isSignal",{value:!0,writable:!1}),G}function B(j){let z,A=!0,F=new Set,G=()=>{if(!A)if(A=!0,M)F.forEach((K)=>P.add(K));else F.forEach((K)=>K())},H=()=>{if(I)F.add(I);if(A){let K=I;I=G,N.push(G);try{z=j()}finally{N.pop(),I=K}A=!1}return z};return Object.defineProperty(H,"_isDerived",{value:!0,writable:!1}),H}function V(j,z={}){let A,F=!1,G=()=>{if(F)return;if(A)A(),A=void 0;let H=I;I=G,N.push(G);try{A=j()}finally{N.pop(),I=H}};if(z.immediate!==!1)G();return()=>{if(F=!0,A)A()}}function g(j){if(M){j();return}M=!0;try{j()}finally{M=!1,P.forEach((z)=>z()),P.clear()}}function d(j){S.push(j)}function p(j){W.push(j)}function m(j){return typeof j==="function"&&j._isSignal===!0}function D(j){return typeof j==="function"&&j._isDerived===!0}function r(j){if(m(j)||D(j))return j();return j}function y(j){let z=I;I=null;try{return j()}finally{I=z}}function v(j,z){let A=typeof j==="function"?j:()=>j,F=w([]),G=B(()=>F().reduce((J,L)=>z(J,L.action),A())),H=!1;return V(()=>{if(A(),!H){H=!0;return}if(y(()=>F().length))F.set([])}),[G,(J,L)=>{let T={action:J};F.set([...F(),T]);let Q=()=>{let U=F().filter((Y)=>Y!==T);if(U.length!==F().length)F.set(U)};if(L&&typeof L.then==="function")Promise.resolve(L).then(Q,Q);return Q}]}var I=null,N,M=!1,P,S,W;var h=C(()=>{N=[],P=new Set,S=[],W=[]});h();export{v as useOptimistic,r as untrack,w as state,y as peek,d as onMount,p as onDestroy,m as isSignal,D as isDerived,V as effect,B as derived,g as batch};
