Skip to content

Commit 44ff400

Browse files
committed
text-emphasis-position
1 parent a98319b commit 44ff400

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

src/lib.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4409,5 +4409,43 @@ mod tests {
44094409
firefox: Some(45 << 16),
44104410
..Browsers::default()
44114411
});
4412+
4413+
minify_test(".foo { text-emphasis-position: over }", ".foo{text-emphasis-position:over}");
4414+
minify_test(".foo { text-emphasis-position: under }", ".foo{text-emphasis-position:under}");
4415+
minify_test(".foo { text-emphasis-position: over right }", ".foo{text-emphasis-position:over}");
4416+
minify_test(".foo { text-emphasis-position: over left }", ".foo{text-emphasis-position:over left}");
4417+
4418+
prefix_test(r#"
4419+
.foo {
4420+
text-emphasis-position: over;
4421+
}
4422+
"#, indoc! {r#"
4423+
.foo {
4424+
-webkit-text-emphasis-position: over;
4425+
text-emphasis-position: over;
4426+
}
4427+
"#},
4428+
Browsers {
4429+
safari: Some(10 << 16),
4430+
chrome: Some(30 << 16),
4431+
firefox: Some(45 << 16),
4432+
..Browsers::default()
4433+
});
4434+
4435+
prefix_test(r#"
4436+
.foo {
4437+
text-emphasis-position: over left;
4438+
}
4439+
"#, indoc! {r#"
4440+
.foo {
4441+
text-emphasis-position: over left;
4442+
}
4443+
"#},
4444+
Browsers {
4445+
safari: Some(10 << 16),
4446+
chrome: Some(30 << 16),
4447+
firefox: Some(45 << 16),
4448+
..Browsers::default()
4449+
});
44124450
}
44134451
}

src/properties/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ define_properties! {
464464
"text-emphasis-style": TextEmphasisStyle(TextEmphasisStyle, VendorPrefix) / "webkit",
465465
"text-emphasis-color": TextEmphasisColor(CssColor, VendorPrefix) / "webkit",
466466
"text-emphasis": TextEmphasis(TextEmphasis, VendorPrefix) / "webkit",
467+
"text-emphasis-position": TextEmphasisPosition(TextEmphasisPosition, VendorPrefix) / "webkit",
467468
}
468469

469470
impl<T: smallvec::Array<Item = V>, V: Parse> Parse for SmallVec<T> {

src/properties/text.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ impl ToCss for TextEmphasisStyle {
590590
}
591591
}
592592

593+
/// https://www.w3.org/TR/2020/WD-css-text-decor-4-20200506/#text-emphasis-property
593594
#[derive(Debug, Clone, PartialEq)]
594595
pub struct TextEmphasis {
595596
style: TextEmphasisStyle,
@@ -639,6 +640,47 @@ impl ToCss for TextEmphasis {
639640
}
640641
}
641642

643+
enum_property!(TextEmphasisPositionVertical,
644+
Over,
645+
Under
646+
);
647+
648+
enum_property!(TextEmphasisPositionHorizontal,
649+
Left,
650+
Right
651+
);
652+
653+
/// https://www.w3.org/TR/2020/WD-css-text-decor-4-20200506/#text-emphasis-position-property
654+
#[derive(Debug, Clone, PartialEq)]
655+
pub struct TextEmphasisPosition {
656+
vertical: TextEmphasisPositionVertical,
657+
horizontal: TextEmphasisPositionHorizontal
658+
}
659+
660+
impl Parse for TextEmphasisPosition {
661+
fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i, ()>> {
662+
if let Ok(horizontal) = input.try_parse(TextEmphasisPositionHorizontal::parse) {
663+
let vertical = TextEmphasisPositionVertical::parse(input)?;
664+
Ok(TextEmphasisPosition { horizontal, vertical })
665+
} else {
666+
let vertical = TextEmphasisPositionVertical::parse(input)?;
667+
let horizontal = input.try_parse(TextEmphasisPositionHorizontal::parse).unwrap_or(TextEmphasisPositionHorizontal::Right);
668+
Ok(TextEmphasisPosition { horizontal, vertical })
669+
}
670+
}
671+
}
672+
673+
impl ToCss for TextEmphasisPosition {
674+
fn to_css<W>(&self, dest: &mut Printer<W>) -> std::fmt::Result where W: std::fmt::Write {
675+
self.vertical.to_css(dest)?;
676+
if self.horizontal != TextEmphasisPositionHorizontal::Right {
677+
dest.write_char(' ')?;
678+
self.horizontal.to_css(dest)?;
679+
}
680+
Ok(())
681+
}
682+
}
683+
642684
#[derive(Default)]
643685
pub struct TextDecorationHandler {
644686
targets: Option<Browsers>,
@@ -648,6 +690,7 @@ pub struct TextDecorationHandler {
648690
color: Option<(CssColor, VendorPrefix)>,
649691
emphasis_style: Option<(TextEmphasisStyle, VendorPrefix)>,
650692
emphasis_color: Option<(CssColor, VendorPrefix)>,
693+
emphasis_position: Option<(TextEmphasisPosition, VendorPrefix)>,
651694
decls: Vec<Property>
652695
}
653696

@@ -712,6 +755,7 @@ impl PropertyHandler for TextDecorationHandler {
712755
property!(emphasis_style, &val.style, vp);
713756
property!(emphasis_color, &val.color, vp);
714757
}
758+
TextEmphasisPosition(val, vp) => property!(emphasis_position, val, vp),
715759
_ => return false
716760
}
717761

@@ -732,6 +776,7 @@ impl TextDecorationHandler {
732776
let mut color = std::mem::take(&mut self.color);
733777
let mut emphasis_style = std::mem::take(&mut self.emphasis_style);
734778
let mut emphasis_color = std::mem::take(&mut self.emphasis_color);
779+
let mut emphasis_position = std::mem::take(&mut self.emphasis_position);
735780

736781
if let (Some((line, line_vp)), Some(thickness_val), Some((style, style_vp)), Some((color, color_vp))) = (&mut line, &mut thickness, &mut style, &mut color) {
737782
let intersection = *line_vp | *style_vp | *color_vp;
@@ -803,5 +848,21 @@ impl TextDecorationHandler {
803848

804849
single_property!(emphasis_style, TextEmphasisStyle);
805850
single_property!(emphasis_color, TextEmphasisColor);
851+
852+
if let Some((pos, vp)) = emphasis_position {
853+
if !vp.is_empty() {
854+
let mut prefix = vp;
855+
if prefix.contains(VendorPrefix::None) {
856+
if let Some(targets) = self.targets {
857+
prefix = Feature::TextEmphasisPosition.prefixes_for(targets);
858+
// Prefixed version does not support horizontal keyword.
859+
if pos.horizontal != TextEmphasisPositionHorizontal::Right {
860+
prefix = VendorPrefix::None;
861+
}
862+
}
863+
}
864+
self.decls.push(Property::TextEmphasisPosition(pos, prefix))
865+
}
866+
}
806867
}
807868
}

0 commit comments

Comments
 (0)