Skip to content
Apexify.jsDocs
Apexify.js version v5.4.5

Advanced / Composition · guide

Preset scene components (painter.components)

Current Apexify.js 6.0.0 documentation for Preset scene components (painter.components).

apexify.jsRuntime: nodeCURRENTSince 6.0.0

painter.components exposes small factories. Every toLayers(options) returns ordinary SceneLayer[] that you can spread into renderScene, SceneBuilder.addLayers, or template insertions.

They are static rendering helpers, not DOM widgets. They do not carry accessibility semantics such as alt text, ARIA labels, or reading order. If the generated image is shown in HTML or another accessible UI, provide the appropriate accessible name/description in that surrounding UI.

All built-ins validate finite/positive geometry and relevant resource limits before returning layers.


Common pattern

SOURCEtypescript
typescript
Studio
import { ApexPainter } from "apexify.js"; const painter = new ApexPainter({ type: "buffer" }); const layers = [  ...painter.components.badge.toLayers({    text: "Beta",    x: 24,    y: 24,    paddingX: 10,    paddingY: 6,    radius: 999,    background: "#312e81",    color: "#e0e7ff",    fontSize: 13,  }),  ...painter.components.progressBar.toLayers({    x: 24,    y: 64,    width: 320,    height: 14,    value: 72,    max: 100,    background: "#1e293b",    fill: "#38bdf8",    radius: 6,    showLabel: true,    labelColor: "#e2e8f0",  }),]; const png = await painter.renderScene({  width: 420,  height: 140,  background: { colorBg: "#020617" },  layers,});

Earlier entries paint below later entries.


badge.toLayers

BadgeToLayersOptions: required text, x, y; optional paddingX, paddingY, radius, background, color, fontSize.

The component estimates pill width from text length/font size, enforces non-negative padding/radius and positive font size, and clamps the corner radius to the produced box.


progressBar.toLayers

ProgressBarToLayersOptions: x, y, width, height, value; optional max (default 100), track background, fill, radius, showLabel, labelColor.

  • Width/height and max must be positive.
  • value is clamped into [0, max].
  • The fill never exceeds the declared progress-bar width.
  • Zero progress emits no fill layer.

avatar.toLayers

AvatarToLayersOptions: source (non-empty path/URL string or Buffer), x, y, size, optional borderColor, borderWidth.

The image uses circular clipping. A positive borderWidth with borderColor emits a ring layer behind the clipped image. Invalid/empty sources and border widths larger than the avatar size are rejected.


card.toLayers

CardToLayersOptions: x, y, width, height, optional radius, background, borderColor / borderWidth, title, body, title/body font sizes and colors, padding.

The component emits a rounded panel followed by optional text layers. Padding and border width are validated so a positive content area remains. Text uses the available card width as its wrap bound.


watermark.toLayers

WatermarkToLayersOptions: text, canvasWidth, canvasHeight, optional position (bottom-right, bottom-left, top-right, top-left, center), fontSize, color, margin.

The watermark is canvas-aware: invalid position values are rejected, text must fit the supplied canvas dimensions, and corner margins may not push the estimated watermark outside the canvas. Use it late in the layer array when it should paint on top.


Mixing with arbitrary scene layers

SOURCEtypescript
typescript
Studio
const ui = [  ...painter.components.card.toLayers({    x: 32,    y: 32,    width: 360,    height: 200,    radius: 16,    background: "#0f172a",    borderColor: "#334155",    borderWidth: 1,    title: "Usage",    titleFontSize: 18,    body: "You are at 72% of your quota.",    bodyFontSize: 14,    padding: 16,  }),  ...painter.components.watermark.toLayers({    text: "CONFIDENTIAL",    canvasWidth: 480,    canvasHeight: 280,    position: "center",    fontSize: 36,    color: "#f9731644",  }),]; await painter.renderScene({  width: 480,  height: 280,  background: { colorBg: "#020617" },  layers: ui,});

The option types are exported from apexify.js and the type-only apexify.js/types subpath.


Next steps