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