PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.14.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.14.0
2.14.0 2.13.0 2.13.1 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 All 81 releases
ablocks / includes / blocks / text-path / block.php

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

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