wrec 0.22.6 → 0.22.8

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.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/dist/wrec.es.js +203 -173
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -151,6 +151,7 @@ to one of those strings.
151
151
 
152
152
  Server-side rendering (SSR) is supported.
153
153
  This requires importing from "wrec/ssr" instead of "wrec".
154
+ "wrec/ssr" should only be imported by server code.
154
155
  That bundle is much larger because it bundles the node-html-parser package.
155
156
  However, the size increase is not likely an issue
156
157
  because it is used on the server-side rather than downloaded to web browsers.
package/dist/wrec.es.js CHANGED
@@ -1,10 +1,10 @@
1
1
  var B = (r) => {
2
2
  throw TypeError(r);
3
3
  };
4
- var O = (r, t, e) => t.has(r) || B("Cannot " + e);
5
- var u = (r, t, e) => (O(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) => (O(r, t, "write to private field"), s ? s.call(r, e) : t.set(r, e), e), V = (r, t, e) => (O(r, t, "access private method"), e);
4
+ var N = (r, t, e) => t.has(r) || B("Cannot " + e);
5
+ var u = (r, t, e) => (N(r, t, "read from private field"), e ? e.call(r) : t.get(r)), b = (r, t, e) => t.has(r) ? B("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(r) : t.set(r, e), w = (r, t, e, s) => (N(r, t, "write to private field"), s ? s.call(r, e) : t.set(r, e), e), V = (r, t, e) => (N(r, t, "access private method"), e);
6
6
  import W from "xss";
7
- function Z(r, t, e = "") {
7
+ function U(r, t, e = "") {
8
8
  const s = /* @__PURE__ */ new WeakMap(), o = {
9
9
  // Intercept property reads.
10
10
  // This creates nested proxies lazily.
@@ -13,38 +13,38 @@ function Z(r, t, e = "") {
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 h = e ? `${e}.${n}` : n, f = Z(c, t, h);
17
- return s.set(c, f), f;
16
+ const f = e ? `${e}.${n}` : n, l = U(c, t, f);
17
+ return s.set(c, l), l;
18
18
  },
19
19
  // Intercept property writes.
20
20
  set(i, n, c) {
21
21
  const a = Reflect.get(i, n);
22
22
  if (a !== c) {
23
23
  Reflect.set(i, n, c);
24
- const h = e ? `${e}.${n}` : n;
25
- t(h, a, c);
24
+ const f = e ? `${e}.${n}` : n;
25
+ t(f, a, c);
26
26
  }
27
27
  return !0;
28
28
  }
29
29
  };
30
30
  return new Proxy(r, o);
31
31
  }
32
- function U(r) {
32
+ function Z(r) {
33
33
  const t = {};
34
34
  for (const [e, s] of Object.entries(r)) {
35
35
  const o = typeof s == "object" && s !== null;
36
- t[e] = o ? U(s) : s;
36
+ t[e] = o ? Z(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, R, d, v, C, g, N, Y;
43
+ var y, $, d, v, C, g, O, Y;
44
44
  const T = class T {
45
45
  constructor(t, e, s) {
46
- b(this, N);
47
- b(this, R, /* @__PURE__ */ Symbol("objectId"));
46
+ b(this, O);
47
+ b(this, $, /* @__PURE__ */ Symbol("objectId"));
48
48
  // This cannot be replaced by a WeakMap<ChangeListener, Set<string>>
49
49
  // because there is no way to iterate over the keys of a WeakMap.
50
50
  b(this, d, []);
@@ -54,7 +54,7 @@ const T = class T {
54
54
  if (!t) throw new z("name cannot be empty");
55
55
  if (u(T, y).has(t))
56
56
  throw new z(`WrecState with name "${t}" already exists`);
57
- if (w(this, v, t), w(this, C, e), w(this, g, Z({}, V(this, N, Y).bind(this))), e && P) {
57
+ if (w(this, v, t), w(this, C, e), w(this, g, U({}, V(this, O, Y).bind(this))), e && P) {
58
58
  const o = sessionStorage.getItem("wrec-state-" + t), i = o ? JSON.parse(o) : void 0;
59
59
  i && (s = i);
60
60
  }
@@ -106,7 +106,7 @@ const T = class T {
106
106
  }), u(this, g)[t] = e;
107
107
  }
108
108
  get id() {
109
- return u(this, R);
109
+ return u(this, $);
110
110
  }
111
111
  // This is useful for debugging from the DevTools console.
112
112
  // For example: state.log()
@@ -119,7 +119,7 @@ const T = class T {
119
119
  w(this, d, u(this, d).filter((e) => e.listenerRef.deref() !== t));
120
120
  }
121
121
  };
122
- y = new WeakMap(), R = new WeakMap(), d = new WeakMap(), v = new WeakMap(), C = new WeakMap(), g = new WeakMap(), N = new WeakSet(), Y = function(t, e, s) {
122
+ y = new WeakMap(), $ = new WeakMap(), d = new WeakMap(), v = new WeakMap(), C = new WeakMap(), g = new WeakMap(), O = new WeakSet(), Y = function(t, e, s) {
123
123
  const o = /* @__PURE__ */ new Set();
124
124
  for (const i of u(this, d)) {
125
125
  const n = i.listenerRef.deref();
@@ -144,7 +144,7 @@ y = new WeakMap(), R = new WeakMap(), d = new WeakMap(), v = new WeakMap(), C =
144
144
  }, b(T, y, /* @__PURE__ */ new Map()), P && window.addEventListener("beforeunload", () => {
145
145
  for (const [t, e] of u(T, y).entries())
146
146
  if (u(e, C)) {
147
- const s = U(e);
147
+ const s = Z(e);
148
148
  sessionStorage.setItem("wrec-state-" + t, JSON.stringify(s));
149
149
  }
150
150
  });
@@ -221,7 +221,7 @@ const rt = /* @__PURE__ */ new Set([
221
221
  };
222
222
  class E extends Error {
223
223
  }
224
- const at = /([a-zA-Z-]+)\s*:\s*([^;}]+)/g, G = "a-zA-Z_$", ft = G + "0-9", S = `[${G}][${ft}]*`, ht = /<!--\s*(.*?)\s*-->/, lt = /<(\w+)(?:\s[^>]*)?>((?:[^<]|<(?!\w))*?)<\/\1>/g, j = new RegExp(`^this\\.${S}$`), L = new RegExp(`this\\.${S}(\\.${S})*`, "g"), Q = new RegExp(`this\\.${S}(\\.${S})*`), ut = 5;
224
+ const at = /([a-zA-Z-]+)\s*:\s*([^;}]+)/g, G = "a-zA-Z_$", ft = G + "0-9", A = `[${G}][${ft}]*`, lt = /<!--\s*(.*?)\s*-->/, ht = /<(\w+)(?:\s[^>]*)?>((?:[^<]|<(?!\w))*?)<\/\1>/g, L = new RegExp(`^this\\.${A}$`), j = new RegExp(`this\\.${A}(\\.${A})*`, "g"), Q = new RegExp(`this\\.${A}(\\.${A})*`), ut = 5;
225
225
  function pt(r) {
226
226
  return r instanceof HTMLButtonElement || r instanceof HTMLFieldSetElement || r instanceof HTMLInputElement || r instanceof HTMLSelectElement || r instanceof HTMLTextAreaElement || r instanceof p;
227
227
  }
@@ -233,11 +233,11 @@ function Et(r, t, e) {
233
233
  return e && (s.innerHTML = e), s;
234
234
  }
235
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) {
236
+ function R(r) {
237
237
  const t = [];
238
238
  let e = r.firstElementChild;
239
239
  for (; e; )
240
- t.push(e), e.shadowRoot && t.push(...$(e.shadowRoot)), e.firstElementChild && t.push(...$(e)), e = e.nextElementSibling;
240
+ t.push(e), e.shadowRoot && t.push(...R(e.shadowRoot)), e.firstElementChild && t.push(...R(e)), e = e.nextElementSibling;
241
241
  return t;
242
242
  }
243
243
  const M = (r) => r.substring(ut).split(".")[0];
@@ -251,7 +251,7 @@ function I(r) {
251
251
  const t = typeof r;
252
252
  return t === "string" || t === "number" || t === "boolean";
253
253
  }
254
- function A(r) {
254
+ function S(r) {
255
255
  return r.localName === "textarea";
256
256
  }
257
257
  function D(r) {
@@ -289,7 +289,7 @@ function k(r, t, e) {
289
289
  }
290
290
  async function bt(r) {
291
291
  const t = /* @__PURE__ */ new Set();
292
- for (const s of $(r.content)) {
292
+ for (const s of R(r.content)) {
293
293
  const { localName: o } = s;
294
294
  o.includes("-") && t.add(o);
295
295
  }
@@ -352,21 +352,24 @@ class p extends ct {
352
352
  static propToExprsMap;
353
353
  static template = null;
354
354
  // This is true while the batchSet method is running.
355
- #f = !1;
355
+ #h = !1;
356
+ // This holds the names of computed properties
357
+ // that are currently being updated.
358
+ #u = /* @__PURE__ */ new Set();
356
359
  #t = this.constructor;
357
360
  // This is a map from expressions to references to them
358
361
  // which can be found in element text content,
359
362
  // attribute values, and CSS property values.
360
363
  // Each component instance needs its own map.
361
- #o = /* @__PURE__ */ new Map();
362
- #h = {};
364
+ #s = /* @__PURE__ */ new Map();
365
+ #p = {};
363
366
  #i;
364
367
  // For components that set `formAssociated` to true,
365
368
  // this stores in the initial value of each property
366
369
  // in the formAssociatedCallback method
367
370
  // so they can be restored in the formResetCallback method.
368
- #l = {};
369
- #u = null;
371
+ #d = {};
372
+ #m = null;
370
373
  // This is a map from properties in this web component
371
374
  // to corresponding properties in a parent web component.
372
375
  // This must be an instance property because
@@ -374,11 +377,11 @@ class p extends ct {
374
377
  // to the properties of different parent components.
375
378
  // This is used to update a parent property
376
379
  // when the corresponding child property value changes.
377
- #p = /* @__PURE__ */ new Map();
380
+ #b = /* @__PURE__ */ new Map();
378
381
  // This is a map from component properties to state bindings.
379
382
  // It must be instance-specific because each component instance
380
383
  // can bind the same property to a different WrecState/path.
381
- #m = /* @__PURE__ */ new Map();
384
+ #r = /* @__PURE__ */ new Map();
382
385
  static define(t) {
383
386
  if (this.elementName = t, _.get(t))
384
387
  throw new E(`custom element ${t} is already defined`);
@@ -390,50 +393,50 @@ class p extends ct {
390
393
  this.#n("attrToPropMap") || (t.attrToPropMap = /* @__PURE__ */ new Map()), this.#n("properties") || (t.properties = {}), this.#n("propToAttrMap") || (t.propToAttrMap = /* @__PURE__ */ new Map()), this.#n("propToComputedMap") || (t.propToComputedMap = /* @__PURE__ */ new Map()), this.#n("propToExprsMap") || (t.propToExprsMap = /* @__PURE__ */ new Map());
391
394
  }
392
395
  attributeChangedCallback(t, e, s) {
393
- t === "disabled" && this.#g();
396
+ t === "disabled" && this.#w();
394
397
  const o = p.getPropName(t);
395
- if (this.#r(o)) {
396
- const i = this.#S(o, s);
398
+ if (this.#c(o)) {
399
+ const i = this.#x(o, s);
397
400
  this[o] = i;
398
- const n = this.#h[o];
401
+ const n = this.#p[o];
399
402
  n && this.setFormValue(n, String(i)), this.propertyChangedCallback(o, e, s);
400
403
  }
401
404
  }
402
405
  // This applies multiple property changes and only updates
403
406
  // the affected parts of the DOM after all of them are made.
404
407
  batchSet(t) {
405
- this.#f = !0;
408
+ this.#h = !0;
406
409
  const e = this.#t.propToExprsMap, s = /* @__PURE__ */ new Set();
407
410
  for (const [c, a] of Object.entries(t)) {
408
411
  this[c] = a;
409
- const h = e.get(c) ?? [];
410
- for (const f of h)
411
- s.add(f);
412
+ const f = e.get(c) ?? [];
413
+ for (const l of f)
414
+ s.add(l);
412
415
  }
413
416
  const o = this.#t.propToComputedMap, i = /* @__PURE__ */ new Set(), n = {};
414
417
  for (const c of Object.keys(t)) {
415
418
  const a = o.get(c) || [];
416
- for (const [h, f] of a)
417
- i.add(h), n[h] = f;
419
+ for (const [f, l] of a)
420
+ i.add(f), n[f] = l;
418
421
  }
419
422
  for (const c of i) {
420
423
  const a = n[c];
421
- this[c] = this.#s(a);
422
- const h = e.get(c) ?? [];
423
- for (const f of h)
424
- s.add(f);
424
+ this.#a(c, this.#o(a));
425
+ const f = e.get(c) ?? [];
426
+ for (const l of f)
427
+ s.add(l);
425
428
  }
426
429
  for (; ; ) {
427
430
  let c = !1;
428
431
  for (const a of i) {
429
- const h = n[a], f = this.#s(h), l = this[a];
430
- JSON.stringify(f) !== JSON.stringify(l) && (this[a] = f, c = !0);
432
+ const f = n[a], l = this.#o(f), h = this[a];
433
+ JSON.stringify(l) !== JSON.stringify(h) && (this.#a(a, l), c = !0);
431
434
  }
432
435
  if (!c) break;
433
436
  }
434
- this.#y([...s]), this.#f = !1;
437
+ this.#E([...s]), this.#h = !1;
435
438
  }
436
- async #x() {
439
+ async #$() {
437
440
  const t = this.#t;
438
441
  let { template: e } = t;
439
442
  e || (e = t.template = document.createElement("template"), e.innerHTML = t.buildHTML()), await bt(e), this.shadowRoot.replaceChildren(e.content.cloneNode(!0));
@@ -451,59 +454,65 @@ class p extends ct {
451
454
  this[e] = s;
452
455
  }
453
456
  connectedCallback() {
454
- this.#F(), this.#$(), this.#x().then(() => {
455
- this.hasAttribute("disabled") && this.#g(), this.#C(this.shadowRoot), this.#w(this.shadowRoot), this.#P();
457
+ this.#D(), this.#N(), this.#$().then(() => {
458
+ this.hasAttribute("disabled") && this.#w(), this.#R(this.shadowRoot), this.#M(this.shadowRoot), this.#O();
456
459
  });
457
460
  }
458
- #P() {
461
+ #O() {
459
462
  const t = this.#t, { properties: e } = t;
460
463
  for (const [s, { computed: o }] of Object.entries(e))
461
- o && (this[s] = this.#s(o));
464
+ o && this.#a(s, this.#o(o));
462
465
  }
463
- #$() {
466
+ #N() {
464
467
  const t = this.#t, { observedAttributes: e, properties: s } = t;
465
468
  for (const [o, i] of Object.entries(s))
466
- i.computed || this.#b(o, i, e);
469
+ i.computed || this.#y(o, i, e);
467
470
  for (const [o, i] of Object.entries(s))
468
- i.computed && this.#b(o, i, e);
471
+ i.computed && this.#y(o, i, e);
469
472
  }
470
- #b(t, e, s) {
473
+ #y(t, e, s) {
471
474
  if (t === "class" || t === "style")
472
475
  throw new E(`"${t}" is a reserved property`);
473
476
  const o = p.getAttrName(t), i = this.hasAttribute(o);
474
477
  e.required && !i && this.#e(this, o, "is a required attribute");
475
478
  let n = e.value;
476
479
  this.hasOwnProperty(t) && (n = this[t], delete this[t]);
477
- const { type: c } = e, a = c === Boolean ? n || i : s.includes(o) && i ? this.#A(t, o) : n ?? K(e), h = "#" + t;
478
- this[h] = a, e.computed && this.#j(t, e), Object.defineProperty(this, t, {
480
+ const { type: c } = e, a = c === Boolean ? n || i : s.includes(o) && i ? this.#C(t, o) : n ?? K(e), f = "#" + t;
481
+ this[f] = a, e.computed && this.#k(t, e), Object.defineProperty(this, t, {
479
482
  enumerable: !0,
480
483
  get() {
481
- return this[h];
484
+ return this[f];
482
485
  },
483
- set(f) {
484
- c === Number && typeof f == "string" && (f = H(f));
485
- const l = this[h];
486
- if (f === l) return;
487
- this.#I(t, c, f), this[h] = f;
488
- const m = this.#m.get(t);
489
- m && ot(m.state, m.stateProp, f), this.#L(t, c, f, o), this.#f || (this.#H(t), this.#M(t)), this.#k(t, f);
490
- const x = this.#h[t];
491
- x && this.setFormValue(x, String(f)), this.propertyChangedCallback(t, l, f), e.dispatch && this.dispatch("change", {
486
+ set(l) {
487
+ e.computed && !this.#u.has(t) && this.#e(
488
+ null,
489
+ t,
490
+ "is a computed property and cannot be set directly"
491
+ ), c === Number && typeof l == "string" && (l = H(l));
492
+ const h = this[f];
493
+ if (l === h) return;
494
+ this.#V(t, c, l), this[f] = l;
495
+ const m = this.#r.get(t);
496
+ m && ot(m.state, m.stateProp, l), this.#F(t, c, l, o), this.#h || (this.#_(t), this.#v(t)), this.#I(t, l);
497
+ const x = this.#p[t];
498
+ x && this.setFormValue(x, String(l)), this.propertyChangedCallback(t, h, l), e.dispatch && this.dispatch("change", {
492
499
  tagName: this.localName,
493
500
  property: t,
494
- oldValue: l,
495
- value: f
501
+ oldValue: h,
502
+ value: l
496
503
  });
497
504
  }
498
505
  });
499
506
  }
500
- #g() {
501
- const t = this.hasAttribute("disabled"), e = $(this.shadowRoot);
507
+ #w() {
508
+ const t = this.hasAttribute("disabled"), e = R(this.shadowRoot);
502
509
  for (const s of e)
503
510
  pt(s) && (s.disabled = t);
504
511
  }
505
512
  disconnectedCallback() {
506
- this.#o.clear(), this.#l.clear(), this.#p.clear();
513
+ for (const { state: t } of this.#r.values())
514
+ t.removeListener(this);
515
+ this.#s.clear(), this.#d.clear(), this.#b.clear(), this.#r.clear();
507
516
  }
508
517
  dispatch(t, e) {
509
518
  this.dispatchEvent(
@@ -519,43 +528,53 @@ class p extends ct {
519
528
  displayIfSet(t, e = "block") {
520
529
  return `display: ${t ? e : "none"}`;
521
530
  }
522
- #R(t) {
531
+ #L(t) {
523
532
  const e = t instanceof p;
524
533
  for (const s of t.getAttributeNames()) {
525
- const o = t.getAttribute(s), i = this.#T(t, o);
534
+ const o = t.getAttribute(s), i = this.#A(t, o);
526
535
  if (i) {
527
536
  const n = this[i];
528
- n === void 0 && this.#a(t, s, i);
537
+ n === void 0 && this.#l(t, s, i);
529
538
  let [c, a] = s.split(":");
530
- const h = p.getPropName(c);
531
- t[h] = 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 && t.#p.set(
539
+ const f = p.getPropName(c), l = this.#T(i);
540
+ e && t.#T(f) || (t[f] = n), c === "value" && (a ? (t["on" + a] === void 0 && this.#e(t, s, "refers to an unsupported event name"), t.setAttribute(c, this[i])) : a = "change"), e && !l && t.#b.set(
532
541
  p.getPropName(c),
533
542
  i
534
543
  );
535
544
  }
536
- this.#c(o, t, s);
545
+ this.#f(o, t, s);
537
546
  }
538
547
  }
539
- #y(t) {
548
+ #E(t) {
540
549
  for (const e of t) {
541
- const s = this.#s(e), o = this.#o.get(e) ?? [];
542
- for (const i of o)
543
- if (i instanceof HTMLElement)
544
- this.#v(i, s);
545
- else if (!(i instanceof CSSStyleRule)) {
546
- const { element: n, attrName: c } = i;
547
- n instanceof CSSStyleRule ? n.style.setProperty(c, s) : k(n, c, s);
550
+ const s = this.#o(e), o = this.#s.get(e) ?? [], i = /* @__PURE__ */ new Set();
551
+ for (const n of o) {
552
+ const c = n instanceof HTMLElement || n instanceof CSSStyleRule ? n : n.element;
553
+ if (c instanceof HTMLElement && !c.isConnected) {
554
+ i.add(n);
555
+ continue;
556
+ }
557
+ if (n instanceof HTMLElement)
558
+ this.#P(n, s);
559
+ else if (!(n instanceof CSSStyleRule)) {
560
+ const { element: a, attrName: f } = n;
561
+ a instanceof CSSStyleRule ? a.style.setProperty(f, s) : k(a, f, s);
548
562
  }
563
+ }
564
+ if (i.size > 0) {
565
+ const n = o.filter((c) => !i.has(c));
566
+ n.length === 0 ? this.#s.delete(e) : this.#s.set(e, n);
567
+ }
549
568
  }
550
569
  }
551
- #s(t) {
570
+ #o(t) {
552
571
  const { context: e } = this.#t;
553
572
  return new Function(
554
573
  "context",
555
574
  `const {${Object.keys(e).join(",")}} = context; return ${t};`
556
575
  ).call(this, e);
557
576
  }
558
- #N(t) {
577
+ #j(t) {
559
578
  const { localName: e } = t;
560
579
  if (e === "style") {
561
580
  const { sheet: s } = t, o = s?.cssRules ?? [], i = Array.from(o);
@@ -564,15 +583,15 @@ class p extends ct {
564
583
  const c = Array.from(n.style);
565
584
  for (const a of c)
566
585
  if (a.startsWith("--")) {
567
- const h = n.style.getPropertyValue(a);
568
- this.#c(h, n, a);
586
+ const f = n.style.getPropertyValue(a);
587
+ this.#f(f, n, a);
569
588
  }
570
589
  }
571
590
  } else {
572
591
  let s = "";
573
- if (A(t)) {
574
- this.#c(t.textContent, t);
575
- const o = t.textContent?.match(ht);
592
+ if (S(t)) {
593
+ this.#f(t.textContent, t);
594
+ const o = t.textContent?.match(lt);
576
595
  o && (s = o[1]);
577
596
  } else {
578
597
  const o = Array.from(t.childNodes).find(
@@ -581,8 +600,8 @@ class p extends ct {
581
600
  o && (s = o.textContent?.trim() ?? "");
582
601
  }
583
602
  if (s) {
584
- const o = this.#T(t, s);
585
- o && A(t) ? t.textContent = this[o] : this.#c(s, t);
603
+ const o = this.#A(t, s);
604
+ o && S(t) ? t.textContent = this[o] : this.#f(s, t);
586
605
  }
587
606
  }
588
607
  }
@@ -595,7 +614,7 @@ class p extends ct {
595
614
  if (!t) {
596
615
  const n = this.getAttribute("name");
597
616
  if (n)
598
- if (this.#r("value"))
617
+ if (this.#c("value"))
599
618
  t = `value:${n}`;
600
619
  else
601
620
  return;
@@ -607,16 +626,16 @@ class p extends ct {
607
626
  const [c, a] = n.split(":");
608
627
  e[c.trim()] = a.trim();
609
628
  }
610
- this.#h = e, this.#i = new FormData(), this.#u = this.attachInternals(), this.#u.setFormValue(this.#i);
611
- const o = Object.keys(this.#t.properties), i = this.#l;
629
+ this.#p = e, this.#i = new FormData(), this.#m = this.attachInternals(), this.#m.setFormValue(this.#i);
630
+ const o = Object.keys(this.#t.properties), i = this.#d;
612
631
  for (const n of o)
613
632
  i[n] = this[n];
614
633
  }
615
634
  formResetCallback() {
616
- const t = this.#l;
635
+ const t = this.#d;
617
636
  for (const e of Object.keys(t)) {
618
637
  let s = t[e];
619
- j.test(s) && (s = this.#s(s)), this[e] = s;
638
+ L.test(s) && (s = this.#o(s)), this[e] = s;
620
639
  }
621
640
  }
622
641
  static getAttrName(t) {
@@ -627,35 +646,38 @@ class p extends ct {
627
646
  let e = this.attrToPropMap.get(t);
628
647
  return e || (e = t.replace(/-([a-z])/g, (s, o) => o.toUpperCase()), this.attrToPropMap.set(t, e)), e;
629
648
  }
630
- #O(t, e, s) {
649
+ #H(t, e, s) {
631
650
  if (s.length !== 1) return;
632
651
  const [o] = s;
633
- if (!j.test(o)) return;
634
- const i = D(t) || A(t);
652
+ if (!L.test(o)) return;
653
+ const i = D(t) || S(t);
635
654
  let [n, c] = (e ?? "").split(":");
636
- if (!(i && n === "value" || A(t))) return;
655
+ if (!(i && n === "value" || S(t))) return;
637
656
  c ? t["on" + c] === void 0 && this.#e(t, e, "refers to an unsupported event name") : c = "change";
638
- const h = M(o);
639
- t.addEventListener(c, (f) => {
640
- const { target: l } = f;
641
- if (!l) return;
642
- const m = l.value, { type: x } = this.#t.properties[h];
643
- this[h] = x === Number ? H(m) : m, this.#M(h);
657
+ const f = M(o);
658
+ t.addEventListener(c, (l) => {
659
+ const { target: h } = l;
660
+ if (!h) return;
661
+ const m = h.value, { type: x } = this.#t.properties[f];
662
+ this[f] = x === Number ? H(m) : m, this.#v(f);
644
663
  });
645
664
  }
646
665
  #n(t) {
647
666
  return Object.hasOwn(this.#t, t);
648
667
  }
649
- #r(t) {
668
+ #c(t) {
650
669
  return !!this.#t.properties[t];
651
670
  }
652
- #w(t) {
671
+ #T(t) {
672
+ return !!this.#t.properties[t]?.computed;
673
+ }
674
+ #M(t) {
653
675
  const e = Array.from(t.querySelectorAll("*"));
654
676
  for (const s of e)
655
- this.#R(s), s.firstElementChild || this.#N(s);
677
+ this.#L(s), s.firstElementChild || this.#j(s);
656
678
  }
657
679
  // formAssociated is only needed when the component is inside a form.
658
- #E() {
680
+ #S() {
659
681
  if (this.#t.formAssociated || this.closest("form") === null) return;
660
682
  const t = this.#t.name;
661
683
  this.#e(
@@ -673,35 +695,43 @@ class p extends ct {
673
695
  // Subclasses can override this to add functionality.
674
696
  propertyChangedCallback(t, e, s) {
675
697
  }
676
- #T(t, e) {
677
- if (!e || !j.test(e)) return;
698
+ #A(t, e) {
699
+ if (!e || !L.test(e)) return;
678
700
  const s = M(e);
679
- return this[s] === void 0 && this.#a(t, "", s), s;
701
+ return this[s] === void 0 && this.#l(t, "", s), s;
680
702
  }
681
- #M(t) {
703
+ #v(t) {
682
704
  const e = this.#t.propToExprsMap.get(t) || [];
683
- this.#y(e);
705
+ this.#E(e);
684
706
  }
685
- #j(t, e) {
707
+ #k(t, e) {
686
708
  const { computed: s, uses: o } = e, i = this.#t.propToComputedMap;
687
- function n(a, h) {
688
- let f = i.get(a);
689
- f || (f = [], i.set(a, f)), f.push([t, h]);
709
+ function n(a, f) {
710
+ let l = i.get(a);
711
+ l || (l = [], i.set(a, l)), l.push([t, f]);
690
712
  }
691
- const c = s.match(L) || [];
713
+ const c = s.match(j) || [];
692
714
  for (const a of c) {
693
- const h = M(a);
694
- this[h] === void 0 && this.#a(null, t, h), typeof this[h] != "function" && n(h, s);
715
+ const f = M(a);
716
+ this[f] === void 0 && this.#l(null, t, f), typeof this[f] != "function" && n(f, s);
695
717
  }
696
718
  if (o)
697
719
  for (const a of o.split(","))
698
720
  n(a.trim(), s);
699
721
  }
722
+ #a(t, e) {
723
+ this.#u.add(t);
724
+ try {
725
+ this[t] = e;
726
+ } finally {
727
+ this.#u.delete(t);
728
+ }
729
+ }
700
730
  // WARNING: Do not place untrusted JavaScript expressions
701
731
  // in attribute values or the text content of elements!
702
- #c(t, e, s = void 0) {
732
+ #f(t, e, s = void 0) {
703
733
  if (!t) return;
704
- const o = this.#d(e, s, t);
734
+ const o = this.#g(e, s, t);
705
735
  if (!o) {
706
736
  const a = t.replaceAll("this..", "this.");
707
737
  s ? k(e, s, a) : "textContent" in e && (e.textContent = a);
@@ -709,24 +739,24 @@ class p extends ct {
709
739
  }
710
740
  const i = this.#t;
711
741
  o.forEach((a) => {
712
- const h = M(a);
713
- if (typeof this[h] == "function") return;
714
- const f = i.propToExprsMap;
715
- let l = f.get(h);
716
- l || (l = [], f.set(h, l)), l.includes(t) || l.push(t);
742
+ const f = M(a);
743
+ if (typeof this[f] == "function") return;
744
+ const l = i.propToExprsMap;
745
+ let h = l.get(f);
746
+ h || (h = [], l.set(f, h)), h.includes(t) || h.push(t);
717
747
  });
718
- for (const [a, h] of this.#o.entries())
719
- for (const f of h) {
720
- const l = f instanceof HTMLElement || f instanceof CSSStyleRule ? f : f.element;
721
- l instanceof CSSStyleRule || l.isConnected || this.#o.set(
748
+ for (const [a, f] of this.#s.entries())
749
+ for (const l of f) {
750
+ const h = l instanceof HTMLElement || l instanceof CSSStyleRule ? l : l.element;
751
+ h instanceof CSSStyleRule || h.isConnected || this.#s.set(
722
752
  a,
723
- h.filter((m) => m !== f)
753
+ f.filter((m) => m !== l)
724
754
  );
725
755
  }
726
- let n = this.#o.get(t);
727
- n || (n = [], this.#o.set(t, n)), n.push(s ? { element: e, attrName: s } : e), e instanceof HTMLElement && this.#O(e, s, o);
728
- const c = this.#s(t);
729
- s ? k(e, s, c) : this.#v(e, c);
756
+ let n = this.#s.get(t);
757
+ n || (n = [], this.#s.set(t, n)), n.push(s ? { element: e, attrName: s } : e), e instanceof HTMLElement && this.#H(e, s, o);
758
+ const c = this.#o(t);
759
+ s ? k(e, s, c) : this.#P(e, c);
730
760
  }
731
761
  // This follows the best practice
732
762
  // "Do not override author-set, global attributes."
@@ -734,7 +764,7 @@ class p extends ct {
734
764
  this.hasAttribute(t) || this.setAttribute(t, e);
735
765
  }
736
766
  setFormValue(t, e) {
737
- !this.#i || !I(e) || (this.#i.set(t, e), this.#u?.setFormValue(this.#i));
767
+ !this.#i || !I(e) || (this.#i.set(t, e), this.#m?.setFormValue(this.#i));
738
768
  }
739
769
  static ssr(t = {}) {
740
770
  throw new E('Import Wrec from "wrec/ssr" to use the ssr method.');
@@ -745,14 +775,14 @@ class p extends ct {
745
775
  `component ${this.#t.elementName}` + (t ? `, element "${o}"` : "") + (e ? `, attribute "${e}"` : "") + ` ${s}`
746
776
  );
747
777
  }
748
- #a(t, e, s) {
778
+ #l(t, e, s) {
749
779
  this.#e(t, e, `refers to missing property "${s}"`);
750
780
  }
751
- #A(t, e) {
752
- return this.#S(t, this.getAttribute(e));
781
+ #C(t, e) {
782
+ return this.#x(t, this.getAttribute(e));
753
783
  }
754
- #S(t, e) {
755
- if (e?.match(L)) return e;
784
+ #x(t, e) {
785
+ if (e?.match(j)) return e;
756
786
  const o = this.#t.properties[t], { type: i, values: n } = o;
757
787
  if (i || this.#e(null, t, "does not specify its type"), e === null)
758
788
  return i === Boolean ? !1 : K(o);
@@ -777,20 +807,20 @@ class p extends ct {
777
807
  }
778
808
  // Updates the matching attribute for a property.
779
809
  // VS Code thinks this is never called, but it is called by #defineProp.
780
- #L(t, e, s, o) {
810
+ #F(t, e, s, o) {
781
811
  if (I(s)) {
782
- const i = e === Boolean ? this.hasAttribute(o) : this.#A(t, o);
812
+ const i = e === Boolean ? this.hasAttribute(o) : this.#C(t, o);
783
813
  s !== i && st(this, o || t, s);
784
814
  }
785
815
  }
786
816
  // Updates all computed properties that reference this property.
787
817
  // VS Code thinks this is never called, but it is called by #defineProp.
788
- #H(t) {
818
+ #_(t) {
789
819
  const s = this.#t.propToComputedMap.get(t) || [];
790
820
  for (const [o, i] of s)
791
- this[o] = this.#s(i);
821
+ this.#a(o, this.#o(i));
792
822
  }
793
- #v(t, e) {
823
+ #P(t, e) {
794
824
  if (e === void 0) return;
795
825
  const s = t instanceof HTMLElement;
796
826
  Array.isArray(e) && (e = e.join(""));
@@ -801,17 +831,17 @@ class p extends ct {
801
831
  " computed content is not a string or number"
802
832
  );
803
833
  const i = String(e);
804
- if (t instanceof HTMLElement && A(t))
834
+ if (t instanceof HTMLElement && S(t))
805
835
  t.value = i;
806
836
  else if (s && o === "string" && i.trim().startsWith("<")) {
807
837
  const n = nt(i);
808
- t.innerHTML = n, this.#C(t), this.#w(t);
838
+ t.innerHTML = n, this.#R(t), this.#M(t);
809
839
  } else s && (t.textContent = i);
810
840
  }
811
841
  // Update corresponding parent web component property if bound to one.
812
842
  // VS Code thinks this is never called, but it is called by #defineProp.
813
- #k(t, e) {
814
- const s = this.#p.get(t);
843
+ #I(t, e) {
844
+ const s = this.#b.get(t);
815
845
  if (!s) return;
816
846
  const o = this.getRootNode();
817
847
  if (!(o instanceof ShadowRoot)) return;
@@ -831,43 +861,43 @@ class p extends ct {
831
861
  for (const s of Object.keys(t))
832
862
  e[s] = s;
833
863
  }
834
- this.#_(t, e);
864
+ this.#B(t, e);
835
865
  for (const [s, o] of Object.entries(e))
836
- if (this.#r(o)) {
866
+ if (this.#c(o)) {
837
867
  const i = q(t, s);
838
- i !== void 0 && (this[o] = i), this.#m.set(o, { state: t, stateProp: s });
868
+ i !== void 0 && (this[o] = i), this.#r.set(o, { state: t, stateProp: s });
839
869
  }
840
870
  t.addListener(this, e);
841
871
  }
842
- #F() {
872
+ #D() {
843
873
  const t = new Set(Object.keys(this.#t.properties));
844
874
  for (const e of this.getAttributeNames())
845
875
  if (!rt.has(e) && !e.startsWith("on")) {
846
876
  if (e === "form-assoc") {
847
- this.#E();
877
+ this.#S();
848
878
  continue;
849
879
  }
850
880
  if (!t.has(p.getPropName(e))) {
851
881
  if (e === "name") {
852
- this.#E();
882
+ this.#S();
853
883
  continue;
854
884
  }
855
885
  this.#e(null, e, "is not a supported attribute");
856
886
  }
857
887
  }
858
888
  }
859
- #d(t, e, s) {
860
- const o = s.match(L);
889
+ #g(t, e, s) {
890
+ const o = s.match(j);
861
891
  if (o)
862
892
  return o.forEach((i) => {
863
893
  const n = M(i);
864
- this[n] === void 0 && this.#a(t, e, n);
894
+ this[n] === void 0 && this.#l(t, e, n);
865
895
  }), o;
866
896
  }
867
- #_(t, e) {
897
+ #B(t, e) {
868
898
  for (const [s, o] of Object.entries(e)) {
869
899
  let i = q(t, s);
870
- i === void 0 && this.#e(this, void 0, `invalid state path "${s}"`), i = this[o], this.#r(o) || this.#e(
900
+ i === void 0 && this.#e(this, void 0, `invalid state path "${s}"`), i = this[o], this.#c(o) || this.#e(
871
901
  null,
872
902
  o,
873
903
  "refers to missing property in useState map"
@@ -876,7 +906,7 @@ class p extends ct {
876
906
  }
877
907
  // When type is an array, this can't validate the type of the array elements.
878
908
  // This is called by #defineProp.
879
- #I(t, e, s) {
909
+ #V(t, e, s) {
880
910
  const { values: o } = this.#t.properties[t];
881
911
  if (o) {
882
912
  let n;
@@ -898,7 +928,7 @@ class p extends ct {
898
928
  `was set to a ${i}, but must be a ${e.name}`
899
929
  );
900
930
  }
901
- #C(t) {
931
+ #R(t) {
902
932
  const e = Array.from(t.querySelectorAll("*"));
903
933
  for (const s of e) {
904
934
  const o = [];
@@ -908,9 +938,9 @@ class p extends ct {
908
938
  let c = n.slice(2);
909
939
  c = c[0].toLowerCase() + c.slice(1).toLowerCase();
910
940
  const a = i.value;
911
- this.#d(s, n, a);
912
- let h;
913
- typeof this[a] == "function" ? h = (f) => this[a](f) : (this.#d(s, n, a), h = () => this.#s(a)), s.addEventListener(c, h), o.push(n);
941
+ this.#g(s, n, a);
942
+ let f;
943
+ typeof this[a] == "function" ? f = (l) => this[a](l) : (this.#g(s, n, a), f = () => this.#o(a)), s.addEventListener(c, f), o.push(n);
914
944
  }
915
945
  }
916
946
  for (const i of o)
@@ -938,7 +968,7 @@ function Tt(r, ...t) {
938
968
  function Mt(r, ...t) {
939
969
  let e = tt(r, t);
940
970
  for (; ; ) {
941
- const s = lt.exec(e);
971
+ const s = ht.exec(e);
942
972
  if (!s || s[1] === "style") break;
943
973
  const o = mt(s[2]);
944
974
  if (Q.test(o)) {
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.22.6",
5
+ "version": "0.22.8",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",