Documentation
¶
Overview ¶
Package tw compiles Tailwind CSS v4 style utility classes, such as "flex items-center gap-2 rounded-md bg-blue-500 hover:bg-blue-600", into scene styles. It reproduces Tailwind's default theme scales and naming for the properties the GPUI style protocol carries; it is not a CSS engine. Classes that would need a property the protocol lacks fail to compile rather than being ignored.
Index ¶
Constants ¶
const RootFontSize = 16
RootFontSize is the rem size, in logical pixels, that GPUI uses by default. Lengths stay in rems where the protocol accepts them; font sizes, border widths, corner radii and shadows are pixel values and are converted with it.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Classes ¶
type Classes struct {
// contains filtered or unexported fields
}
Classes is a compiled class list: a style and the partial refinement GPUI applies while the element is hovered. Both accessors return copies.
func MustCompile ¶
MustCompile is Compile for class lists known at build time; it panics on error.
func (*Classes) Apply ¶
Apply sets a snapshot builder's style, hover refinement and conditional refinements.
func (*Classes) Conditions ¶
func (c *Classes) Conditions() []*scene.ConditionalStyle
Conditions returns the refinements for breakpoint and dark: utilities, in the order GPUI applies them, or nil when the list has none.
type Compiler ¶
type Compiler struct {
// contains filtered or unexported fields
}
Compiler compiles class lists against one theme. It is safe for concurrent use and caches compiled lists.
func New ¶
New copies the theme into a compiler, rejecting values the GPUI style protocol cannot carry.
type Theme ¶
type Theme struct {
// Spacing is one step of the numeric scale, in rems: p-4 is 4 * Spacing.
Spacing float32
// Colors serve bg-*, text-* and border-*.
Colors map[string]*scene.Color
// FontSizes are rems, for text-*.
FontSizes map[string]float32
// FontWeights are in [100, 900], for font-*.
FontWeights map[string]uint32
// FontFamilies are single family names, for font-*. The default theme has
// none, because Tailwind's stacks name fonts GPUI cannot select by name.
FontFamilies map[string]string
// Radii are rems, for rounded-*.
Radii map[string]float32
// Containers are rems, for w-*, min-w-* and max-w-*.
Containers map[string]float32
// Shadows serve shadow-*; offsets, blur and spread are pixels.
Shadows map[string][]*scene.Shadow
// Breakpoints are rems, for variants such as md: and max-md:. Media
// queries compare the window's width, with 16px rems.
Breakpoints map[string]float32
}
Theme holds the scales that utilities resolve names against, mirroring Tailwind's theme variables. Keys are the class suffixes: Colors["red-500"] serves bg-red-500, FontSizes["sm"] serves text-sm. The empty key is the bare utility, as Radii[""] for rounded and Shadows[""] for shadow. New copies the theme, so later changes to these maps do not affect a compiler.