Documentation
¶
Overview ¶
Package styler implements the Kite style resolution engine.
Four-Layer Cascade (ADR-010) ¶
The Resolver applies style contributions in the following order, from weakest to strongest precedence:
Inherited values (OriginInherited): inheritable properties (Foreground, Bold, Italic, Underline, Strikethrough, TextWrap, TextOverflow, WhiteSpace, WordBreak, OverflowWrap, ListStyleType, CursorShape, CursorColor) flow from the parent's Computed style into the child when the child does not supply its own value.
Element-type defaults (OriginUADefault): each element type may return a sparse Style from DefaultStyle() to override the root baseline for its specific tag. For example, a <span> returns Display:Inline. Author styles can override these.
Author styles (OriginAuthor): the author-set sparse Style returned by RawStyle() is overlaid on top of inherited and default values. These are the styles the application developer writes (e.g. via element.Style()).
UA-intrinsic styles (OriginUserAgent): the highest-precedence layer, returned by IntrinsicStyle(). Replaced and compound elements (e.g. <input>, <textarea>) use this layer to force UA-mandated properties (e.g. Display:InlineBlock, OverflowX:Clip, WhiteSpace:PreWrap) that the author cannot override. Most elements return an empty style.S() from IntrinsicStyle(), paying zero additional cost.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheEntry ¶
CacheEntry holds the inputs and output of a single Resolve call for one node. Both fields are pointers; comparing them is O(1) and allocation-free.
type CascadeOrigin ¶
type CascadeOrigin uint8
CascadeOrigin identifies the layer of the style cascade that a value comes from. Origins are listed from weakest to strongest; a higher origin wins when both provide a value for the same property.
The enum is internal to the styler package (ADR-010). It must not leak into dom, render, layout, or paint.
const ( // OriginInherited represents a value that was inherited from the parent's // Computed style. This is the weakest origin. OriginInherited CascadeOrigin = iota // OriginUADefault represents the element-type default style contributed // by DefaultStyle(). Overridable by the author. OriginUADefault // OriginAuthor represents the author-set sparse style from RawStyle(). OriginAuthor // OriginUserAgent represents the UA-mandated intrinsic style from // IntrinsicStyle(). This is the strongest origin; authors cannot override it. OriginUserAgent )
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver performs inheritance, default application, and computed-value resolution for a kitex style tree.
Cache policy: Resolve returns the same *Computed pointer when the node does not have DirtyStyle set and the parent *Computed pointer is unchanged. The cache-hit path performs zero heap allocations.
Single-threaded contract: Resolver is not safe for concurrent use.
func NewResolver ¶
func NewResolver() *Resolver
NewResolver creates a Resolver seeded with style.DefaultStyle as the baseline.
func (*Resolver) Invalidate ¶
Invalidate removes the cached entry for node, forcing a full re-resolve on the next Resolve call regardless of the DirtyStyle flag.
func (*Resolver) Resolve ¶
Resolve returns the Computed style for ro, inheriting from parent where appropriate and overlaying the logical node's own style on top.
When the cache is warm (DirtyStyle is false and the parent pointer is unchanged), Resolve returns the cached pointer with zero allocations.