@cntrl-site/components 0.1.0-alpha.30 → 0.1.0-alpha.31
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/index.js +55 -13
- package/dist/index.mjs +55 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1690,13 +1690,8 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
1690
1690
|
};
|
|
1691
1691
|
const handleImageWrapperClick = (e) => {
|
|
1692
1692
|
var _a, _b;
|
|
1693
|
-
const
|
|
1694
|
-
|
|
1695
|
-
if (e.target === e.currentTarget) {
|
|
1696
|
-
handleClose();
|
|
1697
|
-
}
|
|
1698
|
-
return;
|
|
1699
|
-
}
|
|
1693
|
+
const currentImage = content[currentIndex];
|
|
1694
|
+
const isCover = (currentImage == null ? void 0 : currentImage.image.objectFit) === "cover";
|
|
1700
1695
|
let clientX;
|
|
1701
1696
|
let clientY;
|
|
1702
1697
|
if ("changedTouches" in e && e.changedTouches.length > 0) {
|
|
@@ -1708,7 +1703,20 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
1708
1703
|
} else {
|
|
1709
1704
|
return;
|
|
1710
1705
|
}
|
|
1711
|
-
|
|
1706
|
+
let inside;
|
|
1707
|
+
if (isCover && imageRef.current) {
|
|
1708
|
+
const imgRect = imageRef.current.getBoundingClientRect();
|
|
1709
|
+
inside = clientX >= imgRect.left && clientX <= imgRect.right && clientY >= imgRect.top && clientY <= imgRect.bottom;
|
|
1710
|
+
} else {
|
|
1711
|
+
const rect = imageRef.current ? getDisplayedImageRect(imageRef.current) : null;
|
|
1712
|
+
if (!rect) {
|
|
1713
|
+
if (e.target === e.currentTarget) {
|
|
1714
|
+
handleClose();
|
|
1715
|
+
}
|
|
1716
|
+
return;
|
|
1717
|
+
}
|
|
1718
|
+
inside = clientX >= rect.x && clientX <= rect.x + rect.width && clientY >= rect.y && clientY <= rect.y + rect.height;
|
|
1719
|
+
}
|
|
1712
1720
|
if (inside) {
|
|
1713
1721
|
if (triggers.type === "click" && triggers.switch === "image") {
|
|
1714
1722
|
if (triggers.repeat === "close" && currentIndex === content.length - 1) {
|
|
@@ -1753,6 +1761,32 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
1753
1761
|
handleClose();
|
|
1754
1762
|
}
|
|
1755
1763
|
};
|
|
1764
|
+
const onImageClick = (e) => {
|
|
1765
|
+
var _a, _b;
|
|
1766
|
+
e.stopPropagation();
|
|
1767
|
+
if (triggers.type === "click" && triggers.switch === "image") {
|
|
1768
|
+
if (triggers.repeat === "close" && currentIndex === content.length - 1) {
|
|
1769
|
+
handleClose();
|
|
1770
|
+
} else {
|
|
1771
|
+
(_a = lightboxRef.current) == null ? void 0 : _a.go("+1");
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
if (triggers.type === "click" && triggers.switch === "50/50") {
|
|
1775
|
+
const img2 = e.currentTarget;
|
|
1776
|
+
const rect = img2.getBoundingClientRect();
|
|
1777
|
+
const clickX = e.clientX - rect.left;
|
|
1778
|
+
const clickY = e.clientY - rect.top;
|
|
1779
|
+
const imgWidth = rect.width;
|
|
1780
|
+
const imgHeight = rect.height;
|
|
1781
|
+
let dir;
|
|
1782
|
+
if (slider.direction === "horiz") {
|
|
1783
|
+
dir = clickX < imgWidth / 2 ? "-1" : "+1";
|
|
1784
|
+
} else {
|
|
1785
|
+
dir = clickY < imgHeight / 2 ? "-1" : "+1";
|
|
1786
|
+
}
|
|
1787
|
+
(_b = lightboxRef.current) == null ? void 0 : _b.go(dir);
|
|
1788
|
+
}
|
|
1789
|
+
};
|
|
1756
1790
|
React.useEffect(() => {
|
|
1757
1791
|
if (!isOpen) return;
|
|
1758
1792
|
const onKeyDown = (event) => {
|
|
@@ -1909,11 +1943,18 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
1909
1943
|
return;
|
|
1910
1944
|
}
|
|
1911
1945
|
if (e.touches.length === 0 && e.changedTouches.length > 0) {
|
|
1912
|
-
const
|
|
1913
|
-
|
|
1914
|
-
if (!rect) return;
|
|
1946
|
+
const currentImage = content[currentIndex];
|
|
1947
|
+
const isCover = (currentImage == null ? void 0 : currentImage.image.objectFit) === "cover";
|
|
1915
1948
|
const touch = e.changedTouches[0];
|
|
1916
|
-
|
|
1949
|
+
let inside;
|
|
1950
|
+
if (isCover && imageRef.current) {
|
|
1951
|
+
const imgRect = imageRef.current.getBoundingClientRect();
|
|
1952
|
+
inside = touch.clientX >= imgRect.left && touch.clientX <= imgRect.right && touch.clientY >= imgRect.top && touch.clientY <= imgRect.bottom;
|
|
1953
|
+
} else {
|
|
1954
|
+
const rect = imageRef.current ? getDisplayedImageRect(imageRef.current) : null;
|
|
1955
|
+
if (!rect) return;
|
|
1956
|
+
inside = touch.clientX >= rect.x && touch.clientX <= rect.x + rect.width && touch.clientY >= rect.y && touch.clientY <= rect.y + rect.height;
|
|
1957
|
+
}
|
|
1917
1958
|
if (!inside) {
|
|
1918
1959
|
e.stopPropagation();
|
|
1919
1960
|
isClosingRef.current = true;
|
|
@@ -1931,7 +1972,7 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
1931
1972
|
return () => {
|
|
1932
1973
|
document.removeEventListener("touchend", handleTouchEnd);
|
|
1933
1974
|
};
|
|
1934
|
-
}, [isOpen, handleClose, currentIndex]);
|
|
1975
|
+
}, [isOpen, handleClose, currentIndex, content]);
|
|
1935
1976
|
if (!isOpen && !isClosing) return null;
|
|
1936
1977
|
return reactDom.createPortal(
|
|
1937
1978
|
/* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
@@ -2023,6 +2064,7 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
2023
2064
|
[styles.cover]: item.image.objectFit === "cover",
|
|
2024
2065
|
[styles.scaleSlide]: slider.type === "scale"
|
|
2025
2066
|
}),
|
|
2067
|
+
onClick: item.image.objectFit !== "contain" ? onImageClick : void 0,
|
|
2026
2068
|
src: item.image.url,
|
|
2027
2069
|
alt: item.image.name ?? "",
|
|
2028
2070
|
style: {
|
package/dist/index.mjs
CHANGED
|
@@ -1688,13 +1688,8 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
1688
1688
|
};
|
|
1689
1689
|
const handleImageWrapperClick = (e) => {
|
|
1690
1690
|
var _a, _b;
|
|
1691
|
-
const
|
|
1692
|
-
|
|
1693
|
-
if (e.target === e.currentTarget) {
|
|
1694
|
-
handleClose();
|
|
1695
|
-
}
|
|
1696
|
-
return;
|
|
1697
|
-
}
|
|
1691
|
+
const currentImage = content[currentIndex];
|
|
1692
|
+
const isCover = (currentImage == null ? void 0 : currentImage.image.objectFit) === "cover";
|
|
1698
1693
|
let clientX;
|
|
1699
1694
|
let clientY;
|
|
1700
1695
|
if ("changedTouches" in e && e.changedTouches.length > 0) {
|
|
@@ -1706,7 +1701,20 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
1706
1701
|
} else {
|
|
1707
1702
|
return;
|
|
1708
1703
|
}
|
|
1709
|
-
|
|
1704
|
+
let inside;
|
|
1705
|
+
if (isCover && imageRef.current) {
|
|
1706
|
+
const imgRect = imageRef.current.getBoundingClientRect();
|
|
1707
|
+
inside = clientX >= imgRect.left && clientX <= imgRect.right && clientY >= imgRect.top && clientY <= imgRect.bottom;
|
|
1708
|
+
} else {
|
|
1709
|
+
const rect = imageRef.current ? getDisplayedImageRect(imageRef.current) : null;
|
|
1710
|
+
if (!rect) {
|
|
1711
|
+
if (e.target === e.currentTarget) {
|
|
1712
|
+
handleClose();
|
|
1713
|
+
}
|
|
1714
|
+
return;
|
|
1715
|
+
}
|
|
1716
|
+
inside = clientX >= rect.x && clientX <= rect.x + rect.width && clientY >= rect.y && clientY <= rect.y + rect.height;
|
|
1717
|
+
}
|
|
1710
1718
|
if (inside) {
|
|
1711
1719
|
if (triggers.type === "click" && triggers.switch === "image") {
|
|
1712
1720
|
if (triggers.repeat === "close" && currentIndex === content.length - 1) {
|
|
@@ -1751,6 +1759,32 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
1751
1759
|
handleClose();
|
|
1752
1760
|
}
|
|
1753
1761
|
};
|
|
1762
|
+
const onImageClick = (e) => {
|
|
1763
|
+
var _a, _b;
|
|
1764
|
+
e.stopPropagation();
|
|
1765
|
+
if (triggers.type === "click" && triggers.switch === "image") {
|
|
1766
|
+
if (triggers.repeat === "close" && currentIndex === content.length - 1) {
|
|
1767
|
+
handleClose();
|
|
1768
|
+
} else {
|
|
1769
|
+
(_a = lightboxRef.current) == null ? void 0 : _a.go("+1");
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
if (triggers.type === "click" && triggers.switch === "50/50") {
|
|
1773
|
+
const img2 = e.currentTarget;
|
|
1774
|
+
const rect = img2.getBoundingClientRect();
|
|
1775
|
+
const clickX = e.clientX - rect.left;
|
|
1776
|
+
const clickY = e.clientY - rect.top;
|
|
1777
|
+
const imgWidth = rect.width;
|
|
1778
|
+
const imgHeight = rect.height;
|
|
1779
|
+
let dir;
|
|
1780
|
+
if (slider.direction === "horiz") {
|
|
1781
|
+
dir = clickX < imgWidth / 2 ? "-1" : "+1";
|
|
1782
|
+
} else {
|
|
1783
|
+
dir = clickY < imgHeight / 2 ? "-1" : "+1";
|
|
1784
|
+
}
|
|
1785
|
+
(_b = lightboxRef.current) == null ? void 0 : _b.go(dir);
|
|
1786
|
+
}
|
|
1787
|
+
};
|
|
1754
1788
|
useEffect(() => {
|
|
1755
1789
|
if (!isOpen) return;
|
|
1756
1790
|
const onKeyDown = (event) => {
|
|
@@ -1907,11 +1941,18 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
1907
1941
|
return;
|
|
1908
1942
|
}
|
|
1909
1943
|
if (e.touches.length === 0 && e.changedTouches.length > 0) {
|
|
1910
|
-
const
|
|
1911
|
-
|
|
1912
|
-
if (!rect) return;
|
|
1944
|
+
const currentImage = content[currentIndex];
|
|
1945
|
+
const isCover = (currentImage == null ? void 0 : currentImage.image.objectFit) === "cover";
|
|
1913
1946
|
const touch = e.changedTouches[0];
|
|
1914
|
-
|
|
1947
|
+
let inside;
|
|
1948
|
+
if (isCover && imageRef.current) {
|
|
1949
|
+
const imgRect = imageRef.current.getBoundingClientRect();
|
|
1950
|
+
inside = touch.clientX >= imgRect.left && touch.clientX <= imgRect.right && touch.clientY >= imgRect.top && touch.clientY <= imgRect.bottom;
|
|
1951
|
+
} else {
|
|
1952
|
+
const rect = imageRef.current ? getDisplayedImageRect(imageRef.current) : null;
|
|
1953
|
+
if (!rect) return;
|
|
1954
|
+
inside = touch.clientX >= rect.x && touch.clientX <= rect.x + rect.width && touch.clientY >= rect.y && touch.clientY <= rect.y + rect.height;
|
|
1955
|
+
}
|
|
1915
1956
|
if (!inside) {
|
|
1916
1957
|
e.stopPropagation();
|
|
1917
1958
|
isClosingRef.current = true;
|
|
@@ -1929,7 +1970,7 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
1929
1970
|
return () => {
|
|
1930
1971
|
document.removeEventListener("touchend", handleTouchEnd);
|
|
1931
1972
|
};
|
|
1932
|
-
}, [isOpen, handleClose, currentIndex]);
|
|
1973
|
+
}, [isOpen, handleClose, currentIndex, content]);
|
|
1933
1974
|
if (!isOpen && !isClosing) return null;
|
|
1934
1975
|
return createPortal(
|
|
1935
1976
|
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
@@ -2021,6 +2062,7 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
2021
2062
|
[styles.cover]: item.image.objectFit === "cover",
|
|
2022
2063
|
[styles.scaleSlide]: slider.type === "scale"
|
|
2023
2064
|
}),
|
|
2065
|
+
onClick: item.image.objectFit !== "contain" ? onImageClick : void 0,
|
|
2024
2066
|
src: item.image.url,
|
|
2025
2067
|
alt: item.image.name ?? "",
|
|
2026
2068
|
style: {
|