@cntrl-site/sdk-nextjs 0.15.3 → 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.5-beta.0.tgz +0 -0
- package/lib/common/useCurrentLayout.js +8 -4
- package/lib/components/ArticleWrapper.js +7 -6
- package/lib/components/Item.js +17 -8
- 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 +14 -7
- package/src/components/Item.tsx +19 -5
- package/src/components/items/RichTextItem.tsx +6 -1
- package/src/components/items/useRichTextItem.ts +1 -1
- package/src/utils/RichTextConverter/RichTextConverter.tsx +9 -10
|
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,18 +23,21 @@ const useCurrentLayout = () => {
|
|
|
22
23
|
}, []);
|
|
23
24
|
}, [layouts]);
|
|
24
25
|
const getCurrentLayout = (0, react_1.useCallback)((articleWidth) => {
|
|
25
|
-
|
|
26
|
-
return
|
|
26
|
+
const range = layoutRanges.find(l => articleWidth >= l.start && articleWidth < l.end);
|
|
27
|
+
return range;
|
|
27
28
|
}, [layoutRanges]);
|
|
28
29
|
const [layoutId, setLayoutId] = (0, react_1.useState)(undefined);
|
|
30
|
+
const [deviation, setDeviation] = (0, react_1.useState)(1);
|
|
29
31
|
(0, react_1.useEffect)(() => {
|
|
30
32
|
if (!articleRectObserver)
|
|
31
33
|
return;
|
|
32
34
|
return articleRectObserver.on('resize', () => {
|
|
33
35
|
const articleWidth = articleRectObserver.width;
|
|
34
|
-
|
|
36
|
+
const { layoutId, exemplary } = getCurrentLayout(articleWidth);
|
|
37
|
+
setLayoutId(layoutId);
|
|
38
|
+
setDeviation(articleWidth / exemplary);
|
|
35
39
|
});
|
|
36
40
|
}, [articleRectObserver, getCurrentLayout]);
|
|
37
|
-
return layoutId;
|
|
41
|
+
return { layoutId, layoutDeviation: deviation };
|
|
38
42
|
};
|
|
39
43
|
exports.useCurrentLayout = useCurrentLayout;
|
|
@@ -12,20 +12,21 @@ 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);
|
|
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, 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: `
|
|
29
30
|
.article-wrapper {
|
|
30
31
|
opacity: 1;
|
|
31
32
|
transition: opacity 0.2s ease;
|
package/lib/components/Item.js
CHANGED
|
@@ -37,9 +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)();
|
|
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;
|
|
43
45
|
const [wrapperHeight, setWrapperHeight] = (0, react_1.useState)(undefined);
|
|
44
46
|
const { scale, scaleAnchor } = (0, useItemScale_1.useItemScale)(item, sectionId);
|
|
45
47
|
const { top, left } = (0, useItemPosition_1.useItemPosition)(item, sectionId);
|
|
@@ -72,14 +74,21 @@ const Item = ({ item, sectionId }) => {
|
|
|
72
74
|
(0, react_1.useEffect)(() => {
|
|
73
75
|
isInitialRef.current = false;
|
|
74
76
|
}, []);
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
transformOrigin:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
const isRichText = isItemType(item, sdk_1.ArticleItemType.RichText);
|
|
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: `
|
|
83
92
|
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, hidden, hoverParams, sticky, sectionHeight, layoutParams]) => {
|
|
84
93
|
const sizingAxis = parseSizing(layoutParams.sizing);
|
|
85
94
|
return (`
|
|
@@ -35,7 +35,10 @@ const RichTextItem = ({ item, sectionId, onResize }) => {
|
|
|
35
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: {
|
|
36
36
|
transform: `rotate(${angle}deg)`,
|
|
37
37
|
filter: `blur(${blur * 100}vw)`
|
|
38
|
-
} }, { children:
|
|
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]) => {
|
|
39
42
|
return (`
|
|
40
43
|
.rich-text-wrapper-${item.id} {
|
|
41
44
|
transition: ${(0, HoverStyles_1.getTransitions)(['angle', 'blur'], hoverParams)};
|
|
@@ -13,7 +13,7 @@ const useRichTextItem = (item) => {
|
|
|
13
13
|
const preset = presetId
|
|
14
14
|
? (_a = typePresets === null || typePresets === void 0 ? void 0 : typePresets.presets.find(p => p.id === presetId)) !== null && _a !== void 0 ? _a : 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
|
};
|
|
19
19
|
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
|
var _a, _b, _c;
|
|
15
15
|
const { text, blocks = [] } = richText.commonParams;
|
|
16
16
|
const root = [];
|
|
@@ -34,7 +34,7 @@ class RichTextConverter {
|
|
|
34
34
|
const lh = RichTextConverter.fromDraftToInline({
|
|
35
35
|
name: 'LINEHEIGHT',
|
|
36
36
|
value: currentLineHeight[l.id]
|
|
37
|
-
});
|
|
37
|
+
}, l.exemplary);
|
|
38
38
|
styleRules[l.id].push(`.rt_${richText.id}_br_${blockIndex} {${lh}}`);
|
|
39
39
|
});
|
|
40
40
|
continue;
|
|
@@ -62,7 +62,6 @@ class RichTextConverter {
|
|
|
62
62
|
text-align: ${ta};
|
|
63
63
|
white-space: ${whiteSpace};
|
|
64
64
|
overflow-wrap: break-word;
|
|
65
|
-
${!hasPreset ? 'line-height: 0;' : ''}
|
|
66
65
|
}
|
|
67
66
|
`);
|
|
68
67
|
});
|
|
@@ -96,6 +95,7 @@ class RichTextConverter {
|
|
|
96
95
|
kids.push(sliceSymbols(content, offset));
|
|
97
96
|
}
|
|
98
97
|
for (const item of group) {
|
|
98
|
+
const { exemplary } = layouts.find(l => l.id === item.layout);
|
|
99
99
|
const entitiesGroups = (_c = this.groupEntities(entities, item.styles)) !== null && _c !== void 0 ? _c : [];
|
|
100
100
|
for (const entitiesGroup of entitiesGroups) {
|
|
101
101
|
if (!entitiesGroup.stylesGroup)
|
|
@@ -108,7 +108,7 @@ class RichTextConverter {
|
|
|
108
108
|
}
|
|
109
109
|
styleRules[item.layout].push(`
|
|
110
110
|
.${blockClass} .s-${styleGroup.start}-${styleGroup.end} {
|
|
111
|
-
${styleGroup.styles.map(s => RichTextConverter.fromDraftToInline(s)).join('\n')}
|
|
111
|
+
${styleGroup.styles.map(s => RichTextConverter.fromDraftToInline(s, exemplary)).join('\n')}
|
|
112
112
|
}
|
|
113
113
|
`);
|
|
114
114
|
if (color) {
|
|
@@ -192,17 +192,17 @@ class RichTextConverter {
|
|
|
192
192
|
}
|
|
193
193
|
return entitiesGroups;
|
|
194
194
|
}
|
|
195
|
-
static fromDraftToInline(draftStyle) {
|
|
195
|
+
static fromDraftToInline(draftStyle, exemplary) {
|
|
196
196
|
const { value, name } = draftStyle;
|
|
197
197
|
const map = {
|
|
198
198
|
'COLOR': { 'color': getResolvedValue(value, name) },
|
|
199
199
|
'TYPEFACE': { 'font-family': `${value}` },
|
|
200
200
|
'FONTSTYLE': value ? Object.assign({}, exports.FontStyles[value]) : {},
|
|
201
201
|
'FONTWEIGHT': { 'font-weight': value },
|
|
202
|
-
'FONTSIZE': { 'font-size': `${parseFloat(value) *
|
|
203
|
-
'LINEHEIGHT': { 'line-height': `${parseFloat(value) *
|
|
204
|
-
'LETTERSPACING': { 'letter-spacing': `${parseFloat(value) *
|
|
205
|
-
'WORDSPACING': { 'word-spacing': `${parseFloat(value) *
|
|
202
|
+
'FONTSIZE': { 'font-size': `${parseFloat(value) * exemplary}px` },
|
|
203
|
+
'LINEHEIGHT': { 'line-height': `${parseFloat(value) * exemplary}px` },
|
|
204
|
+
'LETTERSPACING': { 'letter-spacing': `${parseFloat(value) * exemplary}px` },
|
|
205
|
+
'WORDSPACING': { 'word-spacing': `${parseFloat(value) * exemplary}px` },
|
|
206
206
|
'TEXTTRANSFORM': value ? { 'text-transform': value } : { 'text-transform': sdk_1.TextTransform.None },
|
|
207
207
|
'VERTICALALIGN': value ? { 'vertical-align': value } : { 'vertical-align': sdk_1.VerticalAlign.Unset },
|
|
208
208
|
'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,23 +6,30 @@ 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 = () => {
|
|
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
|
+
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/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,11 +87,13 @@ 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
|
+
const scaleIfRichText = isRichText
|
|
92
|
+
? { transformOrigin: 'top left', transform: 'scale(var(--layout-deviation))' }
|
|
93
|
+
: {};
|
|
94
|
+
|
|
89
95
|
const styles = {
|
|
90
|
-
|
|
91
|
-
transformOrigin: ScaleAnchorMap[scaleAnchor],
|
|
92
|
-
width: `${sizingAxis.x === SizingType.Manual ? `${width * 100}vw` : 'max-content'}`,
|
|
93
|
-
height: `${sizingAxis.y === SizingType.Manual ? `${height * 100}vw` : 'unset'}`,
|
|
96
|
+
...scaleIfRichText,
|
|
94
97
|
top: stickyTop
|
|
95
98
|
};
|
|
96
99
|
|
|
@@ -104,7 +107,18 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item, sectionId}) => {
|
|
|
104
107
|
className={`item-${item.id}`}
|
|
105
108
|
style={isInitialRef.current ? {} : styles }
|
|
106
109
|
>
|
|
107
|
-
<
|
|
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>
|
|
108
122
|
</div>
|
|
109
123
|
<JSXStyle id={id}>{`
|
|
110
124
|
${getLayoutStyles(layouts, layoutValues, ([area, hidden, hoverParams, sticky, sectionHeight, layoutParams]) => {
|
|
@@ -38,7 +38,12 @@ export const RichTextItem: FC<ItemProps<TRichTextItem>> = ({ item, sectionId, on
|
|
|
38
38
|
filter: `blur(${blur * 100}vw)`
|
|
39
39
|
}}
|
|
40
40
|
>
|
|
41
|
-
{
|
|
41
|
+
<div className="rich-text-scale" style={{
|
|
42
|
+
// transformOrigin: 'top left',
|
|
43
|
+
// transform: 'scale(var(--layout-deviation))'
|
|
44
|
+
}}>
|
|
45
|
+
{content}
|
|
46
|
+
</div>
|
|
42
47
|
</div>
|
|
43
48
|
<JSXStyle id={id}>
|
|
44
49
|
{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 }
|