Sources/Elements/New-AreaElement.cs

namespace Belin.Html.Elements;
 
using System.Globalization;
 
/// <summary>
/// Creates a new <c>area</c> element.
/// </summary>
[Cmdlet(VerbsCommon.New, "HtmlAreaElement"), Alias("area"), OutputType(typeof(string))]
public class NewAreaElementCommand(): NewElementCommand("area", isVoid: true) {
 
    /// <summary>
    /// A text to display on browsers that do not display images.
    /// </summary>
    [Parameter]
    public string? Alt { get; set; }
 
    /// <summary>
    /// The browsing context to show the results of navigation.
    /// </summary>
    [Parameter, ValidateCount(3, int.MaxValue)]
    public double[]? Coords { get; set; }
 
    /// <summary>
    /// The suggested filename when the browser treats the linked URL as a download.
    /// </summary>
    [Parameter]
    public string? Download { get; set; }
 
    /// <summary>
    /// The hyperlink target for the area.
    /// </summary>
    [Parameter(Mandatory = true)]
    public required Uri Href { get; set; }
 
    /// <summary>
    /// A list of URLs. When the link is followed, the browser will send <c>POST</c> requests with the body <c>PING</c> to the URLs.
    /// </summary>
    [Parameter]
    public Uri[] Ping { get; set; } = [];
 
    /// <summary>
    /// The relationship of the linked URL.
    /// </summary>
    [Parameter]
    public string[] Rel { get; set; } = [];
 
    /// <summary>
    /// The browsing context to show the results of navigation.
    /// </summary>
    [Parameter, ValidateSet("circle", "default", "poly", "rect")]
    public string? Shape { get; set; }
 
    /// <summary>
    /// The browsing context to show the results of navigation.
    /// </summary>
    [Parameter]
    public string? Target { get; set; }
 
    /// <summary>
    /// Populates the specified attribute collection with the element attributes.
    /// </summary>
    /// <param name="attributes">The attribute collection to populate.</param>
    protected override void RenderAttributes(IDictionary<string, object?> attributes) {
        base.RenderAttributes(attributes);
        attributes["href"] = Href;
 
        if (Shape is not null) {
            attributes["shape"] = Shape;
            if (Coords is not null && Shape != "default") attributes["coords"] = string.Join(',', Coords.Select(number => number.ToString(CultureInfo.InvariantCulture)));
        }
 
        if (Alt is not null) attributes["alt"] = Alt;
        if (!string.IsNullOrWhiteSpace(Download)) attributes["download"] = Download;
        if (Ping.Length > 0) attributes["ping"] = string.Join(' ', Ping).Trim();
        if (Rel.Length > 0) attributes["rel"] = string.Join(' ', Rel).Trim();
        if (!string.IsNullOrWhiteSpace(Target)) attributes["target"] = Target;
    }
}