PluginProbe
Elementor Website Builder – more than just a page builder / 4.1.0-beta2
Elementor Website Builder – more than just a page builder v4.1.0-beta2
4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 All 454 releases
elementor / modules / atomic-widgets / styles / size-constants.php

size-constants.php in Elementor Website Builder – more than just a page builder 4.1.0-beta2, at modules/atomic-widgets/styles/size-constants.php

288 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\AtomicWidgets\Styles;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit; // Exit if accessed directly.
7 }
8
9 class Size_Constants {
10 const UNIT_PX = 'px';
11 const UNIT_PERCENT = '%';
12 const UNIT_EM = 'em';
13 const UNIT_REM = 'rem';
14 const UNIT_VW = 'vw';
15 const UNIT_VH = 'vh';
16 const UNIT_CH = 'ch';
17 const UNIT_VMIN = 'vmin';
18 const UNIT_VMAX = 'vmax';
19 const UNIT_SECOND = 's';
20 const UNIT_MILLI_SECOND = 'ms';
21 const UNIT_DEG = 'deg';
22 const UNIT_RAD = 'rad';
23 const UNIT_GRAD = 'grad';
24 const UNIT_TURN = 'turn';
25 const UNIT_AUTO = 'auto';
26 const UNIT_CUSTOM = 'custom';
27
28 const DEFAULT_UNIT = self::UNIT_PX;
29
30 private const ORDER = [
31 self::UNIT_PX,
32 self::UNIT_PERCENT,
33 self::UNIT_EM,
34 self::UNIT_REM,
35 self::UNIT_VW,
36 self::UNIT_VH,
37 self::UNIT_CH,
38 self::UNIT_VMIN,
39 self::UNIT_VMAX,
40 self::UNIT_DEG,
41 self::UNIT_RAD,
42 self::UNIT_GRAD,
43 self::UNIT_TURN,
44 self::UNIT_SECOND,
45 self::UNIT_MILLI_SECOND,
46 self::UNIT_AUTO,
47 self::UNIT_CUSTOM,
48 ];
49
50 private const LENGTH_UNITS = [
51 self::UNIT_PX,
52 self::UNIT_EM,
53 self::UNIT_REM,
54 self::UNIT_VW,
55 self::UNIT_VH,
56 self::UNIT_CH,
57 ];
58
59 private const TIME_UNITS = [
60 self::UNIT_MILLI_SECOND,
61 self::UNIT_SECOND,
62 ];
63
64 private const ANGLE_UNITS = [
65 self::UNIT_DEG,
66 self::UNIT_RAD,
67 self::UNIT_GRAD,
68 self::UNIT_TURN,
69 ];
70
71 private const EXTENDED_UNITS = [
72 self::UNIT_AUTO,
73 self::UNIT_CUSTOM,
74 ];
75
76 private const VIEWPORT_MIN_MAX_UNITS = [
77 self::UNIT_VMIN,
78 self::UNIT_VMAX,
79 ];
80
81 private const NUMERIC_UNITS = [
82 ...self::LENGTH_UNITS,
83 self::UNIT_PERCENT,
84 self::UNIT_CUSTOM,
85 ];
86
87 private static function presets(): array {
88 return [
89 'layout' => self::sort_by_preferred_order( self::NUMERIC_UNITS ),
90 'spacing' => self::sort_by_preferred_order( self::NUMERIC_UNITS ),
91 'position' => self::NUMERIC_UNITS,
92 'typography' => self::NUMERIC_UNITS,
93 'border' => self::NUMERIC_UNITS,
94 'box_shadow' => self::NUMERIC_UNITS,
95 'transform' => self::NUMERIC_UNITS,
96
97 'spacing_margin' => self::standard_units(),
98
99 'anchor_offset' => [
100 ...self::LENGTH_UNITS,
101 self::UNIT_CUSTOM,
102 ],
103
104 'stroke_width' => [
105 self::UNIT_PX,
106 self::UNIT_EM,
107 self::UNIT_REM,
108 self::UNIT_CUSTOM,
109 ],
110
111 'transition' => [
112 ...self::TIME_UNITS,
113 self::UNIT_CUSTOM,
114 ],
115
116 'opacity' => [
117 self::UNIT_PERCENT,
118 self::UNIT_CUSTOM,
119 ],
120
121 'rotate' => [
122 ...self::ANGLE_UNITS,
123 self::UNIT_CUSTOM,
124 ],
125
126 'drop_shadow' => [
127 ...self::LENGTH_UNITS,
128 self::UNIT_CUSTOM,
129 ],
130
131 'blur_filter' => [
132 ...self::LENGTH_UNITS,
133 self::UNIT_CUSTOM,
134 ],
135
136 'intensity_filter' => [
137 self::UNIT_PERCENT,
138 self::UNIT_CUSTOM,
139 ],
140
141 'color_tone_filter' => [
142 self::UNIT_PERCENT,
143 self::UNIT_CUSTOM,
144 ],
145
146 'hue_rotate_filter' => [
147 ...self::ANGLE_UNITS,
148 self::UNIT_CUSTOM,
149 ],
150 ];
151 }
152
153 private static function sort_by_preferred_order( array $units ): array {
154 $index = array_flip( self::ORDER );
155
156 usort( $units, fn( $a, $b ) =>
157 ( $index[ $a ] ?? PHP_INT_MAX ) <=> ( $index[ $b ] ?? PHP_INT_MAX )
158 );
159
160 return $units;
161 }
162
163 public static function standard_units(): array {
164 return self::sort_by_preferred_order( [
165 ...self::LENGTH_UNITS,
166 self::UNIT_PERCENT,
167 self::UNIT_AUTO,
168 self::UNIT_CUSTOM,
169 ] );
170 }
171
172 public static function all_supported_units(): array {
173 return [
174 ...self::LENGTH_UNITS,
175 ...self::TIME_UNITS,
176 ...self::ANGLE_UNITS,
177 ...self::EXTENDED_UNITS,
178 ...self::VIEWPORT_MIN_MAX_UNITS,
179 self::UNIT_PERCENT,
180 ];
181 }
182
183 public static function grouped_units(): array {
184 return [
185 'length' => self::LENGTH_UNITS,
186 'angle' => self::ANGLE_UNITS,
187 'time' => self::TIME_UNITS,
188 'extended_units' => self::EXTENDED_UNITS,
189 ];
190 }
191
192 private static function by_group( string $group ): array {
193 $groups = self::grouped_units();
194
195 return $groups[ $group ] ?? [];
196 }
197
198 public static function get_preset( string $name ): array {
199 $presets = self::presets();
200
201 return $presets[ $name ] ?? [];
202 }
203
204 public static function length(): array {
205 return self::by_group( 'length' );
206 }
207
208 public static function time(): array {
209 return self::by_group( 'time' );
210 }
211
212 public static function angle(): array {
213 return self::by_group( 'angle' );
214 }
215
216 public static function layout(): array {
217 return self::get_preset( 'layout' );
218 }
219
220 public static function spacing_margin(): array {
221 return self::get_preset( 'spacing_margin' );
222 }
223
224 public static function spacing(): array {
225 return self::get_preset( 'spacing' );
226 }
227
228 public static function position(): array {
229 return self::get_preset( 'position' );
230 }
231
232 public static function anchor_offset(): array {
233 return self::get_preset( 'anchor_offset' );
234 }
235
236 public static function typography(): array {
237 return self::get_preset( 'typography' );
238 }
239
240 public static function stroke_width(): array {
241 return self::get_preset( 'stroke_width' );
242 }
243
244 public static function transition(): array {
245 return self::get_preset( 'transition' );
246 }
247
248 public static function border(): array {
249 return self::get_preset( 'border' );
250 }
251
252 public static function opacity(): array {
253 return self::get_preset( 'opacity' );
254 }
255
256 public static function box_shadow(): array {
257 return self::get_preset( 'box_shadow' );
258 }
259
260 public static function rotate(): array {
261 return self::get_preset( 'rotate' );
262 }
263
264 public static function transform(): array {
265 return self::get_preset( 'transform' );
266 }
267
268 public static function drop_shadow(): array {
269 return self::get_preset( 'drop_shadow' );
270 }
271
272 public static function blur_filter(): array {
273 return self::get_preset( 'blur_filter' );
274 }
275
276 public static function intensity_filter(): array {
277 return self::get_preset( 'intensity_filter' );
278 }
279
280 public static function color_tone_filter(): array {
281 return self::get_preset( 'color_tone_filter' );
282 }
283
284 public static function hue_rotate_filter(): array {
285 return self::get_preset( 'hue_rotate_filter' );
286 }
287 }
288