| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\AtomicWidgets\CssConverter; |
| 4 |
|
| 5 |
use Elementor\Modules\AtomicWidgets\CssConverter\Expanders\Background_Shorthand_Expander; |
| 6 |
use Elementor\Modules\AtomicWidgets\CssConverter\Expanders\Border_Shorthand_Expander; |
| 7 |
use Elementor\Modules\AtomicWidgets\CssConverter\Expanders\Outline_Shorthand_Expander; |
| 8 |
use Elementor\Modules\AtomicWidgets\CssConverter\Expanders\Physical_To_Logical_Expander; |
| 9 |
use Elementor\Modules\AtomicWidgets\Styles\Style_Schema; |
| 10 |
use Elementor\Modules\Variables\Services\Variables_Service; |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; // Exit if accessed directly. |
| 14 |
} |
| 15 |
|
| 16 |
class Expander_Registry_Factory { |
| 17 |
const BORDER_SIDES = [ 'top', 'right', 'bottom', 'left' ]; |
| 18 |
|
| 19 |
public static function create( ?Variables_Service $variables_service = null ): Expander_Registry { |
| 20 |
$schema = Style_Schema::get_style_schema(); |
| 21 |
$style_enum = $schema['border-style']->get_enum(); |
| 22 |
|
| 23 |
$registry = ( new Expander_Registry() ) |
| 24 |
->register( new Physical_To_Logical_Expander() ) |
| 25 |
->register( new Background_Shorthand_Expander( $variables_service ) ) |
| 26 |
->register( new Outline_Shorthand_Expander() ) |
| 27 |
->register( new Border_Shorthand_Expander( 'border', self::border_longhands( '' ), $style_enum, $variables_service ) ); |
| 28 |
|
| 29 |
foreach ( self::BORDER_SIDES as $side ) { |
| 30 |
$registry->register( |
| 31 |
new Border_Shorthand_Expander( "border-$side", self::border_longhands( "$side-" ), $style_enum, $variables_service ) |
| 32 |
); |
| 33 |
} |
| 34 |
|
| 35 |
return $registry; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Role -> longhand property name for the all-sides (`border`, infix '') or per-side (e.g. 'top-') |
| 40 |
* shorthand. Per-side style/color have no converter and route to custom_css. |
| 41 |
* |
| 42 |
* @return array<string, string> |
| 43 |
*/ |
| 44 |
public static function border_longhands( string $infix ): array { |
| 45 |
return [ |
| 46 |
Border_Shorthand_Expander::ROLE_WIDTH => "border-{$infix}width", |
| 47 |
Border_Shorthand_Expander::ROLE_STYLE => "border-{$infix}style", |
| 48 |
Border_Shorthand_Expander::ROLE_COLOR => "border-{$infix}color", |
| 49 |
]; |
| 50 |
} |
| 51 |
} |
| 52 |
|