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