"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const throttle = require("../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/throttle.js");
const usePreviewFitScale = (width, height, scaleDom, callback) => {
  const baseWidth = width;
  const baseHeight = height;
  const scale = {
    width: 1,
    height: 1
  };
  const baseProportion = parseFloat((baseWidth / baseHeight).toFixed(5));
  const calcRate = () => {
    const currentRate = parseFloat(
      (window.innerWidth / window.innerHeight).toFixed(5)
    );
    if (scaleDom) {
      if (currentRate > baseProportion) {
        scale.width = parseFloat((window.innerHeight * baseProportion / baseWidth).toFixed(5));
        scale.height = parseFloat((window.innerHeight / baseHeight).toFixed(5));
        scaleDom.style.transform = `scale(${scale.width}, ${scale.height})`;
      } else {
        scale.height = parseFloat((window.innerWidth / baseProportion / baseHeight).toFixed(5));
        scale.width = parseFloat((window.innerWidth / baseWidth).toFixed(5));
        scaleDom.style.transform = `scale(${scale.width}, ${scale.height})`;
      }
      if (callback)
        callback(scale);
    }
  };
  const resize = throttle.default(() => {
    calcRate();
  }, 200);
  const windowResize = () => {
    window.addEventListener("resize", resize);
  };
  const unWindowResize = () => {
    window.removeEventListener("resize", resize);
  };
  return {
    calcRate,
    windowResize,
    unWindowResize
  };
};
const usePreviewScrollYScale = (width, height, scaleDom, callback) => {
  const baseWidth = width;
  const baseHeight = height;
  const scale = {
    width: 1,
    height: 1
  };
  const baseProportion = parseFloat((baseWidth / baseHeight).toFixed(5));
  const calcRate = () => {
    if (scaleDom) {
      scale.height = parseFloat((window.innerWidth / baseProportion / baseHeight).toFixed(5));
      scale.width = parseFloat((window.innerWidth / baseWidth).toFixed(5));
      scaleDom.style.transform = `scale(${scale.width}, ${scale.height})`;
      if (callback)
        callback(scale);
    }
  };
  const resize = throttle.default(() => {
    calcRate();
  }, 200);
  const windowResize = () => {
    window.addEventListener("resize", resize);
  };
  const unWindowResize = () => {
    window.removeEventListener("resize", resize);
  };
  return {
    calcRate,
    windowResize,
    unWindowResize
  };
};
const usePreviewScrollXScale = (width, height, scaleDom, callback) => {
  const baseWidth = width;
  const baseHeight = height;
  const scale = {
    height: 1,
    width: 1
  };
  const baseProportion = parseFloat((baseWidth / baseHeight).toFixed(5));
  const calcRate = () => {
    if (scaleDom) {
      scale.width = parseFloat((window.innerHeight * baseProportion / baseWidth).toFixed(5));
      scale.height = parseFloat((window.innerHeight / baseHeight).toFixed(5));
      scaleDom.style.transform = `scale(${scale.width}, ${scale.height})`;
      if (callback)
        callback(scale);
    }
  };
  const resize = throttle.default(() => {
    calcRate();
  }, 200);
  const windowResize = () => {
    window.addEventListener("resize", resize);
  };
  const unWindowResize = () => {
    window.removeEventListener("resize", resize);
  };
  return {
    calcRate,
    windowResize,
    unWindowResize
  };
};
const usePreviewFullScale = (width, height, scaleDom, callback) => {
  const scale = {
    width: 1,
    height: 1
  };
  const calcRate = () => {
    if (scaleDom) {
      scale.width = parseFloat((window.innerWidth / width).toFixed(5));
      scale.height = parseFloat((window.innerHeight / height).toFixed(5));
      scaleDom.style.transform = `scale(${scale.width}, ${scale.height})`;
      if (callback)
        callback(scale);
    }
  };
  const resize = throttle.default(() => {
    calcRate();
  }, 200);
  const windowResize = () => {
    window.addEventListener("resize", resize);
  };
  const unWindowResize = () => {
    window.removeEventListener("resize", resize);
  };
  return {
    calcRate,
    windowResize,
    unWindowResize
  };
};
exports.usePreviewFitScale = usePreviewFitScale;
exports.usePreviewFullScale = usePreviewFullScale;
exports.usePreviewScrollXScale = usePreviewScrollXScale;
exports.usePreviewScrollYScale = usePreviewScrollYScale;
