Skip to main content

css_ast/types/
stroke_layer.rs

1use super::prelude::*;
2use crate::{Color, FillOrigin, Paint, PositionAndSize, RepeatStyle};
3use css_parse::Box;
4
5/// Represents a single layer of the `stroke` shorthand.
6///
7/// The `stroke` property is a shorthand for `stroke-image`, `stroke-position`,
8/// `stroke-size`, `stroke-repeat`, `stroke-origin`, and `stroke-color`,
9/// modelled on `background`'s `<bg-layer>#` grammar the same way `fill` is
10/// (see `FillLayer`). The `color` field is only meaningful on the final
11/// layer, but we parse it permissively on every layer, matching `BgLayer`'s
12/// approach.
13///
14/// <https://drafts.csswg.org/fill-stroke-3/#stroke>
15#[node]
16#[derive(Parse, Peek, ToCursors, ToSpan, SemanticEq, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
17#[parse(all_must_occur)]
18#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
19#[cfg_attr(feature = "visitable", derive(csskit_derives::Visitable), visit)]
20#[derive(csskit_derives::NodeWithMetadata)]
21pub struct StrokeLayer<'a> {
22	pub image: Option<Paint<'a>>,
23	pub position: Option<Box<'a, PositionAndSize<'a>>>,
24	pub repeat: Option<RepeatStyle>,
25	pub origin: Option<FillOrigin>,
26	pub color: Option<Color<'a>>,
27}
28
29#[cfg(test)]
30mod tests {
31	use super::*;
32	use crate::CssAtomSet;
33	use css_parse::{assert_parse, assert_peek_false};
34
35	#[test]
36	fn test_writes() {
37		assert_parse!(CssAtomSet::ATOMS, StrokeLayer, "none");
38		assert_parse!(CssAtomSet::ATOMS, StrokeLayer, "url(foo.svg)");
39		assert_parse!(CssAtomSet::ATOMS, StrokeLayer, "currentcolor");
40		assert_parse!(CssAtomSet::ATOMS, StrokeLayer, "center");
41		assert_parse!(CssAtomSet::ATOMS, StrokeLayer, "center / cover");
42		assert_parse!(CssAtomSet::ATOMS, StrokeLayer, "repeat-x");
43		assert_parse!(CssAtomSet::ATOMS, StrokeLayer, "stroke-box");
44		assert_parse!(CssAtomSet::ATOMS, StrokeLayer, "url(foo.svg) center no-repeat stroke-box red");
45	}
46
47	#[test]
48	fn test_errors() {
49		assert_peek_false!(CssAtomSet::ATOMS, StrokeLayer, "");
50	}
51}