1<?php 2 3 4namespace ComboStrap; 5 6 7class FontSize 8{ 9 10 const FONT_SIZE = "font-size"; 11 const CANONICAL = self::FONT_SIZE; 12 13 const SCALE_TO_HEADING_NUMBER = [ 14 6=>1, 15 5=>2, 16 4=>3, 17 3=>4, 18 2=>5, 19 1=>6 20 ]; 21 const HEADING_NUMBER = [ 22 "h1"=>1, 23 "h2"=>2, 24 "h3"=>3, 25 "h4"=>4, 26 "h5"=>5, 27 "h6"=>6 28 ]; 29 30 /** 31 * 32 * https://getbootstrap.com/docs/5.0/utilities/text/#font-size 33 * @param TagAttributes $tagAttributes 34 */ 35 public static function processFontSizeAttribute(TagAttributes &$tagAttributes) 36 { 37 38 if ($tagAttributes->hasComponentAttribute(self::FONT_SIZE)) { 39 $value = $tagAttributes->getValueAndRemove(self::FONT_SIZE); 40 if(is_numeric($value)){ 41 if (key_exists($value, self::SCALE_TO_HEADING_NUMBER)){ 42 $headingValue = self::SCALE_TO_HEADING_NUMBER[$value]; 43 $tagAttributes->addClassName("fs-$headingValue"); 44 } else { 45 LogUtility::msg("The font-size scale value ($value) is not between 1 and 6.",LogUtility::LVL_MSG_ERROR,self::CANONICAL); 46 } 47 48 } else { 49 if (key_exists($value, self::HEADING_NUMBER)){ 50 $headingValue = self::HEADING_NUMBER[$value]; 51 $tagAttributes->addClassName("fs-$headingValue"); 52 } else { 53 $tagAttributes->addStyleDeclarationIfNotSet("font-size", $value); 54 } 55 } 56 } 57 58 } 59 60 61 62} 63