PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.4.3
Kubio AI Page Builder v2.4.3
2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / lib / src / Core / StyleManager / Props / Transform.php
kubio / lib / src / Core / StyleManager / Props Last commit date
Animation.php 4 years ago Background.php 1 year ago BackgroundImage.php 1 year ago Border.php 2 years ago BoxShadow.php 4 years ago ColumnWidth.php 4 years ago CustomHeight.php 4 years ago CustomSize.php 4 years ago Gap.php 4 years ago Height.php 4 years ago JustifyContent.php 4 years ago MaxWidth.php 4 years ago MultipleImage.php 4 years ago ObjectCss.php 4 years ago Opacity.php 4 years ago Property.php 4 years ago PropertyBase.php 4 years ago Size.php 4 years ago Stroke.php 4 years ago TBLR.php 4 years ago TextShadow.php 4 years ago Transform.php 2 years ago Transition.php 4 years ago Typography.php 2 years ago UnitValuePercentage.php 4 years ago UnitValuePx.php 4 years ago ValueProxy.php 4 years ago Width.php 4 years ago
Transform.php
176 lines
1 <?php
2
3
4 namespace Kubio\Core\StyleManager\Props;
5
6
7 use Kubio\Core\LodashBasic;
8 use Kubio\Core\StyleManager\ParserUtils;
9 use function array_push;
10 use function is_array;
11 use function wp_is_numeric_array;
12
13 class Transform extends PropertyBase {
14
15
16 function parse( $value, $options ) {
17 if ( array_key_exists( 'none', $value ) && $value['none'] === true ) {
18 return array(
19 'transform' => 'none',
20 );
21 }
22 $style = array();
23 $valueWithDefault = $this->valueWithDefault( $value );
24 $perspective_ = $this->computePerspective( $valueWithDefault['perspective'] );
25 $translateArr = $this->computeTranslate( $valueWithDefault['translate'] );
26 $scaleArr = $this->computeScale( $valueWithDefault['scale'] );
27 $rotateArr = $this->computeRotate( $valueWithDefault['rotate'] );
28 $skewArr = $this->computeSkew( $valueWithDefault['skew'] );
29
30 $transform = ParserUtils::joinNonEmpty(
31 LodashBasic::concat( $perspective_, $translateArr, $scaleArr, $rotateArr, $skewArr )
32 );
33
34 if ( $transform ) {
35 $style['transform'] = $transform;
36 }
37
38 if ( $transform && ParserUtils::isNotEmptyButCanBeZero( $style['transform'] ) ) {
39 $xyz = $this->computeOrigin( $valueWithDefault['origin'] );
40 $transformOrigin = ParserUtils::joinNonEmpty( array( $xyz['x'], $xyz['y'], $xyz['z'] ) );
41 if ( $transformOrigin ) {
42 $style['transformOrigin'] = $transformOrigin;
43 }
44 }
45
46 return $style;
47 }
48
49 public function valueWithDefault( $value ) {
50 $defaultValue = $this->getDefaultValue();
51 return LodashBasic::mergeSkipSeqArray( array(), $defaultValue, $value );
52 }
53
54 function computePerspective( $value ) {
55 $results = array();
56 $perspective = ParserUtils::toValueUnitStringFunction( 'perspective', $value );
57 if ( isset( $perspective ) ) {
58 array_push( $results, $perspective );
59 }
60
61 return $results;
62 }
63
64 function computeTranslate( $XYZValues ) {
65 return $this->computeXYZ(
66 $XYZValues,
67 array(
68 'key' => 'translate',
69 'defaultUnit' => 'px',
70 )
71 );
72 }
73
74 function computeXYZ( $xyzArr, $options ) {
75 $key = $options['key'];
76 $defaultUnit = LodashBasic::get( $options, 'defaultUnit', '' );
77 $isUnitLess = LodashBasic::get( $options, 'isUnitLess', false );
78 $resultArr = array();
79
80 foreach ( $xyzArr as $item ) {
81 if ( ! is_array( $item ) ) {
82 continue;
83 }
84 if ( array_key_exists( 'axis', $item ) ) {
85 $resultArr = LodashBasic::concat(
86 $resultArr,
87 $this->addDirectionValues(
88 $key . strtoupper( $item['axis'] ),
89 LodashBasic::get( $item, 'value' ),
90 $defaultUnit,
91 $isUnitLess
92 )
93 );
94 }
95 }
96
97 return $resultArr;
98 }
99
100 function addDirectionValues( $key, $value, $defaultUnit = '', $isUnitLess = false ) {
101 $translateArray = $value;
102 if ( ! wp_is_numeric_array( $value ) ) {
103 $translateArray = array( $value );
104 }
105 $result = array();
106 foreach ( $translateArray as $translate ) {
107 $str = ParserUtils::toValueUnitStringFunction(
108 $key,
109 $translate,
110 null,
111 $defaultUnit,
112 $isUnitLess
113 );
114 array_push( $result, $str );
115 }
116 return $result;
117 }
118
119 function computeScale( $XYZValues = array() ) {
120 return $this->computeXYZ(
121 $XYZValues,
122 array(
123 'key' => 'scale',
124 'isUnitLess' => true,
125 )
126 );
127 }
128
129 function computeRotate( $rotateValues = array() ) {
130 $rotates = array();
131
132 $rotates = LodashBasic::concat(
133 $rotates,
134 $this->computeXYZ(
135 $rotateValues,
136 array(
137 'key' => 'rotate',
138 'defaultUnit' => 'deg',
139 )
140 )
141 );
142 return $rotates;
143 }
144
145 function computeSkew( $skewValues = array() ) {
146 $skews = $this->computeXYZ(
147 $skewValues,
148 array(
149 'key' => 'skew',
150 'defaultUnit' => 'deg',
151 )
152 );
153 return $skews;
154 }
155
156 function computeOrigin( $originOptions ) {
157 $transformOrigin = array(
158 'x' => $this->getOriginData( $originOptions, 'x.value', 'x.customValue' ),
159 'y' => $this->getOriginData( $originOptions, 'y.value', 'y.customValue' ),
160 'z' => $this->getOriginData( $originOptions, 'z.value', 'z.customValue' ),
161 );
162 return $transformOrigin;
163 }
164
165 function getOriginData( $originOptions, $valuePath, $customValuePath ) {
166 if ( LodashBasic::get( $originOptions, $valuePath ) === 'custom' ) {
167 $originX = LodashBasic::get( $originOptions, $customValuePath );
168 $result = ParserUtils::toValueUnitString( $originX );
169 } else {
170 $result = LodashBasic::get( $originOptions, $valuePath );
171 }
172
173 return $result;
174 }
175 }
176