Struct lightningcss::stylesheet::StyleSheet
source · pub struct StyleSheet<'i, 'o, T = DefaultAtRule> {
pub rules: CssRuleList<'i, T>,
pub sources: Vec<String>,
/* private fields */
}
Expand description
A CSS style sheet, representing a .css
file or inline <style>
element.
Style sheets can be parsed from a string, constructed from scratch, or created using a Bundler. Then, they can be minified and transformed for a set of target browsers, and serialied to a string.
Example
use lightningcss::stylesheet::{
StyleSheet, ParserOptions, MinifyOptions, PrinterOptions
};
// Parse a style sheet from a string.
let mut stylesheet = StyleSheet::parse(
r#"
.foo {
color: red;
}
.bar {
color: red;
}
"#,
ParserOptions::default()
).unwrap();
// Minify the stylesheet.
stylesheet.minify(MinifyOptions::default()).unwrap();
// Serialize it to a string.
let res = stylesheet.to_css(PrinterOptions::default()).unwrap();
assert_eq!(res.code, ".foo, .bar {\n color: red;\n}\n");
Fields§
§rules: CssRuleList<'i, T>
A list of top-level rules within the style sheet.
sources: Vec<String>
A list of file names for all source files included within the style sheet.
Sources are referenced by index in the loc
property of each rule.
Implementations§
source§impl<'i, 'o> StyleSheet<'i, 'o, DefaultAtRule>
impl<'i, 'o> StyleSheet<'i, 'o, DefaultAtRule>
sourcepub fn parse(
code: &'i str,
options: ParserOptions<'o, 'i>
) -> Result<Self, Error<ParserError<'i>>>
pub fn parse( code: &'i str, options: ParserOptions<'o, 'i> ) -> Result<Self, Error<ParserError<'i>>>
Parse a style sheet from a string.
source§impl<'i, 'o, T> StyleSheet<'i, 'o, T>where
T: ToCss,
impl<'i, 'o, T> StyleSheet<'i, 'o, T>where T: ToCss,
sourcepub fn new(
sources: Vec<String>,
rules: CssRuleList<'i, T>,
options: ParserOptions<'o, 'i>
) -> StyleSheet<'i, 'o, T>
pub fn new( sources: Vec<String>, rules: CssRuleList<'i, T>, options: ParserOptions<'o, 'i> ) -> StyleSheet<'i, 'o, T>
Creates a new style sheet with the given source filenames and rules.
sourcepub fn parse_with<P: AtRuleParser<'i, AtRule = T>>(
code: &'i str,
options: ParserOptions<'o, 'i>,
at_rule_parser: &mut P
) -> Result<Self, Error<ParserError<'i>>>
pub fn parse_with<P: AtRuleParser<'i, AtRule = T>>( code: &'i str, options: ParserOptions<'o, 'i>, at_rule_parser: &mut P ) -> Result<Self, Error<ParserError<'i>>>
Parse a style sheet from a string.
sourcepub fn source_map_url(&self, source_index: usize) -> Option<&String>
pub fn source_map_url(&self, source_index: usize) -> Option<&String>
Returns the source map URL for the source at the given index.
sourcepub fn source_map(&self, source_index: usize) -> Option<SourceMap>
Available on crate feature sourcemap
only.
pub fn source_map(&self, source_index: usize) -> Option<SourceMap>
sourcemap
only.Returns the inline source map associated with the source at the given index.
sourcepub fn minify(
&mut self,
options: MinifyOptions
) -> Result<(), Error<MinifyErrorKind>>
pub fn minify( &mut self, options: MinifyOptions ) -> Result<(), Error<MinifyErrorKind>>
Minify and transform the style sheet for the provided browser targets.
sourcepub fn to_css(
&self,
options: PrinterOptions<'_>
) -> Result<ToCssResult, Error<PrinterErrorKind>>
pub fn to_css( &self, options: PrinterOptions<'_> ) -> Result<ToCssResult, Error<PrinterErrorKind>>
Serialize the style sheet to a CSS string.
Trait Implementations§
source§impl<'i, 'o, T: Debug> Debug for StyleSheet<'i, 'o, T>
impl<'i, 'o, T: Debug> Debug for StyleSheet<'i, 'o, T>
source§impl<'de: 'i, 'i, 'o, T> Deserialize<'de> for StyleSheet<'i, 'o, T>where
T: Deserialize<'de>,
impl<'de: 'i, 'i, 'o, T> Deserialize<'de> for StyleSheet<'i, 'o, T>where T: Deserialize<'de>,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl<'i, 'o, T> JsonSchema for StyleSheet<'i, 'o, T>where
T: JsonSchema,
impl<'i, 'o, T> JsonSchema for StyleSheet<'i, 'o, T>where T: JsonSchema,
source§fn schema_name() -> String
fn schema_name() -> String
source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read moresource§impl<'i, 'o, T> Serialize for StyleSheet<'i, 'o, T>where
T: Serialize,
impl<'i, 'o, T> Serialize for StyleSheet<'i, 'o, T>where T: Serialize,
source§impl<'i, 'o, T, V> Visit<'i, T, V> for StyleSheet<'i, 'o, T>where
T: Visit<'i, T, V>,
V: Visitor<'i, T>,
Available on crate feature visitor
only.
impl<'i, 'o, T, V> Visit<'i, T, V> for StyleSheet<'i, 'o, T>where T: Visit<'i, T, V>, V: Visitor<'i, T>,
visitor
only.