@cntrl-site/sdk-nextjs 1.8.19-alpha.1 → 1.8.19-alpha.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.
|
Binary file
|
|
@@ -12,45 +12,40 @@ const SectionVideo = ({ container, sectionId, media }) => {
|
|
|
12
12
|
const { url, size, position, offsetX, coverUrl, play } = media;
|
|
13
13
|
const id = (0, react_1.useId)();
|
|
14
14
|
const [isPlaying, setIsPlaying] = (0, react_1.useState)(false);
|
|
15
|
+
const [userPaused, setUserPaused] = (0, react_1.useState)(false);
|
|
16
|
+
const [isClickedOnCover, setIsClickedOnCover] = (0, react_1.useState)(false);
|
|
15
17
|
const handleCoverClick = () => {
|
|
16
18
|
if (!video || play !== 'on-click')
|
|
17
19
|
return;
|
|
20
|
+
setIsClickedOnCover(true);
|
|
18
21
|
if (isPlaying) {
|
|
19
22
|
video.pause();
|
|
23
|
+
setUserPaused(true);
|
|
20
24
|
}
|
|
21
25
|
else {
|
|
22
26
|
video.play();
|
|
27
|
+
setUserPaused(false);
|
|
23
28
|
}
|
|
24
29
|
};
|
|
25
30
|
(0, react_1.useEffect)(() => {
|
|
26
|
-
if (!video || play !== '
|
|
31
|
+
if (!video || play !== 'on-click')
|
|
27
32
|
return;
|
|
28
33
|
const observer = new IntersectionObserver(([entry]) => {
|
|
34
|
+
if (userPaused || !isClickedOnCover)
|
|
35
|
+
return;
|
|
29
36
|
if (entry.isIntersecting) {
|
|
30
|
-
video.
|
|
31
|
-
video.play().catch(() => { });
|
|
37
|
+
video.play();
|
|
32
38
|
}
|
|
33
39
|
else {
|
|
34
|
-
video.style.display = 'none';
|
|
35
40
|
video.pause();
|
|
36
41
|
}
|
|
37
|
-
}, {
|
|
38
|
-
root: null,
|
|
39
|
-
rootMargin: '50px',
|
|
40
|
-
threshold: 0
|
|
41
42
|
});
|
|
42
43
|
observer.observe(container);
|
|
43
44
|
return () => observer.disconnect();
|
|
44
|
-
}, [container, play]);
|
|
45
|
-
(0, react_1.useEffect)(() => {
|
|
46
|
-
if (!video || play !== 'on-click')
|
|
47
|
-
return;
|
|
48
|
-
video.currentTime = 0.01;
|
|
49
|
-
video.pause();
|
|
50
|
-
}, [play]);
|
|
45
|
+
}, [container, play, userPaused, isClickedOnCover]);
|
|
51
46
|
const isContainHeight = size === 'contain-height';
|
|
52
47
|
const hasOffsetX = offsetX !== null && size === 'contain';
|
|
53
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("video", { ref: setVideo, autoPlay: play === 'auto', loop: true, style: { opacity: !isPlaying && play === 'on-click' ? 0 : 1 }, controls: false, muted: play === 'auto', playsInline: true, preload: "auto", className: `video-background-${sectionId}`, onPlay: () => setIsPlaying(true), onPause: () => setIsPlaying(false), children: (0, jsx_runtime_1.jsx)("source", { src: `${url}#t=0.001` }) }), (0, jsx_runtime_1.jsx)("div", { className: `video-background-${sectionId}-cover-container`, onClick: handleCoverClick, children: coverUrl && play === 'on-click' && ((0, jsx_runtime_1.jsx)("img", { src: coverUrl, alt: "Video cover", className: `video-background-${sectionId}-cover`, style: { opacity: isPlaying ? 0 : 1 } })) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
48
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("video", { ref: setVideo, autoPlay: play === 'auto', loop: true, style: { opacity: !isPlaying && play === 'on-click' && coverUrl ? 0 : 1 }, controls: false, muted: play === 'auto', playsInline: true, preload: "auto", className: `video-background-${sectionId}`, onPlay: () => setIsPlaying(true), onPause: () => setIsPlaying(false), children: (0, jsx_runtime_1.jsx)("source", { src: `${url}#t=0.001` }) }), (0, jsx_runtime_1.jsx)("div", { className: `video-background-${sectionId}-cover-container`, onClick: handleCoverClick, children: coverUrl && play === 'on-click' && ((0, jsx_runtime_1.jsx)("img", { src: coverUrl, alt: "Video cover", className: `video-background-${sectionId}-cover`, style: { opacity: isPlaying ? 0 : 1 } })) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
54
49
|
.video-background-${sectionId}-cover-container {
|
|
55
50
|
position: absolute;
|
|
56
51
|
pointer-events: ${play === 'on-click' ? 'auto' : 'none'};
|
package/package.json
CHANGED
|
@@ -22,43 +22,36 @@ export const SectionVideo: FC<Props> = ({ container, sectionId, media }) => {
|
|
|
22
22
|
const { url, size, position, offsetX, coverUrl, play } = media;
|
|
23
23
|
const id = useId();
|
|
24
24
|
const [isPlaying, setIsPlaying] = useState(false);
|
|
25
|
+
const [userPaused, setUserPaused] = useState(false);
|
|
26
|
+
const [isClickedOnCover, setIsClickedOnCover] = useState(false);
|
|
25
27
|
|
|
26
28
|
const handleCoverClick = () => {
|
|
27
29
|
if (!video || play !== 'on-click') return;
|
|
30
|
+
setIsClickedOnCover(true);
|
|
28
31
|
if (isPlaying) {
|
|
29
32
|
video.pause();
|
|
33
|
+
setUserPaused(true);
|
|
30
34
|
} else {
|
|
31
35
|
video.play();
|
|
36
|
+
setUserPaused(false);
|
|
32
37
|
}
|
|
33
38
|
};
|
|
34
39
|
|
|
35
40
|
useEffect(() => {
|
|
36
|
-
if (!video || play !== '
|
|
41
|
+
if (!video || play !== 'on-click') return;
|
|
37
42
|
const observer = new IntersectionObserver(
|
|
38
43
|
([entry]) => {
|
|
44
|
+
if (userPaused || !isClickedOnCover) return;
|
|
39
45
|
if (entry.isIntersecting) {
|
|
40
|
-
video.
|
|
41
|
-
video.play().catch(() => {});
|
|
46
|
+
video.play();
|
|
42
47
|
} else {
|
|
43
|
-
video.style.display = 'none';
|
|
44
48
|
video.pause();
|
|
45
49
|
}
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
root: null,
|
|
49
|
-
rootMargin: '50px',
|
|
50
|
-
threshold: 0
|
|
51
50
|
}
|
|
52
51
|
);
|
|
53
52
|
observer.observe(container);
|
|
54
53
|
return () => observer.disconnect();
|
|
55
|
-
}, [container, play]);
|
|
56
|
-
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
if (!video || play !== 'on-click') return;
|
|
59
|
-
video.currentTime = 0.01;
|
|
60
|
-
video.pause();
|
|
61
|
-
}, [play]);
|
|
54
|
+
}, [container, play, userPaused, isClickedOnCover]);
|
|
62
55
|
|
|
63
56
|
const isContainHeight = size === 'contain-height';
|
|
64
57
|
const hasOffsetX = offsetX !== null && size === 'contain';
|
|
@@ -69,7 +62,7 @@ export const SectionVideo: FC<Props> = ({ container, sectionId, media }) => {
|
|
|
69
62
|
ref={setVideo}
|
|
70
63
|
autoPlay={play === 'auto'}
|
|
71
64
|
loop
|
|
72
|
-
style={{ opacity: !isPlaying && play === 'on-click' ? 0 : 1 }}
|
|
65
|
+
style={{ opacity: !isPlaying && play === 'on-click' && coverUrl ? 0 : 1 }}
|
|
73
66
|
controls={false}
|
|
74
67
|
muted={play === 'auto'}
|
|
75
68
|
playsInline
|