PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0
Elementor Website Builder – more than just a page builder v4.3.0
4.3.2 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 All 455 releases
elementor / modules / atomic-widgets / css-converter / converters / border-radius-property-converter.php

border-radius-property-converter.php in Elementor Website Builder – more than just a page builder 4.3.0, at modules/atomic-widgets/css-converter/converters/border-radius-property-converter.php

62 lines 2.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\AtomicWidgets\CssConverter\Converters;
4
5 use Elementor\Modules\AtomicWidgets\CssConverter\Conversion_Context;
6 use Elementor\Modules\AtomicWidgets\CssConverter\Property_Converter_Base;
7 use Elementor\Modules\AtomicWidgets\CssConverter\ValueParsers\Box_Shorthand_Parser;
8 use Elementor\Modules\AtomicWidgets\PropTypes\Border_Radius_Prop_Type;
9 use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly.
13 }
14
15 /**
16 * Reusable converter for border-radius (Union(Border_Radius | Size)). One instance per property.
17 * Delegates tokenizing/expansion to Box_Shorthand_Parser; a null parse declines (-> custom_css).
18 *
19 * A single token emits the Size member. Two-to-four tokens expand via the CSS corner rule
20 * (top-left/top-right/bottom-right/bottom-left) and map physical->logical (TL=start-start,
21 * TR=start-end, BR=end-end, BL=end-start) into a Border_Radius PropValue. Elliptical values (a "/"
22 * separating horizontal/vertical radii) cannot be modeled by the single-Size-per-corner shape, so
23 * they decline to custom_css — the parser already rejects the "/" form while keeping calc() division
24 * (a single paren-wrapped token) convertible.
25 */
26 class Border_Radius_Property_Converter extends Property_Converter_Base {
27 private string $property;
28
29 public function __construct( string $property ) {
30 $this->property = $property;
31 }
32
33 protected function get_supported_properties(): array {
34 return [ $this->property ];
35 }
36
37 protected function do_convert( Conversion_Context $context, array $rule ): bool {
38 $parsed = Box_Shorthand_Parser::parse( $rule['value'] );
39
40 if ( null === $parsed ) {
41 return false;
42 }
43
44 if ( isset( $parsed['single'] ) ) {
45 $context->set_prop( $this->property, Size_Prop_Type::generate( $parsed['single'] ) );
46
47 return true;
48 }
49
50 [ $top_left, $top_right, $bottom_right, $bottom_left ] = $parsed['sides'];
51
52 $context->set_prop( $this->property, Border_Radius_Prop_Type::generate( [
53 'start-start' => Size_Prop_Type::generate( $top_left ),
54 'start-end' => Size_Prop_Type::generate( $top_right ),
55 'end-end' => Size_Prop_Type::generate( $bottom_right ),
56 'end-start' => Size_Prop_Type::generate( $bottom_left ),
57 ] ) );
58
59 return true;
60 }
61 }
62