|
|
Donner
C++20 SVG rendering library
|
Donner CSS library, a standalone composable CSS parser. More...
Namespaces | |
| namespace | parser |
| Parsers for various CSS data types, such as the top-level StylesheetParser and SelectorParser, as well as internal details such as ColorParser. | |
Classes | |
| struct | RGBA |
| Represents as 32-bit RGBA color, with each component in the range [0, 255]. More... | |
| struct | HSLA |
| Represents an HSLA color. More... | |
| struct | Color |
| Represents a CSS color value, like a RGBA color from a #rrggbb or #rgb hex value, or the currentcolor keyword. More... | |
| struct | Function |
| A CSS function, such as rgb(255, 0, 0), parsed into a function name and a list of parameter values. More... | |
| struct | SimpleBlock |
| A CSS simple block, such as a rule block or a parenthesized expression. More... | |
| struct | ComponentValue |
| A CSS component value, which is either a token, or a parsed function or block. More... | |
| class | CSS |
| Public API for parsing CSS. More... | |
| struct | Declaration |
| A declaration is a CSS name/value pair, such as color: red;. More... | |
| struct | DeclarationOrAtRule |
| Return value of parsers that may return either a declaration or an AtRule, specifically donner::css::parser::DeclarationListParser::Parse. More... | |
| struct | AnbValue |
| An+B microsyntax value, which is parsed by parser::AnbMicrosyntaxParser. More... | |
| struct | FontFaceSource |
| A single entry listed in src:—either a local face, a URL, or inline data. More... | |
| struct | FontFace |
| In-memory representation of a single @font-face rule. More... | |
| struct | AtRule |
| Rules starting with an @ are called At-Rules, and are used to define CSS features such as @media, @font-face, @keyframes, etc. More... | |
| struct | QualifiedRule |
| A QualifiedRule has a list of component values and a block, this is the intermediate representation of a stylesheet rule. More... | |
| struct | InvalidRule |
| InvalidRule is used to represent a rule which could not be parsed, such as an invalid at-rule. More... | |
| struct | Rule |
| Holds a CSS rule which can either be a standard QualifiedRule, an AtRule, or an InvalidRule if there was a parse error. More... | |
| struct | Selector |
| A top-level Selector, which is a list of ComplexSelector. More... | |
| struct | AttributeSelector |
| Selectors which match against element attributes, such as a[href^="https://"] or h1[title]. More... | |
| struct | ClassSelector |
| Selector which match the element's class attribute, for example .foo matches an element with class foo. More... | |
| struct | SelectorMatchResult |
| Returned by Selector::matches to indicate whether the selector matched, and if so, the specificity of the match. More... | |
| struct | ComplexSelector |
| A complex selector is a sequence of one or more compound selectors, separated by combinators. More... | |
| struct | CompoundSelector |
| A compound selector is a sequence of simple selectors, which represents a set of conditions that are combined to match a single element. More... | |
| struct | IdSelector |
| Selector which match the element's id attribute, for example #foo matches an element with an id="foo" attribute. More... | |
| struct | PseudoClassSelector |
| Selectors which start with one colon, e.g. More... | |
| struct | PseudoElementSelector |
| Selectors which start with two colons are called pseudo-elements, e.g. More... | |
| struct | SelectorMatchOptions |
| Options for matching a selector against an element. More... | |
| struct | TypeSelector |
| Selector which matches the element type, e.g. More... | |
| class | Specificity |
| A CSS specificity value (id, class, type), as defined in https://www.w3.org/TR/selectors-4/#specificity-rules, which is used during cascading to determine which style takes precedence. More... | |
| struct | SelectorRule |
| A rule in a stylesheet, which consists of a selector and a list of declarations. More... | |
| class | Stylesheet |
| A CSS stylesheet, which is a list of rules. More... | |
| class | MultiSelectorMatcher |
| class | ComplexSelectorIsImpl |
| struct | Token |
| A CSS token, which are created as a first step when parsing a CSS string. More... | |
| struct | WqName |
| A CSS qualified name, which is a name optionally associated with a namespace. More... | |
Typedefs | |
| using | TokenIndex = size_t |
| Type of the token unique identifier, which is returned by Token::tokenIndex() and Token::indexOf<T>(). | |
Enumerations | |
| enum class | AttrMatcher { Includes , DashMatch , PrefixMatch , SuffixMatch , SubstringMatch , Eq } |
| For attribute selectors, different match modes are available, which are specified by this enum. More... | |
| enum class | Combinator { Descendant , Child , NextSibling , SubsequentSibling , Column } |
| Between two compound selectors, there can be a combinator, which specifies how the two elements are associated in the tree. More... | |
| enum class | MatcherOptions { CaseSensitive , CaseInsensitive , Default = CaseSensitive } |
| enum class | NumberType { Integer , Number } |
| Indicates if a number is an integer or a floating point number, used for number-containing tokens such as `Token::Number` and Token::Dimension. More... | |
Functions | |
| std::ostream & | operator<< (std::ostream &os, const RGBA &color) |
| std::ostream & | operator<< (std::ostream &os, const HSLA &color) |
| std::ostream & | operator<< (std::ostream &os, const Color &color) |
| std::ostream & | operator<< (std::ostream &os, const Function &func) |
| std::ostream & | operator<< (std::ostream &os, const SimpleBlock &block) |
| std::ostream & | operator<< (std::ostream &os, const Declaration &declaration) |
| MATCHER_P (TokenIsImpl, token, "") | |
| template<typename T, typename... Args> | |
| auto | TokenIs (Args... args) |
| Given a Token or a variant containing a token, matches if the token is equal, ignoring the offset. | |
| template<typename... Args> | |
| auto | TokenIsIdent (Args... args) |
| template<typename... Args> | |
| auto | TokenIsFunction (Args... args) |
| template<typename... Args> | |
| auto | TokenIsAtKeyword (Args... args) |
| template<typename... Args> | |
| auto | TokenIsHash (Args... args) |
| template<typename... Args> | |
| auto | TokenIsString (Args... args) |
| template<typename... Args> | |
| auto | TokenIsBadString (Args... args) |
| template<typename... Args> | |
| auto | TokenIsUrl (Args... args) |
| template<typename... Args> | |
| auto | TokenIsBadUrl (Args... args) |
| template<typename... Args> | |
| auto | TokenIsDelim (Args... args) |
| template<typename... Args> | |
| auto | TokenIsNumber (Args... args) |
| template<typename... Args> | |
| auto | TokenIsPercentage (Args... args) |
| template<typename... Args> | |
| auto | TokenIsDimension (Args... args) |
| template<typename... Args> | |
| auto | TokenIsWhitespace (Args... args) |
| template<typename... Args> | |
| auto | TokenIsCDO (Args... args) |
| template<typename... Args> | |
| auto | TokenIsCDC (Args... args) |
| template<typename... Args> | |
| auto | TokenIsColon (Args... args) |
| template<typename... Args> | |
| auto | TokenIsSemicolon (Args... args) |
| template<typename... Args> | |
| auto | TokenIsComma (Args... args) |
| template<typename... Args> | |
| auto | TokenIsSquareBracket (Args... args) |
| template<typename... Args> | |
| auto | TokenIsParenthesis (Args... args) |
| template<typename... Args> | |
| auto | TokenIsCurlyBracket (Args... args) |
| template<typename... Args> | |
| auto | TokenIsCloseSquareBracket (Args... args) |
| template<typename... Args> | |
| auto | TokenIsCloseParenthesis (Args... args) |
| template<typename... Args> | |
| auto | TokenIsCloseCurlyBracket (Args... args) |
| template<typename... Args> | |
| auto | TokenIsErrorToken (Args... args) |
| template<typename... Args> | |
| auto | TokenIsEofToken (Args... args) |
| MATCHER_P3 (DeclarationIsImpl, nameMatcher, valuesMatcher, importantMatcher, "") | |
| template<typename NameMatcher, typename ValuesMatcher, typename ImportantMatcher> | |
| auto | DeclarationIs (NameMatcher nameMatcher, ValuesMatcher valuesMatcher, ImportantMatcher importantMatcher) |
| template<typename NameMatcher, typename ValuesMatcher> | |
| auto | DeclarationIs (NameMatcher nameMatcher, ValuesMatcher valuesMatcher) |
| MATCHER_P3 (AtRuleIsImpl, nameMatcher, preludeMatcher, blockMatcher, "") | |
| template<typename NameMatcher, typename PreludeMatcher, typename BlockMatcher> | |
| auto | AtRuleIs (NameMatcher nameMatcher, PreludeMatcher preludeMatcher, BlockMatcher blockMatcher) |
| template<typename NameMatcher, typename PreludeMatcher> | |
| auto | AtRuleIs (NameMatcher nameMatcher, PreludeMatcher preludeMatcher) |
| MATCHER (InvalidRuleTypeImpl, "") | |
| auto | InvalidRuleType () |
| MATCHER_P2 (FunctionIs, nameMatcher, valuesMatcher, "") | |
| MATCHER_P2 (SimpleBlockIs, associatedTokenMatcher, valuesMatcher, "") | |
| template<typename ValuesMatcher> | |
| auto | SimpleBlockIsCurly (ValuesMatcher valuesMatcher) |
| template<typename ValuesMatcher> | |
| auto | SimpleBlockIsSquare (ValuesMatcher valuesMatcher) |
| template<typename ValuesMatcher> | |
| auto | SimpleBlockIsParenthesis (ValuesMatcher valuesMatcher) |
| MATCHER_P2 (QualifiedRuleIsImpl, preludeMatcher, blockMatcher, "") | |
| template<typename PreludeMatcher, typename BlockMatcher> | |
| auto | QualifiedRuleIs (PreludeMatcher preludeMatcher, BlockMatcher blockMatcher) |
| std::ostream & | operator<< (std::ostream &os, const AtRule &rule) |
| std::ostream & | operator<< (std::ostream &os, const Selector &obj) |
| Ostream output operator for Selector, prints a debug representation of the selector, e.g. Selector(div, .class, #id). | |
| std::ostream & | operator<< (std::ostream &os, AttrMatcher matcher) |
| Ostream output operator. | |
| std::ostream & | operator<< (std::ostream &os, const ComplexSelector &obj) |
| Ostream output operator for ComplexSelector, outputs debug strings e.g. "ComplexSelector(CompoundSelector(TypeSelector(name)))". | |
| std::ostream & | operator<< (std::ostream &os, Combinator combinator) |
| Ostream output operator. | |
| std::ostream & | operator<< (std::ostream &os, const PseudoClassSelector &obj) |
| Ostream output operator for PseudoClassSelector, outputs a debug string e.g. PseudoClassSelector(after). | |
| template<typename... Args> | |
| auto | SelectorsAre (const Args &... matchers) |
| Match a Selector against an array of ComplexSelectors, used like: | |
| Specificity | computeSpecificity (std::string_view str) |
| Get the specificity of the Selector string (id, class, type). | |
| template<typename... Args> | |
| auto | ComplexSelectorIs (const Args &... matchers) |
| Match either a single ComplexSelector, or a Selector containing a single ComplexSelector. | |
| MATCHER_P (SpecificityIs, specificity, "") | |
| Checks if either a Selector, ComplexSelector, or Specificity has the given specificity. | |
| template<typename... Args> | |
| auto | EntryIs (Combinator combinator, const Args &... matchers) |
| template<typename... Args> | |
| auto | EntryIs (const Args &... matchers) |
| MATCHER_P2 (PseudoElementSelectorIsImpl, ident, argsMatcher, "") | |
| auto | PseudoElementSelectorIs (const char *ident) |
| template<typename ArgsMatcher> | |
| auto | PseudoElementSelectorIs (const char *ident, ArgsMatcher argsMatcher) |
| MATCHER_P2 (TypeSelectorIsImpl, ns, name, "") | |
| auto | TypeSelectorIs (const char *name) |
| auto | TypeSelectorIs (const char *ns, const char *name) |
| MATCHER_P (IdSelectorIs, name, "") | |
| MATCHER_P (ClassSelectorIs, name, "") | |
| MATCHER_P2 (PseudoClassSelectorIsImpl, ident, argsMatcher, "") | |
| auto | PseudoClassSelectorIs (const char *ident) |
| template<typename ArgsMatcher> | |
| auto | PseudoClassSelectorIs (const char *ident, ArgsMatcher argsMatcher) |
| MATCHER_P3 (AttributeSelectorIsImpl, ns, name, matcherMatcher, "") | |
| auto | AttributeSelectorIs (const char *name) |
| auto | AttributeSelectorIs (const char *ns, const char *name) |
| template<typename MatcherMatcher> | |
| auto | AttributeSelectorIs (const char *name, MatcherMatcher matcherMatcher) |
| template<typename MatcherMatcher> | |
| auto | AttributeSelectorIs (const char *ns, const char *name, MatcherMatcher matcherMatcher) |
| auto | MatcherIs (AttrMatcher op, const char *value, MatcherOptions options=MatcherOptions::Default) |
Donner CSS library, a standalone composable CSS parser.
This library is designed to be used in other projects, and provides building blocks to add CSS parsing to any application. This is used by Donner itself to parse SVG stylesheets, but it can be used for HTML-based CSS as well.
This library includes support for parsing rules and declarations, as well as matching selectors against a DOM tree.
To get started, parse a Stylesheet using CSS::ParseStylesheet, and then use the returned Stylesheet object to match against a DOM tree:
| struct donner::css::FontFace |
In-memory representation of a single @font-face rule.
| Class Members | ||
|---|---|---|
| RcString | familyName | font-family descriptor |
| vector< FontFaceSource > | sources | ordered src list |
| struct donner::css::SelectorMatchOptions |
Options for matching a selector against an element.
This is used to pass additional information to the matching algorithm, such as the element to match against for relative queries.
| T | A type that fulfills the ElementLike concept, matching the Selector::matches method. |
| Class Members | ||
|---|---|---|
| const T * | relativeToElement | Enables relative querying and uses this element as the reference point. For example, > div will match div that is a child of relativeToElement. |
| const T * | scopeElement = nullptr | Element to match against :scope queries. Cannot be matched directly, but can be used for relative matching. |
|
strong |
For attribute selectors, different match modes are available, which are specified by this enum.
See https://www.w3.org/TR/selectors-4/#attribute-selectors for the full definition.
These are used within square brackets on the selector list, such as a[href^="https://"] or h1[title], and AttrMatcher represents the separator between the attribute name and string, such as ^= or =.
|
strong |
Between two compound selectors, there can be a combinator, which specifies how the two elements are associated in the tree.
By default, a space between compound selectors is a descendant combinator, e.g. div span is a Descendant combinator, while div > span is a Child combinator.
| Enumerator | |
|---|---|
| Descendant | Space-separated, finds descendants in the tree. |
| Child | '>', finds direct children in the tree. |
| NextSibling | '+', finds the next sibling in the tree. |
| SubsequentSibling | '~', finds all subsequent siblings in the tree. |
| Column | '||', finds the next column in the tree. Note that this is a new feature in CSS Selectors Level 4, but isn't applicable to SVG. |
|
strong |
Indicates if a number is an integer or a floating point number, used for number-containing tokens such as `Token::Number` and Token::Dimension.
| Enumerator | |
|---|---|
| Integer | Integer number (no decimal point). |
| Number | Floating point number. |
| auto donner::css::ComplexSelectorIs | ( | const Args &... | matchers | ) |
Match either a single ComplexSelector, or a Selector containing a single ComplexSelector.
Example
| matchers... | Matchers against a ComplexSelector::Entry. |
|
inline |
| donner::css::MATCHER_P | ( | SpecificityIs | , |
| specificity | , | ||
| "" | ) |
Checks if either a Selector, ComplexSelector, or Specificity has the given specificity.
Examples:
| arg | Selector, ComplexSelector, or Specificity to match against. |
| specificity | Specificity to match against. |
|
inline |
Ostream output operator.
Outputs the combinator character, e.g. ' ', '>', '+', '~' or '||'.
| os | The output stream. |
| combinator | The combinator. |
| std::ostream & donner::css::operator<< | ( | std::ostream & | os, |
| const AtRule & | rule ) |
| os | Output stream. |
| rule | AtRule to output. |
| std::ostream & donner::css::operator<< | ( | std::ostream & | os, |
| const Color & | color ) |
| std::ostream & donner::css::operator<< | ( | std::ostream & | os, |
| const Declaration & | declaration ) |
| os | Output stream. |
| declaration | Declaration to output. |
| std::ostream & donner::css::operator<< | ( | std::ostream & | os, |
| const Function & | func ) |
| os | Output stream. |
| func | Function to output. |
| std::ostream & donner::css::operator<< | ( | std::ostream & | os, |
| const HSLA & | color ) |
Outputs: hsla(h, s, l, a).
| os | The output stream. |
| color | The color to output. |
| std::ostream & donner::css::operator<< | ( | std::ostream & | os, |
| const RGBA & | color ) |
Outputs: rgba(r, g, b, a).
| os | The output stream. |
| color | The color to output. |
| std::ostream & donner::css::operator<< | ( | std::ostream & | os, |
| const SimpleBlock & | block ) |
| os | Output stream. |
| block | Simple block to output. |
| auto donner::css::SelectorsAre | ( | const Args &... | matchers | ) |
Match a Selector against an array of ComplexSelectors, used like:
| matchers | Matcher against a ComplexSelector array. |