style

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package style says how a diagram looks, at three levels.

A Theme is the first: a handful of colors and measures every diagram is drawn from, as Pele's --pele-* variables are. A diagram's parts name its colors by Token (Surface, Border, Series(2)…) rather than by value, so a change of theme only redraws.

Overrides are the second: a Style for each role of the parts of diagrams, such as "flowchart.node" or "sequence.actor", that sets some of what the theme gives. Over them lies the style the diagram's author set in its text, with style and classDef lines and a palette, which a scene's items carry apart from the diagram's own. A Look that is ThemeOnly leaves it out, for a host that draws with its design tokens alone.

The third, drawing a part some way of one's own, belongs to the backends, as each draws with tools of its own; see the svg package.

What changes where things are — the font, the sizes of text — is not style: it is given to layout, and a change of it lays the diagram out again.

Index

Constants

This section is empty.

Variables

View Source
var (
	None       = Paint{/* contains filtered or unexported fields */}
	Bg         = Paint{/* contains filtered or unexported fields */}
	Fg         = Paint{/* contains filtered or unexported fields */}
	Muted      = Paint{/* contains filtered or unexported fields */}
	Line       = Paint{/* contains filtered or unexported fields */}
	Surface    = Paint{/* contains filtered or unexported fields */}
	SurfaceAlt = Paint{/* contains filtered or unexported fields */}
	Border     = Paint{/* contains filtered or unexported fields */}
	Accent     = Paint{/* contains filtered or unexported fields */}
	Critical   = Paint{/* contains filtered or unexported fields */}
)

The colors of the theme, and None, which draws nothing.

View Source
var Solid = Dash{nil, true}

Solid is a line with no gaps.

Functions

This section is empty.

Types

type Cap

type Cap uint8

A Cap is how the ends of a stroked line are drawn, as SVG's stroke-linecap: the ends of a line and of each of its dashes. The zero Cap is unset, and takes what is under it; a line nothing sets one for ends flat, as SVG's do.

const (
	CapButt   Cap = iota + 1 // flat, at the end
	CapRound                 // a half circle about the end
	CapSquare                // flat, half the line's width past the end
)

func (Cap) Set

func (c Cap) Set() bool

Set reports whether the cap was set.

func (Cap) String

func (c Cap) String() string

String is the cap's name in SVG and CSS, "butt", "round" or "square", or "" when unset.

type Color

type Color struct{ R, G, B, A uint8 }

A Color is a color in sRGB with straight alpha.

func Hex

func Hex(s string) Color

Hex is the color #rgb, #rgba, #rrggbb or #rrggbbaa writes; it panics on anything else, so it is for colors written in code. ParseColor reads them from text.

func ParseColor

func ParseColor(s string) (Color, bool)

ParseColor reads a CSS color: a hex color, rgb() or rgba(), hsl() or hsla(), a named color or transparent, with the white space of CSS about it, its names in either case of their ASCII letters. A hue may be in degrees, gradians, radians or turns, and a channel none, which is 0. It reports false for anything else, such as currentColor or var().

func RGB

func RGB(r, g, b uint8) Color

RGB is an opaque color.

func (Color) String

func (c Color) String() string

String writes the color as #rrggbb, or #rrggbbaa when it is not opaque.

type Dash

type Dash struct {
	// contains filtered or unexported fields
}

A Dash is the pattern of a line's dashes and gaps, or a solid line, or unset.

func Dashes

func Dashes(lengths ...float64) Dash

Dashes is a line of dashes and gaps of the lengths given in turn.

func (Dash) Pattern

func (d Dash) Pattern() []float64

Pattern is the lengths of the dashes and gaps; none for a solid line.

func (Dash) Set

func (d Dash) Set() bool

Set reports whether the dash was set.

type Join

type Join uint8

A Join is how a stroked line turns its corners, as SVG's stroke-linejoin. The zero Join is unset, and takes what is under it; a line nothing sets one for turns its corners mitred, as SVG's do.

const (
	// JoinMiter turns a corner in a point where the line's sides meet, or bevelled where
	// SVG's miter limit of 4 would: where the point is more than four times half the line's
	// width from the corner.
	JoinMiter Join = iota + 1
	JoinRound      // an arc about the corner
	JoinBevel      // straight across, from one side's end to the other's
)

func (Join) Set

func (j Join) Set() bool

Set reports whether the join was set.

func (Join) String

func (j Join) String() string

String is the join's name in SVG and CSS, "miter", "round" or "bevel", or "" when unset.

type Look

type Look struct {
	Theme     *Theme // nil is Default
	Overrides Overrides
	// ThemeOnly draws a scene with the theme and the overrides alone, leaving out all that
	// the diagram's author set for painting: the style the author gave each part, a
	// palette's colors among it, the colors picked for what lies on a fill the author set,
	// and the casings drawn about the lines inside such a fill. A host sets it to keep a
	// look its design tokens restrict. It moves nothing: the size, weight and slant of text
	// the author set stay, as the layout measured them.
	ThemeOnly bool
}

A Look is a theme and the overrides on it: all of style a backend is given.

func (*Look) Cascade

func (l *Look) Cascade(role string, own, author Style) Style

Cascade is the style of a part of a role: the theme's measures under the diagram's own style for the part, under the overrides for its role, under the style its author gave it in the diagram's text. Text is written in Fg unless something sets another paint. Where the look is ThemeOnly, the author's style is left out, and so are the part's Ground and TextGround, which a diagram sets only on a fill the author set.

func (*Look) Draws added in v0.5.0

func (l *Look) Draws(role string) bool

Draws reports whether a backend draws the parts of a role: all but the casings, the roles ending in ".casing", where the look is ThemeOnly, since a diagram draws a casing only about a line inside a fill the author set.

func (*Look) Resolve

func (l *Look) Resolve(role string, own, author Style) Resolved

Resolve settles a part's style in the look.

func (*Look) Shade added in v0.4.0

func (l *Look) Shade(author Style) (Paint, bool)

Shade is what a part painted scene.Shade is filled with, before the opacity a backend lays it at over a fill the author sets: the theme's Bg, or, on a fill the author sets that ink picks a color on, the other of Fg and Bg, the one that stands out less on the fill, as Pele 1.12 keeps an entity's stripes light on a light fill and dark on a dark one. It reports whether it was picked on a fill. A fill an override sets leaves the shade the theme's Bg, since the backend lays a shade at an opacity only over a fill the author sets. Where the look is ThemeOnly, the shade is the theme's Bg, as for a part its author set no fill on.

func (*Look) ThemeOrDefault

func (l *Look) ThemeOrDefault() *Theme

ThemeOrDefault is the look's theme, or Default when it has none. The default is shared: to change it, change a copy.

type Num

type Num struct {
	// contains filtered or unexported fields
}

A Num is a measure that may be unset, and then takes what is under it.

func N

func N(v float64) Num

N is the measure v.

func (Num) Get

func (n Num) Get() (float64, bool)

Get is the measure, and whether it was set.

func (Num) Or

func (n Num) Or(d float64) float64

Or is the measure, or d when it was not set.

type Overrides

type Overrides map[string]Style

Overrides give styles to the roles of diagrams' parts, as "flowchart.node", by the names of scene.Role.

type Paint

type Paint struct {
	// contains filtered or unexported fields
}

A Paint is what a part is filled, stroked or written with: a color of the theme, a color of its own, or nothing. The zero Paint is unset, and takes what is under it.

func Of

func Of(c Color) Paint

Of paints with a color of its own.

func Series

func Series(n int) Paint

Series is the color of the nth series of a chart, of eight that repeat.

func (Paint) Alpha

func (p Paint) Alpha(a float64) Paint

Alpha is the paint at a part of its opacity.

func (Paint) Base

func (p Paint) Base() Token

Base is the token of the color the paint is laid over, if it is.

func (Paint) Color

func (p Paint) Color(th *Theme) Color

Color is the color the paint draws with in a theme; its alpha is 0 when it draws nothing.

func (Paint) Factor

func (p Paint) Factor() float32

Factor is the part of its opacity the paint is drawn at.

func (Paint) Over

func (p Paint) Over(base Paint) Paint

Over is the paint laid over a color of the theme: an opaque color, the paint's color at its opacity mixed into base's, as CSS's color-mix does in sRGB. It is for what must hide what is under it in the color it would seem to have there: a title's halo over a group.

func (Paint) Own

func (p Paint) Own() Color

Own is the paint's own color, when it is not one of the theme's.

func (Paint) Set

func (p Paint) Set() bool

Set reports whether the paint was set: an unset one takes what is under it.

func (Paint) Token

func (p Paint) Token() Token

Token is the theme's token the paint is, if it is one; Token.Name tells.

func (Paint) Visible

func (p Paint) Visible() bool

Visible reports whether the paint draws: it is set, and not None.

type Resolved

type Resolved struct {
	// Fill and Stroke are at the style's fill and stroke opacities; alpha 0 draws nothing.
	Fill, Stroke, Text Color
	// Marker is the stroke's color without the stroke opacity, which markers are filled
	// with, as Pele fills them in the color of the line alone.
	Marker      Color
	Line        Color // the theme's color of lines, for parts painted solid
	Bg          Color // the theme's background
	Shade       Color // for parts painted shade, as Look.Shade picks it
	Hollow      Color // the theme's background, or the ground, for parts painted hollow
	StrokeWidth float64
	Radius      float64
	Dash        []float64 // none for a solid line
	Cap         Cap       // CapButt when nothing set it, as SVG's initial value
	Join        Join      // JoinMiter when nothing set it, as SVG's initial value
	Opacity     float64
	Halo        Color // alpha 0 draws none
	HaloWidth   float64
}

Resolved is a style with its colors and measures settled, ready to draw.

type Style

type Style struct {
	Fill   Paint
	Stroke Paint // outlines and lines, and the markers at their ends
	Text   Paint
	// FillOpacity and StrokeOpacity are the opacities the fill and the stroke are drawn at,
	// from 0 to 1, as SVG's fill-opacity and stroke-opacity: apart from the paints, so that
	// each is laid over what is under it on its own, as CSS cascades them. A fill the author
	// sets over a part the diagram draws at an opacity is drawn at that opacity. They do not
	// reach the part's text, and markers are filled in the stroke's color without its
	// opacity and stroked with it, as Pele draws them.
	FillOpacity   Num
	StrokeOpacity Num
	StrokeWidth   Num
	Radius        Num // of the corners of a box that takes the theme's
	// MaxRadius caps the theme's radius where no level sets one, as a treemap's small boxes
	// are rounded by min(var(--_r), cap) in Pele.
	MaxRadius Num
	Dash      Dash
	Cap       Cap  // of the ends of lines and of their dashes
	Join      Join // of the corners of lines and outlines
	Opacity   Num  // of the whole part
	// Halo is drawn about the letters of the part's text, HaloWidth wide, so that lines
	// under the text stop short of it: the title of a group an edge runs through.
	Halo      Paint
	HaloWidth Num
	// OnFill says that the part's text is set on its fill. Where an override or the part's
	// author sets a fill over the diagram's own, and neither sets a color for the text, the
	// text is drawn in the theme's Fg or Bg, whichever stands out more against that fill, as
	// Pele's ink picks a color for a label on a fill a style sets. A diagram sets it on the
	// parts whose labels Pele draws so.
	OnFill bool
	// Ground is the fill under the part where it lies inside a fill its author sets on
	// another part, as an edge inside a group with a fill of its own. Unless an override or
	// the part's author sets them, the part's stroke and text are drawn in the theme's Fg or
	// Bg, whichever stands out more against the ground, as Pele draws an edge or a label
	// inside one fill in the color of that fill's labels, and what it paints Hollow is filled
	// with the ground, as Pele's hollowOn fills a marker. A diagram sets it only on a fill ink
	// can pick a color on.
	Ground Paint
	// TextGround is the fill under the part's text alone, where the text lies inside a fill
	// its author sets on another part and the rest of the part keeps its own colors, as the
	// name under a sequence diagram's figure in a box. Unless an override or the part's
	// author sets one, the text is drawn in the theme's Fg or Bg, whichever stands out more
	// against it. A diagram sets it only on a fill ink can pick a color on.
	TextGround Paint
}

A Style is how a part is painted. What it leaves unset comes from under it.

func (Style) Over

func (s Style) Over(base Style) Style

Over is s laid over base: what s sets, and what base sets where s does not.

type Theme

type Theme struct {
	Bg         Color // behind the diagram, and behind labels on lines
	Fg         Color // text
	Muted      Color // secondary text, as the titles of groups
	Line       Color // edges and other lines
	Surface    Color // the inside of shapes
	SurfaceAlt Color // the inside of groups, and of shapes set apart
	Border     Color // the outlines of shapes
	Accent     Color // what a diagram marks out
	Critical   Color // what a diagram marks as critical
	Series     [8]Color

	Radius      float64 // of the corners of rounded boxes
	StrokeWidth float64 // of outlines and lines
}

A Theme is the colors and measures diagrams are drawn with.

func Default

func Default() *Theme

Default is Pele's light theme.

func Kohu

func Kohu() *Theme

Kohu is limu's light theme, in the colors of limu kohu, the red limu of Hawaiʻi, in a tide pool: neutrals of the pool's teal, the limu's red for the accent, and amber for what is critical, so that it is not taken for the accent. The series are colors of algae.

func KohuDark

func KohuDark() *Theme

KohuDark is limu's dark theme, Kohu's colors in the dark of the pool.

func (*Theme) Color

func (th *Theme) Color(t Token) Color

Color is the theme's color for a token.

type Token

type Token uint8

A Token names a color of the theme.

func (Token) Name

func (t Token) Name() string

Name is the token's name, as in the variables the svg package writes: "surface-alt", "series-3". It is empty for a color that is not the theme's.

Jump to

Keyboard shortcuts

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