wrec 0.23.0 → 0.23.2

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