Documentation
¶
Overview ¶
Package css parses CSS syntax into Growse-owned rules.
Index ¶
- Constants
- func DecodeString(value string) (string, bool)
- func ResolveResourceURLs(stylesheet *Stylesheet, baseURL *url.URL)
- type AttributeMatcher
- type AttributeSelector
- type Combinator
- type ComponentKind
- type ComponentValue
- type CompoundSelector
- type Declaration
- type ImportRule
- type Keyframe
- type KeyframesRule
- type MediaFeature
- type MediaModifier
- type MediaQuery
- type PseudoClass
- type PseudoClassKind
- type PseudoElementKind
- type Rule
- type RuleKind
- type Selector
- type SelectorKind
- type Stylesheet
- type Value
Constants ¶
const ( // MaxKeyframesRules bounds named keyframe storage per stylesheet. MaxKeyframesRules = 256 // MaxFramesPerKeyframesRule bounds selector blocks in one @keyframes rule. MaxFramesPerKeyframesRule = 256 // MaxDeclarationsPerKeyframe bounds work performed for one sampled frame. MaxDeclarationsPerKeyframe = 64 // MaxOffsetsPerKeyframe bounds comma-separated selectors in one block. MaxOffsetsPerKeyframe = 64 )
Variables ¶
This section is empty.
Functions ¶
func DecodeString ¶
DecodeString decodes one quoted CSS string, including hexadecimal escapes.
func ResolveResourceURLs ¶
func ResolveResourceURLs(stylesheet *Stylesheet, baseURL *url.URL)
ResolveResourceURLs makes supported CSS resource URLs absolute while their stylesheet base URL is still known.
Types ¶
type AttributeMatcher ¶
type AttributeMatcher uint8
AttributeMatcher identifies how an attribute value is compared.
const ( AttributePresent AttributeMatcher = iota AttributeExact AttributeIncludes AttributeDashMatch AttributePrefix AttributeSuffix AttributeSubstring )
type AttributeSelector ¶
type AttributeSelector struct {
Name string
Matcher AttributeMatcher
Value string
}
AttributeSelector is one attribute condition in a compound selector.
type Combinator ¶
type Combinator uint8
Combinator describes the relationship between two adjacent compounds.
const ( CombinatorDescendant Combinator = iota CombinatorChild CombinatorAdjacentSibling CombinatorGeneralSibling )
type ComponentKind ¶
type ComponentKind uint8
ComponentKind identifies a component value token.
const ( ComponentIdentifier ComponentKind = iota ComponentFunction ComponentAtKeyword ComponentHash ComponentString ComponentURL ComponentNumber ComponentPercentage ComponentDimension ComponentWhitespace ComponentDelimiter ComponentBlockStart ComponentBlockEnd ComponentComma ComponentBad )
type ComponentValue ¶
type ComponentValue struct {
Kind ComponentKind
Raw string
}
ComponentValue is one typed token in a declaration value.
type CompoundSelector ¶
type CompoundSelector struct {
Universal bool
Type string
IDs []string
Classes []string
Attributes []AttributeSelector
Pseudos []PseudoClass
Hover bool
PseudoElement PseudoElementKind
}
CompoundSelector is a sequence of simple selectors without a combinator.
type Declaration ¶
Declaration is one CSS property/value pair.
func ParseDeclarations ¶
func ParseDeclarations(value string) ([]Declaration, error)
ParseDeclarations parses the contents of an element's style attribute.
type ImportRule ¶
type ImportRule struct {
URL string
Media []MediaQuery
}
ImportRule references a stylesheet and an optional media query list.
type Keyframe ¶
type Keyframe struct {
Offsets []float64
Declarations []Declaration
}
Keyframe contains normalized offsets and declarations for one keyframe block.
type KeyframesRule ¶
KeyframesRule is one named CSS animation keyframe list.
type MediaFeature ¶
MediaFeature is a media feature name and its optional value.
type MediaModifier ¶
type MediaModifier uint8
MediaModifier changes how one media query is interpreted.
const ( MediaModifierNone MediaModifier = iota MediaModifierNot MediaModifierOnly )
type MediaQuery ¶
type MediaQuery struct {
Modifier MediaModifier
Type string
Features []MediaFeature
}
MediaQuery is one comma-separated media query. Features are combined by and.
type PseudoClass ¶
type PseudoClass struct {
Kind PseudoClassKind
A int
B int
Negation *CompoundSelector
}
PseudoClass stores a pseudo-class and its parsed arguments. Nth expressions use A*n+B, while :not() stores its Level 3 simple-selector argument.
type PseudoClassKind ¶
type PseudoClassKind uint8
PseudoClassKind identifies a supported pseudo-class condition.
const ( PseudoRoot PseudoClassKind = iota PseudoEmpty PseudoFirstChild PseudoLastChild PseudoOnlyChild PseudoFirstOfType PseudoLastOfType PseudoOnlyOfType PseudoNthChild PseudoNthLastChild PseudoNthOfType PseudoNthLastOfType PseudoNot PseudoLink PseudoFocus PseudoEnabled PseudoDisabled PseudoChecked PseudoValid PseudoInvalid )
type PseudoElementKind ¶
type PseudoElementKind uint8
PseudoElementKind identifies generated content attached to an element.
const ( PseudoElementNone PseudoElementKind = iota PseudoElementBefore PseudoElementAfter )
type Rule ¶
type Rule struct {
Kind RuleKind
Selectors []Selector
Declarations []Declaration
Order int
Media [][]MediaQuery
}
Rule associates selectors with declarations.
type Selector ¶
type Selector struct {
Kind SelectorKind
Tag string
Class string
ID string
Hover bool
Compounds []CompoundSelector
Combinators []Combinator
}
Selector is a parsed selector. The legacy fields remain populated for the original four selector forms while Compounds is the canonical AST.
func (Selector) Specificity ¶
Specificity returns the selector's (ID, class, tag) specificity tuple.
type SelectorKind ¶
type SelectorKind uint8
SelectorKind identifies the limited selector forms supported by the MVP.
const ( SelectorTag SelectorKind = iota SelectorClass SelectorID SelectorTagClass SelectorUniversal SelectorCompound )
type Stylesheet ¶
type Stylesheet struct {
Rules []Rule
Imports []ImportRule
Keyframes []KeyframesRule
}
Stylesheet is an ordered collection of CSS rules.
func Parse ¶
func Parse(reader io.Reader) (*Stylesheet, error)
Parse reads a stylesheet. Unsupported selectors and at-rules are ignored.
func (*Stylesheet) Append ¶
func (s *Stylesheet) Append(other *Stylesheet)
Append adds another stylesheet while preserving global source order.
type Value ¶
type Value struct {
Raw string
Components []ComponentValue
}
Value is a declaration value before property-specific computation. Raw preserves the serialized input while Components exposes typed CSS tokens.