Documentation
¶
Overview ¶
Package color owns colour for the tinywasm framework: how a colour is written, how it is read, and how two of them relate.
It carries no build tag, so it crosses into WASM. That is deliberate: a colour is a value the frontend genuinely handles, and the package holds nothing else — no CSS, no PDF, no files.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Color ¶
type Color string
Color is a CSS-style hex string: "#RRGGBB" or "#RGB", and supports alpha as "#RRGGBBAA" or "#RGBA", as well as "transparent".
It stays a string on purpose. Colours are authored as hex everywhere in this ecosystem — in a design token, in a document theme, in a stylesheet — so a struct would force a conversion at every boundary and buy nothing.
func Mix ¶ added in v0.1.1
Mix blends two colors in the Oklab color space. pct is the interpolation weight of b from 0.0 (all a) to 1.0 (all b).
func (Color) Luminance ¶ added in v0.1.1
Luminance returns the WCAG relative luminance of the color. If the color is invalid, it returns 0.0.
func (Color) Over ¶ added in v0.1.1
Over composes a translucent color (this color `c`) over an opaque background color `backdrop`. If the backdrop has alpha, it still blends them using the standard Porter-Duff Over operator.
func (Color) RGB ¶ added in v0.1.1
RGB decomposes the colour into its three 0-255 channels, discarding any alpha channel if present.
The empty colour is not an error: it resolves to black, which is what an unset field should paint. Anything else that is neither "#RGB", "#RGBA", "#RRGGBB", "#RRGGBBAA" nor "transparent" is a defect in the caller and is reported.