wrec 0.21.0 → 0.21.2
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.es.js +354 -352
- package/package.json +3 -3
package/dist/wrec.es.js
CHANGED
|
@@ -1,67 +1,68 @@
|
|
|
1
|
-
var
|
|
2
|
-
throw TypeError(
|
|
1
|
+
var K = (r) => {
|
|
2
|
+
throw TypeError(r);
|
|
3
3
|
};
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
import
|
|
7
|
-
|
|
4
|
+
var D = (r, t, e) => t.has(r) || K("Cannot " + e);
|
|
5
|
+
var p = (r, t, e) => (D(r, t, "read from private field"), e ? e.call(r) : t.get(r)), E = (r, t, e) => t.has(r) ? K("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(r) : t.set(r, e), M = (r, t, e, s) => (D(r, t, "write to private field"), s ? s.call(r, e) : t.set(r, e), e), Z = (r, t, e) => (D(r, t, "access private method"), e);
|
|
6
|
+
import { HTMLElement as nt, NodeType as F, parse as rt, TextNode as ct } from "node-html-parser";
|
|
7
|
+
import X from "xss";
|
|
8
|
+
function G(r, t, e = "") {
|
|
8
9
|
const s = /* @__PURE__ */ new WeakMap(), o = {
|
|
9
10
|
// Intercept property reads.
|
|
10
11
|
// This creates nested proxies lazily.
|
|
11
|
-
get(i,
|
|
12
|
-
const c = Reflect.get(i,
|
|
12
|
+
get(i, n) {
|
|
13
|
+
const c = Reflect.get(i, n);
|
|
13
14
|
if (c === null || typeof c != "object") return c;
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
const
|
|
15
|
+
const a = s.get(c);
|
|
16
|
+
if (a) return a;
|
|
17
|
+
const f = e ? `${e}.${n}` : n, l = G(c, t, f);
|
|
17
18
|
return s.set(c, l), l;
|
|
18
19
|
},
|
|
19
20
|
// Intercept property writes.
|
|
20
|
-
set(i,
|
|
21
|
-
const
|
|
22
|
-
if (
|
|
23
|
-
Reflect.set(i,
|
|
24
|
-
const
|
|
25
|
-
t(
|
|
21
|
+
set(i, n, c) {
|
|
22
|
+
const a = Reflect.get(i, n);
|
|
23
|
+
if (a !== c) {
|
|
24
|
+
Reflect.set(i, n, c);
|
|
25
|
+
const f = e ? `${e}.${n}` : n;
|
|
26
|
+
t(f, a, c);
|
|
26
27
|
}
|
|
27
28
|
return !0;
|
|
28
29
|
}
|
|
29
30
|
};
|
|
30
|
-
return new Proxy(
|
|
31
|
+
return new Proxy(r, o);
|
|
31
32
|
}
|
|
32
|
-
function
|
|
33
|
+
function Q(r) {
|
|
33
34
|
const t = {};
|
|
34
|
-
for (const [e, s] of Object.entries(
|
|
35
|
+
for (const [e, s] of Object.entries(r)) {
|
|
35
36
|
const o = typeof s == "object" && s !== null;
|
|
36
|
-
t[e] = o ?
|
|
37
|
+
t[e] = o ? Q(s) : s;
|
|
37
38
|
}
|
|
38
39
|
return t;
|
|
39
40
|
}
|
|
40
|
-
const
|
|
41
|
-
let
|
|
41
|
+
const O = typeof window < "u" && typeof window.document < "u";
|
|
42
|
+
let U = class extends Error {
|
|
42
43
|
};
|
|
43
|
-
var
|
|
44
|
-
const
|
|
44
|
+
var T, H, m, N, $, w, _, tt;
|
|
45
|
+
const A = class A {
|
|
45
46
|
constructor(t, e, s) {
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
E(this, _);
|
|
48
|
+
E(this, H, /* @__PURE__ */ Symbol("objectId"));
|
|
48
49
|
// This cannot be replaced by a WeakMap<ChangeListener, Set<string>>
|
|
49
50
|
// because there is no way to iterate over the keys of a WeakMap.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (!t) throw new
|
|
55
|
-
if (
|
|
56
|
-
throw new
|
|
57
|
-
if (
|
|
51
|
+
E(this, m, []);
|
|
52
|
+
E(this, N);
|
|
53
|
+
E(this, $);
|
|
54
|
+
E(this, w);
|
|
55
|
+
if (!t) throw new U("name cannot be empty");
|
|
56
|
+
if (p(A, T).has(t))
|
|
57
|
+
throw new U(`WrecState with name "${t}" already exists`);
|
|
58
|
+
if (M(this, N, t), M(this, $, e), M(this, w, G({}, Z(this, _, tt).bind(this))), e && O) {
|
|
58
59
|
const o = sessionStorage.getItem("wrec-state-" + t), i = o ? JSON.parse(o) : void 0;
|
|
59
60
|
i && (s = i);
|
|
60
61
|
}
|
|
61
62
|
if (s)
|
|
62
63
|
for (const [o, i] of Object.entries(s))
|
|
63
64
|
this.addProperty(o, i);
|
|
64
|
-
|
|
65
|
+
p(A, T).set(t, this);
|
|
65
66
|
}
|
|
66
67
|
// This static method is useful for accessing a specific WrecState object
|
|
67
68
|
// from the DevTools console. For example:
|
|
@@ -74,22 +75,22 @@ const E = class E {
|
|
|
74
75
|
// state.color = 'blue';
|
|
75
76
|
// state.team.leader.name = 'Mark';
|
|
76
77
|
static get(t) {
|
|
77
|
-
return
|
|
78
|
+
return p(this, T).get(t);
|
|
78
79
|
}
|
|
79
80
|
/**
|
|
80
81
|
* @param listener - object that has a "changed" method
|
|
81
82
|
* @param map - map from state property paths to component properties
|
|
82
83
|
*/
|
|
83
84
|
addListener(t, e = {}) {
|
|
84
|
-
const s =
|
|
85
|
+
const s = p(this, m).find(
|
|
85
86
|
(o) => o.listenerRef.deref() === t
|
|
86
87
|
);
|
|
87
88
|
if (s) {
|
|
88
89
|
const { propertyMap: o } = s;
|
|
89
|
-
for (const [i,
|
|
90
|
-
o[i] =
|
|
90
|
+
for (const [i, n] of Object.entries(e))
|
|
91
|
+
o[i] = n;
|
|
91
92
|
} else
|
|
92
|
-
|
|
93
|
+
p(this, m).push({
|
|
93
94
|
listenerRef: new WeakRef(t),
|
|
94
95
|
propertyMap: e
|
|
95
96
|
});
|
|
@@ -98,38 +99,38 @@ const E = class E {
|
|
|
98
99
|
Object.defineProperty(this, t, {
|
|
99
100
|
enumerable: !0,
|
|
100
101
|
get() {
|
|
101
|
-
return
|
|
102
|
+
return p(this, w)[t];
|
|
102
103
|
},
|
|
103
104
|
set(s) {
|
|
104
|
-
|
|
105
|
+
p(this, w)[t] = s;
|
|
105
106
|
}
|
|
106
|
-
}),
|
|
107
|
+
}), p(this, w)[t] = e;
|
|
107
108
|
}
|
|
108
109
|
get id() {
|
|
109
|
-
return
|
|
110
|
+
return p(this, H);
|
|
110
111
|
}
|
|
111
112
|
// This is useful for debugging from the DevTools console.
|
|
112
113
|
// For example: state.log()
|
|
113
114
|
log() {
|
|
114
|
-
console.log("WrecState:",
|
|
115
|
-
for (const [t, e] of Object.entries(
|
|
115
|
+
console.log("WrecState:", p(this, N));
|
|
116
|
+
for (const [t, e] of Object.entries(p(this, w)))
|
|
116
117
|
console.log(` ${t} = ${JSON.stringify(e)}`);
|
|
117
118
|
}
|
|
118
119
|
removeListener(t) {
|
|
119
|
-
|
|
120
|
+
M(this, m, p(this, m).filter((e) => e.listenerRef.deref() !== t));
|
|
120
121
|
}
|
|
121
122
|
};
|
|
122
|
-
|
|
123
|
+
T = new WeakMap(), H = new WeakMap(), m = new WeakMap(), N = new WeakMap(), $ = new WeakMap(), w = new WeakMap(), _ = new WeakSet(), tt = function(t, e, s) {
|
|
123
124
|
const o = /* @__PURE__ */ new Set();
|
|
124
|
-
for (const i of
|
|
125
|
-
const
|
|
126
|
-
if (!
|
|
125
|
+
for (const i of p(this, m)) {
|
|
126
|
+
const n = i.listenerRef.deref();
|
|
127
|
+
if (!n)
|
|
127
128
|
o.add(i);
|
|
128
|
-
else if (
|
|
129
|
+
else if (O && n instanceof HTMLElement && !n.isConnected)
|
|
129
130
|
o.add(i);
|
|
130
131
|
else {
|
|
131
|
-
const { propertyMap: c } = i,
|
|
132
|
-
(
|
|
132
|
+
const { propertyMap: c } = i, a = Object.keys(c);
|
|
133
|
+
(a.length === 0 || a.includes(t)) && n.changed(
|
|
133
134
|
t,
|
|
134
135
|
c[t],
|
|
135
136
|
s,
|
|
@@ -138,32 +139,59 @@ g = new WeakMap(), R = new WeakMap(), p = new WeakMap(), v = new WeakMap(), C =
|
|
|
138
139
|
);
|
|
139
140
|
}
|
|
140
141
|
}
|
|
141
|
-
|
|
142
|
+
M(this, m, p(this, m).filter(
|
|
142
143
|
(i) => !o.has(i)
|
|
143
144
|
));
|
|
144
|
-
},
|
|
145
|
-
for (const [t, e] of
|
|
146
|
-
if (
|
|
147
|
-
const s =
|
|
145
|
+
}, E(A, T, /* @__PURE__ */ new Map()), O && window.addEventListener("beforeunload", () => {
|
|
146
|
+
for (const [t, e] of p(A, T).entries())
|
|
147
|
+
if (p(e, $)) {
|
|
148
|
+
const s = Q(e);
|
|
148
149
|
sessionStorage.setItem("wrec-state-" + t, JSON.stringify(s));
|
|
149
150
|
}
|
|
150
151
|
});
|
|
151
|
-
let
|
|
152
|
-
|
|
153
|
-
function
|
|
154
|
-
let e =
|
|
152
|
+
let z = A;
|
|
153
|
+
O && process.env.NODE_ENV === "development" && (window.WrecState = z);
|
|
154
|
+
function Y(r, t) {
|
|
155
|
+
let e = r;
|
|
155
156
|
for (const s of t.split("."))
|
|
156
157
|
e = e[s];
|
|
157
158
|
return e;
|
|
158
159
|
}
|
|
159
|
-
function
|
|
160
|
+
function at(r, t, e) {
|
|
160
161
|
const s = t.split("."), o = s.length - 1;
|
|
161
|
-
let i =
|
|
162
|
-
s.forEach((
|
|
163
|
-
c === o ? i[
|
|
162
|
+
let i = r;
|
|
163
|
+
s.forEach((n, c) => {
|
|
164
|
+
c === o ? i[n] = e : i = i[n];
|
|
164
165
|
});
|
|
165
166
|
}
|
|
166
|
-
const
|
|
167
|
+
const ft = /* @__PURE__ */ new Set(["input", "label", "option", "th"]);
|
|
168
|
+
function lt(r) {
|
|
169
|
+
const t = {
|
|
170
|
+
allowCommentTag: !0,
|
|
171
|
+
onTag: (o, i) => {
|
|
172
|
+
if (ft.has(o)) return i;
|
|
173
|
+
},
|
|
174
|
+
onTagAttr(o, i, n) {
|
|
175
|
+
if (i.startsWith("on")) return "";
|
|
176
|
+
},
|
|
177
|
+
safeAttrValue(o, i, n) {
|
|
178
|
+
return i === "class" || o === "a" && i === "href" && !n.startsWith("javascript") || o === "img" && i === "src" ? n : "";
|
|
179
|
+
},
|
|
180
|
+
stripIgnoreTagBody: ["script", "style", "iframe"],
|
|
181
|
+
whiteList: {
|
|
182
|
+
...X.getDefaultWhiteList(),
|
|
183
|
+
label: ["class", "for"],
|
|
184
|
+
span: ["class"]
|
|
185
|
+
}
|
|
186
|
+
}, e = [];
|
|
187
|
+
r = r.replace(/<!--[\s\S]*?-->/g, (o) => {
|
|
188
|
+
const i = `__COMMENT_${e.length}__`;
|
|
189
|
+
return e.push(o), i;
|
|
190
|
+
});
|
|
191
|
+
let s = X(r, t);
|
|
192
|
+
return s = s.replace(/__COMMENT_(\d+)__/g, (o, i) => e[i]), s;
|
|
193
|
+
}
|
|
194
|
+
const ht = /* @__PURE__ */ new Set([
|
|
167
195
|
"class",
|
|
168
196
|
"disabled",
|
|
169
197
|
"hidden",
|
|
@@ -171,131 +199,95 @@ const st = /* @__PURE__ */ new Set([
|
|
|
171
199
|
"tabindex",
|
|
172
200
|
"title"
|
|
173
201
|
]);
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
whenDefined: () => Promise.reject()
|
|
186
|
-
};
|
|
187
|
-
} else {
|
|
188
|
-
const n = /* @__PURE__ */ new Set([
|
|
189
|
-
"onblur",
|
|
190
|
-
"onchange",
|
|
191
|
-
"onclick",
|
|
192
|
-
"onfocus",
|
|
193
|
-
"oninput",
|
|
194
|
-
"onkeydown",
|
|
195
|
-
"onreset",
|
|
196
|
-
"onsubmit"
|
|
197
|
-
]);
|
|
198
|
-
J.addHook(
|
|
199
|
-
"uponSanitizeAttribute",
|
|
200
|
-
(t, e) => {
|
|
201
|
-
const { attrName: s } = e, o = s.toLowerCase();
|
|
202
|
-
n.has(o) && (e.forceKeepAttr = !0);
|
|
203
|
-
}
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
class A extends Error {
|
|
202
|
+
typeof window > "u" && (global.HTMLElement = nt, global.customElements = {
|
|
203
|
+
get: (r) => {
|
|
204
|
+
},
|
|
205
|
+
getName: () => "",
|
|
206
|
+
define: () => {
|
|
207
|
+
},
|
|
208
|
+
upgrade: () => {
|
|
209
|
+
},
|
|
210
|
+
whenDefined: () => Promise.reject()
|
|
211
|
+
});
|
|
212
|
+
class x extends Error {
|
|
207
213
|
}
|
|
208
|
-
const
|
|
209
|
-
function
|
|
210
|
-
return
|
|
214
|
+
const ut = /([a-zA-Z-]+)\s*:\s*([^;}]+)/g, et = "a-zA-Z_$", pt = et + "0-9", P = `[${et}][${pt}]*`, dt = /<!--\s*(.*?)\s*-->/, mt = /<(\w+)(?:\s[^>]*)?>((?:[^<]|<(?!\w))*?)<\/\1>/g, V = new RegExp(`^this\\.${P}$`), I = new RegExp(`this\\.${P}(\\.${P})*`, "g"), L = new RegExp(`this\\.${P}(\\.${P})*`), bt = 5;
|
|
215
|
+
function gt(r) {
|
|
216
|
+
return r instanceof HTMLButtonElement || r instanceof HTMLFieldSetElement || r instanceof HTMLInputElement || r instanceof HTMLSelectElement || r instanceof HTMLTextAreaElement || r instanceof b;
|
|
211
217
|
}
|
|
212
|
-
function
|
|
213
|
-
const s = document.createElement(
|
|
218
|
+
function St(r, t, e) {
|
|
219
|
+
const s = document.createElement(r);
|
|
214
220
|
if (t)
|
|
215
221
|
for (const [o, i] of Object.entries(t))
|
|
216
222
|
s.setAttribute(o, i);
|
|
217
223
|
return e && (s.innerHTML = e), s;
|
|
218
224
|
}
|
|
219
|
-
const
|
|
220
|
-
function
|
|
225
|
+
const yt = (r) => r === String ? "" : r === Number ? 0 : r === Boolean ? !1 : r === Array ? [] : r === Object ? {} : void 0;
|
|
226
|
+
function j(r) {
|
|
221
227
|
const t = [];
|
|
222
|
-
let e =
|
|
228
|
+
let e = r.firstElementChild;
|
|
223
229
|
for (; e; )
|
|
224
|
-
t.push(e), e.shadowRoot && t.push(
|
|
230
|
+
t.push(e), e.shadowRoot && t.push(...j(e.shadowRoot)), e.firstElementChild && t.push(...j(e)), e = e.nextElementSibling;
|
|
225
231
|
return t;
|
|
226
232
|
}
|
|
227
|
-
const
|
|
228
|
-
function
|
|
229
|
-
let e =
|
|
233
|
+
const S = (r) => r.substring(bt).split(".")[0];
|
|
234
|
+
function st(r, t) {
|
|
235
|
+
let e = r[0];
|
|
230
236
|
return t.forEach((s, o) => {
|
|
231
|
-
e += s +
|
|
237
|
+
e += s + r[o + 1];
|
|
232
238
|
}), e;
|
|
233
239
|
}
|
|
234
|
-
function
|
|
235
|
-
const t = typeof
|
|
240
|
+
function q(r) {
|
|
241
|
+
const t = typeof r;
|
|
236
242
|
return t === "string" || t === "number" || t === "boolean";
|
|
237
243
|
}
|
|
238
|
-
function
|
|
239
|
-
return
|
|
244
|
+
function C(r) {
|
|
245
|
+
return r.localName === "textarea";
|
|
240
246
|
}
|
|
241
|
-
function
|
|
242
|
-
const { localName: t } =
|
|
247
|
+
function J(r) {
|
|
248
|
+
const { localName: t } = r;
|
|
243
249
|
return t === "input" || t === "select";
|
|
244
250
|
}
|
|
245
|
-
const
|
|
246
|
-
function
|
|
247
|
-
return
|
|
248
|
-
}
|
|
249
|
-
function ht(n) {
|
|
250
|
-
let t = n.trim(), e = null;
|
|
251
|
-
/^\s*<tr[\s>]/i.test(t) ? (t = `<table><tbody>${t}</tbody></table>`, e = "tbody") : /^\s*<(td|th)[\s>]/i.test(t) ? (t = `<table><tbody><tr>${t}</tr></tbody></table>`, e = "tr") : /^\s*<option[\s>]/i.test(t) ? (t = `<select>${t}</select>`, e = "select") : /^\s*<col[\s>]/i.test(t) && (t = `<table><colgroup>${t}</colgroup></table>`, e = "colgroup");
|
|
252
|
-
const s = J.sanitize(t, {
|
|
253
|
-
ADD_TAGS: ["#comment"],
|
|
254
|
-
ALLOW_UNKNOWN_PROTOCOLS: !0,
|
|
255
|
-
RETURN_DOM_FRAGMENT: !0
|
|
256
|
-
});
|
|
257
|
-
if (e) {
|
|
258
|
-
const o = s.querySelector(e);
|
|
259
|
-
if (o) return o.childNodes;
|
|
260
|
-
}
|
|
261
|
-
return s.childNodes;
|
|
251
|
+
const Et = (r) => r.replace(/<!--[\s\S]*?-->/g, "");
|
|
252
|
+
function ot(r, t, e, s) {
|
|
253
|
+
return r.slice(0, t) + s + r.slice(t + e);
|
|
262
254
|
}
|
|
263
|
-
function
|
|
264
|
-
const t = Number(
|
|
265
|
-
if (isNaN(t)) throw new
|
|
255
|
+
function W(r) {
|
|
256
|
+
const t = Number(r);
|
|
257
|
+
if (isNaN(t)) throw new x(`can't convert "${r}" to a number`);
|
|
266
258
|
return t;
|
|
267
259
|
}
|
|
268
|
-
function
|
|
260
|
+
function it(r, t, e) {
|
|
269
261
|
const [s, o] = t.split(":");
|
|
270
|
-
if (
|
|
262
|
+
if (q(e))
|
|
271
263
|
if (typeof e == "boolean") {
|
|
272
|
-
e ?
|
|
273
|
-
const i =
|
|
274
|
-
|
|
264
|
+
e ? r.setAttribute(s, s) : r.removeAttribute(s);
|
|
265
|
+
const i = b.getPropName(s);
|
|
266
|
+
r[i] = e;
|
|
275
267
|
} else {
|
|
276
|
-
const i =
|
|
277
|
-
i !==
|
|
268
|
+
const i = r.getAttribute(t), n = String(e);
|
|
269
|
+
i !== n && (r.setAttribute(s, n), s === "value" && J(r) && (r.value = n));
|
|
278
270
|
}
|
|
279
271
|
else {
|
|
280
|
-
const i =
|
|
281
|
-
|
|
272
|
+
const i = b.getPropName(t);
|
|
273
|
+
r[i] = e;
|
|
282
274
|
}
|
|
283
275
|
}
|
|
284
|
-
function
|
|
276
|
+
function B(r, t, e) {
|
|
285
277
|
const [s, o] = t.split(":");
|
|
286
|
-
|
|
278
|
+
r instanceof CSSStyleRule ? r.style.setProperty(s, e) : (it(r, s, e), s === "value" && J(r) && (r.value = e));
|
|
287
279
|
}
|
|
288
|
-
async function
|
|
280
|
+
async function wt(r) {
|
|
289
281
|
const t = /* @__PURE__ */ new Set();
|
|
290
|
-
for (const s of
|
|
282
|
+
for (const s of j(r.content)) {
|
|
291
283
|
const { localName: o } = s;
|
|
292
284
|
o.includes("-") && t.add(o);
|
|
293
285
|
}
|
|
294
286
|
function e(s) {
|
|
295
287
|
return new Promise((o, i) => {
|
|
296
288
|
setTimeout(() => {
|
|
297
|
-
const
|
|
298
|
-
i(new Error(
|
|
289
|
+
const n = `custom element <${s}> not defined`;
|
|
290
|
+
i(new Error(n));
|
|
299
291
|
}, 1e3);
|
|
300
292
|
});
|
|
301
293
|
}
|
|
@@ -305,7 +297,7 @@ async function ut(n) {
|
|
|
305
297
|
)
|
|
306
298
|
);
|
|
307
299
|
}
|
|
308
|
-
class
|
|
300
|
+
class b extends HTMLElement {
|
|
309
301
|
// There is one instance of `attrToPropMap`, `properties`, `propToAttrMap`,
|
|
310
302
|
// `propToComputedMap`, and `propToExprsMap` per Wrec subclass,
|
|
311
303
|
// not one for only the Wrec class.
|
|
@@ -372,7 +364,7 @@ class d extends HTMLElement {
|
|
|
372
364
|
#u = /* @__PURE__ */ new Map();
|
|
373
365
|
static define(t) {
|
|
374
366
|
if (this.elementName = t, customElements.get(t))
|
|
375
|
-
throw new
|
|
367
|
+
throw new x(`custom element ${t} is already defined`);
|
|
376
368
|
customElements.define(t, this);
|
|
377
369
|
}
|
|
378
370
|
constructor() {
|
|
@@ -382,12 +374,12 @@ class d extends HTMLElement {
|
|
|
382
374
|
}
|
|
383
375
|
attributeChangedCallback(t, e, s) {
|
|
384
376
|
t === "disabled" && this.#m();
|
|
385
|
-
const o =
|
|
377
|
+
const o = b.getPropName(t);
|
|
386
378
|
if (this.#n(o)) {
|
|
387
379
|
const i = this.#M(o, String(s));
|
|
388
380
|
this[o] = i;
|
|
389
|
-
const
|
|
390
|
-
|
|
381
|
+
const n = this.#f[o];
|
|
382
|
+
n && this.setFormValue(n, String(i)), this.propertyChangedCallback(o, e, s);
|
|
391
383
|
}
|
|
392
384
|
}
|
|
393
385
|
// This applies multiple property changes and only updates
|
|
@@ -395,39 +387,39 @@ class d extends HTMLElement {
|
|
|
395
387
|
batchSet(t) {
|
|
396
388
|
this.#a = !0;
|
|
397
389
|
const e = this.#t.propToExprsMap, s = /* @__PURE__ */ new Set();
|
|
398
|
-
for (const [c,
|
|
399
|
-
this[c] =
|
|
400
|
-
const
|
|
401
|
-
for (const l of
|
|
390
|
+
for (const [c, a] of Object.entries(t)) {
|
|
391
|
+
this[c] = a;
|
|
392
|
+
const f = e.get(c) ?? [];
|
|
393
|
+
for (const l of f)
|
|
402
394
|
s.add(l);
|
|
403
395
|
}
|
|
404
|
-
const o = this.#t.propToComputedMap, i = /* @__PURE__ */ new Set(),
|
|
396
|
+
const o = this.#t.propToComputedMap, i = /* @__PURE__ */ new Set(), n = {};
|
|
405
397
|
for (const c of Object.keys(t)) {
|
|
406
|
-
const
|
|
407
|
-
for (const [
|
|
408
|
-
i.add(
|
|
398
|
+
const a = o.get(c) || [];
|
|
399
|
+
for (const [f, l] of a)
|
|
400
|
+
i.add(f), n[f] = l;
|
|
409
401
|
}
|
|
410
402
|
for (const c of i) {
|
|
411
|
-
const
|
|
412
|
-
this[c] = this.#s(
|
|
413
|
-
const
|
|
414
|
-
for (const l of
|
|
403
|
+
const a = n[c];
|
|
404
|
+
this[c] = this.#s(a);
|
|
405
|
+
const f = e.get(c) ?? [];
|
|
406
|
+
for (const l of f)
|
|
415
407
|
s.add(l);
|
|
416
408
|
}
|
|
417
409
|
for (; ; ) {
|
|
418
410
|
let c = !1;
|
|
419
|
-
for (const
|
|
420
|
-
const
|
|
421
|
-
JSON.stringify(l) !== JSON.stringify(
|
|
411
|
+
for (const a of i) {
|
|
412
|
+
const f = n[a], l = this.#s(f), u = this[a];
|
|
413
|
+
JSON.stringify(l) !== JSON.stringify(u) && (this[a] = l, c = !0);
|
|
422
414
|
}
|
|
423
415
|
if (!c) break;
|
|
424
416
|
}
|
|
425
417
|
this.#b([...s]), this.#a = !1;
|
|
426
418
|
}
|
|
427
|
-
async #
|
|
419
|
+
async #S() {
|
|
428
420
|
const t = this.#t;
|
|
429
421
|
let { template: e } = t;
|
|
430
|
-
e || (e = t.template = document.createElement("template"), e.innerHTML = t.buildHTML()), await
|
|
422
|
+
e || (e = t.template = document.createElement("template"), e.innerHTML = t.buildHTML()), await wt(e), this.shadowRoot.replaceChildren(e.content.cloneNode(!0));
|
|
431
423
|
}
|
|
432
424
|
static buildHTML() {
|
|
433
425
|
let t = `<style>
|
|
@@ -435,15 +427,15 @@ class d extends HTMLElement {
|
|
|
435
427
|
this.css && (t += this.css), t += `</style>
|
|
436
428
|
`;
|
|
437
429
|
let e = this.html.trim();
|
|
438
|
-
if (!e) throw new
|
|
430
|
+
if (!e) throw new x("static property html must be set");
|
|
439
431
|
return e.startsWith("<") || (e = `<span><!--${e}--></span>`), t + e;
|
|
440
432
|
}
|
|
441
433
|
changed(t, e, s) {
|
|
442
434
|
this[e] = s;
|
|
443
435
|
}
|
|
444
436
|
connectedCallback() {
|
|
445
|
-
this.#H(), this.#x(), this.#
|
|
446
|
-
this.hasAttribute("disabled") && this.#m(), this.#
|
|
437
|
+
this.#H(), this.#x(), this.#S().then(() => {
|
|
438
|
+
this.hasAttribute("disabled") && this.#m(), this.#v(this.shadowRoot), this.#g(this.shadowRoot), this.#C();
|
|
447
439
|
});
|
|
448
440
|
}
|
|
449
441
|
#C() {
|
|
@@ -460,38 +452,38 @@ class d extends HTMLElement {
|
|
|
460
452
|
}
|
|
461
453
|
#d(t, e, s) {
|
|
462
454
|
if (t === "class" || t === "style")
|
|
463
|
-
throw new
|
|
464
|
-
const o =
|
|
455
|
+
throw new x(`"${t}" is a reserved property`);
|
|
456
|
+
const o = b.getAttrName(t), i = this.hasAttribute(o);
|
|
465
457
|
e.required && !i && this.#e(this, o, "is a required attribute");
|
|
466
|
-
let
|
|
467
|
-
this.hasOwnProperty(t) && (
|
|
468
|
-
const { type: c } = e,
|
|
469
|
-
this[
|
|
458
|
+
let n = e.value;
|
|
459
|
+
this.hasOwnProperty(t) && (n = this[t], delete this[t]);
|
|
460
|
+
const { type: c } = e, a = c === Boolean ? n || i : s.includes(o) && i ? this.#T(t, o) : n || yt(c), f = "#" + t;
|
|
461
|
+
this[f] = a, e.computed && this.#R(t, e), Object.defineProperty(this, t, {
|
|
470
462
|
enumerable: !0,
|
|
471
463
|
get() {
|
|
472
|
-
return this[
|
|
464
|
+
return this[f];
|
|
473
465
|
},
|
|
474
466
|
set(l) {
|
|
475
|
-
c === Number && typeof l == "string" && (l =
|
|
476
|
-
const
|
|
477
|
-
if (l ===
|
|
478
|
-
this.#
|
|
479
|
-
const { state:
|
|
480
|
-
|
|
481
|
-
const
|
|
482
|
-
|
|
467
|
+
c === Number && typeof l == "string" && (l = W(l));
|
|
468
|
+
const u = this[f];
|
|
469
|
+
if (l === u) return;
|
|
470
|
+
this.#k(t, c, l), this[f] = l;
|
|
471
|
+
const { state: h, stateProp: d } = this.#t.properties[t];
|
|
472
|
+
d && at(h, d, l), this.#O(t, c, l, o), this.#a || (this.#L(t), this.#w(t)), this.#j(t, l);
|
|
473
|
+
const g = this.#f[t];
|
|
474
|
+
g && this.setFormValue(g, String(l)), this.propertyChangedCallback(t, u, l), e.dispatch && this.dispatch("change", {
|
|
483
475
|
tagName: this.localName,
|
|
484
476
|
property: t,
|
|
485
|
-
oldValue:
|
|
477
|
+
oldValue: u,
|
|
486
478
|
value: l
|
|
487
479
|
});
|
|
488
480
|
}
|
|
489
481
|
});
|
|
490
482
|
}
|
|
491
483
|
#m() {
|
|
492
|
-
const t = this.hasAttribute("disabled"), e =
|
|
484
|
+
const t = this.hasAttribute("disabled"), e = j(this.shadowRoot);
|
|
493
485
|
for (const s of e)
|
|
494
|
-
|
|
486
|
+
gt(s) && (s.disabled = t);
|
|
495
487
|
}
|
|
496
488
|
disconnectedCallback() {
|
|
497
489
|
this.#o.clear(), this.#l.clear(), this.#u.clear();
|
|
@@ -510,16 +502,16 @@ class d extends HTMLElement {
|
|
|
510
502
|
displayIfSet(t, e = "block") {
|
|
511
503
|
return `display: ${t ? e : "none"}`;
|
|
512
504
|
}
|
|
513
|
-
#
|
|
514
|
-
const e = t instanceof
|
|
505
|
+
#P(t) {
|
|
506
|
+
const e = t instanceof b;
|
|
515
507
|
for (const s of t.getAttributeNames()) {
|
|
516
|
-
const o = t.getAttribute(s), i = this.#
|
|
508
|
+
const o = t.getAttribute(s), i = this.#E(t, o);
|
|
517
509
|
if (i) {
|
|
518
|
-
const
|
|
519
|
-
|
|
520
|
-
let [c,
|
|
521
|
-
c === "value" && (
|
|
522
|
-
|
|
510
|
+
const n = this[i];
|
|
511
|
+
n === void 0 && this.#c(t, s, i), t[i] = n;
|
|
512
|
+
let [c, a] = s.split(":");
|
|
513
|
+
c === "value" && (a ? (t["on" + a] === void 0 && this.#e(t, s, "refers to an unsupported event name"), t.setAttribute(c, this[i])) : a = "change"), e && t.#u.set(
|
|
514
|
+
b.getPropName(c),
|
|
523
515
|
i
|
|
524
516
|
);
|
|
525
517
|
}
|
|
@@ -533,8 +525,8 @@ class d extends HTMLElement {
|
|
|
533
525
|
if (i instanceof HTMLElement)
|
|
534
526
|
this.#A(i, s);
|
|
535
527
|
else if (!(i instanceof CSSStyleRule)) {
|
|
536
|
-
const { element:
|
|
537
|
-
|
|
528
|
+
const { element: n, attrName: c } = i;
|
|
529
|
+
n instanceof CSSStyleRule ? n.style.setProperty(c, s) : B(n, c, s);
|
|
538
530
|
}
|
|
539
531
|
}
|
|
540
532
|
}
|
|
@@ -545,34 +537,34 @@ class d extends HTMLElement {
|
|
|
545
537
|
`const {${Object.keys(e).join(",")}} = context; return ${t};`
|
|
546
538
|
).call(this, e);
|
|
547
539
|
}
|
|
548
|
-
#
|
|
540
|
+
#N(t) {
|
|
549
541
|
const { localName: e } = t;
|
|
550
542
|
if (e === "style") {
|
|
551
543
|
const { sheet: s } = t, o = s?.cssRules ?? [], i = Array.from(o);
|
|
552
|
-
for (const
|
|
553
|
-
if (
|
|
554
|
-
const c = Array.from(
|
|
555
|
-
for (const
|
|
556
|
-
if (
|
|
557
|
-
const
|
|
558
|
-
this.#r(
|
|
544
|
+
for (const n of i)
|
|
545
|
+
if (n.constructor === CSSStyleRule) {
|
|
546
|
+
const c = Array.from(n.style);
|
|
547
|
+
for (const a of c)
|
|
548
|
+
if (a.startsWith("--")) {
|
|
549
|
+
const f = n.style.getPropertyValue(a);
|
|
550
|
+
this.#r(f, n, a);
|
|
559
551
|
}
|
|
560
552
|
}
|
|
561
553
|
} else {
|
|
562
554
|
let s = "";
|
|
563
|
-
if (
|
|
555
|
+
if (C(t)) {
|
|
564
556
|
this.#r(t.textContent, t);
|
|
565
|
-
const o = t.textContent?.match(
|
|
557
|
+
const o = t.textContent?.match(dt);
|
|
566
558
|
o && (s = o[1]);
|
|
567
559
|
} else {
|
|
568
560
|
const o = Array.from(t.childNodes).find(
|
|
569
|
-
(i) => i.nodeType ===
|
|
561
|
+
(i) => i.nodeType === F.COMMENT_NODE
|
|
570
562
|
);
|
|
571
563
|
o && (s = o.textContent?.trim() ?? "");
|
|
572
564
|
}
|
|
573
565
|
if (s) {
|
|
574
|
-
const o = this.#
|
|
575
|
-
o &&
|
|
566
|
+
const o = this.#E(t, s);
|
|
567
|
+
o && C(t) ? t.textContent = this[o] : this.#r(s, t);
|
|
576
568
|
}
|
|
577
569
|
}
|
|
578
570
|
}
|
|
@@ -583,30 +575,30 @@ class d extends HTMLElement {
|
|
|
583
575
|
formAssociatedCallback() {
|
|
584
576
|
let t = this.getAttribute("form-assoc");
|
|
585
577
|
if (!t) {
|
|
586
|
-
const
|
|
587
|
-
if (
|
|
578
|
+
const n = this.getAttribute("name");
|
|
579
|
+
if (n)
|
|
588
580
|
if (this.#n("value"))
|
|
589
|
-
t = `value:${
|
|
581
|
+
t = `value:${n}`;
|
|
590
582
|
else
|
|
591
583
|
return;
|
|
592
584
|
else
|
|
593
585
|
return;
|
|
594
586
|
}
|
|
595
587
|
const e = {}, s = t.split(",");
|
|
596
|
-
for (const
|
|
597
|
-
const [c,
|
|
598
|
-
e[c.trim()] =
|
|
588
|
+
for (const n of s) {
|
|
589
|
+
const [c, a] = n.split(":");
|
|
590
|
+
e[c.trim()] = a.trim();
|
|
599
591
|
}
|
|
600
592
|
this.#f = e, this.#i = new FormData(), this.#h = this.attachInternals(), this.#h.setFormValue(this.#i);
|
|
601
593
|
const o = Object.keys(this.#t.properties), i = this.#l;
|
|
602
|
-
for (const
|
|
603
|
-
i[
|
|
594
|
+
for (const n of o)
|
|
595
|
+
i[n] = this[n];
|
|
604
596
|
}
|
|
605
597
|
formResetCallback() {
|
|
606
598
|
const t = this.#l;
|
|
607
599
|
for (const e of Object.keys(t)) {
|
|
608
600
|
let s = t[e];
|
|
609
|
-
|
|
601
|
+
V.test(s) && (s = this.#s(s)), this[e] = s;
|
|
610
602
|
}
|
|
611
603
|
}
|
|
612
604
|
static getAttrName(t) {
|
|
@@ -620,29 +612,29 @@ class d extends HTMLElement {
|
|
|
620
612
|
#$(t, e, s) {
|
|
621
613
|
if (s.length !== 1) return;
|
|
622
614
|
const [o] = s;
|
|
623
|
-
if (!
|
|
624
|
-
const i =
|
|
625
|
-
let [
|
|
626
|
-
if (!(i &&
|
|
615
|
+
if (!V.test(o)) return;
|
|
616
|
+
const i = J(t) || C(t);
|
|
617
|
+
let [n, c] = (e ?? "").split(":");
|
|
618
|
+
if (!(i && n === "value" || C(t))) return;
|
|
627
619
|
c ? t["on" + c] === void 0 && this.#e(t, e, "refers to an unsupported event name") : c = "change";
|
|
628
|
-
const
|
|
620
|
+
const f = S(o);
|
|
629
621
|
t.addEventListener(c, (l) => {
|
|
630
|
-
const { target:
|
|
631
|
-
if (!
|
|
632
|
-
const
|
|
633
|
-
this[
|
|
622
|
+
const { target: u } = l;
|
|
623
|
+
if (!u) return;
|
|
624
|
+
const h = u.value, { type: d } = this.#t.properties[f];
|
|
625
|
+
this[f] = d === Number ? W(h) : h, this.#w(f);
|
|
634
626
|
});
|
|
635
627
|
}
|
|
636
628
|
#n(t) {
|
|
637
629
|
return !!this.#t.properties[t];
|
|
638
630
|
}
|
|
639
|
-
#
|
|
631
|
+
#g(t) {
|
|
640
632
|
const e = Array.from(t.querySelectorAll("*"));
|
|
641
633
|
for (const s of e)
|
|
642
|
-
this.#
|
|
634
|
+
this.#P(s), s.firstElementChild || this.#N(s);
|
|
643
635
|
}
|
|
644
636
|
// formAssociated is only needed when the component is inside a form.
|
|
645
|
-
#
|
|
637
|
+
#y() {
|
|
646
638
|
if (this.#t.formAssociated || this.closest("form") === null) return;
|
|
647
639
|
const t = this.#t.name;
|
|
648
640
|
this.#e(
|
|
@@ -653,36 +645,36 @@ class d extends HTMLElement {
|
|
|
653
645
|
}
|
|
654
646
|
static get observedAttributes() {
|
|
655
647
|
const t = Object.keys(this.properties || {}).map(
|
|
656
|
-
(e) =>
|
|
648
|
+
(e) => b.getAttrName(e)
|
|
657
649
|
);
|
|
658
650
|
return t.includes("disabled") || t.push("disabled"), t;
|
|
659
651
|
}
|
|
660
652
|
// Subclasses can override this to add functionality.
|
|
661
653
|
propertyChangedCallback(t, e, s) {
|
|
662
654
|
}
|
|
663
|
-
#
|
|
664
|
-
if (!e || !
|
|
665
|
-
const s =
|
|
655
|
+
#E(t, e) {
|
|
656
|
+
if (!e || !V.test(e)) return;
|
|
657
|
+
const s = S(e);
|
|
666
658
|
return this[s] === void 0 && this.#c(t, "", s), s;
|
|
667
659
|
}
|
|
668
|
-
#
|
|
660
|
+
#w(t) {
|
|
669
661
|
const e = this.#t.propToExprsMap.get(t) || [];
|
|
670
662
|
this.#b(e);
|
|
671
663
|
}
|
|
672
664
|
#R(t, e) {
|
|
673
665
|
const { computed: s, uses: o } = e, i = this.#t.propToComputedMap;
|
|
674
|
-
function
|
|
675
|
-
let l = i.get(
|
|
676
|
-
l || (l = [], i.set(
|
|
666
|
+
function n(a, f) {
|
|
667
|
+
let l = i.get(a);
|
|
668
|
+
l || (l = [], i.set(a, l)), l.push([t, f]);
|
|
677
669
|
}
|
|
678
|
-
const c = s.match(
|
|
679
|
-
for (const
|
|
680
|
-
const
|
|
681
|
-
this[
|
|
670
|
+
const c = s.match(I) || [];
|
|
671
|
+
for (const a of c) {
|
|
672
|
+
const f = S(a);
|
|
673
|
+
this[f] === void 0 && this.#c(null, t, f), typeof this[f] != "function" && n(f, s);
|
|
682
674
|
}
|
|
683
675
|
if (o)
|
|
684
|
-
for (const
|
|
685
|
-
|
|
676
|
+
for (const a of o.split(","))
|
|
677
|
+
n(a.trim(), s);
|
|
686
678
|
}
|
|
687
679
|
// WARNING: Do not place untrusted JavaScript expressions
|
|
688
680
|
// in attribute values or the text content of elements!
|
|
@@ -690,30 +682,30 @@ class d extends HTMLElement {
|
|
|
690
682
|
if (!t) return;
|
|
691
683
|
const o = this.#p(e, s, t);
|
|
692
684
|
if (!o) {
|
|
693
|
-
const
|
|
694
|
-
s ?
|
|
685
|
+
const a = t.replaceAll("this..", "this.");
|
|
686
|
+
s ? B(e, s, a) : "textContent" in e && (e.textContent = a);
|
|
695
687
|
return;
|
|
696
688
|
}
|
|
697
689
|
const i = this.#t;
|
|
698
|
-
o.forEach((
|
|
699
|
-
const
|
|
700
|
-
if (typeof this[
|
|
690
|
+
o.forEach((a) => {
|
|
691
|
+
const f = S(a);
|
|
692
|
+
if (typeof this[f] == "function") return;
|
|
701
693
|
const l = i.propToExprsMap;
|
|
702
|
-
let
|
|
703
|
-
|
|
694
|
+
let u = l.get(f);
|
|
695
|
+
u || (u = [], l.set(f, u)), u.includes(t) || u.push(t);
|
|
704
696
|
});
|
|
705
|
-
for (const [
|
|
706
|
-
for (const l of
|
|
707
|
-
const
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
697
|
+
for (const [a, f] of this.#o.entries())
|
|
698
|
+
for (const l of f) {
|
|
699
|
+
const u = l instanceof HTMLElement || l instanceof CSSStyleRule ? l : l.element;
|
|
700
|
+
u instanceof CSSStyleRule || u.isConnected || this.#o.set(
|
|
701
|
+
a,
|
|
702
|
+
f.filter((h) => h !== l)
|
|
711
703
|
);
|
|
712
704
|
}
|
|
713
|
-
let
|
|
714
|
-
|
|
705
|
+
let n = this.#o.get(t);
|
|
706
|
+
n || (n = [], this.#o.set(t, n)), n.push(s ? { element: e, attrName: s } : e), e instanceof HTMLElement && this.#$(e, s, o);
|
|
715
707
|
const c = this.#s(t);
|
|
716
|
-
s ?
|
|
708
|
+
s ? B(e, s, c) : this.#A(e, c);
|
|
717
709
|
}
|
|
718
710
|
// This follows the best practice
|
|
719
711
|
// "Do not override author-set, global attributes."
|
|
@@ -721,50 +713,60 @@ class d extends HTMLElement {
|
|
|
721
713
|
this.hasAttribute(t) || this.setAttribute(t, e);
|
|
722
714
|
}
|
|
723
715
|
setFormValue(t, e) {
|
|
724
|
-
!this.#i || !
|
|
716
|
+
!this.#i || !q(e) || (this.#i.set(t, e), this.#h?.setFormValue(this.#i));
|
|
725
717
|
}
|
|
726
718
|
static ssr(t = {}) {
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
return new Function("return " + a).call(t);
|
|
734
|
-
}
|
|
735
|
-
let s = "";
|
|
736
|
-
for (const [a, l] of Object.entries(t)) {
|
|
737
|
-
const h = this.getAttrName(a);
|
|
738
|
-
s += ` ${h}="${l}"`;
|
|
719
|
+
let e = "";
|
|
720
|
+
const s = Object.keys(t);
|
|
721
|
+
s.sort();
|
|
722
|
+
for (const h of s) {
|
|
723
|
+
const d = this.getAttrName(h);
|
|
724
|
+
e += ` ${d}="${t[h]}"`;
|
|
739
725
|
}
|
|
740
|
-
const o = this.
|
|
741
|
-
for (const
|
|
742
|
-
|
|
743
|
-
const { value:
|
|
744
|
-
|
|
726
|
+
const o = this.properties;
|
|
727
|
+
for (const [h, d] of Object.entries(o))
|
|
728
|
+
if (t[h] === void 0) {
|
|
729
|
+
const { value: g } = d;
|
|
730
|
+
g !== void 0 && (t[h] = g);
|
|
745
731
|
}
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
732
|
+
function i(h) {
|
|
733
|
+
return new Function("return " + h).call(t);
|
|
734
|
+
}
|
|
735
|
+
function n(h) {
|
|
736
|
+
const { attributes: d } = h;
|
|
737
|
+
for (const [y, R] of Object.entries(d))
|
|
738
|
+
if (L.test(R)) {
|
|
739
|
+
const v = i(R), k = o[y].value;
|
|
740
|
+
v === k ? h.removeAttribute(y) : h.setAttribute(y, v);
|
|
741
|
+
}
|
|
742
|
+
const { childNodes: g } = h;
|
|
743
|
+
g.forEach((y, R) => {
|
|
744
|
+
if (y.nodeType === F.ELEMENT_NODE)
|
|
745
|
+
n(y);
|
|
746
|
+
else if (y.nodeType === F.COMMENT_NODE) {
|
|
747
|
+
const v = y.textContent ?? "";
|
|
748
|
+
if (L.test(v)) {
|
|
749
|
+
const k = i(v);
|
|
750
|
+
g[R] = new ct(k);
|
|
752
751
|
}
|
|
753
752
|
}
|
|
753
|
+
});
|
|
754
754
|
}
|
|
755
|
-
const c =
|
|
756
|
-
|
|
755
|
+
const c = this.buildHTML(), a = rt(c, { comment: !0 }), { children: f } = a;
|
|
756
|
+
f.forEach(n);
|
|
757
|
+
const l = f.map((h) => h.outerHTML).join(`
|
|
758
|
+
`), { elementName: u } = this;
|
|
757
759
|
return `
|
|
758
|
-
<${
|
|
760
|
+
<${u}${e}>
|
|
759
761
|
<template shadowrootmode="open">
|
|
760
|
-
${
|
|
762
|
+
${l}
|
|
761
763
|
</template>
|
|
762
|
-
</${
|
|
764
|
+
</${u}>
|
|
763
765
|
`;
|
|
764
766
|
}
|
|
765
767
|
#e(t, e, s) {
|
|
766
768
|
const o = t instanceof HTMLElement ? t.localName : "CSS rule";
|
|
767
|
-
throw new
|
|
769
|
+
throw new x(
|
|
768
770
|
`component ${this.#t.elementName}` + (t ? `, element "${o}"` : "") + (e ? `, attribute "${e}"` : "") + ` ${s}`
|
|
769
771
|
);
|
|
770
772
|
}
|
|
@@ -775,10 +777,10 @@ class d extends HTMLElement {
|
|
|
775
777
|
return this.#M(t, this.getAttribute(e));
|
|
776
778
|
}
|
|
777
779
|
#M(t, e) {
|
|
778
|
-
if (e?.match(
|
|
780
|
+
if (e?.match(I)) return e;
|
|
779
781
|
const s = this.#t, { type: o } = s.properties[t];
|
|
780
782
|
if (o || this.#e(null, t, "does not specify its type"), o === String) return e;
|
|
781
|
-
if (o === Number) return
|
|
783
|
+
if (o === Number) return W(e);
|
|
782
784
|
if (o === Boolean)
|
|
783
785
|
return e === "true" ? !0 : e === "false" || e === "null" ? !1 : (e && e !== t && this.#e(
|
|
784
786
|
null,
|
|
@@ -789,9 +791,9 @@ class d extends HTMLElement {
|
|
|
789
791
|
// Updates the matching attribute for a property.
|
|
790
792
|
// VS Code thinks this is never called, but it is called by #defineProp.
|
|
791
793
|
#O(t, e, s, o) {
|
|
792
|
-
if (
|
|
794
|
+
if (q(s)) {
|
|
793
795
|
const i = e === Boolean ? this.hasAttribute(o) : this.#T(t, o);
|
|
794
|
-
s !== i &&
|
|
796
|
+
s !== i && it(this, o || t, s);
|
|
795
797
|
}
|
|
796
798
|
}
|
|
797
799
|
// Updates all computed properties that reference this property.
|
|
@@ -812,11 +814,11 @@ class d extends HTMLElement {
|
|
|
812
814
|
" computed content is not a string or number"
|
|
813
815
|
);
|
|
814
816
|
const i = String(e);
|
|
815
|
-
if (t instanceof HTMLElement &&
|
|
817
|
+
if (t instanceof HTMLElement && C(t))
|
|
816
818
|
t.value = i;
|
|
817
819
|
else if (s && o === "string" && i.trim().startsWith("<")) {
|
|
818
|
-
const
|
|
819
|
-
t.
|
|
820
|
+
const n = lt(i);
|
|
821
|
+
t.innerHTML = n, this.#v(t), this.#g(t);
|
|
820
822
|
} else s && (t.textContent = i);
|
|
821
823
|
}
|
|
822
824
|
// Update corresponding parent web component property if bound to one.
|
|
@@ -828,8 +830,8 @@ class d extends HTMLElement {
|
|
|
828
830
|
if (!(o instanceof ShadowRoot)) return;
|
|
829
831
|
const { host: i } = o;
|
|
830
832
|
if (!i) return;
|
|
831
|
-
const
|
|
832
|
-
|
|
833
|
+
const n = i;
|
|
834
|
+
n[s] = e;
|
|
833
835
|
}
|
|
834
836
|
/**
|
|
835
837
|
* @param state - WrecState object
|
|
@@ -842,27 +844,27 @@ class d extends HTMLElement {
|
|
|
842
844
|
for (const s of Object.keys(t))
|
|
843
845
|
e[s] = s;
|
|
844
846
|
}
|
|
845
|
-
this.#
|
|
847
|
+
this.#_(t, e);
|
|
846
848
|
for (const [s, o] of Object.entries(e))
|
|
847
849
|
if (this.#n(o)) {
|
|
848
|
-
const i =
|
|
850
|
+
const i = Y(t, s);
|
|
849
851
|
i !== void 0 && (this[o] = i);
|
|
850
|
-
const
|
|
851
|
-
|
|
852
|
+
const n = this.#t.properties[o];
|
|
853
|
+
n.state = t, n.stateProp = s;
|
|
852
854
|
}
|
|
853
855
|
t.addListener(this, e);
|
|
854
856
|
}
|
|
855
857
|
#H() {
|
|
856
858
|
const t = new Set(Object.keys(this.#t.properties));
|
|
857
859
|
for (const e of this.getAttributeNames())
|
|
858
|
-
if (!
|
|
860
|
+
if (!ht.has(e) && !e.startsWith("on")) {
|
|
859
861
|
if (e === "form-assoc") {
|
|
860
|
-
this.#
|
|
862
|
+
this.#y();
|
|
861
863
|
continue;
|
|
862
864
|
}
|
|
863
|
-
if (!t.has(
|
|
865
|
+
if (!t.has(b.getPropName(e))) {
|
|
864
866
|
if (e === "name") {
|
|
865
|
-
this.#
|
|
867
|
+
this.#y();
|
|
866
868
|
continue;
|
|
867
869
|
}
|
|
868
870
|
this.#e(null, e, "is not a supported attribute");
|
|
@@ -870,16 +872,16 @@ class d extends HTMLElement {
|
|
|
870
872
|
}
|
|
871
873
|
}
|
|
872
874
|
#p(t, e, s) {
|
|
873
|
-
const o = s.match(
|
|
875
|
+
const o = s.match(I);
|
|
874
876
|
if (o)
|
|
875
877
|
return o.forEach((i) => {
|
|
876
|
-
const
|
|
877
|
-
this[
|
|
878
|
+
const n = S(i);
|
|
879
|
+
this[n] === void 0 && this.#c(t, e, n);
|
|
878
880
|
}), o;
|
|
879
881
|
}
|
|
880
|
-
#
|
|
882
|
+
#_(t, e) {
|
|
881
883
|
for (const [s, o] of Object.entries(e)) {
|
|
882
|
-
let i =
|
|
884
|
+
let i = Y(t, s);
|
|
883
885
|
i === void 0 && this.#e(this, void 0, `invalid state path "${s}"`), i = this[o], this.#n(o) || this.#e(
|
|
884
886
|
null,
|
|
885
887
|
o,
|
|
@@ -889,7 +891,7 @@ class d extends HTMLElement {
|
|
|
889
891
|
}
|
|
890
892
|
// When type is an array, this can't validate the type of the array elements.
|
|
891
893
|
// This is called by #defineProp.
|
|
892
|
-
#
|
|
894
|
+
#k(t, e, s) {
|
|
893
895
|
if (s instanceof e) return;
|
|
894
896
|
let o = typeof s;
|
|
895
897
|
if (o === "object") {
|
|
@@ -906,19 +908,19 @@ class d extends HTMLElement {
|
|
|
906
908
|
`was set to a ${o}, but must be a ${e.name}`
|
|
907
909
|
);
|
|
908
910
|
}
|
|
909
|
-
#
|
|
911
|
+
#v(t) {
|
|
910
912
|
const e = Array.from(t.querySelectorAll("*"));
|
|
911
913
|
for (const s of e) {
|
|
912
914
|
const o = [];
|
|
913
915
|
for (const i of Array.from(s.attributes)) {
|
|
914
|
-
const
|
|
915
|
-
if (
|
|
916
|
-
let c =
|
|
916
|
+
const n = i.name;
|
|
917
|
+
if (n.startsWith("on")) {
|
|
918
|
+
let c = n.slice(2);
|
|
917
919
|
c = c[0].toLowerCase() + c.slice(1).toLowerCase();
|
|
918
|
-
const
|
|
919
|
-
this.#p(s,
|
|
920
|
-
let
|
|
921
|
-
typeof this[
|
|
920
|
+
const a = i.value;
|
|
921
|
+
this.#p(s, n, a);
|
|
922
|
+
let f;
|
|
923
|
+
typeof this[a] == "function" ? f = (l) => this[a](l) : (this.#p(s, n, a), f = () => this.#s(a)), s.addEventListener(c, f), o.push(n);
|
|
922
924
|
}
|
|
923
925
|
}
|
|
924
926
|
for (const i of o)
|
|
@@ -926,40 +928,40 @@ class d extends HTMLElement {
|
|
|
926
928
|
}
|
|
927
929
|
}
|
|
928
930
|
}
|
|
929
|
-
function
|
|
930
|
-
let e =
|
|
931
|
+
function Ct(r, ...t) {
|
|
932
|
+
let e = st(r, t);
|
|
931
933
|
for (; ; ) {
|
|
932
|
-
const s =
|
|
934
|
+
const s = ut.exec(e);
|
|
933
935
|
if (!s) break;
|
|
934
936
|
const o = s[2];
|
|
935
|
-
if (
|
|
937
|
+
if (L.test(o)) {
|
|
936
938
|
const i = s[1];
|
|
937
939
|
if (!i.startsWith("--")) {
|
|
938
|
-
const
|
|
940
|
+
const n = `--${i}: ${o};
|
|
939
941
|
${i}: var(--${i})`;
|
|
940
|
-
e =
|
|
942
|
+
e = ot(e, s.index, s[0].length, n);
|
|
941
943
|
}
|
|
942
944
|
}
|
|
943
945
|
}
|
|
944
946
|
return e;
|
|
945
947
|
}
|
|
946
|
-
function
|
|
947
|
-
let e =
|
|
948
|
+
function xt(r, ...t) {
|
|
949
|
+
let e = st(r, t);
|
|
948
950
|
for (; ; ) {
|
|
949
|
-
const s =
|
|
951
|
+
const s = mt.exec(e);
|
|
950
952
|
if (!s || s[1] === "style") break;
|
|
951
|
-
const o =
|
|
952
|
-
if (
|
|
953
|
-
const i = `<!-- ${o.trim()} -->`,
|
|
954
|
-
e =
|
|
953
|
+
const o = Et(s[2]);
|
|
954
|
+
if (L.test(o)) {
|
|
955
|
+
const i = `<!-- ${o.trim()} -->`, n = s.index + s[0].indexOf(">") + 1;
|
|
956
|
+
e = ot(e, n, o.length, i);
|
|
955
957
|
}
|
|
956
958
|
}
|
|
957
959
|
return e;
|
|
958
960
|
}
|
|
959
961
|
export {
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
962
|
+
b as Wrec,
|
|
963
|
+
z as WrecState,
|
|
964
|
+
St as createElement,
|
|
965
|
+
Ct as css,
|
|
966
|
+
xt as html
|
|
965
967
|
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "wrec",
|
|
3
3
|
"description": "a small library that greatly simplifies building web components",
|
|
4
4
|
"author": "R. Mark Volkmann",
|
|
5
|
-
"version": "0.21.
|
|
5
|
+
"version": "0.21.2",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"vite-plugin-dts": "^4.5.4"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"
|
|
50
|
-
"
|
|
49
|
+
"node-html-parser": "^7.1.0",
|
|
50
|
+
"xss": "^1.0.15"
|
|
51
51
|
}
|
|
52
52
|
}
|