< Summary

Information
Class: Allyaria.Theming.Helpers.ThemeFontApplier
Assembly: Allyaria.Theming
File(s): /home/runner/work/allyaria/allyaria/src/Allyaria.Theming/Helpers/ThemeFontApplier.cs
Line coverage
100%
Covered lines: 72
Uncovered lines: 0
Coverable lines: 72
Total lines: 186
Line coverage: 100%
Branch coverage
100%
Covered branches: 22
Total branches: 22
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%2222100%

File(s)

/home/runner/work/allyaria/allyaria/src/Allyaria.Theming/Helpers/ThemeFontApplier.cs

#LineLine coverage
 1namespace 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>
 21internal 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)
 16569        : base(themeMapper: themeMapper, isHighContrast: isHighContrast, componentType: componentType)
 70    {
 71        // Apply palette-based colors (optional)
 16572        if (paletteType is not null)
 73        {
 1974            AddRange(
 1975                collection: new ThemeColorApplier(
 1976                    themeMapper: themeMapper,
 1977                    isHighContrast: isHighContrast,
 1978                    componentType: componentType,
 1979                    paletteType: paletteType.Value,
 1980                    isVariant: true,
 1981                    hasBackground: false,
 1982                    isOutline: false
 1983                )
 1984            );
 85        }
 86
 87        // Apply font family
 16588        if (fontFace is not null)
 89        {
 1890            Add(
 1891                item: themeMapper.GetFont(
 1892                    isHighContrast: isHighContrast,
 1893                    componentType: componentType,
 1894                    fontType: fontFace.Value
 1895                )
 1896            );
 97        }
 98
 99        // Apply font size
 165100        if (!string.IsNullOrWhiteSpace(value: fontSize))
 101        {
 145102            Add(item: CreateUpdater(styleType: StyleType.FontSize, value: new StyleLength(value: fontSize)));
 103        }
 104
 105        // Apply font style (italic/normal)
 165106        if (fontStyle is not null)
 107        {
 1108            Add(item: CreateUpdater(styleType: StyleType.FontStyle, value: new StyleFontStyle(kind: fontStyle.Value)));
 109        }
 110
 111        // Apply font weight (e.g., 400, 700)
 165112        if (fontWeight is not null)
 113        {
 97114            Add(
 97115                item: CreateUpdater(styleType: StyleType.FontWeight, value: new StyleFontWeight(kind: fontWeight.Value))
 97116            );
 117        }
 118
 119        // Apply line height
 165120        if (!string.IsNullOrWhiteSpace(value: lineHeight))
 121        {
 145122            Add(item: CreateUpdater(styleType: StyleType.LineHeight, value: new StyleLength(value: lineHeight)));
 123        }
 124
 125        // Apply bottom margin and padding reset
 165126        if (!string.IsNullOrWhiteSpace(value: marginBottom))
 127        {
 113128            Add(
 113129                item: CreateUpdater(
 113130                    styleType: StyleType.Margin, value: new StyleGroup(
 113131                        type: StyleGroupType.Margin,
 113132                        blockStart: new StyleLength(value: Sizing.Size0),
 113133                        blockEnd: new StyleLength(value: marginBottom),
 113134                        inlineStart: new StyleLength(value: Sizing.Size0),
 113135                        inlineEnd: new StyleLength(value: Sizing.Size0)
 113136                    )
 113137                )
 113138            );
 139
 113140            Add(item: CreateUpdater(styleType: StyleType.Padding, value: new StyleLength(value: Sizing.Size0)));
 141        }
 142
 143        // Apply text decoration line (e.g., underline)
 165144        if (textDecorationLine is not null)
 145        {
 17146            Add(
 17147                item: CreateUpdater(
 17148                    styleType: StyleType.TextDecorationLine,
 17149                    value: new StyleTextDecorationLine(kind: textDecorationLine.Value)
 17150                )
 17151            );
 152        }
 153
 154        // Apply text decoration style (e.g., solid, dotted)
 165155        if (textDecorationStyle is not null)
 156        {
 17157            Add(
 17158                item: CreateUpdater(
 17159                    styleType: StyleType.TextDecorationStyle,
 17160                    value: new StyleTextDecorationStyle(kind: textDecorationStyle.Value)
 17161                )
 17162            );
 163        }
 164
 165        // Apply text decoration thickness
 165166        if (!string.IsNullOrWhiteSpace(value: textDecorationThickness))
 167        {
 17168            Add(
 17169                item: CreateUpdater(
 17170                    styleType: StyleType.TextDecorationThickness,
 17171                    value: new StyleLength(value: textDecorationThickness)
 17172                )
 17173            );
 174        }
 175
 176        // Apply text transform (uppercase, lowercase, capitalize)
 165177        if (textTransform is not null)
 178        {
 1179            Add(
 1180                item: CreateUpdater(
 1181                    styleType: StyleType.TextTransform, value: new StyleTextTransform(kind: textTransform.Value)
 1182                )
 1183            );
 184        }
 165185    }
 186}