function contextListener(e) {
	return function(t) {
		e.call(this, t, this.__data__);
	};
}
function parseTypenames(e) {
	return e.trim().split(/^|\s+/).map(function(e) {
		var t = "", n = e.indexOf(".");
		return n >= 0 && (t = e.slice(n + 1), e = e.slice(0, n)), {
			type: e,
			name: t
		};
	});
}
function onRemove(e) {
	return function() {
		var t = this.__on;
		if (t) {
			for (var n = 0, r = -1, i = t.length, a; n < i; ++n) a = t[n], (!e.type || a.type === e.type) && a.name === e.name ? this.removeEventListener(a.type, a.listener, a.options) : t[++r] = a;
			++r ? t.length = r : delete this.__on;
		}
	};
}
function onAdd(t, n, r) {
	return function() {
		var i = this.__on, a, o = contextListener(n);
		if (i) {
			for (var s = 0, c = i.length; s < c; ++s) if ((a = i[s]).type === t.type && a.name === t.name) {
				this.removeEventListener(a.type, a.listener, a.options), this.addEventListener(a.type, a.listener = o, a.options = r), a.value = n;
				return;
			}
		}
		this.addEventListener(t.type, o, r), a = {
			type: t.type,
			name: t.name,
			value: n,
			listener: o,
			options: r
		}, i ? i.push(a) : this.__on = [a];
	};
}
function on_default(e, i, a) {
	var o = parseTypenames(e + ""), s, c = o.length, l;
	if (arguments.length < 2) {
		var u = this.node().__on;
		if (u) {
			for (var d = 0, f = u.length, p; d < f; ++d) for (s = 0, p = u[d]; s < c; ++s) if ((l = o[s]).type === p.type && l.name === p.name) return p.value;
		}
		return;
	}
	for (u = i ? onAdd : onRemove, s = 0; s < c; ++s) this.each(u(o[s], i, a));
	return this;
}
export { on_default as default };
