css

package
v0.0.0-...-ada8b72 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: BSD-3-Clause Imports: 11 Imported by: 0

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

View Source
const (

	// Flags for content dependent dimensions
	DimenContentMax uint32 = 0x0010
	DimenContentMin uint32 = 0x0020
	DimenContentFit uint32 = 0x0030
)

Variables

This section is empty.

Functions

func GetCascadedProperty

func GetCascadedProperty(node *styledtree.StyNode, key string) (style.Property, error)

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

func GetProperty(node *styledtree.StyNode, key string) (style.Property, error)

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) IsKind

func (m *DMatcher) IsKind(d DimenT) *DMatcher

func (*DMatcher) Just

func (m *DMatcher) Just(du *dimen.DU) *DMatcher

func (*DMatcher) Percentage

func (m *DMatcher) Percentage(p *Percent) *DMatcher

func (*DMatcher) Unset

func (m *DMatcher) Unset() *DMatcher

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 Auto

func Auto() DimenT

func DimenOption

func DimenOption(p style.Property) DimenT

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 Inherit

func Inherit() DimenT

func Initial

func Initial() DimenT

func JustDimen

func JustDimen(x dimen.DU) DimenT

JustDimen creates a CSS dimension with a fixed value of x.

func ParseDimen

func ParseDimen(s string) (DimenT, error)

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

func (d DimenT) IsAbsolute() bool

IsAbsolute returns true if d represents a valid absolute dimension.

func (DimenT) IsNone

func (d DimenT) IsNone() bool

IsNone returns true if d is unset.

func (DimenT) IsPercent

func (d DimenT) IsPercent() bool

IsPercent returns true if d represents a percentage dimension (`%`).

func (DimenT) IsRelative

func (d DimenT) IsRelative() bool

IsRelative returns true if d represents a valid relative dimension (`%`, `em`, etc.).

func (DimenT) Match

func (d DimenT) Match() *DMatcher

func (DimenT) UnitString

func (o DimenT) UnitString() string

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) Inner

func (disp DisplayMode) Inner() DisplayMode

Inner returns inner 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) Outer

func (disp DisplayMode) Outer() DisplayMode

Outer returns outer mode

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) IsKind

func (m *PMatcher) IsKind(p PositionT) *PMatcher

func (*PMatcher) Relative

func (m *PMatcher) Relative(o *[]PositionOffset) *PMatcher

type PosDir

type PosDir uint8

PosDir is either Top, Right, Bottom or Left.

const (
	Top PosDir = iota
	Right
	Bottom
	Left
)

type PositionOffset

type PositionOffset struct {
	Dim DimenT
	Dir PosDir
}

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

func Position(p style.Property) PositionT

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 Static

func Static() PositionT

Static creates a CSS position of value `static`.

func (PositionT) IsAbsolute

func (p PositionT) IsAbsolute() bool

IsAbsolute returns true if d represents a valid absolute position.

func (PositionT) IsFixed

func (p PositionT) IsFixed() bool

IsFixed returns true if d represents a fixed position.

func (PositionT) IsRelative

func (p PositionT) IsRelative() bool

IsRelative returns true if p represents a valid relative position.

func (PositionT) IsUnset

func (p PositionT) IsUnset() bool

IsUnset returns true if p is unset.

func (PositionT) Match

func (p PositionT) Match() *PMatcher

Jump to

Keyboard shortcuts

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