@cntrl-site/components 0.1.0-alpha.27 → 0.1.0-alpha.28
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 +103 -69
- package/dist/index.mjs +103 -69
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1639,17 +1639,21 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
1639
1639
|
const [currentIndex, setCurrentIndex] = React.useState(0);
|
|
1640
1640
|
const [splideKey, setSplideKey] = React.useState(0);
|
|
1641
1641
|
const [isClosing, setIsClosing] = React.useState(false);
|
|
1642
|
-
const [imageDimensions, setImageDimensions] = React.useState({});
|
|
1643
1642
|
const lightboxRef = React.useRef(null);
|
|
1644
1643
|
const prevSliderTypeRef = React.useRef(null);
|
|
1645
1644
|
const imageRef = React.useRef(null);
|
|
1646
|
-
const imgWrapperRef = React.useRef(null);
|
|
1647
1645
|
const isClosingRef = React.useRef(false);
|
|
1648
1646
|
const contentRef = React.useRef(null);
|
|
1649
1647
|
const animationEndHandlerRef = React.useRef(null);
|
|
1648
|
+
const appearAnimationEndHandlerRef = React.useRef(null);
|
|
1650
1649
|
const { appear, triggers, slider, thumbnail, controls, area, caption: caption2, layout } = settings.lightboxBlock;
|
|
1651
1650
|
const appearDurationMs = appear.duration ? parseInt(appear.duration) : 300;
|
|
1652
1651
|
const handleClose = React.useCallback(() => {
|
|
1652
|
+
const isMobile = window.matchMedia("(max-width: 768px)").matches;
|
|
1653
|
+
const colorAlpha = getColorAlpha(area.color);
|
|
1654
|
+
if (isMobile && !isEditor && colorAlpha > 0.9) {
|
|
1655
|
+
document.body.style.backgroundColor = "";
|
|
1656
|
+
}
|
|
1653
1657
|
setIsClosing(true);
|
|
1654
1658
|
isClosingRef.current = true;
|
|
1655
1659
|
const handleAnimationEnd = (e) => {
|
|
@@ -1666,7 +1670,7 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
1666
1670
|
animationEndHandlerRef.current = handleAnimationEnd;
|
|
1667
1671
|
contentRef.current.addEventListener("animationend", handleAnimationEnd);
|
|
1668
1672
|
}
|
|
1669
|
-
}, [onClose, appearDurationMs]);
|
|
1673
|
+
}, [onClose, appearDurationMs, area.color, isEditor]);
|
|
1670
1674
|
const handleBackdropClick = (e) => {
|
|
1671
1675
|
if (!closeOnBackdropClick) return;
|
|
1672
1676
|
if (e.target === e.currentTarget) {
|
|
@@ -1674,8 +1678,52 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
1674
1678
|
}
|
|
1675
1679
|
};
|
|
1676
1680
|
const handleImageWrapperClick = (e) => {
|
|
1681
|
+
var _a, _b;
|
|
1677
1682
|
if (!closeOnBackdropClick) return;
|
|
1678
|
-
|
|
1683
|
+
const rect = imageRef.current ? getDisplayedImageRect(imageRef.current) : null;
|
|
1684
|
+
if (!rect) {
|
|
1685
|
+
if (e.target === e.currentTarget) {
|
|
1686
|
+
handleClose();
|
|
1687
|
+
}
|
|
1688
|
+
return;
|
|
1689
|
+
}
|
|
1690
|
+
let clientX;
|
|
1691
|
+
let clientY;
|
|
1692
|
+
if ("changedTouches" in e && e.changedTouches.length > 0) {
|
|
1693
|
+
clientX = e.changedTouches[0].clientX;
|
|
1694
|
+
clientY = e.changedTouches[0].clientY;
|
|
1695
|
+
} else if ("clientX" in e) {
|
|
1696
|
+
clientX = e.clientX;
|
|
1697
|
+
clientY = e.clientY;
|
|
1698
|
+
} else {
|
|
1699
|
+
return;
|
|
1700
|
+
}
|
|
1701
|
+
const inside = clientX >= rect.x && clientX <= rect.x + rect.width && clientY >= rect.y && clientY <= rect.y + rect.height;
|
|
1702
|
+
if (inside) {
|
|
1703
|
+
if (triggers.type === "click" && triggers.switch === "image") {
|
|
1704
|
+
if (triggers.repeat === "close" && currentIndex === content.length - 1) {
|
|
1705
|
+
handleClose();
|
|
1706
|
+
} else {
|
|
1707
|
+
(_a = lightboxRef.current) == null ? void 0 : _a.go("+1");
|
|
1708
|
+
}
|
|
1709
|
+
} else if (triggers.type === "click" && triggers.switch === "50/50") {
|
|
1710
|
+
const img2 = imageRef.current;
|
|
1711
|
+
if (img2) {
|
|
1712
|
+
const imgRect = img2.getBoundingClientRect();
|
|
1713
|
+
const clickX = clientX - imgRect.left;
|
|
1714
|
+
const clickY = clientY - imgRect.top;
|
|
1715
|
+
const imgWidth = imgRect.width;
|
|
1716
|
+
const imgHeight = imgRect.height;
|
|
1717
|
+
let dir;
|
|
1718
|
+
if (slider.direction === "horiz") {
|
|
1719
|
+
dir = clickX < imgWidth / 2 ? "-1" : "+1";
|
|
1720
|
+
} else {
|
|
1721
|
+
dir = clickY < imgHeight / 2 ? "-1" : "+1";
|
|
1722
|
+
}
|
|
1723
|
+
(_b = lightboxRef.current) == null ? void 0 : _b.go(dir);
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
} else {
|
|
1679
1727
|
handleClose();
|
|
1680
1728
|
}
|
|
1681
1729
|
};
|
|
@@ -1761,73 +1809,38 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
1761
1809
|
}
|
|
1762
1810
|
prevSliderTypeRef.current = slider.type;
|
|
1763
1811
|
}, [slider.type]);
|
|
1764
|
-
React.useEffect(() => {
|
|
1765
|
-
if (!imageRef.current || !imgWrapperRef.current || !isOpen) {
|
|
1766
|
-
setImageDimensions({});
|
|
1767
|
-
return;
|
|
1768
|
-
}
|
|
1769
|
-
const img2 = imageRef.current;
|
|
1770
|
-
const wrapper2 = imgWrapperRef.current;
|
|
1771
|
-
const currentItem = content[currentIndex];
|
|
1772
|
-
if ((currentItem == null ? void 0 : currentItem.image.objectFit) !== "contain") {
|
|
1773
|
-
setImageDimensions({});
|
|
1774
|
-
return;
|
|
1775
|
-
}
|
|
1776
|
-
const calculateDimensions = () => {
|
|
1777
|
-
if (!img2.naturalWidth || !img2.naturalHeight) return;
|
|
1778
|
-
const wrapperRect = wrapper2.getBoundingClientRect();
|
|
1779
|
-
const wrapperStyle = window.getComputedStyle(wrapper2);
|
|
1780
|
-
const paddingTop = parseFloat(wrapperStyle.paddingTop) || 0;
|
|
1781
|
-
const paddingRight = parseFloat(wrapperStyle.paddingRight) || 0;
|
|
1782
|
-
const paddingBottom = parseFloat(wrapperStyle.paddingBottom) || 0;
|
|
1783
|
-
const paddingLeft = parseFloat(wrapperStyle.paddingLeft) || 0;
|
|
1784
|
-
const contentWidth = wrapperRect.width - paddingLeft - paddingRight;
|
|
1785
|
-
const contentHeight = wrapperRect.height - paddingTop - paddingBottom;
|
|
1786
|
-
const containerRatio = contentWidth / contentHeight;
|
|
1787
|
-
const imgRatio = img2.naturalWidth / img2.naturalHeight;
|
|
1788
|
-
let width;
|
|
1789
|
-
let height;
|
|
1790
|
-
if (imgRatio > containerRatio) {
|
|
1791
|
-
width = contentWidth;
|
|
1792
|
-
height = contentWidth / imgRatio;
|
|
1793
|
-
} else {
|
|
1794
|
-
height = contentHeight;
|
|
1795
|
-
width = contentHeight * imgRatio;
|
|
1796
|
-
}
|
|
1797
|
-
setImageDimensions({ width, height });
|
|
1798
|
-
};
|
|
1799
|
-
if (img2.complete && img2.naturalWidth > 0) {
|
|
1800
|
-
calculateDimensions();
|
|
1801
|
-
} else {
|
|
1802
|
-
img2.onload = calculateDimensions;
|
|
1803
|
-
}
|
|
1804
|
-
const handleResize = () => calculateDimensions();
|
|
1805
|
-
window.addEventListener("resize", handleResize);
|
|
1806
|
-
return () => {
|
|
1807
|
-
window.removeEventListener("resize", handleResize);
|
|
1808
|
-
if (img2.onload) {
|
|
1809
|
-
img2.onload = null;
|
|
1810
|
-
}
|
|
1811
|
-
};
|
|
1812
|
-
}, [isOpen, currentIndex, content]);
|
|
1813
1812
|
React.useEffect(() => {
|
|
1814
1813
|
if (!isOpen) return;
|
|
1815
1814
|
const originalOverflow = document.body.style.overflow;
|
|
1816
1815
|
document.body.style.overflow = "hidden";
|
|
1817
1816
|
const isMobile = window.matchMedia("(max-width: 768px)").matches;
|
|
1818
|
-
|
|
1819
|
-
|
|
1817
|
+
const colorAlpha = getColorAlpha(area.color);
|
|
1818
|
+
const handleAppearAnimationEnd = (e) => {
|
|
1819
|
+
if (e.target === contentRef.current && !isClosingRef.current && e.animationName) {
|
|
1820
|
+
if (isMobile && !isEditor && colorAlpha > 0.9) {
|
|
1821
|
+
document.body.style.backgroundColor = area.color;
|
|
1822
|
+
}
|
|
1823
|
+
if (contentRef.current && appearAnimationEndHandlerRef.current) {
|
|
1824
|
+
contentRef.current.removeEventListener("animationend", appearAnimationEndHandlerRef.current);
|
|
1825
|
+
}
|
|
1826
|
+
appearAnimationEndHandlerRef.current = null;
|
|
1827
|
+
}
|
|
1828
|
+
};
|
|
1829
|
+
if (contentRef.current && isMobile && !isEditor && colorAlpha > 0.9) {
|
|
1830
|
+
appearAnimationEndHandlerRef.current = handleAppearAnimationEnd;
|
|
1831
|
+
contentRef.current.addEventListener("animationend", handleAppearAnimationEnd);
|
|
1820
1832
|
}
|
|
1821
1833
|
const preventScroll = (e) => e.preventDefault();
|
|
1822
1834
|
document.addEventListener("touchmove", preventScroll, { passive: false });
|
|
1823
1835
|
return () => {
|
|
1824
1836
|
document.body.style.overflow = originalOverflow;
|
|
1825
1837
|
document.removeEventListener("touchmove", preventScroll);
|
|
1826
|
-
if (
|
|
1827
|
-
|
|
1838
|
+
if (contentRef.current && appearAnimationEndHandlerRef.current) {
|
|
1839
|
+
contentRef.current.removeEventListener("animationend", appearAnimationEndHandlerRef.current);
|
|
1840
|
+
appearAnimationEndHandlerRef.current = null;
|
|
1828
1841
|
}
|
|
1829
1842
|
};
|
|
1830
|
-
}, [isOpen]);
|
|
1843
|
+
}, [isOpen, area.color, isEditor]);
|
|
1831
1844
|
const handleArrowClick = (dir) => {
|
|
1832
1845
|
var _a;
|
|
1833
1846
|
(_a = lightboxRef.current) == null ? void 0 : _a.go(dir);
|
|
@@ -1918,7 +1931,6 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
1918
1931
|
if (!rect) return;
|
|
1919
1932
|
const touch = e.changedTouches[0];
|
|
1920
1933
|
const inside = touch.clientX >= rect.x && touch.clientX <= rect.x + rect.width && touch.clientY >= rect.y && touch.clientY <= rect.y + rect.height;
|
|
1921
|
-
console.log("inside", rect.width, rect.height);
|
|
1922
1934
|
if (!inside) {
|
|
1923
1935
|
e.stopPropagation();
|
|
1924
1936
|
isClosingRef.current = true;
|
|
@@ -1979,8 +1991,7 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
1979
1991
|
animationTimingFunction: "ease",
|
|
1980
1992
|
animationFillMode: "both",
|
|
1981
1993
|
...appear.type === "mix" && !isClosing && { animationDelay: `${backdropDurationMs / 2}ms` },
|
|
1982
|
-
...appear.type === "mix" && isClosing && { animationDelay: "0ms" }
|
|
1983
|
-
"--splide-speed": slider.duration || "500ms"
|
|
1994
|
+
...appear.type === "mix" && isClosing && { animationDelay: "0ms" }
|
|
1984
1995
|
},
|
|
1985
1996
|
children: [
|
|
1986
1997
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -2017,7 +2028,6 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
2017
2028
|
return /* @__PURE__ */ jsxRuntime.jsx(reactSplide.SplideSlide, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2018
2029
|
"div",
|
|
2019
2030
|
{
|
|
2020
|
-
ref: index === currentIndex ? imgWrapperRef : null,
|
|
2021
2031
|
className: styles.imgWrapper,
|
|
2022
2032
|
onClick: handleImageWrapperClick,
|
|
2023
2033
|
style: { padding: scalingValue(layout.padding.top, isEditor) + " " + scalingValue(layout.padding.right, isEditor) + " " + scalingValue(layout.padding.bottom, isEditor) + " " + scalingValue(layout.padding.left, isEditor) },
|
|
@@ -2032,14 +2042,11 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
2032
2042
|
}),
|
|
2033
2043
|
src: item.image.url,
|
|
2034
2044
|
alt: item.image.name ?? "",
|
|
2035
|
-
onClick: onImageClick,
|
|
2045
|
+
onClick: item.image.objectFit !== "contain" ? onImageClick : void 0,
|
|
2036
2046
|
style: {
|
|
2037
2047
|
...imageStyle2,
|
|
2038
|
-
...item.image.objectFit === "contain"
|
|
2039
|
-
|
|
2040
|
-
height: `${imageDimensions.height}px`,
|
|
2041
|
-
maxWidth: "none",
|
|
2042
|
-
maxHeight: "none"
|
|
2048
|
+
...item.image.objectFit === "contain" ? {
|
|
2049
|
+
pointerEvents: "none"
|
|
2043
2050
|
} : {}
|
|
2044
2051
|
}
|
|
2045
2052
|
}
|
|
@@ -2231,6 +2238,25 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
2231
2238
|
document.getElementById(portalId)
|
|
2232
2239
|
);
|
|
2233
2240
|
};
|
|
2241
|
+
const getColorAlpha = (color) => {
|
|
2242
|
+
const rgbaMatch = color.match(/rgba?\(([^)]+)\)/);
|
|
2243
|
+
if (rgbaMatch) {
|
|
2244
|
+
const values = rgbaMatch[1].split(",").map((v) => parseFloat(v.trim()));
|
|
2245
|
+
if (values.length === 4) {
|
|
2246
|
+
return values[3];
|
|
2247
|
+
}
|
|
2248
|
+
return 1;
|
|
2249
|
+
}
|
|
2250
|
+
const hexMatch = color.match(/^#([0-9a-fA-F]{8})$/);
|
|
2251
|
+
if (hexMatch) {
|
|
2252
|
+
const alphaHex = hexMatch[1].substring(6, 8);
|
|
2253
|
+
return parseInt(alphaHex, 16) / 255;
|
|
2254
|
+
}
|
|
2255
|
+
if (color.match(/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/)) {
|
|
2256
|
+
return 1;
|
|
2257
|
+
}
|
|
2258
|
+
return 1;
|
|
2259
|
+
};
|
|
2234
2260
|
const LightboxComponent = {
|
|
2235
2261
|
element: LightboxGallery,
|
|
2236
2262
|
id: "lightbox",
|
|
@@ -2569,15 +2595,23 @@ const LightboxComponent = {
|
|
|
2569
2595
|
},
|
|
2570
2596
|
properties: {
|
|
2571
2597
|
top: {
|
|
2598
|
+
min: 0,
|
|
2599
|
+
step: 1,
|
|
2572
2600
|
type: "number"
|
|
2573
2601
|
},
|
|
2574
2602
|
left: {
|
|
2603
|
+
min: 0,
|
|
2604
|
+
step: 1,
|
|
2575
2605
|
type: "number"
|
|
2576
2606
|
},
|
|
2577
2607
|
right: {
|
|
2608
|
+
min: 0,
|
|
2609
|
+
step: 1,
|
|
2578
2610
|
type: "number"
|
|
2579
2611
|
},
|
|
2580
2612
|
bottom: {
|
|
2613
|
+
min: 0,
|
|
2614
|
+
step: 1,
|
|
2581
2615
|
type: "number"
|
|
2582
2616
|
}
|
|
2583
2617
|
}
|
|
@@ -2833,7 +2867,7 @@ const LightboxComponent = {
|
|
|
2833
2867
|
layout: {
|
|
2834
2868
|
position: "middle-center",
|
|
2835
2869
|
offset: { x: 0, y: 0 },
|
|
2836
|
-
padding: { top: 0, right: 0, bottom: 0, left: 0 }
|
|
2870
|
+
padding: { top: 0.04, right: 0, bottom: 0.04, left: 0 }
|
|
2837
2871
|
},
|
|
2838
2872
|
controls: {
|
|
2839
2873
|
isActive: true,
|
package/dist/index.mjs
CHANGED
|
@@ -1637,17 +1637,21 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
1637
1637
|
const [currentIndex, setCurrentIndex] = React.useState(0);
|
|
1638
1638
|
const [splideKey, setSplideKey] = React.useState(0);
|
|
1639
1639
|
const [isClosing, setIsClosing] = React.useState(false);
|
|
1640
|
-
const [imageDimensions, setImageDimensions] = React.useState({});
|
|
1641
1640
|
const lightboxRef = useRef(null);
|
|
1642
1641
|
const prevSliderTypeRef = useRef(null);
|
|
1643
1642
|
const imageRef = useRef(null);
|
|
1644
|
-
const imgWrapperRef = useRef(null);
|
|
1645
1643
|
const isClosingRef = useRef(false);
|
|
1646
1644
|
const contentRef = useRef(null);
|
|
1647
1645
|
const animationEndHandlerRef = useRef(null);
|
|
1646
|
+
const appearAnimationEndHandlerRef = useRef(null);
|
|
1648
1647
|
const { appear, triggers, slider, thumbnail, controls, area, caption: caption2, layout } = settings.lightboxBlock;
|
|
1649
1648
|
const appearDurationMs = appear.duration ? parseInt(appear.duration) : 300;
|
|
1650
1649
|
const handleClose = useCallback(() => {
|
|
1650
|
+
const isMobile = window.matchMedia("(max-width: 768px)").matches;
|
|
1651
|
+
const colorAlpha = getColorAlpha(area.color);
|
|
1652
|
+
if (isMobile && !isEditor && colorAlpha > 0.9) {
|
|
1653
|
+
document.body.style.backgroundColor = "";
|
|
1654
|
+
}
|
|
1651
1655
|
setIsClosing(true);
|
|
1652
1656
|
isClosingRef.current = true;
|
|
1653
1657
|
const handleAnimationEnd = (e) => {
|
|
@@ -1664,7 +1668,7 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
1664
1668
|
animationEndHandlerRef.current = handleAnimationEnd;
|
|
1665
1669
|
contentRef.current.addEventListener("animationend", handleAnimationEnd);
|
|
1666
1670
|
}
|
|
1667
|
-
}, [onClose, appearDurationMs]);
|
|
1671
|
+
}, [onClose, appearDurationMs, area.color, isEditor]);
|
|
1668
1672
|
const handleBackdropClick = (e) => {
|
|
1669
1673
|
if (!closeOnBackdropClick) return;
|
|
1670
1674
|
if (e.target === e.currentTarget) {
|
|
@@ -1672,8 +1676,52 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
1672
1676
|
}
|
|
1673
1677
|
};
|
|
1674
1678
|
const handleImageWrapperClick = (e) => {
|
|
1679
|
+
var _a, _b;
|
|
1675
1680
|
if (!closeOnBackdropClick) return;
|
|
1676
|
-
|
|
1681
|
+
const rect = imageRef.current ? getDisplayedImageRect(imageRef.current) : null;
|
|
1682
|
+
if (!rect) {
|
|
1683
|
+
if (e.target === e.currentTarget) {
|
|
1684
|
+
handleClose();
|
|
1685
|
+
}
|
|
1686
|
+
return;
|
|
1687
|
+
}
|
|
1688
|
+
let clientX;
|
|
1689
|
+
let clientY;
|
|
1690
|
+
if ("changedTouches" in e && e.changedTouches.length > 0) {
|
|
1691
|
+
clientX = e.changedTouches[0].clientX;
|
|
1692
|
+
clientY = e.changedTouches[0].clientY;
|
|
1693
|
+
} else if ("clientX" in e) {
|
|
1694
|
+
clientX = e.clientX;
|
|
1695
|
+
clientY = e.clientY;
|
|
1696
|
+
} else {
|
|
1697
|
+
return;
|
|
1698
|
+
}
|
|
1699
|
+
const inside = clientX >= rect.x && clientX <= rect.x + rect.width && clientY >= rect.y && clientY <= rect.y + rect.height;
|
|
1700
|
+
if (inside) {
|
|
1701
|
+
if (triggers.type === "click" && triggers.switch === "image") {
|
|
1702
|
+
if (triggers.repeat === "close" && currentIndex === content.length - 1) {
|
|
1703
|
+
handleClose();
|
|
1704
|
+
} else {
|
|
1705
|
+
(_a = lightboxRef.current) == null ? void 0 : _a.go("+1");
|
|
1706
|
+
}
|
|
1707
|
+
} else if (triggers.type === "click" && triggers.switch === "50/50") {
|
|
1708
|
+
const img2 = imageRef.current;
|
|
1709
|
+
if (img2) {
|
|
1710
|
+
const imgRect = img2.getBoundingClientRect();
|
|
1711
|
+
const clickX = clientX - imgRect.left;
|
|
1712
|
+
const clickY = clientY - imgRect.top;
|
|
1713
|
+
const imgWidth = imgRect.width;
|
|
1714
|
+
const imgHeight = imgRect.height;
|
|
1715
|
+
let dir;
|
|
1716
|
+
if (slider.direction === "horiz") {
|
|
1717
|
+
dir = clickX < imgWidth / 2 ? "-1" : "+1";
|
|
1718
|
+
} else {
|
|
1719
|
+
dir = clickY < imgHeight / 2 ? "-1" : "+1";
|
|
1720
|
+
}
|
|
1721
|
+
(_b = lightboxRef.current) == null ? void 0 : _b.go(dir);
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
} else {
|
|
1677
1725
|
handleClose();
|
|
1678
1726
|
}
|
|
1679
1727
|
};
|
|
@@ -1759,73 +1807,38 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
1759
1807
|
}
|
|
1760
1808
|
prevSliderTypeRef.current = slider.type;
|
|
1761
1809
|
}, [slider.type]);
|
|
1762
|
-
useEffect(() => {
|
|
1763
|
-
if (!imageRef.current || !imgWrapperRef.current || !isOpen) {
|
|
1764
|
-
setImageDimensions({});
|
|
1765
|
-
return;
|
|
1766
|
-
}
|
|
1767
|
-
const img2 = imageRef.current;
|
|
1768
|
-
const wrapper2 = imgWrapperRef.current;
|
|
1769
|
-
const currentItem = content[currentIndex];
|
|
1770
|
-
if ((currentItem == null ? void 0 : currentItem.image.objectFit) !== "contain") {
|
|
1771
|
-
setImageDimensions({});
|
|
1772
|
-
return;
|
|
1773
|
-
}
|
|
1774
|
-
const calculateDimensions = () => {
|
|
1775
|
-
if (!img2.naturalWidth || !img2.naturalHeight) return;
|
|
1776
|
-
const wrapperRect = wrapper2.getBoundingClientRect();
|
|
1777
|
-
const wrapperStyle = window.getComputedStyle(wrapper2);
|
|
1778
|
-
const paddingTop = parseFloat(wrapperStyle.paddingTop) || 0;
|
|
1779
|
-
const paddingRight = parseFloat(wrapperStyle.paddingRight) || 0;
|
|
1780
|
-
const paddingBottom = parseFloat(wrapperStyle.paddingBottom) || 0;
|
|
1781
|
-
const paddingLeft = parseFloat(wrapperStyle.paddingLeft) || 0;
|
|
1782
|
-
const contentWidth = wrapperRect.width - paddingLeft - paddingRight;
|
|
1783
|
-
const contentHeight = wrapperRect.height - paddingTop - paddingBottom;
|
|
1784
|
-
const containerRatio = contentWidth / contentHeight;
|
|
1785
|
-
const imgRatio = img2.naturalWidth / img2.naturalHeight;
|
|
1786
|
-
let width;
|
|
1787
|
-
let height;
|
|
1788
|
-
if (imgRatio > containerRatio) {
|
|
1789
|
-
width = contentWidth;
|
|
1790
|
-
height = contentWidth / imgRatio;
|
|
1791
|
-
} else {
|
|
1792
|
-
height = contentHeight;
|
|
1793
|
-
width = contentHeight * imgRatio;
|
|
1794
|
-
}
|
|
1795
|
-
setImageDimensions({ width, height });
|
|
1796
|
-
};
|
|
1797
|
-
if (img2.complete && img2.naturalWidth > 0) {
|
|
1798
|
-
calculateDimensions();
|
|
1799
|
-
} else {
|
|
1800
|
-
img2.onload = calculateDimensions;
|
|
1801
|
-
}
|
|
1802
|
-
const handleResize = () => calculateDimensions();
|
|
1803
|
-
window.addEventListener("resize", handleResize);
|
|
1804
|
-
return () => {
|
|
1805
|
-
window.removeEventListener("resize", handleResize);
|
|
1806
|
-
if (img2.onload) {
|
|
1807
|
-
img2.onload = null;
|
|
1808
|
-
}
|
|
1809
|
-
};
|
|
1810
|
-
}, [isOpen, currentIndex, content]);
|
|
1811
1810
|
useEffect(() => {
|
|
1812
1811
|
if (!isOpen) return;
|
|
1813
1812
|
const originalOverflow = document.body.style.overflow;
|
|
1814
1813
|
document.body.style.overflow = "hidden";
|
|
1815
1814
|
const isMobile = window.matchMedia("(max-width: 768px)").matches;
|
|
1816
|
-
|
|
1817
|
-
|
|
1815
|
+
const colorAlpha = getColorAlpha(area.color);
|
|
1816
|
+
const handleAppearAnimationEnd = (e) => {
|
|
1817
|
+
if (e.target === contentRef.current && !isClosingRef.current && e.animationName) {
|
|
1818
|
+
if (isMobile && !isEditor && colorAlpha > 0.9) {
|
|
1819
|
+
document.body.style.backgroundColor = area.color;
|
|
1820
|
+
}
|
|
1821
|
+
if (contentRef.current && appearAnimationEndHandlerRef.current) {
|
|
1822
|
+
contentRef.current.removeEventListener("animationend", appearAnimationEndHandlerRef.current);
|
|
1823
|
+
}
|
|
1824
|
+
appearAnimationEndHandlerRef.current = null;
|
|
1825
|
+
}
|
|
1826
|
+
};
|
|
1827
|
+
if (contentRef.current && isMobile && !isEditor && colorAlpha > 0.9) {
|
|
1828
|
+
appearAnimationEndHandlerRef.current = handleAppearAnimationEnd;
|
|
1829
|
+
contentRef.current.addEventListener("animationend", handleAppearAnimationEnd);
|
|
1818
1830
|
}
|
|
1819
1831
|
const preventScroll = (e) => e.preventDefault();
|
|
1820
1832
|
document.addEventListener("touchmove", preventScroll, { passive: false });
|
|
1821
1833
|
return () => {
|
|
1822
1834
|
document.body.style.overflow = originalOverflow;
|
|
1823
1835
|
document.removeEventListener("touchmove", preventScroll);
|
|
1824
|
-
if (
|
|
1825
|
-
|
|
1836
|
+
if (contentRef.current && appearAnimationEndHandlerRef.current) {
|
|
1837
|
+
contentRef.current.removeEventListener("animationend", appearAnimationEndHandlerRef.current);
|
|
1838
|
+
appearAnimationEndHandlerRef.current = null;
|
|
1826
1839
|
}
|
|
1827
1840
|
};
|
|
1828
|
-
}, [isOpen]);
|
|
1841
|
+
}, [isOpen, area.color, isEditor]);
|
|
1829
1842
|
const handleArrowClick = (dir) => {
|
|
1830
1843
|
var _a;
|
|
1831
1844
|
(_a = lightboxRef.current) == null ? void 0 : _a.go(dir);
|
|
@@ -1916,7 +1929,6 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
1916
1929
|
if (!rect) return;
|
|
1917
1930
|
const touch = e.changedTouches[0];
|
|
1918
1931
|
const inside = touch.clientX >= rect.x && touch.clientX <= rect.x + rect.width && touch.clientY >= rect.y && touch.clientY <= rect.y + rect.height;
|
|
1919
|
-
console.log("inside", rect.width, rect.height);
|
|
1920
1932
|
if (!inside) {
|
|
1921
1933
|
e.stopPropagation();
|
|
1922
1934
|
isClosingRef.current = true;
|
|
@@ -1977,8 +1989,7 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
1977
1989
|
animationTimingFunction: "ease",
|
|
1978
1990
|
animationFillMode: "both",
|
|
1979
1991
|
...appear.type === "mix" && !isClosing && { animationDelay: `${backdropDurationMs / 2}ms` },
|
|
1980
|
-
...appear.type === "mix" && isClosing && { animationDelay: "0ms" }
|
|
1981
|
-
"--splide-speed": slider.duration || "500ms"
|
|
1992
|
+
...appear.type === "mix" && isClosing && { animationDelay: "0ms" }
|
|
1982
1993
|
},
|
|
1983
1994
|
children: [
|
|
1984
1995
|
/* @__PURE__ */ jsx(
|
|
@@ -2015,7 +2026,6 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
2015
2026
|
return /* @__PURE__ */ jsx(SplideSlide, { children: /* @__PURE__ */ jsx(
|
|
2016
2027
|
"div",
|
|
2017
2028
|
{
|
|
2018
|
-
ref: index === currentIndex ? imgWrapperRef : null,
|
|
2019
2029
|
className: styles.imgWrapper,
|
|
2020
2030
|
onClick: handleImageWrapperClick,
|
|
2021
2031
|
style: { padding: scalingValue(layout.padding.top, isEditor) + " " + scalingValue(layout.padding.right, isEditor) + " " + scalingValue(layout.padding.bottom, isEditor) + " " + scalingValue(layout.padding.left, isEditor) },
|
|
@@ -2030,14 +2040,11 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
2030
2040
|
}),
|
|
2031
2041
|
src: item.image.url,
|
|
2032
2042
|
alt: item.image.name ?? "",
|
|
2033
|
-
onClick: onImageClick,
|
|
2043
|
+
onClick: item.image.objectFit !== "contain" ? onImageClick : void 0,
|
|
2034
2044
|
style: {
|
|
2035
2045
|
...imageStyle2,
|
|
2036
|
-
...item.image.objectFit === "contain"
|
|
2037
|
-
|
|
2038
|
-
height: `${imageDimensions.height}px`,
|
|
2039
|
-
maxWidth: "none",
|
|
2040
|
-
maxHeight: "none"
|
|
2046
|
+
...item.image.objectFit === "contain" ? {
|
|
2047
|
+
pointerEvents: "none"
|
|
2041
2048
|
} : {}
|
|
2042
2049
|
}
|
|
2043
2050
|
}
|
|
@@ -2229,6 +2236,25 @@ const Lightbox = ({ isOpen, onClose, content, styles: lightboxStyles, settings,
|
|
|
2229
2236
|
document.getElementById(portalId)
|
|
2230
2237
|
);
|
|
2231
2238
|
};
|
|
2239
|
+
const getColorAlpha = (color) => {
|
|
2240
|
+
const rgbaMatch = color.match(/rgba?\(([^)]+)\)/);
|
|
2241
|
+
if (rgbaMatch) {
|
|
2242
|
+
const values = rgbaMatch[1].split(",").map((v) => parseFloat(v.trim()));
|
|
2243
|
+
if (values.length === 4) {
|
|
2244
|
+
return values[3];
|
|
2245
|
+
}
|
|
2246
|
+
return 1;
|
|
2247
|
+
}
|
|
2248
|
+
const hexMatch = color.match(/^#([0-9a-fA-F]{8})$/);
|
|
2249
|
+
if (hexMatch) {
|
|
2250
|
+
const alphaHex = hexMatch[1].substring(6, 8);
|
|
2251
|
+
return parseInt(alphaHex, 16) / 255;
|
|
2252
|
+
}
|
|
2253
|
+
if (color.match(/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/)) {
|
|
2254
|
+
return 1;
|
|
2255
|
+
}
|
|
2256
|
+
return 1;
|
|
2257
|
+
};
|
|
2232
2258
|
const LightboxComponent = {
|
|
2233
2259
|
element: LightboxGallery,
|
|
2234
2260
|
id: "lightbox",
|
|
@@ -2567,15 +2593,23 @@ const LightboxComponent = {
|
|
|
2567
2593
|
},
|
|
2568
2594
|
properties: {
|
|
2569
2595
|
top: {
|
|
2596
|
+
min: 0,
|
|
2597
|
+
step: 1,
|
|
2570
2598
|
type: "number"
|
|
2571
2599
|
},
|
|
2572
2600
|
left: {
|
|
2601
|
+
min: 0,
|
|
2602
|
+
step: 1,
|
|
2573
2603
|
type: "number"
|
|
2574
2604
|
},
|
|
2575
2605
|
right: {
|
|
2606
|
+
min: 0,
|
|
2607
|
+
step: 1,
|
|
2576
2608
|
type: "number"
|
|
2577
2609
|
},
|
|
2578
2610
|
bottom: {
|
|
2611
|
+
min: 0,
|
|
2612
|
+
step: 1,
|
|
2579
2613
|
type: "number"
|
|
2580
2614
|
}
|
|
2581
2615
|
}
|
|
@@ -2831,7 +2865,7 @@ const LightboxComponent = {
|
|
|
2831
2865
|
layout: {
|
|
2832
2866
|
position: "middle-center",
|
|
2833
2867
|
offset: { x: 0, y: 0 },
|
|
2834
|
-
padding: { top: 0, right: 0, bottom: 0, left: 0 }
|
|
2868
|
+
padding: { top: 0.04, right: 0, bottom: 0.04, left: 0 }
|
|
2835
2869
|
},
|
|
2836
2870
|
controls: {
|
|
2837
2871
|
isActive: true,
|