| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\AtomicWidgets\Styles; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
/** |
| 10 |
* Projects an element's stored `styles` map into the MCP round-trip shape: |
| 11 |
* |
| 12 |
* [ |
| 13 |
* '__style_id' => 'e-widget1-abc1234', |
| 14 |
* 'css' => 'color: red; &:hover { color: blue; } @media(--mobile) { ... }', |
| 15 |
* ] |
| 16 |
* |
| 17 |
* The `css` value follows the same raw CSS format that the write-side tools |
| 18 |
* (manage-classes, manage-elements.update.style, build-composition.style) |
| 19 |
* accept as input, so consumers can round-trip styles without transformation. |
| 20 |
* |
| 21 |
* Rendering itself is delegated to `Local_Style` / `Local_Style_Variant` so each |
| 22 |
* domain object owns its own CSS output — the serializer only adapts the shape. |
| 23 |
*/ |
| 24 |
class Local_Style_Serializer { |
| 25 |
|
| 26 |
public static function serialize( array $styles ): array { |
| 27 |
$local_style = Local_Style::from_styles_map( $styles ); |
| 28 |
|
| 29 |
if ( null === $local_style ) { |
| 30 |
return []; |
| 31 |
} |
| 32 |
|
| 33 |
return [ |
| 34 |
'__style_id' => $local_style->id(), |
| 35 |
'css' => $local_style->to_css(), |
| 36 |
]; |
| 37 |
} |
| 38 |
} |
| 39 |
|