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 / Separators / Separator.php
kubio / lib / src / Core / Separators Last commit date
Separator.php 4 years ago Separators.php 4 years ago
Separator.php
79 lines
1 <?php
2
3 namespace Kubio\Core\Separators;
4
5 use Kubio\Config;
6 use Kubio\Core\Element;
7 use Kubio\Core\LodashBasic;
8 use Kubio\Core\StyleManager\ParserUtils;
9 use Kubio\Core\Styles\Utils;
10 use function file_exists;
11 use function file_get_contents;
12 use function sanitize_file_name;
13 use const KUBIO_ROOT_DIR;
14
15 class Separator extends Element {
16
17 function __construct( $tag_name, $props, $children, $block ) {
18 parent::__construct( $tag_name, $props, $children, $block );
19
20 $position = $this->getProp( 'position' );
21 $negative = $this->getProp( 'negative' );
22
23 $enabledByMedia = $this->getProp( 'enabledByMedia' );
24
25 $visibilityPerMedia = $this->getVisibilityPerMedia( $enabledByMedia );
26
27 $style = array(
28 'fill' => $this->getProp( 'color' ),
29 'height' => ParserUtils::toValueUnitString( $this->getProp( 'height' ) ),
30 );
31
32 if ( ! $this->getProp( 'overlap' ) ) {
33 $style['position'] = 'relative';
34 }
35
36 $style[ $position ] = 'calc(0px)';
37
38 $type = sanitize_file_name( $this->getProp( 'type' ) );
39
40 $top = $position === 'top';
41 $shouldUseNegative = $negative && file_exists( KUBIO_ROOT_DIR . "lib/shapes/separators/${type}-negative.svg" );
42
43 $supportsNegative = file_exists( KUBIO_ROOT_DIR . "lib/shapes/separators/${type}-negative.svg" );
44
45 if ( ( $shouldUseNegative && $top ) || ( ! $shouldUseNegative && ! $top ) ) {
46 $style['transform'] = 'rotateX(180deg)';
47 }
48
49 if ( $negative && $supportsNegative ) {
50 $type = $type . '-negative';
51 }
52
53 $html = file_get_contents( KUBIO_ROOT_DIR . 'lib/shapes/separators/' . $type . '.svg' );
54 $this->extendProps(
55 array(
56 'className' => array_merge( array( 'h-separator' ), $visibilityPerMedia ),
57 'style' => $style,
58 )
59 );
60
61 $this->setChildren( array( $html ) );
62 }
63
64 public function getVisibilityPerMedia( $enabledByMedia = array() ) {
65 $classes = array();
66 $prefix = 'h-separator--display';
67 foreach ( $enabledByMedia as $media => $enabled ) {
68 $value = $enabled ? 'flex' : 'none';
69 $mediaPrefix = utils::getMediaPrefix( $media );
70 $values = LodashBasic::compactWithExceptions( array( $prefix, $value, $mediaPrefix ), array( '0', 0 ) );
71 $prefixedClass = implode( '-', $values );
72
73 $classes[] = $prefixedClass;
74 }
75 return $classes;
76 }
77 }
78
79