@cntrl-site/sdk-nextjs 0.23.0 → 0.24.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/.idea/inspectionProfiles/Project_Default.xml +15 -0
- package/lib/components/items/ImageItem.js +23 -6
- package/lib/utils/effects/useImageFx.js +2 -5
- package/package.json +3 -3
- package/src/components/items/ImageItem.tsx +22 -2
- package/src/utils/effects/useImageFx.ts +6 -2
- package/cntrl-site-sdk-nextjs-0.23.0.tgz +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<component name="InspectionProjectProfileManager">
|
|
2
|
+
<profile version="1.0">
|
|
3
|
+
<option name="myName" value="Project Default" />
|
|
4
|
+
<inspection_tool class="HtmlUnknownAttribute" enabled="true" level="WARNING" enabled_by_default="true">
|
|
5
|
+
<option name="myValues">
|
|
6
|
+
<value>
|
|
7
|
+
<list size="1">
|
|
8
|
+
<item index="0" class="java.lang.String" itemvalue="jsx" />
|
|
9
|
+
</list>
|
|
10
|
+
</value>
|
|
11
|
+
</option>
|
|
12
|
+
<option name="myCustomValuesEnabled" value="true" />
|
|
13
|
+
</inspection_tool>
|
|
14
|
+
</profile>
|
|
15
|
+
</component>
|
|
@@ -17,8 +17,16 @@ 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 baseVariables = `precision mediump float;
|
|
21
|
+
uniform sampler2D u_image;
|
|
22
|
+
uniform sampler2D u_pattern;
|
|
23
|
+
uniform vec2 u_imgDimensions;
|
|
24
|
+
uniform vec2 u_patternDimensions;
|
|
25
|
+
uniform float u_time;
|
|
26
|
+
uniform vec2 u_cursor;
|
|
27
|
+
varying vec2 v_texCoord;`;
|
|
20
28
|
const ImageItem = ({ item, sectionId, onResize }) => {
|
|
21
|
-
var _a, _b, _c, _d;
|
|
29
|
+
var _a, _b, _c, _d, _e;
|
|
22
30
|
const id = (0, react_1.useId)();
|
|
23
31
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
24
32
|
const { radius, strokeWidth, opacity, strokeColor, blur } = (0, useFileItem_1.useFileItem)(item, sectionId);
|
|
@@ -28,20 +36,29 @@ const ImageItem = ({ item, sectionId, onResize }) => {
|
|
|
28
36
|
(0, useRegisterResize_1.useRegisterResize)(ref, onResize);
|
|
29
37
|
const { url, hasGLEffect, fragmentShader } = item.commonParams;
|
|
30
38
|
const fxCanvas = (0, react_1.useRef)(null);
|
|
39
|
+
const controls = (_a = item.commonParams.FXControls) !== null && _a !== void 0 ? _a : [];
|
|
40
|
+
const controlsVariables = controls.map((c) => `uniform ${c.type} ${c.shaderParam};`)
|
|
41
|
+
.join('\n');
|
|
42
|
+
const controlValues = controls.reduce((acc, control) => {
|
|
43
|
+
acc[control.shaderParam] = control.value;
|
|
44
|
+
return acc;
|
|
45
|
+
}, {});
|
|
46
|
+
const fullShaderCode = `${baseVariables}\n${controlsVariables}\n${fragmentShader}`;
|
|
31
47
|
(0, useImageFx_1.useImageFx)(fxCanvas.current, hasGLEffect !== null && hasGLEffect !== void 0 ? hasGLEffect : false, {
|
|
32
48
|
imageUrl: url,
|
|
33
|
-
fragmentShader,
|
|
34
|
-
cursor: item.commonParams.FXCursor
|
|
49
|
+
fragmentShader: fullShaderCode,
|
|
50
|
+
cursor: item.commonParams.FXCursor,
|
|
51
|
+
controls: controlValues
|
|
35
52
|
});
|
|
36
53
|
const rect = (0, useElementRect_1.useElementRect)(ref);
|
|
37
|
-
const rectWidth = Math.floor((
|
|
38
|
-
const rectHeight = Math.floor((
|
|
54
|
+
const rectWidth = Math.floor((_b = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _b !== void 0 ? _b : 0);
|
|
55
|
+
const rectHeight = Math.floor((_c = rect === null || rect === void 0 ? void 0 : rect.height) !== null && _c !== void 0 ? _c : 0);
|
|
39
56
|
const inlineStyles = {
|
|
40
57
|
borderRadius: `${radius * 100}vw`,
|
|
41
58
|
borderWidth: `${strokeWidth * 100}vw`,
|
|
42
59
|
borderColor: `${borderColor.toCss()}`
|
|
43
60
|
};
|
|
44
|
-
return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, Object.assign({ url: (
|
|
61
|
+
return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, Object.assign({ 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", Object.assign({ className: `image-wrapper-${item.id}`, ref: setRef, style: {
|
|
45
62
|
opacity: `${opacity}`,
|
|
46
63
|
transform: `rotate(${angle}deg)`,
|
|
47
64
|
filter: `blur(${blur * 100}vw)`
|
|
@@ -6,16 +6,13 @@ 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 }) {
|
|
9
|
+
function useImageFx(canvas, enabled, { imageUrl, fragmentShader, cursor, controls }) {
|
|
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, {
|
|
16
|
-
time: 0,
|
|
17
|
-
cursor: type === 'mouse' ? mousePos.current : [x, y]
|
|
18
|
-
});
|
|
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));
|
|
19
16
|
}, [imageUrl, fragmentShader]);
|
|
20
17
|
(0, react_1.useEffect)(() => {
|
|
21
18
|
if (!cursor || cursor.type !== 'mouse' || !canvas || !imageFx)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntrl-site/sdk-nextjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.2",
|
|
4
4
|
"description": "SDK for Next.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -22,8 +22,8 @@
|
|
|
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.0.5
|
|
26
|
-
"@cntrl-site/sdk": "^1.
|
|
25
|
+
"@cntrl-site/effects": "^1.0.5",
|
|
26
|
+
"@cntrl-site/sdk": "^1.7.1",
|
|
27
27
|
"@types/vimeo__player": "^2.18.0",
|
|
28
28
|
"@vimeo/player": "^2.20.1",
|
|
29
29
|
"html-react-parser": "^3.0.1",
|
|
@@ -12,6 +12,15 @@ import { useRegisterResize } from "../../common/useRegisterResize";
|
|
|
12
12
|
import { useImageFx } from '../../utils/effects/useImageFx';
|
|
13
13
|
import { useElementRect } from '../../utils/useElementRect';
|
|
14
14
|
|
|
15
|
+
const baseVariables = `precision mediump float;
|
|
16
|
+
uniform sampler2D u_image;
|
|
17
|
+
uniform sampler2D u_pattern;
|
|
18
|
+
uniform vec2 u_imgDimensions;
|
|
19
|
+
uniform vec2 u_patternDimensions;
|
|
20
|
+
uniform float u_time;
|
|
21
|
+
uniform vec2 u_cursor;
|
|
22
|
+
varying vec2 v_texCoord;`;
|
|
23
|
+
|
|
15
24
|
export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize }) => {
|
|
16
25
|
const id = useId();
|
|
17
26
|
const { layouts } = useCntrlContext();
|
|
@@ -22,10 +31,19 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
|
|
|
22
31
|
useRegisterResize(ref, onResize);
|
|
23
32
|
const { url, hasGLEffect, fragmentShader } = item.commonParams;
|
|
24
33
|
const fxCanvas = useRef<HTMLCanvasElement | null>(null);
|
|
34
|
+
const controls = item.commonParams.FXControls ?? [];
|
|
35
|
+
const controlsVariables = controls.map((c) => `uniform ${c.type} ${c.shaderParam};`)
|
|
36
|
+
.join('\n');
|
|
37
|
+
const controlValues = controls.reduce<Record<string, ControlValue>>((acc, control) => {
|
|
38
|
+
acc[control.shaderParam] = control.value;
|
|
39
|
+
return acc;
|
|
40
|
+
}, {});
|
|
41
|
+
const fullShaderCode = `${baseVariables}\n${controlsVariables}\n${fragmentShader}`;
|
|
25
42
|
useImageFx(fxCanvas.current, hasGLEffect ?? false, {
|
|
26
43
|
imageUrl: url,
|
|
27
|
-
fragmentShader,
|
|
28
|
-
cursor: item.commonParams.FXCursor
|
|
44
|
+
fragmentShader: fullShaderCode,
|
|
45
|
+
cursor: item.commonParams.FXCursor,
|
|
46
|
+
controls: controlValues
|
|
29
47
|
});
|
|
30
48
|
const rect = useElementRect(ref);
|
|
31
49
|
const rectWidth = Math.floor(rect?.width ?? 0);
|
|
@@ -117,3 +135,5 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
|
|
|
117
135
|
</LinkWrapper>
|
|
118
136
|
);
|
|
119
137
|
};
|
|
138
|
+
|
|
139
|
+
type ControlValue = number | [number, number];
|
|
@@ -12,6 +12,8 @@ interface FxParams {
|
|
|
12
12
|
imageUrl?: string;
|
|
13
13
|
fragmentShader?: string;
|
|
14
14
|
cursor?: FXCursor;
|
|
15
|
+
// TODO use types from SDk
|
|
16
|
+
controls?: Record<string, number | [number, number]>;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
const PATTERN_URL = 'https://cdn.cntrl.site/client-app-files/texture2.png';
|
|
@@ -23,7 +25,8 @@ export function useImageFx(
|
|
|
23
25
|
{
|
|
24
26
|
imageUrl,
|
|
25
27
|
fragmentShader,
|
|
26
|
-
cursor
|
|
28
|
+
cursor,
|
|
29
|
+
controls
|
|
27
30
|
}: FxParams
|
|
28
31
|
): void {
|
|
29
32
|
const mousePos = useRef<[number, number]>([0.0, 0.0]);
|
|
@@ -37,7 +40,8 @@ export function useImageFx(
|
|
|
37
40
|
fragmentShader!,
|
|
38
41
|
{
|
|
39
42
|
time: 0,
|
|
40
|
-
cursor: type === 'mouse' ? mousePos.current : [x, y]
|
|
43
|
+
cursor: type === 'mouse' ? mousePos.current : [x, y],
|
|
44
|
+
...controls
|
|
41
45
|
});
|
|
42
46
|
}, [imageUrl, fragmentShader]);
|
|
43
47
|
|
|
Binary file
|