Skip to content

Commit

Permalink
Merge pull request #128 from WPS:hschwentner/issue127
Browse files Browse the repository at this point in the history
Chromium-based Browsers: Export to png results in error
hschwentner authored Nov 23, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents cb6d187 + 0eee3e7 commit e72e302
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions app/domain-story-modeler/features/export/pngDownload.js
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ let width, height;
let title = document.getElementById('title'),
infoText = document.getElementById('infoText');

export function downloadPNG(withTitle) {
export async function downloadPNG(withTitle) {
let canvas = document.getElementById('canvas');
let container = canvas.getElementsByClassName('djs-container');
let svgElements = container[0].getElementsByTagName('svg');
@@ -20,7 +20,7 @@ export function downloadPNG(withTitle) {
let onLoadTriggered = false;

// removes unwanted black dots in image
let svg = extractSVG(viewport);
let svg = await extractSVG(viewport);

svg = prepareSVG(svg, layerBase, withTitle);

@@ -94,15 +94,26 @@ export function downloadPNG(withTitle) {
image.src ='';
}

async function wait(ms) {
// eslint-disable-next-line no-undef
return new Promise((resolve, reject) =>
setTimeout(() => {
resolve();
}, ms));
}

function extractSVG(viewport) {
async function extractSVG(viewport) {
let layerResizers = viewport.getElementsByClassName('layer-resizers');
let layerOverlays = viewport.getElementsByClassName('layer-overlays');
let transform = viewport.getAttribute('transform');
let translate = viewport.getAttribute('translate');

const layerRes = layerResizers[0];
const layerOver= layerOverlays[0];
let layerRes, layerOver;
while (layerOver == undefined) {
await wait(500);
layerOver = layerOverlays[0];
layerRes = layerResizers[0];
}

const layerResizersParent = layerResizers[0].parentNode;
const layerOverlaysParent = layerOverlays[0].parentNode;

0 comments on commit e72e302

Please sign in to comment.