xdesign-vue-next
Version:
XDesign Component for vue-next
64 lines (60 loc) • 3.28 kB
JavaScript
/**
* xdesign v1.0.6
* (c) 2023 xdesign
* @license MIT
*/
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import isString from 'lodash/isString';
import isArray from 'lodash/isArray';
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var downloadFile = function downloadFile(imgSrc) {
var _imgSrc$split, _imgSrc$split$split, _imgSrc$split$split$s;
var image = new Image();
var name = (imgSrc === null || imgSrc === void 0 || (_imgSrc$split = imgSrc.split) === null || _imgSrc$split === void 0 || (_imgSrc$split = _imgSrc$split.call(imgSrc, "?")) === null || _imgSrc$split === void 0 || (_imgSrc$split = _imgSrc$split[0]) === null || _imgSrc$split === void 0 || (_imgSrc$split$split = _imgSrc$split.split) === null || _imgSrc$split$split === void 0 || (_imgSrc$split$split = _imgSrc$split$split.call(_imgSrc$split, "#")) === null || _imgSrc$split$split === void 0 || (_imgSrc$split$split = _imgSrc$split$split[0]) === null || _imgSrc$split$split === void 0 || (_imgSrc$split$split$s = _imgSrc$split$split.split) === null || _imgSrc$split$split$s === void 0 ? void 0 : _imgSrc$split$split$s.call(_imgSrc$split$split, "/").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 !isString(image) && !(image instanceof File);
};
var formatImages = function formatImages(images) {
if (!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