"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
require("../../../../node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.js");
const pinia = require("pinia");
const publicConfig = require("../../../packages/public/publicConfig.js");
const debounce = require("../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/debounce.js");
const cloneDeep = require("../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/cloneDeep.js");
const index = require("../../../settings/chartThemes/index.js");
const designSetting = require("../../../settings/designSetting.js");
const chartHistoryStore$1 = require("../chartHistoryStore/chartHistoryStore.js");
const settingStore$1 = require("../settingStore/settingStore.js");
const chartHistoryStore_d = require("../chartHistoryStore/chartHistoryStore.d.js");
const editPageEnum = require("../../../enums/editPageEnum.js");
const utils = require("../../../utils/utils.js");
require("../../../../node_modules/.pnpm/crypto-js@4.1.1/node_modules/crypto-js/index.js");
const type = require("../../../utils/type.js");
require("../../../enums/pageEnum.js");
require("../../../router/index.js");
require("../designStore/designStore.js");
const plugin = require("../../../utils/plugin.js");
require("../../../components/GoLoading/index.js");
const chartEditStore_d = require("./chartEditStore.d.js");
const reactivity_esmBundler = require("../../../../node_modules/.pnpm/@vue_reactivity@3.3.4/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js");
const chartHistoryStore = chartHistoryStore$1.useChartHistoryStore();
const settingStore = settingStore$1.useSettingStore();
const useChartEditStore = pinia.defineStore({
  id: "useChartEditStore",
  state: () => ({
    // 画布属性
    editCanvas: {
      // 编辑区域 Dom
      editLayoutDom: null,
      editContentDom: null,
      // 偏移量
      offset: 20,
      // 系统控制缩放
      scale: 1,
      // 用户控制的缩放
      userScale: 1,
      // 锁定缩放
      lockScale: false,
      // 初始化
      isCreate: false,
      // 拖拽中
      isDrag: false,
      // 框选中
      isSelect: false,
      // 代码编辑中
      isCodeEdit: false
    },
    // 右键菜单
    rightMenuShow: false,
    // 鼠标定位
    mousePosition: {
      startX: 0,
      startY: 0,
      x: 0,
      y: 0
    },
    // 目标图表
    targetChart: {
      hoverId: void 0,
      selectId: []
    },
    // 记录临时数据（复制等）
    recordChart: void 0,
    // -----------------------
    // 画布属性（需存储给后端）
    editCanvasConfig: {
      // 项目名称
      projectName: void 0,
      // 默认宽度
      width: 1920,
      // 默认高度
      height: 1080,
      // 启用滤镜
      filterShow: false,
      // 色相
      hueRotate: 0,
      // 饱和度
      saturate: 1,
      // 对比度
      contrast: 1,
      // 亮度
      brightness: 1,
      // 透明度
      opacity: 1,
      // 变换（暂不更改）
      rotateZ: 0,
      rotateX: 0,
      rotateY: 0,
      skewX: 0,
      skewY: 0,
      // 混合模式
      blendMode: "normal",
      // 默认背景色
      background: void 0,
      backgroundImage: void 0,
      // 是否使用纯颜色
      selectColor: true,
      // chart 主题色
      chartThemeColor: index.defaultTheme,
      // 自定义颜色列表
      chartCustomThemeColorInfo: void 0,
      // 全局配置
      chartThemeSetting: index.globalThemeJson,
      // 适配方式
      previewScaleType: designSetting.previewScaleType
    },
    // 数据请求处理（需存储给后端）
    requestGlobalConfig: {
      requestDataPond: [],
      requestOriginUrl: "",
      requestInterval: designSetting.requestInterval,
      requestIntervalUnit: designSetting.requestIntervalUnit,
      requestParams: {
        Body: {
          "form-data": {},
          "x-www-form-urlencoded": {},
          json: "",
          xml: ""
        },
        Header: {},
        Params: {}
      }
    },
    // 图表数组（需存储给后端）
    componentList: []
  }),
  getters: {
    getMousePosition() {
      return this.mousePosition;
    },
    getRightMenuShow() {
      return this.rightMenuShow;
    },
    getEditCanvas() {
      return this.editCanvas;
    },
    getEditCanvasConfig() {
      return this.editCanvasConfig;
    },
    getTargetChart() {
      return this.targetChart;
    },
    getRecordChart() {
      return this.recordChart;
    },
    getRequestGlobalConfig() {
      return this.requestGlobalConfig;
    },
    getComponentList() {
      return this.componentList;
    },
    // 获取需要存储的数据项
    getStorageInfo() {
      return {
        [chartEditStore_d.ChartEditStoreEnum.EDIT_CANVAS_CONFIG]: this.getEditCanvasConfig,
        [chartEditStore_d.ChartEditStoreEnum.COMPONENT_LIST]: this.getComponentList,
        [chartEditStore_d.ChartEditStoreEnum.REQUEST_GLOBAL_CONFIG]: this.getRequestGlobalConfig
      };
    }
  },
  actions: {
    // * 设置 editCanvas 数据项
    setEditCanvas(key, value) {
      this.editCanvas[key] = value;
    },
    // * 设置 editCanvasConfig（需保存后端） 数据项
    setEditCanvasConfig(key, value) {
      this.editCanvasConfig[key] = value;
    },
    // * 设置右键菜单
    setRightMenuShow(value) {
      this.rightMenuShow = value;
    },
    // * 设置目标数据 hover
    setTargetHoverChart(hoverId) {
      this.targetChart.hoverId = hoverId;
    },
    // * 设置目标数据 select
    setTargetSelectChart(selectId, push = false) {
      if (this.targetChart.selectId.find((e) => e === selectId))
        return;
      if (!selectId) {
        this.targetChart.selectId = [];
        return;
      }
      if (push) {
        if (type.isString(selectId)) {
          this.targetChart.selectId.push(selectId);
          return;
        }
        if (type.isArray(selectId)) {
          this.targetChart.selectId.push(...selectId);
          return;
        }
      } else {
        if (type.isString(selectId)) {
          this.targetChart.selectId = [selectId];
          return;
        }
        if (type.isArray(selectId)) {
          this.targetChart.selectId = selectId;
          return;
        }
      }
    },
    // * 设置记录数据
    setRecordChart(item) {
      this.recordChart = cloneDeep.default(item);
    },
    // * 设置鼠标位置
    setMousePosition(x, y, startX, startY) {
      if (x)
        this.mousePosition.x = x;
      if (y)
        this.mousePosition.y = y;
      if (startX)
        this.mousePosition.startX = startX;
      if (startY)
        this.mousePosition.startY = startY;
    },
    // * 找到目标 id 数据的下标位置，id可为父级或子集数组（无则返回-1）
    fetchTargetIndex(id) {
      const targetId = id || this.getTargetChart.selectId.length && this.getTargetChart.selectId[0] || void 0;
      if (!targetId) {
        plugin.loadingFinish();
        return -1;
      }
      const targetIndex = this.componentList.findIndex((e) => e.id === targetId);
      if (targetIndex !== -1) {
        return targetIndex;
      } else {
        const length = this.getComponentList.length;
        for (let i = 0; i < length; i++) {
          if (this.getComponentList[i].isGroup) {
            for (const cItem of this.getComponentList[i].groupList) {
              if (cItem.id === targetId) {
                return i;
              }
            }
          }
        }
      }
      return -1;
    },
    // * 统一格式化处理入参 id
    idPreFormat(id) {
      const idArr = [];
      if (!id) {
        idArr.push(...this.getTargetChart.selectId);
        return idArr;
      }
      if (type.isString(id))
        idArr.push(id);
      if (type.isArray(id))
        idArr.push(...id);
      return idArr;
    },
    /**
     * * 新增组件列表
     * @param componentInstance 新图表实例
     * @param isHead 是否头部插入
     * @param isHistory 是否进行记录
     * @returns
     */
    addComponentList(componentInstance, isHead = false, isHistory = false) {
      if (componentInstance instanceof Array) {
        componentInstance.forEach((item) => {
          this.addComponentList(item, isHead, isHistory);
        });
        return;
      }
      if (isHistory) {
        chartHistoryStore.createAddHistory([componentInstance]);
      }
      if (isHead) {
        this.componentList.unshift(componentInstance);
        return;
      }
      this.componentList.push(componentInstance);
    },
    // * 删除组件
    removeComponentList(id, isHistory = true) {
      try {
        const idArr = this.idPreFormat(id);
        const history = [];
        if (!idArr.length)
          return;
        plugin.loadingStart();
        idArr.forEach((ids) => {
          const index2 = this.fetchTargetIndex(ids);
          if (index2 !== -1) {
            history.push(this.getComponentList[index2]);
            this.componentList.splice(index2, 1);
          }
        });
        isHistory && chartHistoryStore.createDeleteHistory(history);
        plugin.loadingFinish();
        return;
      } catch (value) {
        plugin.loadingError();
      }
    },
    // * 重置组件位置
    resetComponentPosition(item, isForward) {
      const index2 = this.fetchTargetIndex(item.id);
      if (index2 > -1) {
        const componentInstance = this.getComponentList[index2];
        if (isForward) {
          componentInstance.attr = Object.assign(componentInstance.attr, {
            x: item.attr.x + item.attr.offsetX,
            y: item.attr.y + item.attr.offsetY
          });
        } else {
          componentInstance.attr = Object.assign(componentInstance.attr, {
            x: item.attr.x,
            y: item.attr.y
          });
        }
      }
    },
    // * 移动组件
    moveComponentList(item) {
      chartHistoryStore.createMoveHistory(item);
    },
    // * 更新组件列表某一项的值
    updateComponentList(index2, newData) {
      if (index2 < 1 && index2 > this.getComponentList.length)
        return;
      this.componentList[index2] = newData;
    },
    // * 设置页面样式属性
    setPageStyle(key, value) {
      const dom = this.getEditCanvas.editContentDom;
      if (dom) {
        dom.style[key] = value;
      }
    },
    // * 移动组件列表层级位置到两端
    setBothEnds(isEnd = false, isHistory = true) {
      try {
        if (this.getTargetChart.selectId.length > 1)
          return;
        plugin.loadingStart();
        const length = this.getComponentList.length;
        if (length < 2) {
          plugin.loadingFinish();
          return;
        }
        const index2 = this.fetchTargetIndex();
        const targetData = this.getComponentList[index2];
        if (index2 !== -1) {
          if (isEnd && index2 === 0 || !isEnd && index2 === length - 1) {
            plugin.loadingFinish();
            return;
          }
          const setIndex = (componentInstance, i) => {
            const temp = cloneDeep.default(componentInstance);
            temp.attr.zIndex = i;
            return temp;
          };
          if (isHistory) {
            chartHistoryStore.createLayerHistory(
              [setIndex(targetData, index2)],
              isEnd ? chartHistoryStore_d.HistoryActionTypeEnum.BOTTOM : chartHistoryStore_d.HistoryActionTypeEnum.TOP
            );
          }
          this.addComponentList(targetData, isEnd);
          this.getComponentList.splice(isEnd ? index2 + 1 : index2, 1);
          plugin.loadingFinish();
          return;
        }
      } catch (value) {
        plugin.loadingError();
      }
    },
    // * 置顶
    setTop(isHistory = true) {
      this.setBothEnds(false, isHistory);
    },
    // * 置底
    setBottom(isHistory = true) {
      this.setBothEnds(true, isHistory);
    },
    // * 上移/下移互换图表位置
    wrap(isDown = false, isHistory = true) {
      try {
        if (this.getTargetChart.selectId.length > 1)
          return;
        plugin.loadingStart();
        const length = this.getComponentList.length;
        if (length < 2) {
          plugin.loadingFinish();
          return;
        }
        const index2 = this.fetchTargetIndex();
        if (index2 !== -1) {
          if (isDown && index2 === 0 || !isDown && index2 === length - 1) {
            plugin.loadingFinish();
            return;
          }
          const swapIndex = isDown ? index2 - 1 : index2 + 1;
          const targetItem = this.getComponentList[index2];
          const swapItem = this.getComponentList[swapIndex];
          if (isHistory) {
            chartHistoryStore.createLayerHistory(
              [targetItem],
              isDown ? chartHistoryStore_d.HistoryActionTypeEnum.DOWN : chartHistoryStore_d.HistoryActionTypeEnum.UP
            );
          }
          this.updateComponentList(index2, swapItem);
          this.updateComponentList(swapIndex, targetItem);
          plugin.loadingFinish();
          return;
        }
      } catch (value) {
        plugin.loadingError();
      }
    },
    // * 图层上移
    setUp(isHistory = true) {
      this.wrap(false, isHistory);
    },
    // * 图层下移
    setDown(isHistory = true) {
      this.wrap(true, isHistory);
    },
    // * 复制
    setCopy(isCut = false) {
      try {
        if (this.getTargetChart.selectId.length > 1)
          return;
        if (document.getElementsByClassName("n-modal-body-wrapper").length)
          return;
        plugin.loadingStart();
        const index2 = this.fetchTargetIndex();
        if (index2 !== -1) {
          const copyData = {
            charts: this.getComponentList[index2],
            type: isCut ? chartHistoryStore_d.HistoryActionTypeEnum.CUT : chartHistoryStore_d.HistoryActionTypeEnum.COPY
          };
          this.setRecordChart(copyData);
          window["$message"].success(isCut ? "剪切图表成功" : "复制图表成功！");
          plugin.loadingFinish();
        }
      } catch (value) {
        plugin.loadingError();
      }
    },
    // * 剪切
    setCut() {
      this.setCopy(true);
    },
    // * 粘贴
    setParse() {
      try {
        plugin.loadingStart();
        const recordCharts = this.getRecordChart;
        if (recordCharts === void 0) {
          plugin.loadingFinish();
          return;
        }
        const parseHandle = (e) => {
          e = cloneDeep.default(e);
          e.attr.x = this.getMousePosition.startX;
          e.attr.y = this.getMousePosition.startY;
          e.id = utils.getUUID();
          if (e.isGroup) {
            e.groupList.forEach((item) => {
              item.id = utils.getUUID();
            });
          }
          return e;
        };
        const isCut = recordCharts.type === chartHistoryStore_d.HistoryActionTypeEnum.CUT;
        const targetList = Array.isArray(recordCharts.charts) ? recordCharts.charts : [recordCharts.charts];
        targetList.forEach((e) => {
          this.addComponentList(parseHandle(e), void 0, true);
          if (isCut) {
            this.setTargetSelectChart(e.id);
            this.removeComponentList(void 0, true);
          }
        });
        if (isCut)
          this.setRecordChart(void 0);
        plugin.loadingFinish();
      } catch (value) {
        plugin.loadingError();
      }
    },
    // * 撤回/前进 目标处理
    setBackAndSetForwardHandle(HistoryItem, isForward = false) {
      if (HistoryItem.targetType === chartHistoryStore_d.HistoryTargetTypeEnum.CANVAS) {
        this.editCanvas = HistoryItem.historyData[0];
        return;
      }
      this.setTargetSelectChart();
      let historyData = HistoryItem.historyData;
      if (type.isArray(historyData)) {
        historyData.forEach((item) => {
          this.setTargetSelectChart(item.id, true);
        });
      }
      const isAdd = HistoryItem.actionType === chartHistoryStore_d.HistoryActionTypeEnum.ADD;
      const isDel = HistoryItem.actionType === chartHistoryStore_d.HistoryActionTypeEnum.DELETE;
      if (isAdd || isDel) {
        if (isAdd && isForward || isDel && !isForward) {
          historyData.forEach((item) => {
            this.addComponentList(item);
          });
          return;
        }
        historyData.forEach((item) => {
          this.removeComponentList(item.id, false);
        });
        return;
      }
      const isMove = HistoryItem.actionType === chartHistoryStore_d.HistoryActionTypeEnum.MOVE;
      if (isMove) {
        historyData.forEach((item) => {
          this.resetComponentPosition(item, isForward);
        });
        return;
      }
      const isTop = HistoryItem.actionType === chartHistoryStore_d.HistoryActionTypeEnum.TOP;
      const isBottom = HistoryItem.actionType === chartHistoryStore_d.HistoryActionTypeEnum.BOTTOM;
      if (isTop || isBottom) {
        if (!isForward) {
          if (isTop)
            this.getComponentList.pop();
          if (isBottom)
            this.getComponentList.shift();
          this.getComponentList.splice(historyData[0].attr.zIndex, 0, historyData[0]);
          return;
        }
        if (isTop)
          this.setTop(false);
        if (isBottom)
          this.setBottom(false);
      }
      const isUp = HistoryItem.actionType === chartHistoryStore_d.HistoryActionTypeEnum.UP;
      const isDown = HistoryItem.actionType === chartHistoryStore_d.HistoryActionTypeEnum.DOWN;
      if (isUp || isDown) {
        if (isUp && isForward || isDown && !isForward) {
          this.setUp(false);
          return;
        }
        this.setDown(false);
        return;
      }
      const isGroup = HistoryItem.actionType === chartHistoryStore_d.HistoryActionTypeEnum.GROUP;
      const isUnGroup = HistoryItem.actionType === chartHistoryStore_d.HistoryActionTypeEnum.UN_GROUP;
      if (isGroup || isUnGroup) {
        if (isGroup && isForward || isUnGroup && !isForward) {
          const ids = [];
          if (historyData.length > 1) {
            historyData.forEach((item) => {
              ids.push(item.id);
            });
          } else {
            const group = historyData[0];
            group.groupList.forEach((item) => {
              ids.unshift(item.id);
            });
          }
          this.setGroup(ids, false);
          return;
        }
        if (historyData.length > 1) {
          this.setUnGroup([historyData[0].id], void 0, false);
        } else {
          this.setUnGroup([historyData[0].groupList[0].id], void 0, false);
        }
        return;
      }
      const isLock = HistoryItem.actionType === chartHistoryStore_d.HistoryActionTypeEnum.LOCK;
      const isUnLock = HistoryItem.actionType === chartHistoryStore_d.HistoryActionTypeEnum.UNLOCK;
      if (isLock || isUnLock) {
        if (isLock && isForward || isUnLock && !isForward) {
          historyData.forEach((item) => {
            this.setLock(!item.status.lock, false);
          });
          return;
        }
        historyData.forEach((item) => {
          this.setUnLock(false);
        });
        return;
      }
      const isHide = HistoryItem.actionType === chartHistoryStore_d.HistoryActionTypeEnum.HIDE;
      const isShow = HistoryItem.actionType === chartHistoryStore_d.HistoryActionTypeEnum.SHOW;
      if (isHide || isShow) {
        if (isHide && isForward || isShow && !isForward) {
          historyData.forEach((item) => {
            this.setHide(!item.status.hide, false);
          });
          return;
        }
        historyData.forEach((item) => {
          this.setShow(false);
        });
        return;
      }
    },
    // * 撤回
    setBack() {
      try {
        plugin.loadingStart();
        const targetData = chartHistoryStore.backAction();
        if (!targetData) {
          plugin.loadingFinish();
          return;
        }
        this.setBackAndSetForwardHandle(targetData);
        plugin.loadingFinish();
      } catch (value) {
        plugin.loadingError();
      }
    },
    // * 前进
    setForward() {
      try {
        plugin.loadingStart();
        const targetData = chartHistoryStore.forwardAction();
        if (!targetData) {
          plugin.loadingFinish();
          return;
        }
        this.setBackAndSetForwardHandle(targetData, true);
        plugin.loadingFinish();
      } catch (value) {
        plugin.loadingError();
      }
    },
    // * 移动位置
    setMove(keyboardValue) {
      const index2 = this.fetchTargetIndex();
      if (index2 === -1)
        return;
      const attr = this.getComponentList[index2].attr;
      const distance = settingStore.getChartMoveDistance;
      switch (keyboardValue) {
        case editPageEnum.MenuEnum.ARROW_UP:
          attr.y -= distance;
          break;
        case editPageEnum.MenuEnum.ARROW_RIGHT:
          attr.x += distance;
          break;
        case editPageEnum.MenuEnum.ARROW_DOWN:
          attr.y += distance;
          break;
        case editPageEnum.MenuEnum.ARROW_LEFT:
          attr.x -= distance;
          break;
      }
    },
    // * 创建分组
    setGroup(id, isHistory = true) {
      try {
        const selectIds = this.idPreFormat(id) || this.getTargetChart.selectId;
        if (selectIds.length < 2)
          return;
        plugin.loadingStart();
        const groupClass = new publicConfig.PublicGroupConfigClass();
        const groupAttr = {
          l: this.getEditCanvasConfig.width,
          t: this.getEditCanvasConfig.height,
          r: 0,
          b: 0
        };
        const targetList = [];
        const historyList = [];
        const newSelectIds = [];
        selectIds.forEach((id2) => {
          const targetIndex = this.fetchTargetIndex(id2);
          if (targetIndex !== -1 && this.getComponentList[targetIndex].isGroup) {
            this.setUnGroup(
              [id2],
              (e) => {
                e.forEach((e2) => {
                  this.addComponentList(e2);
                  newSelectIds.push(e2.id);
                });
              },
              false
            );
          } else if (targetIndex !== -1) {
            newSelectIds.push(id2);
          }
        });
        newSelectIds.forEach((id2) => {
          const item = this.componentList.splice(this.fetchTargetIndex(id2), 1)[0];
          const { x, y, w, h } = item.attr;
          const { l, t, r, b } = groupAttr;
          groupAttr.l = l > x ? x : l;
          groupAttr.t = t > y ? y : t;
          groupAttr.r = r < x + w ? x + w : r;
          groupAttr.b = b < y + h ? y + h : b;
          targetList.unshift(item);
          historyList.push(reactivity_esmBundler.toRaw(item));
        });
        if (isHistory)
          chartHistoryStore.createGroupHistory(historyList);
        targetList.forEach((item) => {
          item.attr.x = item.attr.x - groupAttr.l;
          item.attr.y = item.attr.y - groupAttr.t;
          groupClass.groupList.push(item);
        });
        groupClass.attr.x = groupAttr.l;
        groupClass.attr.y = groupAttr.t;
        groupClass.attr.w = groupAttr.r - groupAttr.l;
        groupClass.attr.h = groupAttr.b - groupAttr.t;
        this.addComponentList(groupClass);
        this.setTargetSelectChart(groupClass.id);
        plugin.loadingFinish();
      } catch (error) {
        console.log(error);
        window["$message"].error("创建分组失败，请联系管理员！");
        plugin.loadingFinish();
      }
    },
    // * 解除分组
    setUnGroup(ids, callBack, isHistory = true) {
      try {
        const selectGroupIdArr = ids || this.getTargetChart.selectId;
        if (selectGroupIdArr.length !== 1)
          return;
        plugin.loadingStart();
        const unGroup = (targetIndex2) => {
          const targetGroup = this.getComponentList[targetIndex2];
          if (!targetGroup.isGroup)
            return;
          if (isHistory)
            chartHistoryStore.createUnGroupHistory(cloneDeep.default([targetGroup]));
          targetGroup.groupList.reverse().forEach((item) => {
            item.attr.x = item.attr.x + targetGroup.attr.x;
            item.attr.y = item.attr.y + targetGroup.attr.y;
            if (!callBack) {
              this.addComponentList(item);
            }
          });
          this.setTargetSelectChart(targetGroup.id);
          this.removeComponentList(targetGroup.id, false);
          if (callBack) {
            callBack(targetGroup.groupList);
          }
        };
        const targetIndex = this.fetchTargetIndex(selectGroupIdArr[0]);
        if (targetIndex !== -1) {
          unGroup(targetIndex);
        }
        plugin.loadingFinish();
      } catch (error) {
        console.log(error);
        window["$message"].error("解除分组失败，请联系管理员！");
        plugin.loadingFinish();
      }
    },
    // * 锁定
    setLock(status = true, isHistory = true) {
      try {
        if (this.getTargetChart.selectId.length > 1)
          return;
        plugin.loadingStart();
        const index2 = this.fetchTargetIndex();
        if (index2 !== -1) {
          const targetItem = this.getComponentList[index2];
          targetItem.status.lock = status;
          if (isHistory) {
            status ? chartHistoryStore.createLockHistory([targetItem]) : chartHistoryStore.createUnLockHistory([targetItem]);
          }
          this.updateComponentList(index2, targetItem);
          if (status)
            this.setTargetSelectChart(void 0);
          plugin.loadingFinish();
          return;
        }
      } catch (value) {
        plugin.loadingError();
      }
    },
    // * 解除锁定
    setUnLock(isHistory = true) {
      this.setLock(false, isHistory);
    },
    // * 隐藏
    setHide(status = true, isHistory = true) {
      try {
        if (this.getTargetChart.selectId.length > 1)
          return;
        plugin.loadingStart();
        const index2 = this.fetchTargetIndex();
        if (index2 !== -1) {
          const targetItem = this.getComponentList[index2];
          targetItem.status.hide = status;
          if (isHistory) {
            status ? chartHistoryStore.createHideHistory([targetItem]) : chartHistoryStore.createShowHistory([targetItem]);
          }
          this.updateComponentList(index2, targetItem);
          plugin.loadingFinish();
          if (status)
            this.setTargetSelectChart(void 0);
        }
      } catch (value) {
        plugin.loadingError();
      }
    },
    // * 显示
    setShow(isHistory = true) {
      this.setHide(false, isHistory);
    },
    // ----------------
    // * 设置页面大小
    setPageSize(scale) {
      this.setPageStyle("height", `${this.editCanvasConfig.height * scale}px`);
      this.setPageStyle("width", `${this.editCanvasConfig.width * scale}px`);
    },
    // * 计算缩放
    computedScale() {
      if (this.getEditCanvas.editLayoutDom) {
        const width = this.getEditCanvas.editLayoutDom.clientWidth - this.getEditCanvas.offset * 2 - 5;
        const height = this.getEditCanvas.editLayoutDom.clientHeight - this.getEditCanvas.offset * 4;
        const editCanvasWidth = this.editCanvasConfig.width;
        const editCanvasHeight = this.editCanvasConfig.height;
        const baseProportion = parseFloat((editCanvasWidth / editCanvasHeight).toFixed(5));
        const currentRate = parseFloat((width / height).toFixed(5));
        if (currentRate > baseProportion) {
          const scaleWidth = parseFloat((height * baseProportion / editCanvasWidth).toFixed(5));
          this.setScale(scaleWidth > 1 ? 1 : scaleWidth);
        } else {
          const scaleHeight = parseFloat((width / baseProportion / editCanvasHeight).toFixed(5));
          this.setScale(scaleHeight > 1 ? 1 : scaleHeight);
        }
      } else {
        window["$message"].warning("请先创建画布，再进行缩放");
      }
    },
    // * 监听缩放
    listenerScale() {
      const resize = debounce.default(this.computedScale, 200);
      resize();
      window.addEventListener("resize", resize);
      const remove = () => {
        window.removeEventListener("resize", resize);
      };
      return remove;
    },
    /**
     * * 设置缩放
     * @param scale 0~1 number 缩放比例;
     * @param force boolean 强制缩放
     */
    setScale(scale, force = false) {
      if (!this.getEditCanvas.lockScale || force) {
        this.setPageSize(scale);
        this.getEditCanvas.userScale = scale;
        this.getEditCanvas.scale = scale;
      }
    }
  }
});
exports.useChartEditStore = useChartEditStore;
