Documentation ¶
Overview ¶
Package css provides functionality for CSS styling.
CSS properties are plentyful and some of them are complicated. This package trys to shield clients from the cumbersome handling of CSS properties resulting of (1) the textual nature of CSS properties and (2) the complicated semantics of computing style attributes for a given node.
Status ¶
This is a very first draft. It is unstable and the API will change without notice. Please be patient.
License ¶
Governed by a 3-Clause BSD license. License file may be found in the root folder of this module.
Copyright © 2017–2022 Norbert Pillmayer <norbert@pillmayer.com>
Index ¶
- Constants
- func GetCascadedProperty(node *styledtree.StyNode, key string) (style.Property, error)
- func GetLocalProperty(pmap *style.PropertyMap, key string) style.Property
- func GetProperty(node *styledtree.StyNode, key string) (style.Property, error)
- type DMatchExpr
- type DMatcher
- type DimenPatterns
- type DimenT
- type DisplayMode
- func (disp DisplayMode) Contains(d DisplayMode) bool
- func (disp DisplayMode) FullString() string
- func (disp DisplayMode) Inner() DisplayMode
- func (disp DisplayMode) IsBlockLevel() bool
- func (disp DisplayMode) Outer() DisplayMode
- func (disp DisplayMode) Overlaps(d DisplayMode) bool
- func (disp *DisplayMode) Set(d DisplayMode)
- func (i DisplayMode) String() string
- func (disp DisplayMode) Symbol() string
- type PMatchExpr
- type PMatcher
- type PosDir
- type PositionOffset
- type PositionPatterns
- type PositionT
Constants ¶
const ( // Flags for content dependent dimensions DimenContentMax uint32 = 0x0010 DimenContentMin uint32 = 0x0020 DimenContentFit uint32 = 0x0030 )
Variables ¶
This section is empty.
Functions ¶
func GetCascadedProperty ¶
GetCascadedProperty gets the value of a property. The search cascades to parent property maps, if available.
Clients will usually call GetProperty(…) instead as this will respect CSS semantics for inherited properties.
The call to GetCascadedProperty will flag an error if the style property isn't found (which should not happen, as every property should be included in the 'user-agent' default style properties).
func GetLocalProperty ¶
func GetLocalProperty(pmap *style.PropertyMap, key string) style.Property
GetLocalProperty returns a style property value, if it is set locally for a styled node's property map. No cascading is performed.
func GetProperty ¶
GetProperty gets the value of a property. If the property is not set locally on the style node and the property is inheritable, he search cascades to parent property maps, if available.
The call to GetProperty will flag an error if the style property isn't found (which should not happen, as every property should be included in the 'user-agent' default style properties).
Types ¶
type DMatchExpr ¶
type DMatchExpr[T any] struct { // contains filtered or unexported fields }
func DimenPattern ¶
func DimenPattern[T any](d DimenT) *DMatchExpr[T]
func (*DMatchExpr[T]) Const ¶
func (m *DMatchExpr[T]) Const(x T) T
func (*DMatchExpr[T]) OneOf ¶
func (m *DMatchExpr[T]) OneOf(patterns DimenPatterns[T]) T
func (*DMatchExpr[T]) With ¶
func (m *DMatchExpr[T]) With(du *dimen.DU) *DMatchExpr[T]
type DMatcher ¶
type DMatcher struct {
// contains filtered or unexported fields
}
func (*DMatcher) Percentage ¶
type DimenPatterns ¶
type DimenPatterns[T any] struct { Unset T Auto T Inherit T Initial T Just T Default T }
type DimenPatterns[T any] map[*MatchExpr[T]]T
type DimenT ¶
type DimenT struct {
// contains filtered or unexported fields
}
DimenT is an option type for CSS dimensions.
func DimenOption ¶
DimenOption returns an optional dimension type from a property string. It will never return an error, even with illegal input, but instead will then return an unset dimension.
func ParseDimen ¶
ParseDimen parses a string to return an optional dimension. Syntax is CSS Unit. Valid dimensions are
15px 80% -33rem
func Percentage ¶
func Percentage(n Percent) DimenT
Percentage creates a CSS dimension with a %-relative value.
func (DimenT) IsAbsolute ¶
IsAbsolute returns true if d represents a valid absolute dimension.
func (DimenT) IsRelative ¶
IsRelative returns true if d represents a valid relative dimension (`%`, `em`, etc.).
func (DimenT) UnitString ¶
UnitString returns 'sp' (scaled points) for non-relative dimensions and a string denoting the defined unit for relative dimensions.
type DisplayMode ¶
type DisplayMode uint16
DisplayMode is a type for CSS property "display".
const ( NoMode DisplayMode = iota // unset or error condition DisplayNone DisplayMode = 0x0001 // CSS outer display = none BlockMode DisplayMode = 0x0002 // CSS block context (inner or outer) InlineMode DisplayMode = 0x0004 // CSS inline context FlowRootMode DisplayMode = 0x0010 // CSS flow-root display property ListItemMode DisplayMode = 0x0020 // CSS list-item display FlexMode DisplayMode = 0x0040 // CSS inner display = flex GridMode DisplayMode = 0x0080 // CSS inner display = grid TableMode DisplayMode = 0x0100 // CSS table display property (inner or outer) InnerBlockMode DisplayMode = 0x0200 // CSS inner block mode (inline-block) InnerInlineMode DisplayMode = 0x0400 // CSS inner inline mode (paragraphs) )
Flags for box context and display mode (outer and inner).
func ParseDisplay ¶
func ParseDisplay(display string) (DisplayMode, error)
ParseDisplay returns mode flags from a display property string (outer and inner).
func (DisplayMode) Contains ¶
func (disp DisplayMode) Contains(d DisplayMode) bool
Contains checks if a display mode contains a given atomic mode. Returns false for d = NoMode.
func (DisplayMode) FullString ¶
func (disp DisplayMode) FullString() string
FullString returns all atomic modes set in a display mode.
func (DisplayMode) IsBlockLevel ¶
func (disp DisplayMode) IsBlockLevel() bool
IsBlockLevel return true if it has outer display level of BlockMode.
A block-level element is defined as (from the spec): Block-level elements are those elements of the source document that are formatted visually as blocks (e.g., paragraphs). The following values of the 'display' property make an element block-level: 'block', 'list-item', and 'table'.
func (DisplayMode) Overlaps ¶
func (disp DisplayMode) Overlaps(d DisplayMode) bool
Overlaps returns true if a given display mode shares at least one atomic mode flag with disp (excluding NoMode).
func (*DisplayMode) Set ¶
func (disp *DisplayMode) Set(d DisplayMode)
Set sets a given atomic mode within this display mode.
func (DisplayMode) String ¶
func (i DisplayMode) String() string
func (DisplayMode) Symbol ¶
func (disp DisplayMode) Symbol() string
Symbol returns a Unicode symbol for a mode.
type PMatchExpr ¶
type PMatchExpr[T any] struct { // contains filtered or unexported fields }
PMatchExpr is part of pattern matching for PositionT types and intended to be instantiated using `PosPattern()` only.
func PositionPattern ¶
func PositionPattern[T any](p PositionT) *PMatchExpr[T]
func (*PMatchExpr[T]) Const ¶
func (m *PMatchExpr[T]) Const(x T) T
func (*PMatchExpr[T]) OneOf ¶
func (m *PMatchExpr[T]) OneOf(patterns PositionPatterns[T]) T
func (*PMatchExpr[T]) With ¶
func (m *PMatchExpr[T]) With(o *[]PositionOffset) *PMatchExpr[T]
type PMatcher ¶
type PMatcher struct {
// contains filtered or unexported fields
}
func (*PMatcher) Absolute ¶
func (m *PMatcher) Absolute(o *[]PositionOffset) *PMatcher
func (*PMatcher) Fixed ¶
func (m *PMatcher) Fixed(o *[]PositionOffset) *PMatcher
func (*PMatcher) Relative ¶
func (m *PMatcher) Relative(o *[]PositionOffset) *PMatcher
type PositionOffset ¶
func NormalizeOffsets ¶
func NormalizeOffsets(offsets []PositionOffset) []PositionOffset
NormalizeOffsets normalizes offset properties (Top, Right, Bottom, Left) into a 4-way slice, ordered by PDir. Invalid PDir-s are silently dropped.
func ZeroOffsets ¶
func ZeroOffsets() []PositionOffset
ZeroOffsets returns (Top, Right, Bottom, Left) = (0, 0, 0, 0)
type PositionPatterns ¶
type PositionPatterns[T any] struct { Unset T Static T Absolute T Relative T Fixed T Default T }
type PositionT ¶
type PositionT struct {
// contains filtered or unexported fields
}
PositionT is an option type for CSS positions.
func Absolute ¶
func Absolute(offsets []PositionOffset) PositionT
Absolute creates a CSS position of value `absolute`, given optional offsets. offsets may be provied partially or none at all.
func Fixed ¶
func Fixed(offsets []PositionOffset) PositionT
Fixed creates a CSS position of value `fixed`, given optional offsets. offsets may be provied partially or none at all.
func Position ¶
Position returns an optional position type from a property string. It will never return an error, even with illegal input, but instead will then return an unset position.
func Relative ¶
func Relative(offsets []PositionOffset) PositionT
Relative creates a CSS position of value `relative`, given optional offsets. offsets may be provied partially or none at all.
func (PositionT) IsAbsolute ¶
IsAbsolute returns true if d represents a valid absolute position.
func (PositionT) IsRelative ¶
IsRelative returns true if p represents a valid relative position.