@clubmed/trident-ui
Version:
Shared ClubMed React UI components
1,697 lines • 62.8 kB
JavaScript
import * as Bt from "react";
import { useState as Re, useEffect as H, useLayoutEffect as Vi, useRef as Y, forwardRef as Fi, useCallback as Gt, useMemo as Se, useContext as Ci } from "react";
import { unstable_batchedUpdates as Ei } from "react-dom";
var nt = _e(), y = (e) => ye(e, nt), rt = _e();
y.write = (e) => ye(e, rt);
var Fe = _e();
y.onStart = (e) => ye(e, Fe);
var st = _e();
y.onFrame = (e) => ye(e, st);
var at = _e();
y.onFinish = (e) => ye(e, at);
var K = [];
y.setTimeout = (e, t) => {
const i = y.now() + t, n = () => {
const s = K.findIndex((a) => a.cancel == n);
~s && K.splice(s, 1), M -= ~s ? 1 : 0;
}, r = { time: i, handler: e, cancel: n };
return K.splice(Yt(i), 0, r), M += 1, Ht(), r;
};
var Yt = (e) => ~(~K.findIndex((t) => t.time > e) || ~K.length);
y.cancel = (e) => {
Fe.delete(e), st.delete(e), at.delete(e), nt.delete(e), rt.delete(e);
};
y.sync = (e) => {
Ye = !0, y.batchedUpdates(e), Ye = !1;
};
y.throttle = (e) => {
let t;
function i() {
try {
e(...t);
} finally {
t = null;
}
}
function n(...r) {
t = r, y.onStart(i);
}
return n.handler = e, n.cancel = () => {
Fe.delete(i), t = null;
}, n;
};
var ot = typeof window < "u" ? window.requestAnimationFrame : (
// eslint-disable-next-line @typescript-eslint/no-empty-function
(() => {
})
);
y.use = (e) => ot = e;
y.now = typeof performance < "u" ? () => performance.now() : Date.now;
y.batchedUpdates = (e) => e();
y.catch = console.error;
y.frameLoop = "always";
y.advance = () => {
y.frameLoop !== "demand" ? console.warn(
"Cannot call the manual advancement of rafz whilst frameLoop is not set as demand"
) : Xt();
};
var Q = -1, M = 0, Ye = !1;
function ye(e, t) {
Ye ? (t.delete(e), e(0)) : (t.add(e), Ht());
}
function Ht() {
Q < 0 && (Q = 0, y.frameLoop !== "demand" && ot(Wt));
}
function Oi() {
Q = -1;
}
function Wt() {
~Q && (ot(Wt), y.batchedUpdates(Xt));
}
function Xt() {
const e = Q;
Q = y.now();
const t = Yt(Q);
if (t && (Zt(K.splice(0, t), (i) => i.handler()), M -= t), !M) {
Oi();
return;
}
Fe.flush(), nt.flush(e ? Math.min(64, Q - e) : 16.667), st.flush(), rt.flush(), at.flush();
}
function _e() {
let e = /* @__PURE__ */ new Set(), t = e;
return {
add(i) {
M += t == e && !e.has(i) ? 1 : 0, e.add(i);
},
delete(i) {
return M -= t == e && e.has(i) ? 1 : 0, e.delete(i);
},
flush(i) {
t.size && (e = /* @__PURE__ */ new Set(), M -= t.size, Zt(t, (n) => n(i) && e.add(n)), M += e.size, t = e);
}
};
}
function Zt(e, t) {
e.forEach((i) => {
try {
t(i);
} catch (n) {
y.catch(n);
}
});
}
var Ui = Object.defineProperty, qi = (e, t) => {
for (var i in t)
Ui(e, i, { get: t[i], enumerable: !0 });
}, O = {};
qi(O, {
assign: () => ji,
colors: () => L,
createStringInterpolator: () => lt,
skipAnimation: () => Jt,
to: () => Kt,
willAdvance: () => ct
});
function He() {
}
var $i = (e, t, i) => Object.defineProperty(e, t, { value: i, writable: !0, configurable: !0 }), o = {
arr: Array.isArray,
obj: (e) => !!e && e.constructor.name === "Object",
fun: (e) => typeof e == "function",
str: (e) => typeof e == "string",
num: (e) => typeof e == "number",
und: (e) => e === void 0
};
function z(e, t) {
if (o.arr(e)) {
if (!o.arr(t) || e.length !== t.length) return !1;
for (let i = 0; i < e.length; i++)
if (e[i] !== t[i]) return !1;
return !0;
}
return e === t;
}
var S = (e, t) => e.forEach(t);
function $(e, t, i) {
if (o.arr(e)) {
for (let n = 0; n < e.length; n++)
t.call(i, e[n], `${n}`);
return;
}
for (const n in e)
e.hasOwnProperty(n) && t.call(i, e[n], n);
}
var I = (e) => o.und(e) ? [] : o.arr(e) ? e : [e];
function ae(e, t) {
if (e.size) {
const i = Array.from(e);
e.clear(), S(i, t);
}
}
var se = (e, ...t) => ae(e, (i) => i(...t)), ut = () => typeof window > "u" || !window.navigator || /ServerSideRendering|^Deno\//.test(window.navigator.userAgent), lt, Kt, L = null, Jt = !1, ct = He, ji = (e) => {
e.to && (Kt = e.to), e.now && (y.now = e.now), e.colors !== void 0 && (L = e.colors), e.skipAnimation != null && (Jt = e.skipAnimation), e.createStringInterpolator && (lt = e.createStringInterpolator), e.requestAnimationFrame && y.use(e.requestAnimationFrame), e.batchedUpdates && (y.batchedUpdates = e.batchedUpdates), e.willAdvance && (ct = e.willAdvance), e.frameLoop && (y.frameLoop = e.frameLoop);
}, oe = /* @__PURE__ */ new Set(), V = [], De = [], ke = 0, Ce = {
get idle() {
return !oe.size && !V.length;
},
/** Advance the given animation on every frame until idle. */
start(e) {
ke > e.priority ? (oe.add(e), y.onStart(zi)) : (ei(e), y(We));
},
/** Advance all animations by the given time. */
advance: We,
/** Call this when an animation's priority changes. */
sort(e) {
if (ke)
y.onFrame(() => Ce.sort(e));
else {
const t = V.indexOf(e);
~t && (V.splice(t, 1), ti(e));
}
},
/**
* Clear all animations. For testing purposes.
*
* ☠️ Never call this from within the frameloop.
*/
clear() {
V = [], oe.clear();
}
};
function zi() {
oe.forEach(ei), oe.clear(), y(We);
}
function ei(e) {
V.includes(e) || ti(e);
}
function ti(e) {
V.splice(
Ni(V, (t) => t.priority > e.priority),
0,
e
);
}
function We(e) {
const t = De;
for (let i = 0; i < V.length; i++) {
const n = V[i];
ke = n.priority, n.idle || (ct(n), n.advance(e), n.idle || t.push(n));
}
return ke = 0, De = V, De.length = 0, V = t, V.length > 0;
}
function Ni(e, t) {
const i = e.findIndex(t);
return i < 0 ? e.length : i;
}
var Di = {
transparent: 0,
aliceblue: 4042850303,
antiquewhite: 4209760255,
aqua: 16777215,
aquamarine: 2147472639,
azure: 4043309055,
beige: 4126530815,
bisque: 4293182719,
black: 255,
blanchedalmond: 4293643775,
blue: 65535,
blueviolet: 2318131967,
brown: 2771004159,
burlywood: 3736635391,
burntsienna: 3934150143,
cadetblue: 1604231423,
chartreuse: 2147418367,
chocolate: 3530104575,
coral: 4286533887,
cornflowerblue: 1687547391,
cornsilk: 4294499583,
crimson: 3692313855,
cyan: 16777215,
darkblue: 35839,
darkcyan: 9145343,
darkgoldenrod: 3095792639,
darkgray: 2846468607,
darkgreen: 6553855,
darkgrey: 2846468607,
darkkhaki: 3182914559,
darkmagenta: 2332068863,
darkolivegreen: 1433087999,
darkorange: 4287365375,
darkorchid: 2570243327,
darkred: 2332033279,
darksalmon: 3918953215,
darkseagreen: 2411499519,
darkslateblue: 1211993087,
darkslategray: 793726975,
darkslategrey: 793726975,
darkturquoise: 13554175,
darkviolet: 2483082239,
deeppink: 4279538687,
deepskyblue: 12582911,
dimgray: 1768516095,
dimgrey: 1768516095,
dodgerblue: 512819199,
firebrick: 2988581631,
floralwhite: 4294635775,
forestgreen: 579543807,
fuchsia: 4278255615,
gainsboro: 3705462015,
ghostwhite: 4177068031,
gold: 4292280575,
goldenrod: 3668254975,
gray: 2155905279,
green: 8388863,
greenyellow: 2919182335,
grey: 2155905279,
honeydew: 4043305215,
hotpink: 4285117695,
indianred: 3445382399,
indigo: 1258324735,
ivory: 4294963455,
khaki: 4041641215,
lavender: 3873897215,
lavenderblush: 4293981695,
lawngreen: 2096890111,
lemonchiffon: 4294626815,
lightblue: 2916673279,
lightcoral: 4034953471,
lightcyan: 3774873599,
lightgoldenrodyellow: 4210742015,
lightgray: 3553874943,
lightgreen: 2431553791,
lightgrey: 3553874943,
lightpink: 4290167295,
lightsalmon: 4288707327,
lightseagreen: 548580095,
lightskyblue: 2278488831,
lightslategray: 2005441023,
lightslategrey: 2005441023,
lightsteelblue: 2965692159,
lightyellow: 4294959359,
lime: 16711935,
limegreen: 852308735,
linen: 4210091775,
magenta: 4278255615,
maroon: 2147483903,
mediumaquamarine: 1724754687,
mediumblue: 52735,
mediumorchid: 3126187007,
mediumpurple: 2473647103,
mediumseagreen: 1018393087,
mediumslateblue: 2070474495,
mediumspringgreen: 16423679,
mediumturquoise: 1221709055,
mediumvioletred: 3340076543,
midnightblue: 421097727,
mintcream: 4127193855,
mistyrose: 4293190143,
moccasin: 4293178879,
navajowhite: 4292783615,
navy: 33023,
oldlace: 4260751103,
olive: 2155872511,
olivedrab: 1804477439,
orange: 4289003775,
orangered: 4282712319,
orchid: 3664828159,
palegoldenrod: 4008225535,
palegreen: 2566625535,
paleturquoise: 2951671551,
palevioletred: 3681588223,
papayawhip: 4293907967,
peachpuff: 4292524543,
peru: 3448061951,
pink: 4290825215,
plum: 3718307327,
powderblue: 2967529215,
purple: 2147516671,
rebeccapurple: 1714657791,
red: 4278190335,
rosybrown: 3163525119,
royalblue: 1097458175,
saddlebrown: 2336560127,
salmon: 4202722047,
sandybrown: 4104413439,
seagreen: 780883967,
seashell: 4294307583,
sienna: 2689740287,
silver: 3233857791,
skyblue: 2278484991,
slateblue: 1784335871,
slategray: 1887473919,
slategrey: 1887473919,
snow: 4294638335,
springgreen: 16744447,
steelblue: 1182971135,
tan: 3535047935,
teal: 8421631,
thistle: 3636451583,
tomato: 4284696575,
turquoise: 1088475391,
violet: 4001558271,
wheat: 4125012991,
white: 4294967295,
whitesmoke: 4126537215,
yellow: 4294902015,
yellowgreen: 2597139199
}, E = "[-+]?\\d*\\.?\\d+", Ie = E + "%";
function Ee(...e) {
return "\\(\\s*(" + e.join(")\\s*,\\s*(") + ")\\s*\\)";
}
var Qi = new RegExp("rgb" + Ee(E, E, E)), Mi = new RegExp("rgba" + Ee(E, E, E, E)), Li = new RegExp("hsl" + Ee(E, Ie, Ie)), Bi = new RegExp(
"hsla" + Ee(E, Ie, Ie, E)
), Gi = /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/, Yi = /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/, Hi = /^#([0-9a-fA-F]{6})$/, Wi = /^#([0-9a-fA-F]{8})$/;
function Xi(e) {
let t;
return typeof e == "number" ? e >>> 0 === e && e >= 0 && e <= 4294967295 ? e : null : (t = Hi.exec(e)) ? parseInt(t[1] + "ff", 16) >>> 0 : L && L[e] !== void 0 ? L[e] : (t = Qi.exec(e)) ? (Z(t[1]) << 24 | // r
Z(t[2]) << 16 | // g
Z(t[3]) << 8 | // b
255) >>> // a
0 : (t = Mi.exec(e)) ? (Z(t[1]) << 24 | // r
Z(t[2]) << 16 | // g
Z(t[3]) << 8 | // b
Rt(t[4])) >>> // a
0 : (t = Gi.exec(e)) ? parseInt(
t[1] + t[1] + // r
t[2] + t[2] + // g
t[3] + t[3] + // b
"ff",
// a
16
) >>> 0 : (t = Wi.exec(e)) ? parseInt(t[1], 16) >>> 0 : (t = Yi.exec(e)) ? parseInt(
t[1] + t[1] + // r
t[2] + t[2] + // g
t[3] + t[3] + // b
t[4] + t[4],
// a
16
) >>> 0 : (t = Li.exec(e)) ? (Pt(
xt(t[1]),
// h
Ae(t[2]),
// s
Ae(t[3])
// l
) | 255) >>> // a
0 : (t = Bi.exec(e)) ? (Pt(
xt(t[1]),
// h
Ae(t[2]),
// s
Ae(t[3])
// l
) | Rt(t[4])) >>> // a
0 : null;
}
function Qe(e, t, i) {
return i < 0 && (i += 1), i > 1 && (i -= 1), i < 1 / 6 ? e + (t - e) * 6 * i : i < 1 / 2 ? t : i < 2 / 3 ? e + (t - e) * (2 / 3 - i) * 6 : e;
}
function Pt(e, t, i) {
const n = i < 0.5 ? i * (1 + t) : i + t - i * t, r = 2 * i - n, s = Qe(r, n, e + 1 / 3), a = Qe(r, n, e), u = Qe(r, n, e - 1 / 3);
return Math.round(s * 255) << 24 | Math.round(a * 255) << 16 | Math.round(u * 255) << 8;
}
function Z(e) {
const t = parseInt(e, 10);
return t < 0 ? 0 : t > 255 ? 255 : t;
}
function xt(e) {
return (parseFloat(e) % 360 + 360) % 360 / 360;
}
function Rt(e) {
const t = parseFloat(e);
return t < 0 ? 0 : t > 1 ? 255 : Math.round(t * 255);
}
function Ae(e) {
const t = parseFloat(e);
return t < 0 ? 0 : t > 100 ? 1 : t / 100;
}
function kt(e) {
let t = Xi(e);
if (t === null) return e;
t = t || 0;
const i = (t & 4278190080) >>> 24, n = (t & 16711680) >>> 16, r = (t & 65280) >>> 8, s = (t & 255) / 255;
return `rgba(${i}, ${n}, ${r}, ${s})`;
}
var ce = (e, t, i) => {
if (o.fun(e))
return e;
if (o.arr(e))
return ce({
range: e,
output: t,
extrapolate: i
});
if (o.str(e.output[0]))
return lt(e);
const n = e, r = n.output, s = n.range || [0, 1], a = n.extrapolateLeft || n.extrapolate || "extend", u = n.extrapolateRight || n.extrapolate || "extend", c = n.easing || ((l) => l);
return (l) => {
const m = Ki(l, s);
return Zi(
l,
s[m],
s[m + 1],
r[m],
r[m + 1],
c,
a,
u,
n.map
);
};
};
function Zi(e, t, i, n, r, s, a, u, c) {
let l = c ? c(e) : e;
if (l < t) {
if (a === "identity") return l;
a === "clamp" && (l = t);
}
if (l > i) {
if (u === "identity") return l;
u === "clamp" && (l = i);
}
return n === r ? n : t === i ? e <= t ? n : r : (t === -1 / 0 ? l = -l : i === 1 / 0 ? l = l - t : l = (l - t) / (i - t), l = s(l), n === -1 / 0 ? l = -l : r === 1 / 0 ? l = l + n : l = l * (r - n) + n, l);
}
function Ki(e, t) {
for (var i = 1; i < t.length - 1 && !(t[i] >= e); ++i)
;
return i - 1;
}
var Ji = {
linear: (e) => e
}, de = Symbol.for("FluidValue.get"), ee = Symbol.for("FluidValue.observers"), T = (e) => !!(e && e[de]), k = (e) => e && e[de] ? e[de]() : e, It = (e) => e[ee] || null;
function en(e, t) {
e.eventObserved ? e.eventObserved(t) : e(t);
}
function fe(e, t) {
const i = e[ee];
i && i.forEach((n) => {
en(n, t);
});
}
var ii = class {
constructor(e) {
if (!e && !(e = this.get))
throw Error("Unknown getter");
tn(this, e);
}
}, tn = (e, t) => ni(e, de, t);
function te(e, t) {
if (e[de]) {
let i = e[ee];
i || ni(e, ee, i = /* @__PURE__ */ new Set()), i.has(t) || (i.add(t), e.observerAdded && e.observerAdded(i.size, t));
}
return t;
}
function he(e, t) {
const i = e[ee];
if (i && i.has(t)) {
const n = i.size - 1;
n ? i.delete(t) : e[ee] = null, e.observerRemoved && e.observerRemoved(n, t);
}
}
var ni = (e, t, i) => Object.defineProperty(e, t, {
value: i,
writable: !0,
configurable: !0
}), Pe = /[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, nn = /(#(?:[0-9a-f]{2}){2,4}|(#[0-9a-f]{3})|(rgb|hsl)a?\((-?\d+%?[,\s]+){2,3}\s*[\d\.]+%?\))/gi, Tt = new RegExp(`(${Pe.source})(%|[a-z]+)`, "i"), rn = /rgba\(([0-9\.-]+), ([0-9\.-]+), ([0-9\.-]+), ([0-9\.-]+)\)/gi, Oe = /var\((--[a-zA-Z0-9-_]+),? ?([a-zA-Z0-9 ()%#.,-]+)?\)/, ri = (e) => {
const [t, i] = sn(e);
if (!t || ut())
return e;
const n = window.getComputedStyle(document.documentElement).getPropertyValue(t);
if (n)
return n.trim();
if (i && i.startsWith("--")) {
const r = window.getComputedStyle(document.documentElement).getPropertyValue(i);
return r || e;
} else {
if (i && Oe.test(i))
return ri(i);
if (i)
return i;
}
return e;
}, sn = (e) => {
const t = Oe.exec(e);
if (!t) return [,];
const [, i, n] = t;
return [i, n];
}, Me, an = (e, t, i, n, r) => `rgba(${Math.round(t)}, ${Math.round(i)}, ${Math.round(n)}, ${r})`, si = (e) => {
Me || (Me = L ? (
// match color names, ignore partial matches
new RegExp(`(${Object.keys(L).join("|")})(?!\\w)`, "g")
) : (
// never match
/^\b$/
));
const t = e.output.map((s) => k(s).replace(Oe, ri).replace(nn, kt).replace(Me, kt)), i = t.map((s) => s.match(Pe).map(Number)), r = i[0].map(
(s, a) => i.map((u) => {
if (!(a in u))
throw Error('The arity of each "output" value must be equal');
return u[a];
})
).map(
(s) => ce({ ...e, output: s })
);
return (s) => {
const a = !Tt.test(t[0]) && t.find((c) => Tt.test(c))?.replace(Pe, "");
let u = 0;
return t[0].replace(
Pe,
() => `${r[u++](s)}${a || ""}`
).replace(rn, an);
};
}, dt = "react-spring: ", ai = (e) => {
const t = e;
let i = !1;
if (typeof t != "function")
throw new TypeError(`${dt}once requires a function parameter`);
return (...n) => {
i || (t(...n), i = !0);
};
}, on = ai(console.warn);
function un() {
on(
`${dt}The "interpolate" function is deprecated in v9 (use "to" instead)`
);
}
var ln = ai(console.warn);
function cn() {
ln(
`${dt}Directly calling start instead of using the api object is deprecated in v9 (use ".start" instead), this will be removed in later 0.X.0 versions`
);
}
function Ue(e) {
return o.str(e) && (e[0] == "#" || /\d/.test(e) || // Do not identify a CSS variable as an AnimatedString if its SSR
!ut() && Oe.test(e) || e in (L || {}));
}
var ft = ut() ? H : Vi, dn = () => {
const e = Y(!1);
return ft(() => (e.current = !0, () => {
e.current = !1;
}), []), e;
};
function oi() {
const e = Re()[1], t = dn();
return () => {
t.current && e(Math.random());
};
}
var ui = (e) => H(e, fn), fn = [];
function Vt(e) {
const t = Y(void 0);
return H(() => {
t.current = e;
}), t.current;
}
var me = Symbol.for("Animated:node"), hn = (e) => !!e && e[me] === e, q = (e) => e && e[me], ht = (e, t) => $i(e, me, t), qe = (e) => e && e[me] && e[me].getPayload(), li = class {
constructor() {
ht(this, this);
}
/** Get every `AnimatedValue` used by this node. */
getPayload() {
return this.payload || [];
}
}, $e = class ci extends li {
constructor(t) {
super(), this._value = t, this.done = !0, this.durationProgress = 0, o.num(this._value) && (this.lastPosition = this._value);
}
/** @internal */
static create(t) {
return new ci(t);
}
getPayload() {
return [this];
}
getValue() {
return this._value;
}
setValue(t, i) {
return o.num(t) && (this.lastPosition = t, i && (t = Math.round(t / i) * i, this.done && (this.lastPosition = t))), this._value === t ? !1 : (this._value = t, !0);
}
reset() {
const { done: t } = this;
this.done = !1, o.num(this._value) && (this.elapsedTime = 0, this.durationProgress = 0, this.lastPosition = this._value, t && (this.lastVelocity = null), this.v0 = null);
}
}, Te = class di extends $e {
constructor(t) {
super(0), this._string = null, this._toString = ce({
output: [t, t]
});
}
/** @internal */
static create(t) {
return new di(t);
}
getValue() {
const t = this._string;
return t ?? (this._string = this._toString(this._value));
}
setValue(t) {
if (o.str(t)) {
if (t == this._string)
return !1;
this._string = t, this._value = 1;
} else if (super.setValue(t))
this._string = null;
else
return !1;
return !0;
}
reset(t) {
t && (this._toString = ce({
output: [this.getValue(), t]
})), this._value = 0, super.reset();
}
}, Ve = { dependencies: null }, je = class extends li {
constructor(e) {
super(), this.source = e, this.setValue(e);
}
getValue(e) {
const t = {};
return $(this.source, (i, n) => {
hn(i) ? t[n] = i.getValue(e) : T(i) ? t[n] = k(i) : e || (t[n] = i);
}), t;
}
/** Replace the raw object data */
setValue(e) {
this.source = e, this.payload = this._makePayload(e);
}
reset() {
this.payload && S(this.payload, (e) => e.reset());
}
/** Create a payload set. */
_makePayload(e) {
if (e) {
const t = /* @__PURE__ */ new Set();
return $(e, this._addToPayload, t), Array.from(t);
}
}
/** Add to a payload set. */
_addToPayload(e) {
Ve.dependencies && T(e) && Ve.dependencies.add(e);
const t = qe(e);
t && S(t, (i) => this.add(i));
}
}, mn = class fi extends je {
constructor(t) {
super(t);
}
/** @internal */
static create(t) {
return new fi(t);
}
getValue() {
return this.source.map((t) => t.getValue());
}
setValue(t) {
const i = this.getPayload();
return t.length == i.length ? i.map((n, r) => n.setValue(t[r])).some(Boolean) : (super.setValue(t.map(pn)), !0);
}
};
function pn(e) {
return (Ue(e) ? Te : $e).create(e);
}
function Xe(e) {
const t = q(e);
return t ? t.constructor : o.arr(e) ? mn : Ue(e) ? Te : $e;
}
var Ft = (e, t) => {
const i = (
// Function components must use "forwardRef" to avoid being
// re-rendered on every animation frame.
!o.fun(e) || e.prototype && e.prototype.isReactComponent
);
return Fi((n, r) => {
const s = Y(null), a = i && // eslint-disable-next-line react-hooks/rules-of-hooks
Gt(
(_) => {
s.current = yn(r, _);
},
[r]
), [u, c] = vn(n, t), l = oi(), m = () => {
const _ = s.current;
if (i && !_)
return;
(_ ? t.applyAnimatedValues(_, u.getValue(!0)) : !1) === !1 && l();
}, d = new gn(m, c), h = Y(void 0);
ft(() => (h.current = d, S(c, (_) => te(_, d)), () => {
h.current && (S(
h.current.deps,
(_) => he(_, h.current)
), y.cancel(h.current.update));
})), H(m, []), ui(() => () => {
const _ = h.current;
S(_.deps, (g) => he(g, _));
});
const p = t.getComponentProps(u.getValue());
return /* @__PURE__ */ Bt.createElement(e, { ...p, ref: a });
});
}, gn = class {
constructor(e, t) {
this.update = e, this.deps = t;
}
eventObserved(e) {
e.type == "change" && y.write(this.update);
}
};
function vn(e, t) {
const i = /* @__PURE__ */ new Set();
return Ve.dependencies = i, e.style && (e = {
...e,
style: t.createAnimatedStyle(e.style)
}), e = new je(e), Ve.dependencies = null, [e, i];
}
function yn(e, t) {
return e && (o.fun(e) ? e(t) : e.current = t), t;
}
var Ct = Symbol.for("AnimatedComponent"), _n = (e, {
applyAnimatedValues: t = () => !1,
createAnimatedStyle: i = (r) => new je(r),
getComponentProps: n = (r) => r
} = {}) => {
const r = {
applyAnimatedValues: t,
createAnimatedStyle: i,
getComponentProps: n
}, s = (a) => {
const u = Et(a) || "Anonymous";
return o.str(a) ? a = s[a] || (s[a] = Ft(a, r)) : a = a[Ct] || (a[Ct] = Ft(a, r)), a.displayName = `Animated(${u})`, a;
};
return $(e, (a, u) => {
o.arr(e) && (u = Et(a)), s[u] = s(a);
}), {
animated: s
};
}, Et = (e) => o.str(e) ? e : e && o.str(e.displayName) ? e.displayName : o.fun(e) && e.name || null;
function G(e, ...t) {
return o.fun(e) ? e(...t) : e;
}
var ue = (e, t) => e === !0 || !!(t && e && (o.fun(e) ? e(t) : I(e).includes(t))), hi = (e, t) => o.obj(e) ? t && e[t] : e, mi = (e, t) => e.default === !0 ? e[t] : e.default ? e.default[t] : void 0, bn = (e) => e, mt = (e, t = bn) => {
let i = wn;
e.default && e.default !== !0 && (e = e.default, i = Object.keys(e));
const n = {};
for (const r of i) {
const s = t(e[r], r);
o.und(s) || (n[r] = s);
}
return n;
}, wn = [
"config",
"onProps",
"onStart",
"onChange",
"onPause",
"onResume",
"onRest"
], Sn = {
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,
// Transition props
items: 1,
trail: 1,
sort: 1,
expires: 1,
initial: 1,
enter: 1,
update: 1,
leave: 1,
children: 1,
onDestroyed: 1,
// Internal props
keys: 1,
callId: 1,
parentId: 1
};
function An(e) {
const t = {};
let i = 0;
if ($(e, (n, r) => {
Sn[r] || (t[r] = n, i++);
}), i)
return t;
}
function pi(e) {
const t = An(e);
if (t) {
const i = { to: t };
return $(e, (n, r) => r in t || (i[r] = n)), i;
}
return { ...e };
}
function pe(e) {
return e = k(e), o.arr(e) ? e.map(pe) : Ue(e) ? O.createStringInterpolator({
range: [0, 1],
output: [e, e]
})(1) : e;
}
function Pn(e) {
for (const t in e) return !0;
return !1;
}
function Ze(e) {
return o.fun(e) || o.arr(e) && o.obj(e[0]);
}
function xn(e, t) {
e.ref?.delete(e), t?.delete(e);
}
function Rn(e, t) {
t && e.ref !== t && (e.ref?.delete(e), t.add(e), e.ref = t);
}
var kn = {
default: { tension: 170, friction: 26 }
}, Ke = {
...kn.default,
mass: 1,
damping: 1,
easing: Ji.linear,
clamp: !1
}, In = class {
constructor() {
this.velocity = 0, Object.assign(this, Ke);
}
};
function Tn(e, t, i) {
i && (i = { ...i }, Ot(i, t), t = { ...i, ...t }), Ot(e, t), Object.assign(e, t);
for (const a in Ke)
e[a] == null && (e[a] = Ke[a]);
let { frequency: n, damping: r } = e;
const { mass: s } = e;
return o.und(n) || (n < 0.01 && (n = 0.01), r < 0 && (r = 0), e.tension = Math.pow(2 * Math.PI / n, 2) * s, e.friction = 4 * Math.PI * r * s / n), e;
}
function Ot(e, t) {
if (!o.und(t.decay))
e.duration = void 0;
else {
const i = !o.und(t.tension) || !o.und(t.friction);
(i || !o.und(t.frequency) || !o.und(t.damping) || !o.und(t.mass)) && (e.duration = void 0, e.decay = void 0), i && (e.frequency = void 0);
}
}
var Ut = [], Vn = class {
constructor() {
this.changed = !1, this.values = Ut, this.toValues = null, this.fromValues = Ut, this.config = new In(), this.immediate = !1;
}
};
function gi(e, { key: t, props: i, defaultProps: n, state: r, actions: s }) {
return new Promise((a, u) => {
let c, l, m = ue(i.cancel ?? n?.cancel, t);
if (m)
p();
else {
o.und(i.pause) || (r.paused = ue(i.pause, t));
let _ = n?.pause;
_ !== !0 && (_ = r.paused || ue(_, t)), c = G(i.delay || 0, t), _ ? (r.resumeQueue.add(h), s.pause()) : (s.resume(), h());
}
function d() {
r.resumeQueue.add(h), r.timeouts.delete(l), l.cancel(), c = l.time - y.now();
}
function h() {
c > 0 && !O.skipAnimation ? (r.delayed = !0, l = y.setTimeout(p, c), r.pauseQueue.add(d), r.timeouts.add(l)) : p();
}
function p() {
r.delayed && (r.delayed = !1), r.pauseQueue.delete(d), r.timeouts.delete(l), e <= (r.cancelId || 0) && (m = !0);
try {
s.start({ ...i, callId: e, cancel: m }, a);
} catch (_) {
u(_);
}
}
});
}
var pt = (e, t) => t.length == 1 ? t[0] : t.some((i) => i.cancelled) ? J(e.get()) : t.every((i) => i.noop) ? vi(e.get()) : C(
e.get(),
t.every((i) => i.finished)
), vi = (e) => ({
value: e,
noop: !0,
finished: !0,
cancelled: !1
}), C = (e, t, i = !1) => ({
value: e,
finished: t,
cancelled: i
}), J = (e) => ({
value: e,
cancelled: !0,
finished: !1
});
function yi(e, t, i, n) {
const { callId: r, parentId: s, onRest: a } = t, { asyncTo: u, promise: c } = i;
return !s && e === u && !t.reset ? c : i.promise = (async () => {
i.asyncId = r, i.asyncTo = e;
const l = mt(
t,
(b, f) => (
// The `onRest` prop is only called when the `runAsync` promise is resolved.
f === "onRest" ? void 0 : b
)
);
let m, d;
const h = new Promise(
(b, f) => (m = b, d = f)
), p = (b) => {
const f = (
// The `cancel` prop or `stop` method was used.
r <= (i.cancelId || 0) && J(n) || // The async `to` prop was replaced.
r !== i.asyncId && C(n, !1)
);
if (f)
throw b.result = f, d(b), b;
}, _ = (b, f) => {
const w = new qt(), v = new $t();
return (async () => {
if (O.skipAnimation)
throw ge(i), v.result = C(n, !1), d(v), v;
p(w);
const A = o.obj(b) ? { ...b } : { ...f, to: b };
A.parentId = r, $(l, (U, x) => {
o.und(A[x]) && (A[x] = U);
});
const P = await n.start(A);
return p(w), i.paused && await new Promise((U) => {
i.resumeQueue.add(U);
}), P;
})();
};
let g;
if (O.skipAnimation)
return ge(i), C(n, !1);
try {
let b;
o.arr(e) ? b = (async (f) => {
for (const w of f)
await _(w);
})(e) : b = Promise.resolve(e(_, n.stop.bind(n))), await Promise.all([b.then(m), h]), g = C(n.get(), !0, !1);
} catch (b) {
if (b instanceof qt)
g = b.result;
else if (b instanceof $t)
g = b.result;
else
throw b;
} finally {
r == i.asyncId && (i.asyncId = s, i.asyncTo = s ? u : void 0, i.promise = s ? c : void 0);
}
return o.fun(a) && y.batchedUpdates(() => {
a(g, n, n.item);
}), g;
})();
}
function ge(e, t) {
ae(e.timeouts, (i) => i.cancel()), e.pauseQueue.clear(), e.resumeQueue.clear(), e.asyncId = e.asyncTo = e.promise = void 0, t && (e.cancelId = t);
}
var qt = class 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."
);
}
}, $t = class extends Error {
constructor() {
super("SkipAnimationSignal");
}
}, Je = (e) => e instanceof gt, Fn = 1, gt = class extends ii {
constructor() {
super(...arguments), this.id = Fn++, this._priority = 0;
}
get priority() {
return this._priority;
}
set priority(e) {
this._priority != e && (this._priority = e, this._onPriorityChange(e));
}
/** Get the current value */
get() {
const e = q(this);
return e && e.getValue();
}
/** Create a spring that maps our value to another value */
to(...e) {
return O.to(this, e);
}
/** @deprecated Use the `to` method instead. */
interpolate(...e) {
return un(), O.to(this, e);
}
toJSON() {
return this.get();
}
observerAdded(e) {
e == 1 && this._attach();
}
observerRemoved(e) {
e == 0 && this._detach();
}
/** Called when the first child is added. */
_attach() {
}
/** Called when the last child is removed. */
_detach() {
}
/** Tell our children about our new value */
_onChange(e, t = !1) {
fe(this, {
type: "change",
parent: this,
value: e,
idle: t
});
}
/** Tell our children about our new priority */
_onPriorityChange(e) {
this.idle || Ce.sort(this), fe(this, {
type: "priority",
parent: this,
priority: e
});
}
}, W = Symbol.for("SpringPhase"), _i = 1, et = 2, tt = 4, Le = (e) => (e[W] & _i) > 0, D = (e) => (e[W] & et) > 0, ie = (e) => (e[W] & tt) > 0, jt = (e, t) => t ? e[W] |= et | _i : e[W] &= ~et, zt = (e, t) => t ? e[W] |= tt : e[W] &= ~tt, Cn = class extends gt {
constructor(e, t) {
if (super(), this.animation = new Vn(), 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, !o.und(e) || !o.und(t)) {
const i = o.obj(e) ? { ...e } : { ...t, from: e };
o.und(i.default) && (i.default = !0), this.start(i);
}
}
/** Equals true when not advancing on each frame. */
get idle() {
return !(D(this) || this._state.asyncTo) || ie(this);
}
get goal() {
return k(this.animation.to);
}
get velocity() {
const e = q(this);
return e instanceof $e ? e.lastVelocity || 0 : e.getPayload().map((t) => t.lastVelocity || 0);
}
/**
* When true, this value has been animated at least once.
*/
get hasAnimated() {
return Le(this);
}
/**
* When true, this value has an unfinished animation,
* which is either active or paused.
*/
get isAnimating() {
return D(this);
}
/**
* When true, all current and future animations are paused.
*/
get isPaused() {
return ie(this);
}
/**
*
*
*/
get isDelayed() {
return this._state.delayed;
}
/** Advance the current animation by a number of milliseconds */
advance(e) {
let t = !0, i = !1;
const n = this.animation;
let { toValues: r } = n;
const { config: s } = n, a = qe(n.to);
!a && T(n.to) && (r = I(k(n.to))), n.values.forEach((l, m) => {
if (l.done) return;
const d = (
// Animated strings always go from 0 to 1.
l.constructor == Te ? 1 : a ? a[m].lastPosition : r[m]
);
let h = n.immediate, p = d;
if (!h) {
if (p = l.lastPosition, s.tension <= 0) {
l.done = !0;
return;
}
let _ = l.elapsedTime += e;
const g = n.fromValues[m], b = l.v0 != null ? l.v0 : l.v0 = o.arr(s.velocity) ? s.velocity[m] : s.velocity;
let f;
const w = s.precision || (g == d ? 5e-3 : Math.min(1, Math.abs(d - g) * 1e-3));
if (o.und(s.duration))
if (s.decay) {
const v = s.decay === !0 ? 0.998 : s.decay, A = Math.exp(-(1 - v) * _);
p = g + b / (1 - v) * (1 - A), h = Math.abs(l.lastPosition - p) <= w, f = b * A;
} else {
f = l.lastVelocity == null ? b : l.lastVelocity;
const v = s.restVelocity || w / 10, A = s.clamp ? 0 : s.bounce, P = !o.und(A), U = g == d ? l.v0 > 0 : g < d;
let x, B = !1;
const R = 1, N = Math.ceil(e / R);
for (let F = 0; F < N && (x = Math.abs(f) > v, !(!x && (h = Math.abs(d - p) <= w, h))); ++F) {
P && (B = p == d || p > d == U, B && (f = -f * A, p = d));
const j = -s.tension * 1e-6 * (p - d), X = -s.friction * 1e-3 * f, be = (j + X) / s.mass;
f = f + be * R, p = p + f * R;
}
}
else {
let v = 1;
s.duration > 0 && (this._memoizedDuration !== s.duration && (this._memoizedDuration = s.duration, l.durationProgress > 0 && (l.elapsedTime = s.duration * l.durationProgress, _ = l.elapsedTime += e)), v = (s.progress || 0) + _ / this._memoizedDuration, v = v > 1 ? 1 : v < 0 ? 0 : v, l.durationProgress = v), p = g + s.easing(v) * (d - g), f = (p - l.lastPosition) / e, h = v == 1;
}
l.lastVelocity = f, Number.isNaN(p) && (console.warn("Got NaN while animating:", this), h = !0);
}
a && !a[m].done && (h = !1), h ? l.done = !0 : t = !1, l.setValue(p, s.round) && (i = !0);
});
const u = q(this), c = u.getValue();
if (t) {
const l = k(n.to);
(c !== l || i) && !s.decay ? (u.setValue(l), this._onChange(l)) : i && s.decay && this._onChange(c), this._stop();
} else i && this._onChange(c);
}
/** Set the current value, while stopping the current animation */
set(e) {
return y.batchedUpdates(() => {
this._stop(), this._focus(e), this._set(e);
}), this;
}
/**
* Freeze the active animation in time, as well as any updates merged
* before `resume` is called.
*/
pause() {
this._update({ pause: !0 });
}
/** Resume the animation if paused. */
resume() {
this._update({ pause: !1 });
}
/** Skip to the end of the current animation. */
finish() {
if (D(this)) {
const { to: e, config: t } = this.animation;
y.batchedUpdates(() => {
this._onStart(), t.decay || this._set(e, !1), this._stop();
});
}
return this;
}
/** Push props into the pending queue. */
update(e) {
return (this.queue || (this.queue = [])).push(e), this;
}
start(e, t) {
let i;
return o.und(e) ? (i = this.queue || [], this.queue = []) : i = [o.obj(e) ? e : { ...t, to: e }], Promise.all(
i.map((n) => this._update(n))
).then((n) => pt(this, n));
}
/**
* Stop the current animation, and cancel any delayed updates.
*
* Pass `true` to call `onRest` with `cancelled: true`.
*/
stop(e) {
const { to: t } = this.animation;
return this._focus(this.get()), ge(this._state, e && this._lastCallId), y.batchedUpdates(() => this._stop(t, e)), this;
}
/** Restart the animation. */
reset() {
this._update({ reset: !0 });
}
/** @internal */
eventObserved(e) {
e.type == "change" ? this._start() : e.type == "priority" && (this.priority = e.priority + 1);
}
/**
* Parse the `to` and `from` range from the given `props` object.
*
* This also ensures the initial value is available to animated components
* during the render phase.
*/
_prepareNode(e) {
const t = this.key || "";
let { to: i, from: n } = e;
i = o.obj(i) ? i[t] : i, (i == null || Ze(i)) && (i = void 0), n = o.obj(n) ? n[t] : n, n == null && (n = void 0);
const r = { to: i, from: n };
return Le(this) || (e.reverse && ([i, n] = [n, i]), n = k(n), o.und(n) ? q(this) || this._set(i) : this._set(n)), r;
}
/** Every update is processed by this method before merging. */
_update({ ...e }, t) {
const { key: i, defaultProps: n } = this;
e.default && Object.assign(
n,
mt(
e,
(a, u) => /^on/.test(u) ? hi(a, i) : a
)
), Dt(this, e, "onProps"), re(this, "onProps", e, this);
const r = this._prepareNode(e);
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 s = this._state;
return gi(++this._lastCallId, {
key: i,
props: e,
defaultProps: n,
state: s,
actions: {
pause: () => {
ie(this) || (zt(this, !0), se(s.pauseQueue), re(
this,
"onPause",
C(this, ne(this, this.animation.to)),
this
));
},
resume: () => {
ie(this) && (zt(this, !1), D(this) && this._resume(), se(s.resumeQueue), re(
this,
"onResume",
C(this, ne(this, this.animation.to)),
this
));
},
start: this._merge.bind(this, r)
}
}).then((a) => {
if (e.loop && a.finished && !(t && a.noop)) {
const u = bi(e);
if (u)
return this._update(u, !0);
}
return a;
});
}
/** Merge props into the current animation */
_merge(e, t, i) {
if (t.cancel)
return this.stop(!0), i(J(this));
const n = !o.und(e.to), r = !o.und(e.from);
if (n || r)
if (t.callId > this._lastToId)
this._lastToId = t.callId;
else
return i(J(this));
const { key: s, defaultProps: a, animation: u } = this, { to: c, from: l } = u;
let { to: m = c, from: d = l } = e;
r && !n && (!t.default || o.und(m)) && (m = d), t.reverse && ([m, d] = [d, m]);
const h = !z(d, l);
h && (u.from = d), d = k(d);
const p = !z(m, c);
p && this._focus(m);
const _ = Ze(t.to), { config: g } = u, { decay: b, velocity: f } = g;
(n || r) && (g.velocity = 0), t.config && !_ && Tn(
g,
G(t.config, s),
// Avoid calling the same "config" prop twice.
t.config !== a.config ? G(a.config, s) : void 0
);
let w = q(this);
if (!w || o.und(m))
return i(C(this, !0));
const v = (
// When `reset` is undefined, the `from` prop implies `reset: true`,
// except for declarative updates. When `reset` is defined, there
// must exist a value to animate from.
o.und(t.reset) ? r && !t.default : !o.und(d) && ue(t.reset, s)
), A = v ? d : this.get(), P = pe(m), U = o.num(P) || o.arr(P) || Ue(P), x = !_ && (!U || ue(a.immediate || t.immediate, s));
if (p) {
const F = Xe(m);
if (F !== w.constructor)
if (x)
w = this._set(P);
else
throw Error(
`Cannot animate between ${w.constructor.name} and ${F.name}, as the "to" prop suggests`
);
}
const B = w.constructor;
let R = T(m), N = !1;
if (!R) {
const F = v || !Le(this) && h;
(p || F) && (N = z(pe(A), P), R = !N), (!z(u.immediate, x) && !x || !z(g.decay, b) || !z(g.velocity, f)) && (R = !0);
}
if (N && D(this) && (u.changed && !v ? R = !0 : R || this._stop(c)), !_ && ((R || T(c)) && (u.values = w.getPayload(), u.toValues = T(m) ? null : B == Te ? [1] : I(P)), u.immediate != x && (u.immediate = x, !x && !v && this._set(c)), R)) {
const { onRest: F } = u;
S(On, (X) => Dt(this, t, X));
const j = C(this, ne(this, c));
se(this._pendingCalls, j), this._pendingCalls.add(i), u.changed && y.batchedUpdates(() => {
u.changed = !v, F?.(j, this), v ? G(a.onRest, j) : u.onStart?.(j, this);
});
}
v && this._set(A), _ ? i(yi(t.to, t, this._state, this)) : R ? this._start() : D(this) && !p ? this._pendingCalls.add(i) : i(vi(A));
}
/** Update the `animation.to` value, which might be a `FluidValue` */
_focus(e) {
const t = this.animation;
e !== t.to && (It(this) && this._detach(), t.to = e, It(this) && this._attach());
}
_attach() {
let e = 0;
const { to: t } = this.animation;
T(t) && (te(t, this), Je(t) && (e = t.priority + 1)), this.priority = e;
}
_detach() {
const { to: e } = this.animation;
T(e) && he(e, this);
}
/**
* Update the current value from outside the frameloop,
* and return the `Animated` node.
*/
_set(e, t = !0) {
const i = k(e);
if (!o.und(i)) {
const n = q(this);
if (!n || !z(i, n.getValue())) {
const r = Xe(i);
!n || n.constructor != r ? ht(this, r.create(i)) : n.setValue(i), n && y.batchedUpdates(() => {
this._onChange(i, t);
});
}
}
return q(this);
}
_onStart() {
const e = this.animation;
e.changed || (e.changed = !0, re(
this,
"onStart",
C(this, ne(this, e.to)),
this
));
}
_onChange(e, t) {
t || (this._onStart(), G(this.animation.onChange, e, this)), G(this.defaultProps.onChange, e, this), super._onChange(e, t);
}
// This method resets the animation state (even if already animating) to
// ensure the latest from/to range is used, and it also ensures this spring
// is added to the frameloop.
_start() {
const e = this.animation;
q(this).reset(k(e.to)), e.immediate || (e.fromValues = e.values.map((t) => t.lastPosition)), D(this) || (jt(this, !0), ie(this) || this._resume());
}
_resume() {
O.skipAnimation ? this.finish() : Ce.start(this);
}
/**
* Exit the frameloop and notify `onRest` listeners.
*
* Always wrap `_stop` calls with `batchedUpdates`.
*/
_stop(e, t) {
if (D(this)) {
jt(this, !1);
const i = this.animation;
S(i.values, (r) => {
r.done = !0;
}), i.toValues && (i.onChange = i.onPause = i.onResume = void 0), fe(this, {
type: "idle",
parent: this
});
const n = t ? J(this.get()) : C(this.get(), ne(this, e ?? i.to));
se(this._pendingCalls, n), i.changed && (i.changed = !1, re(this, "onRest", n, this));
}
}
};
function ne(e, t) {
const i = pe(t), n = pe(e.get());
return z(n, i);
}
function bi(e, t = e.loop, i = e.to) {
const n = G(t);
if (n) {
const r = n !== !0 && pi(n), s = (r || e).reverse, a = !r || r.reset;
return ve({
...e,
loop: t,
// Avoid updating default props when looping.
default: !1,
// Never loop the `pause` prop.
pause: void 0,
// For the "reverse" prop to loop as expected, the "to" prop
// must be undefined. The "reverse" prop is ignored when the
// "to" prop is an array or function.
to: !s || Ze(i) ? i : void 0,
// Ignore the "from" prop except on reset.
from: a ? e.from : void 0,
reset: a,
// The "loop" prop can return a "useSpring" props object to
// override any of the original props.
...r
});
}
}
function ve(e) {
const { to: t, from: i } = e = pi(e), n = /* @__PURE__ */ new Set();
return o.obj(t) && Nt(t, n), o.obj(i) && Nt(i, n), e.keys = n.size ? Array.from(n) : null, e;
}
function En(e) {
const t = ve(e);
return o.und(t.default) && (t.default = mt(t)), t;
}
function Nt(e, t) {
$(e, (i, n) => i != null && t.add(n));
}
var On = [
"onStart",
"onRest",
"onChange",
"onPause",
"onResume"
];
function Dt(e, t, i) {
e.animation[i] = t[i] !== mi(t, i) ? hi(t[i], e.key) : void 0;
}
function re(e, t, ...i) {
e.animation[t]?.(...i), e.defaultProps[t]?.(...i);
}
var Un = ["onStart", "onChange", "onRest"], qn = 1, $n = class {
constructor(e, t) {
this.id = qn++, this.springs = {}, this.queue = [], this._lastAsyncId = 0, this._active = /* @__PURE__ */ new Set(), this._changed = /* @__PURE__ */ new Set(), this._started = !1, 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), t && (this._flush = t), e && this.start({ default: !0, ...e });
}
/**
* Equals `true` when no spring values are in the frameloop, and
* no async animation is currently active.
*/
get idle() {
return !this._state.asyncTo && Object.values(this.springs).every((e) => e.idle && !e.isDelayed && !e.isPaused);
}
get item() {
return this._item;
}
set item(e) {
this._item = e;
}
/** Get the current values of our springs */
get() {
const e = {};
return this.each((t, i) => e[i] = t.get()), e;
}
/** Set the current values without animating. */
set(e) {
for (const t in e) {
const i = e[t];
o.und(i) || this.springs[t].set(i);
}
}
/** Push an update onto the queue of each value. */
update(e) {
return e && this.queue.push(ve(e)), this;
}
/**
* Start the queued animations for every spring, and resolve the returned
* promise once all queued animations have finished or been cancelled.
*
* When you pass a queue (instead of nothing), that queue is used instead of
* the queued animations added with the `update` method, which are left alone.
*/
start(e) {
let { queue: t } = this;
return e ? t = I(e).map(ve) : this.queue = [], this._flush ? this._flush(this, t) : (xi(this, t), it(this, t));
}
/** @internal */
stop(e, t) {
if (e !== !!e && (t = e), t) {
const i = this.springs;
S(I(t), (n) => i[n].stop(!!e));
} else
ge(this._state, this._lastAsyncId), this.each((i) => i.stop(!!e));
return this;
}
/** Freeze the active animation in time */
pause(e) {
if (o.und(e))
this.start({ pause: !0 });
else {
const t = this.springs;
S(I(e), (i) => t[i].pause());
}
return this;
}
/** Resume the animation if paused. */
resume(e) {
if (o.und(e))
this.start({ pause: !1 });
else {
const t = this.springs;
S(I(e), (i) => t[i].resume());
}
return this;
}
/** Call a function once per spring value */
each(e) {
$(this.springs, e);
}
/** @internal Called at the end of every animation frame */
_onFrame() {
const { onStart: e, onChange: t, onRest: i } = this._events, n = this._active.size > 0, r = this._changed.size > 0;
(n && !this._started || r && !this._started) && (this._started = !0, ae(e, ([u, c]) => {
c.value = this.get(), u(c, this, this._item);
}));
const s = !n && this._started, a = r || s && i.size ? this.get() : null;
r && t.size && ae(t, ([u, c]) => {
c.value = a, u(c, this, this._item);
}), s && (this._started = !1, ae(i, ([u, c]) => {
c.value = a, u(c, this, this._item);
}));
}
/** @internal */
eventObserved(e) {
if (e.type == "change")
this._changed.add(e.parent), e.idle || this._active.add(e.parent);
else if (e.type == "idle")
this._active.delete(e.parent);
else return;
y.onFrame(this._onFrame);
}
};
function it(e, t) {
return Promise.all(t.map((i) => wi(e, i))).then(
(i) => pt(e, i)
);
}
async function wi(e, t, i) {
const { keys: n, to: r, from: s, loop: a, onRest: u, onResolve: c } = t, l = o.obj(t.default) && t.default;
a && (t.loop = !1), r === !1 && (t.to = null), s === !1 && (t.from = null);
const m = o.arr(r) || o.fun(r) ? r : void 0;
m ? (t.to = void 0, t.onRest = void 0, l && (l.onRest = void 0)) : S(Un, (g) => {
const b = t[g];
if (o.fun(b)) {
const f = e._events[g];
t[g] = ({ finished: w, cancelled: v }) => {
const A = f.get(b);
A ? (w || (A.finished = !1), v && (A.cancelled = !0)) : f.set(b, {
value: null,
finished: w || !1,
cancelled: v || !1
});
}, l && (l[g] = t[g]);
}
});
const d = e._state;
t.pause === !d.paused ? (d.paused = t.pause, se(t.pause ? d.pauseQueue : d.resumeQueue)) : d.paused && (t.pause = !0);
const h = (n || Object.keys(e.springs)).map(
(g) => e.springs[g].start(t)
), p = t.cancel === !0 || mi(t, "cancel") === !0;
(m || p && d.asyncId) && h.push(
gi(++e._lastAsyncId, {
props: t,
state: d,
actions: {
pause: He,
resume: He,
start(g, b) {
p ? (ge(d, e._lastAsyncId), b(J(e))) : (g.onRest = u, b(
yi(
m,
g,
d,
e
)
));
}
}
})
), d.paused && await new Promise((g) => {
d.resumeQueue.add(g);
});
const _ = pt(e, await Promise.all(h));
if (a && _.finished && !(i && _.noop)) {
const g = bi(t, a, r);
if (g)
return xi(e, [g]), wi(e, g, !0);
}
return c && y.batchedUpdates(() => c(_, e, e.item)), _;
}
function Qt(e, t) {
const i = { ...e.springs };
return t && S(I(t), (n) => {
o.und(n.keys) && (n = ve(n)), o.obj(n.to) || (n = { ...n, to: void 0 }), Pi(i, n, (r) => Ai(r));
}), Si(e, i), i;
}
function Si(e, t) {
$(t, (i, n) => {
e.springs[n] || (e.springs[n] = i, te(i, e));
});
}
function Ai(e, t) {
const i = new Cn();
return i.key = e, t && te(i, t), i;
}
function Pi(e, t, i) {
t.keys && S(t.keys, (n) => {
(e[n] || (e[n] = i(n)))._prepareNode(t);
});
}
function xi(e, t) {
S(t, (i) => {
Pi(e.springs, i, (n) => Ai(n, e));
});
}
var jn = Bt.createContext({
pause: !1,
immediate: !1
}), zn = () => {
const e = [], t = function(n) {
cn();
const r = [];
return S(e, (s, a) => {
if (o.und(n))
r.push(s.start());
else {
const u = i(n, s, a);
u && r.push(s.start(u));
}
}), r;
};
t.current = e, t.add = function(n) {
e.includes(n) || e.push(n);
}, t.delete = function(n) {
const r = e.indexOf