forked from AngleSharp/AngleSharp.Css
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlexDeclaration.cs
More file actions
71 lines (58 loc) · 1.95 KB
/
FlexDeclaration.cs
File metadata and controls
71 lines (58 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#nullable disable
namespace AngleSharp.Css.Declarations
{
using AngleSharp.Css.Dom;
using AngleSharp.Css.Values;
using AngleSharp.Text;
using System;
using static ValueConverters;
static class FlexDeclaration
{
public static String Name = PropertyNames.Flex;
public static String[] Longhands = new[]
{
PropertyNames.FlexGrow,
PropertyNames.FlexShrink,
PropertyNames.FlexBasis,
};
public static IValueConverter Converter = new FlexAggregator();
public static ICssValue InitialValue = null;
public static PropertyFlags Flags = PropertyFlags.Shorthand;
sealed class FlexAggregator : IValueAggregator, IValueConverter
{
private static readonly IValueConverter converter = Or(None, WithAny(
FlexGrowDeclaration.Converter,
FlexShrinkDeclaration.Converter,
FlexBasisDeclaration.Converter));
public ICssValue Convert(StringSource source)
{
return converter.Convert(source);
}
public ICssValue Merge(ICssValue[] values)
{
var grow = values[0];
var shrink = values[1];
var basis = values[2];
if (grow != null || shrink != null || basis != null)
{
return new CssTupleValue(new[] { grow, shrink, basis });
}
return null;
}
public ICssValue[] Split(ICssValue value)
{
var options = value as CssTupleValue;
if (options != null)
{
return new[]
{
options.Items[0],
options.Items[1],
options.Items[2],
};
}
return null;
}
}
}
}