base-css-compiler.php
2 years ago
border-css-compiler.php
2 years ago
border-radius-css-compiler.php
2 years ago
base-css-compiler.php
77 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Modules\Jet_Style\Css_Compilers; |
| 5 | |
| 6 | use Jet_Form_Builder\Classes\Arrayable\Array_Tools; |
| 7 | |
| 8 | // If this file is called directly, abort. |
| 9 | if ( ! defined( 'WPINC' ) ) { |
| 10 | die; |
| 11 | } |
| 12 | |
| 13 | /** |
| 14 | * @since 3.1.0 |
| 15 | * |
| 16 | * Class Base_Css_Compiler |
| 17 | * @package Jet_Form_Builder\Compatibility\Wp_Experiments\Css_Compilers |
| 18 | */ |
| 19 | class Base_Css_Compiler { |
| 20 | |
| 21 | /** |
| 22 | * @var string |
| 23 | */ |
| 24 | protected $css_var; |
| 25 | protected $path; |
| 26 | |
| 27 | // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found |
| 28 | public function is_supported( array $path ): bool { |
| 29 | return true; |
| 30 | } |
| 31 | |
| 32 | // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed |
| 33 | public function compile_declarations( |
| 34 | \WP_Style_Engine_CSS_Declarations $declarations, |
| 35 | array $root_styles, |
| 36 | array &$class_names |
| 37 | ) { |
| 38 | $declarations->add_declaration( |
| 39 | $this->css_var, |
| 40 | Array_Tools::get( $root_styles, $this->path, '' ) |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | public function compile_class_names( |
| 45 | array &$class_names, |
| 46 | array $root_styles |
| 47 | ) { |
| 48 | if ( ! $this->has_hover_path() || |
| 49 | empty( Array_Tools::get( $root_styles, $this->path, '' ) ) |
| 50 | ) { |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | // remove selector from path |
| 55 | $without_first = array_slice( $this->path, 1 ); |
| 56 | |
| 57 | $class_names[] = 'has-hover-' . implode( '-', $without_first ); |
| 58 | } |
| 59 | |
| 60 | protected function has_hover_path(): bool { |
| 61 | return false !== strpos( $this->path[0], ':hover' ); |
| 62 | } |
| 63 | |
| 64 | public function set_css_var( string $name ): Base_Css_Compiler { |
| 65 | $this->css_var = $name; |
| 66 | |
| 67 | return $this; |
| 68 | } |
| 69 | |
| 70 | public function set_path( array $path ): Base_Css_Compiler { |
| 71 | $this->path = $path; |
| 72 | |
| 73 | return $this; |
| 74 | } |
| 75 | |
| 76 | } |
| 77 |