@cntrl-site/sdk-nextjs 0.14.2 → 0.14.4
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.14.3.tgz +0 -0
- package/cntrl-site-sdk-nextjs-0.14.4.tgz +0 -0
- package/lib/common/useCurrentLayout.js +1 -6
- package/lib/common/useKeyframeValue.js +2 -2
- package/lib/components/Article.js +5 -4
- package/lib/components/ArticleWrapper.js +35 -0
- package/lib/components/Item.js +6 -4
- package/lib/components/items/ImageItem.js +5 -4
- package/lib/components/items/RectangleItem.js +6 -4
- package/lib/components/items/RichTextItem.js +6 -5
- package/lib/components/items/VideoItem.js +5 -4
- package/lib/components/items/VimeoEmbed.js +5 -4
- package/lib/components/items/YoutubeEmbed.js +5 -4
- package/lib/components/items/useEmbedVideoItem.js +9 -3
- package/lib/components/items/useFileItem.js +9 -3
- package/lib/components/items/useRectangleItem.js +15 -3
- package/lib/components/items/useRichTextItem.js +3 -3
- package/lib/components/items/useRichTextItemValues.js +17 -0
- package/lib/components/items/useStickyItemTop.js +12 -6
- package/lib/components/useItemDimensions.js +2 -2
- package/lib/components/useItemPosition.js +10 -4
- package/lib/components/useItemScale.js +5 -4
- package/lib/components/useLayoutContext.js +10 -0
- package/lib/components/useSectionColor.js +5 -3
- package/lib/provider/LayoutContext.js +5 -0
- package/lib/utils/Animator/Animator.js +33 -1
- package/lib/utils/HoverStyles/HoverStyles.js +5 -1
- package/package.json +2 -2
- package/src/common/useCurrentLayout.ts +2 -9
- package/src/common/useKeyframeValue.ts +3 -3
- package/src/components/Article.tsx +15 -12
- package/src/components/ArticleWrapper.tsx +36 -0
- package/src/components/Item.tsx +5 -4
- package/src/components/items/ImageItem.tsx +5 -4
- package/src/components/items/RectangleItem.tsx +6 -4
- package/src/components/items/RichTextItem.tsx +6 -5
- package/src/components/items/VideoItem.tsx +5 -4
- package/src/components/items/VimeoEmbed.tsx +6 -6
- package/src/components/items/YoutubeEmbed.tsx +5 -4
- package/src/components/items/useEmbedVideoItem.ts +15 -4
- package/src/components/items/useFileItem.ts +14 -3
- package/src/components/items/useRectangleItem.ts +25 -3
- package/src/components/items/useRichTextItem.ts +3 -3
- package/src/components/items/useRichTextItemValues.ts +27 -0
- package/src/components/items/useStickyItemTop.ts +11 -7
- package/src/components/useItemDimensions.ts +2 -2
- package/src/components/useItemPosition.ts +8 -4
- package/src/components/useItemScale.ts +6 -5
- package/src/components/useLayoutContext.ts +7 -0
- package/src/components/useSectionColor.ts +4 -3
- package/src/provider/LayoutContext.ts +3 -0
- package/src/utils/Animator/Animator.ts +39 -1
- package/src/utils/HoverStyles/HoverStyles.ts +5 -1
- package/cntrl-site-sdk-nextjs-0.12.9.tgz +0 -0
- package/cntrl-site-sdk-nextjs-0.14.1.tgz +0 -0
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import { TArticleItemAny } from '@cntrl-site/sdk';
|
|
2
|
-
import { useCurrentLayout } from '../../common/useCurrentLayout';
|
|
1
|
+
import { AnchorSide, TArticleItemAny } from '@cntrl-site/sdk';
|
|
3
2
|
import { useKeyframeValue } from '../../common/useKeyframeValue';
|
|
4
3
|
import { getAnchoredItemTop } from '../../utils/getAnchoredItemTop';
|
|
4
|
+
import { useLayoutContext } from '../useLayoutContext';
|
|
5
5
|
|
|
6
6
|
export function useStickyItemTop(item: TArticleItemAny, sectionHeightMap: Record<string, string>, sectionId: string) {
|
|
7
|
-
const layoutId =
|
|
7
|
+
const layoutId = useLayoutContext();
|
|
8
8
|
const { top } = useKeyframeValue<{ top: number; left: number }>(
|
|
9
9
|
item,
|
|
10
|
-
(item, layoutId) =>
|
|
10
|
+
(item, layoutId) => {
|
|
11
|
+
if (!layoutId) return { top: 0, left: 0 }
|
|
12
|
+
return item.area[layoutId];
|
|
13
|
+
},
|
|
11
14
|
(animator, scroll, value) => animator.getPositions(value, scroll),
|
|
12
15
|
sectionId,
|
|
13
16
|
[layoutId]
|
|
14
17
|
);
|
|
15
|
-
const sticky = item.sticky[layoutId];
|
|
16
|
-
const sectionHeight = sectionHeightMap[layoutId];
|
|
17
|
-
|
|
18
|
+
const sticky = layoutId ? item.sticky[layoutId] : undefined;
|
|
19
|
+
const sectionHeight = layoutId ? sectionHeightMap[layoutId] : '0vh';
|
|
20
|
+
const anchorSide = layoutId ? item.area[layoutId].anchorSide : AnchorSide.Top;
|
|
21
|
+
return sticky ? `${getAnchoredItemTop(top - sticky.from, sectionHeight, anchorSide)}` : 0
|
|
18
22
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TArticleItemAny } from '@cntrl-site/sdk';
|
|
2
|
-
import { useCurrentLayout } from '../common/useCurrentLayout';
|
|
3
2
|
import { useKeyframeValue } from '../common/useKeyframeValue';
|
|
3
|
+
import { useLayoutContext } from './useLayoutContext';
|
|
4
4
|
|
|
5
5
|
const defaultArea = {
|
|
6
6
|
left: 0,
|
|
@@ -12,7 +12,7 @@ const defaultArea = {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
export const useItemDimensions = (item: TArticleItemAny, sectionId: string) => {
|
|
15
|
-
const layoutId =
|
|
15
|
+
const layoutId = useLayoutContext();
|
|
16
16
|
const { width, height } = useKeyframeValue<{ width: number; height: number }>(
|
|
17
17
|
item,
|
|
18
18
|
(item, layoutId) => layoutId ? item.area[layoutId] : defaultArea,
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import { AnchorSide, TArticleItemAny } from '@cntrl-site/sdk';
|
|
2
2
|
import { useKeyframeValue } from '../common/useKeyframeValue';
|
|
3
|
-
import { useCurrentLayout } from '../common/useCurrentLayout';
|
|
4
3
|
import { getItemTopStyle } from '../utils/getItemTopStyle';
|
|
4
|
+
import { useLayoutContext } from './useLayoutContext';
|
|
5
5
|
|
|
6
6
|
export const useItemPosition = (item: TArticleItemAny, sectionId: string) => {
|
|
7
|
-
const layoutId =
|
|
7
|
+
const layoutId = useLayoutContext();
|
|
8
8
|
const { top, left } = useKeyframeValue<{ top: number; left: number }>(
|
|
9
9
|
item,
|
|
10
|
-
(item, layoutId) =>
|
|
10
|
+
(item, layoutId) => {
|
|
11
|
+
if (!layoutId) return { top: 0, left: -10 };
|
|
12
|
+
return item.area[layoutId]
|
|
13
|
+
},
|
|
11
14
|
(animator, scroll, value) => animator.getPositions(value, scroll),
|
|
12
15
|
sectionId,
|
|
13
16
|
[layoutId]
|
|
14
17
|
);
|
|
18
|
+
const anchorSide = layoutId ? item.area[layoutId].anchorSide : AnchorSide.Top;
|
|
15
19
|
return {
|
|
16
|
-
top: getItemTopStyle(top,
|
|
20
|
+
top: getItemTopStyle(top, anchorSide),
|
|
17
21
|
left: `${left * 100}vw`
|
|
18
22
|
};
|
|
19
23
|
};
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { TArticleItemAny } from '@cntrl-site/sdk';
|
|
1
|
+
import { ScaleAnchor, TArticleItemAny } from '@cntrl-site/sdk';
|
|
2
2
|
import { useKeyframeValue } from '../common/useKeyframeValue';
|
|
3
|
-
import {
|
|
3
|
+
import { useLayoutContext } from './useLayoutContext';
|
|
4
4
|
|
|
5
5
|
export const useItemScale = (item: TArticleItemAny, sectionId: string) => {
|
|
6
|
-
const
|
|
6
|
+
const layoutId = useLayoutContext();
|
|
7
7
|
const { scale } = useKeyframeValue(
|
|
8
8
|
item,
|
|
9
9
|
(item, layoutId) => ({ scale: layoutId ? item.area[layoutId].scale : 1 }),
|
|
10
10
|
(animator, scroll, value) => animator.getScale(value, scroll),
|
|
11
|
-
sectionId
|
|
11
|
+
sectionId,
|
|
12
|
+
[layoutId]
|
|
12
13
|
);
|
|
13
|
-
const scaleAnchor = item.area[
|
|
14
|
+
const scaleAnchor = layoutId ? item.area[layoutId].scaleAnchor : ScaleAnchor.MiddleCenter;
|
|
14
15
|
|
|
15
16
|
return { scale, scaleAnchor };
|
|
16
17
|
};
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { useCurrentLayout } from '../common/useCurrentLayout';
|
|
2
1
|
import { useMemo } from 'react';
|
|
3
2
|
import { CntrlColor } from '@cntrl-site/sdk';
|
|
3
|
+
import { useLayoutContext } from './useLayoutContext';
|
|
4
4
|
|
|
5
5
|
type LayoutIdentifier = string;
|
|
6
6
|
const DEFAULT_COLOR = 'rgba(0, 0, 0, 0)';
|
|
7
7
|
|
|
8
8
|
export const useSectionColor = (colorData: Record<LayoutIdentifier, string | null>): CntrlColor => {
|
|
9
|
-
const layoutId =
|
|
9
|
+
const layoutId = useLayoutContext();
|
|
10
10
|
return useMemo(() => {
|
|
11
|
+
if (!layoutId) return CntrlColor.parse(DEFAULT_COLOR);
|
|
11
12
|
const layoutColor = colorData[layoutId];
|
|
12
13
|
return CntrlColor.parse(
|
|
13
14
|
!layoutColor
|
|
14
15
|
? DEFAULT_COLOR
|
|
15
16
|
: layoutColor
|
|
16
17
|
);
|
|
17
|
-
}, []);
|
|
18
|
+
}, [layoutId]);
|
|
18
19
|
};
|
|
@@ -196,6 +196,42 @@ export class Animator {
|
|
|
196
196
|
};
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
+
getBlur(
|
|
200
|
+
values: TKeyframeValueMap[KeyframeType.Blur],
|
|
201
|
+
pos: number
|
|
202
|
+
): TKeyframeValueMap[KeyframeType.Blur] {
|
|
203
|
+
const keyframes = this.keyframesMap[KeyframeType.Blur];
|
|
204
|
+
if (!keyframes || !keyframes.length) return values;
|
|
205
|
+
if (keyframes.length === 1) {
|
|
206
|
+
const [keyframe] = keyframes;
|
|
207
|
+
return {
|
|
208
|
+
blur: keyframe.value.blur
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
const { start, end } = this.getStartEnd<KeyframeType.Blur>(pos, keyframes);
|
|
212
|
+
return {
|
|
213
|
+
blur: rangeMap(pos, start.position, end.position, start.value.blur, end.value.blur, true)
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
getBackdropBlur(
|
|
218
|
+
values: TKeyframeValueMap[KeyframeType.BackdropBlur],
|
|
219
|
+
pos: number
|
|
220
|
+
): TKeyframeValueMap[KeyframeType.BackdropBlur] {
|
|
221
|
+
const keyframes = this.keyframesMap[KeyframeType.BackdropBlur];
|
|
222
|
+
if (!keyframes || !keyframes.length) return values;
|
|
223
|
+
if (keyframes.length === 1) {
|
|
224
|
+
const [keyframe] = keyframes;
|
|
225
|
+
return {
|
|
226
|
+
backdropBlur: keyframe.value.backdropBlur
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
const { start, end } = this.getStartEnd<KeyframeType.BackdropBlur>(pos, keyframes);
|
|
230
|
+
return {
|
|
231
|
+
backdropBlur: rangeMap(pos, start.position, end.position, start.value.backdropBlur, end.value.backdropBlur, true)
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
199
235
|
getStartEnd<T extends KeyframeType>(position: number, keyframes: AnimationData<T>[]): PositionKeyframes<T> {
|
|
200
236
|
const index = binSearchInsertAt(keyframes, { position }, compare);
|
|
201
237
|
const end = index === keyframes.length ? index - 1 : index;
|
|
@@ -234,7 +270,9 @@ function createKeyframesMap(): KeyframesMap {
|
|
|
234
270
|
[KeyframeType.Rotation]: [],
|
|
235
271
|
[KeyframeType.BorderColor]: [],
|
|
236
272
|
[KeyframeType.Opacity]: [],
|
|
237
|
-
[KeyframeType.Scale]: []
|
|
273
|
+
[KeyframeType.Scale]: [],
|
|
274
|
+
[KeyframeType.Blur]: [],
|
|
275
|
+
[KeyframeType.BackdropBlur]: []
|
|
238
276
|
};
|
|
239
277
|
}
|
|
240
278
|
|
|
@@ -17,6 +17,8 @@ const hoverTransformationMap: Record<keyof ItemHoverParams, HoverParamsGetter> =
|
|
|
17
17
|
'strokeWidth': (strokeWidth: number) => `border-width: ${strokeWidth * 100}vw !important;`,
|
|
18
18
|
'strokeColor': (strokeColor: string) => `border-color: ${CntrlColor.parse(strokeColor).toCss()} !important;`,
|
|
19
19
|
'fillColor': (fillColor: string) => `background-color: ${CntrlColor.parse(fillColor).toCss()} !important;`,
|
|
20
|
+
'blur': (blur: number) => `filter: blur(${blur * 100}vw) !important;`,
|
|
21
|
+
'backdropBlur': (backdropBlur: number) => `backdrop-filter: blur(${backdropBlur * 100}vw) !important;`
|
|
20
22
|
};
|
|
21
23
|
|
|
22
24
|
const CSSPropertyNameMap: Record<keyof ItemHoverParams, string> = {
|
|
@@ -30,7 +32,9 @@ const CSSPropertyNameMap: Record<keyof ItemHoverParams, string> = {
|
|
|
30
32
|
'radius': 'border-radius',
|
|
31
33
|
'strokeWidth': 'border-width',
|
|
32
34
|
'strokeColor': 'border-color',
|
|
33
|
-
'fillColor': 'background-color'
|
|
35
|
+
'fillColor': 'background-color',
|
|
36
|
+
'blur': 'filter',
|
|
37
|
+
'backdropBlur': 'backdrop-filter'
|
|
34
38
|
};
|
|
35
39
|
|
|
36
40
|
export function getTransitions<T extends ArticleItemType>(
|
|
Binary file
|
|
Binary file
|