@cntrl-site/sdk-nextjs 1.0.19-alpha.2 → 1.0.19-alpha.4
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/lib/components/Article.js +1 -1
- package/lib/components/Item.js +31 -36
- package/lib/components/items/CodeEmbedItem.js +11 -15
- package/lib/components/items/CustomItem.js +7 -12
- package/lib/components/items/GroupItem.js +11 -15
- package/lib/components/items/ImageItem.js +21 -24
- package/lib/components/items/RectangleItem.js +24 -18
- package/lib/components/items/RichTextItem.js +19 -14
- package/lib/components/items/VideoItem.js +22 -23
- package/lib/components/items/VimeoEmbed.js +16 -22
- package/lib/components/items/YoutubeEmbed.js +16 -23
- package/lib/components/useItemPosition.js +10 -5
- package/lib/interactions/CSSPropertyNameMap.js +38 -0
- package/lib/interactions/InteractionsRegistry.js +158 -0
- package/lib/interactions/ItemInteractionCtrl.js +55 -0
- package/lib/interactions/getTransition.js +21 -0
- package/lib/interactions/types.js +2 -0
- package/lib/interactions/useItemInteractionCtrl.js +17 -0
- package/lib/provider/InteractionsContext.js +17 -39
- package/lib/utils/getStyleFromItemStateAndParams.js +9 -0
- package/package.json +1 -1
- package/src/components/Article.tsx +2 -2
- package/src/components/Item.tsx +40 -34
- package/src/components/items/CodeEmbedItem.tsx +11 -14
- package/src/components/items/CustomItem.tsx +8 -13
- package/src/components/items/GroupItem.tsx +12 -14
- package/src/components/items/ImageItem.tsx +29 -25
- package/src/components/items/RectangleItem.tsx +30 -16
- package/src/components/items/RichTextItem.tsx +26 -20
- package/src/components/items/VideoItem.tsx +31 -25
- package/src/components/items/VimeoEmbed.tsx +21 -21
- package/src/components/items/YoutubeEmbed.tsx +17 -23
- package/src/components/useItemPosition.ts +12 -5
- package/src/interactions/CSSPropertyNameMap.ts +38 -0
- package/src/interactions/InteractionsRegistry.ts +193 -0
- package/src/interactions/ItemInteractionCtrl.ts +56 -0
- package/src/interactions/getTransition.ts +27 -0
- package/src/interactions/types.ts +32 -0
- package/src/interactions/useItemInteractionCtrl.ts +18 -0
- package/src/provider/InteractionsContext.old.tsx +65 -0
- package/src/provider/InteractionsContext.test.tsx +7 -7
- package/src/provider/InteractionsContext.tsx +17 -54
- package/src/utils/getStyleFromItemStateAndParams.ts +8 -0
- package/lib/components/useStatesClassNames.js +0 -18
- package/lib/components/useStatesTransitions.js +0 -89
- package/lib/utils/StateStyles/StateStyles.js +0 -89
- package/lib/utils/getStatesCSS.js +0 -16
- package/src/components/useStatesClassNames.ts +0 -23
- package/src/components/useStatesTransitions.ts +0 -95
- package/src/utils/StateStyles/StateStyles.ts +0 -99
- package/src/utils/getStatesCSS.ts +0 -24
|
@@ -16,29 +16,34 @@ const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
|
16
16
|
const useRegisterResize_1 = require("../../common/useRegisterResize");
|
|
17
17
|
const useLayoutContext_1 = require("../useLayoutContext");
|
|
18
18
|
const ScrollPlaybackVideo_1 = require("../ScrollPlaybackVideo");
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const VideoItem = ({ item, sectionId, onResize }) => {
|
|
23
|
-
var _a, _b, _c;
|
|
19
|
+
const getStyleFromItemStateAndParams_1 = require("../../utils/getStyleFromItemStateAndParams");
|
|
20
|
+
const VideoItem = ({ item, sectionId, onResize, interactionCtrl }) => {
|
|
21
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
24
22
|
const id = (0, react_1.useId)();
|
|
25
23
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
26
|
-
const { radius, strokeWidth, strokeColor, opacity, blur } = (0, useFileItem_1.useFileItem)(item, sectionId);
|
|
27
|
-
const
|
|
28
|
-
const borderColor = (0, react_1.useMemo)(() => strokeColor ? color_1.CntrlColor.parse(strokeColor) : undefined, [strokeColor]);
|
|
24
|
+
const { radius: itemRadius, strokeWidth: itemStrokeWidth, strokeColor: itemStrokeColor, opacity: itemOpacity, blur: itemBlur } = (0, useFileItem_1.useFileItem)(item, sectionId);
|
|
25
|
+
const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
29
26
|
const [ref, setRef] = (0, react_1.useState)(null);
|
|
30
27
|
const videoRef = (0, react_1.useRef)(null);
|
|
31
28
|
const layoutId = (0, useLayoutContext_1.useLayoutContext)();
|
|
32
29
|
const scrollPlayback = layoutId ? item.layoutParams[layoutId].scrollPlayback : null;
|
|
33
|
-
const layoutValues = [item.area, item.layoutParams
|
|
34
|
-
const statesWrapperClassNames = (0, useStatesClassNames_1.useStatesClassNames)(item.id, item.state, 'video-wrapper');
|
|
35
|
-
const statesVideoClassNames = (0, useStatesClassNames_1.useStatesClassNames)(item.id, item.state, 'video');
|
|
30
|
+
const layoutValues = [item.area, item.layoutParams];
|
|
36
31
|
const hasScrollPlayback = scrollPlayback !== null;
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
const wrapperStateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['angle', 'opacity', 'blur']);
|
|
33
|
+
const videoStateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['strokeWidth', 'radius', 'strokeColor']);
|
|
34
|
+
const borderColor = (0, react_1.useMemo)(() => {
|
|
35
|
+
var _a;
|
|
36
|
+
const strokeColor = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_a = videoStateParams === null || videoStateParams === void 0 ? void 0 : videoStateParams.styles) === null || _a === void 0 ? void 0 : _a.color, itemStrokeColor);
|
|
37
|
+
return strokeColor ? color_1.CntrlColor.parse(strokeColor) : undefined;
|
|
38
|
+
}, [(_a = videoStateParams === null || videoStateParams === void 0 ? void 0 : videoStateParams.styles) === null || _a === void 0 ? void 0 : _a.color, itemStrokeColor]);
|
|
39
|
+
const angle = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_b = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _b === void 0 ? void 0 : _b.angle, itemAngle);
|
|
40
|
+
const opacity = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_c = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _c === void 0 ? void 0 : _c.opacity, itemOpacity);
|
|
41
|
+
const blur = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_d = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _d === void 0 ? void 0 : _d.blur, itemBlur);
|
|
42
|
+
const strokeWidth = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_e = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _e === void 0 ? void 0 : _e.strokeWidth, itemStrokeWidth);
|
|
43
|
+
const radius = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_f = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _f === void 0 ? void 0 : _f.radius, itemRadius);
|
|
39
44
|
(0, useRegisterResize_1.useRegisterResize)(ref, onResize);
|
|
40
|
-
const inlineStyles = Object.assign(Object.assign(Object.assign({}, (radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {})), (strokeWidth !== undefined ? { borderWidth: `${strokeWidth * 100}vw` } : {})), (borderColor ? { borderColor: `${borderColor.toCss()}` } : {}));
|
|
41
|
-
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: (
|
|
45
|
+
const inlineStyles = Object.assign(Object.assign(Object.assign(Object.assign({}, (radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {})), (strokeWidth !== undefined ? { borderWidth: `${strokeWidth * 100}vw` } : {})), (borderColor ? { borderColor: `${borderColor.toCss()}` } : {})), { transition: (_g = videoStateParams === null || videoStateParams === void 0 ? void 0 : videoStateParams.transition) !== null && _g !== void 0 ? _g : 'none' });
|
|
46
|
+
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: (_h = item.link) === null || _h === void 0 ? void 0 : _h.url, target: (_j = item.link) === null || _j === void 0 ? void 0 : _j.target, children: [(0, jsx_runtime_1.jsx)("div", { className: `video-wrapper-${item.id}`, ref: setRef, style: Object.assign(Object.assign(Object.assign(Object.assign({}, (opacity !== undefined ? { opacity } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), { transition: (_k = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.transition) !== null && _k !== void 0 ? _k : 'none' }), children: hasScrollPlayback ? ((0, jsx_runtime_1.jsx)(ScrollPlaybackVideo_1.ScrollPlaybackVideo, { sectionId: sectionId, src: item.commonParams.url, playbackParams: scrollPlayback, style: inlineStyles, className: `video video-playback-wrapper video-${item.id}` })) : ((0, jsx_runtime_1.jsx)("video", { poster: (_l = item.commonParams.coverUrl) !== null && _l !== void 0 ? _l : '', ref: videoRef, autoPlay: true, muted: true, loop: true, playsInline: true, className: `video video-${item.id}`, style: inlineStyles, children: (0, jsx_runtime_1.jsx)("source", { src: item.commonParams.url }) })) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
42
47
|
.video-wrapper-${item.id} {
|
|
43
48
|
position: absolute;
|
|
44
49
|
overflow: hidden;
|
|
@@ -59,30 +64,24 @@ const VideoItem = ({ item, sectionId, onResize }) => {
|
|
|
59
64
|
pointer-events: auto;
|
|
60
65
|
}
|
|
61
66
|
.video-${item.id} {
|
|
62
|
-
border-color: ${
|
|
67
|
+
border-color: ${itemStrokeColor};
|
|
63
68
|
}
|
|
64
69
|
.video-playback-wrapper {
|
|
65
70
|
display: flex;
|
|
66
71
|
justify-content: center;
|
|
67
72
|
}
|
|
68
|
-
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams
|
|
69
|
-
const wrapperStatesCSS = (0, getStatesCSS_1.getStatesCSS)(item.id, 'video-wrapper', ['angle', 'opacity', 'blur'], stateParams);
|
|
70
|
-
const videoStatesCSS = (0, getStatesCSS_1.getStatesCSS)(item.id, 'video', ['strokeWidth', 'radius', 'strokeColor'], stateParams);
|
|
73
|
+
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams]) => {
|
|
71
74
|
return (`
|
|
72
75
|
.video-wrapper-${item.id} {
|
|
73
76
|
opacity: ${layoutParams.opacity};
|
|
74
77
|
transform: rotate(${area.angle}deg);
|
|
75
78
|
filter: ${layoutParams.blur !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
|
|
76
|
-
transition: all 0.2s ease;
|
|
77
79
|
}
|
|
78
80
|
.video-${item.id} {
|
|
79
81
|
border-color: ${color_1.CntrlColor.parse(layoutParams.strokeColor).fmt('rgba')};
|
|
80
82
|
border-radius: ${layoutParams.radius * 100}vw;
|
|
81
83
|
border-width: ${layoutParams.strokeWidth * 100}vw;
|
|
82
|
-
transition: all 0.2s ease;
|
|
83
84
|
}
|
|
84
|
-
${wrapperStatesCSS}
|
|
85
|
-
${videoStatesCSS}
|
|
86
85
|
`);
|
|
87
86
|
})}
|
|
88
87
|
` })] }));
|
|
@@ -14,27 +14,27 @@ const useItemAngle_1 = require("../useItemAngle");
|
|
|
14
14
|
const sdk_1 = require("@cntrl-site/sdk");
|
|
15
15
|
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
16
16
|
const useRegisterResize_1 = require("../../common/useRegisterResize");
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const VimeoEmbedItem = ({ item, sectionId, onResize }) => {
|
|
21
|
-
var _a, _b, _c;
|
|
17
|
+
const getStyleFromItemStateAndParams_1 = require("../../utils/getStyleFromItemStateAndParams");
|
|
18
|
+
const VimeoEmbedItem = ({ item, sectionId, onResize, interactionCtrl }) => {
|
|
19
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
22
20
|
const id = (0, react_1.useId)();
|
|
23
21
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
24
|
-
const { radius, blur, opacity } = (0, useEmbedVideoItem_1.useEmbedVideoItem)(item, sectionId);
|
|
22
|
+
const { radius: itemRadius, blur: itemBlur, opacity: itemOpacity } = (0, useEmbedVideoItem_1.useEmbedVideoItem)(item, sectionId);
|
|
25
23
|
const [iframeRef, setIframeRef] = (0, react_1.useState)(null);
|
|
26
24
|
const vimeoPlayer = (0, react_1.useMemo)(() => iframeRef ? new player_1.default(iframeRef) : undefined, [iframeRef]);
|
|
27
|
-
const
|
|
25
|
+
const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
28
26
|
const { play, controls, loop, muted, pictureInPicture, url } = item.commonParams;
|
|
29
27
|
const [ref, setRef] = (0, react_1.useState)(null);
|
|
30
28
|
const [imgRef, setImgRef] = (0, react_1.useState)(null);
|
|
31
29
|
const [isCoverVisible, setIsCoverVisible] = (0, react_1.useState)(false);
|
|
32
|
-
const layoutValues = [item.area, item.layoutParams
|
|
33
|
-
const
|
|
34
|
-
const
|
|
30
|
+
const layoutValues = [item.area, item.layoutParams];
|
|
31
|
+
const wrapperStateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['angle', 'blur', 'opacity']);
|
|
32
|
+
const frameStateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['radius']);
|
|
33
|
+
const angle = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_a = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _a === void 0 ? void 0 : _a.angle, itemAngle);
|
|
34
|
+
const blur = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_b = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _b === void 0 ? void 0 : _b.blur, itemBlur);
|
|
35
|
+
const opacity = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_c = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _c === void 0 ? void 0 : _c.opacity, itemOpacity);
|
|
36
|
+
const radius = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_d = frameStateParams === null || frameStateParams === void 0 ? void 0 : frameStateParams.styles) === null || _d === void 0 ? void 0 : _d.radius, itemRadius);
|
|
35
37
|
(0, useRegisterResize_1.useRegisterResize)(ref, onResize);
|
|
36
|
-
(0, useStatesTransitions_1.useStatesTransitions)(ref, item.state, ['angle', 'blur', 'opacity']);
|
|
37
|
-
(0, useStatesTransitions_1.useStatesTransitions)(iframeRef, item.state, ['radius']);
|
|
38
38
|
const getValidVimeoUrl = (url) => {
|
|
39
39
|
const validURL = new URL(url);
|
|
40
40
|
validURL.searchParams.append('controls', String(controls));
|
|
@@ -67,7 +67,7 @@ const VimeoEmbedItem = ({ item, sectionId, onResize }) => {
|
|
|
67
67
|
vimeoPlayer.play();
|
|
68
68
|
setIsCoverVisible(false);
|
|
69
69
|
};
|
|
70
|
-
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: (
|
|
70
|
+
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: (_e = item.link) === null || _e === void 0 ? void 0 : _e.url, target: (_f = item.link) === null || _f === void 0 ? void 0 : _f.target, children: [(0, jsx_runtime_1.jsxs)("div", { className: `embed-video-wrapper-${item.id}`, ref: setRef, style: Object.assign(Object.assign(Object.assign(Object.assign({}, (opacity !== undefined ? { opacity } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), { transition: (_g = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.transition) !== null && _g !== void 0 ? _g : 'none' }), onMouseEnter: () => {
|
|
71
71
|
if (!vimeoPlayer || play !== 'on-hover')
|
|
72
72
|
return;
|
|
73
73
|
vimeoPlayer.play();
|
|
@@ -75,7 +75,7 @@ const VimeoEmbedItem = ({ item, sectionId, onResize }) => {
|
|
|
75
75
|
if (!vimeoPlayer || play !== 'on-hover')
|
|
76
76
|
return;
|
|
77
77
|
vimeoPlayer.pause();
|
|
78
|
-
}, children: [item.commonParams.coverUrl && ((0, jsx_runtime_1.jsx)("img", { ref: setImgRef, onClick: () => onCoverClick(), src: (
|
|
78
|
+
}, children: [item.commonParams.coverUrl && ((0, jsx_runtime_1.jsx)("img", { ref: setImgRef, onClick: () => onCoverClick(), src: (_h = item.commonParams.coverUrl) !== null && _h !== void 0 ? _h : '', style: {
|
|
79
79
|
display: isCoverVisible ? 'block' : 'none',
|
|
80
80
|
cursor: 'pointer',
|
|
81
81
|
position: 'absolute',
|
|
@@ -84,7 +84,7 @@ const VimeoEmbedItem = ({ item, sectionId, onResize }) => {
|
|
|
84
84
|
width: '100%',
|
|
85
85
|
top: '0',
|
|
86
86
|
left: '0'
|
|
87
|
-
}, alt: "Cover img" })), (0, jsx_runtime_1.jsx)("iframe", { ref: setIframeRef, className: `embed-video
|
|
87
|
+
}, alt: "Cover img" })), (0, jsx_runtime_1.jsx)("iframe", { ref: setIframeRef, className: `embed-video`, src: validUrl || '', allow: "autoplay; fullscreen; picture-in-picture;", allowFullScreen: true, style: Object.assign(Object.assign({}, (radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {})), { transition: (_j = frameStateParams === null || frameStateParams === void 0 ? void 0 : frameStateParams.transition) !== null && _j !== void 0 ? _j : 'none' }) })] }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
88
88
|
.embed-video-wrapper-${item.id} {
|
|
89
89
|
position: absolute;
|
|
90
90
|
width: 100%;
|
|
@@ -97,22 +97,16 @@ const VimeoEmbedItem = ({ item, sectionId, onResize }) => {
|
|
|
97
97
|
border: none;
|
|
98
98
|
overflow: hidden;
|
|
99
99
|
}
|
|
100
|
-
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams
|
|
101
|
-
const wrapperStatesCSS = (0, getStatesCSS_1.getStatesCSS)(item.id, 'embed-video-wrapper', ['angle', 'blur', 'opacity'], stateParams);
|
|
102
|
-
const videoStatesCSS = (0, getStatesCSS_1.getStatesCSS)(item.id, 'embed-video', ['radius'], stateParams);
|
|
100
|
+
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams]) => {
|
|
103
101
|
return (`
|
|
104
102
|
.embed-video-wrapper-${item.id} {
|
|
105
103
|
opacity: ${layoutParams.opacity};
|
|
106
104
|
transform: rotate(${area.angle}deg);
|
|
107
105
|
filter: ${layoutParams.blur !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
|
|
108
|
-
transition: all 0.2s ease;
|
|
109
106
|
}
|
|
110
107
|
.embed-video-wrapper-${item.id} .embed-video {
|
|
111
108
|
border-radius: ${layoutParams.radius * 100}vw;
|
|
112
|
-
transition: all 0.2s ease;
|
|
113
109
|
}
|
|
114
|
-
${wrapperStatesCSS}
|
|
115
|
-
${videoStatesCSS}
|
|
116
110
|
`);
|
|
117
111
|
})}
|
|
118
112
|
` })] }));
|
|
@@ -15,28 +15,27 @@ const sdk_1 = require("@cntrl-site/sdk");
|
|
|
15
15
|
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
16
16
|
const useYouTubeIframeApi_1 = require("../../utils/Youtube/useYouTubeIframeApi");
|
|
17
17
|
const useRegisterResize_1 = require("../../common/useRegisterResize");
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const YoutubeEmbedItem = ({ item, sectionId, onResize }) => {
|
|
22
|
-
var _a, _b, _c;
|
|
18
|
+
const getStyleFromItemStateAndParams_1 = require("../../utils/getStyleFromItemStateAndParams");
|
|
19
|
+
const YoutubeEmbedItem = ({ item, sectionId, onResize, interactionCtrl }) => {
|
|
20
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
23
21
|
const id = (0, react_1.useId)();
|
|
24
22
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
25
23
|
const { play, controls, url } = item.commonParams;
|
|
26
|
-
const { radius, blur, opacity } = (0, useEmbedVideoItem_1.useEmbedVideoItem)(item, sectionId);
|
|
27
|
-
const
|
|
24
|
+
const { radius: itemRadius, blur: itemBlur, opacity: itemOpacity } = (0, useEmbedVideoItem_1.useEmbedVideoItem)(item, sectionId);
|
|
25
|
+
const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
28
26
|
const YT = (0, useYouTubeIframeApi_1.useYouTubeIframeApi)();
|
|
29
27
|
const [div, setDiv] = (0, react_1.useState)(null);
|
|
30
|
-
const [wrapperRef, setWrapperRef] = (0, react_1.useState)(null);
|
|
31
28
|
const [player, setPlayer] = (0, react_1.useState)(undefined);
|
|
32
29
|
const [isCoverVisible, setIsCoverVisible] = (0, react_1.useState)(false);
|
|
33
30
|
const [imgRef, setImgRef] = (0, react_1.useState)(null);
|
|
34
|
-
const layoutValues = [item.area, item.layoutParams
|
|
35
|
-
const
|
|
36
|
-
const
|
|
31
|
+
const layoutValues = [item.area, item.layoutParams];
|
|
32
|
+
const wrapperStateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['angle', 'blur', 'opacity']);
|
|
33
|
+
const frameStateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['radius']);
|
|
34
|
+
const angle = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_a = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _a === void 0 ? void 0 : _a.angle, itemAngle);
|
|
35
|
+
const blur = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_b = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _b === void 0 ? void 0 : _b.blur, itemBlur);
|
|
36
|
+
const opacity = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_c = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _c === void 0 ? void 0 : _c.opacity, itemOpacity);
|
|
37
|
+
const radius = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_d = frameStateParams === null || frameStateParams === void 0 ? void 0 : frameStateParams.styles) === null || _d === void 0 ? void 0 : _d.radius, itemRadius);
|
|
37
38
|
(0, useRegisterResize_1.useRegisterResize)(div, onResize);
|
|
38
|
-
(0, useStatesTransitions_1.useStatesTransitions)(wrapperRef, item.state, ['angle', 'blur', 'opacity']);
|
|
39
|
-
(0, useStatesTransitions_1.useStatesTransitions)(div, item.state, ['radius']);
|
|
40
39
|
(0, react_1.useEffect)(() => {
|
|
41
40
|
const newUrl = new URL(url);
|
|
42
41
|
const videoId = (0, getValidYoutubeUrl_1.getYoutubeId)(newUrl);
|
|
@@ -87,7 +86,7 @@ const YoutubeEmbedItem = ({ item, sectionId, onResize }) => {
|
|
|
87
86
|
setIsCoverVisible(true);
|
|
88
87
|
}
|
|
89
88
|
}, []);
|
|
90
|
-
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: (
|
|
89
|
+
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: (_e = item.link) === null || _e === void 0 ? void 0 : _e.url, target: (_f = item.link) === null || _f === void 0 ? void 0 : _f.target, children: [(0, jsx_runtime_1.jsxs)("div", { className: `embed-youtube-video-wrapper-${item.id}`, onMouseEnter: () => {
|
|
91
90
|
if (!player || play !== 'on-hover')
|
|
92
91
|
return;
|
|
93
92
|
player.playVideo();
|
|
@@ -95,7 +94,7 @@ const YoutubeEmbedItem = ({ item, sectionId, onResize }) => {
|
|
|
95
94
|
if (!player || play !== 'on-hover')
|
|
96
95
|
return;
|
|
97
96
|
player.pauseVideo();
|
|
98
|
-
}, style: Object.assign(Object.assign(Object.assign({}, (opacity !== undefined ? { opacity } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), children: [item.commonParams.coverUrl && ((0, jsx_runtime_1.jsx)("img", { ref: setImgRef, onClick: () => onCoverClick(), src: (
|
|
97
|
+
}, style: Object.assign(Object.assign(Object.assign(Object.assign({}, (opacity !== undefined ? { opacity } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), { transition: (_g = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.transition) !== null && _g !== void 0 ? _g : 'none' }), children: [item.commonParams.coverUrl && ((0, jsx_runtime_1.jsx)("img", { ref: setImgRef, onClick: () => onCoverClick(), src: (_h = item.commonParams.coverUrl) !== null && _h !== void 0 ? _h : '', style: {
|
|
99
98
|
display: isCoverVisible ? 'block' : 'none',
|
|
100
99
|
cursor: 'pointer',
|
|
101
100
|
position: 'absolute',
|
|
@@ -105,7 +104,7 @@ const YoutubeEmbedItem = ({ item, sectionId, onResize }) => {
|
|
|
105
104
|
top: '0',
|
|
106
105
|
left: '0',
|
|
107
106
|
zIndex: 1
|
|
108
|
-
}, alt: "Cover img" })), (0, jsx_runtime_1.jsx)("div", { className: `embed-${item.id}
|
|
107
|
+
}, alt: "Cover img" })), (0, jsx_runtime_1.jsx)("div", { className: `embed-${item.id}`, ref: setDiv, style: Object.assign(Object.assign({}, (radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {})), { transition: (_j = frameStateParams === null || frameStateParams === void 0 ? void 0 : frameStateParams.transition) !== null && _j !== void 0 ? _j : 'none' }) })] }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
109
108
|
.embed-youtube-video-wrapper-${item.id},
|
|
110
109
|
.embed-${item.id} {
|
|
111
110
|
position: absolute;
|
|
@@ -121,22 +120,16 @@ const YoutubeEmbedItem = ({ item, sectionId, onResize }) => {
|
|
|
121
120
|
z-index: 1;
|
|
122
121
|
border: none;
|
|
123
122
|
}
|
|
124
|
-
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams
|
|
125
|
-
const wrapperStatesCSS = (0, getStatesCSS_1.getStatesCSS)(item.id, 'embed-youtube-video-wrapper', ['angle', 'blur', 'opacity'], stateParams);
|
|
126
|
-
const embedStatesCSS = (0, getStatesCSS_1.getStatesCSS)(item.id, 'embed', ['radius'], stateParams);
|
|
123
|
+
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams]) => {
|
|
127
124
|
return (`
|
|
128
125
|
.embed-youtube-video-wrapper-${item.id} {
|
|
129
126
|
opacity: ${layoutParams.opacity};
|
|
130
127
|
transform: rotate(${area.angle}deg);
|
|
131
128
|
filter: ${layoutParams.blur !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
|
|
132
|
-
transition: all 0.2s ease;
|
|
133
129
|
}
|
|
134
130
|
.embed-youtube-video-wrapper-${item.id} .embed-${item.id} {
|
|
135
131
|
border-radius: ${layoutParams.radius * 100}vw;
|
|
136
|
-
transition: all 0.2s ease;
|
|
137
132
|
}
|
|
138
|
-
${wrapperStatesCSS}
|
|
139
|
-
${embedStatesCSS}
|
|
140
133
|
`);
|
|
141
134
|
})}
|
|
142
135
|
` })] }));
|
|
@@ -5,7 +5,8 @@ const sdk_1 = require("@cntrl-site/sdk");
|
|
|
5
5
|
const useKeyframeValue_1 = require("../common/useKeyframeValue");
|
|
6
6
|
const getItemTopStyle_1 = require("../utils/getItemTopStyle");
|
|
7
7
|
const useLayoutContext_1 = require("./useLayoutContext");
|
|
8
|
-
const useItemPosition = (item, sectionId) => {
|
|
8
|
+
const useItemPosition = (item, sectionId, stateValues) => {
|
|
9
|
+
var _a, _b;
|
|
9
10
|
const layoutId = (0, useLayoutContext_1.useLayoutContext)();
|
|
10
11
|
const position = (0, useKeyframeValue_1.useKeyframeValue)(item, sdk_1.KeyframeType.Position, (item, layoutId) => {
|
|
11
12
|
if (!layoutId)
|
|
@@ -14,12 +15,16 @@ const useItemPosition = (item, sectionId) => {
|
|
|
14
15
|
}, (animator, scroll, value) => value ? animator.getPositions(value, scroll) : undefined, sectionId, [layoutId]);
|
|
15
16
|
const anchorSide = layoutId ? item.area[layoutId].anchorSide : sdk_1.AnchorSide.Top;
|
|
16
17
|
const positionType = layoutId ? item.area[layoutId].positionType : sdk_1.PositionType.ScreenBased;
|
|
17
|
-
//
|
|
18
|
+
// to prevent fixed item (with anchor point bottom) to jump when scroll in safari on mobile
|
|
18
19
|
const isScreenBasedBottom = positionType === sdk_1.PositionType.ScreenBased && anchorSide === sdk_1.AnchorSide.Bottom;
|
|
20
|
+
if (!position)
|
|
21
|
+
return undefined;
|
|
22
|
+
const top = (_a = stateValues === null || stateValues === void 0 ? void 0 : stateValues.top) !== null && _a !== void 0 ? _a : position.top;
|
|
23
|
+
const left = (_b = stateValues === null || stateValues === void 0 ? void 0 : stateValues.left) !== null && _b !== void 0 ? _b : position.left;
|
|
19
24
|
return position ? {
|
|
20
|
-
bottom: isScreenBasedBottom ? `${-
|
|
21
|
-
top: isScreenBasedBottom ? 'unset' : (0, getItemTopStyle_1.getItemTopStyle)(
|
|
22
|
-
left: `${
|
|
25
|
+
bottom: isScreenBasedBottom ? `${-top * 100}vw` : 'unset',
|
|
26
|
+
top: isScreenBasedBottom ? 'unset' : (0, getItemTopStyle_1.getItemTopStyle)(top, anchorSide),
|
|
27
|
+
left: `${left * 100}vw`
|
|
23
28
|
} : undefined;
|
|
24
29
|
};
|
|
25
30
|
exports.useItemPosition = useItemPosition;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getStyleKeysFromCSSProperty = exports.CSSPropertyNameMap = void 0;
|
|
4
|
+
exports.CSSPropertyNameMap = {
|
|
5
|
+
'width': 'width',
|
|
6
|
+
'height': 'height',
|
|
7
|
+
'top': 'top',
|
|
8
|
+
'left': 'left',
|
|
9
|
+
'scale': 'transform',
|
|
10
|
+
'angle': 'transform',
|
|
11
|
+
'opacity': 'opacity',
|
|
12
|
+
'radius': 'border-radius',
|
|
13
|
+
'strokeWidth': 'border-width',
|
|
14
|
+
'strokeColor': 'border-color',
|
|
15
|
+
'fillColor': 'background-color',
|
|
16
|
+
'blur': 'filter',
|
|
17
|
+
'backdropBlur': 'backdrop-filter',
|
|
18
|
+
'letterSpacing': 'letter-spacing',
|
|
19
|
+
'wordSpacing': 'word-spacing',
|
|
20
|
+
'color': 'color'
|
|
21
|
+
};
|
|
22
|
+
const PropertyNameCSSMap = {
|
|
23
|
+
'transform': ['angle', 'scale'],
|
|
24
|
+
'border-radius': ['radius'],
|
|
25
|
+
'border-width': ['strokeWidth'],
|
|
26
|
+
'border-color': ['strokeColor'],
|
|
27
|
+
'background-color': ['fillColor'],
|
|
28
|
+
'filter': ['blur'],
|
|
29
|
+
'backdrop-filter': ['backdrop-blur'],
|
|
30
|
+
'letter-spacing': ['letterSpacing'],
|
|
31
|
+
'word-spacing': ['wordSpacing'],
|
|
32
|
+
};
|
|
33
|
+
function getStyleKeysFromCSSProperty(cssProp) {
|
|
34
|
+
var _a;
|
|
35
|
+
const key = (_a = PropertyNameCSSMap[cssProp]) !== null && _a !== void 0 ? _a : [cssProp];
|
|
36
|
+
return key;
|
|
37
|
+
}
|
|
38
|
+
exports.getStyleKeysFromCSSProperty = getStyleKeysFromCSSProperty;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InteractionsRegistry = void 0;
|
|
4
|
+
class InteractionsRegistry {
|
|
5
|
+
constructor(article, layoutId) {
|
|
6
|
+
this.layoutId = layoutId;
|
|
7
|
+
this.ctrls = new Map();
|
|
8
|
+
const { interactions } = article;
|
|
9
|
+
const items = article.sections.flatMap((section) => section.items);
|
|
10
|
+
const activeStatesIds = interactions.reduce((map, inter) => {
|
|
11
|
+
var _a;
|
|
12
|
+
const activeStateId = (_a = inter.states.find((state) => state.id !== inter.startStateId)) === null || _a === void 0 ? void 0 : _a.id;
|
|
13
|
+
map.push(activeStateId);
|
|
14
|
+
return map;
|
|
15
|
+
}, []);
|
|
16
|
+
const interactionStateMap = interactions.reduce((map, { id, startStateId }) => {
|
|
17
|
+
map[id] = startStateId;
|
|
18
|
+
return map;
|
|
19
|
+
}, {});
|
|
20
|
+
const itemStageMap = items.reduce((map, item) => {
|
|
21
|
+
map[item.id] = { type: 'active', isStartState: true };
|
|
22
|
+
return map;
|
|
23
|
+
}, {});
|
|
24
|
+
const stateItemsIdsMap = activeStatesIds.reduce((map, stateId) => {
|
|
25
|
+
map[stateId] = items
|
|
26
|
+
.filter((item) => {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
const layoutStates = (_a = item.state[layoutId]) !== null && _a !== void 0 ? _a : {};
|
|
29
|
+
const state = (_b = layoutStates === null || layoutStates === void 0 ? void 0 : layoutStates[stateId]) !== null && _b !== void 0 ? _b : {};
|
|
30
|
+
const hasKeys = Object.keys(state).length !== 0;
|
|
31
|
+
return hasKeys;
|
|
32
|
+
})
|
|
33
|
+
.map((item) => item.id);
|
|
34
|
+
return map;
|
|
35
|
+
}, {});
|
|
36
|
+
this.items = items;
|
|
37
|
+
this.interactions = interactions;
|
|
38
|
+
this.itemStageMap = itemStageMap;
|
|
39
|
+
this.stateItemsIdsMap = stateItemsIdsMap;
|
|
40
|
+
this.interactionStateMap = interactionStateMap;
|
|
41
|
+
}
|
|
42
|
+
register(itemId, ctrl) {
|
|
43
|
+
this.ctrls.set(itemId, ctrl);
|
|
44
|
+
}
|
|
45
|
+
getStatePropsForItem(itemId) {
|
|
46
|
+
var _a, _b;
|
|
47
|
+
const { items, layoutId } = this;
|
|
48
|
+
const item = items.find((item) => item.id === itemId);
|
|
49
|
+
const stage = this.itemStageMap[itemId];
|
|
50
|
+
if (!stage)
|
|
51
|
+
return {};
|
|
52
|
+
// handle "active" stage
|
|
53
|
+
if (stage.type === 'active') {
|
|
54
|
+
if (stage.isStartState)
|
|
55
|
+
return {};
|
|
56
|
+
const params = (_a = item.state[layoutId]) === null || _a === void 0 ? void 0 : _a[stage.stateId];
|
|
57
|
+
const stateProps = Object.entries(params).reduce((map, [key, stateDetails]) => {
|
|
58
|
+
const style = key;
|
|
59
|
+
map[style] = {
|
|
60
|
+
value: stateDetails.value
|
|
61
|
+
};
|
|
62
|
+
return map;
|
|
63
|
+
}, {});
|
|
64
|
+
return stateProps;
|
|
65
|
+
}
|
|
66
|
+
// handle "transitioning" stage
|
|
67
|
+
const activeStateId = stage.direction === 'in' ? stage.to : stage.from;
|
|
68
|
+
const params = (_b = item.state[layoutId]) === null || _b === void 0 ? void 0 : _b[activeStateId];
|
|
69
|
+
return Object.entries(params).reduce((map, [key, stateDetails]) => {
|
|
70
|
+
const style = key;
|
|
71
|
+
const details = stateDetails;
|
|
72
|
+
map[style] = {
|
|
73
|
+
value: stage.direction === 'in' ? details.value : undefined,
|
|
74
|
+
transition: {
|
|
75
|
+
timing: details[stage.direction].timing,
|
|
76
|
+
duration: details[stage.direction].duration,
|
|
77
|
+
delay: details[stage.direction].delay
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
return map;
|
|
81
|
+
}, {});
|
|
82
|
+
}
|
|
83
|
+
notifyTrigger(itemId, triggerType) {
|
|
84
|
+
var _a;
|
|
85
|
+
for (const interaction of this.interactions) {
|
|
86
|
+
const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
|
|
87
|
+
const matchingTrigger = interaction.triggers.find((trigger) => trigger.itemId === itemId
|
|
88
|
+
&& trigger.from === currentStateId
|
|
89
|
+
&& trigger.type === triggerType);
|
|
90
|
+
if (!matchingTrigger)
|
|
91
|
+
continue;
|
|
92
|
+
const activeStateId = this.getActiveInteractionState(interaction.id);
|
|
93
|
+
const isNewStateActive = matchingTrigger.to === activeStateId;
|
|
94
|
+
this.setCurrentStateForInteraction(interaction.id, matchingTrigger.to);
|
|
95
|
+
const transitioningItems = (_a = this.stateItemsIdsMap[activeStateId]) !== null && _a !== void 0 ? _a : [];
|
|
96
|
+
for (const [itemId, stage] of Object.entries(this.itemStageMap)) {
|
|
97
|
+
if (!transitioningItems.includes(itemId))
|
|
98
|
+
continue;
|
|
99
|
+
this.itemStageMap[itemId] = {
|
|
100
|
+
type: 'transitioning',
|
|
101
|
+
from: stage.type === 'transitioning' ? stage.to : stage.stateId,
|
|
102
|
+
to: matchingTrigger.to,
|
|
103
|
+
direction: isNewStateActive ? 'in' : 'out'
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
this.notifyItemCtrlsChange(transitioningItems);
|
|
107
|
+
this.notifyTransitionStartForItems(transitioningItems, activeStateId);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
notifyTransitionStartForItems(itemsIds, activeStateId) {
|
|
111
|
+
var _a, _b, _c;
|
|
112
|
+
for (const itemId of itemsIds) {
|
|
113
|
+
const ctrl = this.ctrls.get(itemId);
|
|
114
|
+
const item = this.items.find((item) => item.id === itemId);
|
|
115
|
+
const keys = Object.keys((_b = (_a = item.state[this.layoutId]) === null || _a === void 0 ? void 0 : _a[activeStateId]) !== null && _b !== void 0 ? _b : {});
|
|
116
|
+
(_c = ctrl === null || ctrl === void 0 ? void 0 : ctrl.handleTransitionStart) === null || _c === void 0 ? void 0 : _c.call(ctrl, keys);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
notifyTransitionEnd(itemId) {
|
|
120
|
+
var _a;
|
|
121
|
+
const prevState = this.itemStageMap[itemId];
|
|
122
|
+
if (prevState.type !== 'transitioning')
|
|
123
|
+
return; // throw?
|
|
124
|
+
this.itemStageMap[itemId] = {
|
|
125
|
+
type: 'active',
|
|
126
|
+
stateId: prevState.to,
|
|
127
|
+
isStartState: prevState.direction === 'out'
|
|
128
|
+
};
|
|
129
|
+
(_a = this.ctrls.get(itemId)) === null || _a === void 0 ? void 0 : _a.receiveChange();
|
|
130
|
+
}
|
|
131
|
+
getCurrentStateByInteractionId(id) {
|
|
132
|
+
let state;
|
|
133
|
+
for (const interactionId of Object.keys(this.interactionStateMap)) {
|
|
134
|
+
if (id !== interactionId)
|
|
135
|
+
continue;
|
|
136
|
+
state = this.interactionStateMap[interactionId];
|
|
137
|
+
}
|
|
138
|
+
if (!state)
|
|
139
|
+
throw new Error(`Failed to find current state for interaction w/ id="${id}"`);
|
|
140
|
+
return state;
|
|
141
|
+
}
|
|
142
|
+
setCurrentStateForInteraction(interactionId, stateId) {
|
|
143
|
+
this.interactionStateMap = Object.assign(Object.assign({}, this.interactionStateMap), { [interactionId]: stateId });
|
|
144
|
+
}
|
|
145
|
+
getActiveInteractionState(interactionId) {
|
|
146
|
+
var _a;
|
|
147
|
+
const { interactions } = this;
|
|
148
|
+
const interaction = interactions.find((interaction) => interaction.id === interactionId);
|
|
149
|
+
return (_a = interaction.states.find(state => state.id !== interaction.startStateId)) === null || _a === void 0 ? void 0 : _a.id;
|
|
150
|
+
}
|
|
151
|
+
notifyItemCtrlsChange(itemsIds) {
|
|
152
|
+
var _a;
|
|
153
|
+
for (const itemId of itemsIds) {
|
|
154
|
+
(_a = this.ctrls.get(itemId)) === null || _a === void 0 ? void 0 : _a.receiveChange();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.InteractionsRegistry = InteractionsRegistry;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ItemInteractionController = void 0;
|
|
4
|
+
const getTransition_1 = require("./getTransition");
|
|
5
|
+
const CSSPropertyNameMap_1 = require("./CSSPropertyNameMap");
|
|
6
|
+
class ItemInteractionController {
|
|
7
|
+
constructor(itemId, registry, onChange) {
|
|
8
|
+
this.itemId = itemId;
|
|
9
|
+
this.registry = registry;
|
|
10
|
+
this.onChange = onChange;
|
|
11
|
+
this.transitionsInProgress = new Set();
|
|
12
|
+
this.handleTransitionStart = (types) => {
|
|
13
|
+
this.transitionsInProgress.clear();
|
|
14
|
+
for (const type of types) {
|
|
15
|
+
this.transitionsInProgress.add(type);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
this.handleTransitionEnd = (cssPropKey) => {
|
|
19
|
+
const styleKeys = (0, CSSPropertyNameMap_1.getStyleKeysFromCSSProperty)(cssPropKey);
|
|
20
|
+
for (const key of styleKeys) {
|
|
21
|
+
const found = this.transitionsInProgress.has(key);
|
|
22
|
+
if (!found)
|
|
23
|
+
continue;
|
|
24
|
+
this.transitionsInProgress.delete(key);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
if (this.transitionsInProgress.size !== 0)
|
|
28
|
+
return;
|
|
29
|
+
this.registry.notifyTransitionEnd(this.itemId);
|
|
30
|
+
};
|
|
31
|
+
this.registry.register(itemId, this);
|
|
32
|
+
}
|
|
33
|
+
getState(keys) {
|
|
34
|
+
const stateProps = this.registry.getStatePropsForItem(this.itemId);
|
|
35
|
+
const styles = keys.reduce((map, styleKey) => {
|
|
36
|
+
const prop = stateProps[styleKey];
|
|
37
|
+
if ((prop === null || prop === void 0 ? void 0 : prop.value) === undefined)
|
|
38
|
+
return map;
|
|
39
|
+
map[styleKey] = prop.value;
|
|
40
|
+
return map;
|
|
41
|
+
}, {});
|
|
42
|
+
const transition = (0, getTransition_1.getTransition)(stateProps, keys);
|
|
43
|
+
return {
|
|
44
|
+
styles,
|
|
45
|
+
transition
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
sendTrigger(type) {
|
|
49
|
+
this.registry.notifyTrigger(this.itemId, type);
|
|
50
|
+
}
|
|
51
|
+
receiveChange() {
|
|
52
|
+
this.onChange();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.ItemInteractionController = ItemInteractionController;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTransition = void 0;
|
|
4
|
+
const CSSPropertyNameMap_1 = require("./CSSPropertyNameMap");
|
|
5
|
+
function getTransition(state, keys) {
|
|
6
|
+
if (Object.keys(state).length === 0)
|
|
7
|
+
return 'none';
|
|
8
|
+
const transitions = [];
|
|
9
|
+
for (const [key, params] of Object.entries(state)) {
|
|
10
|
+
if (!keys.includes(key) || !params.transition)
|
|
11
|
+
continue;
|
|
12
|
+
const { transition: { duration, delay, timing } } = params;
|
|
13
|
+
const cssKey = CSSPropertyNameMap_1.CSSPropertyNameMap[key];
|
|
14
|
+
const nonZeroDuration = Math.max(duration, 0.01);
|
|
15
|
+
transitions.push(`${cssKey} ${nonZeroDuration}ms ${timing} ${delay}ms`);
|
|
16
|
+
}
|
|
17
|
+
return transitions.length > 0
|
|
18
|
+
? transitions.join(', ')
|
|
19
|
+
: 'none';
|
|
20
|
+
}
|
|
21
|
+
exports.getTransition = getTransition;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useItemInteractionCtrl = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const ItemInteractionCtrl_1 = require("./ItemInteractionCtrl");
|
|
6
|
+
const InteractionsContext_1 = require("../provider/InteractionsContext");
|
|
7
|
+
function useItemInteractionCtrl(itemId) {
|
|
8
|
+
const [_, triggerRender] = (0, react_1.useState)(0);
|
|
9
|
+
const registry = (0, InteractionsContext_1.useInteractionsRegistry)();
|
|
10
|
+
const ctrl = (0, react_1.useMemo)(() => {
|
|
11
|
+
if (!registry)
|
|
12
|
+
return;
|
|
13
|
+
return new ItemInteractionCtrl_1.ItemInteractionController(itemId, registry, () => triggerRender(prev => prev + 1));
|
|
14
|
+
}, [itemId, registry]);
|
|
15
|
+
return ctrl;
|
|
16
|
+
}
|
|
17
|
+
exports.useItemInteractionCtrl = useItemInteractionCtrl;
|