@cntrl-site/components 0.1.18 → 0.1.19
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/dist/Components/utils/getImageRect.d.ts +6 -0
- package/dist/index.js +40 -24
- package/dist/index.mjs +40 -24
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1729,15 +1729,20 @@ const getPositionStyles = (position, offset, isEditor) => {
|
|
|
1729
1729
|
}
|
|
1730
1730
|
return styles2;
|
|
1731
1731
|
};
|
|
1732
|
+
function getPaddingValues(img2) {
|
|
1733
|
+
const style = window.getComputedStyle(img2);
|
|
1734
|
+
return {
|
|
1735
|
+
top: parseFloat(style.paddingTop) || 0,
|
|
1736
|
+
right: parseFloat(style.paddingRight) || 0,
|
|
1737
|
+
bottom: parseFloat(style.paddingBottom) || 0,
|
|
1738
|
+
left: parseFloat(style.paddingLeft) || 0
|
|
1739
|
+
};
|
|
1740
|
+
}
|
|
1732
1741
|
function getDisplayedImageRect(img2) {
|
|
1733
1742
|
const container = img2.getBoundingClientRect();
|
|
1734
|
-
const
|
|
1735
|
-
const
|
|
1736
|
-
const
|
|
1737
|
-
const paddingBottom = parseFloat(style.paddingBottom) || 0;
|
|
1738
|
-
const paddingLeft = parseFloat(style.paddingLeft) || 0;
|
|
1739
|
-
const containerW = Math.max(0, container.width - paddingLeft - paddingRight);
|
|
1740
|
-
const containerH = Math.max(0, container.height - paddingTop - paddingBottom);
|
|
1743
|
+
const padding = getPaddingValues(img2);
|
|
1744
|
+
const containerW = Math.max(0, container.width - padding.left - padding.right);
|
|
1745
|
+
const containerH = Math.max(0, container.height - padding.top - padding.bottom);
|
|
1741
1746
|
const imgW = img2.naturalWidth;
|
|
1742
1747
|
const imgH = img2.naturalHeight;
|
|
1743
1748
|
const containerRatio = containerW / containerH;
|
|
@@ -1750,8 +1755,8 @@ function getDisplayedImageRect(img2) {
|
|
|
1750
1755
|
renderedH = containerH;
|
|
1751
1756
|
renderedW = containerH * imgRatio;
|
|
1752
1757
|
}
|
|
1753
|
-
const contentLeft = container.left +
|
|
1754
|
-
const contentTop = container.top +
|
|
1758
|
+
const contentLeft = container.left + padding.left;
|
|
1759
|
+
const contentTop = container.top + padding.top;
|
|
1755
1760
|
const offsetX = (containerW - renderedW) / 2 + contentLeft;
|
|
1756
1761
|
const offsetY = (containerH - renderedH) / 2 + contentTop;
|
|
1757
1762
|
return {
|
|
@@ -1761,6 +1766,16 @@ function getDisplayedImageRect(img2) {
|
|
|
1761
1766
|
height: renderedH
|
|
1762
1767
|
};
|
|
1763
1768
|
}
|
|
1769
|
+
function getPaddedContainerBounds(img2) {
|
|
1770
|
+
const container = img2.getBoundingClientRect();
|
|
1771
|
+
const padding = getPaddingValues(img2);
|
|
1772
|
+
return {
|
|
1773
|
+
left: container.left + padding.left,
|
|
1774
|
+
right: container.right - padding.right,
|
|
1775
|
+
top: container.top + padding.top,
|
|
1776
|
+
bottom: container.bottom - padding.bottom
|
|
1777
|
+
};
|
|
1778
|
+
}
|
|
1764
1779
|
function getColorAlpha(color) {
|
|
1765
1780
|
const rgbaMatch = color.match(/rgba?\(([^)]+)\)/);
|
|
1766
1781
|
if (rgbaMatch) {
|
|
@@ -1991,17 +2006,8 @@ const Lightbox = ({ isOpen, onClose, content, lightboxStyles, settings, portalId
|
|
|
1991
2006
|
}
|
|
1992
2007
|
let inside;
|
|
1993
2008
|
if (isCover && imageRef.current) {
|
|
1994
|
-
const
|
|
1995
|
-
|
|
1996
|
-
const paddingTop = parseFloat(style.paddingTop) || 0;
|
|
1997
|
-
const paddingRight = parseFloat(style.paddingRight) || 0;
|
|
1998
|
-
const paddingBottom = parseFloat(style.paddingBottom) || 0;
|
|
1999
|
-
const paddingLeft = parseFloat(style.paddingLeft) || 0;
|
|
2000
|
-
const contentLeft = imgRect.left + paddingLeft;
|
|
2001
|
-
const contentRight = imgRect.right - paddingRight;
|
|
2002
|
-
const contentTop = imgRect.top + paddingTop;
|
|
2003
|
-
const contentBottom = imgRect.bottom - paddingBottom;
|
|
2004
|
-
inside = clientX >= contentLeft && clientX <= contentRight && clientY >= contentTop && clientY <= contentBottom;
|
|
2009
|
+
const bounds = getPaddedContainerBounds(imageRef.current);
|
|
2010
|
+
inside = clientX >= bounds.left && clientX <= bounds.right && clientY >= bounds.top && clientY <= bounds.bottom;
|
|
2005
2011
|
} else {
|
|
2006
2012
|
const rect = imageRef.current ? getDisplayedImageRect(imageRef.current) : null;
|
|
2007
2013
|
if (!rect) {
|
|
@@ -2098,6 +2104,9 @@ const Lightbox = ({ isOpen, onClose, content, lightboxStyles, settings, portalId
|
|
|
2098
2104
|
if (target && (target.closest(`.${classes.thumbsWrapper}`) || target.closest(`.${classes.thumbsContainer}`))) {
|
|
2099
2105
|
return;
|
|
2100
2106
|
}
|
|
2107
|
+
if (slider.type === "slide") {
|
|
2108
|
+
return;
|
|
2109
|
+
}
|
|
2101
2110
|
e.preventDefault();
|
|
2102
2111
|
};
|
|
2103
2112
|
document.addEventListener("touchmove", preventScroll, { passive: false });
|
|
@@ -2110,10 +2119,11 @@ const Lightbox = ({ isOpen, onClose, content, lightboxStyles, settings, portalId
|
|
|
2110
2119
|
}
|
|
2111
2120
|
setAnimationFinished(false);
|
|
2112
2121
|
};
|
|
2113
|
-
}, [isOpen, isEditor, area.color]);
|
|
2122
|
+
}, [isOpen, isEditor, area.color, slider.type]);
|
|
2114
2123
|
react.useEffect(() => {
|
|
2115
2124
|
if (!isOpen) return;
|
|
2116
2125
|
const handleTouchEnd = (e) => {
|
|
2126
|
+
var _a, _b;
|
|
2117
2127
|
if (isClosingRef.current) {
|
|
2118
2128
|
e.stopPropagation();
|
|
2119
2129
|
return;
|
|
@@ -2126,14 +2136,20 @@ const Lightbox = ({ isOpen, onClose, content, lightboxStyles, settings, portalId
|
|
|
2126
2136
|
if (target && (target.closest(`.${classes.thumbsContainer}`) || target.closest(`.${classes.thumbItem}`))) {
|
|
2127
2137
|
return;
|
|
2128
2138
|
}
|
|
2139
|
+
if (slider.type === "slide" && triggers.type === "drag" && ((_b = (_a = lightboxRef.current) == null ? void 0 : _a.splide) == null ? void 0 : _b.root)) {
|
|
2140
|
+
const splideContainer = lightboxRef.current.splide.root;
|
|
2141
|
+
if (target && (splideContainer.contains(target) || splideContainer === target)) {
|
|
2142
|
+
return;
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2129
2145
|
if (e.touches.length === 0 && e.changedTouches.length > 0) {
|
|
2130
2146
|
const currentImage = content[currentIndex];
|
|
2131
2147
|
const isCover = (currentImage == null ? void 0 : currentImage.image.objectFit) === "cover";
|
|
2132
2148
|
const touch = e.changedTouches[0];
|
|
2133
2149
|
let inside;
|
|
2134
2150
|
if (isCover && imageRef.current) {
|
|
2135
|
-
const
|
|
2136
|
-
inside = touch.clientX >=
|
|
2151
|
+
const bounds = getPaddedContainerBounds(imageRef.current);
|
|
2152
|
+
inside = touch.clientX >= bounds.left && touch.clientX <= bounds.right && touch.clientY >= bounds.top && touch.clientY <= bounds.bottom;
|
|
2137
2153
|
} else {
|
|
2138
2154
|
const rect = imageRef.current ? getDisplayedImageRect(imageRef.current) : null;
|
|
2139
2155
|
if (!rect) return;
|
|
@@ -2307,7 +2323,7 @@ const Lightbox = ({ isOpen, onClose, content, lightboxStyles, settings, portalId
|
|
|
2307
2323
|
height: "100%",
|
|
2308
2324
|
type: slider.type === "fade" || slider.type === "scale" ? "fade" : "loop",
|
|
2309
2325
|
padding: 0,
|
|
2310
|
-
rewind:
|
|
2326
|
+
rewind: triggers.repeat !== "close",
|
|
2311
2327
|
start: 0
|
|
2312
2328
|
},
|
|
2313
2329
|
style: { "--splide-speed": slider.duration },
|
package/dist/index.mjs
CHANGED
|
@@ -1727,15 +1727,20 @@ const getPositionStyles = (position, offset, isEditor) => {
|
|
|
1727
1727
|
}
|
|
1728
1728
|
return styles2;
|
|
1729
1729
|
};
|
|
1730
|
+
function getPaddingValues(img2) {
|
|
1731
|
+
const style = window.getComputedStyle(img2);
|
|
1732
|
+
return {
|
|
1733
|
+
top: parseFloat(style.paddingTop) || 0,
|
|
1734
|
+
right: parseFloat(style.paddingRight) || 0,
|
|
1735
|
+
bottom: parseFloat(style.paddingBottom) || 0,
|
|
1736
|
+
left: parseFloat(style.paddingLeft) || 0
|
|
1737
|
+
};
|
|
1738
|
+
}
|
|
1730
1739
|
function getDisplayedImageRect(img2) {
|
|
1731
1740
|
const container = img2.getBoundingClientRect();
|
|
1732
|
-
const
|
|
1733
|
-
const
|
|
1734
|
-
const
|
|
1735
|
-
const paddingBottom = parseFloat(style.paddingBottom) || 0;
|
|
1736
|
-
const paddingLeft = parseFloat(style.paddingLeft) || 0;
|
|
1737
|
-
const containerW = Math.max(0, container.width - paddingLeft - paddingRight);
|
|
1738
|
-
const containerH = Math.max(0, container.height - paddingTop - paddingBottom);
|
|
1741
|
+
const padding = getPaddingValues(img2);
|
|
1742
|
+
const containerW = Math.max(0, container.width - padding.left - padding.right);
|
|
1743
|
+
const containerH = Math.max(0, container.height - padding.top - padding.bottom);
|
|
1739
1744
|
const imgW = img2.naturalWidth;
|
|
1740
1745
|
const imgH = img2.naturalHeight;
|
|
1741
1746
|
const containerRatio = containerW / containerH;
|
|
@@ -1748,8 +1753,8 @@ function getDisplayedImageRect(img2) {
|
|
|
1748
1753
|
renderedH = containerH;
|
|
1749
1754
|
renderedW = containerH * imgRatio;
|
|
1750
1755
|
}
|
|
1751
|
-
const contentLeft = container.left +
|
|
1752
|
-
const contentTop = container.top +
|
|
1756
|
+
const contentLeft = container.left + padding.left;
|
|
1757
|
+
const contentTop = container.top + padding.top;
|
|
1753
1758
|
const offsetX = (containerW - renderedW) / 2 + contentLeft;
|
|
1754
1759
|
const offsetY = (containerH - renderedH) / 2 + contentTop;
|
|
1755
1760
|
return {
|
|
@@ -1759,6 +1764,16 @@ function getDisplayedImageRect(img2) {
|
|
|
1759
1764
|
height: renderedH
|
|
1760
1765
|
};
|
|
1761
1766
|
}
|
|
1767
|
+
function getPaddedContainerBounds(img2) {
|
|
1768
|
+
const container = img2.getBoundingClientRect();
|
|
1769
|
+
const padding = getPaddingValues(img2);
|
|
1770
|
+
return {
|
|
1771
|
+
left: container.left + padding.left,
|
|
1772
|
+
right: container.right - padding.right,
|
|
1773
|
+
top: container.top + padding.top,
|
|
1774
|
+
bottom: container.bottom - padding.bottom
|
|
1775
|
+
};
|
|
1776
|
+
}
|
|
1762
1777
|
function getColorAlpha(color) {
|
|
1763
1778
|
const rgbaMatch = color.match(/rgba?\(([^)]+)\)/);
|
|
1764
1779
|
if (rgbaMatch) {
|
|
@@ -1989,17 +2004,8 @@ const Lightbox = ({ isOpen, onClose, content, lightboxStyles, settings, portalId
|
|
|
1989
2004
|
}
|
|
1990
2005
|
let inside;
|
|
1991
2006
|
if (isCover && imageRef.current) {
|
|
1992
|
-
const
|
|
1993
|
-
|
|
1994
|
-
const paddingTop = parseFloat(style.paddingTop) || 0;
|
|
1995
|
-
const paddingRight = parseFloat(style.paddingRight) || 0;
|
|
1996
|
-
const paddingBottom = parseFloat(style.paddingBottom) || 0;
|
|
1997
|
-
const paddingLeft = parseFloat(style.paddingLeft) || 0;
|
|
1998
|
-
const contentLeft = imgRect.left + paddingLeft;
|
|
1999
|
-
const contentRight = imgRect.right - paddingRight;
|
|
2000
|
-
const contentTop = imgRect.top + paddingTop;
|
|
2001
|
-
const contentBottom = imgRect.bottom - paddingBottom;
|
|
2002
|
-
inside = clientX >= contentLeft && clientX <= contentRight && clientY >= contentTop && clientY <= contentBottom;
|
|
2007
|
+
const bounds = getPaddedContainerBounds(imageRef.current);
|
|
2008
|
+
inside = clientX >= bounds.left && clientX <= bounds.right && clientY >= bounds.top && clientY <= bounds.bottom;
|
|
2003
2009
|
} else {
|
|
2004
2010
|
const rect = imageRef.current ? getDisplayedImageRect(imageRef.current) : null;
|
|
2005
2011
|
if (!rect) {
|
|
@@ -2096,6 +2102,9 @@ const Lightbox = ({ isOpen, onClose, content, lightboxStyles, settings, portalId
|
|
|
2096
2102
|
if (target && (target.closest(`.${classes.thumbsWrapper}`) || target.closest(`.${classes.thumbsContainer}`))) {
|
|
2097
2103
|
return;
|
|
2098
2104
|
}
|
|
2105
|
+
if (slider.type === "slide") {
|
|
2106
|
+
return;
|
|
2107
|
+
}
|
|
2099
2108
|
e.preventDefault();
|
|
2100
2109
|
};
|
|
2101
2110
|
document.addEventListener("touchmove", preventScroll, { passive: false });
|
|
@@ -2108,10 +2117,11 @@ const Lightbox = ({ isOpen, onClose, content, lightboxStyles, settings, portalId
|
|
|
2108
2117
|
}
|
|
2109
2118
|
setAnimationFinished(false);
|
|
2110
2119
|
};
|
|
2111
|
-
}, [isOpen, isEditor, area.color]);
|
|
2120
|
+
}, [isOpen, isEditor, area.color, slider.type]);
|
|
2112
2121
|
useEffect(() => {
|
|
2113
2122
|
if (!isOpen) return;
|
|
2114
2123
|
const handleTouchEnd = (e) => {
|
|
2124
|
+
var _a, _b;
|
|
2115
2125
|
if (isClosingRef.current) {
|
|
2116
2126
|
e.stopPropagation();
|
|
2117
2127
|
return;
|
|
@@ -2124,14 +2134,20 @@ const Lightbox = ({ isOpen, onClose, content, lightboxStyles, settings, portalId
|
|
|
2124
2134
|
if (target && (target.closest(`.${classes.thumbsContainer}`) || target.closest(`.${classes.thumbItem}`))) {
|
|
2125
2135
|
return;
|
|
2126
2136
|
}
|
|
2137
|
+
if (slider.type === "slide" && triggers.type === "drag" && ((_b = (_a = lightboxRef.current) == null ? void 0 : _a.splide) == null ? void 0 : _b.root)) {
|
|
2138
|
+
const splideContainer = lightboxRef.current.splide.root;
|
|
2139
|
+
if (target && (splideContainer.contains(target) || splideContainer === target)) {
|
|
2140
|
+
return;
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2127
2143
|
if (e.touches.length === 0 && e.changedTouches.length > 0) {
|
|
2128
2144
|
const currentImage = content[currentIndex];
|
|
2129
2145
|
const isCover = (currentImage == null ? void 0 : currentImage.image.objectFit) === "cover";
|
|
2130
2146
|
const touch = e.changedTouches[0];
|
|
2131
2147
|
let inside;
|
|
2132
2148
|
if (isCover && imageRef.current) {
|
|
2133
|
-
const
|
|
2134
|
-
inside = touch.clientX >=
|
|
2149
|
+
const bounds = getPaddedContainerBounds(imageRef.current);
|
|
2150
|
+
inside = touch.clientX >= bounds.left && touch.clientX <= bounds.right && touch.clientY >= bounds.top && touch.clientY <= bounds.bottom;
|
|
2135
2151
|
} else {
|
|
2136
2152
|
const rect = imageRef.current ? getDisplayedImageRect(imageRef.current) : null;
|
|
2137
2153
|
if (!rect) return;
|
|
@@ -2305,7 +2321,7 @@ const Lightbox = ({ isOpen, onClose, content, lightboxStyles, settings, portalId
|
|
|
2305
2321
|
height: "100%",
|
|
2306
2322
|
type: slider.type === "fade" || slider.type === "scale" ? "fade" : "loop",
|
|
2307
2323
|
padding: 0,
|
|
2308
|
-
rewind:
|
|
2324
|
+
rewind: triggers.repeat !== "close",
|
|
2309
2325
|
start: 0
|
|
2310
2326
|
},
|
|
2311
2327
|
style: { "--splide-speed": slider.duration },
|