Donner SVG main
0.8.0 ยท 766e862a0.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
donner::css::Declaration Struct Reference

A declaration is a CSS name/value pair, such as color: red;. More...

#include "donner/css/Declaration.h"

Classes

struct  AuthoredLayout
 Offsets relative to the declaration name. They survive relocation of an untouched rule. More...

Public Member Functions

 Declaration (RcString name, std::vector< ComponentValue > values={}, const FileOffset &sourceOffset=FileOffset::Offset(0), bool important=false)
 Construct a new Declaration object.
 ~Declaration ()=default
 Destructor.
 Declaration (const Declaration &other)=default
 Copy constructor.
 Declaration (Declaration &&other) noexcept=default
 Move constructor.
Declaration & operator= (const Declaration &other)=default
 Copy assignment operator.
Declaration & operator= (Declaration &&other) noexcept=default
 Move assignment operator.
bool operator== (const Declaration &other) const
 Equality operator.
std::string toCssText () const
 Serialize this declaration back to its CSS text representation, e.g.
std::optional< SourceRange > authoredNameRange () const
 Precise editable spans. Synthetic or incomplete constructs have no such range.
std::optional< SourceRange > authoredValueRange () const
std::optional< SourceRange > authoredPriorityRange () const
std::optional< SourceRange > authoredDeclarationRange () const

Public Attributes

RcString name
 Name of the declaration.
std::vector< ComponentValue > values
 List of component values for the declaration.
FileOffset sourceOffset
 Offset of the declaration name in the source string.
SourceRange sourceRange
 Source byte range of the declaration in the stylesheet or style="" attribute, from the first byte of the name to the offset of the last consumed value token.
std::size_t sourceByteSize = 0
 Serialized declaration bytes, computed once by the parser for cascade-work accounting.
std::uint32_t nameSourceByteLength = 0
 Byte length of the authored identifier, including CSS escapes. Zero means unavailable.
struct donner::css::Declaration::AuthoredLayout authored
bool important = false
 Whether the declaration ends with !important. Syntax classification of the values at construction or parser finalization.
VariableReferences variableReferences = VariableReferences::None

Friends

std::ostream & operator<< (std::ostream &os, const Declaration &declaration)
 Output a human-readable representation of the declaration to a stream.

Detailed Description

A declaration is a CSS name/value pair, such as color: red;.

The name is a CSS identifier, and the value is a list of component values which can be parsed into higher-level constructs, such as a transform: transform: translate(10px, 20px);.

The important flag is set if the declaration ends with !important, and the tokens for !important are not included in the values list.


Class Documentation

◆ donner::css::Declaration::AuthoredLayout

struct donner::css::Declaration::AuthoredLayout

Offsets relative to the declaration name. They survive relocation of an untouched rule.

Class Members
size_t colonEnd = 0
size_t end = 0
size_t importantStart = 0

Constructor & Destructor Documentation

◆ Declaration()

donner::css::Declaration::Declaration ( RcString name,
std::vector< ComponentValue > values = {},
const FileOffset & sourceOffset = FileOffset::Offset(0),
bool important = false )
inline

Construct a new Declaration object.

Parameters
nameName of the declaration.
valuesList of component values for the declaration.
sourceOffsetOffset of the declaration name in the source string.
importantWhether the declaration ends with !important.

Member Function Documentation

◆ toCssText()

std::string donner::css::Declaration::toCssText ( ) const

Serialize this declaration back to its CSS text representation, e.g.

fill: red.

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const Declaration & declaration )
friend

Output a human-readable representation of the declaration to a stream.

Parameters
osOutput stream.
declarationDeclaration to output.

Member Data Documentation

◆ sourceRange

SourceRange donner::css::Declaration::sourceRange

Source byte range of the declaration in the stylesheet or style="" attribute, from the first byte of the name to the offset of the last consumed value token.

For fill: red, sourceRange.start points at f and sourceRange.end points at r (the start of the last value token, not past its last byte). This is deliberately a best-effort approximation: structured-editing callers that need a byte-perfect end to splice into a style="" value can compute the trailing bound from the source text by scanning forward from sourceRange.end to the ;, closing brace, or end-of-input.

sourceRange.start == sourceRange.end means "no consumed value tokens" - either the parser failed partway, or the caller constructed the Declaration directly without going through DeclarationListParser.


The documentation for this struct was generated from the following file: