PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.11.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.11.0
2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 All 80 releases
ablocks / includes / controls / mask.php

mask.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.11.0, at includes/controls/mask.php

140 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 size: named value (contain / cover)
94 if ( $value[ 'maskSize' . $device ] && 'custom' !== $value[ 'maskSize' . $device ] ) {
95 $css['mask-size'] = $value[ 'maskSize' . $device ];
96 $css['-webkit-mask-size'] = $css['mask-size'];
97 }
98
99 // Device-specific size: custom px/em/% value
100 if (
101 $value[ 'maskSize' . $device ] &&
102 'custom' === $value[ 'maskSize' . $device ] &&
103 $value[ 'scaleUnit' . $device ]
104 ) {
105 $css['mask-size'] = $value[ 'scale' . $device ] . $value[ 'scaleUnit' . $device ];
106 $css['-webkit-mask-size'] = $css['mask-size'];
107 }
108
109 // Device-specific position: named value (e.g. top left, center center)
110 if (
111 $value[ 'maskPosition' . $device ] &&
112 'custom' !== $value[ 'maskPosition' . $device ]
113 ) {
114 $css['mask-position'] = $value[ 'maskPosition' . $device ];
115 $css['-webkit-mask-position'] = $css['mask-position'];
116 }
117
118 // Device-specific position: custom X Y values
119 // Use !== '' rather than truthy so a value of '0' is not skipped.
120 if ( 'custom' === $value[ 'maskPosition' . $device ] ) {
121 $x_val = $value[ 'xPosition' . $device ] !== '' ? $value[ 'xPosition' . $device ] : '0';
122 $y_val = $value[ 'yPosition' . $device ] !== '' ? $value[ 'yPosition' . $device ] : '0';
123 $x_unit = $value[ 'xPositionUnit' . $device ];
124 $y_unit = $value[ 'yPositionUnit' . $device ];
125 $css['mask-position'] = $x_val . $x_unit . ' ' . $y_val . $y_unit;
126 $css['-webkit-mask-position'] = $css['mask-position'];
127 }
128
129 // Device-specific repeat override
130 if ( $value[ 'maskRepeat' . $device ] ) {
131 $css['mask-repeat'] = $value[ 'maskRepeat' . $device ];
132 $css['-webkit-mask-repeat'] = $css['mask-repeat'];
133 }
134
135 return $css;
136 }
137
138
139 }
140