import { assign as q, forEach as o } from "../../../../min-dash/dist/index.esm.mjs";
import { queryAll as X, query as K, delegate as z } from "../../../../min-dom/dist/index.esm.mjs";
import { isPrimaryButton as o$1, isAuxiliaryButton as e } from "../../util/Mouse.mjs";
import { remove as A, create as M, attr as N, append as _ } from "../../../../tiny-svg/dist/index.esm.mjs";
import { createLine as f, updateLine as p } from "../../util/RenderUtil.mjs";
function V(r) {
  return true;
}
function u(r) {
  return o$1(r) || e(r);
}
var k = 500;
function G(r, h, j) {
  var m = this;
  function c(e2, t, i) {
    if (!L(e2, t)) {
      var n, o2, s;
      i ? o2 = h.getGraphics(i) : (n = t.delegateTarget || t.target, n && (o2 = n, i = h.get(o2))), !(!o2 || !i) && (s = r.fire(e2, {
        element: i,
        gfx: o2,
        originalEvent: t
      }), s === false && (t.stopPropagation(), t.preventDefault()));
    }
  }
  var g = {};
  function v(e2) {
    return g[e2];
  }
  function L(e2, t) {
    var i = p$1[e2] || o$1;
    return !i(t);
  }
  var l = {
    click: "element.click",
    contextmenu: "element.contextmenu",
    dblclick: "element.dblclick",
    mousedown: "element.mousedown",
    mousemove: "element.mousemove",
    mouseover: "element.hover",
    mouseout: "element.out",
    mouseup: "element.mouseup"
  }, p$1 = {
    "element.contextmenu": V,
    "element.mousedown": u,
    "element.mouseup": u,
    "element.click": u,
    "element.dblclick": u
  };
  function I(e2, t, i) {
    var n = l[e2];
    if (!n)
      throw new Error("unmapped DOM event name <" + e2 + ">");
    return c(n, t, i);
  }
  var S = "svg, .djs-element";
  function E(e2, t, i, n) {
    var o2 = g[i] = function(s) {
      c(i, s);
    };
    n && (p$1[i] = n), o2.$delegate = z.bind(e2, S, t, o2);
  }
  function H(e2, t, i) {
    var n = v(i);
    n && z.unbind(e2, t, n.$delegate);
  }
  function b(e2) {
    o(l, function(t, i) {
      E(e2, i, t);
    });
  }
  function O(e2) {
    o(l, function(t, i) {
      H(e2, i, t);
    });
  }
  r.on("canvas.destroy", function(e2) {
    O(e2.svg);
  }), r.on("canvas.init", function(e2) {
    b(e2.svg);
  }), r.on(["shape.added", "connection.added"], function(e2) {
    var t = e2.element, i = e2.gfx;
    r.fire("interactionEvents.createHit", { element: t, gfx: i });
  }), r.on([
    "shape.changed",
    "connection.changed"
  ], k, function(e2) {
    var t = e2.element, i = e2.gfx;
    r.fire("interactionEvents.updateHit", { element: t, gfx: i });
  }), r.on("interactionEvents.createHit", k, function(e2) {
    var t = e2.element, i = e2.gfx;
    m.createDefaultHit(t, i);
  }), r.on("interactionEvents.updateHit", function(e2) {
    var t = e2.element, i = e2.gfx;
    m.updateDefaultHit(t, i);
  });
  var A$1 = a("djs-hit djs-hit-stroke"), D = a("djs-hit djs-hit-click-stroke"), Y = a("djs-hit djs-hit-all"), M$1 = a("djs-hit djs-hit-no-move"), P = {
    all: Y,
    "click-stroke": D,
    stroke: A$1,
    "no-move": M$1
  };
  function a(e2, t) {
    return t = q({
      stroke: "white",
      strokeWidth: 15
    }, t || {}), j.cls(e2, ["no-fill", "no-border"], t);
  }
  function x(e2, t) {
    var i = P[t];
    if (!i)
      throw new Error("invalid hit type <" + t + ">");
    return N(e2, i), e2;
  }
  function w(e2, t) {
    _(e2, t);
  }
  this.removeHits = function(e2) {
    var t = X(".djs-hit", e2);
    o(t, A);
  }, this.createDefaultHit = function(e2, t) {
    var i = e2.waypoints, n = e2.isFrame, o2;
    return i ? this.createWaypointsHit(t, i) : (o2 = n ? "stroke" : "all", this.createBoxHit(t, o2, {
      width: e2.width,
      height: e2.height
    }));
  }, this.createWaypointsHit = function(e2, t) {
    var i = f(t);
    return x(i, "stroke"), w(e2, i), i;
  }, this.createBoxHit = function(e2, t, i) {
    i = q({
      x: 0,
      y: 0
    }, i);
    var n = M("rect");
    return x(n, t), N(n, i), w(e2, n), n;
  }, this.updateDefaultHit = function(e2, t) {
    var i = K(".djs-hit", t);
    if (i)
      return e2.waypoints ? p(i, e2.waypoints) : N(i, {
        width: e2.width,
        height: e2.height
      }), i;
  }, this.fire = c, this.triggerMouseEvent = I, this.mouseHandler = v, this.registerEvent = E, this.unregisterEvent = H;
}
G.$inject = [
  "eventBus",
  "elementRegistry",
  "styles"
];
export {
  G as default
};
