wrec 0.16.9 → 0.17.1
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 +31 -6
- package/dist/wrec.es.js +268 -240
- package/dist/wrec.umd.js +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -41,12 +41,12 @@ Here are the steps:
|
|
|
41
41
|
|
|
42
42
|
1. Create a new directory for the project and `cd` to it.
|
|
43
43
|
|
|
44
|
-
1.
|
|
44
|
+
1. Enter `npm init -y` to create a `package.json` file.
|
|
45
45
|
|
|
46
|
-
1.
|
|
46
|
+
1. Enter `npm i wrec` to install the wrec library.
|
|
47
47
|
|
|
48
|
-
1.
|
|
49
|
-
This is
|
|
48
|
+
1. Enter `npm i -D vite` to install vite.
|
|
49
|
+
This is used to run a local HTTP server.
|
|
50
50
|
|
|
51
51
|
1. Add the following script in `package.json`:
|
|
52
52
|
|
|
@@ -91,7 +91,7 @@ Here are the steps:
|
|
|
91
91
|
</button>
|
|
92
92
|
<span>this.count</span>
|
|
93
93
|
<button onClick="this.count++" type="button">+</button>
|
|
94
|
-
<span>(this.count < 10 ? "single" : "
|
|
94
|
+
<span>(this.count < 10 ? "single" : "multi") + "-digit"</span>
|
|
95
95
|
</div>
|
|
96
96
|
`;
|
|
97
97
|
}
|
|
@@ -113,7 +113,7 @@ Here are the steps:
|
|
|
113
113
|
</html>
|
|
114
114
|
```
|
|
115
115
|
|
|
116
|
-
1.
|
|
116
|
+
1. Enter `npm run dev` to start a local server.
|
|
117
117
|
|
|
118
118
|
1. Browse localhost:5173.
|
|
119
119
|
|
|
@@ -173,3 +173,28 @@ This uses the `data-binding`, `number-slider`, `radio-group`,
|
|
|
173
173
|
`select-list`, and `toggle-switch` components.
|
|
174
174
|
|
|
175
175
|
`speedometer-demo.html` demonstrates fancy graphics.
|
|
176
|
+
|
|
177
|
+
`state-demo.html` demonstrates using the `WrecState` class
|
|
178
|
+
to share state across multiple wrec components.
|
|
179
|
+
|
|
180
|
+
- This creates a `WrecState` object with the name "demo"
|
|
181
|
+
and with a "name" property set to "World".
|
|
182
|
+
- The "value" property of the `labeled-input` component
|
|
183
|
+
is mapped to the state "name" property.
|
|
184
|
+
- The "name" property of the `hello-world` component
|
|
185
|
+
is mapped to the state "name" property because
|
|
186
|
+
when no mapping is specified, identical property names are mapped.
|
|
187
|
+
- Changing the input value in the `label-input` component and
|
|
188
|
+
moving focus to commit the change updates the state `name` property.
|
|
189
|
+
- The `hello-world` component uses that same state property.
|
|
190
|
+
- Clicking the "Reset" button sets the state "name" property
|
|
191
|
+
back to "World".
|
|
192
|
+
- The state object can be retrieved and modified
|
|
193
|
+
in the DevTools console as follows:
|
|
194
|
+
|
|
195
|
+
```js
|
|
196
|
+
state = WrecState.get('demo');
|
|
197
|
+
state; // to examine the entire object
|
|
198
|
+
state.name; // to see current value of "name" property
|
|
199
|
+
state.name = 'Earth'; // to modify "name" property
|
|
200
|
+
```
|
package/dist/wrec.es.js
CHANGED
|
@@ -1,133 +1,156 @@
|
|
|
1
|
-
function
|
|
1
|
+
function R(r, t) {
|
|
2
2
|
let e = r;
|
|
3
3
|
for (const s of t.split("."))
|
|
4
4
|
e = e[s];
|
|
5
5
|
return e;
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function O(r, t, e) {
|
|
8
8
|
const s = t.split("."), o = s.length - 1;
|
|
9
9
|
let i = r;
|
|
10
|
-
s.forEach((n,
|
|
11
|
-
|
|
10
|
+
s.forEach((n, h) => {
|
|
11
|
+
h === o ? i[n] = e : i = i[n];
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
|
-
class
|
|
14
|
+
class m extends Error {
|
|
15
15
|
}
|
|
16
|
-
const
|
|
16
|
+
const k = /([a-zA-Z-]+)\s*:\s*([^;}]+)/g, P = "a-zA-Z_$", F = P + "0-9", b = `[${P}][${F}]*`, j = /<!--\s*(.*?)\s*-->/, _ = /<(\w+)(?:\s[^>]*)?>((?:[^<]|<(?!\w))*?)<\/\1>/g, A = new RegExp(`^this\\.${b}$`), y = new RegExp(`this\\.${b}(\\.${b})*`, "g"), N = new RegExp(`this\\.${b}(\\.${b})*`), V = /* @__PURE__ */ new Set(["class", "style"]), $ = 5;
|
|
17
17
|
function I(r) {
|
|
18
|
-
return r instanceof HTMLButtonElement || r instanceof HTMLFieldSetElement || r instanceof HTMLInputElement || r instanceof HTMLSelectElement || r instanceof HTMLTextAreaElement || r instanceof
|
|
18
|
+
return r instanceof HTMLButtonElement || r instanceof HTMLFieldSetElement || r instanceof HTMLInputElement || r instanceof HTMLSelectElement || r instanceof HTMLTextAreaElement || r instanceof u;
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function q(r, t, e) {
|
|
21
21
|
const s = document.createElement(r);
|
|
22
22
|
if (t)
|
|
23
23
|
for (const [o, i] of Object.entries(t))
|
|
24
24
|
s.setAttribute(o, i);
|
|
25
25
|
return e && (s.innerHTML = e), s;
|
|
26
26
|
}
|
|
27
|
-
const
|
|
28
|
-
function
|
|
27
|
+
const D = (r) => r === String ? "" : r === Number ? 0 : r === Boolean ? !1 : r === Array ? [] : r === Object ? {} : void 0;
|
|
28
|
+
function w(r) {
|
|
29
29
|
const t = [];
|
|
30
30
|
let e = r.firstElementChild;
|
|
31
31
|
for (; e; )
|
|
32
|
-
t.push(e), e.shadowRoot && t.push(...
|
|
32
|
+
t.push(e), e.shadowRoot && t.push(...w(e.shadowRoot)), e.firstElementChild && t.push(...w(e)), e = e.nextElementSibling;
|
|
33
33
|
return t;
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
if (r.id === t) return r;
|
|
37
|
-
const { shadowRoot: e } = r;
|
|
38
|
-
if (e)
|
|
39
|
-
for (const s of Array.from(e.children)) {
|
|
40
|
-
const o = C(s, t);
|
|
41
|
-
if (o) return o;
|
|
42
|
-
}
|
|
43
|
-
for (const s of Array.from(r.children)) {
|
|
44
|
-
const o = C(s, t);
|
|
45
|
-
if (o) return o;
|
|
46
|
-
}
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
const g = (r) => r.substring(v).split(".")[0];
|
|
35
|
+
const E = (r) => r.substring($).split(".")[0];
|
|
50
36
|
function x(r, t) {
|
|
51
37
|
let e = r[0];
|
|
52
38
|
return t.forEach((s, o) => {
|
|
53
39
|
e += s + r[o + 1];
|
|
54
40
|
}), e;
|
|
55
41
|
}
|
|
56
|
-
function
|
|
42
|
+
function S(r) {
|
|
57
43
|
const t = typeof r;
|
|
58
44
|
return t === "string" || t === "number" || t === "boolean";
|
|
59
45
|
}
|
|
60
|
-
|
|
61
|
-
|
|
46
|
+
function d(r) {
|
|
47
|
+
return r.localName === "textarea";
|
|
48
|
+
}
|
|
49
|
+
function v(r) {
|
|
50
|
+
const { localName: t } = r;
|
|
51
|
+
return t === "input" || t === "select";
|
|
52
|
+
}
|
|
53
|
+
const B = (r) => r.replace(/<!--[\s\S]*?-->/g, "");
|
|
54
|
+
function L(r, t, e, s) {
|
|
62
55
|
return r.slice(0, t) + s + r.slice(t + e);
|
|
63
56
|
}
|
|
64
|
-
function
|
|
57
|
+
function C(r) {
|
|
65
58
|
const t = Number(r);
|
|
66
|
-
if (isNaN(t)) throw new
|
|
59
|
+
if (isNaN(t)) throw new m(`can't convert "${r}" to a number`);
|
|
67
60
|
return t;
|
|
68
61
|
}
|
|
69
|
-
function
|
|
70
|
-
|
|
62
|
+
function H(r, t, e) {
|
|
63
|
+
const [s, o] = t.split(":");
|
|
64
|
+
if (S(e))
|
|
71
65
|
if (typeof e == "boolean") {
|
|
72
|
-
e ? r.setAttribute(
|
|
73
|
-
const
|
|
74
|
-
r[
|
|
75
|
-
} else
|
|
76
|
-
r.getAttribute(t)
|
|
66
|
+
e ? r.setAttribute(s, s) : r.removeAttribute(s);
|
|
67
|
+
const i = u.getPropName(s);
|
|
68
|
+
r[i] = e;
|
|
69
|
+
} else {
|
|
70
|
+
const i = r.getAttribute(t), n = String(e);
|
|
71
|
+
i !== n && (r.setAttribute(s, n), s === "value" && v(r) && (r.value = n));
|
|
72
|
+
}
|
|
77
73
|
else {
|
|
78
|
-
const
|
|
79
|
-
r[
|
|
74
|
+
const i = u.getPropName(t);
|
|
75
|
+
r[i] = e;
|
|
80
76
|
}
|
|
81
77
|
}
|
|
82
|
-
function
|
|
83
|
-
|
|
78
|
+
function T(r, t, e) {
|
|
79
|
+
const [s, o] = t.split(":");
|
|
80
|
+
r instanceof CSSRule ? r.style.setProperty(s, e) : (H(r, s, e), s === "value" && v(r) && (r.value = e));
|
|
84
81
|
}
|
|
85
|
-
class
|
|
82
|
+
class u extends HTMLElement {
|
|
83
|
+
// This is used to lookup the camelCase property name
|
|
84
|
+
// that corresponds to a kebab-case attribute name.
|
|
86
85
|
static #p = /* @__PURE__ */ new Map();
|
|
86
|
+
// This is used to lookup the kebab-case attribute name
|
|
87
|
+
// that corresponds to a camelCase property name.
|
|
87
88
|
static #d = /* @__PURE__ */ new Map();
|
|
88
|
-
|
|
89
|
+
// This can be set in each Wrec subclass.
|
|
90
|
+
// It describes CSS rules that a web component uses.
|
|
89
91
|
static css = "";
|
|
92
|
+
// Set this to true in Wrec subclasses that need
|
|
93
|
+
// the ability to contribute data to form submissions.
|
|
90
94
|
static formAssociated = !1;
|
|
95
|
+
// This must be set in each Wrec subclass.
|
|
96
|
+
// It describes HTML that a web component renders.
|
|
91
97
|
static html = "";
|
|
98
|
+
// There is one instance of `properties`, `propToComputedMap`,
|
|
99
|
+
// and `propToExprsMap` per Wrec subclass,
|
|
100
|
+
// not one for only the Wrec class.
|
|
101
|
+
// This must be set in each Wrec subclass.
|
|
102
|
+
// It describes all the properties that a web component supports.
|
|
92
103
|
static properties = {};
|
|
104
|
+
// This is a map from properties to arrays of
|
|
105
|
+
// computed property expressions that use the property.
|
|
106
|
+
// It is used to update computed properties
|
|
107
|
+
// when the properties on which they depend are modified.
|
|
108
|
+
// See the method #updateComputedProperties.
|
|
109
|
+
// This map cannot be private.
|
|
93
110
|
static propToComputedMap = null;
|
|
111
|
+
// This is a map from properties to expressions that refer to them.
|
|
112
|
+
// It is the sma for all instances of a component.
|
|
113
|
+
// This map cannot be private.
|
|
94
114
|
static propToExprsMap = null;
|
|
95
115
|
static template = null;
|
|
96
116
|
#t = this.constructor;
|
|
117
|
+
// This is a map from expressions to references to them
|
|
118
|
+
// which can be found in element text content,
|
|
119
|
+
// attribute values, and CSS property values.
|
|
120
|
+
// Each component instance needs its own map.
|
|
97
121
|
#s = /* @__PURE__ */ new Map();
|
|
98
|
-
#
|
|
99
|
-
#
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
//
|
|
104
|
-
|
|
105
|
-
#h =
|
|
122
|
+
#a = {};
|
|
123
|
+
#i;
|
|
124
|
+
// For components that set `formAssociated` to true,
|
|
125
|
+
// this stores in the initial value of each property
|
|
126
|
+
// in the formAssociatedCallback method
|
|
127
|
+
// so they can be restored in the formResetCallback method.
|
|
128
|
+
#f = {};
|
|
129
|
+
#h = null;
|
|
130
|
+
// This is a map from properties in this web component
|
|
131
|
+
// to corresponding properties in a parent web component.
|
|
132
|
+
// This must be an instance property because
|
|
133
|
+
// each component instance can have its properties mapped
|
|
134
|
+
// to the properties of different parent components.
|
|
135
|
+
// This is used to update a parent property
|
|
136
|
+
// when the corresponding child property value changes.
|
|
137
|
+
#l = /* @__PURE__ */ new Map();
|
|
106
138
|
constructor() {
|
|
107
139
|
super(), this.attachShadow({ mode: "open" });
|
|
108
140
|
const t = this.#t;
|
|
109
141
|
t.properties || (t.properties = {}), t.propToComputedMap || (t.propToComputedMap = /* @__PURE__ */ new Map()), t.propToExprsMap || (t.propToExprsMap = /* @__PURE__ */ new Map());
|
|
110
142
|
}
|
|
111
143
|
attributeChangedCallback(t, e, s) {
|
|
112
|
-
t === "disabled" && this.#
|
|
113
|
-
const o =
|
|
144
|
+
t === "disabled" && this.#m();
|
|
145
|
+
const o = u.getPropName(t);
|
|
114
146
|
if (this.#n(o)) {
|
|
115
|
-
const i = this.#
|
|
147
|
+
const i = this.#y(o, String(s));
|
|
116
148
|
this[o] = i;
|
|
117
|
-
const n = this.#
|
|
149
|
+
const n = this.#a[o];
|
|
118
150
|
n && this.setFormValue(n, String(i)), this.propertyChangedCallback(o, e, s);
|
|
119
151
|
}
|
|
120
152
|
}
|
|
121
|
-
|
|
122
|
-
#g(t, e, s, o) {
|
|
123
|
-
t.addEventListener(o, (n) => {
|
|
124
|
-
const a = n.target, { value: c } = a, { type: h } = this.#t.properties[e];
|
|
125
|
-
this[e] = h === Number ? y(c) : c;
|
|
126
|
-
});
|
|
127
|
-
let i = this.#f.get(e);
|
|
128
|
-
i || (i = [], this.#f.set(e, i)), i.push(s ? { element: t, attrName: s } : t);
|
|
129
|
-
}
|
|
130
|
-
#S() {
|
|
153
|
+
#w() {
|
|
131
154
|
const t = this.#t;
|
|
132
155
|
let e = t.template;
|
|
133
156
|
if (!e) {
|
|
@@ -141,54 +164,50 @@ class l extends HTMLElement {
|
|
|
141
164
|
this[e] = s;
|
|
142
165
|
}
|
|
143
166
|
connectedCallback() {
|
|
144
|
-
this.#
|
|
145
|
-
this.shadowRoot && (this.#
|
|
167
|
+
this.#O(), this.#v(), this.#w(), this.hasAttribute("disabled") && this.#m(), requestAnimationFrame(() => {
|
|
168
|
+
this.shadowRoot && (this.#T(this.shadowRoot), this.#b(this.shadowRoot)), this.#S();
|
|
146
169
|
});
|
|
147
170
|
}
|
|
148
|
-
#
|
|
171
|
+
#S() {
|
|
149
172
|
const t = this.#t, { properties: e } = t;
|
|
150
173
|
for (const [s, { computed: o }] of Object.entries(e))
|
|
151
|
-
o && (this[s] = this.#
|
|
152
|
-
}
|
|
153
|
-
static dataForId(t) {
|
|
154
|
-
const e = crypto.randomUUID();
|
|
155
|
-
return l.#d.set(e, t), e;
|
|
174
|
+
o && (this[s] = this.#o(o));
|
|
156
175
|
}
|
|
157
|
-
#
|
|
176
|
+
#v() {
|
|
158
177
|
const t = this.#t, { observedAttributes: e, properties: s } = t;
|
|
159
178
|
for (const [o, i] of Object.entries(s))
|
|
160
|
-
this.#
|
|
179
|
+
this.#M(o, i, e);
|
|
161
180
|
}
|
|
162
|
-
#
|
|
163
|
-
const o =
|
|
181
|
+
#M(t, e, s) {
|
|
182
|
+
const o = u.getAttrName(t), i = this.hasAttribute(o);
|
|
164
183
|
e.required && !i && this.#e(this, t, "is a required attribute");
|
|
165
184
|
let n = e.value;
|
|
166
|
-
this.hasOwnProperty(t) && (n = this[t], delete this[t])
|
|
167
|
-
const { type:
|
|
168
|
-
this[
|
|
185
|
+
this.hasOwnProperty(t) && (n = this[t], delete this[t]);
|
|
186
|
+
const { type: h } = e, c = h === Boolean ? n || i : s.includes(o) && i ? this.#A(t, o) : n || D(h), f = "#" + t;
|
|
187
|
+
this[f] = c, e.computed && this.#$(t, e), Object.defineProperty(this, t, {
|
|
169
188
|
enumerable: !0,
|
|
170
189
|
get() {
|
|
171
|
-
return this[
|
|
190
|
+
return this[f];
|
|
172
191
|
},
|
|
173
|
-
set(
|
|
174
|
-
|
|
175
|
-
const
|
|
176
|
-
if (
|
|
177
|
-
this.#
|
|
178
|
-
const { state:
|
|
179
|
-
|
|
180
|
-
const M = this.#
|
|
181
|
-
M && this.setFormValue(M, String(
|
|
192
|
+
set(a) {
|
|
193
|
+
h === Number && typeof a == "string" && (a = C(a));
|
|
194
|
+
const l = this[f];
|
|
195
|
+
if (a === l) return;
|
|
196
|
+
this.#F(t, h, a), this[f] = a;
|
|
197
|
+
const { state: p, stateProp: g } = this.#t.properties[t];
|
|
198
|
+
g && O(p, g, a), this.#L(t), this.#x(t, h, a, o), this.#E(t), this.#H(t, a);
|
|
199
|
+
const M = this.#a[t];
|
|
200
|
+
M && this.setFormValue(M, String(a)), this.propertyChangedCallback(t, l, a), e.dispatch && this.dispatch("change", { [t]: a });
|
|
182
201
|
}
|
|
183
202
|
});
|
|
184
203
|
}
|
|
185
|
-
#
|
|
186
|
-
const t = this.hasAttribute("disabled"), e =
|
|
204
|
+
#m() {
|
|
205
|
+
const t = this.hasAttribute("disabled"), e = w(this.shadowRoot);
|
|
187
206
|
for (const s of e)
|
|
188
207
|
I(s) && (s.disabled = t);
|
|
189
208
|
}
|
|
190
209
|
disconnectedCallback() {
|
|
191
|
-
this.#s.clear(), this.#
|
|
210
|
+
this.#s.clear(), this.#f.clear(), this.#l.clear();
|
|
192
211
|
}
|
|
193
212
|
dispatch(t, e) {
|
|
194
213
|
this.dispatchEvent(
|
|
@@ -209,43 +228,44 @@ class l extends HTMLElement {
|
|
|
209
228
|
static elementName() {
|
|
210
229
|
return this.name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
211
230
|
}
|
|
212
|
-
#
|
|
213
|
-
const e = t instanceof
|
|
231
|
+
#R(t) {
|
|
232
|
+
const e = t instanceof u;
|
|
214
233
|
for (const s of t.getAttributeNames()) {
|
|
215
|
-
const o = t.getAttribute(s), i = this.#
|
|
234
|
+
const o = t.getAttribute(s), i = this.#g(t, o);
|
|
216
235
|
if (i) {
|
|
217
236
|
const n = this[i];
|
|
218
|
-
n === void 0 && this.#
|
|
219
|
-
let [
|
|
220
|
-
|
|
221
|
-
|
|
237
|
+
n === void 0 && this.#c(t, s, i), t[i] = n;
|
|
238
|
+
let [h, c] = s.split(":");
|
|
239
|
+
h === "value" && (c ? (t["on" + c] === void 0 && this.#e(t, s, "refers to an unsupported event name"), t.setAttribute(h, this[i])) : c = "change"), e && t.#l.set(
|
|
240
|
+
u.getPropName(h),
|
|
222
241
|
i
|
|
223
242
|
);
|
|
224
243
|
}
|
|
225
|
-
this.#
|
|
244
|
+
this.#r(o, t, s);
|
|
226
245
|
}
|
|
227
246
|
}
|
|
228
|
-
#
|
|
247
|
+
#o(t) {
|
|
229
248
|
const e = new Function("return " + t).call(this);
|
|
230
249
|
return Array.isArray(e) ? e.join("") : e;
|
|
231
250
|
}
|
|
232
|
-
|
|
251
|
+
#P(t) {
|
|
233
252
|
const { localName: e } = t;
|
|
234
253
|
if (e === "style") {
|
|
235
254
|
const { sheet: s } = t, o = s?.cssRules ?? [], i = Array.from(o);
|
|
236
255
|
for (const n of i)
|
|
237
256
|
if (n.constructor === CSSStyleRule) {
|
|
238
|
-
const
|
|
239
|
-
for (const c of
|
|
257
|
+
const h = Array.from(n.style);
|
|
258
|
+
for (const c of h)
|
|
240
259
|
if (c.startsWith("--")) {
|
|
241
|
-
const
|
|
242
|
-
this.#
|
|
260
|
+
const f = n.style.getPropertyValue(c);
|
|
261
|
+
this.#r(f, n, c);
|
|
243
262
|
}
|
|
244
263
|
}
|
|
245
264
|
} else {
|
|
246
265
|
let s = "";
|
|
247
|
-
if (
|
|
248
|
-
|
|
266
|
+
if (d(t)) {
|
|
267
|
+
this.#r(t.textContent, t);
|
|
268
|
+
const o = t.textContent?.match(j);
|
|
249
269
|
o && (s = o[1]);
|
|
250
270
|
} else {
|
|
251
271
|
const o = Array.from(t.childNodes).find(
|
|
@@ -254,8 +274,8 @@ class l extends HTMLElement {
|
|
|
254
274
|
o && (s = o.textContent?.trim() ?? "");
|
|
255
275
|
}
|
|
256
276
|
if (s) {
|
|
257
|
-
const o = this.#
|
|
258
|
-
|
|
277
|
+
const o = this.#g(t, s);
|
|
278
|
+
o && d(t) ? t.textContent = this[o] : this.#r(s, t);
|
|
259
279
|
}
|
|
260
280
|
}
|
|
261
281
|
}
|
|
@@ -271,80 +291,99 @@ class l extends HTMLElement {
|
|
|
271
291
|
if (this.#n("value"))
|
|
272
292
|
t = `value:${n}`;
|
|
273
293
|
else
|
|
274
|
-
|
|
275
|
-
"can't submit by name because component has no value property"
|
|
276
|
-
);
|
|
294
|
+
return;
|
|
277
295
|
else
|
|
278
296
|
return;
|
|
279
297
|
}
|
|
280
298
|
const e = {}, s = t.split(",");
|
|
281
299
|
for (const n of s) {
|
|
282
|
-
const [
|
|
283
|
-
e[
|
|
300
|
+
const [h, c] = n.split(":");
|
|
301
|
+
e[h.trim()] = c.trim();
|
|
284
302
|
}
|
|
285
|
-
this.#
|
|
286
|
-
const o = Object.keys(this.#t.properties), i = this.#
|
|
303
|
+
this.#a = e, this.#i = new FormData(), this.#h = this.attachInternals(), this.#h.setFormValue(this.#i);
|
|
304
|
+
const o = Object.keys(this.#t.properties), i = this.#f;
|
|
287
305
|
for (const n of o)
|
|
288
306
|
i[n] = this[n];
|
|
289
307
|
}
|
|
290
308
|
formResetCallback() {
|
|
291
|
-
const t = this.#
|
|
292
|
-
for (const e of Object.keys(t))
|
|
293
|
-
|
|
309
|
+
const t = this.#f;
|
|
310
|
+
for (const e of Object.keys(t)) {
|
|
311
|
+
let s = t[e];
|
|
312
|
+
A.test(s) && (s = this.#o(s)), this[e] = s;
|
|
313
|
+
}
|
|
294
314
|
}
|
|
295
315
|
static getAttrName(t) {
|
|
296
|
-
let e =
|
|
297
|
-
return e || (e = t.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(),
|
|
316
|
+
let e = u.#d.get(t);
|
|
317
|
+
return e || (e = t.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), u.#d.set(t, e)), e;
|
|
298
318
|
}
|
|
299
319
|
static getPropName(t) {
|
|
300
|
-
let e =
|
|
301
|
-
return e || (e = t.replace(/-([a-z])/g, (s, o) => o.toUpperCase()),
|
|
320
|
+
let e = u.#p.get(t);
|
|
321
|
+
return e || (e = t.replace(/-([a-z])/g, (s, o) => o.toUpperCase()), u.#p.set(t, e)), e;
|
|
322
|
+
}
|
|
323
|
+
#N(t, e, s) {
|
|
324
|
+
if (s.length !== 1) return;
|
|
325
|
+
const [o] = s;
|
|
326
|
+
if (!A.test(o)) return;
|
|
327
|
+
const i = v(t) || d(t);
|
|
328
|
+
let [n, h] = (e ?? "").split(":");
|
|
329
|
+
if (!(i && n === "value" || d(t))) return;
|
|
330
|
+
h ? t["on" + h] === void 0 && this.#e(t, e, "refers to an unsupported event name") : h = "change";
|
|
331
|
+
const f = E(o);
|
|
332
|
+
t.addEventListener(h, (a) => {
|
|
333
|
+
const { target: l } = a;
|
|
334
|
+
if (!l) return;
|
|
335
|
+
const p = l.value, { type: g } = this.#t.properties[f];
|
|
336
|
+
this[f] = g === Number ? C(p) : p, this.#E(f);
|
|
337
|
+
});
|
|
302
338
|
}
|
|
303
339
|
#n(t) {
|
|
304
340
|
return !!this.#t.properties[t];
|
|
305
341
|
}
|
|
306
|
-
#
|
|
342
|
+
#b(t) {
|
|
307
343
|
const e = Array.from(t.querySelectorAll("*"));
|
|
308
344
|
for (const s of e)
|
|
309
|
-
this.#
|
|
345
|
+
this.#R(s), s.firstElementChild || this.#P(s);
|
|
310
346
|
}
|
|
311
347
|
static get observedAttributes() {
|
|
312
|
-
const t = Object.keys(this.properties || {}).map(
|
|
348
|
+
const t = Object.keys(this.properties || {}).map(u.getAttrName);
|
|
313
349
|
return t.includes("disabled") || t.push("disabled"), t;
|
|
314
350
|
}
|
|
315
351
|
// Subclasses can override this to add functionality.
|
|
316
352
|
propertyChangedCallback(t, e, s) {
|
|
317
353
|
}
|
|
318
|
-
#
|
|
319
|
-
if (!e || !
|
|
320
|
-
const s =
|
|
321
|
-
return this[s] === void 0 && this.#
|
|
354
|
+
#g(t, e) {
|
|
355
|
+
if (!e || !A.test(e)) return;
|
|
356
|
+
const s = E(e);
|
|
357
|
+
return this[s] === void 0 && this.#c(t, "", s), s;
|
|
322
358
|
}
|
|
323
|
-
#
|
|
359
|
+
#E(t) {
|
|
324
360
|
const o = this.#t.propToExprsMap.get(t) || [];
|
|
325
361
|
for (const i of o) {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
362
|
+
let n = this.#o(i);
|
|
363
|
+
const h = this.#s.get(i) ?? [];
|
|
364
|
+
for (const c of h)
|
|
365
|
+
if (c instanceof HTMLElement)
|
|
366
|
+
this.#C(c, n);
|
|
367
|
+
else if (!(c instanceof CSSStyleRule)) {
|
|
368
|
+
const { element: f, attrName: a } = c;
|
|
369
|
+
f instanceof CSSStyleRule ? f.style.setProperty(a, n) : T(f, a, n);
|
|
370
|
+
}
|
|
329
371
|
}
|
|
330
|
-
requestAnimationFrame(() => {
|
|
331
|
-
this.#k(t);
|
|
332
|
-
});
|
|
333
372
|
}
|
|
334
373
|
static register() {
|
|
335
374
|
const t = this.elementName();
|
|
336
375
|
customElements.get(t) || customElements.define(t, this);
|
|
337
376
|
}
|
|
338
|
-
|
|
377
|
+
#$(t, e) {
|
|
339
378
|
const { computed: s, uses: o } = e, i = this.#t.propToComputedMap;
|
|
340
|
-
function n(c,
|
|
341
|
-
let
|
|
342
|
-
|
|
379
|
+
function n(c, f) {
|
|
380
|
+
let a = i.get(c);
|
|
381
|
+
a || (a = [], i.set(c, a)), a.push([t, f]);
|
|
343
382
|
}
|
|
344
|
-
const
|
|
345
|
-
for (const c of
|
|
346
|
-
const
|
|
347
|
-
this[
|
|
383
|
+
const h = s.match(y) || [];
|
|
384
|
+
for (const c of h) {
|
|
385
|
+
const f = c.substring($);
|
|
386
|
+
this[f] === void 0 && this.#c(null, t, f), typeof this[f] != "function" && n(f, s);
|
|
348
387
|
}
|
|
349
388
|
if (o)
|
|
350
389
|
for (const c of o.split(","))
|
|
@@ -352,34 +391,34 @@ class l extends HTMLElement {
|
|
|
352
391
|
}
|
|
353
392
|
// WARNING: Do not place untrusted JavaScript expressions
|
|
354
393
|
// in attribute values or the text content of elements!
|
|
355
|
-
#
|
|
394
|
+
#r(t, e, s = void 0) {
|
|
356
395
|
if (!t) return;
|
|
357
396
|
const o = this.#u(e, s, t);
|
|
358
397
|
if (!o) {
|
|
359
398
|
const c = t.replaceAll("this..", "this.");
|
|
360
|
-
s ?
|
|
399
|
+
s ? T(e, s, c) : "textContent" in e && (e.textContent = c);
|
|
361
400
|
return;
|
|
362
401
|
}
|
|
363
402
|
const i = this.#t;
|
|
364
403
|
o.forEach((c) => {
|
|
365
|
-
const
|
|
366
|
-
if (typeof this[
|
|
367
|
-
const
|
|
368
|
-
let
|
|
369
|
-
|
|
404
|
+
const f = E(c);
|
|
405
|
+
if (typeof this[f] == "function") return;
|
|
406
|
+
const a = i.propToExprsMap;
|
|
407
|
+
let l = a.get(f);
|
|
408
|
+
l || (l = [], a.set(f, l)), l.includes(t) || l.push(t);
|
|
370
409
|
});
|
|
371
|
-
for (const [c,
|
|
372
|
-
for (const
|
|
373
|
-
const
|
|
374
|
-
|
|
410
|
+
for (const [c, f] of this.#s.entries())
|
|
411
|
+
for (const a of f) {
|
|
412
|
+
const l = a instanceof HTMLElement || a instanceof CSSStyleRule ? a : a.element;
|
|
413
|
+
l instanceof CSSStyleRule || l.isConnected || this.#s.set(
|
|
375
414
|
c,
|
|
376
|
-
|
|
415
|
+
f.filter((p) => p !== a)
|
|
377
416
|
);
|
|
378
417
|
}
|
|
379
418
|
let n = this.#s.get(t);
|
|
380
|
-
n || (n = [], this.#s.set(t, n)), n.push(s ? { element: e, attrName: s } : e);
|
|
381
|
-
const
|
|
382
|
-
s ?
|
|
419
|
+
n || (n = [], this.#s.set(t, n)), n.push(s ? { element: e, attrName: s } : e), e instanceof HTMLElement && this.#N(e, s, o);
|
|
420
|
+
const h = this.#o(t);
|
|
421
|
+
s ? T(e, s, h) : this.#C(e, h);
|
|
383
422
|
}
|
|
384
423
|
// This follows the best practice
|
|
385
424
|
// "Do not override author-set, global attributes."
|
|
@@ -387,33 +426,25 @@ class l extends HTMLElement {
|
|
|
387
426
|
this.hasAttribute(t) || this.setAttribute(t, e);
|
|
388
427
|
}
|
|
389
428
|
setFormValue(t, e) {
|
|
390
|
-
!this.#
|
|
391
|
-
}
|
|
392
|
-
static #O() {
|
|
393
|
-
for (const [t, e] of l.#d.entries()) {
|
|
394
|
-
const s = C(document.body, t);
|
|
395
|
-
if (s)
|
|
396
|
-
for (const [o, i] of Object.entries(e))
|
|
397
|
-
s[o] = i;
|
|
398
|
-
}
|
|
429
|
+
!this.#i || !S(e) || (this.#i.set(t, e), this.#h?.setFormValue(this.#i));
|
|
399
430
|
}
|
|
400
431
|
#e(t, e, s) {
|
|
401
432
|
const o = this.#t, i = t instanceof HTMLElement ? t.localName : "CSS rule";
|
|
402
|
-
throw new
|
|
433
|
+
throw new m(
|
|
403
434
|
`component ${o.elementName()}` + (t ? `, element "${i}"` : "") + (e ? `, attribute "${e}"` : "") + ` ${s}`
|
|
404
435
|
);
|
|
405
436
|
}
|
|
406
|
-
#
|
|
437
|
+
#c(t, e, s) {
|
|
407
438
|
this.#e(t, e, `refers to missing property "${s}"`);
|
|
408
439
|
}
|
|
409
|
-
#
|
|
410
|
-
return this.#
|
|
440
|
+
#A(t, e) {
|
|
441
|
+
return this.#y(t, this.getAttribute(e));
|
|
411
442
|
}
|
|
412
|
-
#
|
|
413
|
-
if (e?.match(
|
|
443
|
+
#y(t, e) {
|
|
444
|
+
if (e?.match(y)) return e;
|
|
414
445
|
const s = this.#t, { type: o } = s.properties[t];
|
|
415
446
|
if (o || this.#e(null, t, "does not specify its type"), o === String) return e;
|
|
416
|
-
if (o === Number) return
|
|
447
|
+
if (o === Number) return C(e);
|
|
417
448
|
if (o === Boolean)
|
|
418
449
|
return e === "true" ? !0 : e === "false" || e === "null" ? !1 : (e && e !== t && this.#e(
|
|
419
450
|
null,
|
|
@@ -422,43 +453,33 @@ class l extends HTMLElement {
|
|
|
422
453
|
), e === t);
|
|
423
454
|
}
|
|
424
455
|
// Updates the matching attribute for a property if there is one.
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
456
|
+
// VS Code thinks this is never called, but it is called by #defineProp.
|
|
457
|
+
#x(t, e, s, o) {
|
|
458
|
+
if (S(s) && this.hasAttribute(o)) {
|
|
459
|
+
const i = e === Boolean ? this.hasAttribute(o) : this.#A(t, o);
|
|
460
|
+
s !== i && H(this, t, s);
|
|
429
461
|
}
|
|
430
462
|
}
|
|
431
|
-
#k(t) {
|
|
432
|
-
const e = this[t], s = this.#f.get(t) || [];
|
|
433
|
-
for (const o of s)
|
|
434
|
-
if (o instanceof HTMLElement)
|
|
435
|
-
o.localName === "textarea" ? o.value = e : o.textContent = e;
|
|
436
|
-
else if (!(o instanceof CSSStyleRule)) {
|
|
437
|
-
const { element: i, attrName: n } = o;
|
|
438
|
-
if (i instanceof HTMLElement) {
|
|
439
|
-
const a = l.getPropName(n);
|
|
440
|
-
i[a] = e;
|
|
441
|
-
} else i instanceof CSSStyleRule && i.style.setProperty(n, e);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
463
|
// Updates all computed properties that reference this property.
|
|
445
|
-
#
|
|
464
|
+
// VS Code thinks this is never called, but it is called by #defineProp.
|
|
465
|
+
#L(t) {
|
|
446
466
|
const s = this.#t.propToComputedMap.get(t) || [];
|
|
447
467
|
for (const [o, i] of s)
|
|
448
|
-
this[o] = this.#
|
|
468
|
+
this[o] = this.#o(i);
|
|
449
469
|
}
|
|
450
|
-
#
|
|
470
|
+
#C(t, e) {
|
|
451
471
|
if (e === void 0) return;
|
|
452
|
-
const s = t instanceof HTMLElement, o =
|
|
453
|
-
|
|
472
|
+
const s = t instanceof HTMLElement, o = typeof e;
|
|
473
|
+
o !== "string" && o !== "number" && this.#e(
|
|
454
474
|
t,
|
|
455
475
|
void 0,
|
|
456
476
|
" computed content is not a string or number"
|
|
457
|
-
),
|
|
477
|
+
), t instanceof HTMLElement && d(t) ? t.value = e : s && o === "string" && e.trim().startsWith("<") ? (t.innerHTML = e, this.#T(t), this.#b(t)) : s && (t.textContent = e);
|
|
458
478
|
}
|
|
459
479
|
// Update corresponding parent web component property if bound to one.
|
|
460
|
-
|
|
461
|
-
|
|
480
|
+
// VS Code thinks this is never called, but it is called by #defineProp.
|
|
481
|
+
#H(t, e) {
|
|
482
|
+
const s = this.#l.get(t);
|
|
462
483
|
if (!s) return;
|
|
463
484
|
const o = this.getRootNode();
|
|
464
485
|
if (!(o instanceof ShadowRoot)) return;
|
|
@@ -478,32 +499,39 @@ class l extends HTMLElement {
|
|
|
478
499
|
for (const s of Object.keys(t))
|
|
479
500
|
e[s] = s;
|
|
480
501
|
}
|
|
481
|
-
this.#
|
|
502
|
+
this.#k(t, e);
|
|
482
503
|
for (const [s, o] of Object.entries(e))
|
|
483
504
|
if (this.#n(o)) {
|
|
484
|
-
const i =
|
|
505
|
+
const i = R(t, s);
|
|
485
506
|
i !== void 0 && (this[o] = i);
|
|
486
507
|
const n = this.#t.properties[o];
|
|
487
508
|
n.state = t, n.stateProp = s;
|
|
488
509
|
}
|
|
489
510
|
t.addListener(this, e);
|
|
490
511
|
}
|
|
491
|
-
#
|
|
492
|
-
const t = this.#t, e =
|
|
512
|
+
#O() {
|
|
513
|
+
const t = this.#t, e = new Set(Object.keys(t.properties));
|
|
514
|
+
for (const o of e)
|
|
515
|
+
V.has(o) && this.#e(
|
|
516
|
+
null,
|
|
517
|
+
"",
|
|
518
|
+
`property "${o}" is not allowed because it is a reserved attribute`
|
|
519
|
+
);
|
|
520
|
+
const s = this.#t.name;
|
|
493
521
|
for (const o of this.getAttributeNames())
|
|
494
522
|
if (o !== "class" && o !== "id" && o !== "disabled" && !o.startsWith("on")) {
|
|
495
523
|
if (o === "form-assoc") {
|
|
496
|
-
if (!
|
|
497
|
-
throw new
|
|
498
|
-
`add "static formAssociated = true;" to class ${
|
|
524
|
+
if (!t.formAssociated)
|
|
525
|
+
throw new m(
|
|
526
|
+
`add "static formAssociated = true;" to class ${s}`
|
|
499
527
|
);
|
|
500
528
|
continue;
|
|
501
529
|
}
|
|
502
|
-
if (!
|
|
530
|
+
if (!e.has(u.getPropName(o))) {
|
|
503
531
|
if (o === "name") {
|
|
504
532
|
if (t.formAssociated) continue;
|
|
505
|
-
throw new
|
|
506
|
-
`name attribute requires "static formAssociated = true;" in class ${
|
|
533
|
+
throw new m(
|
|
534
|
+
`name attribute requires "static formAssociated = true;" in class ${s}`
|
|
507
535
|
);
|
|
508
536
|
}
|
|
509
537
|
this.#e(null, o, "is not a supported attribute");
|
|
@@ -511,18 +539,18 @@ class l extends HTMLElement {
|
|
|
511
539
|
}
|
|
512
540
|
}
|
|
513
541
|
#u(t, e, s) {
|
|
514
|
-
const o = s.match(
|
|
542
|
+
const o = s.match(y);
|
|
515
543
|
if (o)
|
|
516
544
|
return o.forEach((i) => {
|
|
517
|
-
const n =
|
|
518
|
-
this[n] === void 0 && this.#
|
|
545
|
+
const n = E(i);
|
|
546
|
+
this[n] === void 0 && this.#c(t, e, n);
|
|
519
547
|
}), o;
|
|
520
548
|
}
|
|
521
|
-
#
|
|
549
|
+
#k(t, e) {
|
|
522
550
|
for (const [s, o] of Object.entries(e)) {
|
|
523
|
-
let i =
|
|
551
|
+
let i = R(t, s);
|
|
524
552
|
if (i === void 0)
|
|
525
|
-
throw new
|
|
553
|
+
throw new m(`invalid state path "${s}"`);
|
|
526
554
|
i = this[o], this.#n(o) || this.#e(
|
|
527
555
|
null,
|
|
528
556
|
o,
|
|
@@ -531,7 +559,7 @@ class l extends HTMLElement {
|
|
|
531
559
|
}
|
|
532
560
|
}
|
|
533
561
|
// When type is an array, this can't validate the type of the array elements.
|
|
534
|
-
#
|
|
562
|
+
#F(t, e, s) {
|
|
535
563
|
if (s instanceof e) return;
|
|
536
564
|
let o = typeof s;
|
|
537
565
|
if (o === "object") {
|
|
@@ -548,19 +576,19 @@ class l extends HTMLElement {
|
|
|
548
576
|
`was set to a ${o}, but must be a ${e.name}`
|
|
549
577
|
);
|
|
550
578
|
}
|
|
551
|
-
#
|
|
579
|
+
#T(t) {
|
|
552
580
|
const e = Array.from(t.querySelectorAll("*"));
|
|
553
581
|
for (const s of e) {
|
|
554
582
|
const o = [];
|
|
555
583
|
for (const i of Array.from(s.attributes)) {
|
|
556
584
|
const n = i.name;
|
|
557
585
|
if (n.startsWith("on")) {
|
|
558
|
-
let
|
|
559
|
-
|
|
586
|
+
let h = n.slice(2);
|
|
587
|
+
h = h[0].toLowerCase() + h.slice(1).toLowerCase();
|
|
560
588
|
const c = i.value;
|
|
561
589
|
this.#u(s, n, c);
|
|
562
|
-
let
|
|
563
|
-
typeof this[c] == "function" ?
|
|
590
|
+
let f;
|
|
591
|
+
typeof this[c] == "function" ? f = (a) => this[c](a) : (this.#u(s, n, c), f = () => this.#o(c)), s.addEventListener(h, f), o.push(n);
|
|
564
592
|
}
|
|
565
593
|
}
|
|
566
594
|
for (const i of o)
|
|
@@ -568,39 +596,39 @@ class l extends HTMLElement {
|
|
|
568
596
|
}
|
|
569
597
|
}
|
|
570
598
|
}
|
|
571
|
-
function
|
|
599
|
+
function z(r, ...t) {
|
|
572
600
|
let e = x(r, t);
|
|
573
601
|
for (; ; ) {
|
|
574
|
-
const s =
|
|
602
|
+
const s = k.exec(e);
|
|
575
603
|
if (!s) break;
|
|
576
604
|
const o = s[2];
|
|
577
|
-
if (
|
|
605
|
+
if (N.test(o)) {
|
|
578
606
|
const i = s[1];
|
|
579
607
|
if (!i.startsWith("--")) {
|
|
580
608
|
const n = `--${i}: ${o};
|
|
581
609
|
${i}: var(--${i});`;
|
|
582
|
-
e =
|
|
610
|
+
e = L(e, s.index, s[0].length, n);
|
|
583
611
|
}
|
|
584
612
|
}
|
|
585
613
|
}
|
|
586
614
|
return e;
|
|
587
615
|
}
|
|
588
|
-
function
|
|
616
|
+
function Z(r, ...t) {
|
|
589
617
|
let e = x(r, t);
|
|
590
618
|
for (; ; ) {
|
|
591
|
-
const s =
|
|
592
|
-
if (!s) break;
|
|
593
|
-
const o =
|
|
594
|
-
if (
|
|
619
|
+
const s = _.exec(e);
|
|
620
|
+
if (!s || s[1] === "style") break;
|
|
621
|
+
const o = B(s[2]);
|
|
622
|
+
if (N.test(o)) {
|
|
595
623
|
const i = `<!-- ${o.trim()} -->`, n = s.index + s[0].indexOf(">") + 1;
|
|
596
|
-
e =
|
|
624
|
+
e = L(e, n, o.length, i);
|
|
597
625
|
}
|
|
598
626
|
}
|
|
599
627
|
return e;
|
|
600
628
|
}
|
|
601
629
|
export {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
630
|
+
u as Wrec,
|
|
631
|
+
q as createElement,
|
|
632
|
+
z as css,
|
|
633
|
+
Z as html
|
|
606
634
|
};
|
package/dist/wrec.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(p,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(p=typeof globalThis<"u"?globalThis:p||self,d(p.wrec={}))})(this,(function(p){"use strict";function d(r,t){let e=r;for(const s of t.split("."))e=e[s];return e}function O(r,t,e){const s=t.split("."),o=s.length-1;let i=r;s.forEach((n,a)=>{a===o?i[n]=e:i=i[n]})}class m extends Error{}const H=/([a-zA-Z-]+)\s*:\s*([^;}]+)/g,M="a-zA-Z_$",k=M+"0-9",b=`[${M}][${k}]*`,j=/<!--\s*(.*?)\s*-->/,F=/<(\w+)(?:\s[^>]*)?>((?:[^<]|<(?!\w))*?)<\/\1>/g,I=new RegExp(`^this\\.${b}$`),g=new RegExp(`this\\.${b}(\\.${b})*`,"g"),P=new RegExp(`this\\.${b}(\\.${b})*`),R=5;function B(r){return r instanceof HTMLButtonElement||r instanceof HTMLFieldSetElement||r instanceof HTMLInputElement||r instanceof HTMLSelectElement||r instanceof HTMLTextAreaElement||r instanceof l}function V(r,t,e){const s=document.createElement(r);if(t)for(const[o,i]of Object.entries(t))s.setAttribute(o,i);return e&&(s.innerHTML=e),s}const D=r=>r===String?"":r===Number?0:r===Boolean?!1:r===Array?[]:r===Object?{}:void 0;function y(r){const t=[];let e=r.firstElementChild;for(;e;)t.push(e),e.shadowRoot&&t.push(...y(e.shadowRoot)),e.firstElementChild&&t.push(...y(e)),e=e.nextElementSibling;return t}function E(r,t){if(r.id===t)return r;const{shadowRoot:e}=r;if(e)for(const s of Array.from(e.children)){const o=E(s,t);if(o)return o}for(const s of Array.from(r.children)){const o=E(s,t);if(o)return o}return null}const A=r=>r.substring(R).split(".")[0];function v(r,t){let e=r[0];return t.forEach((s,o)=>{e+=s+r[o+1]}),e}function T(r){const t=typeof r;return t==="string"||t==="number"||t==="boolean"}const q=r=>r.replace(/<!--[\s\S]*?-->/g,"");function $(r,t,e,s){return r.slice(0,t)+s+r.slice(t+e)}function w(r){const t=Number(r);if(isNaN(t))throw new m(`can't convert "${r}" to a number`);return t}function x(r,t,e){if(T(e))if(typeof e=="boolean"){e?r.setAttribute(t,t):r.removeAttribute(t);const s=l.getPropName(t);r[s]=e}else r.getAttribute(t)!==e&&r.setAttribute(t,String(e));else{const s=l.getPropName(t);r[s]=e}}function C(r,t,e){r instanceof CSSRule?r.style.setProperty(t,e):x(r,t,e)}class l extends HTMLElement{static#p=new Map;static#d=new Map;static#m=new Map;static css="";static formAssociated=!1;static html="";static properties={};static propToComputedMap=null;static propToExprsMap=null;static template=null;#t=this.constructor;#s=new Map;#c={};#o;#b={};#a=null;#f=new Map;#h=new Map;constructor(){super(),this.attachShadow({mode:"open"});const t=this.#t;t.properties||(t.properties={}),t.propToComputedMap||(t.propToComputedMap=new Map),t.propToExprsMap||(t.propToExprsMap=new Map)}attributeChangedCallback(t,e,s){t==="disabled"&&this.#y();const o=l.getPropName(t);if(this.#n(o)){const i=this.#w(o,String(s));this[o]=i;const n=this.#c[o];n&&this.setFormValue(n,String(i)),this.propertyChangedCallback(o,e,s)}}#g(t,e,s,o){t.addEventListener(o,n=>{const a=n.target,{value:c}=a,{type:h}=this.#t.properties[e];this[e]=h===Number?w(c):c});let i=this.#f.get(e);i||(i=[],this.#f.set(e,i)),i.push(s?{element:t,attrName:s}:t)}#M(){const t=this.#t;let e=t.template;if(!e){e=t.template=document.createElement("template");let s="<style> :host([hidden]) { display: none; } ";t.css&&(s+=t.css),s+="</style>",s+=t.html,e.innerHTML=s}this.shadowRoot?.replaceChildren(e.content.cloneNode(!0))}changed(t,e,s){this[e]=s}connectedCallback(){this.#I(),this.#R(),this.#M(),this.hasAttribute("disabled")&&this.#y(),requestAnimationFrame(()=>{this.shadowRoot&&(this.#S(this.shadowRoot),this.#E(this.shadowRoot),l.#O()),this.#P()})}#P(){const t=this.#t,{properties:e}=t;for(const[s,{computed:o}]of Object.entries(e))o&&(this[s]=this.#i(o))}static dataForId(t){const e=crypto.randomUUID();return l.#d.set(e,t),e}#R(){const t=this.#t,{observedAttributes:e,properties:s}=t;for(const[o,i]of Object.entries(s))this.#v(o,i,e)}#v(t,e,s){const o=l.getAttrName(t),i=this.hasAttribute(o);e.required&&!i&&this.#e(this,t,"is a required attribute");let n=e.value;this.hasOwnProperty(t)&&(n=this[t],delete this[t]),console.log("wrec.ts #defineProp: propName =",t),console.log("wrec.ts #defineProp: value =",n);const{type:a}=e,c=a===Boolean?n||i:s.includes(o)&&i?this.#T(t,o):n||D(a),h="#"+t;this[h]=c,e.computed&&this.#N(t,e),Object.defineProperty(this,t,{enumerable:!0,get(){return this[h]},set(f){a===Number&&typeof f=="string"&&(f=w(f));const u=this[h];if(f===u)return;this.#V(t,a,f),this[h]=f;const{state:S,stateProp:L}=this.#t.properties[t];L&&O(S,L,f),this.#j(t),this.#H(t,a,f,o),this.#L(t),this.#F(t,f);const N=this.#c[t];N&&this.setFormValue(N,String(f)),this.propertyChangedCallback(t,u,f),e.dispatch&&this.dispatch("change",{[t]:f})}})}#y(){const t=this.hasAttribute("disabled"),e=y(this.shadowRoot);for(const s of e)B(s)&&(s.disabled=t)}disconnectedCallback(){this.#s.clear(),this.#h.clear()}dispatch(t,e){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e}))}displayIfSet(t,e="block"){return`display: ${t?e:"none"}`}static elementName(){return this.name.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}#$(t){const e=t instanceof l;for(const s of t.getAttributeNames()){const o=t.getAttribute(s),i=this.#A(t,o);if(i){const n=this[i];n===void 0&&this.#r(t,s,i),t[i]=n;let[a,c]=s.split(":");a==="value"&&(c?(t["on"+c]===void 0&&this.#e(t,s,"refers to an unsupported event name"),t.setAttribute(a,this[i])):c="change",this.#g(t,i,a,c)),e&&t.#h.set(l.getPropName(a),i)}this.#l(o,t,s)}}#i(t){const e=new Function("return "+t).call(this);return Array.isArray(e)?e.join(""):e}#x(t){const{localName:e}=t;if(e==="style"){const{sheet:s}=t,o=s?.cssRules??[],i=Array.from(o);for(const n of i)if(n.constructor===CSSStyleRule){const a=Array.from(n.style);for(const c of a)if(c.startsWith("--")){const h=n.style.getPropertyValue(c);this.#l(h,n,c)}}}else{let s="";if(e==="textarea"){const o=t.textContent?.match(j);o&&(s=o[1])}else{const o=Array.from(t.childNodes).find(i=>i.nodeType===Node.COMMENT_NODE);o&&(s=o.textContent?.trim()??"")}if(s){const o=this.#A(t,s);e==="textarea"&&o?(this.#g(t,o,null,"change"),t.textContent=this[o]):this.#l(s,t)}}}formAssociatedCallback(){let t=this.getAttribute("form-assoc");if(!t){const n=this.getAttribute("name");if(n)if(this.#n("value"))t=`value:${n}`;else throw new m("can't submit by name because component has no value property");else return}const e={},s=t.split(",");for(const n of s){const[a,c]=n.split(":");e[a.trim()]=c.trim()}this.#c=e,this.#o=new FormData,this.#a=this.attachInternals(),this.#a.setFormValue(this.#o);const o=Object.keys(this.#t.properties),i=this.#b;for(const n of o)i[n]=this[n]}formResetCallback(){const t=this.#b;for(const e of Object.keys(t))this[e]=t[e]}static getAttrName(t){let e=l.#m.get(t);return e||(e=t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),l.#m.set(t,e)),e}static getPropName(t){let e=l.#p.get(t);return e||(e=t.replace(/-([a-z])/g,(s,o)=>o.toUpperCase()),l.#p.set(t,e)),e}#n(t){return!!this.#t.properties[t]}#E(t){const e=Array.from(t.querySelectorAll("*"));for(const s of e)this.#$(s),s.firstElementChild||this.#x(s)}static get observedAttributes(){const t=Object.keys(this.properties||{}).map(l.getAttrName);return t.includes("disabled")||t.push("disabled"),t}propertyChangedCallback(t,e,s){}#A(t,e){if(!e||!I.test(e))return;const s=A(e);return this[s]===void 0&&this.#r(t,"",s),s}#L(t){const o=this.#t.propToExprsMap.get(t)||[];for(const i of o){const n=this.#i(i),a=this.#s.get(i)??[];for(const c of a)c instanceof HTMLElement?this.#C(c,n):c instanceof CSSStyleRule||C(c.element,c.attrName,n)}requestAnimationFrame(()=>{this.#k(t)})}static register(){const t=this.elementName();customElements.get(t)||customElements.define(t,this)}#N(t,e){const{computed:s,uses:o}=e,i=this.#t.propToComputedMap;function n(c,h){let f=i.get(c);f||(f=[],i.set(c,f)),f.push([t,h])}const a=s.match(g)||[];for(const c of a){const h=c.substring(R);this[h]===void 0&&this.#r(null,t,h),typeof this[h]!="function"&&n(h,s)}if(o)for(const c of o.split(","))n(c,s)}#l(t,e,s=void 0){if(!t)return;const o=this.#u(e,s,t);if(!o){const c=t.replaceAll("this..","this.");s?C(e,s,c):"textContent"in e&&(e.textContent=c);return}const i=this.#t;o.forEach(c=>{const h=A(c);if(typeof this[h]=="function")return;const f=i.propToExprsMap;let u=f.get(h);u||(u=[],f.set(h,u)),u.includes(t)||u.push(t)});for(const[c,h]of this.#s.entries())for(const f of h){const u=f instanceof HTMLElement||f instanceof CSSStyleRule?f:f.element;u instanceof CSSStyleRule||u.isConnected||this.#s.set(c,h.filter(S=>S!==f))}let n=this.#s.get(t);n||(n=[],this.#s.set(t,n)),n.push(s?{element:e,attrName:s}:e);const a=this.#i(t);s?C(e,s,a):this.#C(e,a)}setAttributeSafe(t,e){this.hasAttribute(t)||this.setAttribute(t,e)}setFormValue(t,e){!this.#o||!T(e)||(this.#o.set(t,e),this.#a?.setFormValue(this.#o))}static#O(){for(const[t,e]of l.#d.entries()){const s=E(document.body,t);if(s)for(const[o,i]of Object.entries(e))s[o]=i}}#e(t,e,s){const o=this.#t,i=t instanceof HTMLElement?t.localName:"CSS rule";throw new m(`component ${o.elementName()}`+(t?`, element "${i}"`:"")+(e?`, attribute "${e}"`:"")+` ${s}`)}#r(t,e,s){this.#e(t,e,`refers to missing property "${s}"`)}#T(t,e){return this.#w(t,this.getAttribute(e))}#w(t,e){if(e?.match(g))return e;const s=this.#t,{type:o}=s.properties[t];if(o||this.#e(null,t,"does not specify its type"),o===String)return e;if(o===Number)return w(e);if(o===Boolean)return e==="true"?!0:e==="false"||e==="null"?!1:(e&&e!==t&&this.#e(null,t,"is a Boolean attribute, so its value must match attribute name or be missing"),e===t)}#H(t,e,s,o){if(T(s)&&this.hasAttribute(o)){const i=e===Boolean?this.hasAttribute(o):this.#T(t,o);s!==i&&x(this,t,s)}}#k(t){const e=this[t],s=this.#f.get(t)||[];for(const o of s)if(o instanceof HTMLElement)o.localName==="textarea"?o.value=e:o.textContent=e;else if(!(o instanceof CSSStyleRule)){const{element:i,attrName:n}=o;if(i instanceof HTMLElement){const a=l.getPropName(n);i[a]=e}else i instanceof CSSStyleRule&&i.style.setProperty(n,e)}}#j(t){const s=this.#t.propToComputedMap.get(t)||[];for(const[o,i]of s)this[o]=this.#i(i)}#C(t,e){if(e===void 0)return;const s=t instanceof HTMLElement,o=s?t.localName:"",i=typeof e;i!=="string"&&i!=="number"&&this.#e(t,void 0," computed content is not a string or number"),o==="textarea"?t.value=e:s&&i==="string"&&e.trim().startsWith("<")?(t.innerHTML=e,this.#S(t),this.#E(t)):s&&(t.textContent=e)}#F(t,e){const s=this.#h.get(t);if(!s)return;const o=this.getRootNode();if(!(o instanceof ShadowRoot))return;const{host:i}=o;if(!i)return;const n=i;n[s]=e}useState(t,e){if(!e){e={};for(const s of Object.keys(t))e[s]=s}this.#B(t,e);for(const[s,o]of Object.entries(e))if(this.#n(o)){const i=d(t,s);i!==void 0&&(this[o]=i);const n=this.#t.properties[o];n.state=t,n.stateProp=s}t.addListener(this,e)}#I(){const t=this.#t,e=this.#t.name,s=new Set(Object.keys(t.properties));for(const o of this.getAttributeNames())if(o!=="class"&&o!=="id"&&o!=="disabled"&&!o.startsWith("on")){if(o==="form-assoc"){if(!this.#t.formAssociated)throw new m(`add "static formAssociated = true;" to class ${e}`);continue}if(!s.has(l.getPropName(o))){if(o==="name"){if(t.formAssociated)continue;throw new m(`name attribute requires "static formAssociated = true;" in class ${e}`)}this.#e(null,o,"is not a supported attribute")}}}#u(t,e,s){const o=s.match(g);if(o)return o.forEach(i=>{const n=A(i);this[n]===void 0&&this.#r(t,e,n)}),o}#B(t,e){for(const[s,o]of Object.entries(e)){let i=d(t,s);if(i===void 0)throw new m(`invalid state path "${s}"`);i=this[o],this.#n(o)||this.#e(null,o,"refers to missing property in useState map")}}#V(t,e,s){if(s instanceof e)return;let o=typeof s;if(o==="object"){const{constructor:i}=s;o=i.name,i!==e&&this.#e(null,t,`was set to a ${o}, but must be a ${e.name}`)}o!==e.name.toLowerCase()&&this.#e(null,t,`was set to a ${o}, but must be a ${e.name}`)}#S(t){const e=Array.from(t.querySelectorAll("*"));for(const s of e){const o=[];for(const i of Array.from(s.attributes)){const n=i.name;if(n.startsWith("on")){let a=n.slice(2);a=a[0].toLowerCase()+a.slice(1).toLowerCase();const c=i.value;this.#u(s,n,c);let h;typeof this[c]=="function"?h=f=>this[c](f):(this.#u(s,n,c),h=()=>this.#i(c)),s.addEventListener(a,h),o.push(n)}}for(const i of o)s.removeAttribute(i)}}}function _(r,...t){let e=v(r,t);for(;;){const s=H.exec(e);if(!s)break;const o=s[2];if(P.test(o)){const i=s[1];if(!i.startsWith("--")){const n=`--${i}: ${o};
|
|
2
|
-
${i}: var(--${i});`;e
|
|
1
|
+
(function(p,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(p=typeof globalThis<"u"?globalThis:p||self,d(p.wrec={}))})(this,(function(p){"use strict";function d(r,t){let e=r;for(const s of t.split("."))e=e[s];return e}function k(r,t,e){const s=t.split("."),o=s.length-1;let i=r;s.forEach((n,h)=>{h===o?i[n]=e:i=i[n]})}class b extends Error{}const j=/([a-zA-Z-]+)\s*:\s*([^;}]+)/g,P="a-zA-Z_$",F=P+"0-9",g=`[${P}][${F}]*`,_=/<!--\s*(.*?)\s*-->/,V=/<(\w+)(?:\s[^>]*)?>((?:[^<]|<(?!\w))*?)<\/\1>/g,T=new RegExp(`^this\\.${g}$`),C=new RegExp(`this\\.${g}(\\.${g})*`,"g"),N=new RegExp(`this\\.${g}(\\.${g})*`),I=new Set(["class","style"]),$=5;function D(r){return r instanceof HTMLButtonElement||r instanceof HTMLFieldSetElement||r instanceof HTMLInputElement||r instanceof HTMLSelectElement||r instanceof HTMLTextAreaElement||r instanceof u}function B(r,t,e){const s=document.createElement(r);if(t)for(const[o,i]of Object.entries(t))s.setAttribute(o,i);return e&&(s.innerHTML=e),s}const q=r=>r===String?"":r===Number?0:r===Boolean?!1:r===Array?[]:r===Object?{}:void 0;function w(r){const t=[];let e=r.firstElementChild;for(;e;)t.push(e),e.shadowRoot&&t.push(...w(e.shadowRoot)),e.firstElementChild&&t.push(...w(e)),e=e.nextElementSibling;return t}const A=r=>r.substring($).split(".")[0];function x(r,t){let e=r[0];return t.forEach((s,o)=>{e+=s+r[o+1]}),e}function S(r){const t=typeof r;return t==="string"||t==="number"||t==="boolean"}function E(r){return r.localName==="textarea"}function v(r){const{localName:t}=r;return t==="input"||t==="select"}const z=r=>r.replace(/<!--[\s\S]*?-->/g,"");function L(r,t,e,s){return r.slice(0,t)+s+r.slice(t+e)}function M(r){const t=Number(r);if(isNaN(t))throw new b(`can't convert "${r}" to a number`);return t}function O(r,t,e){const[s,o]=t.split(":");if(S(e))if(typeof e=="boolean"){e?r.setAttribute(s,s):r.removeAttribute(s);const i=u.getPropName(s);r[i]=e}else{const i=r.getAttribute(t),n=String(e);i!==n&&(r.setAttribute(s,n),s==="value"&&v(r)&&(r.value=n))}else{const i=u.getPropName(t);r[i]=e}}function R(r,t,e){const[s,o]=t.split(":");r instanceof CSSRule?r.style.setProperty(s,e):(O(r,s,e),s==="value"&&v(r)&&(r.value=e))}class u extends HTMLElement{static#p=new Map;static#d=new Map;static css="";static formAssociated=!1;static html="";static properties={};static propToComputedMap=null;static propToExprsMap=null;static template=null;#t=this.constructor;#s=new Map;#a={};#i;#f={};#h=null;#u=new Map;constructor(){super(),this.attachShadow({mode:"open"});const t=this.#t;t.properties||(t.properties={}),t.propToComputedMap||(t.propToComputedMap=new Map),t.propToExprsMap||(t.propToExprsMap=new Map)}attributeChangedCallback(t,e,s){t==="disabled"&&this.#m();const o=u.getPropName(t);if(this.#n(o)){const i=this.#y(o,String(s));this[o]=i;const n=this.#a[o];n&&this.setFormValue(n,String(i)),this.propertyChangedCallback(o,e,s)}}#w(){const t=this.#t;let e=t.template;if(!e){e=t.template=document.createElement("template");let s="<style> :host([hidden]) { display: none; } ";t.css&&(s+=t.css),s+="</style>",s+=t.html,e.innerHTML=s}this.shadowRoot?.replaceChildren(e.content.cloneNode(!0))}changed(t,e,s){this[e]=s}connectedCallback(){this.#H(),this.#v(),this.#w(),this.hasAttribute("disabled")&&this.#m(),requestAnimationFrame(()=>{this.shadowRoot&&(this.#C(this.shadowRoot),this.#b(this.shadowRoot)),this.#S()})}#S(){const t=this.#t,{properties:e}=t;for(const[s,{computed:o}]of Object.entries(e))o&&(this[s]=this.#o(o))}#v(){const t=this.#t,{observedAttributes:e,properties:s}=t;for(const[o,i]of Object.entries(s))this.#M(o,i,e)}#M(t,e,s){const o=u.getAttrName(t),i=this.hasAttribute(o);e.required&&!i&&this.#e(this,t,"is a required attribute");let n=e.value;this.hasOwnProperty(t)&&(n=this[t],delete this[t]);const{type:h}=e,c=h===Boolean?n||i:s.includes(o)&&i?this.#A(t,o):n||q(h),f="#"+t;this[f]=c,e.computed&&this.#$(t,e),Object.defineProperty(this,t,{enumerable:!0,get(){return this[f]},set(a){h===Number&&typeof a=="string"&&(a=M(a));const l=this[f];if(a===l)return;this.#j(t,h,a),this[f]=a;const{state:m,stateProp:y}=this.#t.properties[t];y&&k(m,y,a),this.#L(t),this.#x(t,h,a,o),this.#E(t),this.#O(t,a);const H=this.#a[t];H&&this.setFormValue(H,String(a)),this.propertyChangedCallback(t,l,a),e.dispatch&&this.dispatch("change",{[t]:a})}})}#m(){const t=this.hasAttribute("disabled"),e=w(this.shadowRoot);for(const s of e)D(s)&&(s.disabled=t)}disconnectedCallback(){this.#s.clear(),this.#f.clear(),this.#u.clear()}dispatch(t,e){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e}))}displayIfSet(t,e="block"){return`display: ${t?e:"none"}`}static elementName(){return this.name.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}#R(t){const e=t instanceof u;for(const s of t.getAttributeNames()){const o=t.getAttribute(s),i=this.#g(t,o);if(i){const n=this[i];n===void 0&&this.#c(t,s,i),t[i]=n;let[h,c]=s.split(":");h==="value"&&(c?(t["on"+c]===void 0&&this.#e(t,s,"refers to an unsupported event name"),t.setAttribute(h,this[i])):c="change"),e&&t.#u.set(u.getPropName(h),i)}this.#r(o,t,s)}}#o(t){const e=new Function("return "+t).call(this);return Array.isArray(e)?e.join(""):e}#P(t){const{localName:e}=t;if(e==="style"){const{sheet:s}=t,o=s?.cssRules??[],i=Array.from(o);for(const n of i)if(n.constructor===CSSStyleRule){const h=Array.from(n.style);for(const c of h)if(c.startsWith("--")){const f=n.style.getPropertyValue(c);this.#r(f,n,c)}}}else{let s="";if(E(t)){this.#r(t.textContent,t);const o=t.textContent?.match(_);o&&(s=o[1])}else{const o=Array.from(t.childNodes).find(i=>i.nodeType===Node.COMMENT_NODE);o&&(s=o.textContent?.trim()??"")}if(s){const o=this.#g(t,s);o&&E(t)?t.textContent=this[o]:this.#r(s,t)}}}formAssociatedCallback(){let t=this.getAttribute("form-assoc");if(!t){const n=this.getAttribute("name");if(n)if(this.#n("value"))t=`value:${n}`;else return;else return}const e={},s=t.split(",");for(const n of s){const[h,c]=n.split(":");e[h.trim()]=c.trim()}this.#a=e,this.#i=new FormData,this.#h=this.attachInternals(),this.#h.setFormValue(this.#i);const o=Object.keys(this.#t.properties),i=this.#f;for(const n of o)i[n]=this[n]}formResetCallback(){const t=this.#f;for(const e of Object.keys(t)){let s=t[e];T.test(s)&&(s=this.#o(s)),this[e]=s}}static getAttrName(t){let e=u.#d.get(t);return e||(e=t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),u.#d.set(t,e)),e}static getPropName(t){let e=u.#p.get(t);return e||(e=t.replace(/-([a-z])/g,(s,o)=>o.toUpperCase()),u.#p.set(t,e)),e}#N(t,e,s){if(s.length!==1)return;const[o]=s;if(!T.test(o))return;const i=v(t)||E(t);let[n,h]=(e??"").split(":");if(!(i&&n==="value"||E(t)))return;h?t["on"+h]===void 0&&this.#e(t,e,"refers to an unsupported event name"):h="change";const f=A(o);t.addEventListener(h,a=>{const{target:l}=a;if(!l)return;const m=l.value,{type:y}=this.#t.properties[f];this[f]=y===Number?M(m):m,this.#E(f)})}#n(t){return!!this.#t.properties[t]}#b(t){const e=Array.from(t.querySelectorAll("*"));for(const s of e)this.#R(s),s.firstElementChild||this.#P(s)}static get observedAttributes(){const t=Object.keys(this.properties||{}).map(u.getAttrName);return t.includes("disabled")||t.push("disabled"),t}propertyChangedCallback(t,e,s){}#g(t,e){if(!e||!T.test(e))return;const s=A(e);return this[s]===void 0&&this.#c(t,"",s),s}#E(t){const o=this.#t.propToExprsMap.get(t)||[];for(const i of o){let n=this.#o(i);const h=this.#s.get(i)??[];for(const c of h)if(c instanceof HTMLElement)this.#T(c,n);else if(!(c instanceof CSSStyleRule)){const{element:f,attrName:a}=c;f instanceof CSSStyleRule?f.style.setProperty(a,n):R(f,a,n)}}}static register(){const t=this.elementName();customElements.get(t)||customElements.define(t,this)}#$(t,e){const{computed:s,uses:o}=e,i=this.#t.propToComputedMap;function n(c,f){let a=i.get(c);a||(a=[],i.set(c,a)),a.push([t,f])}const h=s.match(C)||[];for(const c of h){const f=c.substring($);this[f]===void 0&&this.#c(null,t,f),typeof this[f]!="function"&&n(f,s)}if(o)for(const c of o.split(","))n(c,s)}#r(t,e,s=void 0){if(!t)return;const o=this.#l(e,s,t);if(!o){const c=t.replaceAll("this..","this.");s?R(e,s,c):"textContent"in e&&(e.textContent=c);return}const i=this.#t;o.forEach(c=>{const f=A(c);if(typeof this[f]=="function")return;const a=i.propToExprsMap;let l=a.get(f);l||(l=[],a.set(f,l)),l.includes(t)||l.push(t)});for(const[c,f]of this.#s.entries())for(const a of f){const l=a instanceof HTMLElement||a instanceof CSSStyleRule?a:a.element;l instanceof CSSStyleRule||l.isConnected||this.#s.set(c,f.filter(m=>m!==a))}let n=this.#s.get(t);n||(n=[],this.#s.set(t,n)),n.push(s?{element:e,attrName:s}:e),e instanceof HTMLElement&&this.#N(e,s,o);const h=this.#o(t);s?R(e,s,h):this.#T(e,h)}setAttributeSafe(t,e){this.hasAttribute(t)||this.setAttribute(t,e)}setFormValue(t,e){!this.#i||!S(e)||(this.#i.set(t,e),this.#h?.setFormValue(this.#i))}#e(t,e,s){const o=this.#t,i=t instanceof HTMLElement?t.localName:"CSS rule";throw new b(`component ${o.elementName()}`+(t?`, element "${i}"`:"")+(e?`, attribute "${e}"`:"")+` ${s}`)}#c(t,e,s){this.#e(t,e,`refers to missing property "${s}"`)}#A(t,e){return this.#y(t,this.getAttribute(e))}#y(t,e){if(e?.match(C))return e;const s=this.#t,{type:o}=s.properties[t];if(o||this.#e(null,t,"does not specify its type"),o===String)return e;if(o===Number)return M(e);if(o===Boolean)return e==="true"?!0:e==="false"||e==="null"?!1:(e&&e!==t&&this.#e(null,t,"is a Boolean attribute, so its value must match attribute name or be missing"),e===t)}#x(t,e,s,o){if(S(s)&&this.hasAttribute(o)){const i=e===Boolean?this.hasAttribute(o):this.#A(t,o);s!==i&&O(this,t,s)}}#L(t){const s=this.#t.propToComputedMap.get(t)||[];for(const[o,i]of s)this[o]=this.#o(i)}#T(t,e){if(e===void 0)return;const s=t instanceof HTMLElement,o=typeof e;o!=="string"&&o!=="number"&&this.#e(t,void 0," computed content is not a string or number"),t instanceof HTMLElement&&E(t)?t.value=e:s&&o==="string"&&e.trim().startsWith("<")?(t.innerHTML=e,this.#C(t),this.#b(t)):s&&(t.textContent=e)}#O(t,e){const s=this.#u.get(t);if(!s)return;const o=this.getRootNode();if(!(o instanceof ShadowRoot))return;const{host:i}=o;if(!i)return;const n=i;n[s]=e}useState(t,e){if(!e){e={};for(const s of Object.keys(t))e[s]=s}this.#k(t,e);for(const[s,o]of Object.entries(e))if(this.#n(o)){const i=d(t,s);i!==void 0&&(this[o]=i);const n=this.#t.properties[o];n.state=t,n.stateProp=s}t.addListener(this,e)}#H(){const t=this.#t,e=new Set(Object.keys(t.properties));for(const o of e)I.has(o)&&this.#e(null,"",`property "${o}" is not allowed because it is a reserved attribute`);const s=this.#t.name;for(const o of this.getAttributeNames())if(o!=="class"&&o!=="id"&&o!=="disabled"&&!o.startsWith("on")){if(o==="form-assoc"){if(!t.formAssociated)throw new b(`add "static formAssociated = true;" to class ${s}`);continue}if(!e.has(u.getPropName(o))){if(o==="name"){if(t.formAssociated)continue;throw new b(`name attribute requires "static formAssociated = true;" in class ${s}`)}this.#e(null,o,"is not a supported attribute")}}}#l(t,e,s){const o=s.match(C);if(o)return o.forEach(i=>{const n=A(i);this[n]===void 0&&this.#c(t,e,n)}),o}#k(t,e){for(const[s,o]of Object.entries(e)){let i=d(t,s);if(i===void 0)throw new b(`invalid state path "${s}"`);i=this[o],this.#n(o)||this.#e(null,o,"refers to missing property in useState map")}}#j(t,e,s){if(s instanceof e)return;let o=typeof s;if(o==="object"){const{constructor:i}=s;o=i.name,i!==e&&this.#e(null,t,`was set to a ${o}, but must be a ${e.name}`)}o!==e.name.toLowerCase()&&this.#e(null,t,`was set to a ${o}, but must be a ${e.name}`)}#C(t){const e=Array.from(t.querySelectorAll("*"));for(const s of e){const o=[];for(const i of Array.from(s.attributes)){const n=i.name;if(n.startsWith("on")){let h=n.slice(2);h=h[0].toLowerCase()+h.slice(1).toLowerCase();const c=i.value;this.#l(s,n,c);let f;typeof this[c]=="function"?f=a=>this[c](a):(this.#l(s,n,c),f=()=>this.#o(c)),s.addEventListener(h,f),o.push(n)}}for(const i of o)s.removeAttribute(i)}}}function Z(r,...t){let e=x(r,t);for(;;){const s=j.exec(e);if(!s)break;const o=s[2];if(N.test(o)){const i=s[1];if(!i.startsWith("--")){const n=`--${i}: ${o};
|
|
2
|
+
${i}: var(--${i});`;e=L(e,s.index,s[0].length,n)}}}return e}function K(r,...t){let e=x(r,t);for(;;){const s=V.exec(e);if(!s||s[1]==="style")break;const o=z(s[2]);if(N.test(o)){const i=`<!-- ${o.trim()} -->`,n=s.index+s[0].indexOf(">")+1;e=L(e,n,o.length,i)}}return e}p.Wrec=u,p.createElement=B,p.css=Z,p.html=K,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "wrec",
|
|
3
3
|
"description": "a small library that greatly simplifies building web components",
|
|
4
4
|
"author": "R. Mark Volkmann",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.17.1",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"clean": "rm -rf dist",
|
|
26
26
|
"preview": "vite preview",
|
|
27
27
|
"lint": "oxlint",
|
|
28
|
-
"minify": "tsc && terser dist/wrec.js dist/state.js -c -m -o dist/wrec.min.js",
|
|
28
|
+
"minify": "tsc && terser dist/wrec.js dist/wrec-state.js -c -m -o dist/wrec.min.js",
|
|
29
29
|
"reinstall": "rm -rf node_modules package-lock.json && npm install",
|
|
30
30
|
"test": "playwright test",
|
|
31
31
|
"testui": "playwright test --ui",
|