@cntrl-site/sdk-nextjs 1.9.123 → 1.9.125

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.
@@ -36,7 +36,7 @@ const StructuredBlockItem = ({ block, maxWidthMap }) => {
36
36
  align-self: ${getAlignSelf((_a = area.alignment) !== null && _a !== void 0 ? _a : 'center')};
37
37
  width: ${sizingAxis.x === 'manual' && area.width ? `${area.width * 100}vw` : maxWidth !== null && maxWidth !== void 0 ? maxWidth : 'max-content'};
38
38
  height: ${sizingAxis.y === 'manual' && area.height ? `${area.height * 100}vw` : 'unset'};
39
- padding-top: ${area.paddingTop ? `${area.paddingTop * 100}vw` : 'unset'};
39
+ margin-top: ${area.paddingTop ? `${area.paddingTop * 100}vw` : 'unset'};
40
40
  outline: none;
41
41
  left: ${((_b = area.horizontalOffset) !== null && _b !== void 0 ? _b : 0) * 100}vw;
42
42
  position: relative;
@@ -28,6 +28,7 @@ const useSizing_1 = require("./useSizing");
28
28
  const useItemPointerEvents_1 = require("./useItemPointerEvents");
29
29
  const useItemArea_1 = require("./useItemArea");
30
30
  const useDraggable_1 = require("./useDraggable");
31
+ const getViewportHeightUnit_1 = require("../../utils/getViewportHeightUnit");
31
32
  const ItemGeometryContext_1 = require("../../ItemGeometry/ItemGeometryContext");
32
33
  const stickyFix = `
33
34
  -webkit-transform: translate3d(0, 0, 0);
@@ -119,7 +120,8 @@ const Item = ({ item, sectionId, articleHeight, isParentVisible = true, isInGrou
119
120
  const anchorSide = layout ? item.area[layout].anchorSide : sdk_1.AnchorSide.Top;
120
121
  const dimensionsType = layout ? item.area[layout].dimensionsType : sdk_1.DimensionsType.PixelsBased;
121
122
  const isContainItem = dimensionsType === sdk_1.DimensionsType.PercentageBased;
122
- const itemInnerHeight = isContainItem ? `${height}vh` : `${height * 100}vw`;
123
+ const vhUnit = (0, getViewportHeightUnit_1.getViewportHeightUnit)();
124
+ const itemInnerHeight = isContainItem ? `${height}${vhUnit}` : `${height * 100}vw`;
123
125
  const positionType = layout ? item.area[layout].positionType : sdk_1.PositionType.ScreenBased;
124
126
  const isScreenBasedBottom = positionType === sdk_1.PositionType.ScreenBased && anchorSide === sdk_1.AnchorSide.Bottom;
125
127
  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;
@@ -128,7 +130,7 @@ const Item = ({ item, sectionId, articleHeight, isParentVisible = true, isInGrou
128
130
  var _a;
129
131
  e.stopPropagation();
130
132
  (_a = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.handleTransitionEnd) === null || _a === void 0 ? void 0 : _a.call(interactionCtrl, e.propertyName);
131
- }, style: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (top !== undefined ? { top: isScreenBasedBottom ? 'unset' : isContainItem ? (0, getItemTopStyle_1.getPercentageBasedTopStyle)(top, height, anchorSide) : (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' }), (blendMode && { mixBlendMode: blendMode })), children: [(0, jsx_runtime_1.jsx)("div", { suppressHydrationWarning: true, className: `item-${item.id}`, style: {
133
+ }, style: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (top !== undefined ? { top: isScreenBasedBottom ? 'unset' : isContainItem ? (0, getItemTopStyle_1.getPercentageBasedTopStyle)(top, height, anchorSide, vhUnit) : (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' }), (blendMode && { mixBlendMode: blendMode })), children: [(0, jsx_runtime_1.jsx)("div", { suppressHydrationWarning: true, className: `item-${item.id}`, style: {
132
134
  opacity: (keyframes.length !== 0 && !layout) ? 0 : 1,
133
135
  top: sticky ? (0, getAnchoredItemTop_1.getAnchoredItemTop)(stickyTop, `${sectionHeight}px`, anchorSide) : 0,
134
136
  height: isRichText && itemHeight !== undefined ? `${itemHeight * 100}vw` : 'unset'
@@ -152,7 +154,9 @@ const Item = ({ item, sectionId, articleHeight, isParentVisible = true, isInGrou
152
154
  const sizingAxis = (0, useSizing_1.parseSizing)(layoutParams.sizing);
153
155
  const isScreenBasedBottom = area.positionType === sdk_1.PositionType.ScreenBased && area.anchorSide === sdk_1.AnchorSide.Bottom;
154
156
  const scaleAnchor = area.scaleAnchor;
155
- const innerHeight = (area === null || area === void 0 ? void 0 : area.dimensionsType) && (area === null || area === void 0 ? void 0 : area.dimensionsType) === sdk_1.DimensionsType.PercentageBased ? `${area.height}vh` : `${area.height * 100}vw`;
157
+ const isAreaContainItem = (area === null || area === void 0 ? void 0 : area.dimensionsType) === sdk_1.DimensionsType.PercentageBased;
158
+ const innerHeightFallback = isAreaContainItem ? `${area.height}vh` : `${area.height * 100}vw`;
159
+ const innerHeight = isAreaContainItem ? `${area.height}svh` : `${area.height * 100}vw`;
156
160
  return (`
157
161
  .item-${item.id} {
158
162
  position: ${sticky ? 'sticky' : 'absolute'};
@@ -166,6 +170,7 @@ const Item = ({ item, sectionId, articleHeight, isParentVisible = true, isInGrou
166
170
  width: ${sizingAxis.x === 'manual'
167
171
  ? `${area.width * 100}vw`
168
172
  : 'max-content'};
173
+ height: ${sizingAxis.y === 'manual' ? innerHeightFallback : 'unset'};
169
174
  height: ${sizingAxis.y === 'manual' ? innerHeight : 'unset'};
170
175
  transform-origin: ${ScaleAnchorMap_1.ScaleAnchorMap[scaleAnchor]};
171
176
  transform: scale(${area.scale});
@@ -177,6 +182,7 @@ const Item = ({ item, sectionId, articleHeight, isParentVisible = true, isInGrou
177
182
  ${!isInGroup && sticky ? stickyFix : ''}
178
183
  pointer-events: none;
179
184
  bottom: ${isScreenBasedBottom ? `${-area.top * 100}vw` : 'unset'};
185
+ top: ${isScreenBasedBottom ? 'unset' : isContainItem ? (0, getItemTopStyle_1.getPercentageBasedTopStyle)(area.top, area.height, area.anchorSide, 'vh') : (0, getItemTopStyle_1.getItemTopStyle)(area.top, area.anchorSide)};
180
186
  top: ${isScreenBasedBottom ? 'unset' : isContainItem ? (0, getItemTopStyle_1.getPercentageBasedTopStyle)(area.top, area.height, area.anchorSide) : (0, getItemTopStyle_1.getItemTopStyle)(area.top, area.anchorSide)};
181
187
  left: ${area.left * 100}vw;
182
188
  }
@@ -14,7 +14,7 @@ function getAnchorSideShift(anchorSide, height) {
14
14
  return 0;
15
15
  }
16
16
  }
17
- function getPercentageBasedTopStyle(top, height, anchorSide) {
17
+ function getPercentageBasedTopStyle(top, height, anchorSide, unit = 'svh') {
18
18
  const defaultValue = `${top * 100}vw`;
19
19
  if (!anchorSide)
20
20
  return defaultValue;
@@ -22,9 +22,9 @@ function getPercentageBasedTopStyle(top, height, anchorSide) {
22
22
  case sdk_1.AnchorSide.Top:
23
23
  return defaultValue;
24
24
  case sdk_1.AnchorSide.Center:
25
- return `calc(50% + ${top * 100}vw - ${getAnchorSideShift(anchorSide, height)}vh)`;
25
+ return `calc(50% + ${top * 100}vw - ${getAnchorSideShift(anchorSide, height)}${unit})`;
26
26
  case sdk_1.AnchorSide.Bottom:
27
- return `calc(100% + ${top * 100}vw - ${getAnchorSideShift(anchorSide, height)}vh)`;
27
+ return `calc(100% + ${top * 100}vw - ${getAnchorSideShift(anchorSide, height)}${unit})`;
28
28
  }
29
29
  }
30
30
  exports.getPercentageBasedTopStyle = getPercentageBasedTopStyle;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getViewportHeightUnit = void 0;
4
+ let cachedUnit;
5
+ // Inline styles hold a single value, so the CSS fallback-declaration trick
6
+ // doesn't apply there — pick the unit at runtime instead.
7
+ function getViewportHeightUnit() {
8
+ if (cachedUnit !== undefined)
9
+ return cachedUnit;
10
+ if (typeof window === 'undefined')
11
+ return 'svh';
12
+ const supportsSvh = typeof CSS !== 'undefined' && CSS.supports
13
+ ? CSS.supports('height', '1svh')
14
+ : false;
15
+ cachedUnit = supportsSvh ? 'svh' : 'vh';
16
+ return cachedUnit;
17
+ }
18
+ exports.getViewportHeightUnit = getViewportHeightUnit;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "1.9.123",
3
+ "version": "1.9.125",
4
4
  "description": "SDK for Next.js",
5
5
  "author": "arsen@momdesign.nyc",
6
6
  "license": "MIT",
@@ -44,7 +44,7 @@ export const StructuredBlockItem: FC<Props> = ({ block, maxWidthMap }) => {
44
44
  align-self: ${getAlignSelf(area.alignment ?? 'center')};
45
45
  width: ${sizingAxis.x === 'manual' && area.width ? `${area.width * 100}vw` : maxWidth ?? 'max-content'};
46
46
  height: ${sizingAxis.y === 'manual' && area.height ? `${area.height * 100}vw` : 'unset'};
47
- padding-top: ${area.paddingTop ? `${area.paddingTop * 100}vw` : 'unset'};
47
+ margin-top: ${area.paddingTop ? `${area.paddingTop * 100}vw` : 'unset'};
48
48
  outline: none;
49
49
  left: ${(area.horizontalOffset ?? 0) * 100}vw;
50
50
  position: relative;
@@ -36,6 +36,7 @@ import { parseSizing, useSizing } from './useSizing';
36
36
  import { useItemPointerEvents } from './useItemPointerEvents';
37
37
  import { useItemArea } from './useItemArea';
38
38
  import { useDraggable } from './useDraggable';
39
+ import { getViewportHeightUnit } from '../../utils/getViewportHeightUnit';
39
40
  import { ItemGeometryContext } from '../../ItemGeometry/ItemGeometryContext';
40
41
 
41
42
  export interface ItemProps<I extends ItemAny> {
@@ -150,7 +151,8 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight, isP
150
151
  const anchorSide = layout ? item.area[layout].anchorSide : AnchorSide.Top;
151
152
  const dimensionsType = layout ? item.area[layout].dimensionsType : DimensionsType.PixelsBased;
152
153
  const isContainItem = dimensionsType === DimensionsType.PercentageBased;
153
- const itemInnerHeight = isContainItem ? `${height}vh` : `${height! * 100}vw`;
154
+ const vhUnit = getViewportHeightUnit();
155
+ const itemInnerHeight = isContainItem ? `${height}${vhUnit}` : `${height! * 100}vw`;
154
156
  const positionType = layout ? item.area[layout].positionType : PositionType.ScreenBased;
155
157
  const isScreenBasedBottom = positionType === PositionType.ScreenBased && anchorSide === AnchorSide.Bottom;
156
158
  const scale = innerStateProps?.styles?.scale ?? itemScale;
@@ -164,7 +166,7 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight, isP
164
166
  interactionCtrl?.handleTransitionEnd?.(e.propertyName);
165
167
  }}
166
168
  style={{
167
- ...(top !== undefined ? { top: isScreenBasedBottom ? 'unset' : isContainItem ? getPercentageBasedTopStyle(top, height, anchorSide) : getItemTopStyle(top, anchorSide) } : {}),
169
+ ...(top !== undefined ? { top: isScreenBasedBottom ? 'unset' : isContainItem ? getPercentageBasedTopStyle(top, height, anchorSide, vhUnit) : getItemTopStyle(top, anchorSide) } : {}),
168
170
  ...(left !== undefined ? { left: `${left * 100}vw` } : {}),
169
171
  ...(top !== undefined ? { bottom: isScreenBasedBottom ? `${-top * 100}vw` : 'unset' } : {}),
170
172
  ...(wrapperHeight !== undefined ? { height: `${wrapperHeight * 100}vw` } : {}),
@@ -231,7 +233,9 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight, isP
231
233
  const sizingAxis = parseSizing(layoutParams.sizing);
232
234
  const isScreenBasedBottom = area.positionType === PositionType.ScreenBased && area.anchorSide === AnchorSide.Bottom;
233
235
  const scaleAnchor = area.scaleAnchor as AreaAnchor;
234
- const innerHeight = area?.dimensionsType && area?.dimensionsType === DimensionsType.PercentageBased ? `${area.height}vh` : `${area.height * 100}vw`;
236
+ const isAreaContainItem = area?.dimensionsType === DimensionsType.PercentageBased;
237
+ const innerHeightFallback = isAreaContainItem ? `${area.height}vh` : `${area.height * 100}vw`;
238
+ const innerHeight = isAreaContainItem ? `${area.height}svh` : `${area.height * 100}vw`;
235
239
  return (`
236
240
  .item-${item.id} {
237
241
  position: ${sticky ? 'sticky' : 'absolute'};
@@ -245,6 +249,7 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight, isP
245
249
  width: ${sizingAxis.x === 'manual'
246
250
  ? `${area.width * 100}vw`
247
251
  : 'max-content'};
252
+ height: ${sizingAxis.y === 'manual' ? innerHeightFallback : 'unset'};
248
253
  height: ${sizingAxis.y === 'manual' ? innerHeight : 'unset'};
249
254
  transform-origin: ${ScaleAnchorMap[scaleAnchor]};
250
255
  transform: scale(${area.scale});
@@ -256,6 +261,7 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight, isP
256
261
  ${!isInGroup && sticky ? stickyFix : ''}
257
262
  pointer-events: none;
258
263
  bottom: ${isScreenBasedBottom ? `${-area.top * 100}vw` : 'unset'};
264
+ top: ${isScreenBasedBottom ? 'unset' : isContainItem ? getPercentageBasedTopStyle(area.top, area.height, area.anchorSide, 'vh') : getItemTopStyle(area.top, area.anchorSide)};
259
265
  top: ${isScreenBasedBottom ? 'unset' : isContainItem ? getPercentageBasedTopStyle(area.top, area.height, area.anchorSide) : getItemTopStyle(area.top, area.anchorSide)};
260
266
  left: ${area.left * 100}vw;
261
267
  }
@@ -12,16 +12,16 @@ function getAnchorSideShift(anchorSide: AnchorSide, height?: number) {
12
12
  }
13
13
  }
14
14
 
15
- export function getPercentageBasedTopStyle(top: number, height?: number, anchorSide?: AnchorSide) {
15
+ export function getPercentageBasedTopStyle(top: number, height?: number, anchorSide?: AnchorSide, unit: 'vh' | 'svh' = 'svh') {
16
16
  const defaultValue = `${top * 100}vw`;
17
17
  if (!anchorSide) return defaultValue;
18
18
  switch (anchorSide) {
19
19
  case AnchorSide.Top:
20
20
  return defaultValue;
21
21
  case AnchorSide.Center:
22
- return `calc(50% + ${top * 100}vw - ${getAnchorSideShift(anchorSide, height)}vh)`;
22
+ return `calc(50% + ${top * 100}vw - ${getAnchorSideShift(anchorSide, height)}${unit})`;
23
23
  case AnchorSide.Bottom:
24
- return `calc(100% + ${top * 100}vw - ${getAnchorSideShift(anchorSide, height)}vh)`;
24
+ return `calc(100% + ${top * 100}vw - ${getAnchorSideShift(anchorSide, height)}${unit})`;
25
25
  }
26
26
  }
27
27
 
@@ -0,0 +1,13 @@
1
+ let cachedUnit: 'vh' | 'svh' | undefined;
2
+
3
+ // Inline styles hold a single value, so the CSS fallback-declaration trick
4
+ // doesn't apply there — pick the unit at runtime instead.
5
+ export function getViewportHeightUnit(): 'vh' | 'svh' {
6
+ if (cachedUnit !== undefined) return cachedUnit;
7
+ if (typeof window === 'undefined') return 'svh';
8
+ const supportsSvh = typeof CSS !== 'undefined' && CSS.supports
9
+ ? CSS.supports('height', '1svh')
10
+ : false;
11
+ cachedUnit = supportsSvh ? 'svh' : 'vh';
12
+ return cachedUnit;
13
+ }