Skip to content
Document Authoring DA  API Docs v1.16.0
npmGitHub

Shape

Shape:

Represents a shape element within a document.

Shape is one of the inline element types that can appear within text content, alongside text and Image elements. A shape has a preset geometry (ShapePreset), a display size, an optional fill and outline, and an optional text body. You obtain Shape objects by iterating through inline elements and checking their type discriminator.

For sizing, a shape exposes only Shape.extent and Shape.setExtent, like Image; rotation and position are not exposed.

type: "shape"

Type discriminator for inline elements.

Always has the value 'shape'. Use this property to narrow the inline element type and access shape-specific methods.

extent(): Extent

Gets the current display dimensions of the shape, in points

Extent

An Extent object containing the shape’s width and height

if (inline.type === 'shape') {
const extent = inline.extent();
console.log(`Shape: ${extent.width} x ${extent.height}`);
}

setExtent(extent): void

Sets the display dimensions of the shape, in points (1 point = 1/72 inch).

Partial<Extent>

Partial extent object with width and/or height to set

void

When specifying only one dimension, the other remains unchanged (aspect ratio is not maintained automatically).

shape.setExtent({ width: 120, height: 80 });

geometry(): ShapeGeometry

Gets the shape’s geometry as a ShapeGeometry.

ShapeGeometry

const geometry = shape.geometry();
if (geometry.type === 'preset') {
console.log('preset:', geometry.preset);
}

setGeometry(geometry): void

Sets the shape’s geometry.

ShapeGeometry

A ShapeGeometry (common shapes are listed first in ShapePreset).

void

shape.setGeometry({ type: 'preset', preset: 'star5' });

fill(): ShapeFill | null

Gets the shape’s fill: null if the shape has no fill, otherwise a ShapeFill whose color is the fill color (or null for a transparent interior).

ShapeFill | null

const fill = shape.fill();
console.log('fill color:', fill?.color ?? 'none');

setFill(fill): void

Sets the shape’s fill. Pass null or { color: null } for no fill (a transparent interior), or a ShapeFill with a color to fill it.

ShapeFill | null

void

shape.setFill({ color: '#ff0000' });
shape.setFill(null); // no fill

outline(): ShapeOutline | null

Gets the shape’s outline: null if the shape has no outline, otherwise a ShapeOutline. The outline is drawn only when both its color and width are non-null.

ShapeOutline | null

const outline = shape.outline();
console.log('outline width:', outline?.width ?? 'none');

setOutline(outline): void

Sets the shape’s outline. Pass null — or a ShapeOutline with a null color or width — for no outline, or a ShapeOutline with both a color and a width to draw it.

ShapeOutline | null

void

shape.setOutline({ color: '#000000', width: 1.5 });
shape.setOutline(null); // no outline

text(): BlockLevelContainer | null

Gets the shape’s text body as a BlockLevelContainer, or null if the shape has no text body.

BlockLevelContainer | null

Use the returned container to read and modify the paragraphs and tables inside the shape, the same way you would with a table cell or footnote.

This reflects the shape’s existing text body and does not create one: a shape with no text body returns null. Use Shape.ensureText to add a body to a shape that lacks one.

const body = shape.text();
if (body !== null) {
// read or modify the paragraphs inside the shape
}

ensureText(): BlockLevelContainer

Gets the shape’s text body, creating an empty one if the shape has no text body yet, and returns it as a BlockLevelContainer.

BlockLevelContainer

Unlike Shape.text, this never returns null: a shape that had no body gets a new one seeded with a single empty paragraph, ready for content. A shape that already has a body is returned unchanged.

const body = shape.ensureText();
body.blocklevels()[0].asTextView().setText('Label');