Skip to content

Options

Every option accepted by outlineSvg, outlinePathData and the CLI.

optiondefaultdescription
strokeWidthfrom the SVGoverride the width for every stroked element
linecapfrom the SVGoverride stroke-linecap
linejoinfrom the SVGoverride stroke-linejoin
miterLimitfrom the SVGoverride stroke-miterlimit
toleranceviewBox / 2400max deviation of flattened curves, in user units
curvestruefit the result with cubic Béziers instead of emitting polygons
fitTolerance2 × tolerancemax deviation of the fitted curves from the exact polygon
cornerAngle30turn angle (degrees) above which a vertex stays a sharp corner
fillstruealso include shapes that already have a fill (--no-fills)
fillcurrentColorfill written on the output path
precision3decimal places in the output
outerWindingcwwinding of outer contours (cw on screen is what fonts expect)
onWarningnonecalled for every unsupported feature that changes the result
strictfalsethrow instead of converting when the input has such a feature

The CLI has the same options in kebab-case: --stroke-width, --fit-tolerance, --no-curves, --no-fills and so on. onWarning maps to warnings on stderr and strict to --strict.

Warnings

Some things in an SVG can't be reproduced by a single filled path, and the converter would rather tell you than fail quietly. When the input uses one of them, onWarning gets called with a { code, message, element } object and the conversion carries on without that feature. Nothing is reported for input that only uses supported features, so a handler that logs is safe to leave on in a build.

ts
import { outlineSvg } from 'unstroke';

const filled = outlineSvg(svgSource, {
  onWarning: (w) => console.warn(`${w.code}: ${w.message}`),
});
codewhat it means
unsupported-elementa <text>, <image> or <foreignObject> was skipped
dasharraystroke-dasharray is ignored, the stroke is outlined as a solid line
markersmarker-start, marker-mid or marker-end is ignored
clip-pathclip-path or mask is ignored, the whole shape is emitted
filterfilter is ignored
vector-effectvector-effect="non-scaling-stroke" is ignored, the width scales with the transform
opacityopacity, stroke-opacity or fill-opacity below 1 is ignored, the result is opaque
paintmore than one colour, or a gradient or pattern, is merged into one fill colour

Each distinct warning is reported once per document. With strict: true the same input throws an UnsupportedSvgError instead, and its warnings array holds everything that was found. That's the mode I'd use in a build pipeline, where a silently dashed line is worse than a failed build.