2023-05-09 22:55:35 +10:00
|
|
|
import 'core-js/features/object/assign';
|
|
|
|
import 'core-js/features/object/values';
|
|
|
|
import 'core-js/features/symbol';
|
|
|
|
import 'core-js/features/promise/finally';
|
|
|
|
import { decode as decodeBase64 } from '../utils/base64';
|
2020-02-19 03:22:44 +11:00
|
|
|
|
2018-04-23 17:15:51 +10:00
|
|
|
if (!HTMLCanvasElement.prototype.toBlob) {
|
|
|
|
const BASE64_MARKER = ';base64,';
|
|
|
|
|
|
|
|
Object.defineProperty(HTMLCanvasElement.prototype, 'toBlob', {
|
2023-05-10 20:59:29 +10:00
|
|
|
value: function (
|
|
|
|
this: HTMLCanvasElement,
|
|
|
|
callback: BlobCallback,
|
|
|
|
type = 'image/png',
|
|
|
|
quality: unknown
|
|
|
|
) {
|
|
|
|
const dataURL: string = this.toDataURL(type, quality);
|
2018-04-23 17:15:51 +10:00
|
|
|
let data;
|
|
|
|
|
|
|
|
if (dataURL.indexOf(BASE64_MARKER) >= 0) {
|
|
|
|
const [, base64] = dataURL.split(BASE64_MARKER);
|
|
|
|
data = decodeBase64(base64);
|
|
|
|
} else {
|
|
|
|
[, data] = dataURL.split(',');
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(new Blob([data], { type }));
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|