Takumi

Reference

Paint options, tree methods, and serialized field formats.

Entry points

APIResult
paint(node, options?)A Promise<PaintTree> using a shared painter
new Painter()A painter with its own registered fonts
painter.paint(node, options?)A Promise<PaintTree> using that painter
painter.registerFont(font)Registers a font before painting
painter.free()Releases the painter's WebAssembly memory

node accepts JSX, an HTML string, or a takumi node tree.

Paint options

OptionTypeEffect
width, heightnumberCanvas size in device pixels; omitted dimensions follow content
devicePixelRationumberDevice pixels per CSS pixel; default 1
fontsFontLoader[]Fonts registered before layout
imagesImagesInputImages keyed by the referenced src
cssCssInput | readonly CssInput[]Stylesheets applied before layout
fontFamiliesstring[]Fallback family chain for this call
langstringDefault BCP-47 language tag on the root

PaintTree

MemberValue
width, heightCanvas size in device pixels
fontsFont instances referenced by run fontIndex
rootRoot PaintNode
[...tree]Nodes in paint order, parents before children
textRuns(){ run, node } pairs in paint order
find(id)First node whose source.id matches, or undefined

PaintNode

FieldValue
source?Input path, ID, tag name, and class name; absent for an anonymous box
x, y, width, heightCanvas origin and border-box size
contentBoxRect inset by border and padding, in border-box space
transform?Absolute matrix for a rotated, scaled, or skewed box
matrixGetter: transform, or translation by x and y
opacityGroup opacity from 0 to 1
blendMode?, isolateGroup blend mode and isolation
clip?Rounded padding-box clip with x and y axis flags
background?Color, clip mode, and bottom-to-top image layers
border?, shadows?, outline?Box decorations
image?Replaced image source and placement after object fit and position
inlineBackgrounds?Rounded inline-span rectangles
textShadows?, textRuns, textAlign?Text drawing and alignment data
unresolvedEffects?CSS text for filter, backdrop filter, mask image, and clip path
childrenChild boxes in paint order

PaintTextRun

FieldValue
textRun text
x, yBaseline start in border-box space
widthAdvance
ascent, descentTypographic distances from the baseline
top, bottomGetters: y - ascent and y + descent
fontIndex, fontFont table index and resolved font object
fontSize, lineHeight, letterSpacingUsed text metrics in device pixels
color, opacityFill color and span opacity
transform?Additional text-fit matrix
glyphsGlyph IDs and offsets from run origin
decorations?, stroke?Text decoration rectangles and text stroke
textByteRange, spanId?UTF-8 source byte range and inline span ID

PaintFont records family?, faceIndex, weight, style, width, variations, syntheticBoldWidth?, and syntheticObliqueAngle?. The optional family is absent when the registry cannot name the face.

Value formats

TypeFormat
Rgba[r, g, b, a], each byte from 0 to 255
Matrix[a, b, c, d, e, f]
PaintRect{ x, y, width, height }
RadiiFour [x, y] pairs: top-left, top-right, bottom-right, bottom-left
Border sidesArrays ordered top, right, bottom, left
PaintBackgroundLayerfill, tiles (xs, ys, width, height), blendMode
PaintFillDiscriminated linear, radial, conic, or image fill
PaintShadowoffsetX, offsetY, blur, spread, color

Last updated on

On this page