parse pathdata and get bounding box
npm install svg-pathdata-getbboxA arcto parameters largeArc, sweep – also with the final point:
A 5 10 45 1 0 40 20
`
can also be expressed like so
`
A 5 10 45 10 40 20
`
or even worse
`
A 5 10 45 1040 20
`
... pretty hard to unravel – I don't blame anyone.
This script combines multiple non-iterative approaches to find extreme points for:
* Q quadratic béziers
* C cubic béziers
* A arc commands
Normalization doesn't convert quadratics or arcs to cubics.
All in all, this method should be quite fast and accurate.
Usage - browser
Load script e.g via cdn
`
`
Or minified version (7KB minified / 4KB gzipped)
`
`
$3
`
let d =
;
let bb = getBBoxFromD(d);
console.log(bb);
`
$3
This method actually queries all svg geometry elements within a target and sums up all bbox values to get the total bbox.
It also converts shapes like , etc to elements to calculate extremes based on pathData. This method can't retrieve bbox values from elements!
`
let bb = getBBoxFromEl(svg)
`
Usage - node.js
`
npm install svg-pathdata-getbbox
`
`
var pathDataBB = require("svg-pathdata-getbbox");
var { getBBoxFromEl, getBBoxFromD, getPathDataBBox } = pathDataBB;
var d =
;
var bb = getBBoxFromD(d);
console.log(bb)
``