styler

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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:

  1. 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.

  2. 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.

  3. 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()).

  4. 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

type CacheEntry struct {
	Parent *style.Computed
	Result *style.Computed
}

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

func (r *Resolver) Invalidate(n dom.Node)

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

func (r *Resolver) Resolve(ro render.Object, parent *style.Computed) *style.Computed

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.

func (*Resolver) ResolveTree

func (r *Resolver) ResolveTree(ro render.Object, parent *style.Computed, force bool)

ResolveTree recursively resolves styles for the given render subtree.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL