mirror of
https://github.com/penpot/penpot.git
synced 2025-05-10 05:26:37 +02:00
🐛 Fixes problems with the picker for Safari and Firefox
This commit is contained in:
parent
ba529b9fd6
commit
264811c5ee
7 changed files with 158 additions and 127 deletions
33
frontend/resources/polyfills/createImageBitmap.js
Normal file
33
frontend/resources/polyfills/createImageBitmap.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Safari and Edge polyfill for createImageBitmap
|
||||
* https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/createImageBitmap
|
||||
*
|
||||
* Support source image types Blob and ImageData.
|
||||
*
|
||||
* From: https://dev.to/nektro/createimagebitmap-polyfill-for-safari-and-edge-228
|
||||
* Updated by Yoan Tournade <yoan@ytotech.com>
|
||||
*/
|
||||
if (!('createImageBitmap' in window)) {
|
||||
window.createImageBitmap = async function (data) {
|
||||
return new Promise((resolve,reject) => {
|
||||
let dataURL;
|
||||
if (data instanceof Blob) {
|
||||
dataURL = URL.createObjectURL(data);
|
||||
} else if (data instanceof ImageData) {
|
||||
const canvas = document.createElement('canvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
canvas.width = data.width;
|
||||
canvas.height = data.height;
|
||||
ctx.putImageData(data,0,0);
|
||||
dataURL = canvas.toDataURL();
|
||||
} else {
|
||||
throw new Error('createImageBitmap does not handle the provided image source type');
|
||||
}
|
||||
const img = document.createElement('img');
|
||||
img.addEventListener('load',function () {
|
||||
resolve(this);
|
||||
});
|
||||
img.src = dataURL;
|
||||
});
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue