@cntrl-site/sdk-nextjs 0.12.8 → 0.13.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/lib/components/Item.js +15 -4
- package/lib/components/Section.js +6 -1
- package/lib/components/items/CustomItem.js +18 -1
- package/lib/components/items/ImageItem.js +20 -2
- package/lib/components/items/RectangleItem.js +13 -6
- package/lib/components/items/RichTextItem.js +16 -2
- package/lib/components/items/VideoItem.js +21 -3
- package/lib/components/items/VimeoEmbed.js +48 -15
- package/lib/components/items/YoutubeEmbed.js +15 -1
- package/lib/components/useItemPosition.js +3 -17
- package/lib/components/useSectionColor.js +4 -2
- package/lib/utils/HoverStyles/HoverStyles.js +67 -0
- package/lib/utils/RichTextConverter/RichTextConverter.js +10 -0
- package/lib/utils/getItemTopStyle.js +18 -0
- package/package.json +4 -2
- package/src/components/Item.tsx +15 -5
- package/src/components/Section.tsx +6 -1
- package/src/components/items/CustomItem.tsx +20 -2
- package/src/components/items/ImageItem.tsx +23 -4
- package/src/components/items/RectangleItem.tsx +15 -8
- package/src/components/items/RichTextItem.tsx +18 -4
- package/src/components/items/VideoItem.tsx +30 -11
- package/src/components/items/VimeoEmbed.tsx +62 -29
- package/src/components/items/YoutubeEmbed.tsx +15 -1
- package/src/components/useItemPosition.ts +1 -13
- package/src/components/useSectionColor.ts +7 -3
- package/src/utils/HoverStyles/HoverStyles.ts +74 -0
- package/src/utils/RichTextConverter/RichTextConverter.tsx +10 -0
- package/src/utils/getItemTopStyle.ts +14 -0
package/lib/components/Item.js
CHANGED
|
@@ -22,6 +22,8 @@ const useCurrentLayout_1 = require("../common/useCurrentLayout");
|
|
|
22
22
|
const useItemScale_1 = require("./useItemScale");
|
|
23
23
|
const ScaleAnchorMap_1 = require("../utils/ScaleAnchorMap");
|
|
24
24
|
const useSectionHeightMap_1 = require("./useSectionHeightMap");
|
|
25
|
+
const HoverStyles_1 = require("../utils/HoverStyles/HoverStyles");
|
|
26
|
+
const getItemTopStyle_1 = require("../utils/getItemTopStyle");
|
|
25
27
|
const itemsMap = {
|
|
26
28
|
[sdk_1.ArticleItemType.Rectangle]: RectangleItem_1.RectangleItem,
|
|
27
29
|
[sdk_1.ArticleItemType.Image]: ImageItem_1.ImageItem,
|
|
@@ -41,7 +43,7 @@ const Item = ({ item, sectionId }) => {
|
|
|
41
43
|
const sectionHeight = (0, useSectionHeightMap_1.useSectionHeightData)(sectionId);
|
|
42
44
|
const layout = (0, useCurrentLayout_1.useCurrentLayout)();
|
|
43
45
|
const { width, height } = (0, useItemDimensions_1.useItemDimensions)(item, sectionId);
|
|
44
|
-
const layoutValues = [item.area, item.hidden];
|
|
46
|
+
const layoutValues = [item.area, item.hidden, item.state.hover];
|
|
45
47
|
const isInitialRef = (0, react_1.useRef)(true);
|
|
46
48
|
layoutValues.push(item.sticky);
|
|
47
49
|
layoutValues.push(sectionHeight);
|
|
@@ -72,11 +74,11 @@ const Item = ({ item, sectionId }) => {
|
|
|
72
74
|
height: `${sizingAxis.y === sdk_1.ArticleItemSizingType.Manual ? `${height * 100}vw` : 'unset'}`,
|
|
73
75
|
};
|
|
74
76
|
return ((0, jsx_runtime_1.jsxs)("div", { className: `item-wrapper-${item.id}`, style: { top, left, ...(wrapperHeight ? { height: `${wrapperHeight * 100}vw` } : {}) }, children: [(0, jsx_runtime_1.jsx)("div", { suppressHydrationWarning: true, className: `item-${item.id}`, style: isInitialRef.current ? {} : styles, children: (0, jsx_runtime_1.jsx)(ItemComponent, { item: item, sectionId: sectionId, onResize: handleItemResize }) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
75
|
-
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, hidden, sticky, sectionHeight, layoutParams]) => {
|
|
77
|
+
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, hidden, hoverParams, sticky, sectionHeight, layoutParams]) => {
|
|
76
78
|
const sizingAxis = parseSizing(layoutParams.sizing);
|
|
77
79
|
return (`
|
|
78
80
|
.item-${item.id} {
|
|
79
|
-
position: ${sticky ? 'sticky' : 'absolute'};
|
|
81
|
+
position: ${sticky ? 'sticky' : 'absolute'};
|
|
80
82
|
width: ${sizingAxis.x === sdk_1.ArticleItemSizingType.Manual ? `${area.width * 100}vw` : 'max-content'};
|
|
81
83
|
height: ${sizingAxis.y === sdk_1.ArticleItemSizingType.Manual ? `w${area.height * 100}vw` : 'unset'};
|
|
82
84
|
transform: scale(${scale});
|
|
@@ -84,7 +86,9 @@ const Item = ({ item, sectionId }) => {
|
|
|
84
86
|
transform-origin: ${ScaleAnchorMap_1.ScaleAnchorMap[scaleAnchor]};
|
|
85
87
|
pointer-events: auto;
|
|
86
88
|
--webkit-backface-visibility: hidden;
|
|
89
|
+
cursor: ${hoverParams ? 'pointer' : 'default'};
|
|
87
90
|
visibility: ${hidden ? 'hidden' : 'visible'};
|
|
91
|
+
transition: ${(0, HoverStyles_1.getTransitions)(['width', 'height', 'scale'], hoverParams)};
|
|
88
92
|
}
|
|
89
93
|
.item-wrapper-${item.id} {
|
|
90
94
|
position: absolute;
|
|
@@ -92,9 +96,16 @@ const Item = ({ item, sectionId }) => {
|
|
|
92
96
|
-webkit-transform: translate3d(0, 0, 0);
|
|
93
97
|
transform: translate3d(0, 0, 0);
|
|
94
98
|
pointer-events: none;
|
|
95
|
-
top: ${(0,
|
|
99
|
+
top: ${(0, getItemTopStyle_1.getItemTopStyle)(area.top, area.anchorSide)};
|
|
96
100
|
left: ${area.left * 100}vw;
|
|
97
101
|
height: ${sticky ? `${getStickyItemWrapperHeight(sticky, area.height) * 100}vw` : 'unset'};
|
|
102
|
+
transition: ${(0, HoverStyles_1.getTransitions)(['left', 'top'], hoverParams)};
|
|
103
|
+
}
|
|
104
|
+
.item-${item.id}:hover {
|
|
105
|
+
${(0, HoverStyles_1.getHoverStyles)(['width', 'height', 'scale'], hoverParams)}
|
|
106
|
+
}
|
|
107
|
+
.item-wrapper-${item.id}:hover {
|
|
108
|
+
${(0, HoverStyles_1.getHoverStyles)(['left', 'top'], hoverParams, area.anchorSide)}
|
|
98
109
|
}
|
|
99
110
|
`);
|
|
100
111
|
})}
|
|
@@ -35,7 +35,7 @@ const Section = ({ section, data, children }) => {
|
|
|
35
35
|
if (SectionComponent)
|
|
36
36
|
return (0, jsx_runtime_1.jsx)("div", { ref: sectionRef, children: (0, jsx_runtime_1.jsx)(SectionComponent, { data: data, children: children }) });
|
|
37
37
|
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `section-${section.id}`, id: section.name, style: {
|
|
38
|
-
backgroundColor: backgroundColor
|
|
38
|
+
backgroundColor: backgroundColor.toCss()
|
|
39
39
|
}, ref: sectionRef, children: children }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
40
40
|
${(0, sdk_1.getLayoutStyles)(layouts, [section.height], ([height]) => (`
|
|
41
41
|
.section-${section.id} {
|
|
@@ -43,6 +43,11 @@ const Section = ({ section, data, children }) => {
|
|
|
43
43
|
position: relative;
|
|
44
44
|
}`))}
|
|
45
45
|
${getSectionVisibilityStyles()}
|
|
46
|
+
@supports not (color: oklch(42% 0.3 90 / 1)) {
|
|
47
|
+
.section-${section.id} {
|
|
48
|
+
background-color: ${backgroundColor.fmt('rgba')};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
46
51
|
` })] }));
|
|
47
52
|
};
|
|
48
53
|
exports.Section = Section;
|
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.CustomItem = void 0;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const sdk_1 = require("@cntrl-site/sdk");
|
|
4
9
|
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
10
|
+
const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
|
|
11
|
+
const style_1 = __importDefault(require("styled-jsx/style"));
|
|
5
12
|
const CustomItem = ({ item }) => {
|
|
6
13
|
const sdk = (0, useCntrlContext_1.useCntrlContext)();
|
|
14
|
+
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
7
15
|
const component = sdk.customItems.get(item.commonParams.name);
|
|
8
16
|
if (!component)
|
|
9
17
|
return null;
|
|
10
|
-
return component({})
|
|
18
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `custom-component-${item.id}`, children: component({}) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: item.id, children: `${(0, sdk_1.getLayoutStyles)(layouts, [item.state.hover], ([hoverParams]) => {
|
|
19
|
+
return (`
|
|
20
|
+
.custom-component-${item.id} {
|
|
21
|
+
transition: ${(0, HoverStyles_1.getTransitions)(['angle'], hoverParams)};
|
|
22
|
+
}
|
|
23
|
+
.custom-component-${item.id}:hover {
|
|
24
|
+
${(0, HoverStyles_1.getHoverStyles)(['angle'], hoverParams)}
|
|
25
|
+
}
|
|
26
|
+
`);
|
|
27
|
+
})}` })] }));
|
|
11
28
|
};
|
|
12
29
|
exports.CustomItem = CustomItem;
|
|
@@ -11,18 +11,26 @@ const sdk_1 = require("@cntrl-site/sdk");
|
|
|
11
11
|
const LinkWrapper_1 = require("../LinkWrapper");
|
|
12
12
|
const useFileItem_1 = require("./useFileItem");
|
|
13
13
|
const useItemAngle_1 = require("../useItemAngle");
|
|
14
|
+
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
15
|
+
const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
|
|
14
16
|
const ImageItem = ({ item, sectionId }) => {
|
|
15
17
|
const id = (0, react_1.useId)();
|
|
18
|
+
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
16
19
|
const { radius, strokeWidth, opacity, strokeColor } = (0, useFileItem_1.useFileItem)(item, sectionId);
|
|
17
20
|
const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
18
|
-
const borderColor = (0, react_1.useMemo)(() => sdk_1.CntrlColor.parse(strokeColor)
|
|
21
|
+
const borderColor = (0, react_1.useMemo)(() => sdk_1.CntrlColor.parse(strokeColor), [strokeColor]);
|
|
19
22
|
return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: item.link?.url, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `image-wrapper-${item.id}`, style: {
|
|
20
23
|
borderRadius: `${radius * 100}vw`,
|
|
21
24
|
borderWidth: `${strokeWidth * 100}vw`,
|
|
22
25
|
opacity: `${opacity}`,
|
|
23
|
-
borderColor: `${borderColor}`,
|
|
26
|
+
borderColor: `${borderColor.toCss()}`,
|
|
24
27
|
transform: `rotate(${angle}deg)`
|
|
25
28
|
}, children: (0, jsx_runtime_1.jsx)("img", { className: "image", src: item.commonParams.url }) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
29
|
+
@supports not (color: oklch(42% 0.3 90 / 1)) {
|
|
30
|
+
.image-wrapper-${item.id} {
|
|
31
|
+
border-color: ${borderColor.fmt('rgba')};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
26
34
|
.image-wrapper-${item.id} {
|
|
27
35
|
position: absolute;
|
|
28
36
|
overflow: hidden;
|
|
@@ -39,6 +47,16 @@ const ImageItem = ({ item, sectionId }) => {
|
|
|
39
47
|
object-fit: cover;
|
|
40
48
|
pointer-events: none;
|
|
41
49
|
}
|
|
50
|
+
${(0, sdk_1.getLayoutStyles)(layouts, [item.state.hover], ([hoverParams]) => {
|
|
51
|
+
return (`
|
|
52
|
+
.image-wrapper-${item.id} {
|
|
53
|
+
transition: ${(0, HoverStyles_1.getTransitions)(['angle', 'strokeWidth', 'radius', 'strokeColor', 'opacity'], hoverParams)};
|
|
54
|
+
}
|
|
55
|
+
.image-wrapper-${item.id}:hover {
|
|
56
|
+
${(0, HoverStyles_1.getHoverStyles)(['angle', 'strokeWidth', 'radius', 'strokeColor', 'opacity'], hoverParams)}
|
|
57
|
+
}
|
|
58
|
+
`);
|
|
59
|
+
})}
|
|
42
60
|
` })] }) }));
|
|
43
61
|
};
|
|
44
62
|
exports.ImageItem = ImageItem;
|
|
@@ -11,8 +11,11 @@ const sdk_1 = require("@cntrl-site/sdk");
|
|
|
11
11
|
const LinkWrapper_1 = require("../LinkWrapper");
|
|
12
12
|
const useRectangleItem_1 = require("./useRectangleItem");
|
|
13
13
|
const useItemAngle_1 = require("../useItemAngle");
|
|
14
|
+
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
15
|
+
const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
|
|
14
16
|
const RectangleItem = ({ item, sectionId }) => {
|
|
15
17
|
const id = (0, react_1.useId)();
|
|
18
|
+
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
16
19
|
const { fillColor, radius, strokeWidth, strokeColor } = (0, useRectangleItem_1.useRectangleItem)(item, sectionId);
|
|
17
20
|
const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
18
21
|
const backgroundColor = (0, react_1.useMemo)(() => sdk_1.CntrlColor.parse(fillColor), [fillColor]);
|
|
@@ -24,12 +27,6 @@ const RectangleItem = ({ item, sectionId }) => {
|
|
|
24
27
|
borderColor: `${borderColor.toCss()}`,
|
|
25
28
|
transform: `rotate(${angle}deg)`
|
|
26
29
|
} }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
27
|
-
@supports (color: oklch(42% 0.3 90 / 1)) {
|
|
28
|
-
.rectangle-${item.id} {
|
|
29
|
-
background-color: ${backgroundColor.fmt('oklch')};
|
|
30
|
-
border-color: ${borderColor.fmt('oklch')};
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
30
|
@supports not (color: oklch(42% 0.3 90 / 1)) {
|
|
34
31
|
.rectangle-${item.id} {
|
|
35
32
|
background-color: ${backgroundColor.fmt('rgba')};
|
|
@@ -43,6 +40,16 @@ const RectangleItem = ({ item, sectionId }) => {
|
|
|
43
40
|
border-style: solid;
|
|
44
41
|
box-sizing: border-box;
|
|
45
42
|
}
|
|
43
|
+
${(0, sdk_1.getLayoutStyles)(layouts, [item.state.hover], ([hoverParams]) => {
|
|
44
|
+
return (`
|
|
45
|
+
.rectangle-${item.id} {
|
|
46
|
+
transition: ${(0, HoverStyles_1.getTransitions)(['angle', 'fillColor', 'strokeWidth', 'radius', 'strokeColor'], hoverParams)};
|
|
47
|
+
}
|
|
48
|
+
.rectangle-${item.id}:hover {
|
|
49
|
+
${(0, HoverStyles_1.getHoverStyles)(['angle', 'fillColor', 'strokeWidth', 'radius', 'strokeColor'], hoverParams)}
|
|
50
|
+
}
|
|
51
|
+
`);
|
|
52
|
+
})}
|
|
46
53
|
` })] }) }));
|
|
47
54
|
};
|
|
48
55
|
exports.RectangleItem = RectangleItem;
|
|
@@ -6,13 +6,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.RichTextItem = void 0;
|
|
7
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
8
|
const react_1 = require("react");
|
|
9
|
+
const sdk_1 = require("@cntrl-site/sdk");
|
|
9
10
|
const style_1 = __importDefault(require("styled-jsx/style"));
|
|
10
11
|
const useRichTextItem_1 = require("./useRichTextItem");
|
|
11
12
|
const useItemAngle_1 = require("../useItemAngle");
|
|
13
|
+
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
14
|
+
const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
|
|
12
15
|
const RichTextItem = ({ item, sectionId, onResize }) => {
|
|
13
16
|
const [content, styles, preset] = (0, useRichTextItem_1.useRichTextItem)(item);
|
|
17
|
+
const id = (0, react_1.useId)();
|
|
14
18
|
const [ref, setRef] = (0, react_1.useState)(null);
|
|
15
19
|
const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
20
|
+
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
16
21
|
const className = preset ? `cntrl-preset-${preset.id}` : undefined;
|
|
17
22
|
(0, react_1.useEffect)(() => {
|
|
18
23
|
if (!ref || !onResize)
|
|
@@ -26,8 +31,17 @@ const RichTextItem = ({ item, sectionId, onResize }) => {
|
|
|
26
31
|
observer.unobserve(ref);
|
|
27
32
|
};
|
|
28
33
|
}, [ref, onResize]);
|
|
29
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { ref: setRef, className: className
|
|
34
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { ref: setRef, className: `${className} rich-text-wrapper-${item.id}`, style: {
|
|
30
35
|
transform: `rotate(${angle}deg)`
|
|
31
|
-
}, children: content }), (0, jsx_runtime_1.
|
|
36
|
+
}, children: content }), (0, jsx_runtime_1.jsxs)(style_1.default, { id: id, children: [styles, `${(0, sdk_1.getLayoutStyles)(layouts, [item.state.hover], ([hoverParams]) => {
|
|
37
|
+
return (`
|
|
38
|
+
.rich-text-wrapper-${item.id} {
|
|
39
|
+
transition: ${(0, HoverStyles_1.getTransitions)(['angle'], hoverParams)};
|
|
40
|
+
}
|
|
41
|
+
.rich-text-wrapper-${item.id}:hover {
|
|
42
|
+
${(0, HoverStyles_1.getHoverStyles)(['angle'], hoverParams)}
|
|
43
|
+
}
|
|
44
|
+
`);
|
|
45
|
+
})}`] })] }));
|
|
32
46
|
};
|
|
33
47
|
exports.RichTextItem = RichTextItem;
|
|
@@ -11,19 +11,27 @@ const sdk_1 = require("@cntrl-site/sdk");
|
|
|
11
11
|
const LinkWrapper_1 = require("../LinkWrapper");
|
|
12
12
|
const useFileItem_1 = require("./useFileItem");
|
|
13
13
|
const useItemAngle_1 = require("../useItemAngle");
|
|
14
|
+
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
15
|
+
const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
|
|
14
16
|
const VideoItem = ({ item, sectionId }) => {
|
|
15
17
|
const id = (0, react_1.useId)();
|
|
18
|
+
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
16
19
|
const { radius, strokeWidth, strokeColor, opacity } = (0, useFileItem_1.useFileItem)(item, sectionId);
|
|
17
20
|
const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
18
|
-
const borderColor = (0, react_1.useMemo)(() => sdk_1.CntrlColor.parse(strokeColor)
|
|
21
|
+
const borderColor = (0, react_1.useMemo)(() => sdk_1.CntrlColor.parse(strokeColor), [strokeColor]);
|
|
19
22
|
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: item.link?.url, children: [(0, jsx_runtime_1.jsx)("div", { className: `video-wrapper-${item.id}`, style: {
|
|
20
23
|
borderRadius: `${radius * 100}vw`,
|
|
21
24
|
borderWidth: `${strokeWidth * 100}vw`,
|
|
22
25
|
opacity: `${opacity}`,
|
|
23
|
-
borderColor: `${borderColor}`,
|
|
26
|
+
borderColor: `${borderColor.toCss()}`,
|
|
24
27
|
transform: `rotate(${angle}deg)`
|
|
25
28
|
}, children: (0, jsx_runtime_1.jsx)("video", { autoPlay: true, muted: true, loop: true, playsInline: true, className: "video", children: (0, jsx_runtime_1.jsx)("source", { src: item.commonParams.url }) }) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
26
|
-
|
|
29
|
+
@supports not (color: oklch(42% 0.3 90 / 1)) {
|
|
30
|
+
.video-wrapper-${item.id} {
|
|
31
|
+
border-color: ${borderColor.fmt('rgba')};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
.video-wrapper-${item.id} {
|
|
27
35
|
position: absolute;
|
|
28
36
|
overflow: hidden;
|
|
29
37
|
width: 100%;
|
|
@@ -40,6 +48,16 @@ const VideoItem = ({ item, sectionId }) => {
|
|
|
40
48
|
object-fit: cover;
|
|
41
49
|
pointer-events: none;
|
|
42
50
|
}
|
|
51
|
+
${(0, sdk_1.getLayoutStyles)(layouts, [item.state.hover], ([hoverParams]) => {
|
|
52
|
+
return (`
|
|
53
|
+
.video-wrapper-${item.id} {
|
|
54
|
+
transition: ${(0, HoverStyles_1.getTransitions)(['angle', 'strokeWidth', 'radius', 'strokeColor', 'opacity'], hoverParams)};
|
|
55
|
+
}
|
|
56
|
+
.video-wrapper-${item.id}:hover {
|
|
57
|
+
${(0, HoverStyles_1.getHoverStyles)(['angle', 'strokeWidth', 'radius', 'strokeColor', 'opacity'], hoverParams)}
|
|
58
|
+
}
|
|
59
|
+
`);
|
|
60
|
+
})}
|
|
43
61
|
` })] }));
|
|
44
62
|
};
|
|
45
63
|
exports.VideoItem = VideoItem;
|
|
@@ -6,19 +6,34 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.VimeoEmbedItem = void 0;
|
|
7
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
8
|
const react_1 = require("react");
|
|
9
|
+
const player_1 = __importDefault(require("@vimeo/player"));
|
|
9
10
|
const style_1 = __importDefault(require("styled-jsx/style"));
|
|
10
11
|
const LinkWrapper_1 = require("../LinkWrapper");
|
|
11
12
|
const useEmbedVideoItem_1 = require("./useEmbedVideoItem");
|
|
12
13
|
const useItemAngle_1 = require("../useItemAngle");
|
|
14
|
+
const sdk_1 = require("@cntrl-site/sdk");
|
|
15
|
+
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
16
|
+
const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
|
|
17
|
+
const useCurrentLayout_1 = require("../../common/useCurrentLayout");
|
|
13
18
|
const VimeoEmbedItem = ({ item, sectionId }) => {
|
|
14
19
|
const id = (0, react_1.useId)();
|
|
20
|
+
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
21
|
+
const layout = (0, useCurrentLayout_1.useCurrentLayout)();
|
|
15
22
|
const { radius } = (0, useEmbedVideoItem_1.useEmbedVideoItem)(item, sectionId);
|
|
23
|
+
const [iframeRef, setIframeRef] = (0, react_1.useState)(null);
|
|
24
|
+
const vimeoPlayer = (0, react_1.useMemo)(() => iframeRef ? new player_1.default(iframeRef) : undefined, [iframeRef]);
|
|
25
|
+
const isAutoPlayOnHover = (0, react_1.useMemo)(() => {
|
|
26
|
+
const layoutHoverStates = item.state.hover[layout];
|
|
27
|
+
if (!layoutHoverStates)
|
|
28
|
+
return false;
|
|
29
|
+
return layoutHoverStates.autoplay === true;
|
|
30
|
+
}, [layout, item]);
|
|
16
31
|
const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
17
32
|
const { autoplay, controls, loop, muted, pictureInPicture, url } = item.commonParams;
|
|
18
33
|
const getValidVimeoUrl = (url) => {
|
|
19
34
|
const validURL = new URL(url);
|
|
20
35
|
validURL.searchParams.append('controls', String(controls));
|
|
21
|
-
validURL.searchParams.append('autoplay',
|
|
36
|
+
validURL.searchParams.append('autoplay', String(autoplay));
|
|
22
37
|
validURL.searchParams.append('muted', String(muted));
|
|
23
38
|
validURL.searchParams.append('loop', String(loop));
|
|
24
39
|
validURL.searchParams.append('pip', String(pictureInPicture));
|
|
@@ -32,19 +47,37 @@ const VimeoEmbedItem = ({ item, sectionId }) => {
|
|
|
32
47
|
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: item.link?.url, children: [(0, jsx_runtime_1.jsx)("div", { className: `embed-video-wrapper-${item.id}`, style: {
|
|
33
48
|
borderRadius: `${radius * 100}vw`,
|
|
34
49
|
transform: `rotate(${angle}deg)`
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
}, onMouseEnter: () => {
|
|
51
|
+
if (!vimeoPlayer || !isAutoPlayOnHover)
|
|
52
|
+
return;
|
|
53
|
+
vimeoPlayer.play();
|
|
54
|
+
}, onMouseLeave: () => {
|
|
55
|
+
if (!vimeoPlayer || !isAutoPlayOnHover)
|
|
56
|
+
return;
|
|
57
|
+
vimeoPlayer.pause();
|
|
58
|
+
}, children: (0, jsx_runtime_1.jsx)("iframe", { ref: setIframeRef, className: "embedVideo", src: validUrl || '', allow: "autoplay; fullscreen; picture-in-picture;", allowFullScreen: true }) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
59
|
+
.embed-video-wrapper-${item.id} {
|
|
60
|
+
position: absolute;
|
|
61
|
+
overflow: hidden;
|
|
62
|
+
width: 100%;
|
|
63
|
+
height: 100%;
|
|
64
|
+
}
|
|
65
|
+
.embedVideo {
|
|
66
|
+
width: 100%;
|
|
67
|
+
height: 100%;
|
|
68
|
+
z-index: 1;
|
|
69
|
+
border: none;
|
|
70
|
+
}
|
|
71
|
+
${(0, sdk_1.getLayoutStyles)(layouts, [item.state.hover], ([hoverParams]) => {
|
|
72
|
+
return (`
|
|
73
|
+
.embed-video-wrapper-${item.id} {
|
|
74
|
+
transition: ${(0, HoverStyles_1.getTransitions)(['angle', 'radius'], hoverParams)};
|
|
75
|
+
}
|
|
76
|
+
.embed-video-wrapper-${item.id}:hover {
|
|
77
|
+
${(0, HoverStyles_1.getHoverStyles)(['angle', 'radius'], hoverParams)}
|
|
78
|
+
}
|
|
79
|
+
`);
|
|
80
|
+
})}
|
|
81
|
+
` })] }));
|
|
49
82
|
};
|
|
50
83
|
exports.VimeoEmbedItem = VimeoEmbedItem;
|
|
@@ -11,8 +11,12 @@ const LinkWrapper_1 = require("../LinkWrapper");
|
|
|
11
11
|
const getValidYoutubeUrl_1 = require("../../utils/getValidYoutubeUrl");
|
|
12
12
|
const useEmbedVideoItem_1 = require("./useEmbedVideoItem");
|
|
13
13
|
const useItemAngle_1 = require("../useItemAngle");
|
|
14
|
+
const sdk_1 = require("@cntrl-site/sdk");
|
|
15
|
+
const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
|
|
16
|
+
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
14
17
|
const YoutubeEmbedItem = ({ item, sectionId }) => {
|
|
15
18
|
const id = (0, react_1.useId)();
|
|
19
|
+
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
16
20
|
const { autoplay, controls, url } = item.commonParams;
|
|
17
21
|
const { radius } = (0, useEmbedVideoItem_1.useEmbedVideoItem)(item, sectionId);
|
|
18
22
|
const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
@@ -21,7 +25,7 @@ const YoutubeEmbedItem = ({ item, sectionId }) => {
|
|
|
21
25
|
const id = (0, getValidYoutubeUrl_1.getYoutubeId)(newUrl);
|
|
22
26
|
const validUrl = new URL(`https://www.youtube.com/embed/${id}`);
|
|
23
27
|
validUrl.searchParams.append('controls', `${Number(controls)}`);
|
|
24
|
-
validUrl.searchParams.append('autoplay',
|
|
28
|
+
validUrl.searchParams.append('autoplay', `${Number(autoplay)}`);
|
|
25
29
|
validUrl.searchParams.append('mute', `${Number(autoplay)}`);
|
|
26
30
|
return validUrl.href;
|
|
27
31
|
};
|
|
@@ -42,6 +46,16 @@ const YoutubeEmbedItem = ({ item, sectionId }) => {
|
|
|
42
46
|
z-index: 1;
|
|
43
47
|
border: none;
|
|
44
48
|
}
|
|
49
|
+
${(0, sdk_1.getLayoutStyles)(layouts, [item.state.hover], ([hoverParams]) => {
|
|
50
|
+
return (`
|
|
51
|
+
.embed-youtube-video-wrapper-${item.id} {
|
|
52
|
+
transition: ${(0, HoverStyles_1.getTransitions)(['angle', 'radius'], hoverParams)};
|
|
53
|
+
}
|
|
54
|
+
.embed-youtube-video-wrapper-${item.id}:hover {
|
|
55
|
+
${(0, HoverStyles_1.getHoverStyles)(['angle', 'radius'], hoverParams)}
|
|
56
|
+
}
|
|
57
|
+
`);
|
|
58
|
+
})}
|
|
45
59
|
` })] }));
|
|
46
60
|
};
|
|
47
61
|
exports.YoutubeEmbedItem = YoutubeEmbedItem;
|
|
@@ -1,29 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const sdk_1 = require("@cntrl-site/sdk");
|
|
3
|
+
exports.useItemPosition = void 0;
|
|
5
4
|
const useKeyframeValue_1 = require("../common/useKeyframeValue");
|
|
6
5
|
const useCurrentLayout_1 = require("../common/useCurrentLayout");
|
|
6
|
+
const getItemTopStyle_1 = require("../utils/getItemTopStyle");
|
|
7
7
|
const useItemPosition = (item, sectionId) => {
|
|
8
8
|
const layoutId = (0, useCurrentLayout_1.useCurrentLayout)();
|
|
9
9
|
const { top, left } = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => item.area[layoutId], (animator, scroll, value) => animator.getPositions(value, scroll), sectionId, [layoutId]);
|
|
10
10
|
return {
|
|
11
|
-
top: getItemTopStyle(top, item.area[layoutId].anchorSide),
|
|
11
|
+
top: (0, getItemTopStyle_1.getItemTopStyle)(top, item.area[layoutId].anchorSide),
|
|
12
12
|
left: `${left * 100}vw`
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
15
|
exports.useItemPosition = useItemPosition;
|
|
16
|
-
function getItemTopStyle(top, anchorSide) {
|
|
17
|
-
const defaultValue = `${top * 100}vw`;
|
|
18
|
-
if (!anchorSide)
|
|
19
|
-
return defaultValue;
|
|
20
|
-
switch (anchorSide) {
|
|
21
|
-
case sdk_1.AnchorSide.Top:
|
|
22
|
-
return defaultValue;
|
|
23
|
-
case sdk_1.AnchorSide.Center:
|
|
24
|
-
return `calc(50% + ${top * 100}vw)`;
|
|
25
|
-
case sdk_1.AnchorSide.Bottom:
|
|
26
|
-
return `calc(100% + ${top * 100}vw)`;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.getItemTopStyle = getItemTopStyle;
|
|
@@ -4,12 +4,14 @@ exports.useSectionColor = void 0;
|
|
|
4
4
|
const useCurrentLayout_1 = require("../common/useCurrentLayout");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const sdk_1 = require("@cntrl-site/sdk");
|
|
7
|
-
const DEFAULT_COLOR = '
|
|
7
|
+
const DEFAULT_COLOR = 'rgba(0, 0, 0, 0)';
|
|
8
8
|
const useSectionColor = (colorData) => {
|
|
9
9
|
const layoutId = (0, useCurrentLayout_1.useCurrentLayout)();
|
|
10
10
|
return (0, react_1.useMemo)(() => {
|
|
11
11
|
const layoutColor = colorData[layoutId];
|
|
12
|
-
return
|
|
12
|
+
return sdk_1.CntrlColor.parse(!layoutColor
|
|
13
|
+
? DEFAULT_COLOR
|
|
14
|
+
: layoutColor);
|
|
13
15
|
}, []);
|
|
14
16
|
};
|
|
15
17
|
exports.useSectionColor = useSectionColor;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHoverStyles = exports.getTransitions = void 0;
|
|
4
|
+
const sdk_1 = require("@cntrl-site/sdk");
|
|
5
|
+
const getItemTopStyle_1 = require("../getItemTopStyle");
|
|
6
|
+
const hoverTransformationMap = {
|
|
7
|
+
'width': (width) => `width: ${width * 100}vw !important;`,
|
|
8
|
+
'height': (height) => `height: ${height * 100}vw !important;`,
|
|
9
|
+
'top': (top, anchorSide) => `top: ${(0, getItemTopStyle_1.getItemTopStyle)(top, anchorSide)} !important;`,
|
|
10
|
+
'left': (left) => `left: ${left * 100}vw !important;`,
|
|
11
|
+
'scale': (scale) => `transform: scale(${scale}) !important;`,
|
|
12
|
+
'angle': (angle) => `transform: rotate(${angle}deg) !important;`,
|
|
13
|
+
'opacity': (opacity) => `opacity: ${opacity} !important;`,
|
|
14
|
+
'radius': (radius) => `border-radius: ${radius * 100}vw !important;`,
|
|
15
|
+
'strokeWidth': (strokeWidth) => `border-width: ${strokeWidth * 100}vw !important;`,
|
|
16
|
+
'strokeColor': (strokeColor) => `border-color: ${sdk_1.CntrlColor.parse(strokeColor).toCss()} !important;`,
|
|
17
|
+
'fillColor': (fillColor) => `background-color: ${sdk_1.CntrlColor.parse(fillColor).toCss()} !important;`,
|
|
18
|
+
};
|
|
19
|
+
const CSSPropertyNameMap = {
|
|
20
|
+
'width': 'width',
|
|
21
|
+
'height': 'height',
|
|
22
|
+
'top': 'top',
|
|
23
|
+
'left': 'left',
|
|
24
|
+
'scale': 'transform',
|
|
25
|
+
'angle': 'transform',
|
|
26
|
+
'opacity': 'opacity',
|
|
27
|
+
'radius': 'border-radius',
|
|
28
|
+
'strokeWidth': 'border-width',
|
|
29
|
+
'strokeColor': 'border-color',
|
|
30
|
+
'fillColor': 'background-color'
|
|
31
|
+
};
|
|
32
|
+
function getTransitions(values, hover) {
|
|
33
|
+
if (!hover)
|
|
34
|
+
return 'unset';
|
|
35
|
+
const transitionValues = values.reduce((acc, valueName) => {
|
|
36
|
+
if (valueName in hover && hover[valueName] !== undefined) {
|
|
37
|
+
const hoverProperties = hover[valueName];
|
|
38
|
+
return [
|
|
39
|
+
...acc,
|
|
40
|
+
`${CSSPropertyNameMap[valueName]} ${hoverProperties.duration}ms ${hoverProperties.timing} ${hoverProperties.delay}ms`
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
return acc;
|
|
44
|
+
}, []);
|
|
45
|
+
if (!transitionValues.length)
|
|
46
|
+
return 'unset';
|
|
47
|
+
return transitionValues.join(', ');
|
|
48
|
+
}
|
|
49
|
+
exports.getTransitions = getTransitions;
|
|
50
|
+
function getHoverStyles(values, hover, anchorSide) {
|
|
51
|
+
if (!hover)
|
|
52
|
+
return '';
|
|
53
|
+
const hoverValues = values.reduce((acc, valueName) => {
|
|
54
|
+
if (valueName in hover && hover[valueName] !== undefined) {
|
|
55
|
+
const hoverProperties = hover[valueName];
|
|
56
|
+
return [
|
|
57
|
+
...acc,
|
|
58
|
+
hoverTransformationMap[valueName](hoverProperties.value, anchorSide)
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
return acc;
|
|
62
|
+
}, []);
|
|
63
|
+
if (!hoverValues.length)
|
|
64
|
+
return '';
|
|
65
|
+
return hoverValues.join('\n');
|
|
66
|
+
}
|
|
67
|
+
exports.getHoverStyles = getHoverStyles;
|
|
@@ -100,6 +100,7 @@ class RichTextConverter {
|
|
|
100
100
|
continue;
|
|
101
101
|
for (const styleGroup of entitiesGroup.stylesGroup) {
|
|
102
102
|
const lineHeight = styleGroup.styles.find(s => s.name === 'LINEHEIGHT');
|
|
103
|
+
const color = styleGroup.styles.find(s => s.name === 'COLOR');
|
|
103
104
|
if (lineHeight?.value) {
|
|
104
105
|
currentLineHeight[item.layout] = lineHeight.value;
|
|
105
106
|
}
|
|
@@ -108,6 +109,15 @@ class RichTextConverter {
|
|
|
108
109
|
${styleGroup.styles.map(s => RichTextConverter.fromDraftToInline(s)).join('\n')}
|
|
109
110
|
}
|
|
110
111
|
`);
|
|
112
|
+
if (color) {
|
|
113
|
+
styleRules[item.layout].push(`
|
|
114
|
+
@supports not (color: oklch(42% 0.3 90 / 1)) {
|
|
115
|
+
.${blockClass} .s-${styleGroup.start}-${styleGroup.end} {
|
|
116
|
+
color: ${sdk_1.CntrlColor.parse(getResolvedValue(color.value, 'COLOR')).fmt('rgba')};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
`);
|
|
120
|
+
}
|
|
111
121
|
}
|
|
112
122
|
}
|
|
113
123
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getItemTopStyle = void 0;
|
|
4
|
+
const sdk_1 = require("@cntrl-site/sdk");
|
|
5
|
+
function getItemTopStyle(top, anchorSide) {
|
|
6
|
+
const defaultValue = `${top * 100}vw`;
|
|
7
|
+
if (!anchorSide)
|
|
8
|
+
return defaultValue;
|
|
9
|
+
switch (anchorSide) {
|
|
10
|
+
case sdk_1.AnchorSide.Top:
|
|
11
|
+
return defaultValue;
|
|
12
|
+
case sdk_1.AnchorSide.Center:
|
|
13
|
+
return `calc(50% + ${top * 100}vw)`;
|
|
14
|
+
case sdk_1.AnchorSide.Bottom:
|
|
15
|
+
return `calc(100% + ${top * 100}vw)`;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.getItemTopStyle = getItemTopStyle;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntrl-site/sdk-nextjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "SDK for Next.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://github.com/cntrl-site/sdk-nextjs#readme",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@cntrl-site/sdk": "^1.1.
|
|
24
|
+
"@cntrl-site/sdk": "^1.1.6",
|
|
25
|
+
"@vimeo/player": "^2.20.1",
|
|
25
26
|
"html-react-parser": "^3.0.1",
|
|
26
27
|
"styled-jsx": "^5.0.2"
|
|
27
28
|
},
|
|
@@ -38,6 +39,7 @@
|
|
|
38
39
|
"@types/jest": "^29.2.5",
|
|
39
40
|
"@types/node": "^18.11.7",
|
|
40
41
|
"@types/react": "^18.0.15",
|
|
42
|
+
"@types/vimeo__player": "^2.18.0",
|
|
41
43
|
"jest": "^29.3.1",
|
|
42
44
|
"ts-jest": "^29.0.3",
|
|
43
45
|
"typescript": "^4.9.5"
|