AngleSharp by Florian Rappl

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

.NET API 1,171,968 bytes

 CssBackgroundProperty

More information available at: https://developer.mozilla.org/en-US/docs/Web/CSS/background
using AngleSharp.Css; using AngleSharp.Css.Values; using AngleSharp.Extensions; using System; using System.Collections.Generic; namespace AngleSharp.Dom.Css { internal sealed class CssBackgroundProperty : CssShorthandProperty, ICssBackgroundProperty, ICssProperty, ICssBackgroundAttachmentProperty, ICssBackgroundClipProperty, ICssBackgroundColorProperty, ICssBackgroundImageProperty, ICssBackgroundOriginProperty, ICssBackgroundPositionProperty, ICssBackgroundRepeatProperty, ICssBackgroundSizeProperty { private static readonly IValueConverter<Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue>> NormalLayerConverter = Converters.WithAny(CssBackgroundImageProperty.Converter.Val().Option(), Converters.WithOrder(CssBackgroundPositionProperty.Converter.Val().Option(), CssBackgroundSizeProperty.Converter.StartsWithDelimiter().Val().Option()), CssBackgroundRepeatProperty.Converter.Val().Option(), CssBackgroundAttachmentProperty.Converter.Val().Option(), CssBackgroundOriginProperty.Converter.Val().Option(), CssBackgroundClipProperty.Converter.Val().Option()); private static readonly IValueConverter<Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue, ICssValue>> FinalLayerConverter = Converters.WithAny(CssBackgroundImageProperty.Converter.Val().Option(), Converters.WithOrder(CssBackgroundPositionProperty.Converter.Val().Option(), CssBackgroundSizeProperty.Converter.StartsWithDelimiter().Val().Option()), CssBackgroundRepeatProperty.Converter.Val().Option(), CssBackgroundAttachmentProperty.Converter.Val().Option(), CssBackgroundOriginProperty.Converter.Val().Option(), CssBackgroundClipProperty.Converter.Val().Option(), CssBackgroundColorProperty.Converter.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); private readonly CssBackgroundImageProperty _image; private readonly CssBackgroundPositionProperty _position; private readonly CssBackgroundSizeProperty _size; private readonly CssBackgroundRepeatProperty _repeat; private readonly CssBackgroundAttachmentProperty _attachment; private readonly CssBackgroundOriginProperty _origin; private readonly CssBackgroundClipProperty _clip; private readonly CssBackgroundColorProperty _color; public IEnumerable<IImageSource> Images => _image.Images; public IEnumerable<Point> Positions => _position.Positions; public IEnumerable<BackgroundRepeat> HorizontalRepeats => _repeat.HorizontalRepeats; public IEnumerable<BackgroundRepeat> VerticalRepeats => _repeat.VerticalRepeats; public IEnumerable<BackgroundAttachment> Attachments => _attachment.Attachments; public IEnumerable<BoxModel> Origins => _origin.Origins; public IEnumerable<BoxModel> Clips => _clip.Clips; public Color Color => _color.Color; public IEnumerable<bool> IsCovered => _size.IsCovered; public IEnumerable<bool> IsContained => _size.IsContained; public IEnumerable<Point> Sizes => _size.Sizes; internal CssBackgroundProperty(CssStyleDeclaration rule) : base(PropertyNames.Background, rule, PropertyFlags.Animatable) { _image = Get<CssBackgroundImageProperty>(); _position = Get<CssBackgroundPositionProperty>(); _size = Get<CssBackgroundSizeProperty>(); _repeat = Get<CssBackgroundRepeatProperty>(); _attachment = Get<CssBackgroundAttachmentProperty>(); _origin = Get<CssBackgroundOriginProperty>(); _clip = Get<CssBackgroundClipProperty>(); _color = Get<CssBackgroundColorProperty>(); } 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) { _image.TrySetValue(Transform(m, (Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue> n) => n.Item1)); _position.TrySetValue(Transform(m, (Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue> n) => n.Item2.Item1)); _size.TrySetValue(Transform(m, (Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue> n) => n.Item2.Item2)); _repeat.TrySetValue(Transform(m, (Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue> n) => n.Item3)); _attachment.TrySetValue(Transform(m, (Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue> n) => n.Item4)); _origin.TrySetValue(Transform(m, (Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue> n) => n.Item5)); _clip.TrySetValue(Transform(m, (Tuple<ICssValue, Tuple<ICssValue, ICssValue>, ICssValue, ICssValue, ICssValue, ICssValue> n) => n.Item6)); _color.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) { if (!IsComplete(properties)) return string.Empty; List<string> list = new List<string>(); list.Add(_image.SerializeValue()); list.Add(_position.SerializeValue()); if (_size.HasValue) { list.Add("/"); list.Add(_size.SerializeValue()); } list.Add(_repeat.SerializeValue()); list.Add(_attachment.SerializeValue()); list.Add(_clip.SerializeValue()); list.Add(_origin.SerializeValue()); list.Add(_color.SerializeValue()); list.RemoveAll((string m) => string.IsNullOrEmpty(m)); return string.Join(" ", list); } } }