@but212/atom-effect-jquery 0.16.0 → 0.17.0

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.
package/dist/index.mjs CHANGED
@@ -1,22 +1,21 @@
1
- import l from "jquery";
2
- import { default as Vt } from "jquery";
3
- const Ze = {
4
- /** One second in milliseconds */
1
+ import u from "jquery";
2
+ import { default as Me } from "jquery";
3
+ const Wt = {
5
4
  ONE_SECOND_MS: 1e3
6
- }, _e = {
5
+ }, ht = {
7
6
  IDLE: "idle",
8
7
  PENDING: "pending",
9
8
  RESOLVED: "resolved",
10
9
  REJECTED: "rejected"
11
- }, w = {
10
+ }, F = {
12
11
  DISPOSED: 1,
13
12
  HAS_FN_SUBS: 2,
14
13
  HAS_OBJ_SUBS: 4
15
- }, U = {
16
- ...w,
14
+ }, k = {
15
+ ...F,
17
16
  EXECUTING: 8
18
- }, f = {
19
- ...w,
17
+ }, h = {
18
+ ...F,
20
19
  DIRTY: 8,
21
20
  IDLE: 16,
22
21
  PENDING: 32,
@@ -24,695 +23,540 @@ const Ze = {
24
23
  REJECTED: 128,
25
24
  RECOMPUTING: 256,
26
25
  HAS_ERROR: 512
27
- }, L = {
28
- ...w,
26
+ }, R = {
27
+ ...F,
29
28
  SYNC: 8,
30
29
  NOTIFICATION_SCHEDULED: 16
31
- }, q = {
32
- /** Maximum effect executions per second to detect infinite loops (Legacy/Fallback) */
30
+ }, $ = {
31
+ // Infinite loop protection
33
32
  MAX_EXECUTIONS_PER_SECOND: 1e3,
34
- /**
35
- * Maximum executions per effect within a single flush cycle
36
- * Increased from 50 to 100
37
- */
38
33
  MAX_EXECUTIONS_PER_EFFECT: 100,
39
- /**
40
- * Maximum total executions across all effects in a single flush cycle
41
- * Increased from 5000 to 10000
42
- */
34
+ // Batch processing limits to prevent blocking the main thread for too long
43
35
  MAX_EXECUTIONS_PER_FLUSH: 1e4,
44
- /** Maximum iterations for synchronous flush loop to prevent infinite loops */
45
36
  MAX_FLUSH_ITERATIONS: 1e3,
46
- /** Minimum allowed value for max flush iterations */
47
37
  MIN_FLUSH_ITERATIONS: 10,
48
- /** Threshold for shrinking the batch queue to assist GC */
49
38
  BATCH_QUEUE_SHRINK_THRESHOLD: 1e3
50
- }, we = {
51
- /** Maximum dependencies before warning about large dependency graphs */
39
+ }, kt = {
52
40
  MAX_DEPENDENCIES: 1e3,
53
- /** Enable infinite loop detection warnings */
54
41
  WARN_INFINITE_LOOP: !0
55
- }, K = 1073741823, Z = typeof process < "u" && process.env && process.env.NODE_ENV !== "production", et = Object.freeze([]);
56
- class Q extends Error {
57
- /**
58
- * Creates a new AtomError
59
- * @param message - Error message describing what went wrong
60
- * @param cause - Original error that caused this error
61
- * @param recoverable - Whether the operation can be retried
62
- */
63
- constructor(e, t = null, s = !0) {
64
- super(e), this.name = "AtomError", this.cause = t, this.recoverable = s, this.timestamp = /* @__PURE__ */ new Date();
42
+ }, G = 1073741823, m = typeof process < "u" && process.env && process.env.NODE_ENV !== "production" || typeof __DEV__ < "u" && !!__DEV__, Kt = Object.freeze([]);
43
+ class Z extends Error {
44
+ constructor(t, e = null, s = !0) {
45
+ super(t), this.cause = e, this.recoverable = s, this.timestamp = /* @__PURE__ */ new Date(), this.name = "AtomError";
65
46
  }
66
47
  }
67
- class $ extends Q {
68
- /**
69
- * Creates a new ComputedError
70
- * @param message - Error message
71
- * @param cause - Original error
72
- */
73
- constructor(e, t = null) {
74
- super(e, t, !0), this.name = "ComputedError";
48
+ class B extends Z {
49
+ constructor(t, e = null) {
50
+ super(t, e, !0), this.name = "ComputedError";
75
51
  }
76
52
  }
77
- class Y extends Q {
78
- /**
79
- * Creates a new EffectError
80
- * @param message - Error message
81
- * @param cause - Original error
82
- */
83
- constructor(e, t = null) {
84
- super(e, t, !1), this.name = "EffectError";
53
+ class q extends Z {
54
+ constructor(t, e = null) {
55
+ super(t, e, !1), this.name = "EffectError";
85
56
  }
86
57
  }
87
- class ue extends Q {
88
- /**
89
- * Creates a new SchedulerError
90
- * @param message - Error message
91
- * @param cause - Original error
92
- */
93
- constructor(e, t = null) {
94
- super(e, t, !1), this.name = "SchedulerError";
58
+ class it extends Z {
59
+ constructor(t, e = null) {
60
+ super(t, e, !1), this.name = "SchedulerError";
95
61
  }
96
62
  }
97
- const C = {
98
- // ─────────────────────────────────────────────────────────────────
99
- // Computed errors
100
- // ─────────────────────────────────────────────────────────────────
101
- /**
102
- * Error thrown when computed() receives a non-function argument.
103
- */
104
- COMPUTED_MUST_BE_FUNCTION: "Computed function must be a function",
105
- /**
106
- * Error thrown when accessing a pending async computed without a default value.
107
- */
108
- COMPUTED_ASYNC_PENDING_NO_DEFAULT: "Async computation is pending. No default value provided",
109
- /**
110
- * Error thrown when a synchronous computed computation fails.
111
- */
112
- COMPUTED_COMPUTATION_FAILED: "Computed computation failed",
113
- /**
114
- * Error thrown when an asynchronous computed computation fails.
115
- */
116
- COMPUTED_ASYNC_COMPUTATION_FAILED: "Async computed computation failed",
117
- /**
118
- * Error thrown when a circular dependency is detected during computation.
119
- */
120
- COMPUTED_CIRCULAR_DEPENDENCY: "Circular dependency detected during computation",
121
- /**
122
- * Error thrown when accessing a disposed computed value.
123
- */
124
- COMPUTED_DISPOSED: "Cannot access a disposed computed",
125
- // ─────────────────────────────────────────────────────────────────
126
- // Atom errors
127
- // ─────────────────────────────────────────────────────────────────
128
- /**
129
- * Error thrown when atom.subscribe() receives an invalid listener.
130
- */
131
- ATOM_SUBSCRIBER_MUST_BE_FUNCTION: "Subscription listener must be a function or Subscriber object",
132
- /**
133
- * Error logged when an individual subscriber throws during notification.
134
- * @remarks This error is caught and logged to prevent cascading failures.
135
- */
136
- ATOM_INDIVIDUAL_SUBSCRIBER_FAILED: "Error during individual atom subscriber execution",
137
- // ─────────────────────────────────────────────────────────────────
138
- // Effect errors
139
- // ─────────────────────────────────────────────────────────────────
140
- /**
141
- * Error thrown when effect() receives a non-function argument.
142
- */
143
- EFFECT_MUST_BE_FUNCTION: "Effect function must be a function",
144
- /**
145
- * Error thrown when an effect's execution fails.
146
- */
147
- EFFECT_EXECUTION_FAILED: "Effect execution failed",
148
- /**
149
- * Error thrown when an effect's cleanup function fails.
150
- */
151
- EFFECT_CLEANUP_FAILED: "Effect cleanup function execution failed",
152
- /**
153
- * Error thrown when attempting to run a disposed effect.
154
- */
155
- EFFECT_DISPOSED: "Cannot run a disposed effect",
156
- // ─────────────────────────────────────────────────────────────────
157
- // Debug warnings
158
- // ─────────────────────────────────────────────────────────────────
159
- /**
160
- * Warning message for large dependency graphs.
161
- *
162
- * @param count - The number of dependencies detected
163
- * @returns Formatted warning message with dependency count
164
- *
165
- * @example
166
- * ```ts
167
- * console.warn(ERROR_MESSAGES.LARGE_DEPENDENCY_GRAPH(150));
168
- * // Output: "Large dependency graph detected: 150 dependencies"
169
- * ```
170
- */
171
- LARGE_DEPENDENCY_GRAPH: (n) => `Large dependency graph detected: ${n} dependencies`,
172
- /**
173
- * Error logged when the onError callback itself throws an error.
174
- * @remarks This prevents cascading failures from masking the original error.
175
- */
176
- CALLBACK_ERROR_IN_ERROR_HANDLER: "Error occurred during onError callback execution"
177
- }, Se = /* @__PURE__ */ Symbol("debugName"), tt = /* @__PURE__ */ Symbol("id"), ye = /* @__PURE__ */ Symbol("type"), Ie = /* @__PURE__ */ Symbol("noDefaultValue");
178
- function nt(n) {
179
- return "dependencies" in n && Array.isArray(n.dependencies);
180
- }
181
- function Ve(n, e, t) {
182
- if (!t.has(n.id)) {
183
- if (t.add(n.id), n === e)
184
- throw new $("Indirect circular dependency detected");
185
- if (nt(n)) {
186
- const s = n.dependencies;
187
- for (let i = 0; i < s.length; i++) {
188
- const o = s[i];
189
- o && Ve(o, e, t);
190
- }
63
+ const At = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), Zt = /* @__PURE__ */ Symbol("AtomEffect.Id"), vt = /* @__PURE__ */ Symbol("AtomEffect.Type"), pt = /* @__PURE__ */ Symbol("AtomEffect.NoDefaultValue"), te = (n) => "dependencies" in n && Array.isArray(n.dependencies);
64
+ function Bt(n, t, e) {
65
+ if (n === t)
66
+ throw new B(
67
+ "Circular dependency detected: The computation refers to itself explicitly or implicitly."
68
+ );
69
+ if (!e.has(n.id) && (e.add(n.id), te(n))) {
70
+ const s = n.dependencies;
71
+ for (let i = 0; i < s.length; i++) {
72
+ const o = s[i];
73
+ o && Bt(o, t, e);
191
74
  }
192
75
  }
193
76
  }
194
- const F = {
195
- enabled: typeof process < "u" && process.env?.NODE_ENV === "development",
196
- maxDependencies: we.MAX_DEPENDENCIES,
197
- warnInfiniteLoop: we.WARN_INFINITE_LOOP,
198
- warn(n, e) {
199
- this.enabled && n && console.warn(`[Atom Effect] ${e}`);
77
+ const X = {
78
+ // Dev mode flag
79
+ enabled: m,
80
+ maxDependencies: kt.MAX_DEPENDENCIES,
81
+ warnInfiniteLoop: kt.WARN_INFINITE_LOOP,
82
+ warn(n, t) {
83
+ m && this.enabled && n && console.warn(`[Atom Effect] ${t}`);
200
84
  },
201
- /**
202
- * Checks for circular dependencies.
203
- * Direct check runs always; indirect check only in dev mode.
204
- * @throws {ComputedError} When circular dependency detected
205
- */
206
- checkCircular(n, e) {
207
- if (n === e)
208
- throw new $("Direct circular dependency detected");
209
- this.enabled && Ve(n, e, /* @__PURE__ */ new Set());
85
+ checkCircular(n, t) {
86
+ if (n === t)
87
+ throw new B("Direct circular dependency detected");
88
+ m && this.enabled && Bt(n, t, /* @__PURE__ */ new Set());
210
89
  },
211
- attachDebugInfo(n, e, t) {
212
- if (!this.enabled)
213
- return;
90
+ attachDebugInfo(n, t, e) {
91
+ if (!m || !this.enabled) return;
214
92
  const s = n;
215
- s[Se] = `${e}_${t}`, s[tt] = t, s[ye] = e;
216
- },
217
- getDebugName(n) {
218
- if (n != null && Se in n)
219
- return n[Se];
93
+ s[At] = `${t}_${e}`, s[Zt] = e, s[vt] = t;
220
94
  },
221
- getDebugType(n) {
222
- if (n != null && ye in n)
223
- return n[ye];
224
- }
95
+ getDebugName: (n) => n?.[At],
96
+ getDebugType: (n) => n?.[vt]
225
97
  };
226
- let st = 1;
227
- const it = () => st++;
228
- class He {
229
- constructor() {
230
- this.flags = 0, this.version = 0, this._lastSeenEpoch = -1, this._modifiedAtEpoch = -1, this.id = it() & K, this._tempUnsub = void 0;
231
- }
232
- }
233
- class ze extends He {
234
- /**
235
- * Subscribes a listener function or Subscriber object to value changes.
236
- */
237
- subscribe(e) {
238
- if (typeof e == "function")
239
- return this._addSubscriber(this._fnSubs, e, w.HAS_FN_SUBS);
240
- if (e !== null && typeof e == "object" && "execute" in e)
241
- return this._addSubscriber(this._objSubs, e, w.HAS_OBJ_SUBS);
242
- throw new Q(C.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);
98
+ let ee = 1;
99
+ const ne = () => ee++;
100
+ function $t(n, t, e) {
101
+ if (typeof t == "function") {
102
+ const i = t;
103
+ for (let o = 0, r = e.length; o < r; o++) {
104
+ const c = e[o];
105
+ if (c && c.fn === i) return;
106
+ }
107
+ e.push(new St(i, void 0)), n.flags |= F.HAS_FN_SUBS, "_fnSubCount" in n && n._fnSubCount++;
108
+ return;
243
109
  }
244
- /**
245
- * Internal helper for subscription logic to reduce code duplication and branching.
246
- */
247
- _addSubscriber(e, t, s) {
248
- return e.indexOf(t) !== -1 ? (Z && console.warn(
249
- "Attempted to subscribe the same listener twice. Ignoring duplicate subscription."
250
- ), () => {
251
- }) : (e.push(t), this.flags |= s, () => {
252
- const i = e.indexOf(t);
253
- if (i === -1) return;
254
- const o = e.pop();
255
- i < e.length && (e[i] = o), e.length === 0 && (this.flags &= ~s);
256
- });
110
+ if ("addDependency" in t) {
111
+ t.addDependency(n);
112
+ return;
257
113
  }
258
- /**
259
- * Gets the total number of active subscribers.
260
- */
261
- subscriberCount() {
262
- return this._fnSubs.length + this._objSubs.length;
114
+ const s = t;
115
+ for (let i = 0, o = e.length; i < o; i++) {
116
+ const r = e[i];
117
+ if (r && r.sub === s) return;
263
118
  }
264
- /**
265
- * Notifies all subscribers of a change.
266
- */
267
- _notifySubscribers(e, t) {
268
- const s = this.flags;
269
- if (s & (w.HAS_FN_SUBS | w.HAS_OBJ_SUBS)) {
270
- if (s & w.HAS_FN_SUBS) {
271
- const i = this._fnSubs;
272
- for (let o = 0; o < i.length; o++)
273
- try {
274
- i[o](e, t);
275
- } catch (r) {
276
- this._handleNotifyError(r);
277
- }
278
- }
279
- if (s & w.HAS_OBJ_SUBS) {
280
- const i = this._objSubs;
281
- for (let o = 0; o < i.length; o++)
282
- try {
283
- i[o].execute();
284
- } catch (r) {
285
- this._handleNotifyError(r);
286
- }
287
- }
119
+ e.push(new St(void 0, s)), n.flags |= F.HAS_OBJ_SUBS, "_objSubCount" in n && n._objSubCount++;
120
+ }
121
+ function se(n, t, e) {
122
+ for (let s = 0, i = t.length; s < i; s++) {
123
+ const o = t[s];
124
+ o && (o.node._tempUnsub = o.unsub);
125
+ }
126
+ for (let s = 0, i = n.length; s < i; s++) {
127
+ const o = n[s];
128
+ if (!o) continue;
129
+ const r = o.node;
130
+ r._tempUnsub !== void 0 ? (o.unsub = r._tempUnsub, r._tempUnsub = void 0) : (X.checkCircular(r, e), o.unsub = r.subscribe(e));
131
+ }
132
+ for (let s = 0, i = t.length; s < i; s++) {
133
+ const o = t[s];
134
+ if (o) {
135
+ const r = o.node;
136
+ r._tempUnsub !== void 0 && (r._tempUnsub(), r._tempUnsub = void 0), o.unsub = void 0;
288
137
  }
289
138
  }
290
- /**
291
- * Hoisted error reporter to keep notification loops lean and aid JIT inlining.
292
- */
293
- _handleNotifyError(e) {
294
- console.error(new Q(C.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED, e));
139
+ }
140
+ class mt {
141
+ constructor(t, e, s = void 0) {
142
+ this.node = t, this.version = e, this.unsub = s;
295
143
  }
296
144
  }
297
- class ot {
298
- constructor() {
299
- this.frozen = 0, this.tooLarge = 0, this.poolFull = 0;
145
+ class St {
146
+ constructor(t, e) {
147
+ this.fn = t, this.sub = e;
300
148
  }
301
149
  }
302
- class rt {
150
+ const S = {
151
+ // Computed Errors
152
+ COMPUTED_MUST_BE_FUNCTION: "Computed target must be a function",
153
+ COMPUTED_ASYNC_PENDING_NO_DEFAULT: "Async computation pending with no default value",
154
+ COMPUTED_COMPUTATION_FAILED: "Computation execution failed",
155
+ COMPUTED_ASYNC_COMPUTATION_FAILED: "Async computation execution failed",
156
+ COMPUTED_CIRCULAR_DEPENDENCY: "Circular dependency detected",
157
+ COMPUTED_DISPOSED: "Attempted to access disposed computed",
158
+ // Atom Errors
159
+ ATOM_SUBSCRIBER_MUST_BE_FUNCTION: "Subscriber must be a function or Subscriber object",
160
+ ATOM_INDIVIDUAL_SUBSCRIBER_FAILED: "Subscriber execution failed",
161
+ // Effect Errors
162
+ EFFECT_MUST_BE_FUNCTION: "Effect target must be a function",
163
+ EFFECT_EXECUTION_FAILED: "Effect execution failed",
164
+ EFFECT_CLEANUP_FAILED: "Effect cleanup failed",
165
+ EFFECT_DISPOSED: "Attempted to run disposed effect",
166
+ CALLBACK_ERROR_IN_ERROR_HANDLER: "Exception encountered in onError handler"
167
+ };
168
+ function K(n, t, e) {
169
+ if (n instanceof Z)
170
+ return n;
171
+ const s = n instanceof Error, i = s ? n.message : String(n), o = s ? n : void 0;
172
+ let r = "Unexpected error";
173
+ n instanceof TypeError ? r = "Type error" : n instanceof ReferenceError && (r = "Reference error");
174
+ const c = `${r} (${e}): ${i}`;
175
+ return new t(c, o);
176
+ }
177
+ class jt {
303
178
  constructor() {
304
- this.acquired = 0, this.released = 0, this.rejected = new ot();
179
+ this.flags = 0, this.version = 0, this._lastSeenEpoch = -1, this._modifiedAtEpoch = -1, this.id = ne() & G, this._tempUnsub = void 0;
305
180
  }
306
181
  }
307
- class Ne {
182
+ class Ht extends jt {
308
183
  constructor() {
309
- this.pool = [], this.maxPoolSize = 50, this.maxReusableCapacity = 256, this.stats = Z ? new rt() : null;
310
- }
311
- /** Acquires an array from the pool or creates a new one if the pool is empty. */
312
- acquire() {
313
- const e = this.stats;
314
- return e && e.acquired++, this.pool.pop() ?? [];
184
+ super(...arguments), this._fnSubCount = 0, this._objSubCount = 0;
315
185
  }
316
186
  /**
317
- * Releases an array back to the pool.
318
- * Clears the array before storing it.
187
+ * Adds subscriber.
319
188
  */
320
- release(e, t) {
321
- const s = this.stats;
322
- if (t && e === t) return;
323
- if (Object.isFrozen(e)) {
324
- s && s.rejected.frozen++;
325
- return;
326
- }
327
- if (e.length > this.maxReusableCapacity) {
328
- s && s.rejected.tooLarge++;
329
- return;
330
- }
331
- const i = this.pool;
332
- if (i.length >= this.maxPoolSize) {
333
- s && s.rejected.poolFull++;
334
- return;
189
+ subscribe(t) {
190
+ const e = typeof t == "function";
191
+ if (!e && (!t || typeof t.execute != "function"))
192
+ throw K(
193
+ new TypeError("Invalid subscriber"),
194
+ Z,
195
+ S.ATOM_SUBSCRIBER_MUST_BE_FUNCTION
196
+ );
197
+ const s = this._subscribers;
198
+ for (let o = 0, r = s.length; o < r; o++) {
199
+ const c = s[o];
200
+ if (c && (e ? c.fn === t : c.sub === t))
201
+ return m && console.warn("Duplicate subscription ignored."), () => {
202
+ };
335
203
  }
336
- e.length = 0, i.push(e), s && s.released++;
337
- }
338
- /** Returns current stats for the pool (dev mode only). */
339
- getStats() {
340
- const e = this.stats;
341
- if (!e) return null;
342
- const { acquired: t, released: s, rejected: i } = e, { frozen: o, tooLarge: r, poolFull: c } = i;
343
- return {
344
- acquired: t,
345
- released: s,
346
- rejected: {
347
- frozen: o,
348
- tooLarge: r,
349
- poolFull: c
350
- },
351
- leaked: t - s - (o + r + c),
352
- poolSize: this.pool.length
353
- };
204
+ const i = new St(
205
+ e ? t : void 0,
206
+ e ? void 0 : t
207
+ );
208
+ return s.push(i), e ? (this._fnSubCount++, this.flags |= F.HAS_FN_SUBS) : (this._objSubCount++, this.flags |= F.HAS_OBJ_SUBS), () => this._unsubscribe(i);
354
209
  }
355
- /** Resets the pool and its stats. */
356
- reset() {
357
- this.pool.length = 0;
358
- const e = this.stats;
359
- e && (e.acquired = 0, e.released = 0, e.rejected.frozen = 0, e.rejected.tooLarge = 0, e.rejected.poolFull = 0);
210
+ _unsubscribe(t) {
211
+ const e = this._subscribers, s = e.indexOf(t);
212
+ if (s === -1) return;
213
+ const i = e.pop();
214
+ s < e.length && i && (e[s] = i), t.fn ? this._fnSubCount-- : this._objSubCount--, e.length === 0 ? (this.flags &= -7, this._fnSubCount = 0, this._objSubCount = 0) : t.fn && this._fnSubCount <= 0 ? (this.flags &= -3, this._fnSubCount = 0) : !t.fn && this._objSubCount <= 0 && (this.flags &= -5, this._objSubCount = 0);
360
215
  }
361
- }
362
- const v = Object.freeze([]), X = Object.freeze([]), R = Object.freeze([]), G = new Ne(), W = new Ne(), j = new Ne();
363
- function z(n, e, t, s) {
364
- if (e != null) {
365
- if (typeof e.addDependency == "function") {
366
- e.addDependency(n);
367
- return;
368
- }
369
- if (typeof e == "function") {
370
- const i = e;
371
- t.indexOf(i) === -1 && (t.push(i), n.flags |= w.HAS_FN_SUBS);
372
- return;
373
- }
374
- if (typeof e.execute == "function") {
375
- const i = e;
376
- s.indexOf(i) === -1 && (s.push(i), n.flags |= w.HAS_OBJ_SUBS);
216
+ subscriberCount() {
217
+ return this._subscribers.length;
218
+ }
219
+ _notifySubscribers(t, e) {
220
+ if (!(this.flags & (F.HAS_FN_SUBS | F.HAS_OBJ_SUBS))) return;
221
+ const s = this._subscribers, i = s.length;
222
+ for (let o = 0; o < i; o++) {
223
+ const r = s[o];
224
+ if (r)
225
+ try {
226
+ r.fn ? r.fn(t, e) : r.sub && r.sub.execute();
227
+ } catch (c) {
228
+ this._handleNotifyError(c);
229
+ }
377
230
  }
378
231
  }
232
+ _handleNotifyError(t) {
233
+ console.error(K(t, Z, S.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED));
234
+ }
379
235
  }
380
- function ct(n, e, t, s) {
381
- const i = e.length;
382
- if (i > 0)
383
- for (let c = 0; c < i; c++) {
384
- const u = e[c];
385
- u && (u._tempUnsub = t[c]);
386
- }
387
- const o = n.length, r = W.acquire();
388
- r.length = o;
389
- for (let c = 0; c < o; c++) {
390
- const u = n[c];
391
- if (!u) continue;
392
- const h = u._tempUnsub;
393
- h ? (r[c] = h, u._tempUnsub = void 0) : (F.checkCircular(u, s), r[c] = u.subscribe(s));
394
- }
395
- if (i > 0)
396
- for (let c = 0; c < i; c++) {
397
- const u = e[c];
398
- if (u) {
399
- const h = u._tempUnsub;
400
- h && (h(), u._tempUnsub = void 0);
401
- }
402
- }
403
- return t !== X && W.release(t), r;
404
- }
405
- let le = 0;
406
- function qe() {
407
- return le = le + 1 & K || 1, le;
408
- }
409
- function ut() {
410
- return le;
411
- }
412
- let De = 0, Oe = 0, fe = !1;
413
- function ke() {
414
- return fe ? (Z && console.warn(
415
- "Warning: startFlush() called during flush - ignored to prevent infinite loop detection bypass"
416
- ), !1) : (fe = !0, De = De + 1 & K || 1, Oe = 0, !0);
417
- }
418
- function Le() {
419
- fe = !1;
420
- }
421
- function ht() {
422
- return fe ? ++Oe : 0;
236
+ let rt = 0;
237
+ const Vt = () => (rt = rt + 1 & G || 1, rt), ie = () => rt;
238
+ let bt = 0, Ct = 0, ut = !1;
239
+ function Ut() {
240
+ return ut ? (m && console.warn("startFlush() called during flush - ignored"), !1) : (ut = !0, bt = bt + 1 & G || 1, Ct = 0, !0);
423
241
  }
424
- class lt {
425
- constructor() {
426
- this._queueBuffer = [[], []], this._bufferIndex = 0, this._size = 0, this._epoch = 0, this._isProcessing = !1, this._isBatching = !1, this._batchDepth = 0, this._batchQueue = [], this._batchQueueSize = 0, this._isFlushingSync = !1, this._maxFlushIterations = q.MAX_FLUSH_ITERATIONS;
427
- }
428
- /**
429
- * Returns the current operational phase of the scheduler.
430
- */
242
+ const Rt = () => {
243
+ ut = !1;
244
+ }, oe = () => ut ? ++Ct : 0, A = {
245
+ /** Queue buffer */
246
+ _queueBuffer: [[], []],
247
+ _bufferIndex: 0,
248
+ _size: 0,
249
+ /** Epoch counter */
250
+ _epoch: 0,
251
+ /** State flags */
252
+ _isProcessing: !1,
253
+ _isBatching: !1,
254
+ _isFlushingSync: !1,
255
+ /** Batching state */
256
+ _batchDepth: 0,
257
+ _batchQueue: [],
258
+ _batchQueueSize: 0,
259
+ /** Config */
260
+ _maxFlushIterations: $.MAX_FLUSH_ITERATIONS,
431
261
  get phase() {
432
262
  return this._isProcessing || this._isFlushingSync ? 2 : this._isBatching ? 1 : 0;
433
- }
434
- /** Current number of pending jobs. */
263
+ },
435
264
  get queueSize() {
436
265
  return this._size;
437
- }
438
- /**
439
- * Returns whether the scheduler is currently batching updates.
440
- */
266
+ },
441
267
  get isBatching() {
442
268
  return this._isBatching;
443
- }
269
+ },
444
270
  /**
445
- * Schedules a task for execution.
271
+ * Schedules job.
446
272
  */
447
- schedule(e) {
448
- if (Z && typeof e != "function")
449
- throw new ue("Scheduler callback must be a function");
450
- const t = this._epoch;
451
- if (e._nextEpoch === t) return;
452
- if (e._nextEpoch = t, this._isBatching || this._isFlushingSync) {
453
- this._batchQueue[this._batchQueueSize++] = e;
454
- return;
273
+ schedule(n) {
274
+ if (m && typeof n != "function")
275
+ throw new it("Scheduler callback must be a function");
276
+ if (n._nextEpoch !== this._epoch) {
277
+ if (n._nextEpoch = this._epoch, this._isBatching || this._isFlushingSync) {
278
+ this._batchQueue[this._batchQueueSize++] = n;
279
+ return;
280
+ }
281
+ this._queueBuffer[this._bufferIndex][this._size++] = n, this._isProcessing || this._flush();
455
282
  }
456
- const s = this._bufferIndex, i = this._size;
457
- this._queueBuffer[s][i] = e, this._size = i + 1, this._isProcessing || this.flush();
458
- }
283
+ },
459
284
  /**
460
- * Schedules a microtask-based flush of the queue.
461
- * Coalesces multiple schedule calls into a single microtask execution.
285
+ * Triggers flush.
462
286
  */
463
- flush() {
464
- this._isProcessing || this._size === 0 || (this._isProcessing = !0, queueMicrotask(() => {
465
- try {
466
- if (this._size === 0) return;
467
- const e = ke();
468
- this._drainQueue(), e && Le();
469
- } finally {
470
- this._isProcessing = !1, this._size > 0 && !this._isBatching && this.flush();
471
- }
472
- }));
473
- }
287
+ _flush() {
288
+ this._isProcessing || this._size === 0 || (this._isProcessing = !0, queueMicrotask(this._runLoop));
289
+ },
474
290
  /**
475
- * Immediately flushes all queues synchronously.
476
- * Used at the end of a batch block or when immediate reflection is required.
291
+ * Scheduler loop.
477
292
  */
478
- flushSync() {
293
+ _runLoop: () => {
294
+ try {
295
+ if (A._size === 0) return;
296
+ const n = Ut();
297
+ A._drainQueue(), n && Rt();
298
+ } finally {
299
+ A._isProcessing = !1, A._size > 0 && !A._isBatching && A._flush();
300
+ }
301
+ },
302
+ _flushSync() {
479
303
  this._isFlushingSync = !0;
480
- const e = ke();
304
+ const n = Ut();
481
305
  try {
482
306
  this._mergeBatchQueue(), this._drainQueue();
483
307
  } finally {
484
- this._isFlushingSync = !1, e && Le();
308
+ this._isFlushingSync = !1, n && Rt();
485
309
  }
486
- }
487
- /**
488
- * Merges jobs from the batching queue into the primary queue.
489
- * Increments the epoch to ensure deduplication.
490
- */
310
+ },
491
311
  _mergeBatchQueue() {
492
- const e = this._batchQueueSize;
493
- if (e === 0) return;
494
- const t = ++this._epoch, s = this._batchQueue, i = this._queueBuffer[this._bufferIndex];
495
- let o = this._size;
496
- for (let r = 0; r < e; r++) {
497
- const c = s[r];
498
- c._nextEpoch !== t && (c._nextEpoch = t, i[o++] = c);
312
+ if (this._batchQueueSize === 0) return;
313
+ const n = ++this._epoch, t = this._batchQueue, e = this._queueBuffer[this._bufferIndex];
314
+ let s = this._size;
315
+ for (let i = 0; i < this._batchQueueSize; i++) {
316
+ const o = t[i];
317
+ o._nextEpoch !== n && (o._nextEpoch = n, e[s++] = o);
499
318
  }
500
- this._size = o, this._batchQueueSize = 0, s.length > q.BATCH_QUEUE_SHRINK_THRESHOLD && (s.length = 0);
501
- }
319
+ this._size = s, this._batchQueueSize = 0, t.length > $.BATCH_QUEUE_SHRINK_THRESHOLD && (t.length = 0);
320
+ },
502
321
  _drainQueue() {
503
- let e = 0;
504
- const t = this._maxFlushIterations;
322
+ let n = 0;
505
323
  for (; this._size > 0; ) {
506
- if (++e > t) {
324
+ if (++n > this._maxFlushIterations) {
507
325
  this._handleFlushOverflow();
508
326
  return;
509
327
  }
510
328
  this._processQueue(), this._mergeBatchQueue();
511
329
  }
512
- }
330
+ },
513
331
  _processQueue() {
514
- const e = this._bufferIndex, t = this._queueBuffer[e], s = this._size;
515
- this._bufferIndex = e ^ 1, this._size = 0, this._epoch++, this._processJobs(t, s);
516
- }
332
+ const n = this._bufferIndex, t = this._queueBuffer[n], e = this._size;
333
+ this._bufferIndex = n ^ 1, this._size = 0, this._epoch++;
334
+ for (let s = 0; s < e; s++)
335
+ try {
336
+ t[s]();
337
+ } catch (i) {
338
+ console.error(new it("Error occurred during scheduler execution", i));
339
+ }
340
+ t.length = 0;
341
+ },
517
342
  _handleFlushOverflow() {
518
343
  console.error(
519
- new ue(
344
+ new it(
520
345
  `Maximum flush iterations (${this._maxFlushIterations}) exceeded. Possible infinite loop.`
521
346
  )
522
347
  ), this._size = 0, this._queueBuffer[this._bufferIndex].length = 0, this._batchQueueSize = 0;
523
- }
524
- _processJobs(e, t) {
525
- for (let s = 0; s < t; s++)
526
- try {
527
- const i = e[s];
528
- i && i();
529
- } catch (i) {
530
- console.error(
531
- new ue("Error occurred during scheduler execution", i)
532
- );
533
- }
534
- e.length = 0;
535
- }
348
+ },
536
349
  startBatch() {
537
350
  this._batchDepth++, this._isBatching = !0;
538
- }
351
+ },
539
352
  endBatch() {
540
- const e = this._batchDepth;
541
- if (e === 0) {
542
- Z && console.warn("endBatch() called without matching startBatch(). Ignoring.");
353
+ if (this._batchDepth === 0) {
354
+ m && console.warn("endBatch() called without matching startBatch(). Ignoring.");
543
355
  return;
544
356
  }
545
- const t = e - 1;
546
- this._batchDepth = t, t === 0 && (this.flushSync(), this._isBatching = !1);
547
- }
548
- setMaxFlushIterations(e) {
549
- if (e < q.MIN_FLUSH_ITERATIONS)
550
- throw new ue(
551
- `Max flush iterations must be at least ${q.MIN_FLUSH_ITERATIONS}`
357
+ --this._batchDepth === 0 && (this._flushSync(), this._isBatching = !1);
358
+ },
359
+ setMaxFlushIterations(n) {
360
+ if (n < $.MIN_FLUSH_ITERATIONS)
361
+ throw new it(
362
+ `Max flush iterations must be at least ${$.MIN_FLUSH_ITERATIONS}`
552
363
  );
553
- this._maxFlushIterations = e;
554
- }
555
- }
556
- const oe = new lt();
557
- class at {
558
- constructor() {
559
- this.current = null;
364
+ this._maxFlushIterations = n;
560
365
  }
366
+ }, Q = {
367
+ /** Active listener. */
368
+ current: null,
561
369
  /**
562
- * Runs the provided function within the context of the given listener.
563
- * Restores the previous context after the function completes or throws.
370
+ * Executes in context.
564
371
  *
565
- * @param listener - The tracking listener to associate with the current execution.
566
- * @param fn - The function to execute.
372
+ * @param listener - The subscriber.
373
+ * @param fn - The logic to execute.
374
+ * @returns The result of `fn`.
567
375
  */
568
- run(e, t) {
569
- const s = this.current;
570
- this.current = e;
376
+ run(n, t) {
377
+ const e = this.current;
378
+ this.current = n;
571
379
  try {
572
380
  return t();
573
381
  } finally {
574
- this.current = s;
382
+ this.current = e;
575
383
  }
576
384
  }
577
- /**
578
- * Retrieves the listener currently associated with the tracking context.
579
- */
580
- getCurrent() {
581
- return this.current;
582
- }
583
- }
584
- const O = new at();
585
- function Xe(n) {
586
- if (typeof n != "function")
587
- throw new Q("Untracked callback must be a function");
588
- const e = O.current;
589
- O.current = null;
385
+ };
386
+ function zt(n) {
387
+ const t = Q.current;
388
+ if (t === null) return n();
389
+ Q.current = null;
590
390
  try {
591
391
  return n();
592
392
  } finally {
593
- O.current = e;
393
+ Q.current = t;
594
394
  }
595
395
  }
596
- class ft extends ze {
597
- constructor(e, t) {
598
- super(), this._value = e, this._pendingOldValue = void 0, this._notifyTask = void 0, this._fnSubs = [], this._objSubs = [], t && (this.flags |= L.SYNC), F.attachDebugInfo(this, "atom", this.id);
396
+ const re = R.HAS_FN_SUBS | R.HAS_OBJ_SUBS;
397
+ class ce extends Ht {
398
+ constructor(t, e) {
399
+ super(), this._pendingOldValue = void 0, this._notifyTask = void 0, this._subscribers = [], this._value = t, e && (this.flags |= R.SYNC), X.attachDebugInfo(this, "atom", this.id);
400
+ }
401
+ get value() {
402
+ const t = Q.current;
403
+ return t && $t(this, t, this._subscribers), this._value;
404
+ }
405
+ set value(t) {
406
+ const e = this._value;
407
+ if (Object.is(e, t)) return;
408
+ this._value = t, this.version = this.version + 1 & G;
409
+ const s = this.flags;
410
+ if (!((s & re) === 0 || s & R.NOTIFICATION_SCHEDULED)) {
411
+ if (this._pendingOldValue = e, this.flags = s | R.NOTIFICATION_SCHEDULED, s & R.SYNC && !A.isBatching) {
412
+ this._flushNotifications();
413
+ return;
414
+ }
415
+ this._notifyTask || (this._notifyTask = () => this._flushNotifications()), A.schedule(this._notifyTask);
416
+ }
599
417
  }
600
418
  /**
601
- * Returns the current value and registers the atom as a dependency if in a tracking context.
419
+ * Triggers subscribers.
602
420
  */
603
- get value() {
604
- const e = O.current;
605
- return e && z(this, e, this._fnSubs, this._objSubs), this._value;
421
+ _flushNotifications() {
422
+ const t = this.flags;
423
+ if (!(t & R.NOTIFICATION_SCHEDULED) || t & R.DISPOSED)
424
+ return;
425
+ const e = this._pendingOldValue;
426
+ this._pendingOldValue = void 0, this.flags &= -17, this._notifySubscribers(this._value, e);
427
+ }
428
+ peek() {
429
+ return this._value;
430
+ }
431
+ dispose() {
432
+ this.flags & R.DISPOSED || (this._subscribers.length = 0, this.flags |= R.DISPOSED, this._value = void 0, this._pendingOldValue = void 0, this._notifyTask = void 0);
606
433
  }
434
+ }
435
+ function ue(n, t = {}) {
436
+ return new ce(n, t.sync ?? !1);
437
+ }
438
+ class le {
607
439
  /**
608
- * Sets a new value and schedules notifications if the value has changed.
440
+ * @param limit - Max unique arrays to hold (default: 50). Prevents the pool itself from consuming too much memory.
441
+ * @param capacity - Max length of an array to accept (default: 256).
609
442
  */
610
- set value(e) {
611
- const t = this._value;
612
- t === e || Object.is(t, e) || (this._value = e, this.version = this.version + 1 & K, this.flags & (L.HAS_FN_SUBS | L.HAS_OBJ_SUBS) && this._scheduleNotification(t));
443
+ constructor(t = 50, e = 256) {
444
+ this.limit = t, this.capacity = e, this.pool = [], this.stats = m ? {
445
+ acquired: 0,
446
+ released: 0,
447
+ rejected: { frozen: 0, tooLarge: 0, poolFull: 0 }
448
+ } : null;
613
449
  }
614
450
  /**
615
- * Schedules or flushes notifications based on sync mode and batching state.
451
+ * Acquires array.
616
452
  */
617
- _scheduleNotification(e) {
618
- let t = this.flags;
619
- if (t & L.NOTIFICATION_SCHEDULED || (this._pendingOldValue = e, t |= L.NOTIFICATION_SCHEDULED, this.flags = t), t & L.SYNC && !oe.isBatching) {
620
- this._flushNotifications();
621
- return;
622
- }
623
- this._notifyTask || (this._notifyTask = () => this._flushNotifications());
624
- const s = this._notifyTask;
625
- oe.schedule(s);
453
+ acquire() {
454
+ return m && this.stats && this.stats.acquired++, this.pool.pop() ?? [];
626
455
  }
627
456
  /**
628
- * Flushes scheduled notifications and resets state for the next cycle.
457
+ * Releases array.
458
+ *
459
+ * @param arr - Array to release.
460
+ * @param emptyConst - Optional empty constant.
629
461
  */
630
- _flushNotifications() {
631
- const e = this.flags;
632
- if (!(e & L.NOTIFICATION_SCHEDULED) || e & L.DISPOSED)
633
- return;
634
- const t = this._pendingOldValue;
635
- this._pendingOldValue = void 0, this.flags = e & -17, this._notifySubscribers(this._value, t);
462
+ release(t, e) {
463
+ if (!(e && t === e)) {
464
+ if (t.length > this.capacity) {
465
+ m && this.stats && this.stats.rejected.tooLarge++;
466
+ return;
467
+ }
468
+ if (this.pool.length >= this.limit) {
469
+ m && this.stats && this.stats.rejected.poolFull++;
470
+ return;
471
+ }
472
+ if (Object.isFrozen(t)) {
473
+ m && this.stats && this.stats.rejected.frozen++;
474
+ return;
475
+ }
476
+ t.length = 0, this.pool.push(t), m && this.stats && this.stats.released++;
477
+ }
636
478
  }
637
479
  /**
638
- * Returns the current value without registering it as a dependency.
480
+ * Pool stats.
639
481
  */
640
- peek() {
641
- return this._value;
482
+ getStats() {
483
+ if (!m || !this.stats) return null;
484
+ const { acquired: t, released: e, rejected: s } = this.stats, i = t - e - (s.frozen + s.tooLarge + s.poolFull);
485
+ return {
486
+ acquired: t,
487
+ released: e,
488
+ rejected: { ...s },
489
+ leaked: i,
490
+ poolSize: this.pool.length
491
+ };
642
492
  }
643
493
  /**
644
- * Disposes of the atom and releases all subscribers and tasks.
494
+ * Resets pool.
645
495
  */
646
- dispose() {
647
- const e = this.flags;
648
- e & L.DISPOSED || (this._fnSubs.length = 0, this._objSubs.length = 0, this.flags = e | L.DISPOSED, this._value = void 0, this._pendingOldValue = void 0, this._notifyTask = void 0);
496
+ reset() {
497
+ this.pool.length = 0, m && this.stats && (this.stats = {
498
+ acquired: 0,
499
+ released: 0,
500
+ rejected: { frozen: 0, tooLarge: 0, poolFull: 0 }
501
+ });
649
502
  }
650
503
  }
651
- function dt(n, e = {}) {
652
- return new ft(n, e.sync ?? !1);
653
- }
654
- function se(n, e, t) {
655
- if (n instanceof TypeError)
656
- return new e(`Type error (${t}): ${n.message}`, n);
657
- if (n instanceof ReferenceError)
658
- return new e(`Reference error (${t}): ${n.message}`, n);
659
- if (n instanceof Q)
660
- return n;
661
- const s = n instanceof Error ? n.message : String(n), i = n instanceof Error ? n : null;
662
- return new e(`Unexpected error (${t}): ${s}`, i);
663
- }
664
- function Te(n) {
504
+ const tt = (n) => Object.freeze(n);
505
+ tt([]);
506
+ tt([]);
507
+ tt([]);
508
+ tt([]);
509
+ const T = tt([]);
510
+ tt([]);
511
+ const j = new le();
512
+ function yt(n) {
665
513
  return n !== null && typeof n == "object" && "value" in n && typeof n.subscribe == "function";
666
514
  }
667
- function Fe(n) {
668
- return F.enabled && n != null && typeof n == "object" && F.getDebugType(n) === "computed" ? !0 : Te(n) && typeof n.invalidate == "function";
515
+ function wt(n) {
516
+ return yt(n) && typeof n.invalidate == "function";
669
517
  }
670
- function Ge(n) {
671
- return n != null && typeof n.then == "function";
518
+ function qt(n) {
519
+ return n !== null && typeof n == "object" && typeof n.then == "function";
672
520
  }
673
- const Qe = f.RESOLVED | f.PENDING | f.REJECTED, pe = Array(Qe + 1).fill(_e.IDLE);
674
- pe[f.RESOLVED] = _e.RESOLVED;
675
- pe[f.PENDING] = _e.PENDING;
676
- pe[f.REJECTED] = _e.REJECTED;
677
- const Pe = 3, Me = Number.MAX_SAFE_INTEGER - 1;
678
- class Je extends ze {
679
- constructor(e, t = {}) {
680
- if (typeof e != "function")
681
- throw new $(C.COMPUTED_MUST_BE_FUNCTION);
682
- if (super(), this._value = void 0, this.flags = f.DIRTY | f.IDLE, this._error = null, this._promiseId = 0, this._equal = t.equal ?? Object.is, this._fn = e, this._defaultValue = "defaultValue" in t ? t.defaultValue : Ie, this._onError = t.onError ?? null, this._fnSubs = [], this._objSubs = [], this._dependencies = v, this._dependencyVersions = R, this._unsubscribes = X, this._cachedErrors = null, this._errorCacheEpoch = -1, this._asyncStartAggregateVersion = 0, this._asyncRetryCount = 0, this._trackEpoch = -1, this._trackDeps = v, this._trackVersions = R, this._trackCount = 0, F.attachDebugInfo(this, "computed", this.id), F.enabled) {
683
- const s = this;
684
- s.subscriberCount = this.subscriberCount.bind(this), s.isDirty = () => (this.flags & f.DIRTY) !== 0, s.dependencies = this._dependencies;
685
- }
686
- if (t.lazy === !1)
521
+ const Xt = h.RESOLVED | h.PENDING | h.REJECTED, at = Array(Xt + 1).fill(ht.IDLE);
522
+ at[h.RESOLVED] = ht.RESOLVED;
523
+ at[h.PENDING] = ht.PENDING;
524
+ at[h.REJECTED] = ht.REJECTED;
525
+ const xt = 3, Lt = Number.MAX_SAFE_INTEGER - 1;
526
+ class Gt extends Ht {
527
+ constructor(t, e = {}) {
528
+ if (typeof t != "function") throw new B(S.COMPUTED_MUST_BE_FUNCTION);
529
+ if (super(), this._error = null, this._promiseId = 0, this._subscribers = [], this._links = T, this._cachedErrors = null, this._errorCacheEpoch = -1, this._asyncStartAggregateVersion = 0, this._asyncRetryCount = 0, this._trackEpoch = -1, this._trackLinks = T, this._trackCount = 0, this._value = void 0, this.flags = h.DIRTY | h.IDLE, this._equal = e.equal ?? Object.is, this._fn = t, this._defaultValue = "defaultValue" in e ? e.defaultValue : pt, this._onError = e.onError ?? null, X.attachDebugInfo(this, "computed", this.id), e.lazy === !1)
687
530
  try {
688
531
  this._recompute();
689
532
  } catch {
690
533
  }
691
534
  }
535
+ _track() {
536
+ const t = Q.current;
537
+ t && $t(this, t, this._subscribers);
538
+ }
692
539
  get value() {
693
- const e = O.current;
694
- e && z(this, e, this._fnSubs, this._objSubs);
695
- let t = this.flags;
696
- if ((t & (f.RESOLVED | f.DIRTY | f.IDLE)) === f.RESOLVED)
540
+ this._track();
541
+ const t = this.flags;
542
+ if ((t & (h.RESOLVED | h.DIRTY | h.IDLE)) === h.RESOLVED)
697
543
  return this._value;
698
- if (t & f.DISPOSED)
699
- throw new $(C.COMPUTED_DISPOSED);
700
- if (t & f.RECOMPUTING) {
701
- const o = this._defaultValue;
702
- if (o !== Ie) return o;
703
- throw new $(C.COMPUTED_CIRCULAR_DEPENDENCY);
544
+ if (t & h.DISPOSED)
545
+ throw new B(S.COMPUTED_DISPOSED);
546
+ if (t & h.RECOMPUTING) {
547
+ if (this._defaultValue !== pt) return this._defaultValue;
548
+ throw new B(S.COMPUTED_CIRCULAR_DEPENDENCY);
704
549
  }
705
- if (t & (f.DIRTY | f.IDLE) && (this._recompute(), t = this.flags), t & f.RESOLVED)
550
+ if (t & (h.DIRTY | h.IDLE) && (this._recompute(), this.flags & h.RESOLVED))
706
551
  return this._value;
707
- const s = this._defaultValue, i = s !== Ie;
708
- if (t & f.PENDING) {
709
- if (i) return s;
710
- throw new $(C.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
552
+ const e = this._defaultValue, s = e !== pt;
553
+ if (this.flags & h.PENDING) {
554
+ if (s) return e;
555
+ throw new B(S.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
711
556
  }
712
- if (t & f.REJECTED) {
713
- const o = this._error;
714
- if (o?.recoverable && i) return s;
715
- throw o;
557
+ if (this.flags & h.REJECTED) {
558
+ if (this._error?.recoverable && s) return e;
559
+ throw this._error;
716
560
  }
717
561
  return this._value;
718
562
  }
@@ -720,454 +564,386 @@ class Je extends ze {
720
564
  return this._value;
721
565
  }
722
566
  get state() {
723
- const e = O.current;
724
- return e && z(this, e, this._fnSubs, this._objSubs), pe[this.flags & Qe];
567
+ return this._track(), at[this.flags & Xt];
725
568
  }
726
569
  get hasError() {
727
- const e = O.current;
728
- if (e && z(this, e, this._fnSubs, this._objSubs), this.flags & (f.REJECTED | f.HAS_ERROR)) return !0;
729
- const t = this._dependencies;
730
- for (let s = 0, i = t.length; s < i; s++)
731
- if (t[s].flags & f.HAS_ERROR) return !0;
570
+ if (this._track(), this.flags & (h.REJECTED | h.HAS_ERROR)) return !0;
571
+ const t = this._links;
572
+ for (let e = 0, s = t.length; e < s; e++) {
573
+ const i = t[e]?.node;
574
+ if (i && i.flags & h.HAS_ERROR) return !0;
575
+ }
732
576
  return !1;
733
577
  }
578
+ // ... (isValid, errors, lastError getters remain structurally similar, omitted for brevity if mostly unchanged) ...
734
579
  get isValid() {
735
580
  return !this.hasError;
736
581
  }
737
582
  get errors() {
738
- const e = O.current;
739
- if (e && z(this, e, this._fnSubs, this._objSubs), !this.hasError) return et;
740
- const t = ut();
741
- if (this._errorCacheEpoch === t && this._cachedErrors !== null)
742
- return this._cachedErrors;
743
- const s = /* @__PURE__ */ new Set(), i = this._error;
744
- i && s.add(i);
745
- const o = this._dependencies;
746
- for (let c = 0, u = o.length; c < u; c++) {
747
- const h = o[c];
748
- if (h.flags & f.HAS_ERROR) {
749
- const p = h.errors;
750
- if (p)
751
- for (let a = 0, _ = p.length; a < _; a++) {
752
- const d = p[a];
753
- d && s.add(d);
583
+ if (this._track(), !this.hasError) return Kt;
584
+ const t = ie();
585
+ if (this._errorCacheEpoch === t && this._cachedErrors) return this._cachedErrors;
586
+ const e = /* @__PURE__ */ new Set();
587
+ this._error && e.add(this._error);
588
+ const s = this._links;
589
+ for (let o = 0, r = s.length; o < r; o++) {
590
+ const c = s[o].node;
591
+ if (c.flags & h.HAS_ERROR) {
592
+ const l = c;
593
+ if (l.errors) {
594
+ const a = l.errors;
595
+ for (let d = 0; d < a.length; d++) {
596
+ const N = a[d];
597
+ N && e.add(N);
754
598
  }
599
+ }
755
600
  }
756
601
  }
757
- const r = Object.freeze(Array.from(s));
758
- return this._errorCacheEpoch = t, this._cachedErrors = r, r;
602
+ const i = Object.freeze(Array.from(e));
603
+ return this._errorCacheEpoch = t, this._cachedErrors = i, i;
759
604
  }
760
605
  get lastError() {
761
- const e = O.current;
762
- return e && z(this, e, this._fnSubs, this._objSubs), this._error;
606
+ return this._track(), this._error;
763
607
  }
764
608
  get isPending() {
765
- const e = O.current;
766
- return e && z(this, e, this._fnSubs, this._objSubs), (this.flags & f.PENDING) !== 0;
609
+ return this._track(), (this.flags & h.PENDING) !== 0;
767
610
  }
768
611
  get isResolved() {
769
- const e = O.current;
770
- return e && z(this, e, this._fnSubs, this._objSubs), (this.flags & f.RESOLVED) !== 0;
612
+ return this._track(), (this.flags & h.RESOLVED) !== 0;
771
613
  }
772
614
  invalidate() {
773
- this._markDirty();
774
- const e = this._dependencyVersions;
775
- e !== R && (j.release(e), this._dependencyVersions = R), this._errorCacheEpoch = -1, this._cachedErrors = null;
615
+ this._markDirty(), this._errorCacheEpoch = -1, this._cachedErrors = null;
776
616
  }
777
617
  dispose() {
778
- if (this.flags & f.DISPOSED) return;
779
- const e = this._unsubscribes;
780
- if (e !== X) {
781
- for (let i = 0, o = e.length; i < o; i++) {
782
- const r = e[i];
783
- r && r();
784
- }
785
- W.release(e), this._unsubscribes = X;
618
+ if (this.flags & h.DISPOSED) return;
619
+ const t = this._links;
620
+ if (t !== T) {
621
+ for (let e = 0, s = t.length; e < s; e++)
622
+ t[e].unsub?.();
623
+ j.release(t), this._links = T;
624
+ }
625
+ this._subscribers.length = 0, this.flags = h.DISPOSED | h.DIRTY | h.IDLE, this._error = null, this._value = void 0, this._promiseId = (this._promiseId + 1) % Lt, this._cachedErrors = null, this._errorCacheEpoch = -1;
626
+ }
627
+ addDependency(t) {
628
+ if (t._lastSeenEpoch !== this._trackEpoch) {
629
+ if (t._lastSeenEpoch = this._trackEpoch, this._trackCount < this._trackLinks.length) {
630
+ const e = this._trackLinks[this._trackCount];
631
+ e.node = t, e.version = t.version;
632
+ } else
633
+ this._trackLinks.push(new mt(t, t.version));
634
+ this._trackCount++;
786
635
  }
787
- const t = this._dependencies;
788
- t !== v && (G.release(t), this._dependencies = v);
789
- const s = this._dependencyVersions;
790
- s !== R && (j.release(s), this._dependencyVersions = R), this._fnSubs.length = 0, this._objSubs.length = 0, this.flags = f.DISPOSED | f.DIRTY | f.IDLE, this._error = null, this._value = void 0, this._promiseId = (this._promiseId + 1) % Me, this._cachedErrors = null, this._errorCacheEpoch = -1;
791
- }
792
- addDependency(e) {
793
- if (e._lastSeenEpoch === this._trackEpoch) return;
794
- e._lastSeenEpoch = this._trackEpoch;
795
- const t = this._trackCount, s = this._trackDeps, i = this._trackVersions;
796
- t < s.length ? (s[t] = e, i[t] = e.version) : (s.push(e), i.push(e.version)), this._trackCount = t + 1;
797
636
  }
798
- _commitDeps(e) {
799
- const t = this._trackDeps, s = this._trackVersions, i = this._trackCount;
800
- t.length = i, s.length = i, this._unsubscribes = ct(t, e, this._unsubscribes, this), this._dependencies = t, this._dependencyVersions = s;
637
+ _commitDeps(t) {
638
+ this._trackLinks.length = this._trackCount, se(this._trackLinks, t, this), this._links = this._trackLinks;
801
639
  }
802
640
  _recompute() {
803
- if (this.flags & f.RECOMPUTING) return;
804
- this.flags |= f.RECOMPUTING;
805
- const e = this._dependencies, t = this._dependencyVersions;
806
- this._trackEpoch = qe(), this._trackDeps = G.acquire(), this._trackVersions = j.acquire(), this._trackCount = 0;
807
- let s = !1;
641
+ if (this.flags & h.RECOMPUTING) return;
642
+ this.flags |= h.RECOMPUTING;
643
+ const t = this._links;
644
+ this._trackEpoch = Vt(), this._trackLinks = j.acquire(), this._trackCount = 0;
645
+ let e = !1;
808
646
  try {
809
- const i = O.run(this, this._fn);
810
- this._commitDeps(e), s = !0, Ge(i) ? this._handleAsyncComputation(i) : this._finalizeResolution(i);
811
- } catch (i) {
812
- let o = i;
813
- if (!s)
647
+ const s = Q.run(this, this._fn);
648
+ this._commitDeps(t), e = !0, qt(s) ? this._handleAsyncComputation(s) : this._finalizeResolution(s);
649
+ } catch (s) {
650
+ if (!e)
814
651
  try {
815
- this._commitDeps(e), s = !0;
816
- } catch (r) {
817
- o = r;
652
+ this._commitDeps(t), e = !0;
653
+ } catch {
818
654
  }
819
- this._handleComputationError(o);
655
+ this._handleError(s, S.COMPUTED_COMPUTATION_FAILED, !0);
820
656
  } finally {
821
- s ? (e !== v && G.release(e), t !== R && j.release(t)) : (G.release(this._trackDeps), j.release(this._trackVersions)), this._trackEpoch = -1, this._trackDeps = v, this._trackVersions = R, this._trackCount = 0, this.flags &= -257;
657
+ e && t !== T ? j.release(t) : e || j.release(this._trackLinks), this._trackEpoch = -1, this._trackLinks = T, this._trackCount = 0, this.flags &= -257;
822
658
  }
823
659
  }
824
- _handleAsyncComputation(e) {
825
- this.flags = (this.flags | f.PENDING) & -217, this._notifySubscribers(void 0, void 0), this._asyncStartAggregateVersion = this._captureVersionSnapshot(), this._asyncRetryCount = 0, this._promiseId = (this._promiseId + 1) % Me;
826
- const t = this._promiseId;
827
- e.then((s) => {
828
- if (t === this._promiseId) {
829
- if (this._captureVersionSnapshot() !== this._asyncStartAggregateVersion) {
830
- if (this._asyncRetryCount < Pe) {
831
- this._asyncRetryCount++, this._markDirty();
832
- return;
833
- }
834
- this._handleAsyncRejection(
835
- new $(`Async drift threshold exceeded after ${Pe} retries.`)
836
- );
837
- return;
660
+ _handleAsyncComputation(t) {
661
+ this.flags = (this.flags | h.PENDING) & -217, this._notifySubscribers(void 0, void 0), this._asyncStartAggregateVersion = this._captureVersionSnapshot(), this._asyncRetryCount = 0, this._promiseId = (this._promiseId + 1) % Lt;
662
+ const e = this._promiseId;
663
+ t.then(
664
+ (s) => {
665
+ if (e === this._promiseId) {
666
+ if (this._captureVersionSnapshot() !== this._asyncStartAggregateVersion)
667
+ return this._asyncRetryCount++ < xt ? this._markDirty() : this._handleError(
668
+ new B(`Async drift threshold exceeded after ${xt} retries.`),
669
+ S.COMPUTED_ASYNC_COMPUTATION_FAILED
670
+ );
671
+ this._finalizeResolution(s), this._notifySubscribers(s, void 0);
838
672
  }
839
- this._finalizeResolution(s), this._notifySubscribers(s, void 0);
840
- }
841
- }).catch((s) => {
842
- t === this._promiseId && this._handleAsyncRejection(s);
843
- });
673
+ },
674
+ (s) => e === this._promiseId && this._handleError(s, S.COMPUTED_ASYNC_COMPUTATION_FAILED)
675
+ );
844
676
  }
845
677
  _captureVersionSnapshot() {
846
- let e = 0;
847
- const t = this._dependencies;
848
- for (let s = 0, i = t.length; s < i; s++) {
849
- const o = t[s];
850
- if (o) {
851
- const r = o.version;
852
- e = ((e << 5) - e | 0) + r & K;
853
- }
854
- }
855
- return e;
856
- }
857
- _handleAsyncRejection(e) {
858
- const t = se(e, $, C.COMPUTED_ASYNC_COMPUTATION_FAILED);
859
- this.flags & f.REJECTED || (this.version = this.version + 1 & K), this._error = t, this.flags = this.flags & -121 | (f.REJECTED | f.HAS_ERROR);
860
- const s = this._onError;
861
- if (s)
678
+ let t = 0;
679
+ const e = this._links;
680
+ for (let s = 0, i = e.length; s < i; s++)
681
+ t = ((t << 5) - t | 0) + e[s].node.version & G;
682
+ return t;
683
+ }
684
+ _handleError(t, e, s = !1) {
685
+ const i = K(t, B, e);
686
+ if (!s && !(this.flags & h.REJECTED) && (this.version = this.version + 1 & G), this._error = i, this.flags = this.flags & -121 | (h.REJECTED | h.HAS_ERROR), this._onError)
862
687
  try {
863
- s(t);
864
- } catch (i) {
865
- console.error(C.CALLBACK_ERROR_IN_ERROR_HANDLER, i);
688
+ this._onError(i);
689
+ } catch (o) {
690
+ console.error(S.CALLBACK_ERROR_IN_ERROR_HANDLER, o);
866
691
  }
692
+ if (s) throw i;
867
693
  this._notifySubscribers(void 0, void 0);
868
694
  }
869
- _finalizeResolution(e) {
870
- (!(this.flags & f.RESOLVED) || !this._equal(this._value, e)) && (this.version = this.version + 1 & K), this._value = e, this._error = null, this.flags = (this.flags | f.RESOLVED) & -697, this._cachedErrors = null, this._errorCacheEpoch = -1;
871
- }
872
- _handleComputationError(e) {
873
- const t = se(e, $, C.COMPUTED_COMPUTATION_FAILED);
874
- this._error = t, this.flags = this.flags & -121 | (f.REJECTED | f.HAS_ERROR);
875
- const s = this._onError;
876
- if (s)
877
- try {
878
- s(t);
879
- } catch (i) {
880
- console.error(C.CALLBACK_ERROR_IN_ERROR_HANDLER, i);
881
- }
882
- throw t;
695
+ _finalizeResolution(t) {
696
+ (!(this.flags & h.RESOLVED) || !this._equal(this._value, t)) && (this.version = this.version + 1 & G), this._value = t, this._error = null, this.flags = (this.flags | h.RESOLVED) & -697, this._cachedErrors = null, this._errorCacheEpoch = -1;
883
697
  }
884
698
  execute() {
885
699
  this._markDirty();
886
700
  }
887
701
  /** @internal */
888
702
  _markDirty() {
889
- const e = this.flags;
890
- e & (f.RECOMPUTING | f.DIRTY) || (this.flags = e | f.DIRTY, this._notifySubscribers(void 0, void 0));
703
+ this.flags & (h.RECOMPUTING | h.DIRTY) || (this.flags |= h.DIRTY, this._notifySubscribers(void 0, void 0));
891
704
  }
892
705
  }
893
- Object.freeze(Je.prototype);
894
- function _t(n, e = {}) {
895
- return new Je(n, e);
706
+ Object.freeze(Gt.prototype);
707
+ function he(n, t = {}) {
708
+ return new Gt(n, t);
896
709
  }
897
- class pt extends He {
898
- constructor(e, t = {}) {
899
- super(), this._cleanup = null, this._dependencies = v, this._dependencyVersions = R, this._unsubscribes = X, this._nextDeps = null, this._nextVersions = null, this._nextUnsubs = null, this._executeTask = void 0, this._onError = t.onError ?? null, this._currentEpoch = -1, this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._fn = e, this._sync = t.sync ?? !1, this._maxExecutions = t.maxExecutionsPerSecond ?? q.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = t.maxExecutionsPerFlush ?? q.MAX_EXECUTIONS_PER_EFFECT, this._trackModifications = t.trackModifications ?? !1, this._executionCount = 0, this._historyPtr = 0;
900
- const s = Number.isFinite(this._maxExecutions), i = s ? Math.min(this._maxExecutions + 1, q.MAX_EXECUTIONS_PER_SECOND + 1) : 0;
901
- this._historyCapacity = i, this._history = Z && s && i > 0 ? new Array(i).fill(0) : null, this._execId = 0, F.attachDebugInfo(this, "effect", this.id);
710
+ class ae extends jt {
711
+ constructor(t, e = {}) {
712
+ super(), this._cleanup = null, this._links = T, this._nextLinks = null, this._currentEpoch = -1, this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._executionCount = 0, this._historyPtr = 0, this._execId = 0, this._fn = t, this._onError = e.onError ?? null, this._sync = e.sync ?? !1, this._maxExecutions = e.maxExecutionsPerSecond ?? $.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = e.maxExecutionsPerFlush ?? $.MAX_EXECUTIONS_PER_EFFECT, this._trackModifications = e.trackModifications ?? !1;
713
+ const s = Number.isFinite(this._maxExecutions), i = s ? Math.min(this._maxExecutions + 1, $.MAX_EXECUTIONS_PER_SECOND + 1) : 0;
714
+ this._historyCapacity = i, this._history = m && s && i > 0 ? new Array(i).fill(0) : null, X.attachDebugInfo(this, "effect", this.id);
902
715
  }
903
716
  run() {
904
- if (this.flags & U.DISPOSED)
905
- throw new Y(C.EFFECT_DISPOSED);
717
+ if (this.flags & k.DISPOSED)
718
+ throw new q(S.EFFECT_DISPOSED);
906
719
  this.execute(!0);
907
720
  }
908
721
  dispose() {
909
- const e = this.flags;
910
- if (e & U.DISPOSED) return;
911
- if (this.flags = e | U.DISPOSED, this._cleanup) {
912
- try {
913
- this._cleanup();
914
- } catch (o) {
915
- this._handleExecutionError(o, C.EFFECT_CLEANUP_FAILED);
916
- }
917
- this._cleanup = null;
918
- }
919
- const t = this._unsubscribes;
920
- if (t !== X) {
921
- for (let o = 0, r = t.length; o < r; o++) {
922
- const c = t[o];
923
- c && c();
924
- }
925
- W.release(t), this._unsubscribes = X;
926
- }
927
- const s = this._dependencies;
928
- s !== v && (G.release(s), this._dependencies = v);
929
- const i = this._dependencyVersions;
930
- i !== R && (j.release(i), this._dependencyVersions = R), this._executeTask = void 0;
931
- }
932
- addDependency(e) {
933
- if (!(this.flags & U.EXECUTING)) return;
934
- const t = this._currentEpoch;
935
- if (e._lastSeenEpoch === t) return;
936
- e._lastSeenEpoch = t;
937
- const s = this._nextDeps, i = this._nextVersions, o = this._nextUnsubs;
938
- s.push(e), i.push(e.version);
939
- const r = e._tempUnsub;
940
- if (r) {
941
- o.push(r), e._tempUnsub = void 0;
722
+ this.flags & k.DISPOSED || (this.flags |= k.DISPOSED, this._execCleanup(), this._releaseLinks(this._links), this._links = T, this._executeTask = void 0);
723
+ }
724
+ addDependency(t) {
725
+ if (!(this.flags & k.EXECUTING) || t._lastSeenEpoch === this._currentEpoch) return;
726
+ t._lastSeenEpoch = this._currentEpoch;
727
+ const e = this._nextLinks;
728
+ if (t._tempUnsub) {
729
+ e.push(new mt(t, t.version, t._tempUnsub)), t._tempUnsub = void 0;
942
730
  return;
943
731
  }
944
732
  try {
945
- const c = this._sync, u = this._trackModifications, h = e.subscribe(() => {
946
- if (u && this.flags & U.EXECUTING && (e._modifiedAtEpoch = this._currentEpoch), c) {
947
- this.execute();
948
- return;
949
- }
950
- this._executeTask || (this._executeTask = () => this.execute());
951
- const p = this._executeTask;
952
- oe.schedule(p);
953
- });
954
- o.push(h);
955
- } catch (c) {
956
- console.error(se(c, Y, C.EFFECT_EXECUTION_FAILED)), o.push(() => {
733
+ const s = t.subscribe(() => {
734
+ if (this._trackModifications && this.flags & k.EXECUTING && (t._modifiedAtEpoch = this._currentEpoch), this._sync) return this.execute();
735
+ this._executeTask || (this._executeTask = () => this.execute()), A.schedule(this._executeTask);
957
736
  });
737
+ e.push(new mt(t, t.version, s));
738
+ } catch (s) {
739
+ console.error(K(s, q, S.EFFECT_EXECUTION_FAILED));
958
740
  }
959
741
  }
960
- execute(e = !1) {
961
- if (this.flags & (U.DISPOSED | U.EXECUTING)) return;
962
- if (!e) {
963
- const a = this._dependencies, _ = a.length;
964
- if (_ > 0) {
965
- const d = this._dependencyVersions;
966
- let S = !1;
967
- for (let T = 0; T < _; T++) {
968
- const I = a[T];
969
- if (I.version !== d[T]) {
970
- S = !0;
971
- break;
972
- }
973
- if ("value" in I)
742
+ /**
743
+ * Executes effect with tracking.
744
+ */
745
+ execute(t = !1) {
746
+ if (this.flags & (k.DISPOSED | k.EXECUTING) || !t && this._links.length > 0 && !this._isDirty()) return;
747
+ this._checkInfiniteLoops(), this.flags |= k.EXECUTING, this._execCleanup();
748
+ const e = this._links;
749
+ if (e !== T)
750
+ for (let o = 0, r = e.length; o < r; o++) {
751
+ const c = e[o];
752
+ c && (c.node._tempUnsub = c.unsub);
753
+ }
754
+ const s = j.acquire();
755
+ this._nextLinks = s, this._currentEpoch = Vt();
756
+ let i = !1;
757
+ try {
758
+ const o = Q.run(this, this._fn);
759
+ this._links = s, i = !0, this._checkLoopWarnings(), qt(o) ? this._handleAsyncResult(o) : this._cleanup = typeof o == "function" ? o : null;
760
+ } catch (o) {
761
+ i = !0, this._handleExecutionError(o), this._cleanup = null;
762
+ } finally {
763
+ this._finalizeDependencies(i, e, s), this.flags &= -9;
764
+ }
765
+ }
766
+ _handleAsyncResult(t) {
767
+ const e = ++this._execId;
768
+ t.then(
769
+ (s) => {
770
+ if (e !== this._execId || this.flags & k.DISPOSED) {
771
+ if (typeof s == "function")
974
772
  try {
975
- if (Xe(() => I.value), I.version !== d[T]) {
976
- S = !0;
977
- break;
978
- }
979
- } catch {
980
- S = !0;
981
- break;
773
+ s();
774
+ } catch (i) {
775
+ this._handleExecutionError(i, S.EFFECT_CLEANUP_FAILED);
982
776
  }
777
+ return;
778
+ }
779
+ typeof s == "function" && (this._cleanup = s);
780
+ },
781
+ (s) => e === this._execId && this._handleExecutionError(s)
782
+ );
783
+ }
784
+ _finalizeDependencies(t, e, s) {
785
+ if (this._nextLinks = null, t) {
786
+ if (e !== T) {
787
+ for (let i = 0, o = e.length; i < o; i++) {
788
+ const r = e[i], c = r?.node._tempUnsub;
789
+ c && (c(), r && (r.node._tempUnsub = void 0));
983
790
  }
984
- if (!S) return;
791
+ j.release(e);
985
792
  }
793
+ } else if (this._releaseLinks(s), j.release(s), e !== T)
794
+ for (let i = 0, o = e.length; i < o; i++)
795
+ e[i] && (e[i].node._tempUnsub = void 0);
796
+ }
797
+ _releaseLinks(t) {
798
+ if (t !== T) {
799
+ for (let e = 0, s = t.length; e < s; e++)
800
+ t[e]?.unsub?.();
801
+ j.release(t);
986
802
  }
987
- const t = De;
988
- this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), ht() > q.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++;
989
- const s = this._history;
990
- if (s) {
991
- const a = Date.now(), _ = this._historyPtr;
992
- s[_] = a;
993
- const d = (_ + 1) % this._historyCapacity;
994
- this._historyPtr = d;
995
- const S = s[d] || 0;
996
- if (S > 0 && a - S < Ze.ONE_SECOND_MS) {
997
- const T = new Y(
998
- "Effect executed too frequently within 1 second. Suspected infinite loop."
999
- );
1000
- if (this.dispose(), this._handleExecutionError(T), Z) throw T;
1001
- return;
803
+ }
804
+ _isDirty() {
805
+ const t = this._links;
806
+ for (let e = 0, s = t.length; e < s; e++) {
807
+ const i = t[e], o = i.node;
808
+ if (o.version !== i.version) return !0;
809
+ if ("value" in o) {
810
+ try {
811
+ zt(() => o.value);
812
+ } catch {
813
+ return !0;
814
+ }
815
+ if (o.version !== i.version) return !0;
1002
816
  }
1003
817
  }
1004
- if (this.flags |= U.EXECUTING, this._cleanup) {
818
+ return !1;
819
+ }
820
+ _execCleanup() {
821
+ if (this._cleanup) {
1005
822
  try {
1006
823
  this._cleanup();
1007
- } catch (a) {
1008
- this._handleExecutionError(a, C.EFFECT_CLEANUP_FAILED);
824
+ } catch (t) {
825
+ this._handleExecutionError(t, S.EFFECT_CLEANUP_FAILED);
1009
826
  }
1010
827
  this._cleanup = null;
1011
828
  }
1012
- const i = this._dependencies, o = this._dependencyVersions, r = this._unsubscribes;
1013
- if (i !== v)
1014
- for (let a = 0, _ = i.length; a < _; a++) {
1015
- const d = i[a];
1016
- d && (d._tempUnsub = r[a]);
1017
- }
1018
- const c = G.acquire(), u = j.acquire(), h = W.acquire();
1019
- this._nextDeps = c, this._nextVersions = u, this._nextUnsubs = h, this._currentEpoch = qe();
1020
- let p = !1;
1021
- try {
1022
- const a = O.run(this, this._fn);
1023
- this._dependencies = c, this._dependencyVersions = u, this._unsubscribes = h, p = !0, this._checkLoopWarnings();
1024
- const _ = ++this._execId;
1025
- Ge(a) ? a.then((d) => {
1026
- if (_ !== this._execId || this.flags & U.DISPOSED) {
1027
- if (typeof d == "function")
1028
- try {
1029
- d();
1030
- } catch (S) {
1031
- this._handleExecutionError(S, C.EFFECT_CLEANUP_FAILED);
1032
- }
1033
- return;
1034
- }
1035
- typeof d == "function" && (this._cleanup = d);
1036
- }).catch((d) => {
1037
- _ === this._execId && this._handleExecutionError(d);
1038
- }) : this._cleanup = typeof a == "function" ? a : null;
1039
- } catch (a) {
1040
- p = !0, this._handleExecutionError(a), this._cleanup = null;
1041
- } finally {
1042
- if (this._nextDeps = null, this._nextVersions = null, this._nextUnsubs = null, p) {
1043
- if (i !== v) {
1044
- for (let a = 0, _ = i.length; a < _; a++) {
1045
- const d = i[a], S = d ? d._tempUnsub : void 0;
1046
- S && (S(), d && (d._tempUnsub = void 0));
1047
- }
1048
- G.release(i);
1049
- }
1050
- o !== R && j.release(o), r !== X && W.release(r);
1051
- } else {
1052
- G.release(c), j.release(u);
1053
- for (let a = 0, _ = h.length; a < _; a++) {
1054
- const d = h[a];
1055
- d && d();
1056
- }
1057
- if (W.release(h), i !== v)
1058
- for (let a = 0, _ = i.length; a < _; a++) {
1059
- const d = i[a];
1060
- d && (d._tempUnsub = void 0);
1061
- }
829
+ }
830
+ _checkInfiniteLoops() {
831
+ const t = bt;
832
+ if (this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), oe() > $.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++, this._history) {
833
+ const e = Date.now();
834
+ this._history[this._historyPtr] = e, this._historyPtr = (this._historyPtr + 1) % this._historyCapacity;
835
+ const s = this._history[this._historyPtr] || 0;
836
+ if (s > 0 && e - s < Wt.ONE_SECOND_MS) {
837
+ const i = new q(
838
+ "Effect executed too frequently within 1 second. Suspected infinite loop."
839
+ );
840
+ if (this.dispose(), this._handleExecutionError(i), m) throw i;
1062
841
  }
1063
- this.flags &= -9;
1064
842
  }
1065
843
  }
1066
844
  get isDisposed() {
1067
- return (this.flags & U.DISPOSED) !== 0;
845
+ return (this.flags & k.DISPOSED) !== 0;
1068
846
  }
1069
847
  get executionCount() {
1070
848
  return this._executionCount;
1071
849
  }
1072
850
  get isExecuting() {
1073
- return (this.flags & U.EXECUTING) !== 0;
851
+ return (this.flags & k.EXECUTING) !== 0;
1074
852
  }
1075
- _throwInfiniteLoopError(e) {
1076
- const t = new Y(
1077
- `Infinite loop detected (${e}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${Oe}`
853
+ _throwInfiniteLoopError(t) {
854
+ const e = new q(
855
+ `Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${Ct}`
1078
856
  );
1079
- throw this.dispose(), console.error(t), t;
857
+ throw this.dispose(), console.error(e), e;
1080
858
  }
1081
- _handleExecutionError(e, t = C.EFFECT_EXECUTION_FAILED) {
1082
- const s = se(e, Y, t);
1083
- console.error(s);
1084
- const i = this._onError;
1085
- if (i)
859
+ _handleExecutionError(t, e = S.EFFECT_EXECUTION_FAILED) {
860
+ const s = K(t, q, e);
861
+ if (console.error(s), this._onError)
1086
862
  try {
1087
- i(s);
1088
- } catch (o) {
1089
- console.error(se(o, Y, C.CALLBACK_ERROR_IN_ERROR_HANDLER));
863
+ this._onError(s);
864
+ } catch (i) {
865
+ console.error(K(i, q, S.CALLBACK_ERROR_IN_ERROR_HANDLER));
1090
866
  }
1091
867
  }
1092
868
  _checkLoopWarnings() {
1093
- if (this._trackModifications && F.enabled) {
1094
- const e = this._dependencies, t = this._currentEpoch;
869
+ if (this._trackModifications && X.enabled) {
870
+ const t = this._currentEpoch, e = this._links;
1095
871
  for (let s = 0, i = e.length; s < i; s++) {
1096
- const o = e[s];
1097
- o && o._modifiedAtEpoch === t && F.warn(
872
+ const o = e[s].node;
873
+ o._modifiedAtEpoch === t && X.warn(
1098
874
  !0,
1099
- `Effect is reading a dependency (${F.getDebugName(o) || "unknown"}) that it just modified. Infinite loop may occur`
875
+ `Effect is reading a dependency (${X.getDebugName(o) || "unknown"}) that it just modified. Infinite loop may occur`
1100
876
  );
1101
877
  }
1102
878
  }
1103
879
  }
1104
880
  }
1105
- function ee(n, e = {}) {
881
+ function Y(n, t = {}) {
1106
882
  if (typeof n != "function")
1107
- throw new Y(C.EFFECT_MUST_BE_FUNCTION);
1108
- const t = new pt(n, e);
1109
- return t.execute(), t;
883
+ throw new q(S.EFFECT_MUST_BE_FUNCTION);
884
+ const e = new ae(n, t);
885
+ return e.execute(), e;
1110
886
  }
1111
- function Ae(n) {
887
+ function It(n) {
1112
888
  if (typeof n != "function")
1113
- throw new Q("Batch callback must be a function");
1114
- oe.startBatch();
889
+ throw new TypeError("Batch callback must be a function");
890
+ A.startBatch();
1115
891
  try {
1116
892
  return n();
1117
893
  } finally {
1118
- oe.endBatch();
894
+ A.endBatch();
1119
895
  }
1120
896
  }
1121
- function Et(n) {
897
+ function fe(n) {
1122
898
  return n !== null && typeof n == "object" && "value" in n && "subscribe" in n;
1123
899
  }
1124
- function Ee(n) {
900
+ function ft(n) {
1125
901
  if (!n) return "unknown";
1126
- const e = "jquery" in n ? n[0] : n;
1127
- if (!e) return "unknown";
1128
- const t = e.id;
1129
- if (t && typeof t == "string") return `#${t}`;
1130
- const s = e.tagName.toLowerCase(), i = e.classList;
902
+ const t = "jquery" in n ? n[0] : n;
903
+ if (!t) return "unknown";
904
+ const e = t.id;
905
+ if (e && typeof e == "string") return `#${e}`;
906
+ const s = t.tagName.toLowerCase(), i = t.classList;
1131
907
  if (i && i.length > 0) {
1132
908
  let o = s;
1133
909
  for (let r = 0, c = i.length; r < c; r++) {
1134
- const u = i[r];
1135
- u && (o += `.${u}`);
910
+ const l = i[r];
911
+ l && (o += `.${l}`);
1136
912
  }
1137
913
  return o;
1138
914
  }
1139
915
  return s;
1140
916
  }
1141
- function gt(n) {
1142
- const e = n.length;
1143
- if (e === 0) return new Int32Array(0);
1144
- const t = new Int32Array(e), s = new Int32Array(e);
917
+ function _e(n) {
918
+ const t = n.length;
919
+ if (t === 0) return new Int32Array(0);
920
+ const e = new Int32Array(t), s = new Int32Array(t);
1145
921
  let i = 0;
1146
- for (let r = 0; r < e; r++) {
922
+ for (let r = 0; r < t; r++) {
1147
923
  const c = n[r];
1148
924
  if (c === void 0 || c === -1) continue;
1149
- const u = i > 0 ? s[i - 1] : void 0;
1150
- if (i === 0 || u !== void 0 && (n[u] ?? -1) < c) {
1151
- t[r] = u ?? -1, s[i++] = r;
925
+ const l = i > 0 ? s[i - 1] : void 0;
926
+ if (i === 0 || l !== void 0 && (n[l] ?? -1) < c) {
927
+ e[r] = l ?? -1, s[i++] = r;
1152
928
  continue;
1153
929
  }
1154
- let h = 0, p = i - 1;
1155
- for (; h < p; ) {
1156
- const _ = h + p >>> 1, d = s[_];
1157
- d !== void 0 && (n[d] ?? -1) < c ? h = _ + 1 : p = _;
930
+ let a = 0, d = i - 1;
931
+ for (; a < d; ) {
932
+ const C = a + d >>> 1, v = s[C];
933
+ v !== void 0 && (n[v] ?? -1) < c ? a = C + 1 : d = C;
1158
934
  }
1159
- const a = s[h];
1160
- a !== void 0 && c < (n[a] ?? Number.MAX_SAFE_INTEGER) && (h > 0 && (t[r] = s[h - 1] ?? -1), s[h] = r);
935
+ const N = s[a];
936
+ N !== void 0 && c < (n[N] ?? Number.MAX_SAFE_INTEGER) && (a > 0 && (e[r] = s[a - 1] ?? -1), s[a] = r);
1161
937
  }
1162
938
  const o = new Int32Array(i);
1163
939
  if (i > 0) {
1164
940
  let r = s[i - 1];
1165
941
  for (let c = i - 1; c >= 0 && r !== void 0 && r !== -1; c--)
1166
- o[c] = r, r = t[r];
942
+ o[c] = r, r = e[r];
1167
943
  }
1168
944
  return o;
1169
945
  }
1170
- function mt() {
946
+ function de() {
1171
947
  if (typeof window < "u") {
1172
948
  const n = window.__ATOM_DEBUG__;
1173
949
  if (typeof n == "boolean") return n;
@@ -1178,401 +954,401 @@ function mt() {
1178
954
  }
1179
955
  return !1;
1180
956
  }
1181
- let J = mt();
1182
- const g = {
957
+ let z = de();
958
+ const _ = {
1183
959
  get enabled() {
1184
- return J;
960
+ return z;
1185
961
  },
1186
962
  set enabled(n) {
1187
- J = n;
963
+ z = n;
1188
964
  },
1189
- log(n, ...e) {
1190
- J && console.log(`[atom-effect-jquery] ${n}:`, ...e);
965
+ log(n, ...t) {
966
+ z && console.log(`[atom-effect-jquery] ${n}:`, ...t);
1191
967
  },
1192
- atomChanged(n, e, t) {
1193
- J && console.log(
968
+ atomChanged(n, t, e) {
969
+ z && console.log(
1194
970
  `[atom-effect-jquery] Atom "${n ?? "anonymous"}" changed:`,
1195
- e,
971
+ t,
1196
972
  "→",
1197
- t
973
+ e
1198
974
  );
1199
975
  },
1200
976
  /**
1201
977
  * Logs DOM updates and triggers visual highlight.
1202
978
  */
1203
- domUpdated(n, e, t) {
1204
- J && (console.log(`[atom-effect-jquery] DOM updated: ${Ee(n)}.${e} =`, t), bt(n));
979
+ domUpdated(n, t, e) {
980
+ z && (console.log(`[atom-effect-jquery] DOM updated: ${ft(n)}.${t} =`, e), Ee(n));
1205
981
  },
1206
982
  cleanup(n) {
1207
- J && console.log(`[atom-effect-jquery] Cleanup: ${n}`);
983
+ z && console.log(`[atom-effect-jquery] Cleanup: ${n}`);
1208
984
  },
1209
985
  warn(...n) {
1210
- J && console.warn("[atom-effect-jquery]", ...n);
1211
- }
1212
- }, Ce = /* @__PURE__ */ new WeakMap();
1213
- function bt(n) {
1214
- const e = "jquery" in n ? n[0] : n;
1215
- if (!e || !e.isConnected) return;
1216
- let t = Ce.get(e);
1217
- if (t || (t = {}, Ce.set(e, t)), t.timer && clearTimeout(t.timer), t.cleanupTimer && clearTimeout(t.cleanupTimer), !t.orgStyle) {
1218
- const i = e.style;
1219
- t.orgStyle = {
986
+ z && console.warn("[atom-effect-jquery]", ...n);
987
+ }
988
+ }, gt = /* @__PURE__ */ new WeakMap();
989
+ function Ee(n) {
990
+ const t = "jquery" in n ? n[0] : n;
991
+ if (!t || !t.isConnected) return;
992
+ let e = gt.get(t);
993
+ if (e || (e = {}, gt.set(t, e)), e.timer && clearTimeout(e.timer), e.cleanupTimer && clearTimeout(e.cleanupTimer), !e.orgStyle) {
994
+ const i = t.style;
995
+ e.orgStyle = {
1220
996
  outline: i.outline,
1221
997
  outlineOffset: i.outlineOffset,
1222
998
  transition: i.transition
1223
999
  };
1224
1000
  }
1225
- const s = e.style;
1226
- s.outline = "2px solid rgba(255, 68, 68, 0.8)", s.outlineOffset = "1px", s.transition = "none", t.timer = setTimeout(() => {
1227
- e.isConnected && (s.transition = "outline 0.5s ease-out", requestAnimationFrame(() => {
1228
- if (!e.isConnected) return;
1229
- const i = t?.orgStyle;
1230
- i && (s.outline = i.outline, s.outlineOffset = i.outlineOffset), t.cleanupTimer = setTimeout(() => {
1231
- e.isConnected && t?.orgStyle && (s.transition = t.orgStyle.transition), Ce.delete(e);
1001
+ const s = t.style;
1002
+ s.outline = "2px solid rgba(255, 68, 68, 0.8)", s.outlineOffset = "1px", s.transition = "none", e.timer = setTimeout(() => {
1003
+ t.isConnected && (s.transition = "outline 0.5s ease-out", requestAnimationFrame(() => {
1004
+ if (!t.isConnected) return;
1005
+ const i = e?.orgStyle;
1006
+ i && (s.outline = i.outline, s.outlineOffset = i.outlineOffset), e.cleanupTimer = setTimeout(() => {
1007
+ t.isConnected && e?.orgStyle && (s.transition = e.orgStyle.transition), gt.delete(t);
1232
1008
  }, 500);
1233
1009
  }));
1234
1010
  }, 100);
1235
1011
  }
1236
- const St = /* @__PURE__ */ new WeakMap();
1237
- function Ye(n, e = {}) {
1238
- const t = dt(n, e);
1239
- return e.name && St.set(t, { name: e.name }), t;
1012
+ const pe = /* @__PURE__ */ new WeakMap();
1013
+ function Qt(n, t = {}) {
1014
+ const e = ue(n, t);
1015
+ return t.name && pe.set(e, { name: t.name }), e;
1240
1016
  }
1241
- Object.defineProperty(Ye, "debug", {
1017
+ Object.defineProperty(Qt, "debug", {
1242
1018
  get() {
1243
- return g.enabled;
1019
+ return _.enabled;
1244
1020
  },
1245
1021
  set(n) {
1246
- g.enabled = n;
1022
+ _.enabled = n;
1247
1023
  }
1248
1024
  });
1249
- function yt() {
1025
+ function ge() {
1250
1026
  return new Promise((n) => setTimeout(n, 0));
1251
1027
  }
1252
- l.extend({
1253
- atom: Ye,
1254
- computed: _t,
1255
- effect: ee,
1256
- batch: Ae,
1257
- untracked: Xe,
1258
- isAtom: Te,
1259
- isComputed: Fe,
1260
- isReactive: (n) => Te(n) || Fe(n),
1261
- nextTick: yt
1028
+ u.extend({
1029
+ atom: Qt,
1030
+ computed: he,
1031
+ effect: Y,
1032
+ batch: It,
1033
+ untracked: zt,
1034
+ isAtom: yt,
1035
+ isComputed: wt,
1036
+ isReactive: (n) => yt(n) || wt(n),
1037
+ nextTick: ge
1262
1038
  });
1263
- const he = "_aes-bound";
1264
- class It {
1039
+ const ot = "_aes-bound";
1040
+ class me {
1265
1041
  records = /* @__PURE__ */ new WeakMap();
1266
1042
  boundElements = /* @__PURE__ */ new WeakSet();
1267
1043
  preservedNodes = /* @__PURE__ */ new WeakSet();
1268
1044
  ignoredNodes = /* @__PURE__ */ new WeakSet();
1269
1045
  // Prevent redundant cleanup
1270
- keep(e) {
1271
- this.preservedNodes.add(e);
1046
+ keep(t) {
1047
+ this.preservedNodes.add(t);
1272
1048
  }
1273
- isKept(e) {
1274
- return this.preservedNodes.has(e);
1049
+ isKept(t) {
1050
+ return this.preservedNodes.has(t);
1275
1051
  }
1276
- markIgnored(e) {
1277
- this.ignoredNodes.add(e);
1052
+ markIgnored(t) {
1053
+ this.ignoredNodes.add(t);
1278
1054
  }
1279
- isIgnored(e) {
1280
- return this.ignoredNodes.has(e);
1055
+ isIgnored(t) {
1056
+ return this.ignoredNodes.has(t);
1281
1057
  }
1282
- _getOrCreateRecord(e) {
1283
- let t = this.records.get(e);
1284
- return t || (t = {}, this.records.set(e, t), this.boundElements.has(e) || (this.boundElements.add(e), e.classList.add(he))), t;
1058
+ _getOrCreateRecord(t) {
1059
+ let e = this.records.get(t);
1060
+ return e || (e = {}, this.records.set(t, e), this.boundElements.has(t) || (this.boundElements.add(t), t.classList.add(ot))), e;
1285
1061
  }
1286
- trackEffect(e, t) {
1287
- const s = this._getOrCreateRecord(e);
1288
- s.effects || (s.effects = []), s.effects.push(t);
1062
+ trackEffect(t, e) {
1063
+ const s = this._getOrCreateRecord(t);
1064
+ s.effects || (s.effects = []), s.effects.push(e);
1289
1065
  }
1290
- trackCleanup(e, t) {
1291
- const s = this._getOrCreateRecord(e);
1292
- s.cleanups || (s.cleanups = []), s.cleanups.push(t);
1066
+ trackCleanup(t, e) {
1067
+ const s = this._getOrCreateRecord(t);
1068
+ s.cleanups || (s.cleanups = []), s.cleanups.push(e);
1293
1069
  }
1294
- hasBind(e) {
1295
- return this.boundElements.has(e);
1070
+ hasBind(t) {
1071
+ return this.boundElements.has(t);
1296
1072
  }
1297
- cleanup(e) {
1298
- if (!this.boundElements.delete(e)) return;
1299
- const t = this.records.get(e);
1300
- if (!t) return;
1301
- this.records.delete(e), this.preservedNodes.delete(e), this.ignoredNodes.delete(e), e.classList.remove(he), g.enabled && g.cleanup(Ee(e));
1302
- const s = t.effects;
1073
+ cleanup(t) {
1074
+ if (!this.boundElements.delete(t)) return;
1075
+ const e = this.records.get(t);
1076
+ if (!e) return;
1077
+ this.records.delete(t), this.preservedNodes.delete(t), this.ignoredNodes.delete(t), t.classList.remove(ot), _.enabled && _.cleanup(ft(t));
1078
+ const s = e.effects;
1303
1079
  if (s)
1304
1080
  for (let o = 0, r = s.length; o < r; o++)
1305
1081
  try {
1306
1082
  s[o]?.dispose();
1307
1083
  } catch (c) {
1308
- g.warn("Effect dispose error:", c);
1084
+ _.warn("Effect dispose error:", c);
1309
1085
  }
1310
- const i = t.cleanups;
1086
+ const i = e.cleanups;
1311
1087
  if (i)
1312
1088
  for (let o = 0, r = i.length; o < r; o++)
1313
1089
  try {
1314
1090
  i[o]?.();
1315
1091
  } catch (c) {
1316
- g.warn("Cleanup error:", c);
1092
+ _.warn("Cleanup error:", c);
1317
1093
  }
1318
1094
  }
1319
- cleanupDescendants(e) {
1320
- const t = e.querySelectorAll(`.${he}`);
1321
- for (let s = 0, i = t.length; s < i; s++) {
1322
- const o = t[s];
1323
- o && this.boundElements.has(o) ? this.cleanup(o) : o && o.classList.remove(he);
1095
+ cleanupDescendants(t) {
1096
+ const e = t.querySelectorAll(`.${ot}`);
1097
+ for (let s = 0, i = e.length; s < i; s++) {
1098
+ const o = e[s];
1099
+ o && this.boundElements.has(o) ? this.cleanup(o) : o && o.classList.remove(ot);
1324
1100
  }
1325
1101
  }
1326
- cleanupTree(e) {
1327
- this.cleanupDescendants(e), this.cleanup(e);
1102
+ cleanupTree(t) {
1103
+ this.cleanupDescendants(t), this.cleanup(t);
1328
1104
  }
1329
1105
  }
1330
- const b = new It();
1331
- let ie = null;
1332
- function Ct(n = document.body) {
1333
- ie || (ie = new MutationObserver((e) => {
1334
- for (let t = 0, s = e.length; t < s; t++) {
1335
- const i = e[t]?.removedNodes;
1106
+ const p = new me();
1107
+ let et = null;
1108
+ function Se(n = document.body) {
1109
+ et || (et = new MutationObserver((t) => {
1110
+ for (let e = 0, s = t.length; e < s; e++) {
1111
+ const i = t[e]?.removedNodes;
1336
1112
  if (!i) continue;
1337
1113
  const o = i.length;
1338
1114
  if (o !== 0)
1339
1115
  for (let r = 0; r < o; r++) {
1340
1116
  const c = i[r];
1341
- c.nodeType === 1 && (c.isConnected || b.isKept(c) || b.isIgnored(c) || b.cleanupTree(c));
1117
+ c.nodeType === 1 && (c.isConnected || p.isKept(c) || p.isIgnored(c) || p.cleanupTree(c));
1342
1118
  }
1343
1119
  }
1344
- }), ie.observe(n, { childList: !0, subtree: !0 }));
1120
+ }), et.observe(n, { childList: !0, subtree: !0 }));
1345
1121
  }
1346
- function Mt() {
1347
- ie?.disconnect(), ie = null;
1122
+ function xe() {
1123
+ et?.disconnect(), et = null;
1348
1124
  }
1349
- function D(n, e, t, s) {
1350
- Et(e) ? b.trackEffect(
1125
+ function b(n, t, e, s) {
1126
+ fe(t) ? p.trackEffect(
1351
1127
  n,
1352
- ee(() => {
1353
- const i = e.value;
1354
- t(i), g.domUpdated(l(n), s, i);
1128
+ Y(() => {
1129
+ const i = t.value;
1130
+ e(i), _.domUpdated(u(n), s, i);
1355
1131
  })
1356
- ) : (t(e), g.domUpdated(l(n), s, e));
1132
+ ) : (e(t), _.domUpdated(u(n), s, t));
1357
1133
  }
1358
- var y = /* @__PURE__ */ ((n) => (n[n.None = 0] = "None", n[n.Focused = 1] = "Focused", n[n.Composing = 2] = "Composing", n[n.SyncingToAtom = 4] = "SyncingToAtom", n[n.SyncingToDom = 8] = "SyncingToDom", n[n.Busy = 14] = "Busy", n))(y || {});
1359
- function Re() {
1134
+ var g = /* @__PURE__ */ ((n) => (n[n.None = 0] = "None", n[n.Focused = 1] = "Focused", n[n.Composing = 2] = "Composing", n[n.SyncingToAtom = 4] = "SyncingToAtom", n[n.SyncingToDom = 8] = "SyncingToDom", n[n.Busy = 14] = "Busy", n))(g || {});
1135
+ function Dt() {
1360
1136
  return {
1361
1137
  timeoutId: null,
1362
1138
  flags: 0
1363
1139
  /* None */
1364
1140
  };
1365
1141
  }
1366
- function We(n, e, t = {}) {
1142
+ function Yt(n, t, e = {}) {
1367
1143
  const {
1368
1144
  debounce: s,
1369
1145
  event: i = "input",
1370
1146
  parse: o = (I) => I,
1371
1147
  format: r = (I) => String(I ?? ""),
1372
1148
  equal: c = Object.is
1373
- } = t, u = Re(), h = n[0], p = () => {
1374
- if (!(u.flags & y.Busy)) {
1375
- u.flags |= y.SyncingToAtom;
1149
+ } = e, l = Dt(), a = n[0], d = () => {
1150
+ if (!(l.flags & g.Busy)) {
1151
+ l.flags |= g.SyncingToAtom;
1376
1152
  try {
1377
- const I = h.value, A = o(I);
1378
- c(e.value, A) || (e.value = A);
1153
+ const I = a.value, D = o(I);
1154
+ c(t.value, D) || (t.value = D);
1379
1155
  } finally {
1380
- u.flags &= ~y.SyncingToAtom;
1156
+ l.flags &= ~g.SyncingToAtom;
1381
1157
  }
1382
1158
  }
1383
- }, a = () => {
1384
- u.timeoutId && (clearTimeout(u.timeoutId), u.timeoutId = null, p()), u.flags &= ~y.Focused;
1385
- const I = r(e.value);
1386
- h.value !== I && (h.value = I);
1387
- }, _ = () => {
1388
- u.flags & y.Busy || (s ? (u.timeoutId && clearTimeout(u.timeoutId), u.timeoutId = setTimeout(p, s)) : p());
1389
- }, d = {
1159
+ }, N = () => {
1160
+ l.timeoutId && (clearTimeout(l.timeoutId), l.timeoutId = null, d()), l.flags &= ~g.Focused;
1161
+ const I = r(t.value);
1162
+ a.value !== I && (a.value = I);
1163
+ }, C = () => {
1164
+ l.flags & g.Busy || (s ? (l.timeoutId && clearTimeout(l.timeoutId), l.timeoutId = setTimeout(d, s)) : d());
1165
+ }, v = {
1390
1166
  compositionstart: () => {
1391
- u.flags |= y.Composing;
1167
+ l.flags |= g.Composing;
1392
1168
  },
1393
1169
  compositionend: () => {
1394
- u.flags &= ~y.Composing, p();
1170
+ l.flags &= ~g.Composing, d();
1395
1171
  },
1396
1172
  focus: () => {
1397
- u.flags |= y.Focused;
1173
+ l.flags |= g.Focused;
1398
1174
  },
1399
- blur: a,
1400
- [i]: _,
1401
- change: _
1175
+ blur: N,
1176
+ [i]: C,
1177
+ change: C
1402
1178
  };
1403
- return n.on(d), { effect: () => {
1404
- const I = e.value, A = r(I), x = h.value;
1405
- if (x !== A && !(u.flags & y.Focused && c(o(x), I))) {
1406
- u.flags |= y.SyncingToDom;
1179
+ return n.on(v), { effect: () => {
1180
+ const I = t.value, D = r(I), O = a.value;
1181
+ if (O !== D && !(l.flags & g.Focused && c(o(O), I))) {
1182
+ l.flags |= g.SyncingToDom;
1407
1183
  try {
1408
- if (u.flags & y.Focused) {
1409
- const { selectionStart: re, selectionEnd: ge } = h;
1410
- h.value = A;
1411
- const V = A.length;
1412
- h.setSelectionRange(Math.min(re ?? V, V), Math.min(ge ?? V, V));
1184
+ if (l.flags & g.Focused) {
1185
+ const { selectionStart: nt, selectionEnd: _t } = a;
1186
+ a.value = D;
1187
+ const P = D.length;
1188
+ a.setSelectionRange(Math.min(nt ?? P, P), Math.min(_t ?? P, P));
1413
1189
  } else
1414
- h.value = A;
1415
- g.domUpdated(n, "val", A);
1190
+ a.value = D;
1191
+ _.domUpdated(n, "val", D);
1416
1192
  } finally {
1417
- u.flags &= ~y.SyncingToDom;
1193
+ l.flags &= ~g.SyncingToDom;
1418
1194
  }
1419
1195
  }
1420
1196
  }, cleanup: () => {
1421
- n.off(d), u.timeoutId && clearTimeout(u.timeoutId);
1197
+ n.off(v), l.timeoutId && clearTimeout(l.timeoutId);
1422
1198
  } };
1423
1199
  }
1424
- l.fn.atomText = function(n, e) {
1200
+ u.fn.atomText = function(n, t) {
1425
1201
  return this.each(function() {
1426
- const t = l(this);
1427
- D(this, n, e ? (i) => t.text(e(i)) : (i) => t.text(String(i ?? "")), "text");
1202
+ const e = u(this);
1203
+ b(this, n, t ? (i) => e.text(t(i)) : (i) => e.text(String(i ?? "")), "text");
1428
1204
  });
1429
1205
  };
1430
- l.fn.atomHtml = function(n) {
1206
+ u.fn.atomHtml = function(n) {
1431
1207
  return this.each(function() {
1432
- const e = l(this);
1433
- D(this, n, (t) => e.html(String(t ?? "")), "html");
1208
+ const t = u(this);
1209
+ b(this, n, (e) => t.html(String(e ?? "")), "html");
1434
1210
  });
1435
1211
  };
1436
- l.fn.atomClass = function(n, e) {
1212
+ u.fn.atomClass = function(n, t) {
1437
1213
  return this.each(function() {
1438
- const t = l(this);
1439
- D(
1214
+ const e = u(this);
1215
+ b(
1440
1216
  this,
1441
- e,
1442
- (s) => t.toggleClass(n, !!s),
1217
+ t,
1218
+ (s) => e.toggleClass(n, !!s),
1443
1219
  `class.${n}`
1444
1220
  );
1445
1221
  });
1446
1222
  };
1447
- l.fn.atomCss = function(n, e, t) {
1223
+ u.fn.atomCss = function(n, t, e) {
1448
1224
  return this.each(function() {
1449
- const s = l(this);
1450
- D(this, e, t ? (o) => s.css(n, `${o}${t}`) : (o) => s.css(n, o), `css.${n}`);
1225
+ const s = u(this);
1226
+ b(this, t, e ? (o) => s.css(n, `${o}${e}`) : (o) => s.css(n, o), `css.${n}`);
1451
1227
  });
1452
1228
  };
1453
- l.fn.atomAttr = function(n, e) {
1229
+ u.fn.atomAttr = function(n, t) {
1454
1230
  return this.each(function() {
1455
- const t = l(this);
1456
- D(
1231
+ const e = u(this);
1232
+ b(
1457
1233
  this,
1458
- e,
1234
+ t,
1459
1235
  (s) => {
1460
1236
  if (s == null || s === !1) {
1461
- t.removeAttr(n);
1237
+ e.removeAttr(n);
1462
1238
  return;
1463
1239
  }
1464
- t.attr(n, s === !0 ? n : String(s));
1240
+ e.attr(n, s === !0 ? n : String(s));
1465
1241
  },
1466
1242
  `attr.${n}`
1467
1243
  );
1468
1244
  });
1469
1245
  };
1470
- l.fn.atomProp = function(n, e) {
1246
+ u.fn.atomProp = function(n, t) {
1471
1247
  return this.each(function() {
1472
- const t = l(this);
1473
- D(this, e, (s) => t.prop(n, s), `prop.${n}`);
1248
+ const e = u(this);
1249
+ b(this, t, (s) => e.prop(n, s), `prop.${n}`);
1474
1250
  });
1475
1251
  };
1476
- l.fn.atomShow = function(n) {
1252
+ u.fn.atomShow = function(n) {
1477
1253
  return this.each(function() {
1478
- const e = l(this);
1479
- D(this, n, (t) => e.toggle(!!t), "show");
1254
+ const t = u(this);
1255
+ b(this, n, (e) => t.toggle(!!e), "show");
1480
1256
  });
1481
1257
  };
1482
- l.fn.atomHide = function(n) {
1258
+ u.fn.atomHide = function(n) {
1483
1259
  return this.each(function() {
1484
- const e = l(this);
1485
- D(this, n, (t) => e.toggle(!t), "hide");
1260
+ const t = u(this);
1261
+ b(this, n, (e) => t.toggle(!e), "hide");
1486
1262
  });
1487
1263
  };
1488
- l.fn.atomVal = function(n, e = {}) {
1264
+ u.fn.atomVal = function(n, t = {}) {
1489
1265
  return this.each(function() {
1490
- const { effect: t, cleanup: s } = We(l(this), n, e);
1491
- b.trackEffect(this, ee(t)), b.trackCleanup(this, s);
1266
+ const { effect: e, cleanup: s } = Yt(u(this), n, t);
1267
+ p.trackEffect(this, Y(e)), p.trackCleanup(this, s);
1492
1268
  });
1493
1269
  };
1494
- l.fn.atomChecked = function(n) {
1270
+ u.fn.atomChecked = function(n) {
1495
1271
  return this.each(function() {
1496
- const e = l(this), t = this, s = Re(), i = () => {
1497
- if (s.flags & y.Busy) return;
1498
- const r = t.checked;
1272
+ const t = u(this), e = this, s = Dt(), i = () => {
1273
+ if (s.flags & g.Busy) return;
1274
+ const r = e.checked;
1499
1275
  n.value !== r && (n.value = r);
1500
1276
  };
1501
- e.on("change", i), b.trackCleanup(this, () => e.off("change", i));
1502
- const o = ee(() => {
1503
- s.flags |= y.SyncingToDom;
1277
+ t.on("change", i), p.trackCleanup(this, () => t.off("change", i));
1278
+ const o = Y(() => {
1279
+ s.flags |= g.SyncingToDom;
1504
1280
  const r = !!n.value;
1505
- t.checked !== r && (t.checked = r, g.domUpdated(e, "checked", r)), s.flags &= ~y.SyncingToDom;
1281
+ e.checked !== r && (e.checked = r, _.domUpdated(t, "checked", r)), s.flags &= ~g.SyncingToDom;
1506
1282
  });
1507
- b.trackEffect(this, o);
1283
+ p.trackEffect(this, o);
1508
1284
  });
1509
1285
  };
1510
- l.fn.atomOn = function(n, e) {
1286
+ u.fn.atomOn = function(n, t) {
1511
1287
  return this.each(function() {
1512
- const t = l(this);
1513
- t.on(n, e), b.trackCleanup(this, () => t.off(n, e));
1288
+ const e = u(this);
1289
+ e.on(n, t), p.trackCleanup(this, () => e.off(n, t));
1514
1290
  });
1515
1291
  };
1516
- l.fn.atomUnbind = function() {
1292
+ u.fn.atomUnbind = function() {
1517
1293
  return this.each(function() {
1518
- b.cleanupTree(this);
1294
+ p.cleanupTree(this);
1519
1295
  });
1520
1296
  };
1521
- const Be = /* @__PURE__ */ Object.create(null);
1522
- function Dt(n) {
1523
- let e = Be[n];
1524
- return e || (e = n.includes("-") ? n.replace(/-./g, (t) => t[1].toUpperCase()) : n, Be[n] = e, e);
1297
+ const Ft = /* @__PURE__ */ Object.create(null);
1298
+ function be(n) {
1299
+ let t = Ft[n];
1300
+ return t || (t = n.includes("-") ? n.replace(/-./g, (e) => e[1].toUpperCase()) : n, Ft[n] = t, t);
1525
1301
  }
1526
- function Tt(n, e) {
1527
- const t = n.el;
1528
- D(
1529
- t,
1302
+ function ye(n, t) {
1303
+ const e = n.el;
1304
+ b(
1530
1305
  e,
1306
+ t,
1531
1307
  (s) => {
1532
1308
  const i = typeof s == "string" ? s : String(s ?? "");
1533
- t.textContent !== i && (t.textContent = i);
1309
+ e.textContent !== i && (e.textContent = i);
1534
1310
  },
1535
1311
  "text"
1536
1312
  );
1537
1313
  }
1538
- function Nt(n, e) {
1539
- const t = n.el;
1540
- D(
1541
- t,
1314
+ function Ce(n, t) {
1315
+ const e = n.el;
1316
+ b(
1542
1317
  e,
1318
+ t,
1543
1319
  (s) => {
1544
1320
  const i = String(s ?? "");
1545
- t.innerHTML !== i && (t.innerHTML = i);
1321
+ e.innerHTML !== i && (e.innerHTML = i);
1546
1322
  },
1547
1323
  "html"
1548
1324
  );
1549
1325
  }
1550
- function Ot(n, e) {
1551
- for (const t in e)
1552
- D(
1326
+ function Ie(n, t) {
1327
+ for (const e in t)
1328
+ b(
1553
1329
  n.el,
1554
- e[t],
1330
+ t[e],
1555
1331
  (s) => {
1556
- n.el.classList.toggle(t, !!s);
1332
+ n.el.classList.toggle(e, !!s);
1557
1333
  },
1558
- `class.${t}`
1334
+ `class.${e}`
1559
1335
  );
1560
1336
  }
1561
- function At(n, e) {
1562
- const t = n.el, s = t.style;
1563
- for (const i in e) {
1564
- const o = e[i];
1337
+ function De(n, t) {
1338
+ const e = n.el, s = e.style;
1339
+ for (const i in t) {
1340
+ const o = t[i];
1565
1341
  if (o === void 0) continue;
1566
- const r = Dt(i);
1567
- Array.isArray(o) ? D(
1568
- t,
1342
+ const r = be(i);
1343
+ Array.isArray(o) ? b(
1344
+ e,
1569
1345
  o[0],
1570
1346
  (c) => {
1571
1347
  s[r] = `${c}${o[1]}`;
1572
1348
  },
1573
1349
  `css.${i}`
1574
- ) : D(
1575
- t,
1350
+ ) : b(
1351
+ e,
1576
1352
  o,
1577
1353
  (c) => {
1578
1354
  s[r] = c;
@@ -1581,316 +1357,316 @@ function At(n, e) {
1581
1357
  );
1582
1358
  }
1583
1359
  }
1584
- function Rt(n, e) {
1585
- const t = n.el;
1586
- for (const s in e)
1587
- D(
1588
- t,
1589
- e[s],
1360
+ function Te(n, t) {
1361
+ const e = n.el;
1362
+ for (const s in t)
1363
+ b(
1364
+ e,
1365
+ t[s],
1590
1366
  (i) => {
1591
1367
  if (i == null || i === !1) {
1592
- t.removeAttribute(s);
1368
+ e.removeAttribute(s);
1593
1369
  return;
1594
1370
  }
1595
1371
  const o = i === !0 ? s : String(i);
1596
- t.getAttribute(s) !== o && t.setAttribute(s, o);
1372
+ e.getAttribute(s) !== o && e.setAttribute(s, o);
1597
1373
  },
1598
1374
  `attr.${s}`
1599
1375
  );
1600
1376
  }
1601
- function vt(n, e) {
1602
- const t = n.el;
1603
- for (const s in e)
1604
- D(
1377
+ function Ne(n, t) {
1378
+ const e = n.el;
1379
+ for (const s in t)
1380
+ b(
1605
1381
  n.el,
1606
- e[s],
1382
+ t[s],
1607
1383
  (i) => {
1608
- t[s] !== i && (t[s] = i);
1384
+ e[s] !== i && (e[s] = i);
1609
1385
  },
1610
1386
  `prop.${s}`
1611
1387
  );
1612
1388
  }
1613
- function xt(n, e) {
1614
- const t = n.el;
1615
- D(
1616
- t,
1389
+ function Oe(n, t) {
1390
+ const e = n.el;
1391
+ b(
1617
1392
  e,
1393
+ t,
1618
1394
  (s) => {
1619
- t.style.display = s ? "" : "none", g.enabled && g.domUpdated(t, "show", s);
1395
+ e.style.display = s ? "" : "none", _.enabled && _.domUpdated(e, "show", s);
1620
1396
  },
1621
1397
  "show"
1622
1398
  );
1623
1399
  }
1624
- function Ut(n, e) {
1625
- const t = n.el;
1626
- D(
1627
- t,
1400
+ function ke(n, t) {
1401
+ const e = n.el;
1402
+ b(
1628
1403
  e,
1404
+ t,
1629
1405
  (s) => {
1630
- t.style.display = s ? "none" : "", g.enabled && g.domUpdated(t, "hide", s);
1406
+ e.style.display = s ? "none" : "", _.enabled && _.domUpdated(e, "hide", s);
1631
1407
  },
1632
1408
  "hide"
1633
1409
  );
1634
1410
  }
1635
- function wt(n, e) {
1636
- const t = Array.isArray(e), { effect: s, cleanup: i } = We(
1411
+ function Ae(n, t) {
1412
+ const e = Array.isArray(t), { effect: s, cleanup: i } = Yt(
1637
1413
  n.$el,
1638
- t ? e[0] : e,
1639
- t ? e[1] : {}
1414
+ e ? t[0] : t,
1415
+ e ? t[1] : {}
1640
1416
  );
1641
- b.trackEffect(n.el, ee(s)), n.trackCleanup(i);
1417
+ p.trackEffect(n.el, Y(s)), n.trackCleanup(i);
1642
1418
  }
1643
- function kt(n, e) {
1644
- const t = n.el, s = Re(), i = () => {
1645
- if (s.flags & y.Busy) return;
1646
- const r = t.checked;
1647
- e.value !== r && (e.value = r);
1419
+ function ve(n, t) {
1420
+ const e = n.el, s = Dt(), i = () => {
1421
+ if (s.flags & g.Busy) return;
1422
+ const r = e.checked;
1423
+ t.value !== r && (t.value = r);
1648
1424
  };
1649
- t.addEventListener("change", i), n.trackCleanup(() => t.removeEventListener("change", i));
1650
- const o = ee(() => {
1651
- s.flags |= y.SyncingToDom;
1652
- const r = !!e.value;
1653
- t.checked !== r && (t.checked = r, g.enabled && g.domUpdated(t, "checked", r)), s.flags &= ~y.SyncingToDom;
1425
+ e.addEventListener("change", i), n.trackCleanup(() => e.removeEventListener("change", i));
1426
+ const o = Y(() => {
1427
+ s.flags |= g.SyncingToDom;
1428
+ const r = !!t.value;
1429
+ e.checked !== r && (e.checked = r, _.enabled && _.domUpdated(e, "checked", r)), s.flags &= ~g.SyncingToDom;
1654
1430
  });
1655
- b.trackEffect(t, o);
1431
+ p.trackEffect(e, o);
1656
1432
  }
1657
- function Lt(n, e) {
1658
- for (const t in e) {
1659
- const s = e[t];
1433
+ function Ue(n, t) {
1434
+ for (const e in t) {
1435
+ const s = t[e];
1660
1436
  if (typeof s != "function") continue;
1661
1437
  const i = (o) => {
1662
- Ae(
1438
+ It(
1663
1439
  () => s.call(
1664
1440
  n.el,
1665
- l.Event(o.type, { originalEvent: o })
1441
+ u.Event(o.type, { originalEvent: o })
1666
1442
  )
1667
1443
  );
1668
1444
  };
1669
- n.el.addEventListener(t, i), n.trackCleanup(() => n.el.removeEventListener(t, i));
1445
+ n.el.addEventListener(e, i), n.trackCleanup(() => n.el.removeEventListener(e, i));
1670
1446
  }
1671
1447
  }
1672
- l.fn.atomBind = function(n) {
1448
+ u.fn.atomBind = function(n) {
1673
1449
  return this.each(function() {
1674
- const e = this;
1675
- let t = null;
1450
+ const t = this;
1451
+ let e = null;
1676
1452
  const s = {
1677
1453
  get $el() {
1678
- return t || (t = l(e)), t;
1454
+ return e || (e = u(t)), e;
1679
1455
  },
1680
- el: e,
1681
- trackCleanup: (i) => b.trackCleanup(e, i)
1456
+ el: t,
1457
+ trackCleanup: (i) => p.trackCleanup(t, i)
1682
1458
  };
1683
- n.text !== void 0 && Tt(s, n.text), n.html !== void 0 && Nt(s, n.html), n.class && Ot(s, n.class), n.css && At(s, n.css), n.attr && Rt(s, n.attr), n.prop && vt(s, n.prop), n.show !== void 0 && xt(s, n.show), n.hide !== void 0 && Ut(s, n.hide), n.val !== void 0 && wt(s, n.val), n.checked !== void 0 && kt(s, n.checked), n.on && Lt(s, n.on);
1459
+ n.text !== void 0 && ye(s, n.text), n.html !== void 0 && Ce(s, n.html), n.class && Ie(s, n.class), n.css && De(s, n.css), n.attr && Te(s, n.attr), n.prop && Ne(s, n.prop), n.show !== void 0 && Oe(s, n.show), n.hide !== void 0 && ke(s, n.hide), n.val !== void 0 && Ae(s, n.val), n.checked !== void 0 && ve(s, n.checked), n.on && Ue(s, n.on);
1684
1460
  });
1685
1461
  };
1686
- l.fn.atomList = function(n, e) {
1687
- const { key: t, render: s, bind: i, update: o, onAdd: r, onRemove: c, empty: u } = e, h = typeof t == "function" ? t : (p, a) => p[t];
1462
+ u.fn.atomList = function(n, t) {
1463
+ const { key: e, render: s, bind: i, update: o, onAdd: r, onRemove: c, empty: l } = t, a = typeof e == "function" ? e : (d, N) => d[e];
1688
1464
  return this.each(function() {
1689
- const p = l(this), a = Ee(this), _ = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Set();
1690
- let S = [], T = null;
1691
- const I = ee(() => {
1692
- const A = n.value, x = A.length;
1693
- if (x === 0 ? u && !T && (T = l(u).appendTo(p)) : T && (T.remove(), T = null), x === 0 && _.size === 0) {
1694
- S = [];
1465
+ const d = u(this), N = ft(this), C = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Set();
1466
+ let H = [], V = null;
1467
+ const I = Y(() => {
1468
+ const D = n.value, O = D.length;
1469
+ if (O === 0 ? l && !V && (V = u(l).appendTo(d)) : V && (V.remove(), V = null), O === 0 && C.size === 0) {
1470
+ H = [];
1695
1471
  return;
1696
1472
  }
1697
- g.log("list", `${a} updating with ${x} items`);
1698
- const re = /* @__PURE__ */ new Map(), ge = S.length;
1699
- for (let E = 0; E < ge; E++)
1700
- re.set(S[E], E);
1701
- const V = new Array(x), me = /* @__PURE__ */ new Set(), ve = new Int32Array(x);
1702
- for (let E = 0; E < x; E++) {
1703
- const M = A[E], m = h(M, E);
1704
- g.enabled && me.has(m) && console.warn(`[atomList] Duplicate key "${m}" at index ${E}.`), V[E] = m, me.add(m), ve[E] = re.get(m) ?? -1;
1473
+ _.log("list", `${N} updating with ${O} items`);
1474
+ const nt = /* @__PURE__ */ new Map(), _t = H.length;
1475
+ for (let f = 0; f < _t; f++)
1476
+ nt.set(H[f], f);
1477
+ const P = new Array(O), dt = /* @__PURE__ */ new Set(), Tt = new Int32Array(O);
1478
+ for (let f = 0; f < O; f++) {
1479
+ const x = D[f], E = a(x, f);
1480
+ _.enabled && dt.has(E) && console.warn(`[atomList] Duplicate key "${E}" at index ${f}.`), P[f] = E, dt.add(E), Tt[f] = nt.get(E) ?? -1;
1705
1481
  }
1706
- if (_.size > 0)
1707
- for (const [E, M] of _) {
1708
- if (me.has(E) || d.has(E)) continue;
1709
- const m = () => {
1710
- M.$el.remove(), M.$el[0] && b.cleanup(M.$el[0]), d.delete(E), g.log("list", `${a} removed item:`, E);
1482
+ if (C.size > 0)
1483
+ for (const [f, x] of C) {
1484
+ if (dt.has(f) || v.has(f)) continue;
1485
+ const E = () => {
1486
+ x.$el.remove(), x.$el[0] && p.cleanup(x.$el[0]), v.delete(f), _.log("list", `${N} removed item:`, f);
1711
1487
  };
1712
- if (_.delete(E), d.add(E), c) {
1713
- const N = c(M.$el);
1714
- N instanceof Promise ? N.then(m) : m();
1488
+ if (C.delete(f), v.add(f), c) {
1489
+ const y = c(x.$el);
1490
+ y instanceof Promise ? y.then(E) : E();
1715
1491
  } else
1716
- m();
1492
+ E();
1717
1493
  }
1718
- if (x === 0) {
1719
- S = [];
1494
+ if (O === 0) {
1495
+ H = [];
1720
1496
  return;
1721
1497
  }
1722
- const xe = gt(ve);
1723
- let be = xe.length - 1, P = null;
1724
- for (let E = x - 1; E >= 0; E--) {
1725
- const M = V[E], m = A[E], N = _.get(M);
1726
- if (N) {
1727
- const te = N.item;
1728
- N.item = m;
1729
- const k = N.$el[0];
1730
- if (!k) continue;
1498
+ const Nt = _e(Tt);
1499
+ let Et = Nt.length - 1, w = null;
1500
+ for (let f = O - 1; f >= 0; f--) {
1501
+ const x = P[f], E = D[f], y = C.get(x);
1502
+ if (y) {
1503
+ const J = y.item;
1504
+ y.item = E;
1505
+ const U = y.$el[0];
1506
+ if (!U) continue;
1731
1507
  if (o)
1732
- o(N.$el, m, E), g.domUpdated(N.$el, "list.update", m);
1733
- else if (te !== m) {
1734
- let H = !0;
1735
- if (typeof te == "object" && te !== null && typeof m == "object" && m !== null) {
1736
- H = !1;
1737
- let B = 0;
1738
- const ce = te, Ue = m;
1739
- for (const ne in ce) {
1740
- if (ce[ne] !== Ue[ne]) {
1741
- H = !0;
1508
+ o(y.$el, E, f), _.domUpdated(y.$el, "list.update", E);
1509
+ else if (J !== E) {
1510
+ let M = !0;
1511
+ if (typeof J == "object" && J !== null && typeof E == "object" && E !== null) {
1512
+ M = !1;
1513
+ let L = 0;
1514
+ const st = J, Ot = E;
1515
+ for (const W in st) {
1516
+ if (st[W] !== Ot[W]) {
1517
+ M = !0;
1742
1518
  break;
1743
1519
  }
1744
- B++;
1520
+ L++;
1745
1521
  }
1746
- if (!H) {
1747
- let ne = 0;
1748
- for (const Ft in Ue)
1749
- if (ne++, ne > B) {
1750
- H = !0;
1522
+ if (!M) {
1523
+ let W = 0;
1524
+ for (const Re in Ot)
1525
+ if (W++, W > L) {
1526
+ M = !0;
1751
1527
  break;
1752
1528
  }
1753
- B !== ne && (H = !0);
1529
+ L !== W && (M = !0);
1754
1530
  }
1755
1531
  }
1756
- if (H) {
1757
- const B = l(s(m, E)), ce = P === k;
1758
- N.$el.replaceWith(B), N.$el = B, i && i(B, m, E), g.domUpdated(B, "list.render", m), ce && (P = B[0] || null);
1532
+ if (M) {
1533
+ const L = u(s(E, f)), st = w === U;
1534
+ y.$el.replaceWith(L), y.$el = L, i && i(L, E, f), _.domUpdated(L, "list.render", E), st && (w = L[0] || null);
1759
1535
  }
1760
1536
  }
1761
- if (be >= 0 && xe[be] === E)
1762
- be--;
1537
+ if (Et >= 0 && Nt[Et] === f)
1538
+ Et--;
1763
1539
  else {
1764
- const H = N.$el[0];
1765
- P?.isConnected ? P !== H && N.$el.insertBefore(P) : N.$el.appendTo(p);
1540
+ const M = y.$el[0];
1541
+ w?.isConnected ? w !== M && y.$el.insertBefore(w) : y.$el.appendTo(d);
1766
1542
  }
1767
- P = N.$el[0] || null;
1543
+ w = y.$el[0] || null;
1768
1544
  } else {
1769
- const te = s(m, E), k = l(te);
1770
- _.set(M, { $el: k, item: m }), P?.isConnected ? k.insertBefore(P) : k.appendTo(p), i && i(k, m, E), r && r(k), g.domUpdated(k, "list.add", m), P = k[0] || null;
1545
+ const J = s(E, f), U = u(J);
1546
+ C.set(x, { $el: U, item: E }), w?.isConnected ? U.insertBefore(w) : U.appendTo(d), i && i(U, E, f), r && r(U), _.domUpdated(U, "list.add", E), w = U[0] || null;
1771
1547
  }
1772
1548
  }
1773
- S = V;
1549
+ H = P;
1774
1550
  });
1775
- b.trackEffect(this, I), b.trackCleanup(this, () => {
1776
- _.clear(), d.clear(), S = [], T?.remove();
1551
+ p.trackEffect(this, I), p.trackCleanup(this, () => {
1552
+ C.clear(), v.clear(), H = [], V?.remove();
1777
1553
  });
1778
1554
  });
1779
1555
  };
1780
- const ae = /* @__PURE__ */ new WeakMap();
1781
- l.fn.atomMount = function(n, e = {}) {
1556
+ const ct = /* @__PURE__ */ new WeakMap();
1557
+ u.fn.atomMount = function(n, t = {}) {
1782
1558
  return this.each(function() {
1783
- const t = g.enabled, s = t ? Ee(this) : "", i = ae.get(this);
1784
- i && (t && g.log("mount", `${s} unmounting existing component`), i()), t && g.log("mount", `${s} mounting component`);
1559
+ const e = _.enabled, s = e ? ft(this) : "", i = ct.get(this);
1560
+ i && (e && _.log("mount", `${s} unmounting existing component`), i()), e && _.log("mount", `${s} mounting component`);
1785
1561
  let o;
1786
1562
  try {
1787
- o = n(l(this), e);
1563
+ o = n(u(this), t);
1788
1564
  } catch (c) {
1789
1565
  console.error("[atom-effect-jquery] Mount error:", c);
1790
1566
  return;
1791
1567
  }
1792
1568
  const r = () => {
1793
- if (ae.delete(this)) {
1794
- if (t && g.log("mount", `${s} full cleanup`), typeof o == "function")
1569
+ if (ct.delete(this)) {
1570
+ if (e && _.log("mount", `${s} full cleanup`), typeof o == "function")
1795
1571
  try {
1796
1572
  o();
1797
1573
  } catch (c) {
1798
1574
  console.error("[atom-effect-jquery] Cleanup error:", c);
1799
1575
  }
1800
- b.cleanupTree(this);
1576
+ p.cleanupTree(this);
1801
1577
  }
1802
1578
  };
1803
- ae.set(this, r), b.trackCleanup(this, r);
1579
+ ct.set(this, r), p.trackCleanup(this, r);
1804
1580
  });
1805
1581
  };
1806
- l.fn.atomUnmount = function() {
1582
+ u.fn.atomUnmount = function() {
1807
1583
  return this.each(function() {
1808
- const n = ae.get(this);
1584
+ const n = ct.get(this);
1809
1585
  n && n();
1810
1586
  });
1811
1587
  };
1812
- const de = /* @__PURE__ */ new WeakMap();
1813
- let $e = !1;
1814
- const je = (n) => {
1815
- let e = de.get(n);
1816
- return e || (e = function(...t) {
1817
- return Ae(() => n.apply(this, t));
1818
- }, de.set(n, e)), e;
1588
+ const lt = /* @__PURE__ */ new WeakMap();
1589
+ let Pt = !1;
1590
+ const Mt = (n) => {
1591
+ let t = lt.get(n);
1592
+ return t || (t = function(...e) {
1593
+ return It(() => n.apply(this, e));
1594
+ }, lt.set(n, t)), t;
1819
1595
  };
1820
- function Ke() {
1821
- if ($e) return;
1822
- $e = !0;
1823
- const n = l.fn.on, e = l.fn.off, t = l.fn.remove, s = l.fn.empty, i = l.fn.detach;
1824
- l.fn.remove = function(o) {
1596
+ function Jt() {
1597
+ if (Pt) return;
1598
+ Pt = !0;
1599
+ const n = u.fn.on, t = u.fn.off, e = u.fn.remove, s = u.fn.empty, i = u.fn.detach;
1600
+ u.fn.remove = function(o) {
1825
1601
  const r = o ? this.filter(o) : this;
1826
- for (let c = 0, u = r.length; c < u; c++) {
1827
- const h = r[c];
1828
- h && (b.cleanupTree(h), b.markIgnored(h));
1602
+ for (let c = 0, l = r.length; c < l; c++) {
1603
+ const a = r[c];
1604
+ a && (p.cleanupTree(a), p.markIgnored(a));
1829
1605
  }
1830
- return t.call(this, o);
1831
- }, l.fn.empty = function() {
1606
+ return e.call(this, o);
1607
+ }, u.fn.empty = function() {
1832
1608
  for (let o = 0, r = this.length; o < r; o++) {
1833
1609
  const c = this[o];
1834
- c && b.cleanupDescendants(c);
1610
+ c && p.cleanupDescendants(c);
1835
1611
  }
1836
1612
  return s.call(this);
1837
- }, l.fn.detach = function(o) {
1613
+ }, u.fn.detach = function(o) {
1838
1614
  const r = o ? this.filter(o) : this;
1839
- for (let c = 0, u = r.length; c < u; c++) {
1840
- const h = r[c];
1841
- h && b.keep(h);
1615
+ for (let c = 0, l = r.length; c < l; c++) {
1616
+ const a = r[c];
1617
+ a && p.keep(a);
1842
1618
  }
1843
1619
  return i.call(this, o);
1844
- }, l.fn.on = function(...o) {
1620
+ }, u.fn.on = function(...o) {
1845
1621
  const r = o[0];
1846
1622
  if (r && typeof r == "object") {
1847
- const c = r, u = {};
1848
- for (const h in c) {
1849
- const p = c[h];
1850
- p && (u[h] = je(p));
1623
+ const c = r, l = {};
1624
+ for (const a in c) {
1625
+ const d = c[a];
1626
+ d && (l[a] = Mt(d));
1851
1627
  }
1852
- o[0] = u;
1628
+ o[0] = l;
1853
1629
  } else
1854
1630
  for (let c = o.length - 1; c >= 0; c--)
1855
1631
  if (typeof o[c] == "function") {
1856
- o[c] = je(o[c]);
1632
+ o[c] = Mt(o[c]);
1857
1633
  break;
1858
1634
  }
1859
1635
  return n.apply(this, o);
1860
- }, l.fn.off = function(...o) {
1636
+ }, u.fn.off = function(...o) {
1861
1637
  const r = o[0];
1862
1638
  if (r && typeof r == "object") {
1863
- const c = r, u = {};
1864
- for (const h in c) {
1865
- const p = c[h];
1866
- p && (u[h] = de.get(p) || p);
1639
+ const c = r, l = {};
1640
+ for (const a in c) {
1641
+ const d = c[a];
1642
+ d && (l[a] = lt.get(d) || d);
1867
1643
  }
1868
- o[0] = u;
1644
+ o[0] = l;
1869
1645
  } else
1870
1646
  for (let c = o.length - 1; c >= 0; c--)
1871
1647
  if (typeof o[c] == "function") {
1872
- o[c] = de.get(o[c]) || o[c];
1648
+ o[c] = lt.get(o[c]) || o[c];
1873
1649
  break;
1874
1650
  }
1875
- return e.apply(this, o);
1651
+ return t.apply(this, o);
1876
1652
  };
1877
1653
  }
1878
- const Bt = Ke;
1879
- Ke();
1880
- l(() => {
1881
- Ct(document.body);
1654
+ const Le = Jt;
1655
+ Jt();
1656
+ u(() => {
1657
+ Se(document.body);
1882
1658
  });
1883
1659
  export {
1884
- dt as atom,
1885
- Ae as batch,
1886
- _t as computed,
1887
- Vt as default,
1888
- Mt as disableAutoCleanup,
1889
- ee as effect,
1890
- Ct as enableAutoCleanup,
1891
- Bt as enablejQueryBatching,
1892
- Ke as enablejQueryOverrides,
1893
- b as registry,
1894
- Xe as untracked
1660
+ ue as atom,
1661
+ It as batch,
1662
+ he as computed,
1663
+ Me as default,
1664
+ xe as disableAutoCleanup,
1665
+ Y as effect,
1666
+ Se as enableAutoCleanup,
1667
+ Le as enablejQueryBatching,
1668
+ Jt as enablejQueryOverrides,
1669
+ p as registry,
1670
+ zt as untracked
1895
1671
  };
1896
1672
  //# sourceMappingURL=index.mjs.map