← All changes
|
modules/atomic-widgets/css-converter/converters/size-property-converter.php
+19
-0
4.2.2
→
trunk
View file →
| @@ -5,8 +5,9 @@ | ||
| 5 | 5 | use Elementor\Modules\AtomicWidgets\CssConverter\Conversion_Context; |
| 6 | 6 | use Elementor\Modules\AtomicWidgets\CssConverter\Property_Converter_Base; |
| 7 | 7 | use Elementor\Modules\AtomicWidgets\CssConverter\ValueParsers\Size_Value_Parser; |
| 8 | 8 | use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type; |
| 9 | +use Elementor\Modules\AtomicWidgets\Styles\Size_Constants; | |
| 9 | 10 | |
| 10 | 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | 12 | exit; // Exit if accessed directly. |
| 12 | 13 | } |
| @@ -28,8 +29,26 @@ | ||
| 28 | 29 | } |
| 29 | 30 | |
| 30 | 31 | protected function get_supported_properties(): array { |
| 31 | 32 | return [ $this->property ]; |
| 33 | + } | |
| 34 | + | |
| 35 | + protected function get_custom_converter( Conversion_Context $context, array $rule ): ?callable { | |
| 36 | + if ( 'opacity' !== $rule['property'] || ! preg_match( '/^-?\d*\.?\d+$/', $rule['value'] ?? '' ) ) { | |
| 37 | + return null; | |
| 38 | + } | |
| 39 | + | |
| 40 | + return function() use ( $context, $rule ) { | |
| 41 | + $constrained = max( 0.0, min( (float) $rule['value'], 1.0 ) ); | |
| 42 | + $size = round( $constrained * 100, 4 ); | |
| 43 | + | |
| 44 | + $context->set_prop( 'opacity', Size_Prop_Type::generate( [ | |
| 45 | + 'size' => 0.0 === $size ? 0 : $size, | |
| 46 | + 'unit' => Size_Constants::UNIT_PERCENT, | |
| 47 | + ] ) ); | |
| 48 | + | |
| 49 | + return true; | |
| 50 | + }; | |
| 32 | 51 | } |
| 33 | 52 | |
| 34 | 53 | protected function do_convert( Conversion_Context $context, array $rule ): bool { |
| 35 | 54 | $parsed = Size_Value_Parser::parse( $rule['value'], $this->allow_unitless ); |