import { set as n, unset as e$1 } from "../../util/Cursor.mjs";
import { install as o } from "../../util/ClickTrap.mjs";
import { delta as e } from "../../util/PositionUtil.mjs";
import { closest as D, event as m } from "../../../../min-dom/dist/index.esm.mjs";
import { toPoint as r } from "../../util/Event.mjs";
var y = 15;
function x(o$1, m$1) {
  var n$1;
  o$1.on("element.mousedown", 500, function(t) {
    return f(t.originalEvent);
  });
  function i(t) {
    var r$1 = n$1.start, c = n$1.button, u = r(t), e$12 = e(u, r$1);
    if (!n$1.dragging && M(e$12) > y && (n$1.dragging = true, c === 0 && o(o$1), n("grab")), n$1.dragging) {
      var g = n$1.last || n$1.start;
      e$12 = e(u, g), m$1.scroll({
        dx: e$12.x,
        dy: e$12.y
      }), n$1.last = u;
    }
    t.preventDefault();
  }
  function s(t) {
    m.unbind(document, "mousemove", i), m.unbind(document, "mouseup", s), n$1 = null, e$1();
  }
  function f(t) {
    if (!D(t.target, ".djs-draggable")) {
      var r$1 = t.button;
      if (!(r$1 >= 2 || t.ctrlKey || t.shiftKey || t.altKey))
        return n$1 = {
          button: r$1,
          start: r(t)
        }, m.bind(document, "mousemove", i), m.bind(document, "mouseup", s), true;
    }
  }
  this.isActive = function() {
    return !!n$1;
  };
}
x.$inject = [
  "eventBus",
  "canvas"
];
function M(o2) {
  return Math.sqrt(Math.pow(o2.x, 2) + Math.pow(o2.y, 2));
}
export {
  x as default
};
