PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.1
Elementor Website Builder – more than just a page builder v4.3.1
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 4.0.8 All 454 releases
elementor / modules / atomic-widgets / css-converter / value-parsers / css-token-splitter.php

css-token-splitter.php in Elementor Website Builder – more than just a page builder 4.3.1, at modules/atomic-widgets/css-converter/value-parsers/css-token-splitter.php

90 lines 1.7 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\AtomicWidgets\CssConverter\ValueParsers;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit; // Exit if accessed directly.
7 }
8
9 /**
10 * Stateless tokenizer shared by the box shorthands and shorthand expanders. Splits a CSS value on
11 * whitespace runs that sit at parenthesis depth 0, so function values such as calc(50% - 10px) or
12 * rgb(0, 0, 0) stay intact as a single token.
13 */
14 class Css_Token_Splitter {
15 /**
16 * Split a CSS value on top-level commas (paren-aware), trimming each segment.
17 *
18 * @return string[]
19 */
20 public static function split_by_comma( string $value ): array {
21 $tokens = [];
22 $current = '';
23 $depth = 0;
24 $length = strlen( $value );
25
26 for ( $i = 0; $i < $length; $i++ ) {
27 $char = $value[ $i ];
28
29 if ( '(' === $char ) {
30 ++$depth;
31 } elseif ( ')' === $char ) {
32 $depth = max( 0, $depth - 1 );
33 }
34
35 if ( 0 === $depth && ',' === $char ) {
36 $tokens[] = trim( $current );
37 $current = '';
38 continue;
39 }
40
41 $current .= $char;
42 }
43
44 $last = trim( $current );
45
46 if ( '' !== $last ) {
47 $tokens[] = $last;
48 }
49
50 return $tokens;
51 }
52
53 /**
54 * @return string[]
55 */
56 public static function split_by_whitespace( string $value ): array {
57 $tokens = [];
58 $current = '';
59 $depth = 0;
60 $length = strlen( $value );
61
62 for ( $i = 0; $i < $length; $i++ ) {
63 $char = $value[ $i ];
64
65 if ( '(' === $char ) {
66 ++$depth;
67 } elseif ( ')' === $char ) {
68 $depth = max( 0, $depth - 1 );
69 }
70
71 if ( 0 === $depth && ( ' ' === $char || "\t" === $char || "\n" === $char ) ) {
72 if ( '' !== $current ) {
73 $tokens[] = $current;
74 $current = '';
75 }
76
77 continue;
78 }
79
80 $current .= $char;
81 }
82
83 if ( '' !== $current ) {
84 $tokens[] = $current;
85 }
86
87 return $tokens;
88 }
89 }
90