UNPKG

tdesign-react

Version:
37 lines (32 loc) 1.1 kB
/** * tdesign v1.15.1 * (c) 2025 tdesign * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var downloadFile = function downloadFile(imgSrc) { var _imgSrc$split; var image = new Image(); var name = (imgSrc === null || imgSrc === void 0 || (_imgSrc$split = imgSrc.split) === null || _imgSrc$split === void 0 ? void 0 : _imgSrc$split.call(imgSrc, "/").pop()) || Math.random().toString(32).slice(2); image.setAttribute("crossOrigin", "anonymous"); image.onload = function () { var canvas = document.createElement("canvas"); canvas.width = image.width; canvas.height = image.height; var context = canvas.getContext("2d"); context.drawImage(image, 0, 0, image.width, image.height); canvas.toBlob(function (blob) { var url = URL.createObjectURL(blob); var a = document.createElement("a"); a.download = name; a.href = url; a.click(); a.remove(); URL.revokeObjectURL(url); }); }; image.src = imgSrc; }; exports.downloadFile = downloadFile; //# sourceMappingURL=utils.js.map