| | | 1 | | namespace Allyaria.Theming.StyleTypes; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents a CSS <c>line-break</c> value within the Allyaria theming system. Provides a strongly typed wrapper for |
| | | 5 | | /// controlling line-breaking behavior for text content. |
| | | 6 | | /// </summary> |
| | | 7 | | public sealed record StyleLineBreak : StyleValueBase |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Initializes a new instance of the <see cref="StyleLineBreak" /> record using the specified <see cref="Kind" /> v |
| | | 11 | | /// </summary> |
| | | 12 | | /// <param name="kind">The line-breaking behavior kind to represent.</param> |
| | | 13 | | public StyleLineBreak(Kind kind) |
| | 36 | 14 | | : base(value: kind.GetDescription()) { } |
| | | 15 | | |
| | | 16 | | /// <summary>Defines the supported CSS <c>line-break</c> property values.</summary> |
| | | 17 | | public enum Kind |
| | | 18 | | { |
| | | 19 | | /// <summary> |
| | | 20 | | /// Allows unrestrained line breaks between any two characters for maximum flexibility. Useful for text with lon |
| | | 21 | | /// URLs. |
| | | 22 | | /// </summary> |
| | | 23 | | [Description(description: "anywhere")] |
| | | 24 | | Anywhere, |
| | | 25 | | |
| | | 26 | | /// <summary>Uses the default line-breaking rules based on the document’s language and script.</summary> |
| | | 27 | | [Description(description: "auto")] |
| | | 28 | | Auto, |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Provides looser line-breaking rules that may allow additional break opportunities, often used for East Asian |
| | | 32 | | /// improve readability. |
| | | 33 | | /// </summary> |
| | | 34 | | [Description(description: "loose")] |
| | | 35 | | Loose, |
| | | 36 | | |
| | | 37 | | /// <summary>Applies standard line-breaking rules following the language’s usual behavior.</summary> |
| | | 38 | | [Description(description: "normal")] |
| | | 39 | | Normal, |
| | | 40 | | |
| | | 41 | | /// <summary>Uses the most restrictive line-breaking rules, allowing breaks only where absolutely necessary.</su |
| | | 42 | | [Description(description: "strict")] |
| | | 43 | | Strict |
| | | 44 | | } |
| | | 45 | | |
| | | 46 | | /// <summary> |
| | | 47 | | /// Parses a string representation of a CSS <c>line-break</c> value into a <see cref="StyleLineBreak" /> instance. |
| | | 48 | | /// </summary> |
| | | 49 | | /// <param name="value">The string representation of the line-break value.</param> |
| | | 50 | | /// <returns>A new <see cref="StyleLineBreak" /> instance representing the parsed value.</returns> |
| | | 51 | | /// <exception cref="AryArgumentException"> |
| | | 52 | | /// Thrown when the provided <paramref name="value" /> does not correspond to a valid <see cref="Kind" />. |
| | | 53 | | /// </exception> |
| | | 54 | | public static StyleLineBreak Parse(string? value) |
| | 12 | 55 | | => value.TryParseEnum<Kind>(result: out var kind) |
| | 12 | 56 | | ? new StyleLineBreak(kind: kind) |
| | 12 | 57 | | : throw new AryArgumentException(message: $"Invalid style: {value}", argName: nameof(value)); |
| | | 58 | | |
| | | 59 | | /// <summary>Attempts to parse a string into a <see cref="StyleLineBreak" /> instance.</summary> |
| | | 60 | | /// <param name="value">The string representation of the line-break value to parse.</param> |
| | | 61 | | /// <param name="result"> |
| | | 62 | | /// When this method returns, contains the parsed <see cref="StyleLineBreak" /> instance or <see langword="null" /> |
| | | 63 | | /// parsing failed. |
| | | 64 | | /// </param> |
| | | 65 | | /// <returns><see langword="true" /> if parsing succeeded; otherwise, <see langword="false" />.</returns> |
| | | 66 | | public static bool TryParse(string? value, out StyleLineBreak? result) |
| | | 67 | | { |
| | | 68 | | try |
| | | 69 | | { |
| | 3 | 70 | | result = Parse(value: value); |
| | | 71 | | |
| | 1 | 72 | | return true; |
| | | 73 | | } |
| | 2 | 74 | | catch |
| | | 75 | | { |
| | 2 | 76 | | result = null; |
| | | 77 | | |
| | 2 | 78 | | return false; |
| | | 79 | | } |
| | 3 | 80 | | } |
| | | 81 | | |
| | | 82 | | /// <summary>Implicitly converts a string into a <see cref="StyleLineBreak" /> instance.</summary> |
| | | 83 | | /// <param name="value">The string representation of the line-break value.</param> |
| | | 84 | | /// <returns>A <see cref="StyleLineBreak" /> instance representing the provided value.</returns> |
| | | 85 | | /// <exception cref="AryArgumentException"> |
| | | 86 | | /// Thrown when the provided string cannot be parsed into a valid |
| | | 87 | | /// <see cref="Kind" />. |
| | | 88 | | /// </exception> |
| | 2 | 89 | | public static implicit operator StyleLineBreak(string? value) => Parse(value: value); |
| | | 90 | | |
| | | 91 | | /// <summary>Implicitly converts a <see cref="StyleLineBreak" /> instance to its string representation.</summary> |
| | | 92 | | /// <param name="value">The <see cref="StyleLineBreak" /> instance to convert.</param> |
| | | 93 | | /// <returns> |
| | | 94 | | /// The underlying CSS <c>line-break</c> string value, or an empty string if <paramref name="value" /> is |
| | | 95 | | /// <see langword="null" />. |
| | | 96 | | /// </returns> |
| | 2 | 97 | | public static implicit operator string(StyleLineBreak? value) => (value?.Value).OrDefaultIfEmpty(); |
| | | 98 | | } |