@cntrl-site/sdk-nextjs 0.15.0 → 0.15.2-beta.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.1.tgz +0 -0
- package/cntrl-site-sdk-nextjs-0.15.2.tgz +0 -0
- package/lib/common/useCurrentLayout.js +8 -3
- package/lib/components/ArticleWrapper.js +6 -2
- package/lib/components/Head.js +10 -9
- package/lib/components/Item.js +7 -1
- package/lib/components/items/RichTextItem.js +4 -1
- package/lib/components/items/useRichTextItem.js +1 -1
- package/lib/utils/RichTextConverter/RichTextConverter.js +9 -9
- package/package.json +1 -1
- package/src/common/useCurrentLayout.ts +15 -4
- package/src/components/ArticleWrapper.tsx +10 -3
- package/src/components/Head.tsx +10 -9
- package/src/components/Item.tsx +8 -1
- package/src/components/items/RichTextItem.tsx +6 -1
- package/src/components/items/useRichTextItem.ts +1 -1
- package/src/utils/RichTextConverter/RichTextConverter.tsx +9 -10
- package/cntrl-site-sdk-nextjs-0.12.10.tgz +0 -0
- package/cntrl-site-sdk-nextjs-0.14.6.tgz +0 -0
- package/cntrl-site-sdk-nextjs-0.14.7.tgz +0 -0
|
Binary file
|
|
Binary file
|
|
@@ -15,6 +15,7 @@ const useCurrentLayout = () => {
|
|
|
15
15
|
...acc,
|
|
16
16
|
{
|
|
17
17
|
layoutId: layout.id,
|
|
18
|
+
exemplary: layout.exemplary,
|
|
18
19
|
start: layout.startsWith,
|
|
19
20
|
end: next ? next.startsWith : Number.MAX_SAFE_INTEGER
|
|
20
21
|
}
|
|
@@ -22,17 +23,21 @@ const useCurrentLayout = () => {
|
|
|
22
23
|
}, []);
|
|
23
24
|
}, [layouts]);
|
|
24
25
|
const getCurrentLayout = (0, react_1.useCallback)((articleWidth) => {
|
|
25
|
-
|
|
26
|
+
const range = layoutRanges.find(l => articleWidth >= l.start && articleWidth < l.end);
|
|
27
|
+
return range;
|
|
26
28
|
}, [layoutRanges]);
|
|
27
29
|
const [layoutId, setLayoutId] = (0, react_1.useState)(undefined);
|
|
30
|
+
const [deviation, setDeviation] = (0, react_1.useState)(1);
|
|
28
31
|
(0, react_1.useEffect)(() => {
|
|
29
32
|
if (!articleRectObserver)
|
|
30
33
|
return;
|
|
31
34
|
return articleRectObserver.on('resize', () => {
|
|
32
35
|
const articleWidth = articleRectObserver.width;
|
|
33
|
-
|
|
36
|
+
const { layoutId, exemplary } = getCurrentLayout(articleWidth);
|
|
37
|
+
setLayoutId(layoutId);
|
|
38
|
+
setDeviation(articleWidth / exemplary);
|
|
34
39
|
});
|
|
35
40
|
}, [articleRectObserver, getCurrentLayout]);
|
|
36
|
-
return layoutId;
|
|
41
|
+
return { layoutId, layoutDeviation: deviation };
|
|
37
42
|
};
|
|
38
43
|
exports.useCurrentLayout = useCurrentLayout;
|
|
@@ -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 layoutId = (0, useCurrentLayout_1.useCurrentLayout)();
|
|
15
|
+
const { layoutId, layoutDeviation } = (0, useCurrentLayout_1.useCurrentLayout)();
|
|
16
16
|
(0, react_1.useEffect)(() => {
|
|
17
17
|
const onPageLoad = () => {
|
|
18
18
|
setIsPageLoaded(true);
|
|
@@ -25,7 +25,11 @@ const ArticleWrapper = ({ children }) => {
|
|
|
25
25
|
return () => window.removeEventListener('load', 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
33
|
.article-wrapper {
|
|
30
34
|
opacity: 1;
|
|
31
35
|
transition: opacity 0.2s ease;
|
package/lib/components/Head.js
CHANGED
|
@@ -18,16 +18,17 @@ const CNTRLHead = ({ meta, project }) => {
|
|
|
18
18
|
const customFonts = project.fonts.custom;
|
|
19
19
|
const htmlHead = (0, html_react_parser_1.default)(project.html.head);
|
|
20
20
|
const ffGenerator = new sdk_1.FontFaceGenerator(customFonts);
|
|
21
|
+
const links = Object.values(parsedFonts).map((value, i) => {
|
|
22
|
+
if (!value)
|
|
23
|
+
return;
|
|
24
|
+
const rel = value?.rel || value.props?.rel;
|
|
25
|
+
const href = value?.href || value.props?.href;
|
|
26
|
+
if (!rel || !href)
|
|
27
|
+
return;
|
|
28
|
+
return ((0, jsx_runtime_1.jsx)("link", { rel: rel, href: href }, `link-${rel}-${href}`));
|
|
29
|
+
});
|
|
21
30
|
return ((0, jsx_runtime_1.jsxs)(head_1.default, { children: [(0, jsx_runtime_1.jsx)("title", { children: meta.title }), (0, jsx_runtime_1.jsx)("meta", { name: "description", content: meta.description }), (0, jsx_runtime_1.jsx)("meta", { name: "keywords", content: meta.keywords }), (0, jsx_runtime_1.jsx)("meta", { property: "og:image", content: meta.opengraphThumbnail }), (0, jsx_runtime_1.jsx)("link", { rel: "icon", href: meta.favicon }), customFonts.length > 0 && ((0, jsx_runtime_1.jsx)("style", { dangerouslySetInnerHTML: {
|
|
22
31
|
__html: ffGenerator.generate()
|
|
23
|
-
} })),
|
|
24
|
-
if (!value)
|
|
25
|
-
return undefined;
|
|
26
|
-
const rel = value?.rel || value.props?.rel;
|
|
27
|
-
const href = value?.href || value.props?.href;
|
|
28
|
-
if (!rel || !href)
|
|
29
|
-
return undefined;
|
|
30
|
-
return ((0, jsx_runtime_1.jsx)("link", { rel: rel, href: href }, i));
|
|
31
|
-
}), htmlHead] }));
|
|
32
|
+
} })), links, htmlHead] }));
|
|
32
33
|
};
|
|
33
34
|
exports.CNTRLHead = CNTRLHead;
|
package/lib/components/Item.js
CHANGED
|
@@ -40,6 +40,7 @@ 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;
|
|
43
44
|
const [wrapperHeight, setWrapperHeight] = (0, react_1.useState)(undefined);
|
|
44
45
|
const { scale, scaleAnchor } = (0, useItemScale_1.useItemScale)(item, sectionId);
|
|
45
46
|
const { top, left } = (0, useItemPosition_1.useItemPosition)(item, sectionId);
|
|
@@ -72,10 +73,15 @@ const Item = ({ item, sectionId }) => {
|
|
|
72
73
|
(0, react_1.useEffect)(() => {
|
|
73
74
|
isInitialRef.current = false;
|
|
74
75
|
}, []);
|
|
76
|
+
const isRichText = isItemType(item, sdk_1.ArticleItemType.RichText);
|
|
75
77
|
const styles = {
|
|
76
78
|
transform: `scale(${scale})`,
|
|
77
79
|
transformOrigin: ScaleAnchorMap_1.ScaleAnchorMap[scaleAnchor],
|
|
78
|
-
width: `${sizingAxis.x === sdk_1.ArticleItemSizingType.Manual
|
|
80
|
+
width: `${sizingAxis.x === sdk_1.ArticleItemSizingType.Manual
|
|
81
|
+
? isRichText
|
|
82
|
+
? `${width * exemplary}px`
|
|
83
|
+
: `${width * 100}vw`
|
|
84
|
+
: 'max-content'}`,
|
|
79
85
|
height: `${sizingAxis.y === sdk_1.ArticleItemSizingType.Manual ? `${height * 100}vw` : 'unset'}`,
|
|
80
86
|
top: stickyTop
|
|
81
87
|
};
|
|
@@ -34,7 +34,10 @@ const RichTextItem = ({ item, sectionId, onResize }) => {
|
|
|
34
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
35
|
transform: `rotate(${angle}deg)`,
|
|
36
36
|
filter: `blur(${blur * 100}vw)`
|
|
37
|
-
}, children:
|
|
37
|
+
}, children: (0, jsx_runtime_1.jsx)("div", { className: "rich-text-scale", style: {
|
|
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
41
|
return (`
|
|
39
42
|
.rich-text-wrapper-${item.id} {
|
|
40
43
|
transition: ${(0, HoverStyles_1.getTransitions)(['angle', 'blur'], hoverParams)};
|
|
@@ -12,7 +12,7 @@ const useRichTextItem = (item) => {
|
|
|
12
12
|
const preset = presetId
|
|
13
13
|
? typePresets?.presets.find(p => p.id === presetId) ?? null
|
|
14
14
|
: null;
|
|
15
|
-
const [content, styles] = richTextConv.toHtml(item, layouts
|
|
15
|
+
const [content, styles] = richTextConv.toHtml(item, layouts);
|
|
16
16
|
return [content, styles, preset];
|
|
17
17
|
};
|
|
18
18
|
exports.useRichTextItem = useRichTextItem;
|
|
@@ -10,7 +10,7 @@ exports.FontStyles = {
|
|
|
10
10
|
'italic': { 'font-style': 'italic' }
|
|
11
11
|
};
|
|
12
12
|
class RichTextConverter {
|
|
13
|
-
toHtml(richText, layouts
|
|
13
|
+
toHtml(richText, layouts) {
|
|
14
14
|
const { text, blocks = [] } = richText.commonParams;
|
|
15
15
|
const root = [];
|
|
16
16
|
const styleRules = layouts.reduce((rec, layout) => {
|
|
@@ -32,7 +32,7 @@ class RichTextConverter {
|
|
|
32
32
|
const lh = RichTextConverter.fromDraftToInline({
|
|
33
33
|
name: 'LINEHEIGHT',
|
|
34
34
|
value: currentLineHeight[l.id]
|
|
35
|
-
});
|
|
35
|
+
}, l.exemplary);
|
|
36
36
|
styleRules[l.id].push(`.rt_${richText.id}_br_${blockIndex} {${lh}}`);
|
|
37
37
|
});
|
|
38
38
|
continue;
|
|
@@ -60,7 +60,6 @@ class RichTextConverter {
|
|
|
60
60
|
text-align: ${ta};
|
|
61
61
|
white-space: ${whiteSpace};
|
|
62
62
|
overflow-wrap: break-word;
|
|
63
|
-
${!hasPreset ? 'line-height: 0;' : ''}
|
|
64
63
|
}
|
|
65
64
|
`);
|
|
66
65
|
});
|
|
@@ -94,6 +93,7 @@ class RichTextConverter {
|
|
|
94
93
|
kids.push(sliceSymbols(content, offset));
|
|
95
94
|
}
|
|
96
95
|
for (const item of group) {
|
|
96
|
+
const { exemplary } = layouts.find(l => l.id === item.layout);
|
|
97
97
|
const entitiesGroups = this.groupEntities(entities, item.styles) ?? [];
|
|
98
98
|
for (const entitiesGroup of entitiesGroups) {
|
|
99
99
|
if (!entitiesGroup.stylesGroup)
|
|
@@ -106,7 +106,7 @@ class RichTextConverter {
|
|
|
106
106
|
}
|
|
107
107
|
styleRules[item.layout].push(`
|
|
108
108
|
.${blockClass} .s-${styleGroup.start}-${styleGroup.end} {
|
|
109
|
-
${styleGroup.styles.map(s => RichTextConverter.fromDraftToInline(s)).join('\n')}
|
|
109
|
+
${styleGroup.styles.map(s => RichTextConverter.fromDraftToInline(s, exemplary)).join('\n')}
|
|
110
110
|
}
|
|
111
111
|
`);
|
|
112
112
|
if (color) {
|
|
@@ -194,17 +194,17 @@ class RichTextConverter {
|
|
|
194
194
|
}
|
|
195
195
|
return entitiesGroups;
|
|
196
196
|
}
|
|
197
|
-
static fromDraftToInline(draftStyle) {
|
|
197
|
+
static fromDraftToInline(draftStyle, exemplary) {
|
|
198
198
|
const { value, name } = draftStyle;
|
|
199
199
|
const map = {
|
|
200
200
|
'COLOR': { 'color': getResolvedValue(value, name) },
|
|
201
201
|
'TYPEFACE': { 'font-family': `${value}` },
|
|
202
202
|
'FONTSTYLE': value ? { ...exports.FontStyles[value] } : {},
|
|
203
203
|
'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) *
|
|
204
|
+
'FONTSIZE': { 'font-size': `${parseFloat(value) * exemplary}px` },
|
|
205
|
+
'LINEHEIGHT': { 'line-height': `${parseFloat(value) * exemplary}px` },
|
|
206
|
+
'LETTERSPACING': { 'letter-spacing': `${parseFloat(value) * exemplary}px` },
|
|
207
|
+
'WORDSPACING': { 'word-spacing': `${parseFloat(value) * exemplary}px` },
|
|
208
208
|
'TEXTTRANSFORM': value ? { 'text-transform': value } : { 'text-transform': sdk_1.TextTransform.None },
|
|
209
209
|
'VERTICALALIGN': value ? { 'vertical-align': value } : { 'vertical-align': sdk_1.VerticalAlign.Unset },
|
|
210
210
|
'TEXTDECORATION': { 'text-decoration': value }
|
package/package.json
CHANGED
|
@@ -4,11 +4,17 @@ import { ArticleRectContext } from '../provider/ArticleRectContext';
|
|
|
4
4
|
|
|
5
5
|
interface LayoutData {
|
|
6
6
|
layoutId: string;
|
|
7
|
+
exemplary: number;
|
|
7
8
|
start: number;
|
|
8
9
|
end: number;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
type UseCurrentLayoutReturn = {
|
|
13
|
+
layoutId: string | undefined;
|
|
14
|
+
layoutDeviation: number;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const useCurrentLayout = (): UseCurrentLayoutReturn => {
|
|
12
18
|
const { layouts } = useCntrlContext();
|
|
13
19
|
const articleRectObserver = useContext(ArticleRectContext);
|
|
14
20
|
const layoutRanges = useMemo(() => {
|
|
@@ -19,6 +25,7 @@ export const useCurrentLayout = (): string | undefined => {
|
|
|
19
25
|
...acc,
|
|
20
26
|
{
|
|
21
27
|
layoutId: layout.id,
|
|
28
|
+
exemplary: layout.exemplary,
|
|
22
29
|
start: layout.startsWith,
|
|
23
30
|
end: next ? next.startsWith : Number.MAX_SAFE_INTEGER
|
|
24
31
|
}
|
|
@@ -26,16 +33,20 @@ export const useCurrentLayout = (): string | undefined => {
|
|
|
26
33
|
}, []);
|
|
27
34
|
}, [layouts]);
|
|
28
35
|
const getCurrentLayout = useCallback((articleWidth: number) => {
|
|
29
|
-
|
|
36
|
+
const range = layoutRanges.find(l => articleWidth >= l.start && articleWidth < l.end);
|
|
37
|
+
return range;
|
|
30
38
|
}, [layoutRanges]);
|
|
31
39
|
const [layoutId, setLayoutId] = useState<string | undefined>(undefined);
|
|
40
|
+
const [deviation, setDeviation] = useState(1);
|
|
32
41
|
useEffect(() => {
|
|
33
42
|
if (!articleRectObserver) return;
|
|
34
43
|
return articleRectObserver.on('resize', () => {
|
|
35
44
|
const articleWidth = articleRectObserver.width;
|
|
36
|
-
|
|
45
|
+
const { layoutId, exemplary } = getCurrentLayout(articleWidth)!;
|
|
46
|
+
setLayoutId(layoutId);
|
|
47
|
+
setDeviation(articleWidth / exemplary);
|
|
37
48
|
});
|
|
38
49
|
}, [articleRectObserver, getCurrentLayout]);
|
|
39
50
|
|
|
40
|
-
return layoutId;
|
|
51
|
+
return { layoutId, layoutDeviation: deviation };
|
|
41
52
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { FC, PropsWithChildren, useEffect, useId, useState } from 'react';
|
|
1
|
+
import React, { CSSProperties, 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 layoutId = useCurrentLayout();
|
|
9
|
+
const { layoutId, layoutDeviation } = useCurrentLayout();
|
|
10
10
|
|
|
11
11
|
useEffect(() => {
|
|
12
12
|
const onPageLoad = () => {
|
|
@@ -19,10 +19,17 @@ 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;
|
|
22
23
|
|
|
23
24
|
return (
|
|
24
25
|
<LayoutContext.Provider value={layoutId}>
|
|
25
|
-
<div
|
|
26
|
+
<div
|
|
27
|
+
className="article-wrapper"
|
|
28
|
+
style={{
|
|
29
|
+
opacity: layoutId && isPageLoaded ? 1 : 0,
|
|
30
|
+
...layoutDeviationStyle
|
|
31
|
+
}}
|
|
32
|
+
>
|
|
26
33
|
{children}
|
|
27
34
|
</div>
|
|
28
35
|
<JSXStyle id={id}>{`
|
package/src/components/Head.tsx
CHANGED
|
@@ -18,6 +18,15 @@ export const CNTRLHead: FC<Props> = ({ meta, project }) => {
|
|
|
18
18
|
const customFonts = project.fonts.custom;
|
|
19
19
|
const htmlHead = HTMLReactParser(project.html.head);
|
|
20
20
|
const ffGenerator = new FontFaceGenerator(customFonts);
|
|
21
|
+
const links = Object.values(parsedFonts as ReturnType<typeof domToReact>).map((value, i) => {
|
|
22
|
+
if (!value) return;
|
|
23
|
+
const rel = value?.rel || value.props?.rel;
|
|
24
|
+
const href = value?.href || value.props?.href;
|
|
25
|
+
if (!rel || !href) return;
|
|
26
|
+
return (
|
|
27
|
+
<link key={`link-${rel}-${href}`} rel={rel} href={href} />
|
|
28
|
+
);
|
|
29
|
+
});
|
|
21
30
|
return (
|
|
22
31
|
<Head>
|
|
23
32
|
<title>{meta.title}</title>
|
|
@@ -32,15 +41,7 @@ export const CNTRLHead: FC<Props> = ({ meta, project }) => {
|
|
|
32
41
|
}}
|
|
33
42
|
/>
|
|
34
43
|
)}
|
|
35
|
-
{
|
|
36
|
-
if (!value) return undefined;
|
|
37
|
-
const rel = value?.rel || value.props?.rel;
|
|
38
|
-
const href = value?.href || value.props?.href;
|
|
39
|
-
if (!rel || !href) return undefined;
|
|
40
|
-
return (
|
|
41
|
-
<link key={i} rel={rel} href={href} />
|
|
42
|
-
);
|
|
43
|
-
})}
|
|
44
|
+
{links}
|
|
44
45
|
{htmlHead}
|
|
45
46
|
|
|
46
47
|
</Head>
|
package/src/components/Item.tsx
CHANGED
|
@@ -51,6 +51,7 @@ 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;
|
|
54
55
|
const [wrapperHeight, setWrapperHeight] = useState<undefined | number>(undefined);
|
|
55
56
|
const { scale, scaleAnchor } = useItemScale(item, sectionId);
|
|
56
57
|
const { top, left } = useItemPosition(item, sectionId);
|
|
@@ -86,10 +87,16 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item, sectionId}) => {
|
|
|
86
87
|
isInitialRef.current = false;
|
|
87
88
|
}, []);
|
|
88
89
|
|
|
90
|
+
const isRichText = isItemType(item, ArticleItemType.RichText);
|
|
91
|
+
|
|
89
92
|
const styles = {
|
|
90
93
|
transform: `scale(${scale})`,
|
|
91
94
|
transformOrigin: ScaleAnchorMap[scaleAnchor],
|
|
92
|
-
width: `${sizingAxis.x === SizingType.Manual
|
|
95
|
+
width: `${sizingAxis.x === SizingType.Manual
|
|
96
|
+
? isRichText
|
|
97
|
+
? `${width * exemplary}px`
|
|
98
|
+
: `${width * 100}vw`
|
|
99
|
+
: 'max-content'}`,
|
|
93
100
|
height: `${sizingAxis.y === SizingType.Manual ? `${height * 100}vw` : 'unset'}`,
|
|
94
101
|
top: stickyTop
|
|
95
102
|
};
|
|
@@ -37,7 +37,12 @@ export const RichTextItem: FC<ItemProps<TRichTextItem>> = ({ item, sectionId, on
|
|
|
37
37
|
filter: `blur(${blur * 100}vw)`
|
|
38
38
|
}}
|
|
39
39
|
>
|
|
40
|
-
{
|
|
40
|
+
<div className="rich-text-scale" style={{
|
|
41
|
+
transformOrigin: 'top left',
|
|
42
|
+
transform: 'scale(var(--layout-deviation))'
|
|
43
|
+
}}>
|
|
44
|
+
{content}
|
|
45
|
+
</div>
|
|
41
46
|
</div>
|
|
42
47
|
<JSXStyle id={id}>
|
|
43
48
|
{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);
|
|
17
17
|
return [content, styles, preset];
|
|
18
18
|
};
|
|
@@ -38,8 +38,7 @@ export const FontStyles: Record<string, Record<string, string>> = {
|
|
|
38
38
|
export class RichTextConverter {
|
|
39
39
|
toHtml(
|
|
40
40
|
richText: TRichTextItem,
|
|
41
|
-
layouts: TLayout[]
|
|
42
|
-
hasPreset: boolean
|
|
41
|
+
layouts: TLayout[]
|
|
43
42
|
): [ReactNode[], string] {
|
|
44
43
|
const { text, blocks = [] } = richText.commonParams;
|
|
45
44
|
const root: ReactElement[] = [];
|
|
@@ -63,7 +62,7 @@ export class RichTextConverter {
|
|
|
63
62
|
const lh = RichTextConverter.fromDraftToInline({
|
|
64
63
|
name: 'LINEHEIGHT',
|
|
65
64
|
value: currentLineHeight[l.id]
|
|
66
|
-
});
|
|
65
|
+
}, l.exemplary);
|
|
67
66
|
styleRules[l.id].push(`.rt_${richText.id}_br_${blockIndex} {${lh}}`);
|
|
68
67
|
});
|
|
69
68
|
continue;
|
|
@@ -91,7 +90,6 @@ export class RichTextConverter {
|
|
|
91
90
|
text-align: ${ta};
|
|
92
91
|
white-space: ${whiteSpace};
|
|
93
92
|
overflow-wrap: break-word;
|
|
94
|
-
${!hasPreset ? 'line-height: 0;' : ''}
|
|
95
93
|
}
|
|
96
94
|
`);
|
|
97
95
|
});
|
|
@@ -129,6 +127,7 @@ export class RichTextConverter {
|
|
|
129
127
|
kids.push(sliceSymbols(content, offset));
|
|
130
128
|
}
|
|
131
129
|
for (const item of group) {
|
|
130
|
+
const { exemplary } = layouts.find(l => l.id === item.layout)!;
|
|
132
131
|
const entitiesGroups = this.groupEntities(entities, item.styles) ?? [];
|
|
133
132
|
for (const entitiesGroup of entitiesGroups) {
|
|
134
133
|
if (!entitiesGroup.stylesGroup) continue;
|
|
@@ -140,7 +139,7 @@ export class RichTextConverter {
|
|
|
140
139
|
}
|
|
141
140
|
styleRules[item.layout].push(`
|
|
142
141
|
.${blockClass} .s-${styleGroup.start}-${styleGroup.end} {
|
|
143
|
-
${styleGroup.styles.map(s => RichTextConverter.fromDraftToInline(s)).join('\n')}
|
|
142
|
+
${styleGroup.styles.map(s => RichTextConverter.fromDraftToInline(s, exemplary)).join('\n')}
|
|
144
143
|
}
|
|
145
144
|
`);
|
|
146
145
|
if (color) {
|
|
@@ -232,17 +231,17 @@ export class RichTextConverter {
|
|
|
232
231
|
return entitiesGroups;
|
|
233
232
|
}
|
|
234
233
|
|
|
235
|
-
private static fromDraftToInline(draftStyle: Style): string {
|
|
234
|
+
private static fromDraftToInline(draftStyle: Style, exemplary: number): string {
|
|
236
235
|
const { value, name } = draftStyle;
|
|
237
236
|
const map: Record<string, Record<string, string | undefined>> = {
|
|
238
237
|
'COLOR': { 'color': getResolvedValue(value, name) },
|
|
239
238
|
'TYPEFACE': { 'font-family': `${value}` },
|
|
240
239
|
'FONTSTYLE': value ? { ...FontStyles[value] } : {},
|
|
241
240
|
'FONTWEIGHT': { 'font-weight': value },
|
|
242
|
-
'FONTSIZE': { 'font-size': `${parseFloat(value!) *
|
|
243
|
-
'LINEHEIGHT': { 'line-height': `${parseFloat(value!) *
|
|
244
|
-
'LETTERSPACING': { 'letter-spacing': `${parseFloat(value!) *
|
|
245
|
-
'WORDSPACING': { 'word-spacing': `${parseFloat(value!) *
|
|
241
|
+
'FONTSIZE': { 'font-size': `${parseFloat(value!) * exemplary}px` },
|
|
242
|
+
'LINEHEIGHT': { 'line-height': `${parseFloat(value!) * exemplary}px` },
|
|
243
|
+
'LETTERSPACING': { 'letter-spacing': `${parseFloat(value!) * exemplary}px` },
|
|
244
|
+
'WORDSPACING': { 'word-spacing': `${parseFloat(value!) * exemplary}px` },
|
|
246
245
|
'TEXTTRANSFORM': value ? { 'text-transform': value as TextTransform } : { 'text-transform': TextTransform.None },
|
|
247
246
|
'VERTICALALIGN': value ? { 'vertical-align': value as VerticalAlign } : { 'vertical-align': VerticalAlign.Unset },
|
|
248
247
|
'TEXTDECORATION': { 'text-decoration': value }
|
|
Binary file
|
|
Binary file
|
|
Binary file
|