UNPKG

tdesign-vue

Version:
62 lines (58 loc) 2.45 kB
/** * tdesign v1.14.1 * (c) 2025 tdesign * @license MIT */ import _defineProperty from '@babel/runtime/helpers/defineProperty'; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } 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; }; var isImageInfo = function isImageInfo(image) { return !!image && typeof image !== "string" && !(image instanceof File); }; var formatImages = function formatImages(images) { if (!Array.isArray(images)) return []; return images.map(function (item) { if (isImageInfo(item)) { return _objectSpread({ download: true, thumbnail: item.mainImage }, item); } return { mainImage: item, thumbnail: item, download: true }; }); }; var getOverlay = function getOverlay(props) { if (props.showOverlay !== void 0) { return props.showOverlay; } return props.mode === "modal"; }; export { downloadFile, formatImages, getOverlay }; //# sourceMappingURL=utils.js.map