@cntrl-site/sdk-nextjs 1.11.6 → 1.11.8
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.
- package/lib/components/items/FileItem/ImageItem.js +30 -7
- package/lib/components/items/FileItem/useFileItem.js +8 -1
- package/lib/utils/getSvgFill/getSvgFill.js +29 -0
- package/package.json +2 -2
- package/src/components/items/FileItem/ImageItem.tsx +53 -11
- package/src/components/items/FileItem/useFileItem.ts +14 -1
- package/src/utils/getSvgFill/getSvgFill.ts +27 -0
|
@@ -20,13 +20,14 @@ const getStyleFromItemStateAndParams_1 = require("../../../utils/getStyleFromIte
|
|
|
20
20
|
const useItemFXData_1 = require("../../../common/useItemFXData");
|
|
21
21
|
const getFill_1 = require("../../../utils/getFill");
|
|
22
22
|
const useItemGeometry_1 = require("../../../ItemGeometry/useItemGeometry");
|
|
23
|
+
const getSvgFill_1 = require("../../../utils/getSvgFill/getSvgFill");
|
|
23
24
|
const ImageItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
|
|
24
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
25
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
25
26
|
const reactId = (0, react_1.useId)();
|
|
26
27
|
const id = `${reactId}-image-${item.id}`;
|
|
27
28
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
28
29
|
const layoutId = (0, useLayoutContext_1.useLayoutContext)();
|
|
29
|
-
const { radius: itemRadius, strokeWidth: itemStrokeWidth, opacity: itemOpacity, strokeFill: itemStrokeFill, blur: itemBlur } = (0, useFileItem_1.useFileItem)(item, sectionId);
|
|
30
|
+
const { radius: itemRadius, strokeWidth: itemStrokeWidth, opacity: itemOpacity, strokeFill: itemStrokeFill, blur: itemBlur, fill: itemFill } = (0, useFileItem_1.useFileItem)(item, sectionId);
|
|
30
31
|
const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
31
32
|
const [wrapperRef, setWrapperRef] = (0, react_1.useState)(null);
|
|
32
33
|
(0, useRegisterResize_1.useRegisterResize)(wrapperRef, onResize);
|
|
@@ -41,7 +42,7 @@ const ImageItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityCha
|
|
|
41
42
|
const width = area && exemplary ? area.width * exemplary : 0;
|
|
42
43
|
const height = area && exemplary ? area.height * exemplary : 0;
|
|
43
44
|
const wrapperStateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['angle', 'opacity', 'blur']);
|
|
44
|
-
const imgStateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['strokeWidth', 'radius', 'strokeFill']);
|
|
45
|
+
const imgStateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['strokeWidth', 'radius', 'strokeFill', 'fill']);
|
|
45
46
|
(0, react_1.useEffect)(() => {
|
|
46
47
|
isInitialRef.current = false;
|
|
47
48
|
}, []);
|
|
@@ -60,22 +61,29 @@ const ImageItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityCha
|
|
|
60
61
|
const angle = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_j = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _j === void 0 ? void 0 : _j.angle, itemAngle);
|
|
61
62
|
const opacity = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_k = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _k === void 0 ? void 0 : _k.opacity, itemOpacity);
|
|
62
63
|
const blur = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_l = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _l === void 0 ? void 0 : _l.blur, itemBlur);
|
|
64
|
+
const fill = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_m = imgStateParams === null || imgStateParams === void 0 ? void 0 : imgStateParams.styles) === null || _m === void 0 ? void 0 : _m.fill, itemFill);
|
|
65
|
+
// decided from the item data alone, so the server and the browser render the same element
|
|
66
|
+
const hasSvgFill = (0, getSvgFill_1.isSvgUrl)(url) && (Object.values(item.layoutParams).some(params => params.fill && params.fill.length > 0)
|
|
67
|
+
|| Object.values(item.state).some(params => params.fill !== undefined));
|
|
68
|
+
const svgFill = fill ? (0, getSvgFill_1.getSvgFill)(fill, url) : undefined;
|
|
63
69
|
const stroke = strokeFill
|
|
64
|
-
? (
|
|
70
|
+
? (_o = (0, getFill_1.getFill)(strokeFill)) !== null && _o !== void 0 ? _o : 'transparent'
|
|
65
71
|
: 'transparent';
|
|
66
72
|
const inlineStyles = Object.assign(Object.assign(Object.assign({}, (radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {})), (strokeWidth !== undefined ? {
|
|
67
73
|
borderColor: stroke,
|
|
68
74
|
borderWidth: `${strokeWidth * 100}vw`,
|
|
69
75
|
borderRadius: radius !== undefined ? `${radius * 100}vw` : 'inherit',
|
|
70
76
|
borderStyle: 'solid',
|
|
71
|
-
} : {})), { transition: (
|
|
77
|
+
} : {})), { transition: (_p = imgStateParams === null || imgStateParams === void 0 ? void 0 : imgStateParams.transition) !== null && _p !== void 0 ? _p : 'none' });
|
|
72
78
|
const isInteractive = opacity !== 0;
|
|
73
79
|
(0, react_1.useEffect)(() => {
|
|
74
80
|
onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(isInteractive);
|
|
75
81
|
}, [isInteractive, onVisibilityChange]);
|
|
76
|
-
return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: (
|
|
82
|
+
return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: (_q = item.link) === null || _q === void 0 ? void 0 : _q.url, target: (_r = item.link) === null || _r === void 0 ? void 0 : _r.target, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `image-wrapper-${item.id}`, ref: setWrapperRef, style: Object.assign(Object.assign(Object.assign(Object.assign({}, (opacity !== undefined ? { opacity } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), { willChange: blur !== 0 && blur !== undefined ? 'transform' : 'unset', transition: (_s = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.transition) !== null && _s !== void 0 ? _s : 'none' }), children: hasGLEffect && isFXAllowed
|
|
77
83
|
? ((0, jsx_runtime_1.jsx)("canvas", { style: inlineStyles, ref: fxCanvas, className: `img-canvas image-${item.id}`, width: rectWidth, height: rectHeight, role: "img", "aria-label": altText }))
|
|
78
|
-
:
|
|
84
|
+
: hasSvgFill
|
|
85
|
+
? ((0, jsx_runtime_1.jsx)("div", { role: "img", "aria-label": altText, className: `image image-${item.id}`, style: inlineStyles, children: (0, jsx_runtime_1.jsx)("div", { className: `image-svg-fill image-svg-fill-${item.id}`, style: Object.assign(Object.assign({}, (svgFill ? { background: svgFill.background, WebkitMask: svgFill.mask, mask: svgFill.mask } : {})), { transition: (_t = imgStateParams === null || imgStateParams === void 0 ? void 0 : imgStateParams.transition) !== null && _t !== void 0 ? _t : 'none' }) }) }))
|
|
86
|
+
: ((0, jsx_runtime_1.jsx)("img", { alt: altText, className: `image image-${item.id}`, style: inlineStyles, src: item.commonParams.url })) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
79
87
|
.image-wrapper-${item.id} {
|
|
80
88
|
position: absolute;
|
|
81
89
|
width: 100%;
|
|
@@ -93,6 +101,10 @@ const ImageItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityCha
|
|
|
93
101
|
overflow: hidden;
|
|
94
102
|
box-sizing: border-box;
|
|
95
103
|
}
|
|
104
|
+
.image-svg-fill {
|
|
105
|
+
width: 100%;
|
|
106
|
+
height: 100%;
|
|
107
|
+
}
|
|
96
108
|
.img-canvas {
|
|
97
109
|
border: solid;
|
|
98
110
|
width: 100%;
|
|
@@ -102,6 +114,7 @@ const ImageItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityCha
|
|
|
102
114
|
box-sizing: border-box;
|
|
103
115
|
}
|
|
104
116
|
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams]) => {
|
|
117
|
+
var _a;
|
|
105
118
|
return (`
|
|
106
119
|
.image-wrapper-${item.id} {
|
|
107
120
|
opacity: ${layoutParams.opacity};
|
|
@@ -115,8 +128,18 @@ const ImageItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityCha
|
|
|
115
128
|
border-radius: ${layoutParams.radius * 100}vw;
|
|
116
129
|
border-width: ${layoutParams.strokeWidth * 100}vw;
|
|
117
130
|
}
|
|
131
|
+
${hasSvgFill ? getSvgFillCss(item.id, (0, getSvgFill_1.getSvgFill)((_a = layoutParams.fill) !== null && _a !== void 0 ? _a : [], url)) : ''}
|
|
118
132
|
`);
|
|
119
133
|
})}
|
|
120
134
|
` })] }) }));
|
|
121
135
|
};
|
|
122
136
|
exports.ImageItem = ImageItem;
|
|
137
|
+
function getSvgFillCss(itemId, { background, mask }) {
|
|
138
|
+
return `
|
|
139
|
+
.image-svg-fill-${itemId} {
|
|
140
|
+
background: ${background};
|
|
141
|
+
-webkit-mask: ${mask};
|
|
142
|
+
mask: ${mask};
|
|
143
|
+
}
|
|
144
|
+
`;
|
|
145
|
+
}
|
|
@@ -44,6 +44,13 @@ function useFileItem(item, sectionId) {
|
|
|
44
44
|
const layoutParams = item.layoutParams[layoutId];
|
|
45
45
|
return 'blur' in layoutParams ? layoutParams.blur : 0;
|
|
46
46
|
}, (animator, scroll, value) => value !== undefined ? animator.getBlur({ blur: value }, scroll).blur : undefined, sectionId, [layoutId]);
|
|
47
|
-
|
|
47
|
+
const fill = (0, useKeyframeValue_1.useKeyframeValue)(item, sdk_1.KeyframeType.Fill, (item, layoutId) => {
|
|
48
|
+
var _a;
|
|
49
|
+
if (!layoutId)
|
|
50
|
+
return;
|
|
51
|
+
const layoutParams = item.layoutParams[layoutId];
|
|
52
|
+
return 'fill' in layoutParams ? (_a = layoutParams.fill) !== null && _a !== void 0 ? _a : [] : [];
|
|
53
|
+
}, (animator, scroll, value) => value ? animator.getFill(value, scroll) : undefined, sectionId, [layoutId]);
|
|
54
|
+
return { radius, strokeWidth, opacity, strokeFill, blur, fill };
|
|
48
55
|
}
|
|
49
56
|
exports.useFileItem = useFileItem;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSvgFill = exports.isSvgUrl = void 0;
|
|
4
|
+
const getFill_1 = require("../getFill");
|
|
5
|
+
function isSvgUrl(url) {
|
|
6
|
+
return /\.svg(?:[?#]|$)/i.test(url);
|
|
7
|
+
}
|
|
8
|
+
exports.isSvgUrl = isSvgUrl;
|
|
9
|
+
function getSvgFill(fills, url) {
|
|
10
|
+
const svg = `url("${url.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}")`;
|
|
11
|
+
if (fills.length === 0) {
|
|
12
|
+
return { background: `${svg} center / cover no-repeat`, mask: 'none' };
|
|
13
|
+
}
|
|
14
|
+
return { background: getFillsBackground(fills), mask: `${svg} no-repeat center / cover` };
|
|
15
|
+
}
|
|
16
|
+
exports.getSvgFill = getSvgFill;
|
|
17
|
+
function getFillsBackground(fills) {
|
|
18
|
+
const layers = fills
|
|
19
|
+
.map(fill => ({ fill, value: (0, getFill_1.getFill)(fill) }))
|
|
20
|
+
.filter((layer) => !!layer.value && layer.value !== 'transparent');
|
|
21
|
+
return layers
|
|
22
|
+
.map(({ fill, value }, index) => {
|
|
23
|
+
if (fill.type !== 'solid')
|
|
24
|
+
return `${value} center / cover no-repeat`;
|
|
25
|
+
return index === 0 ? value : `linear-gradient(${value}, ${value})`;
|
|
26
|
+
})
|
|
27
|
+
.reverse()
|
|
28
|
+
.join(', ') || 'transparent';
|
|
29
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntrl-site/sdk-nextjs",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.8",
|
|
4
4
|
"description": "SDK for Next.js",
|
|
5
5
|
"author": "arsen@momdesign.nyc",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@cntrl-site/color": "^1.0.0",
|
|
33
33
|
"@cntrl-site/components": "^1.0.110",
|
|
34
34
|
"@cntrl-site/effects": "^1.4.2",
|
|
35
|
-
"@cntrl-site/sdk": "^1.29.
|
|
35
|
+
"@cntrl-site/sdk": "^1.29.9",
|
|
36
36
|
"@types/vimeo__player": "^2.18.0",
|
|
37
37
|
"@vimeo/player": "^2.25.0",
|
|
38
38
|
"franc-min": "^5.0.0",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FC, useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
2
2
|
import JSXStyle from 'styled-jsx/style';
|
|
3
|
-
import { getLayoutStyles, ImageItem as TImageItem } from '@cntrl-site/sdk';
|
|
3
|
+
import { FillLayer, getLayoutStyles, ImageItem as TImageItem } from '@cntrl-site/sdk';
|
|
4
4
|
import { ItemProps } from '../Item';
|
|
5
5
|
import { LinkWrapper } from '../LinkWrapper';
|
|
6
6
|
import { useFileItem } from './useFileItem';
|
|
@@ -14,6 +14,7 @@ import { getStyleFromItemStateAndParams } from '../../../utils/getStyleFromItemS
|
|
|
14
14
|
import { useItemFXData } from '../../../common/useItemFXData';
|
|
15
15
|
import { getFill } from '../../../utils/getFill';
|
|
16
16
|
import { useItemGeometry } from '../../../ItemGeometry/useItemGeometry';
|
|
17
|
+
import { getSvgFill, isSvgUrl } from '../../../utils/getSvgFill/getSvgFill';
|
|
17
18
|
|
|
18
19
|
export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
|
|
19
20
|
const reactId = useId();
|
|
@@ -25,7 +26,8 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
|
|
|
25
26
|
strokeWidth: itemStrokeWidth,
|
|
26
27
|
opacity: itemOpacity,
|
|
27
28
|
strokeFill: itemStrokeFill,
|
|
28
|
-
blur: itemBlur
|
|
29
|
+
blur: itemBlur,
|
|
30
|
+
fill: itemFill
|
|
29
31
|
} = useFileItem(item, sectionId);
|
|
30
32
|
const itemAngle = useItemAngle(item, sectionId);
|
|
31
33
|
const [wrapperRef, setWrapperRef] = useState<HTMLDivElement | null>(null);
|
|
@@ -41,7 +43,7 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
|
|
|
41
43
|
const width = area && exemplary ? area.width * exemplary : 0;
|
|
42
44
|
const height = area && exemplary ? area.height * exemplary : 0;
|
|
43
45
|
const wrapperStateParams = interactionCtrl?.getState<number>(['angle', 'opacity', 'blur']);
|
|
44
|
-
const imgStateParams = interactionCtrl?.getState<any>(['strokeWidth', 'radius', 'strokeFill']);
|
|
46
|
+
const imgStateParams = interactionCtrl?.getState<any>(['strokeWidth', 'radius', 'strokeFill', 'fill']);
|
|
45
47
|
useEffect(() => {
|
|
46
48
|
isInitialRef.current = false;
|
|
47
49
|
}, []);
|
|
@@ -67,6 +69,14 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
|
|
|
67
69
|
const opacity = getStyleFromItemStateAndParams(wrapperStateParams?.styles?.opacity, itemOpacity);
|
|
68
70
|
const blur = getStyleFromItemStateAndParams(wrapperStateParams?.styles?.blur, itemBlur);
|
|
69
71
|
|
|
72
|
+
const fill: FillLayer[] | undefined = getStyleFromItemStateAndParams(imgStateParams?.styles?.fill, itemFill);
|
|
73
|
+
// decided from the item data alone, so the server and the browser render the same element
|
|
74
|
+
const hasSvgFill = isSvgUrl(url) && (
|
|
75
|
+
Object.values(item.layoutParams).some(params => params.fill && params.fill.length > 0)
|
|
76
|
+
|| Object.values(item.state).some(params => params.fill !== undefined)
|
|
77
|
+
);
|
|
78
|
+
const svgFill = fill ? getSvgFill(fill, url) : undefined;
|
|
79
|
+
|
|
70
80
|
const stroke = strokeFill
|
|
71
81
|
? getFill(strokeFill) ?? 'transparent'
|
|
72
82
|
: 'transparent';
|
|
@@ -110,14 +120,31 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
|
|
|
110
120
|
aria-label={altText}
|
|
111
121
|
/>
|
|
112
122
|
)
|
|
113
|
-
:
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
123
|
+
: hasSvgFill
|
|
124
|
+
? (
|
|
125
|
+
<div
|
|
126
|
+
role="img"
|
|
127
|
+
aria-label={altText}
|
|
128
|
+
className={`image image-${item.id}`}
|
|
129
|
+
style={inlineStyles}
|
|
130
|
+
>
|
|
131
|
+
<div
|
|
132
|
+
className={`image-svg-fill image-svg-fill-${item.id}`}
|
|
133
|
+
style={{
|
|
134
|
+
...(svgFill ? { background: svgFill.background, WebkitMask: svgFill.mask, mask: svgFill.mask } : {}),
|
|
135
|
+
transition: imgStateParams?.transition ?? 'none'
|
|
136
|
+
}}
|
|
137
|
+
/>
|
|
138
|
+
</div>
|
|
139
|
+
)
|
|
140
|
+
: (
|
|
141
|
+
<img
|
|
142
|
+
alt={altText}
|
|
143
|
+
className={`image image-${item.id}`}
|
|
144
|
+
style={inlineStyles}
|
|
145
|
+
src={item.commonParams.url}
|
|
146
|
+
/>
|
|
147
|
+
)}
|
|
121
148
|
</div>
|
|
122
149
|
<JSXStyle id={id}>{`
|
|
123
150
|
.image-wrapper-${item.id} {
|
|
@@ -137,6 +164,10 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
|
|
|
137
164
|
overflow: hidden;
|
|
138
165
|
box-sizing: border-box;
|
|
139
166
|
}
|
|
167
|
+
.image-svg-fill {
|
|
168
|
+
width: 100%;
|
|
169
|
+
height: 100%;
|
|
170
|
+
}
|
|
140
171
|
.img-canvas {
|
|
141
172
|
border: solid;
|
|
142
173
|
width: 100%;
|
|
@@ -159,6 +190,7 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
|
|
|
159
190
|
border-radius: ${layoutParams.radius * 100}vw;
|
|
160
191
|
border-width: ${layoutParams.strokeWidth * 100}vw;
|
|
161
192
|
}
|
|
193
|
+
${hasSvgFill ? getSvgFillCss(item.id, getSvgFill(layoutParams.fill ?? [], url)) : ''}
|
|
162
194
|
`);
|
|
163
195
|
})}
|
|
164
196
|
`}</JSXStyle>
|
|
@@ -166,3 +198,13 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
|
|
|
166
198
|
</LinkWrapper>
|
|
167
199
|
);
|
|
168
200
|
};
|
|
201
|
+
|
|
202
|
+
function getSvgFillCss(itemId: string, { background, mask }: { background: string; mask: string }) {
|
|
203
|
+
return `
|
|
204
|
+
.image-svg-fill-${itemId} {
|
|
205
|
+
background: ${background};
|
|
206
|
+
-webkit-mask: ${mask};
|
|
207
|
+
mask: ${mask};
|
|
208
|
+
}
|
|
209
|
+
`;
|
|
210
|
+
}
|
|
@@ -77,5 +77,18 @@ export function useFileItem(item: ImageItem | VideoItem, sectionId: string) {
|
|
|
77
77
|
[layoutId]
|
|
78
78
|
);
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
const fill = useKeyframeValue(
|
|
81
|
+
item,
|
|
82
|
+
KeyframeType.Fill,
|
|
83
|
+
(item, layoutId) => {
|
|
84
|
+
if (!layoutId) return;
|
|
85
|
+
const layoutParams = item.layoutParams[layoutId];
|
|
86
|
+
return 'fill' in layoutParams ? layoutParams.fill ?? [] : [];
|
|
87
|
+
},
|
|
88
|
+
(animator, scroll, value) => value ? animator.getFill(value, scroll) : undefined,
|
|
89
|
+
sectionId,
|
|
90
|
+
[layoutId]
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
return { radius, strokeWidth, opacity, strokeFill, blur, fill };
|
|
81
94
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FillLayer } from '@cntrl-site/sdk';
|
|
2
|
+
import { getFill } from '../getFill';
|
|
3
|
+
|
|
4
|
+
export function isSvgUrl(url: string): boolean {
|
|
5
|
+
return /\.svg(?:[?#]|$)/i.test(url);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function getSvgFill(fills: FillLayer[], url: string): { background: string; mask: string } {
|
|
9
|
+
const svg = `url("${url.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}")`;
|
|
10
|
+
if (fills.length === 0) {
|
|
11
|
+
return { background: `${svg} center / cover no-repeat`, mask: 'none' };
|
|
12
|
+
}
|
|
13
|
+
return { background: getFillsBackground(fills), mask: `${svg} no-repeat center / cover` };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function getFillsBackground(fills: FillLayer[]): string {
|
|
17
|
+
const layers = fills
|
|
18
|
+
.map(fill => ({ fill, value: getFill(fill) }))
|
|
19
|
+
.filter((layer): layer is { fill: FillLayer; value: string } => !!layer.value && layer.value !== 'transparent');
|
|
20
|
+
return layers
|
|
21
|
+
.map(({ fill, value }, index) => {
|
|
22
|
+
if (fill.type !== 'solid') return `${value} center / cover no-repeat`;
|
|
23
|
+
return index === 0 ? value : `linear-gradient(${value}, ${value})`;
|
|
24
|
+
})
|
|
25
|
+
.reverse()
|
|
26
|
+
.join(', ') || 'transparent';
|
|
27
|
+
}
|