@vertz/ui-primitives 0.2.16 → 0.2.18

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.
Files changed (117) hide show
  1. package/dist/shared/chunk-18y8gfk0.js +308 -0
  2. package/dist/shared/chunk-4085nbdq.js +196 -0
  3. package/dist/shared/chunk-4da5zksy.js +46 -0
  4. package/dist/shared/chunk-7ffg0caj.js +265 -0
  5. package/dist/shared/{chunk-w06tst6x.js → chunk-7kpsyjd7.js} +9 -5
  6. package/dist/shared/chunk-7krvqrwq.js +177 -0
  7. package/dist/shared/chunk-8ak7vdk1.js +151 -0
  8. package/dist/shared/chunk-8nk0ya7a.js +163 -0
  9. package/dist/shared/chunk-8tvzqry6.js +218 -0
  10. package/dist/shared/{chunk-qpfqyrc5.js → chunk-96d9nr7y.js} +1 -1
  11. package/dist/shared/chunk-9hj9p7s2.js +95 -0
  12. package/dist/shared/chunk-avxcmmk6.js +178 -0
  13. package/dist/shared/chunk-bew4bjgf.js +165 -0
  14. package/dist/shared/chunk-dpsgb1xw.js +18 -0
  15. package/dist/shared/chunk-g9qvd20g.js +133 -0
  16. package/dist/shared/chunk-gkddsbmh.js +73 -0
  17. package/dist/shared/chunk-gt0wth9h.js +128 -0
  18. package/dist/shared/chunk-hr9hx58m.js +71 -0
  19. package/dist/shared/{chunk-n92bvn5d.js → chunk-j4cm8avr.js} +85 -59
  20. package/dist/shared/chunk-jz0s6srh.js +161 -0
  21. package/dist/shared/chunk-kg27s15c.js +282 -0
  22. package/dist/shared/chunk-m1ptgp1s.js +142 -0
  23. package/dist/shared/{chunk-9cqe2q6e.js → chunk-n9nwx58j.js} +9 -5
  24. package/dist/shared/chunk-ppcv3ehd.js +85 -0
  25. package/dist/shared/{chunk-vq9tfzh8.js → chunk-rnjm61t0.js} +5 -1
  26. package/dist/shared/chunk-sqs8kyb2.js +288 -0
  27. package/dist/shared/chunk-tfyg0qrp.js +117 -0
  28. package/dist/shared/chunk-ttsyf6ma.js +239 -0
  29. package/dist/shared/chunk-x0we8gcy.js +219 -0
  30. package/dist/shared/{chunk-6pnjrst7.js → chunk-x2hz98qn.js} +2 -2
  31. package/dist/shared/chunk-yr9yzpvq.js +107 -0
  32. package/dist/src/accordion/accordion.d.ts +14 -2
  33. package/dist/src/accordion/accordion.js +2 -1
  34. package/dist/src/badge/badge.d.ts +13 -1
  35. package/dist/src/badge/badge.js +2 -1
  36. package/dist/src/button/button.d.ts +16 -14
  37. package/dist/src/button/button.js +2 -2
  38. package/dist/src/calendar/calendar.d.ts +14 -2
  39. package/dist/src/calendar/calendar.js +2 -1
  40. package/dist/src/carousel/carousel.d.ts +14 -2
  41. package/dist/src/carousel/carousel.js +2 -1
  42. package/dist/src/checkbox/checkbox.d.ts +15 -13
  43. package/dist/src/checkbox/checkbox.js +2 -2
  44. package/dist/src/collapsible/collapsible.d.ts +14 -2
  45. package/dist/src/collapsible/collapsible.js +2 -1
  46. package/dist/src/combobox/combobox.d.ts +14 -2
  47. package/dist/src/combobox/combobox.js +2 -1
  48. package/dist/src/command/command.d.ts +14 -2
  49. package/dist/src/command/command.js +2 -1
  50. package/dist/src/context-menu/context-menu.d.ts +14 -2
  51. package/dist/src/context-menu/context-menu.js +2 -1
  52. package/dist/src/date-picker/date-picker.js +4 -3
  53. package/dist/src/dialog/dialog.d.ts +14 -2
  54. package/dist/src/dialog/dialog.js +2 -1
  55. package/dist/src/dropdown-menu/dropdown-menu.d.ts +13 -1
  56. package/dist/src/dropdown-menu/dropdown-menu.js +3 -2
  57. package/dist/src/hover-card/hover-card.d.ts +14 -2
  58. package/dist/src/hover-card/hover-card.js +2 -1
  59. package/dist/src/index.d.ts +132 -140
  60. package/dist/src/index.js +31 -30
  61. package/dist/src/menu/menu.d.ts +14 -2
  62. package/dist/src/menu/menu.js +2 -1
  63. package/dist/src/menubar/menubar.d.ts +14 -2
  64. package/dist/src/menubar/menubar.js +2 -1
  65. package/dist/src/navigation-menu/navigation-menu.d.ts +14 -2
  66. package/dist/src/navigation-menu/navigation-menu.js +2 -1
  67. package/dist/src/popover/popover.d.ts +14 -2
  68. package/dist/src/popover/popover.js +2 -1
  69. package/dist/src/progress/progress.d.ts +14 -2
  70. package/dist/src/progress/progress.js +2 -1
  71. package/dist/src/radio/radio.d.ts +14 -2
  72. package/dist/src/radio/radio.js +2 -1
  73. package/dist/src/resizable-panel/resizable-panel.d.ts +14 -2
  74. package/dist/src/resizable-panel/resizable-panel.js +2 -1
  75. package/dist/src/scroll-area/scroll-area.d.ts +14 -2
  76. package/dist/src/scroll-area/scroll-area.js +2 -1
  77. package/dist/src/select/select.d.ts +14 -2
  78. package/dist/src/select/select.js +2 -1
  79. package/dist/src/slider/slider.d.ts +14 -2
  80. package/dist/src/slider/slider.js +2 -1
  81. package/dist/src/switch/switch.d.ts +13 -1
  82. package/dist/src/switch/switch.js +2 -1
  83. package/dist/src/tabs/tabs.d.ts +14 -2
  84. package/dist/src/tabs/tabs.js +2 -1
  85. package/dist/src/toast/toast.d.ts +14 -2
  86. package/dist/src/toast/toast.js +2 -1
  87. package/dist/src/toggle/toggle.d.ts +13 -1
  88. package/dist/src/toggle/toggle.js +2 -1
  89. package/dist/src/toggle-group/toggle-group.d.ts +14 -2
  90. package/dist/src/toggle-group/toggle-group.js +2 -1
  91. package/dist/src/tooltip/tooltip.d.ts +14 -2
  92. package/dist/src/tooltip/tooltip.js +2 -1
  93. package/package.json +3 -3
  94. package/dist/shared/chunk-2h5qpc00.js +0 -98
  95. package/dist/shared/chunk-31yptvbf.js +0 -151
  96. package/dist/shared/chunk-3pantb0p.js +0 -108
  97. package/dist/shared/chunk-3s6s6f06.js +0 -61
  98. package/dist/shared/chunk-48v8j0vh.js +0 -267
  99. package/dist/shared/chunk-6dmt4513.js +0 -78
  100. package/dist/shared/chunk-6sqwjfg8.js +0 -169
  101. package/dist/shared/chunk-8qfeqrrz.js +0 -179
  102. package/dist/shared/chunk-bcfzteh0.js +0 -148
  103. package/dist/shared/chunk-cr9sbwns.js +0 -235
  104. package/dist/shared/chunk-cvbf1js1.js +0 -52
  105. package/dist/shared/chunk-dkhst4wv.js +0 -97
  106. package/dist/shared/chunk-e3aj5yw4.js +0 -115
  107. package/dist/shared/chunk-fv1y77tn.js +0 -225
  108. package/dist/shared/chunk-h42bk324.js +0 -58
  109. package/dist/shared/chunk-h9m9x5my.js +0 -119
  110. package/dist/shared/chunk-qq0e0gym.js +0 -73
  111. package/dist/shared/chunk-tk1k1bet.js +0 -93
  112. package/dist/shared/chunk-tvpgeswh.js +0 -216
  113. package/dist/shared/chunk-vcp10kne.js +0 -175
  114. package/dist/shared/chunk-ve006hmy.js +0 -51
  115. package/dist/shared/chunk-vx1ajy2z.js +0 -115
  116. package/dist/shared/chunk-wnttq0gv.js +0 -49
  117. package/dist/shared/chunk-x6qzr3g6.js +0 -100
@@ -6,67 +6,86 @@ import {
6
6
  setDataState,
7
7
  setValueRange
8
8
  } from "./chunk-vvjyx7fe.js";
9
+ import {
10
+ applyAttrs
11
+ } from "./chunk-dpsgb1xw.js";
9
12
 
10
- // src/resizable-panel/resizable-panel.ts
13
+ // src/resizable-panel/resizable-panel.tsx
14
+ import { __element, __on } from "@vertz/ui/internals";
11
15
  import { signal } from "@vertz/ui";
12
- var ResizablePanel = {
13
- Root(options = {}) {
14
- const { orientation = "horizontal", onResize } = options;
15
- const state = { sizes: signal([]) };
16
- const panels = [];
17
- const handles = [];
18
- const root = document.createElement("div");
19
- root.style.display = "flex";
20
- root.style.flexDirection = orientation === "horizontal" ? "row" : "column";
21
- root.setAttribute("data-orientation", orientation);
22
- function updateSizes(newSizes) {
23
- state.sizes.value = [...newSizes];
24
- for (let i = 0;i < panels.length; i++) {
25
- const panel = panels[i];
26
- if (!panel)
27
- continue;
16
+ function ResizablePanelRoot(options = {}) {
17
+ const { orientation = "horizontal", onResize, ...attrs } = options;
18
+ const state = { sizes: signal([]) };
19
+ const panels = [];
20
+ const handles = [];
21
+ function updateSizes(newSizes) {
22
+ state.sizes.value = [...newSizes];
23
+ for (let i = 0;i < panels.length; i++) {
24
+ const panel = panels[i];
25
+ if (!panel)
26
+ continue;
27
+ const size = newSizes[i] ?? 0;
28
+ panel.el.style.flex = `0 0 ${size}%`;
29
+ }
30
+ for (let i = 0;i < handles.length; i++) {
31
+ const handle = handles[i];
32
+ const leftPanel = panels[i];
33
+ if (handle && leftPanel) {
28
34
  const size = newSizes[i] ?? 0;
29
- panel.el.style.flex = `0 0 ${size}%`;
35
+ setValueRange(handle, Math.round(size), Math.round(leftPanel.minSize), Math.round(leftPanel.maxSize));
30
36
  }
31
- for (let i = 0;i < handles.length; i++) {
32
- const handle = handles[i];
33
- const leftPanel = panels[i];
34
- if (handle && leftPanel) {
35
- const size = newSizes[i] ?? 0;
36
- setValueRange(handle, Math.round(size), Math.round(leftPanel.minSize), Math.round(leftPanel.maxSize));
37
- }
38
- }
39
- onResize?.(newSizes);
40
37
  }
41
- function Panel(panelOptions = {}) {
42
- const { defaultSize, minSize = 0, maxSize = 100 } = panelOptions;
43
- const el = document.createElement("div");
44
- el.setAttribute("data-panel", "");
45
- panels.push({ el, minSize, maxSize });
46
- const sizes = state.sizes.peek();
47
- if (defaultSize != null) {
48
- sizes.push(defaultSize);
49
- } else {
50
- const equalSize = 100 / panels.length;
51
- sizes.length = 0;
52
- for (let i = 0;i < panels.length; i++) {
53
- sizes.push(equalSize);
54
- }
38
+ onResize?.(newSizes);
39
+ }
40
+ const root = (() => {
41
+ const __el0 = __element("div");
42
+ {
43
+ const __v = `display: flex; flex-direction: ${orientation === "horizontal" ? "row" : "column"};`;
44
+ if (__v != null && __v !== false)
45
+ __el0.setAttribute("style", __v === true ? "" : __v);
46
+ }
47
+ {
48
+ const __v = orientation;
49
+ if (__v != null && __v !== false)
50
+ __el0.setAttribute("data-orientation", __v === true ? "" : __v);
51
+ }
52
+ return __el0;
53
+ })();
54
+ function Panel(panelOptions = {}) {
55
+ const { defaultSize, minSize = 0, maxSize = 100 } = panelOptions;
56
+ const el = (() => {
57
+ const __el1 = __element("div");
58
+ __el1.setAttribute("data-panel", "");
59
+ return __el1;
60
+ })();
61
+ panels.push({ el, minSize, maxSize });
62
+ const sizes = state.sizes.peek();
63
+ if (defaultSize != null) {
64
+ sizes.push(defaultSize);
65
+ } else {
66
+ const equalSize = 100 / panels.length;
67
+ sizes.length = 0;
68
+ for (let i = 0;i < panels.length; i++) {
69
+ sizes.push(equalSize);
55
70
  }
56
- updateSizes(sizes);
57
- root.appendChild(el);
58
- return el;
59
71
  }
60
- function Handle() {
61
- const handleIndex = handles.length;
62
- const handle = document.createElement("div");
63
- handle.setAttribute("role", "separator");
64
- handle.setAttribute("tabindex", "0");
65
- handle.setAttribute("data-orientation", orientation);
66
- setDataState(handle, "idle");
67
- handles.push(handle);
68
- const STEP = 5;
69
- handle.addEventListener("keydown", (event) => {
72
+ updateSizes(sizes);
73
+ root.appendChild(el);
74
+ return el;
75
+ }
76
+ function Handle() {
77
+ const handleIndex = handles.length;
78
+ const handle = (() => {
79
+ const __el2 = __element("div");
80
+ __el2.setAttribute("role", "separator");
81
+ __el2.setAttribute("tabindex", "0");
82
+ {
83
+ const __v = orientation;
84
+ if (__v != null && __v !== false)
85
+ __el2.setAttribute("data-orientation", __v === true ? "" : __v);
86
+ }
87
+ __el2.setAttribute("data-state", "idle");
88
+ __on(__el2, "keydown", (event) => {
70
89
  const sizes = [...state.sizes.peek()];
71
90
  const leftIdx = handleIndex;
72
91
  const rightIdx = handleIndex + 1;
@@ -76,6 +95,7 @@ var ResizablePanel = {
76
95
  return;
77
96
  let leftSize = sizes[leftIdx] ?? 0;
78
97
  let rightSize = sizes[rightIdx] ?? 0;
98
+ const STEP = 5;
79
99
  const growKey = orientation === "horizontal" ? Keys.ArrowRight : Keys.ArrowDown;
80
100
  const shrinkKey = orientation === "horizontal" ? Keys.ArrowLeft : Keys.ArrowUp;
81
101
  if (isKey(event, growKey)) {
@@ -105,7 +125,7 @@ var ResizablePanel = {
105
125
  sizes[rightIdx] = rightSize;
106
126
  updateSizes(sizes);
107
127
  });
108
- handle.addEventListener("pointerdown", (event) => {
128
+ __on(__el2, "pointerdown", (event) => {
109
129
  event.preventDefault();
110
130
  handle.setPointerCapture(event.pointerId);
111
131
  setDataState(handle, "dragging");
@@ -139,11 +159,17 @@ var ResizablePanel = {
139
159
  handle.addEventListener("pointermove", onMove);
140
160
  handle.addEventListener("pointerup", onUp);
141
161
  });
142
- root.appendChild(handle);
143
- return handle;
144
- }
145
- return { root, state, Panel, Handle };
162
+ return __el2;
163
+ })();
164
+ handles.push(handle);
165
+ root.appendChild(handle);
166
+ return handle;
146
167
  }
168
+ applyAttrs(root, attrs);
169
+ return { root, state, Panel, Handle };
170
+ }
171
+ var ResizablePanel = {
172
+ Root: ResizablePanelRoot
147
173
  };
148
174
 
149
175
  export { ResizablePanel };
@@ -0,0 +1,161 @@
1
+ import {
2
+ applyAttrs
3
+ } from "./chunk-dpsgb1xw.js";
4
+
5
+ // src/scroll-area/scroll-area.tsx
6
+ import { __element, __enterChildren, __exitChildren, __insert, __on } from "@vertz/ui/internals";
7
+ import { signal } from "@vertz/ui";
8
+ function ScrollAreaRoot(options = {}) {
9
+ const { orientation = "vertical", type: _type, ...attrs } = options;
10
+ const state = {
11
+ scrollTop: signal(0),
12
+ scrollLeft: signal(0)
13
+ };
14
+ let isDraggingY = false;
15
+ let startY = 0;
16
+ let startScrollTop = 0;
17
+ let isDraggingX = false;
18
+ let startX = 0;
19
+ let startScrollLeft = 0;
20
+ function syncThumbY() {
21
+ const { scrollTop, scrollHeight, clientHeight } = viewport;
22
+ if (scrollHeight <= clientHeight) {
23
+ thumbY.style.height = "0";
24
+ return;
25
+ }
26
+ const ratio = clientHeight / scrollHeight;
27
+ thumbY.style.height = `${ratio * 100}%`;
28
+ const scrollRatio = scrollTop / (scrollHeight - clientHeight);
29
+ thumbY.style.transform = `translateY(${scrollRatio * (1 / ratio - 1) * 100}%)`;
30
+ state.scrollTop.value = scrollTop;
31
+ }
32
+ function syncThumbX() {
33
+ const { scrollLeft, scrollWidth, clientWidth } = viewport;
34
+ if (scrollWidth <= clientWidth) {
35
+ thumbX.style.width = "0";
36
+ return;
37
+ }
38
+ const ratio = clientWidth / scrollWidth;
39
+ thumbX.style.width = `${ratio * 100}%`;
40
+ const scrollRatio = scrollLeft / (scrollWidth - clientWidth);
41
+ thumbX.style.transform = `translateX(${scrollRatio * (1 / ratio - 1) * 100}%)`;
42
+ state.scrollLeft.value = scrollLeft;
43
+ }
44
+ function update() {
45
+ syncThumbY();
46
+ syncThumbX();
47
+ }
48
+ function handleViewportScroll() {
49
+ if (orientation === "vertical" || orientation === "both")
50
+ syncThumbY();
51
+ if (orientation === "horizontal" || orientation === "both")
52
+ syncThumbX();
53
+ }
54
+ function handleThumbYDown(e) {
55
+ isDraggingY = true;
56
+ startY = e.clientY;
57
+ startScrollTop = viewport.scrollTop;
58
+ thumbY.setPointerCapture(e.pointerId);
59
+ e.preventDefault();
60
+ }
61
+ function handleThumbYMove(e) {
62
+ if (!isDraggingY)
63
+ return;
64
+ const delta = e.clientY - startY;
65
+ const scrollbarHeight = scrollbarY.clientHeight;
66
+ const scrollRange = viewport.scrollHeight - viewport.clientHeight;
67
+ if (scrollbarHeight > 0) {
68
+ viewport.scrollTop = startScrollTop + delta / scrollbarHeight * scrollRange;
69
+ }
70
+ }
71
+ function handleThumbYUp(e) {
72
+ isDraggingY = false;
73
+ thumbY.releasePointerCapture(e.pointerId);
74
+ }
75
+ function handleThumbXDown(e) {
76
+ isDraggingX = true;
77
+ startX = e.clientX;
78
+ startScrollLeft = viewport.scrollLeft;
79
+ thumbX.setPointerCapture(e.pointerId);
80
+ e.preventDefault();
81
+ }
82
+ function handleThumbXMove(e) {
83
+ if (!isDraggingX)
84
+ return;
85
+ const delta = e.clientX - startX;
86
+ const scrollbarWidth = scrollbarX.clientWidth;
87
+ const scrollRange = viewport.scrollWidth - viewport.clientWidth;
88
+ if (scrollbarWidth > 0) {
89
+ viewport.scrollLeft = startScrollLeft + delta / scrollbarWidth * scrollRange;
90
+ }
91
+ }
92
+ function handleThumbXUp(e) {
93
+ isDraggingX = false;
94
+ thumbX.releasePointerCapture(e.pointerId);
95
+ }
96
+ const thumbY = (() => {
97
+ const __el0 = __element("div");
98
+ __on(__el0, "pointerdown", handleThumbYDown);
99
+ __on(__el0, "pointermove", handleThumbYMove);
100
+ __on(__el0, "pointerup", handleThumbYUp);
101
+ return __el0;
102
+ })();
103
+ const scrollbarY = (() => {
104
+ const __el1 = __element("div");
105
+ __el1.setAttribute("aria-hidden", "true");
106
+ __el1.setAttribute("data-orientation", "vertical");
107
+ __enterChildren(__el1);
108
+ __insert(__el1, thumbY);
109
+ __exitChildren();
110
+ return __el1;
111
+ })();
112
+ const thumbX = (() => {
113
+ const __el2 = __element("div");
114
+ __on(__el2, "pointerdown", handleThumbXDown);
115
+ __on(__el2, "pointermove", handleThumbXMove);
116
+ __on(__el2, "pointerup", handleThumbXUp);
117
+ return __el2;
118
+ })();
119
+ const scrollbarX = (() => {
120
+ const __el3 = __element("div");
121
+ __el3.setAttribute("aria-hidden", "true");
122
+ __el3.setAttribute("data-orientation", "horizontal");
123
+ __enterChildren(__el3);
124
+ __insert(__el3, thumbX);
125
+ __exitChildren();
126
+ return __el3;
127
+ })();
128
+ const content = (() => {
129
+ const __el4 = __element("div");
130
+ return __el4;
131
+ })();
132
+ const viewport = (() => {
133
+ const __el5 = __element("div");
134
+ __el5.setAttribute("style", "overflow: scroll;");
135
+ __on(__el5, "scroll", handleViewportScroll);
136
+ __enterChildren(__el5);
137
+ __insert(__el5, content);
138
+ __exitChildren();
139
+ return __el5;
140
+ })();
141
+ viewport.style.scrollbarWidth = "none";
142
+ const root = (() => {
143
+ const __el6 = __element("div");
144
+ __el6.setAttribute("style", "position: relative; overflow: hidden;");
145
+ __enterChildren(__el6);
146
+ __insert(__el6, viewport);
147
+ __exitChildren();
148
+ return __el6;
149
+ })();
150
+ if (orientation === "vertical" || orientation === "both")
151
+ root.appendChild(scrollbarY);
152
+ if (orientation === "horizontal" || orientation === "both")
153
+ root.appendChild(scrollbarX);
154
+ applyAttrs(root, attrs);
155
+ return { root, viewport, content, scrollbarY, thumbY, scrollbarX, thumbX, state, update };
156
+ }
157
+ var ScrollArea = {
158
+ Root: ScrollAreaRoot
159
+ };
160
+
161
+ export { ScrollArea };
@@ -0,0 +1,282 @@
1
+ import {
2
+ createDismiss
3
+ } from "./chunk-a6wp8c32.js";
4
+ import {
5
+ createFloatingPosition
6
+ } from "./chunk-0mcr52hc.js";
7
+ import {
8
+ Keys,
9
+ handleListNavigation,
10
+ isKey
11
+ } from "./chunk-jctqs9m4.js";
12
+ import {
13
+ setDataState,
14
+ setExpanded,
15
+ setHidden,
16
+ setHiddenAnimated,
17
+ setSelected
18
+ } from "./chunk-vvjyx7fe.js";
19
+ import {
20
+ applyAttrs
21
+ } from "./chunk-dpsgb1xw.js";
22
+ import {
23
+ linkedIds
24
+ } from "./chunk-8y1jf6xr.js";
25
+
26
+ // src/select/select.tsx
27
+ import { __element, __enterChildren, __exitChildren, __insert, __on } from "@vertz/ui/internals";
28
+ import { signal } from "@vertz/ui";
29
+ function SelectRoot(options = {}) {
30
+ const { defaultValue = "", placeholder = "", onValueChange, positioning, ...attrs } = options;
31
+ const ids = linkedIds("select");
32
+ const state = {
33
+ open: signal(false),
34
+ value: signal(defaultValue),
35
+ activeIndex: signal(-1)
36
+ };
37
+ const items = [];
38
+ let floatingCleanup = null;
39
+ let dismissCleanup = null;
40
+ function updateActiveItem(index) {
41
+ for (let i = 0;i < items.length; i++) {
42
+ items[i]?.setAttribute("tabindex", i === index ? "0" : "-1");
43
+ }
44
+ }
45
+ function selectItem(value) {
46
+ state.value.value = value;
47
+ for (const item of items) {
48
+ const isActive = item.getAttribute("data-value") === value;
49
+ setSelected(item, isActive);
50
+ setDataState(item, isActive ? "active" : "inactive");
51
+ if (isActive) {
52
+ triggerText.textContent = item.textContent ?? value;
53
+ }
54
+ }
55
+ onValueChange?.(value);
56
+ close();
57
+ }
58
+ function open() {
59
+ state.open.value = true;
60
+ setExpanded(trigger, true);
61
+ setHidden(content, false);
62
+ setDataState(trigger, "open");
63
+ setDataState(content, "open");
64
+ if (positioning) {
65
+ const result = createFloatingPosition(trigger, content, positioning);
66
+ floatingCleanup = result.cleanup;
67
+ dismissCleanup = createDismiss({
68
+ onDismiss: close,
69
+ insideElements: [trigger, content],
70
+ escapeKey: false
71
+ });
72
+ } else {
73
+ const rect = trigger.getBoundingClientRect();
74
+ const side = window.innerHeight - rect.bottom >= rect.top ? "bottom" : "top";
75
+ content.setAttribute("data-side", side);
76
+ }
77
+ const selectedIdx = items.findIndex((item) => item.getAttribute("data-value") === state.value.peek());
78
+ if (selectedIdx >= 0) {
79
+ state.activeIndex.value = selectedIdx;
80
+ updateActiveItem(selectedIdx);
81
+ items[selectedIdx]?.focus();
82
+ } else {
83
+ state.activeIndex.value = -1;
84
+ updateActiveItem(-1);
85
+ content.focus();
86
+ }
87
+ }
88
+ function close() {
89
+ state.open.value = false;
90
+ setExpanded(trigger, false);
91
+ setDataState(trigger, "closed");
92
+ setDataState(content, "closed");
93
+ setHiddenAnimated(content, true);
94
+ floatingCleanup?.();
95
+ floatingCleanup = null;
96
+ dismissCleanup?.();
97
+ dismissCleanup = null;
98
+ trigger.focus();
99
+ }
100
+ const triggerText = (() => {
101
+ const __el0 = __element("span");
102
+ __el0.setAttribute("data-part", "value");
103
+ __enterChildren(__el0);
104
+ __insert(__el0, defaultValue || placeholder);
105
+ __exitChildren();
106
+ return __el0;
107
+ })();
108
+ const trigger = (() => {
109
+ const __el1 = __element("button");
110
+ __el1.setAttribute("type", "button");
111
+ __el1.setAttribute("role", "combobox");
112
+ {
113
+ const __v = ids.triggerId;
114
+ if (__v != null && __v !== false)
115
+ __el1.setAttribute("id", __v === true ? "" : __v);
116
+ }
117
+ {
118
+ const __v = ids.contentId;
119
+ if (__v != null && __v !== false)
120
+ __el1.setAttribute("aria-controls", __v === true ? "" : __v);
121
+ }
122
+ __el1.setAttribute("aria-haspopup", "listbox");
123
+ __el1.setAttribute("aria-expanded", "false");
124
+ __el1.setAttribute("data-state", "closed");
125
+ __on(__el1, "click", () => {
126
+ if (state.open.peek()) {
127
+ close();
128
+ } else {
129
+ open();
130
+ }
131
+ });
132
+ __on(__el1, "keydown", (event) => {
133
+ if (isKey(event, Keys.ArrowDown, Keys.ArrowUp, Keys.Enter, Keys.Space)) {
134
+ event.preventDefault();
135
+ if (!state.open.peek()) {
136
+ open();
137
+ }
138
+ }
139
+ });
140
+ __enterChildren(__el1);
141
+ __insert(__el1, triggerText);
142
+ __exitChildren();
143
+ return __el1;
144
+ })();
145
+ const content = (() => {
146
+ const __el2 = __element("div");
147
+ __el2.setAttribute("role", "listbox");
148
+ __el2.setAttribute("tabindex", "-1");
149
+ {
150
+ const __v = ids.contentId;
151
+ if (__v != null && __v !== false)
152
+ __el2.setAttribute("id", __v === true ? "" : __v);
153
+ }
154
+ __el2.setAttribute("aria-hidden", "true");
155
+ __el2.setAttribute("data-state", "closed");
156
+ __el2.setAttribute("style", "display: none");
157
+ __on(__el2, "keydown", (event) => {
158
+ if (isKey(event, Keys.Escape)) {
159
+ event.preventDefault();
160
+ close();
161
+ return;
162
+ }
163
+ if (isKey(event, Keys.Enter, Keys.Space)) {
164
+ event.preventDefault();
165
+ const active = items[state.activeIndex.peek()];
166
+ if (active) {
167
+ const val = active.getAttribute("data-value");
168
+ if (val !== null)
169
+ selectItem(val);
170
+ }
171
+ return;
172
+ }
173
+ if (state.activeIndex.peek() === -1) {
174
+ if (isKey(event, Keys.ArrowDown)) {
175
+ event.preventDefault();
176
+ state.activeIndex.value = 0;
177
+ updateActiveItem(0);
178
+ items[0]?.focus();
179
+ return;
180
+ }
181
+ if (isKey(event, Keys.ArrowUp)) {
182
+ event.preventDefault();
183
+ const last = items.length - 1;
184
+ state.activeIndex.value = last;
185
+ updateActiveItem(last);
186
+ items[last]?.focus();
187
+ return;
188
+ }
189
+ }
190
+ const result = handleListNavigation(event, items, { orientation: "vertical" });
191
+ if (result) {
192
+ const idx = items.indexOf(result);
193
+ if (idx >= 0) {
194
+ state.activeIndex.value = idx;
195
+ updateActiveItem(idx);
196
+ }
197
+ return;
198
+ }
199
+ if (event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
200
+ const char = event.key.toLowerCase();
201
+ const match = items.find((item) => item.textContent?.toLowerCase().startsWith(char));
202
+ if (match) {
203
+ const idx = items.indexOf(match);
204
+ state.activeIndex.value = idx;
205
+ updateActiveItem(idx);
206
+ match.focus();
207
+ }
208
+ }
209
+ });
210
+ return __el2;
211
+ })();
212
+ function createItem(value, label, parent) {
213
+ const isSelectedItem = value === defaultValue;
214
+ const item = (() => {
215
+ const __el3 = __element("div");
216
+ __el3.setAttribute("role", "option");
217
+ {
218
+ const __v = value;
219
+ if (__v != null && __v !== false)
220
+ __el3.setAttribute("data-value", __v === true ? "" : __v);
221
+ }
222
+ __el3.setAttribute("tabindex", "-1");
223
+ {
224
+ const __v = isSelectedItem ? "true" : "false";
225
+ if (__v != null && __v !== false)
226
+ __el3.setAttribute("aria-selected", __v === true ? "" : __v);
227
+ }
228
+ {
229
+ const __v = isSelectedItem ? "active" : "inactive";
230
+ if (__v != null && __v !== false)
231
+ __el3.setAttribute("data-state", __v === true ? "" : __v);
232
+ }
233
+ __on(__el3, "click", () => selectItem(value));
234
+ __enterChildren(__el3);
235
+ __insert(__el3, label ?? value);
236
+ __exitChildren();
237
+ return __el3;
238
+ })();
239
+ if (isSelectedItem) {
240
+ triggerText.textContent = item.textContent ?? value;
241
+ }
242
+ items.push(item);
243
+ (parent ?? content).appendChild(item);
244
+ return item;
245
+ }
246
+ function Item(value, label) {
247
+ return createItem(value, label);
248
+ }
249
+ function Group(label) {
250
+ const el = (() => {
251
+ const __el4 = __element("div");
252
+ __el4.setAttribute("role", "group");
253
+ {
254
+ const __v = label;
255
+ if (__v != null && __v !== false)
256
+ __el4.setAttribute("aria-label", __v === true ? "" : __v);
257
+ }
258
+ return __el4;
259
+ })();
260
+ content.appendChild(el);
261
+ return {
262
+ el,
263
+ Item: (value, itemLabel) => createItem(value, itemLabel, el)
264
+ };
265
+ }
266
+ function Separator() {
267
+ const hr = (() => {
268
+ const __el5 = __element("hr");
269
+ __el5.setAttribute("role", "separator");
270
+ return __el5;
271
+ })();
272
+ content.appendChild(hr);
273
+ return hr;
274
+ }
275
+ applyAttrs(trigger, attrs);
276
+ return { trigger, content, state, Item, Group, Separator };
277
+ }
278
+ var Select = {
279
+ Root: SelectRoot
280
+ };
281
+
282
+ export { Select };