PluginProbe
Elementor Website Builder – more than just a page builder / 4.1.2
Elementor Website Builder – more than just a page builder v4.1.2
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.1.2, at modules/variables/classes/size-style-schema.php

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