@cntrl-site/sdk-nextjs 0.15.5-2 → 0.15.5-3

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.
@@ -35,6 +35,11 @@ const itemsMap = {
35
35
  [sdk_1.ArticleItemType.VimeoEmbed]: VimeoEmbed_1.VimeoEmbedItem,
36
36
  [sdk_1.ArticleItemType.Custom]: CustomItem_1.CustomItem
37
37
  };
38
+ const RichTextWrapper = ({ isRichText, children }) => {
39
+ if (!isRichText)
40
+ return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
41
+ return ((0, jsx_runtime_1.jsx)("div", Object.assign({ style: { transformOrigin: 'top left', transform: 'scale(var(--layout-deviation))' } }, { children: children })));
42
+ };
38
43
  const noop = () => null;
39
44
  const Item = ({ item, sectionId }) => {
40
45
  var _a, _b;
@@ -43,6 +48,7 @@ const Item = ({ item, sectionId }) => {
43
48
  const layout = (0, useLayoutContext_1.useLayoutContext)();
44
49
  const exemplary = (_b = (_a = layouts.find(l => l.id === layout)) === null || _a === void 0 ? void 0 : _a.exemplary) !== null && _b !== void 0 ? _b : 1;
45
50
  const [wrapperHeight, setWrapperHeight] = (0, react_1.useState)(undefined);
51
+ const [itemHeight, setItemHeight] = (0, react_1.useState)(undefined);
46
52
  const { scale, scaleAnchor } = (0, useItemScale_1.useItemScale)(item, sectionId);
47
53
  const { top, left } = (0, useItemPosition_1.useItemPosition)(item, sectionId);
48
54
  const sectionHeight = (0, useSectionHeightMap_1.useSectionHeightData)(sectionId);
@@ -69,43 +75,45 @@ const Item = ({ item, sectionId }) => {
69
75
  return;
70
76
  }
71
77
  const wrapperHeight = getStickyItemWrapperHeight(sticky, height);
78
+ setItemHeight(height);
72
79
  setWrapperHeight(wrapperHeight);
73
80
  };
74
81
  (0, react_1.useEffect)(() => {
75
82
  isInitialRef.current = false;
76
83
  }, []);
77
84
  const isRichText = isItemType(item, sdk_1.ArticleItemType.RichText);
78
- const scaleIfRichText = isRichText
79
- ? { transformOrigin: 'top left', transform: 'scale(var(--layout-deviation))' }
80
- : {};
81
- const styles = Object.assign(Object.assign({}, scaleIfRichText), { top: stickyTop });
82
- return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: `item-wrapper-${item.id}`, style: isInitialRef.current ? {} : Object.assign({ top, left }, (wrapperHeight ? { height: `${wrapperHeight * 100}vw` } : {})) }, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ suppressHydrationWarning: true, className: `item-${item.id}`, style: isInitialRef.current ? {} : styles }, { children: (0, jsx_runtime_1.jsx)("div", Object.assign({ className: `item-${item.id}-inner`, style: {
83
- width: `${sizingAxis.x === sdk_1.ArticleItemSizingType.Manual
84
- ? isRichText
85
- ? `${width * exemplary}px`
86
- : `${width * 100}vw`
87
- : 'max-content'}`,
88
- height: `${sizingAxis.y === sdk_1.ArticleItemSizingType.Manual ? `${height * 100}vw` : 'unset'}`,
89
- transform: `scale(${scale})`,
90
- transformOrigin: ScaleAnchorMap_1.ScaleAnchorMap[scaleAnchor]
91
- } }, { children: (0, jsx_runtime_1.jsx)(ItemComponent, { item: item, sectionId: sectionId, onResize: handleItemResize }) })) })), (0, jsx_runtime_1.jsx)(style_1.default, Object.assign({ id: id }, { children: `
85
+ const styles = {
86
+ top: stickyTop,
87
+ height: isRichText && itemHeight ? `${itemHeight * 100}vw` : 'unset'
88
+ };
89
+ return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: `item-wrapper-${item.id}`, style: isInitialRef.current ? {} : Object.assign({ top, left }, (wrapperHeight ? { height: `${wrapperHeight * 100}vw` } : {})) }, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ suppressHydrationWarning: true, className: `item-${item.id}`, style: isInitialRef.current ? {} : styles }, { children: (0, jsx_runtime_1.jsx)(RichTextWrapper, Object.assign({ isRichText: isRichText }, { children: (0, jsx_runtime_1.jsx)("div", Object.assign({ className: `item-${item.id}-inner`, style: {
90
+ width: `${sizingAxis.x === sdk_1.ArticleItemSizingType.Manual
91
+ ? isRichText
92
+ ? `${width * exemplary}px`
93
+ : `${width * 100}vw`
94
+ : 'max-content'}`,
95
+ height: `${sizingAxis.y === sdk_1.ArticleItemSizingType.Manual ? `${height * 100}vw` : 'unset'}`,
96
+ transform: `scale(${scale})`,
97
+ transformOrigin: ScaleAnchorMap_1.ScaleAnchorMap[scaleAnchor]
98
+ } }, { children: (0, jsx_runtime_1.jsx)(ItemComponent, { item: item, sectionId: sectionId, onResize: handleItemResize }) })) })) })), (0, jsx_runtime_1.jsx)(style_1.default, Object.assign({ id: id }, { children: `
92
99
  ${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, hidden, hoverParams, sticky, sectionHeight, layoutParams]) => {
93
100
  const sizingAxis = parseSizing(layoutParams.sizing);
94
101
  return (`
95
102
  .item-${item.id} {
96
103
  position: ${sticky ? 'sticky' : 'absolute'};
97
- width: ${sizingAxis.x === sdk_1.ArticleItemSizingType.Manual ? `${area.width * 100}vw` : 'max-content'};
98
- height: ${sizingAxis.y === sdk_1.ArticleItemSizingType.Manual ? `${area.height * 100}vw` : 'unset'};
99
- transform: scale(${scale});
100
104
  top: ${sticky ? `${(0, getAnchoredItemTop_1.getAnchoredItemTop)(area.top - sticky.from, sectionHeight, area.anchorSide)}` : 0};
101
- transform-origin: ${ScaleAnchorMap_1.ScaleAnchorMap[scaleAnchor]};
102
105
  pointer-events: auto;
103
- --webkit-backface-visibility: hidden;
104
106
  cursor: ${hoverParams ? 'pointer' : 'default'};
105
107
  visibility: ${hidden ? 'hidden' : 'visible'};
108
+ height: fit-content;
106
109
  }
107
110
  .item-${item.id}-inner {
108
111
  transition: ${(0, HoverStyles_1.getTransitions)(['width', 'height', 'scale'], hoverParams)};
112
+ width: ${sizingAxis.x === sdk_1.ArticleItemSizingType.Manual ? `${area.width * 100}vw` : 'max-content'};
113
+ height: ${sizingAxis.y === sdk_1.ArticleItemSizingType.Manual ? `${area.height * 100}vw` : 'unset'};
114
+ transform: scale(${scale});
115
+ transform-origin: ${ScaleAnchorMap_1.ScaleAnchorMap[scaleAnchor]};
116
+ --webkit-backface-visibility: hidden;
109
117
  }
110
118
  .item-wrapper-${item.id} {
111
119
  position: absolute;
@@ -14,11 +14,10 @@ const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
14
14
  const useRichTextItemValues_1 = require("./useRichTextItemValues");
15
15
  const resize_observer_polyfill_1 = __importDefault(require("resize-observer-polyfill"));
16
16
  const RichTextItem = ({ item, sectionId, onResize }) => {
17
- const [content, styles, preset] = (0, useRichTextItem_1.useRichTextItem)(item);
17
+ const [content, styles] = (0, useRichTextItem_1.useRichTextItem)(item);
18
18
  const id = (0, react_1.useId)();
19
19
  const [ref, setRef] = (0, react_1.useState)(null);
20
20
  const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
21
- const className = preset ? `cntrl-preset-${preset.id}` : undefined;
22
21
  const { angle, blur } = (0, useRichTextItemValues_1.useRichTextItemValues)(item, sectionId);
23
22
  (0, react_1.useEffect)(() => {
24
23
  if (!ref || !onResize)
@@ -32,7 +31,7 @@ const RichTextItem = ({ item, sectionId, onResize }) => {
32
31
  observer.unobserve(ref);
33
32
  };
34
33
  }, [ref, onResize]);
35
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ ref: setRef, className: `${className} rich-text-wrapper-${item.id}`, style: {
34
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ ref: setRef, className: `rich-text-wrapper-${item.id}`, style: {
36
35
  transform: `rotate(${angle}deg)`,
37
36
  filter: `blur(${blur * 100}vw)`
38
37
  } }, { children: content })), (0, jsx_runtime_1.jsxs)(style_1.default, Object.assign({ id: id }, { children: [styles, `${(0, sdk_1.getLayoutStyles)(layouts, [item.state.hover], ([hoverParams]) => {
@@ -5,7 +5,7 @@ const useKeyframeValue_1 = require("../../common/useKeyframeValue");
5
5
  const useLayoutContext_1 = require("../useLayoutContext");
6
6
  const useRichTextItemValues = (item, sectionId) => {
7
7
  const layoutId = (0, useLayoutContext_1.useLayoutContext)();
8
- const angle = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => ({ angle: layoutId ? item.area[layoutId].angle : 0 }), (animator, scroll, value) => animator.getRotation(value, scroll), sectionId);
8
+ const { angle } = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => ({ angle: layoutId ? item.area[layoutId].angle : 0 }), (animator, scroll, value) => animator.getRotation(value, scroll), sectionId);
9
9
  const blur = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => {
10
10
  if (!layoutId)
11
11
  return 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "0.15.5-2",
3
+ "version": "0.15.5-3",
4
4
  "description": "SDK for Next.js",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/index.ts",
@@ -1,4 +1,4 @@
1
- import { ComponentType, FC, useEffect, useId, useRef, useState } from 'react';
1
+ import { ComponentType, FC, PropsWithChildren, useEffect, useId, useRef, useState } from 'react';
2
2
  import JSXStyle from 'styled-jsx/style';
3
3
  import {
4
4
  AnchorSide,
@@ -45,6 +45,19 @@ const itemsMap: Record<ArticleItemType, ComponentType<ItemProps<any>>> = {
45
45
  [ArticleItemType.Custom]: CustomItem
46
46
  };
47
47
 
48
+ interface RTWrapperProps {
49
+ isRichText: boolean;
50
+ }
51
+
52
+ const RichTextWrapper: FC<PropsWithChildren<RTWrapperProps>> = ({ isRichText, children }) => {
53
+ if (!isRichText) return <>{children}</>;
54
+ return (
55
+ <div style={{ transformOrigin: 'top left', transform: 'scale(var(--layout-deviation))' }}>
56
+ {children}
57
+ </div>
58
+ );
59
+ };
60
+
48
61
  const noop = () => null;
49
62
 
50
63
  export const Item: FC<ItemProps<TArticleItemAny>> = ({ item, sectionId}) => {
@@ -53,6 +66,7 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item, sectionId}) => {
53
66
  const layout = useLayoutContext();
54
67
  const exemplary = layouts.find(l => l.id === layout)?.exemplary ?? 1;
55
68
  const [wrapperHeight, setWrapperHeight] = useState<undefined | number>(undefined);
69
+ const [itemHeight, setItemHeight] = useState<undefined | number>(undefined);
56
70
  const { scale, scaleAnchor } = useItemScale(item, sectionId);
57
71
  const { top, left } = useItemPosition(item, sectionId);
58
72
  const sectionHeight = useSectionHeightData(sectionId);
@@ -79,7 +93,8 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item, sectionId}) => {
79
93
  setWrapperHeight(undefined);
80
94
  return;
81
95
  }
82
- const wrapperHeight = getStickyItemWrapperHeight(sticky, height)
96
+ const wrapperHeight = getStickyItemWrapperHeight(sticky, height);
97
+ setItemHeight(height);
83
98
  setWrapperHeight(wrapperHeight);
84
99
  };
85
100
 
@@ -88,13 +103,10 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item, sectionId}) => {
88
103
  }, []);
89
104
 
90
105
  const isRichText = isItemType(item, ArticleItemType.RichText);
91
- const scaleIfRichText = isRichText
92
- ? { transformOrigin: 'top left', transform: 'scale(var(--layout-deviation))' }
93
- : {};
94
106
 
95
107
  const styles = {
96
- ...scaleIfRichText,
97
- top: stickyTop
108
+ top: stickyTop,
109
+ height: isRichText && itemHeight ? `${itemHeight * 100}vw` : 'unset'
98
110
  };
99
111
 
100
112
  return (
@@ -107,21 +119,23 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item, sectionId}) => {
107
119
  className={`item-${item.id}`}
108
120
  style={isInitialRef.current ? {} : styles }
109
121
  >
110
- <div
111
- className={`item-${item.id}-inner`}
112
- style={{
113
- width: `${sizingAxis.x === SizingType.Manual
114
- ? isRichText
115
- ? `${width * exemplary}px`
116
- : `${width * 100}vw`
117
- : 'max-content'}`,
118
- height: `${sizingAxis.y === SizingType.Manual ? `${height * 100}vw` : 'unset'}`,
119
- transform: `scale(${scale})`,
120
- transformOrigin: ScaleAnchorMap[scaleAnchor]
121
- }}
122
- >
123
- <ItemComponent item={item} sectionId={sectionId} onResize={handleItemResize} />
124
- </div>
122
+ <RichTextWrapper isRichText={isRichText}>
123
+ <div
124
+ className={`item-${item.id}-inner`}
125
+ style={{
126
+ width: `${sizingAxis.x === SizingType.Manual
127
+ ? isRichText
128
+ ? `${width * exemplary}px`
129
+ : `${width * 100}vw`
130
+ : 'max-content'}`,
131
+ height: `${sizingAxis.y === SizingType.Manual ? `${height * 100}vw` : 'unset'}`,
132
+ transform: `scale(${scale})`,
133
+ transformOrigin: ScaleAnchorMap[scaleAnchor]
134
+ }}
135
+ >
136
+ <ItemComponent item={item} sectionId={sectionId} onResize={handleItemResize} />
137
+ </div>
138
+ </RichTextWrapper>
125
139
  </div>
126
140
  <JSXStyle id={id}>{`
127
141
  ${getLayoutStyles(layouts, layoutValues, ([area, hidden, hoverParams, sticky, sectionHeight, layoutParams]) => {
@@ -129,18 +143,19 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item, sectionId}) => {
129
143
  return (`
130
144
  .item-${item.id} {
131
145
  position: ${sticky ? 'sticky' : 'absolute'};
132
- width: ${sizingAxis.x === SizingType.Manual ? `${area.width * 100}vw` : 'max-content'};
133
- height: ${sizingAxis.y === SizingType.Manual ? `${area.height * 100}vw` : 'unset'};
134
- transform: scale(${scale});
135
146
  top: ${sticky ? `${getAnchoredItemTop(area.top - sticky.from, sectionHeight, area.anchorSide)}` : 0};
136
- transform-origin: ${ScaleAnchorMap[scaleAnchor]};
137
147
  pointer-events: auto;
138
- --webkit-backface-visibility: hidden;
139
148
  cursor: ${hoverParams ? 'pointer' : 'default'};
140
149
  visibility: ${hidden ? 'hidden' : 'visible'};
150
+ height: fit-content;
141
151
  }
142
152
  .item-${item.id}-inner {
143
153
  transition: ${getTransitions(['width', 'height', 'scale'], hoverParams)};
154
+ width: ${sizingAxis.x === SizingType.Manual ? `${area.width * 100}vw` : 'max-content'};
155
+ height: ${sizingAxis.y === SizingType.Manual ? `${area.height * 100}vw` : 'unset'};
156
+ transform: scale(${scale});
157
+ transform-origin: ${ScaleAnchorMap[scaleAnchor]};
158
+ --webkit-backface-visibility: hidden;
144
159
  }
145
160
  .item-wrapper-${item.id} {
146
161
  position: absolute;
@@ -9,11 +9,10 @@ import { useRichTextItemValues } from './useRichTextItemValues';
9
9
  import ResizeObserver from 'resize-observer-polyfill';
10
10
 
11
11
  export const RichTextItem: FC<ItemProps<TRichTextItem>> = ({ item, sectionId, onResize }) => {
12
- const [content, styles, preset] = useRichTextItem(item);
12
+ const [content, styles] = useRichTextItem(item);
13
13
  const id = useId();
14
14
  const [ref, setRef] = useState<HTMLDivElement | null>(null);
15
15
  const { layouts } = useCntrlContext();
16
- const className = preset ? `cntrl-preset-${preset.id}` : undefined;
17
16
  const { angle, blur } = useRichTextItemValues(item, sectionId);
18
17
 
19
18
  useEffect(() => {
@@ -32,7 +31,7 @@ export const RichTextItem: FC<ItemProps<TRichTextItem>> = ({ item, sectionId, on
32
31
  <>
33
32
  <div
34
33
  ref={setRef}
35
- className={`${className} rich-text-wrapper-${item.id}`}
34
+ className={`rich-text-wrapper-${item.id}`}
36
35
  style={{
37
36
  transform: `rotate(${angle}deg)`,
38
37
  filter: `blur(${blur * 100}vw)`
@@ -4,7 +4,7 @@ import { useLayoutContext } from '../useLayoutContext';
4
4
 
5
5
  export const useRichTextItemValues = (item: TRichTextItem, sectionId: string) => {
6
6
  const layoutId = useLayoutContext();
7
- const angle = useKeyframeValue(
7
+ const { angle } = useKeyframeValue(
8
8
  item,
9
9
  (item, layoutId) => ({ angle: layoutId ? item.area[layoutId].angle : 0 }),
10
10
  (animator, scroll, value) => animator.getRotation(value, scroll),
Binary file
Binary file