pub struct StyleSheet<'i, 'o, T = DefaultAtRule> {
pub rules: CssRuleList<'i, T>,
pub sources: Vec<String>,
pub license_comments: Vec<CowArcStr<'i>>,
/* 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.
license_comments: Vec<CowArcStr<'i>>
The license comments that appeared at the start of the file.
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>
impl<'i, 'o, T> StyleSheet<'i, 'o, T>
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 schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
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>
Available on crate feature visitor
only.
impl<'i, 'o, T, V> Visit<'i, T, V> for StyleSheet<'i, 'o, T>
visitor
only.Source§const CHILD_TYPES: VisitTypes
const CHILD_TYPES: VisitTypes
Auto Trait Implementations§
impl<'i, 'o, T> Freeze for StyleSheet<'i, 'o, T>
impl<'i, 'o, T> RefUnwindSafe for StyleSheet<'i, 'o, T>where
T: RefUnwindSafe,
impl<'i, 'o, T> Send for StyleSheet<'i, 'o, T>where
T: Send,
impl<'i, 'o, T> Sync for StyleSheet<'i, 'o, T>where
T: Sync,
impl<'i, 'o, T> Unpin for StyleSheet<'i, 'o, T>where
T: Unpin,
impl<'i, 'o, T> UnwindSafe for StyleSheet<'i, 'o, T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more