finished imagedownload strategy

pull/3395/head
Joseph Izang 2 years ago
parent 5a78b0f0c3
commit 56f1851bbb
  1. 43
      libs/remix-ui/solidity-uml-gen/src/lib/utilities/UmlDownloadStrategy.ts
  2. 1
      package.json
  3. 22
      yarn.lock

@ -1,5 +1,7 @@
import jsPDF from 'jspdf' import jsPDF from 'jspdf'
import 'svg2pdf.js' import 'svg2pdf.js'
import { SVG } from '@svgdotjs/svg.js'
import { Canvg } from 'canvg'
const jsPdf = new jsPDF('landscape', 'px', 'a4') const jsPdf = new jsPDF('landscape', 'px', 'a4')
@ -50,23 +52,30 @@ class PdfUmlDownloadStrategy implements IUmlDownloadStrategy {
class ImageUmlDownloadStrategy implements IUmlDownloadStrategy { class ImageUmlDownloadStrategy implements IUmlDownloadStrategy {
public download (uml: string, fileName: string): void { public download (uml: string, fileName: string): void {
// const svg = new Blob([uml], { type: 'image/svg+xml;charset=utf-8' }) const svg = new Blob([uml], { type: 'image/svg+xml;charset=utf-8' })
// const url = URL.createObjectURL(svg) const Url = window.URL || window.webkitURL
// const img = new Image() const url = Url.createObjectURL(svg)
// img.onload = () => { const img = document.createElement('img')
// const canvas = document.createElement('canvas') img.onload = () => {
// canvas.width = img.width const canvas = document.createElement('canvas')
// canvas.height = img.height canvas.width = img.naturalWidth
// const ctx = canvas.getContext('2d') canvas.height = img.naturalHeight
// ctx.drawImage(img, 0, 0) const ctx = canvas.getContext('2d')
// const png = canvas.toDataURL('image/png') const scale = window.devicePixelRatio*1
// const a = document.createElement('a') canvas.style.width = `${Math.round(img.naturalWidth/scale)}`.concat('px')
// a.download = fileName.split('/')[1].split('.')[0].concat('.png') canvas.style.height = `${Math.round(img.naturalHeight/scale)}`.concat('px')
// a.href = png canvas.style.margin = '0'
// a.click() canvas.style.padding = '0'
// } ctx.scale(window.devicePixelRatio, window.devicePixelRatio)
// img.src = url ctx.drawImage(img, 0, 0, Math.round(img.naturalWidth/scale), Math.round(img.naturalHeight/scale))
// } const png = canvas.toDataURL('image/png')
const a = document.createElement('a')
a.download = fileName.split('/')[1].split('.')[0].concat('.png')
a.href = png
console.log('about to click the link to download the png!!!')
a.click()
}
img.src = url
} }
} }

@ -146,6 +146,7 @@
"bn.js": "^5.1.2", "bn.js": "^5.1.2",
"bootstrap": "^5.2.2", "bootstrap": "^5.2.2",
"brace": "^0.8.0", "brace": "^0.8.0",
"canvg": "^4.0.1",
"change-case": "^4.1.1", "change-case": "^4.1.1",
"chokidar": "^2.1.8", "chokidar": "^2.1.8",
"color-support": "^1.1.3", "color-support": "^1.1.3",

@ -5619,6 +5619,11 @@
dependencies: dependencies:
antlr4ts "^0.5.0-alpha.4" antlr4ts "^0.5.0-alpha.4"
"@svgdotjs/svg.js@^3.1.2":
version "3.1.2"
resolved "https://registry.yarnpkg.com/@svgdotjs/svg.js/-/svg.js-3.1.2.tgz#acd62ebc5a6ef5b3a70e4a3912ce643a150c56e7"
integrity sha512-0ZCWTiuRjCXT2SUoVDiu+8DLuRQlkxZbO680Y2QkV7jNsULzJajrx6A3MxA/IBQg6UGV5csgPZ8w7U57hZSK+A==
"@svgr/babel-plugin-add-jsx-attribute@^6.5.1": "@svgr/babel-plugin-add-jsx-attribute@^6.5.1":
version "6.5.1" version "6.5.1"
resolved "https://registry.yarnpkg.com/@svgr/babel-plugin-add-jsx-attribute/-/babel-plugin-add-jsx-attribute-6.5.1.tgz#74a5d648bd0347bda99d82409d87b8ca80b9a1ba" resolved "https://registry.yarnpkg.com/@svgr/babel-plugin-add-jsx-attribute/-/babel-plugin-add-jsx-attribute-6.5.1.tgz#74a5d648bd0347bda99d82409d87b8ca80b9a1ba"
@ -6155,6 +6160,11 @@
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301" resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301"
integrity sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw== integrity sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==
"@types/offscreencanvas@^2019.6.4":
version "2019.7.0"
resolved "https://registry.yarnpkg.com/@types/offscreencanvas/-/offscreencanvas-2019.7.0.tgz#e4a932069db47bb3eabeb0b305502d01586fa90d"
integrity sha512-PGcyveRIpL1XIqK8eBsmRBt76eFgtzuPiSTyKHZxnGemp2yzGzWpjYKAfK3wIMiU7eH+851yEpiuP8JZerTmWg==
"@types/parse-json@^4.0.0": "@types/parse-json@^4.0.0":
version "4.0.0" version "4.0.0"
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0" resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
@ -9295,6 +9305,18 @@ canvg@^3.0.6:
stackblur-canvas "^2.0.0" stackblur-canvas "^2.0.0"
svg-pathdata "^6.0.3" svg-pathdata "^6.0.3"
canvg@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/canvg/-/canvg-4.0.1.tgz#122532dffeff6fc36074582af2cd37c454ae9ffa"
integrity sha512-5gD/d6SiCCT7baLnVr0hokYe93DfcHW2rSqdKOuOQD84YMlyfttnZ8iQsThTdX6koYam+PROz/FuQTo500zqGw==
dependencies:
"@types/offscreencanvas" "^2019.6.4"
"@types/raf" "^3.4.0"
raf "^3.4.1"
rgbcolor "^1.0.1"
stackblur-canvas "^2.0.0"
svg-pathdata "^6.0.3"
capital-case@^1.0.4: capital-case@^1.0.4:
version "1.0.4" version "1.0.4"
resolved "https://registry.yarnpkg.com/capital-case/-/capital-case-1.0.4.tgz#9d130292353c9249f6b00fa5852bee38a717e669" resolved "https://registry.yarnpkg.com/capital-case/-/capital-case-1.0.4.tgz#9d130292353c9249f6b00fa5852bee38a717e669"

Loading…
Cancel
Save