elementor
/
modules
/
mcp
/
abilities
/
appliers
/
v3
/
serializer
/
serializers
/
box-shadow-prefix-serializer.php
box-shadow-prefix-serializer.php in Elementor Website Builder – more than just a page builder trunk, at modules/mcp/abilities/appliers/v3/serializer/serializers/box-shadow-prefix-serializer.php
| 1 | <?php |
| 2 | |
| 3 | namespace Elementor\Modules\Mcp\Abilities\Appliers\V3\Serializer\Serializers; |
| 4 | |
| 5 | use Elementor\Modules\Mcp\Abilities\Appliers\V3\Serializer\V3_Block_Accumulator; |
| 6 | use Elementor\Modules\Mcp\Abilities\Appliers\V3\V3_Value_Formatters; |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * Inverse of {@see \Elementor\Modules\Mcp\Abilities\Appliers\V3\Converter\Converters\Box_Shadow_Prefix_Converter}. |
| 14 | * Reassembles `<prefix>_box_shadow_type` (visibility toggle) + `<prefix>_box_shadow` |
| 15 | * (shape) into `box-shadow: [inset ]<h> <v> <blur> <spread> <color>`. |
| 16 | */ |
| 17 | class Box_Shadow_Prefix_Serializer extends Base_Property_Serializer { |
| 18 | |
| 19 | public function is_supported( array $entry, string $property, ?string $state ): bool { |
| 20 | return isset( $entry['box_shadow_prefix'] ); |
| 21 | } |
| 22 | |
| 23 | public function emit( V3_Block_Accumulator $blocks, array $settings, array $entry, string $property, ?string $state ): void { |
| 24 | $prefix = (string) $entry['box_shadow_prefix']; |
| 25 | $type = $settings[ $prefix . '_box_shadow_type' ] ?? null; |
| 26 | $shadow = $settings[ $prefix . '_box_shadow' ] ?? null; |
| 27 | if ( 'yes' !== $type || ! is_array( $shadow ) ) { |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | $parts = [ |
| 32 | V3_Value_Formatters::format_size( $shadow['horizontal'] ?? 0 ), |
| 33 | V3_Value_Formatters::format_size( $shadow['vertical'] ?? 0 ), |
| 34 | V3_Value_Formatters::format_size( $shadow['blur'] ?? 0 ), |
| 35 | V3_Value_Formatters::format_size( $shadow['spread'] ?? 0 ), |
| 36 | ]; |
| 37 | if ( isset( $shadow['color'] ) && '' !== $shadow['color'] ) { |
| 38 | $parts[] = $shadow['color']; |
| 39 | } |
| 40 | if ( isset( $shadow['position'] ) && 'inset' === $shadow['position'] ) { |
| 41 | array_unshift( $parts, 'inset' ); |
| 42 | } |
| 43 | |
| 44 | $blocks->push( self::BASE_BREAKPOINT, $state, 'box-shadow', implode( ' ', $parts ) ); |
| 45 | } |
| 46 | } |
| 47 |