@cntrl-site/sdk-nextjs 0.23.0 → 0.24.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.
@@ -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,31 @@ 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}`;
47
+ console.log('fullShaderCode', fullShaderCode);
48
+ console.log('controlValues', controlValues);
31
49
  (0, useImageFx_1.useImageFx)(fxCanvas.current, hasGLEffect !== null && hasGLEffect !== void 0 ? hasGLEffect : false, {
32
50
  imageUrl: url,
33
- fragmentShader,
34
- cursor: item.commonParams.FXCursor
51
+ fragmentShader: fullShaderCode,
52
+ cursor: item.commonParams.FXCursor,
53
+ controls: controlValues
35
54
  });
36
55
  const rect = (0, useElementRect_1.useElementRect)(ref);
37
- const rectWidth = Math.floor((_a = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _a !== void 0 ? _a : 0);
38
- const rectHeight = Math.floor((_b = rect === null || rect === void 0 ? void 0 : rect.height) !== null && _b !== void 0 ? _b : 0);
56
+ const rectWidth = Math.floor((_b = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _b !== void 0 ? _b : 0);
57
+ const rectHeight = Math.floor((_c = rect === null || rect === void 0 ? void 0 : rect.height) !== null && _c !== void 0 ? _c : 0);
39
58
  const inlineStyles = {
40
59
  borderRadius: `${radius * 100}vw`,
41
60
  borderWidth: `${strokeWidth * 100}vw`,
42
61
  borderColor: `${borderColor.toCss()}`
43
62
  };
44
- return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, Object.assign({ url: (_c = item.link) === null || _c === void 0 ? void 0 : _c.url, target: (_d = item.link) === null || _d === void 0 ? void 0 : _d.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: {
63
+ 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
64
  opacity: `${opacity}`,
46
65
  transform: `rotate(${angle}deg)`,
47
66
  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.23.0",
3
+ "version": "0.24.0",
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-1",
26
- "@cntrl-site/sdk": "^1.6.0",
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,21 @@ 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}`;
42
+ console.log('fullShaderCode', fullShaderCode);
43
+ console.log('controlValues', controlValues);
25
44
  useImageFx(fxCanvas.current, hasGLEffect ?? false, {
26
45
  imageUrl: url,
27
- fragmentShader,
28
- cursor: item.commonParams.FXCursor
46
+ fragmentShader: fullShaderCode,
47
+ cursor: item.commonParams.FXCursor,
48
+ controls: controlValues
29
49
  });
30
50
  const rect = useElementRect(ref);
31
51
  const rectWidth = Math.floor(rect?.width ?? 0);
@@ -117,3 +137,5 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
117
137
  </LinkWrapper>
118
138
  );
119
139
  };
140
+
141
+ 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