| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\Mcp\Abilities\Appliers\V3\Mapper; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
/** |
| 10 |
* Re-serializes CSS fragments that could not be mapped to V3 settings, back into a |
| 11 |
* single CSS string suitable for V3's `custom_css`. Wraps state fragments as `&:state` |
| 12 |
* and non-desktop breakpoints as `@media(--breakpoint) { ... }`. |
| 13 |
*/ |
| 14 |
class Unmapped_Css_Serializer { |
| 15 |
|
| 16 |
public function serialize_declaration( string $breakpoint, ?string $state, string $property, string $value ): string { |
| 17 |
$decl = $property . ': ' . $value . ';'; |
| 18 |
|
| 19 |
if ( null !== $state ) { |
| 20 |
$decl = '&:' . $state . ' { ' . $decl . ' }'; |
| 21 |
} |
| 22 |
|
| 23 |
return $this->serialize_breakpoint_block( $breakpoint, $decl ); |
| 24 |
} |
| 25 |
|
| 26 |
public function serialize_nested_block( string $breakpoint, string $selector, string $css ): string { |
| 27 |
$inner = '&' . $selector . ' { ' . trim( $css ) . ' }'; |
| 28 |
|
| 29 |
return $this->serialize_breakpoint_block( $breakpoint, $inner ); |
| 30 |
} |
| 31 |
|
| 32 |
public function serialize_breakpoint_block( string $breakpoint, string $css ): string { |
| 33 |
$css = trim( $css ); |
| 34 |
if ( '' === $css ) { |
| 35 |
return ''; |
| 36 |
} |
| 37 |
|
| 38 |
if ( Responsive_Key_Resolver::BASE_BREAKPOINT === $breakpoint ) { |
| 39 |
return $css; |
| 40 |
} |
| 41 |
|
| 42 |
return '@media(--' . $breakpoint . ') { ' . $css . ' }'; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* @param string[] $parts |
| 47 |
*/ |
| 48 |
public function join( array $parts ): string { |
| 49 |
$parts = array_values( array_filter( array_map( 'trim', $parts ) ) ); |
| 50 |
|
| 51 |
return implode( ' ', $parts ); |
| 52 |
} |
| 53 |
} |
| 54 |
|