| @@ -3,14 +3,11 @@ | ||
| 3 | 3 | namespace Elementor\Modules\AtomicWidgets\Styles; |
| 4 | 4 | |
| 5 | 5 | use Elementor\Core\Utils\Collection; |
| 6 | 6 | use Elementor\Modules\AtomicWidgets\Module; |
| 7 | -use Elementor\Modules\AtomicWidgets\PropTypes\Contracts\Font_Enqueueable; | |
| 8 | -use Elementor\Modules\AtomicWidgets\PropTypes\Contracts\Prop_Type; | |
| 9 | -use Elementor\Modules\AtomicWidgets\PropTypes\Union_Prop_Type; | |
| 10 | -use Elementor\Modules\AtomicWidgets\PropsResolver\Render_Props_Resolver; | |
| 11 | 7 | use Elementor\Plugin; |
| 12 | 8 | use Elementor\Utils; |
| 9 | +use Elementor\Modules\AtomicWidgets\PropsResolver\Render_Props_Resolver; | |
| 13 | 10 | |
| 14 | 11 | class Styles_Renderer { |
| 15 | 12 | const DEFAULT_SELECTOR_PREFIX = '.elementor'; |
| 16 | 13 | |
| @@ -18,9 +15,9 @@ | ||
| 18 | 15 | * @var array<string, array{direction: 'min' | 'max', value: int, is_enabled: boolean}> |
| 19 | 16 | */ |
| 20 | 17 | private array $breakpoints; |
| 21 | 18 | |
| 22 | - private $on_font_enqueue; | |
| 19 | + private $on_prop_transform; | |
| 23 | 20 | |
| 24 | 21 | private string $selector_prefix; |
| 25 | 22 | |
| 26 | 23 | /** |
| @@ -64,10 +61,10 @@ | ||
| 64 | 61 | |
| 65 | 62 | return implode( '', $css_style ); |
| 66 | 63 | } |
| 67 | 64 | |
| 68 | - public function on_font_enqueue( callable $callback ): self { | |
| 69 | - $this->on_font_enqueue = $callback; | |
| 65 | + public function on_prop_transform( callable $callback ): self { | |
| 66 | + $this->on_prop_transform = $callback; | |
| 70 | 67 | |
| 71 | 68 | return $this; |
| 72 | 69 | } |
| 73 | 70 | |
| @@ -144,44 +141,16 @@ | ||
| 144 | 141 | $schema = Style_Schema::get(); |
| 145 | 142 | |
| 146 | 143 | return Collection::make( Render_Props_Resolver::for_styles()->resolve( $schema, $props ) ) |
| 147 | 144 | ->filter() |
| 148 | - ->map( function ( $value, $prop ) use ( $props, $schema ) { | |
| 149 | - $this->maybe_enqueue_font( $schema, $prop, $props[ $prop ] ?? null ); | |
| 145 | + ->map( function ( $value, $prop ) { | |
| 146 | + if ( $this->on_prop_transform ) { | |
| 147 | + call_user_func( $this->on_prop_transform, $prop, $value ); | |
| 148 | + } | |
| 150 | 149 | |
| 151 | 150 | return $prop . ':' . $value . ';'; |
| 152 | 151 | } ) |
| 153 | 152 | ->implode( '' ); |
| 154 | - } | |
| 155 | - | |
| 156 | - private function maybe_enqueue_font( array $schema, string $prop_key, $prop_value ): void { | |
| 157 | - if ( ! $this->on_font_enqueue || ! is_array( $prop_value ) || empty( $prop_value['value'] ) ) { | |
| 158 | - return; | |
| 159 | - } | |
| 160 | - | |
| 161 | - $enqueueable = $this->resolve_font_enqueueable( $schema[ $prop_key ] ?? null, $prop_value ); | |
| 162 | - | |
| 163 | - if ( ! $enqueueable ) { | |
| 164 | - return; | |
| 165 | - } | |
| 166 | - | |
| 167 | - $font = $enqueueable->get_enqueue_font_family( $prop_value['value'] ); | |
| 168 | - | |
| 169 | - if ( $font ) { | |
| 170 | - call_user_func( $this->on_font_enqueue, $font ); | |
| 171 | - } | |
| 172 | - } | |
| 173 | - | |
| 174 | - private function resolve_font_enqueueable( ?Prop_Type $prop_type, array $prop_value ): ?Font_Enqueueable { | |
| 175 | - if ( $prop_type instanceof Union_Prop_Type ) { | |
| 176 | - $prop_type = $prop_type->get_prop_type( $prop_value['$$type'] ?? '' ); | |
| 177 | - } | |
| 178 | - | |
| 179 | - if ( $prop_type instanceof Font_Enqueueable ) { | |
| 180 | - return $prop_type; | |
| 181 | - } | |
| 182 | - | |
| 183 | - return null; | |
| 184 | 153 | } |
| 185 | 154 | |
| 186 | 155 | private function custom_css_to_css_string( ?array $custom_css ): string { |
| 187 | 156 | return ! empty( $custom_css['raw'] ) |