var noop = { value: () => {} };
function dispatch() {
	for (var e = 0, t = arguments.length, r = {}, i; e < t; ++e) {
		if (!(i = arguments[e] + "") || i in r || /[\s.]/.test(i)) throw Error("illegal type: " + i);
		r[i] = [];
	}
	return new Dispatch(r);
}
function Dispatch(e) {
	this._ = e;
}
function parseTypenames(e, t) {
	return e.trim().split(/^|\s+/).map(function(e) {
		var n = "", r = e.indexOf(".");
		if (r >= 0 && (n = e.slice(r + 1), e = e.slice(0, r)), e && !t.hasOwnProperty(e)) throw Error("unknown type: " + e);
		return {
			type: e,
			name: n
		};
	});
}
Dispatch.prototype = dispatch.prototype = {
	constructor: Dispatch,
	on: function(e, t) {
		var n = this._, o = parseTypenames(e + "", n), s, c = -1, l = o.length;
		if (arguments.length < 2) {
			for (; ++c < l;) if ((s = (e = o[c]).type) && (s = get(n[s], e.name))) return s;
			return;
		}
		if (t != null && typeof t != "function") throw Error("invalid callback: " + t);
		for (; ++c < l;) if (s = (e = o[c]).type) n[s] = set(n[s], e.name, t);
		else if (t == null) for (s in n) n[s] = set(n[s], e.name, null);
		return this;
	},
	copy: function() {
		var e = {}, t = this._;
		for (var r in t) e[r] = t[r].slice();
		return new Dispatch(e);
	},
	call: function(e, t) {
		if ((i = arguments.length - 2) > 0) for (var n = Array(i), r = 0, i, a; r < i; ++r) n[r] = arguments[r + 2];
		if (!this._.hasOwnProperty(e)) throw Error("unknown type: " + e);
		for (a = this._[e], r = 0, i = a.length; r < i; ++r) a[r].value.apply(t, n);
	},
	apply: function(e, t, n) {
		if (!this._.hasOwnProperty(e)) throw Error("unknown type: " + e);
		for (var r = this._[e], i = 0, a = r.length; i < a; ++i) r[i].value.apply(t, n);
	}
};
function get(e, t) {
	for (var n = 0, r = e.length, i; n < r; ++n) if ((i = e[n]).name === t) return i.value;
}
function set(t, n, r) {
	for (var i = 0, a = t.length; i < a; ++i) if (t[i].name === n) {
		t[i] = noop, t = t.slice(0, i).concat(t.slice(i + 1));
		break;
	}
	return r != null && t.push({
		name: n,
		value: r
	}), t;
}
var dispatch_default = dispatch;
export { dispatch_default as default };
