< Summary

Information
Class: Allyaria.Theming.StyleTypes.StyleAlign
Assembly: Allyaria.Theming
File(s): /home/runner/work/allyaria/allyaria/src/Allyaria.Theming/StyleTypes/StyleAlign.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 127
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
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%11100%
Parse(...)100%22100%
TryParse(...)100%11100%
op_Implicit(...)100%11100%
op_Implicit(...)100%22100%

File(s)

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

#LineLine coverage
 1namespace Allyaria.Theming.StyleTypes;
 2
 3/// <summary>
 4/// Represents a CSS alignment value used within the Allyaria theming system. Provides typed access to standard CSS
 5/// alignment keywords (e.g., center, start, stretch) through the <see cref="Kind" /> enumeration.
 6/// </summary>
 7public sealed record StyleAlign : StyleValueBase
 8{
 9    /// <summary>
 10    /// Initializes a new instance of the <see cref="StyleAlign" /> record using the specified alignment kind.
 11    /// </summary>
 12    /// <param name="kind">The alignment kind to represent (e.g., <see cref="Kind.Center" />).</param>
 13    public StyleAlign(Kind kind)
 6014        : base(value: kind.GetDescription()) { }
 15
 16    /// <summary>Defines the supported CSS alignment values.</summary>
 17    public enum Kind
 18    {
 19        /// <summary>Aligns the baseline of the element with the baseline of its parent.</summary>
 20        [Description(description: "baseline")]
 21        Baseline,
 22
 23        /// <summary>Centers the element along the alignment axis.</summary>
 24        [Description(description: "center")]
 25        Center,
 26
 27        /// <summary>Aligns the element to the end of the alignment container.</summary>
 28        [Description(description: "end")]
 29        End,
 30
 31        /// <summary>Aligns the first baseline of the element with the first baseline of its parent.</summary>
 32        [Description(description: "first baseline")]
 33        FirstBaseline,
 34
 35        /// <summary>Aligns the element to the end of the flex container's cross axis.</summary>
 36        [Description(description: "flex-end")]
 37        FlexEnd,
 38
 39        /// <summary>Aligns the element to the start of the flex container's cross axis.</summary>
 40        [Description(description: "flex-start")]
 41        FlexStart,
 42
 43        /// <summary>Aligns the last baseline of the element with the last baseline of its parent.</summary>
 44        [Description(description: "last baseline")]
 45        LastBaseline,
 46
 47        /// <summary>Represents the default alignment behavior for the property.</summary>
 48        [Description(description: "normal")]
 49        Normal,
 50
 51        /// <summary>Centers the element safely without overflowing its container.</summary>
 52        [Description(description: "safe center")]
 53        SafeCenter,
 54
 55        /// <summary>Distributes elements evenly with space around each item.</summary>
 56        [Description(description: "space-around")]
 57        SpaceAround,
 58
 59        /// <summary>Distributes elements evenly with the first element at the start and last at the end.</summary>
 60        [Description(description: "space-between")]
 61        SpaceBetween,
 62
 63        /// <summary>Distributes elements evenly with equal spacing between and around them.</summary>
 64        [Description(description: "space-evenly")]
 65        SpaceEvenly,
 66
 67        /// <summary>Aligns the element to the start of the alignment container.</summary>
 68        [Description(description: "start")]
 69        Start,
 70
 71        /// <summary>Stretches the element to fill the container along the alignment axis.</summary>
 72        [Description(description: "stretch")]
 73        Stretch,
 74
 75        /// <summary>Centers the element even if it may cause overflow (unsafe).</summary>
 76        [Description(description: "unsafe center")]
 77        UnsafeCenter
 78    }
 79
 80    /// <summary>Parses the provided string value into a <see cref="StyleAlign" /> instance.</summary>
 81    /// <param name="value">The string representation of a CSS alignment value.</param>
 82    /// <returns>A new <see cref="StyleAlign" /> instance representing the parsed value.</returns>
 83    /// <exception cref="AryArgumentException">
 84    /// Thrown when the provided <paramref name="value" /> does not match any valid
 85    /// <see cref="Kind" />.
 86    /// </exception>
 87    public static StyleAlign Parse(string? value)
 1388        => value.TryParseEnum<Kind>(result: out var kind)
 1389            ? new StyleAlign(kind: kind)
 1390            : throw new AryArgumentException(message: $"Invalid style: {value}", argName: nameof(value));
 91
 92    /// <summary>Attempts to parse a string into a <see cref="StyleAlign" /> instance.</summary>
 93    /// <param name="value">The string value to parse.</param>
 94    /// <param name="result">
 95    /// When this method returns, contains the parsed <see cref="StyleAlign" /> instance or <see langword="null" /> if p
 96    /// failed.
 97    /// </param>
 98    /// <returns><see langword="true" /> if parsing was successful; otherwise, <see langword="false" />.</returns>
 99    public static bool TryParse(string? value, out StyleAlign? result)
 100    {
 101        try
 102        {
 3103            result = Parse(value: value);
 104
 1105            return true;
 106        }
 2107        catch
 108        {
 2109            result = null;
 110
 2111            return false;
 112        }
 3113    }
 114
 115    /// <summary>Implicitly converts a string to a <see cref="StyleAlign" /> instance.</summary>
 116    /// <param name="value">The string representation of the alignment value.</param>
 117    /// <returns>A <see cref="StyleAlign" /> instance representing the provided value.</returns>
 118    /// <exception cref="AryArgumentException">Thrown when the string cannot be parsed into a valid alignment kind.</exc
 2119    public static implicit operator StyleAlign(string? value) => Parse(value: value);
 120
 121    /// <summary>Implicitly converts a <see cref="StyleAlign" /> instance to its string value.</summary>
 122    /// <param name="value">The <see cref="StyleAlign" /> instance to convert.</param>
 123    /// <returns>
 124    /// The underlying CSS alignment string or an empty string if <paramref name="value" /> is <see langword="null" />.
 125    /// </returns>
 2126    public static implicit operator string(StyleAlign? value) => (value?.Value).OrDefaultIfEmpty();
 127}