@jasonshimmy/custom-elements-runtime 0.0.2 → 0.0.3-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/README.md +39 -36
- package/dist/custom-elements-runtime.cjs.js +1 -1
- package/dist/custom-elements-runtime.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.es.js +210 -210
- package/dist/custom-elements-runtime.es.js.map +1 -1
- package/dist/custom-elements-runtime.umd.js +1 -1
- package/dist/custom-elements-runtime.umd.js.map +1 -1
- package/dist/runtime.d.ts +1 -1
- 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: (n, r,
|
|
6
|
+
set: (n, r, o) => (n[r] = o, this.notify(), !0)
|
|
7
7
|
});
|
|
8
8
|
}
|
|
9
9
|
subscribe(t) {
|
|
@@ -33,10 +33,10 @@ class y extends EventTarget {
|
|
|
33
33
|
* @param data - Optional event payload
|
|
34
34
|
*/
|
|
35
35
|
emit(t, n) {
|
|
36
|
-
const r = Date.now(),
|
|
37
|
-
if (!
|
|
36
|
+
const r = Date.now(), o = this.eventCounters.get(t);
|
|
37
|
+
if (!o || r - o.window > 1e3)
|
|
38
38
|
this.eventCounters.set(t, { count: 1, window: r });
|
|
39
|
-
else if (
|
|
39
|
+
else if (o.count++, o.count > 50 && (console.error(`Event storm detected for "${t}": ${o.count} events in 1 second. Throttling...`), o.count > 100)) {
|
|
40
40
|
console.warn(`Blocking further "${t}" events to prevent infinite loop`);
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
@@ -47,9 +47,9 @@ class y extends EventTarget {
|
|
|
47
47
|
cancelable: !0
|
|
48
48
|
}));
|
|
49
49
|
const s = this.handlers[t];
|
|
50
|
-
s && s.forEach((
|
|
50
|
+
s && s.forEach((i) => {
|
|
51
51
|
try {
|
|
52
|
-
|
|
52
|
+
i(n);
|
|
53
53
|
} catch (a) {
|
|
54
54
|
console.error(`Error in global event handler for "${t}":`, a);
|
|
55
55
|
}
|
|
@@ -95,8 +95,8 @@ class y extends EventTarget {
|
|
|
95
95
|
*/
|
|
96
96
|
once(t, n) {
|
|
97
97
|
return new Promise((r) => {
|
|
98
|
-
const
|
|
99
|
-
|
|
98
|
+
const o = this.on(t, (s) => {
|
|
99
|
+
o(), n(s), r(s);
|
|
100
100
|
});
|
|
101
101
|
});
|
|
102
102
|
}
|
|
@@ -158,10 +158,10 @@ function W(e) {
|
|
|
158
158
|
function F(e, t = {}) {
|
|
159
159
|
q || console.warn("[SSR] renderToString should only be used on the server");
|
|
160
160
|
try {
|
|
161
|
-
const n = e.state, r = W(n),
|
|
161
|
+
const n = e.state, r = W(n), o = e.template(n, r);
|
|
162
162
|
let s = "";
|
|
163
163
|
t.includeStyles && e.style && (s = `<style>${typeof e.style == "function" ? e.style(n) : e.style}</style>`);
|
|
164
|
-
const
|
|
164
|
+
const i = t.sanitizeAttributes ? t.sanitizeAttributes(e.attrs || {}) : e.attrs || {}, a = Object.entries(i).map(([d, f]) => `${H(d)}="${H(f)}"`).join(" "), l = `${a ? `<${e.tag} ${a}>` : `<${e.tag}>`}${s}${o}</${e.tag}>`;
|
|
165
165
|
return t.prettyPrint ? G(l) : l;
|
|
166
166
|
} catch (n) {
|
|
167
167
|
return console.error(`[SSR] Error rendering ${e.tag}:`, n), `<${e.tag}><div style="color: red;">SSR Error: ${K(String(n))}</div></${e.tag}>`;
|
|
@@ -172,18 +172,18 @@ function tt(e, t = {}) {
|
|
|
172
172
|
components: /* @__PURE__ */ new Map(),
|
|
173
173
|
styles: /* @__PURE__ */ new Set()
|
|
174
174
|
}, r = [];
|
|
175
|
-
e.forEach((
|
|
176
|
-
if (n.components.set(
|
|
177
|
-
const c = typeof
|
|
175
|
+
e.forEach((i) => {
|
|
176
|
+
if (n.components.set(i.tag, i), i.style) {
|
|
177
|
+
const c = typeof i.style == "function" ? i.style(i.state) : i.style;
|
|
178
178
|
n.styles.add(c);
|
|
179
179
|
}
|
|
180
|
-
const a = F(
|
|
180
|
+
const a = F(i, { ...t, includeStyles: !1 });
|
|
181
181
|
r.push(a);
|
|
182
182
|
});
|
|
183
|
-
const
|
|
183
|
+
const o = Array.from(n.styles).join(`
|
|
184
184
|
`);
|
|
185
185
|
return { html: r.join(`
|
|
186
|
-
`), styles:
|
|
186
|
+
`), styles: o, context: n };
|
|
187
187
|
}
|
|
188
188
|
function et(e) {
|
|
189
189
|
const t = Array.from(e.components.entries()).map(([n, r]) => ({
|
|
@@ -243,8 +243,8 @@ function w(e, t) {
|
|
|
243
243
|
if (Array.isArray(t[n])) {
|
|
244
244
|
for (const r of t[n])
|
|
245
245
|
if (r && typeof r == "object") {
|
|
246
|
-
for (const
|
|
247
|
-
if (typeof r[
|
|
246
|
+
for (const o in r)
|
|
247
|
+
if (typeof r[o] == "string" && e === r[o])
|
|
248
248
|
return $(e);
|
|
249
249
|
}
|
|
250
250
|
}
|
|
@@ -252,33 +252,33 @@ function w(e, t) {
|
|
|
252
252
|
return String(e);
|
|
253
253
|
}
|
|
254
254
|
function nt(e, ...t) {
|
|
255
|
-
function n(r,
|
|
255
|
+
function n(r, o, s) {
|
|
256
256
|
if (Array.isArray(r)) {
|
|
257
|
-
const
|
|
258
|
-
return
|
|
257
|
+
const i = r.map((a) => n(a, o, s));
|
|
258
|
+
return i.some((a) => a instanceof Promise) ? Promise.all(i).then((a) => a.join("")) : i.join("");
|
|
259
259
|
}
|
|
260
260
|
if (typeof r == "function") {
|
|
261
|
-
const
|
|
262
|
-
return
|
|
261
|
+
const i = n(r(o, s), o, s);
|
|
262
|
+
return i instanceof Promise, i;
|
|
263
263
|
}
|
|
264
264
|
return r == null ? "" : r instanceof Promise ? r : String(r);
|
|
265
265
|
}
|
|
266
|
-
return (r,
|
|
267
|
-
let s = "",
|
|
266
|
+
return (r, o) => {
|
|
267
|
+
let s = "", i = !1;
|
|
268
268
|
const a = [];
|
|
269
269
|
for (let c = 0; c < e.length; c++)
|
|
270
270
|
if (s += e[c], c < t.length) {
|
|
271
271
|
let l = t[c];
|
|
272
272
|
const d = e[c], f = /data-on-[a-z]+="?$/.test(d);
|
|
273
|
-
l = n(l, r,
|
|
273
|
+
l = n(l, r, o), l instanceof Promise ? (i = !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
|
|
275
|
+
return i ? Promise.all(a).then((c) => {
|
|
276
276
|
let l = "", d = 0;
|
|
277
277
|
for (let f = 0; f < e.length; f++)
|
|
278
278
|
if (l += e[f], f < t.length) {
|
|
279
279
|
let u = t[f];
|
|
280
280
|
const h = e[f], m = /data-on-[a-z]+="?$/.test(h);
|
|
281
|
-
u = n(u, r,
|
|
281
|
+
u = n(u, r, o), 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
283
|
return l;
|
|
284
284
|
}) : s;
|
|
@@ -286,20 +286,20 @@ function nt(e, ...t) {
|
|
|
286
286
|
}
|
|
287
287
|
function rt(e, ...t) {
|
|
288
288
|
const n = "compiled-" + Math.random().toString(36).slice(2);
|
|
289
|
-
function r(s,
|
|
290
|
-
return Array.isArray(s) ? s.map((c) => r(c,
|
|
289
|
+
function r(s, i, a) {
|
|
290
|
+
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);
|
|
291
291
|
}
|
|
292
|
-
const
|
|
292
|
+
const o = (s, i) => {
|
|
293
293
|
let a = "";
|
|
294
294
|
for (let c = 0; c < e.length; c++)
|
|
295
295
|
if (a += e[c], c < t.length) {
|
|
296
296
|
let l = t[c];
|
|
297
297
|
const d = e[c], f = /data-on-[a-z]+="?$/.test(d);
|
|
298
|
-
l = r(l, s,
|
|
298
|
+
l = r(l, s, i), /=\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
300
|
return a;
|
|
301
301
|
};
|
|
302
|
-
return
|
|
302
|
+
return o.id = n, o;
|
|
303
303
|
}
|
|
304
304
|
function st(e, ...t) {
|
|
305
305
|
let n = "";
|
|
@@ -314,7 +314,7 @@ function ot(e) {
|
|
|
314
314
|
return Object.entries(e).map(([t, n]) => `${t}: ${n}`).join("; ");
|
|
315
315
|
}
|
|
316
316
|
function U(e, t, n) {
|
|
317
|
-
const [r, ...
|
|
317
|
+
const [r, ...o] = n.split("|").map((a) => a.trim());
|
|
318
318
|
if (!r || r === "__proto__" || r === "constructor" || r === "prototype") return;
|
|
319
319
|
function s(a, c, l) {
|
|
320
320
|
const d = c.split(".");
|
|
@@ -323,7 +323,7 @@ function U(e, t, n) {
|
|
|
323
323
|
d[u] in f || (f[d[u]] = {}), f = f[d[u]];
|
|
324
324
|
f[d[d.length - 1]] = l;
|
|
325
325
|
}
|
|
326
|
-
const
|
|
326
|
+
const i = (a) => {
|
|
327
327
|
let c;
|
|
328
328
|
if (e instanceof HTMLInputElement && e.type === "checkbox") {
|
|
329
329
|
c = e.value;
|
|
@@ -341,7 +341,7 @@ function U(e, t, n) {
|
|
|
341
341
|
l !== null || d !== null ? e.checked ? s(t, r, l) : s(t, r, d !== null ? d : !1) : s(t, r, e.checked);
|
|
342
342
|
} 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) => {
|
|
343
343
|
d.checked = d.value === String(c);
|
|
344
|
-
})) : (c = e.value, e instanceof HTMLInputElement && e.type === "number" && (c = Number(c)),
|
|
344
|
+
})) : (c = e.value, e instanceof HTMLInputElement && e.type === "number" && (c = Number(c)), o.includes("trim") && typeof c == "string" && (c = c.trim()), o.includes("number") && (c = Number(c)), s(t, r, c));
|
|
345
345
|
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)) {
|
|
346
346
|
let l = e.parentElement;
|
|
347
347
|
for (; l && !(l instanceof HTMLElement && l.shadowRoot); )
|
|
@@ -350,7 +350,7 @@ function U(e, t, n) {
|
|
|
350
350
|
}
|
|
351
351
|
a.type === "blur" && (e._isDirty = !1);
|
|
352
352
|
};
|
|
353
|
-
e.addEventListener("input",
|
|
353
|
+
e.addEventListener("input", i), e.addEventListener("change", i), e.addEventListener("keydown", i), e.addEventListener("blur", i);
|
|
354
354
|
}
|
|
355
355
|
const R = (() => {
|
|
356
356
|
try {
|
|
@@ -361,35 +361,35 @@ const R = (() => {
|
|
|
361
361
|
return typeof window < "u" ? window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1" : !1;
|
|
362
362
|
})();
|
|
363
363
|
function at(e, t = {}) {
|
|
364
|
-
const { development: n = R, cache: r = !0, optimize:
|
|
364
|
+
const { development: n = R, cache: r = !0, optimize: o = !0 } = t, s = N(e);
|
|
365
365
|
if (r && T.has(s)) {
|
|
366
366
|
if (n) {
|
|
367
|
-
const
|
|
367
|
+
const i = E.get(s) || {
|
|
368
368
|
compilationTime: 0,
|
|
369
369
|
renderTime: 0,
|
|
370
370
|
updateTime: 0,
|
|
371
371
|
cacheHits: 0,
|
|
372
372
|
cacheMisses: 0
|
|
373
373
|
};
|
|
374
|
-
|
|
374
|
+
i.cacheHits++, E.set(s, i);
|
|
375
375
|
}
|
|
376
376
|
return T.get(s);
|
|
377
377
|
}
|
|
378
378
|
if (n) {
|
|
379
|
-
const
|
|
379
|
+
const i = E.get(s) || {
|
|
380
380
|
compilationTime: 0,
|
|
381
381
|
renderTime: 0,
|
|
382
382
|
updateTime: 0,
|
|
383
383
|
cacheHits: 0,
|
|
384
384
|
cacheMisses: 0
|
|
385
385
|
};
|
|
386
|
-
|
|
386
|
+
i.cacheMisses++, E.set(s, i);
|
|
387
387
|
}
|
|
388
388
|
try {
|
|
389
|
-
const
|
|
390
|
-
return r && T.set(s,
|
|
391
|
-
} catch (
|
|
392
|
-
return n && (console.error("[Template Compiler] Error compiling template:",
|
|
389
|
+
const i = B(e, { development: n, optimize: o });
|
|
390
|
+
return r && T.set(s, i), i;
|
|
391
|
+
} catch (i) {
|
|
392
|
+
return n && (console.error("[Template Compiler] Error compiling template:", i), console.error("[Template Compiler] Template:", e)), {
|
|
393
393
|
statics: [e],
|
|
394
394
|
dynamics: [],
|
|
395
395
|
fragment: null,
|
|
@@ -437,14 +437,14 @@ class X {
|
|
|
437
437
|
}
|
|
438
438
|
compile() {
|
|
439
439
|
this.parseTemplate();
|
|
440
|
-
const t = this.createStaticFragment(), n = N(this.template), r = (
|
|
441
|
-
let
|
|
440
|
+
const t = this.createStaticFragment(), n = N(this.template), r = (o, s) => {
|
|
441
|
+
let i = "";
|
|
442
442
|
for (let a = 0; a < this.statics.length; a++)
|
|
443
|
-
if (
|
|
444
|
-
let c = this.dynamics[a].getValue(
|
|
443
|
+
if (i += this.statics[a], a < this.dynamics.length) {
|
|
444
|
+
let c = this.dynamics[a].getValue(o, s);
|
|
445
445
|
if (c instanceof Promise)
|
|
446
446
|
return Promise.all(this.dynamics.map((l) => {
|
|
447
|
-
const d = l.getValue(
|
|
447
|
+
const d = l.getValue(o, s);
|
|
448
448
|
return d instanceof Promise ? d : Promise.resolve(d);
|
|
449
449
|
})).then((l) => {
|
|
450
450
|
let d = "";
|
|
@@ -452,9 +452,9 @@ class X {
|
|
|
452
452
|
d += this.statics[f], f < l.length && (d += l[f]);
|
|
453
453
|
return d;
|
|
454
454
|
});
|
|
455
|
-
|
|
455
|
+
i += c;
|
|
456
456
|
}
|
|
457
|
-
return
|
|
457
|
+
return i;
|
|
458
458
|
};
|
|
459
459
|
return {
|
|
460
460
|
statics: this.statics,
|
|
@@ -471,7 +471,7 @@ class X {
|
|
|
471
471
|
for (; (r = t.exec(this.template)) !== null; ) {
|
|
472
472
|
const s = this.template.slice(n, r.index);
|
|
473
473
|
this.statics.push(s);
|
|
474
|
-
let
|
|
474
|
+
let i = s.match(/([a-zA-Z0-9_-]+)\s*=\s*"?$/), a = i ? i[1] : void 0, c;
|
|
475
475
|
if (s.endsWith('style="color:'))
|
|
476
476
|
a = "style", c = "color";
|
|
477
477
|
else if (a === "style") {
|
|
@@ -481,34 +481,34 @@ class X {
|
|
|
481
481
|
const l = r[1].trim();
|
|
482
482
|
this.analyzeDynamicExpression(l, this.dynamics.length, a, c), n = r.index + r[0].length;
|
|
483
483
|
}
|
|
484
|
-
const
|
|
485
|
-
this.statics.push(
|
|
484
|
+
const o = this.template.slice(n);
|
|
485
|
+
this.statics.push(o);
|
|
486
486
|
}
|
|
487
|
-
analyzeDynamicExpression(t, n, r,
|
|
488
|
-
let s = "text",
|
|
489
|
-
r ? r === "class" ? (s = "class",
|
|
487
|
+
analyzeDynamicExpression(t, n, r, o) {
|
|
488
|
+
let s = "text", i;
|
|
489
|
+
r ? r === "class" ? (s = "class", i = "class") : r === "style" ? (s = "style", i = o || "style") : r === "value" ? (s = "property", i = "value") : (s = "attribute", i = r) : t.includes("class.") ? (s = "class", i = t.split(".")[1]) : t.includes("style.") ? (s = "style", i = t.split(".")[1]) : t.includes("@") ? (s = "event", i = t.split("@")[1]) : t === "class" ? (s = "class", i = "class") : t === "style" ? (s = "style", i = "style") : t === "value" ? (s = "property", i = "value") : t === "title" && (s = "attribute", i = "title");
|
|
490
490
|
const a = `__DYNAMIC_${n}__`, c = this.statics.join(a);
|
|
491
491
|
let l = Z(c, a);
|
|
492
492
|
this.statics.length === 2 && s !== "text" ? l = [0] : this.statics.length === 2 && l.length === 0 && (l = [0]), this.dynamics.push({
|
|
493
493
|
path: l,
|
|
494
494
|
type: s,
|
|
495
|
-
target:
|
|
495
|
+
target: i,
|
|
496
496
|
getValue: this.createValueGetter(t)
|
|
497
497
|
});
|
|
498
498
|
}
|
|
499
499
|
createValueGetter(t) {
|
|
500
500
|
return (n, r) => {
|
|
501
501
|
try {
|
|
502
|
-
let
|
|
502
|
+
let o;
|
|
503
503
|
if (t && typeof t == "function")
|
|
504
|
-
|
|
504
|
+
o = t(n);
|
|
505
505
|
else if (typeof t == "string" && t.startsWith("state.")) {
|
|
506
506
|
const s = t.slice(6);
|
|
507
|
-
|
|
508
|
-
} else typeof t == "string" && /^[a-zA-Z0-9_$]+$/.test(t) ?
|
|
509
|
-
return
|
|
510
|
-
} catch (
|
|
511
|
-
return this.options.development && console.warn(`[Template Compiler] Error evaluating expression: ${t}`,
|
|
507
|
+
o = n[s];
|
|
508
|
+
} else typeof t == "string" && /^[a-zA-Z0-9_$]+$/.test(t) ? o = n[t] : (typeof t == "string" && t.includes("("), o = "");
|
|
509
|
+
return o;
|
|
510
|
+
} catch (o) {
|
|
511
|
+
return this.options.development && console.warn(`[Template Compiler] Error evaluating expression: ${t}`, o), "";
|
|
512
512
|
}
|
|
513
513
|
};
|
|
514
514
|
}
|
|
@@ -519,10 +519,10 @@ class X {
|
|
|
519
519
|
const t = this.statics.join("");
|
|
520
520
|
if (!t.trim())
|
|
521
521
|
return null;
|
|
522
|
-
const r = new DOMParser().parseFromString(t, "text/html"),
|
|
522
|
+
const r = new DOMParser().parseFromString(t, "text/html"), o = document.createDocumentFragment();
|
|
523
523
|
for (; r.body.firstChild; )
|
|
524
|
-
|
|
525
|
-
return
|
|
524
|
+
o.appendChild(r.body.firstChild);
|
|
525
|
+
return o;
|
|
526
526
|
} catch (t) {
|
|
527
527
|
return this.options.development && console.warn("[Template Compiler] Could not create static fragment:", t), null;
|
|
528
528
|
}
|
|
@@ -534,10 +534,10 @@ function O(e, t) {
|
|
|
534
534
|
return e;
|
|
535
535
|
let n = e;
|
|
536
536
|
for (let r = 0; r < t.length; r++) {
|
|
537
|
-
const
|
|
538
|
-
if (!n.childNodes || n.childNodes.length <=
|
|
537
|
+
const o = t[r];
|
|
538
|
+
if (!n.childNodes || n.childNodes.length <= o)
|
|
539
539
|
return null;
|
|
540
|
-
n = n.childNodes[
|
|
540
|
+
n = n.childNodes[o];
|
|
541
541
|
}
|
|
542
542
|
return n;
|
|
543
543
|
} catch {
|
|
@@ -548,16 +548,16 @@ function j(e, t, n) {
|
|
|
548
548
|
let r;
|
|
549
549
|
return e.fragment && !e.hasDynamics ? r = e.fragment.cloneNode(!0) : r = Y(e, t, n), r;
|
|
550
550
|
}
|
|
551
|
-
function V(e, t, n, r,
|
|
551
|
+
function V(e, t, n, r, o) {
|
|
552
552
|
if (e.hasDynamics)
|
|
553
553
|
for (const s of e.dynamics)
|
|
554
554
|
try {
|
|
555
|
-
const
|
|
556
|
-
if (
|
|
555
|
+
const i = s.getValue(n, r);
|
|
556
|
+
if (o !== void 0 && s.getValue(o, r) === i)
|
|
557
557
|
continue;
|
|
558
|
-
I(t, s,
|
|
559
|
-
} catch (
|
|
560
|
-
console.warn("[Template Compiler] Error applying update:",
|
|
558
|
+
I(t, s, i);
|
|
559
|
+
} catch (i) {
|
|
560
|
+
console.warn("[Template Compiler] Error applying update:", i);
|
|
561
561
|
}
|
|
562
562
|
}
|
|
563
563
|
function Y(e, t, n) {
|
|
@@ -572,28 +572,28 @@ function Y(e, t, n) {
|
|
|
572
572
|
}
|
|
573
573
|
if (typeof document > "u")
|
|
574
574
|
return new DocumentFragment();
|
|
575
|
-
const s = new DOMParser().parseFromString(r, "text/html"),
|
|
575
|
+
const s = new DOMParser().parseFromString(r, "text/html"), i = document.createDocumentFragment();
|
|
576
576
|
for (; s.body.firstChild; )
|
|
577
|
-
|
|
577
|
+
i.appendChild(s.body.firstChild);
|
|
578
578
|
for (const a of e.dynamics) {
|
|
579
|
-
const c = a.getValue(t, n), l = O(
|
|
579
|
+
const c = a.getValue(t, n), l = O(i, a.path);
|
|
580
580
|
I(l, a, c);
|
|
581
581
|
}
|
|
582
|
-
return
|
|
582
|
+
return i;
|
|
583
583
|
}
|
|
584
584
|
function I(e, t, n) {
|
|
585
585
|
try {
|
|
586
586
|
if (t.type === "text") {
|
|
587
|
-
const
|
|
587
|
+
const o = document.createTreeWalker(
|
|
588
588
|
e,
|
|
589
589
|
NodeFilter.SHOW_TEXT
|
|
590
590
|
);
|
|
591
|
-
let s = !1,
|
|
592
|
-
for (;
|
|
593
|
-
const c =
|
|
591
|
+
let s = !1, i;
|
|
592
|
+
for (; i = o.nextNode(); ) {
|
|
593
|
+
const c = i.textContent || "";
|
|
594
594
|
if (c.includes("Count: ")) {
|
|
595
595
|
const l = c.replace(/Count: \d+/, `Count: ${n}`);
|
|
596
|
-
|
|
596
|
+
i.textContent = l, s = !0;
|
|
597
597
|
}
|
|
598
598
|
}
|
|
599
599
|
if (s) return;
|
|
@@ -607,8 +607,8 @@ function I(e, t, n) {
|
|
|
607
607
|
switch (t.type) {
|
|
608
608
|
case "attribute":
|
|
609
609
|
if (r.nodeType === Node.ELEMENT_NODE && t.target) {
|
|
610
|
-
const
|
|
611
|
-
n == null || n === "" ?
|
|
610
|
+
const o = r;
|
|
611
|
+
n == null || n === "" ? o.removeAttribute(t.target) : o.setAttribute(t.target, String(n));
|
|
612
612
|
}
|
|
613
613
|
break;
|
|
614
614
|
case "property":
|
|
@@ -616,14 +616,14 @@ function I(e, t, n) {
|
|
|
616
616
|
break;
|
|
617
617
|
case "class":
|
|
618
618
|
if (r.nodeType === Node.ELEMENT_NODE && t.target) {
|
|
619
|
-
const
|
|
620
|
-
|
|
619
|
+
const o = r;
|
|
620
|
+
o.className = n == null ? "" : String(n), o.setAttribute("class", n == null ? "" : String(n));
|
|
621
621
|
}
|
|
622
622
|
break;
|
|
623
623
|
case "style":
|
|
624
624
|
if (r.nodeType === Node.ELEMENT_NODE && t.target) {
|
|
625
|
-
const
|
|
626
|
-
|
|
625
|
+
const o = r;
|
|
626
|
+
o.style[t.target] = n == null ? "" : String(n), o.setAttribute("style", n == null ? `${t.target}:` : `${t.target}:${n}`);
|
|
627
627
|
}
|
|
628
628
|
break;
|
|
629
629
|
default:
|
|
@@ -642,8 +642,8 @@ function N(e) {
|
|
|
642
642
|
}
|
|
643
643
|
return `tpl_${Math.abs(t).toString(36)}`;
|
|
644
644
|
}
|
|
645
|
-
function x(e, t, n, r,
|
|
646
|
-
return r &&
|
|
645
|
+
function x(e, t, n, r, o) {
|
|
646
|
+
return r && o ? `${t}.${e}[${n}]:${r}:${o}` : r ? `${t}.${e}[${n}]:${r}` : `${t}.${e}[${n}]`;
|
|
647
647
|
}
|
|
648
648
|
function D(e, t, n) {
|
|
649
649
|
if (!(!e || !(e instanceof Element)) && e.contains(n) && n.parentNode === e)
|
|
@@ -685,7 +685,7 @@ function J(e) {
|
|
|
685
685
|
type: "#fragment",
|
|
686
686
|
key: void 0,
|
|
687
687
|
props: {},
|
|
688
|
-
children: n.map((
|
|
688
|
+
children: n.map((o, s) => k(o, "#fragment", s)),
|
|
689
689
|
dom: void 0
|
|
690
690
|
};
|
|
691
691
|
}
|
|
@@ -695,23 +695,23 @@ function k(e, t = "", n = 0) {
|
|
|
695
695
|
if (e.nodeType === Node.TEXT_NODE)
|
|
696
696
|
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 };
|
|
697
697
|
if (e.nodeType === Node.ELEMENT_NODE) {
|
|
698
|
-
const r = e,
|
|
698
|
+
const r = e, o = {};
|
|
699
699
|
Array.from(r.attributes).forEach((l) => {
|
|
700
|
-
|
|
700
|
+
o[l.name] = l.value;
|
|
701
701
|
});
|
|
702
702
|
const s = r.tagName.toLowerCase();
|
|
703
|
-
let
|
|
703
|
+
let i;
|
|
704
704
|
if ((s === "input" || s === "select" || s === "textarea") && r.hasAttribute("data-model")) {
|
|
705
705
|
const l = r.getAttribute("data-model"), d = r.getAttribute("type") ?? "";
|
|
706
|
-
|
|
706
|
+
i = `${s}:${l}:${d}`, o["data-uid"] = i, r.setAttribute("data-uid", i);
|
|
707
707
|
let f = r.getAttribute("value"), u = r.getAttribute("checked");
|
|
708
|
-
f && (
|
|
709
|
-
} else s === "input" || s === "textarea" || s === "select" || r.hasAttribute("contenteditable") ? (
|
|
710
|
-
const a = Array.from(r.childNodes).map((l, d) => k(l,
|
|
708
|
+
f && (o.value = f), u && (o.checked = u);
|
|
709
|
+
} else s === "input" || s === "textarea" || s === "select" || r.hasAttribute("contenteditable") ? (i = `${s}:${t}:${n}`, o["data-uid"] = i, r.setAttribute("data-uid", i)) : (i = x(s, t, n), s === "li" && (o["data-uid"] = i, r.setAttribute("data-uid", i)));
|
|
710
|
+
const a = Array.from(r.childNodes).map((l, d) => k(l, i, d));
|
|
711
711
|
return {
|
|
712
712
|
type: s,
|
|
713
|
-
key:
|
|
714
|
-
props:
|
|
713
|
+
key: i,
|
|
714
|
+
props: o,
|
|
715
715
|
children: a,
|
|
716
716
|
dom: r
|
|
717
717
|
};
|
|
@@ -723,17 +723,17 @@ function L(e, t, n) {
|
|
|
723
723
|
function r(c) {
|
|
724
724
|
return !!c && c.type !== "#whitespace" && !(c.type === "#text" && (!c.props?.nodeValue || /^\s*$/.test(c.props.nodeValue)));
|
|
725
725
|
}
|
|
726
|
-
const
|
|
726
|
+
const o = Array.isArray(t.children) ? t.children.filter(r) : [], s = Array.isArray(n.children) ? n.children.filter(r) : [], i = n.type === "input" || n.type === "select" || n.type === "textarea";
|
|
727
727
|
if (t.type !== n.type || t.key !== n.key) {
|
|
728
728
|
const c = g(n);
|
|
729
729
|
if (c instanceof Node && t.dom instanceof Node && e.contains(t.dom)) {
|
|
730
|
-
if (D(e, c, t.dom),
|
|
730
|
+
if (D(e, c, t.dom), i && n.props && e.firstChild instanceof HTMLInputElement) {
|
|
731
731
|
const l = e.firstChild;
|
|
732
732
|
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");
|
|
733
733
|
}
|
|
734
734
|
} else if (c instanceof Node)
|
|
735
735
|
if (c) {
|
|
736
|
-
if (e.appendChild(c), n.dom = c,
|
|
736
|
+
if (e.appendChild(c), n.dom = c, i && n.props && e.firstChild instanceof HTMLInputElement) {
|
|
737
737
|
const l = e.firstChild;
|
|
738
738
|
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");
|
|
739
739
|
}
|
|
@@ -743,7 +743,7 @@ function L(e, t, n) {
|
|
|
743
743
|
n.dom = void 0;
|
|
744
744
|
return;
|
|
745
745
|
}
|
|
746
|
-
if (
|
|
746
|
+
if (i && t.dom instanceof HTMLElement && n.props) {
|
|
747
747
|
for (const [c, l] of Object.entries(n.props))
|
|
748
748
|
if (c === "value" && e.firstChild instanceof HTMLInputElement)
|
|
749
749
|
e.firstChild.value = l;
|
|
@@ -756,8 +756,8 @@ function L(e, t, n) {
|
|
|
756
756
|
}
|
|
757
757
|
else
|
|
758
758
|
t.dom.setAttribute(c, l);
|
|
759
|
-
for (let c = n.children.length; c <
|
|
760
|
-
|
|
759
|
+
for (let c = n.children.length; c < o.length; c++)
|
|
760
|
+
o[c] && o[c].dom && t.dom && t.dom.contains(o[c].dom) && t.dom.removeChild(o[c].dom);
|
|
761
761
|
return;
|
|
762
762
|
}
|
|
763
763
|
const a = t.dom;
|
|
@@ -791,11 +791,11 @@ function L(e, t, n) {
|
|
|
791
791
|
}
|
|
792
792
|
if (a instanceof Element) {
|
|
793
793
|
const c = /* @__PURE__ */ new Map();
|
|
794
|
-
|
|
794
|
+
o.forEach((u) => u.key && c.set(u.key, u));
|
|
795
795
|
const l = new Set(s.map((u) => u.key));
|
|
796
796
|
let d = [];
|
|
797
797
|
for (let u = 0; u < s.length; u++) {
|
|
798
|
-
const h = s[u], m = h.key ? c.get(h.key) :
|
|
798
|
+
const h = s[u], m = h.key ? c.get(h.key) : o[u];
|
|
799
799
|
let p;
|
|
800
800
|
const A = h.type === "input" || h.type === "select" || h.type === "textarea";
|
|
801
801
|
if (m && m.dom && (!A || m.type === h.type && m.key === h.key))
|
|
@@ -817,7 +817,7 @@ function L(e, t, n) {
|
|
|
817
817
|
}
|
|
818
818
|
h.dom = p, p && d.push(p);
|
|
819
819
|
}
|
|
820
|
-
for (
|
|
820
|
+
for (o.forEach((u) => {
|
|
821
821
|
!l.has(u.key) && u.dom && a.contains(u.dom) && a.removeChild(u.dom);
|
|
822
822
|
}); a.childNodes.length > s.length; )
|
|
823
823
|
a.removeChild(a.lastChild);
|
|
@@ -836,9 +836,9 @@ function L(e, t, n) {
|
|
|
836
836
|
}
|
|
837
837
|
}
|
|
838
838
|
function M(e, t) {
|
|
839
|
-
const n = [], r = t ? Object.keys(t) : [],
|
|
839
|
+
const n = [], r = t ? Object.keys(t) : [], o = { ...e };
|
|
840
840
|
let s = null;
|
|
841
|
-
function
|
|
841
|
+
function i(d) {
|
|
842
842
|
return n.push(d), () => {
|
|
843
843
|
const f = n.indexOf(d);
|
|
844
844
|
f !== -1 && n.splice(f, 1);
|
|
@@ -852,7 +852,7 @@ function M(e, t) {
|
|
|
852
852
|
if (c.has(d)) return c.get(d);
|
|
853
853
|
const f = new Proxy(d, {
|
|
854
854
|
get(u, h, m) {
|
|
855
|
-
if (h === "subscribe") return
|
|
855
|
+
if (h === "subscribe") return i;
|
|
856
856
|
if (h === "set") return a;
|
|
857
857
|
if (t && r.includes(h))
|
|
858
858
|
return t[h](s);
|
|
@@ -874,7 +874,7 @@ function M(e, t) {
|
|
|
874
874
|
});
|
|
875
875
|
return c.set(d, f), f;
|
|
876
876
|
}
|
|
877
|
-
return s = l(
|
|
877
|
+
return s = l(o), s;
|
|
878
878
|
}
|
|
879
879
|
const v = [];
|
|
880
880
|
function ct(e) {
|
|
@@ -882,11 +882,11 @@ function ct(e) {
|
|
|
882
882
|
}
|
|
883
883
|
function _(e, t = /* @__PURE__ */ new WeakSet()) {
|
|
884
884
|
if (e === null || typeof e != "object" || t.has(e)) return e;
|
|
885
|
-
if (t.add(e), Array.isArray(e)) return e.map((
|
|
885
|
+
if (t.add(e), Array.isArray(e)) return e.map((o) => _(o, t));
|
|
886
886
|
Object.getPrototypeOf(e) !== Object.prototype && Object.getPrototypeOf(e) !== null && Object.setPrototypeOf(e, null);
|
|
887
887
|
const n = ["__proto__", "constructor", "prototype"], r = /* @__PURE__ */ Object.create(null);
|
|
888
|
-
for (const
|
|
889
|
-
n.includes(
|
|
888
|
+
for (const o of Object.keys(e))
|
|
889
|
+
n.includes(o) || (r[o] = _(e[o], t));
|
|
890
890
|
return r;
|
|
891
891
|
}
|
|
892
892
|
function S(e) {
|
|
@@ -947,18 +947,18 @@ typeof HTMLElement < "u" && (P = class extends HTMLElement {
|
|
|
947
947
|
attributeChangedCallback(e, t, n) {
|
|
948
948
|
if (!(e === "__proto__" || e === "constructor" || e === "prototype") && this.stateObj && e in this.stateObj) {
|
|
949
949
|
const r = typeof this.config?.state?.[e];
|
|
950
|
-
let
|
|
950
|
+
let o = n;
|
|
951
951
|
if (n === null)
|
|
952
|
-
|
|
952
|
+
o = void 0;
|
|
953
953
|
else if (r === "number")
|
|
954
|
-
if (
|
|
955
|
-
|
|
954
|
+
if (o === void 0 || o === "")
|
|
955
|
+
o = this.config?.state?.[e];
|
|
956
956
|
else {
|
|
957
|
-
const s = Number(
|
|
958
|
-
|
|
957
|
+
const s = Number(o);
|
|
958
|
+
o = isNaN(s) ? this.config?.state?.[e] : s;
|
|
959
959
|
}
|
|
960
|
-
else r === "boolean" && (
|
|
961
|
-
|
|
960
|
+
else r === "boolean" && (o = o === "true");
|
|
961
|
+
o = _(o), this.stateObj[e] !== o && (this.config?.debug && console.log("[runtime] state update:", { name: e, value: o }), this.stateObj[e] = o, this.render());
|
|
962
962
|
}
|
|
963
963
|
}
|
|
964
964
|
/**
|
|
@@ -968,14 +968,14 @@ typeof HTMLElement < "u" && (P = class extends HTMLElement {
|
|
|
968
968
|
this.shadowRoot && (this.shadowRoot.querySelectorAll("input[data-model]").forEach((e) => {
|
|
969
969
|
const t = e.getAttribute("data-model");
|
|
970
970
|
if (!t || !this.stateObj || typeof this.stateObj[t] > "u") return;
|
|
971
|
-
const n = e, r = String(this.stateObj[t]),
|
|
971
|
+
const n = e, r = String(this.stateObj[t]), o = document.activeElement === n;
|
|
972
972
|
n._hasDirtyListener || (n.addEventListener("input", () => {
|
|
973
973
|
n._isDirty = !0;
|
|
974
974
|
}), n.addEventListener("blur", () => {
|
|
975
975
|
n._isDirty = !1;
|
|
976
976
|
}), n._hasDirtyListener = !0);
|
|
977
977
|
const s = !!n._isDirty;
|
|
978
|
-
|
|
978
|
+
o || s || n.type !== "radio" && n.type !== "checkbox" && n.value !== r && (n.value = r);
|
|
979
979
|
}), this.rebindEventListeners());
|
|
980
980
|
}
|
|
981
981
|
/**
|
|
@@ -993,12 +993,12 @@ typeof HTMLElement < "u" && (P = class extends HTMLElement {
|
|
|
993
993
|
if (!t || !this.stateObj || typeof this.stateObj[t] > "u") return;
|
|
994
994
|
const n = e, r = String(this.stateObj[t]);
|
|
995
995
|
if (n.type === "checkbox") {
|
|
996
|
-
const
|
|
997
|
-
if (Array.isArray(
|
|
998
|
-
n.checked =
|
|
996
|
+
const o = this.stateObj[t];
|
|
997
|
+
if (Array.isArray(o))
|
|
998
|
+
n.checked = o.includes(n.value);
|
|
999
999
|
else {
|
|
1000
|
-
const s = n.getAttribute("data-true-value"),
|
|
1001
|
-
s !== null ||
|
|
1000
|
+
const s = n.getAttribute("data-true-value"), i = n.getAttribute("data-false-value");
|
|
1001
|
+
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;
|
|
1002
1002
|
}
|
|
1003
1003
|
} else n.type === "radio" || (n.value = r);
|
|
1004
1004
|
}), this.shadowRoot.querySelectorAll("textarea[data-model]").forEach((e) => {
|
|
@@ -1019,17 +1019,17 @@ typeof HTMLElement < "u" && (P = class extends HTMLElement {
|
|
|
1019
1019
|
e._listItemModelListener && (e.removeEventListener("input", e._listItemModelListener), e.removeEventListener("change", e._listItemModelListener), delete e._listItemModelListener);
|
|
1020
1020
|
const n = t.match(/^([a-zA-Z0-9_]+)\[(\d+)\]\.([a-zA-Z0-9_]+)$/);
|
|
1021
1021
|
if (n) {
|
|
1022
|
-
const [,
|
|
1023
|
-
e instanceof HTMLInputElement && e.type === "checkbox" && (e.checked = !!(Array.isArray(c) && c[a] && c[a][
|
|
1022
|
+
const [, o, s, i] = n, a = parseInt(s, 10), c = this.stateObj[o];
|
|
1023
|
+
e instanceof HTMLInputElement && e.type === "checkbox" && (e.checked = !!(Array.isArray(c) && c[a] && c[a][i]));
|
|
1024
1024
|
const l = (d) => {
|
|
1025
|
-
!Array.isArray(c) || !c[a] || (e instanceof HTMLInputElement && e.type === "checkbox" ? c[a][
|
|
1025
|
+
!Array.isArray(c) || !c[a] || (e instanceof HTMLInputElement && e.type === "checkbox" ? c[a][i] = e.checked : c[a][i] = e.value);
|
|
1026
1026
|
};
|
|
1027
1027
|
e.addEventListener("input", l), e.addEventListener("change", l), e._listItemModelListener = l;
|
|
1028
1028
|
return;
|
|
1029
1029
|
}
|
|
1030
1030
|
const r = t.match(/^([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)((?:\|[a-zA-Z0-9_]+)*)$/);
|
|
1031
1031
|
if (r) {
|
|
1032
|
-
const [,
|
|
1032
|
+
const [, o, s, i] = r, a = this.stateObj[o], c = i ? i.split("|").map((d) => d.trim()).filter(Boolean) : [];
|
|
1033
1033
|
e instanceof HTMLInputElement && e.type === "checkbox" ? e.checked = !!(a && a[s]) : e instanceof HTMLInputElement && (e.value = a ? String(a[s] ?? "") : "");
|
|
1034
1034
|
const l = (d) => {
|
|
1035
1035
|
if (!a) return;
|
|
@@ -1053,8 +1053,8 @@ typeof HTMLElement < "u" && (P = class extends HTMLElement {
|
|
|
1053
1053
|
if (!(!n || !(n in this.stateObj)))
|
|
1054
1054
|
if (t instanceof HTMLInputElement)
|
|
1055
1055
|
if (t.type === "checkbox") {
|
|
1056
|
-
const r = this.stateObj[n],
|
|
1057
|
-
Array.isArray(r) ? t.checked = r.includes(t.value) :
|
|
1056
|
+
const r = this.stateObj[n], o = t.getAttribute("data-true-value"), s = t.getAttribute("data-false-value");
|
|
1057
|
+
Array.isArray(r) ? t.checked = r.includes(t.value) : o !== null || s !== null ? String(r) === o ? 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;
|
|
1058
1058
|
} else t.type === "radio" ? t.checked = t.value === String(this.stateObj[n]) : t.value = String(this.stateObj[n] ?? "");
|
|
1059
1059
|
else (t instanceof HTMLTextAreaElement || t instanceof HTMLSelectElement) && (t.value = String(this.stateObj[n] ?? ""));
|
|
1060
1060
|
}));
|
|
@@ -1087,20 +1087,20 @@ typeof HTMLElement < "u" && (P = class extends HTMLElement {
|
|
|
1087
1087
|
this.scheduleRender();
|
|
1088
1088
|
})), this.api = {
|
|
1089
1089
|
state: this.stateObj,
|
|
1090
|
-
emit: (s,
|
|
1091
|
-
onGlobal: (s,
|
|
1092
|
-
const a = C.on(s,
|
|
1090
|
+
emit: (s, i) => this.dispatchEvent(new CustomEvent(s, { detail: i, bubbles: !0 })),
|
|
1091
|
+
onGlobal: (s, i) => {
|
|
1092
|
+
const a = C.on(s, i);
|
|
1093
1093
|
return this._globalUnsubscribes.push(a), a;
|
|
1094
1094
|
},
|
|
1095
|
-
offGlobal: (s,
|
|
1096
|
-
emitGlobal: (s,
|
|
1095
|
+
offGlobal: (s, i) => C.off(s, i),
|
|
1096
|
+
emitGlobal: (s, i) => C.emit(s, i)
|
|
1097
1097
|
}, Object.keys(this.config).forEach((s) => {
|
|
1098
1098
|
if (s.startsWith("on") && s.length > 2 && typeof this.config[s] == "function") {
|
|
1099
|
-
const
|
|
1099
|
+
const i = s.charAt(2).toLowerCase() + s.slice(3), a = (c) => {
|
|
1100
1100
|
const l = c.detail ?? c;
|
|
1101
1101
|
this.config[s](l, this.api.state, this.api);
|
|
1102
1102
|
};
|
|
1103
|
-
this.addEventListener(
|
|
1103
|
+
this.addEventListener(i, a), this._autoWiredHandlers[i] || (this._autoWiredHandlers[i] = []), this._autoWiredHandlers[i].push(a);
|
|
1104
1104
|
}
|
|
1105
1105
|
}), this.attachShadow({ mode: "open" }), n.style) {
|
|
1106
1106
|
const s = document.createElement("style");
|
|
@@ -1109,22 +1109,22 @@ typeof HTMLElement < "u" && (P = class extends HTMLElement {
|
|
|
1109
1109
|
if (typeof this.config.hydrate == "function") {
|
|
1110
1110
|
const s = this.shadowRoot?.querySelectorAll("[data-hydrate]");
|
|
1111
1111
|
try {
|
|
1112
|
-
s && s.length > 0 ? s.forEach((
|
|
1112
|
+
s && s.length > 0 ? s.forEach((i) => {
|
|
1113
1113
|
try {
|
|
1114
|
-
this.config.hydrate(
|
|
1114
|
+
this.config.hydrate(i, this.stateObj, this.api);
|
|
1115
1115
|
} catch (a) {
|
|
1116
1116
|
typeof this.config.onError == "function" && this.config.onError(a instanceof Error ? a : new Error(String(a)), this.api.state, this.api), this._handleRenderError(a);
|
|
1117
1117
|
}
|
|
1118
1118
|
}) : this.config.hydrate(this.shadowRoot, this.stateObj, this.api);
|
|
1119
|
-
} catch (
|
|
1120
|
-
typeof this.config.onError == "function" && this.config.onError(
|
|
1119
|
+
} catch (i) {
|
|
1120
|
+
typeof this.config.onError == "function" && this.config.onError(i instanceof Error ? i : new Error(String(i)), this.api.state, this.api), this._handleRenderError(i);
|
|
1121
1121
|
}
|
|
1122
1122
|
}
|
|
1123
1123
|
if (this.hasAttribute("data-hydrated") ? this.processRefs() : this.render(), !this._mountedCalled && typeof this.config.onMounted == "function")
|
|
1124
1124
|
try {
|
|
1125
1125
|
const s = this.config.onMounted(this.api.state, this.api);
|
|
1126
|
-
S(s) ? s.catch((
|
|
1127
|
-
typeof this.config.onError == "function" && this.config.onError(
|
|
1126
|
+
S(s) ? s.catch((i) => {
|
|
1127
|
+
typeof this.config.onError == "function" && this.config.onError(i, this.api.state, this.api), this._handleRenderError(i);
|
|
1128
1128
|
}).finally(() => {
|
|
1129
1129
|
this._mountedCalled = !0;
|
|
1130
1130
|
}) : this._mountedCalled = !0;
|
|
@@ -1215,11 +1215,11 @@ typeof HTMLElement < "u" && (P = class extends HTMLElement {
|
|
|
1215
1215
|
if (!this.shadowRoot) return;
|
|
1216
1216
|
["data-on-input", "data-on-change", "data-on-blur", "data-on-click"].forEach((t) => {
|
|
1217
1217
|
this.shadowRoot.querySelectorAll(`[${t}]`).forEach((n) => {
|
|
1218
|
-
const r = t.replace("data-on-", ""),
|
|
1219
|
-
if (!
|
|
1218
|
+
const r = t.replace("data-on-", ""), o = n.getAttribute(t);
|
|
1219
|
+
if (!o || typeof this.config[o] != "function") return;
|
|
1220
1220
|
n._boundHandlers && n._boundHandlers[r] && n.removeEventListener(r, n._boundHandlers[r]);
|
|
1221
|
-
const s = this.config[
|
|
1222
|
-
n.addEventListener(r,
|
|
1221
|
+
const s = this.config[o], i = (a) => s.call(this, a);
|
|
1222
|
+
n.addEventListener(r, i), n._boundHandlers || (n._boundHandlers = {}), n._boundHandlers[r] = i;
|
|
1223
1223
|
});
|
|
1224
1224
|
}), Array.from(this.shadowRoot.children).forEach((t) => {
|
|
1225
1225
|
t instanceof HTMLElement && typeof t.rebindEventListeners == "function" && t.rebindEventListeners();
|
|
@@ -1235,15 +1235,15 @@ typeof HTMLElement < "u" && (P = class extends HTMLElement {
|
|
|
1235
1235
|
try {
|
|
1236
1236
|
let t = function(n) {
|
|
1237
1237
|
const r = /* @__PURE__ */ new WeakSet();
|
|
1238
|
-
function
|
|
1238
|
+
function o(s) {
|
|
1239
1239
|
if (s === null || typeof s != "object" || r.has(s)) return s;
|
|
1240
|
-
if (r.add(s), Array.isArray(s)) return s.map(
|
|
1241
|
-
const
|
|
1240
|
+
if (r.add(s), Array.isArray(s)) return s.map(o);
|
|
1241
|
+
const i = {};
|
|
1242
1242
|
for (const a in s)
|
|
1243
|
-
Object.prototype.hasOwnProperty.call(s, a) && (
|
|
1244
|
-
return
|
|
1243
|
+
Object.prototype.hasOwnProperty.call(s, a) && (i[a] = o(s[a]));
|
|
1244
|
+
return i;
|
|
1245
1245
|
}
|
|
1246
|
-
return
|
|
1246
|
+
return o(n);
|
|
1247
1247
|
};
|
|
1248
1248
|
if (typeof e == "string") {
|
|
1249
1249
|
let n = function(c) {
|
|
@@ -1254,14 +1254,14 @@ typeof HTMLElement < "u" && (P = class extends HTMLElement {
|
|
|
1254
1254
|
}, r = function(c) {
|
|
1255
1255
|
c.children.forEach(r);
|
|
1256
1256
|
};
|
|
1257
|
-
const
|
|
1257
|
+
const o = n(e), s = J(o);
|
|
1258
1258
|
r(s);
|
|
1259
|
-
const
|
|
1260
|
-
if (!
|
|
1259
|
+
const i = this.shadowRoot;
|
|
1260
|
+
if (!i)
|
|
1261
1261
|
return;
|
|
1262
|
-
let a =
|
|
1263
|
-
if (a || (a = document.createElement("style"),
|
|
1264
|
-
const c = Array.from(
|
|
1262
|
+
let a = i.querySelector("style");
|
|
1263
|
+
if (a || (a = document.createElement("style"), i.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") {
|
|
1264
|
+
const c = Array.from(i.childNodes).find(
|
|
1265
1265
|
(l) => l.nodeType === 1 && l !== a
|
|
1266
1266
|
);
|
|
1267
1267
|
if (c) {
|
|
@@ -1279,7 +1279,7 @@ typeof HTMLElement < "u" && (P = class extends HTMLElement {
|
|
|
1279
1279
|
} else
|
|
1280
1280
|
s.children.forEach((l) => {
|
|
1281
1281
|
const d = g(l);
|
|
1282
|
-
d &&
|
|
1282
|
+
d && i.appendChild(d), l.dom = d ?? void 0;
|
|
1283
1283
|
});
|
|
1284
1284
|
} else {
|
|
1285
1285
|
let c = Array.from(this.shadowRoot.childNodes).find(
|
|
@@ -1299,19 +1299,19 @@ typeof HTMLElement < "u" && (P = class extends HTMLElement {
|
|
|
1299
1299
|
} else {
|
|
1300
1300
|
const n = !this.shadowRoot.firstElementChild, r = this.lastCompiledTemplate?.id === e.id;
|
|
1301
1301
|
if (n) {
|
|
1302
|
-
const
|
|
1303
|
-
this.shadowRoot.appendChild(
|
|
1302
|
+
const o = j(e, this.stateObj, this.api);
|
|
1303
|
+
this.shadowRoot.appendChild(o);
|
|
1304
1304
|
} else if (r && this.shadowRoot.firstElementChild) {
|
|
1305
|
-
const
|
|
1306
|
-
V(e, this.shadowRoot.firstElementChild, this.stateObj, this.api,
|
|
1305
|
+
const o = this.lastState;
|
|
1306
|
+
V(e, this.shadowRoot.firstElementChild, this.stateObj, this.api, o || void 0);
|
|
1307
1307
|
} else {
|
|
1308
|
-
const
|
|
1308
|
+
const o = j(e, this.stateObj, this.api);
|
|
1309
1309
|
let s = this.shadowRoot.querySelector("style");
|
|
1310
1310
|
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 = "";
|
|
1311
|
-
let
|
|
1312
|
-
for (
|
|
1313
|
-
|
|
1314
|
-
|
|
1311
|
+
let i = this.shadowRoot.querySelector("[data-root]");
|
|
1312
|
+
for (i || (i = document.createElement("div"), i.setAttribute("data-root", ""), this.shadowRoot.appendChild(i)); i.firstChild; )
|
|
1313
|
+
i.removeChild(i.firstChild);
|
|
1314
|
+
i.appendChild(o);
|
|
1315
1315
|
}
|
|
1316
1316
|
this.lastCompiledTemplate = e;
|
|
1317
1317
|
}
|
|
@@ -1361,15 +1361,15 @@ typeof HTMLElement < "u" && (P = class extends HTMLElement {
|
|
|
1361
1361
|
const r = this.shadowRoot.querySelector(`[data-ref="${t}"]`);
|
|
1362
1362
|
if (r) {
|
|
1363
1363
|
e.has(r) || e.set(r, /* @__PURE__ */ new Set());
|
|
1364
|
-
const
|
|
1365
|
-
r.addEventListener = function(
|
|
1366
|
-
const l = `${
|
|
1367
|
-
|
|
1364
|
+
const o = e.get(r), s = r.addEventListener;
|
|
1365
|
+
r.addEventListener = function(i, a, c) {
|
|
1366
|
+
const l = `${i}`;
|
|
1367
|
+
o.has(l) || (o.add(l), s.call(r, i, a, c));
|
|
1368
1368
|
}, r.setAttribute("data-refs-processed", "true");
|
|
1369
1369
|
try {
|
|
1370
1370
|
n(r, this.api.state, this.api);
|
|
1371
|
-
} catch (
|
|
1372
|
-
this._handleRenderError(
|
|
1371
|
+
} catch (i) {
|
|
1372
|
+
this._handleRenderError(i);
|
|
1373
1373
|
}
|
|
1374
1374
|
}
|
|
1375
1375
|
});
|
|
@@ -1386,15 +1386,15 @@ typeof HTMLElement < "u" && (P = class extends HTMLElement {
|
|
|
1386
1386
|
const n = t;
|
|
1387
1387
|
Array.from(n.attributes).forEach((r) => {
|
|
1388
1388
|
if (r.name.startsWith("data-on-")) {
|
|
1389
|
-
const
|
|
1390
|
-
if (typeof
|
|
1391
|
-
n._boundHandlers && n._boundHandlers[
|
|
1389
|
+
const o = r.name.slice(8), s = r.value, i = this.config[s];
|
|
1390
|
+
if (typeof i == "function") {
|
|
1391
|
+
n._boundHandlers && n._boundHandlers[o] && n.removeEventListener(o, n._boundHandlers[o]);
|
|
1392
1392
|
const a = (c) => {
|
|
1393
|
-
|
|
1393
|
+
i.call(this.config, c, this.api.state, this.api), this.syncControlledInputsAndEvents();
|
|
1394
1394
|
};
|
|
1395
|
-
n.addEventListener(
|
|
1395
|
+
n.addEventListener(o, a), n._boundHandlers || (n._boundHandlers = {}), n._boundHandlers[o] = a;
|
|
1396
1396
|
} else
|
|
1397
|
-
this.config.debug && console.warn(`[runtime] Handler '${s}' not found on config for event '${
|
|
1397
|
+
this.config.debug && console.warn(`[runtime] Handler '${s}' not found on config for event '${o}'`, n);
|
|
1398
1398
|
}
|
|
1399
1399
|
}), t = e.nextNode();
|
|
1400
1400
|
}
|
|
@@ -1415,9 +1415,9 @@ typeof HTMLElement < "u" && (P = class extends HTMLElement {
|
|
|
1415
1415
|
}
|
|
1416
1416
|
});
|
|
1417
1417
|
function lt(e, t) {
|
|
1418
|
-
if (t = _(t), t.debug && console.log(`[runtime] Debugging component: ${e}`, t), !e || !t.template
|
|
1419
|
-
t && typeof t.onError == "function" && t.onError(new Error("Component requires tag
|
|
1420
|
-
state: t.state,
|
|
1418
|
+
if (t = _(t), t.debug && console.log(`[runtime] Debugging component: ${e}`, t), !e || !t.template) {
|
|
1419
|
+
t && typeof t.onError == "function" && t.onError(new Error("Component requires tag and template"), t.state ?? {}, {
|
|
1420
|
+
state: t.state ?? {},
|
|
1421
1421
|
emit: () => {
|
|
1422
1422
|
},
|
|
1423
1423
|
onGlobal: () => () => {
|
|
@@ -1429,11 +1429,11 @@ function lt(e, t) {
|
|
|
1429
1429
|
}), t && t.debug && console.error("[runtime] Malformed config:", { tag: e, config: t });
|
|
1430
1430
|
return;
|
|
1431
1431
|
}
|
|
1432
|
-
if (v.forEach((
|
|
1432
|
+
if (v.forEach((d) => {
|
|
1433
1433
|
try {
|
|
1434
|
-
|
|
1435
|
-
} catch (
|
|
1436
|
-
t && typeof t.onError == "function" && t.onError(
|
|
1434
|
+
d.onInit?.(t);
|
|
1435
|
+
} catch (f) {
|
|
1436
|
+
t && typeof t.onError == "function" && t.onError(f instanceof Error ? f : new Error(String(f)), t.state, {
|
|
1437
1437
|
state: t.state,
|
|
1438
1438
|
emit: () => {
|
|
1439
1439
|
},
|
|
@@ -1443,32 +1443,32 @@ function lt(e, t) {
|
|
|
1443
1443
|
},
|
|
1444
1444
|
emitGlobal: () => {
|
|
1445
1445
|
}
|
|
1446
|
-
}), t && t.debug && console.error("[runtime] Plugin onInit error:",
|
|
1446
|
+
}), t && t.debug && console.error("[runtime] Plugin onInit error:", f);
|
|
1447
1447
|
}
|
|
1448
1448
|
}), (typeof window < "u" && window.VITE_DEV_HMR || typeof import.meta < "u" && void 0) && customElements.get(e))
|
|
1449
1449
|
try {
|
|
1450
|
-
document.querySelectorAll(e).forEach((
|
|
1450
|
+
document.querySelectorAll(e).forEach((d) => d.remove()), window.customElements._definitions && delete window.customElements._definitions[e];
|
|
1451
1451
|
} catch {
|
|
1452
1452
|
}
|
|
1453
1453
|
if (customElements.get(e)) {
|
|
1454
1454
|
t.debug && console.warn(`[runtime] Component "${e}" already registered`);
|
|
1455
1455
|
return;
|
|
1456
1456
|
}
|
|
1457
|
-
const s = M(t.state, t.computed);
|
|
1457
|
+
const s = M(t.state ?? {}, t.computed);
|
|
1458
1458
|
t.state = s, t._subscribe = s.subscribe;
|
|
1459
|
-
const
|
|
1460
|
-
(
|
|
1459
|
+
const i = t.state ?? {}, a = Object.keys(i).filter(
|
|
1460
|
+
(d) => ["string", "number", "boolean"].includes(typeof i[d])
|
|
1461
1461
|
);
|
|
1462
|
-
class
|
|
1462
|
+
class c extends P {
|
|
1463
1463
|
static get observedAttributes() {
|
|
1464
|
-
return
|
|
1464
|
+
return a;
|
|
1465
1465
|
}
|
|
1466
1466
|
constructor() {
|
|
1467
1467
|
super();
|
|
1468
1468
|
}
|
|
1469
1469
|
}
|
|
1470
|
-
const
|
|
1471
|
-
typeof customElements < "u" && !customElements.get(e) && (window.__componentRegistry = window.__componentRegistry || {}, window.__componentRegistry[e] = t, customElements.define(e,
|
|
1470
|
+
const l = c;
|
|
1471
|
+
typeof customElements < "u" && !customElements.get(e) && (window.__componentRegistry = window.__componentRegistry || {}, window.__componentRegistry[e] = t, customElements.define(e, l));
|
|
1472
1472
|
}
|
|
1473
1473
|
export {
|
|
1474
1474
|
Q as Store,
|