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