@but212/atom-effect-jquery 0.23.0 → 0.24.1

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