path-rite

boundingBox

Get the axis-aligned bounding box of a path.

boundingBox(svgPath: string): { minX: number, minY: number, maxX: number, maxY: number }

svgPath — SVG path d-attribute string.

Returns — An object with minX, minY, maxX, maxY defining the bounding rectangle.

// Get bounds of a triangle
const bbox = pathRite.boundingBox("M 10 20 L 80 5 L 50 90 Z");
// bbox === { minX: 10, minY: 5, maxX: 80, maxY: 90 }