| | | 1 | | namespace Allyaria.Theming.StyleTypes; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents a CSS <c>text-decoration-line</c> value within the Allyaria theming system. Provides a strongly typed |
| | | 5 | | /// wrapper for defining the decoration lines applied to text (e.g., underline, overline, line-through). |
| | | 6 | | /// </summary> |
| | | 7 | | public sealed record StyleTextDecorationLine : StyleValueBase |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Initializes a new instance of the <see cref="StyleTextDecorationLine" /> record using the specified <see cref="K |
| | | 11 | | /// value. |
| | | 12 | | /// </summary> |
| | | 13 | | /// <param name="kind">The text decoration line combination to represent.</param> |
| | | 14 | | public StyleTextDecorationLine(Kind kind) |
| | 88 | 15 | | : base(value: kind.GetDescription()) { } |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// Defines the supported CSS <c>text-decoration-line</c> property values. Multiple decorations can be represented b |
| | | 19 | | /// combining values. |
| | | 20 | | /// </summary> |
| | | 21 | | public enum Kind |
| | | 22 | | { |
| | | 23 | | /// <summary>Applies all standard text decorations: overline, line-through, and underline.</summary> |
| | | 24 | | [Description(description: "overline line-through underline")] |
| | | 25 | | All, |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Draws a line through the middle of the text (commonly used to indicate deleted or discounted content). |
| | | 29 | | /// </summary> |
| | | 30 | | [Description(description: "line-through")] |
| | | 31 | | LineThrough, |
| | | 32 | | |
| | | 33 | | /// <summary>Removes any text decorations from the element.</summary> |
| | | 34 | | [Description(description: "none")] |
| | | 35 | | None, |
| | | 36 | | |
| | | 37 | | /// <summary>Draws a line above the text (overline).</summary> |
| | | 38 | | [Description(description: "overline")] |
| | | 39 | | Overline, |
| | | 40 | | |
| | | 41 | | /// <summary>Draws both an overline and a line-through on the text.</summary> |
| | | 42 | | [Description(description: "overline line-through")] |
| | | 43 | | OverlineLineThrough, |
| | | 44 | | |
| | | 45 | | /// <summary>Draws both an overline and an underline on the text.</summary> |
| | | 46 | | [Description(description: "overline underline")] |
| | | 47 | | OverlineUnderline, |
| | | 48 | | |
| | | 49 | | /// <summary>Draws a line beneath the text (underline).</summary> |
| | | 50 | | [Description(description: "underline")] |
| | | 51 | | Underline, |
| | | 52 | | |
| | | 53 | | /// <summary>Draws both an underline and a line-through on the text.</summary> |
| | | 54 | | [Description(description: "underline line-through")] |
| | | 55 | | UnderlineLineThrough |
| | | 56 | | } |
| | | 57 | | |
| | | 58 | | /// <summary> |
| | | 59 | | /// Parses a string representation of a CSS <c>text-decoration-line</c> value into a <see cref="StyleTextDecorationL |
| | | 60 | | /// instance. |
| | | 61 | | /// </summary> |
| | | 62 | | /// <param name="value">The string representation of the text-decoration-line value.</param> |
| | | 63 | | /// <returns>A new <see cref="StyleTextDecorationLine" /> instance representing the parsed value.</returns> |
| | | 64 | | /// <exception cref="AryArgumentException"> |
| | | 65 | | /// Thrown when the provided <paramref name="value" /> does not correspond to a valid <see cref="Kind" />. |
| | | 66 | | /// </exception> |
| | | 67 | | public static StyleTextDecorationLine Parse(string? value) |
| | 15 | 68 | | => value.TryParseEnum<Kind>(result: out var kind) |
| | 15 | 69 | | ? new StyleTextDecorationLine(kind: kind) |
| | 15 | 70 | | : throw new AryArgumentException(message: $"Invalid style: {value}", argName: nameof(value)); |
| | | 71 | | |
| | | 72 | | /// <summary>Attempts to parse a string into a <see cref="StyleTextDecorationLine" /> instance.</summary> |
| | | 73 | | /// <param name="value">The string representation of the text-decoration-line value to parse.</param> |
| | | 74 | | /// <param name="result"> |
| | | 75 | | /// When this method returns, contains the parsed <see cref="StyleTextDecorationLine" /> instance or |
| | | 76 | | /// <see langword="null" /> if parsing failed. |
| | | 77 | | /// </param> |
| | | 78 | | /// <returns><see langword="true" /> if parsing succeeded; otherwise, <see langword="false" />.</returns> |
| | | 79 | | public static bool TryParse(string? value, out StyleTextDecorationLine? result) |
| | | 80 | | { |
| | | 81 | | try |
| | | 82 | | { |
| | 3 | 83 | | result = Parse(value: value); |
| | | 84 | | |
| | 1 | 85 | | return true; |
| | | 86 | | } |
| | 2 | 87 | | catch |
| | | 88 | | { |
| | 2 | 89 | | result = null; |
| | | 90 | | |
| | 2 | 91 | | return false; |
| | | 92 | | } |
| | 3 | 93 | | } |
| | | 94 | | |
| | | 95 | | /// <summary>Implicitly converts a string into a <see cref="StyleTextDecorationLine" /> instance.</summary> |
| | | 96 | | /// <param name="value">The string representation of the text-decoration-line value.</param> |
| | | 97 | | /// <returns>A <see cref="StyleTextDecorationLine" /> instance representing the provided value.</returns> |
| | | 98 | | /// <exception cref="AryArgumentException"> |
| | | 99 | | /// Thrown when the provided string cannot be parsed into a valid |
| | | 100 | | /// <see cref="Kind" />. |
| | | 101 | | /// </exception> |
| | 2 | 102 | | public static implicit operator StyleTextDecorationLine(string? value) => Parse(value: value); |
| | | 103 | | |
| | | 104 | | /// <summary>Implicitly converts a <see cref="StyleTextDecorationLine" /> instance to its string representation.</su |
| | | 105 | | /// <param name="value">The <see cref="StyleTextDecorationLine" /> instance to convert.</param> |
| | | 106 | | /// <returns> |
| | | 107 | | /// The underlying CSS <c>text-decoration-line</c> string value, or an empty string if <paramref name="value" /> is |
| | | 108 | | /// <see langword="null" />. |
| | | 109 | | /// </returns> |
| | 2 | 110 | | public static implicit operator string(StyleTextDecorationLine? value) => (value?.Value).OrDefaultIfEmpty(); |
| | | 111 | | } |