CSSOM¶
The CSS Object Model: parse stylesheets into typed rules and resolve the cascade to a computed style.
computed_style() runs the CSS Cascade for one element – it collects every <style> sheet in the element’s
document plus the inline style along its ancestor chain, matches the native selector engine, orders the declarations
by origin importance, the style attribute, specificity, and source order, then applies inheritance and each property’s
initial value. The parse, selector match, and cascade all run in the C core; the classes here are the typed, read-only
result shapes. They are the turbohtml-native spelling of the CSSOM CSSStyleSheet / CSSRuleList /
CSSStyleRule / CSSStyleDeclaration interfaces.
The value computed_style() returns is the computed value, not the used value: turbohtml renders nothing, so no
layout runs and lengths, percentages, relative units, and system colors come back as written rather than resolved to
pixels. See The cascade and computed style for that boundary and the property set the cascade covers.
- turbohtml.cssom.computed_style(element)[source]¶
Resolve the CSS cascade for one element and return its computed style.
The cascade reads every
<style>element in the element’s document plus the inlinestyleattributes along its ancestor chain, matches the native selector engine, and orders declarations by importance, the style attribute, specificity, and source order before applying inheritance and initial values.- Parameters:
element (
Element) – the element to compute the style of.- Return type:
- Returns:
the resolved, read-only computed style.
- final class turbohtml.cssom.ComputedStyle(values)[source]¶
An element’s resolved computed style, the read-only result of
computed_style().It exposes one value per supported longhand property (never a shorthand), each already resolved through the cascade, inheritance, and initial values. Missing properties fall back to their initial value, so
get()never returnsNonefor a supported property.- get(name, default=None)[source]¶
Return a property’s computed value, or
defaultwhen it is not a supported property.
- __getitem__(name)[source]¶
Return a property’s computed value, raising
KeyErrorfor an unsupported property.
- final class turbohtml.cssom.StyleSheet(text)[source]¶
A parsed stylesheet, the turbohtml spelling of CSSOM’s
CSSStyleSheet.At-rules (
@media,@import, and the like) are skipped: only top-level style rules joinrules.- Parameters:
text (
str) – the CSS source, such as the text of a<style>element.
- final class turbohtml.cssom.RuleList(rules)[source]¶
A read-only sequence of
StyleRule, the turbohtml spelling of CSSOM’sCSSRuleList.
- final class turbohtml.cssom.StyleRule(selector_text, style)[source]¶
One CSS style rule, the turbohtml spelling of CSSOM’s
CSSStyleRule: a selector and its declarations.- Parameters:
selector_text (
str)style (
StyleDeclaration)
- property style: StyleDeclaration¶
The rule’s declaration block.
- final class turbohtml.cssom.StyleDeclaration(items)[source]¶
A read-only block of CSS declarations, the turbohtml spelling of CSSOM’s
CSSStyleDeclaration.Each declaration keeps its property name, value, and
!importantflag in source order. A property may appear more than once (a later duplicate wins, as the cascade would resolve it);get()and indexing return the winning value, while iteration andproperties()visit each distinct property once, in first-seen order.- classmethod parse(text)[source]¶
Parse a declaration block – an inline
styleattribute or a rule body – into a declaration.- Parameters:
text (
str) – the CSS declaration text, such as"color: red; margin: 0 auto".- Return type:
- Returns:
the parsed declaration.