@cntrl-site/sdk-nextjs 1.9.44 → 1.9.45
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.
|
@@ -19,7 +19,7 @@ const getFill_1 = require("../../../utils/getFill");
|
|
|
19
19
|
const areFillsVisible_1 = require("../../../utils/areFillsVisible/areFillsVisible");
|
|
20
20
|
const useItemGeometry_1 = require("../../../ItemGeometry/useItemGeometry");
|
|
21
21
|
const RectangleItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
|
|
22
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
22
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
23
23
|
const id = (0, react_1.useId)();
|
|
24
24
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
25
25
|
const { fill: itemFill, radius: itemRadius, strokeWidth: itemStrokeWidth, strokeFill: itemStrokeFill, blur: itemBlur, backdropBlur: itemBackdropBlur } = (0, useRectangleItem_1.useRectangleItem)(item, sectionId);
|
|
@@ -27,30 +27,30 @@ const RectangleItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilit
|
|
|
27
27
|
const stateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['angle', 'blur', 'backdropBlur', 'strokeFill']);
|
|
28
28
|
const stateFillParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['fill', 'strokeWidth', 'radius']);
|
|
29
29
|
const stateFillLayers = (_a = stateFillParams === null || stateFillParams === void 0 ? void 0 : stateFillParams.styles) === null || _a === void 0 ? void 0 : _a.fill;
|
|
30
|
-
const
|
|
30
|
+
const fillTransition = (_b = stateFillParams === null || stateFillParams === void 0 ? void 0 : stateFillParams.transition) !== null && _b !== void 0 ? _b : 'none';
|
|
31
31
|
const styles = (_c = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) !== null && _c !== void 0 ? _c : {};
|
|
32
32
|
const layoutValues = [item.area, item.layoutParams];
|
|
33
33
|
const [ref, setRef] = (0, react_1.useState)(null);
|
|
34
34
|
(0, useRegisterResize_1.useRegisterResize)(ref, onResize);
|
|
35
35
|
(0, useItemGeometry_1.useItemGeometry)(item.id, ref);
|
|
36
36
|
const backdropBlur = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(styles === null || styles === void 0 ? void 0 : styles.backdropBlur, itemBackdropBlur);
|
|
37
|
-
const radius = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(
|
|
38
|
-
const strokeWidth = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(
|
|
39
|
-
const strokeFill = (
|
|
37
|
+
const radius = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_d = stateFillParams === null || stateFillParams === void 0 ? void 0 : stateFillParams.styles) === null || _d === void 0 ? void 0 : _d.radius, itemRadius);
|
|
38
|
+
const strokeWidth = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_e = stateFillParams === null || stateFillParams === void 0 ? void 0 : stateFillParams.styles) === null || _e === void 0 ? void 0 : _e.strokeWidth, itemStrokeWidth);
|
|
39
|
+
const strokeFill = (_g = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_f = styles === null || styles === void 0 ? void 0 : styles.strokeFill) === null || _f === void 0 ? void 0 : _f[0], itemStrokeFill === null || itemStrokeFill === void 0 ? void 0 : itemStrokeFill[0])) !== null && _g !== void 0 ? _g : itemStrokeFill === null || itemStrokeFill === void 0 ? void 0 : itemStrokeFill[0];
|
|
40
40
|
const angle = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(styles === null || styles === void 0 ? void 0 : styles.angle, itemAngle);
|
|
41
41
|
const blur = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(styles === null || styles === void 0 ? void 0 : styles.blur, itemBlur);
|
|
42
42
|
const backdropFilterValue = backdropBlur ? `blur(${backdropBlur * 100}vw)` : undefined;
|
|
43
|
-
const isInteractive = (0, areFillsVisible_1.areFillsVisible)((
|
|
43
|
+
const isInteractive = (0, areFillsVisible_1.areFillsVisible)((_h = stateFillLayers !== null && stateFillLayers !== void 0 ? stateFillLayers : itemFill) !== null && _h !== void 0 ? _h : [])
|
|
44
44
|
|| (strokeWidth !== 0 && strokeFill && strokeFill.value && color_1.CntrlColor.parse(strokeFill.value).getAlpha() !== 0);
|
|
45
45
|
(0, react_1.useEffect)(() => {
|
|
46
46
|
onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(isInteractive);
|
|
47
47
|
}, [isInteractive, onVisibilityChange]);
|
|
48
48
|
const stroke = strokeFill
|
|
49
|
-
? (
|
|
49
|
+
? (_j = (0, getFill_1.getFill)(strokeFill)) !== null && _j !== void 0 ? _j : 'transparent'
|
|
50
50
|
: 'transparent';
|
|
51
|
-
return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: (
|
|
51
|
+
return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: (_k = item.link) === null || _k === void 0 ? void 0 : _k.url, target: (_l = item.link) === null || _l === void 0 ? void 0 : _l.target, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `rectangle-${item.id}`, ref: setRef, style: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), { willChange: blur !== 0 && blur !== undefined ? 'transform' : 'unset' }), (backdropFilterValue !== undefined
|
|
52
52
|
? { backdropFilter: backdropFilterValue, WebkitBackdropFilter: backdropFilterValue }
|
|
53
|
-
: {})), { transition: (
|
|
53
|
+
: {})), { transition: (_m = stateParams === null || stateParams === void 0 ? void 0 : stateParams.transition) !== null && _m !== void 0 ? _m : 'none' }), children: itemFill && itemFill.map((fill, index) => {
|
|
54
54
|
var _a, _b;
|
|
55
55
|
const stateFillLayer = stateFillLayers === null || stateFillLayers === void 0 ? void 0 : stateFillLayers.find((layer) => layer.id === fill.id);
|
|
56
56
|
const value = stateFillLayer
|
|
@@ -59,7 +59,7 @@ const RectangleItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilit
|
|
|
59
59
|
const background = value
|
|
60
60
|
? (_b = (0, getFill_1.getFill)(value)) !== null && _b !== void 0 ? _b : 'transparent'
|
|
61
61
|
: 'transparent';
|
|
62
|
-
return ((0, jsx_runtime_1.jsx)(Fill, { fill: value, itemId: item.id, background: background,
|
|
62
|
+
return ((0, jsx_runtime_1.jsx)(Fill, { fill: value, itemId: item.id, background: background, fillTransition: fillTransition, transition: (stateParams === null || stateParams === void 0 ? void 0 : stateParams.transition) || '', radius: radius, strokeWidth: strokeWidth, isHighest: index === itemFill.length - 1, borderColor: stroke }, fill.id));
|
|
63
63
|
}) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
64
64
|
.rectangle-${item.id} {
|
|
65
65
|
position: absolute;
|
|
@@ -92,13 +92,13 @@ const RectangleItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilit
|
|
|
92
92
|
` })] }) }));
|
|
93
93
|
};
|
|
94
94
|
exports.RectangleItem = RectangleItem;
|
|
95
|
-
function Fill({ fill, itemId, background,
|
|
95
|
+
function Fill({ fill, itemId, background, fillTransition, transition, radius, strokeWidth, isHighest, borderColor }) {
|
|
96
96
|
const isRotatedImage = fill.type === 'image' && fill.rotation && fill.rotation !== 0;
|
|
97
97
|
return ((0, jsx_runtime_1.jsx)("div", { className: fill.type === 'image' ? `image-fill-${itemId}` : `fill-${itemId}`, style: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (fill.type === 'solid' ? {
|
|
98
98
|
background,
|
|
99
|
-
transition:
|
|
100
|
-
? `${
|
|
101
|
-
:
|
|
99
|
+
transition: fillTransition && fillTransition !== 'none' && fillTransition.trim()
|
|
100
|
+
? `${fillTransition}, ${transition}`
|
|
101
|
+
: fillTransition
|
|
102
102
|
} : {})), (fill.type === 'image'
|
|
103
103
|
? {
|
|
104
104
|
transform: `rotate(${fill.rotation}deg)`,
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FC,
|
|
1
|
+
import { FC, useEffect, useId, useState } from 'react';
|
|
2
2
|
import JSXStyle from 'styled-jsx/style';
|
|
3
3
|
import { RectangleItem as TRectangleItem, getLayoutStyles, FillLayer } from '@cntrl-site/sdk';
|
|
4
4
|
import { CntrlColor } from '@cntrl-site/color';
|
|
@@ -26,17 +26,17 @@ export const RectangleItem: FC<ItemProps<TRectangleItem>> = ({ item, sectionId,
|
|
|
26
26
|
} = useRectangleItem(item, sectionId);
|
|
27
27
|
const itemAngle = useItemAngle(item, sectionId);
|
|
28
28
|
const stateParams = interactionCtrl?.getState<any>(['angle', 'blur', 'backdropBlur', 'strokeFill']);
|
|
29
|
-
const stateFillParams = interactionCtrl?.getState<
|
|
29
|
+
const stateFillParams = interactionCtrl?.getState<any>(['fill', 'strokeWidth', 'radius']);
|
|
30
30
|
const stateFillLayers = stateFillParams?.styles?.fill;
|
|
31
|
-
const
|
|
31
|
+
const fillTransition = stateFillParams?.transition ?? 'none';
|
|
32
32
|
const styles = stateParams?.styles ?? {};
|
|
33
33
|
const layoutValues: Record<string, any>[] = [item.area, item.layoutParams];
|
|
34
34
|
const [ref, setRef] = useState<HTMLDivElement | null>(null);
|
|
35
35
|
useRegisterResize(ref, onResize);
|
|
36
36
|
useItemGeometry(item.id, ref);
|
|
37
37
|
const backdropBlur = getStyleFromItemStateAndParams(styles?.backdropBlur, itemBackdropBlur);
|
|
38
|
-
const radius = getStyleFromItemStateAndParams(styles?.radius, itemRadius);
|
|
39
|
-
const strokeWidth = getStyleFromItemStateAndParams(styles?.strokeWidth, itemStrokeWidth);
|
|
38
|
+
const radius = getStyleFromItemStateAndParams(stateFillParams?.styles?.radius, itemRadius);
|
|
39
|
+
const strokeWidth = getStyleFromItemStateAndParams(stateFillParams?.styles?.strokeWidth, itemStrokeWidth);
|
|
40
40
|
const strokeFill = getStyleFromItemStateAndParams(styles?.strokeFill?.[0], itemStrokeFill?.[0]) ?? itemStrokeFill?.[0];
|
|
41
41
|
const angle = getStyleFromItemStateAndParams(styles?.angle, itemAngle);
|
|
42
42
|
const blur = getStyleFromItemStateAndParams(styles?.blur, itemBlur);
|
|
@@ -69,7 +69,7 @@ export const RectangleItem: FC<ItemProps<TRectangleItem>> = ({ item, sectionId,
|
|
|
69
69
|
}}
|
|
70
70
|
>
|
|
71
71
|
{itemFill && itemFill.map((fill, index) => {
|
|
72
|
-
const stateFillLayer = stateFillLayers?.find((layer) => layer.id === fill.id);
|
|
72
|
+
const stateFillLayer = stateFillLayers?.find((layer: FillLayer) => layer.id === fill.id);
|
|
73
73
|
const value = stateFillLayer
|
|
74
74
|
? (getStyleFromItemStateAndParams<FillLayer>(stateFillLayer, fill) ?? fill)
|
|
75
75
|
: fill;
|
|
@@ -83,7 +83,7 @@ export const RectangleItem: FC<ItemProps<TRectangleItem>> = ({ item, sectionId,
|
|
|
83
83
|
fill={value}
|
|
84
84
|
itemId={item.id}
|
|
85
85
|
background={background}
|
|
86
|
-
|
|
86
|
+
fillTransition={fillTransition}
|
|
87
87
|
transition={stateParams?.transition || ''}
|
|
88
88
|
radius={radius}
|
|
89
89
|
strokeWidth={strokeWidth}
|
|
@@ -128,11 +128,11 @@ export const RectangleItem: FC<ItemProps<TRectangleItem>> = ({ item, sectionId,
|
|
|
128
128
|
);
|
|
129
129
|
};
|
|
130
130
|
|
|
131
|
-
function Fill({ fill, itemId, background,
|
|
131
|
+
function Fill({ fill, itemId, background, fillTransition, transition, radius, strokeWidth, isHighest, borderColor }: {
|
|
132
132
|
fill: FillLayer;
|
|
133
133
|
itemId: string;
|
|
134
134
|
background: string;
|
|
135
|
-
|
|
135
|
+
fillTransition: string;
|
|
136
136
|
transition: string;
|
|
137
137
|
radius: number;
|
|
138
138
|
strokeWidth: number;
|
|
@@ -147,9 +147,9 @@ function Fill({ fill, itemId, background, solidTransition, transition, radius, s
|
|
|
147
147
|
style={{
|
|
148
148
|
...(fill.type === 'solid' ? {
|
|
149
149
|
background,
|
|
150
|
-
transition:
|
|
151
|
-
? `${
|
|
152
|
-
:
|
|
150
|
+
transition: fillTransition && fillTransition !== 'none' && fillTransition.trim()
|
|
151
|
+
? `${fillTransition}, ${transition}`
|
|
152
|
+
: fillTransition
|
|
153
153
|
} : {}),
|
|
154
154
|
...(fill.type === 'image'
|
|
155
155
|
? {
|