@cntrl-site/sdk-nextjs 0.27.2 → 0.28.1
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/ImageItem.js +11 -5
- package/lib/components/items/VideoItem.js +9 -5
- package/lib/utils/effects/useImageFx.js +3 -3
- package/package.json +2 -2
- package/src/components/items/ImageItem.tsx +18 -7
- package/src/components/items/VideoItem.tsx +31 -21
- package/src/utils/effects/useImageFx.ts +8 -3
|
@@ -17,6 +17,7 @@ const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
|
|
|
17
17
|
const useRegisterResize_1 = require("../../common/useRegisterResize");
|
|
18
18
|
const useImageFx_1 = require("../../utils/effects/useImageFx");
|
|
19
19
|
const useElementRect_1 = require("../../utils/useElementRect");
|
|
20
|
+
const useLayoutContext_1 = require("../useLayoutContext");
|
|
20
21
|
const baseVariables = `precision mediump float;
|
|
21
22
|
uniform sampler2D u_image;
|
|
22
23
|
uniform sampler2D u_pattern;
|
|
@@ -26,9 +27,10 @@ uniform float u_time;
|
|
|
26
27
|
uniform vec2 u_cursor;
|
|
27
28
|
varying vec2 v_texCoord;`;
|
|
28
29
|
const ImageItem = ({ item, sectionId, onResize }) => {
|
|
29
|
-
var _a, _b, _c, _d, _e;
|
|
30
|
+
var _a, _b, _c, _d, _e, _f;
|
|
30
31
|
const id = (0, react_1.useId)();
|
|
31
32
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
33
|
+
const layoutId = (0, useLayoutContext_1.useLayoutContext)();
|
|
32
34
|
const { radius, strokeWidth, opacity, strokeColor, blur } = (0, useFileItem_1.useFileItem)(item, sectionId);
|
|
33
35
|
const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
34
36
|
const borderColor = (0, react_1.useMemo)(() => color_1.CntrlColor.parse(strokeColor), [strokeColor]);
|
|
@@ -44,21 +46,25 @@ const ImageItem = ({ item, sectionId, onResize }) => {
|
|
|
44
46
|
return acc;
|
|
45
47
|
}, {});
|
|
46
48
|
const fullShaderCode = `${baseVariables}\n${controlsVariables}\n${fragmentShader}`;
|
|
49
|
+
const area = layoutId ? item.area[layoutId] : null;
|
|
50
|
+
const exemplary = (_b = layouts === null || layouts === void 0 ? void 0 : layouts.find(l => l.id === layoutId)) === null || _b === void 0 ? void 0 : _b.exemplary;
|
|
51
|
+
const width = area && exemplary ? area.width * exemplary : 0;
|
|
52
|
+
const height = area && exemplary ? area.height * exemplary : 0;
|
|
47
53
|
(0, useImageFx_1.useImageFx)(fxCanvas.current, hasGLEffect !== null && hasGLEffect !== void 0 ? hasGLEffect : false, {
|
|
48
54
|
imageUrl: url,
|
|
49
55
|
fragmentShader: fullShaderCode,
|
|
50
56
|
cursor: item.commonParams.FXCursor,
|
|
51
57
|
controls: controlValues
|
|
52
|
-
});
|
|
58
|
+
}, width, height);
|
|
53
59
|
const rect = (0, useElementRect_1.useElementRect)(ref);
|
|
54
|
-
const rectWidth = Math.floor((
|
|
55
|
-
const rectHeight = Math.floor((
|
|
60
|
+
const rectWidth = Math.floor((_c = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _c !== void 0 ? _c : 0);
|
|
61
|
+
const rectHeight = Math.floor((_d = rect === null || rect === void 0 ? void 0 : rect.height) !== null && _d !== void 0 ? _d : 0);
|
|
56
62
|
const inlineStyles = {
|
|
57
63
|
borderRadius: `${radius * 100}vw`,
|
|
58
64
|
borderWidth: `${strokeWidth * 100}vw`,
|
|
59
65
|
borderColor: `${borderColor.toCss()}`
|
|
60
66
|
};
|
|
61
|
-
return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: (
|
|
67
|
+
return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: (_e = item.link) === null || _e === void 0 ? void 0 : _e.url, target: (_f = item.link) === null || _f === void 0 ? void 0 : _f.target, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `image-wrapper-${item.id}`, ref: setRef, style: {
|
|
62
68
|
opacity: `${opacity}`,
|
|
63
69
|
transform: `rotate(${angle}deg)`,
|
|
64
70
|
filter: `blur(${blur * 100}vw)`
|
|
@@ -30,20 +30,24 @@ const VideoItem = ({ item, sectionId, onResize }) => {
|
|
|
30
30
|
const scrollPlayback = item.layoutParams[layoutId].scrollPlayback;
|
|
31
31
|
const hasScrollPlayback = scrollPlayback !== null;
|
|
32
32
|
(0, useRegisterResize_1.useRegisterResize)(ref, onResize);
|
|
33
|
-
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: (_a = item.link) === null || _a === void 0 ? void 0 : _a.url, target: (_b = item.link) === null || _b === void 0 ? void 0 : _b.target, children: [(0, jsx_runtime_1.jsx)("div", { className: `video-wrapper-${item.id}`, ref: setRef, style: {
|
|
33
|
+
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: (_a = item.link) === null || _a === void 0 ? void 0 : _a.url, target: (_b = item.link) === null || _b === void 0 ? void 0 : _b.target, children: [hasScrollPlayback ? ((0, jsx_runtime_1.jsx)("div", { className: `video-wrapper-${item.id}`, ref: setRef, style: {
|
|
34
34
|
opacity: `${opacity}`,
|
|
35
35
|
transform: `rotate(${angle}deg)`,
|
|
36
36
|
filter: `blur(${blur * 100}vw)`,
|
|
37
|
-
overflow:
|
|
38
|
-
}, children:
|
|
37
|
+
overflow: 'hidden'
|
|
38
|
+
}, children: (0, jsx_runtime_1.jsx)(ScrollPlaybackVideo_1.ScrollPlaybackVideo, { sectionId: sectionId, src: item.commonParams.url, playbackParams: scrollPlayback, style: {
|
|
39
39
|
borderRadius: `${radius * 100}vw`,
|
|
40
40
|
borderWidth: `${strokeWidth * 100}vw`,
|
|
41
41
|
borderColor: `${borderColor.toCss()}`
|
|
42
|
-
}, className: `video video-playback-wrapper video-${item.id}` })) : ((0, jsx_runtime_1.jsx)("
|
|
42
|
+
}, className: `video video-playback-wrapper video-${item.id}` }) })) : ((0, jsx_runtime_1.jsx)("div", { className: `video-wrapper-${item.id}`, ref: setRef, style: {
|
|
43
|
+
opacity: `${opacity}`,
|
|
44
|
+
transform: `rotate(${angle}deg)`,
|
|
45
|
+
filter: `blur(${blur * 100}vw)`
|
|
46
|
+
}, children: (0, jsx_runtime_1.jsx)("video", { ref: videoRef, autoPlay: true, muted: true, loop: true, playsInline: true, className: `video video-${item.id}`, style: {
|
|
43
47
|
borderRadius: `${radius * 100}vw`,
|
|
44
48
|
borderWidth: `${strokeWidth * 100}vw`,
|
|
45
49
|
borderColor: `${borderColor.toCss()}`
|
|
46
|
-
}, children: (0, jsx_runtime_1.jsx)("source", { src: item.commonParams.url }) })
|
|
50
|
+
}, children: (0, jsx_runtime_1.jsx)("source", { src: item.commonParams.url }) }) })), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
47
51
|
@supports not (color: oklch(42% 0.3 90 / 1)) {
|
|
48
52
|
.video-${item.id} {
|
|
49
53
|
border-color: ${borderColor.fmt('rgba')};
|
|
@@ -6,14 +6,14 @@ const effects_1 = require("@cntrl-site/effects");
|
|
|
6
6
|
const rangeMap_1 = require("../rangeMap");
|
|
7
7
|
const PATTERN_URL = 'https://cdn.cntrl.site/client-app-files/texture2.png';
|
|
8
8
|
const PATTERN_2_URL = 'https://cdn.cntrl.site/client-app-files/bayer16.png';
|
|
9
|
-
function useImageFx(canvas, enabled, { imageUrl, fragmentShader, cursor, controls }) {
|
|
9
|
+
function useImageFx(canvas, enabled, { imageUrl, fragmentShader, cursor, controls }, width, height) {
|
|
10
10
|
const mousePos = (0, react_1.useRef)([0.0, 0.0]);
|
|
11
11
|
const imageFx = (0, react_1.useMemo)(() => {
|
|
12
12
|
if (!imageUrl || !cursor)
|
|
13
13
|
return undefined;
|
|
14
14
|
const { type, x, y } = cursor;
|
|
15
|
-
return new effects_1.ImageEffect(imageUrl, PATTERN_URL, PATTERN_2_URL, fragmentShader, Object.assign({ time: 0, cursor: type === 'mouse' ? mousePos.current : [x, y] }, controls));
|
|
16
|
-
}, [imageUrl, fragmentShader]);
|
|
15
|
+
return new effects_1.ImageEffect(imageUrl, PATTERN_URL, PATTERN_2_URL, fragmentShader, Object.assign({ time: 0, cursor: type === 'mouse' ? mousePos.current : [x, y] }, controls), width, height);
|
|
16
|
+
}, [imageUrl, fragmentShader, width, height]);
|
|
17
17
|
(0, react_1.useEffect)(() => {
|
|
18
18
|
if (!cursor || cursor.type !== 'mouse' || !canvas || !imageFx)
|
|
19
19
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntrl-site/sdk-nextjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.1",
|
|
4
4
|
"description": "SDK for Next.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"homepage": "https://github.com/cntrl-site/sdk-nextjs#readme",
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@cntrl-site/color": "^1.0.0",
|
|
25
|
-
"@cntrl-site/effects": "^1.
|
|
25
|
+
"@cntrl-site/effects": "^1.2.0",
|
|
26
26
|
"@cntrl-site/sdk": "^1.9.1",
|
|
27
27
|
"@types/vimeo__player": "^2.18.0",
|
|
28
28
|
"@vimeo/player": "^2.20.1",
|
|
@@ -11,6 +11,7 @@ import { getHoverStyles, getTransitions } from '../../utils/HoverStyles/HoverSty
|
|
|
11
11
|
import { useRegisterResize } from "../../common/useRegisterResize";
|
|
12
12
|
import { useImageFx } from '../../utils/effects/useImageFx';
|
|
13
13
|
import { useElementRect } from '../../utils/useElementRect';
|
|
14
|
+
import { useLayoutContext } from '../useLayoutContext';
|
|
14
15
|
|
|
15
16
|
const baseVariables = `precision mediump float;
|
|
16
17
|
uniform sampler2D u_image;
|
|
@@ -24,6 +25,7 @@ varying vec2 v_texCoord;`;
|
|
|
24
25
|
export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize }) => {
|
|
25
26
|
const id = useId();
|
|
26
27
|
const { layouts } = useCntrlContext();
|
|
28
|
+
const layoutId = useLayoutContext();
|
|
27
29
|
const { radius, strokeWidth, opacity, strokeColor, blur } = useFileItem(item, sectionId);
|
|
28
30
|
const angle = useItemAngle(item, sectionId);
|
|
29
31
|
const borderColor = useMemo(() => CntrlColor.parse(strokeColor), [strokeColor]);
|
|
@@ -39,12 +41,22 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
|
|
|
39
41
|
return acc;
|
|
40
42
|
}, {});
|
|
41
43
|
const fullShaderCode = `${baseVariables}\n${controlsVariables}\n${fragmentShader}`;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
const area = layoutId ? item.area[layoutId] : null;
|
|
45
|
+
const exemplary = layouts?.find(l => l.id === layoutId)?.exemplary;
|
|
46
|
+
const width = area && exemplary ? area.width * exemplary : 0;
|
|
47
|
+
const height = area && exemplary ? area.height * exemplary : 0;
|
|
48
|
+
useImageFx(
|
|
49
|
+
fxCanvas.current,
|
|
50
|
+
hasGLEffect ?? false,
|
|
51
|
+
{
|
|
52
|
+
imageUrl: url,
|
|
53
|
+
fragmentShader: fullShaderCode,
|
|
54
|
+
cursor: item.commonParams.FXCursor,
|
|
55
|
+
controls: controlValues
|
|
56
|
+
},
|
|
57
|
+
width,
|
|
58
|
+
height
|
|
59
|
+
);
|
|
48
60
|
const rect = useElementRect(ref);
|
|
49
61
|
const rectWidth = Math.floor(rect?.width ?? 0);
|
|
50
62
|
const rectHeight = Math.floor(rect?.height ?? 0);
|
|
@@ -81,7 +93,6 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
|
|
|
81
93
|
src={item.commonParams.url}
|
|
82
94
|
/>
|
|
83
95
|
)}
|
|
84
|
-
|
|
85
96
|
</div>
|
|
86
97
|
<JSXStyle id={id}>{`
|
|
87
98
|
@supports not (color: oklch(42% 0.3 90 / 1)) {
|
|
@@ -28,17 +28,17 @@ export const VideoItem: FC<ItemProps<TVideoItem>> = ({ item, sectionId, onResize
|
|
|
28
28
|
|
|
29
29
|
return (
|
|
30
30
|
<LinkWrapper url={item.link?.url} target={item.link?.target}>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
31
|
+
{hasScrollPlayback ? (
|
|
32
|
+
<div
|
|
33
|
+
className={`video-wrapper-${item.id}`}
|
|
34
|
+
ref={setRef}
|
|
35
|
+
style={{
|
|
36
|
+
opacity: `${opacity}`,
|
|
37
|
+
transform: `rotate(${angle}deg)`,
|
|
38
|
+
filter: `blur(${blur * 100}vw)`,
|
|
39
|
+
overflow: 'hidden'
|
|
40
|
+
}}
|
|
41
|
+
>
|
|
42
42
|
<ScrollPlaybackVideo
|
|
43
43
|
sectionId={sectionId}
|
|
44
44
|
src={item.commonParams.url}
|
|
@@ -50,7 +50,17 @@ export const VideoItem: FC<ItemProps<TVideoItem>> = ({ item, sectionId, onResize
|
|
|
50
50
|
}}
|
|
51
51
|
className={`video video-playback-wrapper video-${item.id}`}
|
|
52
52
|
/>
|
|
53
|
-
|
|
53
|
+
</div>
|
|
54
|
+
) : (
|
|
55
|
+
<div
|
|
56
|
+
className={`video-wrapper-${item.id}`}
|
|
57
|
+
ref={setRef}
|
|
58
|
+
style={{
|
|
59
|
+
opacity: `${opacity}`,
|
|
60
|
+
transform: `rotate(${angle}deg)`,
|
|
61
|
+
filter: `blur(${blur * 100}vw)`
|
|
62
|
+
}}
|
|
63
|
+
>
|
|
54
64
|
<video
|
|
55
65
|
ref={videoRef}
|
|
56
66
|
autoPlay
|
|
@@ -59,15 +69,15 @@ export const VideoItem: FC<ItemProps<TVideoItem>> = ({ item, sectionId, onResize
|
|
|
59
69
|
playsInline
|
|
60
70
|
className={`video video-${item.id}`}
|
|
61
71
|
style={{
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
borderRadius: `${radius * 100}vw`,
|
|
73
|
+
borderWidth: `${strokeWidth * 100}vw`,
|
|
74
|
+
borderColor: `${borderColor.toCss()}`
|
|
75
|
+
}}
|
|
76
|
+
>
|
|
77
|
+
<source src={item.commonParams.url} />
|
|
78
|
+
</video>
|
|
79
|
+
</div>
|
|
80
|
+
)}
|
|
71
81
|
<JSXStyle id={id}>{`
|
|
72
82
|
@supports not (color: oklch(42% 0.3 90 / 1)) {
|
|
73
83
|
.video-${item.id} {
|
|
@@ -27,7 +27,9 @@ export function useImageFx(
|
|
|
27
27
|
fragmentShader,
|
|
28
28
|
cursor,
|
|
29
29
|
controls
|
|
30
|
-
}: FxParams
|
|
30
|
+
}: FxParams,
|
|
31
|
+
width: number,
|
|
32
|
+
height: number
|
|
31
33
|
): void {
|
|
32
34
|
const mousePos = useRef<[number, number]>([0.0, 0.0]);
|
|
33
35
|
const imageFx = useMemo<ImageEffect | undefined>(() => {
|
|
@@ -42,8 +44,11 @@ export function useImageFx(
|
|
|
42
44
|
time: 0,
|
|
43
45
|
cursor: type === 'mouse' ? mousePos.current : [x, y],
|
|
44
46
|
...controls
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
+
},
|
|
48
|
+
width,
|
|
49
|
+
height
|
|
50
|
+
);
|
|
51
|
+
}, [imageUrl, fragmentShader, width, height]);
|
|
47
52
|
|
|
48
53
|
useEffect(() => {
|
|
49
54
|
if (!cursor || cursor.type !== 'mouse' || !canvas || !imageFx) return;
|