welcome-ui
Version:
Customizable design system with react, typescript, tailwindcss and ariakit.
725 lines (724 loc) • 21.9 kB
JavaScript
"use client";
import { a as Ge, c as Fe, b as Ze, d as Je } from "./NI3IVY7K-DxnarnKs.js";
import { P as _e, a as Ke, u as Te, b as Qe } from "./Y67KZUMI-CtXJ_hZt.js";
import { e as et, c as ue, _ as J, i as K, ae as ke, u as Z, M as ae, x as he, d as R, a as E, f as ce, b as le, k as De, l as Pe, S as Oe, a7 as U, V as tt, p as xe, z as ot, q as ge, m as rt, A as nt, W as st, w as it, r as at, aa as ut, v as ct, F as lt, G as q, I as k, H as M, K as dt } from "./OE2EFRVA-C3721cM3.js";
import { B as ft, N as pt, L as mt, A as vt, O as ht, g as Pt, C as gt, a as wt } from "./floating-ui.dom.browser.min-Bza9K_UR.js";
import { useRef as X, useState as de, useEffect as D, useContext as xt, createContext as St, useCallback as Ne, useMemo as Ae } from "react";
import { jsx as A, jsxs as Et } from "react/jsx-runtime";
import { a as bt, u as Ve, m as yt, o as Ot, t as At, c as We, d as ie, b as ze } from "./RTNCFSKZ-P4icqVD0.js";
var Q = et(
[Ke],
[_e]
);
Q.useContext;
Q.useScopedContext;
var Se = Q.useProviderContext, so = Q.ContextProvider, Ct = Q.ScopedContextProvider;
function me(t) {
return [t.clientX, t.clientY];
}
function Ce(t, r) {
const [o, e] = t;
let n = !1;
const s = r.length;
for (let a = s, l = 0, u = a - 1; l < a; u = l++) {
const [i, c] = r[l], [x, p] = r[u], [, S] = r[u === 0 ? a - 1 : u - 1] || [0, 0], m = (c - p) * (o - i) - (i - x) * (e - c);
if (p < c) {
if (e >= p && e < c) {
if (m === 0) return !0;
m > 0 && (e === p ? e > S && (n = !n) : n = !n);
}
} else if (c < p) {
if (e > c && e <= p) {
if (m === 0) return !0;
m < 0 && (e === p ? e < S && (n = !n) : n = !n);
}
} else if (e === c && (o >= x && o <= i || o >= i && o <= x))
return !0;
}
return n;
}
function Ht(t, r) {
const { top: o, right: e, bottom: n, left: s } = r, [a, l] = t, u = a < s ? "left" : a > e ? "right" : null, i = l < o ? "top" : l > n ? "bottom" : null;
return [u, i];
}
function He(t, r) {
const o = t.getBoundingClientRect(), { top: e, right: n, bottom: s, left: a } = o, [l, u] = Ht(r, o), i = [r];
return l ? (u !== "top" && i.push([l === "left" ? a : n, e]), i.push([l === "left" ? n : a, e]), i.push([l === "left" ? n : a, s]), u !== "bottom" && i.push([l === "left" ? a : n, s])) : u === "top" ? (i.push([a, e]), i.push([a, s]), i.push([n, s]), i.push([n, e])) : (i.push([a, s]), i.push([a, e]), i.push([n, e]), i.push([n, s])), i;
}
var $t = "div";
function $e(t = 0, r = 0, o = 0, e = 0) {
if (typeof DOMRect == "function")
return new DOMRect(t, r, o, e);
const n = {
x: t,
y: r,
width: o,
height: e,
top: r,
right: t + o,
bottom: r + e,
left: t
};
return R(E({}, n), { toJSON: () => n });
}
function Mt(t) {
if (!t) return $e();
const { x: r, y: o, width: e, height: n } = t;
return $e(r, o, e, n);
}
function Rt(t, r) {
return {
contextElement: t || void 0,
getBoundingClientRect: () => {
const e = t, n = r == null ? void 0 : r(e);
return n || !e ? Mt(n) : e.getBoundingClientRect();
}
};
}
function Ft(t) {
return /^(?:top|bottom|left|right)(?:-(?:start|end))?$/.test(t);
}
function Me(t) {
const r = window.devicePixelRatio || 1;
return Math.round(t * r) / r;
}
function _t(t, r) {
return mt(({ placement: o }) => {
var e;
const n = ((t == null ? void 0 : t.clientHeight) || 0) / 2, s = typeof r.gutter == "number" ? r.gutter + n : (e = r.gutter) != null ? e : n;
return {
crossAxis: !!o.split("-")[1] ? void 0 : r.shift,
mainAxis: s,
alignmentAxis: r.shift
};
});
}
function Tt(t) {
if (t.flip === !1) return;
const r = typeof t.flip == "string" ? t.flip.split(" ") : void 0;
return K(
!r || r.every(Ft),
process.env.NODE_ENV !== "production" && "`flip` expects a spaced-delimited list of placements"
), vt({
padding: t.overflowPadding,
fallbackPlacements: r
});
}
function kt(t) {
if (!(!t.slide && !t.overlap))
return ht({
mainAxis: t.slide,
crossAxis: t.overlap,
padding: t.overflowPadding,
limiter: wt()
});
}
function Dt(t) {
return gt({
padding: t.overflowPadding,
apply({ elements: r, availableWidth: o, availableHeight: e, rects: n }) {
const s = r.floating, a = Math.round(n.reference.width);
o = Math.floor(o), e = Math.floor(e), s.style.setProperty(
"--popover-anchor-width",
`${a}px`
), s.style.setProperty(
"--popover-available-width",
`${o}px`
), s.style.setProperty(
"--popover-available-height",
`${e}px`
), t.sameWidth && (s.style.width = `${a}px`), t.fitViewport && (s.style.maxWidth = `${o}px`, s.style.maxHeight = `${e}px`);
}
});
}
function Nt(t, r) {
if (t)
return Pt({
element: t,
padding: r.arrowPadding
});
}
var je = ue(
function(r) {
var o = r, {
store: e,
modal: n = !1,
portal: s = !!n,
preserveTabOrder: a = !0,
autoFocusOnShow: l = !0,
wrapperProps: u,
fixed: i = !1,
flip: c = !0,
shift: x = 0,
slide: p = !0,
overlap: S = !1,
sameWidth: m = !1,
fitViewport: b = !1,
gutter: w,
arrowPadding: f = 4,
overflowPadding: v = 8,
getAnchorRect: C,
updatePosition: F
} = o, h = J(o, [
"store",
"modal",
"portal",
"preserveTabOrder",
"autoFocusOnShow",
"wrapperProps",
"fixed",
"flip",
"shift",
"slide",
"overlap",
"sameWidth",
"fitViewport",
"gutter",
"arrowPadding",
"overflowPadding",
"getAnchorRect",
"updatePosition"
]);
const W = Te();
e = e || W, K(
e,
process.env.NODE_ENV !== "production" && "Popover must receive a `store` prop or be wrapped in a PopoverProvider component."
);
const N = e.useState("arrowElement"), y = e.useState("anchorElement"), fe = e.useState("disclosureElement"), P = e.useState("popoverElement"), V = e.useState("contentElement"), ee = e.useState("placement"), d = e.useState("mounted"), O = e.useState("rendered"), g = X(null), [H, _] = de(!1), { portalRef: pe, domReady: z } = ke(s, h.portalRef), j = Z(C), B = Z(F), Y = !!F;
ae(() => {
if (!(P != null && P.isConnected)) return;
P.style.setProperty(
"--popover-overflow-padding",
`${v}px`
);
const $ = Rt(y, j), G = async () => {
if (!d) return;
N || (g.current = g.current || document.createElement("div"));
const I = N || g.current, qe = [
_t(I, { gutter: w, shift: x }),
Tt({ flip: c, overflowPadding: v }),
kt({ slide: p, overlap: S, overflowPadding: v }),
Nt(I, { arrowPadding: f }),
Dt({
sameWidth: m,
fitViewport: b,
overflowPadding: v
})
], L = await pt($, P, {
placement: ee,
strategy: i ? "fixed" : "absolute",
middleware: qe
});
e == null || e.setState("currentPlacement", L.placement), _(!0);
const Xe = Me(L.x), Ye = Me(L.y);
if (Object.assign(P.style, {
top: "0",
left: "0",
transform: `translate3d(${Xe}px,${Ye}px,0)`
}), I && L.middlewareData.arrow) {
const { x: oe, y: re } = L.middlewareData.arrow, Ee = L.placement.split("-")[0], ne = I.clientWidth / 2, se = I.clientHeight / 2, be = oe != null ? oe + ne : -ne, ye = re != null ? re + se : -se;
P.style.setProperty(
"--popover-transform-origin",
{
top: `${be}px calc(100% + ${se}px)`,
bottom: `${be}px ${-se}px`,
left: `calc(100% + ${ne}px) ${ye}px`,
right: `${-ne}px ${ye}px`
}[Ee]
), Object.assign(I.style, {
left: oe != null ? `${oe}px` : "",
top: re != null ? `${re}px` : "",
[Ee]: "100%"
});
}
}, Ue = ft($, P, async () => {
Y ? (await B({ updatePosition: G }), _(!0)) : await G();
}, {
// JSDOM doesn't support ResizeObserver
elementResize: typeof ResizeObserver == "function"
});
return () => {
_(!1), Ue();
};
}, [
e,
O,
P,
N,
y,
P,
ee,
d,
z,
i,
c,
x,
p,
S,
m,
b,
w,
f,
v,
j,
Y,
B
]), ae(() => {
if (!d || !z || !(P != null && P.isConnected) || !(V != null && V.isConnected)) return;
const $ = () => {
P.style.zIndex = getComputedStyle(V).zIndex;
};
$();
let G = requestAnimationFrame(() => {
G = requestAnimationFrame($);
});
return () => cancelAnimationFrame(G);
}, [d, z, P, V]);
const te = i ? "fixed" : "absolute";
return h = he(
h,
($) => /* @__PURE__ */ A(
"div",
R(E({}, u), {
style: E({
// https://floating-ui.com/docs/computeposition#initial-layout
position: te,
top: 0,
left: 0,
width: "max-content"
}, u == null ? void 0 : u.style),
ref: e == null ? void 0 : e.setPopoverElement,
children: $
})
),
[e, te, u]
), h = he(
h,
($) => /* @__PURE__ */ A(_e, { value: e, children: $ }),
[e]
), h = R(E({
// data-placing is not part of the public API. We're setting this here so
// we can wait for the popover to be positioned before other components
// move focus into it. For example, this attribute is observed by the
// Combobox component with the autoSelect behavior.
"data-placing": !H || void 0
}, h), {
style: E({
position: "relative"
}, h.style)
}), h = Ge(R(E({
store: e,
modal: n,
portal: s,
preserveTabOrder: a,
preserveTabOrderAnchor: fe || y,
autoFocusOnShow: H && l
}, h), {
portalRef: pe
})), h;
}
), io = Fe(
ce(function(r) {
const o = je(r);
return le($t, o);
}),
Te
), Vt = "div";
function Be(t, r, o, e) {
return rt(r) ? !0 : t ? !!(ge(r, t) || o && ge(o, t) || e != null && e.some((n) => Be(t, n, o))) : !1;
}
function Wt(t) {
var r = t, {
store: o
} = r, e = J(r, [
"store"
]);
const [n, s] = de(!1), a = o.useState("mounted");
D(() => {
a || s(!1);
}, [a]);
const l = e.onFocus, u = Z((c) => {
l == null || l(c), !c.defaultPrevented && s(!0);
}), i = X(null);
return D(() => bt(o, ["anchorElement"], (c) => {
i.current = c.anchorElement;
}), []), e = R(E({
autoFocusOnHide: n,
finalFocus: i
}, e), {
onFocus: u
}), e;
}
var Re = St(null), zt = ue(
function(r) {
var o = r, {
store: e,
modal: n = !1,
portal: s = !!n,
hideOnEscape: a = !0,
hideOnHoverOutside: l = !0,
disablePointerEventsOnApproach: u = !!l
} = o, i = J(o, [
"store",
"modal",
"portal",
"hideOnEscape",
"hideOnHoverOutside",
"disablePointerEventsOnApproach"
]);
const c = Se();
e = e || c, K(
e,
process.env.NODE_ENV !== "production" && "Hovercard must receive a `store` prop or be wrapped in a HovercardProvider component."
);
const x = X(null), [p, S] = de([]), m = X(0), b = X(null), { portalRef: w, domReady: f } = ke(s, i.portalRef), v = De(), C = !!l, F = Pe(l), h = !!u, W = Pe(
u
), N = e.useState("open"), y = e.useState("mounted");
D(() => {
if (!f || !y || !C && !h) return;
const d = x.current;
return d ? Oe(
U("mousemove", (g) => {
if (!e || !v()) return;
const { anchorElement: H, hideTimeout: _, timeout: pe } = e.getState(), z = b.current, [j] = g.composedPath(), B = H;
if (Be(j, d, B, p)) {
b.current = j && B && ge(B, j) ? me(g) : null, window.clearTimeout(m.current), m.current = 0;
return;
}
if (!m.current) {
if (z) {
const Y = me(g), te = He(d, z);
if (Ce(Y, te)) {
if (b.current = Y, !W(g)) return;
g.preventDefault(), g.stopPropagation();
return;
}
}
F(g) && (m.current = window.setTimeout(() => {
m.current = 0, e == null || e.hide();
}, _ ?? pe));
}
}, !0),
() => clearTimeout(m.current)
) : void 0;
}, [
e,
v,
f,
y,
C,
h,
p,
W,
F
]), D(() => {
if (!f || !y || !h) return;
const d = (O) => {
const g = x.current;
if (!g) return;
const H = b.current;
if (!H) return;
const _ = He(g, H);
if (Ce(me(O), _)) {
if (!W(O)) return;
O.preventDefault(), O.stopPropagation();
}
};
return Oe(
// Note: we may need to add pointer events here in the future.
U("mouseenter", d, !0),
U("mouseover", d, !0),
U("mouseout", d, !0),
U("mouseleave", d, !0)
);
}, [f, y, h, W]), D(() => {
f && (N || e == null || e.setAutoFocusOnShow(!1));
}, [e, f, N]);
const fe = tt(N);
D(() => {
if (f)
return () => {
fe.current || e == null || e.setAutoFocusOnShow(!1);
};
}, [e, f]);
const P = xt(Re);
ae(() => {
if (n || !s || !y || !f) return;
const d = x.current;
if (d)
return P == null ? void 0 : P(d);
}, [n, s, y, f]);
const V = Ne(
(d) => {
S((g) => [...g, d]);
const O = P == null ? void 0 : P(d);
return () => {
S(
(g) => g.filter((H) => H !== d)
), O == null || O();
};
},
[P]
);
i = he(
i,
(d) => /* @__PURE__ */ A(Ct, { value: e, children: /* @__PURE__ */ A(Re.Provider, { value: V, children: d }) }),
[e, V]
), i = R(E({}, i), {
ref: xe(x, i.ref)
}), i = Wt(E({ store: e }, i));
const ee = e.useState(
(d) => n || d.autoFocusOnShow
);
return i = je(R(E({
store: e,
modal: n,
portal: s,
autoFocusOnShow: ee
}, i), {
portalRef: w,
hideOnEscape(d) {
return ot(a, d) ? !1 : (requestAnimationFrame(() => {
requestAnimationFrame(() => {
e == null || e.hide();
});
}), !0);
}
})), i;
}
), ao = Fe(
ce(function(r) {
const o = zt(r);
return le(Vt, o);
}),
Se
), jt = "a", Bt = ue(
function(r) {
var o = r, { store: e, showOnHover: n = !0 } = o, s = J(o, ["store", "showOnHover"]);
const a = Se();
e = e || a, K(
e,
process.env.NODE_ENV !== "production" && "HovercardAnchor must receive a `store` prop or be wrapped in a HovercardProvider component."
);
const l = nt(s), u = X(0);
D(() => () => window.clearTimeout(u.current), []), D(() => U("mouseleave", (f) => {
if (!e) return;
const { anchorElement: v } = e.getState();
v && f.target === v && (window.clearTimeout(u.current), u.current = 0);
}, !0), [e]);
const i = s.onMouseMove, c = Pe(n), x = De(), p = Z((w) => {
if (i == null || i(w), l || !e || w.defaultPrevented || u.current || !x() || !c(w)) return;
const f = w.currentTarget;
e.setAnchorElement(f), e.setDisclosureElement(f);
const { showTimeout: v, timeout: C } = e.getState(), F = () => {
u.current = 0, x() && (e == null || e.setAnchorElement(f), e == null || e.show(), queueMicrotask(() => {
e == null || e.setDisclosureElement(f);
}));
}, h = v ?? C;
h === 0 ? F() : u.current = window.setTimeout(F, h);
}), S = s.onClick, m = Z((w) => {
S == null || S(w), e && (window.clearTimeout(u.current), u.current = 0);
}), b = Ne(
(w) => {
if (!e) return;
const { anchorElement: f } = e.getState();
f != null && f.isConnected || e.setAnchorElement(w);
},
[e]
);
return s = R(E({}, s), {
ref: xe(b, s.ref),
onMouseMove: p,
onClick: m
}), s = st(s), s;
}
), uo = ce(function(r) {
const o = Bt(r);
return le(jt, o);
}), ve = "M23 27.8C24.1 29 26.4 30 28 30H30H0H2C3.7 30 5.9 29 7 27.8L14 20.6C14.7 19.8 15.3 19.8 16 20.6L23 27.8Z", It = "div", we = 30, T = we / 2, Lt = {
top: `rotate(180 ${T} ${T})`,
right: `rotate(-90 ${T} ${T})`,
bottom: `rotate(0 ${T} ${T})`,
left: `rotate(90 ${T} ${T})`
};
function Ut(t) {
const [r, o] = de(), e = Ve(t, "contentElement");
return ae(() => {
if (!e) return;
const s = ut(e).getComputedStyle(e);
o(s);
}, [e]), r;
}
function qt(t) {
var r;
return t ? (r = t.getPropertyValue("box-shadow").match(/0px 0px 0px ([^0]+px)/)) == null ? void 0 : r[1] : void 0;
}
function Xt(t, r) {
if (!r) return;
const o = r.getPropertyValue(`border-${t}-color`);
if (o) return o;
const n = r.getPropertyValue("box-shadow").match(/0px 0px 0px [^,]+/);
return n && n[0].replace(/^0px 0px 0px\s+[^\s,]+/, "").trim() || void 0;
}
var Yt = ue(
function(r) {
var o = r, {
store: e,
size: n = we,
borderWidth: s
} = o, a = J(o, [
"store",
"size",
"borderWidth"
]);
const l = Qe();
e = e || l, K(
e,
process.env.NODE_ENV !== "production" && "PopoverArrow must be wrapped in a Popover component."
);
const u = Ve(
e,
(v) => v.currentPlacement.split("-")[0]
), i = it(), c = Ut(e), x = Xt(u, c) || "none", p = (c == null ? void 0 : c.getPropertyValue("background-color")) || "none", [S, m] = Ae(() => {
if (s != null) return [s, !1];
if (!c) return [0, !1];
const v = qt(c);
if (v) return [Number.parseInt(v, 10), !0];
const C = c.getPropertyValue(`border-${u}-width`);
return C ? [Math.ceil(Number.parseFloat(C)), !1] : [0, !1];
}, [s, c, u]), b = S * 2 * (we / n), w = Lt[u], f = Ae(
() => /* @__PURE__ */ A("svg", { display: "block", viewBox: "0 0 30 30", children: /* @__PURE__ */ Et("g", { transform: w, children: [
!m && // When using the CSS border property, set the fill color to match
// the background behind the stroke so transparent strokes match
// the appearance of borders on HTML elements.
/* @__PURE__ */ A(
"path",
{
fill: "none",
stroke: `var(--ak-layer, ${p})`,
d: ve,
mask: `url(#${i})`
}
),
/* @__PURE__ */ A("path", { fill: "none", d: ve, mask: `url(#${i})` }),
/* @__PURE__ */ A("path", { stroke: "none", d: ve }),
/* @__PURE__ */ A("mask", { id: i, maskUnits: "userSpaceOnUse", children: /* @__PURE__ */ A(
"rect",
{
x: "-15",
y: "0",
width: "60",
height: "30",
fill: "white",
stroke: "black"
}
) })
] }) }),
[w, m, p, i]
);
return a = R(E({
children: f,
"aria-hidden": !0
}, a), {
ref: xe(e.setArrowElement, a.ref),
style: E({
position: "absolute",
fontSize: n,
width: "1em",
height: "1em",
pointerEvents: "none",
fill: `var(--ak-layer, ${p})`,
stroke: `var(--ak-layer-border, ${x})`,
strokeWidth: b
}, a.style)
}), at(a);
}
), co = ct(
ce(function(r) {
const o = Yt(r);
return le(It, o);
})
);
function Ie(t = {}) {
var r = t, {
popover: o
} = r, e = lt(r, [
"popover"
]);
const n = yt(
e.store,
Ot(o, [
"arrowElement",
"anchorElement",
"contentElement",
"popoverElement",
"disclosureElement"
])
);
At(e, n);
const s = n == null ? void 0 : n.getState(), a = Ze(q(k({}, e), { store: n })), l = M(
e.placement,
s == null ? void 0 : s.placement,
"bottom"
), u = q(k({}, a.getState()), {
placement: l,
currentPlacement: l,
anchorElement: M(s == null ? void 0 : s.anchorElement, null),
popoverElement: M(s == null ? void 0 : s.popoverElement, null),
arrowElement: M(s == null ? void 0 : s.arrowElement, null),
rendered: Symbol("rendered")
}), i = We(u, a, n);
return q(k(k({}, a), i), {
setAnchorElement: (c) => i.setState("anchorElement", c),
setPopoverElement: (c) => i.setState("popoverElement", c),
setArrowElement: (c) => i.setState("arrowElement", c),
render: () => i.setState("rendered", Symbol("rendered"))
});
}
function Le(t, r, o) {
return dt(r, [o.popover]), ie(t, o, "placement"), Je(t, r, o);
}
function lo(t = {}) {
const [r, o] = ze(Ie, t);
return Le(r, o, t);
}
function Gt(t = {}) {
var r;
const o = (r = t.store) == null ? void 0 : r.getState(), e = Ie(q(k({}, t), {
placement: M(
t.placement,
o == null ? void 0 : o.placement,
"bottom"
)
})), n = M(t.timeout, o == null ? void 0 : o.timeout, 500), s = q(k({}, e.getState()), {
timeout: n,
showTimeout: M(t.showTimeout, o == null ? void 0 : o.showTimeout),
hideTimeout: M(t.hideTimeout, o == null ? void 0 : o.hideTimeout),
autoFocusOnShow: M(o == null ? void 0 : o.autoFocusOnShow, !1)
}), a = We(s, e, t.store);
return q(k(k({}, e), a), {
setAutoFocusOnShow: (l) => a.setState("autoFocusOnShow", l)
});
}
function Zt(t, r, o) {
return ie(t, o, "timeout"), ie(t, o, "showTimeout"), ie(t, o, "hideTimeout"), Le(t, r, o);
}
function fo(t = {}) {
const [r, o] = ze(Gt, t);
return Zt(r, o, t);
}
export {
Ct as H,
co as P,
so as a,
Yt as b,
Bt as c,
Gt as d,
Zt as e,
uo as f,
ao as g,
lo as h,
fo as i,
io as j,
zt as u
};