@cntrl-site/sdk-nextjs 0.15.2-beta.0 → 0.15.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cntrl-site-sdk-nextjs-0.15.2.tgz +0 -0
- package/cntrl-site-sdk-nextjs-0.15.3.tgz +0 -0
- package/lib/common/useCurrentLayout.js +4 -8
- package/lib/components/Article.js +4 -4
- package/lib/components/ArticleWrapper.js +3 -7
- package/lib/components/Head.js +4 -6
- package/lib/components/Item.js +5 -10
- package/lib/components/LayoutStyle.js +3 -3
- package/lib/components/LinkWrapper.js +1 -1
- package/lib/components/Page.js +1 -1
- package/lib/components/Section.js +4 -4
- package/lib/components/items/CustomItem.js +2 -2
- package/lib/components/items/ImageItem.js +4 -3
- package/lib/components/items/RectangleItem.js +4 -3
- package/lib/components/items/RichTextItem.js +5 -7
- package/lib/components/items/VideoItem.js +4 -3
- package/lib/components/items/VimeoEmbed.js +4 -3
- package/lib/components/items/YoutubeEmbed.js +6 -4
- package/lib/components/items/useRichTextItem.js +3 -2
- package/lib/components/useSectionHeightMap.js +1 -1
- package/lib/provider/CntrlProvider.js +1 -1
- package/lib/provider/CntrlSdkContext.js +22 -11
- package/lib/provider/CustomSectionRegistry.js +4 -2
- package/lib/utils/ArticleRectManager/ArticleRectObserver.js +5 -1
- package/lib/utils/EventEmitter.js +4 -2
- package/lib/utils/RichTextConverter/RichTextConverter.js +25 -27
- package/lib/utils/Youtube/YouTubeIframeApiLoader.js +17 -6
- package/package.json +4 -3
- package/src/common/useCurrentLayout.ts +4 -15
- package/src/components/ArticleWrapper.tsx +3 -10
- package/src/components/Item.tsx +1 -8
- package/src/components/items/RichTextItem.tsx +2 -6
- package/src/components/items/useRichTextItem.ts +1 -1
- package/src/utils/ArticleRectManager/ArticleRectObserver.ts +1 -0
- package/src/utils/RichTextConverter/RichTextConverter.tsx +10 -9
- package/cntrl-site-sdk-nextjs-0.15.1.tgz +0 -0
|
Binary file
|
|
Binary file
|
|
@@ -15,7 +15,6 @@ const useCurrentLayout = () => {
|
|
|
15
15
|
...acc,
|
|
16
16
|
{
|
|
17
17
|
layoutId: layout.id,
|
|
18
|
-
exemplary: layout.exemplary,
|
|
19
18
|
start: layout.startsWith,
|
|
20
19
|
end: next ? next.startsWith : Number.MAX_SAFE_INTEGER
|
|
21
20
|
}
|
|
@@ -23,21 +22,18 @@ const useCurrentLayout = () => {
|
|
|
23
22
|
}, []);
|
|
24
23
|
}, [layouts]);
|
|
25
24
|
const getCurrentLayout = (0, react_1.useCallback)((articleWidth) => {
|
|
26
|
-
|
|
27
|
-
return
|
|
25
|
+
var _a;
|
|
26
|
+
return (_a = layoutRanges.find(l => articleWidth >= l.start && articleWidth < l.end)) === null || _a === void 0 ? void 0 : _a.layoutId;
|
|
28
27
|
}, [layoutRanges]);
|
|
29
28
|
const [layoutId, setLayoutId] = (0, react_1.useState)(undefined);
|
|
30
|
-
const [deviation, setDeviation] = (0, react_1.useState)(1);
|
|
31
29
|
(0, react_1.useEffect)(() => {
|
|
32
30
|
if (!articleRectObserver)
|
|
33
31
|
return;
|
|
34
32
|
return articleRectObserver.on('resize', () => {
|
|
35
33
|
const articleWidth = articleRectObserver.width;
|
|
36
|
-
|
|
37
|
-
setLayoutId(layoutId);
|
|
38
|
-
setDeviation(articleWidth / exemplary);
|
|
34
|
+
setLayoutId(getCurrentLayout(articleWidth));
|
|
39
35
|
});
|
|
40
36
|
}, [articleRectObserver, getCurrentLayout]);
|
|
41
|
-
return
|
|
37
|
+
return layoutId;
|
|
42
38
|
};
|
|
43
39
|
exports.useCurrentLayout = useCurrentLayout;
|
|
@@ -16,14 +16,14 @@ const Article = ({ article, sectionData }) => {
|
|
|
16
16
|
const articleRef = (0, react_1.useRef)(null);
|
|
17
17
|
const articleRectObserver = (0, useArticleRectObserver_1.useArticleRectObserver)(articleRef.current);
|
|
18
18
|
const id = (0, react_1.useId)();
|
|
19
|
-
return ((0, jsx_runtime_1.jsxs)(ArticleRectContext_1.ArticleRectContext.Provider, { value: articleRectObserver, children: [(0, jsx_runtime_1.jsx)(ArticleWrapper_1.ArticleWrapper, { children: (0, jsx_runtime_1.jsx)("div", { className: "article", ref: articleRef, children: article.sections.map((section, i) => {
|
|
19
|
+
return ((0, jsx_runtime_1.jsxs)(ArticleRectContext_1.ArticleRectContext.Provider, Object.assign({ value: articleRectObserver }, { children: [(0, jsx_runtime_1.jsx)(ArticleWrapper_1.ArticleWrapper, { children: (0, jsx_runtime_1.jsx)("div", Object.assign({ className: "article", ref: articleRef }, { children: article.sections.map((section, i) => {
|
|
20
20
|
const data = section.name ? sectionData[section.name] : {};
|
|
21
|
-
return ((0, jsx_runtime_1.jsx)(Section_1.Section, { section: section, data: data, children: article.sections[i].items.map(item => ((0, jsx_runtime_1.jsx)(Item_1.Item, { item: item, sectionId: section.id }, item.id))) }, section.id));
|
|
22
|
-
}) }) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
21
|
+
return ((0, jsx_runtime_1.jsx)(Section_1.Section, Object.assign({ section: section, data: data }, { children: article.sections[i].items.map(item => ((0, jsx_runtime_1.jsx)(Item_1.Item, { item: item, sectionId: section.id }, item.id))) }), section.id));
|
|
22
|
+
}) })) }), (0, jsx_runtime_1.jsx)(style_1.default, Object.assign({ id: id }, { children: `
|
|
23
23
|
.article {
|
|
24
24
|
position: relative;
|
|
25
25
|
overflow: clip;
|
|
26
26
|
}
|
|
27
|
-
` })] }));
|
|
27
|
+
` }))] })));
|
|
28
28
|
};
|
|
29
29
|
exports.Article = Article;
|
|
@@ -12,7 +12,7 @@ const LayoutContext_1 = require("../provider/LayoutContext");
|
|
|
12
12
|
const ArticleWrapper = ({ children }) => {
|
|
13
13
|
const id = (0, react_1.useId)();
|
|
14
14
|
const [isPageLoaded, setIsPageLoaded] = (0, react_1.useState)(false);
|
|
15
|
-
const
|
|
15
|
+
const layoutId = (0, useCurrentLayout_1.useCurrentLayout)();
|
|
16
16
|
(0, react_1.useEffect)(() => {
|
|
17
17
|
const onPageLoad = () => {
|
|
18
18
|
setIsPageLoaded(true);
|
|
@@ -25,15 +25,11 @@ const ArticleWrapper = ({ children }) => {
|
|
|
25
25
|
return () => window.removeEventListener('load', onPageLoad);
|
|
26
26
|
}
|
|
27
27
|
}, []);
|
|
28
|
-
|
|
29
|
-
return ((0, jsx_runtime_1.jsxs)(LayoutContext_1.LayoutContext.Provider, { value: layoutId, children: [(0, jsx_runtime_1.jsx)("div", { className: "article-wrapper", style: {
|
|
30
|
-
opacity: layoutId && isPageLoaded ? 1 : 0,
|
|
31
|
-
...layoutDeviationStyle
|
|
32
|
-
}, children: children }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
28
|
+
return ((0, jsx_runtime_1.jsxs)(LayoutContext_1.LayoutContext.Provider, Object.assign({ value: layoutId }, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ className: "article-wrapper", style: { opacity: layoutId && isPageLoaded ? 1 : 0 } }, { children: children })), (0, jsx_runtime_1.jsx)(style_1.default, Object.assign({ id: id }, { children: `
|
|
33
29
|
.article-wrapper {
|
|
34
30
|
opacity: 1;
|
|
35
31
|
transition: opacity 0.2s ease;
|
|
36
32
|
}
|
|
37
|
-
` })] }));
|
|
33
|
+
` }))] })));
|
|
38
34
|
};
|
|
39
35
|
exports.ArticleWrapper = ArticleWrapper;
|
package/lib/components/Head.js
CHANGED
|
@@ -11,18 +11,16 @@ const sdk_1 = require("@cntrl-site/sdk");
|
|
|
11
11
|
const CNTRLHead = ({ meta, project }) => {
|
|
12
12
|
const googleFonts = (0, html_react_parser_1.default)(project.fonts.google);
|
|
13
13
|
const adobeFonts = (0, html_react_parser_1.default)(project.fonts.adobe);
|
|
14
|
-
const parsedFonts = {
|
|
15
|
-
...(typeof googleFonts === 'object' ? googleFonts : {}),
|
|
16
|
-
...(typeof adobeFonts === 'object' ? adobeFonts : {})
|
|
17
|
-
};
|
|
14
|
+
const parsedFonts = Object.assign(Object.assign({}, (typeof googleFonts === 'object' ? googleFonts : {})), (typeof adobeFonts === 'object' ? adobeFonts : {}));
|
|
18
15
|
const customFonts = project.fonts.custom;
|
|
19
16
|
const htmlHead = (0, html_react_parser_1.default)(project.html.head);
|
|
20
17
|
const ffGenerator = new sdk_1.FontFaceGenerator(customFonts);
|
|
21
18
|
const links = Object.values(parsedFonts).map((value, i) => {
|
|
19
|
+
var _a, _b;
|
|
22
20
|
if (!value)
|
|
23
21
|
return;
|
|
24
|
-
const rel = value
|
|
25
|
-
const href = value
|
|
22
|
+
const rel = (value === null || value === void 0 ? void 0 : value.rel) || ((_a = value.props) === null || _a === void 0 ? void 0 : _a.rel);
|
|
23
|
+
const href = (value === null || value === void 0 ? void 0 : value.href) || ((_b = value.props) === null || _b === void 0 ? void 0 : _b.href);
|
|
26
24
|
if (!rel || !href)
|
|
27
25
|
return;
|
|
28
26
|
return ((0, jsx_runtime_1.jsx)("link", { rel: rel, href: href }, `link-${rel}-${href}`));
|
package/lib/components/Item.js
CHANGED
|
@@ -40,7 +40,6 @@ const Item = ({ item, sectionId }) => {
|
|
|
40
40
|
const id = (0, react_1.useId)();
|
|
41
41
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
42
42
|
const layout = (0, useLayoutContext_1.useLayoutContext)();
|
|
43
|
-
const exemplary = layouts.find(l => l.id === layout)?.exemplary ?? 1;
|
|
44
43
|
const [wrapperHeight, setWrapperHeight] = (0, react_1.useState)(undefined);
|
|
45
44
|
const { scale, scaleAnchor } = (0, useItemScale_1.useItemScale)(item, sectionId);
|
|
46
45
|
const { top, left } = (0, useItemPosition_1.useItemPosition)(item, sectionId);
|
|
@@ -73,19 +72,14 @@ const Item = ({ item, sectionId }) => {
|
|
|
73
72
|
(0, react_1.useEffect)(() => {
|
|
74
73
|
isInitialRef.current = false;
|
|
75
74
|
}, []);
|
|
76
|
-
const isRichText = isItemType(item, sdk_1.ArticleItemType.RichText);
|
|
77
75
|
const styles = {
|
|
78
76
|
transform: `scale(${scale})`,
|
|
79
77
|
transformOrigin: ScaleAnchorMap_1.ScaleAnchorMap[scaleAnchor],
|
|
80
|
-
width: `${sizingAxis.x === sdk_1.ArticleItemSizingType.Manual
|
|
81
|
-
? isRichText
|
|
82
|
-
? `${width * exemplary}px`
|
|
83
|
-
: `${width * 100}vw`
|
|
84
|
-
: 'max-content'}`,
|
|
78
|
+
width: `${sizingAxis.x === sdk_1.ArticleItemSizingType.Manual ? `${width * 100}vw` : 'max-content'}`,
|
|
85
79
|
height: `${sizingAxis.y === sdk_1.ArticleItemSizingType.Manual ? `${height * 100}vw` : 'unset'}`,
|
|
86
80
|
top: stickyTop
|
|
87
81
|
};
|
|
88
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: `item-wrapper-${item.id}`, style: isInitialRef.current ? {} : { top, left,
|
|
82
|
+
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: `item-wrapper-${item.id}`, style: isInitialRef.current ? {} : Object.assign({ top, left }, (wrapperHeight ? { height: `${wrapperHeight * 100}vw` } : {})) }, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ 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, Object.assign({ id: id }, { children: `
|
|
89
83
|
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, hidden, hoverParams, sticky, sectionHeight, layoutParams]) => {
|
|
90
84
|
const sizingAxis = parseSizing(layoutParams.sizing);
|
|
91
85
|
return (`
|
|
@@ -121,11 +115,12 @@ const Item = ({ item, sectionId }) => {
|
|
|
121
115
|
}
|
|
122
116
|
`);
|
|
123
117
|
})}
|
|
124
|
-
` })] }));
|
|
118
|
+
` }))] })));
|
|
125
119
|
};
|
|
126
120
|
exports.Item = Item;
|
|
127
121
|
function getStickyItemWrapperHeight(sticky, itemHeight) {
|
|
128
|
-
|
|
122
|
+
var _a;
|
|
123
|
+
const end = (_a = sticky.to) !== null && _a !== void 0 ? _a : 100;
|
|
129
124
|
return end - sticky.from + itemHeight;
|
|
130
125
|
}
|
|
131
126
|
function parseSizing(sizing = 'manual') {
|
|
@@ -9,10 +9,10 @@ const sdk_1 = require("@cntrl-site/sdk");
|
|
|
9
9
|
const style_1 = __importDefault(require("styled-jsx/style"));
|
|
10
10
|
const LayoutStyle = ({ id, layouts, layoutId, children }) => {
|
|
11
11
|
const layout = layouts.find(l => l.id === layoutId);
|
|
12
|
-
return ((0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
12
|
+
return ((0, jsx_runtime_1.jsx)(style_1.default, Object.assign({ id: id }, { children: `
|
|
13
13
|
${(0, sdk_1.getLayoutMediaQuery)(layoutId, layouts)} {
|
|
14
|
-
${children
|
|
14
|
+
${children === null || children === void 0 ? void 0 : children(layout)}
|
|
15
15
|
}
|
|
16
|
-
` }));
|
|
16
|
+
` })));
|
|
17
17
|
};
|
|
18
18
|
exports.LayoutStyle = LayoutStyle;
|
|
@@ -4,7 +4,7 @@ exports.LinkWrapper = void 0;
|
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const LinkWrapper = ({ url, children }) => {
|
|
6
6
|
const validUrl = url && buildValidUrl(url);
|
|
7
|
-
return url ? ((0, jsx_runtime_1.jsx)("a", { href: validUrl, target: url.startsWith('/') || url.startsWith('#') ? '_self' : '_blank', rel: "noreferrer", children: children })) : ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children }));
|
|
7
|
+
return url ? ((0, jsx_runtime_1.jsx)("a", Object.assign({ href: validUrl, target: url.startsWith('/') || url.startsWith('#') ? '_self' : '_blank', rel: "noreferrer" }, { children: children }))) : ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children }));
|
|
8
8
|
};
|
|
9
9
|
exports.LinkWrapper = LinkWrapper;
|
|
10
10
|
function buildValidUrl(url) {
|
package/lib/components/Page.js
CHANGED
|
@@ -18,6 +18,6 @@ const Page = ({ article, project, meta, keyframes, sectionData }) => {
|
|
|
18
18
|
const beforeBodyClose = (0, html_react_parser_1.default)(project.html.beforeBodyClose);
|
|
19
19
|
const keyframesRepo = (0, react_1.useMemo)(() => new Keyframes_1.Keyframes(keyframes), [keyframes]);
|
|
20
20
|
const { typePresets, layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
21
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Head_1.CNTRLHead, { project: project, meta: meta }), afterBodyOpen, (0, jsx_runtime_1.jsx)(KeyframesContext_1.KeyframesContext.Provider, { value: keyframesRepo, children: (0, jsx_runtime_1.jsx)(Article_1.Article, { article: article, sectionData: sectionData }) }), beforeBodyClose, typePresets && typePresets.presets.length > 0 && ((0, jsx_runtime_1.jsx)("style", { children: (0, generateTypePresetStyles_1.generateTypePresetStyles)(typePresets, layouts) }))] }));
|
|
21
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Head_1.CNTRLHead, { project: project, meta: meta }), afterBodyOpen, (0, jsx_runtime_1.jsx)(KeyframesContext_1.KeyframesContext.Provider, Object.assign({ value: keyframesRepo }, { children: (0, jsx_runtime_1.jsx)(Article_1.Article, { article: article, sectionData: sectionData }) })), beforeBodyClose, typePresets && typePresets.presets.length > 0 && ((0, jsx_runtime_1.jsx)("style", { children: (0, generateTypePresetStyles_1.generateTypePresetStyles)(typePresets, layouts) }))] }));
|
|
22
22
|
};
|
|
23
23
|
exports.Page = Page;
|
|
@@ -33,10 +33,10 @@ const Section = ({ section, data, children }) => {
|
|
|
33
33
|
}, '');
|
|
34
34
|
};
|
|
35
35
|
if (SectionComponent)
|
|
36
|
-
return (0, jsx_runtime_1.jsx)("div", { ref: sectionRef, children: (0, jsx_runtime_1.jsx)(SectionComponent, { data: data, children: children }) });
|
|
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: {
|
|
36
|
+
return (0, jsx_runtime_1.jsx)("div", Object.assign({ ref: sectionRef }, { children: (0, jsx_runtime_1.jsx)(SectionComponent, Object.assign({ data: data }, { children: children })) }));
|
|
37
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ className: `section-${section.id}`, id: section.name, style: {
|
|
38
38
|
backgroundColor: backgroundColor.toCss()
|
|
39
|
-
}, ref: sectionRef, children: children }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
39
|
+
}, ref: sectionRef }, { children: children })), (0, jsx_runtime_1.jsx)(style_1.default, Object.assign({ id: id }, { children: `
|
|
40
40
|
${(0, sdk_1.getLayoutStyles)(layouts, [section.height], ([height]) => (`
|
|
41
41
|
.section-${section.id} {
|
|
42
42
|
height: ${getSectionHeight(height)};
|
|
@@ -48,7 +48,7 @@ const Section = ({ section, data, children }) => {
|
|
|
48
48
|
background-color: ${backgroundColor.fmt('rgba')};
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
` })] }));
|
|
51
|
+
` }))] }));
|
|
52
52
|
};
|
|
53
53
|
exports.Section = Section;
|
|
54
54
|
function getSectionHeight(heightData) {
|
|
@@ -15,7 +15,7 @@ const CustomItem = ({ item }) => {
|
|
|
15
15
|
const component = sdk.customItems.get(item.commonParams.name);
|
|
16
16
|
if (!component)
|
|
17
17
|
return null;
|
|
18
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `custom-component-${item.id}
|
|
18
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ className: `custom-component-${item.id}` }, { children: component({}) })), (0, jsx_runtime_1.jsx)(style_1.default, Object.assign({ id: item.id }, { children: `${(0, sdk_1.getLayoutStyles)(layouts, [item.state.hover], ([hoverParams]) => {
|
|
19
19
|
return (`
|
|
20
20
|
.custom-component-${item.id} {
|
|
21
21
|
transition: ${(0, HoverStyles_1.getTransitions)(['angle'], hoverParams)};
|
|
@@ -24,6 +24,6 @@ const CustomItem = ({ item }) => {
|
|
|
24
24
|
${(0, HoverStyles_1.getHoverStyles)(['angle'], hoverParams)}
|
|
25
25
|
}
|
|
26
26
|
`);
|
|
27
|
-
})}` })] }));
|
|
27
|
+
})}` }))] }));
|
|
28
28
|
};
|
|
29
29
|
exports.CustomItem = CustomItem;
|
|
@@ -14,19 +14,20 @@ const useItemAngle_1 = require("../useItemAngle");
|
|
|
14
14
|
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
15
15
|
const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
|
|
16
16
|
const ImageItem = ({ item, sectionId }) => {
|
|
17
|
+
var _a;
|
|
17
18
|
const id = (0, react_1.useId)();
|
|
18
19
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
19
20
|
const { radius, strokeWidth, opacity, strokeColor, blur } = (0, useFileItem_1.useFileItem)(item, sectionId);
|
|
20
21
|
const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
21
22
|
const borderColor = (0, react_1.useMemo)(() => sdk_1.CntrlColor.parse(strokeColor), [strokeColor]);
|
|
22
|
-
return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: item.link
|
|
23
|
+
return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, Object.assign({ url: (_a = item.link) === null || _a === void 0 ? void 0 : _a.url }, { children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ className: `image-wrapper-${item.id}`, style: {
|
|
23
24
|
borderRadius: `${radius * 100}vw`,
|
|
24
25
|
borderWidth: `${strokeWidth * 100}vw`,
|
|
25
26
|
opacity: `${opacity}`,
|
|
26
27
|
borderColor: `${borderColor.toCss()}`,
|
|
27
28
|
transform: `rotate(${angle}deg)`,
|
|
28
29
|
filter: `blur(${blur * 100}vw)`
|
|
29
|
-
}, children: (0, jsx_runtime_1.jsx)("img", { className: "image", src: item.commonParams.url }) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
30
|
+
} }, { children: (0, jsx_runtime_1.jsx)("img", { className: "image", src: item.commonParams.url }) })), (0, jsx_runtime_1.jsx)(style_1.default, Object.assign({ id: id }, { children: `
|
|
30
31
|
@supports not (color: oklch(42% 0.3 90 / 1)) {
|
|
31
32
|
.image-wrapper-${item.id} {
|
|
32
33
|
border-color: ${borderColor.fmt('rgba')};
|
|
@@ -58,6 +59,6 @@ const ImageItem = ({ item, sectionId }) => {
|
|
|
58
59
|
}
|
|
59
60
|
`);
|
|
60
61
|
})}
|
|
61
|
-
` })] }) }));
|
|
62
|
+
` }))] }) })));
|
|
62
63
|
};
|
|
63
64
|
exports.ImageItem = ImageItem;
|
|
@@ -14,13 +14,14 @@ const useItemAngle_1 = require("../useItemAngle");
|
|
|
14
14
|
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
15
15
|
const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
|
|
16
16
|
const RectangleItem = ({ item, sectionId }) => {
|
|
17
|
+
var _a;
|
|
17
18
|
const id = (0, react_1.useId)();
|
|
18
19
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
19
20
|
const { fillColor, radius, strokeWidth, strokeColor, blur, backdropBlur } = (0, useRectangleItem_1.useRectangleItem)(item, sectionId);
|
|
20
21
|
const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
21
22
|
const backgroundColor = (0, react_1.useMemo)(() => sdk_1.CntrlColor.parse(fillColor), [fillColor]);
|
|
22
23
|
const borderColor = (0, react_1.useMemo)(() => sdk_1.CntrlColor.parse(strokeColor), [strokeColor]);
|
|
23
|
-
return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: item.link
|
|
24
|
+
return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, Object.assign({ url: (_a = item.link) === null || _a === void 0 ? void 0 : _a.url }, { children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `rectangle-${item.id}`, style: {
|
|
24
25
|
backgroundColor: `${backgroundColor.toCss()}`,
|
|
25
26
|
borderRadius: `${radius * 100}vw`,
|
|
26
27
|
borderWidth: `${strokeWidth * 100}vw`,
|
|
@@ -30,7 +31,7 @@ const RectangleItem = ({ item, sectionId }) => {
|
|
|
30
31
|
backdropFilter: backdropBlur !== 0 ? `blur(${backdropBlur * 100}vw)` : 'unset',
|
|
31
32
|
// @ts-ignore
|
|
32
33
|
'-webkit-backdrop-filter': backdropBlur !== 0 ? `blur(${backdropBlur * 100}vw)` : 'unset',
|
|
33
|
-
} }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
34
|
+
} }), (0, jsx_runtime_1.jsx)(style_1.default, Object.assign({ id: id }, { children: `
|
|
34
35
|
@supports not (color: oklch(42% 0.3 90 / 1)) {
|
|
35
36
|
.rectangle-${item.id} {
|
|
36
37
|
background-color: ${backgroundColor.fmt('rgba')};
|
|
@@ -54,6 +55,6 @@ const RectangleItem = ({ item, sectionId }) => {
|
|
|
54
55
|
}
|
|
55
56
|
`);
|
|
56
57
|
})}
|
|
57
|
-
` })] }) }));
|
|
58
|
+
` }))] }) })));
|
|
58
59
|
};
|
|
59
60
|
exports.RectangleItem = RectangleItem;
|
|
@@ -12,6 +12,7 @@ const useRichTextItem_1 = require("./useRichTextItem");
|
|
|
12
12
|
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
13
13
|
const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
|
|
14
14
|
const useRichTextItemValues_1 = require("./useRichTextItemValues");
|
|
15
|
+
const resize_observer_polyfill_1 = __importDefault(require("resize-observer-polyfill"));
|
|
15
16
|
const RichTextItem = ({ item, sectionId, onResize }) => {
|
|
16
17
|
const [content, styles, preset] = (0, useRichTextItem_1.useRichTextItem)(item);
|
|
17
18
|
const id = (0, react_1.useId)();
|
|
@@ -22,7 +23,7 @@ const RichTextItem = ({ item, sectionId, onResize }) => {
|
|
|
22
23
|
(0, react_1.useEffect)(() => {
|
|
23
24
|
if (!ref || !onResize)
|
|
24
25
|
return;
|
|
25
|
-
const observer = new
|
|
26
|
+
const observer = new resize_observer_polyfill_1.default((entries) => {
|
|
26
27
|
const [entry] = entries;
|
|
27
28
|
onResize(entry.target.getBoundingClientRect().height / window.innerWidth);
|
|
28
29
|
});
|
|
@@ -31,13 +32,10 @@ const RichTextItem = ({ item, sectionId, onResize }) => {
|
|
|
31
32
|
observer.unobserve(ref);
|
|
32
33
|
};
|
|
33
34
|
}, [ref, onResize]);
|
|
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: {
|
|
35
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ ref: setRef, className: `${className} rich-text-wrapper-${item.id}`, style: {
|
|
35
36
|
transform: `rotate(${angle}deg)`,
|
|
36
37
|
filter: `blur(${blur * 100}vw)`
|
|
37
|
-
}, children: (0, jsx_runtime_1.
|
|
38
|
-
transformOrigin: 'top left',
|
|
39
|
-
transform: 'scale(var(--layout-deviation))'
|
|
40
|
-
}, children: content }) }), (0, jsx_runtime_1.jsxs)(style_1.default, { id: id, children: [styles, `${(0, sdk_1.getLayoutStyles)(layouts, [item.state.hover], ([hoverParams]) => {
|
|
38
|
+
} }, { children: content })), (0, jsx_runtime_1.jsxs)(style_1.default, Object.assign({ id: id }, { children: [styles, `${(0, sdk_1.getLayoutStyles)(layouts, [item.state.hover], ([hoverParams]) => {
|
|
41
39
|
return (`
|
|
42
40
|
.rich-text-wrapper-${item.id} {
|
|
43
41
|
transition: ${(0, HoverStyles_1.getTransitions)(['angle', 'blur'], hoverParams)};
|
|
@@ -46,6 +44,6 @@ const RichTextItem = ({ item, sectionId, onResize }) => {
|
|
|
46
44
|
${(0, HoverStyles_1.getHoverStyles)(['angle', 'blur'], hoverParams)}
|
|
47
45
|
}
|
|
48
46
|
`);
|
|
49
|
-
})}`] })] }));
|
|
47
|
+
})}`] }))] }));
|
|
50
48
|
};
|
|
51
49
|
exports.RichTextItem = RichTextItem;
|
|
@@ -14,19 +14,20 @@ const useItemAngle_1 = require("../useItemAngle");
|
|
|
14
14
|
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
15
15
|
const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
|
|
16
16
|
const VideoItem = ({ item, sectionId }) => {
|
|
17
|
+
var _a;
|
|
17
18
|
const id = (0, react_1.useId)();
|
|
18
19
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
19
20
|
const { radius, strokeWidth, strokeColor, opacity, blur } = (0, useFileItem_1.useFileItem)(item, sectionId);
|
|
20
21
|
const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
21
22
|
const borderColor = (0, react_1.useMemo)(() => sdk_1.CntrlColor.parse(strokeColor), [strokeColor]);
|
|
22
|
-
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: item.link
|
|
23
|
+
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, Object.assign({ url: (_a = item.link) === null || _a === void 0 ? void 0 : _a.url }, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ className: `video-wrapper-${item.id}`, style: {
|
|
23
24
|
borderRadius: `${radius * 100}vw`,
|
|
24
25
|
borderWidth: `${strokeWidth * 100}vw`,
|
|
25
26
|
opacity: `${opacity}`,
|
|
26
27
|
borderColor: `${borderColor.toCss()}`,
|
|
27
28
|
transform: `rotate(${angle}deg)`,
|
|
28
29
|
filter: `blur(${blur * 100}vw)`
|
|
29
|
-
}, 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: `
|
|
30
|
+
} }, { children: (0, jsx_runtime_1.jsx)("video", Object.assign({ 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, Object.assign({ id: id }, { children: `
|
|
30
31
|
@supports not (color: oklch(42% 0.3 90 / 1)) {
|
|
31
32
|
.video-wrapper-${item.id} {
|
|
32
33
|
border-color: ${borderColor.fmt('rgba')};
|
|
@@ -59,6 +60,6 @@ const VideoItem = ({ item, sectionId }) => {
|
|
|
59
60
|
}
|
|
60
61
|
`);
|
|
61
62
|
})}
|
|
62
|
-
` })] }));
|
|
63
|
+
` }))] })));
|
|
63
64
|
};
|
|
64
65
|
exports.VideoItem = VideoItem;
|
|
@@ -15,6 +15,7 @@ const sdk_1 = require("@cntrl-site/sdk");
|
|
|
15
15
|
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
16
16
|
const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
|
|
17
17
|
const VimeoEmbedItem = ({ item, sectionId }) => {
|
|
18
|
+
var _a;
|
|
18
19
|
const id = (0, react_1.useId)();
|
|
19
20
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
20
21
|
const { radius, blur } = (0, useEmbedVideoItem_1.useEmbedVideoItem)(item, sectionId);
|
|
@@ -36,7 +37,7 @@ const VimeoEmbedItem = ({ item, sectionId }) => {
|
|
|
36
37
|
return validURL.href;
|
|
37
38
|
};
|
|
38
39
|
const validUrl = getValidVimeoUrl(url);
|
|
39
|
-
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: item.link
|
|
40
|
+
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, Object.assign({ url: (_a = item.link) === null || _a === void 0 ? void 0 : _a.url }, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ className: `embed-video-wrapper-${item.id}`, style: {
|
|
40
41
|
borderRadius: `${radius * 100}vw`,
|
|
41
42
|
transform: `rotate(${angle}deg)`,
|
|
42
43
|
filter: `blur(${blur * 100}vw)`
|
|
@@ -48,7 +49,7 @@ const VimeoEmbedItem = ({ item, sectionId }) => {
|
|
|
48
49
|
if (!vimeoPlayer || play !== 'on-hover')
|
|
49
50
|
return;
|
|
50
51
|
vimeoPlayer.pause();
|
|
51
|
-
}, 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: `
|
|
52
|
+
} }, { 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, Object.assign({ id: id }, { children: `
|
|
52
53
|
.embed-video-wrapper-${item.id} {
|
|
53
54
|
position: absolute;
|
|
54
55
|
overflow: hidden;
|
|
@@ -71,6 +72,6 @@ const VimeoEmbedItem = ({ item, sectionId }) => {
|
|
|
71
72
|
}
|
|
72
73
|
`);
|
|
73
74
|
})}
|
|
74
|
-
` })] }));
|
|
75
|
+
` }))] })));
|
|
75
76
|
};
|
|
76
77
|
exports.VimeoEmbedItem = VimeoEmbedItem;
|
|
@@ -16,6 +16,7 @@ const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
|
|
|
16
16
|
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
17
17
|
const useYouTubeIframeApi_1 = require("../../utils/Youtube/useYouTubeIframeApi");
|
|
18
18
|
const YoutubeEmbedItem = ({ item, sectionId }) => {
|
|
19
|
+
var _a;
|
|
19
20
|
const id = (0, react_1.useId)();
|
|
20
21
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
21
22
|
const { play, controls, url } = item.commonParams;
|
|
@@ -48,12 +49,13 @@ const YoutubeEmbedItem = ({ item, sectionId }) => {
|
|
|
48
49
|
}
|
|
49
50
|
});
|
|
50
51
|
return () => {
|
|
52
|
+
var _a;
|
|
51
53
|
setPlayer(undefined);
|
|
52
54
|
player.destroy();
|
|
53
|
-
placeholder.parentElement
|
|
55
|
+
(_a = placeholder.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(placeholder);
|
|
54
56
|
};
|
|
55
57
|
}, [YT, div]);
|
|
56
|
-
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: item.link
|
|
58
|
+
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, Object.assign({ url: (_a = item.link) === null || _a === void 0 ? void 0 : _a.url }, { children: [(0, jsx_runtime_1.jsx)("div", { className: `embed-youtube-video-wrapper-${item.id}`, onMouseEnter: () => {
|
|
57
59
|
if (!player || play !== 'on-hover')
|
|
58
60
|
return;
|
|
59
61
|
player.playVideo();
|
|
@@ -65,7 +67,7 @@ const YoutubeEmbedItem = ({ item, sectionId }) => {
|
|
|
65
67
|
borderRadius: `${radius * 100}vw`,
|
|
66
68
|
transform: `rotate(${angle}deg)`,
|
|
67
69
|
filter: `blur(${blur * 100}vw)`
|
|
68
|
-
} }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
70
|
+
} }), (0, jsx_runtime_1.jsx)(style_1.default, Object.assign({ id: id }, { children: `
|
|
69
71
|
.embed-youtube-video-wrapper-${item.id} {
|
|
70
72
|
position: absolute;
|
|
71
73
|
overflow: hidden;
|
|
@@ -88,6 +90,6 @@ const YoutubeEmbedItem = ({ item, sectionId }) => {
|
|
|
88
90
|
}
|
|
89
91
|
`);
|
|
90
92
|
})}
|
|
91
|
-
` })] }));
|
|
93
|
+
` }))] })));
|
|
92
94
|
};
|
|
93
95
|
exports.YoutubeEmbedItem = YoutubeEmbedItem;
|
|
@@ -6,13 +6,14 @@ const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
|
6
6
|
const useLayoutContext_1 = require("../useLayoutContext");
|
|
7
7
|
const richTextConv = new RichTextConverter_1.RichTextConverter();
|
|
8
8
|
const useRichTextItem = (item) => {
|
|
9
|
+
var _a;
|
|
9
10
|
const layoutId = (0, useLayoutContext_1.useLayoutContext)();
|
|
10
11
|
const { layouts, typePresets } = (0, useCntrlContext_1.useCntrlContext)();
|
|
11
12
|
const presetId = layoutId ? item.layoutParams[layoutId].preset : null;
|
|
12
13
|
const preset = presetId
|
|
13
|
-
? typePresets
|
|
14
|
+
? (_a = typePresets === null || typePresets === void 0 ? void 0 : typePresets.presets.find(p => p.id === presetId)) !== null && _a !== void 0 ? _a : null
|
|
14
15
|
: null;
|
|
15
|
-
const [content, styles] = richTextConv.toHtml(item, layouts);
|
|
16
|
+
const [content, styles] = richTextConv.toHtml(item, layouts, !!preset);
|
|
16
17
|
return [content, styles, preset];
|
|
17
18
|
};
|
|
18
19
|
exports.useRichTextItem = useRichTextItem;
|
|
@@ -16,5 +16,5 @@ function getSectionHeightMap(sectionHeight) {
|
|
|
16
16
|
}
|
|
17
17
|
exports.getSectionHeightMap = getSectionHeightMap;
|
|
18
18
|
function getDefaultHeightData(layouts) {
|
|
19
|
-
return layouts.reduce((acc, layout) => ({
|
|
19
|
+
return layouts.reduce((acc, layout) => (Object.assign(Object.assign({}, acc), { [layout.id]: '0' })), {});
|
|
20
20
|
}
|
|
@@ -5,6 +5,6 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
5
5
|
const CntrlContext_1 = require("./CntrlContext");
|
|
6
6
|
const defaultContext_1 = require("./defaultContext");
|
|
7
7
|
const CntrlProvider = ({ children }) => {
|
|
8
|
-
return ((0, jsx_runtime_1.jsx)(CntrlContext_1.CntrlContext.Provider, { value: defaultContext_1.cntrlSdkContext, children: children }));
|
|
8
|
+
return ((0, jsx_runtime_1.jsx)(CntrlContext_1.CntrlContext.Provider, Object.assign({ value: defaultContext_1.cntrlSdkContext }, { children: children })));
|
|
9
9
|
};
|
|
10
10
|
exports.CntrlProvider = CntrlProvider;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.CntrlSdkContext = void 0;
|
|
4
13
|
class CntrlSdkContext {
|
|
@@ -8,17 +17,19 @@ class CntrlSdkContext {
|
|
|
8
17
|
this._layouts = [];
|
|
9
18
|
this.sectionHeightMap = new Map();
|
|
10
19
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
resolveSectionData(sections) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const resolvers = sections.map(section => {
|
|
23
|
+
const resolver = section.name ? this.customSections.getResolver(section.name) : undefined;
|
|
24
|
+
if (!resolver)
|
|
25
|
+
return;
|
|
26
|
+
return {
|
|
27
|
+
name: section.name,
|
|
28
|
+
resolver
|
|
29
|
+
};
|
|
30
|
+
}).filter(isDefined);
|
|
31
|
+
return Object.fromEntries(yield Promise.all(resolvers.map(({ name, resolver }) => __awaiter(this, void 0, void 0, function* () { return [name, yield resolver()]; }))));
|
|
32
|
+
});
|
|
22
33
|
}
|
|
23
34
|
init({ project, typePresets, article }) {
|
|
24
35
|
this.setTypePresets(typePresets);
|
|
@@ -10,10 +10,12 @@ class CustomSectionRegistry {
|
|
|
10
10
|
return this;
|
|
11
11
|
}
|
|
12
12
|
getComponent(name) {
|
|
13
|
-
|
|
13
|
+
var _a;
|
|
14
|
+
return (_a = this.definitions.get(name)) === null || _a === void 0 ? void 0 : _a.component;
|
|
14
15
|
}
|
|
15
16
|
getResolver(name) {
|
|
16
|
-
|
|
17
|
+
var _a;
|
|
18
|
+
return (_a = this.definitions.get(name)) === null || _a === void 0 ? void 0 : _a.dataResolver;
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
exports.CustomSectionRegistry = CustomSectionRegistry;
|
|
@@ -1,7 +1,11 @@
|
|
|
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.ArticleRectObserver = void 0;
|
|
4
7
|
const EventEmitter_1 = require("../EventEmitter");
|
|
8
|
+
const resize_observer_polyfill_1 = __importDefault(require("resize-observer-polyfill"));
|
|
5
9
|
class ArticleRectObserver extends EventEmitter_1.EventEmitter {
|
|
6
10
|
constructor() {
|
|
7
11
|
super();
|
|
@@ -14,7 +18,7 @@ class ArticleRectObserver extends EventEmitter_1.EventEmitter {
|
|
|
14
18
|
this.handleScroll = (scroll) => {
|
|
15
19
|
this.setScroll(scroll / this.articleWidth);
|
|
16
20
|
};
|
|
17
|
-
this.resizeObserver = new
|
|
21
|
+
this.resizeObserver = new resize_observer_polyfill_1.default(this.handleResize.bind(this));
|
|
18
22
|
}
|
|
19
23
|
get scroll() {
|
|
20
24
|
return this.scrollPos;
|
|
@@ -6,16 +6,18 @@ class EventEmitter {
|
|
|
6
6
|
this.listeners = {};
|
|
7
7
|
}
|
|
8
8
|
on(event, listener) {
|
|
9
|
+
var _a;
|
|
9
10
|
if (!Array.isArray(this.listeners[event])) {
|
|
10
11
|
this.listeners[event] = [];
|
|
11
12
|
}
|
|
12
|
-
this.listeners[event]
|
|
13
|
+
(_a = this.listeners[event]) === null || _a === void 0 ? void 0 : _a.push(listener);
|
|
13
14
|
return () => {
|
|
14
15
|
this.off(event, listener);
|
|
15
16
|
};
|
|
16
17
|
}
|
|
17
18
|
off(event, listener) {
|
|
18
|
-
|
|
19
|
+
var _a;
|
|
20
|
+
const filtered = (_a = this.listeners[event]) === null || _a === void 0 ? void 0 : _a.filter(l => l !== listener);
|
|
19
21
|
this.listeners[event] = filtered && filtered.length > 0 ? filtered : undefined;
|
|
20
22
|
}
|
|
21
23
|
emit(event, payload) {
|
|
@@ -10,7 +10,8 @@ exports.FontStyles = {
|
|
|
10
10
|
'italic': { 'font-style': 'italic' }
|
|
11
11
|
};
|
|
12
12
|
class RichTextConverter {
|
|
13
|
-
toHtml(richText, layouts) {
|
|
13
|
+
toHtml(richText, layouts, hasPreset) {
|
|
14
|
+
var _a, _b, _c;
|
|
14
15
|
const { text, blocks = [] } = richText.commonParams;
|
|
15
16
|
const root = [];
|
|
16
17
|
const styleRules = layouts.reduce((rec, layout) => {
|
|
@@ -18,21 +19,22 @@ class RichTextConverter {
|
|
|
18
19
|
return rec;
|
|
19
20
|
}, {});
|
|
20
21
|
let currentLineHeight = layouts.reduce((rec, layout) => {
|
|
22
|
+
var _a, _b;
|
|
21
23
|
const styles = richText.layoutParams[layout.id].styles;
|
|
22
|
-
rec[layout.id] = styles
|
|
24
|
+
rec[layout.id] = (_b = (_a = styles === null || styles === void 0 ? void 0 : styles.find(s => s.style === 'LINEHEIGHT')) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '0';
|
|
23
25
|
return rec;
|
|
24
26
|
}, {});
|
|
25
27
|
for (let blockIndex = 0; blockIndex < blocks.length; blockIndex++) {
|
|
26
28
|
const block = blocks[blockIndex];
|
|
27
29
|
const content = text.slice(block.start, block.end);
|
|
28
|
-
const entities = block.entities.sort((a, b) => a.start - b.start)
|
|
30
|
+
const entities = (_a = block.entities.sort((a, b) => a.start - b.start)) !== null && _a !== void 0 ? _a : [];
|
|
29
31
|
if (content.length === 0) {
|
|
30
|
-
root.push((0, jsx_runtime_1.jsx)("div", { className: `rt_${richText.id}_br_${blockIndex}
|
|
32
|
+
root.push((0, jsx_runtime_1.jsx)("div", Object.assign({ className: `rt_${richText.id}_br_${blockIndex}` }, { children: (0, jsx_runtime_1.jsx)("br", {}) })));
|
|
31
33
|
layouts.forEach(l => {
|
|
32
34
|
const lh = RichTextConverter.fromDraftToInline({
|
|
33
35
|
name: 'LINEHEIGHT',
|
|
34
36
|
value: currentLineHeight[l.id]
|
|
35
|
-
}
|
|
37
|
+
});
|
|
36
38
|
styleRules[l.id].push(`.rt_${richText.id}_br_${blockIndex} {${lh}}`);
|
|
37
39
|
});
|
|
38
40
|
continue;
|
|
@@ -41,13 +43,13 @@ class RichTextConverter {
|
|
|
41
43
|
const params = richText.layoutParams[layoutId];
|
|
42
44
|
const styles = params.styles
|
|
43
45
|
.filter(s => s.start >= block.start && s.end <= block.end)
|
|
44
|
-
.map(s => ({
|
|
46
|
+
.map(s => (Object.assign(Object.assign({}, s), { start: s.start - block.start, end: s.end - block.start })));
|
|
45
47
|
return ({
|
|
46
48
|
layout: layoutId,
|
|
47
49
|
styles: this.normalizeStyles(styles, entities)
|
|
48
50
|
});
|
|
49
51
|
});
|
|
50
|
-
const sameLayouts = groupBy(newStylesGroup, (item) => this.serializeRanges(item.styles
|
|
52
|
+
const sameLayouts = groupBy(newStylesGroup, (item) => { var _a; return this.serializeRanges((_a = item.styles) !== null && _a !== void 0 ? _a : []); });
|
|
51
53
|
for (const group of Object.values(sameLayouts)) {
|
|
52
54
|
const blockClass = `rt_${richText.id}-b${blockIndex}_${layouts.map(l => group.some(g => g.layout === l.id) ? '1' : '0').join('')}`;
|
|
53
55
|
const kids = [];
|
|
@@ -60,11 +62,12 @@ class RichTextConverter {
|
|
|
60
62
|
text-align: ${ta};
|
|
61
63
|
white-space: ${whiteSpace};
|
|
62
64
|
overflow-wrap: break-word;
|
|
65
|
+
${!hasPreset ? 'line-height: 0;' : ''}
|
|
63
66
|
}
|
|
64
67
|
`);
|
|
65
68
|
});
|
|
66
69
|
const item = group[0];
|
|
67
|
-
const entitiesGroups = this.groupEntities(entities, item.styles)
|
|
70
|
+
const entitiesGroups = (_b = this.groupEntities(entities, item.styles)) !== null && _b !== void 0 ? _b : [];
|
|
68
71
|
let offset = 0;
|
|
69
72
|
for (const entity of entitiesGroups) {
|
|
70
73
|
const entityKids = [];
|
|
@@ -76,7 +79,7 @@ class RichTextConverter {
|
|
|
76
79
|
if (offset < style.start) {
|
|
77
80
|
entityKids.push(sliceSymbols(content, offset, style.start));
|
|
78
81
|
}
|
|
79
|
-
entityKids.push((0, jsx_runtime_1.jsx)("span", { className: `s-${style.start}-${style.end}
|
|
82
|
+
entityKids.push((0, jsx_runtime_1.jsx)("span", Object.assign({ className: `s-${style.start}-${style.end}` }, { children: sliceSymbols(content, style.start, style.end) }), style.start));
|
|
80
83
|
offset = style.end;
|
|
81
84
|
}
|
|
82
85
|
if (offset < entity.end) {
|
|
@@ -84,7 +87,7 @@ class RichTextConverter {
|
|
|
84
87
|
offset = entity.end;
|
|
85
88
|
}
|
|
86
89
|
if (entity.link) {
|
|
87
|
-
kids.push((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: entity.link, children: entityKids }, entity.start));
|
|
90
|
+
kids.push((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, Object.assign({ url: entity.link }, { children: entityKids }), entity.start));
|
|
88
91
|
continue;
|
|
89
92
|
}
|
|
90
93
|
kids.push(...entityKids);
|
|
@@ -93,20 +96,19 @@ class RichTextConverter {
|
|
|
93
96
|
kids.push(sliceSymbols(content, offset));
|
|
94
97
|
}
|
|
95
98
|
for (const item of group) {
|
|
96
|
-
const
|
|
97
|
-
const entitiesGroups = this.groupEntities(entities, item.styles) ?? [];
|
|
99
|
+
const entitiesGroups = (_c = this.groupEntities(entities, item.styles)) !== null && _c !== void 0 ? _c : [];
|
|
98
100
|
for (const entitiesGroup of entitiesGroups) {
|
|
99
101
|
if (!entitiesGroup.stylesGroup)
|
|
100
102
|
continue;
|
|
101
103
|
for (const styleGroup of entitiesGroup.stylesGroup) {
|
|
102
104
|
const lineHeight = styleGroup.styles.find(s => s.name === 'LINEHEIGHT');
|
|
103
105
|
const color = styleGroup.styles.find(s => s.name === 'COLOR');
|
|
104
|
-
if (lineHeight
|
|
106
|
+
if (lineHeight === null || lineHeight === void 0 ? void 0 : lineHeight.value) {
|
|
105
107
|
currentLineHeight[item.layout] = lineHeight.value;
|
|
106
108
|
}
|
|
107
109
|
styleRules[item.layout].push(`
|
|
108
110
|
.${blockClass} .s-${styleGroup.start}-${styleGroup.end} {
|
|
109
|
-
${styleGroup.styles.map(s => RichTextConverter.fromDraftToInline(s
|
|
111
|
+
${styleGroup.styles.map(s => RichTextConverter.fromDraftToInline(s)).join('\n')}
|
|
110
112
|
}
|
|
111
113
|
`);
|
|
112
114
|
if (color) {
|
|
@@ -121,7 +123,7 @@ class RichTextConverter {
|
|
|
121
123
|
}
|
|
122
124
|
}
|
|
123
125
|
}
|
|
124
|
-
root.push((0, jsx_runtime_1.jsx)("div", { className: blockClass, children: kids }, blockClass));
|
|
126
|
+
root.push((0, jsx_runtime_1.jsx)("div", Object.assign({ className: blockClass }, { children: kids }), blockClass));
|
|
125
127
|
}
|
|
126
128
|
}
|
|
127
129
|
const styles = layouts.map(l => `
|
|
@@ -185,26 +187,22 @@ class RichTextConverter {
|
|
|
185
187
|
const start = entityDividers[i];
|
|
186
188
|
const end = entityDividers[i + 1];
|
|
187
189
|
const entity = entities.find(e => e.start === start);
|
|
188
|
-
entitiesGroups.push({
|
|
189
|
-
|
|
190
|
-
start,
|
|
191
|
-
end,
|
|
192
|
-
...(entity && { link: entity.data.url })
|
|
193
|
-
});
|
|
190
|
+
entitiesGroups.push(Object.assign({ stylesGroup: styleGroups.filter(s => s.start >= start && s.end <= end), start,
|
|
191
|
+
end }, (entity && { link: entity.data.url })));
|
|
194
192
|
}
|
|
195
193
|
return entitiesGroups;
|
|
196
194
|
}
|
|
197
|
-
static fromDraftToInline(draftStyle
|
|
195
|
+
static fromDraftToInline(draftStyle) {
|
|
198
196
|
const { value, name } = draftStyle;
|
|
199
197
|
const map = {
|
|
200
198
|
'COLOR': { 'color': getResolvedValue(value, name) },
|
|
201
199
|
'TYPEFACE': { 'font-family': `${value}` },
|
|
202
|
-
'FONTSTYLE': value ? {
|
|
200
|
+
'FONTSTYLE': value ? Object.assign({}, exports.FontStyles[value]) : {},
|
|
203
201
|
'FONTWEIGHT': { 'font-weight': value },
|
|
204
|
-
'FONTSIZE': { 'font-size': `${parseFloat(value) *
|
|
205
|
-
'LINEHEIGHT': { 'line-height': `${parseFloat(value) *
|
|
206
|
-
'LETTERSPACING': { 'letter-spacing': `${parseFloat(value) *
|
|
207
|
-
'WORDSPACING': { 'word-spacing': `${parseFloat(value) *
|
|
202
|
+
'FONTSIZE': { 'font-size': `${parseFloat(value) * 100}vw` },
|
|
203
|
+
'LINEHEIGHT': { 'line-height': `${parseFloat(value) * 100}vw` },
|
|
204
|
+
'LETTERSPACING': { 'letter-spacing': `${parseFloat(value) * 100}vw` },
|
|
205
|
+
'WORDSPACING': { 'word-spacing': `${parseFloat(value) * 100}vw` },
|
|
208
206
|
'TEXTTRANSFORM': value ? { 'text-transform': value } : { 'text-transform': sdk_1.TextTransform.None },
|
|
209
207
|
'VERTICALALIGN': value ? { 'vertical-align': value } : { 'vertical-align': sdk_1.VerticalAlign.Unset },
|
|
210
208
|
'TEXTDECORATION': { 'text-decoration': value }
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.captureStackTrace = exports.YouTubeIframeApiLoader = void 0;
|
|
4
13
|
const YT_IFRAME_API_URL = 'https://www.youtube.com/iframe_api';
|
|
@@ -12,12 +21,14 @@ class YouTubeIframeApiLoader {
|
|
|
12
21
|
constructor() {
|
|
13
22
|
this.loadingPromise = this.loadApi();
|
|
14
23
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
getApi() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
yield this.loadingPromise;
|
|
27
|
+
if (!window.YT) {
|
|
28
|
+
throw new Error('YouTube IFrame API is not loaded');
|
|
29
|
+
}
|
|
30
|
+
return window.YT;
|
|
31
|
+
});
|
|
21
32
|
}
|
|
22
33
|
loadApi() {
|
|
23
34
|
return new Promise((resolve, reject) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntrl-site/sdk-nextjs",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.3",
|
|
4
4
|
"description": "SDK for Next.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -21,16 +21,17 @@
|
|
|
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.10",
|
|
25
25
|
"@types/vimeo__player": "^2.18.0",
|
|
26
26
|
"@vimeo/player": "^2.20.1",
|
|
27
27
|
"html-react-parser": "^3.0.1",
|
|
28
|
+
"resize-observer-polyfill": "^1.5.1",
|
|
28
29
|
"styled-jsx": "^5.0.2"
|
|
29
30
|
},
|
|
30
31
|
"peerDependencies": {
|
|
31
32
|
"@types/lodash.isequal": "^4.5.6",
|
|
32
33
|
"lodash.isequal": "^4.5.0",
|
|
33
|
-
"next": "^13.
|
|
34
|
+
"next": "^13.0.0",
|
|
34
35
|
"react": "^18.2.0",
|
|
35
36
|
"react-dom": "^18.2.0"
|
|
36
37
|
},
|
|
@@ -4,17 +4,11 @@ import { ArticleRectContext } from '../provider/ArticleRectContext';
|
|
|
4
4
|
|
|
5
5
|
interface LayoutData {
|
|
6
6
|
layoutId: string;
|
|
7
|
-
exemplary: number;
|
|
8
7
|
start: number;
|
|
9
8
|
end: number;
|
|
10
9
|
}
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
layoutId: string | undefined;
|
|
14
|
-
layoutDeviation: number;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const useCurrentLayout = (): UseCurrentLayoutReturn => {
|
|
11
|
+
export const useCurrentLayout = (): string | undefined => {
|
|
18
12
|
const { layouts } = useCntrlContext();
|
|
19
13
|
const articleRectObserver = useContext(ArticleRectContext);
|
|
20
14
|
const layoutRanges = useMemo(() => {
|
|
@@ -25,7 +19,6 @@ export const useCurrentLayout = (): UseCurrentLayoutReturn => {
|
|
|
25
19
|
...acc,
|
|
26
20
|
{
|
|
27
21
|
layoutId: layout.id,
|
|
28
|
-
exemplary: layout.exemplary,
|
|
29
22
|
start: layout.startsWith,
|
|
30
23
|
end: next ? next.startsWith : Number.MAX_SAFE_INTEGER
|
|
31
24
|
}
|
|
@@ -33,20 +26,16 @@ export const useCurrentLayout = (): UseCurrentLayoutReturn => {
|
|
|
33
26
|
}, []);
|
|
34
27
|
}, [layouts]);
|
|
35
28
|
const getCurrentLayout = useCallback((articleWidth: number) => {
|
|
36
|
-
|
|
37
|
-
return range;
|
|
29
|
+
return layoutRanges.find(l => articleWidth >= l.start && articleWidth < l.end)?.layoutId;
|
|
38
30
|
}, [layoutRanges]);
|
|
39
31
|
const [layoutId, setLayoutId] = useState<string | undefined>(undefined);
|
|
40
|
-
const [deviation, setDeviation] = useState(1);
|
|
41
32
|
useEffect(() => {
|
|
42
33
|
if (!articleRectObserver) return;
|
|
43
34
|
return articleRectObserver.on('resize', () => {
|
|
44
35
|
const articleWidth = articleRectObserver.width;
|
|
45
|
-
|
|
46
|
-
setLayoutId(layoutId);
|
|
47
|
-
setDeviation(articleWidth / exemplary);
|
|
36
|
+
setLayoutId(getCurrentLayout(articleWidth));
|
|
48
37
|
});
|
|
49
38
|
}, [articleRectObserver, getCurrentLayout]);
|
|
50
39
|
|
|
51
|
-
return
|
|
40
|
+
return layoutId;
|
|
52
41
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { FC, PropsWithChildren, useEffect, useId, useState } from 'react';
|
|
2
2
|
import JSXStyle from 'styled-jsx/style';
|
|
3
3
|
import { useCurrentLayout } from '../common/useCurrentLayout';
|
|
4
4
|
import { LayoutContext } from '../provider/LayoutContext';
|
|
@@ -6,7 +6,7 @@ import { LayoutContext } from '../provider/LayoutContext';
|
|
|
6
6
|
export const ArticleWrapper: FC<PropsWithChildren<{}>> = ({ children }) => {
|
|
7
7
|
const id = useId();
|
|
8
8
|
const [isPageLoaded, setIsPageLoaded] = useState(false);
|
|
9
|
-
const
|
|
9
|
+
const layoutId = useCurrentLayout();
|
|
10
10
|
|
|
11
11
|
useEffect(() => {
|
|
12
12
|
const onPageLoad = () => {
|
|
@@ -19,17 +19,10 @@ export const ArticleWrapper: FC<PropsWithChildren<{}>> = ({ children }) => {
|
|
|
19
19
|
return () => window.removeEventListener('load', onPageLoad);
|
|
20
20
|
}
|
|
21
21
|
}, []);
|
|
22
|
-
const layoutDeviationStyle = {'--layout-deviation': layoutDeviation} as CSSProperties;
|
|
23
22
|
|
|
24
23
|
return (
|
|
25
24
|
<LayoutContext.Provider value={layoutId}>
|
|
26
|
-
<div
|
|
27
|
-
className="article-wrapper"
|
|
28
|
-
style={{
|
|
29
|
-
opacity: layoutId && isPageLoaded ? 1 : 0,
|
|
30
|
-
...layoutDeviationStyle
|
|
31
|
-
}}
|
|
32
|
-
>
|
|
25
|
+
<div className="article-wrapper" style={{ opacity: layoutId && isPageLoaded ? 1 : 0 }}>
|
|
33
26
|
{children}
|
|
34
27
|
</div>
|
|
35
28
|
<JSXStyle id={id}>{`
|
package/src/components/Item.tsx
CHANGED
|
@@ -51,7 +51,6 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item, sectionId}) => {
|
|
|
51
51
|
const id = useId();
|
|
52
52
|
const { layouts } = useCntrlContext();
|
|
53
53
|
const layout = useLayoutContext();
|
|
54
|
-
const exemplary = layouts.find(l => l.id === layout)?.exemplary ?? 1;
|
|
55
54
|
const [wrapperHeight, setWrapperHeight] = useState<undefined | number>(undefined);
|
|
56
55
|
const { scale, scaleAnchor } = useItemScale(item, sectionId);
|
|
57
56
|
const { top, left } = useItemPosition(item, sectionId);
|
|
@@ -87,16 +86,10 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item, sectionId}) => {
|
|
|
87
86
|
isInitialRef.current = false;
|
|
88
87
|
}, []);
|
|
89
88
|
|
|
90
|
-
const isRichText = isItemType(item, ArticleItemType.RichText);
|
|
91
|
-
|
|
92
89
|
const styles = {
|
|
93
90
|
transform: `scale(${scale})`,
|
|
94
91
|
transformOrigin: ScaleAnchorMap[scaleAnchor],
|
|
95
|
-
width: `${sizingAxis.x === SizingType.Manual
|
|
96
|
-
? isRichText
|
|
97
|
-
? `${width * exemplary}px`
|
|
98
|
-
: `${width * 100}vw`
|
|
99
|
-
: 'max-content'}`,
|
|
92
|
+
width: `${sizingAxis.x === SizingType.Manual ? `${width * 100}vw` : 'max-content'}`,
|
|
100
93
|
height: `${sizingAxis.y === SizingType.Manual ? `${height * 100}vw` : 'unset'}`,
|
|
101
94
|
top: stickyTop
|
|
102
95
|
};
|
|
@@ -6,6 +6,7 @@ import { useRichTextItem } from './useRichTextItem';
|
|
|
6
6
|
import { useCntrlContext } from '../../provider/useCntrlContext';
|
|
7
7
|
import { getHoverStyles, getTransitions } from '../../utils/HoverStyles/HoverStyles';
|
|
8
8
|
import { useRichTextItemValues } from './useRichTextItemValues';
|
|
9
|
+
import ResizeObserver from 'resize-observer-polyfill';
|
|
9
10
|
|
|
10
11
|
export const RichTextItem: FC<ItemProps<TRichTextItem>> = ({ item, sectionId, onResize }) => {
|
|
11
12
|
const [content, styles, preset] = useRichTextItem(item);
|
|
@@ -37,12 +38,7 @@ export const RichTextItem: FC<ItemProps<TRichTextItem>> = ({ item, sectionId, on
|
|
|
37
38
|
filter: `blur(${blur * 100}vw)`
|
|
38
39
|
}}
|
|
39
40
|
>
|
|
40
|
-
|
|
41
|
-
transformOrigin: 'top left',
|
|
42
|
-
transform: 'scale(var(--layout-deviation))'
|
|
43
|
-
}}>
|
|
44
|
-
{content}
|
|
45
|
-
</div>
|
|
41
|
+
{content}
|
|
46
42
|
</div>
|
|
47
43
|
<JSXStyle id={id}>
|
|
48
44
|
{styles}
|
|
@@ -13,6 +13,6 @@ export const useRichTextItem = (item: TRichTextItem): [ReactNode[], string, TTyp
|
|
|
13
13
|
const preset = presetId
|
|
14
14
|
? typePresets?.presets.find(p => p.id === presetId) ?? null
|
|
15
15
|
: null;
|
|
16
|
-
const [content, styles] = richTextConv.toHtml(item, layouts);
|
|
16
|
+
const [content, styles] = richTextConv.toHtml(item, layouts, !!preset);
|
|
17
17
|
return [content, styles, preset];
|
|
18
18
|
};
|
|
@@ -38,7 +38,8 @@ export const FontStyles: Record<string, Record<string, string>> = {
|
|
|
38
38
|
export class RichTextConverter {
|
|
39
39
|
toHtml(
|
|
40
40
|
richText: TRichTextItem,
|
|
41
|
-
layouts: TLayout[]
|
|
41
|
+
layouts: TLayout[],
|
|
42
|
+
hasPreset: boolean
|
|
42
43
|
): [ReactNode[], string] {
|
|
43
44
|
const { text, blocks = [] } = richText.commonParams;
|
|
44
45
|
const root: ReactElement[] = [];
|
|
@@ -62,7 +63,7 @@ export class RichTextConverter {
|
|
|
62
63
|
const lh = RichTextConverter.fromDraftToInline({
|
|
63
64
|
name: 'LINEHEIGHT',
|
|
64
65
|
value: currentLineHeight[l.id]
|
|
65
|
-
}
|
|
66
|
+
});
|
|
66
67
|
styleRules[l.id].push(`.rt_${richText.id}_br_${blockIndex} {${lh}}`);
|
|
67
68
|
});
|
|
68
69
|
continue;
|
|
@@ -90,6 +91,7 @@ export class RichTextConverter {
|
|
|
90
91
|
text-align: ${ta};
|
|
91
92
|
white-space: ${whiteSpace};
|
|
92
93
|
overflow-wrap: break-word;
|
|
94
|
+
${!hasPreset ? 'line-height: 0;' : ''}
|
|
93
95
|
}
|
|
94
96
|
`);
|
|
95
97
|
});
|
|
@@ -127,7 +129,6 @@ export class RichTextConverter {
|
|
|
127
129
|
kids.push(sliceSymbols(content, offset));
|
|
128
130
|
}
|
|
129
131
|
for (const item of group) {
|
|
130
|
-
const { exemplary } = layouts.find(l => l.id === item.layout)!;
|
|
131
132
|
const entitiesGroups = this.groupEntities(entities, item.styles) ?? [];
|
|
132
133
|
for (const entitiesGroup of entitiesGroups) {
|
|
133
134
|
if (!entitiesGroup.stylesGroup) continue;
|
|
@@ -139,7 +140,7 @@ export class RichTextConverter {
|
|
|
139
140
|
}
|
|
140
141
|
styleRules[item.layout].push(`
|
|
141
142
|
.${blockClass} .s-${styleGroup.start}-${styleGroup.end} {
|
|
142
|
-
${styleGroup.styles.map(s => RichTextConverter.fromDraftToInline(s
|
|
143
|
+
${styleGroup.styles.map(s => RichTextConverter.fromDraftToInline(s)).join('\n')}
|
|
143
144
|
}
|
|
144
145
|
`);
|
|
145
146
|
if (color) {
|
|
@@ -231,17 +232,17 @@ export class RichTextConverter {
|
|
|
231
232
|
return entitiesGroups;
|
|
232
233
|
}
|
|
233
234
|
|
|
234
|
-
private static fromDraftToInline(draftStyle: Style
|
|
235
|
+
private static fromDraftToInline(draftStyle: Style): string {
|
|
235
236
|
const { value, name } = draftStyle;
|
|
236
237
|
const map: Record<string, Record<string, string | undefined>> = {
|
|
237
238
|
'COLOR': { 'color': getResolvedValue(value, name) },
|
|
238
239
|
'TYPEFACE': { 'font-family': `${value}` },
|
|
239
240
|
'FONTSTYLE': value ? { ...FontStyles[value] } : {},
|
|
240
241
|
'FONTWEIGHT': { 'font-weight': value },
|
|
241
|
-
'FONTSIZE': { 'font-size': `${parseFloat(value!) *
|
|
242
|
-
'LINEHEIGHT': { 'line-height': `${parseFloat(value!) *
|
|
243
|
-
'LETTERSPACING': { 'letter-spacing': `${parseFloat(value!) *
|
|
244
|
-
'WORDSPACING': { 'word-spacing': `${parseFloat(value!) *
|
|
242
|
+
'FONTSIZE': { 'font-size': `${parseFloat(value!) * 100}vw` },
|
|
243
|
+
'LINEHEIGHT': { 'line-height': `${parseFloat(value!) * 100}vw` },
|
|
244
|
+
'LETTERSPACING': { 'letter-spacing': `${parseFloat(value!) * 100}vw` },
|
|
245
|
+
'WORDSPACING': { 'word-spacing': `${parseFloat(value!) * 100}vw` },
|
|
245
246
|
'TEXTTRANSFORM': value ? { 'text-transform': value as TextTransform } : { 'text-transform': TextTransform.None },
|
|
246
247
|
'VERTICALALIGN': value ? { 'vertical-align': value as VerticalAlign } : { 'vertical-align': VerticalAlign.Unset },
|
|
247
248
|
'TEXTDECORATION': { 'text-decoration': value }
|
|
Binary file
|