@cntrl-site/sdk-nextjs 0.15.2-beta.0 → 0.15.5-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/cntrl-site-sdk-nextjs-0.15.2.tgz +0 -0
- package/cntrl-site-sdk-nextjs-0.15.3.tgz +0 -0
- package/cntrl-site-sdk-nextjs-0.15.5-beta.0.tgz +0 -0
- package/lib/components/Article.js +4 -4
- package/lib/components/ArticleWrapper.js +6 -9
- package/lib/components/Head.js +4 -6
- package/lib/components/Item.js +19 -15
- 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 +8 -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 +2 -1
- 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 +16 -18
- package/lib/utils/Youtube/YouTubeIframeApiLoader.js +17 -6
- package/package.json +4 -3
- package/src/components/ArticleWrapper.tsx +4 -4
- package/src/components/Item.tsx +16 -9
- package/src/components/items/RichTextItem.tsx +3 -2
- package/src/utils/ArticleRectManager/ArticleRectObserver.ts +1 -0
- package/cntrl-site-sdk-nextjs-0.15.1.tgz +0 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -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;
|
|
@@ -17,23 +17,20 @@ const ArticleWrapper = ({ children }) => {
|
|
|
17
17
|
const onPageLoad = () => {
|
|
18
18
|
setIsPageLoaded(true);
|
|
19
19
|
};
|
|
20
|
-
if (document.readyState === '
|
|
21
|
-
onPageLoad
|
|
20
|
+
if (document.readyState === 'loading') {
|
|
21
|
+
window.addEventListener('DOMContentLoaded', onPageLoad);
|
|
22
|
+
return () => window.removeEventListener('DOMContentLoaded', onPageLoad);
|
|
22
23
|
}
|
|
23
24
|
else {
|
|
24
|
-
|
|
25
|
-
return () => window.removeEventListener('load', onPageLoad);
|
|
25
|
+
onPageLoad();
|
|
26
26
|
}
|
|
27
27
|
}, []);
|
|
28
28
|
const layoutDeviationStyle = { '--layout-deviation': layoutDeviation };
|
|
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: `
|
|
29
|
+
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: Object.assign({ opacity: layoutId && isPageLoaded ? 1 : 0 }, layoutDeviationStyle) }, { children: children })), (0, jsx_runtime_1.jsx)(style_1.default, Object.assign({ id: id }, { children: `
|
|
33
30
|
.article-wrapper {
|
|
34
31
|
opacity: 1;
|
|
35
32
|
transition: opacity 0.2s ease;
|
|
36
33
|
}
|
|
37
|
-
` })] }));
|
|
34
|
+
` }))] })));
|
|
38
35
|
};
|
|
39
36
|
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
|
@@ -37,10 +37,11 @@ const itemsMap = {
|
|
|
37
37
|
};
|
|
38
38
|
const noop = () => null;
|
|
39
39
|
const Item = ({ item, sectionId }) => {
|
|
40
|
+
var _a, _b;
|
|
40
41
|
const id = (0, react_1.useId)();
|
|
41
42
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
42
43
|
const layout = (0, useLayoutContext_1.useLayoutContext)();
|
|
43
|
-
const exemplary = layouts.find(l => l.id === layout)
|
|
44
|
+
const exemplary = (_b = (_a = layouts.find(l => l.id === layout)) === null || _a === void 0 ? void 0 : _a.exemplary) !== null && _b !== void 0 ? _b : 1;
|
|
44
45
|
const [wrapperHeight, setWrapperHeight] = (0, react_1.useState)(undefined);
|
|
45
46
|
const { scale, scaleAnchor } = (0, useItemScale_1.useItemScale)(item, sectionId);
|
|
46
47
|
const { top, left } = (0, useItemPosition_1.useItemPosition)(item, sectionId);
|
|
@@ -74,18 +75,20 @@ const Item = ({ item, sectionId }) => {
|
|
|
74
75
|
isInitialRef.current = false;
|
|
75
76
|
}, []);
|
|
76
77
|
const isRichText = isItemType(item, sdk_1.ArticleItemType.RichText);
|
|
77
|
-
const
|
|
78
|
-
transform:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
78
|
+
const scaleIfRichText = isRichText
|
|
79
|
+
? { transformOrigin: 'top left', transform: 'scale(var(--layout-deviation))' }
|
|
80
|
+
: {};
|
|
81
|
+
const styles = Object.assign(Object.assign({}, scaleIfRichText), { top: stickyTop });
|
|
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)("div", Object.assign({ style: {
|
|
83
|
+
width: `${sizingAxis.x === sdk_1.ArticleItemSizingType.Manual
|
|
84
|
+
? isRichText
|
|
85
|
+
? `${width * exemplary}px`
|
|
86
|
+
: `${width * 100}vw`
|
|
87
|
+
: 'max-content'}`,
|
|
88
|
+
height: `${sizingAxis.y === sdk_1.ArticleItemSizingType.Manual ? `${height * 100}vw` : 'unset'}`,
|
|
89
|
+
transform: `scale(${scale})`,
|
|
90
|
+
transformOrigin: ScaleAnchorMap_1.ScaleAnchorMap[scaleAnchor]
|
|
91
|
+
} }, { 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
92
|
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, hidden, hoverParams, sticky, sectionHeight, layoutParams]) => {
|
|
90
93
|
const sizingAxis = parseSizing(layoutParams.sizing);
|
|
91
94
|
return (`
|
|
@@ -121,11 +124,12 @@ const Item = ({ item, sectionId }) => {
|
|
|
121
124
|
}
|
|
122
125
|
`);
|
|
123
126
|
})}
|
|
124
|
-
` })] }));
|
|
127
|
+
` }))] })));
|
|
125
128
|
};
|
|
126
129
|
exports.Item = Item;
|
|
127
130
|
function getStickyItemWrapperHeight(sticky, itemHeight) {
|
|
128
|
-
|
|
131
|
+
var _a;
|
|
132
|
+
const end = (_a = sticky.to) !== null && _a !== void 0 ? _a : 100;
|
|
129
133
|
return end - sticky.from + itemHeight;
|
|
130
134
|
}
|
|
131
135
|
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,13 @@ 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.jsx)("div", { className: "rich-text-scale", style: {
|
|
38
|
-
|
|
39
|
-
|
|
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: (0, jsx_runtime_1.jsx)("div", Object.assign({ className: "rich-text-scale", style: {
|
|
39
|
+
// transformOrigin: 'top left',
|
|
40
|
+
// transform: 'scale(var(--layout-deviation))'
|
|
41
|
+
} }, { 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
42
|
return (`
|
|
42
43
|
.rich-text-wrapper-${item.id} {
|
|
43
44
|
transition: ${(0, HoverStyles_1.getTransitions)(['angle', 'blur'], hoverParams)};
|
|
@@ -46,6 +47,6 @@ const RichTextItem = ({ item, sectionId, onResize }) => {
|
|
|
46
47
|
${(0, HoverStyles_1.getHoverStyles)(['angle', 'blur'], hoverParams)}
|
|
47
48
|
}
|
|
48
49
|
`);
|
|
49
|
-
})}`] })] }));
|
|
50
|
+
})}`] }))] }));
|
|
50
51
|
};
|
|
51
52
|
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,11 +6,12 @@ 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
16
|
const [content, styles] = richTextConv.toHtml(item, layouts);
|
|
16
17
|
return [content, styles, preset];
|
|
@@ -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) {
|
|
@@ -11,6 +11,7 @@ exports.FontStyles = {
|
|
|
11
11
|
};
|
|
12
12
|
class RichTextConverter {
|
|
13
13
|
toHtml(richText, layouts) {
|
|
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,16 +19,17 @@ 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',
|
|
@@ -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 = [];
|
|
@@ -64,7 +66,7 @@ class RichTextConverter {
|
|
|
64
66
|
`);
|
|
65
67
|
});
|
|
66
68
|
const item = group[0];
|
|
67
|
-
const entitiesGroups = this.groupEntities(entities, item.styles)
|
|
69
|
+
const entitiesGroups = (_b = this.groupEntities(entities, item.styles)) !== null && _b !== void 0 ? _b : [];
|
|
68
70
|
let offset = 0;
|
|
69
71
|
for (const entity of entitiesGroups) {
|
|
70
72
|
const entityKids = [];
|
|
@@ -76,7 +78,7 @@ class RichTextConverter {
|
|
|
76
78
|
if (offset < style.start) {
|
|
77
79
|
entityKids.push(sliceSymbols(content, offset, style.start));
|
|
78
80
|
}
|
|
79
|
-
entityKids.push((0, jsx_runtime_1.jsx)("span", { className: `s-${style.start}-${style.end}
|
|
81
|
+
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
82
|
offset = style.end;
|
|
81
83
|
}
|
|
82
84
|
if (offset < entity.end) {
|
|
@@ -84,7 +86,7 @@ class RichTextConverter {
|
|
|
84
86
|
offset = entity.end;
|
|
85
87
|
}
|
|
86
88
|
if (entity.link) {
|
|
87
|
-
kids.push((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: entity.link, children: entityKids }, entity.start));
|
|
89
|
+
kids.push((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, Object.assign({ url: entity.link }, { children: entityKids }), entity.start));
|
|
88
90
|
continue;
|
|
89
91
|
}
|
|
90
92
|
kids.push(...entityKids);
|
|
@@ -94,14 +96,14 @@ class RichTextConverter {
|
|
|
94
96
|
}
|
|
95
97
|
for (const item of group) {
|
|
96
98
|
const { exemplary } = layouts.find(l => l.id === item.layout);
|
|
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(`
|
|
@@ -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,12 +187,8 @@ 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
|
}
|
|
@@ -199,7 +197,7 @@ class RichTextConverter {
|
|
|
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
202
|
'FONTSIZE': { 'font-size': `${parseFloat(value) * exemplary}px` },
|
|
205
203
|
'LINEHEIGHT': { 'line-height': `${parseFloat(value) * exemplary}px` },
|
|
@@ -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.5-0",
|
|
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
|
},
|
|
@@ -12,11 +12,11 @@ export const ArticleWrapper: FC<PropsWithChildren<{}>> = ({ children }) => {
|
|
|
12
12
|
const onPageLoad = () => {
|
|
13
13
|
setIsPageLoaded(true);
|
|
14
14
|
};
|
|
15
|
-
if (document.readyState === '
|
|
16
|
-
onPageLoad
|
|
15
|
+
if (document.readyState === 'loading') {
|
|
16
|
+
window.addEventListener('DOMContentLoaded', onPageLoad);
|
|
17
|
+
return () => window.removeEventListener('DOMContentLoaded', onPageLoad);
|
|
17
18
|
} else {
|
|
18
|
-
|
|
19
|
-
return () => window.removeEventListener('load', onPageLoad);
|
|
19
|
+
onPageLoad();
|
|
20
20
|
}
|
|
21
21
|
}, []);
|
|
22
22
|
const layoutDeviationStyle = {'--layout-deviation': layoutDeviation} as CSSProperties;
|
package/src/components/Item.tsx
CHANGED
|
@@ -88,16 +88,12 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item, sectionId}) => {
|
|
|
88
88
|
}, []);
|
|
89
89
|
|
|
90
90
|
const isRichText = isItemType(item, ArticleItemType.RichText);
|
|
91
|
+
const scaleIfRichText = isRichText
|
|
92
|
+
? { transformOrigin: 'top left', transform: 'scale(var(--layout-deviation))' }
|
|
93
|
+
: {};
|
|
91
94
|
|
|
92
95
|
const styles = {
|
|
93
|
-
|
|
94
|
-
transformOrigin: ScaleAnchorMap[scaleAnchor],
|
|
95
|
-
width: `${sizingAxis.x === SizingType.Manual
|
|
96
|
-
? isRichText
|
|
97
|
-
? `${width * exemplary}px`
|
|
98
|
-
: `${width * 100}vw`
|
|
99
|
-
: 'max-content'}`,
|
|
100
|
-
height: `${sizingAxis.y === SizingType.Manual ? `${height * 100}vw` : 'unset'}`,
|
|
96
|
+
...scaleIfRichText,
|
|
101
97
|
top: stickyTop
|
|
102
98
|
};
|
|
103
99
|
|
|
@@ -111,7 +107,18 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item, sectionId}) => {
|
|
|
111
107
|
className={`item-${item.id}`}
|
|
112
108
|
style={isInitialRef.current ? {} : styles }
|
|
113
109
|
>
|
|
114
|
-
<
|
|
110
|
+
<div style={{
|
|
111
|
+
width: `${sizingAxis.x === SizingType.Manual
|
|
112
|
+
? isRichText
|
|
113
|
+
? `${width * exemplary}px`
|
|
114
|
+
: `${width * 100}vw`
|
|
115
|
+
: 'max-content'}`,
|
|
116
|
+
height: `${sizingAxis.y === SizingType.Manual ? `${height * 100}vw` : 'unset'}`,
|
|
117
|
+
transform: `scale(${scale})`,
|
|
118
|
+
transformOrigin: ScaleAnchorMap[scaleAnchor]
|
|
119
|
+
}}>
|
|
120
|
+
<ItemComponent item={item} sectionId={sectionId} onResize={handleItemResize} />
|
|
121
|
+
</div>
|
|
115
122
|
</div>
|
|
116
123
|
<JSXStyle id={id}>{`
|
|
117
124
|
${getLayoutStyles(layouts, layoutValues, ([area, hidden, hoverParams, sticky, sectionHeight, layoutParams]) => {
|
|
@@ -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);
|
|
@@ -38,8 +39,8 @@ export const RichTextItem: FC<ItemProps<TRichTextItem>> = ({ item, sectionId, on
|
|
|
38
39
|
}}
|
|
39
40
|
>
|
|
40
41
|
<div className="rich-text-scale" style={{
|
|
41
|
-
transformOrigin: 'top left',
|
|
42
|
-
transform: 'scale(var(--layout-deviation))'
|
|
42
|
+
// transformOrigin: 'top left',
|
|
43
|
+
// transform: 'scale(var(--layout-deviation))'
|
|
43
44
|
}}>
|
|
44
45
|
{content}
|
|
45
46
|
</div>
|
|
Binary file
|