@cntrl-site/sdk-nextjs 1.5.0 → 1.5.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/lib/components/items/GroupItem/GroupItem.js +5 -4
- package/lib/components/items/GroupItem/useGroupItem.js +7 -1
- package/lib/utils/getValidYoutubeUrl.js +15 -6
- package/package.json +2 -2
- package/src/components/items/GroupItem/GroupItem.tsx +4 -2
- package/src/components/items/GroupItem/useGroupItem.ts +14 -1
- package/src/utils/getValidYoutubeUrl.ts +14 -6
|
@@ -16,23 +16,24 @@ const useItemAngle_1 = require("../useItemAngle");
|
|
|
16
16
|
const useGroupItem_1 = require("./useGroupItem");
|
|
17
17
|
const getStyleFromItemStateAndParams_1 = require("../../../utils/getStyleFromItemStateAndParams");
|
|
18
18
|
const GroupItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
|
|
19
|
-
var _a, _b, _c, _d, _e;
|
|
19
|
+
var _a, _b, _c, _d, _e, _f;
|
|
20
20
|
const id = (0, react_1.useId)();
|
|
21
21
|
const { items } = item;
|
|
22
22
|
const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
23
23
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
24
|
-
const { opacity: itemOpacity } = (0, useGroupItem_1.useGroupItem)(item, sectionId);
|
|
24
|
+
const { opacity: itemOpacity, blur: itemBlur } = (0, useGroupItem_1.useGroupItem)(item, sectionId);
|
|
25
25
|
const layoutValues = [item.area, item.layoutParams];
|
|
26
26
|
const [ref, setRef] = (0, react_1.useState)(null);
|
|
27
27
|
(0, useRegisterResize_1.useRegisterResize)(ref, onResize);
|
|
28
|
-
const stateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['opacity', 'angle']);
|
|
28
|
+
const stateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['opacity', 'angle', 'blur']);
|
|
29
29
|
const angle = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_a = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) === null || _a === void 0 ? void 0 : _a.angle, itemAngle);
|
|
30
30
|
const opacity = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_b = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) === null || _b === void 0 ? void 0 : _b.opacity, itemOpacity);
|
|
31
|
+
const blur = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_c = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) === null || _c === void 0 ? void 0 : _c.blur, itemBlur);
|
|
31
32
|
const isInteractive = opacity !== 0 && opacity !== undefined;
|
|
32
33
|
(0, react_1.useEffect)(() => {
|
|
33
34
|
onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(isInteractive);
|
|
34
35
|
}, [isInteractive, onVisibilityChange]);
|
|
35
|
-
return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: (
|
|
36
|
+
return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: (_d = item.link) === null || _d === void 0 ? void 0 : _d.url, target: (_e = item.link) === null || _e === void 0 ? void 0 : _e.target, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `group-${item.id}`, ref: setRef, style: Object.assign(Object.assign(Object.assign(Object.assign({}, (opacity !== undefined ? { opacity } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), { transition: (_f = stateParams === null || stateParams === void 0 ? void 0 : stateParams.transition) !== null && _f !== void 0 ? _f : 'none' }), children: items && items.map(item => ((0, jsx_runtime_1.jsx)(Item_1.Item, { item: item, sectionId: sectionId, isParentVisible: isInteractive, isInGroup: true }, item.id))) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
36
37
|
.group-${item.id} {
|
|
37
38
|
position: absolute;
|
|
38
39
|
width: 100%;
|
|
@@ -12,6 +12,12 @@ function useGroupItem(item, sectionId) {
|
|
|
12
12
|
const layoutParams = item.layoutParams[layoutId];
|
|
13
13
|
return 'opacity' in layoutParams ? layoutParams.opacity : 1;
|
|
14
14
|
}, (animator, scroll, value) => value !== undefined ? animator.getOpacity({ opacity: value }, scroll).opacity : undefined, sectionId, [layoutId]);
|
|
15
|
-
|
|
15
|
+
const blur = (0, useKeyframeValue_1.useKeyframeValue)(item, sdk_1.KeyframeType.Blur, (item, layoutId) => {
|
|
16
|
+
if (!layoutId)
|
|
17
|
+
return;
|
|
18
|
+
const layoutParams = item.layoutParams[layoutId];
|
|
19
|
+
return 'blur' in layoutParams ? layoutParams.blur : 0;
|
|
20
|
+
}, (animator, scroll, value) => value !== undefined ? animator.getBlur({ blur: value }, scroll).blur : undefined, sectionId, [layoutId]);
|
|
21
|
+
return { opacity, blur };
|
|
16
22
|
}
|
|
17
23
|
exports.useGroupItem = useGroupItem;
|
|
@@ -8,18 +8,27 @@ var Allowed;
|
|
|
8
8
|
})(Allowed || (Allowed = {}));
|
|
9
9
|
function getYoutubeId({ hostname, pathname, search }) {
|
|
10
10
|
if (hostname !== Allowed.Full && hostname !== Allowed.Tiny) {
|
|
11
|
-
throw new Error(`Cannot get valid
|
|
11
|
+
throw new Error(`Cannot get valid YouTube ID from "${hostname}" - address is not whitelisted`);
|
|
12
12
|
}
|
|
13
13
|
switch (hostname) {
|
|
14
14
|
case Allowed.Tiny:
|
|
15
15
|
return pathname.replace('/', '');
|
|
16
16
|
case Allowed.Full:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
if (pathname.startsWith('/shorts/')) {
|
|
18
|
+
const shortsId = pathname.split('/shorts/')[1];
|
|
19
|
+
if (!shortsId) {
|
|
20
|
+
throw new Error('Cannot get valid YouTube Shorts ID from the pathname.');
|
|
21
|
+
}
|
|
22
|
+
return shortsId;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const searchParams = new URLSearchParams(search);
|
|
26
|
+
const id = searchParams.get('v');
|
|
27
|
+
if (!id) {
|
|
28
|
+
throw new Error('Cannot get valid YouTube ID from search params.');
|
|
29
|
+
}
|
|
30
|
+
return id;
|
|
21
31
|
}
|
|
22
|
-
return id;
|
|
23
32
|
}
|
|
24
33
|
}
|
|
25
34
|
exports.getYoutubeId = getYoutubeId;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntrl-site/sdk-nextjs",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "SDK for Next.js",
|
|
5
5
|
"author": "arsen@momdesign.nyc",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@antfu/eslint-config": "^3.8.0",
|
|
32
32
|
"@cntrl-site/color": "^1.0.0",
|
|
33
33
|
"@cntrl-site/effects": "^1.3.2",
|
|
34
|
-
"@cntrl-site/sdk": "^1.
|
|
34
|
+
"@cntrl-site/sdk": "^1.19.0",
|
|
35
35
|
"@types/vimeo__player": "^2.18.0",
|
|
36
36
|
"@vimeo/player": "^2.25.0",
|
|
37
37
|
"html-react-parser": "^3.0.1",
|
|
@@ -14,13 +14,14 @@ export const GroupItem: FC<ItemProps<TGroupItem>> = ({ item, sectionId, onResize
|
|
|
14
14
|
const { items } = item;
|
|
15
15
|
const itemAngle = useItemAngle(item, sectionId);
|
|
16
16
|
const { layouts } = useCntrlContext();
|
|
17
|
-
const { opacity: itemOpacity } = useGroupItem(item, sectionId);
|
|
17
|
+
const { opacity: itemOpacity, blur: itemBlur } = useGroupItem(item, sectionId);
|
|
18
18
|
const layoutValues: Record<string, any>[] = [item.area, item.layoutParams];
|
|
19
19
|
const [ref, setRef] = useState<HTMLDivElement | null>(null);
|
|
20
20
|
useRegisterResize(ref, onResize);
|
|
21
|
-
const stateParams = interactionCtrl?.getState(['opacity', 'angle']);
|
|
21
|
+
const stateParams = interactionCtrl?.getState(['opacity', 'angle', 'blur']);
|
|
22
22
|
const angle = getStyleFromItemStateAndParams(stateParams?.styles?.angle, itemAngle);
|
|
23
23
|
const opacity = getStyleFromItemStateAndParams(stateParams?.styles?.opacity, itemOpacity);
|
|
24
|
+
const blur = getStyleFromItemStateAndParams(stateParams?.styles?.blur, itemBlur);
|
|
24
25
|
const isInteractive = opacity !== 0 && opacity !== undefined;
|
|
25
26
|
useEffect(() => {
|
|
26
27
|
onVisibilityChange?.(isInteractive);
|
|
@@ -34,6 +35,7 @@ export const GroupItem: FC<ItemProps<TGroupItem>> = ({ item, sectionId, onResize
|
|
|
34
35
|
style={{
|
|
35
36
|
...(opacity !== undefined ? { opacity } : {}),
|
|
36
37
|
...(angle !== undefined ? { transform: `rotate(${angle}deg)` } : {}),
|
|
38
|
+
...(blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {}),
|
|
37
39
|
transition: stateParams?.transition ?? 'none'
|
|
38
40
|
}}
|
|
39
41
|
>
|
|
@@ -17,5 +17,18 @@ export function useGroupItem(item: GroupItem, sectionId: string) {
|
|
|
17
17
|
[layoutId]
|
|
18
18
|
);
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
const blur = useKeyframeValue(
|
|
21
|
+
item,
|
|
22
|
+
KeyframeType.Blur,
|
|
23
|
+
(item, layoutId) => {
|
|
24
|
+
if (!layoutId) return;
|
|
25
|
+
const layoutParams = item.layoutParams[layoutId];
|
|
26
|
+
return 'blur' in layoutParams ? layoutParams.blur : 0;
|
|
27
|
+
},
|
|
28
|
+
(animator, scroll, value) => value !== undefined ? animator.getBlur({ blur: value }, scroll).blur : undefined,
|
|
29
|
+
sectionId,
|
|
30
|
+
[layoutId]
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
return { opacity, blur };
|
|
21
34
|
}
|
|
@@ -5,17 +5,25 @@ enum Allowed {
|
|
|
5
5
|
|
|
6
6
|
export function getYoutubeId({ hostname, pathname, search }: URL): string {
|
|
7
7
|
if (hostname !== Allowed.Full && hostname !== Allowed.Tiny) {
|
|
8
|
-
throw new Error(`Cannot get valid
|
|
8
|
+
throw new Error(`Cannot get valid YouTube ID from "${hostname}" - address is not whitelisted`);
|
|
9
9
|
}
|
|
10
10
|
switch (hostname) {
|
|
11
11
|
case Allowed.Tiny:
|
|
12
12
|
return pathname.replace('/', '');
|
|
13
13
|
case Allowed.Full:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
if (pathname.startsWith('/shorts/')) {
|
|
15
|
+
const shortsId = pathname.split('/shorts/')[1];
|
|
16
|
+
if (!shortsId) {
|
|
17
|
+
throw new Error('Cannot get valid YouTube Shorts ID from the pathname.');
|
|
18
|
+
}
|
|
19
|
+
return shortsId;
|
|
20
|
+
} else {
|
|
21
|
+
const searchParams = new URLSearchParams(search);
|
|
22
|
+
const id = searchParams.get('v');
|
|
23
|
+
if (!id) {
|
|
24
|
+
throw new Error('Cannot get valid YouTube ID from search params.');
|
|
25
|
+
}
|
|
26
|
+
return id;
|
|
18
27
|
}
|
|
19
|
-
return id;
|
|
20
28
|
}
|
|
21
29
|
}
|