Search
Loading...
Skip to content

Using Strokes

Add outlines around shapes, text, and graphics to enhance visual definition and create decorative effects.

5 mins
estimated time
Download
StackBlitz
GitHub

Strokes add visual outlines that define block boundaries. You can customize their color, width, line style (solid, dashed, dotted), position relative to the block edge, and corner treatment. CE.SDK provides programmatic APIs for complete stroke management in headless workflows.

This guide covers how to apply and manage strokes programmatically using the block API.

Checking Stroke Support#

Before applying strokes programmatically, verify the block supports them using supportsStroke(). Not all block types have stroke capabilities.

// Check if the block supports strokes before applying
const canHaveStroke = engine.block.supportsStroke(graphic);
console.log('Block supports strokes:', canHaveStroke);

Enabling Strokes#

Enable strokes on a block using setStrokeEnabled(). You can check the current state with isStrokeEnabled().

// Enable stroke on the block
engine.block.setStrokeEnabled(graphic, true);
// Verify stroke is enabled
const strokeEnabled = engine.block.isStrokeEnabled(graphic);
console.log('Stroke enabled:', strokeEnabled);

Setting Stroke Color#

Control stroke color using setStrokeColor() with an RGBA color object. Color values range from 0.0 to 1.0. Retrieve the current color with getStrokeColor().

// Set stroke color to blue (RGBA values from 0.0 to 1.0)
engine.block.setStrokeColor(graphic, { r: 0.2, g: 0.4, b: 0.9, a: 1.0 });
// Read the current stroke color
const strokeColor = engine.block.getStrokeColor(graphic);
console.log('Stroke color:', strokeColor);

Setting Stroke Width#

Set stroke thickness in design units using setStrokeWidth(). Larger values create more prominent outlines. Get the current width with getStrokeWidth().

// Set stroke width in design units
engine.block.setStrokeWidth(graphic, 8);
// Read the current stroke width
const strokeWidth = engine.block.getStrokeWidth(graphic);
console.log('Stroke width:', strokeWidth);

Stroke Styles#

Control the line pattern using setStrokeStyle(). Available styles include:

  • Solid - Continuous line
  • Dashed - Square-ended dashes with gaps
  • DashedRound - Round-ended dashes with gaps
  • Dotted - Circular dots
  • LongDashed - Longer square-ended dashes
  • LongDashedRound - Longer round-ended dashes
// Set stroke style to dashed
// Available styles: 'Solid', 'Dashed', 'DashedRound', 'Dotted',
// 'LongDashed', 'LongDashedRound'
engine.block.setStrokeStyle(graphic, 'Dashed');
// Read the current stroke style
const strokeStyle = engine.block.getStrokeStyle(graphic);
console.log('Stroke style:', strokeStyle);

Stroke Position#

Control where the stroke renders relative to the block edge using setStrokePosition():

  • Center - Stroke centered on the edge (default)
  • Inner - Stroke rendered inside the block boundary
  • Outer - Stroke rendered outside the block boundary

Position affects how strokes interact with adjacent elements and overall layout dimensions. Inner strokes stay within the block bounds, while outer strokes extend beyond them.

// Set stroke position relative to block edge
// Available positions: 'Center', 'Inner', 'Outer'
engine.block.setStrokePosition(graphic, 'Outer');
// Read the current stroke position
const strokePosition = engine.block.getStrokePosition(graphic);
console.log('Stroke position:', strokePosition);

Stroke Corner Geometry#

Control how stroke corners are rendered using setStrokeCornerGeometry(). This is particularly visible on rectangular shapes:

  • Miter - Sharp pointed corners (default)
  • Round - Smoothly curved corners
  • Bevel - Flat cut corners
// Set stroke corner geometry
// Available geometries: 'Miter', 'Round', 'Bevel'
engine.block.setStrokeCornerGeometry(graphic, 'Round');
// Read the current corner geometry
const cornerGeometry = engine.block.getStrokeCornerGeometry(graphic);
console.log('Corner geometry:', cornerGeometry);

Troubleshooting#

If strokes don’t appear as expected, check these common issues:

  • Stroke not visible - Verify stroke is enabled with isStrokeEnabled() and width is greater than 0
  • Stroke color appears wrong - Ensure color values are in the 0.0-1.0 range, not 0-255
  • Stroke affects layout unexpectedly - Use Inner position to keep strokes within bounds, or Outer if you want strokes to extend beyond the block
  • Block doesn’t support strokes - Use supportsStroke() to verify capability before applying stroke properties

API Reference#

MethodDescription
block.supportsStroke(block)Check if a block supports strokes
block.setStrokeEnabled(block, enabled)Enable or disable stroke on a block
block.isStrokeEnabled(block)Check if stroke is enabled
block.setStrokeColor(block, color)Set stroke color (RGBA, values 0.0-1.0)
block.getStrokeColor(block)Get current stroke color
block.setStrokeWidth(block, width)Set stroke thickness in design units
block.getStrokeWidth(block)Get current stroke width
block.setStrokeStyle(block, style)Set line pattern (Solid, Dashed, Dotted, etc.)
block.getStrokeStyle(block)Get current stroke style
block.setStrokePosition(block, position)Set stroke position (Center, Inner, Outer)
block.getStrokePosition(block)Get current stroke position
block.setStrokeCornerGeometry(block, type)Set corner rendering (Miter, Round, Bevel)
block.getStrokeCornerGeometry(block)Get current corner geometry