@cntrl-site/sdk-nextjs 1.9.6 → 1.9.8

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.
Binary file
@@ -4,12 +4,12 @@ exports.getSectionHeightMap = exports.useSectionHeightData = void 0;
4
4
  const react_1 = require("react");
5
5
  const CntrlContext_1 = require("../../provider/CntrlContext");
6
6
  const Section_1 = require("./Section");
7
- const useSectionHeightData = (sectionId) => {
7
+ function useSectionHeightData(sectionId) {
8
8
  const sectionHeightContext = (0, react_1.useContext)(CntrlContext_1.CntrlContext);
9
9
  const layouts = sectionHeightContext.layouts;
10
10
  const sectionHeightData = sectionHeightContext.getSectionHeightData(sectionId);
11
11
  return sectionHeightData ? getSectionHeightMap(sectionHeightData) : getDefaultHeightData(layouts);
12
- };
12
+ }
13
13
  exports.useSectionHeightData = useSectionHeightData;
14
14
  function getSectionHeightMap(sectionHeight) {
15
15
  return Object.fromEntries(Object.entries(sectionHeight).map(([sectionId, heightData]) => [sectionId, (0, Section_1.getSectionHeight)(heightData)]));
@@ -75,13 +75,11 @@ const ImageItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityCha
75
75
  '--stroke-background-repeat': strokeValue.behavior === 'repeat' ? 'repeat' : 'no-repeat'
76
76
  } : {})) : {})), { willChange: blur !== 0 && blur !== undefined ? 'transform' : 'unset', transition: (_q = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.transition) !== null && _q !== void 0 ? _q : 'none' }), children: [hasGLEffect && isFXAllowed
77
77
  ? ((0, jsx_runtime_1.jsx)("canvas", { style: inlineStyles, ref: fxCanvas, className: `img-canvas image-${item.id}`, width: rectWidth, height: rectHeight }))
78
- : ((0, jsx_runtime_1.jsx)("img", { alt: "", className: `image image-${item.id}`, style: inlineStyles, src: item.commonParams.url })), (0, jsx_runtime_1.jsx)("div", { className: `image-border-${item.id}`, style: Object.assign({ position: 'absolute', inset: 0, borderRadius: 'inherit', pointerEvents: 'none', zIndex: 2, WebkitMask: 'linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)', WebkitMaskComposite: 'xor', maskComposite: 'exclude' }, (strokeWidth !== 0 && strokeValue ? Object.assign(Object.assign(Object.assign({}, (strokeWidth ? { padding: `${strokeWidth * 100}vw` } : {})), (strokeValue.type === 'solid' ? { transition: strokeSolidTransition, background: stroke } : {})), (strokeValue.type === 'image' ? {
78
+ : ((0, jsx_runtime_1.jsx)("img", { alt: "", className: `image image-${item.id}`, style: inlineStyles, src: item.commonParams.url })), strokeWidth !== 0 && strokeValue && ((0, jsx_runtime_1.jsx)("div", { className: `image-border-${item.id}`, style: Object.assign({ position: 'absolute', inset: 0, borderRadius: 'inherit', pointerEvents: 'none', zIndex: 2, WebkitMask: 'linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)', WebkitMaskComposite: 'xor', maskComposite: 'exclude' }, (strokeWidth !== 0 && strokeValue ? Object.assign(Object.assign(Object.assign({}, (strokeWidth ? { padding: `${strokeWidth * 100}vw` } : {})), (strokeValue.type === 'solid' ? { transition: strokeSolidTransition, background: stroke } : {})), (strokeValue.type === 'image' ? {
79
79
  backgroundPosition: 'center',
80
80
  backgroundSize: strokeValue.behavior === 'repeat' ? `${strokeValue.backgroundSize}%` : strokeValue.behavior,
81
81
  backgroundRepeat: strokeValue.behavior === 'repeat' ? 'repeat' : 'no-repeat'
82
- } : {
83
- background: stroke,
84
- })) : { background: stroke })) })] }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
82
+ } : { background: stroke })) : {})) }))] }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
85
83
  .image-wrapper-${item.id} {
86
84
  position: absolute;
87
85
  width: 100%;
@@ -138,13 +138,11 @@ const VideoItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityCha
138
138
  else {
139
139
  videoRef.play();
140
140
  }
141
- } })))] })), (0, jsx_runtime_1.jsx)("div", { className: `video-border-${item.id}`, style: Object.assign({ position: 'absolute', inset: 0, borderRadius: 'inherit', pointerEvents: 'none', zIndex: 2, WebkitMask: 'linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)', WebkitMaskComposite: 'xor', maskComposite: 'exclude' }, (strokeWidth !== 0 && strokeValue ? Object.assign(Object.assign(Object.assign({}, (strokeWidth ? { padding: `${strokeWidth * 100}vw` } : {})), (strokeValue.type === 'solid' ? { transition: strokeSolidTransition, background: stroke } : {})), (strokeValue.type === 'image' ? {
141
+ } })))] })), strokeWidth !== 0 && strokeValue && ((0, jsx_runtime_1.jsx)("div", { className: `video-border-${item.id}`, style: Object.assign({ position: 'absolute', inset: 0, borderRadius: 'inherit', pointerEvents: 'none', zIndex: 2, WebkitMask: 'linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)', WebkitMaskComposite: 'xor', maskComposite: 'exclude' }, (strokeWidth !== 0 && strokeValue ? Object.assign(Object.assign(Object.assign({}, (strokeWidth ? { padding: `${strokeWidth * 100}vw` } : {})), (strokeValue.type === 'solid' ? { transition: strokeSolidTransition, background: stroke } : {})), (strokeValue.type === 'image' ? {
142
142
  backgroundPosition: 'center',
143
143
  backgroundSize: strokeValue.behavior === 'repeat' ? `${strokeValue.backgroundSize}%` : strokeValue.behavior,
144
144
  backgroundRepeat: strokeValue.behavior === 'repeat' ? 'repeat' : 'no-repeat'
145
- } : {
146
- background: stroke,
147
- })) : { background: stroke })) })] }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
145
+ } : { background: stroke })) : {})) }))] }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
148
146
  .video-wrapper-${item.id} {
149
147
  position: absolute;
150
148
  overflow: hidden;
@@ -60,14 +60,16 @@ const Item = ({ item, sectionId, articleHeight, isParentVisible = true, isInGrou
60
60
  width: (_d = innerStateProps === null || innerStateProps === void 0 ? void 0 : innerStateProps.styles) === null || _d === void 0 ? void 0 : _d.width,
61
61
  height: (_e = innerStateProps === null || innerStateProps === void 0 ? void 0 : innerStateProps.styles) === null || _e === void 0 ? void 0 : _e.height
62
62
  });
63
- const sectionHeight = (0, useSectionHeightMap_1.useSectionHeightData)(sectionId);
63
+ const sectionHeightLayoutMap = (0, useSectionHeightMap_1.useSectionHeightData)(sectionId);
64
+ const sectionHeight = layout && sectionHeightLayoutMap[layout] ? sectionHeightLayoutMap[layout] : '0';
64
65
  const stickyTop = (0, useStickyItemTop_1.useStickyItemTop)(item, sectionId, (_f = wrapperStateProps === null || wrapperStateProps === void 0 ? void 0 : wrapperStateProps.styles) === null || _f === void 0 ? void 0 : _f.top);
65
66
  const layoutValues = [item.area, item.hidden];
66
67
  layoutValues.push(item.sticky);
67
- layoutValues.push(sectionHeight);
68
+ layoutValues.push(sectionHeightLayoutMap);
68
69
  if (item.layoutParams) {
69
70
  layoutValues.push(item.layoutParams);
70
71
  }
72
+ const sticky = layout ? item.sticky[layout] : undefined;
71
73
  const sizingAxis = (0, useSizing_1.useSizing)(item);
72
74
  const ItemComponent = itemsMap_1.itemsMap[item.type] || noop;
73
75
  const sectionTop = rectObserver ? rectObserver.getSectionTop(sectionId) : 0;
@@ -117,8 +119,8 @@ const Item = ({ item, sectionId, articleHeight, isParentVisible = true, isInGrou
117
119
  (_a = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.handleTransitionEnd) === null || _a === void 0 ? void 0 : _a.call(interactionCtrl, e.propertyName);
118
120
  }, style: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (top !== undefined ? { top: isScreenBasedBottom ? 'unset' : (0, getItemTopStyle_1.getItemTopStyle)(top, anchorSide) } : {})), (left !== undefined ? { left: `${left * 100}vw` } : {})), (top !== undefined ? { bottom: isScreenBasedBottom ? `${-top * 100}vw` : 'unset' } : {})), (wrapperHeight !== undefined ? { height: `${wrapperHeight * 100}vw` } : {})), { transition: (_k = wrapperStateProps === null || wrapperStateProps === void 0 ? void 0 : wrapperStateProps.transition) !== null && _k !== void 0 ? _k : 'none' }), children: [(0, jsx_runtime_1.jsx)("div", { suppressHydrationWarning: true, className: `item-${item.id}`, style: {
119
121
  opacity: (keyframes.length !== 0 && !layout) ? 0 : 1,
120
- top: `${stickyTop * 100}vw`,
121
- height: isRichText && itemHeight !== undefined ? `${itemHeight * 100}vw` : 'unset',
122
+ top: sticky ? (0, getAnchoredItemTop_1.getAnchoredItemTop)(stickyTop, sectionHeight, anchorSide) : 0,
123
+ height: isRichText && itemHeight !== undefined ? `${itemHeight * 100}vw` : 'unset'
122
124
  }, children: (0, jsx_runtime_1.jsx)(RichTextWrapper_1.RichTextWrapper, { isRichText: isRichText, children: (0, jsx_runtime_1.jsx)("div", Object.assign({ className: `item-${item.id}-inner`, ref: itemInnerRef, style: Object.assign(Object.assign(Object.assign({ top: `${position.y}px`, left: `${position.x}px` }, ((width !== undefined && height !== undefined)
123
125
  ? {
124
126
  width: `${sizingAxis.x === 'manual'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "1.9.6",
3
+ "version": "1.9.8",
4
4
  "description": "SDK for Next.js",
5
5
  "author": "arsen@momdesign.nyc",
6
6
  "license": "MIT",
@@ -3,17 +3,17 @@ import { CntrlContext } from '../../provider/CntrlContext';
3
3
  import { Layout, SectionHeight } from '@cntrl-site/sdk';
4
4
  import { getSectionHeight } from './Section';
5
5
 
6
- export const useSectionHeightData = (sectionId: string): Record<string, string> => {
6
+ export function useSectionHeightData(sectionId: string): Record<string, string> {
7
7
  const sectionHeightContext = useContext(CntrlContext);
8
8
  const layouts = sectionHeightContext.layouts;
9
9
  const sectionHeightData = sectionHeightContext.getSectionHeightData(sectionId);
10
10
  return sectionHeightData ? getSectionHeightMap(sectionHeightData) : getDefaultHeightData(layouts);
11
- };
11
+ }
12
12
 
13
13
  export function getSectionHeightMap(sectionHeight: Record<string, SectionHeight>): Record<string, string> {
14
14
  return Object.fromEntries(Object.entries(sectionHeight).map(([sectionId, heightData]) => [sectionId, getSectionHeight(heightData)]));
15
15
  }
16
16
 
17
17
  function getDefaultHeightData(layouts: Layout[]) {
18
- return layouts.reduce((acc, layout) => ({...acc, [layout.id]: '0'}), {});
18
+ return layouts.reduce((acc, layout) => ({ ...acc, [layout.id]: '0' }), {});
19
19
  }
@@ -123,31 +123,30 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
123
123
  src={item.commonParams.url}
124
124
  />
125
125
  )}
126
- <div
127
- className={`image-border-${item.id}`}
128
- style={{
129
- position: 'absolute',
130
- inset: 0,
131
- borderRadius: 'inherit',
132
- pointerEvents: 'none',
133
- zIndex: 2,
134
- WebkitMask: 'linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)',
135
- WebkitMaskComposite: 'xor',
136
- maskComposite: 'exclude',
137
- ...(strokeWidth !== 0 && strokeValue ? {
138
- ...(strokeWidth ? { padding: `${strokeWidth * 100}vw` } : {}),
139
- ...(strokeValue.type === 'solid' ? { transition: strokeSolidTransition, background: stroke } : {}),
140
- ...(strokeValue.type === 'image' ? {
141
- backgroundPosition: 'center',
142
- backgroundSize: strokeValue.behavior === 'repeat' ? `${strokeValue.backgroundSize}%` : strokeValue.behavior,
143
- backgroundRepeat: strokeValue.behavior === 'repeat' ? 'repeat' : 'no-repeat'
144
- } : {
145
- background: stroke,
146
- }
147
- )
148
- } : { background: stroke }),
149
- }}
150
- />
126
+ {strokeWidth !== 0 && strokeValue && (
127
+ <div
128
+ className={`image-border-${item.id}`}
129
+ style={{
130
+ position: 'absolute',
131
+ inset: 0,
132
+ borderRadius: 'inherit',
133
+ pointerEvents: 'none',
134
+ zIndex: 2,
135
+ WebkitMask: 'linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)',
136
+ WebkitMaskComposite: 'xor',
137
+ maskComposite: 'exclude',
138
+ ...(strokeWidth !== 0 && strokeValue ? {
139
+ ...(strokeWidth ? { padding: `${strokeWidth * 100}vw` } : {}),
140
+ ...(strokeValue.type === 'solid' ? { transition: strokeSolidTransition, background: stroke } : {}),
141
+ ...(strokeValue.type === 'image' ? {
142
+ backgroundPosition: 'center',
143
+ backgroundSize: strokeValue.behavior === 'repeat' ? `${strokeValue.backgroundSize}%` : strokeValue.behavior,
144
+ backgroundRepeat: strokeValue.behavior === 'repeat' ? 'repeat' : 'no-repeat'
145
+ } : { background: stroke })
146
+ } : {}),
147
+ }}
148
+ />
149
+ )}
151
150
  </div>
152
151
  <JSXStyle id={id}>{`
153
152
  .image-wrapper-${item.id} {
@@ -217,31 +217,30 @@ export const VideoItem: FC<ItemProps<TVideoItem>> = ({ item, sectionId, onResize
217
217
  ))}
218
218
  </>
219
219
  )}
220
- <div
221
- className={`video-border-${item.id}`}
222
- style={{
223
- position: 'absolute',
224
- inset: 0,
225
- borderRadius: 'inherit',
226
- pointerEvents: 'none',
227
- zIndex: 2,
228
- WebkitMask: 'linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)',
229
- WebkitMaskComposite: 'xor',
230
- maskComposite: 'exclude',
231
- ...(strokeWidth !== 0 && strokeValue ? {
232
- ...(strokeWidth ? { padding: `${strokeWidth * 100}vw` } : {}),
233
- ...(strokeValue.type === 'solid' ? { transition: strokeSolidTransition, background: stroke } : {}),
234
- ...(strokeValue.type === 'image' ? {
235
- backgroundPosition: 'center',
236
- backgroundSize: strokeValue.behavior === 'repeat' ? `${strokeValue.backgroundSize}%` : strokeValue.behavior,
237
- backgroundRepeat: strokeValue.behavior === 'repeat' ? 'repeat' : 'no-repeat'
238
- } : {
239
- background: stroke,
240
- }
241
- )
242
- } : { background: stroke }),
243
- }}
244
- />
220
+ {strokeWidth !== 0 && strokeValue && (
221
+ <div
222
+ className={`video-border-${item.id}`}
223
+ style={{
224
+ position: 'absolute',
225
+ inset: 0,
226
+ borderRadius: 'inherit',
227
+ pointerEvents: 'none',
228
+ zIndex: 2,
229
+ WebkitMask: 'linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)',
230
+ WebkitMaskComposite: 'xor',
231
+ maskComposite: 'exclude',
232
+ ...(strokeWidth !== 0 && strokeValue ? {
233
+ ...(strokeWidth ? { padding: `${strokeWidth * 100}vw` } : {}),
234
+ ...(strokeValue.type === 'solid' ? { transition: strokeSolidTransition, background: stroke } : {}),
235
+ ...(strokeValue.type === 'image' ? {
236
+ backgroundPosition: 'center',
237
+ backgroundSize: strokeValue.behavior === 'repeat' ? `${strokeValue.backgroundSize}%` : strokeValue.behavior,
238
+ backgroundRepeat: strokeValue.behavior === 'repeat' ? 'repeat' : 'no-repeat'
239
+ } : { background: stroke })
240
+ } : {}),
241
+ }}
242
+ />
243
+ )}
245
244
  </div>
246
245
  <JSXStyle id={id}>{`
247
246
  .video-wrapper-${item.id} {
@@ -90,14 +90,16 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight, isP
90
90
  width: innerStateProps?.styles?.width as number,
91
91
  height: innerStateProps?.styles?.height as number
92
92
  });
93
- const sectionHeight = useSectionHeightData(sectionId);
93
+ const sectionHeightLayoutMap = useSectionHeightData(sectionId);
94
+ const sectionHeight = layout && sectionHeightLayoutMap[layout] ? sectionHeightLayoutMap[layout] : '0';
94
95
  const stickyTop = useStickyItemTop(item, sectionId, wrapperStateProps?.styles?.top as number);
95
96
  const layoutValues: Record<string, any>[] = [item.area, item.hidden];
96
97
  layoutValues.push(item.sticky);
97
- layoutValues.push(sectionHeight);
98
+ layoutValues.push(sectionHeightLayoutMap);
98
99
  if (item.layoutParams) {
99
100
  layoutValues.push(item.layoutParams);
100
101
  }
102
+ const sticky = layout ? item.sticky[layout] : undefined;
101
103
  const sizingAxis = useSizing(item);
102
104
  const ItemComponent = itemsMap[item.type] || noop;
103
105
  const sectionTop = rectObserver ? rectObserver.getSectionTop(sectionId) : 0;
@@ -161,8 +163,8 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight, isP
161
163
  className={`item-${item.id}`}
162
164
  style={{
163
165
  opacity: (keyframes.length !== 0 && !layout) ? 0 : 1,
164
- top: `${stickyTop * 100}vw`,
165
- height: isRichText && itemHeight !== undefined ? `${itemHeight * 100}vw` : 'unset',
166
+ top: sticky ?getAnchoredItemTop(stickyTop, sectionHeight, anchorSide) : 0,
167
+ height: isRichText && itemHeight !== undefined ? `${itemHeight * 100}vw` : 'unset'
166
168
  }}
167
169
  >
168
170
  <RichTextWrapper isRichText={isRichText}>
@@ -13,7 +13,7 @@ export function useItemArea(
13
13
  KeyframeType.Position,
14
14
  (item, layoutId) => {
15
15
  if (!layoutId) return;
16
- return item.area[layoutId]
16
+ return item.area[layoutId];
17
17
  },
18
18
  (animator, scroll, value) => value ? animator.getPositions(value, scroll) : undefined,
19
19
  sectionId,
@@ -2,7 +2,7 @@ import { ItemAny, KeyframeType } from '@cntrl-site/sdk';
2
2
  import { useKeyframeValue } from '../../common/useKeyframeValue';
3
3
  import { useLayoutContext } from '../useLayoutContext';
4
4
 
5
- export function useStickyItemTop(item: ItemAny, sectionId: string, stateTop?: number) {
5
+ export function useStickyItemTop(item: ItemAny, sectionId: string, stateTop?: number) {
6
6
  const layoutId = useLayoutContext();
7
7
  const data = useKeyframeValue<{ top: number; left: number } | undefined>(
8
8
  item,