Node
Native N-API renderer for Node.js, Bun, and Deno.
takumi-js/node re-exports @takumi-rs/core — the native binding built per-platform via N-API.
It loads only on runtimes with native module support (Node.js, Bun, Deno). For Workers, Vite, or
the browser use takumi-js/wasm instead.
The native renderer is the fastest path and the only one that supports loadFontSync, font fallback, animation pipelines, and persistent image preloading at full throughput. Use it directly when you want to manage one renderer across many requests instead of paying construction cost per call.
Classes
Renderer
import { } from "takumi-js/node";
import { , } from "takumi-js/helpers";
const = new ({ : true });
.(new ());
const = await .(({ : [("Hello")] }), {
: 1200,
: 630,
: "png",
});Methods on the Renderer instance:
| Method | Returns | Purpose |
|---|---|---|
loadFontSync(font) | void | Block on font registration. Safe at startup, not inside a handler. |
loadFont(font, signal?) | Promise<number> | Register one font without blocking. |
loadFonts(fonts, signal?) | Promise<number> | Register many fonts concurrently. |
render(node, options?, signal?) | Promise<Buffer> | Render a node tree to a static image buffer. |
measure(node, options?, signal?) | Promise<MeasuredNode> | Run layout only. See the Measure guide. |
renderAnimation(options, signal?) | Promise<Buffer> | Sample a scene timeline at fps and encode WebP / APNG / GIF. |
encodeFrames(frames, options, signal?) | Promise<Buffer> | Encode a precomputed frame sequence (each frame has its own node). |
putPersistentImage(source, signal?) | Promise<void> | Add an image to the in-memory store referenced by src URL. |
clearImageStore() | void | Drop every persistent image. Useful on memory-constrained hosts. |
Options
ConstructRendererOptions
Prop
Type
Description
persistentImages?arrayThe images that needs to be preloaded into the renderer.
fonts?arrayThe fonts being used.
loadDefaultFonts?unionWhether to load the default fonts.
If fonts are provided, this will be false by default.
RenderOptions
Prop
Type
Description
width?numberThe width of the image. If not provided, the width will be automatically calculated based on the content.
height?numberThe height of the image. If not provided, the height will be automatically calculated based on the content.
format?unionThe format of the image.
quality?numberThe quality of JPEG format (0-100).
drawDebugBorder?unionWhether to draw debug borders.
fetchedResources?arrayThe fetched resources to use.
stylesheets?arrayCSS stylesheets to apply before rendering.
keyframes?unionStructured keyframes to register alongside stylesheets.
devicePixelRatio?numberThe device pixel ratio.
timeMs?numberThe animation timeline time in milliseconds.
dithering?unionThe output dithering algorithm.
RenderAnimationOptions
Prop
Type
Description
scenesarrayThe scenes to render sequentially.
drawDebugBorder?unionWhether to draw debug borders around layout elements.
widthnumberThe width of each frame in pixels.
heightnumberThe height of each frame in pixels.
format?unionThe output animation format (WebP, APNG, or GIF).
quality?numberThe quality of WebP format (0-100). Ignored for APNG and GIF.
fpsnumberFrames per second for timeline sampling.
fetchedResources?arrayThe fetched resources to use.
stylesheets?arrayCSS stylesheets to apply before rendering.
devicePixelRatio?numberThe device pixel ratio.
EncodeFramesOptions
Prop
Type
Description
drawDebugBorder?unionWhether to draw debug borders around layout elements.
widthnumberThe width of each frame in pixels.
heightnumberThe height of each frame in pixels.
format?unionThe output animation format (WebP, APNG, or GIF).
quality?numberThe quality of WebP format (0-100). Ignored for APNG and GIF.
fetchedResources?arrayThe fetched resources to use.
stylesheets?arrayCSS stylesheets to apply before rendering.
devicePixelRatio?numberThe device pixel ratio.
Supporting types
Font / FontDetails
Prop
Type
Description
name?stringThe name of the font. If not provided, the name in the font file will be used.
dataByteBufThe font data.
weight?numberThe weight of the font. If not provided, the weight in the font file will be used.
style?unionThe style of the font. If not provided, the style in the font file will be used.
Font is FontDetails | Uint8Array | ArrayBuffer | Buffer. Passing raw bytes works when the font file contains its own metadata.
MeasuredNode
Prop
Type
Description
widthnumberThe measured width of the node.
heightnumberThe measured height of the node.
transformtupleThe transformation matrix of the node.
childrenarrayThe children of the node.
runsarrayThe text runs within the node.
ImageSource
Prop
Type
Description
srcstringThe source URL of the image.
dataunionThe raw image data (Uint8Array or ArrayBuffer).
AnimationFrameSource / AnimationSceneSource
Prop
Type
Description
nodeNodeThe node tree to render for this frame.
durationMsnumberThe duration of this frame in milliseconds.
Prop
Type
Description
nodeNodeThe node tree to render for this scene.
durationMsnumberThe duration of this scene in milliseconds.
Last updated on