< Summary

Information
Class: Allyaria.Theming.StyleTypes.StyleGroup
Assembly: Allyaria.Theming
File(s): /home/runner/work/allyaria/allyaria/src/Allyaria.Theming/StyleTypes/StyleGroup.cs
Line coverage
100%
Covered lines: 40
Uncovered lines: 0
Coverable lines: 40
Total lines: 126
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
get_BlockEnd()100%11100%
get_BlockStart()100%11100%
get_InlineEnd()100%11100%
get_InlineStart()100%11100%
get_Type()100%11100%
get_Value()100%11100%
BuildCss(...)100%11100%
ToCss(...)100%11100%

File(s)

/home/runner/work/allyaria/allyaria/src/Allyaria.Theming/StyleTypes/StyleGroup.cs

#LineLine coverage
 1namespace Allyaria.Theming.StyleTypes;
 2
 3/// <summary>
 4/// Represents a grouped set of logical CSS values for block and inline directions, implementing <see cref="IStyleValue"
 5/// so that it can participate in the Allyaria theming pipeline. A <see cref="StyleGroup" /> computes its final CSS usin
 6/// the associated <see cref="StyleGroupType" />.
 7/// </summary>
 8public sealed record StyleGroup : IStyleValue
 9{
 10    /// <summary>
 11    /// Initializes a new instance of the <see cref="StyleGroup" /> record with a single <see cref="IStyleValue" /> appl
 12    /// all logical directions (block-start, block-end, inline-start, inline-end).
 13    /// </summary>
 14    /// <param name="type">
 15    /// The <see cref="StyleGroupType" /> that describes which CSS properties will be generated for this group.
 16    /// </param>
 17    /// <param name="value">The style value applied uniformly to all logical directions in the group.</param>
 218    public StyleGroup(StyleGroupType type, IStyleValue value)
 19    {
 220        BlockEnd = value;
 221        BlockStart = value;
 222        InlineEnd = value;
 223        InlineStart = value;
 224        Type = type;
 225    }
 26
 27    /// <summary>
 28    /// Initializes a new instance of the <see cref="StyleGroup" /> record with separate <see cref="IStyleValue" /> valu
 29    /// block and inline dimensions. The block value is used for both block-start and block-end, and the inline value is
 30    /// for both inline-start and inline-end.
 31    /// </summary>
 32    /// <param name="type">
 33    /// The <see cref="StyleGroupType" /> that describes which CSS properties will be generated for this group.
 34    /// </param>
 35    /// <param name="block">The style value applied to the block-start and block-end logical directions.</param>
 36    /// <param name="inline">The style value applied to the inline-start and inline-end logical directions.</param>
 137    public StyleGroup(StyleGroupType type, IStyleValue block, IStyleValue inline)
 38    {
 139        BlockEnd = block;
 140        BlockStart = block;
 141        InlineEnd = inline;
 142        InlineStart = inline;
 143        Type = type;
 144    }
 45
 46    /// <summary>
 47    /// Initializes a new instance of the <see cref="StyleGroup" /> record with explicit values for each logical directi
 48    /// (block-start, block-end, inline-start, inline-end).
 49    /// </summary>
 50    /// <param name="type">
 51    /// The <see cref="StyleGroupType" /> that describes which CSS properties will be generated for this group.
 52    /// </param>
 53    /// <param name="blockStart">The style value applied to the block-start logical direction.</param>
 54    /// <param name="blockEnd">The style value applied to the block-end logical direction.</param>
 55    /// <param name="inlineStart">The style value applied to the inline-start logical direction.</param>
 56    /// <param name="inlineEnd">The style value applied to the inline-end logical direction.</param>
 11657    public StyleGroup(StyleGroupType type,
 11658        IStyleValue blockStart,
 11659        IStyleValue blockEnd,
 11660        IStyleValue inlineStart,
 11661        IStyleValue inlineEnd)
 62    {
 11663        BlockEnd = blockEnd;
 11664        BlockStart = blockStart;
 11665        InlineEnd = inlineEnd;
 11666        InlineStart = inlineStart;
 11667        Type = type;
 11668    }
 69
 70    /// <summary>Gets the style value associated with the block-end logical direction.</summary>
 169671    public IStyleValue BlockEnd { get; init; }
 72
 73    /// <summary>Gets the style value associated with the block-start logical direction.</summary>
 169674    public IStyleValue BlockStart { get; init; }
 75
 76    /// <summary>Gets the style value associated with the inline-end logical direction.</summary>
 169677    public IStyleValue InlineEnd { get; init; }
 78
 79    /// <summary>Gets the style value associated with the inline-start logical direction.</summary>
 169680    public IStyleValue InlineStart { get; init; }
 81
 82    /// <summary>
 83    /// Gets the <see cref="StyleGroupType" /> that determines which underlying CSS properties are produced when this gr
 84    /// rendered.
 85    /// </summary>
 12586    public StyleGroupType Type { get; init; }
 87
 88    /// <summary>
 89    /// Gets a composite string value representing the grouped styles in the order: block-end, block-start, inline-end,
 90    /// inline-start. This is the logical value exposed via <see cref="IStyleValue.Value" />.
 91    /// </summary>
 157192    public string Value => $"{BlockEnd.Value} {BlockStart.Value} {InlineEnd.Value} {InlineStart.Value}";
 93
 94    /// <summary>
 95    /// Adds the grouped style values to the provided <see cref="CssBuilder" /> instance using the CSS property names re
 96    /// from <see cref="Type" />.
 97    /// </summary>
 98    /// <param name="builder">The <see cref="CssBuilder" /> to which the CSS variables/properties are added.</param>
 99    /// <param name="varPrefix">
 100    /// An optional prefix used when emitting CSS custom properties or variables. If <see langword="null" /> or empty, n
 101    /// prefix is applied.
 102    /// </param>
 103    /// <returns>The same <see cref="CssBuilder" /> instance passed in, allowing fluent chaining of method calls.</retur
 104    internal CssBuilder BuildCss(CssBuilder builder, string? varPrefix = "")
 105    {
 3106        var typeDescription = Type.GetDescription();
 3107        var typeList = typeDescription.Split(separator: ',');
 108
 3109        builder
 3110            .Add(name: typeList[0], value: BlockEnd.Value, varPrefix: varPrefix)
 3111            .Add(name: typeList[1], value: BlockStart.Value, varPrefix: varPrefix)
 3112            .Add(name: typeList[2], value: InlineEnd.Value, varPrefix: varPrefix)
 3113            .Add(name: typeList[3], value: InlineStart.Value, varPrefix: varPrefix);
 114
 3115        return builder;
 116    }
 117
 118    /// <summary>Builds the CSS representation for this <see cref="StyleGroup" /> and returns it as a string.</summary>
 119    /// <param name="varPrefix">
 120    /// An optional prefix used when emitting CSS custom properties or variables. If <see langword="null" />, the defaul
 121    /// prefixing behavior for <see cref="CssBuilder" /> is used.
 122    /// </param>
 123    /// <returns>A string containing the serialized CSS generated from this <see cref="StyleGroup" />.</returns>
 124    public string ToCss(string? varPrefix = null)
 2125        => BuildCss(builder: new CssBuilder(), varPrefix: varPrefix).ToString();
 126}