kk-web-components 1.0.3 → 1.0.5
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/package.json +1 -1
- package/src/ui-icon.js +11 -7
package/package.json
CHANGED
package/src/ui-icon.js
CHANGED
|
@@ -4,6 +4,7 @@ const sharedStyles = new CSSStyleSheet();
|
|
|
4
4
|
sharedStyles.replaceSync(`
|
|
5
5
|
:host {
|
|
6
6
|
flex-shrink: 0;
|
|
7
|
+
display: block;
|
|
7
8
|
|
|
8
9
|
svg {
|
|
9
10
|
display: block;
|
|
@@ -51,17 +52,20 @@ class UiIcon extends HTMLElement {
|
|
|
51
52
|
|
|
52
53
|
// Hide from screen readers
|
|
53
54
|
svg.setAttribute("aria-hidden", "true");
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
svg.setAttribute("part", "icon"); // Expose svg for styling
|
|
56
|
+
|
|
57
|
+
// Validate values
|
|
58
|
+
const isValidSize = Number.isInteger(size) && size > 0;
|
|
59
|
+
const isValidViewbox = viewbox && /^(\d+(\.\d+)?\s){3}\d+(\.\d+)?$/.test(viewbox);
|
|
60
|
+
const isValidRotation = !isNaN(parseFloat(rotation));
|
|
61
|
+
|
|
62
|
+
if (isValidViewbox) {
|
|
56
63
|
svg.setAttribute("viewBox", viewbox);
|
|
57
|
-
} else {
|
|
58
|
-
// Set size attributes
|
|
64
|
+
} else if (isValidSize) {
|
|
59
65
|
svg.setAttribute("width", size);
|
|
60
66
|
svg.setAttribute("height", size);
|
|
61
67
|
}
|
|
62
|
-
|
|
63
|
-
// Apply rotation if provided
|
|
64
|
-
if (rotation) {
|
|
68
|
+
if (isValidRotation) {
|
|
65
69
|
svg.style.transform = `rotate(${rotation}deg)`;
|
|
66
70
|
}
|
|
67
71
|
|