@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.
- package/dist/custom-elements-runtime.cjs.js +12 -12
- package/dist/custom-elements-runtime.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.es.js +755 -756
- package/dist/custom-elements-runtime.es.js.map +1 -1
- package/dist/custom-elements-runtime.umd.js +12 -12
- package/dist/custom-elements-runtime.umd.js.map +1 -1
- package/dist/runtime.d.ts +1 -7
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ class Q {
|
|
|
3
3
|
listeners = [];
|
|
4
4
|
constructor(t) {
|
|
5
5
|
this.state = new Proxy(t, {
|
|
6
|
-
set: (
|
|
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,
|
|
36
|
-
const
|
|
37
|
-
if (!
|
|
38
|
-
this.eventCounters.set(t, { count: 1, window:
|
|
39
|
-
else if (
|
|
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:
|
|
44
|
+
detail: n,
|
|
45
45
|
bubbles: !1,
|
|
46
46
|
// Global events don't need to bubble
|
|
47
47
|
cancelable: !0
|
|
48
48
|
}));
|
|
49
|
-
const
|
|
50
|
-
|
|
49
|
+
const s = this.handlers[t];
|
|
50
|
+
s && s.forEach((o) => {
|
|
51
51
|
try {
|
|
52
|
-
|
|
53
|
-
} catch (
|
|
54
|
-
console.error(`Error in global event handler for "${t}":`,
|
|
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,
|
|
64
|
-
return this.handlers[t] || (this.handlers[t] = /* @__PURE__ */ new Set()), this.handlers[t].add(
|
|
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,
|
|
72
|
-
const
|
|
73
|
-
|
|
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,
|
|
89
|
-
return this.addEventListener(t,
|
|
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,
|
|
97
|
-
return new Promise((
|
|
98
|
-
const
|
|
99
|
-
|
|
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 [
|
|
130
|
-
t[
|
|
131
|
-
count:
|
|
132
|
-
handlersCount: this.getHandlerCount(
|
|
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(),
|
|
144
|
-
function
|
|
143
|
+
const C = y.getInstance(), q = typeof window > "u" || typeof document > "u";
|
|
144
|
+
function W(e) {
|
|
145
145
|
return {
|
|
146
|
-
state:
|
|
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
|
|
159
|
-
|
|
158
|
+
function F(e, t = {}) {
|
|
159
|
+
q || console.warn("[SSR] renderToString should only be used on the server");
|
|
160
160
|
try {
|
|
161
|
-
const
|
|
162
|
-
let
|
|
163
|
-
t.includeStyles &&
|
|
164
|
-
const
|
|
165
|
-
return t.prettyPrint ?
|
|
166
|
-
} catch (
|
|
167
|
-
return console.error(`[SSR] Error rendering ${
|
|
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(
|
|
171
|
-
const
|
|
170
|
+
function tt(e, t = {}) {
|
|
171
|
+
const n = {
|
|
172
172
|
components: /* @__PURE__ */ new Map(),
|
|
173
173
|
styles: /* @__PURE__ */ new Set()
|
|
174
|
-
},
|
|
175
|
-
|
|
176
|
-
if (
|
|
177
|
-
const
|
|
178
|
-
|
|
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
|
|
181
|
-
|
|
180
|
+
const a = F(o, { ...t, includeStyles: !1 });
|
|
181
|
+
r.push(a);
|
|
182
182
|
});
|
|
183
|
-
const
|
|
183
|
+
const i = Array.from(n.styles).join(`
|
|
184
184
|
`);
|
|
185
|
-
return { html:
|
|
186
|
-
`), styles:
|
|
185
|
+
return { html: r.join(`
|
|
186
|
+
`), styles: i, context: n };
|
|
187
187
|
}
|
|
188
|
-
function et(
|
|
189
|
-
const t = Array.from(
|
|
190
|
-
tag:
|
|
191
|
-
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
|
|
228
|
+
const K = (e) => e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'"), H = (e) => e.replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">"), G = (e) => e.replace(/></g, `>
|
|
229
229
|
<`).split(`
|
|
230
230
|
`).map((t) => {
|
|
231
|
-
const
|
|
232
|
-
return " ".repeat(Math.max(0,
|
|
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 $(
|
|
236
|
-
return String(
|
|
235
|
+
function $(e) {
|
|
236
|
+
return String(e).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
237
237
|
}
|
|
238
|
-
function w(
|
|
239
|
-
if (typeof
|
|
240
|
-
for (const
|
|
241
|
-
if (typeof t[
|
|
242
|
-
return $(
|
|
243
|
-
if (Array.isArray(t[
|
|
244
|
-
for (const
|
|
245
|
-
if (
|
|
246
|
-
for (const
|
|
247
|
-
if (typeof
|
|
248
|
-
return $(
|
|
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(
|
|
252
|
+
return String(e);
|
|
253
253
|
}
|
|
254
|
-
function nt(
|
|
255
|
-
function
|
|
256
|
-
if (Array.isArray(
|
|
257
|
-
const
|
|
258
|
-
return
|
|
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
|
|
261
|
-
const
|
|
262
|
-
return
|
|
260
|
+
if (typeof r == "function") {
|
|
261
|
+
const o = n(r(i, s), i, s);
|
|
262
|
+
return o instanceof Promise, o;
|
|
263
263
|
}
|
|
264
|
-
return
|
|
265
|
-
}
|
|
266
|
-
return (
|
|
267
|
-
let
|
|
268
|
-
const
|
|
269
|
-
for (let
|
|
270
|
-
if (
|
|
271
|
-
let
|
|
272
|
-
const d =
|
|
273
|
-
|
|
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, """).replace(/'/g, "'"), s += l) : !f && !/=\s*"?$/.test(d) ? s += w(l, r) : s += l;
|
|
274
274
|
}
|
|
275
|
-
return
|
|
276
|
-
let
|
|
277
|
-
for (let
|
|
278
|
-
if (
|
|
279
|
-
let
|
|
280
|
-
const h =
|
|
281
|
-
|
|
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, """).replace(/'/g, "'"), l += u) : !m && !/=\s*"?$/.test(h) ? l += w(u, r) : l += u;
|
|
282
282
|
}
|
|
283
|
-
return
|
|
284
|
-
}) :
|
|
283
|
+
return l;
|
|
284
|
+
}) : s;
|
|
285
285
|
};
|
|
286
286
|
}
|
|
287
|
-
function rt(
|
|
288
|
-
const
|
|
289
|
-
function
|
|
290
|
-
return Array.isArray(
|
|
291
|
-
}
|
|
292
|
-
const
|
|
293
|
-
let
|
|
294
|
-
for (let
|
|
295
|
-
if (
|
|
296
|
-
let
|
|
297
|
-
const d =
|
|
298
|
-
|
|
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, """).replace(/'/g, "'"), a += l) : !f && !/=\s*"?$/.test(d) ? a += w(l, s) : a += l ?? "";
|
|
299
299
|
}
|
|
300
|
-
return
|
|
300
|
+
return a;
|
|
301
301
|
};
|
|
302
|
-
return
|
|
302
|
+
return i.id = n, i;
|
|
303
303
|
}
|
|
304
|
-
function st(
|
|
305
|
-
let
|
|
306
|
-
for (let
|
|
307
|
-
|
|
308
|
-
return
|
|
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(
|
|
311
|
-
return
|
|
310
|
+
function it(e) {
|
|
311
|
+
return e;
|
|
312
312
|
}
|
|
313
|
-
function ot(
|
|
314
|
-
return { [
|
|
313
|
+
function ot(e, t) {
|
|
314
|
+
return { [e]: t };
|
|
315
315
|
}
|
|
316
|
-
function at(
|
|
317
|
-
return Object.keys(
|
|
316
|
+
function at(e) {
|
|
317
|
+
return Object.keys(e).filter((t) => e[t]).join(" ");
|
|
318
318
|
}
|
|
319
|
-
function ct(
|
|
320
|
-
return Object.entries(
|
|
319
|
+
function ct(e) {
|
|
320
|
+
return Object.entries(e).map(([t, n]) => `${t}: ${n}`).join("; ");
|
|
321
321
|
}
|
|
322
|
-
function
|
|
323
|
-
const [
|
|
324
|
-
if (!
|
|
325
|
-
function
|
|
326
|
-
const d =
|
|
327
|
-
let
|
|
328
|
-
for (let
|
|
329
|
-
d[
|
|
330
|
-
|
|
331
|
-
}
|
|
332
|
-
const
|
|
333
|
-
let
|
|
334
|
-
if (
|
|
335
|
-
|
|
336
|
-
const
|
|
337
|
-
let
|
|
338
|
-
if (
|
|
339
|
-
if (
|
|
340
|
-
|
|
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
|
|
343
|
-
|
|
342
|
+
const u = f.indexOf(c);
|
|
343
|
+
u !== -1 && f.splice(u, 1);
|
|
344
344
|
}
|
|
345
|
-
|
|
345
|
+
s(t, r, [...f]);
|
|
346
346
|
} else
|
|
347
|
-
|
|
348
|
-
} else
|
|
349
|
-
d.checked = d.value === String(
|
|
350
|
-
})) : (
|
|
351
|
-
if ("_vnode" in
|
|
352
|
-
let
|
|
353
|
-
for (;
|
|
354
|
-
|
|
355
|
-
|
|
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
|
-
|
|
357
|
+
a.type === "blur" && (e._isDirty = !1);
|
|
358
358
|
};
|
|
359
|
-
|
|
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(
|
|
370
|
-
const { development:
|
|
371
|
-
if (
|
|
372
|
-
if (
|
|
373
|
-
const
|
|
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
|
-
|
|
380
|
+
o.cacheHits++, E.set(s, o);
|
|
381
381
|
}
|
|
382
|
-
return T.get(
|
|
382
|
+
return T.get(s);
|
|
383
383
|
}
|
|
384
|
-
if (
|
|
385
|
-
const
|
|
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
|
-
|
|
392
|
+
o.cacheMisses++, E.set(s, o);
|
|
393
393
|
}
|
|
394
394
|
try {
|
|
395
|
-
const
|
|
396
|
-
return
|
|
397
|
-
} catch (
|
|
398
|
-
return
|
|
399
|
-
statics: [
|
|
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:
|
|
402
|
+
id: s,
|
|
403
403
|
hasDynamics: !1,
|
|
404
|
-
render: () =>
|
|
404
|
+
render: () => e
|
|
405
405
|
};
|
|
406
406
|
}
|
|
407
407
|
}
|
|
408
|
-
function
|
|
408
|
+
function Z(e, t) {
|
|
409
409
|
if (typeof document > "u")
|
|
410
410
|
return [0];
|
|
411
411
|
try {
|
|
412
|
-
let
|
|
413
|
-
if (
|
|
414
|
-
if (
|
|
415
|
-
return
|
|
416
|
-
} else if (
|
|
417
|
-
let
|
|
418
|
-
for (let d = 0; d <
|
|
419
|
-
const
|
|
420
|
-
if (
|
|
421
|
-
return
|
|
422
|
-
|
|
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
|
|
428
|
-
return
|
|
429
|
-
} catch (
|
|
430
|
-
return R && console.warn("[Template Compiler] Error finding DOM path for placeholder:", t,
|
|
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
|
|
434
|
-
return new
|
|
433
|
+
function B(e, t) {
|
|
434
|
+
return new X(e, t).compile();
|
|
435
435
|
}
|
|
436
|
-
class
|
|
436
|
+
class X {
|
|
437
437
|
template;
|
|
438
438
|
options;
|
|
439
439
|
dynamics = [];
|
|
440
440
|
statics = [];
|
|
441
|
-
constructor(t,
|
|
442
|
-
this.template = t, this.options =
|
|
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(),
|
|
447
|
-
let
|
|
448
|
-
for (let
|
|
449
|
-
if (
|
|
450
|
-
let
|
|
451
|
-
if (
|
|
452
|
-
return Promise.all(this.dynamics.map((
|
|
453
|
-
const d =
|
|
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((
|
|
455
|
+
})).then((l) => {
|
|
456
456
|
let d = "";
|
|
457
|
-
for (let
|
|
458
|
-
d += this.statics[
|
|
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
|
-
|
|
461
|
+
o += c;
|
|
462
462
|
}
|
|
463
|
-
return
|
|
463
|
+
return o;
|
|
464
464
|
};
|
|
465
465
|
return {
|
|
466
466
|
statics: this.statics,
|
|
467
467
|
dynamics: this.dynamics,
|
|
468
468
|
fragment: t,
|
|
469
|
-
id:
|
|
469
|
+
id: n,
|
|
470
470
|
hasDynamics: this.dynamics.length > 0,
|
|
471
|
-
render:
|
|
471
|
+
render: r
|
|
472
472
|
};
|
|
473
473
|
}
|
|
474
474
|
parseTemplate() {
|
|
475
475
|
const t = /\{\{([^}]+)\}\}/g;
|
|
476
|
-
let
|
|
477
|
-
for (; (
|
|
478
|
-
const
|
|
479
|
-
this.statics.push(
|
|
480
|
-
let
|
|
481
|
-
if (
|
|
482
|
-
|
|
483
|
-
else if (
|
|
484
|
-
const d =
|
|
485
|
-
d && (
|
|
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
|
|
488
|
-
this.analyzeDynamicExpression(
|
|
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
|
|
491
|
-
this.statics.push(
|
|
492
|
-
}
|
|
493
|
-
analyzeDynamicExpression(t,
|
|
494
|
-
let
|
|
495
|
-
|
|
496
|
-
const
|
|
497
|
-
let
|
|
498
|
-
this.statics.length === 2 &&
|
|
499
|
-
path:
|
|
500
|
-
type:
|
|
501
|
-
target:
|
|
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 (
|
|
506
|
+
return (n, r) => {
|
|
507
507
|
try {
|
|
508
|
-
let
|
|
508
|
+
let i;
|
|
509
509
|
if (t && typeof t == "function")
|
|
510
|
-
|
|
510
|
+
i = t(n);
|
|
511
511
|
else if (typeof t == "string" && t.startsWith("state.")) {
|
|
512
|
-
const
|
|
513
|
-
|
|
514
|
-
} else typeof t == "string" && /^[a-zA-Z0-9_$]+$/.test(t) ?
|
|
515
|
-
return
|
|
516
|
-
} catch (
|
|
517
|
-
return this.options.development && console.warn(`[Template Compiler] Error evaluating expression: ${t}`,
|
|
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
|
|
529
|
-
for (;
|
|
530
|
-
|
|
531
|
-
return
|
|
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(
|
|
537
|
+
function O(e, t) {
|
|
538
538
|
try {
|
|
539
|
-
if (t.length === 1 && t[0] === 0 &&
|
|
540
|
-
return
|
|
541
|
-
let
|
|
542
|
-
for (let
|
|
543
|
-
const
|
|
544
|
-
if (!
|
|
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
|
-
|
|
546
|
+
n = n.childNodes[i];
|
|
547
547
|
}
|
|
548
|
-
return
|
|
548
|
+
return n;
|
|
549
549
|
} catch {
|
|
550
550
|
return null;
|
|
551
551
|
}
|
|
552
552
|
}
|
|
553
|
-
function j(
|
|
554
|
-
let
|
|
555
|
-
return
|
|
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
|
|
558
|
-
if (
|
|
559
|
-
for (const
|
|
557
|
+
function V(e, t, n, r, i) {
|
|
558
|
+
if (e.hasDynamics)
|
|
559
|
+
for (const s of e.dynamics)
|
|
560
560
|
try {
|
|
561
|
-
const
|
|
562
|
-
if (
|
|
561
|
+
const o = s.getValue(n, r);
|
|
562
|
+
if (i !== void 0 && s.getValue(i, r) === o)
|
|
563
563
|
continue;
|
|
564
|
-
I(t,
|
|
565
|
-
} catch (
|
|
566
|
-
console.warn("[Template Compiler] Error applying update:",
|
|
564
|
+
I(t, s, o);
|
|
565
|
+
} catch (o) {
|
|
566
|
+
console.warn("[Template Compiler] Error applying update:", o);
|
|
567
567
|
}
|
|
568
568
|
}
|
|
569
|
-
function
|
|
570
|
-
let
|
|
571
|
-
for (let
|
|
572
|
-
if (
|
|
573
|
-
const
|
|
574
|
-
if (
|
|
575
|
-
const
|
|
576
|
-
|
|
577
|
-
} else (
|
|
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
|
|
582
|
-
for (;
|
|
583
|
-
|
|
584
|
-
for (const
|
|
585
|
-
const
|
|
586
|
-
I(
|
|
587
|
-
}
|
|
588
|
-
return
|
|
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(
|
|
590
|
+
function I(e, t, n) {
|
|
591
591
|
try {
|
|
592
592
|
if (t.type === "text") {
|
|
593
|
-
const
|
|
594
|
-
|
|
593
|
+
const i = document.createTreeWalker(
|
|
594
|
+
e,
|
|
595
595
|
NodeFilter.SHOW_TEXT
|
|
596
596
|
);
|
|
597
|
-
let
|
|
598
|
-
for (;
|
|
599
|
-
const
|
|
600
|
-
if (
|
|
601
|
-
const
|
|
602
|
-
|
|
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 (
|
|
606
|
-
const
|
|
607
|
-
|
|
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
|
|
611
|
-
if (!
|
|
610
|
+
const r = O(e, t.path);
|
|
611
|
+
if (!r)
|
|
612
612
|
return;
|
|
613
613
|
switch (t.type) {
|
|
614
614
|
case "attribute":
|
|
615
|
-
if (
|
|
616
|
-
const
|
|
617
|
-
|
|
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
|
-
|
|
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 (
|
|
625
|
-
const
|
|
626
|
-
|
|
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 (
|
|
631
|
-
const
|
|
632
|
-
|
|
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 (
|
|
639
|
-
(typeof globalThis < "u" ? globalThis.isDevelopment : R) && console.warn("[Template Compiler] Error applying update:", t,
|
|
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(),
|
|
643
|
-
function N(
|
|
642
|
+
const T = /* @__PURE__ */ new Map(), E = /* @__PURE__ */ new Map();
|
|
643
|
+
function N(e) {
|
|
644
644
|
let t = 0;
|
|
645
|
-
for (let
|
|
646
|
-
const
|
|
647
|
-
t = (t << 5) - 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(
|
|
652
|
-
return
|
|
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(
|
|
655
|
-
if (!(!
|
|
654
|
+
function D(e, t, n) {
|
|
655
|
+
if (!(!e || !(e instanceof Element)) && e.contains(n) && n.parentNode === e)
|
|
656
656
|
try {
|
|
657
|
-
|
|
658
|
-
} catch (
|
|
659
|
-
console.error("[VDOM] safeReplaceChild: error replacing child",
|
|
660
|
-
parent:
|
|
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:
|
|
663
|
-
parentHTML:
|
|
662
|
+
oldChild: n,
|
|
663
|
+
parentHTML: e.outerHTML,
|
|
664
664
|
newChildHTML: t.outerHTML,
|
|
665
|
-
oldChildHTML:
|
|
665
|
+
oldChildHTML: n.outerHTML
|
|
666
666
|
});
|
|
667
667
|
}
|
|
668
668
|
}
|
|
669
|
-
function g(
|
|
670
|
-
if (
|
|
669
|
+
function g(e) {
|
|
670
|
+
if (e.type === "#whitespace")
|
|
671
671
|
return null;
|
|
672
|
-
if (
|
|
673
|
-
const
|
|
674
|
-
return
|
|
675
|
-
}
|
|
676
|
-
const t = document.createElement(
|
|
677
|
-
for (const [
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
for (const
|
|
681
|
-
const
|
|
682
|
-
|
|
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
|
|
686
|
+
function J(e) {
|
|
687
687
|
const t = document.createElement("template");
|
|
688
|
-
t.innerHTML =
|
|
689
|
-
const
|
|
690
|
-
return
|
|
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:
|
|
694
|
+
children: n.map((i, s) => k(i, "#fragment", s)),
|
|
695
695
|
dom: void 0
|
|
696
696
|
};
|
|
697
697
|
}
|
|
698
|
-
function k(
|
|
699
|
-
if (!
|
|
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 (
|
|
702
|
-
return !
|
|
703
|
-
if (
|
|
704
|
-
const
|
|
705
|
-
Array.from(
|
|
706
|
-
|
|
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
|
|
709
|
-
let
|
|
710
|
-
if ((
|
|
711
|
-
const
|
|
712
|
-
|
|
713
|
-
let
|
|
714
|
-
|
|
715
|
-
} else
|
|
716
|
-
const
|
|
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:
|
|
719
|
-
key:
|
|
720
|
-
props:
|
|
721
|
-
children:
|
|
722
|
-
dom:
|
|
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(
|
|
728
|
-
if (!t || !
|
|
729
|
-
function
|
|
730
|
-
return !!
|
|
731
|
-
}
|
|
732
|
-
const
|
|
733
|
-
if (t.type !==
|
|
734
|
-
const
|
|
735
|
-
if (
|
|
736
|
-
if (D(
|
|
737
|
-
const
|
|
738
|
-
|
|
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 (
|
|
741
|
-
if (
|
|
742
|
-
if (
|
|
743
|
-
const
|
|
744
|
-
|
|
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
|
-
|
|
747
|
+
n.dom = void 0;
|
|
748
748
|
else
|
|
749
|
-
|
|
749
|
+
n.dom = void 0;
|
|
750
750
|
return;
|
|
751
751
|
}
|
|
752
|
-
if (
|
|
753
|
-
for (const [
|
|
754
|
-
if (
|
|
755
|
-
|
|
756
|
-
else if (
|
|
757
|
-
|
|
758
|
-
else if (
|
|
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[
|
|
760
|
+
t.dom[c] = l;
|
|
761
761
|
} catch {
|
|
762
762
|
}
|
|
763
763
|
else
|
|
764
|
-
t.dom.setAttribute(
|
|
765
|
-
for (let
|
|
766
|
-
|
|
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
|
|
770
|
-
if (
|
|
771
|
-
const
|
|
772
|
-
for (const [d,
|
|
773
|
-
if (!(
|
|
774
|
-
if (
|
|
775
|
-
|
|
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
|
-
|
|
778
|
+
a.setAttribute(d, f);
|
|
779
779
|
}
|
|
780
|
-
if (
|
|
781
|
-
for (const [d,
|
|
782
|
-
|
|
783
|
-
for (const d of Array.from(
|
|
784
|
-
if (!(d in
|
|
785
|
-
if (
|
|
786
|
-
|
|
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 (
|
|
790
|
-
if (
|
|
791
|
-
|
|
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
|
|
794
|
-
|
|
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 (
|
|
799
|
-
const
|
|
800
|
-
|
|
801
|
-
const
|
|
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
|
|
804
|
-
const h =
|
|
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(
|
|
808
|
+
L(a, m, h), p = m.dom;
|
|
809
809
|
else {
|
|
810
|
-
const
|
|
811
|
-
if (p =
|
|
812
|
-
if ((p instanceof Element || p instanceof Node) && p.contains(
|
|
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:
|
|
814
|
+
parentTag: a.tagName,
|
|
815
815
|
childTag: p.tagName,
|
|
816
|
-
parentUid:
|
|
816
|
+
parentUid: a.getAttribute?.("data-uid"),
|
|
817
817
|
childUid: p.getAttribute?.("data-uid"),
|
|
818
|
-
parent:
|
|
818
|
+
parent: a,
|
|
819
819
|
child: p
|
|
820
820
|
}), new Error("VDOM patch error: Attempted to insert a parent into its own child");
|
|
821
|
-
|
|
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 (
|
|
827
|
-
!
|
|
828
|
-
});
|
|
829
|
-
|
|
830
|
-
for (let
|
|
831
|
-
if (
|
|
832
|
-
if ((d[
|
|
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
|
-
|
|
834
|
+
a.insertBefore(d[u], a.childNodes[u] || null);
|
|
835
835
|
}
|
|
836
|
-
|
|
837
|
-
const
|
|
838
|
-
Array.from(
|
|
839
|
-
const m =
|
|
840
|
-
(m && !
|
|
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(
|
|
845
|
-
const
|
|
846
|
-
let
|
|
847
|
-
function
|
|
848
|
-
return
|
|
849
|
-
const
|
|
850
|
-
|
|
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
|
|
854
|
-
Object.assign(
|
|
855
|
-
}
|
|
856
|
-
const
|
|
857
|
-
function
|
|
858
|
-
if (
|
|
859
|
-
const
|
|
860
|
-
get(
|
|
861
|
-
if (h === "subscribe") return
|
|
862
|
-
if (h === "set") return
|
|
863
|
-
if (t &&
|
|
864
|
-
return t[h](
|
|
865
|
-
const p = Reflect.get(
|
|
866
|
-
return typeof p == "object" && p !== null ?
|
|
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(
|
|
869
|
-
if (t &&
|
|
868
|
+
set(u, h, m, p) {
|
|
869
|
+
if (t && r.includes(h))
|
|
870
870
|
return !1;
|
|
871
|
-
const A =
|
|
872
|
-
return A !== m &&
|
|
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(
|
|
875
|
-
if (t &&
|
|
874
|
+
deleteProperty(u, h) {
|
|
875
|
+
if (t && r.includes(h))
|
|
876
876
|
return !1;
|
|
877
|
-
const m = Reflect.deleteProperty(
|
|
878
|
-
return
|
|
877
|
+
const m = Reflect.deleteProperty(u, h);
|
|
878
|
+
return n.forEach((p) => p(s)), m;
|
|
879
879
|
}
|
|
880
880
|
});
|
|
881
|
-
return
|
|
881
|
+
return c.set(d, f), f;
|
|
882
882
|
}
|
|
883
|
-
return
|
|
883
|
+
return s = l(i), s;
|
|
884
884
|
}
|
|
885
|
-
const
|
|
886
|
-
function dt(
|
|
887
|
-
|
|
885
|
+
const v = [];
|
|
886
|
+
function dt(e) {
|
|
887
|
+
v.push(e);
|
|
888
888
|
}
|
|
889
|
-
function
|
|
890
|
-
if (
|
|
891
|
-
if (t.add(
|
|
892
|
-
Object.getPrototypeOf(
|
|
893
|
-
const
|
|
894
|
-
for (const
|
|
895
|
-
|
|
896
|
-
return
|
|
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(
|
|
899
|
-
return !!
|
|
898
|
+
function S(e) {
|
|
899
|
+
return !!e && typeof e.then == "function";
|
|
900
900
|
}
|
|
901
|
-
|
|
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
|
|
913
|
-
this.config.reflect.forEach((
|
|
914
|
-
if (
|
|
915
|
-
this.removeAttribute(
|
|
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[
|
|
919
|
-
["string", "number", "boolean"].includes(typeof n) ? n == null ? this.removeAttribute(
|
|
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(
|
|
927
|
-
const
|
|
928
|
-
typeof
|
|
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(
|
|
941
|
-
super.removeEventListener(
|
|
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
|
|
949
|
-
return Object.keys(
|
|
950
|
-
(
|
|
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(
|
|
957
|
-
if (!(
|
|
958
|
-
const
|
|
959
|
-
let
|
|
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
|
-
|
|
962
|
-
else if (
|
|
963
|
-
if (
|
|
964
|
-
|
|
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(
|
|
967
|
-
|
|
963
|
+
const s = Number(i);
|
|
964
|
+
i = isNaN(s) ? this.config?.state?.[e] : s;
|
|
968
965
|
}
|
|
969
|
-
else
|
|
970
|
-
|
|
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((
|
|
978
|
-
const
|
|
979
|
-
if (!
|
|
980
|
-
const 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
|
-
|
|
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((
|
|
995
|
-
const
|
|
996
|
-
if (!
|
|
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 =
|
|
999
|
-
n.checked = n.value ===
|
|
1000
|
-
}), this.shadowRoot.querySelectorAll("input[data-model]").forEach((
|
|
1001
|
-
const
|
|
1002
|
-
if (!
|
|
1003
|
-
const n =
|
|
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
|
|
1006
|
-
if (Array.isArray(
|
|
1007
|
-
n.checked =
|
|
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"),
|
|
1010
|
-
s !== null ||
|
|
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 =
|
|
1013
|
-
}), this.shadowRoot.querySelectorAll("textarea[data-model]").forEach((
|
|
1014
|
-
const
|
|
1015
|
-
!
|
|
1016
|
-
}), this.shadowRoot.querySelectorAll("select[data-model]").forEach((
|
|
1017
|
-
const
|
|
1018
|
-
!
|
|
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((
|
|
1026
|
-
const
|
|
1027
|
-
if (!
|
|
1028
|
-
|
|
1029
|
-
const n =
|
|
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 [,
|
|
1032
|
-
|
|
1033
|
-
const
|
|
1034
|
-
!Array.isArray(c) || !c[
|
|
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
|
-
|
|
1033
|
+
e.addEventListener("input", l), e.addEventListener("change", l), e._listItemModelListener = l;
|
|
1037
1034
|
return;
|
|
1038
1035
|
}
|
|
1039
|
-
const
|
|
1040
|
-
if (
|
|
1041
|
-
const [,
|
|
1042
|
-
|
|
1043
|
-
const
|
|
1044
|
-
if (!
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
1057
|
-
|
|
1058
|
-
const n =
|
|
1059
|
-
n && (
|
|
1060
|
-
}),
|
|
1061
|
-
const [n] =
|
|
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 (
|
|
1064
|
-
if (
|
|
1065
|
-
const
|
|
1066
|
-
Array.isArray(
|
|
1067
|
-
} else
|
|
1068
|
-
else (
|
|
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
|
|
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
|
|
1095
|
-
if (this.stateObj =
|
|
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,
|
|
1100
|
-
onGlobal: (s,
|
|
1101
|
-
const
|
|
1102
|
-
return this._globalUnsubscribes.push(
|
|
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,
|
|
1105
|
-
emitGlobal: (s,
|
|
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
|
|
1109
|
-
const
|
|
1110
|
-
this.config[s](
|
|
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(
|
|
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((
|
|
1118
|
+
s && s.length > 0 ? s.forEach((o) => {
|
|
1122
1119
|
try {
|
|
1123
|
-
this.config.hydrate(
|
|
1124
|
-
} catch (
|
|
1125
|
-
typeof this.config.onError == "function" && this.config.onError(
|
|
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 (
|
|
1129
|
-
typeof this.config.onError == "function" && this.config.onError(
|
|
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((
|
|
1136
|
-
typeof this.config.onError == "function" && this.config.onError(
|
|
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
|
|
1147
|
-
if (
|
|
1148
|
-
const
|
|
1149
|
-
let n = this.getAttribute(
|
|
1150
|
-
|
|
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
|
|
1156
|
-
S(
|
|
1157
|
-
typeof this.config.onError == "function" && this.config.onError(
|
|
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 (
|
|
1162
|
-
typeof this.config.onError == "function" && this.config.onError(
|
|
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(([
|
|
1171
|
-
|
|
1172
|
-
super.removeEventListener(
|
|
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((
|
|
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
|
|
1177
|
-
S(
|
|
1178
|
-
typeof this.config.onError == "function" && this.config.onError(
|
|
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 (
|
|
1183
|
-
typeof this.config.onError == "function" && this.config.onError(
|
|
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
|
-
|
|
1190
|
+
v.forEach((t) => {
|
|
1194
1191
|
try {
|
|
1195
|
-
|
|
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((
|
|
1196
|
+
}), this.config.computed && Object.values(this.config.computed).forEach((t) => {
|
|
1200
1197
|
try {
|
|
1201
|
-
|
|
1198
|
+
t(this.stateObj);
|
|
1202
1199
|
} catch (n) {
|
|
1203
1200
|
this._handleRenderError(n);
|
|
1204
1201
|
}
|
|
1205
1202
|
});
|
|
1206
|
-
const
|
|
1207
|
-
|
|
1208
|
-
this._hasError || (this._renderTemplateResult(
|
|
1209
|
-
}).catch((
|
|
1210
|
-
this._handleRenderError(
|
|
1211
|
-
}) : this._hasError || (this._renderTemplateResult(
|
|
1212
|
-
} catch (
|
|
1213
|
-
this._handleRenderError(
|
|
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((
|
|
1226
|
-
this.shadowRoot.querySelectorAll(`[${
|
|
1227
|
-
const
|
|
1228
|
-
if (!
|
|
1229
|
-
n._boundHandlers && n._boundHandlers[
|
|
1230
|
-
const s = this.config[
|
|
1231
|
-
n.addEventListener(
|
|
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((
|
|
1234
|
-
|
|
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(
|
|
1239
|
+
_renderTemplateResult(e) {
|
|
1243
1240
|
if (!this._hasError)
|
|
1244
1241
|
try {
|
|
1245
|
-
let
|
|
1246
|
-
const
|
|
1247
|
-
function
|
|
1248
|
-
if (s === null || typeof s != "object") return s;
|
|
1249
|
-
if (
|
|
1250
|
-
|
|
1251
|
-
const
|
|
1252
|
-
|
|
1253
|
-
|
|
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
|
|
1252
|
+
return i(n);
|
|
1257
1253
|
};
|
|
1258
|
-
if (typeof
|
|
1254
|
+
if (typeof e == "string") {
|
|
1259
1255
|
let n = function(c) {
|
|
1260
|
-
return c.replace(/<([a-zA-Z0-9]+)([^>]*)>/g, (
|
|
1261
|
-
const
|
|
1262
|
-
return `<${
|
|
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
|
-
},
|
|
1265
|
-
c.children.forEach(
|
|
1260
|
+
}, r = function(c) {
|
|
1261
|
+
c.children.forEach(r);
|
|
1266
1262
|
};
|
|
1267
|
-
const
|
|
1268
|
-
|
|
1269
|
-
const
|
|
1270
|
-
if (!
|
|
1263
|
+
const i = n(e), s = J(i);
|
|
1264
|
+
r(s);
|
|
1265
|
+
const o = this.shadowRoot;
|
|
1266
|
+
if (!o)
|
|
1271
1267
|
return;
|
|
1272
|
-
let
|
|
1273
|
-
if (
|
|
1274
|
-
const c = Array.from(
|
|
1275
|
-
(
|
|
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
|
|
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
|
-
},
|
|
1288
|
-
L(c,
|
|
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((
|
|
1291
|
-
const
|
|
1292
|
-
|
|
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
|
-
(
|
|
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
|
|
1301
|
-
|
|
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,
|
|
1306
|
+
const n = !this.shadowRoot.firstElementChild, r = this.lastCompiledTemplate?.id === e.id;
|
|
1311
1307
|
if (n) {
|
|
1312
|
-
const
|
|
1313
|
-
this.shadowRoot.appendChild(
|
|
1314
|
-
} else if (
|
|
1315
|
-
const
|
|
1316
|
-
|
|
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
|
|
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
|
|
1322
|
-
for (
|
|
1323
|
-
|
|
1324
|
-
|
|
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 =
|
|
1322
|
+
this.lastCompiledTemplate = e;
|
|
1327
1323
|
}
|
|
1328
|
-
this.lastState =
|
|
1329
|
-
} catch (
|
|
1330
|
-
this._handleRenderError(
|
|
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(
|
|
1339
|
-
if (this._hasError = !0, this.config.debug && console.error(`[runtime] Render error in <${this.tagName.toLowerCase()}>:`,
|
|
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(
|
|
1342
|
-
} catch (
|
|
1343
|
-
this.config.debug && console.error("[runtime] Error in onError handler:",
|
|
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(
|
|
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
|
|
1360
|
-
if (!
|
|
1361
|
-
const
|
|
1362
|
-
|
|
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
|
|
1370
|
-
Object.entries(this.config.refs).forEach(([
|
|
1371
|
-
const
|
|
1372
|
-
if (
|
|
1373
|
-
|
|
1374
|
-
const
|
|
1375
|
-
|
|
1376
|
-
const
|
|
1377
|
-
|
|
1378
|
-
},
|
|
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(
|
|
1381
|
-
} catch (
|
|
1382
|
-
this._handleRenderError(
|
|
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
|
|
1394
|
-
let
|
|
1395
|
-
for (;
|
|
1396
|
-
const n =
|
|
1397
|
-
Array.from(n.attributes).forEach((
|
|
1398
|
-
if (
|
|
1399
|
-
const
|
|
1400
|
-
if (typeof
|
|
1401
|
-
n._boundHandlers && n._boundHandlers[
|
|
1402
|
-
const
|
|
1403
|
-
|
|
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(
|
|
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 '${
|
|
1403
|
+
this.config.debug && console.warn(`[runtime] Handler '${s}' not found on config for event '${i}'`, n);
|
|
1408
1404
|
}
|
|
1409
|
-
}),
|
|
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(
|
|
1417
|
-
const
|
|
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
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
}
|
|
1426
|
-
}
|
|
1427
|
-
function ft(
|
|
1428
|
-
|
|
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:
|
|
1435
|
+
}), t && t.debug && console.error("[runtime] Malformed config:", { tag: e, config: t });
|
|
1441
1436
|
return;
|
|
1442
1437
|
}
|
|
1443
|
-
if (
|
|
1438
|
+
if (v.forEach((l) => {
|
|
1444
1439
|
try {
|
|
1445
|
-
|
|
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(
|
|
1454
|
+
}), (typeof window < "u" && window.VITE_DEV_HMR || typeof import.meta < "u" && void 0) && customElements.get(e))
|
|
1460
1455
|
try {
|
|
1461
|
-
document.querySelectorAll(
|
|
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(
|
|
1465
|
-
t.debug && console.warn(`[runtime] Component "${
|
|
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
|
|
1471
|
-
(
|
|
1472
|
-
)
|
|
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
|
|
1470
|
+
return o;
|
|
1475
1471
|
}
|
|
1476
1472
|
constructor() {
|
|
1477
1473
|
super();
|
|
1478
1474
|
}
|
|
1479
|
-
}
|
|
1480
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1504
|
-
|
|
1502
|
+
F as renderToString,
|
|
1503
|
+
v as runtimePlugins,
|
|
1505
1504
|
D as safeReplaceChild,
|
|
1506
1505
|
ct as styles,
|
|
1507
|
-
|
|
1508
|
-
|
|
1506
|
+
V as updateCompiledTemplate,
|
|
1507
|
+
U as useDataModel,
|
|
1509
1508
|
dt as useRuntimePlugin
|
|
1510
1509
|
};
|
|
1511
1510
|
//# sourceMappingURL=custom-elements-runtime.es.js.map
|