PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.6.3
Kubio AI Page Builder v2.6.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 / StyleManager.php
kubio / lib / src / Core / StyleManager Last commit date
Generics 1 year ago Props 1 year ago BlockStyleRender.php 1 year ago DynamicStyles.php 1 year ago GlobalStyleRender.php 1 year ago MainAttribute.php 4 years ago ParserUtils.php 1 year ago StyleManager.php 2 years ago StyleParser.php 1 year ago StyleRender.php 1 year ago Utils.php 1 year ago
StyleManager.php
88 lines
1 <?php
2
3 namespace Kubio\Core\StyleManager;
4
5 use Kubio\Config;
6 use Kubio\Core\LodashBasic;
7 use Kubio\Core\Utils;
8
9 use function array_merge;
10 #[\AllowDynamicProperties]
11 class StyleManager {
12
13 private static $instance;
14 private $styles = array(
15 'shared' => array(),
16 'local' => array(),
17 'dynamic' => array(),
18 'global' => array(),
19 );
20
21 private $style_join = array(
22 'new_line' => '',
23 'tab' => '',
24 );
25
26 public function __construct() {
27 if ( Utils::isDebug() ) {
28 $this->style_join = array(
29 'new_line' => "\n",
30 'tab' => "\t",
31 );
32
33 }
34 }
35
36 static function getInstance() {
37 if ( ! self::$instance ) {
38 self::$instance = new self();
39 }
40
41 return self::$instance;
42 }
43
44 function registerBlockStyle( $styleByType ) {
45 foreach ( $styleByType as $type => $styleByMedia ) {
46 foreach ( $styleByMedia as $media => $styles ) {
47 $path = array( $type, $media );
48 LodashBasic::set( $this->styles, $path, array_merge( LodashBasic::get( $this->styles, $path, array() ), $styles ) );
49 }
50 }
51 }
52
53 public function render() {
54 $renderByMedia = array();
55 foreach ( $this->styles as $styleByMedia ) {
56 foreach ( $styleByMedia as $media => $styles ) {
57 if ( ! isset( $renderByMedia[ $media ] ) ) {
58 $renderByMedia[ $media ] = array();
59 }
60 $renderByMedia[ $media ] = array_merge( $renderByMedia[ $media ], $styles );
61 }
62 }
63
64 $render = '';
65
66 $devices = LodashBasic::mapValues( Config::value( 'medias' ), 'id' );
67 $mediasById = Config::mediasById();
68
69 $device_rules = array();
70
71 foreach ( $devices as $device ) {
72 if ( isset( $renderByMedia[ $device ] ) ) {
73 $query = LodashBasic::get( $mediasById, array( $device, 'query' ), false );
74 $rules = join( $this->style_join['new_line'], $renderByMedia[ $device ] );
75 if ( $query ) {
76 $device_rules[] = $query . "{$this->style_join['tab']}{{$this->style_join['new_line']}{$rules}{$this->style_join['new_line']}}";
77 } else {
78 $device_rules[] = $rules;
79 }
80 }
81 }
82
83 $render .= join( '', $device_rules );
84
85 return $render;
86 }
87 }
88