@but212/atom-effect-jquery 0.21.3 → 0.22.1

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