Painting Colors
These functions tell you the exact color a CSS class paints right now: a background, a text color, a stroke, or a semantic color like error. Use them when something you draw in JavaScript has to match.
Color and Token Fills
Every function takes an optional { el }: the id
or element whose nearest .screen
supplies the paint. Each returns a
Fill; the shape and how the reading works
are on
Paint API
Paint API
TRMNLPaint: read the exact colors and patterns CSS paints right now, from JavaScript
TRMNLPaint is the framework's JavaScript API for its paint: colors, border lines, and text styles. Ask it for any framework color and it returns what CSS would actually paint right now, with the device and the active theme already applied. Use it wherever JavaScript draws: charts, canvases, or your own rendering.
. The token names match the
Colors
Colors
Complete palette definition: grayscale, chromatic hues, and semantic roles
The Colors system defines the complete palette for the framework: grayscale, chromatic hues, and semantic roles (primary, success, error, warning). Use these tokens with bg--, text--, and other utilities. See Background and Text Color for usage examples.
palette.
-
bg(token, { el }): a background token (bg--<token>), e.g.'black','gray-40','red-55','error'. On solid modes you get a color-only Fill; on dither modes, a pattern Fill. -
text(token, { el }): a text token (text--<token>). Framework text is painted by clipping a background to the letters, so the Fill carries both the color and the image. -
stroke(token, { el }): a stroke token (text-stroke--<token>), returned as a concretergbin a color-only Fill. -
semantic(slot, { el }): one of the framework's named color roles:canvas,surface,text-primary,text-secondary,text-inverse,backdrop,border-strong,border-muted,fill-strong,fill-muted,fill-soft,stroke-contrast, oricon. Patterns come through intact. -
textColor(token, { el }): the single color of a named text utility ('default','muted', ...), for SVG or canvas text. When the text is painted with a pattern, you get the pattern's ink, the color the letters actually read as.
// Resolve a token for the current screen mode/theme.
var fill = TRMNLPaint.bg("red-55", { el: "my-chart" });
// => solid mode: { color: "rgb(204, 0, 0)", image: null, url: null, size: null }
// => dither mode: { color: "rgb(255,255,255)", image: "url(...)", url: "data:...", size: 16 }
// The default text color as one plain color, for SVG or canvas text.
var textColor = TRMNLPaint.textColor("default", { el: "my-chart" });
Painting Fills
A resolved Fill is painted back with one call. Wrap the painting in
watch() so it re-runs when the screen's mode,
dark or theme classes change; see
Paint API
Paint API
TRMNLPaint: read the exact colors and patterns CSS paints right now, from JavaScript
TRMNLPaint is the framework's JavaScript API for its paint: colors, border lines, and text styles. Ask it for any framework color and it returns what CSS would actually paint right now, with the device and the active theme already applied. Use it wherever JavaScript draws: charts, canvases, or your own rendering.
.
-
apply(node, fill): paints a node's background from a Fill, layering the color under the pattern exactly as the framework itself does.
var swatch = document.getElementById("legend-swatch");
TRMNLPaint.watch(swatch, function () {
// Solid on 4-bit+ panels, a composited dither tile on 1- and 2-bit screens.
TRMNLPaint.apply(swatch, TRMNLPaint.bg("gray-30", { el: swatch }));
});