Skip to content

Commit

Permalink
Chromium-based Browsers: Export to png results in error
Browse files Browse the repository at this point in the history
Fixes #127
  • Loading branch information
hschwentner committed Nov 23, 2022
1 parent f47bb6d commit 0eee3e7
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
Expand Up @@ -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');
Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0eee3e7

Please sign in to comment.