| | | 1 | | namespace Allyaria.Theming.StyleTypes; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents a CSS <c>text-wrap-style</c> value within the Allyaria theming system. Provides a strongly typed wrapper |
| | | 5 | | /// defining how lines of text should wrap within a block container. |
| | | 6 | | /// </summary> |
| | | 7 | | public sealed record StyleTextWrapStyle : StyleValueBase |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Initializes a new instance of the <see cref="StyleTextWrapStyle" /> record using the specified <see cref="Kind" |
| | | 11 | | /// value. |
| | | 12 | | /// </summary> |
| | | 13 | | /// <param name="kind">The text wrapping behavior to represent.</param> |
| | | 14 | | public StyleTextWrapStyle(Kind kind) |
| | 30 | 15 | | : base(value: kind.GetDescription()) { } |
| | | 16 | | |
| | | 17 | | /// <summary>Defines the supported CSS <c>text-wrap-style</c> property values.</summary> |
| | | 18 | | public enum Kind |
| | | 19 | | { |
| | | 20 | | /// <summary>Uses the browser’s default line-breaking and wrapping rules for the text.</summary> |
| | | 21 | | [Description(description: "auto")] |
| | | 22 | | Auto, |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Balances wrapped lines within a block, distributing text evenly across lines when possible. Useful for headi |
| | | 26 | | /// short multi-line text. |
| | | 27 | | /// </summary> |
| | | 28 | | [Description(description: "balance")] |
| | | 29 | | Balance, |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Adjusts wrapping to produce visually pleasing text edges, potentially varying line lengths slightly to impro |
| | | 33 | | /// aesthetics. |
| | | 34 | | /// </summary> |
| | | 35 | | [Description(description: "pretty")] |
| | | 36 | | Pretty, |
| | | 37 | | |
| | | 38 | | /// <summary> |
| | | 39 | | /// Maintains consistent line-breaking behavior for a stable layout even when content changes or is dynamically |
| | | 40 | | /// </summary> |
| | | 41 | | [Description(description: "stable")] |
| | | 42 | | Stable |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Parses a string representation of a CSS <c>text-wrap-style</c> value into a <see cref="StyleTextWrapStyle" /> in |
| | | 47 | | /// </summary> |
| | | 48 | | /// <param name="value">The string representation of the text-wrap-style value.</param> |
| | | 49 | | /// <returns>A new <see cref="StyleTextWrapStyle" /> instance representing the parsed value.</returns> |
| | | 50 | | /// <exception cref="AryArgumentException"> |
| | | 51 | | /// Thrown when the provided <paramref name="value" /> does not correspond to a valid <see cref="Kind" />. |
| | | 52 | | /// </exception> |
| | | 53 | | public static StyleTextWrapStyle Parse(string? value) |
| | 11 | 54 | | => value.TryParseEnum<Kind>(result: out var kind) |
| | 11 | 55 | | ? new StyleTextWrapStyle(kind: kind) |
| | 11 | 56 | | : throw new AryArgumentException(message: $"Invalid style: {value}", argName: nameof(value)); |
| | | 57 | | |
| | | 58 | | /// <summary>Attempts to parse a string into a <see cref="StyleTextWrapStyle" /> instance.</summary> |
| | | 59 | | /// <param name="value">The string representation of the text-wrap-style value to parse.</param> |
| | | 60 | | /// <param name="result"> |
| | | 61 | | /// When this method returns, contains the parsed <see cref="StyleTextWrapStyle" /> instance or <see langword="null" |
| | | 62 | | /// parsing failed. |
| | | 63 | | /// </param> |
| | | 64 | | /// <returns><see langword="true" /> if parsing succeeded; otherwise, <see langword="false" />.</returns> |
| | | 65 | | public static bool TryParse(string? value, out StyleTextWrapStyle? result) |
| | | 66 | | { |
| | | 67 | | try |
| | | 68 | | { |
| | 3 | 69 | | result = Parse(value: value); |
| | | 70 | | |
| | 1 | 71 | | return true; |
| | | 72 | | } |
| | 2 | 73 | | catch |
| | | 74 | | { |
| | 2 | 75 | | result = null; |
| | | 76 | | |
| | 2 | 77 | | return false; |
| | | 78 | | } |
| | 3 | 79 | | } |
| | | 80 | | |
| | | 81 | | /// <summary>Implicitly converts a string into a <see cref="StyleTextWrapStyle" /> instance.</summary> |
| | | 82 | | /// <param name="value">The string representation of the text-wrap-style value.</param> |
| | | 83 | | /// <returns>A <see cref="StyleTextWrapStyle" /> instance representing the provided value.</returns> |
| | | 84 | | /// <exception cref="AryArgumentException"> |
| | | 85 | | /// Thrown when the provided string cannot be parsed into a valid |
| | | 86 | | /// <see cref="Kind" />. |
| | | 87 | | /// </exception> |
| | 2 | 88 | | public static implicit operator StyleTextWrapStyle(string? value) => Parse(value: value); |
| | | 89 | | |
| | | 90 | | /// <summary>Implicitly converts a <see cref="StyleTextWrapStyle" /> instance to its string representation.</summary |
| | | 91 | | /// <param name="value">The <see cref="StyleTextWrapStyle" /> instance to convert.</param> |
| | | 92 | | /// <returns> |
| | | 93 | | /// The underlying CSS <c>text-wrap-style</c> string value, or an empty string if <paramref name="value" /> is |
| | | 94 | | /// <see langword="null" />. |
| | | 95 | | /// </returns> |
| | 2 | 96 | | public static implicit operator string(StyleTextWrapStyle? value) => (value?.Value).OrDefaultIfEmpty(); |
| | | 97 | | } |