Takumi

The measure() API

Measure node dimensions and text runs with Renderer.measure() before rendering an image.

measure() returns a node's laid-out size without rendering it. Use it to fit a headline into a fixed width, or to place a badge against the measured box.

Measure with the native renderer
import {  } from "takumi-js/node";
import {  } from "takumi-js/helpers/jsx";

const  = new ();
const { ,  } = await (< ="text-xl">I'm a text node</>);

const { width,  } = await .(, {  }); 
const width: number

The measured width of the node.

Returned fields

measure() resolves to a MeasuredNode.

Prop

Type

Description

width?number

Laid-out width

height?number

Laid-out height

transform?[number, number, number, number, number, number]

Transformation matrix that places the box on the page

children?MeasuredNode[]

Measured child nodes

runs?MeasuredTextRun[]

Text runs the node lays out

Every length is a device pixel. A 20px box measures 40 under a devicePixelRatio of 2.

Text runs

A node that lays out text reports one MeasuredTextRun per shaped run.

Prop

Type

Description

text?string

The run's text

x?number

Left edge, measured from the content box of the node that owns the run

y?number

Top edge, measured from the content box of the node that owns the run

width?number

Run width

height?number

Run height

Coordinates

transform is absolute. It places the box on the page, and every node carries one, including the boxes takumi generates to lay out inline content.

A run's x and y are not absolute. They start at the content box of the node that owns the run, so add that node's padding and border to place a run on the page.

Last updated on

On this page