#![feature(allocator_api)]
#![allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
#![warn(unused_must_use)]
extern crate self as bun_css;
#[macro_export]
macro_rules! match_ignore_ascii_case {
($name:expr, { $( $($lit:literal)|+ $(if $guard:expr)? => $arm:expr ,)* _ => $fallback:expr $(,)? }) => {{
let __n: &[u8] = $name;
$( if ($( ::bun_core::strings::eql_case_insensitive_ascii_check_length(__n, $lit) )||+) $(&& ($guard))? { $arm } else )* { $fallback }
}};
}
#[path = "compat.rs"]
pub mod compat;
#[path = "logical.rs"]
pub mod logical;
#[path = "prefixes.rs"]
pub mod prefixes;
#[path = "sourcemap.rs"]
pub mod sourcemap;
#[path = "targets.rs"]
pub mod targets;
#[path = "css_modules.rs"]
pub mod css_modules;
#[path = "dependencies.rs"]
pub mod dependencies;
#[path = "error.rs"]
pub mod error;
#[path = "small_list.rs"]
pub mod small_list;
pub use small_list::SmallList;
#[path = "media_query.rs"]
pub mod media_query;
#[path = "properties/mod.rs"]
pub mod properties;
#[path = "rules/mod.rs"]
pub mod rules;
#[path = "selectors/mod.rs"]
pub mod selectors;
#[path = "context.rs"]
pub mod context;
#[path = "declaration.rs"]
pub mod declaration;
pub use context::{DeclarationContext, PropertyHandlerContext, SupportsEntry};
pub use declaration::{DeclarationBlock, DeclarationHandler, DeclarationList};
pub use properties as css_properties;
pub use rules as css_rules;
pub use selectors::selector;
pub use values as css_values;
pub use css_parser::{
CssRef, CssRefTag, CssResult as Result, Delimiters, EnumProperty, IntoParserError, Maybe,
ParserState, enum_property_util, nth, parse_utility, signfns, void_wrap,
};
pub(crate) type Str = *const [u8];
#[inline(always)]
pub(crate) unsafe fn arena_str(p: Str) -> &'static [u8] {
unsafe { &*p }
}
pub use compat::Feature;
pub use error::ParserErrorKind as ParseErrorKind;
pub use error::ParserErrorKind as ErrorKind;
pub use properties::custom::{TokenList, TokenListFns};
pub use values::ident::{CustomIdentFns, DashedIdentFns, IdentFns};
pub use values::string::{CssString as CSSString, CssStringFns as CSSStringFns};
pub use generics as generic;
pub use generics::{implement_deep_clone, implement_eql, implement_hash};
pub use generics::{CssEql, DeepClone};
pub use bun_css_derive::{DefineEnumProperty, Parse, ToCss};
pub use css_parser::{dtoa_short, f32_length_with_5_digits, serializer, to_css};
#[path = "generics.rs"]
pub mod generics;
#[path = "css_parser.rs"]
pub mod css_parser;
#[path = "printer.rs"]
pub mod printer;
#[path = "values/mod.rs"]
pub mod values;
pub mod values_stub {
pub mod color {
pub use crate::values::color::*;
pub type CssColorParseResult = crate::values::color::ParseResult;
pub use crate::css_parser::color::hsl_to_rgb;
}
pub mod ident {
pub use crate::values::ident::*;
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PrintErr {
CSSPrintError,
}
impl PrintErr {
#[inline]
pub fn name(self) -> &'static str {
"CSSPrintError"
}
}
impl core::fmt::Display for PrintErr {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("CSS print error")
}
}
impl core::error::Error for PrintErr {}
pub(crate) type PrintResult<T = ()> = core::result::Result<T, PrintErr>;
pub use dependencies::Dependency;
pub use css_parser::{
DefaultAtRule, LocalsResultsMap, MinifyOptions, Parser, ParserFlags, ParserInput,
ParserOptions, StyleAttribute, StyleSheet, StylesheetExtra, ToCssResult,
};
pub use printer::{ImportInfo, Printer, PrinterOptions, PseudoClasses};
pub type ImportRecordHandler<'a> = printer::ImportInfo<'a>;
pub use values::color::{CssColor, FloatColor, LABColor, LabColor, PredefinedColor, RGBA};
pub use values_stub::color::CssColorParseResult;
pub use error::{
BasicParseError, BasicParseErrorKind, Err, ErrorLocation, MinifyError, MinifyErrorKind,
ParseError, ParserError, ParserErrorKind, PrinterError, PrinterErrorKind, SelectorError,
};
pub type Error = Err<ParserError>;
pub use logical::{LogicalGroup, PropertyCategory};
pub use targets::{Browsers, Features, Targets};
pub use css_parser::BundlerStyleSheet;
pub use properties::PropertyIdTag;
pub use rules::import::ImportConditions;
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct VendorPrefix: u8 {
const NONE = 0b0000_0001;
const WEBKIT = 0b0000_0010;
const MOZ = 0b0000_0100;
const MS = 0b0000_1000;
const O = 0b0001_0000;
}
}
impl VendorPrefix {
pub const EMPTY: VendorPrefix = VendorPrefix::empty();
pub const ALL_PREFIXES: VendorPrefix = VendorPrefix::all();
pub const FIELDS: &'static [VendorPrefix] = &[
VendorPrefix::WEBKIT,
VendorPrefix::MOZ,
VendorPrefix::MS,
VendorPrefix::O,
VendorPrefix::NONE,
];
#[inline]
pub fn from_name_str(name: &str) -> VendorPrefix {
match name {
"none" => VendorPrefix::NONE,
"webkit" => VendorPrefix::WEBKIT,
"moz" => VendorPrefix::MOZ,
"ms" => VendorPrefix::MS,
"o" => VendorPrefix::O,
_ => unreachable!(),
}
}
#[inline]
pub fn or_none(self) -> VendorPrefix {
self.or_(VendorPrefix::NONE)
}
#[inline]
pub fn or_(self, other: VendorPrefix) -> VendorPrefix {
if self.is_empty() { other } else { self }
}
pub fn difference_(left: Self, right: Self) -> Self {
Self::from_bits_retain(left.bits().wrapping_sub(right.bits()))
}
pub fn bitwise_and(self, b: Self) -> Self {
self & b
}
pub fn as_bits(self) -> u8 {
self.bits()
}
#[inline]
pub fn strip_from(name: &[u8]) -> (VendorPrefix, &[u8]) {
use bun_core::strings::starts_with_case_insensitive_ascii as has;
if has(name, b"-webkit-") {
(VendorPrefix::WEBKIT, &name[8..])
} else if has(name, b"-moz-") {
(VendorPrefix::MOZ, &name[5..])
} else if has(name, b"-o-") {
(VendorPrefix::O, &name[3..])
} else if has(name, b"-ms-") {
(VendorPrefix::MS, &name[4..])
} else {
(VendorPrefix::NONE, name)
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub struct SourceLocation {
pub line: u32,
pub column: u32,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, DeepClone)]
pub struct Location {
pub source_index: u32,
pub line: u32,
pub column: u32,
}
impl Location {
pub fn dummy() -> Location {
Location {
source_index: u32::MAX,
line: u32::MAX,
column: u32::MAX,
}
}
}
#[derive(Clone, Copy, Debug)]
pub struct Num {
pub has_sign: bool,
pub value: f32,
pub int_value: Option<i32>,
}
#[derive(Copy, Clone, Debug)]
pub struct Dimension {
pub num: Num,
pub unit: &'static [u8],
}
#[derive(Clone, Debug)]
pub enum Token {
Ident(&'static [u8]),
Function(&'static [u8]),
AtKeyword(&'static [u8]),
UnrestrictedHash(&'static [u8]),
IdHash(&'static [u8]),
QuotedString(&'static [u8]),
BadString(&'static [u8]),
UnquotedUrl(&'static [u8]),
BadUrl(&'static [u8]),
Delim(u32),
Number(Num),
Percentage {
has_sign: bool,
unit_value: f32,
int_value: Option<i32>,
},
Dimension(Dimension),
Whitespace(&'static [u8]),
Cdo,
Cdc,
IncludeMatch,
DashMatch,
PrefixMatch,
SuffixMatch,
SubstringMatch,
Colon,
Semicolon,
Comma,
OpenSquare,
CloseSquare,
OpenParen,
CloseParen,
OpenCurly,
CloseCurly,
Comment(&'static [u8]),
}
impl core::fmt::Display for Token {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
use bstr::BStr;
match self {
Token::Ident(v)
| Token::Function(v)
| Token::AtKeyword(v)
| Token::UnrestrictedHash(v)
| Token::IdHash(v)
| Token::QuotedString(v)
| Token::BadString(v)
| Token::UnquotedUrl(v)
| Token::BadUrl(v)
| Token::Whitespace(v)
| Token::Comment(v) => {
write!(f, "{}", BStr::new(v))
}
Token::Delim(c) => write!(f, "{}", char::from_u32(*c).unwrap_or('\u{FFFD}')),
Token::Number(n) => write!(f, "{}", n.value),
Token::Percentage { unit_value, .. } => write!(f, "{}%", *unit_value * 100.0),
Token::Dimension(d) => write!(f, "{}{}", d.num.value, BStr::new(d.unit)),
Token::Cdo => f.write_str("<!--"),
Token::Cdc => f.write_str("-->"),
Token::IncludeMatch => f.write_str("~="),
Token::DashMatch => f.write_str("|="),
Token::PrefixMatch => f.write_str("^="),
Token::SuffixMatch => f.write_str("$="),
Token::SubstringMatch => f.write_str("*="),
Token::Colon => f.write_str(":"),
Token::Semicolon => f.write_str(";"),
Token::Comma => f.write_str(","),
Token::OpenSquare => f.write_str("["),
Token::CloseSquare => f.write_str("]"),
Token::OpenParen => f.write_str("("),
Token::CloseParen => f.write_str(")"),
Token::OpenCurly => f.write_str("{"),
Token::CloseCurly => f.write_str("}"),
}
}
}