PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 1.2.3
Kubio AI Page Builder v1.2.3
2.8.5 2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / lib / src / Core / StyleManager / StyleParser.php
kubio / lib / src / Core / StyleManager Last commit date
Generics 4 years ago Props 4 years ago BlockStyleRender.php 4 years ago DynamicStyles.php 4 years ago GlobalStyleRender.php 4 years ago MainAttribute.php 4 years ago ParserUtils.php 4 years ago StyleManager.php 4 years ago StyleParser.php 4 years ago StyleRender.php 4 years ago Utils.php 4 years ago
StyleParser.php
127 lines
1 <?php
2
3 namespace Kubio\Core\StyleManager;
4
5 use Kubio\Core\LodashBasic;
6 use Kubio\Core\StyleManager\Props\Animation;
7 use Kubio\Core\StyleManager\Props\Background;
8 use Kubio\Core\StyleManager\Props\Border;
9 use Kubio\Core\StyleManager\Props\BoxShadow;
10 use Kubio\Core\StyleManager\Props\ColumnWidth;
11 use Kubio\Core\StyleManager\Props\CustomHeight;
12 use Kubio\Core\StyleManager\Props\Height;
13 use Kubio\Core\StyleManager\Props\MultipleImage;
14 use Kubio\Core\StyleManager\Props\Opacity;
15 use Kubio\Core\StyleManager\Props\Size;
16 use Kubio\Core\StyleManager\Props\Stroke;
17 use Kubio\Core\StyleManager\Props\TBLR;
18 use Kubio\Core\StyleManager\Props\TextShadow;
19 use Kubio\Core\StyleManager\Props\Transform;
20 use Kubio\Core\StyleManager\Props\Transition;
21 use Kubio\Core\StyleManager\Props\Typography;
22 use Kubio\Core\StyleManager\Props\Width;
23 use Kubio\Core\StyleManager\Props\Gap;
24 use Kubio\Core\StyleManager\Props\UnitValuePercentage;
25 use Kubio\Core\StyleManager\Props\ObjectCss;
26 use Kubio\Core\StyleManager\Props\MaxWidth;
27
28 class StyleParser {
29
30 public $groups;
31 public static $instance = null;
32
33 protected function __construct() {
34 $properties = array(
35 new Background( 'background' ),
36 new TBLR( 'padding' ),
37 new TBLR( 'margin' ),
38 new ColumnWidth( 'columnWidth' ),
39 new CustomHeight( 'customHeight' ),
40 new BoxShadow( 'boxShadow' ),
41 new TextShadow( 'textShadow' ),
42 new Border( 'border' ),
43 new Typography( 'typography' ),
44 new Size( 'size' ),
45 new Transform( 'transform' ),
46 new Opacity( 'opacity' ),
47 new Gap( 'gap' ),
48 new Width( 'width' ),
49 new Height( 'height' ),
50 new Stroke( 'stroke' ),
51 new MultipleImage( 'multipleImage' ),
52 new UnitValuePercentage( 'top' ),
53 new UnitValuePercentage( 'right' ),
54 new UnitValuePercentage( 'bottom' ),
55 new UnitValuePercentage( 'left' ),
56 new MaxWidth( 'maxWidth' ),
57 new UnitValuePercentage( 'maxHeight' ),
58 new UnitValuePercentage( 'minHeight' ),
59 new ObjectCss( 'object' ),
60 new Animation( 'animation' ),
61 new Transition( 'transition' ),
62 );
63
64 $this->groups = array();
65 foreach ( $properties as $property ) {
66 $this->addProperty( $property->name, $property );
67 }
68 }
69
70 public static function getInstance() {
71 if ( ! self::$instance ) {
72 self::$instance = new StyleParser();
73 }
74 return self::$instance;
75 }
76
77 public function evaluateString( $value ) {
78 return $value;
79 }
80
81 public function addProperty( $name, $property ) {
82 $this->groups[ $name ] = $property;
83 }
84
85 public function evaluate( $value ) {
86 if ( LodashBasic::isString( $value ) ) {
87 return $this->evaluateString( $value );
88 }
89 if ( is_array( $value ) ) {
90 foreach ( $value as $name => $val ) {
91 $value[ $name ] = $this->evaluate( $val );
92 }
93 }
94 return $value;
95 }
96
97 public function transform( $obj, $context, $skipNormal = false ) {
98 if ( ! $obj ) {
99 return;
100 }
101 $css = array();
102 foreach ( $obj as $prop => $___ ) {
103 if ( isset( $this->groups[ $prop ] ) ) {
104 if ( LodashBasic::isString( $obj[ $prop ] ) ) {
105 $css = LodashBasic::merge( $css, $this->evaluate( array( 'prop' => $obj[ $prop ] ) ) );
106 } else {
107 $newProps = $this->groups[ $prop ]->parse( $obj[ $prop ], $context );
108 $newProps = $this->evaluate( $newProps );
109 $css = LodashBasic::merge( $css, $newProps );
110 }
111 } else {
112
113 if ( strpos( $prop, '--' ) === 0 ) {
114 $css[ $prop ] = ParserUtils::toValueUnitString( $obj[ $prop ] );
115 } else {
116 if ( ! $skipNormal ) {
117 if ( is_numeric( $obj[ $prop ] ) || is_string( $obj[ $prop ] ) ) {
118 $css[ $prop ] = $this->evaluate( $obj[ $prop ] );
119 }
120 }
121 }
122 }
123 }
124 return $css;
125 }
126 }
127