| 1 |
import { |
| 2 |
boxCss, |
| 3 |
colorControls, |
| 4 |
objectToCssString, |
| 5 |
rangerCss, |
| 6 |
spacingGenerate, |
| 7 |
wrapInMediaQuery, |
| 8 |
} from "../shared/helpFn"; |
| 9 |
const dynamicCss = (attributes) => { |
| 10 |
const { |
| 11 |
uniqueId, |
| 12 |
maxWidth, |
| 13 |
smartImageWidth, |
| 14 |
smartImageHeight, |
| 15 |
imageFocalPoint, |
| 16 |
smartImgBgEnable, |
| 17 |
smartImgBg, |
| 18 |
smartBgImgBorder, |
| 19 |
smartBgImgBorderWidth, |
| 20 |
smartBgImgBorderRadius, |
| 21 |
smartBgImgInnerPadding, |
| 22 |
imgTitleEnable, |
| 23 |
imgTitleTypography, |
| 24 |
imgTitleFontSize, |
| 25 |
imgTitleLineHeight, |
| 26 |
imgTitleLetterSpacing, |
| 27 |
imgTitleWordSpacing, |
| 28 |
imgCaptionEnable, |
| 29 |
imgCaptionTypography, |
| 30 |
imgCapFontSize, |
| 31 |
imgCapLineHeight, |
| 32 |
imgCapLetterSpacing, |
| 33 |
imgCapWordSpacing, |
| 34 |
imgTextColor, |
| 35 |
imgTextPadding, |
| 36 |
imageBorder, |
| 37 |
imageBorderWidth, |
| 38 |
imageBorderRadius, |
| 39 |
imageBoxShadowEnable, |
| 40 |
imageBoxShadow, |
| 41 |
imageBlur, |
| 42 |
imageBrightness, |
| 43 |
imageContrast, |
| 44 |
imageSaturation, |
| 45 |
imageHue, |
| 46 |
enableLink, |
| 47 |
linkType, |
| 48 |
linkBtnTypography, |
| 49 |
linkBtnFontSize, |
| 50 |
linkBtnLineHeight, |
| 51 |
linkBtnLetterSpacing, |
| 52 |
linkBtnWordSpacing, |
| 53 |
linkButtonColor, |
| 54 |
linkButtonBg, |
| 55 |
linkButtonBorder, |
| 56 |
linkBtnBorderWidth, |
| 57 |
linkBtnBorderRadius, |
| 58 |
linkBtnBoxShadowEnable, |
| 59 |
linkBtnBoxShadow, |
| 60 |
linkBtnPadding, |
| 61 |
linkBtnBorderWidthHover, |
| 62 |
linkBtnBorderRadiusHover, |
| 63 |
linkBtnBoxShadowEnableHover, |
| 64 |
linkBtnBoxShadowHover, |
| 65 |
imageShapeSet, |
| 66 |
maskingShapedUpload, |
| 67 |
maskSize, |
| 68 |
imgHoverOverlayEnable, |
| 69 |
imgHoverOverlayColor, |
| 70 |
aspectRatio, |
| 71 |
imgMaskingEnable, |
| 72 |
selectImageShape, |
| 73 |
imageFilter, |
| 74 |
imgHoverEffectOpacity, |
| 75 |
} = attributes; |
| 76 |
|
| 77 |
const rangeValue = (attr, deviceType = "Desktop") => { |
| 78 |
return attr?.device?.[deviceType]; |
| 79 |
}; |
| 80 |
const getMaskSvgFile = (svgName) => { |
| 81 |
return `${sp_smart_post_block_localize?.pluginUrl}public/assets/img/${svgName}`; |
| 82 |
}; |
| 83 |
const imgBrightFilter = (deviceType) => |
| 84 |
rangeValue(imageBrightness, deviceType) !== "" ? `brightness(${rangeValue(imageBrightness, deviceType)}%)` : ""; |
| 85 |
const imgContrastFilter = (deviceType) => |
| 86 |
rangeValue(imageContrast, deviceType) !== "" ? `contrast(${rangeValue(imageContrast, deviceType)}%)` : ""; |
| 87 |
const imgSaturateFilter = (deviceType) => |
| 88 |
rangeValue(imageSaturation, deviceType) !== "" ? `saturate(${rangeValue(imageSaturation, deviceType)}%)` : ""; |
| 89 |
const imgBlurFilter = (deviceType) => |
| 90 |
rangeValue(imageBlur, deviceType) !== "" ? `blur(${rangeValue(imageBlur, deviceType)}px)` : ""; |
| 91 |
const imgHueFilter = (deviceType) => |
| 92 |
rangeValue(imageHue, deviceType) !== "" ? `hue-rotate(${rangeValue(imageHue, deviceType)}deg)` : ""; |
| 93 |
|
| 94 |
const imgFilterValue = (deviceType) => { |
| 95 |
const brightness = imgBrightFilter(deviceType); |
| 96 |
const contrastFilter = imgContrastFilter(deviceType); |
| 97 |
const saturateFilter = imgSaturateFilter(deviceType); |
| 98 |
const blurFilter = imgBlurFilter(deviceType); |
| 99 |
const hueFilter = imgHueFilter(deviceType); |
| 100 |
return `${brightness} ${contrastFilter} ${saturateFilter} ${blurFilter} ${hueFilter}`; |
| 101 |
}; |
| 102 |
|
| 103 |
const smartImageResponsiveCss = (deviceType) => { |
| 104 |
const allResponsiveCss = [ |
| 105 |
{ |
| 106 |
class: `#${uniqueId} .sp-smart-post-smart-image`, |
| 107 |
styles: { |
| 108 |
"max-width": aspectRatio !== "custom" ? rangerCss(maxWidth, deviceType) : "unset", |
| 109 |
}, |
| 110 |
}, |
| 111 |
{ |
| 112 |
class: `#${uniqueId} .sp-smart-image-area .sp-smart-image.sp-image-ratio-custom`, |
| 113 |
styles: { |
| 114 |
width: rangerCss(smartImageWidth, deviceType), |
| 115 |
height: rangerCss(smartImageHeight, deviceType), |
| 116 |
}, |
| 117 |
}, |
| 118 |
{ |
| 119 |
class: `#${uniqueId} .sp-smart-image-area .sp-smart-image`, |
| 120 |
styles: { |
| 121 |
"object-position": `${imageFocalPoint?.x * 100}% ${imageFocalPoint?.y * 100}%`, |
| 122 |
}, |
| 123 |
}, |
| 124 |
{ |
| 125 |
class: `#${uniqueId} .sp-smart-image-wrapper .sp-smart-image-area`, |
| 126 |
styles: { |
| 127 |
padding: spacingGenerate(smartBgImgInnerPadding, deviceType), |
| 128 |
}, |
| 129 |
}, |
| 130 |
{ |
| 131 |
class: `#${uniqueId} .sp-smart-image-area .sp-smart-image-wrapper`, |
| 132 |
styles: { |
| 133 |
"border-width": spacingGenerate(imageBorderWidth, deviceType), |
| 134 |
"border-radius": spacingGenerate(imageBorderRadius, deviceType), |
| 135 |
"box-shadow": boxCss(imageBoxShadowEnable, deviceType, imageBoxShadow, "color"), |
| 136 |
}, |
| 137 |
}, |
| 138 |
]; |
| 139 |
|
| 140 |
if (smartImgBgEnable) { |
| 141 |
allResponsiveCss.push( |
| 142 |
...[ |
| 143 |
{ |
| 144 |
class: `#${uniqueId} .sp-smart-image-wrapper .sp-smart-image-area`, |
| 145 |
styles: { |
| 146 |
"border-width": spacingGenerate(smartBgImgBorderWidth, deviceType), |
| 147 |
"border-radius": spacingGenerate(smartBgImgBorderRadius, deviceType), |
| 148 |
}, |
| 149 |
}, |
| 150 |
] |
| 151 |
); |
| 152 |
} |
| 153 |
if (imgTitleEnable) { |
| 154 |
allResponsiveCss.push( |
| 155 |
...[ |
| 156 |
{ |
| 157 |
class: `#${uniqueId} .sp-smart-image-title-area .sp-smart-image-title`, |
| 158 |
styles: { |
| 159 |
"font-size": rangerCss(imgTitleFontSize, deviceType), |
| 160 |
"line-height": rangerCss(imgTitleLineHeight, deviceType), |
| 161 |
"letter-spacing": rangerCss(imgTitleLetterSpacing, deviceType), |
| 162 |
"word-spacing": rangerCss(imgTitleWordSpacing, deviceType), |
| 163 |
}, |
| 164 |
}, |
| 165 |
] |
| 166 |
); |
| 167 |
} |
| 168 |
if (imgCaptionEnable) { |
| 169 |
allResponsiveCss.push( |
| 170 |
...[ |
| 171 |
{ |
| 172 |
class: `#${uniqueId} .sp-smart-image-caption-area .sp-smart-image-caption`, |
| 173 |
styles: { |
| 174 |
"font-size": rangerCss(imgCapFontSize, deviceType), |
| 175 |
"line-height": rangerCss(imgCapLineHeight, deviceType), |
| 176 |
"letter-spacing": rangerCss(imgCapLetterSpacing, deviceType), |
| 177 |
"word-spacing": rangerCss(imgCapWordSpacing, deviceType), |
| 178 |
}, |
| 179 |
}, |
| 180 |
] |
| 181 |
); |
| 182 |
} |
| 183 |
if (imgTitleEnable || imgCaptionEnable) { |
| 184 |
allResponsiveCss.push( |
| 185 |
...[ |
| 186 |
{ |
| 187 |
class: `#${uniqueId} .sp-smart-image-text-container`, |
| 188 |
styles: { |
| 189 |
padding: spacingGenerate(imgTextPadding, deviceType), |
| 190 |
}, |
| 191 |
}, |
| 192 |
] |
| 193 |
); |
| 194 |
} |
| 195 |
if (enableLink && "button" === linkType) { |
| 196 |
allResponsiveCss.push( |
| 197 |
...[ |
| 198 |
{ |
| 199 |
class: `#${uniqueId} .sp-smart-image-link-btn-wrapper .sp-smart-image-link-btn`, |
| 200 |
styles: { |
| 201 |
"font-size": rangerCss(linkBtnFontSize, deviceType), |
| 202 |
"line-height": rangerCss(linkBtnLineHeight, deviceType), |
| 203 |
"letter-spacing": rangerCss(linkBtnLetterSpacing, deviceType), |
| 204 |
"word-spacing": rangerCss(linkBtnWordSpacing, deviceType), |
| 205 |
"border-width": spacingGenerate(linkBtnBorderWidth, deviceType), |
| 206 |
"border-radius": spacingGenerate(linkBtnBorderRadius, deviceType), |
| 207 |
"box-shadow": boxCss(linkBtnBoxShadowEnable, deviceType, linkBtnBoxShadow, "color"), |
| 208 |
padding: spacingGenerate(linkBtnPadding, deviceType), |
| 209 |
}, |
| 210 |
}, |
| 211 |
{ |
| 212 |
class: `#${uniqueId} .sp-smart-image-link-btn-wrapper .sp-smart-image-link-btn:hover`, |
| 213 |
styles: { |
| 214 |
"border-width": spacingGenerate(linkBtnBorderWidthHover, deviceType), |
| 215 |
"border-radius": spacingGenerate(linkBtnBorderRadiusHover, deviceType), |
| 216 |
"box-shadow": boxCss( |
| 217 |
linkBtnBoxShadowEnableHover, |
| 218 |
deviceType, |
| 219 |
linkBtnBoxShadowHover, |
| 220 |
"color" |
| 221 |
), |
| 222 |
padding: spacingGenerate(linkBtnPadding, deviceType), |
| 223 |
}, |
| 224 |
}, |
| 225 |
] |
| 226 |
); |
| 227 |
} |
| 228 |
if (imageFilter) { |
| 229 |
allResponsiveCss.push( |
| 230 |
...[ |
| 231 |
{ |
| 232 |
class: `#${uniqueId} .sp-smart-image-area .sp-smart-image-wrapper`, |
| 233 |
styles: { |
| 234 |
filter: imgFilterValue(deviceType), |
| 235 |
}, |
| 236 |
}, |
| 237 |
] |
| 238 |
); |
| 239 |
} |
| 240 |
|
| 241 |
return allResponsiveCss; |
| 242 |
}; |
| 243 |
|
| 244 |
let desktopCss = [ |
| 245 |
...smartImageResponsiveCss("Desktop"), |
| 246 |
{ |
| 247 |
class: `#${uniqueId} .sp-smart-image-area .sp-smart-image-wrapper`, |
| 248 |
styles: { |
| 249 |
"border-style": imageBorder?.style, |
| 250 |
"border-color": imageBorder?.color, |
| 251 |
// filter: imgFilterValue("Desktop"), |
| 252 |
}, |
| 253 |
}, |
| 254 |
{ |
| 255 |
class: `#${uniqueId} .sp-smart-image-area .sp-smart-image-wrapper:hover`, |
| 256 |
styles: { |
| 257 |
"border-color": imageBorder?.hoverColor, |
| 258 |
}, |
| 259 |
}, |
| 260 |
]; |
| 261 |
|
| 262 |
if (smartImgBgEnable) { |
| 263 |
desktopCss.push( |
| 264 |
...[ |
| 265 |
{ |
| 266 |
class: `#${uniqueId} .sp-smart-image-wrapper .sp-smart-image-area`, |
| 267 |
styles: { |
| 268 |
background: colorControls( |
| 269 |
smartImgBg?.color?.style, |
| 270 |
smartImgBg?.color?.solidColor, |
| 271 |
smartImgBg?.color?.gradient |
| 272 |
), |
| 273 |
"border-style": smartBgImgBorder?.style, |
| 274 |
"border-color": smartBgImgBorder?.color, |
| 275 |
}, |
| 276 |
}, |
| 277 |
{ |
| 278 |
class: `#${uniqueId} .sp-smart-image-wrapper .sp-smart-image-area:hover`, |
| 279 |
styles: { |
| 280 |
background: colorControls( |
| 281 |
smartImgBg?.hover?.style, |
| 282 |
smartImgBg?.hover?.solidColor, |
| 283 |
smartImgBg?.hover?.gradient |
| 284 |
), |
| 285 |
"border-color": smartBgImgBorder?.hoverColor, |
| 286 |
}, |
| 287 |
}, |
| 288 |
] |
| 289 |
); |
| 290 |
} |
| 291 |
if (imgTitleEnable) { |
| 292 |
desktopCss.push( |
| 293 |
...[ |
| 294 |
{ |
| 295 |
class: `#${uniqueId} .sp-smart-image-title-area .sp-smart-image-title`, |
| 296 |
styles: { |
| 297 |
color: imgTextColor?.color, |
| 298 |
"font-family": imgTitleTypography?.typography?.family, |
| 299 |
"font-weight": imgTitleTypography?.typography?.fontWeight, |
| 300 |
"font-style": imgTitleTypography?.typography?.style, |
| 301 |
"text-transform": imgTitleTypography?.typography?.transform, |
| 302 |
"text-decoration": imgTitleTypography?.typography?.decoration, |
| 303 |
}, |
| 304 |
}, |
| 305 |
{ |
| 306 |
class: `#${uniqueId} .sp-smart-image-title-area .sp-smart-image-title:hover`, |
| 307 |
styles: { |
| 308 |
color: imgTextColor?.hover, |
| 309 |
}, |
| 310 |
}, |
| 311 |
] |
| 312 |
); |
| 313 |
} |
| 314 |
if (imgCaptionEnable) { |
| 315 |
desktopCss.push( |
| 316 |
...[ |
| 317 |
{ |
| 318 |
class: `#${uniqueId} .sp-smart-image-caption-area .sp-smart-image-caption`, |
| 319 |
styles: { |
| 320 |
color: imgTextColor?.color, |
| 321 |
"font-family": imgCaptionTypography?.typography?.family, |
| 322 |
"font-weight": imgCaptionTypography?.typography?.fontWeight, |
| 323 |
"font-style": imgCaptionTypography?.typography?.style, |
| 324 |
"text-transform": imgCaptionTypography?.typography?.transform, |
| 325 |
"text-decoration": imgCaptionTypography?.typography?.decoration, |
| 326 |
}, |
| 327 |
}, |
| 328 |
{ |
| 329 |
class: `#${uniqueId} .sp-smart-image-caption-area .sp-smart-image-caption:hover`, |
| 330 |
styles: { |
| 331 |
color: imgTextColor?.hover, |
| 332 |
}, |
| 333 |
}, |
| 334 |
] |
| 335 |
); |
| 336 |
} |
| 337 |
if (enableLink && "button" === linkType) { |
| 338 |
desktopCss.push( |
| 339 |
...[ |
| 340 |
{ |
| 341 |
class: `#${uniqueId} .sp-smart-image-link-btn-wrapper .sp-smart-image-link-btn`, |
| 342 |
styles: { |
| 343 |
"font-family": linkBtnTypography?.typography?.family, |
| 344 |
"font-weight": linkBtnTypography?.typography?.fontWeight, |
| 345 |
"font-style": linkBtnTypography?.typography?.style, |
| 346 |
"text-decoration": linkBtnTypography?.typography?.decoration, |
| 347 |
"text-transform": linkBtnTypography?.typography?.transform, |
| 348 |
color: linkButtonColor.color, |
| 349 |
background: colorControls( |
| 350 |
linkButtonBg?.color?.style, |
| 351 |
linkButtonBg?.color?.solidColor, |
| 352 |
linkButtonBg?.color?.gradient |
| 353 |
), |
| 354 |
"border-style": linkButtonBorder?.style, |
| 355 |
"border-color": linkButtonBorder?.color, |
| 356 |
}, |
| 357 |
}, |
| 358 |
{ |
| 359 |
class: `#${uniqueId} .sp-smart-image-link-btn-wrapper .sp-smart-image-link-btn:hover`, |
| 360 |
styles: { |
| 361 |
color: linkButtonColor.hover, |
| 362 |
background: colorControls( |
| 363 |
linkButtonBg?.hover?.style, |
| 364 |
linkButtonBg?.hover?.solidColor, |
| 365 |
linkButtonBg?.hover?.gradient |
| 366 |
), |
| 367 |
"border-color": linkButtonBorder?.hoverColor, |
| 368 |
}, |
| 369 |
}, |
| 370 |
] |
| 371 |
); |
| 372 |
} |
| 373 |
if (imgMaskingEnable && "custom" === imageShapeSet && maskingShapedUpload?.hasOwnProperty("url")) { |
| 374 |
desktopCss.push( |
| 375 |
...[ |
| 376 |
{ |
| 377 |
class: `#${uniqueId} .sp-smart-image-wrapper .sp-smart-image-area.sp-custom-mask`, |
| 378 |
styles: { |
| 379 |
"mask-image": `url("${maskingShapedUpload?.url}")`, |
| 380 |
"mask-size": maskSize, |
| 381 |
}, |
| 382 |
}, |
| 383 |
] |
| 384 |
); |
| 385 |
} |
| 386 |
if (imgHoverOverlayEnable) { |
| 387 |
desktopCss.push( |
| 388 |
...[ |
| 389 |
{ |
| 390 |
class: `#${uniqueId} .sp-smart-image-area:hover .sp-hover-img-overlay`, |
| 391 |
styles: { |
| 392 |
background: colorControls( |
| 393 |
imgHoverOverlayColor?.color?.style, |
| 394 |
imgHoverOverlayColor?.color?.solidColor, |
| 395 |
imgHoverOverlayColor?.color?.gradient |
| 396 |
), |
| 397 |
opacity: imgHoverEffectOpacity, |
| 398 |
}, |
| 399 |
}, |
| 400 |
] |
| 401 |
); |
| 402 |
} |
| 403 |
if (imgMaskingEnable && imageShapeSet === "shape-set") { |
| 404 |
const maskImage = { |
| 405 |
"shape-two": `url( "${getMaskSvgFile("circle.svg")}")`, |
| 406 |
"shape-six": `url( "${getMaskSvgFile("blobCircle.svg")}")`, |
| 407 |
"shape-seven": `url( "${getMaskSvgFile("blobTriangle.svg")}")`, |
| 408 |
}; |
| 409 |
|
| 410 |
desktopCss.push( |
| 411 |
...[ |
| 412 |
{ |
| 413 |
class: `#${uniqueId} .sp-smart-image-wrapper .sp-smart-image-area`, |
| 414 |
styles: { |
| 415 |
"mask-image": maskImage[selectImageShape], |
| 416 |
}, |
| 417 |
}, |
| 418 |
] |
| 419 |
); |
| 420 |
} |
| 421 |
|
| 422 |
let tabletCss = [...smartImageResponsiveCss("Tablet")]; |
| 423 |
|
| 424 |
let mobileCss = [...smartImageResponsiveCss("Mobile")]; |
| 425 |
|
| 426 |
const tabletMediaQueryCss = wrapInMediaQuery(objectToCssString(tabletCss), "only screen and (max-width: 1023px)"); |
| 427 |
const mobileMediaQueryCss = wrapInMediaQuery(objectToCssString(mobileCss), "only screen and (max-width: 599px)"); |
| 428 |
|
| 429 |
desktopCss = desktopCss.filter((item) => item.value !== "" && item.value !== " !important"); |
| 430 |
tabletCss = tabletCss.filter((item) => item.value !== "" && item.value !== " !important"); |
| 431 |
mobileCss = mobileCss.filter((item) => item.value !== "" && item.value !== " !important"); |
| 432 |
|
| 433 |
return `${objectToCssString(desktopCss)} ${tabletMediaQueryCss} ${mobileMediaQueryCss}`; |
| 434 |
}; |
| 435 |
|
| 436 |
export default dynamicCss; |
| 437 |
|