PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / trunk
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder vtrunk
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 1.2.0 1.2.1 All 78 releases
ablocks / includes / controls / mask.php

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

144 lines 4.8 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 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