"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");
require("../../../store/modules/designStore/designStore.js");
require("../../../settings/designSetting.js");
require("../../../../node_modules/.pnpm/screenfull@6.0.2/node_modules/screenfull/index.js");
require("../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_root.js");
require("../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseGetTag.js");
require("../../../../node_modules/.pnpm/html2canvas@1.4.1/node_modules/html2canvas/dist/html2canvas.esm.js");
require("../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseClone.js");
require("../../../../node_modules/.pnpm/crypto-js@4.1.1/node_modules/crypto-js/index.js");
require("../../../enums/pageEnum.js");
require("../../../router/index.js");
require("../../../../node_modules/.pnpm/vue3-lazyload@0.2.5-beta_a6dezdz3je235ci4e3tu4rayna/node_modules/vue3-lazyload/dist/vue3-lazyload.esm.js");
require("../../../components/GoSkeleton/index.vue.js");
require("../../../components/GoLoading/index.js");
const usePreviewScale_hook = require("../../../hooks/usePreviewScale.hook.js");
require("../../../api/axios.js");
require("../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/merge.js");
require("../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/pick.js");
require("../../../../node_modules/.pnpm/echarts@5.4.3/node_modules/echarts/index.js");
const styleEnum = require("../../../enums/styleEnum.js");
require("../../../store/modules/langStore/langStore.js");
const reactivity_esmBundler = require("../../../../node_modules/.pnpm/@vue_reactivity@3.3.4/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js");
const runtimeCore_esmBundler = require("../../../../node_modules/.pnpm/@vue_runtime-core@3.3.4/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js");
const SCALE_KEY = "scale-value";
const useScale = (localStorageInfo) => {
  const entityRef = reactivity_esmBundler.ref();
  const previewRef = reactivity_esmBundler.ref();
  const width = reactivity_esmBundler.ref(localStorageInfo.editCanvasConfig.width);
  const height = reactivity_esmBundler.ref(localStorageInfo.editCanvasConfig.height);
  const scaleRef = reactivity_esmBundler.ref({ width: 1, height: 1 });
  runtimeCore_esmBundler.provide(SCALE_KEY, scaleRef);
  const useAddWheelHandle = (removeEvent) => {
    addEventListener(
      "wheel",
      (e) => {
        var _a, _b;
        if ((_a = window == null ? void 0 : window.$KeyboardActive) == null ? void 0 : _a.ctrl) {
          e.preventDefault();
          e.stopPropagation();
          removeEvent();
          const transform = (_b = previewRef.value) == null ? void 0 : _b.style.transform;
          const regRes = transform.match(/scale\((\d+\.?\d*)*/);
          const width2 = regRes[1];
          const previewBoxDom = document.querySelector(".go-preview");
          const entityDom = document.querySelector(".go-preview-entity");
          if (previewBoxDom) {
            previewBoxDom.style.overflow = "unset";
            previewBoxDom.style.position = "absolute";
          }
          if (entityDom) {
            entityDom.style.overflow = "unset";
          }
          if (e.wheelDelta > 0) {
            const resNum = parseFloat(Number(width2).toFixed(2));
            previewRef.value.style.transform = `scale(${resNum > 5 ? 5 : resNum + 0.1})`;
          } else {
            const resNum = parseFloat(Number(width2).toFixed(2));
            previewRef.value.style.transform = `scale(${resNum < 0.2 ? 0.2 : resNum - 0.1})`;
          }
        }
      },
      { passive: false }
    );
  };
  const updateScaleRef = (scale) => {
    scaleRef.value = { ...scale };
  };
  runtimeCore_esmBundler.onMounted(() => {
    switch (localStorageInfo.editCanvasConfig.previewScaleType) {
      case styleEnum.PreviewScaleEnum.FIT:
        (() => {
          const { calcRate, windowResize, unWindowResize } = usePreviewScale_hook.usePreviewFitScale(
            width.value,
            height.value,
            previewRef.value,
            updateScaleRef
          );
          calcRate();
          windowResize();
          useAddWheelHandle(unWindowResize);
          runtimeCore_esmBundler.onUnmounted(() => {
            unWindowResize();
          });
        })();
        break;
      case styleEnum.PreviewScaleEnum.SCROLL_Y:
        (() => {
          const { calcRate, windowResize, unWindowResize } = usePreviewScale_hook.usePreviewScrollYScale(
            width.value,
            height.value,
            previewRef.value,
            (scale) => {
              const dom = entityRef.value;
              dom.style.width = `${width.value * scale.width}px`;
              dom.style.height = `${height.value * scale.height}px`;
              updateScaleRef(scale);
            }
          );
          calcRate();
          windowResize();
          useAddWheelHandle(unWindowResize);
          runtimeCore_esmBundler.onUnmounted(() => {
            unWindowResize();
          });
        })();
        break;
      case styleEnum.PreviewScaleEnum.SCROLL_X:
        (() => {
          const { calcRate, windowResize, unWindowResize } = usePreviewScale_hook.usePreviewScrollXScale(
            width.value,
            height.value,
            previewRef.value,
            (scale) => {
              const dom = entityRef.value;
              dom.style.width = `${width.value * scale.width}px`;
              dom.style.height = `${height.value * scale.height}px`;
              updateScaleRef(scale);
            }
          );
          calcRate();
          windowResize();
          useAddWheelHandle(unWindowResize);
          runtimeCore_esmBundler.onUnmounted(() => {
            unWindowResize();
          });
        })();
        break;
      case styleEnum.PreviewScaleEnum.FULL:
        (() => {
          const { calcRate, windowResize, unWindowResize } = usePreviewScale_hook.usePreviewFullScale(
            width.value,
            height.value,
            previewRef.value,
            updateScaleRef
          );
          calcRate();
          windowResize();
          useAddWheelHandle(unWindowResize);
          runtimeCore_esmBundler.onUnmounted(() => {
            unWindowResize();
          });
        })();
        break;
    }
  });
  return {
    entityRef,
    previewRef,
    scaleRef
  };
};
exports.SCALE_KEY = SCALE_KEY;
exports.useScale = useScale;
