PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / trunk
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments vtrunk
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 BlockCurrencyConversionSupportService.php 1 year ago BlockPatternsService.php 1 year ago BlockService.php 4 months ago BlockServiceProvider.php 4 months ago BlockStylesService.php 3 months ago BlockValidationService.php 2 years ago CartMenuIconMigrationService.php 1 year ago CartMigrationService.php 1 year ago FormModeSwitcherService.php 10 hours ago ProductCollectionBadgesMigrationService.php 1 year ago ProductListFilterTagsMigrationService.php 1 year ago ProductListMigrationService.php 1 year ago ProductListService.php 1 year ago ProductPageBlocksMigrationService.php 1 year ago ProductPriceChoicesMigrationService.php 1 year ago ProductQuickViewService.php 9 months ago ProductReviewFormService.php 4 months ago ProductSelectedPriceMigrationService.php 1 year ago ProductVariantsMigrationService.php 1 year ago URLParamService.php 3 months ago
BlockStylesService.php
264 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 dimensions values from the block editor
131 *
132 * @return array
133 */
134 public function getDimensionsValues() {
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 $attributes = array();
142
143 $has_min_height_support = block_has_support( $block_type, array( 'dimensions', 'minHeight' ), false );
144 $block_styles = isset( $block_attributes['style'] ) ? $block_attributes['style'] : null;
145
146 if ( ! $block_styles ) {
147 return $attributes;
148 }
149
150 $dimensions_block_styles = array();
151 $dimensions_block_styles['minHeight'] = null;
152 if ( $has_min_height_support ) {
153 $dimensions_block_styles['minHeight'] = isset( $block_styles['dimensions']['minHeight'] )
154 ? $block_styles['dimensions']['minHeight']
155 : null;
156 }
157
158 return $dimensions_block_styles;
159 }
160
161 /**
162 * Get the color values from the block editor
163 *
164 * @return array
165 */
166 public function getColorValues() {
167 $block = $this->block ? $this->block : \WP_Block_Supports::$block_to_render;
168 $block_type = \WP_Block_Type_Registry::get_instance()->get_registered(
169 $block['blockName']
170 );
171 $block_attributes = $block['attrs'] ?? [];
172
173 $color_support = isset( $block_type->supports['color'] ) ? $block_type->supports['color'] : false;
174
175 $has_text_colors_support = true === $color_support ||
176 ( isset( $color_support['text'] ) && $color_support['text'] ) ||
177 ( is_array( $color_support ) && ! isset( $color_support['text'] ) );
178 $has_background_colors_support = true === $color_support ||
179 ( isset( $color_support['background'] ) && $color_support['background'] ) ||
180 ( is_array( $color_support ) && ! isset( $color_support['background'] ) );
181 $has_gradients_support = isset( $color_support['gradients'] ) ? $color_support['gradients'] : false;
182 $color_block_styles = array();
183
184 // Text colors.
185 if ( $has_text_colors_support ) {
186 $preset_text_color = array_key_exists( 'textColor', $block_attributes ) ? "var:preset|color|{$block_attributes['textColor']}" : null;
187 $custom_text_color = isset( $block_attributes['style']['color']['text'] ) ? $block_attributes['style']['color']['text'] : null;
188 $color_block_styles['text'] = $preset_text_color ? $preset_text_color : $custom_text_color;
189 }
190
191 // Background colors.
192 if ( $has_background_colors_support ) {
193 $preset_background_color = array_key_exists( 'backgroundColor', $block_attributes ) ? "var:preset|color|{$block_attributes['backgroundColor']}" : null;
194 $custom_background_color = isset( $block_attributes['style']['color']['background'] ) ? $block_attributes['style']['color']['background'] : null;
195 $color_block_styles['background'] = $preset_background_color ? $preset_background_color : $custom_background_color;
196 }
197
198 // Gradients.
199 if ( $has_gradients_support ) {
200 $preset_gradient_color = array_key_exists( 'gradient', $block_attributes ) ? "var:preset|gradient|{$block_attributes['gradient']}" : null;
201 $custom_gradient_color = isset( $block_attributes['style']['color']['gradient'] ) ? $block_attributes['style']['color']['gradient'] : null;
202 $color_block_styles['gradient'] = $preset_gradient_color ? $preset_gradient_color : $custom_gradient_color;
203 }
204
205 return $color_block_styles;
206 }
207
208 /**
209 * Get the style declarations
210 *
211 * @param bool $combine Whether to combine the styles or not.
212 * @param object $block The block object.
213 *
214 * @return array
215 */
216 public function get( $combine = true, $block = null ) {
217 if ( $block ) {
218 $this->block = $block;
219 }
220
221 if ( $combine ) {
222 return wp_style_engine_get_styles(
223 array(
224 'spacing' => $this->getSpacingValues(),
225 'border' => $this->getBorderValues(),
226 'color' => $this->getColorValues(),
227 'dimensions' => $this->getDimensionsValues(),
228 ),
229 array(
230 'context' => 'block-supports',
231 )
232 );
233 }
234
235 return array(
236 'spacing' => wp_style_engine_get_styles( array( 'spacing' => $this->getSpacingValues() ) ),
237 'border' => wp_style_engine_get_styles( array( 'border' => $this->getBorderValues() ) ),
238 'color' => wp_style_engine_get_styles( array( 'color' => $this->getColorValues() ) ),
239 'dimensions' => wp_style_engine_get_styles( array( 'dimensions' => $this->getDimensionsValues() ) ),
240 );
241 }
242
243 /**
244 * Get the spacing preset css variable.
245 *
246 * @param string $value The value.
247 *
248 * @return string|void
249 */
250 public function getBlockGapPresetCssVar( $value ) {
251 if ( ! $value ) {
252 return;
253 }
254
255 preg_match( '/var:preset\|spacing\|(.+)/', $value, $matches );
256
257 if ( ! $matches ) {
258 return $value;
259 }
260
261 return "var(--wp--preset--spacing--$matches[1])";
262 }
263 }
264