Documentation
¶
Overview ¶
Package css is the CSS intermediate representation the stylesheet is built in: typed values, declarations, rules, custom properties and the two at-rules the design system uses.
It exists so that the application's stylesheet is a Go value rather than a file somebody edits. ui/style compiles a component's class list into rules here; design writes its tokens here as custom properties; the result renders once at startup and is served as one artifact. Nothing parses CSS, because nothing in this repository authors any.
Derived from github.com/septagon-oss/styleengine (Apache-2.0); see NOTICE. The parser, the minifier, the diagnostics and the @layer/@supports/@font-face families were left behind with the repository: this package emits what one design system needs and reads nothing.
Index ¶
- type Declaration
- type Keyframes
- type Rule
- type Sheet
- func (s *Sheet) AddRule(r Rule) *Sheet
- func (s *Sheet) CSS() string
- func (s *Sheet) Keyframes(name string, fn func(*Keyframes)) *Sheet
- func (s *Sheet) Media(query string, fn func(*Sheet)) *Sheet
- func (s *Sheet) Merge(other *Sheet) *Sheet
- func (s *Sheet) Rules() []Rule
- func (s *Sheet) Select(selector string, decls ...Declaration) *Sheet
- func (s *Sheet) Var(name, value string) *Sheet
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Declaration ¶
Declaration is one property and its value.
func (Declaration) CSS ¶
func (d Declaration) CSS() string
CSS renders the declaration without its terminator.
type Keyframes ¶
type Keyframes struct {
// contains filtered or unexported fields
}
Keyframes accumulates the stops of one animation.
type Rule ¶
type Rule struct {
Selector string
Decls []Declaration
}
Rule is a selector and what it declares. The selector is a string rather than a parsed type: every selector in this repository is built by ui/style from a class name it just compiled, so there is nothing to normalise and nothing a caller could get wrong that a parser would catch.
type Sheet ¶
type Sheet struct {
// contains filtered or unexported fields
}
Sheet is an ordered, deduplicated collection of rules and at-rules. It is built by one goroutine and then rendered; it carries no lock, because the application builds its stylesheet once.
func (*Sheet) AddRule ¶
AddRule adds a rule, merging into an existing one with the same selector so that two components contributing to one selector do not produce two blocks.
func (*Sheet) CSS ¶
CSS renders the whole sheet: rules first, at-rules after, each separated by a blank line. The output is deterministic, which is what makes the stylesheet something a test can assert about.
func (*Sheet) Keyframes ¶
Keyframes declares an animation. Stops render in offset order, so "from" and "0%" are the same place whichever a caller wrote.
func (*Sheet) Rules ¶
Rules is every top-level rule, in insertion order. It is read by the test that proves every class a component declares resolves to something.
type Value ¶
type Value interface {
CSS() string
// contains filtered or unexported methods
}
Value is the right-hand side of a declaration. A Value renders itself, so a var() reference cannot be confused with the text of one.
func Literal ¶
Literal is a value emitted verbatim. Every caller in this repository passes a token value or a string it built itself; there is no untrusted input here, because nobody outside the binary contributes CSS.
func VarRef ¶
VarRef references a custom property. The leading "--" is added here, so the name a theme registers and the name a rule reads are the same string.
It panics on a name or a fallback that could break out of the var() expression. This is a wiring mistake in Go source, like httpx.Permission's: the alternative is a stylesheet that renders once, silently malformed.