AngleSharp by Florian Rappl

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

.NET API 1,172,480 bytes

 CssFontWeightProperty

Information: https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight
using AngleSharp.Css; using AngleSharp.Extensions; using System; using System.Collections.Generic; namespace AngleSharp.Dom.Css { internal sealed class CssFontWeightProperty : CssProperty, ICssFontWeightProperty, ICssProperty { internal struct FontWeight { public bool IsRelative; public int Value; } private static readonly Dictionary<string, FontWeight> FontWeights; internal static readonly FontWeight Default; internal static readonly IValueConverter<FontWeight> Converter; private FontWeight _weight; public int Weight => _weight.Value; public bool IsRelative => _weight.IsRelative; static CssFontWeightProperty() { Dictionary<string, FontWeight> dictionary = new Dictionary<string, FontWeight>(StringComparer.OrdinalIgnoreCase); string normal = Keywords.Normal; FontWeight value = new FontWeight { IsRelative = false, Value = 400 }; dictionary.Add(normal, value); string bold = Keywords.Bold; value = new FontWeight { IsRelative = false, Value = 700 }; dictionary.Add(bold, value); string bolder = Keywords.Bolder; value = new FontWeight { IsRelative = true, Value = 100 }; dictionary.Add(bolder, value); string lighter = Keywords.Lighter; value = new FontWeight { IsRelative = true, Value = -100 }; dictionary.Add(lighter, value); FontWeights = dictionary; Default = FontWeights[Keywords.Normal]; Converter = FontWeights.ToConverter().Or(Converters.IntegerConverter.Constraint(delegate(int m) { if (m >= 100) return m <= 900; return false; }).To(delegate(int m) { FontWeight result = default(FontWeight); result.IsRelative = false; result.Value = m; return result; })); } internal CssFontWeightProperty(CssStyleDeclaration rule) : base(PropertyNames.FontWeight, rule, PropertyFlags.Inherited | PropertyFlags.Animatable) { Reset(); } private void SetWeight(FontWeight weight) { _weight = weight; } internal override void Reset() { _weight = Default; } protected override bool IsValid(ICssValue value) { return Converter.TryConvert(value, SetWeight); } } }