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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use super::layer::LayerName;
use super::supports::SupportsCondition;
use super::Location;
use crate::dependencies::{Dependency, ImportDependency};
use crate::error::PrinterError;
use crate::media_query::MediaList;
use crate::printer::Printer;
use crate::traits::ToCss;
use crate::values::string::CowArcStr;
use crate::visitor::Visit;
use cssparser::*;
#[derive(Debug, PartialEq, Clone, Visit)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ImportRule<'i> {
#[cfg_attr(feature = "serde", serde(borrow))]
#[skip_visit]
pub url: CowArcStr<'i>,
#[skip_visit]
pub layer: Option<Option<LayerName<'i>>>,
pub supports: Option<SupportsCondition<'i>>,
pub media: MediaList<'i>,
#[skip_visit]
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,
{
let dep = if dest.dependencies.is_some() {
Some(ImportDependency::new(self, dest.filename()))
} else {
None
};
dest.add_mapping(self.loc);
dest.write_str("@import ")?;
if let Some(dep) = dep {
serialize_string(&dep.placeholder, dest)?;
if let Some(dependencies) = &mut dest.dependencies {
dependencies.push(Dependency::Import(dep))
}
} else {
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(";")
}
}