arethesis 0.1.3 → 0.1.5

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.
@@ -1221,18 +1221,18 @@ var C = class {
1221
1221
  this.map.delete(e);
1222
1222
  }
1223
1223
  };
1224
- function se(e) {
1224
+ function w(e) {
1225
1225
  try {
1226
1226
  return e === "memory" ? new oe() : e === "session" ? sessionStorage : e && typeof e == "object" ? e : localStorage;
1227
1227
  } catch {
1228
1228
  return new oe();
1229
1229
  }
1230
1230
  }
1231
- function ce(e) {
1231
+ function se(e) {
1232
1232
  let t = e.replace(/-/g, "+").replace(/_/g, "/"), n = t + "=".repeat((4 - t.length % 4) % 4), r = atob(n), i = Uint8Array.from(r, (e) => e.charCodeAt(0));
1233
1233
  return new TextDecoder().decode(i);
1234
1234
  }
1235
- var w = class extends f {
1235
+ var T = class extends f {
1236
1236
  config;
1237
1237
  storage;
1238
1238
  refreshPromise = null;
@@ -1247,7 +1247,7 @@ var w = class extends f {
1247
1247
  refreshThreshold: 60,
1248
1248
  refreshBodyField: "refresh_token",
1249
1249
  ...e
1250
- }, this.storage = se(e.storage), this.fetchImpl = t.fetch ?? (() => globalThis.fetch.bind(globalThis)), this.resolveUrl = t.resolveUrl ?? ((e) => e), typeof window < "u" && (e.storage === void 0 || e.storage === "local") && (this.storageListener = (e) => {
1250
+ }, this.storage = w(e.storage), this.fetchImpl = t.fetch ?? (() => globalThis.fetch.bind(globalThis)), this.resolveUrl = t.resolveUrl ?? ((e) => e), typeof window < "u" && (e.storage === void 0 || e.storage === "local") && (this.storageListener = (e) => {
1251
1251
  (e.key === this.config.accessTokenKey || e.key === null) && (this.parsed = null, this.emit("change", { authenticated: this.isAuthenticated() }));
1252
1252
  }, window.addEventListener("storage", this.storageListener));
1253
1253
  }
@@ -1286,7 +1286,7 @@ var w = class extends f {
1286
1286
  else {
1287
1287
  let n = e.split(".");
1288
1288
  if (n.length === 3) try {
1289
- let e = JSON.parse(ce(n[1]));
1289
+ let e = JSON.parse(se(n[1]));
1290
1290
  t = e && typeof e == "object" ? e : null;
1291
1291
  } catch {
1292
1292
  t = null;
@@ -1397,7 +1397,7 @@ var w = class extends f {
1397
1397
  destroy() {
1398
1398
  this.storageListener && window.removeEventListener("storage", this.storageListener), this.storageListener = null, this.clear();
1399
1399
  }
1400
- }, T = class extends f {
1400
+ }, E = class extends f {
1401
1401
  options;
1402
1402
  attempts = 0;
1403
1403
  timer = null;
@@ -1432,7 +1432,7 @@ var w = class extends f {
1432
1432
  cancel() {
1433
1433
  this.timer && clearTimeout(this.timer), this.timer = null, this.attempts = 0;
1434
1434
  }
1435
- }, le = class {
1435
+ }, ce = class {
1436
1436
  config;
1437
1437
  source = null;
1438
1438
  store = null;
@@ -1444,7 +1444,7 @@ var w = class extends f {
1444
1444
  handlers = new f();
1445
1445
  customEvents = /* @__PURE__ */ new Set();
1446
1446
  constructor(e) {
1447
- this.config = e, this.policy = new T(e);
1447
+ this.config = e, this.policy = new E(e);
1448
1448
  }
1449
1449
  connectStore(e, t) {
1450
1450
  this.store = e, this.listViews = t ?? null;
@@ -1556,7 +1556,7 @@ var w = class extends f {
1556
1556
  disconnect() {
1557
1557
  this.generation++, this.policy.cancel(), this.source?.close(), this.source = null, this.policy.status = "closed";
1558
1558
  }
1559
- }, ue = /* @__PURE__ */ new Set(["ping", "pong"]), de = class {
1559
+ }, le = /* @__PURE__ */ new Set(["ping", "pong"]), ue = class {
1560
1560
  config;
1561
1561
  socket = null;
1562
1562
  channels = /* @__PURE__ */ new Map();
@@ -1571,7 +1571,7 @@ var w = class extends f {
1571
1571
  pingInterval: 3e4,
1572
1572
  maxQueue: 1e3,
1573
1573
  ...e
1574
- }, this.policy = new T(e);
1574
+ }, this.policy = new E(e);
1575
1575
  }
1576
1576
  setTokenProvider(e) {
1577
1577
  this.getToken = e;
@@ -1626,7 +1626,7 @@ var w = class extends f {
1626
1626
  console.error("WebSocket: ignoring non-JSON message");
1627
1627
  return;
1628
1628
  }
1629
- t && typeof t.type == "string" && !ue.has(t.type) && this.dispatch(t);
1629
+ t && typeof t.type == "string" && !le.has(t.type) && this.dispatch(t);
1630
1630
  };
1631
1631
  }
1632
1632
  dispatch(e) {
@@ -1692,7 +1692,7 @@ var w = class extends f {
1692
1692
  }
1693
1693
  this.policy.status = "closed";
1694
1694
  }
1695
- }, fe = "json.webpubsub.azure.v1", pe = class {
1695
+ }, de = "json.webpubsub.azure.v1", fe = class {
1696
1696
  config;
1697
1697
  socket = null;
1698
1698
  channels = /* @__PURE__ */ new Map();
@@ -1713,7 +1713,7 @@ var w = class extends f {
1713
1713
  ackTimeout: 15e3,
1714
1714
  autoJoinGroups: [],
1715
1715
  ...e
1716
- }, this.policy = new T(e);
1716
+ }, this.policy = new E(e);
1717
1717
  }
1718
1718
  connectStore(e, t) {
1719
1719
  this.store = e, this.listViews = t ?? null;
@@ -1749,7 +1749,7 @@ var w = class extends f {
1749
1749
  return;
1750
1750
  }
1751
1751
  if (e !== this.generation) return;
1752
- let n = this.config.socketFactory ? this.config.socketFactory(t, fe) : new WebSocket(t, fe);
1752
+ let n = this.config.socketFactory ? this.config.socketFactory(t, de) : new WebSocket(t, de);
1753
1753
  this.socket = n, n.onmessage = (e) => {
1754
1754
  if (this.socket !== n) return;
1755
1755
  let t;
@@ -1901,8 +1901,8 @@ var w = class extends f {
1901
1901
  }
1902
1902
  this.policy.status = "closed";
1903
1903
  }
1904
- }, E = (e) => typeof e == "number" && e > 0, me = (e) => typeof e == "number" && e < 0, D = (e) => typeof e == "string";
1905
- function O(e) {
1904
+ }, D = (e) => typeof e == "number" && e > 0, pe = (e) => typeof e == "number" && e < 0, O = (e) => typeof e == "string";
1905
+ function me(e) {
1906
1906
  return e === void 0 ? "none" : typeof e == "string" ? "insert" : e > 0 ? "retain" : "delete";
1907
1907
  }
1908
1908
  var k = class e {
@@ -1914,16 +1914,16 @@ var k = class e {
1914
1914
  if (e === 0) return this;
1915
1915
  this.baseLength += e, this.targetLength += e;
1916
1916
  let t = this.ops[this.ops.length - 1];
1917
- return t !== void 0 && E(t) ? this.ops[this.ops.length - 1] = t + e : this.ops.push(e), this;
1917
+ return t !== void 0 && D(t) ? this.ops[this.ops.length - 1] = t + e : this.ops.push(e), this;
1918
1918
  }
1919
1919
  insert(e) {
1920
1920
  if (e === "") return this;
1921
1921
  this.targetLength += e.length;
1922
1922
  let t = this.ops, n = t[t.length - 1];
1923
- if (n !== void 0 && D(n)) t[t.length - 1] = n + e;
1924
- else if (n !== void 0 && me(n)) {
1923
+ if (n !== void 0 && O(n)) t[t.length - 1] = n + e;
1924
+ else if (n !== void 0 && pe(n)) {
1925
1925
  let r = t[t.length - 2];
1926
- r !== void 0 && D(r) ? t[t.length - 2] = r + e : (t[t.length] = n, t[t.length - 2] = e);
1926
+ r !== void 0 && O(r) ? t[t.length - 2] = r + e : (t[t.length] = n, t[t.length - 2] = e);
1927
1927
  } else t.push(e);
1928
1928
  return this;
1929
1929
  }
@@ -1932,27 +1932,27 @@ var k = class e {
1932
1932
  if (t === 0) return this;
1933
1933
  this.baseLength += t;
1934
1934
  let n = this.ops[this.ops.length - 1];
1935
- return n !== void 0 && me(n) ? this.ops[this.ops.length - 1] = n - t : this.ops.push(-t), this;
1935
+ return n !== void 0 && pe(n) ? this.ops[this.ops.length - 1] = n - t : this.ops.push(-t), this;
1936
1936
  }
1937
1937
  isNoop() {
1938
- return this.ops.length === 0 || this.ops.length === 1 && E(this.ops[0]);
1938
+ return this.ops.length === 0 || this.ops.length === 1 && D(this.ops[0]);
1939
1939
  }
1940
1940
  apply(e) {
1941
1941
  if (e.length !== this.baseLength) throw Error(`Operation base length ${this.baseLength} does not match document length ${e.length}`);
1942
1942
  let t = [], n = 0;
1943
- for (let r of this.ops) E(r) ? (t.push(e.slice(n, n + r)), n += r) : D(r) ? t.push(r) : n -= r;
1943
+ for (let r of this.ops) D(r) ? (t.push(e.slice(n, n + r)), n += r) : O(r) ? t.push(r) : n -= r;
1944
1944
  return t.join("");
1945
1945
  }
1946
1946
  invert(t) {
1947
1947
  let n = new e(), r = 0;
1948
- for (let e of this.ops) E(e) ? (n.retain(e), r += e) : D(e) ? n.delete(e.length) : (n.insert(t.slice(r, r - e)), r -= e);
1948
+ for (let e of this.ops) D(e) ? (n.retain(e), r += e) : O(e) ? n.delete(e.length) : (n.insert(t.slice(r, r - e)), r -= e);
1949
1949
  return n;
1950
1950
  }
1951
1951
  compose(t) {
1952
1952
  if (this.targetLength !== t.baseLength) throw Error("compose: length mismatch");
1953
1953
  let n = new e(), r = this.ops, i = t.ops, a = 0, o = 0, s = r[a++], c = i[o++];
1954
1954
  for (;;) {
1955
- let e = O(s), t = O(c);
1955
+ let e = me(s), t = me(c);
1956
1956
  if (e === "none" && t === "none") break;
1957
1957
  if (e === "delete") n.delete(s), s = r[a++];
1958
1958
  else if (t === "insert") n.insert(c), c = i[o++];
@@ -1979,7 +1979,7 @@ var k = class e {
1979
1979
  if (t.baseLength !== n.baseLength) throw Error("transform: operations must share a base");
1980
1980
  let r = new e(), i = new e(), a = t.ops, o = n.ops, s = 0, c = 0, l = a[s++], u = o[c++];
1981
1981
  for (;;) {
1982
- let e = O(l), t = O(u);
1982
+ let e = me(l), t = me(u);
1983
1983
  if (e === "none" && t === "none") break;
1984
1984
  if (e === "insert") {
1985
1985
  r.insert(l), i.retain(l.length), l = a[s++];
@@ -1999,7 +1999,7 @@ var k = class e {
1999
1999
  let n = e, r = 0;
2000
2000
  for (let i of this.ops) {
2001
2001
  if (r > e) break;
2002
- E(i) ? r += i : D(i) ? (r < e || r === e && !t) && (n += i.length) : (n -= Math.min(-i, Math.max(0, e - r)), r -= i);
2002
+ D(i) ? r += i : O(i) ? (r < e || r === e && !t) && (n += i.length) : (n -= Math.min(-i, Math.max(0, e - r)), r -= i);
2003
2003
  }
2004
2004
  return n;
2005
2005
  }
@@ -2025,7 +2025,7 @@ var k = class e {
2025
2025
  return n;
2026
2026
  }
2027
2027
  toString() {
2028
- return this.ops.map((e) => E(e) ? `retain ${e}` : D(e) ? `insert ${JSON.stringify(e)}` : `delete ${-e}`).join(", ");
2028
+ return this.ops.map((e) => D(e) ? `retain ${e}` : O(e) ? `insert ${JSON.stringify(e)}` : `delete ${-e}`).join(", ");
2029
2029
  }
2030
2030
  }, he = class {
2031
2031
  callbacks;
@@ -2064,7 +2064,7 @@ var k = class e {
2064
2064
  let t = e;
2065
2065
  return this.outstanding && (t = this.outstanding.transformIndex(t)), this.buffer && (t = this.buffer.transformIndex(t)), t;
2066
2066
  }
2067
- }, ge = class {
2067
+ }, A = class {
2068
2068
  element;
2069
2069
  previous;
2070
2070
  composing = !1;
@@ -2117,10 +2117,10 @@ var k = class e {
2117
2117
  destroy() {
2118
2118
  this.controller.abort();
2119
2119
  }
2120
- }, _e = /* @__PURE__ */ "boxSizing.width.height.overflowX.overflowY.borderTopWidth.borderRightWidth.borderBottomWidth.borderLeftWidth.paddingTop.paddingRight.paddingBottom.paddingLeft.fontStyle.fontVariant.fontWeight.fontStretch.fontSize.lineHeight.fontFamily.textAlign.textTransform.textIndent.letterSpacing.wordSpacing.tabSize.whiteSpace.wordBreak.overflowWrap".split(".");
2121
- function ve(e, t) {
2120
+ }, ge = /* @__PURE__ */ "boxSizing.width.height.overflowX.overflowY.borderTopWidth.borderRightWidth.borderBottomWidth.borderLeftWidth.paddingTop.paddingRight.paddingBottom.paddingLeft.fontStyle.fontVariant.fontWeight.fontStretch.fontSize.lineHeight.fontFamily.textAlign.textTransform.textIndent.letterSpacing.wordSpacing.tabSize.whiteSpace.wordBreak.overflowWrap".split(".");
2121
+ function _e(e, t) {
2122
2122
  let n = document.createElement("div"), r = getComputedStyle(e);
2123
- for (let e of _e) n.style[e] = r[e];
2123
+ for (let e of ge) n.style[e] = r[e];
2124
2124
  Object.assign(n.style, {
2125
2125
  position: "absolute",
2126
2126
  visibility: "hidden",
@@ -2139,7 +2139,7 @@ function ve(e, t) {
2139
2139
  };
2140
2140
  return n.remove(), o;
2141
2141
  }
2142
- var ye = class {
2142
+ var ve = class {
2143
2143
  textarea;
2144
2144
  layer;
2145
2145
  cursors = [];
@@ -2173,7 +2173,7 @@ var ye = class {
2173
2173
  this.layer.replaceChildren();
2174
2174
  for (let r of this.cursors) {
2175
2175
  if (!r.selection) continue;
2176
- let i = r.user?.color ?? "#7c3aed", a = ve(e, Math.min(r.selection.head, e.value.length)), o = document.createElement("div");
2176
+ let i = r.user?.color ?? "#7c3aed", a = _e(e, Math.min(r.selection.head, e.value.length)), o = document.createElement("div");
2177
2177
  o.className = "collab-cursor", Object.assign(o.style, {
2178
2178
  position: "absolute",
2179
2179
  top: `${t + a.top}px`,
@@ -2196,7 +2196,7 @@ var ye = class {
2196
2196
  destroy() {
2197
2197
  cancelAnimationFrame(this.frame), this.controller.abort(), this.layer.remove();
2198
2198
  }
2199
- }, be = class extends f {
2199
+ }, ye = class extends f {
2200
2200
  ws;
2201
2201
  options;
2202
2202
  docId;
@@ -2212,9 +2212,10 @@ var ye = class {
2212
2212
  opCounter = 0;
2213
2213
  presenceTimer = null;
2214
2214
  _status = "connecting";
2215
+ wasReadOnly = null;
2215
2216
  clientId = null;
2216
2217
  constructor(e, t, n, r = {}) {
2217
- super(), this.ws = e, this.options = r, this.docId = t, this.channel = `doc:${t}`, this.adapter = n instanceof HTMLElement ? new ge(n) : n, n instanceof HTMLTextAreaElement && r.cursors !== !1 && (this.overlay = new ye(n)), n instanceof HTMLElement && n.setAttribute("aria-busy", "true"), this.adapter.attach((e) => this.handleLocalEdit(e), (e) => this.queuePresence(e)), this.unsubscribe = e.subscribe(this.channel, (e) => this.handleMessage(e)), this.offOpen = e.onOpen(() => this.join()), this.offStatus = e.onStatusChange((e) => {
2218
+ super(), this.ws = e, this.options = r, this.docId = t, this.channel = `doc:${t}`, this.adapter = n instanceof HTMLElement ? new A(n) : n, n instanceof HTMLTextAreaElement && r.cursors !== !1 && (this.overlay = new ve(n)), n instanceof HTMLElement && (n.setAttribute("aria-busy", "true"), (n instanceof HTMLTextAreaElement || n instanceof HTMLInputElement) && (this.wasReadOnly = n.readOnly, n.readOnly = !0)), this.adapter.attach((e) => this.handleLocalEdit(e), (e) => this.queuePresence(e)), this.unsubscribe = e.subscribe(this.channel, (e) => this.handleMessage(e)), this.offOpen = e.onOpen(() => this.join()), this.offStatus = e.onStatusChange((e) => {
2218
2219
  e !== "open" && this.setStatus("offline");
2219
2220
  }), e.isConnected ? this.join() : e.connect();
2220
2221
  }
@@ -2291,7 +2292,7 @@ var ye = class {
2291
2292
  }
2292
2293
  this.cursors.clear();
2293
2294
  for (let t of e.peers ?? []) this.cursors.set(t.clientId, t);
2294
- this.emitPresence(), this.adapter instanceof ge && this.adapter.element.removeAttribute("aria-busy"), this.updateStatus();
2295
+ this.emitPresence(), this.adapter instanceof A && (this.adapter.element.removeAttribute("aria-busy"), this.wasReadOnly !== null && (this.adapter.element.readOnly = this.wasReadOnly), this.wasReadOnly = null), this.updateStatus();
2295
2296
  }
2296
2297
  sendOp(e, t) {
2297
2298
  this.outstandingOpId = `${this.clientId ?? "c"}-${++this.opCounter}`, this.ws.send({
@@ -2357,9 +2358,9 @@ var ye = class {
2357
2358
  this.presenceTimer && clearTimeout(this.presenceTimer), this.ws.isConnected && this.ws.send({
2358
2359
  type: "collab:leave",
2359
2360
  channel: this.channel
2360
- }), this.unsubscribe?.(), this.offOpen?.(), this.offStatus?.(), this.adapter.destroy(), this.overlay?.destroy(), this.clear();
2361
+ }), this.unsubscribe?.(), this.offOpen?.(), this.offStatus?.(), this.adapter instanceof A && this.wasReadOnly !== null && (this.adapter.element.readOnly = this.wasReadOnly, this.adapter.element.removeAttribute("aria-busy")), this.adapter.destroy(), this.overlay?.destroy(), this.clear();
2361
2362
  }
2362
- }, xe = class {
2363
+ }, be = class {
2363
2364
  getWs;
2364
2365
  constructor(e) {
2365
2366
  this.getWs = e;
@@ -2367,17 +2368,17 @@ var ye = class {
2367
2368
  open(e, t, n = {}) {
2368
2369
  let r = this.getWs();
2369
2370
  if (!r) throw Error("Collaboration needs a WebSocket: pass `websocket` to Arethesis.init().");
2370
- return new be(r, e, t, n);
2371
+ return new ye(r, e, t, n);
2371
2372
  }
2372
- }, Se = /^(\d{4})-(\d{2})-(\d{2})$/;
2373
- function A(e) {
2373
+ }, xe = /^(\d{4})-(\d{2})-(\d{2})$/;
2374
+ function j(e) {
2374
2375
  if (e == null || e === "") return null;
2375
2376
  if (e instanceof Date) return isNaN(e.getTime()) ? null : e;
2376
2377
  if (typeof e == "number") {
2377
2378
  let t = new Date(e);
2378
2379
  return isNaN(t.getTime()) ? null : t;
2379
2380
  }
2380
- let t = String(e), n = Se.exec(t);
2381
+ let t = String(e), n = xe.exec(t);
2381
2382
  if (n) {
2382
2383
  let e = new Date(Number(n[1]), Number(n[2]) - 1, Number(n[3]));
2383
2384
  return isNaN(e.getTime()) ? null : e;
@@ -2385,45 +2386,45 @@ function A(e) {
2385
2386
  let r = new Date(t);
2386
2387
  return isNaN(r.getTime()) ? null : r;
2387
2388
  }
2388
- var j = (e, t = 2) => String(e).padStart(t, "0");
2389
- function M(e) {
2390
- return `${e.getFullYear()}-${j(e.getMonth() + 1)}-${j(e.getDate())}`;
2389
+ var M = (e, t = 2) => String(e).padStart(t, "0");
2390
+ function N(e) {
2391
+ return `${e.getFullYear()}-${M(e.getMonth() + 1)}-${M(e.getDate())}`;
2391
2392
  }
2392
- function Ce(e) {
2393
- return `${M(e)}T${j(e.getHours())}:${j(e.getMinutes())}`;
2393
+ function Se(e) {
2394
+ return `${N(e)}T${M(e.getHours())}:${M(e.getMinutes())}`;
2394
2395
  }
2395
- function N(e) {
2396
+ function P(e) {
2396
2397
  return new Date(e.getFullYear(), e.getMonth(), e.getDate());
2397
2398
  }
2398
- var we = /YYYY|YY|MM|M|DD|D|HH|H|hh|h|mm|ss|A/g;
2399
- function Te(e, t) {
2399
+ var Ce = /YYYY|YY|MM|M|DD|D|HH|H|hh|h|mm|ss|A/g;
2400
+ function we(e, t) {
2400
2401
  let n = e.getHours() % 12 || 12, r = {
2401
2402
  YYYY: String(e.getFullYear()),
2402
2403
  YY: String(e.getFullYear()).slice(-2),
2403
- MM: j(e.getMonth() + 1),
2404
+ MM: M(e.getMonth() + 1),
2404
2405
  M: String(e.getMonth() + 1),
2405
- DD: j(e.getDate()),
2406
+ DD: M(e.getDate()),
2406
2407
  D: String(e.getDate()),
2407
- HH: j(e.getHours()),
2408
+ HH: M(e.getHours()),
2408
2409
  H: String(e.getHours()),
2409
- hh: j(n),
2410
+ hh: M(n),
2410
2411
  h: String(n),
2411
- mm: j(e.getMinutes()),
2412
- ss: j(e.getSeconds()),
2412
+ mm: M(e.getMinutes()),
2413
+ ss: M(e.getSeconds()),
2413
2414
  A: e.getHours() < 12 ? "AM" : "PM"
2414
2415
  };
2415
- return t.split(/(\[[^\]]*\])/).map((e) => e.startsWith("[") && e.endsWith("]") ? e.slice(1, -1) : e.replace(we, (e) => r[e])).join("");
2416
+ return t.split(/(\[[^\]]*\])/).map((e) => e.startsWith("[") && e.endsWith("]") ? e.slice(1, -1) : e.replace(Ce, (e) => r[e])).join("");
2416
2417
  }
2417
2418
  // src/binding/validation-engine.ts
2418
- var P = (e) => e == null || e === "" || Array.isArray(e) && e.length === 0, Ee = /^[^\s@]+@[^\s@.]+(?:\.[^\s@.]+)+$/, De = /^\+?[\d\s\-().]+$/, Oe = class {
2419
+ var F = (e) => e == null || e === "" || Array.isArray(e) && e.length === 0, Te = /^[^\s@]+@[^\s@.]+(?:\.[^\s@.]+)+$/, Ee = /^\+?[\d\s\-().]+$/, De = class {
2419
2420
  validators = /* @__PURE__ */ new Map();
2420
2421
  constructor() {
2421
2422
  this.registerBuiltIns();
2422
2423
  }
2423
2424
  registerBuiltIns() {
2424
2425
  let e = (e) => Array.isArray(e) ? e.length : String(e).length;
2425
- this.registerValidator("required", (e) => typeof e == "string" ? e.trim().length > 0 : typeof e == "boolean" ? e : !P(e), { message: "This field is required" }), this.registerValidator("email", (e) => P(e) || Ee.test(String(e)), { message: "Enter a valid email address" }), this.registerValidator("url", (e) => {
2426
- if (P(e)) return !0;
2426
+ this.registerValidator("required", (e) => typeof e == "string" ? e.trim().length > 0 : typeof e == "boolean" ? e : !F(e), { message: "This field is required" }), this.registerValidator("email", (e) => F(e) || Te.test(String(e)), { message: "Enter a valid email address" }), this.registerValidator("url", (e) => {
2427
+ if (F(e)) return !0;
2427
2428
  try {
2428
2429
  let t = new URL(String(e));
2429
2430
  return t.protocol === "http:" || t.protocol === "https:";
@@ -2431,16 +2432,16 @@ var P = (e) => e == null || e === "" || Array.isArray(e) && e.length === 0, Ee =
2431
2432
  return !1;
2432
2433
  }
2433
2434
  }, { message: "Enter a valid URL" }), this.registerValidator("phone", (e) => {
2434
- if (P(e)) return !0;
2435
+ if (F(e)) return !0;
2435
2436
  let t = String(e), n = t.replace(/\D/g, "").length;
2436
- return De.test(t) && n >= 7 && n <= 15;
2437
- }, { message: "Enter a valid phone number" }), this.registerValidator("minLength", (t, n) => P(t) || e(t) >= Number(n.min), { message: "Must be at least {min} characters" }), this.registerValidator("maxLength", (t, n) => P(t) || e(t) <= Number(n.max), { message: "Must be at most {max} characters" });
2437
+ return Ee.test(t) && n >= 7 && n <= 15;
2438
+ }, { message: "Enter a valid phone number" }), this.registerValidator("minLength", (t, n) => F(t) || e(t) >= Number(n.min), { message: "Must be at least {min} characters" }), this.registerValidator("maxLength", (t, n) => F(t) || e(t) <= Number(n.max), { message: "Must be at most {max} characters" });
2438
2439
  let t = (e) => typeof e == "number" ? e : Number(e);
2439
- this.registerValidator("numeric", (e) => P(e) || !isNaN(t(e)), { message: "Must be a number" }), this.registerValidator("integer", (e) => P(e) || Number.isInteger(t(e)), { message: "Must be a whole number" }), this.registerValidator("min", (e, n) => P(e) || !isNaN(t(e)) && t(e) >= Number(n.min), { message: "Must be at least {min}" }), this.registerValidator("max", (e, n) => P(e) || !isNaN(t(e)) && t(e) <= Number(n.max), { message: "Must be at most {max}" }), this.registerValidator("between", (e, n) => P(e) || !isNaN(t(e)) && t(e) >= Number(n.min) && t(e) <= Number(n.max), { message: "Must be between {min} and {max}" }), this.registerValidator("pattern", (e, t) => {
2440
- if (P(e)) return !0;
2440
+ this.registerValidator("numeric", (e) => F(e) || !isNaN(t(e)), { message: "Must be a number" }), this.registerValidator("integer", (e) => F(e) || Number.isInteger(t(e)), { message: "Must be a whole number" }), this.registerValidator("min", (e, n) => F(e) || !isNaN(t(e)) && t(e) >= Number(n.min), { message: "Must be at least {min}" }), this.registerValidator("max", (e, n) => F(e) || !isNaN(t(e)) && t(e) <= Number(n.max), { message: "Must be at most {max}" }), this.registerValidator("between", (e, n) => F(e) || !isNaN(t(e)) && t(e) >= Number(n.min) && t(e) <= Number(n.max), { message: "Must be between {min} and {max}" }), this.registerValidator("pattern", (e, t) => {
2441
+ if (F(e)) return !0;
2441
2442
  let n = t.pattern instanceof RegExp ? t.pattern : new RegExp(String(t.pattern), typeof t.flags == "string" ? t.flags : void 0);
2442
2443
  return n.lastIndex = 0, n.test(String(e));
2443
- }, { message: "Invalid format" }), this.registerValidator("oneOf", (e, t) => P(e) || Array.isArray(t.values) && t.values.includes(e), { message: "Choose a valid option" }), this.registerValidator("equals", (e, t, n) => e === n.data[String(t.field)], { message: "Must match {field}" }), this.registerValidator("date", (e) => P(e) || A(e) !== null, { message: "Enter a valid date" }), this.registerValidator("custom", (e, t, n) => {
2444
+ }, { message: "Invalid format" }), this.registerValidator("oneOf", (e, t) => F(e) || Array.isArray(t.values) && t.values.includes(e), { message: "Choose a valid option" }), this.registerValidator("equals", (e, t, n) => e === n.data[String(t.field)], { message: "Must match {field}" }), this.registerValidator("date", (e) => F(e) || j(e) !== null, { message: "Enter a valid date" }), this.registerValidator("custom", (e, t, n) => {
2444
2445
  let r = t.fn;
2445
2446
  return !r || r(e, n);
2446
2447
  }, { message: "Invalid value" });
@@ -2530,27 +2531,27 @@ var P = (e) => e == null || e === "" || Array.isArray(e) && e.length === 0, Ee =
2530
2531
  };
2531
2532
  return e.replace(/\{(\w+)\}/g, (e, t) => t in r ? String(r[t]) : e);
2532
2533
  }
2533
- }, ke = /* @__PURE__ */ new Set([
2534
+ }, Oe = /* @__PURE__ */ new Set([
2534
2535
  "http:",
2535
2536
  "https:",
2536
2537
  "mailto:",
2537
2538
  "tel:"
2538
- ]), Ae = /* @__PURE__ */ new Set([
2539
+ ]), ke = /* @__PURE__ */ new Set([
2539
2540
  "http:",
2540
2541
  "https:",
2541
2542
  "blob:"
2542
- ]), je = /^data:image\/(png|gif|jpe?g|webp|avif|svg\+xml);/i;
2543
- function F(e, t = "link") {
2543
+ ]), Ae = /^data:image\/(png|gif|jpe?g|webp|avif|svg\+xml);/i;
2544
+ function I(e, t = "link") {
2544
2545
  if (e == null) return "";
2545
2546
  let n = String(e).trim();
2546
2547
  if (n === "") return "";
2547
2548
  let r = n.replace(/[\u0000-\u001F\u007F\s]+/g, ""), i = /^([a-z][a-z0-9+.-]*):/i.exec(r);
2548
2549
  if (!i) return n;
2549
2550
  let a = `${i[1].toLowerCase()}:`;
2550
- return t === "image" ? a === "data:" ? je.test(r) && !/svg/i.test(r) ? n : "" : Ae.has(a) ? n : "" : ke.has(a) ? n : "";
2551
+ return t === "image" ? a === "data:" ? Ae.test(r) && !/svg/i.test(r) ? n : "" : ke.has(a) ? n : "" : Oe.has(a) ? n : "";
2551
2552
  }
2552
2553
  // src/utils/sanitize.ts
2553
- var Me = /* @__PURE__ */ "a.abbr.b.blockquote.br.code.del.div.em.figcaption.figure.h1.h2.h3.h4.h5.h6.hr.i.img.ins.kbd.li.mark.ol.p.pre.s.small.span.strong.sub.sup.table.tbody.td.tfoot.th.thead.tr.u.ul".split("."), Ne = {
2554
+ var je = /* @__PURE__ */ "a.abbr.b.blockquote.br.code.del.div.em.figcaption.figure.h1.h2.h3.h4.h5.h6.hr.i.img.ins.kbd.li.mark.ol.p.pre.s.small.span.strong.sub.sup.table.tbody.td.tfoot.th.thead.tr.u.ul".split("."), Me = {
2554
2555
  "*": [
2555
2556
  "class",
2556
2557
  "title",
@@ -2575,7 +2576,7 @@ var Me = /* @__PURE__ */ "a.abbr.b.blockquote.br.code.del.div.em.figcaption.figu
2575
2576
  "scope"
2576
2577
  ],
2577
2578
  ol: ["start"]
2578
- }, Pe = /* @__PURE__ */ new Set([
2579
+ }, Ne = /* @__PURE__ */ new Set([
2579
2580
  "script",
2580
2581
  "style",
2581
2582
  "iframe",
@@ -2596,12 +2597,12 @@ var Me = /* @__PURE__ */ "a.abbr.b.blockquote.br.code.del.div.em.figcaption.figu
2596
2597
  "frame",
2597
2598
  "frameset"
2598
2599
  ]);
2599
- function I(e, t = {}) {
2600
+ function L(e, t = {}) {
2600
2601
  if (e == null) return "";
2601
- let n = new Set(t.allowedTags ?? Me), r = t.allowedAttributes ?? Ne, i = new DOMParser().parseFromString(`<body>${String(e)}</body>`, "text/html");
2602
- return Fe(i.body, n, r), i.body.innerHTML;
2602
+ let n = new Set(t.allowedTags ?? je), r = t.allowedAttributes ?? Me, i = new DOMParser().parseFromString(`<body>${String(e)}</body>`, "text/html");
2603
+ return Pe(i.body, n, r), i.body.innerHTML;
2603
2604
  }
2604
- function Fe(e, t, n) {
2605
+ function Pe(e, t, n) {
2605
2606
  for (let r of Array.from(e.childNodes)) {
2606
2607
  if (r.nodeType === Node.COMMENT_NODE || r.nodeType === Node.PROCESSING_INSTRUCTION_NODE) {
2607
2608
  r.remove();
@@ -2609,44 +2610,44 @@ function Fe(e, t, n) {
2609
2610
  }
2610
2611
  if (r.nodeType !== Node.ELEMENT_NODE) continue;
2611
2612
  let e = r, i = e.tagName.toLowerCase();
2612
- Pe.has(i) ? e.remove() : (Fe(e, t, n), t.has(i) ? Ie(e, i, n) : e.replaceWith(...Array.from(e.childNodes)));
2613
+ Ne.has(i) ? e.remove() : (Pe(e, t, n), t.has(i) ? Fe(e, i, n) : e.replaceWith(...Array.from(e.childNodes)));
2613
2614
  }
2614
2615
  }
2615
- function Ie(e, t, n) {
2616
+ function Fe(e, t, n) {
2616
2617
  let r = /* @__PURE__ */ new Set([...n["*"] ?? [], ...n[t] ?? []]);
2617
2618
  for (let t of Array.from(e.attributes)) {
2618
2619
  let n = t.name.toLowerCase();
2619
2620
  if (!r.has(n) || n.startsWith("on")) e.removeAttribute(t.name);
2620
2621
  else if (n === "href") {
2621
- let n = F(t.value, "link");
2622
+ let n = I(t.value, "link");
2622
2623
  n ? e.setAttribute("href", n) : e.removeAttribute("href");
2623
2624
  } else if (n === "src") {
2624
- let n = F(t.value, "image");
2625
+ let n = I(t.value, "image");
2625
2626
  n ? e.setAttribute("src", n) : e.removeAttribute("src");
2626
2627
  }
2627
2628
  }
2628
2629
  t === "a" && e.getAttribute("target") === "_blank" && e.setAttribute("rel", "noopener noreferrer");
2629
2630
  }
2630
- function L(e) {
2631
+ function R(e) {
2631
2632
  return e == null ? "" : new DOMParser().parseFromString(String(e), "text/html").body.textContent ?? "";
2632
2633
  }
2633
2634
  // src/utils/dom.ts
2634
- function R(e) {
2635
+ function z(e) {
2635
2636
  return typeof CSS < "u" && typeof CSS.escape == "function" ? CSS.escape(e) : e.replace(/([^\w-])/g, "\\$1").replace(/^(\d)/, "\\3$1 ");
2636
2637
  }
2637
- function Le(e) {
2638
+ function Ie(e) {
2638
2639
  return e.replace(/-([a-z0-9])/g, (e, t) => t.toUpperCase());
2639
2640
  }
2640
- var Re = 0;
2641
- function z(e = "ar") {
2642
- return Re += 1, `${e}-${Re.toString(36)}`;
2641
+ var Le = 0;
2642
+ function B(e = "ar") {
2643
+ return Le += 1, `${e}-${Le.toString(36)}`;
2643
2644
  }
2644
- function ze(e) {
2645
+ function Re(e) {
2645
2646
  let t = document.createElement("template");
2646
2647
  return t.innerHTML = e, t.content;
2647
2648
  }
2648
2649
  // src/binding/data-binder.ts
2649
- var Be = /* @__PURE__ */ new Set([
2650
+ var ze = /* @__PURE__ */ new Set([
2650
2651
  "href",
2651
2652
  "src",
2652
2653
  "action",
@@ -2657,29 +2658,29 @@ var Be = /* @__PURE__ */ new Set([
2657
2658
  "background",
2658
2659
  "ping"
2659
2660
  ]);
2660
- function B(e) {
2661
+ function V(e) {
2661
2662
  return e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement || e instanceof HTMLSelectElement;
2662
2663
  }
2663
- function V(e) {
2664
+ function H(e) {
2664
2665
  return e instanceof HTMLElement && (e.isContentEditable || e.getAttribute("contenteditable") === "true");
2665
2666
  }
2666
- function Ve() {
2667
+ function Be() {
2667
2668
  return typeof document < "u" && document.documentElement.lang || "en-US";
2668
2669
  }
2669
- var He = class {
2670
+ var Ve = class {
2670
2671
  validationEngine;
2671
2672
  bindings = /* @__PURE__ */ new WeakMap();
2672
2673
  timers = /* @__PURE__ */ new WeakMap();
2673
2674
  validationRuns = /* @__PURE__ */ new WeakMap();
2674
2675
  touched = /* @__PURE__ */ new WeakSet();
2675
2676
  constructor(e) {
2676
- this.validationEngine = e ?? new Oe();
2677
+ this.validationEngine = e ?? new De();
2677
2678
  }
2678
2679
  bind(e, t, n) {
2679
2680
  this.unbind(e);
2680
2681
  let r = new AbortController(), i = [];
2681
2682
  for (let [t, r] of Object.entries(n.fields)) {
2682
- let n = r.selector ?? `[data-bind="${R(t)}"]`, a = Array.from(e.querySelectorAll(n));
2683
+ let n = r.selector ?? `[data-bind="${z(t)}"]`, a = Array.from(e.querySelectorAll(n));
2683
2684
  e.matches?.(n) && a.unshift(e), i.push({
2684
2685
  key: t,
2685
2686
  path: r.field ?? t,
@@ -2717,7 +2718,7 @@ var He = class {
2717
2718
  let n = r(t, e.path);
2718
2719
  if (!(e.initialized && s(n, e.lastValue))) {
2719
2720
  e.lastValue = n, e.initialized = !0;
2720
- for (let r of e.targets) r === document.activeElement && (B(r) || V(r)) && e.config.twoWay || this.applyValue(r, n, e.config, t);
2721
+ for (let r of e.targets) r === document.activeElement && (V(r) || H(r)) && e.config.twoWay || this.applyValue(r, n, e.config, t);
2721
2722
  }
2722
2723
  }
2723
2724
  }
@@ -2734,13 +2735,13 @@ var He = class {
2734
2735
  }
2735
2736
  }
2736
2737
  applyValue(e, t, n, r) {
2737
- n.visible && (e.hidden = !n.visible(t, r)), n.attribute ? this.applyAttribute(e, n.attribute, this.format(t, n, r)) : B(e) ? this.applyToControl(e, t, n) : n.inputType === "rich-text" && V(e) ? e.innerHTML = I(t) : this.applyToDisplay(e, t, n, r);
2738
+ n.visible && (e.hidden = !n.visible(t, r)), n.attribute ? this.applyAttribute(e, n.attribute, this.format(t, n, r)) : V(e) ? this.applyToControl(e, t, n) : n.inputType === "rich-text" && H(e) ? e.innerHTML = L(t) : this.applyToDisplay(e, t, n, r);
2738
2739
  }
2739
2740
  applyAttribute(e, t, n) {
2740
2741
  let r = t.toLowerCase();
2741
2742
  if (!(r.startsWith("on") || r === "style" && /expression|url\s*\(/i.test(n))) {
2742
- if (Be.has(r)) {
2743
- let i = F(n, r === "href" || r === "action" || r === "formaction" || r === "ping" ? "link" : "image");
2743
+ if (ze.has(r)) {
2744
+ let i = I(n, r === "href" || r === "action" || r === "formaction" || r === "ping" ? "link" : "image");
2744
2745
  i ? e.setAttribute(t, i) : e.removeAttribute(t);
2745
2746
  } else e.setAttribute(t, n);
2746
2747
  }
@@ -2748,20 +2749,20 @@ var He = class {
2748
2749
  format(e, t, n) {
2749
2750
  if (typeof t.format == "function") return t.format(e, n);
2750
2751
  if (e == null || e === "") return t.emptyText ?? "";
2751
- let r = t.locale ?? Ve(), i = t.displayType ?? "text";
2752
+ let r = t.locale ?? Be(), i = t.displayType ?? "text";
2752
2753
  switch (i) {
2753
2754
  case "date":
2754
2755
  case "datetime":
2755
2756
  case "time": {
2756
- let n = A(e);
2757
- return n ? typeof t.format == "string" ? Te(n, t.format) : i === "date" ? n.toLocaleDateString(r, t.intl) : i === "time" ? n.toLocaleTimeString(r, {
2757
+ let n = j(e);
2758
+ return n ? typeof t.format == "string" ? we(n, t.format) : i === "date" ? n.toLocaleDateString(r, t.intl) : i === "time" ? n.toLocaleTimeString(r, {
2758
2759
  hour: "numeric",
2759
2760
  minute: "2-digit",
2760
2761
  ...t.intl
2761
2762
  }) : n.toLocaleString(r, t.intl) : t.emptyText ?? "";
2762
2763
  }
2763
2764
  case "relative": {
2764
- let n = A(e);
2765
+ let n = j(e);
2765
2766
  return n ? Ke(n, r) : t.emptyText ?? "";
2766
2767
  }
2767
2768
  case "currency":
@@ -2788,10 +2789,10 @@ var He = class {
2788
2789
  let i = n.displayType ?? "text", a = this.format(t, n, r);
2789
2790
  switch (i) {
2790
2791
  case "html":
2791
- e.innerHTML = n.trusted ? String(t ?? "") : I(t);
2792
+ e.innerHTML = n.trusted ? String(t ?? "") : L(t);
2792
2793
  return;
2793
2794
  case "image": {
2794
- let n = F(t, "image");
2795
+ let n = I(t, "image");
2795
2796
  if (e instanceof HTMLImageElement) {
2796
2797
  n ? e.src = n : e.removeAttribute("src");
2797
2798
  return;
@@ -2803,7 +2804,7 @@ var He = class {
2803
2804
  return;
2804
2805
  }
2805
2806
  case "link": {
2806
- let i = F(n.href ? n.href(t, r) : t, "link"), o = n.linkText ?? a;
2807
+ let i = I(n.href ? n.href(t, r) : t, "link"), o = n.linkText ?? a;
2807
2808
  if (e instanceof HTMLAnchorElement) {
2808
2809
  i ? e.href = i : e.removeAttribute("href"), n.linkText === void 0 && e.dataset.keepText || (e.textContent = o);
2809
2810
  return;
@@ -2831,11 +2832,11 @@ var He = class {
2831
2832
  }
2832
2833
  case "relative": {
2833
2834
  e.textContent = a;
2834
- let r = typeof n.format == "function" ? null : A(t);
2835
+ let r = typeof n.format == "function" ? null : j(t);
2835
2836
  if (r) {
2836
- let t = n.locale ?? Ve();
2837
- e instanceof HTMLTimeElement && (e.dateTime = r.toISOString()), (!e.hasAttribute("title") || e.hasAttribute("data-relative-title")) && (e.setAttribute("title", r.toLocaleString(t)), e.setAttribute("data-relative-title", "")), n.live === !1 ? H.unwatch(e) : H.watch(e, r, t);
2838
- } else H.unwatch(e);
2837
+ let t = n.locale ?? Be();
2838
+ e instanceof HTMLTimeElement && (e.dateTime = r.toISOString()), (!e.hasAttribute("title") || e.hasAttribute("data-relative-title")) && (e.setAttribute("title", r.toLocaleString(t)), e.setAttribute("data-relative-title", "")), n.live === !1 ? Ge.unwatch(e) : Ge.watch(e, r, t);
2839
+ } else Ge.unwatch(e);
2839
2840
  return;
2840
2841
  }
2841
2842
  default: e.textContent = a;
@@ -2860,13 +2861,13 @@ var He = class {
2860
2861
  return;
2861
2862
  }
2862
2863
  case "date": {
2863
- let n = A(t);
2864
- e.value = n ? M(n) : "";
2864
+ let n = j(t);
2865
+ e.value = n ? N(n) : "";
2865
2866
  return;
2866
2867
  }
2867
2868
  case "datetime": {
2868
- let n = A(t);
2869
- e.value = n ? Ce(n) : "";
2869
+ let n = j(t);
2870
+ e.value = n ? Se(n) : "";
2870
2871
  return;
2871
2872
  }
2872
2873
  case "tags":
@@ -2877,7 +2878,7 @@ var He = class {
2877
2878
  }
2878
2879
  readValue(e, t) {
2879
2880
  let n;
2880
- if (B(e)) switch (this.inputTypeOf(e, t)) {
2881
+ if (V(e)) switch (this.inputTypeOf(e, t)) {
2881
2882
  case "checkbox":
2882
2883
  case "toggle":
2883
2884
  n = e.checked;
@@ -2894,14 +2895,14 @@ var He = class {
2894
2895
  break;
2895
2896
  default: n = e.value;
2896
2897
  }
2897
- else n = V(e) && t.inputType === "rich-text" ? I(e.innerHTML) : e.textContent;
2898
+ else n = H(e) && t.inputType === "rich-text" ? L(e.innerHTML) : e.textContent;
2898
2899
  return t.parse ? t.parse(n) : n;
2899
2900
  }
2900
2901
  values(e) {
2901
2902
  let t = this.bindings.get(e), n = {};
2902
2903
  if (!t) return n;
2903
2904
  for (let e of t.fields) {
2904
- let i = e.targets.find((e) => B(e) || V(e));
2905
+ let i = e.targets.find((e) => V(e) || H(e));
2905
2906
  n[e.key] = i ? this.readValue(i, e.config) : r(t.data, e.path);
2906
2907
  }
2907
2908
  return n;
@@ -2910,7 +2911,7 @@ var He = class {
2910
2911
  return new Set(e.config.validateOn ?? ["blur", "change"]);
2911
2912
  }
2912
2913
  listen(e, t, n) {
2913
- if (!(B(n) || V(n))) return;
2914
+ if (!(V(n) || H(n))) return;
2914
2915
  let { signal: r } = e.controller, i = t.config.validation, a = this.triggers(e), o = (r) => {
2915
2916
  let o = this.readValue(n, t.config), s = () => {
2916
2917
  t.config.twoWay && (t.lastValue = o, e.config.onChange?.(t.path, o));
@@ -2959,7 +2960,7 @@ var He = class {
2959
2960
  let n = [];
2960
2961
  for (let e of t.fields) {
2961
2962
  if (!e.config.validation) continue;
2962
- let i = e.targets.find((e) => B(e) || V(e));
2963
+ let i = e.targets.find((e) => V(e) || H(e));
2963
2964
  if (i) {
2964
2965
  this.touched.add(i);
2965
2966
  let r = await this.validateTarget(t, e, i);
@@ -2983,9 +2984,9 @@ var He = class {
2983
2984
  o.className = "error-summary__title", o.textContent = n.length === 1 ? "Please fix 1 error:" : `Please fix ${n.length} errors:`;
2984
2985
  let s = document.createElement("ul");
2985
2986
  for (let e of n) {
2986
- let n = document.createElement("li"), r = t.fields.find((t) => t.key === e.field), i = r?.config.validation?.label, a = i && !e.message.toLowerCase().includes(i.toLowerCase()) ? `${i}: ${e.message}` : e.message, o = r?.targets.find((e) => B(e) || V(e));
2987
+ let n = document.createElement("li"), r = t.fields.find((t) => t.key === e.field), i = r?.config.validation?.label, a = i && !e.message.toLowerCase().includes(i.toLowerCase()) ? `${i}: ${e.message}` : e.message, o = r?.targets.find((e) => V(e) || H(e));
2987
2988
  if (o) {
2988
- o.id ||= z("field");
2989
+ o.id ||= B("field");
2989
2990
  let e = document.createElement("a");
2990
2991
  e.href = `#${o.id}`, e.textContent = a, e.addEventListener("click", (e) => {
2991
2992
  e.preventDefault(), o.focus();
@@ -3015,14 +3016,14 @@ var He = class {
3015
3016
  let n = e.ownerDocument.getElementById(t);
3016
3017
  if (n?.classList.contains("field-error")) return n;
3017
3018
  }
3018
- let i = (t ? e.closest("form, [data-form], body")?.querySelector(`[data-error-for="${R(t)}"]`) : null) ?? null;
3019
+ let i = (t ? e.closest("form, [data-form], body")?.querySelector(`[data-error-for="${z(t)}"]`) : null) ?? null;
3019
3020
  if (!i) {
3020
3021
  if (!n) return null;
3021
3022
  i = document.createElement("div"), i.className = "field-error", i.setAttribute("data-generated", ""), e.insertAdjacentElement("afterend", i);
3022
3023
  }
3023
- return i.classList.add("field-error"), i.id || (i.id = z("error")), i.setAttribute("aria-live", "polite"), e.setAttribute("aria-describedby", [...r, i.id].join(" ")), i;
3024
+ return i.classList.add("field-error"), i.id || (i.id = B("error")), i.setAttribute("aria-live", "polite"), e.setAttribute("aria-describedby", [...r, i.id].join(" ")), i;
3024
3025
  }
3025
- }, Ue = [
3026
+ }, He = [
3026
3027
  ["year", 31536e3],
3027
3028
  ["month", 2592e3],
3028
3029
  ["week", 604800],
@@ -3031,11 +3032,11 @@ var He = class {
3031
3032
  ["minute", 60],
3032
3033
  ["second", 1]
3033
3034
  ];
3034
- function We(e, t) {
3035
+ function Ue(e, t) {
3035
3036
  let n = Math.abs(t - e.getTime()) / 1e3;
3036
3037
  return n < 60 ? 5e3 : n < 3600 ? 15e3 : n < 86400 ? 3e5 : 36e5;
3037
3038
  }
3038
- var Ge = class {
3039
+ var We = class {
3039
3040
  targets = /* @__PURE__ */ new Map();
3040
3041
  timer = null;
3041
3042
  listening = !1;
@@ -3072,13 +3073,13 @@ var Ge = class {
3072
3073
  schedule(e = Date.now()) {
3073
3074
  if (this.timer || this.targets.size === 0) return;
3074
3075
  let t = Infinity;
3075
- for (let { date: n } of this.targets.values()) t = Math.min(t, We(n, e));
3076
+ for (let { date: n } of this.targets.values()) t = Math.min(t, Ue(n, e));
3076
3077
  this.timer = setTimeout(() => this.tick(), t), !this.listening && typeof document < "u" && (document.addEventListener("visibilitychange", this.onVisibility), this.listening = !0);
3077
3078
  }
3078
- }, H = new Ge();
3079
+ }, Ge = new We();
3079
3080
  function Ke(e, t = "en-US", n = Date.now()) {
3080
3081
  let r = Math.round((e.getTime() - n) / 1e3), i = new Intl.RelativeTimeFormat(t, { numeric: "auto" });
3081
- for (let [e, t] of Ue) if (Math.abs(r) >= t || e === "second") return i.format(Math.round(r / t), e);
3082
+ for (let [e, t] of He) if (Math.abs(r) >= t || e === "second") return i.format(Math.round(r / t), e);
3082
3083
  return i.format(0, "second");
3083
3084
  }
3084
3085
  // src/components/runtime.ts
@@ -3103,7 +3104,7 @@ var Xe = class {
3103
3104
  this.fetchImpl = () => e;
3104
3105
  }
3105
3106
  register(e, t) {
3106
- this.files.set(e, ze(t));
3107
+ this.files.set(e, Re(t));
3107
3108
  for (let t of this.extracted.keys()) t.startsWith(`${e}#`) && this.extracted.delete(t);
3108
3109
  }
3109
3110
  async load(e, t) {
@@ -3113,7 +3114,7 @@ var Xe = class {
3113
3114
  return i || (i = this.extract(n, t, e), this.extracted.set(r, i)), i.cloneNode(!0);
3114
3115
  }
3115
3116
  async has(e, t) {
3116
- return (await this.loadFile(e)).querySelector(`template#${R(t)}`) !== null;
3117
+ return (await this.loadFile(e)).querySelector(`template#${z(t)}`) !== null;
3117
3118
  }
3118
3119
  loadFile(e) {
3119
3120
  let t = this.files.get(e);
@@ -3126,10 +3127,10 @@ var Xe = class {
3126
3127
  async fetchFile(e) {
3127
3128
  let t = await this.fetchImpl()(e);
3128
3129
  if (!t.ok) throw Error(`Failed to load template ${e} (${t.status})`);
3129
- return ze(await t.text());
3130
+ return Re(await t.text());
3130
3131
  }
3131
3132
  extract(e, t, n) {
3132
- let r = e.querySelector(`template#${R(t)}`);
3133
+ let r = e.querySelector(`template#${z(t)}`);
3133
3134
  if (r) return r.content.cloneNode(!0);
3134
3135
  if (t === "main" && !e.querySelector("template")) return e.cloneNode(!0);
3135
3136
  throw Error(`Template "#${t}" not found in ${n}`);
@@ -3200,7 +3201,7 @@ var Xe = class {
3200
3201
  console.error(`data-mixin-${t} is not valid JSON`);
3201
3202
  }
3202
3203
  let i = `data-mixin-${t}-`;
3203
- for (let t of Array.from(e.attributes)) t.name.startsWith(i) && (n[Le(t.name.slice(i.length))] = Qe(t.value));
3204
+ for (let t of Array.from(e.attributes)) t.name.startsWith(i) && (n[Ie(t.name.slice(i.length))] = Qe(t.value));
3204
3205
  return n;
3205
3206
  }
3206
3207
  init(e = document) {
@@ -3266,33 +3267,36 @@ var lt = class extends HTMLElement {
3266
3267
  static bindConfig;
3267
3268
  state = "idle";
3268
3269
  error = null;
3269
- mainTemplateId = "main";
3270
+ mainTemplateId = this.metadata?.templateId ?? "main";
3270
3271
  loadingTemplateId = "loading";
3271
3272
  errorTemplateId = "error";
3272
3273
  #e = null;
3273
- #t = [];
3274
- #n = null;
3275
- #r = [];
3276
- #i = 0;
3277
- #a = null;
3278
- #o = () => {};
3279
- #s = /* @__PURE__ */ new Map();
3280
- #c = null;
3274
+ #t = null;
3275
+ #n = [];
3276
+ #r = null;
3277
+ #i = [];
3278
+ #a = 0;
3279
+ #o = null;
3280
+ #s = () => {};
3281
+ #c = /* @__PURE__ */ new Map();
3281
3282
  #l = null;
3282
- #u = !1;
3283
+ #u = null;
3284
+ #d = !1;
3283
3285
  ready = new Promise((e) => {
3284
- this.#o = e;
3286
+ this.#s = e;
3285
3287
  });
3286
3288
  async connectedCallback() {
3287
- this.#n = new AbortController(), this.#u || (this.#u = !0, await st(), this.hasAttribute("data-hydrate") || !this.metadata?.templateKey ? this.#a = this.mainTemplateId : this.#a === null && await this.render(this.mainTemplateId), this.#o()), this.onConnected(), this.#p();
3289
+ this.#r = new AbortController(), this.#d || (this.#d = !0, await st(), this.hasAttribute("data-hydrate") || !this.metadata?.templateKey ? this.#o = this.mainTemplateId : this.#o === null && await this.render(this.mainTemplateId), this.#s()), this.onConnected();
3290
+ let e = this.#t;
3291
+ this.#t = null, e && !this.#e && this.bind(e.kind === "list" ? e.view : e.ref, e.config), this.#m();
3288
3292
  }
3289
3293
  disconnectedCallback() {
3290
- this.#n?.abort(), this.#n = null;
3291
- for (let e of this.#r.splice(0)) e.destroy();
3292
- this.#f(), this.onDisconnected();
3294
+ this.#r?.abort(), this.#r = null;
3295
+ for (let e of this.#i.splice(0)) e.destroy();
3296
+ this.#t = this.#e, this.#p(), this.onDisconnected();
3293
3297
  }
3294
3298
  get signal() {
3295
- return this.#n ||= new AbortController(), this.#n.signal;
3299
+ return this.#r ||= new AbortController(), this.#r.signal;
3296
3300
  }
3297
3301
  listen(e, t, n, r = {}) {
3298
3302
  e.addEventListener(t, n, {
@@ -3308,7 +3312,7 @@ var lt = class extends HTMLElement {
3308
3312
  }
3309
3313
  useMixin(e, t = {}, n = this) {
3310
3314
  let r = G.apply(n, e, t);
3311
- return r && this.#r.push(r), r;
3315
+ return r && this.#i.push(r), r;
3312
3316
  }
3313
3317
  on(e, t) {
3314
3318
  let n = (e) => t(e.detail, e);
@@ -3339,10 +3343,10 @@ var lt = class extends HTMLElement {
3339
3343
  }
3340
3344
  }
3341
3345
  async render(e) {
3342
- let t = ++this.#i, n = await this.loadTemplate(e);
3343
- return t !== this.#i || !n ? !1 : (this.replaceChildren(n), this.#a = e, this.#s.clear(), this.#c = null, this.#l?.disconnect(), this.#l = null, !0);
3346
+ let t = ++this.#a, n = await this.loadTemplate(e);
3347
+ return t !== this.#a || !n ? !1 : (this.replaceChildren(n), this.#o = e, this.#c.clear(), this.#l = null, this.#u?.disconnect(), this.#u = null, !0);
3344
3348
  }
3345
- #d(e) {
3349
+ #f(e) {
3346
3350
  this.state = e, this.dataset.state = e, this.toggleAttribute("aria-busy", e === "loading");
3347
3351
  }
3348
3352
  get bindConfig() {
@@ -3352,14 +3356,14 @@ var lt = class extends HTMLElement {
3352
3356
  return this.#e ? this.#e.kind === "object" ? this.#e.ref : this.#e.view : null;
3353
3357
  }
3354
3358
  bind(e, t) {
3355
- this.#f();
3359
+ this.#t = null, this.#p();
3356
3360
  let { store: n, listViews: r } = U();
3357
3361
  if (ct(e)) {
3358
3362
  this.#e = {
3359
3363
  kind: "list",
3360
3364
  view: e,
3361
3365
  config: t
3362
- }, this.#t.push(r.subscribe(e.id, (e) => void this.#y(e))), this.#t.push(n.subscribeToType(e.type, (e, t) => this.#C(e, t))), this.ready.then(() => this.#y(e)), (e.status === "idle" || e.status === "stale") && r.load(e).catch((e) => console.error(`<${this.localName}>: failed to load list`, e));
3366
+ }, this.#n.push(r.subscribe(e.id, (e) => void this.#b(e))), this.#n.push(n.subscribeToType(e.type, (e, t) => this.#w(e, t))), this.ready.then(() => this.#b(e)), (e.status === "idle" || e.status === "stale") && r.load(e).catch((e) => console.error(`<${this.localName}>: failed to load list`, e));
3363
3367
  return;
3364
3368
  }
3365
3369
  let i = {
@@ -3370,25 +3374,33 @@ var lt = class extends HTMLElement {
3370
3374
  kind: "object",
3371
3375
  ref: i,
3372
3376
  config: t
3373
- }, this.#t.push(n.subscribe(i.type, i.id, (e, t) => this.#h(e, t)));
3377
+ }, this.#n.push(n.subscribe(i.type, i.id, (e, t) => this.#g(e, t)));
3374
3378
  let a = n.get(i.type, i.id);
3375
- a ? (this.ready.then(() => this.#g(a)), a.status === "stale" && this.refetch()) : n.getTypeConfig(i.type).endpoint && this.refetch();
3379
+ a ? (this.ready.then(() => this.#_(a)), a.status === "stale" && this.refetch()) : n.getTypeConfig(i.type).endpoint && this.refetch();
3376
3380
  }
3377
3381
  bindList(e, t) {
3378
3382
  let n = U().listViews.getOrCreate(e);
3379
3383
  return this.bind(n, t), n;
3380
3384
  }
3381
3385
  unbind() {
3386
+ this.#t = null;
3382
3387
  let e = this.#e !== null;
3383
- this.#f(), e && (this.#d("idle"), this.onUnbind());
3384
- }
3385
- #f() {
3386
- for (let e of this.#t.splice(0)) e();
3387
- this.#l?.disconnect(), this.#l = null, this.#e && U().binder.unbind(this);
3388
- for (let e of this.#s.values()) U().binder.unbind(e);
3389
- this.#s.clear(), this.#e = null;
3388
+ this.#p(), e && (this.#f("idle"), this.onUnbind());
3390
3389
  }
3391
3390
  #p() {
3391
+ for (let e of this.#n.splice(0)) e();
3392
+ this.#u?.disconnect(), this.#u = null;
3393
+ let { binder: e } = U();
3394
+ if (this.#e && e.unbind(this), this.#e?.kind === "list") {
3395
+ let e = this.#y();
3396
+ this.#x(e), this.#l?.remove(), this.#l = null, e.removeAttribute("aria-busy");
3397
+ } else {
3398
+ for (let t of this.#c.values()) e.unbind(t);
3399
+ this.#c.clear();
3400
+ }
3401
+ this.#e = null;
3402
+ }
3403
+ #m() {
3392
3404
  if (this.#e) return;
3393
3405
  let e = this.getAttribute("data-source");
3394
3406
  if (e && e.includes(":")) {
@@ -3431,7 +3443,7 @@ var lt = class extends HTMLElement {
3431
3443
  let { type: r, id: i } = this.#e.ref, a = e.getTypeConfig(r).endpoint;
3432
3444
  if (!a) return;
3433
3445
  let o = e.has(r, i);
3434
- o ? e.setStatus(r, i, "updating") : (this.#d("loading"), await this.#m(this.loadingTemplateId));
3446
+ o ? e.setStatus(r, i, "updating") : (this.#f("loading"), await this.#h(this.loadingTemplateId));
3435
3447
  try {
3436
3448
  await t.fetchEndpoint(a, { id: i });
3437
3449
  } catch (t) {
@@ -3439,28 +3451,28 @@ var lt = class extends HTMLElement {
3439
3451
  o ? e.setStatus(r, i, "error") : await this.showError(t);
3440
3452
  }
3441
3453
  }
3442
- async #m(e) {
3443
- return this.#a === e ? !0 : await this.hasTemplate(e) ? this.render(e) : !1;
3454
+ async #h(e) {
3455
+ return this.#o === e ? !0 : await this.hasTemplate(e) ? this.render(e) : !1;
3444
3456
  }
3445
- #h(e, t) {
3446
- t === "delete" ? (this.#d("idle"), this.onUnbind()) : e && (t === "invalidate" ? (this.dataset.stale = "", U().store.subscriberCount(e.type, e.id) > 0 && this.refetch()) : this.#g(e));
3457
+ #g(e, t) {
3458
+ t === "delete" ? (this.#f("idle"), this.onUnbind()) : e && (t === "invalidate" ? (this.dataset.stale = "", U().store.subscriberCount(e.type, e.id) > 0 && this.refetch()) : this.#_(e));
3447
3459
  }
3448
- async #g(e) {
3460
+ async #_(e) {
3449
3461
  let { binder: t } = U();
3450
- if (this.#a !== this.mainTemplateId) {
3462
+ if (this.#o !== this.mainTemplateId) {
3451
3463
  if (!await this.render(this.mainTemplateId) && this.metadata?.templateKey) return;
3452
3464
  t.unbind(this);
3453
3465
  }
3454
3466
  if (this.#e?.kind !== "object" || this.#e.ref.id !== e.id || this.#e.ref.type !== e.type) return;
3455
- this.#d("loaded"), this.toggleAttribute("data-updating", e.status === "updating"), e.status !== "stale" && delete this.dataset.stale;
3467
+ this.#f("loaded"), this.toggleAttribute("data-updating", e.status === "updating"), e.status !== "stale" && delete this.dataset.stale;
3456
3468
  let n = this.bindConfig;
3457
3469
  if (n) {
3458
3470
  let r = t.getHandle(this);
3459
- r ? r.update(e.data) : t.bind(this, e.data, this.#_(n, e.type, e.id));
3471
+ r ? r.update(e.data) : t.bind(this, e.data, this.#v(n, e.type, e.id));
3460
3472
  }
3461
3473
  this.onBind(e);
3462
3474
  }
3463
- #_(e, t, n) {
3475
+ #v(e, t, n) {
3464
3476
  return e.onChange ? e : {
3465
3477
  ...e,
3466
3478
  onChange: (e, r) => {
@@ -3480,25 +3492,25 @@ var lt = class extends HTMLElement {
3480
3492
  }
3481
3493
  };
3482
3494
  }
3483
- #v() {
3495
+ #y() {
3484
3496
  let e = this.bindConfig?.itemsSelector ?? "[data-items]";
3485
3497
  return this.querySelector(e) ?? this;
3486
3498
  }
3487
- async #y(e) {
3488
- if (this.#e?.kind !== "list" || this.#e.view.id !== e.id || (await this.ready, this.#a !== this.mainTemplateId && !await this.render(this.mainTemplateId) && this.metadata?.templateKey)) return;
3489
- let t = this.bindConfig ?? { fields: {} }, n = this.#v();
3499
+ async #b(e) {
3500
+ if (this.#e?.kind !== "list" || this.#e.view.id !== e.id || (await this.ready, this.#o !== this.mainTemplateId && !await this.render(this.mainTemplateId) && this.metadata?.templateKey)) return;
3501
+ let t = this.bindConfig ?? { fields: {} }, n = this.#y();
3490
3502
  if (n.setAttribute("aria-busy", String(e.status === "loading" || e.status === "loading-more")), e.ids.length === 0) {
3491
- this.#b(n);
3503
+ this.#x(n);
3492
3504
  let r = e.status === "loading" || e.status === "idle" ? t.loadingTemplate : e.status === "error" ? t.errorTemplate : t.emptyTemplate;
3493
- this.#d(e.status === "error" ? "error" : e.status === "loaded" ? "empty" : "loading"), r && await this.#x(n, r, e.error), this.onListChange(e);
3494
- } else n.querySelector(":scope > [data-placeholder]")?.remove(), this.#d(e.status === "error" ? "error" : "loaded"), await this.#S(n, e, t), t.infiniteScroll && this.#w(n, e, t), this.onListChange(e);
3505
+ this.#f(e.status === "error" ? "error" : e.status === "loaded" ? "empty" : "loading"), r && await this.#S(n, r, e.error), this.onListChange(e);
3506
+ } else n.querySelector(":scope > [data-placeholder]")?.remove(), this.#f(e.status === "error" ? "error" : "loaded"), await this.#C(n, e, t), t.infiniteScroll && this.#T(n, e, t), this.onListChange(e);
3495
3507
  }
3496
- #b(e) {
3508
+ #x(e) {
3497
3509
  let { binder: t } = U();
3498
- for (let e of this.#s.values()) t.unbind(e), e.remove();
3499
- this.#s.clear(), e.querySelector(":scope > [data-placeholder]")?.remove();
3510
+ for (let e of this.#c.values()) t.unbind(e), e.remove();
3511
+ this.#c.clear(), e.querySelector(":scope > [data-placeholder]")?.remove();
3500
3512
  }
3501
- async #x(e, t, n) {
3513
+ async #S(e, t, n) {
3502
3514
  let r = await this.loadTemplate(t);
3503
3515
  if (!r) return;
3504
3516
  let i = document.createElement("div");
@@ -3508,64 +3520,64 @@ var lt = class extends HTMLElement {
3508
3520
  }
3509
3521
  i.querySelector("[data-retry]")?.addEventListener("click", () => void this.retry(), { once: !0 });
3510
3522
  }
3511
- async #S(e, t, n) {
3523
+ async #C(e, t, n) {
3512
3524
  let { store: r, binder: i } = U(), a = n.itemTemplate ?? "item", o = new Set(t.ids);
3513
- for (let [e, t] of this.#s) o.has(e) || (i.unbind(t), t.remove(), this.#s.delete(e));
3525
+ for (let [e, t] of this.#c) o.has(e) || (i.unbind(t), t.remove(), this.#c.delete(e));
3514
3526
  let s = null, c = null;
3515
3527
  for (let o of t.ids) {
3516
3528
  let l = r.get(t.type, o);
3517
3529
  if (!l) continue;
3518
- let u = this.#s.get(o);
3530
+ let u = this.#c.get(o);
3519
3531
  if (!u) {
3520
3532
  if (s ??= await this.loadTemplate(a), !s || this.#e?.kind !== "list" || this.#e.view.id !== t.id) return;
3521
- u = s.cloneNode(!0).firstElementChild ?? document.createElement("div"), u.setAttribute("data-id", o), this.#s.set(o, u), i.bind(u, l.data, this.#_(n, t.type, o)), this.onItemRender(u, l);
3533
+ u = s.cloneNode(!0).firstElementChild ?? document.createElement("div"), u.setAttribute("data-id", o), this.#c.set(o, u), i.bind(u, l.data, this.#v(n, t.type, o)), this.onItemRender(u, l);
3522
3534
  }
3523
3535
  let d = c ? c.nextSibling : e.firstChild;
3524
3536
  u !== d && (c ? c.after(u) : e.prepend(u)), c = u;
3525
3537
  }
3526
- this.#c && this.#c.parentElement === e && e.append(this.#c);
3538
+ this.#l && this.#l.parentElement === e && e.append(this.#l);
3527
3539
  }
3528
- #C(e, t) {
3540
+ #w(e, t) {
3529
3541
  if (!e || t !== "update") return;
3530
- let n = this.#s.get(e.id);
3542
+ let n = this.#c.get(e.id);
3531
3543
  n && (U().binder.update(n, e.data), n.toggleAttribute("data-pending", e.sources.has("optimistic") && [...e.sources].pop() === "optimistic"), this.onItemRender(n, e));
3532
3544
  }
3533
- #w(e, t, n) {
3545
+ #T(e, t, n) {
3534
3546
  let r = typeof n.infiniteScroll == "object" ? n.infiniteScroll : {};
3535
- if (this.#c || (this.#c = document.createElement("div"), this.#c.className = "ar-scroll-sentinel", this.#c.setAttribute("aria-hidden", "true")), this.#c.parentElement !== e && e.append(this.#c), !t.hasMore) {
3536
- this.#l?.disconnect(), this.#l = null;
3547
+ if (this.#l || (this.#l = document.createElement("div"), this.#l.className = "ar-scroll-sentinel", this.#l.setAttribute("aria-hidden", "true")), this.#l.parentElement !== e && e.append(this.#l), !t.hasMore) {
3548
+ this.#u?.disconnect(), this.#u = null;
3537
3549
  return;
3538
3550
  }
3539
3551
  if (typeof IntersectionObserver > "u") return;
3540
- this.#l?.disconnect();
3552
+ this.#u?.disconnect();
3541
3553
  let i = r.root === "self" ? this : null;
3542
- this.#l = new IntersectionObserver((e) => {
3554
+ this.#u = new IntersectionObserver((e) => {
3543
3555
  e.some((e) => e.isIntersecting) && this.#e?.kind === "list" && U().listViews.loadMore(this.#e.view).catch((e) => console.error("loadMore failed", e));
3544
3556
  }, {
3545
3557
  root: i,
3546
3558
  rootMargin: `0px 0px ${r.threshold ?? 300}px 0px`
3547
- }), this.#l.observe(this.#c);
3559
+ }), this.#u.observe(this.#l);
3548
3560
  }
3549
3561
  itemElement(e) {
3550
- return this.#s.get(e);
3562
+ return this.#c.get(e);
3551
3563
  }
3552
3564
  async fetchData(e) {
3553
- this.error = null, this.#d("loading"), await this.#m(this.loadingTemplateId);
3565
+ this.error = null, this.#f("loading"), await this.#h(this.loadingTemplateId);
3554
3566
  try {
3555
3567
  let t = await e();
3556
- return await this.#T(), t;
3568
+ return await this.#E(), t;
3557
3569
  } catch (e) {
3558
3570
  return await this.showError(e), null;
3559
3571
  }
3560
3572
  }
3561
- async #T() {
3562
- if (this.#a !== this.mainTemplateId && (await this.render(this.mainTemplateId), U().binder.unbind(this)), this.#d("loaded"), this.#e?.kind === "object") {
3573
+ async #E() {
3574
+ if (this.#o !== this.mainTemplateId && (await this.render(this.mainTemplateId), U().binder.unbind(this)), this.#f("loaded"), this.#e?.kind === "object") {
3563
3575
  let e = U().store.get(this.#e.ref.type, this.#e.ref.id);
3564
- e && await this.#g(e);
3565
- } else this.#e?.kind === "list" && await this.#y(this.#e.view);
3576
+ e && await this.#_(e);
3577
+ } else this.#e?.kind === "list" && await this.#b(this.#e.view);
3566
3578
  }
3567
3579
  async showError(e) {
3568
- if (this.error = e instanceof Error ? e : Error(String(e)), this.#d("error"), !await this.#m(this.errorTemplateId)) return;
3580
+ if (this.error = e instanceof Error ? e : Error(String(e)), this.#f("error"), !await this.#h(this.errorTemplateId)) return;
3569
3581
  let t = this.querySelector("[data-error-message]");
3570
3582
  t && (t.textContent = this.formatErrorMessage(this.error)), this.querySelector("[data-retry]")?.addEventListener("click", () => void this.retry(), { once: !0 });
3571
3583
  }
@@ -3850,7 +3862,7 @@ function gt(e, t = {}) {
3850
3862
  function u(t) {
3851
3863
  if (!o) return;
3852
3864
  let n = o.input, r = e.querySelector(".editable-error");
3853
- r || (r = document.createElement("div"), r.className = "editable-error", r.id = z("editable-error"), r.setAttribute("role", "alert"), e.appendChild(r)), r.textContent = t, n.setAttribute("aria-invalid", "true"), n.setAttribute("aria-describedby", r.id), e.classList.add("is-invalid"), n.focus();
3865
+ r || (r = document.createElement("div"), r.className = "editable-error", r.id = B("editable-error"), r.setAttribute("role", "alert"), e.appendChild(r)), r.textContent = t, n.setAttribute("aria-invalid", "true"), n.setAttribute("aria-describedby", r.id), e.classList.add("is-invalid"), n.focus();
3854
3866
  }
3855
3867
  async function d() {
3856
3868
  if (!o || o.saving) return;
@@ -4256,7 +4268,7 @@ function Ot(e, t = {}) {
4256
4268
  function C(e) {
4257
4269
  if (!d) return;
4258
4270
  let t = d;
4259
- d = null, t.keyboard && (yt = !1, t.item.removeEventListener("keydown", T));
4271
+ d = null, t.keyboard && (yt = !1, t.item.removeEventListener("keydown", E));
4260
4272
  let { item: n, placeholder: r } = t, i = () => {
4261
4273
  ae(t), r && (e && r.parentElement && r.replaceWith(n), r.remove()), oe(t, e);
4262
4274
  };
@@ -4297,7 +4309,7 @@ function Ot(e, t = {}) {
4297
4309
  } else l ? (t.onEnd?.(c), n.keyboard && J(`${v(i)} dropped at position ${s + 1} of ${p(a).length}.`)) : n.keyboard && J(`${v(i)} dropped.`);
4298
4310
  n.keyboard && i.focus();
4299
4311
  }
4300
- function se() {
4312
+ function w() {
4301
4313
  u?.timer && clearTimeout(u.timer), u = null;
4302
4314
  }
4303
4315
  e.addEventListener("pointerdown", (n) => {
@@ -4319,24 +4331,24 @@ function Ot(e, t = {}) {
4319
4331
  }, c);
4320
4332
  }
4321
4333
  }, { signal: r });
4322
- let ce = (e) => {
4334
+ let se = (e) => {
4323
4335
  if (u && e.pointerId === u.pointerId) {
4324
4336
  let t = Math.hypot(e.clientX - u.startX, e.clientY - u.startY);
4325
4337
  if (!u.ready) {
4326
- t > 8 && se();
4338
+ t > 8 && w();
4327
4339
  return;
4328
4340
  }
4329
4341
  if (t < s) return;
4330
4342
  let n = u;
4331
4343
  u = null, x(n, e.clientX, e.clientY), e.preventDefault();
4332
4344
  } else d && !d.keyboard && e.pointerId === d.pointerId && (e.preventDefault(), S(e.clientX, e.clientY));
4333
- }, w = (e) => {
4334
- u && e.pointerId === u.pointerId ? se() : d && !d.keyboard && e.pointerId === d.pointerId && (e.type === "pointerup" && ie(e.clientX, e.clientY), C(e.type === "pointerup"));
4345
+ }, T = (e) => {
4346
+ u && e.pointerId === u.pointerId ? w() : d && !d.keyboard && e.pointerId === d.pointerId && (e.type === "pointerup" && ie(e.clientX, e.clientY), C(e.type === "pointerup"));
4335
4347
  };
4336
- document.addEventListener("pointermove", ce, {
4348
+ document.addEventListener("pointermove", se, {
4337
4349
  signal: r,
4338
4350
  passive: !1
4339
- }), document.addEventListener("pointerup", w, { signal: r }), document.addEventListener("pointercancel", w, { signal: r }), document.addEventListener("touchmove", (e) => {
4351
+ }), document.addEventListener("pointerup", T, { signal: r }), document.addEventListener("pointercancel", T, { signal: r }), document.addEventListener("touchmove", (e) => {
4340
4352
  d && !d.keyboard && e.cancelable && e.preventDefault();
4341
4353
  }, {
4342
4354
  signal: r,
@@ -4348,14 +4360,14 @@ function Ot(e, t = {}) {
4348
4360
  if (!(yt || d) && f(n, n.parentElement) && n.parentElement === e && (t.key === " " || t.key === "Enter")) {
4349
4361
  t.preventDefault();
4350
4362
  let a = b(n, !0);
4351
- yt = !0, n.addEventListener("keydown", T, { signal: r }), n.classList.add(i), n.setAttribute("aria-grabbed", "true"), K(e, "sortable:start", {
4363
+ yt = !0, n.addEventListener("keydown", E, { signal: r }), n.classList.add(i), n.setAttribute("aria-grabbed", "true"), K(e, "sortable:start", {
4352
4364
  item: n,
4353
4365
  from: a.from,
4354
4366
  oldIndex: a.oldIndex
4355
4367
  }), J(`Picked up ${v(n)}. Position ${a.oldIndex + 1} of ${p(a.from).length}. Use arrow keys to move, Space to drop, Escape to cancel.`);
4356
4368
  }
4357
4369
  }, { signal: r });
4358
- function T(t) {
4370
+ function E(t) {
4359
4371
  if (!d || !d.keyboard || t.target !== d.item) return;
4360
4372
  t.stopPropagation();
4361
4373
  let n = d.item, r = n.parentElement, i = p(r), a = i.indexOf(n), s = _(r) === "horizontal", c = s ? "ArrowLeft" : "ArrowUp", l = s ? "ArrowRight" : "ArrowDown", u = m(), f = u.indexOf(r), h = null;
@@ -4402,7 +4414,7 @@ function Ot(e, t = {}) {
4402
4414
  options: t,
4403
4415
  toArray: () => p(e).map((e) => e.getAttribute("data-id") ?? ""),
4404
4416
  destroy: () => {
4405
- se(), d && C(!1), n.abort(), g?.disconnect(), l && Y.get(l)?.delete(e), e.classList.remove("is-sortable");
4417
+ w(), d && C(!1), n.abort(), g?.disconnect(), l && Y.get(l)?.delete(e), e.classList.remove("is-sortable");
4406
4418
  }
4407
4419
  };
4408
4420
  }
@@ -4496,7 +4508,7 @@ G.register("resizable", kt);
4496
4508
  // src/mixins/dropdown.ts
4497
4509
  function At(e, t = {}) {
4498
4510
  if (!(e instanceof HTMLSelectElement)) throw Error("dropdown mixin must be applied to a <select>");
4499
- let n = e, { searchable: r = !0, emptyText: i = "No matches" } = t, a = new AbortController(), { signal: o } = a, s = z("dropdown"), c = document.createElement("div");
4511
+ let n = e, { searchable: r = !0, emptyText: i = "No matches" } = t, a = new AbortController(), { signal: o } = a, s = B("dropdown"), c = document.createElement("div");
4500
4512
  c.className = "dropdown";
4501
4513
  let l = document.createElement("input");
4502
4514
  l.type = "text", l.className = "dropdown__input", l.setAttribute("role", "combobox"), l.setAttribute("aria-expanded", "false"), l.setAttribute("aria-controls", `${s}-list`), l.setAttribute("aria-autocomplete", r ? "list" : "none"), l.autocomplete = "off", l.readOnly = !r, l.placeholder = t.placeholder ?? n.getAttribute("placeholder") ?? "";
@@ -4605,7 +4617,7 @@ function jt(e, t = {}) {
4605
4617
  let { placement: n = "top", delay: r = 300 } = t, i = new AbortController(), { signal: a } = i, o = e.getAttribute("title"), s = () => t.content ?? e.dataset.tooltip ?? o ?? "";
4606
4618
  o !== null && e.removeAttribute("title");
4607
4619
  let c = document.createElement("div");
4608
- c.id = z("tooltip"), c.className = "tooltip", c.setAttribute("role", "tooltip"), c.hidden = !0;
4620
+ c.id = B("tooltip"), c.className = "tooltip", c.setAttribute("role", "tooltip"), c.hidden = !0;
4609
4621
  let l = e.getAttribute("aria-describedby");
4610
4622
  e.setAttribute("aria-describedby", [l, c.id].filter(Boolean).join(" "));
4611
4623
  let u = null;
@@ -4654,7 +4666,7 @@ function Mt(e, t = {}) {
4654
4666
  function p(t, n, r) {
4655
4667
  h(!1), o = r, s = document.activeElement, a = new AbortController();
4656
4668
  let p = a.signal;
4657
- i = document.createElement("div"), i.className = "context-menu", i.id = z("menu"), i.setAttribute("role", "menu");
4669
+ i = document.createElement("div"), i.className = "context-menu", i.id = B("menu"), i.setAttribute("role", "menu");
4658
4670
  for (let e of u()) {
4659
4671
  if (e.separator) {
4660
4672
  let e = document.createElement("div");
@@ -4764,22 +4776,22 @@ function Nt() {
4764
4776
  for (let [t, n] of Object.entries(e)) G.has(t) || G.register(t, n);
4765
4777
  }
4766
4778
  // src/version.ts
4767
- var Z = "0.1.3";
4779
+ var Z = "0.1.5";
4768
4780
  // src/plugins/date-utils.ts
4769
4781
  function Pt(e, t = {}) {
4770
4782
  let n = e instanceof HTMLInputElement ? e : e.querySelector("input"), r = new AbortController();
4771
4783
  if (!n) throw Error("datepicker: no <input> found");
4772
4784
  let i = n.type;
4773
4785
  n.type = "date";
4774
- let a = A(t.min), o = A(t.max);
4775
- return a && (n.min = M(a)), o && (n.max = M(o)), n.addEventListener("change", () => {
4776
- let e = A(n.value);
4786
+ let a = j(t.min), o = j(t.max);
4787
+ return a && (n.min = N(a)), o && (n.max = N(o)), n.addEventListener("change", () => {
4788
+ let e = j(n.value);
4777
4789
  t.onChange?.(e), K(n, "datepicker:change", { date: e });
4778
4790
  }, { signal: r.signal }), {
4779
4791
  name: "datepicker",
4780
4792
  element: e,
4781
4793
  options: t,
4782
- value: () => A(n.value),
4794
+ value: () => j(n.value),
4783
4795
  destroy: () => {
4784
4796
  r.abort(), n.type = i;
4785
4797
  }
@@ -4791,8 +4803,8 @@ function Ft(e, t = {}) {
4791
4803
  let i = new AbortController();
4792
4804
  n.type = "date", r.type = "date";
4793
4805
  let a = () => (r.min = n.value || "", n.max = r.value || "", {
4794
- start: A(n.value),
4795
- end: A(r.value)
4806
+ start: j(n.value),
4807
+ end: j(r.value)
4796
4808
  }), o = () => {
4797
4809
  let n = a();
4798
4810
  t.onChange?.(n), K(e, "daterange:change", n);
@@ -4802,13 +4814,13 @@ function Ft(e, t = {}) {
4802
4814
  element: e,
4803
4815
  options: t,
4804
4816
  value: () => ({
4805
- start: A(n.value),
4806
- end: A(r.value)
4817
+ start: j(n.value),
4818
+ end: j(r.value)
4807
4819
  }),
4808
4820
  destroy: () => i.abort()
4809
4821
  };
4810
4822
  }
4811
- var Q = () => N(/* @__PURE__ */ new Date());
4823
+ var Q = () => P(/* @__PURE__ */ new Date());
4812
4824
  function It() {
4813
4825
  return {
4814
4826
  name: "date-utils",
@@ -4820,30 +4832,30 @@ function It() {
4820
4832
  validators: {
4821
4833
  futureDate: {
4822
4834
  fn: (e, t) => {
4823
- let n = A(e);
4824
- return n ? t.includeToday === !1 ? N(n) > Q() : N(n) >= Q() : !0;
4835
+ let n = j(e);
4836
+ return n ? t.includeToday === !1 ? P(n) > Q() : P(n) >= Q() : !0;
4825
4837
  },
4826
4838
  message: "Choose a date in the future"
4827
4839
  },
4828
4840
  pastDate: {
4829
4841
  fn: (e, t) => {
4830
- let n = A(e);
4831
- return n ? t.includeToday === !1 ? N(n) < Q() : N(n) <= Q() : !0;
4842
+ let n = j(e);
4843
+ return n ? t.includeToday === !1 ? P(n) < Q() : P(n) <= Q() : !0;
4832
4844
  },
4833
4845
  message: "Choose a date in the past"
4834
4846
  },
4835
4847
  dateRange: {
4836
4848
  fn: (e, t) => {
4837
- let n = A(e);
4849
+ let n = j(e);
4838
4850
  if (!n) return !0;
4839
- let r = A(t.min), i = A(t.max);
4840
- return !(r && N(n) < N(r) || i && N(n) > N(i));
4851
+ let r = j(t.min), i = j(t.max);
4852
+ return !(r && P(n) < P(r) || i && P(n) > P(i));
4841
4853
  },
4842
4854
  message: "Choose a date between {min} and {max}"
4843
4855
  },
4844
4856
  businessDay: {
4845
4857
  fn: (e) => {
4846
- let t = A(e);
4858
+ let t = j(e);
4847
4859
  if (!t) return !0;
4848
4860
  let n = t.getDay();
4849
4861
  return n !== 0 && n !== 6;
@@ -4852,10 +4864,10 @@ function It() {
4852
4864
  },
4853
4865
  minAge: {
4854
4866
  fn: (e, t) => {
4855
- let n = A(e);
4867
+ let n = j(e);
4856
4868
  if (!n) return !0;
4857
4869
  let r = Number(t.years ?? 18), i = Q();
4858
- return i.setFullYear(i.getFullYear() - r), N(n) <= i;
4870
+ return i.setFullYear(i.getFullYear() - r), P(n) <= i;
4859
4871
  },
4860
4872
  message: "You must be at least {years} years old"
4861
4873
  }
@@ -5055,10 +5067,10 @@ function $(e, t) {
5055
5067
  }
5056
5068
  }
5057
5069
  function Bt(e, t = {}) {
5058
- let n = new AbortController(), { signal: r } = n, i = e instanceof HTMLTextAreaElement ? e : null, a = i ? document.createElement("div") : e, o = (e) => I(e, t.sanitize), s = document.createElement("div");
5070
+ let n = new AbortController(), { signal: r } = n, i = e instanceof HTMLTextAreaElement ? e : null, a = i ? document.createElement("div") : e, o = (e) => L(e, t.sanitize), s = document.createElement("div");
5059
5071
  s.className = "rich-text", e.insertAdjacentElement("beforebegin", s);
5060
5072
  let c = document.createElement("div");
5061
- c.className = "rich-text__toolbar", c.setAttribute("role", "toolbar"), c.setAttribute("aria-label", "Formatting"), s.appendChild(c), i ? (a.innerHTML = o(i.value), i.hidden = !0, s.append(a, i)) : (a.innerHTML = o(a.innerHTML), s.appendChild(a)), a.contentEditable = "true", a.classList.add("rich-text__content"), a.setAttribute("role", "textbox"), a.setAttribute("aria-multiline", "true"), t.label && a.setAttribute("aria-label", t.label), t.placeholder && (a.dataset.placeholder = t.placeholder), a.id ||= z("rich-text"), $("defaultParagraphSeparator", "p");
5073
+ c.className = "rich-text__toolbar", c.setAttribute("role", "toolbar"), c.setAttribute("aria-label", "Formatting"), s.appendChild(c), i ? (a.innerHTML = o(i.value), i.hidden = !0, s.append(a, i)) : (a.innerHTML = o(a.innerHTML), s.appendChild(a)), a.contentEditable = "true", a.classList.add("rich-text__content"), a.setAttribute("role", "textbox"), a.setAttribute("aria-multiline", "true"), t.label && a.setAttribute("aria-label", t.label), t.placeholder && (a.dataset.placeholder = t.placeholder), a.id ||= B("rich-text"), $("defaultParagraphSeparator", "p");
5062
5074
  let l = [];
5063
5075
  for (let e of t.toolbar ?? Rt) {
5064
5076
  let t = zt[e];
@@ -5075,12 +5087,12 @@ function Bt(e, t = {}) {
5075
5087
  let p = null, m = a.innerHTML;
5076
5088
  function h() {
5077
5089
  let e = o(a.innerHTML);
5078
- e !== m && (m = e, i && (i.value = e, i.dispatchEvent(new Event("input", { bubbles: !0 }))), a.classList.toggle("is-empty", L(e).trim() === ""), K(a, "rich-text:change", {
5090
+ e !== m && (m = e, i && (i.value = e, i.dispatchEvent(new Event("input", { bubbles: !0 }))), a.classList.toggle("is-empty", R(e).trim() === ""), K(a, "rich-text:change", {
5079
5091
  html: e,
5080
- text: L(e)
5092
+ text: R(e)
5081
5093
  }));
5082
5094
  }
5083
- a.classList.toggle("is-empty", L(a.innerHTML).trim() === "");
5095
+ a.classList.toggle("is-empty", R(a.innerHTML).trim() === "");
5084
5096
  function g() {
5085
5097
  let e = document.getSelection();
5086
5098
  if (!e || !e.anchorNode || !a.contains(e.anchorNode)) return;
@@ -5110,7 +5122,7 @@ function Bt(e, t = {}) {
5110
5122
  }
5111
5123
  return u.addEventListener("submit", (e) => {
5112
5124
  e.preventDefault();
5113
- let t = F(d.value.trim(), "link");
5125
+ let t = I(d.value.trim(), "link");
5114
5126
  if (u.hidden = !0, a.focus(), p) {
5115
5127
  let e = document.getSelection();
5116
5128
  e?.removeAllRanges(), e?.addRange(p);
@@ -5156,7 +5168,7 @@ function Bt(e, t = {}) {
5156
5168
  options: t,
5157
5169
  editor: a,
5158
5170
  getHTML: () => o(a.innerHTML),
5159
- getText: () => L(a.innerHTML),
5171
+ getText: () => R(a.innerHTML),
5160
5172
  setHTML: (e) => {
5161
5173
  a.innerHTML = o(e), h();
5162
5174
  },
@@ -5174,13 +5186,13 @@ function Vt() {
5174
5186
  validators: {
5175
5187
  richTextMinLength: {
5176
5188
  fn: (e, t) => {
5177
- let n = L(e).trim();
5189
+ let n = R(e).trim();
5178
5190
  return n === "" || n.length >= Number(t.min ?? 0);
5179
5191
  },
5180
5192
  message: "Write at least {min} characters"
5181
5193
  },
5182
5194
  richTextMaxLength: {
5183
- fn: (e, t) => L(e).trim().length <= Number(t.max ?? Infinity),
5195
+ fn: (e, t) => R(e).trim().length <= Number(t.max ?? Infinity),
5184
5196
  message: "Keep it under {max} characters"
5185
5197
  },
5186
5198
  noEmptyParagraphs: {
@@ -5203,7 +5215,7 @@ var Ut = class e extends f {
5203
5215
  listViews = new u();
5204
5216
  optimistic;
5205
5217
  http = new C();
5206
- validation = new Oe();
5218
+ validation = new De();
5207
5219
  binder;
5208
5220
  plugins;
5209
5221
  collab;
@@ -5218,7 +5230,7 @@ var Ut = class e extends f {
5218
5230
  initPromise = null;
5219
5231
  stopObserving = null;
5220
5232
  constructor() {
5221
- super(), Nt(), Ht(), this.optimistic = new m(this.store, this.listViews), this.binder = new He(this.validation), this.plugins = new ft(this), this.collab = new xe(() => this.ws), this.http.connect({
5233
+ super(), Nt(), Ht(), this.optimistic = new m(this.store, this.listViews), this.binder = new Ve(this.validation), this.plugins = new ft(this), this.collab = new be(() => this.ws), this.http.connect({
5222
5234
  store: this.store,
5223
5235
  listViews: this.listViews
5224
5236
  }), this.listViews.setLoader((e, t) => this.http.loadListView(e, t)), Je({
@@ -5259,7 +5271,7 @@ var Ut = class e extends f {
5259
5271
  for (let e of t.types ?? []) this.defineType(e);
5260
5272
  for (let [e, n] of Object.entries(t.endpoints ?? {})) this.defineEndpoint(e, n);
5261
5273
  for (let [e, n] of Object.entries(t.validation?.messages ?? {})) this.validation.setMessage(e, n);
5262
- t.auth && (this.auth = new w(t.auth, {
5274
+ t.auth && (this.auth = new T(t.auth, {
5263
5275
  fetch: () => t.http?.fetch ?? globalThis.fetch.bind(globalThis),
5264
5276
  resolveUrl: (e) => this.http.resolveUrl(e)
5265
5277
  }), this.http.connect({ auth: this.auth })), t.persistence !== !1 && await this.initPersistence(typeof t.persistence == "object" ? t.persistence : {});
@@ -5267,10 +5279,10 @@ var Ut = class e extends f {
5267
5279
  let t = e.replace(/^ws(s?):\/\//i, "http$1://");
5268
5280
  return this.auth && this.http.isTrustedUrl(t) ? this.auth.ensureValidToken() : null;
5269
5281
  };
5270
- if (t.sse && (this.sse = new le({
5282
+ if (t.sse && (this.sse = new ce({
5271
5283
  ...t.sse,
5272
5284
  url: this.http.resolveUrl(t.sse.url)
5273
- }), this.sse.connectStore(this.store, this.listViews), this.sse.setTokenProvider(n(this.sse.config.url))), t.websocket && (this.ws = new de(t.websocket), this.ws.setTokenProvider(n(t.websocket.url))), t.azurePubSub && (this.azurePubSub = new pe({
5285
+ }), this.sse.connectStore(this.store, this.listViews), this.sse.setTokenProvider(n(this.sse.config.url))), t.websocket && (this.ws = new ue(t.websocket), this.ws.setTokenProvider(n(t.websocket.url))), t.azurePubSub && (this.azurePubSub = new fe({
5274
5286
  ...t.azurePubSub,
5275
5287
  negotiateUrl: this.http.resolveUrl(t.azurePubSub.negotiateUrl),
5276
5288
  fetch: t.azurePubSub.fetch ?? t.http?.fetch
@@ -5328,6 +5340,6 @@ function Gt(e) {
5328
5340
  function Kt(e, t) {
5329
5341
  return Wt().defineEndpoint(e, t);
5330
5342
  }
5331
- export { ge as $, rt as A, R as B, it as C, et as D, Ze as E, U as F, Te as G, I as H, He as I, Ce as J, A as K, Ge as L, tt as M, Xe as N, nt as O, W as P, ve as Q, Ke as R, lt as S, ot as T, F as U, L as V, Oe as W, be as X, xe as Y, ye as Z, _t as _, Bt as a, w as at, ft as b, It as c, _ as ct, Mt as d, u as dt, he as et, jt as f, l as ft, vt as g, i as gt, Ot as h, r as ht, Wt as i, le as it, $e as j, G as k, Z as l, m as lt, kt as m, a as mt, Kt as n, pe as nt, Vt as o, C as ot, At as p, s as pt, M as q, Gt as r, de as rt, Lt as s, v as st, Ut as t, k as tt, Nt as u, f as ut, gt as v, at as w, dt as x, ht as y, H as z };
5343
+ export { A as $, rt as A, z as B, it as C, et as D, Ze as E, U as F, we as G, L as H, Ve as I, Se as J, j as K, We as L, tt as M, Xe as N, nt as O, W as P, _e as Q, Ke as R, lt as S, ot as T, I as U, R as V, De as W, ye as X, be as Y, ve as Z, _t as _, Bt as a, T as at, ft as b, It as c, _ as ct, Mt as d, u as dt, he as et, jt as f, l as ft, vt as g, i as gt, Ot as h, r as ht, Wt as i, ce as it, $e as j, G as k, Z as l, m as lt, kt as m, a as mt, Kt as n, fe as nt, Vt as o, C as ot, At as p, s as pt, N as q, Gt as r, ue as rt, Lt as s, v as st, Ut as t, k as tt, Nt as u, f as ut, gt as v, at as w, dt as x, ht as y, Ge as z };
5332
5344
 
5333
- //# sourceMappingURL=arethesis-D0-ZaXOM.js.map
5345
+ //# sourceMappingURL=arethesis-jPH9QdQE.js.map