@cntrl-site/sdk-nextjs 0.20.1 → 0.21.0
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.
|
@@ -30,7 +30,8 @@ const ImageItem = ({ item, sectionId, onResize }) => {
|
|
|
30
30
|
const fxCanvas = (0, react_1.useRef)(null);
|
|
31
31
|
(0, useImageFx_1.useImageFx)(fxCanvas.current, hasGLEffect !== null && hasGLEffect !== void 0 ? hasGLEffect : false, {
|
|
32
32
|
imageUrl: url,
|
|
33
|
-
fragmentShader
|
|
33
|
+
fragmentShader,
|
|
34
|
+
cursor: item.commonParams.FXCursor
|
|
34
35
|
});
|
|
35
36
|
const rect = (0, useElementRect_1.useElementRect)(ref);
|
|
36
37
|
const rectWidth = Math.floor((_a = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _a !== void 0 ? _a : 0);
|
|
@@ -6,15 +6,19 @@ 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 }) {
|
|
10
|
-
const
|
|
9
|
+
function useImageFx(canvas, enabled, { imageUrl, fragmentShader, cursor }) {
|
|
10
|
+
const mousePos = (0, react_1.useRef)([0.0, 0.0]);
|
|
11
11
|
const imageFx = (0, react_1.useMemo)(() => {
|
|
12
|
-
if (!imageUrl)
|
|
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, {
|
|
16
|
+
time: 0,
|
|
17
|
+
cursor: type === 'mouse' ? mousePos.current : [x, y]
|
|
18
|
+
});
|
|
15
19
|
}, [imageUrl, fragmentShader]);
|
|
16
20
|
(0, react_1.useEffect)(() => {
|
|
17
|
-
if (!canvas || !imageFx)
|
|
21
|
+
if (!cursor || cursor.type !== 'mouse' || !canvas || !imageFx)
|
|
18
22
|
return;
|
|
19
23
|
const handleMouseMove = (evt) => {
|
|
20
24
|
const rect = canvas.getBoundingClientRect();
|
|
@@ -26,7 +30,7 @@ function useImageFx(canvas, enabled, { imageUrl, fragmentShader }) {
|
|
|
26
30
|
return () => {
|
|
27
31
|
window.removeEventListener('mousemove', handleMouseMove);
|
|
28
32
|
};
|
|
29
|
-
}, [canvas, imageFx]);
|
|
33
|
+
}, [canvas, imageFx, cursor === null || cursor === void 0 ? void 0 : cursor.type]);
|
|
30
34
|
(0, react_1.useEffect)(() => {
|
|
31
35
|
const gl = canvas === null || canvas === void 0 ? void 0 : canvas.getContext('webgl2');
|
|
32
36
|
if (!enabled || !canvas || !gl || !imageFx)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntrl-site/sdk-nextjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "SDK for Next.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@cntrl-site/color": "^1.0.0",
|
|
25
25
|
"@cntrl-site/effects": "^1.0.5-1",
|
|
26
|
-
"@cntrl-site/sdk": "^1.4.
|
|
26
|
+
"@cntrl-site/sdk": "^1.4.2",
|
|
27
27
|
"@types/vimeo__player": "^2.18.0",
|
|
28
28
|
"@vimeo/player": "^2.20.1",
|
|
29
29
|
"html-react-parser": "^3.0.1",
|
|
@@ -24,7 +24,8 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
|
|
|
24
24
|
const fxCanvas = useRef<HTMLCanvasElement | null>(null);
|
|
25
25
|
useImageFx(fxCanvas.current, hasGLEffect ?? false, {
|
|
26
26
|
imageUrl: url,
|
|
27
|
-
fragmentShader
|
|
27
|
+
fragmentShader,
|
|
28
|
+
cursor: item.commonParams.FXCursor
|
|
28
29
|
});
|
|
29
30
|
const rect = useElementRect(ref);
|
|
30
31
|
const rectWidth = Math.floor(rect?.width ?? 0);
|
|
@@ -2,9 +2,16 @@ import { useEffect, useMemo, useRef } from 'react';
|
|
|
2
2
|
import { ImageEffect } from '@cntrl-site/effects';
|
|
3
3
|
import { rangeMap } from '../rangeMap';
|
|
4
4
|
|
|
5
|
+
export interface FXCursor {
|
|
6
|
+
type: 'mouse' | 'manual';
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
5
11
|
interface FxParams {
|
|
6
12
|
imageUrl?: string;
|
|
7
13
|
fragmentShader?: string;
|
|
14
|
+
cursor?: FXCursor;
|
|
8
15
|
}
|
|
9
16
|
|
|
10
17
|
const PATTERN_URL = 'https://cdn.cntrl.site/client-app-files/texture2.png';
|
|
@@ -15,22 +22,27 @@ export function useImageFx(
|
|
|
15
22
|
enabled: boolean,
|
|
16
23
|
{
|
|
17
24
|
imageUrl,
|
|
18
|
-
fragmentShader
|
|
25
|
+
fragmentShader,
|
|
26
|
+
cursor
|
|
19
27
|
}: FxParams
|
|
20
28
|
): void {
|
|
21
|
-
const
|
|
29
|
+
const mousePos = useRef<[number, number]>([0.0, 0.0]);
|
|
22
30
|
const imageFx = useMemo<ImageEffect | undefined>(() => {
|
|
23
|
-
if (!imageUrl) return undefined;
|
|
31
|
+
if (!imageUrl || !cursor) return undefined;
|
|
32
|
+
const { type, x, y } = cursor;
|
|
24
33
|
return new ImageEffect(
|
|
25
34
|
imageUrl,
|
|
26
35
|
PATTERN_URL,
|
|
27
36
|
PATTERN_2_URL,
|
|
28
37
|
fragmentShader!,
|
|
29
|
-
{
|
|
38
|
+
{
|
|
39
|
+
time: 0,
|
|
40
|
+
cursor: type === 'mouse' ? mousePos.current : [x, y]
|
|
41
|
+
});
|
|
30
42
|
}, [imageUrl, fragmentShader]);
|
|
31
43
|
|
|
32
44
|
useEffect(() => {
|
|
33
|
-
if (!canvas || !imageFx) return;
|
|
45
|
+
if (!cursor || cursor.type !== 'mouse' || !canvas || !imageFx) return;
|
|
34
46
|
const handleMouseMove = (evt: MouseEvent) => {
|
|
35
47
|
const rect = canvas.getBoundingClientRect();
|
|
36
48
|
const x = rangeMap(evt.clientX, rect.left, rect.left + rect.width, 0, 1);
|
|
@@ -41,7 +53,7 @@ export function useImageFx(
|
|
|
41
53
|
return () => {
|
|
42
54
|
window.removeEventListener('mousemove', handleMouseMove);
|
|
43
55
|
};
|
|
44
|
-
}, [canvas, imageFx]);
|
|
56
|
+
}, [canvas, imageFx, cursor?.type]);
|
|
45
57
|
|
|
46
58
|
useEffect(() => {
|
|
47
59
|
const gl = canvas?.getContext('webgl2');
|
|
Binary file
|