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

Node / Canvas · reference

Canvas stroke — every StrokeOptions field

Current Apexify.js 6.0.0 documentation for Canvas stroke — every StrokeOptions field.

apexify.jsRuntime: nodeCURRENTSince 6.0.0

Set stroke on CanvasConfig with await painter.createCanvas({ … }). Apexify strokes the same logical rectangle as your clipped canvas (x, y, width, height) — optionally inset/outset, dashed, blurred, gradient-coloured, or limited to specific edges.

Naming caveat: stroke.borderPosition chooses which edges get ink (top, left, comma-separated lists, …). canvas.borderPosition controls which corners use canvas.borderRadius on the clip — different meaning. Outline corner rounding uses stroke.roundedCorners + stroke.borderRadius.

Type StrokeOptions ships from apexify.js / apexify.js/types.


Minimal example

SOURCEtypescript
typescript
Studio
import { ApexPainter } from "apexify.js"; const painter = new ApexPainter({ type: "buffer" }); await painter.createCanvas({  width: 400,  height: 240,  colorBg: "#e2e8f0",  borderRadius: 16,  stroke: {    color: "#334155",    width: 3,    opacity: 1,    style: "solid",    borderRadius: 16,    roundedCorners: "all",  },});

Field reference (StrokeOptions)

FieldTypeDefaultWhat it does
colorstring"#000"Stroke colour when gradient is absent.
gradientgradient—Linear / radial / conic stroke paint (overrides color).
widthnumber2lineWidth in CSS pixels.
positionnumber0Expands or contracts the stroked rectangle before width is applied: the engine builds a rect position pixels outward on each side (negative pulls the outline inward).
blurnumber0Gaussian blur on the stroke pass — soft halo around the outline (independent from canvas.blur on fills).
opacitynumber1Alpha multiplier for the entire stroke pass.
borderRadiusnumber | "circular"0Corner rounding for the stroked path (**match canvas.borderRadius for aligned rims).
roundedCornersborderPosition"all"Which corners receive borderRadius (same vocabulary as canvas borderPosition).
borderPositionborderPosition"all"Edge mask: which sides actually draw ("top", "bottom", "left", "right", or comma-separated lists like "top, bottom"). Corner keywords ("top-left", …) expand to two adjacent edges. "all" = full rectangle.
styleunion below"solid"Dash / faux-CSS border personality (see next section).

Line styles (style)

styleAppearance
solidContinuous line (lineDash cleared).
dashedLong dashes (width * 3 gap width * 2).
dottedRound caps with width-spaced dots.
grooveDouble-pass: darker stroke then lighter stroke (simulates inset). Gradients reuse both passes.
ridgeDouble-pass: light then dark (simulates raised edge).
doubleTwo parallel strokes each width / 2 thick.

Groove / ridge / double ignore simple lineDash — they paint two strokes with computed colours derived from color when no gradient is set.


Partial borders (borderPosition on stroke)

Unlike roundedCorners (corner rounding mask), stroke.borderPosition selects which edges receive ink:

SOURCEtypescript
typescript
Studio
stroke: {  color: "#6366f1",  width: 4,  borderPosition: "top, bottom",  borderRadius: 12,}

Corner tokens (top-left, …) map to two sides internally. Use "all" for a full frame.


Combining with canvas corners

  • canvas.borderRadius clips fills.
  • stroke.borderRadius + stroke.roundedCorners shape the outline.

For a rounded rectangle outline that tracks the card, keep stroke.borderRadius aligned with canvas.borderRadius unless you intentionally want a mismatched rim.


Next steps