Converters
A set of already constructed CSS value converters.
using AngleSharp.Css.ValueConverters;
using AngleSharp.Css.Values;
using AngleSharp.Dom;
using AngleSharp.Dom.Css;
using AngleSharp.Extensions;
using System;
namespace AngleSharp.Css
{
internal static class Converters
{
public static readonly IValueConverter<Length> LineWidthConverter = new StructValueConverter<Length>(ValueExtensions.ToBorderWidth);
public static readonly IValueConverter<Length> LineHeightConverter = new StructValueConverter<Length>(ValueExtensions.ToLineHeight);
public static readonly IValueConverter<Length> BorderSliceConverter = new StructValueConverter<Length>(ValueExtensions.ToBorderSlice);
public static readonly IValueConverter<Length> ImageBorderWidthConverter = new StructValueConverter<Length>(ValueExtensions.ToImageBorderWidth);
public static readonly IValueConverter<Length> LengthConverter = new StructValueConverter<Length>(ValueExtensions.ToLength);
public static readonly IValueConverter<Resolution> ResolutionConverter = new StructValueConverter<Resolution>(ValueExtensions.ToResolution);
public static readonly IValueConverter<Frequency> FrequencyConverter = new StructValueConverter<Frequency>(ValueExtensions.ToFrequency);
public static readonly IValueConverter<Time> TimeConverter = new StructValueConverter<Time>(ValueExtensions.ToTime);
public static readonly IValueConverter<CssUrl> UrlConverter = new ClassValueConverter<CssUrl>(ValueExtensions.ToUri);
public static readonly IValueConverter<string> StringConverter = new ClassValueConverter<string>(ValueExtensions.ToCssString);
public static readonly IValueConverter<string> IdentifierConverter = new ClassValueConverter<string>(ValueExtensions.ToIdentifier);
public static readonly IValueConverter<string> AnimatableConverter = new ClassValueConverter<string>(ValueExtensions.ToAnimatableIdentifier);
public static readonly IValueConverter<int> IntegerConverter = new StructValueConverter<int>(ValueExtensions.ToInteger);
public static readonly IValueConverter<Angle> AngleConverter = new StructValueConverter<Angle>(ValueExtensions.ToAngle);
public static readonly IValueConverter<float> NumberConverter = new StructValueConverter<float>(ValueExtensions.ToSingle);
public static readonly IValueConverter<Percent> PercentConverter = new StructValueConverter<Percent>(ValueExtensions.ToPercent);
public static readonly IValueConverter<byte> ByteConverter = new StructValueConverter<byte>(ValueExtensions.ToByte);
public static readonly IValueConverter<Color> PureColorConverter = new StructValueConverter<Color>(ValueExtensions.ToColor);
public static readonly IValueConverter<Length> LengthOrPercentConverter = new StructValueConverter<Length>(ValueExtensions.ToDistance);
public static readonly IValueConverter<Angle> SideOrCornerConverter = WithAny(Assign(Keywords.Left, -1).Or(Keywords.Right, 1).Option(0), Assign(Keywords.Top, 1).Or(Keywords.Bottom, -1).Option(0)).To((Tuple<double, double> m) => new Angle((float)(Math.Atan2(m.Item1, m.Item2) * 180 / 3.141592653589793), Angle.Unit.Deg));
public static readonly IValueConverter<Point> PointConverter = Construct(delegate {
IValueConverter<Length> valueConverter26 = Assign(Keywords.Left, Length.Zero).Or(Keywords.Right, new Length(100, Length.Unit.Percent)).Or(Keywords.Center, new Length(50, Length.Unit.Percent));
IValueConverter<Length> valueConverter27 = Assign(Keywords.Top, Length.Zero).Or(Keywords.Bottom, new Length(100, Length.Unit.Percent)).Or(Keywords.Center, new Length(50, Length.Unit.Percent));
IValueConverter<Length> valueConverter28 = valueConverter26.Or(LengthOrPercentConverter).Required();
IValueConverter<Length> valueConverter29 = valueConverter27.Or(LengthOrPercentConverter).Required();
return LengthOrPercentConverter.To((Length m) => new Point(m, Length.Half)).Or(Toggle(Keywords.Left, Keywords.Right).To((bool m) => new Point(m ? Length.Zero : Length.Full, Length.Half))).Or(Toggle(Keywords.Top, Keywords.Bottom).To((bool m) => new Point(Length.Half, m ? Length.Zero : Length.Full)))
.Or(Keywords.Center, Point.Center)
.Or(WithArgs(valueConverter28, valueConverter29, (Tuple<Length, Length> m) => new Point(m.Item1, m.Item2)))
.Or(WithArgs(valueConverter29, valueConverter28, (Tuple<Length, Length> m) => new Point(m.Item2, m.Item1)))
.Or(WithArgs(valueConverter26, valueConverter27, LengthOrPercentConverter, (Tuple<Length, Length, Length> m) => new Point(m.Item1, m.Item2.Add(m.Item3))))
.Or(WithArgs(valueConverter26, LengthOrPercentConverter, valueConverter27, (Tuple<Length, Length, Length> m) => new Point(m.Item1.Add(m.Item2), m.Item3)))
.Or(WithArgs(valueConverter26, LengthOrPercentConverter, valueConverter27, LengthOrPercentConverter, (Tuple<Length, Length, Length, Length> m) => new Point(m.Item1.Add(m.Item2), m.Item3.Add(m.Item4))));
});
public static readonly IValueConverter<string> AttrConverter = new FunctionValueConverter<string>(FunctionNames.Attr, WithArg(StringConverter.Or(IdentifierConverter)));
public static readonly IValueConverter<StepsTimingFunction> StepsConverter = new FunctionValueConverter<StepsTimingFunction>(FunctionNames.Steps, WithArgs(IntegerConverter.Required(), Assign(Keywords.Start, true).Or(Keywords.End, false).Option(false), (Tuple<int, bool> m) => new StepsTimingFunction(m.Item1, m.Item2)));
public static readonly IValueConverter<CubicBezierTimingFunction> CubicBezierConverter = Construct(delegate {
IValueConverter<float> valueConverter24 = NumberConverter.Required();
string cubicBezier = FunctionNames.CubicBezier;
IValueConverter<float> valueConverter25 = valueConverter24;
return new FunctionValueConverter<CubicBezierTimingFunction>(cubicBezier, WithArgs(valueConverter25, valueConverter25, valueConverter25, valueConverter25, (Tuple<float, float, float, float> m) => new CubicBezierTimingFunction(m.Item1, m.Item2, m.Item3, m.Item4)));
});
public static readonly IValueConverter<Counter> CounterConverter = Construct(delegate {
IValueConverter<string> first5 = IdentifierConverter.Required();
IValueConverter<string> valueConverter23 = IdentifierConverter.Option(Keywords.Decimal);
IValueConverter<string> second2 = StringConverter.Required();
return new FunctionValueConverter<Counter>(FunctionNames.Counter, WithArgs(first5, valueConverter23, (Tuple<string, string> m) => new Counter(m.Item1, m.Item2, null))).Or(new FunctionValueConverter<Counter>(FunctionNames.Counters, WithArgs(first5, second2, valueConverter23, (Tuple<string, string, string> m) => new Counter(m.Item1, m.Item3, m.Item2))));
});
public static readonly IValueConverter<Shape> ShapeConverter = Construct(delegate {
IValueConverter<Length> valueConverter21 = LengthConverter.Required();
string rect = FunctionNames.Rect;
IValueConverter<Length> valueConverter22 = valueConverter21;
return new FunctionValueConverter<Shape>(rect, WithArgs(valueConverter22, valueConverter22, valueConverter22, valueConverter22, (Tuple<Length, Length, Length, Length> m) => new Shape(m.Item1, m.Item2, m.Item3, m.Item4)).Or(WithArg(LengthConverter.Many(4, 4).To((Length[] m) => new Shape(m[0], m[1], m[2], m[3])))));
}).OrDefault();
public static readonly IValueConverter<LinearGradient> LinearGradientConverter = Construct(delegate {
IValueConverter<Angle> secondary2 = SideOrCornerConverter.StartsWithKeyword(Keywords.To);
GradientConverter<Angle> converter2 = new GradientConverter<Angle>(AngleConverter.Or(secondary2), Angle.Half);
return new FunctionValueConverter<LinearGradient>(FunctionNames.LinearGradient, converter2.To((Tuple<Angle, GradientStop[]> m) => new LinearGradient(m.Item1.Value, m.Item2, false))).Or(new FunctionValueConverter<LinearGradient>(FunctionNames.RepeatingLinearGradient, converter2.To((Tuple<Angle, GradientStop[]> m) => new LinearGradient(m.Item1.Value, m.Item2, true))));
});
public static readonly IValueConverter<RadialGradient> RadialGradientConverter = Construct(delegate {
IValueConverter<Point> second = PointConverter.StartsWithKeyword(Keywords.At).Option(Point.Center);
var anon = new {
Width = Length.Zero,
Height = Length.Zero,
SizeMode = RadialGradient.SizeMode.FarthestCorner
};
var primary4 = WithOrder(WithAny(Assign(Keywords.Circle, true).Option(true), LengthConverter.To((Length m) => new {
Width = m,
Height = m,
SizeMode = RadialGradient.SizeMode.None
}).Option(anon)), second);
var primary5 = WithOrder(WithAny(Assign(Keywords.Ellipse, false).Option(false), LengthOrPercentConverter.Many(2, 2).To((Length[] m) => new {
Width = m[0],
Height = m[1],
SizeMode = RadialGradient.SizeMode.None
}).Option(anon)), second);
var secondary = WithOrder(WithAny(Toggle(Keywords.Circle, Keywords.Ellipse).Option(false), Map.RadialGradientSizeModes.ToConverter().To((RadialGradient.SizeMode m) => new {
Width = Length.Zero,
Height = Length.Zero,
SizeMode = m
})), second);
GradientConverter<Tuple<bool, Length, Length, RadialGradient.SizeMode, Point>> converter = new GradientConverter<Tuple<bool, Length, Length, RadialGradient.SizeMode, Point>>(primary4.Or(primary5.Or(secondary)).To(m => Tuple.Create(m.Item1.Item1, m.Item1.Item2.Width, m.Item1.Item2.Height, m.Item1.Item2.SizeMode, m.Item2)), Tuple.Create(false, anon.Width, anon.Height, anon.SizeMode, Point.Center));
return new FunctionValueConverter<RadialGradient>(FunctionNames.RadialGradient, converter.To((Tuple<Tuple<bool, Length, Length, RadialGradient.SizeMode, Point>, GradientStop[]> m) => new RadialGradient(m.Item1.Item1, m.Item1.Item5, m.Item1.Item2, m.Item1.Item3, m.Item1.Item4, m.Item2, false))).Or(new FunctionValueConverter<RadialGradient>(FunctionNames.RepeatingRadialGradient, converter.To((Tuple<Tuple<bool, Length, Length, RadialGradient.SizeMode, Point>, GradientStop[]> m) => new RadialGradient(m.Item1.Item1, m.Item1.Item5, m.Item1.Item2, m.Item1.Item3, m.Item1.Item4, m.Item2, true))));
});
public static readonly IValueConverter<Color> RgbColorConverter = Construct(delegate {
IValueConverter<byte> valueConverter19 = ByteConverter.Required();
string rgb = FunctionNames.Rgb;
IValueConverter<byte> valueConverter20 = valueConverter19;
return new FunctionValueConverter<Color>(rgb, WithArgs(valueConverter20, valueConverter20, valueConverter20, (Tuple<byte, byte, byte> m) => new Color(m.Item1, m.Item2, m.Item3)));
});
public static readonly IValueConverter<Color> RgbaColorConverter = Construct(delegate {
IValueConverter<byte> valueConverter17 = ByteConverter.Required();
IValueConverter<float> fourth = NumberConverter.Required();
string rgba = FunctionNames.Rgba;
IValueConverter<byte> valueConverter18 = valueConverter17;
return new FunctionValueConverter<Color>(rgba, WithArgs(valueConverter18, valueConverter18, valueConverter18, fourth, (Tuple<byte, byte, byte, float> m) => new Color(m.Item1, m.Item2, m.Item3, (double)m.Item4)));
});
public static readonly IValueConverter<Color> HslColorConverter = Construct(delegate {
IValueConverter<Percent> valueConverter14 = PercentConverter.Required();
IValueConverter<float> valueConverter15 = NumberConverter.Required();
string hsl = FunctionNames.Hsl;
IValueConverter<float> first4 = valueConverter15;
IValueConverter<Percent> valueConverter16 = valueConverter14;
return new FunctionValueConverter<Color>(hsl, WithArgs(first4, valueConverter16, valueConverter16, delegate(Tuple<float, Percent, Percent> m) {
float h2 = m.Item1 / 360;
Percent percent2 = m.Item2;
float normalizedValue2 = percent2.NormalizedValue;
percent2 = m.Item3;
return Color.FromHsl(h2, normalizedValue2, percent2.NormalizedValue);
}));
});
public static readonly IValueConverter<Color> HslaColorConverter = Construct(delegate {
IValueConverter<Percent> valueConverter11 = PercentConverter.Required();
IValueConverter<float> valueConverter12 = NumberConverter.Required();
string hsla = FunctionNames.Hsla;
IValueConverter<float> first3 = valueConverter12;
IValueConverter<Percent> valueConverter13 = valueConverter11;
return new FunctionValueConverter<Color>(hsla, WithArgs(first3, valueConverter13, valueConverter13, valueConverter12, delegate(Tuple<float, Percent, Percent, float> m) {
float h = m.Item1 / 360;
Percent percent = m.Item2;
float normalizedValue = percent.NormalizedValue;
percent = m.Item3;
return Color.FromHsla(h, normalizedValue, percent.NormalizedValue, m.Item4);
}));
});
public static readonly IValueConverter<PerspectiveTransform> PerspectiveConverter = Construct(() => new FunctionValueConverter<PerspectiveTransform>(FunctionNames.Perspective, WithArg(LengthConverter.To((Length m) => new PerspectiveTransform(m)))));
public static readonly IValueConverter<MatrixTransform> MatrixTransformConverter = Construct(() => new FunctionValueConverter<MatrixTransform>(FunctionNames.Matrix, WithArgs(NumberConverter, 6, (float[] m) => new MatrixTransform(new float[15] {
m[0],
m[1],
0,
0,
m[2],
m[3],
0,
0,
0,
1,
0,
m[4],
m[5],
0,
1
}))).Or(new FunctionValueConverter<MatrixTransform>(FunctionNames.Matrix3d, WithArgs(NumberConverter, 16, (float[] m) => new MatrixTransform(m)))));
public static readonly IValueConverter<TranslateTransform> TranslateTransformConverter = Construct(delegate {
IValueConverter<Length> valueConverter8 = LengthOrPercentConverter.Required();
IValueConverter<Length> valueConverter9 = LengthOrPercentConverter.Option(Length.Zero);
FunctionValueConverter<TranslateTransform> primary3 = new FunctionValueConverter<TranslateTransform>(FunctionNames.Translate, WithArgs(valueConverter8, valueConverter9, (Tuple<Length, Length> m) => new TranslateTransform(m.Item1, m.Item2, Length.Zero)));
string translate3d = FunctionNames.Translate3d;
IValueConverter<Length> first2 = valueConverter8;
IValueConverter<Length> valueConverter10 = valueConverter9;
return primary3.Or(new FunctionValueConverter<TranslateTransform>(translate3d, WithArgs(first2, valueConverter10, valueConverter10, (Tuple<Length, Length, Length> m) => new TranslateTransform(m.Item1, m.Item2, m.Item3)))).Or(new FunctionValueConverter<TranslateTransform>(FunctionNames.TranslateX, WithArg(LengthOrPercentConverter.To((Length m) => new TranslateTransform(m, Length.Zero, Length.Zero))))).Or(new FunctionValueConverter<TranslateTransform>(FunctionNames.TranslateY, WithArg(LengthOrPercentConverter.To((Length m) => new TranslateTransform(Length.Zero, m, Length.Zero)))))
.Or(new FunctionValueConverter<TranslateTransform>(FunctionNames.TranslateZ, WithArg(LengthOrPercentConverter.To((Length m) => new TranslateTransform(Length.Zero, Length.Zero, m)))));
});
public static readonly IValueConverter<ScaleTransform> ScaleTransformConverter = Construct(delegate {
IValueConverter<float> valueConverter5 = NumberConverter.Required();
IValueConverter<float> valueConverter6 = NumberConverter.Option(NaN);
FunctionValueConverter<ScaleTransform> primary2 = new FunctionValueConverter<ScaleTransform>(FunctionNames.Scale, WithArgs(valueConverter5, valueConverter6, (Tuple<float, float> m) => new ScaleTransform(m.Item1, float.IsNaN(m.Item2) ? m.Item1 : m.Item2, 1)));
string scale3d = FunctionNames.Scale3d;
IValueConverter<float> first = valueConverter5;
IValueConverter<float> valueConverter7 = valueConverter6;
return primary2.Or(new FunctionValueConverter<ScaleTransform>(scale3d, WithArgs(first, valueConverter7, valueConverter7, (Tuple<float, float, float> m) => new ScaleTransform(m.Item1, float.IsNaN(m.Item2) ? m.Item1 : m.Item2, float.IsNaN(m.Item3) ? m.Item1 : m.Item3)))).Or(new FunctionValueConverter<ScaleTransform>(FunctionNames.ScaleX, WithArg(NumberConverter.To((float m) => new ScaleTransform(m, 1, 1))))).Or(new FunctionValueConverter<ScaleTransform>(FunctionNames.ScaleY, WithArg(NumberConverter.To((float m) => new ScaleTransform(1, m, 1)))))
.Or(new FunctionValueConverter<ScaleTransform>(FunctionNames.ScaleZ, WithArg(NumberConverter.To((float m) => new ScaleTransform(1, 1, m)))));
});
public static readonly IValueConverter<RotateTransform> RotateTransformConverter = Construct(delegate {
IValueConverter<float> valueConverter3 = NumberConverter.Required();
FunctionValueConverter<RotateTransform> primary = new FunctionValueConverter<RotateTransform>(FunctionNames.Rotate, WithArg(AngleConverter.To((Angle m) => RotateTransform.RotateZ(m.Value))));
string rotate3d = FunctionNames.Rotate3d;
IValueConverter<float> valueConverter4 = valueConverter3;
return primary.Or(new FunctionValueConverter<RotateTransform>(rotate3d, WithArgs(valueConverter4, valueConverter4, valueConverter4, AngleConverter.Required(), (Tuple<float, float, float, Angle> m) => new RotateTransform(m.Item1, m.Item2, m.Item3, m.Item4.Value)))).Or(new FunctionValueConverter<RotateTransform>(FunctionNames.RotateX, WithArg(AngleConverter.To((Angle m) => RotateTransform.RotateX(m.Value))))).Or(new FunctionValueConverter<RotateTransform>(FunctionNames.RotateY, WithArg(AngleConverter.To((Angle m) => RotateTransform.RotateY(m.Value)))))
.Or(new FunctionValueConverter<RotateTransform>(FunctionNames.RotateZ, WithArg(AngleConverter.To((Angle m) => RotateTransform.RotateZ(m.Value)))));
});
public static readonly IValueConverter<SkewTransform> SkewTransformConverter = Construct(delegate {
IValueConverter<Angle> valueConverter = AngleConverter.Required();
string skew = FunctionNames.Skew;
IValueConverter<Angle> valueConverter2 = valueConverter;
return new FunctionValueConverter<SkewTransform>(skew, WithArgs(valueConverter2, valueConverter2, delegate(Tuple<Angle, Angle> m) {
Angle angle = m.Item1;
float value = angle.Value;
angle = m.Item2;
return new SkewTransform(value, angle.Value);
})).Or(new FunctionValueConverter<SkewTransform>(FunctionNames.SkewX, WithArg(AngleConverter.To((Angle m) => new SkewTransform(m.Value, 0))))).Or(new FunctionValueConverter<SkewTransform>(FunctionNames.SkewY, WithArg(AngleConverter.To((Angle m) => new SkewTransform(0, m.Value)))));
});
public static readonly IValueConverter<ITimingFunction> TransitionConverter = new DictionaryValueConverter<ITimingFunction>(Map.TimingFunctions).Or(StepsConverter.To((Func<StepsTimingFunction, ITimingFunction>)((StepsTimingFunction m) => m))).Or(CubicBezierConverter.To((Func<CubicBezierTimingFunction, ITimingFunction>)((CubicBezierTimingFunction m) => m)));
public static readonly IValueConverter<IImageSource> GradientConverter = LinearGradientConverter.To((Func<LinearGradient, IImageSource>)((LinearGradient m) => m)).Or(RadialGradientConverter.To((Func<RadialGradient, IImageSource>)((RadialGradient m) => m)));
public static readonly IValueConverter<ITransform> TransformConverter = MatrixTransformConverter.To((Func<MatrixTransform, ITransform>)((MatrixTransform m) => m)).Or(ScaleTransformConverter.To((Func<ScaleTransform, ITransform>)((ScaleTransform m) => m))).Or(RotateTransformConverter.To((Func<RotateTransform, ITransform>)((RotateTransform m) => m)))
.Or(TranslateTransformConverter.To((Func<TranslateTransform, ITransform>)((TranslateTransform m) => m)))
.Or(SkewTransformConverter.To((Func<SkewTransform, ITransform>)((SkewTransform m) => m)))
.Or(PerspectiveConverter.To((Func<PerspectiveTransform, ITransform>)((PerspectiveTransform m) => m)));
public static readonly IValueConverter<Color> ColorConverter = PureColorConverter.Or(RgbColorConverter.Or(RgbaColorConverter)).Or(HslColorConverter.Or(HslaColorConverter));
public static readonly IValueConverter<Color> CurrentColorConverter = ColorConverter.WithCurrentColor();
public static readonly IValueConverter<Color?> InvertedColorConverter = CurrentColorConverter.ToNullable().Or(Keywords.Invert, null);
public static readonly IValueConverter<Tuple<int, int>> RatioConverter = WithOrder(IntegerConverter.Required(), IntegerConverter.StartsWithDelimiter().Required());
public static readonly IValueConverter<Shadow> ShadowConverter = WithAny(Assign(Keywords.Inset, true).Option(false), LengthConverter.Many(2, 4).Required(), ColorConverter.WithCurrentColor().Option(Color.Black)).To((Tuple<bool, Length[], Color> m) => new Shadow(m.Item1, m.Item2[0], m.Item2[1], Get(m.Item2, 2, Length.Zero), Get(m.Item2, 3, Length.Zero), m.Item3));
public static readonly IValueConverter<Shadow[]> MultipleShadowConverter = ShadowConverter.FromList().Or(Keywords.None, new Shadow[0]);
public static readonly IValueConverter<IImageSource> ImageSourceConverter = UrlConverter.To((Func<CssUrl, IImageSource>)((CssUrl m) => m)).Or(GradientConverter);
public static readonly IValueConverter<IImageSource> OptionalImageSourceConverter = ImageSourceConverter.Or(Keywords.None, null);
public static readonly IValueConverter<IImageSource[]> MultipleImageSourceConverter = ImageSourceConverter.FromList().Or(Keywords.None, new IImageSource[0]);
public static readonly IValueConverter<Tuple<Length, Length?>> BorderRadiusConverter = WithOrder(LengthOrPercentConverter.Required(), LengthOrPercentConverter.ToNullable().Option(null));
public static readonly IValueConverter<int?> OptionalIntegerConverter = IntegerConverter.OrNullDefault();
public static readonly IValueConverter<int> PositiveIntegerConverter = IntegerConverter.Constraint((int m) => m >= 0);
public static readonly IValueConverter<float> PositiveOrInfiniteNumberConverter = NumberConverter.Constraint((float m) => m >= 0).Or(Keywords.Infinite, Infinity);
public static readonly IValueConverter<float?> OptionalNumberConverter = NumberConverter.ToNullable().Or(Keywords.None, null);
public static readonly IValueConverter<Length> LengthOrNormalConverter = LengthConverter.Or(Keywords.Normal, new Length(1, Length.Unit.Em));
public static readonly IValueConverter<Length?> OptionalLengthConverter = LengthConverter.ToNullable().Or(Keywords.Normal, null);
public static readonly IValueConverter<Length?> AutoLengthConverter = LengthConverter.OrNullDefault();
public static readonly IValueConverter<Length?> OptionalLengthOrPercentConverter = LengthOrPercentConverter.ToNullable().Or(Keywords.None, null);
public static readonly IValueConverter<Length?> AutoLengthOrPercentConverter = LengthOrPercentConverter.OrNullDefault();
public static readonly IValueConverter<Length> FontSizeConverter = LengthOrPercentConverter.Or(Map.FontSizes.ToConverter().To((FontSize m) => m.ToLength()));
public static readonly IValueConverter<LineStyle> LineStyleConverter = Map.LineStyles.ToConverter();
public static readonly IValueConverter<BackgroundAttachment> BackgroundAttachmentConverter = Map.BackgroundAttachments.ToConverter();
public static readonly IValueConverter<BoxModel> BoxModelConverter = Map.BoxModels.ToConverter();
public static readonly IValueConverter<AnimationDirection> AnimationDirectionConverter = Map.AnimationDirections.ToConverter();
public static readonly IValueConverter<AnimationFillStyle> AnimationFillStyleConverter = Map.AnimationFillStyles.ToConverter();
public static readonly IValueConverter<TextDecorationStyle> TextDecorationStyleConverter = Map.TextDecorationStyles.ToConverter();
public static readonly IValueConverter<ListPosition> ListPositionConverter = Map.ListPositions.ToConverter();
public static readonly IValueConverter<ListStyle> ListStyleConverter = Map.ListStyles.ToConverter();
public static readonly IValueConverter<BreakMode> BreakModeConverter = Map.BreakModes.ToConverter();
public static readonly IValueConverter<BreakMode> BreakInsideModeConverter = Map.BreakInsideModes.ToConverter();
public static readonly IValueConverter<BreakMode> PageBreakModeConverter = Map.PageBreakModes.ToConverter();
public static readonly IValueConverter<UnicodeMode> UnicodeModeConverter = Map.UnicodeModes.ToConverter();
public static readonly IValueConverter<Visibility> VisibilityConverter = Map.Visibilities.ToConverter();
public static readonly IValueConverter<PlayState> PlayStateConverter = Assign(Keywords.Running, PlayState.Running).Or(Keywords.Paused, PlayState.Paused);
public static readonly IValueConverter<FontVariant> FontVariantConverter = Assign(Keywords.Normal, FontVariant.Normal).Or(Keywords.SmallCaps, FontVariant.SmallCaps);
public static readonly IValueConverter<DirectionMode> DirectionModeConverter = Assign(Keywords.Ltr, DirectionMode.Ltr).Or(Keywords.Rtl, DirectionMode.Rtl);
public static readonly IValueConverter<HorizontalAlignment> HorizontalAlignmentConverter = Map.HorizontalAlignments.ToConverter();
public static readonly IValueConverter<VerticalAlignment> VerticalAlignmentConverter = Map.VerticalAlignments.ToConverter();
public static readonly IValueConverter<Whitespace> WhitespaceConverter = Map.WhitespaceModes.ToConverter();
public static readonly IValueConverter<TextTransform> TextTransformConverter = Map.TextTransforms.ToConverter();
public static readonly IValueConverter<ObjectFitting> ObjectFittingConverter = Map.ObjectFittings.ToConverter();
public static readonly IValueConverter<PositionMode> PositionModeConverter = Map.PositionModes.ToConverter();
public static readonly IValueConverter<OverflowMode> OverflowModeConverter = Map.OverflowModes.ToConverter();
public static readonly IValueConverter<Floating> FloatingConverter = Map.FloatingModes.ToConverter();
public static readonly IValueConverter<DisplayMode> DisplayModeConverter = Map.DisplayModes.ToConverter();
public static readonly IValueConverter<ClearMode> ClearModeConverter = Map.ClearModes.ToConverter();
public static readonly IValueConverter<FontStretch> FontStretchConverter = Map.FontStretches.ToConverter();
public static readonly IValueConverter<FontStyle> FontStyleConverter = Map.FontStyles.ToConverter();
public static readonly IValueConverter<bool> TableLayoutConverter = Toggle(Keywords.Fixed, Keywords.Auto);
public static readonly IValueConverter<bool> EmptyCellsConverter = Toggle(Keywords.Show, Keywords.Hide);
public static readonly IValueConverter<bool> CaptionSideConverter = Toggle(Keywords.Top, Keywords.Bottom);
public static readonly IValueConverter<bool> BackfaceVisibilityConverter = Toggle(Keywords.Visible, Keywords.Hidden);
public static readonly IValueConverter<bool> BorderCollapseConverter = Toggle(Keywords.Separate, Keywords.Collapse);
public static readonly IValueConverter<bool> BoxDecorationConverter = Toggle(Keywords.Clone, Keywords.Slice);
public static readonly IValueConverter<bool> ColumnSpanConverter = Toggle(Keywords.All, Keywords.None);
public static readonly IValueConverter<bool> ColumnFillConverter = Toggle(Keywords.Balance, Keywords.Auto);
public static IValueConverter<T> Assign<T>(string identifier, T result)
{
return new IdentifierValueConverter<T>(identifier, result);
}
public static IValueConverter<bool> Toggle(string on, string off)
{
return Assign(on, true).Or(off, false);
}
public static IValueConverter<T[]> WithOrder<T>(IValueConverter<T> converter)
{
return new OrderedOptionsConverter<T>(converter);
}
public static IValueConverter<Tuple<T1, T2>> WithOrder<T1, T2>(IValueConverter<T1> first, IValueConverter<T2> second)
{
return new OrderedOptionsConverter<T1, T2>(first, second);
}
public static IValueConverter<Tuple<T1, T2, T3>> WithOrder<T1, T2, T3>(IValueConverter<T1> first, IValueConverter<T2> second, IValueConverter<T3> third)
{
return new OrderedOptionsConverter<T1, T2, T3>(first, second, third);
}
public static IValueConverter<Tuple<T1, T2>> WithAny<T1, T2>(IValueConverter<T1> first, IValueConverter<T2> second)
{
return new UnorderedOptionsConverter<T1, T2>(first, second);
}
public static IValueConverter<Tuple<T1, T2, T3>> WithAny<T1, T2, T3>(IValueConverter<T1> first, IValueConverter<T2> second, IValueConverter<T3> third)
{
return new UnorderedOptionsConverter<T1, T2, T3>(first, second, third);
}
public static IValueConverter<Tuple<T1, T2, T3, T4>> WithAny<T1, T2, T3, T4>(IValueConverter<T1> first, IValueConverter<T2> second, IValueConverter<T3> third, IValueConverter<T4> fourth)
{
return new UnorderedOptionsConverter<T1, T2, T3, T4>(first, second, third, fourth);
}
public static IValueConverter<Tuple<T1, T2, T3, T4, T5>> WithAny<T1, T2, T3, T4, T5>(IValueConverter<T1> first, IValueConverter<T2> second, IValueConverter<T3> third, IValueConverter<T4> fourth, IValueConverter<T5> fifth)
{
return new UnorderedOptionsConverter<T1, T2, T3, T4, T5>(first, second, third, fourth, fifth);
}
public static IValueConverter<Tuple<T1, T2, T3, T4, T5, T6>> WithAny<T1, T2, T3, T4, T5, T6>(IValueConverter<T1> first, IValueConverter<T2> second, IValueConverter<T3> third, IValueConverter<T4> fourth, IValueConverter<T5> fifth, IValueConverter<T6> sixth)
{
return new UnorderedOptionsConverter<T1, T2, T3, T4, T5, T6>(first, second, third, fourth, fifth, sixth);
}
public static IValueConverter<Tuple<T1, T2, T3, T4, T5, T6, T7>> WithAny<T1, T2, T3, T4, T5, T6, T7>(IValueConverter<T1> first, IValueConverter<T2> second, IValueConverter<T3> third, IValueConverter<T4> fourth, IValueConverter<T5> fifth, IValueConverter<T6> sixth, IValueConverter<T7> seventh)
{
return new UnorderedOptionsConverter<T1, T2, T3, T4, T5, T6, T7>(first, second, third, fourth, fifth, sixth, seventh);
}
public static IValueConverter<Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8>>> WithAny<T1, T2, T3, T4, T5, T6, T7, T8>(IValueConverter<T1> first, IValueConverter<T2> second, IValueConverter<T3> third, IValueConverter<T4> fourth, IValueConverter<T5> fifth, IValueConverter<T6> sixth, IValueConverter<T7> seventh, IValueConverter<T8> eighth)
{
return new UnorderedOptionsConverter<T1, T2, T3, T4, T5, T6, T7, T8>(first, second, third, fourth, fifth, sixth, seventh, eighth);
}
private static T Get<T>(T[] array, int index, T defaultValue)
{
if (array.Length <= index)
return defaultValue;
return array[index];
}
private static IValueConverter<T> Construct<T>(Func<IValueConverter<T>> f)
{
return f();
}
private static IValueConverter<T> WithArg<T>(IValueConverter<T> converter)
{
return converter.Atomic();
}
private static IValueConverter<T> WithArgs<T1, T>(IValueConverter<T1> converter, int arguments, Func<T1[], T> transform)
{
return new ArgumentsValueConverter<T1>(converter, arguments).To(transform);
}
private static IValueConverter<T> WithArgs<T1, T2, T>(IValueConverter<T1> first, IValueConverter<T2> second, Func<Tuple<T1, T2>, T> converter)
{
return new ArgumentsValueConverter<T1, T2>(first, second).To(converter);
}
private static IValueConverter<T> WithArgs<T1, T2, T3, T>(IValueConverter<T1> first, IValueConverter<T2> second, IValueConverter<T3> third, Func<Tuple<T1, T2, T3>, T> converter)
{
return new ArgumentsValueConverter<T1, T2, T3>(first, second, third).To(converter);
}
private static IValueConverter<T> WithArgs<T1, T2, T3, T4, T>(IValueConverter<T1> first, IValueConverter<T2> second, IValueConverter<T3> third, IValueConverter<T4> fourth, Func<Tuple<T1, T2, T3, T4>, T> converter)
{
return new ArgumentsValueConverter<T1, T2, T3, T4>(first, second, third, fourth).To(converter);
}
}
}