PluginProbe
Depicter — Popup & Slider Builder / 1.6.2
Depicter — Popup & Slider Builder v1.6.2
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Document / Models / Common / Styles.php

Styles.php in Depicter — Popup & Slider Builder 1.6.2, at app/src/Document/Models/Common/Styles.php

229 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\Document\Models\Common;
3
4
5 use Depicter\Document\CSS\Breakpoints;
6
7 class Styles
8 {
9 /**
10 * @var Styles\Transform
11 */
12 public $transform;
13
14 /**
15 * @var Styles\Opacity
16 */
17 public $opacity;
18
19 /**
20 * @var Styles\BoxShadow
21 */
22 public $boxShadow;
23
24 /**
25 * @var Styles\BackgroundBlur
26 */
27 public $backgroundBlur;
28
29 /**
30 * @var Styles\BackgroundColor
31 */
32 public $backgroundColor;
33
34 /**
35 * @var Styles\Border
36 */
37 public $border;
38
39 /**
40 * @var Styles\Corner
41 */
42 public $corner;
43
44 /**
45 * @var Styles\Filter
46 */
47 public $filter;
48
49 /**
50 * @var Styles\TextShadow
51 */
52 public $textShadow;
53
54 /**
55 * @var Styles\Margin
56 */
57 public $margin;
58
59 /**
60 * @var Styles\Padding
61 */
62 public $padding;
63
64 /**
65 * @var Styles\BlendingMode
66 */
67 public $blendingMode;
68
69 /**
70 * @var Styles\Typography
71 */
72 public $typography;
73
74 /**
75 * @var Styles\Transition
76 */
77 public $transition;
78
79 /**
80 * @var Styles\Svg
81 */
82 public $svg;
83
84 /**
85 * @var Styles\Hover
86 */
87 public $hover;
88
89
90 /**
91 * Retrieves list of fonts used in typography options
92 *
93 * @return array
94 */
95 public function getFontsList()
96 {
97 if( !empty( $this->typography ) ){
98 return $this->typography->getFontsList();
99 }
100
101 return [];
102 }
103
104 /**
105 * Retrieves styles for all available modules
106 *
107 * @param array $states The states to generate style for
108 *
109 * @return array
110 */
111 public function getGeneralCss( $states = 'all' ) {
112 $cssModules = [
113 'filter',
114 'textShadow',
115 'opacity',
116 'padding',
117 'typography',
118 'boxShadow',
119 'transform',
120 'backgroundBlur',
121 'backgroundColor',
122 'border',
123 'corner',
124 'margin'
125 ];
126
127 return $this->generateCssForModules( $cssModules, $states );
128 }
129
130 /**
131 * Get styles for SVG
132 *
133 * @return array
134 */
135 public function getSvgCss() {
136 return $this->generateCssForModules( [ 'svg' ] );
137 }
138
139 /**
140 * Get transition CSS
141 *
142 * @return array
143 */
144 public function getTransitionCss() {
145 $css = $this->getInitialCssVariable();
146 /**
147 * While transition is defined in 'hover' property, we need to consider an exception to generate
148 * transition style for normal state not :hover
149 **/
150 $css = !empty( $this->hover->transition ) ? $this->hover->transition->set( $css ) : $css;
151
152 return $css;
153 }
154
155 /**
156 * Collects and retrieves responsive styles from css modules
157 *
158 * @param array|string $cssModules
159 * @param string $states The states to generate style for
160 *
161 * @return array
162 */
163 protected function generateCssForModules( $cssModules = [], $states = 'all' ){
164 $knownStates = ['normal', 'hover'];
165
166 // translate $states if string or null passed
167 if( is_string( $states ) ){
168 if( $states === 'all' ){
169 $states = $knownStates;
170 } elseif ( in_array( $states, $knownStates ) ){
171 $states = (array) $states;
172 }
173 }
174 if( is_null( $states ) ){
175 $states = $knownStates;
176 }
177
178 $css = $this->getInitialCssVariable();
179
180 // Collect styles from modules
181 foreach ( $cssModules as $cssModule ) {
182 if( in_array( 'normal', $states ) ){
183 $css = ! empty( $this->{$cssModule} ) ? $this->{$cssModule}->set( $css ) : $css;
184 }
185 if( in_array( 'hover', $states ) ){
186 $css['hover'] = !empty( $this->hover->{$cssModule} ) ? $this->hover->{$cssModule}->set( $css['hover'] ) : $css['hover'];
187 }
188 }
189
190 // check if hover style is disabled for one breakpoint then remove all the css modules for that breakpoint
191 if ( in_array( 'hover', $states ) ) {
192 $devices = Breakpoints::names();
193 foreach ( $devices as $device ) {
194 if ( empty( $this->hover->enable->{$device} ) ) {
195 $css['hover'][ $device ] = [];
196 }
197 }
198 }
199
200 return $css;
201 }
202
203 /**
204 * Retrieves a structured list for normal and hover states and breakpoints
205 *
206 * @return array
207 */
208 protected function getInitialCssVariable(){
209 $css = [];
210 $devices = Breakpoints::names();
211 foreach ( $devices as $device ) {
212 $css[ $device ] = [];
213 }
214 $css['hover'] = $css;
215
216 return $css;
217 }
218
219 /**
220 * Get blending mode styles
221 *
222 * @return array
223 */
224 public function getBlendingModeStyle(): array{
225 return $this->generateCssForModules(['blendingMode']);
226 }
227
228 }
229