/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

const downloadFile = function (imgSrc) {
  var _imgSrc$split;
  const image = new Image();
  const 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 = () => {
    const canvas = document.createElement("canvas");
    canvas.width = image.width;
    canvas.height = image.height;
    const context = canvas.getContext("2d");
    context.drawImage(image, 0, 0, image.width, image.height);
    canvas.toBlob(blob => {
      const url = URL.createObjectURL(blob);
      const a = document.createElement("a");
      a.download = name;
      a.href = url;
      a.click();
      a.remove();
      URL.revokeObjectURL(url);
    });
  };
  image.src = imgSrc;
};
const isImageInfo = image => typeof image !== "string";
const formatImages = images => {
  if (!Array.isArray(images)) return [];
  return images.map(item => {
    if (isImageInfo(item)) {
      return {
        download: true,
        thumbnail: item.mainImage,
        ...item
      };
    }
    return {
      mainImage: item,
      thumbnail: item,
      download: true
    };
  });
};
const getOverlay = props => {
  if (props.showOverlay !== void 0) return props.showOverlay;
  return props.mode === "modal";
};

export { downloadFile, formatImages, getOverlay };
//# sourceMappingURL=utils.js.map
