pub struct StyleSheet<'i, 'o, T: AtRuleParser<'i> = DefaultAtRuleParser> {
    pub rules: CssRuleList<'i, T::AtRule>,
    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::AtRule>

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§

Creates a new style sheet with the given source filenames and rules.

Parse a style sheet from a string.

Returns the source map URL for the source at the given index.

Returns the inline source map associated with the source at the given index.

Minify and transform the style sheet for the provided browser targets.

Serialize the style sheet to a CSS string.

Trait Implementations§

Formats the value using the given formatter. Read more
The types of values contained within this value and its children. This is used to skip branches that don’t have any values requested by the Visitor. Read more
Visit the children of this value.
Visits the value by calling an appropriate method on the Visitor. If no corresponding visitor method exists, then the children are visited. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
The archived version of the pointer metadata for this type.
Converts some archived metadata to the pointer metadata for itself.
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Deserializes using the given deserializer

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The type for metadata in pointers and references to Self.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.