wrec 0.42.2 → 0.43.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 CHANGED
@@ -123,6 +123,21 @@ class TrafficLight extends Wrec {
123
123
  With that configuration, the `color` attribute and property can only be set
124
124
  to one of those strings.
125
125
 
126
+ Property definitions can set `reflect` to `false` to prevent property changes
127
+ from being copied to matching attributes:
128
+
129
+ ```js
130
+ class MessageDisplay extends Wrec {
131
+ static properties = {
132
+ message: {
133
+ type: String,
134
+ value: "",
135
+ reflect: false,
136
+ },
137
+ };
138
+ }
139
+ ```
140
+
126
141
  1. Create the file `index.html` containing the following.
127
142
 
128
143
  ```html
@@ -455,16 +455,19 @@ var $ = class e extends O {
455
455
  #t = /* @__PURE__ */ new Set();
456
456
  #n = this.constructor;
457
457
  #r = !1;
458
- #i = /* @__PURE__ */ new Map();
459
- #a = {};
460
- #o;
461
- #s = {};
462
- #c = null;
463
- #l = /* @__PURE__ */ new Map();
464
- #u = /* @__PURE__ */ new Map();
465
- #d = /* @__PURE__ */ new WeakMap();
466
- #f = /* @__PURE__ */ new WeakSet();
467
- #p = /* @__PURE__ */ new Map();
458
+ #i = /* @__PURE__ */ new Set();
459
+ #a = /* @__PURE__ */ new Map();
460
+ #o = {};
461
+ #s = !1;
462
+ #c;
463
+ #l = {};
464
+ #u = null;
465
+ #d = /* @__PURE__ */ new Map();
466
+ #f = /* @__PURE__ */ new Map();
467
+ #p = !1;
468
+ #m = /* @__PURE__ */ new WeakMap();
469
+ #h = /* @__PURE__ */ new WeakSet();
470
+ #g = /* @__PURE__ */ new Map();
468
471
  static define(e) {
469
472
  if (this.elementName = e, k.get(e)) throw new A(`custom element ${e} is already defined`);
470
473
  k.define(e, this);
@@ -472,47 +475,51 @@ var $ = class e extends O {
472
475
  constructor() {
473
476
  super(), this.attachShadow({ mode: "open" });
474
477
  let e = this.#n;
475
- this.#A("attrToPropMap") || (e.attrToPropMap = /* @__PURE__ */ new Map()), this.#A("computedGraph") || (e.computedGraph = null), this.#A("computedPropsRegistered") || (e.computedPropsRegistered = !1), this.#A("properties") || (e.properties = {}), this.#A("propToAttrMap") || (e.propToAttrMap = /* @__PURE__ */ new Map()), this.#A("propToComputedMap") || (e.propToComputedMap = /* @__PURE__ */ new Map()), this.#A("propToExprsMap") || (e.propToExprsMap = /* @__PURE__ */ new Map()), this.#A("registeredComputedProps") || (e.registeredComputedProps = /* @__PURE__ */ new Set());
478
+ this.#P("attrToPropMap") || (e.attrToPropMap = /* @__PURE__ */ new Map()), this.#P("computedGraph") || (e.computedGraph = null), this.#P("computedPropsRegistered") || (e.computedPropsRegistered = !1), this.#P("properties") || (e.properties = {}), this.#P("propToAttrMap") || (e.propToAttrMap = /* @__PURE__ */ new Map()), this.#P("propToComputedMap") || (e.propToComputedMap = /* @__PURE__ */ new Map()), this.#P("propToExprsMap") || (e.propToExprsMap = /* @__PURE__ */ new Map()), this.#P("registeredComputedProps") || (e.registeredComputedProps = /* @__PURE__ */ new Set());
476
479
  }
477
480
  attributeChangedCallback(t, n, r) {
478
- t === "disabled" && this.#y();
481
+ if (this.#i.has(t)) return;
482
+ t === "disabled" && this.#S();
479
483
  let i = e.getPropName(t);
480
- if (!this.#M(i) && this.#j(i)) {
481
- let e = this.#K(i, r);
482
- this.#B(i, e);
483
- let t = this.#a[i];
484
- t && this.setFormValue(t, String(e));
484
+ if (!this.#I(i) && this.#F(i)) {
485
+ let e = this.#Z(i, r), a = this.#j(i);
486
+ if (this.#W(i, e), e !== a && this.#j(i) === a) {
487
+ this.#K(t, n);
488
+ return;
489
+ }
490
+ let o = this.#o[i];
491
+ o && this.setFormValue(o, String(e));
485
492
  }
486
493
  }
487
494
  batchSet(e) {
488
- let t = this.#$(e);
495
+ let t = this.#ie(e);
489
496
  if (t.entries.length === 0) return;
490
497
  let [n, r] = t.entries[0];
491
498
  if (t.errors.length) {
492
- this.#b(n, r, t.errors);
499
+ this.#C(n, r, t.errors);
493
500
  return;
494
501
  }
495
502
  this.#e = !0;
496
503
  let i = this.#n.propToExprsMap, a = /* @__PURE__ */ new Set();
497
504
  try {
498
505
  for (let [e, n] of t.entries) {
499
- this.#B(e, n);
506
+ this.#W(e, n);
500
507
  let t = i.get(e) ?? [];
501
508
  for (let e of t) a.add(e);
502
509
  }
503
- let e = this.#E(t.entries.map(([e]) => e));
510
+ let e = this.#A(t.entries.map(([e]) => e));
504
511
  for (let [t, n] of e) {
505
- this.#z(t, this.#C(n));
512
+ this.#U(t, this.#E(n));
506
513
  let e = i.get(t) ?? [];
507
514
  for (let t of e) a.add(t);
508
515
  }
509
- this.#S([...a]);
516
+ this.#T([...a]);
510
517
  } finally {
511
518
  this.#e = !1;
512
519
  }
513
- for (let [e, n] of t.entries) this.#n.properties[e] && this.#b(e, n, []);
520
+ for (let [e, n] of t.entries) this.#n.properties[e] && this.#C(e, n, []);
514
521
  }
515
- async #m() {
522
+ async #_() {
516
523
  let e = this.#n, { template: t } = e;
517
524
  t || (t = e.template = document.createElement("template"), t.innerHTML = e.buildHTML()), await le(t), this.shadowRoot.replaceChildren(t.content.cloneNode(!0));
518
525
  }
@@ -524,48 +531,48 @@ var $ = class e extends O {
524
531
  return t.startsWith("<") || (t = `<span><!--${t}--></span>`), e + t;
525
532
  }
526
533
  changed(e, t, n) {
527
- this.#B(t, n);
534
+ this.#W(t, n);
528
535
  }
529
- #h() {
536
+ #v() {
530
537
  let { properties: e } = this.#n;
531
- for (let [t, { computed: n }] of Object.entries(e)) n && this.#z(t, this.#C(n));
538
+ for (let [t, { computed: n }] of Object.entries(e)) n && this.#U(t, this.#E(n));
532
539
  }
533
540
  async connectedCallback() {
534
- this.#Q(), this.#g(), await this.#m(), this.hasAttribute("disabled") && this.#y(), this.#ae(this.shadowRoot), this.#P(this.shadowRoot), this.#Z(), this.#h(), this.ready();
541
+ this.#re(), this.#y(), this.#p = !0, this.#s && this.#O(), await this.#_(), this.hasAttribute("disabled") && this.#S(), this.#ue(this.shadowRoot), this.#R(this.shadowRoot), this.#ne(), this.#v(), this.ready();
535
542
  }
536
- #g() {
543
+ #y() {
537
544
  let { observedAttributes: e, properties: t } = this.#n;
538
- for (let [n, r] of Object.entries(t)) r.computed || this.#_(n, r, e);
539
- for (let [n, r] of Object.entries(t)) r.computed && this.#_(n, r, e);
540
- this.#L();
545
+ for (let [n, r] of Object.entries(t)) r.computed || this.#b(n, r, e);
546
+ for (let [n, r] of Object.entries(t)) r.computed && this.#b(n, r, e);
547
+ this.#V();
541
548
  }
542
- #_(t, n, r) {
549
+ #b(t, n, r) {
543
550
  if (t === "class" || t === "style") throw new A(`"${t}" is a reserved property`);
544
551
  let i = e.getAttrName(t), a = this.hasAttribute(i);
545
- n.required && !a && this.#U(this, i, "is a required attribute");
552
+ n.required && !a && this.#J(this, i, "is a required attribute");
546
553
  let o = n.value;
547
- this.hasOwnProperty(t) && (o = this.#D(t), this.#v(t));
548
- let { type: s } = n, c = s === Boolean ? o || a : r.includes(i) && a ? this.#G(t, i) : o ?? F(n), u = "#" + t;
549
- this.#B(u, this.#N(t, s, c)), Object.defineProperty(this, t, {
554
+ this.hasOwnProperty(t) && (o = this.#j(t), this.#x(t));
555
+ let { type: s } = n, c = s === Boolean ? o || a : r.includes(i) && a ? this.#X(t, i) : o ?? F(n), u = "#" + t;
556
+ this.#W(u, this.#L(t, s, c)), Object.defineProperty(this, t, {
550
557
  enumerable: !0,
551
558
  get() {
552
- return this.#D(u);
559
+ return this.#j(u);
553
560
  },
554
561
  set(e) {
555
- n.computed && !this.#t.has(t) && this.#U(null, t, "is a computed property and cannot be set directly"), s === Number && typeof e == "string" && (e = Y(e));
556
- let r = this.#D(u);
562
+ n.computed && !this.#t.has(t) && this.#J(null, t, "is a computed property and cannot be set directly"), s === Number && typeof e == "string" && (e = Y(e));
563
+ let r = this.#j(u);
557
564
  if (e === r) return;
558
- this.#re(t, s, e);
559
- let a = this.#ee(n, t, e);
565
+ this.#ce(t, s, e);
566
+ let a = this.#ae(n, t, e);
560
567
  if (!a.skipped && a.errors.length) {
561
- this.#b(t, e, a.errors);
568
+ this.#C(t, e, a.errors);
562
569
  return;
563
570
  }
564
- e = this.#N(t, s, e), this.#B(u, e);
565
- let o = this.#u.get(t);
566
- o && l(o.state, o.stateProp, e), this.#q(t, s, e, i), this.#e || (this.#J(t), this.#I(t)), this.#X(t, e);
567
- let c = this.#a[t];
568
- c && this.setFormValue(c, String(e)), this.propertyChangedCallback(t, r, e), a.skipped || this.#b(t, e, a.errors), n.dispatch && this.dispatch("change", {
571
+ e = this.#L(t, s, e), this.#W(u, e);
572
+ let o = this.#f.get(t);
573
+ o && l(o.state, o.stateProp, e), this.#Q(t, s, e, i, n.reflect), this.#e || (this.#$(t), this.#B(t)), this.#te(t, e);
574
+ let c = this.#o[t];
575
+ c && this.setFormValue(c, String(e)), this.propertyChangedCallback(t, r, e), a.skipped || this.#C(t, e, a.errors), n.dispatch && this.dispatch("change", {
569
576
  tagName: this.localName,
570
577
  property: t,
571
578
  oldValue: r,
@@ -574,16 +581,16 @@ var $ = class e extends O {
574
581
  }
575
582
  });
576
583
  }
577
- #v(e) {
584
+ #x(e) {
578
585
  delete this[e];
579
586
  }
580
- #y() {
587
+ #S() {
581
588
  let t = this.hasAttribute("disabled"), n = L(this.shadowRoot);
582
589
  for (let r of n) N(r) && (r instanceof e ? t ? r.setAttribute("disabled", "") : r.removeAttribute("disabled") : r.disabled = t);
583
590
  }
584
591
  disconnectedCallback() {
585
- for (let { unsubscribe: e } of this.#p.values()) e();
586
- this.#i.clear(), this.#s = {}, this.#l.clear(), this.#u.clear(), this.#p.clear();
592
+ for (let { unsubscribe: e } of this.#g.values()) e();
593
+ this.#a.clear(), this.#l = {}, this.#d.clear(), this.#f.clear(), this.#g.clear();
587
594
  }
588
595
  dispatch(e, t) {
589
596
  this.dispatchEvent(new CustomEvent(e, {
@@ -592,7 +599,7 @@ var $ = class e extends O {
592
599
  detail: t
593
600
  }));
594
601
  }
595
- #b(e, t, n) {
602
+ #C(e, t, n) {
596
603
  this.#r = !0;
597
604
  try {
598
605
  this.dispatch("validation", {
@@ -608,39 +615,39 @@ var $ = class e extends O {
608
615
  displayIfSet(e, t = "block") {
609
616
  return `display: ${e == null ? "none" : t}`;
610
617
  }
611
- #x(t) {
618
+ #w(t) {
612
619
  let n = t instanceof e;
613
620
  for (let r of t.getAttributeNames()) {
614
621
  let i = t.getAttribute(r);
615
622
  if (r === "ref") {
616
- this.#H(t, i);
623
+ this.#q(t, i);
617
624
  continue;
618
625
  }
619
- let a = this.#F(t, i);
626
+ let a = this.#z(t, i);
620
627
  if (a) {
621
- let i = this.#D(a);
622
- i === void 0 && this.#W(t, r, a);
628
+ let i = this.#j(a);
629
+ i === void 0 && this.#Y(t, r, a);
623
630
  let [o, s] = r.split(":"), c = e.getPropName(o);
624
631
  if (o === "checked") {
625
632
  let { type: e } = this.#n.properties[a];
626
- V(t) && e !== Boolean && this.#U(t, r, `refers to property "${a}" whose type is not Boolean`), W(t) && e !== String && this.#U(t, r, `refers to property "${a}" whose type is not String`);
633
+ V(t) && e !== Boolean && this.#J(t, r, `refers to property "${a}" whose type is not Boolean`), W(t) && e !== String && this.#J(t, r, `refers to property "${a}" whose type is not String`);
627
634
  }
628
- let l = this.#M(a);
629
- n && t.#M(c) || (o === "checked" && W(t) ? t.checked = t.value === i : t[c] = i), o === "value" && (s ? (t["on" + s] === void 0 && this.#U(t, r, "refers to an unsupported event name"), t.setAttribute(o, this.#D(a))) : s = "change"), n && !l && t.#l.set(e.getPropName(o), a);
635
+ let l = this.#I(a);
636
+ n && t.#I(c) || (o === "checked" && W(t) ? t.checked = t.value === i : t[c] = i), o === "value" && (s ? (t["on" + s] === void 0 && this.#J(t, r, "refers to an unsupported event name"), t.setAttribute(o, this.#j(a))) : s = "change"), n && !l && t.#d.set(e.getPropName(o), a);
630
637
  }
631
- this.#V(i, t, r);
638
+ this.#G(i, t, r);
632
639
  }
633
640
  }
634
- #S(e) {
641
+ #T(e) {
635
642
  for (let t of e) {
636
- let e = this.#C(t), n = this.#i.get(t) ?? [], r = /* @__PURE__ */ new Set();
643
+ let e = this.#E(t), n = this.#a.get(t) ?? [], r = /* @__PURE__ */ new Set();
637
644
  for (let t of n) {
638
645
  let n = t instanceof HTMLElement || t instanceof CSSStyleRule ? t : t.element;
639
646
  if (n instanceof HTMLElement && !n.isConnected) {
640
647
  r.add(t);
641
648
  continue;
642
649
  }
643
- if (t instanceof HTMLElement) this.#Y(t, e);
650
+ if (t instanceof HTMLElement) this.#ee(t, e);
644
651
  else if (!(t instanceof CSSStyleRule)) {
645
652
  let { element: n, attrName: r } = t;
646
653
  n instanceof CSSStyleRule ? n.style.setProperty(r, e) : Z(n, r, e);
@@ -648,14 +655,14 @@ var $ = class e extends O {
648
655
  }
649
656
  if (r.size > 0) {
650
657
  let e = n.filter((e) => !r.has(e));
651
- e.length === 0 ? this.#i.delete(t) : this.#i.set(t, e);
658
+ e.length === 0 ? this.#a.delete(t) : this.#a.set(t, e);
652
659
  }
653
660
  }
654
661
  }
655
- #C(e) {
662
+ #E(e) {
656
663
  return v(e, this, this.#n.context);
657
664
  }
658
- #w(e) {
665
+ #D(e) {
659
666
  let { localName: t } = e;
660
667
  if (t === "style") {
661
668
  let { sheet: t } = e, n = t?.cssRules ?? [], r = Array.from(n);
@@ -663,13 +670,13 @@ var $ = class e extends O {
663
670
  let t = Array.from(e.style);
664
671
  for (let n of t) if (n.startsWith("--")) {
665
672
  let t = e.style.getPropertyValue(n);
666
- this.#V(t, e, n);
673
+ this.#G(t, e, n);
667
674
  }
668
675
  }
669
676
  } else {
670
677
  let t = "";
671
678
  if (G(e)) {
672
- this.#V(e.textContent, e);
679
+ this.#G(e.textContent, e);
673
680
  let n = e.textContent?.match(ee);
674
681
  n && (t = n[1]);
675
682
  } else {
@@ -677,16 +684,19 @@ var $ = class e extends O {
677
684
  n && (t = n.textContent?.trim() ?? "");
678
685
  }
679
686
  if (t) {
680
- let n = this.#F(e, t);
681
- n && G(e) ? e.textContent = this.#D(n) : this.#V(t, e);
687
+ let n = this.#z(e, t);
688
+ n && G(e) ? e.textContent = this.#j(n) : this.#G(t, e);
682
689
  }
683
690
  }
684
691
  }
685
692
  formAssociatedCallback() {
693
+ this.#s = !0, this.#p && this.#O();
694
+ }
695
+ #O() {
686
696
  let e = this.getAttribute("form-assoc");
687
697
  if (!e) {
688
698
  let t = this.getAttribute("name");
689
- if (t) if (this.#j("value")) e = `value:${t}`;
699
+ if (t) if (this.#F("value")) e = `value:${t}`;
690
700
  else return;
691
701
  else return;
692
702
  }
@@ -695,26 +705,26 @@ var $ = class e extends O {
695
705
  let [n, r] = e.split(":");
696
706
  t[n.trim()] = r.trim();
697
707
  }
698
- this.#a = t, this.#o = new FormData(), this.#c = this.attachInternals(), this.#c.setFormValue(this.#o);
708
+ this.#o = t, this.#c = new FormData(), this.#u ??= this.attachInternals(), this.#u.setFormValue(this.#c);
699
709
  for (let [e, n] of Object.entries(t)) {
700
- let t = this.#D(e);
710
+ let t = this.#j(e);
701
711
  U(t) && this.setFormValue(n, String(t));
702
712
  }
703
- let r = Object.keys(this.#n.properties), i = this.#s;
704
- for (let e of r) i[e] = this.#D(e);
713
+ let r = Object.keys(this.#n.properties), i = this.#l;
714
+ for (let e of r) i[e] = this.#j(e);
705
715
  }
706
716
  formResetCallback() {
707
- let e = this.#s;
717
+ let e = this.#l;
708
718
  for (let t of Object.keys(e)) {
709
719
  let n = e[t];
710
- f.test(n) && (n = this.#C(n)), this.#B(t, n);
720
+ f.test(n) && (n = this.#E(n)), this.#W(t, n);
711
721
  }
712
722
  }
713
723
  static getAttrName(e) {
714
724
  let t = this.propToAttrMap.get(e);
715
725
  return t || (t = e.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), this.propToAttrMap.set(e, t)), t;
716
726
  }
717
- #T() {
727
+ #k() {
718
728
  let e = this.#n, t = e.computedGraph;
719
729
  if (t) return t;
720
730
  let n = E(), r = E(), i = {};
@@ -731,8 +741,8 @@ var $ = class e extends O {
731
741
  computedToExprMap: i
732
742
  }, e.computedGraph = t, t;
733
743
  }
734
- #E(e) {
735
- let { computedToDependenciesMap: t, computedToDependentsMap: n, computedToExprMap: r } = this.#T(), i = this.#n.propToComputedMap, a = /* @__PURE__ */ new Set(), o = [...new Set(e)];
744
+ #A(e) {
745
+ let { computedToDependenciesMap: t, computedToDependentsMap: n, computedToExprMap: r } = this.#k(), i = this.#n.propToComputedMap, a = /* @__PURE__ */ new Set(), o = [...new Set(e)];
736
746
  for (let e = 0; e < o.length; e++) {
737
747
  let t = o[e], n = i.get(t) || [];
738
748
  for (let [e, t] of n) r[e] = t, a.has(e) || (a.add(e), o.push(e));
@@ -756,77 +766,77 @@ var $ = class e extends O {
756
766
  if (c.length !== a.size) throw new A(`computed properties form a cycle: ${[...a].filter((e) => l.get(e) > 0).sort().join(", ")}`);
757
767
  return c.map((e) => [e, r[e]]);
758
768
  }
759
- #D(e) {
769
+ #j(e) {
760
770
  return this[e];
761
771
  }
762
772
  static getPropName(e) {
763
773
  let t = this.attrToPropMap.get(e);
764
774
  return t || (t = e.replace(/-([a-z])/g, (e, t) => t.toUpperCase()), this.attrToPropMap.set(e, t)), t;
765
775
  }
766
- #O(e, t, n) {
767
- let r = this.#D("#" + e), i = this.#u.get(e);
768
- i && l(i.state, i.stateProp, r), this.#e || (this.#J(e), this.#I(e)), this.#X(e, r), this.propertyChangedCallback(e, t, n);
776
+ #M(e, t, n) {
777
+ let r = this.#j("#" + e), i = this.#f.get(e);
778
+ i && l(i.state, i.stateProp, r), this.#e || (this.#$(e), this.#B(e)), this.#te(e, r), this.propertyChangedCallback(e, t, n);
769
779
  }
770
- #k(e, t, n) {
780
+ #N(e, t, n) {
771
781
  if (n.length !== 1) return;
772
782
  let [r] = n;
773
783
  if (!f.test(r)) return;
774
784
  let i = V(e), a = W(e), o = K(e) || G(e), [s, c] = (t ?? "").split(":");
775
785
  if (!(o && s === "value" || i && s === "checked" || a && s === "checked" || G(e))) return;
776
- c ? e["on" + c] === void 0 && this.#U(e, t, "refers to an unsupported event name") : c = "change";
786
+ c ? e["on" + c] === void 0 && this.#J(e, t, "refers to an unsupported event name") : c = "change";
777
787
  let l = y(r);
778
788
  e.addEventListener(c, (e) => {
779
789
  let { target: t } = e;
780
790
  if (!t) return;
781
791
  let { type: n } = this.#n.properties[l], r = t, { value: o } = r;
782
- s === "checked" ? i ? this.#B(l, r.checked) : a && r.checked && this.#B(l, o) : this.#B(l, n === Number ? Y(o) : o), this.#I(l);
792
+ s === "checked" ? i ? this.#W(l, r.checked) : a && r.checked && this.#W(l, o) : this.#W(l, n === Number ? Y(o) : o), this.#B(l);
783
793
  });
784
794
  }
785
- #A(e) {
795
+ #P(e) {
786
796
  return Object.hasOwn(this.#n, e);
787
797
  }
788
- #j(e) {
798
+ #F(e) {
789
799
  return !!this.#n.properties[e];
790
800
  }
791
- #M(e) {
801
+ #I(e) {
792
802
  return !!this.#n.properties[e]?.computed;
793
803
  }
794
- #N(e, n, r) {
795
- if (typeof r != "object" || !r || n !== Array && n !== Object || this.#f.has(r)) return r;
796
- let i = this.#d.get(r);
804
+ #L(e, n, r) {
805
+ if (typeof r != "object" || !r || n !== Array && n !== Object || this.#h.has(r)) return r;
806
+ let i = this.#m.get(r);
797
807
  if (i) return i;
798
808
  let a = t(r, (t, n, r) => {
799
- this.#O(e, n, r);
809
+ this.#M(e, n, r);
800
810
  });
801
- return this.#d.set(r, a), this.#f.add(a), a;
811
+ return this.#m.set(r, a), this.#h.add(a), a;
802
812
  }
803
- #P(e) {
813
+ #R(e) {
804
814
  let t = Array.from(e.querySelectorAll("*"));
805
- for (let e of t) this.#x(e), e.firstElementChild || this.#w(e);
815
+ for (let e of t) this.#w(e), e.firstElementChild || this.#D(e);
806
816
  }
807
817
  static get observedAttributes() {
808
818
  let t = Object.entries(this.properties || {}).filter(([e, t]) => !t.computed).map(([t]) => e.getAttrName(t));
809
819
  return t.includes("disabled") || t.push("disabled"), t;
810
820
  }
811
821
  propertyChangedCallback(e, t, n) {}
812
- #F(e, t) {
822
+ #z(e, t) {
813
823
  if (!t || !f.test(t)) return;
814
824
  let n = y(t);
815
- return this.#D(n) === void 0 && this.#W(e, "", n), n;
825
+ return this.#j(n) === void 0 && this.#Y(e, "", n), n;
816
826
  }
817
- #I(e) {
827
+ #B(e) {
818
828
  let t = this.#n.propToExprsMap.get(e) || [];
819
- this.#S(t);
829
+ this.#T(t);
820
830
  }
821
831
  ready() {}
822
- #L() {
832
+ #V() {
823
833
  let e = this.#n;
824
834
  if (!e.computedPropsRegistered) {
825
835
  e.computedPropsRegistered = !0, e.computedGraph = null;
826
- for (let [t, n] of Object.entries(e.properties)) n.computed && this.#R(t, n);
836
+ for (let [t, n] of Object.entries(e.properties)) n.computed && this.#H(t, n);
827
837
  }
828
838
  }
829
- #R(e, t) {
839
+ #H(e, t) {
830
840
  let n = this.#n;
831
841
  n.registeredComputedProps.add(e);
832
842
  let r = n.propToComputedMap;
@@ -837,31 +847,31 @@ var $ = class e extends O {
837
847
  let a = t.computed;
838
848
  for (let t of a.matchAll(p)) {
839
849
  let r = y(t[0]);
840
- this.#D(r) === void 0 && this.#W(null, e, r);
850
+ this.#j(r) === void 0 && this.#Y(null, e, r);
841
851
  let o = q(r), s = !1;
842
852
  for (let [e, t] of Object.entries(n.properties)) Q(t.usedBy)?.includes(o) && (i(e, a), s = !0);
843
- !s && typeof this.#D(r) != "function" && i(r, a);
853
+ !s && typeof this.#j(r) != "function" && i(r, a);
844
854
  }
845
855
  for (let t of a.matchAll(d)) {
846
856
  let r = t[1];
847
- if (typeof this.#D(r) != "function") throw new A(`property ${e} computed calls non-method ${r}`);
857
+ if (typeof this.#j(r) != "function") throw new A(`property ${e} computed calls non-method ${r}`);
848
858
  for (let [e, t] of Object.entries(n.properties)) Q(t.usedBy)?.includes(r) && i(e, a);
849
859
  }
850
860
  }
851
- #z(e, t) {
861
+ #U(e, t) {
852
862
  this.#t.add(e);
853
863
  try {
854
- this.#B(e, t);
864
+ this.#W(e, t);
855
865
  } finally {
856
866
  this.#t.delete(e);
857
867
  }
858
868
  }
859
- #B(e, t) {
869
+ #W(e, t) {
860
870
  this[e] = t;
861
871
  }
862
- #V(e, t, n = void 0) {
872
+ #G(e, t, n = void 0) {
863
873
  if (!e) return;
864
- let r = this.#te(t, n, e);
874
+ let r = this.#oe(t, n, e);
865
875
  if (!r) {
866
876
  let r = e.replaceAll("this..", "this.");
867
877
  n ? Z(t, n, r) : "textContent" in t && (t.textContent = r);
@@ -870,53 +880,62 @@ var $ = class e extends O {
870
880
  let i = this.#n;
871
881
  r.forEach((t) => {
872
882
  let n = y(t);
873
- if (typeof this.#D(n) == "function") return;
883
+ if (typeof this.#j(n) == "function") return;
874
884
  let r = i.propToExprsMap, a = r.get(n);
875
885
  a || (a = [], r.set(n, a)), a.includes(e) || a.push(e);
876
886
  });
877
- for (let [e, t] of this.#i.entries()) for (let n of t) {
887
+ for (let [e, t] of this.#a.entries()) for (let n of t) {
878
888
  let r = n instanceof HTMLElement || n instanceof CSSStyleRule ? n : n.element;
879
- r instanceof CSSStyleRule || r.isConnected || this.#i.set(e, t.filter((e) => e !== n));
889
+ r instanceof CSSStyleRule || r.isConnected || this.#a.set(e, t.filter((e) => e !== n));
880
890
  }
881
- let a = this.#i.get(e);
882
- a || (a = [], this.#i.set(e, a)), a.push(n ? {
891
+ let a = this.#a.get(e);
892
+ a || (a = [], this.#a.set(e, a)), a.push(n ? {
883
893
  element: t,
884
894
  attrName: n
885
- } : t), t instanceof HTMLElement && this.#k(t, n, r);
886
- let o = this.#C(e);
887
- n ? Z(t, n, o) : this.#Y(t, o);
895
+ } : t), t instanceof HTMLElement && this.#N(t, n, r);
896
+ let o = this.#E(e);
897
+ n ? Z(t, n, o) : this.#ee(t, o);
888
898
  }
889
- #H(e, t) {
899
+ #K(e, t) {
900
+ this.#i.add(e);
901
+ try {
902
+ t === null ? this.removeAttribute(e) : this.setAttribute(e, t);
903
+ } finally {
904
+ this.#i.delete(e);
905
+ }
906
+ e === "disabled" && this.#S();
907
+ }
908
+ #q(e, t) {
890
909
  let n = t?.trim() ?? "", r = this.#n.properties[n];
891
- r || this.#W(e, "ref", n), r.type !== O && this.#U(e, "ref", `refers to property "${n}" whose type is not HTMLElement`), this.#D(n) && this.#U(e, "ref", `is a duplicate reference to the property "${n}"`), this.#B(n, e), e.removeAttribute("ref");
910
+ r || this.#Y(e, "ref", n), r.type !== O && this.#J(e, "ref", `refers to property "${n}" whose type is not HTMLElement`), this.#j(n) && this.#J(e, "ref", `is a duplicate reference to the property "${n}"`), this.#W(n, e), e.removeAttribute("ref");
892
911
  }
893
912
  setAttributeSafe(e, t) {
894
913
  this.hasAttribute(e) || this.setAttribute(e, t);
895
914
  }
896
915
  setFormValue(e, t) {
897
- !this.#o || !U(t) || (this.#o.set(e, t), this.#c?.setFormValue(this.#o));
916
+ !this.#c || !U(t) || (this.#c.set(e, t), this.#u?.setFormValue(this.#c));
898
917
  }
899
918
  static ssr(e = {}) {
900
919
  throw new A("SSR is not available in the browser build.");
901
920
  }
902
- #U(e, t, n) {
921
+ #J(e, t, n) {
903
922
  let r = e instanceof HTMLElement ? e.localName : "CSS rule";
904
923
  throw new A(`component ${this.#n.elementName}` + (e ? `, element "${r}"` : "") + (t ? `, attribute "${t}"` : "") + ` ${n}`);
905
924
  }
906
- #W(e, t, n) {
907
- this.#U(e, t, `refers to missing property "${n}"`);
925
+ #Y(e, t, n) {
926
+ this.#J(e, t, `refers to missing property "${n}"`);
908
927
  }
909
- #G(e, t) {
910
- return this.#K(e, this.getAttribute(t));
928
+ #X(e, t) {
929
+ return this.#Z(e, this.getAttribute(t));
911
930
  }
912
- #K(t, n) {
931
+ #Z(t, n) {
913
932
  if (n?.match(p)) return n;
914
933
  let r = this.#n.properties[t], { type: i, values: a } = r;
915
- if (i || this.#U(null, t, "does not specify its type"), n === null) return i === Boolean ? !1 : F(r);
934
+ if (i || this.#J(null, t, "does not specify its type"), n === null) return i === Boolean ? !1 : F(r);
916
935
  if (i === String) {
917
936
  if (a && !a.includes(n)) {
918
937
  let e = a.map((e) => `"${e}"`).join(", ");
919
- this.#U(null, t, `must be one of ${e}`);
938
+ this.#J(null, t, `must be one of ${e}`);
920
939
  }
921
940
  return n;
922
941
  }
@@ -925,31 +944,31 @@ var $ = class e extends O {
925
944
  if (n === "true") return !0;
926
945
  if (n === "false" || n === "null") return !1;
927
946
  let r = e.getAttrName(t);
928
- return n && n !== r && this.#U(null, t, "is a Boolean attribute, so its value must match attribute name or be missing"), n === "" || n === r;
947
+ return n && n !== r && this.#J(null, t, "is a Boolean attribute, so its value must match attribute name or be missing"), n === "" || n === r;
929
948
  }
930
949
  }
931
- #q(e, t, n, r) {
932
- U(n) && !this.#M(e) && n !== (t === Boolean ? this.hasAttribute(r) : this.#G(e, r)) && X(this, r || e, n);
950
+ #Q(e, t, n, r, i = !0) {
951
+ i && U(n) && !this.#I(e) && n !== (t === Boolean ? this.hasAttribute(r) : this.#X(e, r)) && X(this, r || e, n);
933
952
  }
934
- #J(e) {
935
- for (let [t, n] of this.#E([e])) this.#z(t, this.#C(n));
953
+ #$(e) {
954
+ for (let [t, n] of this.#A([e])) this.#U(t, this.#E(n));
936
955
  }
937
- #Y(e, t) {
956
+ #ee(e, t) {
938
957
  if (t === void 0) return;
939
958
  let n = e instanceof HTMLElement;
940
959
  Array.isArray(t) && (t = t.join(""));
941
960
  let r = typeof t;
942
- r !== "string" && r !== "number" && this.#U(e, void 0, " computed content is not a string or number");
961
+ r !== "string" && r !== "number" && this.#J(e, void 0, " computed content is not a string or number");
943
962
  let i = String(t);
944
963
  if (e instanceof HTMLElement && G(e)) e.value !== i && (e.value = i);
945
964
  else if (n && r === "string" && i.trim().startsWith("<")) {
946
965
  let t = se(i);
947
966
  if (e.innerHTML === t) return;
948
- e.innerHTML = t, this.#ae(e), this.#P(e);
967
+ e.innerHTML = t, this.#ue(e), this.#R(e);
949
968
  } else n && e.textContent !== i && (e.textContent = i);
950
969
  }
951
- #X(e, t) {
952
- let n = this.#l.get(e);
970
+ #te(e, t) {
971
+ let n = this.#d.get(e);
953
972
  if (!n) return;
954
973
  let r = this.getRootNode();
955
974
  if (!(r instanceof ShadowRoot)) return;
@@ -958,14 +977,14 @@ var $ = class e extends O {
958
977
  let a = i;
959
978
  a[n] = t;
960
979
  }
961
- #Z() {
980
+ #ne() {
962
981
  let e = this.#n, t = (e, t, n) => {
963
982
  let r = e.get(t);
964
983
  r || (r = [], e.set(t, r)), r.includes(n) || r.push(n);
965
984
  }, n = () => {
966
985
  let n = E();
967
986
  e.methodToExprsMap = n;
968
- let r = Array.from(this.#i.keys());
987
+ let r = Array.from(this.#a.keys());
969
988
  for (let e of r) {
970
989
  for (let r of e.matchAll(d)) t(n, r[1], e);
971
990
  for (let r of e.matchAll(p)) t(n, q(y(r[0])), e);
@@ -981,7 +1000,7 @@ var $ = class e extends O {
981
1000
  if (H(e)) {
982
1001
  let n = z(e);
983
1002
  if (typeof R(this, n)?.get != "function") throw new A(`property ${t} usedBy contains non-getter ${e}`);
984
- } else if (typeof this.#D(e) != "function") throw new A(`property ${t} usedBy contains non-method ${e}`);
1003
+ } else if (typeof this.#j(e) != "function") throw new A(`property ${t} usedBy contains non-method ${e}`);
985
1004
  let n = o.get(e) || [];
986
1005
  for (let e of n) s.includes(e) || s.push(e);
987
1006
  }
@@ -992,15 +1011,15 @@ var $ = class e extends O {
992
1011
  t = {};
993
1012
  for (let n of Object.keys(e)) t[n] = n;
994
1013
  }
995
- this.#ne(e, t);
996
- for (let [n, r] of Object.entries(t)) if (this.#j(r)) {
1014
+ this.#se(e, t);
1015
+ for (let [n, r] of Object.entries(t)) if (this.#F(r)) {
997
1016
  let t = o(e, n);
998
- t !== void 0 && this.#B(r, t), this.#u.set(r, {
1017
+ t !== void 0 && this.#W(r, t), this.#f.set(r, {
999
1018
  state: e,
1000
1019
  stateProp: n
1001
1020
  });
1002
1021
  }
1003
- let n = this.#p.get(e), r = {
1022
+ let n = this.#g.get(e), r = {
1004
1023
  ...n?.map,
1005
1024
  ...t
1006
1025
  };
@@ -1008,15 +1027,15 @@ var $ = class e extends O {
1008
1027
  let i = e.subscribe(({ statePath: t, newValue: n }) => {
1009
1028
  let i = r[t];
1010
1029
  if (i) {
1011
- this.#B(i, n);
1030
+ this.#W(i, n);
1012
1031
  return;
1013
1032
  }
1014
1033
  let a = Object.keys(r).find((e) => t.startsWith(e + ".") || e.startsWith(t + "."));
1015
1034
  if (!a) return;
1016
1035
  let s = r[a];
1017
- this.#B(s, o(e, a));
1036
+ this.#W(s, o(e, a));
1018
1037
  }, Object.keys(r));
1019
- this.#p.set(e, {
1038
+ this.#g.set(e, {
1020
1039
  map: r,
1021
1040
  unsubscribe: i
1022
1041
  });
@@ -1024,28 +1043,28 @@ var $ = class e extends O {
1024
1043
  validate(e) {
1025
1044
  return [];
1026
1045
  }
1027
- #Q() {
1046
+ #re() {
1028
1047
  let t = new Set(Object.keys(this.#n.properties));
1029
1048
  for (let n of this.getAttributeNames()) if (!D.has(n) && !n.startsWith("on") && n !== "ref") {
1030
1049
  if (n === "form-assoc") {
1031
- this.#ie();
1050
+ this.#le();
1032
1051
  continue;
1033
1052
  }
1034
1053
  if (!t.has(e.getPropName(n))) {
1035
1054
  if (n === "name") {
1036
- this.#ie();
1055
+ this.#le();
1037
1056
  continue;
1038
1057
  }
1039
- this.#U(null, n, "is not a supported attribute");
1058
+ this.#J(null, n, "is not a supported attribute");
1040
1059
  }
1041
1060
  }
1042
1061
  }
1043
- #$(e) {
1062
+ #ie(e) {
1044
1063
  let t = [], n = [], r = { ...this };
1045
1064
  for (let [i, a] of Object.entries(e)) {
1046
1065
  let e = this.#n.properties[i], o = a;
1047
1066
  if (e) {
1048
- e.computed && this.#U(null, i, "is a computed property and cannot be set directly"), e.type === Number && typeof o == "string" && (o = Y(o)), this.#re(i, e.type, o);
1067
+ e.computed && this.#J(null, i, "is a computed property and cannot be set directly"), e.type === Number && typeof o == "string" && (o = Y(o)), this.#ce(i, e.type, o);
1049
1068
  let t = e.validate?.(o);
1050
1069
  typeof t == "string" && n.push(t);
1051
1070
  }
@@ -1056,7 +1075,7 @@ var $ = class e extends O {
1056
1075
  errors: n
1057
1076
  };
1058
1077
  }
1059
- #ee(e, t, n) {
1078
+ #ae(e, t, n) {
1060
1079
  if (this.#e || this.#r) return {
1061
1080
  errors: [],
1062
1081
  skipped: !0
@@ -1072,39 +1091,39 @@ var $ = class e extends O {
1072
1091
  skipped: !1
1073
1092
  };
1074
1093
  }
1075
- #te(e, t, n) {
1094
+ #oe(e, t, n) {
1076
1095
  let r = n.match(p);
1077
1096
  if (r) return r.forEach((n) => {
1078
1097
  let r = y(n);
1079
- this.#D(r) === void 0 && this.#W(e, t, r);
1098
+ this.#j(r) === void 0 && this.#Y(e, t, r);
1080
1099
  }), r;
1081
1100
  }
1082
- #ne(e, t) {
1101
+ #se(e, t) {
1083
1102
  for (let [n, r] of Object.entries(t)) {
1084
1103
  let t = o(e, n);
1085
- t === void 0 && this.#U(this, void 0, `invalid state path "${n}"`), t = this.#D(r), this.#j(r) || this.#U(null, r, "refers to missing property in useState map");
1104
+ t === void 0 && this.#J(this, void 0, `invalid state path "${n}"`), t = this.#j(r), this.#F(r) || this.#J(null, r, "refers to missing property in useState map");
1086
1105
  }
1087
1106
  }
1088
- #re(e, t, n) {
1107
+ #ce(e, t, n) {
1089
1108
  let { values: r } = this.#n.properties[e];
1090
1109
  if (r) {
1091
1110
  let i;
1092
- t === String ? typeof n == "string" ? r.includes(n) || (i = `must be one of ${r.map((e) => `"${e}"`).join(", ")}`) : i = `value is a ${typeof n}, but type is String` : i = "declares allowed values, but its type is not String", i && this.#U(null, e, i);
1111
+ t === String ? typeof n == "string" ? r.includes(n) || (i = `must be one of ${r.map((e) => `"${e}"`).join(", ")}`) : i = `value is a ${typeof n}, but type is String` : i = "declares allowed values, but its type is not String", i && this.#J(null, e, i);
1093
1112
  }
1094
1113
  if (n instanceof t) return;
1095
1114
  let i = typeof n;
1096
1115
  if (i === "object") {
1097
1116
  let { constructor: r } = n;
1098
- i = r.name, r !== t && this.#U(null, e, `was set to a ${i}, but must be a ${t.name}`);
1117
+ i = r.name, r !== t && this.#J(null, e, `was set to a ${i}, but must be a ${t.name}`);
1099
1118
  }
1100
- i !== t.name.toLowerCase() && this.#U(null, e, `was set to a ${i}, but must be a ${t.name}`);
1119
+ i !== t.name.toLowerCase() && this.#J(null, e, `was set to a ${i}, but must be a ${t.name}`);
1101
1120
  }
1102
- #ie() {
1121
+ #le() {
1103
1122
  if (this.#n.formAssociated || this.closest("form") === null) return;
1104
1123
  let e = this.#n.name;
1105
- this.#U(this, void 0, `inside form, class ${e} requires "static formAssociated = true;"`);
1124
+ this.#J(this, void 0, `inside form, class ${e} requires "static formAssociated = true;"`);
1106
1125
  }
1107
- #ae(e) {
1126
+ #ue(e) {
1108
1127
  let t = Array.from(e.querySelectorAll("*"));
1109
1128
  for (let e of t) {
1110
1129
  let t = [];
@@ -1114,9 +1133,9 @@ var $ = class e extends O {
1114
1133
  let i = r.slice(2);
1115
1134
  i = i[0].toLowerCase() + i.slice(1).toLowerCase();
1116
1135
  let a = n.value;
1117
- this.#te(e, r, a);
1136
+ this.#oe(e, r, a);
1118
1137
  let o;
1119
- typeof this.#D(a) == "function" ? o = (e) => this.#D(a).call(this, e) : (this.#te(e, r, a), o = () => this.#C(a)), e.addEventListener(i, o), t.push(r);
1138
+ typeof this.#j(a) == "function" ? o = (e) => this.#j(a).call(this, e) : (this.#oe(e, r, a), o = () => this.#E(a)), e.addEventListener(i, o), t.push(r);
1120
1139
  }
1121
1140
  }
1122
1141
  for (let n of t) e.removeAttribute(n);
@@ -1,4 +1,4 @@
1
- import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c, u as l } from "./wrec-jeb0Pxec.js";
1
+ import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c, u as l } from "./wrec-B9pzDXTH.js";
2
2
  //#region \0rolldown/runtime.js
3
3
  var u = Object.defineProperty, d = Object.getOwnPropertyDescriptor, f = Object.getOwnPropertyNames, p = Object.prototype.hasOwnProperty, m = (e, t) => () => (e && (t = e(e = 0)), t), h = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), g = (e, t) => {
4
4
  let n = {};
package/dist/wrec.es.js CHANGED
@@ -1,2 +1,2 @@
1
- import { i as e, n as t, r as n, t as r, u as i } from "./wrec-jeb0Pxec.js";
1
+ import { i as e, n as t, r as n, t as r, u as i } from "./wrec-B9pzDXTH.js";
2
2
  export { r as Wrec, i as WrecState, t as createElement, n as css, e as html };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrec",
3
- "version": "0.42.2",
3
+ "version": "0.43.1",
4
4
  "description": "a library that greatly simplifies building web components",
5
5
  "keywords": [
6
6
  "component",
@@ -69,6 +69,6 @@
69
69
  "preview": "vite preview",
70
70
  "test": "node port-check.js && playwright test",
71
71
  "testui": "playwright test --ui",
72
- "unittest": "vitest run"
72
+ "unittest": "vitest run --maxWorkers=1"
73
73
  }
74
74
  }