PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.7.1
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.7.1
1.7.1 1.7.0 1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 All 51 releases
← All changes | app/Services/Theme/Readers/BricksSettingsReader.php +92 -1 1.6.6 → 1.7.1 View file →
@@ -42,11 +42,15 @@
42 42 * palette colour as its fallback (see paletteValues()). A value that cannot be
43 43 * measured — a translucent rgba(), dynamic data, a gradient, a var() nothing
44 44 * resolves — is not stated.
45 45 *
46 + * Radii (see radii()) come from the same theme style: the button's border
47 + * radius (`button.primaryBorder`, else `button.border`) and the Form element's
48 + * field border radius (`form.fieldBorder`). Bricks has no product-card style.
49 + *
46 50 * Verified against Bricks 2.1.3.
47 51 */
48 -class BricksSettingsReader implements ThemeSettingsReader
52 +class BricksSettingsReader implements ThemeSettingsReader, ThemeRadiusReader
49 53 {
50 54 /**
51 55 * Bricks' stylesheet: `body{background-color:#fff}` (frontend.min.css).
52 56 *
@@ -583,6 +587,93 @@
583 587 }
584 588 }
585 589
586 590 return $entries;
591 + }
592 +
593 + /**
594 + * The button and form-field radii of the theme style Bricks applies.
595 + *
596 + * Button: the primary button's border (`:root .bricks-button[class*="primary"]`,
597 + * the style a new Button element gets) over every button's
598 + * (`.bricks-button`). Input: the Form element's field border
599 + * (`.brxe-form` inputs, selects and textareas) — the only field radius a
600 + * theme style holds. A style that sets neither states none; Bricks'
601 + * stylesheet is not read for one.
602 + *
603 + * @return array Role => length, as Bricks prints it.
604 + */
605 + public static function radii(): array
606 + {
607 + if (!self::applies()) {
608 + return [];
609 + }
610 +
611 + $styles = self::activeStyles();
612 +
613 + if (!$styles) {
614 + return [];
615 + }
616 +
617 + $radii = [];
618 +
619 + foreach (['primaryBorder', 'border'] as $key) {
620 + $radius = self::setting($styles, 'button', $key, 'radius');
621 +
622 + if ($radius !== null) {
623 + $radii['btn'] = self::radiusLength($radius);
624 + break;
625 + }
626 + }
627 +
628 + $field = self::setting($styles, 'form', 'fieldBorder', 'radius');
629 +
630 + if ($field !== null) {
631 + $radii['input'] = self::radiusLength($field);
632 + }
633 +
634 + return array_filter($radii, function ($value) {
635 + return $value !== '';
636 + });
637 + }
638 +
639 + /**
640 + * A border control's radius as one length, built the way
641 + * Assets::generate_css_rules_from_setting() builds it: per corner, a
642 + * non-zero bare number takes px, otherwise the corner's unit is appended
643 + * unless the value already carries it. Only four set, equal corners are
644 + * one length.
645 + *
646 + * @param mixed $radius
647 + * @return string
648 + */
649 + protected static function radiusLength($radius): string
650 + {
651 + if (!is_array($radius)) {
652 + return '';
653 + }
654 +
655 + $units = isset($radius['unit']) && is_array($radius['unit']) ? $radius['unit'] : [];
656 + $corners = [];
657 +
658 + foreach (['top', 'right', 'bottom', 'left'] as $direction) {
659 + $number = isset($radius[$direction]) && is_scalar($radius[$direction]) ? (string)$radius[$direction] : '';
660 + $unit = !empty($units[$direction]) && is_string($units[$direction]) ? $units[$direction] : '';
661 +
662 + if ($number === '') {
663 + return '';
664 + }
665 +
666 + if (is_numeric($number) && (float)$number != 0) {
667 + $unit = 'px';
668 + }
669 +
670 + if ($unit === '-' || $unit === 'none') {
671 + $unit = '';
672 + }
673 +
674 + $corners[] = $unit !== '' && strpos($number, $unit) === false ? $number . $unit : $number;
675 + }
676 +
677 + return count(array_unique($corners)) === 1 ? $corners[0] : '';
587 678 }
588 679 }