2023-05-09 05:55:35 -07: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-18 08:22:44 -08:00
|
|
|
|
2023-07-13 02:49:16 -07:00
|
|
|
if (!Object.hasOwn(HTMLCanvasElement.prototype, 'toBlob')) {
|
2018-08-23 13:02:42 -07:00
|
|
|
const BASE64_MARKER = ';base64,';
|
|
|
|
|
|
|
|
Object.defineProperty(HTMLCanvasElement.prototype, 'toBlob', {
|
2023-05-10 03:59:29 -07:00
|
|
|
value: function (
|
|
|
|
this: HTMLCanvasElement,
|
|
|
|
callback: BlobCallback,
|
|
|
|
type = 'image/png',
|
2023-07-13 04:58:47 -07:00
|
|
|
quality: unknown,
|
2023-05-10 03:59:29 -07:00
|
|
|
) {
|
|
|
|
const dataURL: string = this.toDataURL(type, quality);
|
2018-08-23 13:02:42 -07:00
|
|
|
let data;
|
|
|
|
|
2023-07-13 02:49:16 -07:00
|
|
|
if (dataURL.includes(BASE64_MARKER)) {
|
2018-08-23 13:02:42 -07:00
|
|
|
const [, base64] = dataURL.split(BASE64_MARKER);
|
|
|
|
data = decodeBase64(base64);
|
|
|
|
} else {
|
|
|
|
[, data] = dataURL.split(',');
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(new Blob([data], { type }));
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|