atomirx 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,14 +2,14 @@
2
2
 
3
3
  ## Summary
4
4
 
5
- | Utility | Input | Output | Behavior |
6
- | ----------- | --------------- | ---------------------- | -------------------------- |
7
- | `all()` | Array of atoms | Array of values | Waits for all |
8
- | `any()` | Record of atoms | `{ key, value }` | First to resolve |
9
- | `race()` | Record of atoms | `{ key, value }` | First to settle |
10
- | `settled()` | Array of atoms | Array of SettledResult | Waits for all settled |
11
- | `and()` | Array of conds | boolean | AND with short-circuit |
12
- | `or()` | Array of conds | boolean | OR with short-circuit |
5
+ | Utility | Input | Output | Behavior |
6
+ | ----------- | --------------- | ----------------------------- | -------------------------- |
7
+ | `all()` | Array of atoms | Array of values | Waits for all |
8
+ | `any()` | Record of atoms | `KeyedResult` (discriminated) | First to resolve |
9
+ | `race()` | Record of atoms | `KeyedResult` (discriminated) | First to settle |
10
+ | `settled()` | Array of atoms | Array of SettledResult | Waits for all settled |
11
+ | `and()` | Array of conds | boolean | AND with short-circuit |
12
+ | `or()` | Array of conds | boolean | OR with short-circuit |
13
13
 
14
14
  ## all() — Promise.all
15
15
 
@@ -27,11 +27,20 @@ const dashboard$ = derived(({ all }) => {
27
27
  ## any() — Promise.any
28
28
 
29
29
  Returns first resolved. Uses object for key identification.
30
+ Returns a **discriminated union** — checking `key` narrows `value` type.
30
31
 
31
32
  ```typescript
32
33
  const data$ = derived(({ any }) => {
33
34
  const result = any({ primary: primaryApi$, fallback: fallbackApi$ });
34
- // result: { key: "primary" | "fallback", value: T }
35
+
36
+ // Type narrowing works!
37
+ if (result.key === "primary") {
38
+ result.value; // narrowed to primaryApi$ type
39
+ }
40
+
41
+ // Tuple destructuring also works
42
+ const [winner, value] = result;
43
+
35
44
  return result.value;
36
45
  });
37
46
  ```
@@ -41,16 +50,44 @@ const data$ = derived(({ any }) => {
41
50
  ## race() — Promise.race
42
51
 
43
52
  Returns first settled (ready OR error). Uses object.
53
+ Returns a **discriminated union** — checking `key` narrows `value` type.
44
54
 
45
55
  ```typescript
46
56
  const data$ = derived(({ race }) => {
47
57
  const result = race({ cache: cache$, api: api$ });
58
+
59
+ // Type narrowing works!
60
+ if (result.key === "cache") {
61
+ result.value; // narrowed to cache$ type
62
+ }
63
+
64
+ // Tuple destructuring also works
65
+ const [source, value] = result;
66
+
48
67
  return result.value;
49
68
  });
50
69
  ```
51
70
 
52
71
  **Use when:** Show whatever resolves first.
53
72
 
73
+ ### KeyedResult Type
74
+
75
+ `race()` and `any()` return a `KeyedResult<T>` discriminated union:
76
+
77
+ ```typescript
78
+ // For race({ num: numAtom$, str: strAtom$ })
79
+ // Returns: KeyedResultEntry<"num", number> | KeyedResultEntry<"str", string>
80
+
81
+ type KeyedResultEntry<K, V> = readonly [K, V] & { key: K; value: V };
82
+
83
+ // Both access patterns work:
84
+ const result = race({ num: numAtom$, str: strAtom$ });
85
+ result.key; // "num" | "str"
86
+ result.value; // number | string (narrowed when key checked)
87
+ result[0]; // same as key
88
+ result[1]; // same as value
89
+ ```
90
+
54
91
  ## settled() — Promise.allSettled
55
92
 
56
93
  Returns status for each. Waits until all settled.
@@ -98,6 +135,52 @@ type AtomState<T> =
98
135
  | { status: "loading"; promise: Promise<T> };
99
136
  ```
100
137
 
138
+ ## ready() with Async Utilities
139
+
140
+ Use `ready()` to ensure values from `all()`, `race()`, or `any()` are non-null/non-undefined:
141
+
142
+ ### ready() + all()
143
+
144
+ Suspend if ANY atom value is null/undefined:
145
+
146
+ ```typescript
147
+ const dashboard$ = derived(({ ready, all }) => {
148
+ // Suspends if user$ or posts$ value is null/undefined
149
+ const [user, posts] = ready(all([user$, posts$]));
150
+ // user and posts are guaranteed non-null
151
+ return { user, posts };
152
+ });
153
+ ```
154
+
155
+ ### ready() + race()
156
+
157
+ Suspend if winning value is null/undefined. Preserves discriminated union:
158
+
159
+ ```typescript
160
+ const data$ = derived(({ ready, race }) => {
161
+ const result = ready(race({ cache: cache$, api: api$ }));
162
+
163
+ // Type narrowing still works!
164
+ if (result.key === "cache") {
165
+ result.value; // narrowed to cache type (non-null)
166
+ }
167
+
168
+ return { source: result.key, data: result.value };
169
+ });
170
+ ```
171
+
172
+ ### ready() + any()
173
+
174
+ Same pattern as race():
175
+
176
+ ```typescript
177
+ const data$ = derived(({ ready, any }) => {
178
+ const [winner, value] = ready(any({ primary: primary$, fallback: fallback$ }));
179
+ // value is guaranteed non-null
180
+ return { source: winner, data: value };
181
+ });
182
+ ```
183
+
101
184
  ## Combining Patterns
102
185
 
103
186
  ### Graceful Degradation
@@ -4,22 +4,23 @@ SelectContext provides methods for `derived`, `effect`, `useSelector`, and `rx`.
4
4
 
5
5
  ## Methods
6
6
 
7
- | Method | Returns | Description |
8
- | --------------- | -------------------------- | ------------------------------ |
9
- | `read(atom)` | `T` | Get value, suspends if loading |
10
- | `ready(atom)` | `T` (non-nullable) | Block until truthy |
11
- | `state(atom)` | `AtomState<T>` | Get state without suspending |
12
- | `untrack(atom)` | `T` | Read without tracking dep |
13
- | `untrack(fn)` | `T` | Execute fn without tracking |
14
- | `safe(fn)` | `[error?, value?]` | Catch errors, rethrow Promise |
15
- | `all(atoms)` | `T[]` | Wait for all |
16
- | `any(record)` | `{ key, value }` | First to resolve |
17
- | `race(record)` | `{ key, value }` | First to settle |
18
- | `settled()` | `SettledResult<T>[]` | All with status |
19
- | `from(pool)` | `ScopedAtom<T>` | Get atom from pool |
20
- | `track(atom)` | `void` | Track without reading |
21
- | `and(conds)` | `boolean` | Logical AND |
22
- | `or(conds)` | `boolean` | Logical OR |
7
+ | Method | Returns | Description |
8
+ | --------------- | ------------------------------ | ------------------------------------- |
9
+ | `read(atom)` | `T` | Get value, suspends if loading |
10
+ | `ready(atom)` | `T` (non-nullable) | Block until truthy |
11
+ | `ready(values)` | `T[]` (non-nullable elements) | Block until all elements truthy |
12
+ | `state(atom)` | `AtomState<T>` | Get state without suspending |
13
+ | `untrack(atom)` | `T` | Read without tracking dep |
14
+ | `untrack(fn)` | `T` | Execute fn without tracking |
15
+ | `safe(fn)` | `[error?, value?]` | Catch errors, rethrow Promise |
16
+ | `all(atoms)` | `T[]` | Wait for all |
17
+ | `any(record)` | `KeyedResult` (discriminated) | First to resolve, narrows on key |
18
+ | `race(record)` | `KeyedResult` (discriminated) | First to settle, narrows on key |
19
+ | `settled()` | `SettledResult<T>[]` | All with status |
20
+ | `from(pool)` | `ScopedAtom<T>` | Get atom from pool |
21
+ | `track(atom)` | `void` | Track without reading |
22
+ | `and(conds)` | `boolean` | Logical AND |
23
+ | `or(conds)` | `boolean` | Logical OR |
23
24
 
24
25
  ## CRITICAL Rules
25
26
 
@@ -137,13 +138,15 @@ untrack(input)
137
138
  interface SelectContext {
138
139
  read<T>(atom: ReadableAtom<T>): T;
139
140
  ready<T>(atom: ReadableAtom<T | undefined | null>): T;
141
+ ready<T extends Record<string, unknown>>(result: KeyedResult<T>): NonNullableKeyedResult<T>;
142
+ ready<A extends readonly unknown[]>(values: A): { [K in keyof A]: Exclude<A[K], null | undefined> };
140
143
  state<T>(atom: ReadableAtom<T>): AtomState<T>;
141
144
  untrack<T>(atom: ReadableAtom<T>): T;
142
145
  untrack<T>(fn: () => T): T;
143
146
  safe<T>(fn: () => T): [unknown, undefined] | [undefined, T];
144
147
  all<T extends readonly ReadableAtom<unknown>[]>(atoms: T): MapAtomValues<T>;
145
- any<T extends Record<string, ReadableAtom<unknown>>>(atoms: T): { key: keyof T; value: T[keyof T] };
146
- race<T extends Record<string, ReadableAtom<unknown>>>(atoms: T): { key: keyof T; value: T[keyof T] };
148
+ any<T extends Record<string, ReadableAtom<unknown>>>(atoms: T): KeyedResult<MapAtomValues<T>>;
149
+ race<T extends Record<string, ReadableAtom<unknown>>>(atoms: T): KeyedResult<MapAtomValues<T>>;
147
150
  settled<T extends readonly ReadableAtom<unknown>[]>(atoms: T): MapSettledResults<T>;
148
151
  from<P, T>(pool: Pool<P, T>, params: P): ScopedAtom<T>;
149
152
  track(atom: ReadableAtom<unknown>): void;
@@ -151,6 +154,16 @@ interface SelectContext {
151
154
  or(conditions: Condition[]): boolean;
152
155
  }
153
156
 
157
+ // KeyedResult is a discriminated union - checking key narrows value
158
+ type KeyedResult<T extends Record<string, unknown>> = {
159
+ [K in keyof T & string]: KeyedResultEntry<K, T[K]>;
160
+ }[keyof T & string];
161
+
162
+ type KeyedResultEntry<K extends string, V> = readonly [K, V] & { key: K; value: V };
163
+
164
+ type NonNullableKeyedResult<T extends Record<string, unknown>> =
165
+ KeyedResult<{ [K in keyof T]: Exclude<T[K], null | undefined> }>;
166
+
154
167
  type AtomState<T> =
155
168
  | { status: "ready"; value: T }
156
169
  | { status: "error"; error: unknown }
@@ -1 +0,0 @@
1
- "use strict";var jt=Object.defineProperty;var Ot=(e,t,r)=>t in e?jt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var O=(e,t,r)=>Ot(e,typeof t!="symbol"?t+"":t,r);const M=require("./onErrorHook-DHBASmYw.cjs"),Pt=()=>{};class Dt{constructor(t){O(this,"_listeners");O(this,"_settledPayload");O(this,"_isSettled",!1);O(this,"size",()=>this._listeners.size);O(this,"settled",()=>this._isSettled);O(this,"forEach",t=>{this._listeners.forEach(t)});O(this,"on",(t,r)=>{let a;if(r===void 0)a=Array.isArray(t)?t:[t];else{const n=t,c=Array.isArray(r)?r:[r];a=[i=>{const f=n(i);if(f)for(let v=0;v<c.length;v++)c[v](f.value)}]}if(this._isSettled){const n=this._settledPayload;for(let c=0;c<a.length;c++)a[c](n);return Pt}const o=this._listeners;for(let n=0;n<a.length;n++)o.add(a[n]);return()=>{for(let n=0;n<a.length;n++)o.delete(a[n])}});O(this,"emit",t=>{this._isSettled||this._doEmit(t,!1,!1)});O(this,"emitLifo",t=>{this._isSettled||this._doEmit(t,!1,!0)});O(this,"clear",()=>{this._listeners.clear()});O(this,"emitAndClear",t=>{this._isSettled||this._doEmit(t,!0,!1)});O(this,"emitAndClearLifo",t=>{this._isSettled||this._doEmit(t,!0,!0)});O(this,"settle",t=>{this._isSettled||(this._settledPayload=t,this._isSettled=!0,this._doEmit(t,!0,!1))});O(this,"_doEmit",(t,r,a)=>{const o=this._listeners,n=o.size;if(n===0)return;const c=Array.from(o);if(r&&o.clear(),a)for(let i=n-1;i>=0;i--)c[i](t);else for(let i=0;i<n;i++)c[i](t)});this._listeners=new Set(t)}}function B(e){return new Dt(e)}var ee=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function It(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function xt(){this.__data__=[],this.size=0}var kt=xt;function Lt(e,t){return e===t||e!==e&&t!==t}var it=Lt,Mt=it;function Gt(e,t){for(var r=e.length;r--;)if(Mt(e[r][0],t))return r;return-1}var ce=Gt,Rt=ce,qt=Array.prototype,Ht=qt.splice;function Ft(e){var t=this.__data__,r=Rt(t,e);if(r<0)return!1;var a=t.length-1;return r==a?t.pop():Ht.call(t,r,1),--this.size,!0}var Bt=Ft,Ut=ce;function zt(e){var t=this.__data__,r=Ut(t,e);return r<0?void 0:t[r][1]}var Nt=zt,Kt=ce;function Vt(e){return Kt(this.__data__,e)>-1}var Wt=Vt,Yt=ce;function Jt(e,t){var r=this.__data__,a=Yt(r,e);return a<0?(++this.size,r.push([e,t])):r[a][1]=t,this}var Xt=Jt,Zt=kt,Qt=Bt,er=Nt,tr=Wt,rr=Xt;function N(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var a=e[t];this.set(a[0],a[1])}}N.prototype.clear=Zt;N.prototype.delete=Qt;N.prototype.get=er;N.prototype.has=tr;N.prototype.set=rr;var ue=N,ar=ue;function nr(){this.__data__=new ar,this.size=0}var sr=nr;function or(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var ir=or;function cr(e){return this.__data__.get(e)}var ur=cr;function lr(e){return this.__data__.has(e)}var fr=lr,dr=typeof ee=="object"&&ee&&ee.Object===Object&&ee,ct=dr,vr=ct,hr=typeof self=="object"&&self&&self.Object===Object&&self,gr=vr||hr||Function("return this")(),G=gr,pr=G,yr=pr.Symbol,je=yr,Ie=je,ut=Object.prototype,_r=ut.hasOwnProperty,br=ut.toString,X=Ie?Ie.toStringTag:void 0;function mr(e){var t=_r.call(e,X),r=e[X];try{e[X]=void 0;var a=!0}catch{}var o=br.call(e);return a&&(t?e[X]=r:delete e[X]),o}var $r=mr,Ar=Object.prototype,wr=Ar.toString;function Tr(e){return wr.call(e)}var Sr=Tr,xe=je,Cr=$r,Er=Sr,jr="[object Null]",Or="[object Undefined]",ke=xe?xe.toStringTag:void 0;function Pr(e){return e==null?e===void 0?Or:jr:ke&&ke in Object(e)?Cr(e):Er(e)}var le=Pr;function Dr(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var lt=Dr,Ir=le,xr=lt,kr="[object AsyncFunction]",Lr="[object Function]",Mr="[object GeneratorFunction]",Gr="[object Proxy]";function Rr(e){if(!xr(e))return!1;var t=Ir(e);return t==Lr||t==Mr||t==kr||t==Gr}var ft=Rr,qr=G,Hr=qr["__core-js_shared__"],Fr=Hr,ge=Fr,Le=function(){var e=/[^.]+$/.exec(ge&&ge.keys&&ge.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Br(e){return!!Le&&Le in e}var Ur=Br,zr=Function.prototype,Nr=zr.toString;function Kr(e){if(e!=null){try{return Nr.call(e)}catch{}try{return e+""}catch{}}return""}var dt=Kr,Vr=ft,Wr=Ur,Yr=lt,Jr=dt,Xr=/[\\^$.*+?()[\]{}|]/g,Zr=/^\[object .+?Constructor\]$/,Qr=Function.prototype,ea=Object.prototype,ta=Qr.toString,ra=ea.hasOwnProperty,aa=RegExp("^"+ta.call(ra).replace(Xr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function na(e){if(!Yr(e)||Wr(e))return!1;var t=Vr(e)?aa:Zr;return t.test(Jr(e))}var sa=na;function oa(e,t){return e==null?void 0:e[t]}var ia=oa,ca=sa,ua=ia;function la(e,t){var r=ua(e,t);return ca(r)?r:void 0}var K=la,fa=K,da=G,va=fa(da,"Map"),Oe=va,ha=K,ga=ha(Object,"create"),fe=ga,Me=fe;function pa(){this.__data__=Me?Me(null):{},this.size=0}var ya=pa;function _a(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var ba=_a,ma=fe,$a="__lodash_hash_undefined__",Aa=Object.prototype,wa=Aa.hasOwnProperty;function Ta(e){var t=this.__data__;if(ma){var r=t[e];return r===$a?void 0:r}return wa.call(t,e)?t[e]:void 0}var Sa=Ta,Ca=fe,Ea=Object.prototype,ja=Ea.hasOwnProperty;function Oa(e){var t=this.__data__;return Ca?t[e]!==void 0:ja.call(t,e)}var Pa=Oa,Da=fe,Ia="__lodash_hash_undefined__";function xa(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=Da&&t===void 0?Ia:t,this}var ka=xa,La=ya,Ma=ba,Ga=Sa,Ra=Pa,qa=ka;function V(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var a=e[t];this.set(a[0],a[1])}}V.prototype.clear=La;V.prototype.delete=Ma;V.prototype.get=Ga;V.prototype.has=Ra;V.prototype.set=qa;var Ha=V,Ge=Ha,Fa=ue,Ba=Oe;function Ua(){this.size=0,this.__data__={hash:new Ge,map:new(Ba||Fa),string:new Ge}}var za=Ua;function Na(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var Ka=Na,Va=Ka;function Wa(e,t){var r=e.__data__;return Va(t)?r[typeof t=="string"?"string":"hash"]:r.map}var de=Wa,Ya=de;function Ja(e){var t=Ya(this,e).delete(e);return this.size-=t?1:0,t}var Xa=Ja,Za=de;function Qa(e){return Za(this,e).get(e)}var en=Qa,tn=de;function rn(e){return tn(this,e).has(e)}var an=rn,nn=de;function sn(e,t){var r=nn(this,e),a=r.size;return r.set(e,t),this.size+=r.size==a?0:1,this}var on=sn,cn=za,un=Xa,ln=en,fn=an,dn=on;function W(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var a=e[t];this.set(a[0],a[1])}}W.prototype.clear=cn;W.prototype.delete=un;W.prototype.get=ln;W.prototype.has=fn;W.prototype.set=dn;var vt=W,vn=ue,hn=Oe,gn=vt,pn=200;function yn(e,t){var r=this.__data__;if(r instanceof vn){var a=r.__data__;if(!hn||a.length<pn-1)return a.push([e,t]),this.size=++r.size,this;r=this.__data__=new gn(a)}return r.set(e,t),this.size=r.size,this}var _n=yn,bn=ue,mn=sr,$n=ir,An=ur,wn=fr,Tn=_n;function Y(e){var t=this.__data__=new bn(e);this.size=t.size}Y.prototype.clear=mn;Y.prototype.delete=$n;Y.prototype.get=An;Y.prototype.has=wn;Y.prototype.set=Tn;var Sn=Y,Cn="__lodash_hash_undefined__";function En(e){return this.__data__.set(e,Cn),this}var jn=En;function On(e){return this.__data__.has(e)}var Pn=On,Dn=vt,In=jn,xn=Pn;function ne(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new Dn;++t<r;)this.add(e[t])}ne.prototype.add=ne.prototype.push=In;ne.prototype.has=xn;var kn=ne;function Ln(e,t){for(var r=-1,a=e==null?0:e.length;++r<a;)if(t(e[r],r,e))return!0;return!1}var Mn=Ln;function Gn(e,t){return e.has(t)}var Rn=Gn,qn=kn,Hn=Mn,Fn=Rn,Bn=1,Un=2;function zn(e,t,r,a,o,n){var c=r&Bn,i=e.length,f=t.length;if(i!=f&&!(c&&f>i))return!1;var v=n.get(e),w=n.get(t);if(v&&w)return v==t&&w==e;var y=-1,_=!0,$=r&Un?new qn:void 0;for(n.set(e,t),n.set(t,e);++y<i;){var m=e[y],T=t[y];if(a)var u=c?a(T,m,y,t,e,n):a(m,T,y,e,t,n);if(u!==void 0){if(u)continue;_=!1;break}if($){if(!Hn(t,function(d,p){if(!Fn($,p)&&(m===d||o(m,d,r,a,n)))return $.push(p)})){_=!1;break}}else if(!(m===T||o(m,T,r,a,n))){_=!1;break}}return n.delete(e),n.delete(t),_}var ht=zn,Nn=G,Kn=Nn.Uint8Array,Vn=Kn;function Wn(e){var t=-1,r=Array(e.size);return e.forEach(function(a,o){r[++t]=[o,a]}),r}var Yn=Wn;function Jn(e){var t=-1,r=Array(e.size);return e.forEach(function(a){r[++t]=a}),r}var Xn=Jn,Re=je,qe=Vn,Zn=it,Qn=ht,es=Yn,ts=Xn,rs=1,as=2,ns="[object Boolean]",ss="[object Date]",os="[object Error]",is="[object Map]",cs="[object Number]",us="[object RegExp]",ls="[object Set]",fs="[object String]",ds="[object Symbol]",vs="[object ArrayBuffer]",hs="[object DataView]",He=Re?Re.prototype:void 0,pe=He?He.valueOf:void 0;function gs(e,t,r,a,o,n,c){switch(r){case hs:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case vs:return!(e.byteLength!=t.byteLength||!n(new qe(e),new qe(t)));case ns:case ss:case cs:return Zn(+e,+t);case os:return e.name==t.name&&e.message==t.message;case us:case fs:return e==t+"";case is:var i=es;case ls:var f=a&rs;if(i||(i=ts),e.size!=t.size&&!f)return!1;var v=c.get(e);if(v)return v==t;a|=as,c.set(e,t);var w=Qn(i(e),i(t),a,o,n,c);return c.delete(e),w;case ds:if(pe)return pe.call(e)==pe.call(t)}return!1}var ps=gs;function ys(e,t){for(var r=-1,a=t.length,o=e.length;++r<a;)e[o+r]=t[r];return e}var _s=ys,bs=Array.isArray,Pe=bs,ms=_s,$s=Pe;function As(e,t,r){var a=t(e);return $s(e)?a:ms(a,r(e))}var ws=As;function Ts(e,t){for(var r=-1,a=e==null?0:e.length,o=0,n=[];++r<a;){var c=e[r];t(c,r,e)&&(n[o++]=c)}return n}var Ss=Ts;function Cs(){return[]}var Es=Cs,js=Ss,Os=Es,Ps=Object.prototype,Ds=Ps.propertyIsEnumerable,Fe=Object.getOwnPropertySymbols,Is=Fe?function(e){return e==null?[]:(e=Object(e),js(Fe(e),function(t){return Ds.call(e,t)}))}:Os,xs=Is;function ks(e,t){for(var r=-1,a=Array(e);++r<e;)a[r]=t(r);return a}var Ls=ks;function Ms(e){return e!=null&&typeof e=="object"}var ve=Ms,Gs=le,Rs=ve,qs="[object Arguments]";function Hs(e){return Rs(e)&&Gs(e)==qs}var Fs=Hs,Be=Fs,Bs=ve,gt=Object.prototype,Us=gt.hasOwnProperty,zs=gt.propertyIsEnumerable,Ns=Be(function(){return arguments}())?Be:function(e){return Bs(e)&&Us.call(e,"callee")&&!zs.call(e,"callee")},Ks=Ns,se={exports:{}};function Vs(){return!1}var Ws=Vs;se.exports;(function(e,t){var r=G,a=Ws,o=t&&!t.nodeType&&t,n=o&&!0&&e&&!e.nodeType&&e,c=n&&n.exports===o,i=c?r.Buffer:void 0,f=i?i.isBuffer:void 0,v=f||a;e.exports=v})(se,se.exports);var pt=se.exports,Ys=9007199254740991,Js=/^(?:0|[1-9]\d*)$/;function Xs(e,t){var r=typeof e;return t=t??Ys,!!t&&(r=="number"||r!="symbol"&&Js.test(e))&&e>-1&&e%1==0&&e<t}var Zs=Xs,Qs=9007199254740991;function eo(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Qs}var yt=eo,to=le,ro=yt,ao=ve,no="[object Arguments]",so="[object Array]",oo="[object Boolean]",io="[object Date]",co="[object Error]",uo="[object Function]",lo="[object Map]",fo="[object Number]",vo="[object Object]",ho="[object RegExp]",go="[object Set]",po="[object String]",yo="[object WeakMap]",_o="[object ArrayBuffer]",bo="[object DataView]",mo="[object Float32Array]",$o="[object Float64Array]",Ao="[object Int8Array]",wo="[object Int16Array]",To="[object Int32Array]",So="[object Uint8Array]",Co="[object Uint8ClampedArray]",Eo="[object Uint16Array]",jo="[object Uint32Array]",S={};S[mo]=S[$o]=S[Ao]=S[wo]=S[To]=S[So]=S[Co]=S[Eo]=S[jo]=!0;S[no]=S[so]=S[_o]=S[oo]=S[bo]=S[io]=S[co]=S[uo]=S[lo]=S[fo]=S[vo]=S[ho]=S[go]=S[po]=S[yo]=!1;function Oo(e){return ao(e)&&ro(e.length)&&!!S[to(e)]}var Po=Oo;function Do(e){return function(t){return e(t)}}var Io=Do,oe={exports:{}};oe.exports;(function(e,t){var r=ct,a=t&&!t.nodeType&&t,o=a&&!0&&e&&!e.nodeType&&e,n=o&&o.exports===a,c=n&&r.process,i=function(){try{var f=o&&o.require&&o.require("util").types;return f||c&&c.binding&&c.binding("util")}catch{}}();e.exports=i})(oe,oe.exports);var xo=oe.exports,ko=Po,Lo=Io,Ue=xo,ze=Ue&&Ue.isTypedArray,Mo=ze?Lo(ze):ko,_t=Mo,Go=Ls,Ro=Ks,qo=Pe,Ho=pt,Fo=Zs,Bo=_t,Uo=Object.prototype,zo=Uo.hasOwnProperty;function No(e,t){var r=qo(e),a=!r&&Ro(e),o=!r&&!a&&Ho(e),n=!r&&!a&&!o&&Bo(e),c=r||a||o||n,i=c?Go(e.length,String):[],f=i.length;for(var v in e)(t||zo.call(e,v))&&!(c&&(v=="length"||o&&(v=="offset"||v=="parent")||n&&(v=="buffer"||v=="byteLength"||v=="byteOffset")||Fo(v,f)))&&i.push(v);return i}var Ko=No,Vo=Object.prototype;function Wo(e){var t=e&&e.constructor,r=typeof t=="function"&&t.prototype||Vo;return e===r}var Yo=Wo;function Jo(e,t){return function(r){return e(t(r))}}var Xo=Jo,Zo=Xo,Qo=Zo(Object.keys,Object),ei=Qo,ti=Yo,ri=ei,ai=Object.prototype,ni=ai.hasOwnProperty;function si(e){if(!ti(e))return ri(e);var t=[];for(var r in Object(e))ni.call(e,r)&&r!="constructor"&&t.push(r);return t}var oi=si,ii=ft,ci=yt;function ui(e){return e!=null&&ci(e.length)&&!ii(e)}var li=ui,fi=Ko,di=oi,vi=li;function hi(e){return vi(e)?fi(e):di(e)}var gi=hi,pi=ws,yi=xs,_i=gi;function bi(e){return pi(e,_i,yi)}var mi=bi,Ne=mi,$i=1,Ai=Object.prototype,wi=Ai.hasOwnProperty;function Ti(e,t,r,a,o,n){var c=r&$i,i=Ne(e),f=i.length,v=Ne(t),w=v.length;if(f!=w&&!c)return!1;for(var y=f;y--;){var _=i[y];if(!(c?_ in t:wi.call(t,_)))return!1}var $=n.get(e),m=n.get(t);if($&&m)return $==t&&m==e;var T=!0;n.set(e,t),n.set(t,e);for(var u=c;++y<f;){_=i[y];var d=e[_],p=t[_];if(a)var C=c?a(p,d,_,t,e,n):a(d,p,_,e,t,n);if(!(C===void 0?d===p||o(d,p,r,a,n):C)){T=!1;break}u||(u=_=="constructor")}if(T&&!u){var P=e.constructor,j=t.constructor;P!=j&&"constructor"in e&&"constructor"in t&&!(typeof P=="function"&&P instanceof P&&typeof j=="function"&&j instanceof j)&&(T=!1)}return n.delete(e),n.delete(t),T}var Si=Ti,Ci=K,Ei=G,ji=Ci(Ei,"DataView"),Oi=ji,Pi=K,Di=G,Ii=Pi(Di,"Promise"),xi=Ii,ki=K,Li=G,Mi=ki(Li,"Set"),Gi=Mi,Ri=K,qi=G,Hi=Ri(qi,"WeakMap"),Fi=Hi,_e=Oi,be=Oe,me=xi,$e=Gi,Ae=Fi,bt=le,J=dt,Ke="[object Map]",Bi="[object Object]",Ve="[object Promise]",We="[object Set]",Ye="[object WeakMap]",Je="[object DataView]",Ui=J(_e),zi=J(be),Ni=J(me),Ki=J($e),Vi=J(Ae),F=bt;(_e&&F(new _e(new ArrayBuffer(1)))!=Je||be&&F(new be)!=Ke||me&&F(me.resolve())!=Ve||$e&&F(new $e)!=We||Ae&&F(new Ae)!=Ye)&&(F=function(e){var t=bt(e),r=t==Bi?e.constructor:void 0,a=r?J(r):"";if(a)switch(a){case Ui:return Je;case zi:return Ke;case Ni:return Ve;case Ki:return We;case Vi:return Ye}return t});var Wi=F,ye=Sn,Yi=ht,Ji=ps,Xi=Si,Xe=Wi,Ze=Pe,Qe=pt,Zi=_t,Qi=1,et="[object Arguments]",tt="[object Array]",te="[object Object]",ec=Object.prototype,rt=ec.hasOwnProperty;function tc(e,t,r,a,o,n){var c=Ze(e),i=Ze(t),f=c?tt:Xe(e),v=i?tt:Xe(t);f=f==et?te:f,v=v==et?te:v;var w=f==te,y=v==te,_=f==v;if(_&&Qe(e)){if(!Qe(t))return!1;c=!0,w=!1}if(_&&!w)return n||(n=new ye),c||Zi(e)?Yi(e,t,r,a,o,n):Ji(e,t,f,r,a,o,n);if(!(r&Qi)){var $=w&&rt.call(e,"__wrapped__"),m=y&&rt.call(t,"__wrapped__");if($||m){var T=$?e.value():e,u=m?t.value():t;return n||(n=new ye),o(T,u,r,a,n)}}return _?(n||(n=new ye),Xi(e,t,r,a,o,n)):!1}var rc=tc,ac=rc,at=ve;function mt(e,t,r,a,o){return e===t?!0:e==null||t==null||!at(e)&&!at(t)?e!==e&&t!==t:ac(e,t,r,a,mt,o)}var nc=mt,sc=nc;function oc(e,t){return sc(e,t)}var ic=oc;const cc=It(ic);function uc(e,t){return Object.is(e,t)}function Z(e,t,r=Object.is){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;const a=Object.keys(e),o=Object.keys(t);if(a.length!==o.length)return!1;for(const n of a)if(!Object.prototype.hasOwnProperty.call(t,n)||!r(e[n],t[n]))return!1;return!0}function De(e,t){return Z(e,t,Z)}function lc(e,t){return Z(e,t,De)}const $t=cc;function he(e){return!e||e==="strict"?uc:e==="shallow"?Z:e==="shallow2"?De:e==="shallow3"?lc:e==="deep"?$t:e}function nt(e){const t=e;let r=e;return Object.assign((...a)=>r(...a),{getOriginal:()=>t,getCurrent:()=>r,setCurrent(a){r=a}})}function fc(e){return typeof e=="function"&&"getOriginal"in e&&"getCurrent"in e&&"setCurrent"in e}function dc(e,t,r){return e?typeof t=="function"?fc(e.value)?(e.value.setCurrent(t),[e.value,!0]):[nt(t),!1]:t&&t instanceof Date?e.value&&e.value instanceof Date&&t.getTime()===e.value.getTime()?[e.value,!0]:[t,!1]:r(e.value,t)?[e.value,!0]:[t,!1]:typeof t=="function"?[nt(t),!1]:[t,!1]}const ie=M.hook(e=>e()),Q=Symbol.for("atomirx.atom"),we=Symbol.for("atomirx.derived"),Te=Symbol.for("atomirx.scoped"),Se=Symbol.for("atomirx.pool");function z(e){return Object.assign(e,{use(t){if(typeof t!="function")return z(Object.assign({},e,t));const r=t(e);return r?typeof r=="object"||typeof r=="function"?z(r):r:e}})}function D(e){return e!==null&&typeof e=="object"&&"then"in e&&typeof e.then=="function"}const Ce=new WeakMap;function st(e){return Ce.get(e)}function re(e,t){if(t.length===1){if(e==="allSettled"){const a=Promise.allSettled(t).then(()=>{});return Ce.set(a,{type:e,promises:t}),a}return t[0]}const r=Promise[e](t);return r.catch(()=>{}),Ce.set(r,{type:e,promises:t}),r}function vc(e,t){if(e===t)return!0;if(!e||!t)return!1;const r=st(e),a=st(t);return!!r&&!!a&&De(r,a)}const U=new WeakMap;function k(e){const t=U.get(e);if(t)return t;const r={status:"pending",promise:e};return U.set(e,r),e.then(a=>{const o=U.get(e);(o==null?void 0:o.status)==="pending"&&U.set(e,{status:"fulfilled",value:a})},a=>{const o=U.get(e);(o==null?void 0:o.status)==="pending"&&U.set(e,{status:"rejected",error:a})}),r}function hc(e){if(!D(e))return e;const r=k(e);switch(r.status){case"pending":throw r.promise;case"rejected":throw r.error;case"fulfilled":return r.value}}function gc(e){return D(e)?k(e).status==="pending":!1}function pc(e){return D(e)?k(e).status==="fulfilled":!1}function yc(e){return D(e)?k(e).status==="rejected":!1}function At(e,t={}){var j,I,R;const r=B(),a=he(t.equals);let o=null;const n=B();let c=!1;const i=s=>{o&&(o.abort(s),o=null),n.emitAndClear()},f=()=>(o=new AbortController,z({signal:o.signal,onCleanup:n.on})),v=typeof e=="function";let y=v?e(f()):e,_=!1;D(y)&&k(y);const $=()=>{r.forEach(s=>{ie.current(s)})},m=s=>{if(c)return;let l;typeof s=="function"?l=s(y):l=s,!a(l,y)&&(i("value changed"),y=l,_=!0,D(y)&&k(y),$())},T=()=>{if(c)return;i("reset");const s=v?e(f()):e;D(s)&&k(s);const l=!a(s,y);y=s,_=!1,l&&$()},u=()=>_,d=()=>{c||(c=!0,i("disposed"),r.clear())},p=()=>{},C=s=>c?p:r.on(s),P=z({[Q]:!0,meta:t.meta,get(){return y},use:void 0,set:m,reset:T,dirty:u,_dispose:d,on:C});return(R=(I=M.onCreateHook).current)==null||R.call(I,{type:"mutable",key:(j=t.meta)==null?void 0:j.key,meta:t.meta,instance:P}),P}function _c(e){return e}let ae=0;function wt(e){if(ae++,ae===1){let t=new Set;const r=a=>{t.add(a)};try{return M.hook.use([ie(()=>r)],e)}finally{ae--,M.hook.use([ie(()=>r)],()=>{for(;t.size>0;){const a=t;t=new Set;for(const o of a)o()}})}}try{return e()}finally{ae--}}function bc(e,t){let r,a;const o=i=>{i&&typeof i=="object"&&"dispose"in i&&typeof i.dispose=="function"&&i.dispose()},n=()=>{o(r),r=void 0};return Object.assign(()=>{var i,f;return r||(a?r=a(e):r=e(),(f=(i=M.onCreateHook).current)==null||f.call(i,{type:"module",key:t==null?void 0:t.key,meta:t==null?void 0:t.meta,instance:r})),r},{key:t==null?void 0:t.key,override:i=>{if(r!==void 0)throw new Error("Cannot override after initialization. Call override() before accessing the service.");a=i},reset:()=>{a=void 0,n()},invalidate:()=>{a=void 0,n()},isOverridden:()=>a!==void 0,isInitialized:()=>r!==void 0})}function Ee(e){return e!==null&&typeof e=="object"&&Q in e&&e[Q]===!0}function Tt(e){return e!==null&&typeof e=="object"&&we in e&&e[we]===!0}function q(e){if(Tt(e))return e.state();const t=e.get();if(!D(t))return{status:"ready",value:t};const r=k(t);switch(r.status){case"fulfilled":return{status:"ready",value:r.value};case"rejected":return{status:"error",error:r.error};case"pending":return{status:"loading",promise:r.promise}}}const mc=typeof AggregateError<"u"?AggregateError:class extends Error{constructor(r,a){super(a);O(this,"errors");this.name="AggregateError",this.errors=r}};class $c extends Error{constructor(r,a="All atoms rejected"){super(a);O(this,"errors");this.name="AllAtomsRejectedError",this.errors=r}}function Ac(e){let t=e;const r=n=>{throw new Error(`ScopedAtom.${n}() is not allowed. ScopedAtom cannot be accessed directly - use read(virtualAtom) in select context instead. This prevents orphan atom references and ensures proper reactive tracking.`)},a=()=>{if(!t)throw new Error("ScopedAtom._getAtom() was called after disposal. ScopedAtoms are only valid during select() execution. Always use from(pool, params) inside the computation, not outside.");return t};return{[Q]:!0,[Te]:!0,get meta(){return r("meta")},get(){return r("get")},on(n){return r("on")},_getAtom(){return a()},_dispose(){t=void 0}}}function L(e){return e!==null&&typeof e=="object"&&Te in e&&e[Te]===!0}function St(e,t=null){const r=new Set,a=new Map,o=new Map;let n=!0,c=!1;const i=s=>{if(!n)throw new Error(`${s}() was called outside of the selection context. This usually happens when calling context methods in async callbacks (setTimeout, Promise.then, etc.). All atom reads must happen synchronously during selector execution. For async access, use atom.get() directly.`)},f=s=>{i("track"),!c&&(L(s)?r.add(s._getAtom()):r.add(s))},v=(s,l)=>{i("from"),a.has(s)||a.set(s,new Set),a.get(s).add(l);const g=s._getAtom(l);if(o.has(g))return o.get(g);const h=Ac(g);return o.set(g,h),h},w=s=>{i("read"),f(s);const l=L(s)?s._getAtom():s,g=q(l);switch(g.status){case"ready":return g.value;case"error":throw g.error;case"loading":throw g.promise}},y=s=>{i("all");const l=[],g=[];for(const h of s){f(h);const E=L(h)?h._getAtom():h,b=q(E);switch(b.status){case"ready":l.push(b.value);break;case"error":throw b.error;case"loading":g.push(b.promise);break}}if(g.length>0)throw re("all",g);return l},_=s=>{i("race");const l=[],g=Object.entries(s);for(const[h,E]of g){f(E);const b=L(E)?E._getAtom():E,A=q(b);switch(A.status){case"ready":return{key:h,value:A.value};case"error":throw A.error;case"loading":l.push(A.promise);break}}throw l.length>0?re("race",l):new Error("race() called with no atoms")},$=s=>{i("any");const l=[],g=[],h=Object.entries(s);for(const[E,b]of h){f(b);const A=L(b)?b._getAtom():b,x=q(A);switch(x.status){case"ready":return{key:E,value:x.value};case"error":l.push(x.error);break;case"loading":g.push(x.promise);break}}throw g.length>0?re("race",g):new mc(l,"All atoms rejected")},m=s=>{i("settled");const l=[],g=[];for(const h of s){f(h);const E=L(h)?h._getAtom():h,b=q(E);switch(b.status){case"ready":l.push({status:"ready",value:b.value});break;case"error":l.push({status:"error",error:b.error});break;case"loading":g.push(b.promise);break}}if(g.length>0)throw re("allSettled",g);return l},T=s=>{i("safe");try{return[void 0,s()]}catch(l){if(D(l))throw l;return[l,void 0]}};function u(s){if(i("state"),Ee(s)){f(s);const l=L(s)?s._getAtom():s,g=q(l);switch(g.status){case"ready":return{status:"ready",value:g.value,error:void 0};case"error":return{status:"error",value:void 0,error:g.error};case"loading":return{status:"loading",value:void 0,error:void 0}}}try{return{status:"ready",value:s(),error:void 0}}catch(l){return D(l)?{status:"loading",value:void 0,error:void 0}:{status:"error",value:void 0,error:l}}}const d=s=>{if(typeof s=="boolean")return s;if(typeof s=="function"){const l=s();return typeof l=="boolean"?l:!!w(l)}return!!w(s)},p=s=>{i("and");for(const l of s)if(!d(l))return!1;return!0},C=s=>{i("or");for(const l of s)if(d(l))return!0;return!1};function P(s){if(i("untrack"),Ee(s)){const g=L(s)?s._getAtom():s,h=q(g);switch(h.status){case"ready":return h.value;case"error":throw h.error;case"loading":throw h.promise}}const l=c;c=!0;try{return s()}finally{c=l}}const j=z({read:w,from:v,track:f,all:y,any:$,race:_,settled:m,safe:T,state:u,and:p,or:C,untrack:P});let I;try{const s=e(j);if(D(s))throw new Error("select() selector must return a synchronous value, not a Promise. For async data, create an async atom with atom(Promise) and use read() to read it.");I={value:s,error:void 0,promise:void 0,dependencies:r,_atomDeps:r,_poolDeps:a}}catch(s){D(s)?I={value:void 0,error:void 0,promise:s,dependencies:r,_atomDeps:r,_poolDeps:a}:I={value:void 0,error:s,promise:void 0,dependencies:r,_atomDeps:r,_poolDeps:a}}finally{n=!1;for(const s of o.values())s._dispose();o.clear()}return{result:I,startTracking:s=>{const l=[];for(const g of r)l.push(g.on(s));for(const[g,h]of a)for(const E of h)l.push(g._onRemove(E,s));return()=>{for(const g of l)g()}}}}function ot(e){if(e==null)throw new Promise(()=>{});if(D(e)){const t=k(e);if(t.status==="pending")throw t.promise;if(t.status==="fulfilled")return t.value;throw t.error}return e}function wc(){return e=>({...e,ready:(t,r)=>{if(typeof t=="function"){const n=t();if(D(n))throw new Error("ready(callback) overload does not support async callbacks. Use ready(atom, selector?) instead.");return ot(n)}const a=e.read(t),o=r?r(a):a;return ot(o)}})}function Ct(e,t={}){var s,l,g;const r=B(),a=he(t.equals),o="fallback"in t,n=t.fallback;let c,i,f=null,v=!1,w=!1,y=!1,_=0,$=null,m=null;const T=new Map;let u=[],d;const p=h=>{var b,A,x;(b=t.onError)==null||b.call(t,h);const E=t._errorSource??d;(x=(A=M.onErrorHook).current)==null||x.call(A,{source:E,error:h})},C=()=>{r.forEach(h=>{ie.current(h)})},P=h=>{const E=h._atomDeps,b=h._poolDeps;for(const[A,x]of T)E.has(A)||(x(),T.delete(A));for(const A of E)if(!T.has(A)){const x=A.on(()=>{j()});T.set(A,x)}for(const A of u)A();u=[];for(const[A,x]of b)for(const H of x){const Et=A._onRemove(H,()=>{j()});u.push(Et)}},j=(h=!1)=>{const E=++_;return w=!0,i=void 0,$||(f=new Promise((b,A)=>{$=b,m=A}),f.catch(()=>{})),(async()=>{for(;;){if(_!==E)return;const{result:b}=St(H=>e(H.use(wc())));if(P(b),b.promise){h||C();try{if(await b.promise,_!==E)return;continue}catch(H){if(_!==E)return;w=!1,i=H,m==null||m(H),$=null,m=null,p(H),C();return}}if(b.error!==void 0){w=!1,i=b.error,m==null||m(b.error),$=null,m=null,p(b.error),h||C();return}const A=b.value,x=!c;w=!1,i=void 0,(!c||!a(A,c.value))&&(c={value:A},(x||!h)&&C()),$==null||$(A),$=null,m=null;return}})(),f},I=()=>{v||(v=!0,j(!0))},R={[Q]:!0,[we]:!0,meta:t.meta,get(){return I(),f},get staleValue(){if(I(),c)return c.value;if(o)return n},state(){return I(),w?{status:"loading",promise:f}:i!==void 0?{status:"error",error:i}:c?{status:"ready",value:c.value}:{status:"loading",promise:f}},refresh(){y||(v?j():I())},on(h){return y?()=>{}:(I(),r.on(h))},_dispose(){if(!y){y=!0;for(const h of T.values())h();T.clear();for(const h of u)h();u=[],r.clear()}}};return d={type:"derived",key:(s=t.meta)==null?void 0:s.key,meta:t.meta,instance:R},(g=(l=M.onCreateHook).current)==null||g.call(l,d),R}function Tc(e){return t=>{const r=new AbortController;return e(()=>r.abort()),{...t,signal:r.signal,abort:()=>!r.signal.aborted&&r.abort()}}}function Sc(e,t){var i,f,v;let r=!1;const a=B(),o={meta:t==null?void 0:t.meta,dispose:()=>{r||(r=!0,a.emitAndClear())}},n={type:"effect",key:(i=t==null?void 0:t.meta)==null?void 0:i.key,meta:t==null?void 0:t.meta,instance:o};return Ct(w=>{if(a.emitAndClear(),r)return;const y=a.on,_=w.use({onCleanup:y}).use(Tc(y));wt(()=>e(_))},{onError:t==null?void 0:t.onError,_errorSource:n}).get(),(v=(f=M.onCreateHook).current)==null||v.call(f,n),o}function Cc(e,t){var m,T;const{gcTime:r,meta:a}=t,o=he(t.equals??"shallow"),n=[],c=new WeakMap,i=B(),f=u=>u!==null&&(typeof u=="object"||typeof u=="function"),v=u=>{if(f(u)){const d=c.get(u);if(d){const p=n.indexOf(d);if(p!==-1)return{entry:d,index:p};c.delete(u)}}for(let d=0;d<n.length;d++)if(o(n[d].params,u))return f(u)&&c.set(u,n[d]),{entry:n[d],index:d}},w=u=>{const d=At(s=>e(u,s));let p={},C=null;const P=s=>{C&&(clearTimeout(C),C=null);const l=p={};if(D(s)&&k(s).status==="pending"){const h=()=>{p===l&&P(s)};s.then(h,h);return}C=setTimeout(()=>{p===l&&_(u)},r)},j=()=>P(d.get()),I=()=>{C&&(clearTimeout(C),C=null),R()},R=d.on(()=>{p={};const s=d.get();j(),i.emit({type:"change",params:u,value:s})});return j(),{atom:d,params:u,disposeEmitter:B(),resetGC:j,cleanup:I}},y=u=>{const d=v(u);if(d)return d.entry;const p=w(u);return n.push(p),i.emit({type:"create",params:u,value:p.atom.get()}),p},_=u=>{const d=v(u);if(!d)return;const{entry:p,index:C}=d;p.atom._dispose(),p.cleanup();const P=p.atom.get(),j=p.params;p.disposeEmitter.emitAndClear(),n.splice(C,1),i.emit({type:"remove",params:j,value:P})},$={[Se]:!0,meta:a,size(){return n.length},get(u){const d=y(u);return d.resetGC(),d.atom.get()},set(u,d){const p=y(u);p.resetGC(),p.atom.set(d)},has(u){return v(u)!==void 0},remove(u){_(u)},clear(){const u=[...n];for(const d of u)_(d.params)},forEach(u){for(const d of n)u(d.atom.get(),d.params)},on(u){return i.on(u)},_getAtom(u){return y(u).atom},_onRemove(u,d){const p=v(u);return p?p.entry.disposeEmitter.on(d):()=>{}}};return(T=(m=M.onCreateHook).current)==null||T.call(m,{type:"pool",key:a==null?void 0:a.key,meta:a,instance:$}),$}function Ec(e){return e!==null&&typeof e=="object"&&Se in e&&e[Se]===!0}exports.AllAtomsRejectedError=$c;exports.atom=At;exports.batch=wt;exports.deepEqual=$t;exports.define=bc;exports.derived=Ct;exports.effect=Sc;exports.emitter=B;exports.getAtomState=q;exports.isAtom=Ee;exports.isDerived=Tt;exports.isFulfilled=pc;exports.isPending=gc;exports.isPool=Ec;exports.isPromiseLike=D;exports.isRejected=yc;exports.isScopedAtom=L;exports.pool=Cc;exports.promisesEqual=vc;exports.readonly=_c;exports.resolveEquality=he;exports.select=St;exports.shallowEqual=Z;exports.trackPromise=k;exports.tryStabilize=dc;exports.unwrap=hc;exports.withUse=z;