PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.3
Elementor Website Builder – more than just a page builder v4.2.3
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 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / modules / variables / classes / size-style-schema.php

size-style-schema.php in Elementor Website Builder – more than just a page builder 4.2.3, at modules/variables/classes/size-style-schema.php

117 lines 3.2 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\Variables\Classes;
4
5 use Elementor\Modules\AtomicWidgets\PropTypes\Base\Array_Prop_Type;
6 use Elementor\Modules\AtomicWidgets\PropTypes\Base\Object_Prop_Type;
7 use Elementor\Modules\AtomicWidgets\PropTypes\Grid_Track_Size_Prop_Type;
8 use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type;
9 use Elementor\Modules\AtomicWidgets\PropTypes\Union_Prop_Type;
10 use Elementor\Modules\AtomicWidgets\Styles\Size_Constants;
11 use Elementor\Modules\Variables\PropTypes\Size_Variable_Prop_Type;
12 use Elementor\Utils as ElementorUtils;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly.
16 }
17
18 class Size_Style_Schema {
19 private const PRO_VERSION_FOR_GRID_TRACK_VARIABLES = '4.2';
20
21 private $units_to_skip = [];
22
23 public function __construct() {
24 $this->units_to_skip = [
25 ...Size_Constants::angle(),
26 ...Size_Constants::time(),
27 ];
28 }
29
30 private function skip_by_units( Size_Prop_Type $size_prop_type ) {
31 $settings = $size_prop_type->get_settings();
32
33 if ( ! array_key_exists( 'available_units', $settings ) ) {
34 return false;
35 }
36
37 $available_units = $settings['available_units'];
38
39 return count( array_intersect( $available_units, $this->units_to_skip ) ) > 0;
40 }
41
42 public function augment( array $schema ): array {
43 foreach ( $schema as $css_property => $prop_type ) {
44 $schema[ $css_property ] = $this->update( $prop_type );
45 }
46
47 return $schema;
48 }
49
50 private function update( $prop_type ) {
51 if ( $prop_type instanceof Size_Prop_Type ) {
52 return $this->update_size( $prop_type );
53 }
54
55 if ( $prop_type instanceof Union_Prop_Type ) {
56 return $this->update_union( $prop_type );
57 }
58
59 if ( $prop_type instanceof Object_Prop_Type ) {
60 return $this->update_object( $prop_type );
61 }
62
63 if ( $prop_type instanceof Array_Prop_Type ) {
64 return $this->update_array( $prop_type );
65 }
66
67 return $prop_type;
68 }
69
70 private function update_size( Size_Prop_Type $size_prop_type ) {
71 if ( $this->skip_by_units( $size_prop_type ) ) {
72 return $size_prop_type;
73 }
74
75 if (
76 $size_prop_type instanceof Grid_Track_Size_Prop_Type
77 && ! $this->is_grid_track_variables_supported_by_pro()
78 ) {
79 return $size_prop_type;
80 }
81
82 return Union_Prop_Type::create_from( $size_prop_type )
83 ->add_prop_type( Size_Variable_Prop_Type::make() );
84 }
85
86 private function is_grid_track_variables_supported_by_pro(): bool {
87 return ElementorUtils::has_pro()
88 && version_compare( ELEMENTOR_PRO_VERSION, self::PRO_VERSION_FOR_GRID_TRACK_VARIABLES, '>=' );
89 }
90
91 private function update_array( Array_Prop_Type $array_prop_type ): Array_Prop_Type {
92 return $array_prop_type->set_item_type(
93 $this->update( $array_prop_type->get_item_type() )
94 );
95 }
96
97 private function update_object( Object_Prop_Type $object_prop_type ): Object_Prop_Type {
98 return $object_prop_type->set_shape(
99 $this->augment( $object_prop_type->get_shape() )
100 );
101 }
102
103 private function update_union( Union_Prop_Type $union_prop_type ): Union_Prop_Type {
104 foreach ( $union_prop_type->get_prop_types() as $prop_type ) {
105 $updated = $this->update( $prop_type );
106
107 if ( $updated instanceof Union_Prop_Type ) {
108 foreach ( $updated->get_prop_types() as $updated_prop_type ) {
109 $union_prop_type->add_prop_type( $updated_prop_type );
110 }
111 }
112 }
113
114 return $union_prop_type;
115 }
116 }
117