"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
require("../../../../node_modules/.pnpm/dom-helpers@5.2.1/node_modules/dom-helpers/esm/addEventListener.js");
const listen = require("../../../../node_modules/.pnpm/dom-helpers@5.2.1/node_modules/dom-helpers/esm/listen.js");
require("../../../../node_modules/.pnpm/dom-helpers@5.2.1/node_modules/dom-helpers/esm/animationFrame.js");
require("../../../../node_modules/.pnpm/dom-helpers@5.2.1/node_modules/dom-helpers/esm/childNodes.js");
require("../../../../node_modules/.pnpm/dom-helpers@5.2.1/node_modules/dom-helpers/esm/querySelectorAll.js");
const throttle = require("../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/throttle.js");
let prevMoveXValue = [0, 0];
let prevMoveYValue = [0, 0];
const dragCanvas = (e) => {
  var _a, _b;
  const previewBoxDom = document.querySelector(".go-preview");
  if (!previewBoxDom || previewBoxDom.style.position !== "absolute")
    return;
  if (!((_a = window.$KeyboardActive) == null ? void 0 : _a.space))
    return;
  e.preventDefault();
  e.stopPropagation();
  (_b = document.activeElement) == null ? void 0 : _b.blur();
  const startX = e.screenX;
  const startY = e.screenY;
  const listenMousemove = listen.default(
    window,
    "mousemove",
    throttle.default((moveEvent) => {
      const nx = moveEvent.screenX - startX;
      const ny = moveEvent.screenY - startY;
      const [prevMoveX1, prevMoveX2] = prevMoveXValue;
      const [prevMoveY1, prevMoveY2] = prevMoveYValue;
      prevMoveXValue = [prevMoveX2, nx];
      prevMoveYValue = [prevMoveY2, ny];
      if (previewBoxDom) {
        const oldLeft = previewBoxDom.style.left ? Number(previewBoxDom.style.left.split("px")[0]) : 0;
        const oldTop = previewBoxDom.style.top ? Number(previewBoxDom.style.top.split("px")[0]) : 0;
        previewBoxDom.style.left = oldLeft + (prevMoveX2 > prevMoveX1 ? Math.abs(prevMoveX2 - prevMoveX1) : -Math.abs(prevMoveX2 - prevMoveX1)) + "px";
        previewBoxDom.style.top = oldTop + (prevMoveY2 > prevMoveY1 ? Math.abs(prevMoveY2 - prevMoveY1) : -Math.abs(prevMoveY2 - prevMoveY1)) + "px";
      }
    }, 20)
  );
  const listenMouseup = listen.default(window, "mouseup", () => {
    prevMoveXValue = [0, 0];
    prevMoveYValue = [0, 0];
    listenMousemove();
    listenMouseup();
  });
};
exports.dragCanvas = dragCanvas;
