css

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseInline

func ParseInline(src string) (*Declarations, []Diagnostic)

ParseInline parses a declaration list using the stylesheet declaration grammar.

Types

type Color

type Color struct{ R, G, B, A float64 }

type ColorSides

type ColorSides struct{ Top, Right, Bottom, Left Color }

type Computed

type Computed struct {
	Style *Style
	// contains filtered or unexported fields
}

Computed holds both the typed style and the identity needed for descendant matching.

type Declaration

type Declaration struct {
	Property, Value string
	Important       bool
	Line, Col       int
}

type Declarations

type Declarations struct {
	// contains filtered or unexported fields
}

Declarations are parsed inline CSS. Do not modify them after passing them to Compute.

type Diagnostic

type Diagnostic struct {
	Line, Col int
	Message   string
}

type Element

type Element struct {
	Type, ID string
	Classes  []string
	State    StateFlags
	Inline   *Declarations
}

Element is the matching identity for one Compute call. Parentage comes from Computed.

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine is single-goroutine only; neither Compute nor EndFrame is synchronized. Compiled rules never change. Compile a new Engine when CSS changes.

func Compile

func Compile(ua, author Sheet) *Engine

Compile indexes the rightmost compound of every selector and freezes the sheets.

func (*Engine) Compute

func (en *Engine) Compute(e *Element, parent *Computed) *Computed

Compute returns the same *Computed on memo hits. parent must come from this Engine.

func (*Engine) EndFrame

func (en *Engine) EndFrame()

EndFrame advances the generation and drops entries not used in the last two frames.

type Keyword

type Keyword uint8

Keyword is a computed CSS enumerated value. The documented property grammar supplies the possible values for each field.

const (
	KeywordNone Keyword = iota
	KeywordAuto
	KeywordBlock
	KeywordFlex
	KeywordContentBox
	KeywordBorderBox
	KeywordRow
	KeywordColumn
	KeywordNowrap
	KeywordWrap
	KeywordFlexStart
	KeywordFlexEnd
	KeywordCenter
	KeywordSpaceBetween
	KeywordSpaceAround
	KeywordSpaceEvenly
	KeywordStretch
	KeywordVisible
	KeywordHidden
	KeywordScroll
	KeywordNormal
	KeywordItalic
	KeywordOblique
	KeywordStart
	KeywordEnd
	KeywordLeft
	KeywordRight
	KeywordDefault
	KeywordPointer
	KeywordText
	KeywordNotAllowed
	KeywordSolid
	KeywordNumber
)

type KeywordSides

type KeywordSides struct{ Top, Right, Bottom, Left Keyword }

type Length

type Length struct {
	Value float64
	Unit  string
}

type LengthSides

type LengthSides struct{ Top, Right, Bottom, Left Length }

Sides and Corners follow clockwise CSS order.

type Radii

type Radii struct{ TopLeft, TopRight, BottomRight, BottomLeft Length }

type Rule

type Rule struct {
	Selectors    []Selector
	Declarations []Declaration
}

type Selector

type Selector struct {
	Specificity Specificity
	// contains filtered or unexported fields
}

type Shadow

type Shadow struct {
	Inset              bool
	X, Y, Blur, Spread Length
	Color              Color
}

type Sheet

type Sheet struct {
	Rules       []Rule
	Diagnostics []Diagnostic
}

func Parse

func Parse(src string) Sheet

func UA

func UA() Sheet

UA returns the embedded user-agent sheet. Treat the returned sheet as immutable.

type Specificity

type Specificity struct{ IDs, Classes, Types int }

type StateFlags

type StateFlags uint8

StateFlags are the supported CSS pseudo-class states.

const (
	Hover StateFlags = 1 << iota
	Active
	Focus
	FocusVisible
	Disabled
	Checked
)

type Style

type Style struct {
	Color                                                       Color
	Opacity                                                     float64
	BackgroundColor                                             Color
	BorderWidth                                                 LengthSides
	BorderStyle                                                 KeywordSides
	BorderColor                                                 ColorSides
	BorderRadius                                                Radii
	OutlineWidth                                                Length
	OutlineStyle                                                Keyword
	OutlineColor                                                Color
	OutlineOffset                                               Length
	BoxShadow                                                   []Shadow
	Margin, Padding                                             LengthSides
	Width, Height, MinWidth, MinHeight, MaxWidth, MaxHeight     Length
	BoxSizing, Display, FlexDirection, FlexWrap                 Keyword
	FlexGrow, FlexShrink                                        float64
	FlexBasis, RowGap, ColumnGap                                Length
	JustifyContent, AlignItems, AlignSelf, OverflowX, OverflowY Keyword
	FontFamily                                                  []string
	FontSize                                                    Length
	FontWeight                                                  float64
	FontStyle                                                   Keyword
	LineHeight                                                  Length
	LineHeightNumber                                            float64
	LineHeightKind                                              Keyword
	TextAlign                                                   Keyword
	LetterSpacing                                               Length
	LetterSpacingNormal                                         bool
	Cursor                                                      Keyword
	AccentColor                                                 Color // checkbox, radio and slider indicators
}

Style is a computed, immutable value. Slice backing arrays are shared: do not mutate a returned Style or any of its slices.

type Token

type Token struct {
	Kind, Raw, Value string
	Line, Col        int
}

Token is a CSS syntax token. Raw preserves the original spelling for value parsing.

func Tokenize

func Tokenize(src string) []Token

Tokenize scans CSS without panicking on malformed UTF-8 or unterminated constructs.

type Value

type Value struct {
	Length   Length
	Color    Color
	Number   float64
	Keyword  string
	Families []string
	Shadows  []Shadow
}

Jump to

Keyboard shortcuts

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