UNPKG

vue-data-ui

Version:

A user-empowering data visualization Vue 3 components library for eloquent data storytelling

34 lines (33 loc) 1.58 kB
import { d as n } from "./dom-to-png-BNHsLwF7.js"; async function u({ domElement: t, fileName: c, format: f = "png", scale: i = 2, base64: a = !1, img: g = !1 }) { if (!t) return Promise.reject("No element provided"); const h = typeof navigator < "u" && /^((?!chrome|android).)*safari/i.test(navigator.userAgent); if (await new Promise((r) => setTimeout(r, 200)), h) try { await n({ container: t, scale: i }), await n({ container: t, scale: i }), await n({ container: t, scale: i }), await n({ container: t, scale: i }), a && (await n({ container: t, scale: i, base64: a }), await n({ container: t, scale: i, base64: a }), await n({ container: t, scale: i, base64: a }), await n({ container: t, scale: i, base64: a })); } catch { } if (a && g) try { const r = await n({ container: t, scale: i }).then((e) => e), o = await n({ container: t, scale: i, base64: a }).then((e) => e); return { imageUri: r, base64: o }; } catch (r) { console.error("Error generating image information for the chart", r); } else if (a) try { return n({ container: t, scale: i, base64: a }).then((r) => r); } catch (r) { console.error("Error generating the base64 string of the chart", r); } else try { const r = await n({ container: t, scale: i }), o = document.createElement("a"); o.href = r, o.download = `${c}.${f}`, document.body.appendChild(o), o.click(), document.body.removeChild(o); } catch (r) { throw console.error("Error generating image:", r), r; } } export { u as default };