wrec 0.42.2 → 0.43.0

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