PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.16.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.16.0
2.16.0 2.15.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 All 83 releases
← All changes | includes/blocks/carousel/block.php +777 -0 2.7.5 → 2.16.0 View file →
@@ -1,0 +1,777 @@
1 +<?php
2 +namespace ABlocks\Blocks\Carousel;
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\Alignment;
12 +use ABlocks\Controls\Range;
13 +use ABlocks\Controls\Dimensions;
14 +use ABlocks\Controls\Border;
15 +use ABlocks\Controls\Color;
16 +use ABlocks\Controls\BoxShadow;
17 +
18 +
19 +
20 +class Block extends BlockBaseAbstract {
21 + protected $block_name = 'carousel';
22 + protected $style_depends = [ 'ablocks-swiper-style' ];
23 + protected $script_depends = [ 'ablocks-swiper-script' ];
24 +
25 + public function build_css_v1( $attributes ) {
26 +
27 + $css_generator = new CssGenerator( $attributes );
28 +
29 + $css_generator->add_class_styles(
30 + '{{WRAPPER}} .ablocks-carousel-swiper .swiper-wrapper',
31 + $this->get_carousel_css( $attributes ),
32 + $this->get_carousel_css( $attributes, 'Tablet' ),
33 + $this->get_carousel_css( $attributes, 'Mobile' ),
34 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
35 + return $this->get_carousel_css( $attributes, $device );
36 + } )
37 + );
38 + $css_generator->add_class_styles(
39 + '{{WRAPPER}} .ablocks-carousel-swiper > .swiper-wrapper > .swiper-slide',
40 + $this->get_slide_css( $attributes ),
41 + $this->get_slide_css( $attributes, 'Tablet' ),
42 + $this->get_slide_css( $attributes, 'Mobile' ),
43 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
44 + return $this->get_slide_css( $attributes, $device );
45 + } )
46 + );
47 + $css_generator->add_class_styles(
48 + '{{WRAPPER}} .ablocks-carousel-swiper > .swiper-wrapper > .swiper-slide-active',
49 + $this->get_active_slide_css( $attributes ),
50 + $this->get_active_slide_css( $attributes, 'Tablet' ),
51 + $this->get_active_slide_css( $attributes, 'Mobile' ),
52 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
53 + return $this->get_active_slide_css( $attributes, $device );
54 + } )
55 + );
56 + $css_generator->add_class_styles(
57 + '{{WRAPPER}} .ablocks-carousel-navigation__button',
58 + $this->get_navigation_button_css( $attributes ),
59 + $this->get_navigation_button_css( $attributes, 'Tablet' ),
60 + $this->get_navigation_button_css( $attributes, 'Mobile' ),
61 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
62 + return $this->get_navigation_button_css( $attributes, $device );
63 + } )
64 + );
65 + $css_generator->add_class_styles(
66 + '{{WRAPPER}} .ablocks-carousel-navigation__button--next',
67 + $this->get_navigation_next_button_css( $attributes ),
68 + $this->get_navigation_next_button_css( $attributes, 'Tablet' ),
69 + $this->get_navigation_next_button_css( $attributes, 'Mobile' ),
70 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
71 + return $this->get_navigation_next_button_css( $attributes, $device );
72 + } )
73 + );
74 + $css_generator->add_class_styles(
75 + '{{WRAPPER}} .ablocks-carousel-navigation__button--prev',
76 + $this->get_navigation_prev_button_css( $attributes ),
77 + $this->get_navigation_prev_button_css( $attributes, 'Tablet' ),
78 + $this->get_navigation_prev_button_css( $attributes, 'Mobile' ),
79 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
80 + return $this->get_navigation_prev_button_css( $attributes, $device );
81 + } )
82 + );
83 + $css_generator->add_class_styles(
84 + '{{WRAPPER}} .ablocks-carousel-navigation__button .ablocks-icon-wrap',
85 + $this->get_navigation_icon_css( $attributes ),
86 + $this->get_navigation_icon_css( $attributes, 'Tablet' ),
87 + $this->get_navigation_icon_css( $attributes, 'Mobile' ),
88 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
89 + return $this->get_navigation_icon_css( $attributes, $device );
90 + } )
91 + );
92 +
93 + $css_generator->add_class_styles(
94 + '{{WRAPPER}} .ablocks-carousel-pagination',
95 + $this->get_pagination_parent_css( $attributes ),
96 + $this->get_pagination_parent_css( $attributes, 'Tablet' ),
97 + $this->get_pagination_parent_css( $attributes, 'Mobile' ),
98 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
99 + return $this->get_pagination_parent_css( $attributes, $device );
100 + } )
101 + );
102 + $css_generator->add_class_styles(
103 + '{{WRAPPER}} .swiper-pagination-bullet',
104 + $this->get_pagination_color_css( $attributes ),
105 + $this->get_pagination_color_css( $attributes, 'Tablet' ),
106 + $this->get_pagination_color_css( $attributes, 'Mobile' ),
107 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
108 + return $this->get_pagination_color_css( $attributes, $device );
109 + } )
110 + );
111 + $css_generator->add_class_styles(
112 + '{{WRAPPER}} .swiper-pagination-bullet:hover',
113 + $this->get_pagination_color_hover_css( $attributes ),
114 + $this->get_pagination_color_hover_css( $attributes, 'Tablet' ),
115 + $this->get_pagination_color_hover_css( $attributes, 'Mobile' ),
116 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
117 + return $this->get_pagination_color_hover_css( $attributes, $device );
118 + } )
119 + );
120 +
121 + $css_generator->add_class_styles(
122 + '{{WRAPPER}} .swiper-pagination-bullet.swiper-pagination-bullet-active',
123 + $this->get_pagination_active_color_css( $attributes ),
124 + $this->get_pagination_active_color_css( $attributes, 'Tablet' ),
125 + $this->get_pagination_active_color_css( $attributes, 'Mobile' ),
126 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
127 + return $this->get_pagination_active_color_css( $attributes, $device );
128 + } )
129 + );
130 + $css_generator->add_class_styles(
131 + '{{WRAPPER}} .swiper-pagination-bullet.swiper-pagination-bullet-active:hover',
132 + $this->get_pagination_active_color_hover_css( $attributes ),
133 + $this->get_pagination_active_color_hover_css( $attributes, 'Tablet' ),
134 + $this->get_pagination_active_color_hover_css( $attributes, 'Mobile' ),
135 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
136 + return $this->get_pagination_active_color_hover_css( $attributes, $device );
137 + } )
138 + );
139 +
140 + $css_generator->add_class_styles(
141 + '{{WRAPPER}} .ablocks-carousel-navigation__button .ablocks-svg-icon',
142 + $this->get_navigation_icon_svg_css( $attributes ),
143 + $this->get_navigation_icon_svg_css( $attributes, 'Tablet' ),
144 + $this->get_navigation_icon_svg_css( $attributes, 'Mobile' ),
145 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
146 + return $this->get_navigation_icon_svg_css( $attributes, $device );
147 + } )
148 + );
149 + $css_generator->add_class_styles(
150 + '{{WRAPPER}} .ablocks-carousel-navigation__button .ablocks-svg-icon:hover',
151 + $this->get_navigation_icon_svg_hover_css( $attributes ),
152 + $this->get_navigation_icon_svg_hover_css( $attributes, 'Tablet' ),
153 + $this->get_navigation_icon_svg_hover_css( $attributes, 'Mobile' ),
154 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
155 + return $this->get_navigation_icon_svg_hover_css( $attributes, $device );
156 + } )
157 + );
158 + return $css_generator->generate_css();
159 + }
160 +
161 + public function build_css_v2( $attributes ) {
162 +
163 + $css_generator = new CssGeneratorV2( $attributes, $this->block_name );
164 +
165 + $css_generator->add_class_styles(
166 + '{{WRAPPER}} .ablocks-carousel-swiper .swiper-wrapper',
167 + $this->get_carousel_css( $attributes ),
168 + $this->get_carousel_css( $attributes, 'Tablet' ),
169 + $this->get_carousel_css( $attributes, 'Mobile' ),
170 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
171 + return $this->get_carousel_css( $attributes, $device );
172 + } )
173 + );
174 + $css_generator->add_class_styles(
175 + '{{WRAPPER}} .ablocks-carousel-swiper > .swiper-wrapper > .swiper-slide',
176 + $this->get_slide_css( $attributes ),
177 + $this->get_slide_css( $attributes, 'Tablet' ),
178 + $this->get_slide_css( $attributes, 'Mobile' ),
179 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
180 + return $this->get_slide_css( $attributes, $device );
181 + } )
182 + );
183 + $css_generator->add_class_styles(
184 + '{{WRAPPER}} .ablocks-carousel-swiper > .swiper-wrapper > .swiper-slide-active',
185 + $this->get_active_slide_css( $attributes ),
186 + $this->get_active_slide_css( $attributes, 'Tablet' ),
187 + $this->get_active_slide_css( $attributes, 'Mobile' ),
188 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
189 + return $this->get_active_slide_css( $attributes, $device );
190 + } )
191 + );
192 + $css_generator->add_class_styles(
193 + '{{WRAPPER}} .ablocks-carousel-navigation__button',
194 + $this->get_navigation_button_css( $attributes ),
195 + $this->get_navigation_button_css( $attributes, 'Tablet' ),
196 + $this->get_navigation_button_css( $attributes, 'Mobile' ),
197 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
198 + return $this->get_navigation_button_css( $attributes, $device );
199 + } )
200 + );
201 + $css_generator->add_class_styles(
202 + '{{WRAPPER}} .ablocks-carousel-navigation__button--next',
203 + $this->get_navigation_next_button_css( $attributes ),
204 + $this->get_navigation_next_button_css( $attributes, 'Tablet' ),
205 + $this->get_navigation_next_button_css( $attributes, 'Mobile' ),
206 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
207 + return $this->get_navigation_next_button_css( $attributes, $device );
208 + } )
209 + );
210 + $css_generator->add_class_styles(
211 + '{{WRAPPER}} .ablocks-carousel-navigation__button--prev',
212 + $this->get_navigation_prev_button_css( $attributes ),
213 + $this->get_navigation_prev_button_css( $attributes, 'Tablet' ),
214 + $this->get_navigation_prev_button_css( $attributes, 'Mobile' ),
215 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
216 + return $this->get_navigation_prev_button_css( $attributes, $device );
217 + } )
218 + );
219 + $css_generator->add_class_styles(
220 + '{{WRAPPER}} .ablocks-carousel-navigation__button .ablocks-icon-wrap',
221 + $this->get_navigation_icon_css( $attributes ),
222 + $this->get_navigation_icon_css( $attributes, 'Tablet' ),
223 + $this->get_navigation_icon_css( $attributes, 'Mobile' ),
224 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
225 + return $this->get_navigation_icon_css( $attributes, $device );
226 + } )
227 + );
228 +
229 + $css_generator->add_class_styles(
230 + '{{WRAPPER}} .ablocks-carousel-pagination',
231 + $this->get_pagination_parent_css( $attributes ),
232 + $this->get_pagination_parent_css( $attributes, 'Tablet' ),
233 + $this->get_pagination_parent_css( $attributes, 'Mobile' ),
234 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
235 + return $this->get_pagination_parent_css( $attributes, $device );
236 + } )
237 + );
238 + $css_generator->add_class_styles(
239 + '{{WRAPPER}} .swiper-pagination-bullet',
240 + $this->get_pagination_color_css( $attributes ),
241 + $this->get_pagination_color_css( $attributes, 'Tablet' ),
242 + $this->get_pagination_color_css( $attributes, 'Mobile' ),
243 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
244 + return $this->get_pagination_color_css( $attributes, $device );
245 + } )
246 + );
247 + $css_generator->add_class_styles(
248 + '{{WRAPPER}} .swiper-pagination-bullet:hover',
249 + $this->get_pagination_color_hover_css( $attributes ),
250 + $this->get_pagination_color_hover_css( $attributes, 'Tablet' ),
251 + $this->get_pagination_color_hover_css( $attributes, 'Mobile' ),
252 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
253 + return $this->get_pagination_color_hover_css( $attributes, $device );
254 + } )
255 + );
256 +
257 + $css_generator->add_class_styles(
258 + '{{WRAPPER}} .swiper-pagination-bullet.swiper-pagination-bullet-active',
259 + $this->get_pagination_active_color_css( $attributes ),
260 + $this->get_pagination_active_color_css( $attributes, 'Tablet' ),
261 + $this->get_pagination_active_color_css( $attributes, 'Mobile' ),
262 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
263 + return $this->get_pagination_active_color_css( $attributes, $device );
264 + } )
265 + );
266 + $css_generator->add_class_styles(
267 + '{{WRAPPER}} .swiper-pagination-bullet.swiper-pagination-bullet-active:hover',
268 + $this->get_pagination_active_color_hover_css( $attributes ),
269 + $this->get_pagination_active_color_hover_css( $attributes, 'Tablet' ),
270 + $this->get_pagination_active_color_hover_css( $attributes, 'Mobile' ),
271 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
272 + return $this->get_pagination_active_color_hover_css( $attributes, $device );
273 + } )
274 + );
275 +
276 + $css_generator->add_class_styles(
277 + '{{WRAPPER}} .ablocks-carousel-navigation__button .ablocks-svg-icon',
278 + $this->get_navigation_icon_svg_css( $attributes ),
279 + $this->get_navigation_icon_svg_css( $attributes, 'Tablet' ),
280 + $this->get_navigation_icon_svg_css( $attributes, 'Mobile' ),
281 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
282 + return $this->get_navigation_icon_svg_css( $attributes, $device );
283 + } )
284 + );
285 + $css_generator->add_class_styles(
286 + '{{WRAPPER}} .ablocks-carousel-navigation__button .ablocks-svg-icon:hover',
287 + $this->get_navigation_icon_svg_hover_css( $attributes ),
288 + $this->get_navigation_icon_svg_hover_css( $attributes, 'Tablet' ),
289 + $this->get_navigation_icon_svg_hover_css( $attributes, 'Mobile' ),
290 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) {
291 + return $this->get_navigation_icon_svg_hover_css( $attributes, $device );
292 + } )
293 + );
294 + return $css_generator->generate_css();
295 + }
296 + public function build_css( $attributes ) {
297 + if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
298 + return $this->build_css_v2( $attributes );
299 + }
300 + return $this->build_css_v1( $attributes );
301 + }
302 +
303 + public function get_carousel_css( $attributes, $device = '' ) {
304 + $carousel_css = [];
305 + // Temporary approch instead of attribute migration. Might remove it in future
306 + $verticalAlign = isset( $attributes['verticalAlign'][ 'value' . $device ] ) ? $attributes['verticalAlign'][ 'value' . $device ] : '';
307 + if (
308 + ! isset( $attributes['verticalAlign'] )
309 + || (
310 + $attributes['verticalAlignment'] !== '' && $attributes['verticalAlignment'] !== 'center'
311 + )
312 + ) {
313 + $attributes['verticalAlign'][ 'value' . $device ] = $attributes['verticalAlignment'];
314 + $attributes['verticalAlignment'] = '';
315 + } elseif (
316 + $attributes['verticalAlignment'] !== '' && $attributes['verticalAlignment'] === 'center'
317 + ) {
318 + $attributes['verticalAlignment'] = '';
319 + }
320 + // Temporary approch instead of attribute migration. Might remove it in future
321 +
322 + if ( ! empty( $attributes['verticalAlign'][ 'value' . $device ] ) ) {
323 + $carousel_css['align-items'] = $attributes['verticalAlign'][ 'value' . $device ];
324 + }
325 +
326 + // Room below the track for the offset active slide (wrapper is content-box).
327 + $offset = $this->get_active_slide_offset( $attributes, $device );
328 + if ( '' !== $offset ) {
329 + $carousel_css['padding-bottom'] = $offset;
330 + }
331 +
332 + return array_merge(
333 + Range::get_css([
334 + 'attributeValue' => $attributes['carouselHeight'],
335 + 'attribute_object_key' => 'value',
336 + 'isResponsive' => true,
337 + 'defaultValue' => 300,
338 + 'hasUnit' => true,
339 + 'unitDefaultValue' => 'px',
340 + 'property' => 'min-height',
341 + 'device' => $device,
342 + ]),
343 + $carousel_css,
344 + );
345 + }
346 +
347 +
348 + public function get_navigation_button_css( $attributes, $device = '' ) {
349 + $navigation_button_css = [];
350 +
351 + return array_merge(
352 + Range::get_css([
353 + 'attributeValue' => $attributes['navigationIconPositionY'],
354 + 'attribute_object_key' => 'value',
355 + 'defaultValue' => 50,
356 + 'isResponsive' => true,
357 + 'hasUnit' => true,
358 + 'unitDefaultValue' => '%',
359 + 'property' => 'top',
360 + 'device' => $device,
361 + ]),
362 + $navigation_button_css,
363 + );
364 + }
365 +
366 +
367 + public function get_navigation_prev_button_css( $attributes, $device = '' ) {
368 + $navigation_prev_button_css = [];
369 +
370 + return array_merge(
371 + Range::get_css([
372 + 'attributeValue' => $attributes['navigationIconPositionPrevX'],
373 + 'attribute_object_key' => 'value',
374 + 'defaultValue' => -3,
375 + 'hasUnit' => true,
376 + 'isResponsive' => true,
377 + 'unitDefaultValue' => '%',
378 + 'property' => 'left',
379 + 'device' => $device,
380 + ]),
381 + $navigation_prev_button_css,
382 + );
383 + }
384 +
385 + public function get_navigation_next_button_css( $attributes, $device = '' ) {
386 + $navigation_next_button_css = [];
387 +
388 + return array_merge(
389 + Range::get_css([
390 + 'attributeValue' => $attributes['navigationIconPositionNextX'],
391 + 'attribute_object_key' => 'value',
392 + 'defaultValue' => -3,
393 + 'isResponsive' => true,
394 + 'hasUnit' => true,
395 + 'unitDefaultValue' => '%',
396 + 'property' => 'right',
397 + 'device' => $device,
398 + ]),
399 + $navigation_next_button_css,
400 + );
401 + }
402 +
403 +
404 + public function get_navigation_icon_css( $attributes, $device = '' ) {
405 + $navigation_icon_css = [];
406 +
407 + return array_merge(
408 + Range::get_css([
409 + 'attributeValue' => $attributes['navigationIconSize'],
410 + 'attribute_object_key' => 'value',
411 + 'defaultValue' => 35,
412 + 'isResponsive' => true,
413 + 'hasUnit' => true,
414 + 'unitDefaultValue' => 'px',
415 + 'property' => 'font-size',
416 + 'device' => $device,
417 + ]),
418 + $navigation_icon_css,
419 + );
420 + }
421 +
422 +
423 + public function get_navigation_icon_svg_css( $attributes, $device = '' ) {
424 + $navigation_icon_svg_css = [];
425 + if ( isset( $attributes['navigationIconColor'] ) ) {
426 + $navigation_icon_svg_css['fill'] = Color::get_css( isset( $attributes['navigationIconColor'] ) ? $attributes['navigationIconColor'] : '' );
427 + };
428 + if ( isset( $attributes['navigationIconBgColor'] ) ) {
429 + $navigation_icon_svg_css['background-color'] = Color::get_css( isset( $attributes['navigationIconBgColor'] ) ? $attributes['navigationIconBgColor'] : '' );
430 + };
431 + return array_merge(
432 + $navigation_icon_svg_css,
433 + Dimensions::get_css( $this->with_custom_device_dimension_keys( $attributes['navigationIconPadding'], $device ), 'padding', $device ),
434 + Border::get_css( $attributes['navigationIconBorder'], '', $device ),
435 + BoxShadow::get_css( $attributes['navigationIconBoxShadow'], $device ),
436 + );
437 + }
438 + public function get_navigation_icon_svg_hover_css( $attributes, $device = '' ) {
439 + $navigation_icon_svg_hover_css = [];
440 + if ( isset( $attributes['navigationIconColorH'] ) ) {
441 + $navigation_icon_svg_hover_css['fill'] = Color::get_css( isset( $attributes['navigationIconColorH'] ) ? $attributes['navigationIconColorH'] : '' );
442 + };
443 + if ( isset( $attributes['navigationIconBgColorH'] ) ) {
444 + $navigation_icon_svg_hover_css['background-color'] = Color::get_css( isset( $attributes['navigationIconBgColorH'] ) ? $attributes['navigationIconBgColorH'] : '' );
445 + };
446 + return array_merge(
447 + Range::get_css([
448 + 'attributeValue' => $attributes['navigationIconTransition'],
449 + 'attribute_object_key' => 'value',
450 + 'defaultValue' => 10,
451 + 'unitDefaultValue' => 's',
452 + 'property' => 'transition-duration',
453 + 'device' => $device,
454 + ]),
455 + $navigation_icon_svg_hover_css,
456 + Border::get_hover_css( $attributes['navigationIconBorder'], '', $device ),
457 + BoxShadow::get_hover_css( $attributes['navigationIconBoxShadow'], '', $device ),
458 + );
459 + }
460 +
461 + public function get_pagination_parent_css( $attributes, $device = '' ) {
462 + return array_merge(
463 + Range::get_css([
464 + 'attributeValue' => $attributes['paginationPositionX'],
465 + 'attribute_object_key' => 'value',
466 + 'defaultValue' => 47,
467 + 'isResponsive' => true,
468 + 'hasUnit' => true,
469 + 'unitDefaultValue' => '%',
470 + 'property' => 'left',
471 + 'device' => $device,
472 + ]),
473 + Range::get_css([
474 + 'attributeValue' => $attributes['paginationPositionY'],
475 + 'attribute_object_key' => 'value',
476 + 'defaultValue' => 100,
477 + 'isResponsive' => true,
478 + 'hasUnit' => true,
479 + 'unitDefaultValue' => '%',
480 + 'property' => 'top',
481 + 'device' => $device,
482 + ]),
483 + );
484 + }
485 + public function get_pagination_color_css( $attributes, $device = '' ) {
486 + $pagination_color_css = [];
487 + $type = isset( $attributes['paginationType'] ) ? $attributes['paginationType'] : 'default';
488 + $pagination_color_css = [];
489 + if ( isset( $attributes['paginationColor'] ) ) {
490 + $color = Color::get_css( $attributes['paginationColor'] );
491 + if ( $type === 'default' ) {
492 + $pagination_color_css['background-color'] = $color;
493 + } elseif ( $type === 'border1' || $type === 'border3' ) {
494 + $pagination_color_css['border-color'] = $color;
495 + $pagination_color_css['background-color'] = 'transparent';
496 + } elseif ( $type === 'border2' ) {
497 + $pagination_color_css['background-color'] = $color;
498 + $pagination_color_css['border-color'] = $color;
499 + }
500 + }
501 + if ( $type === 'border3' ) {
502 + $dims = $this->get_ellipse_dims( $attributes['paginationSize'], $device );
503 + $pagination_color_css['width'] = $dims['width'];
504 + $pagination_color_css['height'] = $dims['height'];
505 + $pagination_color_css['border-radius'] = '9999px';
506 + }
507 + return array_merge(
508 + $pagination_color_css,
509 + ( $type === 'border3' ? [] : Range::get_css([
510 + 'attributeValue' => $attributes['paginationSize'],
511 + 'attribute_object_key' => 'value',
512 + 'defaultValue' => 8,
513 + 'isResponsive' => true,
514 + 'hasUnit' => true,
515 + 'unitDefaultValue' => 'px',
516 + 'property' => 'width',
517 + 'device' => $device,
518 + ]) ),
519 + ( $type === 'border3' ? [] : Range::get_css([
520 + 'attributeValue' => $attributes['paginationSize'],
521 + 'attribute_object_key' => 'value',
522 + 'defaultValue' => 8,
523 + 'isResponsive' => true,
524 + 'hasUnit' => true,
525 + 'unitDefaultValue' => 'px',
526 + 'property' => 'height',
527 + 'device' => $device,
528 + ]) ),
529 + Border::get_css( $attributes['paginationBorder'], '', $device ),
530 + );
531 + }
532 + public function get_pagination_color_hover_css( $attributes, $device = '' ) {
533 + $pagination_color_css = [];
534 + if ( isset( $attributes['paginationHoverColor'] ) ) {
535 + $pagination_color_css['background-color'] = $attributes['paginationHoverColor'];
536 + };
537 + $type = isset( $attributes['paginationType'] ) ? $attributes['paginationType'] : 'default';
538 + $pagination_color_css = [];
539 + if ( isset( $attributes['paginationHoverColor'] ) ) {
540 + $color = Color::get_css( $attributes['paginationHoverColor'] );
541 + if ( $type === 'default' ) {
542 + $pagination_color_css['background-color'] = $color;
543 + } elseif ( $type === 'border1' || $type === 'border3' ) {
544 + $pagination_color_css['border-color'] = $color;
545 + $pagination_color_css['background-color'] = $color;
546 + } elseif ( $type === 'border2' ) {
547 + $pagination_color_css['background-color'] = 'transparent';
548 + $pagination_color_css['border-color'] = $color;
549 + }
550 + }
551 + if ( $type === 'border3' ) {
552 + $dims = $this->get_ellipse_dims( $attributes['paginationHoverSize'], $device );
553 + $pagination_color_css['width'] = $dims['width'];
554 + $pagination_color_css['height'] = $dims['height'];
555 + $pagination_color_css['border-radius'] = '9999px';
556 + }
557 + return array_merge(
558 + $pagination_color_css,
559 + ( $type === 'border3' ? [] : Range::get_css([
560 + 'attributeValue' => $attributes['paginationHoverSize'],
561 + 'attribute_object_key' => 'value',
562 + 'defaultValue' => 8,
563 + 'isResponsive' => true,
564 + 'hasUnit' => true,
565 + 'unitDefaultValue' => 'px',
566 + 'property' => 'width',
567 + 'device' => $device,
568 + ]) ),
569 + ( $type === 'border3' ? [] : Range::get_css([
570 + 'attributeValue' => $attributes['paginationHoverSize'],
571 + 'attribute_object_key' => 'value',
572 + 'defaultValue' => 8,
573 + 'isResponsive' => true,
574 + 'hasUnit' => true,
575 + 'unitDefaultValue' => 'px',
576 + 'property' => 'height',
577 + 'device' => $device,
578 + ]) ),
579 + Border::get_hover_css( $attributes['paginationBorder'], '', $device ),
580 + );
581 + }
582 +
583 + public function get_pagination_active_color_css( $attributes, $device = '' ) {
584 + $pagination_active_color_css = [];
585 + $type = isset( $attributes['paginationType'] ) ? $attributes['paginationType'] : 'default';
586 + $pagination_active_color_css = [];
587 + if ( isset( $attributes['paginationActiveColor'] ) ) {
588 + $color = Color::get_css( $attributes['paginationActiveColor'] );
589 + if ( $type === 'default' ) {
590 + $pagination_active_color_css['background-color'] = $color;
591 + } elseif ( $type === 'border1' || $type === 'border3' ) {
592 + $pagination_active_color_css['background-color'] = $color;
593 + $pagination_active_color_css['border-color'] = $color;
594 + } elseif ( $type === 'border2' ) {
595 + $pagination_active_color_css['border-color'] = $color;
596 + $pagination_active_color_css['background-color'] = 'transparent';
597 + }
598 + }
599 + if ( $type === 'border3' ) {
600 + $dims = $this->get_ellipse_dims( $attributes['paginationActiveSize'], $device );
601 + $pagination_active_color_css['width'] = $dims['width'];
602 + $pagination_active_color_css['height'] = $dims['height'];
603 + $pagination_active_color_css['border-radius'] = '9999px';
604 + }
605 + return array_merge(
606 + $pagination_active_color_css,
607 + ( $type === 'border3' ? [] : Range::get_css([
608 + 'attributeValue' => $attributes['paginationActiveSize'],
609 + 'attribute_object_key' => 'value',
610 + 'defaultValue' => 8,
611 + 'isResponsive' => true,
612 + 'hasUnit' => true,
613 + 'unitDefaultValue' => 'px',
614 + 'property' => 'width',
615 + 'device' => $device,
616 + ]) ),
617 + ( $type === 'border3' ? [] : Range::get_css([
618 + 'attributeValue' => $attributes['paginationActiveSize'],
619 + 'attribute_object_key' => 'value',
620 + 'defaultValue' => 8,
621 + 'isResponsive' => true,
622 + 'hasUnit' => true,
623 + 'unitDefaultValue' => 'px',
624 + 'property' => 'height',
625 + 'device' => $device,
626 + ]) ),
627 + Border::get_css( $attributes['activePaginationBorder'], '', $device ),
628 + $this->get_pagination_active_width_css( $attributes, $device ),
629 + );
630 + }
631 + public function get_pagination_active_color_hover_css( $attributes, $device = '' ) {
632 + $pagination_active_color_css = [];
633 + $type = isset( $attributes['paginationType'] ) ? $attributes['paginationType'] : 'default';
634 + $pagination_active_color_css = [];
635 + if ( isset( $attributes['paginationActiveHoverColor'] ) ) {
636 + $color = Color::get_css( $attributes['paginationActiveHoverColor'] );
637 + if ( $type === 'default' ) {
638 + $pagination_active_color_css['background-color'] = $color;
639 + } elseif ( $type === 'border1' || $type === 'border3' ) {
640 + $pagination_active_color_css['border-color'] = $color;
641 + $pagination_active_color_css['background-color'] = 'transparent';
642 + } elseif ( $type === 'border2' ) {
643 + $pagination_active_color_css['background-color'] = $color;
644 + $pagination_active_color_css['border-color'] = $color;
645 + }
646 + }
647 + if ( $type === 'border3' ) {
648 + $dims = $this->get_ellipse_dims( $attributes['paginationActiveHoverSize'], $device );
649 + $pagination_active_color_css['width'] = $dims['width'];
650 + $pagination_active_color_css['height'] = $dims['height'];
651 + $pagination_active_color_css['border-radius'] = '9999px';
652 + }
653 +
654 + return array_merge(
655 + $pagination_active_color_css,
656 + ( $type === 'border3' ? [] : Range::get_css([
657 + 'attributeValue' => $attributes['paginationActiveHoverSize'],
658 + 'attribute_object_key' => 'value',
659 + 'defaultValue' => 8,
660 + 'isResponsive' => true,
661 + 'hasUnit' => true,
662 + 'unitDefaultValue' => 'px',
663 + 'property' => 'width',
664 + 'device' => $device,
665 + ]) ),
666 + ( $type === 'border3' ? [] : Range::get_css([
667 + 'attributeValue' => $attributes['paginationActiveHoverSize'],
668 + 'attribute_object_key' => 'value',
669 + 'defaultValue' => 8,
670 + 'isResponsive' => true,
671 + 'hasUnit' => true,
672 + 'unitDefaultValue' => 'px',
673 + 'property' => 'height',
674 + 'device' => $device,
675 + ]) ),
676 + Border::get_hover_css( $attributes['activePaginationBorder'], '', $device ),
677 + $this->get_pagination_active_width_css( $attributes, $device ),
678 + );
679 + }
680 +
681 + /**
682 + * Active-slide offset for a device ('' when unused). Only centered Slide
683 + * carousels use it; an explicit 0 is kept so it can override a wider
684 + * device. Mirrors getActiveSlideOffset() in styling.js.
685 + */
686 + public function get_active_slide_offset( $attributes, $device = '' ) {
687 + if (
688 + ( $attributes['effect'] ?? 'slide' ) !== 'slide'
689 + || empty( $attributes['centeredSlides'] )
690 + ) {
691 + return '';
692 + }
693 + $css = Range::get_css([
694 + 'attributeValue' => $attributes['activeSlideOffset'] ?? '',
695 + 'isResponsive' => true,
696 + 'hasUnit' => true,
697 + 'unitDefaultValue' => 'px',
698 + 'property' => 'offset',
699 + 'device' => $device,
700 + ]);
701 + return $css['offset'] ?? '';
702 + }
703 +
704 + public function get_slide_css( $attributes, $device = '' ) {
705 + return '' !== $this->get_active_slide_offset( $attributes, $device )
706 + ? [ 'transition' => 'transform 0.4s ease' ]
707 + : [];
708 + }
709 +
710 + public function get_active_slide_css( $attributes, $device = '' ) {
711 + $offset = $this->get_active_slide_offset( $attributes, $device );
712 + return '' !== $offset ? [ 'transform' => 'translateY(' . $offset . ')' ] : [];
713 + }
714 +
715 + // Pill-shaped active bullet: own width, height stays the Active Size.
716 + private function get_pagination_active_width_css( $attributes, $device = '' ) {
717 + if ( ( $attributes['paginationType'] ?? 'default' ) !== 'default' ) {
718 + return [];
719 + }
720 + $css = Range::get_css([
721 + 'attributeValue' => $attributes['paginationActiveWidth'] ?? '',
722 + 'isResponsive' => true,
723 + 'hasUnit' => true,
724 + 'unitDefaultValue' => 'px',
725 + 'property' => 'width',
726 + 'device' => $device,
727 + ]);
728 + if ( empty( $css['width'] ) ) {
729 + return [];
730 + }
731 + return [
732 + 'width' => $css['width'],
733 + 'border-radius' => '9999px',
734 + 'transition' => 'width 0.3s ease',
735 + ];
736 + }
737 +
738 + /**
739 + * Dimensions only knows the Tablet/Mobile members, so a custom breakpoint
740 + * suffix (or the generator's probe suffix) reads keys that were never
741 + * stored and raises "Undefined array key" notices. Seed those members as
742 + * unset; stored values still win, so the emitted CSS is unchanged.
743 + */
744 + private function with_custom_device_dimension_keys( $value, $device ) {
745 + if ( ! is_array( $value ) || in_array( $device, [ '', 'Tablet', 'Mobile' ], true ) ) {
746 + return $value;
747 + }
748 + return array_merge(
749 + [
750 + 'isLinked' . $device => false,
751 + 'common' . $device => '',
752 + 'top' . $device => '',
753 + 'right' . $device => '',
754 + 'bottom' . $device => '',
755 + 'left' . $device => '',
756 + ],
757 + $value
758 + );
759 + }
760 +
761 + private function get_ellipse_dims( $sizeAttr, $device = '', $default = 8, $ratio = 1.8 ) {
762 + $vKey = 'value' . $device;
763 + $uKey = 'valueUnit' . $device;
764 +
765 + $v = isset( $sizeAttr[ $vKey ] ) ? floatval( $sizeAttr[ $vKey ] )
766 + : ( isset( $sizeAttr['value'] ) ? floatval( $sizeAttr['value'] ) : $default );
767 + $u = isset( $sizeAttr[ $uKey ] ) ? $sizeAttr[ $uKey ]
768 + : ( isset( $sizeAttr['valueUnit'] ) ? $sizeAttr['valueUnit'] : 'px' );
769 +
770 + return [
771 + 'height' => $v . $u,
772 + 'width' => ( $v * $ratio ) . $u,
773 + ];
774 + }
775 +
776 +
777 +}