From 1ec3fd17ed9cb40b5d3f91c71837b69793c6394d Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Wed, 8 Mar 2023 15:21:11 +0100 Subject: [PATCH] lazyload jspdf. remove redundant package --- .../src/lib/utilities/UmlDownloadStrategy.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libs/remix-ui/solidity-uml-gen/src/lib/utilities/UmlDownloadStrategy.ts b/libs/remix-ui/solidity-uml-gen/src/lib/utilities/UmlDownloadStrategy.ts index 24d6124b29..72920d96d4 100644 --- a/libs/remix-ui/solidity-uml-gen/src/lib/utilities/UmlDownloadStrategy.ts +++ b/libs/remix-ui/solidity-uml-gen/src/lib/utilities/UmlDownloadStrategy.ts @@ -1,5 +1,3 @@ -import jsPDF from 'jspdf' -import 'svg2pdf.js' interface IUmlDownloadStrategy { download (uml: string, fileName: string): void } @@ -13,8 +11,8 @@ class PdfUmlDownloadStrategy implements IUmlDownloadStrategy { const Url = window.URL || window.webkitURL const url = Url.createObjectURL(svg) const img = document.createElement('img') - let doc: jsPDF - img.onload = () => { + let doc + img.onload = async () => { const canvas = document.createElement('canvas') canvas.width = img.naturalWidth canvas.height = img.naturalHeight @@ -26,7 +24,10 @@ class PdfUmlDownloadStrategy implements IUmlDownloadStrategy { canvas.style.padding = '0' ctx.scale(window.devicePixelRatio, window.devicePixelRatio) ctx.drawImage(img, 0, 0, Math.round(img.naturalWidth/scale), Math.round(img.naturalHeight/scale)) - doc = new jsPDF('landscape', 'px', [img.naturalHeight, img.naturalWidth], true) + if (doc === null || doc === undefined) { + const { default: jsPDF } = await import('jspdf') + doc = new jsPDF('landscape', 'px', [img.naturalHeight, img.naturalWidth], true) + } const pageWidth = doc.internal.pageSize.getWidth() const pageHeight = doc.internal.pageSize.getHeight() doc.addImage(canvas.toDataURL('image/png',0.5), 'PNG', 0, 0, pageWidth, pageHeight)