var L = (e, t, i) => new Promise((s, n) => {
  var o = (r) => {
    try {
      l(i.next(r));
    } catch (d) {
      n(d);
    }
  }, c = (r) => {
    try {
      l(i.throw(r));
    } catch (d) {
      n(d);
    }
  }, l = (r) => r.done ? s(r.value) : Promise.resolve(r.value).then(o, c);
  l((i = i.apply(e, t)).next());
});
import { easings as se, Globals as q, createStringInterpolator as ne, useMemoOne as oe, createInterpolator as ae, isEqual as E, is as a, getFluidValue as O, toArray as R, each as S, frameLoop as _t, callFluidObservers as st, FluidValue as re, deprecateInterpolate as ue, useForceUpdate as ce, usePrev as St, useIsomorphicLayoutEffect as he, useOnce as de, hasFluidValue as U, addFluidObserver as ot, removeFluidObserver as Dt, eachProp as $, flush as it, flushCalls as J, noop as At, deprecateDirectCall as le, isAnimatedString as Nt, getFluidObservers as wt } from "../../shared/dist/react-spring-shared.esm.mjs";
import * as Qt from "react";
import { useContext as kt, useMemo as et, useRef as It } from "react";
import { getAnimatedType as ht, setAnimated as zt, getAnimated as j, getPayload as yt, AnimatedValue as fe, AnimatedString as Ct } from "../../animated/dist/react-spring-animated.esm.mjs";
import { raf as T } from "../../rafz/dist/react-spring-rafz.esm.mjs";
function w() {
  return w = Object.assign ? Object.assign.bind() : function(e) {
    for (var t = 1; t < arguments.length; t++) {
      var i = arguments[t];
      for (var s in i)
        Object.prototype.hasOwnProperty.call(i, s) && (e[s] = i[s]);
    }
    return e;
  }, w.apply(this, arguments);
}
function D(e, ...t) {
  return a.fun(e) ? e(...t) : e;
}
const W = (e, t) => e === !0 || !!(t && e && (a.fun(e) ? e(t) : R(e).includes(t))), $t = (e, t) => a.obj(e) ? t && e[t] : e, Bt = (e, t) => e.default === !0 ? e[t] : e.default ? e.default[t] : void 0, me = (e) => e, vt = (e, t = me) => {
  let i = pe;
  e.default && e.default !== !0 && (e = e.default, i = Object.keys(e));
  const s = {};
  for (const n of i) {
    const o = t(e[n], n);
    a.und(o) || (s[n] = o);
  }
  return s;
}, pe = ["config", "onProps", "onStart", "onChange", "onPause", "onResume", "onRest"], ge = {
  config: 1,
  from: 1,
  to: 1,
  ref: 1,
  loop: 1,
  reset: 1,
  pause: 1,
  cancel: 1,
  reverse: 1,
  immediate: 1,
  default: 1,
  delay: 1,
  onProps: 1,
  onStart: 1,
  onChange: 1,
  onPause: 1,
  onResume: 1,
  onRest: 1,
  onResolve: 1,
  items: 1,
  trail: 1,
  sort: 1,
  expires: 1,
  initial: 1,
  enter: 1,
  update: 1,
  leave: 1,
  children: 1,
  onDestroyed: 1,
  keys: 1,
  callId: 1,
  parentId: 1
};
function _e(e) {
  const t = {};
  let i = 0;
  if ($(e, (s, n) => {
    ge[n] || (t[n] = s, i++);
  }), i)
    return t;
}
function Lt(e) {
  const t = _e(e);
  if (t) {
    const i = {
      to: t
    };
    return $(e, (s, n) => n in t || (i[n] = s)), i;
  }
  return w({}, e);
}
function Y(e) {
  return e = O(e), a.arr(e) ? e.map(Y) : Nt(e) ? q.createStringInterpolator({
    range: [0, 1],
    output: [e, e]
  })(1) : e;
}
function ye(e) {
  for (const t in e)
    return !0;
  return !1;
}
function dt(e) {
  return a.fun(e) || a.arr(e) && a.obj(e[0]);
}
function ve(e, t) {
  var i;
  (i = e.ref) == null || i.delete(e), t == null || t.delete(e);
}
function Pe(e, t) {
  if (t && e.ref !== t) {
    var i;
    (i = e.ref) == null || i.delete(e), t.add(e), e.ref = t;
  }
}
const be = {
  default: {
    tension: 170,
    friction: 26
  },
  gentle: {
    tension: 120,
    friction: 14
  },
  wobbly: {
    tension: 180,
    friction: 12
  },
  stiff: {
    tension: 210,
    friction: 20
  },
  slow: {
    tension: 280,
    friction: 60
  },
  molasses: {
    tension: 280,
    friction: 120
  }
}, lt = w({}, be.default, {
  mass: 1,
  damping: 1,
  easing: se.linear,
  clamp: !1
});
class Se {
  constructor() {
    this.tension = void 0, this.friction = void 0, this.frequency = void 0, this.damping = void 0, this.mass = void 0, this.velocity = 0, this.restVelocity = void 0, this.precision = void 0, this.progress = void 0, this.duration = void 0, this.easing = void 0, this.clamp = void 0, this.bounce = void 0, this.decay = void 0, this.round = void 0, Object.assign(this, lt);
  }
}
function Ae(e, t, i) {
  i && (i = w({}, i), Rt(i, t), t = w({}, i, t)), Rt(e, t), Object.assign(e, t);
  for (const c in lt)
    e[c] == null && (e[c] = lt[c]);
  let {
    mass: s,
    frequency: n,
    damping: o
  } = e;
  return a.und(n) || (n < 0.01 && (n = 0.01), o < 0 && (o = 0), e.tension = Math.pow(2 * Math.PI / n, 2) * s, e.friction = 4 * Math.PI * o * s / n), e;
}
function Rt(e, t) {
  if (!a.und(t.decay))
    e.duration = void 0;
  else {
    const i = !a.und(t.tension) || !a.und(t.friction);
    (i || !a.und(t.frequency) || !a.und(t.damping) || !a.und(t.mass)) && (e.duration = void 0, e.decay = void 0), i && (e.frequency = void 0);
  }
}
const Vt = [];
class we {
  constructor() {
    this.changed = !1, this.values = Vt, this.toValues = null, this.fromValues = Vt, this.to = void 0, this.from = void 0, this.config = new Se(), this.immediate = !1;
  }
}
function Gt(e, {
  key: t,
  props: i,
  defaultProps: s,
  state: n,
  actions: o
}) {
  return new Promise((c, l) => {
    var r;
    let d, u, f = W((r = i.cancel) != null ? r : s == null ? void 0 : s.cancel, t);
    if (f)
      y();
    else {
      a.und(i.pause) || (n.paused = W(i.pause, t));
      let m = s == null ? void 0 : s.pause;
      m !== !0 && (m = n.paused || W(m, t)), d = D(i.delay || 0, t), m ? (n.resumeQueue.add(b), o.pause()) : (o.resume(), b());
    }
    function v() {
      n.resumeQueue.add(b), n.timeouts.delete(u), u.cancel(), d = u.time - T.now();
    }
    function b() {
      d > 0 && !q.skipAnimation ? (n.delayed = !0, u = T.setTimeout(y, d), n.pauseQueue.add(v), n.timeouts.add(u)) : y();
    }
    function y() {
      n.delayed && (n.delayed = !1), n.pauseQueue.delete(v), n.timeouts.delete(u), e <= (n.cancelId || 0) && (f = !0);
      try {
        o.start(w({}, i, {
          callId: e,
          cancel: f
        }), c);
      } catch (m) {
        l(m);
      }
    }
  });
}
const Pt = (e, t) => t.length == 1 ? t[0] : t.some((i) => i.cancelled) ? z(e.get()) : t.every((i) => i.noop) ? Ht(e.get()) : V(e.get(), t.every((i) => i.finished)), Ht = (e) => ({
  value: e,
  noop: !0,
  finished: !0,
  cancelled: !1
}), V = (e, t, i = !1) => ({
  value: e,
  finished: t,
  cancelled: i
}), z = (e) => ({
  value: e,
  cancelled: !0,
  finished: !1
});
function Kt(e, t, i, s) {
  const {
    callId: n,
    parentId: o,
    onRest: c
  } = t, {
    asyncTo: l,
    promise: r
  } = i;
  return !o && e === l && !t.reset ? r : i.promise = (() => L(this, null, function* () {
    i.asyncId = n, i.asyncTo = e;
    const d = vt(t, (h, p) => p === "onRest" ? void 0 : h);
    let u, f;
    const v = new Promise((h, p) => (u = h, f = p)), b = (h) => {
      const p = n <= (i.cancelId || 0) && z(s) || n !== i.asyncId && V(s, !1);
      if (p)
        throw h.result = p, f(h), h;
    }, y = (h, p) => {
      const g = new Tt(), P = new Ft();
      return (() => L(this, null, function* () {
        if (q.skipAnimation)
          throw X(i), P.result = V(s, !1), f(P), P;
        b(g);
        const _ = a.obj(h) ? w({}, h) : w({}, p, {
          to: h
        });
        _.parentId = n, $(d, (I, Q) => {
          a.und(_[Q]) && (_[Q] = I);
        });
        const A = yield s.start(_);
        return b(g), i.paused && (yield new Promise((I) => {
          i.resumeQueue.add(I);
        })), A;
      }))();
    };
    let m;
    if (q.skipAnimation)
      return X(i), V(s, !1);
    try {
      let h;
      a.arr(e) ? h = ((p) => L(this, null, function* () {
        for (const g of p)
          yield y(g);
      }))(e) : h = Promise.resolve(e(y, s.stop.bind(s))), yield Promise.all([h.then(u), v]), m = V(s.get(), !0, !1);
    } catch (h) {
      if (h instanceof Tt)
        m = h.result;
      else if (h instanceof Ft)
        m = h.result;
      else
        throw h;
    } finally {
      n == i.asyncId && (i.asyncId = o, i.asyncTo = o ? l : void 0, i.promise = o ? r : void 0);
    }
    return a.fun(c) && T.batchedUpdates(() => {
      c(m, s, s.item);
    }), m;
  }))();
}
function X(e, t) {
  it(e.timeouts, (i) => i.cancel()), e.pauseQueue.clear(), e.resumeQueue.clear(), e.asyncId = e.asyncTo = e.promise = void 0, t && (e.cancelId = t);
}
class Tt extends Error {
  constructor() {
    super("An async animation has been interrupted. You see this error because you forgot to use `await` or `.catch(...)` on its returned promise."), this.result = void 0;
  }
}
class Ft extends Error {
  constructor() {
    super("SkipAnimationSignal"), this.result = void 0;
  }
}
const ft = (e) => e instanceof bt;
let Ie = 1;
class bt extends re {
  constructor(...t) {
    super(...t), this.id = Ie++, this.key = void 0, this._priority = 0;
  }
  get priority() {
    return this._priority;
  }
  set priority(t) {
    this._priority != t && (this._priority = t, this._onPriorityChange(t));
  }
  get() {
    const t = j(this);
    return t && t.getValue();
  }
  to(...t) {
    return q.to(this, t);
  }
  interpolate(...t) {
    return ue(), q.to(this, t);
  }
  toJSON() {
    return this.get();
  }
  observerAdded(t) {
    t == 1 && this._attach();
  }
  observerRemoved(t) {
    t == 0 && this._detach();
  }
  _attach() {
  }
  _detach() {
  }
  _onChange(t, i = !1) {
    st(this, {
      type: "change",
      parent: this,
      value: t,
      idle: i
    });
  }
  _onPriorityChange(t) {
    this.idle || _t.sort(this), st(this, {
      type: "priority",
      parent: this,
      priority: t
    });
  }
}
const N = Symbol.for("SpringPhase"), Jt = 1, mt = 2, pt = 4, ut = (e) => (e[N] & Jt) > 0, M = (e) => (e[N] & mt) > 0, G = (e) => (e[N] & pt) > 0, Ot = (e, t) => t ? e[N] |= mt | Jt : e[N] &= ~mt, xt = (e, t) => t ? e[N] |= pt : e[N] &= ~pt;
class Ce extends bt {
  constructor(t, i) {
    if (super(), this.key = void 0, this.animation = new we(), this.queue = void 0, this.defaultProps = {}, this._state = {
      paused: !1,
      delayed: !1,
      pauseQueue: /* @__PURE__ */ new Set(),
      resumeQueue: /* @__PURE__ */ new Set(),
      timeouts: /* @__PURE__ */ new Set()
    }, this._pendingCalls = /* @__PURE__ */ new Set(), this._lastCallId = 0, this._lastToId = 0, this._memoizedDuration = 0, !a.und(t) || !a.und(i)) {
      const s = a.obj(t) ? w({}, t) : w({}, i, {
        from: t
      });
      a.und(s.default) && (s.default = !0), this.start(s);
    }
  }
  get idle() {
    return !(M(this) || this._state.asyncTo) || G(this);
  }
  get goal() {
    return O(this.animation.to);
  }
  get velocity() {
    const t = j(this);
    return t instanceof fe ? t.lastVelocity || 0 : t.getPayload().map((i) => i.lastVelocity || 0);
  }
  get hasAnimated() {
    return ut(this);
  }
  get isAnimating() {
    return M(this);
  }
  get isPaused() {
    return G(this);
  }
  get isDelayed() {
    return this._state.delayed;
  }
  advance(t) {
    let i = !0, s = !1;
    const n = this.animation;
    let {
      config: o,
      toValues: c
    } = n;
    const l = yt(n.to);
    !l && U(n.to) && (c = R(O(n.to))), n.values.forEach((u, f) => {
      if (u.done)
        return;
      const v = u.constructor == Ct ? 1 : l ? l[f].lastPosition : c[f];
      let b = n.immediate, y = v;
      if (!b) {
        if (y = u.lastPosition, o.tension <= 0) {
          u.done = !0;
          return;
        }
        let m = u.elapsedTime += t;
        const h = n.fromValues[f], p = u.v0 != null ? u.v0 : u.v0 = a.arr(o.velocity) ? o.velocity[f] : o.velocity;
        let g;
        const P = o.precision || (h == v ? 5e-3 : Math.min(1, Math.abs(v - h) * 1e-3));
        if (a.und(o.duration))
          if (o.decay) {
            const _ = o.decay === !0 ? 0.998 : o.decay, A = Math.exp(-(1 - _) * m);
            y = h + p / (1 - _) * (1 - A), b = Math.abs(u.lastPosition - y) <= P, g = p * A;
          } else {
            g = u.lastVelocity == null ? p : u.lastVelocity;
            const _ = o.restVelocity || P / 10, A = o.clamp ? 0 : o.bounce, I = !a.und(A), Q = h == v ? u.v0 > 0 : h < v;
            let x, tt = !1;
            const C = 1, B = Math.ceil(t / C);
            for (let F = 0; F < B && (x = Math.abs(g) > _, !(!x && (b = Math.abs(v - y) <= P, b))); ++F) {
              I && (tt = y == v || y > v == Q, tt && (g = -g * A, y = v));
              const k = -o.tension * 1e-6 * (y - v), rt = -o.friction * 1e-3 * g, ie = (k + rt) / o.mass;
              g = g + ie * C, y = y + g * C;
            }
          }
        else {
          let _ = 1;
          o.duration > 0 && (this._memoizedDuration !== o.duration && (this._memoizedDuration = o.duration, u.durationProgress > 0 && (u.elapsedTime = o.duration * u.durationProgress, m = u.elapsedTime += t)), _ = (o.progress || 0) + m / this._memoizedDuration, _ = _ > 1 ? 1 : _ < 0 ? 0 : _, u.durationProgress = _), y = h + o.easing(_) * (v - h), g = (y - u.lastPosition) / t, b = _ == 1;
        }
        u.lastVelocity = g, Number.isNaN(y) && (console.warn("Got NaN while animating:", this), b = !0);
      }
      l && !l[f].done && (b = !1), b ? u.done = !0 : i = !1, u.setValue(y, o.round) && (s = !0);
    });
    const r = j(this), d = r.getValue();
    if (i) {
      const u = O(n.to);
      (d !== u || s) && !o.decay ? (r.setValue(u), this._onChange(u)) : s && o.decay && this._onChange(d), this._stop();
    } else
      s && this._onChange(d);
  }
  set(t) {
    return T.batchedUpdates(() => {
      this._stop(), this._focus(t), this._set(t);
    }), this;
  }
  pause() {
    this._update({
      pause: !0
    });
  }
  resume() {
    this._update({
      pause: !1
    });
  }
  finish() {
    if (M(this)) {
      const {
        to: t,
        config: i
      } = this.animation;
      T.batchedUpdates(() => {
        this._onStart(), i.decay || this._set(t, !1), this._stop();
      });
    }
    return this;
  }
  update(t) {
    return (this.queue || (this.queue = [])).push(t), this;
  }
  start(t, i) {
    let s;
    return a.und(t) ? (s = this.queue || [], this.queue = []) : s = [a.obj(t) ? t : w({}, i, {
      to: t
    })], Promise.all(s.map((n) => this._update(n))).then((n) => Pt(this, n));
  }
  stop(t) {
    const {
      to: i
    } = this.animation;
    return this._focus(this.get()), X(this._state, t && this._lastCallId), T.batchedUpdates(() => this._stop(i, t)), this;
  }
  reset() {
    this._update({
      reset: !0
    });
  }
  eventObserved(t) {
    t.type == "change" ? this._start() : t.type == "priority" && (this.priority = t.priority + 1);
  }
  _prepareNode(t) {
    const i = this.key || "";
    let {
      to: s,
      from: n
    } = t;
    s = a.obj(s) ? s[i] : s, (s == null || dt(s)) && (s = void 0), n = a.obj(n) ? n[i] : n, n == null && (n = void 0);
    const o = {
      to: s,
      from: n
    };
    return ut(this) || (t.reverse && ([s, n] = [n, s]), n = O(n), a.und(n) ? j(this) || this._set(s) : this._set(n)), o;
  }
  _update(t, i) {
    let s = w({}, t);
    const {
      key: n,
      defaultProps: o
    } = this;
    s.default && Object.assign(o, vt(s, (r, d) => /^on/.test(d) ? $t(r, n) : r)), jt(this, s, "onProps"), K(this, "onProps", s, this);
    const c = this._prepareNode(s);
    if (Object.isFrozen(this))
      throw Error("Cannot animate a `SpringValue` object that is frozen. Did you forget to pass your component to `animated(...)` before animating its props?");
    const l = this._state;
    return Gt(++this._lastCallId, {
      key: n,
      props: s,
      defaultProps: o,
      state: l,
      actions: {
        pause: () => {
          G(this) || (xt(this, !0), J(l.pauseQueue), K(this, "onPause", V(this, H(this, this.animation.to)), this));
        },
        resume: () => {
          G(this) && (xt(this, !1), M(this) && this._resume(), J(l.resumeQueue), K(this, "onResume", V(this, H(this, this.animation.to)), this));
        },
        start: this._merge.bind(this, c)
      }
    }).then((r) => {
      if (s.loop && r.finished && !(i && r.noop)) {
        const d = Wt(s);
        if (d)
          return this._update(d, !0);
      }
      return r;
    });
  }
  _merge(t, i, s) {
    if (i.cancel)
      return this.stop(!0), s(z(this));
    const n = !a.und(t.to), o = !a.und(t.from);
    if (n || o)
      if (i.callId > this._lastToId)
        this._lastToId = i.callId;
      else
        return s(z(this));
    const {
      key: c,
      defaultProps: l,
      animation: r
    } = this, {
      to: d,
      from: u
    } = r;
    let {
      to: f = d,
      from: v = u
    } = t;
    o && !n && (!i.default || a.und(f)) && (f = v), i.reverse && ([f, v] = [v, f]);
    const b = !E(v, u);
    b && (r.from = v), v = O(v);
    const y = !E(f, d);
    y && this._focus(f);
    const m = dt(i.to), {
      config: h
    } = r, {
      decay: p,
      velocity: g
    } = h;
    (n || o) && (h.velocity = 0), i.config && !m && Ae(h, D(i.config, c), i.config !== l.config ? D(l.config, c) : void 0);
    let P = j(this);
    if (!P || a.und(f))
      return s(V(this, !0));
    const _ = a.und(i.reset) ? o && !i.default : !a.und(v) && W(i.reset, c), A = _ ? v : this.get(), I = Y(f), Q = a.num(I) || a.arr(I) || Nt(I), x = !m && (!Q || W(l.immediate || i.immediate, c));
    if (y) {
      const F = ht(f);
      if (F !== P.constructor)
        if (x)
          P = this._set(I);
        else
          throw Error(`Cannot animate between ${P.constructor.name} and ${F.name}, as the "to" prop suggests`);
    }
    const tt = P.constructor;
    let C = U(f), B = !1;
    if (!C) {
      const F = _ || !ut(this) && b;
      (y || F) && (B = E(Y(A), I), C = !B), (!E(r.immediate, x) && !x || !E(h.decay, p) || !E(h.velocity, g)) && (C = !0);
    }
    if (B && M(this) && (r.changed && !_ ? C = !0 : C || this._stop(d)), !m && ((C || U(d)) && (r.values = P.getPayload(), r.toValues = U(f) ? null : tt == Ct ? [1] : R(I)), r.immediate != x && (r.immediate = x, !x && !_ && this._set(d)), C)) {
      const {
        onRest: F
      } = r;
      S(Ve, (rt) => jt(this, i, rt));
      const k = V(this, H(this, d));
      J(this._pendingCalls, k), this._pendingCalls.add(s), r.changed && T.batchedUpdates(() => {
        r.changed = !_, F == null || F(k, this), _ ? D(l.onRest, k) : r.onStart == null || r.onStart(k, this);
      });
    }
    _ && this._set(A), m ? s(Kt(i.to, i, this._state, this)) : C ? this._start() : M(this) && !y ? this._pendingCalls.add(s) : s(Ht(A));
  }
  _focus(t) {
    const i = this.animation;
    t !== i.to && (wt(this) && this._detach(), i.to = t, wt(this) && this._attach());
  }
  _attach() {
    let t = 0;
    const {
      to: i
    } = this.animation;
    U(i) && (ot(i, this), ft(i) && (t = i.priority + 1)), this.priority = t;
  }
  _detach() {
    const {
      to: t
    } = this.animation;
    U(t) && Dt(t, this);
  }
  _set(t, i = !0) {
    const s = O(t);
    if (!a.und(s)) {
      const n = j(this);
      if (!n || !E(s, n.getValue())) {
        const o = ht(s);
        !n || n.constructor != o ? zt(this, o.create(s)) : n.setValue(s), n && T.batchedUpdates(() => {
          this._onChange(s, i);
        });
      }
    }
    return j(this);
  }
  _onStart() {
    const t = this.animation;
    t.changed || (t.changed = !0, K(this, "onStart", V(this, H(this, t.to)), this));
  }
  _onChange(t, i) {
    i || (this._onStart(), D(this.animation.onChange, t, this)), D(this.defaultProps.onChange, t, this), super._onChange(t, i);
  }
  _start() {
    const t = this.animation;
    j(this).reset(O(t.to)), t.immediate || (t.fromValues = t.values.map((i) => i.lastPosition)), M(this) || (Ot(this, !0), G(this) || this._resume());
  }
  _resume() {
    q.skipAnimation ? this.finish() : _t.start(this);
  }
  _stop(t, i) {
    if (M(this)) {
      Ot(this, !1);
      const s = this.animation;
      S(s.values, (o) => {
        o.done = !0;
      }), s.toValues && (s.onChange = s.onPause = s.onResume = void 0), st(this, {
        type: "idle",
        parent: this
      });
      const n = i ? z(this.get()) : V(this.get(), H(this, t != null ? t : s.to));
      J(this._pendingCalls, n), s.changed && (s.changed = !1, K(this, "onRest", n, this));
    }
  }
}
function H(e, t) {
  const i = Y(t), s = Y(e.get());
  return E(s, i);
}
function Wt(e, t = e.loop, i = e.to) {
  let s = D(t);
  if (s) {
    const n = s !== !0 && Lt(s), o = (n || e).reverse, c = !n || n.reset;
    return Z(w({}, e, {
      loop: t,
      default: !1,
      pause: void 0,
      to: !o || dt(i) ? i : void 0,
      from: c ? e.from : void 0,
      reset: c
    }, n));
  }
}
function Z(e) {
  const {
    to: t,
    from: i
  } = e = Lt(e), s = /* @__PURE__ */ new Set();
  return a.obj(t) && Et(t, s), a.obj(i) && Et(i, s), e.keys = s.size ? Array.from(s) : null, e;
}
function Re(e) {
  const t = Z(e);
  return a.und(t.default) && (t.default = vt(t)), t;
}
function Et(e, t) {
  $(e, (i, s) => i != null && t.add(s));
}
const Ve = ["onStart", "onRest", "onChange", "onPause", "onResume"];
function jt(e, t, i) {
  e.animation[i] = t[i] !== Bt(t, i) ? $t(t[i], e.key) : void 0;
}
function K(e, t, ...i) {
  var s, n, o, c;
  (s = (n = e.animation)[t]) == null || s.call(n, ...i), (o = (c = e.defaultProps)[t]) == null || o.call(c, ...i);
}
const Te = ["onStart", "onChange", "onRest"];
let Fe = 1;
class Oe {
  constructor(t, i) {
    this.id = Fe++, this.springs = {}, this.queue = [], this.ref = void 0, this._flush = void 0, this._initialProps = void 0, this._lastAsyncId = 0, this._active = /* @__PURE__ */ new Set(), this._changed = /* @__PURE__ */ new Set(), this._started = !1, this._item = void 0, this._state = {
      paused: !1,
      pauseQueue: /* @__PURE__ */ new Set(),
      resumeQueue: /* @__PURE__ */ new Set(),
      timeouts: /* @__PURE__ */ new Set()
    }, this._events = {
      onStart: /* @__PURE__ */ new Map(),
      onChange: /* @__PURE__ */ new Map(),
      onRest: /* @__PURE__ */ new Map()
    }, this._onFrame = this._onFrame.bind(this), i && (this._flush = i), t && this.start(w({
      default: !0
    }, t));
  }
  get idle() {
    return !this._state.asyncTo && Object.values(this.springs).every((t) => t.idle && !t.isDelayed && !t.isPaused);
  }
  get item() {
    return this._item;
  }
  set item(t) {
    this._item = t;
  }
  get() {
    const t = {};
    return this.each((i, s) => t[s] = i.get()), t;
  }
  set(t) {
    for (const i in t) {
      const s = t[i];
      a.und(s) || this.springs[i].set(s);
    }
  }
  update(t) {
    return t && this.queue.push(Z(t)), this;
  }
  start(t) {
    let {
      queue: i
    } = this;
    return t ? i = R(t).map(Z) : this.queue = [], this._flush ? this._flush(this, i) : (ee(this, i), gt(this, i));
  }
  stop(t, i) {
    if (t !== !!t && (i = t), i) {
      const s = this.springs;
      S(R(i), (n) => s[n].stop(!!t));
    } else
      X(this._state, this._lastAsyncId), this.each((s) => s.stop(!!t));
    return this;
  }
  pause(t) {
    if (a.und(t))
      this.start({
        pause: !0
      });
    else {
      const i = this.springs;
      S(R(t), (s) => i[s].pause());
    }
    return this;
  }
  resume(t) {
    if (a.und(t))
      this.start({
        pause: !1
      });
    else {
      const i = this.springs;
      S(R(t), (s) => i[s].resume());
    }
    return this;
  }
  each(t) {
    $(this.springs, t);
  }
  _onFrame() {
    const {
      onStart: t,
      onChange: i,
      onRest: s
    } = this._events, n = this._active.size > 0, o = this._changed.size > 0;
    (n && !this._started || o && !this._started) && (this._started = !0, it(t, ([r, d]) => {
      d.value = this.get(), r(d, this, this._item);
    }));
    const c = !n && this._started, l = o || c && s.size ? this.get() : null;
    o && i.size && it(i, ([r, d]) => {
      d.value = l, r(d, this, this._item);
    }), c && (this._started = !1, it(s, ([r, d]) => {
      d.value = l, r(d, this, this._item);
    }));
  }
  eventObserved(t) {
    if (t.type == "change")
      this._changed.add(t.parent), t.idle || this._active.add(t.parent);
    else if (t.type == "idle")
      this._active.delete(t.parent);
    else
      return;
    T.onFrame(this._onFrame);
  }
}
function gt(e, t) {
  return Promise.all(t.map((i) => Yt(e, i))).then((i) => Pt(e, i));
}
function Yt(e, t, i) {
  return L(this, null, function* () {
    const {
      keys: s,
      to: n,
      from: o,
      loop: c,
      onRest: l,
      onResolve: r
    } = t, d = a.obj(t.default) && t.default;
    c && (t.loop = !1), n === !1 && (t.to = null), o === !1 && (t.from = null);
    const u = a.arr(n) || a.fun(n) ? n : void 0;
    u ? (t.to = void 0, t.onRest = void 0, d && (d.onRest = void 0)) : S(Te, (m) => {
      const h = t[m];
      if (a.fun(h)) {
        const p = e._events[m];
        t[m] = ({
          finished: g,
          cancelled: P
        }) => {
          const _ = p.get(h);
          _ ? (g || (_.finished = !1), P && (_.cancelled = !0)) : p.set(h, {
            value: null,
            finished: g || !1,
            cancelled: P || !1
          });
        }, d && (d[m] = t[m]);
      }
    });
    const f = e._state;
    t.pause === !f.paused ? (f.paused = t.pause, J(t.pause ? f.pauseQueue : f.resumeQueue)) : f.paused && (t.pause = !0);
    const v = (s || Object.keys(e.springs)).map((m) => e.springs[m].start(t)), b = t.cancel === !0 || Bt(t, "cancel") === !0;
    (u || b && f.asyncId) && v.push(Gt(++e._lastAsyncId, {
      props: t,
      state: f,
      actions: {
        pause: At,
        resume: At,
        start(m, h) {
          b ? (X(f, e._lastAsyncId), h(z(e))) : (m.onRest = l, h(Kt(u, m, f, e)));
        }
      }
    })), f.paused && (yield new Promise((m) => {
      f.resumeQueue.add(m);
    }));
    const y = Pt(e, yield Promise.all(v));
    if (c && y.finished && !(i && y.noop)) {
      const m = Wt(t, c, n);
      if (m)
        return ee(e, [m]), Yt(e, m, !0);
    }
    return r && T.batchedUpdates(() => r(y, e, e.item)), y;
  });
}
function qt(e, t) {
  const i = w({}, e.springs);
  return t && S(R(t), (s) => {
    a.und(s.keys) && (s = Z(s)), a.obj(s.to) || (s = w({}, s, {
      to: void 0
    })), te(i, s, (n) => Zt(n));
  }), Xt(e, i), i;
}
function Xt(e, t) {
  $(t, (i, s) => {
    e.springs[s] || (e.springs[s] = i, ot(i, e));
  });
}
function Zt(e, t) {
  const i = new Ce();
  return i.key = e, t && ot(i, t), i;
}
function te(e, t, i) {
  t.keys && S(t.keys, (s) => {
    (e[s] || (e[s] = i(s)))._prepareNode(t);
  });
}
function ee(e, t) {
  S(t, (i) => {
    te(e.springs, i, (s) => Zt(s, e));
  });
}
function xe(e, t) {
  if (e == null)
    return {};
  var i = {}, s = Object.keys(e), n, o;
  for (o = 0; o < s.length; o++)
    n = s[o], !(t.indexOf(n) >= 0) && (i[n] = e[n]);
  return i;
}
const Ee = ["children"], at = (e) => {
  let {
    children: t
  } = e, i = xe(e, Ee);
  const s = kt(nt), n = i.pause || !!s.pause, o = i.immediate || !!s.immediate;
  i = oe(() => ({
    pause: n,
    immediate: o
  }), [n, o]);
  const {
    Provider: c
  } = nt;
  return Qt.createElement(c, {
    value: i
  }, t);
}, nt = je(at, {});
at.Provider = nt.Provider;
at.Consumer = nt.Consumer;
function je(e, t) {
  return Object.assign(e, Qt.createContext(t)), e.Provider._context = e, e.Consumer._context = e, e;
}
const qe = () => {
  const e = [], t = function(n) {
    le();
    const o = [];
    return S(e, (c, l) => {
      if (a.und(n))
        o.push(c.start());
      else {
        const r = i(n, c, l);
        r && o.push(c.start(r));
      }
    }), o;
  };
  t.current = e, t.add = function(s) {
    e.includes(s) || e.push(s);
  }, t.delete = function(s) {
    const n = e.indexOf(s);
    ~n && e.splice(n, 1);
  }, t.pause = function() {
    return S(e, (s) => s.pause(...arguments)), this;
  }, t.resume = function() {
    return S(e, (s) => s.resume(...arguments)), this;
  }, t.set = function(s) {
    S(e, (n) => n.set(s));
  }, t.start = function(s) {
    const n = [];
    return S(e, (o, c) => {
      if (a.und(s))
        n.push(o.start());
      else {
        const l = this._getProps(s, o, c);
        l && n.push(o.start(l));
      }
    }), n;
  }, t.stop = function() {
    return S(e, (s) => s.stop(...arguments)), this;
  }, t.update = function(s) {
    return S(e, (n, o) => n.update(this._getProps(s, n, o))), this;
  };
  const i = function(n, o, c) {
    return a.fun(n) ? n(c, o) : n;
  };
  return t._getProps = i, t;
};
function Me(e, t, i) {
  const s = a.fun(t) && t;
  s && !i && (i = []);
  const n = et(() => s || arguments.length == 3 ? qe() : void 0, []), o = It(0), c = ce(), l = et(() => ({
    ctrls: [],
    queue: [],
    flush(p, g) {
      const P = qt(p, g);
      return o.current > 0 && !l.queue.length && !Object.keys(P).some((A) => !p.springs[A]) ? gt(p, g) : new Promise((A) => {
        Xt(p, P), l.queue.push(() => {
          A(gt(p, g));
        }), c();
      });
    }
  }), []), r = It([...l.ctrls]), d = [], u = St(e) || 0;
  et(() => {
    S(r.current.slice(e, u), (p) => {
      ve(p, n), p.stop(!0);
    }), r.current.length = e, f(u, e);
  }, [e]), et(() => {
    f(0, Math.min(u, e));
  }, i);
  function f(p, g) {
    for (let P = p; P < g; P++) {
      const _ = r.current[P] || (r.current[P] = new Oe(null, l.flush)), A = s ? s(P, _) : t[P];
      A && (d[P] = Re(A));
    }
  }
  const v = r.current.map((p, g) => qt(p, d[g])), b = kt(at), y = St(b), m = b !== y && ye(b);
  he(() => {
    o.current++, l.ctrls = r.current;
    const {
      queue: p
    } = l;
    p.length && (l.queue = [], S(p, (g) => g())), S(r.current, (g, P) => {
      n == null || n.add(g), m && g.start({
        default: b
      });
      const _ = d[P];
      _ && (Pe(g, _.ref), g.ref ? g.queue.push(_) : g.start(_));
    });
  }), de(() => () => {
    S(l.ctrls, (p) => p.stop(!0));
  });
  const h = v.map((p) => w({}, p));
  return n ? [h, n] : h;
}
function Be(e, t) {
  const i = a.fun(e), [[s], n] = Me(1, i ? e : [e], i ? t || [] : t);
  return i || arguments.length == 2 ? [s, n] : s;
}
let Mt;
(function(e) {
  e.MOUNT = "mount", e.ENTER = "enter", e.UPDATE = "update", e.LEAVE = "leave";
})(Mt || (Mt = {}));
class Ue extends bt {
  constructor(t, i) {
    super(), this.key = void 0, this.idle = !0, this.calc = void 0, this._active = /* @__PURE__ */ new Set(), this.source = t, this.calc = ae(...i);
    const s = this._get(), n = ht(s);
    zt(this, n.create(s));
  }
  advance(t) {
    const i = this._get(), s = this.get();
    E(i, s) || (j(this).setValue(i), this._onChange(i, this.idle)), !this.idle && Ut(this._active) && ct(this);
  }
  _get() {
    const t = a.arr(this.source) ? this.source.map(O) : R(O(this.source));
    return this.calc(...t);
  }
  _start() {
    this.idle && !Ut(this._active) && (this.idle = !1, S(yt(this), (t) => {
      t.done = !1;
    }), q.skipAnimation ? (T.batchedUpdates(() => this.advance()), ct(this)) : _t.start(this));
  }
  _attach() {
    let t = 1;
    S(R(this.source), (i) => {
      U(i) && ot(i, this), ft(i) && (i.idle || this._active.add(i), t = Math.max(t, i.priority + 1));
    }), this.priority = t, this._start();
  }
  _detach() {
    S(R(this.source), (t) => {
      U(t) && Dt(t, this);
    }), this._active.clear(), ct(this);
  }
  eventObserved(t) {
    t.type == "change" ? t.idle ? this.advance() : (this._active.add(t.parent), this._start()) : t.type == "idle" ? this._active.delete(t.parent) : t.type == "priority" && (this.priority = R(this.source).reduce((i, s) => Math.max(i, (ft(s) ? s.priority : 0) + 1), 0));
  }
}
function De(e) {
  return e.idle !== !1;
}
function Ut(e) {
  return !e.size || Array.from(e).every(De);
}
function ct(e) {
  e.idle || (e.idle = !0, S(yt(e), (t) => {
    t.done = !0;
  }), st(e, {
    type: "idle",
    parent: e
  }));
}
q.assign({
  createStringInterpolator: ne,
  to: (e, t) => new Ue(e, t)
});
export {
  Tt as BailSignal,
  Oe as Controller,
  bt as FrameValue,
  q as Globals,
  Ue as Interpolation,
  at as SpringContext,
  qe as SpringRef,
  Ce as SpringValue,
  be as config,
  ae as createInterpolator,
  se as easings,
  Lt as inferTo,
  he as useIsomorphicLayoutEffect,
  Be as useSpring,
  Me as useSprings
};
