color

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 2 Imported by: 0

README

color

Color for the tinywasm framework: parsing, conversion and contrast. WASM-safe, no build tags.

Documentation

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

func Contrast added in v0.1.1

func Contrast(a, b Color) float64

Contrast computes the WCAG contrast ratio between two colors: de 1 (identicos) a 21 (negro/blanco).

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

func Mix(a, b Color, pct float64) Color

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

func (c Color) Luminance() float64

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

func (c Color) Over(backdrop Color) Color

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

func (c Color) RGB() (r, g, b int, err error)

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.

func (Color) RGBA added in v0.1.1

func (c Color) RGBA() (r, g, b, a int, err error)

RGBA decomposes the colour into its four 0-255 channels (red, green, blue, alpha).

The empty colour is not an error: it resolves to opaque black (0, 0, 0, 255). The "transparent" keyword is also supported and resolves to alpha 0 (0, 0, 0, 0).

Jump to

Keyboard shortcuts

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