@nectary/components 5.47.1 → 5.47.3

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/bundle.js CHANGED
@@ -16685,14 +16685,37 @@ const templateHTML$d = '<style>:host{display:block;position:relative}#wrapper{po
16685
16685
  const template$d = document.createElement("template");
16686
16686
  template$d.innerHTML = templateHTML$d;
16687
16687
  const BORDER_WIDTH = 1;
16688
+ const roundedRectPath = ({
16689
+ x,
16690
+ y,
16691
+ width,
16692
+ height,
16693
+ radius
16694
+ }) => {
16695
+ if (radius <= 0) {
16696
+ return `M${x},${y}h${width}v${height}h${-width}z`;
16697
+ }
16698
+ return [
16699
+ `M${x + radius},${y}`,
16700
+ `H${x + width - radius}`,
16701
+ `A${radius},${radius} 0 0 1 ${x + width},${y + radius}`,
16702
+ `V${y + height - radius}`,
16703
+ `A${radius},${radius} 0 0 1 ${x + width - radius},${y + height}`,
16704
+ `H${x + radius}`,
16705
+ `A${radius},${radius} 0 0 1 ${x},${y + height - radius}`,
16706
+ `V${y + radius}`,
16707
+ `A${radius},${radius} 0 0 1 ${x + radius},${y}`,
16708
+ "Z"
16709
+ ].join(" ");
16710
+ };
16688
16711
  class Skeleton extends NectaryElement {
16689
16712
  #shimmer;
16690
16713
  #wrapper;
16691
16714
  #slot;
16692
16715
  #clip;
16693
16716
  #controller = null;
16694
- #bb = null;
16695
- #observer = null;
16717
+ #intersectionObserver = null;
16718
+ #resizeObserver = null;
16696
16719
  #borderWidth = 0;
16697
16720
  constructor() {
16698
16721
  super();
@@ -16713,30 +16736,35 @@ class Skeleton extends NectaryElement {
16713
16736
  this.#slot.addEventListener("slotchange", this.#onSlotChange, {
16714
16737
  signal: this.#controller.signal
16715
16738
  });
16716
- this.#observer = new IntersectionObserver(
16739
+ this.#intersectionObserver = new IntersectionObserver(
16717
16740
  (entries) => {
16718
- this.#bb = entries[0].boundingClientRect;
16719
- if (this.#bb.width === 0) {
16741
+ if (!entries[0].isIntersecting) {
16720
16742
  return;
16721
16743
  }
16722
16744
  this.#buildClipPath();
16745
+ if (this.#wrapper.getBoundingClientRect().width === 0) {
16746
+ return;
16747
+ }
16723
16748
  this.#shimmer.classList.add("animated");
16724
- this.#observer?.disconnect();
16725
- this.#observer = null;
16749
+ this.#intersectionObserver?.disconnect();
16750
+ this.#intersectionObserver = null;
16751
+ this.#resizeObserver = new ResizeObserver(this.#onResize);
16752
+ this.#resizeObserver.observe(this.#wrapper);
16726
16753
  },
16727
- { threshold: 1 }
16754
+ { threshold: 0 }
16728
16755
  );
16729
- this.#observer.observe(this.#wrapper);
16756
+ this.#intersectionObserver.observe(this.#wrapper);
16730
16757
  }
16731
16758
  }
16732
16759
  disconnectedCallback() {
16733
16760
  this.#shimmer.classList.remove("animated");
16734
- this.#bb = null;
16735
16761
  this.#clip.innerHTML = "";
16736
16762
  this.#controller?.abort();
16737
16763
  this.#controller = null;
16738
- this.#observer?.disconnect();
16739
- this.#observer = null;
16764
+ this.#intersectionObserver?.disconnect();
16765
+ this.#intersectionObserver = null;
16766
+ this.#resizeObserver?.disconnect();
16767
+ this.#resizeObserver = null;
16740
16768
  }
16741
16769
  static get observedAttributes() {
16742
16770
  return [
@@ -16747,38 +16775,50 @@ class Skeleton extends NectaryElement {
16747
16775
  attributeChangedCallback(name, _oldVal, newVal) {
16748
16776
  if (name === "card") {
16749
16777
  this.#borderWidth = isAttrTrue(newVal) ? BORDER_WIDTH : 0;
16778
+ this.#buildClipPath();
16750
16779
  }
16751
16780
  }
16752
16781
  #buildClipPath() {
16753
16782
  this.#clip.innerHTML = "";
16754
- if (this.#bb === null) {
16783
+ const bb = this.#wrapper.getBoundingClientRect();
16784
+ if (bb.width === 0) {
16755
16785
  return;
16756
16786
  }
16757
- for (const child of this.#slot.assignedElements()) {
16758
- this.#addClipRect(child);
16787
+ for (const item of this.querySelectorAll("sinch-skeleton-item")) {
16788
+ this.#addClipRect(item, bb);
16759
16789
  }
16760
16790
  }
16761
16791
  #onSlotChange = () => {
16762
16792
  this.#buildClipPath();
16763
16793
  };
16764
- #addClipRect(child) {
16794
+ #onResize = () => {
16795
+ this.#buildClipPath();
16796
+ };
16797
+ #addClipRect(child, bb) {
16765
16798
  const data2 = child.getBoundingClientRect();
16766
- const bb = this.#bb;
16767
- const radiusStr = getCssVar(child, "--sinch-local-shape-radius") ?? "0";
16768
- const radius = attrValueToInteger(radiusStr, {
16769
- min: 0,
16770
- defaultValue: 0
16771
- });
16772
- const rect = document.createElementNS(
16799
+ const x = data2.x - bb.x - this.#borderWidth;
16800
+ const y = data2.y - bb.y - this.#borderWidth;
16801
+ const width = data2.width;
16802
+ const height = data2.height;
16803
+ const radius = Math.min(this.#getClipRadius(child), width / 2, height / 2);
16804
+ const path = document.createElementNS(
16773
16805
  "http://www.w3.org/2000/svg",
16774
- "rect"
16806
+ "path"
16807
+ );
16808
+ path.setAttribute(
16809
+ "d",
16810
+ roundedRectPath({ x, y, width, height, radius })
16775
16811
  );
16776
- rect.setAttribute("x", String(data2.x - bb.x - this.#borderWidth));
16777
- rect.setAttribute("y", String(data2.y - bb.y - this.#borderWidth));
16778
- rect.setAttribute("width", String(data2.width));
16779
- rect.setAttribute("height", String(data2.height));
16780
- rect.setAttribute("rx", String(radius));
16781
- this.#clip.appendChild(rect);
16812
+ this.#clip.appendChild(path);
16813
+ }
16814
+ /** Match the painted skeleton-item corner radius (on #content inside its shadow). */
16815
+ #getClipRadius(child) {
16816
+ const content = child.shadowRoot?.querySelector("#content");
16817
+ const radiusStr = content !== void 0 && content !== null ? getComputedStyle(content).borderRadius.split(/\s+/)[0] ?? "0" : getCssVar(child, "--sinch-local-shape-radius") ?? "0";
16818
+ return attrValueToInteger(radiusStr, {
16819
+ min: 0,
16820
+ defaultValue: 0
16821
+ }) ?? 0;
16782
16822
  }
16783
16823
  }
16784
16824
  defineCustomElement("sinch-skeleton", Skeleton);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nectary/components",
3
- "version": "5.47.1",
3
+ "version": "5.47.3",
4
4
  "files": [
5
5
  "**/*/*.css",
6
6
  "**/*/*.json",
package/skeleton/index.js CHANGED
@@ -5,14 +5,37 @@ const templateHTML = '<style>:host{display:block;position:relative}#wrapper{posi
5
5
  const template = document.createElement("template");
6
6
  template.innerHTML = templateHTML;
7
7
  const BORDER_WIDTH = 1;
8
+ const roundedRectPath = ({
9
+ x,
10
+ y,
11
+ width,
12
+ height,
13
+ radius
14
+ }) => {
15
+ if (radius <= 0) {
16
+ return `M${x},${y}h${width}v${height}h${-width}z`;
17
+ }
18
+ return [
19
+ `M${x + radius},${y}`,
20
+ `H${x + width - radius}`,
21
+ `A${radius},${radius} 0 0 1 ${x + width},${y + radius}`,
22
+ `V${y + height - radius}`,
23
+ `A${radius},${radius} 0 0 1 ${x + width - radius},${y + height}`,
24
+ `H${x + radius}`,
25
+ `A${radius},${radius} 0 0 1 ${x},${y + height - radius}`,
26
+ `V${y + radius}`,
27
+ `A${radius},${radius} 0 0 1 ${x + radius},${y}`,
28
+ "Z"
29
+ ].join(" ");
30
+ };
8
31
  class Skeleton extends NectaryElement {
9
32
  #shimmer;
10
33
  #wrapper;
11
34
  #slot;
12
35
  #clip;
13
36
  #controller = null;
14
- #bb = null;
15
- #observer = null;
37
+ #intersectionObserver = null;
38
+ #resizeObserver = null;
16
39
  #borderWidth = 0;
17
40
  constructor() {
18
41
  super();
@@ -33,30 +56,35 @@ class Skeleton extends NectaryElement {
33
56
  this.#slot.addEventListener("slotchange", this.#onSlotChange, {
34
57
  signal: this.#controller.signal
35
58
  });
36
- this.#observer = new IntersectionObserver(
59
+ this.#intersectionObserver = new IntersectionObserver(
37
60
  (entries) => {
38
- this.#bb = entries[0].boundingClientRect;
39
- if (this.#bb.width === 0) {
61
+ if (!entries[0].isIntersecting) {
40
62
  return;
41
63
  }
42
64
  this.#buildClipPath();
65
+ if (this.#wrapper.getBoundingClientRect().width === 0) {
66
+ return;
67
+ }
43
68
  this.#shimmer.classList.add("animated");
44
- this.#observer?.disconnect();
45
- this.#observer = null;
69
+ this.#intersectionObserver?.disconnect();
70
+ this.#intersectionObserver = null;
71
+ this.#resizeObserver = new ResizeObserver(this.#onResize);
72
+ this.#resizeObserver.observe(this.#wrapper);
46
73
  },
47
- { threshold: 1 }
74
+ { threshold: 0 }
48
75
  );
49
- this.#observer.observe(this.#wrapper);
76
+ this.#intersectionObserver.observe(this.#wrapper);
50
77
  }
51
78
  }
52
79
  disconnectedCallback() {
53
80
  this.#shimmer.classList.remove("animated");
54
- this.#bb = null;
55
81
  this.#clip.innerHTML = "";
56
82
  this.#controller?.abort();
57
83
  this.#controller = null;
58
- this.#observer?.disconnect();
59
- this.#observer = null;
84
+ this.#intersectionObserver?.disconnect();
85
+ this.#intersectionObserver = null;
86
+ this.#resizeObserver?.disconnect();
87
+ this.#resizeObserver = null;
60
88
  }
61
89
  static get observedAttributes() {
62
90
  return [
@@ -67,38 +95,50 @@ class Skeleton extends NectaryElement {
67
95
  attributeChangedCallback(name, _oldVal, newVal) {
68
96
  if (name === "card") {
69
97
  this.#borderWidth = isAttrTrue(newVal) ? BORDER_WIDTH : 0;
98
+ this.#buildClipPath();
70
99
  }
71
100
  }
72
101
  #buildClipPath() {
73
102
  this.#clip.innerHTML = "";
74
- if (this.#bb === null) {
103
+ const bb = this.#wrapper.getBoundingClientRect();
104
+ if (bb.width === 0) {
75
105
  return;
76
106
  }
77
- for (const child of this.#slot.assignedElements()) {
78
- this.#addClipRect(child);
107
+ for (const item of this.querySelectorAll("sinch-skeleton-item")) {
108
+ this.#addClipRect(item, bb);
79
109
  }
80
110
  }
81
111
  #onSlotChange = () => {
82
112
  this.#buildClipPath();
83
113
  };
84
- #addClipRect(child) {
114
+ #onResize = () => {
115
+ this.#buildClipPath();
116
+ };
117
+ #addClipRect(child, bb) {
85
118
  const data = child.getBoundingClientRect();
86
- const bb = this.#bb;
87
- const radiusStr = getCssVar(child, "--sinch-local-shape-radius") ?? "0";
88
- const radius = attrValueToInteger(radiusStr, {
89
- min: 0,
90
- defaultValue: 0
91
- });
92
- const rect = document.createElementNS(
119
+ const x = data.x - bb.x - this.#borderWidth;
120
+ const y = data.y - bb.y - this.#borderWidth;
121
+ const width = data.width;
122
+ const height = data.height;
123
+ const radius = Math.min(this.#getClipRadius(child), width / 2, height / 2);
124
+ const path = document.createElementNS(
93
125
  "http://www.w3.org/2000/svg",
94
- "rect"
126
+ "path"
127
+ );
128
+ path.setAttribute(
129
+ "d",
130
+ roundedRectPath({ x, y, width, height, radius })
95
131
  );
96
- rect.setAttribute("x", String(data.x - bb.x - this.#borderWidth));
97
- rect.setAttribute("y", String(data.y - bb.y - this.#borderWidth));
98
- rect.setAttribute("width", String(data.width));
99
- rect.setAttribute("height", String(data.height));
100
- rect.setAttribute("rx", String(radius));
101
- this.#clip.appendChild(rect);
132
+ this.#clip.appendChild(path);
133
+ }
134
+ /** Match the painted skeleton-item corner radius (on #content inside its shadow). */
135
+ #getClipRadius(child) {
136
+ const content = child.shadowRoot?.querySelector("#content");
137
+ const radiusStr = content !== void 0 && content !== null ? getComputedStyle(content).borderRadius.split(/\s+/)[0] ?? "0" : getCssVar(child, "--sinch-local-shape-radius") ?? "0";
138
+ return attrValueToInteger(radiusStr, {
139
+ min: 0,
140
+ defaultValue: 0
141
+ }) ?? 0;
102
142
  }
103
143
  }
104
144
  defineCustomElement("sinch-skeleton", Skeleton);