@hoosei/voxweave-react
Version:
A customizable and interactive voice UI component for React applications
844 lines (843 loc) • 30.3 kB
JavaScript
import * as t from "react";
import * as be from "react-dom";
import { clamp as Re } from "./index75.js";
import { composeEventHandlers as R } from "./index27.js";
import { createCollection as Je } from "./index76.js";
import { useComposedRefs as k } from "./index24.js";
import { createContextScope as Qe } from "./index28.js";
import { useDirection as et } from "./index77.js";
import { DismissableLayer as tt } from "./index31.js";
import { useFocusGuards as ot } from "./index36.js";
import { FocusScope as nt } from "./index32.js";
import { useId as Ie } from "./index29.js";
import { createPopperScope as _e, Root as rt, Anchor as ct, Content as st, Arrow as lt } from "./index78.js";
import { Portal as it } from "./index33.js";
import { Primitive as M } from "./index35.js";
import { createSlot as at } from "./index21.js";
import { useCallbackRef as dt } from "./index40.js";
import { useControllableState as Ee } from "./index30.js";
import { useLayoutEffect as Y } from "./index39.js";
import { usePrevious as ut } from "./index79.js";
import { VISUALLY_HIDDEN_STYLES as pt } from "./index80.js";
import { hideOthers as ft } from "./index38.js";
import mt from "./index37.js";
import { jsx as p, jsxs as le, Fragment as Te } from "react/jsx-runtime";
var ht = [" ", "Enter", "ArrowUp", "ArrowDown"], vt = [" ", "Enter"], J = "Select", [ae, de, gt] = Je(J), [te, uo] = Qe(J, [
gt,
_e
]), ue = _e(), [St, j] = te(J), [wt, Ct] = te(J), Ne = (o) => {
const {
__scopeSelect: l,
children: e,
open: i,
defaultOpen: c,
onOpenChange: d,
value: n,
defaultValue: r,
onValueChange: s,
dir: f,
name: g,
autoComplete: C,
disabled: E,
required: T,
form: y
} = o, a = ue(l), [h, S] = t.useState(null), [m, v] = t.useState(null), [U, A] = t.useState(!1), oe = et(f), [b, D] = Ee({
prop: i,
defaultProp: c ?? !1,
onChange: d,
caller: J
}), [K, X] = Ee({
prop: n,
defaultProp: r,
onChange: s,
caller: J
}), B = t.useRef(null), V = h ? y || !!h.closest("form") : !0, [G, H] = t.useState(/* @__PURE__ */ new Set()), W = Array.from(G).map((_) => _.props.value).join(";");
return /* @__PURE__ */ p(rt, { ...a, children: /* @__PURE__ */ le(
St,
{
required: T,
scope: l,
trigger: h,
onTriggerChange: S,
valueNode: m,
onValueNodeChange: v,
valueNodeHasChildren: U,
onValueNodeHasChildrenChange: A,
contentId: Ie(),
value: K,
onValueChange: X,
open: b,
onOpenChange: D,
dir: oe,
triggerPointerDownPosRef: B,
disabled: E,
children: [
/* @__PURE__ */ p(ae.Provider, { scope: l, children: /* @__PURE__ */ p(
wt,
{
scope: o.__scopeSelect,
onNativeOptionAdd: t.useCallback((_) => {
H((L) => new Set(L).add(_));
}, []),
onNativeOptionRemove: t.useCallback((_) => {
H((L) => {
const F = new Set(L);
return F.delete(_), F;
});
}, []),
children: e
}
) }),
V ? /* @__PURE__ */ le(
qe,
{
"aria-hidden": !0,
required: T,
tabIndex: -1,
name: g,
autoComplete: C,
value: K,
onChange: (_) => X(_.target.value),
disabled: E,
form: y,
children: [
K === void 0 ? /* @__PURE__ */ p("option", { value: "" }) : null,
Array.from(G)
]
},
W
) : null
]
}
) });
};
Ne.displayName = J;
var Me = "SelectTrigger", Ae = t.forwardRef(
(o, l) => {
const { __scopeSelect: e, disabled: i = !1, ...c } = o, d = ue(e), n = j(Me, e), r = n.disabled || i, s = k(l, n.onTriggerChange), f = de(e), g = t.useRef("touch"), [C, E, T] = Ze((a) => {
const h = f().filter((v) => !v.disabled), S = h.find((v) => v.value === n.value), m = $e(h, a, S);
m !== void 0 && n.onValueChange(m.value);
}), y = (a) => {
r || (n.onOpenChange(!0), T()), a && (n.triggerPointerDownPosRef.current = {
x: Math.round(a.pageX),
y: Math.round(a.pageY)
});
};
return /* @__PURE__ */ p(ct, { asChild: !0, ...d, children: /* @__PURE__ */ p(
M.button,
{
type: "button",
role: "combobox",
"aria-controls": n.contentId,
"aria-expanded": n.open,
"aria-required": n.required,
"aria-autocomplete": "none",
dir: n.dir,
"data-state": n.open ? "open" : "closed",
disabled: r,
"data-disabled": r ? "" : void 0,
"data-placeholder": Xe(n.value) ? "" : void 0,
...c,
ref: s,
onClick: R(c.onClick, (a) => {
a.currentTarget.focus(), g.current !== "mouse" && y(a);
}),
onPointerDown: R(c.onPointerDown, (a) => {
g.current = a.pointerType;
const h = a.target;
h.hasPointerCapture(a.pointerId) && h.releasePointerCapture(a.pointerId), a.button === 0 && a.ctrlKey === !1 && a.pointerType === "mouse" && (y(a), a.preventDefault());
}),
onKeyDown: R(c.onKeyDown, (a) => {
const h = C.current !== "";
!(a.ctrlKey || a.altKey || a.metaKey) && a.key.length === 1 && E(a.key), !(h && a.key === " ") && ht.includes(a.key) && (y(), a.preventDefault());
})
}
) });
}
);
Ae.displayName = Me;
var Oe = "SelectValue", xt = t.forwardRef(
(o, l) => {
const { __scopeSelect: e, className: i, style: c, children: d, placeholder: n = "", ...r } = o, s = j(Oe, e), { onValueNodeHasChildrenChange: f } = s, g = d !== void 0, C = k(l, s.onValueNodeChange);
return Y(() => {
f(g);
}, [f, g]), /* @__PURE__ */ p(
M.span,
{
...r,
ref: C,
style: { pointerEvents: "none" },
children: Xe(s.value) ? /* @__PURE__ */ p(Te, { children: n }) : d
}
);
}
);
xt.displayName = Oe;
var yt = "SelectIcon", It = t.forwardRef(
(o, l) => {
const { __scopeSelect: e, children: i, ...c } = o;
return /* @__PURE__ */ p(M.span, { "aria-hidden": !0, ...c, ref: l, children: i || "▼" });
}
);
It.displayName = yt;
var Tt = "SelectPortal", De = (o) => /* @__PURE__ */ p(it, { asChild: !0, ...o });
De.displayName = Tt;
var Q = "SelectContent", Le = t.forwardRef(
(o, l) => {
const e = j(Q, o.__scopeSelect), [i, c] = t.useState();
if (Y(() => {
c(new DocumentFragment());
}, []), !e.open) {
const d = i;
return d ? be.createPortal(
/* @__PURE__ */ p(ke, { scope: o.__scopeSelect, children: /* @__PURE__ */ p(ae.Slot, { scope: o.__scopeSelect, children: /* @__PURE__ */ p("div", { children: o.children }) }) }),
d
) : null;
}
return /* @__PURE__ */ p(Be, { ...o, ref: l });
}
);
Le.displayName = Q;
var O = 10, [ke, q] = te(Q), Pt = "SelectContentImpl", Rt = at("SelectContent.RemoveScroll"), Be = t.forwardRef(
(o, l) => {
const {
__scopeSelect: e,
position: i = "item-aligned",
onCloseAutoFocus: c,
onEscapeKeyDown: d,
onPointerDownOutside: n,
//
// PopperContent props
side: r,
sideOffset: s,
align: f,
alignOffset: g,
arrowPadding: C,
collisionBoundary: E,
collisionPadding: T,
sticky: y,
hideWhenDetached: a,
avoidCollisions: h,
//
...S
} = o, m = j(Q, e), [v, U] = t.useState(null), [A, oe] = t.useState(null), b = k(l, (u) => U(u)), [D, K] = t.useState(null), [X, B] = t.useState(
null
), V = de(e), [G, H] = t.useState(!1), W = t.useRef(!1);
t.useEffect(() => {
if (v) return ft(v);
}, [v]), ot();
const _ = t.useCallback(
(u) => {
const [I, ...N] = V().map((P) => P.ref.current), [w] = N.slice(-1), x = document.activeElement;
for (const P of u)
if (P === x || (P?.scrollIntoView({ block: "nearest" }), P === I && A && (A.scrollTop = 0), P === w && A && (A.scrollTop = A.scrollHeight), P?.focus(), document.activeElement !== x)) return;
},
[V, A]
), L = t.useCallback(
() => _([D, v]),
[_, D, v]
);
t.useEffect(() => {
G && L();
}, [G, L]);
const { onOpenChange: F, triggerPointerDownPosRef: z } = m;
t.useEffect(() => {
if (v) {
let u = { x: 0, y: 0 };
const I = (w) => {
u = {
x: Math.abs(Math.round(w.pageX) - (z.current?.x ?? 0)),
y: Math.abs(Math.round(w.pageY) - (z.current?.y ?? 0))
};
}, N = (w) => {
u.x <= 10 && u.y <= 10 ? w.preventDefault() : v.contains(w.target) || F(!1), document.removeEventListener("pointermove", I), z.current = null;
};
return z.current !== null && (document.addEventListener("pointermove", I), document.addEventListener("pointerup", N, { capture: !0, once: !0 })), () => {
document.removeEventListener("pointermove", I), document.removeEventListener("pointerup", N, { capture: !0 });
};
}
}, [v, F, z]), t.useEffect(() => {
const u = () => F(!1);
return window.addEventListener("blur", u), window.addEventListener("resize", u), () => {
window.removeEventListener("blur", u), window.removeEventListener("resize", u);
};
}, [F]);
const [pe, ce] = Ze((u) => {
const I = V().filter((x) => !x.disabled), N = I.find((x) => x.ref.current === document.activeElement), w = $e(I, u, N);
w && setTimeout(() => w.ref.current.focus());
}), fe = t.useCallback(
(u, I, N) => {
const w = !W.current && !N;
(m.value !== void 0 && m.value === I || w) && (K(u), w && (W.current = !0));
},
[m.value]
), me = t.useCallback(() => v?.focus(), [v]), ee = t.useCallback(
(u, I, N) => {
const w = !W.current && !N;
(m.value !== void 0 && m.value === I || w) && B(u);
},
[m.value]
), se = i === "popper" ? Se : Ve, ne = se === Se ? {
side: r,
sideOffset: s,
align: f,
alignOffset: g,
arrowPadding: C,
collisionBoundary: E,
collisionPadding: T,
sticky: y,
hideWhenDetached: a,
avoidCollisions: h
} : {};
return /* @__PURE__ */ p(
ke,
{
scope: e,
content: v,
viewport: A,
onViewportChange: oe,
itemRefCallback: fe,
selectedItem: D,
onItemLeave: me,
itemTextRefCallback: ee,
focusSelectedItem: L,
selectedItemText: X,
position: i,
isPositioned: G,
searchRef: pe,
children: /* @__PURE__ */ p(mt, { as: Rt, allowPinchZoom: !0, children: /* @__PURE__ */ p(
nt,
{
asChild: !0,
trapped: m.open,
onMountAutoFocus: (u) => {
u.preventDefault();
},
onUnmountAutoFocus: R(c, (u) => {
m.trigger?.focus({ preventScroll: !0 }), u.preventDefault();
}),
children: /* @__PURE__ */ p(
tt,
{
asChild: !0,
disableOutsidePointerEvents: !0,
onEscapeKeyDown: d,
onPointerDownOutside: n,
onFocusOutside: (u) => u.preventDefault(),
onDismiss: () => m.onOpenChange(!1),
children: /* @__PURE__ */ p(
se,
{
role: "listbox",
id: m.contentId,
"data-state": m.open ? "open" : "closed",
dir: m.dir,
onContextMenu: (u) => u.preventDefault(),
...S,
...ne,
onPlaced: () => H(!0),
ref: b,
style: {
// flex layout so we can place the scroll buttons properly
display: "flex",
flexDirection: "column",
// reset the outline by default as the content MAY get focused
outline: "none",
...S.style
},
onKeyDown: R(S.onKeyDown, (u) => {
const I = u.ctrlKey || u.altKey || u.metaKey;
if (u.key === "Tab" && u.preventDefault(), !I && u.key.length === 1 && ce(u.key), ["ArrowUp", "ArrowDown", "Home", "End"].includes(u.key)) {
let w = V().filter((x) => !x.disabled).map((x) => x.ref.current);
if (["ArrowUp", "End"].includes(u.key) && (w = w.slice().reverse()), ["ArrowUp", "ArrowDown"].includes(u.key)) {
const x = u.target, P = w.indexOf(x);
w = w.slice(P + 1);
}
setTimeout(() => _(w)), u.preventDefault();
}
})
}
)
}
)
}
) })
}
);
}
);
Be.displayName = Pt;
var Et = "SelectItemAlignedPosition", Ve = t.forwardRef((o, l) => {
const { __scopeSelect: e, onPlaced: i, ...c } = o, d = j(Q, e), n = q(Q, e), [r, s] = t.useState(null), [f, g] = t.useState(null), C = k(l, (b) => g(b)), E = de(e), T = t.useRef(!1), y = t.useRef(!0), { viewport: a, selectedItem: h, selectedItemText: S, focusSelectedItem: m } = n, v = t.useCallback(() => {
if (d.trigger && d.valueNode && r && f && a && h && S) {
const b = d.trigger.getBoundingClientRect(), D = f.getBoundingClientRect(), K = d.valueNode.getBoundingClientRect(), X = S.getBoundingClientRect();
if (d.dir !== "rtl") {
const x = X.left - D.left, P = K.left - x, Z = b.left - P, $ = b.width + Z, he = Math.max($, D.width), ve = window.innerWidth - O, ge = Re(P, [
O,
// Prevents the content from going off the starting edge of the
// viewport. It may still go off the ending edge, but this can be
// controlled by the user since they may want to manage overflow in a
// specific way.
// https://github.com/radix-ui/primitives/issues/2049
Math.max(O, ve - he)
]);
r.style.minWidth = $ + "px", r.style.left = ge + "px";
} else {
const x = D.right - X.right, P = window.innerWidth - K.right - x, Z = window.innerWidth - b.right - P, $ = b.width + Z, he = Math.max($, D.width), ve = window.innerWidth - O, ge = Re(P, [
O,
Math.max(O, ve - he)
]);
r.style.minWidth = $ + "px", r.style.right = ge + "px";
}
const B = E(), V = window.innerHeight - O * 2, G = a.scrollHeight, H = window.getComputedStyle(f), W = parseInt(H.borderTopWidth, 10), _ = parseInt(H.paddingTop, 10), L = parseInt(H.borderBottomWidth, 10), F = parseInt(H.paddingBottom, 10), z = W + _ + G + F + L, pe = Math.min(h.offsetHeight * 5, z), ce = window.getComputedStyle(a), fe = parseInt(ce.paddingTop, 10), me = parseInt(ce.paddingBottom, 10), ee = b.top + b.height / 2 - O, se = V - ee, ne = h.offsetHeight / 2, u = h.offsetTop + ne, I = W + _ + u, N = z - I;
if (I <= ee) {
const x = B.length > 0 && h === B[B.length - 1].ref.current;
r.style.bottom = "0px";
const P = f.clientHeight - a.offsetTop - a.offsetHeight, Z = Math.max(
se,
ne + // viewport might have padding bottom, include it to avoid a scrollable viewport
(x ? me : 0) + P + L
), $ = I + Z;
r.style.height = $ + "px";
} else {
const x = B.length > 0 && h === B[0].ref.current;
r.style.top = "0px";
const Z = Math.max(
ee,
W + a.offsetTop + // viewport might have padding top, include it to avoid a scrollable viewport
(x ? fe : 0) + ne
) + N;
r.style.height = Z + "px", a.scrollTop = I - ee + a.offsetTop;
}
r.style.margin = `${O}px 0`, r.style.minHeight = pe + "px", r.style.maxHeight = V + "px", i?.(), requestAnimationFrame(() => T.current = !0);
}
}, [
E,
d.trigger,
d.valueNode,
r,
f,
a,
h,
S,
d.dir,
i
]);
Y(() => v(), [v]);
const [U, A] = t.useState();
Y(() => {
f && A(window.getComputedStyle(f).zIndex);
}, [f]);
const oe = t.useCallback(
(b) => {
b && y.current === !0 && (v(), m?.(), y.current = !1);
},
[v, m]
);
return /* @__PURE__ */ p(
_t,
{
scope: e,
contentWrapper: r,
shouldExpandOnScrollRef: T,
onScrollButtonChange: oe,
children: /* @__PURE__ */ p(
"div",
{
ref: s,
style: {
display: "flex",
flexDirection: "column",
position: "fixed",
zIndex: U
},
children: /* @__PURE__ */ p(
M.div,
{
...c,
ref: C,
style: {
// When we get the height of the content, it includes borders. If we were to set
// the height without having `boxSizing: 'border-box'` it would be too big.
boxSizing: "border-box",
// We need to ensure the content doesn't get taller than the wrapper
maxHeight: "100%",
...c.style
}
}
)
}
)
}
);
});
Ve.displayName = Et;
var bt = "SelectPopperPosition", Se = t.forwardRef((o, l) => {
const {
__scopeSelect: e,
align: i = "start",
collisionPadding: c = O,
...d
} = o, n = ue(e);
return /* @__PURE__ */ p(
st,
{
...n,
...d,
ref: l,
align: i,
collisionPadding: c,
style: {
// Ensure border-box for floating-ui calculations
boxSizing: "border-box",
...d.style,
"--radix-select-content-transform-origin": "var(--radix-popper-transform-origin)",
"--radix-select-content-available-width": "var(--radix-popper-available-width)",
"--radix-select-content-available-height": "var(--radix-popper-available-height)",
"--radix-select-trigger-width": "var(--radix-popper-anchor-width)",
"--radix-select-trigger-height": "var(--radix-popper-anchor-height)"
}
}
);
});
Se.displayName = bt;
var [_t, Pe] = te(Q, {}), we = "SelectViewport", He = t.forwardRef(
(o, l) => {
const { __scopeSelect: e, nonce: i, ...c } = o, d = q(we, e), n = Pe(we, e), r = k(l, d.onViewportChange), s = t.useRef(0);
return /* @__PURE__ */ le(Te, { children: [
/* @__PURE__ */ p(
"style",
{
dangerouslySetInnerHTML: {
__html: "[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"
},
nonce: i
}
),
/* @__PURE__ */ p(ae.Slot, { scope: e, children: /* @__PURE__ */ p(
M.div,
{
"data-radix-select-viewport": "",
role: "presentation",
...c,
ref: r,
style: {
// we use position: 'relative' here on the `viewport` so that when we call
// `selectedItem.offsetTop` in calculations, the offset is relative to the viewport
// (independent of the scrollUpButton).
position: "relative",
flex: 1,
// Viewport should only be scrollable in the vertical direction.
// This won't work in vertical writing modes, so we'll need to
// revisit this if/when that is supported
// https://developer.chrome.com/blog/vertical-form-controls
overflow: "hidden auto",
...c.style
},
onScroll: R(c.onScroll, (f) => {
const g = f.currentTarget, { contentWrapper: C, shouldExpandOnScrollRef: E } = n;
if (E?.current && C) {
const T = Math.abs(s.current - g.scrollTop);
if (T > 0) {
const y = window.innerHeight - O * 2, a = parseFloat(C.style.minHeight), h = parseFloat(C.style.height), S = Math.max(a, h);
if (S < y) {
const m = S + T, v = Math.min(y, m), U = m - v;
C.style.height = v + "px", C.style.bottom === "0px" && (g.scrollTop = U > 0 ? U : 0, C.style.justifyContent = "flex-end");
}
}
}
s.current = g.scrollTop;
})
}
) })
] });
}
);
He.displayName = we;
var We = "SelectGroup", [Nt, Mt] = te(We), At = t.forwardRef(
(o, l) => {
const { __scopeSelect: e, ...i } = o, c = Ie();
return /* @__PURE__ */ p(Nt, { scope: e, id: c, children: /* @__PURE__ */ p(M.div, { role: "group", "aria-labelledby": c, ...i, ref: l }) });
}
);
At.displayName = We;
var Fe = "SelectLabel", Ot = t.forwardRef(
(o, l) => {
const { __scopeSelect: e, ...i } = o, c = Mt(Fe, e);
return /* @__PURE__ */ p(M.div, { id: c.id, ...i, ref: l });
}
);
Ot.displayName = Fe;
var ie = "SelectItem", [Dt, Ue] = te(ie), Ke = t.forwardRef(
(o, l) => {
const {
__scopeSelect: e,
value: i,
disabled: c = !1,
textValue: d,
...n
} = o, r = j(ie, e), s = q(ie, e), f = r.value === i, [g, C] = t.useState(d ?? ""), [E, T] = t.useState(!1), y = k(
l,
(m) => s.itemRefCallback?.(m, i, c)
), a = Ie(), h = t.useRef("touch"), S = () => {
c || (r.onValueChange(i), r.onOpenChange(!1));
};
if (i === "")
throw new Error(
"A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder."
);
return /* @__PURE__ */ p(
Dt,
{
scope: e,
value: i,
disabled: c,
textId: a,
isSelected: f,
onItemTextChange: t.useCallback((m) => {
C((v) => v || (m?.textContent ?? "").trim());
}, []),
children: /* @__PURE__ */ p(
ae.ItemSlot,
{
scope: e,
value: i,
disabled: c,
textValue: g,
children: /* @__PURE__ */ p(
M.div,
{
role: "option",
"aria-labelledby": a,
"data-highlighted": E ? "" : void 0,
"aria-selected": f && E,
"data-state": f ? "checked" : "unchecked",
"aria-disabled": c || void 0,
"data-disabled": c ? "" : void 0,
tabIndex: c ? void 0 : -1,
...n,
ref: y,
onFocus: R(n.onFocus, () => T(!0)),
onBlur: R(n.onBlur, () => T(!1)),
onClick: R(n.onClick, () => {
h.current !== "mouse" && S();
}),
onPointerUp: R(n.onPointerUp, () => {
h.current === "mouse" && S();
}),
onPointerDown: R(n.onPointerDown, (m) => {
h.current = m.pointerType;
}),
onPointerMove: R(n.onPointerMove, (m) => {
h.current = m.pointerType, c ? s.onItemLeave?.() : h.current === "mouse" && m.currentTarget.focus({ preventScroll: !0 });
}),
onPointerLeave: R(n.onPointerLeave, (m) => {
m.currentTarget === document.activeElement && s.onItemLeave?.();
}),
onKeyDown: R(n.onKeyDown, (m) => {
s.searchRef?.current !== "" && m.key === " " || (vt.includes(m.key) && S(), m.key === " " && m.preventDefault());
})
}
)
}
)
}
);
}
);
Ke.displayName = ie;
var re = "SelectItemText", Ge = t.forwardRef(
(o, l) => {
const { __scopeSelect: e, className: i, style: c, ...d } = o, n = j(re, e), r = q(re, e), s = Ue(re, e), f = Ct(re, e), [g, C] = t.useState(null), E = k(
l,
(S) => C(S),
s.onItemTextChange,
(S) => r.itemTextRefCallback?.(S, s.value, s.disabled)
), T = g?.textContent, y = t.useMemo(
() => /* @__PURE__ */ p("option", { value: s.value, disabled: s.disabled, children: T }, s.value),
[s.disabled, s.value, T]
), { onNativeOptionAdd: a, onNativeOptionRemove: h } = f;
return Y(() => (a(y), () => h(y)), [a, h, y]), /* @__PURE__ */ le(Te, { children: [
/* @__PURE__ */ p(M.span, { id: s.textId, ...d, ref: E }),
s.isSelected && n.valueNode && !n.valueNodeHasChildren ? be.createPortal(d.children, n.valueNode) : null
] });
}
);
Ge.displayName = re;
var ze = "SelectItemIndicator", Ye = t.forwardRef(
(o, l) => {
const { __scopeSelect: e, ...i } = o;
return Ue(ze, e).isSelected ? /* @__PURE__ */ p(M.span, { "aria-hidden": !0, ...i, ref: l }) : null;
}
);
Ye.displayName = ze;
var Ce = "SelectScrollUpButton", Lt = t.forwardRef((o, l) => {
const e = q(Ce, o.__scopeSelect), i = Pe(Ce, o.__scopeSelect), [c, d] = t.useState(!1), n = k(l, i.onScrollButtonChange);
return Y(() => {
if (e.viewport && e.isPositioned) {
let r = function() {
const f = s.scrollTop > 0;
d(f);
};
const s = e.viewport;
return r(), s.addEventListener("scroll", r), () => s.removeEventListener("scroll", r);
}
}, [e.viewport, e.isPositioned]), c ? /* @__PURE__ */ p(
je,
{
...o,
ref: n,
onAutoScroll: () => {
const { viewport: r, selectedItem: s } = e;
r && s && (r.scrollTop = r.scrollTop - s.offsetHeight);
}
}
) : null;
});
Lt.displayName = Ce;
var xe = "SelectScrollDownButton", kt = t.forwardRef((o, l) => {
const e = q(xe, o.__scopeSelect), i = Pe(xe, o.__scopeSelect), [c, d] = t.useState(!1), n = k(l, i.onScrollButtonChange);
return Y(() => {
if (e.viewport && e.isPositioned) {
let r = function() {
const f = s.scrollHeight - s.clientHeight, g = Math.ceil(s.scrollTop) < f;
d(g);
};
const s = e.viewport;
return r(), s.addEventListener("scroll", r), () => s.removeEventListener("scroll", r);
}
}, [e.viewport, e.isPositioned]), c ? /* @__PURE__ */ p(
je,
{
...o,
ref: n,
onAutoScroll: () => {
const { viewport: r, selectedItem: s } = e;
r && s && (r.scrollTop = r.scrollTop + s.offsetHeight);
}
}
) : null;
});
kt.displayName = xe;
var je = t.forwardRef((o, l) => {
const { __scopeSelect: e, onAutoScroll: i, ...c } = o, d = q("SelectScrollButton", e), n = t.useRef(null), r = de(e), s = t.useCallback(() => {
n.current !== null && (window.clearInterval(n.current), n.current = null);
}, []);
return t.useEffect(() => () => s(), [s]), Y(() => {
r().find((g) => g.ref.current === document.activeElement)?.ref.current?.scrollIntoView({ block: "nearest" });
}, [r]), /* @__PURE__ */ p(
M.div,
{
"aria-hidden": !0,
...c,
ref: l,
style: { flexShrink: 0, ...c.style },
onPointerDown: R(c.onPointerDown, () => {
n.current === null && (n.current = window.setInterval(i, 50));
}),
onPointerMove: R(c.onPointerMove, () => {
d.onItemLeave?.(), n.current === null && (n.current = window.setInterval(i, 50));
}),
onPointerLeave: R(c.onPointerLeave, () => {
s();
})
}
);
}), Bt = "SelectSeparator", Vt = t.forwardRef(
(o, l) => {
const { __scopeSelect: e, ...i } = o;
return /* @__PURE__ */ p(M.div, { "aria-hidden": !0, ...i, ref: l });
}
);
Vt.displayName = Bt;
var ye = "SelectArrow", Ht = t.forwardRef(
(o, l) => {
const { __scopeSelect: e, ...i } = o, c = ue(e), d = j(ye, e), n = q(ye, e);
return d.open && n.position === "popper" ? /* @__PURE__ */ p(lt, { ...c, ...i, ref: l }) : null;
}
);
Ht.displayName = ye;
var Wt = "SelectBubbleInput", qe = t.forwardRef(
({ __scopeSelect: o, value: l, ...e }, i) => {
const c = t.useRef(null), d = k(i, c), n = ut(l);
return t.useEffect(() => {
const r = c.current;
if (!r) return;
const s = window.HTMLSelectElement.prototype, g = Object.getOwnPropertyDescriptor(
s,
"value"
).set;
if (n !== l && g) {
const C = new Event("change", { bubbles: !0 });
g.call(r, l), r.dispatchEvent(C);
}
}, [n, l]), /* @__PURE__ */ p(
M.select,
{
...e,
style: { ...pt, ...e.style },
ref: d,
defaultValue: l
}
);
}
);
qe.displayName = Wt;
function Xe(o) {
return o === "" || o === void 0;
}
function Ze(o) {
const l = dt(o), e = t.useRef(""), i = t.useRef(0), c = t.useCallback(
(n) => {
const r = e.current + n;
l(r), function s(f) {
e.current = f, window.clearTimeout(i.current), f !== "" && (i.current = window.setTimeout(() => s(""), 1e3));
}(r);
},
[l]
), d = t.useCallback(() => {
e.current = "", window.clearTimeout(i.current);
}, []);
return t.useEffect(() => () => window.clearTimeout(i.current), []), [e, c, d];
}
function $e(o, l, e) {
const c = l.length > 1 && Array.from(l).every((f) => f === l[0]) ? l[0] : l, d = e ? o.indexOf(e) : -1;
let n = Ft(o, Math.max(d, 0));
c.length === 1 && (n = n.filter((f) => f !== e));
const s = n.find(
(f) => f.textValue.toLowerCase().startsWith(c.toLowerCase())
);
return s !== e ? s : void 0;
}
function Ft(o, l) {
return o.map((e, i) => o[(l + i) % o.length]);
}
var po = Ne, fo = Ae, mo = De, ho = Le, vo = He, go = Ke, So = Ge, wo = Ye;
export {
ho as Content,
go as Item,
wo as ItemIndicator,
So as ItemText,
mo as Portal,
po as Root,
Ne as Select,
Ht as SelectArrow,
Le as SelectContent,
At as SelectGroup,
It as SelectIcon,
Ke as SelectItem,
Ye as SelectItemIndicator,
Ge as SelectItemText,
Ot as SelectLabel,
De as SelectPortal,
kt as SelectScrollDownButton,
Lt as SelectScrollUpButton,
Vt as SelectSeparator,
Ae as SelectTrigger,
xt as SelectValue,
He as SelectViewport,
fo as Trigger,
vo as Viewport,
uo as createSelectScope
};
//# sourceMappingURL=index53.js.map