d3-svg-to-png
Advanced tools
Comparing version 0.1.7 to 0.1.8
33
index.js
@@ -36,7 +36,14 @@ const inlineStyles = target => { | ||
var img = document.createElement('img'); | ||
img.setAttribute('src', 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svgData)))); | ||
img.setAttribute( | ||
'src', | ||
'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svgData))) | ||
); | ||
return new Promise(resolve => { | ||
img.onload = () => { | ||
ctxt.drawImage(img, 0, 0); | ||
const file = canvas.toDataURL(`image/${format}`, (format = 'png'), quality); | ||
const file = canvas.toDataURL( | ||
`image/${format}`, | ||
(format = 'png'), | ||
quality | ||
); | ||
resolve(file); | ||
@@ -55,6 +62,18 @@ }; | ||
module.exports = async (target, name, { scale = 1, format = 'png', quality = 0.92, download = true, ignore = null, cssinline = 1 } = {}) => { | ||
module.exports = async ( | ||
target, | ||
name, | ||
{ | ||
scale = 1, | ||
format = 'png', | ||
quality = 0.92, | ||
download = true, | ||
ignore = null, | ||
cssinline = 1 | ||
} = {} | ||
) => { | ||
const elt = document.querySelector(target); | ||
//Remember all HTML, as we will modify the styles | ||
//Remember all HTML and CSS, as we will modify the styles | ||
const rememberHTML = elt.innerHTML; | ||
var rememberCSS; | ||
@@ -68,3 +87,4 @@ //Remove unwanted elements | ||
//Set all the css styles inline | ||
if(cssinline === 1){ | ||
if (cssinline === 1) { | ||
rememberCSS = elt.style.cssText; | ||
inlineStyles(target, ignore); | ||
@@ -85,2 +105,5 @@ } | ||
elt.innerHTML = rememberHTML; | ||
if (cssinline === 1) { | ||
elt.style.cssText = rememberCSS; | ||
} | ||
return file; | ||
@@ -87,0 +110,0 @@ }) |
{ | ||
"name": "d3-svg-to-png", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"description": "Converts SVG elements to PNG and other image formats while keeping CSS styles", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -0,0 +0,0 @@ # d3-svg-to-png |
@@ -0,0 +0,0 @@ declare module 'd3-svg-to-png' { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
109
6964