style

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 14 Imported by: ? 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

Index

Constants

View Source
const (
	AnimationForeground = iota
	AnimationBackground
	AnimationBorderTop
	AnimationBorderRight
	AnimationBorderBottom
	AnimationBorderLeft
	AnimatedColorCount
)
View Source
const AnimatedPropertyCount = 2 + AnimatedColorCount

Variables

Functions

func CopyAnimatedProperties

func CopyAnimatedProperties(dst *AnimationValue, src AnimationValue, properties AnimatedProperties)

func EqualExceptOpacity

func EqualExceptOpacity(a, b *ComputedStyle) bool

EqualExceptOpacity identifies changes that can be applied to a composited group at draw time without repainting its contents.

func HasContainerQueries

func HasContainerQueries(stylesheet *css.Stylesheet) bool

HasContainerQueries reports whether a stylesheet contains rules whose result depends on a laid-out ancestor. Callers can use it to avoid a second style/layout pass for ordinary media-only documents.

func InterpolateAnimatedProperty

func InterpolateAnimatedProperty(dst *AnimationValue, a, b AnimationValue, property AnimatedProperties, t float64)

func IsLength

func IsLength(value Value) bool

func RecomputeInputStateInPlaceWithImpact

func RecomputeInputStateInPlaceWithImpact(root *dom.Node, stylesheet *css.Stylesheet, viewport Viewport, previous, current *css.State, styles Map) (Map, ChangeImpact, error)

RecomputeInputStateInPlaceWithImpact visits the document once, recomputing only branches whose selector matches changed. Recomputing each affected branch also propagates inherited values to its descendants.

func RecomputeInputStateInPlaceWithImpactAndQueries

func RecomputeInputStateInPlaceWithImpactAndQueries(root *dom.Node, stylesheet *css.Stylesheet, viewport Viewport, previous, current *css.State, styles Map, queries *QueryEnvironment) (Map, ChangeImpact, error)

func RecomputeInputStateWithCache

func RecomputeInputStateWithCache(root *dom.Node, stylesheet *css.Stylesheet, viewport Viewport, previous, current *css.State, styles Map, cache *MutationCache) (Map, ChangeImpact, error)

RecomputeInputStateWithCache shares immutable styles with full and mutation cascades, so toggling back to a previous input state reuses its values.

func RecomputeInputStateWithChanges

func RecomputeInputStateWithChanges(root *dom.Node, stylesheet *css.Stylesheet, viewport Viewport, previous, current *css.State, styles Map, changes *[]NodeChange, cache *MutationCache) (Map, ChangeImpact, error)

RecomputeInputStateWithChanges emits changed styles during the input cascade. The caller owns and reuses the output slice, as with subtree mutations.

func RecomputeSubtreesInPlaceWithImpact

func RecomputeSubtreesInPlaceWithImpact(root *dom.Node, stylesheet *css.Stylesheet, viewport Viewport, input *css.State, queries *QueryEnvironment, previousStyles Map, roots []*dom.Node) (Map, ChangeImpact, error)

func RecomputeSubtreesInPlaceWithImpactAndQueries

func RecomputeSubtreesInPlaceWithImpactAndQueries(root *dom.Node, stylesheet *css.Stylesheet, viewport Viewport, input *css.State, queries *QueryEnvironment, previousStyles Map, roots []*dom.Node) (Map, ChangeImpact, error)

func ResolveAnimatedTranslation

func ResolveAnimatedTranslation(value AnimationValue, width, height float64) (float64, float64)

func ResolveLength

func ResolveLength(value Value, base float64) float64

func SameAnimatedProperty

func SameAnimatedProperty(a, b AnimationValue, property AnimatedProperties) bool

Types

type AnimatedProperties

type AnimatedProperties uint8
const (
	AnimatedTransform AnimatedProperties = 1 << iota
	AnimatedOpacity
	AnimatedColor
	AnimatedBackgroundColor
	AnimatedBorderTopColor
	AnimatedBorderRightColor
	AnimatedBorderBottomColor
	AnimatedBorderLeftColor
)

func AnimatedProperty

func AnimatedProperty(name string) AnimatedProperties

type AnimationColor

type AnimationColor struct {
	R, G, B, A, Current float64
}

AnimationColor stores premultiplied, gamma-encoded sRGB. Current retains a currentcolor/inheritance contribution until the element's used color is known.

func ColorForAnimation

func ColorForAnimation(value Value) AnimationColor

func (AnimationColor) Color

func (c AnimationColor) Color() Color

func (AnimationColor) RGBA

func (c AnimationColor) RGBA() (r, g, b, a float64)

func (AnimationColor) Resolve

func (c AnimationColor) Resolve(reference AnimationColor) AnimationColor

type AnimationPoint

type AnimationPoint struct {
	Timing     TimingFunction
	Value      AnimationValue
	Offset     float64
	Properties AnimatedProperties
	HasTiming  bool
}

type AnimationTrack

type AnimationTrack struct {
	Points     []AnimationPoint
	Definition CSSAnimation
	Properties AnimatedProperties
}

func CompileAnimationTracks

func CompileAnimationTracks(node *dom.Node, computed *ComputedStyle, stylesheet *css.Stylesheet, queries *QueryEnvironment) []AnimationTrack

CompileAnimationTracks resolves lengths once, outside the per-frame path. Tracks contain separate endpoints per property; omitted endpoints use the underlying style.

func (*AnimationTrack) Sample

func (track *AnimationTrack) Sample(progress float64, base AnimationValue, before bool) AnimationValue

type AnimationValue

type AnimationValue struct {
	TranslateX, TranslateY                  Value
	Colors                                  [AnimatedColorCount]AnimationColor
	Rotation                                float64
	ScaleX, ScaleY                          float64
	SkewX, TranslateCrossX, TranslateCrossY float64
	Opacity                                 float64
}

func BaseAnimationValue

func BaseAnimationValue(computed *ComputedStyle) AnimationValue

type BackgroundLayer

type BackgroundLayer struct {
	Image      string
	PosXOrigin string
	PosYOrigin string
	Origin     string
	Clip       string
	Attachment string
	SizeX      Value
	SizeY      Value
	PosX       Value
	PosY       Value
	RepeatX    Value
	RepeatY    Value
}

type CSSAnimation

type CSSAnimation struct {
	Name                        string
	Direction, Fill             string
	Timing                      TimingFunction
	Duration, Delay, Iterations float64
	Paused                      bool
}

func (CSSAnimation) Progress

func (a CSSAnimation) Progress(elapsed float64) (progress float64, applies, before bool)

Progress handles delay, fractional iteration counts, direction and fill at exact boundaries.

type ChangeImpact

type ChangeImpact uint8
const (
	ChangeNone ChangeImpact = iota
	ChangePaint
	// ChangeVisual changes generated paint primitives without changing geometry.
	ChangeVisual
	ChangeRebuild
)

func RecomputeSubtreesWithChanges

func RecomputeSubtreesWithChanges(root *dom.Node, stylesheet *css.Stylesheet, viewport Viewport, input *css.State, styles Map, roots []*dom.Node, changes *[]NodeChange, cache *MutationCache) (ChangeImpact, int, error)

RecomputeSubtreesWithChanges updates retained styles and emits changes during the same traversal. Roots must be disjoint and belong to the document.

type Color

type Color struct {
	R uint8
	G uint8
	B uint8
	A uint8
}

func ParseColor

func ParseColor(input string) (Color, error)

ParseColor parses an absolute CSS color. color-mix() currently supports the sRGB interpolation space; currentcolor requires an element's paint context.

type ComputedStyle

type ComputedStyle struct {

	// ExtraBackgroundLayers follows the primary inline Background layer.
	ExtraBackgroundLayers []BackgroundLayer
	BoxShadow             []Shadow
	Filters               []Filter
	// contains filtered or unexported fields
}

func (*ComputedStyle) Animations

func (computed *ComputedStyle) Animations() []CSSAnimation

Animations returns immutable animation definitions shared by computed styles.

func (*ComputedStyle) BackgroundLayer

func (computed *ComputedStyle) BackgroundLayer(index int) *BackgroundLayer

BackgroundLayer returns a borrowed layer. Interned styles must not be mutated.

func (*ComputedStyle) BackgroundLayerCount

func (computed *ComputedStyle) BackgroundLayerCount() int

BackgroundLayerCount includes the primary layer, whose image may be none.

func (*ComputedStyle) HasMotion

func (computed *ComputedStyle) HasMotion() bool

func (*ComputedStyle) TransitionFor

func (computed *ComputedStyle) TransitionFor(index int) TransformTransition

type ContainerMetrics

type ContainerMetrics struct {
	Width  float64
	Height float64
}

type Corners

type Corners struct {
	TopLeft     Radius
	TopRight    Radius
	BottomRight Radius
	BottomLeft  Radius
}

type Cursor added in v0.1.4

type Cursor uint8

Cursor stores a computed CSS keyword in one byte rather than a full Value. The first keyword is the initial value, auto.

func (Cursor) String added in v0.1.4

func (c Cursor) String() string

type Edges

type Edges struct {
	Top    Value
	Right  Value
	Bottom Value
	Left   Value
}

type Filter

type Filter struct {
	Shadow Shadow
	Matrix [20]float64
	Kind   FilterKind
	Amount float64
}

type FilterKind

type FilterKind int
const (
	FilterBlur FilterKind = iota
	FilterBrightness
	FilterOpacity
	FilterContrast
	FilterGrayscale
	FilterSaturate
	FilterSepia
	FilterInvert
	FilterHueRotate
	FilterColorMatrix
	FilterDropShadow
)

type FontStyle

type FontStyle uint8

FontStyle is compact because every computed style stores this inherited value.

const (
	FontNormal FontStyle = iota
	FontItalic
	FontOblique
)

type Map

type Map map[*dom.Node]*ComputedStyle

Map stores one computed style per node. ComputedStyle is a large (~5.5KB) struct, so it is shared by pointer: layout boxes and paint fragments reference the same instance instead of copying it per node. The cascade interns equal instances, so many nodes point at one allocation.

func Compute

func Compute(root *dom.Node, stylesheet *css.Stylesheet) (Map, error)

func ComputeWithCache

func ComputeWithCache(root *dom.Node, stylesheet *css.Stylesheet, viewport Viewport, input *css.State, styles Map, cache *MutationCache) (Map, error)

ComputeWithCache replaces the complete node map while retaining its storage and a bounded index of immutable styles. Equal values can be shared even after DOM nodes are replaced. The caller must invalidate filter definitions when their content changes, as for partial recomputation.

func ComputeWithState

func ComputeWithState(root *dom.Node, stylesheet *css.Stylesheet, input *css.State) (Map, error)

func ComputeWithViewport

func ComputeWithViewport(root *dom.Node, stylesheet *css.Stylesheet, viewport Viewport) (Map, error)

func ComputeWithViewportAndState

func ComputeWithViewportAndState(root *dom.Node, stylesheet *css.Stylesheet, viewport Viewport, input *css.State) (Map, error)

func ComputeWithViewportAndStateAndQueries

func ComputeWithViewportAndStateAndQueries(root *dom.Node, stylesheet *css.Stylesheet, viewport Viewport, input *css.State, queries *QueryEnvironment) (Map, error)

func RecomputeSubtreesInPlaceWithViewportAndStateAndQueries

func RecomputeSubtreesInPlaceWithViewportAndStateAndQueries(root *dom.Node, stylesheet *css.Stylesheet, viewport Viewport, input *css.State, queries *QueryEnvironment, previousStyles Map, roots []*dom.Node) (Map, error)

func (Map) Exclusive

func (m Map) Exclusive(node *dom.Node) *ComputedStyle

Exclusive detaches a node from its interned style so a caller can change it without reaching the sibling nodes which share the same instance.

func (Map) Get

func (m Map) Get(node *dom.Node) (*ComputedStyle, bool)

type MutationCache

type MutationCache struct {
	ContainerMetrics map[*dom.Node]ContainerMetrics
	// contains filtered or unexported fields
}

MutationCache retains document resources across full and partial updates. DOM content/attribute changes other than class/style must invalidate definitions.

func (*MutationCache) InvalidateDefinitions

func (cache *MutationCache) InvalidateDefinitions()

func (*MutationCache) NeedsDocumentStyle

func (cache *MutationCache) NeedsDocumentStyle(stylesheet *css.Stylesheet) bool

NeedsDocumentStyle reports dependencies which cannot be bounded to a changed attribute's descendant branch. Unknown pseudo classes are deliberately conservative so extending the selector engine cannot silently stale styles.

func (*MutationCache) NeedsSiblingStyle

func (cache *MutationCache) NeedsSiblingStyle(stylesheet *css.Stylesheet) bool

type NodeChange

type NodeChange struct {
	Node *dom.Node
	// Tree changes box membership, order or positioning dependencies.
	Tree bool
	// Reorder means order is the only changed tree property; other non-tree
	// style changes may be present and still require normal layout/paint work.
	Reorder bool
	Impact  ChangeImpact
}

NodeChange records the result of the cascade, rather than the mutation that triggered it. The caller owns and reuses the output slice.

type QueryEnvironment

type QueryEnvironment struct {
	ContainerMetrics map[*dom.Node]ContainerMetrics
	Styles           Map
	Viewport         Viewport
}

type Radius

type Radius struct {
	Horizontal Value
	Vertical   Value
}

type Shadow

type Shadow struct {
	OffsetX      Value
	OffsetY      Value
	BlurRadius   Value
	SpreadRadius Value
	Color        Color
	Inset        bool
}

type TimingFunction

type TimingFunction struct {
	Jump           string
	X1, Y1, X2, Y2 float64
	Steps          int
	Kind           TransformEasing
}

TimingFunction is a compiled CSS easing function. Sampling allocates nothing.

func ParseTimingFunction

func ParseTimingFunction(input string) (TimingFunction, bool)

func (TimingFunction) Sample

func (f TimingFunction) Sample(progress float64, before bool) float64

type TransformEasing

type TransformEasing uint8
const (
	TransformEase TransformEasing = iota
	TransformLinear
	TransformEaseIn
	TransformEaseOut
	TransformEaseInOut
)
const (
	TransformCubicBezier TransformEasing = TransformEaseInOut + 1 + iota
	TransformSteps
)

type TransformTransition

type TransformTransition struct {
	Timing   TimingFunction
	Duration float64
	Delay    float64
	Enabled  bool
}

type Value

type Value struct {
	Keyword  string
	LengthPx float64
	Percent  float64
	Number   float64
	Color    Color
	Kind     ValueKind
}

func Auto

func Auto() Value

func ColorValue

func ColorValue(value Color) Value

func Keyword

func Keyword(value string) Value

func LengthCalc

func LengthCalc(pixels, percent float64) Value

func LengthPercent

func LengthPercent(value float64) Value

func LengthPx

func LengthPx(value float64) Value

func Number

func Number(value float64) Value

type ValueKind

type ValueKind uint8
const (
	ValueKeyword ValueKind = iota
	ValueLengthPx
	ValueLengthPercent
	ValueColor
	ValueNumber
	ValueAuto
	ValueLengthCalc
)

type Viewport

type Viewport struct {
	Width  float64
	Height float64
}

Jump to

Keyboard shortcuts

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