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