UNPKG

vue-data-ui

Version:

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

59 lines (58 loc) 1.59 kB
import { d as e } from "./dom-to-png-BNHsLwF7.js"; async function j({ domElement: t, fileName: l, scale: i = 2, options: F = {} }) { if (!t) return Promise.reject("No domElement provided"); const m = typeof navigator < "u" && /^((?!chrome|android).)*safari/i.test(navigator.userAgent); let g; try { g = (await import("jspdf")).default; } catch { return Promise.reject("jspdf is not installed. Run npm install jspdf"); } const a = { width: 595.28, height: 841.89 }; if (m) try { await e({ container: t, scale: i }), await e({ container: t, scale: i }), await e({ container: t, scale: i }), await e({ container: t, scale: i }); } catch { } const s = await e({ container: t, scale: i }); return await new Promise((c, P) => { const n = new window.Image(); n.onload = function() { const o = n.naturalWidth, h = n.naturalHeight; let f = a.width, w = a.width / o * h; const r = new g("", "pt", "a4"); let p = 0, d = h; const u = o / a.width * a.height; if (d < u) r.addImage( s, "PNG", 0, 0, f, w, "", "FAST" ); else for (; d > 0; ) r.addImage( s, "PNG", 0, p, f, w, "", "FAST" ), d -= u, p -= a.height, d > 0 && r.addPage(); r.save(`${l}.pdf`), c(); }, n.onerror = (o) => P("Failed to load image for PDF: " + o), n.src = s; }); } export { j as default };