UNPKG

xdesign-vue-next

Version:

XDesign Component for vue-next

76 lines (68 loc) 3.82 kB
/** * xdesign v1.0.6 * (c) 2023 xdesign * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _defineProperty = require('@babel/runtime/helpers/defineProperty'); var isString = require('lodash/isString'); var isArray = require('lodash/isArray'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty); var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString); var isArray__default = /*#__PURE__*/_interopDefaultLegacy(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__default["default"](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__default["default"](image) && !(image instanceof File); }; var formatImages = function formatImages(images) { if (!isArray__default["default"](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"; }; exports.downloadFile = downloadFile; exports.formatImages = formatImages; exports.getOverlay = getOverlay; //# sourceMappingURL=utils.js.map