import e from "../../d3-dispatch/src/dispatch.js";
import t from "../../d3-selection/src/select.js";
import n from "../../d3-selection/src/pointer.js";
import r, { nonpassive as i, nonpassivecapture as a, nopropagation as o } from "./noevent.js";
import s, { yesdrag as c } from "./nodrag.js";
import l from "./constant.js";
import u from "./event.js";
//#region ../../node_modules/d3-drag/src/drag.js
function d(e) {
	return !e.ctrlKey && !e.button;
}
function f() {
	return this.parentNode;
}
function p(e, t) {
	return t ?? {
		x: e.x,
		y: e.y
	};
}
function m() {
	return navigator.maxTouchPoints || "ontouchstart" in this;
}
function h() {
	var h = d, g = f, _ = p, v = m, y = {}, b = e("start", "drag", "end"), x = 0, S, C, w, T, E = 0;
	function D(e) {
		e.on("mousedown.drag", O).filter(v).on("touchstart.drag", j).on("touchmove.drag", M, i).on("touchend.drag touchcancel.drag", N).style("touch-action", "none").style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
	}
	function O(e, n) {
		if (!(T || !h.call(this, e, n))) {
			var r = P(this, g.call(this, e, n), e, n, "mouse");
			r && (t(e.view).on("mousemove.drag", k, a).on("mouseup.drag", A, a), s(e.view), o(e), w = !1, S = e.clientX, C = e.clientY, r("start", e));
		}
	}
	function k(e) {
		if (r(e), !w) {
			var t = e.clientX - S, n = e.clientY - C;
			w = t * t + n * n > E;
		}
		y.mouse("drag", e);
	}
	function A(e) {
		t(e.view).on("mousemove.drag mouseup.drag", null), c(e.view, w), r(e), y.mouse("end", e);
	}
	function j(e, t) {
		if (h.call(this, e, t)) {
			var n = e.changedTouches, r = g.call(this, e, t), i = n.length, a, s;
			for (a = 0; a < i; ++a) (s = P(this, r, e, t, n[a].identifier, n[a])) && (o(e), s("start", e, n[a]));
		}
	}
	function M(e) {
		var t = e.changedTouches, n = t.length, i, a;
		for (i = 0; i < n; ++i) (a = y[t[i].identifier]) && (r(e), a("drag", e, t[i]));
	}
	function N(e) {
		var t = e.changedTouches, n = t.length, r, i;
		for (T && clearTimeout(T), T = setTimeout(function() {
			T = null;
		}, 500), r = 0; r < n; ++r) (i = y[t[r].identifier]) && (o(e), i("end", e, t[r]));
	}
	function P(e, t, r, i, a, o) {
		var s = b.copy(), c = n(o || r, t), l, d, f;
		if ((f = _.call(e, new u("beforestart", {
			sourceEvent: r,
			target: D,
			identifier: a,
			active: x,
			x: c[0],
			y: c[1],
			dx: 0,
			dy: 0,
			dispatch: s
		}), i)) != null) return l = f.x - c[0] || 0, d = f.y - c[1] || 0, function r(o, p, m) {
			var h = c, g;
			switch (o) {
				case "start":
					y[a] = r, g = x++;
					break;
				case "end": delete y[a], --x;
				case "drag":
					c = n(m || p, t), g = x;
					break;
			}
			s.call(o, e, new u(o, {
				sourceEvent: p,
				subject: f,
				target: D,
				identifier: a,
				active: g,
				x: c[0] + l,
				y: c[1] + d,
				dx: c[0] - h[0],
				dy: c[1] - h[1],
				dispatch: s
			}), i);
		};
	}
	return D.filter = function(e) {
		return arguments.length ? (h = typeof e == "function" ? e : l(!!e), D) : h;
	}, D.container = function(e) {
		return arguments.length ? (g = typeof e == "function" ? e : l(e), D) : g;
	}, D.subject = function(e) {
		return arguments.length ? (_ = typeof e == "function" ? e : l(e), D) : _;
	}, D.touchable = function(e) {
		return arguments.length ? (v = typeof e == "function" ? e : l(!!e), D) : v;
	}, D.on = function() {
		var e = b.on.apply(b, arguments);
		return e === b ? D : e;
	}, D.clickDistance = function(e) {
		return arguments.length ? (E = (e = +e) * e, D) : Math.sqrt(E);
	}, D;
}
//#endregion
export { h as default };
