AngleSharp by Florian Rappl

<PackageReference Include="AngleSharp" Version="0.8.3" />

.NET API 1,189,376 bytes

 CssBackgroundProperty

More information available at: https://developer.mozilla.org/en-US/docs/Web/CSS/background
using AngleSharp.Css; using AngleSharp.Extensions; using System; using System.Collections.Generic; using System.Linq; namespace AngleSharp.Dom.Css { internal sealed class CssBackgroundProperty : CssShorthandProperty { private static readonly IValueConverter<Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue>> NormalLayerConverter = Converters.WithAny(Converters.ImageSourceConverter.Val().Option(), Converters.WithOrder(Converters.PointConverter.Val().Option(), CssBackgroundSizeProperty.SingleConverter.StartsWithDelimiter().Val().Option()), CssBackgroundRepeatProperty.SingleConverter.Val().Option(), Converters.BackgroundAttachmentConverter.Val().Option(), Converters.BoxModelConverter.Val().Option(), Converters.BoxModelConverter.Val().Option()); private static readonly IValueConverter<Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue, ICssValue>> FinalLayerConverter = Converters.WithAny(Converters.ImageSourceConverter.Val().Option(), Converters.WithOrder(Converters.PointConverter.Val().Option(), CssBackgroundSizeProperty.SingleConverter.StartsWithDelimiter().Val().Option()), CssBackgroundRepeatProperty.SingleConverter.Val().Option(), Converters.BackgroundAttachmentConverter.Val().Option(), Converters.BoxModelConverter.Val().Option(), Converters.BoxModelConverter.Val().Option(), Converters.CurrentColorConverter.Val().Option()); private static readonly IValueConverter<Tuple<Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue>[], Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue, ICssValue>>> Converter = NormalLayerConverter.FromList().RequiresEnd(FinalLayerConverter); internal CssBackgroundProperty(CssStyleDeclaration rule) : base(PropertyNames.Background, rule, PropertyFlags.Animatable) { } protected override bool IsValid(ICssValue value) { return Converter.TryConvert(value, delegate(Tuple<Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue>[], Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue, ICssValue>> m) { Get<CssBackgroundImageProperty>().TrySetValue(Transform(m, (Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue> n) => n.Item1)); Get<CssBackgroundPositionProperty>().TrySetValue(Transform(m, (Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue> n) => n.Item2.Item1)); Get<CssBackgroundSizeProperty>().TrySetValue(Transform(m, (Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue> n) => n.Item2.Item2)); Get<CssBackgroundRepeatProperty>().TrySetValue(Transform(m, (Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue> n) => n.Item3)); Get<CssBackgroundAttachmentProperty>().TrySetValue(Transform(m, (Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue> n) => n.Item4)); Get<CssBackgroundOriginProperty>().TrySetValue(Transform(m, (Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue> n) => n.Item5)); Get<CssBackgroundClipProperty>().TrySetValue(Transform(m, (Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue> n) => n.Item6)); Get<CssBackgroundColorProperty>().TrySetValue(m.Item2.Item7); }); } private static ICssValue Transform(Tuple<Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue>[], Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue, ICssValue>> data, Func<Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue>, ICssValue> selector) { Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue> arg = new Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue>(data.Item2.Item1, data.Item2.Item2, data.Item2.Item3, data.Item2.Item4, data.Item2.Item5, data.Item2.Item6); if (data.Item1.Length == 0) return selector(arg); CssValueList cssValueList = new CssValueList(); Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue>[] item = data.Item1; foreach (Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue> arg2 in item) { cssValueList.Add(selector(arg2)); } cssValueList.Add(selector(arg)); return cssValueList; } internal override string SerializeValue(IEnumerable<CssProperty> properties) { CssBackgroundImageProperty cssBackgroundImageProperty = properties.OfType<CssBackgroundImageProperty>().FirstOrDefault(); CssBackgroundPositionProperty cssBackgroundPositionProperty = properties.OfType<CssBackgroundPositionProperty>().FirstOrDefault(); CssBackgroundSizeProperty cssBackgroundSizeProperty = properties.OfType<CssBackgroundSizeProperty>().FirstOrDefault(); CssBackgroundRepeatProperty cssBackgroundRepeatProperty = properties.OfType<CssBackgroundRepeatProperty>().FirstOrDefault(); CssBackgroundAttachmentProperty cssBackgroundAttachmentProperty = properties.OfType<CssBackgroundAttachmentProperty>().FirstOrDefault(); CssBackgroundOriginProperty cssBackgroundOriginProperty = properties.OfType<CssBackgroundOriginProperty>().FirstOrDefault(); CssBackgroundClipProperty cssBackgroundClipProperty = properties.OfType<CssBackgroundClipProperty>().FirstOrDefault(); CssBackgroundColorProperty cssBackgroundColorProperty = properties.OfType<CssBackgroundColorProperty>().FirstOrDefault(); if (cssBackgroundImageProperty == null || cssBackgroundPositionProperty == null || cssBackgroundSizeProperty == null || cssBackgroundRepeatProperty == null || cssBackgroundAttachmentProperty == null || cssBackgroundOriginProperty == null || cssBackgroundClipProperty == null || cssBackgroundColorProperty == null) return string.Empty; List<string> list = new List<string>(); if (cssBackgroundImageProperty.HasValue) list.Add(cssBackgroundImageProperty.SerializeValue()); if (cssBackgroundPositionProperty.HasValue || cssBackgroundSizeProperty.HasValue) { list.Add(cssBackgroundPositionProperty.SerializeValue()); if (cssBackgroundSizeProperty.HasValue) { list.Add("/"); list.Add(cssBackgroundSizeProperty.SerializeValue()); } } if (cssBackgroundRepeatProperty.HasValue) list.Add(cssBackgroundRepeatProperty.SerializeValue()); if (cssBackgroundAttachmentProperty.HasValue) list.Add(cssBackgroundAttachmentProperty.SerializeValue()); if (cssBackgroundClipProperty.HasValue) list.Add(cssBackgroundClipProperty.SerializeValue()); if (cssBackgroundOriginProperty.HasValue) list.Add(cssBackgroundOriginProperty.SerializeValue()); if (cssBackgroundColorProperty.HasValue) list.Add(cssBackgroundColorProperty.SerializeValue()); return string.Join(" ", list); } } }