PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.11.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.11.1
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 1.1.2 All 80 releases
ablocks / includes / blocks / svg-draw / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.11.1, at includes/blocks/svg-draw/block.php

160 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\SvgDraw;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use ABlocks\Classes\BlockBaseAbstract;
9 use ABlocks\Classes\CssGenerator;
10 use ABlocks\Classes\CssGeneratorV2;
11 use ABlocks\Controls\Dimensions;
12 use ABlocks\Controls\Icon;
13 use ABlocks\Controls\Color;
14
15 class Block extends BlockBaseAbstract {
16 protected $block_name = 'svg-draw';
17
18 public function build_css_v1( $attributes ) {
19 $css_generator = new CssGenerator( $attributes, $this->block_name );
20
21 // Generate wrapper CSS start
22 $css_generator->add_class_styles(
23 '{{WRAPPER}} .ablocks-block-container',
24 $this->get_wrapper_css( $attributes ),
25 $this->get_wrapper_css( $attributes, 'Tablet' ),
26 $this->get_wrapper_css( $attributes, 'Mobile' )
27 );
28
29 // Icon Style
30 $css_generator->add_class_styles(
31 '{{WRAPPER}} .ablocks-icon-wrap',
32 Icon::get_wrapper_css( $attributes ),
33 Icon::get_wrapper_css( $attributes, 'Tablet' ),
34 Icon::get_wrapper_css( $attributes, 'Mobile' )
35 );
36 $css_generator->add_class_styles(
37 '{{WRAPPER}} .ablocks-icon-wrap:hover',
38 Icon::get_wrapper_hover_css( $attributes ),
39 Icon::get_wrapper_hover_css( $attributes, 'Tablet' ),
40 Icon::get_wrapper_hover_css( $attributes, 'Mobile' )
41 );
42 $css_generator->add_class_styles(
43 '{{WRAPPER}} svg > path',
44 $this->get_svg_css( $attributes ),
45 $this->get_svg_css( $attributes, 'Tablet' ),
46 $this->get_svg_css( $attributes, 'Mobile' )
47 );
48
49 $css_generator->add_class_styles(
50 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon',
51 Icon::get_element_image_css( $attributes ),
52 Icon::get_element_image_css( $attributes, 'Tablet' ),
53 Icon::get_element_image_css( $attributes, 'Mobile' ),
54 );
55 $css_generator->add_class_styles(
56 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon:hover',
57 Icon::get_element_image_hover_css( $attributes ),
58 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
59 Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
60 );
61 $css_generator->add_class_styles(
62 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon',
63 Icon::get_element_css( $attributes ),
64 Icon::get_element_css( $attributes, 'Tablet' ),
65 Icon::get_element_css( $attributes, 'Mobile' ),
66 );
67 $css_generator->add_class_styles(
68 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon:hover',
69 Icon::get_element_image_hover_css( $attributes ),
70 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
71 Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
72 );
73
74 return $css_generator->generate_css();
75 }
76 public function build_css_v2( $attributes ) {
77 $css_generator = new CssGenerator( $attributes, $this->block_name );
78
79 // Generate wrapper CSS start
80 $css_generator->add_class_styles(
81 '{{WRAPPER}}',
82 $this->get_wrapper_css( $attributes ),
83 $this->get_wrapper_css( $attributes, 'Tablet' ),
84 $this->get_wrapper_css( $attributes, 'Mobile' )
85 );
86
87 // Icon Style
88 $css_generator->add_class_styles(
89 '{{WRAPPER}} .ablocks-icon-wrap',
90 Icon::get_wrapper_css( $attributes ),
91 Icon::get_wrapper_css( $attributes, 'Tablet' ),
92 Icon::get_wrapper_css( $attributes, 'Mobile' )
93 );
94 $css_generator->add_class_styles(
95 '{{WRAPPER}} .ablocks-icon-wrap:hover',
96 Icon::get_wrapper_hover_css( $attributes ),
97 Icon::get_wrapper_hover_css( $attributes, 'Tablet' ),
98 Icon::get_wrapper_hover_css( $attributes, 'Mobile' )
99 );
100 $css_generator->add_class_styles(
101 '{{WRAPPER}} svg > path',
102 $this->get_svg_css( $attributes ),
103 $this->get_svg_css( $attributes, 'Tablet' ),
104 $this->get_svg_css( $attributes, 'Mobile' )
105 );
106
107 $css_generator->add_class_styles(
108 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon',
109 Icon::get_element_image_css( $attributes ),
110 Icon::get_element_image_css( $attributes, 'Tablet' ),
111 Icon::get_element_image_css( $attributes, 'Mobile' ),
112 );
113 $css_generator->add_class_styles(
114 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon:hover',
115 Icon::get_element_image_hover_css( $attributes ),
116 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
117 Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
118 );
119 $css_generator->add_class_styles(
120 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon',
121 Icon::get_element_css( $attributes ),
122 Icon::get_element_css( $attributes, 'Tablet' ),
123 Icon::get_element_css( $attributes, 'Mobile' ),
124 );
125 $css_generator->add_class_styles(
126 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon:hover',
127 Icon::get_element_image_hover_css( $attributes ),
128 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
129 Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
130 );
131
132 return $css_generator->generate_css();
133 }
134 public function build_css( $attributes ) {
135 if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
136 return $this->build_css_v2( $attributes );
137 }
138 return $this->build_css_v1( $attributes );
139 }
140
141 public function get_wrapper_css( $attributes, $device = '' ) {
142 $css = [];
143 $css['display'] = 'flex';
144 if ( ! empty( $attributes['alignment'][ 'value' . $device ] ) ) {
145 $css['justify-content'] = $attributes['alignment'][ 'value' . $device ];
146 }
147 return $css;
148 }
149
150 public function get_svg_css( $attributes = [], $device = '' ) {
151 if ( ! empty( $attributes['duration'] ) ) {
152 $css['animation-duration'] = $attributes['duration'] . 's !important';
153 }
154 return array_merge(
155 [ 'stroke' => Color::get_css( isset( $attributes['svgDrawColor'] ) ? $attributes['svgDrawColor'] : '' ) ],
156 $css
157 );
158 }
159 }
160