| @@ -1,0 +1,95 @@ | ||
| 1 | +<?php | |
| 2 | +namespace ABlocks\Controls; | |
| 3 | + | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | +use ABlocks\Classes\ControlBaseAbstract; | |
| 8 | +class CssFilter extends ControlBaseAbstract { | |
| 9 | + public static function get_attribute_default_value( $is_responsive = false ) { | |
| 10 | + if ( $is_responsive ) { | |
| 11 | + return array( | |
| 12 | + 'blur' => '', | |
| 13 | + 'blurTablet' => '', | |
| 14 | + 'blurMobile' => '', | |
| 15 | + 'brightness' => '', | |
| 16 | + 'brightnessTablet' => '', | |
| 17 | + 'brightnessMobile' => '', | |
| 18 | + 'contrast' => '', | |
| 19 | + 'contrastTablet' => '', | |
| 20 | + 'contrastMobile' => '', | |
| 21 | + 'saturate' => '', | |
| 22 | + 'saturateTablet' => '', | |
| 23 | + 'saturateMobile' => '', | |
| 24 | + 'hue' => '', | |
| 25 | + 'hueTablet' => '', | |
| 26 | + 'hueMobile' => '', | |
| 27 | + | |
| 28 | + 'blurH' => '', | |
| 29 | + 'blurHTablet' => '', | |
| 30 | + 'blurHMobile' => '', | |
| 31 | + 'brightnessH' => '', | |
| 32 | + 'brightnessHTablet' => '', | |
| 33 | + 'brightnessHMobile' => '', | |
| 34 | + 'contrastH' => '', | |
| 35 | + 'contrastHTablet' => '', | |
| 36 | + 'contrastHMobile' => '', | |
| 37 | + 'saturateH' => '', | |
| 38 | + 'saturateHTablet' => '', | |
| 39 | + 'saturateHMobile' => '', | |
| 40 | + 'hueH' => '', | |
| 41 | + 'hueHTablet' => '', | |
| 42 | + 'hueHMobile' => '', | |
| 43 | + ); | |
| 44 | + }//end if | |
| 45 | + return [ | |
| 46 | + 'blur' => '', | |
| 47 | + 'brightness' => '', | |
| 48 | + 'contrast' => '', | |
| 49 | + 'saturate' => '', | |
| 50 | + 'hue' => '', | |
| 51 | + // css filter hover attributes | |
| 52 | + 'blurH' => '', | |
| 53 | + 'brightnessH' => '', | |
| 54 | + 'contrastH' => '', | |
| 55 | + 'saturateH' => '', | |
| 56 | + 'hueH' => '', | |
| 57 | + ]; | |
| 58 | + } | |
| 59 | + public static function get_attribute( $attributeName, $isResponsive = false ) { | |
| 60 | + return [ | |
| 61 | + $attributeName => [ | |
| 62 | + 'type' => 'object', | |
| 63 | + 'default' => self::get_attribute_default_value( $isResponsive ), | |
| 64 | + ], | |
| 65 | + ]; | |
| 66 | + } | |
| 67 | + public static function get_css( $attribute_value, $property = '', $device = '' ) { | |
| 68 | + $value = array_merge( | |
| 69 | + self::get_attribute_default_value( (bool) $device ), | |
| 70 | + $attribute_value | |
| 71 | + ); | |
| 72 | + $css = []; | |
| 73 | + $filterValues = []; | |
| 74 | + if ( isset( $value[ 'brightness' . $device ] ) && $value[ 'brightness' . $device ] !== '' ) { | |
| 75 | + $filterValues[] = 'brightness(' . ( $value[ 'brightness' . $device ] ?? 100 ) . '%)'; | |
| 76 | + } | |
| 77 | + if ( isset( $value[ 'contrast' . $device ] ) && $value[ 'contrast' . $device ] !== '' ) { | |
| 78 | + $filterValues[] = 'contrast(' . ( $value[ 'contrast' . $device ] ?? 100 ) . '%)'; | |
| 79 | + } | |
| 80 | + if ( isset( $value[ 'saturate' . $device ] ) && $value[ 'saturate' . $device ] !== '' ) { | |
| 81 | + $filterValues[] = 'saturate(' . ( $value[ 'saturate' . $device ] ?? 100 ) . '%)'; | |
| 82 | + } | |
| 83 | + if ( isset( $value[ 'blur' . $device ] ) && $value[ 'blur' . $device ] !== '' ) { | |
| 84 | + $filterValues[] = 'blur(' . ( $value[ 'blur' . $device ] ?? 0 ) . 'px)'; | |
| 85 | + } | |
| 86 | + if ( isset( $value[ 'hue' . $device ] ) && $value[ 'hue' . $device ] !== '' ) { | |
| 87 | + $filterValues[] = 'hue-rotate(' . ( $value[ 'hue' . $device ] ?? 0 ) . 'deg)'; | |
| 88 | + } | |
| 89 | + // Only add the filter property if there are valid filter values | |
| 90 | + if ( ! empty( $filterValues ) ) { | |
| 91 | + $css['filter'] = implode( ' ', $filterValues ); | |
| 92 | + } | |
| 93 | + return $css; | |
| 94 | + } | |
| 95 | +} | |