@cntrl-site/sdk-nextjs 1.9.58 → 1.9.60

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.
Binary file
@@ -3,20 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useItemFXData = void 0;
4
4
  const sdk_1 = require("@cntrl-site/sdk");
5
5
  const useKeyframeValue_1 = require("./useKeyframeValue");
6
+ const react_1 = require("react");
6
7
  const baseVariables = `precision mediump float;
7
8
  uniform sampler2D u_image;
8
- uniform sampler2D u_pattern;
9
9
  uniform vec2 u_imgDimensions;
10
- uniform vec2 u_patternDimensions;
11
10
  uniform float u_time;
12
11
  uniform vec2 u_cursor;
13
12
  varying vec2 v_texCoord;`;
14
13
  function useItemFXData(item, sectionId) {
15
- const { fragmentShader: shaderBody, FXControls } = item.commonParams;
14
+ const { fragmentShader: shaderBody, FXControls, FXTextures } = item.commonParams;
16
15
  const controls = FXControls !== null && FXControls !== void 0 ? FXControls : [];
16
+ const texturesUrls = (0, react_1.useMemo)(() => (FXTextures !== null && FXTextures !== void 0 ? FXTextures : []), [FXTextures]);
17
17
  const controlsVariables = controls.map((c) => `uniform ${c.type} ${c.shaderParam};`)
18
18
  .join('\n');
19
- const fragmentShader = `${baseVariables}\n${controlsVariables}\n${shaderBody}`;
19
+ const patternsVariables = texturesUrls
20
+ .map((_, i) => `uniform sampler2D ${mediaEffectPatternUniformNames(i).tex};\nuniform vec2 ${mediaEffectPatternUniformNames(i).dim};`)
21
+ .join('\n');
22
+ const fragmentShader = `${baseVariables}\n${controlsVariables}\n${patternsVariables}\n${shaderBody}`;
20
23
  const controlsValues = (0, useKeyframeValue_1.useKeyframeValue)(item, sdk_1.KeyframeType.FXParams, () => {
21
24
  const defaultValue = controls.reduce((acc, control) => {
22
25
  if (Array.isArray(control.value)) {
@@ -31,7 +34,15 @@ function useItemFXData(item, sectionId) {
31
34
  }, (animator, scroll, value) => animator.getFXParams(value, scroll), sectionId);
32
35
  return {
33
36
  fragmentShader,
34
- controlsValues
37
+ controlsValues,
38
+ texturesUrls
35
39
  };
36
40
  }
37
41
  exports.useItemFXData = useItemFXData;
42
+ function mediaEffectPatternUniformNames(slotIndex) {
43
+ if (slotIndex === 0) {
44
+ return { tex: 'u_pattern', dim: 'u_patternDimensions' };
45
+ }
46
+ const n = slotIndex + 1;
47
+ return { tex: `u_pattern${n}`, dim: `u_pattern${n}Dimensions` };
48
+ }
@@ -35,7 +35,7 @@ const ImageItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityCha
35
35
  const fxCanvas = (0, react_1.useRef)(null);
36
36
  const isInitialRef = (0, react_1.useRef)(true);
37
37
  const layoutValues = [item.area, item.layoutParams];
38
- const { controlsValues, fragmentShader } = (0, useItemFXData_1.useItemFXData)(item, sectionId);
38
+ const { controlsValues, fragmentShader, texturesUrls } = (0, useItemFXData_1.useItemFXData)(item, sectionId);
39
39
  const area = layoutId ? item.area[layoutId] : null;
40
40
  const exemplary = (_a = layouts === null || layouts === void 0 ? void 0 : layouts.find(l => l.id === layoutId)) === null || _a === void 0 ? void 0 : _a.exemplary;
41
41
  const width = area && exemplary ? area.width * exemplary : 0;
@@ -48,7 +48,8 @@ const ImageItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityCha
48
48
  const isFXAllowed = (0, useImageFx_1.useImageFx)(fxCanvas.current, !!(hasGLEffect && !isInitialRef.current), {
49
49
  imageUrl: url,
50
50
  fragmentShader,
51
- controlsValues
51
+ controlsValues,
52
+ texturesUrls
52
53
  }, width, height);
53
54
  const rect = (0, useElementRect_1.useElementRect)(wrapperRef);
54
55
  const rectWidth = Math.floor((_b = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _b !== void 0 ? _b : 0);
@@ -43,7 +43,7 @@ const VideoItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityCha
43
43
  const exemplary = (_a = layouts === null || layouts === void 0 ? void 0 : layouts.find(l => l.id === layoutId)) === null || _a === void 0 ? void 0 : _a.exemplary;
44
44
  const width = area && exemplary ? area.width * exemplary : 0;
45
45
  const height = area && exemplary ? area.height * exemplary : 0;
46
- const { controlsValues, fragmentShader } = (0, useItemFXData_1.useItemFXData)(item, sectionId);
46
+ const { controlsValues, fragmentShader, texturesUrls } = (0, useItemFXData_1.useItemFXData)(item, sectionId);
47
47
  const rect = (0, useElementRect_1.useElementRect)(ref);
48
48
  const rectWidth = Math.floor((_b = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _b !== void 0 ? _b : 0);
49
49
  const rectHeight = Math.floor((_c = rect === null || rect === void 0 ? void 0 : rect.height) !== null && _c !== void 0 ? _c : 0);
@@ -68,7 +68,8 @@ const VideoItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityCha
68
68
  const isFXAllowed = (0, useVideoFx_1.useVideoFx)(fxCanvas.current, !!(hasGLEffect && !isInitialRef.current), {
69
69
  videoUrl: url,
70
70
  fragmentShader,
71
- controls: controlsValues
71
+ controls: controlsValues,
72
+ texturesUrls
72
73
  }, width, height);
73
74
  (0, useRegisterResize_1.useRegisterResize)(ref, onResize);
74
75
  (0, useItemGeometry_1.useItemGeometry)(item.id, ref);
@@ -5,9 +5,7 @@ const react_1 = require("react");
5
5
  const effects_1 = require("@cntrl-site/effects");
6
6
  const rangeMap_1 = require("../rangeMap");
7
7
  const WebGLContextManagerContext_1 = require("../../provider/WebGLContextManagerContext");
8
- const PATTERN_URL = 'https://cdn.cntrl.site/client-app-files/texture2.png';
9
- const PATTERN_2_URL = 'https://cdn.cntrl.site/client-app-files/bayer16.png';
10
- function useImageFx(canvas, enabled, { imageUrl, fragmentShader, controlsValues }, width, height) {
8
+ function useImageFx(canvas, enabled, { imageUrl, fragmentShader, controlsValues, texturesUrls }, width, height) {
11
9
  const webGLContextManager = (0, react_1.useContext)(WebGLContextManagerContext_1.WebglContextManagerContext);
12
10
  const [isFXAllowed, setIsFXAllowed] = (0, react_1.useState)(true);
13
11
  const glRef = (0, react_1.useRef)(null);
@@ -21,8 +19,8 @@ function useImageFx(canvas, enabled, { imageUrl, fragmentShader, controlsValues
21
19
  const imageFx = (0, react_1.useMemo)(() => {
22
20
  if (!imageTextureManager)
23
21
  return;
24
- return new effects_1.MediaEffect(imageTextureManager, PATTERN_URL, PATTERN_2_URL, fragmentShader, Object.assign({ time: 0, cursor: [0, 0] }, controlsValues), width, height);
25
- }, [imageTextureManager, fragmentShader, width, height]);
22
+ return new effects_1.MediaEffect(imageTextureManager, texturesUrls, fragmentShader, Object.assign({ time: 0, cursor: [0, 0] }, controlsValues), width, height);
23
+ }, [imageTextureManager, fragmentShader, width, height, texturesUrls]);
26
24
  (0, react_1.useEffect)(() => {
27
25
  if (!imageFx || !controlsValues)
28
26
  return;
@@ -5,9 +5,7 @@ const react_1 = require("react");
5
5
  const effects_1 = require("@cntrl-site/effects");
6
6
  const rangeMap_1 = require("../rangeMap");
7
7
  const WebGLContextManagerContext_1 = require("../../provider/WebGLContextManagerContext");
8
- const PATTERN_URL = 'https://cdn.cntrl.site/client-app-files/texture2.png';
9
- const PATTERN_2_URL = 'https://cdn.cntrl.site/client-app-files/bayer16.png';
10
- function useVideoFx(canvas, enabled, { videoUrl, fragmentShader, controls }, width, height) {
8
+ function useVideoFx(canvas, enabled, { videoUrl, fragmentShader, controls, texturesUrls }, width, height) {
11
9
  const [isFXAllowed, setIsFXAllowed] = (0, react_1.useState)(true);
12
10
  const [isReady, setIsReady] = (0, react_1.useState)(false);
13
11
  const active = enabled && isReady;
@@ -26,8 +24,8 @@ function useVideoFx(canvas, enabled, { videoUrl, fragmentShader, controls }, wid
26
24
  const videoFx = (0, react_1.useMemo)(() => {
27
25
  if (!videoTextureManager)
28
26
  return;
29
- return new effects_1.MediaEffect(videoTextureManager, PATTERN_URL, PATTERN_2_URL, fragmentShader, Object.assign({ time: 0, cursor: [0, 0] }, controls), width, height);
30
- }, [videoTextureManager, fragmentShader, width, height]);
27
+ return new effects_1.MediaEffect(videoTextureManager, texturesUrls, fragmentShader, Object.assign({ time: 0, cursor: [0, 0] }, controls), width, height);
28
+ }, [videoTextureManager, fragmentShader, width, height, texturesUrls]);
31
29
  (0, react_1.useEffect)(() => {
32
30
  if (!videoTextureManager)
33
31
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "1.9.58",
3
+ "version": "1.9.60",
4
4
  "description": "SDK for Next.js",
5
5
  "author": "arsen@momdesign.nyc",
6
6
  "license": "MIT",
@@ -32,8 +32,8 @@
32
32
  "@antfu/eslint-config": "^3.8.0",
33
33
  "@cntrl-site/color": "^1.0.0",
34
34
  "@cntrl-site/components": "^1.0.5",
35
- "@cntrl-site/effects": "^1.4.0",
36
- "@cntrl-site/sdk": "^1.26.2",
35
+ "@cntrl-site/effects": "^1.4.2",
36
+ "@cntrl-site/sdk": "^1.26.3",
37
37
  "@types/vimeo__player": "^2.18.0",
38
38
  "@vimeo/player": "^2.25.0",
39
39
  "html-react-parser": "^3.0.1",
@@ -1,21 +1,24 @@
1
1
  import { ImageItem, KeyframeType, VideoItem } from '@cntrl-site/sdk';
2
2
  import { useKeyframeValue } from './useKeyframeValue';
3
+ import { useMemo } from 'react';
3
4
 
4
5
  const baseVariables = `precision mediump float;
5
6
  uniform sampler2D u_image;
6
- uniform sampler2D u_pattern;
7
7
  uniform vec2 u_imgDimensions;
8
- uniform vec2 u_patternDimensions;
9
8
  uniform float u_time;
10
9
  uniform vec2 u_cursor;
11
10
  varying vec2 v_texCoord;`;
12
11
 
13
12
  export function useItemFXData(item: ImageItem | VideoItem, sectionId: string): FXData {
14
- const { fragmentShader: shaderBody, FXControls } = item.commonParams;
13
+ const { fragmentShader: shaderBody, FXControls, FXTextures } = item.commonParams;
15
14
  const controls = FXControls ?? [];
15
+ const texturesUrls: string[] = useMemo(() => (FXTextures ?? []), [FXTextures]);
16
16
  const controlsVariables = controls.map((c) => `uniform ${c.type} ${c.shaderParam};`)
17
17
  .join('\n');
18
- const fragmentShader = `${baseVariables}\n${controlsVariables}\n${shaderBody}`;
18
+ const patternsVariables = texturesUrls
19
+ .map((_, i) => `uniform sampler2D ${mediaEffectPatternUniformNames(i).tex};\nuniform vec2 ${mediaEffectPatternUniformNames(i).dim};`)
20
+ .join('\n');
21
+ const fragmentShader = `${baseVariables}\n${controlsVariables}\n${patternsVariables}\n${shaderBody}`;
19
22
  const controlsValues = useKeyframeValue(
20
23
  item,
21
24
  KeyframeType.FXParams,
@@ -35,13 +38,26 @@ export function useItemFXData(item: ImageItem | VideoItem, sectionId: string): F
35
38
  );
36
39
  return {
37
40
  fragmentShader,
38
- controlsValues
41
+ controlsValues,
42
+ texturesUrls
39
43
  };
40
44
  }
41
45
 
46
+ function mediaEffectPatternUniformNames(slotIndex: number): {
47
+ tex: string;
48
+ dim: string;
49
+ } {
50
+ if (slotIndex === 0) {
51
+ return { tex: 'u_pattern', dim: 'u_patternDimensions' };
52
+ }
53
+ const n = slotIndex + 1;
54
+ return { tex: `u_pattern${n}`, dim: `u_pattern${n}Dimensions` };
55
+ }
56
+
42
57
  type FXData = {
43
58
  fragmentShader: string;
44
59
  controlsValues: Record<string, ControlValue>;
60
+ texturesUrls: string[];
45
61
  }
46
62
 
47
63
  type ControlValue = number;
@@ -1,4 +1,4 @@
1
- import { FC, useEffect, useId, useRef, useState } from 'react';
1
+ import { FC, useEffect, useId, useMemo, useRef, useState } from 'react';
2
2
  import JSXStyle from 'styled-jsx/style';
3
3
  import { getLayoutStyles, ImageItem as TImageItem } from '@cntrl-site/sdk';
4
4
  import { ItemProps } from '../Item';
@@ -34,9 +34,8 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
34
34
  const { url, hasGLEffect } = item.commonParams;
35
35
  const fxCanvas = useRef<HTMLCanvasElement | null>(null);
36
36
  const isInitialRef = useRef(true);
37
-
38
37
  const layoutValues: Record<string, any>[] = [item.area, item.layoutParams];
39
- const { controlsValues, fragmentShader } = useItemFXData(item, sectionId);
38
+ const { controlsValues, fragmentShader, texturesUrls } = useItemFXData(item, sectionId);
40
39
  const area = layoutId ? item.area[layoutId] : null;
41
40
  const exemplary = layouts?.find(l => l.id === layoutId)?.exemplary;
42
41
  const width = area && exemplary ? area.width * exemplary : 0;
@@ -52,7 +51,8 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
52
51
  {
53
52
  imageUrl: url,
54
53
  fragmentShader,
55
- controlsValues
54
+ controlsValues,
55
+ texturesUrls
56
56
  },
57
57
  width,
58
58
  height
@@ -43,7 +43,7 @@ export const VideoItem: FC<ItemProps<TVideoItem>> = ({ item, sectionId, onResize
43
43
  const exemplary = layouts?.find(l => l.id === layoutId)?.exemplary;
44
44
  const width = area && exemplary ? area.width * exemplary : 0;
45
45
  const height = area && exemplary ? area.height * exemplary : 0;
46
- const { controlsValues, fragmentShader } = useItemFXData(item, sectionId);
46
+ const { controlsValues, fragmentShader, texturesUrls } = useItemFXData(item, sectionId);
47
47
  const rect = useElementRect(ref);
48
48
  const rectWidth = Math.floor(rect?.width ?? 0);
49
49
  const rectHeight = Math.floor(rect?.height ?? 0);
@@ -71,7 +71,8 @@ export const VideoItem: FC<ItemProps<TVideoItem>> = ({ item, sectionId, onResize
71
71
  {
72
72
  videoUrl: url,
73
73
  fragmentShader,
74
- controls: controlsValues
74
+ controls: controlsValues,
75
+ texturesUrls
75
76
  },
76
77
  width,
77
78
  height
@@ -7,18 +7,17 @@ interface FxParams {
7
7
  imageUrl?: string;
8
8
  fragmentShader: string | null;
9
9
  controlsValues?: Record<string, number | [number, number]>;
10
+ texturesUrls: string[];
10
11
  }
11
12
 
12
- const PATTERN_URL = 'https://cdn.cntrl.site/client-app-files/texture2.png';
13
- const PATTERN_2_URL = 'https://cdn.cntrl.site/client-app-files/bayer16.png';
14
-
15
13
  export function useImageFx(
16
14
  canvas: HTMLCanvasElement | null | undefined,
17
15
  enabled: boolean,
18
16
  {
19
17
  imageUrl,
20
18
  fragmentShader,
21
- controlsValues
19
+ controlsValues,
20
+ texturesUrls
22
21
  }: FxParams,
23
22
  width: number,
24
23
  height: number
@@ -36,8 +35,7 @@ export function useImageFx(
36
35
  if (!imageTextureManager) return;
37
36
  return new MediaEffect(
38
37
  imageTextureManager,
39
- PATTERN_URL,
40
- PATTERN_2_URL,
38
+ texturesUrls,
41
39
  fragmentShader!,
42
40
  {
43
41
  time: 0,
@@ -47,7 +45,7 @@ export function useImageFx(
47
45
  width,
48
46
  height
49
47
  );
50
- }, [imageTextureManager, fragmentShader, width, height]);
48
+ }, [imageTextureManager, fragmentShader, width, height, texturesUrls]);
51
49
 
52
50
  useEffect(() => {
53
51
  if (!imageFx || !controlsValues) return;
@@ -7,18 +7,17 @@ interface FxParams {
7
7
  videoUrl?: string;
8
8
  fragmentShader: string | null;
9
9
  controls?: Record<string, number | [number, number]>;
10
+ texturesUrls: string[];
10
11
  }
11
12
 
12
- const PATTERN_URL = 'https://cdn.cntrl.site/client-app-files/texture2.png';
13
- const PATTERN_2_URL = 'https://cdn.cntrl.site/client-app-files/bayer16.png';
14
-
15
13
  export function useVideoFx(
16
14
  canvas: HTMLCanvasElement | null | undefined,
17
15
  enabled: boolean,
18
16
  {
19
17
  videoUrl,
20
18
  fragmentShader,
21
- controls
19
+ controls,
20
+ texturesUrls
22
21
  }: FxParams,
23
22
  width: number,
24
23
  height: number
@@ -41,8 +40,7 @@ export function useVideoFx(
41
40
  if (!videoTextureManager) return;
42
41
  return new MediaEffect(
43
42
  videoTextureManager,
44
- PATTERN_URL,
45
- PATTERN_2_URL,
43
+ texturesUrls,
46
44
  fragmentShader!,
47
45
  {
48
46
  time: 0,
@@ -52,7 +50,7 @@ export function useVideoFx(
52
50
  width,
53
51
  height
54
52
  );
55
- }, [videoTextureManager, fragmentShader, width, height]);
53
+ }, [videoTextureManager, fragmentShader, width, height, texturesUrls]);
56
54
 
57
55
  useEffect(() => {
58
56
  if (!videoTextureManager) return;
@@ -1,5 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <state>
3
- <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
4
- </state>
5
- </component>
package/.idea/modules.xml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/sdk-nextjs.iml" filepath="$PROJECT_DIR$/.idea/sdk-nextjs.iml" />
6
- </modules>
7
- </component>
8
- </project>
@@ -1,12 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="WEB_MODULE" version="4">
3
- <component name="NewModuleRootManager">
4
- <content url="file://$MODULE_DIR$">
5
- <excludeFolder url="file://$MODULE_DIR$/temp" />
6
- <excludeFolder url="file://$MODULE_DIR$/.tmp" />
7
- <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
- </content>
9
- <orderEntry type="inheritedJdk" />
10
- <orderEntry type="sourceFolder" forTests="false" />
11
- </component>
12
- </module>
package/.idea/vcs.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
- </component>
6
- </project>