PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 3.0.3
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v3.0.3
4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.11.1 1.11.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 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.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 2.0.0 2.0.1 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.12.0 2.13.0 2.14.0 2.14.1 2.15.0 2.15.1 2.16.0 2.16.1 2.16.2 2.16.3 2.17.0 2.17.1 2.17.2 2.18.0 2.19.0 2.19.2 2.19.3 2.19.4 2.2.0 2.2.1 2.20.0 2.20.1 2.20.2 2.20.3 2.20.4 2.20.5 2.20.6 2.21.0 2.22.0 2.22.1 2.23.0 2.24.0 2.25.0 2.25.1 2.25.2 2.26.0 2.27.0 2.27.1 2.28.0 2.29.0 2.29.1 2.29.2 2.29.3 2.29.4 2.3.0 2.3.1 2.30.0 2.31.0 2.31.1 2.31.2 2.31.3 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.40.0 2.40.1 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.9.0 3.0.0 3.0.0-RC1 3.0.0-RC2 3.0.0-beta1 3.0.0-beta2 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.10.0 3.10.1 3.11.0 3.12.0 3.13.0 3.13.1 3.13.2 3.13.3 3.13.4 3.14.0 3.15.0 3.15.1 3.15.2 3.15.3 3.15.4 3.15.5 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.16.6 3.16.7 3.16.8 3.17.0 3.17.1 3.17.2 3.17.3 3.17.4 3.17.5 3.17.6 3.18.0 3.19.0 3.19.1 3.19.2 3.2.0 3.2.1 3.2.2 3.20.0 3.20.1 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 trunk 4.1.0 0.2.19.1 4.1.1 1.0.0 4.2.0 1.0.1 1.0.2
surecart / app / src / BlockLibrary / BlockStylesService.php
surecart / app / src / BlockLibrary Last commit date
BlockAnchorSupportService.php 1 year ago BlockPatternsService.php 1 year ago BlockService.php 1 year ago BlockServiceProvider.php 1 year ago BlockStylesService.php 1 year ago BlockValidationService.php 2 years ago CartMenuIconMigrationService.php 1 year ago CartMigrationService.php 1 year ago FormModeSwitcherService.php 1 year ago ProductCollectionBadgesMigrationService.php 1 year ago ProductListMigrationService.php 1 year ago ProductListService.php 1 year ago ProductPageBlocksMigrationService.php 1 year ago ProductPriceChoicesMigrationService.php 1 year ago ProductSelectedPriceMigrationService.php 1 year ago ProductVariantsMigrationService.php 1 year ago URLParamService.php 1 year ago
BlockStylesService.php
230 lines
1 <?php
2
3 namespace SureCart\BlockLibrary;
4
5 /**
6 * Provide general block-related functionality.
7 */
8 class BlockStylesService {
9 /**
10 * Block.
11 *
12 * @var object
13 */
14 public $block = null;
15
16 /**
17 * Get the spacing values from the block editor
18 *
19 * @return array
20 */
21 public function getSpacingValues() {
22 $block = $this->block ? $this->block : \WP_Block_Supports::$block_to_render;
23 $block_type = \WP_Block_Type_Registry::get_instance()->get_registered(
24 $block['blockName']
25 );
26 $block_attributes = $block['attrs'];
27
28 $attributes = array();
29 $has_padding_support = block_has_support( $block_type, array( 'spacing', 'padding' ), false );
30 $has_margin_support = block_has_support( $block_type, array( 'spacing', 'margin' ), false );
31 $block_styles = isset( $block_attributes['style'] ) ? $block_attributes['style'] : null;
32
33 if ( ! $block_styles ) {
34 return $attributes;
35 }
36
37 $spacing_block_styles = array(
38 'padding' => null,
39 'margin' => null,
40 );
41 if ( $has_padding_support ) {
42 $spacing_block_styles['padding'] = isset( $block_styles['spacing']['padding'] ) ? $block_styles['spacing']['padding'] : null;
43 }
44 if ( $has_margin_support ) {
45 $spacing_block_styles['margin'] = isset( $block_styles['spacing']['margin'] ) ? $block_styles['spacing']['margin'] : null;
46 }
47
48 return $spacing_block_styles;
49 }
50
51 /**
52 * Get the border values from the block editor
53 *
54 * @return array
55 */
56 public function getBorderValues() {
57 $block = $this->block ? $this->block : \WP_Block_Supports::$block_to_render;
58 $block_type = \WP_Block_Type_Registry::get_instance()->get_registered(
59 $block['blockName']
60 );
61 $block_attributes = $block['attrs'];
62
63 $border_block_styles = array();
64 $has_border_color_support = wp_has_border_feature_support( $block_type, 'color' );
65 $has_border_width_support = wp_has_border_feature_support( $block_type, 'width' );
66
67 // Border radius.
68 if (
69 wp_has_border_feature_support( $block_type, 'radius' ) &&
70 isset( $block_attributes['style']['border']['radius'] )
71 ) {
72 $border_radius = $block_attributes['style']['border']['radius'];
73
74 if ( is_numeric( $border_radius ) ) {
75 $border_radius .= 'px';
76 }
77
78 $border_block_styles['radius'] = $border_radius;
79 }
80
81 // Border style.
82 if (
83 wp_has_border_feature_support( $block_type, 'style' ) &&
84 isset( $block_attributes['style']['border']['style'] )
85 ) {
86 $border_block_styles['style'] = $block_attributes['style']['border']['style'];
87 }
88
89 // Border width.
90 if (
91 $has_border_width_support &&
92 isset( $block_attributes['style']['border']['width'] )
93 ) {
94 $border_width = $block_attributes['style']['border']['width'];
95
96 // This check handles original unitless implementation.
97 if ( is_numeric( $border_width ) ) {
98 $border_width .= 'px';
99 }
100
101 $border_block_styles['width'] = $border_width;
102 }
103
104 // Border color.
105 if (
106 $has_border_color_support
107 ) {
108 $preset_border_color = array_key_exists( 'borderColor', $block_attributes ) ? "var:preset|color|{$block_attributes['borderColor']}" : null;
109 $custom_border_color = isset( $block_attributes['style']['border']['color'] ) ? $block_attributes['style']['border']['color'] : null;
110 $border_block_styles['color'] = $preset_border_color ? $preset_border_color : $custom_border_color;
111 }
112
113 // Generates styles for individual border sides.
114 if ( $has_border_color_support || $has_border_width_support ) {
115 foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) {
116 $border = isset( $block_attributes['style']['border'][ $side ] ) ? $block_attributes['style']['border'][ $side ] : null;
117 $border_side_values = array(
118 'width' => isset( $border['width'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' ) ? $border['width'] : null,
119 'color' => isset( $border['color'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' ) ? $border['color'] : null,
120 'style' => isset( $border['style'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'style' ) ? $border['style'] : null,
121 );
122 $border_block_styles[ $side ] = $border_side_values;
123 }
124 }
125
126 return $border_block_styles;
127 }
128
129 /**
130 * Get the color values from the block editor
131 *
132 * @return array
133 */
134 public function getColorValues() {
135 $block = $this->block ? $this->block : \WP_Block_Supports::$block_to_render;
136 $block_type = \WP_Block_Type_Registry::get_instance()->get_registered(
137 $block['blockName']
138 );
139 $block_attributes = $block['attrs'];
140
141 $color_support = isset( $block_type->supports['color'] ) ? $block_type->supports['color'] : false;
142
143 $has_text_colors_support = true === $color_support ||
144 ( isset( $color_support['text'] ) && $color_support['text'] ) ||
145 ( is_array( $color_support ) && ! isset( $color_support['text'] ) );
146 $has_background_colors_support = true === $color_support ||
147 ( isset( $color_support['background'] ) && $color_support['background'] ) ||
148 ( is_array( $color_support ) && ! isset( $color_support['background'] ) );
149 $has_gradients_support = isset( $color_support['gradients'] ) ? $color_support['gradients'] : false;
150 $color_block_styles = array();
151
152 // Text colors.
153 if ( $has_text_colors_support ) {
154 $preset_text_color = array_key_exists( 'textColor', $block_attributes ) ? "var:preset|color|{$block_attributes['textColor']}" : null;
155 $custom_text_color = isset( $block_attributes['style']['color']['text'] ) ? $block_attributes['style']['color']['text'] : null;
156 $color_block_styles['text'] = $preset_text_color ? $preset_text_color : $custom_text_color;
157 }
158
159 // Background colors.
160 if ( $has_background_colors_support ) {
161 $preset_background_color = array_key_exists( 'backgroundColor', $block_attributes ) ? "var:preset|color|{$block_attributes['backgroundColor']}" : null;
162 $custom_background_color = isset( $block_attributes['style']['color']['background'] ) ? $block_attributes['style']['color']['background'] : null;
163 $color_block_styles['background'] = $preset_background_color ? $preset_background_color : $custom_background_color;
164 }
165
166 // Gradients.
167 if ( $has_gradients_support ) {
168 $preset_gradient_color = array_key_exists( 'gradient', $block_attributes ) ? "var:preset|gradient|{$block_attributes['gradient']}" : null;
169 $custom_gradient_color = isset( $block_attributes['style']['color']['gradient'] ) ? $block_attributes['style']['color']['gradient'] : null;
170 $color_block_styles['gradient'] = $preset_gradient_color ? $preset_gradient_color : $custom_gradient_color;
171 }
172
173 return $color_block_styles;
174 }
175
176 /**
177 * Get the style declarations
178 *
179 * @param bool $combine Whether to combine the styles or not.
180 * @param object $block The block object.
181 *
182 * @return array
183 */
184 public function get( $combine = true, $block = null ) {
185 if ( $block ) {
186 $this->block = $block;
187 }
188
189 if ( $combine ) {
190 return wp_style_engine_get_styles(
191 array(
192 'spacing' => $this->getSpacingValues(),
193 'border' => $this->getBorderValues(),
194 'color' => $this->getColorValues(),
195 ),
196 array(
197 'context' => 'block-supports',
198 )
199 );
200 }
201
202 return array(
203 'spacing' => wp_style_engine_get_styles( array( 'spacing' => $this->getSpacingValues() ) ),
204 'border' => wp_style_engine_get_styles( array( 'border' => $this->getBorderValues() ) ),
205 'color' => wp_style_engine_get_styles( array( 'color' => $this->getColorValues() ) ),
206 );
207 }
208
209 /**
210 * Get the spacing preset css variable.
211 *
212 * @param string $value The value.
213 *
214 * @return string|void
215 */
216 public function getBlockGapPresetCssVar( $value ) {
217 if ( ! $value ) {
218 return;
219 }
220
221 preg_match( '/var:preset\|spacing\|(.+)/', $value, $matches );
222
223 if ( ! $matches ) {
224 return $value;
225 }
226
227 return "var(--wp--preset--spacing--$matches[1])";
228 }
229 }
230