css

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Declaration

type Declaration struct {
	Property string
	Value    Value
}

Declaration is one property and its value.

func Decl

func Decl(property string, value Value) Declaration

Decl builds a Declaration.

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.

func (*Keyframes) At

func (k *Keyframes) At(offset string, decls ...Declaration) *Keyframes

At adds one stop: "from", "to", or a percentage.

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.

func (Rule) CSS

func (r Rule) CSS() string

CSS renders the rule, custom properties first and alphabetically so that a theme block diffs stably, everything else in the order it was declared.

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 NewSheet

func NewSheet() *Sheet

NewSheet returns an empty Sheet.

func (*Sheet) AddRule

func (s *Sheet) AddRule(r Rule) *Sheet

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

func (s *Sheet) CSS() string

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

func (s *Sheet) Keyframes(name string, fn func(*Keyframes)) *Sheet

Keyframes declares an animation. Stops render in offset order, so "from" and "0%" are the same place whichever a caller wrote.

func (*Sheet) Media

func (s *Sheet) Media(query string, fn func(*Sheet)) *Sheet

Media nests a @media block.

func (*Sheet) Merge

func (s *Sheet) Merge(other *Sheet) *Sheet

Merge appends another sheet's rules and at-rules into this one.

func (*Sheet) Rules

func (s *Sheet) Rules() []Rule

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.

func (*Sheet) Select

func (s *Sheet) Select(selector string, decls ...Declaration) *Sheet

Select declares a rule on an arbitrary selector, which is how a theme block ([data-theme="dark"]) declares the same properties as :root.

func (*Sheet) Var

func (s *Sheet) Var(name, value string) *Sheet

Var declares a custom property in :root. Re-declaring one replaces it.

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

func Literal(s string) Value

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

func VarRef(name, fallback string) Value

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.

Jump to

Keyboard shortcuts

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