| | | 1 | | namespace Allyaria.Theming.StyleTypes; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents a CSS <c>overflow-wrap</c> value within the Allyaria theming system. Provides a strongly typed wrapper fo |
| | | 5 | | /// controlling word-breaking behavior within elements when text exceeds its container. |
| | | 6 | | /// </summary> |
| | | 7 | | public sealed record StyleOverflowWrap : StyleValueBase |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Initializes a new instance of the <see cref="StyleOverflowWrap" /> record using the specified <see cref="Kind" / |
| | | 11 | | /// value. |
| | | 12 | | /// </summary> |
| | | 13 | | /// <param name="kind">The overflow-wrap behavior to represent.</param> |
| | | 14 | | public StyleOverflowWrap(Kind kind) |
| | 24 | 15 | | : base(value: kind.GetDescription()) { } |
| | | 16 | | |
| | | 17 | | /// <summary>Defines the supported CSS <c>overflow-wrap</c> property values.</summary> |
| | | 18 | | public enum Kind |
| | | 19 | | { |
| | | 20 | | /// <summary> |
| | | 21 | | /// Allows words to be broken at arbitrary points if necessary to prevent overflow. This mode provides maximum f |
| | | 22 | | /// to avoid overflow. |
| | | 23 | | /// </summary> |
| | | 24 | | [Description(description: "anywhere")] |
| | | 25 | | Anywhere, |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Breaks words only if necessary to prevent overflow, similar to <c>normal</c>, but allows breaking within wor |
| | | 29 | | /// they would otherwise overflow. |
| | | 30 | | /// </summary> |
| | | 31 | | [Description(description: "break-word")] |
| | | 32 | | BreakWord, |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Uses default line-breaking rules; words will only wrap at allowed break points (such as spaces or hyphens). |
| | | 36 | | /// </summary> |
| | | 37 | | [Description(description: "normal")] |
| | | 38 | | Normal |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// Parses a string representation of a CSS <c>overflow-wrap</c> value into a <see cref="StyleOverflowWrap" /> insta |
| | | 43 | | /// </summary> |
| | | 44 | | /// <param name="value">The string representation of the overflow-wrap value.</param> |
| | | 45 | | /// <returns>A new <see cref="StyleOverflowWrap" /> instance representing the parsed value.</returns> |
| | | 46 | | /// <exception cref="AryArgumentException"> |
| | | 47 | | /// Thrown when the provided <paramref name="value" /> does not correspond to a valid <see cref="Kind" />. |
| | | 48 | | /// </exception> |
| | | 49 | | public static StyleOverflowWrap Parse(string? value) |
| | 10 | 50 | | => value.TryParseEnum<Kind>(result: out var kind) |
| | 10 | 51 | | ? new StyleOverflowWrap(kind: kind) |
| | 10 | 52 | | : throw new AryArgumentException(message: $"Invalid style: {value}", argName: nameof(value)); |
| | | 53 | | |
| | | 54 | | /// <summary>Attempts to parse a string into a <see cref="StyleOverflowWrap" /> instance.</summary> |
| | | 55 | | /// <param name="value">The string representation of the overflow-wrap value to parse.</param> |
| | | 56 | | /// <param name="result"> |
| | | 57 | | /// When this method returns, contains the parsed <see cref="StyleOverflowWrap" /> instance or <see langword="null" |
| | | 58 | | /// parsing failed. |
| | | 59 | | /// </param> |
| | | 60 | | /// <returns><see langword="true" /> if parsing succeeded; otherwise, <see langword="false" />.</returns> |
| | | 61 | | public static bool TryParse(string? value, out StyleOverflowWrap? result) |
| | | 62 | | { |
| | | 63 | | try |
| | | 64 | | { |
| | 3 | 65 | | result = Parse(value: value); |
| | | 66 | | |
| | 1 | 67 | | return true; |
| | | 68 | | } |
| | 2 | 69 | | catch |
| | | 70 | | { |
| | 2 | 71 | | result = null; |
| | | 72 | | |
| | 2 | 73 | | return false; |
| | | 74 | | } |
| | 3 | 75 | | } |
| | | 76 | | |
| | | 77 | | /// <summary>Implicitly converts a string into a <see cref="StyleOverflowWrap" /> instance.</summary> |
| | | 78 | | /// <param name="value">The string representation of the overflow-wrap value.</param> |
| | | 79 | | /// <returns>A <see cref="StyleOverflowWrap" /> instance representing the provided value.</returns> |
| | | 80 | | /// <exception cref="AryArgumentException"> |
| | | 81 | | /// Thrown when the provided string cannot be parsed into a valid |
| | | 82 | | /// <see cref="Kind" />. |
| | | 83 | | /// </exception> |
| | 2 | 84 | | public static implicit operator StyleOverflowWrap(string? value) => Parse(value: value); |
| | | 85 | | |
| | | 86 | | /// <summary>Implicitly converts a <see cref="StyleOverflowWrap" /> instance to its string representation.</summary> |
| | | 87 | | /// <param name="value">The <see cref="StyleOverflowWrap" /> instance to convert.</param> |
| | | 88 | | /// <returns> |
| | | 89 | | /// The underlying CSS <c>overflow-wrap</c> string value, or an empty string if <paramref name="value" /> is |
| | | 90 | | /// <see langword="null" />. |
| | | 91 | | /// </returns> |
| | 2 | 92 | | public static implicit operator string(StyleOverflowWrap? value) => (value?.Value).OrDefaultIfEmpty(); |
| | | 93 | | } |