@cntrl-site/sdk-nextjs 1.0.20 → 1.1.1

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 (47) hide show
  1. package/jest.config.js +2 -2
  2. package/lib/components/Article.js +9 -8
  3. package/lib/components/Item.js +39 -21
  4. package/lib/components/items/CodeEmbedItem.js +15 -12
  5. package/lib/components/items/CustomItem.js +7 -9
  6. package/lib/components/items/GroupItem.js +15 -12
  7. package/lib/components/items/ImageItem.js +28 -21
  8. package/lib/components/items/RectangleItem.js +28 -15
  9. package/lib/components/items/RichTextItem.js +33 -12
  10. package/lib/components/items/VideoItem.js +26 -19
  11. package/lib/components/items/VimeoEmbed.js +22 -20
  12. package/lib/components/items/YoutubeEmbed.js +20 -18
  13. package/lib/components/useItemPosition.js +10 -5
  14. package/lib/interactions/CSSPropertyNameMap.js +38 -0
  15. package/lib/interactions/InteractionsRegistry.js +220 -0
  16. package/lib/interactions/ItemInteractionCtrl.js +61 -0
  17. package/lib/interactions/getTransition.js +21 -0
  18. package/lib/interactions/types.js +2 -0
  19. package/lib/interactions/useItemInteractionCtrl.js +17 -0
  20. package/lib/provider/InteractionsContext.js +23 -0
  21. package/lib/utils/getStyleFromItemStateAndParams.js +9 -0
  22. package/package.json +7 -4
  23. package/src/components/Article.tsx +30 -27
  24. package/src/components/ArticleWrapper.tsx +1 -2
  25. package/src/components/Item.tsx +75 -29
  26. package/src/components/items/CodeEmbedItem.tsx +15 -11
  27. package/src/components/items/CustomItem.tsx +9 -11
  28. package/src/components/items/GroupItem.tsx +17 -13
  29. package/src/components/items/ImageItem.tsx +35 -20
  30. package/src/components/items/RectangleItem.tsx +35 -14
  31. package/src/components/items/RichTextItem.tsx +41 -14
  32. package/src/components/items/VideoItem.tsx +34 -20
  33. package/src/components/items/VimeoEmbed.tsx +27 -19
  34. package/src/components/items/YoutubeEmbed.tsx +20 -18
  35. package/src/components/useItemPosition.ts +12 -5
  36. package/src/interactions/CSSPropertyNameMap.ts +38 -0
  37. package/src/interactions/InteractionsRegistry.ts +244 -0
  38. package/src/interactions/ItemInteractionCtrl.ts +62 -0
  39. package/src/interactions/getTransition.ts +27 -0
  40. package/src/interactions/types.ts +32 -0
  41. package/src/interactions/useItemInteractionCtrl.ts +18 -0
  42. package/src/provider/InteractionsContext.old.tsx +65 -0
  43. package/src/provider/InteractionsContext.test.tsx +97 -0
  44. package/src/provider/InteractionsContext.tsx +28 -0
  45. package/src/utils/getStyleFromItemStateAndParams.ts +8 -0
  46. package/lib/utils/HoverStyles/HoverStyles.js +0 -77
  47. package/src/utils/HoverStyles/HoverStyles.ts +0 -85
package/jest.config.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2
2
  module.exports = {
3
3
  preset: 'ts-jest',
4
- testEnvironment: 'node',
4
+ testEnvironment: 'jsdom',
5
5
  rootDir: './src'
6
- };
6
+ };
@@ -12,6 +12,7 @@ const Item_1 = require("./Item");
12
12
  const useArticleRectObserver_1 = require("../utils/ArticleRectManager/useArticleRectObserver");
13
13
  const ArticleRectContext_1 = require("../provider/ArticleRectContext");
14
14
  const ArticleWrapper_1 = require("./ArticleWrapper");
15
+ const InteractionsContext_1 = require("../provider/InteractionsContext");
15
16
  const Article = ({ article, sectionData }) => {
16
17
  const articleRef = (0, react_1.useRef)(null);
17
18
  const articleRectObserver = (0, useArticleRectObserver_1.useArticleRectObserver)(articleRef.current);
@@ -24,14 +25,14 @@ const Article = ({ article, sectionData }) => {
24
25
  setArticleHeight(rect.height / rect.width);
25
26
  });
26
27
  }, [articleRectObserver]);
27
- return ((0, jsx_runtime_1.jsxs)(ArticleRectContext_1.ArticleRectContext.Provider, { value: articleRectObserver, children: [(0, jsx_runtime_1.jsx)(ArticleWrapper_1.ArticleWrapper, { children: (0, jsx_runtime_1.jsx)("div", { className: "article", ref: articleRef, children: article.sections.map((section, i) => {
28
- const data = section.name ? sectionData[section.name] : {};
29
- return ((0, jsx_runtime_1.jsx)(Section_1.Section, { section: section, data: data, children: article.sections[i].items.map(item => ((0, jsx_runtime_1.jsx)(Item_1.Item, { item: item, sectionId: section.id, articleHeight: articleHeight }, item.id))) }, section.id));
30
- }) }) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
28
+ return ((0, jsx_runtime_1.jsx)(ArticleRectContext_1.ArticleRectContext.Provider, { value: articleRectObserver, children: (0, jsx_runtime_1.jsxs)(InteractionsContext_1.InteractionsProvider, { article: article, children: [(0, jsx_runtime_1.jsx)(ArticleWrapper_1.ArticleWrapper, { children: (0, jsx_runtime_1.jsx)("div", { className: "article", ref: articleRef, children: article.sections.map((section, i) => {
29
+ const data = section.name ? sectionData[section.name] : {};
30
+ return ((0, jsx_runtime_1.jsx)(Section_1.Section, { section: section, data: data, children: article.sections[i].items.map(item => ((0, jsx_runtime_1.jsx)(Item_1.Item, { item: item, sectionId: section.id, articleHeight: articleHeight }, item.id))) }, section.id));
31
+ }) }) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
31
32
  .article {
32
- position: relative;
33
- overflow: clip;
34
- }
35
- ` })] }));
33
+ position: relative;
34
+ overflow: clip;
35
+ }
36
+ ` })] }) }));
36
37
  };
37
38
  exports.Article = Article;
@@ -21,7 +21,6 @@ const useItemDimensions_1 = require("./useItemDimensions");
21
21
  const useItemScale_1 = require("./useItemScale");
22
22
  const ScaleAnchorMap_1 = require("../utils/ScaleAnchorMap");
23
23
  const useSectionHeightMap_1 = require("./useSectionHeightMap");
24
- const HoverStyles_1 = require("../utils/HoverStyles/HoverStyles");
25
24
  const getItemTopStyle_1 = require("../utils/getItemTopStyle");
26
25
  const useStickyItemTop_1 = require("./items/useStickyItemTop");
27
26
  const getAnchoredItemTop_1 = require("../utils/getAnchoredItemTop");
@@ -31,6 +30,7 @@ const useExemplary_1 = require("../common/useExemplary");
31
30
  const GroupItem_1 = require("./items/GroupItem");
32
31
  const CodeEmbedItem_1 = require("./items/CodeEmbedItem");
33
32
  const KeyframesContext_1 = require("../provider/KeyframesContext");
33
+ const useItemInteractionCtrl_1 = require("../interactions/useItemInteractionCtrl");
34
34
  const itemsMap = {
35
35
  [sdk_1.ArticleItemType.Rectangle]: RectangleItem_1.RectangleItem,
36
36
  [sdk_1.ArticleItemType.Image]: ImageItem_1.ImageItem,
@@ -52,8 +52,10 @@ const RichTextWrapper = ({ isRichText, children }) => {
52
52
  return ((0, jsx_runtime_1.jsx)("div", { style: { transformOrigin: 'top left', transform: 'scale(var(--layout-deviation))' }, children: children }));
53
53
  };
54
54
  const noop = () => null;
55
- const Item = ({ item, sectionId, articleHeight, isInGroup = false }) => {
55
+ const Item = ({ item, sectionId, articleHeight, isParentVisible = true, isInGroup = false }) => {
56
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
56
57
  const itemWrapperRef = (0, react_1.useRef)(null);
58
+ const itemInnerRef = (0, react_1.useRef)(null);
57
59
  const rectObserver = (0, react_1.useContext)(ArticleRectContext_1.ArticleRectContext);
58
60
  const keyframesRepo = (0, react_1.useContext)(KeyframesContext_1.KeyframesContext);
59
61
  const id = (0, react_1.useId)();
@@ -61,14 +63,21 @@ const Item = ({ item, sectionId, articleHeight, isInGroup = false }) => {
61
63
  const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
62
64
  const layout = (0, useLayoutContext_1.useLayoutContext)();
63
65
  const exemplary = (0, useExemplary_1.useExemplary)();
66
+ const [allowPointerEvents, setAllowPointerEvents] = (0, react_1.useState)(isParentVisible);
64
67
  const [wrapperHeight, setWrapperHeight] = (0, react_1.useState)(undefined);
65
68
  const [itemHeight, setItemHeight] = (0, react_1.useState)(undefined);
66
- const scale = (0, useItemScale_1.useItemScale)(item, sectionId);
67
- const position = (0, useItemPosition_1.useItemPosition)(item, sectionId);
69
+ const itemScale = (0, useItemScale_1.useItemScale)(item, sectionId);
70
+ const interactionCtrl = (0, useItemInteractionCtrl_1.useItemInteractionCtrl)(item.id);
71
+ const wrapperStateProps = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['top', 'left']);
72
+ const innerStateProps = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['width', 'height', 'scale']);
73
+ const position = (0, useItemPosition_1.useItemPosition)(item, sectionId, {
74
+ top: (_a = wrapperStateProps === null || wrapperStateProps === void 0 ? void 0 : wrapperStateProps.styles) === null || _a === void 0 ? void 0 : _a.top,
75
+ left: (_b = wrapperStateProps === null || wrapperStateProps === void 0 ? void 0 : wrapperStateProps.styles) === null || _b === void 0 ? void 0 : _b.left,
76
+ });
68
77
  const sectionHeight = (0, useSectionHeightMap_1.useSectionHeightData)(sectionId);
69
78
  const stickyTop = (0, useStickyItemTop_1.useStickyItemTop)(item, sectionHeight, sectionId);
70
79
  const dimensions = (0, useItemDimensions_1.useItemDimensions)(item, sectionId);
71
- const layoutValues = [item.area, item.hidden, item.state.hover];
80
+ const layoutValues = [item.area, item.hidden];
72
81
  const isInitialRef = (0, react_1.useRef)(true);
73
82
  layoutValues.push(item.sticky);
74
83
  layoutValues.push(sectionHeight);
@@ -98,23 +107,41 @@ const Item = ({ item, sectionId, articleHeight, isInGroup = false }) => {
98
107
  setItemHeight(height);
99
108
  setWrapperHeight(wrapperHeight);
100
109
  };
110
+ const handleVisibilityChange = (0, react_1.useCallback)((isVisible) => {
111
+ if (!isParentVisible)
112
+ return;
113
+ setAllowPointerEvents(isVisible);
114
+ }, [isParentVisible]);
101
115
  (0, react_1.useEffect)(() => {
102
116
  isInitialRef.current = false;
103
117
  }, []);
104
118
  const isRichText = isItemType(item, sdk_1.ArticleItemType.RichText);
105
- return ((0, jsx_runtime_1.jsxs)("div", { className: `item-wrapper-${item.id}`, ref: itemWrapperRef, style: Object.assign(Object.assign(Object.assign(Object.assign({}, (position ? { top: position.top } : {})), (position ? { left: position.left } : {})), (position ? { bottom: position.bottom } : {})), (wrapperHeight !== undefined ? { height: `${wrapperHeight * 100}vw` } : {})), children: [(0, jsx_runtime_1.jsx)("div", { suppressHydrationWarning: true, className: `item-${item.id}`, style: {
119
+ const width = ((_d = (_c = innerStateProps === null || innerStateProps === void 0 ? void 0 : innerStateProps.styles) === null || _c === void 0 ? void 0 : _c.width) !== null && _d !== void 0 ? _d : dimensions === null || dimensions === void 0 ? void 0 : dimensions.width);
120
+ const height = ((_f = (_e = innerStateProps === null || innerStateProps === void 0 ? void 0 : innerStateProps.styles) === null || _e === void 0 ? void 0 : _e.height) !== null && _f !== void 0 ? _f : dimensions === null || dimensions === void 0 ? void 0 : dimensions.height);
121
+ const scale = (_h = (_g = innerStateProps === null || innerStateProps === void 0 ? void 0 : innerStateProps.styles) === null || _g === void 0 ? void 0 : _g.scale) !== null && _h !== void 0 ? _h : itemScale;
122
+ return ((0, jsx_runtime_1.jsxs)("div", { className: `item-wrapper-${item.id}`, ref: itemWrapperRef, onTransitionEnd: (e) => {
123
+ var _a;
124
+ e.stopPropagation();
125
+ (_a = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.handleTransitionEnd) === null || _a === void 0 ? void 0 : _a.call(interactionCtrl, e.propertyName);
126
+ }, style: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (position ? { top: position.top } : {})), (position ? { left: position.left } : {})), (position ? { bottom: position.bottom } : {})), (wrapperHeight !== undefined ? { height: `${wrapperHeight * 100}vw` } : {})), { transition: (_j = wrapperStateProps === null || wrapperStateProps === void 0 ? void 0 : wrapperStateProps.transition) !== null && _j !== void 0 ? _j : 'none' }), children: [(0, jsx_runtime_1.jsx)("div", { suppressHydrationWarning: true, className: `item-${item.id}`, style: {
106
127
  opacity: (keyframes.length !== 0 && !layout) ? 0 : 1,
107
128
  top: `${stickyTop * 100}vw`,
108
129
  height: isRichText && itemHeight ? `${itemHeight * 100}vw` : 'unset',
109
- }, children: (0, jsx_runtime_1.jsx)(RichTextWrapper, { isRichText: isRichText, children: (0, jsx_runtime_1.jsx)("div", { className: `item-${item.id}-inner`, style: Object.assign(Object.assign({}, (dimensions ? {
130
+ }, children: (0, jsx_runtime_1.jsx)(RichTextWrapper, { isRichText: isRichText, children: (0, jsx_runtime_1.jsx)("div", { className: `item-${item.id}-inner`, ref: itemInnerRef, onClick: () => {
131
+ interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.sendTrigger('click');
132
+ }, onMouseEnter: () => {
133
+ interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.sendTrigger('hover-in');
134
+ }, onMouseLeave: () => {
135
+ interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.sendTrigger('hover-out');
136
+ }, style: Object.assign(Object.assign(Object.assign({}, ((width && height) ? {
110
137
  width: `${sizingAxis.x === 'manual'
111
138
  ? isRichText
112
- ? `${dimensions.width * exemplary}px`
113
- : `${dimensions.width * 100}vw`
139
+ ? `${width * exemplary}px`
140
+ : `${width * 100}vw`
114
141
  : 'max-content'}`,
115
- height: `${sizingAxis.y === 'manual' ? `${dimensions.height * 100}vw` : 'unset'}`
116
- } : {})), (scale !== undefined ? { transform: `scale(${scale})`, 'WebkitTransform': `scale(${scale})` } : {})), children: (0, jsx_runtime_1.jsx)(ItemComponent, { item: item, sectionId: sectionId, onResize: handleItemResize, articleHeight: articleHeight }) }) }) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
117
- ${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, hidden, hoverParams, sticky, sectionHeight, layoutParams], exemplary) => {
142
+ height: `${sizingAxis.y === 'manual' ? `${height * 100}vw` : 'unset'}`
143
+ } : {})), (scale !== undefined ? { transform: `scale(${scale})`, 'WebkitTransform': `scale(${scale})` } : {})), { transition: (_k = innerStateProps === null || innerStateProps === void 0 ? void 0 : innerStateProps.transition) !== null && _k !== void 0 ? _k : 'none', pointerEvents: allowPointerEvents ? 'auto' : 'none' }), children: (0, jsx_runtime_1.jsx)(ItemComponent, { item: item, sectionId: sectionId, onResize: handleItemResize, articleHeight: articleHeight, interactionCtrl: interactionCtrl, onVisibilityChange: handleVisibilityChange }) }) }) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
144
+ ${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, hidden, sticky, sectionHeight, layoutParams], exemplary) => {
118
145
  const sizingAxis = parseSizing(layoutParams.sizing);
119
146
  const isScreenBasedBottom = area.positionType === sdk_1.PositionType.ScreenBased && area.anchorSide === sdk_1.AnchorSide.Bottom;
120
147
  const scaleAnchor = area.scaleAnchor;
@@ -128,8 +155,6 @@ const Item = ({ item, sectionId, articleHeight, isInGroup = false }) => {
128
155
  height: fit-content;
129
156
  }
130
157
  .item-${item.id}-inner {
131
- transition: ${(0, HoverStyles_1.getTransitions)(['width', 'height', 'scale'], hoverParams)};
132
- pointer-events: auto;
133
158
  width: ${sizingAxis.x === 'manual'
134
159
  ? `${area.width * 100}vw`
135
160
  : 'max-content'};
@@ -145,13 +170,6 @@ const Item = ({ item, sectionId, articleHeight, isInGroup = false }) => {
145
170
  bottom: ${isScreenBasedBottom ? `${-area.top * 100}vw` : 'unset'};
146
171
  top: ${isScreenBasedBottom ? 'unset' : (0, getItemTopStyle_1.getItemTopStyle)(area.top, area.anchorSide)};
147
172
  left: ${area.left * 100}vw;
148
- transition: ${(0, HoverStyles_1.getTransitions)(['left', 'top'], hoverParams)};
149
- }
150
- .item-${item.id}-inner:hover {
151
- ${(0, HoverStyles_1.getHoverStyles)(['width', 'height', 'scale'], hoverParams)};
152
- }
153
- .item-wrapper-${item.id}:hover {
154
- ${(0, HoverStyles_1.getHoverStyles)(['left', 'top'], hoverParams, area.anchorSide)};
155
173
  }
156
174
  `);
157
175
  })}
@@ -8,7 +8,6 @@ const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  const sdk_1 = require("@cntrl-site/sdk");
9
9
  const react_1 = require("react");
10
10
  const useCntrlContext_1 = require("../../provider/useCntrlContext");
11
- const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
12
11
  const style_1 = __importDefault(require("styled-jsx/style"));
13
12
  const useRegisterResize_1 = require("../../common/useRegisterResize");
14
13
  const useItemAngle_1 = require("../useItemAngle");
@@ -25,17 +24,21 @@ const stylesMap = {
25
24
  [sdk_1.AreaAnchor.BottomCenter]: { justifyContent: 'center', alignItems: 'flex-end' },
26
25
  [sdk_1.AreaAnchor.BottomRight]: { justifyContent: 'flex-end', alignItems: 'flex-end' }
27
26
  };
28
- const CodeEmbedItem = ({ item, sectionId, onResize }) => {
29
- var _a, _b;
27
+ const CodeEmbedItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
28
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
30
29
  const id = (0, react_1.useId)();
31
30
  const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
32
- const { anchor, blur, opacity } = (0, useCodeEmbedItem_1.useCodeEmbedItem)(item, sectionId);
33
- const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
31
+ const { anchor, blur: itemBlur, opacity: itemOpacity } = (0, useCodeEmbedItem_1.useCodeEmbedItem)(item, sectionId);
32
+ const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
34
33
  const { html } = item.commonParams;
35
34
  const [ref, setRef] = (0, react_1.useState)(null);
36
35
  (0, useRegisterResize_1.useRegisterResize)(ref, onResize);
37
36
  const pos = stylesMap[anchor];
38
- const layoutValues = [item.area, item.layoutParams, item.state.hover];
37
+ const layoutValues = [item.area, item.layoutParams];
38
+ const stateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['angle', 'blur', 'opacity']);
39
+ const blur = ((_b = (_a = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) === null || _a === void 0 ? void 0 : _a.blur) !== null && _b !== void 0 ? _b : itemBlur);
40
+ const opacity = (_d = (_c = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) === null || _c === void 0 ? void 0 : _c.opacity) !== null && _d !== void 0 ? _d : itemOpacity;
41
+ const angle = (_f = (_e = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) === null || _e === void 0 ? void 0 : _e.angle) !== null && _f !== void 0 ? _f : itemAngle;
39
42
  (0, react_1.useEffect)(() => {
40
43
  if (!ref)
41
44
  return;
@@ -58,7 +61,11 @@ const CodeEmbedItem = ({ item, sectionId, onResize }) => {
58
61
  return;
59
62
  iframe.srcdoc = item.commonParams.html;
60
63
  }, [item.commonParams.html, item.commonParams.iframe, ref]);
61
- return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: (_a = item.link) === null || _a === void 0 ? void 0 : _a.url, target: (_b = item.link) === null || _b === void 0 ? void 0 : _b.target, children: [(0, jsx_runtime_1.jsx)("div", { className: `embed-wrapper-${item.id}`, style: Object.assign(Object.assign(Object.assign({}, (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), (opacity !== undefined ? { opacity } : {})), ref: setRef, children: item.commonParams.iframe ? ((0, jsx_runtime_1.jsx)("iframe", { "data-embed": item.id, className: `embed-${item.id}`, style: Object.assign(Object.assign({}, pos), { border: 'unset' }) })) : ((0, jsx_runtime_1.jsx)("div", { className: `embed-${item.id}`, style: Object.assign({}, pos), dangerouslySetInnerHTML: { __html: html } })) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
64
+ const isInteractive = opacity !== 0;
65
+ (0, react_1.useEffect)(() => {
66
+ onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(isInteractive);
67
+ }, [isInteractive, onVisibilityChange]);
68
+ return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: (_g = item.link) === null || _g === void 0 ? void 0 : _g.url, target: (_h = item.link) === null || _h === void 0 ? void 0 : _h.target, children: [(0, jsx_runtime_1.jsx)("div", { className: `embed-wrapper-${item.id}`, style: Object.assign(Object.assign(Object.assign(Object.assign({}, (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), (opacity !== undefined ? { opacity } : {})), { transition: (_j = stateParams === null || stateParams === void 0 ? void 0 : stateParams.transition) !== null && _j !== void 0 ? _j : 'none' }), ref: setRef, children: item.commonParams.iframe ? ((0, jsx_runtime_1.jsx)("iframe", { "data-embed": item.id, className: `embed-${item.id}`, style: Object.assign(Object.assign({}, pos), { border: 'unset' }) })) : ((0, jsx_runtime_1.jsx)("div", { className: `embed-${item.id}`, style: Object.assign({}, pos), dangerouslySetInnerHTML: { __html: html } })) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
62
69
  .embed-wrapper-${item.id} {
63
70
  position: absolute;
64
71
  width: 100%;
@@ -70,21 +77,17 @@ const CodeEmbedItem = ({ item, sectionId, onResize }) => {
70
77
  z-index: 1;
71
78
  border: none;
72
79
  }
73
- ${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams, hoverParams], exemplary) => {
80
+ ${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams], exemplary) => {
74
81
  return (`
75
82
  .embed-wrapper-${item.id} {
76
83
  opacity: ${layoutParams.opacity};
77
84
  transform: rotate(${area.angle}deg);
78
85
  filter: ${layoutParams.blur !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
79
- transition: ${(0, HoverStyles_1.getTransitions)(['angle', 'blur', 'opacity'], hoverParams)};
80
86
  }
81
87
  .embed-${item.id} {
82
88
  width: ${item.commonParams.scale ? `${area.width * exemplary}px` : '100%'};
83
89
  height: ${item.commonParams.scale ? `${area.height * exemplary}px` : '100%'};
84
90
  }
85
- .embed-wrapper-${item.id}:hover {
86
- ${(0, HoverStyles_1.getHoverStyles)(['angle', 'blur', 'opacity'], hoverParams)}
87
- }
88
91
  `);
89
92
  })}
90
93
  ` })] }));
@@ -8,34 +8,32 @@ const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  const sdk_1 = require("@cntrl-site/sdk");
9
9
  const react_1 = require("react");
10
10
  const useCntrlContext_1 = require("../../provider/useCntrlContext");
11
- const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
12
11
  const style_1 = __importDefault(require("styled-jsx/style"));
13
12
  const useRegisterResize_1 = require("../../common/useRegisterResize");
14
13
  const useItemAngle_1 = require("../useItemAngle");
15
- const CustomItem = ({ item, onResize, sectionId }) => {
14
+ const CustomItem = ({ item, onResize, sectionId, interactionCtrl }) => {
15
+ var _a, _b, _c;
16
16
  const sdk = (0, useCntrlContext_1.useCntrlContext)();
17
17
  const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
18
- const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
18
+ const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
19
19
  const component = sdk.customItems.get(item.commonParams.name);
20
- const layoutValues = [item.area, item.state.hover];
20
+ const layoutValues = [item.area];
21
21
  const [ref, setRef] = (0, react_1.useState)(null);
22
22
  (0, useRegisterResize_1.useRegisterResize)(ref, onResize);
23
+ const stateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['angle']);
24
+ const angle = (_b = (_a = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) === null || _a === void 0 ? void 0 : _a.angle) !== null && _b !== void 0 ? _b : itemAngle;
23
25
  if (!component)
24
26
  return null;
25
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `custom-component-${item.id}`, ref: setRef, style: Object.assign({}, (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), children: component({}) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: item.id, children: `${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, hoverParams]) => {
27
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `custom-component-${item.id}`, ref: setRef, style: Object.assign(Object.assign({}, (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), { transition: (_c = stateParams === null || stateParams === void 0 ? void 0 : stateParams.transition) !== null && _c !== void 0 ? _c : 'none' }), children: component({}) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: item.id, children: `${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area]) => {
26
28
  return (`
27
29
  .custom-component-${item.id} {
28
30
  transform: rotate(${area.angle}deg);
29
- transition: ${(0, HoverStyles_1.getTransitions)(['angle'], hoverParams)};
30
31
  height: 100%;
31
32
  width: 100%;
32
33
  position: absolute;
33
34
  left: 0;
34
35
  top: 0;
35
36
  }
36
- .custom-component-${item.id}:hover {
37
- ${(0, HoverStyles_1.getHoverStyles)(['angle'], hoverParams)};
38
- }
39
37
  `);
40
38
  })}` })] }));
41
39
  };
@@ -9,38 +9,41 @@ const react_1 = require("react");
9
9
  const Item_1 = require("../Item");
10
10
  const style_1 = __importDefault(require("styled-jsx/style"));
11
11
  const sdk_1 = require("@cntrl-site/sdk");
12
- const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
13
12
  const LinkWrapper_1 = require("../LinkWrapper");
14
13
  const useRegisterResize_1 = require("../../common/useRegisterResize");
15
14
  const useCntrlContext_1 = require("../../provider/useCntrlContext");
16
15
  const useItemAngle_1 = require("../useItemAngle");
17
16
  const useGroupItem_1 = require("./useGroupItem");
18
- const GroupItem = ({ item, sectionId, onResize, articleHeight }) => {
19
- var _a, _b;
17
+ const getStyleFromItemStateAndParams_1 = require("../../utils/getStyleFromItemStateAndParams");
18
+ const GroupItem = ({ item, sectionId, onResize, articleHeight, interactionCtrl, onVisibilityChange }) => {
19
+ var _a, _b, _c, _d, _e;
20
20
  const id = (0, react_1.useId)();
21
21
  const { items } = item;
22
- const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
22
+ const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
23
23
  const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
24
- const { opacity } = (0, useGroupItem_1.useGroupItem)(item, sectionId);
25
- const layoutValues = [item.area, item.layoutParams, item.state.hover];
24
+ const { opacity: itemOpacity } = (0, useGroupItem_1.useGroupItem)(item, sectionId);
25
+ const layoutValues = [item.area, item.layoutParams];
26
26
  const [ref, setRef] = (0, react_1.useState)(null);
27
27
  (0, useRegisterResize_1.useRegisterResize)(ref, onResize);
28
- return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: (_a = item.link) === null || _a === void 0 ? void 0 : _a.url, target: (_b = item.link) === null || _b === void 0 ? void 0 : _b.target, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `group-${item.id}`, ref: setRef, style: Object.assign(Object.assign({}, (opacity !== undefined ? { opacity } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), children: items && items.map(item => ((0, jsx_runtime_1.jsx)(Item_1.Item, { item: item, sectionId: sectionId, articleHeight: articleHeight, isInGroup: true }, item.id))) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
28
+ const stateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['opacity', 'angle']);
29
+ const angle = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_a = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) === null || _a === void 0 ? void 0 : _a.angle, itemAngle);
30
+ const opacity = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_b = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) === null || _b === void 0 ? void 0 : _b.opacity, itemOpacity);
31
+ const isInteractive = opacity !== 0 && opacity !== undefined;
32
+ (0, react_1.useEffect)(() => {
33
+ onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(isInteractive);
34
+ }, [isInteractive, onVisibilityChange]);
35
+ return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: (_c = item.link) === null || _c === void 0 ? void 0 : _c.url, target: (_d = item.link) === null || _d === void 0 ? void 0 : _d.target, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `group-${item.id}`, ref: setRef, style: Object.assign(Object.assign(Object.assign({}, (opacity !== undefined ? { opacity } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), { transition: (_e = stateParams === null || stateParams === void 0 ? void 0 : stateParams.transition) !== null && _e !== void 0 ? _e : 'none' }), children: items && items.map(item => ((0, jsx_runtime_1.jsx)(Item_1.Item, { item: item, sectionId: sectionId, articleHeight: articleHeight, isParentVisible: isInteractive, isInGroup: true }, item.id))) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
29
36
  .group-${item.id} {
30
37
  position: absolute;
31
38
  width: 100%;
32
39
  height: 100%;
33
40
  box-sizing: border-box;
34
41
  }
35
- ${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams, hoverParams]) => {
42
+ ${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams]) => {
36
43
  return (`
37
44
  .group-${item.id} {
38
45
  opacity: ${layoutParams.opacity};
39
46
  transform: rotate(${area.angle}deg);
40
- transition: ${(0, HoverStyles_1.getTransitions)(['opacity', 'angle'], hoverParams)};
41
- }
42
- .group-${item.id}:hover {
43
- ${(0, HoverStyles_1.getHoverStyles)(['opacity', 'angle'], hoverParams)};
44
47
  }
45
48
  `);
46
49
  })}
@@ -13,11 +13,11 @@ const LinkWrapper_1 = require("../LinkWrapper");
13
13
  const useFileItem_1 = require("./useFileItem");
14
14
  const useItemAngle_1 = require("../useItemAngle");
15
15
  const useCntrlContext_1 = require("../../provider/useCntrlContext");
16
- const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
17
16
  const useRegisterResize_1 = require("../../common/useRegisterResize");
18
17
  const useImageFx_1 = require("../../utils/effects/useImageFx");
19
18
  const useElementRect_1 = require("../../utils/useElementRect");
20
19
  const useLayoutContext_1 = require("../useLayoutContext");
20
+ const getStyleFromItemStateAndParams_1 = require("../../utils/getStyleFromItemStateAndParams");
21
21
  const baseVariables = `precision mediump float;
22
22
  uniform sampler2D u_image;
23
23
  uniform sampler2D u_pattern;
@@ -26,16 +26,15 @@ uniform vec2 u_patternDimensions;
26
26
  uniform float u_time;
27
27
  uniform vec2 u_cursor;
28
28
  varying vec2 v_texCoord;`;
29
- const ImageItem = ({ item, sectionId, onResize }) => {
30
- var _a, _b, _c, _d, _e;
29
+ const ImageItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
30
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
31
31
  const id = (0, react_1.useId)();
32
32
  const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
33
33
  const layoutId = (0, useLayoutContext_1.useLayoutContext)();
34
- const { radius, strokeWidth, opacity, strokeColor, blur } = (0, useFileItem_1.useFileItem)(item, sectionId);
35
- const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
36
- const borderColor = (0, react_1.useMemo)(() => strokeColor ? color_1.CntrlColor.parse(strokeColor) : undefined, [strokeColor]);
37
- const [ref, setRef] = (0, react_1.useState)(null);
38
- (0, useRegisterResize_1.useRegisterResize)(ref, onResize);
34
+ const { radius: itemRadius, strokeWidth: itemStrokeWidth, opacity: itemOpacity, strokeColor: itemStrokeColor, blur: itemBlur } = (0, useFileItem_1.useFileItem)(item, sectionId);
35
+ const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
36
+ const [wrapperRef, setWrapperRef] = (0, react_1.useState)(null);
37
+ (0, useRegisterResize_1.useRegisterResize)(wrapperRef, onResize);
39
38
  const { url, hasGLEffect, fragmentShader, FXControls, FXCursor } = item.commonParams;
40
39
  const fxCanvas = (0, react_1.useRef)(null);
41
40
  const isInitialRef = (0, react_1.useRef)(true);
@@ -46,12 +45,14 @@ const ImageItem = ({ item, sectionId, onResize }) => {
46
45
  acc[control.shaderParam] = control.value;
47
46
  return acc;
48
47
  }, {});
49
- const layoutValues = [item.area, item.layoutParams, item.state.hover];
48
+ const layoutValues = [item.area, item.layoutParams];
50
49
  const fullShaderCode = `${baseVariables}\n${controlsVariables}\n${fragmentShader}`;
51
50
  const area = layoutId ? item.area[layoutId] : null;
52
51
  const exemplary = (_a = layouts === null || layouts === void 0 ? void 0 : layouts.find(l => l.id === layoutId)) === null || _a === void 0 ? void 0 : _a.exemplary;
53
52
  const width = area && exemplary ? area.width * exemplary : 0;
54
53
  const height = area && exemplary ? area.height * exemplary : 0;
54
+ const wrapperStateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['angle', 'opacity', 'blur']);
55
+ const imgStateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['strokeWidth', 'radius', 'strokeColor']);
55
56
  (0, react_1.useEffect)(() => {
56
57
  isInitialRef.current = false;
57
58
  }, []);
@@ -61,11 +62,25 @@ const ImageItem = ({ item, sectionId, onResize }) => {
61
62
  cursor: FXCursor,
62
63
  controls: controlValues
63
64
  }, width, height);
64
- const rect = (0, useElementRect_1.useElementRect)(ref);
65
+ const rect = (0, useElementRect_1.useElementRect)(wrapperRef);
65
66
  const rectWidth = Math.floor((_b = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _b !== void 0 ? _b : 0);
66
67
  const rectHeight = Math.floor((_c = rect === null || rect === void 0 ? void 0 : rect.height) !== null && _c !== void 0 ? _c : 0);
67
- const inlineStyles = Object.assign(Object.assign(Object.assign({}, (borderColor ? { borderColor: `${borderColor.fmt('rgba')}` } : {})), (radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {})), (strokeWidth !== undefined ? { borderWidth: `${strokeWidth * 100}vw` } : {}));
68
- return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: (_d = item.link) === null || _d === void 0 ? void 0 : _d.url, target: (_e = item.link) === null || _e === void 0 ? void 0 : _e.target, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `image-wrapper-${item.id}`, ref: setRef, style: Object.assign(Object.assign(Object.assign({}, (opacity !== undefined ? { opacity } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), children: hasGLEffect && isFXAllowed ? ((0, jsx_runtime_1.jsx)("canvas", { style: inlineStyles, ref: fxCanvas, className: `img-canvas image-${item.id}`, width: rectWidth, height: rectHeight })) : ((0, jsx_runtime_1.jsx)("img", { alt: "", className: `image image-${item.id}`, style: inlineStyles, src: item.commonParams.url })) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
68
+ const borderColor = (0, react_1.useMemo)(() => {
69
+ var _a;
70
+ const borderColor = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_a = imgStateParams === null || imgStateParams === void 0 ? void 0 : imgStateParams.styles) === null || _a === void 0 ? void 0 : _a.strokeColor, itemStrokeColor);
71
+ return borderColor ? color_1.CntrlColor.parse(borderColor) : undefined;
72
+ }, [itemStrokeColor, (_d = imgStateParams === null || imgStateParams === void 0 ? void 0 : imgStateParams.styles) === null || _d === void 0 ? void 0 : _d.strokeColor]);
73
+ const radius = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_e = imgStateParams === null || imgStateParams === void 0 ? void 0 : imgStateParams.styles) === null || _e === void 0 ? void 0 : _e.radius, itemRadius);
74
+ const strokeWidth = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_f = imgStateParams === null || imgStateParams === void 0 ? void 0 : imgStateParams.styles) === null || _f === void 0 ? void 0 : _f.strokeWidth, itemStrokeWidth);
75
+ const angle = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_g = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _g === void 0 ? void 0 : _g.angle, itemAngle);
76
+ const opacity = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_h = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _h === void 0 ? void 0 : _h.opacity, itemOpacity);
77
+ const blur = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_j = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _j === void 0 ? void 0 : _j.blur, itemBlur);
78
+ const inlineStyles = Object.assign(Object.assign(Object.assign(Object.assign({}, (borderColor ? { borderColor: `${borderColor.fmt('rgba')}` } : {})), (radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {})), (strokeWidth !== undefined ? { borderWidth: `${strokeWidth * 100}vw` } : {})), { transition: (_k = imgStateParams === null || imgStateParams === void 0 ? void 0 : imgStateParams.transition) !== null && _k !== void 0 ? _k : 'none' });
79
+ const isInteractive = opacity !== 0;
80
+ (0, react_1.useEffect)(() => {
81
+ onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(isInteractive);
82
+ }, [isInteractive, onVisibilityChange]);
83
+ return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: (_l = item.link) === null || _l === void 0 ? void 0 : _l.url, target: (_m = item.link) === null || _m === void 0 ? void 0 : _m.target, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `image-wrapper-${item.id}`, ref: setWrapperRef, style: Object.assign(Object.assign(Object.assign(Object.assign({}, (opacity !== undefined ? { opacity } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), { transition: (_o = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.transition) !== null && _o !== void 0 ? _o : 'none' }), children: hasGLEffect && isFXAllowed ? ((0, jsx_runtime_1.jsx)("canvas", { style: inlineStyles, ref: fxCanvas, className: `img-canvas image-${item.id}`, width: rectWidth, height: rectHeight })) : ((0, jsx_runtime_1.jsx)("img", { alt: "", className: `image image-${item.id}`, style: inlineStyles, src: item.commonParams.url })) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
69
84
  .image-wrapper-${item.id} {
70
85
  position: absolute;
71
86
  width: 100%;
@@ -91,25 +106,17 @@ const ImageItem = ({ item, sectionId, onResize }) => {
91
106
  border-width: 0;
92
107
  box-sizing: border-box;
93
108
  }
94
- ${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams, hoverParams]) => {
109
+ ${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams]) => {
95
110
  return (`
96
111
  .image-wrapper-${item.id} {
97
112
  opacity: ${layoutParams.opacity};
98
113
  transform: rotate(${area.angle}deg);
99
114
  filter: ${layoutParams.blur !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
100
- transition: ${(0, HoverStyles_1.getTransitions)(['angle', 'opacity', 'blur'], hoverParams)};
101
- }
102
- .image-wrapper-${item.id}:hover {
103
- ${(0, HoverStyles_1.getHoverStyles)(['angle', 'opacity', 'blur'], hoverParams)};
104
115
  }
105
116
  .image-${item.id} {
106
117
  border-color: ${color_1.CntrlColor.parse(layoutParams.strokeColor).fmt('rgba')};
107
118
  border-radius: ${layoutParams.radius * 100}vw;
108
119
  border-width: ${layoutParams.strokeWidth * 100}vw;
109
- transition: ${(0, HoverStyles_1.getTransitions)(['strokeWidth', 'radius', 'strokeColor'], hoverParams)};
110
- }
111
- .image-wrapper-${item.id}:hover .image, .image-wrapper-${item.id}:hover .img-canvas {
112
- ${(0, HoverStyles_1.getHoverStyles)(['strokeWidth', 'radius', 'strokeColor'], hoverParams)};
113
120
  }
114
121
  `);
115
122
  })}
@@ -13,23 +13,40 @@ const LinkWrapper_1 = require("../LinkWrapper");
13
13
  const useRectangleItem_1 = require("./useRectangleItem");
14
14
  const useItemAngle_1 = require("../useItemAngle");
15
15
  const useCntrlContext_1 = require("../../provider/useCntrlContext");
16
- const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
17
16
  const useRegisterResize_1 = require("../../common/useRegisterResize");
18
- const RectangleItem = ({ item, sectionId, onResize }) => {
19
- var _a, _b;
17
+ const getStyleFromItemStateAndParams_1 = require("../../utils/getStyleFromItemStateAndParams");
18
+ const RectangleItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
19
+ var _a, _b, _c, _d;
20
20
  const id = (0, react_1.useId)();
21
21
  const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
22
- const { fillColor, radius, strokeWidth, strokeColor, blur, backdropBlur } = (0, useRectangleItem_1.useRectangleItem)(item, sectionId);
23
- const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
24
- const backgroundColor = (0, react_1.useMemo)(() => fillColor ? color_1.CntrlColor.parse(fillColor) : undefined, [fillColor]);
25
- const borderColor = (0, react_1.useMemo)(() => strokeColor ? color_1.CntrlColor.parse(strokeColor) : undefined, [strokeColor]);
26
- const layoutValues = [item.area, item.layoutParams, item.state.hover];
22
+ const { fillColor: itemFillColor, radius: itemRadius, strokeWidth: itemStrokeWidth, strokeColor: itemStrokeColor, blur: itemBlur, backdropBlur: itemBackdropBlur } = (0, useRectangleItem_1.useRectangleItem)(item, sectionId);
23
+ const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
24
+ const stateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['angle', 'fillColor', 'strokeWidth', 'radius', 'strokeColor', 'blur', 'backdropBlur']);
25
+ const styles = (_a = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) !== null && _a !== void 0 ? _a : {};
26
+ const backgroundColor = (0, react_1.useMemo)(() => {
27
+ const fillColor = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(styles === null || styles === void 0 ? void 0 : styles.fillColor, itemFillColor);
28
+ return fillColor ? color_1.CntrlColor.parse(fillColor) : undefined;
29
+ }, [itemFillColor, styles === null || styles === void 0 ? void 0 : styles.fillColor]);
30
+ const borderColor = (0, react_1.useMemo)(() => {
31
+ const strokeColor = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(styles === null || styles === void 0 ? void 0 : styles.strokeColor, itemStrokeColor);
32
+ return strokeColor ? color_1.CntrlColor.parse(strokeColor) : undefined;
33
+ }, [itemStrokeColor, styles === null || styles === void 0 ? void 0 : styles.strokeColor]);
34
+ const layoutValues = [item.area, item.layoutParams];
27
35
  const [ref, setRef] = (0, react_1.useState)(null);
28
36
  (0, useRegisterResize_1.useRegisterResize)(ref, onResize);
37
+ const backdropBlur = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(styles === null || styles === void 0 ? void 0 : styles.backdropBlur, itemBackdropBlur);
38
+ const radius = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(styles === null || styles === void 0 ? void 0 : styles.radius, itemRadius);
39
+ const strokeWidth = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(styles === null || styles === void 0 ? void 0 : styles.strokeWidth, itemStrokeWidth);
40
+ const angle = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(styles === null || styles === void 0 ? void 0 : styles.angle, itemAngle);
41
+ const blur = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(styles === null || styles === void 0 ? void 0 : styles.blur, itemBlur);
29
42
  const backdropFilterValue = backdropBlur ? `blur(${backdropBlur * 100}vw)` : undefined;
30
- return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: (_a = item.link) === null || _a === void 0 ? void 0 : _a.url, target: (_b = item.link) === null || _b === void 0 ? void 0 : _b.target, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `rectangle-${item.id}`, ref: setRef, style: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (backgroundColor ? { backgroundColor: `${backgroundColor.fmt('rgba')}` } : {})), (borderColor ? { borderColor: `${borderColor.fmt('rgba')}` } : {})), (radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {})), (strokeWidth !== undefined ? { borderWidth: `${strokeWidth * 100}vw` } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), (backdropFilterValue !== undefined
43
+ const isInteractive = (backgroundColor === null || backgroundColor === void 0 ? void 0 : backgroundColor.getAlpha()) !== 0 || (strokeWidth !== 0 && (borderColor === null || borderColor === void 0 ? void 0 : borderColor.getAlpha()) !== 0);
44
+ (0, react_1.useEffect)(() => {
45
+ onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(isInteractive);
46
+ }, [isInteractive, onVisibilityChange]);
47
+ return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: (_b = item.link) === null || _b === void 0 ? void 0 : _b.url, target: (_c = item.link) === null || _c === void 0 ? void 0 : _c.target, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `rectangle-${item.id}`, ref: setRef, style: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (backgroundColor ? { backgroundColor: `${backgroundColor.fmt('rgba')}` } : {})), (borderColor ? { borderColor: `${borderColor.fmt('rgba')}` } : {})), (radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {})), (strokeWidth !== undefined ? { borderWidth: `${strokeWidth * 100}vw` } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), (backdropFilterValue !== undefined
31
48
  ? { backdropFilter: backdropFilterValue, WebkitBackdropFilter: backdropFilterValue }
32
- : {})) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
49
+ : {})), { transition: (_d = stateParams === null || stateParams === void 0 ? void 0 : stateParams.transition) !== null && _d !== void 0 ? _d : 'none' }) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
33
50
  .rectangle-${item.id} {
34
51
  position: absolute;
35
52
  width: 100%;
@@ -37,7 +54,7 @@ const RectangleItem = ({ item, sectionId, onResize }) => {
37
54
  border-style: solid;
38
55
  box-sizing: border-box;
39
56
  }
40
- ${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams, hoverParams]) => {
57
+ ${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams]) => {
41
58
  return (`
42
59
  .rectangle-${item.id} {
43
60
  background-color: ${color_1.CntrlColor.parse(layoutParams.fillColor).fmt('rgba')};
@@ -48,10 +65,6 @@ const RectangleItem = ({ item, sectionId, onResize }) => {
48
65
  filter: ${layoutParams.blur !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
49
66
  backdrop-filter: ${layoutParams.backdropFilter !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
50
67
  -webkit-backdrop-filter: ${layoutParams.backdropFilter !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
51
- transition: ${(0, HoverStyles_1.getTransitions)(['angle', 'fillColor', 'strokeWidth', 'radius', 'strokeColor', 'blur', 'backdropBlur'], hoverParams)};
52
- }
53
- .rectangle-${item.id}:hover {
54
- ${(0, HoverStyles_1.getHoverStyles)(['angle', 'fillColor', 'strokeWidth', 'radius', 'strokeColor', 'blur', 'backdropBlur'], hoverParams)};
55
68
  }
56
69
  `);
57
70
  })}
@@ -11,24 +11,49 @@ const sdk_1 = require("@cntrl-site/sdk");
11
11
  const style_1 = __importDefault(require("styled-jsx/style"));
12
12
  const useRichTextItem_1 = require("./useRichTextItem");
13
13
  const useCntrlContext_1 = require("../../provider/useCntrlContext");
14
- const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
15
14
  const useRichTextItemValues_1 = require("./useRichTextItemValues");
16
15
  const useRegisterResize_1 = require("../../common/useRegisterResize");
17
16
  const getFontFamilyValue_1 = require("../../utils/getFontFamilyValue");
18
17
  const useExemplary_1 = require("../../common/useExemplary");
19
18
  const useItemAngle_1 = require("../useItemAngle");
20
- const RichTextItem = ({ item, sectionId, onResize }) => {
21
- const [content, styles] = (0, useRichTextItem_1.useRichTextItem)(item);
19
+ const getStyleFromItemStateAndParams_1 = require("../../utils/getStyleFromItemStateAndParams");
20
+ const useCurrentLayout_1 = require("../../common/useCurrentLayout");
21
+ const RichTextItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
22
+ var _a, _b, _c, _d;
22
23
  const id = (0, react_1.useId)();
23
24
  const [ref, setRef] = (0, react_1.useState)(null);
24
25
  const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
25
- const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
26
- const { blur, wordSpacing, letterSpacing, color, fontSize, lineHeight } = (0, useRichTextItemValues_1.useRichTextItemValues)(item, sectionId);
27
- const textColor = (0, react_1.useMemo)(() => color ? color_1.CntrlColor.parse(color) : undefined, [color]);
28
- const layoutValues = [item.area, item.layoutParams, item.state.hover];
26
+ const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
27
+ const { blur: itemBlur, wordSpacing: itemWordSpacing, letterSpacing: itemLetterSpacing, color: itemColor, fontSize, lineHeight } = (0, useRichTextItemValues_1.useRichTextItemValues)(item, sectionId);
28
+ const layoutValues = [item.area, item.layoutParams];
29
29
  const exemplary = (0, useExemplary_1.useExemplary)();
30
+ const { layoutId } = (0, useCurrentLayout_1.useCurrentLayout)();
30
31
  (0, useRegisterResize_1.useRegisterResize)(ref, onResize);
31
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { ref: setRef, className: `rich-text-wrapper-${item.id}`, style: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), (textColor ? { color: `${textColor.fmt('rgba')}` } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (letterSpacing !== undefined ? { letterSpacing: `${letterSpacing * exemplary}px` } : {})), (wordSpacing !== undefined ? { wordSpacing: `${wordSpacing * exemplary}px` } : {})), (fontSize !== undefined ? { fontSize: `${Math.round(fontSize * exemplary)}px` } : {})), (lineHeight !== undefined ? { lineHeight: `${lineHeight * exemplary}px` } : {})), children: content }), (0, jsx_runtime_1.jsxs)(style_1.default, { id: id, children: [styles, `${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams, hoverParams]) => {
32
+ const stateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['angle', 'blur', 'letterSpacing', 'wordSpacing', 'color']);
33
+ const stateStyles = (_a = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) !== null && _a !== void 0 ? _a : {};
34
+ const transition = (_b = stateParams === null || stateParams === void 0 ? void 0 : stateParams.transition) !== null && _b !== void 0 ? _b : 'none';
35
+ const textColor = (0, react_1.useMemo)(() => {
36
+ var _a;
37
+ const color = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_a = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) === null || _a === void 0 ? void 0 : _a.color, itemColor);
38
+ return color ? color_1.CntrlColor.parse(color) : undefined;
39
+ }, [itemColor, stateStyles.color]);
40
+ const angle = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(stateStyles.angle, itemAngle);
41
+ const blur = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(stateStyles.blur, itemBlur);
42
+ const letterSpacing = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(stateStyles.letterSpacing, itemLetterSpacing);
43
+ const wordSpacing = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(stateStyles.wordSpacing, itemWordSpacing);
44
+ const colorAlpha = textColor === null || textColor === void 0 ? void 0 : textColor.getAlpha();
45
+ const rangeStyles = layoutId ? (_d = (_c = item.layoutParams[layoutId]) === null || _c === void 0 ? void 0 : _c.rangeStyles) !== null && _d !== void 0 ? _d : [] : [];
46
+ const rangeColors = rangeStyles.filter((style) => style.style === 'COLOR');
47
+ const hasVisibleRangeColors = rangeColors.some((color) => {
48
+ const alpha = color_1.CntrlColor.parse(color.value).getAlpha();
49
+ return alpha > 0;
50
+ });
51
+ const isInteractive = colorAlpha !== 0 || hasVisibleRangeColors;
52
+ const [content, styles] = (0, useRichTextItem_1.useRichTextItem)(item);
53
+ (0, react_1.useEffect)(() => {
54
+ onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(isInteractive);
55
+ }, [isInteractive, onVisibilityChange]);
56
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { ref: setRef, className: `rich-text-wrapper-${item.id}`, style: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), (textColor ? { color: `${textColor.fmt('rgba')}` } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (letterSpacing !== undefined ? { letterSpacing: `${letterSpacing * exemplary}px` } : {})), (wordSpacing !== undefined ? { wordSpacing: `${wordSpacing * exemplary}px` } : {})), (fontSize !== undefined ? { fontSize: `${Math.round(fontSize * exemplary)}px` } : {})), (lineHeight !== undefined ? { lineHeight: `${lineHeight * exemplary}px` } : {})), { transition }), children: content }), (0, jsx_runtime_1.jsxs)(style_1.default, { id: id, children: [styles, `${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams]) => {
32
57
  const color = color_1.CntrlColor.parse(layoutParams.color);
33
58
  return (`
34
59
  .rich-text-wrapper-${item.id} {
@@ -45,10 +70,6 @@ const RichTextItem = ({ item, sectionId, onResize }) => {
45
70
  transform: rotate(${area.angle}deg);
46
71
  filter: ${layoutParams.blur !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
47
72
  text-transform: ${layoutParams.textTransform};
48
- transition: ${(0, HoverStyles_1.getTransitions)(['angle', 'blur', 'letterSpacing', 'wordSpacing', 'color'], hoverParams)};
49
- }
50
- .rich-text-wrapper-${item.id}:hover {
51
- ${(0, HoverStyles_1.getHoverStyles)(['angle', 'blur', 'letterSpacing', 'wordSpacing', 'color'], hoverParams)};
52
73
  }
53
74
  @supports not (color: oklch(42% 0.3 90 / 1)) {
54
75
  .rich-text-wrapper-${item.id} {