import "../../node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.mjs";
import "../../node_modules/.pnpm/screenfull@6.0.2/node_modules/screenfull/index.mjs";
import "../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_root.mjs";
import "../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseGetTag.mjs";
import Image_404 from "../assets/images/exception/image-404.png.mjs";
import "../../node_modules/.pnpm/html2canvas@1.4.1/node_modules/html2canvas/dist/html2canvas.esm.mjs";
import { toString } from "./type.mjs";
import cloneDeep from "../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/cloneDeep.mjs";
import { WinKeyboard } from "../enums/editPageEnum.mjs";
import { RequestHttpIntervalEnum } from "../enums/httpEnum.mjs";
import { excludeParseEventKeyList, excludeParseEventValueList } from "../enums/eventEnum.mjs";
import { NIcon } from "../../node_modules/.pnpm/naive-ui@2.34.3_vue@3.3.4/node_modules/naive-ui/es/icon/src/Icon.mjs";
import { h } from "../../node_modules/.pnpm/@vue_runtime-core@3.3.4/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.mjs";
const isDev = () => {
  return false;
};
const getUUID = (randomLength = 10) => {
  return Number(Math.random().toString().substring(2, randomLength) + Date.now()).toString(36);
};
const renderIcon = (icon, set = {}) => {
  return () => h(NIcon, set, { default: () => h(icon) });
};
const requireErrorImg = () => {
  return Image_404;
};
const setComponentPosition = (target, x, y) => {
  x && (target.attr.x = x);
  y && (target.attr.y = y);
};
const fileToUrl = (file) => {
  const Url = URL || window.URL || window.webkitURL;
  const ImageUrl = Url.createObjectURL(file);
  return ImageUrl;
};
const newFunctionHandle = (data, res, funcStr, isToString, errorCallBack, successCallBack) => {
  try {
    if (!funcStr)
      return data;
    const fn = new Function("data", "res", funcStr);
    const fnRes = fn(cloneDeep(data), cloneDeep(res));
    const resHandle = isToString ? toString(fnRes) : fnRes;
    successCallBack && successCallBack(resHandle);
    return resHandle;
  } catch (error) {
    errorCallBack && errorCallBack(error);
    return "函数执行错误";
  }
};
const intervalUnitHandle = (num, unit) => {
  switch (unit) {
    case RequestHttpIntervalEnum.SECOND:
      return num * 1e3;
    case RequestHttpIntervalEnum.MINUTE:
      return num * 1e3 * 60;
    case RequestHttpIntervalEnum.HOUR:
      return num * 1e3 * 60 * 60;
    case RequestHttpIntervalEnum.DAY:
      return num * 1e3 * 60 * 60 * 24;
    default:
      return num * 1e3;
  }
};
const setKeyboardDressShow = (keyCode) => {
  var _a, _b;
  const code = /* @__PURE__ */ new Map([
    [17, WinKeyboard.CTRL],
    [32, WinKeyboard.SPACE]
  ]);
  const dom = document.getElementById("keyboard-dress-show");
  if (!dom)
    return;
  if (!keyCode) {
    (_a = window.onKeySpacePressHold) == null ? void 0 : _a.call(window, false);
    dom.innerText = "";
    return;
  }
  if (keyCode && code.has(keyCode)) {
    if (keyCode == 32)
      (_b = window.onKeySpacePressHold) == null ? void 0 : _b.call(window, true);
    dom.innerText = `按下了「${code.get(keyCode)}」键`;
  }
};
const JSONStringify = (data) => {
  return JSON.stringify(
    data,
    (key, val) => {
      if (typeof val === "function") {
        return `${val}`;
      }
      if (typeof val === "undefined") {
        return null;
      }
      return val;
    },
    2
  );
};
const evalFn = (fn) => {
  var Fun = Function;
  return new Fun("return " + fn)();
};
const JSONParse = (data) => {
  return JSON.parse(data, (k, v) => {
    if (excludeParseEventKeyList.includes(k))
      return v;
    if (typeof v === "string") {
      const someValue = excludeParseEventValueList.some((excludeValue) => v.indexOf(excludeValue) > -1);
      if (someValue)
        return v;
    }
    if (typeof v === "string" && v.indexOf && (v.indexOf("function") > -1 || v.indexOf("=>") > -1)) {
      return evalFn(`(function(){return ${v}})()`);
    } else if (typeof v === "string" && v.indexOf && v.indexOf("return ") > -1) {
      const baseLeftIndex = v.indexOf("(");
      if (baseLeftIndex > -1) {
        const newFn = `function ${v.substring(baseLeftIndex)}`;
        return evalFn(`(function(){return ${newFn}})()`);
      }
    }
    return v;
  });
};
const setTitle = (title) => {
  title && (document.title = title);
};
export {
  JSONParse,
  JSONStringify,
  evalFn,
  fileToUrl,
  getUUID,
  intervalUnitHandle,
  isDev,
  newFunctionHandle,
  renderIcon,
  requireErrorImg,
  setComponentPosition,
  setKeyboardDressShow,
  setTitle
};
