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