| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.2/wp-content/themes/blocksy/static/js/customizer/sync/variables/ |
Upload File : |
import { maybePromoteScalarValueIntoResponsive } from 'customizer-sync-helpers/dist/promote-into-responsive'
const componentToHex = (c) => {
var hex = c.toString(16)
return hex.length == 1 ? '0' + hex : hex
}
const withResponsive = ({ responsive, value, cb }) => {
value = maybePromoteScalarValueIntoResponsive(value, responsive)
if (responsive) {
return {
desktop: cb(value.desktop),
tablet: cb(value.tablet),
mobile: cb(value.mobile),
}
}
return cb(value)
}
export const handleBackgroundOptionFor = ({
id,
selector,
responsive = false,
valueExtractor = (value) => value,
addToDescriptors = {},
conditional_var = false,
forced_background_image = false,
}) => ({
[id]: [
{
variable: 'background-color',
variableType: 'property',
selector,
responsive,
extractValue: (value) =>
withResponsive({
value: valueExtractor(value),
responsive,
cb: (value) => {
if (value.background_type === 'gradient') {
return 'initial'
}
if (conditional_var) {
return `var(${conditional_var}, ${value.backgroundColor.default.color})`
}
if (!value) {
return 'CT_CSS_SKIP_RULE'
}
return value.backgroundColor.default.color
},
}),
...addToDescriptors,
},
{
variable: 'background-image',
variableType: 'property',
selector,
responsive,
extractValue: (value) =>
withResponsive({
value: valueExtractor(value),
responsive,
cb: ({
background_type = 'color',
gradient,
background_image,
background_pattern,
patternColor,
backgroundColor,
overlayColor,
} = {}) => {
if (!background_type) {
return 'CT_CSS_SKIP_RULE'
}
if (background_type === 'color') {
if (forced_background_image) {
return 'none'
}
return 'CT_CSS_SKIP_RULE'
}
const str_replace = ($old, $new, $text) =>
($text + '').split($old).join($new)
if (background_type === 'image') {
if (!background_image.url) {
return 'CT_CSS_SKIP_RULE'
}
return `${
overlayColor.default.color !==
'CT_CSS_SKIP_RULE'
? `linear-gradient(${overlayColor.default.color}, ${overlayColor.default.color}), `
: ''
}url(${background_image.url})`
}
if (background_type === 'gradient') {
return gradient
}
let opacity = 1
let color = patternColor
? patternColor.default.color
: ''
if (color.indexOf('theme-palette-color-1') > -1) {
color = getComputedStyle(
document.body
).getPropertyValue('--theme-palette-color-1')
}
if (color.indexOf('theme-palette-color-2') > -1) {
color = getComputedStyle(
document.body
).getPropertyValue('--theme-palette-color-2')
}
if (color.indexOf('theme-palette-color-3') > -1) {
color = getComputedStyle(
document.body
).getPropertyValue('--theme-palette-color-3')
}
if (color.indexOf('theme-palette-color-4') > -1) {
color = getComputedStyle(
document.body
).getPropertyValue('--theme-palette-color-4')
}
if (color.indexOf('theme-palette-color-5') > -1) {
color = getComputedStyle(
document.body
).getPropertyValue('--theme-palette-color-5')
}
if (color.indexOf('theme-palette-color-6') > -1) {
color = getComputedStyle(
document.body
).getPropertyValue('--theme-palette-color-6')
}
if (color.indexOf('theme-palette-color-7') > -1) {
color = getComputedStyle(
document.body
).getPropertyValue('--theme-palette-color-7')
}
if (color.indexOf('theme-palette-color-8') > -1) {
color = getComputedStyle(
document.body
).getPropertyValue('--theme-palette-color-8')
}
if (color.indexOf('rgb') > -1) {
const rgb_array = str_replace(
'rgb(',
'',
str_replace(
')',
'',
str_replace(
'rgba(',
'',
str_replace(' ', '', color)
)
)
).split(',')
color = `#${componentToHex(
parseInt(rgb_array[0], 10)
)}${componentToHex(
parseInt(rgb_array[1], 10)
)}${componentToHex(parseInt(rgb_array[2], 10))}`
if (rgb_array.length > 3) {
opacity = rgb_array[3]
}
}
color = str_replace('#', '', color)
return `url("${str_replace(
'OPACITY',
opacity,
str_replace(
'COLOR',
color,
ct_localizations.customizer_sync.svg_patterns[
background_pattern
] ||
ct_localizations.customizer_sync
.svg_patterns['type-1']
)
)}")`
},
}),
...addToDescriptors,
},
{
variable: 'background-position',
variableType: 'property',
selector,
responsive,
...addToDescriptors,
extractValue: (value) =>
withResponsive({
value: valueExtractor(value),
responsive,
cb: ({ background_type, background_image } = {}) => {
if (background_type !== 'image') {
return 'CT_CSS_SKIP_RULE'
}
return `${Math.round(
parseFloat(background_image.x || 0) * 100
)}% ${Math.round(
parseFloat(background_image.y || 0) * 100
)}%`
},
}),
},
{
variable: 'background-size',
variableType: 'property',
selector,
responsive,
...addToDescriptors,
extractValue: (value) =>
withResponsive({
value: valueExtractor(value),
responsive,
cb: ({ background_type, background_size } = {}) => {
if (background_type !== 'image') {
return 'CT_CSS_SKIP_RULE'
}
return background_size
},
}),
},
{
variable: 'background-attachment',
variableType: 'property',
selector,
responsive,
...addToDescriptors,
extractValue: (value) =>
withResponsive({
value: valueExtractor(value),
responsive,
cb: ({ background_type, background_attachment } = {}) => {
if (background_type !== 'image') {
return 'CT_CSS_SKIP_RULE'
}
return background_attachment
},
}),
},
{
selector,
variable: 'background-repeat',
variableType: 'property',
responsive,
...addToDescriptors,
extractValue: (value) =>
withResponsive({
value: valueExtractor(value),
responsive,
cb: ({ background_type, background_repeat } = {}) => {
if (background_type !== 'image') {
return 'CT_CSS_SKIP_RULE'
}
if (background_repeat === 'repeat') {
return 'CT_CSS_SKIP_RULE'
}
return background_repeat
},
}),
},
],
})
export const getBackgroundVariablesFor = () => ({
// Site background
...handleBackgroundOptionFor({
id: 'site_background',
selector: 'body',
responsive: true,
forced_background_image: true,
}),
})