@jasonshimmy/custom-elements-runtime 0.0.1-beta.2 → 0.0.1-beta.3

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.
@@ -3,7 +3,7 @@ class Q {
3
3
  listeners = [];
4
4
  constructor(t) {
5
5
  this.state = new Proxy(t, {
6
- set: (e, n, a) => (e[n] = a, this.notify(), !0)
6
+ set: (n, r, i) => (n[r] = i, this.notify(), !0)
7
7
  });
8
8
  }
9
9
  subscribe(t) {
@@ -32,26 +32,26 @@ class y extends EventTarget {
32
32
  * @param eventName - Name of the event
33
33
  * @param data - Optional event payload
34
34
  */
35
- emit(t, e) {
36
- const n = Date.now(), a = this.eventCounters.get(t);
37
- if (!a || n - a.window > 1e3)
38
- this.eventCounters.set(t, { count: 1, window: n });
39
- else if (a.count++, a.count > 50 && (console.error(`Event storm detected for "${t}": ${a.count} events in 1 second. Throttling...`), a.count > 100)) {
35
+ emit(t, n) {
36
+ const r = Date.now(), i = this.eventCounters.get(t);
37
+ if (!i || r - i.window > 1e3)
38
+ this.eventCounters.set(t, { count: 1, window: r });
39
+ else if (i.count++, i.count > 50 && (console.error(`Event storm detected for "${t}": ${i.count} events in 1 second. Throttling...`), i.count > 100)) {
40
40
  console.warn(`Blocking further "${t}" events to prevent infinite loop`);
41
41
  return;
42
42
  }
43
43
  this.dispatchEvent(new CustomEvent(t, {
44
- detail: e,
44
+ detail: n,
45
45
  bubbles: !1,
46
46
  // Global events don't need to bubble
47
47
  cancelable: !0
48
48
  }));
49
- const o = this.handlers[t];
50
- o && o.forEach((s) => {
49
+ const s = this.handlers[t];
50
+ s && s.forEach((o) => {
51
51
  try {
52
- s(e);
53
- } catch (i) {
54
- console.error(`Error in global event handler for "${t}":`, i);
52
+ o(n);
53
+ } catch (a) {
54
+ console.error(`Error in global event handler for "${t}":`, a);
55
55
  }
56
56
  });
57
57
  }
@@ -60,17 +60,17 @@ class y extends EventTarget {
60
60
  * @param eventName - Name of the event
61
61
  * @param handler - Handler function
62
62
  */
63
- on(t, e) {
64
- return this.handlers[t] || (this.handlers[t] = /* @__PURE__ */ new Set()), this.handlers[t].add(e), () => this.off(t, e);
63
+ on(t, n) {
64
+ return this.handlers[t] || (this.handlers[t] = /* @__PURE__ */ new Set()), this.handlers[t].add(n), () => this.off(t, n);
65
65
  }
66
66
  /**
67
67
  * Remove a specific handler for a global event.
68
68
  * @param eventName - Name of the event
69
69
  * @param handler - Handler function to remove
70
70
  */
71
- off(t, e) {
72
- const n = this.handlers[t];
73
- n && n.delete(e);
71
+ off(t, n) {
72
+ const r = this.handlers[t];
73
+ r && r.delete(n);
74
74
  }
75
75
  /**
76
76
  * Remove all handlers for a specific event.
@@ -85,18 +85,18 @@ class y extends EventTarget {
85
85
  * @param handler - CustomEvent handler
86
86
  * @param options - AddEventListener options
87
87
  */
88
- listen(t, e, n) {
89
- return this.addEventListener(t, e, n), () => this.removeEventListener(t, e);
88
+ listen(t, n, r) {
89
+ return this.addEventListener(t, n, r), () => this.removeEventListener(t, n);
90
90
  }
91
91
  /**
92
92
  * Register a one-time event handler. Returns a promise that resolves with the event data.
93
93
  * @param eventName - Name of the event
94
94
  * @param handler - Handler function
95
95
  */
96
- once(t, e) {
97
- return new Promise((n) => {
98
- const a = this.on(t, (o) => {
99
- a(), e(o), n(o);
96
+ once(t, n) {
97
+ return new Promise((r) => {
98
+ const i = this.on(t, (s) => {
99
+ i(), n(s), r(s);
100
100
  });
101
101
  });
102
102
  }
@@ -126,10 +126,10 @@ class y extends EventTarget {
126
126
  */
127
127
  getEventStats() {
128
128
  const t = {};
129
- for (const [e, n] of this.eventCounters.entries())
130
- t[e] = {
131
- count: n.count,
132
- handlersCount: this.getHandlerCount(e)
129
+ for (const [n, r] of this.eventCounters.entries())
130
+ t[n] = {
131
+ count: r.count,
132
+ handlersCount: this.getHandlerCount(n)
133
133
  };
134
134
  return t;
135
135
  }
@@ -140,10 +140,10 @@ class y extends EventTarget {
140
140
  this.eventCounters.clear();
141
141
  }
142
142
  }
143
- const C = y.getInstance(), z = typeof window > "u" || typeof document > "u";
144
- function q(r) {
143
+ const C = y.getInstance(), q = typeof window > "u" || typeof document > "u";
144
+ function W(e) {
145
145
  return {
146
- state: r,
146
+ state: e,
147
147
  emit: () => {
148
148
  },
149
149
  // No-op on server
@@ -155,40 +155,40 @@ function q(r) {
155
155
  }
156
156
  };
157
157
  }
158
- function W(r, t = {}) {
159
- z || console.warn("[SSR] renderToString should only be used on the server");
158
+ function F(e, t = {}) {
159
+ q || console.warn("[SSR] renderToString should only be used on the server");
160
160
  try {
161
- const e = r.state, n = q(e), a = r.template(e, n);
162
- let o = "";
163
- t.includeStyles && r.style && (o = `<style>${typeof r.style == "function" ? r.style(e) : r.style}</style>`);
164
- const s = t.sanitizeAttributes ? t.sanitizeAttributes(r.attrs || {}) : r.attrs || {}, i = Object.entries(s).map(([d, u]) => `${H(d)}="${H(u)}"`).join(" "), c = `${i ? `<${r.tag} ${i}>` : `<${r.tag}>`}${o}${a}</${r.tag}>`;
165
- return t.prettyPrint ? K(c) : c;
166
- } catch (e) {
167
- return console.error(`[SSR] Error rendering ${r.tag}:`, e), `<${r.tag}><div style="color: red;">SSR Error: ${F(String(e))}</div></${r.tag}>`;
161
+ const n = e.state, r = W(n), i = e.template(n, r);
162
+ let s = "";
163
+ t.includeStyles && e.style && (s = `<style>${typeof e.style == "function" ? e.style(n) : e.style}</style>`);
164
+ const o = t.sanitizeAttributes ? t.sanitizeAttributes(e.attrs || {}) : e.attrs || {}, a = Object.entries(o).map(([d, f]) => `${H(d)}="${H(f)}"`).join(" "), l = `${a ? `<${e.tag} ${a}>` : `<${e.tag}>`}${s}${i}</${e.tag}>`;
165
+ return t.prettyPrint ? G(l) : l;
166
+ } catch (n) {
167
+ return console.error(`[SSR] Error rendering ${e.tag}:`, n), `<${e.tag}><div style="color: red;">SSR Error: ${K(String(n))}</div></${e.tag}>`;
168
168
  }
169
169
  }
170
- function tt(r, t = {}) {
171
- const e = {
170
+ function tt(e, t = {}) {
171
+ const n = {
172
172
  components: /* @__PURE__ */ new Map(),
173
173
  styles: /* @__PURE__ */ new Set()
174
- }, n = [];
175
- r.forEach((s) => {
176
- if (e.components.set(s.tag, s), s.style) {
177
- const l = typeof s.style == "function" ? s.style(s.state) : s.style;
178
- e.styles.add(l);
174
+ }, r = [];
175
+ e.forEach((o) => {
176
+ if (n.components.set(o.tag, o), o.style) {
177
+ const c = typeof o.style == "function" ? o.style(o.state) : o.style;
178
+ n.styles.add(c);
179
179
  }
180
- const i = W(s, { ...t, includeStyles: !1 });
181
- n.push(i);
180
+ const a = F(o, { ...t, includeStyles: !1 });
181
+ r.push(a);
182
182
  });
183
- const a = Array.from(e.styles).join(`
183
+ const i = Array.from(n.styles).join(`
184
184
  `);
185
- return { html: n.join(`
186
- `), styles: a, context: e };
185
+ return { html: r.join(`
186
+ `), styles: i, context: n };
187
187
  }
188
- function et(r) {
189
- const t = Array.from(r.components.entries()).map(([e, n]) => ({
190
- tag: e,
191
- state: n.state
188
+ function et(e) {
189
+ const t = Array.from(e.components.entries()).map(([n, r]) => ({
190
+ tag: n,
191
+ state: r.state
192
192
  }));
193
193
  return `
194
194
  <script type="module">
@@ -225,138 +225,138 @@ function et(r) {
225
225
  }
226
226
  <\/script>`.trim();
227
227
  }
228
- const F = (r) => r.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;"), H = (r) => r.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&#39;").replace(/</g, "&lt;").replace(/>/g, "&gt;"), K = (r) => r.replace(/></g, `>
228
+ const K = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;"), H = (e) => e.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&#39;").replace(/</g, "&lt;").replace(/>/g, "&gt;"), G = (e) => e.replace(/></g, `>
229
229
  <`).split(`
230
230
  `).map((t) => {
231
- const e = (t.match(/^<[^\/]/g) || []).length - (t.match(/<\//g) || []).length;
232
- return " ".repeat(Math.max(0, e)) + t.trim();
231
+ const n = (t.match(/^<[^\/]/g) || []).length - (t.match(/<\//g) || []).length;
232
+ return " ".repeat(Math.max(0, n)) + t.trim();
233
233
  }).join(`
234
234
  `);
235
- function $(r) {
236
- return String(r).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
235
+ function $(e) {
236
+ return String(e).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
237
237
  }
238
- function w(r, t) {
239
- if (typeof r != "string" || !t) return String(r);
240
- for (const e in t) {
241
- if (typeof t[e] == "string" && r === t[e])
242
- return $(r);
243
- if (Array.isArray(t[e])) {
244
- for (const n of t[e])
245
- if (n && typeof n == "object") {
246
- for (const a in n)
247
- if (typeof n[a] == "string" && r === n[a])
248
- return $(r);
238
+ function w(e, t) {
239
+ if (typeof e != "string" || !t) return String(e);
240
+ for (const n in t) {
241
+ if (typeof t[n] == "string" && e === t[n])
242
+ return $(e);
243
+ if (Array.isArray(t[n])) {
244
+ for (const r of t[n])
245
+ if (r && typeof r == "object") {
246
+ for (const i in r)
247
+ if (typeof r[i] == "string" && e === r[i])
248
+ return $(e);
249
249
  }
250
250
  }
251
251
  }
252
- return String(r);
252
+ return String(e);
253
253
  }
254
- function nt(r, ...t) {
255
- function e(n, a, o) {
256
- if (Array.isArray(n)) {
257
- const s = n.map((i) => e(i, a, o));
258
- return s.some((i) => i instanceof Promise) ? Promise.all(s).then((i) => i.join("")) : s.join("");
254
+ function nt(e, ...t) {
255
+ function n(r, i, s) {
256
+ if (Array.isArray(r)) {
257
+ const o = r.map((a) => n(a, i, s));
258
+ return o.some((a) => a instanceof Promise) ? Promise.all(o).then((a) => a.join("")) : o.join("");
259
259
  }
260
- if (typeof n == "function") {
261
- const s = e(n(a, o), a, o);
262
- return s instanceof Promise, s;
260
+ if (typeof r == "function") {
261
+ const o = n(r(i, s), i, s);
262
+ return o instanceof Promise, o;
263
263
  }
264
- return n == null ? "" : n instanceof Promise ? n : String(n);
265
- }
266
- return (n, a) => {
267
- let o = "", s = !1;
268
- const i = [];
269
- for (let l = 0; l < r.length; l++)
270
- if (o += r[l], l < t.length) {
271
- let c = t[l];
272
- const d = r[l], u = /data-on-[a-z]+="?$/.test(d);
273
- c = e(c, n, a), c instanceof Promise ? (s = !0, i.push(c)) : /=\s*"?$/.test(d) && typeof c == "string" && !u ? (c = c.replace(/"/g, "&quot;").replace(/'/g, "&#39;"), o += c) : !u && !/=\s*"?$/.test(d) ? o += w(c, n) : o += c;
264
+ return r == null ? "" : r instanceof Promise ? r : String(r);
265
+ }
266
+ return (r, i) => {
267
+ let s = "", o = !1;
268
+ const a = [];
269
+ for (let c = 0; c < e.length; c++)
270
+ if (s += e[c], c < t.length) {
271
+ let l = t[c];
272
+ const d = e[c], f = /data-on-[a-z]+="?$/.test(d);
273
+ l = n(l, r, i), l instanceof Promise ? (o = !0, a.push(l)) : /=\s*"?$/.test(d) && typeof l == "string" && !f ? (l = l.replace(/"/g, "&quot;").replace(/'/g, "&#39;"), s += l) : !f && !/=\s*"?$/.test(d) ? s += w(l, r) : s += l;
274
274
  }
275
- return s ? Promise.all(i).then((l) => {
276
- let c = "", d = 0;
277
- for (let u = 0; u < r.length; u++)
278
- if (c += r[u], u < t.length) {
279
- let f = t[u];
280
- const h = r[u], m = /data-on-[a-z]+="?$/.test(h);
281
- f = e(f, n, a), f instanceof Promise ? c += l[d++] : /=\s*"?$/.test(h) && typeof f == "string" && !m ? (f = f.replace(/"/g, "&quot;").replace(/'/g, "&#39;"), c += f) : !m && !/=\s*"?$/.test(h) ? c += w(f, n) : c += f;
275
+ return o ? Promise.all(a).then((c) => {
276
+ let l = "", d = 0;
277
+ for (let f = 0; f < e.length; f++)
278
+ if (l += e[f], f < t.length) {
279
+ let u = t[f];
280
+ const h = e[f], m = /data-on-[a-z]+="?$/.test(h);
281
+ u = n(u, r, i), u instanceof Promise ? l += c[d++] : /=\s*"?$/.test(h) && typeof u == "string" && !m ? (u = u.replace(/"/g, "&quot;").replace(/'/g, "&#39;"), l += u) : !m && !/=\s*"?$/.test(h) ? l += w(u, r) : l += u;
282
282
  }
283
- return c;
284
- }) : o;
283
+ return l;
284
+ }) : s;
285
285
  };
286
286
  }
287
- function rt(r, ...t) {
288
- const e = "compiled-" + Math.random().toString(36).slice(2);
289
- function n(o, s, i) {
290
- return Array.isArray(o) ? o.map((l) => n(l, s, i)).join("") : typeof o == "function" ? n(o(s, i), s, i) : o == null ? "" : String(o);
291
- }
292
- const a = (o, s) => {
293
- let i = "";
294
- for (let l = 0; l < r.length; l++)
295
- if (i += r[l], l < t.length) {
296
- let c = t[l];
297
- const d = r[l], u = /data-on-[a-z]+="?$/.test(d);
298
- c = n(c, o, s), /=\s*"?$/.test(d) && typeof c == "string" && !u ? (c = c.replace(/"/g, "&quot;").replace(/'/g, "&#39;"), i += c) : !u && !/=\s*"?$/.test(d) ? i += w(c, o) : i += c ?? "";
287
+ function rt(e, ...t) {
288
+ const n = "compiled-" + Math.random().toString(36).slice(2);
289
+ function r(s, o, a) {
290
+ return Array.isArray(s) ? s.map((c) => r(c, o, a)).join("") : typeof s == "function" ? r(s(o, a), o, a) : s == null ? "" : String(s);
291
+ }
292
+ const i = (s, o) => {
293
+ let a = "";
294
+ for (let c = 0; c < e.length; c++)
295
+ if (a += e[c], c < t.length) {
296
+ let l = t[c];
297
+ const d = e[c], f = /data-on-[a-z]+="?$/.test(d);
298
+ l = r(l, s, o), /=\s*"?$/.test(d) && typeof l == "string" && !f ? (l = l.replace(/"/g, "&quot;").replace(/'/g, "&#39;"), a += l) : !f && !/=\s*"?$/.test(d) ? a += w(l, s) : a += l ?? "";
299
299
  }
300
- return i;
300
+ return a;
301
301
  };
302
- return a.id = e, a;
302
+ return i.id = n, i;
303
303
  }
304
- function st(r, ...t) {
305
- let e = "";
306
- for (let n = 0; n < r.length; n++)
307
- e += r[n], n < t.length && (e += t[n] ?? "");
308
- return e;
304
+ function st(e, ...t) {
305
+ let n = "";
306
+ for (let r = 0; r < e.length; r++)
307
+ n += e[r], r < t.length && (n += t[r] ?? "");
308
+ return n;
309
309
  }
310
- function it(r) {
311
- return r;
310
+ function it(e) {
311
+ return e;
312
312
  }
313
- function ot(r, t) {
314
- return { [r]: t };
313
+ function ot(e, t) {
314
+ return { [e]: t };
315
315
  }
316
- function at(r) {
317
- return Object.keys(r).filter((t) => r[t]).join(" ");
316
+ function at(e) {
317
+ return Object.keys(e).filter((t) => e[t]).join(" ");
318
318
  }
319
- function ct(r) {
320
- return Object.entries(r).map(([t, e]) => `${t}: ${e}`).join("; ");
319
+ function ct(e) {
320
+ return Object.entries(e).map(([t, n]) => `${t}: ${n}`).join("; ");
321
321
  }
322
- function G(r, t, e) {
323
- const [n, ...a] = e.split("|").map((i) => i.trim());
324
- if (!n || n === "__proto__" || n === "constructor" || n === "prototype") return;
325
- function o(i, l, c) {
326
- const d = l.split(".");
327
- let u = i;
328
- for (let f = 0; f < d.length - 1; f++)
329
- d[f] in u || (u[d[f]] = {}), u = u[d[f]];
330
- u[d[d.length - 1]] = c;
331
- }
332
- const s = (i) => {
333
- let l;
334
- if (r instanceof HTMLInputElement && r.type === "checkbox") {
335
- l = r.value;
336
- const c = r.getAttribute("data-true-value"), d = r.getAttribute("data-false-value");
337
- let u = Array.isArray(t[n]) ? t[n] : void 0;
338
- if (u) {
339
- if (r.checked)
340
- u.includes(l) || u.push(l);
322
+ function U(e, t, n) {
323
+ const [r, ...i] = n.split("|").map((a) => a.trim());
324
+ if (!r || r === "__proto__" || r === "constructor" || r === "prototype") return;
325
+ function s(a, c, l) {
326
+ const d = c.split(".");
327
+ let f = a;
328
+ for (let u = 0; u < d.length - 1; u++)
329
+ d[u] in f || (f[d[u]] = {}), f = f[d[u]];
330
+ f[d[d.length - 1]] = l;
331
+ }
332
+ const o = (a) => {
333
+ let c;
334
+ if (e instanceof HTMLInputElement && e.type === "checkbox") {
335
+ c = e.value;
336
+ const l = e.getAttribute("data-true-value"), d = e.getAttribute("data-false-value");
337
+ let f = Array.isArray(t[r]) ? t[r] : void 0;
338
+ if (f) {
339
+ if (e.checked)
340
+ f.includes(c) || f.push(c);
341
341
  else {
342
- const f = u.indexOf(l);
343
- f !== -1 && u.splice(f, 1);
342
+ const u = f.indexOf(c);
343
+ u !== -1 && f.splice(u, 1);
344
344
  }
345
- o(t, n, [...u]);
345
+ s(t, r, [...f]);
346
346
  } else
347
- c !== null || d !== null ? r.checked ? o(t, n, c) : o(t, n, d !== null ? d : !1) : o(t, n, r.checked);
348
- } else r instanceof HTMLInputElement && r.type === "radio" ? (l = r.value, o(t, n, l), ((r.form || r.closest("form") || r.getRootNode()) instanceof Element ? (r.form || r.closest("form") || r.getRootNode()).querySelectorAll(`input[type="radio"][name="${r.name}"][data-model="${e}"]`) : []).forEach((d) => {
349
- d.checked = d.value === String(l);
350
- })) : (l = r.value, r instanceof HTMLInputElement && r.type === "number" && (l = Number(l)), a.includes("trim") && typeof l == "string" && (l = l.trim()), a.includes("number") && (l = Number(l)), o(t, n, l));
351
- if ("_vnode" in r && typeof r._vnode == "object" && r._vnode?.props && (r._vnode.props.value = l), i.type === "input" && (r._isDirty = !0), i.type === "keydown" && i.key === "Enter" && (r._isDirty = !1, r instanceof HTMLElement && r.isConnected)) {
352
- let c = r.parentElement;
353
- for (; c && !(c instanceof HTMLElement && c.shadowRoot); )
354
- c = c.parentElement;
355
- c && typeof c == "object" && c !== null && "render" in c && typeof c.render == "function" && c.render();
347
+ l !== null || d !== null ? e.checked ? s(t, r, l) : s(t, r, d !== null ? d : !1) : s(t, r, e.checked);
348
+ } else e instanceof HTMLInputElement && e.type === "radio" ? (c = e.value, s(t, r, c), ((e.form || e.closest("form") || e.getRootNode()) instanceof Element ? (e.form || e.closest("form") || e.getRootNode()).querySelectorAll(`input[type="radio"][name="${e.name}"][data-model="${n}"]`) : []).forEach((d) => {
349
+ d.checked = d.value === String(c);
350
+ })) : (c = e.value, e instanceof HTMLInputElement && e.type === "number" && (c = Number(c)), i.includes("trim") && typeof c == "string" && (c = c.trim()), i.includes("number") && (c = Number(c)), s(t, r, c));
351
+ if ("_vnode" in e && typeof e._vnode == "object" && e._vnode?.props && (e._vnode.props.value = c), a.type === "input" && (e._isDirty = !0), a.type === "keydown" && a.key === "Enter" && (e._isDirty = !1, e instanceof HTMLElement && e.isConnected)) {
352
+ let l = e.parentElement;
353
+ for (; l && !(l instanceof HTMLElement && l.shadowRoot); )
354
+ l = l.parentElement;
355
+ l && typeof l == "object" && l !== null && "render" in l && typeof l.render == "function" && l.render();
356
356
  }
357
- i.type === "blur" && (r._isDirty = !1);
357
+ a.type === "blur" && (e._isDirty = !1);
358
358
  };
359
- r.addEventListener("input", s), r.addEventListener("change", s), r.addEventListener("keydown", s), r.addEventListener("blur", s);
359
+ e.addEventListener("input", o), e.addEventListener("change", o), e.addEventListener("keydown", o), e.addEventListener("blur", o);
360
360
  }
361
361
  const R = (() => {
362
362
  try {
@@ -366,155 +366,155 @@ const R = (() => {
366
366
  }
367
367
  return typeof window < "u" ? window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1" : !1;
368
368
  })();
369
- function lt(r, t = {}) {
370
- const { development: e = R, cache: n = !0, optimize: a = !0 } = t, o = N(r);
371
- if (n && T.has(o)) {
372
- if (e) {
373
- const s = v.get(o) || {
369
+ function lt(e, t = {}) {
370
+ const { development: n = R, cache: r = !0, optimize: i = !0 } = t, s = N(e);
371
+ if (r && T.has(s)) {
372
+ if (n) {
373
+ const o = E.get(s) || {
374
374
  compilationTime: 0,
375
375
  renderTime: 0,
376
376
  updateTime: 0,
377
377
  cacheHits: 0,
378
378
  cacheMisses: 0
379
379
  };
380
- s.cacheHits++, v.set(o, s);
380
+ o.cacheHits++, E.set(s, o);
381
381
  }
382
- return T.get(o);
382
+ return T.get(s);
383
383
  }
384
- if (e) {
385
- const s = v.get(o) || {
384
+ if (n) {
385
+ const o = E.get(s) || {
386
386
  compilationTime: 0,
387
387
  renderTime: 0,
388
388
  updateTime: 0,
389
389
  cacheHits: 0,
390
390
  cacheMisses: 0
391
391
  };
392
- s.cacheMisses++, v.set(o, s);
392
+ o.cacheMisses++, E.set(s, o);
393
393
  }
394
394
  try {
395
- const s = Z(r, { development: e, optimize: a });
396
- return n && T.set(o, s), s;
397
- } catch (s) {
398
- return e && (console.error("[Template Compiler] Error compiling template:", s), console.error("[Template Compiler] Template:", r)), {
399
- statics: [r],
395
+ const o = B(e, { development: n, optimize: i });
396
+ return r && T.set(s, o), o;
397
+ } catch (o) {
398
+ return n && (console.error("[Template Compiler] Error compiling template:", o), console.error("[Template Compiler] Template:", e)), {
399
+ statics: [e],
400
400
  dynamics: [],
401
401
  fragment: null,
402
- id: o,
402
+ id: s,
403
403
  hasDynamics: !1,
404
- render: () => r
404
+ render: () => e
405
405
  };
406
406
  }
407
407
  }
408
- function U(r, t) {
408
+ function Z(e, t) {
409
409
  if (typeof document > "u")
410
410
  return [0];
411
411
  try {
412
- let e = function(i, l = []) {
413
- if (i.nodeType === Node.TEXT_NODE) {
414
- if (i.textContent?.includes(t))
415
- return l;
416
- } else if (i.nodeType === Node.ELEMENT_NODE) {
417
- let c = 0;
418
- for (let d = 0; d < i.childNodes.length; d++) {
419
- const u = i.childNodes[d], f = e(u, [...l, c]);
420
- if (f)
421
- return f;
422
- c++;
412
+ let n = function(a, c = []) {
413
+ if (a.nodeType === Node.TEXT_NODE) {
414
+ if (a.textContent?.includes(t))
415
+ return c;
416
+ } else if (a.nodeType === Node.ELEMENT_NODE) {
417
+ let l = 0;
418
+ for (let d = 0; d < a.childNodes.length; d++) {
419
+ const f = a.childNodes[d], u = n(f, [...c, l]);
420
+ if (u)
421
+ return u;
422
+ l++;
423
423
  }
424
424
  }
425
425
  return null;
426
426
  };
427
- const o = new DOMParser().parseFromString(`<div>${r}</div>`, "text/html").body.firstElementChild;
428
- return e(o) || [0];
429
- } catch (e) {
430
- return R && console.warn("[Template Compiler] Error finding DOM path for placeholder:", t, e), [0];
427
+ const s = new DOMParser().parseFromString(`<div>${e}</div>`, "text/html").body.firstElementChild;
428
+ return n(s) || [0];
429
+ } catch (n) {
430
+ return R && console.warn("[Template Compiler] Error finding DOM path for placeholder:", t, n), [0];
431
431
  }
432
432
  }
433
- function Z(r, t) {
434
- return new B(r, t).compile();
433
+ function B(e, t) {
434
+ return new X(e, t).compile();
435
435
  }
436
- class B {
436
+ class X {
437
437
  template;
438
438
  options;
439
439
  dynamics = [];
440
440
  statics = [];
441
- constructor(t, e) {
442
- this.template = t, this.options = e;
441
+ constructor(t, n) {
442
+ this.template = t, this.options = n;
443
443
  }
444
444
  compile() {
445
445
  this.parseTemplate();
446
- const t = this.createStaticFragment(), e = N(this.template), n = (a, o) => {
447
- let s = "";
448
- for (let i = 0; i < this.statics.length; i++)
449
- if (s += this.statics[i], i < this.dynamics.length) {
450
- let l = this.dynamics[i].getValue(a, o);
451
- if (l instanceof Promise)
452
- return Promise.all(this.dynamics.map((c) => {
453
- const d = c.getValue(a, o);
446
+ const t = this.createStaticFragment(), n = N(this.template), r = (i, s) => {
447
+ let o = "";
448
+ for (let a = 0; a < this.statics.length; a++)
449
+ if (o += this.statics[a], a < this.dynamics.length) {
450
+ let c = this.dynamics[a].getValue(i, s);
451
+ if (c instanceof Promise)
452
+ return Promise.all(this.dynamics.map((l) => {
453
+ const d = l.getValue(i, s);
454
454
  return d instanceof Promise ? d : Promise.resolve(d);
455
- })).then((c) => {
455
+ })).then((l) => {
456
456
  let d = "";
457
- for (let u = 0; u < this.statics.length; u++)
458
- d += this.statics[u], u < c.length && (d += c[u]);
457
+ for (let f = 0; f < this.statics.length; f++)
458
+ d += this.statics[f], f < l.length && (d += l[f]);
459
459
  return d;
460
460
  });
461
- s += l;
461
+ o += c;
462
462
  }
463
- return s;
463
+ return o;
464
464
  };
465
465
  return {
466
466
  statics: this.statics,
467
467
  dynamics: this.dynamics,
468
468
  fragment: t,
469
- id: e,
469
+ id: n,
470
470
  hasDynamics: this.dynamics.length > 0,
471
- render: n
471
+ render: r
472
472
  };
473
473
  }
474
474
  parseTemplate() {
475
475
  const t = /\{\{([^}]+)\}\}/g;
476
- let e = 0, n;
477
- for (; (n = t.exec(this.template)) !== null; ) {
478
- const o = this.template.slice(e, n.index);
479
- this.statics.push(o);
480
- let s = o.match(/([a-zA-Z0-9_-]+)\s*=\s*"?$/), i = s ? s[1] : void 0, l;
481
- if (o.endsWith('style="color:'))
482
- i = "style", l = "color";
483
- else if (i === "style") {
484
- const d = o.match(/style\s*=\s*"?([^:;]+):\s*$/);
485
- d && (l = d[1].trim());
476
+ let n = 0, r;
477
+ for (; (r = t.exec(this.template)) !== null; ) {
478
+ const s = this.template.slice(n, r.index);
479
+ this.statics.push(s);
480
+ let o = s.match(/([a-zA-Z0-9_-]+)\s*=\s*"?$/), a = o ? o[1] : void 0, c;
481
+ if (s.endsWith('style="color:'))
482
+ a = "style", c = "color";
483
+ else if (a === "style") {
484
+ const d = s.match(/style\s*=\s*"?([^:;]+):\s*$/);
485
+ d && (c = d[1].trim());
486
486
  }
487
- const c = n[1].trim();
488
- this.analyzeDynamicExpression(c, this.dynamics.length, i, l), e = n.index + n[0].length;
487
+ const l = r[1].trim();
488
+ this.analyzeDynamicExpression(l, this.dynamics.length, a, c), n = r.index + r[0].length;
489
489
  }
490
- const a = this.template.slice(e);
491
- this.statics.push(a);
492
- }
493
- analyzeDynamicExpression(t, e, n, a) {
494
- let o = "text", s;
495
- n ? n === "class" ? (o = "class", s = "class") : n === "style" ? (o = "style", s = a || "style") : n === "value" ? (o = "property", s = "value") : (o = "attribute", s = n) : t.includes("class.") ? (o = "class", s = t.split(".")[1]) : t.includes("style.") ? (o = "style", s = t.split(".")[1]) : t.includes("@") ? (o = "event", s = t.split("@")[1]) : t === "class" ? (o = "class", s = "class") : t === "style" ? (o = "style", s = "style") : t === "value" ? (o = "property", s = "value") : t === "title" && (o = "attribute", s = "title");
496
- const i = `__DYNAMIC_${e}__`, l = this.statics.join(i);
497
- let c = U(l, i);
498
- this.statics.length === 2 && o !== "text" ? c = [0] : this.statics.length === 2 && c.length === 0 && (c = [0]), this.dynamics.push({
499
- path: c,
500
- type: o,
501
- target: s,
490
+ const i = this.template.slice(n);
491
+ this.statics.push(i);
492
+ }
493
+ analyzeDynamicExpression(t, n, r, i) {
494
+ let s = "text", o;
495
+ r ? r === "class" ? (s = "class", o = "class") : r === "style" ? (s = "style", o = i || "style") : r === "value" ? (s = "property", o = "value") : (s = "attribute", o = r) : t.includes("class.") ? (s = "class", o = t.split(".")[1]) : t.includes("style.") ? (s = "style", o = t.split(".")[1]) : t.includes("@") ? (s = "event", o = t.split("@")[1]) : t === "class" ? (s = "class", o = "class") : t === "style" ? (s = "style", o = "style") : t === "value" ? (s = "property", o = "value") : t === "title" && (s = "attribute", o = "title");
496
+ const a = `__DYNAMIC_${n}__`, c = this.statics.join(a);
497
+ let l = Z(c, a);
498
+ this.statics.length === 2 && s !== "text" ? l = [0] : this.statics.length === 2 && l.length === 0 && (l = [0]), this.dynamics.push({
499
+ path: l,
500
+ type: s,
501
+ target: o,
502
502
  getValue: this.createValueGetter(t)
503
503
  });
504
504
  }
505
505
  createValueGetter(t) {
506
- return (e, n) => {
506
+ return (n, r) => {
507
507
  try {
508
- let a;
508
+ let i;
509
509
  if (t && typeof t == "function")
510
- a = t(e);
510
+ i = t(n);
511
511
  else if (typeof t == "string" && t.startsWith("state.")) {
512
- const o = t.slice(6);
513
- a = e[o];
514
- } else typeof t == "string" && /^[a-zA-Z0-9_$]+$/.test(t) ? a = e[t] : (typeof t == "string" && t.includes("("), a = "");
515
- return a;
516
- } catch (a) {
517
- return this.options.development && console.warn(`[Template Compiler] Error evaluating expression: ${t}`, a), "";
512
+ const s = t.slice(6);
513
+ i = n[s];
514
+ } else typeof t == "string" && /^[a-zA-Z0-9_$]+$/.test(t) ? i = n[t] : (typeof t == "string" && t.includes("("), i = "");
515
+ return i;
516
+ } catch (i) {
517
+ return this.options.development && console.warn(`[Template Compiler] Error evaluating expression: ${t}`, i), "";
518
518
  }
519
519
  };
520
520
  }
@@ -525,407 +525,404 @@ class B {
525
525
  const t = this.statics.join("");
526
526
  if (!t.trim())
527
527
  return null;
528
- const n = new DOMParser().parseFromString(t, "text/html"), a = document.createDocumentFragment();
529
- for (; n.body.firstChild; )
530
- a.appendChild(n.body.firstChild);
531
- return a;
528
+ const r = new DOMParser().parseFromString(t, "text/html"), i = document.createDocumentFragment();
529
+ for (; r.body.firstChild; )
530
+ i.appendChild(r.body.firstChild);
531
+ return i;
532
532
  } catch (t) {
533
533
  return this.options.development && console.warn("[Template Compiler] Could not create static fragment:", t), null;
534
534
  }
535
535
  }
536
536
  }
537
- function O(r, t) {
537
+ function O(e, t) {
538
538
  try {
539
- if (t.length === 1 && t[0] === 0 && r instanceof Element)
540
- return r;
541
- let e = r;
542
- for (let n = 0; n < t.length; n++) {
543
- const a = t[n];
544
- if (!e.childNodes || e.childNodes.length <= a)
539
+ if (t.length === 1 && t[0] === 0 && e instanceof Element)
540
+ return e;
541
+ let n = e;
542
+ for (let r = 0; r < t.length; r++) {
543
+ const i = t[r];
544
+ if (!n.childNodes || n.childNodes.length <= i)
545
545
  return null;
546
- e = e.childNodes[a];
546
+ n = n.childNodes[i];
547
547
  }
548
- return e;
548
+ return n;
549
549
  } catch {
550
550
  return null;
551
551
  }
552
552
  }
553
- function j(r, t, e) {
554
- let n;
555
- return r.fragment && !r.hasDynamics ? n = r.fragment.cloneNode(!0) : n = V(r, t, e), n;
553
+ function j(e, t, n) {
554
+ let r;
555
+ return e.fragment && !e.hasDynamics ? r = e.fragment.cloneNode(!0) : r = Y(e, t, n), r;
556
556
  }
557
- function X(r, t, e, n, a) {
558
- if (r.hasDynamics)
559
- for (const o of r.dynamics)
557
+ function V(e, t, n, r, i) {
558
+ if (e.hasDynamics)
559
+ for (const s of e.dynamics)
560
560
  try {
561
- const s = o.getValue(e, n);
562
- if (a !== void 0 && o.getValue(a, n) === s)
561
+ const o = s.getValue(n, r);
562
+ if (i !== void 0 && s.getValue(i, r) === o)
563
563
  continue;
564
- I(t, o, s);
565
- } catch (s) {
566
- console.warn("[Template Compiler] Error applying update:", s);
564
+ I(t, s, o);
565
+ } catch (o) {
566
+ console.warn("[Template Compiler] Error applying update:", o);
567
567
  }
568
568
  }
569
- function V(r, t, e) {
570
- let n = "";
571
- for (let i = 0; i < r.statics.length; i++)
572
- if (n += r.statics[i], i < r.dynamics.length) {
573
- const l = r.dynamics[i];
574
- if (l.type === "text" || l.type === "attribute") {
575
- const c = l.getValue(t, e);
576
- n += String(c ?? "");
577
- } else (l.type === "property" || l.type === "class" || l.type === "style") && (n += "");
569
+ function Y(e, t, n) {
570
+ let r = "";
571
+ for (let a = 0; a < e.statics.length; a++)
572
+ if (r += e.statics[a], a < e.dynamics.length) {
573
+ const c = e.dynamics[a];
574
+ if (c.type === "text" || c.type === "attribute") {
575
+ const l = c.getValue(t, n);
576
+ r += String(l ?? "");
577
+ } else (c.type === "property" || c.type === "class" || c.type === "style") && (r += "");
578
578
  }
579
579
  if (typeof document > "u")
580
580
  return new DocumentFragment();
581
- const o = new DOMParser().parseFromString(n, "text/html"), s = document.createDocumentFragment();
582
- for (; o.body.firstChild; )
583
- s.appendChild(o.body.firstChild);
584
- for (const i of r.dynamics) {
585
- const l = i.getValue(t, e), c = O(s, i.path);
586
- I(c, i, l);
587
- }
588
- return s;
581
+ const s = new DOMParser().parseFromString(r, "text/html"), o = document.createDocumentFragment();
582
+ for (; s.body.firstChild; )
583
+ o.appendChild(s.body.firstChild);
584
+ for (const a of e.dynamics) {
585
+ const c = a.getValue(t, n), l = O(o, a.path);
586
+ I(l, a, c);
587
+ }
588
+ return o;
589
589
  }
590
- function I(r, t, e) {
590
+ function I(e, t, n) {
591
591
  try {
592
592
  if (t.type === "text") {
593
- const a = document.createTreeWalker(
594
- r,
593
+ const i = document.createTreeWalker(
594
+ e,
595
595
  NodeFilter.SHOW_TEXT
596
596
  );
597
- let o = !1, s;
598
- for (; s = a.nextNode(); ) {
599
- const l = s.textContent || "";
600
- if (l.includes("Count: ")) {
601
- const c = l.replace(/Count: \d+/, `Count: ${e}`);
602
- s.textContent = c, o = !0;
597
+ let s = !1, o;
598
+ for (; o = i.nextNode(); ) {
599
+ const c = o.textContent || "";
600
+ if (c.includes("Count: ")) {
601
+ const l = c.replace(/Count: \d+/, `Count: ${n}`);
602
+ o.textContent = l, s = !0;
603
603
  }
604
604
  }
605
- if (o) return;
606
- const i = O(r, t.path);
607
- i && i.nodeType === Node.TEXT_NODE && (i.textContent = e == null ? "" : String(e));
605
+ if (s) return;
606
+ const a = O(e, t.path);
607
+ a && a.nodeType === Node.TEXT_NODE && (a.textContent = n == null ? "" : String(n));
608
608
  return;
609
609
  }
610
- const n = O(r, t.path);
611
- if (!n)
610
+ const r = O(e, t.path);
611
+ if (!r)
612
612
  return;
613
613
  switch (t.type) {
614
614
  case "attribute":
615
- if (n.nodeType === Node.ELEMENT_NODE && t.target) {
616
- const a = n;
617
- e == null || e === "" ? a.removeAttribute(t.target) : a.setAttribute(t.target, String(e));
615
+ if (r.nodeType === Node.ELEMENT_NODE && t.target) {
616
+ const i = r;
617
+ n == null || n === "" ? i.removeAttribute(t.target) : i.setAttribute(t.target, String(n));
618
618
  }
619
619
  break;
620
620
  case "property":
621
- n.nodeType === Node.ELEMENT_NODE && t.target && (n[t.target] = e ?? "", n.setAttribute(t.target, e == null ? "" : String(e)));
621
+ r.nodeType === Node.ELEMENT_NODE && t.target && (r[t.target] = n ?? "", r.setAttribute(t.target, n == null ? "" : String(n)));
622
622
  break;
623
623
  case "class":
624
- if (n.nodeType === Node.ELEMENT_NODE && t.target) {
625
- const a = n;
626
- a.className = e == null ? "" : String(e), a.setAttribute("class", e == null ? "" : String(e));
624
+ if (r.nodeType === Node.ELEMENT_NODE && t.target) {
625
+ const i = r;
626
+ i.className = n == null ? "" : String(n), i.setAttribute("class", n == null ? "" : String(n));
627
627
  }
628
628
  break;
629
629
  case "style":
630
- if (n.nodeType === Node.ELEMENT_NODE && t.target) {
631
- const a = n;
632
- a.style[t.target] = e == null ? "" : String(e), a.setAttribute("style", e == null ? `${t.target}:` : `${t.target}:${e}`);
630
+ if (r.nodeType === Node.ELEMENT_NODE && t.target) {
631
+ const i = r;
632
+ i.style[t.target] = n == null ? "" : String(n), i.setAttribute("style", n == null ? `${t.target}:` : `${t.target}:${n}`);
633
633
  }
634
634
  break;
635
635
  default:
636
636
  throw new Error(`Unknown update type: ${t.type}`);
637
637
  }
638
- } catch (n) {
639
- (typeof globalThis < "u" ? globalThis.isDevelopment : R) && console.warn("[Template Compiler] Error applying update:", t, n);
638
+ } catch (r) {
639
+ (typeof globalThis < "u" ? globalThis.isDevelopment : R) && console.warn("[Template Compiler] Error applying update:", t, r);
640
640
  }
641
641
  }
642
- const T = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Map();
643
- function N(r) {
642
+ const T = /* @__PURE__ */ new Map(), E = /* @__PURE__ */ new Map();
643
+ function N(e) {
644
644
  let t = 0;
645
- for (let e = 0; e < r.length; e++) {
646
- const n = r.charCodeAt(e);
647
- t = (t << 5) - t + n, t = t & t;
645
+ for (let n = 0; n < e.length; n++) {
646
+ const r = e.charCodeAt(n);
647
+ t = (t << 5) - t + r, t = t & t;
648
648
  }
649
649
  return `tpl_${Math.abs(t).toString(36)}`;
650
650
  }
651
- function x(r, t, e, n, a) {
652
- return n && a ? `${t}.${r}[${e}]:${n}:${a}` : n ? `${t}.${r}[${e}]:${n}` : `${t}.${r}[${e}]`;
651
+ function x(e, t, n, r, i) {
652
+ return r && i ? `${t}.${e}[${n}]:${r}:${i}` : r ? `${t}.${e}[${n}]:${r}` : `${t}.${e}[${n}]`;
653
653
  }
654
- function D(r, t, e) {
655
- if (!(!r || !(r instanceof Element)) && r.contains(e) && e.parentNode === r)
654
+ function D(e, t, n) {
655
+ if (!(!e || !(e instanceof Element)) && e.contains(n) && n.parentNode === e)
656
656
  try {
657
- r.replaceChild(t, e);
658
- } catch (n) {
659
- console.error("[VDOM] safeReplaceChild: error replacing child", n, {
660
- parent: r,
657
+ e.replaceChild(t, n);
658
+ } catch (r) {
659
+ console.error("[VDOM] safeReplaceChild: error replacing child", r, {
660
+ parent: e,
661
661
  newChild: t,
662
- oldChild: e,
663
- parentHTML: r.outerHTML,
662
+ oldChild: n,
663
+ parentHTML: e.outerHTML,
664
664
  newChildHTML: t.outerHTML,
665
- oldChildHTML: e.outerHTML
665
+ oldChildHTML: n.outerHTML
666
666
  });
667
667
  }
668
668
  }
669
- function g(r) {
670
- if (r.type === "#whitespace")
669
+ function g(e) {
670
+ if (e.type === "#whitespace")
671
671
  return null;
672
- if (r.type === "#text") {
673
- const e = document.createTextNode(r.props.nodeValue ?? "");
674
- return r.dom = e, e;
675
- }
676
- const t = document.createElement(r.type);
677
- for (const [e, n] of Object.entries(r.props))
678
- e === "value" && t instanceof HTMLInputElement ? t.type === "radio" ? t.setAttribute("value", n) : (t.type, t.value = n, t.setAttribute("value", n)) : t.setAttribute(e, n);
679
- r.dom = t;
680
- for (const e of r.children) {
681
- const n = g(e);
682
- n && t.appendChild(n);
672
+ if (e.type === "#text") {
673
+ const n = document.createTextNode(e.props.nodeValue ?? "");
674
+ return e.dom = n, n;
675
+ }
676
+ const t = document.createElement(e.type);
677
+ for (const [n, r] of Object.entries(e.props))
678
+ n === "value" && t instanceof HTMLInputElement ? t.type === "radio" ? t.setAttribute("value", r) : (t.type, t.value = r, t.setAttribute("value", r)) : t.setAttribute(n, r);
679
+ e.dom = t;
680
+ for (const n of e.children) {
681
+ const r = g(n);
682
+ r && t.appendChild(r);
683
683
  }
684
684
  return t;
685
685
  }
686
- function Y(r) {
686
+ function J(e) {
687
687
  const t = document.createElement("template");
688
- t.innerHTML = r.trim();
689
- const e = Array.from(t.content.childNodes);
690
- return e.length === 1 ? k(e[0]) : {
688
+ t.innerHTML = e.trim();
689
+ const n = Array.from(t.content.childNodes);
690
+ return n.length === 1 ? k(n[0]) : {
691
691
  type: "#fragment",
692
692
  key: void 0,
693
693
  props: {},
694
- children: e.map((a, o) => k(a, "#fragment", o)),
694
+ children: n.map((i, s) => k(i, "#fragment", s)),
695
695
  dom: void 0
696
696
  };
697
697
  }
698
- function k(r, t = "", e = 0) {
699
- if (!r)
698
+ function k(e, t = "", n = 0) {
699
+ if (!e)
700
700
  return { type: "#unknown", key: void 0, props: {}, children: [], dom: void 0 };
701
- if (r.nodeType === Node.TEXT_NODE)
702
- return !r.nodeValue || /^\s*$/.test(r.nodeValue) ? { type: "#whitespace", key: void 0, props: {}, children: [], dom: void 0 } : { type: "#text", key: x("#text", t, e), props: { nodeValue: r.nodeValue }, children: [], dom: r };
703
- if (r.nodeType === Node.ELEMENT_NODE) {
704
- const n = r, a = {};
705
- Array.from(n.attributes).forEach((c) => {
706
- a[c.name] = c.value;
701
+ if (e.nodeType === Node.TEXT_NODE)
702
+ return !e.nodeValue || /^\s*$/.test(e.nodeValue) ? { type: "#whitespace", key: void 0, props: {}, children: [], dom: void 0 } : { type: "#text", key: x("#text", t, n), props: { nodeValue: e.nodeValue }, children: [], dom: e };
703
+ if (e.nodeType === Node.ELEMENT_NODE) {
704
+ const r = e, i = {};
705
+ Array.from(r.attributes).forEach((l) => {
706
+ i[l.name] = l.value;
707
707
  });
708
- const o = n.tagName.toLowerCase();
709
- let s;
710
- if ((o === "input" || o === "select" || o === "textarea") && n.hasAttribute("data-model")) {
711
- const c = n.getAttribute("data-model"), d = n.getAttribute("type") ?? "";
712
- s = `${o}:${c}:${d}`, a["data-uid"] = s, n.setAttribute("data-uid", s);
713
- let u = n.getAttribute("value"), f = n.getAttribute("checked");
714
- u && (a.value = u), f && (a.checked = f);
715
- } else o === "input" || o === "textarea" || o === "select" || n.hasAttribute("contenteditable") ? (s = `${o}:${t}:${e}`, a["data-uid"] = s, n.setAttribute("data-uid", s)) : (s = x(o, t, e), o === "li" && (a["data-uid"] = s, n.setAttribute("data-uid", s)));
716
- const i = Array.from(n.childNodes).map((c, d) => k(c, s, d));
708
+ const s = r.tagName.toLowerCase();
709
+ let o;
710
+ if ((s === "input" || s === "select" || s === "textarea") && r.hasAttribute("data-model")) {
711
+ const l = r.getAttribute("data-model"), d = r.getAttribute("type") ?? "";
712
+ o = `${s}:${l}:${d}`, i["data-uid"] = o, r.setAttribute("data-uid", o);
713
+ let f = r.getAttribute("value"), u = r.getAttribute("checked");
714
+ f && (i.value = f), u && (i.checked = u);
715
+ } else s === "input" || s === "textarea" || s === "select" || r.hasAttribute("contenteditable") ? (o = `${s}:${t}:${n}`, i["data-uid"] = o, r.setAttribute("data-uid", o)) : (o = x(s, t, n), s === "li" && (i["data-uid"] = o, r.setAttribute("data-uid", o)));
716
+ const a = Array.from(r.childNodes).map((l, d) => k(l, o, d));
717
717
  return {
718
- type: o,
719
- key: s,
720
- props: a,
721
- children: i,
722
- dom: n
718
+ type: s,
719
+ key: o,
720
+ props: i,
721
+ children: a,
722
+ dom: r
723
723
  };
724
724
  }
725
725
  return { type: "#unknown", key: void 0, props: {}, children: [], dom: void 0 };
726
726
  }
727
- function L(r, t, e) {
728
- if (!t || !e) return;
729
- function n(l) {
730
- return !!l && l.type !== "#whitespace" && !(l.type === "#text" && (!l.props?.nodeValue || /^\s*$/.test(l.props.nodeValue)));
731
- }
732
- const a = Array.isArray(t.children) ? t.children.filter(n) : [], o = Array.isArray(e.children) ? e.children.filter(n) : [], s = e.type === "input" || e.type === "select" || e.type === "textarea";
733
- if (t.type !== e.type || t.key !== e.key) {
734
- const l = g(e);
735
- if (l instanceof Node && t.dom instanceof Node && r.contains(t.dom)) {
736
- if (D(r, l, t.dom), s && e.props && r.firstChild instanceof HTMLInputElement) {
737
- const c = r.firstChild;
738
- c.type === "radio" || c.type, c.value = e.props.value, c.setAttribute("value", e.props.value), "checked" in e.props && (c.checked = e.props.checked === !0 || e.props.checked === "true");
727
+ function L(e, t, n) {
728
+ if (!t || !n) return;
729
+ function r(c) {
730
+ return !!c && c.type !== "#whitespace" && !(c.type === "#text" && (!c.props?.nodeValue || /^\s*$/.test(c.props.nodeValue)));
731
+ }
732
+ const i = Array.isArray(t.children) ? t.children.filter(r) : [], s = Array.isArray(n.children) ? n.children.filter(r) : [], o = n.type === "input" || n.type === "select" || n.type === "textarea";
733
+ if (t.type !== n.type || t.key !== n.key) {
734
+ const c = g(n);
735
+ if (c instanceof Node && t.dom instanceof Node && e.contains(t.dom)) {
736
+ if (D(e, c, t.dom), o && n.props && e.firstChild instanceof HTMLInputElement) {
737
+ const l = e.firstChild;
738
+ l.type === "radio" || l.type, l.value = n.props.value, l.setAttribute("value", n.props.value), "checked" in n.props && (l.checked = n.props.checked === !0 || n.props.checked === "true");
739
739
  }
740
- } else if (l instanceof Node)
741
- if (l) {
742
- if (r.appendChild(l), e.dom = l, s && e.props && r.firstChild instanceof HTMLInputElement) {
743
- const c = r.firstChild;
744
- c.type === "radio" ? c.setAttribute("value", e.props.value) : (c.type, c.value = e.props.value, c.setAttribute("value", e.props.value)), "checked" in e.props && (c.checked = e.props.checked === !0 || e.props.checked === "true");
740
+ } else if (c instanceof Node)
741
+ if (c) {
742
+ if (e.appendChild(c), n.dom = c, o && n.props && e.firstChild instanceof HTMLInputElement) {
743
+ const l = e.firstChild;
744
+ l.type === "radio" ? l.setAttribute("value", n.props.value) : (l.type, l.value = n.props.value, l.setAttribute("value", n.props.value)), "checked" in n.props && (l.checked = n.props.checked === !0 || n.props.checked === "true");
745
745
  }
746
746
  } else
747
- e.dom = void 0;
747
+ n.dom = void 0;
748
748
  else
749
- e.dom = void 0;
749
+ n.dom = void 0;
750
750
  return;
751
751
  }
752
- if (s && t.dom instanceof HTMLElement && e.props) {
753
- for (const [l, c] of Object.entries(e.props))
754
- if (l === "value" && r.firstChild instanceof HTMLInputElement)
755
- r.firstChild.value = c;
756
- else if (l === "checked" && r.firstChild instanceof HTMLInputElement)
757
- r.firstChild.checked = c === !0 || c === "true";
758
- else if (l in t.dom)
752
+ if (o && t.dom instanceof HTMLElement && n.props) {
753
+ for (const [c, l] of Object.entries(n.props))
754
+ if (c === "value" && e.firstChild instanceof HTMLInputElement)
755
+ e.firstChild.value = l;
756
+ else if (c === "checked" && e.firstChild instanceof HTMLInputElement)
757
+ e.firstChild.checked = l === !0 || l === "true";
758
+ else if (c in t.dom)
759
759
  try {
760
- t.dom[l] = c;
760
+ t.dom[c] = l;
761
761
  } catch {
762
762
  }
763
763
  else
764
- t.dom.setAttribute(l, c);
765
- for (let l = e.children.length; l < a.length; l++)
766
- a[l] && a[l].dom && t.dom && t.dom.contains(a[l].dom) && t.dom.removeChild(a[l].dom);
764
+ t.dom.setAttribute(c, l);
765
+ for (let c = n.children.length; c < i.length; c++)
766
+ i[c] && i[c].dom && t.dom && t.dom.contains(i[c].dom) && t.dom.removeChild(i[c].dom);
767
767
  return;
768
768
  }
769
- const i = t.dom;
770
- if (i && i instanceof Element && e.props) {
771
- const l = i.tagName.toLowerCase() === "input" ? i.getAttribute("type") : void 0, c = i.tagName.includes("-");
772
- for (const [d, u] of Object.entries(e.props))
773
- if (!(l === "radio" && d === "value")) {
774
- if (l === "checkbox" && d === "value") {
775
- i.setAttribute("value", u);
769
+ const a = t.dom;
770
+ if (a && a instanceof Element && n.props) {
771
+ const c = a.tagName.toLowerCase() === "input" ? a.getAttribute("type") : void 0, l = a.tagName.includes("-");
772
+ for (const [d, f] of Object.entries(n.props))
773
+ if (!(c === "radio" && d === "value")) {
774
+ if (c === "checkbox" && d === "value") {
775
+ a.setAttribute("value", f);
776
776
  continue;
777
777
  }
778
- i.setAttribute(d, u);
778
+ a.setAttribute(d, f);
779
779
  }
780
- if (c)
781
- for (const [d, u] of Object.entries(e.props))
782
- i.setAttribute(d, u);
783
- for (const d of Array.from(i.attributes).map((u) => u.name))
784
- if (!(d in e.props)) {
785
- if (l === "radio" && d === "value" || l === "checkbox" && d === "value") continue;
786
- i.removeAttribute(d);
780
+ if (l)
781
+ for (const [d, f] of Object.entries(n.props))
782
+ a.setAttribute(d, f);
783
+ for (const d of Array.from(a.attributes).map((f) => f.name))
784
+ if (!(d in n.props)) {
785
+ if (c === "radio" && d === "value" || c === "checkbox" && d === "value") continue;
786
+ a.removeAttribute(d);
787
787
  }
788
788
  }
789
- if (e.type === "#text") {
790
- if (i && i.nodeType === Node.TEXT_NODE)
791
- i.nodeValue !== e.props.nodeValue && (i.nodeValue = e.props.nodeValue), e.dom = i;
789
+ if (n.type === "#text") {
790
+ if (a && a.nodeType === Node.TEXT_NODE)
791
+ a.nodeValue !== n.props.nodeValue && (a.nodeValue = n.props.nodeValue), n.dom = a;
792
792
  else {
793
- const l = document.createTextNode(e.props.nodeValue ?? "");
794
- i && r.contains(i) && i.parentNode === r ? D(r, l, i) : r.appendChild(l), e.dom = l;
793
+ const c = document.createTextNode(n.props.nodeValue ?? "");
794
+ a && e.contains(a) && a.parentNode === e ? D(e, c, a) : e.appendChild(c), n.dom = c;
795
795
  }
796
796
  return;
797
797
  }
798
- if (i instanceof Element) {
799
- const l = /* @__PURE__ */ new Map();
800
- a.forEach((f) => f.key && l.set(f.key, f));
801
- const c = new Set(o.map((f) => f.key));
798
+ if (a instanceof Element) {
799
+ const c = /* @__PURE__ */ new Map();
800
+ i.forEach((u) => u.key && c.set(u.key, u));
801
+ const l = new Set(s.map((u) => u.key));
802
802
  let d = [];
803
- for (let f = 0; f < o.length; f++) {
804
- const h = o[f], m = h.key ? l.get(h.key) : a[f];
803
+ for (let u = 0; u < s.length; u++) {
804
+ const h = s[u], m = h.key ? c.get(h.key) : i[u];
805
805
  let p;
806
806
  const A = h.type === "input" || h.type === "select" || h.type === "textarea";
807
807
  if (m && m.dom && (!A || m.type === h.type && m.key === h.key))
808
- L(i, m, h), p = m.dom;
808
+ L(a, m, h), p = m.dom;
809
809
  else {
810
- const E = g(h);
811
- if (p = E instanceof Node ? E : void 0, p) {
812
- if ((p instanceof Element || p instanceof Node) && p.contains(i))
810
+ const b = g(h);
811
+ if (p = b instanceof Node ? b : void 0, p) {
812
+ if ((p instanceof Element || p instanceof Node) && p.contains(a))
813
813
  throw console.error("[VDOM] Attempted to insert a parent into its own child:", {
814
- parentTag: i.tagName,
814
+ parentTag: a.tagName,
815
815
  childTag: p.tagName,
816
- parentUid: i.getAttribute?.("data-uid"),
816
+ parentUid: a.getAttribute?.("data-uid"),
817
817
  childUid: p.getAttribute?.("data-uid"),
818
- parent: i,
818
+ parent: a,
819
819
  child: p
820
820
  }), new Error("VDOM patch error: Attempted to insert a parent into its own child");
821
- i.insertBefore(p, i.childNodes[f] || null);
821
+ a.insertBefore(p, a.childNodes[u] || null);
822
822
  }
823
823
  }
824
824
  h.dom = p, p && d.push(p);
825
825
  }
826
- for (a.forEach((f) => {
827
- !c.has(f.key) && f.dom && i.contains(f.dom) && i.removeChild(f.dom);
828
- }); i.childNodes.length > o.length; )
829
- i.removeChild(i.lastChild);
830
- for (let f = 0; f < d.length; f++)
831
- if (i.childNodes[f] !== d[f]) {
832
- if ((d[f] instanceof Element || d[f] instanceof Node) && d[f].contains(i))
826
+ for (i.forEach((u) => {
827
+ !l.has(u.key) && u.dom && a.contains(u.dom) && a.removeChild(u.dom);
828
+ }); a.childNodes.length > s.length; )
829
+ a.removeChild(a.lastChild);
830
+ for (let u = 0; u < d.length; u++)
831
+ if (a.childNodes[u] !== d[u]) {
832
+ if ((d[u] instanceof Element || d[u] instanceof Node) && d[u].contains(a))
833
833
  throw new Error("VDOM patch error: Attempted to insert a parent into its own child");
834
- i.insertBefore(d[f], i.childNodes[f] || null);
834
+ a.insertBefore(d[u], a.childNodes[u] || null);
835
835
  }
836
- e.dom = i;
837
- const u = new Set(o.map((f) => f.key));
838
- Array.from(i.childNodes).forEach((f, h) => {
839
- const m = f.getAttribute?.("data-uid");
840
- (m && !u.has(m) || h >= o.length) && i.removeChild(f);
836
+ n.dom = a;
837
+ const f = new Set(s.map((u) => u.key));
838
+ Array.from(a.childNodes).forEach((u, h) => {
839
+ const m = u.getAttribute?.("data-uid");
840
+ (m && !f.has(m) || h >= s.length) && a.removeChild(u);
841
841
  });
842
842
  }
843
843
  }
844
- function M(r, t) {
845
- const e = [], n = t ? Object.keys(t) : [], a = { ...r };
846
- let o = null;
847
- function s(d) {
848
- return e.push(d), () => {
849
- const u = e.indexOf(d);
850
- u !== -1 && e.splice(u, 1);
844
+ function M(e, t) {
845
+ const n = [], r = t ? Object.keys(t) : [], i = { ...e };
846
+ let s = null;
847
+ function o(d) {
848
+ return n.push(d), () => {
849
+ const f = n.indexOf(d);
850
+ f !== -1 && n.splice(f, 1);
851
851
  };
852
852
  }
853
- function i(d) {
854
- Object.assign(o, d), e.forEach((u) => u(o));
855
- }
856
- const l = /* @__PURE__ */ new WeakMap();
857
- function c(d) {
858
- if (l.has(d)) return l.get(d);
859
- const u = new Proxy(d, {
860
- get(f, h, m) {
861
- if (h === "subscribe") return s;
862
- if (h === "set") return i;
863
- if (t && n.includes(h))
864
- return t[h](o);
865
- const p = Reflect.get(f, h, m);
866
- return typeof p == "object" && p !== null ? c(p) : p;
853
+ function a(d) {
854
+ Object.assign(s, d), n.forEach((f) => f(s));
855
+ }
856
+ const c = /* @__PURE__ */ new WeakMap();
857
+ function l(d) {
858
+ if (c.has(d)) return c.get(d);
859
+ const f = new Proxy(d, {
860
+ get(u, h, m) {
861
+ if (h === "subscribe") return o;
862
+ if (h === "set") return a;
863
+ if (t && r.includes(h))
864
+ return t[h](s);
865
+ const p = Reflect.get(u, h, m);
866
+ return typeof p == "object" && p !== null ? l(p) : p;
867
867
  },
868
- set(f, h, m, p) {
869
- if (t && n.includes(h))
868
+ set(u, h, m, p) {
869
+ if (t && r.includes(h))
870
870
  return !1;
871
- const A = f[h], E = Reflect.set(f, h, m, p);
872
- return A !== m && e.forEach((P) => P(o)), E;
871
+ const A = u[h], b = Reflect.set(u, h, m, p);
872
+ return A !== m && n.forEach((z) => z(s)), b;
873
873
  },
874
- deleteProperty(f, h) {
875
- if (t && n.includes(h))
874
+ deleteProperty(u, h) {
875
+ if (t && r.includes(h))
876
876
  return !1;
877
- const m = Reflect.deleteProperty(f, h);
878
- return e.forEach((p) => p(o)), m;
877
+ const m = Reflect.deleteProperty(u, h);
878
+ return n.forEach((p) => p(s)), m;
879
879
  }
880
880
  });
881
- return l.set(d, u), u;
881
+ return c.set(d, f), f;
882
882
  }
883
- return o = c(a), o;
883
+ return s = l(i), s;
884
884
  }
885
- const _ = [];
886
- function dt(r) {
887
- _.push(r);
885
+ const v = [];
886
+ function dt(e) {
887
+ v.push(e);
888
888
  }
889
- function b(r, t = /* @__PURE__ */ new WeakSet()) {
890
- if (r === null || typeof r != "object" || t.has(r)) return r;
891
- if (t.add(r), Array.isArray(r)) return r.map((a) => b(a, t));
892
- Object.getPrototypeOf(r) !== Object.prototype && Object.getPrototypeOf(r) !== null && Object.setPrototypeOf(r, null);
893
- const e = ["__proto__", "constructor", "prototype"], n = /* @__PURE__ */ Object.create(null);
894
- for (const a of Object.keys(r))
895
- e.includes(a) || (n[a] = b(r[a], t));
896
- return n;
889
+ function _(e, t = /* @__PURE__ */ new WeakSet()) {
890
+ if (e === null || typeof e != "object" || t.has(e)) return e;
891
+ if (t.add(e), Array.isArray(e)) return e.map((i) => _(i, t));
892
+ Object.getPrototypeOf(e) !== Object.prototype && Object.getPrototypeOf(e) !== null && Object.setPrototypeOf(e, null);
893
+ const n = ["__proto__", "constructor", "prototype"], r = /* @__PURE__ */ Object.create(null);
894
+ for (const i of Object.keys(e))
895
+ n.includes(i) || (r[i] = _(e[i], t));
896
+ return r;
897
897
  }
898
- function S(r) {
899
- return !!r && typeof r.then == "function";
898
+ function S(e) {
899
+ return !!e && typeof e.then == "function";
900
900
  }
901
- class J extends HTMLElement {
902
- /**
903
- * Allows updating the state object and triggers a re-render.
904
- * @param newState - Partial state to merge
905
- */
901
+ let P;
902
+ typeof HTMLElement < "u" && (P = class extends HTMLElement {
906
903
  /**
907
904
  * Syncs whitelisted state properties to attributes after render.
908
905
  * Only keys listed in config.reflect are reflected.
909
906
  */
910
907
  syncStateToAttributes() {
911
908
  if (!this.stateObj || !this.config?.reflect || !Array.isArray(this.config.reflect)) return;
912
- const t = ["__proto__", "constructor", "prototype"];
913
- this.config.reflect.forEach((e) => {
914
- if (t.includes(e)) {
915
- this.removeAttribute(e);
909
+ const e = ["__proto__", "constructor", "prototype"];
910
+ this.config.reflect.forEach((t) => {
911
+ if (e.includes(t)) {
912
+ this.removeAttribute(t);
916
913
  return;
917
914
  }
918
- const n = this.stateObj[e];
919
- ["string", "number", "boolean"].includes(typeof n) ? n == null ? this.removeAttribute(e) : this.setAttribute(e, String(n)) : this.removeAttribute(e);
915
+ const n = this.stateObj[t];
916
+ ["string", "number", "boolean"].includes(typeof n) ? n == null ? this.removeAttribute(t) : this.setAttribute(t, String(n)) : this.removeAttribute(t);
920
917
  });
921
918
  }
922
919
  /**
923
920
  * Allows updating the template function at runtime and triggers a re-render.
924
921
  * @param newTemplate - New template function or string
925
922
  */
926
- setTemplate(t) {
927
- const e = this.config;
928
- typeof t == "function" ? e.template = t : e.template = () => t, this.render();
923
+ setTemplate(e) {
924
+ const t = this.config;
925
+ typeof e == "function" ? t.template = e : t.template = () => e, this.render();
929
926
  }
930
927
  _hasError = !1;
931
928
  _mountedCalled = !1;
@@ -937,115 +934,115 @@ class J extends HTMLElement {
937
934
  /**
938
935
  * Override removeEventListener to support auto-wired config handler removal
939
936
  */
940
- removeEventListener(t, e, n) {
941
- super.removeEventListener(t, e, n), this._autoWiredHandlers[t] && (this._autoWiredHandlers[t] = this._autoWiredHandlers[t].filter((a) => a === e ? (super.removeEventListener(t, a, n), !1) : !0), this._autoWiredHandlers[t].length === 0 && delete this._autoWiredHandlers[t]);
937
+ removeEventListener(e, t, n) {
938
+ super.removeEventListener(e, t, n), this._autoWiredHandlers[e] && (this._autoWiredHandlers[e] = this._autoWiredHandlers[e].filter((r) => r === t ? (super.removeEventListener(e, r, n), !1) : !0), this._autoWiredHandlers[e].length === 0 && delete this._autoWiredHandlers[e]);
942
939
  }
943
940
  /**
944
941
  * observedAttributes automatically returns all primitive keys from static state.
945
942
  * This enables automatic attribute observation for all primitive state properties.
946
943
  */
947
944
  static get observedAttributes() {
948
- const t = this.stateObj || {};
949
- return Object.keys(t).filter(
950
- (e) => ["string", "number", "boolean"].includes(typeof t[e])
945
+ const e = this.stateObj || {};
946
+ return Object.keys(e).filter(
947
+ (t) => ["string", "number", "boolean"].includes(typeof e[t])
951
948
  );
952
949
  }
953
950
  /**
954
951
  * Called when an observed attribute changes. Syncs attribute to state and triggers render.
955
952
  */
956
- attributeChangedCallback(t, e, n) {
957
- if (!(t === "__proto__" || t === "constructor" || t === "prototype") && this.stateObj && t in this.stateObj) {
958
- const a = typeof this.config?.state?.[t];
959
- let o = n;
953
+ attributeChangedCallback(e, t, n) {
954
+ if (!(e === "__proto__" || e === "constructor" || e === "prototype") && this.stateObj && e in this.stateObj) {
955
+ const r = typeof this.config?.state?.[e];
956
+ let i = n;
960
957
  if (n === null)
961
- o = void 0;
962
- else if (a === "number")
963
- if (o === void 0 || o === "")
964
- o = this.config?.state?.[t];
958
+ i = void 0;
959
+ else if (r === "number")
960
+ if (i === void 0 || i === "")
961
+ i = this.config?.state?.[e];
965
962
  else {
966
- const s = Number(o);
967
- o = isNaN(s) ? this.config?.state?.[t] : s;
963
+ const s = Number(i);
964
+ i = isNaN(s) ? this.config?.state?.[e] : s;
968
965
  }
969
- else a === "boolean" && (o = o === "true");
970
- o = b(o), this.stateObj[t] !== o && (this.config?.debug && console.log("[runtime] state update:", { name: t, value: o }), this.stateObj[t] = o, this.render());
966
+ else r === "boolean" && (i = i === "true");
967
+ i = _(i), this.stateObj[e] !== i && (this.config?.debug && console.log("[runtime] state update:", { name: e, value: i }), this.stateObj[e] = i, this.render());
971
968
  }
972
969
  }
973
970
  /**
974
971
  * Force sync all controlled input values and event listeners after VDOM patching.
975
972
  */
976
973
  forceSyncControlledInputs() {
977
- this.shadowRoot && (this.shadowRoot.querySelectorAll("input[data-model]").forEach((t) => {
978
- const e = t.getAttribute("data-model");
979
- if (!e || !this.stateObj || typeof this.stateObj[e] > "u") return;
980
- const n = t, a = String(this.stateObj[e]), o = document.activeElement === n;
974
+ this.shadowRoot && (this.shadowRoot.querySelectorAll("input[data-model]").forEach((e) => {
975
+ const t = e.getAttribute("data-model");
976
+ if (!t || !this.stateObj || typeof this.stateObj[t] > "u") return;
977
+ const n = e, r = String(this.stateObj[t]), i = document.activeElement === n;
981
978
  n._hasDirtyListener || (n.addEventListener("input", () => {
982
979
  n._isDirty = !0;
983
980
  }), n.addEventListener("blur", () => {
984
981
  n._isDirty = !1;
985
982
  }), n._hasDirtyListener = !0);
986
983
  const s = !!n._isDirty;
987
- o || s || n.type !== "radio" && n.type !== "checkbox" && n.value !== a && (n.value = a);
984
+ i || s || n.type !== "radio" && n.type !== "checkbox" && n.value !== r && (n.value = r);
988
985
  }), this.rebindEventListeners());
989
986
  }
990
987
  /**
991
988
  * Sync all controlled inputs and event listeners after render
992
989
  */
993
990
  syncControlledInputsAndEvents() {
994
- this.shadowRoot && (this.shadowRoot.querySelectorAll('input[type="radio"][data-model]').forEach((t) => {
995
- const e = t.getAttribute("data-model");
996
- if (!e || !this.stateObj || typeof this.stateObj[e] > "u")
991
+ this.shadowRoot && (this.shadowRoot.querySelectorAll('input[type="radio"][data-model]').forEach((e) => {
992
+ const t = e.getAttribute("data-model");
993
+ if (!t || !this.stateObj || typeof this.stateObj[t] > "u")
997
994
  return;
998
- const n = t, a = String(this.stateObj[e]);
999
- n.checked = n.value === a;
1000
- }), this.shadowRoot.querySelectorAll("input[data-model]").forEach((t) => {
1001
- const e = t.getAttribute("data-model");
1002
- if (!e || !this.stateObj || typeof this.stateObj[e] > "u") return;
1003
- const n = t, a = String(this.stateObj[e]);
995
+ const n = e, r = String(this.stateObj[t]);
996
+ n.checked = n.value === r;
997
+ }), this.shadowRoot.querySelectorAll("input[data-model]").forEach((e) => {
998
+ const t = e.getAttribute("data-model");
999
+ if (!t || !this.stateObj || typeof this.stateObj[t] > "u") return;
1000
+ const n = e, r = String(this.stateObj[t]);
1004
1001
  if (n.type === "checkbox") {
1005
- const o = this.stateObj[e];
1006
- if (Array.isArray(o))
1007
- n.checked = o.includes(n.value);
1002
+ const i = this.stateObj[t];
1003
+ if (Array.isArray(i))
1004
+ n.checked = i.includes(n.value);
1008
1005
  else {
1009
- const s = n.getAttribute("data-true-value"), i = n.getAttribute("data-false-value");
1010
- s !== null || i !== null ? String(o) === s ? n.checked = !0 : String(o) === i ? n.checked = !1 : o === !0 ? n.checked = !0 : n.checked = !1 : n.checked = o === !0 || o === "true" || o === 1;
1006
+ const s = n.getAttribute("data-true-value"), o = n.getAttribute("data-false-value");
1007
+ s !== null || o !== null ? String(i) === s ? n.checked = !0 : String(i) === o ? n.checked = !1 : i === !0 ? n.checked = !0 : n.checked = !1 : n.checked = i === !0 || i === "true" || i === 1;
1011
1008
  }
1012
- } else n.type === "radio" || (n.value = a);
1013
- }), this.shadowRoot.querySelectorAll("textarea[data-model]").forEach((t) => {
1014
- const e = t.getAttribute("data-model");
1015
- !e || !this.stateObj || typeof this.stateObj[e] > "u" || (t.value = String(this.stateObj[e]));
1016
- }), this.shadowRoot.querySelectorAll("select[data-model]").forEach((t) => {
1017
- const e = t.getAttribute("data-model");
1018
- !e || !this.stateObj || typeof this.stateObj[e] > "u" || (t.value = String(this.stateObj[e]));
1009
+ } else n.type === "radio" || (n.value = r);
1010
+ }), this.shadowRoot.querySelectorAll("textarea[data-model]").forEach((e) => {
1011
+ const t = e.getAttribute("data-model");
1012
+ !t || !this.stateObj || typeof this.stateObj[t] > "u" || (e.value = String(this.stateObj[t]));
1013
+ }), this.shadowRoot.querySelectorAll("select[data-model]").forEach((e) => {
1014
+ const t = e.getAttribute("data-model");
1015
+ !t || !this.stateObj || typeof this.stateObj[t] > "u" || (e.value = String(this.stateObj[t]));
1019
1016
  }));
1020
1017
  }
1021
1018
  /**
1022
1019
  * Attach event listeners for input[data-bind] after VDOM patching
1023
1020
  */
1024
1021
  attachListItemModelListeners() {
1025
- this.shadowRoot && this.shadowRoot.querySelectorAll("input[data-bind]").forEach((t) => {
1026
- const e = t.getAttribute("data-bind");
1027
- if (!e) return;
1028
- t._listItemModelListener && (t.removeEventListener("input", t._listItemModelListener), t.removeEventListener("change", t._listItemModelListener), delete t._listItemModelListener);
1029
- const n = e.match(/^([a-zA-Z0-9_]+)\[(\d+)\]\.([a-zA-Z0-9_]+)$/);
1022
+ this.shadowRoot && this.shadowRoot.querySelectorAll("input[data-bind]").forEach((e) => {
1023
+ const t = e.getAttribute("data-bind");
1024
+ if (!t) return;
1025
+ e._listItemModelListener && (e.removeEventListener("input", e._listItemModelListener), e.removeEventListener("change", e._listItemModelListener), delete e._listItemModelListener);
1026
+ const n = t.match(/^([a-zA-Z0-9_]+)\[(\d+)\]\.([a-zA-Z0-9_]+)$/);
1030
1027
  if (n) {
1031
- const [, o, s, i] = n, l = parseInt(s, 10), c = this.stateObj[o];
1032
- t instanceof HTMLInputElement && t.type === "checkbox" && (t.checked = !!(Array.isArray(c) && c[l] && c[l][i]));
1033
- const d = (u) => {
1034
- !Array.isArray(c) || !c[l] || (t instanceof HTMLInputElement && t.type === "checkbox" ? c[l][i] = t.checked : c[l][i] = t.value);
1028
+ const [, i, s, o] = n, a = parseInt(s, 10), c = this.stateObj[i];
1029
+ e instanceof HTMLInputElement && e.type === "checkbox" && (e.checked = !!(Array.isArray(c) && c[a] && c[a][o]));
1030
+ const l = (d) => {
1031
+ !Array.isArray(c) || !c[a] || (e instanceof HTMLInputElement && e.type === "checkbox" ? c[a][o] = e.checked : c[a][o] = e.value);
1035
1032
  };
1036
- t.addEventListener("input", d), t.addEventListener("change", d), t._listItemModelListener = d;
1033
+ e.addEventListener("input", l), e.addEventListener("change", l), e._listItemModelListener = l;
1037
1034
  return;
1038
1035
  }
1039
- const a = e.match(/^([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)((?:\|[a-zA-Z0-9_]+)*)$/);
1040
- if (a) {
1041
- const [, o, s, i] = a, l = this.stateObj[o], c = i ? i.split("|").map((u) => u.trim()).filter(Boolean) : [];
1042
- t instanceof HTMLInputElement && t.type === "checkbox" ? t.checked = !!(l && l[s]) : t instanceof HTMLInputElement && (t.value = l ? String(l[s] ?? "") : "");
1043
- const d = (u) => {
1044
- if (!l) return;
1036
+ const r = t.match(/^([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)((?:\|[a-zA-Z0-9_]+)*)$/);
1037
+ if (r) {
1038
+ const [, i, s, o] = r, a = this.stateObj[i], c = o ? o.split("|").map((d) => d.trim()).filter(Boolean) : [];
1039
+ e instanceof HTMLInputElement && e.type === "checkbox" ? e.checked = !!(a && a[s]) : e instanceof HTMLInputElement && (e.value = a ? String(a[s] ?? "") : "");
1040
+ const l = (d) => {
1041
+ if (!a) return;
1045
1042
  let f;
1046
- t instanceof HTMLInputElement && t.type === "checkbox" ? f = t.checked : (f = t.value, c.includes("number") && (f = Number(f)), c.includes("trim") && typeof f == "string" && (f = f.trim())), l[s] = f;
1043
+ e instanceof HTMLInputElement && e.type === "checkbox" ? f = e.checked : (f = e.value, c.includes("number") && (f = Number(f)), c.includes("trim") && typeof f == "string" && (f = f.trim())), a[s] = f;
1047
1044
  };
1048
- t.addEventListener("input", d), t.addEventListener("change", d), t._listItemModelListener = d;
1045
+ e.addEventListener("input", l), e.addEventListener("change", l), e._listItemModelListener = l;
1049
1046
  }
1050
1047
  });
1051
1048
  }
@@ -1053,19 +1050,19 @@ class J extends HTMLElement {
1053
1050
  * Attach controlled input listeners to sync DOM value to state
1054
1051
  */
1055
1052
  attachControlledInputListeners() {
1056
- const t = this.shadowRoot;
1057
- t && (t.querySelectorAll("[data-model]").forEach((e) => {
1058
- const n = e.getAttribute("data-model");
1059
- n && (e._dataModelBound || (G(e, this.stateObj, n), e._dataModelBound = !0));
1060
- }), t.querySelectorAll("[data-model]").forEach((e) => {
1061
- const [n] = e.getAttribute("data-model")?.split("|").map((a) => a.trim()) ?? [];
1053
+ const e = this.shadowRoot;
1054
+ e && (e.querySelectorAll("[data-model]").forEach((t) => {
1055
+ const n = t.getAttribute("data-model");
1056
+ n && (t._dataModelBound || (U(t, this.stateObj, n), t._dataModelBound = !0));
1057
+ }), e.querySelectorAll("[data-model]").forEach((t) => {
1058
+ const [n] = t.getAttribute("data-model")?.split("|").map((r) => r.trim()) ?? [];
1062
1059
  if (!(!n || !(n in this.stateObj)))
1063
- if (e instanceof HTMLInputElement)
1064
- if (e.type === "checkbox") {
1065
- const a = this.stateObj[n], o = e.getAttribute("data-true-value"), s = e.getAttribute("data-false-value");
1066
- Array.isArray(a) ? e.checked = a.includes(e.value) : o !== null || s !== null ? String(a) === o ? e.checked = !0 : String(a) === s ? e.checked = !1 : a === !0 ? e.checked = !0 : e.checked = !1 : e.checked = a === !0 || a === "true" || a === 1;
1067
- } else e.type === "radio" ? e.checked = e.value === String(this.stateObj[n]) : e.value = String(this.stateObj[n] ?? "");
1068
- else (e instanceof HTMLTextAreaElement || e instanceof HTMLSelectElement) && (e.value = String(this.stateObj[n] ?? ""));
1060
+ if (t instanceof HTMLInputElement)
1061
+ if (t.type === "checkbox") {
1062
+ const r = this.stateObj[n], i = t.getAttribute("data-true-value"), s = t.getAttribute("data-false-value");
1063
+ Array.isArray(r) ? t.checked = r.includes(t.value) : i !== null || s !== null ? String(r) === i ? t.checked = !0 : String(r) === s ? t.checked = !1 : r === !0 ? t.checked = !0 : t.checked = !1 : t.checked = r === !0 || r === "true" || r === 1;
1064
+ } else t.type === "radio" ? t.checked = t.value === String(this.stateObj[n]) : t.value = String(this.stateObj[n] ?? "");
1065
+ else (t instanceof HTMLTextAreaElement || t instanceof HTMLSelectElement) && (t.value = String(this.stateObj[n] ?? ""));
1069
1066
  }));
1070
1067
  }
1071
1068
  config;
@@ -1085,31 +1082,31 @@ class J extends HTMLElement {
1085
1082
  }
1086
1083
  initializeConfig() {
1087
1084
  if (this.config) return;
1088
- const t = this.tagName.toLowerCase(), n = (window.__componentRegistry || {})[t];
1085
+ const e = this.tagName.toLowerCase(), n = (window.__componentRegistry || {})[e];
1089
1086
  if (!n || typeof n != "object")
1090
1087
  throw new Error("Invalid component config: must be an object");
1091
1088
  if (!n.state || typeof n.state != "object")
1092
1089
  throw new Error("Invalid component config: state must be an object");
1093
1090
  this.config = n;
1094
- const a = n.computed ? M(n.state, n.computed) : M(n.state);
1095
- if (this.stateObj = a, typeof this.stateObj.subscribe == "function" && this.unsubscribes.push(this.stateObj.subscribe(() => {
1091
+ const r = n.computed ? M(n.state, n.computed) : M(n.state);
1092
+ if (this.stateObj = r, typeof this.stateObj.subscribe == "function" && this.unsubscribes.push(this.stateObj.subscribe(() => {
1096
1093
  this.scheduleRender();
1097
1094
  })), this.api = {
1098
1095
  state: this.stateObj,
1099
- emit: (s, i) => this.dispatchEvent(new CustomEvent(s, { detail: i, bubbles: !0 })),
1100
- onGlobal: (s, i) => {
1101
- const l = C.on(s, i);
1102
- return this._globalUnsubscribes.push(l), l;
1096
+ emit: (s, o) => this.dispatchEvent(new CustomEvent(s, { detail: o, bubbles: !0 })),
1097
+ onGlobal: (s, o) => {
1098
+ const a = C.on(s, o);
1099
+ return this._globalUnsubscribes.push(a), a;
1103
1100
  },
1104
- offGlobal: (s, i) => C.off(s, i),
1105
- emitGlobal: (s, i) => C.emit(s, i)
1101
+ offGlobal: (s, o) => C.off(s, o),
1102
+ emitGlobal: (s, o) => C.emit(s, o)
1106
1103
  }, Object.keys(this.config).forEach((s) => {
1107
1104
  if (s.startsWith("on") && s.length > 2 && typeof this.config[s] == "function") {
1108
- const i = s.charAt(2).toLowerCase() + s.slice(3), l = (c) => {
1109
- const d = c.detail ?? c;
1110
- this.config[s](d, this.api.state, this.api);
1105
+ const o = s.charAt(2).toLowerCase() + s.slice(3), a = (c) => {
1106
+ const l = c.detail ?? c;
1107
+ this.config[s](l, this.api.state, this.api);
1111
1108
  };
1112
- this.addEventListener(i, l), this._autoWiredHandlers[i] || (this._autoWiredHandlers[i] = []), this._autoWiredHandlers[i].push(l);
1109
+ this.addEventListener(o, a), this._autoWiredHandlers[o] || (this._autoWiredHandlers[o] = []), this._autoWiredHandlers[o].push(a);
1113
1110
  }
1114
1111
  }), this.attachShadow({ mode: "open" }), n.style) {
1115
1112
  const s = document.createElement("style");
@@ -1118,22 +1115,22 @@ class J extends HTMLElement {
1118
1115
  if (typeof this.config.hydrate == "function") {
1119
1116
  const s = this.shadowRoot?.querySelectorAll("[data-hydrate]");
1120
1117
  try {
1121
- s && s.length > 0 ? s.forEach((i) => {
1118
+ s && s.length > 0 ? s.forEach((o) => {
1122
1119
  try {
1123
- this.config.hydrate(i, this.stateObj, this.api);
1124
- } catch (l) {
1125
- typeof this.config.onError == "function" && this.config.onError(l instanceof Error ? l : new Error(String(l)), this.api.state, this.api), this._handleRenderError(l);
1120
+ this.config.hydrate(o, this.stateObj, this.api);
1121
+ } catch (a) {
1122
+ typeof this.config.onError == "function" && this.config.onError(a instanceof Error ? a : new Error(String(a)), this.api.state, this.api), this._handleRenderError(a);
1126
1123
  }
1127
1124
  }) : this.config.hydrate(this.shadowRoot, this.stateObj, this.api);
1128
- } catch (i) {
1129
- typeof this.config.onError == "function" && this.config.onError(i instanceof Error ? i : new Error(String(i)), this.api.state, this.api), this._handleRenderError(i);
1125
+ } catch (o) {
1126
+ typeof this.config.onError == "function" && this.config.onError(o instanceof Error ? o : new Error(String(o)), this.api.state, this.api), this._handleRenderError(o);
1130
1127
  }
1131
1128
  }
1132
1129
  if (this.hasAttribute("data-hydrated") ? this.processRefs() : this.render(), !this._mountedCalled && typeof this.config.onMounted == "function")
1133
1130
  try {
1134
1131
  const s = this.config.onMounted(this.api.state, this.api);
1135
- S(s) ? s.catch((i) => {
1136
- typeof this.config.onError == "function" && this.config.onError(i, this.api.state, this.api), this._handleRenderError(i);
1132
+ S(s) ? s.catch((o) => {
1133
+ typeof this.config.onError == "function" && this.config.onError(o, this.api.state, this.api), this._handleRenderError(o);
1137
1134
  }).finally(() => {
1138
1135
  this._mountedCalled = !0;
1139
1136
  }) : this._mountedCalled = !0;
@@ -1143,23 +1140,23 @@ class J extends HTMLElement {
1143
1140
  }
1144
1141
  connectedCallback() {
1145
1142
  if (this.initializeConfig(), this.stateObj) {
1146
- for (const t of this.getAttributeNames())
1147
- if (t in this.stateObj) {
1148
- const e = typeof this.config?.state?.[t];
1149
- let n = this.getAttribute(t);
1150
- e === "number" ? n = Number(n) : e === "boolean" && (n = n === "true"), this.stateObj[t] = n === null ? void 0 : n;
1143
+ for (const e of this.getAttributeNames())
1144
+ if (e in this.stateObj) {
1145
+ const t = typeof this.config?.state?.[e];
1146
+ let n = this.getAttribute(e);
1147
+ t === "number" ? n = Number(n) : t === "boolean" && (n = n === "true"), this.stateObj[e] = n === null ? void 0 : n;
1151
1148
  }
1152
1149
  }
1153
1150
  if (!this._mountedCalled && typeof this.config.onMounted == "function")
1154
1151
  try {
1155
- const t = this.config.onMounted(this.api.state, this.api);
1156
- S(t) ? t.catch((e) => {
1157
- typeof this.config.onError == "function" && this.config.onError(e, this.api.state, this.api), this._handleRenderError(e);
1152
+ const e = this.config.onMounted(this.api.state, this.api);
1153
+ S(e) ? e.catch((t) => {
1154
+ typeof this.config.onError == "function" && this.config.onError(t, this.api.state, this.api), this._handleRenderError(t);
1158
1155
  }).finally(() => {
1159
1156
  this._mountedCalled = !0;
1160
1157
  }) : this._mountedCalled = !0;
1161
- } catch (t) {
1162
- typeof this.config.onError == "function" && this.config.onError(t, this.api.state, this.api), this._handleRenderError(t), this._mountedCalled = !0;
1158
+ } catch (e) {
1159
+ typeof this.config.onError == "function" && this.config.onError(e, this.api.state, this.api), this._handleRenderError(e), this._mountedCalled = !0;
1163
1160
  }
1164
1161
  typeof this.render == "function" && this.render();
1165
1162
  }
@@ -1167,20 +1164,20 @@ class J extends HTMLElement {
1167
1164
  * Lifecycle: called when element is removed from DOM.
1168
1165
  */
1169
1166
  disconnectedCallback() {
1170
- if (Object.entries(this._autoWiredHandlers).forEach(([t, e]) => {
1171
- e.forEach((n) => {
1172
- super.removeEventListener(t, n);
1167
+ if (Object.entries(this._autoWiredHandlers).forEach(([e, t]) => {
1168
+ t.forEach((n) => {
1169
+ super.removeEventListener(e, n);
1173
1170
  });
1174
- }), this._autoWiredHandlers = {}, this.unsubscribes.forEach((t) => t()), this.unsubscribes = [], this._globalUnsubscribes.forEach((t) => t()), this._globalUnsubscribes = [], !this._unmountedCalled && typeof this.config.onUnmounted == "function")
1171
+ }), this._autoWiredHandlers = {}, this.unsubscribes.forEach((e) => e()), this.unsubscribes = [], this._globalUnsubscribes.forEach((e) => e()), this._globalUnsubscribes = [], !this._unmountedCalled && typeof this.config.onUnmounted == "function")
1175
1172
  try {
1176
- const t = this.config.onUnmounted(this.api.state, this.api);
1177
- S(t) ? t.catch((e) => {
1178
- typeof this.config.onError == "function" && this.config.onError(e, this.api.state, this.api), this._handleRenderError(e);
1173
+ const e = this.config.onUnmounted(this.api.state, this.api);
1174
+ S(e) ? e.catch((t) => {
1175
+ typeof this.config.onError == "function" && this.config.onError(t, this.api.state, this.api), this._handleRenderError(t);
1179
1176
  }).finally(() => {
1180
1177
  this._unmountedCalled = !0;
1181
1178
  }) : this._unmountedCalled = !0;
1182
- } catch (t) {
1183
- typeof this.config.onError == "function" && this.config.onError(t, this.api.state, this.api), this._handleRenderError(t), this._unmountedCalled = !0;
1179
+ } catch (e) {
1180
+ typeof this.config.onError == "function" && this.config.onError(e, this.api.state, this.api), this._handleRenderError(e), this._unmountedCalled = !0;
1184
1181
  }
1185
1182
  this._mountedCalled = !1, this._unmountedCalled = !1;
1186
1183
  }
@@ -1190,27 +1187,27 @@ class J extends HTMLElement {
1190
1187
  render() {
1191
1188
  this._hasError = !1, this.syncControlledInputsAndEvents(), setTimeout(() => this.attachControlledInputListeners(), 0);
1192
1189
  try {
1193
- _.forEach((e) => {
1190
+ v.forEach((t) => {
1194
1191
  try {
1195
- e.onRender?.(this.stateObj, this.api);
1192
+ t.onRender?.(this.stateObj, this.api);
1196
1193
  } catch (n) {
1197
1194
  this._handleRenderError(n);
1198
1195
  }
1199
- }), this.config.computed && Object.values(this.config.computed).forEach((e) => {
1196
+ }), this.config.computed && Object.values(this.config.computed).forEach((t) => {
1200
1197
  try {
1201
- e(this.stateObj);
1198
+ t(this.stateObj);
1202
1199
  } catch (n) {
1203
1200
  this._handleRenderError(n);
1204
1201
  }
1205
1202
  });
1206
- const t = this.config.template(this.stateObj, this.api);
1207
- t instanceof Promise ? t.then((e) => {
1208
- this._hasError || (this._renderTemplateResult(e), this.syncStateToAttributes(), setTimeout(() => this.attachListItemModelListeners(), 0));
1209
- }).catch((e) => {
1210
- this._handleRenderError(e);
1211
- }) : this._hasError || (this._renderTemplateResult(t), this.syncStateToAttributes(), setTimeout(() => this.attachListItemModelListeners(), 0));
1212
- } catch (t) {
1213
- this._handleRenderError(t), this.renderError(t instanceof Error ? t : new Error(String(t)));
1203
+ const e = this.config.template(this.stateObj, this.api);
1204
+ e instanceof Promise ? e.then((t) => {
1205
+ this._hasError || (this._renderTemplateResult(t), this.syncStateToAttributes(), setTimeout(() => this.attachListItemModelListeners(), 0));
1206
+ }).catch((t) => {
1207
+ this._handleRenderError(t);
1208
+ }) : this._hasError || (this._renderTemplateResult(e), this.syncStateToAttributes(), setTimeout(() => this.attachListItemModelListeners(), 0));
1209
+ } catch (e) {
1210
+ this._handleRenderError(e), this.renderError(e instanceof Error ? e : new Error(String(e)));
1214
1211
  }
1215
1212
  }
1216
1213
  /**
@@ -1222,16 +1219,16 @@ class J extends HTMLElement {
1222
1219
  */
1223
1220
  rebindEventListeners() {
1224
1221
  if (!this.shadowRoot) return;
1225
- ["data-on-input", "data-on-change", "data-on-blur", "data-on-click"].forEach((e) => {
1226
- this.shadowRoot.querySelectorAll(`[${e}]`).forEach((n) => {
1227
- const a = e.replace("data-on-", ""), o = n.getAttribute(e);
1228
- if (!o || typeof this.config[o] != "function") return;
1229
- n._boundHandlers && n._boundHandlers[a] && n.removeEventListener(a, n._boundHandlers[a]);
1230
- const s = this.config[o], i = (l) => s.call(this, l);
1231
- n.addEventListener(a, i), n._boundHandlers || (n._boundHandlers = {}), n._boundHandlers[a] = i;
1222
+ ["data-on-input", "data-on-change", "data-on-blur", "data-on-click"].forEach((t) => {
1223
+ this.shadowRoot.querySelectorAll(`[${t}]`).forEach((n) => {
1224
+ const r = t.replace("data-on-", ""), i = n.getAttribute(t);
1225
+ if (!i || typeof this.config[i] != "function") return;
1226
+ n._boundHandlers && n._boundHandlers[r] && n.removeEventListener(r, n._boundHandlers[r]);
1227
+ const s = this.config[i], o = (a) => s.call(this, a);
1228
+ n.addEventListener(r, o), n._boundHandlers || (n._boundHandlers = {}), n._boundHandlers[r] = o;
1232
1229
  });
1233
- }), Array.from(this.shadowRoot.children).forEach((e) => {
1234
- e instanceof HTMLElement && typeof e.rebindEventListeners == "function" && e.rebindEventListeners();
1230
+ }), Array.from(this.shadowRoot.children).forEach((t) => {
1231
+ t instanceof HTMLElement && typeof t.rebindEventListeners == "function" && t.rebindEventListeners();
1235
1232
  });
1236
1233
  }
1237
1234
  /**
@@ -1239,66 +1236,65 @@ class J extends HTMLElement {
1239
1236
  * Handles VDOM patching, style updates, refs, and event binding.
1240
1237
  * @param templateResult - HTML string or compiled template
1241
1238
  */
1242
- _renderTemplateResult(t) {
1239
+ _renderTemplateResult(e) {
1243
1240
  if (!this._hasError)
1244
1241
  try {
1245
- let e = function(n) {
1246
- const a = /* @__PURE__ */ new WeakSet();
1247
- function o(s) {
1248
- if (s === null || typeof s != "object") return s;
1249
- if (a.has(s)) return;
1250
- if (a.add(s), Array.isArray(s)) return s.map(o);
1251
- const i = {};
1252
- for (const l in s)
1253
- Object.prototype.hasOwnProperty.call(s, l) && (i[l] = o(s[l]));
1254
- return i;
1242
+ let t = function(n) {
1243
+ const r = /* @__PURE__ */ new WeakSet();
1244
+ function i(s) {
1245
+ if (s === null || typeof s != "object" || r.has(s)) return s;
1246
+ if (r.add(s), Array.isArray(s)) return s.map(i);
1247
+ const o = {};
1248
+ for (const a in s)
1249
+ Object.prototype.hasOwnProperty.call(s, a) && (o[a] = i(s[a]));
1250
+ return o;
1255
1251
  }
1256
- return o(n);
1252
+ return i(n);
1257
1253
  };
1258
- if (typeof t == "string") {
1254
+ if (typeof e == "string") {
1259
1255
  let n = function(c) {
1260
- return c.replace(/<([a-zA-Z0-9]+)([^>]*)>/g, (d, u, f) => {
1261
- const h = f.replace(/\s+on[a-zA-Z]+\s*=\s*(['"][^'"]*['"]|[^\s>]*)/gi, "");
1262
- return `<${u}${h}>`;
1256
+ return c.replace(/<([a-zA-Z0-9]+)([^>]*)>/g, (l, d, f) => {
1257
+ const u = f.replace(/\s+on[a-zA-Z]+\s*=\s*(['"][^'"]*['"]|[^\s>]*)/gi, "");
1258
+ return `<${d}${u}>`;
1263
1259
  });
1264
- }, a = function(c) {
1265
- c.children.forEach(a);
1260
+ }, r = function(c) {
1261
+ c.children.forEach(r);
1266
1262
  };
1267
- const o = n(t), s = Y(o);
1268
- a(s);
1269
- const i = this.shadowRoot;
1270
- if (!i)
1263
+ const i = n(e), s = J(i);
1264
+ r(s);
1265
+ const o = this.shadowRoot;
1266
+ if (!o)
1271
1267
  return;
1272
- let l = i.querySelector("style");
1273
- if (l || (l = document.createElement("style"), i.appendChild(l)), this.config.style ? l.textContent = typeof this.config.style == "function" ? this.config.style(this.stateObj) : this.config.style : l.textContent = "", s.type === "#fragment") {
1274
- const c = Array.from(i.childNodes).find(
1275
- (d) => d.nodeType === 1 && d !== l
1268
+ let a = o.querySelector("style");
1269
+ if (a || (a = document.createElement("style"), o.appendChild(a)), this.config.style ? a.textContent = typeof this.config.style == "function" ? this.config.style(this.stateObj) : this.config.style : a.textContent = "", s.type === "#fragment") {
1270
+ const c = Array.from(o.childNodes).find(
1271
+ (l) => l.nodeType === 1 && l !== a
1276
1272
  );
1277
1273
  if (c) {
1278
1274
  Array.from(c.childNodes).forEach((f) => {
1279
1275
  f.nodeType === 1 && f.nodeName === "STYLE" || c.removeChild(f);
1280
1276
  });
1281
- const d = {
1277
+ const l = {
1282
1278
  type: "#fragment",
1283
1279
  dom: c,
1284
1280
  children: s.children,
1285
1281
  props: {},
1286
1282
  key: void 0
1287
- }, u = this._prevVNode && this._prevVNode.type === "#fragment" ? { ...this._prevVNode, dom: c } : d;
1288
- L(c, u, d);
1283
+ }, d = this._prevVNode && this._prevVNode.type === "#fragment" ? { ...this._prevVNode, dom: c } : l;
1284
+ L(c, d, l);
1289
1285
  } else
1290
- s.children.forEach((d) => {
1291
- const u = g(d);
1292
- u && i.appendChild(u), d.dom = u ?? void 0;
1286
+ s.children.forEach((l) => {
1287
+ const d = g(l);
1288
+ d && o.appendChild(d), l.dom = d ?? void 0;
1293
1289
  });
1294
1290
  } else {
1295
1291
  let c = Array.from(this.shadowRoot.childNodes).find(
1296
- (d) => d !== l && d.nodeType === 1
1292
+ (l) => l !== a && l.nodeType === 1
1297
1293
  );
1298
1294
  if (c)
1299
1295
  if (this._prevVNode && (this._prevVNode.type !== s.type || this._prevVNode.key !== s.key)) {
1300
- const d = g(s);
1301
- d && (this.shadowRoot.contains(c) && this.shadowRoot.replaceChild(d, c), c = d);
1296
+ const l = g(s);
1297
+ l && (this.shadowRoot.contains(c) && this.shadowRoot.replaceChild(l, c), c = l);
1302
1298
  } else
1303
1299
  L(c, this._prevVNode, s);
1304
1300
  else
@@ -1307,27 +1303,27 @@ class J extends HTMLElement {
1307
1303
  }
1308
1304
  this._prevVNode = s, this.forceSyncControlledInputs(), this.lastCompiledTemplate = null;
1309
1305
  } else {
1310
- const n = !this.shadowRoot.firstElementChild, a = this.lastCompiledTemplate?.id === t.id;
1306
+ const n = !this.shadowRoot.firstElementChild, r = this.lastCompiledTemplate?.id === e.id;
1311
1307
  if (n) {
1312
- const o = j(t, this.stateObj, this.api);
1313
- this.shadowRoot.appendChild(o);
1314
- } else if (a && this.shadowRoot.firstElementChild) {
1315
- const o = this.lastState;
1316
- X(t, this.shadowRoot.firstElementChild, this.stateObj, this.api, o || void 0);
1308
+ const i = j(e, this.stateObj, this.api);
1309
+ this.shadowRoot.appendChild(i);
1310
+ } else if (r && this.shadowRoot.firstElementChild) {
1311
+ const i = this.lastState;
1312
+ V(e, this.shadowRoot.firstElementChild, this.stateObj, this.api, i || void 0);
1317
1313
  } else {
1318
- const o = j(t, this.stateObj, this.api);
1314
+ const i = j(e, this.stateObj, this.api);
1319
1315
  let s = this.shadowRoot.querySelector("style");
1320
1316
  s || (s = document.createElement("style"), this.shadowRoot.insertBefore(s, this.shadowRoot.firstChild)), this.config.style ? s.textContent = typeof this.config.style == "function" ? this.config.style(this.stateObj) : this.config.style : s.textContent = "";
1321
- let i = this.shadowRoot.querySelector("[data-root]");
1322
- for (i || (i = document.createElement("div"), i.setAttribute("data-root", ""), this.shadowRoot.appendChild(i)); i.firstChild; )
1323
- i.removeChild(i.firstChild);
1324
- i.appendChild(o);
1317
+ let o = this.shadowRoot.querySelector("[data-root]");
1318
+ for (o || (o = document.createElement("div"), o.setAttribute("data-root", ""), this.shadowRoot.appendChild(o)); o.firstChild; )
1319
+ o.removeChild(o.firstChild);
1320
+ o.appendChild(i);
1325
1321
  }
1326
- this.lastCompiledTemplate = t;
1322
+ this.lastCompiledTemplate = e;
1327
1323
  }
1328
- this.lastState = e(this.stateObj), this.updateStyle(), this.processRefs(), this.bindEvents(), this.syncControlledInputsAndEvents();
1329
- } catch (e) {
1330
- this._handleRenderError(e);
1324
+ this.lastState = t(this.stateObj), this.updateStyle(), this.processRefs(), this.bindEvents(), this.syncControlledInputsAndEvents();
1325
+ } catch (t) {
1326
+ this._handleRenderError(t);
1331
1327
  }
1332
1328
  }
1333
1329
  /**
@@ -1335,14 +1331,14 @@ class J extends HTMLElement {
1335
1331
  * Logs details and allows fallback UI.
1336
1332
  * @param error - Error object
1337
1333
  */
1338
- _handleRenderError(t) {
1339
- if (this._hasError = !0, this.config.debug && console.error(`[runtime] Render error in <${this.tagName.toLowerCase()}>:`, t), _.forEach((e) => e.onError?.(t instanceof Error ? t : new Error(String(t)), this.stateObj, this.api)), "onError" in this.config && typeof this.config.onError == "function")
1334
+ _handleRenderError(e) {
1335
+ if (this._hasError = !0, this.config.debug && console.error(`[runtime] Render error in <${this.tagName.toLowerCase()}>:`, e), v.forEach((t) => t.onError?.(e instanceof Error ? e : new Error(String(e)), this.stateObj, this.api)), "onError" in this.config && typeof this.config.onError == "function")
1340
1336
  try {
1341
- this.config.onError(t instanceof Error ? t : new Error(String(t)), this.api.state, this.api);
1342
- } catch (e) {
1343
- this.config.debug && console.error("[runtime] Error in onError handler:", e);
1337
+ this.config.onError(e instanceof Error ? e : new Error(String(e)), this.api.state, this.api);
1338
+ } catch (t) {
1339
+ this.config.debug && console.error("[runtime] Error in onError handler:", t);
1344
1340
  }
1345
- this.renderError(t instanceof Error ? t : new Error(String(t)));
1341
+ this.renderError(e instanceof Error ? e : new Error(String(e)));
1346
1342
  }
1347
1343
  /**
1348
1344
  * Schedule a render using requestAnimationFrame, batching multiple state changes.
@@ -1356,30 +1352,30 @@ class J extends HTMLElement {
1356
1352
  * Updates the style element in the shadow root based on the current state.
1357
1353
  */
1358
1354
  updateStyle() {
1359
- const t = this.shadowRoot.querySelector("style");
1360
- if (!t || !this.config.style) return;
1361
- const e = typeof this.config.style == "function" ? this.config.style(this.api.state) : this.config.style;
1362
- t.textContent = e;
1355
+ const e = this.shadowRoot.querySelector("style");
1356
+ if (!e || !this.config.style) return;
1357
+ const t = typeof this.config.style == "function" ? this.config.style(this.api.state) : this.config.style;
1358
+ e.textContent = t;
1363
1359
  }
1364
1360
  /**
1365
1361
  * Processes and attaches ref handlers for elements with data-ref attributes.
1366
1362
  */
1367
1363
  processRefs() {
1368
1364
  if (!this.config.refs) return;
1369
- const t = /* @__PURE__ */ new WeakMap();
1370
- Object.entries(this.config.refs).forEach(([e, n]) => {
1371
- const a = this.shadowRoot.querySelector(`[data-ref="${e}"]`);
1372
- if (a) {
1373
- t.has(a) || t.set(a, /* @__PURE__ */ new Set());
1374
- const o = t.get(a), s = a.addEventListener;
1375
- a.addEventListener = function(i, l, c) {
1376
- const d = `${i}`;
1377
- o.has(d) || (o.add(d), s.call(a, i, l, c));
1378
- }, a.setAttribute("data-refs-processed", "true");
1365
+ const e = /* @__PURE__ */ new WeakMap();
1366
+ Object.entries(this.config.refs).forEach(([t, n]) => {
1367
+ const r = this.shadowRoot.querySelector(`[data-ref="${t}"]`);
1368
+ if (r) {
1369
+ e.has(r) || e.set(r, /* @__PURE__ */ new Set());
1370
+ const i = e.get(r), s = r.addEventListener;
1371
+ r.addEventListener = function(o, a, c) {
1372
+ const l = `${o}`;
1373
+ i.has(l) || (i.add(l), s.call(r, o, a, c));
1374
+ }, r.setAttribute("data-refs-processed", "true");
1379
1375
  try {
1380
- n(a, this.api.state, this.api);
1381
- } catch (i) {
1382
- this._handleRenderError(i);
1376
+ n(r, this.api.state, this.api);
1377
+ } catch (o) {
1378
+ this._handleRenderError(o);
1383
1379
  }
1384
1380
  }
1385
1381
  });
@@ -1390,43 +1386,42 @@ class J extends HTMLElement {
1390
1386
  */
1391
1387
  bindEvents() {
1392
1388
  if (!this.shadowRoot) return;
1393
- const t = document.createTreeWalker(this.shadowRoot, NodeFilter.SHOW_ELEMENT);
1394
- let e = t.nextNode();
1395
- for (; e; ) {
1396
- const n = e;
1397
- Array.from(n.attributes).forEach((a) => {
1398
- if (a.name.startsWith("data-on-")) {
1399
- const o = a.name.slice(8), s = a.value, i = this.config[s];
1400
- if (typeof i == "function") {
1401
- n._boundHandlers && n._boundHandlers[o] && n.removeEventListener(o, n._boundHandlers[o]);
1402
- const l = (c) => {
1403
- i.call(this.config, c, this.api.state, this.api), this.syncControlledInputsAndEvents();
1389
+ const e = document.createTreeWalker(this.shadowRoot, NodeFilter.SHOW_ELEMENT);
1390
+ let t = e.nextNode();
1391
+ for (; t; ) {
1392
+ const n = t;
1393
+ Array.from(n.attributes).forEach((r) => {
1394
+ if (r.name.startsWith("data-on-")) {
1395
+ const i = r.name.slice(8), s = r.value, o = this.config[s];
1396
+ if (typeof o == "function") {
1397
+ n._boundHandlers && n._boundHandlers[i] && n.removeEventListener(i, n._boundHandlers[i]);
1398
+ const a = (c) => {
1399
+ o.call(this.config, c, this.api.state, this.api), this.syncControlledInputsAndEvents();
1404
1400
  };
1405
- n.addEventListener(o, l), n._boundHandlers || (n._boundHandlers = {}), n._boundHandlers[o] = l;
1401
+ n.addEventListener(i, a), n._boundHandlers || (n._boundHandlers = {}), n._boundHandlers[i] = a;
1406
1402
  } else
1407
- this.config.debug && console.warn(`[runtime] Handler '${s}' not found on config for event '${o}'`, n);
1403
+ this.config.debug && console.warn(`[runtime] Handler '${s}' not found on config for event '${i}'`, n);
1408
1404
  }
1409
- }), e = t.nextNode();
1405
+ }), t = e.nextNode();
1410
1406
  }
1411
1407
  }
1412
1408
  /**
1413
1409
  * Renders a fallback error UI in the shadow root.
1414
1410
  * @param error - Error object
1415
1411
  */
1416
- renderError(t) {
1417
- const e = this.config.style ? typeof this.config.style == "function" ? this.config.style(this.api.state) : this.config.style : "";
1412
+ renderError(e) {
1413
+ const t = this.config.style ? typeof this.config.style == "function" ? this.config.style(this.api.state) : this.config.style : "";
1418
1414
  this.shadowRoot.innerHTML = `
1419
- <style>${e}</style>
1420
- <div style="color: red; border: 1px solid red; padding: 1rem; border-radius: 4px;">
1421
- <h3>Error Boundary</h3>
1422
- <div>Error: ${t.message}</div>
1423
- </div>
1424
- `;
1425
- }
1426
- }
1427
- function ft(r, t) {
1428
- const e = b(t), n = b(t.state);
1429
- if (t = e, t.state = n, t.debug && console.log(`[runtime] Debugging component: ${r}`, t), !r || !t.template || !t.state) {
1415
+ <style>${t}</style>
1416
+ <div style="color: red; border: 1px solid red; padding: 1rem; border-radius: 4px;">
1417
+ <h3>Error Boundary</h3>
1418
+ <div>Error: ${e.message}</div>
1419
+ </div>
1420
+ `;
1421
+ }
1422
+ });
1423
+ function ft(e, t) {
1424
+ if (t = _(t), t.debug && console.log(`[runtime] Debugging component: ${e}`, t), !e || !t.template || !t.state) {
1430
1425
  t && typeof t.onError == "function" && t.onError(new Error("Component requires tag, template, and state"), t.state, {
1431
1426
  state: t.state,
1432
1427
  emit: () => {
@@ -1437,12 +1432,12 @@ function ft(r, t) {
1437
1432
  },
1438
1433
  emitGlobal: () => {
1439
1434
  }
1440
- }), t && t.debug && console.error("[runtime] Malformed config:", { tag: r, config: t });
1435
+ }), t && t.debug && console.error("[runtime] Malformed config:", { tag: e, config: t });
1441
1436
  return;
1442
1437
  }
1443
- if (_.forEach((c) => {
1438
+ if (v.forEach((l) => {
1444
1439
  try {
1445
- c.onInit?.(t);
1440
+ l.onInit?.(t);
1446
1441
  } catch (d) {
1447
1442
  t && typeof t.onError == "function" && t.onError(d instanceof Error ? d : new Error(String(d)), t.state, {
1448
1443
  state: t.state,
@@ -1456,28 +1451,32 @@ function ft(r, t) {
1456
1451
  }
1457
1452
  }), t && t.debug && console.error("[runtime] Plugin onInit error:", d);
1458
1453
  }
1459
- }), (typeof window < "u" && window.VITE_DEV_HMR || typeof import.meta < "u" && void 0) && customElements.get(r))
1454
+ }), (typeof window < "u" && window.VITE_DEV_HMR || typeof import.meta < "u" && void 0) && customElements.get(e))
1460
1455
  try {
1461
- document.querySelectorAll(r).forEach((c) => c.remove()), window.customElements._definitions && delete window.customElements._definitions[r];
1456
+ document.querySelectorAll(e).forEach((l) => l.remove()), window.customElements._definitions && delete window.customElements._definitions[e];
1462
1457
  } catch {
1463
1458
  }
1464
- if (customElements.get(r)) {
1465
- t.debug && console.warn(`[runtime] Component "${r}" already registered`);
1459
+ if (customElements.get(e)) {
1460
+ t.debug && console.warn(`[runtime] Component "${e}" already registered`);
1466
1461
  return;
1467
1462
  }
1468
1463
  const s = M(t.state, t.computed);
1469
1464
  t.state = s, t._subscribe = s.subscribe;
1470
- const i = Object.keys(t.state).filter(
1471
- (c) => ["string", "number", "boolean"].includes(typeof t.state[c])
1472
- ), l = class extends J {
1465
+ const o = Object.keys(t.state).filter(
1466
+ (l) => ["string", "number", "boolean"].includes(typeof t.state[l])
1467
+ );
1468
+ class a extends P {
1473
1469
  static get observedAttributes() {
1474
- return i;
1470
+ return o;
1475
1471
  }
1476
1472
  constructor() {
1477
1473
  super();
1478
1474
  }
1479
- };
1480
- customElements.get(r) || (window.__componentRegistry = window.__componentRegistry || {}, window.__componentRegistry[r] = t, customElements.define(r, l));
1475
+ }
1476
+ const c = a;
1477
+ typeof customElements < "u" && !customElements.get(e) && (window.__componentRegistry = window.__componentRegistry || {}, window.__componentRegistry[e] = t, customElements.define(e, c)), (void 0).accept(() => {
1478
+ customElements.get(e) || customElements.define(e, c);
1479
+ });
1481
1480
  }
1482
1481
  export {
1483
1482
  Q as Store,
@@ -1487,7 +1486,7 @@ export {
1487
1486
  ft as component,
1488
1487
  k as createVNodeFromElement,
1489
1488
  st as css,
1490
- b as deepSanitizeObject,
1489
+ _ as deepSanitizeObject,
1491
1490
  C as eventBus,
1492
1491
  et as generateHydrationScript,
1493
1492
  x as getVNodeKey,
@@ -1495,17 +1494,17 @@ export {
1495
1494
  S as isPromise,
1496
1495
  g as mountVNode,
1497
1496
  ot as on,
1498
- Y as parseVNodeFromHTML,
1497
+ J as parseVNodeFromHTML,
1499
1498
  L as patchVNode,
1500
1499
  it as ref,
1501
1500
  j as renderCompiledTemplate,
1502
1501
  tt as renderComponentsToString,
1503
- W as renderToString,
1504
- _ as runtimePlugins,
1502
+ F as renderToString,
1503
+ v as runtimePlugins,
1505
1504
  D as safeReplaceChild,
1506
1505
  ct as styles,
1507
- X as updateCompiledTemplate,
1508
- G as useDataModel,
1506
+ V as updateCompiledTemplate,
1507
+ U as useDataModel,
1509
1508
  dt as useRuntimePlugin
1510
1509
  };
1511
1510
  //# sourceMappingURL=custom-elements-runtime.es.js.map