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

Data for a <style> element. More...

#include "donner/svg/components/StylesheetComponent.h"

Public Member Functions

std::uint64_t contentRevision () const
 Identity of this revision of the document and imported rules.
std::size_t selectorCacheBytes () const
 Bytes retained by ruleIndex, importedRuleIndexes and dependencySummary, charged with the stylesheet.
std::span< const css::FontFace > cascadeFontFaces () const
 Font faces contributed by this active CSS sheet, including imported ones.
void setImportedStylesheets (std::vector< css::Stylesheet > &&imported, std::uint64_t generation, std::vector< StylesheetImportOrigin > origins={})
 Install the resolved imports of stylesheet, updating the selector-dependency caches so that imported selectors also invalidate styles.
bool isCssType () const
 Returns true if the <style> element has either no type attribute, or if it has been manually set to "text/css".
bool usesAttributeInSelector (std::string_view localName) const
 Returns true if this stylesheet contains an attribute selector that could match an attribute with the given local name, meaning writing that attribute can change which elements the stylesheet matches.
void parseStylesheet (const RcStringOrRef &str)
 Parse the contents of the <style> element.
void parseStylesheet (const RcStringOrRef &str, StylesheetSourceMap sourceMap)
 Parse the contents of the <style> element with source provenance.
void parseStylesheet (const RcStringOrRef &str, StylesheetSourceMap sourceMap, ParseWarningSink &warnings)
 Parse stylesheet contents while collecting CSS-local diagnostics.
bool applyTextEdit (const StylesheetComponent &previous, std::string_view updatedText, const StylesheetSourceMap &updatedSourceMap, std::size_t offset, std::size_t removedLength, std::size_t insertedLength, css::EditedRuleWindow *changed=nullptr)
 Install a prepared rule-window splice from the previous projection, when supported.

Public Attributes

css::Stylesheet stylesheet
 The parsed stylesheet from the <style> element.
RcString text
 The raw CSS text the stylesheet was parsed from.
RcString type
 The type attribute of the <style> element.
StylesheetSourceMap sourceMap
 Optional mapping from CSS offsets to SVG document source.
bool isUserAgentStylesheet = false
 True if this is a user agent stylesheet, which is defined by the SVG specification and applied by default by the document. If set, this component is attached to an <svg> element instead. The stylesheet within is applied at lower priority, and should be considered a constant for Donner (it can be overridden, but the base style cannot be changed by the user).
std::vector< css::Stylesheet > importedStylesheets
 Stylesheets loaded through @import, flattened in cascade order: each imported sheet follows the sheets it imports, and all of them precede stylesheet's own rules.
std::vector< StylesheetImportOrigin > importOrigins
 Positions of successful loads in their original import streams.
RuleIndex ruleIndex
 Candidate-rule index of stylesheet, rebuilt whenever it or its imports change.
std::vector< RuleIndex > importedRuleIndexes
 Candidate-rule index of each sheet in importedStylesheets, in the same order.
SelectorDependencySummary dependencySummary
 Which elements a change to each id, class and attribute name named by stylesheet or importedStylesheets can restyle, rebuilt whenever they change.
std::vector< css::FontFace > combinedFontFaces
 Font faces of importedStylesheets followed by stylesheet, populated only when imports contributed any; see cascadeFontFaces().
std::uint64_t fontFaceRevision = 0
 Incremented whenever cascadeFontFaces may have changed, so font registration notices new contents even if their storage address and size are reused.
std::optional< std::uint64_t > importGeneration
 Resource-manager generation for which importedStylesheets was resolved, or nullopt when the imports of the current stylesheet have not been resolved yet.

Detailed Description

Member Function Documentation

◆ applyTextEdit()

bool donner::svg::components::StylesheetComponent::applyTextEdit ( const StylesheetComponent & previous,
std::string_view updatedText,
const StylesheetSourceMap & updatedSourceMap,
std::size_t offset,
std::size_t removedLength,
std::size_t insertedLength,
css::EditedRuleWindow * changed = nullptr )

Install a prepared rule-window splice from the previous projection, when supported.

Parameters
previousPrevious projection.
updatedTextNew CSS text.
updatedSourceMapNew source mapping.
offsetLocal CSS byte offset of the edit.
removedLengthOld byte count.
insertedLengthNew byte count.
changedOptional verified rule ranges, set only when the splice succeeds.
Returns
True when the splice was installed, false when a full parse is needed.

◆ parseStylesheet() [1/3]

void donner::svg::components::StylesheetComponent::parseStylesheet ( const RcStringOrRef & str)

Parse the contents of the <style> element.

Parameters
strThe contents of the <style> element.

◆ parseStylesheet() [2/3]

void donner::svg::components::StylesheetComponent::parseStylesheet ( const RcStringOrRef & str,
StylesheetSourceMap sourceMap )

Parse the contents of the <style> element with source provenance.

Parameters
strThe contents of the <style> element.
sourceMapSource map for local CSS offsets in str.

◆ parseStylesheet() [3/3]

void donner::svg::components::StylesheetComponent::parseStylesheet ( const RcStringOrRef & str,
StylesheetSourceMap sourceMap,
ParseWarningSink & warnings )

Parse stylesheet contents while collecting CSS-local diagnostics.

Parameters
strStylesheet contents.
sourceMapSource provenance for the retained stylesheet.
warningsBounded sink receiving recoverable CSS diagnostics.

◆ setImportedStylesheets()

void donner::svg::components::StylesheetComponent::setImportedStylesheets ( std::vector< css::Stylesheet > && imported,
std::uint64_t generation,
std::vector< StylesheetImportOrigin > origins = {} )

Install the resolved imports of stylesheet, updating the selector-dependency caches so that imported selectors also invalidate styles.

Parameters
importedImported stylesheets in cascade order.
generationResource-manager generation the imports were resolved for.
originsOriginal positions of the successful imports, parallel to imported.

◆ usesAttributeInSelector()

bool donner::svg::components::StylesheetComponent::usesAttributeInSelector ( std::string_view localName) const
inline

Returns true if this stylesheet contains an attribute selector that could match an attribute with the given local name, meaning writing that attribute can change which elements the stylesheet matches.

Deliberately per-name rather than a single "uses any attribute selector" flag: the user agent stylesheet always contains one (*[xml|space=preserve]), so a single flag would be set for every document.

Parameters
localNameAttribute local name, compared case-insensitively to over-approximate.

Member Data Documentation

◆ importedStylesheets

std::vector<css::Stylesheet> donner::svg::components::StylesheetComponent::importedStylesheets

Stylesheets loaded through @import, flattened in cascade order: each imported sheet follows the sheets it imports, and all of them precede stylesheet's own rules.

Populated by ResourceManagerContext::loadStylesheetImports when the document is prepared for rendering, and cleared whenever stylesheet is reparsed. Imported rules have no document source provenance, so source-mapped editor queries consider only stylesheet.


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