var E = { value: () => {
} };
function I() {
  for (var n = 0, e = arguments.length, t = {}, r; n < e; ++n) {
    if (!(r = arguments[n] + "") || r in t || /[\s.]/.test(r)) throw new Error("illegal type: " + r);
    t[r] = [];
  }
  return new h(t);
}
function h(n) {
  this._ = n;
}
function F(n, e) {
  return n.trim().split(/^|\s+/).map(function(t) {
    var r = "", i = t.indexOf(".");
    if (i >= 0 && (r = t.slice(i + 1), t = t.slice(0, i)), t && !e.hasOwnProperty(t)) throw new Error("unknown type: " + t);
    return { type: t, name: r };
  });
}
h.prototype = I.prototype = {
  constructor: h,
  on: function(n, e) {
    var t = this._, r = F(n + "", t), i, o = -1, y = r.length;
    if (arguments.length < 2) {
      for (; ++o < y; ) if ((i = (n = r[o]).type) && (i = O(t[i], n.name))) return i;
      return;
    }
    if (e != null && typeof e != "function") throw new Error("invalid callback: " + e);
    for (; ++o < y; )
      if (i = (n = r[o]).type) t[i] = g(t[i], n.name, e);
      else if (e == null) for (i in t) t[i] = g(t[i], n.name, null);
    return this;
  },
  copy: function() {
    var n = {}, e = this._;
    for (var t in e) n[t] = e[t].slice();
    return new h(n);
  },
  call: function(n, e) {
    if ((i = arguments.length - 2) > 0) for (var t = new Array(i), r = 0, i, o; r < i; ++r) t[r] = arguments[r + 2];
    if (!this._.hasOwnProperty(n)) throw new Error("unknown type: " + n);
    for (o = this._[n], r = 0, i = o.length; r < i; ++r) o[r].value.apply(e, t);
  },
  apply: function(n, e, t) {
    if (!this._.hasOwnProperty(n)) throw new Error("unknown type: " + n);
    for (var r = this._[n], i = 0, o = r.length; i < o; ++i) r[i].value.apply(e, t);
  }
};
function O(n, e) {
  for (var t = 0, r = n.length, i; t < r; ++t)
    if ((i = n[t]).name === e)
      return i.value;
}
function g(n, e, t) {
  for (var r = 0, i = n.length; r < i; ++r)
    if (n[r].name === e) {
      n[r] = E, n = n.slice(0, r).concat(n.slice(r + 1));
      break;
    }
  return t != null && n.push({ name: e, value: t }), n;
}
var a = 0, u = 0, f = 0, k = 1e3, w, s, p = 0, l = 0, m = 0, c = typeof performance == "object" && performance.now ? performance : Date, x = typeof window == "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(n) {
  setTimeout(n, 17);
};
function T() {
  return l || (x(A), l = c.now() + m);
}
function A() {
  l = 0;
}
function _() {
  this._call = this._time = this._next = null;
}
_.prototype = D.prototype = {
  constructor: _,
  restart: function(n, e, t) {
    if (typeof n != "function") throw new TypeError("callback is not a function");
    t = (t == null ? T() : +t) + (e == null ? 0 : +e), !this._next && s !== this && (s ? s._next = this : w = this, s = this), this._call = n, this._time = t, v();
  },
  stop: function() {
    this._call && (this._call = null, this._time = 1 / 0, v());
  }
};
function D(n, e, t) {
  var r = new _();
  return r.restart(n, e, t), r;
}
function P() {
  T(), ++a;
  for (var n = w, e; n; )
    (e = l - n._time) >= 0 && n._call.call(void 0, e), n = n._next;
  --a;
}
function d() {
  l = (p = c.now()) + m, a = u = 0;
  try {
    P();
  } finally {
    a = 0, q(), l = 0;
  }
}
function j() {
  var n = c.now(), e = n - p;
  e > k && (m -= e, p = n);
}
function q() {
  for (var n, e = w, t, r = 1 / 0; e; )
    e._call ? (r > e._time && (r = e._time), n = e, e = e._next) : (t = e._next, e._next = null, e = n ? n._next = t : w = t);
  s = n, v(r);
}
function v(n) {
  if (!a) {
    u && (u = clearTimeout(u));
    var e = n - l;
    e > 24 ? (n < 1 / 0 && (u = setTimeout(d, n - c.now() - m)), f && (f = clearInterval(f))) : (f || (p = c.now(), f = setInterval(j, k)), a = 1, x(d));
  }
}
export {
  _ as T,
  I as d,
  T as n,
  D as t
};
