@cntrl-site/sdk-nextjs 0.27.2 → 0.28.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,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((_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);
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: (_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: `image-wrapper-${item.id}`, ref: setRef, style: {
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)`
@@ -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.27.2",
3
+ "version": "0.28.0",
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.1.0",
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
- useImageFx(fxCanvas.current, hasGLEffect ?? false, {
43
- imageUrl: url,
44
- fragmentShader: fullShaderCode,
45
- cursor: item.commonParams.FXCursor,
46
- controls: controlValues
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)) {
@@ -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
- }, [imageUrl, fragmentShader]);
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;