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