@cntrl-site/sdk-nextjs 1.9.42 → 1.9.44
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.
- package/lib/components/items/Item.js +8 -4
- package/lib/components/items/RectangleItem/RectangleItem.js +2 -2
- package/lib/utils/getItemTopStyle.js +27 -1
- package/package.json +2 -2
- package/src/components/items/Item.tsx +11 -6
- package/src/components/items/RectangleItem/RectangleItem.tsx +2 -2
- package/src/utils/getItemTopStyle.ts +25 -0
|
@@ -117,6 +117,9 @@ const Item = ({ item, sectionId, articleHeight, isParentVisible = true, isInGrou
|
|
|
117
117
|
};
|
|
118
118
|
const isRichText = (0, isItemType_1.isItemType)(item, sdk_1.ArticleItemType.RichText);
|
|
119
119
|
const anchorSide = layout ? item.area[layout].anchorSide : sdk_1.AnchorSide.Top;
|
|
120
|
+
const dimensionsType = layout ? item.area[layout].dimensionsType : sdk_1.DimensionsType.PixelsBased;
|
|
121
|
+
const isContainItem = dimensionsType === sdk_1.DimensionsType.PercentageBased;
|
|
122
|
+
const itemInnerHeight = isContainItem ? `${height}vh` : `${height * 100}vw`;
|
|
120
123
|
const positionType = layout ? item.area[layout].positionType : sdk_1.PositionType.ScreenBased;
|
|
121
124
|
const isScreenBasedBottom = positionType === sdk_1.PositionType.ScreenBased && anchorSide === sdk_1.AnchorSide.Bottom;
|
|
122
125
|
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;
|
|
@@ -125,7 +128,7 @@ const Item = ({ item, sectionId, articleHeight, isParentVisible = true, isInGrou
|
|
|
125
128
|
var _a;
|
|
126
129
|
e.stopPropagation();
|
|
127
130
|
(_a = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.handleTransitionEnd) === null || _a === void 0 ? void 0 : _a.call(interactionCtrl, e.propertyName);
|
|
128
|
-
}, style: Object.assign(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' }), (blendMode && { mixBlendMode: blendMode })), children: [(0, jsx_runtime_1.jsx)("div", { suppressHydrationWarning: true, className: `item-${item.id}`, style: {
|
|
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: {
|
|
129
132
|
opacity: (keyframes.length !== 0 && !layout) ? 0 : 1,
|
|
130
133
|
top: sticky ? (0, getAnchoredItemTop_1.getAnchoredItemTop)(stickyTop, sectionHeight, anchorSide) : 0,
|
|
131
134
|
height: isRichText && itemHeight !== undefined ? `${itemHeight * 100}vw` : 'unset'
|
|
@@ -136,7 +139,7 @@ const Item = ({ item, sectionId, articleHeight, isParentVisible = true, isInGrou
|
|
|
136
139
|
? `${width * exemplary}px`
|
|
137
140
|
: `${width * 100}vw`
|
|
138
141
|
: 'max-content'}`,
|
|
139
|
-
height: `${sizingAxis.y === 'manual' ?
|
|
142
|
+
height: `${sizingAxis.y === 'manual' ? itemInnerHeight : 'unset'}`
|
|
140
143
|
}
|
|
141
144
|
: {})), (scale !== undefined ? { transform: `scale(${scale})`, WebkitTransform: `scale(${scale})` } : {})), { transition: (_l = innerStateProps === null || innerStateProps === void 0 ? void 0 : innerStateProps.transition) !== null && _l !== void 0 ? _l : 'none', cursor: isDraggingActive
|
|
142
145
|
? 'grabbing'
|
|
@@ -149,6 +152,7 @@ const Item = ({ item, sectionId, articleHeight, isParentVisible = true, isInGrou
|
|
|
149
152
|
const sizingAxis = (0, useSizing_1.parseSizing)(layoutParams.sizing);
|
|
150
153
|
const isScreenBasedBottom = area.positionType === sdk_1.PositionType.ScreenBased && area.anchorSide === sdk_1.AnchorSide.Bottom;
|
|
151
154
|
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`;
|
|
152
156
|
return (`
|
|
153
157
|
.item-${item.id} {
|
|
154
158
|
position: ${sticky ? 'sticky' : 'absolute'};
|
|
@@ -162,7 +166,7 @@ const Item = ({ item, sectionId, articleHeight, isParentVisible = true, isInGrou
|
|
|
162
166
|
width: ${sizingAxis.x === 'manual'
|
|
163
167
|
? `${area.width * 100}vw`
|
|
164
168
|
: 'max-content'};
|
|
165
|
-
height: ${sizingAxis.y === 'manual' ?
|
|
169
|
+
height: ${sizingAxis.y === 'manual' ? innerHeight : 'unset'};
|
|
166
170
|
transform-origin: ${ScaleAnchorMap_1.ScaleAnchorMap[scaleAnchor]};
|
|
167
171
|
transform: scale(${area.scale});
|
|
168
172
|
position: relative;
|
|
@@ -173,7 +177,7 @@ const Item = ({ item, sectionId, articleHeight, isParentVisible = true, isInGrou
|
|
|
173
177
|
${!isInGroup && stickyFix}
|
|
174
178
|
pointer-events: none;
|
|
175
179
|
bottom: ${isScreenBasedBottom ? `${-area.top * 100}vw` : 'unset'};
|
|
176
|
-
top: ${isScreenBasedBottom ? 'unset' : (0, getItemTopStyle_1.getItemTopStyle)(area.top, area.anchorSide)};
|
|
180
|
+
top: ${isScreenBasedBottom ? 'unset' : isContainItem ? (0, getItemTopStyle_1.getPercentageBasedTopStyle)(area.top, area.height, area.anchorSide) : (0, getItemTopStyle_1.getItemTopStyle)(area.top, area.anchorSide)};
|
|
177
181
|
left: ${area.left * 100}vw;
|
|
178
182
|
}
|
|
179
183
|
`);
|
|
@@ -24,8 +24,8 @@ const RectangleItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilit
|
|
|
24
24
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
25
25
|
const { fill: itemFill, radius: itemRadius, strokeWidth: itemStrokeWidth, strokeFill: itemStrokeFill, blur: itemBlur, backdropBlur: itemBackdropBlur } = (0, useRectangleItem_1.useRectangleItem)(item, sectionId);
|
|
26
26
|
const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
27
|
-
const stateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['angle', '
|
|
28
|
-
const stateFillParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['fill']);
|
|
27
|
+
const stateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['angle', 'blur', 'backdropBlur', 'strokeFill']);
|
|
28
|
+
const stateFillParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['fill', 'strokeWidth', 'radius']);
|
|
29
29
|
const stateFillLayers = (_a = stateFillParams === null || stateFillParams === void 0 ? void 0 : stateFillParams.styles) === null || _a === void 0 ? void 0 : _a.fill;
|
|
30
30
|
const solidTransition = (_b = stateFillParams === null || stateFillParams === void 0 ? void 0 : stateFillParams.transition) !== null && _b !== void 0 ? _b : 'none';
|
|
31
31
|
const styles = (_c = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) !== null && _c !== void 0 ? _c : {};
|
|
@@ -1,7 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getItemTopStyle = void 0;
|
|
3
|
+
exports.getItemTopStyle = exports.getPercentageBasedTopStyle = void 0;
|
|
4
4
|
const sdk_1 = require("@cntrl-site/sdk");
|
|
5
|
+
function getAnchorSideShift(anchorSide, height) {
|
|
6
|
+
if (!height)
|
|
7
|
+
return 0;
|
|
8
|
+
switch (anchorSide) {
|
|
9
|
+
case sdk_1.AnchorSide.Center:
|
|
10
|
+
return height / 2;
|
|
11
|
+
case sdk_1.AnchorSide.Bottom:
|
|
12
|
+
return height;
|
|
13
|
+
default:
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function getPercentageBasedTopStyle(top, height, anchorSide) {
|
|
18
|
+
const defaultValue = `${top * 100}vw`;
|
|
19
|
+
if (!anchorSide)
|
|
20
|
+
return defaultValue;
|
|
21
|
+
switch (anchorSide) {
|
|
22
|
+
case sdk_1.AnchorSide.Top:
|
|
23
|
+
return defaultValue;
|
|
24
|
+
case sdk_1.AnchorSide.Center:
|
|
25
|
+
return `calc(50% + ${top * 100}vw - ${getAnchorSideShift(anchorSide, height)}vh)`;
|
|
26
|
+
case sdk_1.AnchorSide.Bottom:
|
|
27
|
+
return `calc(100% + ${top * 100}vw - ${getAnchorSideShift(anchorSide, height)}vh)`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.getPercentageBasedTopStyle = getPercentageBasedTopStyle;
|
|
5
31
|
function getItemTopStyle(top, anchorSide) {
|
|
6
32
|
const defaultValue = `${top * 100}vw`;
|
|
7
33
|
if (!anchorSide)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntrl-site/sdk-nextjs",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.44",
|
|
4
4
|
"description": "SDK for Next.js",
|
|
5
5
|
"author": "arsen@momdesign.nyc",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@cntrl-site/color": "^1.0.0",
|
|
33
33
|
"@cntrl-site/components": "^0.1.29",
|
|
34
34
|
"@cntrl-site/effects": "^1.4.0",
|
|
35
|
-
"@cntrl-site/sdk": "^1.25.
|
|
35
|
+
"@cntrl-site/sdk": "^1.25.8",
|
|
36
36
|
"@types/vimeo__player": "^2.18.0",
|
|
37
37
|
"@vimeo/player": "^2.25.0",
|
|
38
38
|
"html-react-parser": "^3.0.1",
|
|
@@ -13,13 +13,14 @@ import {
|
|
|
13
13
|
getLayoutStyles,
|
|
14
14
|
ItemAny,
|
|
15
15
|
AreaAnchor,
|
|
16
|
-
PositionType
|
|
16
|
+
PositionType,
|
|
17
|
+
DimensionsType
|
|
17
18
|
} from '@cntrl-site/sdk';
|
|
18
19
|
import { useCntrlContext } from '../../provider/useCntrlContext';
|
|
19
20
|
import { useItemScale } from './useItemScale';
|
|
20
21
|
import { ScaleAnchorMap } from '../../utils/ScaleAnchorMap';
|
|
21
22
|
import { useSectionHeightData } from '../Section/useSectionHeightMap';
|
|
22
|
-
import { getItemTopStyle } from '../../utils/getItemTopStyle';
|
|
23
|
+
import { getItemTopStyle, getPercentageBasedTopStyle } from '../../utils/getItemTopStyle';
|
|
23
24
|
import { useStickyItemTop } from './useStickyItemTop';
|
|
24
25
|
import { getAnchoredItemTop } from '../../utils/getAnchoredItemTop';
|
|
25
26
|
import { useLayoutContext } from '../useLayoutContext';
|
|
@@ -146,6 +147,9 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight, isP
|
|
|
146
147
|
|
|
147
148
|
const isRichText = isItemType(item, ArticleItemType.RichText);
|
|
148
149
|
const anchorSide = layout ? item.area[layout].anchorSide : AnchorSide.Top;
|
|
150
|
+
const dimensionsType = layout ? item.area[layout].dimensionsType : DimensionsType.PixelsBased;
|
|
151
|
+
const isContainItem = dimensionsType === DimensionsType.PercentageBased;
|
|
152
|
+
const itemInnerHeight = isContainItem ? `${height}vh` : `${height! * 100}vw`;
|
|
149
153
|
const positionType = layout ? item.area[layout].positionType : PositionType.ScreenBased;
|
|
150
154
|
const isScreenBasedBottom = positionType === PositionType.ScreenBased && anchorSide === AnchorSide.Bottom;
|
|
151
155
|
const scale = innerStateProps?.styles?.scale ?? itemScale;
|
|
@@ -159,7 +163,7 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight, isP
|
|
|
159
163
|
interactionCtrl?.handleTransitionEnd?.(e.propertyName);
|
|
160
164
|
}}
|
|
161
165
|
style={{
|
|
162
|
-
...(top !== undefined ? { top: isScreenBasedBottom ? 'unset' : getItemTopStyle(top, anchorSide) } : {}),
|
|
166
|
+
...(top !== undefined ? { top: isScreenBasedBottom ? 'unset' : isContainItem ? getPercentageBasedTopStyle(top, height, anchorSide) : getItemTopStyle(top, anchorSide) } : {}),
|
|
163
167
|
...(left !== undefined ? { left: `${left * 100}vw` } : {}),
|
|
164
168
|
...(top !== undefined ? { bottom: isScreenBasedBottom ? `${-top * 100}vw` : 'unset' } : {}),
|
|
165
169
|
...(wrapperHeight !== undefined ? { height: `${wrapperHeight * 100}vw` } : {}),
|
|
@@ -190,7 +194,7 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight, isP
|
|
|
190
194
|
? `${width * exemplary}px`
|
|
191
195
|
: `${width * 100}vw`
|
|
192
196
|
: 'max-content'}`,
|
|
193
|
-
height: `${sizingAxis.y === 'manual' ?
|
|
197
|
+
height: `${sizingAxis.y === 'manual' ? itemInnerHeight : 'unset'}`
|
|
194
198
|
}
|
|
195
199
|
: {}),
|
|
196
200
|
...(scale !== undefined ? { transform: `scale(${scale})`, WebkitTransform: `scale(${scale})` } : {}),
|
|
@@ -226,6 +230,7 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight, isP
|
|
|
226
230
|
const sizingAxis = parseSizing(layoutParams.sizing);
|
|
227
231
|
const isScreenBasedBottom = area.positionType === PositionType.ScreenBased && area.anchorSide === AnchorSide.Bottom;
|
|
228
232
|
const scaleAnchor = area.scaleAnchor as AreaAnchor;
|
|
233
|
+
const innerHeight = area?.dimensionsType && area?.dimensionsType === DimensionsType.PercentageBased ? `${area.height}vh` : `${area.height * 100}vw`;
|
|
229
234
|
return (`
|
|
230
235
|
.item-${item.id} {
|
|
231
236
|
position: ${sticky ? 'sticky' : 'absolute'};
|
|
@@ -239,7 +244,7 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight, isP
|
|
|
239
244
|
width: ${sizingAxis.x === 'manual'
|
|
240
245
|
? `${area.width * 100}vw`
|
|
241
246
|
: 'max-content'};
|
|
242
|
-
height: ${sizingAxis.y === 'manual' ?
|
|
247
|
+
height: ${sizingAxis.y === 'manual' ? innerHeight : 'unset'};
|
|
243
248
|
transform-origin: ${ScaleAnchorMap[scaleAnchor]};
|
|
244
249
|
transform: scale(${area.scale});
|
|
245
250
|
position: relative;
|
|
@@ -250,7 +255,7 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight, isP
|
|
|
250
255
|
${!isInGroup && stickyFix}
|
|
251
256
|
pointer-events: none;
|
|
252
257
|
bottom: ${isScreenBasedBottom ? `${-area.top * 100}vw` : 'unset'};
|
|
253
|
-
top: ${isScreenBasedBottom ? 'unset' : getItemTopStyle(area.top, area.anchorSide)};
|
|
258
|
+
top: ${isScreenBasedBottom ? 'unset' : isContainItem ? getPercentageBasedTopStyle(area.top, area.height, area.anchorSide) : getItemTopStyle(area.top, area.anchorSide)};
|
|
254
259
|
left: ${area.left * 100}vw;
|
|
255
260
|
}
|
|
256
261
|
`);
|
|
@@ -25,8 +25,8 @@ export const RectangleItem: FC<ItemProps<TRectangleItem>> = ({ item, sectionId,
|
|
|
25
25
|
backdropBlur: itemBackdropBlur
|
|
26
26
|
} = useRectangleItem(item, sectionId);
|
|
27
27
|
const itemAngle = useItemAngle(item, sectionId);
|
|
28
|
-
const stateParams = interactionCtrl?.getState<any>(['angle', '
|
|
29
|
-
const stateFillParams = interactionCtrl?.getState<FillLayer[]>(['fill']);
|
|
28
|
+
const stateParams = interactionCtrl?.getState<any>(['angle', 'blur', 'backdropBlur', 'strokeFill']);
|
|
29
|
+
const stateFillParams = interactionCtrl?.getState<FillLayer[]>(['fill', 'strokeWidth', 'radius']);
|
|
30
30
|
const stateFillLayers = stateFillParams?.styles?.fill;
|
|
31
31
|
const solidTransition = stateFillParams?.transition ?? 'none';
|
|
32
32
|
const styles = stateParams?.styles ?? {};
|
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
import { AnchorSide } from '@cntrl-site/sdk';
|
|
2
2
|
|
|
3
|
+
function getAnchorSideShift(anchorSide: AnchorSide, height?: number) {
|
|
4
|
+
if (!height) return 0;
|
|
5
|
+
switch (anchorSide) {
|
|
6
|
+
case AnchorSide.Center:
|
|
7
|
+
return height / 2;
|
|
8
|
+
case AnchorSide.Bottom:
|
|
9
|
+
return height;
|
|
10
|
+
default:
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getPercentageBasedTopStyle(top: number, height?: number, anchorSide?: AnchorSide) {
|
|
16
|
+
const defaultValue = `${top * 100}vw`;
|
|
17
|
+
if (!anchorSide) return defaultValue;
|
|
18
|
+
switch (anchorSide) {
|
|
19
|
+
case AnchorSide.Top:
|
|
20
|
+
return defaultValue;
|
|
21
|
+
case AnchorSide.Center:
|
|
22
|
+
return `calc(50% + ${top * 100}vw - ${getAnchorSideShift(anchorSide, height)}vh)`;
|
|
23
|
+
case AnchorSide.Bottom:
|
|
24
|
+
return `calc(100% + ${top * 100}vw - ${getAnchorSideShift(anchorSide, height)}vh)`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
3
28
|
export function getItemTopStyle(top: number, anchorSide?: AnchorSide) {
|
|
4
29
|
const defaultValue = `${top * 100}vw`;
|
|
5
30
|
if (!anchorSide) return defaultValue;
|