@cntrl-site/sdk-nextjs 1.8.11 → 1.8.13
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/LICENSE +21 -21
- package/README.md +4 -4
- package/TODO.md +1 -1
- package/cntrl-site-sdk-nextjs-1.8.12.tgz +0 -0
- package/cntrl-site-sdk-nextjs-1.8.13.tgz +0 -0
- package/eslint.config.mjs +35 -35
- package/jest.config.js +6 -6
- package/lib/common/useItemFXData.js +7 -7
- package/lib/common/useRegisterResize.js +2 -2
- package/lib/components/Article.js +5 -5
- package/lib/components/LayoutStyle.js +4 -4
- package/lib/components/Section/Section.js +43 -43
- package/lib/components/items/CodeEmbedItem/CodeEmbedItem.js +35 -35
- package/lib/components/items/ComponentItem/ComponentItem.js +16 -14
- package/lib/components/items/ComponentItem/useComponentItem.js +8 -1
- package/lib/components/items/CompoundItem/CompoundChild.js +20 -20
- package/lib/components/items/CompoundItem/CompoundItem.js +14 -14
- package/lib/components/items/CustomItem/CustomItem.js +9 -9
- package/lib/components/items/EmbedVideoItem/VimeoEmbed.js +23 -23
- package/lib/components/items/EmbedVideoItem/YoutubeEmbed.js +26 -26
- package/lib/components/items/FileItem/ImageItem.js +38 -38
- package/lib/components/items/FileItem/VideoItem.js +45 -45
- package/lib/components/items/GroupItem/GroupItem.js +13 -13
- package/lib/components/items/Item.js +30 -30
- package/lib/components/items/RectangleItem/RectangleItem.js +20 -20
- package/lib/components/items/RichTextItem/RichTextItem.js +21 -21
- package/lib/utils/RichTextConverter/RichTextConverter.js +21 -21
- package/package.json +57 -58
- package/src/common/useCurrentLayout.ts +52 -52
- package/src/common/useExemplary.ts +9 -9
- package/src/common/useItemFXData.ts +47 -47
- package/src/common/useKeyframeValue.ts +85 -85
- package/src/common/useRegisterResize.ts +16 -17
- package/src/components/Article.tsx +66 -66
- package/src/components/ArticleWrapper.tsx +21 -21
- package/src/components/Head.tsx +56 -56
- package/src/components/LayoutStyle.tsx +21 -21
- package/src/components/Page.tsx +33 -33
- package/src/components/ScrollPlaybackVideo.tsx +56 -56
- package/src/components/Section/Section.tsx +164 -164
- package/src/components/Section/useSectionColor.ts +19 -19
- package/src/components/Section/useSectionHeightMap.ts +19 -19
- package/src/components/items/CodeEmbedItem/CodeEmbedItem.tsx +137 -137
- package/src/components/items/CodeEmbedItem/useCodeEmbedItem.ts +36 -36
- package/src/components/items/ComponentItem/ComponentItem.tsx +65 -62
- package/src/components/items/ComponentItem/useComponentItem.ts +35 -23
- package/src/components/items/CompoundItem/CompoundChild.tsx +150 -150
- package/src/components/items/CompoundItem/CompoundItem.tsx +70 -70
- package/src/components/items/CompoundItem/useCompoundItem.ts +21 -21
- package/src/components/items/CustomItem/CustomItem.tsx +48 -48
- package/src/components/items/EmbedVideoItem/VimeoEmbed.tsx +202 -202
- package/src/components/items/EmbedVideoItem/YoutubeEmbed.tsx +187 -187
- package/src/components/items/EmbedVideoItem/useEmbedVideoItem.ts +46 -46
- package/src/components/items/FileItem/ImageItem.tsx +156 -156
- package/src/components/items/FileItem/VideoItem.tsx +185 -185
- package/src/components/items/FileItem/useFileItem.ts +73 -73
- package/src/components/items/GroupItem/GroupItem.tsx +79 -79
- package/src/components/items/GroupItem/useGroupItem.ts +34 -34
- package/src/components/items/Item.tsx +251 -251
- package/src/components/items/LinkWrapper.tsx +39 -39
- package/src/components/items/RectangleItem/RectangleItem.tsx +95 -95
- package/src/components/items/RectangleItem/useRectangleItem.ts +82 -82
- package/src/components/items/RichTextItem/RichTextItem.tsx +105 -105
- package/src/components/items/RichTextItem/useRichTextItem.ts +12 -12
- package/src/components/items/RichTextWrapper.tsx +15 -15
- package/src/components/items/itemsMap.ts +28 -28
- package/src/components/items/useDraggable.ts +252 -252
- package/src/components/items/useItemAngle.ts +13 -13
- package/src/components/items/useItemArea.ts +35 -35
- package/src/components/items/useItemPointerEvents.ts +23 -23
- package/src/components/items/useItemScale.ts +17 -17
- package/src/components/items/useItemTriggers.ts +15 -15
- package/src/components/items/useRichTextItemValues.ts +65 -65
- package/src/components/items/useSizing.ts +25 -25
- package/src/components/items/useStickyItemTop.ts +21 -21
- package/src/components/useLayoutContext.ts +7 -7
- package/src/index.ts +24 -24
- package/src/interactions/CSSPropertyNameMap.ts +38 -38
- package/src/interactions/InteractionsRegistry.ts +283 -283
- package/src/interactions/ItemInteractionCtrl.ts +77 -77
- package/src/interactions/getTransition.ts +27 -27
- package/src/interactions/types.ts +36 -36
- package/src/interactions/useItemInteractionCtrl.ts +18 -18
- package/src/provider/ArticleRectContext.ts +4 -4
- package/src/provider/CntrlContext.ts +5 -5
- package/src/provider/CntrlProvider.tsx +11 -11
- package/src/provider/CntrlSdkContext.ts +83 -83
- package/src/provider/CustomItemRegistry.ts +14 -14
- package/src/provider/CustomItemTypes.ts +3 -3
- package/src/provider/CustomSectionRegistry.ts +25 -25
- package/src/provider/InteractionsContext.old.tsx +66 -66
- package/src/provider/InteractionsContext.test.tsx +97 -97
- package/src/provider/InteractionsContext.tsx +28 -28
- package/src/provider/Keyframes.ts +11 -11
- package/src/provider/KeyframesContext.ts +5 -5
- package/src/provider/LayoutContext.ts +3 -3
- package/src/provider/defaultContext.ts +8 -8
- package/src/provider/useCntrlContext.ts +8 -8
- package/src/styled-jsx.d.ts +1 -1
- package/src/utils/Animator/Animator.ts +371 -371
- package/src/utils/ArticleRectManager/ArticleRectObserver.ts +93 -93
- package/src/utils/ArticleRectManager/useArticleRectObserver.ts +17 -17
- package/src/utils/ArticleRectManager/useSectionRegistry.ts +11 -11
- package/src/utils/EventEmitter.ts +41 -41
- package/src/utils/RichTextConverter/RichTextConverter.tsx +326 -326
- package/src/utils/ScaleAnchorMap.ts +13 -13
- package/src/utils/StickyManager/StickyManager.ts +23 -23
- package/src/utils/Youtube/YouTubeIframeApiLoader.ts +58 -58
- package/src/utils/Youtube/YoutubeIframeApi.ts +101 -101
- package/src/utils/Youtube/useYouTubeIframeApi.ts +12 -12
- package/src/utils/binSearchInsertAt.ts +33 -33
- package/src/utils/castObject.ts +10 -10
- package/src/utils/effects/useImageFx.ts +113 -113
- package/src/utils/effects/useVideoFx.ts +116 -116
- package/src/utils/getAnchoredItemTop.ts +12 -12
- package/src/utils/getCompoundBoundaryStyles.ts +60 -60
- package/src/utils/getFontFamilyValue.ts +3 -3
- package/src/utils/getInvertedRanges.ts +43 -43
- package/src/utils/getItemTopStyle.ts +14 -14
- package/src/utils/getStyleFromItemStateAndParams.ts +8 -8
- package/src/utils/getValidYoutubeUrl.ts +29 -29
- package/src/utils/isItemType.ts +5 -5
- package/src/utils/rangeMap.ts +13 -13
- package/src/utils/useElementRect.ts +23 -23
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
import { FC, useEffect, useId, useMemo, useState } from 'react';
|
|
2
|
-
import JSXStyle from 'styled-jsx/style';
|
|
3
|
-
import { CntrlColor } from '@cntrl-site/color';
|
|
4
|
-
import { RectangleItem as TRectangleItem, getLayoutStyles } from '@cntrl-site/sdk';
|
|
5
|
-
import { ItemProps } from '../Item';
|
|
6
|
-
import { LinkWrapper } from '../LinkWrapper';
|
|
7
|
-
import { useRectangleItem } from './useRectangleItem';
|
|
8
|
-
import { useItemAngle } from '../useItemAngle';
|
|
9
|
-
import { useCntrlContext } from '../../../provider/useCntrlContext';
|
|
10
|
-
import { useRegisterResize } from '../../../common/useRegisterResize';
|
|
11
|
-
import { getStyleFromItemStateAndParams } from '../../../utils/getStyleFromItemStateAndParams';
|
|
12
|
-
|
|
13
|
-
export const RectangleItem: FC<ItemProps<TRectangleItem>> = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
|
|
14
|
-
const id = useId();
|
|
15
|
-
const { layouts } = useCntrlContext();
|
|
16
|
-
const {
|
|
17
|
-
fillColor: itemFillColor,
|
|
18
|
-
radius: itemRadius,
|
|
19
|
-
strokeWidth: itemStrokeWidth,
|
|
20
|
-
strokeColor: itemStrokeColor,
|
|
21
|
-
blur: itemBlur,
|
|
22
|
-
backdropBlur: itemBackdropBlur
|
|
23
|
-
} = useRectangleItem(item, sectionId);
|
|
24
|
-
const itemAngle = useItemAngle(item, sectionId);
|
|
25
|
-
const stateParams = interactionCtrl?.getState(['angle', 'fillColor', 'strokeWidth', 'radius', 'strokeColor', 'blur', 'backdropBlur']);
|
|
26
|
-
const styles = stateParams?.styles ?? {};
|
|
27
|
-
const backgroundColor = useMemo(() => {
|
|
28
|
-
const fillColor = getStyleFromItemStateAndParams(styles?.fillColor, itemFillColor);
|
|
29
|
-
return fillColor ? CntrlColor.parse(fillColor) : undefined;
|
|
30
|
-
}, [itemFillColor, styles?.fillColor]);
|
|
31
|
-
const borderColor = useMemo(() => {
|
|
32
|
-
const strokeColor = getStyleFromItemStateAndParams(styles?.strokeColor, itemStrokeColor);
|
|
33
|
-
return strokeColor ? CntrlColor.parse(strokeColor) : undefined;
|
|
34
|
-
}, [itemStrokeColor, styles?.strokeColor]);
|
|
35
|
-
const layoutValues: Record<string, any>[] = [item.area, item.layoutParams];
|
|
36
|
-
const [ref, setRef] = useState<HTMLDivElement | null>(null);
|
|
37
|
-
useRegisterResize(ref, onResize);
|
|
38
|
-
const backdropBlur = getStyleFromItemStateAndParams(styles?.backdropBlur, itemBackdropBlur);
|
|
39
|
-
const radius = getStyleFromItemStateAndParams(styles?.radius, itemRadius);
|
|
40
|
-
const strokeWidth = getStyleFromItemStateAndParams(styles?.strokeWidth, itemStrokeWidth);
|
|
41
|
-
const angle = getStyleFromItemStateAndParams(styles?.angle, itemAngle);
|
|
42
|
-
const blur = getStyleFromItemStateAndParams(styles?.blur, itemBlur);
|
|
43
|
-
const backdropFilterValue = backdropBlur ? `blur(${backdropBlur * 100}vw)` : undefined;
|
|
44
|
-
const isInteractive = backgroundColor?.getAlpha() !== 0 || (strokeWidth !== 0 && borderColor?.getAlpha() !== 0);
|
|
45
|
-
useEffect(() => {
|
|
46
|
-
onVisibilityChange?.(isInteractive);
|
|
47
|
-
}, [isInteractive, onVisibilityChange]);
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<LinkWrapper url={item.link?.url} target={item.link?.target}>
|
|
51
|
-
<>
|
|
52
|
-
<div
|
|
53
|
-
className={`rectangle-${item.id}`}
|
|
54
|
-
ref={setRef}
|
|
55
|
-
style={{
|
|
56
|
-
...(backgroundColor ? { backgroundColor: `${backgroundColor.fmt('rgba')}` } : {}),
|
|
57
|
-
...(borderColor ? { borderColor: `${borderColor.fmt('rgba')}` } : {}),
|
|
58
|
-
...(radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {}),
|
|
59
|
-
...(strokeWidth !== undefined ? { borderWidth: `${strokeWidth * 100}vw` } : {}),
|
|
60
|
-
...(angle !== undefined ? { transform: `rotate(${angle}deg)` } : {}),
|
|
61
|
-
...(blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {}),
|
|
62
|
-
...(backdropFilterValue !== undefined
|
|
63
|
-
? { backdropFilter: backdropFilterValue, WebkitBackdropFilter: backdropFilterValue }
|
|
64
|
-
: {}
|
|
65
|
-
),
|
|
66
|
-
transition: stateParams?.transition ?? 'none'
|
|
67
|
-
}}
|
|
68
|
-
/>
|
|
69
|
-
<JSXStyle id={id}>{`
|
|
70
|
-
.rectangle-${item.id} {
|
|
71
|
-
position: absolute;
|
|
72
|
-
width: 100%;
|
|
73
|
-
height: 100%;
|
|
74
|
-
border-style: solid;
|
|
75
|
-
box-sizing: border-box;
|
|
76
|
-
}
|
|
77
|
-
${getLayoutStyles(layouts, layoutValues, ([area, layoutParams]) => {
|
|
78
|
-
return (`
|
|
79
|
-
.rectangle-${item.id} {
|
|
80
|
-
background-color: ${CntrlColor.parse(layoutParams.fillColor).fmt('rgba')};
|
|
81
|
-
border-color: ${CntrlColor.parse(layoutParams.strokeColor).fmt('rgba')};
|
|
82
|
-
border-radius: ${layoutParams.radius * 100}vw;
|
|
83
|
-
border-width: ${layoutParams.strokeWidth * 100}vw;
|
|
84
|
-
transform: rotate(${area.angle}deg);
|
|
85
|
-
filter: ${layoutParams.blur !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
|
|
86
|
-
backdrop-filter: ${layoutParams.backdropBlur !== 0 ? `blur(${layoutParams.backdropBlur * 100}vw)` : 'unset'};
|
|
87
|
-
-webkit-backdrop-filter: ${layoutParams.backdropBlur !== 0 ? `blur(${layoutParams.backdropBlur * 100}vw)` : 'unset'};
|
|
88
|
-
}
|
|
89
|
-
`);
|
|
90
|
-
})}
|
|
91
|
-
`}</JSXStyle>
|
|
92
|
-
</>
|
|
93
|
-
</LinkWrapper>
|
|
94
|
-
);
|
|
95
|
-
};
|
|
1
|
+
import { FC, useEffect, useId, useMemo, useState } from 'react';
|
|
2
|
+
import JSXStyle from 'styled-jsx/style';
|
|
3
|
+
import { CntrlColor } from '@cntrl-site/color';
|
|
4
|
+
import { RectangleItem as TRectangleItem, getLayoutStyles } from '@cntrl-site/sdk';
|
|
5
|
+
import { ItemProps } from '../Item';
|
|
6
|
+
import { LinkWrapper } from '../LinkWrapper';
|
|
7
|
+
import { useRectangleItem } from './useRectangleItem';
|
|
8
|
+
import { useItemAngle } from '../useItemAngle';
|
|
9
|
+
import { useCntrlContext } from '../../../provider/useCntrlContext';
|
|
10
|
+
import { useRegisterResize } from '../../../common/useRegisterResize';
|
|
11
|
+
import { getStyleFromItemStateAndParams } from '../../../utils/getStyleFromItemStateAndParams';
|
|
12
|
+
|
|
13
|
+
export const RectangleItem: FC<ItemProps<TRectangleItem>> = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
|
|
14
|
+
const id = useId();
|
|
15
|
+
const { layouts } = useCntrlContext();
|
|
16
|
+
const {
|
|
17
|
+
fillColor: itemFillColor,
|
|
18
|
+
radius: itemRadius,
|
|
19
|
+
strokeWidth: itemStrokeWidth,
|
|
20
|
+
strokeColor: itemStrokeColor,
|
|
21
|
+
blur: itemBlur,
|
|
22
|
+
backdropBlur: itemBackdropBlur
|
|
23
|
+
} = useRectangleItem(item, sectionId);
|
|
24
|
+
const itemAngle = useItemAngle(item, sectionId);
|
|
25
|
+
const stateParams = interactionCtrl?.getState(['angle', 'fillColor', 'strokeWidth', 'radius', 'strokeColor', 'blur', 'backdropBlur']);
|
|
26
|
+
const styles = stateParams?.styles ?? {};
|
|
27
|
+
const backgroundColor = useMemo(() => {
|
|
28
|
+
const fillColor = getStyleFromItemStateAndParams(styles?.fillColor, itemFillColor);
|
|
29
|
+
return fillColor ? CntrlColor.parse(fillColor) : undefined;
|
|
30
|
+
}, [itemFillColor, styles?.fillColor]);
|
|
31
|
+
const borderColor = useMemo(() => {
|
|
32
|
+
const strokeColor = getStyleFromItemStateAndParams(styles?.strokeColor, itemStrokeColor);
|
|
33
|
+
return strokeColor ? CntrlColor.parse(strokeColor) : undefined;
|
|
34
|
+
}, [itemStrokeColor, styles?.strokeColor]);
|
|
35
|
+
const layoutValues: Record<string, any>[] = [item.area, item.layoutParams];
|
|
36
|
+
const [ref, setRef] = useState<HTMLDivElement | null>(null);
|
|
37
|
+
useRegisterResize(ref, onResize);
|
|
38
|
+
const backdropBlur = getStyleFromItemStateAndParams(styles?.backdropBlur, itemBackdropBlur);
|
|
39
|
+
const radius = getStyleFromItemStateAndParams(styles?.radius, itemRadius);
|
|
40
|
+
const strokeWidth = getStyleFromItemStateAndParams(styles?.strokeWidth, itemStrokeWidth);
|
|
41
|
+
const angle = getStyleFromItemStateAndParams(styles?.angle, itemAngle);
|
|
42
|
+
const blur = getStyleFromItemStateAndParams(styles?.blur, itemBlur);
|
|
43
|
+
const backdropFilterValue = backdropBlur ? `blur(${backdropBlur * 100}vw)` : undefined;
|
|
44
|
+
const isInteractive = backgroundColor?.getAlpha() !== 0 || (strokeWidth !== 0 && borderColor?.getAlpha() !== 0);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
onVisibilityChange?.(isInteractive);
|
|
47
|
+
}, [isInteractive, onVisibilityChange]);
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<LinkWrapper url={item.link?.url} target={item.link?.target}>
|
|
51
|
+
<>
|
|
52
|
+
<div
|
|
53
|
+
className={`rectangle-${item.id}`}
|
|
54
|
+
ref={setRef}
|
|
55
|
+
style={{
|
|
56
|
+
...(backgroundColor ? { backgroundColor: `${backgroundColor.fmt('rgba')}` } : {}),
|
|
57
|
+
...(borderColor ? { borderColor: `${borderColor.fmt('rgba')}` } : {}),
|
|
58
|
+
...(radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {}),
|
|
59
|
+
...(strokeWidth !== undefined ? { borderWidth: `${strokeWidth * 100}vw` } : {}),
|
|
60
|
+
...(angle !== undefined ? { transform: `rotate(${angle}deg)` } : {}),
|
|
61
|
+
...(blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {}),
|
|
62
|
+
...(backdropFilterValue !== undefined
|
|
63
|
+
? { backdropFilter: backdropFilterValue, WebkitBackdropFilter: backdropFilterValue }
|
|
64
|
+
: {}
|
|
65
|
+
),
|
|
66
|
+
transition: stateParams?.transition ?? 'none'
|
|
67
|
+
}}
|
|
68
|
+
/>
|
|
69
|
+
<JSXStyle id={id}>{`
|
|
70
|
+
.rectangle-${item.id} {
|
|
71
|
+
position: absolute;
|
|
72
|
+
width: 100%;
|
|
73
|
+
height: 100%;
|
|
74
|
+
border-style: solid;
|
|
75
|
+
box-sizing: border-box;
|
|
76
|
+
}
|
|
77
|
+
${getLayoutStyles(layouts, layoutValues, ([area, layoutParams]) => {
|
|
78
|
+
return (`
|
|
79
|
+
.rectangle-${item.id} {
|
|
80
|
+
background-color: ${CntrlColor.parse(layoutParams.fillColor).fmt('rgba')};
|
|
81
|
+
border-color: ${CntrlColor.parse(layoutParams.strokeColor).fmt('rgba')};
|
|
82
|
+
border-radius: ${layoutParams.radius * 100}vw;
|
|
83
|
+
border-width: ${layoutParams.strokeWidth * 100}vw;
|
|
84
|
+
transform: rotate(${area.angle}deg);
|
|
85
|
+
filter: ${layoutParams.blur !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
|
|
86
|
+
backdrop-filter: ${layoutParams.backdropBlur !== 0 ? `blur(${layoutParams.backdropBlur * 100}vw)` : 'unset'};
|
|
87
|
+
-webkit-backdrop-filter: ${layoutParams.backdropBlur !== 0 ? `blur(${layoutParams.backdropBlur * 100}vw)` : 'unset'};
|
|
88
|
+
}
|
|
89
|
+
`);
|
|
90
|
+
})}
|
|
91
|
+
`}</JSXStyle>
|
|
92
|
+
</>
|
|
93
|
+
</LinkWrapper>
|
|
94
|
+
);
|
|
95
|
+
};
|
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
import { KeyframeType, RectangleItem } from '@cntrl-site/sdk';
|
|
2
|
-
import { useKeyframeValue } from '../../../common/useKeyframeValue';
|
|
3
|
-
import { useLayoutContext } from '../../useLayoutContext';
|
|
4
|
-
|
|
5
|
-
const defaultColor = 'rgba(0, 0, 0, 1)';
|
|
6
|
-
|
|
7
|
-
export function useRectangleItem(item: RectangleItem, sectionId: string) {
|
|
8
|
-
const layoutId = useLayoutContext();
|
|
9
|
-
const radius = useKeyframeValue(
|
|
10
|
-
item,
|
|
11
|
-
KeyframeType.BorderRadius,
|
|
12
|
-
(item, layoutId) => {
|
|
13
|
-
if (!layoutId) return;
|
|
14
|
-
const layoutParams = item.layoutParams[layoutId];
|
|
15
|
-
return 'radius' in layoutParams ? layoutParams.radius : 0;
|
|
16
|
-
},
|
|
17
|
-
(animator, scroll, value) => value !== undefined ? animator.getRadius({ radius: value }, scroll).radius : undefined,
|
|
18
|
-
sectionId,
|
|
19
|
-
[layoutId]
|
|
20
|
-
);
|
|
21
|
-
const strokeWidth = useKeyframeValue(
|
|
22
|
-
item,
|
|
23
|
-
KeyframeType.BorderWidth,
|
|
24
|
-
(item, layoutId) => {
|
|
25
|
-
if (!layoutId) return;
|
|
26
|
-
const layoutParams = item.layoutParams[layoutId];
|
|
27
|
-
return 'strokeWidth' in layoutParams ? layoutParams.strokeWidth : 0;
|
|
28
|
-
},
|
|
29
|
-
(animator, scroll, value) => value !== undefined ? animator.getBorderWidth({ borderWidth: value }, scroll).borderWidth : undefined,
|
|
30
|
-
sectionId,
|
|
31
|
-
[layoutId]
|
|
32
|
-
);
|
|
33
|
-
const fillColor = useKeyframeValue(
|
|
34
|
-
item,
|
|
35
|
-
KeyframeType.Color,
|
|
36
|
-
(item, layoutId) => {
|
|
37
|
-
if (!layoutId) return;
|
|
38
|
-
const layoutParams = item.layoutParams[layoutId];
|
|
39
|
-
return 'fillColor' in layoutParams ? layoutParams.fillColor : defaultColor;
|
|
40
|
-
},
|
|
41
|
-
(animator, scroll, value) => value ? animator.getColor({ color: value }, scroll).color : undefined,
|
|
42
|
-
sectionId,
|
|
43
|
-
[layoutId]
|
|
44
|
-
);
|
|
45
|
-
const strokeColor = useKeyframeValue(
|
|
46
|
-
item,
|
|
47
|
-
KeyframeType.BorderColor,
|
|
48
|
-
(item, layoutId) => {
|
|
49
|
-
if (!layoutId) return;
|
|
50
|
-
const layoutParams = item.layoutParams[layoutId];
|
|
51
|
-
return 'strokeColor' in layoutParams ? layoutParams.strokeColor : defaultColor;
|
|
52
|
-
},
|
|
53
|
-
(animator, scroll, value) => value ? animator.getBorderColor({ color: value }, scroll).color : undefined,
|
|
54
|
-
sectionId,
|
|
55
|
-
[layoutId]
|
|
56
|
-
);
|
|
57
|
-
const blur = useKeyframeValue(
|
|
58
|
-
item,
|
|
59
|
-
KeyframeType.Blur,
|
|
60
|
-
(item, layoutId) => {
|
|
61
|
-
if (!layoutId) return;
|
|
62
|
-
const layoutParams = item.layoutParams[layoutId];
|
|
63
|
-
return 'blur' in layoutParams ? layoutParams.blur : 0;
|
|
64
|
-
},
|
|
65
|
-
(animator, scroll, value) => value !== undefined ? animator.getBlur({ blur: value }, scroll).blur : undefined,
|
|
66
|
-
sectionId,
|
|
67
|
-
[layoutId]
|
|
68
|
-
);
|
|
69
|
-
const backdropBlur = useKeyframeValue(
|
|
70
|
-
item,
|
|
71
|
-
KeyframeType.BackdropBlur,
|
|
72
|
-
(item, layoutId) => {
|
|
73
|
-
if (!layoutId) return;
|
|
74
|
-
const layoutParams = item.layoutParams[layoutId];
|
|
75
|
-
return 'backdropBlur' in layoutParams ? layoutParams.backdropBlur : 0;
|
|
76
|
-
},
|
|
77
|
-
(animator, scroll, value) => value !== undefined ? animator.getBackdropBlur({ backdropBlur: value }, scroll).backdropBlur : undefined,
|
|
78
|
-
sectionId,
|
|
79
|
-
[layoutId]
|
|
80
|
-
);
|
|
81
|
-
return { fillColor, strokeWidth, radius, strokeColor, blur, backdropBlur };
|
|
82
|
-
}
|
|
1
|
+
import { KeyframeType, RectangleItem } from '@cntrl-site/sdk';
|
|
2
|
+
import { useKeyframeValue } from '../../../common/useKeyframeValue';
|
|
3
|
+
import { useLayoutContext } from '../../useLayoutContext';
|
|
4
|
+
|
|
5
|
+
const defaultColor = 'rgba(0, 0, 0, 1)';
|
|
6
|
+
|
|
7
|
+
export function useRectangleItem(item: RectangleItem, sectionId: string) {
|
|
8
|
+
const layoutId = useLayoutContext();
|
|
9
|
+
const radius = useKeyframeValue(
|
|
10
|
+
item,
|
|
11
|
+
KeyframeType.BorderRadius,
|
|
12
|
+
(item, layoutId) => {
|
|
13
|
+
if (!layoutId) return;
|
|
14
|
+
const layoutParams = item.layoutParams[layoutId];
|
|
15
|
+
return 'radius' in layoutParams ? layoutParams.radius : 0;
|
|
16
|
+
},
|
|
17
|
+
(animator, scroll, value) => value !== undefined ? animator.getRadius({ radius: value }, scroll).radius : undefined,
|
|
18
|
+
sectionId,
|
|
19
|
+
[layoutId]
|
|
20
|
+
);
|
|
21
|
+
const strokeWidth = useKeyframeValue(
|
|
22
|
+
item,
|
|
23
|
+
KeyframeType.BorderWidth,
|
|
24
|
+
(item, layoutId) => {
|
|
25
|
+
if (!layoutId) return;
|
|
26
|
+
const layoutParams = item.layoutParams[layoutId];
|
|
27
|
+
return 'strokeWidth' in layoutParams ? layoutParams.strokeWidth : 0;
|
|
28
|
+
},
|
|
29
|
+
(animator, scroll, value) => value !== undefined ? animator.getBorderWidth({ borderWidth: value }, scroll).borderWidth : undefined,
|
|
30
|
+
sectionId,
|
|
31
|
+
[layoutId]
|
|
32
|
+
);
|
|
33
|
+
const fillColor = useKeyframeValue(
|
|
34
|
+
item,
|
|
35
|
+
KeyframeType.Color,
|
|
36
|
+
(item, layoutId) => {
|
|
37
|
+
if (!layoutId) return;
|
|
38
|
+
const layoutParams = item.layoutParams[layoutId];
|
|
39
|
+
return 'fillColor' in layoutParams ? layoutParams.fillColor : defaultColor;
|
|
40
|
+
},
|
|
41
|
+
(animator, scroll, value) => value ? animator.getColor({ color: value }, scroll).color : undefined,
|
|
42
|
+
sectionId,
|
|
43
|
+
[layoutId]
|
|
44
|
+
);
|
|
45
|
+
const strokeColor = useKeyframeValue(
|
|
46
|
+
item,
|
|
47
|
+
KeyframeType.BorderColor,
|
|
48
|
+
(item, layoutId) => {
|
|
49
|
+
if (!layoutId) return;
|
|
50
|
+
const layoutParams = item.layoutParams[layoutId];
|
|
51
|
+
return 'strokeColor' in layoutParams ? layoutParams.strokeColor : defaultColor;
|
|
52
|
+
},
|
|
53
|
+
(animator, scroll, value) => value ? animator.getBorderColor({ color: value }, scroll).color : undefined,
|
|
54
|
+
sectionId,
|
|
55
|
+
[layoutId]
|
|
56
|
+
);
|
|
57
|
+
const blur = useKeyframeValue(
|
|
58
|
+
item,
|
|
59
|
+
KeyframeType.Blur,
|
|
60
|
+
(item, layoutId) => {
|
|
61
|
+
if (!layoutId) return;
|
|
62
|
+
const layoutParams = item.layoutParams[layoutId];
|
|
63
|
+
return 'blur' in layoutParams ? layoutParams.blur : 0;
|
|
64
|
+
},
|
|
65
|
+
(animator, scroll, value) => value !== undefined ? animator.getBlur({ blur: value }, scroll).blur : undefined,
|
|
66
|
+
sectionId,
|
|
67
|
+
[layoutId]
|
|
68
|
+
);
|
|
69
|
+
const backdropBlur = useKeyframeValue(
|
|
70
|
+
item,
|
|
71
|
+
KeyframeType.BackdropBlur,
|
|
72
|
+
(item, layoutId) => {
|
|
73
|
+
if (!layoutId) return;
|
|
74
|
+
const layoutParams = item.layoutParams[layoutId];
|
|
75
|
+
return 'backdropBlur' in layoutParams ? layoutParams.backdropBlur : 0;
|
|
76
|
+
},
|
|
77
|
+
(animator, scroll, value) => value !== undefined ? animator.getBackdropBlur({ backdropBlur: value }, scroll).backdropBlur : undefined,
|
|
78
|
+
sectionId,
|
|
79
|
+
[layoutId]
|
|
80
|
+
);
|
|
81
|
+
return { fillColor, strokeWidth, radius, strokeColor, blur, backdropBlur };
|
|
82
|
+
}
|
|
@@ -1,105 +1,105 @@
|
|
|
1
|
-
import { FC, useEffect, useId, useMemo, useState } from 'react';
|
|
2
|
-
import { CntrlColor } from '@cntrl-site/color';
|
|
3
|
-
import { getLayoutStyles, RichTextItem as TRichTextItem } from '@cntrl-site/sdk';
|
|
4
|
-
import JSXStyle from 'styled-jsx/style';
|
|
5
|
-
import { ItemProps } from '../Item';
|
|
6
|
-
import { useRichTextItem } from './useRichTextItem';
|
|
7
|
-
import { useCntrlContext } from '../../../provider/useCntrlContext';
|
|
8
|
-
import { useRichTextItemValues } from '../useRichTextItemValues';
|
|
9
|
-
import { useRegisterResize } from '../../../common/useRegisterResize';
|
|
10
|
-
import { getFontFamilyValue } from '../../../utils/getFontFamilyValue';
|
|
11
|
-
import { useExemplary } from '../../../common/useExemplary';
|
|
12
|
-
import { useItemAngle } from '../useItemAngle';
|
|
13
|
-
import { getStyleFromItemStateAndParams } from '../../../utils/getStyleFromItemStateAndParams';
|
|
14
|
-
import { useCurrentLayout } from '../../../common/useCurrentLayout';
|
|
15
|
-
|
|
16
|
-
export const RichTextItem: FC<ItemProps<TRichTextItem>> = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
|
|
17
|
-
const id = useId();
|
|
18
|
-
const [ref, setRef] = useState<HTMLDivElement | null>(null);
|
|
19
|
-
const { layouts } = useCntrlContext();
|
|
20
|
-
const itemAngle = useItemAngle(item, sectionId);
|
|
21
|
-
const {
|
|
22
|
-
blur: itemBlur,
|
|
23
|
-
wordSpacing: itemWordSpacing,
|
|
24
|
-
letterSpacing: itemLetterSpacing,
|
|
25
|
-
color: itemColor,
|
|
26
|
-
fontSize,
|
|
27
|
-
lineHeight
|
|
28
|
-
} = useRichTextItemValues(item, sectionId);
|
|
29
|
-
const layoutValues: Record<string, any>[] = [item.area, item.layoutParams];
|
|
30
|
-
const exemplary = useExemplary();
|
|
31
|
-
const { layoutId } = useCurrentLayout();
|
|
32
|
-
useRegisterResize(ref, onResize);
|
|
33
|
-
const stateParams = interactionCtrl?.getState(['angle', 'blur', 'letterSpacing', 'wordSpacing', 'color']);
|
|
34
|
-
const stateStyles = stateParams?.styles ?? {};
|
|
35
|
-
const transition = stateParams?.transition ?? 'none';
|
|
36
|
-
const textColor = useMemo(() => {
|
|
37
|
-
const color = getStyleFromItemStateAndParams(stateParams?.styles?.color, itemColor);
|
|
38
|
-
return color ? CntrlColor.parse(color) : undefined;
|
|
39
|
-
}, [itemColor, stateStyles.color]);
|
|
40
|
-
const angle = getStyleFromItemStateAndParams(stateStyles.angle, itemAngle);
|
|
41
|
-
const blur = getStyleFromItemStateAndParams(stateStyles.blur, itemBlur);
|
|
42
|
-
const letterSpacing = getStyleFromItemStateAndParams(stateStyles.letterSpacing, itemLetterSpacing);
|
|
43
|
-
const wordSpacing = getStyleFromItemStateAndParams(stateStyles.wordSpacing, itemWordSpacing);
|
|
44
|
-
const colorAlpha = textColor?.getAlpha();
|
|
45
|
-
const rangeStyles = layoutId ? item.layoutParams[layoutId]?.rangeStyles ?? [] : [];
|
|
46
|
-
const rangeColors = rangeStyles.filter((style) => style.style === 'COLOR');
|
|
47
|
-
const hasVisibleRangeColors = rangeColors.some((color) => {
|
|
48
|
-
const alpha = CntrlColor.parse(color.value!).getAlpha();
|
|
49
|
-
return alpha > 0;
|
|
50
|
-
});
|
|
51
|
-
const isInteractive = colorAlpha !== 0 || hasVisibleRangeColors;
|
|
52
|
-
const [content, styles] = useRichTextItem(item);
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
onVisibilityChange?.(isInteractive);
|
|
55
|
-
}, [isInteractive, onVisibilityChange]);
|
|
56
|
-
|
|
57
|
-
return (
|
|
58
|
-
<>
|
|
59
|
-
<div
|
|
60
|
-
ref={setRef}
|
|
61
|
-
className={`rich-text-wrapper-${item.id}`}
|
|
62
|
-
style={{
|
|
63
|
-
...(blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {}),
|
|
64
|
-
...(textColor ? { color: `${textColor.fmt('rgba')}` } : {}),
|
|
65
|
-
...(angle !== undefined ? { transform: `rotate(${angle}deg)` } : {}),
|
|
66
|
-
...(letterSpacing !== undefined ? { letterSpacing: `${letterSpacing * exemplary}px` } : {}),
|
|
67
|
-
...(wordSpacing !== undefined ? { wordSpacing: `${wordSpacing * exemplary}px` } : {}),
|
|
68
|
-
...(fontSize !== undefined ? { fontSize: `${Math.round(fontSize * exemplary)}px` } : {}),
|
|
69
|
-
...(lineHeight !== undefined ? { lineHeight: `${lineHeight * exemplary}px` } : {}),
|
|
70
|
-
transition
|
|
71
|
-
}}
|
|
72
|
-
>
|
|
73
|
-
{content}
|
|
74
|
-
</div>
|
|
75
|
-
<JSXStyle id={id}>
|
|
76
|
-
{styles}
|
|
77
|
-
{`${getLayoutStyles(layouts, layoutValues, ([area, layoutParams]) => {
|
|
78
|
-
const color = CntrlColor.parse(layoutParams.color);
|
|
79
|
-
return (`
|
|
80
|
-
.rich-text-wrapper-${item.id} {
|
|
81
|
-
font-size: ${layoutParams.fontSize * 100}vw;
|
|
82
|
-
line-height: ${layoutParams.lineHeight * 100}vw;
|
|
83
|
-
letter-spacing: ${layoutParams.letterSpacing * 100}vw;
|
|
84
|
-
word-spacing: ${layoutParams.wordSpacing * 100}vw;
|
|
85
|
-
font-family: ${getFontFamilyValue(layoutParams.typeFace)};
|
|
86
|
-
font-weight: ${layoutParams.fontWeight};
|
|
87
|
-
font-style: ${layoutParams.fontStyle ? layoutParams.fontStyle : 'normal'};
|
|
88
|
-
vertical-align: ${layoutParams.verticalAlign};
|
|
89
|
-
font-variant: ${layoutParams.fontVariant};
|
|
90
|
-
color: ${color.fmt('rgba')};
|
|
91
|
-
transform: rotate(${area.angle}deg);
|
|
92
|
-
filter: ${layoutParams.blur !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
|
|
93
|
-
text-transform: ${layoutParams.textTransform};
|
|
94
|
-
}
|
|
95
|
-
@supports not (color: oklch(42% 0.3 90 / 1)) {
|
|
96
|
-
.rich-text-wrapper-${item.id} {
|
|
97
|
-
color: ${color.fmt('rgba')};
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
`);
|
|
101
|
-
})}`}
|
|
102
|
-
</JSXStyle>
|
|
103
|
-
</>
|
|
104
|
-
);
|
|
105
|
-
};
|
|
1
|
+
import { FC, useEffect, useId, useMemo, useState } from 'react';
|
|
2
|
+
import { CntrlColor } from '@cntrl-site/color';
|
|
3
|
+
import { getLayoutStyles, RichTextItem as TRichTextItem } from '@cntrl-site/sdk';
|
|
4
|
+
import JSXStyle from 'styled-jsx/style';
|
|
5
|
+
import { ItemProps } from '../Item';
|
|
6
|
+
import { useRichTextItem } from './useRichTextItem';
|
|
7
|
+
import { useCntrlContext } from '../../../provider/useCntrlContext';
|
|
8
|
+
import { useRichTextItemValues } from '../useRichTextItemValues';
|
|
9
|
+
import { useRegisterResize } from '../../../common/useRegisterResize';
|
|
10
|
+
import { getFontFamilyValue } from '../../../utils/getFontFamilyValue';
|
|
11
|
+
import { useExemplary } from '../../../common/useExemplary';
|
|
12
|
+
import { useItemAngle } from '../useItemAngle';
|
|
13
|
+
import { getStyleFromItemStateAndParams } from '../../../utils/getStyleFromItemStateAndParams';
|
|
14
|
+
import { useCurrentLayout } from '../../../common/useCurrentLayout';
|
|
15
|
+
|
|
16
|
+
export const RichTextItem: FC<ItemProps<TRichTextItem>> = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
|
|
17
|
+
const id = useId();
|
|
18
|
+
const [ref, setRef] = useState<HTMLDivElement | null>(null);
|
|
19
|
+
const { layouts } = useCntrlContext();
|
|
20
|
+
const itemAngle = useItemAngle(item, sectionId);
|
|
21
|
+
const {
|
|
22
|
+
blur: itemBlur,
|
|
23
|
+
wordSpacing: itemWordSpacing,
|
|
24
|
+
letterSpacing: itemLetterSpacing,
|
|
25
|
+
color: itemColor,
|
|
26
|
+
fontSize,
|
|
27
|
+
lineHeight
|
|
28
|
+
} = useRichTextItemValues(item, sectionId);
|
|
29
|
+
const layoutValues: Record<string, any>[] = [item.area, item.layoutParams];
|
|
30
|
+
const exemplary = useExemplary();
|
|
31
|
+
const { layoutId } = useCurrentLayout();
|
|
32
|
+
useRegisterResize(ref, onResize);
|
|
33
|
+
const stateParams = interactionCtrl?.getState(['angle', 'blur', 'letterSpacing', 'wordSpacing', 'color']);
|
|
34
|
+
const stateStyles = stateParams?.styles ?? {};
|
|
35
|
+
const transition = stateParams?.transition ?? 'none';
|
|
36
|
+
const textColor = useMemo(() => {
|
|
37
|
+
const color = getStyleFromItemStateAndParams(stateParams?.styles?.color, itemColor);
|
|
38
|
+
return color ? CntrlColor.parse(color) : undefined;
|
|
39
|
+
}, [itemColor, stateStyles.color]);
|
|
40
|
+
const angle = getStyleFromItemStateAndParams(stateStyles.angle, itemAngle);
|
|
41
|
+
const blur = getStyleFromItemStateAndParams(stateStyles.blur, itemBlur);
|
|
42
|
+
const letterSpacing = getStyleFromItemStateAndParams(stateStyles.letterSpacing, itemLetterSpacing);
|
|
43
|
+
const wordSpacing = getStyleFromItemStateAndParams(stateStyles.wordSpacing, itemWordSpacing);
|
|
44
|
+
const colorAlpha = textColor?.getAlpha();
|
|
45
|
+
const rangeStyles = layoutId ? item.layoutParams[layoutId]?.rangeStyles ?? [] : [];
|
|
46
|
+
const rangeColors = rangeStyles.filter((style) => style.style === 'COLOR');
|
|
47
|
+
const hasVisibleRangeColors = rangeColors.some((color) => {
|
|
48
|
+
const alpha = CntrlColor.parse(color.value!).getAlpha();
|
|
49
|
+
return alpha > 0;
|
|
50
|
+
});
|
|
51
|
+
const isInteractive = colorAlpha !== 0 || hasVisibleRangeColors;
|
|
52
|
+
const [content, styles] = useRichTextItem(item);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
onVisibilityChange?.(isInteractive);
|
|
55
|
+
}, [isInteractive, onVisibilityChange]);
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<>
|
|
59
|
+
<div
|
|
60
|
+
ref={setRef}
|
|
61
|
+
className={`rich-text-wrapper-${item.id}`}
|
|
62
|
+
style={{
|
|
63
|
+
...(blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {}),
|
|
64
|
+
...(textColor ? { color: `${textColor.fmt('rgba')}` } : {}),
|
|
65
|
+
...(angle !== undefined ? { transform: `rotate(${angle}deg)` } : {}),
|
|
66
|
+
...(letterSpacing !== undefined ? { letterSpacing: `${letterSpacing * exemplary}px` } : {}),
|
|
67
|
+
...(wordSpacing !== undefined ? { wordSpacing: `${wordSpacing * exemplary}px` } : {}),
|
|
68
|
+
...(fontSize !== undefined ? { fontSize: `${Math.round(fontSize * exemplary)}px` } : {}),
|
|
69
|
+
...(lineHeight !== undefined ? { lineHeight: `${lineHeight * exemplary}px` } : {}),
|
|
70
|
+
transition
|
|
71
|
+
}}
|
|
72
|
+
>
|
|
73
|
+
{content}
|
|
74
|
+
</div>
|
|
75
|
+
<JSXStyle id={id}>
|
|
76
|
+
{styles}
|
|
77
|
+
{`${getLayoutStyles(layouts, layoutValues, ([area, layoutParams]) => {
|
|
78
|
+
const color = CntrlColor.parse(layoutParams.color);
|
|
79
|
+
return (`
|
|
80
|
+
.rich-text-wrapper-${item.id} {
|
|
81
|
+
font-size: ${layoutParams.fontSize * 100}vw;
|
|
82
|
+
line-height: ${layoutParams.lineHeight * 100}vw;
|
|
83
|
+
letter-spacing: ${layoutParams.letterSpacing * 100}vw;
|
|
84
|
+
word-spacing: ${layoutParams.wordSpacing * 100}vw;
|
|
85
|
+
font-family: ${getFontFamilyValue(layoutParams.typeFace)};
|
|
86
|
+
font-weight: ${layoutParams.fontWeight};
|
|
87
|
+
font-style: ${layoutParams.fontStyle ? layoutParams.fontStyle : 'normal'};
|
|
88
|
+
vertical-align: ${layoutParams.verticalAlign};
|
|
89
|
+
font-variant: ${layoutParams.fontVariant};
|
|
90
|
+
color: ${color.fmt('rgba')};
|
|
91
|
+
transform: rotate(${area.angle}deg);
|
|
92
|
+
filter: ${layoutParams.blur !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
|
|
93
|
+
text-transform: ${layoutParams.textTransform};
|
|
94
|
+
}
|
|
95
|
+
@supports not (color: oklch(42% 0.3 90 / 1)) {
|
|
96
|
+
.rich-text-wrapper-${item.id} {
|
|
97
|
+
color: ${color.fmt('rgba')};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
`);
|
|
101
|
+
})}`}
|
|
102
|
+
</JSXStyle>
|
|
103
|
+
</>
|
|
104
|
+
);
|
|
105
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { RichTextItem } from '@cntrl-site/sdk';
|
|
2
|
-
import { RichTextConverter } from '../../../utils/RichTextConverter/RichTextConverter';
|
|
3
|
-
import { useCntrlContext } from '../../../provider/useCntrlContext';
|
|
4
|
-
import { ReactNode } from 'react';
|
|
5
|
-
|
|
6
|
-
const richTextConverter = new RichTextConverter();
|
|
7
|
-
|
|
8
|
-
export const useRichTextItem = (item: RichTextItem): [ReactNode[], string] => {
|
|
9
|
-
const { layouts } = useCntrlContext();
|
|
10
|
-
const [content, styles] = richTextConverter.toHtml(item, layouts);
|
|
11
|
-
return [content, styles];
|
|
12
|
-
};
|
|
1
|
+
import { RichTextItem } from '@cntrl-site/sdk';
|
|
2
|
+
import { RichTextConverter } from '../../../utils/RichTextConverter/RichTextConverter';
|
|
3
|
+
import { useCntrlContext } from '../../../provider/useCntrlContext';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
|
+
|
|
6
|
+
const richTextConverter = new RichTextConverter();
|
|
7
|
+
|
|
8
|
+
export const useRichTextItem = (item: RichTextItem): [ReactNode[], string] => {
|
|
9
|
+
const { layouts } = useCntrlContext();
|
|
10
|
+
const [content, styles] = richTextConverter.toHtml(item, layouts);
|
|
11
|
+
return [content, styles];
|
|
12
|
+
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import React, { FC, PropsWithChildren } from 'react';
|
|
2
|
-
|
|
3
|
-
interface RTWrapperProps {
|
|
4
|
-
isRichText: boolean;
|
|
5
|
-
transformOrigin?: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const RichTextWrapper: FC<PropsWithChildren<RTWrapperProps>> = ({ isRichText, children, transformOrigin = 'top left' }) => {
|
|
9
|
-
if (!isRichText) return <>{children}</>;
|
|
10
|
-
return (
|
|
11
|
-
<div style={{ transformOrigin, transform: 'scale(var(--layout-deviation))' }}>
|
|
12
|
-
{children}
|
|
13
|
-
</div>
|
|
14
|
-
);
|
|
15
|
-
};
|
|
1
|
+
import React, { FC, PropsWithChildren } from 'react';
|
|
2
|
+
|
|
3
|
+
interface RTWrapperProps {
|
|
4
|
+
isRichText: boolean;
|
|
5
|
+
transformOrigin?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const RichTextWrapper: FC<PropsWithChildren<RTWrapperProps>> = ({ isRichText, children, transformOrigin = 'top left' }) => {
|
|
9
|
+
if (!isRichText) return <>{children}</>;
|
|
10
|
+
return (
|
|
11
|
+
<div style={{ transformOrigin, transform: 'scale(var(--layout-deviation))' }}>
|
|
12
|
+
{children}
|
|
13
|
+
</div>
|
|
14
|
+
);
|
|
15
|
+
};
|