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