/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

import { _ as _defineProperty } from './dep-33b15d9d.js';
import { l as log } from './dep-a65fe6e9.js';

/**
 * LDesignUtility v0.1.1
 * (c) 2022 undefined
 * @license MIT
 */

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), true).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 SIZE_MAP = {
  B: 1,
  KB: 1024,
  MB: 1048576,
  GB: 1073741824
};

function returnFileSize(number) {
  if (number < SIZE_MAP.B) {
    return "".concat(number, " Bytes");
  }

  if (number >= SIZE_MAP.B && number < SIZE_MAP.MB) {
    return "".concat((number / SIZE_MAP.B).toFixed(1), " KB");
  }

  if (number >= SIZE_MAP.MB) {
    return "".concat((number / SIZE_MAP.MB).toFixed(1), " MB");
  }

  return "";
}

function getCurrentDate() {
  var d = new Date();
  var month = d.getMonth() + 1;
  month = month < 10 ? "0".concat(month) : month;
  return "".concat(d.getFullYear(), "-").concat(month, "-").concat(d.getDate(), " ").concat(d.getHours(), ":").concat(d.getMinutes(), ":").concat(d.getSeconds());
}

function abridgeName(inputName) {
  var leftCount = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 5;
  var rightCount = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 7;
  var name = inputName;
  var leftLength = 0;
  var rightLength = 0;
  if (!name) return "";

  for (var i = 0; i < name.length; i++) {
    var w = name[i];
    var isCn = escape(w).indexOf("%u") === 0;

    if (i < leftCount * 2 && leftLength < leftCount) {
      isCn ? leftLength += 1 : leftLength += 2;
    } else if (i > i - rightCount && rightLength < rightCount) {
      isCn ? rightLength += 1 : rightLength += 2;
    }
  }

  return name.replace(new RegExp("^(.{".concat(leftLength, "})(.+)(.{").concat(rightLength, "})$")), "$1\u2026$3");
}

function isOverSizeLimit(fileSize, sizeLimit, unit) {
  var units = ["B", "KB", "MB", "GB"];
  var KBIndex = 1;
  var index = units.indexOf(unit);

  if (index === -1) {
    log.warn("Upload", "`sizeLimit.unit` can only be one of ".concat(units.join()));
    index = KBIndex;
  }

  var num = SIZE_MAP[unit];
  return fileSize > sizeLimit * num;
}

var urlCreator = function urlCreator() {
  return window.webkitURL || window.URL;
};

function formatFiles() {
  var files = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
  var format = arguments.length > 1 ? arguments[1] : void 0;
  return files.map(function (fileRaw) {
    var _urlCreator;

    var file = typeof format === "function" ? format(fileRaw) : fileRaw;

    var uploadFile = _objectSpread({
      raw: fileRaw,
      lastModified: fileRaw.lastModified,
      name: fileRaw.name,
      size: fileRaw.size,
      type: fileRaw.type,
      percent: 0,
      status: "waiting"
    }, file);

    uploadFile.url = (_urlCreator = urlCreator()) === null || _urlCreator === void 0 ? void 0 : _urlCreator.createObjectURL(fileRaw);
    return uploadFile;
  });
}

export { abridgeName as a, formatFiles as f, getCurrentDate as g, isOverSizeLimit as i, returnFileSize as r };
//# sourceMappingURL=dep-58b4c751.js.map
