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