@reopt-ai/opt-ui-primitives 1.4.2

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.
package/dist/index.cjs ADDED
@@ -0,0 +1,5020 @@
1
+ "use client";
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __defProps = Object.defineProperties;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
8
+ var __getOwnPropNames = Object.getOwnPropertyNames;
9
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
10
+ var __getProtoOf = Object.getPrototypeOf;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
13
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
+ var __spreadValues = (a, b) => {
15
+ for (var prop in b || (b = {}))
16
+ if (__hasOwnProp.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ if (__getOwnPropSymbols)
19
+ for (var prop of __getOwnPropSymbols(b)) {
20
+ if (__propIsEnum.call(b, prop))
21
+ __defNormalProp(a, prop, b[prop]);
22
+ }
23
+ return a;
24
+ };
25
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
26
+ var __objRest = (source, exclude) => {
27
+ var target = {};
28
+ for (var prop in source)
29
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
30
+ target[prop] = source[prop];
31
+ if (source != null && __getOwnPropSymbols)
32
+ for (var prop of __getOwnPropSymbols(source)) {
33
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
34
+ target[prop] = source[prop];
35
+ }
36
+ return target;
37
+ };
38
+ var __export = (target, all) => {
39
+ for (var name in all)
40
+ __defProp(target, name, { get: all[name], enumerable: true });
41
+ };
42
+ var __copyProps = (to, from, except, desc) => {
43
+ if (from && typeof from === "object" || typeof from === "function") {
44
+ for (let key of __getOwnPropNames(from))
45
+ if (!__hasOwnProp.call(to, key) && key !== except)
46
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
47
+ }
48
+ return to;
49
+ };
50
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
51
+ // If the importer is in node compatibility mode or this is not an ESM
52
+ // file that has been converted to a CommonJS file using a Babel-
53
+ // compatible transform (i.e. "__esModule" has not been set), then set
54
+ // "default" to the CommonJS "module.exports" for node compatibility.
55
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
56
+ mod
57
+ ));
58
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
59
+
60
+ // src/index.ts
61
+ var src_exports = {};
62
+ __export(src_exports, {
63
+ AccordionContent: () => AccordionContent,
64
+ AccordionItem: () => AccordionItem,
65
+ AccordionRoot: () => AccordionRoot,
66
+ AccordionTrigger: () => AccordionTrigger,
67
+ AlertDialogPanel: () => AlertDialogPanel,
68
+ Button: () => Button,
69
+ Checkbox: () => Checkbox,
70
+ ComboboxGroup: () => ComboboxGroup,
71
+ ComboboxGroupLabel: () => ComboboxGroupLabel,
72
+ ComboboxInput: () => ComboboxInput,
73
+ ComboboxItem: () => ComboboxItem,
74
+ ComboboxPopover: () => ComboboxPopover,
75
+ ComboboxRoot: () => ComboboxRoot,
76
+ CommandEmpty: () => CommandEmpty,
77
+ CommandGroup: () => CommandGroup,
78
+ CommandInput: () => CommandInput,
79
+ CommandItem: () => CommandItem,
80
+ CommandList: () => CommandList,
81
+ CommandRoot: () => CommandRoot,
82
+ CommandSeparator: () => CommandSeparator,
83
+ Composite: () => Composite,
84
+ CompositeItem: () => CompositeItem,
85
+ CompositeProvider: () => CompositeProvider,
86
+ CompositeRow: () => CompositeRow,
87
+ DialogDescription: () => DialogDescription,
88
+ DialogDisclosure: () => DialogDisclosure,
89
+ DialogDismiss: () => DialogDismiss,
90
+ DialogHeading: () => DialogHeading,
91
+ DialogPanel: () => DialogPanel,
92
+ DialogRoot: () => DialogRoot,
93
+ DisclosureContent: () => DisclosureContent,
94
+ DisclosureRoot: () => DisclosureRoot,
95
+ DisclosureTrigger: () => DisclosureTrigger,
96
+ FormCheckbox: () => FormCheckbox,
97
+ FormControl: () => FormControl,
98
+ FormDescription: () => FormDescription,
99
+ FormError: () => FormError,
100
+ FormField: () => FormField,
101
+ FormGroup: () => FormGroup,
102
+ FormGroupLabel: () => FormGroupLabel,
103
+ FormInput: () => FormInput,
104
+ FormLabel: () => FormLabel,
105
+ FormProvider: () => FormProvider,
106
+ FormPush: () => FormPush,
107
+ FormRadio: () => FormRadio,
108
+ FormRadioGroup: () => FormRadioGroup,
109
+ FormRemove: () => FormRemove,
110
+ FormReset: () => FormReset,
111
+ FormRoot: () => FormRoot,
112
+ FormSelect: () => FormSelect,
113
+ FormSubmit: () => FormSubmit,
114
+ FormSwitch: () => FormSwitch,
115
+ FormTextarea: () => FormTextarea,
116
+ MenuButtonArrow: () => MenuButtonArrow,
117
+ MenuItem: () => MenuItem,
118
+ MenuItemCheckbox: () => MenuItemCheckbox,
119
+ MenuItemRadio: () => MenuItemRadio,
120
+ MenuPopover: () => MenuPopover,
121
+ MenuRoot: () => MenuRoot,
122
+ MenuSeparator: () => MenuSeparator,
123
+ MenuTrigger: () => MenuTrigger,
124
+ MenubarContainer: () => MenubarContainer,
125
+ MenubarRoot: () => MenubarRoot,
126
+ Meter: () => Meter,
127
+ PopoverClose: () => PopoverClose,
128
+ PopoverContent: () => PopoverContent,
129
+ PopoverRoot: () => PopoverRoot,
130
+ PopoverTrigger: () => PopoverTrigger,
131
+ Progress: () => Progress,
132
+ Radio: () => Radio,
133
+ RadioGroupRoot: () => RadioGroupRoot,
134
+ SelectItem: () => SelectItem,
135
+ SelectLabel: () => SelectLabel,
136
+ SelectPopover: () => SelectPopover,
137
+ SelectRoot: () => SelectRoot,
138
+ SelectTrigger: () => SelectTrigger,
139
+ Separator: () => Separator,
140
+ Switch: () => Switch,
141
+ Tab: () => Tab,
142
+ TabList: () => TabList,
143
+ TabPanel: () => TabPanel,
144
+ TabsRoot: () => TabsRoot,
145
+ Toggle: () => Toggle,
146
+ ToggleGroup: () => ToggleGroup,
147
+ ToolbarButton: () => ToolbarButton,
148
+ ToolbarContainer: () => ToolbarContainer,
149
+ ToolbarRoot: () => ToolbarRoot,
150
+ ToolbarSeparator: () => ToolbarSeparator,
151
+ Tooltip: () => Tooltip,
152
+ TooltipAnchor: () => TooltipAnchor,
153
+ TooltipProvider: () => TooltipProvider,
154
+ useCommandState: () => useCommandState,
155
+ useControllableState: () => useControllableState,
156
+ useDialogClose: () => useDialogClose,
157
+ useEnterLeave: () => useEnterLeave,
158
+ useFieldValue: () => useFieldValue,
159
+ useFloating: () => useFloating,
160
+ useFocusVisible: () => useFocusVisible,
161
+ useFocusableWhenDisabled: () => useFocusableWhenDisabled,
162
+ useFormContext: () => useFormContext,
163
+ useFormStore: () => useFormStore,
164
+ useId: () => useId,
165
+ useMenubarContext: () => useMenubarContext,
166
+ useRadioGroupContext: () => useRadioGroupContext,
167
+ useRovingTabindex: () => useRovingTabindex,
168
+ useScrollActiveDescendantIntoView: () => useScrollActiveDescendantIntoView
169
+ });
170
+ module.exports = __toCommonJS(src_exports);
171
+
172
+ // src/hooks/use-controllable-state.ts
173
+ var import_react = require("react");
174
+ function useControllableState(defaultValue, controlledValue, onChange) {
175
+ const [uncontrolledValue, setUncontrolledValue] = (0, import_react.useState)(defaultValue);
176
+ const isControlled = controlledValue !== void 0;
177
+ const value = isControlled ? controlledValue : uncontrolledValue;
178
+ const setValue = (0, import_react.useCallback)(
179
+ (newValue) => {
180
+ if (!isControlled) {
181
+ setUncontrolledValue(newValue);
182
+ }
183
+ onChange == null ? void 0 : onChange(newValue);
184
+ },
185
+ [isControlled, onChange]
186
+ );
187
+ return [value, setValue];
188
+ }
189
+
190
+ // src/hooks/use-enter-leave.ts
191
+ var import_react2 = require("react");
192
+ function useEnterLeave(open, options) {
193
+ var _a;
194
+ const animated = (_a = options == null ? void 0 : options.animated) != null ? _a : true;
195
+ const ref = (0, import_react2.useRef)(null);
196
+ const [mounted, setMounted] = (0, import_react2.useState)(open);
197
+ const [state, setState] = (0, import_react2.useState)(open ? "entered" : "idle");
198
+ const rafRef = (0, import_react2.useRef)(0);
199
+ (0, import_react2.useEffect)(() => {
200
+ if (open) {
201
+ setMounted(true);
202
+ if (!animated) {
203
+ setState("entered");
204
+ return;
205
+ }
206
+ setState("entering");
207
+ rafRef.current = requestAnimationFrame(() => {
208
+ rafRef.current = requestAnimationFrame(() => {
209
+ setState("entered");
210
+ });
211
+ });
212
+ } else {
213
+ if (!animated) {
214
+ setState("idle");
215
+ setMounted(false);
216
+ return;
217
+ }
218
+ setState(
219
+ (prev) => prev === "entered" || prev === "entering" ? "leaving" : prev
220
+ );
221
+ }
222
+ return () => {
223
+ if (rafRef.current) cancelAnimationFrame(rafRef.current);
224
+ };
225
+ }, [open, animated]);
226
+ (0, import_react2.useEffect)(() => {
227
+ if (state !== "leaving") return;
228
+ let cancelled = false;
229
+ const finish = () => {
230
+ if (cancelled) return;
231
+ setState("idle");
232
+ setMounted(false);
233
+ };
234
+ const el = ref.current;
235
+ if (!el || typeof el.getAnimations !== "function") {
236
+ const raf2 = requestAnimationFrame(finish);
237
+ return () => {
238
+ cancelled = true;
239
+ cancelAnimationFrame(raf2);
240
+ };
241
+ }
242
+ const raf = requestAnimationFrame(() => {
243
+ if (cancelled) return;
244
+ const animations = el.getAnimations();
245
+ if (animations.length === 0) {
246
+ finish();
247
+ return;
248
+ }
249
+ Promise.all(
250
+ animations.map((animation) => animation.finished.catch(() => {
251
+ }))
252
+ ).then(finish);
253
+ });
254
+ return () => {
255
+ cancelled = true;
256
+ cancelAnimationFrame(raf);
257
+ };
258
+ }, [state]);
259
+ const dataAttributes = {};
260
+ if (state === "entering" || state === "entered") {
261
+ dataAttributes["data-enter"] = "";
262
+ }
263
+ if (state === "leaving") {
264
+ dataAttributes["data-leave"] = "";
265
+ }
266
+ return {
267
+ ref,
268
+ mounted,
269
+ dataAttributes,
270
+ state
271
+ };
272
+ }
273
+
274
+ // src/hooks/use-focus-visible.ts
275
+ var import_react3 = require("react");
276
+ var hadKeyboardEvent = true;
277
+ var listenerCount = 0;
278
+ function handleKeyDown(e) {
279
+ if (e.metaKey || e.altKey || e.ctrlKey) return;
280
+ hadKeyboardEvent = true;
281
+ }
282
+ function handlePointerDown() {
283
+ hadKeyboardEvent = false;
284
+ }
285
+ function addGlobalListeners() {
286
+ if (listenerCount === 0 && typeof document !== "undefined") {
287
+ document.addEventListener("keydown", handleKeyDown, true);
288
+ document.addEventListener("pointerdown", handlePointerDown, true);
289
+ document.addEventListener("mousedown", handlePointerDown, true);
290
+ document.addEventListener("touchstart", handlePointerDown, true);
291
+ }
292
+ listenerCount += 1;
293
+ }
294
+ function removeGlobalListeners() {
295
+ listenerCount = Math.max(0, listenerCount - 1);
296
+ if (listenerCount === 0 && typeof document !== "undefined") {
297
+ document.removeEventListener("keydown", handleKeyDown, true);
298
+ document.removeEventListener("pointerdown", handlePointerDown, true);
299
+ document.removeEventListener("mousedown", handlePointerDown, true);
300
+ document.removeEventListener("touchstart", handlePointerDown, true);
301
+ }
302
+ }
303
+ function useFocusVisible() {
304
+ (0, import_react3.useEffect)(() => {
305
+ addGlobalListeners();
306
+ return removeGlobalListeners;
307
+ }, []);
308
+ const onFocus = (0, import_react3.useCallback)((e) => {
309
+ if (hadKeyboardEvent) {
310
+ e.currentTarget.setAttribute("data-focus-visible", "");
311
+ }
312
+ }, []);
313
+ const onBlur = (0, import_react3.useCallback)((e) => {
314
+ e.currentTarget.removeAttribute("data-focus-visible");
315
+ }, []);
316
+ return {
317
+ focusVisibleProps: {
318
+ onFocus,
319
+ onBlur
320
+ }
321
+ };
322
+ }
323
+
324
+ // src/hooks/use-roving-tabindex.ts
325
+ var import_react4 = require("react");
326
+ function useRovingTabindex(options = {}) {
327
+ const {
328
+ orientation = "horizontal",
329
+ loop = false,
330
+ rtl = false,
331
+ columns
332
+ } = options;
333
+ const itemsRef = (0, import_react4.useRef)([]);
334
+ const [activeId, setActiveId] = (0, import_react4.useState)(null);
335
+ const containerRef = (0, import_react4.useRef)(null);
336
+ const seededRef = (0, import_react4.useRef)(false);
337
+ const getEnabledItems = (0, import_react4.useCallback)(() => {
338
+ return itemsRef.current.filter((item) => !item.disabled);
339
+ }, []);
340
+ const register = (0, import_react4.useCallback)(
341
+ (id, element, disabled) => {
342
+ var _a, _b;
343
+ const existing = itemsRef.current.findIndex((item) => item.id === id);
344
+ const activeBecameDisabled = existing >= 0 && id === activeId && !!disabled;
345
+ if (existing >= 0) {
346
+ itemsRef.current[existing] = { id, element, disabled };
347
+ } else {
348
+ itemsRef.current.push({ id, element, disabled });
349
+ }
350
+ if (activeId === null && !seededRef.current && !disabled) {
351
+ seededRef.current = true;
352
+ setActiveId(id);
353
+ } else if (activeBecameDisabled) {
354
+ const next = (_b = (_a = itemsRef.current.find((item) => !item.disabled)) == null ? void 0 : _a.id) != null ? _b : null;
355
+ if (next === null) seededRef.current = false;
356
+ setActiveId(next);
357
+ }
358
+ },
359
+ [activeId]
360
+ );
361
+ const unregister = (0, import_react4.useCallback)(
362
+ (id) => {
363
+ var _a, _b;
364
+ itemsRef.current = itemsRef.current.filter((item) => item.id !== id);
365
+ if (activeId === id) {
366
+ const next = (_b = (_a = getEnabledItems()[0]) == null ? void 0 : _a.id) != null ? _b : null;
367
+ if (next === null) seededRef.current = false;
368
+ setActiveId(next);
369
+ }
370
+ },
371
+ [activeId, getEnabledItems]
372
+ );
373
+ const moveTo = (0, import_react4.useCallback)((id) => {
374
+ setActiveId(id);
375
+ const item = itemsRef.current.find((i) => i.id === id);
376
+ item == null ? void 0 : item.element.focus();
377
+ }, []);
378
+ const moveByOffset = (0, import_react4.useCallback)(
379
+ (offset2) => {
380
+ const enabled = getEnabledItems();
381
+ if (enabled.length === 0) return;
382
+ const currentIndex = enabled.findIndex((item) => item.id === activeId);
383
+ let nextIndex = currentIndex + offset2;
384
+ if (loop) {
385
+ nextIndex = (nextIndex % enabled.length + enabled.length) % enabled.length;
386
+ } else {
387
+ nextIndex = Math.max(0, Math.min(enabled.length - 1, nextIndex));
388
+ }
389
+ moveTo(enabled[nextIndex].id);
390
+ },
391
+ [activeId, getEnabledItems, loop, moveTo]
392
+ );
393
+ const onKeyDown = (0, import_react4.useCallback)(
394
+ (e) => {
395
+ const grid = columns !== void 0 && columns > 0;
396
+ const horizontal = grid || orientation === "horizontal" || orientation === "both";
397
+ const vertical = grid || orientation === "vertical" || orientation === "both";
398
+ const rowOffset = grid ? columns : 1;
399
+ if (vertical && e.key === "ArrowDown") {
400
+ e.preventDefault();
401
+ moveByOffset(rowOffset);
402
+ } else if (vertical && e.key === "ArrowUp") {
403
+ e.preventDefault();
404
+ moveByOffset(-rowOffset);
405
+ } else if (horizontal && e.key === "ArrowRight") {
406
+ e.preventDefault();
407
+ moveByOffset(rtl ? -1 : 1);
408
+ } else if (horizontal && e.key === "ArrowLeft") {
409
+ e.preventDefault();
410
+ moveByOffset(rtl ? 1 : -1);
411
+ } else if (e.key === "Home") {
412
+ e.preventDefault();
413
+ const enabled = getEnabledItems();
414
+ if (enabled.length > 0) moveTo(enabled[0].id);
415
+ } else if (e.key === "End") {
416
+ e.preventDefault();
417
+ const enabled = getEnabledItems();
418
+ if (enabled.length > 0) moveTo(enabled[enabled.length - 1].id);
419
+ }
420
+ },
421
+ [orientation, rtl, columns, moveByOffset, getEnabledItems, moveTo]
422
+ );
423
+ (0, import_react4.useEffect)(() => {
424
+ for (const item of itemsRef.current) {
425
+ if (item.id === activeId) {
426
+ item.element.setAttribute("data-active-item", "");
427
+ } else {
428
+ item.element.removeAttribute("data-active-item");
429
+ }
430
+ }
431
+ }, [activeId]);
432
+ return {
433
+ containerRef,
434
+ containerProps: {
435
+ ref: containerRef,
436
+ onKeyDown
437
+ },
438
+ activeId,
439
+ register,
440
+ unregister,
441
+ moveTo,
442
+ getTabIndex: (id) => id === activeId ? 0 : -1
443
+ };
444
+ }
445
+
446
+ // src/hooks/use-floating.ts
447
+ var import_react5 = require("@floating-ui/react");
448
+ var import_react6 = require("react");
449
+
450
+ // src/internal/state-attrs.ts
451
+ function getStateAttributesProps(attrs) {
452
+ const result = {};
453
+ for (const key in attrs) {
454
+ if (!Object.prototype.hasOwnProperty.call(attrs, key)) continue;
455
+ const value = attrs[key];
456
+ if (value === false || value == null || value === "") continue;
457
+ result[key] = value === true ? "" : String(value);
458
+ }
459
+ return result;
460
+ }
461
+
462
+ // src/hooks/use-floating.ts
463
+ function useFloating(options = {}) {
464
+ var _a, _b, _c, _d, _e, _f;
465
+ const {
466
+ placement = "bottom-start",
467
+ strategy = "absolute",
468
+ gutter,
469
+ sideOffset,
470
+ alignOffset,
471
+ sameWidth = false,
472
+ flip = true,
473
+ lazyFlip = false,
474
+ shift = 8,
475
+ overflowPadding = 12,
476
+ open = false,
477
+ onOpenChange,
478
+ dismiss
479
+ } = options;
480
+ const onOpenChangeRef = (0, import_react6.useRef)(onOpenChange);
481
+ onOpenChangeRef.current = onOpenChange;
482
+ const handleOpenChange = (0, import_react6.useCallback)(
483
+ (next, _event, reason) => {
484
+ var _a2;
485
+ (_a2 = onOpenChangeRef.current) == null ? void 0 : _a2.call(onOpenChangeRef, next, reason);
486
+ },
487
+ []
488
+ );
489
+ const sideOffsetRef = (0, import_react6.useRef)(void 0);
490
+ sideOffsetRef.current = (_a = sideOffset != null ? sideOffset : gutter) != null ? _a : 4;
491
+ const alignOffsetRef = (0, import_react6.useRef)(void 0);
492
+ alignOffsetRef.current = alignOffset;
493
+ const middleware = (0, import_react6.useMemo)(() => {
494
+ const m = [];
495
+ m.push(
496
+ (0, import_react5.offset)((state) => {
497
+ const args = {
498
+ rects: state.rects,
499
+ placement: state.placement
500
+ };
501
+ const so = sideOffsetRef.current;
502
+ const ao = alignOffsetRef.current;
503
+ return {
504
+ mainAxis: typeof so === "function" ? so(args) : so,
505
+ alignmentAxis: ao == null ? void 0 : typeof ao === "function" ? ao(args) : ao
506
+ };
507
+ })
508
+ );
509
+ if (flip) m.push((0, import_react5.flip)({ padding: overflowPadding }));
510
+ if (shift) {
511
+ const shiftPadding = typeof shift === "number" ? shift : 8;
512
+ m.push((0, import_react5.shift)({ padding: shiftPadding }));
513
+ }
514
+ m.push(
515
+ (0, import_react5.size)({
516
+ padding: overflowPadding,
517
+ apply({ rects, elements, availableWidth, availableHeight }) {
518
+ const dpr = typeof window !== "undefined" && window.devicePixelRatio || 1;
519
+ const roundByDpr = (v) => Math.round(v * dpr) / dpr;
520
+ const styles = {
521
+ "--opt-available-width": `${Math.max(0, Math.round(availableWidth))}px`,
522
+ "--opt-available-height": `${Math.max(0, Math.round(availableHeight))}px`,
523
+ "--opt-anchor-width": `${roundByDpr(rects.reference.width)}px`,
524
+ "--opt-anchor-height": `${roundByDpr(rects.reference.height)}px`
525
+ };
526
+ if (sameWidth)
527
+ styles.width = `${roundByDpr(rects.reference.width)}px`;
528
+ Object.assign(elements.floating.style, styles);
529
+ }
530
+ })
531
+ );
532
+ m.push((0, import_react5.hide)({ padding: overflowPadding }));
533
+ return m;
534
+ }, [flip, shift, sameWidth, overflowPadding]);
535
+ const [lockedPlacement, setLockedPlacement] = (0, import_react6.useState)(
536
+ null
537
+ );
538
+ const effectivePlacement = lazyFlip && lockedPlacement ? lockedPlacement : placement;
539
+ const floating = (0, import_react5.useFloating)({
540
+ placement: effectivePlacement,
541
+ strategy,
542
+ middleware,
543
+ whileElementsMounted: open ? import_react5.autoUpdate : void 0,
544
+ open,
545
+ onOpenChange: handleOpenChange
546
+ });
547
+ const dismissConfig = typeof dismiss === "object" ? dismiss : {};
548
+ (0, import_react5.useDismiss)(floating.context, {
549
+ enabled: dismiss !== void 0 && dismiss !== false,
550
+ outsidePress: (_b = dismissConfig.outsidePress) != null ? _b : true,
551
+ escapeKey: (_c = dismissConfig.escapeKey) != null ? _c : true,
552
+ ancestorScroll: (_d = dismissConfig.ancestorScroll) != null ? _d : false
553
+ });
554
+ const isPositioned = floating.isPositioned;
555
+ (0, import_react6.useEffect)(() => {
556
+ if (!open) {
557
+ setLockedPlacement(null);
558
+ }
559
+ }, [open]);
560
+ (0, import_react6.useEffect)(() => {
561
+ if (open && lazyFlip && isPositioned && lockedPlacement === null) {
562
+ setLockedPlacement(floating.placement);
563
+ }
564
+ }, [open, lazyFlip, isPositioned, floating.placement, lockedPlacement]);
565
+ const [side, alignPart] = floating.placement.split("-");
566
+ const align = alignPart != null ? alignPart : "center";
567
+ const anchorHidden = (_f = (_e = floating.middlewareData.hide) == null ? void 0 : _e.referenceHidden) != null ? _f : false;
568
+ return {
569
+ refs: floating.refs,
570
+ floatingStyles: floating.floatingStyles,
571
+ placement: floating.placement,
572
+ side,
573
+ align,
574
+ isPositioned,
575
+ anchorHidden,
576
+ context: floating.context,
577
+ getReferenceProps: () => ({
578
+ ref: floating.refs.setReference
579
+ }),
580
+ getFloatingProps: () => ({
581
+ ref: floating.refs.setFloating,
582
+ style: __spreadValues(__spreadValues({
583
+ // Seed the available-space caps so first-frame CSS
584
+ // (max-height: var(--opt-available-height)) resolves before the size
585
+ // middleware runs — the imperative apply() then refines these.
586
+ "--opt-available-width": "100vw",
587
+ "--opt-available-height": "100vh"
588
+ }, floating.floatingStyles), isPositioned ? null : { opacity: 0 })
589
+ }),
590
+ /**
591
+ * `data-open`/`data-closed`/`data-side`/`data-align`/`data-anchor-hidden`
592
+ * for the positioner. Additive — spread onto the panel alongside existing
593
+ * data attributes so Core can target open state, resolved side, and anchor
594
+ * visibility with CSS only.
595
+ */
596
+ getPositionerStateProps: (isOpen) => getStateAttributesProps({
597
+ "data-open": isOpen,
598
+ "data-closed": !isOpen,
599
+ "data-side": side,
600
+ "data-align": align,
601
+ "data-anchor-hidden": anchorHidden
602
+ })
603
+ };
604
+ }
605
+
606
+ // src/hooks/use-id.ts
607
+ var import_react7 = require("react");
608
+ function useId(providedId) {
609
+ const generatedId = (0, import_react7.useId)();
610
+ return providedId != null ? providedId : generatedId;
611
+ }
612
+
613
+ // src/hooks/use-focusable-when-disabled.ts
614
+ function useFocusableWhenDisabled({
615
+ disabled = false,
616
+ focusableWhenDisabled = false,
617
+ isNativeButton = true,
618
+ tabIndex
619
+ }) {
620
+ const inert = disabled && focusableWhenDisabled;
621
+ return {
622
+ // Emit native `disabled` only when NOT keeping the element focusable.
623
+ disabled: isNativeButton ? disabled && !focusableWhenDisabled : void 0,
624
+ "aria-disabled": inert ? true : void 0,
625
+ // Native buttons are focusable by default; a non-native element needs an
626
+ // explicit tabIndex to remain reachable while disabled.
627
+ tabIndex: !isNativeButton && inert ? tabIndex != null ? tabIndex : 0 : tabIndex
628
+ };
629
+ }
630
+
631
+ // src/hooks/use-scroll-into-view.ts
632
+ var import_react8 = require("react");
633
+ function useScrollActiveDescendantIntoView(activeId) {
634
+ (0, import_react8.useEffect)(() => {
635
+ if (!activeId) return;
636
+ const el = document.getElementById(activeId);
637
+ if (el && typeof el.scrollIntoView === "function") {
638
+ el.scrollIntoView({ block: "nearest", inline: "nearest" });
639
+ }
640
+ }, [activeId]);
641
+ }
642
+
643
+ // src/primitives/disclosure.tsx
644
+ var import_react9 = require("react");
645
+ var import_jsx_runtime = require("react/jsx-runtime");
646
+ var DisclosureContext = (0, import_react9.createContext)(null);
647
+ function useDisclosureContext() {
648
+ const ctx = (0, import_react9.useContext)(DisclosureContext);
649
+ if (!ctx)
650
+ throw new Error("Disclosure components must be used within DisclosureRoot");
651
+ return ctx;
652
+ }
653
+ function DisclosureRoot({
654
+ children,
655
+ open: controlledOpen,
656
+ defaultOpen = false,
657
+ onOpenChange,
658
+ setOpen: setOpenDeprecated,
659
+ animated = true
660
+ }) {
661
+ const [open, setOpen] = useControllableState(
662
+ defaultOpen,
663
+ controlledOpen,
664
+ onOpenChange != null ? onOpenChange : setOpenDeprecated
665
+ );
666
+ const baseId = useId();
667
+ const contentId = `${baseId}-content`;
668
+ const triggerId = `${baseId}-trigger`;
669
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
670
+ DisclosureContext.Provider,
671
+ {
672
+ value: { open, setOpen, contentId, triggerId, animated },
673
+ children
674
+ }
675
+ );
676
+ }
677
+ function DisclosureTrigger(_a) {
678
+ var _b = _a, {
679
+ onClick
680
+ } = _b, props = __objRest(_b, [
681
+ "onClick"
682
+ ]);
683
+ const { open, setOpen, contentId, triggerId } = useDisclosureContext();
684
+ const handleClick = (0, import_react9.useCallback)(
685
+ (e) => {
686
+ setOpen(!open);
687
+ onClick == null ? void 0 : onClick(e);
688
+ },
689
+ [open, setOpen, onClick]
690
+ );
691
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
692
+ "button",
693
+ __spreadValues({
694
+ type: "button",
695
+ id: triggerId,
696
+ "aria-expanded": open,
697
+ "aria-controls": contentId,
698
+ onClick: handleClick
699
+ }, props)
700
+ );
701
+ }
702
+ function DisclosureContent(_a) {
703
+ var _b = _a, {
704
+ hiddenUntilFound = false,
705
+ style
706
+ } = _b, props = __objRest(_b, [
707
+ "hiddenUntilFound",
708
+ "style"
709
+ ]);
710
+ const { open, setOpen, contentId, triggerId, animated } = useDisclosureContext();
711
+ const { ref, mounted, dataAttributes } = useEnterLeave(open, {
712
+ animated: animated && !hiddenUntilFound
713
+ });
714
+ const innerRef = (0, import_react9.useRef)(null);
715
+ (0, import_react9.useEffect)(() => {
716
+ if (innerRef.current) {
717
+ ref.current = innerRef.current;
718
+ }
719
+ }, [ref]);
720
+ (0, import_react9.useEffect)(() => {
721
+ const el = innerRef.current;
722
+ if (!el || !hiddenUntilFound) return;
723
+ const onBeforeMatch = () => setOpen(true);
724
+ el.addEventListener("beforematch", onBeforeMatch);
725
+ return () => el.removeEventListener("beforematch", onBeforeMatch);
726
+ }, [hiddenUntilFound, setOpen]);
727
+ (0, import_react9.useEffect)(() => {
728
+ const el = innerRef.current;
729
+ if (!el || !hiddenUntilFound) return;
730
+ if (open) el.removeAttribute("hidden");
731
+ else el.setAttribute("hidden", "until-found");
732
+ }, [open, hiddenUntilFound]);
733
+ if (hiddenUntilFound) {
734
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
735
+ "div",
736
+ __spreadValues({
737
+ ref: innerRef,
738
+ id: contentId,
739
+ role: "region",
740
+ "aria-labelledby": triggerId,
741
+ "data-state": open ? "open" : "closed",
742
+ style
743
+ }, props)
744
+ );
745
+ }
746
+ if (!mounted) return null;
747
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
748
+ "div",
749
+ __spreadValues(__spreadValues({
750
+ ref: innerRef,
751
+ id: contentId,
752
+ role: "region",
753
+ "aria-labelledby": triggerId,
754
+ style
755
+ }, dataAttributes), props)
756
+ );
757
+ }
758
+
759
+ // src/primitives/button.tsx
760
+ var import_react10 = require("react");
761
+ var import_jsx_runtime2 = require("react/jsx-runtime");
762
+ var Button = (0, import_react10.forwardRef)(
763
+ (_a, ref) => {
764
+ var _b = _a, {
765
+ type = "button",
766
+ clickOnEnter,
767
+ clickOnSpace,
768
+ focusableWhenDisabled = false,
769
+ disabled = false,
770
+ onKeyDown,
771
+ onClick
772
+ } = _b, props = __objRest(_b, [
773
+ "type",
774
+ "clickOnEnter",
775
+ "clickOnSpace",
776
+ "focusableWhenDisabled",
777
+ "disabled",
778
+ "onKeyDown",
779
+ "onClick"
780
+ ]);
781
+ const focusableProps = useFocusableWhenDisabled({
782
+ disabled,
783
+ focusableWhenDisabled
784
+ });
785
+ const inert = disabled && focusableWhenDisabled;
786
+ const handleKeyDown2 = (0, import_react10.useCallback)(
787
+ (e) => {
788
+ if (inert) {
789
+ if (e.key === "Enter" || e.key === " ") {
790
+ e.preventDefault();
791
+ return;
792
+ }
793
+ } else {
794
+ if (clickOnEnter === false && e.key === "Enter") {
795
+ e.preventDefault();
796
+ }
797
+ if (clickOnSpace === false && e.key === " ") {
798
+ e.preventDefault();
799
+ }
800
+ }
801
+ onKeyDown == null ? void 0 : onKeyDown(e);
802
+ },
803
+ [inert, clickOnEnter, clickOnSpace, onKeyDown]
804
+ );
805
+ const handleClick = (0, import_react10.useCallback)(
806
+ (e) => {
807
+ if (inert) {
808
+ e.preventDefault();
809
+ e.stopPropagation();
810
+ return;
811
+ }
812
+ onClick == null ? void 0 : onClick(e);
813
+ },
814
+ [inert, onClick]
815
+ );
816
+ const needsKeyHandler = inert || clickOnEnter === false || clickOnSpace === false;
817
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
818
+ "button",
819
+ __spreadProps(__spreadValues(__spreadValues({
820
+ ref,
821
+ type
822
+ }, focusableProps), props), {
823
+ onKeyDown: needsKeyHandler ? handleKeyDown2 : onKeyDown,
824
+ onClick: handleClick
825
+ })
826
+ );
827
+ }
828
+ );
829
+ Button.displayName = "Button";
830
+
831
+ // src/primitives/dialog.tsx
832
+ var import_react11 = require("react");
833
+ var import_jsx_runtime3 = require("react/jsx-runtime");
834
+ var DialogContext = (0, import_react11.createContext)(null);
835
+ function useDialogContext() {
836
+ const ctx = (0, import_react11.useContext)(DialogContext);
837
+ if (!ctx) throw new Error("Dialog components must be used within DialogRoot");
838
+ return ctx;
839
+ }
840
+ function useDialogClose() {
841
+ const { setOpen } = useDialogContext();
842
+ return () => setOpen(false);
843
+ }
844
+ function DialogRoot({
845
+ children,
846
+ open: controlledOpen,
847
+ defaultOpen = false,
848
+ onOpenChange,
849
+ setOpen: setOpenDeprecated,
850
+ animated = true
851
+ }) {
852
+ const [open, setOpen] = useControllableState(
853
+ defaultOpen,
854
+ controlledOpen,
855
+ onOpenChange != null ? onOpenChange : setOpenDeprecated
856
+ );
857
+ const baseId = useId();
858
+ const headingId = `${baseId}-heading`;
859
+ const descriptionId = `${baseId}-description`;
860
+ const dialogRef = (0, import_react11.useRef)(null);
861
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
862
+ DialogContext.Provider,
863
+ {
864
+ value: { open, setOpen, headingId, descriptionId, animated, dialogRef },
865
+ children
866
+ }
867
+ );
868
+ }
869
+ var DialogDisclosure = (0, import_react11.forwardRef)((_a, ref) => {
870
+ var _b = _a, { onClick } = _b, props = __objRest(_b, ["onClick"]);
871
+ const { setOpen } = useDialogContext();
872
+ const handleClick = (0, import_react11.useCallback)(
873
+ (e) => {
874
+ setOpen(true);
875
+ onClick == null ? void 0 : onClick(e);
876
+ },
877
+ [setOpen, onClick]
878
+ );
879
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", __spreadValues({ ref, type: "button", onClick: handleClick }, props));
880
+ });
881
+ DialogDisclosure.displayName = "DialogDisclosure";
882
+ var DialogPanel = (0, import_react11.forwardRef)(
883
+ (_a, forwardedRef) => {
884
+ var _b = _a, {
885
+ backdrop: _backdrop,
886
+ dismissOnBackdrop = true,
887
+ dismissOnEscape = true,
888
+ children,
889
+ onClick
890
+ } = _b, props = __objRest(_b, [
891
+ "backdrop",
892
+ "dismissOnBackdrop",
893
+ "dismissOnEscape",
894
+ "children",
895
+ "onClick"
896
+ ]);
897
+ const { open, setOpen, headingId, descriptionId, animated, dialogRef } = useDialogContext();
898
+ const {
899
+ ref: enterLeaveRef,
900
+ mounted,
901
+ dataAttributes
902
+ } = useEnterLeave(open, { animated });
903
+ const lastFocusedRef = (0, import_react11.useRef)(null);
904
+ const wasMountedRef = (0, import_react11.useRef)(false);
905
+ (0, import_react11.useEffect)(() => {
906
+ const dialog = dialogRef.current;
907
+ if (!dialog) return;
908
+ if (mounted && !dialog.open) {
909
+ lastFocusedRef.current = document.activeElement;
910
+ dialog.showModal();
911
+ }
912
+ }, [mounted, dialogRef]);
913
+ (0, import_react11.useEffect)(() => {
914
+ var _a2;
915
+ if (mounted) {
916
+ wasMountedRef.current = true;
917
+ } else if (wasMountedRef.current) {
918
+ wasMountedRef.current = false;
919
+ (_a2 = lastFocusedRef.current) == null ? void 0 : _a2.focus();
920
+ lastFocusedRef.current = null;
921
+ }
922
+ }, [mounted]);
923
+ const mergedRef = (0, import_react11.useCallback)(
924
+ (node) => {
925
+ dialogRef.current = node;
926
+ enterLeaveRef.current = node;
927
+ if (typeof forwardedRef === "function") forwardedRef(node);
928
+ else if (forwardedRef) forwardedRef.current = node;
929
+ },
930
+ [dialogRef, enterLeaveRef, forwardedRef]
931
+ );
932
+ (0, import_react11.useEffect)(() => {
933
+ const dialog = dialogRef.current;
934
+ if (!dialog) return;
935
+ const handleCancel = (e) => {
936
+ e.preventDefault();
937
+ if (dismissOnEscape) setOpen(false);
938
+ };
939
+ dialog.addEventListener("cancel", handleCancel);
940
+ return () => dialog.removeEventListener("cancel", handleCancel);
941
+ }, [dialogRef, setOpen, dismissOnEscape]);
942
+ const handleClick = (0, import_react11.useCallback)(
943
+ (e) => {
944
+ if (dismissOnBackdrop && e.target === e.currentTarget) {
945
+ setOpen(false);
946
+ }
947
+ onClick == null ? void 0 : onClick(e);
948
+ },
949
+ [setOpen, onClick, dismissOnBackdrop]
950
+ );
951
+ if (!mounted) return null;
952
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
953
+ "dialog",
954
+ __spreadProps(__spreadValues(__spreadValues({
955
+ ref: mergedRef,
956
+ "aria-labelledby": headingId,
957
+ "aria-describedby": descriptionId,
958
+ onClick: handleClick
959
+ }, dataAttributes), props), {
960
+ children
961
+ })
962
+ );
963
+ }
964
+ );
965
+ DialogPanel.displayName = "DialogPanel";
966
+ var AlertDialogPanel = (0, import_react11.forwardRef)(function AlertDialogPanel2(props, ref) {
967
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
968
+ DialogPanel,
969
+ __spreadValues({
970
+ ref,
971
+ role: "alertdialog",
972
+ dismissOnBackdrop: false,
973
+ dismissOnEscape: false
974
+ }, props)
975
+ );
976
+ });
977
+ function DialogHeading(props) {
978
+ const { headingId } = useDialogContext();
979
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h2", __spreadValues({ id: headingId }, props));
980
+ }
981
+ function DialogDescription(props) {
982
+ const { descriptionId } = useDialogContext();
983
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", __spreadValues({ id: descriptionId }, props));
984
+ }
985
+ var DialogDismiss = (0, import_react11.forwardRef)(
986
+ (_a, ref) => {
987
+ var _b = _a, { onClick } = _b, props = __objRest(_b, ["onClick"]);
988
+ const { setOpen } = useDialogContext();
989
+ const handleClick = (0, import_react11.useCallback)(
990
+ (e) => {
991
+ setOpen(false);
992
+ onClick == null ? void 0 : onClick(e);
993
+ },
994
+ [setOpen, onClick]
995
+ );
996
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", __spreadValues({ ref, type: "button", onClick: handleClick }, props));
997
+ }
998
+ );
999
+ DialogDismiss.displayName = "DialogDismiss";
1000
+
1001
+ // src/primitives/tabs.tsx
1002
+ var import_react12 = require("react");
1003
+ var import_jsx_runtime4 = require("react/jsx-runtime");
1004
+ function nextEnabledTabId(tabs, currentId, delta) {
1005
+ const enabled = tabs.filter((t) => !t.disabled);
1006
+ if (enabled.length === 0) return null;
1007
+ const idx = enabled.findIndex((t) => t.id === currentId);
1008
+ if (idx < 0) return enabled[0].id;
1009
+ const n = enabled.length;
1010
+ const next = ((idx + delta) % n + n) % n;
1011
+ return enabled[next].id;
1012
+ }
1013
+ var TabsContext = (0, import_react12.createContext)(null);
1014
+ function useTabsContext() {
1015
+ const ctx = (0, import_react12.useContext)(TabsContext);
1016
+ if (!ctx) throw new Error("Tabs components must be used within TabsRoot");
1017
+ return ctx;
1018
+ }
1019
+ function TabsRoot({
1020
+ children,
1021
+ selectedId: controlledId,
1022
+ defaultSelectedId = "",
1023
+ onSelectedIdChange,
1024
+ setSelectedId: setSelectedIdDeprecated,
1025
+ orientation = "horizontal"
1026
+ }) {
1027
+ const [selectedId, setSelectedId] = useControllableState(
1028
+ defaultSelectedId,
1029
+ controlledId,
1030
+ onSelectedIdChange != null ? onSelectedIdChange : setSelectedIdDeprecated
1031
+ );
1032
+ const baseId = useId();
1033
+ const tabs = (0, import_react12.useRef)([]);
1034
+ const registerTab = (0, import_react12.useCallback)((id, disabled) => {
1035
+ const existing = tabs.current.findIndex((t) => t.id === id);
1036
+ if (existing >= 0) tabs.current[existing] = { id, disabled };
1037
+ else tabs.current.push({ id, disabled });
1038
+ }, []);
1039
+ const unregisterTab = (0, import_react12.useCallback)((id) => {
1040
+ tabs.current = tabs.current.filter((t) => t.id !== id);
1041
+ }, []);
1042
+ (0, import_react12.useLayoutEffect)(() => {
1043
+ if (!selectedId) {
1044
+ const first = tabs.current.find((t) => !t.disabled);
1045
+ if (first) setSelectedId(first.id);
1046
+ }
1047
+ }, [selectedId, setSelectedId]);
1048
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1049
+ TabsContext.Provider,
1050
+ {
1051
+ value: {
1052
+ selectedId,
1053
+ setSelectedId,
1054
+ baseId,
1055
+ orientation,
1056
+ registerTab,
1057
+ unregisterTab,
1058
+ tabs
1059
+ },
1060
+ children
1061
+ }
1062
+ );
1063
+ }
1064
+ function TabList(_a) {
1065
+ var _b = _a, {
1066
+ role = "tablist",
1067
+ onKeyDown
1068
+ } = _b, props = __objRest(_b, [
1069
+ "role",
1070
+ "onKeyDown"
1071
+ ]);
1072
+ const { selectedId, setSelectedId, tabs, orientation } = useTabsContext();
1073
+ const handleKeyDown2 = (0, import_react12.useCallback)(
1074
+ (e) => {
1075
+ var _a2, _b2, _c, _d, _e;
1076
+ const prevKey = orientation === "vertical" ? "ArrowUp" : "ArrowLeft";
1077
+ const nextKey = orientation === "vertical" ? "ArrowDown" : "ArrowRight";
1078
+ let nextId = null;
1079
+ if (e.key === nextKey) {
1080
+ e.preventDefault();
1081
+ nextId = nextEnabledTabId(tabs.current, selectedId, 1);
1082
+ } else if (e.key === prevKey) {
1083
+ e.preventDefault();
1084
+ nextId = nextEnabledTabId(tabs.current, selectedId, -1);
1085
+ } else if (e.key === "Home") {
1086
+ e.preventDefault();
1087
+ nextId = (_b2 = (_a2 = tabs.current.find((t) => !t.disabled)) == null ? void 0 : _a2.id) != null ? _b2 : null;
1088
+ } else if (e.key === "End") {
1089
+ e.preventDefault();
1090
+ nextId = (_d = (_c = [...tabs.current].reverse().find((t) => !t.disabled)) == null ? void 0 : _c.id) != null ? _d : null;
1091
+ }
1092
+ if (nextId) {
1093
+ setSelectedId(nextId);
1094
+ (_e = document.getElementById(`${nextId}-tab`)) == null ? void 0 : _e.focus();
1095
+ }
1096
+ onKeyDown == null ? void 0 : onKeyDown(e);
1097
+ },
1098
+ [selectedId, setSelectedId, tabs, orientation, onKeyDown]
1099
+ );
1100
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1101
+ "div",
1102
+ __spreadValues({
1103
+ role,
1104
+ "aria-orientation": orientation,
1105
+ onKeyDown: handleKeyDown2
1106
+ }, props)
1107
+ );
1108
+ }
1109
+ function Tab(_a) {
1110
+ var _b = _a, { id, disabled, onClick } = _b, props = __objRest(_b, ["id", "disabled", "onClick"]);
1111
+ const { selectedId, setSelectedId, registerTab, unregisterTab } = useTabsContext();
1112
+ const isSelected = selectedId === id;
1113
+ (0, import_react12.useLayoutEffect)(() => {
1114
+ registerTab(id, disabled);
1115
+ return () => unregisterTab(id);
1116
+ }, [id, disabled, registerTab, unregisterTab]);
1117
+ const handleClick = (0, import_react12.useCallback)(
1118
+ (e) => {
1119
+ if (!disabled) setSelectedId(id);
1120
+ onClick == null ? void 0 : onClick(e);
1121
+ },
1122
+ [id, disabled, setSelectedId, onClick]
1123
+ );
1124
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1125
+ "button",
1126
+ __spreadValues({
1127
+ type: "button",
1128
+ role: "tab",
1129
+ id: `${id}-tab`,
1130
+ "aria-selected": isSelected,
1131
+ "aria-controls": isSelected ? `${id}-panel` : void 0,
1132
+ tabIndex: isSelected ? 0 : -1,
1133
+ disabled,
1134
+ "data-active-item": isSelected ? "" : void 0,
1135
+ onClick: handleClick
1136
+ }, props)
1137
+ );
1138
+ }
1139
+ function TabPanel(_a) {
1140
+ var _b = _a, { tabId } = _b, props = __objRest(_b, ["tabId"]);
1141
+ const { selectedId } = useTabsContext();
1142
+ const isSelected = selectedId === tabId;
1143
+ if (!isSelected) return null;
1144
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1145
+ "div",
1146
+ __spreadValues({
1147
+ role: "tabpanel",
1148
+ id: `${tabId}-panel`,
1149
+ "aria-labelledby": `${tabId}-tab`,
1150
+ tabIndex: 0
1151
+ }, props)
1152
+ );
1153
+ }
1154
+
1155
+ // src/primitives/radio-group.tsx
1156
+ var import_react13 = require("react");
1157
+ var import_jsx_runtime5 = require("react/jsx-runtime");
1158
+ var RadioGroupContext = (0, import_react13.createContext)(null);
1159
+ function useRadioGroupContext() {
1160
+ return (0, import_react13.useContext)(RadioGroupContext);
1161
+ }
1162
+ function RadioGroupRoot(_a) {
1163
+ var _b = _a, {
1164
+ children,
1165
+ name: providedName,
1166
+ value: controlledValue,
1167
+ defaultValue = "",
1168
+ onValueChange,
1169
+ onChange,
1170
+ disabled = false,
1171
+ orientation = "vertical"
1172
+ } = _b, props = __objRest(_b, [
1173
+ "children",
1174
+ "name",
1175
+ "value",
1176
+ "defaultValue",
1177
+ "onValueChange",
1178
+ "onChange",
1179
+ "disabled",
1180
+ "orientation"
1181
+ ]);
1182
+ const [value, setValue] = useControllableState(
1183
+ defaultValue,
1184
+ controlledValue,
1185
+ onValueChange != null ? onValueChange : onChange
1186
+ );
1187
+ const generatedName = (0, import_react13.useId)().replace(/:/g, "");
1188
+ const name = providedName != null ? providedName : `radio-group-${generatedName}`;
1189
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1190
+ RadioGroupContext.Provider,
1191
+ {
1192
+ value: { name, value, setValue, disabled, orientation },
1193
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", __spreadProps(__spreadValues({ role: "radiogroup", "aria-orientation": orientation }, props), { children }))
1194
+ }
1195
+ );
1196
+ }
1197
+ var Radio = (0, import_react13.forwardRef)(
1198
+ (_a, ref) => {
1199
+ var _b = _a, { value, disabled: itemDisabled, className } = _b, props = __objRest(_b, ["value", "disabled", "className"]);
1200
+ const group = useRadioGroupContext();
1201
+ if (!group) throw new Error("Radio must be used within RadioGroupRoot");
1202
+ const {
1203
+ name,
1204
+ value: groupValue,
1205
+ setValue,
1206
+ disabled: groupDisabled
1207
+ } = group;
1208
+ const isDisabled = itemDisabled != null ? itemDisabled : groupDisabled;
1209
+ const isChecked = groupValue === value;
1210
+ const handleChange = (0, import_react13.useCallback)(() => {
1211
+ if (!isDisabled) setValue(value);
1212
+ }, [isDisabled, setValue, value]);
1213
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1214
+ "input",
1215
+ __spreadValues({
1216
+ ref,
1217
+ type: "radio",
1218
+ name,
1219
+ value,
1220
+ checked: isChecked,
1221
+ disabled: isDisabled,
1222
+ onChange: handleChange,
1223
+ className
1224
+ }, props)
1225
+ );
1226
+ }
1227
+ );
1228
+ Radio.displayName = "Radio";
1229
+
1230
+ // src/primitives/tooltip.tsx
1231
+ var import_react15 = __toESM(require("react"), 1);
1232
+
1233
+ // src/internal/merge-props.ts
1234
+ var EVENT_HANDLER = /^on[A-Z]/;
1235
+ function mergeProps(...parts) {
1236
+ const result = {};
1237
+ for (const part of parts) {
1238
+ if (!part) continue;
1239
+ for (const key in part) {
1240
+ if (!Object.prototype.hasOwnProperty.call(part, key)) continue;
1241
+ const value = part[key];
1242
+ const existing = result[key];
1243
+ if (EVENT_HANDLER.test(key) && typeof value === "function" && typeof existing === "function") {
1244
+ const a = existing;
1245
+ const b = value;
1246
+ result[key] = (...args) => {
1247
+ a(...args);
1248
+ return b(...args);
1249
+ };
1250
+ } else if (key === "className") {
1251
+ const merged = [existing, value].filter(Boolean).join(" ");
1252
+ result[key] = merged || void 0;
1253
+ } else if (key === "style" && existing && typeof existing === "object" && value && typeof value === "object") {
1254
+ result[key] = __spreadValues(__spreadValues({}, existing), value);
1255
+ } else {
1256
+ result[key] = value;
1257
+ }
1258
+ }
1259
+ }
1260
+ return result;
1261
+ }
1262
+ function mergeRefs(...refs) {
1263
+ return (value) => {
1264
+ for (const ref of refs) {
1265
+ if (typeof ref === "function") {
1266
+ ref(value);
1267
+ } else if (ref != null) {
1268
+ ref.current = value;
1269
+ }
1270
+ }
1271
+ };
1272
+ }
1273
+
1274
+ // src/internal/overlay-portal.tsx
1275
+ var import_react14 = require("@floating-ui/react");
1276
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1277
+ function OverlayPortal({
1278
+ portal,
1279
+ portalRoot,
1280
+ children
1281
+ }) {
1282
+ if (!portal) return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_jsx_runtime6.Fragment, { children });
1283
+ if (typeof portalRoot === "string") {
1284
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react14.FloatingPortal, { id: portalRoot, children });
1285
+ }
1286
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react14.FloatingPortal, { root: portalRoot != null ? portalRoot : void 0, children });
1287
+ }
1288
+
1289
+ // src/primitives/tooltip.tsx
1290
+ var import_jsx_runtime7 = require("react/jsx-runtime");
1291
+ function mergeAriaDescribedBy(...values) {
1292
+ const ids = values.flatMap(
1293
+ (value) => typeof value === "string" ? value.trim().split(/\s+/) : []
1294
+ );
1295
+ const uniqueIds = [...new Set(ids.filter(Boolean))];
1296
+ return uniqueIds.length > 0 ? uniqueIds.join(" ") : void 0;
1297
+ }
1298
+ var TooltipContext = (0, import_react15.createContext)(null);
1299
+ function useTooltipContext() {
1300
+ const ctx = (0, import_react15.useContext)(TooltipContext);
1301
+ if (!ctx)
1302
+ throw new Error("Tooltip components must be used within TooltipProvider");
1303
+ return ctx;
1304
+ }
1305
+ function TooltipProvider({
1306
+ children,
1307
+ timeout,
1308
+ showTimeout = 700,
1309
+ hideTimeout = 300,
1310
+ placement = "top",
1311
+ animated = true,
1312
+ portal = false,
1313
+ portalRoot = null
1314
+ }) {
1315
+ const [open, setOpen] = (0, import_react15.useState)(false);
1316
+ const tooltipId = useId();
1317
+ const showDelay = timeout != null ? timeout : showTimeout;
1318
+ const showTimerRef = (0, import_react15.useRef)(void 0);
1319
+ const hideTimerRef = (0, import_react15.useRef)(void 0);
1320
+ const { getReferenceProps: getFloatRefProps, getFloatingProps } = useFloating(
1321
+ {
1322
+ placement,
1323
+ gutter: 8,
1324
+ open
1325
+ }
1326
+ );
1327
+ const show = (0, import_react15.useCallback)(() => {
1328
+ clearTimeout(hideTimerRef.current);
1329
+ showTimerRef.current = setTimeout(() => setOpen(true), showDelay);
1330
+ }, [showDelay]);
1331
+ const hide = (0, import_react15.useCallback)(() => {
1332
+ clearTimeout(showTimerRef.current);
1333
+ hideTimerRef.current = setTimeout(() => setOpen(false), hideTimeout);
1334
+ }, [hideTimeout]);
1335
+ (0, import_react15.useEffect)(() => {
1336
+ return () => {
1337
+ clearTimeout(showTimerRef.current);
1338
+ clearTimeout(hideTimerRef.current);
1339
+ };
1340
+ }, []);
1341
+ (0, import_react15.useEffect)(() => {
1342
+ if (!open) return;
1343
+ const handler = (e) => {
1344
+ if (e.key === "Escape") {
1345
+ clearTimeout(showTimerRef.current);
1346
+ clearTimeout(hideTimerRef.current);
1347
+ setOpen(false);
1348
+ }
1349
+ };
1350
+ document.addEventListener("keydown", handler);
1351
+ return () => document.removeEventListener("keydown", handler);
1352
+ }, [open]);
1353
+ const getReferenceProps = (0, import_react15.useCallback)(() => {
1354
+ return __spreadProps(__spreadValues({}, getFloatRefProps()), {
1355
+ "aria-describedby": open ? tooltipId : void 0,
1356
+ onMouseEnter: show,
1357
+ onMouseLeave: hide,
1358
+ onFocus: show,
1359
+ onBlur: hide
1360
+ });
1361
+ }, [getFloatRefProps, open, tooltipId, show, hide]);
1362
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1363
+ TooltipContext.Provider,
1364
+ {
1365
+ value: {
1366
+ open,
1367
+ setOpen,
1368
+ tooltipId,
1369
+ show,
1370
+ hide,
1371
+ animated,
1372
+ portal,
1373
+ portalRoot,
1374
+ getReferenceProps,
1375
+ getFloatingProps
1376
+ },
1377
+ children
1378
+ }
1379
+ );
1380
+ }
1381
+ var TooltipAnchor = (0, import_react15.forwardRef)(
1382
+ (_a, ref) => {
1383
+ var _b = _a, { children, render, "aria-describedby": ariaDescribedBy } = _b, props = __objRest(_b, ["children", "render", "aria-describedby"]);
1384
+ const { getReferenceProps } = useTooltipContext();
1385
+ const _a2 = getReferenceProps(), {
1386
+ ref: referenceRef,
1387
+ "aria-describedby": referenceDescribedBy
1388
+ } = _a2, referenceProps = __objRest(_a2, [
1389
+ "ref",
1390
+ "aria-describedby"
1391
+ ]);
1392
+ if (render) {
1393
+ const renderProps = render.props;
1394
+ const renderRef = renderProps.ref;
1395
+ const mergedProps2 = mergeProps(renderProps, props, referenceProps);
1396
+ return import_react15.default.cloneElement(render, __spreadProps(__spreadValues({}, mergedProps2), {
1397
+ "aria-describedby": mergeAriaDescribedBy(
1398
+ renderProps["aria-describedby"],
1399
+ ariaDescribedBy,
1400
+ referenceDescribedBy
1401
+ ),
1402
+ ref: mergeRefs(renderRef, ref, referenceRef)
1403
+ }));
1404
+ }
1405
+ const mergedProps = mergeProps(props, referenceProps);
1406
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1407
+ "div",
1408
+ __spreadProps(__spreadValues({
1409
+ ref: mergeRefs(
1410
+ ref,
1411
+ referenceRef
1412
+ )
1413
+ }, mergedProps), {
1414
+ "aria-describedby": mergeAriaDescribedBy(
1415
+ ariaDescribedBy,
1416
+ referenceDescribedBy
1417
+ ),
1418
+ children
1419
+ })
1420
+ );
1421
+ }
1422
+ );
1423
+ TooltipAnchor.displayName = "TooltipAnchor";
1424
+ function Tooltip(_a) {
1425
+ var _b = _a, {
1426
+ children,
1427
+ onMouseEnter,
1428
+ onMouseLeave
1429
+ } = _b, props = __objRest(_b, [
1430
+ "children",
1431
+ "onMouseEnter",
1432
+ "onMouseLeave"
1433
+ ]);
1434
+ const {
1435
+ open,
1436
+ tooltipId,
1437
+ show,
1438
+ hide,
1439
+ animated,
1440
+ portal,
1441
+ portalRoot,
1442
+ getFloatingProps
1443
+ } = useTooltipContext();
1444
+ const { mounted, dataAttributes, ref } = useEnterLeave(open, { animated });
1445
+ const floatingProps = getFloatingProps();
1446
+ if (!mounted) return null;
1447
+ const node = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1448
+ "div",
1449
+ __spreadProps(__spreadValues(__spreadValues({
1450
+ ref: (n) => {
1451
+ ref.current = n;
1452
+ if (floatingProps.ref && typeof floatingProps.ref === "function") {
1453
+ floatingProps.ref(n);
1454
+ }
1455
+ },
1456
+ id: tooltipId,
1457
+ role: "tooltip",
1458
+ style: floatingProps.style,
1459
+ onMouseEnter: (e) => {
1460
+ show();
1461
+ onMouseEnter == null ? void 0 : onMouseEnter(e);
1462
+ },
1463
+ onMouseLeave: (e) => {
1464
+ hide();
1465
+ onMouseLeave == null ? void 0 : onMouseLeave(e);
1466
+ }
1467
+ }, dataAttributes), props), {
1468
+ children
1469
+ })
1470
+ );
1471
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(OverlayPortal, { portal, portalRoot, children: node });
1472
+ }
1473
+
1474
+ // src/primitives/popover.tsx
1475
+ var import_react16 = require("react");
1476
+ var import_react17 = require("@floating-ui/react");
1477
+ var import_jsx_runtime8 = require("react/jsx-runtime");
1478
+ var PopoverContext = (0, import_react16.createContext)(null);
1479
+ function usePopoverContext() {
1480
+ const ctx = (0, import_react16.useContext)(PopoverContext);
1481
+ if (!ctx)
1482
+ throw new Error("Popover components must be used within PopoverRoot");
1483
+ return ctx;
1484
+ }
1485
+ function PopoverRoot({
1486
+ children,
1487
+ open: controlledOpen,
1488
+ defaultOpen = false,
1489
+ onOpenChange,
1490
+ setOpen: setOpenDeprecated,
1491
+ placement = "bottom-start",
1492
+ manageFocus = false,
1493
+ animated = true,
1494
+ portal = false,
1495
+ portalRoot = null
1496
+ }) {
1497
+ const [open, setOpen] = useControllableState(
1498
+ defaultOpen,
1499
+ controlledOpen,
1500
+ onOpenChange != null ? onOpenChange : setOpenDeprecated
1501
+ );
1502
+ const popoverId = useId();
1503
+ const {
1504
+ getReferenceProps,
1505
+ getFloatingProps,
1506
+ getPositionerStateProps,
1507
+ context
1508
+ } = useFloating({
1509
+ placement,
1510
+ gutter: 8,
1511
+ open,
1512
+ onOpenChange: setOpen,
1513
+ dismiss: true
1514
+ });
1515
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1516
+ PopoverContext.Provider,
1517
+ {
1518
+ value: {
1519
+ open,
1520
+ setOpen,
1521
+ popoverId,
1522
+ manageFocus,
1523
+ animated,
1524
+ portal,
1525
+ portalRoot,
1526
+ getReferenceProps,
1527
+ getFloatingProps,
1528
+ getPositionerStateProps,
1529
+ context
1530
+ },
1531
+ children
1532
+ }
1533
+ );
1534
+ }
1535
+ var PopoverTrigger = (0, import_react16.forwardRef)((_a, ref) => {
1536
+ var _b = _a, { onClick } = _b, props = __objRest(_b, ["onClick"]);
1537
+ const { open, setOpen, popoverId, getReferenceProps } = usePopoverContext();
1538
+ const refProps = getReferenceProps();
1539
+ const handleClick = (0, import_react16.useCallback)(
1540
+ (e) => {
1541
+ setOpen(!open);
1542
+ onClick == null ? void 0 : onClick(e);
1543
+ },
1544
+ [open, setOpen, onClick]
1545
+ );
1546
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1547
+ "button",
1548
+ __spreadValues({
1549
+ ref: (node) => {
1550
+ if (refProps.ref && typeof refProps.ref === "function") {
1551
+ refProps.ref(node);
1552
+ }
1553
+ if (typeof ref === "function") ref(node);
1554
+ else if (ref) ref.current = node;
1555
+ },
1556
+ type: "button",
1557
+ "aria-expanded": open,
1558
+ "aria-controls": open ? popoverId : void 0,
1559
+ "data-popover-trigger": popoverId,
1560
+ onClick: handleClick
1561
+ }, props)
1562
+ );
1563
+ });
1564
+ PopoverTrigger.displayName = "PopoverTrigger";
1565
+ function PopoverContent(_a) {
1566
+ var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
1567
+ const {
1568
+ open,
1569
+ popoverId,
1570
+ manageFocus,
1571
+ animated,
1572
+ portal,
1573
+ portalRoot,
1574
+ getFloatingProps,
1575
+ getPositionerStateProps,
1576
+ context
1577
+ } = usePopoverContext();
1578
+ const { ref, mounted, dataAttributes } = useEnterLeave(open, { animated });
1579
+ const floatingProps = getFloatingProps();
1580
+ if (!mounted) return null;
1581
+ const node = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1582
+ "div",
1583
+ __spreadProps(__spreadValues(__spreadValues(__spreadValues({
1584
+ ref: (n) => {
1585
+ ref.current = n;
1586
+ if (floatingProps.ref && typeof floatingProps.ref === "function") {
1587
+ floatingProps.ref(n);
1588
+ }
1589
+ },
1590
+ id: popoverId,
1591
+ "data-popover-id": popoverId,
1592
+ tabIndex: -1,
1593
+ style: floatingProps.style
1594
+ }, getPositionerStateProps(open)), dataAttributes), props), {
1595
+ children
1596
+ })
1597
+ );
1598
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(OverlayPortal, { portal, portalRoot, children: manageFocus ? (
1599
+ // Non-modal focus management: move focus into the panel on open, place
1600
+ // tab guards for correct tab-out continuity (incl. the VoiceOver/WebKit
1601
+ // workaround), and return focus to the trigger on close.
1602
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react17.FloatingFocusManager, { context, modal: false, returnFocus: true, children: node })
1603
+ ) : node });
1604
+ }
1605
+ var PopoverClose = (0, import_react16.forwardRef)(
1606
+ (_a, ref) => {
1607
+ var _b = _a, { onClick } = _b, props = __objRest(_b, ["onClick"]);
1608
+ const { setOpen } = usePopoverContext();
1609
+ const handleClick = (0, import_react16.useCallback)(
1610
+ (e) => {
1611
+ setOpen(false);
1612
+ onClick == null ? void 0 : onClick(e);
1613
+ },
1614
+ [setOpen, onClick]
1615
+ );
1616
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", __spreadValues({ ref, type: "button", onClick: handleClick }, props));
1617
+ }
1618
+ );
1619
+ PopoverClose.displayName = "PopoverClose";
1620
+
1621
+ // src/primitives/select.tsx
1622
+ var import_react18 = require("react");
1623
+ var import_jsx_runtime9 = require("react/jsx-runtime");
1624
+ function firstEnabledId(items) {
1625
+ var _a, _b;
1626
+ return (_b = (_a = items.find((i) => !i.disabled)) == null ? void 0 : _a.id) != null ? _b : null;
1627
+ }
1628
+ function moveActiveId(items, activeId, delta) {
1629
+ const enabled = items.filter((i) => !i.disabled);
1630
+ if (enabled.length === 0) return null;
1631
+ const idx = enabled.findIndex((i) => i.id === activeId);
1632
+ if (idx < 0) {
1633
+ return delta > 0 ? enabled[0].id : enabled[enabled.length - 1].id;
1634
+ }
1635
+ const next = Math.min(enabled.length - 1, Math.max(0, idx + delta));
1636
+ return enabled[next].id;
1637
+ }
1638
+ var SelectContext = (0, import_react18.createContext)(null);
1639
+ function useSelectContext() {
1640
+ const ctx = (0, import_react18.useContext)(SelectContext);
1641
+ if (!ctx) throw new Error("Select components must be used within SelectRoot");
1642
+ return ctx;
1643
+ }
1644
+ function SelectRoot({
1645
+ children,
1646
+ value: controlledValue,
1647
+ defaultValue,
1648
+ onValueChange,
1649
+ setValue: setValueDeprecated,
1650
+ multiple = false,
1651
+ name,
1652
+ open: controlledOpen,
1653
+ onOpenChange,
1654
+ setOpen: setOpenDeprecated,
1655
+ animated = true,
1656
+ portal = false,
1657
+ portalRoot = null
1658
+ }) {
1659
+ var _a;
1660
+ const normalizedDefault = defaultValue != null ? defaultValue : multiple ? [] : "";
1661
+ const [value, setValue] = useControllableState(
1662
+ normalizedDefault,
1663
+ controlledValue,
1664
+ onValueChange != null ? onValueChange : setValueDeprecated
1665
+ );
1666
+ const [open, setOpenState] = (0, import_react18.useState)(controlledOpen != null ? controlledOpen : false);
1667
+ const onOpenChangeCb = onOpenChange != null ? onOpenChange : setOpenDeprecated;
1668
+ const [activeId, setActiveId] = (0, import_react18.useState)(null);
1669
+ const selectId = useId();
1670
+ const listboxId = `${selectId}-listbox`;
1671
+ const items = (0, import_react18.useRef)([]);
1672
+ (0, import_react18.useEffect)(() => {
1673
+ if (controlledOpen !== void 0) setOpenState(controlledOpen);
1674
+ }, [controlledOpen]);
1675
+ const setOpen = (0, import_react18.useCallback)(
1676
+ (v) => {
1677
+ if (controlledOpen === void 0) setOpenState(v);
1678
+ onOpenChangeCb == null ? void 0 : onOpenChangeCb(v);
1679
+ if (!v) setActiveId(null);
1680
+ },
1681
+ [controlledOpen, onOpenChangeCb]
1682
+ );
1683
+ const selectedValues = (0, import_react18.useMemo)(
1684
+ () => Array.isArray(value) ? value : value === "" ? [] : [value],
1685
+ [value]
1686
+ );
1687
+ const isSelected = (0, import_react18.useCallback)(
1688
+ (v) => selectedValues.includes(v),
1689
+ [selectedValues]
1690
+ );
1691
+ const selectValue = (0, import_react18.useCallback)(
1692
+ (v) => {
1693
+ if (multiple) {
1694
+ const arr = Array.isArray(value) ? value : value ? [value] : [];
1695
+ setValue(arr.includes(v) ? arr.filter((x) => x !== v) : [...arr, v]);
1696
+ } else {
1697
+ setValue(v);
1698
+ setOpen(false);
1699
+ }
1700
+ },
1701
+ [multiple, value, setValue, setOpen]
1702
+ );
1703
+ const registerItem = (0, import_react18.useCallback)((entry) => {
1704
+ const list = items.current;
1705
+ const existing = list.findIndex((i) => i.id === entry.id);
1706
+ if (existing >= 0) list[existing] = entry;
1707
+ else list.push(entry);
1708
+ }, []);
1709
+ const unregisterItem = (0, import_react18.useCallback)((id) => {
1710
+ items.current = items.current.filter((i) => i.id !== id);
1711
+ }, []);
1712
+ const { getReferenceProps, getFloatingProps } = useFloating({
1713
+ placement: "bottom-start",
1714
+ gutter: 4,
1715
+ sameWidth: true,
1716
+ open,
1717
+ onOpenChange: setOpen,
1718
+ dismiss: { outsidePress: true, escapeKey: false }
1719
+ });
1720
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1721
+ SelectContext.Provider,
1722
+ {
1723
+ value: {
1724
+ open,
1725
+ setOpen,
1726
+ value,
1727
+ selectedValues,
1728
+ multiple,
1729
+ isSelected,
1730
+ selectValue,
1731
+ activeId,
1732
+ setActiveId,
1733
+ selectId,
1734
+ listboxId,
1735
+ getReferenceProps,
1736
+ getFloatingProps,
1737
+ items,
1738
+ registerItem,
1739
+ unregisterItem,
1740
+ animated,
1741
+ portal,
1742
+ portalRoot
1743
+ },
1744
+ children: [
1745
+ children,
1746
+ name && (multiple ? selectedValues.map((v) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("input", { type: "hidden", name, value: v }, v)) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("input", { type: "hidden", name, value: (_a = selectedValues[0]) != null ? _a : "" }))
1747
+ ]
1748
+ }
1749
+ );
1750
+ }
1751
+ function SelectLabel(props) {
1752
+ const { selectId } = useSelectContext();
1753
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("label", __spreadValues({ htmlFor: selectId }, props));
1754
+ }
1755
+ var SelectTrigger = (0, import_react18.forwardRef)(
1756
+ (_a, ref) => {
1757
+ var _b = _a, { onClick, onKeyDown, children } = _b, props = __objRest(_b, ["onClick", "onKeyDown", "children"]);
1758
+ var _a2;
1759
+ const {
1760
+ open,
1761
+ setOpen,
1762
+ selectedValues,
1763
+ multiple,
1764
+ selectValue,
1765
+ selectId,
1766
+ listboxId,
1767
+ getReferenceProps,
1768
+ items,
1769
+ activeId,
1770
+ setActiveId
1771
+ } = useSelectContext();
1772
+ const refProps = getReferenceProps();
1773
+ const typeahead = (0, import_react18.useRef)({
1774
+ buffer: "",
1775
+ timer: 0
1776
+ });
1777
+ const selectActive = (0, import_react18.useCallback)(() => {
1778
+ const item = items.current.find((i) => i.id === activeId);
1779
+ if (item && !item.disabled) {
1780
+ selectValue(item.value);
1781
+ }
1782
+ }, [items, activeId, selectValue]);
1783
+ const runTypeahead = (0, import_react18.useCallback)(
1784
+ (char) => {
1785
+ const t = typeahead.current;
1786
+ window.clearTimeout(t.timer);
1787
+ t.buffer += char.toLowerCase();
1788
+ t.timer = window.setTimeout(() => {
1789
+ t.buffer = "";
1790
+ }, 500);
1791
+ const match = items.current.filter((i) => !i.disabled).find(
1792
+ (i) => {
1793
+ var _a3, _b2;
1794
+ return (_b2 = (_a3 = document.getElementById(i.id)) == null ? void 0 : _a3.textContent) == null ? void 0 : _b2.trim().toLowerCase().startsWith(t.buffer);
1795
+ }
1796
+ );
1797
+ if (match) setActiveId(match.id);
1798
+ },
1799
+ [items, setActiveId]
1800
+ );
1801
+ const handleClick = (0, import_react18.useCallback)(
1802
+ (e) => {
1803
+ setOpen(!open);
1804
+ onClick == null ? void 0 : onClick(e);
1805
+ },
1806
+ [open, setOpen, onClick]
1807
+ );
1808
+ const handleKeyDown2 = (0, import_react18.useCallback)(
1809
+ (e) => {
1810
+ var _a3, _b2;
1811
+ switch (e.key) {
1812
+ case "ArrowDown":
1813
+ e.preventDefault();
1814
+ if (!open) setOpen(true);
1815
+ else setActiveId(moveActiveId(items.current, activeId, 1));
1816
+ break;
1817
+ case "ArrowUp":
1818
+ e.preventDefault();
1819
+ if (!open) setOpen(true);
1820
+ else setActiveId(moveActiveId(items.current, activeId, -1));
1821
+ break;
1822
+ case "Home":
1823
+ if (open) {
1824
+ e.preventDefault();
1825
+ setActiveId(firstEnabledId(items.current));
1826
+ }
1827
+ break;
1828
+ case "End":
1829
+ if (open) {
1830
+ e.preventDefault();
1831
+ const enabled = items.current.filter((i) => !i.disabled);
1832
+ setActiveId((_b2 = (_a3 = enabled[enabled.length - 1]) == null ? void 0 : _a3.id) != null ? _b2 : null);
1833
+ }
1834
+ break;
1835
+ case "Enter":
1836
+ case " ":
1837
+ e.preventDefault();
1838
+ if (open) selectActive();
1839
+ else setOpen(true);
1840
+ break;
1841
+ case "Escape":
1842
+ if (open) {
1843
+ e.preventDefault();
1844
+ setOpen(false);
1845
+ }
1846
+ break;
1847
+ default:
1848
+ if (open && e.key.length === 1 && e.key !== " " && !e.metaKey && !e.ctrlKey && !e.altKey && !e.nativeEvent.isComposing) {
1849
+ runTypeahead(e.key);
1850
+ }
1851
+ }
1852
+ onKeyDown == null ? void 0 : onKeyDown(e);
1853
+ },
1854
+ [
1855
+ open,
1856
+ items,
1857
+ activeId,
1858
+ setActiveId,
1859
+ setOpen,
1860
+ selectActive,
1861
+ runTypeahead,
1862
+ onKeyDown
1863
+ ]
1864
+ );
1865
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1866
+ "button",
1867
+ __spreadProps(__spreadValues({
1868
+ ref: (node) => {
1869
+ if (refProps.ref && typeof refProps.ref === "function") {
1870
+ refProps.ref(node);
1871
+ }
1872
+ if (typeof ref === "function") ref(node);
1873
+ else if (ref) ref.current = node;
1874
+ },
1875
+ type: "button",
1876
+ id: selectId,
1877
+ role: "combobox",
1878
+ "aria-expanded": open,
1879
+ "aria-haspopup": "listbox",
1880
+ "aria-controls": open ? listboxId : void 0,
1881
+ "aria-activedescendant": open ? activeId != null ? activeId : void 0 : void 0,
1882
+ "data-select-trigger": selectId,
1883
+ onClick: handleClick,
1884
+ onKeyDown: handleKeyDown2
1885
+ }, props), {
1886
+ children: children != null ? children : multiple ? selectedValues.join(", ") : (_a2 = selectedValues[0]) != null ? _a2 : ""
1887
+ })
1888
+ );
1889
+ }
1890
+ );
1891
+ SelectTrigger.displayName = "SelectTrigger";
1892
+ function SelectPopover(_a) {
1893
+ var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
1894
+ const {
1895
+ open,
1896
+ multiple,
1897
+ selectedValues,
1898
+ listboxId,
1899
+ selectId,
1900
+ getFloatingProps,
1901
+ items,
1902
+ activeId,
1903
+ setActiveId,
1904
+ animated,
1905
+ portal,
1906
+ portalRoot
1907
+ } = useSelectContext();
1908
+ const { ref, mounted, dataAttributes } = useEnterLeave(open, { animated });
1909
+ const floatingProps = getFloatingProps();
1910
+ (0, import_react18.useLayoutEffect)(() => {
1911
+ if (mounted) {
1912
+ setActiveId((prev) => {
1913
+ var _a2;
1914
+ if (prev) return prev;
1915
+ const selected = items.current.find(
1916
+ (i) => selectedValues.includes(i.value)
1917
+ );
1918
+ return (_a2 = selected == null ? void 0 : selected.id) != null ? _a2 : firstEnabledId(items.current);
1919
+ });
1920
+ }
1921
+ }, [mounted, items, selectedValues, setActiveId]);
1922
+ useScrollActiveDescendantIntoView(activeId);
1923
+ if (!mounted) return null;
1924
+ const node = /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1925
+ "div",
1926
+ __spreadProps(__spreadValues(__spreadValues({
1927
+ ref: (n) => {
1928
+ ref.current = n;
1929
+ if (floatingProps.ref && typeof floatingProps.ref === "function") {
1930
+ floatingProps.ref(n);
1931
+ }
1932
+ },
1933
+ id: listboxId,
1934
+ role: "listbox",
1935
+ "aria-multiselectable": multiple || void 0,
1936
+ "aria-activedescendant": activeId != null ? activeId : void 0,
1937
+ "data-select-id": selectId,
1938
+ style: floatingProps.style
1939
+ }, dataAttributes), props), {
1940
+ children
1941
+ })
1942
+ );
1943
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(OverlayPortal, { portal, portalRoot, children: node });
1944
+ }
1945
+ function SelectItem(_a) {
1946
+ var _b = _a, {
1947
+ value: itemValue,
1948
+ disabled,
1949
+ onClick,
1950
+ children
1951
+ } = _b, props = __objRest(_b, [
1952
+ "value",
1953
+ "disabled",
1954
+ "onClick",
1955
+ "children"
1956
+ ]);
1957
+ const {
1958
+ isSelected: isValueSelected,
1959
+ selectValue,
1960
+ activeId,
1961
+ setActiveId,
1962
+ registerItem,
1963
+ unregisterItem
1964
+ } = useSelectContext();
1965
+ const itemId = useId();
1966
+ const isSelected = isValueSelected(itemValue);
1967
+ const isActive = activeId === itemId;
1968
+ (0, import_react18.useLayoutEffect)(() => {
1969
+ registerItem({ id: itemId, value: itemValue, disabled });
1970
+ return () => unregisterItem(itemId);
1971
+ }, [itemId, itemValue, disabled, registerItem, unregisterItem]);
1972
+ const handleClick = (0, import_react18.useCallback)(
1973
+ (e) => {
1974
+ if (!disabled) {
1975
+ selectValue(itemValue);
1976
+ }
1977
+ onClick == null ? void 0 : onClick(e);
1978
+ },
1979
+ [disabled, itemValue, selectValue, onClick]
1980
+ );
1981
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1982
+ "div",
1983
+ __spreadProps(__spreadValues({
1984
+ id: itemId,
1985
+ role: "option",
1986
+ "aria-selected": isSelected,
1987
+ "aria-disabled": disabled || void 0,
1988
+ "data-active-item": isActive ? "" : void 0,
1989
+ "data-disabled": disabled ? "" : void 0,
1990
+ onClick: handleClick,
1991
+ onMouseEnter: () => {
1992
+ if (!disabled) setActiveId(itemId);
1993
+ }
1994
+ }, props), {
1995
+ children: children != null ? children : itemValue
1996
+ })
1997
+ );
1998
+ }
1999
+
2000
+ // src/primitives/combobox.tsx
2001
+ var import_react19 = require("react");
2002
+ var import_jsx_runtime10 = require("react/jsx-runtime");
2003
+ function firstEnabledId2(items) {
2004
+ var _a, _b;
2005
+ return (_b = (_a = items.find((i) => !i.disabled)) == null ? void 0 : _a.id) != null ? _b : null;
2006
+ }
2007
+ function moveActiveId2(items, activeId, delta) {
2008
+ const enabled = items.filter((i) => !i.disabled);
2009
+ if (enabled.length === 0) return null;
2010
+ const idx = enabled.findIndex((i) => i.id === activeId);
2011
+ if (idx < 0) {
2012
+ return delta > 0 ? enabled[0].id : enabled[enabled.length - 1].id;
2013
+ }
2014
+ const next = Math.min(enabled.length - 1, Math.max(0, idx + delta));
2015
+ return enabled[next].id;
2016
+ }
2017
+ function createComboboxStore(initial) {
2018
+ let state = initial;
2019
+ const listeners = /* @__PURE__ */ new Set();
2020
+ return {
2021
+ getState: () => state,
2022
+ setState: (partial) => {
2023
+ const next = __spreadValues(__spreadValues({}, state), partial);
2024
+ if (next.value === state.value && next.searchValue === state.searchValue && next.activeId === state.activeId && next.open === state.open) {
2025
+ return;
2026
+ }
2027
+ state = next;
2028
+ listeners.forEach((l) => l());
2029
+ },
2030
+ subscribe: (listener) => {
2031
+ listeners.add(listener);
2032
+ return () => {
2033
+ listeners.delete(listener);
2034
+ };
2035
+ }
2036
+ };
2037
+ }
2038
+ var ComboboxStoreContext = (0, import_react19.createContext)(
2039
+ null
2040
+ );
2041
+ function useComboboxStoreContext() {
2042
+ const ctx = (0, import_react19.useContext)(ComboboxStoreContext);
2043
+ if (!ctx)
2044
+ throw new Error("Combobox components must be used within ComboboxRoot");
2045
+ return ctx;
2046
+ }
2047
+ function useComboboxSelector(selector) {
2048
+ const { store } = useComboboxStoreContext();
2049
+ return (0, import_react19.useSyncExternalStore)(
2050
+ store.subscribe,
2051
+ () => selector(store.getState()),
2052
+ () => selector(store.getState())
2053
+ );
2054
+ }
2055
+ var ComboboxFloatingContext = (0, import_react19.createContext)(null);
2056
+ function useComboboxFloating() {
2057
+ const ctx = (0, import_react19.useContext)(ComboboxFloatingContext);
2058
+ if (!ctx)
2059
+ throw new Error("Combobox components must be used within ComboboxRoot");
2060
+ return ctx;
2061
+ }
2062
+ function ComboboxRoot({
2063
+ children,
2064
+ value: controlledValue,
2065
+ defaultValue = "",
2066
+ onValueChange,
2067
+ setValue: setValueDeprecated,
2068
+ open: controlledOpen,
2069
+ onOpenChange,
2070
+ setOpen: setOpenDeprecated,
2071
+ animated = true,
2072
+ portal = false,
2073
+ portalRoot = null
2074
+ }) {
2075
+ const comboboxId = useId();
2076
+ const listboxId = `${comboboxId}-listbox`;
2077
+ const items = (0, import_react19.useRef)([]);
2078
+ const [store] = (0, import_react19.useState)(
2079
+ () => createComboboxStore({
2080
+ value: controlledValue != null ? controlledValue : defaultValue,
2081
+ searchValue: "",
2082
+ activeId: null,
2083
+ open: controlledOpen != null ? controlledOpen : false
2084
+ })
2085
+ );
2086
+ const propsRef = (0, import_react19.useRef)({
2087
+ controlledValue,
2088
+ controlledOpen,
2089
+ onValueChange: onValueChange != null ? onValueChange : setValueDeprecated,
2090
+ onOpenChange: onOpenChange != null ? onOpenChange : setOpenDeprecated
2091
+ });
2092
+ propsRef.current = {
2093
+ controlledValue,
2094
+ controlledOpen,
2095
+ onValueChange: onValueChange != null ? onValueChange : setValueDeprecated,
2096
+ onOpenChange: onOpenChange != null ? onOpenChange : setOpenDeprecated
2097
+ };
2098
+ (0, import_react19.useEffect)(() => {
2099
+ if (controlledValue !== void 0)
2100
+ store.setState({ value: controlledValue });
2101
+ }, [controlledValue, store]);
2102
+ (0, import_react19.useEffect)(() => {
2103
+ if (controlledOpen !== void 0) store.setState({ open: controlledOpen });
2104
+ }, [controlledOpen, store]);
2105
+ const actions = (0, import_react19.useMemo)(
2106
+ () => ({
2107
+ setValue: (v) => {
2108
+ var _a;
2109
+ const p = propsRef.current;
2110
+ if (p.controlledValue === void 0) store.setState({ value: v });
2111
+ (_a = p.onValueChange) == null ? void 0 : _a.call(p, v);
2112
+ },
2113
+ setOpen: (v) => {
2114
+ var _a;
2115
+ const p = propsRef.current;
2116
+ if (p.controlledOpen === void 0) store.setState({ open: v });
2117
+ (_a = p.onOpenChange) == null ? void 0 : _a.call(p, v);
2118
+ if (!v) store.setState({ activeId: null });
2119
+ },
2120
+ setSearchValue: (v) => store.setState({ searchValue: v }),
2121
+ setActiveId: (updater) => {
2122
+ const cur = store.getState().activeId;
2123
+ const next = typeof updater === "function" ? updater(cur) : updater;
2124
+ store.setState({ activeId: next });
2125
+ }
2126
+ }),
2127
+ [store]
2128
+ );
2129
+ const registerItem = (0, import_react19.useCallback)((entry) => {
2130
+ const list = items.current;
2131
+ const existing = list.findIndex((i) => i.id === entry.id);
2132
+ if (existing >= 0) list[existing] = entry;
2133
+ else list.push(entry);
2134
+ }, []);
2135
+ const unregisterItem = (0, import_react19.useCallback)((id) => {
2136
+ items.current = items.current.filter((i) => i.id !== id);
2137
+ }, []);
2138
+ const open = (0, import_react19.useSyncExternalStore)(
2139
+ store.subscribe,
2140
+ () => store.getState().open,
2141
+ () => store.getState().open
2142
+ );
2143
+ const { getReferenceProps, getFloatingProps } = useFloating({
2144
+ placement: "bottom-start",
2145
+ gutter: 4,
2146
+ sameWidth: true,
2147
+ lazyFlip: true,
2148
+ open,
2149
+ onOpenChange: actions.setOpen,
2150
+ dismiss: { outsidePress: true, escapeKey: false }
2151
+ });
2152
+ const storeContext = (0, import_react19.useMemo)(
2153
+ () => ({
2154
+ store,
2155
+ actions,
2156
+ comboboxId,
2157
+ listboxId,
2158
+ items,
2159
+ registerItem,
2160
+ unregisterItem
2161
+ }),
2162
+ [store, actions, comboboxId, listboxId, registerItem, unregisterItem]
2163
+ );
2164
+ const floatingContext = (0, import_react19.useMemo)(
2165
+ () => ({
2166
+ getReferenceProps,
2167
+ getFloatingProps,
2168
+ animated,
2169
+ portal,
2170
+ portalRoot
2171
+ }),
2172
+ [getReferenceProps, getFloatingProps, animated, portal, portalRoot]
2173
+ );
2174
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ComboboxStoreContext.Provider, { value: storeContext, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ComboboxFloatingContext.Provider, { value: floatingContext, children }) });
2175
+ }
2176
+ var ComboboxInput = (0, import_react19.forwardRef)(
2177
+ (_a, ref) => {
2178
+ var _b = _a, { onKeyDown } = _b, props = __objRest(_b, ["onKeyDown"]);
2179
+ const { actions, comboboxId, listboxId, items } = useComboboxStoreContext();
2180
+ const { getReferenceProps } = useComboboxFloating();
2181
+ const open = useComboboxSelector((s) => s.open);
2182
+ const searchValue = useComboboxSelector((s) => s.searchValue);
2183
+ const activeId = useComboboxSelector((s) => s.activeId);
2184
+ const refProps = getReferenceProps();
2185
+ useScrollActiveDescendantIntoView(activeId);
2186
+ const handleChange = (0, import_react19.useCallback)(
2187
+ (e) => {
2188
+ actions.setSearchValue(e.target.value);
2189
+ if (!open) actions.setOpen(true);
2190
+ actions.setActiveId(null);
2191
+ },
2192
+ [actions, open]
2193
+ );
2194
+ const selectActive = (0, import_react19.useCallback)(() => {
2195
+ const item = items.current.find((i) => i.id === activeId);
2196
+ if (item && !item.disabled) {
2197
+ actions.setValue(item.value);
2198
+ actions.setSearchValue(item.value);
2199
+ actions.setOpen(false);
2200
+ }
2201
+ }, [items, activeId, actions]);
2202
+ const handleKeyDown2 = (0, import_react19.useCallback)(
2203
+ (e) => {
2204
+ if (e.nativeEvent.isComposing) {
2205
+ onKeyDown == null ? void 0 : onKeyDown(e);
2206
+ return;
2207
+ }
2208
+ switch (e.key) {
2209
+ case "ArrowDown":
2210
+ e.preventDefault();
2211
+ if (!open) actions.setOpen(true);
2212
+ actions.setActiveId(moveActiveId2(items.current, activeId, 1));
2213
+ break;
2214
+ case "ArrowUp":
2215
+ e.preventDefault();
2216
+ if (!open) actions.setOpen(true);
2217
+ actions.setActiveId(moveActiveId2(items.current, activeId, -1));
2218
+ break;
2219
+ case "Enter":
2220
+ if (open && activeId) {
2221
+ e.preventDefault();
2222
+ selectActive();
2223
+ }
2224
+ break;
2225
+ case "Escape":
2226
+ if (open) {
2227
+ e.preventDefault();
2228
+ actions.setOpen(false);
2229
+ }
2230
+ break;
2231
+ }
2232
+ onKeyDown == null ? void 0 : onKeyDown(e);
2233
+ },
2234
+ [open, actions, activeId, items, selectActive, onKeyDown]
2235
+ );
2236
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
2237
+ "input",
2238
+ __spreadValues({
2239
+ ref: (node) => {
2240
+ if (refProps.ref && typeof refProps.ref === "function") {
2241
+ refProps.ref(node);
2242
+ }
2243
+ if (typeof ref === "function") ref(node);
2244
+ else if (ref) ref.current = node;
2245
+ },
2246
+ type: "text",
2247
+ role: "combobox",
2248
+ id: comboboxId,
2249
+ "aria-expanded": open,
2250
+ "aria-autocomplete": "list",
2251
+ "aria-controls": open ? listboxId : void 0,
2252
+ "aria-activedescendant": open ? activeId != null ? activeId : void 0 : void 0,
2253
+ "data-combobox-input": comboboxId,
2254
+ value: searchValue,
2255
+ onChange: handleChange,
2256
+ onKeyDown: handleKeyDown2
2257
+ }, props)
2258
+ );
2259
+ }
2260
+ );
2261
+ ComboboxInput.displayName = "ComboboxInput";
2262
+ function ComboboxPopover(_a) {
2263
+ var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
2264
+ const { actions, comboboxId, listboxId, items } = useComboboxStoreContext();
2265
+ const { getFloatingProps, animated, portal, portalRoot } = useComboboxFloating();
2266
+ const open = useComboboxSelector((s) => s.open);
2267
+ const { ref, mounted, dataAttributes } = useEnterLeave(open, { animated });
2268
+ const floatingProps = getFloatingProps();
2269
+ (0, import_react19.useLayoutEffect)(() => {
2270
+ if (mounted) {
2271
+ actions.setActiveId((prev) => prev != null ? prev : firstEnabledId2(items.current));
2272
+ }
2273
+ }, [mounted, items, actions]);
2274
+ if (!mounted) return null;
2275
+ const node = /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
2276
+ "div",
2277
+ __spreadProps(__spreadValues(__spreadValues({
2278
+ ref: (n) => {
2279
+ ref.current = n;
2280
+ if (floatingProps.ref && typeof floatingProps.ref === "function") {
2281
+ floatingProps.ref(n);
2282
+ }
2283
+ },
2284
+ id: listboxId,
2285
+ role: "listbox",
2286
+ "data-combobox-id": comboboxId,
2287
+ style: floatingProps.style
2288
+ }, dataAttributes), props), {
2289
+ children
2290
+ })
2291
+ );
2292
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(OverlayPortal, { portal, portalRoot, children: node });
2293
+ }
2294
+ function ComboboxItem(_a) {
2295
+ var _b = _a, {
2296
+ value: itemValue,
2297
+ disabled,
2298
+ onClick,
2299
+ children
2300
+ } = _b, props = __objRest(_b, [
2301
+ "value",
2302
+ "disabled",
2303
+ "onClick",
2304
+ "children"
2305
+ ]);
2306
+ const { actions, registerItem, unregisterItem } = useComboboxStoreContext();
2307
+ const itemId = useId();
2308
+ const isSelected = useComboboxSelector((s) => s.value === itemValue);
2309
+ const isActive = useComboboxSelector((s) => s.activeId === itemId);
2310
+ (0, import_react19.useLayoutEffect)(() => {
2311
+ registerItem({ id: itemId, value: itemValue, disabled });
2312
+ return () => unregisterItem(itemId);
2313
+ }, [itemId, itemValue, disabled, registerItem, unregisterItem]);
2314
+ const handleClick = (0, import_react19.useCallback)(
2315
+ (e) => {
2316
+ if (!disabled) {
2317
+ actions.setValue(itemValue);
2318
+ actions.setSearchValue(itemValue);
2319
+ actions.setOpen(false);
2320
+ }
2321
+ onClick == null ? void 0 : onClick(e);
2322
+ },
2323
+ [disabled, itemValue, actions, onClick]
2324
+ );
2325
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
2326
+ "div",
2327
+ __spreadProps(__spreadValues({
2328
+ id: itemId,
2329
+ role: "option",
2330
+ "aria-selected": isSelected,
2331
+ "aria-disabled": disabled || void 0,
2332
+ "data-active-item": isActive ? "" : void 0,
2333
+ "data-disabled": disabled ? "" : void 0,
2334
+ onClick: handleClick,
2335
+ onMouseEnter: () => {
2336
+ if (!disabled) actions.setActiveId(itemId);
2337
+ }
2338
+ }, props), {
2339
+ children: children != null ? children : itemValue
2340
+ })
2341
+ );
2342
+ }
2343
+ var ComboboxGroupContext = (0, import_react19.createContext)(
2344
+ null
2345
+ );
2346
+ function ComboboxGroup(_a) {
2347
+ var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
2348
+ const labelId = useId();
2349
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ComboboxGroupContext.Provider, { value: { labelId }, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", __spreadProps(__spreadValues({ role: "group", "aria-labelledby": labelId }, props), { children })) });
2350
+ }
2351
+ function ComboboxGroupLabel(props) {
2352
+ const ctx = (0, import_react19.useContext)(ComboboxGroupContext);
2353
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", __spreadValues({ id: ctx == null ? void 0 : ctx.labelId }, props));
2354
+ }
2355
+
2356
+ // src/primitives/command.tsx
2357
+ var import_react20 = require("react");
2358
+ var import_jsx_runtime11 = require("react/jsx-runtime");
2359
+ var CommandContext = (0, import_react20.createContext)(null);
2360
+ function useCommandContext() {
2361
+ const ctx = (0, import_react20.useContext)(CommandContext);
2362
+ if (!ctx)
2363
+ throw new Error("Command components must be used within CommandRoot");
2364
+ return ctx;
2365
+ }
2366
+ function defaultFilter(value, search, keywords) {
2367
+ if (!search) return true;
2368
+ const needle = search.toLowerCase();
2369
+ if (value.toLowerCase().includes(needle)) return true;
2370
+ return keywords.some((k) => k.toLowerCase().includes(needle));
2371
+ }
2372
+ function CommandRoot(_a) {
2373
+ var _b = _a, {
2374
+ children,
2375
+ value: controlledValue,
2376
+ defaultValue = "",
2377
+ onValueChange,
2378
+ shouldFilter = true,
2379
+ filter = defaultFilter,
2380
+ onEscape
2381
+ } = _b, props = __objRest(_b, [
2382
+ "children",
2383
+ "value",
2384
+ "defaultValue",
2385
+ "onValueChange",
2386
+ "shouldFilter",
2387
+ "filter",
2388
+ "onEscape"
2389
+ ]);
2390
+ const [value, setValue] = useControllableState(
2391
+ defaultValue,
2392
+ controlledValue,
2393
+ onValueChange
2394
+ );
2395
+ const [search, setSearch] = (0, import_react20.useState)("");
2396
+ const [activeValue, setActiveValue] = (0, import_react20.useState)("");
2397
+ const itemsRef = (0, import_react20.useRef)(/* @__PURE__ */ new Map());
2398
+ const [version, setVersion] = (0, import_react20.useState)(0);
2399
+ const baseId = useId();
2400
+ const bumpVersion = (0, import_react20.useCallback)(() => setVersion((v) => v + 1), []);
2401
+ const visibleValues = (0, import_react20.useMemo)(() => {
2402
+ const result = [];
2403
+ for (const [, ref] of itemsRef.current) {
2404
+ const item = ref.current;
2405
+ if (!shouldFilter || filter(item.value, search, item.keywords)) {
2406
+ result.push(item.value);
2407
+ }
2408
+ }
2409
+ return result;
2410
+ }, [search, shouldFilter, filter, version]);
2411
+ (0, import_react20.useEffect)(() => {
2412
+ const enabled = visibleValues.filter((v) => {
2413
+ for (const [, ref] of itemsRef.current) {
2414
+ if (ref.current.value === v) return !ref.current.disabled;
2415
+ }
2416
+ return true;
2417
+ });
2418
+ if (enabled.length === 0) {
2419
+ if (activeValue) setActiveValue("");
2420
+ return;
2421
+ }
2422
+ if (!enabled.includes(activeValue) && enabled[0]) {
2423
+ setActiveValue(enabled[0]);
2424
+ }
2425
+ }, [visibleValues, activeValue]);
2426
+ const activeId = (0, import_react20.useMemo)(() => {
2427
+ for (const [id, ref] of itemsRef.current) {
2428
+ if (ref.current.value === activeValue) return id;
2429
+ }
2430
+ return void 0;
2431
+ }, [activeValue, version]);
2432
+ const ctx = (0, import_react20.useMemo)(
2433
+ () => ({
2434
+ search,
2435
+ setSearch,
2436
+ value,
2437
+ setValue,
2438
+ activeValue,
2439
+ setActiveValue,
2440
+ itemsRef,
2441
+ bumpVersion,
2442
+ shouldFilter,
2443
+ filter,
2444
+ visibleValues,
2445
+ activeId,
2446
+ onEscape,
2447
+ inputId: `${baseId}-input`,
2448
+ listId: `${baseId}-list`
2449
+ }),
2450
+ [
2451
+ search,
2452
+ value,
2453
+ setValue,
2454
+ activeValue,
2455
+ bumpVersion,
2456
+ shouldFilter,
2457
+ filter,
2458
+ visibleValues,
2459
+ activeId,
2460
+ onEscape,
2461
+ baseId
2462
+ ]
2463
+ );
2464
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(CommandContext.Provider, { value: ctx, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", __spreadProps(__spreadValues({ "data-slot": "command" }, props), { children })) });
2465
+ }
2466
+ var CommandInput = (0, import_react20.forwardRef)(
2467
+ function CommandInput2(_a, ref) {
2468
+ var _b = _a, { onKeyDown, onValueChange, value: controlledValue } = _b, props = __objRest(_b, ["onKeyDown", "onValueChange", "value"]);
2469
+ const ctx = useCommandContext();
2470
+ const value = controlledValue != null ? controlledValue : ctx.search;
2471
+ useScrollActiveDescendantIntoView(ctx.activeId);
2472
+ const navigableValues = (0, import_react20.useCallback)(() => {
2473
+ const disabled = /* @__PURE__ */ new Set();
2474
+ for (const [, r] of ctx.itemsRef.current) {
2475
+ if (r.current.disabled) disabled.add(r.current.value);
2476
+ }
2477
+ return ctx.visibleValues.filter((v) => !disabled.has(v));
2478
+ }, [ctx]);
2479
+ const handleKeyDown2 = (0, import_react20.useCallback)(
2480
+ (e) => {
2481
+ var _a2, _b2, _c;
2482
+ if (e.nativeEvent.isComposing) {
2483
+ onKeyDown == null ? void 0 : onKeyDown(e);
2484
+ return;
2485
+ }
2486
+ const vals = navigableValues();
2487
+ const idx = vals.indexOf(ctx.activeValue);
2488
+ switch (e.key) {
2489
+ case "ArrowDown": {
2490
+ e.preventDefault();
2491
+ const next = vals[Math.min(idx + 1, vals.length - 1)];
2492
+ if (next) ctx.setActiveValue(next);
2493
+ break;
2494
+ }
2495
+ case "ArrowUp": {
2496
+ e.preventDefault();
2497
+ const prev = vals[Math.max(idx - 1, 0)];
2498
+ if (prev) ctx.setActiveValue(prev);
2499
+ break;
2500
+ }
2501
+ case "Home": {
2502
+ if (vals[0]) {
2503
+ e.preventDefault();
2504
+ ctx.setActiveValue(vals[0]);
2505
+ }
2506
+ break;
2507
+ }
2508
+ case "End": {
2509
+ const last = vals[vals.length - 1];
2510
+ if (last) {
2511
+ e.preventDefault();
2512
+ ctx.setActiveValue(last);
2513
+ }
2514
+ break;
2515
+ }
2516
+ case "Enter": {
2517
+ if (ctx.activeValue && vals.includes(ctx.activeValue)) {
2518
+ e.preventDefault();
2519
+ ctx.setValue(ctx.activeValue);
2520
+ for (const [, r] of ctx.itemsRef.current) {
2521
+ if (r.current.value === ctx.activeValue) {
2522
+ (_b2 = (_a2 = r.current).onSelect) == null ? void 0 : _b2.call(_a2, ctx.activeValue);
2523
+ break;
2524
+ }
2525
+ }
2526
+ }
2527
+ break;
2528
+ }
2529
+ case "Escape": {
2530
+ (_c = ctx.onEscape) == null ? void 0 : _c.call(ctx);
2531
+ break;
2532
+ }
2533
+ }
2534
+ onKeyDown == null ? void 0 : onKeyDown(e);
2535
+ },
2536
+ [ctx, navigableValues, onKeyDown]
2537
+ );
2538
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2539
+ "input",
2540
+ __spreadValues({
2541
+ ref,
2542
+ type: "text",
2543
+ role: "combobox",
2544
+ id: ctx.inputId,
2545
+ "aria-expanded": true,
2546
+ "aria-autocomplete": "list",
2547
+ "aria-controls": ctx.listId,
2548
+ "aria-activedescendant": ctx.activeId,
2549
+ autoCorrect: "off",
2550
+ autoComplete: "off",
2551
+ spellCheck: false,
2552
+ value,
2553
+ onChange: (e) => {
2554
+ ctx.setSearch(e.target.value);
2555
+ onValueChange == null ? void 0 : onValueChange(e.target.value);
2556
+ },
2557
+ onKeyDown: handleKeyDown2
2558
+ }, props)
2559
+ );
2560
+ }
2561
+ );
2562
+ function CommandList(_a) {
2563
+ var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
2564
+ const ctx = useCommandContext();
2565
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", __spreadProps(__spreadValues({ role: "listbox", id: ctx.listId, "data-slot": "command-list" }, props), { children }));
2566
+ }
2567
+ function CommandEmpty(_a) {
2568
+ var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
2569
+ const ctx = useCommandContext();
2570
+ if (ctx.visibleValues.length > 0) return null;
2571
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", __spreadProps(__spreadValues({ role: "presentation", "data-slot": "command-empty" }, props), { children }));
2572
+ }
2573
+ function CommandGroup(_a) {
2574
+ var _b = _a, {
2575
+ heading,
2576
+ children
2577
+ } = _b, props = __objRest(_b, [
2578
+ "heading",
2579
+ "children"
2580
+ ]);
2581
+ const headingId = useId();
2582
+ const hasHeading = heading != null;
2583
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
2584
+ "div",
2585
+ __spreadProps(__spreadValues({
2586
+ role: "group",
2587
+ "data-slot": "command-group",
2588
+ "aria-labelledby": hasHeading ? headingId : void 0
2589
+ }, props), {
2590
+ children: [
2591
+ hasHeading && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2592
+ "div",
2593
+ {
2594
+ id: headingId,
2595
+ "data-slot": "command-group-heading",
2596
+ role: "presentation",
2597
+ children: heading
2598
+ }
2599
+ ),
2600
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { "data-slot": "command-group-items", children })
2601
+ ]
2602
+ })
2603
+ );
2604
+ }
2605
+ function CommandSeparator(props) {
2606
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", __spreadValues({ role: "separator", "data-slot": "command-separator" }, props));
2607
+ }
2608
+ var CommandItem = (0, import_react20.forwardRef)(
2609
+ function CommandItem2(_a, ref) {
2610
+ var _b = _a, {
2611
+ value,
2612
+ keywords,
2613
+ disabled,
2614
+ onSelect,
2615
+ onClick,
2616
+ onMouseEnter,
2617
+ children
2618
+ } = _b, props = __objRest(_b, [
2619
+ "value",
2620
+ "keywords",
2621
+ "disabled",
2622
+ "onSelect",
2623
+ "onClick",
2624
+ "onMouseEnter",
2625
+ "children"
2626
+ ]);
2627
+ const ctx = useCommandContext();
2628
+ const itemId = useId();
2629
+ const metaRef = (0, import_react20.useRef)({
2630
+ value,
2631
+ keywords: keywords != null ? keywords : [],
2632
+ disabled: Boolean(disabled),
2633
+ onSelect
2634
+ });
2635
+ metaRef.current = {
2636
+ value,
2637
+ keywords: keywords != null ? keywords : [],
2638
+ disabled: Boolean(disabled),
2639
+ onSelect
2640
+ };
2641
+ const { itemsRef, bumpVersion } = ctx;
2642
+ (0, import_react20.useLayoutEffect)(() => {
2643
+ const map = itemsRef.current;
2644
+ map.set(itemId, metaRef);
2645
+ bumpVersion();
2646
+ return () => {
2647
+ map.delete(itemId);
2648
+ bumpVersion();
2649
+ };
2650
+ }, [itemId, itemsRef, bumpVersion]);
2651
+ (0, import_react20.useEffect)(() => {
2652
+ bumpVersion();
2653
+ }, [value, disabled, bumpVersion]);
2654
+ const visible = !ctx.shouldFilter || ctx.filter(value, ctx.search, keywords != null ? keywords : []);
2655
+ if (!visible) return null;
2656
+ const isActive = ctx.activeValue === value;
2657
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2658
+ "div",
2659
+ __spreadProps(__spreadValues({
2660
+ ref,
2661
+ role: "option",
2662
+ id: itemId,
2663
+ "aria-selected": isActive || void 0,
2664
+ "aria-disabled": disabled || void 0,
2665
+ "data-active-item": isActive ? "" : void 0,
2666
+ "data-disabled": disabled ? "" : void 0,
2667
+ "data-value": value,
2668
+ "data-slot": "command-item",
2669
+ onClick: (e) => {
2670
+ if (disabled) return;
2671
+ ctx.setValue(value);
2672
+ onSelect == null ? void 0 : onSelect(value);
2673
+ onClick == null ? void 0 : onClick(e);
2674
+ },
2675
+ onMouseEnter: (e) => {
2676
+ if (!disabled) ctx.setActiveValue(value);
2677
+ onMouseEnter == null ? void 0 : onMouseEnter(e);
2678
+ }
2679
+ }, props), {
2680
+ children
2681
+ })
2682
+ );
2683
+ }
2684
+ );
2685
+ function useCommandState() {
2686
+ const { search, value, activeValue, visibleValues } = useCommandContext();
2687
+ return { search, value, activeValue, visibleValues };
2688
+ }
2689
+
2690
+ // src/primitives/menu.tsx
2691
+ var import_react21 = require("react");
2692
+ var import_jsx_runtime12 = require("react/jsx-runtime");
2693
+ function firstEnabledId3(items) {
2694
+ var _a, _b;
2695
+ return (_b = (_a = items.find((i) => !i.disabled)) == null ? void 0 : _a.id) != null ? _b : null;
2696
+ }
2697
+ function moveActiveId3(items, activeId, delta) {
2698
+ const enabled = items.filter((i) => !i.disabled);
2699
+ if (enabled.length === 0) return null;
2700
+ const idx = enabled.findIndex((i) => i.id === activeId);
2701
+ if (idx < 0) {
2702
+ return delta > 0 ? enabled[0].id : enabled[enabled.length - 1].id;
2703
+ }
2704
+ const next = Math.min(enabled.length - 1, Math.max(0, idx + delta));
2705
+ return enabled[next].id;
2706
+ }
2707
+ var MenuContext = (0, import_react21.createContext)(null);
2708
+ function useMenuContext() {
2709
+ const ctx = (0, import_react21.useContext)(MenuContext);
2710
+ if (!ctx) throw new Error("Menu components must be used within MenuRoot");
2711
+ return ctx;
2712
+ }
2713
+ var MenubarContext = (0, import_react21.createContext)(null);
2714
+ function useMenubarContext() {
2715
+ return (0, import_react21.useContext)(MenubarContext);
2716
+ }
2717
+ function MenubarRoot({ children }) {
2718
+ const [activeMenuId, setActiveMenuId] = (0, import_react21.useState)(null);
2719
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(MenubarContext.Provider, { value: { activeMenuId, setActiveMenuId }, children });
2720
+ }
2721
+ function MenubarContainer(_a) {
2722
+ var _b = _a, {
2723
+ onKeyDown
2724
+ } = _b, props = __objRest(_b, [
2725
+ "onKeyDown"
2726
+ ]);
2727
+ const handleKeyDown2 = (0, import_react21.useCallback)(
2728
+ (e) => {
2729
+ if (e.key === "ArrowLeft" || e.key === "ArrowRight" || e.key === "Home" || e.key === "End") {
2730
+ const triggers = Array.from(
2731
+ e.currentTarget.querySelectorAll('[role="menuitem"]')
2732
+ );
2733
+ if (triggers.length > 0) {
2734
+ const current = triggers.indexOf(
2735
+ document.activeElement
2736
+ );
2737
+ let next = current;
2738
+ if (e.key === "ArrowRight")
2739
+ next = current < 0 ? 0 : (current + 1) % triggers.length;
2740
+ else if (e.key === "ArrowLeft")
2741
+ next = current < 0 ? 0 : (current - 1 + triggers.length) % triggers.length;
2742
+ else if (e.key === "Home") next = 0;
2743
+ else if (e.key === "End") next = triggers.length - 1;
2744
+ if (triggers[next]) {
2745
+ e.preventDefault();
2746
+ triggers[next].focus();
2747
+ }
2748
+ }
2749
+ }
2750
+ onKeyDown == null ? void 0 : onKeyDown(e);
2751
+ },
2752
+ [onKeyDown]
2753
+ );
2754
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", __spreadValues({ role: "menubar", onKeyDown: handleKeyDown2 }, props));
2755
+ }
2756
+ function MenuRoot({
2757
+ children,
2758
+ open: controlledOpen,
2759
+ onOpenChange,
2760
+ setOpen: setOpenDeprecated,
2761
+ animated = true,
2762
+ portal = false,
2763
+ portalRoot = null
2764
+ }) {
2765
+ const [open, setOpenState] = (0, import_react21.useState)(controlledOpen != null ? controlledOpen : false);
2766
+ const [activeId, setActiveId] = (0, import_react21.useState)(null);
2767
+ const menuId = useId();
2768
+ const triggerId = `${menuId}-trigger`;
2769
+ const items = (0, import_react21.useRef)([]);
2770
+ const onOpenChangeCb = onOpenChange != null ? onOpenChange : setOpenDeprecated;
2771
+ (0, import_react21.useEffect)(() => {
2772
+ if (controlledOpen !== void 0) setOpenState(controlledOpen);
2773
+ }, [controlledOpen]);
2774
+ const setOpen = (0, import_react21.useCallback)(
2775
+ (v) => {
2776
+ if (controlledOpen === void 0) setOpenState(v);
2777
+ onOpenChangeCb == null ? void 0 : onOpenChangeCb(v);
2778
+ if (!v) setActiveId(null);
2779
+ },
2780
+ [controlledOpen, onOpenChangeCb]
2781
+ );
2782
+ const focusTrigger = (0, import_react21.useCallback)(() => {
2783
+ var _a;
2784
+ (_a = document.getElementById(triggerId)) == null ? void 0 : _a.focus();
2785
+ }, [triggerId]);
2786
+ const { getReferenceProps, getFloatingProps } = useFloating({
2787
+ placement: "bottom-start",
2788
+ gutter: 8,
2789
+ open,
2790
+ onOpenChange: setOpen,
2791
+ dismiss: { outsidePress: true, escapeKey: false }
2792
+ });
2793
+ const registerItem = (0, import_react21.useCallback)((id, disabled) => {
2794
+ const list = items.current;
2795
+ const existing = list.findIndex((i) => i.id === id);
2796
+ if (existing >= 0) list[existing] = { id, disabled };
2797
+ else list.push({ id, disabled });
2798
+ }, []);
2799
+ const unregisterItem = (0, import_react21.useCallback)((id) => {
2800
+ items.current = items.current.filter((i) => i.id !== id);
2801
+ }, []);
2802
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2803
+ MenuContext.Provider,
2804
+ {
2805
+ value: {
2806
+ open,
2807
+ setOpen,
2808
+ menuId,
2809
+ triggerId,
2810
+ getReferenceProps,
2811
+ getFloatingProps,
2812
+ activeId,
2813
+ setActiveId,
2814
+ items,
2815
+ registerItem,
2816
+ unregisterItem,
2817
+ focusTrigger,
2818
+ animated,
2819
+ portal,
2820
+ portalRoot
2821
+ },
2822
+ children
2823
+ }
2824
+ );
2825
+ }
2826
+ var MenuTrigger = (0, import_react21.forwardRef)(
2827
+ (_a, ref) => {
2828
+ var _b = _a, { onClick, onKeyDown, role } = _b, props = __objRest(_b, ["onClick", "onKeyDown", "role"]);
2829
+ const { open, setOpen, menuId, triggerId, getReferenceProps } = useMenuContext();
2830
+ const menubarCtx = useMenubarContext();
2831
+ const refProps = getReferenceProps();
2832
+ const handleClick = (0, import_react21.useCallback)(
2833
+ (e) => {
2834
+ setOpen(!open);
2835
+ onClick == null ? void 0 : onClick(e);
2836
+ },
2837
+ [open, setOpen, onClick]
2838
+ );
2839
+ const handleKeyDown2 = (0, import_react21.useCallback)(
2840
+ (e) => {
2841
+ if (e.key === "ArrowDown" || e.key === "Enter" || e.key === " ") {
2842
+ e.preventDefault();
2843
+ setOpen(true);
2844
+ }
2845
+ onKeyDown == null ? void 0 : onKeyDown(e);
2846
+ },
2847
+ [setOpen, onKeyDown]
2848
+ );
2849
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2850
+ "button",
2851
+ __spreadValues({
2852
+ ref: (node) => {
2853
+ if (refProps.ref && typeof refProps.ref === "function") {
2854
+ refProps.ref(node);
2855
+ }
2856
+ if (typeof ref === "function") ref(node);
2857
+ else if (ref) ref.current = node;
2858
+ },
2859
+ type: "button",
2860
+ role: role != null ? role : menubarCtx ? "menuitem" : void 0,
2861
+ id: triggerId,
2862
+ "aria-expanded": open,
2863
+ "aria-haspopup": "menu",
2864
+ "aria-controls": open ? menuId : void 0,
2865
+ "data-menu-trigger": menuId,
2866
+ onClick: handleClick,
2867
+ onKeyDown: handleKeyDown2
2868
+ }, props)
2869
+ );
2870
+ }
2871
+ );
2872
+ MenuTrigger.displayName = "MenuTrigger";
2873
+ function MenuPopover(_a) {
2874
+ var _b = _a, {
2875
+ children,
2876
+ onKeyDown
2877
+ } = _b, props = __objRest(_b, [
2878
+ "children",
2879
+ "onKeyDown"
2880
+ ]);
2881
+ const {
2882
+ open,
2883
+ setOpen,
2884
+ menuId,
2885
+ triggerId,
2886
+ getFloatingProps,
2887
+ items,
2888
+ activeId,
2889
+ setActiveId,
2890
+ focusTrigger,
2891
+ animated,
2892
+ portal,
2893
+ portalRoot
2894
+ } = useMenuContext();
2895
+ const { ref, mounted, dataAttributes } = useEnterLeave(open, { animated });
2896
+ const floatingProps = getFloatingProps();
2897
+ const menuRef = (0, import_react21.useRef)(null);
2898
+ const typeahead = (0, import_react21.useRef)({
2899
+ buffer: "",
2900
+ timer: 0
2901
+ });
2902
+ const activate = (0, import_react21.useCallback)(() => {
2903
+ var _a2;
2904
+ if (activeId) (_a2 = document.getElementById(activeId)) == null ? void 0 : _a2.click();
2905
+ }, [activeId]);
2906
+ const runTypeahead = (0, import_react21.useCallback)(
2907
+ (char) => {
2908
+ const t = typeahead.current;
2909
+ window.clearTimeout(t.timer);
2910
+ t.buffer += char.toLowerCase();
2911
+ t.timer = window.setTimeout(() => {
2912
+ t.buffer = "";
2913
+ }, 500);
2914
+ const match = items.current.filter((i) => !i.disabled).find(
2915
+ (i) => {
2916
+ var _a2, _b2;
2917
+ return (_b2 = (_a2 = document.getElementById(i.id)) == null ? void 0 : _a2.textContent) == null ? void 0 : _b2.trim().toLowerCase().startsWith(t.buffer);
2918
+ }
2919
+ );
2920
+ if (match) setActiveId(match.id);
2921
+ },
2922
+ [items, setActiveId]
2923
+ );
2924
+ const handleKeyDown2 = (0, import_react21.useCallback)(
2925
+ (e) => {
2926
+ var _a2, _b2;
2927
+ switch (e.key) {
2928
+ case "ArrowDown":
2929
+ e.preventDefault();
2930
+ setActiveId(moveActiveId3(items.current, activeId, 1));
2931
+ break;
2932
+ case "ArrowUp":
2933
+ e.preventDefault();
2934
+ setActiveId(moveActiveId3(items.current, activeId, -1));
2935
+ break;
2936
+ case "Home":
2937
+ e.preventDefault();
2938
+ setActiveId(firstEnabledId3(items.current));
2939
+ break;
2940
+ case "End": {
2941
+ e.preventDefault();
2942
+ const enabled = items.current.filter((i) => !i.disabled);
2943
+ setActiveId((_b2 = (_a2 = enabled[enabled.length - 1]) == null ? void 0 : _a2.id) != null ? _b2 : null);
2944
+ break;
2945
+ }
2946
+ case "Enter":
2947
+ case " ":
2948
+ e.preventDefault();
2949
+ activate();
2950
+ break;
2951
+ case "Escape":
2952
+ e.preventDefault();
2953
+ setOpen(false);
2954
+ focusTrigger();
2955
+ break;
2956
+ case "Tab":
2957
+ setOpen(false);
2958
+ break;
2959
+ default:
2960
+ if (e.key.length === 1 && e.key !== " " && !e.metaKey && !e.ctrlKey && !e.altKey && !e.nativeEvent.isComposing) {
2961
+ runTypeahead(e.key);
2962
+ }
2963
+ }
2964
+ onKeyDown == null ? void 0 : onKeyDown(e);
2965
+ },
2966
+ [
2967
+ activeId,
2968
+ items,
2969
+ setActiveId,
2970
+ setOpen,
2971
+ focusTrigger,
2972
+ activate,
2973
+ runTypeahead,
2974
+ onKeyDown
2975
+ ]
2976
+ );
2977
+ (0, import_react21.useLayoutEffect)(() => {
2978
+ var _a2;
2979
+ if (mounted) {
2980
+ (_a2 = menuRef.current) == null ? void 0 : _a2.focus();
2981
+ setActiveId((prev) => prev != null ? prev : firstEnabledId3(items.current));
2982
+ }
2983
+ }, [mounted, items, setActiveId]);
2984
+ useScrollActiveDescendantIntoView(activeId);
2985
+ if (!mounted) return null;
2986
+ const node = /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2987
+ "div",
2988
+ __spreadProps(__spreadValues(__spreadValues({
2989
+ ref: (n) => {
2990
+ menuRef.current = n;
2991
+ ref.current = n;
2992
+ if (floatingProps.ref && typeof floatingProps.ref === "function") {
2993
+ floatingProps.ref(n);
2994
+ }
2995
+ },
2996
+ id: menuId,
2997
+ role: "menu",
2998
+ "aria-labelledby": triggerId,
2999
+ "aria-activedescendant": activeId != null ? activeId : void 0,
3000
+ "data-menu-id": menuId,
3001
+ style: floatingProps.style,
3002
+ tabIndex: -1,
3003
+ onKeyDown: handleKeyDown2
3004
+ }, dataAttributes), props), {
3005
+ children
3006
+ })
3007
+ );
3008
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(OverlayPortal, { portal, portalRoot, children: node });
3009
+ }
3010
+ function useMenuItemRegistration(disabled) {
3011
+ const { registerItem, unregisterItem, activeId } = useMenuContext();
3012
+ const itemId = useId();
3013
+ (0, import_react21.useLayoutEffect)(() => {
3014
+ registerItem(itemId, disabled);
3015
+ return () => unregisterItem(itemId);
3016
+ }, [itemId, disabled, registerItem, unregisterItem]);
3017
+ return { itemId, isActive: activeId === itemId };
3018
+ }
3019
+ function MenuItem(_a) {
3020
+ var _b = _a, {
3021
+ disabled,
3022
+ hideOnClick = true,
3023
+ onClick,
3024
+ children
3025
+ } = _b, props = __objRest(_b, [
3026
+ "disabled",
3027
+ "hideOnClick",
3028
+ "onClick",
3029
+ "children"
3030
+ ]);
3031
+ const { setOpen, focusTrigger } = useMenuContext();
3032
+ const { itemId, isActive } = useMenuItemRegistration(disabled);
3033
+ const handleClick = (0, import_react21.useCallback)(
3034
+ (e) => {
3035
+ if (disabled) return;
3036
+ onClick == null ? void 0 : onClick(e);
3037
+ if (hideOnClick) {
3038
+ setOpen(false);
3039
+ focusTrigger();
3040
+ }
3041
+ },
3042
+ [disabled, onClick, hideOnClick, setOpen, focusTrigger]
3043
+ );
3044
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3045
+ "div",
3046
+ __spreadProps(__spreadValues({
3047
+ id: itemId,
3048
+ role: "menuitem",
3049
+ tabIndex: -1,
3050
+ "aria-disabled": disabled || void 0,
3051
+ "data-active-item": isActive ? "" : void 0,
3052
+ "data-disabled": disabled ? "" : void 0,
3053
+ onClick: handleClick
3054
+ }, props), {
3055
+ children
3056
+ })
3057
+ );
3058
+ }
3059
+ function MenuItemCheckbox(_a) {
3060
+ var _b = _a, {
3061
+ checked = false,
3062
+ onChange,
3063
+ disabled,
3064
+ onClick,
3065
+ children
3066
+ } = _b, props = __objRest(_b, [
3067
+ "checked",
3068
+ "onChange",
3069
+ "disabled",
3070
+ "onClick",
3071
+ "children"
3072
+ ]);
3073
+ const { itemId, isActive } = useMenuItemRegistration(disabled);
3074
+ const handleClick = (0, import_react21.useCallback)(
3075
+ (e) => {
3076
+ if (disabled) return;
3077
+ onChange == null ? void 0 : onChange(!checked);
3078
+ onClick == null ? void 0 : onClick(e);
3079
+ },
3080
+ [disabled, checked, onChange, onClick]
3081
+ );
3082
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3083
+ "div",
3084
+ __spreadProps(__spreadValues({
3085
+ id: itemId,
3086
+ role: "menuitemcheckbox",
3087
+ "aria-checked": checked,
3088
+ "aria-disabled": disabled || void 0,
3089
+ "data-active-item": isActive ? "" : void 0,
3090
+ "data-disabled": disabled ? "" : void 0,
3091
+ tabIndex: -1,
3092
+ onClick: handleClick
3093
+ }, props), {
3094
+ children
3095
+ })
3096
+ );
3097
+ }
3098
+ function MenuItemRadio(_a) {
3099
+ var _b = _a, {
3100
+ checked = false,
3101
+ onChange,
3102
+ disabled,
3103
+ onClick,
3104
+ children
3105
+ } = _b, props = __objRest(_b, [
3106
+ "checked",
3107
+ "onChange",
3108
+ "disabled",
3109
+ "onClick",
3110
+ "children"
3111
+ ]);
3112
+ const { itemId, isActive } = useMenuItemRegistration(disabled);
3113
+ const handleClick = (0, import_react21.useCallback)(
3114
+ (e) => {
3115
+ if (disabled) return;
3116
+ onChange == null ? void 0 : onChange(!checked);
3117
+ onClick == null ? void 0 : onClick(e);
3118
+ },
3119
+ [disabled, checked, onChange, onClick]
3120
+ );
3121
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3122
+ "div",
3123
+ __spreadProps(__spreadValues({
3124
+ id: itemId,
3125
+ role: "menuitemradio",
3126
+ "aria-checked": checked,
3127
+ "aria-disabled": disabled || void 0,
3128
+ "data-active-item": isActive ? "" : void 0,
3129
+ "data-disabled": disabled ? "" : void 0,
3130
+ tabIndex: -1,
3131
+ onClick: handleClick
3132
+ }, props), {
3133
+ children
3134
+ })
3135
+ );
3136
+ }
3137
+ function MenuSeparator(props) {
3138
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("hr", __spreadValues({ role: "separator" }, props));
3139
+ }
3140
+ function MenuButtonArrow(props) {
3141
+ const { open } = useMenuContext();
3142
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", __spreadProps(__spreadValues({ "aria-hidden": "true", "data-expanded": open ? "" : void 0 }, props), { children: "\u25BE" }));
3143
+ }
3144
+
3145
+ // src/primitives/toolbar.tsx
3146
+ var import_react22 = require("react");
3147
+ var import_jsx_runtime13 = require("react/jsx-runtime");
3148
+ function firstEnabledId4(items) {
3149
+ var _a, _b;
3150
+ return (_b = (_a = items.find((i) => !i.disabled)) == null ? void 0 : _a.id) != null ? _b : null;
3151
+ }
3152
+ function moveActiveId4(items, activeId, delta) {
3153
+ const enabled = items.filter((i) => !i.disabled);
3154
+ if (enabled.length === 0) return null;
3155
+ const idx = enabled.findIndex((i) => i.id === activeId);
3156
+ if (idx < 0) {
3157
+ return delta > 0 ? enabled[0].id : enabled[enabled.length - 1].id;
3158
+ }
3159
+ const next = Math.min(enabled.length - 1, Math.max(0, idx + delta));
3160
+ return enabled[next].id;
3161
+ }
3162
+ var ToolbarContext = (0, import_react22.createContext)(null);
3163
+ function useToolbarContext() {
3164
+ const ctx = (0, import_react22.useContext)(ToolbarContext);
3165
+ if (!ctx)
3166
+ throw new Error("Toolbar components must be used within ToolbarRoot");
3167
+ return ctx;
3168
+ }
3169
+ function ToolbarRoot({
3170
+ children,
3171
+ orientation = "horizontal"
3172
+ }) {
3173
+ const [activeId, setActiveId] = (0, import_react22.useState)(null);
3174
+ const items = (0, import_react22.useRef)([]);
3175
+ const registerItem = (0, import_react22.useCallback)((entry) => {
3176
+ const list = items.current;
3177
+ const existing = list.findIndex((i) => i.id === entry.id);
3178
+ if (existing >= 0) list[existing] = entry;
3179
+ else list.push(entry);
3180
+ }, []);
3181
+ const unregisterItem = (0, import_react22.useCallback)((id) => {
3182
+ items.current = items.current.filter((i) => i.id !== id);
3183
+ setActiveId((prev) => prev === id ? firstEnabledId4(items.current) : prev);
3184
+ }, []);
3185
+ (0, import_react22.useLayoutEffect)(() => {
3186
+ setActiveId((prev) => prev != null ? prev : firstEnabledId4(items.current));
3187
+ }, [activeId]);
3188
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
3189
+ ToolbarContext.Provider,
3190
+ {
3191
+ value: {
3192
+ orientation,
3193
+ activeId,
3194
+ setActiveId,
3195
+ registerItem,
3196
+ unregisterItem,
3197
+ items
3198
+ },
3199
+ children
3200
+ }
3201
+ );
3202
+ }
3203
+ function ToolbarContainer(_a) {
3204
+ var _b = _a, {
3205
+ onKeyDown
3206
+ } = _b, props = __objRest(_b, [
3207
+ "onKeyDown"
3208
+ ]);
3209
+ const { orientation, activeId, setActiveId, items } = useToolbarContext();
3210
+ const focusActive = (0, import_react22.useCallback)(
3211
+ (id) => {
3212
+ var _a2, _b2;
3213
+ if (!id) return;
3214
+ (_b2 = (_a2 = items.current.find((i) => i.id === id)) == null ? void 0 : _a2.element) == null ? void 0 : _b2.focus();
3215
+ },
3216
+ [items]
3217
+ );
3218
+ const handleKeyDown2 = (0, import_react22.useCallback)(
3219
+ (e) => {
3220
+ var _a2, _b2;
3221
+ const prevKey = orientation === "vertical" ? "ArrowUp" : "ArrowLeft";
3222
+ const nextKey = orientation === "vertical" ? "ArrowDown" : "ArrowRight";
3223
+ let nextId;
3224
+ if (e.key === nextKey) {
3225
+ e.preventDefault();
3226
+ nextId = moveActiveId4(items.current, activeId, 1);
3227
+ } else if (e.key === prevKey) {
3228
+ e.preventDefault();
3229
+ nextId = moveActiveId4(items.current, activeId, -1);
3230
+ } else if (e.key === "Home") {
3231
+ e.preventDefault();
3232
+ nextId = firstEnabledId4(items.current);
3233
+ } else if (e.key === "End") {
3234
+ e.preventDefault();
3235
+ const enabled = items.current.filter((i) => !i.disabled);
3236
+ nextId = (_b2 = (_a2 = enabled[enabled.length - 1]) == null ? void 0 : _a2.id) != null ? _b2 : null;
3237
+ }
3238
+ if (nextId) {
3239
+ setActiveId(nextId);
3240
+ focusActive(nextId);
3241
+ }
3242
+ onKeyDown == null ? void 0 : onKeyDown(e);
3243
+ },
3244
+ [orientation, activeId, setActiveId, items, focusActive, onKeyDown]
3245
+ );
3246
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
3247
+ "div",
3248
+ __spreadValues({
3249
+ role: "toolbar",
3250
+ "aria-orientation": orientation,
3251
+ onKeyDown: handleKeyDown2
3252
+ }, props)
3253
+ );
3254
+ }
3255
+ function ToolbarButton(_a) {
3256
+ var _b = _a, {
3257
+ disabled,
3258
+ onFocus
3259
+ } = _b, props = __objRest(_b, [
3260
+ "disabled",
3261
+ "onFocus"
3262
+ ]);
3263
+ const { registerItem, unregisterItem, activeId, setActiveId } = useToolbarContext();
3264
+ const itemId = useId();
3265
+ const buttonRef = (0, import_react22.useRef)(null);
3266
+ const isActive = activeId === itemId;
3267
+ (0, import_react22.useLayoutEffect)(() => {
3268
+ registerItem({ id: itemId, element: buttonRef.current, disabled });
3269
+ return () => unregisterItem(itemId);
3270
+ }, [itemId, disabled, registerItem, unregisterItem]);
3271
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
3272
+ "button",
3273
+ __spreadValues({
3274
+ ref: buttonRef,
3275
+ type: "button",
3276
+ disabled,
3277
+ tabIndex: isActive ? 0 : -1,
3278
+ onFocus: (e) => {
3279
+ if (!disabled) setActiveId(itemId);
3280
+ onFocus == null ? void 0 : onFocus(e);
3281
+ }
3282
+ }, props)
3283
+ );
3284
+ }
3285
+ function ToolbarSeparator(props) {
3286
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("hr", __spreadValues({ role: "separator", "aria-orientation": "vertical" }, props));
3287
+ }
3288
+
3289
+ // src/primitives/composite.tsx
3290
+ var import_react23 = require("react");
3291
+ var import_jsx_runtime14 = require("react/jsx-runtime");
3292
+ function firstEnabledFrom(list, start, dir, loop) {
3293
+ const n = list.length;
3294
+ if (n === 0) return -1;
3295
+ let i = start;
3296
+ for (let guard = 0; guard <= n; guard++) {
3297
+ if (i >= 0 && i < n && !list[i].disabled) return i;
3298
+ i += dir;
3299
+ if (loop) i = (i % n + n) % n;
3300
+ else if (i < 0 || i >= n) return -1;
3301
+ }
3302
+ return -1;
3303
+ }
3304
+ var CompositeContext = (0, import_react23.createContext)(null);
3305
+ function useCompositeContext() {
3306
+ const ctx = (0, import_react23.useContext)(CompositeContext);
3307
+ if (!ctx)
3308
+ throw new Error(
3309
+ "Composite components must be used within CompositeProvider"
3310
+ );
3311
+ return ctx;
3312
+ }
3313
+ function CompositeProvider({
3314
+ children,
3315
+ focusLoop = false,
3316
+ focusWrap = false,
3317
+ orientation = "both",
3318
+ activeId: controlledActiveId,
3319
+ onActiveIdChange,
3320
+ setActiveId: setActiveIdDeprecated
3321
+ }) {
3322
+ const [internalActiveId, setInternalActiveId] = (0, import_react23.useState)(null);
3323
+ const items = (0, import_react23.useRef)([]);
3324
+ const onActiveIdChangeCb = onActiveIdChange != null ? onActiveIdChange : setActiveIdDeprecated;
3325
+ const activeId = controlledActiveId !== void 0 ? controlledActiveId : internalActiveId;
3326
+ const activeIdRef = (0, import_react23.useRef)(activeId);
3327
+ activeIdRef.current = activeId;
3328
+ const seededRef = (0, import_react23.useRef)(false);
3329
+ const setActiveId = (0, import_react23.useCallback)(
3330
+ (id) => {
3331
+ if (controlledActiveId === void 0) setInternalActiveId(id);
3332
+ onActiveIdChangeCb == null ? void 0 : onActiveIdChangeCb(id);
3333
+ },
3334
+ [controlledActiveId, onActiveIdChangeCb]
3335
+ );
3336
+ const registerItem = (0, import_react23.useCallback)(
3337
+ (id, element, row = 0, col = 0, disabled = false) => {
3338
+ const list = items.current;
3339
+ const existing = list.findIndex((i) => i.id === id);
3340
+ const activeBecameDisabled = existing >= 0 && id === activeIdRef.current && disabled;
3341
+ if (existing >= 0) {
3342
+ list[existing] = { id, element, row, col, disabled };
3343
+ } else {
3344
+ list.push({ id, element, row, col, disabled });
3345
+ }
3346
+ if (controlledActiveId !== void 0) return;
3347
+ if (activeIdRef.current === null && !seededRef.current && !disabled) {
3348
+ seededRef.current = true;
3349
+ activeIdRef.current = id;
3350
+ setActiveId(id);
3351
+ } else if (activeBecameDisabled) {
3352
+ const idx = firstEnabledFrom(list, 0, 1, false);
3353
+ const nextId = idx >= 0 ? list[idx].id : null;
3354
+ activeIdRef.current = nextId;
3355
+ if (nextId === null) {
3356
+ seededRef.current = false;
3357
+ setInternalActiveId(null);
3358
+ } else {
3359
+ setActiveId(nextId);
3360
+ }
3361
+ }
3362
+ },
3363
+ [controlledActiveId, setActiveId]
3364
+ );
3365
+ const unregisterItem = (0, import_react23.useCallback)(
3366
+ (id) => {
3367
+ items.current = items.current.filter((i) => i.id !== id);
3368
+ if (controlledActiveId === void 0) {
3369
+ setInternalActiveId((prev) => {
3370
+ if (prev !== id) return prev;
3371
+ const idx = firstEnabledFrom(items.current, 0, 1, false);
3372
+ const nextId = idx >= 0 ? items.current[idx].id : null;
3373
+ activeIdRef.current = nextId;
3374
+ if (nextId === null) seededRef.current = false;
3375
+ return nextId;
3376
+ });
3377
+ }
3378
+ },
3379
+ [controlledActiveId]
3380
+ );
3381
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
3382
+ CompositeContext.Provider,
3383
+ {
3384
+ value: {
3385
+ activeId,
3386
+ setActiveId,
3387
+ registerItem,
3388
+ unregisterItem,
3389
+ items,
3390
+ focusLoop,
3391
+ focusWrap,
3392
+ orientation
3393
+ },
3394
+ children
3395
+ }
3396
+ );
3397
+ }
3398
+ function Composite(_a) {
3399
+ var _b = _a, { onKeyDown, render } = _b, props = __objRest(_b, ["onKeyDown", "render"]);
3400
+ const { activeId, setActiveId, items, focusLoop, focusWrap, orientation } = useCompositeContext();
3401
+ const handleKeyDown2 = (0, import_react23.useCallback)(
3402
+ (e) => {
3403
+ var _a2, _b2, _c, _d;
3404
+ const list = items.current;
3405
+ const currentIndex = list.findIndex((i) => i.id === activeId);
3406
+ if (currentIndex < 0) return;
3407
+ let nextIndex = -1;
3408
+ const { row, col } = list[currentIndex];
3409
+ const isHorizontal = orientation !== "vertical";
3410
+ const isVertical = orientation !== "horizontal";
3411
+ const navigate = (offset2) => {
3412
+ const dir = offset2 >= 0 ? 1 : -1;
3413
+ let target = currentIndex + offset2;
3414
+ if (focusLoop) {
3415
+ target = (target % list.length + list.length) % list.length;
3416
+ } else if (focusWrap && (target < 0 || target >= list.length)) {
3417
+ return void 0;
3418
+ } else {
3419
+ target = Math.max(0, Math.min(list.length - 1, target));
3420
+ }
3421
+ const enabled = firstEnabledFrom(list, target, dir, focusLoop);
3422
+ return enabled >= 0 ? enabled : void 0;
3423
+ };
3424
+ const navigateRow = (dir) => {
3425
+ const sibling = list.find(
3426
+ (i) => i.col === col && i.row === row + dir && !i.disabled
3427
+ );
3428
+ if (sibling) return list.indexOf(sibling);
3429
+ return navigate(dir);
3430
+ };
3431
+ switch (e.key) {
3432
+ case "ArrowRight":
3433
+ if (!isHorizontal) break;
3434
+ e.preventDefault();
3435
+ nextIndex = (_a2 = navigate(1)) != null ? _a2 : currentIndex;
3436
+ break;
3437
+ case "ArrowLeft":
3438
+ if (!isHorizontal) break;
3439
+ e.preventDefault();
3440
+ nextIndex = (_b2 = navigate(-1)) != null ? _b2 : currentIndex;
3441
+ break;
3442
+ case "ArrowDown":
3443
+ if (!isVertical) break;
3444
+ e.preventDefault();
3445
+ nextIndex = (_c = navigateRow(1)) != null ? _c : currentIndex;
3446
+ break;
3447
+ case "ArrowUp":
3448
+ if (!isVertical) break;
3449
+ e.preventDefault();
3450
+ nextIndex = (_d = navigateRow(-1)) != null ? _d : currentIndex;
3451
+ break;
3452
+ case "Home":
3453
+ e.preventDefault();
3454
+ nextIndex = firstEnabledFrom(list, 0, 1, false);
3455
+ break;
3456
+ case "End":
3457
+ e.preventDefault();
3458
+ nextIndex = firstEnabledFrom(list, list.length - 1, -1, false);
3459
+ break;
3460
+ }
3461
+ if (nextIndex >= 0 && list[nextIndex]) {
3462
+ setActiveId(list[nextIndex].id);
3463
+ list[nextIndex].element.focus();
3464
+ }
3465
+ onKeyDown == null ? void 0 : onKeyDown(e);
3466
+ },
3467
+ [
3468
+ activeId,
3469
+ items,
3470
+ focusLoop,
3471
+ focusWrap,
3472
+ orientation,
3473
+ setActiveId,
3474
+ onKeyDown
3475
+ ]
3476
+ );
3477
+ if (render && (0, import_react23.isValidElement)(render)) {
3478
+ const merged = mergeProps(
3479
+ render.props,
3480
+ { onKeyDown: handleKeyDown2 },
3481
+ props
3482
+ );
3483
+ return (0, import_react23.cloneElement)(
3484
+ render,
3485
+ merged
3486
+ );
3487
+ }
3488
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", __spreadValues({ onKeyDown: handleKeyDown2 }, props));
3489
+ }
3490
+ function CompositeRow(_a) {
3491
+ var _b = _a, { render } = _b, props = __objRest(_b, ["render"]);
3492
+ if (render && (0, import_react23.isValidElement)(render)) {
3493
+ const merged = mergeProps(
3494
+ render.props,
3495
+ { role: "row" },
3496
+ props
3497
+ );
3498
+ return (0, import_react23.cloneElement)(
3499
+ render,
3500
+ merged
3501
+ );
3502
+ }
3503
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", __spreadValues({ role: "row" }, props));
3504
+ }
3505
+ function CompositeItem(_a) {
3506
+ var _b = _a, {
3507
+ id: providedId,
3508
+ row = 0,
3509
+ col = 0,
3510
+ disabled,
3511
+ render,
3512
+ onFocus
3513
+ } = _b, props = __objRest(_b, [
3514
+ "id",
3515
+ "row",
3516
+ "col",
3517
+ "disabled",
3518
+ "render",
3519
+ "onFocus"
3520
+ ]);
3521
+ const id = useId(providedId);
3522
+ const { activeId, setActiveId, registerItem, unregisterItem } = useCompositeContext();
3523
+ const ref = (0, import_react23.useRef)(null);
3524
+ const isActive = activeId === id;
3525
+ (0, import_react23.useEffect)(() => {
3526
+ if (ref.current) registerItem(id, ref.current, row, col, disabled);
3527
+ return () => unregisterItem(id);
3528
+ }, [id, row, col, disabled, registerItem, unregisterItem]);
3529
+ const sharedProps = __spreadValues({
3530
+ tabIndex: isActive && !disabled ? 0 : -1,
3531
+ "data-active-item": isActive ? "" : void 0,
3532
+ "aria-disabled": disabled || void 0,
3533
+ // Compose with any consumer-supplied onFocus (previously clobbered by the
3534
+ // spread of `...props`).
3535
+ onFocus: (e) => {
3536
+ if (!disabled) setActiveId(id);
3537
+ onFocus == null ? void 0 : onFocus(e);
3538
+ }
3539
+ }, props);
3540
+ if (render && (0, import_react23.isValidElement)(render)) {
3541
+ const renderRef = render.props.ref;
3542
+ const merged = mergeProps(
3543
+ render.props,
3544
+ sharedProps
3545
+ );
3546
+ return (0, import_react23.cloneElement)(render, __spreadProps(__spreadValues({}, merged), {
3547
+ ref: renderRef ? mergeRefs(ref, renderRef) : ref
3548
+ }));
3549
+ }
3550
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
3551
+ "button",
3552
+ __spreadProps(__spreadValues({
3553
+ type: "button",
3554
+ disabled
3555
+ }, sharedProps), {
3556
+ ref
3557
+ })
3558
+ );
3559
+ }
3560
+
3561
+ // src/primitives/separator.tsx
3562
+ var import_react24 = require("react");
3563
+ var import_jsx_runtime15 = require("react/jsx-runtime");
3564
+ var Separator = (0, import_react24.forwardRef)(
3565
+ function Separator2(_a, ref) {
3566
+ var _b = _a, { orientation = "horizontal", decorative = false } = _b, props = __objRest(_b, ["orientation", "decorative"]);
3567
+ const semanticProps = decorative ? { role: "none" } : { role: "separator", "aria-orientation": orientation };
3568
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
3569
+ "div",
3570
+ __spreadValues(__spreadValues({
3571
+ ref,
3572
+ "data-orientation": orientation
3573
+ }, semanticProps), props)
3574
+ );
3575
+ }
3576
+ );
3577
+
3578
+ // src/primitives/toggle.tsx
3579
+ var import_react25 = require("react");
3580
+ var import_jsx_runtime16 = require("react/jsx-runtime");
3581
+ function firstEnabledId5(items) {
3582
+ var _a, _b;
3583
+ return (_b = (_a = items.find((i) => !i.disabled)) == null ? void 0 : _a.id) != null ? _b : null;
3584
+ }
3585
+ function moveActiveId5(items, activeId, delta) {
3586
+ const enabled = items.filter((i) => !i.disabled);
3587
+ if (enabled.length === 0) return null;
3588
+ const idx = enabled.findIndex((i) => i.id === activeId);
3589
+ if (idx < 0)
3590
+ return delta > 0 ? enabled[0].id : enabled[enabled.length - 1].id;
3591
+ const next = Math.min(enabled.length - 1, Math.max(0, idx + delta));
3592
+ return enabled[next].id;
3593
+ }
3594
+ var ToggleGroupContext = (0, import_react25.createContext)(null);
3595
+ function ToggleGroup(_a) {
3596
+ var _b = _a, {
3597
+ value: controlledValue,
3598
+ defaultValue,
3599
+ onValueChange,
3600
+ toggleMultiple = false,
3601
+ orientation = "horizontal",
3602
+ disabled = false,
3603
+ onKeyDown
3604
+ } = _b, props = __objRest(_b, [
3605
+ "value",
3606
+ "defaultValue",
3607
+ "onValueChange",
3608
+ "toggleMultiple",
3609
+ "orientation",
3610
+ "disabled",
3611
+ "onKeyDown"
3612
+ ]);
3613
+ const normalizedDefault = defaultValue != null ? defaultValue : toggleMultiple ? [] : "";
3614
+ const [value, setValue] = useControllableState(
3615
+ normalizedDefault,
3616
+ controlledValue,
3617
+ onValueChange
3618
+ );
3619
+ const selected = (0, import_react25.useMemo)(
3620
+ () => Array.isArray(value) ? value : value === "" ? [] : [value],
3621
+ [value]
3622
+ );
3623
+ const isPressed = (0, import_react25.useCallback)(
3624
+ (v) => selected.includes(v),
3625
+ [selected]
3626
+ );
3627
+ const toggle = (0, import_react25.useCallback)(
3628
+ (v) => {
3629
+ if (toggleMultiple) {
3630
+ const set = new Set(Array.isArray(value) ? value : []);
3631
+ if (set.has(v)) set.delete(v);
3632
+ else set.add(v);
3633
+ setValue([...set]);
3634
+ } else {
3635
+ const current = Array.isArray(value) ? value[0] : value;
3636
+ setValue(current === v ? "" : v);
3637
+ }
3638
+ },
3639
+ [toggleMultiple, value, setValue]
3640
+ );
3641
+ const [activeId, setActiveId] = (0, import_react25.useState)(null);
3642
+ const items = (0, import_react25.useRef)([]);
3643
+ const registerItem = (0, import_react25.useCallback)((entry) => {
3644
+ const list = items.current;
3645
+ const existing = list.findIndex((i) => i.id === entry.id);
3646
+ if (existing >= 0) list[existing] = entry;
3647
+ else list.push(entry);
3648
+ }, []);
3649
+ const unregisterItem = (0, import_react25.useCallback)((id) => {
3650
+ items.current = items.current.filter((i) => i.id !== id);
3651
+ setActiveId((prev) => prev === id ? firstEnabledId5(items.current) : prev);
3652
+ }, []);
3653
+ (0, import_react25.useLayoutEffect)(() => {
3654
+ setActiveId((prev) => prev != null ? prev : firstEnabledId5(items.current));
3655
+ }, [activeId]);
3656
+ const focusActive = (0, import_react25.useCallback)((id) => {
3657
+ var _a2, _b2;
3658
+ if (!id) return;
3659
+ (_b2 = (_a2 = items.current.find((i) => i.id === id)) == null ? void 0 : _a2.element) == null ? void 0 : _b2.focus();
3660
+ }, []);
3661
+ const handleKeyDown2 = (0, import_react25.useCallback)(
3662
+ (e) => {
3663
+ var _a2, _b2;
3664
+ const prevKey = orientation === "vertical" ? "ArrowUp" : "ArrowLeft";
3665
+ const nextKey = orientation === "vertical" ? "ArrowDown" : "ArrowRight";
3666
+ let nextId;
3667
+ if (e.key === nextKey) {
3668
+ e.preventDefault();
3669
+ nextId = moveActiveId5(items.current, activeId, 1);
3670
+ } else if (e.key === prevKey) {
3671
+ e.preventDefault();
3672
+ nextId = moveActiveId5(items.current, activeId, -1);
3673
+ } else if (e.key === "Home") {
3674
+ e.preventDefault();
3675
+ nextId = firstEnabledId5(items.current);
3676
+ } else if (e.key === "End") {
3677
+ e.preventDefault();
3678
+ const enabled = items.current.filter((i) => !i.disabled);
3679
+ nextId = (_b2 = (_a2 = enabled[enabled.length - 1]) == null ? void 0 : _a2.id) != null ? _b2 : null;
3680
+ }
3681
+ if (nextId) {
3682
+ setActiveId(nextId);
3683
+ focusActive(nextId);
3684
+ }
3685
+ onKeyDown == null ? void 0 : onKeyDown(e);
3686
+ },
3687
+ [orientation, activeId, focusActive, onKeyDown]
3688
+ );
3689
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
3690
+ ToggleGroupContext.Provider,
3691
+ {
3692
+ value: {
3693
+ isPressed,
3694
+ toggle,
3695
+ disabled,
3696
+ orientation,
3697
+ activeId,
3698
+ setActiveId,
3699
+ registerItem,
3700
+ unregisterItem,
3701
+ items
3702
+ },
3703
+ children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", __spreadValues({ role: "group", onKeyDown: handleKeyDown2 }, props))
3704
+ }
3705
+ );
3706
+ }
3707
+ function Toggle(_a) {
3708
+ var _b = _a, {
3709
+ pressed: pressedProp,
3710
+ defaultPressed = false,
3711
+ onPressedChange,
3712
+ value,
3713
+ disabled,
3714
+ onClick,
3715
+ onFocus
3716
+ } = _b, props = __objRest(_b, [
3717
+ "pressed",
3718
+ "defaultPressed",
3719
+ "onPressedChange",
3720
+ "value",
3721
+ "disabled",
3722
+ "onClick",
3723
+ "onFocus"
3724
+ ]);
3725
+ const group = (0, import_react25.useContext)(ToggleGroupContext);
3726
+ const itemId = useId();
3727
+ const buttonRef = (0, import_react25.useRef)(null);
3728
+ const [standalonePressed, setStandalonePressed] = useControllableState(
3729
+ defaultPressed,
3730
+ pressedProp,
3731
+ onPressedChange
3732
+ );
3733
+ const inGroup = group !== null;
3734
+ const isDisabled = disabled || inGroup && group.disabled || false;
3735
+ (0, import_react25.useLayoutEffect)(() => {
3736
+ if (!inGroup) return void 0;
3737
+ group.registerItem({
3738
+ id: itemId,
3739
+ element: buttonRef.current,
3740
+ disabled: isDisabled
3741
+ });
3742
+ return () => group.unregisterItem(itemId);
3743
+ }, [inGroup, group, itemId, isDisabled]);
3744
+ const pressed = inGroup && value !== void 0 ? group.isPressed(value) : standalonePressed;
3745
+ const isActive = inGroup ? group.activeId === itemId : void 0;
3746
+ const handleClick = (0, import_react25.useCallback)(
3747
+ (e) => {
3748
+ if (inGroup) {
3749
+ if (value !== void 0) group.toggle(value);
3750
+ } else {
3751
+ setStandalonePressed(!standalonePressed);
3752
+ }
3753
+ onClick == null ? void 0 : onClick(e);
3754
+ },
3755
+ [inGroup, group, value, setStandalonePressed, standalonePressed, onClick]
3756
+ );
3757
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
3758
+ "button",
3759
+ __spreadValues({
3760
+ ref: buttonRef,
3761
+ type: "button",
3762
+ "aria-pressed": pressed,
3763
+ "data-pressed": pressed ? "" : void 0,
3764
+ disabled: isDisabled,
3765
+ tabIndex: inGroup ? isActive ? 0 : -1 : void 0,
3766
+ onClick: handleClick,
3767
+ onFocus: (e) => {
3768
+ if (inGroup && !isDisabled) group.setActiveId(itemId);
3769
+ onFocus == null ? void 0 : onFocus(e);
3770
+ }
3771
+ }, props)
3772
+ );
3773
+ }
3774
+
3775
+ // src/primitives/switch.tsx
3776
+ var import_react26 = require("react");
3777
+
3778
+ // src/internal/visually-hidden.ts
3779
+ var VISUALLY_HIDDEN = {
3780
+ position: "absolute",
3781
+ width: 1,
3782
+ height: 1,
3783
+ padding: 0,
3784
+ margin: -1,
3785
+ overflow: "hidden",
3786
+ clip: "rect(0 0 0 0)",
3787
+ whiteSpace: "nowrap",
3788
+ border: 0
3789
+ };
3790
+
3791
+ // src/primitives/switch.tsx
3792
+ var import_jsx_runtime17 = require("react/jsx-runtime");
3793
+ var Switch = (0, import_react26.forwardRef)(
3794
+ function Switch2(_a, ref) {
3795
+ var _b = _a, {
3796
+ checked,
3797
+ defaultChecked = false,
3798
+ onCheckedChange,
3799
+ disabled = false,
3800
+ name,
3801
+ value = "on",
3802
+ required,
3803
+ onClick
3804
+ } = _b, props = __objRest(_b, [
3805
+ "checked",
3806
+ "defaultChecked",
3807
+ "onCheckedChange",
3808
+ "disabled",
3809
+ "name",
3810
+ "value",
3811
+ "required",
3812
+ "onClick"
3813
+ ]);
3814
+ const [on, setOn] = useControllableState(
3815
+ defaultChecked,
3816
+ checked,
3817
+ onCheckedChange
3818
+ );
3819
+ const handleClick = (0, import_react26.useCallback)(
3820
+ (e) => {
3821
+ if (disabled) return;
3822
+ setOn(!on);
3823
+ onClick == null ? void 0 : onClick(e);
3824
+ },
3825
+ [disabled, on, setOn, onClick]
3826
+ );
3827
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
3828
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
3829
+ "button",
3830
+ __spreadValues({
3831
+ ref,
3832
+ type: "button",
3833
+ role: "switch",
3834
+ "aria-checked": on,
3835
+ disabled,
3836
+ "data-state": on ? "checked" : "unchecked",
3837
+ "data-disabled": disabled ? "" : void 0,
3838
+ onClick: handleClick
3839
+ }, props)
3840
+ ),
3841
+ name != null && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
3842
+ "input",
3843
+ {
3844
+ type: "checkbox",
3845
+ "aria-hidden": true,
3846
+ tabIndex: -1,
3847
+ name,
3848
+ value,
3849
+ checked: on,
3850
+ required,
3851
+ disabled,
3852
+ readOnly: true,
3853
+ style: VISUALLY_HIDDEN
3854
+ }
3855
+ )
3856
+ ] });
3857
+ }
3858
+ );
3859
+
3860
+ // src/primitives/checkbox.tsx
3861
+ var import_react27 = require("react");
3862
+ var import_jsx_runtime18 = require("react/jsx-runtime");
3863
+ var Checkbox = (0, import_react27.forwardRef)(
3864
+ function Checkbox2(_a, ref) {
3865
+ var _b = _a, {
3866
+ checked,
3867
+ defaultChecked = false,
3868
+ indeterminate = false,
3869
+ onCheckedChange,
3870
+ disabled = false,
3871
+ name,
3872
+ value = "on",
3873
+ required,
3874
+ onClick,
3875
+ children
3876
+ } = _b, props = __objRest(_b, [
3877
+ "checked",
3878
+ "defaultChecked",
3879
+ "indeterminate",
3880
+ "onCheckedChange",
3881
+ "disabled",
3882
+ "name",
3883
+ "value",
3884
+ "required",
3885
+ "onClick",
3886
+ "children"
3887
+ ]);
3888
+ const [on, setOn] = useControllableState(
3889
+ defaultChecked,
3890
+ checked,
3891
+ onCheckedChange
3892
+ );
3893
+ const handleClick = (0, import_react27.useCallback)(
3894
+ (e) => {
3895
+ if (disabled) return;
3896
+ setOn(indeterminate ? true : !on);
3897
+ onClick == null ? void 0 : onClick(e);
3898
+ },
3899
+ [disabled, indeterminate, on, setOn, onClick]
3900
+ );
3901
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
3902
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
3903
+ "button",
3904
+ __spreadProps(__spreadValues({
3905
+ ref,
3906
+ type: "button",
3907
+ role: "checkbox",
3908
+ "aria-checked": indeterminate ? "mixed" : on,
3909
+ disabled,
3910
+ "data-state": indeterminate ? "indeterminate" : on ? "checked" : "unchecked",
3911
+ "data-disabled": disabled ? "" : void 0,
3912
+ onClick: handleClick
3913
+ }, props), {
3914
+ children
3915
+ })
3916
+ ),
3917
+ name != null && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
3918
+ "input",
3919
+ {
3920
+ type: "checkbox",
3921
+ "aria-hidden": true,
3922
+ tabIndex: -1,
3923
+ name,
3924
+ value,
3925
+ checked: on,
3926
+ required,
3927
+ disabled,
3928
+ readOnly: true,
3929
+ style: VISUALLY_HIDDEN
3930
+ }
3931
+ )
3932
+ ] });
3933
+ }
3934
+ );
3935
+
3936
+ // src/primitives/progress.tsx
3937
+ var import_react28 = require("react");
3938
+ var import_jsx_runtime19 = require("react/jsx-runtime");
3939
+ function formatPercent(fraction) {
3940
+ return new Intl.NumberFormat(void 0, { style: "percent" }).format(
3941
+ fraction
3942
+ );
3943
+ }
3944
+ var Progress = (0, import_react28.forwardRef)(
3945
+ function Progress2(_a, ref) {
3946
+ var _b = _a, { value = null, min = 0, max = 100, getValueLabel } = _b, props = __objRest(_b, ["value", "min", "max", "getValueLabel"]);
3947
+ const indeterminate = value == null || Number.isNaN(value);
3948
+ const clamped = indeterminate ? null : Math.min(max, Math.max(min, value));
3949
+ const fraction = clamped == null || max === min ? 0 : (clamped - min) / (max - min);
3950
+ const valueText = clamped == null ? void 0 : getValueLabel ? getValueLabel(clamped, min, max) : formatPercent(fraction);
3951
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
3952
+ "div",
3953
+ __spreadValues({
3954
+ ref,
3955
+ role: "progressbar",
3956
+ "aria-valuemin": min,
3957
+ "aria-valuemax": max,
3958
+ "aria-valuenow": clamped != null ? clamped : void 0,
3959
+ "aria-valuetext": valueText,
3960
+ "data-state": indeterminate ? "indeterminate" : fraction >= 1 ? "complete" : "loading",
3961
+ "data-value": clamped != null ? clamped : void 0
3962
+ }, props)
3963
+ );
3964
+ }
3965
+ );
3966
+
3967
+ // src/primitives/meter.tsx
3968
+ var import_react29 = require("react");
3969
+ var import_jsx_runtime20 = require("react/jsx-runtime");
3970
+ function formatPercent2(fraction) {
3971
+ return new Intl.NumberFormat(void 0, { style: "percent" }).format(
3972
+ fraction
3973
+ );
3974
+ }
3975
+ var Meter = (0, import_react29.forwardRef)(function Meter2(_a, ref) {
3976
+ var _b = _a, { value, min = 0, max = 100, getValueLabel } = _b, props = __objRest(_b, ["value", "min", "max", "getValueLabel"]);
3977
+ const clamped = Math.min(max, Math.max(min, value));
3978
+ const fraction = max === min ? 0 : (clamped - min) / (max - min);
3979
+ const valueText = getValueLabel ? getValueLabel(clamped, min, max) : formatPercent2(fraction);
3980
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3981
+ "div",
3982
+ __spreadValues({
3983
+ ref,
3984
+ role: "meter",
3985
+ "aria-valuemin": min,
3986
+ "aria-valuemax": max,
3987
+ "aria-valuenow": clamped,
3988
+ "aria-valuetext": valueText,
3989
+ "data-value": clamped
3990
+ }, props)
3991
+ );
3992
+ });
3993
+
3994
+ // src/primitives/accordion.tsx
3995
+ var import_react30 = require("react");
3996
+ var import_jsx_runtime21 = require("react/jsx-runtime");
3997
+ var AccordionRootContext = (0, import_react30.createContext)(
3998
+ null
3999
+ );
4000
+ function useAccordionRoot() {
4001
+ const ctx = (0, import_react30.useContext)(AccordionRootContext);
4002
+ if (!ctx) {
4003
+ throw new Error("Accordion components must be used within AccordionRoot");
4004
+ }
4005
+ return ctx;
4006
+ }
4007
+ var AccordionItemContext = (0, import_react30.createContext)(
4008
+ null
4009
+ );
4010
+ function useAccordionItem() {
4011
+ const ctx = (0, import_react30.useContext)(AccordionItemContext);
4012
+ if (!ctx) {
4013
+ throw new Error(
4014
+ "AccordionTrigger/AccordionContent must be used within AccordionItem"
4015
+ );
4016
+ }
4017
+ return ctx;
4018
+ }
4019
+ function AccordionRoot({
4020
+ children,
4021
+ type = "single",
4022
+ value: controlledValue,
4023
+ defaultValue,
4024
+ onValueChange,
4025
+ collapsible = false,
4026
+ disabled = false,
4027
+ animated = true
4028
+ }) {
4029
+ const multiple = type === "multiple";
4030
+ const normalizedDefault = defaultValue != null ? defaultValue : multiple ? [] : null;
4031
+ const [value, setValue] = useControllableState(
4032
+ normalizedDefault,
4033
+ controlledValue,
4034
+ onValueChange
4035
+ );
4036
+ const isExpanded = (0, import_react30.useCallback)(
4037
+ (v) => Array.isArray(value) ? value.includes(v) : value === v,
4038
+ [value]
4039
+ );
4040
+ const toggle = (0, import_react30.useCallback)(
4041
+ (v) => {
4042
+ if (multiple) {
4043
+ const set = new Set(Array.isArray(value) ? value : []);
4044
+ if (set.has(v)) set.delete(v);
4045
+ else set.add(v);
4046
+ setValue([...set]);
4047
+ } else {
4048
+ const current = Array.isArray(value) ? value[0] : value;
4049
+ if (current === v) {
4050
+ if (collapsible) setValue(null);
4051
+ } else {
4052
+ setValue(v);
4053
+ }
4054
+ }
4055
+ },
4056
+ [multiple, value, collapsible, setValue]
4057
+ );
4058
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4059
+ AccordionRootContext.Provider,
4060
+ {
4061
+ value: { isExpanded, toggle, disabled, animated },
4062
+ children
4063
+ }
4064
+ );
4065
+ }
4066
+ function AccordionItem(_a) {
4067
+ var _b = _a, {
4068
+ value,
4069
+ disabled = false
4070
+ } = _b, props = __objRest(_b, [
4071
+ "value",
4072
+ "disabled"
4073
+ ]);
4074
+ const root = useAccordionRoot();
4075
+ const baseId = useId();
4076
+ const itemDisabled = disabled || root.disabled;
4077
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4078
+ AccordionItemContext.Provider,
4079
+ {
4080
+ value: {
4081
+ value,
4082
+ triggerId: `${baseId}-trigger`,
4083
+ contentId: `${baseId}-content`,
4084
+ disabled: itemDisabled
4085
+ },
4086
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", __spreadValues({ "data-state": root.isExpanded(value) ? "open" : "closed" }, props))
4087
+ }
4088
+ );
4089
+ }
4090
+ function AccordionTrigger(_a) {
4091
+ var _b = _a, {
4092
+ onClick,
4093
+ disabled
4094
+ } = _b, props = __objRest(_b, [
4095
+ "onClick",
4096
+ "disabled"
4097
+ ]);
4098
+ const root = useAccordionRoot();
4099
+ const item = useAccordionItem();
4100
+ const expanded = root.isExpanded(item.value);
4101
+ const isDisabled = disabled || item.disabled;
4102
+ const handleClick = (0, import_react30.useCallback)(
4103
+ (e) => {
4104
+ if (!isDisabled) root.toggle(item.value);
4105
+ onClick == null ? void 0 : onClick(e);
4106
+ },
4107
+ [isDisabled, root, item.value, onClick]
4108
+ );
4109
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4110
+ "button",
4111
+ __spreadValues({
4112
+ type: "button",
4113
+ id: item.triggerId,
4114
+ "aria-expanded": expanded,
4115
+ "aria-controls": item.contentId,
4116
+ disabled: isDisabled,
4117
+ "data-state": expanded ? "open" : "closed",
4118
+ onClick: handleClick
4119
+ }, props)
4120
+ );
4121
+ }
4122
+ function AccordionContent(_a) {
4123
+ var _b = _a, { style } = _b, props = __objRest(_b, ["style"]);
4124
+ const root = useAccordionRoot();
4125
+ const item = useAccordionItem();
4126
+ const expanded = root.isExpanded(item.value);
4127
+ const { ref, mounted, dataAttributes } = useEnterLeave(expanded, {
4128
+ animated: root.animated
4129
+ });
4130
+ const innerRef = (0, import_react30.useRef)(null);
4131
+ (0, import_react30.useEffect)(() => {
4132
+ if (innerRef.current) {
4133
+ ref.current = innerRef.current;
4134
+ }
4135
+ }, [ref]);
4136
+ if (!mounted) return null;
4137
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4138
+ "div",
4139
+ __spreadValues(__spreadValues({
4140
+ ref: innerRef,
4141
+ id: item.contentId,
4142
+ role: "region",
4143
+ "aria-labelledby": item.triggerId,
4144
+ style
4145
+ }, dataAttributes), props)
4146
+ );
4147
+ }
4148
+
4149
+ // src/form/form-store.ts
4150
+ var import_react31 = require("react");
4151
+ function getByPath(obj, path) {
4152
+ return path.split(".").reduce((acc, key) => {
4153
+ if (acc == null || typeof acc !== "object") return void 0;
4154
+ return acc[key];
4155
+ }, obj);
4156
+ }
4157
+ function setByPath(obj, path, value) {
4158
+ const keys = path.split(".");
4159
+ const result = __spreadValues({}, obj);
4160
+ let current = result;
4161
+ for (let i = 0; i < keys.length - 1; i++) {
4162
+ const key = keys[i];
4163
+ const next = current[key];
4164
+ if (Array.isArray(next)) {
4165
+ current[key] = [...next];
4166
+ } else if (next && typeof next === "object") {
4167
+ current[key] = __spreadValues({}, next);
4168
+ } else {
4169
+ current[key] = {};
4170
+ }
4171
+ current = current[key];
4172
+ }
4173
+ current[keys[keys.length - 1]] = value;
4174
+ return result;
4175
+ }
4176
+ function deepEqual(a, b) {
4177
+ if (a === b) return true;
4178
+ if (a == null || b == null) return false;
4179
+ if (typeof a !== typeof b) return false;
4180
+ if (Array.isArray(a) && Array.isArray(b)) {
4181
+ if (a.length !== b.length) return false;
4182
+ return a.every((v, i) => deepEqual(v, b[i]));
4183
+ }
4184
+ if (typeof a === "object" && typeof b === "object") {
4185
+ const keysA = Object.keys(a);
4186
+ const keysB = Object.keys(b);
4187
+ if (keysA.length !== keysB.length) return false;
4188
+ return keysA.every(
4189
+ (k) => deepEqual(
4190
+ a[k],
4191
+ b[k]
4192
+ )
4193
+ );
4194
+ }
4195
+ return false;
4196
+ }
4197
+ function collectFieldPaths(value, prefix = "") {
4198
+ if (Array.isArray(value)) {
4199
+ if (value.length === 0) {
4200
+ return prefix ? [prefix] : [];
4201
+ }
4202
+ return value.flatMap(
4203
+ (item, index) => collectFieldPaths(item, prefix ? `${prefix}.${index}` : `${index}`)
4204
+ );
4205
+ }
4206
+ if (value && typeof value === "object") {
4207
+ const entries = Object.entries(value);
4208
+ if (entries.length === 0) {
4209
+ return prefix ? [prefix] : [];
4210
+ }
4211
+ return entries.flatMap(
4212
+ ([key, nestedValue]) => collectFieldPaths(nestedValue, prefix ? `${prefix}.${key}` : key)
4213
+ );
4214
+ }
4215
+ return prefix ? [prefix] : [];
4216
+ }
4217
+ function createFormStore(optionsRef) {
4218
+ function getOptions() {
4219
+ return optionsRef.current;
4220
+ }
4221
+ function getDefaultValues() {
4222
+ return __spreadValues({}, getOptions().defaultValues);
4223
+ }
4224
+ function getValidateOn() {
4225
+ var _a;
4226
+ return (_a = getOptions().validateOn) != null ? _a : "change";
4227
+ }
4228
+ let values = getDefaultValues();
4229
+ let validationErrors = {};
4230
+ let injectedErrors = {};
4231
+ let errors = {};
4232
+ let touched = /* @__PURE__ */ new Set();
4233
+ let submitting = false;
4234
+ let submitError = void 0;
4235
+ let validating = false;
4236
+ let version = 0;
4237
+ let submitToken = 0;
4238
+ const listeners = /* @__PURE__ */ new Set();
4239
+ const controls = /* @__PURE__ */ new Map();
4240
+ function notify() {
4241
+ version++;
4242
+ for (const l of listeners) l();
4243
+ }
4244
+ function focusFirstInvalid(errs) {
4245
+ for (const [name, getElement] of controls) {
4246
+ if (!errs[name]) continue;
4247
+ const el = getElement();
4248
+ if (!el) return;
4249
+ el.focus();
4250
+ if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
4251
+ try {
4252
+ el.select();
4253
+ } catch (e) {
4254
+ }
4255
+ }
4256
+ return;
4257
+ }
4258
+ }
4259
+ function recombineErrors() {
4260
+ errors = __spreadValues(__spreadValues({}, injectedErrors), validationErrors);
4261
+ }
4262
+ function runValidation() {
4263
+ var _a;
4264
+ const validate = getOptions().validate;
4265
+ if (!validate) {
4266
+ validationErrors = {};
4267
+ recombineErrors();
4268
+ return errors;
4269
+ }
4270
+ validating = true;
4271
+ try {
4272
+ validationErrors = (_a = validate(values)) != null ? _a : {};
4273
+ } finally {
4274
+ validating = false;
4275
+ }
4276
+ recombineErrors();
4277
+ return errors;
4278
+ }
4279
+ const store = {
4280
+ getValues: () => values,
4281
+ getValue: ((name) => getByPath(values, name)),
4282
+ setValue: ((name, value) => {
4283
+ values = setByPath(values, name, value);
4284
+ touched.add(name);
4285
+ if (name in injectedErrors) {
4286
+ delete injectedErrors[name];
4287
+ recombineErrors();
4288
+ }
4289
+ if (getValidateOn() === "change") {
4290
+ errors = runValidation();
4291
+ }
4292
+ notify();
4293
+ }),
4294
+ getErrors: () => __spreadValues({}, errors),
4295
+ getError: (name) => errors[name],
4296
+ setError: (name, error) => {
4297
+ if (error === void 0) {
4298
+ delete injectedErrors[name];
4299
+ } else {
4300
+ injectedErrors[name] = error;
4301
+ touched.add(name);
4302
+ }
4303
+ recombineErrors();
4304
+ if (!validating) {
4305
+ notify();
4306
+ }
4307
+ },
4308
+ getFieldTouched: (name) => touched.has(name),
4309
+ setFieldTouched: (name, isTouched) => {
4310
+ if (isTouched) {
4311
+ touched.add(name);
4312
+ if (getValidateOn() === "blur") {
4313
+ errors = runValidation();
4314
+ }
4315
+ } else {
4316
+ touched.delete(name);
4317
+ }
4318
+ notify();
4319
+ },
4320
+ isDirty: () => {
4321
+ const defaultValues = getDefaultValues();
4322
+ return !deepEqual(values, defaultValues);
4323
+ },
4324
+ isFieldDirty: (name) => {
4325
+ const defaultValues = getDefaultValues();
4326
+ return !deepEqual(
4327
+ getByPath(values, name),
4328
+ getByPath(defaultValues, name)
4329
+ );
4330
+ },
4331
+ validate: () => {
4332
+ errors = runValidation();
4333
+ for (const key of collectFieldPaths(values)) {
4334
+ touched.add(key);
4335
+ }
4336
+ for (const key of Object.keys(errors)) {
4337
+ touched.add(key);
4338
+ }
4339
+ notify();
4340
+ return errors;
4341
+ },
4342
+ reset: () => {
4343
+ values = getDefaultValues();
4344
+ validationErrors = {};
4345
+ injectedErrors = {};
4346
+ errors = {};
4347
+ touched = /* @__PURE__ */ new Set();
4348
+ submitting = false;
4349
+ submitError = void 0;
4350
+ submitToken += 1;
4351
+ notify();
4352
+ },
4353
+ resetField: (name) => {
4354
+ const defaultValues = getDefaultValues();
4355
+ const defaultVal = getByPath(defaultValues, name);
4356
+ values = setByPath(values, name, defaultVal);
4357
+ delete validationErrors[name];
4358
+ delete injectedErrors[name];
4359
+ recombineErrors();
4360
+ touched.delete(name);
4361
+ notify();
4362
+ },
4363
+ registerControl: (name, getElement) => {
4364
+ controls.set(name, getElement);
4365
+ return () => {
4366
+ if (controls.get(name) === getElement) controls.delete(name);
4367
+ };
4368
+ },
4369
+ submit: (e) => {
4370
+ var _a, _b, _c;
4371
+ (_a = e == null ? void 0 : e.preventDefault) == null ? void 0 : _a.call(e);
4372
+ if (submitting) return;
4373
+ submitError = void 0;
4374
+ const errs = store.validate();
4375
+ if (Object.keys(errs).length > 0) {
4376
+ focusFirstInvalid(errs);
4377
+ return;
4378
+ }
4379
+ const result = (_c = (_b = getOptions()).onSubmit) == null ? void 0 : _c.call(_b, values);
4380
+ if (result && typeof result === "object" && "then" in result) {
4381
+ const token = submitToken += 1;
4382
+ submitting = true;
4383
+ notify();
4384
+ result.then(
4385
+ () => {
4386
+ if (token !== submitToken) return;
4387
+ submitting = false;
4388
+ notify();
4389
+ },
4390
+ (err) => {
4391
+ if (token !== submitToken) return;
4392
+ submitting = false;
4393
+ submitError = err;
4394
+ notify();
4395
+ }
4396
+ );
4397
+ }
4398
+ },
4399
+ isSubmitting: () => submitting,
4400
+ getSubmitError: () => submitError,
4401
+ push: ((name, item) => {
4402
+ const arr = getByPath(values, name);
4403
+ const newArr = Array.isArray(arr) ? [...arr, item] : [item];
4404
+ values = setByPath(values, name, newArr);
4405
+ touched.add(name);
4406
+ if (getValidateOn() === "change") {
4407
+ errors = runValidation();
4408
+ }
4409
+ notify();
4410
+ }),
4411
+ remove: (name, index) => {
4412
+ const arr = getByPath(values, name);
4413
+ if (Array.isArray(arr)) {
4414
+ const newArr = arr.filter((_, i) => i !== index);
4415
+ values = setByPath(values, name, newArr);
4416
+ touched.add(name);
4417
+ if (getValidateOn() === "change") {
4418
+ errors = runValidation();
4419
+ }
4420
+ notify();
4421
+ }
4422
+ },
4423
+ subscribe: (listener) => {
4424
+ listeners.add(listener);
4425
+ return () => listeners.delete(listener);
4426
+ },
4427
+ getSnapshot: () => version
4428
+ };
4429
+ return store;
4430
+ }
4431
+ function useFormStore(options) {
4432
+ const optionsRef = (0, import_react31.useRef)(options);
4433
+ optionsRef.current = options;
4434
+ const storeRef = (0, import_react31.useRef)(void 0);
4435
+ if (!storeRef.current) {
4436
+ storeRef.current = createFormStore(optionsRef);
4437
+ }
4438
+ (0, import_react31.useSyncExternalStore)(
4439
+ storeRef.current.subscribe,
4440
+ storeRef.current.getSnapshot,
4441
+ storeRef.current.getSnapshot
4442
+ );
4443
+ return storeRef.current;
4444
+ }
4445
+ function useFieldValue(store, name) {
4446
+ const getSnapshot = (0, import_react31.useCallback)(
4447
+ () => store.getValue(name),
4448
+ [store, name]
4449
+ );
4450
+ (0, import_react31.useSyncExternalStore)(store.subscribe, getSnapshot, getSnapshot);
4451
+ return store.getValue(name);
4452
+ }
4453
+ var noopSubscribe = () => () => {
4454
+ };
4455
+ function useFieldValueMaybe(store, name) {
4456
+ const subscribe = (0, import_react31.useCallback)(
4457
+ (cb) => store ? store.subscribe(cb) : noopSubscribe(),
4458
+ [store]
4459
+ );
4460
+ const getSnapshot = (0, import_react31.useCallback)(
4461
+ () => store ? store.getValue(name) : void 0,
4462
+ [store, name]
4463
+ );
4464
+ return (0, import_react31.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
4465
+ }
4466
+ function useStoreSubscription(store) {
4467
+ const subscribe = (0, import_react31.useCallback)(
4468
+ (cb) => store ? store.subscribe(cb) : noopSubscribe(),
4469
+ [store]
4470
+ );
4471
+ const getSnapshot = (0, import_react31.useCallback)(
4472
+ () => store ? store.getSnapshot() : 0,
4473
+ [store]
4474
+ );
4475
+ (0, import_react31.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
4476
+ }
4477
+
4478
+ // src/form/form-context.tsx
4479
+ var import_react32 = require("react");
4480
+ var import_jsx_runtime22 = require("react/jsx-runtime");
4481
+ var FormContext = (0, import_react32.createContext)(null);
4482
+ function FormProvider({
4483
+ store,
4484
+ children
4485
+ }) {
4486
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(FormContext.Provider, { value: store, children });
4487
+ }
4488
+ function useFormContext() {
4489
+ return (0, import_react32.useContext)(FormContext);
4490
+ }
4491
+
4492
+ // src/form/form-primitives.tsx
4493
+ var import_react33 = require("react");
4494
+ var import_jsx_runtime23 = require("react/jsx-runtime");
4495
+ function useRegisterControl(form, name, forwardedRef) {
4496
+ const elRef = (0, import_react33.useRef)(null);
4497
+ (0, import_react33.useEffect)(() => {
4498
+ if (!form) return;
4499
+ return form.registerControl(name, () => elRef.current);
4500
+ }, [form, name]);
4501
+ return (0, import_react33.useMemo)(
4502
+ () => mergeRefs((node) => {
4503
+ elRef.current = node;
4504
+ }, forwardedRef),
4505
+ [forwardedRef]
4506
+ );
4507
+ }
4508
+ var FormFieldContext = (0, import_react33.createContext)(null);
4509
+ function useFormField() {
4510
+ return (0, import_react33.useContext)(FormFieldContext);
4511
+ }
4512
+ function composeDescribedBy(field, hasError, own) {
4513
+ const ids = [
4514
+ own,
4515
+ hasError && field ? field.errorId : null,
4516
+ (field == null ? void 0 : field.hasDescription) ? field.descriptionId : null
4517
+ ].filter(Boolean);
4518
+ return ids.length ? ids.join(" ") : void 0;
4519
+ }
4520
+ function FormRoot(_a) {
4521
+ var _b = _a, { onSubmit } = _b, props = __objRest(_b, ["onSubmit"]);
4522
+ const form = useFormContext();
4523
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
4524
+ "form",
4525
+ __spreadValues({
4526
+ onSubmit: (e) => {
4527
+ e.preventDefault();
4528
+ form == null ? void 0 : form.submit();
4529
+ onSubmit == null ? void 0 : onSubmit(e);
4530
+ }
4531
+ }, props)
4532
+ );
4533
+ }
4534
+ function FormField(_a) {
4535
+ var _b = _a, { name } = _b, props = __objRest(_b, ["name"]);
4536
+ const base = useId();
4537
+ const [hasDescription, setHasDescription] = (0, import_react33.useState)(false);
4538
+ const ctx = (0, import_react33.useMemo)(
4539
+ () => ({
4540
+ name,
4541
+ inputId: `${base}-input`,
4542
+ errorId: `${base}-error`,
4543
+ descriptionId: `${base}-description`,
4544
+ hasDescription,
4545
+ setHasDescription
4546
+ }),
4547
+ [name, base, hasDescription]
4548
+ );
4549
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(FormFieldContext.Provider, { value: ctx, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", __spreadValues({}, props)) });
4550
+ }
4551
+ function FormLabel(_a) {
4552
+ var _b = _a, { htmlFor, name: _name } = _b, props = __objRest(_b, ["htmlFor", "name"]);
4553
+ const field = useFormField();
4554
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("label", __spreadValues({ htmlFor: htmlFor != null ? htmlFor : field == null ? void 0 : field.inputId }, props));
4555
+ }
4556
+ var FormInput = (0, import_react33.forwardRef)(
4557
+ (_a, ref) => {
4558
+ var _b = _a, { name, id, onChange, "aria-describedby": ariaDescribedBy } = _b, props = __objRest(_b, ["name", "id", "onChange", "aria-describedby"]);
4559
+ var _a2;
4560
+ const form = useFormContext();
4561
+ const field = useFormField();
4562
+ const value = (_a2 = useFieldValueMaybe(form, name)) != null ? _a2 : "";
4563
+ const error = form == null ? void 0 : form.getError(name);
4564
+ const touched = form == null ? void 0 : form.getFieldTouched(name);
4565
+ const hasError = Boolean(error && touched);
4566
+ const setRef = useRegisterControl(form, name, ref);
4567
+ const handleChange = (0, import_react33.useCallback)(
4568
+ (e) => {
4569
+ const el = e.target;
4570
+ let next = el.value;
4571
+ if (el.type === "number" && el.value !== "") {
4572
+ next = Number.isNaN(el.valueAsNumber) ? el.value : el.valueAsNumber;
4573
+ }
4574
+ form == null ? void 0 : form.setValue(name, next);
4575
+ onChange == null ? void 0 : onChange(e);
4576
+ },
4577
+ [form, name, onChange]
4578
+ );
4579
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
4580
+ "input",
4581
+ __spreadValues({
4582
+ ref: setRef,
4583
+ id: id != null ? id : field == null ? void 0 : field.inputId,
4584
+ name,
4585
+ value,
4586
+ onChange: handleChange,
4587
+ onBlur: () => form == null ? void 0 : form.setFieldTouched(name, true),
4588
+ "aria-invalid": hasError || void 0,
4589
+ "aria-describedby": composeDescribedBy(field, hasError, ariaDescribedBy)
4590
+ }, props)
4591
+ );
4592
+ }
4593
+ );
4594
+ FormInput.displayName = "FormInput";
4595
+ var FormTextarea = (0, import_react33.forwardRef)(
4596
+ (_a, ref) => {
4597
+ var _b = _a, { name, id, onChange, "aria-describedby": ariaDescribedBy } = _b, props = __objRest(_b, ["name", "id", "onChange", "aria-describedby"]);
4598
+ var _a2;
4599
+ const form = useFormContext();
4600
+ const field = useFormField();
4601
+ const value = (_a2 = useFieldValueMaybe(form, name)) != null ? _a2 : "";
4602
+ const error = form == null ? void 0 : form.getError(name);
4603
+ const touched = form == null ? void 0 : form.getFieldTouched(name);
4604
+ const hasError = Boolean(error && touched);
4605
+ const setRef = useRegisterControl(form, name, ref);
4606
+ const handleChange = (0, import_react33.useCallback)(
4607
+ (e) => {
4608
+ form == null ? void 0 : form.setValue(name, e.target.value);
4609
+ onChange == null ? void 0 : onChange(e);
4610
+ },
4611
+ [form, name, onChange]
4612
+ );
4613
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
4614
+ "textarea",
4615
+ __spreadValues({
4616
+ ref: setRef,
4617
+ id: id != null ? id : field == null ? void 0 : field.inputId,
4618
+ name,
4619
+ value,
4620
+ onChange: handleChange,
4621
+ onBlur: () => form == null ? void 0 : form.setFieldTouched(name, true),
4622
+ "aria-invalid": hasError || void 0,
4623
+ "aria-describedby": composeDescribedBy(field, hasError, ariaDescribedBy)
4624
+ }, props)
4625
+ );
4626
+ }
4627
+ );
4628
+ FormTextarea.displayName = "FormTextarea";
4629
+ var FormSelect = (0, import_react33.forwardRef)(
4630
+ (_a, ref) => {
4631
+ var _b = _a, {
4632
+ name,
4633
+ id,
4634
+ onChange,
4635
+ "aria-describedby": ariaDescribedBy,
4636
+ children
4637
+ } = _b, props = __objRest(_b, [
4638
+ "name",
4639
+ "id",
4640
+ "onChange",
4641
+ "aria-describedby",
4642
+ "children"
4643
+ ]);
4644
+ var _a2;
4645
+ const form = useFormContext();
4646
+ const field = useFormField();
4647
+ const value = (_a2 = useFieldValueMaybe(form, name)) != null ? _a2 : "";
4648
+ const error = form == null ? void 0 : form.getError(name);
4649
+ const touched = form == null ? void 0 : form.getFieldTouched(name);
4650
+ const hasError = Boolean(error && touched);
4651
+ const setRef = useRegisterControl(form, name, ref);
4652
+ const handleChange = (0, import_react33.useCallback)(
4653
+ (e) => {
4654
+ form == null ? void 0 : form.setValue(name, e.target.value);
4655
+ onChange == null ? void 0 : onChange(e);
4656
+ },
4657
+ [form, name, onChange]
4658
+ );
4659
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
4660
+ "select",
4661
+ __spreadProps(__spreadValues({
4662
+ ref: setRef,
4663
+ id: id != null ? id : field == null ? void 0 : field.inputId,
4664
+ name,
4665
+ value,
4666
+ onChange: handleChange,
4667
+ onBlur: () => form == null ? void 0 : form.setFieldTouched(name, true),
4668
+ "aria-invalid": hasError || void 0,
4669
+ "aria-describedby": composeDescribedBy(field, hasError, ariaDescribedBy)
4670
+ }, props), {
4671
+ children
4672
+ })
4673
+ );
4674
+ }
4675
+ );
4676
+ FormSelect.displayName = "FormSelect";
4677
+ var FormSwitch = (0, import_react33.forwardRef)(
4678
+ (_a, ref) => {
4679
+ var _b = _a, { name, onClick, onBlur, "aria-describedby": ariaDescribedBy } = _b, props = __objRest(_b, ["name", "onClick", "onBlur", "aria-describedby"]);
4680
+ const form = useFormContext();
4681
+ const field = useFormField();
4682
+ const checked = Boolean(useFieldValueMaybe(form, name));
4683
+ const error = form == null ? void 0 : form.getError(name);
4684
+ const touched = form == null ? void 0 : form.getFieldTouched(name);
4685
+ const hasError = Boolean(error && touched);
4686
+ const handleClick = (0, import_react33.useCallback)(
4687
+ (e) => {
4688
+ form == null ? void 0 : form.setValue(name, !checked);
4689
+ onClick == null ? void 0 : onClick(e);
4690
+ },
4691
+ [form, name, checked, onClick]
4692
+ );
4693
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
4694
+ "button",
4695
+ __spreadValues({
4696
+ ref,
4697
+ type: "button",
4698
+ role: "switch",
4699
+ "aria-checked": checked,
4700
+ "aria-describedby": composeDescribedBy(field, hasError, ariaDescribedBy),
4701
+ onClick: handleClick,
4702
+ onBlur: (e) => {
4703
+ form == null ? void 0 : form.setFieldTouched(name, true);
4704
+ onBlur == null ? void 0 : onBlur(e);
4705
+ }
4706
+ }, props)
4707
+ );
4708
+ }
4709
+ );
4710
+ FormSwitch.displayName = "FormSwitch";
4711
+ var FormCheckbox = (0, import_react33.forwardRef)(
4712
+ (_a, ref) => {
4713
+ var _b = _a, {
4714
+ name,
4715
+ value,
4716
+ onChange,
4717
+ onBlur,
4718
+ "aria-describedby": ariaDescribedBy
4719
+ } = _b, props = __objRest(_b, [
4720
+ "name",
4721
+ "value",
4722
+ "onChange",
4723
+ "onBlur",
4724
+ "aria-describedby"
4725
+ ]);
4726
+ const form = useFormContext();
4727
+ const field = useFormField();
4728
+ const fieldValue = useFieldValueMaybe(form, name);
4729
+ const checked = value ? Array.isArray(fieldValue) && fieldValue.includes(value) : Boolean(fieldValue);
4730
+ const error = form == null ? void 0 : form.getError(name);
4731
+ const touched = form == null ? void 0 : form.getFieldTouched(name);
4732
+ const hasError = Boolean(error && touched);
4733
+ const handleChange = (0, import_react33.useCallback)(
4734
+ (e) => {
4735
+ if (value && Array.isArray(fieldValue)) {
4736
+ const newArr = e.target.checked ? [...fieldValue, value] : fieldValue.filter((v) => v !== value);
4737
+ form == null ? void 0 : form.setValue(name, newArr);
4738
+ } else if (value) {
4739
+ form == null ? void 0 : form.setValue(name, e.target.checked ? [value] : []);
4740
+ } else {
4741
+ form == null ? void 0 : form.setValue(name, e.target.checked);
4742
+ }
4743
+ onChange == null ? void 0 : onChange(e);
4744
+ },
4745
+ [form, name, value, fieldValue, onChange]
4746
+ );
4747
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
4748
+ "input",
4749
+ __spreadValues({
4750
+ ref,
4751
+ type: "checkbox",
4752
+ name,
4753
+ checked,
4754
+ onChange: handleChange,
4755
+ onBlur: (e) => {
4756
+ form == null ? void 0 : form.setFieldTouched(name, true);
4757
+ onBlur == null ? void 0 : onBlur(e);
4758
+ },
4759
+ "aria-invalid": hasError || void 0,
4760
+ "aria-describedby": composeDescribedBy(field, hasError, ariaDescribedBy)
4761
+ }, props)
4762
+ );
4763
+ }
4764
+ );
4765
+ FormCheckbox.displayName = "FormCheckbox";
4766
+ function FormRadioGroup(_a) {
4767
+ var _b = _a, { name: _name } = _b, props = __objRest(_b, ["name"]);
4768
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", __spreadValues({ role: "radiogroup" }, props));
4769
+ }
4770
+ var FormRadio = (0, import_react33.forwardRef)(
4771
+ (_a, ref) => {
4772
+ var _b = _a, {
4773
+ name,
4774
+ value,
4775
+ onChange,
4776
+ onBlur,
4777
+ "aria-describedby": ariaDescribedBy
4778
+ } = _b, props = __objRest(_b, [
4779
+ "name",
4780
+ "value",
4781
+ "onChange",
4782
+ "onBlur",
4783
+ "aria-describedby"
4784
+ ]);
4785
+ const form = useFormContext();
4786
+ const field = useFormField();
4787
+ const fieldValue = useFieldValueMaybe(form, name);
4788
+ const checked = fieldValue === value;
4789
+ const error = form == null ? void 0 : form.getError(name);
4790
+ const touched = form == null ? void 0 : form.getFieldTouched(name);
4791
+ const hasError = Boolean(error && touched);
4792
+ const handleChange = (0, import_react33.useCallback)(
4793
+ (e) => {
4794
+ form == null ? void 0 : form.setValue(name, value);
4795
+ onChange == null ? void 0 : onChange(e);
4796
+ },
4797
+ [form, name, value, onChange]
4798
+ );
4799
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
4800
+ "input",
4801
+ __spreadValues({
4802
+ ref,
4803
+ type: "radio",
4804
+ name,
4805
+ value,
4806
+ checked,
4807
+ onChange: handleChange,
4808
+ onBlur: (e) => {
4809
+ form == null ? void 0 : form.setFieldTouched(name, true);
4810
+ onBlur == null ? void 0 : onBlur(e);
4811
+ },
4812
+ "aria-invalid": hasError || void 0,
4813
+ "aria-describedby": composeDescribedBy(field, hasError, ariaDescribedBy)
4814
+ }, props)
4815
+ );
4816
+ }
4817
+ );
4818
+ FormRadio.displayName = "FormRadio";
4819
+ function FormDescription(_a) {
4820
+ var _b = _a, {
4821
+ name: _name
4822
+ } = _b, props = __objRest(_b, [
4823
+ "name"
4824
+ ]);
4825
+ const field = useFormField();
4826
+ const setHasDescription = field == null ? void 0 : field.setHasDescription;
4827
+ (0, import_react33.useEffect)(() => {
4828
+ setHasDescription == null ? void 0 : setHasDescription(true);
4829
+ return () => setHasDescription == null ? void 0 : setHasDescription(false);
4830
+ }, [setHasDescription]);
4831
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("p", __spreadValues({ id: field == null ? void 0 : field.descriptionId }, props));
4832
+ }
4833
+ function FormError(_a) {
4834
+ var _b = _a, { name, children } = _b, props = __objRest(_b, ["name", "children"]);
4835
+ const form = useFormContext();
4836
+ const field = useFormField();
4837
+ useStoreSubscription(form);
4838
+ const error = form == null ? void 0 : form.getError(name);
4839
+ const touched = form == null ? void 0 : form.getFieldTouched(name);
4840
+ if (!error || !touched) return null;
4841
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("p", __spreadProps(__spreadValues({ id: field == null ? void 0 : field.errorId, role: "alert" }, props), { children: children != null ? children : error }));
4842
+ }
4843
+ var FormControl = FormInput;
4844
+ function FormSubmit(_a) {
4845
+ var _b = _a, {
4846
+ type = "submit",
4847
+ disabled
4848
+ } = _b, props = __objRest(_b, [
4849
+ "type",
4850
+ "disabled"
4851
+ ]);
4852
+ const form = useFormContext();
4853
+ useStoreSubscription(form);
4854
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
4855
+ "button",
4856
+ __spreadValues({
4857
+ type,
4858
+ disabled: disabled != null ? disabled : form == null ? void 0 : form.isSubmitting()
4859
+ }, props)
4860
+ );
4861
+ }
4862
+ function FormReset(_a) {
4863
+ var _b = _a, { onClick } = _b, props = __objRest(_b, ["onClick"]);
4864
+ const form = useFormContext();
4865
+ const handleClick = (0, import_react33.useCallback)(
4866
+ (e) => {
4867
+ form == null ? void 0 : form.reset();
4868
+ onClick == null ? void 0 : onClick(e);
4869
+ },
4870
+ [form, onClick]
4871
+ );
4872
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("button", __spreadValues({ type: "button", onClick: handleClick }, props));
4873
+ }
4874
+ function FormPush(_a) {
4875
+ var _b = _a, { name, value, onClick } = _b, props = __objRest(_b, ["name", "value", "onClick"]);
4876
+ const form = useFormContext();
4877
+ const handleClick = (0, import_react33.useCallback)(
4878
+ (e) => {
4879
+ form == null ? void 0 : form.push(name, value);
4880
+ onClick == null ? void 0 : onClick(e);
4881
+ },
4882
+ [form, name, value, onClick]
4883
+ );
4884
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("button", __spreadValues({ type: "button", onClick: handleClick }, props));
4885
+ }
4886
+ function FormRemove(_a) {
4887
+ var _b = _a, {
4888
+ name,
4889
+ index,
4890
+ onClick
4891
+ } = _b, props = __objRest(_b, [
4892
+ "name",
4893
+ "index",
4894
+ "onClick"
4895
+ ]);
4896
+ const form = useFormContext();
4897
+ const handleClick = (0, import_react33.useCallback)(
4898
+ (e) => {
4899
+ form == null ? void 0 : form.remove(name, index);
4900
+ onClick == null ? void 0 : onClick(e);
4901
+ },
4902
+ [form, name, index, onClick]
4903
+ );
4904
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("button", __spreadValues({ type: "button", onClick: handleClick }, props));
4905
+ }
4906
+ function FormGroup(props) {
4907
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("fieldset", __spreadValues({}, props));
4908
+ }
4909
+ function FormGroupLabel(props) {
4910
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("legend", __spreadValues({}, props));
4911
+ }
4912
+ // Annotate the CommonJS export names for ESM import in node:
4913
+ 0 && (module.exports = {
4914
+ AccordionContent,
4915
+ AccordionItem,
4916
+ AccordionRoot,
4917
+ AccordionTrigger,
4918
+ AlertDialogPanel,
4919
+ Button,
4920
+ Checkbox,
4921
+ ComboboxGroup,
4922
+ ComboboxGroupLabel,
4923
+ ComboboxInput,
4924
+ ComboboxItem,
4925
+ ComboboxPopover,
4926
+ ComboboxRoot,
4927
+ CommandEmpty,
4928
+ CommandGroup,
4929
+ CommandInput,
4930
+ CommandItem,
4931
+ CommandList,
4932
+ CommandRoot,
4933
+ CommandSeparator,
4934
+ Composite,
4935
+ CompositeItem,
4936
+ CompositeProvider,
4937
+ CompositeRow,
4938
+ DialogDescription,
4939
+ DialogDisclosure,
4940
+ DialogDismiss,
4941
+ DialogHeading,
4942
+ DialogPanel,
4943
+ DialogRoot,
4944
+ DisclosureContent,
4945
+ DisclosureRoot,
4946
+ DisclosureTrigger,
4947
+ FormCheckbox,
4948
+ FormControl,
4949
+ FormDescription,
4950
+ FormError,
4951
+ FormField,
4952
+ FormGroup,
4953
+ FormGroupLabel,
4954
+ FormInput,
4955
+ FormLabel,
4956
+ FormProvider,
4957
+ FormPush,
4958
+ FormRadio,
4959
+ FormRadioGroup,
4960
+ FormRemove,
4961
+ FormReset,
4962
+ FormRoot,
4963
+ FormSelect,
4964
+ FormSubmit,
4965
+ FormSwitch,
4966
+ FormTextarea,
4967
+ MenuButtonArrow,
4968
+ MenuItem,
4969
+ MenuItemCheckbox,
4970
+ MenuItemRadio,
4971
+ MenuPopover,
4972
+ MenuRoot,
4973
+ MenuSeparator,
4974
+ MenuTrigger,
4975
+ MenubarContainer,
4976
+ MenubarRoot,
4977
+ Meter,
4978
+ PopoverClose,
4979
+ PopoverContent,
4980
+ PopoverRoot,
4981
+ PopoverTrigger,
4982
+ Progress,
4983
+ Radio,
4984
+ RadioGroupRoot,
4985
+ SelectItem,
4986
+ SelectLabel,
4987
+ SelectPopover,
4988
+ SelectRoot,
4989
+ SelectTrigger,
4990
+ Separator,
4991
+ Switch,
4992
+ Tab,
4993
+ TabList,
4994
+ TabPanel,
4995
+ TabsRoot,
4996
+ Toggle,
4997
+ ToggleGroup,
4998
+ ToolbarButton,
4999
+ ToolbarContainer,
5000
+ ToolbarRoot,
5001
+ ToolbarSeparator,
5002
+ Tooltip,
5003
+ TooltipAnchor,
5004
+ TooltipProvider,
5005
+ useCommandState,
5006
+ useControllableState,
5007
+ useDialogClose,
5008
+ useEnterLeave,
5009
+ useFieldValue,
5010
+ useFloating,
5011
+ useFocusVisible,
5012
+ useFocusableWhenDisabled,
5013
+ useFormContext,
5014
+ useFormStore,
5015
+ useId,
5016
+ useMenubarContext,
5017
+ useRadioGroupContext,
5018
+ useRovingTabindex,
5019
+ useScrollActiveDescendantIntoView
5020
+ });