@nectary/components 5.47.2 → 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,6 +16685,29 @@ 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;
@@ -16773,21 +16796,29 @@ class Skeleton extends NectaryElement {
16773
16796
  };
16774
16797
  #addClipRect(child, bb) {
16775
16798
  const data2 = child.getBoundingClientRect();
16776
- const radiusStr = getCssVar(child, "--sinch-local-shape-radius") ?? "0";
16777
- const radius = attrValueToInteger(radiusStr, {
16778
- min: 0,
16779
- defaultValue: 0
16780
- });
16781
- 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(
16782
16805
  "http://www.w3.org/2000/svg",
16783
- "rect"
16806
+ "path"
16807
+ );
16808
+ path.setAttribute(
16809
+ "d",
16810
+ roundedRectPath({ x, y, width, height, radius })
16784
16811
  );
16785
- rect.setAttribute("x", String(data2.x - bb.x - this.#borderWidth));
16786
- rect.setAttribute("y", String(data2.y - bb.y - this.#borderWidth));
16787
- rect.setAttribute("width", String(data2.width));
16788
- rect.setAttribute("height", String(data2.height));
16789
- rect.setAttribute("rx", String(radius));
16790
- 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;
16791
16822
  }
16792
16823
  }
16793
16824
  defineCustomElement("sinch-skeleton", Skeleton);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nectary/components",
3
- "version": "5.47.2",
3
+ "version": "5.47.3",
4
4
  "files": [
5
5
  "**/*/*.css",
6
6
  "**/*/*.json",
package/skeleton/index.js CHANGED
@@ -5,6 +5,29 @@ 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;
@@ -93,21 +116,29 @@ class Skeleton extends NectaryElement {
93
116
  };
94
117
  #addClipRect(child, bb) {
95
118
  const data = child.getBoundingClientRect();
96
- const radiusStr = getCssVar(child, "--sinch-local-shape-radius") ?? "0";
97
- const radius = attrValueToInteger(radiusStr, {
98
- min: 0,
99
- defaultValue: 0
100
- });
101
- 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(
102
125
  "http://www.w3.org/2000/svg",
103
- "rect"
126
+ "path"
104
127
  );
105
- rect.setAttribute("x", String(data.x - bb.x - this.#borderWidth));
106
- rect.setAttribute("y", String(data.y - bb.y - this.#borderWidth));
107
- rect.setAttribute("width", String(data.width));
108
- rect.setAttribute("height", String(data.height));
109
- rect.setAttribute("rx", String(radius));
110
- this.#clip.appendChild(rect);
128
+ path.setAttribute(
129
+ "d",
130
+ roundedRectPath({ x, y, width, height, radius })
131
+ );
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;
111
142
  }
112
143
  }
113
144
  defineCustomElement("sinch-skeleton", Skeleton);