/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var VueCompositionAPI = require('@vue/composition-api');

function useDrag(initTransform) {
  const transform = VueCompositionAPI.ref(initTransform);
  const mouseDownHandler = e => {
    const {
      pageX: startX,
      pageY: startY
    } = e;
    const {
      translateX,
      translateY
    } = transform.value;
    const mouseMoveHandler = e2 => {
      const {
        pageX,
        pageY
      } = e2;
      transform.value = {
        translateX: translateX + pageX - startX,
        translateY: translateY + pageY - startY
      };
    };
    const mouseUpHandler = () => {
      document.removeEventListener("mousemove", mouseMoveHandler);
      document.removeEventListener("mouseup", mouseUpHandler);
    };
    document.addEventListener("mousemove", mouseMoveHandler);
    document.addEventListener("mouseup", mouseUpHandler);
  };
  const resetTransform = () => {
    transform.value = {
      ...initTransform
    };
  };
  return {
    transform,
    mouseDownHandler,
    resetTransform
  };
}
function useMirror() {
  const mirror = VueCompositionAPI.ref(1);
  const onMirror = () => {
    mirror.value *= -1;
  };
  const resetMirror = () => {
    mirror.value = 1;
  };
  return {
    mirror,
    onMirror,
    resetMirror
  };
}
function useScale() {
  let imageScale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
    max: 2,
    min: 0.5,
    step: 0.5
  };
  const {
    max,
    min,
    step
  } = imageScale;
  const scale = VueCompositionAPI.ref(1);
  const onZoomIn = () => {
    setScale(scale.value + step);
  };
  const onZoomOut = () => {
    setScale(scale.value - step);
  };
  const resetScale = () => {
    scale.value = 1;
  };
  const setScale = newScale => {
    let value = newScale;
    if (newScale < min) value = min;
    if (newScale > max) value = max;
    scale.value = value;
  };
  return {
    scale,
    onZoomIn,
    onZoomOut,
    resetScale
  };
}
function useRotate() {
  const rotate = VueCompositionAPI.ref(0);
  const ROTATE_DEG = 90;
  const onRotate = () => {
    rotate.value += ROTATE_DEG;
  };
  const resetRotate = () => {
    rotate.value = 0;
  };
  return {
    rotate,
    onRotate,
    resetRotate
  };
}

exports.useDrag = useDrag;
exports.useMirror = useMirror;
exports.useRotate = useRotate;
exports.useScale = useScale;
//# sourceMappingURL=index.js.map
