-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #183 from cwall-dev/feature/containerqueries
Added support for @container queries and comparison operators
- Loading branch information
Showing
28 changed files
with
403 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
namespace ExCSS.Tests | ||
{ | ||
using ExCSS; | ||
using Xunit; | ||
using System.Linq; | ||
|
||
public class CssContainerTests : CssConstructionFunctions | ||
{ | ||
[Fact] | ||
public void SimpleContainer() | ||
{ | ||
const string source = "@container tall (min-width: 500px) and (min-height: 300px) {h2 { line-height: 1.6; } }"; | ||
var result = ParseStyleSheet(source); | ||
Assert.Equal(source, result.StylesheetText.Text); | ||
var rule = result.Rules[0] as ContainerRule; | ||
Assert.NotNull(rule); | ||
Assert.Equal("@container tall (min-width: 500px) and (min-height: 300px) { h2 { line-height: 1.6 } }", rule.Text); | ||
Assert.Equal("tall", rule.Name); | ||
Assert.Equal("(min-width: 500px) and (min-height: 300px)", rule.ConditionText); | ||
var childRule = rule.Children.OfType<StyleRule>().First(); | ||
Assert.Equal("h2 { line-height: 1.6 }", childRule.ToCss()); | ||
} | ||
|
||
[Fact] | ||
public void ContainerWithoutName() | ||
{ | ||
const string source = "@container (min-width: 500px) and (min-height: 300px) {h2 { line-height: 1.6; } }"; | ||
var result = ParseStyleSheet(source); | ||
Assert.Equal(source, result.StylesheetText.Text); | ||
var rule = result.Rules[0] as ContainerRule; | ||
Assert.NotNull(rule); | ||
Assert.Equal("@container (min-width: 500px) and (min-height: 300px) { h2 { line-height: 1.6 } }", rule.Text); | ||
Assert.Equal(string.Empty, rule.Name); | ||
Assert.Equal("(min-width: 500px) and (min-height: 300px)", rule.ConditionText); | ||
var childRule = rule.Children.OfType<StyleRule>().First(); | ||
Assert.Equal("h2 { line-height: 1.6 }", childRule.ToCss()); | ||
} | ||
|
||
[Fact] | ||
public void ContainerWithoutCondition() | ||
{ | ||
const string source = "@container tall {h2 { line-height: 1.6; } }"; | ||
var result = ParseStyleSheet(source); | ||
Assert.Equal(source, result.StylesheetText.Text); | ||
var rule = result.Rules[0] as ContainerRule; | ||
Assert.NotNull(rule); | ||
Assert.Equal("@container tall { h2 { line-height: 1.6 } }", rule.Text); | ||
Assert.Equal("tall", rule.Name); | ||
Assert.Equal(string.Empty, rule.ConditionText); | ||
var childRule = rule.Children.OfType<StyleRule>().First(); | ||
Assert.Equal("h2 { line-height: 1.6 }", childRule.ToCss()); | ||
} | ||
|
||
[Fact] | ||
public void ContainerWithComparisonOperators() | ||
{ | ||
const string source = "@container tall (width < 500px) and (height >= 300px) {h2 { line-height: 1.6; } }"; | ||
var result = ParseStyleSheet(source); | ||
Assert.Equal(source, result.StylesheetText.Text); | ||
var rule = result.Rules[0] as ContainerRule; | ||
Assert.NotNull(rule); | ||
Assert.Equal("@container tall (width < 500px) and (height >= 300px) { h2 { line-height: 1.6 } }", rule.Text); | ||
Assert.Equal("tall", rule.Name); | ||
Assert.Equal("(width < 500px) and (height >= 300px)", rule.ConditionText); | ||
var childRule = rule.Children.OfType<StyleRule>().First(); | ||
Assert.Equal("h2 { line-height: 1.6 }", childRule.ToCss()); | ||
} | ||
|
||
[Fact] | ||
public void CSSWithTwoContainers() | ||
{ | ||
const string source = @"li { | ||
container-type: inline-size; | ||
} | ||
@container (min-width: 45ch) { | ||
li span { | ||
color: rgb(255, 0, 0); | ||
font-size: 2rem !important; | ||
} | ||
} | ||
@container (min-width: 70ch) { | ||
li span { | ||
color: rgb(0, 0, 255); | ||
font-size: 3rem !important; | ||
} | ||
}"; | ||
var result = ParseStyleSheet(source); | ||
Assert.Equal(source, result.StylesheetText.Text); | ||
Assert.Equal(3, result.Rules.Length); | ||
var rule1 = result.Rules[0] as StyleRule; | ||
var rule2 = result.Rules[1] as ContainerRule; | ||
var rule3 = result.Rules[2] as ContainerRule; | ||
Assert.NotNull(rule1); | ||
Assert.NotNull(rule2); | ||
Assert.NotNull(rule3); | ||
Assert.Equal("li { container-type: inline-size }", rule1.ToCss()); | ||
Assert.Equal("@container (min-width: 45ch) { li span { color: rgb(255, 0, 0); font-size: 2rem !important } }", rule2.ToCss()); | ||
Assert.Equal("@container (min-width: 70ch) { li span { color: rgb(0, 0, 255); font-size: 3rem !important } }", rule3.ToCss()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace ExCSS | ||
{ | ||
public enum ContainerType : byte | ||
{ | ||
Normal, | ||
Size, | ||
InlineSize | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ public enum RuleType : byte | |
Document, | ||
FontFeatureValues, | ||
Viewport, | ||
RegionStyle | ||
RegionStyle, | ||
Container | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace ExCSS | ||
{ | ||
internal sealed class SizeMediaFeature : MediaFeature | ||
{ | ||
public SizeMediaFeature(string name) : base(name) | ||
{ | ||
} | ||
|
||
internal override IValueConverter Converter => Converters.LengthConverter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.