@inkeep/cxkit-primitives 0.5.91 → 0.5.92

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,787 @@
1
+ "use client";
2
+ import { jsx as m, jsxs as Ne, Fragment as Ie } from "react/jsx-runtime";
3
+ import * as t from "react";
4
+ import * as Ee from "react-dom";
5
+ import { clamp as Re } from "@radix-ui/number";
6
+ import { composeEventHandlers as R } from "@radix-ui/primitive";
7
+ import { createCollection as Qe } from "@radix-ui/react-collection";
8
+ import { useComposedRefs as k } from "@radix-ui/react-compose-refs";
9
+ import { createContextScope as et } from "@radix-ui/react-context";
10
+ import { useDirection as tt } from "@radix-ui/react-direction";
11
+ import { DismissableLayer as ot } from "@radix-ui/react-dismissable-layer";
12
+ import { useFocusGuards as nt } from "@radix-ui/react-focus-guards";
13
+ import { FocusScope as rt } from "@radix-ui/react-focus-scope";
14
+ import { useId as Te } from "@radix-ui/react-id";
15
+ import * as ie from "@radix-ui/react-popper";
16
+ import { createPopperScope as _e } from "@radix-ui/react-popper";
17
+ import "@radix-ui/react-portal";
18
+ import { Primitive as _ } from "@radix-ui/react-primitive";
19
+ import { createSlot as ct } from "@radix-ui/react-slot";
20
+ import { useCallbackRef as st } from "@radix-ui/react-use-callback-ref";
21
+ import { useControllableState as be } from "@radix-ui/react-use-controllable-state";
22
+ import { useLayoutEffect as W } from "@radix-ui/react-use-layout-effect";
23
+ import { hideOthers as lt } from "aria-hidden";
24
+ import { RemoveScroll as it } from "react-remove-scroll";
25
+ const at = [" ", "Enter", "ArrowUp", "ArrowDown"], dt = [" ", "Enter"], q = "Select", [ae, de, ut] = Qe(q), [ee, Jt] = et(q, [
26
+ ut,
27
+ _e
28
+ ]), ue = _e(), [pt, F] = ee(q), [ft, mt] = ee(q), Me = (o) => {
29
+ const {
30
+ __scopeSelect: i,
31
+ children: e,
32
+ open: l,
33
+ defaultOpen: r,
34
+ onOpenChange: d,
35
+ value: n,
36
+ defaultValue: c,
37
+ onValueChange: s,
38
+ dir: f,
39
+ disabled: S,
40
+ required: x
41
+ } = o, b = ue(i), [P, y] = t.useState(null), [a, h] = t.useState(null), [w, p] = t.useState(!1), g = tt(f), [H, M] = be({
42
+ prop: l,
43
+ defaultProp: r ?? !1,
44
+ onChange: d,
45
+ // @ts-expect-error
46
+ caller: q
47
+ }), [te, N] = be({
48
+ prop: n,
49
+ defaultProp: c,
50
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
51
+ onChange: s,
52
+ // @ts-expect-error
53
+ caller: q
54
+ }), L = t.useRef(null), [oe, K] = t.useState(/* @__PURE__ */ new Set());
55
+ return /* @__PURE__ */ m(ie.Root, { ...b, children: /* @__PURE__ */ m(
56
+ pt,
57
+ {
58
+ required: x,
59
+ scope: i,
60
+ trigger: P,
61
+ onTriggerChange: y,
62
+ valueNode: a,
63
+ onValueNodeChange: h,
64
+ valueNodeHasChildren: w,
65
+ onValueNodeHasChildrenChange: p,
66
+ contentId: Te(),
67
+ value: te,
68
+ onValueChange: N,
69
+ open: !!H,
70
+ onOpenChange: M,
71
+ dir: g,
72
+ triggerPointerDownPosRef: L,
73
+ disabled: S,
74
+ children: /* @__PURE__ */ m(ae.Provider, { scope: i, children: /* @__PURE__ */ m(
75
+ ft,
76
+ {
77
+ scope: o.__scopeSelect,
78
+ onNativeOptionAdd: t.useCallback((O) => {
79
+ K((A) => new Set(A).add(O));
80
+ }, []),
81
+ onNativeOptionRemove: t.useCallback((O) => {
82
+ K((A) => {
83
+ const V = new Set(A);
84
+ return V.delete(O), V;
85
+ });
86
+ }, []),
87
+ children: e
88
+ }
89
+ ) })
90
+ }
91
+ ) });
92
+ };
93
+ Me.displayName = q;
94
+ const Oe = "SelectTrigger", Ae = t.forwardRef(
95
+ (o, i) => {
96
+ const { __scopeSelect: e, disabled: l = !1, ...r } = o, d = ue(e), n = F(Oe, e), c = n.disabled || l, s = k(i, n.onTriggerChange), f = de(e), S = t.useRef("touch"), [x, b, P] = $e((a) => {
97
+ const h = f().filter((g) => !g.disabled), w = h.find((g) => g.value === n.value), p = Je(h, a, w);
98
+ p !== void 0 && n.onValueChange(p.value);
99
+ }), y = (a) => {
100
+ c || (n.onOpenChange(!0), P()), a && (n.triggerPointerDownPosRef.current = {
101
+ x: Math.round(a.pageX),
102
+ y: Math.round(a.pageY)
103
+ });
104
+ };
105
+ return /* @__PURE__ */ m(ie.Anchor, { asChild: !0, ...d, children: /* @__PURE__ */ m(
106
+ _.button,
107
+ {
108
+ type: "button",
109
+ role: "combobox",
110
+ "aria-controls": n.contentId,
111
+ "aria-expanded": n.open,
112
+ "aria-required": n.required,
113
+ "aria-autocomplete": "none",
114
+ dir: n.dir,
115
+ "data-state": n.open ? "open" : "closed",
116
+ disabled: c,
117
+ "data-disabled": c ? "" : void 0,
118
+ "data-placeholder": Ze(n.value) ? "" : void 0,
119
+ ...r,
120
+ ref: s,
121
+ onClick: R(r.onClick, (a) => {
122
+ a.currentTarget.focus(), S.current !== "mouse" && y(a);
123
+ }),
124
+ onPointerDown: R(r.onPointerDown, (a) => {
125
+ S.current = a.pointerType;
126
+ const h = a.target;
127
+ h.hasPointerCapture(a.pointerId) && h.releasePointerCapture(a.pointerId), a.button === 0 && a.ctrlKey === !1 && a.pointerType === "mouse" && (y(a), a.preventDefault());
128
+ }),
129
+ onKeyDown: R(r.onKeyDown, (a) => {
130
+ const h = x.current !== "";
131
+ !(a.ctrlKey || a.altKey || a.metaKey) && a.key.length === 1 && b(a.key), !(h && a.key === " ") && at.includes(a.key) && (y(), a.preventDefault());
132
+ })
133
+ }
134
+ ) });
135
+ }
136
+ );
137
+ Ae.displayName = Oe;
138
+ const De = "SelectValue", Le = t.forwardRef(
139
+ (o, i) => {
140
+ const { __scopeSelect: e, className: l, style: r, children: d, placeholder: n = "", ...c } = o, s = F(De, e), { onValueNodeHasChildrenChange: f } = s, S = d !== void 0, x = k(i, s.onValueNodeChange);
141
+ return W(() => {
142
+ f(S);
143
+ }, [f, S]), /* @__PURE__ */ m(
144
+ _.span,
145
+ {
146
+ ...c,
147
+ ref: x,
148
+ style: { pointerEvents: "none" },
149
+ children: Ze(s.value) ? /* @__PURE__ */ m(Ie, { children: n }) : d
150
+ }
151
+ );
152
+ }
153
+ );
154
+ Le.displayName = De;
155
+ const ht = "SelectIcon", ke = t.forwardRef(
156
+ (o, i) => {
157
+ const { __scopeSelect: e, children: l, ...r } = o;
158
+ return /* @__PURE__ */ m(_.span, { "aria-hidden": !0, ...r, ref: i, children: l || "▼" });
159
+ }
160
+ );
161
+ ke.displayName = ht;
162
+ const j = "SelectContent", He = t.forwardRef(
163
+ (o, i) => {
164
+ const e = F(j, o.__scopeSelect), [l, r] = t.useState();
165
+ if (W(() => {
166
+ r(new DocumentFragment());
167
+ }, []), !e.open) {
168
+ const d = l;
169
+ return d ? Ee.createPortal(
170
+ /* @__PURE__ */ m(Ve, { scope: o.__scopeSelect, children: /* @__PURE__ */ m(ae.Slot, { scope: o.__scopeSelect, children: /* @__PURE__ */ m("div", { children: o.children }) }) }),
171
+ d
172
+ ) : null;
173
+ }
174
+ return /* @__PURE__ */ m(Be, { ...o, ref: i });
175
+ }
176
+ );
177
+ He.displayName = j;
178
+ const D = 10, [Ve, U] = ee(j), gt = "SelectContentImpl", St = ct("SelectContent.RemoveScroll"), Be = t.forwardRef(
179
+ (o, i) => {
180
+ const {
181
+ __scopeSelect: e,
182
+ position: l = "item-aligned",
183
+ onCloseAutoFocus: r,
184
+ onEscapeKeyDown: d,
185
+ onPointerDownOutside: n,
186
+ //
187
+ // PopperContent props
188
+ side: c,
189
+ sideOffset: s,
190
+ align: f,
191
+ alignOffset: S,
192
+ arrowPadding: x,
193
+ collisionBoundary: b,
194
+ collisionPadding: P,
195
+ sticky: y,
196
+ hideWhenDetached: a,
197
+ avoidCollisions: h,
198
+ //
199
+ ...w
200
+ } = o, p = F(j, e), [g, H] = t.useState(null), [M, te] = t.useState(null), N = k(i, (u) => H(u)), [L, oe] = t.useState(null), [K, O] = t.useState(
201
+ null
202
+ ), A = de(e), [V, X] = t.useState(!1), G = t.useRef(!1);
203
+ t.useEffect(() => {
204
+ if (g) return lt(g);
205
+ }, [g]), nt();
206
+ const Z = t.useCallback(
207
+ (u) => {
208
+ const [I, ...E] = A().map((T) => T.ref.current), [v] = E.slice(-1), C = document.activeElement;
209
+ for (const T of u)
210
+ if (T === C || (T?.scrollIntoView({ block: "nearest" }), T === I && M && (M.scrollTop = 0), T === v && M && (M.scrollTop = M.scrollHeight), T?.focus(), document.activeElement !== C)) return;
211
+ },
212
+ [A, M]
213
+ ), $ = t.useCallback(
214
+ () => Z([L, g]),
215
+ [Z, L, g]
216
+ );
217
+ t.useEffect(() => {
218
+ V && $();
219
+ }, [V, $]);
220
+ const { onOpenChange: J, triggerPointerDownPosRef: B } = p;
221
+ t.useEffect(() => {
222
+ if (g) {
223
+ let u = { x: 0, y: 0 };
224
+ const I = (v) => {
225
+ u = {
226
+ x: Math.abs(Math.round(v.pageX) - (B.current?.x ?? 0)),
227
+ y: Math.abs(Math.round(v.pageY) - (B.current?.y ?? 0))
228
+ };
229
+ }, E = (v) => {
230
+ u.x <= 10 && u.y <= 10 ? v.preventDefault() : g.contains(v.target) || J(!1), document.removeEventListener("pointermove", I), B.current = null;
231
+ };
232
+ return B.current !== null && (document.addEventListener("pointermove", I), document.addEventListener("pointerup", E, { capture: !0, once: !0 })), () => {
233
+ document.removeEventListener("pointermove", I), document.removeEventListener("pointerup", E, { capture: !0 });
234
+ };
235
+ }
236
+ }, [g, J, B]), t.useEffect(() => {
237
+ const u = () => J(!1);
238
+ return window.addEventListener("blur", u), window.addEventListener("resize", u), () => {
239
+ window.removeEventListener("blur", u), window.removeEventListener("resize", u);
240
+ };
241
+ }, [J]);
242
+ const [pe, ce] = $e((u) => {
243
+ const I = A().filter((C) => !C.disabled), E = I.find((C) => C.ref.current === document.activeElement), v = Je(I, u, E);
244
+ v && setTimeout(() => v.ref.current.focus());
245
+ }), fe = t.useCallback(
246
+ (u, I, E) => {
247
+ const v = !G.current && !E;
248
+ (p.value !== void 0 && p.value === I || v) && (oe(u), v && (G.current = !0));
249
+ },
250
+ [p.value]
251
+ ), me = t.useCallback(() => g?.focus(), [g]), Q = t.useCallback(
252
+ (u, I, E) => {
253
+ const v = !G.current && !E;
254
+ (p.value !== void 0 && p.value === I || v) && O(u);
255
+ },
256
+ [p.value]
257
+ ), se = l === "popper" ? we : We, ne = se === we ? {
258
+ side: c,
259
+ sideOffset: s,
260
+ align: f,
261
+ alignOffset: S,
262
+ arrowPadding: x,
263
+ collisionBoundary: b,
264
+ collisionPadding: P,
265
+ sticky: y,
266
+ hideWhenDetached: a,
267
+ avoidCollisions: h
268
+ } : {};
269
+ return /* @__PURE__ */ m(
270
+ Ve,
271
+ {
272
+ scope: e,
273
+ content: g,
274
+ viewport: M,
275
+ onViewportChange: te,
276
+ itemRefCallback: fe,
277
+ selectedItem: L,
278
+ onItemLeave: me,
279
+ itemTextRefCallback: Q,
280
+ focusSelectedItem: $,
281
+ selectedItemText: K,
282
+ position: l,
283
+ isPositioned: V,
284
+ searchRef: pe,
285
+ children: /* @__PURE__ */ m(it, { as: St, allowPinchZoom: !0, removeScrollBar: !1, children: /* @__PURE__ */ m(
286
+ rt,
287
+ {
288
+ asChild: !0,
289
+ trapped: p.open,
290
+ onMountAutoFocus: (u) => {
291
+ u.preventDefault();
292
+ },
293
+ onUnmountAutoFocus: R(r, (u) => {
294
+ p.trigger?.focus({ preventScroll: !0 }), u.preventDefault();
295
+ }),
296
+ children: /* @__PURE__ */ m(
297
+ ot,
298
+ {
299
+ asChild: !0,
300
+ disableOutsidePointerEvents: !0,
301
+ onEscapeKeyDown: d,
302
+ onPointerDownOutside: n,
303
+ onFocusOutside: (u) => u.preventDefault(),
304
+ onDismiss: () => p.onOpenChange(!1),
305
+ children: /* @__PURE__ */ m(
306
+ se,
307
+ {
308
+ role: "listbox",
309
+ id: p.contentId,
310
+ "data-state": p.open ? "open" : "closed",
311
+ dir: p.dir,
312
+ onContextMenu: (u) => u.preventDefault(),
313
+ ...w,
314
+ ...ne,
315
+ onPlaced: () => X(!0),
316
+ ref: N,
317
+ style: {
318
+ // flex layout so we can place the scroll buttons properly
319
+ display: "flex",
320
+ flexDirection: "column",
321
+ // reset the outline by default as the content MAY get focused
322
+ outline: "none",
323
+ ...w.style
324
+ },
325
+ onKeyDown: R(w.onKeyDown, (u) => {
326
+ const I = u.ctrlKey || u.altKey || u.metaKey;
327
+ if (u.key === "Tab" && u.preventDefault(), !I && u.key.length === 1 && ce(u.key), ["ArrowUp", "ArrowDown", "Home", "End"].includes(u.key)) {
328
+ let v = A().filter((C) => !C.disabled).map((C) => C.ref.current);
329
+ if (["ArrowUp", "End"].includes(u.key) && (v = v.slice().reverse()), ["ArrowUp", "ArrowDown"].includes(u.key)) {
330
+ const C = u.target, T = v.indexOf(C);
331
+ v = v.slice(T + 1);
332
+ }
333
+ setTimeout(() => Z(v)), u.preventDefault();
334
+ }
335
+ })
336
+ }
337
+ )
338
+ }
339
+ )
340
+ }
341
+ ) })
342
+ }
343
+ );
344
+ }
345
+ );
346
+ Be.displayName = gt;
347
+ const wt = "SelectItemAlignedPosition", We = t.forwardRef((o, i) => {
348
+ const { __scopeSelect: e, onPlaced: l, ...r } = o, d = F(j, e), n = U(j, e), [c, s] = t.useState(null), [f, S] = t.useState(null), x = k(i, (N) => S(N)), b = de(e), P = t.useRef(!1), y = t.useRef(!0), { viewport: a, selectedItem: h, selectedItemText: w, focusSelectedItem: p } = n, g = t.useCallback(() => {
349
+ if (d.trigger && d.valueNode && c && f && a && h && w) {
350
+ const N = d.trigger.getBoundingClientRect(), L = f.getBoundingClientRect(), oe = d.valueNode.getBoundingClientRect(), K = w.getBoundingClientRect();
351
+ if (d.dir !== "rtl") {
352
+ const C = K.left - L.left, T = oe.left - C, z = N.left - T, Y = N.width + z, he = Math.max(Y, L.width), ge = window.innerWidth - D, Se = Re(T, [
353
+ D,
354
+ // Prevents the content from going off the starting edge of the
355
+ // viewport. It may still go off the ending edge, but this can be
356
+ // controlled by the user since they may want to manage overflow in a
357
+ // specific way.
358
+ // https://github.com/radix-ui/primitives/issues/2049
359
+ Math.max(D, ge - he)
360
+ ]);
361
+ c.style.minWidth = Y + "px", c.style.left = Se + "px";
362
+ } else {
363
+ const C = L.right - K.right, T = window.innerWidth - oe.right - C, z = window.innerWidth - N.right - T, Y = N.width + z, he = Math.max(Y, L.width), ge = window.innerWidth - D, Se = Re(T, [
364
+ D,
365
+ Math.max(D, ge - he)
366
+ ]);
367
+ c.style.minWidth = Y + "px", c.style.right = Se + "px";
368
+ }
369
+ const O = b(), A = window.innerHeight - D * 2, V = a.scrollHeight, X = window.getComputedStyle(f), G = Number.parseInt(X.borderTopWidth, 10), Z = Number.parseInt(X.paddingTop, 10), $ = Number.parseInt(X.borderBottomWidth, 10), J = Number.parseInt(X.paddingBottom, 10), B = G + Z + V + J + $, pe = Math.min(h.offsetHeight * 5, B), ce = window.getComputedStyle(a), fe = Number.parseInt(ce.paddingTop, 10), me = Number.parseInt(ce.paddingBottom, 10), Q = N.top + N.height / 2 - D, se = A - Q, ne = h.offsetHeight / 2, u = h.offsetTop + ne, I = G + Z + u, E = B - I;
370
+ if (I <= Q) {
371
+ const C = O.length > 0 && h === O[O.length - 1].ref.current;
372
+ c.style.bottom = "0px";
373
+ const T = f.clientHeight - a.offsetTop - a.offsetHeight, z = Math.max(
374
+ se,
375
+ ne + // viewport might have padding bottom, include it to avoid a scrollable viewport
376
+ (C ? me : 0) + T + $
377
+ ), Y = I + z;
378
+ c.style.height = Y + "px";
379
+ } else {
380
+ const C = O.length > 0 && h === O[0].ref.current;
381
+ c.style.top = "0px";
382
+ const z = Math.max(
383
+ Q,
384
+ G + a.offsetTop + // viewport might have padding top, include it to avoid a scrollable viewport
385
+ (C ? fe : 0) + ne
386
+ ) + E;
387
+ c.style.height = z + "px", a.scrollTop = I - Q + a.offsetTop;
388
+ }
389
+ c.style.margin = `${D}px 0`, c.style.minHeight = pe + "px", c.style.maxHeight = A + "px", l?.(), requestAnimationFrame(() => P.current = !0);
390
+ }
391
+ }, [
392
+ b,
393
+ d.trigger,
394
+ d.valueNode,
395
+ c,
396
+ f,
397
+ a,
398
+ h,
399
+ w,
400
+ d.dir,
401
+ l
402
+ ]);
403
+ W(() => g(), [g]);
404
+ const [H, M] = t.useState();
405
+ W(() => {
406
+ f && M(window.getComputedStyle(f).zIndex);
407
+ }, [f]);
408
+ const te = t.useCallback(
409
+ (N) => {
410
+ N && y.current === !0 && (g(), p?.(), y.current = !1);
411
+ },
412
+ [g, p]
413
+ );
414
+ return /* @__PURE__ */ m(
415
+ Ct,
416
+ {
417
+ scope: e,
418
+ contentWrapper: c,
419
+ shouldExpandOnScrollRef: P,
420
+ onScrollButtonChange: te,
421
+ children: /* @__PURE__ */ m(
422
+ "div",
423
+ {
424
+ ref: s,
425
+ style: {
426
+ display: "flex",
427
+ flexDirection: "column",
428
+ position: "fixed",
429
+ zIndex: H
430
+ },
431
+ children: /* @__PURE__ */ m(
432
+ _.div,
433
+ {
434
+ ...r,
435
+ ref: x,
436
+ style: {
437
+ // When we get the height of the content, it includes borders. If we were to set
438
+ // the height without having `boxSizing: 'border-box'` it would be too big.
439
+ boxSizing: "border-box",
440
+ // We need to ensure the content doesn't get taller than the wrapper
441
+ maxHeight: "100%",
442
+ ...r.style
443
+ }
444
+ }
445
+ )
446
+ }
447
+ )
448
+ }
449
+ );
450
+ });
451
+ We.displayName = wt;
452
+ const vt = "SelectPopperPosition", we = t.forwardRef((o, i) => {
453
+ const {
454
+ __scopeSelect: e,
455
+ align: l = "start",
456
+ collisionPadding: r = D,
457
+ ...d
458
+ } = o, n = ue(e);
459
+ return /* @__PURE__ */ m(
460
+ ie.Content,
461
+ {
462
+ ...n,
463
+ ...d,
464
+ ref: i,
465
+ align: l,
466
+ collisionPadding: r,
467
+ style: {
468
+ // Ensure border-box for floating-ui calculations
469
+ boxSizing: "border-box",
470
+ ...d.style,
471
+ "--radix-select-content-transform-origin": "var(--radix-popper-transform-origin)",
472
+ "--radix-select-content-available-width": "var(--radix-popper-available-width)",
473
+ "--radix-select-content-available-height": "var(--radix-popper-available-height)",
474
+ "--radix-select-trigger-width": "var(--radix-popper-anchor-width)",
475
+ "--radix-select-trigger-height": "var(--radix-popper-anchor-height)"
476
+ }
477
+ }
478
+ );
479
+ });
480
+ we.displayName = vt;
481
+ const [Ct, Pe] = ee(j, {}), ve = "SelectViewport", Fe = t.forwardRef(
482
+ (o, i) => {
483
+ const { __scopeSelect: e, nonce: l, ...r } = o, d = U(ve, e), n = Pe(ve, e), c = k(i, d.onViewportChange), s = t.useRef(0);
484
+ return /* @__PURE__ */ Ne(Ie, { children: [
485
+ /* @__PURE__ */ m(
486
+ "style",
487
+ {
488
+ dangerouslySetInnerHTML: {
489
+ __html: "[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"
490
+ },
491
+ nonce: l
492
+ }
493
+ ),
494
+ /* @__PURE__ */ m(ae.Slot, { scope: e, children: /* @__PURE__ */ m(
495
+ _.div,
496
+ {
497
+ "data-radix-select-viewport": "",
498
+ role: "presentation",
499
+ ...r,
500
+ ref: c,
501
+ style: {
502
+ // we use position: 'relative' here on the `viewport` so that when we call
503
+ // `selectedItem.offsetTop` in calculations, the offset is relative to the viewport
504
+ // (independent of the scrollUpButton).
505
+ position: "relative",
506
+ flex: 1,
507
+ // Viewport should only be scrollable in the vertical direction.
508
+ // This won't work in vertical writing modes, so we'll need to
509
+ // revisit this if/when that is supported
510
+ // https://developer.chrome.com/blog/vertical-form-controls
511
+ overflow: "hidden auto",
512
+ ...r.style
513
+ },
514
+ onScroll: R(r.onScroll, (f) => {
515
+ const S = f.currentTarget, { contentWrapper: x, shouldExpandOnScrollRef: b } = n;
516
+ if (b?.current && x) {
517
+ const P = Math.abs(s.current - S.scrollTop);
518
+ if (P > 0) {
519
+ const y = window.innerHeight - D * 2, a = Number.parseFloat(x.style.minHeight), h = Number.parseFloat(x.style.height), w = Math.max(a, h);
520
+ if (w < y) {
521
+ const p = w + P, g = Math.min(y, p), H = p - g;
522
+ x.style.height = g + "px", x.style.bottom === "0px" && (S.scrollTop = H > 0 ? H : 0, x.style.justifyContent = "flex-end");
523
+ }
524
+ }
525
+ }
526
+ s.current = S.scrollTop;
527
+ })
528
+ }
529
+ ) })
530
+ ] });
531
+ }
532
+ );
533
+ Fe.displayName = ve;
534
+ const Ue = "SelectGroup", [xt, yt] = ee(Ue), It = t.forwardRef(
535
+ (o, i) => {
536
+ const { __scopeSelect: e, ...l } = o, r = Te();
537
+ return /* @__PURE__ */ m(xt, { scope: e, id: r, children: /* @__PURE__ */ m(_.div, { role: "group", "aria-labelledby": r, ...l, ref: i }) });
538
+ }
539
+ );
540
+ It.displayName = Ue;
541
+ const Ke = "SelectLabel", Tt = t.forwardRef(
542
+ (o, i) => {
543
+ const { __scopeSelect: e, ...l } = o, r = yt(Ke, e);
544
+ return /* @__PURE__ */ m(_.div, { id: r.id, ...l, ref: i });
545
+ }
546
+ );
547
+ Tt.displayName = Ke;
548
+ const le = "SelectItem", [Pt, Ge] = ee(le), ze = t.forwardRef(
549
+ (o, i) => {
550
+ const { __scopeSelect: e, value: l, disabled: r = !1, textValue: d, ...n } = o, c = F(le, e), s = U(le, e), f = c.value === l, [S, x] = t.useState(d ?? ""), [b, P] = t.useState(!1), y = k(
551
+ i,
552
+ (p) => s.itemRefCallback?.(p, l, r)
553
+ ), a = Te(), h = t.useRef("touch"), w = () => {
554
+ r || (c.onValueChange(l), c.onOpenChange(!1));
555
+ };
556
+ if (l === "")
557
+ throw new Error(
558
+ "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."
559
+ );
560
+ return /* @__PURE__ */ m(
561
+ Pt,
562
+ {
563
+ scope: e,
564
+ value: l,
565
+ disabled: r,
566
+ textId: a,
567
+ isSelected: f,
568
+ onItemTextChange: t.useCallback((p) => {
569
+ x((g) => g || (p?.textContent ?? "").trim());
570
+ }, []),
571
+ children: /* @__PURE__ */ m(
572
+ ae.ItemSlot,
573
+ {
574
+ scope: e,
575
+ value: l,
576
+ disabled: r,
577
+ textValue: S,
578
+ children: /* @__PURE__ */ m(
579
+ _.div,
580
+ {
581
+ role: "option",
582
+ "aria-labelledby": a,
583
+ "data-highlighted": b ? "" : void 0,
584
+ "aria-selected": f && b,
585
+ "data-state": f ? "checked" : "unchecked",
586
+ "aria-disabled": r || void 0,
587
+ "data-disabled": r ? "" : void 0,
588
+ tabIndex: r ? void 0 : -1,
589
+ ...n,
590
+ ref: y,
591
+ onFocus: R(n.onFocus, () => P(!0)),
592
+ onBlur: R(n.onBlur, () => P(!1)),
593
+ onClick: R(n.onClick, () => {
594
+ h.current !== "mouse" && w();
595
+ }),
596
+ onPointerUp: R(n.onPointerUp, () => {
597
+ h.current === "mouse" && w();
598
+ }),
599
+ onPointerDown: R(n.onPointerDown, (p) => {
600
+ h.current = p.pointerType;
601
+ }),
602
+ onPointerMove: R(n.onPointerMove, (p) => {
603
+ h.current = p.pointerType, r ? s.onItemLeave?.() : h.current === "mouse" && p.currentTarget.focus({ preventScroll: !0 });
604
+ }),
605
+ onPointerLeave: R(n.onPointerLeave, (p) => {
606
+ p.currentTarget === document.activeElement && s.onItemLeave?.();
607
+ }),
608
+ onKeyDown: R(n.onKeyDown, (p) => {
609
+ s.searchRef?.current !== "" && p.key === " " || (dt.includes(p.key) && w(), p.key === " " && p.preventDefault());
610
+ })
611
+ }
612
+ )
613
+ }
614
+ )
615
+ }
616
+ );
617
+ }
618
+ );
619
+ ze.displayName = le;
620
+ const re = "SelectItemText", Ye = t.forwardRef(
621
+ (o, i) => {
622
+ const { __scopeSelect: e, className: l, style: r, ...d } = o, n = F(re, e), c = U(re, e), s = Ge(re, e), f = mt(re, e), [S, x] = t.useState(null), b = k(
623
+ i,
624
+ (w) => x(w),
625
+ s.onItemTextChange,
626
+ (w) => c.itemTextRefCallback?.(w, s.value, s.disabled)
627
+ ), P = S?.textContent, y = t.useMemo(
628
+ () => /* @__PURE__ */ m("option", { value: s.value, disabled: s.disabled, children: P }, s.value),
629
+ [s.disabled, s.value, P]
630
+ ), { onNativeOptionAdd: a, onNativeOptionRemove: h } = f;
631
+ return W(() => (a(y), () => h(y)), [a, h, y]), /* @__PURE__ */ Ne(Ie, { children: [
632
+ /* @__PURE__ */ m(_.span, { id: s.textId, ...d, ref: b }),
633
+ s.isSelected && n.valueNode && !n.valueNodeHasChildren ? Ee.createPortal(d.children, n.valueNode) : null
634
+ ] });
635
+ }
636
+ );
637
+ Ye.displayName = re;
638
+ const qe = "SelectItemIndicator", je = t.forwardRef(
639
+ (o, i) => {
640
+ const { __scopeSelect: e, ...l } = o;
641
+ return Ge(qe, e).isSelected ? /* @__PURE__ */ m(_.span, { "aria-hidden": !0, ...l, ref: i }) : null;
642
+ }
643
+ );
644
+ je.displayName = qe;
645
+ const Ce = "SelectScrollUpButton", Rt = t.forwardRef((o, i) => {
646
+ const e = U(Ce, o.__scopeSelect), l = Pe(Ce, o.__scopeSelect), [r, d] = t.useState(!1), n = k(i, l.onScrollButtonChange);
647
+ return W(() => {
648
+ if (e.viewport && e.isPositioned) {
649
+ let c = function() {
650
+ const f = s.scrollTop > 0;
651
+ d(f);
652
+ };
653
+ const s = e.viewport;
654
+ return c(), s.addEventListener("scroll", c), () => s.removeEventListener("scroll", c);
655
+ }
656
+ }, [e.viewport, e.isPositioned]), r ? /* @__PURE__ */ m(
657
+ Xe,
658
+ {
659
+ ...o,
660
+ ref: n,
661
+ onAutoScroll: () => {
662
+ const { viewport: c, selectedItem: s } = e;
663
+ c && s && (c.scrollTop = c.scrollTop - s.offsetHeight);
664
+ }
665
+ }
666
+ ) : null;
667
+ });
668
+ Rt.displayName = Ce;
669
+ const xe = "SelectScrollDownButton", bt = t.forwardRef((o, i) => {
670
+ const e = U(xe, o.__scopeSelect), l = Pe(xe, o.__scopeSelect), [r, d] = t.useState(!1), n = k(i, l.onScrollButtonChange);
671
+ return W(() => {
672
+ if (e.viewport && e.isPositioned) {
673
+ let c = function() {
674
+ const f = s.scrollHeight - s.clientHeight, S = Math.ceil(s.scrollTop) < f;
675
+ d(S);
676
+ };
677
+ const s = e.viewport;
678
+ return c(), s.addEventListener("scroll", c), () => s.removeEventListener("scroll", c);
679
+ }
680
+ }, [e.viewport, e.isPositioned]), r ? /* @__PURE__ */ m(
681
+ Xe,
682
+ {
683
+ ...o,
684
+ ref: n,
685
+ onAutoScroll: () => {
686
+ const { viewport: c, selectedItem: s } = e;
687
+ c && s && (c.scrollTop = c.scrollTop + s.offsetHeight);
688
+ }
689
+ }
690
+ ) : null;
691
+ });
692
+ bt.displayName = xe;
693
+ const Xe = t.forwardRef((o, i) => {
694
+ const { __scopeSelect: e, onAutoScroll: l, ...r } = o, d = U("SelectScrollButton", e), n = t.useRef(null), c = de(e), s = t.useCallback(() => {
695
+ n.current !== null && (window.clearInterval(n.current), n.current = null);
696
+ }, []);
697
+ return t.useEffect(() => () => s(), [s]), W(() => {
698
+ c().find((S) => S.ref.current === document.activeElement)?.ref.current?.scrollIntoView({ block: "nearest" });
699
+ }, [c]), /* @__PURE__ */ m(
700
+ _.div,
701
+ {
702
+ "aria-hidden": !0,
703
+ ...r,
704
+ ref: i,
705
+ style: { flexShrink: 0, ...r.style },
706
+ onPointerDown: R(r.onPointerDown, () => {
707
+ n.current === null && (n.current = window.setInterval(l, 50));
708
+ }),
709
+ onPointerMove: R(r.onPointerMove, () => {
710
+ d.onItemLeave?.(), n.current === null && (n.current = window.setInterval(l, 50));
711
+ }),
712
+ onPointerLeave: R(r.onPointerLeave, () => {
713
+ s();
714
+ })
715
+ }
716
+ );
717
+ }), Nt = "SelectSeparator", Et = t.forwardRef(
718
+ (o, i) => {
719
+ const { __scopeSelect: e, ...l } = o;
720
+ return /* @__PURE__ */ m(_.div, { "aria-hidden": !0, ...l, ref: i });
721
+ }
722
+ );
723
+ Et.displayName = Nt;
724
+ const ye = "SelectArrow", _t = t.forwardRef(
725
+ (o, i) => {
726
+ const { __scopeSelect: e, ...l } = o, r = ue(e), d = F(ye, e), n = U(ye, e);
727
+ return d.open && n.position === "popper" ? /* @__PURE__ */ m(ie.Arrow, { ...r, ...l, ref: i }) : null;
728
+ }
729
+ );
730
+ _t.displayName = ye;
731
+ function Ze(o) {
732
+ return o === "" || o === void 0;
733
+ }
734
+ function $e(o) {
735
+ const i = st(o), e = t.useRef(""), l = t.useRef(0), r = t.useCallback(
736
+ (n) => {
737
+ const c = e.current + n;
738
+ i(c), function s(f) {
739
+ e.current = f, window.clearTimeout(l.current), f !== "" && (l.current = window.setTimeout(() => s(""), 1e3));
740
+ }(c);
741
+ },
742
+ [i]
743
+ ), d = t.useCallback(() => {
744
+ e.current = "", window.clearTimeout(l.current);
745
+ }, []);
746
+ return t.useEffect(() => () => window.clearTimeout(l.current), []), [e, r, d];
747
+ }
748
+ function Je(o, i, e) {
749
+ const r = i.length > 1 && Array.from(i).every((f) => f === i[0]) ? i[0] : i, d = e ? o.indexOf(e) : -1;
750
+ let n = Mt(o, Math.max(d, 0));
751
+ r.length === 1 && (n = n.filter((f) => f !== e));
752
+ const s = n.find(
753
+ (f) => f.textValue.toLowerCase().startsWith(r.toLowerCase())
754
+ );
755
+ return s !== e ? s : void 0;
756
+ }
757
+ function Mt(o, i) {
758
+ return o.map((e, l) => o[(i + l) % o.length]);
759
+ }
760
+ const Qt = Me, eo = Ae, to = Le, oo = ke, no = He, ro = Fe, co = ze, so = Ye, lo = je;
761
+ export {
762
+ no as Content,
763
+ oo as Icon,
764
+ co as Item,
765
+ lo as ItemIndicator,
766
+ so as ItemText,
767
+ Qt as Root,
768
+ Me as Select,
769
+ _t as SelectArrow,
770
+ He as SelectContent,
771
+ It as SelectGroup,
772
+ ke as SelectIcon,
773
+ ze as SelectItem,
774
+ je as SelectItemIndicator,
775
+ Ye as SelectItemText,
776
+ Tt as SelectLabel,
777
+ bt as SelectScrollDownButton,
778
+ Rt as SelectScrollUpButton,
779
+ Et as SelectSeparator,
780
+ Ae as SelectTrigger,
781
+ Le as SelectValue,
782
+ Fe as SelectViewport,
783
+ eo as Trigger,
784
+ to as Value,
785
+ ro as Viewport,
786
+ Jt as createSelectScope
787
+ };