/**
 * ldesign v0.4.2
 * (c) 2023 ldesign
 * @license MIT
 */

import { _ as _defineProperty } from '../_chunks/dep-eb20e23f.mjs';
import { i as isString_1 } from '../_chunks/dep-1cf2b129.mjs';
import { i as isArray_1 } from '../_chunks/dep-e3b14d70.mjs';
import '../_chunks/dep-b4041200.mjs';
import '../_chunks/dep-a0b4a044.mjs';
import '../_chunks/dep-c959a6fb.mjs';
import '../_chunks/dep-66d6733b.mjs';
import '../_chunks/dep-c31e1d9e.mjs';

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;
  var image = new Image();
  var name = (imgSrc === null || imgSrc === void 0 ? 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 !isString_1(image);
};
var formatImages = function formatImages(images) {
  if (!isArray_1(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.mjs.map
