< Summary

Information
Class: Allyaria.Theming.Styles.AllyariaStyle
Assembly: Allyaria.Theming
File(s): /home/runner/work/allyaria/allyaria/src/Allyaria.Theming/Styles/AllyariaStyle.cs
Line coverage
100%
Covered lines: 28
Uncovered lines: 0
Coverable lines: 28
Total lines: 112
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
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%44100%
get_Palette()100%11100%
get_PaletteDisabled()100%11100%
get_PaletteHover()100%11100%
get_Typography()100%11100%
get_TypographyDisabled()100%11100%
get_TypographyHover()100%11100%
ToCss()100%11100%
ToCssHover()100%11100%
ToCssVars(...)100%22100%

File(s)

/home/runner/work/allyaria/allyaria/src/Allyaria.Theming/Styles/AllyariaStyle.cs

#LineLine coverage
 1using System.Text.RegularExpressions;
 2
 3namespace Allyaria.Theming.Styles;
 4
 5/// <summary>
 6/// Represents a combined Allyaria style that encapsulates both palette and typography settings. Provides methods to
 7/// generate CSS fragments and CSS custom property declarations for applying the style, including distinct "hover"
 8/// variants.
 9/// </summary>
 10public readonly record struct AllyariaStyle
 11{
 12    /// <summary>Initializes a new instance of the <see cref="AllyariaStyle" /> struct.</summary>
 13    /// <param name="palette">The color palette to apply.</param>
 14    /// <param name="typography">The typography settings to apply.</param>
 15    /// <param name="paletteHover">
 16    /// The color palette to apply for hover effects. If null, it is derived from <paramref name="palette" />.
 17    /// </param>
 18    /// <param name="typographyHover">
 19    /// The typography settings to apply for hover effects. Defaults to
 20    /// <paramref name="typography" />.
 21    /// </param>
 22    /// <param name="paletteDisabled">
 23    /// The color palette to apply for disabled state. If null, it is derived from <paramref name="palette" />.
 24    /// </param>
 25    /// <param name="typographyDisabled">
 26    /// The typography settings to apply for disabled state. Defaults to
 27    /// <paramref name="typography" />.
 28    /// </param>
 29    public AllyariaStyle(AllyariaPalette palette,
 30        AllyariaTypography typography,
 31        AllyariaPalette? paletteHover = null,
 32        AllyariaTypography? typographyHover = null,
 33        AllyariaPalette? paletteDisabled = null,
 34        AllyariaTypography? typographyDisabled = null)
 35    {
 2036        Palette = palette;
 2037        Typography = typography;
 2038        PaletteHover = paletteHover ?? palette.ToHoverPalette();
 2039        TypographyHover = typographyHover ?? typography;
 2040        PaletteDisabled = paletteDisabled ?? palette.ToDisabledPalette();
 2041        TypographyDisabled = typographyDisabled ?? typography;
 2042    }
 43
 44    /// <summary>Gets the color palette to apply.</summary>
 1045    public AllyariaPalette Palette { get; }
 46
 47    /// <summary>Gets the color palette to apply for disabled state.</summary>
 1448    public AllyariaPalette PaletteDisabled { get; }
 49
 50    /// <summary>Gets the color palette to apply for hover effects.</summary>
 1651    public AllyariaPalette PaletteHover { get; }
 52
 53    /// <summary>Gets the typography settings to apply.</summary>
 1054    public AllyariaTypography Typography { get; }
 55
 56    /// <summary>Gets the typography settings to apply for disabled state.</summary>
 857    public AllyariaTypography TypographyDisabled { get; }
 58
 59    /// <summary>Gets the typography settings to apply for hover effects.</summary>
 1460    public AllyariaTypography TypographyHover { get; }
 61
 62    /// <summary>Builds the full CSS string for this style, combining palette and typography CSS.</summary>
 63    /// <returns>A concatenated CSS string including palette and typography CSS.</returns>
 264    public string ToCss() => string.Concat(Palette.ToCss(), Typography.ToCss());
 65
 66    /// <summary>
 67    /// Builds the full CSS string for the <c>:hover</c> state, combining hover palette and hover typography CSS.
 68    /// </summary>
 69    /// <returns>A concatenated CSS string including hover palette and hover typography CSS.</returns>
 270    public string ToCssHover() => string.Concat(PaletteHover.ToCss(), TypographyHover.ToCss());
 71
 72    /// <summary>
 73    /// Builds a CSS string for custom property (variable) declarations representing this style and its hover variants. 
 74    /// optional <paramref name="prefix" /> is normalized by trimming whitespace and dashes, converting to lowercase, an
 75    /// replacing spaces with hyphens. If no usable prefix remains, variables are emitted with the default <c>aa</c> pre
 76    /// Hover prefix appends <c>-hover</c> to the prefix.
 77    /// </summary>
 78    /// <param name="prefix">
 79    /// An optional namespace for the CSS variables (e.g., <c>"editor"</c>). Spaces and control characters are replaced 
 80    /// hyphens. If empty or whitespace, defaults to <c>aa</c>. Hover prefix appends <c>-hover</c> to the prefix.
 81    /// </param>
 82    /// <returns>
 83    /// A concatenated CSS string that includes palette and typography variable declarations for both base and hover sta
 84    /// using the same normalized prefix.
 85    /// </returns>
 86    /// <remarks>
 87    /// This method composes the results of <see cref="AllyariaPalette.ToCssVars(string)" /> and
 88    /// <see cref="AllyariaTypography.ToCssVars(string)" /> with a normalized prefix. Hover variables are emitted with a
 89    /// additional <c>-hover</c> suffix appended to the base prefix.
 90    /// </remarks>
 91    public string ToCssVars(string prefix = "")
 92    {
 893        var basePrefix = Regex.Replace(prefix, @"[\s-]+", "-").Trim('-').ToLowerInvariant();
 94
 895        if (string.IsNullOrWhiteSpace(basePrefix))
 96        {
 497            basePrefix = "aa";
 98        }
 99
 8100        var disabledPrefix = $"{basePrefix}-disabled";
 8101        var hoverPrefix = $"{basePrefix}-hover";
 102
 8103        return string.Concat(
 8104            Palette.ToCssVars(basePrefix),
 8105            Typography.ToCssVars(basePrefix),
 8106            PaletteDisabled.ToCssVars(disabledPrefix),
 8107            TypographyDisabled.ToCssVars(disabledPrefix),
 8108            PaletteHover.ToCssVars(hoverPrefix),
 8109            TypographyHover.ToCssVars(hoverPrefix)
 8110        );
 111    }
 112}