/** * Minified by jsDelivr using Terser v5.15.1. * Original file: /npm/d3-svg-to-png@0.3.1/index.js * * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files */ function inlineStyles(e, t) { const n = window.getComputedStyle(e); for (const e of n) t.style[e] = n[e]; for (let n = 0; n < e.children.length; n++) inlineStyles(e.children[n], t.children[n]); } function copyToCanvas({ source: e, target: t, scale: n, format: o, quality: l }) { let a = new XMLSerializer().serializeToString(t), i = document.createElement("canvas"), r = e.getBoundingClientRect(); (i.width = r.width * n), (i.height = r.height * n), (i.style.width = r.width), (i.style.height = r.height); let c = i.getContext("2d"); c.scale(n, n); let d = document.createElement("img"); return ( d.setAttribute("src", "data:image/svg+xml;base64," + btoa(unescape(encodeURIComponent(a)))), new Promise((e) => { d.onload = () => { c.drawImage(d, 0, 0), e(i.toDataURL(`image/${"jpg" === o ? "jpeg" : o}`, l)); }; }) ); } function downloadImage({ file: e, name: t, format: n }) { let o = document.createElement("a"); (o.download = `${t}.${n}`), (o.href = e), document.body.appendChild(o), o.click(), document.body.removeChild(o); } async function svgToPng( e, t, { scale: n = 1, format: o = "png", quality: l = 0.92, download: a = !0, ignore: i = null, cssinline: r = 1, background: c = null, } = {} ) { e = e instanceof Element ? e : document.querySelector(e); const d = document.createElementNS("http://www.w3.org/2000/svg", "svg"); d.innerHTML = e.innerHTML; for (const t of e.attributes) d.setAttribute(t.name, t.value); if ((1 === r && inlineStyles(e, d), c && (d.style.background = c), null != i)) { const e = d.querySelectorAll(i); [].forEach.call(e, (e) => e.parentNode.removeChild(e)); } const s = await copyToCanvas({ source: e, target: d, scale: n, format: o, quality: l }); return a && downloadImage({ file: s, name: t, format: o }), s; } window.svgToPng = svgToPng; //# sourceMappingURL=/sm/14eea0125d103380ac8a8d5d87aec7122e2b707361f72c63dfeb2e62361d38e4.map