| 1 |
<?php |
| 2 |
|
| 3 |
namespace ABlocks\Blocks\TextPath; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
use ABlocks\Classes\BlockBaseAbstract; |
| 10 |
use ABlocks\Classes\CssGenerator; |
| 11 |
use ABlocks\Controls\Typography; |
| 12 |
use ABlocks\Controls\Dimensions; |
| 13 |
use ABlocks\Controls\Border; |
| 14 |
use ABlocks\Controls\Icon; |
| 15 |
use ABlocks\Controls\BoxShadow; |
| 16 |
use ABlocks\Controls\Range; |
| 17 |
use ABlocks\Controls\Alignment; |
| 18 |
use ABlocks\Controls\TextStroke; |
| 19 |
use ABlocks\Controls\Responsive; |
| 20 |
use ABlocks\Controls\Color; |
| 21 |
use ABlocks\Controls\TextShadow; |
| 22 |
|
| 23 |
|
| 24 |
class Block extends BlockBaseAbstract { |
| 25 |
|
| 26 |
protected $block_name = 'text-path'; |
| 27 |
|
| 28 |
public function build_css( $attributes ) { |
| 29 |
$css_generator = new CssGenerator( $attributes ); |
| 30 |
$css_generator->add_class_styles( |
| 31 |
'{{WRAPPER}}', |
| 32 |
$this->get_wrapper_css( $attributes ), |
| 33 |
$this->get_wrapper_css( $attributes, 'Tablet' ), |
| 34 |
$this->get_wrapper_css( $attributes, 'Mobile' ) |
| 35 |
); |
| 36 |
|
| 37 |
$css_generator->add_class_styles( |
| 38 |
'{{WRAPPER}} .ablocks-text-path', |
| 39 |
$this->get_text_path_container_css( $attributes ), |
| 40 |
$this->get_text_path_container_css( $attributes, 'Tablet' ), |
| 41 |
$this->get_text_path_container_css( $attributes, 'Mobile' ) |
| 42 |
); |
| 43 |
|
| 44 |
$css_generator->add_class_styles( |
| 45 |
'{{WRAPPER}} .ablocks-text-path-text', |
| 46 |
$this->get_text_css( $attributes ), |
| 47 |
$this->get_text_css( $attributes, 'Tablet' ), |
| 48 |
$this->get_text_css( $attributes, 'Mobile' ) |
| 49 |
); |
| 50 |
|
| 51 |
$css_generator->add_class_styles( |
| 52 |
'{{WRAPPER}} .ablocks-text-path-text:hover', |
| 53 |
$this->get_text_hover_css( $attributes ), |
| 54 |
$this->get_text_hover_css( $attributes, 'Tablet' ), |
| 55 |
$this->get_text_hover_css( $attributes, 'Mobile' ) |
| 56 |
); |
| 57 |
|
| 58 |
$css_generator->add_class_styles( |
| 59 |
'{{WRAPPER}} .ablocks-path-text-path', |
| 60 |
$this->get_text_path_css( $attributes ), |
| 61 |
$this->get_text_path_css( $attributes, 'Tablet' ), |
| 62 |
$this->get_text_path_css( $attributes, 'Mobile' ) |
| 63 |
); |
| 64 |
|
| 65 |
return $css_generator->generate_css(); |
| 66 |
} |
| 67 |
// wrapper css grnerate |
| 68 |
public function get_wrapper_css( $attributes, $device = '' ) { |
| 69 |
return [ 'width' => '100%' ]; |
| 70 |
} |
| 71 |
// text path css generate |
| 72 |
public function get_text_css( $attributes, $device = '' ) { |
| 73 |
$typography = isset( $attributes['typography'] ) && is_array( $attributes['typography'] ) |
| 74 |
? $attributes['typography'] |
| 75 |
: []; |
| 76 |
|
| 77 |
$text_shadow = ! empty( $attributes['textShadow'] ) |
| 78 |
? TextShadow::get_css( $attributes['textShadow'], '', $device ) : []; |
| 79 |
|
| 80 |
$typography_value = array_merge( $typography, [ 'font-weight' => '400' ] ); |
| 81 |
|
| 82 |
return array_merge( |
| 83 |
Typography::get_css( $typography_value, $device ), |
| 84 |
$text_shadow |
| 85 |
); |
| 86 |
} |
| 87 |
|
| 88 |
// container css genarate |
| 89 |
public function get_text_path_container_css( $attributes, $device = '' ) { |
| 90 |
$text_path_container_css = Range::get_css( [] ); |
| 91 |
|
| 92 |
$text_path_css = Range::get_css( [] ); |
| 93 |
|
| 94 |
if ( ! empty( $attributes['alignment'][ 'value' . $device ] ) ) { |
| 95 |
$text_path_container_css['justify-content'] = $attributes['alignment'][ 'value' . $device ]; |
| 96 |
} |
| 97 |
return array_merge( |
| 98 |
$text_path_container_css, |
| 99 |
$text_path_css, |
| 100 |
); |
| 101 |
|
| 102 |
} |
| 103 |
|
| 104 |
// text hover css generate |
| 105 |
public function get_text_hover_css( $attributes, $device = '' ) { |
| 106 |
$css = []; |
| 107 |
if ( ! empty( $attributes['textColorH'] ) ) { |
| 108 |
$css['fill'] = $attributes['textColorH']; |
| 109 |
} |
| 110 |
return array_merge( |
| 111 |
Range::get_css([ |
| 112 |
'attributeValue' => isset( $attributes['transition'] ) ? $attributes['transition'] : '', |
| 113 |
'attribute_object_key' => 'value', |
| 114 |
'defaultValue' => 0, |
| 115 |
'unitDefaultValue' => 's', |
| 116 |
'property' => 'transition-duration', |
| 117 |
'device' => $device, |
| 118 |
]), |
| 119 |
$css, |
| 120 |
); |
| 121 |
} |
| 122 |
// path css genarate |
| 123 |
public function get_text_path_css( $attributes, $device = '' ) { |
| 124 |
$css = []; |
| 125 |
if ( ! empty( $attributes['rotate'] ) ) { |
| 126 |
$css['transform'] = "rotate({$attributes['rotate']}deg)"; |
| 127 |
} |
| 128 |
$css['--width'] = isset( $attributes['iconSize'] ) ? $attributes['iconSize'] . 'px' : '0px'; |
| 129 |
return $css; |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
|