wrec 0.22.1 → 0.22.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/wrec-ssr.d.ts +7 -2
- package/dist/wrec-ssr.es.js +41 -52
- package/dist/wrec.d.ts +6 -1
- package/dist/wrec.es.js +33 -32
- package/package.json +1 -1
package/dist/wrec-ssr.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
declare type ChangeListener = {
|
|
2
2
|
changed: (statePath: string, componentProperty: string, newValue: unknown, oldValue: unknown, state: WrecState) => void;
|
|
3
3
|
};
|
|
4
4
|
|
|
@@ -8,13 +8,18 @@ export declare function css(strings: TemplateStringsArray, ...values: unknown[])
|
|
|
8
8
|
|
|
9
9
|
export declare function html(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
10
10
|
|
|
11
|
+
declare const HTMLElementBase: {
|
|
12
|
+
new (): HTMLElement;
|
|
13
|
+
prototype: HTMLElement;
|
|
14
|
+
};
|
|
15
|
+
|
|
11
16
|
declare type LooseObject = Record<string, unknown>;
|
|
12
17
|
|
|
13
18
|
declare type StringToAny = Record<string, any>;
|
|
14
19
|
|
|
15
20
|
declare type StringToString = Record<string, string>;
|
|
16
21
|
|
|
17
|
-
export declare abstract class Wrec extends
|
|
22
|
+
export declare abstract class Wrec extends HTMLElementBase implements ChangeListener {
|
|
18
23
|
#private;
|
|
19
24
|
private static attrToPropMap;
|
|
20
25
|
private static propToAttrMap;
|
package/dist/wrec-ssr.es.js
CHANGED
|
@@ -1,71 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Wrec as
|
|
3
|
-
import { WrecState as
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
upgrade: () => {
|
|
13
|
-
},
|
|
14
|
-
whenDefined: () => Promise.reject(new Error("customElements is not available"))
|
|
15
|
-
});
|
|
16
|
-
R.ssr = function(o = {}) {
|
|
17
|
-
let l = "";
|
|
18
|
-
const m = Object.keys(o);
|
|
19
|
-
m.sort();
|
|
20
|
-
for (const t of m) {
|
|
21
|
-
const n = this.getAttrName(t);
|
|
22
|
-
l += ` ${n}="${o[t]}"`;
|
|
1
|
+
import { parse as S, NodeType as h, TextNode as O } from "node-html-parser";
|
|
2
|
+
import { Wrec as _ } from "./wrec.es.js";
|
|
3
|
+
import { WrecState as j, createElement as C, css as F, html as D } from "./wrec.es.js";
|
|
4
|
+
const $ = "a-zA-Z_$", w = $ + "0-9", T = `[${$}][${w}]*`, d = new RegExp(`this\\.${T}(\\.${T})*`), y = 5, A = (a) => a.substring(y).split(".")[0];
|
|
5
|
+
_.ssr = function(o = {}) {
|
|
6
|
+
let u = "";
|
|
7
|
+
const l = Object.keys(o);
|
|
8
|
+
l.sort();
|
|
9
|
+
for (const t of l) {
|
|
10
|
+
const s = this.getAttrName(t);
|
|
11
|
+
u += ` ${s}="${o[t]}"`;
|
|
23
12
|
}
|
|
24
|
-
const
|
|
25
|
-
for (const [t,
|
|
13
|
+
const f = this.properties;
|
|
14
|
+
for (const [t, s] of Object.entries(f))
|
|
26
15
|
if (o[t] === void 0) {
|
|
27
|
-
const { value:
|
|
28
|
-
|
|
16
|
+
const { value: n } = s;
|
|
17
|
+
n !== void 0 && (o[t] = n);
|
|
29
18
|
}
|
|
30
|
-
function
|
|
19
|
+
function m(t) {
|
|
31
20
|
return new Function("return " + t).call(o);
|
|
32
21
|
}
|
|
33
|
-
function
|
|
34
|
-
const { attributes:
|
|
35
|
-
for (const [e,
|
|
36
|
-
if (
|
|
37
|
-
const r =
|
|
38
|
-
r ===
|
|
22
|
+
function p(t) {
|
|
23
|
+
const { attributes: s } = t;
|
|
24
|
+
for (const [e, c] of Object.entries(s))
|
|
25
|
+
if (d.test(c)) {
|
|
26
|
+
const r = m(c), i = A(e), R = f[i]?.value ?? "";
|
|
27
|
+
r === R ? t.removeAttribute(e) : t.setAttribute(e, String(r));
|
|
39
28
|
}
|
|
40
|
-
const { childNodes:
|
|
41
|
-
|
|
42
|
-
if (e.nodeType ===
|
|
43
|
-
|
|
44
|
-
else if (e.nodeType ===
|
|
29
|
+
const { childNodes: n } = t;
|
|
30
|
+
n.forEach((e, c) => {
|
|
31
|
+
if (e.nodeType === h.ELEMENT_NODE)
|
|
32
|
+
p(e);
|
|
33
|
+
else if (e.nodeType === h.COMMENT_NODE) {
|
|
45
34
|
const r = e.textContent ?? "";
|
|
46
|
-
if (
|
|
47
|
-
const
|
|
48
|
-
|
|
35
|
+
if (d.test(r)) {
|
|
36
|
+
const i = m(r);
|
|
37
|
+
n[c] = new O(String(i));
|
|
49
38
|
}
|
|
50
39
|
}
|
|
51
40
|
});
|
|
52
41
|
}
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
`),
|
|
42
|
+
const b = this.buildHTML(), g = S(b, { comment: !0 }), { children: E } = g;
|
|
43
|
+
E.forEach(p);
|
|
44
|
+
const v = E.map((t) => t.outerHTML).join(`
|
|
45
|
+
`), N = this.elementName;
|
|
57
46
|
return `
|
|
58
|
-
<${
|
|
47
|
+
<${N}${u}>
|
|
59
48
|
<template shadowrootmode="open">
|
|
60
|
-
${
|
|
49
|
+
${v}
|
|
61
50
|
</template>
|
|
62
|
-
</${
|
|
51
|
+
</${N}>
|
|
63
52
|
`;
|
|
64
53
|
};
|
|
65
54
|
export {
|
|
66
|
-
|
|
67
|
-
|
|
55
|
+
_ as Wrec,
|
|
56
|
+
j as WrecState,
|
|
68
57
|
C as createElement,
|
|
69
|
-
|
|
70
|
-
|
|
58
|
+
F as css,
|
|
59
|
+
D as html
|
|
71
60
|
};
|
package/dist/wrec.d.ts
CHANGED
|
@@ -8,13 +8,18 @@ export declare function css(strings: TemplateStringsArray, ...values: unknown[])
|
|
|
8
8
|
|
|
9
9
|
export declare function html(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
10
10
|
|
|
11
|
+
declare const HTMLElementBase: {
|
|
12
|
+
new (): HTMLElement;
|
|
13
|
+
prototype: HTMLElement;
|
|
14
|
+
};
|
|
15
|
+
|
|
11
16
|
declare type LooseObject = Record<string, unknown>;
|
|
12
17
|
|
|
13
18
|
declare type StringToAny = Record<string, any>;
|
|
14
19
|
|
|
15
20
|
declare type StringToString = Record<string, string>;
|
|
16
21
|
|
|
17
|
-
export declare abstract class Wrec extends
|
|
22
|
+
export declare abstract class Wrec extends HTMLElementBase implements ChangeListener {
|
|
18
23
|
#private;
|
|
19
24
|
private static attrToPropMap;
|
|
20
25
|
private static propToAttrMap;
|
package/dist/wrec.es.js
CHANGED
|
@@ -206,7 +206,8 @@ const nt = /* @__PURE__ */ new Set([
|
|
|
206
206
|
"id",
|
|
207
207
|
"tabindex",
|
|
208
208
|
"title"
|
|
209
|
-
]),
|
|
209
|
+
]), rt = globalThis.HTMLElement ?? class {
|
|
210
|
+
}, F = globalThis.customElements ?? {
|
|
210
211
|
get: (n) => {
|
|
211
212
|
},
|
|
212
213
|
getName: () => "",
|
|
@@ -220,18 +221,18 @@ const nt = /* @__PURE__ */ new Set([
|
|
|
220
221
|
};
|
|
221
222
|
class E extends Error {
|
|
222
223
|
}
|
|
223
|
-
const
|
|
224
|
-
function
|
|
224
|
+
const ct = /([a-zA-Z-]+)\s*:\s*([^;}]+)/g, Y = "a-zA-Z_$", at = Y + "0-9", S = `[${Y}][${at}]*`, ft = /<!--\s*(.*?)\s*-->/, ht = /<(\w+)(?:\s[^>]*)?>((?:[^<]|<(?!\w))*?)<\/\1>/g, L = new RegExp(`^this\\.${S}$`), j = new RegExp(`this\\.${S}(\\.${S})*`, "g"), G = new RegExp(`this\\.${S}(\\.${S})*`), lt = 5;
|
|
225
|
+
function pt(n) {
|
|
225
226
|
return n instanceof HTMLButtonElement || n instanceof HTMLFieldSetElement || n instanceof HTMLInputElement || n instanceof HTMLSelectElement || n instanceof HTMLTextAreaElement || n instanceof u;
|
|
226
227
|
}
|
|
227
|
-
function
|
|
228
|
+
function wt(n, t, e) {
|
|
228
229
|
const s = document.createElement(n);
|
|
229
230
|
if (t)
|
|
230
231
|
for (const [o, i] of Object.entries(t))
|
|
231
232
|
s.setAttribute(o, i);
|
|
232
233
|
return e && (s.innerHTML = e), s;
|
|
233
234
|
}
|
|
234
|
-
const
|
|
235
|
+
const ut = (n) => n === String ? "" : n === Number ? 0 : n === Boolean ? !1 : n === Array ? [] : n === Object ? {} : void 0;
|
|
235
236
|
function R(n) {
|
|
236
237
|
const t = [];
|
|
237
238
|
let e = n.firstElementChild;
|
|
@@ -239,7 +240,7 @@ function R(n) {
|
|
|
239
240
|
t.push(e), e.shadowRoot && t.push(...R(e.shadowRoot)), e.firstElementChild && t.push(...R(e)), e = e.nextElementSibling;
|
|
240
241
|
return t;
|
|
241
242
|
}
|
|
242
|
-
const M = (n) => n.substring(
|
|
243
|
+
const M = (n) => n.substring(lt).split(".")[0];
|
|
243
244
|
function Q(n, t) {
|
|
244
245
|
let e = n[0];
|
|
245
246
|
return t.forEach((s, o) => {
|
|
@@ -257,11 +258,11 @@ function D(n) {
|
|
|
257
258
|
const { localName: t } = n;
|
|
258
259
|
return t === "input" || t === "select";
|
|
259
260
|
}
|
|
260
|
-
const
|
|
261
|
+
const dt = (n) => n.replace(/<!--[\s\S]*?-->/g, "");
|
|
261
262
|
function tt(n, t, e, s) {
|
|
262
263
|
return n.slice(0, t) + s + n.slice(t + e);
|
|
263
264
|
}
|
|
264
|
-
function
|
|
265
|
+
function H(n) {
|
|
265
266
|
const t = Number(n);
|
|
266
267
|
if (isNaN(t)) throw new E(`can't convert "${n}" to a number`);
|
|
267
268
|
return t;
|
|
@@ -282,11 +283,11 @@ function et(n, t, e) {
|
|
|
282
283
|
n[i] = e;
|
|
283
284
|
}
|
|
284
285
|
}
|
|
285
|
-
function
|
|
286
|
+
function k(n, t, e) {
|
|
286
287
|
const [s, o] = t.split(":");
|
|
287
288
|
n instanceof CSSStyleRule ? n.style.setProperty(s, e) : (et(n, s, e), s === "value" && D(n) && (n.value = e));
|
|
288
289
|
}
|
|
289
|
-
async function
|
|
290
|
+
async function mt(n) {
|
|
290
291
|
const t = /* @__PURE__ */ new Set();
|
|
291
292
|
for (const s of R(n.content)) {
|
|
292
293
|
const { localName: o } = s;
|
|
@@ -309,7 +310,7 @@ async function dt(n) {
|
|
|
309
310
|
)
|
|
310
311
|
);
|
|
311
312
|
}
|
|
312
|
-
class u extends
|
|
313
|
+
class u extends rt {
|
|
313
314
|
// There is one instance of `attrToPropMap`, `properties`, `propToAttrMap`,
|
|
314
315
|
// `propToComputedMap`, and `propToExprsMap` per Wrec subclass,
|
|
315
316
|
// not one for only the Wrec class.
|
|
@@ -435,7 +436,7 @@ class u extends HTMLElement {
|
|
|
435
436
|
async #x() {
|
|
436
437
|
const t = this.#t;
|
|
437
438
|
let { template: e } = t;
|
|
438
|
-
e || (e = t.template = document.createElement("template"), e.innerHTML = t.buildHTML()), await
|
|
439
|
+
e || (e = t.template = document.createElement("template"), e.innerHTML = t.buildHTML()), await mt(e), this.shadowRoot.replaceChildren(e.content.cloneNode(!0));
|
|
439
440
|
}
|
|
440
441
|
static buildHTML() {
|
|
441
442
|
let t = `<style>
|
|
@@ -473,19 +474,19 @@ class u extends HTMLElement {
|
|
|
473
474
|
e.required && !i && this.#e(this, o, "is a required attribute");
|
|
474
475
|
let r = e.value;
|
|
475
476
|
this.hasOwnProperty(t) && (r = this[t], delete this[t]);
|
|
476
|
-
const { type: c } = e, a = c === Boolean ? r || i : s.includes(o) && i ? this.#A(t, o) : r ||
|
|
477
|
+
const { type: c } = e, a = c === Boolean ? r || i : s.includes(o) && i ? this.#A(t, o) : r || ut(c), h = "#" + t;
|
|
477
478
|
this[h] = a, e.computed && this.#L(t, e), Object.defineProperty(this, t, {
|
|
478
479
|
enumerable: !0,
|
|
479
480
|
get() {
|
|
480
481
|
return this[h];
|
|
481
482
|
},
|
|
482
483
|
set(f) {
|
|
483
|
-
c === Number && typeof f == "string" && (f =
|
|
484
|
+
c === Number && typeof f == "string" && (f = H(f));
|
|
484
485
|
const l = this[h];
|
|
485
486
|
if (f === l) return;
|
|
486
487
|
this.#I(t, c, f), this[h] = f;
|
|
487
488
|
const m = this.#m.get(t);
|
|
488
|
-
m && st(m.state, m.stateProp, f), this.#j(t, c, f, o), this.#f || (this.#
|
|
489
|
+
m && st(m.state, m.stateProp, f), this.#j(t, c, f, o), this.#f || (this.#H(t), this.#M(t)), this.#k(t, f);
|
|
489
490
|
const x = this.#h[t];
|
|
490
491
|
x && this.setFormValue(x, String(f)), this.propertyChangedCallback(t, l, f), e.dispatch && this.dispatch("change", {
|
|
491
492
|
tagName: this.localName,
|
|
@@ -499,7 +500,7 @@ class u extends HTMLElement {
|
|
|
499
500
|
#g() {
|
|
500
501
|
const t = this.hasAttribute("disabled"), e = R(this.shadowRoot);
|
|
501
502
|
for (const s of e)
|
|
502
|
-
|
|
503
|
+
pt(s) && (s.disabled = t);
|
|
503
504
|
}
|
|
504
505
|
disconnectedCallback() {
|
|
505
506
|
this.#o.clear(), this.#l.clear(), this.#u.clear();
|
|
@@ -543,7 +544,7 @@ class u extends HTMLElement {
|
|
|
543
544
|
this.#v(i, s);
|
|
544
545
|
else if (!(i instanceof CSSStyleRule)) {
|
|
545
546
|
const { element: r, attrName: c } = i;
|
|
546
|
-
r instanceof CSSStyleRule ? r.style.setProperty(c, s) :
|
|
547
|
+
r instanceof CSSStyleRule ? r.style.setProperty(c, s) : k(r, c, s);
|
|
547
548
|
}
|
|
548
549
|
}
|
|
549
550
|
}
|
|
@@ -571,7 +572,7 @@ class u extends HTMLElement {
|
|
|
571
572
|
let s = "";
|
|
572
573
|
if (A(t)) {
|
|
573
574
|
this.#c(t.textContent, t);
|
|
574
|
-
const o = t.textContent?.match(
|
|
575
|
+
const o = t.textContent?.match(ft);
|
|
575
576
|
o && (s = o[1]);
|
|
576
577
|
} else {
|
|
577
578
|
const o = Array.from(t.childNodes).find(
|
|
@@ -639,7 +640,7 @@ class u extends HTMLElement {
|
|
|
639
640
|
const { target: l } = f;
|
|
640
641
|
if (!l) return;
|
|
641
642
|
const m = l.value, { type: x } = this.#t.properties[h];
|
|
642
|
-
this[h] = x === Number ?
|
|
643
|
+
this[h] = x === Number ? H(m) : m, this.#M(h);
|
|
643
644
|
});
|
|
644
645
|
}
|
|
645
646
|
#n(t) {
|
|
@@ -703,7 +704,7 @@ class u extends HTMLElement {
|
|
|
703
704
|
const o = this.#d(e, s, t);
|
|
704
705
|
if (!o) {
|
|
705
706
|
const a = t.replaceAll("this..", "this.");
|
|
706
|
-
s ?
|
|
707
|
+
s ? k(e, s, a) : "textContent" in e && (e.textContent = a);
|
|
707
708
|
return;
|
|
708
709
|
}
|
|
709
710
|
const i = this.#t;
|
|
@@ -725,7 +726,7 @@ class u extends HTMLElement {
|
|
|
725
726
|
let r = this.#o.get(t);
|
|
726
727
|
r || (r = [], this.#o.set(t, r)), r.push(s ? { element: e, attrName: s } : e), e instanceof HTMLElement && this.#O(e, s, o);
|
|
727
728
|
const c = this.#s(t);
|
|
728
|
-
s ?
|
|
729
|
+
s ? k(e, s, c) : this.#v(e, c);
|
|
729
730
|
}
|
|
730
731
|
// This follows the best practice
|
|
731
732
|
// "Do not override author-set, global attributes."
|
|
@@ -754,7 +755,7 @@ class u extends HTMLElement {
|
|
|
754
755
|
if (e?.match(j)) return e;
|
|
755
756
|
const s = this.#t, { type: o } = s.properties[t];
|
|
756
757
|
if (o || this.#e(null, t, "does not specify its type"), o === String) return e;
|
|
757
|
-
if (o === Number) return
|
|
758
|
+
if (o === Number) return H(e);
|
|
758
759
|
if (o === Boolean) {
|
|
759
760
|
if (e === "true") return !0;
|
|
760
761
|
if (e === "false" || e === "null") return !1;
|
|
@@ -776,7 +777,7 @@ class u extends HTMLElement {
|
|
|
776
777
|
}
|
|
777
778
|
// Updates all computed properties that reference this property.
|
|
778
779
|
// VS Code thinks this is never called, but it is called by #defineProp.
|
|
779
|
-
#
|
|
780
|
+
#H(t) {
|
|
780
781
|
const s = this.#t.propToComputedMap.get(t) || [];
|
|
781
782
|
for (const [o, i] of s)
|
|
782
783
|
this[o] = this.#s(i);
|
|
@@ -801,7 +802,7 @@ class u extends HTMLElement {
|
|
|
801
802
|
}
|
|
802
803
|
// Update corresponding parent web component property if bound to one.
|
|
803
804
|
// VS Code thinks this is never called, but it is called by #defineProp.
|
|
804
|
-
#
|
|
805
|
+
#k(t, e) {
|
|
805
806
|
const s = this.#u.get(t);
|
|
806
807
|
if (!s) return;
|
|
807
808
|
const o = this.getRootNode();
|
|
@@ -904,10 +905,10 @@ class u extends HTMLElement {
|
|
|
904
905
|
}
|
|
905
906
|
}
|
|
906
907
|
}
|
|
907
|
-
function
|
|
908
|
+
function Et(n, ...t) {
|
|
908
909
|
let e = Q(n, t);
|
|
909
910
|
for (; ; ) {
|
|
910
|
-
const s =
|
|
911
|
+
const s = ct.exec(e);
|
|
911
912
|
if (!s) break;
|
|
912
913
|
const o = s[2];
|
|
913
914
|
if (G.test(o)) {
|
|
@@ -921,12 +922,12 @@ function wt(n, ...t) {
|
|
|
921
922
|
}
|
|
922
923
|
return e;
|
|
923
924
|
}
|
|
924
|
-
function
|
|
925
|
+
function Tt(n, ...t) {
|
|
925
926
|
let e = Q(n, t);
|
|
926
927
|
for (; ; ) {
|
|
927
|
-
const s =
|
|
928
|
+
const s = ht.exec(e);
|
|
928
929
|
if (!s || s[1] === "style") break;
|
|
929
|
-
const o =
|
|
930
|
+
const o = dt(s[2]);
|
|
930
931
|
if (G.test(o)) {
|
|
931
932
|
const i = `<!-- ${o.trim()} -->`, r = s.index + s[0].indexOf(">") + 1;
|
|
932
933
|
e = tt(e, r, o.length, i);
|
|
@@ -937,7 +938,7 @@ function Et(n, ...t) {
|
|
|
937
938
|
export {
|
|
938
939
|
u as Wrec,
|
|
939
940
|
_ as WrecState,
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
941
|
+
wt as createElement,
|
|
942
|
+
Et as css,
|
|
943
|
+
Tt as html
|
|
943
944
|
};
|