/var/www/html/wp-content/plugins/elementor/modules/atomic-widgets/styles/atomic-widget-styles.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php

namespace Elementor\Modules\AtomicWidgets\Styles;

use 
Elementor\Core\Files\CSS\Post;
use 
Elementor\Element_Base;
use 
Elementor\Modules\AtomicWidgets\Base\Atomic_Element_Base;
use 
Elementor\Modules\AtomicWidgets\Base\Atomic_Widget_Base;
use 
Elementor\Plugin;

class 
Atomic_Widget_Styles {
    public function 
register_hooks() {
        
add_action'elementor/element/parse_css', fn( Post $postElement_Base $element ) => $this->parse_element_style$post$element ), 10);
    }

    private function 
parse_element_stylePost $postElement_Base $element ) {
        if ( ! ( 
$element instanceof Atomic_Widget_Base || $element instanceof Atomic_Element_Base )
            || 
Post::class !== get_class$post ) ) {
            return;
        }

        
$styles $element->get_raw_data()['styles'];

        if ( empty( 
$styles ) ) {
            return;
        }

        
$this->styles_enqueue_fonts$styles );

        
$css Styles_Renderer::make( [
            
'breakpoints' => Plugin::$instance->breakpoints->get_breakpoints_config(),
        ] )->
render$styles );

        
$post->get_stylesheet()->add_raw_css$css );
    }

    
/**
     * @param array<int, array{
     *     id: string,
     *     type: string,
     *     variants: array<int, array{
     *         props: array<string, mixed>,
     *         meta: array<string, mixed>
     *     }>
     * }> $styles
     */
    
private function styles_enqueue_fonts( array $styles ): void {
        foreach ( 
$styles as $style ) {
            foreach ( 
$style['variants'] as $variant ) {
                if ( isset( 
$variant['props']['font-family'] ) ) {
                    
Plugin::$instance->frontend->enqueue_font$variant['props']['font-family'] );
                }
            }
        }
    }
}