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
use super::layer::LayerName;
use super::supports::SupportsCondition;
use super::Location;
use crate::error::PrinterError;
use crate::media_query::MediaList;
use crate::printer::Printer;
use crate::traits::ToCss;
use crate::values::string::CowArcStr;
use cssparser::*;
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ImportRule<'i> {
#[cfg_attr(feature = "serde", serde(borrow))]
pub url: CowArcStr<'i>,
pub layer: Option<Option<LayerName<'i>>>,
pub supports: Option<SupportsCondition<'i>>,
pub media: MediaList<'i>,
pub loc: Location,
}
impl<'i> ToCss for ImportRule<'i> {
fn to_css<W>(&self, dest: &mut Printer<W>) -> Result<(), PrinterError>
where
W: std::fmt::Write,
{
dest.add_mapping(self.loc);
dest.write_str("@import ")?;
serialize_string(&self.url, dest)?;
if let Some(layer) = &self.layer {
dest.write_str(" layer")?;
if let Some(name) = layer {
dest.write_char('(')?;
name.to_css(dest)?;
dest.write_char(')')?;
}
}
if let Some(supports) = &self.supports {
dest.write_str(" supports")?;
if matches!(
supports,
SupportsCondition::Declaration(_) | SupportsCondition::Parens(_)
) {
supports.to_css(dest)?;
} else {
dest.write_char('(')?;
supports.to_css(dest)?;
dest.write_char(')')?;
}
}
if !self.media.media_queries.is_empty() {
dest.write_char(' ')?;
self.media.to_css(dest)?;
}
dest.write_str(";")
}
}