@cntrl-site/sdk-nextjs 1.0.3 → 1.0.4

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,5 @@
1
+ <component name="ProjectCodeStyleConfiguration">
2
+ <state>
3
+ <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
4
+ </state>
5
+ </component>
@@ -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>
Binary file
@@ -27,7 +27,7 @@ uniform float u_time;
27
27
  uniform vec2 u_cursor;
28
28
  varying vec2 v_texCoord;`;
29
29
  const ImageItem = ({ item, sectionId, onResize }) => {
30
- var _a, _b, _c, _d, _e, _f;
30
+ var _a, _b, _c, _d, _e;
31
31
  const id = (0, react_1.useId)();
32
32
  const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
33
33
  const layoutId = (0, useLayoutContext_1.useLayoutContext)();
@@ -36,10 +36,10 @@ const ImageItem = ({ item, sectionId, onResize }) => {
36
36
  const borderColor = (0, react_1.useMemo)(() => strokeColor ? color_1.CntrlColor.parse(strokeColor) : undefined, [strokeColor]);
37
37
  const [ref, setRef] = (0, react_1.useState)(null);
38
38
  (0, useRegisterResize_1.useRegisterResize)(ref, onResize);
39
- const { url, hasGLEffect, fragmentShader } = item.commonParams;
39
+ const { url, hasGLEffect, fragmentShader, FXControls, FXCursor } = item.commonParams;
40
40
  const fxCanvas = (0, react_1.useRef)(null);
41
41
  const isInitialRef = (0, react_1.useRef)(true);
42
- const controls = (_a = item.commonParams.FXControls) !== null && _a !== void 0 ? _a : [];
42
+ const controls = FXControls !== null && FXControls !== void 0 ? FXControls : [];
43
43
  const controlsVariables = controls.map((c) => `uniform ${c.type} ${c.shaderParam};`)
44
44
  .join('\n');
45
45
  const controlValues = controls.reduce((acc, control) => {
@@ -49,23 +49,24 @@ const ImageItem = ({ item, sectionId, onResize }) => {
49
49
  const layoutValues = [item.area, item.layoutParams, item.state.hover];
50
50
  const fullShaderCode = `${baseVariables}\n${controlsVariables}\n${fragmentShader}`;
51
51
  const area = layoutId ? item.area[layoutId] : null;
52
- const exemplary = (_b = layouts === null || layouts === void 0 ? void 0 : layouts.find(l => l.id === layoutId)) === null || _b === void 0 ? void 0 : _b.exemplary;
52
+ const exemplary = (_a = layouts === null || layouts === void 0 ? void 0 : layouts.find(l => l.id === layoutId)) === null || _a === void 0 ? void 0 : _a.exemplary;
53
53
  const width = area && exemplary ? area.width * exemplary : 0;
54
54
  const height = area && exemplary ? area.height * exemplary : 0;
55
55
  (0, react_1.useEffect)(() => {
56
56
  isInitialRef.current = false;
57
57
  }, []);
58
- (0, useImageFx_1.useImageFx)(fxCanvas.current, !!(hasGLEffect && !isInitialRef.current), {
58
+ const isFXAllowed = (0, useImageFx_1.useImageFx)(fxCanvas.current, !!(hasGLEffect && !isInitialRef.current), {
59
59
  imageUrl: url,
60
60
  fragmentShader: fullShaderCode,
61
- cursor: item.commonParams.FXCursor,
61
+ cursor: FXCursor,
62
62
  controls: controlValues
63
63
  }, width, height);
64
+ console.log('isFXAllowed: ', isFXAllowed);
64
65
  const rect = (0, useElementRect_1.useElementRect)(ref);
65
- const rectWidth = Math.floor((_c = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _c !== void 0 ? _c : 0);
66
- const rectHeight = Math.floor((_d = rect === null || rect === void 0 ? void 0 : rect.height) !== null && _d !== void 0 ? _d : 0);
66
+ const rectWidth = Math.floor((_b = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _b !== void 0 ? _b : 0);
67
+ const rectHeight = Math.floor((_c = rect === null || rect === void 0 ? void 0 : rect.height) !== null && _c !== void 0 ? _c : 0);
67
68
  const inlineStyles = Object.assign(Object.assign(Object.assign({}, (borderColor ? { borderColor: `${borderColor.fmt('rgba')}` } : {})), (radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {})), (strokeWidth !== undefined ? { borderWidth: `${strokeWidth * 100}vw` } : {}));
68
- 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: Object.assign(Object.assign(Object.assign({}, (opacity !== undefined ? { opacity } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), children: item.commonParams.hasGLEffect ? ((0, jsx_runtime_1.jsx)("canvas", { style: inlineStyles, ref: fxCanvas, className: `img-canvas image-${item.id}`, width: rectWidth, height: rectHeight })) : ((0, jsx_runtime_1.jsx)("img", { alt: "", className: `image image-${item.id}`, style: inlineStyles, src: item.commonParams.url })) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
69
+ 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: Object.assign(Object.assign(Object.assign({}, (opacity !== undefined ? { opacity } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), children: hasGLEffect && isFXAllowed ? ((0, jsx_runtime_1.jsx)("canvas", { style: inlineStyles, ref: fxCanvas, className: `img-canvas image-${item.id}`, width: rectWidth, height: rectHeight })) : ((0, jsx_runtime_1.jsx)("img", { alt: "", className: `image image-${item.id}`, style: inlineStyles, src: item.commonParams.url })) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
69
70
  .image-wrapper-${item.id} {
70
71
  position: absolute;
71
72
  width: 100%;
@@ -7,6 +7,7 @@ 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
9
  function useImageFx(canvas, enabled, { imageUrl, fragmentShader, cursor, controls }, width, height) {
10
+ const [isFXAllowed, setIsFXAllowed] = (0, react_1.useState)(true);
10
11
  const mousePos = (0, react_1.useRef)([0.0, 0.0]);
11
12
  const imageFx = (0, react_1.useMemo)(() => {
12
13
  if (!imageUrl || !cursor || !enabled)
@@ -41,7 +42,12 @@ function useImageFx(canvas, enabled, { imageUrl, fragmentShader, cursor, control
41
42
  time += 0.1;
42
43
  imageFx.setViewport(Math.floor(canvas.width), Math.floor(canvas.height));
43
44
  imageFx.setParam('time', time);
44
- imageFx.render(gl);
45
+ try {
46
+ imageFx.render(gl);
47
+ }
48
+ catch (e) {
49
+ setIsFXAllowed(false);
50
+ }
45
51
  frame = requestAnimationFrame(renderFrame);
46
52
  };
47
53
  const observer = new IntersectionObserver(([entry]) => {
@@ -56,11 +62,17 @@ function useImageFx(canvas, enabled, { imageUrl, fragmentShader, cursor, control
56
62
  }
57
63
  });
58
64
  observer.observe(canvas);
59
- imageFx.prepare(gl);
65
+ try {
66
+ imageFx.prepare(gl);
67
+ }
68
+ catch (e) {
69
+ setIsFXAllowed(false);
70
+ }
60
71
  return () => {
61
72
  window.cancelAnimationFrame(frame);
62
73
  observer.disconnect();
63
74
  };
64
75
  }, [canvas, imageFx, enabled]);
76
+ return isFXAllowed;
65
77
  }
66
78
  exports.useImageFx = useImageFx;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "SDK for Next.js",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/index.ts",
@@ -31,10 +31,10 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
31
31
  const borderColor = useMemo(() => strokeColor ? CntrlColor.parse(strokeColor) : undefined, [strokeColor]);
32
32
  const [ref, setRef] = useState<HTMLDivElement | null>(null);
33
33
  useRegisterResize(ref, onResize);
34
- const { url, hasGLEffect, fragmentShader } = item.commonParams;
34
+ const { url, hasGLEffect, fragmentShader, FXControls, FXCursor } = item.commonParams;
35
35
  const fxCanvas = useRef<HTMLCanvasElement | null>(null);
36
36
  const isInitialRef = useRef(true);
37
- const controls = item.commonParams.FXControls ?? [];
37
+ const controls = FXControls ?? [];
38
38
  const controlsVariables = controls.map((c) => `uniform ${c.type} ${c.shaderParam};`)
39
39
  .join('\n');
40
40
  const controlValues = controls.reduce<Record<string, ControlValue>>((acc, control) => {
@@ -50,18 +50,19 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
50
50
  useEffect(() => {
51
51
  isInitialRef.current = false;
52
52
  }, []);
53
- useImageFx(
53
+ const isFXAllowed = useImageFx(
54
54
  fxCanvas.current,
55
55
  !!(hasGLEffect && !isInitialRef.current),
56
56
  {
57
57
  imageUrl: url,
58
58
  fragmentShader: fullShaderCode,
59
- cursor: item.commonParams.FXCursor,
59
+ cursor: FXCursor,
60
60
  controls: controlValues
61
61
  },
62
62
  width,
63
63
  height
64
64
  );
65
+ console.log('isFXAllowed: ', isFXAllowed);
65
66
  const rect = useElementRect(ref);
66
67
  const rectWidth = Math.floor(rect?.width ?? 0);
67
68
  const rectHeight = Math.floor(rect?.height ?? 0);
@@ -82,7 +83,7 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
82
83
  ...(blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {}),
83
84
  }}
84
85
  >
85
- {item.commonParams.hasGLEffect ? (
86
+ {hasGLEffect && isFXAllowed ? (
86
87
  <canvas
87
88
  style={inlineStyles}
88
89
  ref={fxCanvas}
@@ -1,4 +1,4 @@
1
- import { useEffect, useMemo, useRef } from 'react';
1
+ import { useEffect, useMemo, useRef, useState } from 'react';
2
2
  import { ImageEffect } from '@cntrl-site/effects';
3
3
  import { rangeMap } from '../rangeMap';
4
4
 
@@ -30,7 +30,8 @@ export function useImageFx(
30
30
  }: FxParams,
31
31
  width: number,
32
32
  height: number
33
- ): void {
33
+ ): boolean {
34
+ const [isFXAllowed, setIsFXAllowed] = useState(true);
34
35
  const mousePos = useRef<[number, number]>([0.0, 0.0]);
35
36
  const imageFx = useMemo<ImageEffect | undefined>(() => {
36
37
  if (!imageUrl || !cursor || !enabled) return undefined;
@@ -77,7 +78,11 @@ export function useImageFx(
77
78
  time += 0.1;
78
79
  imageFx.setViewport(Math.floor(canvas.width), Math.floor(canvas.height));
79
80
  imageFx.setParam('time', time);
80
- imageFx.render(gl);
81
+ try {
82
+ imageFx.render(gl);
83
+ } catch (e) {
84
+ setIsFXAllowed(false);
85
+ }
81
86
  frame = requestAnimationFrame(renderFrame);
82
87
  };
83
88
 
@@ -93,11 +98,16 @@ export function useImageFx(
93
98
  }
94
99
  });
95
100
  observer.observe(canvas);
96
- imageFx.prepare(gl);
101
+ try {
102
+ imageFx.prepare(gl);
103
+ } catch (e) {
104
+ setIsFXAllowed(false);
105
+ }
97
106
 
98
107
  return () => {
99
108
  window.cancelAnimationFrame(frame);
100
109
  observer.disconnect();
101
110
  };
102
111
  }, [canvas, imageFx, enabled]);
112
+ return isFXAllowed;
103
113
  }
Binary file