PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 1.6.4
Kubio AI Page Builder v1.6.4
2.8.4 2.8.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 4 years ago BackgroundImage.php 4 years ago Border.php 4 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 4 years ago Transition.php 4 years ago Typography.php 3 years ago UnitValuePercentage.php 4 years ago UnitValuePx.php 4 years ago ValueProxy.php 4 years ago Width.php 4 years ago
Transform.php
173 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 ( array_key_exists( 'axis', $item ) ) {
82 $resultArr = LodashBasic::concat(
83 $resultArr,
84 $this->addDirectionValues(
85 $key . strtoupper( $item['axis'] ),
86 LodashBasic::get( $item, 'value' ),
87 $defaultUnit,
88 $isUnitLess
89 )
90 );
91 }
92 }
93
94 return $resultArr;
95 }
96
97 function addDirectionValues( $key, $value, $defaultUnit = '', $isUnitLess = false ) {
98 $translateArray = $value;
99 if ( ! wp_is_numeric_array( $value ) ) {
100 $translateArray = array( $value );
101 }
102 $result = array();
103 foreach ( $translateArray as $translate ) {
104 $str = ParserUtils::toValueUnitStringFunction(
105 $key,
106 $translate,
107 null,
108 $defaultUnit,
109 $isUnitLess
110 );
111 array_push( $result, $str );
112 }
113 return $result;
114 }
115
116 function computeScale( $XYZValues = array() ) {
117 return $this->computeXYZ(
118 $XYZValues,
119 array(
120 'key' => 'scale',
121 'isUnitLess' => true,
122 )
123 );
124 }
125
126 function computeRotate( $rotateValues = array() ) {
127 $rotates = array();
128
129 $rotates = LodashBasic::concat(
130 $rotates,
131 $this->computeXYZ(
132 $rotateValues,
133 array(
134 'key' => 'rotate',
135 'defaultUnit' => 'deg',
136 )
137 )
138 );
139 return $rotates;
140 }
141
142 function computeSkew( $skewValues = array() ) {
143 $skews = $this->computeXYZ(
144 $skewValues,
145 array(
146 'key' => 'skew',
147 'defaultUnit' => 'deg',
148 )
149 );
150 return $skews;
151 }
152
153 function computeOrigin( $originOptions ) {
154 $transformOrigin = array(
155 'x' => $this->getOriginData( $originOptions, 'x.value', 'x.customValue' ),
156 'y' => $this->getOriginData( $originOptions, 'y.value', 'y.customValue' ),
157 'z' => $this->getOriginData( $originOptions, 'z.value', 'z.customValue' ),
158 );
159 return $transformOrigin;
160 }
161
162 function getOriginData( $originOptions, $valuePath, $customValuePath ) {
163 if ( LodashBasic::get( $originOptions, $valuePath ) === 'custom' ) {
164 $originX = LodashBasic::get( $originOptions, $customValuePath );
165 $result = ParserUtils::toValueUnitString( $originX );
166 } else {
167 $result = LodashBasic::get( $originOptions, $valuePath );
168 }
169
170 return $result;
171 }
172 }
173