@cntrl-site/sdk-nextjs 1.8.10 → 1.8.11

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.
Files changed (121) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +4 -4
  3. package/TODO.md +1 -1
  4. package/eslint.config.mjs +35 -35
  5. package/jest.config.js +6 -6
  6. package/lib/common/useItemFXData.js +7 -7
  7. package/lib/components/Article.js +5 -5
  8. package/lib/components/LayoutStyle.js +4 -4
  9. package/lib/components/Section/Section.js +43 -43
  10. package/lib/components/items/CodeEmbedItem/CodeEmbedItem.js +35 -30
  11. package/lib/components/items/ComponentItem/ComponentItem.js +11 -11
  12. package/lib/components/items/CompoundItem/CompoundChild.js +20 -20
  13. package/lib/components/items/CompoundItem/CompoundItem.js +14 -14
  14. package/lib/components/items/CustomItem/CustomItem.js +9 -9
  15. package/lib/components/items/EmbedVideoItem/VimeoEmbed.js +23 -23
  16. package/lib/components/items/EmbedVideoItem/YoutubeEmbed.js +26 -26
  17. package/lib/components/items/FileItem/ImageItem.js +38 -38
  18. package/lib/components/items/FileItem/VideoItem.js +45 -45
  19. package/lib/components/items/GroupItem/GroupItem.js +13 -13
  20. package/lib/components/items/Item.js +30 -30
  21. package/lib/components/items/RectangleItem/RectangleItem.js +20 -20
  22. package/lib/components/items/RichTextItem/RichTextItem.js +21 -21
  23. package/lib/utils/RichTextConverter/RichTextConverter.js +21 -21
  24. package/package.json +58 -57
  25. package/src/common/useCurrentLayout.ts +52 -52
  26. package/src/common/useExemplary.ts +9 -9
  27. package/src/common/useItemFXData.ts +47 -47
  28. package/src/common/useKeyframeValue.ts +85 -85
  29. package/src/common/useRegisterResize.ts +17 -17
  30. package/src/components/Article.tsx +66 -66
  31. package/src/components/ArticleWrapper.tsx +21 -21
  32. package/src/components/Head.tsx +56 -56
  33. package/src/components/LayoutStyle.tsx +21 -21
  34. package/src/components/Page.tsx +33 -33
  35. package/src/components/ScrollPlaybackVideo.tsx +56 -56
  36. package/src/components/Section/Section.tsx +164 -164
  37. package/src/components/Section/useSectionColor.ts +19 -19
  38. package/src/components/Section/useSectionHeightMap.ts +19 -19
  39. package/src/components/items/CodeEmbedItem/CodeEmbedItem.tsx +137 -132
  40. package/src/components/items/CodeEmbedItem/useCodeEmbedItem.ts +36 -36
  41. package/src/components/items/ComponentItem/ComponentItem.tsx +62 -62
  42. package/src/components/items/ComponentItem/useComponentItem.ts +23 -23
  43. package/src/components/items/CompoundItem/CompoundChild.tsx +150 -150
  44. package/src/components/items/CompoundItem/CompoundItem.tsx +70 -70
  45. package/src/components/items/CompoundItem/useCompoundItem.ts +21 -21
  46. package/src/components/items/CustomItem/CustomItem.tsx +48 -48
  47. package/src/components/items/EmbedVideoItem/VimeoEmbed.tsx +202 -202
  48. package/src/components/items/EmbedVideoItem/YoutubeEmbed.tsx +187 -187
  49. package/src/components/items/EmbedVideoItem/useEmbedVideoItem.ts +46 -46
  50. package/src/components/items/FileItem/ImageItem.tsx +156 -156
  51. package/src/components/items/FileItem/VideoItem.tsx +185 -185
  52. package/src/components/items/FileItem/useFileItem.ts +73 -73
  53. package/src/components/items/GroupItem/GroupItem.tsx +79 -79
  54. package/src/components/items/GroupItem/useGroupItem.ts +34 -34
  55. package/src/components/items/Item.tsx +251 -251
  56. package/src/components/items/LinkWrapper.tsx +39 -39
  57. package/src/components/items/RectangleItem/RectangleItem.tsx +95 -95
  58. package/src/components/items/RectangleItem/useRectangleItem.ts +82 -82
  59. package/src/components/items/RichTextItem/RichTextItem.tsx +105 -105
  60. package/src/components/items/RichTextItem/useRichTextItem.ts +12 -12
  61. package/src/components/items/RichTextWrapper.tsx +15 -15
  62. package/src/components/items/itemsMap.ts +28 -28
  63. package/src/components/items/useDraggable.ts +252 -252
  64. package/src/components/items/useItemAngle.ts +13 -13
  65. package/src/components/items/useItemArea.ts +35 -35
  66. package/src/components/items/useItemPointerEvents.ts +23 -23
  67. package/src/components/items/useItemScale.ts +17 -17
  68. package/src/components/items/useItemTriggers.ts +15 -15
  69. package/src/components/items/useRichTextItemValues.ts +65 -65
  70. package/src/components/items/useSizing.ts +25 -25
  71. package/src/components/items/useStickyItemTop.ts +21 -21
  72. package/src/components/useLayoutContext.ts +7 -7
  73. package/src/index.ts +24 -24
  74. package/src/interactions/CSSPropertyNameMap.ts +38 -38
  75. package/src/interactions/InteractionsRegistry.ts +283 -283
  76. package/src/interactions/ItemInteractionCtrl.ts +77 -77
  77. package/src/interactions/getTransition.ts +27 -27
  78. package/src/interactions/types.ts +36 -36
  79. package/src/interactions/useItemInteractionCtrl.ts +18 -18
  80. package/src/provider/ArticleRectContext.ts +4 -4
  81. package/src/provider/CntrlContext.ts +5 -5
  82. package/src/provider/CntrlProvider.tsx +11 -11
  83. package/src/provider/CntrlSdkContext.ts +83 -83
  84. package/src/provider/CustomItemRegistry.ts +14 -14
  85. package/src/provider/CustomItemTypes.ts +3 -3
  86. package/src/provider/CustomSectionRegistry.ts +25 -25
  87. package/src/provider/InteractionsContext.old.tsx +66 -66
  88. package/src/provider/InteractionsContext.test.tsx +97 -97
  89. package/src/provider/InteractionsContext.tsx +28 -28
  90. package/src/provider/Keyframes.ts +11 -11
  91. package/src/provider/KeyframesContext.ts +5 -5
  92. package/src/provider/LayoutContext.ts +3 -3
  93. package/src/provider/defaultContext.ts +8 -8
  94. package/src/provider/useCntrlContext.ts +8 -8
  95. package/src/styled-jsx.d.ts +1 -1
  96. package/src/utils/Animator/Animator.ts +371 -371
  97. package/src/utils/ArticleRectManager/ArticleRectObserver.ts +93 -93
  98. package/src/utils/ArticleRectManager/useArticleRectObserver.ts +17 -17
  99. package/src/utils/ArticleRectManager/useSectionRegistry.ts +11 -11
  100. package/src/utils/EventEmitter.ts +41 -41
  101. package/src/utils/RichTextConverter/RichTextConverter.tsx +326 -326
  102. package/src/utils/ScaleAnchorMap.ts +13 -13
  103. package/src/utils/StickyManager/StickyManager.ts +23 -23
  104. package/src/utils/Youtube/YouTubeIframeApiLoader.ts +58 -58
  105. package/src/utils/Youtube/YoutubeIframeApi.ts +101 -101
  106. package/src/utils/Youtube/useYouTubeIframeApi.ts +12 -12
  107. package/src/utils/binSearchInsertAt.ts +33 -33
  108. package/src/utils/castObject.ts +10 -10
  109. package/src/utils/effects/useImageFx.ts +113 -113
  110. package/src/utils/effects/useVideoFx.ts +116 -116
  111. package/src/utils/getAnchoredItemTop.ts +12 -12
  112. package/src/utils/getCompoundBoundaryStyles.ts +60 -60
  113. package/src/utils/getFontFamilyValue.ts +3 -3
  114. package/src/utils/getInvertedRanges.ts +43 -43
  115. package/src/utils/getItemTopStyle.ts +14 -14
  116. package/src/utils/getStyleFromItemStateAndParams.ts +8 -8
  117. package/src/utils/getValidYoutubeUrl.ts +29 -29
  118. package/src/utils/isItemType.ts +5 -5
  119. package/src/utils/rangeMap.ts +13 -13
  120. package/src/utils/useElementRect.ts +23 -23
  121. package/cntrl-site-sdk-nextjs-1.8.1.tgz +0 -0
@@ -1,187 +1,187 @@
1
- import { FC, useEffect, useId, useState } from 'react';
2
- import JSXStyle from 'styled-jsx/style';
3
- import { ItemProps } from '../Item';
4
- import { LinkWrapper } from '../LinkWrapper';
5
- import { getYoutubeId } from '../../../utils/getValidYoutubeUrl';
6
- import { useEmbedVideoItem } from './useEmbedVideoItem';
7
- import { useItemAngle } from '../useItemAngle';
8
- import { getLayoutStyles, YoutubeEmbedItem as TYoutubeEmbedItem } from '@cntrl-site/sdk';
9
- import { useCntrlContext } from '../../../provider/useCntrlContext';
10
- import { useYouTubeIframeApi } from '../../../utils/Youtube/useYouTubeIframeApi';
11
- import { YTPlayer } from '../../../utils/Youtube/YoutubeIframeApi';
12
- import { useRegisterResize } from "../../../common/useRegisterResize";
13
- import { getStyleFromItemStateAndParams } from '../../../utils/getStyleFromItemStateAndParams';
14
-
15
- export const YoutubeEmbedItem: FC<ItemProps<TYoutubeEmbedItem>> = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
16
- const id = useId();
17
- const { layouts } = useCntrlContext();
18
- const { play, controls, url } = item.commonParams;
19
- const { radius: itemRadius, blur: itemBlur, opacity: itemOpacity } = useEmbedVideoItem(item, sectionId);
20
- const itemAngle = useItemAngle(item, sectionId);
21
- const YT = useYouTubeIframeApi();
22
- const [div, setDiv] = useState<HTMLDivElement | null>(null);
23
- const [player, setPlayer] = useState<YTPlayer | undefined>(undefined);
24
- const [isCoverVisible, setIsCoverVisible] = useState(false);
25
- const [imgRef, setImgRef] = useState<HTMLImageElement | null>(null);
26
- const layoutValues: Record<string, any>[] = [item.area, item.layoutParams];
27
- const wrapperStateParams = interactionCtrl?.getState(['angle', 'blur', 'opacity']);
28
- const frameStateParams = interactionCtrl?.getState(['radius']);
29
- const angle = getStyleFromItemStateAndParams(wrapperStateParams?.styles?.angle, itemAngle);
30
- const blur = getStyleFromItemStateAndParams(wrapperStateParams?.styles?.blur, itemBlur);
31
- const opacity = getStyleFromItemStateAndParams(wrapperStateParams?.styles?.opacity, itemOpacity);
32
- const radius = getStyleFromItemStateAndParams(frameStateParams?.styles?.radius, itemRadius);
33
- const isInteractive = opacity !== 0;
34
- useEffect(() => {
35
- onVisibilityChange?.(isInteractive);
36
- }, [isInteractive, onVisibilityChange]);
37
- useRegisterResize(div, onResize);
38
- useEffect(() => {
39
- const newUrl = new URL(url);
40
- const videoId = getYoutubeId(newUrl);
41
- if (!YT || !videoId || !div) return;
42
- const placeholder = document.createElement('div');
43
- div.appendChild(placeholder);
44
- const player = new YT.Player(placeholder, {
45
- videoId,
46
- playerVars: {
47
- autoplay: play === 'auto' ? '1' : '0',
48
- controls: controls ? '1' : '0'
49
- },
50
- events: {
51
- onStateChange: (event) => {
52
- if (play !== 'auto') return;
53
- if (event.data === 1) {
54
- setIsCoverVisible(false);
55
- }
56
- if (event.data === 2 || event.data === -1 ) {
57
- setIsCoverVisible(true);
58
- }
59
- },
60
- onReady: (event) => {
61
- setPlayer(event.target);
62
- if (play !== 'on-click') {
63
- player.mute();
64
- }
65
- }
66
- }
67
- });
68
- return () => {
69
- setPlayer(undefined);
70
- player.destroy();
71
- placeholder.parentElement?.removeChild(placeholder);
72
- };
73
- }, [YT, div]);
74
-
75
- const onCoverClick = () => {
76
- if (!player || !imgRef) return;
77
- player.playVideo();
78
- setIsCoverVisible(false);
79
- };
80
-
81
- useEffect(() => {
82
- if (play === 'on-click' && !controls) {
83
- setIsCoverVisible(true);
84
- }
85
- }, []);
86
-
87
- useEffect(() => {
88
- onVisibilityChange?.(isInteractive);
89
- if (!isInteractive && player) {
90
- player.pauseVideo();
91
- }
92
- }, [isInteractive, onVisibilityChange, player]);
93
-
94
- useEffect(() => {
95
- if (!player || !interactionCtrl) return;
96
- interactionCtrl.setActionReceiver((type) => {
97
- switch(type) {
98
- case 'play':
99
- player.playVideo();
100
- break;
101
- case 'pause':
102
- player.pauseVideo();
103
- break;
104
- }
105
- });
106
- }, [interactionCtrl, player]);
107
-
108
- return (
109
- <LinkWrapper url={item.link?.url} target={item.link?.target}>
110
- <div
111
- className={`embed-youtube-video-wrapper-${item.id}`}
112
- onMouseEnter={() => {
113
- if (!player || play !== 'on-hover') return;
114
- player.playVideo();
115
- }}
116
- onMouseLeave={() => {
117
- if (!player || play !== 'on-hover') return;
118
- player.pauseVideo();
119
- }}
120
- style={{
121
- ...(opacity !== undefined ? { opacity } : {}),
122
- ...(angle !== undefined ? { transform: `rotate(${angle}deg)` } : {}),
123
- ...(blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {}),
124
- transition: wrapperStateParams?.transition ?? 'none'
125
- }}
126
- >
127
- {item.commonParams.coverUrl && (
128
- <img
129
- ref={setImgRef}
130
- onClick={() => onCoverClick()}
131
- src={item.commonParams.coverUrl ?? ''}
132
- style={{
133
- display: isCoverVisible ? 'block' : 'none',
134
- cursor: 'pointer',
135
- position: 'absolute',
136
- objectFit: 'cover',
137
- height: '100%',
138
- width: '100%',
139
- top: '0',
140
- left: '0',
141
- zIndex: 1
142
- }}
143
- alt="Cover img"
144
- />
145
- )}
146
- <div
147
- className={`embed-${item.id}`}
148
- ref={setDiv}
149
- style={{
150
- ...(radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {}),
151
- transition: frameStateParams?.transition ?? 'none'
152
- }}
153
- />
154
- </div>
155
- <JSXStyle id={id}>{`
156
- .embed-youtube-video-wrapper-${item.id},
157
- .embed-${item.id} {
158
- position: absolute;
159
- width: 100%;
160
- height: 100%;
161
- }
162
- .embed-${item.id} {
163
- overflow: hidden;
164
- }
165
- .embed-youtube-video-wrapper-${item.id} iframe {
166
- width: 100%;
167
- height: 100%;
168
- z-index: 1;
169
- border: none;
170
- }
171
- ${getLayoutStyles(layouts, layoutValues, ([area, layoutParams]) => {
172
- return (`
173
- .embed-youtube-video-wrapper-${item.id} {
174
- opacity: ${layoutParams.opacity};
175
- transform: rotate(${area.angle}deg);
176
- filter: ${layoutParams.blur !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
177
- }
178
- .embed-youtube-video-wrapper-${item.id} .embed-${item.id} {
179
- border-radius: ${layoutParams.radius * 100}vw;
180
- }
181
- `);
182
- })}
183
- `}</JSXStyle>
184
- </LinkWrapper>
185
- )
186
- };
187
-
1
+ import { FC, useEffect, useId, useState } from 'react';
2
+ import JSXStyle from 'styled-jsx/style';
3
+ import { ItemProps } from '../Item';
4
+ import { LinkWrapper } from '../LinkWrapper';
5
+ import { getYoutubeId } from '../../../utils/getValidYoutubeUrl';
6
+ import { useEmbedVideoItem } from './useEmbedVideoItem';
7
+ import { useItemAngle } from '../useItemAngle';
8
+ import { getLayoutStyles, YoutubeEmbedItem as TYoutubeEmbedItem } from '@cntrl-site/sdk';
9
+ import { useCntrlContext } from '../../../provider/useCntrlContext';
10
+ import { useYouTubeIframeApi } from '../../../utils/Youtube/useYouTubeIframeApi';
11
+ import { YTPlayer } from '../../../utils/Youtube/YoutubeIframeApi';
12
+ import { useRegisterResize } from "../../../common/useRegisterResize";
13
+ import { getStyleFromItemStateAndParams } from '../../../utils/getStyleFromItemStateAndParams';
14
+
15
+ export const YoutubeEmbedItem: FC<ItemProps<TYoutubeEmbedItem>> = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
16
+ const id = useId();
17
+ const { layouts } = useCntrlContext();
18
+ const { play, controls, url } = item.commonParams;
19
+ const { radius: itemRadius, blur: itemBlur, opacity: itemOpacity } = useEmbedVideoItem(item, sectionId);
20
+ const itemAngle = useItemAngle(item, sectionId);
21
+ const YT = useYouTubeIframeApi();
22
+ const [div, setDiv] = useState<HTMLDivElement | null>(null);
23
+ const [player, setPlayer] = useState<YTPlayer | undefined>(undefined);
24
+ const [isCoverVisible, setIsCoverVisible] = useState(false);
25
+ const [imgRef, setImgRef] = useState<HTMLImageElement | null>(null);
26
+ const layoutValues: Record<string, any>[] = [item.area, item.layoutParams];
27
+ const wrapperStateParams = interactionCtrl?.getState(['angle', 'blur', 'opacity']);
28
+ const frameStateParams = interactionCtrl?.getState(['radius']);
29
+ const angle = getStyleFromItemStateAndParams(wrapperStateParams?.styles?.angle, itemAngle);
30
+ const blur = getStyleFromItemStateAndParams(wrapperStateParams?.styles?.blur, itemBlur);
31
+ const opacity = getStyleFromItemStateAndParams(wrapperStateParams?.styles?.opacity, itemOpacity);
32
+ const radius = getStyleFromItemStateAndParams(frameStateParams?.styles?.radius, itemRadius);
33
+ const isInteractive = opacity !== 0;
34
+ useEffect(() => {
35
+ onVisibilityChange?.(isInteractive);
36
+ }, [isInteractive, onVisibilityChange]);
37
+ useRegisterResize(div, onResize);
38
+ useEffect(() => {
39
+ const newUrl = new URL(url);
40
+ const videoId = getYoutubeId(newUrl);
41
+ if (!YT || !videoId || !div) return;
42
+ const placeholder = document.createElement('div');
43
+ div.appendChild(placeholder);
44
+ const player = new YT.Player(placeholder, {
45
+ videoId,
46
+ playerVars: {
47
+ autoplay: play === 'auto' ? '1' : '0',
48
+ controls: controls ? '1' : '0'
49
+ },
50
+ events: {
51
+ onStateChange: (event) => {
52
+ if (play !== 'auto') return;
53
+ if (event.data === 1) {
54
+ setIsCoverVisible(false);
55
+ }
56
+ if (event.data === 2 || event.data === -1 ) {
57
+ setIsCoverVisible(true);
58
+ }
59
+ },
60
+ onReady: (event) => {
61
+ setPlayer(event.target);
62
+ if (play !== 'on-click') {
63
+ player.mute();
64
+ }
65
+ }
66
+ }
67
+ });
68
+ return () => {
69
+ setPlayer(undefined);
70
+ player.destroy();
71
+ placeholder.parentElement?.removeChild(placeholder);
72
+ };
73
+ }, [YT, div]);
74
+
75
+ const onCoverClick = () => {
76
+ if (!player || !imgRef) return;
77
+ player.playVideo();
78
+ setIsCoverVisible(false);
79
+ };
80
+
81
+ useEffect(() => {
82
+ if (play === 'on-click' && !controls) {
83
+ setIsCoverVisible(true);
84
+ }
85
+ }, []);
86
+
87
+ useEffect(() => {
88
+ onVisibilityChange?.(isInteractive);
89
+ if (!isInteractive && player) {
90
+ player.pauseVideo();
91
+ }
92
+ }, [isInteractive, onVisibilityChange, player]);
93
+
94
+ useEffect(() => {
95
+ if (!player || !interactionCtrl) return;
96
+ interactionCtrl.setActionReceiver((type) => {
97
+ switch(type) {
98
+ case 'play':
99
+ player.playVideo();
100
+ break;
101
+ case 'pause':
102
+ player.pauseVideo();
103
+ break;
104
+ }
105
+ });
106
+ }, [interactionCtrl, player]);
107
+
108
+ return (
109
+ <LinkWrapper url={item.link?.url} target={item.link?.target}>
110
+ <div
111
+ className={`embed-youtube-video-wrapper-${item.id}`}
112
+ onMouseEnter={() => {
113
+ if (!player || play !== 'on-hover') return;
114
+ player.playVideo();
115
+ }}
116
+ onMouseLeave={() => {
117
+ if (!player || play !== 'on-hover') return;
118
+ player.pauseVideo();
119
+ }}
120
+ style={{
121
+ ...(opacity !== undefined ? { opacity } : {}),
122
+ ...(angle !== undefined ? { transform: `rotate(${angle}deg)` } : {}),
123
+ ...(blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {}),
124
+ transition: wrapperStateParams?.transition ?? 'none'
125
+ }}
126
+ >
127
+ {item.commonParams.coverUrl && (
128
+ <img
129
+ ref={setImgRef}
130
+ onClick={() => onCoverClick()}
131
+ src={item.commonParams.coverUrl ?? ''}
132
+ style={{
133
+ display: isCoverVisible ? 'block' : 'none',
134
+ cursor: 'pointer',
135
+ position: 'absolute',
136
+ objectFit: 'cover',
137
+ height: '100%',
138
+ width: '100%',
139
+ top: '0',
140
+ left: '0',
141
+ zIndex: 1
142
+ }}
143
+ alt="Cover img"
144
+ />
145
+ )}
146
+ <div
147
+ className={`embed-${item.id}`}
148
+ ref={setDiv}
149
+ style={{
150
+ ...(radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {}),
151
+ transition: frameStateParams?.transition ?? 'none'
152
+ }}
153
+ />
154
+ </div>
155
+ <JSXStyle id={id}>{`
156
+ .embed-youtube-video-wrapper-${item.id},
157
+ .embed-${item.id} {
158
+ position: absolute;
159
+ width: 100%;
160
+ height: 100%;
161
+ }
162
+ .embed-${item.id} {
163
+ overflow: hidden;
164
+ }
165
+ .embed-youtube-video-wrapper-${item.id} iframe {
166
+ width: 100%;
167
+ height: 100%;
168
+ z-index: 1;
169
+ border: none;
170
+ }
171
+ ${getLayoutStyles(layouts, layoutValues, ([area, layoutParams]) => {
172
+ return (`
173
+ .embed-youtube-video-wrapper-${item.id} {
174
+ opacity: ${layoutParams.opacity};
175
+ transform: rotate(${area.angle}deg);
176
+ filter: ${layoutParams.blur !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
177
+ }
178
+ .embed-youtube-video-wrapper-${item.id} .embed-${item.id} {
179
+ border-radius: ${layoutParams.radius * 100}vw;
180
+ }
181
+ `);
182
+ })}
183
+ `}</JSXStyle>
184
+ </LinkWrapper>
185
+ )
186
+ };
187
+
@@ -1,46 +1,46 @@
1
- import { KeyframeType, VimeoEmbedItem, YoutubeEmbedItem } from '@cntrl-site/sdk';
2
- import { useKeyframeValue } from '../../../common/useKeyframeValue';
3
- import { useLayoutContext } from '../../useLayoutContext';
4
-
5
- export const useEmbedVideoItem = (item: VimeoEmbedItem | YoutubeEmbedItem, sectionId: string) => {
6
- const layoutId = useLayoutContext();
7
- const radius = useKeyframeValue(
8
- item,
9
- KeyframeType.BorderRadius,
10
- (item, layoutId) => {
11
- if (!layoutId) return;
12
- const layoutParams = item.layoutParams[layoutId];
13
- return 'radius' in layoutParams ? layoutParams.radius : 0;
14
- },
15
- (animator, scroll, value) => value !== undefined ? animator.getRadius({ radius: value }, scroll).radius : undefined,
16
- sectionId,
17
- [layoutId]
18
- );
19
- const blur = useKeyframeValue(
20
- item,
21
- KeyframeType.Blur,
22
- (item, layoutId) => {
23
- if (!layoutId) return;
24
- const layoutParams = item.layoutParams[layoutId];
25
- return 'blur' in layoutParams ? layoutParams.blur : 0;
26
- },
27
- (animator, scroll, value) => value !== undefined ? animator.getBlur({ blur: value }, scroll).blur : undefined,
28
- sectionId,
29
- [layoutId]
30
- );
31
-
32
- const opacity = useKeyframeValue(
33
- item,
34
- KeyframeType.Opacity,
35
- (item, layoutId) => {
36
- if (!layoutId) return;
37
- const layoutParams = item.layoutParams[layoutId];
38
- return 'opacity' in layoutParams ? layoutParams.opacity : 1;
39
- },
40
- (animator, scroll, value) => value !== undefined ? animator.getOpacity({ opacity: value }, scroll).opacity : undefined,
41
- sectionId,
42
- [layoutId]
43
- );
44
-
45
- return { radius, blur, opacity };
46
- };
1
+ import { KeyframeType, VimeoEmbedItem, YoutubeEmbedItem } from '@cntrl-site/sdk';
2
+ import { useKeyframeValue } from '../../../common/useKeyframeValue';
3
+ import { useLayoutContext } from '../../useLayoutContext';
4
+
5
+ export const useEmbedVideoItem = (item: VimeoEmbedItem | YoutubeEmbedItem, sectionId: string) => {
6
+ const layoutId = useLayoutContext();
7
+ const radius = useKeyframeValue(
8
+ item,
9
+ KeyframeType.BorderRadius,
10
+ (item, layoutId) => {
11
+ if (!layoutId) return;
12
+ const layoutParams = item.layoutParams[layoutId];
13
+ return 'radius' in layoutParams ? layoutParams.radius : 0;
14
+ },
15
+ (animator, scroll, value) => value !== undefined ? animator.getRadius({ radius: value }, scroll).radius : undefined,
16
+ sectionId,
17
+ [layoutId]
18
+ );
19
+ const blur = useKeyframeValue(
20
+ item,
21
+ KeyframeType.Blur,
22
+ (item, layoutId) => {
23
+ if (!layoutId) return;
24
+ const layoutParams = item.layoutParams[layoutId];
25
+ return 'blur' in layoutParams ? layoutParams.blur : 0;
26
+ },
27
+ (animator, scroll, value) => value !== undefined ? animator.getBlur({ blur: value }, scroll).blur : undefined,
28
+ sectionId,
29
+ [layoutId]
30
+ );
31
+
32
+ const opacity = useKeyframeValue(
33
+ item,
34
+ KeyframeType.Opacity,
35
+ (item, layoutId) => {
36
+ if (!layoutId) return;
37
+ const layoutParams = item.layoutParams[layoutId];
38
+ return 'opacity' in layoutParams ? layoutParams.opacity : 1;
39
+ },
40
+ (animator, scroll, value) => value !== undefined ? animator.getOpacity({ opacity: value }, scroll).opacity : undefined,
41
+ sectionId,
42
+ [layoutId]
43
+ );
44
+
45
+ return { radius, blur, opacity };
46
+ };