PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.8.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.8.0
2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 All 78 releases
ablocks / includes / blocks / text-path / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.8.0, at includes/blocks/text-path/block.php

161 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 use ABlocks\Classes\CssGeneratorV2;
23
24
25 class Block extends BlockBaseAbstract {
26
27 protected $block_name = 'text-path';
28
29 public function build_css_v1( $attributes ) {
30 $css_generator = new CssGenerator( $attributes, $this->block_name );
31 $css_generator->add_class_styles(
32 '{{WRAPPER}}.ablocks-block--text-path:not(.ablocks-block-container),
33 {{WRAPPER}}.ablocks-block--text-path .ablocks-block-container',
34 $this->get_text_path_container_css( $attributes ),
35 $this->get_text_path_container_css( $attributes, 'Tablet' ),
36 $this->get_text_path_container_css( $attributes, 'Mobile' )
37 );
38
39 $css_generator->add_class_styles(
40 '{{WRAPPER}} .ablocks-text-path-text',
41 $this->get_text_css( $attributes ),
42 $this->get_text_css( $attributes, 'Tablet' ),
43 $this->get_text_css( $attributes, 'Mobile' )
44 );
45
46 $css_generator->add_class_styles(
47 '{{WRAPPER}} .ablocks-text-path-text:hover',
48 $this->get_text_hover_css( $attributes ),
49 $this->get_text_hover_css( $attributes, 'Tablet' ),
50 $this->get_text_hover_css( $attributes, 'Mobile' )
51 );
52
53 $css_generator->add_class_styles(
54 '{{WRAPPER}} .ablocks-path-text-path',
55 $this->get_text_path_css( $attributes ),
56 $this->get_text_path_css( $attributes, 'Tablet' ),
57 $this->get_text_path_css( $attributes, 'Mobile' )
58 );
59
60 return $css_generator->generate_css();
61 }
62 public function build_css_v2( $attributes ) {
63 $css_generator = new CssGeneratorV2( $attributes, $this->block_name );
64
65 $css_generator->add_class_styles(
66 '{{WRAPPER}}.ablocks-block--text-path:not(.ablocks-block-container),
67 {{WRAPPER}}.ablocks-block--text-path .ablocks-block-container',
68 $this->get_text_path_container_css( $attributes ),
69 $this->get_text_path_container_css( $attributes, 'Tablet' ),
70 $this->get_text_path_container_css( $attributes, 'Mobile' )
71 );
72
73 $css_generator->add_class_styles(
74 '{{WRAPPER}} .ablocks-text-path-text',
75 $this->get_text_css( $attributes ),
76 $this->get_text_css( $attributes, 'Tablet' ),
77 $this->get_text_css( $attributes, 'Mobile' )
78 );
79
80 $css_generator->add_class_styles(
81 '{{WRAPPER}} .ablocks-text-path-text:hover',
82 $this->get_text_hover_css( $attributes ),
83 $this->get_text_hover_css( $attributes, 'Tablet' ),
84 $this->get_text_hover_css( $attributes, 'Mobile' )
85 );
86
87 $css_generator->add_class_styles(
88 '{{WRAPPER}} .ablocks-path-text-path',
89 $this->get_text_path_css( $attributes ),
90 $this->get_text_path_css( $attributes, 'Tablet' ),
91 $this->get_text_path_css( $attributes, 'Mobile' )
92 );
93
94 return $css_generator->generate_css();
95 }
96 public function build_css( $attributes ) {
97 if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
98 return $this->build_css_v2( $attributes );
99 }
100 return $this->build_css_v1( $attributes );
101 }
102 // text path css generate
103 public function get_text_css( $attributes, $device = '' ) {
104 $typography = isset( $attributes['typography'] ) && is_array( $attributes['typography'] )
105 ? $attributes['typography']
106 : [];
107 $typographyValueGlobal = ! empty( $attributes['typographyGlobal'] ) ? $attributes['typographyGlobal'] : [];
108
109 $text_shadow = ! empty( $attributes['textShadow'] )
110 ? TextShadow::get_css( $attributes['textShadow'], '', $device ) : [];
111
112 $typography_value = array_merge( $typography, [ 'font-weight' => '400' ] );
113
114 return array_merge(
115 Typography::get_css( $typography_value, '', $device, $typographyValueGlobal ),
116 $text_shadow
117 );
118 }
119
120 // container css genarate
121 public function get_text_path_container_css( $attributes, $device = '' ) {
122 $text_path_container_css = Range::get_css( [] );
123
124 $text_path_css = Range::get_css( [] );
125
126 if ( ! empty( $attributes['alignment'][ 'value' . $device ] ) ) {
127 $text_path_container_css['justify-content'] = $attributes['alignment'][ 'value' . $device ];
128 }
129 return array_merge(
130 $text_path_container_css,
131 $text_path_css,
132 );
133
134 }
135
136 // text hover css generate
137 public function get_text_hover_css( $attributes, $device = '' ) {
138 return array_merge(
139 [ 'fill' => Color::get_css( isset( $attributes['textColorH'] ) ? $attributes['textColorH'] : '' ) ],
140 Range::get_css([
141 'attributeValue' => isset( $attributes['transition'] ) ? $attributes['transition'] : '',
142 'attribute_object_key' => 'value',
143 'defaultValue' => 0,
144 'unitDefaultValue' => 's',
145 'property' => 'transition-duration',
146 'device' => $device,
147 ]),
148 );
149 }
150 // path css genarate
151 public function get_text_path_css( $attributes, $device = '' ) {
152 $css = [];
153 if ( ! empty( $attributes['rotate'] ) ) {
154 $css['transform'] = "rotate({$attributes['rotate']}deg)";
155 }
156 $css['--width'] = isset( $attributes['iconSize'] ) ? $attributes['iconSize'] . 'px' : '0px';
157 return $css;
158 }
159 }
160
161