| 1 |
<?php |
| 2 |
namespace ABlocks\Controls; |
| 3 |
|
| 4 |
use ABlocks\Classes\ControlBaseAbstract; |
| 5 |
|
| 6 |
class Mask extends ControlBaseAbstract { |
| 7 |
public static function get_attribute_default_value( $is_responsive = false ) { |
| 8 |
if ( $is_responsive ) { |
| 9 |
return [ |
| 10 |
'mask' => false, |
| 11 |
'maskTablet' => false, |
| 12 |
'maskMobile' => false, |
| 13 |
'maskShape' => 'circle', |
| 14 |
'customMaskShape' => '', |
| 15 |
'maskSize' => '', |
| 16 |
'maskSizeTablet' => '', |
| 17 |
'maskSizeMobile' => '', |
| 18 |
'maskPosition' => '', |
| 19 |
'maskPositionTablet' => '', |
| 20 |
'maskPositionMobile' => '', |
| 21 |
'maskRepeat' => '', |
| 22 |
'maskRepeatTablet' => '', |
| 23 |
'maskRepeatMobile' => '', |
| 24 |
'scaleUnit' => 'px', |
| 25 |
'scaleUnitTablet' => 'px', |
| 26 |
'scaleUnitMobile' => 'px', |
| 27 |
'scale' => '0', |
| 28 |
'scaleTablet' => '0', |
| 29 |
'scaleMobile' => '0', |
| 30 |
'xPositionUnit' => 'px', |
| 31 |
'xPositionUnitTablet' => 'px', |
| 32 |
'xPositionUnitMobile' => 'px', |
| 33 |
'xPosition' => '', |
| 34 |
'xPositionTablet' => '0', |
| 35 |
'xPositionMobile' => '0', |
| 36 |
'yPositionUnit' => 'px', |
| 37 |
'yPositionUnitTablet' => 'px', |
| 38 |
'yPositionUnitMobile' => 'px', |
| 39 |
'yPosition' => '0', |
| 40 |
'yPositionTablet' => '0', |
| 41 |
'yPositionMobile' => '0', |
| 42 |
]; |
| 43 |
}//end if |
| 44 |
return [ |
| 45 |
'mask' => false, |
| 46 |
'maskShape' => 'circle', |
| 47 |
'maskSize' => '', |
| 48 |
'maskPosition' => '', |
| 49 |
'maskRepeat' => '', |
| 50 |
'scaleUnit' => 'px', |
| 51 |
'scale' => '0', |
| 52 |
'xPosition' => '', |
| 53 |
'xPositionUnit' => 'px', |
| 54 |
'yPosition' => '', |
| 55 |
'yPositionUnit' => 'px', |
| 56 |
]; |
| 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 |
|
| 68 |
public static function get_css( $attribute_value, $property = '', $device = '' ) { |
| 69 |
$default_attar_value = self::get_attribute_default_value( (bool) $device ); |
| 70 |
$value = wp_parse_args( $attribute_value, $default_attar_value ); |
| 71 |
|
| 72 |
$css = []; |
| 73 |
|
| 74 |
// Base mask defaults — desktop only. Tablet/mobile calls must NOT re-state these |
| 75 |
// because filter_responsive_styles would incorrectly emit them in media queries when |
| 76 |
// the user's desktop setting differs (e.g. desktop position: top left → tablet would |
| 77 |
// wrongly reset to center center). |
| 78 |
if ( $value['mask'] && '' === $device ) { |
| 79 |
if ( 'custom' === $value['maskShape'] ) { |
| 80 |
$css['mask-image'] = 'url(' . $value['customMaskShape'] . ')'; |
| 81 |
} else { |
| 82 |
$css['mask-image'] = 'url(' . ABLOCKS_ROOT_URL . '/assets/images/mask-shapes/' . $value['maskShape'] . '.svg)'; |
| 83 |
} |
| 84 |
$css['-webkit-mask-image'] = $css['mask-image']; |
| 85 |
$css['mask-size'] = 'contain'; |
| 86 |
$css['-webkit-mask-size'] = 'contain'; |
| 87 |
$css['mask-position'] = 'center center'; |
| 88 |
$css['-webkit-mask-position'] = 'center center'; |
| 89 |
$css['mask-repeat'] = 'no-repeat'; |
| 90 |
$css['-webkit-mask-repeat'] = 'no-repeat'; |
| 91 |
} |
| 92 |
|
| 93 |
// Device-specific overrides. Read through device_member(): a custom |
| 94 |
// breakpoint (or the generator's value-less probe suffix) has no key of |
| 95 |
// its own in the control's defaults, and indexing it directly is what |
| 96 |
// produced "Undefined array key …" notices on every page. |
| 97 |
$mask_size = self::device_member( $value, 'maskSize', $device ); |
| 98 |
$mask_position = self::device_member( $value, 'maskPosition', $device ); |
| 99 |
$mask_repeat = self::device_member( $value, 'maskRepeat', $device ); |
| 100 |
|
| 101 |
// Device-specific size: named value (contain / cover) |
| 102 |
if ( $mask_size && 'custom' !== $mask_size ) { |
| 103 |
$css['mask-size'] = $mask_size; |
| 104 |
$css['-webkit-mask-size'] = $css['mask-size']; |
| 105 |
} |
| 106 |
|
| 107 |
// Device-specific size: custom px/em/% value |
| 108 |
$scale_unit = self::device_member( $value, 'scaleUnit', $device ); |
| 109 |
if ( $mask_size && 'custom' === $mask_size && $scale_unit ) { |
| 110 |
$css['mask-size'] = self::device_member( $value, 'scale', $device ) . $scale_unit; |
| 111 |
$css['-webkit-mask-size'] = $css['mask-size']; |
| 112 |
} |
| 113 |
|
| 114 |
// Device-specific position: named value (e.g. top left, center center) |
| 115 |
if ( $mask_position && 'custom' !== $mask_position ) { |
| 116 |
$css['mask-position'] = $mask_position; |
| 117 |
$css['-webkit-mask-position'] = $css['mask-position']; |
| 118 |
} |
| 119 |
|
| 120 |
// Device-specific position: custom X Y values |
| 121 |
// Use !== '' rather than truthy so a value of '0' is not skipped. |
| 122 |
if ( 'custom' === $mask_position ) { |
| 123 |
$x_pos = self::device_member( $value, 'xPosition', $device ); |
| 124 |
$y_pos = self::device_member( $value, 'yPosition', $device ); |
| 125 |
$x_val = '' !== $x_pos ? $x_pos : '0'; |
| 126 |
$y_val = '' !== $y_pos ? $y_pos : '0'; |
| 127 |
$x_unit = self::device_member( $value, 'xPositionUnit', $device ); |
| 128 |
$y_unit = self::device_member( $value, 'yPositionUnit', $device ); |
| 129 |
$css['mask-position'] = $x_val . $x_unit . ' ' . $y_val . $y_unit; |
| 130 |
$css['-webkit-mask-position'] = $css['mask-position']; |
| 131 |
} |
| 132 |
|
| 133 |
// Device-specific repeat override |
| 134 |
if ( $mask_repeat ) { |
| 135 |
$css['mask-repeat'] = $mask_repeat; |
| 136 |
$css['-webkit-mask-repeat'] = $css['mask-repeat']; |
| 137 |
} |
| 138 |
|
| 139 |
return $css; |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
} |
| 144 |
|