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