PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 1.6.4
Kubio AI Page Builder v1.6.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 3 years ago BlockStyleRender.php 4 years ago DynamicStyles.php 3 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 3 years ago Utils.php 4 years ago
StyleParser.php
126 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\JustifyContent;
25 use Kubio\Core\StyleManager\Props\UnitValuePercentage;
26 use Kubio\Core\StyleManager\Props\UnitValuePx;
27 use Kubio\Core\StyleManager\Props\ObjectCss;
28 use Kubio\Core\StyleManager\Props\MaxWidth;
29
30 class StyleParser {
31
32 public $groups;
33 public static $instance = null;
34
35 protected function __construct() {
36 $properties = array(
37 new Background( 'background' ),
38 new TBLR( 'padding' ),
39 new TBLR( 'margin' ),
40 new ColumnWidth( 'columnWidth' ),
41 new CustomHeight( 'customHeight' ),
42 new BoxShadow( 'boxShadow' ),
43 new TextShadow( 'textShadow' ),
44 new Border( 'border' ),
45 new Typography( 'typography' ),
46 new Size( 'size' ),
47 new Transform( 'transform' ),
48 new Opacity( 'opacity' ),
49 new Gap( 'gap' ),
50 new JustifyContent( 'justifyContent' ),
51 new Width( 'width' ),
52 new Height( 'height' ),
53 new Stroke( 'stroke' ),
54 new MultipleImage( 'multipleImage' ),
55 new UnitValuePercentage( 'top' ),
56 new UnitValuePercentage( 'right' ),
57 new UnitValuePercentage( 'bottom' ),
58 new UnitValuePercentage( 'left' ),
59 new MaxWidth( 'maxWidth' ),
60 new UnitValuePx( 'maxHeight' ),
61 new UnitValuePx( 'minHeight' ),
62 new ObjectCss( 'object' ),
63 new Animation( 'animation' ),
64 new Transition( 'transition' ),
65 );
66
67 $this->groups = array();
68 foreach ( $properties as $property ) {
69 $this->addProperty( $property->name, $property );
70 }
71 }
72
73 public static function getInstance() {
74 if ( ! self::$instance ) {
75 self::$instance = new StyleParser();
76 }
77 return self::$instance;
78 }
79
80 public function evaluateString( $value ) {
81 return $value;
82 }
83
84 public function addProperty( $name, $property ) {
85 $this->groups[ $name ] = $property;
86 }
87
88 public function evaluate( $value ) {
89 if ( LodashBasic::isString( $value ) ) {
90 return $this->evaluateString( $value );
91 }
92 if ( is_array( $value ) ) {
93 foreach ( $value as $name => $val ) {
94 $value[ $name ] = $this->evaluate( $val );
95 }
96 }
97 return $value;
98 }
99
100 public function transform( $obj, $context, $skipNormal = false ) {
101 if ( ! $obj ) {
102 return;
103 }
104 $css = array();
105 foreach ( $obj as $prop => $___ ) {
106 if ( isset( $this->groups[ $prop ] ) ) {
107 $newProps = $this->groups[ $prop ]->parse( $obj[ $prop ], $context );
108 $newProps = $this->evaluate( $newProps );
109 $css = LodashBasic::merge( $css, (array)$newProps );
110 } else {
111
112 if ( strpos( $prop, '--' ) === 0 ) {
113 $css[ $prop ] = ParserUtils::toValueUnitString( $obj[ $prop ] );
114 } else {
115 if ( ! $skipNormal ) {
116 if ( is_numeric( $obj[ $prop ] ) || is_string( $obj[ $prop ] ) ) {
117 $css[ $prop ] = $this->evaluate( $obj[ $prop ] );
118 }
119 }
120 }
121 }
122 }
123 return $css;
124 }
125 }
126