UNPKG

@ceereals/vue-pdf

Version:

Vue PDF - Create PDF documents using Vue components

148 lines (147 loc) 4.35 kB
import { defineComponent as m, useSlots as p, computed as _, createElementBlock as b, openBlock as w, createCommentVNode as h, unref as c, renderSlot as v, createTextVNode as S, toDisplayString as D } from "vue"; import { u as P } from "../index-Bq3KRt_g.js"; import { C as G, h as I, k as j, c as U, D as O, E as W, G as z, I as A, b as H, l as J, L as K, N as M, n as Q, P as X, a as Y, i as Z, j as ee, m as oe, R as re, S as te, e as ae, g as ne, T as se, d as le, V as ie, f as ce } from "../index-Bq3KRt_g.js"; const y = Symbol.for("root"), g = ["src"], B = /* @__PURE__ */ m({ __name: "PDFViewer", props: { showToolbar: { type: Boolean, default: !0 }, enableProvideBridge: { type: Boolean, default: !0 }, queryParams: {} }, setup(u, { expose: d }) { const a = u, f = p(), { url: l, execute: s, root: o } = P( () => f.default().filter((r) => r.type !== Symbol.for("v-cmt"))[0], { enableProvideBridge: a.enableProvideBridge } ); d({ execute: s, [y]: o }); const n = _(() => { if (!l.value) return ""; const r = new URLSearchParams(); a.showToolbar !== void 0 && r.append("toolbar", String(+a.showToolbar)), a.queryParams && Object.entries(a.queryParams).forEach(([t, e]) => { r.append(t, String(e)); }); const i = r.toString(); return `${l.value}#${i}`; }); return (r, i) => (w(), b("iframe", { src: n.value, frameborder: "0" }, null, 8, g)); } }), k = ["href", "download"], q = /* @__PURE__ */ m({ __name: "PDFDownloadLink", props: { fileName: { default: "document.pdf" }, label: { default: "Download" } }, emits: ["click"], setup(u, { expose: d, emit: a }) { const f = u, l = a, s = p(); if (!s.default) throw new Error("PDFDownloadLink requires a default slot"); const { url: o, blob: n, isLoading: r } = P( () => s.default().filter((e) => e.type !== Symbol.for("v-cmt"))[0] ?? (() => { throw new Error("PDFDownloadLink requires a default slot"); })() ), i = () => { window.navigator.msSaveBlob && window.navigator.msSaveBlob(n.value, f.fileName); }, t = (e) => { i(), l("click", e); }; return d({ blob: n, isLoading: r, url: o }), (e, E) => c(o) ? (w(), b("a", { key: 0, href: c(o), download: e.fileName, onClick: t }, [ v(e.$slots, "label", { blob: c(n) }, () => [ S(D(e.label), 1) ]) ], 8, k)) : h("", !0); } }), T = ["href"], x = /* @__PURE__ */ m({ __name: "PDFPrint", props: { label: { default: "Print" } }, emits: ["click"], setup(u, { expose: d, emit: a }) { const f = u, l = a, s = p(); if (!s.default) throw new Error("PDFPrint requires a default slot"); const { url: o, blob: n, isLoading: r } = P( () => s.default().filter((t) => t.type !== Symbol.for("v-cmt"))[0] ?? (() => { throw new Error("PDFPrint requires a default slot"); })() ), i = (t) => { if (!o.value) return; t.preventDefault(); const e = window.open(o.value, "_blank"); e?.addEventListener( "load", () => { e.focus(), e.print(); }, { once: !0 } ), l("click", t); }; return d({ blob: n, isLoading: r, url: o }), (t, e) => c(o) ? (w(), b("a", { key: 0, href: c(o), onClick: i }, [ v(t.$slots, "label", { blob: c(n) }, () => [ S(D(f.label), 1) ]) ], 8, T)) : h("", !0); } }), C = () => { throw new Error("renderToFile is not available in the browser"); }, $ = () => { throw new Error("renderToBuffer is not available in the browser"); }, N = () => { throw new Error("renderToStream is not available in the browser"); }; export { G as Canvas, I as Circle, j as ClipPath, U as Defs, O as Document, W as Ellipse, z as G, A as Image, H as Line, J as LinearGradient, K as Link, M as Note, q as PDFDownloadLink, x as PDFPrint, Q as PDFSuspense, B as PDFViewer, X as Page, Y as Path, Z as Polygon, ee as Polyline, oe as RadialGradient, re as Rect, te as Stop, ae as Svg, ne as SvgText, se as Text, le as Tspan, ie as View, ce as fontStore, $ as renderToBuffer, C as renderToFile, N as renderToStream, P as usePdf };