@jasonshimmy/custom-elements-runtime 0.1.2 → 0.1.4

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.
@@ -1,20 +1,42 @@
1
- function Re(e) {
2
- let t = new Proxy(e, {
3
- set: (i, l, c) => (i[l] = c, s(), !0)
1
+ function rt(e, t) {
2
+ return J(e ? t : [], "when-block");
3
+ }
4
+ function nt(e, t) {
5
+ return e.map((r, n) => {
6
+ const o = typeof r == "object" ? r?.key ?? r?.id ?? `idx-${n}` : String(r);
7
+ return J(t(r, n), `each-${o}`);
4
8
  });
5
- const n = [];
6
- function r(i) {
7
- n.push(i), i(t);
8
- }
9
- function o() {
10
- return t;
11
- }
12
- function s() {
13
- n.forEach((i) => i(t));
9
+ }
10
+ function ve() {
11
+ const e = [];
12
+ return {
13
+ when(t, r) {
14
+ return e.push([t, r]), this;
15
+ },
16
+ otherwise(t) {
17
+ return e.push([!0, t]), this;
18
+ },
19
+ done() {
20
+ return xe(...e);
21
+ }
22
+ };
23
+ }
24
+ function xe(...e) {
25
+ for (let t = 0; t < e.length; t++) {
26
+ const [r, n] = e[t];
27
+ if (r) return [J(n, `whenChain-branch-${t}`)];
14
28
  }
15
- return { subscribe: r, getState: o };
29
+ return [J([], "whenChain-empty")];
30
+ }
31
+ function J(e, t) {
32
+ const r = e ? Array.isArray(e) ? e.filter(Boolean) : [e].filter(Boolean) : [];
33
+ return {
34
+ tag: "#anchor",
35
+ key: t,
36
+ children: r
37
+ };
16
38
  }
17
- class B extends EventTarget {
39
+ class O extends EventTarget {
18
40
  handlers = {};
19
41
  static instance;
20
42
  eventCounters = /* @__PURE__ */ new Map();
@@ -22,7 +44,7 @@ class B extends EventTarget {
22
44
  * Returns the singleton instance of GlobalEventBus
23
45
  */
24
46
  static getInstance() {
25
- return B.instance || (B.instance = new B()), B.instance;
47
+ return O.instance || (O.instance = new O()), O.instance;
26
48
  }
27
49
  // Enhanced emit method with better typing and event storm protection
28
50
  /**
@@ -30,16 +52,16 @@ class B extends EventTarget {
30
52
  * @param eventName - Name of the event
31
53
  * @param data - Optional event payload
32
54
  */
33
- emit(t, n) {
34
- const r = Date.now(), o = this.eventCounters.get(t);
35
- if (!o || r - o.window > 1e3)
36
- this.eventCounters.set(t, { count: 1, window: r });
55
+ emit(t, r) {
56
+ const n = Date.now(), o = this.eventCounters.get(t);
57
+ if (!o || n - o.window > 1e3)
58
+ this.eventCounters.set(t, { count: 1, window: n });
37
59
  else if (o.count++, o.count > 50 && (console.error(`Event storm detected for "${t}": ${o.count} events in 1 second. Throttling...`), o.count > 100)) {
38
60
  console.warn(`Blocking further "${t}" events to prevent infinite loop`);
39
61
  return;
40
62
  }
41
63
  this.dispatchEvent(new CustomEvent(t, {
42
- detail: n,
64
+ detail: r,
43
65
  bubbles: !1,
44
66
  // Global events don't need to bubble
45
67
  cancelable: !0
@@ -47,9 +69,9 @@ class B extends EventTarget {
47
69
  const s = this.handlers[t];
48
70
  s && s.forEach((i) => {
49
71
  try {
50
- i(n);
51
- } catch (l) {
52
- console.error(`Error in global event handler for "${t}":`, l);
72
+ i(r);
73
+ } catch (a) {
74
+ console.error(`Error in global event handler for "${t}":`, a);
53
75
  }
54
76
  });
55
77
  }
@@ -58,17 +80,17 @@ class B extends EventTarget {
58
80
  * @param eventName - Name of the event
59
81
  * @param handler - Handler function
60
82
  */
61
- on(t, n) {
62
- return this.handlers[t] || (this.handlers[t] = /* @__PURE__ */ new Set()), this.handlers[t].add(n), () => this.off(t, n);
83
+ on(t, r) {
84
+ return this.handlers[t] || (this.handlers[t] = /* @__PURE__ */ new Set()), this.handlers[t].add(r), () => this.off(t, r);
63
85
  }
64
86
  /**
65
87
  * Remove a specific handler for a global event.
66
88
  * @param eventName - Name of the event
67
89
  * @param handler - Handler function to remove
68
90
  */
69
- off(t, n) {
70
- const r = this.handlers[t];
71
- r && r.delete(n);
91
+ off(t, r) {
92
+ const n = this.handlers[t];
93
+ n && n.delete(r);
72
94
  }
73
95
  /**
74
96
  * Remove all handlers for a specific event.
@@ -83,18 +105,18 @@ class B extends EventTarget {
83
105
  * @param handler - CustomEvent handler
84
106
  * @param options - AddEventListener options
85
107
  */
86
- listen(t, n, r) {
87
- return this.addEventListener(t, n, r), () => this.removeEventListener(t, n);
108
+ listen(t, r, n) {
109
+ return this.addEventListener(t, r, n), () => this.removeEventListener(t, r);
88
110
  }
89
111
  /**
90
112
  * Register a one-time event handler. Returns a promise that resolves with the event data.
91
113
  * @param eventName - Name of the event
92
114
  * @param handler - Handler function
93
115
  */
94
- once(t, n) {
95
- return new Promise((r) => {
116
+ once(t, r) {
117
+ return new Promise((n) => {
96
118
  const o = this.on(t, (s) => {
97
- o(), n(s), r(s);
119
+ o(), r(s), n(s);
98
120
  });
99
121
  });
100
122
  }
@@ -124,10 +146,10 @@ class B extends EventTarget {
124
146
  */
125
147
  getEventStats() {
126
148
  const t = {};
127
- for (const [n, r] of this.eventCounters.entries())
128
- t[n] = {
129
- count: r.count,
130
- handlersCount: this.getHandlerCount(n)
149
+ for (const [r, n] of this.eventCounters.entries())
150
+ t[r] = {
151
+ count: n.count,
152
+ handlersCount: this.getHandlerCount(r)
131
153
  };
132
154
  return t;
133
155
  }
@@ -138,437 +160,271 @@ class B extends EventTarget {
138
160
  this.eventCounters.clear();
139
161
  }
140
162
  }
141
- const Be = B.getInstance();
142
- function P(e, t = {}, n, r) {
143
- const o = r ?? t.key;
144
- return { tag: e, key: o, props: t, children: n };
163
+ const H = O.getInstance(), ot = (e, t) => H.emit(e, t), it = (e, t) => H.on(e, t), st = (e, t) => H.off(e, t), at = (e, t) => H.once(e, t), lt = (e, t, r) => H.listen(e, t, r);
164
+ function ie(e) {
165
+ let t = { ...e };
166
+ const r = [];
167
+ function n(a) {
168
+ r.push(a), a(t);
169
+ }
170
+ function o() {
171
+ return t;
172
+ }
173
+ function s(a) {
174
+ const c = typeof a == "function" ? a(t) : a;
175
+ t = { ...t, ...c }, i();
176
+ }
177
+ function i() {
178
+ r.forEach((a) => a(t));
179
+ }
180
+ return { subscribe: n, getState: o, setState: s };
145
181
  }
146
- function I(e) {
147
- return !!e && typeof e == "object" && (e.type === "AnchorBlock" || e.tag === "#anchor");
182
+ function ne(e) {
183
+ return e.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
148
184
  }
149
- function R(e) {
150
- return typeof e == "object" && e !== null && "tag" in e && !I(e);
185
+ function ee(e) {
186
+ return typeof e == "string" ? e.replace(
187
+ /[&<>"']/g,
188
+ (t) => ({
189
+ "&": "&amp;",
190
+ "<": "&lt;",
191
+ ">": "&gt;",
192
+ '"': "&quot;",
193
+ "'": "&#39;"
194
+ })[t]
195
+ ) : e;
151
196
  }
152
- function le(e, t) {
153
- return e.key != null ? e : { ...e, key: t };
197
+ function we(e, t, r) {
198
+ if (r)
199
+ for (const [n, o] of Object.entries(r)) {
200
+ let s, i = {};
201
+ if (Array.isArray(o) ? (s = o[0], i = o[1] || {}) : s = o, t.set(n, {
202
+ callback: s,
203
+ options: i,
204
+ oldValue: te(e, n)
205
+ }), i.immediate)
206
+ try {
207
+ const a = te(e, n);
208
+ s(a, void 0, e);
209
+ } catch (a) {
210
+ console.error(`Error in immediate watcher for "${n}":`, a);
211
+ }
212
+ }
154
213
  }
155
- function ce(e, t = [], n = {}) {
156
- const r = {}, o = {}, s = {}, i = /([:@#]?)([a-zA-Z0-9-:\.]+)=("([^"\\]*(\\.[^"\\]*)*)"|'([^'\\]*(\\.[^'\\]*)*)')/g;
157
- let l;
158
- for (; l = i.exec(e); ) {
159
- const c = l[1], d = l[2], p = (l[4] || l[6]) ?? "", u = p.match(/^{{(\d+)}}$/);
160
- let f = u ? t[Number(u[1])] ?? null : p;
161
- if (u || (f === "true" ? f = !0 : f === "false" ? f = !1 : f === "null" ? f = null : isNaN(Number(f)) || (f = Number(f))), c === ":")
162
- typeof f == "boolean" ? o[d] = f : f != null && (r[d] = f);
163
- else if (c === "@") {
164
- const m = "on" + d.charAt(0).toUpperCase() + d.slice(1);
165
- r[m] = typeof f == "function" ? f : typeof n[f] == "function" ? n[f] : void 0;
166
- } else if (c === "#") {
167
- const [m, ...h] = d.split("."), S = [...h];
168
- let y = f, a = [...S];
169
- if (m === "model" && typeof y == "string" && y.includes(".")) {
170
- const b = ["trim", "number", "lazy"], g = y.split(".");
171
- let x = y;
172
- const w = [];
173
- for (let k = g.length - 1; k > 0 && b.includes(g[k]); k--)
174
- w.unshift(g[k]), x = g.slice(0, k).join(".");
175
- y = x, a.push(...w);
176
- }
177
- s[m] = {
178
- value: y,
179
- modifiers: a
180
- };
181
- } else d === "ref" ? r.ref = f : o[d] = f;
182
- }
183
- return { props: r, attrs: o, directives: s };
214
+ function te(e, t) {
215
+ return t.split(".").reduce((r, n) => r?.[n], e);
184
216
  }
185
- function fe(e, t, n) {
186
- function r(a, b) {
187
- return P("#text", {}, a, b);
188
- }
189
- let o = "";
190
- for (let a = 0; a < e.length; a++)
191
- o += e[a], a < t.length && (o += `{{${a}}}`);
192
- const s = /<\/?([a-zA-Z0-9-]+)([^>]*)\/?>|{{(\d+)}}|([^<]+)/g, i = [];
193
- let l = null, c, d = [], p = null, u = {}, f, m = 0, h = [];
194
- function S(a) {
195
- !a || typeof a != "object" || I(a) || (a.props || a.attrs ? (a.props && (u.props || (u.props = {}), Object.assign(u.props, a.props)), a.attrs && (u.attrs || (u.attrs = {}), Object.keys(a.attrs).forEach((b) => {
196
- if (b === "style" && u.attrs.style) {
197
- const g = u.attrs.style.replace(
198
- /;?\s*$/,
199
- ""
200
- ), x = a.attrs.style.replace(/^;?\s*/, "");
201
- u.attrs.style = g + "; " + x;
202
- } else if (b === "class" && u.attrs.class) {
203
- const g = u.attrs.class.trim().split(/\s+/).filter(Boolean), x = a.attrs.class.trim().split(/\s+/).filter(Boolean), w = [
204
- .../* @__PURE__ */ new Set([...g, ...x])
205
- ];
206
- u.attrs.class = w.join(" ");
207
- } else
208
- u.attrs[b] = a.attrs[b];
209
- }))) : (u.props || (u.props = {}), Object.assign(u.props, a)));
210
- }
211
- function y(a, b) {
212
- const g = p ? d : h;
213
- if (I(a)) {
214
- const x = a.key ?? b;
215
- let w = a.children;
216
- g.push({
217
- ...a,
218
- key: x,
219
- children: w
220
- });
221
- return;
222
- }
223
- if (R(a)) {
224
- g.push(le(a, void 0));
225
- return;
217
+ function ke(e, t, r, n) {
218
+ const o = (i, a) => {
219
+ if (i === a) return !0;
220
+ if (typeof i != typeof a || typeof i != "object" || i === null || a === null) return !1;
221
+ if (Array.isArray(i) && Array.isArray(a))
222
+ return i.length !== a.length ? !1 : i.every((g, d) => o(g, a[d]));
223
+ const c = Object.keys(i), f = Object.keys(a);
224
+ return c.length !== f.length ? !1 : c.every((g) => o(i[g], a[g]));
225
+ }, s = t.get(r);
226
+ if (s && !o(n, s.oldValue))
227
+ try {
228
+ s.callback(n, s.oldValue, e), s.oldValue = n;
229
+ } catch (i) {
230
+ console.error(`Error in watcher for "${r}":`, i);
226
231
  }
227
- if (Array.isArray(a)) {
228
- if (a.length === 0) return;
229
- for (let x = 0; x < a.length; x++) {
230
- const w = a[x];
231
- I(w) || R(w) || Array.isArray(w) ? y(w, `${b}-${x}`) : w !== null && typeof w == "object" ? S(w) : g.push(r(String(w), `${b}-${x}`));
232
+ for (const [i, a] of t.entries())
233
+ if (a.options.deep && r.startsWith(i + "."))
234
+ try {
235
+ const c = te(e, i);
236
+ o(c, a.oldValue) || (a.callback(c, a.oldValue, e), a.oldValue = c);
237
+ } catch (c) {
238
+ console.error(`Error in deep watcher for "${i}":`, c);
232
239
  }
233
- return;
234
- }
235
- if (a !== null && typeof a == "object") {
236
- S(a);
237
- return;
238
- }
239
- g.push(r(String(a), b));
240
+ }
241
+ function $e(e, t, r) {
242
+ if (!t.props) return;
243
+ function n(o, s) {
244
+ return s === Boolean ? o === "true" : s === Number ? Number(o) : o;
240
245
  }
241
- for (; c = s.exec(o); )
242
- if (c[1]) {
243
- const a = c[1], b = c[0][1] === "/", g = c[0][c[0].length - 2] === "/", {
244
- props: x,
245
- attrs: w,
246
- directives: k
247
- } = ce(c[2] || "", t, n), $ = { props: {}, attrs: {} };
248
- for (const v in x) $.props[v] = x[v];
249
- for (const v in w) $.attrs[v] = w[v];
250
- for (const [v, _] of Object.entries(k))
251
- if (v === "bind")
252
- if (typeof _.value == "object" && _.value !== null)
253
- for (const [A, E] of Object.entries(_.value))
254
- typeof E == "boolean" ? $.attrs[A] = E : E != null && ($.attrs[A] = String(E));
255
- else _.value != null && ($.attrs[v] = String(_.value));
256
- else if (v === "show") {
257
- const A = !!_.value;
258
- $.attrs.style = ($.attrs.style || "") + (A ? "" : "; display: none !important");
259
- } else if (v === "class") {
260
- const A = _.value;
261
- let E = [];
262
- if (typeof A == "string")
263
- E = A.split(/\s+/).filter(Boolean);
264
- else if (Array.isArray(A)) {
265
- for (const j of A)
266
- if (typeof j == "string")
267
- E.push(...j.split(/\s+/).filter(Boolean));
268
- else if (j && typeof j == "object")
269
- for (const [L, N] of Object.entries(j))
270
- N && E.push(...L.split(/\s+/).filter(Boolean));
271
- } else if (A && typeof A == "object")
272
- for (const [j, L] of Object.entries(A))
273
- L && E.push(...j.split(/\s+/).filter(Boolean));
274
- const O = $.attrs.class || "", M = [
275
- .../* @__PURE__ */ new Set([
276
- ...O.split(/\s+/).filter(Boolean),
277
- ...E
278
- ])
279
- ];
280
- $.attrs.class = M.join(" ");
281
- } else if (v === "style") {
282
- const A = _.value;
283
- let E = "";
284
- if (typeof A == "string")
285
- E = A;
286
- else if (A && typeof A == "object") {
287
- const M = [];
288
- for (const [j, L] of Object.entries(A))
289
- if (L != null && L !== "") {
290
- const N = j.replace(
291
- /[A-Z]/g,
292
- (ae) => `-${ae.toLowerCase()}`
293
- ), se = [
294
- "width",
295
- "height",
296
- "top",
297
- "right",
298
- "bottom",
299
- "left",
300
- "margin",
301
- "margin-top",
302
- "margin-right",
303
- "margin-bottom",
304
- "margin-left",
305
- "padding",
306
- "padding-top",
307
- "padding-right",
308
- "padding-bottom",
309
- "padding-left",
310
- "font-size",
311
- "line-height",
312
- "border-width",
313
- "border-radius",
314
- "min-width",
315
- "max-width",
316
- "min-height",
317
- "max-height"
318
- ];
319
- let X = String(L);
320
- typeof L == "number" && se.includes(N) && (X = `${L}px`), M.push(`${N}: ${X}`);
321
- }
322
- E = M.join("; ") + (M.length > 0 ? ";" : "");
323
- }
324
- const O = $.attrs.style || "";
325
- $.attrs.style = O + (O && !O.endsWith(";") ? "; " : "") + E;
326
- }
327
- const C = {};
328
- for (const [v, _] of Object.entries(k))
329
- ["bind", "show", "class", "style"].includes(v) || (C[v] = _);
330
- if (Object.keys(C).length > 0 && ($.directives = C), b) {
331
- const v = P(
332
- p,
333
- u,
334
- d.length === 1 && R(d[0]) && d[0].tag === "#text" ? typeof d[0].children == "string" ? d[0].children : "" : d.length ? d : void 0,
335
- f
336
- ), _ = i.pop();
337
- _ ? (p = _.tag, u = _.props, f = _.key, d = _.children, d.push(v)) : l = v;
338
- } else g ? (p ? d : h).push(P(a, $, void 0, void 0)) : (p && i.push({
339
- tag: p,
340
- props: u,
341
- children: d,
342
- key: f
343
- }), p = a, u = $, d = []);
344
- } else if (typeof c[3] < "u") {
345
- const a = Number(c[3]), b = t[a], g = `interp-${a}`;
346
- y(b, g);
347
- } else if (c[4]) {
348
- const a = c[4], b = p ? d : h, g = a.split(/({{\d+}})/);
349
- for (const x of g) {
350
- if (!x) continue;
351
- const w = x.match(/^{{(\d+)}}$/);
352
- if (w) {
353
- const k = Number(w[1]), $ = t[k], C = `interp-${k}`;
354
- y($, C);
355
- } else {
356
- const k = `text-${m++}`;
357
- b.push(r(x, k));
358
- }
359
- }
246
+ Object.entries(t.props).forEach(([o, s]) => {
247
+ if (s.type === Function && typeof e[o] == "function")
248
+ r[o] = e[o];
249
+ else {
250
+ const i = e.getAttribute(ne(o));
251
+ i !== null ? r[o] = ee(n(i, s.type)) : "default" in s && s.default !== void 0 && (r[o] = ee(s.default));
360
252
  }
361
- if (l)
362
- return R(l) && Array.isArray(l.children) && (l.children = l.children.filter(
363
- (a) => R(a) ? a.tag !== "#text" || typeof a.children == "string" && a.children.trim() !== "" : !0
364
- // keep non-element VNodes (including anchors) as-is
365
- )), l;
366
- if (h.length > 0) {
367
- const a = h.filter(
368
- (b) => R(b) ? b.tag !== "#text" || typeof b.children == "string" && b.children.trim() !== "" : !0
369
- );
370
- return a.length === 1 ? a[0] : a;
371
- }
372
- return P("div", {}, "", "fallback-root");
373
- }
374
- function Oe(e, ...t) {
375
- const n = t[t.length - 1], r = typeof n == "object" && n && !Array.isArray(n) ? n : void 0;
376
- return fe(e, t, r);
253
+ });
377
254
  }
378
- function Me(e, t) {
379
- return K(e ? t : [], "when-block");
255
+ function Ce(e, t, r, n) {
256
+ e.onConnected && !r && (e.onConnected(t), n(!0));
380
257
  }
381
- function Ne(e, t) {
382
- return e.map((n, r) => {
383
- const o = typeof n == "object" ? n?.key ?? n?.id ?? `idx-${r}` : String(n);
384
- return K(t(n, r), `each-${o}`);
385
- });
258
+ function Se(e, t, r, n, o, s, i, a) {
259
+ e.onDisconnected && e.onDisconnected(t), r.forEach((c) => c()), n(), o(), s(!1), i(null), a(!1);
386
260
  }
387
- function Pe() {
388
- const e = [];
389
- return {
390
- when(t, n) {
391
- return e.push([t, n]), this;
392
- },
393
- otherwise(t) {
394
- return e.push([!0, t]), this;
395
- },
396
- done() {
397
- return ue(...e);
398
- }
399
- };
261
+ function _e(e, t, r, n, o) {
262
+ e.onAttributeChanged && e.onAttributeChanged(t, r, n, o);
400
263
  }
401
- function ue(...e) {
402
- for (let t = 0; t < e.length; t++) {
403
- const [n, r] = e[t];
404
- if (n) return [K(r, `whenChain-branch-${t}`)];
264
+ function R(e, t) {
265
+ if (t && e instanceof HTMLElement) {
266
+ for (const r in t)
267
+ t[r] === e && delete t[r];
268
+ for (const r of Array.from(e.childNodes))
269
+ R(r, t);
405
270
  }
406
- return [K([], "whenChain-empty")];
407
271
  }
408
- function K(e, t) {
409
- const n = e ? Array.isArray(e) ? e.filter(Boolean) : [e].filter(Boolean) : [];
410
- return {
411
- tag: "#anchor",
412
- key: t,
413
- children: n
414
- };
415
- }
416
- function z(e, t) {
417
- return t.split(".").reduce((n, r) => n?.[r], e);
272
+ function N(e, t) {
273
+ return t.split(".").reduce((r, n) => r?.[n], e);
418
274
  }
419
- function Y(e, t, n) {
420
- const r = t.split("."), o = r.pop();
275
+ function se(e, t, r) {
276
+ const n = t.split("."), o = n.pop();
421
277
  if (!o) return;
422
- const s = r.reduce((i, l) => (l in i || (i[l] = {}), i[l]), e);
423
- s[o] = n;
278
+ const s = n.reduce((i, a) => (a in i || (i[a] = {}), i[a]), e);
279
+ s[o] = r;
424
280
  }
425
- function de(e, t, n, r, o, s, i) {
281
+ function Ae(e, t, r, n, o, s, i) {
426
282
  if (!s) return;
427
- const l = t.includes("lazy"), c = t.includes("trim"), d = t.includes("number"), p = () => {
428
- const y = s._state || s;
429
- return z(y, e);
430
- }, u = p();
431
- let f = "text";
432
- const m = r?.type;
433
- if (i instanceof HTMLInputElement ? f = m || i.type || "text" : i instanceof HTMLSelectElement ? f = "select" : i instanceof HTMLTextAreaElement && (f = "textarea"), f === "checkbox")
434
- if (Array.isArray(u)) {
435
- const y = i?.getAttribute("value") || r?.value || "", a = u.includes(y);
436
- i && i.checked !== a && (n.checked = a);
283
+ const a = t.includes("lazy"), c = t.includes("trim"), f = t.includes("number"), g = () => {
284
+ const h = s._state || s;
285
+ return N(h, e);
286
+ }, d = g();
287
+ let u = "text";
288
+ const v = n?.type;
289
+ if (i instanceof HTMLInputElement ? u = v || i.type || "text" : i instanceof HTMLSelectElement ? u = "select" : i instanceof HTMLTextAreaElement && (u = "textarea"), u === "checkbox")
290
+ if (Array.isArray(d)) {
291
+ const h = i?.getAttribute("value") || n?.value || "", l = d.includes(h);
292
+ i && i.checked !== l && (r.checked = l);
437
293
  } else {
438
- const y = i?.getAttribute("true-value") || !0, a = u === y;
439
- i && i.checked !== a && (n.checked = a);
294
+ const h = i?.getAttribute("true-value") || !0, l = d === h;
295
+ i && i.checked !== l && (r.checked = l);
440
296
  }
441
- else if (f === "radio") {
442
- const y = r?.value || "", a = u === y;
443
- i && i.checked !== a && (n.checked = a);
444
- } else if (f === "select")
297
+ else if (u === "radio") {
298
+ const h = n?.value || "", l = d === h;
299
+ i && i.checked !== l && (r.checked = l);
300
+ } else if (u === "select")
445
301
  if (i && i.hasAttribute("multiple")) {
446
- const y = i, a = Array.isArray(u) ? u : [];
302
+ const h = i, l = Array.isArray(d) ? d : [];
447
303
  setTimeout(() => {
448
- Array.from(y.options).forEach((b) => {
449
- const g = a.includes(b.value);
450
- b.selected !== g && (b.selected = g);
304
+ Array.from(h.options).forEach((p) => {
305
+ const m = l.includes(p.value);
306
+ p.selected !== m && (p.selected = m);
451
307
  });
452
308
  }, 0);
453
309
  } else
454
310
  setTimeout(() => {
455
- i instanceof HTMLSelectElement && i.value !== String(u) && (i.value = String(u));
311
+ i instanceof HTMLSelectElement && i.value !== String(d) && (i.value = String(d));
456
312
  }, 0);
457
313
  else {
458
- const y = String(u ?? "");
459
- (!i || i.value !== y) && (n.value = u);
460
- }
461
- const h = l || f === "checkbox" || f === "radio" || f === "select" ? "change" : "input", S = (y) => {
462
- if (y.isComposing || o._isComposing || y.isTrusted === !1) return;
463
- const a = y.target;
464
- if (a._modelUpdating) return;
465
- const b = p();
466
- let g = a.value;
467
- if (f === "checkbox")
468
- if (Array.isArray(b)) {
469
- const $ = a.getAttribute("value") || "", C = [...b];
470
- if (a.checked)
471
- C.includes($) || C.push($);
314
+ const h = String(d ?? "");
315
+ (!i || i.value !== h) && (r.value = d);
316
+ }
317
+ const y = a || u === "checkbox" || u === "radio" || u === "select" ? "change" : "input", b = (h) => {
318
+ if (h.isComposing || o._isComposing || h.isTrusted === !1) return;
319
+ const l = h.target;
320
+ if (l._modelUpdating) return;
321
+ const p = g();
322
+ let m = l.value;
323
+ if (u === "checkbox")
324
+ if (Array.isArray(p)) {
325
+ const S = l.getAttribute("value") || "", _ = [...p];
326
+ if (l.checked)
327
+ _.includes(S) || _.push(S);
472
328
  else {
473
- const v = C.indexOf($);
474
- v > -1 && C.splice(v, 1);
329
+ const w = _.indexOf(S);
330
+ w > -1 && _.splice(w, 1);
475
331
  }
476
- g = C;
332
+ m = _;
477
333
  } else {
478
- const $ = a.getAttribute("true-value") || !0, C = a.getAttribute("false-value") || !1;
479
- g = a.checked ? $ : C;
334
+ const S = l.getAttribute("true-value") || !0, _ = l.getAttribute("false-value") || !1;
335
+ m = l.checked ? S : _;
480
336
  }
481
- else if (f === "radio")
482
- g = a.getAttribute("value") || a.value;
483
- else if (f === "select" && a.multiple) {
484
- const $ = a;
485
- g = Array.from($.selectedOptions).map(
486
- (C) => C.value
337
+ else if (u === "radio")
338
+ m = l.getAttribute("value") || l.value;
339
+ else if (u === "select" && l.multiple) {
340
+ const S = l;
341
+ m = Array.from(S.selectedOptions).map(
342
+ (_) => _.value
487
343
  );
488
- } else if (c && (g = g.trim()), d) {
489
- const $ = Number(g);
490
- isNaN($) || (g = $);
344
+ } else if (c && (m = m.trim()), f) {
345
+ const S = Number(m);
346
+ isNaN(S) || (m = S);
491
347
  }
492
- const x = s._state || s, w = z(x, e);
493
- if (Array.isArray(g) && Array.isArray(w) ? JSON.stringify([...g].sort()) !== JSON.stringify([...w].sort()) : g !== w) {
494
- const $ = y.target;
495
- $._modelUpdating = !0, Y(x, e, g), setTimeout(() => {
496
- $._modelUpdating = !1;
348
+ const x = s._state || s, k = N(x, e);
349
+ if (Array.isArray(m) && Array.isArray(k) ? JSON.stringify([...m].sort()) !== JSON.stringify([...k].sort()) : m !== k) {
350
+ const S = h.target;
351
+ S._modelUpdating = !0, se(x, e, m), setTimeout(() => {
352
+ S._modelUpdating = !1;
497
353
  }, 0), s._requestRender && s._requestRender();
498
354
  }
499
355
  };
500
- if (o[h] = S, f === "text" || f === "textarea") {
501
- const y = () => {
356
+ if (o[y] = b, u === "text" || u === "textarea") {
357
+ const h = () => {
502
358
  o._isComposing = !0;
503
- }, a = (b) => {
359
+ }, l = (p) => {
504
360
  o._isComposing = !1;
505
- const g = b.target;
361
+ const m = p.target;
506
362
  setTimeout(() => {
507
- if (g) {
508
- let x = g.value;
509
- if (c && (x = x.trim()), d) {
510
- const C = Number(x);
511
- isNaN(C) || (x = C);
363
+ if (m) {
364
+ let x = m.value;
365
+ if (c && (x = x.trim()), f) {
366
+ const _ = Number(x);
367
+ isNaN(_) || (x = _);
512
368
  }
513
- const w = s._state || s, k = z(w, e);
514
- (Array.isArray(x) && Array.isArray(k) ? JSON.stringify([...x].sort()) !== JSON.stringify([...k].sort()) : x !== k) && (g && (g._modelUpdating = !0, setTimeout(() => {
515
- g._modelUpdating = !1;
516
- }, 0)), Y(w, e, x), s._requestRender && s._requestRender());
369
+ const k = s._state || s, $ = N(k, e);
370
+ (Array.isArray(x) && Array.isArray($) ? JSON.stringify([...x].sort()) !== JSON.stringify([...$].sort()) : x !== $) && (m && (m._modelUpdating = !0, setTimeout(() => {
371
+ m._modelUpdating = !1;
372
+ }, 0)), se(k, e, x), s._requestRender && s._requestRender());
517
373
  }
518
374
  }, 0);
519
375
  };
520
- o.compositionstart = y, o.compositionend = a;
376
+ o.compositionstart = h, o.compositionend = l;
521
377
  }
522
378
  }
523
- function pe(e, t, n, r) {
524
- if (r)
379
+ function Ee(e, t, r, n) {
380
+ if (n)
525
381
  try {
526
382
  const o = JSON.parse(e);
527
383
  if (typeof o == "object")
528
384
  for (const [s, i] of Object.entries(o))
529
385
  t[s] = i;
530
386
  } catch {
531
- const o = z(r, e);
532
- n[e] = o;
387
+ const o = N(n, e);
388
+ r[e] = o;
533
389
  }
534
390
  }
535
- function he(e, t, n) {
536
- if (!n) return;
537
- const r = z(n, e), o = t.style || "", s = r ? "" : "none";
391
+ function Te(e, t, r) {
392
+ if (!r) return;
393
+ const n = N(r, e), o = t.style || "", s = n ? "" : "none";
538
394
  if (o) {
539
- const i = o.split(";").filter(Boolean), l = i.findIndex(
395
+ const i = o.split(";").filter(Boolean), a = i.findIndex(
540
396
  (c) => c.trim().startsWith("display:")
541
397
  );
542
- l >= 0 ? i[l] = `display: ${s}` : i.push(`display: ${s}`), t.style = i.join("; ");
398
+ a >= 0 ? i[a] = `display: ${s}` : i.push(`display: ${s}`), t.style = i.join("; ");
543
399
  } else
544
400
  t.style = `display: ${s}`;
545
401
  }
546
- function ge(e, t, n) {
547
- if (!n) return;
548
- const r = z(n, e);
402
+ function je(e, t, r) {
403
+ if (!r) return;
404
+ const n = N(r, e);
549
405
  let o = [];
550
- typeof r == "string" ? o = [r] : Array.isArray(r) ? o = r.filter(Boolean) : typeof r == "object" && (o = Object.entries(r).filter(([, l]) => !!l).map(([l]) => l));
406
+ typeof n == "string" ? o = [n] : Array.isArray(n) ? o = n.filter(Boolean) : typeof n == "object" && (o = Object.entries(n).filter(([, a]) => !!a).map(([a]) => a));
551
407
  const s = t.class || "", i = s ? `${s} ${o.join(" ")}`.trim() : o.join(" ");
552
408
  i && (t.class = i);
553
409
  }
554
- function me(e, t, n) {
555
- let r;
410
+ function Le(e, t, r) {
411
+ let n;
556
412
  if (typeof e == "string") {
557
- if (!n) return;
558
- r = z(n, e);
413
+ if (!r) return;
414
+ n = N(r, e);
559
415
  } else
560
- r = e;
416
+ n = e;
561
417
  let o = "";
562
- if (typeof r == "string")
563
- o = r;
564
- else if (r && typeof r == "object") {
418
+ if (typeof n == "string")
419
+ o = n;
420
+ else if (n && typeof n == "object") {
565
421
  const i = [];
566
- for (const [l, c] of Object.entries(r))
422
+ for (const [a, c] of Object.entries(n))
567
423
  if (c != null && c !== "") {
568
- const d = l.replace(
424
+ const f = a.replace(
569
425
  /[A-Z]/g,
570
- (f) => `-${f.toLowerCase()}`
571
- ), p = [
426
+ (u) => `-${u.toLowerCase()}`
427
+ ), g = [
572
428
  "width",
573
429
  "height",
574
430
  "top",
@@ -594,336 +450,334 @@ function me(e, t, n) {
594
450
  "min-height",
595
451
  "max-height"
596
452
  ];
597
- let u = String(c);
598
- typeof c == "number" && p.includes(d) && (u = `${c}px`), i.push(`${d}: ${u}`);
453
+ let d = String(c);
454
+ typeof c == "number" && g.includes(f) && (d = `${c}px`), i.push(`${f}: ${d}`);
599
455
  }
600
456
  o = i.join("; ") + (i.length > 0 ? ";" : "");
601
457
  }
602
458
  const s = t.style || "";
603
459
  t.style = s + (s && !s.endsWith(";") ? "; " : "") + o;
604
460
  }
605
- function ie(e, t, n, r) {
606
- const o = {}, s = { ...r || {} }, i = {};
607
- for (const [l, c] of Object.entries(e)) {
608
- const { value: d, modifiers: p } = c;
609
- switch (l) {
461
+ function he(e, t, r, n) {
462
+ const o = {}, s = { ...n || {} }, i = {};
463
+ for (const [a, c] of Object.entries(e)) {
464
+ const { value: f, modifiers: g } = c;
465
+ switch (a) {
610
466
  case "model":
611
- de(
612
- typeof d == "string" ? d : String(d),
613
- p,
467
+ Ae(
468
+ typeof f == "string" ? f : String(f),
469
+ g,
614
470
  o,
615
471
  s,
616
472
  i,
617
473
  t,
618
- n
474
+ r
619
475
  );
620
476
  break;
621
477
  case "bind":
622
- pe(d, o, s, t);
478
+ Ee(f, o, s, t);
623
479
  break;
624
480
  case "show":
625
- he(d, s, t);
481
+ Te(f, s, t);
626
482
  break;
627
483
  case "class":
628
- ge(d, s, t);
484
+ je(f, s, t);
629
485
  break;
630
486
  case "style":
631
- me(d, s, t);
487
+ Le(f, s, t);
632
488
  break;
633
489
  }
634
490
  }
635
491
  return { props: o, attrs: s, listeners: i };
636
492
  }
637
- function Z(e, t) {
493
+ function re(e, t) {
638
494
  if (Array.isArray(e)) {
639
495
  const s = /* @__PURE__ */ new Set();
640
496
  return e.map((i) => {
641
497
  if (!i || typeof i != "object") return i;
642
- let l = i.props?.key ?? i.key;
643
- if (!l) {
644
- const u = i.tag || "node", f = i.props?.attrs?.id ?? i.props?.attrs?.name ?? i.props?.attrs?.["data-key"] ?? "";
645
- l = f ? `${t}:${u}:${f}` : `${t}:${u}`;
498
+ let a = i.props?.key ?? i.key;
499
+ if (!a) {
500
+ const d = i.tag || "node", u = i.props?.attrs?.id ?? i.props?.attrs?.name ?? i.props?.attrs?.["data-key"] ?? "";
501
+ a = u ? `${t}:${d}:${u}` : `${t}:${d}`;
646
502
  }
647
- let c = l, d = 1;
503
+ let c = a, f = 1;
648
504
  for (; s.has(c); )
649
- c = `${l}#${d++}`;
505
+ c = `${a}#${f++}`;
650
506
  s.add(c);
651
- let p = i.children;
652
- return Array.isArray(p) && (p = Z(p, c)), { ...i, key: c, children: p };
507
+ let g = i.children;
508
+ return Array.isArray(g) && (g = re(g, c)), { ...i, key: c, children: g };
653
509
  });
654
510
  }
655
- const n = e;
656
- let r = n.props?.key ?? n.key ?? t, o = n.children;
657
- return Array.isArray(o) && (o = Z(o, r)), { ...n, key: r, children: o };
511
+ const r = e;
512
+ let n = r.props?.key ?? r.key ?? t, o = r.children;
513
+ return Array.isArray(o) && (o = re(o, n)), { ...r, key: n, children: o };
658
514
  }
659
- function ye(e, t, n, r) {
660
- const o = n.directives ?? {}, s = ie(
515
+ function Be(e, t, r, n) {
516
+ const o = r.directives ?? {}, s = he(
661
517
  o,
662
- r,
518
+ n,
663
519
  e,
664
- n.attrs
520
+ r.attrs
665
521
  ), i = {
666
522
  ...t.props,
667
- ...n.props,
523
+ ...r.props,
668
524
  ...s.props
669
- }, l = {
525
+ }, a = {
670
526
  ...t.attrs,
671
- ...n.attrs,
527
+ ...r.attrs,
672
528
  ...s.attrs
673
- }, c = t.props ?? {}, d = i;
674
- for (const f in { ...c, ...d }) {
675
- const m = c[f], h = d[f];
676
- m !== h && (f === "value" && (e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement || e instanceof HTMLSelectElement) ? e.value !== h && (e.value = h ?? "") : f === "checked" && e instanceof HTMLInputElement ? e.checked = !!h : f.startsWith("on") && typeof h == "function" ? (typeof m == "function" && e.removeEventListener(f.slice(2).toLowerCase(), m), e.addEventListener(f.slice(2).toLowerCase(), h)) : h == null || h === !1 ? e.removeAttribute(f) : e.setAttribute(f, String(h)));
529
+ }, c = t.props ?? {}, f = i;
530
+ for (const u in { ...c, ...f }) {
531
+ const v = c[u], y = f[u];
532
+ v !== y && (u === "value" && (e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement || e instanceof HTMLSelectElement) ? e.value !== y && (e.value = y ?? "") : u === "checked" && e instanceof HTMLInputElement ? e.checked = !!y : u.startsWith("on") && typeof y == "function" ? (typeof v == "function" && e.removeEventListener(u.slice(2).toLowerCase(), v), e.addEventListener(u.slice(2).toLowerCase(), y)) : y == null || y === !1 ? e.removeAttribute(u) : e.setAttribute(u, String(y)));
677
533
  }
678
- for (const [f, m] of Object.entries(
534
+ for (const [u, v] of Object.entries(
679
535
  s.listeners || {}
680
536
  ))
681
- e.addEventListener(f, m);
682
- const p = t.attrs ?? {}, u = l;
683
- for (const f in { ...p, ...u }) {
684
- const m = p[f], h = u[f];
685
- m !== h && (h == null || h === !1 ? e.removeAttribute(f) : e.setAttribute(f, String(h)));
537
+ e.addEventListener(u, v);
538
+ const g = t.attrs ?? {}, d = a;
539
+ for (const u in { ...g, ...d }) {
540
+ const v = g[u], y = d[u];
541
+ v !== y && (y == null || y === !1 ? e.removeAttribute(u) : e.setAttribute(u, String(y)));
686
542
  }
687
543
  }
688
- function T(e, t, n) {
544
+ function T(e, t, r) {
689
545
  if (typeof e == "string")
690
546
  return document.createTextNode(e);
691
547
  if (e.tag === "#text") {
692
- const u = document.createTextNode(
548
+ const d = document.createTextNode(
693
549
  typeof e.children == "string" ? e.children : ""
694
550
  );
695
- return e.key != null && (u.key = e.key), u;
551
+ return e.key != null && (d.key = e.key), d;
696
552
  }
697
553
  if (e.tag === "#anchor") {
698
- const u = e, f = Array.isArray(u.children) ? u.children : [], m = document.createTextNode(""), h = document.createTextNode("");
699
- u.key != null && (m.key = `${u.key}:start`, h.key = `${u.key}:end`), u._startNode = m, u._endNode = h;
700
- const S = document.createDocumentFragment();
701
- S.appendChild(m);
702
- for (const y of f)
703
- S.appendChild(T(y, t));
704
- return S.appendChild(h), S;
705
- }
706
- const r = document.createElement(e.tag);
707
- e.key != null && (r.key = e.key);
708
- const { props: o = {}, attrs: s = {}, directives: i = {} } = e.props ?? {}, l = ie(i, t, r, s), c = {
554
+ const d = e, u = Array.isArray(d.children) ? d.children : [], v = document.createTextNode(""), y = document.createTextNode("");
555
+ d.key != null && (v.key = `${d.key}:start`, y.key = `${d.key}:end`), d._startNode = v, d._endNode = y;
556
+ const b = document.createDocumentFragment();
557
+ b.appendChild(v);
558
+ for (const h of u)
559
+ b.appendChild(T(h, t));
560
+ return b.appendChild(y), b;
561
+ }
562
+ const n = document.createElement(e.tag);
563
+ e.key != null && (n.key = e.key);
564
+ const { props: o = {}, attrs: s = {}, directives: i = {} } = e.props ?? {}, a = he(i, t, n, s), c = {
709
565
  ...o,
710
- ...l.props
711
- }, d = {
566
+ ...a.props
567
+ }, f = {
712
568
  ...s,
713
- ...l.attrs
569
+ ...a.attrs
714
570
  };
715
- for (const u in d) {
716
- const f = d[u];
717
- typeof f == "boolean" ? f && r.setAttribute(u, "") : f != null && r.setAttribute(u, String(f));
718
- }
719
- for (const u in c) {
720
- const f = c[u];
721
- if (u === "value" && (r instanceof HTMLInputElement || r instanceof HTMLTextAreaElement || r instanceof HTMLSelectElement))
722
- r.value = f ?? "";
723
- else if (u === "checked" && r instanceof HTMLInputElement)
724
- r.checked = !!f;
725
- else if (u.startsWith("on") && typeof f == "function")
726
- r.addEventListener(u.slice(2).toLowerCase(), f);
571
+ for (const d in f) {
572
+ const u = f[d];
573
+ typeof u == "boolean" ? u && n.setAttribute(d, "") : u != null && n.setAttribute(d, String(u));
574
+ }
575
+ for (const d in c) {
576
+ const u = c[d];
577
+ if (d === "value" && (n instanceof HTMLInputElement || n instanceof HTMLTextAreaElement || n instanceof HTMLSelectElement))
578
+ n.value = u ?? "";
579
+ else if (d === "checked" && n instanceof HTMLInputElement)
580
+ n.checked = !!u;
581
+ else if (d.startsWith("on") && typeof u == "function")
582
+ n.addEventListener(d.slice(2).toLowerCase(), u);
727
583
  else {
728
- if (u.startsWith("on") && f === void 0)
584
+ if (d.startsWith("on") && u === void 0)
729
585
  continue;
730
- f == null || f === !1 ? r.removeAttribute(u) : r.setAttribute(u, String(f));
586
+ u == null || u === !1 ? n.removeAttribute(d) : n.setAttribute(d, String(u));
731
587
  }
732
588
  }
733
- for (const [u, f] of Object.entries(
734
- l.listeners || {}
589
+ for (const [d, u] of Object.entries(
590
+ a.listeners || {}
735
591
  ))
736
- r.addEventListener(u, f);
737
- const p = e.props?.ref ?? (e.props?.props && e.props.props.ref);
738
- if (typeof e != "string" && p && n && (n[p] = r), Array.isArray(e.children))
739
- for (const u of e.children)
740
- r.appendChild(T(u, t, n));
741
- else typeof e.children == "string" && (r.textContent = e.children);
742
- return r;
592
+ n.addEventListener(d, u);
593
+ const g = e.props?.ref ?? (e.props?.props && e.props.props.ref);
594
+ if (typeof e != "string" && g && r && (r[g] = n), Array.isArray(e.children))
595
+ for (const d of e.children)
596
+ n.appendChild(T(d, t, r));
597
+ else typeof e.children == "string" && (n.textContent = e.children);
598
+ return n;
743
599
  }
744
- function be(e, t, n, r, o) {
745
- if (typeof n == "string") {
746
- e.textContent !== n && (e.textContent = n);
600
+ function ze(e, t, r, n, o) {
601
+ if (typeof r == "string") {
602
+ e.textContent !== r && (e.textContent = r);
747
603
  return;
748
604
  }
749
- if (!Array.isArray(n)) return;
750
- const s = Array.from(e.childNodes), i = Array.isArray(t) ? t : [], l = /* @__PURE__ */ new Map();
751
- for (const m of i)
752
- m && m.key != null && l.set(m.key, m);
605
+ if (!Array.isArray(r)) return;
606
+ const s = Array.from(e.childNodes), i = Array.isArray(t) ? t : [], a = /* @__PURE__ */ new Map();
607
+ for (const v of i)
608
+ v && v.key != null && a.set(v.key, v);
753
609
  const c = /* @__PURE__ */ new Map();
754
- for (const m of s) {
755
- const h = m.key;
756
- h != null && c.set(h, m);
757
- }
758
- const d = /* @__PURE__ */ new Set();
759
- let p = e.firstChild;
760
- function u(m, h) {
761
- let S = m;
762
- for (; S && (d.add(S), S !== h); )
763
- S = S.nextSibling;
764
- }
765
- function f(m, h, S, y) {
766
- const a = [];
767
- let b = m.nextSibling;
768
- for (; b && b !== h; )
769
- a.push(b), b = b.nextSibling;
770
- const g = Array.isArray(S) ? S : [];
771
- if (y.some((w) => w && w.key != null) || g.some((w) => w && w.key != null)) {
772
- const w = /* @__PURE__ */ new Map(), k = /* @__PURE__ */ new Map();
773
- for (const v of g)
774
- v && v.key != null && w.set(v.key, v);
775
- for (const v of a) {
776
- const _ = v.key;
777
- _ != null && k.set(_, v);
610
+ for (const v of s) {
611
+ const y = v.key;
612
+ y != null && c.set(y, v);
613
+ }
614
+ const f = /* @__PURE__ */ new Set();
615
+ let g = e.firstChild;
616
+ function d(v, y) {
617
+ let b = v;
618
+ for (; b && (f.add(b), b !== y); )
619
+ b = b.nextSibling;
620
+ }
621
+ function u(v, y, b, h) {
622
+ const l = [];
623
+ let p = v.nextSibling;
624
+ for (; p && p !== y; )
625
+ l.push(p), p = p.nextSibling;
626
+ const m = Array.isArray(b) ? b : [];
627
+ if (h.some((k) => k && k.key != null) || m.some((k) => k && k.key != null)) {
628
+ const k = /* @__PURE__ */ new Map(), $ = /* @__PURE__ */ new Map();
629
+ for (const w of m)
630
+ w && w.key != null && k.set(w.key, w);
631
+ for (const w of l) {
632
+ const C = w.key;
633
+ C != null && $.set(C, w);
778
634
  }
779
- const $ = /* @__PURE__ */ new Set();
780
- let C = m.nextSibling;
781
- for (const v of y) {
782
- let _;
783
- if (v.key != null && k.has(v.key)) {
784
- const A = w.get(v.key);
785
- _ = D(
786
- k.get(v.key),
635
+ const S = /* @__PURE__ */ new Set();
636
+ let _ = v.nextSibling;
637
+ for (const w of h) {
638
+ let C;
639
+ if (w.key != null && $.has(w.key)) {
640
+ const A = k.get(w.key);
641
+ C = K(
642
+ $.get(w.key),
787
643
  A,
788
- v,
789
- r
790
- ), $.add(_), _ !== C && e.contains(_) && e.insertBefore(_, C);
644
+ w,
645
+ n
646
+ ), S.add(C), C !== _ && e.contains(C) && e.insertBefore(C, _);
791
647
  } else
792
- _ = T(v, r), e.insertBefore(_, C), $.add(_);
793
- C = _.nextSibling;
648
+ C = T(w, n), e.insertBefore(C, _), S.add(C);
649
+ _ = C.nextSibling;
794
650
  }
795
- for (const v of a)
796
- !$.has(v) && e.contains(v) && e.removeChild(v);
651
+ for (const w of l)
652
+ !S.has(w) && e.contains(w) && e.removeChild(w);
797
653
  } else {
798
- const w = Math.min(
799
- g.length,
800
- y.length
654
+ const k = Math.min(
655
+ m.length,
656
+ h.length
801
657
  );
802
- for (let k = 0; k < w; k++) {
803
- const $ = g[k], C = y[k], v = D(a[k], $, C, r);
804
- v !== a[k] && (e.insertBefore(v, a[k]), e.removeChild(a[k]));
658
+ for (let $ = 0; $ < k; $++) {
659
+ const S = m[$], _ = h[$], w = K(l[$], S, _, n);
660
+ w !== l[$] && (e.insertBefore(w, l[$]), e.removeChild(l[$]));
805
661
  }
806
- for (let k = w; k < y.length; k++)
807
- e.insertBefore(T(y[k], r), h);
808
- for (let k = w; k < a.length; k++)
809
- e.removeChild(a[k]);
662
+ for (let $ = k; $ < h.length; $++)
663
+ e.insertBefore(T(h[$], n), y);
664
+ for (let $ = k; $ < l.length; $++)
665
+ e.removeChild(l[$]);
810
666
  }
811
667
  }
812
- for (const m of n) {
813
- let h;
814
- if (m.tag === "#anchor") {
815
- const S = m.key, y = `${S}:start`, a = `${S}:end`;
816
- let b = c.get(y), g = c.get(a);
817
- const x = Array.isArray(m.children) ? m.children : [];
818
- if (b || (b = document.createTextNode(""), b.key = y), g || (g = document.createTextNode(""), g.key = a), m._startNode = b, m._endNode = g, !e.contains(b) || !e.contains(g)) {
819
- e.insertBefore(b, p);
820
- for (const w of x)
821
- e.insertBefore(T(w, r), p);
822
- e.insertBefore(g, p);
668
+ for (const v of r) {
669
+ let y;
670
+ if (v.tag === "#anchor") {
671
+ const b = v.key, h = `${b}:start`, l = `${b}:end`;
672
+ let p = c.get(h), m = c.get(l);
673
+ const x = Array.isArray(v.children) ? v.children : [];
674
+ if (p || (p = document.createTextNode(""), p.key = h), m || (m = document.createTextNode(""), m.key = l), v._startNode = p, v._endNode = m, !e.contains(p) || !e.contains(m)) {
675
+ e.insertBefore(p, g);
676
+ for (const k of x)
677
+ e.insertBefore(T(k, n), g);
678
+ e.insertBefore(m, g);
823
679
  } else
824
- f(
825
- b,
826
- g,
827
- l.get(S)?.children,
680
+ u(
681
+ p,
682
+ m,
683
+ a.get(b)?.children,
828
684
  x
829
685
  );
830
- u(b, g), p = g.nextSibling;
686
+ d(p, m), g = m.nextSibling;
831
687
  continue;
832
688
  }
833
- if (m.key != null && c.has(m.key)) {
834
- const S = l.get(m.key);
835
- h = D(
836
- c.get(m.key),
837
- S,
838
- m,
839
- r,
689
+ if (v.key != null && c.has(v.key)) {
690
+ const b = a.get(v.key);
691
+ y = K(
692
+ c.get(v.key),
693
+ b,
694
+ v,
695
+ n,
840
696
  o
841
- ), d.add(h), h !== p && e.contains(h) && (p && !e.contains(p) && (p = null), e.insertBefore(h, p));
697
+ ), f.add(y), y !== g && e.contains(y) && (g && !e.contains(g) && (g = null), e.insertBefore(y, g));
842
698
  } else
843
- h = T(m, r, o), p && !e.contains(p) && (p = null), e.insertBefore(h, p), d.add(h);
844
- p = h.nextSibling;
845
- }
846
- for (const m of s)
847
- if (!d.has(m) && e.contains(m)) {
848
- if (m instanceof HTMLElement && o)
849
- for (const h in o)
850
- o[h] === m && delete o[h];
851
- e.removeChild(m);
852
- }
699
+ y = T(v, n, o), g && !e.contains(g) && (g = null), e.insertBefore(y, g), f.add(y);
700
+ g = y.nextSibling;
701
+ }
702
+ for (const v of s)
703
+ !f.has(v) && e.contains(v) && (R(v, o), e.removeChild(v));
853
704
  }
854
- function D(e, t, n, r, o) {
855
- if (t && typeof t != "string" && t.props?.ref && o && delete o[t.props.ref], t === n) return e;
856
- if (typeof n == "string") {
705
+ function K(e, t, r, n, o) {
706
+ if (t && typeof t != "string" && t.props?.ref && o && R(e, o), t === r) return e;
707
+ if (typeof r == "string") {
857
708
  if (e.nodeType === Node.TEXT_NODE)
858
- return e.textContent !== n && (e.textContent = n), e;
709
+ return e.textContent !== r && (e.textContent = r), e;
859
710
  {
860
- const i = document.createTextNode(n);
711
+ const i = document.createTextNode(r);
861
712
  return e.parentNode?.replaceChild(i, e), i;
862
713
  }
863
714
  }
864
- if (n && typeof n != "string" && n.tag === "#anchor") {
865
- const i = n, l = Array.isArray(i.children) ? i.children : [], c = i._startNode ?? document.createTextNode(""), d = i._endNode ?? document.createTextNode("");
866
- i.key != null && (c.key = `${i.key}:start`, d.key = `${i.key}:end`), i._startNode = c, i._endNode = d;
867
- const p = document.createDocumentFragment();
868
- p.appendChild(c);
869
- for (const u of l)
870
- p.appendChild(T(u, r));
871
- return p.appendChild(d), e.parentNode?.replaceChild(p, e), c;
715
+ if (r && typeof r != "string" && r.tag === "#anchor") {
716
+ const i = r, a = Array.isArray(i.children) ? i.children : [], c = i._startNode ?? document.createTextNode(""), f = i._endNode ?? document.createTextNode("");
717
+ i.key != null && (c.key = `${i.key}:start`, f.key = `${i.key}:end`), i._startNode = c, i._endNode = f;
718
+ const g = document.createDocumentFragment();
719
+ g.appendChild(c);
720
+ for (const d of a)
721
+ g.appendChild(T(d, n));
722
+ return g.appendChild(f), e.parentNode?.replaceChild(g, e), c;
872
723
  }
873
- if (!n) {
724
+ if (!r) {
725
+ R(e, o);
874
726
  const i = document.createComment("removed");
875
727
  return e.parentNode?.replaceChild(i, e), i;
876
728
  }
877
729
  if (!t || typeof t == "string") {
878
- const i = T(n, r, o);
879
- return typeof n != "string" && n.props?.ref && o && (o[n.props.ref] = i), e.parentNode?.replaceChild(i, e), i;
880
- }
881
- if (n.tag === "#anchor") {
882
- const i = Array.isArray(n.children) ? n.children : [], l = n._startNode ?? document.createTextNode(""), c = n._endNode ?? document.createTextNode("");
883
- n.key != null && (l.key = `${n.key}:start`, c.key = `${n.key}:end`), n._startNode = l, n._endNode = c;
884
- const d = document.createDocumentFragment();
885
- d.appendChild(l);
886
- for (const p of i)
887
- d.appendChild(T(p, r));
888
- return d.appendChild(c), e.parentNode?.replaceChild(d, e), l;
889
- }
890
- if (typeof t != "string" && typeof n != "string" && t.tag === n.tag && t.key === n.key) {
730
+ R(e, o);
731
+ const i = T(r, n, o);
732
+ return typeof r != "string" && r.props?.ref && o && (o[r.props.ref] = i), e.parentNode?.replaceChild(i, e), i;
733
+ }
734
+ if (r.tag === "#anchor") {
735
+ const i = Array.isArray(r.children) ? r.children : [], a = r._startNode ?? document.createTextNode(""), c = r._endNode ?? document.createTextNode("");
736
+ r.key != null && (a.key = `${r.key}:start`, c.key = `${r.key}:end`), r._startNode = a, r._endNode = c;
737
+ const f = document.createDocumentFragment();
738
+ f.appendChild(a);
739
+ for (const g of i)
740
+ f.appendChild(T(g, n));
741
+ return f.appendChild(c), e.parentNode?.replaceChild(f, e), a;
742
+ }
743
+ if (typeof t != "string" && typeof r != "string" && t.tag === r.tag && t.key === r.key) {
891
744
  const i = e;
892
- return ye(i, t.props || {}, n.props || {}, r), be(i, t.children, n.children, r, o), typeof n != "string" && n.props?.ref && o && (o[n.props.ref] = i), i;
745
+ return Be(i, t.props || {}, r.props || {}, n), ze(i, t.children, r.children, n, o), typeof r != "string" && r.props?.ref && o && (o[r.props.ref] = i), i;
893
746
  }
894
- const s = T(n, r, o);
895
- return typeof n != "string" && n.props?.ref && o && (o[n.props.ref] = s), e.parentNode?.replaceChild(s, e), s;
747
+ R(e, o);
748
+ const s = T(r, n, o);
749
+ return typeof r != "string" && r.props?.ref && o && (o[r.props.ref] = s), e.parentNode?.replaceChild(s, e), s;
896
750
  }
897
- function xe(e, t, n, r) {
898
- const o = (p) => p.key == null ? { ...p, key: "__root__" } : p;
899
- let s = Array.isArray(t) ? { tag: "div", key: "__root__", children: t } : o(t);
900
- s = Z(s, String(s.key ?? "root"));
901
- const i = e._prevVNode ?? null, l = e._prevDom ?? e.firstChild ?? null;
902
- let c;
903
- i && l ? typeof i != "string" && typeof s != "string" && i.tag === s.tag && i.key === s.key ? c = D(l, i, s, n, r) : (c = T(s, n, r), e.replaceChild(c, l)) : (c = T(s, n, r), e.firstChild ? e.replaceChild(c, e.firstChild) : e.appendChild(c));
904
- const d = [];
905
- for (let p = 0; p < e.childNodes.length; p++) {
906
- const u = e.childNodes[p];
907
- if (u !== c && u.nodeName !== "STYLE") {
908
- if (u instanceof HTMLElement && r)
909
- for (const f in r)
910
- r[f] === u && delete r[f];
911
- d.push(u);
912
- }
751
+ function Re(e, t, r, n) {
752
+ let o;
753
+ Array.isArray(t) ? t.length === 1 ? (o = t[0], o && typeof o == "object" && o.key == null && (o = { ...o, key: "__root__" })) : o = { tag: "div", key: "__root__", children: t } : (o = t, o && typeof o == "object" && o.key == null && (o = { ...o, key: "__root__" })), o = re(o, String(o.key ?? "root"));
754
+ const s = e._prevVNode ?? null, i = e._prevDom ?? e.firstChild ?? null;
755
+ let a;
756
+ s && i ? typeof s != "string" && typeof o != "string" && s.tag === o.tag && s.key === o.key ? a = K(i, s, o, r, n) : (a = T(o, r, n), e.replaceChild(a, i)) : (a = T(o, r, n), e.firstChild ? e.replaceChild(a, e.firstChild) : e.appendChild(a));
757
+ const c = [];
758
+ for (let f = 0; f < e.childNodes.length; f++) {
759
+ const g = e.childNodes[f];
760
+ g !== a && g.nodeName !== "STYLE" && (R(g, n), c.push(g));
913
761
  }
914
- d.forEach((p) => e.removeChild(p)), e._prevVNode = s, e._prevDom = c;
762
+ c.forEach((f) => e.removeChild(f)), e._prevVNode = o, e._prevDom = a;
763
+ }
764
+ function ge(e, ...t) {
765
+ let r = "";
766
+ for (let n = 0; n < e.length; n++)
767
+ r += e[n], n < t.length && (r += t[n]);
768
+ return r;
915
769
  }
916
- function oe(e) {
770
+ function ye(e) {
917
771
  return e.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\s+/g, " ").replace(/\s*([{}:;,>+~])\s*/g, "$1").replace(/;}/g, "}").trim();
918
772
  }
919
- let H = null;
920
- function G() {
921
- return H || (H = new CSSStyleSheet(), H.replaceSync(oe(we))), H;
773
+ let I = null;
774
+ function ae() {
775
+ return I || (I = new CSSStyleSheet(), I.replaceSync(ye(Me))), I;
922
776
  }
923
- function ve(e) {
777
+ function Ne(e) {
924
778
  return e.replace(/url\s*\(\s*['"]?javascript:[^)]*\)/gi, "").replace(/<script[\s\S]*?>[\s\S]*?<\/script>/gi, "").replace(/expression\s*\([^)]*\)/gi, "");
925
779
  }
926
- const we = `
780
+ const Me = ge`
927
781
  :host, *, ::before, ::after {
928
782
  all: isolate;
929
783
  box-sizing: border-box;
@@ -981,7 +835,7 @@ const we = `
981
835
  sup { top: -.5em }
982
836
  [disabled], [aria-disabled=true] { cursor: not-allowed }
983
837
  [hidden] { display: none }
984
- `, ke = {
838
+ `, Pe = {
985
839
  gray: {
986
840
  50: "var(--color-gray-50, #f9fafb)",
987
841
  100: "var(--color-gray-100, #f3f4f6)",
@@ -1116,7 +970,7 @@ const we = `
1116
970
  },
1117
971
  white: { DEFAULT: "var(--color-white, #ffffff)" },
1118
972
  black: { DEFAULT: "var(--color-black, #000000)" }
1119
- }, F = {
973
+ }, Q = {
1120
974
  /* Display */
1121
975
  block: "display:block;",
1122
976
  inline: "display:inline;",
@@ -1290,7 +1144,7 @@ const we = `
1290
1144
  "transition-colors": "transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;",
1291
1145
  "transition-opacity": "transition-property:opacity;",
1292
1146
  "transition-transform": "transition-property:transform;"
1293
- }, _e = "var(--spacing, 0.25rem)", ee = {
1147
+ }, Oe = "var(--spacing, 0.25rem)", le = {
1294
1148
  m: ["margin"],
1295
1149
  mx: ["margin-inline"],
1296
1150
  my: ["margin-block"],
@@ -1321,7 +1175,7 @@ const we = `
1321
1175
  gap: ["gap"],
1322
1176
  "gap-x": ["column-gap"],
1323
1177
  "gap-y": ["row-gap"]
1324
- }, $e = {
1178
+ }, We = {
1325
1179
  // State variants
1326
1180
  before: (e, t) => `${e}::before{${t}}`,
1327
1181
  after: (e, t) => `${e}::after{${t}}`,
@@ -1347,7 +1201,7 @@ const we = `
1347
1201
  "peer-focus": (e, t) => `.peer:focus ~ ${e}{${t}}`,
1348
1202
  "peer-checked": (e, t) => `.peer:checked ~ ${e}{${t}}`,
1349
1203
  "peer-disabled": (e, t) => `.peer:disabled ~ ${e}{${t}}`
1350
- }, te = {
1204
+ }, ce = {
1351
1205
  // Responsive
1352
1206
  sm: "(min-width:640px)",
1353
1207
  md: "(min-width:768px)",
@@ -1356,23 +1210,23 @@ const we = `
1356
1210
  "2xl": "(min-width:1536px)",
1357
1211
  // Dark mode (now plain string)
1358
1212
  dark: "(prefers-color-scheme: dark)"
1359
- }, V = ["sm", "md", "lg", "xl", "2xl"];
1360
- function U(e) {
1361
- const t = e.startsWith("-"), r = (t ? e.slice(1) : e).split("-");
1362
- if (r.length < 2) return null;
1363
- const o = r.slice(0, -1).join("-"), s = r[r.length - 1], i = parseFloat(s);
1364
- if (Number.isNaN(i) || !ee[o]) return null;
1365
- const l = t ? "-" : "";
1366
- return ee[o].map((c) => `${c}:calc(${l}${_e} * ${i});`).join("");
1213
+ }, Z = ["sm", "md", "lg", "xl", "2xl"];
1214
+ function X(e) {
1215
+ const t = e.startsWith("-"), n = (t ? e.slice(1) : e).split("-");
1216
+ if (n.length < 2) return null;
1217
+ const o = n.slice(0, -1).join("-"), s = n[n.length - 1], i = parseFloat(s);
1218
+ if (Number.isNaN(i) || !le[o]) return null;
1219
+ const a = t ? "-" : "";
1220
+ return le[o].map((c) => `${c}:calc(${a}${Oe} * ${i});`).join("");
1367
1221
  }
1368
- function re(e) {
1369
- const t = e.replace("#", ""), n = parseInt(t, 16), r = n >> 16 & 255, o = n >> 8 & 255, s = n & 255;
1370
- return `${r} ${o} ${s}`;
1222
+ function fe(e) {
1223
+ const t = e.replace("#", ""), r = parseInt(t, 16), n = r >> 16 & 255, o = r >> 8 & 255, s = r & 255;
1224
+ return `${n} ${o} ${s}`;
1371
1225
  }
1372
- function Se(e) {
1226
+ function De(e) {
1373
1227
  const t = /^(bg|text|border|shadow|outline|caret|accent)-([a-z]+)-?(\d{2,3}|DEFAULT)?$/.exec(e);
1374
1228
  if (!t) return null;
1375
- const [, n, r, o = "DEFAULT"] = t, s = ke[r]?.[o];
1229
+ const [, r, n, o = "DEFAULT"] = t, s = Pe[n]?.[o];
1376
1230
  return s ? `${{
1377
1231
  bg: "background-color",
1378
1232
  text: "color",
@@ -1381,40 +1235,40 @@ function Se(e) {
1381
1235
  outline: "outline-color",
1382
1236
  caret: "caret-color",
1383
1237
  accent: "accent-color"
1384
- }[n]}:${s};` : null;
1238
+ }[r]}:${s};` : null;
1385
1239
  }
1386
- function Ce(e) {
1387
- const [t, n] = e.split("/");
1388
- if (!n) return { base: t };
1389
- const r = parseInt(n, 10);
1390
- return isNaN(r) || r < 0 || r > 100 ? { base: t } : { base: t, opacity: r / 100 };
1240
+ function He(e) {
1241
+ const [t, r] = e.split("/");
1242
+ if (!r) return { base: t };
1243
+ const n = parseInt(r, 10);
1244
+ return isNaN(n) || n < 0 || n > 100 ? { base: t } : { base: t, opacity: n / 100 };
1391
1245
  }
1392
- function q(e) {
1393
- const { base: t, opacity: n } = Ce(e), r = Se(t);
1394
- if (r) {
1395
- if (n !== void 0) {
1396
- const s = /#([0-9a-f]{6})/i.exec(r);
1246
+ function Y(e) {
1247
+ const { base: t, opacity: r } = He(e), n = De(t);
1248
+ if (n) {
1249
+ if (r !== void 0) {
1250
+ const s = /#([0-9a-f]{6})/i.exec(n);
1397
1251
  if (s) {
1398
- const i = re(s[0]);
1399
- return r.replace(/#([0-9a-f]{6})/i, `rgb(${i} / ${n})`);
1252
+ const i = fe(s[0]);
1253
+ return n.replace(/#([0-9a-f]{6})/i, `rgb(${i} / ${r})`);
1400
1254
  }
1401
1255
  }
1402
- return r;
1256
+ return n;
1403
1257
  }
1404
- const o = W(t);
1405
- if (o && n !== void 0) {
1258
+ const o = U(t);
1259
+ if (o && r !== void 0) {
1406
1260
  const s = /#([0-9a-f]{6})/i.exec(o);
1407
1261
  if (s) {
1408
- const i = re(s[0]);
1409
- return o.replace(/#([0-9a-f]{6})/i, `rgb(${i} / ${n})`);
1262
+ const i = fe(s[0]);
1263
+ return o.replace(/#([0-9a-f]{6})/i, `rgb(${i} / ${r})`);
1410
1264
  }
1411
1265
  }
1412
1266
  return o;
1413
1267
  }
1414
- function W(e) {
1415
- const t = e.indexOf("-["), n = e.endsWith("]");
1416
- if (t > 0 && n) {
1417
- const r = e.slice(0, t);
1268
+ function U(e) {
1269
+ const t = e.indexOf("-["), r = e.endsWith("]");
1270
+ if (t > 0 && r) {
1271
+ const n = e.slice(0, t);
1418
1272
  let o = e.slice(t + 2, -1);
1419
1273
  o = o.replace(/_/g, " ");
1420
1274
  const i = {
@@ -1456,108 +1310,145 @@ function W(e) {
1456
1310
  weight: "font-weight",
1457
1311
  leading: "line-height",
1458
1312
  z: "z-index"
1459
- }[r] ?? r.replace(/_/g, "-");
1313
+ }[n] ?? n.replace(/_/g, "-");
1460
1314
  if (i && o) return `${i}:${o};`;
1461
1315
  }
1462
1316
  return null;
1463
1317
  }
1464
- function Ae(e) {
1318
+ function qe(e) {
1465
1319
  return e.replace(/([!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~])/g, "\\$1");
1466
1320
  }
1467
- function Ee(e) {
1468
- const t = /class\s*=\s*["']([^"']+)["']/g, n = [];
1469
- let r;
1470
- for (; r = t.exec(e); ) {
1321
+ function Ie(e) {
1322
+ const t = /class\s*=\s*["']([^"']+)["']/g, r = [];
1323
+ let n;
1324
+ for (; n = t.exec(e); ) {
1471
1325
  let o = "", s = !1;
1472
- for (const i of r[1])
1473
- i === "[" && (s = !0), i === "]" && (s = !1), i === " " && !s ? (o && n.push(o), o = "") : o += i;
1474
- o && n.push(o);
1326
+ for (const i of n[1])
1327
+ i === "[" && (s = !0), i === "]" && (s = !1), i === " " && !s ? (o && r.push(o), o = "") : o += i;
1328
+ o && r.push(o);
1475
1329
  }
1476
- return n.filter(Boolean);
1330
+ return r.filter(Boolean);
1477
1331
  }
1478
- const ne = /* @__PURE__ */ new Map(), Te = 16;
1479
- function je(e) {
1480
- const t = Date.now(), n = ne.get(e);
1481
- if (n && t - n.timestamp < Te) return n.css;
1482
- const r = Ee(e), o = new Set(r), s = [], i = [], l = [], c = [], d = {};
1483
- function p(h, S = !1) {
1484
- const y = (S ? "dark|" : "") + h;
1485
- if (y in d) return d[y];
1486
- const a = f(h, S);
1487
- return d[y] = a, a;
1488
- }
1489
- function u(h) {
1490
- const S = h.some((a) => V.includes(a)), y = h.includes("dark");
1491
- return h.length === 0 ? 1 : !S && !y ? 2 : S && !y ? 3 : 4;
1492
- }
1493
- function f(h, S = !1) {
1494
- const y = h.split(":"), a = y.find(
1495
- (_) => F[_] || U(_) || q(_) || W(_)
1332
+ const ue = /* @__PURE__ */ new Map(), Fe = 16;
1333
+ function Ke(e) {
1334
+ const t = Date.now(), r = ue.get(e);
1335
+ if (r && t - r.timestamp < Fe) return r.css;
1336
+ const n = Ie(e), o = new Set(n), s = [], i = [], a = [], c = [], f = {};
1337
+ function g(y, b = !1) {
1338
+ const h = (b ? "dark|" : "") + y;
1339
+ if (h in f) return f[h];
1340
+ const l = u(y, b);
1341
+ return f[h] = l, l;
1342
+ }
1343
+ function d(y) {
1344
+ const b = y.some((l) => Z.includes(l)), h = y.includes("dark");
1345
+ return y.length === 0 ? 1 : !b && !h ? 2 : b && !h ? 3 : 4;
1346
+ }
1347
+ function u(y, b = !1) {
1348
+ const h = y.split(":"), l = h.find(
1349
+ (C) => Q[C] || X(C) || Y(C) || U(C)
1496
1350
  );
1497
- if (!a) return null;
1498
- const b = F[a] ?? U(a) ?? q(a) ?? W(a);
1499
- if (!b) return null;
1500
- let g = `.${Ae(h)}`, x = b;
1501
- const w = y.indexOf(a);
1502
- let k = w >= 0 ? y.slice(0, w) : [];
1503
- S && (k = k.filter((_) => _ !== "dark"));
1504
- const $ = k.filter((_) => V.includes(_)), C = $.length ? $[$.length - 1] : null;
1505
- for (const _ of k) {
1506
- if (V.includes(_)) continue;
1507
- const A = $e[_];
1508
- typeof A == "function" && (g = A(g, x).replace(/\{.*$/, ""));
1351
+ if (!l) return null;
1352
+ const p = Q[l] ?? X(l) ?? Y(l) ?? U(l);
1353
+ if (!p) return null;
1354
+ let m = `.${qe(y)}`, x = p;
1355
+ const k = h.indexOf(l);
1356
+ let $ = k >= 0 ? h.slice(0, k) : [];
1357
+ b && ($ = $.filter((C) => C !== "dark"));
1358
+ const S = $.filter((C) => Z.includes(C)), _ = S.length ? S[S.length - 1] : null;
1359
+ for (const C of $) {
1360
+ if (Z.includes(C)) continue;
1361
+ const A = We[C];
1362
+ typeof A == "function" && (m = A(m, x).replace(/\{.*$/, ""));
1509
1363
  }
1510
- let v = `${g}{${x}}`;
1511
- return S && C ? v = `@media (prefers-color-scheme: dark) and ${te[C]}{${v}}` : S ? v = `@media (prefers-color-scheme: dark){${v}}` : C && (v = `@media ${te[C]}{${v}}`), v;
1364
+ let w = `${m}{${x}}`;
1365
+ return b && _ ? w = `@media (prefers-color-scheme: dark) and ${ce[_]}{${w}}` : b ? w = `@media (prefers-color-scheme: dark){${w}}` : _ && (w = `@media ${ce[_]}{${w}}`), w;
1512
1366
  }
1513
- for (const h of o) {
1514
- const S = h.split(":"), y = S.find(
1515
- (x) => F[x] || U(x) || q(x) || W(x)
1367
+ for (const y of o) {
1368
+ const b = y.split(":"), h = b.find(
1369
+ (x) => Q[x] || X(x) || Y(x) || U(x)
1516
1370
  );
1517
- if (!y) continue;
1518
- const a = S.indexOf(y), b = a >= 0 ? S.slice(0, a) : [], g = u(b);
1519
- if (g === 4) {
1520
- const x = p(h, !0);
1371
+ if (!h) continue;
1372
+ const l = b.indexOf(h), p = l >= 0 ? b.slice(0, l) : [], m = d(p);
1373
+ if (m === 4) {
1374
+ const x = g(y, !0);
1521
1375
  x && c.push(x);
1522
1376
  } else {
1523
- const x = p(h);
1524
- x && (g === 1 ? s.push(x) : g === 2 ? i.push(x) : g === 3 && l.push(x));
1377
+ const x = g(y);
1378
+ x && (m === 1 ? s.push(x) : m === 2 ? i.push(x) : m === 3 && a.push(x));
1525
1379
  }
1526
1380
  }
1527
- const m = [...s, ...i, ...l, ...c].join("");
1528
- return ne.set(e, { css: m, timestamp: t }), m;
1381
+ const v = [...s, ...i, ...a, ...c].join("");
1382
+ return ue.set(e, { css: v, timestamp: t }), v;
1529
1383
  }
1530
- const Le = /* @__PURE__ */ new Map();
1531
- function Q(e) {
1532
- return e.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
1384
+ function Ue(e, t, r, n, o, s, i, a) {
1385
+ if (!e) return;
1386
+ if (t.loadingTemplate && r.isLoading) {
1387
+ M(e, t.loadingTemplate(r), r, n, o);
1388
+ return;
1389
+ }
1390
+ if (t.errorTemplate && r.hasError) {
1391
+ r.error instanceof Error && M(e, t.errorTemplate(r.error, r), r, n, o);
1392
+ return;
1393
+ }
1394
+ const c = t.render(r);
1395
+ if (c instanceof Promise) {
1396
+ s(!0), c.then((f) => {
1397
+ s(!1), i(null), M(e, f, r, n, o), a(e.innerHTML);
1398
+ }).catch((f) => {
1399
+ s(!1), i(f), t.errorTemplate && M(e, t.errorTemplate(f, r), r, n, o);
1400
+ }), t.loadingTemplate && M(e, t.loadingTemplate(r), r, n, o);
1401
+ return;
1402
+ }
1403
+ M(e, c, r, n, o), a(e.innerHTML);
1533
1404
  }
1534
- function J(e) {
1535
- return typeof e == "string" ? e.replace(
1536
- /[&<>"']/g,
1537
- (t) => ({
1538
- "&": "&amp;",
1539
- "<": "&lt;",
1540
- ">": "&gt;",
1541
- '"': "&quot;",
1542
- "'": "&#39;"
1543
- })[t]
1544
- ) : e;
1405
+ function M(e, t, r, n, o) {
1406
+ e && (Re(
1407
+ e,
1408
+ Array.isArray(t) ? t : [t],
1409
+ r,
1410
+ n
1411
+ ), o(e.innerHTML));
1545
1412
  }
1546
- function He(e, ...t) {
1547
- let n = "";
1548
- for (let r = 0; r < e.length; r++)
1549
- n += e[r], r < t.length && (n += t[r]);
1550
- return n;
1413
+ function Ve(e, t, r, n, o, s, i) {
1414
+ if (s !== null && clearTimeout(s), Date.now() - t < 16) {
1415
+ if (o(r + 1), r > 10) {
1416
+ console.warn("Potential infinite render loop detected. Skipping render."), i(null);
1417
+ return;
1418
+ }
1419
+ } else
1420
+ o(0);
1421
+ const c = setTimeout(() => {
1422
+ n(Date.now()), e(), i(null);
1423
+ }, 0);
1424
+ i(c);
1551
1425
  }
1552
- function Ie(e, t, n) {
1553
- let r = Q(e);
1554
- r.includes("-") || (r = `cer-${r}`);
1426
+ function Je(e, t, r, n, o, s) {
1427
+ if (!e) return;
1428
+ const i = Ke(n);
1429
+ if (!t.style && (!i || i.trim() === "")) {
1430
+ s(null), e.adoptedStyleSheets = [ae()];
1431
+ return;
1432
+ }
1433
+ let a = "";
1434
+ t.style && (typeof t.style == "string" ? a = t.style : typeof t.style == "function" && (a = t.style(r)));
1435
+ let c = Ne(`${a}
1436
+ ${i}
1437
+ `);
1438
+ c = ye(c);
1439
+ let f = o;
1440
+ f || (f = new CSSStyleSheet()), (f.cssRules.length === 0 || f.toString() !== c) && f.replaceSync(c), e.adoptedStyleSheets = [ae(), f], s(f);
1441
+ }
1442
+ const Qe = /* @__PURE__ */ new Map();
1443
+ function de(e, t, r) {
1444
+ let n = ne(e);
1445
+ n.includes("-") || (n = `cer-${n}`);
1555
1446
  let o;
1556
- typeof t == "function" ? o = { ...n, render: t } : o = t, typeof o.onError != "function" && (o.onError = (s, i) => {
1557
- console.error(`[${r}] Error:`, s, i);
1558
- }), Le.set(r, o), typeof window < "u" && !customElements.get(r) && customElements.define(r, ze(o));
1447
+ typeof t == "function" ? o = { ...r, render: t } : o = t, typeof o.onError != "function" && (o.onError = (s, i) => {
1448
+ console.error(`[${n}] Error:`, s, i);
1449
+ }), Qe.set(n, o), typeof window < "u" && !customElements.get(n) && customElements.define(n, Ze(o));
1559
1450
  }
1560
- function ze(e) {
1451
+ function Ze(e) {
1561
1452
  if (!e.render)
1562
1453
  throw new Error(
1563
1454
  "Component must have a render function"
@@ -1577,6 +1468,24 @@ function ze(e) {
1577
1468
  _initializing = !0;
1578
1469
  _styleSheet = null;
1579
1470
  _lastHtmlStringForJitCSS = "";
1471
+ /**
1472
+ * Returns the last rendered HTML string for JIT CSS.
1473
+ */
1474
+ get lastHtmlStringForJitCSS() {
1475
+ return this._lastHtmlStringForJitCSS;
1476
+ }
1477
+ /**
1478
+ * Returns true if the component is currently loading.
1479
+ */
1480
+ get isLoading() {
1481
+ return this._templateLoading;
1482
+ }
1483
+ /**
1484
+ * Returns the last error thrown during rendering, or null if none.
1485
+ */
1486
+ get lastError() {
1487
+ return this._templateError;
1488
+ }
1580
1489
  _cfg;
1581
1490
  _lastRenderTime = 0;
1582
1491
  _renderCount = 0;
@@ -1590,30 +1499,35 @@ function ze(e) {
1590
1499
  writable: !1,
1591
1500
  enumerable: !1,
1592
1501
  configurable: !1
1502
+ }), Object.defineProperty(t, "requestRender", {
1503
+ value: () => this.requestRender(),
1504
+ writable: !1,
1505
+ enumerable: !1,
1506
+ configurable: !1
1593
1507
  }), this.context = t, this._applyProps(e), Object.defineProperty(this.context, "emit", {
1594
- value: (n, r, o) => {
1508
+ value: (r, n, o) => {
1595
1509
  this.dispatchEvent(
1596
- new CustomEvent(n, {
1597
- detail: r,
1510
+ new CustomEvent(r, {
1511
+ detail: n,
1598
1512
  bubbles: !0,
1599
1513
  composed: !0,
1600
1514
  ...o || {}
1601
1515
  })
1602
1516
  );
1603
- const s = `on${n.charAt(0).toUpperCase()}${n.slice(1)}`, i = typeof this[s] == "function" ? this[s] : void 0, l = typeof this.context[s] == "function" ? this.context[s] : void 0, c = typeof e[s] == "function" ? e[s] : void 0;
1604
- i && i(r, this.context), l && l !== i && l(r, this.context), c && c !== i && c !== l && c(r, this.context);
1517
+ const s = `on${r.charAt(0).toUpperCase()}${r.slice(1)}`, i = typeof this[s] == "function" ? this[s] : void 0, a = typeof this.context[s] == "function" ? this.context[s] : void 0, c = typeof e[s] == "function" ? e[s] : void 0;
1518
+ i && i(n, this.context), a && a !== i && a(n, this.context), c && c !== i && c !== a && c(n, this.context);
1605
1519
  },
1606
1520
  writable: !1,
1607
1521
  enumerable: !1,
1608
1522
  configurable: !1
1609
- }), Object.keys(e).forEach((n) => {
1610
- const r = e[n];
1611
- if (typeof r == "function" && !n.startsWith("on"))
1612
- this.context[n] = (...o) => r(...o, this.context);
1613
- else if (n.startsWith("on") && n.length > 2 && n[2] === n[2].toUpperCase()) {
1614
- const o = n.slice(2, 3).toLowerCase() + n.slice(3);
1523
+ }), Object.keys(e).forEach((r) => {
1524
+ const n = e[r];
1525
+ if (typeof n == "function" && !r.startsWith("on"))
1526
+ this.context[r] = (...o) => n(...o, this.context);
1527
+ else if (r.startsWith("on") && r.length > 2 && r[2] === r[2].toUpperCase()) {
1528
+ const o = r.slice(2, 3).toLowerCase() + r.slice(3);
1615
1529
  this.addEventListener(o, (s) => {
1616
- const i = typeof this[n] == "function" ? this[n] : this.context[n];
1530
+ const i = typeof this[r] == "function" ? this[r] : this.context[r];
1617
1531
  typeof i == "function" && i(s.detail, this.context);
1618
1532
  });
1619
1533
  }
@@ -1621,34 +1535,61 @@ function ze(e) {
1621
1535
  }
1622
1536
  connectedCallback() {
1623
1537
  this._runLogicWithinErrorBoundary(e, () => {
1624
- e.onConnected && !this._mounted && (e.onConnected(this.context), this._mounted = !0);
1538
+ Ce(
1539
+ e,
1540
+ this.context,
1541
+ this._mounted,
1542
+ (t) => {
1543
+ this._mounted = t;
1544
+ }
1545
+ );
1625
1546
  });
1626
1547
  }
1627
1548
  disconnectedCallback() {
1628
1549
  this._runLogicWithinErrorBoundary(e, () => {
1629
- e.onDisconnected && e.onDisconnected(this.context), this._listeners.forEach((t) => t()), this._listeners = [], this._watchers.clear(), this._templateLoading = !1, this._templateError = null, this._mounted = !1;
1550
+ Se(
1551
+ e,
1552
+ this.context,
1553
+ this._listeners,
1554
+ () => {
1555
+ this._listeners = [];
1556
+ },
1557
+ () => {
1558
+ this._watchers.clear();
1559
+ },
1560
+ (t) => {
1561
+ this._templateLoading = t;
1562
+ },
1563
+ (t) => {
1564
+ this._templateError = t;
1565
+ },
1566
+ (t) => {
1567
+ this._mounted = t;
1568
+ }
1569
+ );
1630
1570
  });
1631
1571
  }
1632
- attributeChangedCallback(t, n, r) {
1572
+ attributeChangedCallback(t, r, n) {
1633
1573
  this._runLogicWithinErrorBoundary(e, () => {
1634
- this._applyProps(e), e.onAttributeChanged && e.onAttributeChanged(
1574
+ this._applyProps(e), _e(
1575
+ e,
1635
1576
  t,
1636
- n,
1637
1577
  r,
1578
+ n,
1638
1579
  this.context
1639
1580
  );
1640
1581
  });
1641
1582
  }
1642
1583
  static get observedAttributes() {
1643
- return e.props ? Object.keys(e.props).map(Q) : [];
1584
+ return e.props ? Object.keys(e.props).map(ne) : [];
1644
1585
  }
1645
1586
  _applyComputed(t) {
1646
1587
  this._runLogicWithinErrorBoundary(e, () => {
1647
- t.computed && Object.entries(t.computed).forEach(([n, r]) => {
1648
- Object.defineProperty(this.context, n, {
1588
+ t.computed && Object.entries(t.computed).forEach(([r, n]) => {
1589
+ Object.defineProperty(this.context, r, {
1649
1590
  get: () => {
1650
- const o = r(this.context);
1651
- return J(o);
1591
+ const o = n(this.context);
1592
+ return ee(o);
1652
1593
  },
1653
1594
  enumerable: !0
1654
1595
  });
@@ -1658,90 +1599,69 @@ function ze(e) {
1658
1599
  // --- Render ---
1659
1600
  _render(t) {
1660
1601
  this._runLogicWithinErrorBoundary(t, () => {
1661
- if (!this.shadowRoot) return;
1662
- if (this._templateLoading && t.loadingTemplate) {
1663
- this._renderOutput(t.loadingTemplate(this.context));
1664
- return;
1665
- }
1666
- if (this._templateError && t.errorTemplate) {
1667
- this._renderOutput(t.errorTemplate(this._templateError, this.context));
1668
- return;
1669
- }
1670
- const n = t.render(this.context);
1671
- if (n instanceof Promise) {
1672
- this._templateLoading = !0, n.then((r) => (this._templateLoading = !1, this._templateError = null, this._renderOutput(r), r)).catch((r) => {
1673
- if (this._templateLoading = !1, this._templateError = r, t.errorTemplate) {
1674
- const o = t.errorTemplate(r, this.context);
1675
- return this._renderOutput(o), o;
1676
- }
1677
- throw r;
1678
- }), t.loadingTemplate && this._renderOutput(t.loadingTemplate(this.context));
1679
- return;
1680
- }
1681
- this._renderOutput(n), this._applyStyle(t);
1602
+ Ue(
1603
+ this.shadowRoot,
1604
+ t,
1605
+ this.context,
1606
+ this._refs,
1607
+ (r) => {
1608
+ this._lastHtmlStringForJitCSS = r, typeof this.onHtmlStringUpdate == "function" && this.onHtmlStringUpdate(r);
1609
+ },
1610
+ (r) => {
1611
+ this._templateLoading = r, typeof this.onLoadingStateChange == "function" && this.onLoadingStateChange(r);
1612
+ },
1613
+ (r) => {
1614
+ this._templateError = r, typeof this.onErrorStateChange == "function" && this.onErrorStateChange(r);
1615
+ },
1616
+ (r) => this._applyStyle(t, r)
1617
+ );
1682
1618
  });
1683
1619
  }
1684
- // --- Helper to render output ---
1685
- _renderOutput(t) {
1686
- if (!this.shadowRoot) return;
1687
- const n = new Proxy(this.context, {
1688
- get: (r, o) => o === "_requestRender" ? () => this._requestRender() : o === "context" ? r : typeof o == "string" && o.includes(".") ? o.split(".").reduce((s, i) => s?.[i], r) : r[o],
1689
- set: (r, o, s) => {
1690
- if (typeof o == "string" && o.includes(".")) {
1691
- const i = o.split("."), l = i.pop();
1692
- if (!l) return !1;
1693
- const c = i.reduce((d, p) => (p in d || (d[p] = {}), d[p]), r);
1694
- return c[l] = s, !0;
1695
- }
1696
- return r[o] = s, !0;
1697
- }
1698
- });
1699
- xe(
1700
- this.shadowRoot,
1701
- Array.isArray(t) ? t : [t],
1702
- n,
1703
- this._refs
1704
- ), this._lastHtmlStringForJitCSS = this.shadowRoot.innerHTML;
1620
+ requestRender() {
1621
+ this._requestRender();
1705
1622
  }
1706
1623
  _requestRender() {
1707
- if (this._renderTimeoutId !== null && clearTimeout(this._renderTimeoutId), Date.now() - this._lastRenderTime < 16) {
1708
- if (this._renderCount++, this._renderCount > 10) {
1709
- console.warn(
1710
- `[${this.tagName}] Potential infinite render loop detected. Skipping render.`
1711
- ), this._renderTimeoutId = null;
1712
- return;
1713
- }
1714
- } else
1715
- this._renderCount = 0;
1716
- this._renderTimeoutId = setTimeout(() => {
1717
- this._lastRenderTime = Date.now(), this._render(this._cfg), this._renderTimeoutId = null;
1718
- }, 0);
1624
+ this._runLogicWithinErrorBoundary(this._cfg, () => {
1625
+ Ve(
1626
+ () => this._render(this._cfg),
1627
+ this._lastRenderTime,
1628
+ this._renderCount,
1629
+ (t) => {
1630
+ this._lastRenderTime = t;
1631
+ },
1632
+ (t) => {
1633
+ this._renderCount = t;
1634
+ },
1635
+ this._renderTimeoutId,
1636
+ (t) => {
1637
+ this._renderTimeoutId = t;
1638
+ }
1639
+ );
1640
+ });
1719
1641
  }
1720
1642
  // --- Style ---
1721
- _applyStyle(t) {
1643
+ _applyStyle(t, r) {
1722
1644
  this._runLogicWithinErrorBoundary(t, () => {
1723
- if (!this.shadowRoot) return;
1724
- const n = je(this._lastHtmlStringForJitCSS);
1725
- if (!t.style && (!n || n.trim() === "")) {
1726
- this._styleSheet = null, this.shadowRoot.adoptedStyleSheets = [G()];
1727
- return;
1728
- }
1729
- let r = "";
1730
- t.style && (typeof t.style == "string" ? r = t.style : typeof t.style == "function" && (r = t.style(this.context)));
1731
- let o = ve(`${r}
1732
- ${n}
1733
- `);
1734
- o = oe(o), this._styleSheet || (this._styleSheet = new CSSStyleSheet()), (this._styleSheet.cssRules.length === 0 || this._styleSheet.toString() !== o) && this._styleSheet.replaceSync(o), this.shadowRoot.adoptedStyleSheets = [G(), this._styleSheet];
1645
+ Je(
1646
+ this.shadowRoot,
1647
+ t,
1648
+ this.context,
1649
+ r,
1650
+ this._styleSheet,
1651
+ (n) => {
1652
+ this._styleSheet = n;
1653
+ }
1654
+ );
1735
1655
  });
1736
1656
  }
1737
1657
  // --- Error Boundary function ---
1738
- _runLogicWithinErrorBoundary(t, n) {
1658
+ _runLogicWithinErrorBoundary(t, r) {
1739
1659
  this._hasError && (this._hasError = !1);
1740
1660
  try {
1741
- n();
1742
- } catch (r) {
1743
- this._hasError = !0, t.onError && t.onError(r, this.context), t.errorFallback && this.shadowRoot && (this.shadowRoot.innerHTML = t.errorFallback(
1744
- r,
1661
+ r();
1662
+ } catch (n) {
1663
+ this._hasError = !0, t.onError && t.onError(n, this.context), t.errorFallback && this.shadowRoot && (this.shadowRoot.innerHTML = t.errorFallback(
1664
+ n,
1745
1665
  this.context
1746
1666
  ));
1747
1667
  }
@@ -1749,11 +1669,11 @@ ${n}
1749
1669
  // --- State, props, computed ---
1750
1670
  _initContext(t) {
1751
1671
  try {
1752
- let n = function(o, s = "") {
1672
+ let r = function(o, s = "") {
1753
1673
  return Array.isArray(o) ? new Proxy(o, {
1754
- get(i, l, c) {
1755
- const d = Reflect.get(i, l, c);
1756
- return typeof d == "function" && typeof l == "string" && [
1674
+ get(i, a, c) {
1675
+ const f = Reflect.get(i, a, c);
1676
+ return typeof f == "function" && typeof a == "string" && [
1757
1677
  "push",
1758
1678
  "pop",
1759
1679
  "shift",
@@ -1761,132 +1681,522 @@ ${n}
1761
1681
  "splice",
1762
1682
  "sort",
1763
1683
  "reverse"
1764
- ].includes(l) ? function(...u) {
1765
- const f = d.apply(i, u);
1766
- if (!r._initializing) {
1767
- const m = s || "root";
1768
- r._triggerWatchers(m, i), r._render(t);
1684
+ ].includes(a) ? function(...d) {
1685
+ const u = f.apply(i, d);
1686
+ if (!n._initializing) {
1687
+ const v = s || "root";
1688
+ n._triggerWatchers(v, i), n._render(t);
1769
1689
  }
1770
- return f;
1771
- } : d;
1690
+ return u;
1691
+ } : f;
1772
1692
  },
1773
- set(i, l, c) {
1774
- if (i[l] = c, !r._initializing) {
1775
- const d = s ? `${s}.${String(l)}` : String(l);
1776
- r._triggerWatchers(d, c), r._render(t);
1693
+ set(i, a, c) {
1694
+ if (i[a] = c, !n._initializing) {
1695
+ const f = s ? `${s}.${String(a)}` : String(a);
1696
+ n._triggerWatchers(f, c), n._render(t);
1777
1697
  }
1778
1698
  return !0;
1779
1699
  },
1780
- deleteProperty(i, l) {
1781
- if (delete i[l], !r._initializing) {
1782
- const c = s ? `${s}.${String(l)}` : String(l);
1783
- r._triggerWatchers(c, void 0), r._render(t);
1700
+ deleteProperty(i, a) {
1701
+ if (delete i[a], !n._initializing) {
1702
+ const c = s ? `${s}.${String(a)}` : String(a);
1703
+ n._triggerWatchers(c, void 0), n._render(t);
1784
1704
  }
1785
1705
  return !0;
1786
1706
  }
1787
1707
  }) : o && typeof o == "object" ? (Object.keys(o).forEach((i) => {
1788
- const l = s ? `${s}.${i}` : i;
1789
- o[i] = n(o[i], l);
1708
+ const a = s ? `${s}.${i}` : i;
1709
+ o[i] = r(o[i], a);
1790
1710
  }), new Proxy(o, {
1791
- set(i, l, c) {
1792
- const d = s ? `${s}.${String(l)}` : String(l);
1793
- return i[l] = n(c, d), r._initializing || (r._triggerWatchers(
1794
- d,
1795
- i[l]
1796
- ), r._render(t)), !0;
1711
+ set(i, a, c) {
1712
+ const f = s ? `${s}.${String(a)}` : String(a);
1713
+ return i[a] = r(c, f), n._initializing || (n._triggerWatchers(
1714
+ f,
1715
+ i[a]
1716
+ ), n._render(t)), !0;
1797
1717
  },
1798
- get(i, l, c) {
1799
- return Reflect.get(i, l, c);
1718
+ get(i, a, c) {
1719
+ return Reflect.get(i, a, c);
1800
1720
  }
1801
1721
  })) : o;
1802
1722
  };
1803
- const r = this;
1804
- return n({ ...t.state });
1723
+ const n = this;
1724
+ return r({ ...t.state });
1805
1725
  } catch {
1806
1726
  return {};
1807
1727
  }
1808
1728
  }
1809
1729
  _initWatchers(t) {
1810
- if (t.watch)
1811
- for (const [n, r] of Object.entries(t.watch)) {
1812
- let o, s = {};
1813
- if (Array.isArray(r) ? (o = r[0], s = r[1] || {}) : o = r, this._watchers.set(n, {
1814
- callback: o,
1815
- options: s,
1816
- oldValue: this._getNestedValue(n)
1817
- }), s.immediate)
1818
- try {
1819
- const i = this._getNestedValue(n);
1820
- o(i, void 0, this.context);
1821
- } catch (i) {
1822
- console.error(`Error in immediate watcher for "${n}":`, i);
1823
- }
1824
- }
1730
+ this._runLogicWithinErrorBoundary(t, () => {
1731
+ we(
1732
+ this.context,
1733
+ this._watchers,
1734
+ t.watch || {}
1735
+ );
1736
+ });
1825
1737
  }
1826
- _getNestedValue(t) {
1827
- return t.split(".").reduce(
1828
- (n, r) => n?.[r],
1829
- this.context
1830
- );
1738
+ _triggerWatchers(t, r) {
1739
+ ke(this.context, this._watchers, t, r);
1831
1740
  }
1832
- _triggerWatchers(t, n) {
1833
- const r = (s, i) => {
1834
- if (s === i) return !0;
1835
- if (typeof s != typeof i || typeof s != "object" || s === null || i === null) return !1;
1836
- if (Array.isArray(s) && Array.isArray(i))
1837
- return s.length !== i.length ? !1 : s.every((d, p) => r(d, i[p]));
1838
- const l = Object.keys(s), c = Object.keys(i);
1839
- return l.length !== c.length ? !1 : l.every((d) => r(s[d], i[d]));
1840
- }, o = this._watchers.get(t);
1841
- if (o && !r(n, o.oldValue))
1741
+ _applyProps(t) {
1742
+ this._runLogicWithinErrorBoundary(t, () => {
1842
1743
  try {
1843
- o.callback(n, o.oldValue, this.context), o.oldValue = n;
1844
- } catch (s) {
1845
- console.error(`Error in watcher for "${t}":`, s);
1744
+ $e(this, t, this.context);
1745
+ } catch (r) {
1746
+ this._hasError = !0, t.onError && t.onError(r, this.context), t.errorFallback && this.shadowRoot && (this.shadowRoot.innerHTML = t.errorFallback(r, this.context));
1846
1747
  }
1847
- for (const [s, i] of this._watchers.entries())
1848
- if (i.options.deep && t.startsWith(s + "."))
1849
- try {
1850
- const l = this._getNestedValue(s);
1851
- r(l, i.oldValue) || (i.callback(l, i.oldValue, this.context), i.oldValue = l);
1852
- } catch (l) {
1853
- console.error(`Error in deep watcher for "${s}":`, l);
1748
+ });
1749
+ }
1750
+ };
1751
+ }
1752
+ function F(e, t = {}, r, n) {
1753
+ const o = n ?? t.key;
1754
+ return { tag: e, key: o, props: t, children: r };
1755
+ }
1756
+ function V(e) {
1757
+ return !!e && typeof e == "object" && (e.type === "AnchorBlock" || e.tag === "#anchor");
1758
+ }
1759
+ function P(e) {
1760
+ return typeof e == "object" && e !== null && "tag" in e && !V(e);
1761
+ }
1762
+ function Xe(e, t) {
1763
+ return e.key != null ? e : { ...e, key: t };
1764
+ }
1765
+ function Ye(e, t = [], r = {}) {
1766
+ const n = {}, o = {}, s = {}, i = /([:@#]?)([a-zA-Z0-9-:\.]+)=("([^"\\]*(\\.[^"\\]*)*)"|'([^'\\]*(\\.[^'\\]*)*)')/g;
1767
+ let a;
1768
+ for (; a = i.exec(e); ) {
1769
+ const c = a[1], f = a[2], g = (a[4] || a[6]) ?? "", d = g.match(/^{{(\d+)}}$/);
1770
+ let u = d ? t[Number(d[1])] ?? null : g;
1771
+ if (d || (u === "true" ? u = !0 : u === "false" ? u = !1 : u === "null" ? u = null : isNaN(Number(u)) || (u = Number(u))), c === ":")
1772
+ typeof u == "boolean" ? o[f] = u : u != null && (n[f] = u);
1773
+ else if (c === "@") {
1774
+ const v = "on" + f.charAt(0).toUpperCase() + f.slice(1);
1775
+ n[v] = typeof u == "function" ? u : typeof r[u] == "function" ? r[u] : void 0;
1776
+ } else if (c === "#") {
1777
+ const [v, ...y] = f.split("."), b = [...y];
1778
+ let h = u, l = [...b];
1779
+ if (v === "model" && typeof h == "string" && h.includes(".")) {
1780
+ const p = ["trim", "number", "lazy"], m = h.split(".");
1781
+ let x = h;
1782
+ const k = [];
1783
+ for (let $ = m.length - 1; $ > 0 && p.includes(m[$]); $--)
1784
+ k.unshift(m[$]), x = m.slice(0, $).join(".");
1785
+ h = x, l.push(...k);
1786
+ }
1787
+ s[v] = {
1788
+ value: h,
1789
+ modifiers: l
1790
+ };
1791
+ } else f === "ref" ? n.ref = u : o[f] = u;
1792
+ }
1793
+ return { props: n, attrs: o, directives: s };
1794
+ }
1795
+ function Ge(e, t, r) {
1796
+ function n(l, p) {
1797
+ return F("#text", {}, l, p);
1798
+ }
1799
+ let o = "";
1800
+ for (let l = 0; l < e.length; l++)
1801
+ o += e[l], l < t.length && (o += `{{${l}}}`);
1802
+ const s = /<\/?([a-zA-Z0-9-]+)([^>]*)\/?>|{{(\d+)}}|([^<]+)/g, i = [];
1803
+ let a = null, c, f = [], g = null, d = {}, u, v = 0, y = [];
1804
+ function b(l) {
1805
+ !l || typeof l != "object" || V(l) || (l.props || l.attrs ? (l.props && (d.props || (d.props = {}), Object.assign(d.props, l.props)), l.attrs && (d.attrs || (d.attrs = {}), Object.keys(l.attrs).forEach((p) => {
1806
+ if (p === "style" && d.attrs.style) {
1807
+ const m = d.attrs.style.replace(
1808
+ /;?\s*$/,
1809
+ ""
1810
+ ), x = l.attrs.style.replace(/^;?\s*/, "");
1811
+ d.attrs.style = m + "; " + x;
1812
+ } else if (p === "class" && d.attrs.class) {
1813
+ const m = d.attrs.class.trim().split(/\s+/).filter(Boolean), x = l.attrs.class.trim().split(/\s+/).filter(Boolean), k = [
1814
+ .../* @__PURE__ */ new Set([...m, ...x])
1815
+ ];
1816
+ d.attrs.class = k.join(" ");
1817
+ } else
1818
+ d.attrs[p] = l.attrs[p];
1819
+ }))) : (d.props || (d.props = {}), Object.assign(d.props, l)));
1820
+ }
1821
+ function h(l, p) {
1822
+ const m = g ? f : y;
1823
+ if (V(l)) {
1824
+ const x = l.key ?? p;
1825
+ let k = l.children;
1826
+ m.push({
1827
+ ...l,
1828
+ key: x,
1829
+ children: k
1830
+ });
1831
+ return;
1832
+ }
1833
+ if (P(l)) {
1834
+ m.push(Xe(l, void 0));
1835
+ return;
1836
+ }
1837
+ if (Array.isArray(l)) {
1838
+ if (l.length === 0) return;
1839
+ for (let x = 0; x < l.length; x++) {
1840
+ const k = l[x];
1841
+ V(k) || P(k) || Array.isArray(k) ? h(k, `${p}-${x}`) : k !== null && typeof k == "object" ? b(k) : m.push(n(String(k), `${p}-${x}`));
1842
+ }
1843
+ return;
1844
+ }
1845
+ if (l !== null && typeof l == "object") {
1846
+ b(l);
1847
+ return;
1848
+ }
1849
+ m.push(n(String(l), p));
1850
+ }
1851
+ for (; c = s.exec(o); )
1852
+ if (c[1]) {
1853
+ const l = c[1], p = c[0][1] === "/", m = c[0][c[0].length - 2] === "/", {
1854
+ props: x,
1855
+ attrs: k,
1856
+ directives: $
1857
+ } = Ye(c[2] || "", t, r), S = { props: {}, attrs: {} };
1858
+ for (const w in x) S.props[w] = x[w];
1859
+ for (const w in k) S.attrs[w] = k[w];
1860
+ for (const [w, C] of Object.entries($))
1861
+ if (w === "bind")
1862
+ if (typeof C.value == "object" && C.value !== null)
1863
+ for (const [A, E] of Object.entries(C.value))
1864
+ typeof E == "boolean" ? S.attrs[A] = E : E != null && (S.attrs[A] = String(E));
1865
+ else C.value != null && (S.attrs[w] = String(C.value));
1866
+ else if (w === "show") {
1867
+ const A = !!C.value;
1868
+ S.attrs.style = (S.attrs.style || "") + (A ? "" : "; display: none !important");
1869
+ } else if (w === "class") {
1870
+ const A = C.value;
1871
+ let E = [];
1872
+ if (typeof A == "string")
1873
+ E = A.split(/\s+/).filter(Boolean);
1874
+ else if (Array.isArray(A)) {
1875
+ for (const j of A)
1876
+ if (typeof j == "string")
1877
+ E.push(...j.split(/\s+/).filter(Boolean));
1878
+ else if (j && typeof j == "object")
1879
+ for (const [L, q] of Object.entries(j))
1880
+ q && E.push(...L.split(/\s+/).filter(Boolean));
1881
+ } else if (A && typeof A == "object")
1882
+ for (const [j, L] of Object.entries(A))
1883
+ L && E.push(...j.split(/\s+/).filter(Boolean));
1884
+ const W = S.attrs.class || "", D = [
1885
+ .../* @__PURE__ */ new Set([
1886
+ ...W.split(/\s+/).filter(Boolean),
1887
+ ...E
1888
+ ])
1889
+ ];
1890
+ S.attrs.class = D.join(" ");
1891
+ } else if (w === "style") {
1892
+ const A = C.value;
1893
+ let E = "";
1894
+ if (typeof A == "string")
1895
+ E = A;
1896
+ else if (A && typeof A == "object") {
1897
+ const D = [];
1898
+ for (const [j, L] of Object.entries(A))
1899
+ if (L != null && L !== "") {
1900
+ const q = j.replace(
1901
+ /[A-Z]/g,
1902
+ (be) => `-${be.toLowerCase()}`
1903
+ ), me = [
1904
+ "width",
1905
+ "height",
1906
+ "top",
1907
+ "right",
1908
+ "bottom",
1909
+ "left",
1910
+ "margin",
1911
+ "margin-top",
1912
+ "margin-right",
1913
+ "margin-bottom",
1914
+ "margin-left",
1915
+ "padding",
1916
+ "padding-top",
1917
+ "padding-right",
1918
+ "padding-bottom",
1919
+ "padding-left",
1920
+ "font-size",
1921
+ "line-height",
1922
+ "border-width",
1923
+ "border-radius",
1924
+ "min-width",
1925
+ "max-width",
1926
+ "min-height",
1927
+ "max-height"
1928
+ ];
1929
+ let oe = String(L);
1930
+ typeof L == "number" && me.includes(q) && (oe = `${L}px`), D.push(`${q}: ${oe}`);
1931
+ }
1932
+ E = D.join("; ") + (D.length > 0 ? ";" : "");
1854
1933
  }
1934
+ const W = S.attrs.style || "";
1935
+ S.attrs.style = W + (W && !W.endsWith(";") ? "; " : "") + E;
1936
+ }
1937
+ const _ = {};
1938
+ for (const [w, C] of Object.entries($))
1939
+ ["bind", "show", "class", "style"].includes(w) || (_[w] = C);
1940
+ if (Object.keys(_).length > 0 && (S.directives = _), p) {
1941
+ const w = F(
1942
+ g,
1943
+ d,
1944
+ f.length === 1 && P(f[0]) && f[0].tag === "#text" ? typeof f[0].children == "string" ? f[0].children : "" : f.length ? f : void 0,
1945
+ u
1946
+ ), C = i.pop();
1947
+ C ? (g = C.tag, d = C.props, u = C.key, f = C.children, f.push(w)) : a = w;
1948
+ } else m ? (g ? f : y).push(F(l, S, void 0, void 0)) : (g && i.push({
1949
+ tag: g,
1950
+ props: d,
1951
+ children: f,
1952
+ key: u
1953
+ }), g = l, d = S, f = []);
1954
+ } else if (typeof c[3] < "u") {
1955
+ const l = Number(c[3]), p = t[l], m = `interp-${l}`;
1956
+ h(p, m);
1957
+ } else if (c[4]) {
1958
+ const l = c[4], p = g ? f : y, m = l.split(/({{\d+}})/);
1959
+ for (const x of m) {
1960
+ if (!x) continue;
1961
+ const k = x.match(/^{{(\d+)}}$/);
1962
+ if (k) {
1963
+ const $ = Number(k[1]), S = t[$], _ = `interp-${$}`;
1964
+ h(S, _);
1965
+ } else {
1966
+ const $ = `text-${v++}`;
1967
+ p.push(n(x, $));
1968
+ }
1969
+ }
1855
1970
  }
1856
- _applyProps(t) {
1971
+ if (a)
1972
+ return P(a) && Array.isArray(a.children) && (a.children = a.children.filter(
1973
+ (l) => P(l) ? l.tag !== "#text" || typeof l.children == "string" && l.children.trim() !== "" : !0
1974
+ // keep non-element VNodes (including anchors) as-is
1975
+ )), a;
1976
+ if (y.length > 0) {
1977
+ const l = y.filter(
1978
+ (p) => P(p) ? p.tag !== "#text" || typeof p.children == "string" && p.children.trim() !== "" : !0
1979
+ );
1980
+ return l.length === 1 ? l[0] : l;
1981
+ }
1982
+ return F("div", {}, "", "fallback-root");
1983
+ }
1984
+ function z(e, ...t) {
1985
+ const r = t[t.length - 1], n = typeof r == "object" && r && !Array.isArray(r) ? r : void 0;
1986
+ return Ge(e, t, n);
1987
+ }
1988
+ const pe = (e) => e ? typeof URLSearchParams > "u" ? {} : Object.fromEntries(new URLSearchParams(e)) : {}, B = (e, t) => {
1989
+ for (const r of e) {
1990
+ const n = [], o = r.path.replace(/:[^/]+/g, (a) => (n.push(a.slice(1)), "([^/]+)")), s = new RegExp(`^${o}$`), i = t.match(s);
1991
+ if (i) {
1992
+ const a = {};
1993
+ return n.forEach((c, f) => {
1994
+ a[c] = i[f + 1];
1995
+ }), { route: r, params: a };
1996
+ }
1997
+ }
1998
+ return { route: null, params: {} };
1999
+ }, G = {};
2000
+ async function et(e) {
2001
+ if (e.component) return e.component;
2002
+ if (e.load) {
2003
+ if (G[e.path]) return G[e.path];
2004
+ try {
2005
+ const t = await e.load();
2006
+ return G[e.path] = t.default, t.default;
2007
+ } catch {
2008
+ throw new Error(`Failed to load component for route: ${e.path}`);
2009
+ }
2010
+ }
2011
+ throw new Error(`No component or loader defined for route: ${e.path}`);
2012
+ }
2013
+ function tt(e) {
2014
+ const { routes: t, base: r = "", initialUrl: n } = e;
2015
+ let o, s, i, a, c, f, g;
2016
+ const d = async (b, h) => {
2017
+ const l = t.find((p) => B([p], b.path).route !== null);
2018
+ if (l?.beforeEnter)
1857
2019
  try {
1858
- let n = function(r, o) {
1859
- return o === Boolean ? r === "true" : o === Number ? Number(r) : r;
1860
- };
1861
- if (!t.props) return;
1862
- Object.entries(t.props).forEach(([r, o]) => {
1863
- if (o.type === Function && typeof this[r] == "function")
1864
- this.context[r] = this[r];
1865
- else {
1866
- const s = this.getAttribute(Q(r));
1867
- s !== null ? this.context[r] = J(
1868
- n(s, o.type)
1869
- ) : "default" in o && o.default !== void 0 && (this.context[r] = J(o.default));
1870
- }
1871
- });
1872
- } catch (n) {
1873
- this._hasError = !0, t.onError && t.onError(n, this.context), t.errorFallback && this.shadowRoot && (this.shadowRoot.innerHTML = t.errorFallback(
1874
- n,
1875
- this.context
1876
- ));
2020
+ const p = await l.beforeEnter(b, h);
2021
+ return typeof p == "string" ? (await y(p, !0), !1) : p !== !1;
2022
+ } catch (p) {
2023
+ return console.error("beforeEnter error", p), !1;
2024
+ }
2025
+ return !0;
2026
+ }, u = async (b, h) => {
2027
+ const l = t.find((p) => B([p], b.path).route !== null);
2028
+ if (l?.onEnter)
2029
+ try {
2030
+ const p = await l.onEnter(b, h);
2031
+ return typeof p == "string" ? (await y(p, !0), !1) : p !== !1;
2032
+ } catch (p) {
2033
+ return console.error("onEnter error", p), !1;
2034
+ }
2035
+ return !0;
2036
+ }, v = (b, h) => {
2037
+ const l = t.find((p) => B([p], b.path).route !== null);
2038
+ if (l?.afterEnter)
2039
+ try {
2040
+ l.afterEnter(b, h);
2041
+ } catch (p) {
2042
+ console.error("afterEnter error", p);
1877
2043
  }
2044
+ }, y = async (b, h = !1) => {
2045
+ try {
2046
+ const l = {
2047
+ path: b.replace(r, "") || "/",
2048
+ query: {}
2049
+ }, p = B(t, l.path);
2050
+ if (!p) throw new Error(`No route found for ${l.path}`);
2051
+ const m = i.getState(), x = {
2052
+ path: l.path,
2053
+ params: p.params,
2054
+ query: l.query
2055
+ };
2056
+ if (!await d(x, m) || !await u(x, m)) return;
2057
+ typeof window < "u" && typeof document < "u" && (h ? window.history.replaceState({}, "", r + b) : window.history.pushState({}, "", r + b)), i.setState(x), v(x, m);
2058
+ } catch (l) {
2059
+ console.error("Navigation error:", l);
1878
2060
  }
1879
2061
  };
2062
+ if (typeof window < "u" && typeof document < "u") {
2063
+ o = () => {
2064
+ const h = new URL(window.location.href), l = h.pathname.replace(r, "") || "/", p = pe(h.search);
2065
+ return { path: l, query: p };
2066
+ }, s = o();
2067
+ const b = B(t, s.path);
2068
+ i = ie({
2069
+ path: s.path,
2070
+ params: b.params,
2071
+ query: s.query
2072
+ }), a = async (h = !1) => {
2073
+ const l = o();
2074
+ await y(l.path, h);
2075
+ }, window.addEventListener("popstate", () => a(!0)), c = (h) => y(h, !1), f = (h) => y(h, !0), g = () => window.history.back();
2076
+ } else {
2077
+ o = () => {
2078
+ const h = new URL(n || "/", "http://localhost"), l = h.pathname.replace(r, "") || "/", p = pe(h.search);
2079
+ return { path: l, query: p };
2080
+ }, s = o();
2081
+ const b = B(t, s.path);
2082
+ i = ie({
2083
+ path: s.path,
2084
+ params: b.params,
2085
+ query: s.query
2086
+ }), a = async () => {
2087
+ }, c = async () => {
2088
+ }, f = async () => {
2089
+ }, g = () => {
2090
+ };
2091
+ }
2092
+ return {
2093
+ store: i,
2094
+ push: c,
2095
+ replace: f,
2096
+ back: g,
2097
+ subscribe: i.subscribe,
2098
+ matchRoute: (b) => B(t, b),
2099
+ getCurrent: () => i.getState(),
2100
+ resolveRouteComponent: et
2101
+ };
2102
+ }
2103
+ function ct(e, t) {
2104
+ return B(e, t);
2105
+ }
2106
+ function ft(e) {
2107
+ const t = tt(e);
2108
+ return de("router-view", {
2109
+ async render() {
2110
+ if (!t) return z`<div>Router not initialized.</div>`;
2111
+ const r = t.getCurrent(), { path: n } = r, o = t.matchRoute(n);
2112
+ if (!o.route) return z`<div>Not found</div>`;
2113
+ let s = o.route.component;
2114
+ if (o.route.load) {
2115
+ const i = await o.route.load();
2116
+ typeof i.default == "string" && (s = i.default);
2117
+ }
2118
+ return typeof s == "string" ? z`<${s}></${s}>` : z`<div>Invalid route component</div>`;
2119
+ },
2120
+ onConnected(r) {
2121
+ t && typeof t.subscribe == "function" && t.subscribe(() => {
2122
+ typeof r.requestRender == "function" && r.requestRender();
2123
+ });
2124
+ }
2125
+ }), de("router-link", {
2126
+ state: {},
2127
+ props: {
2128
+ to: { type: String, default: "" },
2129
+ tag: { type: String, default: "a" },
2130
+ replace: { type: Boolean, default: !1 },
2131
+ exact: { type: Boolean, default: !1 },
2132
+ activeClass: { type: String, default: "active" },
2133
+ exactActiveClass: { type: String, default: "exact-active" },
2134
+ ariaCurrentValue: { type: String, default: "page" },
2135
+ disabled: { type: Boolean, default: !1 },
2136
+ external: { type: Boolean, default: !1 },
2137
+ style: { type: String, default: ge`
2138
+ [aria-disabled="true"] {
2139
+ pointer-events: none;
2140
+ opacity: 0.5;
2141
+ }
2142
+ ` }
2143
+ },
2144
+ style: (r) => r.props.style,
2145
+ render: (r) => {
2146
+ const n = t.getCurrent(), o = r.props.to, s = r.props.exact, i = r.props.exactActiveClass, a = r.props.activeClass, c = r.props.ariaCurrentValue, f = r.props.tag, g = r.props.disabled, d = r.props.external, u = n.path === o, v = s ? u : n && typeof n.path == "string" ? n.path.startsWith(o) : !1, y = u ? i : v ? a : "", b = u ? `aria-current="${c}"` : "", h = f === "button", l = g ? h ? 'disabled aria-disabled="true" tabindex="-1"' : 'aria-disabled="true" tabindex="-1"' : "", p = d && (f === "a" || !f) ? 'target="_blank" rel="noopener noreferrer"' : "";
2147
+ return z`
2148
+ ${ve().when(h, z`
2149
+ <button
2150
+ part="button"
2151
+ class="${y}"
2152
+ ${b}
2153
+ ${l}
2154
+ ${p}
2155
+ data-on-click="navigate"
2156
+ ><slot></slot></button>
2157
+ `).otherwise(z`
2158
+ <a
2159
+ part="link"
2160
+ href="${o}"
2161
+ class="${y}"
2162
+ ${b}
2163
+ ${l}
2164
+ ${p}
2165
+ data-on-click="navigate"
2166
+ ><slot></slot></a>
2167
+ `).done()}
2168
+ `;
2169
+ },
2170
+ navigate: (r, n) => {
2171
+ const { disabled: o, external: s, tag: i, replace: a, to: c } = n.props;
2172
+ if (o) {
2173
+ r.preventDefault();
2174
+ return;
2175
+ }
2176
+ s && (i === "a" || !i) || (r.preventDefault(), a ? t.replace(c) : t.push(c));
2177
+ }
2178
+ }), t;
1880
2179
  }
1881
2180
  export {
1882
- Ie as component,
1883
- ze as createElementClass,
1884
- Re as createStore,
1885
- He as css,
1886
- Ne as each,
1887
- Be as eventBus,
1888
- Oe as html,
1889
- Pe as match,
1890
- Me as when
2181
+ O as GlobalEventBus,
2182
+ de as component,
2183
+ ie as createStore,
2184
+ ge as css,
2185
+ nt as each,
2186
+ ot as emit,
2187
+ H as eventBus,
2188
+ z as html,
2189
+ ft as initRouter,
2190
+ lt as listen,
2191
+ ve as match,
2192
+ B as matchRoute,
2193
+ ct as matchRouteSSR,
2194
+ st as off,
2195
+ it as on,
2196
+ at as once,
2197
+ pe as parseQuery,
2198
+ et as resolveRouteComponent,
2199
+ tt as useRouter,
2200
+ rt as when
1891
2201
  };
1892
2202
  //# sourceMappingURL=custom-elements-runtime.es.js.map