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