Skip to content

Ft jspdf as peer dep #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -951,3 +951,7 @@ const textContent = createTSpans({
v-html="textContent"
/>
```

## PDF generation

This package requires jspdf as a peer dependency. Please install it in your project if you intend on using the PDF printing feature.
68 changes: 40 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vue-data-ui",
"private": false,
"version": "2.8.1",
"version": "2.8.2-beta.0",
"type": "module",
"description": "A user-empowering data visualization Vue 3 components library for eloquent data storytelling",
"keywords": [
Expand Down Expand Up @@ -92,12 +92,17 @@
"preprod": "node del-dev-dep.cjs && npm run clean && vite build --mode production && node copy-types.cjs && node copy-docs.cjs && node post-build.cjs"
},
"peerDependencies": {
"vue": ">=3.3.0"
"vue": ">=3.3.0",
"jspdf": "^3.0.1"
},
"peerDependenciesMeta": {
"jspdf": {
"optional": true
}
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.2.3",
"cypress": "^14.0.3",
"jspdf": "^3.0.1",
"remove-attr": "^0.0.13",
"sass": "^1.57.1",
"simple-git": "^3.24.0",
Expand Down
8 changes: 7 additions & 1 deletion src/components/vue-ui-annotator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,6 @@
import { opacity, treeShake, convertConfigColors } from "../lib";
import { useConfig } from "../useConfig";
import { domToPng } from "../dom-to-png";
import JsPDF from "jspdf";

// TODO: add tooltips for all buttons

Expand Down Expand Up @@ -2852,6 +2851,13 @@ export default {
});

try {
let JsPDF;
try {
JsPDF = (await import("jspdf")).default;
} catch (e) {
throw new Error("jspdf is not installed.");
}

const pngDataUrl = await domToPng({
container: wrapper,
scale: 2,
Expand Down
9 changes: 8 additions & 1 deletion src/pdf.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import JsPDF from "jspdf";
import { domToPng } from "./dom-to-png";

export default async function pdf({ domElement, fileName, scale = 2, options = {} }) {
if (!domElement) return Promise.reject("No domElement provided");

let JsPDF;

try {
JsPDF = (await import('jspdf')).default;
} catch (e) {
return Promise.reject('jspdf is not installed.')
}

const a4 = {
width: 595.28,
height: 841.89,
Expand Down
2 changes: 1 addition & 1 deletion types/vue-data-ui.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ declare module "vue-data-ui" {
table?: string;
tooltip?: string;
};
// html2canvas options
// old html2canvas options
print?: {
allowTaint?: boolean;
backgroundColor?: string;
Expand Down
2 changes: 1 addition & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default defineConfig({
rollupOptions: {
// make sure to externalize deps that shouldn't be bundled
// into your library
external: ["vue", "vue-data-ui"],
external: ["vue", "vue-data-ui", "jspdf"],
output: {
// Provide global variables to use in the UMD build
// for externalized deps
Expand Down