@but212/atom-effect-jquery 0.21.2 → 0.22.0

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