@cntrl-site/sdk-nextjs 1.0.20 → 1.1.0
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/jest.config.js +2 -2
- package/lib/components/Article.js +9 -8
- package/lib/components/Head.js +1 -1
- package/lib/components/Item.js +39 -21
- package/lib/components/items/CodeEmbedItem.js +15 -12
- package/lib/components/items/CustomItem.js +7 -9
- package/lib/components/items/GroupItem.js +15 -12
- package/lib/components/items/ImageItem.js +28 -21
- package/lib/components/items/RectangleItem.js +28 -15
- package/lib/components/items/RichTextItem.js +33 -12
- package/lib/components/items/VideoItem.js +26 -19
- package/lib/components/items/VimeoEmbed.js +22 -20
- package/lib/components/items/YoutubeEmbed.js +20 -18
- package/lib/components/useItemPosition.js +10 -5
- package/lib/interactions/CSSPropertyNameMap.js +38 -0
- package/lib/interactions/InteractionsRegistry.js +220 -0
- package/lib/interactions/ItemInteractionCtrl.js +61 -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 +23 -0
- package/lib/utils/getStyleFromItemStateAndParams.js +9 -0
- package/package.json +7 -4
- package/src/components/Article.tsx +30 -27
- package/src/components/ArticleWrapper.tsx +1 -2
- package/src/components/Head.tsx +7 -11
- package/src/components/Item.tsx +75 -29
- package/src/components/items/CodeEmbedItem.tsx +15 -11
- package/src/components/items/CustomItem.tsx +9 -11
- package/src/components/items/GroupItem.tsx +17 -13
- package/src/components/items/ImageItem.tsx +35 -20
- package/src/components/items/RectangleItem.tsx +35 -14
- package/src/components/items/RichTextItem.tsx +41 -14
- package/src/components/items/VideoItem.tsx +34 -20
- package/src/components/items/VimeoEmbed.tsx +27 -19
- package/src/components/items/YoutubeEmbed.tsx +20 -18
- package/src/components/useItemPosition.ts +12 -5
- package/src/interactions/CSSPropertyNameMap.ts +38 -0
- package/src/interactions/InteractionsRegistry.ts +244 -0
- package/src/interactions/ItemInteractionCtrl.ts +62 -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 +97 -0
- package/src/provider/InteractionsContext.tsx +28 -0
- package/src/utils/getStyleFromItemStateAndParams.ts +8 -0
- package/lib/utils/HoverStyles/HoverStyles.js +0 -77
- package/src/utils/HoverStyles/HoverStyles.ts +0 -85
|
@@ -11,24 +11,49 @@ const sdk_1 = require("@cntrl-site/sdk");
|
|
|
11
11
|
const style_1 = __importDefault(require("styled-jsx/style"));
|
|
12
12
|
const useRichTextItem_1 = require("./useRichTextItem");
|
|
13
13
|
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
14
|
-
const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
|
|
15
14
|
const useRichTextItemValues_1 = require("./useRichTextItemValues");
|
|
16
15
|
const useRegisterResize_1 = require("../../common/useRegisterResize");
|
|
17
16
|
const getFontFamilyValue_1 = require("../../utils/getFontFamilyValue");
|
|
18
17
|
const useExemplary_1 = require("../../common/useExemplary");
|
|
19
18
|
const useItemAngle_1 = require("../useItemAngle");
|
|
20
|
-
const
|
|
21
|
-
|
|
19
|
+
const getStyleFromItemStateAndParams_1 = require("../../utils/getStyleFromItemStateAndParams");
|
|
20
|
+
const useCurrentLayout_1 = require("../../common/useCurrentLayout");
|
|
21
|
+
const RichTextItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
|
|
22
|
+
var _a, _b, _c, _d;
|
|
22
23
|
const id = (0, react_1.useId)();
|
|
23
24
|
const [ref, setRef] = (0, react_1.useState)(null);
|
|
24
25
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
25
|
-
const
|
|
26
|
-
const { blur, wordSpacing, letterSpacing, color, fontSize, lineHeight } = (0, useRichTextItemValues_1.useRichTextItemValues)(item, sectionId);
|
|
27
|
-
const
|
|
28
|
-
const layoutValues = [item.area, item.layoutParams, item.state.hover];
|
|
26
|
+
const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
27
|
+
const { blur: itemBlur, wordSpacing: itemWordSpacing, letterSpacing: itemLetterSpacing, color: itemColor, fontSize, lineHeight } = (0, useRichTextItemValues_1.useRichTextItemValues)(item, sectionId);
|
|
28
|
+
const layoutValues = [item.area, item.layoutParams];
|
|
29
29
|
const exemplary = (0, useExemplary_1.useExemplary)();
|
|
30
|
+
const { layoutId } = (0, useCurrentLayout_1.useCurrentLayout)();
|
|
30
31
|
(0, useRegisterResize_1.useRegisterResize)(ref, onResize);
|
|
31
|
-
|
|
32
|
+
const stateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['angle', 'blur', 'letterSpacing', 'wordSpacing', 'color']);
|
|
33
|
+
const stateStyles = (_a = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) !== null && _a !== void 0 ? _a : {};
|
|
34
|
+
const transition = (_b = stateParams === null || stateParams === void 0 ? void 0 : stateParams.transition) !== null && _b !== void 0 ? _b : 'none';
|
|
35
|
+
const textColor = (0, react_1.useMemo)(() => {
|
|
36
|
+
var _a;
|
|
37
|
+
const color = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_a = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) === null || _a === void 0 ? void 0 : _a.color, itemColor);
|
|
38
|
+
return color ? color_1.CntrlColor.parse(color) : undefined;
|
|
39
|
+
}, [itemColor, stateStyles.color]);
|
|
40
|
+
const angle = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(stateStyles.angle, itemAngle);
|
|
41
|
+
const blur = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(stateStyles.blur, itemBlur);
|
|
42
|
+
const letterSpacing = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(stateStyles.letterSpacing, itemLetterSpacing);
|
|
43
|
+
const wordSpacing = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(stateStyles.wordSpacing, itemWordSpacing);
|
|
44
|
+
const colorAlpha = textColor === null || textColor === void 0 ? void 0 : textColor.getAlpha();
|
|
45
|
+
const rangeStyles = layoutId ? (_d = (_c = item.layoutParams[layoutId]) === null || _c === void 0 ? void 0 : _c.rangeStyles) !== null && _d !== void 0 ? _d : [] : [];
|
|
46
|
+
const rangeColors = rangeStyles.filter((style) => style.style === 'COLOR');
|
|
47
|
+
const hasVisibleRangeColors = rangeColors.some((color) => {
|
|
48
|
+
const alpha = color_1.CntrlColor.parse(color.value).getAlpha();
|
|
49
|
+
return alpha > 0;
|
|
50
|
+
});
|
|
51
|
+
const isInteractive = colorAlpha !== 0 || hasVisibleRangeColors;
|
|
52
|
+
const [content, styles] = (0, useRichTextItem_1.useRichTextItem)(item);
|
|
53
|
+
(0, react_1.useEffect)(() => {
|
|
54
|
+
onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(isInteractive);
|
|
55
|
+
}, [isInteractive, onVisibilityChange]);
|
|
56
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { ref: setRef, className: `rich-text-wrapper-${item.id}`, style: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), (textColor ? { color: `${textColor.fmt('rgba')}` } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (letterSpacing !== undefined ? { letterSpacing: `${letterSpacing * exemplary}px` } : {})), (wordSpacing !== undefined ? { wordSpacing: `${wordSpacing * exemplary}px` } : {})), (fontSize !== undefined ? { fontSize: `${Math.round(fontSize * exemplary)}px` } : {})), (lineHeight !== undefined ? { lineHeight: `${lineHeight * exemplary}px` } : {})), { transition }), children: content }), (0, jsx_runtime_1.jsxs)(style_1.default, { id: id, children: [styles, `${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams]) => {
|
|
32
57
|
const color = color_1.CntrlColor.parse(layoutParams.color);
|
|
33
58
|
return (`
|
|
34
59
|
.rich-text-wrapper-${item.id} {
|
|
@@ -45,10 +70,6 @@ const RichTextItem = ({ item, sectionId, onResize }) => {
|
|
|
45
70
|
transform: rotate(${area.angle}deg);
|
|
46
71
|
filter: ${layoutParams.blur !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
|
|
47
72
|
text-transform: ${layoutParams.textTransform};
|
|
48
|
-
transition: ${(0, HoverStyles_1.getTransitions)(['angle', 'blur', 'letterSpacing', 'wordSpacing', 'color'], hoverParams)};
|
|
49
|
-
}
|
|
50
|
-
.rich-text-wrapper-${item.id}:hover {
|
|
51
|
-
${(0, HoverStyles_1.getHoverStyles)(['angle', 'blur', 'letterSpacing', 'wordSpacing', 'color'], hoverParams)};
|
|
52
73
|
}
|
|
53
74
|
@supports not (color: oklch(42% 0.3 90 / 1)) {
|
|
54
75
|
.rich-text-wrapper-${item.id} {
|
|
@@ -13,26 +13,41 @@ const LinkWrapper_1 = require("../LinkWrapper");
|
|
|
13
13
|
const useFileItem_1 = require("./useFileItem");
|
|
14
14
|
const useItemAngle_1 = require("../useItemAngle");
|
|
15
15
|
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
16
|
-
const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
|
|
17
16
|
const useRegisterResize_1 = require("../../common/useRegisterResize");
|
|
18
17
|
const useLayoutContext_1 = require("../useLayoutContext");
|
|
19
18
|
const ScrollPlaybackVideo_1 = require("../ScrollPlaybackVideo");
|
|
20
|
-
const
|
|
21
|
-
|
|
19
|
+
const getStyleFromItemStateAndParams_1 = require("../../utils/getStyleFromItemStateAndParams");
|
|
20
|
+
const VideoItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
|
|
21
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
22
22
|
const id = (0, react_1.useId)();
|
|
23
23
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
24
|
-
const { radius, strokeWidth, strokeColor, opacity, blur } = (0, useFileItem_1.useFileItem)(item, sectionId);
|
|
25
|
-
const
|
|
26
|
-
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);
|
|
27
26
|
const [ref, setRef] = (0, react_1.useState)(null);
|
|
28
27
|
const videoRef = (0, react_1.useRef)(null);
|
|
29
28
|
const layoutId = (0, useLayoutContext_1.useLayoutContext)();
|
|
30
29
|
const scrollPlayback = layoutId ? item.layoutParams[layoutId].scrollPlayback : null;
|
|
31
|
-
const layoutValues = [item.area, item.layoutParams
|
|
30
|
+
const layoutValues = [item.area, item.layoutParams];
|
|
32
31
|
const hasScrollPlayback = scrollPlayback !== null;
|
|
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);
|
|
33
44
|
(0, useRegisterResize_1.useRegisterResize)(ref, onResize);
|
|
34
|
-
const inlineStyles = Object.assign(Object.assign(Object.assign({}, (radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {})), (strokeWidth !== undefined ? { borderWidth: `${strokeWidth * 100}vw` } : {})), (borderColor ? { borderColor: `${borderColor.toCss()}` } : {}));
|
|
35
|
-
|
|
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
|
+
const isInteractive = opacity !== 0;
|
|
47
|
+
(0, react_1.useEffect)(() => {
|
|
48
|
+
onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(isInteractive);
|
|
49
|
+
}, [isInteractive, onVisibilityChange]);
|
|
50
|
+
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: `
|
|
36
51
|
.video-wrapper-${item.id} {
|
|
37
52
|
position: absolute;
|
|
38
53
|
overflow: hidden;
|
|
@@ -53,31 +68,23 @@ const VideoItem = ({ item, sectionId, onResize }) => {
|
|
|
53
68
|
pointer-events: auto;
|
|
54
69
|
}
|
|
55
70
|
.video-${item.id} {
|
|
56
|
-
border-color: ${
|
|
71
|
+
border-color: ${itemStrokeColor};
|
|
57
72
|
}
|
|
58
73
|
.video-playback-wrapper {
|
|
59
74
|
display: flex;
|
|
60
75
|
justify-content: center;
|
|
61
76
|
}
|
|
62
|
-
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams
|
|
77
|
+
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams]) => {
|
|
63
78
|
return (`
|
|
64
79
|
.video-wrapper-${item.id} {
|
|
65
80
|
opacity: ${layoutParams.opacity};
|
|
66
81
|
transform: rotate(${area.angle}deg);
|
|
67
82
|
filter: ${layoutParams.blur !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
|
|
68
|
-
transition: ${(0, HoverStyles_1.getTransitions)(['angle', 'opacity', 'blur'], hoverParams)};
|
|
69
|
-
}
|
|
70
|
-
.video-wrapper-${item.id}:hover {
|
|
71
|
-
${(0, HoverStyles_1.getHoverStyles)(['angle', 'opacity', 'blur'], hoverParams)};
|
|
72
83
|
}
|
|
73
84
|
.video-${item.id} {
|
|
74
85
|
border-color: ${color_1.CntrlColor.parse(layoutParams.strokeColor).fmt('rgba')};
|
|
75
86
|
border-radius: ${layoutParams.radius * 100}vw;
|
|
76
87
|
border-width: ${layoutParams.strokeWidth * 100}vw;
|
|
77
|
-
transition: ${(0, HoverStyles_1.getTransitions)(['strokeWidth', 'radius', 'strokeColor'], hoverParams)};
|
|
78
|
-
}
|
|
79
|
-
.video-wrapper-${item.id}:hover .video {
|
|
80
|
-
${(0, HoverStyles_1.getHoverStyles)(['strokeWidth', 'radius', 'strokeColor'], hoverParams)};
|
|
81
88
|
}
|
|
82
89
|
`);
|
|
83
90
|
})}
|
|
@@ -13,21 +13,27 @@ const useEmbedVideoItem_1 = require("./useEmbedVideoItem");
|
|
|
13
13
|
const useItemAngle_1 = require("../useItemAngle");
|
|
14
14
|
const sdk_1 = require("@cntrl-site/sdk");
|
|
15
15
|
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
16
|
-
const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
|
|
17
16
|
const useRegisterResize_1 = require("../../common/useRegisterResize");
|
|
18
|
-
const
|
|
19
|
-
|
|
17
|
+
const getStyleFromItemStateAndParams_1 = require("../../utils/getStyleFromItemStateAndParams");
|
|
18
|
+
const VimeoEmbedItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
|
|
19
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
20
20
|
const id = (0, react_1.useId)();
|
|
21
21
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
22
|
-
const { radius, blur, opacity } = (0, useEmbedVideoItem_1.useEmbedVideoItem)(item, sectionId);
|
|
22
|
+
const { radius: itemRadius, blur: itemBlur, opacity: itemOpacity } = (0, useEmbedVideoItem_1.useEmbedVideoItem)(item, sectionId);
|
|
23
23
|
const [iframeRef, setIframeRef] = (0, react_1.useState)(null);
|
|
24
24
|
const vimeoPlayer = (0, react_1.useMemo)(() => iframeRef ? new player_1.default(iframeRef) : undefined, [iframeRef]);
|
|
25
|
-
const
|
|
25
|
+
const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
26
26
|
const { play, controls, loop, muted, pictureInPicture, url } = item.commonParams;
|
|
27
27
|
const [ref, setRef] = (0, react_1.useState)(null);
|
|
28
28
|
const [imgRef, setImgRef] = (0, react_1.useState)(null);
|
|
29
29
|
const [isCoverVisible, setIsCoverVisible] = (0, react_1.useState)(false);
|
|
30
|
-
const layoutValues = [item.area, item.layoutParams
|
|
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);
|
|
31
37
|
(0, useRegisterResize_1.useRegisterResize)(ref, onResize);
|
|
32
38
|
const getValidVimeoUrl = (url) => {
|
|
33
39
|
const validURL = new URL(url);
|
|
@@ -61,7 +67,11 @@ const VimeoEmbedItem = ({ item, sectionId, onResize }) => {
|
|
|
61
67
|
vimeoPlayer.play();
|
|
62
68
|
setIsCoverVisible(false);
|
|
63
69
|
};
|
|
64
|
-
|
|
70
|
+
const isInteractive = opacity !== 0;
|
|
71
|
+
(0, react_1.useEffect)(() => {
|
|
72
|
+
onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(isInteractive);
|
|
73
|
+
}, [isInteractive, onVisibilityChange]);
|
|
74
|
+
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: () => {
|
|
65
75
|
if (!vimeoPlayer || play !== 'on-hover')
|
|
66
76
|
return;
|
|
67
77
|
vimeoPlayer.play();
|
|
@@ -69,7 +79,7 @@ const VimeoEmbedItem = ({ item, sectionId, onResize }) => {
|
|
|
69
79
|
if (!vimeoPlayer || play !== 'on-hover')
|
|
70
80
|
return;
|
|
71
81
|
vimeoPlayer.pause();
|
|
72
|
-
}, children: [item.commonParams.coverUrl && ((0, jsx_runtime_1.jsx)("img", { ref: setImgRef, onClick: () => onCoverClick(), src: (
|
|
82
|
+
}, 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: {
|
|
73
83
|
display: isCoverVisible ? 'block' : 'none',
|
|
74
84
|
cursor: 'pointer',
|
|
75
85
|
position: 'absolute',
|
|
@@ -78,36 +88,28 @@ const VimeoEmbedItem = ({ item, sectionId, onResize }) => {
|
|
|
78
88
|
width: '100%',
|
|
79
89
|
top: '0',
|
|
80
90
|
left: '0'
|
|
81
|
-
}, alt: "Cover img" })), (0, jsx_runtime_1.jsx)("iframe", { ref: setIframeRef, className:
|
|
91
|
+
}, 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: `
|
|
82
92
|
.embed-video-wrapper-${item.id} {
|
|
83
93
|
position: absolute;
|
|
84
94
|
width: 100%;
|
|
85
95
|
height: 100%;
|
|
86
96
|
}
|
|
87
|
-
.
|
|
97
|
+
.embed-video {
|
|
88
98
|
width: 100%;
|
|
89
99
|
height: 100%;
|
|
90
100
|
z-index: 1;
|
|
91
101
|
border: none;
|
|
92
102
|
overflow: hidden;
|
|
93
103
|
}
|
|
94
|
-
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams
|
|
104
|
+
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams]) => {
|
|
95
105
|
return (`
|
|
96
106
|
.embed-video-wrapper-${item.id} {
|
|
97
107
|
opacity: ${layoutParams.opacity};
|
|
98
108
|
transform: rotate(${area.angle}deg);
|
|
99
109
|
filter: ${layoutParams.blur !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
|
|
100
|
-
transition: ${(0, HoverStyles_1.getTransitions)(['angle', 'blur', 'opacity'], hoverParams)};
|
|
101
|
-
}
|
|
102
|
-
.embed-video-wrapper-${item.id}:hover {
|
|
103
|
-
${(0, HoverStyles_1.getHoverStyles)(['angle', 'blur', 'opacity'], hoverParams)}
|
|
104
110
|
}
|
|
105
|
-
.embed-video-wrapper-${item.id} .
|
|
111
|
+
.embed-video-wrapper-${item.id} .embed-video {
|
|
106
112
|
border-radius: ${layoutParams.radius * 100}vw;
|
|
107
|
-
transition: ${(0, HoverStyles_1.getTransitions)(['radius'], hoverParams)};
|
|
108
|
-
}
|
|
109
|
-
.embed-video-wrapper-${item.id}:hover .embedVideo {
|
|
110
|
-
${(0, HoverStyles_1.getHoverStyles)(['radius'], hoverParams)};
|
|
111
113
|
}
|
|
112
114
|
`);
|
|
113
115
|
})}
|
|
@@ -12,23 +12,33 @@ const getValidYoutubeUrl_1 = require("../../utils/getValidYoutubeUrl");
|
|
|
12
12
|
const useEmbedVideoItem_1 = require("./useEmbedVideoItem");
|
|
13
13
|
const useItemAngle_1 = require("../useItemAngle");
|
|
14
14
|
const sdk_1 = require("@cntrl-site/sdk");
|
|
15
|
-
const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
|
|
16
15
|
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
17
16
|
const useYouTubeIframeApi_1 = require("../../utils/Youtube/useYouTubeIframeApi");
|
|
18
17
|
const useRegisterResize_1 = require("../../common/useRegisterResize");
|
|
19
|
-
const
|
|
20
|
-
|
|
18
|
+
const getStyleFromItemStateAndParams_1 = require("../../utils/getStyleFromItemStateAndParams");
|
|
19
|
+
const YoutubeEmbedItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
|
|
20
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
21
21
|
const id = (0, react_1.useId)();
|
|
22
22
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
23
23
|
const { play, controls, url } = item.commonParams;
|
|
24
|
-
const { radius, blur, opacity } = (0, useEmbedVideoItem_1.useEmbedVideoItem)(item, sectionId);
|
|
25
|
-
const
|
|
24
|
+
const { radius: itemRadius, blur: itemBlur, opacity: itemOpacity } = (0, useEmbedVideoItem_1.useEmbedVideoItem)(item, sectionId);
|
|
25
|
+
const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
26
26
|
const YT = (0, useYouTubeIframeApi_1.useYouTubeIframeApi)();
|
|
27
27
|
const [div, setDiv] = (0, react_1.useState)(null);
|
|
28
28
|
const [player, setPlayer] = (0, react_1.useState)(undefined);
|
|
29
29
|
const [isCoverVisible, setIsCoverVisible] = (0, react_1.useState)(false);
|
|
30
30
|
const [imgRef, setImgRef] = (0, react_1.useState)(null);
|
|
31
|
-
const layoutValues = [item.area, item.layoutParams
|
|
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);
|
|
38
|
+
const isInteractive = opacity !== 0;
|
|
39
|
+
(0, react_1.useEffect)(() => {
|
|
40
|
+
onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(isInteractive);
|
|
41
|
+
}, [isInteractive, onVisibilityChange]);
|
|
32
42
|
(0, useRegisterResize_1.useRegisterResize)(div, onResize);
|
|
33
43
|
(0, react_1.useEffect)(() => {
|
|
34
44
|
const newUrl = new URL(url);
|
|
@@ -80,7 +90,7 @@ const YoutubeEmbedItem = ({ item, sectionId, onResize }) => {
|
|
|
80
90
|
setIsCoverVisible(true);
|
|
81
91
|
}
|
|
82
92
|
}, []);
|
|
83
|
-
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: (
|
|
93
|
+
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: () => {
|
|
84
94
|
if (!player || play !== 'on-hover')
|
|
85
95
|
return;
|
|
86
96
|
player.playVideo();
|
|
@@ -88,7 +98,7 @@ const YoutubeEmbedItem = ({ item, sectionId, onResize }) => {
|
|
|
88
98
|
if (!player || play !== 'on-hover')
|
|
89
99
|
return;
|
|
90
100
|
player.pauseVideo();
|
|
91
|
-
}, 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: (
|
|
101
|
+
}, 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: {
|
|
92
102
|
display: isCoverVisible ? 'block' : 'none',
|
|
93
103
|
cursor: 'pointer',
|
|
94
104
|
position: 'absolute',
|
|
@@ -98,7 +108,7 @@ const YoutubeEmbedItem = ({ item, sectionId, onResize }) => {
|
|
|
98
108
|
top: '0',
|
|
99
109
|
left: '0',
|
|
100
110
|
zIndex: 1
|
|
101
|
-
}, alt: "Cover img" })), (0, jsx_runtime_1.jsx)("div", { className: `embed-${item.id}`, ref: setDiv, style: Object.assign({}, (radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {})) })] }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
111
|
+
}, 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: `
|
|
102
112
|
.embed-youtube-video-wrapper-${item.id},
|
|
103
113
|
.embed-${item.id} {
|
|
104
114
|
position: absolute;
|
|
@@ -114,23 +124,15 @@ const YoutubeEmbedItem = ({ item, sectionId, onResize }) => {
|
|
|
114
124
|
z-index: 1;
|
|
115
125
|
border: none;
|
|
116
126
|
}
|
|
117
|
-
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams
|
|
127
|
+
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams]) => {
|
|
118
128
|
return (`
|
|
119
129
|
.embed-youtube-video-wrapper-${item.id} {
|
|
120
130
|
opacity: ${layoutParams.opacity};
|
|
121
131
|
transform: rotate(${area.angle}deg);
|
|
122
132
|
filter: ${layoutParams.blur !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
|
|
123
|
-
transition: ${(0, HoverStyles_1.getTransitions)(['angle', 'blur', 'opacity'], hoverParams)};
|
|
124
133
|
}
|
|
125
134
|
.embed-youtube-video-wrapper-${item.id} .embed-${item.id} {
|
|
126
135
|
border-radius: ${layoutParams.radius * 100}vw;
|
|
127
|
-
transition: ${(0, HoverStyles_1.getTransitions)(['radius'], hoverParams)};
|
|
128
|
-
}
|
|
129
|
-
.embed-youtube-video-wrapper-${item.id}:hover {
|
|
130
|
-
${(0, HoverStyles_1.getHoverStyles)(['angle', 'blur', 'opacity'], hoverParams)};
|
|
131
|
-
}
|
|
132
|
-
.embed-youtube-video-wrapper-${item.id}:hover .embed-${item.id} {
|
|
133
|
-
${(0, HoverStyles_1.getHoverStyles)(['radius'], hoverParams)};
|
|
134
136
|
}
|
|
135
137
|
`);
|
|
136
138
|
})}
|
|
@@ -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;
|