PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.2
Elementor Website Builder – more than just a page builder v4.3.2
4.3.2 4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 All 455 releases
elementor / modules / mcp / abilities / appliers / v3 / mapper / css-declaration-parser.php

css-declaration-parser.php in Elementor Website Builder – more than just a page builder 4.3.2, at modules/mcp/abilities/appliers/v3/mapper/css-declaration-parser.php

57 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\Mcp\Abilities\Appliers\V3\Mapper;
4
5 use Elementor\Modules\Mcp\Abilities\Utils\Style_Variants_Merger;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit;
9 }
10
11 /**
12 * Extracts `property: value` declarations from a CSS block and normalizes selector
13 * fragments into V3 pseudo-states (hover|focus|active or null).
14 */
15 class Css_Declaration_Parser {
16
17 /**
18 * @return array<int, array{property: string, value: string}>
19 */
20 public function parse_declarations( string $css ): array {
21 $rules = [];
22
23 foreach ( explode( ';', $css ) as $declaration ) {
24 $declaration = trim( $declaration );
25 $separator = strpos( $declaration, ':' );
26
27 if ( false === $separator ) {
28 continue;
29 }
30
31 $property = strtolower( trim( substr( $declaration, 0, $separator ) ) );
32 $value = trim( substr( $declaration, $separator + 1 ) );
33
34 if ( '' === $property || '' === $value || 'null' === $value ) {
35 continue;
36 }
37
38 $rules[] = [
39 'property' => $property,
40 'value' => $value,
41 ];
42 }
43
44 return $rules;
45 }
46
47 public function normalize_state( ?string $selector ): ?string {
48 if ( null === $selector || '' === $selector ) {
49 return null;
50 }
51
52 $state = strtolower( ltrim( $selector, ':' ) );
53
54 return in_array( $state, Style_Variants_Merger::PSEUDO_STATES, true ) ? $state : null;
55 }
56 }
57