@but212/atom-effect-jquery 0.26.0 → 0.27.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
@@ -50,7 +50,13 @@ var d = Object.freeze([]), f = class {
50
50
  this.fn = e, this.sub = t;
51
51
  }
52
52
  notify(e, t) {
53
- this.fn ? this.fn(e, t) : this.sub && this.sub.execute();
53
+ let n = this.fn;
54
+ if (n !== void 0) {
55
+ n(e, t);
56
+ return;
57
+ }
58
+ let r = this.sub;
59
+ r !== void 0 && r.execute();
54
60
  }
55
61
  }, m = class extends Error {
56
62
  constructor(e, t = null, n = !0) {
@@ -95,20 +101,18 @@ var d = Object.freeze([]), f = class {
95
101
  return this._count;
96
102
  }
97
103
  getAt(e) {
98
- switch (e) {
104
+ if (e < 4) switch (e) {
99
105
  case 0: return this._s0;
100
106
  case 1: return this._s1;
101
107
  case 2: return this._s2;
102
108
  case 3: return this._s3;
103
- default: {
104
- let t = this._overflow;
105
- if (t !== null && e >= 4) {
106
- let n = e - 4;
107
- if (n < t.length) return t[n] ?? null;
108
- }
109
- return null;
110
- }
111
109
  }
110
+ let t = this._overflow;
111
+ if (t !== null) {
112
+ let n = t[e - 4];
113
+ return n === void 0 ? null : n;
114
+ }
115
+ return null;
112
116
  }
113
117
  setAt(e, t) {
114
118
  switch (e) {
@@ -124,31 +128,27 @@ var d = Object.freeze([]), f = class {
124
128
  case 3:
125
129
  this._s3 = t;
126
130
  break;
127
- default: {
128
- this._overflow ??= [];
129
- let n = this._overflow;
130
- n[e - 4] = t;
131
- }
131
+ default: this._overflow ??= [], this._overflow[e - 4] = t;
132
132
  }
133
133
  e >= this._count && (this._count = e + 1);
134
134
  }
135
135
  truncateFrom(e) {
136
136
  let t = this._count;
137
137
  if (e >= t) return;
138
- if (e <= 3) switch (e) {
139
- case 0: {
138
+ if (e <= 3) {
139
+ if (e <= 0) {
140
140
  let e = this._s0;
141
141
  e != null && (this._onItemRemoved(e), this._s0 = null);
142
142
  }
143
- case 1: {
143
+ if (e <= 1) {
144
144
  let e = this._s1;
145
145
  e != null && (this._onItemRemoved(e), this._s1 = null);
146
146
  }
147
- case 2: {
147
+ if (e <= 2) {
148
148
  let e = this._s2;
149
149
  e != null && (this._onItemRemoved(e), this._s2 = null);
150
150
  }
151
- case 3: {
151
+ if (e <= 3) {
152
152
  let e = this._s3;
153
153
  e != null && (this._onItemRemoved(e), this._s3 = null);
154
154
  }
@@ -185,10 +185,11 @@ var d = Object.freeze([]), f = class {
185
185
  this._addToOverflow(e);
186
186
  }
187
187
  _addToOverflow(e) {
188
- if (this._overflow === null) this._overflow = [e];
188
+ let t = this._overflow;
189
+ if (t === null) this._overflow = [e];
189
190
  else {
190
- let t = this._freeIndices;
191
- t !== null && t.length > 0 ? this._overflow[t.pop()] = e : this._overflow.push(e);
191
+ let n = this._freeIndices;
192
+ n !== null && n.length > 0 ? t[n.pop()] = e : t.push(e);
192
193
  }
193
194
  this._count++;
194
195
  }
@@ -199,7 +200,11 @@ var d = Object.freeze([]), f = class {
199
200
  if (this._s3 === e) return this._s3 = null, this._count--, !0;
200
201
  let t = this._overflow;
201
202
  if (t == null) return !1;
202
- for (let n = 0, r = t.length; n < r; n++) if (t[n] === e) return t[n] = null, this._count--, this._freeIndices === null && (this._freeIndices = []), this._freeIndices.push(n), !0;
203
+ for (let n = 0, r = t.length; n < r; n++) if (t[n] === e) {
204
+ t[n] = null, this._count--;
205
+ let e = this._freeIndices;
206
+ return e === null && (e = this._freeIndices = []), e.push(n), !0;
207
+ }
203
208
  return !1;
204
209
  }
205
210
  has(e) {
@@ -212,48 +217,51 @@ var d = Object.freeze([]), f = class {
212
217
  return !1;
213
218
  }
214
219
  forEach(e) {
215
- if (this._count === 0) return;
216
- let t = this._s0;
217
- t != null && e(t);
218
- let n = this._s1;
219
- n != null && e(n);
220
- let r = this._s2;
221
- r != null && e(r);
222
- let i = this._s3;
223
- i != null && e(i);
224
- let a = this._overflow;
225
- if (a != null) for (let t = 0, n = a.length; t < n; t++) {
226
- let n = a[t];
227
- n != null && e(n);
220
+ let t = this._count;
221
+ if (t === 0) return;
222
+ let n = 0, r = this._s0;
223
+ if (r != null && (e(r), ++n === t)) return;
224
+ let i = this._s1;
225
+ if (i != null && (e(i), ++n === t)) return;
226
+ let a = this._s2;
227
+ if (a != null && (e(a), ++n === t)) return;
228
+ let o = this._s3;
229
+ if (o != null && (e(o), ++n === t)) return;
230
+ let s = this._overflow;
231
+ if (s != null) for (let r = 0, i = s.length; r < i; r++) {
232
+ let i = s[r];
233
+ if (i != null && (e(i), ++n === t)) return;
228
234
  }
229
235
  }
230
236
  forEachIndexed(e) {
231
237
  let t = this._count;
232
238
  if (t === 0) return 0;
233
239
  let n = 0, r = this._s0;
234
- r != null && (e(r), n++);
240
+ if (r != null && (e(r), ++n === t)) return n;
235
241
  let i = this._s1;
236
- i != null && (e(i), n++);
242
+ if (i != null && (e(i), ++n === t)) return n;
237
243
  let a = this._s2;
238
- a != null && (e(a), n++);
244
+ if (a != null && (e(a), ++n === t)) return n;
239
245
  let o = this._s3;
240
- if (o != null && (e(o), n++), n === t) return n;
246
+ if (o != null && (e(o), ++n === t)) return n;
241
247
  let s = this._overflow;
242
- if (s != null) for (let t = 0, r = s.length; t < r; t++) {
243
- let r = s[t];
244
- r != null && (e(r), n++);
248
+ if (s != null) for (let r = 0, i = s.length; r < i; r++) {
249
+ let i = s[r];
250
+ if (i != null && (e(i), ++n === t)) return n;
245
251
  }
246
252
  return n;
247
253
  }
248
254
  compact() {
249
255
  let e = this._overflow;
250
- if (e === null || e.length === 0) return;
251
- let t = 0;
252
- for (; t < e.length;) if (e[t] === null) {
253
- for (; e.length > t && e[e.length - 1] === null;) e.pop();
254
- e.length > t && (e[t] = e.pop(), t++);
255
- } else t++;
256
- this._freeIndices = null, e.length === 0 && (this._overflow = null);
256
+ if (e === null) return;
257
+ let t = e.length;
258
+ if (t === 0) return;
259
+ let n = 0;
260
+ for (; n < t;) if (e[n] === null) {
261
+ for (; t > n && e[t - 1] === null;) e.pop(), t--;
262
+ t > n && (e[n] = e.pop(), t--, n++);
263
+ } else n++;
264
+ this._freeIndices = null, t === 0 && (this._overflow = null);
257
265
  }
258
266
  clear() {
259
267
  this._s0 = null, this._s1 = null, this._s2 = null, this._s3 = null, this._count = 0, this._overflow !== null && (this._overflow.length = 0, this._overflow = null), this._freeIndices = null;
@@ -261,107 +269,164 @@ var d = Object.freeze([]), f = class {
261
269
  dispose() {
262
270
  this.clear();
263
271
  }
264
- }, b = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), x = /* @__PURE__ */ Symbol("AtomEffect.Type"), S = /* @__PURE__ */ Symbol("AtomEffect.NoDefaultValue"), C = {
265
- enabled: !1,
266
- warnInfiniteLoop: o.WARN_INFINITE_LOOP,
267
- warn(e, t) {},
268
- attachDebugInfo(e, t, n) {},
269
- getDebugName: (e) => e?.[b],
270
- getDebugType: (e) => e?.[x]
271
- }, ee = 1, te = () => ee++;
272
- function w(e, t, n) {
273
- if (e instanceof m) return e;
274
- let r = e instanceof Error, i = r ? e.message : String(e), a = r ? e : void 0;
275
- return new t(`${r ? e.constructor.name : "Unexpected error"} (${n}): ${i}`, a);
272
+ }, b = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), x = /* @__PURE__ */ Symbol("AtomEffect.Type"), S = /* @__PURE__ */ Symbol("AtomEffect.NoDefaultValue"), C = new class {
273
+ constructor() {
274
+ this.enabled = !1, this.warnInfiniteLoop = o.WARN_INFINITE_LOOP;
275
+ }
276
+ warn(e, t) {}
277
+ attachDebugInfo(e, t, n) {}
278
+ getDebugName(e) {
279
+ if (e != null) return e[b];
280
+ }
281
+ getDebugType(e) {
282
+ if (e != null) return e[x];
283
+ }
284
+ }(), ee = 1, w = () => ee++ | 0;
285
+ function T(e, t, n) {
286
+ return e instanceof m ? e : e instanceof Error ? new t(`${e.name || e.constructor.name || "Error"} (${n}): ${e.message}`, e) : new t(`Unexpected error (${n}): ${String(e)}`);
276
287
  }
277
- var ne = class {
288
+ var te = class {
278
289
  constructor() {
279
- this.flags = 0, this.version = 0, this._lastSeenEpoch = c.UNINITIALIZED, this._notifying = 0, this._hotIndex = -1, this._slots = null, this._deps = null, this.id = te() & l;
290
+ this.flags = 0, this.version = 0, this._lastSeenEpoch = c.UNINITIALIZED, this._notifying = 0, this._hotIndex = -1, this._slots = null, this._deps = null, this.id = w() & l;
291
+ }
292
+ get isDisposed() {
293
+ return (this.flags & r.DISPOSED) !== 0;
294
+ }
295
+ get isComputed() {
296
+ return (this.flags & r.IS_COMPUTED) !== 0;
297
+ }
298
+ get hasError() {
299
+ return !1;
280
300
  }
281
301
  subscribe(e) {
282
302
  let t = typeof e == "function";
283
- if (!t && (!e || typeof e.execute != "function")) throw w(/* @__PURE__ */ TypeError("Invalid subscriber"), m, v.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);
303
+ if (!t && (!e || typeof e.execute != "function")) throw T(/* @__PURE__ */ TypeError("Invalid subscriber"), m, v.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);
284
304
  let n = this._slots;
285
305
  n || (n = new y(), this._slots = n);
286
306
  let r = !1;
287
- if (n.forEach((n) => {
288
- (t ? n.fn === e : n.sub === e) && (r = !0);
289
- }), r) return () => {};
307
+ if (n._s0 != null && (t ? n._s0.fn === e : n._s0.sub === e)) r = !0;
308
+ else if (n._s1 != null && (t ? n._s1.fn === e : n._s1.sub === e)) r = !0;
309
+ else if (n._s2 != null && (t ? n._s2.fn === e : n._s2.sub === e)) r = !0;
310
+ else if (n._s3 != null && (t ? n._s3.fn === e : n._s3.sub === e)) r = !0;
311
+ else {
312
+ let i = n._overflow;
313
+ if (i != null) for (let n = 0, a = i.length; n < a; n++) {
314
+ let a = i[n];
315
+ if (a != null && (t ? a.fn === e : a.sub === e)) {
316
+ r = !0;
317
+ break;
318
+ }
319
+ }
320
+ }
321
+ if (r) return () => {};
290
322
  let i = new p(t ? e : void 0, t ? void 0 : e);
291
323
  return n.add(i), () => this._unsubscribe(i);
292
324
  }
293
325
  _unsubscribe(e) {
294
- if (this._slots) {
295
- if (this._notifying > 0) {
296
- this._slots.remove(e);
297
- return;
298
- }
299
- this._slots.remove(e), this._slots.compact();
300
- }
326
+ let t = this._slots;
327
+ t && (t.remove(e), this._notifying === 0 && t.compact());
301
328
  }
302
329
  subscriberCount() {
303
- return this._slots ? this._slots.size : 0;
330
+ let e = this._slots;
331
+ return e === null ? 0 : e.size;
304
332
  }
305
333
  _notifySubscribers(e, t) {
306
334
  let n = this._slots;
307
- if (!(!n || n.size === 0)) {
335
+ if (!(n === null || n.size === 0)) {
308
336
  this._notifying++;
309
337
  try {
310
- n.forEach((n) => {
311
- try {
312
- n.notify(e, t);
338
+ let r = n._s0;
339
+ if (r != null) try {
340
+ r.notify(e, t);
341
+ } catch (e) {
342
+ this._logNotifyError(e);
343
+ }
344
+ if (r = n._s1, r != null) try {
345
+ r.notify(e, t);
346
+ } catch (e) {
347
+ this._logNotifyError(e);
348
+ }
349
+ if (r = n._s2, r != null) try {
350
+ r.notify(e, t);
351
+ } catch (e) {
352
+ this._logNotifyError(e);
353
+ }
354
+ if (r = n._s3, r != null) try {
355
+ r.notify(e, t);
356
+ } catch (e) {
357
+ this._logNotifyError(e);
358
+ }
359
+ let i = n._overflow;
360
+ if (i != null) for (let n = 0, r = i.length; n < r; n++) {
361
+ let r = i[n];
362
+ if (r != null) try {
363
+ r.notify(e, t);
313
364
  } catch (e) {
314
- console.error(w(e, m, v.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED));
365
+ this._logNotifyError(e);
315
366
  }
316
- });
367
+ }
317
368
  } finally {
318
- this._notifying--, this._notifying === 0 && n.compact();
369
+ --this._notifying === 0 && n.compact();
319
370
  }
320
371
  }
321
372
  }
373
+ _logNotifyError(e) {
374
+ console.error(T(e, m, v.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED));
375
+ }
322
376
  _isDirty() {
323
377
  let e = this._deps;
324
- if (!e || e.size === 0) return !1;
325
- if (this._hotIndex !== -1) {
326
- let t = e.getAt(this._hotIndex);
327
- if (t != null && t.node.version !== t.version) return !0;
378
+ if (e === null || e.size === 0) return !1;
379
+ let t = this._hotIndex;
380
+ if (t !== -1) {
381
+ let n = e.getAt(t);
382
+ if (n != null && n.node.version !== n.version) return !0;
328
383
  }
329
384
  return !e.hasComputeds && !e.isDirtyFast() ? !1 : this._deepDirtyCheck();
330
385
  }
331
- }, re = 0, ie = () => (re = re + 1 & 1073741823 || 1, re), ae = (e) => e + 1 & 1073741823 || 1, oe = 0, se = !1, ce = 0, le = () => ce;
386
+ }, ne = 0;
387
+ function re() {
388
+ let e = ne + 1 & l;
389
+ return ne = e === 0 ? 1 : e, ne;
390
+ }
391
+ function ie(e) {
392
+ let t = e + 1 & l;
393
+ return t === 0 ? 1 : t;
394
+ }
395
+ var ae = 0, E = !1, oe = 0;
396
+ function se() {
397
+ return oe;
398
+ }
399
+ function ce() {
400
+ return E ? !1 : (E = !0, oe = re(), ae = 0, !0);
401
+ }
402
+ function le() {
403
+ E = !1;
404
+ }
332
405
  function ue() {
333
- return se ? !1 : (se = !0, ce = ie(), oe = 0, !0);
406
+ if (!E) return 0;
407
+ let e = ++ae;
408
+ if (e <= a.MAX_EXECUTIONS_PER_FLUSH) return e;
409
+ throw Error(`[atom-effect] Infinite loop detected: flush execution count exceeded ${a.MAX_EXECUTIONS_PER_FLUSH}`);
334
410
  }
335
- var de = () => {
336
- se = !1;
337
- }, fe = () => {
338
- if (!se) return 0;
339
- let e = ++oe;
340
- if (e > a.MAX_EXECUTIONS_PER_FLUSH) throw Error(`[atom-effect] Infinite loop detected: flush execution count exceeded ${a.MAX_EXECUTIONS_PER_FLUSH}`);
341
- return e;
342
- }, pe = /* @__PURE__ */ (function(e) {
343
- return e[e.IDLE = 0] = "IDLE", e[e.BATCHING = 1] = "BATCHING", e[e.FLUSHING = 2] = "FLUSHING", e;
344
- })({}), T = new class {
411
+ var de = new class {
345
412
  constructor() {
346
- this._queueBuffer = [[], []], this._bufferIndex = 0, this._size = 0, this._epoch = 0, this._isProcessing = !1, this._isBatching = !1, this._isFlushingSync = !1, this._batchDepth = 0, this._batchQueue = [], this._batchQueueSize = 0, this._maxFlushIterations = a.MAX_FLUSH_ITERATIONS, this.onOverflow = null, this._boundRunLoop = this._runLoop.bind(this);
347
- }
348
- get phase() {
349
- return this._isProcessing || this._isFlushingSync ? pe.FLUSHING : this._isBatching ? pe.BATCHING : pe.IDLE;
413
+ this._queueBuffer = [[], []], this._bufferIndex = 0, this._size = 0, this._epoch = 0, this._isProcessing = !1, this._isFlushingSync = !1, this._batchDepth = 0, this._batchQueue = [], this._batchQueueSize = 0, this._maxFlushIterations = a.MAX_FLUSH_ITERATIONS, this.onOverflow = null, this._boundRunLoop = this._runLoop.bind(this);
350
414
  }
351
415
  get queueSize() {
352
416
  return this._size;
353
417
  }
354
418
  get isBatching() {
355
- return this._isBatching;
419
+ return this._batchDepth > 0;
356
420
  }
357
421
  schedule(e) {
358
- if (e._nextEpoch !== this._epoch) {
359
- if (e._nextEpoch = this._epoch, this._isBatching || this._isFlushingSync) {
360
- this._batchQueue[this._batchQueueSize++] = e;
361
- return;
362
- }
363
- this._queueBuffer[this._bufferIndex][this._size++] = e, this._isProcessing || this._flush();
422
+ let t = this._epoch;
423
+ if (e._nextEpoch === t) return;
424
+ if (e._nextEpoch = t, this._batchDepth > 0 || this._isFlushingSync) {
425
+ this._batchQueue[this._batchQueueSize++] = e;
426
+ return;
364
427
  }
428
+ let n = this._bufferIndex, r = this._queueBuffer[n];
429
+ r[this._size++] = e, this._isProcessing || this._flush();
365
430
  }
366
431
  _flush() {
367
432
  this._isProcessing || this._size === 0 || (this._isProcessing = !0, queueMicrotask(this._boundRunLoop));
@@ -369,29 +434,30 @@ var de = () => {
369
434
  _runLoop() {
370
435
  try {
371
436
  if (this._size === 0) return;
372
- let e = ue();
373
- this._drainQueue(), e && de();
437
+ let e = ce();
438
+ this._drainQueue(), e && le();
374
439
  } finally {
375
- this._isProcessing = !1, this._size > 0 && !this._isBatching && this._flush();
440
+ this._isProcessing = !1, this._size > 0 && this._batchDepth === 0 && this._flush();
376
441
  }
377
442
  }
378
443
  _flushSync() {
379
444
  this._isFlushingSync = !0;
380
- let e = ue();
445
+ let e = ce();
381
446
  try {
382
447
  this._mergeBatchQueue(), this._drainQueue();
383
448
  } finally {
384
- this._isFlushingSync = !1, e && de();
449
+ this._isFlushingSync = !1, e && le();
385
450
  }
386
451
  }
387
452
  _mergeBatchQueue() {
388
- if (this._batchQueueSize === 0) return;
389
- let e = ++this._epoch, t = this._batchQueue, n = this._queueBuffer[this._bufferIndex], r = this._size;
390
- for (let i = 0; i < this._batchQueueSize; i++) {
391
- let a = t[i];
392
- a._nextEpoch !== e && (a._nextEpoch = e, n[r++] = a);
453
+ let e = this._batchQueueSize;
454
+ if (e === 0) return;
455
+ let t = ++this._epoch, n = this._batchQueue, r = this._bufferIndex, i = this._queueBuffer[r], a = this._size;
456
+ for (let r = 0; r < e; r++) {
457
+ let e = n[r];
458
+ e._nextEpoch !== t && (e._nextEpoch = t, i[a++] = e);
393
459
  }
394
- this._size = r, this._batchQueueSize = 0, t.length = 0;
460
+ this._size = a, this._batchQueueSize = 0, n.length = 0;
395
461
  }
396
462
  _drainQueue() {
397
463
  let e = 0;
@@ -405,33 +471,41 @@ var de = () => {
405
471
  }
406
472
  _processQueue() {
407
473
  let e = this._bufferIndex, t = this._queueBuffer[e], n = this._size;
408
- this._bufferIndex = e ^ 1, this._size = 0, this._epoch++;
409
- for (let e = 0; e < n; e++) try {
474
+ this._bufferIndex = e ^ 1, this._size = 0, this._epoch = this._epoch + 1 | 0;
475
+ for (let e = 0; e < n; e++) {
410
476
  let n = t[e];
411
- typeof n == "function" ? n() : n.execute();
412
- } catch (e) {
413
- console.error(new _("Error occurred during scheduler execution", e));
477
+ try {
478
+ typeof n == "function" ? n() : n.execute();
479
+ } catch (e) {
480
+ console.error(new _("Error occurred during scheduler execution", e));
481
+ }
414
482
  }
415
483
  t.length = 0;
416
484
  }
417
485
  _handleFlushOverflow() {
418
- let e = this._size + this._batchQueueSize;
419
- if (console.error(new _(v.SCHEDULER_FLUSH_OVERFLOW(this._maxFlushIterations, e))), this._size = 0, this._queueBuffer[this._bufferIndex].length = 0, this._batchQueueSize = 0, this.onOverflow) try {
420
- this.onOverflow(e);
486
+ let e = this._size + this._batchQueueSize, t = this._maxFlushIterations;
487
+ console.error(new _(v.SCHEDULER_FLUSH_OVERFLOW(t, e))), this._size = 0;
488
+ let n = this._bufferIndex;
489
+ this._queueBuffer[n].length = 0, this._batchQueueSize = 0;
490
+ let r = this.onOverflow;
491
+ if (r) try {
492
+ r(e);
421
493
  } catch {}
422
494
  }
423
495
  startBatch() {
424
- this._batchDepth++, this._isBatching = !0;
496
+ this._batchDepth++;
425
497
  }
426
498
  endBatch() {
427
- this._batchDepth !== 0 && --this._batchDepth === 0 && (this._flushSync(), this._isBatching = !1);
499
+ this._batchDepth !== 0 && --this._batchDepth === 0 && this._flushSync();
428
500
  }
429
501
  setMaxFlushIterations(e) {
430
502
  if (e < a.MIN_FLUSH_ITERATIONS) throw new _(`Max flush iterations must be at least ${a.MIN_FLUSH_ITERATIONS}`);
431
503
  this._maxFlushIterations = e;
432
504
  }
433
- }(), me = /* @__PURE__ */ Symbol.for("atom-effect/atom"), he = /* @__PURE__ */ Symbol.for("atom-effect/computed"), ge = /* @__PURE__ */ Symbol.for("atom-effect/effect"), _e = /* @__PURE__ */ Symbol.for("atom-effect/writable"), E = {
434
- current: null,
505
+ }(), fe = /* @__PURE__ */ Symbol.for("atom-effect/atom"), pe = /* @__PURE__ */ Symbol.for("atom-effect/computed"), me = /* @__PURE__ */ Symbol.for("atom-effect/effect"), he = /* @__PURE__ */ Symbol.for("atom-effect/writable"), D = new class {
506
+ constructor() {
507
+ this.current = null;
508
+ }
435
509
  run(e, t) {
436
510
  let n = this.current;
437
511
  this.current = e;
@@ -441,52 +515,54 @@ var de = () => {
441
515
  this.current = n;
442
516
  }
443
517
  }
444
- };
445
- function D(e) {
446
- let t = E.current;
447
- if (t === null) return e();
448
- E.current = null;
518
+ }();
519
+ function O(e) {
520
+ let t = D, n = t.current;
521
+ if (n === null) return e();
522
+ t.current = null;
449
523
  try {
450
524
  return e();
451
525
  } finally {
452
- E.current = t;
526
+ t.current = n;
453
527
  }
454
528
  }
455
- var ve = class extends ne {
529
+ var ge = class extends te {
456
530
  constructor(e, t) {
457
- super(), this[me] = !0, this[_e] = !0, this._value = e, this._pendingOldValue = void 0, t && (this.flags |= i.SYNC), C.attachDebugInfo(this, "atom", this.id);
531
+ super(), this[fe] = !0, this[he] = !0, this._value = e, t && (this.flags |= i.SYNC), C.attachDebugInfo(this, "atom", this.id);
532
+ }
533
+ get isNotificationScheduled() {
534
+ return (this.flags & i.NOTIFICATION_SCHEDULED) !== 0;
535
+ }
536
+ get isSync() {
537
+ return (this.flags & i.SYNC) !== 0;
458
538
  }
459
539
  get value() {
460
- return E.current?.addDependency(this), this._value;
540
+ return D.current?.addDependency(this), this._value;
461
541
  }
462
542
  set value(e) {
463
543
  let t = this._value;
464
544
  if (Object.is(t, e)) return;
465
- this._value = e, this.version = ae(this.version);
466
- let n = this._slots, r = this.flags;
467
- if (n == null || n.size === 0 || r & i.NOTIFICATION_SCHEDULED) return;
468
- this._pendingOldValue = t;
469
- let a = r | i.NOTIFICATION_SCHEDULED;
470
- if (this.flags = a, (a & i.SYNC) !== 0 && !T.isBatching) {
471
- this._flushNotifications();
472
- return;
473
- }
474
- T.schedule(this);
545
+ this._value = e, this.version = ie(this.version);
546
+ let n = this.flags;
547
+ if ((n & i.NOTIFICATION_SCHEDULED) !== 0) return;
548
+ let r = this._slots;
549
+ r == null || r.size === 0 || (this._pendingOldValue = t, this.flags = n | i.NOTIFICATION_SCHEDULED, (n & i.SYNC) !== 0 && !de.isBatching ? this._flushNotifications() : de.schedule(this));
475
550
  }
476
551
  execute() {
477
552
  this._flushNotifications();
478
553
  }
479
554
  _flushNotifications() {
480
555
  let e = this.flags;
481
- if (!(e & i.NOTIFICATION_SCHEDULED) || e & i.DISPOSED) return;
556
+ if ((e & (i.NOTIFICATION_SCHEDULED | i.DISPOSED)) !== i.NOTIFICATION_SCHEDULED) return;
482
557
  let t = this._pendingOldValue;
483
- this._pendingOldValue = void 0, this.flags &= ~i.NOTIFICATION_SCHEDULED, this._notifySubscribers(this._value, t);
558
+ this._pendingOldValue = void 0, this.flags = e & ~i.NOTIFICATION_SCHEDULED, this._notifySubscribers(this._value, t);
484
559
  }
485
560
  peek() {
486
561
  return this._value;
487
562
  }
488
563
  dispose() {
489
- this.flags & i.DISPOSED || (this._slots?.clear(), this.flags |= i.DISPOSED, this._value = void 0, this._pendingOldValue = void 0);
564
+ let e = this.flags;
565
+ (e & i.DISPOSED) === 0 && (this._slots?.clear(), this.flags = e | i.DISPOSED, this._value = void 0, this._pendingOldValue = void 0);
490
566
  }
491
567
  _deepDirtyCheck() {
492
568
  return !1;
@@ -495,12 +571,12 @@ var ve = class extends ne {
495
571
  this.dispose();
496
572
  }
497
573
  };
498
- function O(e, t = {}) {
499
- return new ve(e, t.sync ?? !1);
574
+ function k(e, t = {}) {
575
+ return new ge(e, t.sync ?? !1);
500
576
  }
501
- var ye = class extends y {
502
- constructor() {
503
- super(), this._map = null, this._SCAN_THRESHOLD = 32, this.hasComputeds = !1, this._depsHash = 0, this._map = null, this.hasComputeds = !1, this._depsHash = 0;
577
+ var _e = class extends y {
578
+ constructor(...e) {
579
+ super(...e), this._map = null, this._SCAN_THRESHOLD = 32, this.hasComputeds = !1, this._depsHash = 0;
504
580
  }
505
581
  prepareTracking() {
506
582
  this.hasComputeds = !1;
@@ -544,41 +620,54 @@ var ye = class extends y {
544
620
  }
545
621
  }
546
622
  }
547
- let i = t > 4 ? t : 4, a = this._overflow;
548
- if (a) for (let n = i - 4, r = a.length; n < r; n++) {
549
- let r = a[n];
550
- if (r && r.node === e && r.unsub) return r.version = e.version, this._swapGeneral(n + 4, t, r), !0;
623
+ let i = this._overflow;
624
+ if (i) {
625
+ let n = e.version, r = t > 4 ? t : 4, a = i.length;
626
+ for (let o = r - 4; o < a; o++) {
627
+ let r = i[o];
628
+ if (r && r.node === e && r.unsub) return r.version = n, this._swapGeneral(o + 4, t, r), !0;
629
+ }
551
630
  }
552
631
  return !1;
553
632
  }
554
633
  _claimViaMap(e, t) {
555
- if (this._map === null) {
556
- this._map = /* @__PURE__ */ new Map();
634
+ let n = this._map;
635
+ if (n === null) {
636
+ n = this._map = /* @__PURE__ */ new Map();
557
637
  let e = this._count;
558
- t < 4 && (t <= 0 && this._s0?.unsub && this._map.set(this._s0.node, 0), t <= 1 && this._s1?.unsub && this._map.set(this._s1.node, 1), t <= 2 && this._s2?.unsub && this._map.set(this._s2.node, 2), t <= 3 && this._s3?.unsub && this._map.set(this._s3.node, 3));
559
- let n = this._overflow;
560
- if (n && e > 4) {
561
- let e = t > 4 ? t : 4;
562
- for (let t = e - 4, r = n.length; t < r; t++) {
563
- let e = n[t];
564
- e?.unsub && this._map.set(e.node, t + 4);
638
+ if (t < 4) {
639
+ let e = this._s0;
640
+ t <= 0 && e?.unsub && n.set(e.node, 0);
641
+ let r = this._s1;
642
+ t <= 1 && r?.unsub && n.set(r.node, 1);
643
+ let i = this._s2;
644
+ t <= 2 && i?.unsub && n.set(i.node, 2);
645
+ let a = this._s3;
646
+ t <= 3 && a?.unsub && n.set(a.node, 3);
647
+ }
648
+ let r = this._overflow;
649
+ if (r && e > 4) {
650
+ let e = t > 4 ? t : 4, i = r.length;
651
+ for (let t = e - 4; t < i; t++) {
652
+ let e = r[t];
653
+ e?.unsub && n.set(e.node, t + 4);
565
654
  }
566
655
  }
567
656
  }
568
- let n = this._map.get(e);
569
- if (n === void 0 || n < t) return !1;
570
- let r = this.getAt(n);
571
- if (r == null || !r.unsub) return !1;
572
- if (r.version = e.version, n !== t) {
573
- let i = this.getAt(t);
574
- this.setAt(t, r), this.setAt(n, i), i?.unsub && this._map.set(i.node, n), this._map.set(e, t);
657
+ let r = n.get(e);
658
+ if (r === void 0 || r < t) return !1;
659
+ let i = this.getAt(r);
660
+ if (i == null || !i.unsub) return !1;
661
+ if (i.version = e.version, r !== t) {
662
+ let a;
663
+ a = t === 0 ? this._s0 : t === 1 ? this._s1 : t === 2 ? this._s2 : t === 3 ? this._s3 : this._overflow[t - 4] ?? null, this.setAt(t, i), this.setAt(r, a), a?.unsub && n.set(a.node, r), n.set(e, t);
575
664
  }
576
665
  return !0;
577
666
  }
578
667
  _swapGeneral(e, t, n) {
579
668
  if (e === t) return;
580
- let r = this.getAt(t);
581
- if (this.setAt(t, n), e === 0) this._s0 = r;
669
+ let r;
670
+ if (r = t === 0 ? this._s0 : t === 1 ? this._s1 : t === 2 ? this._s2 : t === 3 ? this._s3 : this._overflow[t - 4] ?? null, this.setAt(t, n), e === 0) this._s0 = r;
582
671
  else if (e === 1) this._s1 = r;
583
672
  else if (e === 2) this._s2 = r;
584
673
  else if (e === 3) this._s3 = r;
@@ -590,8 +679,8 @@ var ye = class extends y {
590
679
  insertNew(e, t) {
591
680
  let n = this._count;
592
681
  if (e < n) {
593
- let t = this.getAt(e);
594
- t != null && (this._addToOverflow(t), this._map !== null && t.unsub && this._map.set(t.node, this._count - 1));
682
+ let t;
683
+ t = e === 0 ? this._s0 : e === 1 ? this._s1 : e === 2 ? this._s2 : e === 3 ? this._s3 : this._overflow[e - 4] ?? null, t != null && (this._addToOverflow(t), this._map !== null && t.unsub && this._map.set(t.node, this._count - 1));
595
684
  }
596
685
  if (e === 0) this._s0 = t;
597
686
  else if (e === 1) this._s1 = t;
@@ -607,109 +696,102 @@ var ye = class extends y {
607
696
  e >= this._count || (super.truncateFrom(e), this._map !== null && (this._map.clear(), this._map = null));
608
697
  }
609
698
  seal() {
610
- let e = this._count;
611
- if (e === 0) {
612
- this._depsHash = 0;
613
- return;
614
- }
615
- let t = u.VERSION_BITS, n = 0;
616
- if (e >= 1) {
617
- let e = this._s0;
618
- n = n + (e.version << t) + e.node.id | 0;
619
- }
620
- if (e >= 2) {
621
- let e = this._s1;
622
- n = n + (e.version << t) + e.node.id | 0;
623
- }
624
- if (e >= 3) {
625
- let e = this._s2;
626
- n = n + (e.version << t) + e.node.id | 0;
627
- }
628
- if (e >= 4) {
629
- let e = this._s3;
630
- n = n + (e.version << t) + e.node.id | 0;
631
- }
632
- if (e > 4) {
633
- let e = this._overflow;
634
- for (let r = 0, i = e.length; r < i; r++) {
635
- let i = e[r];
636
- n = n + (i.version << t) + i.node.id | 0;
637
- }
638
- }
639
- this._depsHash = n;
699
+ this._depsHash = this._calculateHash(!1);
640
700
  }
641
701
  isDirtyFast() {
642
- let e = this._count;
643
- if (e === 0) return !1;
644
- let t = u.VERSION_BITS, n = 0;
645
- if (e >= 1) {
646
- let e = this._s0.node;
647
- n = n + (e.version << t) + e.id | 0;
648
- }
649
- if (e >= 2) {
650
- let e = this._s1.node;
651
- n = n + (e.version << t) + e.id | 0;
652
- }
653
- if (e >= 3) {
654
- let e = this._s2.node;
655
- n = n + (e.version << t) + e.id | 0;
656
- }
657
- if (e >= 4) {
658
- let e = this._s3.node;
659
- n = n + (e.version << t) + e.id | 0;
660
- }
661
- if (e > 4) {
662
- let e = this._overflow;
663
- for (let r = 0, i = e.length; r < i; r++) {
664
- let i = e[r].node;
665
- n = n + (i.version << t) + i.id | 0;
702
+ return this._calculateHash(!0) !== this._depsHash;
703
+ }
704
+ _calculateHash(e) {
705
+ let t = this._count;
706
+ if (t === 0) return 0;
707
+ let n = u.VERSION_BITS, r = 0, i = this._s0;
708
+ if (i != null) {
709
+ let a = i.node, o = e ? a.version : i.version;
710
+ r = r + (o << n) + a.id | 0;
711
+ let s = this._s1;
712
+ if (t > 1 && s != null) {
713
+ let i = s.node, a = e ? i.version : s.version;
714
+ r = r + (a << n) + i.id | 0;
715
+ let o = this._s2;
716
+ if (t > 2 && o != null) {
717
+ let i = o.node, a = e ? i.version : o.version;
718
+ r = r + (a << n) + i.id | 0;
719
+ let s = this._s3;
720
+ if (t > 3 && s != null) {
721
+ let t = s.node, i = e ? t.version : s.version;
722
+ r = r + (i << n) + t.id | 0;
723
+ }
724
+ }
666
725
  }
667
726
  }
668
- return n !== this._depsHash;
727
+ if (t > 4) {
728
+ let t = this._overflow;
729
+ for (let i = 0, a = t.length; i < a; i++) {
730
+ let a = t[i], o = a.node, s = e ? o.version : a.version;
731
+ r = r + (s << n) + o.id | 0;
732
+ }
733
+ }
734
+ return r;
669
735
  }
670
736
  disposeAll() {
671
- this._count > 0 && this.truncateFrom(0), this.hasComputeds = !1, this._map !== null && (this._map.clear(), this._map = null);
737
+ this._count > 0 && this.truncateFrom(0), this.hasComputeds = !1;
672
738
  }
673
739
  remove(e) {
674
740
  throw Error("remove() is strictly prohibited in DepSlotBuffer to preserve sequential cache paths.");
675
741
  }
676
742
  compact() {}
677
743
  };
678
- function be(e) {
679
- return typeof e == "object" && !!e && me in e;
744
+ function ve(e) {
745
+ return typeof e == "object" && !!e && fe in e;
680
746
  }
681
- function xe(e) {
682
- return typeof e == "object" && !!e && he in e;
747
+ function ye(e) {
748
+ return typeof e == "object" && !!e && pe in e;
683
749
  }
684
- function Se(e) {
750
+ function be(e) {
685
751
  return typeof e == "object" && !!e && typeof e.then == "function";
686
752
  }
687
- var { IDLE: k, DIRTY: A, PENDING: j, RESOLVED: M, REJECTED: N, HAS_ERROR: P, RECOMPUTING: Ce, DISPOSED: we, IS_COMPUTED: Te, FORCE_COMPUTE: Ee } = r, De = class extends ne {
753
+ var { IDLE: A, DIRTY: j, PENDING: M, RESOLVED: N, REJECTED: P, HAS_ERROR: xe, RECOMPUTING: F, DISPOSED: Se, IS_COMPUTED: I, FORCE_COMPUTE: Ce } = r, we = class extends te {
688
754
  constructor(e, t = {}) {
689
755
  if (typeof e != "function") throw new h(v.COMPUTED_MUST_BE_FUNCTION);
690
- if (super(), this[me] = !0, this[he] = !0, this._error = null, this._promiseId = 0, this._deps = new ye(), this._asyncRetryCount = 0, this._lastDriftEpoch = c.UNINITIALIZED, this._trackEpoch = c.UNINITIALIZED, this._trackCount = 0, this._value = void 0, this.flags = Te | A | k, this._equal = t.equal ?? Object.is, this._fn = e, this._defaultValue = "defaultValue" in t ? t.defaultValue : S, this._onError = t.onError ?? null, this._maxAsyncRetries = (t.maxAsyncRetries ?? s.MAX_ASYNC_RETRIES) & l, C.attachDebugInfo(this, "computed", this.id), t.lazy === !1) try {
756
+ if (super(), this[fe] = !0, this[pe] = !0, this._error = null, this._promiseId = 0, this._deps = new _e(), this._asyncRetryCount = 0, this._lastDriftEpoch = c.UNINITIALIZED, this._trackEpoch = c.UNINITIALIZED, this._trackCount = 0, this._value = void 0, this.flags = I | j | A, this._equal = t.equal ?? Object.is, this._fn = e, this._defaultValue = "defaultValue" in t ? t.defaultValue : S, this._onError = t.onError ?? null, this._maxAsyncRetries = (t.maxAsyncRetries ?? s.MAX_ASYNC_RETRIES) & l, C.attachDebugInfo(this, "computed", this.id), t.lazy === !1) try {
691
757
  this._recompute();
692
758
  } catch {}
693
759
  }
760
+ get isDirty() {
761
+ return (this.flags & j) !== 0;
762
+ }
763
+ get isRejected() {
764
+ return (this.flags & P) !== 0;
765
+ }
766
+ get isRecomputing() {
767
+ return (this.flags & F) !== 0;
768
+ }
769
+ get _hasErrorInternal() {
770
+ return (this.flags & xe) !== 0;
771
+ }
694
772
  _track() {
695
- E.current?.addDependency(this);
773
+ D.current?.addDependency(this);
696
774
  }
697
775
  get value() {
698
- this._track();
776
+ D.current?.addDependency(this);
699
777
  let e = this.flags;
700
- if ((e & (M | A | k)) === M) return this._value;
701
- if (e & we) throw new h(v.COMPUTED_DISPOSED);
702
- if (e & Ce) {
703
- if (this._defaultValue !== S) return this._defaultValue;
778
+ if ((e & (N | j | A)) === N) return this._value;
779
+ if ((e & Se) !== 0) throw new h(v.COMPUTED_DISPOSED);
780
+ if ((e & F) !== 0) {
781
+ let e = this._defaultValue;
782
+ if (e !== S) return e;
704
783
  throw new h(v.COMPUTED_CIRCULAR_DEPENDENCY);
705
784
  }
706
- if (e & (A | k) && ((e & k) === 0 && (e & Ee) === 0 && this._deps.size > 0 && !this._isDirty() ? this.flags &= ~A : this._recompute(), this.flags & M)) return this._value;
785
+ if ((e & (j | A)) !== 0) {
786
+ let t = this._deps;
787
+ if ((e & A) === 0 && (e & Ce) === 0 && t.size > 0 && !this._isDirty() ? e = this.flags &= ~j : (this._recompute(), e = this.flags), (e & N) !== 0) return this._value;
788
+ }
707
789
  let t = this._defaultValue, n = t !== S;
708
- if (this.flags & j) {
790
+ if ((e & M) !== 0) {
709
791
  if (n) return t;
710
792
  throw new h(v.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
711
793
  }
712
- if (this.flags & N) {
794
+ if ((e & P) !== 0) {
713
795
  if (n) return t;
714
796
  throw this._error;
715
797
  }
@@ -719,38 +801,35 @@ var { IDLE: k, DIRTY: A, PENDING: j, RESOLVED: M, REJECTED: N, HAS_ERROR: P, REC
719
801
  return this._value;
720
802
  }
721
803
  get state() {
722
- this._track();
804
+ D.current?.addDependency(this);
723
805
  let e = this.flags;
724
- return e & M ? t.RESOLVED : e & j ? t.PENDING : e & N ? t.REJECTED : t.IDLE;
806
+ return (e & N) === 0 ? (e & M) === 0 ? (e & P) === 0 ? t.IDLE : t.REJECTED : t.PENDING : t.RESOLVED;
725
807
  }
726
808
  get hasError() {
727
- if (this._track(), this.flags & (N | P)) return !0;
809
+ if (D.current?.addDependency(this), (this.flags & (P | xe)) !== 0) return !0;
728
810
  let e = this._deps;
729
811
  if (!e.hasComputeds) return !1;
730
812
  let t = e.size;
731
- for (let n = 0; n < t; n++) {
732
- let t = e.getAt(n);
733
- if (t != null && t.node.flags & P) return !0;
734
- }
813
+ for (let n = 0; n < t; n++) if (e.getAt(n)?.node.hasError) return !0;
735
814
  return !1;
736
815
  }
737
816
  get isValid() {
738
817
  return !this.hasError;
739
818
  }
740
819
  get errors() {
741
- this._track();
742
- let e = [];
743
- this._error && e.push(this._error);
744
- let t = this._deps;
745
- if (!t.hasComputeds) return e.length === 0 ? d : Object.freeze(e);
746
- let n = t.size;
747
- for (let r = 0; r < n; r++) {
748
- let n = t.getAt(r);
749
- if (n == null) continue;
750
- let i = n.node;
751
- i.flags & P && this._collectErrorsFromDep(i, e);
820
+ D.current?.addDependency(this);
821
+ let e = this._error, t = this._deps;
822
+ if (!t.hasComputeds) return e == null ? d : Object.freeze([e]);
823
+ let n = [];
824
+ e != null && n.push(e);
825
+ let r = t.size;
826
+ for (let e = 0; e < r; e++) {
827
+ let r = t.getAt(e);
828
+ if (r == null) continue;
829
+ let i = r.node;
830
+ (i.flags & I) !== 0 && i.hasError && this._collectErrorsFromDep(i, n);
752
831
  }
753
- return e.length === 0 ? d : Object.freeze(e);
832
+ return n.length === 0 ? d : Object.freeze(n);
754
833
  }
755
834
  _collectErrorsFromDep(e, t) {
756
835
  let n = e.errors, r = n.length;
@@ -760,57 +839,58 @@ var { IDLE: k, DIRTY: A, PENDING: j, RESOLVED: M, REJECTED: N, HAS_ERROR: P, REC
760
839
  }
761
840
  }
762
841
  get lastError() {
763
- return this._track(), this._error;
842
+ return D.current?.addDependency(this), this._error;
764
843
  }
765
844
  get isPending() {
766
- return this._track(), (this.flags & j) !== 0;
845
+ return D.current?.addDependency(this), (this.flags & M) !== 0;
767
846
  }
768
847
  get isResolved() {
769
- return this._track(), (this.flags & M) !== 0;
848
+ return D.current?.addDependency(this), (this.flags & N) !== 0;
770
849
  }
771
850
  invalidate() {
772
- this.flags |= Ee, this._markDirty();
851
+ this.flags |= Ce, this._markDirty();
773
852
  }
774
853
  dispose() {
775
- this.flags & we || (this._deps.disposeAll(), this._slots?.clear(), this.flags = we | A | k, this._error = null, this._value = void 0, this._hotIndex = -1);
854
+ (this.flags & Se) === 0 && (this._deps.disposeAll(), this._slots != null && this._slots.clear(), this.flags = Se | j | A, this._error = null, this._value = void 0, this._hotIndex = -1);
776
855
  }
777
856
  [Symbol.dispose]() {
778
857
  this.dispose();
779
858
  }
780
859
  addDependency(e) {
781
- if (e._lastSeenEpoch === this._trackEpoch) return;
782
- e._lastSeenEpoch = this._trackEpoch;
783
- let t = this._trackCount, n = this._deps.getAt(t);
784
- if (n != null && n.node === e) n.version = e.version;
785
- else if (!this._deps.claimExisting(e, t)) {
786
- let n = new f(e, e.version, e.subscribe(this));
787
- this._deps.insertNew(t, n);
860
+ let t = this._trackEpoch;
861
+ if (e._lastSeenEpoch === t) return;
862
+ e._lastSeenEpoch = t;
863
+ let n = this._trackCount++, r = this._deps, i = r.getAt(n);
864
+ if (i != null && i.node === e) i.version = e.version;
865
+ else if (!r.claimExisting(e, n)) {
866
+ let t = new f(e, e.version, e.subscribe(this));
867
+ r.insertNew(n, t);
788
868
  }
789
- e.flags & Te && (this._deps.hasComputeds = !0), this._trackCount = t + 1;
869
+ (e.flags & I) !== 0 && (r.hasComputeds = !0);
790
870
  }
791
871
  _recompute() {
792
- if (this.flags & Ce) return;
793
- this.flags = (this.flags | Ce) & ~Ee, this._trackEpoch = ie(), this._trackCount = 0, this._deps.prepareTracking(), this._hotIndex = -1;
872
+ if (this.isRecomputing) return;
873
+ this.flags = (this.flags | F) & ~Ce, this._trackEpoch = re(), this._trackCount = 0, this._deps.prepareTracking(), this._hotIndex = -1;
794
874
  let e = !1;
795
875
  try {
796
- let t = E.run(this, this._fn);
797
- this._deps.truncateFrom(this._trackCount), this._deps.seal(), e = !0, Se(t) ? this._handleAsyncComputation(t) : this._finalizeResolution(t);
876
+ let t = D.run(this, this._fn);
877
+ this._deps.truncateFrom(this._trackCount), this._deps.seal(), e = !0, be(t) ? this._handleAsyncComputation(t) : this._finalizeResolution(t);
798
878
  } catch (t) {
799
879
  if (!e) try {
800
880
  this._deps.truncateFrom(this._trackCount);
801
881
  } catch {}
802
882
  this._handleError(t, v.COMPUTED_COMPUTATION_FAILED, !0);
803
883
  } finally {
804
- this._trackEpoch = c.UNINITIALIZED, this._trackCount = 0, this.flags &= ~Ce;
884
+ this._trackEpoch = c.UNINITIALIZED, this._trackCount = 0, this.flags &= ~F;
805
885
  }
806
886
  }
807
887
  _handleAsyncComputation(e) {
808
- this.flags = (this.flags | j) & ~(k | A | M | N), this._notifySubscribers(void 0, void 0), this._asyncRetryCount = 0, this._promiseId = (this._promiseId + 1) % s.MAX_PROMISE_ID;
888
+ this.flags = (this.flags | M) & ~(A | j | N | P), this._notifySubscribers(void 0, void 0), this._asyncRetryCount = 0, this._promiseId = (this._promiseId + 1) % s.MAX_PROMISE_ID;
809
889
  let t = this._promiseId;
810
890
  e.then((e) => {
811
891
  if (t === this._promiseId) {
812
892
  if (this._isDirty()) {
813
- let e = le();
893
+ let e = se();
814
894
  return this._lastDriftEpoch !== e && (this._lastDriftEpoch = e, this._asyncRetryCount = 0), this._asyncRetryCount++ < this._maxAsyncRetries ? this._markDirty() : this._handleError(new h(`Async drift threshold exceeded after ${this._maxAsyncRetries} retries.`), v.COMPUTED_ASYNC_COMPUTATION_FAILED);
815
895
  }
816
896
  this._finalizeResolution(e), this._notifySubscribers(e, void 0);
@@ -818,8 +898,8 @@ var { IDLE: k, DIRTY: A, PENDING: j, RESOLVED: M, REJECTED: N, HAS_ERROR: P, REC
818
898
  }, (e) => t === this._promiseId && this._handleError(e, v.COMPUTED_ASYNC_COMPUTATION_FAILED));
819
899
  }
820
900
  _handleError(e, t, n = !1) {
821
- let r = w(e, h, t);
822
- if (!n && !(this.flags & N) && (this.version = ae(this.version)), this._error = r, this.flags = this.flags & ~(k | A | j | M) | N | P, this._onError) try {
901
+ let r = T(e, h, t);
902
+ if (!n && !this.isRejected && (this.version = ie(this.version)), this._error = r, this.flags = this.flags & ~(A | j | M | N) | P | xe, this._onError) try {
823
903
  this._onError(r);
824
904
  } catch (e) {
825
905
  console.error(v.CALLBACK_ERROR_IN_ERROR_HANDLER, e);
@@ -828,62 +908,79 @@ var { IDLE: k, DIRTY: A, PENDING: j, RESOLVED: M, REJECTED: N, HAS_ERROR: P, REC
828
908
  this._notifySubscribers(void 0, void 0);
829
909
  }
830
910
  _finalizeResolution(e) {
831
- (!(this.flags & M) || !this._equal(this._value, e)) && (this.version = ae(this.version)), this._value = e, this._error = null, this.flags = (this.flags | M) & ~(k | A | j | N | P);
911
+ let t = this.flags;
912
+ ((t & N) === 0 || !this._equal(this._value, e)) && (this.version = ie(this.version)), this._value = e, this._error = null, this.flags = (t | N) & ~(A | j | M | P | xe);
832
913
  }
833
914
  execute() {
834
915
  this._markDirty();
835
916
  }
836
917
  _markDirty() {
837
- this.flags & (Ce | A) || (this.flags |= A, this._notifySubscribers(void 0, void 0));
918
+ let e = this.flags;
919
+ (e & (F | j)) === 0 && (this.flags = e | j, this._notifySubscribers(void 0, void 0));
838
920
  }
839
921
  _isDirty() {
840
922
  let e = this._deps;
841
923
  return e.hasComputeds ? this._deepDirtyCheck() : e.isDirtyFast();
842
924
  }
843
925
  _deepDirtyCheck() {
844
- let e = this._deps, t = E.current;
845
- E.current = null;
926
+ let e = this._deps, t = D.current;
927
+ D.current = null;
846
928
  try {
847
929
  let t = e.size;
848
930
  for (let n = 0; n < t; n++) {
849
931
  let t = e.getAt(n);
850
932
  if (t == null) continue;
851
933
  let r = t.node;
852
- if (r.flags & Te) try {
934
+ if ((r.flags & I) !== 0) try {
853
935
  r.value;
854
936
  } catch {}
855
937
  if (r.version !== t.version) return this._hotIndex = n, !0;
856
938
  }
857
939
  return this._hotIndex = -1, !1;
858
940
  } finally {
859
- E.current = t;
941
+ D.current = t;
860
942
  }
861
943
  }
862
944
  };
863
- function F(e, t = {}) {
864
- return new De(e, t);
945
+ function L(e, t = {}) {
946
+ return new we(e, t);
865
947
  }
866
- var Oe = class extends ne {
948
+ var Te = class extends te {
867
949
  constructor(e, t = {}) {
868
- super(), this[ge] = !0, this._cleanup = null, this._deps = new ye(), this._currentEpoch = c.UNINITIALIZED, this._lastFlushEpoch = c.UNINITIALIZED, this._fn = e, this._onError = t.onError ?? null, this._sync = t.sync ?? !1, this._maxExecutions = t.maxExecutionsPerSecond ?? a.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = t.maxExecutionsPerFlush ?? a.MAX_EXECUTIONS_PER_EFFECT, this._cleanup = null, this._deps = new ye(), this._currentEpoch = c.UNINITIALIZED, this._lastFlushEpoch = c.UNINITIALIZED, this._executionsInEpoch = 0, this._executionCount = 0, this._windowStart = 0, this._windowCount = 0, this._execId = 0, this._trackCount = 0, this._sync ? this._notifyCallback = () => this.execute() : this._notifyCallback = () => T.schedule(this), C.attachDebugInfo(this, "effect", this.id);
950
+ super(), this[me] = !0, this._cleanup = null, this._deps = new _e(), this._currentEpoch = c.UNINITIALIZED, this._lastFlushEpoch = c.UNINITIALIZED, this._fn = e, this._onError = t.onError ?? null, this._sync = t.sync ?? !1, this._maxExecutions = t.maxExecutionsPerSecond ?? a.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = t.maxExecutionsPerFlush ?? a.MAX_EXECUTIONS_PER_EFFECT, this._executionsInEpoch = 0, this._executionCount = 0, this._windowStart = 0, this._windowCount = 0, this._execId = 0, this._trackCount = 0, this._sync ? this._notifyCallback = () => this.execute() : this._notifyCallback = () => de.schedule(this), C.attachDebugInfo(this, "effect", this.id);
869
951
  }
870
952
  run() {
871
- if (this.flags & n.DISPOSED) throw new g(v.EFFECT_DISPOSED);
953
+ if (this.isDisposed) throw new g(v.EFFECT_DISPOSED);
872
954
  this.execute(!0);
873
955
  }
874
956
  dispose() {
875
- this.flags & n.DISPOSED || (this.flags |= n.DISPOSED, this._execCleanup(), this._deps?.disposeAll());
957
+ this.isDisposed || (this.flags |= n.DISPOSED, this._execCleanup(), this._deps?.disposeAll());
876
958
  }
877
959
  [Symbol.dispose]() {
878
960
  this.dispose();
879
961
  }
880
962
  addDependency(e) {
881
- if (!(this.flags & n.EXECUTING)) return;
963
+ if ((this.flags & n.EXECUTING) === 0) return;
882
964
  let t = this._currentEpoch;
883
965
  if (e._lastSeenEpoch === t) return;
884
966
  e._lastSeenEpoch = t;
885
- let i = this._trackCount, a = this._deps, o;
886
- o = i === 0 ? a._s0 : i === 1 ? a._s1 : i === 2 ? a._s2 : i === 3 ? a._s3 : a.getAt(i), o != null && o.node === e ? o.version = e.version : a.claimExisting(e, i) || this._insertNewDependency(e, i), e.flags & r.IS_COMPUTED && (a.hasComputeds = !0), this._trackCount = i + 1;
967
+ let r = this._trackCount++, i = this._deps, a;
968
+ switch (r) {
969
+ case 0:
970
+ a = i._s0;
971
+ break;
972
+ case 1:
973
+ a = i._s1;
974
+ break;
975
+ case 2:
976
+ a = i._s2;
977
+ break;
978
+ case 3:
979
+ a = i._s3;
980
+ break;
981
+ default: a = i.getAt(r);
982
+ }
983
+ a != null && a.node === e ? a.version = e.version : i.claimExisting(e, r) || this._insertNewDependency(e, r), e.isComputed && (i.hasComputeds = !0);
887
984
  }
888
985
  _insertNewDependency(e, t) {
889
986
  let n;
@@ -891,7 +988,7 @@ var Oe = class extends ne {
891
988
  let t = e.subscribe(this._notifyCallback);
892
989
  n = new f(e, e.version, t);
893
990
  } catch (t) {
894
- let r = w(t, g, v.EFFECT_EXECUTION_FAILED);
991
+ let r = T(t, g, v.EFFECT_EXECUTION_FAILED);
895
992
  if (console.error(r), this._onError) try {
896
993
  this._onError(r);
897
994
  } catch {}
@@ -900,17 +997,18 @@ var Oe = class extends ne {
900
997
  this._deps.insertNew(t, n);
901
998
  }
902
999
  execute(e = !1) {
903
- if (this.flags & (n.DISPOSED | n.EXECUTING)) return;
904
- let t = this._deps;
905
- if (!e && t.size > 0 && !this._isDirty()) return;
906
- this._checkInfiniteLoops(), this.flags |= n.EXECUTING, this._execCleanup(), this._currentEpoch = ie(), this._trackCount = 0, t.prepareTracking(), this._hotIndex = -1;
907
- let r = !1;
1000
+ let t = this.flags;
1001
+ if ((t & (n.DISPOSED | n.EXECUTING)) !== 0) return;
1002
+ let r = this._deps;
1003
+ if (!e && r.size > 0 && !this._isDirty()) return;
1004
+ this._checkInfiniteLoops(), this.flags = t | n.EXECUTING, this._execCleanup(), this._currentEpoch = re(), this._trackCount = 0, r.prepareTracking(), this._hotIndex = -1;
1005
+ let i = !1;
908
1006
  try {
909
- let e = E.run(this, this._fn);
910
- t.truncateFrom(this._trackCount), t.seal(), r = !0, Se(e) ? this._handleAsyncResult(e) : this._cleanup = typeof e == "function" ? e : null;
1007
+ let e = D.run(this, this._fn);
1008
+ r.truncateFrom(this._trackCount), r.seal(), i = !0, be(e) ? this._handleAsyncResult(e) : this._cleanup = typeof e == "function" ? e : null;
911
1009
  } catch (e) {
912
- if (!r) try {
913
- t.truncateFrom(this._trackCount);
1010
+ if (!i) try {
1011
+ r.truncateFrom(this._trackCount);
914
1012
  } catch {}
915
1013
  this._handleExecutionError(e), this._cleanup = null;
916
1014
  } finally {
@@ -924,7 +1022,7 @@ var Oe = class extends ne {
924
1022
  _handleAsyncResult(e) {
925
1023
  let t = ++this._execId;
926
1024
  e.then((e) => {
927
- if (t !== this._execId || this.flags & n.DISPOSED) {
1025
+ if (t !== this._execId || this.isDisposed) {
928
1026
  if (typeof e == "function") try {
929
1027
  e();
930
1028
  } catch (e) {
@@ -936,20 +1034,20 @@ var Oe = class extends ne {
936
1034
  }, (e) => t === this._execId && this._handleExecutionError(e));
937
1035
  }
938
1036
  _deepDirtyCheck() {
939
- let e = E.current;
940
- E.current = null;
1037
+ let e = D.current;
1038
+ D.current = null;
941
1039
  let t = this._deps;
942
1040
  try {
943
1041
  let e = t.size;
944
1042
  for (let n = 0; n < e; n++) {
945
1043
  let e = t.getAt(n);
946
1044
  if (e == null) continue;
947
- let i = e.node;
948
- if (i.flags & r.IS_COMPUTED && this._tryPullComputed(i), i.version !== e.version) return this._hotIndex = n, !0;
1045
+ let r = e.node;
1046
+ if (r.isComputed && this._tryPullComputed(r), r.version !== e.version) return this._hotIndex = n, !0;
949
1047
  }
950
1048
  return !1;
951
1049
  } finally {
952
- E.current = e;
1050
+ D.current = e;
953
1051
  }
954
1052
  }
955
1053
  _tryPullComputed(e) {
@@ -958,18 +1056,19 @@ var Oe = class extends ne {
958
1056
  } catch {}
959
1057
  }
960
1058
  _execCleanup() {
961
- if (this._cleanup) {
1059
+ let e = this._cleanup;
1060
+ if (e != null) {
1061
+ this._cleanup = null;
962
1062
  try {
963
- this._cleanup();
1063
+ e();
964
1064
  } catch (e) {
965
1065
  this._handleExecutionError(e, v.EFFECT_CLEANUP_FAILED);
966
1066
  }
967
- this._cleanup = null;
968
1067
  }
969
1068
  }
970
1069
  _checkInfiniteLoops() {
971
- let e = le();
972
- this._lastFlushEpoch !== e && (this._lastFlushEpoch = e, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), fe() > a.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++;
1070
+ let e = se();
1071
+ this._lastFlushEpoch !== e && (this._lastFlushEpoch = e, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), ue() > a.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++;
973
1072
  }
974
1073
  _checkFrequencyLimit() {
975
1074
  if (!Number.isFinite(this._maxExecutions)) return;
@@ -983,9 +1082,6 @@ var Oe = class extends ne {
983
1082
  throw this.dispose(), this._handleExecutionError(e), e;
984
1083
  }
985
1084
  }
986
- get isDisposed() {
987
- return (this.flags & n.DISPOSED) !== 0;
988
- }
989
1085
  get executionCount() {
990
1086
  return this._executionCount;
991
1087
  }
@@ -993,89 +1089,86 @@ var Oe = class extends ne {
993
1089
  return (this.flags & n.EXECUTING) !== 0;
994
1090
  }
995
1091
  _throwInfiniteLoopError(e) {
996
- let t = new g(`Infinite loop detected (${e}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${oe}`);
1092
+ let t = new g(`Infinite loop detected (${e}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${ae}`);
997
1093
  throw this.dispose(), console.error(t), t;
998
1094
  }
999
1095
  _handleExecutionError(e, t = v.EFFECT_EXECUTION_FAILED) {
1000
- let n = w(e, g, t);
1096
+ let n = T(e, g, t);
1001
1097
  if (console.error(n), this._onError) try {
1002
1098
  this._onError(n);
1003
1099
  } catch (e) {
1004
- console.error(w(e, g, v.CALLBACK_ERROR_IN_ERROR_HANDLER));
1100
+ console.error(T(e, g, v.CALLBACK_ERROR_IN_ERROR_HANDLER));
1005
1101
  }
1006
1102
  }
1007
1103
  };
1008
- function I(e, t = {}) {
1104
+ function R(e, t = {}) {
1009
1105
  if (typeof e != "function") throw new g(v.EFFECT_MUST_BE_FUNCTION);
1010
- let n = new Oe(e, t);
1106
+ let n = new Te(e, t);
1011
1107
  return n.execute(), n;
1012
1108
  }
1013
- function ke(e) {
1109
+ function Ee(e) {
1014
1110
  if (typeof e != "function") throw TypeError(v.BATCH_CALLBACK_MUST_BE_FUNCTION);
1015
- T.startBatch();
1111
+ let t = de;
1112
+ t.startBatch();
1016
1113
  try {
1017
1114
  return e();
1018
1115
  } finally {
1019
- T.endBatch();
1116
+ t.endBatch();
1020
1117
  }
1021
1118
  }
1022
1119
  //#endregion
1023
1120
  //#region src/utils/index.ts
1024
- function L(e) {
1025
- return be(e);
1026
- }
1027
- function Ae(e) {
1028
- return !!e && typeof e.then == "function";
1029
- }
1030
- function R(e) {
1031
- let t = e.tagName.toLowerCase();
1032
- if (e.id) return `${t}#${e.id}`;
1033
- let n = e.classList, r = n.length;
1034
- if (r === 0) return t;
1035
- let i = t;
1036
- for (let e = 0; e < r; e++) i += `.${n[e]}`;
1037
- return i;
1121
+ var z = (e) => ve(e), De = (e) => typeof e == "object" && !!e && typeof e.then == "function";
1122
+ function B(e) {
1123
+ let t = e.localName, n = e.id;
1124
+ if (n) return `${t}#${n}`;
1125
+ let r = e.className;
1126
+ if (typeof r == "string") {
1127
+ let e = r.trim();
1128
+ if (e) return `${t}.${e.replace(/\s+/g, ".")}`;
1129
+ }
1130
+ return t;
1038
1131
  }
1039
- var z = Object.prototype.hasOwnProperty;
1040
- function je(e, t) {
1132
+ var V = Object.prototype.hasOwnProperty;
1133
+ function Oe(e, t) {
1041
1134
  if (e === t) return !0;
1042
- if (e === null || t === null || typeof e != "object" || typeof t != "object") return !1;
1043
- let n = Object.keys(e), r = Object.keys(t);
1044
- if (n.length !== r.length) return !1;
1045
- let i = e, a = t;
1046
- for (let e = 0; e < n.length; e++) {
1047
- let t = n[e];
1048
- if (!z.call(a, t) || i[t] !== a[t]) return !1;
1049
- }
1050
- return !0;
1135
+ if (typeof e != "object" || !e || typeof t != "object" || !t) return !1;
1136
+ let n = e, r = t, i = 0;
1137
+ for (let e in n) if (V.call(n, e)) {
1138
+ if (!V.call(r, e) || n[e] !== r[e]) return !1;
1139
+ i++;
1140
+ }
1141
+ let a = 0;
1142
+ for (let e in r) V.call(r, e) && a++;
1143
+ return i === a;
1051
1144
  }
1052
1145
  //#endregion
1053
1146
  //#region src/constants.ts
1054
- var B = {
1147
+ var H = {
1055
1148
  ROUTE: "[atom-route]",
1056
1149
  BINDING: "[atom-binding]",
1057
1150
  LIST: "[atom-list]",
1058
1151
  MOUNT: "[atom-mount]"
1059
- }, V = Object.freeze({
1152
+ }, U = Object.freeze({
1060
1153
  mode: "hash",
1061
1154
  basePath: "",
1062
1155
  autoBindLinks: !1,
1063
1156
  activeClass: "active"
1064
- }), Me = {
1157
+ }), ke = {
1065
1158
  EVENT: "input",
1066
1159
  DEBOUNCE: 0
1067
- }, Ne = { HIGHLIGHT_DURATION_MS: 500 }, Pe = new Set([
1160
+ }, Ae = { HIGHLIGHT_DURATION_MS: 500 }, je = new Set([
1068
1161
  "input",
1069
1162
  "select",
1070
1163
  "textarea"
1071
- ]), Fe = new Set([
1164
+ ]), Me = new Set([
1072
1165
  "innerHTML",
1073
1166
  "outerHTML",
1074
1167
  "srcdoc",
1075
1168
  "__proto__",
1076
1169
  "constructor",
1077
1170
  "prototype"
1078
- ]), H = {
1171
+ ]), W = {
1079
1172
  ROUTE: {
1080
1173
  NOT_FOUND: (e) => `Route "${e}" not found and no notFound route configured`,
1081
1174
  TEMPLATE_NOT_FOUND: (e) => `Template "${e}" not found`,
@@ -1103,78 +1196,71 @@ var B = {
1103
1196
  CLEANUP_ERROR: (e) => `Cleanup error${e ? ` in component <${e}>` : ""}`
1104
1197
  },
1105
1198
  CORE: { EFFECT_DISPOSE_ERROR: (e) => `Effect dispose error${e ? `: ${e}` : ""}` }
1106
- }, Ie = `${Ne.HIGHLIGHT_DURATION_MS / 1e3}s`;
1107
- function Le() {
1108
- if (typeof window < "u") {
1109
- let e = window.__ATOM_DEBUG__;
1110
- if (typeof e == "boolean") return e;
1111
- }
1199
+ }, Ne = typeof window < "u", Pe = `${Ae.HIGHLIGHT_DURATION_MS / 1e3}s`;
1200
+ function Fe() {
1201
+ if (Ne && window.__ATOM_DEBUG__ === !0) return !0;
1112
1202
  try {
1113
1203
  if (globalThis.process?.env?.VITE_ATOM_DEBUG === "true") return !0;
1114
1204
  } catch {}
1115
1205
  return !1;
1116
1206
  }
1117
- var Re = Le(), U = {
1207
+ var Ie = Fe(), G = new class {
1118
1208
  get enabled() {
1119
- if (typeof window < "u") {
1120
- let e = window.__ATOM_DEBUG__;
1121
- if (typeof e == "boolean") return e;
1122
- }
1123
- return Re;
1124
- },
1209
+ return Ne && window.__ATOM_DEBUG__ === !0 || Ie;
1210
+ }
1125
1211
  set enabled(e) {
1126
- Re = e;
1127
- },
1212
+ Ie = e;
1213
+ }
1128
1214
  log(e, ...t) {
1129
- this.enabled && console.log(`${e}`, ...t);
1130
- },
1215
+ this.enabled && console.log(e, ...t);
1216
+ }
1131
1217
  atomChanged(e, t, n, r) {
1132
1218
  this.enabled && console.log(`${e} Atom "${t ?? "anonymous"}" changed:`, n, "→", r);
1133
- },
1219
+ }
1134
1220
  domUpdated(e, t, n, r) {
1135
1221
  if (!this.enabled) return;
1136
1222
  let i = t instanceof Element ? t : t[0];
1137
- i && (console.log(`${e} DOM updated: ${R(i)}.${n} =`, r), Ge(i));
1138
- },
1223
+ i?.isConnected && (console.log(`${e} DOM updated: ${B(i)}.${n} =`, r), Ue(i));
1224
+ }
1139
1225
  cleanup(e, t) {
1140
1226
  this.enabled && console.log(`${e} Cleanup: ${t}`);
1141
- },
1227
+ }
1142
1228
  warn(e, t, ...n) {
1143
1229
  console.warn(`${e} ${t}`, ...n);
1144
- },
1230
+ }
1145
1231
  error(e, t, n) {
1146
1232
  console.error(`${e} ${t}`, n);
1147
1233
  }
1148
- }, ze = "atom-debug-highlight", Be = "data-atom-debug", Ve;
1149
- function He() {
1150
- if ((Ve instanceof HTMLStyleElement ? Ve : Ve?.deref())?.isConnected || document.querySelector(`style[${Be}]`)) return;
1151
- let e = document.createElement("style");
1152
- e.setAttribute(Be, ""), e.textContent = `.${ze}{outline:2px solid rgba(255,68,68,0.8);outline-offset:1px;transition:outline ${Ie} ease-out}`, document.head.appendChild(e), Ve = typeof WeakRef < "u" ? new WeakRef(e) : e;
1234
+ }(), Le = "atom-debug-highlight", Re = "data-atom-debug", ze = !1;
1235
+ function Be() {
1236
+ if (ze || !Ne) return;
1237
+ if (document.querySelector(`style[${Re}]`)) {
1238
+ ze = !0;
1239
+ return;
1240
+ }
1241
+ let e = Object.assign(document.createElement("style"), { textContent: `.${Le}{outline:2px solid rgba(255,68,68,0.8);outline-offset:1px;transition:outline ${Pe} ease-out}` });
1242
+ e.setAttribute(Re, ""), document.head.appendChild(e), ze = !0;
1153
1243
  }
1154
- var Ue = /* @__PURE__ */ new WeakMap(), We = /* @__PURE__ */ new WeakMap();
1155
- function Ge(e) {
1156
- if (!U.enabled || !e.isConnected) return;
1157
- He();
1158
- let t = We.get(e);
1159
- t !== void 0 && cancelAnimationFrame(t);
1160
- let n = Ue.get(e);
1161
- n !== void 0 && clearTimeout(n);
1162
- let r = requestAnimationFrame(() => {
1163
- We.delete(e), e.isConnected && (e.classList.add(ze), Ue.set(e, setTimeout(() => {
1164
- e.isConnected && e.classList.remove(ze), Ue.delete(e);
1165
- }, Ne.HIGHLIGHT_DURATION_MS)));
1166
- });
1167
- We.set(e, r);
1244
+ var Ve = /* @__PURE__ */ new WeakMap(), He = /* @__PURE__ */ new WeakMap();
1245
+ function Ue(e) {
1246
+ if (!G.enabled || !e.isConnected) return;
1247
+ Be();
1248
+ let t = He.get(e), n = Ve.get(e);
1249
+ t !== void 0 && cancelAnimationFrame(t), n !== void 0 && (clearTimeout(n), Ve.delete(e)), He.set(e, requestAnimationFrame(() => {
1250
+ He.delete(e), e.isConnected && (e.classList.add(Le), Ve.set(e, setTimeout(() => {
1251
+ e.isConnected && e.classList.remove(Le), Ve.delete(e);
1252
+ }, Ae.HIGHLIGHT_DURATION_MS)));
1253
+ }));
1168
1254
  }
1169
1255
  //#endregion
1170
1256
  //#region src/core/lens.ts
1171
- var Ke = Symbol.for("atom-effect/atom"), qe = Symbol.for("atom-effect/writable");
1172
- function Je(e, t, n, r) {
1257
+ var We = Symbol.for("atom-effect/atom"), Ge = Symbol.for("atom-effect/writable");
1258
+ function Ke(e, t, n, r) {
1173
1259
  if (n === t.length) return r;
1174
- let i = t[n], a = e && typeof e == "object" ? e : {}, o = a[i], s = Je(o, t, n + 1, r);
1260
+ let i = t[n], a = typeof e == "object" && e ? e : {}, o = a[i], s = Ke(o, t, n + 1, r);
1175
1261
  if (Object.is(o, s)) return e;
1176
1262
  if (Array.isArray(a)) {
1177
- let e = [...a], t = Number.parseInt(i, 10);
1263
+ let e = a.slice(), t = Number.parseInt(i, 10);
1178
1264
  return Number.isNaN(t) ? e[i] = s : e[t] = s, e;
1179
1265
  }
1180
1266
  return {
@@ -1182,87 +1268,75 @@ function Je(e, t, n, r) {
1182
1268
  [i]: s
1183
1269
  };
1184
1270
  }
1185
- function W(e, t) {
1186
- let n = e;
1187
- for (let e = 0, r = t.length; e < r && n != null; e++) n = n[t[e]];
1271
+ function K(e, t) {
1272
+ let n = e, r = t.length;
1273
+ for (let e = 0; e < r; e++) {
1274
+ if (n == null) return;
1275
+ n = n[t[e]];
1276
+ }
1188
1277
  return n;
1189
1278
  }
1190
- function Ye(e, t) {
1279
+ function qe(e, t) {
1191
1280
  let n = t.includes(".") ? t.split(".") : [t], r = /* @__PURE__ */ new Set(), i = () => {
1192
- for (let e of r) e();
1193
- r.clear();
1281
+ r.forEach((e) => e()), r.clear();
1194
1282
  };
1195
1283
  return {
1196
1284
  get value() {
1197
- return W(e.value, n);
1285
+ return K(e.value, n);
1198
1286
  },
1199
1287
  set value(t) {
1200
- let r = e.peek(), i = Je(r, n, 0, t);
1288
+ let r = e.peek(), i = Ke(r, n, 0, t);
1201
1289
  i !== r && (e.value = i);
1202
1290
  },
1203
- peek() {
1204
- return W(e.peek(), n);
1205
- },
1291
+ peek: () => K(e.peek(), n),
1206
1292
  subscribe(t) {
1207
1293
  let i = e.subscribe((e, r) => {
1208
- let i = W(e, n), a = W(r, n);
1294
+ let i = K(e, n), a = K(r, n);
1209
1295
  Object.is(i, a) || t(i, a);
1210
1296
  });
1211
1297
  return r.add(i), () => {
1212
1298
  i(), r.delete(i);
1213
1299
  };
1214
1300
  },
1215
- subscriberCount() {
1216
- return r.size;
1217
- },
1301
+ subscriberCount: () => r.size,
1218
1302
  dispose: i,
1219
1303
  [Symbol.dispose]: i,
1220
- [Ke]: !0,
1221
- [qe]: !0
1304
+ [We]: !0,
1305
+ [Ge]: !0
1222
1306
  };
1223
1307
  }
1224
- function Xe(e, t) {
1225
- return Ye(e, t);
1226
- }
1227
- function Ze(e) {
1228
- return (t) => Ye(e, t);
1229
- }
1308
+ var Je = (e, t) => qe(e, t), Ye = (e) => (t) => qe(e, t);
1230
1309
  //#endregion
1231
1310
  //#region src/core/namespace.ts
1232
- function Qe(e, t) {
1233
- return O(e, t);
1311
+ function Xe(e, t) {
1312
+ return k(e, t);
1234
1313
  }
1235
- Object.defineProperty(Qe, "debug", {
1314
+ Object.defineProperty(Xe, "debug", {
1236
1315
  enumerable: !0,
1237
1316
  configurable: !0,
1238
- get() {
1239
- return U.enabled;
1240
- },
1241
- set(e) {
1242
- U.enabled = e;
1317
+ get: () => G.enabled,
1318
+ set: (e) => {
1319
+ G.enabled = e;
1243
1320
  }
1244
1321
  });
1245
- function $e() {
1246
- return new Promise((e) => setTimeout(e, 0));
1247
- }
1248
- var et = {
1249
- atom: Qe,
1250
- computed: F,
1251
- effect: I,
1252
- batch: ke,
1253
- untracked: D,
1254
- isAtom: be,
1255
- isComputed: xe,
1256
- isReactive: L,
1257
- nextTick: $e,
1258
- atomLens: Ye,
1259
- composeLens: Xe,
1260
- lensFor: Ze
1261
- };
1262
- e.extend(et);
1322
+ var Ze = () => Promise.resolve();
1323
+ e.extend({
1324
+ atom: Xe,
1325
+ computed: L,
1326
+ effect: R,
1327
+ batch: Ee,
1328
+ untracked: O,
1329
+ isAtom: ve,
1330
+ isComputed: ye,
1331
+ isReactive: z,
1332
+ nextTick: Ze,
1333
+ atomLens: qe,
1334
+ composeLens: Je,
1335
+ lensFor: Ye
1336
+ });
1263
1337
  //#endregion
1264
1338
  //#region src/utils/array-pool.ts
1265
- var tt = class {
1339
+ var Qe = class {
1266
1340
  constructor(e = 50, t = 256) {
1267
1341
  this.limit = e, this.capacity = t, this.pool = [];
1268
1342
  }
@@ -1275,7 +1349,7 @@ var tt = class {
1275
1349
  reset() {
1276
1350
  this.pool.length = 0;
1277
1351
  }
1278
- }, nt = class {
1352
+ }, $e = class {
1279
1353
  constructor(e, t, n = 64) {
1280
1354
  this.factory = e, this.reset = t, this.limit = n, this.pool = [];
1281
1355
  }
@@ -1283,21 +1357,25 @@ var tt = class {
1283
1357
  return this.pool.pop() ?? this.factory();
1284
1358
  }
1285
1359
  release(e) {
1286
- this.pool.length >= this.limit || (this.reset(e), this.pool.push(e));
1360
+ this.pool.length < this.limit && (this.reset(e), this.pool.push(e));
1287
1361
  }
1288
1362
  drain() {
1289
- this.pool.length = 0;
1363
+ this.pool.length > 0 && (this.pool.length = 0);
1290
1364
  }
1291
1365
  get size() {
1292
1366
  return this.pool.length;
1293
1367
  }
1294
- }, rt = new tt(), it = new tt(), at = new nt(() => ({
1368
+ }, et = new Qe(), tt = new Qe(), nt = new $e(() => ({
1295
1369
  effects: void 0,
1296
1370
  cleanups: void 0,
1297
1371
  componentCleanup: void 0
1298
1372
  }), (e) => {
1299
1373
  e.effects = void 0, e.cleanups = void 0, e.componentCleanup = void 0;
1300
- }, 128), G = "_aes-bound", K = new class {
1374
+ }, 128), rt = !1;
1375
+ function it() {
1376
+ rt || (rt = !0, typeof document < "u" && document.body && ot(document.body));
1377
+ }
1378
+ var q = "_aes-bound", J = new class {
1301
1379
  constructor() {
1302
1380
  this.records = /* @__PURE__ */ new WeakMap(), this.preservedNodes = /* @__PURE__ */ new WeakSet(), this.ignoredNodes = /* @__PURE__ */ new WeakSet();
1303
1381
  }
@@ -1314,257 +1392,264 @@ var tt = class {
1314
1392
  return this.ignoredNodes.has(e);
1315
1393
  }
1316
1394
  getOrCreateRecord(e) {
1395
+ it();
1317
1396
  let t = this.records.get(e);
1318
- return t || (t = at.acquire(), this.records.set(e, t), e.classList.add(G)), t;
1397
+ return t || (t = nt.acquire(), this.records.set(e, t), e.classList.add(q)), t;
1319
1398
  }
1320
1399
  trackEffect(e, t) {
1321
1400
  let n = this.getOrCreateRecord(e);
1322
- n.effects ??= rt.acquire(), n.effects.push(t);
1401
+ n.effects ||= et.acquire(), n.effects.push(t);
1323
1402
  }
1324
1403
  trackCleanup(e, t) {
1325
1404
  let n = this.getOrCreateRecord(e);
1326
- n.cleanups ??= it.acquire(), n.cleanups.push(t);
1405
+ n.cleanups ||= tt.acquire(), n.cleanups.push(t);
1327
1406
  }
1328
1407
  setComponentCleanup(e, t) {
1329
- let n = this.getOrCreateRecord(e);
1330
- n.componentCleanup = t;
1408
+ this.getOrCreateRecord(e).componentCleanup = t;
1331
1409
  }
1332
1410
  hasBind(e) {
1333
1411
  return this.records.has(e);
1334
1412
  }
1335
1413
  cleanup(e) {
1336
- let t = this.records.get(e);
1337
- if (!t) {
1338
- e.nodeType === 1 && e.classList.remove(G), this.preservedNodes.delete(e), this.ignoredNodes.delete(e);
1414
+ let t = e.nodeType === 1, n = this.records.get(e);
1415
+ if (this.preservedNodes.delete(e), this.ignoredNodes.delete(e), !n) {
1416
+ t && e.classList.remove(q);
1339
1417
  return;
1340
1418
  }
1341
- if (this.records.delete(e), this.preservedNodes.delete(e), this.ignoredNodes.delete(e), e.nodeType === 1 && e.classList.remove(G), U.enabled) {
1342
- let t = e.nodeType === 1 ? R(e) : e.nodeName || "Node";
1343
- U.cleanup(B.BINDING, t);
1419
+ if (this.records.delete(e), t && e.classList.remove(q), G.enabled) {
1420
+ let n = t ? B(e) : e.nodeName || "Node";
1421
+ G.cleanup(H.BINDING, n);
1344
1422
  }
1345
- if (t.componentCleanup) try {
1346
- t.componentCleanup();
1347
- } catch (t) {
1348
- let n = e.nodeType === 1 ? R(e) : "Node";
1349
- U.error(B.MOUNT, H.MOUNT.CLEANUP_ERROR(n), t);
1350
- }
1351
- if (t.effects) {
1352
- let n = t.effects;
1353
- for (let t = 0, r = n.length; t < r; t++) try {
1354
- n[t].dispose();
1355
- } catch (t) {
1356
- let n = e.nodeType === 1 ? R(e) : "Node";
1357
- U.error(B.BINDING, H.CORE.EFFECT_DISPOSE_ERROR(n), t);
1423
+ let r = t ? B(e) : "Node";
1424
+ if (n.componentCleanup) try {
1425
+ n.componentCleanup();
1426
+ } catch (e) {
1427
+ G.error(H.MOUNT, W.MOUNT.CLEANUP_ERROR(r), e);
1428
+ }
1429
+ if (n.effects) {
1430
+ for (let e of n.effects) try {
1431
+ e.dispose();
1432
+ } catch (e) {
1433
+ G.error(H.BINDING, W.CORE.EFFECT_DISPOSE_ERROR(r), e);
1358
1434
  }
1359
- rt.release(n), t.effects = void 0;
1360
- }
1361
- if (t.cleanups) {
1362
- let n = t.cleanups;
1363
- for (let t = 0, r = n.length; t < r; t++) try {
1364
- n[t]();
1365
- } catch (t) {
1366
- let n = e.nodeType === 1 ? R(e) : "Node";
1367
- U.error(B.BINDING, H.BINDING.CLEANUP_ERROR(n), t);
1435
+ et.release(n.effects), n.effects = void 0;
1436
+ }
1437
+ if (n.cleanups) {
1438
+ for (let e of n.cleanups) try {
1439
+ e();
1440
+ } catch (e) {
1441
+ G.error(H.BINDING, W.BINDING.CLEANUP_ERROR(r), e);
1368
1442
  }
1369
- it.release(n), t.cleanups = void 0;
1443
+ tt.release(n.cleanups), n.cleanups = void 0;
1370
1444
  }
1371
- at.release(t);
1445
+ nt.release(n);
1372
1446
  }
1373
1447
  cleanupDescendants(e) {
1374
- let t = "getElementsByClassName" in e && typeof e.getElementsByClassName == "function" ? e.getElementsByClassName(G) : e.querySelectorAll(`.${G}`);
1375
- for (let e = t.length - 1; e >= 0; e--) {
1448
+ let t = e.getElementsByClassName ? e.getElementsByClassName(q) : e.querySelectorAll(`.${q}`), n = t.length;
1449
+ if (n !== 0) for (let e = n - 1; e >= 0; e--) {
1376
1450
  let n = t[e];
1377
- n && (this.records.has(n) ? this.cleanup(n) : (n.classList.remove(G), U.enabled && U.warn(B.BINDING, `${G} class found on unregistered element:`, n)));
1451
+ this.records.has(n) ? this.cleanup(n) : n.classList.remove(q);
1378
1452
  }
1379
1453
  }
1380
1454
  cleanupTree(e) {
1381
1455
  (e.nodeType === 1 || e.nodeType === 11) && this.cleanupDescendants(e), this.cleanup(e);
1382
1456
  }
1383
- }(), ot = /* @__PURE__ */ new Map();
1384
- function st(e) {
1385
- if (ot.has(e)) return;
1457
+ }(), at = /* @__PURE__ */ new Map();
1458
+ function ot(e) {
1459
+ if (at.has(e)) return;
1386
1460
  let t = new MutationObserver((e) => {
1387
- for (let t = 0, n = e.length; t < n; t++) {
1388
- let n = e[t].removedNodes;
1389
- for (let e = 0, t = n.length; e < t; e++) {
1390
- let t = n[e];
1391
- t.nodeType === 1 && (t.isConnected || K.isKept(t) || K.isIgnored(t) || K.cleanupTree(t));
1461
+ let t = J;
1462
+ for (let n = 0, r = e.length; n < r; n++) {
1463
+ let r = e[n].removedNodes;
1464
+ for (let e = 0, n = r.length; e < n; e++) {
1465
+ let n = r[e];
1466
+ if (n.nodeType !== 1) continue;
1467
+ let i = n;
1468
+ i.isConnected || t.isKept(i) || t.isIgnored(i) || t.cleanupTree(i);
1392
1469
  }
1393
1470
  }
1394
1471
  });
1395
1472
  t.observe(e, {
1396
1473
  childList: !0,
1397
1474
  subtree: !0
1398
- }), ot.set(e, t);
1475
+ }), at.set(e, t);
1399
1476
  }
1400
- function ct() {
1401
- ot.forEach((e) => e.disconnect()), ot.clear();
1477
+ function st() {
1478
+ at.forEach((e) => e.disconnect()), at.clear();
1402
1479
  }
1403
1480
  //#endregion
1404
1481
  //#region src/core/jquery-patch.ts
1405
- var lt = Symbol("atom-effect-internal"), ut = /* @__PURE__ */ new WeakMap(), q = null, dt = (e) => {
1406
- if (e[lt]) return e;
1407
- let t = ut.get(e);
1482
+ var ct = Symbol("atom-effect-internal"), lt = /* @__PURE__ */ new WeakMap(), Y = null, ut = (e) => {
1483
+ if (e[ct]) return e;
1484
+ let t = lt.get(e);
1408
1485
  return t || (t = function(...t) {
1409
- return ke(() => e.apply(this, t));
1410
- }, t[lt] = !0, ut.set(e, t)), t;
1486
+ return Ee(() => e.apply(this, t));
1487
+ }, t[ct] = !0, lt.set(e, t)), t;
1411
1488
  };
1412
- function ft(e) {
1413
- let t = {}, n = Object.entries(e);
1414
- for (let e = 0, r = n.length; e < r; e++) {
1415
- let r = n[e], i = r[0], a = r[1];
1416
- a && (t[i] = dt(a));
1417
- }
1489
+ function dt(e) {
1490
+ let t = {};
1491
+ for (let n in e) e[n] && (t[n] = ut(e[n]));
1418
1492
  return t;
1419
1493
  }
1420
- function pt(e) {
1421
- let t = {}, n = Object.entries(e);
1422
- for (let e = 0, r = n.length; e < r; e++) {
1423
- let r = n[e], i = r[0], a = r[1];
1424
- t[i] = a ? ut.get(a) ?? a : void 0;
1494
+ function ft(e) {
1495
+ let t = {};
1496
+ for (let n in e) {
1497
+ let r = e[n];
1498
+ t[n] = r ? lt.get(r) ?? r : void 0;
1425
1499
  }
1426
1500
  return t;
1427
1501
  }
1428
- function mt() {
1429
- if (q !== null) return;
1430
- q = {
1502
+ function pt() {
1503
+ if (Y !== null) return;
1504
+ Y = {
1431
1505
  on: e.fn.on,
1432
1506
  off: e.fn.off,
1433
1507
  remove: e.fn.remove,
1434
1508
  empty: e.fn.empty,
1435
1509
  detach: e.fn.detach
1436
1510
  };
1437
- let t = q;
1511
+ let t = Y;
1438
1512
  e.fn.remove = function(e) {
1439
- let n = e ? this.filter(e) : this;
1440
- for (let e = 0, t = n.length; e < t; e++) {
1513
+ let n = e ? this.filter(e) : this, r = n.length;
1514
+ for (let e = 0; e < r; e++) {
1441
1515
  let t = n[e];
1442
- t && (K.markIgnored(t), K.cleanupTree(t));
1516
+ t && (J.markIgnored(t), J.cleanupTree(t));
1443
1517
  }
1444
- let r = t.remove.call(this, e);
1445
- return r === void 0 ? this : r;
1518
+ return t.remove.call(this, e) ?? this;
1446
1519
  }, e.fn.empty = function() {
1447
- for (let e = 0, t = this.length; e < t; e++) {
1448
- let t = this[e];
1449
- t?.hasChildNodes() && K.cleanupDescendants(t);
1520
+ let e = this.length;
1521
+ for (let t = 0; t < e; t++) {
1522
+ let e = this[t];
1523
+ e?.hasChildNodes() && J.cleanupDescendants(e);
1450
1524
  }
1451
- let e = t.empty.call(this);
1452
- return e === void 0 ? this : e;
1525
+ return t.empty.call(this) ?? this;
1453
1526
  }, e.fn.detach = function(e) {
1454
- let n = e ? this.filter(e) : this;
1455
- for (let e = 0, t = n.length; e < t; e++) {
1527
+ let n = e ? this.filter(e) : this, r = n.length;
1528
+ for (let e = 0; e < r; e++) {
1456
1529
  let t = n[e];
1457
- t && K.keep(t);
1530
+ t && J.keep(t);
1458
1531
  }
1459
- let r = t.detach.call(this, e);
1460
- return r === void 0 ? this : r;
1532
+ return t.detach.call(this, e) ?? this;
1461
1533
  }, e.fn.on = function(...e) {
1462
1534
  let n = e[0];
1463
- if (n && typeof n == "object") e[0] = ft(n);
1535
+ if (n && typeof n == "object") e[0] = dt(n);
1464
1536
  else {
1465
1537
  let t = e.length - 1;
1466
- t >= 0 && typeof e[t] == "function" && (e[t] = dt(e[t]));
1538
+ t >= 0 && typeof e[t] == "function" && (e[t] = ut(e[t]));
1467
1539
  }
1468
- let r = t.on.apply(this, e);
1469
- return r === void 0 ? this : r;
1540
+ return t.on.apply(this, e) ?? this;
1470
1541
  }, e.fn.off = function(...e) {
1471
1542
  let n = e[0];
1472
- if (n && typeof n == "object") e[0] = pt(n);
1543
+ if (n && typeof n == "object") e[0] = ft(n);
1473
1544
  else {
1474
1545
  let t = e.length - 1;
1475
1546
  if (t >= 0 && typeof e[t] == "function") {
1476
1547
  let n = e[t];
1477
- e[t] = ut.get(n) ?? n;
1548
+ e[t] = lt.get(n) ?? n;
1478
1549
  }
1479
1550
  }
1480
- let r = t.off.apply(this, e);
1481
- return r === void 0 ? this : r;
1551
+ return t.off.apply(this, e) ?? this;
1482
1552
  };
1483
1553
  }
1484
- function ht() {
1485
- q !== null && (e.fn.on = q.on, e.fn.off = q.off, e.fn.remove = q.remove, e.fn.empty = q.empty, e.fn.detach = q.detach, q = null);
1554
+ function mt() {
1555
+ Y !== null && (e.fn.on = Y.on, e.fn.off = Y.off, e.fn.remove = Y.remove, e.fn.empty = Y.empty, e.fn.detach = Y.detach, Y = null);
1486
1556
  }
1487
1557
  //#endregion
1488
1558
  //#region src/types.ts
1489
- var J = /* @__PURE__ */ function(e) {
1559
+ var X = /* @__PURE__ */ function(e) {
1490
1560
  return e[e.None = 0] = "None", e[e.Focused = 1] = "Focused", e[e.Composing = 2] = "Composing", e[e.SyncingToAtom = 4] = "SyncingToAtom", e[e.SyncingToDom = 8] = "SyncingToDom", e[e.Busy = 14] = "Busy", e;
1491
- }({}), gt = 0;
1492
- function Y(e) {
1493
- e[lt] = !0;
1561
+ }({}), ht = 0;
1562
+ function gt(e) {
1563
+ e[ct] = !0;
1494
1564
  }
1495
1565
  var _t = class {
1496
1566
  constructor(e, t, n) {
1497
1567
  this.flags = 0, this.timeoutId = void 0, this.handleCompositionStart = () => {
1498
- this.flags |= J.Composing;
1568
+ this.flags |= X.Composing;
1499
1569
  }, this.handleCompositionEnd = () => {
1500
- this.flags &= ~J.Composing, this.handleInput();
1570
+ this.flags &= ~X.Composing, this.handleInput();
1501
1571
  }, this.handleFocus = () => {
1502
- this.flags |= J.Focused;
1572
+ this.flags |= X.Focused;
1503
1573
  }, this.handleBlur = () => {
1504
- this.flags &= ~J.Focused;
1505
- let e = !!(this.flags & J.Composing);
1506
- this.flags &= ~J.Composing, this.flushPendingDebounce(), e && this.timeoutId === void 0 && this.syncAtomFromDom(), this.normalizeDomValue();
1574
+ this.flags &= ~X.Focused;
1575
+ let e = !!(this.flags & X.Composing);
1576
+ this.flags &= ~X.Composing, this.flushPendingDebounce(), e && this.timeoutId === void 0 && this.syncAtomFromDom(), this.normalizeDomValue();
1507
1577
  }, this.syncDomFromAtom = () => {
1508
1578
  let e = this.atom.value;
1509
- D(() => {
1510
- let t = this.format(e), n;
1511
- if (n = this.isMultipleSelect ? this.$el.val() || [] : this.el.value, this.equal(n, e)) return;
1512
- let r = !!(this.flags & J.Focused);
1513
- if (r) try {
1514
- let t = this.isMultipleSelect ? n : this.parse(this.el.value);
1515
- if (this.equal(t, e)) return;
1579
+ O(() => {
1580
+ let t = this.isMultipleSelect, n = this.format(e), r = t ? this.$el.val() || [] : this.el.value;
1581
+ if (this.equal(r, e)) return;
1582
+ let i = !!(this.flags & X.Focused);
1583
+ if (i) try {
1584
+ let n = t ? r : this.parse(this.el.value);
1585
+ if (this.equal(n, e)) return;
1516
1586
  } catch {}
1517
- this.flags |= J.SyncingToDom;
1587
+ this.flags |= X.SyncingToDom;
1518
1588
  try {
1519
- if (this.isMultipleSelect) this.$el.val(e);
1520
- else if (r && (this.el instanceof HTMLInputElement || this.el instanceof HTMLTextAreaElement)) try {
1521
- let e = this.el.selectionStart, n = this.el.selectionEnd;
1522
- this.el.value = t;
1523
- let r = t.length;
1524
- e !== null && n !== null && this.el.setSelectionRange(e < r ? e : r, n < r ? n : r);
1589
+ if (t) this.$el.val(e);
1590
+ else if (i && this.isTextControl) try {
1591
+ let e = this.el, t = e.selectionStart, r = e.selectionEnd;
1592
+ e.value = n;
1593
+ let i = n.length;
1594
+ t !== null && r !== null && e.setSelectionRange(t < i ? t : i, r < i ? r : i);
1525
1595
  } catch {
1526
- this.el.value = t;
1596
+ this.el.value = n;
1527
1597
  }
1528
- else this.el.value = t;
1529
- U.enabled && U.domUpdated(B.BINDING, this.$el, "val", t);
1598
+ else this.el.value = n;
1599
+ G.enabled && G.domUpdated(H.BINDING, this.$el, "val", n);
1530
1600
  } finally {
1531
- this.flags &= ~J.SyncingToDom;
1601
+ this.flags &= ~X.SyncingToDom;
1532
1602
  }
1533
1603
  });
1534
1604
  }, this.cleanup = () => {
1535
1605
  this.$el.off(this.ns), clearTimeout(this.timeoutId), this.timeoutId = void 0;
1536
- }, this.$el = e, this.el = e[0], this.atom = t, this.isMultipleSelect = this.el.tagName === "SELECT" && this.el.multiple, this.ns = `.atomBind-${++gt}`;
1537
- let r = n.debounce ?? 0, i = n.event ?? Me.EVENT;
1538
- this.parse = n.parse ?? ((e) => e), this.format = n.format ?? ((e) => this.isMultipleSelect ? (Array.isArray(e) ? e : e ? [String(e)] : []).join(",") : String(e ?? ""));
1539
- let a = n.equal ?? Object.is;
1540
- this.equal = (e, t) => a(e, t) ? !0 : Array.isArray(e) && Array.isArray(t) ? e.length === t.length && e.every((e, n) => Object.is(e, t[n])) : !1, r > 0 ? this.handleInput = () => {
1541
- this.flags & J.Composing || (clearTimeout(this.timeoutId), this.timeoutId = setTimeout(() => this.syncAtomFromDom(), r));
1606
+ }, this.$el = e, this.el = e[0], this.atom = t;
1607
+ let r = this.el.tagName, i = r === "SELECT" && this.el.multiple;
1608
+ this.isMultipleSelect = i, this.isTextControl = r === "INPUT" || r === "TEXTAREA", this.ns = `.atomBind-${++ht}`;
1609
+ let a = n.debounce ?? 0;
1610
+ this.parse = n.parse ?? ((e) => e), i ? this.format = n.format ?? ((e) => (Array.isArray(e) ? e : e ? [String(e)] : []).join(",")) : this.format = n.format ?? ((e) => String(e ?? ""));
1611
+ let o = n.equal ?? Object.is;
1612
+ i ? this.equal = (e, t) => {
1613
+ if (o(e, t)) return !0;
1614
+ if (Array.isArray(e) && Array.isArray(t)) {
1615
+ let n = e.length;
1616
+ if (n !== t.length) return !1;
1617
+ for (let r = 0; r < n; r++) if (!Object.is(e[r], t[r])) return !1;
1618
+ return !0;
1619
+ }
1620
+ return !1;
1621
+ } : this.equal = o, a > 0 ? this.handleInput = () => {
1622
+ this.flags & X.Composing || (clearTimeout(this.timeoutId), this.timeoutId = setTimeout(() => this.syncAtomFromDom(), a));
1542
1623
  } : this.handleInput = () => {
1543
- this.flags & J.Composing || this.syncAtomFromDom();
1544
- }, Y(this.handleFocus), Y(this.handleBlur), Y(this.handleCompositionStart), Y(this.handleCompositionEnd), Y(this.handleInput), this.bindEvents(i);
1624
+ this.flags & X.Composing || this.syncAtomFromDom();
1625
+ }, [
1626
+ this.handleFocus,
1627
+ this.handleBlur,
1628
+ this.handleCompositionStart,
1629
+ this.handleCompositionEnd,
1630
+ this.handleInput
1631
+ ].forEach(gt), this.bindEvents(n.event ?? ke.EVENT);
1545
1632
  }
1546
1633
  flushPendingDebounce() {
1547
1634
  this.timeoutId !== void 0 && (clearTimeout(this.timeoutId), this.timeoutId = void 0, this.syncAtomFromDom());
1548
1635
  }
1549
1636
  normalizeDomValue() {
1550
- let e = this.format(this.atom.peek());
1637
+ let e = this.atom.peek(), t = this.format(e);
1551
1638
  if (this.isMultipleSelect) {
1552
- let e = this.$el.val() || [], t = Array.isArray(this.atom.peek()) ? this.atom.peek() : [];
1553
- this.equal(e, t) || this.$el.val(t);
1554
- } else this.el.value !== e && (this.el.value = e);
1639
+ let t = this.$el.val() || [], n = Array.isArray(e) ? e : [];
1640
+ this.equal(t, n) || this.$el.val(n);
1641
+ } else this.el.value !== t && (this.el.value = t);
1555
1642
  }
1556
1643
  syncAtomFromDom() {
1557
- if (!(this.flags & J.Busy)) {
1558
- this.flags |= J.SyncingToAtom;
1644
+ if (!(this.flags & X.Busy)) {
1645
+ this.flags |= X.SyncingToAtom;
1559
1646
  try {
1560
- let e;
1561
- e = this.isMultipleSelect ? this.$el.val() || [] : this.el.value;
1562
- let t = this.parse(e);
1563
- this.equal(this.atom.peek(), t) || (this.atom.value = t);
1647
+ let e = this.isMultipleSelect, t = e ? this.$el.val() || [] : this.el.value, n = e ? t : this.parse(t);
1648
+ this.equal(this.atom.peek(), n) || (this.atom.value = n);
1564
1649
  } catch (e) {
1565
- U.warn(B.BINDING, H.BINDING.PARSE_ERROR(e instanceof Error ? e.message : String(e)), e);
1650
+ G.warn(H.BINDING, W.BINDING.PARSE_ERROR(e instanceof Error ? e.message : String(e)), e);
1566
1651
  } finally {
1567
- this.flags &= ~J.SyncingToAtom;
1652
+ this.flags &= ~X.SyncingToAtom;
1568
1653
  }
1569
1654
  }
1570
1655
  }
@@ -1576,72 +1661,71 @@ var _t = class {
1576
1661
  function vt(e, t, n) {
1577
1662
  let r = new _t(e, t, n);
1578
1663
  return {
1579
- fx: I(r.syncDomFromAtom),
1580
- cleanup: r.cleanup
1664
+ fx: R(r.syncDomFromAtom),
1665
+ cleanup: () => {
1666
+ r &&= (r.cleanup(), null);
1667
+ }
1581
1668
  };
1582
1669
  }
1583
1670
  //#endregion
1584
1671
  //#region src/core/effect-factory.ts
1585
1672
  function yt(e, t, n, r) {
1586
1673
  let i = null, a = (t) => {
1587
- if (Ae(t)) {
1588
- let a = t;
1589
- i = a, a.then((t) => {
1590
- i === a && D(() => {
1591
- try {
1592
- n(t), U.enabled && U.domUpdated(B.BINDING, e, `${r} (async)`, t);
1593
- } catch (e) {
1594
- U.error(B.BINDING, H.BINDING.UPDATER_ERROR(r), e);
1595
- }
1596
- });
1597
- }).catch((e) => {
1598
- i === a && U.error(B.BINDING, H.BINDING.UPDATER_ERROR(r), e);
1599
- });
1600
- } else {
1674
+ if (!De(t)) {
1601
1675
  i = null;
1602
1676
  try {
1603
- n(t), U.enabled && U.domUpdated(B.BINDING, e, r, t);
1677
+ n(t), G.enabled && G.domUpdated(H.BINDING, e, r, t);
1604
1678
  } catch (e) {
1605
- U.error(B.BINDING, H.BINDING.UPDATER_ERROR(r, !0), e);
1679
+ G.error(H.BINDING, W.BINDING.UPDATER_ERROR(r, !0), e);
1606
1680
  }
1681
+ return;
1607
1682
  }
1608
- };
1609
- L(t) ? K.trackEffect(e, I(() => {
1610
- let e = t.value;
1611
- D(() => a(e));
1612
- }, { name: r })) : typeof t == "function" ? K.trackEffect(e, I(() => {
1613
- let e = t();
1614
- D(() => a(e));
1615
- }, { name: r })) : D(() => a(t));
1683
+ i = t, t.then((a) => {
1684
+ i === t && O(() => {
1685
+ try {
1686
+ n(a), G.enabled && G.domUpdated(H.BINDING, e, `${r} (async)`, a);
1687
+ } catch (e) {
1688
+ G.error(H.BINDING, W.BINDING.UPDATER_ERROR(r), e);
1689
+ }
1690
+ });
1691
+ }).catch((e) => {
1692
+ i === t && G.error(H.BINDING, W.BINDING.UPDATER_ERROR(r), e);
1693
+ });
1694
+ }, o = z(t);
1695
+ o || typeof t == "function" ? J.trackEffect(e, R(() => {
1696
+ let e = o ? t.value : t();
1697
+ O(() => a(e));
1698
+ }, { name: r })) : O(() => a(t));
1616
1699
  }
1617
1700
  function bt(e, t, n, r) {
1618
1701
  let i = Object.keys(t), a = [], o = {};
1619
- for (let e = 0; e < i.length; e++) {
1702
+ for (let e = 0, n = i.length; e < n; e++) {
1620
1703
  let n = i[e], r = t[n];
1621
- L(r) || typeof r == "function" ? a.push(n) : o[n] = r;
1704
+ z(r) || typeof r == "function" ? a.push(n) : o[n] = r;
1622
1705
  }
1623
1706
  let s = 0, c = (t) => {
1624
- let i = Object.keys(t), a = [], o = {};
1625
- for (let e = 0; e < i.length; e++) {
1707
+ let a = [], o = {}, c = i.length;
1708
+ for (let e = 0; e < c; e++) {
1626
1709
  let n = i[e], r = t[n];
1627
- Ae(r) ? a.push(r.then((e) => ({
1710
+ De(r) ? a.push(r.then((e) => ({
1628
1711
  key: n,
1629
1712
  val: e
1630
1713
  }))) : o[n] = r;
1631
1714
  }
1632
- if (a.length > 0) {
1715
+ let l = a.length;
1716
+ if (l > 0) {
1633
1717
  let t = ++s;
1634
1718
  Promise.all(a).then((i) => {
1635
1719
  if (t === s) {
1636
- for (let e = 0; e < i.length; e++) {
1637
- let { key: t, val: n } = i[e];
1638
- o[t] = n;
1720
+ for (let e = 0; e < l; e++) {
1721
+ let t = i[e];
1722
+ o[t.key] = t.val;
1639
1723
  }
1640
- D(() => {
1724
+ O(() => {
1641
1725
  try {
1642
- n(o), U.enabled && U.domUpdated(B.BINDING, e, `${r} (async)`, o);
1726
+ n(o), G.enabled && G.domUpdated(H.BINDING, e, `${r} (async)`, o);
1643
1727
  } catch (e) {
1644
- U.error(B.BINDING, H.BINDING.UPDATER_ERROR(r), e);
1728
+ G.error(H.BINDING, W.BINDING.UPDATER_ERROR(r), e);
1645
1729
  }
1646
1730
  });
1647
1731
  }
@@ -1649,20 +1733,20 @@ function bt(e, t, n, r) {
1649
1733
  } else {
1650
1734
  s++;
1651
1735
  try {
1652
- n(o), U.enabled && U.domUpdated(B.BINDING, e, r, o);
1736
+ n(o), G.enabled && G.domUpdated(H.BINDING, e, r, o);
1653
1737
  } catch (e) {
1654
- U.error(B.BINDING, H.BINDING.UPDATER_ERROR(r, !0), e);
1738
+ G.error(H.BINDING, W.BINDING.UPDATER_ERROR(r, !0), e);
1655
1739
  }
1656
1740
  }
1657
1741
  };
1658
- a.length > 0 ? K.trackEffect(e, I(() => {
1742
+ a.length > 0 ? J.trackEffect(e, R(() => {
1659
1743
  let e = { ...o };
1660
- for (let n = 0; n < a.length; n++) {
1744
+ for (let n = 0, r = a.length; n < r; n++) {
1661
1745
  let r = a[n], i = t[r];
1662
- e[r] = L(i) ? i.value : i();
1746
+ e[r] = z(i) ? i.value : i();
1663
1747
  }
1664
- D(() => c(e));
1665
- }, { name: r })) : D(() => c(o));
1748
+ O(() => c(e));
1749
+ }, { name: r })) : O(() => c(o));
1666
1750
  }
1667
1751
  //#endregion
1668
1752
  //#region src/utils/sanitize.ts
@@ -1686,21 +1770,19 @@ var xt = new Set([
1686
1770
  Tab: " ",
1687
1771
  NewLine: "\n"
1688
1772
  }, Ot = /&(colon|Tab|NewLine);/g, kt = /<\?[\s\S]*?\?>/g, At = /(<(script|iframe|object|embed|base|meta|applet|noscript|form|style|link)\b[^>]*>([\s\S]*?)<\/\2>|<(script|iframe|object|embed|base|meta|applet|noscript|form|style|link)\b[^>]*\/?>)/gi, jt = /(j\s*a\s*v\s*a\s*s\s*c\s*r\s*i\s*p\s*t|v\s*b\s*s\s*c\s*r\s*i\s*p\s*t)\s*:/gi, Mt = /data\s*:\s*(?:text\/(?:html|javascript|vbscript|xml)|application\/(?:javascript|xhtml\+xml|xml|x-shockwave-flash)|image\/svg\+xml)/gi, Nt = /\bon\w+\s*=/gim, Pt = new RegExp(Ct.source, "gim");
1689
- function X(e) {
1690
- let t = String(e ?? "");
1691
- t = t.replace(Tt, ""), t = t.replace(Et, (e, t, n) => String.fromCodePoint(t ? parseInt(t, 16) : parseInt(n, 10))), t = t.replace(Ot, (e, t) => Dt[t] ?? ""), t = t.replace(kt, "");
1692
- let n;
1693
- do
1694
- n = t, t = t.replace(At, "");
1695
- while (t !== n);
1696
- return t = t.replace(jt, "data-unsafe-protocol:"), t = t.replace(Mt, "data-unsafe-protocol:"), t = t.replace(Nt, "data-unsafe-attr="), t = t.replace(Pt, "data-unsafe-css:"), t;
1773
+ function Z(e) {
1774
+ if (!e) return "";
1775
+ let t = String(e).replace(Tt, "").replace(Et, (e, t, n) => String.fromCodePoint(t ? parseInt(t, 16) : parseInt(n, 10))).replace(Ot, (e, t) => Dt[t] ?? "");
1776
+ if (t.indexOf("<") !== -1) {
1777
+ t = t.replace(kt, "");
1778
+ let e;
1779
+ do
1780
+ e = t, t = t.replace(At, "");
1781
+ while (t !== e);
1782
+ }
1783
+ return t.replace(jt, "data-unsafe-protocol:").replace(Mt, "data-unsafe-protocol:").replace(Nt, "data-unsafe-attr=").replace(Pt, "data-unsafe-css:");
1697
1784
  }
1698
- function Ft(e) {
1699
- return e.toLowerCase().includes("url(") ? wt.test(e) : !1;
1700
- }
1701
- //#endregion
1702
- //#region src/bindings/unified.ts
1703
- var It = /* @__PURE__ */ new Map();
1785
+ var Ft = (e) => e.length < 15 ? !1 : e.toLowerCase().includes("url(") && wt.test(e), It = /* @__PURE__ */ new Map();
1704
1786
  function Lt(e) {
1705
1787
  let t = It.get(e);
1706
1788
  return t === void 0 ? (t = e.includes("-") ? e.replace(/-./g, (e) => e[1].toUpperCase()) : e, It.set(e, t), t) : t;
@@ -1708,98 +1790,96 @@ function Lt(e) {
1708
1790
  var Rt = /* @__PURE__ */ new WeakMap();
1709
1791
  function zt(e) {
1710
1792
  let t = Rt.get(e);
1711
- return t || (t = F(() => {
1793
+ return t || (t = L(() => {
1712
1794
  let t = e.value;
1713
- return Ae(t) ? t.then((e) => X(e)) : X(t);
1795
+ return De(t) ? t.then((e) => Z(e)) : Z(t);
1714
1796
  }), Rt.set(e, t)), t;
1715
1797
  }
1716
1798
  function Bt(e) {
1717
1799
  return {
1718
1800
  el: e,
1719
- trackCleanup: (t) => K.trackCleanup(e, t)
1801
+ trackCleanup: (t) => J.trackCleanup(e, t)
1720
1802
  };
1721
1803
  }
1722
- function Vt(e, t, n) {
1723
- let r = e.el;
1724
- yt(r, t, (e) => {
1725
- let t = n ? n(e) : typeof e == "string" ? e : String(e ?? "");
1726
- r.textContent !== t && (r.textContent = t);
1804
+ function Vt({ el: e }, t, n) {
1805
+ yt(e, t, (t) => {
1806
+ let r = n ? n(t) : String(t ?? "");
1807
+ e.textContent !== r && (e.textContent = r);
1727
1808
  }, "text");
1728
1809
  }
1729
- function Ht(e, t) {
1730
- let n = e.el, r = be(t) ? zt(t) : t;
1731
- yt(n, r, (e) => {
1732
- let i = r === t ? X(e) : e;
1733
- n.innerHTML !== i && (K.cleanupDescendants(n), n.innerHTML = i);
1810
+ function Ht({ el: e }, t) {
1811
+ let n = ve(t) ? zt(t) : t;
1812
+ yt(e, n, (r) => {
1813
+ let i = n === t ? Z(r) : r;
1814
+ e.innerHTML !== i && (J.cleanupDescendants(e), e.innerHTML = i);
1734
1815
  }, "html");
1735
1816
  }
1736
- function Ut(e, t) {
1737
- let n = e.el, r = {};
1738
- for (let e in t) z.call(t, e) && (r[e] = e.trim().split(/\s+/).filter(Boolean));
1739
- bt(n, t, (e) => {
1740
- for (let t in e) {
1741
- let i = e[t], a = r[t];
1742
- i ? n.classList.add(...a) : n.classList.remove(...a);
1817
+ function Ut({ el: e }, t) {
1818
+ let n = {};
1819
+ for (let e in t) if (V.call(t, e)) {
1820
+ let t = e.trim();
1821
+ n[e] = t.indexOf(" ") === -1 ? [t] : t.split(/\s+/).filter(Boolean);
1822
+ }
1823
+ bt(e, t, (t) => {
1824
+ for (let r in t) {
1825
+ let i = n[r];
1826
+ t[r] ? e.classList.add(...i) : e.classList.remove(...i);
1743
1827
  }
1744
1828
  }, "class");
1745
1829
  }
1746
- function Wt(e, t) {
1747
- let n = e.el, r = n.style, i = {}, a = {};
1748
- for (let e in t) if (z.call(t, e)) {
1749
- let n = t[e], [r, o] = Array.isArray(n) ? n : [n, ""];
1750
- i[e] = r, a[e] = {
1830
+ function Wt({ el: e }, t) {
1831
+ let n = e.style, r = {}, i = {};
1832
+ for (let e in t) if (V.call(t, e)) {
1833
+ let n = t[e], [a, o] = Array.isArray(n) ? n : [n, ""];
1834
+ r[e] = a, i[e] = {
1751
1835
  camel: Lt(e),
1752
1836
  unit: o
1753
1837
  };
1754
1838
  }
1755
- bt(n, i, (e) => {
1839
+ bt(e, r, (e) => {
1756
1840
  for (let t in e) {
1757
- let n = e[t], { camel: i, unit: o } = a[t], s = o ? String(n) + o : String(n);
1758
- Ft(s) || r[i] !== s && (r[i] = s);
1841
+ let r = i[t], a = e[t], o = r.unit ? `${a}${r.unit}` : String(a), s = r.camel;
1842
+ !Ft(o) && n[s] !== o && (n[s] = o);
1759
1843
  }
1760
1844
  }, "css");
1761
1845
  }
1762
- function Gt(e, t) {
1763
- let n = e.el, r = {}, i = {};
1764
- for (let e in t) if (z.call(t, e)) {
1765
- let n = e.toLowerCase();
1766
- if (n.startsWith("on")) {
1767
- console.warn(`${B.BINDING} ${H.SECURITY.BLOCKED_EVENT_HANDLER(e)}`);
1846
+ function Gt({ el: e }, t) {
1847
+ let n = {}, r = {}, i = {};
1848
+ for (let a in t) {
1849
+ if (!V.call(t, a)) continue;
1850
+ let o = a.toLowerCase();
1851
+ if (o.startsWith("on")) {
1852
+ console.warn(`${H.BINDING} ${W.SECURITY.BLOCKED_EVENT_HANDLER(a)}`);
1768
1853
  continue;
1769
1854
  }
1770
- r[e] = t[e], i[e] = {
1771
- isAria: n.startsWith("aria-"),
1772
- isUrl: xt.has(n)
1773
- };
1855
+ n[a] = t[a], r[a] = {
1856
+ isAria: o.startsWith("aria-"),
1857
+ isUrl: xt.has(o)
1858
+ }, i[a] = e.getAttribute(a);
1774
1859
  }
1775
- let a = {};
1776
- for (let e in r) a[e] = n.getAttribute(e);
1777
- bt(n, r, (e) => {
1778
- for (let t in e) {
1779
- let r = e[t], o = i[t], s = o.isAria;
1780
- if (r == null || r === !1 && !s) {
1781
- a[t] !== null && (n.removeAttribute(t), a[t] = null);
1860
+ bt(e, n, (t) => {
1861
+ for (let n in t) {
1862
+ let a = r[n], o = t[n];
1863
+ if (o == null || o === !1 && !a.isAria) {
1864
+ i[n] !== null && e.removeAttribute(n), i[n] = null;
1782
1865
  continue;
1783
1866
  }
1784
- let c = r === !0 ? s ? "true" : t : String(r);
1785
- if (o.isUrl && St.test(c)) {
1786
- console.warn(`${B.BINDING} ${H.SECURITY.BLOCKED_PROTOCOL(t)}`);
1867
+ let s = o === !0 ? a.isAria ? "true" : n : String(o);
1868
+ if (a.isUrl && St.test(s)) {
1869
+ console.warn(`${H.BINDING} ${W.SECURITY.BLOCKED_PROTOCOL(n)}`);
1787
1870
  continue;
1788
1871
  }
1789
- a[t] !== c && (n.setAttribute(t, c), a[t] = c);
1872
+ i[n] !== s && (e.setAttribute(n, s), i[n] = s);
1790
1873
  }
1791
1874
  }, "attr");
1792
1875
  }
1793
1876
  function Kt(e, t) {
1794
1877
  let n = e.el, r = {}, i = {};
1795
- for (let e in t) if (z.call(t, e)) {
1878
+ for (let e in t) {
1879
+ if (!V.call(t, e)) continue;
1796
1880
  let n = e.toLowerCase();
1797
- if (n.startsWith("on")) {
1798
- console.warn(`${B.BINDING} ${H.SECURITY.BLOCKED_EVENT_HANDLER(e)}`);
1799
- continue;
1800
- }
1801
- if (Fe.has(e)) {
1802
- console.warn(`${B.BINDING} ${H.SECURITY.BLOCKED_PROP(e)}`);
1881
+ if (n.startsWith("on") || Me.has(e)) {
1882
+ console.warn(`${H.BINDING} ${n.startsWith("on") ? W.SECURITY.BLOCKED_EVENT_HANDLER(e) : W.SECURITY.BLOCKED_PROP(e)}`);
1803
1883
  continue;
1804
1884
  }
1805
1885
  r[e] = t[e], i[e] = { isUrl: xt.has(n) };
@@ -1808,440 +1888,427 @@ function Kt(e, t) {
1808
1888
  for (let t in e) {
1809
1889
  let r = e[t];
1810
1890
  if (i[t].isUrl && typeof r == "string" && St.test(r)) {
1811
- console.warn(`${B.BINDING} ${H.SECURITY.BLOCKED_PROTOCOL(t)}`);
1891
+ console.warn(`${H.BINDING} ${W.SECURITY.BLOCKED_PROTOCOL(t)}`);
1812
1892
  continue;
1813
1893
  }
1814
1894
  n[t] !== r && (n[t] = r);
1815
1895
  }
1816
1896
  }, "prop");
1817
1897
  }
1818
- function qt(e, t, n) {
1819
- let r = e.el, i = n ? "hide" : "show", a = r.style.display, o = a === "none" ? "" : a;
1820
- yt(r, t, (e) => {
1821
- let t = n === !!e ? "none" : o;
1822
- r.style.display !== t && (r.style.display = t);
1823
- }, i);
1898
+ function qt({ el: e }, t, n) {
1899
+ let r = e.style.display === "none" ? "" : e.style.display;
1900
+ yt(e, t, (t) => {
1901
+ let i = n === !!t ? "none" : r;
1902
+ e.style.display !== i && (e.style.display = i);
1903
+ }, n ? "hide" : "show");
1824
1904
  }
1825
1905
  function Jt(t, n, r = {}) {
1826
1906
  let i = t.el.tagName.toLowerCase();
1827
- if (!Pe.has(i)) {
1828
- console.warn(`${B.BINDING} ${H.BINDING.INVALID_INPUT_ELEMENT(i)}`);
1907
+ if (!je.has(i)) {
1908
+ console.warn(`${H.BINDING} ${W.BINDING.INVALID_INPUT_ELEMENT(i)}`);
1829
1909
  return;
1830
1910
  }
1831
1911
  let { fx: a, cleanup: o } = vt(e(t.el), n, r);
1832
- K.trackEffect(t.el, a), t.trackCleanup(o);
1912
+ J.trackEffect(t.el, a), t.trackCleanup(o);
1833
1913
  }
1834
1914
  function Yt(t, n) {
1835
- let r = t.el, i = e(r), a = r.type === "radio", o = () => {
1836
- let t = r.checked;
1837
- if (n.peek() !== t && (n.value = t, a && t && r.name)) {
1838
- let t = r.name.replace(/"/g, "\\\"");
1839
- (r.form ? e(r.form) : e(document)).find(`input[type="radio"][name="${t}"]`).not(r).trigger("change.atomRadioSync");
1840
- }
1915
+ let r = t.el, i = e(r), a = () => {
1916
+ n.peek() !== r.checked && (n.value = r.checked, r.type === "radio" && r.checked && r.name && (r.form ? e(r.form) : e(document)).find(`input[type="radio"][name="${r.name.replace(/"/g, "\\\"")}"]`).not(r).trigger("change.atomRadioSync"));
1841
1917
  };
1842
- o[lt] = !0, i.on("change change.atomRadioSync", o), t.trackCleanup(() => i.off("change change.atomRadioSync", o));
1843
- let s = I(() => {
1918
+ a[ct] = !0, i.on("change change.atomRadioSync", a), t.trackCleanup(() => i.off("change change.atomRadioSync", a)), J.trackEffect(r, R(() => {
1844
1919
  let e = !!n.value;
1845
- D(() => {
1846
- r.checked !== e && (r.checked = e, U.enabled && U.domUpdated(B.BINDING, r, "checked", e));
1920
+ O(() => {
1921
+ r.checked !== e && (r.checked = e, G.enabled && G.domUpdated(H.BINDING, r, "checked", e));
1847
1922
  });
1848
- });
1849
- K.trackEffect(r, s);
1923
+ }));
1850
1924
  }
1851
1925
  function Xt(t, n) {
1852
1926
  let r = e(t.el);
1853
1927
  r.on(n), t.trackCleanup(() => r.off(n));
1854
1928
  }
1855
- function Zt(t, n, r) {
1856
- let i = e(t.el);
1857
- i.on(n, r), t.trackCleanup(() => i.off(n, r));
1929
+ function Zt({ el: t, trackCleanup: n }, r, i) {
1930
+ let a = e(t);
1931
+ a.on(r, i), n(() => a.off(r, i));
1858
1932
  }
1859
1933
  function Qt(e) {
1860
- K.cleanupTree(e);
1934
+ J.cleanupTree(e);
1861
1935
  }
1862
1936
  //#endregion
1863
1937
  //#region src/bindings/form.ts
1864
1938
  function $t(e, t, n = {}) {
1865
- let r = e.elements, i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = I(() => {
1866
- let e = t.value;
1867
- D(() => {
1868
- for (let [t, n] of i) {
1869
- let r = W(e, a.get(t));
1870
- Object.is(n.peek(), r) || (n.value = r);
1939
+ let r = /* @__PURE__ */ new Map(), i = [], a = R(() => {
1940
+ let e = t.value, n = i.length;
1941
+ n !== 0 && O(() => {
1942
+ for (let t = 0; t < n; t++) {
1943
+ let n = i[t], r = K(e, n.parts);
1944
+ Object.is(n.atom.peek(), r) || (n.atom.value = r);
1871
1945
  }
1872
1946
  });
1873
1947
  });
1874
- K.trackEffect(e, o);
1875
- let s = (n) => {
1876
- let r = i.get(n);
1877
- if (!r) {
1948
+ J.trackEffect(e, a);
1949
+ let o = (n) => {
1950
+ let a = r.get(n);
1951
+ if (!a) {
1878
1952
  let o = n.includes(".") ? n.split(".") : [n];
1879
- a.set(n, o), r = O(W(t.peek(), o));
1880
- let s = I(() => {
1881
- let e = r.value, n = t.peek(), i = Je(n, o, 0, e);
1882
- i !== n && (t.value = i);
1883
- });
1884
- K.trackEffect(e, s), i.set(n, r);
1953
+ a = k(K(t.peek(), o)), i.push({
1954
+ atom: a,
1955
+ parts: o
1956
+ }), J.trackEffect(e, R(() => {
1957
+ let e = a.value, n = t.peek(), r = Ke(n, o, 0, e);
1958
+ r !== n && (t.value = r);
1959
+ })), r.set(n, a);
1885
1960
  }
1886
- return r;
1887
- }, c = (e) => {
1961
+ return a;
1962
+ }, s = (e) => {
1888
1963
  if (!(e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement || e instanceof HTMLSelectElement)) return;
1889
1964
  let t = e.name;
1890
- if (!t || K.hasBind(e)) return;
1891
- let r = s(t), i = Bt(e);
1965
+ if (!t || J.hasBind(e)) return;
1966
+ let r = o(t), i = Bt(e);
1892
1967
  e instanceof HTMLInputElement && (e.type === "checkbox" || e.type === "radio") ? Yt(i, r) : Jt(i, r, n);
1893
1968
  };
1894
- for (let e = 0, t = r.length; e < t; e++) c(r[e]);
1895
- let l = new MutationObserver((e) => {
1969
+ for (let t = 0, n = e.elements.length; t < n; t++) s(e.elements[t]);
1970
+ let c = new MutationObserver((e) => {
1896
1971
  for (let t = 0, n = e.length; t < n; t++) {
1897
1972
  let n = e[t];
1898
- if (n.type === "childList") {
1899
- let e = n.addedNodes;
1900
- for (let t = 0, n = e.length; t < n; t++) if (e[t].nodeType === 1) {
1901
- let n = e[t];
1902
- c(n);
1903
- let r = n.querySelectorAll("input, select, textarea");
1904
- for (let e = 0, t = r.length; e < t; e++) c(r[e]);
1973
+ if (n.type === "childList") for (let e = 0, t = n.addedNodes.length; e < t; e++) {
1974
+ let t = n.addedNodes[e];
1975
+ if (t.nodeType === 1) {
1976
+ let e = t;
1977
+ s(e);
1978
+ let n = e.matches?.("input, select, textarea") ? [e] : e.querySelectorAll("input, select, textarea");
1979
+ for (let e = 0, t = n.length; e < t; e++) s(n[e]);
1905
1980
  }
1906
- } else n.type === "attributes" && n.attributeName === "name" && c(n.target);
1981
+ }
1982
+ else n.type === "attributes" && n.attributeName === "name" && s(n.target);
1907
1983
  }
1908
1984
  });
1909
- l.observe(e, {
1985
+ c.observe(e, {
1910
1986
  childList: !0,
1911
1987
  subtree: !0,
1912
1988
  attributes: !0,
1913
1989
  attributeFilter: ["name"]
1914
- }), K.trackCleanup(e, () => l.disconnect());
1990
+ }), J.trackCleanup(e, () => c.disconnect());
1915
1991
  }
1916
1992
  //#endregion
1917
1993
  //#region src/bindings/chainable.ts
1918
- function Z(e, t) {
1919
- for (let n = 0, r = e.length; n < r; n++) {
1920
- let r = e[n];
1921
- r.nodeType === 1 ? t(Bt(r), r) : U.enabled && U.log(B.BINDING, `Skipping non-Element node (nodeType=${r.nodeType})`);
1994
+ function Q(e, t) {
1995
+ let n = e.length;
1996
+ for (let r = 0; r < n; r++) {
1997
+ let n = e[r];
1998
+ if (n?.nodeType === 1) {
1999
+ let e = n;
2000
+ t(Bt(e), e);
2001
+ } else G.enabled && n && G.log(H.BINDING, `Skipping non-Element node (nodeType=${n.nodeType})`);
1922
2002
  }
1923
2003
  return e;
1924
2004
  }
1925
2005
  e.fn.atomText = function(e, t) {
1926
- return Z(this, (n) => Vt(n, e, t));
2006
+ return Q(this, (n) => Vt(n, e, t));
1927
2007
  }, e.fn.atomHtml = function(e) {
1928
- return Z(this, (t) => Ht(t, e));
2008
+ return Q(this, (t) => Ht(t, e));
1929
2009
  }, e.fn.atomClass = function(e, t) {
1930
- if (typeof e == "string" && t === void 0) return console.warn(`${B.BINDING} ${H.BINDING.MISSING_CONDITION("atomClass")}`), this;
1931
- let n = typeof e == "string" ? { [e]: t } : e;
1932
- return Z(this, (e) => Ut(e, n));
2010
+ if (typeof e == "string") {
2011
+ if (t === void 0) return console.warn(`${H.BINDING} ${W.BINDING.MISSING_CONDITION("atomClass")}`), this;
2012
+ let n = { [e]: t };
2013
+ return Q(this, (e) => Ut(e, n));
2014
+ }
2015
+ return Q(this, (t) => Ut(t, e));
1933
2016
  }, e.fn.atomCss = function(e, t, n) {
1934
- if (typeof e == "string" && t === void 0) return console.warn(`${B.BINDING} ${H.BINDING.MISSING_SOURCE("atomCss")}`), this;
1935
- let r = typeof e == "string" ? { [e]: n ? [t, n] : t } : e;
1936
- return Z(this, (e) => Wt(e, r));
2017
+ if (typeof e == "string") {
2018
+ if (t === void 0) return console.warn(`${H.BINDING} ${W.BINDING.MISSING_SOURCE("atomCss")}`), this;
2019
+ let r = { [e]: n ? [t, n] : t };
2020
+ return Q(this, (e) => Wt(e, r));
2021
+ }
2022
+ return Q(this, (t) => Wt(t, e));
1937
2023
  }, e.fn.atomAttr = function(e, t) {
1938
- if (typeof e == "string" && t === void 0) return console.warn(`${B.BINDING} ${H.BINDING.MISSING_SOURCE("atomAttr")}`), this;
1939
- let n = typeof e == "string" ? { [e]: t } : e;
1940
- return Z(this, (e) => Gt(e, n));
2024
+ if (typeof e == "string") {
2025
+ if (t === void 0) return console.warn(`${H.BINDING} ${W.BINDING.MISSING_SOURCE("atomAttr")}`), this;
2026
+ let n = { [e]: t };
2027
+ return Q(this, (e) => Gt(e, n));
2028
+ }
2029
+ return Q(this, (t) => Gt(t, e));
1941
2030
  }, e.fn.atomProp = function(e, t) {
1942
- if (typeof e == "string" && t === void 0) return console.warn(`${B.BINDING} ${H.BINDING.MISSING_SOURCE("atomProp")}`), this;
1943
- let n = typeof e == "string" ? { [e]: t } : e;
1944
- return Z(this, (e) => Kt(e, n));
2031
+ if (typeof e == "string") {
2032
+ if (t === void 0) return console.warn(`${H.BINDING} ${W.BINDING.MISSING_SOURCE("atomProp")}`), this;
2033
+ let n = { [e]: t };
2034
+ return Q(this, (e) => Kt(e, n));
2035
+ }
2036
+ return Q(this, (t) => Kt(t, e));
1945
2037
  }, e.fn.atomShow = function(e) {
1946
- return Z(this, (t) => qt(t, e, !1));
2038
+ return Q(this, (t) => qt(t, e, !1));
1947
2039
  }, e.fn.atomHide = function(e) {
1948
- return Z(this, (t) => qt(t, e, !0));
2040
+ return Q(this, (t) => qt(t, e, !0));
1949
2041
  }, e.fn.atomVal = function(e, t = {}) {
1950
- return Z(this, (n) => Jt(n, e, t));
2042
+ return Q(this, (n) => Jt(n, e, t));
1951
2043
  }, e.fn.atomChecked = function(e) {
1952
- return Z(this, (t) => Yt(t, e));
2044
+ return Q(this, (t) => Yt(t, e));
1953
2045
  }, e.fn.atomForm = function(e, t = {}) {
1954
- return Z(this, (n, r) => {
2046
+ return Q(this, (n, r) => {
1955
2047
  r instanceof HTMLFormElement && $t(r, e, t);
1956
2048
  });
1957
2049
  }, e.fn.atomOn = function(e, t) {
1958
- return Z(this, (n) => Zt(n, e, t));
2050
+ return Q(this, (n) => Zt(n, e, t));
1959
2051
  }, e.fn.atomBind = function(e) {
1960
2052
  let { text: t, html: n, class: r, css: i, attr: a, prop: o, show: s, hide: c, val: l, checked: u, form: d, on: f } = e, p = l === void 0 ? null : Array.isArray(l) ? {
1961
2053
  atom: l[0],
1962
- opts: l[1]
2054
+ options: l[1]
1963
2055
  } : {
1964
2056
  atom: l,
1965
- opts: void 0
2057
+ options: void 0
1966
2058
  };
1967
- return Z(this, (e) => {
1968
- t !== void 0 && Vt(e, t), n !== void 0 && Ht(e, n), r !== void 0 && Ut(e, r), i !== void 0 && Wt(e, i), a !== void 0 && Gt(e, a), o !== void 0 && Kt(e, o), s !== void 0 && qt(e, s, !1), c !== void 0 && qt(e, c, !0), p !== null && Jt(e, p.atom, p.opts), u !== void 0 && Yt(e, u), d !== void 0 && e.el instanceof HTMLFormElement && $t(e.el, d), f !== void 0 && Xt(e, f);
2059
+ return Q(this, (e) => {
2060
+ t !== void 0 && Vt(e, t), n !== void 0 && Ht(e, n), r !== void 0 && Ut(e, r), i !== void 0 && Wt(e, i), a !== void 0 && Gt(e, a), o !== void 0 && Kt(e, o), s !== void 0 && qt(e, s, !1), c !== void 0 && qt(e, c, !0), p && Jt(e, p.atom, p.options), u !== void 0 && Yt(e, u), d !== void 0 && e.el instanceof HTMLFormElement && $t(e.el, d), f !== void 0 && Xt(e, f);
1969
2061
  });
1970
2062
  }, e.fn.atomUnbind = function() {
1971
- for (let e = 0, t = this.length; e < t; e++) {
1972
- let t = this[e];
1973
- t.nodeType === 1 && Qt(t);
2063
+ let e = this.length;
2064
+ for (let t = 0; t < e; t++) {
2065
+ let e = this[t];
2066
+ e?.nodeType === 1 && Qt(e);
1974
2067
  }
1975
2068
  return this;
1976
2069
  };
1977
2070
  //#endregion
1978
2071
  //#region src/bindings/list.ts
1979
- var en = /* @__PURE__ */ new WeakMap(), tn = 0, nn = new nt(() => /* @__PURE__ */ new Map(), (e) => e.clear()), rn = new nt(() => /* @__PURE__ */ new Set(), (e) => e.clear()), Q = new tt(100, 1024);
2072
+ var en = /* @__PURE__ */ new WeakMap(), tn = 0, nn = new $e(() => /* @__PURE__ */ new Map(), (e) => e.clear()), rn = new $e(() => /* @__PURE__ */ new Set(), (e) => e.clear()), $ = new Qe(100, 1024);
1980
2073
  function an(e, t, n) {
1981
- t?.isConnected ? e.insertBefore(t) : e.appendTo(n);
2074
+ if (e instanceof Element) {
2075
+ n.insertBefore(e, t);
2076
+ return;
2077
+ }
2078
+ let r = e.length;
2079
+ for (let i = 0; i < r; i++) {
2080
+ let r = e[i];
2081
+ r && n.insertBefore(r, t);
2082
+ }
1982
2083
  }
1983
- function $(t) {
2084
+ function on(t) {
1984
2085
  return t instanceof Element ? e(t) : t;
1985
2086
  }
1986
- var on = class {
2087
+ var sn = class {
1987
2088
  constructor(e, t, n) {
1988
2089
  this.$container = e, this.containerSelector = t, this.onRemove = n, this.oldKeys = [], this.oldItems = [], this.oldNodes = [], this.removingKeys = /* @__PURE__ */ new Set(), this.$emptyEl = null, this.keyToIndex = /* @__PURE__ */ new Map(), this.statesBuffer = new Uint8Array(256), this.indicesBuffer = new Int32Array(256);
1989
2090
  }
1990
2091
  scheduleRemoval(e, t) {
1991
2092
  let n = () => {
1992
- this.fx?.isDisposed || (t.remove(), this.removingKeys.delete(e), U.log(B.LIST, `${this.containerSelector} removed item:`, e));
1993
- };
1994
- if (!this.onRemove) {
1995
- n();
1996
- return;
1997
- }
1998
- let r = this.onRemove(t);
2093
+ this.fx?.isDisposed || (t[0]?.isConnected && t.remove(), this.removingKeys.delete(e), G.enabled && G.log(H.LIST, `${this.containerSelector} removed item:`, e));
2094
+ }, r = this.onRemove?.(t);
1999
2095
  r instanceof Promise ? r.then(n, n) : n();
2000
2096
  }
2001
2097
  removeItem(e, t) {
2002
- for (let e = 0; e < t.length; e++) {
2003
- let n = t[e];
2004
- n instanceof Element && n.removeAttribute("data-atom-key");
2005
- }
2098
+ for (let e = 0; e < t.length; e++) t[e] instanceof Element && t[e].removeAttribute("data-atom-key");
2006
2099
  this.removingKeys.add(e), this.scheduleRemoval(e, t);
2007
2100
  }
2008
2101
  dispose() {
2009
- this.removingKeys.clear(), this.oldKeys.length = 0, this.oldItems.length = 0, this.oldNodes.length = 0, this.keyToIndex.clear(), this.$emptyEl?.remove(), this.$container.off(".atomList");
2010
- let e = new Uint8Array(), t = new Int32Array();
2011
- this.statesBuffer = e, this.indicesBuffer = t;
2102
+ this.removingKeys.clear(), this.oldKeys.length = 0, this.oldItems.length = 0, this.oldNodes.length = 0, this.keyToIndex.clear(), this.$emptyEl?.remove(), this.$container.off(".atomList"), this.statesBuffer = new Uint8Array(), this.indicesBuffer = new Int32Array();
2012
2103
  }
2013
2104
  ensureBuffers(e) {
2014
2105
  this.statesBuffer.length < e && (this.statesBuffer = new Uint8Array(Math.max(e, this.statesBuffer.length * 2))), this.indicesBuffer.length < e && (this.indicesBuffer = new Int32Array(Math.max(e, this.indicesBuffer.length * 2)));
2015
2106
  }
2016
2107
  };
2017
- function sn(t, n, r, i) {
2108
+ function cn(t, n, r, i) {
2018
2109
  if (t.$emptyEl && n > 0 && (t.$emptyEl.remove(), t.$emptyEl = null), n !== 0) return;
2019
2110
  let { oldKeys: a, oldNodes: o, onRemove: s } = t;
2020
2111
  if (s) for (let e = 0, n = a.length; e < n; e++) {
2021
- let n = a[e], r = o[e];
2022
- r && t.removeItem(n, $(r));
2112
+ let n = a[e];
2113
+ o[e] && t.removeItem(n, on(o[e]));
2023
2114
  }
2024
2115
  else {
2025
2116
  for (let e = 0, n = a.length; e < n; e++) t.removingKeys.delete(a[e]);
2026
2117
  r.empty();
2027
2118
  }
2028
- i && !t.$emptyEl && (t.$emptyEl = e(typeof i == "string" ? X(i) : i).appendTo(r)), Q.release(t.oldKeys), Q.release(t.oldItems), Q.release(t.oldNodes), t.oldKeys = [], t.oldItems = [], t.oldNodes = [];
2119
+ i && !t.$emptyEl && (t.$emptyEl = e(typeof i == "string" ? Z(i) : i), t.$emptyEl.appendTo(r)), $.release(t.oldKeys), $.release(t.oldItems), $.release(t.oldNodes), t.oldKeys = [], t.oldItems = [], t.oldNodes = [];
2029
2120
  }
2030
- function cn(e, t, n, r, i, a) {
2031
- let { oldKeys: o, oldItems: s, oldNodes: c, removingKeys: l, keyToIndex: u } = e, d = o.length, f = 0, p = d - 1, m = n - 1;
2121
+ function ln(e, t, n, r, i, a) {
2122
+ let { oldKeys: o, oldItems: s, oldNodes: c, removingKeys: l, keyToIndex: u } = e, d = o.length, f = 0, p = d - 1, m = n - 1, h = a || Oe;
2032
2123
  for (; f <= p && f <= m;) {
2033
2124
  let e = t[f], n = r(e, f);
2034
- if (o[f] !== n) break;
2035
- let i = s[f];
2036
- if (!(a ? a(i, e) : je(i, e))) break;
2037
- u.set(n, f), f++;
2125
+ if (o[f] !== n || !h(s[f], e)) break;
2126
+ u.set(n, f++);
2038
2127
  }
2039
2128
  for (; p >= f && m >= f;) {
2040
2129
  let e = t[m], n = r(e, m);
2041
- if (o[p] !== n) break;
2042
- let i = s[p];
2043
- if (!(a ? a(i, e) : je(i, e))) break;
2044
- u.set(n, m), p--, m--;
2045
- }
2046
- let h = nn.acquire();
2047
- for (let e = f; e <= p; e++) h.set(o[e], e);
2048
- let g = Q.acquire();
2049
- g.length = n;
2130
+ if (o[p] !== n || !h(s[p], e)) break;
2131
+ u.set(n, m--), p--;
2132
+ }
2133
+ let g = nn.acquire();
2134
+ for (let e = f; e <= p; e++) g.set(o[e], e);
2050
2135
  let _ = rn.acquire();
2051
2136
  e.ensureBuffers(n);
2052
- let v = Q.acquire();
2137
+ let v = $.acquire();
2053
2138
  v.length = n;
2054
- let y = Q.acquire();
2139
+ let y = $.acquire();
2055
2140
  y.length = n;
2056
- let b = e.statesBuffer, x = e.indicesBuffer, S = Q.acquire(), C = Q.acquire(), ee = Q.acquire();
2057
- for (let e = 0; e < f; e++) g[e] = o[e], v[e] = t[e], y[e] = c[e], b[e] = 3, x[e] = e;
2058
- for (let e = d - 1, r = n - 1; r > m; r--, e--) g[r] = o[e], v[r] = t[r], y[r] = c[e], b[r] = 3, x[r] = e;
2141
+ let b = $.acquire();
2142
+ b.length = n;
2143
+ let x = e.statesBuffer, S = e.indicesBuffer, C = $.acquire(), ee = $.acquire(), w = $.acquire();
2144
+ for (let e = 0; e < f; e++) v[e] = o[e], y[e] = t[e], b[e] = c[e], x[e] = 3, S[e] = e;
2145
+ for (let e = d - 1, r = n - 1; r > m; r--, e--) v[r] = o[e], y[r] = t[r], b[r] = c[e], x[r] = 3, S[r] = e;
2059
2146
  for (let n = f; n <= m; n++) {
2060
2147
  let o = t[n], d = r(o, n);
2061
- if (g[n] = d, v[n] = o, u.set(d, n), _.has(d)) {
2062
- U.warn(B.LIST, H.LIST.DUPLICATE_KEY(d, n, e.containerSelector)), x[n] = -1;
2148
+ if (v[n] = d, y[n] = o, u.set(d, n), _.has(d)) {
2149
+ G.warn(H.LIST, W.LIST.DUPLICATE_KEY(d, n, e.containerSelector)), S[n] = -1;
2063
2150
  continue;
2064
2151
  }
2065
2152
  _.add(d);
2066
- let f = h.get(d);
2153
+ let f = g.get(d);
2067
2154
  if (f === void 0) {
2068
- S.push(d), C.push(o), ee.push(n), x[n] = -1, b[n] = 1;
2155
+ C.push(d), ee.push(o), w.push(n), S[n] = -1, x[n] = 1;
2069
2156
  continue;
2070
2157
  }
2071
2158
  let p = s[f];
2072
- y[n] = c[f];
2073
- let m = a ? a(p, o) : je(p, o);
2074
- !i && p !== o && !m ? (S.push(d), C.push(o), ee.push(n), b[n] = 2) : b[n] = 0, x[n] = l.has(d) ? -1 : f;
2159
+ b[n] = c[f], !i && p !== o && !(a ? a(p, o) : Oe(p, o)) ? (C.push(d), ee.push(o), w.push(n), x[n] = 2) : x[n] = 0, S[n] = l.has(d) ? -1 : f;
2075
2160
  }
2076
- return nn.release(h), {
2077
- newKeys: g,
2161
+ return nn.release(g), {
2162
+ newKeys: v,
2078
2163
  newKeySet: _,
2079
- newItems: v,
2080
- newNodes: y,
2081
- newStates: b,
2082
- newIndices: x,
2083
- trKeys: S,
2084
- trItems: C,
2085
- trIdxs: ee,
2164
+ newItems: y,
2165
+ newNodes: b,
2166
+ newStates: x,
2167
+ newIndices: S,
2168
+ trKeys: C,
2169
+ trItems: ee,
2170
+ trIdxs: w,
2086
2171
  startIndex: f,
2087
2172
  oldEndIndex: p,
2088
2173
  newEndIndex: m
2089
2174
  };
2090
2175
  }
2091
- function ln(t, n, r) {
2092
- let { trKeys: i, trItems: a, trIdxs: o, newNodes: s, newStates: c } = t, l = i.length, u = n.render, d = Array(l), f = [], p = 0;
2176
+ function un(t, n, r) {
2177
+ let { trKeys: i, trItems: a, trIdxs: o, newNodes: s, newStates: c } = t, l = i.length, u = Array(l), d = [], f = 0;
2093
2178
  for (let e = 0; e < l; e++) {
2094
- let t = u(a[e], o[e]);
2095
- d[e] = t, typeof t == "string" && (f.push(t), p++);
2179
+ let t = n.render(a[e], o[e]);
2180
+ u[e] = t, typeof t == "string" && (d.push(t), f++);
2096
2181
  }
2097
- let m = null, h = f.length;
2098
- if (h > 0) if (h === 1) m = [X(f[0])];
2182
+ let p = null;
2183
+ if (d.length > 0) if (d.length === 1) p = [Z(d[0])];
2099
2184
  else {
2100
2185
  let e = `<template data-atom-sep="${(tn++).toString(36)}"></template>`;
2101
- m = X(f.join(e)).split(e);
2186
+ p = Z(d.join(e)).split(e);
2102
2187
  }
2103
- if (r && m && p === l && !n.bind && !n.onAdd && !n.onRemove && !n.events) return m;
2104
- let g = 0;
2188
+ if (r && p && f === l && !n.bind && !n.onAdd && !n.onRemove && !n.events) return p;
2189
+ let m = 0;
2105
2190
  for (let t = 0; t < l; t++) {
2106
- let n = d[t], r = e(typeof n == "string" ? m[g++] : n), a = o[t], l = c[a], u = i[t], f = String(u);
2191
+ let n = u[t], r = e(typeof n == "string" ? p[m++] : n), a = o[t], l = String(i[t]);
2107
2192
  for (let e = 0, t = r.length; e < t; e++) {
2108
2193
  let t = r[e];
2109
- t instanceof Element && t.setAttribute("data-atom-key", f);
2194
+ t instanceof Element && t.setAttribute("data-atom-key", l);
2110
2195
  }
2111
- if (l === 2) {
2196
+ if (c[a] === 2 && s[a]) {
2112
2197
  let e = s[a];
2113
- if (e) {
2114
- let t = $(e);
2115
- for (let e = 0, n = t.length; e < n; e++) {
2116
- let n = t[e];
2117
- n && K.cleanupTree(n);
2118
- }
2119
- t.replaceWith(r);
2198
+ if (e instanceof Element) J.cleanupTree(e);
2199
+ else for (let t = 0, n = e.length; t < n; t++) {
2200
+ let n = e[t];
2201
+ n instanceof Element && J.cleanupTree(n);
2120
2202
  }
2203
+ on(e).replaceWith(r);
2121
2204
  }
2122
2205
  s[a] = r.length === 1 ? r[0] : r;
2123
2206
  }
2124
2207
  return null;
2125
2208
  }
2126
- function un(e, t) {
2127
- let { startIndex: n, oldEndIndex: r, newKeySet: i } = t, { oldKeys: a, oldNodes: o } = e;
2209
+ function dn(e, t) {
2210
+ let { startIndex: n, oldEndIndex: r, newKeySet: i } = t;
2128
2211
  for (let t = n; t <= r; t++) {
2129
- let n = a[t];
2130
- if (i.has(n)) continue;
2131
- let r = o[t];
2132
- r && e.removeItem(n, $(r));
2212
+ let n = e.oldKeys[t];
2213
+ !i.has(n) && e.oldNodes[t] && e.removeItem(n, on(e.oldNodes[t]));
2133
2214
  }
2134
2215
  }
2135
- function dn(t, n, r, i, a, o) {
2136
- let { bind: s, update: c, onAdd: l } = a, { newKeys: u, newItems: d, newNodes: f, newStates: p, newIndices: m } = n, h = u.length, g = t.oldKeys.length === 0;
2137
- if (o !== null) {
2138
- r.innerHTML = o.join("");
2216
+ function fn(t, n, r, i, a) {
2217
+ let { newKeys: o, newItems: s, newNodes: c, newStates: l, newIndices: u } = n, d = o.length;
2218
+ if (a !== null) {
2219
+ r.innerHTML = a.join("");
2139
2220
  let n = r.firstElementChild;
2140
- for (let r = 0; r < h && n; r++) {
2141
- let i = u[r];
2142
- n.setAttribute("data-atom-key", String(i)), f[r] = n, p[r] = 0, t.removingKeys.delete(i), U.enabled && U.domUpdated(B.LIST, e(n), "list.add", d[r]), n = n.nextElementSibling;
2143
- }
2221
+ for (let r = 0; r < d && n; r++) n.setAttribute("data-atom-key", String(o[r])), c[r] = n, l[r] = 0, t.removingKeys.delete(o[r]), G.enabled && G.domUpdated(H.LIST, e(n), "list.add", s[r]), n = n.nextElementSibling;
2144
2222
  return;
2145
2223
  }
2146
- if (g) {
2224
+ if (t.oldKeys.length === 0) {
2147
2225
  let e = document.createDocumentFragment();
2148
- for (let t = 0; t < h; t++) {
2149
- let n = f[t];
2226
+ for (let t = 0; t < d; t++) {
2227
+ let n = c[t];
2150
2228
  if (n instanceof Element) e.appendChild(n);
2151
2229
  else for (let t = 0; t < n.length; t++) e.appendChild(n[t]);
2152
2230
  }
2153
2231
  r.appendChild(e);
2154
2232
  } else {
2155
2233
  let e = null, t = 2147483647;
2156
- for (let n = h - 1; n >= 0; n--) {
2157
- let r = m[n], a = f[n];
2158
- r !== -1 && r < t ? t = r : an($(a), e, i), e = a instanceof Element ? a : a[0] ?? null;
2159
- }
2160
- }
2161
- for (let e = 0; e < h; e++) {
2162
- let n = f[e], r = p[e];
2163
- if (r !== 3) {
2164
- let i = $(n), a = d[e];
2165
- if (r === 0 ? c?.(i, a, e) : s?.(i, a, e), r === 1) {
2166
- l?.(i);
2167
- let n = u[e];
2168
- t.removingKeys.delete(n), U.enabled && U.domUpdated(B.LIST, i, "list.add", d[e]);
2169
- }
2234
+ for (let n = d - 1; n >= 0; n--) {
2235
+ let i = u[n];
2236
+ i !== -1 && i < t ? t = i : an(c[n], e, r);
2237
+ let a = c[n];
2238
+ e = a instanceof Element ? a : a[0] ?? null;
2239
+ }
2240
+ }
2241
+ for (let e = 0; e < d; e++) {
2242
+ let n = l[e];
2243
+ if (n !== 3) {
2244
+ let r = on(c[e]), a = s[e];
2245
+ n === 0 ? i.update?.(r, a, e) : i.bind?.(r, a, e), n === 1 && (i.onAdd?.(r), t.removingKeys.delete(o[e]), G.enabled && G.domUpdated(H.LIST, r, "list.add", a));
2170
2246
  }
2171
2247
  }
2172
2248
  }
2173
2249
  e.fn.atomList = function(t, n) {
2174
- let { key: r, bind: i, update: a, onAdd: o, onRemove: s, empty: c, events: l, isEqual: u } = n, d = typeof r == "function" ? r : (e, t) => e[r], f = {
2175
- bind: i,
2176
- update: a,
2177
- onAdd: o,
2178
- onRemove: s,
2179
- events: l
2250
+ let r = typeof n.key == "function" ? n.key : (e) => e[n.key], i = {
2251
+ bind: n.bind,
2252
+ update: n.update,
2253
+ onAdd: n.onAdd,
2254
+ onRemove: n.onRemove,
2255
+ events: n.events
2180
2256
  };
2181
- for (let r = 0, i = this.length; r < i; r++) {
2182
- let i = this[r], o = e(i);
2183
- o.off(".atomList");
2184
- let p = en.get(i);
2185
- p && (p.fx.dispose(), p.ctx.dispose());
2186
- let m = R(i), h = new on(o, m, s), g = I(() => {
2187
- let e = t.value, r = e.length;
2188
- D(() => {
2189
- if (sn(h, r, o, c), r === 0) return;
2190
- U.log(B.LIST, `${m} updating with ${r} items`);
2191
- let t = cn(h, e, r, d, a, u), s = ln(t, n, h.oldKeys.length === 0);
2192
- if (un(h, t), dn(h, t, i, o, f, s), l) {
2193
- let { startIndex: e, oldEndIndex: n, newKeySet: r } = t;
2194
- for (let t = e; t <= n; t++) {
2195
- let e = h.oldKeys[t];
2196
- r.has(e) || h.keyToIndex.delete(e);
2197
- }
2198
- }
2199
- Q.release(h.oldKeys), Q.release(h.oldItems), Q.release(h.oldNodes), h.oldKeys = t.newKeys, h.oldItems = t.newItems, h.oldNodes = t.newNodes, rn.release(t.newKeySet), Q.release(t.trKeys), Q.release(t.trItems), Q.release(t.trIdxs);
2257
+ for (let a = 0, o = this.length; a < o; a++) {
2258
+ let o = this[a], s = e(o);
2259
+ s.off(".atomList");
2260
+ let c = en.get(o);
2261
+ c && (c.fx.dispose(), c.ctx.dispose());
2262
+ let l = new sn(s, B(o), n.onRemove), u = R(() => {
2263
+ let e = t.value, a = e.length;
2264
+ O(() => {
2265
+ if (cn(l, a, s, n.empty), a === 0) return;
2266
+ G.enabled && G.log(H.LIST, `${l.containerSelector} updating with ${a} items`);
2267
+ let t = ln(l, e, a, r, n.update, n.isEqual), c = un(t, n, l.oldKeys.length === 0);
2268
+ if (dn(l, t), fn(l, t, o, i, c), n.events) for (let e = t.startIndex; e <= t.oldEndIndex; e++) t.newKeySet.has(l.oldKeys[e]) || l.keyToIndex.delete(l.oldKeys[e]);
2269
+ $.release(l.oldKeys), $.release(l.oldItems), $.release(l.oldNodes), l.oldKeys = t.newKeys, l.oldItems = t.newItems, l.oldNodes = t.newNodes, rn.release(t.newKeySet), $.release(t.trKeys), $.release(t.trItems), $.release(t.trIdxs);
2200
2270
  });
2201
2271
  });
2202
- if (h.fx = g, l) for (let e in l) {
2203
- if (!z.call(l, e)) continue;
2204
- let t = l[e], n = e.indexOf(" "), r = n === -1 ? e : e.slice(0, n), i = (n === -1 ? null : e.slice(n + 1).trim()) || "> *";
2205
- o.on(`${r}.atomList`, i, function(e) {
2206
- let n = e.target.closest?.("[data-atom-key]");
2207
- if (!n) return;
2208
- let r = n.getAttribute("data-atom-key");
2209
- if (r === null) return;
2210
- let i = r;
2211
- if (!h.keyToIndex.has(r)) {
2212
- let e = Number(r);
2213
- !Number.isNaN(e) && h.keyToIndex.has(e) && (i = e);
2272
+ if (l.fx = u, n.events) for (let e in n.events) {
2273
+ if (!V.call(n.events, e)) continue;
2274
+ let t = e.indexOf(" "), r = t === -1 ? e : e.slice(0, t), i = t === -1 ? "> *" : e.slice(t + 1).trim(), a = n.events[e];
2275
+ s.on(`${r}.atomList`, i, function(e) {
2276
+ let t = e.target.closest?.("[data-atom-key]"), n = t?.getAttribute("data-atom-key");
2277
+ if (n == null) return;
2278
+ let r = n;
2279
+ if (!l.keyToIndex.has(n)) {
2280
+ let e = Number(n);
2281
+ !Number.isNaN(e) && l.keyToIndex.has(e) && (r = e);
2214
2282
  }
2215
- let a = h.keyToIndex.get(i);
2216
- a !== void 0 && t.call(n, h.oldItems[a], a, e);
2283
+ let i = l.keyToIndex.get(r);
2284
+ i !== void 0 && a.call(t, l.oldItems[i], i, e);
2217
2285
  });
2218
2286
  }
2219
- K.trackEffect(i, g), en.set(i, {
2220
- fx: g,
2221
- ctx: h
2222
- }), K.trackCleanup(i, () => {
2223
- h.dispose(), en.delete(i);
2287
+ J.trackEffect(o, u), en.set(o, {
2288
+ fx: u,
2289
+ ctx: l
2290
+ }), J.trackCleanup(o, () => {
2291
+ l.dispose(), en.delete(o);
2224
2292
  });
2225
2293
  }
2226
2294
  return this;
2227
2295
  };
2228
2296
  //#endregion
2229
2297
  //#region src/bindings/mount.ts
2230
- var fn = Object.freeze({});
2298
+ var pn = Object.freeze({});
2231
2299
  e.fn.atomMount = function(t, n) {
2232
- let r = n ?? fn;
2233
- for (let n = 0, i = this.length; n < i; n++) {
2234
- let i = this[n];
2235
- if (!i) continue;
2236
- K.cleanupTree(i);
2237
- let a = e(i), o;
2238
- try {
2239
- o = D(() => t(a, r));
2240
- } catch (e) {
2241
- U.error(B.MOUNT, H.MOUNT.ERROR(t.name), e);
2242
- continue;
2300
+ let r = n ?? pn, i = t.name || "Component";
2301
+ for (let n = 0, a = this.length; n < a; n++) {
2302
+ let a = this[n];
2303
+ if (a) {
2304
+ J.cleanupTree(a);
2305
+ try {
2306
+ let n = O(() => t(e(a), r));
2307
+ typeof n == "function" && J.setComponentCleanup(a, n);
2308
+ } catch (e) {
2309
+ G.error(H.MOUNT, W.MOUNT.ERROR(i), e);
2310
+ }
2243
2311
  }
2244
- typeof o == "function" && K.setComponentCleanup(i, o);
2245
2312
  }
2246
2313
  return this;
2247
2314
  }, e.fn.atomUnmount = function() {
@@ -2253,141 +2320,117 @@ e.fn.atomMount = function(t, n) {
2253
2320
  };
2254
2321
  //#endregion
2255
2322
  //#region src/features/route.ts
2256
- function pn(e, t) {
2323
+ function mn(e, t) {
2257
2324
  try {
2258
- return history.pushState(e, "", t), !0;
2325
+ history.pushState(e, "", t);
2259
2326
  } catch (e) {
2260
- return U.warn(B.ROUTE, "PushState failed (likely file:// protocol or security restriction). UI will update, but URL will not.", e), !1;
2327
+ G.warn(H.ROUTE, "PushState failed (likely file:// protocol or security restriction). UI will update, but URL will not.", e);
2261
2328
  }
2262
2329
  }
2263
- var mn = class {
2330
+ var hn = class {
2264
2331
  constructor(t) {
2265
2332
  this.isDestroyed = !1, this.previousRoute = "", this.cleanups = [], this.templateCache = /* @__PURE__ */ new Map(), this.routeCleanups = [], this.lastRawQuery = "", this.cachedParams = {}, this.config = {
2266
- ...t,
2267
- mode: t.mode ?? V.mode,
2268
- basePath: t.basePath ?? V.basePath,
2269
- autoBindLinks: t.autoBindLinks ?? V.autoBindLinks,
2270
- activeClass: t.activeClass ?? V.activeClass
2271
- }, this.isHistoryMode = this.config.mode === "history", this.$target = e(this.config.target), this.normalizedBasePath = this.config.basePath?.replace(/\/$/, "") || "", this.activeClass = this.config.activeClass ?? V.activeClass, this.previousUrl = this.isHistoryMode ? window.location.pathname + window.location.search : window.location.hash, this.currentRouteAtom = O(this.getRouteName()), this.currentRoute = this.currentRouteAtom, this.queryParamsAtom = O(this.getQueryParams()), this.queryParams = F(() => this.queryParamsAtom.value), this.handleUrlChange = this.handleUrlChange.bind(this), this.destroy = this.destroy.bind(this), this.init();
2333
+ mode: U.mode,
2334
+ basePath: U.basePath,
2335
+ autoBindLinks: U.autoBindLinks,
2336
+ activeClass: U.activeClass,
2337
+ ...t
2338
+ }, this.isHistoryMode = this.config.mode === "history", this.basePath = this.config.basePath.replace(/\/$/, ""), this.activeClass = this.config.activeClass, this.$target = e(this.config.target), this.previousUrl = this.isHistoryMode ? location.pathname + location.search : location.hash, this.currentRouteAtom = k(this.getRouteName()), this.currentRoute = this.currentRouteAtom, this.queryParamsAtom = k(this.getQueryParams()), this.queryParams = L(() => this.queryParamsAtom.value), this.init();
2272
2339
  }
2273
2340
  init() {
2274
- let e = this.isHistoryMode ? "popstate" : "hashchange";
2275
- window.addEventListener(e, this.handleUrlChange), this.cleanups.push(() => window.removeEventListener(e, this.handleUrlChange));
2276
- let t = I(() => {
2341
+ let e = this.isHistoryMode ? "popstate" : "hashchange", t = this.handleUrlChange.bind(this);
2342
+ window.addEventListener(e, t), this.cleanups.push(() => window.removeEventListener(e, t));
2343
+ let n = R(() => {
2277
2344
  let e = this.currentRouteAtom.value;
2278
- D(() => {
2279
- let e = this.routeCleanups;
2280
- for (let t = 0, n = e.length; t < n; t++) try {
2281
- e[t]();
2282
- } catch (e) {
2283
- U.warn(B.ROUTE, "Cleanup error during route transition:", e);
2284
- }
2285
- e.length = 0;
2345
+ O(() => {
2346
+ for (let e of this.routeCleanups) try {
2347
+ e();
2348
+ } catch {}
2349
+ this.routeCleanups.length = 0;
2286
2350
  }), this.renderRoute(e);
2287
2351
  });
2288
- this.cleanups.push(() => t.dispose()), this.setupAutoBindLinks(), this.$target[0] && K.trackCleanup(this.$target[0], this.destroy);
2352
+ this.cleanups.push(() => n.dispose()), this.setupAutoBindLinks(), this.$target[0] && J.trackCleanup(this.$target[0], () => this.destroy());
2289
2353
  }
2290
2354
  getRouteName() {
2291
- let e = this.config.default;
2355
+ let { default: e } = this.config;
2292
2356
  if (this.isHistoryMode) {
2293
- let t = window.location.pathname, n = 0, r = this.normalizedBasePath;
2294
- return r && t.startsWith(r) && (n = r.length), t.charCodeAt(n) === 47 && n++, (n === 0 ? t : t.substring(n)) || e;
2357
+ let t = this.basePath, n = location.pathname;
2358
+ return t && n.startsWith(t) && (n = n.substring(t.length)), n.replace(/^\//, "") || e;
2295
2359
  }
2296
- let t = window.location.hash;
2297
- if (t.length <= 1) return e;
2298
- let n = t.indexOf("?");
2299
- return (n === -1 ? t.substring(1) : t.substring(1, n)) || e;
2360
+ return location.hash.split("?")[0].substring(1) || e;
2300
2361
  }
2301
2362
  getQueryParams() {
2302
- let e = "";
2303
- if (this.isHistoryMode) e = window.location.search.substring(1);
2304
- else {
2305
- let t = window.location.hash, n = t.indexOf("?");
2306
- n !== -1 && (e = t.substring(n + 1));
2307
- }
2308
- if (e === this.lastRawQuery) return this.cachedParams;
2309
- let t = {};
2310
- e && new URLSearchParams(e).forEach((e, n) => {
2311
- t[n] = e;
2363
+ let e = location.hash, t = e.indexOf("?"), n = this.isHistoryMode ? location.search.substring(1) : t === -1 ? "" : e.substring(t + 1);
2364
+ if (n === this.lastRawQuery) return this.cachedParams;
2365
+ this.lastRawQuery = n;
2366
+ let r = {}, i = 0;
2367
+ n && new URLSearchParams(n).forEach((e, t) => {
2368
+ r[t] = e, i++;
2312
2369
  });
2313
- let n = !1, r = this.cachedParams, i = Object.keys(r), a = Object.keys(t);
2314
- if (i.length !== a.length) n = !0;
2315
- else for (let e = 0, i = a.length; e < i; e++) {
2316
- let i = a[e];
2317
- if (r[i] !== t[i]) {
2318
- n = !0;
2370
+ let a = 0;
2371
+ for (let e in this.cachedParams) a++;
2372
+ let o = i !== a;
2373
+ if (!o) {
2374
+ for (let e in r) if (r[e] !== this.cachedParams[e]) {
2375
+ o = !0;
2319
2376
  break;
2320
2377
  }
2321
2378
  }
2322
- return n && (this.cachedParams = t), this.lastRawQuery = e, e.includes("%"), this.cachedParams;
2379
+ return o && (n.indexOf("%"), this.cachedParams = r), this.cachedParams;
2323
2380
  }
2324
2381
  setUrl(e) {
2325
- if (this.isHistoryMode) {
2326
- let t = `${this.normalizedBasePath}/${e}`;
2327
- pn(null, t), this.previousUrl = t;
2328
- } else {
2329
- let t = `#${e}`;
2330
- window.location.hash = t, this.previousUrl = t;
2331
- }
2382
+ let t = this.isHistoryMode ? `${this.basePath}/${e}` : `#${e}`;
2383
+ this.isHistoryMode ? mn(null, t) : location.hash = t, this.previousUrl = this.isHistoryMode ? t : location.hash;
2332
2384
  }
2333
2385
  restoreUrl() {
2334
- this.isHistoryMode ? pn(null, this.previousUrl) : window.location.hash = this.previousUrl;
2335
- }
2336
- getCurrentUrl() {
2337
- return this.isHistoryMode ? window.location.pathname + window.location.search : window.location.hash;
2338
- }
2339
- getRouteConfig(e) {
2340
- let { routes: t, notFound: n } = this.config, r = t[e];
2341
- return !r && n && (r = t[n]), r || (U.warn(B.ROUTE, H.ROUTE.NOT_FOUND(e)), null);
2342
- }
2343
- renderTemplate(e) {
2344
- let t = this.templateCache.get(e);
2345
- if (!t) {
2346
- let n = document.querySelector(e);
2347
- if (!n || !(n instanceof HTMLTemplateElement)) return U.warn(B.ROUTE, H.ROUTE.TEMPLATE_NOT_FOUND(e)), !1;
2348
- t = n, this.templateCache.set(e, t);
2349
- }
2350
- let n = t.content.cloneNode(!0);
2351
- return this.$target.append(n), !0;
2386
+ this.isHistoryMode ? mn(null, this.previousUrl) : location.hash = this.previousUrl;
2352
2387
  }
2353
2388
  renderRoute(e) {
2354
- if (this.isDestroyed) return;
2355
- let t = this.$target[0];
2356
- if (!t) {
2357
- U.warn(B.ROUTE, H.ROUTE.TARGET_NOT_FOUND(this.config.target));
2389
+ if (this.isDestroyed || !this.$target[0]) return;
2390
+ let { routes: t, notFound: n, beforeTransition: r, afterTransition: i } = this.config, a = t[e] ?? (n ? t[n] : void 0);
2391
+ if (!a) {
2392
+ G.warn(H.ROUTE, W.ROUTE.NOT_FOUND(e));
2358
2393
  return;
2359
2394
  }
2360
- let n = this.getRouteConfig(e);
2361
- if (!n) return;
2362
- let r = this.getQueryParams(), i = this.previousRoute, { beforeTransition: a, afterTransition: o } = this.config;
2363
- a && D(() => a(i, e)), this.$target.empty();
2364
- let s = r, { onEnter: c } = n;
2365
- if (c) {
2366
- let e = D(() => c(r, this));
2367
- e !== void 0 && (s = {
2368
- ...r,
2395
+ let o = this.getQueryParams(), s = this.previousRoute;
2396
+ r && O(() => r(s, e)), this.$target.empty();
2397
+ let c = o;
2398
+ if (a.onEnter) {
2399
+ let e = O(() => a.onEnter(o, this));
2400
+ e && (c = {
2401
+ ...o,
2369
2402
  ...e
2370
2403
  });
2371
2404
  }
2372
- let l = (e) => {
2373
- this.routeCleanups.push(e);
2374
- };
2375
- n.render ? n.render(t, e, s, l, this) : n.template && this.renderTemplate(n.template) && n.onMount && n.onMount(this.$target.children(), l, this), o && D(() => o(i, e)), this.previousRoute = e;
2405
+ let l = (e) => this.routeCleanups.push(e);
2406
+ if (a.render) a.render(this.$target[0], e, c, l, this);
2407
+ else if (a.template) {
2408
+ let e = this.templateCache.get(a.template);
2409
+ if (!e) {
2410
+ let t = document.querySelector(a.template);
2411
+ if (t instanceof HTMLTemplateElement) e = t, this.templateCache.set(a.template, e);
2412
+ else {
2413
+ G.warn(H.ROUTE, W.ROUTE.TEMPLATE_NOT_FOUND(a.template));
2414
+ return;
2415
+ }
2416
+ }
2417
+ this.$target.append(e.content.cloneNode(!0)), a.onMount && a.onMount(this.$target.children(), l, this);
2418
+ }
2419
+ i && O(() => i(s, e)), this.previousRoute = e;
2376
2420
  }
2377
2421
  handleUrlChange() {
2378
2422
  if (this.isDestroyed) return;
2379
- let e = this.getCurrentUrl();
2423
+ let e = this.isHistoryMode ? location.pathname + location.search : location.hash;
2380
2424
  if (e === this.previousUrl) return;
2381
- let t = this.getRouteName(), n = this.currentRouteAtom.peek(), r = this.getQueryParams();
2425
+ let t = this.getRouteName(), n = this.currentRouteAtom.peek();
2382
2426
  if (n !== t) {
2383
- let e = this.config.routes[n];
2384
- if (e?.onLeave && D(() => e.onLeave(this)) === !1) {
2427
+ if (O(() => this.config.routes[n]?.onLeave?.(this)) === !1) {
2385
2428
  this.restoreUrl();
2386
2429
  return;
2387
2430
  }
2388
- this.currentRouteAtom.value = t, this.queryParamsAtom.value = r;
2389
- } else this.queryParamsAtom.value = r;
2390
- this.previousUrl = e;
2431
+ this.currentRouteAtom.value = t;
2432
+ }
2433
+ this.queryParamsAtom.value = this.getQueryParams(), this.previousUrl = e;
2391
2434
  }
2392
2435
  setupAutoBindLinks() {
2393
2436
  if (!this.config.autoBindLinks) return;
@@ -2396,123 +2439,122 @@ var mn = class {
2396
2439
  let t = e.currentTarget.dataset.route;
2397
2440
  t != null && this.navigate(t);
2398
2441
  };
2399
- e(document).on("click", "[data-route]", t), this.cleanups.push(() => {
2400
- e(document).off("click", "[data-route]", t);
2401
- });
2402
- let n = this.activeClass, r = [], i = I(() => {
2403
- let e = this.currentRouteAtom.value;
2404
- D(() => {
2405
- for (let e = 0, t = r.length; e < t; e++) {
2406
- let t = r[e];
2407
- t.classList.remove(n), t.removeAttribute("aria-current");
2442
+ e(document).on("click", "[data-route]", t), this.cleanups.push(() => e(document).off("click", "[data-route]", t));
2443
+ let n = [], r = R(() => {
2444
+ let e = this.currentRouteAtom.value, t = this.activeClass;
2445
+ O(() => {
2446
+ let r = n.length;
2447
+ for (let e = 0; e < r; e++) {
2448
+ let r = n[e];
2449
+ r.classList.remove(t), r.removeAttribute("aria-current");
2408
2450
  }
2409
2451
  try {
2410
- let t = e.replace(/"/g, "\\\""), i = document.querySelectorAll(`[data-route="${t}"]`), a = i.length, o = Array(a);
2452
+ let r = `[data-route="${e.replace(/"/g, "\\\"")}"]`, i = Array.from(document.querySelectorAll(r)), a = i.length;
2411
2453
  for (let e = 0; e < a; e++) {
2412
- let t = i[e];
2413
- t.classList.add(n), t.setAttribute("aria-current", "page"), o[e] = t;
2454
+ let n = i[e];
2455
+ n.classList.add(t), n.setAttribute("aria-current", "page");
2414
2456
  }
2415
- r = o;
2457
+ n = i;
2416
2458
  } catch {
2417
- r = [];
2459
+ n = [];
2418
2460
  }
2419
2461
  });
2420
2462
  });
2421
- this.cleanups.push(() => i.dispose());
2463
+ this.cleanups.push(() => r.dispose());
2422
2464
  }
2423
2465
  navigate(e) {
2424
2466
  if (this.isDestroyed) return;
2425
- let t = this.currentRouteAtom.peek(), n = this.config.routes[t];
2426
- if (n?.onLeave && n.onLeave(this) === !1) return;
2427
- let r = e || this.config.default;
2428
- if (!r) {
2429
- U.warn(B.ROUTE, "navigate() called with empty routeName and no default configured.");
2430
- return;
2431
- }
2432
- this.setUrl(r), this.queryParamsAtom.value = {}, this.currentRouteAtom.value = r;
2467
+ let t = this.currentRouteAtom.peek();
2468
+ if (this.config.routes[t]?.onLeave?.(this) === !1) return;
2469
+ let n = e || this.config.default;
2470
+ n && (this.setUrl(n), this.queryParamsAtom.value = {}, this.currentRouteAtom.value = n);
2433
2471
  }
2434
2472
  destroy() {
2435
- if (this.isDestroyed) return;
2436
- this.isDestroyed = !0;
2437
- let e = this.cleanups;
2438
- this.cleanups = [];
2439
- for (let t = 0, n = e.length; t < n; t++) try {
2440
- e[t]();
2441
- } catch (e) {
2442
- U.warn(B.ROUTE, "Cleanup error during destroy:", e);
2473
+ if (!this.isDestroyed) {
2474
+ this.isDestroyed = !0;
2475
+ for (let e of this.cleanups) try {
2476
+ e();
2477
+ } catch {}
2478
+ this.templateCache.clear();
2443
2479
  }
2444
- this.templateCache.clear();
2445
2480
  }
2446
2481
  };
2447
- function hn(e) {
2448
- return new mn(e);
2482
+ function gn(e) {
2483
+ return new hn(e);
2449
2484
  }
2450
- e.extend({ route: hn });
2485
+ e.extend({ route: gn });
2451
2486
  //#endregion
2452
2487
  //#region src/features/fetch.ts
2453
- var gn = class {
2454
- constructor(e, t) {
2455
- this.abortController = null, this.isStaticUrl = typeof e == "string", this.isStaticUrl ? this.staticUrl = e : this.getUrl = e, typeof t.ajaxOptions == "function" ? (this.ajaxOptionsFn = t.ajaxOptions, this.staticOptions = {}) : this.staticOptions = { ...t.ajaxOptions }, t.method !== void 0 && (this.staticOptions.method = t.method), t.headers !== void 0 && (this.staticOptions.headers = {
2456
- ...this.staticOptions.headers,
2457
- ...t.headers
2458
- }), this.transformFn = t.transform, this.onErrorFn = t.onError, this.execute = this.execute.bind(this);
2488
+ var _n = class {
2489
+ constructor(t, n) {
2490
+ this.abortController = null, this.execute = async () => {
2491
+ this.abortController?.abort(), this.abortController = new AbortController();
2492
+ let { signal: t } = this.abortController, n = this.ajaxOptionsFn?.() ?? {}, r = {
2493
+ ...this.staticOptions,
2494
+ ...n,
2495
+ headers: {
2496
+ ...this.staticOptions.headers,
2497
+ ...n.headers
2498
+ },
2499
+ url: this.isStaticUrl ? this.staticUrl : this.getUrl(),
2500
+ success: void 0,
2501
+ error: void 0,
2502
+ complete: void 0
2503
+ }, i = e.ajax(r);
2504
+ t.onabort = () => i.abort(), t.aborted && i.abort();
2505
+ try {
2506
+ let e = await i;
2507
+ return this.transformFn ? this.transformFn(e) : e;
2508
+ } catch (e) {
2509
+ if (t.aborted) {
2510
+ let e = /* @__PURE__ */ Error("AbortError");
2511
+ throw e.name = "AbortError", e;
2512
+ }
2513
+ return this.handleError(e);
2514
+ } finally {
2515
+ t.onabort = null, this.abortController?.signal === t && (this.abortController = null);
2516
+ }
2517
+ };
2518
+ let r = typeof t == "string";
2519
+ this.isStaticUrl = r, r ? (this.staticUrl = t, this.getUrl = () => this.staticUrl) : this.getUrl = t, this.ajaxOptionsFn = typeof n.ajaxOptions == "function" ? n.ajaxOptions : void 0;
2520
+ let i = typeof n.ajaxOptions == "object" ? n.ajaxOptions : {};
2521
+ this.staticOptions = {
2522
+ ...i,
2523
+ method: n.method,
2524
+ headers: {
2525
+ ...i?.headers,
2526
+ ...n.headers
2527
+ }
2528
+ }, this.transformFn = n.transform, this.onErrorFn = n.onError;
2459
2529
  }
2460
2530
  abort() {
2461
2531
  this.abortController?.abort();
2462
2532
  }
2463
- async execute() {
2464
- this.abortController?.abort(), this.abortController = new AbortController();
2465
- let t = this.abortController.signal, n = this.ajaxOptionsFn ? this.ajaxOptionsFn() : {}, r = e.extend(!0, {}, this.staticOptions, n);
2466
- r.success = void 0, r.error = void 0, r.complete = void 0, r.url = this.isStaticUrl ? this.staticUrl : this.getUrl();
2467
- let i = e.ajax(r);
2468
- t.onabort = () => i.abort(), t.aborted && i.abort();
2469
- let a;
2470
- try {
2471
- a = await i;
2472
- } catch (e) {
2473
- if (t.aborted) {
2474
- let e = /* @__PURE__ */ Error("AbortError");
2475
- throw e.name = "AbortError", e;
2476
- }
2477
- let n;
2478
- if (e && e.readyState !== void 0) {
2479
- let t = e;
2480
- n = /* @__PURE__ */ Error(`Network Error: ${t.statusText || "Unknown"} (${t.status})`), n.jqXHR = t;
2481
- } else n = e instanceof Error ? e : Error(String(e ?? "Unknown network error"));
2482
- let r = this.onErrorFn;
2483
- if (r) try {
2484
- r(n);
2485
- } catch {}
2486
- throw n;
2487
- } finally {
2488
- t.onabort = null, this.abortController?.signal === t && (this.abortController = null);
2489
- }
2490
- let o = this.transformFn;
2491
- if (o) try {
2492
- return o(a);
2493
- } catch (e) {
2494
- let t = this.onErrorFn;
2495
- if (t) try {
2496
- t(e);
2497
- } catch {}
2498
- throw e;
2499
- }
2500
- return a;
2533
+ handleError(e) {
2534
+ let t;
2535
+ if (e && e.readyState !== void 0) {
2536
+ let n = e;
2537
+ t = /* @__PURE__ */ Error(`Network Error: ${n.statusText || "Unknown"} (${n.status})`), t.jqXHR = n;
2538
+ } else t = e instanceof Error ? e : Error(String(e ?? "Unknown error"));
2539
+ if (this.onErrorFn) try {
2540
+ this.onErrorFn(t);
2541
+ } catch {}
2542
+ throw t;
2501
2543
  }
2502
2544
  };
2503
2545
  //#endregion
2504
2546
  //#region src/index.ts
2505
2547
  e.extend({ atomFetch(e, t) {
2506
- let n = new gn(e, t), r = !(t.eager ?? !0), i = F(n.execute, {
2548
+ let n = new _n(e, t), r = L(n.execute, {
2507
2549
  defaultValue: t.defaultValue,
2508
- lazy: r
2550
+ lazy: t.eager === !1
2509
2551
  });
2510
- return Object.assign(i, { abort: () => n.abort() });
2552
+ return Object.assign(r, { abort: () => n.abort() });
2511
2553
  } }), e(() => {
2512
- mt(), st(document.body);
2554
+ pt(), ot(document.body);
2513
2555
  });
2514
- var _n = e;
2556
+ var vn = e;
2515
2557
  //#endregion
2516
- export { O as atom, Ye as atomLens, ke as batch, Xe as composeLens, F as computed, _n as default, ct as disableAutoCleanup, ht as disablejQueryOverrides, I as effect, st as enableAutoCleanup, mt as enablejQueryOverrides, be as isAtom, xe as isComputed, L as isReactive, Ze as lensFor, $e as nextTick, K as registry, D as untracked };
2558
+ export { k as atom, qe as atomLens, Ee as batch, Je as composeLens, L as computed, vn as default, st as disableAutoCleanup, mt as disablejQueryOverrides, R as effect, ot as enableAutoCleanup, pt as enablejQueryOverrides, ve as isAtom, ye as isComputed, z as isReactive, Ye as lensFor, Ze as nextTick, J as registry, O as untracked };
2517
2559
 
2518
2560
  //# sourceMappingURL=index.mjs.map