svg-path-bbox

Compute bounding boxes of SVG paths.

Usage no npm install needed!

<script type="module">
  import svgPathBbox from 'https://cdn.skypack.dev/svg-path-bbox';
</script>

README

📦 svg-path-bbox

NPM version License NodeJS versions

SVG paths bounding box calculator.

Status

Tests Coverage status

Install

npm install svg-path-bbox

Documentation

Usage

> const svgPathBbox = require("svg-path-bbox")
> svgPathBbox("M5 10l2 3z")
[ 5, 10, 7, 13 ]
> svgPathBbox("M5 10c3 0 3 3 0 3z")
[ 5, 10, 7.25, 13 ]

Returned bounding box is an array made up like viewBox SVG attributes [x0, y0, x1, y1] of unrounded values:

Command line

$ svg-path-bbox "M5 10c3 0 3 3 0 3z"
5 10 7.25 13

$ svg-path-bbox "M5 10c3 0 3 3 0 3z" "M2 8m5 5z"
5 10 7.25 13
2 8 7 13

Reference

# svgPathBbox(d) ⇒ Array

Computes the bounding box of SVG path following the SVG 1.1 specification.

  • d (string) SVG path.

Thanks to