@but212/atom-effect-jquery 0.22.2 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,14 +1,14 @@
1
- import l from "jquery";
2
- import { default as Ys } from "jquery";
3
- const ut = {
1
+ import h from "jquery";
2
+ import { default as zs } from "jquery";
3
+ const rt = {
4
4
  IDLE: "idle",
5
5
  PENDING: "pending",
6
6
  RESOLVED: "resolved",
7
7
  REJECTED: "rejected"
8
- }, k = {
8
+ }, w = {
9
9
  DISPOSED: 1,
10
10
  EXECUTING: 8
11
- }, ue = {
11
+ }, Qt = {
12
12
  DISPOSED: 1,
13
13
  /** Marker bit: identifies this node as a computed. */
14
14
  IS_COMPUTED: 2,
@@ -23,7 +23,7 @@ const ut = {
23
23
  DISPOSED: 1,
24
24
  SYNC: 8,
25
25
  NOTIFICATION_SCHEDULED: 16
26
- }, q = {
26
+ }, j = {
27
27
  // Infinite loop protection
28
28
  MAX_EXECUTIONS_PER_SECOND: 1e3,
29
29
  MAX_EXECUTIONS_PER_EFFECT: 100,
@@ -33,81 +33,61 @@ const ut = {
33
33
  MIN_FLUSH_ITERATIONS: 10,
34
34
  // Memory management
35
35
  BATCH_QUEUE_SHRINK_THRESHOLD: 1e3
36
- }, ke = {
36
+ }, Ce = {
37
37
  WARN_INFINITE_LOOP: !0
38
- }, Zt = {
38
+ }, $t = {
39
39
  MAX_ASYNC_RETRIES: 3,
40
40
  MAX_PROMISE_ID: Number.MAX_SAFE_INTEGER - 1
41
- }, yt = 1073741823, xe = typeof process < "u" && process.env && !1 || !1, Pe = Object.freeze([]);
42
- class et extends Error {
43
- constructor(t, e = null, n = !0) {
44
- super(t), this.cause = e, this.recoverable = n, this.name = "AtomError";
41
+ }, Y = {
42
+ /** Uninitialized epoch marker. Used as initial value before any flush has occurred. */
43
+ UNINITIALIZED: -1
44
+ }, mt = 1073741823, Te = typeof process < "u" && process.env && !1 || !1, Se = Object.freeze([]);
45
+ function Pt(n, t, e) {
46
+ const s = /* @__PURE__ */ new Map();
47
+ for (let i = 0; i < t.length; i++) {
48
+ const o = t[i];
49
+ o?.unsub && s.set(o.node, o.unsub);
50
+ }
51
+ for (let i = 0; i < n.length; i++) {
52
+ const o = n[i];
53
+ if (!o) continue;
54
+ const r = o.node, c = s.get(r);
55
+ c !== void 0 ? (o.unsub = c, s.delete(r)) : o.unsub || (o.unsub = r.subscribe(e));
45
56
  }
57
+ for (const i of s.values())
58
+ i();
46
59
  }
47
- class j extends et {
48
- constructor(t, e = null) {
49
- super(t, e, !0), this.name = "ComputedError";
60
+ class ht {
61
+ constructor(t, e, s = void 0) {
62
+ this.node = t, this.version = e, this.unsub = s;
50
63
  }
51
64
  }
52
- class Z extends et {
53
- constructor(t, e = null) {
54
- super(t, e, !1), this.name = "EffectError";
65
+ class Ne {
66
+ constructor(t, e) {
67
+ this.fn = t, this.sub = e;
55
68
  }
56
- }
57
- class Lt extends et {
58
- constructor(t, e = null) {
59
- super(t, e, !1), this.name = "SchedulerError";
69
+ notify(t, e) {
70
+ this.fn ? this.fn(t, e) : this.sub && this.sub.execute();
60
71
  }
61
72
  }
62
- const $e = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), Me = /* @__PURE__ */ Symbol("AtomEffect.Type"), Ut = /* @__PURE__ */ Symbol("AtomEffect.NoDefaultValue"), Ct = {
63
- // Dev mode flag
64
- enabled: xe,
65
- warnInfiniteLoop: ke.WARN_INFINITE_LOOP,
66
- warn(s, t) {
67
- },
68
- checkCircular(s, t) {
69
- if (s === t)
70
- throw new j("Direct circular dependency detected");
71
- },
72
- attachDebugInfo(s, t, e) {
73
- },
74
- getDebugName: (s) => s?.[$e],
75
- getDebugType: (s) => s?.[Me]
76
- };
77
- let Fe = 1;
78
- const Be = () => Fe++;
79
- function fe(s, t, e) {
80
- if (typeof t == "function") {
81
- const i = t;
82
- if (e.some((o) => o && o.fn === i)) return;
83
- e.push(new Mt(i, void 0));
84
- return;
85
- }
86
- if ("addDependency" in t) {
87
- t.addDependency(s);
88
- return;
73
+ class W extends Error {
74
+ constructor(t, e = null, s = !0) {
75
+ super(t), this.cause = e, this.recoverable = s, this.name = "AtomError";
89
76
  }
90
- const n = t;
91
- e.some((i) => i && i.sub === n) || e.push(new Mt(void 0, n));
92
77
  }
93
- function te(s, t, e) {
94
- const n = /* @__PURE__ */ new Map();
95
- t.forEach((i) => {
96
- i?.unsub && n.set(i.node, i.unsub);
97
- }), s.forEach((i) => {
98
- if (!i) return;
99
- const o = i.node, r = n.get(o);
100
- r !== void 0 ? (i.unsub = r, n.delete(o)) : (Ct.checkCircular(o, e), i.unsub = o.subscribe(e));
101
- }), n.forEach((i) => i());
78
+ class z extends W {
79
+ constructor(t, e = null) {
80
+ super(t, e, !0), this.name = "ComputedError";
81
+ }
102
82
  }
103
- class $t {
104
- constructor(t, e, n = void 0) {
105
- this.node = t, this.version = e, this.unsub = n;
83
+ class q extends W {
84
+ constructor(t, e = null) {
85
+ super(t, e, !1), this.name = "EffectError";
106
86
  }
107
87
  }
108
- class Mt {
109
- constructor(t, e) {
110
- this.fn = t, this.sub = e;
88
+ class yt extends W {
89
+ constructor(t, e = null) {
90
+ super(t, e, !1), this.name = "SchedulerError";
111
91
  }
112
92
  }
113
93
  const b = {
@@ -127,82 +107,140 @@ const b = {
127
107
  EFFECT_CLEANUP_FAILED: "Effect cleanup failed",
128
108
  EFFECT_DISPOSED: "Attempted to run disposed effect",
129
109
  // Scheduler Errors
130
- SCHEDULER_FLUSH_OVERFLOW: (s, t) => `Maximum flush iterations (${s}) exceeded. ${t} jobs dropped. Possible infinite loop.`,
110
+ SCHEDULER_FLUSH_OVERFLOW: (n, t) => `Maximum flush iterations (${n}) exceeded. ${t} jobs dropped. Possible infinite loop.`,
131
111
  // System / Debug
132
112
  CALLBACK_ERROR_IN_ERROR_HANDLER: "Exception encountered in onError handler",
133
113
  // Effect frequency
134
114
  EFFECT_FREQUENCY_LIMIT_EXCEEDED: "Effect executed too frequently within 1 second. Suspected infinite loop.",
135
115
  SCHEDULER_CALLBACK_MUST_BE_FUNCTION: "Scheduler callback must be a function",
136
- SCHEDULER_END_BATCH_WITHOUT_START: "endBatch() called without matching startBatch(). Ignoring."
116
+ SCHEDULER_END_BATCH_WITHOUT_START: "endBatch() called without matching startBatch(). Ignoring.",
117
+ BATCH_CALLBACK_MUST_BE_FUNCTION: "Batch callback must be a function"
118
+ }, be = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), Re = /* @__PURE__ */ Symbol("AtomEffect.Type"), Ct = /* @__PURE__ */ Symbol("AtomEffect.NoDefaultValue"), Lt = {
119
+ // Dev mode flag
120
+ enabled: Te,
121
+ warnInfiniteLoop: Ce.WARN_INFINITE_LOOP,
122
+ warn(n, t) {
123
+ },
124
+ attachDebugInfo(n, t, e) {
125
+ },
126
+ getDebugName: (n) => n?.[be],
127
+ getDebugType: (n) => n?.[Re]
137
128
  };
138
- function tt(s, t, e) {
139
- if (s instanceof et)
140
- return s;
141
- const n = s instanceof Error, i = n ? s.message : String(s), o = n ? s : void 0, r = `${n ? s.constructor.name : "Unexpected error"} (${e}): ${i}`;
129
+ let ve = 1;
130
+ const De = () => ve++;
131
+ function Q(n, t, e) {
132
+ if (n instanceof W)
133
+ return n;
134
+ const s = n instanceof Error, i = s ? n.message : String(n), o = s ? n : void 0, r = `${s ? n.constructor.name : "Unexpected error"} (${e}): ${i}`;
142
135
  return new t(r, o);
143
136
  }
144
- class de {
137
+ class Wt {
145
138
  constructor() {
146
- this.flags = 0, this.version = 0, this._lastSeenEpoch = -1, this.id = Be() & yt;
139
+ this.flags = 0, this.version = 0, this._lastSeenEpoch = Y.UNINITIALIZED, this.id = De() & mt;
147
140
  }
148
141
  }
149
- class _e extends de {
142
+ class Zt extends Wt {
143
+ constructor() {
144
+ super(...arguments), this._notifying = 0;
145
+ }
150
146
  /**
151
147
  * Adds subscriber.
152
148
  */
153
149
  subscribe(t) {
154
150
  const e = typeof t == "function";
155
151
  if (!e && (!t || typeof t.execute != "function"))
156
- throw tt(
152
+ throw Q(
157
153
  new TypeError("Invalid subscriber"),
158
- et,
154
+ W,
159
155
  b.ATOM_SUBSCRIBER_MUST_BE_FUNCTION
160
156
  );
161
- if (this._subscribers.some((i) => i ? e ? i.fn === t : i.sub === t : !1))
157
+ const s = this._subscribers, i = s.length;
158
+ let o = !1;
159
+ for (let c = 0; c < i; c++) {
160
+ const a = s[c];
161
+ if (a != null && (e ? a.fn === t : a.sub === t)) {
162
+ o = !0;
163
+ break;
164
+ }
165
+ }
166
+ if (o)
162
167
  return () => {
163
168
  };
164
- const n = new Mt(
169
+ const r = new Ne(
165
170
  e ? t : void 0,
166
171
  e ? void 0 : t
167
172
  );
168
- return this._subscribers.push(n), () => this._unsubscribe(n);
173
+ return s.push(r), () => this._unsubscribe(r);
169
174
  }
170
175
  _unsubscribe(t) {
171
- const e = this._subscribers, n = e.indexOf(t);
172
- if (n === -1) return;
176
+ const e = this._subscribers;
177
+ let s = -1;
178
+ for (let o = 0; o < e.length; o++)
179
+ if (e[o] === t) {
180
+ s = o;
181
+ break;
182
+ }
183
+ if (s === -1) return;
184
+ if (this._notifying > 0) {
185
+ e[s] = null;
186
+ return;
187
+ }
173
188
  const i = e.pop();
174
- n < e.length && i && (e[n] = i);
189
+ s < e.length && i !== void 0 && (e[s] = i);
175
190
  }
176
191
  subscriberCount() {
177
- return this._subscribers.length;
192
+ let t = 0;
193
+ const e = this._subscribers;
194
+ for (let s = 0; s < e.length; s++)
195
+ e[s] != null && t++;
196
+ return t;
178
197
  }
179
198
  _notifySubscribers(t, e) {
180
- this._subscribers.length !== 0 && this._subscribers.slice(0).forEach((n) => {
181
- if (n)
182
- try {
183
- n.fn ? n.fn(t, e) : n.sub && n.sub.execute();
184
- } catch (i) {
185
- this._handleNotifyError(i);
199
+ const s = this._subscribers, i = s.length;
200
+ if (i !== 0) {
201
+ this._notifying++;
202
+ try {
203
+ for (let o = 0; o < i; o++) {
204
+ const r = s[o];
205
+ if (r != null)
206
+ try {
207
+ r.notify(t, e);
208
+ } catch (c) {
209
+ this._handleNotifyError(c);
210
+ }
186
211
  }
187
- });
212
+ } finally {
213
+ this._notifying--, this._notifying === 0 && this._cleanupTombstones();
214
+ }
215
+ }
216
+ }
217
+ _cleanupTombstones() {
218
+ const t = this._subscribers;
219
+ let e = 0;
220
+ for (; e < t.length; )
221
+ if (t[e] === null) {
222
+ const s = t.pop();
223
+ e < t.length && s !== void 0 && (t[e] = s);
224
+ } else
225
+ e++;
188
226
  }
189
227
  _handleNotifyError(t) {
190
- console.error(tt(t, et, b.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED));
228
+ console.error(Q(t, W, b.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED));
191
229
  }
192
230
  }
193
- let wt = 0;
194
- const zt = () => (wt = wt + 1 & yt || 1, wt), Ft = (s) => s + 1 & yt;
195
- let jt = 0, gt = !1, Ee = 0;
196
- const pe = () => Ee;
197
- function ee() {
198
- return gt ? !1 : (gt = !0, Ee = zt(), jt = 0, !0);
231
+ let Tt = 0;
232
+ const kt = () => (Tt = Tt + 1 & mt || 1, Tt), vt = (n) => n + 1 & mt;
233
+ let At = 0, ut = !1, Jt = 0;
234
+ const te = () => Jt;
235
+ function Mt() {
236
+ return ut ? !1 : (ut = !0, Jt = kt(), At = 0, !0);
199
237
  }
200
- const se = () => {
201
- gt = !1;
202
- }, He = () => gt ? ++jt : 0;
203
- class Ge {
238
+ const Ft = () => {
239
+ ut = !1;
240
+ }, Oe = () => ut ? ++At : 0;
241
+ class Le {
204
242
  constructor() {
205
- 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 = q.MAX_FLUSH_ITERATIONS, this.onOverflow = null, this._boundRunLoop = this._runLoop.bind(this);
243
+ 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 = j.MAX_FLUSH_ITERATIONS, this.onOverflow = null, this._boundRunLoop = this._runLoop.bind(this);
206
244
  }
207
245
  get phase() {
208
246
  return this._isProcessing || this._isFlushingSync ? 2 : this._isBatching ? 1 : 0;
@@ -237,28 +275,28 @@ class Ge {
237
275
  _runLoop() {
238
276
  try {
239
277
  if (this._size === 0) return;
240
- const t = ee();
241
- this._drainQueue(), t && se();
278
+ const t = Mt();
279
+ this._drainQueue(), t && Ft();
242
280
  } finally {
243
281
  this._isProcessing = !1, this._size > 0 && !this._isBatching && this._flush();
244
282
  }
245
283
  }
246
284
  _flushSync() {
247
285
  this._isFlushingSync = !0;
248
- const t = ee();
286
+ const t = Mt();
249
287
  try {
250
288
  this._mergeBatchQueue(), this._drainQueue();
251
289
  } finally {
252
- this._isFlushingSync = !1, t && se();
290
+ this._isFlushingSync = !1, t && Ft();
253
291
  }
254
292
  }
255
293
  _mergeBatchQueue() {
256
294
  if (this._batchQueueSize === 0) return;
257
- const t = ++this._epoch, e = this._batchQueue, n = this._queueBuffer[this._bufferIndex];
295
+ const t = ++this._epoch, e = this._batchQueue, s = this._queueBuffer[this._bufferIndex];
258
296
  let i = this._size;
259
297
  e.slice(0, this._batchQueueSize).forEach((o) => {
260
- o._nextEpoch !== t && (o._nextEpoch = t, n[i++] = o);
261
- }), this._size = i, this._batchQueueSize = 0, e.length > q.BATCH_QUEUE_SHRINK_THRESHOLD && (e.length = 0);
298
+ o._nextEpoch !== t && (o._nextEpoch = t, s[i++] = o);
299
+ }), this._size = i, this._batchQueueSize = 0, e.length > j.BATCH_QUEUE_SHRINK_THRESHOLD && (e.length = 0);
262
300
  }
263
301
  _drainQueue() {
264
302
  let t = 0;
@@ -271,20 +309,21 @@ class Ge {
271
309
  }
272
310
  }
273
311
  _processQueue() {
274
- const t = this._bufferIndex, e = this._queueBuffer[t], n = this._size;
312
+ const t = this._bufferIndex, e = this._queueBuffer[t], s = this._size;
275
313
  this._bufferIndex = t ^ 1, this._size = 0, this._epoch++;
276
- for (let i = 0; i < n; i++)
314
+ for (let i = 0; i < s; i++)
277
315
  try {
278
- e[i]();
316
+ const o = e[i];
317
+ typeof o == "function" ? o() : o.execute();
279
318
  } catch (o) {
280
- console.error(new Lt("Error occurred during scheduler execution", o));
319
+ console.error(new yt("Error occurred during scheduler execution", o));
281
320
  }
282
321
  e.length = 0;
283
322
  }
284
323
  _handleFlushOverflow() {
285
324
  const t = this._size + this._batchQueueSize;
286
325
  if (console.error(
287
- new Lt(
326
+ new yt(
288
327
  b.SCHEDULER_FLUSH_OVERFLOW(this._maxFlushIterations, t)
289
328
  )
290
329
  ), this._size = 0, this._queueBuffer[this._bufferIndex].length = 0, this._batchQueueSize = 0, this.onOverflow)
@@ -300,14 +339,14 @@ class Ge {
300
339
  this._batchDepth !== 0 && --this._batchDepth === 0 && (this._flushSync(), this._isBatching = !1);
301
340
  }
302
341
  setMaxFlushIterations(t) {
303
- if (t < q.MIN_FLUSH_ITERATIONS)
304
- throw new Lt(
305
- `Max flush iterations must be at least ${q.MIN_FLUSH_ITERATIONS}`
342
+ if (t < j.MIN_FLUSH_ITERATIONS)
343
+ throw new yt(
344
+ `Max flush iterations must be at least ${j.MIN_FLUSH_ITERATIONS}`
306
345
  );
307
346
  this._maxFlushIterations = t;
308
347
  }
309
348
  }
310
- const ot = new Ge(), Vt = /* @__PURE__ */ Symbol.for("atom-effect/atom"), ge = /* @__PURE__ */ Symbol.for("atom-effect/computed"), ze = /* @__PURE__ */ Symbol.for("atom-effect/effect"), P = {
349
+ const ot = new Le(), Ut = /* @__PURE__ */ Symbol.for("atom-effect/atom"), ee = /* @__PURE__ */ Symbol.for("atom-effect/computed"), ke = /* @__PURE__ */ Symbol.for("atom-effect/effect"), Ae = /* @__PURE__ */ Symbol.for("atom-effect/writable"), $ = {
311
350
  /** Active listener. */
312
351
  current: null,
313
352
  /**
@@ -317,9 +356,9 @@ const ot = new Ge(), Vt = /* @__PURE__ */ Symbol.for("atom-effect/atom"), ge = /
317
356
  * @param fn - The logic to execute.
318
357
  * @returns The result of `fn`.
319
358
  */
320
- run(s, t) {
359
+ run(n, t) {
321
360
  const e = this.current;
322
- this.current = s;
361
+ this.current = n;
323
362
  try {
324
363
  return t();
325
364
  } finally {
@@ -327,38 +366,44 @@ const ot = new Ge(), Vt = /* @__PURE__ */ Symbol.for("atom-effect/atom"), ge = /
327
366
  }
328
367
  }
329
368
  };
330
- function H(s) {
331
- const t = P.current;
332
- if (t === null) return s();
333
- P.current = null;
369
+ function P(n) {
370
+ const t = $.current;
371
+ if (t === null) return n();
372
+ $.current = null;
334
373
  try {
335
- return s();
374
+ return n();
336
375
  } finally {
337
- P.current = t;
376
+ $.current = t;
338
377
  }
339
378
  }
340
- var ne;
341
- class je extends _e {
379
+ var Bt, Gt;
380
+ class Ue extends Zt {
342
381
  constructor(t, e) {
343
- super(), this._pendingOldValue = void 0, this._notifyTask = () => this._flushNotifications(), this._subscribers = [], this[ne] = !0, this._value = t, e && (this.flags |= M.SYNC), Ct.attachDebugInfo(this, "atom", this.id);
382
+ super(), this._pendingOldValue = void 0, this._subscribers = [], this[Gt] = !0, this[Bt] = !0, this._value = t, e && (this.flags |= M.SYNC), Lt.attachDebugInfo(this, "atom", this.id);
344
383
  }
345
384
  get value() {
346
- const t = P.current;
347
- return t && fe(this, t, this._subscribers), this._value;
385
+ return $.current?.addDependency(this), this._value;
348
386
  }
349
387
  set value(t) {
350
388
  const e = this._value;
351
389
  if (Object.is(e, t)) return;
352
- this._value = t, this.version = Ft(this.version);
353
- const n = this.flags;
354
- if (!(this._subscribers.length === 0 || n & M.NOTIFICATION_SCHEDULED)) {
355
- if (this._pendingOldValue = e, this.flags = n | M.NOTIFICATION_SCHEDULED, n & M.SYNC && !ot.isBatching) {
390
+ this._value = t, this.version = vt(this.version);
391
+ const s = this.flags;
392
+ if (!(this._subscribers.length === 0 || s & M.NOTIFICATION_SCHEDULED)) {
393
+ if (this._pendingOldValue = e, this.flags = s | M.NOTIFICATION_SCHEDULED, s & M.SYNC && !ot.isBatching) {
356
394
  this._flushNotifications();
357
395
  return;
358
396
  }
359
- ot.schedule(this._notifyTask);
397
+ ot.schedule(this);
360
398
  }
361
399
  }
400
+ /**
401
+ * Executes scheduled notification.
402
+ * @internal
403
+ */
404
+ execute() {
405
+ this._flushNotifications();
406
+ }
362
407
  /**
363
408
  * Triggers subscribers.
364
409
  */
@@ -375,21 +420,21 @@ class je extends _e {
375
420
  dispose() {
376
421
  this.flags & M.DISPOSED || (this._subscribers.length = 0, this.flags |= M.DISPOSED, this._value = void 0, this._pendingOldValue = void 0);
377
422
  }
378
- [(ne = Vt, Symbol.dispose)]() {
423
+ [(Gt = Ut, Bt = Ae, Symbol.dispose)]() {
379
424
  this.dispose();
380
425
  }
381
426
  }
382
- function Bt(s, t = {}) {
383
- return new je(s, t.sync ?? !1);
427
+ function Dt(n, t = {}) {
428
+ return new Ue(n, t.sync ?? !1);
384
429
  }
385
- class Ve {
430
+ class we {
386
431
  /**
387
432
  * @param limit - Max unique arrays to hold (default: 50). Prevents the pool itself from consuming too much memory.
388
433
  * @param capacity - Max length of an array to accept (default: 256).
389
434
  * @param enableStats - Force-enable stats even in production (default: false).
390
435
  */
391
- constructor(t = 50, e = 256, n = !1) {
392
- this.limit = t, this.capacity = e, this.pool = [], this.stats = null, this.stats = n ? {
436
+ constructor(t = 50, e = 256, s = !1) {
437
+ this.limit = t, this.capacity = e, this.pool = [], this.stats = null, this.stats = s ? {
393
438
  acquired: 0,
394
439
  released: 0,
395
440
  rejected: { frozen: 0, tooLarge: 0, poolFull: 0 }
@@ -429,11 +474,11 @@ class Ve {
429
474
  */
430
475
  getStats() {
431
476
  if (!this.stats) return null;
432
- const { acquired: t, released: e, rejected: n } = this.stats, i = t - e - (n.frozen + n.tooLarge + n.poolFull);
477
+ const { acquired: t, released: e, rejected: s } = this.stats, i = t - e - (s.frozen + s.tooLarge + s.poolFull);
433
478
  return {
434
479
  acquired: t,
435
480
  released: e,
436
- rejected: { ...n },
481
+ rejected: { ...s },
437
482
  leaked: i,
438
483
  poolSize: this.pool.length
439
484
  };
@@ -449,58 +494,57 @@ class Ve {
449
494
  });
450
495
  }
451
496
  }
452
- const A = Object.freeze(
497
+ const L = Object.freeze(
453
498
  []
454
- ), B = new Ve();
455
- function qt(s) {
456
- return s !== null && typeof s == "object" && Vt in s;
499
+ ), F = new we();
500
+ function wt(n) {
501
+ return n !== null && typeof n == "object" && Ut in n;
457
502
  }
458
- function qe(s) {
459
- return s !== null && typeof s == "object" && ge in s;
503
+ function xe(n) {
504
+ return n !== null && typeof n == "object" && ee in n;
460
505
  }
461
- function me(s) {
462
- return s !== null && typeof s == "object" && typeof s.then == "function";
506
+ function se(n) {
507
+ return n !== null && typeof n == "object" && typeof n.then == "function";
463
508
  }
464
- var ie, oe;
465
- const { IDLE: ft, DIRTY: K, PENDING: Et, RESOLVED: V, REJECTED: nt, HAS_ERROR: dt, RECOMPUTING: st, DISPOSED: kt, IS_COMPUTED: Xe } = ue;
466
- function Qe(s) {
467
- return s & V ? ut.RESOLVED : s & Et ? ut.PENDING : s & nt ? ut.REJECTED : ut.IDLE;
509
+ var Ht, jt;
510
+ const { IDLE: ct, DIRTY: K, PENDING: lt, RESOLVED: H, REJECTED: it, HAS_ERROR: at, RECOMPUTING: tt, DISPOSED: St, IS_COMPUTED: $e } = Qt;
511
+ function Pe(n) {
512
+ return n & H ? rt.RESOLVED : n & lt ? rt.PENDING : n & it ? rt.REJECTED : rt.IDLE;
468
513
  }
469
- class Ye extends _e {
514
+ class Me extends Zt {
470
515
  constructor(t, e = {}) {
471
- if (typeof t != "function") throw new j(b.COMPUTED_MUST_BE_FUNCTION);
472
- super(), this[oe] = !0, this[ie] = !0, this._error = null, this._promiseId = 0, this._subscribers = [], this._links = A, this._asyncStartAggregateVersion = 0, this._asyncRetryCount = 0, this._lastDriftEpoch = -1, this._trackEpoch = -1, this._trackLinks = A, this._trackCount = 0, this._value = void 0, this.flags = Xe | K | ft, this._equal = e.equal ?? Object.is, this._fn = t, this._defaultValue = "defaultValue" in e ? e.defaultValue : Ut, this._onError = e.onError ?? null;
473
- const n = e.maxAsyncRetries;
474
- if (this._maxAsyncRetries = (n ?? Zt.MAX_ASYNC_RETRIES) & yt, Ct.attachDebugInfo(this, "computed", this.id), e.lazy === !1)
516
+ if (typeof t != "function") throw new z(b.COMPUTED_MUST_BE_FUNCTION);
517
+ super(), this[jt] = !0, this[Ht] = !0, this._error = null, this._promiseId = 0, this._subscribers = [], this._links = L, this._asyncStartAggregateVersion = 0, this._asyncRetryCount = 0, this._lastDriftEpoch = Y.UNINITIALIZED, this._trackEpoch = Y.UNINITIALIZED, this._trackLinks = L, this._trackCount = 0, this._value = void 0, this.flags = $e | K | ct, this._equal = e.equal ?? Object.is, this._fn = t, this._defaultValue = "defaultValue" in e ? e.defaultValue : Ct, this._onError = e.onError ?? null;
518
+ const s = e.maxAsyncRetries;
519
+ if (this._maxAsyncRetries = (s ?? $t.MAX_ASYNC_RETRIES) & mt, Lt.attachDebugInfo(this, "computed", this.id), e.lazy === !1)
475
520
  try {
476
521
  this._recompute();
477
522
  } catch {
478
523
  }
479
524
  }
480
525
  _track() {
481
- const t = P.current;
482
- t && fe(this, t, this._subscribers);
526
+ $.current?.addDependency(this);
483
527
  }
484
528
  get value() {
485
529
  this._track();
486
530
  const t = this.flags;
487
- if ((t & (V | K | ft)) === V)
531
+ if ((t & (H | K | ct)) === H)
488
532
  return this._value;
489
- if (t & kt)
490
- throw new j(b.COMPUTED_DISPOSED);
491
- if (t & st) {
492
- if (this._defaultValue !== Ut) return this._defaultValue;
493
- throw new j(b.COMPUTED_CIRCULAR_DEPENDENCY);
533
+ if (t & St)
534
+ throw new z(b.COMPUTED_DISPOSED);
535
+ if (t & tt) {
536
+ if (this._defaultValue !== Ct) return this._defaultValue;
537
+ throw new z(b.COMPUTED_CIRCULAR_DEPENDENCY);
494
538
  }
495
- if (t & (K | ft) && (this._recompute(), this.flags & V))
539
+ if (t & (K | ct) && (this._recompute(), this.flags & H))
496
540
  return this._value;
497
- const e = this._defaultValue, n = e !== Ut;
498
- if (this.flags & Et) {
499
- if (n) return e;
500
- throw new j(b.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
541
+ const e = this._defaultValue, s = e !== Ct;
542
+ if (this.flags & lt) {
543
+ if (s) return e;
544
+ throw new z(b.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
501
545
  }
502
- if (this.flags & nt) {
503
- if (n) return e;
546
+ if (this.flags & it) {
547
+ if (s) return e;
504
548
  throw this._error;
505
549
  }
506
550
  return this._value;
@@ -509,20 +553,20 @@ class Ye extends _e {
509
553
  return this._value;
510
554
  }
511
555
  get state() {
512
- return this._track(), Qe(this.flags);
556
+ return this._track(), Pe(this.flags);
513
557
  }
514
558
  get hasError() {
515
- return this._track(), this.flags & (nt | dt) ? !0 : this._links.some((t) => t?.node?.flags & dt);
559
+ return this._track(), this.flags & (it | at) ? !0 : this._links.some((t) => t?.node?.flags & at);
516
560
  }
517
561
  get isValid() {
518
562
  return !this.hasError;
519
563
  }
520
564
  get errors() {
521
- if (this._track(), !this.hasError) return Pe;
565
+ if (this._track(), !this.hasError) return Se;
522
566
  const t = [];
523
567
  return this._error && t.push(this._error), this._links.forEach((e) => {
524
- const n = e.node;
525
- n.flags & dt && n.errors.forEach((i) => {
568
+ const s = e.node;
569
+ s.flags & at && s.errors.forEach((i) => {
526
570
  i && !t.includes(i) && t.push(i);
527
571
  });
528
572
  }), Object.freeze(t);
@@ -531,203 +575,257 @@ class Ye extends _e {
531
575
  return this._track(), this._error;
532
576
  }
533
577
  get isPending() {
534
- return this._track(), (this.flags & Et) !== 0;
578
+ return this._track(), (this.flags & lt) !== 0;
535
579
  }
536
580
  get isResolved() {
537
- return this._track(), (this.flags & V) !== 0;
581
+ return this._track(), (this.flags & H) !== 0;
538
582
  }
539
583
  invalidate() {
540
584
  this._markDirty();
541
585
  }
542
586
  dispose() {
543
- if (this.flags & kt) return;
587
+ if (this.flags & St) return;
544
588
  const t = this._links;
545
- t !== A && (t.forEach((e) => e.unsub?.()), B.release(t), this._links = A), this._subscribers.length = 0, this.flags = kt | K | ft, this._error = null, this._value = void 0;
589
+ t !== L && (t.forEach((e) => e.unsub?.()), F.release(t), this._links = L), this._subscribers.length = 0, this.flags = St | K | ct, this._error = null, this._value = void 0;
546
590
  }
547
- [(oe = Vt, ie = ge, Symbol.dispose)]() {
591
+ [(jt = Ut, Ht = ee, Symbol.dispose)]() {
548
592
  this.dispose();
549
593
  }
550
594
  addDependency(t) {
551
595
  if (t._lastSeenEpoch !== this._trackEpoch) {
552
- if (t._lastSeenEpoch = this._trackEpoch, this._trackCount < this._trackLinks.length) {
553
- const e = this._trackLinks[this._trackCount];
554
- e.node = t, e.version = t.version;
555
- } else
556
- this._trackLinks.push(new $t(t, t.version));
557
- this._trackCount++;
596
+ if (t._lastSeenEpoch = this._trackEpoch, this._trackLinks === this._links && this._trackCount < this._links.length && this._links[this._trackCount].node === t) {
597
+ this._links[this._trackCount].version = t.version, this._trackCount++;
598
+ return;
599
+ }
600
+ if (this._trackLinks === this._links) {
601
+ const e = F.acquire();
602
+ for (let s = 0; s < this._trackCount; s++)
603
+ e[s] = this._links[s];
604
+ this._trackLinks = e;
605
+ }
606
+ this._trackCount < this._trackLinks.length ? this._trackLinks[this._trackCount] = new ht(t, t.version) : this._trackLinks.push(new ht(t, t.version)), this._trackCount++;
558
607
  }
559
608
  }
560
609
  _recompute() {
561
- if (this.flags & st) return;
562
- this.flags |= st;
610
+ if (this.flags & tt) return;
611
+ this.flags |= tt;
563
612
  const t = this._links;
564
- this._trackEpoch = zt(), this._trackLinks = B.acquire(), this._trackCount = 0;
613
+ this._trackEpoch = kt(), this._trackLinks = t, this._trackCount = 0;
565
614
  let e = !1;
566
615
  try {
567
- const n = P.run(this, this._fn);
568
- this._trackLinks.length = this._trackCount, te(this._trackLinks, t, this), this._links = this._trackLinks, e = !0, me(n) ? this._handleAsyncComputation(n) : this._finalizeResolution(n);
569
- } catch (n) {
616
+ const s = $.run(this, this._fn);
617
+ if (this._trackLinks === t)
618
+ if (this._trackCount === t.length)
619
+ e = !0;
620
+ else {
621
+ for (let i = this._trackCount; i < t.length; i++)
622
+ t[i].unsub?.();
623
+ t.length = this._trackCount, e = !0;
624
+ }
625
+ else
626
+ this._trackLinks.length = this._trackCount, Pt(this._trackLinks, t, this), this._links = this._trackLinks, e = !0;
627
+ se(s) ? this._handleAsyncComputation(s) : this._finalizeResolution(s);
628
+ } catch (s) {
570
629
  if (!e)
571
630
  try {
572
- this._trackLinks.length = this._trackCount, te(this._trackLinks, t, this), this._links = this._trackLinks, e = !0;
631
+ if (this._trackLinks === t) {
632
+ for (let i = this._trackCount; i < t.length; i++)
633
+ t[i].unsub?.();
634
+ t.length = this._trackCount, e = !0;
635
+ } else
636
+ this._trackLinks.length = this._trackCount, Pt(this._trackLinks, t, this), this._links = this._trackLinks, e = !0;
573
637
  } catch {
574
638
  }
575
- this._handleError(n, b.COMPUTED_COMPUTATION_FAILED, !0);
639
+ this._handleError(s, b.COMPUTED_COMPUTATION_FAILED, !0);
576
640
  } finally {
577
- e && t !== A ? B.release(t) : e || B.release(this._trackLinks), this._trackEpoch = -1, this._trackLinks = A, this._trackCount = 0, this.flags &= ~st;
641
+ e ? this._links !== t && t !== L && F.release(t) : this._trackLinks !== t && this._trackLinks !== L && F.release(this._trackLinks), this._trackEpoch = Y.UNINITIALIZED, this._trackLinks = L, this._trackCount = 0, this.flags &= ~tt;
578
642
  }
579
643
  }
580
644
  _handleAsyncComputation(t) {
581
- this.flags = (this.flags | Et) & -217, this._notifySubscribers(void 0, void 0), this._asyncStartAggregateVersion = this._captureVersionSnapshot(), this._asyncRetryCount = 0, this._promiseId = (this._promiseId + 1) % Zt.MAX_PROMISE_ID;
645
+ this.flags = (this.flags | lt) & -217, this._notifySubscribers(void 0, void 0), this._asyncStartAggregateVersion = this._captureVersionSnapshot(), this._asyncRetryCount = 0, this._promiseId = (this._promiseId + 1) % $t.MAX_PROMISE_ID;
582
646
  const e = this._promiseId;
583
647
  t.then(
584
- (n) => {
648
+ (s) => {
585
649
  if (e === this._promiseId) {
586
650
  if (this._captureVersionSnapshot() !== this._asyncStartAggregateVersion) {
587
- const i = pe();
651
+ const i = te();
588
652
  return this._lastDriftEpoch !== i && (this._lastDriftEpoch = i, this._asyncRetryCount = 0), this._asyncRetryCount++ < this._maxAsyncRetries ? this._markDirty() : this._handleError(
589
- new j(
653
+ new z(
590
654
  `Async drift threshold exceeded after ${this._maxAsyncRetries} retries.`
591
655
  ),
592
656
  b.COMPUTED_ASYNC_COMPUTATION_FAILED
593
657
  );
594
658
  }
595
- this._finalizeResolution(n), this._notifySubscribers(n, void 0);
659
+ this._finalizeResolution(s), this._notifySubscribers(s, void 0);
596
660
  }
597
661
  },
598
- (n) => e === this._promiseId && this._handleError(n, b.COMPUTED_ASYNC_COMPUTATION_FAILED)
662
+ (s) => e === this._promiseId && this._handleError(s, b.COMPUTED_ASYNC_COMPUTATION_FAILED)
599
663
  );
600
664
  }
601
665
  _captureVersionSnapshot() {
602
666
  let t = 0;
603
667
  const e = this._links;
604
- for (let n = 0, i = e.length; n < i; n++)
605
- t = (t << 5) - t + e[n].node.version | 0;
668
+ for (let s = 0, i = e.length; s < i; s++)
669
+ t = (t << 5) - t + e[s].node.version | 0;
606
670
  return t;
607
671
  }
608
- _handleError(t, e, n = !1) {
609
- const i = tt(t, j, e);
610
- if (!n && !(this.flags & nt) && (this.version = Ft(this.version)), this._error = i, this.flags = this.flags & -121 | nt | dt, this._onError)
672
+ _handleError(t, e, s = !1) {
673
+ const i = Q(t, z, e);
674
+ if (!s && !(this.flags & it) && (this.version = vt(this.version)), this._error = i, this.flags = this.flags & -121 | it | at, this._onError)
611
675
  try {
612
676
  this._onError(i);
613
677
  } catch (o) {
614
678
  console.error(b.CALLBACK_ERROR_IN_ERROR_HANDLER, o);
615
679
  }
616
- if (n) throw i;
680
+ if (s) throw i;
617
681
  this._notifySubscribers(void 0, void 0);
618
682
  }
619
683
  _finalizeResolution(t) {
620
- (!(this.flags & V) || !this._equal(this._value, t)) && (this.version = Ft(this.version)), this._value = t, this._error = null, this.flags = (this.flags | V) & -697;
684
+ (!(this.flags & H) || !this._equal(this._value, t)) && (this.version = vt(this.version)), this._value = t, this._error = null, this.flags = (this.flags | H) & -697;
621
685
  }
622
686
  execute() {
623
687
  this._markDirty();
624
688
  }
625
689
  /** @internal */
626
690
  _markDirty() {
627
- this.flags & (st | K) || (this.flags |= K, this._notifySubscribers(void 0, void 0));
691
+ this.flags & (tt | K) || (this.flags |= K, this._notifySubscribers(void 0, void 0));
628
692
  }
629
693
  }
630
- function St(s, t = {}) {
631
- return new Ye(s, t);
694
+ function gt(n, t = {}) {
695
+ return new Me(n, t);
632
696
  }
633
- var re;
634
- class Ke extends de {
697
+ var Vt;
698
+ class Fe extends Wt {
635
699
  constructor(t, e = {}) {
636
- super(), this[re] = !0, this._cleanup = null, this._links = A, this._nextLinks = null, this._prevLinks = A, this._currentEpoch = -1, this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._executionCount = 0, this._windowStart = 0, this._windowCount = 0, this._execId = 0, this._fn = t, this._onError = e.onError ?? null, this._sync = e.sync ?? !1, this._maxExecutions = e.maxExecutionsPerSecond ?? q.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = e.maxExecutionsPerFlush ?? q.MAX_EXECUTIONS_PER_EFFECT, this._sync ? (this._executeTask = void 0, this._notifyCallback = () => this.execute()) : (this._executeTask = () => this.execute(), this._notifyCallback = () => ot.schedule(this._executeTask)), Ct.attachDebugInfo(this, "effect", this.id);
700
+ super(), this[Vt] = !0, this._cleanup = null, this._links = L, this._nextLinks = null, this._prevLinks = L, this._currentEpoch = Y.UNINITIALIZED, this._lastFlushEpoch = Y.UNINITIALIZED, this._executionsInEpoch = 0, this._executionCount = 0, this._windowStart = 0, this._windowCount = 0, this._execId = 0, this._trackCount = 0, this._fn = t, this._onError = e.onError ?? null, this._sync = e.sync ?? !1, this._maxExecutions = e.maxExecutionsPerSecond ?? j.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = e.maxExecutionsPerFlush ?? j.MAX_EXECUTIONS_PER_EFFECT, this._sync ? this._notifyCallback = () => this.execute() : this._notifyCallback = () => ot.schedule(this), Lt.attachDebugInfo(this, "effect", this.id);
637
701
  }
638
702
  run() {
639
- if (this.flags & k.DISPOSED)
640
- throw new Z(b.EFFECT_DISPOSED);
703
+ if (this.flags & w.DISPOSED)
704
+ throw new q(b.EFFECT_DISPOSED);
641
705
  this.execute(!0);
642
706
  }
643
707
  dispose() {
644
- this.flags & k.DISPOSED || (this.flags |= k.DISPOSED, this._execCleanup(), this._unsubLinks(this._links), this._links !== A && B.release(this._links), this._links = A, this._prevLinks = A);
708
+ this.flags & w.DISPOSED || (this.flags |= w.DISPOSED, this._execCleanup(), this._unsubLinks(this._links), this._links !== L && F.release(this._links), this._links = L, this._prevLinks = L);
645
709
  }
646
- [(re = ze, Symbol.dispose)]() {
710
+ [(Vt = ke, Symbol.dispose)]() {
647
711
  this.dispose();
648
712
  }
649
713
  addDependency(t) {
650
- if (!(this.flags & k.EXECUTING)) return;
714
+ if (!(this.flags & w.EXECUTING)) return;
651
715
  const e = this._currentEpoch;
652
716
  if (t._lastSeenEpoch === e) return;
653
717
  t._lastSeenEpoch = e;
654
- const n = this._nextLinks, i = this._prevLinks, o = i.findIndex((r) => r && r.node === t && r.unsub);
655
- if (o !== -1) {
656
- const r = i[o];
657
- r.version = t.version, n.push(r), i[o] = null;
718
+ const s = this._prevLinks;
719
+ if (this._nextLinks === s && this._trackCount < s.length && s[this._trackCount].node === t) {
720
+ s[this._trackCount].version = t.version, this._trackCount++;
658
721
  return;
659
722
  }
660
- try {
661
- const r = t.subscribe(this._notifyCallback);
662
- n.push(new $t(t, t.version, r));
663
- } catch (r) {
664
- const c = tt(r, Z, b.EFFECT_EXECUTION_FAILED);
665
- if (console.error(c), this._onError)
666
- try {
667
- this._onError(c);
668
- } catch {
669
- }
670
- n.push(new $t(t, t.version, void 0));
723
+ if (this._nextLinks === s) {
724
+ const r = F.acquire();
725
+ for (let c = 0; c < this._trackCount; c++)
726
+ r[c] = s[c];
727
+ this._nextLinks = r;
728
+ }
729
+ const i = this._nextLinks;
730
+ let o = -1;
731
+ for (let r = this._trackCount; r < s.length; r++) {
732
+ const c = s[r];
733
+ if (c && c.node === t && c.unsub) {
734
+ o = r;
735
+ break;
736
+ }
671
737
  }
738
+ if (o !== -1) {
739
+ const r = s[o];
740
+ r.version = t.version, i[this._trackCount] = r, s[o] = null;
741
+ } else
742
+ try {
743
+ const r = t.subscribe(this._notifyCallback);
744
+ i[this._trackCount] = new ht(t, t.version, r);
745
+ } catch (r) {
746
+ const c = Q(r, q, b.EFFECT_EXECUTION_FAILED);
747
+ if (console.error(c), this._onError)
748
+ try {
749
+ this._onError(c);
750
+ } catch {
751
+ }
752
+ i[this._trackCount] = new ht(t, t.version, void 0);
753
+ }
754
+ this._trackCount++;
672
755
  }
673
756
  /**
674
757
  * Executes effect with tracking.
675
758
  */
676
759
  execute(t = !1) {
677
- if (this.flags & (k.DISPOSED | k.EXECUTING) || !t && this._links.length > 0 && !this._isDirty()) return;
678
- this._checkInfiniteLoops(), this.flags |= k.EXECUTING, this._execCleanup(), this._prevLinks = this._links;
679
- const e = B.acquire();
680
- this._nextLinks = e, this._currentEpoch = zt();
681
- let n = !1;
760
+ if (this.flags & (w.DISPOSED | w.EXECUTING) || !t && this._links.length > 0 && !this._isDirty()) return;
761
+ this._checkInfiniteLoops(), this.flags |= w.EXECUTING, this._execCleanup(), this._prevLinks = this._links, this._nextLinks = this._links, this._currentEpoch = kt(), this._trackCount = 0;
762
+ let e = !1;
682
763
  try {
683
- const i = P.run(this, this._fn);
684
- this._links = e, n = !0, me(i) ? this._handleAsyncResult(i) : this._cleanup = typeof i == "function" ? i : null;
685
- } catch (i) {
686
- this._links = e, n = !0, this._handleExecutionError(i), this._cleanup = null;
764
+ const s = $.run(this, this._fn);
765
+ if (this._nextLinks === this._prevLinks)
766
+ if (this._trackCount === this._prevLinks.length)
767
+ e = !0;
768
+ else {
769
+ for (let i = this._trackCount; i < this._prevLinks.length; i++)
770
+ this._prevLinks[i]?.unsub?.();
771
+ this._prevLinks.length = this._trackCount, e = !0;
772
+ }
773
+ else
774
+ this._nextLinks.length = this._trackCount, e = !0;
775
+ this._links = this._nextLinks, se(s) ? this._handleAsyncResult(s) : this._cleanup = typeof s == "function" ? s : null;
776
+ } catch (s) {
777
+ if (!e)
778
+ if (this._nextLinks === this._prevLinks) {
779
+ for (let i = this._trackCount; i < this._prevLinks.length; i++)
780
+ this._prevLinks[i]?.unsub?.();
781
+ this._prevLinks.length = this._trackCount, e = !0;
782
+ } else
783
+ this._nextLinks.length = this._trackCount, e = !0;
784
+ this._links = this._nextLinks, this._handleExecutionError(s), this._cleanup = null;
687
785
  } finally {
688
- this._finalizeDependencies(n, this._prevLinks, e), this.flags &= -9;
786
+ this._finalizeDependencies(e, this._prevLinks, this._nextLinks), this.flags &= -9;
689
787
  }
690
788
  }
691
789
  _handleAsyncResult(t) {
692
790
  const e = ++this._execId;
693
791
  t.then(
694
- (n) => {
695
- if (e !== this._execId || this.flags & k.DISPOSED) {
696
- if (typeof n == "function")
792
+ (s) => {
793
+ if (e !== this._execId || this.flags & w.DISPOSED) {
794
+ if (typeof s == "function")
697
795
  try {
698
- n();
796
+ s();
699
797
  } catch (i) {
700
798
  this._handleExecutionError(i, b.EFFECT_CLEANUP_FAILED);
701
799
  }
702
800
  return;
703
801
  }
704
- typeof n == "function" && (this._cleanup = n);
802
+ typeof s == "function" && (this._cleanup = s);
705
803
  },
706
- (n) => e === this._execId && this._handleExecutionError(n)
804
+ (s) => e === this._execId && this._handleExecutionError(s)
707
805
  );
708
806
  }
709
- _finalizeDependencies(t, e, n) {
710
- this._nextLinks = null, this._prevLinks = A, t ? (e.forEach((i) => i?.unsub?.()), e !== A && B.release(e)) : (this._unsubLinks(n), B.release(n));
807
+ _finalizeDependencies(t, e, s) {
808
+ this._nextLinks = null, this._prevLinks = L, t ? s !== e && e !== L && (e.forEach((i) => i?.unsub?.()), F.release(e)) : s !== e && s !== L && s && (this._unsubLinks(s), F.release(s));
711
809
  }
712
810
  _unsubLinks(t) {
713
811
  t.forEach((e) => e?.unsub?.());
714
812
  }
715
813
  _isDirty() {
716
- const t = this._links, e = P.current;
717
- P.current = null;
814
+ const t = this._links, e = $.current;
815
+ $.current = null;
718
816
  try {
719
- return t.some((n) => {
720
- const i = n.node;
721
- if (i.flags & ue.IS_COMPUTED)
817
+ return t.some((s) => {
818
+ const i = s.node;
819
+ if (i.flags & Qt.IS_COMPUTED)
722
820
  try {
723
821
  i.value;
724
822
  } catch {
725
823
  return !0;
726
824
  }
727
- return i.version !== n.version;
825
+ return i.version !== s.version;
728
826
  });
729
827
  } finally {
730
- P.current = e;
828
+ $.current = e;
731
829
  }
732
830
  }
733
831
  _execCleanup() {
@@ -741,51 +839,51 @@ class Ke extends de {
741
839
  }
742
840
  }
743
841
  _checkInfiniteLoops() {
744
- const t = pe();
745
- this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), He() > q.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++;
842
+ const t = te();
843
+ this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), Oe() > j.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++;
746
844
  }
747
845
  get isDisposed() {
748
- return (this.flags & k.DISPOSED) !== 0;
846
+ return (this.flags & w.DISPOSED) !== 0;
749
847
  }
750
848
  get executionCount() {
751
849
  return this._executionCount;
752
850
  }
753
851
  get isExecuting() {
754
- return (this.flags & k.EXECUTING) !== 0;
852
+ return (this.flags & w.EXECUTING) !== 0;
755
853
  }
756
854
  _throwInfiniteLoopError(t) {
757
- const e = new Z(
758
- `Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${jt}`
855
+ const e = new q(
856
+ `Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${At}`
759
857
  );
760
858
  throw this.dispose(), console.error(e), e;
761
859
  }
762
860
  _handleExecutionError(t, e = b.EFFECT_EXECUTION_FAILED) {
763
- const n = tt(t, Z, e);
764
- if (console.error(n), this._onError)
861
+ const s = Q(t, q, e);
862
+ if (console.error(s), this._onError)
765
863
  try {
766
- this._onError(n);
864
+ this._onError(s);
767
865
  } catch (i) {
768
- console.error(tt(i, Z, b.CALLBACK_ERROR_IN_ERROR_HANDLER));
866
+ console.error(Q(i, q, b.CALLBACK_ERROR_IN_ERROR_HANDLER));
769
867
  }
770
868
  }
771
869
  }
772
- function X(s, t = {}) {
773
- if (typeof s != "function")
774
- throw new Z(b.EFFECT_MUST_BE_FUNCTION);
775
- const e = new Ke(s, t);
870
+ function V(n, t = {}) {
871
+ if (typeof n != "function")
872
+ throw new q(b.EFFECT_MUST_BE_FUNCTION);
873
+ const e = new Fe(n, t);
776
874
  return e.execute(), e;
777
875
  }
778
- function Ie(s) {
779
- if (typeof s != "function")
780
- throw new TypeError("Batch callback must be a function");
876
+ function ne(n) {
877
+ if (typeof n != "function")
878
+ throw new TypeError(b.BATCH_CALLBACK_MUST_BE_FUNCTION);
781
879
  ot.startBatch();
782
880
  try {
783
- return s();
881
+ return n();
784
882
  } finally {
785
883
  ot.endBatch();
786
884
  }
787
885
  }
788
- const g = {
886
+ const E = {
789
887
  /** Used by the SPA router ($.route). */
790
888
  ROUTE: "[atom-route]",
791
889
  /** Used by all reactive binding helpers (bindText, bindCss, bindAttr, …). */
@@ -794,276 +892,258 @@ const g = {
794
892
  LIST: "[atom-list]",
795
893
  /** Used by mount/unmount lifecycle helpers. */
796
894
  MOUNT: "[atom-mount]"
797
- }, _t = Object.freeze({
895
+ }, et = Object.freeze({
798
896
  mode: "hash",
799
897
  basePath: "",
800
898
  autoBindLinks: !1,
801
899
  activeClass: "active"
802
- }), We = {
900
+ }), Be = {
901
+ /** Default DOM event to trigger synchronization. */
803
902
  EVENT: "input"
804
- }, Je = /* @__PURE__ */ new Set(["input", "select", "textarea"]), Ze = /* @__PURE__ */ new Set([
805
- "innerHTML",
806
- "outerHTML",
807
- "srcdoc",
808
- "__proto__",
809
- "constructor",
810
- "prototype"
811
- ]), T = {
812
- ROUTE_NOT_FOUND: (s) => `Route "${s}" not found and no notFound route configured`,
813
- TEMPLATE_NOT_FOUND: (s) => `Template "${s}" not found`,
814
- TARGET_NOT_FOUND: (s) => `Target element "${s}" not found`,
815
- MALFORMED_URI: (s) => `Malformed URI component: ${s}`,
816
- /** Emitted when sanitizeHtml modifies the input. Prefixed at call site with LOG_PREFIXES.BINDING or LIST to identify the originating subsystem. */
817
- UNSAFE_CONTENT: () => "Unsafe content neutralized during sanitization.",
818
- /** Emitted by bindCss when a CSS style property value contains a dangerous protocol. */
819
- BLOCKED_DANGEROUS_CSS_VALUE: (s) => `Blocked dangerous value in CSS style property "${s}".`,
820
- BLOCKED_EVENT_HANDLER: (s) => `Blocked setting dangerous event handler attribute "${s}".`,
821
- BLOCKED_PROTOCOL: (s) => `Blocked dangerous protocol in "${s}" attribute.`,
822
- BLOCKED_DANGEROUS_PROP: (s) => `Blocked setting dangerous property "${s}". Use html binding for sanitized HTML.`,
823
- INVALID_INPUT_ELEMENT: (s) => `Val binding used on non-input element <${s}>.`,
824
- MISSING_SOURCE: (s) => `[${s}] source is required when prop/name is a string.`,
825
- MISSING_CONDITION: (s) => `[${s}] condition is required when className is a string.`,
826
- DUPLICATE_KEY: (s, t) => `Duplicate key "${s}" at index ${t}.`,
827
- UPDATER_ERROR: (s) => `Updater threw in binding "${s}"`,
828
- EFFECT_DISPOSE_ERROR: () => "Effect dispose error",
829
- BINDING_CLEANUP_ERROR: () => "Binding cleanup error",
830
- PARSE_ERROR: () => "parse() threw during DOM→Atom sync",
831
- MOUNT_ERROR: () => "Mount error",
832
- MOUNT_CLEANUP_ERROR: () => "Cleanup error"
833
- };
834
- function ye(s) {
835
- return qt(s);
836
- }
837
- function Xt(s) {
838
- const t = s.tagName.toLowerCase();
839
- if (s.id) return `${t}#${s.id}`;
840
- const e = s.classList, n = e.length;
841
- if (n === 0) return t;
842
- let i = t;
843
- for (let o = 0; o < n; o++)
844
- i += `.${e[o]}`;
845
- return i;
846
- }
847
- const ts = /* @__PURE__ */ new Set([
848
- "href",
903
+ }, ie = {
904
+ /** Default duration in ms for visual highlighting during DOM updates. */
905
+ HIGHLIGHT_DURATION_MS: 500
906
+ }, Ge = /* @__PURE__ */ new Set(["input", "select", "textarea"]), He = /* @__PURE__ */ new Set([
849
907
  "src",
908
+ "href",
850
909
  "action",
851
910
  "formaction",
852
- "xlink:href",
853
911
  "data",
854
912
  "poster",
855
- "srcset",
856
913
  "background",
857
914
  "cite",
858
915
  "longdesc",
859
916
  "profile",
860
917
  "usemap",
861
918
  "classid",
862
- "codebase"
863
- ]), rt = Object.prototype.hasOwnProperty, es = /^\s*(?:javascript|vbscript)\s*:/i, ss = (
864
- // biome-ignore lint/suspicious/noControlCharactersInRegex: Intentionally matching control characters for XSS sanitization
865
- /(?:expression\s*\(|behavior\s*:|-moz-binding\s*:|(?:\\[0-9a-f]{1,6}\s*|[\s\x00-\x20/'"])*(?: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|d\s*a\s*t\s*a)\s*:(?!image\/))/i
866
- ), ns = /url\s*\(\s*(?:["']?\s*)?(?:javascript|vbscript)\s*:/i, is = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, os = /&#x([0-9a-f]+);?|&#([0-9]+);?/gi, rs = {
867
- colon: ":",
868
- Tab: " ",
869
- NewLine: `
870
- `
871
- }, cs = /&(colon|Tab|NewLine);/g, as = /<\?[\s\S]*?\?>/g, ls = /(<(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, hs = /(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, us = /data\s*:\s*(?:text\/(?:html|javascript|vbscript|xml)|application\/(?:javascript|xhtml\+xml|xml|x-shockwave-flash)|image\/svg\+xml)/gi, fs = /\bon\w+\s*=/gim, ds = new RegExp(ss.source, "gim");
872
- function Ht(s) {
873
- let t = String(s ?? "");
874
- t = t.replace(is, ""), t = t.replace(
875
- os,
876
- (n, i, o) => String.fromCodePoint(i ? parseInt(i, 16) : parseInt(o, 10))
877
- ), t = t.replace(cs, (n, i) => rs[i] ?? ""), t = t.replace(as, "");
878
- let e;
879
- do
880
- e = t, t = t.replace(ls, "");
881
- while (t !== e);
882
- return t = t.replace(hs, "data-unsafe-protocol:"), t = t.replace(us, "data-unsafe-protocol:"), t = t.replace(fs, "data-unsafe-attr="), t = t.replace(ds, "data-unsafe-css:"), t;
883
- }
884
- function _s(s, t) {
885
- return ts.has(s.toLowerCase()) ? es.test(t) : !1;
886
- }
887
- function Es(s) {
888
- return s.toLowerCase().includes("url(") ? ns.test(s) : !1;
919
+ "codebase",
920
+ "xlink:href"
921
+ ]), je = /* @__PURE__ */ new Set([
922
+ "innerHTML",
923
+ "outerHTML",
924
+ "srcdoc",
925
+ "__proto__",
926
+ "constructor",
927
+ "prototype"
928
+ ]), S = {
929
+ ROUTE: {
930
+ NOT_FOUND: (n) => `Route "${n}" not found and no notFound route configured`,
931
+ TEMPLATE_NOT_FOUND: (n) => `Template "${n}" not found`,
932
+ TARGET_NOT_FOUND: (n) => `Target element "${n}" not found`,
933
+ MALFORMED_URI: (n) => `Malformed URI component: ${n}`
934
+ },
935
+ SECURITY: {
936
+ /** Emitted when sanitizeHtml modifies the input. */
937
+ UNSAFE_CONTENT: () => "Unsafe content neutralized during sanitization.",
938
+ /** Emitted when a CSS style property value contains a dangerous protocol. */
939
+ BLOCKED_CSS_VALUE: (n) => `Blocked dangerous value in CSS style property "${n}".`,
940
+ BLOCKED_EVENT_HANDLER: (n) => `Blocked setting dangerous event handler attribute/property "${n}".`,
941
+ BLOCKED_PROTOCOL: (n) => `Blocked dangerous protocol in "${n}".`,
942
+ BLOCKED_PROP: (n) => `Blocked setting dangerous property "${n}". Use html binding for sanitized HTML.`
943
+ },
944
+ BINDING: {
945
+ INVALID_INPUT_ELEMENT: (n) => `Val binding used on non-input element <${n}>.`,
946
+ MISSING_SOURCE: (n) => `[${n}] source is required when prop/name is a string.`,
947
+ MISSING_CONDITION: (n) => `[${n}] condition is required when className is a string.`,
948
+ UPDATER_ERROR: (n, t) => `Updater threw in binding "${n}"${t ? " (static)" : ""}`,
949
+ CLEANUP_ERROR: (n) => `Binding cleanup error${n ? `: ${n}` : ""}`,
950
+ PARSE_ERROR: (n) => `parse() threw during DOM→Atom sync${n ? `: ${n}` : ""}`
951
+ },
952
+ LIST: {
953
+ DUPLICATE_KEY: (n, t, e) => `Duplicate key "${n}" at index ${t} in atomList <${e}>.`
954
+ },
955
+ MOUNT: {
956
+ ERROR: (n) => `Mount error${n ? ` in component <${n}>` : ""}`,
957
+ CLEANUP_ERROR: (n) => `Cleanup error${n ? ` in component <${n}>` : ""}`
958
+ },
959
+ CORE: {
960
+ EFFECT_DISPOSE_ERROR: (n) => `Effect dispose error${n ? `: ${n}` : ""}`
961
+ }
962
+ };
963
+ function oe(n) {
964
+ return wt(n);
965
+ }
966
+ function X(n) {
967
+ const t = n.tagName.toLowerCase();
968
+ if (n.id) return `${t}#${n.id}`;
969
+ const e = n.classList, s = e.length;
970
+ if (s === 0) return t;
971
+ let i = t;
972
+ for (let o = 0; o < s; o++)
973
+ i += `.${e[o]}`;
974
+ return i;
889
975
  }
890
- function ps(s, t) {
891
- if (s === t) return !0;
892
- if (s === null || t === null || typeof s != "object" || typeof t != "object") return !1;
893
- const e = Object.keys(s), n = Object.keys(t);
894
- if (e.length !== n.length) return !1;
895
- const i = s, o = t;
976
+ const Z = Object.prototype.hasOwnProperty;
977
+ function Ve(n, t) {
978
+ if (n === t) return !0;
979
+ if (n === null || t === null || typeof n != "object" || typeof t != "object") return !1;
980
+ const e = Object.keys(n), s = Object.keys(t);
981
+ if (e.length !== s.length) return !1;
982
+ const i = n, o = t;
896
983
  for (let r = 0; r < e.length; r++) {
897
984
  const c = e[r];
898
- if (!rt.call(o, c) || i[c] !== o[c])
985
+ if (!Z.call(o, c) || i[c] !== o[c])
899
986
  return !1;
900
987
  }
901
988
  return !0;
902
989
  }
903
- function gs(s) {
904
- const t = s.length;
990
+ function ze(n) {
991
+ const t = n.length;
905
992
  if (t === 0) return new Int32Array(0);
906
- const e = new Int32Array(t).fill(-1), n = new Int32Array(t);
993
+ const e = new Int32Array(t).fill(-1), s = new Int32Array(t);
907
994
  let i = 0;
908
995
  for (let r = 0; r < t; r++) {
909
- const c = s[r];
996
+ const c = n[r];
910
997
  if (c === void 0 || c === -1) continue;
911
- const E = i > 0 ? n[i - 1] : void 0;
912
- if (i === 0 || E !== void 0 && (s[E] ?? -1) < c) {
913
- e[r] = E ?? -1, n[i++] = r;
998
+ const a = i > 0 ? s[i - 1] : void 0;
999
+ if (i === 0 || a !== void 0 && (n[a] ?? -1) < c) {
1000
+ e[r] = a ?? -1, s[i++] = r;
914
1001
  continue;
915
1002
  }
916
- let d = 0, m = i - 1;
917
- for (; d < m; ) {
918
- const p = d + m >>> 1, O = n[p];
919
- O !== void 0 && (s[O] ?? -1) < c ? d = p + 1 : m = p;
1003
+ let l = 0, u = i - 1;
1004
+ for (; l < u; ) {
1005
+ const y = l + u >>> 1, p = s[y];
1006
+ p !== void 0 && (n[p] ?? -1) < c ? l = y + 1 : u = y;
920
1007
  }
921
- const N = n[d];
922
- N !== void 0 && c < (s[N] ?? Number.MAX_SAFE_INTEGER) && (d > 0 && (e[r] = n[d - 1] ?? -1), n[d] = r);
1008
+ const _ = s[l];
1009
+ _ !== void 0 && c < (n[_] ?? Number.MAX_SAFE_INTEGER) && (l > 0 && (e[r] = s[l - 1] ?? -1), s[l] = r);
923
1010
  }
924
1011
  const o = new Int32Array(i);
925
1012
  if (i > 0) {
926
- let r = n[i - 1];
1013
+ let r = s[i - 1];
927
1014
  for (let c = i - 1; c >= 0 && r !== void 0 && r !== -1; c--)
928
1015
  o[c] = r, r = e[r];
929
1016
  }
930
1017
  return o;
931
1018
  }
932
- const ms = {}, Ce = 600, Is = `${Ce / 1e3}s`;
933
- function ys() {
1019
+ const Ke = { BASE_URL: "/", DEV: !1, MODE: "production", PROD: !0, SSR: !1 }, qe = `${ie.HIGHLIGHT_DURATION_MS / 1e3}s`;
1020
+ function Xe() {
934
1021
  if (typeof window < "u") {
935
- const s = window.__ATOM_DEBUG__;
936
- if (typeof s == "boolean") return s;
1022
+ const n = window.__ATOM_DEBUG__;
1023
+ if (typeof n == "boolean") return n;
937
1024
  }
938
- return ms?.VITE_ATOM_DEBUG === "true";
1025
+ try {
1026
+ if (Ke?.VITE_ATOM_DEBUG === "true") return !0;
1027
+ } catch {
1028
+ }
1029
+ try {
1030
+ if (globalThis.process?.env?.VITE_ATOM_DEBUG === "true")
1031
+ return !0;
1032
+ } catch {
1033
+ }
1034
+ return !1;
939
1035
  }
940
- let W = ys();
941
- const f = {
1036
+ let zt = Xe();
1037
+ const d = {
942
1038
  get enabled() {
943
- return W;
1039
+ if (typeof window < "u") {
1040
+ const n = window.__ATOM_DEBUG__;
1041
+ if (typeof n == "boolean") return n;
1042
+ }
1043
+ return zt;
944
1044
  },
945
- set enabled(s) {
946
- W = s;
1045
+ set enabled(n) {
1046
+ zt = n;
947
1047
  },
948
1048
  /**
949
1049
  * Logs a message only when debug mode is active.
950
1050
  */
951
- log(s, ...t) {
952
- W && console.log(`${g.MOUNT} ${s}:`, ...t);
1051
+ log(n, ...t) {
1052
+ this.enabled && console.log(`${n}`, ...t);
953
1053
  },
954
1054
  /**
955
1055
  * Logs an atom value change only when debug mode is active.
956
1056
  */
957
- atomChanged(s, t, e) {
958
- W && console.log(
959
- `${g.MOUNT} Atom "${s ?? "anonymous"}" changed:`,
960
- t,
961
- "→",
962
- e
963
- );
1057
+ atomChanged(n, t, e, s) {
1058
+ this.enabled && console.log(`${n} Atom "${t ?? "anonymous"}" changed:`, e, "→", s);
964
1059
  },
965
1060
  /**
966
1061
  * Logs a DOM update and triggers a visual highlight flash.
967
- * Only active when debug mode is enabled.
968
- *
969
- * @param target - The element or jQuery wrapper that was updated.
970
- * @param type - The binding type (e.g. 'text', 'checked', 'attr.href').
971
- * @param value - The new value that was applied.
972
1062
  */
973
- domUpdated(s, t, e) {
974
- if (!W) return;
975
- const n = s instanceof Element ? s : s[0];
976
- n instanceof HTMLElement && (console.log(`${g.MOUNT} DOM updated: ${Xt(n)}.${t} =`, e), bs(n));
1063
+ domUpdated(n, t, e, s) {
1064
+ if (!this.enabled) return;
1065
+ const i = t instanceof Element ? t : t[0];
1066
+ i && (console.log(`${n} DOM updated: ${X(i)}.${e} =`, s), Qe(i));
977
1067
  },
978
1068
  /**
979
1069
  * Logs a cleanup event only when debug mode is active.
980
1070
  */
981
- cleanup(s) {
982
- W && console.log(`${g.MOUNT} Cleanup: ${s}`);
1071
+ cleanup(n, t) {
1072
+ this.enabled && console.log(`${n} Cleanup: ${t}`);
983
1073
  },
984
1074
  /**
985
- * Unconditional warning for runtime errors and unexpected states.
986
- * Not gated by debugEnabled — these are always surfaced regardless of
987
- * debug mode because they indicate real problems (e.g. dispose failures,
988
- * missing route targets, pushState security errors).
989
- *
990
- * `prefix` is the subsystem tag (e.g. `LOG_PREFIXES.ROUTE`) so that the
991
- * originating subsystem appears in the log rather than the generic MOUNT tag.
992
- * Pass an empty string to emit a prefix-free message.
1075
+ * Unconditional warning for runtime errors.
993
1076
  */
994
- warn(s, t, ...e) {
995
- console.warn(`${s} ${t}`, ...e);
1077
+ warn(n, t, ...e) {
1078
+ console.warn(`${n} ${t}`, ...e);
996
1079
  },
997
1080
  /**
998
1081
  * Unconditional error for binding failures.
999
- * Not gated by debugEnabled — binding errors are always surfaced because
1000
- * they indicate a broken updater that silently stopped applying values.
1001
1082
  */
1002
- error(s, t, e) {
1003
- console.error(`${s} ${t}`, e);
1004
- }
1005
- }, Gt = "atom-debug-highlight", Cs = "data-atom-debug";
1006
- let ce;
1007
- function Ss() {
1008
- if (ce?.deref()?.isConnected) return;
1009
- const s = document.createElement("style");
1010
- s.setAttribute(Cs, ""), s.textContent = `.${Gt}{outline:2px solid rgba(255,68,68,0.8);outline-offset:1px;transition:outline ${Is} ease-out}`, document.head.appendChild(s), ce = new WeakRef(s);
1011
- }
1012
- const xt = /* @__PURE__ */ new WeakMap(), Pt = /* @__PURE__ */ new WeakMap();
1013
- function bs(s) {
1014
- if (!s.isConnected) return;
1015
- Ss();
1016
- const t = Pt.get(s);
1083
+ error(n, t, e) {
1084
+ console.error(`${n} ${t}`, e);
1085
+ }
1086
+ }, Ot = "atom-debug-highlight", Kt = "data-atom-debug";
1087
+ let st;
1088
+ function Ye() {
1089
+ if ((st instanceof HTMLStyleElement ? st : st?.deref())?.isConnected || document.querySelector(`style[${Kt}]`)) return;
1090
+ const t = document.createElement("style");
1091
+ t.setAttribute(Kt, ""), t.textContent = `.${Ot}{outline:2px solid rgba(255,68,68,0.8);outline-offset:1px;transition:outline ${qe} ease-out}`, document.head.appendChild(t), typeof WeakRef < "u" ? st = new WeakRef(t) : st = t;
1092
+ }
1093
+ const Nt = /* @__PURE__ */ new WeakMap(), bt = /* @__PURE__ */ new WeakMap();
1094
+ function Qe(n) {
1095
+ if (!d.enabled || !n.isConnected) return;
1096
+ Ye();
1097
+ const t = bt.get(n);
1017
1098
  t !== void 0 && cancelAnimationFrame(t);
1018
- const e = xt.get(s);
1099
+ const e = Nt.get(n);
1019
1100
  e !== void 0 && clearTimeout(e);
1020
- const n = requestAnimationFrame(() => {
1021
- Pt.delete(s), s.classList.add(Gt), xt.set(
1022
- s,
1101
+ const s = requestAnimationFrame(() => {
1102
+ bt.delete(n), n.isConnected && (n.classList.add(Ot), Nt.set(
1103
+ n,
1023
1104
  setTimeout(() => {
1024
- s.classList.remove(Gt), xt.delete(s);
1025
- }, Ce)
1026
- );
1105
+ n.isConnected && n.classList.remove(Ot), Nt.delete(n);
1106
+ }, ie.HIGHLIGHT_DURATION_MS)
1107
+ ));
1027
1108
  });
1028
- Pt.set(s, n);
1109
+ bt.set(n, s);
1029
1110
  }
1030
- function Se(s, t) {
1031
- return Bt(s, t);
1111
+ function re(n, t) {
1112
+ return Dt(n, t);
1032
1113
  }
1033
- Object.defineProperty(Se, "debug", {
1114
+ Object.defineProperty(re, "debug", {
1034
1115
  enumerable: !0,
1035
1116
  // configurable: true allows tests and advanced consumers to redefine or
1036
1117
  // delete the accessor if needed. The default (false) would permanently lock
1037
1118
  // the property on the function object.
1038
1119
  configurable: !0,
1039
1120
  get() {
1040
- return f.enabled;
1121
+ return d.enabled;
1041
1122
  },
1042
- set(s) {
1043
- f.enabled = s;
1123
+ set(n) {
1124
+ d.enabled = n;
1044
1125
  }
1045
1126
  });
1046
- function Ts() {
1047
- return new Promise((s) => setTimeout(s, 0));
1048
- }
1049
- const Rs = {
1050
- // `atom` carries a runtime `debug` accessor added via Object.defineProperty.
1051
- // TypeScript cannot see it through the declared function type, so the double
1052
- // cast is unavoidable. The NamespaceExtensions annotation still verifies all
1053
- // other fields; only `atom`'s shape escapes static checking here.
1054
- atom: Se,
1055
- computed: St,
1056
- effect: X,
1057
- batch: Ie,
1058
- untracked: H,
1059
- isAtom: qt,
1060
- isComputed: qe,
1061
- isReactive: ye,
1062
- nextTick: Ts
1127
+ function We() {
1128
+ return new Promise((n) => setTimeout(n, 0));
1129
+ }
1130
+ const Ze = {
1131
+ // Double cast required for the `atom` function due to its runtime `debug`
1132
+ // accessor (see JSDoc for `function atom` above). All other fields are
1133
+ // fully verified by `NamespaceExtensions`.
1134
+ atom: re,
1135
+ computed: gt,
1136
+ effect: V,
1137
+ batch: ne,
1138
+ untracked: P,
1139
+ isAtom: wt,
1140
+ isComputed: xe,
1141
+ isReactive: oe,
1142
+ nextTick: We
1063
1143
  };
1064
- l.extend(Rs);
1065
- const J = "_aes-bound";
1066
- class Ns {
1144
+ h.extend(Ze);
1145
+ const G = "_aes-bound";
1146
+ class Je {
1067
1147
  constructor() {
1068
1148
  this.records = /* @__PURE__ */ new WeakMap(), this.preservedNodes = /* @__PURE__ */ new WeakSet(), this.ignoredNodes = /* @__PURE__ */ new WeakSet();
1069
1149
  }
@@ -1087,19 +1167,19 @@ class Ns {
1087
1167
  // --------------------------------------------------------------------------
1088
1168
  getOrCreateRecord(t) {
1089
1169
  let e = this.records.get(t);
1090
- return e || (e = {}, this.records.set(t, e), t.classList.add(J)), e;
1170
+ return e || (e = { effects: void 0, cleanups: void 0, componentCleanup: void 0 }, this.records.set(t, e), t.classList.add(G)), e;
1091
1171
  }
1092
1172
  trackEffect(t, e) {
1093
- const n = this.getOrCreateRecord(t);
1094
- n.effects ??= [], n.effects.push(e);
1173
+ const s = this.getOrCreateRecord(t);
1174
+ s.effects ??= [], s.effects.push(e);
1095
1175
  }
1096
1176
  trackCleanup(t, e) {
1097
- const n = this.getOrCreateRecord(t);
1098
- n.cleanups ??= [], n.cleanups.push(e);
1177
+ const s = this.getOrCreateRecord(t);
1178
+ s.cleanups ??= [], s.cleanups.push(e);
1099
1179
  }
1100
1180
  setComponentCleanup(t, e) {
1101
- const n = this.getOrCreateRecord(t);
1102
- n.componentCleanup = e;
1181
+ const s = this.getOrCreateRecord(t);
1182
+ s.componentCleanup = e;
1103
1183
  }
1104
1184
  hasBind(t) {
1105
1185
  return this.records.has(t);
@@ -1110,667 +1190,921 @@ class Ns {
1110
1190
  cleanup(t) {
1111
1191
  const e = this.records.get(t);
1112
1192
  if (!e) {
1113
- t.isConnected && t.classList.remove(J), this.preservedNodes.delete(t), this.ignoredNodes.delete(t);
1193
+ t.nodeType === 1 && t.classList.remove(G), this.preservedNodes.delete(t), this.ignoredNodes.delete(t);
1114
1194
  return;
1115
1195
  }
1116
- if (this.records.delete(t), this.preservedNodes.delete(t), this.ignoredNodes.delete(t), t.isConnected && t.classList.remove(J), f.enabled && f.cleanup(Xt(t)), e.componentCleanup)
1196
+ if (this.records.delete(t), this.preservedNodes.delete(t), this.ignoredNodes.delete(t), t.nodeType === 1 && t.classList.remove(G), d.enabled) {
1197
+ const s = t.nodeType === 1 ? X(t) : t.nodeName || "Node";
1198
+ d.cleanup(E.BINDING, s);
1199
+ }
1200
+ if (e.componentCleanup)
1117
1201
  try {
1118
1202
  e.componentCleanup();
1119
- } catch (n) {
1120
- f.error(g.MOUNT, T.MOUNT_CLEANUP_ERROR(), n);
1203
+ } catch (s) {
1204
+ const i = t.nodeType === 1 ? X(t) : "Node";
1205
+ d.error(E.MOUNT, S.MOUNT.CLEANUP_ERROR(i), s);
1121
1206
  }
1122
1207
  if (e.effects) {
1123
- const n = e.effects;
1124
- for (let i = 0, o = n.length; i < o; i++)
1208
+ const s = e.effects;
1209
+ for (let i = 0, o = s.length; i < o; i++)
1125
1210
  try {
1126
- n[i].dispose();
1211
+ s[i].dispose();
1127
1212
  } catch (r) {
1128
- f.error(g.BINDING, T.EFFECT_DISPOSE_ERROR(), r);
1213
+ const c = t.nodeType === 1 ? X(t) : "Node";
1214
+ d.error(E.BINDING, S.CORE.EFFECT_DISPOSE_ERROR(c), r);
1129
1215
  }
1130
1216
  }
1131
1217
  if (e.cleanups) {
1132
- const n = e.cleanups;
1133
- for (let i = 0, o = n.length; i < o; i++)
1218
+ const s = e.cleanups;
1219
+ for (let i = 0, o = s.length; i < o; i++)
1134
1220
  try {
1135
- n[i]();
1221
+ s[i]();
1136
1222
  } catch (r) {
1137
- f.error(g.BINDING, T.BINDING_CLEANUP_ERROR(), r);
1223
+ const c = t.nodeType === 1 ? X(t) : "Node";
1224
+ d.error(E.BINDING, S.BINDING.CLEANUP_ERROR(c), r);
1138
1225
  }
1139
1226
  }
1140
1227
  }
1141
1228
  cleanupDescendants(t) {
1142
- const e = t.getElementsByClassName(J);
1143
- for (let n = e.length - 1; n >= 0; n--) {
1144
- const i = e[n];
1145
- i && (this.records.has(i) ? this.cleanup(i) : (i.classList.remove(J), f.enabled && f.warn(
1146
- g.BINDING,
1147
- `${J} class found on unregistered element:`,
1229
+ const e = "getElementsByClassName" in t && typeof t.getElementsByClassName == "function" ? t.getElementsByClassName(G) : t.querySelectorAll(`.${G}`);
1230
+ for (let s = e.length - 1; s >= 0; s--) {
1231
+ const i = e[s];
1232
+ i && (this.records.has(i) ? this.cleanup(i) : (i.classList.remove(G), d.enabled && d.warn(
1233
+ E.BINDING,
1234
+ `${G} class found on unregistered element:`,
1148
1235
  i
1149
1236
  )));
1150
1237
  }
1151
1238
  }
1152
1239
  cleanupTree(t) {
1153
- this.cleanupDescendants(t), this.cleanup(t);
1240
+ (t.nodeType === 1 || t.nodeType === 11) && this.cleanupDescendants(t), this.cleanup(t);
1154
1241
  }
1155
1242
  }
1156
- const y = new Ns();
1157
- let it = null, pt = null;
1158
- function Os(s) {
1159
- if (it !== null) {
1160
- pt !== s && f.warn(
1161
- g.BINDING,
1162
- "enableAutoCleanup() called with a different root while already active. Observation was NOT switched — call disableAutoCleanup() first.",
1163
- { current: pt, requested: s }
1164
- );
1243
+ const R = new Je(), ft = /* @__PURE__ */ new Map();
1244
+ function ts(n) {
1245
+ if (ft.has(n))
1165
1246
  return;
1166
- }
1167
- pt = s, it = new MutationObserver((t) => {
1168
- for (let e = 0, n = t.length; e < n; e++) {
1169
- const i = t[e].removedNodes;
1170
- for (let o = 0, r = i.length; o < r; o++) {
1171
- const c = i[o];
1172
- c.nodeType === 1 && (c.isConnected || y.isKept(c) || y.isIgnored(c) || y.cleanupTree(c));
1247
+ const t = new MutationObserver((e) => {
1248
+ for (let s = 0, i = e.length; s < i; s++) {
1249
+ const o = e[s].removedNodes;
1250
+ for (let r = 0, c = o.length; r < c; r++) {
1251
+ const a = o[r];
1252
+ a.nodeType === 1 && (a.isConnected || R.isKept(a) || R.isIgnored(a) || R.cleanupTree(a));
1173
1253
  }
1174
1254
  }
1175
- }), it.observe(s, { childList: !0, subtree: !0 });
1255
+ });
1256
+ t.observe(n, { childList: !0, subtree: !0 }), ft.set(n, t);
1176
1257
  }
1177
- function Vs() {
1178
- it?.disconnect(), it = null, pt = null;
1258
+ function Gs() {
1259
+ ft.forEach((n) => n.disconnect()), ft.clear();
1179
1260
  }
1180
- function Q(s, t, e, n) {
1181
- if (ye(t)) {
1261
+ function B(n, t, e, s) {
1262
+ if (oe(t)) {
1182
1263
  const i = t;
1183
- y.trackEffect(
1184
- s,
1185
- X(() => {
1186
- const o = i.value;
1187
- H(() => {
1188
- try {
1189
- e(o);
1190
- } catch (r) {
1191
- f.error(g.BINDING, `${T.UPDATER_ERROR(n)}:`, r);
1192
- return;
1193
- }
1194
- f.enabled && f.domUpdated(s, n, o);
1195
- });
1196
- })
1264
+ R.trackEffect(
1265
+ n,
1266
+ V(
1267
+ () => {
1268
+ const o = i.value;
1269
+ P(() => {
1270
+ try {
1271
+ e(o);
1272
+ } catch (r) {
1273
+ d.error(E.BINDING, S.BINDING.UPDATER_ERROR(s), r);
1274
+ return;
1275
+ }
1276
+ d.enabled && d.domUpdated(E.BINDING, n, s, o);
1277
+ });
1278
+ },
1279
+ { name: s }
1280
+ )
1197
1281
  );
1198
- } else {
1199
- try {
1200
- e(t);
1201
- } catch (i) {
1202
- f.error(g.BINDING, `${T.UPDATER_ERROR(n)} (static):`, i);
1203
- return;
1204
- }
1205
- f.enabled && f.domUpdated(s, n, t);
1206
- }
1282
+ } else
1283
+ P(() => {
1284
+ try {
1285
+ e(t);
1286
+ } catch (i) {
1287
+ d.error(E.BINDING, S.BINDING.UPDATER_ERROR(s, !0), i);
1288
+ return;
1289
+ }
1290
+ d.enabled && d.domUpdated(E.BINDING, n, s, t);
1291
+ });
1207
1292
  }
1208
- const F = /* @__PURE__ */ Symbol("atom-effect-internal"), mt = /* @__PURE__ */ new WeakMap();
1293
+ const dt = /* @__PURE__ */ Symbol("atom-effect-internal"), _t = /* @__PURE__ */ new WeakMap();
1209
1294
  let x = null;
1210
- const be = (s) => {
1211
- if (s[F]) return s;
1212
- let t = mt.get(s);
1295
+ const ce = (n) => {
1296
+ if (n[dt]) return n;
1297
+ let t = _t.get(n);
1213
1298
  return t || (t = function(...e) {
1214
- return Ie(() => s.apply(this, e));
1215
- }, t[F] = !0, mt.set(s, t)), t;
1299
+ return ne(() => n.apply(this, e));
1300
+ }, t[dt] = !0, _t.set(n, t)), t;
1216
1301
  };
1217
- function Ds(s) {
1218
- const t = {};
1219
- return Object.keys(s).forEach((e) => {
1220
- const n = s[e];
1221
- n && (t[e] = be(n));
1222
- }), t;
1223
- }
1224
- function vs(s) {
1225
- const t = {};
1226
- return Object.keys(s).forEach((e) => {
1227
- const n = s[e];
1228
- t[e] = n ? mt.get(n) ?? n : void 0;
1229
- }), t;
1230
- }
1231
- function As() {
1302
+ function es(n) {
1303
+ const t = {}, e = Object.entries(n);
1304
+ for (let s = 0, i = e.length; s < i; s++) {
1305
+ const o = e[s], r = o[0], c = o[1];
1306
+ c && (t[r] = ce(c));
1307
+ }
1308
+ return t;
1309
+ }
1310
+ function ss(n) {
1311
+ const t = {}, e = Object.entries(n);
1312
+ for (let s = 0, i = e.length; s < i; s++) {
1313
+ const o = e[s], r = o[0], c = o[1];
1314
+ t[r] = c ? _t.get(c) ?? c : void 0;
1315
+ }
1316
+ return t;
1317
+ }
1318
+ function ns() {
1232
1319
  if (x !== null) return;
1233
1320
  x = {
1234
- on: l.fn.on,
1235
- off: l.fn.off,
1236
- remove: l.fn.remove,
1237
- empty: l.fn.empty,
1238
- detach: l.fn.detach
1321
+ on: h.fn.on,
1322
+ off: h.fn.off,
1323
+ remove: h.fn.remove,
1324
+ empty: h.fn.empty,
1325
+ detach: h.fn.detach
1239
1326
  };
1240
- const s = x;
1241
- l.fn.remove = function(t) {
1327
+ const n = x;
1328
+ h.fn.remove = function(t) {
1242
1329
  const e = t ? this.filter(t) : this;
1243
- for (let n = 0, i = e.length; n < i; n++) {
1244
- const o = e[n];
1245
- o && (y.markIgnored(o), y.cleanupTree(o));
1330
+ for (let i = 0, o = e.length; i < o; i++) {
1331
+ const r = e[i];
1332
+ r && (R.markIgnored(r), R.cleanupTree(r));
1246
1333
  }
1247
- return s.remove.call(this, t);
1248
- }, l.fn.empty = function() {
1249
- for (let t = 0, e = this.length; t < e; t++) {
1250
- const n = this[t];
1251
- n && y.cleanupDescendants(n);
1334
+ const s = n.remove.call(this, t);
1335
+ return s !== void 0 ? s : this;
1336
+ }, h.fn.empty = function() {
1337
+ for (let e = 0, s = this.length; e < s; e++) {
1338
+ const i = this[e];
1339
+ i?.hasChildNodes() && R.cleanupDescendants(i);
1252
1340
  }
1253
- return s.empty.call(this);
1254
- }, l.fn.detach = function(t) {
1341
+ const t = n.empty.call(this);
1342
+ return t !== void 0 ? t : this;
1343
+ }, h.fn.detach = function(t) {
1255
1344
  const e = t ? this.filter(t) : this;
1256
- for (let n = 0, i = e.length; n < i; n++) {
1257
- const o = e[n];
1258
- o && y.keep(o);
1345
+ for (let i = 0, o = e.length; i < o; i++) {
1346
+ const r = e[i];
1347
+ r && R.keep(r);
1259
1348
  }
1260
- return s.detach.call(this, t);
1261
- }, l.fn.on = function(...t) {
1349
+ const s = n.detach.call(this, t);
1350
+ return s !== void 0 ? s : this;
1351
+ }, h.fn.on = function(...t) {
1262
1352
  const e = t[0];
1263
1353
  if (e && typeof e == "object")
1264
- t[0] = Ds(e);
1265
- else
1266
- for (let n = t.length - 1; n >= 0; n--)
1267
- if (typeof t[n] == "function") {
1268
- t[n] = be(t[n]);
1269
- break;
1270
- }
1271
- return s.on.apply(this, t);
1272
- }, l.fn.off = function(...t) {
1354
+ t[0] = es(e);
1355
+ else {
1356
+ const i = t.length - 1;
1357
+ i >= 0 && typeof t[i] == "function" && (t[i] = ce(t[i]));
1358
+ }
1359
+ const s = n.on.apply(this, t);
1360
+ return s !== void 0 ? s : this;
1361
+ }, h.fn.off = function(...t) {
1273
1362
  const e = t[0];
1274
1363
  if (e && typeof e == "object")
1275
- t[0] = vs(e);
1276
- else
1277
- for (let n = t.length - 1; n >= 0; n--)
1278
- if (typeof t[n] == "function") {
1279
- const i = t[n];
1280
- t[n] = mt.get(i) ?? i;
1281
- break;
1282
- }
1283
- return s.off.apply(this, t);
1364
+ t[0] = ss(e);
1365
+ else {
1366
+ const i = t.length - 1;
1367
+ if (i >= 0 && typeof t[i] == "function") {
1368
+ const o = t[i];
1369
+ t[i] = _t.get(o) ?? o;
1370
+ }
1371
+ }
1372
+ const s = n.off.apply(this, t);
1373
+ return s !== void 0 ? s : this;
1284
1374
  };
1285
1375
  }
1286
- function qs() {
1287
- x !== null && (l.fn.on = x.on, l.fn.off = x.off, l.fn.remove = x.remove, l.fn.empty = x.empty, l.fn.detach = x.detach, x = null);
1376
+ function Hs() {
1377
+ x !== null && (h.fn.on = x.on, h.fn.off = x.off, h.fn.remove = x.remove, h.fn.empty = x.empty, h.fn.detach = x.detach, x = null);
1288
1378
  }
1289
- var v = /* @__PURE__ */ ((s) => (s[s.None = 0] = "None", s[s.Focused = 1] = "Focused", s[s.Composing = 2] = "Composing", s[s.SyncingToAtom = 4] = "SyncingToAtom", s[s.SyncingToDom = 8] = "SyncingToDom", s[s.Busy = 14] = "Busy", s))(v || {});
1290
- let Ls = 0;
1291
- class Us {
1292
- constructor(t, e, n) {
1379
+ var O = /* @__PURE__ */ ((n) => (n[n.None = 0] = "None", n[n.Focused = 1] = "Focused", n[n.Composing = 2] = "Composing", n[n.SyncingToAtom = 4] = "SyncingToAtom", n[n.SyncingToDom = 8] = "SyncingToDom", n[n.Busy = 14] = "Busy", n))(O || {});
1380
+ let is = 0;
1381
+ function nt(n) {
1382
+ n[dt] = !0;
1383
+ }
1384
+ class os {
1385
+ constructor(t, e, s) {
1293
1386
  this.flags = 0, this.timeoutId = void 0, this.handleCompositionStart = () => {
1294
- this.flags |= v.Composing;
1387
+ this.flags |= O.Composing;
1295
1388
  }, this.handleCompositionEnd = () => {
1296
- this.flags &= ~v.Composing, this.handleInput();
1389
+ this.flags &= ~O.Composing, this.handleInput();
1297
1390
  }, this.handleFocus = () => {
1298
- this.flags |= v.Focused;
1391
+ this.flags |= O.Focused;
1299
1392
  }, this.handleBlur = () => {
1300
- this.flags &= ~v.Focused, this.timeoutId !== void 0 && (clearTimeout(this.timeoutId), this.timeoutId = void 0, this.syncAtomFromDom());
1301
- const r = this.format(this.atom.peek());
1302
- this.el.value !== r && (this.el.value = r);
1393
+ this.flags &= ~O.Focused;
1394
+ const c = !!(this.flags & O.Composing);
1395
+ this.flags &= ~O.Composing, this.flushPendingDebounce(), c && this.timeoutId === void 0 && this.syncAtomFromDom(), this.normalizeDomValue();
1303
1396
  }, this.syncDomFromAtom = () => {
1304
- const r = this.atom.value;
1305
- H(() => {
1306
- const c = this.format(r), E = this.el.value;
1307
- if (E === c) return;
1308
- const d = !!(this.flags & v.Focused);
1309
- if (d)
1397
+ const c = this.atom.value;
1398
+ P(() => {
1399
+ const a = this.format(c);
1400
+ let l;
1401
+ if (this.isMultipleSelect ? l = this.$el.val() || [] : l = this.el.value, this.equal(l, c)) return;
1402
+ const u = !!(this.flags & O.Focused);
1403
+ if (u)
1310
1404
  try {
1311
- if (this.equal(this.parse(E), r)) return;
1405
+ const _ = this.isMultipleSelect ? l : this.parse(this.el.value);
1406
+ if (this.equal(_, c)) return;
1312
1407
  } catch {
1313
1408
  }
1314
- this.flags |= v.SyncingToDom;
1409
+ this.flags |= O.SyncingToDom;
1315
1410
  try {
1316
- if (d && (this.el instanceof HTMLInputElement || this.el instanceof HTMLTextAreaElement)) {
1317
- const m = this.el.selectionStart, N = this.el.selectionEnd;
1318
- this.el.value = c;
1319
- const p = c.length;
1320
- m !== null && N !== null && this.el.setSelectionRange(m < p ? m : p, N < p ? N : p);
1321
- } else
1322
- this.el.value = c;
1323
- f.domUpdated(this.$el, "val", c);
1411
+ if (this.isMultipleSelect)
1412
+ this.$el.val(c);
1413
+ else if (u && (this.el instanceof HTMLInputElement || this.el instanceof HTMLTextAreaElement))
1414
+ try {
1415
+ const _ = this.el.selectionStart, y = this.el.selectionEnd;
1416
+ this.el.value = a;
1417
+ const p = a.length;
1418
+ _ !== null && y !== null && this.el.setSelectionRange(_ < p ? _ : p, y < p ? y : p);
1419
+ } catch {
1420
+ this.el.value = a;
1421
+ }
1422
+ else
1423
+ this.el.value = a;
1424
+ d.enabled && d.domUpdated(E.BINDING, this.$el, "val", a);
1324
1425
  } finally {
1325
- this.flags &= ~v.SyncingToDom;
1426
+ this.flags &= ~O.SyncingToDom;
1326
1427
  }
1327
1428
  });
1328
1429
  }, this.cleanup = () => {
1329
1430
  this.$el.off(this.ns), clearTimeout(this.timeoutId), this.timeoutId = void 0;
1330
- }, this.$el = t, this.el = t[0], this.atom = e, this.ns = `.atomBind-${++Ls}`;
1331
- const i = n.debounce ?? 0, o = n.event ?? We.EVENT;
1332
- this.parse = n.parse ?? ((r) => r), this.format = n.format ?? ((r) => String(r ?? "")), this.equal = n.equal ?? Object.is, i > 0 ? this.handleInput = () => {
1333
- this.flags & v.Composing || (clearTimeout(this.timeoutId), this.timeoutId = setTimeout(() => this.syncAtomFromDom(), i));
1431
+ }, this.$el = t, this.el = t[0], this.atom = e, this.isMultipleSelect = this.el.tagName === "SELECT" && this.el.multiple, this.ns = `.atomBind-${++is}`;
1432
+ const i = s.debounce ?? 0, o = s.event ?? Be.EVENT;
1433
+ this.parse = s.parse ?? ((c) => c), this.format = s.format ?? ((c) => this.isMultipleSelect ? (Array.isArray(c) ? c : c ? [String(c)] : []).join(",") : String(c ?? ""));
1434
+ const r = s.equal ?? Object.is;
1435
+ this.equal = (c, a) => r(c, a) ? !0 : Array.isArray(c) && Array.isArray(a) ? c.length === a.length && c.every((l, u) => Object.is(l, a[u])) : !1, i > 0 ? this.handleInput = () => {
1436
+ this.flags & O.Composing || (clearTimeout(this.timeoutId), this.timeoutId = setTimeout(() => this.syncAtomFromDom(), i));
1334
1437
  } : this.handleInput = () => {
1335
- this.flags & v.Composing || this.syncAtomFromDom();
1336
- }, this.handleFocus[F] = !0, this.handleBlur[F] = !0, this.handleCompositionStart[F] = !0, this.handleCompositionEnd[F] = !0, this.handleInput[F] = !0, this.bindEvents(o);
1438
+ this.flags & O.Composing || this.syncAtomFromDom();
1439
+ }, nt(this.handleFocus), nt(this.handleBlur), nt(this.handleCompositionStart), nt(this.handleCompositionEnd), nt(this.handleInput), this.bindEvents(o);
1440
+ }
1441
+ // --- Blur helpers ---
1442
+ /**
1443
+ * Flushes any pending debounce timer immediately.
1444
+ * Called on blur so that a value the user finished typing is not lost
1445
+ * when focus moves away before the debounce delay expires.
1446
+ */
1447
+ flushPendingDebounce() {
1448
+ this.timeoutId !== void 0 && (clearTimeout(this.timeoutId), this.timeoutId = void 0, this.syncAtomFromDom());
1449
+ }
1450
+ /**
1451
+ * Re-formats the current atom value into the input element on blur.
1452
+ * Ensures the displayed text matches the canonical format (e.g. trims trailing
1453
+ * spaces, applies number formatting) after the user finishes editing.
1454
+ */
1455
+ normalizeDomValue() {
1456
+ const t = this.format(this.atom.peek());
1457
+ if (this.isMultipleSelect) {
1458
+ const e = this.$el.val() || [], s = Array.isArray(this.atom.peek()) ? this.atom.peek() : [];
1459
+ this.equal(e, s) || this.$el.val(s);
1460
+ } else this.el.value !== t && (this.el.value = t);
1337
1461
  }
1338
1462
  // --- Sync Logic ---
1339
1463
  syncAtomFromDom() {
1340
- if (!(this.flags & v.Busy)) {
1341
- this.flags |= v.SyncingToAtom;
1464
+ if (!(this.flags & O.Busy)) {
1465
+ this.flags |= O.SyncingToAtom;
1342
1466
  try {
1343
- const t = this.parse(this.el.value);
1344
- this.equal(this.atom.peek(), t) || (this.atom.value = t);
1467
+ let t;
1468
+ this.isMultipleSelect ? t = this.$el.val() || [] : t = this.el.value;
1469
+ const e = this.parse(t);
1470
+ this.equal(this.atom.peek(), e) || (this.atom.value = e);
1345
1471
  } catch (t) {
1346
- f.warn(g.BINDING, `${T.PARSE_ERROR()}:`, t);
1472
+ d.warn(
1473
+ E.BINDING,
1474
+ S.BINDING.PARSE_ERROR(t instanceof Error ? t.message : String(t)),
1475
+ t
1476
+ );
1347
1477
  } finally {
1348
- this.flags &= ~v.SyncingToAtom;
1478
+ this.flags &= ~O.SyncingToAtom;
1349
1479
  }
1350
1480
  }
1351
1481
  }
1352
1482
  bindEvents(t) {
1353
- const e = this.ns;
1354
- this.$el.on(`focus${e}`, this.handleFocus).on(`blur${e}`, this.handleBlur).on(`compositionstart${e}`, this.handleCompositionStart).on(`compositionend${e}`, this.handleCompositionEnd).on(`${t}${e}`, this.handleInput);
1483
+ const e = this.ns, s = t.trim().split(/\s+/).map((i) => `${i}${e}`).join(" ");
1484
+ this.$el.on(`focus${e}`, this.handleFocus).on(`blur${e}`, this.handleBlur).on(`compositionstart${e}`, this.handleCompositionStart).on(`compositionend${e}`, this.handleCompositionEnd).on(s, this.handleInput);
1355
1485
  }
1356
1486
  }
1357
- function ws(s, t, e) {
1358
- const n = new Us(s, t, e);
1359
- return { fx: X(n.syncDomFromAtom), cleanup: n.cleanup };
1487
+ function rs(n, t, e) {
1488
+ const s = new os(n, t, e);
1489
+ return { fx: V(s.syncDomFromAtom), cleanup: s.cleanup };
1360
1490
  }
1361
- const ae = /* @__PURE__ */ new Map();
1362
- function ks(s) {
1363
- let t = ae.get(s);
1364
- return t !== void 0 || (t = s.includes("-") ? s.replace(/-./g, (e) => e[1].toUpperCase()) : s, ae.set(s, t)), t;
1491
+ const cs = /* @__PURE__ */ new Set([
1492
+ "href",
1493
+ "src",
1494
+ "action",
1495
+ "formaction",
1496
+ "xlink:href",
1497
+ "data",
1498
+ "poster",
1499
+ "background",
1500
+ "cite",
1501
+ "longdesc",
1502
+ "profile",
1503
+ "usemap",
1504
+ "classid",
1505
+ "codebase"
1506
+ ]), as = /^\s*(?:javascript|vbscript)\s*:/i, ls = (
1507
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: Intentionally matching control characters for XSS sanitization
1508
+ /(?:expression\s*\(|behavior\s*:|-moz-binding\s*:|(?:\\[0-9a-f]{1,6}\s*|[\s\x00-\x20/'"])*(?: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|d\s*a\s*t\s*a)\s*:(?!image\/))/i
1509
+ ), hs = /url\s*\(\s*(?:["']?\s*)?(?:javascript|vbscript)\s*:/i, us = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, fs = /&#x([0-9a-f]+);?|&#([0-9]+);?/gi, ds = {
1510
+ colon: ":",
1511
+ Tab: " ",
1512
+ NewLine: `
1513
+ `
1514
+ }, _s = /&(colon|Tab|NewLine);/g, ps = /<\?[\s\S]*?\?>/g, Es = /(<(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, ms = /(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, gs = /data\s*:\s*(?:text\/(?:html|javascript|vbscript|xml)|application\/(?:javascript|xhtml\+xml|xml|x-shockwave-flash)|image\/svg\+xml)/gi, Is = /\bon\w+\s*=/gim, ys = new RegExp(ls.source, "gim");
1515
+ function pt(n) {
1516
+ let t = String(n ?? "");
1517
+ t = t.replace(us, ""), t = t.replace(
1518
+ fs,
1519
+ (s, i, o) => String.fromCodePoint(i ? parseInt(i, 16) : parseInt(o, 10))
1520
+ ), t = t.replace(_s, (s, i) => ds[i] ?? ""), t = t.replace(ps, "");
1521
+ let e;
1522
+ do
1523
+ e = t, t = t.replace(Es, "");
1524
+ while (t !== e);
1525
+ return t = t.replace(ms, "data-unsafe-protocol:"), t = t.replace(gs, "data-unsafe-protocol:"), t = t.replace(Is, "data-unsafe-attr="), t = t.replace(ys, "data-unsafe-css:"), t;
1365
1526
  }
1366
- const le = /* @__PURE__ */ new WeakMap();
1367
- function xs(s) {
1368
- let t = le.get(s);
1369
- return t || (t = St(() => Ht(s.value)), le.set(s, t)), t;
1527
+ function ae(n, t) {
1528
+ return cs.has(n.toLowerCase()) ? as.test(t) : !1;
1370
1529
  }
1371
- function U(s) {
1530
+ function Cs(n) {
1531
+ return n.toLowerCase().includes("url(") ? hs.test(n) : !1;
1532
+ }
1533
+ const qt = /* @__PURE__ */ new Map();
1534
+ function Ts(n) {
1535
+ let t = qt.get(n);
1536
+ return t !== void 0 || (t = n.includes("-") ? n.replace(/-./g, (e) => e[1].toUpperCase()) : n, qt.set(n, t)), t;
1537
+ }
1538
+ const Xt = /* @__PURE__ */ new WeakMap();
1539
+ function Ss(n) {
1540
+ let t = Xt.get(n);
1541
+ return t || (t = gt(() => pt(n.value)), Xt.set(n, t)), t;
1542
+ }
1543
+ function A(n) {
1372
1544
  return {
1373
- $el: l(s),
1374
- el: s,
1375
- trackCleanup: (t) => y.trackCleanup(s, t)
1545
+ $el: h(n),
1546
+ el: n,
1547
+ trackCleanup: (t) => R.trackCleanup(n, t)
1376
1548
  };
1377
1549
  }
1378
- function Te(s, t, e) {
1379
- const n = s.el;
1380
- Q(
1381
- n,
1550
+ function le(n, t, e) {
1551
+ const s = n.el;
1552
+ B(
1553
+ s,
1382
1554
  t,
1383
1555
  (i) => {
1384
1556
  const o = e ? e(i) : typeof i == "string" ? i : String(i ?? "");
1385
- n.textContent !== o && (n.textContent = o);
1557
+ s.textContent !== o && (s.textContent = o);
1386
1558
  },
1387
1559
  "text"
1388
1560
  );
1389
1561
  }
1390
- function Re(s, t) {
1391
- const e = s.el, n = qt(t) ? xs(t) : t;
1392
- Q(
1562
+ function he(n, t) {
1563
+ const e = n.el, s = wt(t) ? Ss(t) : t;
1564
+ B(
1393
1565
  e,
1394
- n,
1566
+ s,
1395
1567
  (i) => {
1396
- e.innerHTML !== i && (y.cleanupDescendants(e), e.innerHTML = i);
1568
+ e.innerHTML !== i && (R.cleanupDescendants(e), e.innerHTML = i);
1397
1569
  },
1398
1570
  "html"
1399
1571
  );
1400
1572
  }
1401
- function Ne(s, t) {
1573
+ function ue(n, t) {
1402
1574
  for (const e in t)
1403
- if (rt.call(t, e)) {
1404
- const n = t[e];
1405
- Q(
1406
- s.el,
1407
- n,
1408
- (i) => {
1409
- s.el.classList.toggle(e, !!i);
1575
+ if (Z.call(t, e)) {
1576
+ const s = t[e], i = e.trim().split(/\s+/).filter(Boolean);
1577
+ i.length > 1 ? B(
1578
+ n.el,
1579
+ s,
1580
+ (o) => {
1581
+ o ? n.el.classList.add(...i) : n.el.classList.remove(...i);
1582
+ },
1583
+ `class.${e}`
1584
+ ) : i.length === 1 && B(
1585
+ n.el,
1586
+ s,
1587
+ (o) => {
1588
+ n.el.classList.toggle(i[0], !!o);
1410
1589
  },
1411
1590
  `class.${e}`
1412
1591
  );
1413
1592
  }
1414
1593
  }
1415
- function Oe(s, t) {
1416
- const e = s.el, n = e.style;
1594
+ function fe(n, t) {
1595
+ const e = n.el, s = e.style;
1417
1596
  for (const i in t)
1418
- if (rt.call(t, i)) {
1419
- const o = t[i], r = ks(i), [c, E] = Array.isArray(o) ? o : [o, ""];
1420
- Q(
1597
+ if (Z.call(t, i)) {
1598
+ const o = t[i], r = Ts(i), [c, a] = Array.isArray(o) ? o : [o, ""];
1599
+ B(
1421
1600
  e,
1422
1601
  c,
1423
- (d) => {
1424
- const m = E ? `${d}${E}` : String(d);
1425
- Es(m) || (n[r] = m);
1602
+ (l) => {
1603
+ const u = a ? String(l) + a : String(l);
1604
+ Cs(u) || (s[r] = u);
1426
1605
  },
1427
1606
  `css.${i}`
1428
1607
  );
1429
1608
  }
1430
1609
  }
1431
- function De(s, t) {
1432
- const e = s.el;
1433
- for (const n in t)
1434
- if (rt.call(t, n)) {
1435
- if (n.toLowerCase().startsWith("on")) continue;
1436
- Q(
1610
+ function de(n, t) {
1611
+ const e = n.el;
1612
+ for (const s in t)
1613
+ if (Z.call(t, s)) {
1614
+ const i = s.toLowerCase();
1615
+ if (i.startsWith("on")) {
1616
+ console.warn(
1617
+ `${E.BINDING} ${S.SECURITY.BLOCKED_EVENT_HANDLER(s)}`
1618
+ );
1619
+ continue;
1620
+ }
1621
+ const o = i.startsWith("aria-");
1622
+ B(
1437
1623
  e,
1438
- t[n],
1439
- (i) => {
1440
- if (i == null || i === !1) {
1441
- e.removeAttribute(n);
1624
+ t[s],
1625
+ (r) => {
1626
+ if (r == null) {
1627
+ e.removeAttribute(s);
1628
+ return;
1629
+ }
1630
+ if (r === !1 && !o) {
1631
+ e.removeAttribute(s);
1442
1632
  return;
1443
1633
  }
1444
- const o = i === !0 ? n : String(i);
1445
- _s(n, o) || e.getAttribute(n) !== o && e.setAttribute(n, o);
1634
+ const c = r === !0 ? o ? "true" : s : String(r);
1635
+ if (ae(s, c)) {
1636
+ console.warn(
1637
+ `${E.BINDING} ${S.SECURITY.BLOCKED_PROTOCOL(s)}`
1638
+ );
1639
+ return;
1640
+ }
1641
+ e.getAttribute(s) !== c && e.setAttribute(s, c);
1446
1642
  },
1447
- `attr.${n}`
1643
+ `attr.${s}`
1448
1644
  );
1449
1645
  }
1450
1646
  }
1451
- function ve(s, t) {
1452
- const e = s.el;
1453
- for (const n in t)
1454
- if (rt.call(t, n)) {
1455
- if (Ze.has(n)) continue;
1456
- Q(
1457
- s.el,
1458
- t[n],
1459
- (i) => {
1460
- e[n] !== i && (e[n] = i);
1647
+ function _e(n, t) {
1648
+ const e = n.el;
1649
+ for (const s in t)
1650
+ if (Z.call(t, s)) {
1651
+ const i = s.toLowerCase();
1652
+ if (i.startsWith("on")) {
1653
+ console.warn(
1654
+ `${E.BINDING} ${S.SECURITY.BLOCKED_EVENT_HANDLER(s)}`
1655
+ );
1656
+ continue;
1657
+ }
1658
+ if (je.has(s)) {
1659
+ console.warn(`${E.BINDING} ${S.SECURITY.BLOCKED_PROP(s)}`);
1660
+ continue;
1661
+ }
1662
+ const o = He.has(i);
1663
+ B(
1664
+ n.el,
1665
+ t[s],
1666
+ (r) => {
1667
+ if (o && typeof r == "string" && ae(s, r)) {
1668
+ console.warn(
1669
+ `${E.BINDING} ${S.SECURITY.BLOCKED_PROTOCOL(s)}`
1670
+ );
1671
+ return;
1672
+ }
1673
+ e[s] !== r && (e[s] = r);
1461
1674
  },
1462
- `prop.${n}`
1675
+ `prop.${s}`
1463
1676
  );
1464
1677
  }
1465
1678
  }
1466
- function It(s, t, e) {
1467
- const n = s.el;
1468
- Q(
1469
- n,
1679
+ function Et(n, t, e) {
1680
+ const s = n.el, i = e ? "hide" : "show", o = s.style.display, r = o === "none" ? "" : o;
1681
+ B(
1682
+ s,
1470
1683
  t,
1471
- (o) => {
1472
- const r = e !== !!o;
1473
- n.style.display = r ? "" : "none";
1684
+ (c) => {
1685
+ s.style.display = e !== !!c ? r : "none";
1474
1686
  },
1475
- e ? "hide" : "show"
1687
+ i
1476
1688
  );
1477
1689
  }
1478
- function Ae(s, t, e = {}) {
1479
- const n = s.el.tagName.toLowerCase();
1480
- if (!Je.has(n)) {
1481
- console.warn(`${g.BINDING} ${T.INVALID_INPUT_ELEMENT(n)}`);
1690
+ function pe(n, t, e = {}) {
1691
+ const s = n.el.tagName.toLowerCase();
1692
+ if (!Ge.has(s)) {
1693
+ console.warn(
1694
+ `${E.BINDING} ${S.BINDING.INVALID_INPUT_ELEMENT(s)}`
1695
+ );
1482
1696
  return;
1483
1697
  }
1484
- const { fx: i, cleanup: o } = ws(s.$el, t, e);
1485
- y.trackEffect(s.el, i), s.trackCleanup(o);
1698
+ const { fx: i, cleanup: o } = rs(n.$el, t, e);
1699
+ R.trackEffect(n.el, i), n.trackCleanup(o);
1486
1700
  }
1487
- function Le(s, t) {
1488
- const e = s.el, n = s.$el, i = () => {
1489
- const r = e.checked;
1490
- t.value !== r && (t.value = r);
1701
+ function Ee(n, t) {
1702
+ const e = n.el, s = n.$el, i = e.type === "radio", o = () => {
1703
+ const c = e.checked;
1704
+ if (t.value !== c && (t.value = c, i && c && e.name)) {
1705
+ const a = e.name.replace(/"/g, '\\"');
1706
+ (e.form ? h(e.form) : h(document)).find(`input[type="radio"][name="${a}"]`).not(e).trigger("change.atomRadioSync");
1707
+ }
1491
1708
  };
1492
- i[F] = !0, n.on("change", i), s.trackCleanup(() => n.off("change", i));
1493
- const o = X(() => {
1494
- const r = !!t.value;
1495
- H(() => {
1496
- e.checked !== r && (e.checked = r, f.domUpdated(n, "checked", r));
1709
+ o[dt] = !0, s.on("change change.atomRadioSync", o), n.trackCleanup(() => s.off("change change.atomRadioSync", o));
1710
+ const r = V(() => {
1711
+ const c = !!t.value;
1712
+ P(() => {
1713
+ e.checked !== c && (e.checked = c, d.enabled && d.domUpdated(E.BINDING, s, "checked", c));
1497
1714
  });
1498
1715
  });
1499
- y.trackEffect(e, o);
1716
+ R.trackEffect(e, r);
1717
+ }
1718
+ function Ns(n, t) {
1719
+ const e = n.$el;
1720
+ e.on(t), n.trackCleanup(() => e.off(t));
1500
1721
  }
1501
- function Ps(s, t) {
1502
- const e = s.$el;
1503
- e.on(t), s.trackCleanup(() => e.off(t));
1722
+ function bs(n, t, e) {
1723
+ const s = n.$el;
1724
+ s.on(t, e), n.trackCleanup(() => s.off(t, e));
1504
1725
  }
1505
- function $s(s, t, e) {
1506
- const n = s.$el;
1507
- n.on(t, e), s.trackCleanup(() => n.off(t, e));
1726
+ function me(n) {
1727
+ R.cleanupTree(n);
1508
1728
  }
1509
- function Ue(s) {
1510
- y.cleanupTree(s);
1729
+ function k(n) {
1730
+ d.enabled && d.log(E.BINDING, `Skipping non-Element node (nodeType=${n})`);
1511
1731
  }
1512
- l.fn.atomText = function(s, t) {
1513
- for (let e = 0, n = this.length; e < n; e++)
1514
- Te(U(this[e]), s, t);
1732
+ h.fn.atomText = function(n, t) {
1733
+ for (let e = 0, s = this.length; e < s; e++) {
1734
+ const i = this[e];
1735
+ i.nodeType === 1 ? le(A(i), n, t) : k(i.nodeType);
1736
+ }
1515
1737
  return this;
1516
1738
  };
1517
- l.fn.atomHtml = function(s) {
1518
- for (let t = 0, e = this.length; t < e; t++)
1519
- Re(U(this[t]), s);
1739
+ h.fn.atomHtml = function(n) {
1740
+ for (let t = 0, e = this.length; t < e; t++) {
1741
+ const s = this[t];
1742
+ s.nodeType === 1 ? he(A(s), n) : k(s.nodeType);
1743
+ }
1520
1744
  return this;
1521
1745
  };
1522
- l.fn.atomClass = function(s, t) {
1523
- if (typeof s == "string" && t === void 0)
1524
- return console.warn(`${g.BINDING} ${T.MISSING_CONDITION("atomClass")}`), this;
1525
- const e = typeof s == "string" ? { [s]: t } : s;
1526
- for (let n = 0, i = this.length; n < i; n++)
1527
- Ne(U(this[n]), e);
1746
+ h.fn.atomClass = function(n, t) {
1747
+ if (typeof n == "string" && t === void 0)
1748
+ return console.warn(
1749
+ `${E.BINDING} ${S.BINDING.MISSING_CONDITION("atomClass")}`
1750
+ ), this;
1751
+ const e = typeof n == "string" ? { [n]: t } : n;
1752
+ for (let s = 0, i = this.length; s < i; s++) {
1753
+ const o = this[s];
1754
+ o.nodeType === 1 ? ue(A(o), e) : k(o.nodeType);
1755
+ }
1528
1756
  return this;
1529
1757
  };
1530
- l.fn.atomCss = function(s, t, e) {
1531
- if (typeof s == "string" && t === void 0)
1532
- return console.warn(`${g.BINDING} ${T.MISSING_SOURCE("atomCss")}`), this;
1533
- const n = typeof s == "string" ? { [s]: e ? [t, e] : t } : s;
1534
- for (let i = 0, o = this.length; i < o; i++)
1535
- Oe(U(this[i]), n);
1758
+ h.fn.atomCss = function(n, t, e) {
1759
+ if (typeof n == "string" && t === void 0)
1760
+ return console.warn(`${E.BINDING} ${S.BINDING.MISSING_SOURCE("atomCss")}`), this;
1761
+ const s = typeof n == "string" ? { [n]: e ? [t, e] : t } : n;
1762
+ for (let i = 0, o = this.length; i < o; i++) {
1763
+ const r = this[i];
1764
+ r.nodeType === 1 ? fe(A(r), s) : k(r.nodeType);
1765
+ }
1536
1766
  return this;
1537
1767
  };
1538
- l.fn.atomAttr = function(s, t) {
1539
- if (typeof s == "string" && t === void 0)
1540
- return console.warn(`${g.BINDING} ${T.MISSING_SOURCE("atomAttr")}`), this;
1541
- const e = typeof s == "string" ? { [s]: t } : s;
1542
- for (let n = 0, i = this.length; n < i; n++)
1543
- De(U(this[n]), e);
1768
+ h.fn.atomAttr = function(n, t) {
1769
+ if (typeof n == "string" && t === void 0)
1770
+ return console.warn(`${E.BINDING} ${S.BINDING.MISSING_SOURCE("atomAttr")}`), this;
1771
+ const e = typeof n == "string" ? { [n]: t } : n;
1772
+ for (let s = 0, i = this.length; s < i; s++) {
1773
+ const o = this[s];
1774
+ o.nodeType === 1 ? de(A(o), e) : k(o.nodeType);
1775
+ }
1544
1776
  return this;
1545
1777
  };
1546
- l.fn.atomProp = function(s, t) {
1547
- if (typeof s == "string" && t === void 0)
1548
- return console.warn(`${g.BINDING} ${T.MISSING_SOURCE("atomProp")}`), this;
1549
- const e = typeof s == "string" ? { [s]: t } : s;
1550
- for (let n = 0, i = this.length; n < i; n++)
1551
- ve(U(this[n]), e);
1778
+ h.fn.atomProp = function(n, t) {
1779
+ if (typeof n == "string" && t === void 0)
1780
+ return console.warn(`${E.BINDING} ${S.BINDING.MISSING_SOURCE("atomProp")}`), this;
1781
+ const e = typeof n == "string" ? { [n]: t } : n;
1782
+ for (let s = 0, i = this.length; s < i; s++) {
1783
+ const o = this[s];
1784
+ o.nodeType === 1 ? _e(A(o), e) : k(o.nodeType);
1785
+ }
1552
1786
  return this;
1553
1787
  };
1554
- l.fn.atomShow = function(s) {
1555
- for (let t = 0, e = this.length; t < e; t++)
1556
- It(U(this[t]), s, !1);
1788
+ h.fn.atomShow = function(n) {
1789
+ for (let t = 0, e = this.length; t < e; t++) {
1790
+ const s = this[t];
1791
+ s.nodeType === 1 ? Et(A(s), n, !1) : k(s.nodeType);
1792
+ }
1557
1793
  return this;
1558
1794
  };
1559
- l.fn.atomHide = function(s) {
1560
- for (let t = 0, e = this.length; t < e; t++)
1561
- It(U(this[t]), s, !0);
1795
+ h.fn.atomHide = function(n) {
1796
+ for (let t = 0, e = this.length; t < e; t++) {
1797
+ const s = this[t];
1798
+ s.nodeType === 1 ? Et(A(s), n, !0) : k(s.nodeType);
1799
+ }
1562
1800
  return this;
1563
1801
  };
1564
- l.fn.atomVal = function(s, t = {}) {
1565
- for (let e = 0, n = this.length; e < n; e++)
1566
- Ae(U(this[e]), s, t);
1802
+ h.fn.atomVal = function(n, t = {}) {
1803
+ for (let e = 0, s = this.length; e < s; e++) {
1804
+ const i = this[e];
1805
+ i.nodeType === 1 ? pe(
1806
+ A(i),
1807
+ n,
1808
+ t
1809
+ ) : k(i.nodeType);
1810
+ }
1567
1811
  return this;
1568
1812
  };
1569
- l.fn.atomChecked = function(s) {
1570
- for (let t = 0, e = this.length; t < e; t++)
1571
- Le(U(this[t]), s);
1813
+ h.fn.atomChecked = function(n) {
1814
+ for (let t = 0, e = this.length; t < e; t++) {
1815
+ const s = this[t];
1816
+ s.nodeType === 1 ? Ee(A(s), n) : k(s.nodeType);
1817
+ }
1572
1818
  return this;
1573
1819
  };
1574
- l.fn.atomOn = function(s, t) {
1575
- for (let e = 0, n = this.length; e < n; e++)
1576
- $s(U(this[e]), s, t);
1820
+ h.fn.atomOn = function(n, t) {
1821
+ for (let e = 0, s = this.length; e < s; e++) {
1822
+ const i = this[e];
1823
+ i.nodeType === 1 ? bs(A(i), n, t) : k(i.nodeType);
1824
+ }
1577
1825
  return this;
1578
1826
  };
1579
- l.fn.atomBind = function(s) {
1580
- const { text: t, html: e, class: n, css: i, attr: o, prop: r, show: c, hide: E, val: d, checked: m, on: N } = s;
1581
- let p, O;
1582
- d !== void 0 && (Array.isArray(d) ? (p = d[0], O = d[1]) : p = d);
1583
- for (let G = 0, C = this.length; G < C; G++) {
1584
- const I = U(this[G]);
1585
- t !== void 0 && Te(I, t), e !== void 0 && Re(I, e), n !== void 0 && Ne(I, n), i !== void 0 && Oe(I, i), o !== void 0 && De(I, o), r !== void 0 && ve(I, r), c !== void 0 && It(I, c, !1), E !== void 0 && It(I, E, !0), d !== void 0 && Ae(I, p, O), m !== void 0 && Le(I, m), N !== void 0 && Ps(I, N);
1827
+ h.fn.atomBind = function(n) {
1828
+ const { text: t, html: e, class: s, css: i, attr: o, prop: r, show: c, hide: a, val: l, checked: u, on: _ } = n, y = l === void 0 ? null : Array.isArray(l) ? {
1829
+ atom: l[0],
1830
+ opts: l[1]
1831
+ } : { atom: l, opts: void 0 };
1832
+ for (let p = 0, v = this.length; p < v; p++) {
1833
+ const C = this[p];
1834
+ if (C.nodeType !== 1) {
1835
+ k(C.nodeType);
1836
+ continue;
1837
+ }
1838
+ const T = A(C);
1839
+ t !== void 0 && le(T, t), e !== void 0 && he(T, e), s !== void 0 && ue(T, s), i !== void 0 && fe(T, i), o !== void 0 && de(T, o), r !== void 0 && _e(T, r), c !== void 0 && Et(T, c, !1), a !== void 0 && Et(T, a, !0), y !== null && pe(T, y.atom, y.opts), u !== void 0 && Ee(T, u), _ !== void 0 && Ns(T, _);
1586
1840
  }
1587
1841
  return this;
1588
1842
  };
1589
- l.fn.atomUnbind = function() {
1590
- for (let s = 0, t = this.length; s < t; s++)
1591
- Ue(this[s]);
1843
+ h.fn.atomUnbind = function() {
1844
+ for (let n = 0, t = this.length; n < t; n++) {
1845
+ const e = this[n];
1846
+ e.nodeType === 1 ? me(e) : k(e.nodeType);
1847
+ }
1592
1848
  return this;
1593
1849
  };
1594
- function Ms(s, t, e) {
1595
- t?.isConnected ? s.insertBefore(t) : s.appendTo(e);
1596
- }
1597
- l.fn.atomList = function(s, t) {
1598
- const { key: e, render: n, bind: i, update: o, onAdd: r, onRemove: c, empty: E } = t, d = typeof e == "function" ? e : (m, N) => m[e];
1599
- for (let m = 0, N = this.length; m < N; m++) {
1600
- const p = this[m], O = l(p), G = Xt(p), C = /* @__PURE__ */ new Map(), I = /* @__PURE__ */ new Set();
1601
- let R = [], Y = null;
1602
- const we = (L, D) => {
1603
- const z = () => {
1604
- bt?.isDisposed || (D.$el.remove(), I.delete(L), f.log("list", `${G} removed item:`, L));
1605
- };
1606
- if (!c) {
1607
- z();
1608
- return;
1609
- }
1610
- const $ = c(D.$el);
1611
- $ instanceof Promise ? $.then(z, z) : z();
1612
- }, Qt = (L, D) => {
1613
- C.delete(L), I.add(L), we(L, D);
1850
+ const Rt = /* @__PURE__ */ new WeakMap();
1851
+ let Rs = 0;
1852
+ function vs(n, t, e) {
1853
+ t?.isConnected ? n.insertBefore(t) : n.appendTo(e);
1854
+ }
1855
+ function Ds(n, t, e, s, i, o) {
1856
+ t.$el[0] && (n === void 0 ? o && o(t.$el, e, s) : i && i(t.$el, e, s));
1857
+ }
1858
+ class Os {
1859
+ constructor(t, e, s) {
1860
+ this.$container = t, this.containerSelector = e, this.onRemove = s, this.itemMap = /* @__PURE__ */ new Map(), this.removingKeys = /* @__PURE__ */ new Set(), this.oldKeys = [], this.$emptyEl = null, this.elToKey = /* @__PURE__ */ new WeakMap(), this.keyToIndex = /* @__PURE__ */ new Map();
1861
+ }
1862
+ scheduleRemoval(t, e) {
1863
+ const s = () => {
1864
+ this.fx?.isDisposed || (e.$el.remove(), this.removingKeys.delete(t), d.log(E.LIST, `${this.containerSelector} removed item:`, t));
1614
1865
  };
1615
- let bt;
1616
- bt = X(() => {
1617
- const L = s.value, D = L.length;
1618
- H(() => {
1619
- if (Y && D > 0 && (Y.remove(), Y = null), D === 0) {
1620
- if (E && !Y) {
1621
- const a = typeof E == "string" ? Ht(E) : E;
1622
- Y = l(a).appendTo(O);
1623
- }
1624
- for (let a = 0; a < R.length; a++) {
1625
- const h = R[a], _ = C.get(h);
1626
- _ && Qt(h, _);
1627
- }
1628
- R.length = 0;
1629
- return;
1630
- }
1631
- f.log("list", `${G} updating with ${D} items`);
1632
- const z = /* @__PURE__ */ new Map();
1633
- for (let a = 0; a < R.length; a++)
1634
- z.set(R[a], a);
1635
- const $ = new Array(D), Tt = /* @__PURE__ */ new Set(), ct = new Int32Array(D), at = [], Rt = [], Nt = [];
1636
- for (let a = 0; a < D; a++) {
1637
- const h = L[a], _ = d(h, a);
1638
- if ($[a] = _, Tt.has(_)) {
1639
- f.warn(g.LIST, T.DUPLICATE_KEY(_, a)), ct[a] = -1;
1640
- continue;
1641
- }
1642
- Tt.add(_);
1643
- const S = C.get(_);
1644
- if (S) {
1645
- const u = S.item;
1646
- !o && u !== h && !ps(u, h) && (at.push(_), Rt.push(h), Nt.push(a)), ct[a] = I.has(_) ? -1 : z.get(_) ?? -1;
1647
- } else
1648
- at.push(_), Rt.push(h), Nt.push(a), ct[a] = -1;
1649
- }
1650
- const lt = at.length, Yt = new Array(
1651
- lt
1652
- ), Ot = [];
1653
- for (let a = 0; a < lt; a++) {
1654
- const h = n(Rt[a], Nt[a]);
1655
- Yt[a] = h, typeof h == "string" && Ot.push(h);
1656
- }
1657
- let ht = null;
1658
- if (Ot.length > 0) {
1659
- const a = `<!--sep-${Math.random().toString(36).substring(2)}-${Date.now().toString(36)}-->`;
1660
- ht = Ht(Ot.join(a)).split(a);
1661
- }
1662
- let Kt = 0;
1663
- for (let a = 0; a < lt; a++) {
1664
- const h = Yt[a], _ = typeof h == "string" ? l(ht[Kt++]) : l(h), S = at[a], u = C.get(S);
1665
- if (u) {
1666
- const w = u.$el[0];
1667
- w && y.cleanupTree(w), u.$el.replaceWith(_), u.$el = _, u.state = "replaced";
1668
- } else
1669
- C.set(S, { $el: _, item: null, state: "new" });
1670
- }
1671
- for (let a = 0; a < R.length; a++) {
1672
- const h = R[a];
1673
- if (!Tt.has(h)) {
1674
- const _ = C.get(h);
1675
- _ && Qt(h, _);
1676
- }
1677
- }
1678
- const Wt = gs(ct);
1679
- let Dt = Wt.length - 1, Jt = null;
1680
- const vt = R.length === 0;
1681
- if (vt && ht !== null && Kt === lt && !i && !r && !c && I.size === 0) {
1682
- p.innerHTML = ht.join("");
1683
- let a = 0;
1684
- for (let h = 0; h < D; h++) {
1685
- const _ = $[h], S = L[h], u = C.get(_);
1686
- if (!u) continue;
1687
- const w = p.children[a++];
1688
- w && (u.$el = l(w), u.item = S, u.state = void 0, I.delete(_), f.domUpdated(u.$el, "list.add", S));
1689
- }
1690
- } else {
1691
- const a = vt ? document.createDocumentFragment() : null;
1692
- if (vt && a) {
1693
- for (let h = D - 1; h >= 0; h--) {
1694
- const _ = $[h], S = L[h], u = C.get(_);
1695
- if (!u) continue;
1696
- const w = u.state;
1697
- u.item = S, u.state = void 0, u.$el[0] && (w === void 0 ? o && o(u.$el, S, h) : i && i(u.$el, S, h));
1698
- for (let At = u.$el.length - 1; At >= 0; At--)
1699
- a.insertBefore(u.$el[At], a.firstChild);
1700
- w === "new" && (r && r(u.$el), I.delete(_), f.domUpdated(u.$el, "list.add", S));
1701
- }
1702
- p.appendChild(a);
1703
- } else
1704
- for (let h = D - 1; h >= 0; h--) {
1705
- const _ = $[h], S = L[h], u = C.get(_);
1706
- if (!u) continue;
1707
- const w = u.state;
1708
- u.item = S, u.state = void 0, u.$el[0] && (w === void 0 ? o && o(u.$el, S, h) : i && i(u.$el, S, h)), Dt >= 0 && Wt[Dt] === h ? Dt-- : Ms(u.$el, Jt, O), Jt = u.$el[0] ?? null, w === "new" && (r && r(u.$el), I.delete(_), f.domUpdated(u.$el, "list.add", S));
1709
- }
1710
- }
1711
- R = $;
1866
+ if (!this.onRemove) {
1867
+ s();
1868
+ return;
1869
+ }
1870
+ const i = this.onRemove(e.$el);
1871
+ i instanceof Promise ? i.then(s, s) : s();
1872
+ }
1873
+ removeItem(t, e) {
1874
+ for (let s = 0; s < e.$el.length; s++) {
1875
+ const i = e.$el[s];
1876
+ i && this.elToKey.delete(i);
1877
+ }
1878
+ this.itemMap.delete(t), this.removingKeys.add(t), this.scheduleRemoval(t, e);
1879
+ }
1880
+ dispose() {
1881
+ this.itemMap.clear(), this.removingKeys.clear(), this.oldKeys.length = 0, this.keyToIndex.clear(), this.$emptyEl?.remove(), this.$container.off(".atomList");
1882
+ }
1883
+ }
1884
+ function Ls(n, t, e, s) {
1885
+ if (n.$emptyEl && t > 0 && (n.$emptyEl.remove(), n.$emptyEl = null), t !== 0) return;
1886
+ if (s && !n.$emptyEl) {
1887
+ const r = typeof s == "string" ? pt(s) : s;
1888
+ n.$emptyEl = h(r).appendTo(e);
1889
+ }
1890
+ const { oldKeys: i, itemMap: o } = n;
1891
+ for (let r = 0, c = i.length; r < c; r++) {
1892
+ const a = i[r], l = o.get(a);
1893
+ l && n.removeItem(a, l);
1894
+ }
1895
+ i.length = 0;
1896
+ }
1897
+ function ks(n, t, e, s, i) {
1898
+ const { oldKeys: o, itemMap: r, removingKeys: c } = n, a = /* @__PURE__ */ new Map();
1899
+ for (let C = 0, T = o.length; C < T; C++)
1900
+ a.set(o[C], C);
1901
+ const l = new Array(e), u = /* @__PURE__ */ new Set(), _ = new Int32Array(e), y = [], p = [], v = [];
1902
+ for (let C = 0; C < e; C++) {
1903
+ const T = t[C], f = s(T, C);
1904
+ if (l[C] = f, u.has(f)) {
1905
+ d.warn(E.LIST, S.LIST.DUPLICATE_KEY(f, C, n.containerSelector)), _[C] = -1;
1906
+ continue;
1907
+ }
1908
+ u.add(f);
1909
+ const I = r.get(f);
1910
+ if (!I) {
1911
+ y.push(f), p.push(T), v.push(C), _[C] = -1;
1912
+ continue;
1913
+ }
1914
+ const m = I.item;
1915
+ !i && m !== T && !Ve(m, T) && (y.push(f), p.push(T), v.push(C)), _[C] = c.has(f) ? -1 : a.get(f) ?? -1;
1916
+ }
1917
+ return { newKeys: l, newKeySet: u, newIndices: _, trKeys: y, trItems: p, trIdxs: v };
1918
+ }
1919
+ function As(n, t, e, s) {
1920
+ const { trKeys: i, trItems: o, trIdxs: r } = t, c = i.length, a = n.itemMap, l = e.render, u = new Array(c), _ = [];
1921
+ let y = 0;
1922
+ for (let f = 0; f < c; f++) {
1923
+ const I = l(o[f], r[f]);
1924
+ u[f] = I, typeof I == "string" && (_.push(I), y++);
1925
+ }
1926
+ let p = null;
1927
+ const v = _.length;
1928
+ if (v === 1)
1929
+ p = [pt(_[0])];
1930
+ else if (v > 1) {
1931
+ const I = `<template data-atom-sep="${(Rs++).toString(36)}"></template>`;
1932
+ p = pt(_.join(I)).split(I);
1933
+ }
1934
+ if (s && p !== null && y === c && !e.bind && !e.onAdd && !e.onRemove && !e.events)
1935
+ return p;
1936
+ let T = 0;
1937
+ for (let f = 0; f < c; f++) {
1938
+ const I = u[f], m = typeof I == "string" ? h(p[T++]) : h(I), N = i[f], g = a.get(N);
1939
+ if (!g) {
1940
+ a.set(N, { $el: m, item: null, state: "new" });
1941
+ continue;
1942
+ }
1943
+ const D = g.$el[0];
1944
+ D && R.cleanupTree(D), g.$el.replaceWith(m), g.$el = m, g.state = "replaced";
1945
+ }
1946
+ return null;
1947
+ }
1948
+ function Us(n, t) {
1949
+ const { oldKeys: e, itemMap: s } = n;
1950
+ for (let i = 0, o = e.length; i < o; i++) {
1951
+ const r = e[i];
1952
+ if (t.has(r)) continue;
1953
+ const c = s.get(r);
1954
+ c && n.removeItem(r, c);
1955
+ }
1956
+ }
1957
+ function ws(n, t, e, s, i, o, r) {
1958
+ const { bind: c, update: a, onAdd: l } = o, { newKeys: u, newIndices: _ } = e, y = t.length, p = n.oldKeys.length === 0, v = ze(_);
1959
+ let C = v.length - 1;
1960
+ const { itemMap: T, removingKeys: f } = n;
1961
+ if (r !== null) {
1962
+ s.innerHTML = r.join("");
1963
+ let I = 0;
1964
+ for (let m = 0; m < y; m++) {
1965
+ const N = u[m], g = t[m], D = s.children[I++];
1966
+ if (D) {
1967
+ const U = h(D);
1968
+ T.set(N, { $el: U, item: g, state: void 0 }), f.delete(N), d.enabled && d.domUpdated(E.LIST, U, "list.add", g);
1969
+ }
1970
+ }
1971
+ return;
1972
+ }
1973
+ if (p) {
1974
+ const I = document.createDocumentFragment();
1975
+ for (let m = y - 1; m >= 0; m--) {
1976
+ const N = u[m], g = T.get(N);
1977
+ if (!g) continue;
1978
+ const D = g.$el;
1979
+ for (let U = D.length - 1; U >= 0; U--)
1980
+ I.insertBefore(D[U], I.firstChild);
1981
+ }
1982
+ s.appendChild(I);
1983
+ } else {
1984
+ let I = null;
1985
+ for (let m = y - 1; m >= 0; m--) {
1986
+ const N = u[m], g = T.get(N);
1987
+ g && (C >= 0 && v[C] === m ? C-- : vs(g.$el, I, i), I = g.$el[0] ?? null);
1988
+ }
1989
+ }
1990
+ for (let I = 0; I < y; I++) {
1991
+ const m = u[I], N = t[I], g = T.get(m);
1992
+ if (!g) continue;
1993
+ const D = g.state;
1994
+ g.item = N, g.state = void 0, Ds(D, g, N, I, c, a), D === "new" && (l && l(g.$el), f.delete(m), d.enabled && d.domUpdated(E.LIST, g.$el, "list.add", N));
1995
+ }
1996
+ }
1997
+ function xs(n, t) {
1998
+ const { newKeys: e, newKeySet: s } = t, i = e.length, { oldKeys: o, itemMap: r, elToKey: c, keyToIndex: a } = n;
1999
+ for (let l = 0, u = o.length; l < u; l++) {
2000
+ const _ = o[l];
2001
+ s.has(_) || a.delete(_);
2002
+ }
2003
+ for (let l = 0; l < i; l++) {
2004
+ const u = e[l], _ = r.get(u);
2005
+ if (_) {
2006
+ for (let y = 0; y < _.$el.length; y++) {
2007
+ const p = _.$el[y];
2008
+ p && c.set(p, u);
2009
+ }
2010
+ a.set(u, l);
2011
+ }
2012
+ }
2013
+ }
2014
+ h.fn.atomList = function(n, t) {
2015
+ const { key: e, bind: s, update: i, onAdd: o, onRemove: r, empty: c, events: a } = t, l = typeof e == "function" ? e : (_, y) => _[e], u = { bind: s, update: i, onAdd: o, onRemove: r, events: a };
2016
+ for (let _ = 0, y = this.length; _ < y; _++) {
2017
+ const p = this[_], v = h(p);
2018
+ v.off(".atomList");
2019
+ const C = Rt.get(p);
2020
+ C && (C.fx.dispose(), C.ctx.dispose());
2021
+ const T = X(p), f = new Os(v, T, r), I = V(() => {
2022
+ const m = n.value, N = m.length;
2023
+ P(() => {
2024
+ if (Ls(f, N, v, c), N === 0) return;
2025
+ d.log(E.LIST, `${T} updating with ${N} items`);
2026
+ const g = ks(f, m, N, l, i), D = f.oldKeys.length === 0, U = As(f, g, t, D);
2027
+ Us(f, g.newKeySet), ws(f, m, g, p, v, u, U), a && xs(f, g), f.oldKeys = g.newKeys;
1712
2028
  });
1713
- }), y.trackEffect(p, bt), y.trackCleanup(p, () => {
1714
- C.clear(), I.clear(), R.length = 0, Y?.remove();
2029
+ });
2030
+ if (f.fx = I, a)
2031
+ for (const m in a) {
2032
+ if (!Z.call(a, m)) continue;
2033
+ const N = a[m], g = m.indexOf(" "), D = g === -1 ? m : m.slice(0, g), U = g === -1 ? null : m.slice(g + 1).trim(), ge = U || "> *", Ie = function(ye) {
2034
+ let J = this;
2035
+ for (; J && J !== p; ) {
2036
+ const It = f.elToKey.get(J);
2037
+ if (It !== void 0) {
2038
+ const xt = f.itemMap.get(It);
2039
+ xt && N.call(this, xt.item, f.keyToIndex.get(It) ?? -1, ye);
2040
+ return;
2041
+ }
2042
+ J = J.parentElement;
2043
+ }
2044
+ };
2045
+ v.on(`${D}.atomList`, ge, Ie);
2046
+ }
2047
+ R.trackEffect(p, I), Rt.set(p, { fx: I, ctx: f }), R.trackCleanup(p, () => {
2048
+ f.dispose(), Rt.delete(p);
1715
2049
  });
1716
2050
  }
1717
2051
  return this;
1718
2052
  };
1719
- const Fs = Object.freeze({});
1720
- l.fn.atomMount = function(s, t) {
1721
- const e = t ?? Fs;
1722
- for (let n = 0, i = this.length; n < i; n++) {
1723
- const o = this[n];
2053
+ const $s = Object.freeze({});
2054
+ h.fn.atomMount = function(n, t) {
2055
+ const e = t ?? $s;
2056
+ for (let s = 0, i = this.length; s < i; s++) {
2057
+ const o = this[s];
1724
2058
  if (!o) continue;
1725
- y.cleanupTree(o);
1726
- const r = l(o);
2059
+ R.cleanupTree(o);
2060
+ const r = h(o);
1727
2061
  let c;
1728
2062
  try {
1729
- c = H(() => s(r, e));
1730
- } catch (E) {
1731
- f.error(g.MOUNT, T.MOUNT_ERROR(), E);
2063
+ c = P(() => n(r, e));
2064
+ } catch (a) {
2065
+ d.error(E.MOUNT, S.MOUNT.ERROR(n.name), a);
1732
2066
  continue;
1733
2067
  }
1734
- typeof c == "function" && y.setComponentCleanup(o, c);
2068
+ typeof c == "function" && R.setComponentCleanup(o, c);
1735
2069
  }
1736
2070
  return this;
1737
2071
  };
1738
- l.fn.atomUnmount = function() {
1739
- for (let s = 0, t = this.length; s < t; s++) {
1740
- const e = this[s];
1741
- e && Ue(e);
2072
+ h.fn.atomUnmount = function() {
2073
+ for (let n = 0, t = this.length; n < t; n++) {
2074
+ const e = this[n];
2075
+ e && me(e);
1742
2076
  }
1743
2077
  return this;
1744
2078
  };
1745
- function he(s, t) {
2079
+ function Yt(n, t) {
1746
2080
  try {
1747
- return history.pushState(s, "", t), !0;
2081
+ return history.pushState(n, "", t), !0;
1748
2082
  } catch (e) {
1749
- return f.warn(
1750
- g.ROUTE,
2083
+ return d.warn(
2084
+ E.ROUTE,
1751
2085
  "PushState failed (likely file:// protocol or security restriction). UI will update, but URL will not.",
1752
2086
  e
1753
2087
  ), !1;
1754
2088
  }
1755
2089
  }
1756
- class Bs {
2090
+ class Ps {
1757
2091
  constructor(t) {
1758
2092
  this.isDestroyed = !1, this.previousRoute = "", this.cleanups = [], this.templateCache = /* @__PURE__ */ new Map(), this.config = {
1759
2093
  ...t,
1760
- mode: t.mode ?? _t.mode,
1761
- basePath: t.basePath ?? _t.basePath,
1762
- autoBindLinks: t.autoBindLinks ?? _t.autoBindLinks,
1763
- activeClass: t.activeClass ?? _t.activeClass
1764
- }, this.isHistoryMode = this.config.mode === "history", this.$target = l(this.config.target), this.normalizedBasePath = this.config.basePath?.replace(/\/$/, "") || "", this.previousUrl = this.isHistoryMode ? window.location.pathname + window.location.search : window.location.hash, this.currentRouteAtom = Bt(this.getRouteName()), this.currentRoute = this.currentRouteAtom, this.queryParamsAtom = Bt(this.getQueryParams()), this.queryParams = St(() => this.queryParamsAtom.value), this.handleUrlChange = this.handleUrlChange.bind(this), this.destroy = this.destroy.bind(this), this.init();
2094
+ mode: t.mode ?? et.mode,
2095
+ basePath: t.basePath ?? et.basePath,
2096
+ autoBindLinks: t.autoBindLinks ?? et.autoBindLinks,
2097
+ activeClass: t.activeClass ?? et.activeClass
2098
+ }, this.isHistoryMode = this.config.mode === "history", this.$target = h(this.config.target), this.normalizedBasePath = this.config.basePath?.replace(/\/$/, "") || "", this.activeClass = this.config.activeClass ?? et.activeClass, this.previousUrl = this.isHistoryMode ? window.location.pathname + window.location.search : window.location.hash, this.currentRouteAtom = Dt(this.getRouteName()), this.currentRoute = this.currentRouteAtom, this.queryParamsAtom = Dt(this.getQueryParams()), this.queryParams = gt(() => this.queryParamsAtom.value), this.handleUrlChange = this.handleUrlChange.bind(this), this.destroy = this.destroy.bind(this), this.init();
1765
2099
  }
1766
2100
  init() {
1767
2101
  const t = this.isHistoryMode ? "popstate" : "hashchange";
1768
2102
  window.addEventListener(t, this.handleUrlChange), this.cleanups.push(() => window.removeEventListener(t, this.handleUrlChange));
1769
- const e = X(() => {
1770
- const n = this.currentRouteAtom.value;
1771
- H(() => this.renderRoute(n));
2103
+ const e = V(() => {
2104
+ const s = this.currentRouteAtom.value;
2105
+ P(() => this.renderRoute(s));
1772
2106
  });
1773
- this.cleanups.push(() => e.dispose()), this.setupAutoBindLinks(), this.$target[0] && y.trackCleanup(this.$target[0], this.destroy);
2107
+ this.cleanups.push(() => e.dispose()), this.setupAutoBindLinks(), this.$target[0] && R.trackCleanup(this.$target[0], this.destroy);
1774
2108
  }
1775
2109
  // --- Mode-abstracted internal methods ---
1776
2110
  /**
@@ -1783,8 +2117,8 @@ class Bs {
1783
2117
  let o = window.location.pathname;
1784
2118
  return this.normalizedBasePath && o.startsWith(this.normalizedBasePath) && (o = o.substring(this.normalizedBasePath.length)), o.charCodeAt(0) === 47 && (o = o.slice(1)), o || t;
1785
2119
  }
1786
- const e = window.location.hash, n = e.indexOf("?");
1787
- return (n === -1 ? e.substring(1) : e.substring(1, n)) || t;
2120
+ const e = window.location.hash, s = e.indexOf("?");
2121
+ return (s === -1 ? e.substring(1) : e.substring(1, s)) || t;
1788
2122
  }
1789
2123
  /**
1790
2124
  * Parses query parameters from the current URL.
@@ -1793,6 +2127,12 @@ class Bs {
1793
2127
  * only (`{ a: '2' }`). This matches `URLSearchParams` → `Object.fromEntries`
1794
2128
  * behaviour. If multi-value keys are needed, access `queryParams` via
1795
2129
  * `new URLSearchParams(window.location.search).getAll('key')` directly.
2130
+ *
2131
+ * Malformed percent-encoding (e.g. `%FF%FE`) is handled silently by
2132
+ * `URLSearchParams` — it replaces undecodable sequences with the replacement
2133
+ * character (U+FFFD) and continues parsing. If malformed encoding is detected,
2134
+ * a warning is emitted via `debug.warn`, but the best-effort parsed result
2135
+ * is still returned.
1796
2136
  */
1797
2137
  getQueryParams() {
1798
2138
  let t;
@@ -1803,14 +2143,14 @@ class Bs {
1803
2143
  if (o === -1) return {};
1804
2144
  t = i.substring(o + 1);
1805
2145
  }
1806
- const e = new URLSearchParams(t), n = Object.fromEntries(e);
2146
+ const e = new URLSearchParams(t), s = Object.fromEntries(e);
1807
2147
  if (t.includes("%"))
1808
2148
  try {
1809
2149
  decodeURIComponent(t);
1810
2150
  } catch {
1811
- f.warn(g.ROUTE, T.MALFORMED_URI(t));
2151
+ d.warn(E.ROUTE, S.ROUTE.MALFORMED_URI(t));
1812
2152
  }
1813
- return n;
2153
+ return s;
1814
2154
  }
1815
2155
  /**
1816
2156
  * Updates the browser URL to reflect a new route and keeps `previousUrl`
@@ -1819,7 +2159,7 @@ class Bs {
1819
2159
  setUrl(t) {
1820
2160
  if (this.isHistoryMode) {
1821
2161
  const e = `${this.normalizedBasePath}/${t}`;
1822
- he(null, e), this.previousUrl = e;
2162
+ Yt(null, e), this.previousUrl = e;
1823
2163
  } else {
1824
2164
  const e = `#${t}`;
1825
2165
  window.location.hash = e, this.previousUrl = e;
@@ -1831,7 +2171,7 @@ class Bs {
1831
2171
  * that occur with replaceState during popstate events.
1832
2172
  */
1833
2173
  restoreUrl() {
1834
- this.isHistoryMode ? he(null, this.previousUrl) : window.location.hash = this.previousUrl;
2174
+ this.isHistoryMode ? Yt(null, this.previousUrl) : window.location.hash = this.previousUrl;
1835
2175
  }
1836
2176
  /**
1837
2177
  * Returns the current full URL string for comparison purposes.
@@ -1844,9 +2184,9 @@ class Bs {
1844
2184
  * Resolves route configuration, falling back to notFound route if needed.
1845
2185
  */
1846
2186
  getRouteConfig(t) {
1847
- const { routes: e, notFound: n } = this.config;
2187
+ const { routes: e, notFound: s } = this.config;
1848
2188
  let i = e[t];
1849
- return !i && n && (i = e[n]), i || (f.warn(g.ROUTE, T.ROUTE_NOT_FOUND(t)), null);
2189
+ return !i && s && (i = e[s]), i || (d.warn(E.ROUTE, S.ROUTE.NOT_FOUND(t)), null);
1850
2190
  }
1851
2191
  /**
1852
2192
  * Appends cloned template content into the target container.
@@ -1858,11 +2198,11 @@ class Bs {
1858
2198
  if (!e) {
1859
2199
  const i = document.querySelector(t);
1860
2200
  if (!i || !(i instanceof HTMLTemplateElement))
1861
- return f.warn(g.ROUTE, T.TEMPLATE_NOT_FOUND(t)), !1;
2201
+ return d.warn(E.ROUTE, S.ROUTE.TEMPLATE_NOT_FOUND(t)), !1;
1862
2202
  e = i, this.templateCache.set(t, e);
1863
2203
  }
1864
- const n = e.content.cloneNode(!0);
1865
- return this.$target.append(n), !0;
2204
+ const s = e.content.cloneNode(!0);
2205
+ return this.$target.append(s), !0;
1866
2206
  }
1867
2207
  /**
1868
2208
  * Renders the specified route, including lifecycle hooks and content.
@@ -1873,27 +2213,33 @@ class Bs {
1873
2213
  * outgoing content are disposed before the nodes are removed — preventing
1874
2214
  * the MutationObserver auto-cleanup path from firing a redundant cleanup.
1875
2215
  *
1876
- * If `beforeTransition` throws, the render is aborted and the outgoing
1877
- * content remains in the DOM. This is intentional — a throwing hook signals
1878
- * that the transition should not proceed.
2216
+ * EXCEPTION BEHAVIOUR:
2217
+ * - `beforeTransition` throws render aborted, outgoing DOM intact,
2218
+ * `previousRoute` unchanged. Intentional: a throwing hook signals that
2219
+ * the transition should not proceed.
2220
+ * - `onEnter` throws → container is already empty (`$target.empty()` ran),
2221
+ * rendering is skipped, and `previousRoute` is NOT updated. The router
2222
+ * is left in an empty-container / stale-previousRoute state. This behavior
2223
+ * is by design to prevent unintended state changes if the `onEnter` hook fails.
2224
+ * If recovery is needed, the hook should catch its own errors internally.
1879
2225
  */
1880
2226
  renderRoute(t) {
1881
2227
  if (this.isDestroyed) return;
1882
2228
  const e = this.$target[0];
1883
2229
  if (!e) {
1884
- f.warn(g.ROUTE, T.TARGET_NOT_FOUND(this.config.target));
2230
+ d.warn(E.ROUTE, S.ROUTE.TARGET_NOT_FOUND(this.config.target));
1885
2231
  return;
1886
2232
  }
1887
- const n = this.getRouteConfig(t);
1888
- if (!n) return;
2233
+ const s = this.getRouteConfig(t);
2234
+ if (!s) return;
1889
2235
  const i = this.getQueryParams(), o = this.previousRoute;
1890
2236
  this.config.beforeTransition && this.config.beforeTransition(o, t), this.$target.empty();
1891
2237
  let r = i;
1892
- if (n.onEnter) {
1893
- const c = n.onEnter(i);
2238
+ if (s.onEnter) {
2239
+ const c = s.onEnter(i);
1894
2240
  c !== void 0 && (r = { ...i, ...c });
1895
2241
  }
1896
- n.render ? n.render(e, t, r) : n.template && this.renderTemplate(n.template) && n.onMount && n.onMount(this.$target.children()), this.config.afterTransition && this.config.afterTransition(o, t), this.previousRoute = t;
2242
+ s.render ? s.render(e, t, r) : s.template && this.renderTemplate(s.template) && s.onMount && s.onMount(this.$target.children()), this.config.afterTransition && this.config.afterTransition(o, t), this.previousRoute = t;
1897
2243
  }
1898
2244
  /**
1899
2245
  * Handles browser URL change events (hashchange or popstate).
@@ -1902,9 +2248,9 @@ class Bs {
1902
2248
  if (this.isDestroyed) return;
1903
2249
  const t = this.getCurrentUrl();
1904
2250
  if (t === this.previousUrl) return;
1905
- const e = this.getRouteName(), n = this.currentRouteAtom.peek(), i = this.getQueryParams();
1906
- if (n !== e) {
1907
- const o = this.config.routes[n];
2251
+ const e = this.getRouteName(), s = this.currentRouteAtom.peek(), i = this.getQueryParams();
2252
+ if (s !== e) {
2253
+ const o = this.config.routes[s];
1908
2254
  if (o?.onLeave && o.onLeave() === !1) {
1909
2255
  this.restoreUrl();
1910
2256
  return;
@@ -1912,7 +2258,7 @@ class Bs {
1912
2258
  this.currentRouteAtom.value = e, this.queryParamsAtom.value = i;
1913
2259
  } else {
1914
2260
  this.queryParamsAtom.value = i;
1915
- const o = this.config.routes[n];
2261
+ const o = this.config.routes[s];
1916
2262
  o?.onParamsChange ? o.onParamsChange(i) : this.renderRoute(e);
1917
2263
  }
1918
2264
  this.previousUrl = t;
@@ -1935,20 +2281,20 @@ class Bs {
1935
2281
  const o = i.currentTarget.dataset.route;
1936
2282
  o != null && this.navigate(o);
1937
2283
  };
1938
- l(document).on("click", "[data-route]", t), this.cleanups.push(() => {
1939
- l(document).off("click", "[data-route]", t);
2284
+ h(document).on("click", "[data-route]", t), this.cleanups.push(() => {
2285
+ h(document).off("click", "[data-route]", t);
1940
2286
  });
1941
- const { activeClass: e } = this.config, n = X(() => {
2287
+ const e = this.activeClass, s = V(() => {
1942
2288
  const i = this.currentRouteAtom.value;
1943
- H(() => {
2289
+ P(() => {
1944
2290
  const o = document.querySelectorAll("[data-route]");
1945
2291
  for (let r = 0, c = o.length; r < c; r++) {
1946
- const E = o[r], d = E.dataset.route, m = i === d;
1947
- E.classList.toggle(e, m), m ? E.setAttribute("aria-current", "page") : E.removeAttribute("aria-current");
2292
+ const a = o[r], l = a.dataset.route, u = i === l;
2293
+ a.classList.toggle(e, u), u ? a.setAttribute("aria-current", "page") : a.removeAttribute("aria-current");
1948
2294
  }
1949
2295
  });
1950
2296
  });
1951
- this.cleanups.push(() => n.dispose());
2297
+ this.cleanups.push(() => s.dispose());
1952
2298
  }
1953
2299
  /**
1954
2300
  * Navigates to the specified route programmatically.
@@ -1960,13 +2306,13 @@ class Bs {
1960
2306
  */
1961
2307
  navigate(t) {
1962
2308
  if (this.isDestroyed) return;
1963
- const e = this.currentRouteAtom.peek(), n = this.config.routes[e];
1964
- if (n?.onLeave && n.onLeave() === !1)
2309
+ const e = this.currentRouteAtom.peek(), s = this.config.routes[e];
2310
+ if (s?.onLeave && s.onLeave() === !1)
1965
2311
  return;
1966
2312
  const i = t || this.config.default;
1967
2313
  if (!i) {
1968
- f.warn(
1969
- g.ROUTE,
2314
+ d.warn(
2315
+ E.ROUTE,
1970
2316
  "navigate() called with empty routeName and no default configured."
1971
2317
  );
1972
2318
  return;
@@ -1982,72 +2328,104 @@ class Bs {
1982
2328
  if (this.isDestroyed) return;
1983
2329
  this.isDestroyed = !0;
1984
2330
  const t = this.cleanups;
1985
- for (let e = 0, n = t.length; e < n; e++)
2331
+ this.cleanups = [];
2332
+ for (let e = 0, s = t.length; e < s; e++)
1986
2333
  try {
1987
2334
  t[e]();
1988
2335
  } catch (i) {
1989
- f.warn(g.ROUTE, "Cleanup error during destroy:", i);
2336
+ d.warn(E.ROUTE, "Cleanup error during destroy:", i);
1990
2337
  }
1991
- this.cleanups.length = 0, this.templateCache.clear();
2338
+ this.templateCache.clear();
1992
2339
  }
1993
2340
  }
1994
- function Hs(s) {
1995
- return new Bs(s);
2341
+ function Ms(n) {
2342
+ return new Ps(n);
1996
2343
  }
1997
- l.extend({
1998
- route: Hs
1999
- });
2000
- const Gs = new Promise(() => {
2344
+ h.extend({
2345
+ route: Ms
2001
2346
  });
2002
- l.extend({
2003
- atomFetch(s, t) {
2004
- const { defaultValue: e, transform: n, method: i, headers: o, ajaxOptions: r, onError: c, eager: E } = t, d = typeof s == "string", m = d ? s : void 0, N = d ? null : s, p = Object.assign({}, r);
2005
- i !== void 0 && (p.method = i), o !== void 0 && (p.headers = o), d && (p.url = m);
2006
- let O = null;
2007
- return St(
2008
- async () => {
2009
- O?.abort(), O = new AbortController();
2010
- const C = O.signal;
2011
- d || (p.url = N());
2012
- const I = l.ajax(p);
2013
- C.onabort = () => I.abort(), C.aborted && I.abort();
2347
+ class Fs {
2348
+ constructor(t, e) {
2349
+ this.abortController = null, this.isStaticUrl = typeof t == "string", this.isStaticUrl ? this.staticUrl = t : this.getUrl = t, typeof e.ajaxOptions == "function" ? (this.ajaxOptionsFn = e.ajaxOptions, this.staticOptions = {}) : this.staticOptions = { ...e.ajaxOptions }, e.method !== void 0 && (this.staticOptions.method = e.method), e.headers !== void 0 && (this.staticOptions.headers = { ...this.staticOptions.headers, ...e.headers }), this.transformFn = e.transform, this.onErrorFn = e.onError, this.execute = this.execute.bind(this);
2350
+ }
2351
+ abort() {
2352
+ this.abortController?.abort();
2353
+ }
2354
+ async execute() {
2355
+ this.abortController?.abort(), this.abortController = new AbortController();
2356
+ const t = this.abortController.signal, e = this.ajaxOptionsFn ? this.ajaxOptionsFn() : {}, s = h.extend(!0, {}, this.staticOptions, e);
2357
+ s.success = void 0, s.error = void 0, s.complete = void 0, s.url = this.isStaticUrl ? this.staticUrl : this.getUrl();
2358
+ const i = h.ajax(s);
2359
+ t.onabort = () => i.abort(), t.aborted && i.abort();
2360
+ let o;
2361
+ try {
2362
+ o = await i;
2363
+ } catch (c) {
2364
+ if (t.aborted) {
2365
+ const u = new Error("AbortError");
2366
+ throw u.name = "AbortError", u;
2367
+ }
2368
+ let a;
2369
+ if (c && typeof c.readyState < "u") {
2370
+ const u = c;
2371
+ a = new Error(`Network Error: ${u.statusText || "Unknown"} (${u.status})`), a.jqXHR = u;
2372
+ } else
2373
+ a = c instanceof Error ? c : new Error(String(c ?? "Unknown network error"));
2374
+ const l = this.onErrorFn;
2375
+ if (l)
2014
2376
  try {
2015
- const R = await I;
2016
- return n ? n(R) : R;
2017
- } catch (R) {
2018
- if (C.aborted)
2019
- return Gs;
2377
+ l(a);
2378
+ } catch {
2379
+ }
2380
+ throw a;
2381
+ } finally {
2382
+ t.onabort = null, this.abortController?.signal === t && (this.abortController = null);
2383
+ }
2384
+ const r = this.transformFn;
2385
+ if (r)
2386
+ try {
2387
+ return r(o);
2388
+ } catch (c) {
2389
+ const a = this.onErrorFn;
2390
+ if (a)
2020
2391
  try {
2021
- c?.(R);
2392
+ a(c);
2022
2393
  } catch {
2023
2394
  }
2024
- throw R;
2025
- } finally {
2026
- C.onabort = null, O.signal === C && (O = null);
2027
- }
2028
- },
2029
- { defaultValue: e, lazy: !(E ?? !0) }
2030
- );
2395
+ throw c;
2396
+ }
2397
+ return o;
2398
+ }
2399
+ }
2400
+ h.extend({
2401
+ atomFetch(n, t) {
2402
+ const e = new Fs(n, t), s = !(t.eager ?? !0), i = gt(e.execute, {
2403
+ defaultValue: t.defaultValue,
2404
+ lazy: s
2405
+ });
2406
+ return Object.assign(i, {
2407
+ abort: () => e.abort()
2408
+ });
2031
2409
  }
2032
2410
  });
2033
- l(() => {
2034
- As(), Os(document.body);
2411
+ h(() => {
2412
+ ns(), ts(document.body);
2035
2413
  });
2036
2414
  export {
2037
- Bt as atom,
2038
- Ie as batch,
2039
- St as computed,
2040
- Ys as default,
2041
- Vs as disableAutoCleanup,
2042
- qs as disablejQueryOverrides,
2043
- X as effect,
2044
- Os as enableAutoCleanup,
2045
- As as enablejQueryOverrides,
2046
- qt as isAtom,
2047
- qe as isComputed,
2048
- ye as isReactive,
2049
- Ts as nextTick,
2050
- y as registry,
2051
- H as untracked
2415
+ Dt as atom,
2416
+ ne as batch,
2417
+ gt as computed,
2418
+ zs as default,
2419
+ Gs as disableAutoCleanup,
2420
+ Hs as disablejQueryOverrides,
2421
+ V as effect,
2422
+ ts as enableAutoCleanup,
2423
+ ns as enablejQueryOverrides,
2424
+ wt as isAtom,
2425
+ xe as isComputed,
2426
+ oe as isReactive,
2427
+ We as nextTick,
2428
+ R as registry,
2429
+ P as untracked
2052
2430
  };
2053
2431
  //# sourceMappingURL=index.mjs.map