Skip to content

Commit

Permalink
Revert "refactor: updated screenshot.js to use dynamic module imports"
Browse files Browse the repository at this point in the history
This reverts commit 2e6fc1e.
  • Loading branch information
MarcMcIntosh committed Dec 8, 2020
1 parent 2e6fc1e commit 75b807c
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/toolbar/preview/screenshot.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
let html2canvasPromise;

const screenshot = async () => {
document.getElementById('prismic-toolbar-v2').setAttribute('data-html2canvas-ignore', true);
if (!html2canvasPromise) html2canvasPromise = script('https://html2canvas.hertzen.com/dist/html2canvas.min.js');
await html2canvasPromise;

const canvas = await window.html2canvas(document.body, {
logging: false,
width: '100%',
height: window.innerHeight,
});
return new Promise(resolve => canvas.toBlob(resolve, 'image/jpeg', 0.6));
};

const options = { logging: false, width: '100%', height: window.innerHeight };

return import('https://html2canvas.hertzen.com/dist/html2canvas.esm.js')
.then(html2canvas => html2canvas(document.body, options))
.then(canvas => new Promise(resolve => canvas.toBlob(resolve, 'image/jpeg', 0.6)));
function script(src) {
return new Promise(resolve => {
const el = document.createElement('script');
el.src = src;
document.head.appendChild(el);
el.addEventListener('load', () => resolve(el));
});
}

export default screenshot;

0 comments on commit 75b807c

Please sign in to comment.