-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: updated screenshot.js to use dynamic module imports
- Loading branch information
1 parent
eb73191
commit 2e6fc1e
Showing
1 changed file
with
5 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,11 @@ | ||
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)); | ||
}; | ||
|
||
function script(src) { | ||
return new Promise(resolve => { | ||
const el = document.createElement('script'); | ||
el.src = src; | ||
document.head.appendChild(el); | ||
el.addEventListener('load', () => resolve(el)); | ||
}); | ||
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))); | ||
} | ||
|
||
export default screenshot; |