@but212/atom-effect-jquery 0.29.0 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,60 +1,120 @@
1
1
  import e from "jquery";
2
2
  //#region ../core/dist/index.mjs
3
3
  var t = {
4
+ DISPOSED: 1,
5
+ IS_COMPUTED: 2,
6
+ DIRTY: 256,
7
+ RECOMPUTING: 512,
8
+ HAS_ERROR: 1024,
9
+ FORCE_COMPUTE: 2048,
10
+ IDLE: 65536,
11
+ PENDING: 131072,
12
+ RESOLVED: 262144,
13
+ REJECTED: 524288,
14
+ ATOM_SYNC: 16777216,
15
+ ATOM_NOTIFICATION_SCHEDULED: 33554432,
16
+ EFFECT_EXECUTING: 268435456
17
+ };
18
+ Object.freeze({
19
+ ASYNC_STATE: t.IDLE | t.PENDING | t.RESOLVED | t.REJECTED,
20
+ COMPUTED_DIRTY_MASK: t.DIRTY | t.RECOMPUTING | t.FORCE_COMPUTE
21
+ });
22
+ var n = Object.freeze({
4
23
  IDLE: "idle",
5
24
  PENDING: "pending",
6
25
  RESOLVED: "resolved",
7
26
  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
+ }), r = Object.freeze({
28
+ DISPOSED: t.DISPOSED,
29
+ EXECUTING: t.EFFECT_EXECUTING
30
+ }), i = Object.freeze({
31
+ DISPOSED: t.DISPOSED,
32
+ IS_COMPUTED: t.IS_COMPUTED,
33
+ DIRTY: t.DIRTY,
34
+ IDLE: t.IDLE,
35
+ PENDING: t.PENDING,
36
+ RESOLVED: t.RESOLVED,
37
+ REJECTED: t.REJECTED,
38
+ RECOMPUTING: t.RECOMPUTING,
39
+ HAS_ERROR: t.HAS_ERROR,
40
+ FORCE_COMPUTE: t.FORCE_COMPUTE
41
+ }), a = Object.freeze({
42
+ DISPOSED: t.DISPOSED,
43
+ SYNC: t.ATOM_SYNC,
44
+ NOTIFICATION_SCHEDULED: t.ATOM_NOTIFICATION_SCHEDULED
45
+ }), o = Object.freeze({
27
46
  MAX_EXECUTIONS_PER_SECOND: 1e3,
28
47
  MAX_EXECUTIONS_PER_EFFECT: 100,
29
48
  MAX_EXECUTIONS_PER_FLUSH: 1e4,
30
49
  MAX_FLUSH_ITERATIONS: 1e3,
31
50
  MIN_FLUSH_ITERATIONS: 10,
32
51
  BATCH_QUEUE_SHRINK_THRESHOLD: 1e3
33
- }, o = {
52
+ }), s = 1073741823, c = Object.freeze({
34
53
  WARN_INFINITE_LOOP: !0,
35
- EFFECT_FREQUENCY_WINDOW: 1e3
36
- }, s = { MAX_PROMISE_ID: 2 ** 53 - 1 - 1 }, c = {
54
+ EFFECT_FREQUENCY_WINDOW: 1e3,
55
+ LOOP_THRESHOLD: 100
56
+ }), l = Object.freeze({ MAX_PROMISE_ID: s }), u = Object.freeze({
37
57
  UNINITIALIZED: -1,
38
58
  MIN: 1
39
- }, l = 1073741823;
40
- typeof process < "u" && process.env;
41
- var u = Object.freeze([]), d = class extends Error {
42
- constructor(e, t = null, n = !0) {
43
- super(e), this.cause = t, this.recoverable = n, this.name = "AtomError";
59
+ }), d = !1;
60
+ try {
61
+ d = !!(typeof globalThis < "u" && globalThis.__ATOM_DEBUG__ || typeof sessionStorage < "u" && sessionStorage.getItem("__ATOM_DEBUG__") === "true");
62
+ } catch {}
63
+ var f = (typeof process < "u" && process.env, typeof __DEV__ < "u" && !!__DEV__ || d), p = Object.freeze([]), m = class e extends Error {
64
+ constructor(e, t = null, n = !0, r) {
65
+ super(e), this.cause = t, this.recoverable = n, this.code = r, this.name = "AtomError", Error.captureStackTrace && Error.captureStackTrace(this, this.constructor);
66
+ }
67
+ getChain() {
68
+ if (this.cause === null || this.cause === void 0) return [this];
69
+ let t = [this], n = /* @__PURE__ */ new Set([this]), r = this.cause;
70
+ for (; r != null;) {
71
+ let i = n.has(r);
72
+ if (t.push(r), i) break;
73
+ if (n.add(r), r instanceof e) r = r.cause;
74
+ else if (r instanceof Error && "cause" in r) r = r.cause;
75
+ else break;
76
+ }
77
+ return t;
78
+ }
79
+ toJSON(t = /* @__PURE__ */ new Set()) {
80
+ if (t.has(this)) return {
81
+ name: this.name,
82
+ message: "[Circular Reference]",
83
+ recoverable: this.recoverable,
84
+ code: this.code
85
+ };
86
+ t.add(this);
87
+ let n = this.cause;
88
+ return this.cause instanceof e ? n = this.cause.toJSON(t) : this.cause instanceof Error && (n = {
89
+ name: this.cause.name,
90
+ message: this.cause.message,
91
+ stack: this.cause.stack,
92
+ cause: this.cause.cause
93
+ }), {
94
+ name: this.name,
95
+ message: this.message,
96
+ code: this.code,
97
+ recoverable: this.recoverable,
98
+ stack: this.stack,
99
+ cause: n
100
+ };
101
+ }
102
+ static format(e, t, n) {
103
+ return `${e} (${t}): ${n}`;
44
104
  }
45
- }, f = class extends d {
46
- constructor(e, t = null) {
47
- super(e, t, !0), this.name = "ComputedError";
105
+ }, h = class extends m {
106
+ constructor(...e) {
107
+ super(...e), this.name = "ComputedError";
48
108
  }
49
- }, p = class extends d {
50
- constructor(e, t = null) {
51
- super(e, t, !1), this.name = "EffectError";
109
+ }, g = class extends m {
110
+ constructor(e, t = null, n = !1, r) {
111
+ super(e, t, n, r), this.name = "EffectError";
52
112
  }
53
- }, m = class extends d {
54
- constructor(e, t = null) {
55
- super(e, t, !1), this.name = "SchedulerError";
113
+ }, _ = class extends m {
114
+ constructor(e, t = null, n = !1, r) {
115
+ super(e, t, n, r), this.name = "SchedulerError";
56
116
  }
57
- }, h = {
117
+ }, v = {
58
118
  COMPUTED_MUST_BE_FUNCTION: "Computed target must be a function",
59
119
  COMPUTED_ASYNC_PENDING_NO_DEFAULT: "Async computation pending with no default value",
60
120
  COMPUTED_COMPUTATION_FAILED: "Computation execution failed",
@@ -74,198 +134,185 @@ var u = Object.freeze([]), d = class extends Error {
74
134
  SCHEDULER_END_BATCH_WITHOUT_START: "endBatch() called without matching startBatch(). Ignoring.",
75
135
  BATCH_CALLBACK_MUST_BE_FUNCTION: "Batch callback must be a function"
76
136
  };
77
- function g(e, t, n) {
78
- return e instanceof d ? e : e instanceof Error ? new t(`${e.name || e.constructor.name || "Error"} (${n}): ${e.message}`, e) : new t(`Unexpected error (${n}): ${String(e)}`);
137
+ function y(e, t, n) {
138
+ if (e instanceof m) return new t(m.format(e.name, n, e.message), e, e.recoverable, e.code);
139
+ if (e instanceof Error) {
140
+ let r = e.name || e.constructor.name || "Error";
141
+ return new t(m.format(r, n, e.message), e);
142
+ }
143
+ return new t(m.format("Unexpected error", n, String(e)), e);
79
144
  }
80
- var ee = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), _ = /* @__PURE__ */ Symbol("AtomEffect.Type"), v = /* @__PURE__ */ Symbol("AtomEffect.NoDefaultValue"), y = new class {
145
+ var b = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), x = /* @__PURE__ */ Symbol("AtomEffect.Id"), S = /* @__PURE__ */ Symbol("AtomEffect.Type"), C = /* @__PURE__ */ Symbol("AtomEffect.NoDefaultValue"), w = "[Atom Effect]", T = f ? new class {
81
146
  constructor() {
82
- this.enabled = !1, this.warnInfiniteLoop = o.WARN_INFINITE_LOOP;
147
+ this.enabled = !0, this.warnInfiniteLoop = c.WARN_INFINITE_LOOP, this._updateCounts = /* @__PURE__ */ new Map(), this._nodeRegistry = /* @__PURE__ */ new Map(), this._threshold = c.LOOP_THRESHOLD, this._cleanupScheduled = !1, this.warn = (e, t) => {
148
+ this.enabled && e && console.warn(`${w} ${t}`);
149
+ }, this.registerNode = (e) => {
150
+ this._nodeRegistry.set(e.id, new WeakRef(e));
151
+ }, this.attachDebugInfo = (e, t, n, r) => {
152
+ this.enabled && (Object.defineProperties(e, {
153
+ [b]: {
154
+ value: r ?? `${t}_${n}`,
155
+ configurable: !0
156
+ },
157
+ [x]: {
158
+ value: n,
159
+ configurable: !0
160
+ },
161
+ [S]: {
162
+ value: t,
163
+ configurable: !0
164
+ }
165
+ }), this.registerNode(e));
166
+ }, this.trackUpdate = (e, t) => {
167
+ if (!this.enabled || !this.warnInfiniteLoop) return;
168
+ let n = this._updateCounts, r = (n.get(e) ?? 0) + 1;
169
+ r > this._threshold ? this.warn(!0, `Infinite loop detected for ${t ?? `dependency ${e}`}. Over ${this._threshold} updates in a single execution scope.`) : n.set(e, r), this._cleanupScheduled || (this._cleanupScheduled = !0, Promise.resolve().then(() => {
170
+ this._updateCounts.clear(), this._cleanupScheduled = !1;
171
+ }));
172
+ }, this.dumpGraph = () => {
173
+ let e = [];
174
+ for (let [t, n] of this._nodeRegistry) {
175
+ let r = n.deref();
176
+ r ? e.push({
177
+ id: t,
178
+ name: this.getDebugName(r),
179
+ type: this.getDebugType(r),
180
+ updateCount: this._updateCounts.get(t) ?? 0
181
+ }) : (this._nodeRegistry.delete(t), this._updateCounts.delete(t));
182
+ }
183
+ return e;
184
+ }, this.getDebugName = (e) => {
185
+ if (e) return e[b];
186
+ }, this.getDebugType = (e) => {
187
+ if (e) return e[S];
188
+ };
83
189
  }
84
- warn(e, t) {}
85
- attachDebugInfo(e, t, n) {}
86
- getDebugName(e) {
87
- if (e != null) return e[ee];
190
+ }() : {
191
+ enabled: !1,
192
+ warnInfiniteLoop: !1,
193
+ warn: () => {},
194
+ registerNode: () => {},
195
+ attachDebugInfo: () => {},
196
+ trackUpdate: () => {},
197
+ dumpGraph: () => [],
198
+ getDebugName: () => {},
199
+ getDebugType: () => {}
200
+ }, ee = 1, te = () => ee++ | 0, ne = class {
201
+ constructor() {
202
+ this._s0 = null, this._s1 = null, this._s2 = null, this._s3 = null, this._count = 0, this._actualCount = 0, this._overflow = null, this._freeIndices = null;
88
203
  }
89
- getDebugType(e) {
90
- if (e != null) return e[_];
204
+ _rawWrite(e, t) {
205
+ if (e < 4) e === 0 ? this._s0 = t : e === 1 ? this._s1 = t : e === 2 ? this._s2 = t : this._s3 = t;
206
+ else {
207
+ this._overflow === null && (this._overflow = []);
208
+ let n = this._overflow, r = e - 4;
209
+ n[r] = t;
210
+ }
91
211
  }
92
- }(), b = 1, x = () => b++ | 0, S = class {
93
- constructor() {
94
- this._s0 = null, this._s1 = null, this._s2 = null, this._s3 = null, this._count = 0, this._overflow = null, this._freeIndices = null;
212
+ _rawAdd(e) {
213
+ if (this._s0 === null) return this._s0 = e, 0;
214
+ if (this._s1 === null) return this._s1 = e, 1;
215
+ if (this._s2 === null) return this._s2 = e, 2;
216
+ if (this._s3 === null) return this._s3 = e, 3;
217
+ this._overflow === null && (this._overflow = []);
218
+ let t = this._overflow, n = this._freeIndices;
219
+ if (n !== null && n.length > 0) {
220
+ let r = n.pop();
221
+ return t[r] = e, r + 4;
222
+ }
223
+ return t.push(e), 4 + t.length - 1;
224
+ }
225
+ _rawSwap(e, t) {
226
+ if (e === t) return;
227
+ let n = this.getAt(e), r = this.getAt(t);
228
+ this._rawWrite(e, r), this._rawWrite(t, n);
95
229
  }
96
230
  get size() {
231
+ return this._actualCount;
232
+ }
233
+ get physicalSize() {
97
234
  return this._count;
98
235
  }
99
236
  getAt(e) {
100
- if (e < 4) switch (e) {
101
- case 0: return this._s0;
102
- case 1: return this._s1;
103
- case 2: return this._s2;
104
- case 3: return this._s3;
105
- }
106
- let t = this._overflow;
107
- if (t !== null) {
108
- let n = t[e - 4];
109
- return n === void 0 ? null : n;
110
- }
111
- return null;
237
+ return e < 4 ? e === 0 ? this._s0 : e === 1 ? this._s1 : e === 2 ? this._s2 : this._s3 : this._overflow?.[e - 4] ?? null;
112
238
  }
113
239
  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: this._overflow ??= [], this._overflow[e - 4] = t;
128
- }
129
- e >= this._count && (this._count = e + 1);
240
+ let n = this.getAt(e);
241
+ n !== t && (this._rawWrite(e, t), n === null ? this._actualCount++ : t === null && this._actualCount--, t !== null && e >= this._count ? this._count = e + 1 : t === null && this._shrinkPhysicalSizeFrom(e));
242
+ }
243
+ _shrinkPhysicalSizeFrom(e) {
244
+ if (e === this._count - 1) for (this._count--; this._count > 0 && this.getAt(this._count - 1) == null;) this._count--;
130
245
  }
131
246
  truncateFrom(e) {
132
- let t = this._count;
133
- if (e >= t) return;
134
- if (e <= 3) {
135
- if (e <= 0) {
136
- let e = this._s0;
137
- e != null && (this._onItemRemoved(e), this._s0 = null);
138
- }
139
- if (e <= 1) {
140
- let e = this._s1;
141
- e != null && (this._onItemRemoved(e), this._s1 = null);
142
- }
143
- if (e <= 2) {
144
- let e = this._s2;
145
- e != null && (this._onItemRemoved(e), this._s2 = null);
146
- }
147
- if (e <= 3) {
148
- let e = this._s3;
149
- e != null && (this._onItemRemoved(e), this._s3 = null);
150
- }
151
- }
152
- let n = this._overflow;
153
- if (n !== null && t > 4) {
154
- let t = e > 4 ? e - 4 : 0, r = n.length;
155
- for (let e = t; e < r; e++) {
156
- let t = n[e];
157
- t != null && (this._onItemRemoved(t), n[e] = null);
247
+ e <= 3 && (e <= 0 && this._s0 !== null && (this._onItemRemoved(this._s0), this._s0 = null, this._actualCount--), e <= 1 && this._s1 !== null && (this._onItemRemoved(this._s1), this._s1 = null, this._actualCount--), e <= 2 && this._s2 !== null && (this._onItemRemoved(this._s2), this._s2 = null, this._actualCount--), e <= 3 && this._s3 !== null && (this._onItemRemoved(this._s3), this._s3 = null, this._actualCount--));
248
+ let t = this._overflow;
249
+ if (t !== null) {
250
+ let n = e > 4 ? e - 4 : 0, r = t.length;
251
+ for (let e = n; e < r; e++) {
252
+ let n = t[e];
253
+ n != null && (this._onItemRemoved(n), t[e] = null, this._actualCount--);
158
254
  }
159
- e <= 4 ? (n.length = 0, this._overflow = null) : n.length = e - 4;
255
+ e <= 4 ? this._overflow = null : t.length = e - 4;
160
256
  }
161
- this._freeIndices !== null && (this._freeIndices = null), this._count = e;
257
+ this._count = e, this._actualCount < 0 && (this._actualCount = 0), this._freeIndices = null;
162
258
  }
163
259
  _onItemRemoved(e) {}
164
260
  add(e) {
165
- if (this._s0 === null) {
166
- this._s0 = e, this._count++;
167
- return;
168
- }
169
- if (this._s1 === null) {
170
- this._s1 = e, this._count++;
171
- return;
172
- }
173
- if (this._s2 === null) {
174
- this._s2 = e, this._count++;
175
- return;
176
- }
177
- if (this._s3 === null) {
178
- this._s3 = e, this._count++;
179
- return;
180
- }
181
- this._addToOverflow(e);
182
- }
183
- _addToOverflow(e) {
184
- let t = this._overflow;
185
- if (t === null) this._overflow = [e];
186
- else {
187
- let n = this._freeIndices;
188
- n !== null && n.length > 0 ? t[n.pop()] = e : t.push(e);
189
- }
190
- this._count++;
261
+ let t = this._rawAdd(e);
262
+ return t >= this._count && (this._count = t + 1), this._actualCount++, t;
191
263
  }
192
264
  remove(e) {
193
- if (this._s0 === e) return this._s0 = null, this._count--, !0;
194
- if (this._s1 === e) return this._s1 = null, this._count--, !0;
195
- if (this._s2 === e) return this._s2 = null, this._count--, !0;
196
- if (this._s3 === e) return this._s3 = null, this._count--, !0;
197
- let t = this._overflow;
198
- if (t == null) return !1;
199
- for (let n = 0, r = t.length; n < r; n++) if (t[n] === e) {
200
- t[n] = null, this._count--;
201
- let e = this._freeIndices;
202
- return e === null && (e = this._freeIndices = []), e.push(n), !0;
265
+ let t = -1;
266
+ if (this._s0 === e) t = 0;
267
+ else if (this._s1 === e) t = 1;
268
+ else if (this._s2 === e) t = 2;
269
+ else if (this._s3 === e) t = 3;
270
+ else {
271
+ let n = this._overflow;
272
+ n !== null && (t = n.indexOf(e), t !== -1 && (t += 4));
203
273
  }
204
- return !1;
274
+ return t === -1 ? !1 : (this._rawWrite(t, null), this._shrinkPhysicalSizeFrom(t), this._actualCount--, t >= 4 && (this._freeIndices === null && (this._freeIndices = []), this._freeIndices.push(t - 4)), !0);
205
275
  }
206
276
  has(e) {
207
- if (this._count === 0) return !1;
277
+ if (this._actualCount === 0) return !1;
208
278
  if (this._s0 === e || this._s1 === e || this._s2 === e || this._s3 === e) return !0;
209
279
  let t = this._overflow;
210
- if (t != null) {
211
- for (let n = 0, r = t.length; n < r; n++) if (t[n] === e) return !0;
212
- }
213
- return !1;
280
+ return t === null ? !1 : t.indexOf(e) !== -1;
214
281
  }
215
282
  forEach(e) {
216
- let t = this._count;
283
+ let t = this._actualCount;
217
284
  if (t === 0) return;
218
- let n = 0, r = this._s0;
219
- if (r != null && (e(r), ++n === t)) return;
220
- let i = this._s1;
221
- if (i != null && (e(i), ++n === t)) return;
222
- let a = this._s2;
223
- if (a != null && (e(a), ++n === t)) return;
224
- let o = this._s3;
225
- if (o != null && (e(o), ++n === t)) return;
226
- let s = this._overflow;
227
- if (s != null) for (let r = 0, i = s.length; r < i; r++) {
228
- let i = s[r];
229
- if (i != null && (e(i), ++n === t)) return;
230
- }
231
- }
232
- forEachIndexed(e) {
233
- let t = this._count;
234
- if (t === 0) return 0;
235
- let n = 0, r = this._s0;
236
- if (r != null && (e(r), ++n === t)) return n;
237
- let i = this._s1;
238
- if (i != null && (e(i), ++n === t)) return n;
239
- let a = this._s2;
240
- if (a != null && (e(a), ++n === t)) return n;
241
- let o = this._s3;
242
- if (o != null && (e(o), ++n === t)) return n;
243
- let s = this._overflow;
244
- if (s != null) for (let r = 0, i = s.length; r < i; r++) {
245
- let i = s[r];
246
- if (i != null && (e(i), ++n === t)) return n;
247
- }
248
- return n;
285
+ if (t === this._count) {
286
+ this._s0 != null && e(this._s0), this._s1 != null && e(this._s1), this._s2 != null && e(this._s2), this._s3 != null && e(this._s3);
287
+ let t = this._overflow;
288
+ if (t !== null) for (let n = 0, r = t.length; n < r; n++) {
289
+ let r = t[n];
290
+ r != null && e(r);
291
+ }
292
+ return;
293
+ }
294
+ let n = 0, r = this._count;
295
+ for (let i = 0; i < r; i++) {
296
+ let r = this.getAt(i);
297
+ if (r != null && (e(r), ++n >= t)) break;
298
+ }
249
299
  }
250
300
  compact() {
251
- let e = this._overflow;
252
- if (e === null) return;
253
- let t = e.length;
254
- if (t === 0) return;
255
- let n = 0;
256
- for (; n < t;) if (e[n] === null) {
257
- for (; t > n && e[t - 1] === null;) e.pop(), t--;
258
- t > n && (e[n] = e.pop(), t--, n++);
259
- } else n++;
260
- this._freeIndices = null, t === 0 && (this._overflow = null);
301
+ if (this._actualCount === this._count) return;
302
+ let e = 0, t = this._count;
303
+ for (let n = 0; n < t; n++) {
304
+ let t = this.getAt(n);
305
+ t != null && (n !== e && (this._rawWrite(e, t), this._rawWrite(n, null)), e++);
306
+ }
307
+ this._count = this._actualCount, this._overflow !== null && (e <= 4 ? this._overflow = null : this._overflow.length = e - 4), this._freeIndices = null;
261
308
  }
262
309
  clear() {
263
- 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), this._freeIndices = null;
310
+ this._s0 = this._s1 = this._s2 = this._s3 = null, this._count = 0, this._actualCount = 0, this._overflow = null, this._freeIndices = null;
264
311
  }
265
312
  dispose() {
266
313
  this.clear();
267
314
  }
268
- }, C = class extends S {
315
+ }, re = class extends ne {
269
316
  constructor(...e) {
270
317
  super(...e), this._map = null, this._SCAN_THRESHOLD = 32, this.hasComputeds = !1;
271
318
  }
@@ -273,144 +320,106 @@ var ee = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), _ = /* @__PURE__ */ Sym
273
320
  this.hasComputeds = !1;
274
321
  }
275
322
  _onItemRemoved(e) {
276
- let t = e.unsub;
277
- t && t();
323
+ e.unsub?.();
324
+ }
325
+ setAt(e, t) {
326
+ let n = this.getAt(e);
327
+ super.setAt(e, t), this._map !== null && (n?.unsub && this._map.delete(n.node), t?.unsub && this._map.set(t.node, e));
278
328
  }
279
329
  claimExisting(e, t) {
280
330
  let n = this._count;
281
- if (t >= n) return !1;
282
- let r = n - t;
283
- if (this._map !== null || r > this._SCAN_THRESHOLD) return this._claimViaMap(e, t);
284
- if (t < 4) switch (t) {
285
- case 0: {
286
- let t = this._s0;
287
- if (t && t.node === e && t.unsub) return t.version = e.version, !0;
288
- }
289
- case 1: if (n > 1) {
290
- let n = this._s1;
291
- if (n && n.node === e && n.unsub) return n.version = e.version, t !== 1 && (this._s1 = this._s0, this._s0 = n), !0;
292
- }
293
- case 2: if (n > 2) {
294
- let n = this._s2;
295
- if (n && n.node === e && n.unsub) {
296
- if (n.version = e.version, t !== 2) {
297
- let e = t === 0 ? this._s0 : this._s1;
298
- t === 0 ? this._s0 = n : this._s1 = n, this._s2 = e;
299
- }
300
- return !0;
301
- }
302
- }
303
- case 3: if (n > 3) {
304
- let n = this._s3;
305
- if (n && n.node === e && n.unsub) {
306
- if (n.version = e.version, t !== 3) {
307
- let e;
308
- 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;
309
- }
310
- return !0;
311
- }
312
- }
313
- }
314
- let i = this._overflow;
315
- if (i) {
316
- let n = e.version, r = t > 4 ? t : 4, a = i.length;
317
- for (let o = r - 4; o < a; o++) {
318
- let r = i[o];
319
- if (r && r.node === e && r.unsub) return r.version = n, this._swapGeneral(o + 4, t, r), !0;
320
- }
331
+ if (n <= t) return !1;
332
+ let r = this.getAt(t);
333
+ if (r && r.node === e && r.unsub) return r.version = e.version, !0;
334
+ if (this._map !== null || n - t > this._SCAN_THRESHOLD) return this._claimViaMap(e, t);
335
+ for (let r = t + 1; r < n; r++) {
336
+ let n = this.getAt(r);
337
+ if (n && n.node === e && n.unsub) return n.version = e.version, this._rawSwap(r, t), !0;
321
338
  }
322
339
  return !1;
323
340
  }
324
341
  _claimViaMap(e, t) {
325
- let n = this._map;
326
- if (n === null) {
327
- n = this._map = /* @__PURE__ */ new Map();
328
- let e = this._count;
329
- if (t < 4) {
330
- let e = this._s0;
331
- t <= 0 && e?.unsub && n.set(e.node, 0);
332
- let r = this._s1;
333
- t <= 1 && r?.unsub && n.set(r.node, 1);
334
- let i = this._s2;
335
- t <= 2 && i?.unsub && n.set(i.node, 2);
336
- let a = this._s3;
337
- t <= 3 && a?.unsub && n.set(a.node, 3);
338
- }
339
- let r = this._overflow;
340
- if (r && e > 4) {
341
- let e = t > 4 ? t : 4, i = r.length;
342
- for (let t = e - 4; t < i; t++) {
343
- let e = r[t];
344
- e?.unsub && n.set(e.node, t + 4);
345
- }
346
- }
347
- }
348
- let r = n.get(e);
342
+ this._map === null && (this._map = this._initMap());
343
+ let n = this._map, r = n.get(e);
349
344
  if (r === void 0 || r < t) return !1;
350
345
  let i = this.getAt(r);
351
346
  if (i == null || !i.unsub) return !1;
352
347
  if (i.version = e.version, r !== t) {
353
- let a;
354
- a = t === 0 ? this._s0 : t === 1 ? this._s1 : t === 2 ? this._s2 : t === 3 ? this._s3 : this._overflow[t - 4] ?? null, this.setAt(t, i), this.setAt(r, a), a?.unsub && n.set(a.node, r), n.set(e, t);
348
+ let i = this.getAt(t);
349
+ this._rawSwap(r, t), n.set(e, t), i?.unsub && n.set(i.node, r);
355
350
  }
356
351
  return !0;
357
352
  }
358
- _swapGeneral(e, t, n) {
359
- if (e === t) return;
360
- let r;
361
- if (r = t === 0 ? this._s0 : t === 1 ? this._s1 : t === 2 ? this._s2 : t === 3 ? this._s3 : this._overflow[t - 4] ?? null, this.setAt(t, n), e === 0) this._s0 = r;
362
- else if (e === 1) this._s1 = r;
363
- else if (e === 2) this._s2 = r;
364
- else if (e === 3) this._s3 = r;
365
- else {
366
- let t = this._overflow;
367
- t[e - 4] = r;
353
+ _initMap() {
354
+ let e = /* @__PURE__ */ new Map();
355
+ for (let t = 0; t < this._count; t++) {
356
+ let n = this.getAt(t);
357
+ n?.unsub && e.set(n.node, t);
368
358
  }
359
+ return e;
369
360
  }
370
361
  insertNew(e, t) {
371
- let n = this._count;
372
- if (e < n) {
373
- let t;
374
- t = e === 0 ? this._s0 : e === 1 ? this._s1 : e === 2 ? this._s2 : e === 3 ? this._s3 : this._overflow[e - 4] ?? null, t != null && (this._addToOverflow(t), this._map !== null && t.unsub && this._map.set(t.node, this._count - 1));
375
- }
376
- if (e === 0) this._s0 = t;
377
- else if (e === 1) this._s1 = t;
378
- else if (e === 2) this._s2 = t;
379
- else if (e === 3) this._s3 = t;
380
- else {
381
- let n = this._overflow;
382
- n || (n = [], this._overflow = n), n[e - 4] = t;
362
+ let n = this.getAt(e);
363
+ if (n !== null) {
364
+ let e = this._rawAdd(n);
365
+ e >= this._count && (this._count = e + 1), this._map !== null && n.unsub && this._map.set(n.node, e);
383
366
  }
384
- e >= n && (this._count = e + 1);
385
- }
386
- truncateFrom(e) {
387
- e >= this._count || (super.truncateFrom(e), this._map !== null && (this._map.clear(), this._map = null));
367
+ this._rawWrite(e, t), e >= this._count && (this._count = e + 1), this._actualCount++, this._map !== null && t.unsub && this._map.set(t.node, e);
388
368
  }
389
- disposeAll() {
390
- this._count > 0 && this.truncateFrom(0), this.hasComputeds = !1;
369
+ add(e) {
370
+ let t = super.add(e);
371
+ return this._map !== null && e.unsub && this._map.set(e.node, t), t;
391
372
  }
392
373
  remove(e) {
393
- throw Error("remove() is strictly prohibited in DepSlotBuffer to preserve sequential cache paths.");
374
+ throw Error("remove() prohibited");
394
375
  }
395
376
  compact() {}
396
- }, w = class {
377
+ truncateFrom(e) {
378
+ super.truncateFrom(e), this._map !== null && (this._map = null);
379
+ }
380
+ disposeAll() {
381
+ this.truncateFrom(0), this.hasComputeds = !1;
382
+ }
383
+ }, E = /* @__PURE__ */ Symbol.for("atom-effect/brand"), D = {
384
+ Atom: 1,
385
+ Writable: 2,
386
+ Computed: 4,
387
+ Effect: 8
388
+ };
389
+ function ie(e, t) {
390
+ if (!e) return !1;
391
+ let n = typeof e;
392
+ return (n === "object" || n === "function") && !!((e[E] ?? 0) & t);
393
+ }
394
+ function ae(e) {
395
+ return ie(e, D.Atom);
396
+ }
397
+ function oe(e) {
398
+ return ie(e, D.Computed);
399
+ }
400
+ function se(e) {
401
+ if (e instanceof Promise) return !0;
402
+ if (!e) return !1;
403
+ let t = typeof e;
404
+ return (t === "object" || t === "function") && typeof e.then == "function";
405
+ }
406
+ var ce = class {
397
407
  constructor(e, t, n = void 0) {
398
408
  this.node = e, this.version = t, this.unsub = n;
399
409
  }
400
- }, te = class {
401
- constructor(e, t) {
410
+ }, le = class {
411
+ constructor(e = void 0, t = void 0) {
402
412
  this.fn = e, this.sub = t;
403
413
  }
404
414
  notify(e, t) {
405
- let n = this.fn;
406
- if (n !== void 0) {
407
- n(e, t);
408
- return;
409
- }
410
- let r = this.sub;
411
- r !== void 0 && r.execute();
415
+ k(() => {
416
+ let n = this.fn;
417
+ n !== void 0 && n(e, t);
418
+ let r = this.sub;
419
+ r !== void 0 && r.execute();
420
+ });
412
421
  }
413
- }, T = new class {
422
+ }, O = new class {
414
423
  constructor() {
415
424
  this.current = null;
416
425
  }
@@ -419,14 +428,15 @@ var ee = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), _ = /* @__PURE__ */ Sym
419
428
  let n = this.current;
420
429
  this.current = e;
421
430
  try {
422
- return t();
431
+ let e = t();
432
+ return f && T.warn(se(e), "Detected Promise returned within tracking context. Dependencies accessed after \"await\" will NOT be tracked. Consider using synchronous tracking before the async boundary."), e;
423
433
  } finally {
424
434
  this.current = n;
425
435
  }
426
436
  }
427
437
  }();
428
- function E(e) {
429
- let t = T, n = t.current;
438
+ function k(e) {
439
+ let t = O, n = t.current;
430
440
  if (n === null) return e();
431
441
  t.current = null;
432
442
  try {
@@ -435,24 +445,24 @@ function E(e) {
435
445
  t.current = n;
436
446
  }
437
447
  }
438
- var ne = class {
448
+ var ue = class {
439
449
  constructor() {
440
- this.flags = 0, this.version = 0, this._lastSeenEpoch = c.UNINITIALIZED, this._notifying = 0, this._hotIndex = -1, this._slots = null, this._deps = null, this.id = x() & l;
450
+ this.flags = 0, this.version = 0, this._lastSeenEpoch = u.UNINITIALIZED, this._nextEpoch = void 0, this._notifying = 0, this._hotIndex = -1, this._slots = null, this._deps = null, this.id = te() & s;
441
451
  }
442
452
  get isDisposed() {
443
- return (this.flags & r.DISPOSED) !== 0;
453
+ return (this.flags & i.DISPOSED) !== 0;
444
454
  }
445
455
  get isComputed() {
446
- return (this.flags & r.IS_COMPUTED) !== 0;
456
+ return (this.flags & i.IS_COMPUTED) !== 0;
447
457
  }
448
458
  get hasError() {
449
459
  return !1;
450
460
  }
451
461
  subscribe(e) {
452
462
  let t = typeof e == "function";
453
- if (!t && (!e || typeof e.execute != "function")) throw g(/* @__PURE__ */ TypeError("Invalid subscriber"), d, h.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);
463
+ if (!t && (!e || typeof e.execute != "function")) throw y(/* @__PURE__ */ TypeError("Invalid subscriber"), m, v.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);
454
464
  let n = this._slots;
455
- n || (n = new S(), this._slots = n);
465
+ n || (n = new ne(), this._slots = n);
456
466
  let r = !1;
457
467
  if (n._s0 != null && (t ? n._s0.fn === e : n._s0.sub === e)) r = !0;
458
468
  else if (n._s1 != null && (t ? n._s1.fn === e : n._s1.sub === e)) r = !0;
@@ -468,8 +478,8 @@ var ne = class {
468
478
  }
469
479
  }
470
480
  }
471
- if (r) return () => {};
472
- let i = new te(t ? e : void 0, t ? void 0 : e);
481
+ if (r) return f && console.warn(`[atom-effect] Duplicate subscription ignored on node ${this.id}`), () => {};
482
+ let i = new le(t ? e : void 0, t ? void 0 : e);
473
483
  return n.add(i), () => this._unsubscribe(i);
474
484
  }
475
485
  _unsubscribe(e) {
@@ -521,7 +531,7 @@ var ne = class {
521
531
  }
522
532
  }
523
533
  _logNotifyError(e) {
524
- console.error(g(e, d, h.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED));
534
+ console.error(y(e, m, v.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED));
525
535
  }
526
536
  _isDirty() {
527
537
  let e = this._deps;
@@ -533,90 +543,94 @@ var ne = class {
533
543
  }
534
544
  return this._deepDirtyCheck();
535
545
  }
536
- }, re = /* @__PURE__ */ Symbol.for("atom-effect/atom"), ie = /* @__PURE__ */ Symbol.for("atom-effect/computed"), ae = /* @__PURE__ */ Symbol.for("atom-effect/effect"), oe = /* @__PURE__ */ Symbol.for("atom-effect/writable"), se = 0;
537
- function ce() {
538
- let e = se + 1 & l;
539
- return se = e === 0 ? 1 : e, se;
546
+ }, de = 0;
547
+ function fe() {
548
+ let e = de + 1 & s;
549
+ return de = e === 0 ? 1 : e, de;
540
550
  }
541
- function le(e) {
542
- let t = e + 1 & l;
551
+ function pe(e) {
552
+ let t = e + 1 & s;
543
553
  return t === 0 ? 1 : t;
544
554
  }
545
- var ue = 0, de = !1, fe = 0;
546
- function pe() {
547
- return fe;
555
+ var me = 0, he = !1, ge = 0;
556
+ function _e() {
557
+ return ge;
548
558
  }
549
- function me() {
550
- return de ? !1 : (de = !0, fe = ce(), ue = 0, !0);
559
+ function ve() {
560
+ return he ? (f && console.warn("startFlush() called during flush - ignored"), !1) : (he = !0, ge = fe(), me = 0, !0);
551
561
  }
552
- function he() {
553
- de = !1;
562
+ function ye() {
563
+ he = !1;
554
564
  }
555
- function ge() {
556
- if (!de) return 0;
557
- let e = ++ue;
558
- if (e <= a.MAX_EXECUTIONS_PER_FLUSH) return e;
559
- throw Error(`[atom-effect] Infinite loop detected: flush execution count exceeded ${a.MAX_EXECUTIONS_PER_FLUSH}`);
565
+ function be() {
566
+ if (!he) return 0;
567
+ let e = ++me;
568
+ if (e <= o.MAX_EXECUTIONS_PER_FLUSH) return e;
569
+ throw Error(`[atom-effect] Infinite loop detected: flush execution count exceeded ${o.MAX_EXECUTIONS_PER_FLUSH}`);
560
570
  }
561
- var D = new class {
571
+ var A = new class {
562
572
  constructor() {
563
- this._queueBuffer = [[], []], this._bufferIndex = 0, this._size = 0, this._epoch = 0, this._isProcessing = !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);
573
+ this._queueBuffer = [[], []], this._bufferIndex = 0, this._size = 0, this._epoch = 0, this._isProcessing = !1, this._isFlushingSync = !1, this._batchDepth = 0, this._batchQueue = [], this._batchQueueSize = 0, this._maxFlushIterations = o.MAX_FLUSH_ITERATIONS, this.onOverflow = null, this._boundRunLoop = this._runLoop.bind(this);
564
574
  }
565
575
  get queueSize() {
566
- return this._size;
576
+ return this._size + this._batchQueueSize;
567
577
  }
568
578
  get isBatching() {
569
579
  return this._batchDepth > 0;
570
580
  }
571
581
  schedule(e) {
582
+ if (f && typeof e != "function" && (!e || typeof e.execute != "function")) throw new _(v.SCHEDULER_CALLBACK_MUST_BE_FUNCTION);
572
583
  let t = this._epoch;
573
584
  if (e._nextEpoch === t) return;
574
585
  if (e._nextEpoch = t, this._batchDepth > 0 || this._isFlushingSync) {
575
586
  this._batchQueue[this._batchQueueSize++] = e;
576
587
  return;
577
588
  }
578
- let n = this._bufferIndex, r = this._queueBuffer[n];
579
- r[this._size++] = e, this._isProcessing || this._flush();
589
+ let n = this._queueBuffer[this._bufferIndex];
590
+ n[this._size++] = e, this._isProcessing || this._flush();
580
591
  }
581
592
  _flush() {
582
593
  this._isProcessing || this._size === 0 || (this._isProcessing = !0, queueMicrotask(this._boundRunLoop));
583
594
  }
584
595
  _runLoop() {
585
596
  try {
586
- if (this._size === 0) return;
587
- let e = me();
588
- this._drainQueue(), e && he();
597
+ if (this._size === 0 && this._batchQueueSize === 0) return;
598
+ let e = ve();
599
+ this._drainQueue(), e && ye();
589
600
  } finally {
590
- this._isProcessing = !1, this._size > 0 && this._batchDepth === 0 && this._flush();
601
+ this._isProcessing = !1;
591
602
  }
592
603
  }
593
604
  _flushSync() {
605
+ if (this._size === 0 && this._batchQueueSize === 0) return;
606
+ let e = this._isFlushingSync;
594
607
  this._isFlushingSync = !0;
595
- let e = me();
608
+ let t = ve();
596
609
  try {
597
610
  this._mergeBatchQueue(), this._drainQueue();
598
611
  } finally {
599
- this._isFlushingSync = !1, e && he();
612
+ this._isFlushingSync = e, t && ye();
600
613
  }
601
614
  }
602
615
  _mergeBatchQueue() {
603
616
  let e = this._batchQueueSize;
604
617
  if (e === 0) return;
605
- let t = ++this._epoch, n = this._batchQueue, r = this._bufferIndex, i = this._queueBuffer[r], a = this._size;
606
- for (let r = 0; r < e; r++) {
607
- let e = n[r];
608
- e._nextEpoch !== t && (e._nextEpoch = t, i[a++] = e);
618
+ this._epoch = this._epoch + 1 | 0;
619
+ let t = this._epoch, n = this._batchQueue, r = this._queueBuffer[this._bufferIndex], i = this._size;
620
+ for (let a = 0; a < e; a++) {
621
+ let e = n[a];
622
+ e._nextEpoch !== t && (e._nextEpoch = t, r[i++] = e), n[a] = void 0;
609
623
  }
610
- this._size = a, this._batchQueueSize = 0, n.length = 0;
624
+ this._size = i, this._batchQueueSize = 0, n.length > o.BATCH_QUEUE_SHRINK_THRESHOLD && (n.length = 0);
611
625
  }
612
626
  _drainQueue() {
613
627
  let e = 0;
614
- for (; this._size > 0;) {
628
+ for (; this._size > 0 || this._batchQueueSize > 0;) {
615
629
  if (++e > this._maxFlushIterations) {
616
630
  this._handleFlushOverflow();
617
631
  return;
618
632
  }
619
- this._processQueue(), this._mergeBatchQueue();
633
+ this._batchQueueSize > 0 && this._mergeBatchQueue(), this._size > 0 && this._processQueue();
620
634
  }
621
635
  }
622
636
  _processQueue() {
@@ -624,82 +638,81 @@ var D = new class {
624
638
  this._bufferIndex = e ^ 1, this._size = 0, this._epoch = this._epoch + 1 | 0;
625
639
  for (let e = 0; e < n; e++) {
626
640
  let n = t[e];
641
+ t[e] = void 0;
627
642
  try {
628
643
  typeof n == "function" ? n() : n.execute();
629
644
  } catch (e) {
630
- console.error(new m("Error occurred during scheduler execution", e));
645
+ console.error(new _("Error occurred during scheduler execution", e));
631
646
  }
632
647
  }
633
- t.length = 0;
634
648
  }
635
649
  _handleFlushOverflow() {
636
- let e = this._size + this._batchQueueSize, t = this._maxFlushIterations;
637
- console.error(new m(h.SCHEDULER_FLUSH_OVERFLOW(t, e))), this._size = 0;
638
- let n = this._bufferIndex;
639
- this._queueBuffer[n].length = 0, this._batchQueueSize = 0;
640
- let r = this.onOverflow;
641
- if (r) try {
642
- r(e);
650
+ let e = this._size + this._batchQueueSize;
651
+ console.error(new _(v.SCHEDULER_FLUSH_OVERFLOW(this._maxFlushIterations, e))), this._size = 0, this._queueBuffer[0].length = 0, this._queueBuffer[1].length = 0, this._batchQueueSize = 0, this._batchQueue.length = 0;
652
+ let t = this.onOverflow;
653
+ if (t) try {
654
+ t(e);
643
655
  } catch {}
644
656
  }
645
657
  startBatch() {
646
658
  this._batchDepth++;
647
659
  }
648
660
  endBatch() {
649
- this._batchDepth !== 0 && --this._batchDepth === 0 && this._flushSync();
661
+ if (this._batchDepth === 0) {
662
+ f && console.warn(v.SCHEDULER_END_BATCH_WITHOUT_START);
663
+ return;
664
+ }
665
+ --this._batchDepth === 0 && (this._isFlushingSync || this._flushSync());
650
666
  }
651
667
  setMaxFlushIterations(e) {
652
- if (e < a.MIN_FLUSH_ITERATIONS) throw new m(`Max flush iterations must be at least ${a.MIN_FLUSH_ITERATIONS}`);
668
+ if (e < o.MIN_FLUSH_ITERATIONS) throw new _(`Max iterations must be at least ${o.MIN_FLUSH_ITERATIONS}`);
653
669
  this._maxFlushIterations = e;
654
670
  }
655
671
  }();
656
- function _e(e) {
657
- if (typeof e != "function") throw TypeError(h.BATCH_CALLBACK_MUST_BE_FUNCTION);
658
- let t = D;
659
- t.startBatch();
672
+ function xe(e) {
673
+ if (f && typeof e != "function") throw TypeError(v.BATCH_CALLBACK_MUST_BE_FUNCTION);
674
+ A.startBatch();
660
675
  try {
661
676
  return e();
662
677
  } finally {
663
- t.endBatch();
678
+ A.endBatch();
664
679
  }
665
680
  }
666
- var ve = class extends ne {
681
+ var Se = class extends ue {
667
682
  constructor(e, t) {
668
- super(), this[re] = !0, this[oe] = !0, this._value = e, t && (this.flags |= i.SYNC), y.attachDebugInfo(this, "atom", this.id);
683
+ super(), this[E] = D.Atom | D.Writable, this._value = e, this._equal = t.equal ?? Object.is, t.sync && (this.flags |= a.SYNC), T.attachDebugInfo(this, "atom", this.id, t.name);
669
684
  }
670
685
  get isNotificationScheduled() {
671
- return (this.flags & i.NOTIFICATION_SCHEDULED) !== 0;
686
+ return (this.flags & a.NOTIFICATION_SCHEDULED) !== 0;
672
687
  }
673
688
  get isSync() {
674
- return (this.flags & i.SYNC) !== 0;
689
+ return (this.flags & a.SYNC) !== 0;
675
690
  }
676
691
  get value() {
677
- return T.current?.addDependency(this), this._value;
692
+ return O.current?.addDependency(this), this._value;
678
693
  }
679
694
  set value(e) {
680
695
  let t = this._value;
681
- if (Object.is(t, e)) return;
682
- this._value = e, this.version = le(this.version);
683
- let n = this.flags;
684
- if ((n & i.NOTIFICATION_SCHEDULED) !== 0) return;
685
- let r = this._slots;
686
- r == null || r.size === 0 || (this._pendingOldValue = t, this.flags = n | i.NOTIFICATION_SCHEDULED, (n & i.SYNC) !== 0 && !D.isBatching ? this._flushNotifications() : D.schedule(this));
696
+ if (this._equal(t, e) || (this._value = e, this.version = pe(this.version), T.trackUpdate(this.id, T.getDebugName(this)), (this.flags & a.NOTIFICATION_SCHEDULED) !== 0)) return;
697
+ let n = this._slots;
698
+ n == null || n.size === 0 || (this._pendingOldValue = t, this.flags |= a.NOTIFICATION_SCHEDULED, (this.flags & a.SYNC) !== 0 && !A.isBatching ? this._notifying === 0 && this._flushNotifications() : A.schedule(this));
687
699
  }
688
700
  execute() {
689
701
  this._flushNotifications();
690
702
  }
691
703
  _flushNotifications() {
692
- let e = this.flags;
693
- if ((e & (i.NOTIFICATION_SCHEDULED | i.DISPOSED)) !== i.NOTIFICATION_SCHEDULED) return;
694
- let t = this._pendingOldValue;
695
- this._pendingOldValue = void 0, this.flags = e & ~i.NOTIFICATION_SCHEDULED, this._notifySubscribers(this._value, t);
704
+ let e = a.NOTIFICATION_SCHEDULED, t = a.DISPOSED, n = a.SYNC;
705
+ for (; (this.flags & (e | t)) === e;) {
706
+ let t = this._pendingOldValue;
707
+ if (this._pendingOldValue = void 0, this.flags &= ~e, this._equal(this._value, t) || this._notifySubscribers(this._value, t), (this.flags & n) === 0 || A.isBatching) break;
708
+ }
696
709
  }
697
710
  peek() {
698
711
  return this._value;
699
712
  }
700
713
  dispose() {
701
714
  let e = this.flags;
702
- (e & i.DISPOSED) === 0 && (this._slots?.clear(), this.flags = e | i.DISPOSED, this._value = void 0, this._pendingOldValue = void 0);
715
+ (e & a.DISPOSED) === 0 && (this._slots?.clear(), this.flags = e | a.DISPOSED, this._value = void 0, this._pendingOldValue = void 0, this._equal = Object.is);
703
716
  }
704
717
  _deepDirtyCheck() {
705
718
  return !1;
@@ -708,60 +721,51 @@ var ve = class extends ne {
708
721
  this.dispose();
709
722
  }
710
723
  };
711
- function O(e, t = {}) {
712
- return new ve(e, t.sync ?? !1);
713
- }
714
- function ye(e) {
715
- return typeof e == "object" && !!e && re in e;
724
+ function Ce(e, t = {}) {
725
+ return new Se(e, t);
716
726
  }
717
- function be(e) {
718
- return typeof e == "object" && !!e && ie in e;
719
- }
720
- function xe(e) {
721
- return typeof e == "object" && !!e && typeof e.then == "function";
722
- }
723
- var { IDLE: k, DIRTY: A, PENDING: j, RESOLVED: M, REJECTED: N, HAS_ERROR: Se, RECOMPUTING: P, DISPOSED: Ce, IS_COMPUTED: we, FORCE_COMPUTE: Te } = r, Ee = class extends ne {
727
+ var { IDLE: j, DIRTY: M, PENDING: N, RESOLVED: P, REJECTED: F, HAS_ERROR: we, RECOMPUTING: I, DISPOSED: Te, IS_COMPUTED: L, FORCE_COMPUTE: Ee } = i, De = class extends ue {
724
728
  constructor(e, t = {}) {
725
- if (typeof e != "function") throw new f(h.COMPUTED_MUST_BE_FUNCTION);
726
- if (super(), this[re] = !0, this[ie] = !0, this._error = null, this._promiseId = 0, this._deps = new C(), this._trackEpoch = c.UNINITIALIZED, this._trackCount = 0, this._value = void 0, this.flags = we | A | k, this._equal = t.equal ?? Object.is, this._fn = e, this._defaultValue = "defaultValue" in t ? t.defaultValue : v, this._onError = t.onError ?? null, y.attachDebugInfo(this, "computed", this.id), t.lazy === !1) try {
729
+ if (typeof e != "function") throw new h(v.COMPUTED_MUST_BE_FUNCTION);
730
+ if (super(), this[E] = D.Atom | D.Computed, this._error = null, this._promiseId = 0, this._deps = new re(), this._trackEpoch = u.UNINITIALIZED, this._trackCount = 0, this._value = void 0, this.flags = L | M | j, this._equal = t.equal ?? Object.is, this._fn = e, this._defaultValue = "defaultValue" in t ? t.defaultValue : C, this._onError = t.onError ?? null, T.attachDebugInfo(this, "computed", this.id, t.name), t.lazy === !1) try {
727
731
  this._recompute();
728
732
  } catch {}
729
733
  }
730
734
  get isDirty() {
731
- return (this.flags & A) !== 0;
735
+ return (this.flags & M) !== 0;
732
736
  }
733
737
  get isRejected() {
734
- return (this.flags & N) !== 0;
738
+ return (this.flags & F) !== 0;
735
739
  }
736
740
  get isRecomputing() {
737
- return (this.flags & P) !== 0;
741
+ return (this.flags & I) !== 0;
738
742
  }
739
743
  get _hasErrorInternal() {
740
- return (this.flags & Se) !== 0;
744
+ return (this.flags & we) !== 0;
741
745
  }
742
746
  _track() {
743
- T.current?.addDependency(this);
747
+ O.current?.addDependency(this);
744
748
  }
745
749
  get value() {
746
- T.current?.addDependency(this);
750
+ O.current?.addDependency(this);
747
751
  let e = this.flags;
748
- if ((e & (M | A | k)) === M) return this._value;
749
- if ((e & Ce) !== 0) throw new f(h.COMPUTED_DISPOSED);
750
- if ((e & P) !== 0) {
752
+ if ((e & (P | M | j)) === P) return this._value;
753
+ if ((e & Te) !== 0) throw new h(v.COMPUTED_DISPOSED);
754
+ if ((e & I) !== 0) {
751
755
  let e = this._defaultValue;
752
- if (e !== v) return e;
753
- throw new f(h.COMPUTED_CIRCULAR_DEPENDENCY);
756
+ if (e !== C) return e;
757
+ throw new h(v.COMPUTED_CIRCULAR_DEPENDENCY);
754
758
  }
755
- if ((e & (A | k)) !== 0) {
759
+ if ((e & (M | j)) !== 0) {
756
760
  let t = this._deps;
757
- if ((e & k) === 0 && (e & Te) === 0 && t.size > 0 && !this._isDirty() ? e = this.flags &= ~A : (this._recompute(), e = this.flags), (e & M) !== 0) return this._value;
761
+ if ((e & j) === 0 && (e & Ee) === 0 && t.size > 0 && !this._isDirty() ? e = this.flags &= ~M : (this._recompute(), e = this.flags), (e & P) !== 0) return this._value;
758
762
  }
759
- let t = this._defaultValue, n = t !== v;
760
- if ((e & j) !== 0) {
763
+ let t = this._defaultValue, n = t !== C;
764
+ if ((e & N) !== 0) {
761
765
  if (n) return t;
762
- throw new f(h.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
766
+ throw new h(v.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
763
767
  }
764
- if ((e & N) !== 0) {
768
+ if ((e & F) !== 0) {
765
769
  if (n) return t;
766
770
  throw this._error;
767
771
  }
@@ -771,57 +775,60 @@ var { IDLE: k, DIRTY: A, PENDING: j, RESOLVED: M, REJECTED: N, HAS_ERROR: Se, RE
771
775
  return this._value;
772
776
  }
773
777
  get state() {
774
- T.current?.addDependency(this);
778
+ O.current?.addDependency(this);
775
779
  let e = this.flags;
776
- return (e & M) === 0 ? (e & j) === 0 ? (e & N) === 0 ? t.IDLE : t.REJECTED : t.PENDING : t.RESOLVED;
780
+ return (e & P) === 0 ? (e & N) === 0 ? (e & F) === 0 ? n.IDLE : n.REJECTED : n.PENDING : n.RESOLVED;
777
781
  }
778
782
  get hasError() {
779
- if (T.current?.addDependency(this), (this.flags & (N | Se)) !== 0) return !0;
783
+ if (O.current?.addDependency(this), (this.flags & (F | we)) !== 0) return !0;
780
784
  let e = this._deps;
781
- if (!e.hasComputeds) return !1;
782
- let t = e.size;
783
- for (let n = 0; n < t; n++) if (e.getAt(n)?.node.hasError) return !0;
784
- return !1;
785
+ return e.hasComputeds ? k(() => {
786
+ let t = e.size;
787
+ for (let n = 0; n < t; n++) if (e.getAt(n)?.node.hasError) return !0;
788
+ return !1;
789
+ }) : !1;
785
790
  }
786
791
  get isValid() {
787
792
  return !this.hasError;
788
793
  }
789
794
  get errors() {
790
- T.current?.addDependency(this);
795
+ O.current?.addDependency(this);
791
796
  let e = this._error, t = this._deps;
792
- if (!t.hasComputeds) return e == null ? u : Object.freeze([e]);
797
+ if (!t.hasComputeds) return e == null ? p : Object.freeze([e]);
793
798
  let n = [];
794
- e != null && n.push(e);
795
- let r = t.size;
796
- for (let e = 0; e < r; e++) {
797
- let r = t.getAt(e);
798
- if (r == null) continue;
799
- let i = r.node;
800
- (i.flags & we) !== 0 && i.hasError && this._collectErrorsFromDep(i, n);
801
- }
802
- return n.length === 0 ? u : Object.freeze(n);
799
+ return e != null && n.push(e), k(() => {
800
+ let e = t.size;
801
+ for (let r = 0; r < e; r++) {
802
+ let e = t.getAt(r)?.node;
803
+ e != null && (e.flags & L) !== 0 && this._accumulateErrors(e, n);
804
+ }
805
+ }), n.length === 0 ? p : Object.freeze(n);
803
806
  }
804
- _collectErrorsFromDep(e, t) {
805
- let n = e.errors, r = n.length;
806
- for (let e = 0; e < r; e++) {
807
- let r = n[e];
808
- r != null && !t.includes(r) && t.push(r);
807
+ _accumulateErrors(e, t) {
808
+ let n = e._error;
809
+ n != null && !t.includes(n) && t.push(n);
810
+ let r = e._deps;
811
+ if (!r.hasComputeds) return;
812
+ let i = r.size;
813
+ for (let e = 0; e < i; e++) {
814
+ let n = r.getAt(e)?.node;
815
+ n != null && (n.flags & L) !== 0 && this._accumulateErrors(n, t);
809
816
  }
810
817
  }
811
818
  get lastError() {
812
- return T.current?.addDependency(this), this._error;
819
+ return O.current?.addDependency(this), this._error;
813
820
  }
814
821
  get isPending() {
815
- return T.current?.addDependency(this), (this.flags & j) !== 0;
822
+ return O.current?.addDependency(this), (this.flags & N) !== 0;
816
823
  }
817
824
  get isResolved() {
818
- return T.current?.addDependency(this), (this.flags & M) !== 0;
825
+ return O.current?.addDependency(this), (this.flags & P) !== 0;
819
826
  }
820
827
  invalidate() {
821
- this.flags |= Te, this._markDirty();
828
+ this.flags |= Ee, this._markDirty();
822
829
  }
823
830
  dispose() {
824
- (this.flags & Ce) === 0 && (this._deps.disposeAll(), this._slots != null && this._slots.clear(), this.flags = Ce | A | k, this._error = null, this._value = void 0, this._hotIndex = -1);
831
+ (this.flags & Te) === 0 && (this._deps.disposeAll(), this._slots != null && this._slots.clear(), this.flags = Te | M | j, this._error = null, this._value = void 0, this._hotIndex = -1);
825
832
  }
826
833
  [Symbol.dispose]() {
827
834
  this.dispose();
@@ -833,102 +840,102 @@ var { IDLE: k, DIRTY: A, PENDING: j, RESOLVED: M, REJECTED: N, HAS_ERROR: Se, RE
833
840
  let n = this._trackCount++, r = this._deps, i = r.getAt(n);
834
841
  if (i != null && i.node === e) i.version = e.version;
835
842
  else if (!r.claimExisting(e, n)) {
836
- let t = new w(e, e.version, e.subscribe(this));
843
+ let t = new ce(e, e.version, e.subscribe(this));
837
844
  r.insertNew(n, t);
838
845
  }
839
- (e.flags & we) !== 0 && (r.hasComputeds = !0);
846
+ (e.flags & L) !== 0 && (r.hasComputeds = !0);
840
847
  }
841
848
  _recompute() {
842
849
  if (this.isRecomputing) return;
843
- this.flags = (this.flags | P) & ~Te, this._trackEpoch = ce(), this._trackCount = 0, this._deps.prepareTracking(), this._hotIndex = -1;
850
+ this.flags = (this.flags | I) & ~Ee, this._trackEpoch = fe(), this._trackCount = 0, this._deps.prepareTracking(), this._hotIndex = -1;
844
851
  let e = !1;
845
852
  try {
846
- let t = T.run(this, this._fn);
847
- this._deps.truncateFrom(this._trackCount), e = !0, xe(t) ? this._handleAsyncComputation(t) : this._finalizeResolution(t);
853
+ let t = O.run(this, this._fn);
854
+ this._deps.truncateFrom(this._trackCount), e = !0, se(t) ? this._handleAsyncComputation(t) : this._finalizeResolution(t);
848
855
  } catch (t) {
849
856
  if (!e) try {
850
857
  this._deps.truncateFrom(this._trackCount);
851
- } catch {}
852
- this._handleError(t, h.COMPUTED_COMPUTATION_FAILED, !0);
858
+ } catch (e) {
859
+ f && console.warn("[atom-effect] _commitDeps failed during error recovery:", e);
860
+ }
861
+ this._handleError(t, v.COMPUTED_COMPUTATION_FAILED, !0);
853
862
  } finally {
854
- this._trackEpoch = c.UNINITIALIZED, this._trackCount = 0, this.flags &= ~P;
863
+ this._trackEpoch = u.UNINITIALIZED, this._trackCount = 0, this.flags &= ~I;
855
864
  }
856
865
  }
857
866
  _handleAsyncComputation(e) {
858
- this.flags = (this.flags | j) & ~(k | A | M | N), this._notifySubscribers(void 0, void 0), this._promiseId = (this._promiseId + 1) % s.MAX_PROMISE_ID;
867
+ this.flags = (this.flags | N) & ~(j | M | P | F), this._notifySubscribers(void 0, void 0), this._promiseId = (this._promiseId + 1) % l.MAX_PROMISE_ID;
859
868
  let t = this._promiseId;
860
869
  e.then((e) => {
861
870
  if (t === this._promiseId) {
862
871
  if (this._isDirty()) return this._markDirty();
863
872
  this._finalizeResolution(e), this._notifySubscribers(e, void 0);
864
873
  }
865
- }, (e) => t === this._promiseId && this._handleError(e, h.COMPUTED_ASYNC_COMPUTATION_FAILED));
874
+ }, (e) => t === this._promiseId && this._handleError(e, v.COMPUTED_ASYNC_COMPUTATION_FAILED));
866
875
  }
867
876
  _handleError(e, t, n = !1) {
868
- let r = g(e, f, t);
869
- if (!n && !this.isRejected && (this.version = le(this.version)), this._error = r, this.flags = this.flags & ~(k | A | j | M) | N | Se, this._onError) try {
877
+ let r = y(e, h, t);
878
+ if ((!this.isRejected || this._error !== r) && (this.version = pe(this.version)), this._error = r, this.flags = this.flags & ~(j | M | N | P) | F | we, this._onError) try {
870
879
  this._onError(r);
871
880
  } catch (e) {
872
- console.error(h.CALLBACK_ERROR_IN_ERROR_HANDLER, e);
881
+ console.error(v.CALLBACK_ERROR_IN_ERROR_HANDLER, e);
873
882
  }
874
- if (n) throw r;
875
- this._notifySubscribers(void 0, void 0);
883
+ if (this._notifySubscribers(void 0, void 0), n) throw r;
876
884
  }
877
885
  _finalizeResolution(e) {
878
886
  let t = this.flags;
879
- ((t & M) === 0 || !this._equal(this._value, e)) && (this.version = le(this.version)), this._value = e, this._error = null, this.flags = (t | M) & ~(k | A | j | N | Se);
887
+ ((t & P) === 0 || !this._equal(this._value, e)) && (this.version = pe(this.version)), this._value = e, this._error = null, this.flags = (t | P) & ~(j | M | N | F | we);
880
888
  }
881
889
  execute() {
882
890
  this._markDirty();
883
891
  }
884
892
  _markDirty() {
885
893
  let e = this.flags;
886
- (e & (P | A)) === 0 && (this.flags = e | A, this._notifySubscribers(void 0, void 0));
894
+ (e & (I | M)) === 0 && (this.flags = e | M, T.trackUpdate(this.id, T.getDebugName(this)), this._notifySubscribers(void 0, void 0));
887
895
  }
888
896
  _deepDirtyCheck() {
889
- let e = this._deps, t = T.current;
890
- T.current = null;
891
- try {
897
+ let e = this._deps;
898
+ return k(() => {
892
899
  let t = e.size;
893
900
  for (let n = 0; n < t; n++) {
894
901
  let t = e.getAt(n);
895
902
  if (t == null) continue;
896
903
  let r = t.node;
897
- if ((r.flags & we) !== 0) try {
904
+ if ((r.flags & L) !== 0) try {
898
905
  r.value;
899
- } catch {}
906
+ } catch {
907
+ f && console.warn(`[atom-effect] Dependency #${r.id} threw during dirty check`);
908
+ }
900
909
  if (r.version !== t.version) return this._hotIndex = n, !0;
901
910
  }
902
911
  return this._hotIndex = -1, !1;
903
- } finally {
904
- T.current = t;
905
- }
912
+ });
906
913
  }
907
914
  };
908
- function F(e, t = {}) {
909
- return new Ee(e, t);
915
+ function Oe(e, t = {}) {
916
+ return new De(e, t);
910
917
  }
911
- var De = class extends ne {
918
+ var ke = class extends ue {
912
919
  constructor(e, t = {}) {
913
- super(), this[ae] = !0, this._cleanup = null, this._deps = new C(), 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._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 = () => D.schedule(this), y.attachDebugInfo(this, "effect", this.id);
920
+ super(), this[E] = D.Effect, this._cleanup = null, this._deps = new re(), this._currentEpoch = u.UNINITIALIZED, this._lastFlushEpoch = u.UNINITIALIZED, this._fn = e, this._onError = t.onError ?? null, this._sync = t.sync ?? !1, this._maxExecutions = t.maxExecutionsPerSecond ?? o.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = t.maxExecutionsPerFlush ?? o.MAX_EXECUTIONS_PER_EFFECT, 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 = () => A.schedule(this), T.attachDebugInfo(this, "effect", this.id, t.name);
914
921
  }
915
922
  run() {
916
- if (this.isDisposed) throw new p(h.EFFECT_DISPOSED);
923
+ if (this.isDisposed) throw new g(v.EFFECT_DISPOSED);
917
924
  this.execute(!0);
918
925
  }
919
926
  dispose() {
920
- this.isDisposed || (this.flags |= n.DISPOSED, this._execCleanup(), this._deps?.disposeAll());
927
+ this.isDisposed || (this.flags |= r.DISPOSED, this._execCleanup(), this._deps?.disposeAll());
921
928
  }
922
929
  [Symbol.dispose]() {
923
930
  this.dispose();
924
931
  }
925
932
  addDependency(e) {
926
- if ((this.flags & n.EXECUTING) === 0) return;
933
+ if ((this.flags & r.EXECUTING) === 0) return;
927
934
  let t = this._currentEpoch;
928
935
  if (e._lastSeenEpoch === t) return;
929
936
  e._lastSeenEpoch = t;
930
- let r = this._trackCount++, i = this._deps, a;
931
- switch (r) {
937
+ let n = this._trackCount++, i = this._deps, a;
938
+ switch (n) {
932
939
  case 0:
933
940
  a = i._s0;
934
941
  break;
@@ -941,41 +948,43 @@ var De = class extends ne {
941
948
  case 3:
942
949
  a = i._s3;
943
950
  break;
944
- default: a = i.getAt(r);
951
+ default: a = i.getAt(n);
945
952
  }
946
- a != null && a.node === e ? a.version = e.version : i.claimExisting(e, r) || this._insertNewDependency(e, r), e.isComputed && (i.hasComputeds = !0);
953
+ a != null && a.node === e ? a.version = e.version : i.claimExisting(e, n) || this._insertNewDependency(e, n), e.isComputed && (i.hasComputeds = !0);
947
954
  }
948
955
  _insertNewDependency(e, t) {
949
956
  let n;
950
957
  try {
951
958
  let t = e.subscribe(this._notifyCallback);
952
- n = new w(e, e.version, t);
959
+ n = new ce(e, e.version, t);
953
960
  } catch (t) {
954
- let r = g(t, p, h.EFFECT_EXECUTION_FAILED);
961
+ let r = y(t, g, v.EFFECT_EXECUTION_FAILED);
955
962
  if (console.error(r), this._onError) try {
956
963
  this._onError(r);
957
964
  } catch {}
958
- n = new w(e, e.version, void 0);
965
+ n = new ce(e, e.version, void 0);
959
966
  }
960
967
  this._deps.insertNew(t, n);
961
968
  }
962
969
  execute(e = !1) {
963
970
  let t = this.flags;
964
- if ((t & (n.DISPOSED | n.EXECUTING)) !== 0) return;
965
- let r = this._deps;
966
- if (!e && r.size > 0 && !this._isDirty()) return;
967
- this._checkInfiniteLoops(), this.flags = t | n.EXECUTING, this._execCleanup(), this._currentEpoch = ce(), this._trackCount = 0, r.prepareTracking(), this._hotIndex = -1;
971
+ if ((t & (r.DISPOSED | r.EXECUTING)) !== 0) return;
972
+ let n = this._deps;
973
+ if (!e && n.size > 0 && !this._isDirty()) return;
974
+ this._checkInfiniteLoops(), T.trackUpdate(this.id, T.getDebugName(this)), this.flags = t | r.EXECUTING, this._execCleanup(), this._currentEpoch = fe(), this._trackCount = 0, n.prepareTracking(), this._hotIndex = -1;
968
975
  let i = !1;
969
976
  try {
970
- let e = T.run(this, this._fn);
971
- r.truncateFrom(this._trackCount), i = !0, xe(e) ? this._handleAsyncResult(e) : this._cleanup = typeof e == "function" ? e : null;
977
+ let e = O.run(this, this._fn);
978
+ n.truncateFrom(this._trackCount), i = !0, se(e) ? this._handleAsyncResult(e) : this._cleanup = typeof e == "function" ? e : null;
972
979
  } catch (e) {
973
980
  if (!i) try {
974
- r.truncateFrom(this._trackCount);
975
- } catch {}
981
+ n.truncateFrom(this._trackCount);
982
+ } catch (e) {
983
+ f && console.warn("[atom-effect] _commitDeps failed during error recovery:", e);
984
+ }
976
985
  this._handleExecutionError(e), this._cleanup = null;
977
986
  } finally {
978
- this.flags &= ~n.EXECUTING;
987
+ this.flags &= ~r.EXECUTING;
979
988
  }
980
989
  }
981
990
  _handleAsyncResult(e) {
@@ -985,7 +994,7 @@ var De = class extends ne {
985
994
  if (typeof e == "function") try {
986
995
  e();
987
996
  } catch (e) {
988
- this._handleExecutionError(e, h.EFFECT_CLEANUP_FAILED);
997
+ this._handleExecutionError(e, v.EFFECT_CLEANUP_FAILED);
989
998
  }
990
999
  return;
991
1000
  }
@@ -993,8 +1002,8 @@ var De = class extends ne {
993
1002
  }, (e) => t === this._execId && this._handleExecutionError(e));
994
1003
  }
995
1004
  _deepDirtyCheck() {
996
- let e = T.current;
997
- T.current = null;
1005
+ let e = O.current;
1006
+ O.current = null;
998
1007
  let t = this._deps;
999
1008
  try {
1000
1009
  let e = t.size;
@@ -1006,13 +1015,15 @@ var De = class extends ne {
1006
1015
  }
1007
1016
  return !1;
1008
1017
  } finally {
1009
- T.current = e;
1018
+ O.current = e;
1010
1019
  }
1011
1020
  }
1012
1021
  _tryPullComputed(e) {
1013
1022
  try {
1014
1023
  e.value;
1015
- } catch {}
1024
+ } catch {
1025
+ f && console.warn(`[atom-effect] Dependency #${e.id} threw during dirty check`);
1026
+ }
1016
1027
  }
1017
1028
  _execCleanup() {
1018
1029
  let e = this._cleanup;
@@ -1021,23 +1032,23 @@ var De = class extends ne {
1021
1032
  try {
1022
1033
  e();
1023
1034
  } catch (e) {
1024
- this._handleExecutionError(e, h.EFFECT_CLEANUP_FAILED);
1035
+ this._handleExecutionError(e, v.EFFECT_CLEANUP_FAILED);
1025
1036
  }
1026
1037
  }
1027
1038
  }
1028
1039
  _checkInfiniteLoops() {
1029
- let e = pe();
1030
- this._lastFlushEpoch !== e && (this._lastFlushEpoch = e, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), ge() > a.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++;
1040
+ let e = _e();
1041
+ this._lastFlushEpoch !== e && (this._lastFlushEpoch = e, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), be() > o.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++, f && this._checkFrequencyLimit();
1031
1042
  }
1032
1043
  _checkFrequencyLimit() {
1033
1044
  if (!Number.isFinite(this._maxExecutions)) return;
1034
1045
  let e = Date.now();
1035
- if (e - this._windowStart >= o.EFFECT_FREQUENCY_WINDOW) {
1046
+ if (e - this._windowStart >= c.EFFECT_FREQUENCY_WINDOW) {
1036
1047
  this._windowStart = e, this._windowCount = 1;
1037
1048
  return;
1038
1049
  }
1039
1050
  if (++this._windowCount > this._maxExecutions) {
1040
- let e = new p(h.EFFECT_FREQUENCY_LIMIT_EXCEEDED);
1051
+ let e = new g(v.EFFECT_FREQUENCY_LIMIT_EXCEEDED);
1041
1052
  throw this.dispose(), this._handleExecutionError(e), e;
1042
1053
  }
1043
1054
  }
@@ -1045,27 +1056,26 @@ var De = class extends ne {
1045
1056
  return this._executionCount;
1046
1057
  }
1047
1058
  get isExecuting() {
1048
- return (this.flags & n.EXECUTING) !== 0;
1059
+ return (this.flags & r.EXECUTING) !== 0;
1049
1060
  }
1050
1061
  _throwInfiniteLoopError(e) {
1051
- let t = new p(`Infinite loop detected (${e}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${ue}`);
1062
+ let t = new g(`Infinite loop detected (${e}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${me}`);
1052
1063
  throw this.dispose(), console.error(t), t;
1053
1064
  }
1054
- _handleExecutionError(e, t = h.EFFECT_EXECUTION_FAILED) {
1055
- let n = g(e, p, t);
1065
+ _handleExecutionError(e, t = v.EFFECT_EXECUTION_FAILED) {
1066
+ let n = y(e, g, t);
1056
1067
  if (console.error(n), this._onError) try {
1057
1068
  this._onError(n);
1058
1069
  } catch (e) {
1059
- console.error(g(e, p, h.CALLBACK_ERROR_IN_ERROR_HANDLER));
1070
+ console.error(y(e, g, v.CALLBACK_ERROR_IN_ERROR_HANDLER));
1060
1071
  }
1061
1072
  }
1062
1073
  };
1063
- function I(e, t = {}) {
1064
- if (typeof e != "function") throw new p(h.EFFECT_MUST_BE_FUNCTION);
1065
- let n = new De(e, t);
1074
+ function R(e, t = {}) {
1075
+ if (typeof e != "function") throw new g(v.EFFECT_MUST_BE_FUNCTION);
1076
+ let n = new ke(e, t);
1066
1077
  return n.execute(), n;
1067
1078
  }
1068
- var Oe = /* @__PURE__ */ Symbol.for("atom-effect/atom"), ke = /* @__PURE__ */ Symbol.for("atom-effect/writable");
1069
1079
  function Ae(e, t, n, r) {
1070
1080
  if (n === t.length) return r;
1071
1081
  let i = t[n], a = typeof e == "object" && e ? e : {}, o = a[i], s = Ae(o, t, n + 1, r);
@@ -1079,7 +1089,7 @@ function Ae(e, t, n, r) {
1079
1089
  [i]: s
1080
1090
  };
1081
1091
  }
1082
- function L(e, t) {
1092
+ function z(e, t) {
1083
1093
  let n = e, r = t.length;
1084
1094
  for (let e = 0; e < r; e++) {
1085
1095
  if (n == null) return;
@@ -1093,16 +1103,16 @@ function je(e, t) {
1093
1103
  };
1094
1104
  return {
1095
1105
  get value() {
1096
- return L(e.value, n);
1106
+ return z(e.value, n);
1097
1107
  },
1098
1108
  set value(t) {
1099
1109
  let r = e.peek(), i = Ae(r, n, 0, t);
1100
1110
  i !== r && (e.value = i);
1101
1111
  },
1102
- peek: () => L(e.peek(), n),
1112
+ peek: () => z(e.peek(), n),
1103
1113
  subscribe(t) {
1104
1114
  let i = e.subscribe((e, r) => {
1105
- let i = L(e, n), a = L(r, n);
1115
+ let i = z(e, n), a = z(r, n);
1106
1116
  Object.is(i, a) || t(i, a);
1107
1117
  });
1108
1118
  return r.add(i), () => {
@@ -1112,61 +1122,57 @@ function je(e, t) {
1112
1122
  subscriberCount: () => r.size,
1113
1123
  dispose: i,
1114
1124
  [Symbol.dispose]: i,
1115
- [Oe]: !0,
1116
- [ke]: !0
1125
+ [E]: D.Atom | D.Writable
1117
1126
  };
1118
1127
  }
1119
- var Me = (e, t) => je(e, t), Ne = (e) => (t) => je(e, t), R = (e) => ye(e), Pe = (e) => typeof e == "object" && !!e && typeof e.then == "function";
1120
- function Fe(e) {
1121
- let t = e.localName, n = e.id;
1122
- if (n) return `${t}#${n}`;
1123
- let r = e.className;
1124
- if (typeof r == "string") {
1125
- let e = r.trim();
1126
- if (e) return `${t}.${e.replace(/\s+/g, ".")}`;
1127
- }
1128
- return t;
1128
+ var Me = (e, t) => je(e, t), Ne = (e) => (t) => je(e, t), Pe = (e) => typeof e == "object" && !!e, Fe = (e) => ae(e), Ie = (e) => (Pe(e) || typeof e == "function") && typeof e.then == "function";
1129
+ function Le(e) {
1130
+ let { localName: t, id: n, className: r } = e, i = t;
1131
+ n && (i += `#${n}`);
1132
+ let a = typeof r == "string" ? r : r.baseVal;
1133
+ if (typeof a == "string") {
1134
+ let e = a.trim();
1135
+ e && (i += `.${e.replace(/\s+/g, ".")}`);
1136
+ }
1137
+ let o = e.type;
1138
+ return o && typeof o == "string" && o !== "text" && (i += `.${o}`), i;
1129
1139
  }
1130
- var z = Object.prototype.hasOwnProperty;
1131
- function Ie(e, t) {
1140
+ var B = Object.prototype.hasOwnProperty;
1141
+ function Re(e, t) {
1132
1142
  if (e === t) return !0;
1133
- if (typeof e != "object" || !e || typeof t != "object" || !t) return !1;
1134
- let n = e, r = t, i = 0;
1135
- for (let e in n) if (z.call(n, e)) {
1136
- if (!z.call(r, e) || n[e] !== r[e]) return !1;
1137
- i++;
1138
- }
1139
- let a = 0;
1140
- for (let e in r) z.call(r, e) && a++;
1141
- return i === a;
1143
+ if (!Pe(e) || !Pe(t)) return !1;
1144
+ let n = e, r = t, i = Object.keys(n), a = Object.keys(r);
1145
+ if (i.length !== a.length) return !1;
1146
+ for (let e of i) if (!B.call(r, e) || !Object.is(n[e], r[e])) return !1;
1147
+ return !0;
1142
1148
  }
1143
1149
  //#endregion
1144
1150
  //#region src/constants.ts
1145
- var B = {
1151
+ var V = {
1146
1152
  ROUTE: "[atom-route]",
1147
1153
  BINDING: "[atom-binding]",
1148
1154
  LIST: "[atom-list]",
1149
1155
  MOUNT: "[atom-mount]"
1150
- }, Le = Object.freeze({
1156
+ }, ze = Object.freeze({
1151
1157
  mode: "hash",
1152
1158
  basePath: "",
1153
1159
  autoBindLinks: !1,
1154
1160
  activeClass: "active"
1155
- }), Re = {
1161
+ }), Be = Object.freeze({
1156
1162
  EVENT: "input",
1157
1163
  DEBOUNCE: 0
1158
- }, ze = { HIGHLIGHT_DURATION_MS: 500 }, Be = new Set([
1164
+ }), Ve = Object.freeze({ HIGHLIGHT_DURATION_MS: 500 }), He = new Set([
1159
1165
  "input",
1160
1166
  "select",
1161
1167
  "textarea"
1162
- ]), Ve = new Set([
1168
+ ]), Ue = new Set([
1163
1169
  "innerHTML",
1164
1170
  "outerHTML",
1165
1171
  "srcdoc",
1166
1172
  "__proto__",
1167
1173
  "constructor",
1168
1174
  "prototype"
1169
- ]), V = {
1175
+ ]), We = "(?: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)", H = {
1170
1176
  ROUTE: {
1171
1177
  NOT_FOUND: (e) => `Route "${e}" not found and no notFound route configured`,
1172
1178
  TEMPLATE_NOT_FOUND: (e) => `Template "${e}" not found`,
@@ -1194,24 +1200,44 @@ var B = {
1194
1200
  CLEANUP_ERROR: (e) => `Cleanup error${e ? ` in component <${e}>` : ""}`
1195
1201
  },
1196
1202
  CORE: { EFFECT_DISPOSE_ERROR: (e) => `Effect dispose error${e ? `: ${e}` : ""}` }
1197
- }, He = typeof window < "u", Ue = `${ze.HIGHLIGHT_DURATION_MS / 1e3}s`;
1198
- function We() {
1203
+ }, Ge = "atom-debug-highlight", U = "data-atom-debug", Ke = typeof window < "u", qe = /* @__PURE__ */ new WeakMap(), Je = /* @__PURE__ */ new WeakMap(), Ye = !1, Xe = () => `${Ve.HIGHLIGHT_DURATION_MS / 1e3}s`, Ze = () => `
1204
+ [${U}] {
1205
+ transition: outline ${Xe()} ease-out;
1206
+ }
1207
+ .${Ge} {
1208
+ outline: 2px solid rgba(255, 68, 68, 0.8);
1209
+ outline-offset: 1px;
1210
+ }
1211
+ `.replace(/\s+/g, " ");
1212
+ function Qe() {
1213
+ if (Ye || !Ke) return;
1214
+ if (document.querySelector(`style[${U}]`)) {
1215
+ Ye = !0;
1216
+ return;
1217
+ }
1218
+ let e = document.createElement("style");
1219
+ e.setAttribute(U, ""), e.textContent = Ze(), document.head.appendChild(e), Ye = !0;
1220
+ }
1221
+ function $e() {
1199
1222
  let e = globalThis;
1200
- if (He && e.window?.__ATOM_DEBUG__ === !0) return !0;
1223
+ if (e.__ATOM_DEBUG__ !== void 0) return !!e.__ATOM_DEBUG__;
1201
1224
  try {
1202
- if (e.process?.env?.VITE_ATOM_DEBUG === "true") return !0;
1225
+ if (typeof sessionStorage < "u" && sessionStorage.getItem("__ATOM_DEBUG__") === "true") return !0;
1203
1226
  } catch {}
1204
- return !1;
1227
+ return e.process?.env?.NODE_ENV !== "production" && e.process?.env?.NODE_ENV !== void 0 ? !0 : e.__DEV__ === void 0 ? !1 : !!e.__DEV__;
1205
1228
  }
1206
- var H = new class {
1229
+ var et = class {
1207
1230
  constructor() {
1208
- this._enabled = !1, this._lastState = !1, this.log = () => {}, this.atomChanged = () => {}, this.domUpdated = () => {}, this.cleanup = () => {}, this._enabled = We(), this._lastState = this._enabled, this._applyMethods(this._enabled);
1231
+ this.enabled = !0;
1232
+ }
1233
+ log(e, ...t) {
1234
+ this.enabled && console.log(e, ...t);
1209
1235
  }
1210
- get enabled() {
1211
- return this._enabled;
1236
+ atomChanged(e, t, n, r) {
1237
+ this.enabled && console.log(`${e} Atom "${t ?? "anonymous"}" changed:`, n, "→", r);
1212
1238
  }
1213
- set enabled(e) {
1214
- this._enabled !== e && (this._enabled = e, this._applyMethods(e));
1239
+ cleanup(e, t) {
1240
+ this.enabled && console.log(`${e} Cleanup: ${t}`);
1215
1241
  }
1216
1242
  warn(e, t, ...n) {
1217
1243
  console.warn(`${e} ${t}`, ...n);
@@ -1219,64 +1245,62 @@ var H = new class {
1219
1245
  error(e, t, n) {
1220
1246
  console.error(`${e} ${t}`, n);
1221
1247
  }
1222
- _applyMethods(e) {
1223
- e ? (this.log = (e, ...t) => console.log(e, ...t), this.atomChanged = (e, t, n, r) => console.log(`${e} Atom "${t ?? "anonymous"}" changed:`, n, "→", r), this.domUpdated = (e, t, n, r) => {
1224
- let i = t instanceof Element ? t : t[0];
1225
- i?.isConnected && (console.log(`${e} DOM updated: ${Fe(i)}.${n} =`, r), this._highlightElement(i));
1226
- }, this.cleanup = (e, t) => console.log(`${e} Cleanup: ${t}`)) : (this.log = () => {}, this.atomChanged = () => {}, this.domUpdated = () => {}, this.cleanup = () => {});
1227
- }
1228
- _highlightElement(e) {
1229
- if (!e.isConnected) return;
1230
- Je();
1231
- let t = Xe.get(e), n = Ye.get(e);
1232
- t !== void 0 && cancelAnimationFrame(t), n !== void 0 && (clearTimeout(n), Ye.delete(e)), Xe.set(e, requestAnimationFrame(() => {
1233
- Xe.delete(e), e.isConnected && (e.classList.add(Ge), Ye.set(e, setTimeout(() => {
1234
- e.isConnected && e.classList.remove(Ge), Ye.delete(e);
1235
- }, ze.HIGHLIGHT_DURATION_MS)));
1248
+ domUpdated(e, t, n, r) {
1249
+ if (!this.enabled) return;
1250
+ let i = "jquery" in t ? t[0] : t;
1251
+ i && i.nodeType === 1 && i.isConnected && (console.log(`${e} DOM updated: ${Le(i)}.${n} =`, r), this._triggerVisualHighlight(i));
1252
+ }
1253
+ _triggerVisualHighlight(e) {
1254
+ let t = globalThis, n = t.requestAnimationFrame, r = t.cancelAnimationFrame;
1255
+ if (!Ke || typeof n != "function") return;
1256
+ Qe();
1257
+ let i = Je.get(e), a = qe.get(e);
1258
+ i !== void 0 && typeof r == "function" && r(i), a !== void 0 && (clearTimeout(a), qe.delete(e)), e.hasAttribute(U) || e.setAttribute(U, ""), Je.set(e, n(() => {
1259
+ Je.delete(e), e.isConnected && (e.classList.add(Ge), qe.set(e, setTimeout(() => {
1260
+ e.classList.remove(Ge), qe.delete(e);
1261
+ }, Ve.HIGHLIGHT_DURATION_MS)));
1236
1262
  }));
1237
1263
  }
1238
- }(), Ge = "atom-debug-highlight", Ke = "data-atom-debug", qe = !1;
1239
- function Je() {
1240
- if (qe || !He) return;
1241
- if (document.querySelector(`style[${Ke}]`)) {
1242
- qe = !0;
1243
- return;
1244
- }
1245
- let e = Object.assign(document.createElement("style"), { textContent: `.${Ge}{outline:2px solid rgba(255,68,68,0.8);outline-offset:1px;transition:outline ${Ue} ease-out}` });
1246
- e.setAttribute(Ke, ""), document.head.appendChild(e), qe = !0;
1247
- }
1248
- var Ye = /* @__PURE__ */ new WeakMap(), Xe = /* @__PURE__ */ new WeakMap();
1264
+ }, W = $e() ? new et() : {
1265
+ enabled: !1,
1266
+ log: () => {},
1267
+ atomChanged: () => {},
1268
+ domUpdated: () => {},
1269
+ cleanup: () => {},
1270
+ warn: (e, t, ...n) => console.warn(`${e} ${t}`, ...n),
1271
+ error: (e, t, n) => console.error(`${e} ${t}`, n)
1272
+ };
1249
1273
  //#endregion
1250
1274
  //#region src/core/namespace.ts
1251
- function Ze(e, t) {
1252
- return O(e, t);
1275
+ function tt(e, t) {
1276
+ return Ce(e, t);
1253
1277
  }
1254
- Object.defineProperty(Ze, "debug", {
1278
+ Object.defineProperty(tt, "debug", {
1255
1279
  enumerable: !0,
1256
1280
  configurable: !0,
1257
- get: () => H.enabled,
1281
+ get: () => W.enabled,
1258
1282
  set: (e) => {
1259
- H.enabled = e;
1283
+ W.enabled = e;
1260
1284
  }
1261
1285
  });
1262
- var Qe = () => Promise.resolve();
1286
+ var nt = () => Promise.resolve();
1263
1287
  e.extend({
1264
- atom: Ze,
1265
- computed: F,
1266
- effect: I,
1267
- batch: _e,
1268
- untracked: E,
1269
- isAtom: ye,
1270
- isComputed: be,
1271
- isReactive: R,
1272
- nextTick: Qe,
1288
+ atom: tt,
1289
+ computed: Oe,
1290
+ effect: R,
1291
+ batch: xe,
1292
+ untracked: k,
1293
+ isAtom: ae,
1294
+ isComputed: oe,
1295
+ isReactive: Fe,
1296
+ nextTick: nt,
1273
1297
  atomLens: je,
1274
1298
  composeLens: Me,
1275
1299
  lensFor: Ne
1276
1300
  });
1277
1301
  //#endregion
1278
1302
  //#region src/utils/pool.ts
1279
- var $e = class {
1303
+ var rt = class {
1280
1304
  constructor(e = 50, t = 256) {
1281
1305
  this.limit = e, this.capacity = t, this.pool = [];
1282
1306
  }
@@ -1284,12 +1308,14 @@ var $e = class {
1284
1308
  return this.pool.pop() ?? [];
1285
1309
  }
1286
1310
  release(e) {
1287
- e.length > this.capacity || this.pool.length >= this.limit || Object.isFrozen(e) || (e.length = 0, this.pool.push(e));
1311
+ if (Object.isFrozen(e)) return;
1312
+ let t = e.length;
1313
+ e.length = 0, this.pool.length < this.limit && t <= this.capacity && this.pool.indexOf(e) === -1 && this.pool.push(e);
1288
1314
  }
1289
1315
  reset() {
1290
1316
  this.pool.length = 0;
1291
1317
  }
1292
- }, et = class {
1318
+ }, it = class {
1293
1319
  constructor(e, t, n = 64) {
1294
1320
  this.factory = e, this.reset = t, this.limit = n, this.pool = [];
1295
1321
  }
@@ -1297,7 +1323,7 @@ var $e = class {
1297
1323
  return this.pool.pop() ?? this.factory();
1298
1324
  }
1299
1325
  release(e) {
1300
- this.pool.length < this.limit && (this.reset(e), this.pool.push(e));
1326
+ Object.isFrozen(e) || (this.reset(e), this.pool.length < this.limit && this.pool.indexOf(e) === -1 && this.pool.push(e));
1301
1327
  }
1302
1328
  drain() {
1303
1329
  this.pool.length > 0 && (this.pool.length = 0);
@@ -1305,17 +1331,36 @@ var $e = class {
1305
1331
  get size() {
1306
1332
  return this.pool.length;
1307
1333
  }
1308
- }, tt = new $e(), nt = new $e(), rt = new et(() => ({
1334
+ }, at = 128, ot = new rt(at), st = new rt(at), ct = new it(() => ({
1309
1335
  effects: void 0,
1310
1336
  cleanups: void 0,
1311
1337
  componentCleanup: void 0
1312
1338
  }), (e) => {
1313
- e.effects = void 0, e.cleanups = void 0, e.componentCleanup = void 0;
1314
- }, 128), it = !1;
1315
- function at() {
1316
- it || (it = !0, typeof document < "u" && document.body && ot(document.body));
1339
+ if (e.effects) {
1340
+ let t = e.effects.length;
1341
+ for (let n = 0; n < t; n++) try {
1342
+ e.effects[n].dispose();
1343
+ } catch {}
1344
+ ot.release(e.effects), e.effects = void 0;
1345
+ }
1346
+ if (e.cleanups) {
1347
+ let t = e.cleanups.length;
1348
+ for (let n = 0; n < t; n++) try {
1349
+ e.cleanups[n]();
1350
+ } catch {}
1351
+ st.release(e.cleanups), e.cleanups = void 0;
1352
+ }
1353
+ if (e.componentCleanup) {
1354
+ try {
1355
+ e.componentCleanup();
1356
+ } catch {}
1357
+ e.componentCleanup = void 0;
1358
+ }
1359
+ }, at), lt = !1;
1360
+ function ut() {
1361
+ lt || typeof document < "u" && document.body && (lt = !0, dt(document.body));
1317
1362
  }
1318
- var U = "_aes-bound", W = new class {
1363
+ var G = "_aes-bound", K = new class {
1319
1364
  constructor() {
1320
1365
  this.records = /* @__PURE__ */ new WeakMap(), this.preservedNodes = /* @__PURE__ */ new WeakSet(), this.ignoredNodes = /* @__PURE__ */ new WeakSet();
1321
1366
  }
@@ -1332,17 +1377,17 @@ var U = "_aes-bound", W = new class {
1332
1377
  return this.ignoredNodes.has(e);
1333
1378
  }
1334
1379
  getOrCreateRecord(e) {
1335
- at();
1380
+ ut();
1336
1381
  let t = this.records.get(e);
1337
- return t || (t = rt.acquire(), this.records.set(e, t), e.classList.add(U)), t;
1382
+ return t || (t = ct.acquire(), this.records.set(e, t), e.classList.add(G)), t;
1338
1383
  }
1339
1384
  trackEffect(e, t) {
1340
1385
  let n = this.getOrCreateRecord(e);
1341
- n.effects ||= tt.acquire(), n.effects.push(t);
1386
+ n.effects ||= ot.acquire(), n.effects.push(t);
1342
1387
  }
1343
1388
  trackCleanup(e, t) {
1344
1389
  let n = this.getOrCreateRecord(e);
1345
- n.cleanups ||= nt.acquire(), n.cleanups.push(t);
1390
+ n.cleanups ||= st.acquire(), n.cleanups.push(t);
1346
1391
  }
1347
1392
  setComponentCleanup(e, t) {
1348
1393
  this.getOrCreateRecord(e).componentCleanup = t;
@@ -1351,54 +1396,58 @@ var U = "_aes-bound", W = new class {
1351
1396
  return this.records.has(e);
1352
1397
  }
1353
1398
  cleanup(e) {
1354
- let t = e.nodeType === 1, n = this.records.get(e);
1355
- if (this.preservedNodes.delete(e), this.ignoredNodes.delete(e), !n) {
1356
- t && e.classList.remove(U);
1399
+ if (this.preservedNodes.delete(e), this.ignoredNodes.delete(e), e.nodeType !== 1) return;
1400
+ let t = e, n = this.records.get(t);
1401
+ if (!n) {
1402
+ t.classList.remove(G);
1357
1403
  return;
1358
1404
  }
1359
- this.records.delete(e), t && e.classList.remove(U);
1360
- let r = t ? Fe(e) : e.nodeName || "Node";
1361
- if (H.cleanup(B.BINDING, r), n.componentCleanup) try {
1362
- n.componentCleanup();
1363
- } catch (e) {
1364
- H.error(B.MOUNT, V.MOUNT.CLEANUP_ERROR(r), e);
1405
+ this.records.delete(t), t.classList.remove(G);
1406
+ let r = Le(t);
1407
+ if (W.cleanup(V.BINDING, r), n.componentCleanup) {
1408
+ try {
1409
+ n.componentCleanup();
1410
+ } catch (e) {
1411
+ W.error(V.MOUNT, H.MOUNT.CLEANUP_ERROR(r), e);
1412
+ }
1413
+ n.componentCleanup = void 0;
1365
1414
  }
1366
1415
  if (n.effects) {
1367
1416
  for (let e of n.effects) try {
1368
1417
  e.dispose();
1369
1418
  } catch (e) {
1370
- H.error(B.BINDING, V.CORE.EFFECT_DISPOSE_ERROR(r), e);
1419
+ W.error(V.BINDING, H.CORE.EFFECT_DISPOSE_ERROR(r), e);
1371
1420
  }
1372
- tt.release(n.effects), n.effects = void 0;
1421
+ ot.release(n.effects), n.effects = void 0;
1373
1422
  }
1374
1423
  if (n.cleanups) {
1375
1424
  for (let e of n.cleanups) try {
1376
1425
  e();
1377
1426
  } catch (e) {
1378
- H.error(B.BINDING, V.BINDING.CLEANUP_ERROR(r), e);
1427
+ W.error(V.BINDING, H.BINDING.CLEANUP_ERROR(r), e);
1379
1428
  }
1380
- nt.release(n.cleanups), n.cleanups = void 0;
1429
+ st.release(n.cleanups), n.cleanups = void 0;
1381
1430
  }
1382
- rt.release(n);
1431
+ ct.release(n);
1383
1432
  }
1384
1433
  cleanupDescendants(e) {
1385
- let t = e.getElementsByClassName ? e.getElementsByClassName(U) : e.querySelectorAll(`.${U}`), n = t.length;
1434
+ let t = "getElementsByClassName" in e ? e.getElementsByClassName(G) : e.querySelectorAll(`.${G}`), n = t.length;
1386
1435
  if (n === 0) return;
1387
1436
  let r = Array(n);
1388
1437
  for (let e = 0; e < n; e++) r[e] = t[e];
1389
1438
  for (let e = n - 1; e >= 0; e--) {
1390
1439
  let t = r[e];
1391
- this.records.has(t) ? this.cleanup(t) : t.classList.remove(U);
1440
+ this.records.has(t) ? this.cleanup(t) : t.classList.remove(G);
1392
1441
  }
1393
1442
  }
1394
1443
  cleanupTree(e) {
1395
1444
  (e.nodeType === 1 || e.nodeType === 11) && this.cleanupDescendants(e), this.cleanup(e);
1396
1445
  }
1397
- }(), G = /* @__PURE__ */ new Map();
1398
- function ot(e) {
1399
- if (G.has(e)) return;
1446
+ }(), q = /* @__PURE__ */ new Map();
1447
+ function dt(e) {
1448
+ if (q.has(e)) return;
1400
1449
  let t = new MutationObserver((e) => {
1401
- let t = W;
1450
+ let t = K;
1402
1451
  for (let n = 0, r = e.length; n < r; n++) {
1403
1452
  let r = e[n].removedNodes;
1404
1453
  for (let e = 0, n = r.length; e < n; e++) {
@@ -1412,197 +1461,249 @@ function ot(e) {
1412
1461
  t.observe(e, {
1413
1462
  childList: !0,
1414
1463
  subtree: !0
1415
- }), G.set(e, t);
1464
+ }), q.set(e, t);
1416
1465
  }
1417
- function st() {
1418
- G.forEach((e) => e.disconnect()), G.clear();
1466
+ function ft() {
1467
+ q.forEach((e) => e.disconnect()), q.clear();
1468
+ }
1469
+ //#endregion
1470
+ //#region src/core/dom.ts
1471
+ function pt(e) {
1472
+ return {
1473
+ el: e,
1474
+ trackCleanup: (t) => K.trackCleanup(e, t)
1475
+ };
1476
+ }
1477
+ function J(e, t, n = {}) {
1478
+ for (let r = 0, i = e.length; r < i; r++) {
1479
+ let i = e[r];
1480
+ if (i?.nodeType === 1) {
1481
+ let e = i;
1482
+ t(n.needsCtx ? pt(e) : null, e);
1483
+ } else i && W.log(V.BINDING, `Skipping non-Element node (nodeType=${i.nodeType})`);
1484
+ }
1485
+ return e;
1486
+ }
1487
+ function mt(e) {
1488
+ return Array.isArray(e) && e.length === 2 && (typeof e[0] == "function" || e[0] !== null && typeof e[0] == "object" && ("value" in e[0] || "then" in e[0])) ? e : [e];
1419
1489
  }
1420
1490
  //#endregion
1421
1491
  //#region src/core/jquery-patch.ts
1422
- var K = Symbol("atom-effect-internal"), q = /* @__PURE__ */ new WeakMap(), J = null, ct = (e) => {
1423
- if (e[K]) return e;
1424
- let t = q.get(e);
1425
- return t || (t = function(...t) {
1426
- return _e(() => e.apply(this, t));
1427
- }, t[K] = !0, q.set(e, t)), t;
1428
- };
1429
- function lt(e) {
1492
+ var Y = Symbol.for("atom-effect-internal"), ht = Symbol.for("atom-effect-wrapped"), gt = /* @__PURE__ */ new WeakMap(), X = null, _t = (e) => {
1493
+ let t = e;
1494
+ if (t[Y]) return e;
1495
+ let n = t[ht];
1496
+ if (n) return n;
1497
+ if (n = gt.get(e), !n) {
1498
+ n = function(...t) {
1499
+ return xe(() => e.apply(this, t));
1500
+ }, n[Y] = !0, gt.set(e, n);
1501
+ try {
1502
+ t[ht] = n;
1503
+ } catch {}
1504
+ }
1505
+ return n;
1506
+ }, vt = (e) => e[ht] ?? gt.get(e) ?? e;
1507
+ function yt(e) {
1430
1508
  let t = {};
1431
- for (let n in e) e[n] && (t[n] = ct(e[n]));
1509
+ for (let n in e) {
1510
+ let r = e[n];
1511
+ typeof r == "function" ? t[n] = _t(r) : r !== void 0 && (t[n] = r);
1512
+ }
1432
1513
  return t;
1433
1514
  }
1434
- function ut(e) {
1515
+ function bt(e) {
1435
1516
  let t = {};
1436
1517
  for (let n in e) {
1437
1518
  let r = e[n];
1438
- t[n] = r ? q.get(r) ?? r : void 0;
1519
+ typeof r == "function" ? t[n] = vt(r) : t[n] = r;
1439
1520
  }
1440
1521
  return t;
1441
1522
  }
1442
- function dt() {
1443
- if (J !== null) return;
1444
- J = {
1523
+ function xt(e, t, n) {
1524
+ let r = e[0];
1525
+ if (r && typeof r == "object") e[0] = t(r);
1526
+ else for (let t = 1; t < e.length; t++) typeof e[t] == "function" && (e[t] = n(e[t]));
1527
+ }
1528
+ function St(e) {
1529
+ return function(...t) {
1530
+ return xt(t, yt, _t), e.apply(this, t) ?? this;
1531
+ };
1532
+ }
1533
+ function Ct() {
1534
+ if (X !== null) return;
1535
+ X = {
1445
1536
  on: e.fn.on,
1537
+ one: e.fn.one,
1446
1538
  off: e.fn.off,
1447
1539
  remove: e.fn.remove,
1448
1540
  empty: e.fn.empty,
1449
1541
  detach: e.fn.detach
1450
1542
  };
1451
- let t = J;
1543
+ let t = X;
1452
1544
  e.fn.remove = function(e) {
1453
1545
  let n = e ? this.filter(e) : this, r = n.length;
1454
1546
  for (let e = 0; e < r; e++) {
1455
1547
  let t = n[e];
1456
- t && (W.markIgnored(t), W.cleanupTree(t));
1548
+ t && (K.markIgnored(t), K.cleanupTree(t));
1457
1549
  }
1458
1550
  return t.remove.call(this, e) ?? this;
1459
1551
  }, e.fn.empty = function() {
1460
1552
  let e = this.length;
1461
1553
  for (let t = 0; t < e; t++) {
1462
1554
  let e = this[t];
1463
- e?.hasChildNodes() && W.cleanupDescendants(e);
1555
+ e?.hasChildNodes() && K.cleanupDescendants(e);
1464
1556
  }
1465
1557
  return t.empty.call(this) ?? this;
1466
1558
  }, e.fn.detach = function(e) {
1467
1559
  let n = e ? this.filter(e) : this, r = n.length;
1468
1560
  for (let e = 0; e < r; e++) {
1469
1561
  let t = n[e];
1470
- t && W.keep(t);
1562
+ t && K.keep(t);
1471
1563
  }
1472
1564
  return t.detach.call(this, e) ?? this;
1473
- }, e.fn.on = function(...e) {
1474
- let n = e[0];
1475
- if (n && typeof n == "object") e[0] = lt(n);
1476
- else {
1477
- let t = e.length - 1;
1478
- t >= 0 && typeof e[t] == "function" && (e[t] = ct(e[t]));
1479
- }
1480
- return t.on.apply(this, e) ?? this;
1481
- }, e.fn.off = function(...e) {
1482
- let n = e[0];
1483
- if (n && typeof n == "object") e[0] = ut(n);
1484
- else {
1485
- let t = e.length - 1;
1486
- if (t >= 0 && typeof e[t] == "function") {
1487
- let n = e[t];
1488
- e[t] = q.get(n) ?? n;
1489
- }
1490
- }
1491
- return t.off.apply(this, e) ?? this;
1565
+ }, e.fn.on = St(t.on), e.fn.one = St(t.one), e.fn.off = function(...e) {
1566
+ return xt(e, bt, vt), t.off.apply(this, e) ?? this;
1492
1567
  };
1493
1568
  }
1494
- function ft() {
1495
- 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);
1569
+ function wt() {
1570
+ X !== null && (e.fn.on = X.on, e.fn.one = X.one, e.fn.off = X.off, e.fn.remove = X.remove, e.fn.empty = X.empty, e.fn.detach = X.detach, X = null);
1496
1571
  }
1497
1572
  //#endregion
1498
1573
  //#region src/types.ts
1499
- var Y = /* @__PURE__ */ function(e) {
1574
+ var Z = /* @__PURE__ */ function(e) {
1500
1575
  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;
1501
- }({}), pt = 0;
1502
- function mt(e) {
1503
- e[K] = !0;
1576
+ }({}), Tt = 0;
1577
+ function Et(e) {
1578
+ e[Y] = !0;
1504
1579
  }
1505
- var ht = class {
1580
+ var Dt = class {
1506
1581
  constructor(e, t, n) {
1507
1582
  this.flags = 0, this.timeoutId = void 0, this.handleCompositionStart = () => {
1508
- this.flags |= Y.Composing;
1583
+ this.flags |= Z.Composing;
1509
1584
  }, this.handleCompositionEnd = () => {
1510
- this.flags &= ~Y.Composing, this.handleInput();
1585
+ this.flags &= ~Z.Composing, this.handleInput();
1511
1586
  }, this.handleFocus = () => {
1512
- this.flags |= Y.Focused;
1587
+ this.flags |= Z.Focused;
1513
1588
  }, this.handleBlur = () => {
1514
- this.flags &= ~Y.Focused;
1515
- let e = !!(this.flags & Y.Composing);
1516
- this.flags &= ~Y.Composing, this.flushPendingDebounce(), e && this.timeoutId === void 0 && this.syncAtomFromDom(), this.normalizeDomValue();
1589
+ this.flags &= ~Z.Focused;
1590
+ let e = !!(this.flags & Z.Composing);
1591
+ this.flags &= ~Z.Composing;
1592
+ let t = this.flushPendingDebounce();
1593
+ e && !t && this.syncAtomFromDom(), this.normalizeDomValue();
1517
1594
  }, this.syncDomFromAtom = () => {
1518
1595
  let e = this.atom.value;
1519
- E(() => {
1520
- let t = this.format(e), n = this.getRawDom();
1521
- if (this.isMultipleSelect) {
1522
- if (this.equal(n, e)) return;
1523
- } else if (n === t) return;
1524
- if (this.flags & Y.Focused) try {
1525
- if (this.equal(this.readDom(), e)) return;
1526
- } catch {}
1527
- this.flags |= Y.SyncingToDom;
1596
+ this.flags & Z.Busy || k(() => {
1597
+ if (this.isDomUpToDate(e)) return;
1598
+ let t = this.format(e);
1599
+ this.flags |= Z.SyncingToDom;
1528
1600
  try {
1529
- this.writeDom(e, t), H.domUpdated(B.BINDING, this.$el, "val", t);
1601
+ this.writeDom(e, t), W.domUpdated(V.BINDING, this.$el, "val", t);
1530
1602
  } finally {
1531
- this.flags &= ~Y.SyncingToDom;
1603
+ this.flags &= ~Z.SyncingToDom;
1532
1604
  }
1533
1605
  });
1534
1606
  }, this.cleanup = () => {
1535
1607
  this.$el.off(this.ns), clearTimeout(this.timeoutId), this.timeoutId = void 0;
1536
1608
  }, this.$el = e, this.el = e[0], this.atom = t;
1537
- let r = this.el.tagName, i = r === "SELECT" && this.el.multiple;
1538
- this.isMultipleSelect = i, this.isTextControl = r === "INPUT" || r === "TEXTAREA", this.ns = `.atomBind-${++pt}`;
1539
- let a = n.debounce ?? 0;
1540
- this.parse = n.parse ?? ((e) => e), i ? (this.format = n.format ?? ((e) => (Array.isArray(e) ? e : e ? [String(e)] : []).join(",")), this.getRawDom = () => this.$el.val() || [], this.readDom = () => this.getRawDom(), this.writeDom = (e) => {
1541
- this.$el.val(e);
1542
- }) : (this.format = n.format ?? ((e) => String(e ?? "")), this.getRawDom = () => this.el.value, this.readDom = () => this.parse(this.el.value), this.isTextControl ? this.writeDom = (e, t) => {
1543
- if (this.flags & Y.Focused) try {
1544
- let e = this.el, n = e.selectionStart, r = e.selectionEnd;
1545
- e.value = t;
1546
- let i = t.length;
1547
- n !== null && r !== null && e.setSelectionRange(n < i ? n : i, r < i ? r : i);
1548
- } catch {
1549
- this.el.value = t;
1550
- }
1551
- else this.el.value = t;
1552
- } : this.writeDom = (e, t) => {
1553
- this.el.value = t;
1554
- });
1555
- let o = n.equal ?? Object.is;
1556
- i ? this.equal = (e, t) => {
1557
- if (o(e, t)) return !0;
1558
- if (Array.isArray(e) && Array.isArray(t)) {
1559
- let n = e.length;
1560
- if (n !== t.length) return !1;
1561
- for (let r = 0; r < n; r++) if (!Object.is(e[r], t[r])) return !1;
1562
- return !0;
1563
- }
1564
- return !1;
1565
- } : this.equal = o, a > 0 ? this.handleInput = () => {
1566
- this.flags & Y.Composing || (clearTimeout(this.timeoutId), this.timeoutId = setTimeout(() => this.syncAtomFromDom(), a));
1609
+ let r = this.el.tagName;
1610
+ this.isMultipleSelect = r === "SELECT" && this.el.multiple, this.isTextControl = r === "INPUT" || r === "TEXTAREA", this.ns = `.atomBind-${++Tt}`;
1611
+ let { parse: i, format: a, equal: o, readDom: s, getRawDom: c, writeDom: l } = this.initStrategies(n);
1612
+ this.parse = i, this.format = a, this.equal = o, this.readDom = s, this.getRawDom = c, this.writeDom = l;
1613
+ let u = n.debounce ?? 0;
1614
+ u > 0 ? this.handleInput = () => {
1615
+ this.flags & Z.Composing || (clearTimeout(this.timeoutId), this.timeoutId = setTimeout(() => this.syncAtomFromDom(), u));
1567
1616
  } : this.handleInput = () => {
1568
- this.flags & Y.Composing || this.syncAtomFromDom();
1617
+ this.flags & Z.Composing || this.syncAtomFromDom();
1569
1618
  }, [
1570
1619
  this.handleFocus,
1571
1620
  this.handleBlur,
1572
1621
  this.handleCompositionStart,
1573
1622
  this.handleCompositionEnd,
1574
1623
  this.handleInput
1575
- ].forEach(mt), this.bindEvents(n.event ?? Re.EVENT);
1624
+ ].forEach(Et), this.bindEvents(n.event ?? Be.EVENT);
1625
+ }
1626
+ initStrategies(e) {
1627
+ let t = e.parse ?? ((e) => e), n = e.equal ?? Object.is;
1628
+ return this.isMultipleSelect ? {
1629
+ parse: t,
1630
+ format: e.format ?? ((e) => (Array.isArray(e) ? e : e ? [String(e)] : []).join(",")),
1631
+ getRawDom: () => this.$el.val() || [],
1632
+ readDom: () => this.$el.val() || [],
1633
+ writeDom: (e) => {
1634
+ this.$el.val(e);
1635
+ },
1636
+ equal: (e, t) => {
1637
+ if (n(e, t)) return !0;
1638
+ if (Array.isArray(e) && Array.isArray(t)) {
1639
+ let n = e.length;
1640
+ if (n !== t.length) return !1;
1641
+ for (let r = 0; r < n; r++) if (!Object.is(e[r], t[r])) return !1;
1642
+ return !0;
1643
+ }
1644
+ return !1;
1645
+ }
1646
+ } : {
1647
+ parse: t,
1648
+ format: e.format ?? ((e) => String(e ?? "")),
1649
+ equal: n,
1650
+ readDom: () => t(this.el.value),
1651
+ getRawDom: () => this.el.value,
1652
+ writeDom: this.isTextControl ? (e, t) => this.writeTextValue(t) : (e, t) => {
1653
+ this.el.value = t;
1654
+ }
1655
+ };
1656
+ }
1657
+ writeTextValue(e) {
1658
+ let t = this.el;
1659
+ if (this.flags & Z.Focused) try {
1660
+ let n = t.selectionStart, r = t.selectionEnd;
1661
+ t.value = e;
1662
+ let i = e.length;
1663
+ n !== null && r !== null && t.setSelectionRange(Math.min(n, i), Math.min(r, i));
1664
+ } catch {
1665
+ t.value = e;
1666
+ }
1667
+ else t.value = e;
1576
1668
  }
1577
1669
  flushPendingDebounce() {
1578
- this.timeoutId !== void 0 && (clearTimeout(this.timeoutId), this.timeoutId = void 0, this.syncAtomFromDom());
1670
+ return this.timeoutId === void 0 ? !1 : (clearTimeout(this.timeoutId), this.timeoutId = void 0, this.syncAtomFromDom(), !0);
1579
1671
  }
1580
1672
  normalizeDomValue() {
1581
1673
  let e = this.atom.peek(), t = this.format(e), n = this.getRawDom();
1582
1674
  this.isMultipleSelect ? this.equal(n, e) || this.writeDom(e, t) : n !== t && this.writeDom(e, t);
1583
1675
  }
1584
1676
  syncAtomFromDom() {
1585
- if (!(this.flags & Y.Busy)) {
1586
- this.flags |= Y.SyncingToAtom;
1677
+ if (!(this.flags & Z.Busy)) {
1678
+ this.flags |= Z.SyncingToAtom;
1587
1679
  try {
1588
1680
  let e = this.readDom();
1589
1681
  this.equal(this.atom.peek(), e) || (this.atom.value = e);
1590
1682
  } catch (e) {
1591
- H.warn(B.BINDING, V.BINDING.PARSE_ERROR(e instanceof Error ? e.message : String(e)), e);
1683
+ W.warn(V.BINDING, H.BINDING.PARSE_ERROR(e instanceof Error ? e.message : String(e)), e);
1592
1684
  } finally {
1593
- this.flags &= ~Y.SyncingToAtom;
1685
+ this.flags &= ~Z.SyncingToAtom;
1594
1686
  }
1595
1687
  }
1596
1688
  }
1689
+ isDomUpToDate(e) {
1690
+ let t = this.getRawDom();
1691
+ if (this.isMultipleSelect) return this.equal(t, e);
1692
+ if (t === this.format(e)) return !0;
1693
+ if (this.flags & Z.Focused) try {
1694
+ return this.equal(this.readDom(), e);
1695
+ } catch {}
1696
+ return !1;
1697
+ }
1597
1698
  bindEvents(e) {
1598
1699
  let t = this.ns, n = e.trim().split(/\s+/).map((e) => `${e}${t}`).join(" ");
1599
1700
  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);
1600
1701
  }
1601
1702
  };
1602
- function gt(e, t, n) {
1603
- let r = new ht(e, t, n);
1703
+ function Ot(e, t, n) {
1704
+ let r = new Dt(e, t, n);
1604
1705
  return {
1605
- fx: I(r.syncDomFromAtom),
1706
+ fx: R(r.syncDomFromAtom),
1606
1707
  cleanup: () => {
1607
1708
  r &&= (r.cleanup(), null);
1608
1709
  }
@@ -1610,88 +1711,114 @@ function gt(e, t, n) {
1610
1711
  }
1611
1712
  //#endregion
1612
1713
  //#region src/core/effect-factory.ts
1613
- function _t(e, t, n, r) {
1614
- let i = null, a = (t) => {
1615
- if (!Pe(t)) {
1616
- i = null;
1617
- try {
1618
- n(t), H.domUpdated(B.BINDING, e, r, t);
1619
- } catch (e) {
1620
- H.error(B.BINDING, V.BINDING.UPDATER_ERROR(r, !0), e);
1621
- }
1714
+ function kt(e, t, n, r) {
1715
+ let i = {
1716
+ latestId: 0,
1717
+ isDisposed: !1
1718
+ };
1719
+ K.trackCleanup(e, () => {
1720
+ i.isDisposed = !0;
1721
+ });
1722
+ let a = (t) => {
1723
+ if (!Ie(t)) {
1724
+ i.latestId++, k(() => {
1725
+ try {
1726
+ n(t), W.domUpdated(V.BINDING, e, r, t);
1727
+ } catch (e) {
1728
+ W.error(V.BINDING, H.BINDING.UPDATER_ERROR(r, !0), e);
1729
+ }
1730
+ });
1622
1731
  return;
1623
1732
  }
1624
- i = t, t.then((a) => {
1625
- i === t && E(() => {
1733
+ let a = ++i.latestId;
1734
+ t.then((t) => {
1735
+ a === i.latestId && !i.isDisposed && k(() => {
1626
1736
  try {
1627
- n(a), H.domUpdated(B.BINDING, e, `${r} (async)`, a);
1737
+ n(t), W.domUpdated(V.BINDING, e, `${r} (async)`, t);
1628
1738
  } catch (e) {
1629
- H.error(B.BINDING, V.BINDING.UPDATER_ERROR(r), e);
1739
+ W.error(V.BINDING, H.BINDING.UPDATER_ERROR(r), e);
1630
1740
  }
1631
1741
  });
1632
1742
  }).catch((e) => {
1633
- i === t && H.error(B.BINDING, V.BINDING.UPDATER_ERROR(r), e);
1743
+ a === i.latestId && !i.isDisposed && W.error(V.BINDING, H.BINDING.UPDATER_ERROR(r), e);
1634
1744
  });
1635
- }, o = R(t);
1636
- o || typeof t == "function" ? W.trackEffect(e, I(() => {
1637
- let e = o ? t.value : t();
1638
- E(() => a(e));
1639
- }, { name: r })) : E(() => a(t));
1745
+ }, o = Fe(t);
1746
+ o || typeof t == "function" ? K.trackEffect(e, R(() => {
1747
+ a(o ? t.value : t());
1748
+ }, { name: r })) : a(t);
1640
1749
  }
1641
- function X(e, t, n, r) {
1750
+ function At(e, t, n, r) {
1642
1751
  let i = Object.keys(t), a = [], o = [], s = [], c = {};
1643
1752
  for (let e = 0, n = i.length; e < n; e++) {
1644
- let n = i[e], r = t[n], l = R(r);
1753
+ let n = i[e], r = t[n], l = Fe(r);
1645
1754
  l || typeof r == "function" ? (a.push(n), o.push(r), s.push(l)) : c[n] = r;
1646
1755
  }
1647
- let l = 0, u = (t) => {
1756
+ let l = {
1757
+ latestId: 0,
1758
+ isDisposed: !1,
1759
+ cache: {}
1760
+ };
1761
+ K.trackCleanup(e, () => {
1762
+ l.isDisposed = !0;
1763
+ });
1764
+ let u = (t) => {
1648
1765
  let a = [], o = {}, s = i.length;
1649
1766
  for (let e = 0; e < s; e++) {
1650
1767
  let n = i[e], r = t[n];
1651
- Pe(r) ? a.push(r.then((e) => ({
1768
+ if (Ie(r) && B.call(l.cache, n)) {
1769
+ let e = l.cache[n];
1770
+ if (e.p === r) {
1771
+ o[n] = e.v;
1772
+ continue;
1773
+ }
1774
+ }
1775
+ Ie(r) ? a.push(r.then((e) => (l.cache[n] = {
1776
+ p: r,
1777
+ v: e
1778
+ }, {
1652
1779
  key: n,
1653
1780
  val: e
1654
1781
  }))) : o[n] = r;
1655
1782
  }
1656
- let c = a.length;
1657
- if (c > 0) {
1658
- let t = ++l;
1783
+ if (a.length > 0) {
1784
+ let t = ++l.latestId;
1659
1785
  Promise.all(a).then((i) => {
1660
- if (t === l) {
1661
- for (let e = 0; e < c; e++) {
1786
+ if (t === l.latestId && !l.isDisposed) {
1787
+ for (let e = 0, t = i.length; e < t; e++) {
1662
1788
  let t = i[e];
1663
1789
  o[t.key] = t.val;
1664
1790
  }
1665
- E(() => {
1791
+ k(() => {
1666
1792
  try {
1667
- n(o), H.domUpdated(B.BINDING, e, `${r} (async)`, o);
1793
+ n(o), W.domUpdated(V.BINDING, e, `${r} (async)`, o);
1668
1794
  } catch (e) {
1669
- H.error(B.BINDING, V.BINDING.UPDATER_ERROR(r), e);
1795
+ W.error(V.BINDING, H.BINDING.UPDATER_ERROR(r), e);
1670
1796
  }
1671
1797
  });
1672
1798
  }
1799
+ }, (e) => {
1800
+ t === l.latestId && !l.isDisposed && W.error(V.BINDING, H.BINDING.UPDATER_ERROR(r), e);
1673
1801
  });
1674
- } else {
1675
- l++;
1802
+ } else l.latestId++, k(() => {
1676
1803
  try {
1677
- n(o), H.domUpdated(B.BINDING, e, r, o);
1804
+ n(o), W.domUpdated(V.BINDING, e, r, o);
1678
1805
  } catch (e) {
1679
- H.error(B.BINDING, V.BINDING.UPDATER_ERROR(r, !0), e);
1806
+ W.error(V.BINDING, H.BINDING.UPDATER_ERROR(r, !0), e);
1680
1807
  }
1681
- }
1808
+ });
1682
1809
  };
1683
- a.length > 0 ? W.trackEffect(e, I(() => {
1810
+ a.length > 0 ? K.trackEffect(e, R(() => {
1684
1811
  let e = { ...c };
1685
1812
  for (let t = 0, n = a.length; t < n; t++) {
1686
1813
  let n = o[t];
1687
1814
  e[a[t]] = s[t] ? n.value : n();
1688
1815
  }
1689
- E(() => u(e));
1690
- }, { name: r })) : E(() => u(c));
1816
+ u(e);
1817
+ }, { name: r })) : u(c);
1691
1818
  }
1692
1819
  //#endregion
1693
1820
  //#region src/utils/sanitize.ts
1694
- var vt = new Set([
1821
+ var jt = new Set([
1695
1822
  "href",
1696
1823
  "src",
1697
1824
  "action",
@@ -1705,116 +1832,139 @@ var vt = new Set([
1705
1832
  "profile",
1706
1833
  "usemap",
1707
1834
  "classid",
1708
- "codebase"
1709
- ]), yt = /^\s*(?:javascript|vbscript)\s*:/i, bt = /(?: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, xt = /url\s*\(\s*(?:["']?\s*)?(?:javascript|vbscript)\s*:/i, St = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, Ct = /&#x([0-9a-f]+);?|&#([0-9]+);?/gi, wt = {
1835
+ "codebase",
1836
+ "fill",
1837
+ "filter",
1838
+ "mask",
1839
+ "marker-start",
1840
+ "marker-mid",
1841
+ "marker-end",
1842
+ "clip-path"
1843
+ ]), Mt = {
1710
1844
  colon: ":",
1711
1845
  Tab: " ",
1712
1846
  NewLine: "\n"
1713
- }, Tt = /&(colon|Tab|NewLine);/g, Et = /<\?[\s\S]*?\?>/g, Dt = /(<(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, Ot = /(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, kt = /data\s*:\s*(?:text\/(?:html|javascript|vbscript|xml)|application\/(?:javascript|xhtml\+xml|xml|x-shockwave-flash)|image\/svg\+xml)/gi, At = /\bon\w+\s*=/gim, jt = new RegExp(bt.source, "gim");
1714
- function Mt(e) {
1715
- let t = e.length;
1716
- for (let n = 0; n < t; n++) {
1717
- let t = e.charCodeAt(n);
1718
- if (t === 60 || t === 38 || t <= 31 && t !== 9 && t !== 10 && t !== 13) return !0;
1719
- }
1720
- if (e.indexOf(":") !== -1) return !0;
1721
- let n = e.toLowerCase(), r = n.indexOf("on");
1722
- if (r !== -1 && r < t - 2) {
1723
- let e = n.charCodeAt(r + 2);
1847
+ }, Nt = /&#x([0-9a-f]+);?|&#([0-9]+);?/gi, Pt = /&(colon|Tab|NewLine);/g, Ft = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, It = /[<&\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/, Lt = /<\?[\s\S]*?\?>/g, Rt = /(<(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, zt = /\bon\w+\s*=/gim, Bt = /data\s*:\s*(?:text\/(?:html|javascript|vbscript|xml)|application\/(?:javascript|xhtml\+xml|xml|x-shockwave-flash)|image\/svg\+xml)/gi, Vt = RegExp(`${We}\\s*:`, "gi"), Ht = RegExp(`^\\s*${We}\\s*:`, "i"), Ut = `(?:expression\\s*\\(|behavior\\s*:|-moz-binding\\s*:|(?:\\\\[0-9a-f]{1,6}\\s*|[\\s\\x00-\\x20/'"])*${We}\\s*:(?!image\\/)|data\\s*:\\s*(?!image\\/))`, Wt = new RegExp(Ut, "gim"), Gt = new RegExp(Ut, "im"), Kt = RegExp(`url\\s*\\(\\s*(?:["']?\\s*)?${We}\\s*:`, "i");
1848
+ function qt(e) {
1849
+ return e.replace(Nt, (e, t, n) => {
1850
+ let r = t ? parseInt(t, 16) : parseInt(n, 10);
1851
+ return r >= 0 && r <= 1114111 ? String.fromCodePoint(r) : "";
1852
+ }).replace(Pt, (e, t) => Mt[t] ?? "").replace(Ft, "");
1853
+ }
1854
+ function Jt(e) {
1855
+ return Ht.test(e) || new RegExp(Bt.source, "i").test(e);
1856
+ }
1857
+ function Yt(e) {
1858
+ return e.toLowerCase().includes("url(") && Kt.test(e) || Gt.test(e);
1859
+ }
1860
+ function Xt(e) {
1861
+ if (It.test(e) || e.indexOf(":") !== -1) return !0;
1862
+ let t = e.toLowerCase(), n = t.indexOf("on");
1863
+ for (; n !== -1 && n < e.length - 2;) {
1864
+ let e = t.charCodeAt(n + 2);
1724
1865
  if (e >= 97 && e <= 122) return !0;
1866
+ n = t.indexOf("on", n + 1);
1725
1867
  }
1726
1868
  return !1;
1727
1869
  }
1728
- function Z(e) {
1870
+ function Q(e) {
1729
1871
  if (!e) return "";
1730
1872
  let t = String(e);
1731
- if (!Mt(t)) return t;
1732
- let n = t.replace(St, "").replace(Ct, (e, t, n) => String.fromCodePoint(t ? parseInt(t, 16) : parseInt(n, 10))).replace(Tt, (e, t) => wt[t] ?? "");
1873
+ if (!Xt(t)) return t;
1874
+ let n = qt(t);
1733
1875
  if (n.indexOf("<") !== -1) {
1734
- n = n.replace(Et, "");
1876
+ n = n.replace(Lt, "");
1735
1877
  let e;
1736
1878
  do
1737
- e = n, n = n.replace(Dt, "");
1879
+ e = n, n = n.replace(Rt, "");
1738
1880
  while (n !== e);
1739
1881
  }
1740
- return n.replace(Ot, "data-unsafe-protocol:").replace(kt, "data-unsafe-protocol:").replace(At, "data-unsafe-attr=").replace(jt, "data-unsafe-css:");
1882
+ return n.replace(Wt, "data-unsafe-css:").replace(Vt, "data-unsafe-protocol:").replace(Bt, "data-unsafe-protocol:").replace(zt, "data-unsafe-attr=");
1741
1883
  }
1742
- var Nt = (e) => e.length < 15 ? !1 : e.toLowerCase().includes("url(") && xt.test(e), Pt = /* @__PURE__ */ new Map();
1743
- function Ft(e) {
1744
- let t = Pt.get(e);
1745
- return t === void 0 ? (t = e.includes("-") ? e.replace(/-./g, (e) => e[1].toUpperCase()) : e, Pt.set(e, t), t) : t;
1884
+ var Zt = (e, t) => {
1885
+ let n = e.toLowerCase();
1886
+ return jt.has(n) ? Jt(qt(t)) : !1;
1887
+ }, Qt = (e) => Yt(qt(e)), $t = /* @__PURE__ */ new Map();
1888
+ function en(e) {
1889
+ let t = $t.get(e);
1890
+ return t === void 0 ? (t = e.includes("-") ? e.replace(/-./g, (e) => e[1].toUpperCase()) : e, $t.set(e, t), t) : t;
1746
1891
  }
1747
- var It = /* @__PURE__ */ new WeakMap();
1748
- function Lt(e) {
1749
- let t = It.get(e);
1750
- return t || (t = F(() => {
1892
+ var tn = /* @__PURE__ */ new WeakMap();
1893
+ function nn(e) {
1894
+ let t = tn.get(e);
1895
+ return t || (t = Oe(() => {
1751
1896
  let t = e.value;
1752
- return Pe(t) ? t.then((e) => Z(e)) : Z(t);
1753
- }), It.set(e, t)), t;
1897
+ return Ie(t) ? t.then((e) => Q(e)) : Q(t);
1898
+ }), tn.set(e, t)), t;
1754
1899
  }
1755
- function Rt(e) {
1756
- return {
1757
- el: e,
1758
- trackCleanup: (t) => W.trackCleanup(e, t)
1759
- };
1760
- }
1761
- function zt({ el: e }, t, n) {
1762
- _t(e, t, (t) => {
1900
+ function rn({ el: e }, t, n) {
1901
+ kt(e, t, (t) => {
1763
1902
  let r = n ? n(t) : String(t ?? "");
1764
1903
  e.textContent !== r && (e.textContent = r);
1765
1904
  }, "text");
1766
1905
  }
1767
- function Bt({ el: e }, t) {
1768
- let n = ye(t) ? Lt(t) : t;
1769
- _t(e, n, (r) => {
1770
- let i = n === t ? Z(r) : r;
1771
- e.innerHTML !== i && (W.cleanupDescendants(e), e.innerHTML = i);
1906
+ function an({ el: e }, t) {
1907
+ let n = ae(t) ? nn(t) : t, r = null;
1908
+ kt(e, n, (i) => {
1909
+ let a = n === t ? Q(i) : i;
1910
+ r !== a && (K.cleanupDescendants(e), e.innerHTML = a, r = a);
1772
1911
  }, "html");
1773
1912
  }
1774
- function Vt({ el: e }, t) {
1775
- let n = {};
1776
- for (let e in t) if (z.call(t, e)) {
1913
+ function on({ el: e }, t) {
1914
+ let n = {}, r = {};
1915
+ for (let e in t) if (B.call(t, e)) {
1777
1916
  let t = e.trim();
1778
- n[e] = t.indexOf(" ") === -1 ? [t] : t.split(/\s+/).filter(Boolean);
1779
- }
1780
- X(e, t, (t) => {
1781
- for (let r in t) {
1782
- let i = n[r];
1783
- t[r] ? e.classList.add(...i) : e.classList.remove(...i);
1917
+ n[e] = /\s/.test(t) ? t.split(/\s+/).filter(Boolean) : [t];
1918
+ }
1919
+ At(e, t, (t) => {
1920
+ for (let i in t) {
1921
+ let a = !!t[i];
1922
+ if (r[i] === a) continue;
1923
+ let o = n[i];
1924
+ if (a) e.classList.add(...o);
1925
+ else for (let r of o) {
1926
+ let a = !1;
1927
+ for (let e in t) if (e !== i && t[e] && n[e].includes(r)) {
1928
+ a = !0;
1929
+ break;
1930
+ }
1931
+ a || e.classList.remove(r);
1932
+ }
1933
+ r[i] = a;
1784
1934
  }
1785
1935
  }, "class");
1786
1936
  }
1787
- function Ht({ el: e }, t) {
1788
- let n = e.style, r = {}, i = {};
1789
- for (let e in t) if (z.call(t, e)) {
1937
+ function sn({ el: e }, t) {
1938
+ let n = e.style, r = {}, i = {}, a = {};
1939
+ for (let e in t) if (B.call(t, e)) {
1790
1940
  let n = t[e], [a, o] = Array.isArray(n) ? n : [n, ""];
1791
1941
  r[e] = a, i[e] = {
1792
- camel: Ft(e),
1942
+ camel: en(e),
1793
1943
  unit: o
1794
1944
  };
1795
1945
  }
1796
- X(e, r, (e) => {
1946
+ At(e, r, (e) => {
1797
1947
  for (let t in e) {
1798
- let r = i[t], a = e[t], o = r.unit ? `${a}${r.unit}` : String(a), s = r.camel;
1799
- !Nt(o) && n[s] !== o && (n[s] = o);
1948
+ let r = i[t], o = e[t], s = r.unit ? `${o}${r.unit}` : String(o), c = r.camel;
1949
+ a[t] !== s && (Qt(s) || (n[c] = s), a[t] = s);
1800
1950
  }
1801
1951
  }, "css");
1802
1952
  }
1803
- function Ut({ el: e }, t) {
1953
+ function cn({ el: e }, t) {
1804
1954
  let n = {}, r = {}, i = {};
1805
1955
  for (let a in t) {
1806
- if (!z.call(t, a)) continue;
1956
+ if (!B.call(t, a)) continue;
1807
1957
  let o = a.toLowerCase();
1808
1958
  if (o.startsWith("on")) {
1809
- console.warn(`${B.BINDING} ${V.SECURITY.BLOCKED_EVENT_HANDLER(a)}`);
1959
+ console.warn(`${V.BINDING} ${H.SECURITY.BLOCKED_EVENT_HANDLER(a)}`);
1810
1960
  continue;
1811
1961
  }
1812
1962
  n[a] = t[a], r[a] = {
1813
1963
  isAria: o.startsWith("aria-"),
1814
- isUrl: vt.has(o)
1964
+ isUrl: jt.has(o)
1815
1965
  }, i[a] = e.getAttribute(a);
1816
1966
  }
1817
- X(e, n, (t) => {
1967
+ At(e, n, (t) => {
1818
1968
  for (let n in t) {
1819
1969
  let a = r[n], o = t[n];
1820
1970
  if (o == null || o === !1 && !a.isAria) {
@@ -1822,96 +1972,100 @@ function Ut({ el: e }, t) {
1822
1972
  continue;
1823
1973
  }
1824
1974
  let s = o === !0 ? a.isAria ? "true" : n : String(o);
1825
- if (a.isUrl && yt.test(s)) {
1826
- console.warn(`${B.BINDING} ${V.SECURITY.BLOCKED_PROTOCOL(n)}`);
1975
+ if (Zt(n, s)) {
1976
+ console.warn(`${V.BINDING} ${H.SECURITY.BLOCKED_PROTOCOL(n)}`);
1827
1977
  continue;
1828
1978
  }
1829
1979
  i[n] !== s && (e.setAttribute(n, s), i[n] = s);
1830
1980
  }
1831
1981
  }, "attr");
1832
1982
  }
1833
- function Wt(e, t) {
1834
- let n = e.el, r = {}, i = {};
1983
+ function ln(e, t) {
1984
+ let n = e.el, r = {}, i = {}, a = {};
1835
1985
  for (let e in t) {
1836
- if (!z.call(t, e)) continue;
1986
+ if (!B.call(t, e)) continue;
1837
1987
  let n = e.toLowerCase();
1838
- if (n.startsWith("on") || Ve.has(e)) {
1839
- console.warn(`${B.BINDING} ${n.startsWith("on") ? V.SECURITY.BLOCKED_EVENT_HANDLER(e) : V.SECURITY.BLOCKED_PROP(e)}`);
1988
+ if (n.startsWith("on") || Ue.has(e)) {
1989
+ console.warn(`${V.BINDING} ${n.startsWith("on") ? H.SECURITY.BLOCKED_EVENT_HANDLER(e) : H.SECURITY.BLOCKED_PROP(e)}`);
1840
1990
  continue;
1841
1991
  }
1842
- r[e] = t[e], i[e] = { isUrl: vt.has(n) };
1992
+ r[e] = t[e], i[e] = { isUrl: jt.has(n) };
1843
1993
  }
1844
- X(e.el, r, (e) => {
1994
+ At(e.el, r, (e) => {
1845
1995
  for (let t in e) {
1846
1996
  let r = e[t];
1847
- if (i[t].isUrl && typeof r == "string" && yt.test(r)) {
1848
- console.warn(`${B.BINDING} ${V.SECURITY.BLOCKED_PROTOCOL(t)}`);
1849
- continue;
1997
+ if (a[t] !== r) {
1998
+ if (typeof r == "string" && Zt(t, r)) {
1999
+ console.warn(`${V.BINDING} ${H.SECURITY.BLOCKED_PROTOCOL(t)}`);
2000
+ continue;
2001
+ }
2002
+ n[t] = r, a[t] = r;
1850
2003
  }
1851
- n[t] !== r && (n[t] = r);
1852
2004
  }
1853
2005
  }, "prop");
1854
2006
  }
1855
- function Gt({ el: e }, t, n) {
2007
+ function un({ el: e }, t, n) {
1856
2008
  let r = e.style.display === "none" ? "" : e.style.display;
1857
- _t(e, t, (t) => {
1858
- let i = n === !!t ? "none" : r;
1859
- e.style.display !== i && (e.style.display = i);
2009
+ kt(e, t, (t) => {
2010
+ n === !!t ? e.style.display !== "none" && (r = e.style.display, e.style.display = "none") : e.style.display === "none" && (e.style.display = r);
1860
2011
  }, n ? "hide" : "show");
1861
2012
  }
1862
- function Kt(t, n, r = {}) {
2013
+ function dn(t, n, r = {}) {
1863
2014
  let i = t.el.tagName.toLowerCase();
1864
- if (!Be.has(i)) {
1865
- console.warn(`${B.BINDING} ${V.BINDING.INVALID_INPUT_ELEMENT(i)}`);
2015
+ if (!He.has(i)) {
2016
+ console.warn(`${V.BINDING} ${H.BINDING.INVALID_INPUT_ELEMENT(i)}`);
1866
2017
  return;
1867
2018
  }
1868
- let { fx: a, cleanup: o } = gt(e(t.el), n, r);
1869
- W.trackEffect(t.el, a), t.trackCleanup(o);
2019
+ let { fx: a, cleanup: o } = Ot(e(t.el), n, r);
2020
+ K.trackEffect(t.el, a), t.trackCleanup(o);
2021
+ }
2022
+ function fn(t) {
2023
+ t.type === "radio" && t.name && (t.form ? e(t.form) : e(document)).find(`input[type="radio"][name="${e.escapeSelector(t.name)}"]`).not(t).trigger("change.atomRadioSync");
1870
2024
  }
1871
- function qt(t, n) {
2025
+ function pn(t, n) {
1872
2026
  let r = t.el, i = e(r), a = () => {
1873
- n.peek() !== r.checked && (n.value = r.checked, r.type === "radio" && r.checked && r.name && (r.form ? e(r.form) : e(document)).find(`input[type="radio"][name="${r.name.replace(/"/g, "\\\"")}"]`).not(r).trigger("change.atomRadioSync"));
2027
+ n.peek() !== r.checked && (n.value = r.checked, fn(r));
1874
2028
  };
1875
- a[K] = !0, i.on("change change.atomRadioSync", a), t.trackCleanup(() => i.off("change change.atomRadioSync", a)), W.trackEffect(r, I(() => {
2029
+ a[Y] = !0, i.on("change change.atomRadioSync", a), t.trackCleanup(() => i.off("change change.atomRadioSync", a)), K.trackEffect(r, R(() => {
1876
2030
  let e = !!n.value;
1877
- E(() => {
1878
- r.checked !== e && (r.checked = e, H.domUpdated(B.BINDING, r, "checked", e));
2031
+ k(() => {
2032
+ r.checked !== e && (r.checked = e, W.domUpdated(V.BINDING, r, "checked", e), e && fn(r));
1879
2033
  });
1880
2034
  }));
1881
2035
  }
1882
- function Jt(t, n) {
2036
+ function mn(t, n) {
1883
2037
  let r = e(t.el);
1884
2038
  r.on(n), t.trackCleanup(() => r.off(n));
1885
2039
  }
1886
- function Yt({ el: t, trackCleanup: n }, r, i) {
2040
+ function hn({ el: t, trackCleanup: n }, r, i) {
1887
2041
  let a = e(t);
1888
2042
  a.on(r, i), n(() => a.off(r, i));
1889
2043
  }
1890
- function Xt(e) {
1891
- W.cleanupTree(e);
2044
+ function gn(e) {
2045
+ K.cleanupTree(e);
1892
2046
  }
1893
2047
  //#endregion
1894
2048
  //#region src/bindings/form.ts
1895
- var Zt = "input, select, textarea", Qt = class {
2049
+ var _n = "input, select, textarea", vn = class {
1896
2050
  constructor(e, t, n = {}) {
1897
2051
  this.form = e, this.atom = t, this.options = n, this.fieldMap = /* @__PURE__ */ new Map(), this.fields = [], this.elementNames = /* @__PURE__ */ new WeakMap(), this.isSyncingFromLeaf = !1, this.init();
1898
2052
  }
1899
2053
  init() {
1900
- let e = I(() => {
2054
+ let e = R(() => {
1901
2055
  let e = this.atom.value;
1902
- this.isSyncingFromLeaf || !this.fields.length || _e(() => {
1903
- E(() => {
2056
+ this.isSyncingFromLeaf || !this.fields.length || xe(() => {
2057
+ k(() => {
1904
2058
  for (let t = 0; t < this.fields.length; t++) {
1905
- let n = this.fields[t], r = L(e, n.parts);
2059
+ let n = this.fields[t], r = z(e, n.parts);
1906
2060
  Object.is(n.atom.peek(), r) || (n.atom.value = r);
1907
2061
  }
1908
2062
  });
1909
2063
  });
1910
2064
  });
1911
- W.trackEffect(this.form, e), this.bindElement(this.form), this.setupObserver();
2065
+ K.trackEffect(this.form, e), this.bindElement(this.form), this.setupObserver();
1912
2066
  }
1913
2067
  bindElement(e) {
1914
- let t = e.matches?.(Zt) ? [e] : e.querySelectorAll?.(Zt) || [];
2068
+ let t = e.matches?.(_n) ? [e] : e.querySelectorAll?.(_n) || [];
1915
2069
  for (let e = 0, n = t.length; e < n; e++) this.bindControl(t[e]);
1916
2070
  }
1917
2071
  bindControl(e) {
@@ -1919,11 +2073,11 @@ var Zt = "input, select, textarea", Qt = class {
1919
2073
  let t = e, n = t.name;
1920
2074
  if (!n) return;
1921
2075
  let r = this.elementNames.get(t);
1922
- if (r !== void 0 && r !== n && W.cleanup(t), this.elementNames.has(t) && r === n) return;
2076
+ if (r !== void 0 && r !== n && K.cleanup(t), this.elementNames.has(t) && r === n) return;
1923
2077
  let i = this.acquireField(n);
1924
2078
  this.elementNames.set(t, n);
1925
- let a = Rt(t);
1926
- a.trackCleanup(() => this.releaseField(t, n)), t instanceof HTMLInputElement && (t.type === "radio" || t.type === "checkbox") ? this.bindToggle(a, i.atom, t.value, t.type === "checkbox") : Kt(a, i.atom, this.options);
2079
+ let a = pt(t);
2080
+ a.trackCleanup(() => this.releaseField(t, n)), t instanceof HTMLInputElement && (t.type === "radio" || t.type === "checkbox") ? this.bindToggle(a, i.atom, t.value, t.type === "checkbox") : dn(a, i.atom, this.options);
1927
2081
  }
1928
2082
  bindToggle(t, n, r, i) {
1929
2083
  let a = t.el, o = () => {
@@ -1933,7 +2087,7 @@ var Zt = "input, select, textarea", Qt = class {
1933
2087
  a.checked ? t.add(r) : t.delete(r), n.value = Array.from(t);
1934
2088
  } else n.value = i ? a.checked : r;
1935
2089
  };
1936
- o[K] = !0, e(a).on("change", o), t.trackCleanup(() => e(a).off("change", o)), W.trackEffect(a, I(() => {
2090
+ o[Y] = !0, e(a).on("change", o), t.trackCleanup(() => e(a).off("change", o)), K.trackEffect(a, R(() => {
1937
2091
  let e = n.value, t = i ? Array.isArray(e) ? e.some((e) => String(e) === r) : !!e : String(e) === r;
1938
2092
  a.checked !== t && (a.checked = t);
1939
2093
  }));
@@ -1941,21 +2095,21 @@ var Zt = "input, select, textarea", Qt = class {
1941
2095
  acquireField(e) {
1942
2096
  let t = this.fieldMap.get(e);
1943
2097
  if (t) return t.refCount++, t;
1944
- let n = e.replace(/\[(\w+)\]/g, ".$1").split(".").filter(Boolean), r = O(L(this.atom.peek(), n));
2098
+ let n = e.replace(/\[(\w+)\]/g, ".$1").split(".").filter(Boolean), r = Ce(z(this.atom.peek(), n));
1945
2099
  return t = {
1946
2100
  atom: r,
1947
2101
  parts: n,
1948
2102
  name: e,
1949
2103
  refCount: 1,
1950
2104
  effect: null
1951
- }, t.effect = I(() => {
2105
+ }, t.effect = R(() => {
1952
2106
  let t = r.value;
1953
2107
  this.options.transform && (t = this.options.transform(e, t));
1954
2108
  let i = this.atom.peek(), a = Ae(i, n, 0, t);
1955
2109
  if (a !== i) {
1956
2110
  this.isSyncingFromLeaf = !0;
1957
2111
  try {
1958
- this.atom.value = a, this.options.onChange && E(() => this.options.onChange(e, t));
2112
+ this.atom.value = a, this.options.onChange && k(() => this.options.onChange(e, t));
1959
2113
  } finally {
1960
2114
  this.isSyncingFromLeaf = !1;
1961
2115
  }
@@ -1968,7 +2122,7 @@ var Zt = "input, select, textarea", Qt = class {
1968
2122
  let e = this.fields.indexOf(n);
1969
2123
  e !== -1 && this.fields.splice(e, 1), n.effect?.dispose(), this.fieldMap.delete(t);
1970
2124
  }
1971
- W.cleanup(e);
2125
+ K.cleanup(e);
1972
2126
  }
1973
2127
  setupObserver() {
1974
2128
  let e = new MutationObserver((e) => {
@@ -1986,141 +2140,107 @@ var Zt = "input, select, textarea", Qt = class {
1986
2140
  subtree: !0,
1987
2141
  attributes: !0,
1988
2142
  attributeFilter: ["name"]
1989
- }), W.trackCleanup(this.form, () => e.disconnect());
2143
+ }), K.trackCleanup(this.form, () => e.disconnect());
1990
2144
  }
1991
2145
  };
1992
- function $t(e, t, n = {}) {
1993
- new Qt(e, t, n);
1994
- }
1995
- //#endregion
1996
- //#region src/bindings/chainable.ts
1997
- function Q(e, t) {
1998
- let n = e.length;
1999
- for (let r = 0; r < n; r++) {
2000
- let n = e[r];
2001
- if (n?.nodeType === 1) {
2002
- let e = n;
2003
- t(Rt(e), e);
2004
- } else n && H.log(B.BINDING, `Skipping non-Element node (nodeType=${n.nodeType})`);
2005
- }
2006
- return e;
2146
+ function yn(e, t, n = {}) {
2147
+ new vn(e, t, n);
2007
2148
  }
2008
2149
  e.fn.atomText = function(e, t) {
2009
- return Q(this, (n) => zt(n, e, t));
2150
+ return J(this, (n) => rn(n, e, t), { needsCtx: !0 });
2010
2151
  }, e.fn.atomHtml = function(e) {
2011
- return Q(this, (t) => Bt(t, e));
2152
+ return J(this, (t) => an(t, e), { needsCtx: !0 });
2012
2153
  }, e.fn.atomClass = function(e, t) {
2013
- if (typeof e == "string") {
2014
- if (t === void 0) return console.warn(`${B.BINDING} ${V.BINDING.MISSING_CONDITION("atomClass")}`), this;
2015
- let n = { [e]: t };
2016
- return Q(this, (e) => Vt(e, n));
2017
- }
2018
- return Q(this, (t) => Vt(t, e));
2154
+ let n = typeof e == "string" ? t === void 0 ? null : { [e]: t } : e;
2155
+ return n ? J(this, (e) => on(e, n), { needsCtx: !0 }) : (console.warn(`${V.BINDING} ${H.BINDING.MISSING_CONDITION("atomClass")}`), this);
2019
2156
  }, e.fn.atomCss = function(e, t, n) {
2020
- if (typeof e == "string") {
2021
- if (t === void 0) return console.warn(`${B.BINDING} ${V.BINDING.MISSING_SOURCE("atomCss")}`), this;
2022
- let r = { [e]: n ? [t, n] : t };
2023
- return Q(this, (e) => Ht(e, r));
2024
- }
2025
- return Q(this, (t) => Ht(t, e));
2157
+ let r = typeof e == "string" ? t === void 0 ? null : { [e]: n ? [t, n] : t } : e;
2158
+ return r ? J(this, (e) => sn(e, r), { needsCtx: !0 }) : (console.warn(`${V.BINDING} ${H.BINDING.MISSING_SOURCE("atomCss")}`), this);
2026
2159
  }, e.fn.atomAttr = function(e, t) {
2027
- if (typeof e == "string") {
2028
- if (t === void 0) return console.warn(`${B.BINDING} ${V.BINDING.MISSING_SOURCE("atomAttr")}`), this;
2029
- let n = { [e]: t };
2030
- return Q(this, (e) => Ut(e, n));
2031
- }
2032
- return Q(this, (t) => Ut(t, e));
2160
+ let n = typeof e == "string" ? t === void 0 ? null : { [e]: t } : e;
2161
+ return n ? J(this, (e) => cn(e, n), { needsCtx: !0 }) : (console.warn(`${V.BINDING} ${H.BINDING.MISSING_SOURCE("atomAttr")}`), this);
2033
2162
  }, e.fn.atomProp = function(e, t) {
2034
- if (typeof e == "string") {
2035
- if (t === void 0) return console.warn(`${B.BINDING} ${V.BINDING.MISSING_SOURCE("atomProp")}`), this;
2036
- let n = { [e]: t };
2037
- return Q(this, (e) => Wt(e, n));
2038
- }
2039
- return Q(this, (t) => Wt(t, e));
2163
+ let n = typeof e == "string" ? t === void 0 ? null : { [e]: t } : e;
2164
+ return n ? J(this, (e) => ln(e, n), { needsCtx: !0 }) : (console.warn(`${V.BINDING} ${H.BINDING.MISSING_SOURCE("atomProp")}`), this);
2040
2165
  }, e.fn.atomShow = function(e) {
2041
- return Q(this, (t) => Gt(t, e, !1));
2166
+ return J(this, (t) => un(t, e, !1), { needsCtx: !0 });
2042
2167
  }, e.fn.atomHide = function(e) {
2043
- return Q(this, (t) => Gt(t, e, !0));
2168
+ return J(this, (t) => un(t, e, !0), { needsCtx: !0 });
2044
2169
  }, e.fn.atomVal = function(e, t = {}) {
2045
- return Q(this, (n) => Kt(n, e, t));
2170
+ return J(this, (n) => dn(n, e, t), { needsCtx: !0 });
2046
2171
  }, e.fn.atomChecked = function(e) {
2047
- return Q(this, (t) => qt(t, e));
2172
+ return J(this, (t) => pn(t, e), { needsCtx: !0 });
2048
2173
  }, e.fn.atomForm = function(e, t = {}) {
2049
- return Q(this, (n, r) => {
2050
- r instanceof HTMLFormElement && $t(r, e, t);
2051
- });
2174
+ return J(this, (n, r) => {
2175
+ r instanceof HTMLFormElement ? yn(r, e, t) : W.log(V.BINDING, "Skipping non-Form element for atomForm");
2176
+ }, { needsCtx: !1 });
2052
2177
  }, e.fn.atomOn = function(e, t) {
2053
- return Q(this, (n) => Yt(n, e, t));
2178
+ return J(this, (n) => hn(n, e, t), { needsCtx: !0 });
2054
2179
  };
2055
- var en = [
2056
- (e, t) => zt(e, t.text),
2057
- (e, t) => Bt(e, t.html),
2058
- (e, t) => Vt(e, t.class),
2059
- (e, t) => Ht(e, t.css),
2060
- (e, t) => Ut(e, t.attr),
2061
- (e, t) => Wt(e, t.prop),
2062
- (e, t) => Gt(e, t.show, !1),
2063
- (e, t) => Gt(e, t.hide, !0),
2180
+ var bn = [
2181
+ (e, t) => rn(e, ...mt(t.text)),
2182
+ (e, t) => an(e, t.html),
2183
+ (e, t) => on(e, t.class),
2184
+ (e, t) => sn(e, t.css),
2185
+ (e, t) => cn(e, t.attr),
2186
+ (e, t) => ln(e, t.prop),
2187
+ (e, t) => un(e, t.show, !1),
2188
+ (e, t) => un(e, t.hide, !0),
2189
+ (e, t) => dn(e, ...mt(t.val)),
2190
+ (e, t) => pn(e, t.checked),
2064
2191
  (e, t) => {
2065
- let n = t.val;
2066
- Array.isArray(n) ? Kt(e, n[0], n[1]) : Kt(e, n);
2192
+ e.el instanceof HTMLFormElement && yn(e.el, ...mt(t.form));
2067
2193
  },
2068
- (e, t) => qt(e, t.checked),
2069
- (e, t) => {
2070
- if (e.el instanceof HTMLFormElement) {
2071
- let n = t.form;
2072
- Array.isArray(n) ? $t(e.el, n[0], n[1]) : $t(e.el, n);
2073
- }
2074
- },
2075
- (e, t) => Jt(e, t.on)
2194
+ (e, t) => mn(e, t.on)
2076
2195
  ];
2077
2196
  e.fn.atomBind = function(e) {
2078
2197
  let t = 0;
2079
- return e.text !== void 0 && (t |= 1), e.html !== void 0 && (t |= 2), e.class !== void 0 && (t |= 4), e.css !== void 0 && (t |= 8), e.attr !== void 0 && (t |= 16), e.prop !== void 0 && (t |= 32), e.show !== void 0 && (t |= 64), e.hide !== void 0 && (t |= 128), e.val !== void 0 && (t |= 256), e.checked !== void 0 && (t |= 512), e.form !== void 0 && (t |= 1024), e.on !== void 0 && (t |= 2048), t === 0 ? this : Q(this, (n) => {
2198
+ return e.text !== void 0 && (t |= 1), e.html !== void 0 && (t |= 2), e.class !== void 0 && (t |= 4), e.css !== void 0 && (t |= 8), e.attr !== void 0 && (t |= 16), e.prop !== void 0 && (t |= 32), e.show !== void 0 && (t |= 64), e.hide !== void 0 && (t |= 128), e.val !== void 0 && (t |= 256), e.checked !== void 0 && (t |= 512), e.form !== void 0 && (t |= 1024), e.on !== void 0 && (t |= 2048), t === 0 ? this : J(this, (n) => {
2080
2199
  let r = t;
2081
2200
  for (; r > 0;) {
2082
2201
  let t = r & -r;
2083
- en[31 - Math.clz32(t)](n, e), r ^= t;
2202
+ bn[31 - Math.clz32(t)](n, e), r ^= t;
2084
2203
  }
2085
- });
2204
+ }, { needsCtx: !0 });
2086
2205
  }, e.fn.atomUnbind = function() {
2087
- let e = this.length;
2088
- for (let t = 0; t < e; t++) {
2089
- let e = this[t];
2090
- e?.nodeType === 1 && Xt(e);
2091
- }
2092
- return this;
2206
+ return J(this, (e, t) => gn(t), { needsCtx: !1 });
2093
2207
  };
2094
2208
  //#endregion
2095
- //#region src/bindings/list.ts
2096
- var tn = /* @__PURE__ */ new WeakMap(), nn = 0, rn = new et(() => /* @__PURE__ */ new Map(), (e) => e.clear()), an = new et(() => /* @__PURE__ */ new Set(), (e) => e.clear()), $ = new $e(100, 1024);
2097
- function on(e, t, n) {
2098
- if (e instanceof Element) {
2099
- n.insertBefore(e, t);
2100
- return;
2101
- }
2102
- let r = e.length;
2103
- for (let i = 0; i < r; i++) {
2104
- let r = e[i];
2105
- r && n.insertBefore(r, t);
2209
+ //#region src/bindings/list/utils.ts
2210
+ function xn(t) {
2211
+ return t instanceof Element ? e(t) : t;
2212
+ }
2213
+ function Sn(e, t) {
2214
+ if (e instanceof Element) t === null ? e.removeAttribute("data-atom-key") : e.setAttribute("data-atom-key", t);
2215
+ else if (!e.nodeType) {
2216
+ let n = e;
2217
+ for (let e = 0, r = n.length; e < r; e++) {
2218
+ let r = n[e];
2219
+ r instanceof Element && (t === null ? r.removeAttribute("data-atom-key") : r.setAttribute("data-atom-key", t));
2220
+ }
2106
2221
  }
2107
2222
  }
2108
- function sn(t) {
2109
- return t instanceof Element ? e(t) : t;
2223
+ function Cn(e) {
2224
+ if (e instanceof Element) K.cleanupTree(e);
2225
+ else for (let t = 0, n = e.length; t < n; t++) {
2226
+ let n = e[t];
2227
+ n instanceof Element && K.cleanupTree(n);
2228
+ }
2110
2229
  }
2111
- var cn = class {
2230
+ //#endregion
2231
+ //#region src/bindings/list/context.ts
2232
+ var wn = class {
2112
2233
  constructor(e, t, n) {
2113
2234
  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);
2114
2235
  }
2115
2236
  scheduleRemoval(e, t) {
2116
2237
  let n = () => {
2117
- this.fx?.isDisposed || (t[0]?.isConnected && t.remove(), this.removingKeys.delete(e), H.log(B.LIST, `${this.containerSelector} removed item:`, e));
2238
+ this.fx?.isDisposed || t[0] instanceof Element && t[0].hasAttribute("data-atom-key") || (t[0]?.isConnected && t.remove(), this.removingKeys.delete(e), W.log(V.LIST, `${this.containerSelector} removed item:`, e));
2118
2239
  }, r = this.onRemove?.(t);
2119
2240
  r instanceof Promise ? r.then(n, n) : n();
2120
2241
  }
2121
2242
  removeItem(e, t) {
2122
- for (let e = 0; e < t.length; e++) t[e] instanceof Element && t[e].removeAttribute("data-atom-key");
2123
- this.removingKeys.add(e), this.scheduleRemoval(e, t);
2243
+ Sn(t, null), this.removingKeys.add(e), this.scheduleRemoval(e, t);
2124
2244
  }
2125
2245
  dispose() {
2126
2246
  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"), this.statesBuffer = new Uint8Array(), this.indicesBuffer = new Int32Array();
@@ -2129,148 +2249,171 @@ var cn = class {
2129
2249
  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)));
2130
2250
  }
2131
2251
  };
2132
- function ln(t, n, r, i) {
2133
- if (t.$emptyEl && n > 0 && (t.$emptyEl.remove(), t.$emptyEl = null), n !== 0) return;
2134
- let { oldKeys: a, oldNodes: o, onRemove: s } = t;
2135
- if (s) for (let e = 0, n = a.length; e < n; e++) {
2136
- let n = a[e];
2137
- o[e] && t.removeItem(n, sn(o[e]));
2138
- }
2139
- else {
2140
- for (let e = 0, n = a.length; e < n; e++) t.removingKeys.delete(a[e]);
2141
- r.empty();
2142
- }
2143
- i && !t.$emptyEl && (t.$emptyEl = e(typeof i == "string" ? Z(i) : i), t.$emptyEl.appendTo(r)), $.release(t.oldKeys), $.release(t.oldItems), $.release(t.oldNodes), t.oldKeys = [], t.oldItems = [], t.oldNodes = [];
2144
- }
2145
- function un(e, t, n, r, i, a) {
2146
- let { oldKeys: o, oldItems: s, oldNodes: c, removingKeys: l, keyToIndex: u } = e, d = o.length, f = 0, p = d - 1, m = n - 1, h = a || Ie;
2147
- for (; f <= p && f <= m;) {
2148
- let e = t[f], n = r(e, f);
2149
- if (o[f] !== n || !h(s[f], e)) break;
2150
- u.set(n, f++);
2151
- }
2152
- for (; p >= f && m >= f;) {
2153
- let e = t[m], n = r(e, m);
2154
- if (o[p] !== n || !h(s[p], e)) break;
2155
- u.set(n, m--), p--;
2156
- }
2157
- let g = rn.acquire();
2158
- for (let e = f; e <= p; e++) g.set(o[e], e);
2159
- let ee = an.acquire();
2252
+ //#endregion
2253
+ //#region src/bindings/list/diff.ts
2254
+ function Tn(e, t, n, r, i, a, o) {
2255
+ let { oldKeys: s, oldItems: c, oldNodes: l, removingKeys: u, keyToIndex: d } = e, f = s.length, p = 0, m = f - 1, h = n - 1, g = a || Re;
2256
+ for (; p <= m && p <= h;) {
2257
+ let e = t[p], n = r(e, p);
2258
+ if (s[p] !== n || !g(c[p], e) || !l[p]) break;
2259
+ d.set(n, p++);
2260
+ }
2261
+ for (; m >= p && h >= p;) {
2262
+ let e = t[h], n = r(e, h);
2263
+ if (s[m] !== n || !g(c[m], e) || !l[m]) break;
2264
+ d.set(n, h--), m--;
2265
+ }
2266
+ let _ = o.map.acquire();
2267
+ for (let e = p; e <= m; e++) _.set(s[e], e);
2268
+ let v = o.set.acquire();
2160
2269
  e.ensureBuffers(n);
2161
- let _ = $.acquire();
2162
- _.length = n;
2163
- let v = $.acquire();
2164
- v.length = n;
2165
- let y = $.acquire();
2270
+ let y = o.array.acquire();
2166
2271
  y.length = n;
2167
- let b = e.statesBuffer, x = e.indicesBuffer, S = $.acquire(), C = $.acquire(), w = $.acquire();
2168
- for (let e = 0; e < f; e++) _[e] = o[e], v[e] = t[e], y[e] = c[e], b[e] = 3, x[e] = e;
2169
- for (let e = d - 1, r = n - 1; r > m; r--, e--) _[r] = o[e], v[r] = t[r], y[r] = c[e], b[r] = 3, x[r] = e;
2170
- for (let n = f; n <= m; n++) {
2171
- let o = t[n], d = r(o, n);
2172
- if (_[n] = d, v[n] = o, u.set(d, n), ee.has(d)) {
2173
- H.warn(B.LIST, V.LIST.DUPLICATE_KEY(d, n, e.containerSelector)), x[n] = -1;
2272
+ let b = o.array.acquire();
2273
+ b.length = n;
2274
+ let x = o.array.acquire();
2275
+ x.length = n;
2276
+ let S = e.statesBuffer, C = e.indicesBuffer, w = o.array.acquire(), T = o.array.acquire(), ee = o.array.acquire();
2277
+ for (let e = 0; e < p; e++) {
2278
+ let n = s[e];
2279
+ y[e] = n, b[e] = t[e], x[e] = l[e], S[e] = 3, C[e] = e, v.add(n);
2280
+ }
2281
+ for (let e = f - 1, r = n - 1; r > h; r--, e--) {
2282
+ let n = s[e];
2283
+ y[r] = n, b[r] = t[r], x[r] = l[e], S[r] = 3, C[r] = e, v.add(n);
2284
+ }
2285
+ for (let n = p; n <= h; n++) {
2286
+ let o = t[n], s = r(o, n);
2287
+ if (y[n] = s, b[n] = o, d.set(s, n), v.has(s)) {
2288
+ W.warn(V.LIST, H.LIST.DUPLICATE_KEY(s, n, e.containerSelector)), C[n] = -1;
2174
2289
  continue;
2175
2290
  }
2176
- ee.add(d);
2177
- let f = g.get(d);
2291
+ v.add(s);
2292
+ let f = _.get(s);
2178
2293
  if (f === void 0) {
2179
- S.push(d), C.push(o), w.push(n), x[n] = -1, b[n] = 1;
2294
+ w.push(s), T.push(o), ee.push(n), C[n] = -1, S[n] = 1;
2180
2295
  continue;
2181
2296
  }
2182
- let p = s[f];
2183
- y[n] = c[f], !i && p !== o && !(a ? a(p, o) : Ie(p, o)) ? (S.push(d), C.push(o), w.push(n), b[n] = 2) : b[n] = 0, x[n] = l.has(d) ? -1 : f;
2184
- }
2185
- return rn.release(g), {
2186
- newKeys: _,
2187
- newKeySet: ee,
2188
- newItems: v,
2189
- newNodes: y,
2190
- newStates: b,
2191
- newIndices: x,
2192
- trKeys: S,
2193
- trItems: C,
2194
- trIdxs: w,
2195
- startIndex: f,
2196
- oldEndIndex: p,
2197
- newEndIndex: m
2297
+ let p = c[f];
2298
+ x[n] = l[f], !i && p !== o && !(a ? a(p, o) : Re(p, o)) ? (w.push(s), T.push(o), ee.push(n), S[n] = 2) : S[n] = 0, C[n] = u.has(s) ? -1 : f;
2299
+ }
2300
+ return o.map.release(_), {
2301
+ newKeys: y,
2302
+ newKeySet: v,
2303
+ newItems: b,
2304
+ newNodes: x,
2305
+ newStates: S,
2306
+ newIndices: C,
2307
+ trKeys: w,
2308
+ trItems: T,
2309
+ trIdxs: ee,
2310
+ startIndex: p,
2311
+ oldEndIndex: m,
2312
+ newEndIndex: h
2198
2313
  };
2199
2314
  }
2200
- function dn(t, n, r) {
2315
+ //#endregion
2316
+ //#region src/bindings/list/dom.ts
2317
+ var En = 0;
2318
+ function Dn(e, t, n) {
2319
+ if (!e) return;
2320
+ if (e instanceof Element) {
2321
+ n.insertBefore(e, t);
2322
+ return;
2323
+ }
2324
+ let r = e.length;
2325
+ for (let i = 0; i < r; i++) {
2326
+ let r = e[i];
2327
+ r && n.insertBefore(r, t);
2328
+ }
2329
+ }
2330
+ function On(t, n, r, i, a) {
2331
+ if (t.$emptyEl && n > 0 && (t.$emptyEl.remove(), t.$emptyEl = null), n !== 0) return;
2332
+ let { oldKeys: o, oldNodes: s, onRemove: c } = t;
2333
+ if (c) for (let e = 0, n = o.length; e < n; e++) {
2334
+ let n = o[e];
2335
+ s[e] && t.removeItem(n, xn(s[e]));
2336
+ }
2337
+ else {
2338
+ for (let e = 0, n = o.length; e < n; e++) t.removingKeys.delete(o[e]);
2339
+ r.empty();
2340
+ }
2341
+ i && !t.$emptyEl && (t.$emptyEl = e(typeof i == "string" ? Q(i) : i), t.$emptyEl.appendTo(r)), a.release(t.oldKeys), a.release(t.oldItems), a.release(t.oldNodes), t.oldKeys = [], t.oldItems = [], t.oldNodes = [];
2342
+ }
2343
+ function kn(t, n, r) {
2201
2344
  let { trKeys: i, trItems: a, trIdxs: o, newNodes: s, newStates: c } = t, l = i.length, u = Array(l), d = [], f = 0;
2202
2345
  for (let e = 0; e < l; e++) {
2203
2346
  let t = n.render(a[e], o[e]);
2204
2347
  u[e] = t, typeof t == "string" && (d.push(t), f++);
2205
2348
  }
2206
2349
  let p = null;
2207
- if (d.length > 0) if (d.length === 1) p = [Z(d[0])];
2350
+ if (d.length > 0) if (d.length === 1) p = [Q(d[0])];
2208
2351
  else {
2209
- let e = `<template data-atom-sep="${(nn++).toString(36)}"></template>`;
2210
- p = Z(d.join(e)).split(e);
2352
+ let e = `<template data-atom-sep="${(En++).toString(36)}"></template>`;
2353
+ p = Q(d.join(e)).split(e);
2211
2354
  }
2212
- if (r && p && f === l && !n.bind && !n.onAdd && !n.onRemove && !n.events) return p;
2355
+ if (r && p && f === l && !n.bind && !n.onAdd && !n.onRemove && !n.events && e.parseHTML(p.join("")).length === l) return p;
2213
2356
  let m = 0;
2214
2357
  for (let t = 0; t < l; t++) {
2215
- let n = u[t], r = e(typeof n == "string" ? p[m++] : n), a = o[t], l = String(i[t]);
2216
- for (let e = 0, t = r.length; e < t; e++) {
2217
- let t = r[e];
2218
- t instanceof Element && t.setAttribute("data-atom-key", l);
2219
- }
2220
- if (c[a] === 2 && s[a]) {
2358
+ let n = u[t], r = e(typeof n == "string" ? e.parseHTML(p[m++]) : n), a = o[t];
2359
+ if (Sn(r, String(i[t])), c[a] === 2 && s[a]) {
2221
2360
  let e = s[a];
2222
- if (e instanceof Element) W.cleanupTree(e);
2223
- else for (let t = 0, n = e.length; t < n; t++) {
2224
- let n = e[t];
2225
- n instanceof Element && W.cleanupTree(n);
2226
- }
2227
- sn(e).replaceWith(r);
2361
+ Cn(e);
2362
+ let t = xn(e);
2363
+ t.first().before(r), t.remove();
2228
2364
  }
2229
2365
  s[a] = r.length === 1 ? r[0] : r;
2230
2366
  }
2231
2367
  return null;
2232
2368
  }
2233
- function fn(e, t) {
2369
+ function An(e, t) {
2234
2370
  let { startIndex: n, oldEndIndex: r, newKeySet: i } = t;
2235
2371
  for (let t = n; t <= r; t++) {
2236
2372
  let n = e.oldKeys[t];
2237
- !i.has(n) && e.oldNodes[t] && e.removeItem(n, sn(e.oldNodes[t]));
2373
+ !i.has(n) && e.oldNodes[t] && e.removeItem(n, xn(e.oldNodes[t]));
2238
2374
  }
2239
2375
  }
2240
- function pn(t, n, r, i, a) {
2376
+ function jn(t, n, r, i, a) {
2241
2377
  let { newKeys: o, newItems: s, newNodes: c, newStates: l, newIndices: u } = n, d = o.length;
2242
2378
  if (a !== null) {
2243
2379
  r.innerHTML = a.join("");
2244
2380
  let n = r.firstElementChild;
2245
- for (let r = 0; r < d && n; r++) n.setAttribute("data-atom-key", String(o[r])), c[r] = n, l[r] = 0, t.removingKeys.delete(o[r]), H.domUpdated(B.LIST, e(n), "list.add", s[r]), n = n.nextElementSibling;
2381
+ for (let r = 0; r < d && n; r++) n.setAttribute("data-atom-key", String(o[r])), c[r] = n, l[r] = 0, t.removingKeys.delete(o[r]), W.domUpdated(V.LIST, e(n), "list.add", s[r]), n = n.nextElementSibling;
2246
2382
  return;
2247
2383
  }
2248
- if (t.oldKeys.length === 0) {
2384
+ if (t.oldKeys.length === 0 && t.removingKeys.size === 0) {
2249
2385
  let e = document.createDocumentFragment();
2250
2386
  for (let t = 0; t < d; t++) {
2251
2387
  let n = c[t];
2252
- if (n instanceof Element) e.appendChild(n);
2388
+ if (n) if (n instanceof Element) e.appendChild(n);
2253
2389
  else for (let t = 0; t < n.length; t++) e.appendChild(n[t]);
2254
2390
  }
2255
- r.appendChild(e);
2391
+ r.innerHTML = "", r.appendChild(e);
2256
2392
  } else {
2257
2393
  let e = null, t = 2147483647;
2258
2394
  for (let n = d - 1; n >= 0; n--) {
2259
- let i = u[n];
2260
- i !== -1 && i < t ? t = i : on(c[n], e, r);
2261
- let a = c[n];
2262
- e = a instanceof Element ? a : a[0] ?? null;
2395
+ let i = u[n], a = c[n];
2396
+ a && (i !== -1 && i < t ? t = i : Dn(a, e, r), e = a instanceof Element ? a : a[0] ?? null);
2263
2397
  }
2264
2398
  }
2265
2399
  for (let e = 0; e < d; e++) {
2266
2400
  let n = l[e];
2267
2401
  if (n !== 3) {
2268
- let r = sn(c[e]), a = s[e];
2269
- n === 0 ? i.update?.(r, a, e) : i.bind?.(r, a, e), n === 1 && (i.onAdd?.(r), t.removingKeys.delete(o[e]), H.domUpdated(B.LIST, r, "list.add", a));
2402
+ let r = c[e];
2403
+ if (!r) continue;
2404
+ let a = xn(r), l = s[e];
2405
+ n === 0 ? i.update?.(a, l, e) : i.bind?.(a, l, e), n === 1 && (i.onAdd?.(a), t.removingKeys.delete(o[e]), W.domUpdated(V.LIST, a, "list.add", l));
2270
2406
  }
2271
2407
  }
2272
2408
  }
2273
- e.fn.atomList = function(t, n) {
2409
+ //#endregion
2410
+ //#region src/bindings/list/index.ts
2411
+ var Mn = /* @__PURE__ */ new WeakMap(), Nn = new it(() => /* @__PURE__ */ new Map(), (e) => e.clear()), Pn = new it(() => /* @__PURE__ */ new Set(), (e) => e.clear()), $ = new rt(100, 1024), Fn = {
2412
+ map: Nn,
2413
+ set: Pn,
2414
+ array: $
2415
+ };
2416
+ function In(t, n) {
2274
2417
  let r = typeof n.key == "function" ? n.key : (e) => e[n.key], i = {
2275
2418
  bind: n.bind,
2276
2419
  update: n.update,
@@ -2281,20 +2424,20 @@ e.fn.atomList = function(t, n) {
2281
2424
  for (let a = 0, o = this.length; a < o; a++) {
2282
2425
  let o = this[a], s = e(o);
2283
2426
  s.off(".atomList");
2284
- let c = tn.get(o);
2427
+ let c = Mn.get(o);
2285
2428
  c && (c.fx.dispose(), c.ctx.dispose());
2286
- let l = new cn(s, Fe(o), n.onRemove), u = I(() => {
2429
+ let l = new wn(s, Le(o), n.onRemove), u = R(() => {
2287
2430
  let e = t.value, a = e.length;
2288
- E(() => {
2289
- if (ln(l, a, s, n.empty), a === 0) return;
2290
- H.log(B.LIST, `${l.containerSelector} updating with ${a} items`);
2291
- let t = un(l, e, a, r, n.update, n.isEqual), c = dn(t, n, l.oldKeys.length === 0);
2292
- if (fn(l, t), pn(l, t, o, i, c), n.events) for (let e = t.startIndex; e <= t.oldEndIndex; e++) t.newKeySet.has(l.oldKeys[e]) || l.keyToIndex.delete(l.oldKeys[e]);
2293
- $.release(l.oldKeys), $.release(l.oldItems), $.release(l.oldNodes), l.oldKeys = t.newKeys, l.oldItems = t.newItems, l.oldNodes = t.newNodes, an.release(t.newKeySet), $.release(t.trKeys), $.release(t.trItems), $.release(t.trIdxs);
2431
+ k(() => {
2432
+ if (On(l, a, s, n.empty, $), a === 0) return;
2433
+ W.log(V.LIST, `${l.containerSelector} updating with ${a} items`);
2434
+ let t = Tn(l, e, a, r, n.update, n.isEqual, Fn), c = kn(t, n, l.oldKeys.length === 0);
2435
+ if (An(l, t), jn(l, t, o, i, c), n.events) for (let e = t.startIndex; e <= t.oldEndIndex; e++) t.newKeySet.has(l.oldKeys[e]) || l.keyToIndex.delete(l.oldKeys[e]);
2436
+ $.release(l.oldKeys), $.release(l.oldItems), $.release(l.oldNodes), l.oldKeys = t.newKeys, l.oldItems = t.newItems, l.oldNodes = t.newNodes, Pn.release(t.newKeySet), $.release(t.trKeys), $.release(t.trItems), $.release(t.trIdxs);
2294
2437
  });
2295
2438
  });
2296
2439
  if (l.fx = u, n.events) for (let e in n.events) {
2297
- if (!z.call(n.events, e)) continue;
2440
+ if (!B.call(n.events, e)) continue;
2298
2441
  let t = e.indexOf(" "), r = t === -1 ? e : e.slice(0, t), i = t === -1 ? "> *" : e.slice(t + 1).trim(), a = n.events[e];
2299
2442
  s.on(`${r}.atomList`, i, function(e) {
2300
2443
  let t = e.target.closest?.("[data-atom-key]"), n = t?.getAttribute("data-atom-key");
@@ -2308,119 +2451,132 @@ e.fn.atomList = function(t, n) {
2308
2451
  i !== void 0 && a.call(t, l.oldItems[i], i, e);
2309
2452
  });
2310
2453
  }
2311
- W.trackEffect(o, u), tn.set(o, {
2454
+ K.trackEffect(o, u), Mn.set(o, {
2312
2455
  fx: u,
2313
2456
  ctx: l
2314
- }), W.trackCleanup(o, () => {
2315
- l.dispose(), tn.delete(o);
2457
+ }), K.trackCleanup(o, () => {
2458
+ l.dispose(), Mn.delete(o);
2316
2459
  });
2317
2460
  }
2318
2461
  return this;
2319
- };
2462
+ }
2463
+ e.fn.atomList = In;
2320
2464
  //#endregion
2321
2465
  //#region src/bindings/mount.ts
2322
- var mn = Object.freeze({});
2466
+ var Ln = Object.freeze({});
2323
2467
  e.fn.atomMount = function(t, n) {
2324
- let r = n ?? mn, i = t.name || "Component";
2325
- for (let n = 0, a = this.length; n < a; n++) {
2326
- let a = this[n];
2327
- if (a) {
2328
- W.cleanupTree(a);
2329
- try {
2330
- let n = E(() => t(e(a), r));
2331
- typeof n == "function" && W.setComponentCleanup(a, n);
2332
- } catch (e) {
2333
- H.error(B.MOUNT, V.MOUNT.ERROR(i), e);
2334
- }
2468
+ let r = n ?? Ln, i = t.name || "Component";
2469
+ return J(this, (n, a) => {
2470
+ K.cleanupTree(a);
2471
+ try {
2472
+ let n = k(() => xe(() => t(e(a), r)));
2473
+ typeof n == "function" && K.setComponentCleanup(a, n);
2474
+ } catch (e) {
2475
+ W.error(V.MOUNT, H.MOUNT.ERROR(i), e);
2335
2476
  }
2336
- }
2337
- return this;
2477
+ });
2338
2478
  }, e.fn.atomUnmount = function() {
2339
- for (let e = 0, t = this.length; e < t; e++) {
2340
- let t = this[e];
2341
- t && Xt(t);
2342
- }
2343
- return this;
2479
+ return J(this, (e, t) => gn(t));
2344
2480
  };
2345
2481
  //#endregion
2346
2482
  //#region src/features/route.ts
2347
- function hn(e, t) {
2483
+ function Rn(e, t) {
2348
2484
  try {
2349
2485
  history.pushState(e, "", t);
2350
2486
  } catch (e) {
2351
- H.warn(B.ROUTE, "PushState failed (likely file:// protocol or security restriction). UI will update, but URL will not.", e);
2487
+ W.warn(V.ROUTE, "PushState failed (likely file:// protocol or security restriction). UI will update, but URL will not.", e);
2352
2488
  }
2353
2489
  }
2354
- var gn = class {
2490
+ var zn = class {
2491
+ parseQueryParams(e) {
2492
+ let t = {};
2493
+ return e && new URLSearchParams(e).forEach((e, n) => {
2494
+ t[n] = e;
2495
+ }), t;
2496
+ }
2355
2497
  constructor(t) {
2356
2498
  this.isDestroyed = !1, this.previousRoute = "", this.cleanups = [], this.templateCache = /* @__PURE__ */ new Map(), this.routeCleanups = [], this.lastRawQuery = "", this.cachedParams = {}, this.config = {
2357
- mode: Le.mode,
2358
- basePath: Le.basePath,
2359
- autoBindLinks: Le.autoBindLinks,
2360
- activeClass: Le.activeClass,
2499
+ mode: ze.mode,
2500
+ basePath: ze.basePath,
2501
+ autoBindLinks: ze.autoBindLinks,
2502
+ activeClass: ze.activeClass,
2503
+ notFound: t.notFound || "",
2504
+ beforeTransition: t.beforeTransition || (() => {}),
2505
+ afterTransition: t.afterTransition || (() => {}),
2361
2506
  ...t
2362
- }, this.isHistoryMode = this.config.mode === "history", this.basePath = this.config.basePath.replace(/\/$/, ""), this.activeClass = this.config.activeClass, this.$target = e(this.config.target), this.previousUrl = this.isHistoryMode ? location.pathname + location.search : location.hash, this.currentRouteAtom = O(this.getRouteName()), this.currentRoute = this.currentRouteAtom, this.queryParamsAtom = O(this.getQueryParams()), this.queryParams = F(() => this.queryParamsAtom.value), this.init();
2507
+ }, this.isHistoryMode = this.config.mode === "history", this.basePath = this.config.basePath.replace(/\/$/, ""), this.activeClass = this.config.activeClass, this.$target = e(this.config.target), this.previousUrl = this.isHistoryMode ? location.pathname + location.search : location.hash, this.currentRouteAtom = Ce(this.getRouteName()), this.currentRoute = this.currentRouteAtom, this.queryParamsAtom = Ce(this.getQueryParams()), this.queryParams = Oe(() => this.queryParamsAtom.value), this.init();
2363
2508
  }
2364
2509
  init() {
2365
2510
  let e = this.isHistoryMode ? "popstate" : "hashchange", t = this.handleUrlChange.bind(this);
2366
2511
  window.addEventListener(e, t), this.cleanups.push(() => window.removeEventListener(e, t));
2367
- let n = I(() => {
2512
+ let n = R(() => {
2368
2513
  let e = this.currentRouteAtom.value;
2369
- E(() => {
2514
+ k(() => {
2370
2515
  for (let e of this.routeCleanups) try {
2371
2516
  e();
2372
2517
  } catch {}
2373
2518
  this.routeCleanups.length = 0;
2374
2519
  }), this.renderRoute(e);
2375
2520
  });
2376
- this.cleanups.push(() => n.dispose()), this.setupAutoBindLinks(), this.$target[0] && W.trackCleanup(this.$target[0], () => this.destroy());
2521
+ this.cleanups.push(() => n.dispose()), this.setupAutoBindLinks(), this.$target[0] && K.trackCleanup(this.$target[0], () => this.destroy());
2377
2522
  }
2378
2523
  getRouteName() {
2379
2524
  let { default: e } = this.config;
2380
2525
  if (this.isHistoryMode) {
2381
2526
  let t = this.basePath, n = location.pathname;
2382
- return t && n.startsWith(t) && (n = n.substring(t.length)), n.replace(/^\//, "") || e;
2527
+ return t && (n === t || n.startsWith(`${t}/`)) && (n = n.substring(t.length)), n.replace(/^\/+/, "") || e;
2383
2528
  }
2384
- return location.hash.split("?")[0].substring(1) || e;
2529
+ let t = location.hash, { route: n } = this.splitPath(t.startsWith("#") ? t.substring(1) : t);
2530
+ return n || e;
2385
2531
  }
2386
2532
  getQueryParams() {
2387
- let e = location.hash, t = e.indexOf("?"), n = this.isHistoryMode ? location.search.substring(1) : t === -1 ? "" : e.substring(t + 1);
2388
- if (n === this.lastRawQuery) return this.cachedParams;
2389
- this.lastRawQuery = n;
2390
- let r = {}, i = 0;
2391
- n && new URLSearchParams(n).forEach((e, t) => {
2392
- r[t] = e, i++;
2393
- });
2394
- let a = 0;
2395
- for (let e in this.cachedParams) a++;
2396
- let o = i !== a;
2397
- if (!o) {
2398
- for (let e in r) if (r[e] !== this.cachedParams[e]) {
2399
- o = !0;
2400
- break;
2401
- }
2402
- }
2403
- return o && (n.indexOf("%"), this.cachedParams = r), this.cachedParams;
2533
+ let e = this.getCurrentRawQuery();
2534
+ if (e === this.lastRawQuery) return this.cachedParams;
2535
+ this.lastRawQuery = e;
2536
+ let t = this.parseQueryParams(e);
2537
+ return this.areParamsEqual(t, this.cachedParams) ? this.cachedParams : (e.indexOf("%"), this.cachedParams = t, t);
2538
+ }
2539
+ getCurrentRawQuery() {
2540
+ if (this.isHistoryMode) return location.search.substring(1);
2541
+ let e = location.hash, t = e.indexOf("?");
2542
+ return t === -1 ? "" : e.substring(t + 1);
2543
+ }
2544
+ areParamsEqual(e, t) {
2545
+ let n = Object.keys(e);
2546
+ if (n.length !== Object.keys(t).length) return !1;
2547
+ for (let r of n) if (e[r] !== t[r]) return !1;
2548
+ return !0;
2549
+ }
2550
+ splitPath(e) {
2551
+ let t = e.indexOf("?"), n = t === -1 ? e : e.slice(0, t), r = t === -1 ? void 0 : e.slice(t + 1);
2552
+ return {
2553
+ route: n.replace(/^\/+/, ""),
2554
+ query: r
2555
+ };
2404
2556
  }
2405
2557
  setUrl(e) {
2406
- let t = this.isHistoryMode ? `${this.basePath}/${e}` : `#${e}`;
2407
- this.isHistoryMode ? hn(null, t) : location.hash = t, this.previousUrl = this.isHistoryMode ? t : location.hash;
2558
+ let { route: t, query: n } = this.splitPath(e), r = n ? `${t}?${n}` : t, i = this.isHistoryMode ? `${this.basePath}/${r}` : `#${r}`;
2559
+ this.isHistoryMode ? Rn(null, i) : location.hash = i, this.previousUrl = this.isHistoryMode ? i : location.hash;
2408
2560
  }
2409
2561
  restoreUrl() {
2410
- this.isHistoryMode ? hn(null, this.previousUrl) : location.hash = this.previousUrl;
2562
+ try {
2563
+ this.isHistoryMode ? history.replaceState(null, "", this.previousUrl) : location.hash = this.previousUrl;
2564
+ } catch (e) {
2565
+ W.warn(V.ROUTE, "Restore URL failed", e);
2566
+ }
2411
2567
  }
2412
2568
  renderRoute(e) {
2413
2569
  if (this.isDestroyed || !this.$target[0]) return;
2414
2570
  let { routes: t, notFound: n, beforeTransition: r, afterTransition: i } = this.config, a = t[e] ?? (n ? t[n] : void 0);
2415
2571
  if (!a) {
2416
- H.warn(B.ROUTE, V.ROUTE.NOT_FOUND(e));
2572
+ W.warn(V.ROUTE, H.ROUTE.NOT_FOUND(e));
2417
2573
  return;
2418
2574
  }
2419
2575
  let o = this.getQueryParams(), s = this.previousRoute;
2420
- r && E(() => r(s, e)), this.$target.empty();
2576
+ r && k(() => r(s, e)), this.$target.empty();
2421
2577
  let c = o;
2422
2578
  if (a.onEnter) {
2423
- let e = E(() => a.onEnter(o, this));
2579
+ let e = k(() => a.onEnter(o, this));
2424
2580
  e && (c = {
2425
2581
  ...o,
2426
2582
  ...e
@@ -2434,13 +2590,13 @@ var gn = class {
2434
2590
  let t = document.querySelector(a.template);
2435
2591
  if (t instanceof HTMLTemplateElement) e = t, this.templateCache.set(a.template, e);
2436
2592
  else {
2437
- H.warn(B.ROUTE, V.ROUTE.TEMPLATE_NOT_FOUND(a.template));
2593
+ W.warn(V.ROUTE, H.ROUTE.TEMPLATE_NOT_FOUND(a.template));
2438
2594
  return;
2439
2595
  }
2440
2596
  }
2441
2597
  this.$target.append(e.content.cloneNode(!0)), a.onMount && a.onMount(this.$target.children(), l, this);
2442
2598
  }
2443
- i && E(() => i(s, e)), this.previousRoute = e;
2599
+ i && k(() => i(s, e)), this.previousRoute = e;
2444
2600
  }
2445
2601
  handleUrlChange() {
2446
2602
  if (this.isDestroyed) return;
@@ -2448,7 +2604,7 @@ var gn = class {
2448
2604
  if (e === this.previousUrl) return;
2449
2605
  let t = this.getRouteName(), n = this.currentRouteAtom.peek();
2450
2606
  if (n !== t) {
2451
- if (E(() => this.config.routes[n]?.onLeave?.(this)) === !1) {
2607
+ if (k(() => this.config.routes[n]?.onLeave?.(this)) === !1) {
2452
2608
  this.restoreUrl();
2453
2609
  return;
2454
2610
  }
@@ -2464,34 +2620,33 @@ var gn = class {
2464
2620
  t != null && this.navigate(t);
2465
2621
  };
2466
2622
  e(document).on("click", "[data-route]", t), this.cleanups.push(() => e(document).off("click", "[data-route]", t));
2467
- let n = [], r = I(() => {
2623
+ let n = [], r = R(() => {
2468
2624
  let e = this.currentRouteAtom.value, t = this.activeClass;
2469
- E(() => {
2470
- let r = n.length;
2471
- for (let e = 0; e < r; e++) {
2472
- let r = n[e];
2473
- r.classList.remove(t), r.removeAttribute("aria-current");
2474
- }
2625
+ k(() => {
2626
+ for (let e of n) e.classList.remove(t), e.removeAttribute("aria-current");
2475
2627
  try {
2476
- let r = `[data-route="${e.replace(/"/g, "\\\"")}"]`, i = Array.from(document.querySelectorAll(r)), a = i.length;
2477
- for (let e = 0; e < a; e++) {
2478
- let n = i[e];
2479
- n.classList.add(t), n.setAttribute("aria-current", "page");
2480
- }
2628
+ let r = `[data-route="${e.replace(/"/g, "\\\"")}"]`, i = Array.from(document.querySelectorAll(r));
2629
+ for (let e of i) e.classList.add(t), e.setAttribute("aria-current", "page");
2481
2630
  n = i;
2482
2631
  } catch {
2483
2632
  n = [];
2484
2633
  }
2485
2634
  });
2486
2635
  });
2487
- this.cleanups.push(() => r.dispose());
2636
+ this.cleanups.push(() => {
2637
+ r.dispose(), n.length = 0;
2638
+ });
2488
2639
  }
2489
- navigate(e) {
2640
+ navigate(t) {
2490
2641
  if (this.isDestroyed) return;
2491
- let t = this.currentRouteAtom.peek();
2492
- if (this.config.routes[t]?.onLeave?.(this) === !1) return;
2493
- let n = e || this.config.default;
2494
- n && (this.setUrl(n), this.queryParamsAtom.value = {}, this.currentRouteAtom.value = n);
2642
+ let n = this.currentRouteAtom.peek();
2643
+ if (this.config.routes[n]?.onLeave?.(this) === !1) return;
2644
+ let { route: r, query: i } = this.splitPath(t), a = r || this.config.default || "";
2645
+ a && e.batch(() => {
2646
+ this.setUrl(t);
2647
+ let e = i ? this.parseQueryParams(i) : {};
2648
+ this.areParamsEqual(e, this.queryParamsAtom.peek()) || (this.queryParamsAtom.value = e), this.currentRouteAtom.value = a;
2649
+ });
2495
2650
  }
2496
2651
  destroy() {
2497
2652
  if (!this.isDestroyed) {
@@ -2499,44 +2654,33 @@ var gn = class {
2499
2654
  for (let e of this.cleanups) try {
2500
2655
  e();
2501
2656
  } catch {}
2502
- this.templateCache.clear();
2657
+ this.cleanups.length = 0, this.templateCache.clear();
2503
2658
  }
2504
2659
  }
2505
2660
  };
2506
- function _n(e) {
2507
- return new gn(e);
2661
+ function Bn(e) {
2662
+ return new zn(e);
2508
2663
  }
2509
- e.extend({ route: _n });
2664
+ e.extend({ route: Bn });
2510
2665
  //#endregion
2511
2666
  //#region src/features/fetch.ts
2512
- var vn = class {
2667
+ var Vn = class {
2513
2668
  constructor(t, n) {
2514
2669
  this.abortController = null, this.execute = async () => {
2515
- this.abortController?.abort(), this.abortController = new AbortController();
2516
- let { signal: t } = this.abortController, n = this.ajaxOptionsFn?.() ?? {}, r = {
2517
- ...this.staticOptions,
2518
- ...n,
2519
- headers: {
2520
- ...this.staticOptions.headers,
2521
- ...n.headers
2522
- },
2523
- url: this.isStaticUrl ? this.staticUrl : this.getUrl(),
2524
- success: void 0,
2525
- error: void 0,
2526
- complete: void 0
2527
- }, i = e.ajax(r);
2528
- t.onabort = () => i.abort(), t.aborted && i.abort();
2670
+ this.abort();
2671
+ let t = new AbortController();
2672
+ this.abortController = t;
2673
+ let { signal: n } = t, r;
2529
2674
  try {
2530
- let e = await i;
2531
- return this.transformFn ? this.transformFn(e) : e;
2675
+ let t = this.prepareSettings(), i = e.ajax(t);
2676
+ r = () => i.abort(), n.addEventListener("abort", r), n.aborted && i.abort();
2677
+ let a = await i;
2678
+ return this.transformFn ? this.transformFn(a) : a;
2532
2679
  } catch (e) {
2533
- if (t.aborted) {
2534
- let e = /* @__PURE__ */ Error("AbortError");
2535
- throw e.name = "AbortError", e;
2536
- }
2680
+ if (n.aborted) throw this.createAbortError();
2537
2681
  return this.handleError(e);
2538
2682
  } finally {
2539
- t.onabort = null, this.abortController?.signal === t && (this.abortController = null);
2683
+ r && n.removeEventListener("abort", r), this.abortController === t && (this.abortController = null);
2540
2684
  }
2541
2685
  };
2542
2686
  let r = typeof t == "string";
@@ -2544,12 +2688,11 @@ var vn = class {
2544
2688
  let i = typeof n.ajaxOptions == "object" ? n.ajaxOptions : {};
2545
2689
  this.staticOptions = {
2546
2690
  ...i,
2547
- method: n.method,
2548
2691
  headers: {
2549
2692
  ...i?.headers,
2550
2693
  ...n.headers
2551
2694
  }
2552
- }, this.transformFn = n.transform, this.onErrorFn = n.onError;
2695
+ }, n.method && (this.staticOptions.method = n.method), this.transformFn = n.transform, this.onErrorFn = n.onError;
2553
2696
  }
2554
2697
  abort() {
2555
2698
  this.abortController?.abort();
@@ -2565,20 +2708,41 @@ var vn = class {
2565
2708
  } catch {}
2566
2709
  throw t;
2567
2710
  }
2711
+ prepareSettings() {
2712
+ let e = this.ajaxOptionsFn?.() ?? {};
2713
+ return {
2714
+ ...this.staticOptions,
2715
+ ...e,
2716
+ headers: {
2717
+ ...this.staticOptions.headers,
2718
+ ...e.headers
2719
+ },
2720
+ url: this.isStaticUrl ? this.staticUrl : this.getUrl(),
2721
+ success: void 0,
2722
+ error: void 0,
2723
+ complete: void 0
2724
+ };
2725
+ }
2726
+ createAbortError() {
2727
+ let e = /* @__PURE__ */ Error("AbortError");
2728
+ return e.name = "AbortError", e;
2729
+ }
2568
2730
  };
2569
2731
  //#endregion
2570
2732
  //#region src/index.ts
2571
2733
  e.extend({ atomFetch(e, t) {
2572
- let n = new vn(e, t), r = F(n.execute, {
2734
+ let n = new Vn(e, t), r = Oe(n.execute, {
2573
2735
  defaultValue: t.defaultValue,
2574
2736
  lazy: t.eager === !1
2575
- });
2576
- return Object.assign(r, { abort: () => n.abort() });
2737
+ }), i = r.dispose.bind(r);
2738
+ return r.dispose = () => {
2739
+ n.abort(), i();
2740
+ }, Object.assign(r, { abort: () => n.abort() });
2577
2741
  } }), e(() => {
2578
- dt(), ot(document.body);
2742
+ Ct(), document.body && dt(document.body);
2579
2743
  });
2580
- var yn = e;
2744
+ var Hn = e;
2581
2745
  //#endregion
2582
- export { yn as default, st as disableAutoCleanup, ft as disablejQueryOverrides, ot as enableAutoCleanup, dt as enablejQueryOverrides, R as isReactive, Qe as nextTick, W as registry };
2746
+ export { Hn as default, ft as disableAutoCleanup, wt as disablejQueryOverrides, dt as enableAutoCleanup, Ct as enablejQueryOverrides, Fe as isReactive, nt as nextTick, K as registry };
2583
2747
 
2584
2748
  //# sourceMappingURL=index.mjs.map