| | | 1 | | namespace Allyaria.Theming.Helpers; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Applies font, text, and spacing-related styles to a given <see cref="ComponentType" /> using Allyaria theming |
| | | 5 | | /// conventions. |
| | | 6 | | /// </summary> |
| | | 7 | | /// <remarks> |
| | | 8 | | /// <para> |
| | | 9 | | /// The <see cref="ThemeFontApplier" /> class allows for applying typography settings such as font face, size, weigh |
| | | 10 | | /// line height, margin, and text decoration. |
| | | 11 | | /// </para> |
| | | 12 | | /// <para> |
| | | 13 | | /// It also supports color inheritance from the specified <see cref="PaletteType" /> when applicable, ensuring that |
| | | 14 | | /// font styling remains consistent across brand variants and accessibility modes. |
| | | 15 | | /// </para> |
| | | 16 | | /// <para> |
| | | 17 | | /// This class is used by <see cref="ThemeBuilder" /> to configure typography for headings, paragraphs, links, and |
| | | 18 | | /// global text elements. |
| | | 19 | | /// </para> |
| | | 20 | | /// </remarks> |
| | | 21 | | internal sealed class ThemeFontApplier : ThemeApplierBase |
| | | 22 | | { |
| | | 23 | | /// <summary> |
| | | 24 | | /// Initializes a new instance of the <see cref="ThemeFontApplier" /> class with optional typography and color param |
| | | 25 | | /// </summary> |
| | | 26 | | /// <param name="themeMapper">The <see cref="ThemeMapper" /> instance used for theme resolution.</param> |
| | | 27 | | /// <param name="isHighContrast">Specifies whether the configuration targets high-contrast themes.</param> |
| | | 28 | | /// <param name="componentType">The <see cref="ComponentType" /> representing the element being styled.</param> |
| | | 29 | | /// <param name="paletteType"> |
| | | 30 | | /// Optional. The <see cref="PaletteType" /> defining which color family to use for the text element. If provided, c |
| | | 31 | | /// are applied through a <see cref="ThemeColorApplier" />. |
| | | 32 | | /// </param> |
| | | 33 | | /// <param name="fontFace"> |
| | | 34 | | /// Optional. The <see cref="FontFaceType" /> identifying which font family to apply. If not provided, defaults to t |
| | | 35 | | /// brand's standard font. |
| | | 36 | | /// </param> |
| | | 37 | | /// <param name="fontSize">Optional. The font size (e.g., "1rem", "16px").</param> |
| | | 38 | | /// <param name="fontStyle">Optional. The <see cref="StyleFontStyle.Kind" /> indicating italic or normal style.</par |
| | | 39 | | /// <param name="fontWeight">Optional. The <see cref="StyleFontWeight.Kind" /> indicating font weight (e.g., 400, 70 |
| | | 40 | | /// <param name="lineHeight">Optional. The line height value, typically expressed as a unitless number or CSS length |
| | | 41 | | /// <param name="marginBottom"> |
| | | 42 | | /// Optional. The bottom margin for typographic spacing, typically applied to headings or |
| | | 43 | | /// paragraphs. |
| | | 44 | | /// </param> |
| | | 45 | | /// <param name="textDecorationLine"> |
| | | 46 | | /// Optional. The <see cref="StyleTextDecorationLine.Kind" /> defining which text decoration line (e.g., underline). |
| | | 47 | | /// </param> |
| | | 48 | | /// <param name="textDecorationStyle"> |
| | | 49 | | /// Optional. The <see cref="StyleTextDecorationStyle.Kind" /> specifying the decoration style (solid, dotted, etc.) |
| | | 50 | | /// </param> |
| | | 51 | | /// <param name="textDecorationThickness">Optional. The CSS thickness value (e.g., "2px") for text decorations.</par |
| | | 52 | | /// <param name="textTransform"> |
| | | 53 | | /// Optional. The <see cref="StyleTextTransform.Kind" /> specifying text casing (uppercase, lowercase, etc.). |
| | | 54 | | /// </param> |
| | | 55 | | public ThemeFontApplier(ThemeMapper themeMapper, |
| | | 56 | | bool isHighContrast, |
| | | 57 | | ComponentType componentType, |
| | | 58 | | PaletteType? paletteType = null, |
| | | 59 | | FontFaceType? fontFace = null, |
| | | 60 | | string? fontSize = null, |
| | | 61 | | StyleFontStyle.Kind? fontStyle = null, |
| | | 62 | | StyleFontWeight.Kind? fontWeight = null, |
| | | 63 | | string? lineHeight = null, |
| | | 64 | | string? marginBottom = null, |
| | | 65 | | StyleTextDecorationLine.Kind? textDecorationLine = null, |
| | | 66 | | StyleTextDecorationStyle.Kind? textDecorationStyle = null, |
| | | 67 | | string? textDecorationThickness = null, |
| | | 68 | | StyleTextTransform.Kind? textTransform = null) |
| | 165 | 69 | | : base(themeMapper: themeMapper, isHighContrast: isHighContrast, componentType: componentType) |
| | | 70 | | { |
| | | 71 | | // Apply palette-based colors (optional) |
| | 165 | 72 | | if (paletteType is not null) |
| | | 73 | | { |
| | 19 | 74 | | AddRange( |
| | 19 | 75 | | collection: new ThemeColorApplier( |
| | 19 | 76 | | themeMapper: themeMapper, |
| | 19 | 77 | | isHighContrast: isHighContrast, |
| | 19 | 78 | | componentType: componentType, |
| | 19 | 79 | | paletteType: paletteType.Value, |
| | 19 | 80 | | isVariant: true, |
| | 19 | 81 | | hasBackground: false, |
| | 19 | 82 | | isOutline: false |
| | 19 | 83 | | ) |
| | 19 | 84 | | ); |
| | | 85 | | } |
| | | 86 | | |
| | | 87 | | // Apply font family |
| | 165 | 88 | | if (fontFace is not null) |
| | | 89 | | { |
| | 18 | 90 | | Add( |
| | 18 | 91 | | item: themeMapper.GetFont( |
| | 18 | 92 | | isHighContrast: isHighContrast, |
| | 18 | 93 | | componentType: componentType, |
| | 18 | 94 | | fontType: fontFace.Value |
| | 18 | 95 | | ) |
| | 18 | 96 | | ); |
| | | 97 | | } |
| | | 98 | | |
| | | 99 | | // Apply font size |
| | 165 | 100 | | if (!string.IsNullOrWhiteSpace(value: fontSize)) |
| | | 101 | | { |
| | 145 | 102 | | Add(item: CreateUpdater(styleType: StyleType.FontSize, value: new StyleLength(value: fontSize))); |
| | | 103 | | } |
| | | 104 | | |
| | | 105 | | // Apply font style (italic/normal) |
| | 165 | 106 | | if (fontStyle is not null) |
| | | 107 | | { |
| | 1 | 108 | | Add(item: CreateUpdater(styleType: StyleType.FontStyle, value: new StyleFontStyle(kind: fontStyle.Value))); |
| | | 109 | | } |
| | | 110 | | |
| | | 111 | | // Apply font weight (e.g., 400, 700) |
| | 165 | 112 | | if (fontWeight is not null) |
| | | 113 | | { |
| | 97 | 114 | | Add( |
| | 97 | 115 | | item: CreateUpdater(styleType: StyleType.FontWeight, value: new StyleFontWeight(kind: fontWeight.Value)) |
| | 97 | 116 | | ); |
| | | 117 | | } |
| | | 118 | | |
| | | 119 | | // Apply line height |
| | 165 | 120 | | if (!string.IsNullOrWhiteSpace(value: lineHeight)) |
| | | 121 | | { |
| | 145 | 122 | | Add(item: CreateUpdater(styleType: StyleType.LineHeight, value: new StyleLength(value: lineHeight))); |
| | | 123 | | } |
| | | 124 | | |
| | | 125 | | // Apply bottom margin and padding reset |
| | 165 | 126 | | if (!string.IsNullOrWhiteSpace(value: marginBottom)) |
| | | 127 | | { |
| | 113 | 128 | | Add( |
| | 113 | 129 | | item: CreateUpdater( |
| | 113 | 130 | | styleType: StyleType.Margin, value: new StyleGroup( |
| | 113 | 131 | | type: StyleGroupType.Margin, |
| | 113 | 132 | | blockStart: new StyleLength(value: Sizing.Size0), |
| | 113 | 133 | | blockEnd: new StyleLength(value: marginBottom), |
| | 113 | 134 | | inlineStart: new StyleLength(value: Sizing.Size0), |
| | 113 | 135 | | inlineEnd: new StyleLength(value: Sizing.Size0) |
| | 113 | 136 | | ) |
| | 113 | 137 | | ) |
| | 113 | 138 | | ); |
| | | 139 | | |
| | 113 | 140 | | Add(item: CreateUpdater(styleType: StyleType.Padding, value: new StyleLength(value: Sizing.Size0))); |
| | | 141 | | } |
| | | 142 | | |
| | | 143 | | // Apply text decoration line (e.g., underline) |
| | 165 | 144 | | if (textDecorationLine is not null) |
| | | 145 | | { |
| | 17 | 146 | | Add( |
| | 17 | 147 | | item: CreateUpdater( |
| | 17 | 148 | | styleType: StyleType.TextDecorationLine, |
| | 17 | 149 | | value: new StyleTextDecorationLine(kind: textDecorationLine.Value) |
| | 17 | 150 | | ) |
| | 17 | 151 | | ); |
| | | 152 | | } |
| | | 153 | | |
| | | 154 | | // Apply text decoration style (e.g., solid, dotted) |
| | 165 | 155 | | if (textDecorationStyle is not null) |
| | | 156 | | { |
| | 17 | 157 | | Add( |
| | 17 | 158 | | item: CreateUpdater( |
| | 17 | 159 | | styleType: StyleType.TextDecorationStyle, |
| | 17 | 160 | | value: new StyleTextDecorationStyle(kind: textDecorationStyle.Value) |
| | 17 | 161 | | ) |
| | 17 | 162 | | ); |
| | | 163 | | } |
| | | 164 | | |
| | | 165 | | // Apply text decoration thickness |
| | 165 | 166 | | if (!string.IsNullOrWhiteSpace(value: textDecorationThickness)) |
| | | 167 | | { |
| | 17 | 168 | | Add( |
| | 17 | 169 | | item: CreateUpdater( |
| | 17 | 170 | | styleType: StyleType.TextDecorationThickness, |
| | 17 | 171 | | value: new StyleLength(value: textDecorationThickness) |
| | 17 | 172 | | ) |
| | 17 | 173 | | ); |
| | | 174 | | } |
| | | 175 | | |
| | | 176 | | // Apply text transform (uppercase, lowercase, capitalize) |
| | 165 | 177 | | if (textTransform is not null) |
| | | 178 | | { |
| | 1 | 179 | | Add( |
| | 1 | 180 | | item: CreateUpdater( |
| | 1 | 181 | | styleType: StyleType.TextTransform, value: new StyleTextTransform(kind: textTransform.Value) |
| | 1 | 182 | | ) |
| | 1 | 183 | | ); |
| | | 184 | | } |
| | 165 | 185 | | } |
| | | 186 | | } |