0.12.2 • Published 3 years ago

dom-to-svg v0.12.2

Weekly downloads
96
License
MIT
Repository
github
Last release
3 years ago

DOM to SVG

npm CI status license: MIT semantic-release

Library to convert a given HTML DOM node into an accessible SVG "screenshot".

Demo 📸

Try out the SVG Screenshots Chrome extension which uses this library to allow you to take SVG screenshots of any webpage. You can find the source code at github.com/felixfbecker/svg-screenshots.

Usage

import { documentToSVG, elementToSVG, inlineResources, formatXML } from 'dom-to-svg'

// Capture the whole document
const svgDocument = documentToSVG(document)

// Capture specific element
const svgDocument = elementToSVG(document.querySelector('#my-element'))

// Inline external resources (fonts, images, etc) as data: URIs
await inlineResources(svgDocument.documentElement)

// Get SVG string
const svgString = new XMLSerializer().serializeToString(svgDocument)

The output can be used as-is as valid SVG or easily passed to other packages to pretty-print or compress.

Features

  • Does NOT rely on <foreignObject> - SVGs will work in design tools like Illustrator, Figma etc.
  • Maintains DOM accessibility tree by annotating SVG with correct ARIA attributes.
  • Maintains interactive links.
  • Maintains text to allow copying to clipboard.
  • Can inline external resources like images, fonts, etc to make SVG self-contained.
  • Maintains CSS stacking order of elements.
  • Outputs debug attributes on SVG to trace elements back to their DOM nodes.

Caveats

  • Designed to run in the browser. Using JSDOM on the server will likely not work, but it can easily run inside Puppeteer.
0.12.2

3 years ago

0.12.1

3 years ago

0.12.0

3 years ago

0.11.8

3 years ago

0.11.9

3 years ago

0.11.7

3 years ago

0.11.4

3 years ago

0.11.5

3 years ago

0.11.6

3 years ago

0.11.3

3 years ago

0.11.2

3 years ago

0.11.1

3 years ago

0.11.0

3 years ago

0.10.0

3 years ago

0.9.5

3 years ago

0.9.4

3 years ago

0.9.3

3 years ago

0.9.2

3 years ago

0.9.1

3 years ago

0.9.0

3 years ago

0.8.5

3 years ago

0.8.4

3 years ago

0.8.3

3 years ago

0.8.2

3 years ago

0.8.1

3 years ago

0.7.2

3 years ago

0.8.0

3 years ago

0.7.1

3 years ago

0.7.0

3 years ago

0.6.0

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.3

3 years ago

0.0.2

4 years ago

0.0.1

4 years ago