@cntrl-site/sdk-nextjs 0.14.0 → 0.14.2
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/cntrl-site-sdk-nextjs-0.12.9.tgz +0 -0
- package/cntrl-site-sdk-nextjs-0.14.1.tgz +0 -0
- package/lib/components/Item.js +5 -11
- package/lib/components/items/useStickyItemTop.js +14 -0
- package/lib/utils/getAnchoredItemTop.js +15 -0
- package/package.json +2 -2
- package/src/components/Item.tsx +4 -11
- package/src/components/items/useStickyItemTop.ts +18 -0
- package/src/utils/getAnchoredItemTop.ts +12 -0
|
Binary file
|
|
Binary file
|
package/lib/components/Item.js
CHANGED
|
@@ -24,6 +24,8 @@ const ScaleAnchorMap_1 = require("../utils/ScaleAnchorMap");
|
|
|
24
24
|
const useSectionHeightMap_1 = require("./useSectionHeightMap");
|
|
25
25
|
const HoverStyles_1 = require("../utils/HoverStyles/HoverStyles");
|
|
26
26
|
const getItemTopStyle_1 = require("../utils/getItemTopStyle");
|
|
27
|
+
const useStickyItemTop_1 = require("./items/useStickyItemTop");
|
|
28
|
+
const getAnchoredItemTop_1 = require("../utils/getAnchoredItemTop");
|
|
27
29
|
const itemsMap = {
|
|
28
30
|
[sdk_1.ArticleItemType.Rectangle]: RectangleItem_1.RectangleItem,
|
|
29
31
|
[sdk_1.ArticleItemType.Image]: ImageItem_1.ImageItem,
|
|
@@ -41,6 +43,7 @@ const Item = ({ item, sectionId }) => {
|
|
|
41
43
|
const { scale, scaleAnchor } = (0, useItemScale_1.useItemScale)(item, sectionId);
|
|
42
44
|
const { top, left } = (0, useItemPosition_1.useItemPosition)(item, sectionId);
|
|
43
45
|
const sectionHeight = (0, useSectionHeightMap_1.useSectionHeightData)(sectionId);
|
|
46
|
+
const stickyTop = (0, useStickyItemTop_1.useStickyItemTop)(item, sectionHeight, sectionId);
|
|
44
47
|
const layout = (0, useCurrentLayout_1.useCurrentLayout)();
|
|
45
48
|
const { width, height } = (0, useItemDimensions_1.useItemDimensions)(item, sectionId);
|
|
46
49
|
const layoutValues = [item.area, item.hidden, item.state.hover];
|
|
@@ -72,6 +75,7 @@ const Item = ({ item, sectionId }) => {
|
|
|
72
75
|
transformOrigin: ScaleAnchorMap_1.ScaleAnchorMap[scaleAnchor],
|
|
73
76
|
width: `${sizingAxis.x === sdk_1.ArticleItemSizingType.Manual ? `${width * 100}vw` : 'max-content'}`,
|
|
74
77
|
height: `${sizingAxis.y === sdk_1.ArticleItemSizingType.Manual ? `${height * 100}vw` : 'unset'}`,
|
|
78
|
+
top: stickyTop
|
|
75
79
|
};
|
|
76
80
|
return ((0, jsx_runtime_1.jsxs)("div", { className: `item-wrapper-${item.id}`, style: { top, left, ...(wrapperHeight ? { height: `${wrapperHeight * 100}vw` } : {}) }, children: [(0, jsx_runtime_1.jsx)("div", { suppressHydrationWarning: true, className: `item-${item.id}`, style: isInitialRef.current ? {} : styles, children: (0, jsx_runtime_1.jsx)(ItemComponent, { item: item, sectionId: sectionId, onResize: handleItemResize }) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
77
81
|
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, hidden, hoverParams, sticky, sectionHeight, layoutParams]) => {
|
|
@@ -82,7 +86,7 @@ const Item = ({ item, sectionId }) => {
|
|
|
82
86
|
width: ${sizingAxis.x === sdk_1.ArticleItemSizingType.Manual ? `${area.width * 100}vw` : 'max-content'};
|
|
83
87
|
height: ${sizingAxis.y === sdk_1.ArticleItemSizingType.Manual ? `w${area.height * 100}vw` : 'unset'};
|
|
84
88
|
transform: scale(${scale});
|
|
85
|
-
top: ${sticky ? `${getAnchoredItemTop(area.top - sticky.from, sectionHeight, area.anchorSide)}` : 0};
|
|
89
|
+
top: ${sticky ? `${(0, getAnchoredItemTop_1.getAnchoredItemTop)(area.top - sticky.from, sectionHeight, area.anchorSide)}` : 0};
|
|
86
90
|
transform-origin: ${ScaleAnchorMap_1.ScaleAnchorMap[scaleAnchor]};
|
|
87
91
|
pointer-events: auto;
|
|
88
92
|
--webkit-backface-visibility: hidden;
|
|
@@ -112,16 +116,6 @@ const Item = ({ item, sectionId }) => {
|
|
|
112
116
|
` })] }));
|
|
113
117
|
};
|
|
114
118
|
exports.Item = Item;
|
|
115
|
-
function getAnchoredItemTop(top, sectionHeight, anchorSide) {
|
|
116
|
-
const styleTop = `${top * 100}vw`;
|
|
117
|
-
switch (anchorSide) {
|
|
118
|
-
case sdk_1.AnchorSide.Center: return `calc(${styleTop} + ${sectionHeight} / 2)`;
|
|
119
|
-
case sdk_1.AnchorSide.Bottom: return `calc(${styleTop} + ${sectionHeight})`;
|
|
120
|
-
case sdk_1.AnchorSide.Top:
|
|
121
|
-
default:
|
|
122
|
-
return styleTop;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
119
|
function getStickyItemWrapperHeight(sticky, itemHeight) {
|
|
126
120
|
const end = sticky.to ?? 100;
|
|
127
121
|
return end - sticky.from + itemHeight;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useStickyItemTop = void 0;
|
|
4
|
+
const useCurrentLayout_1 = require("../../common/useCurrentLayout");
|
|
5
|
+
const useKeyframeValue_1 = require("../../common/useKeyframeValue");
|
|
6
|
+
const getAnchoredItemTop_1 = require("../../utils/getAnchoredItemTop");
|
|
7
|
+
function useStickyItemTop(item, sectionHeightMap, sectionId) {
|
|
8
|
+
const layoutId = (0, useCurrentLayout_1.useCurrentLayout)();
|
|
9
|
+
const { top } = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => item.area[layoutId], (animator, scroll, value) => animator.getPositions(value, scroll), sectionId, [layoutId]);
|
|
10
|
+
const sticky = item.sticky[layoutId];
|
|
11
|
+
const sectionHeight = sectionHeightMap[layoutId];
|
|
12
|
+
return sticky ? `${(0, getAnchoredItemTop_1.getAnchoredItemTop)(top - sticky.from, sectionHeight, item.area[layoutId].anchorSide)}` : 0;
|
|
13
|
+
}
|
|
14
|
+
exports.useStickyItemTop = useStickyItemTop;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAnchoredItemTop = void 0;
|
|
4
|
+
const sdk_1 = require("@cntrl-site/sdk");
|
|
5
|
+
function getAnchoredItemTop(top, sectionHeight, anchorSide) {
|
|
6
|
+
const styleTop = `${top * 100}vw`;
|
|
7
|
+
switch (anchorSide) {
|
|
8
|
+
case sdk_1.AnchorSide.Center: return `calc(${styleTop} + ${sectionHeight} / 2)`;
|
|
9
|
+
case sdk_1.AnchorSide.Bottom: return `calc(${styleTop} + ${sectionHeight})`;
|
|
10
|
+
case sdk_1.AnchorSide.Top:
|
|
11
|
+
default:
|
|
12
|
+
return styleTop;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.getAnchoredItemTop = getAnchoredItemTop;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntrl-site/sdk-nextjs",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.2",
|
|
4
4
|
"description": "SDK for Next.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://github.com/cntrl-site/sdk-nextjs#readme",
|
|
23
23
|
"dependencies": {
|
|
24
|
+
"@types/vimeo__player": "^2.18.0",
|
|
24
25
|
"@cntrl-site/sdk": "^1.1.8",
|
|
25
26
|
"@vimeo/player": "^2.20.1",
|
|
26
27
|
"html-react-parser": "^3.0.1",
|
|
@@ -39,7 +40,6 @@
|
|
|
39
40
|
"@types/jest": "^29.2.5",
|
|
40
41
|
"@types/node": "^18.11.7",
|
|
41
42
|
"@types/react": "^18.0.15",
|
|
42
|
-
"@types/vimeo__player": "^2.18.0",
|
|
43
43
|
"jest": "^29.3.1",
|
|
44
44
|
"ts-jest": "^29.0.3",
|
|
45
45
|
"typescript": "^4.9.5"
|
package/src/components/Item.tsx
CHANGED
|
@@ -26,6 +26,8 @@ import { ScaleAnchorMap } from '../utils/ScaleAnchorMap';
|
|
|
26
26
|
import { useSectionHeightData } from './useSectionHeightMap';
|
|
27
27
|
import { getHoverStyles, getTransitions } from '../utils/HoverStyles/HoverStyles';
|
|
28
28
|
import { getItemTopStyle } from '../utils/getItemTopStyle';
|
|
29
|
+
import { useStickyItemTop } from './items/useStickyItemTop';
|
|
30
|
+
import { getAnchoredItemTop } from '../utils/getAnchoredItemTop';
|
|
29
31
|
|
|
30
32
|
export interface ItemProps<I extends TArticleItemAny> {
|
|
31
33
|
item: I;
|
|
@@ -52,6 +54,7 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item, sectionId}) => {
|
|
|
52
54
|
const { scale, scaleAnchor } = useItemScale(item, sectionId);
|
|
53
55
|
const { top, left } = useItemPosition(item, sectionId);
|
|
54
56
|
const sectionHeight = useSectionHeightData(sectionId);
|
|
57
|
+
const stickyTop = useStickyItemTop(item, sectionHeight, sectionId);
|
|
55
58
|
const layout = useCurrentLayout();
|
|
56
59
|
const { width, height } = useItemDimensions(item, sectionId);
|
|
57
60
|
const layoutValues: Record<string, any>[] = [item.area, item.hidden, item.state.hover];
|
|
@@ -87,6 +90,7 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item, sectionId}) => {
|
|
|
87
90
|
transformOrigin: ScaleAnchorMap[scaleAnchor],
|
|
88
91
|
width: `${sizingAxis.x === SizingType.Manual ? `${width * 100}vw` : 'max-content'}`,
|
|
89
92
|
height: `${sizingAxis.y === SizingType.Manual ? `${height * 100}vw` : 'unset'}`,
|
|
93
|
+
top: stickyTop
|
|
90
94
|
};
|
|
91
95
|
|
|
92
96
|
return (
|
|
@@ -142,17 +146,6 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item, sectionId}) => {
|
|
|
142
146
|
);
|
|
143
147
|
};
|
|
144
148
|
|
|
145
|
-
function getAnchoredItemTop(top: number, sectionHeight: string, anchorSide: AnchorSide) {
|
|
146
|
-
const styleTop = `${top * 100}vw`;
|
|
147
|
-
switch (anchorSide) {
|
|
148
|
-
case AnchorSide.Center: return `calc(${styleTop} + ${sectionHeight} / 2)`;
|
|
149
|
-
case AnchorSide.Bottom: return `calc(${styleTop} + ${sectionHeight})`;
|
|
150
|
-
case AnchorSide.Top:
|
|
151
|
-
default:
|
|
152
|
-
return styleTop;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
149
|
function getStickyItemWrapperHeight(sticky: TStickyParams, itemHeight: number): number {
|
|
157
150
|
const end = sticky.to ?? 100;
|
|
158
151
|
return end - sticky.from + itemHeight;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TArticleItemAny } from '@cntrl-site/sdk';
|
|
2
|
+
import { useCurrentLayout } from '../../common/useCurrentLayout';
|
|
3
|
+
import { useKeyframeValue } from '../../common/useKeyframeValue';
|
|
4
|
+
import { getAnchoredItemTop } from '../../utils/getAnchoredItemTop';
|
|
5
|
+
|
|
6
|
+
export function useStickyItemTop(item: TArticleItemAny, sectionHeightMap: Record<string, string>, sectionId: string) {
|
|
7
|
+
const layoutId = useCurrentLayout();
|
|
8
|
+
const { top } = useKeyframeValue<{ top: number; left: number }>(
|
|
9
|
+
item,
|
|
10
|
+
(item, layoutId) => item.area[layoutId],
|
|
11
|
+
(animator, scroll, value) => animator.getPositions(value, scroll),
|
|
12
|
+
sectionId,
|
|
13
|
+
[layoutId]
|
|
14
|
+
);
|
|
15
|
+
const sticky = item.sticky[layoutId];
|
|
16
|
+
const sectionHeight = sectionHeightMap[layoutId];
|
|
17
|
+
return sticky ? `${getAnchoredItemTop(top - sticky.from, sectionHeight, item.area[layoutId].anchorSide)}` : 0
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AnchorSide } from '@cntrl-site/sdk';
|
|
2
|
+
|
|
3
|
+
export function getAnchoredItemTop(top: number, sectionHeight: string, anchorSide?: AnchorSide) {
|
|
4
|
+
const styleTop = `${top * 100}vw`;
|
|
5
|
+
switch (anchorSide) {
|
|
6
|
+
case AnchorSide.Center: return `calc(${styleTop} + ${sectionHeight} / 2)`;
|
|
7
|
+
case AnchorSide.Bottom: return `calc(${styleTop} + ${sectionHeight})`;
|
|
8
|
+
case AnchorSide.Top:
|
|
9
|
+
default:
|
|
10
|
+
return styleTop;
|
|
11
|
+
}
|
|
12
|
+
}
|