@agile-plus/headless 0.0.0-stage → 0.1.1

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 (196) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +150 -2
  3. package/dist/index.cjs +2610 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +30 -0
  6. package/dist/index.d.ts +30 -0
  7. package/dist/index.js +2631 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/types-2ROaIfZ9.d.cts +57 -0
  10. package/dist/types-2ROaIfZ9.d.ts +57 -0
  11. package/dist/types-C9nl8qeg.d.cts +100 -0
  12. package/dist/types-C9nl8qeg.d.ts +100 -0
  13. package/dist/types-DM4s_xZa.d.cts +128 -0
  14. package/dist/types-DM4s_xZa.d.ts +128 -0
  15. package/dist/useCheckbox/index.cjs +255 -0
  16. package/dist/useCheckbox/index.cjs.map +1 -0
  17. package/dist/useCheckbox/index.d.cts +145 -0
  18. package/dist/useCheckbox/index.d.ts +145 -0
  19. package/dist/useCheckbox/index.js +232 -0
  20. package/dist/useCheckbox/index.js.map +1 -0
  21. package/dist/useCheckboxGroup/index.cjs +100 -0
  22. package/dist/useCheckboxGroup/index.cjs.map +1 -0
  23. package/dist/useCheckboxGroup/index.d.cts +102 -0
  24. package/dist/useCheckboxGroup/index.d.ts +102 -0
  25. package/dist/useCheckboxGroup/index.js +73 -0
  26. package/dist/useCheckboxGroup/index.js.map +1 -0
  27. package/dist/useCollapsible/index.cjs +151 -0
  28. package/dist/useCollapsible/index.cjs.map +1 -0
  29. package/dist/useCollapsible/index.d.cts +106 -0
  30. package/dist/useCollapsible/index.d.ts +106 -0
  31. package/dist/useCollapsible/index.js +129 -0
  32. package/dist/useCollapsible/index.js.map +1 -0
  33. package/dist/useDialog/index.cjs +294 -0
  34. package/dist/useDialog/index.cjs.map +1 -0
  35. package/dist/useDialog/index.d.cts +105 -0
  36. package/dist/useDialog/index.d.ts +105 -0
  37. package/dist/useDialog/index.js +267 -0
  38. package/dist/useDialog/index.js.map +1 -0
  39. package/dist/useForm/index.cjs +123 -0
  40. package/dist/useForm/index.cjs.map +1 -0
  41. package/dist/useForm/index.d.cts +22 -0
  42. package/dist/useForm/index.d.ts +22 -0
  43. package/dist/useForm/index.js +96 -0
  44. package/dist/useForm/index.js.map +1 -0
  45. package/dist/useFormControl/index.cjs +162 -0
  46. package/dist/useFormControl/index.cjs.map +1 -0
  47. package/dist/useFormControl/index.d.cts +116 -0
  48. package/dist/useFormControl/index.d.ts +116 -0
  49. package/dist/useFormControl/index.js +143 -0
  50. package/dist/useFormControl/index.js.map +1 -0
  51. package/dist/useFormField/index.cjs +45 -0
  52. package/dist/useFormField/index.cjs.map +1 -0
  53. package/dist/useFormField/index.d.cts +22 -0
  54. package/dist/useFormField/index.d.ts +22 -0
  55. package/dist/useFormField/index.js +18 -0
  56. package/dist/useFormField/index.js.map +1 -0
  57. package/dist/useFormMessage/index.cjs +77 -0
  58. package/dist/useFormMessage/index.cjs.map +1 -0
  59. package/dist/useFormMessage/index.d.cts +80 -0
  60. package/dist/useFormMessage/index.d.ts +80 -0
  61. package/dist/useFormMessage/index.js +54 -0
  62. package/dist/useFormMessage/index.js.map +1 -0
  63. package/dist/usePresence/index.cjs +117 -0
  64. package/dist/usePresence/index.cjs.map +1 -0
  65. package/dist/usePresence/index.d.cts +52 -0
  66. package/dist/usePresence/index.d.ts +52 -0
  67. package/dist/usePresence/index.js +90 -0
  68. package/dist/usePresence/index.js.map +1 -0
  69. package/dist/useRadioGroup/index.cjs +197 -0
  70. package/dist/useRadioGroup/index.cjs.map +1 -0
  71. package/dist/useRadioGroup/index.d.cts +162 -0
  72. package/dist/useRadioGroup/index.d.ts +162 -0
  73. package/dist/useRadioGroup/index.js +170 -0
  74. package/dist/useRadioGroup/index.js.map +1 -0
  75. package/dist/useScrollArea/index.cjs +309 -0
  76. package/dist/useScrollArea/index.cjs.map +1 -0
  77. package/dist/useScrollArea/index.d.cts +127 -0
  78. package/dist/useScrollArea/index.d.ts +127 -0
  79. package/dist/useScrollArea/index.js +287 -0
  80. package/dist/useScrollArea/index.js.map +1 -0
  81. package/dist/useSlider/index.cjs +417 -0
  82. package/dist/useSlider/index.cjs.map +1 -0
  83. package/dist/useSlider/index.d.cts +215 -0
  84. package/dist/useSlider/index.d.ts +215 -0
  85. package/dist/useSlider/index.js +401 -0
  86. package/dist/useSlider/index.js.map +1 -0
  87. package/dist/useSwitch/index.cjs +264 -0
  88. package/dist/useSwitch/index.cjs.map +1 -0
  89. package/dist/useSwitch/index.d.cts +110 -0
  90. package/dist/useSwitch/index.d.ts +110 -0
  91. package/dist/useSwitch/index.js +237 -0
  92. package/dist/useSwitch/index.js.map +1 -0
  93. package/dist/useTabs/index.cjs +153 -0
  94. package/dist/useTabs/index.cjs.map +1 -0
  95. package/dist/useTabs/index.d.cts +84 -0
  96. package/dist/useTabs/index.d.ts +84 -0
  97. package/dist/useTabs/index.js +126 -0
  98. package/dist/useTabs/index.js.map +1 -0
  99. package/dist/useToast/index.cjs +375 -0
  100. package/dist/useToast/index.cjs.map +1 -0
  101. package/dist/useToast/index.d.cts +148 -0
  102. package/dist/useToast/index.d.ts +148 -0
  103. package/dist/useToast/index.js +358 -0
  104. package/dist/useToast/index.js.map +1 -0
  105. package/dist/useToastProvider/index.cjs +118 -0
  106. package/dist/useToastProvider/index.cjs.map +1 -0
  107. package/dist/useToastProvider/index.d.cts +25 -0
  108. package/dist/useToastProvider/index.d.ts +25 -0
  109. package/dist/useToastProvider/index.js +96 -0
  110. package/dist/useToastProvider/index.js.map +1 -0
  111. package/dist/useToastViewport/index.cjs +227 -0
  112. package/dist/useToastViewport/index.cjs.map +1 -0
  113. package/dist/useToastViewport/index.d.cts +130 -0
  114. package/dist/useToastViewport/index.d.ts +130 -0
  115. package/dist/useToastViewport/index.js +207 -0
  116. package/dist/useToastViewport/index.js.map +1 -0
  117. package/dist/useToggle/index.cjs +86 -0
  118. package/dist/useToggle/index.cjs.map +1 -0
  119. package/dist/useToggle/index.d.cts +66 -0
  120. package/dist/useToggle/index.d.ts +66 -0
  121. package/dist/useToggle/index.js +59 -0
  122. package/dist/useToggle/index.js.map +1 -0
  123. package/dist/useToggleGroup/index.cjs +227 -0
  124. package/dist/useToggleGroup/index.cjs.map +1 -0
  125. package/dist/useToggleGroup/index.d.cts +159 -0
  126. package/dist/useToggleGroup/index.d.ts +159 -0
  127. package/dist/useToggleGroup/index.js +207 -0
  128. package/dist/useToggleGroup/index.js.map +1 -0
  129. package/package.json +163 -3
  130. package/src/index.ts +37 -0
  131. package/src/useCheckbox/index.ts +3 -0
  132. package/src/useCheckbox/types.ts +150 -0
  133. package/src/useCheckbox/useCheckbox.ts +141 -0
  134. package/src/useCheckboxGroup/index.ts +3 -0
  135. package/src/useCheckboxGroup/types.ts +104 -0
  136. package/src/useCheckboxGroup/useCheckboxGroup.ts +79 -0
  137. package/src/useCollapsible/index.ts +3 -0
  138. package/src/useCollapsible/types.ts +103 -0
  139. package/src/useCollapsible/useCollapsible.ts +160 -0
  140. package/src/useDialog/index.ts +3 -0
  141. package/src/useDialog/types.ts +109 -0
  142. package/src/useDialog/useDialog.ts +181 -0
  143. package/src/useForm/index.ts +9 -0
  144. package/src/useForm/types.ts +149 -0
  145. package/src/useForm/useForm.ts +156 -0
  146. package/src/useFormControl/index.ts +3 -0
  147. package/src/useFormControl/types.ts +101 -0
  148. package/src/useFormControl/useFormControl.ts +181 -0
  149. package/src/useFormField/index.ts +3 -0
  150. package/src/useFormField/types.ts +65 -0
  151. package/src/useFormField/useFormField.ts +46 -0
  152. package/src/useFormMessage/index.ts +3 -0
  153. package/src/useFormMessage/types.ts +64 -0
  154. package/src/useFormMessage/useFormMessage.ts +116 -0
  155. package/src/usePresence/index.ts +3 -0
  156. package/src/usePresence/types.ts +38 -0
  157. package/src/usePresence/usePresence.ts +168 -0
  158. package/src/useRadioGroup/index.ts +8 -0
  159. package/src/useRadioGroup/types.ts +173 -0
  160. package/src/useRadioGroup/useRadioGroup.ts +204 -0
  161. package/src/useScrollArea/index.ts +3 -0
  162. package/src/useScrollArea/types.ts +141 -0
  163. package/src/useScrollArea/useScrollArea.ts +360 -0
  164. package/src/useSlider/index.ts +3 -0
  165. package/src/useSlider/types.ts +231 -0
  166. package/src/useSlider/useSlider.ts +486 -0
  167. package/src/useSwitch/index.ts +3 -0
  168. package/src/useSwitch/types.ts +109 -0
  169. package/src/useSwitch/useSwitch.ts +144 -0
  170. package/src/useTabs/index.ts +3 -0
  171. package/src/useTabs/types.ts +83 -0
  172. package/src/useTabs/useTabs.ts +196 -0
  173. package/src/useToast/index.ts +3 -0
  174. package/src/useToast/types.ts +167 -0
  175. package/src/useToast/useToast.ts +378 -0
  176. package/src/useToastProvider/index.ts +3 -0
  177. package/src/useToastProvider/types.ts +121 -0
  178. package/src/useToastProvider/useToastProvider.ts +115 -0
  179. package/src/useToastViewport/index.ts +3 -0
  180. package/src/useToastViewport/types.ts +131 -0
  181. package/src/useToastViewport/useToastViewport.ts +319 -0
  182. package/src/useToggle/index.ts +3 -0
  183. package/src/useToggle/types.ts +59 -0
  184. package/src/useToggle/useToggle.ts +57 -0
  185. package/src/useToggleGroup/index.ts +3 -0
  186. package/src/useToggleGroup/types.ts +171 -0
  187. package/src/useToggleGroup/useToggleGroup.ts +260 -0
  188. package/src/utils/env.ts +26 -0
  189. package/src/utils/useBubbleInput.ts +168 -0
  190. package/src/utils/useCollection.ts +92 -0
  191. package/src/utils/useControllable.ts +96 -0
  192. package/src/utils/useFocusTrap.ts +160 -0
  193. package/src/utils/useFormResetListener.ts +80 -0
  194. package/src/utils/usePointerDrag.ts +101 -0
  195. package/src/utils/useResizeObserver.ts +60 -0
  196. package/src/utils/useScrollLock.ts +95 -0
package/dist/index.cjs ADDED
@@ -0,0 +1,2610 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ useCheckbox: () => useCheckbox,
24
+ useCheckboxGroup: () => useCheckboxGroup,
25
+ useCollapsible: () => useCollapsible,
26
+ useDialog: () => useDialog,
27
+ useForm: () => useForm,
28
+ useFormControl: () => useFormControl,
29
+ useFormField: () => useFormField,
30
+ useFormMessage: () => useFormMessage,
31
+ usePresence: () => usePresence,
32
+ useRadioGroup: () => useRadioGroup,
33
+ useScrollArea: () => useScrollArea,
34
+ useSlider: () => useSlider,
35
+ useSwitch: () => useSwitch,
36
+ useTabs: () => useTabs,
37
+ useToast: () => useToast,
38
+ useToastProvider: () => useToastProvider,
39
+ useToastViewport: () => useToastViewport,
40
+ useToggle: () => useToggle,
41
+ useToggleGroup: () => useToggleGroup
42
+ });
43
+ module.exports = __toCommonJS(src_exports);
44
+
45
+ // src/useDialog/useDialog.ts
46
+ var import_vue3 = require("vue");
47
+ var import_dialog = require("@agile-plus/primitives/dialog");
48
+
49
+ // src/utils/useFocusTrap.ts
50
+ var import_vue = require("vue");
51
+ var import_dom = require("@agile-plus/primitives/dom");
52
+ var trapStack = [];
53
+ function focusWithin(container, target) {
54
+ target.focus({ preventScroll: true });
55
+ if (!container.contains(document.activeElement)) {
56
+ container.focus({ preventScroll: true });
57
+ }
58
+ }
59
+ function useFocusTrap(options) {
60
+ const token = /* @__PURE__ */ Symbol("focus-trap");
61
+ let isActive = false;
62
+ function isTopmost() {
63
+ return trapStack[trapStack.length - 1] === token;
64
+ }
65
+ function handleKeydown(event) {
66
+ if (event.defaultPrevented || event.key !== "Tab") return;
67
+ if (event.altKey || event.ctrlKey || event.metaKey) return;
68
+ if (!isTopmost()) return;
69
+ const container = options.container.value;
70
+ if (!container?.isConnected) return;
71
+ const tabbables = (0, import_dom.getTabbableCandidates)(container);
72
+ if (tabbables.length === 0) {
73
+ event.preventDefault();
74
+ container.focus({ preventScroll: true });
75
+ return;
76
+ }
77
+ const first = tabbables[0];
78
+ const last = tabbables[tabbables.length - 1];
79
+ const current = document.activeElement;
80
+ if (!(current instanceof HTMLElement) || !container.contains(current)) {
81
+ event.preventDefault();
82
+ focusWithin(container, event.shiftKey ? last : first);
83
+ return;
84
+ }
85
+ const atStart = current === container || current === first;
86
+ if (event.shiftKey && atStart) {
87
+ event.preventDefault();
88
+ focusWithin(container, last);
89
+ return;
90
+ }
91
+ if (!event.shiftKey && current === last) {
92
+ event.preventDefault();
93
+ focusWithin(container, first);
94
+ }
95
+ }
96
+ function handleFocusIn(event) {
97
+ if (!isTopmost()) return;
98
+ const container = options.container.value;
99
+ if (!container?.isConnected) return;
100
+ const target = event.target;
101
+ if (target instanceof Node && container.contains(target)) return;
102
+ const tabbables = (0, import_dom.getTabbableCandidates)(container);
103
+ focusWithin(container, tabbables[0] ?? container);
104
+ }
105
+ function activate() {
106
+ if (isActive) return;
107
+ isActive = true;
108
+ trapStack.push(token);
109
+ document.addEventListener("keydown", handleKeydown);
110
+ document.addEventListener("focusin", handleFocusIn, true);
111
+ }
112
+ function deactivate() {
113
+ if (!isActive) return;
114
+ isActive = false;
115
+ const index = trapStack.indexOf(token);
116
+ if (index !== -1) trapStack.splice(index, 1);
117
+ document.removeEventListener("keydown", handleKeydown);
118
+ document.removeEventListener("focusin", handleFocusIn, true);
119
+ }
120
+ (0, import_vue.watch)(
121
+ [() => (0, import_vue.toValue)(options.active), options.container],
122
+ ([active, container]) => {
123
+ if (active && container) {
124
+ activate();
125
+ return;
126
+ }
127
+ deactivate();
128
+ },
129
+ { immediate: true, flush: "post" }
130
+ );
131
+ (0, import_vue.onScopeDispose)(deactivate);
132
+ }
133
+
134
+ // src/utils/useScrollLock.ts
135
+ var import_vue2 = require("vue");
136
+
137
+ // src/utils/env.ts
138
+ var isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
139
+ function isObserverAvailable(constructor) {
140
+ return typeof constructor === "function";
141
+ }
142
+
143
+ // src/utils/useScrollLock.ts
144
+ var lockCount = 0;
145
+ var originalOverflow = "";
146
+ var originalPaddingRight = "";
147
+ function getScrollbarWidth() {
148
+ const documentWidth = document.documentElement.clientWidth;
149
+ if (documentWidth <= 0) return 0;
150
+ return Math.max(0, window.innerWidth - documentWidth);
151
+ }
152
+ function acquireScrollLock() {
153
+ const body = document.body;
154
+ if (lockCount === 0) {
155
+ originalOverflow = body.style.overflow;
156
+ originalPaddingRight = body.style.paddingRight;
157
+ const scrollbarWidth = getScrollbarWidth();
158
+ if (scrollbarWidth > 0) {
159
+ const currentPadding = Number.parseFloat(window.getComputedStyle(body).paddingRight) || 0;
160
+ body.style.paddingRight = `${currentPadding + scrollbarWidth}px`;
161
+ }
162
+ body.style.overflow = "hidden";
163
+ }
164
+ lockCount += 1;
165
+ let released = false;
166
+ return () => {
167
+ if (released) return;
168
+ released = true;
169
+ lockCount = Math.max(0, lockCount - 1);
170
+ if (lockCount > 0) return;
171
+ body.style.overflow = originalOverflow;
172
+ body.style.paddingRight = originalPaddingRight;
173
+ };
174
+ }
175
+ function useScrollLock(active) {
176
+ if (!isBrowser) return;
177
+ let release = null;
178
+ (0, import_vue2.watch)(
179
+ () => (0, import_vue2.toValue)(active),
180
+ (isActive) => {
181
+ if (isActive) {
182
+ release ??= acquireScrollLock();
183
+ return;
184
+ }
185
+ release?.();
186
+ release = null;
187
+ },
188
+ { immediate: true }
189
+ );
190
+ (0, import_vue2.onScopeDispose)(() => {
191
+ release?.();
192
+ release = null;
193
+ });
194
+ }
195
+
196
+ // src/useDialog/useDialog.ts
197
+ function useDialog(options = {}) {
198
+ const { defaultOpen = false, closeOnEscape = true, closeOnOverlayClick = true } = options;
199
+ const controlledOpen = (0, import_vue3.computed)(() => (0, import_vue3.toValue)(options.open));
200
+ const isControlled = (0, import_vue3.computed)(() => controlledOpen.value !== void 0);
201
+ const machine = (0, import_dialog.createDialogMachine)({
202
+ defaultOpen,
203
+ closeOnEscape,
204
+ closeOnOverlayClick
205
+ });
206
+ const internalOpen = (0, import_vue3.ref)(machine.getState().open);
207
+ const isOpen = (0, import_vue3.computed)(() => isControlled.value ? controlledOpen.value : internalOpen.value);
208
+ const contentElement = (0, import_vue3.ref)(null);
209
+ const portalTarget = (0, import_vue3.computed)(() => (0, import_vue3.toValue)(options.container) ?? "body");
210
+ function setContentElement(node) {
211
+ contentElement.value = typeof HTMLElement !== "undefined" && node instanceof HTMLElement ? node : null;
212
+ }
213
+ useFocusTrap({ active: isOpen, container: contentElement });
214
+ useScrollLock(isOpen);
215
+ const unsubscribe = machine.subscribe((state) => {
216
+ if (!isControlled.value) {
217
+ internalOpen.value = state.open;
218
+ }
219
+ });
220
+ (0, import_vue3.watch)(
221
+ controlledOpen,
222
+ (value) => {
223
+ if (value !== void 0) {
224
+ machine.send({ type: "SET_OPEN", payload: value });
225
+ }
226
+ },
227
+ { immediate: true }
228
+ );
229
+ function setOpen(value) {
230
+ options.onOpenChange?.(value);
231
+ if (!isControlled.value) {
232
+ machine.send({ type: "SET_OPEN", payload: value });
233
+ }
234
+ }
235
+ function open() {
236
+ setOpen(true);
237
+ }
238
+ function close() {
239
+ setOpen(false);
240
+ }
241
+ function toggle() {
242
+ setOpen(!isOpen.value);
243
+ }
244
+ function onContentKeydown(event) {
245
+ const result = (0, import_dialog.handleDialogKeydown)(event.key, {
246
+ isOpen: isOpen.value,
247
+ canCloseOnEscape: closeOnEscape
248
+ });
249
+ if (result.handled) {
250
+ event.preventDefault();
251
+ }
252
+ if (result.shouldClose) {
253
+ close();
254
+ }
255
+ }
256
+ function onOverlayClick() {
257
+ if (closeOnOverlayClick) {
258
+ close();
259
+ }
260
+ }
261
+ (0, import_vue3.onScopeDispose)(() => {
262
+ unsubscribe();
263
+ machine.destroy();
264
+ });
265
+ const ids = machine.getState();
266
+ function getTriggerProps() {
267
+ return {
268
+ id: ids.triggerId,
269
+ "aria-haspopup": "dialog",
270
+ "aria-expanded": isOpen.value,
271
+ "aria-controls": isOpen.value ? ids.contentId : void 0
272
+ };
273
+ }
274
+ function getContentProps() {
275
+ return {
276
+ id: ids.contentId,
277
+ role: "dialog",
278
+ "aria-modal": true,
279
+ "aria-labelledby": ids.titleId,
280
+ "aria-describedby": ids.descriptionId,
281
+ tabindex: -1
282
+ };
283
+ }
284
+ function getOverlayProps() {
285
+ return {
286
+ "aria-hidden": true
287
+ };
288
+ }
289
+ function getTitleProps() {
290
+ return { id: ids.titleId };
291
+ }
292
+ function getDescriptionProps() {
293
+ return { id: ids.descriptionId };
294
+ }
295
+ return {
296
+ isOpen,
297
+ open,
298
+ close,
299
+ toggle,
300
+ portalTarget,
301
+ getTriggerProps,
302
+ getContentProps,
303
+ getOverlayProps,
304
+ getTitleProps,
305
+ getDescriptionProps,
306
+ setContentElement,
307
+ onContentKeydown,
308
+ onOverlayClick
309
+ };
310
+ }
311
+
312
+ // src/useTabs/useTabs.ts
313
+ var import_vue4 = require("vue");
314
+ var import_tabs = require("@agile-plus/primitives/tabs");
315
+ function useTabs(options = {}) {
316
+ const { defaultValue = "", activationMode = "automatic", orientation = "horizontal" } = options;
317
+ const uid = (0, import_vue4.useId)();
318
+ function getTriggerId(tabValue) {
319
+ return `${uid}-tab-${tabValue}`;
320
+ }
321
+ function getPanelId(tabValue) {
322
+ return `${uid}-tabpanel-${tabValue}`;
323
+ }
324
+ const controlledActive = (0, import_vue4.computed)(() => (0, import_vue4.toValue)(options.modelValue));
325
+ const isControlled = (0, import_vue4.computed)(() => controlledActive.value !== void 0);
326
+ const machine = (0, import_tabs.createTabsMachine)({
327
+ defaultValue,
328
+ activationMode,
329
+ orientation
330
+ });
331
+ const internalActive = (0, import_vue4.ref)(machine.getState().activeValue);
332
+ const activeValue = (0, import_vue4.computed)(
333
+ () => isControlled.value ? controlledActive.value : internalActive.value
334
+ );
335
+ const unsubscribe = machine.subscribe((state) => {
336
+ const changed = state.activeValue !== activeValue.value;
337
+ if (!isControlled.value) {
338
+ internalActive.value = state.activeValue;
339
+ }
340
+ if (changed) {
341
+ options.onValueChange?.(state.activeValue);
342
+ }
343
+ });
344
+ (0, import_vue4.watch)(
345
+ controlledActive,
346
+ (value) => {
347
+ if (value !== void 0) {
348
+ machine.send({ type: "SET_ACTIVE", payload: value });
349
+ }
350
+ },
351
+ { immediate: true }
352
+ );
353
+ function setActive(value) {
354
+ if (isControlled.value) {
355
+ options.onValueChange?.(value);
356
+ return;
357
+ }
358
+ machine.send({ type: "SET_ACTIVE", payload: value });
359
+ }
360
+ function registerTab(value) {
361
+ machine.send({ type: "REGISTER_TAB", payload: value });
362
+ }
363
+ function unregisterTab(value) {
364
+ machine.send({ type: "UNREGISTER_TAB", payload: value });
365
+ }
366
+ function onTriggerKeydown(event) {
367
+ const state = machine.getState();
368
+ const result = (0, import_tabs.handleTabsKeydown)(event.key, {
369
+ tabValues: state.tabValues,
370
+ focusedValue: state.focusedValue,
371
+ orientation: state.orientation,
372
+ loop: true
373
+ });
374
+ if (result.handled) {
375
+ event.preventDefault();
376
+ }
377
+ if (result.nextFocusedValue !== null) {
378
+ machine.send({ type: "FOCUS_TAB", payload: result.nextFocusedValue });
379
+ document.getElementById(getTriggerId(result.nextFocusedValue))?.focus();
380
+ }
381
+ if (event.key === "Enter" || event.key === " ") {
382
+ const focused = machine.getState().focusedValue;
383
+ if (focused !== null && activationMode === "manual") {
384
+ event.preventDefault();
385
+ setActive(focused);
386
+ }
387
+ }
388
+ }
389
+ (0, import_vue4.onUnmounted)(() => {
390
+ unsubscribe();
391
+ machine.destroy();
392
+ });
393
+ function getTabListProps() {
394
+ return {
395
+ role: "tablist",
396
+ "aria-orientation": orientation
397
+ };
398
+ }
399
+ function getTriggerProps(value) {
400
+ const isActive = activeValue.value === value;
401
+ return {
402
+ role: "tab",
403
+ "aria-selected": isActive,
404
+ "aria-controls": getPanelId(value),
405
+ id: getTriggerId(value),
406
+ tabindex: isActive ? 0 : -1,
407
+ "data-state": isActive ? "active" : "inactive",
408
+ "data-value": value
409
+ };
410
+ }
411
+ function getContentProps(value) {
412
+ const isActive = activeValue.value === value;
413
+ return {
414
+ role: "tabpanel",
415
+ "aria-labelledby": getTriggerId(value),
416
+ id: getPanelId(value),
417
+ tabindex: 0,
418
+ "data-state": isActive ? "active" : "inactive",
419
+ "data-value": value,
420
+ hidden: !isActive
421
+ };
422
+ }
423
+ return {
424
+ activeValue,
425
+ setActive,
426
+ registerTab,
427
+ unregisterTab,
428
+ getTabListProps,
429
+ getTriggerProps,
430
+ getContentProps,
431
+ onTriggerKeydown
432
+ };
433
+ }
434
+
435
+ // src/useRadioGroup/useRadioGroup.ts
436
+ var import_vue7 = require("vue");
437
+ var import_radio_group = require("@agile-plus/primitives/radio-group");
438
+
439
+ // src/utils/useCollection.ts
440
+ var import_vue5 = require("vue");
441
+ function useCollection(options) {
442
+ const entries = (0, import_vue5.shallowRef)([]);
443
+ const items = (0, import_vue5.computed)(() => entries.value);
444
+ function add(item) {
445
+ const key = options.key(item);
446
+ entries.value = [...entries.value.filter((existing) => options.key(existing) !== key), item];
447
+ return () => {
448
+ entries.value = entries.value.filter((existing) => existing !== item);
449
+ };
450
+ }
451
+ function remove(key) {
452
+ entries.value = entries.value.filter((existing) => options.key(existing) !== key);
453
+ }
454
+ function replace(item) {
455
+ const key = options.key(item);
456
+ entries.value = entries.value.map(
457
+ (existing) => options.key(existing) === key ? item : existing
458
+ );
459
+ }
460
+ return { items, add, remove, replace };
461
+ }
462
+
463
+ // src/utils/useControllable.ts
464
+ var import_vue6 = require("vue");
465
+ function useControllable(options) {
466
+ const controlled = (0, import_vue6.computed)(() => (0, import_vue6.toValue)(options.value));
467
+ const isControlled = (0, import_vue6.computed)(() => controlled.value !== void 0);
468
+ const internal = (0, import_vue6.shallowRef)(options.defaultValue);
469
+ const value = (0, import_vue6.computed)(() => {
470
+ const current = controlled.value;
471
+ return current === void 0 ? internal.value : current;
472
+ });
473
+ function set(next) {
474
+ if (!isControlled.value) internal.value = next;
475
+ options.onChange?.(next);
476
+ }
477
+ function replace(next) {
478
+ if (isControlled.value) return;
479
+ internal.value = next;
480
+ }
481
+ return { value, isControlled, set, replace };
482
+ }
483
+
484
+ // src/useRadioGroup/useRadioGroup.ts
485
+ function useRadioGroup(options = {}) {
486
+ const { defaultValue = "", loop = true } = options;
487
+ const uid = (0, import_vue7.useId)();
488
+ const state = useControllable({
489
+ value: () => (0, import_vue7.toValue)(options.modelValue),
490
+ defaultValue,
491
+ onChange: (next) => options.onValueChange?.(next)
492
+ });
493
+ const value = state.value;
494
+ const isGroupDisabled = (0, import_vue7.computed)(() => (0, import_vue7.toValue)(options.disabled) === true);
495
+ const hasName = (0, import_vue7.computed)(() => !!(0, import_vue7.toValue)(options.name));
496
+ const collection = useCollection({ key: (item) => item.value });
497
+ const enabledValues = (0, import_vue7.computed)(
498
+ () => isGroupDisabled.value ? [] : collection.items.value.filter((item) => !item.disabled).map((item) => item.value)
499
+ );
500
+ const tabStopValue = (0, import_vue7.computed)(
501
+ () => value.value === "" ? enabledValues.value[0] ?? "" : value.value
502
+ );
503
+ function getItemId(itemValue) {
504
+ return `${uid}-radio-${itemValue}`;
505
+ }
506
+ function setValue(next) {
507
+ state.set(next);
508
+ }
509
+ function registerItem(itemValue) {
510
+ if (collection.items.value.some((item) => item.value === itemValue)) return;
511
+ collection.add({ value: itemValue, disabled: false });
512
+ }
513
+ function setItemDisabled(itemValue, disabled) {
514
+ const current = collection.items.value.find((item) => item.value === itemValue);
515
+ if (!current || current.disabled === disabled) return;
516
+ collection.replace({ value: itemValue, disabled });
517
+ }
518
+ function unregisterItem(itemValue) {
519
+ collection.remove(itemValue);
520
+ if (value.value === itemValue) state.replace("");
521
+ }
522
+ function isItemDisabled(itemValue) {
523
+ if (isGroupDisabled.value) return true;
524
+ return collection.items.value.find((item) => item.value === itemValue)?.disabled === true;
525
+ }
526
+ function onItemKeydown(event) {
527
+ const current = event.currentTarget;
528
+ const focusedValue = current?.dataset.value ?? null;
529
+ const result = (0, import_radio_group.handleRadioGroupKeydown)(event.key, {
530
+ enabledValues: enabledValues.value,
531
+ focusedValue,
532
+ loop
533
+ });
534
+ if (!result.handled) return;
535
+ event.preventDefault();
536
+ if (result.nextValue === null) return;
537
+ setValue(result.nextValue);
538
+ document.getElementById(getItemId(result.nextValue))?.focus();
539
+ }
540
+ function getRootProps() {
541
+ const required = (0, import_vue7.toValue)(options.required) === true;
542
+ const labelledby = (0, import_vue7.toValue)(options.ariaLabelledby);
543
+ const describedby = (0, import_vue7.toValue)(options.ariaDescribedby);
544
+ const orientation = (0, import_vue7.toValue)(options.orientation) ?? "horizontal";
545
+ return {
546
+ role: "radiogroup",
547
+ "aria-orientation": orientation,
548
+ // 样式层依赖 data-* 而非 aria-*:ARIA 属性面向辅助技术,不应成为视觉契约。
549
+ "data-orientation": orientation,
550
+ "aria-required": required || void 0,
551
+ "aria-labelledby": labelledby || void 0,
552
+ "aria-describedby": describedby || void 0,
553
+ "aria-disabled": isGroupDisabled.value || void 0,
554
+ "data-disabled": isGroupDisabled.value || void 0
555
+ };
556
+ }
557
+ function getItemProps(itemValue) {
558
+ const checked = value.value === itemValue;
559
+ const disabled = isItemDisabled(itemValue);
560
+ const focusable = !disabled && (checked || tabStopValue.value === itemValue);
561
+ return {
562
+ id: getItemId(itemValue),
563
+ role: "radio",
564
+ "aria-checked": checked,
565
+ "aria-disabled": disabled || void 0,
566
+ tabindex: focusable ? 0 : -1,
567
+ "data-state": checked ? "checked" : "unchecked",
568
+ "data-disabled": disabled || void 0,
569
+ "data-value": itemValue,
570
+ "data-orientation": (0, import_vue7.toValue)(options.orientation) ?? "horizontal"
571
+ };
572
+ }
573
+ function getInputProps(itemValue) {
574
+ const name = (0, import_vue7.toValue)(options.name);
575
+ if (!name) return null;
576
+ return {
577
+ type: "radio",
578
+ name,
579
+ value: itemValue,
580
+ checked: value.value === itemValue,
581
+ disabled: isItemDisabled(itemValue),
582
+ tabindex: -1,
583
+ "aria-hidden": true
584
+ };
585
+ }
586
+ return {
587
+ value,
588
+ isGroupDisabled,
589
+ hasName,
590
+ setValue,
591
+ registerItem,
592
+ setItemDisabled,
593
+ unregisterItem,
594
+ isItemDisabled,
595
+ getRootProps,
596
+ getItemProps,
597
+ getInputProps,
598
+ onItemKeydown
599
+ };
600
+ }
601
+
602
+ // src/useCheckbox/useCheckbox.ts
603
+ var import_vue11 = require("vue");
604
+ var import_checkbox = require("@agile-plus/primitives/checkbox");
605
+ var import_form2 = require("@agile-plus/primitives/form");
606
+
607
+ // src/utils/useBubbleInput.ts
608
+ var import_vue10 = require("vue");
609
+ var import_form = require("@agile-plus/primitives/form");
610
+
611
+ // src/utils/useResizeObserver.ts
612
+ var import_vue8 = require("vue");
613
+ function useResizeObserver(onResize) {
614
+ let observer = null;
615
+ function observe(element) {
616
+ if (!element || !isBrowser || !isObserverAvailable(globalThis.ResizeObserver)) return;
617
+ observer ??= new ResizeObserver(() => onResize());
618
+ observer.observe(element);
619
+ }
620
+ function unobserve(element) {
621
+ observer?.unobserve(element);
622
+ }
623
+ function disconnect() {
624
+ observer?.disconnect();
625
+ observer = null;
626
+ }
627
+ (0, import_vue8.onScopeDispose)(disconnect);
628
+ return { observe, unobserve, disconnect };
629
+ }
630
+
631
+ // src/utils/useFormResetListener.ts
632
+ var import_vue9 = require("vue");
633
+ function resolveForm(element, formId) {
634
+ if (!isBrowser) return null;
635
+ if (formId) {
636
+ const node = document.getElementById(formId);
637
+ return node instanceof HTMLFormElement ? node : null;
638
+ }
639
+ const native = element && "form" in element ? element.form : null;
640
+ if (native instanceof HTMLFormElement) return native;
641
+ const closest = element?.closest("form");
642
+ return closest instanceof HTMLFormElement ? closest : null;
643
+ }
644
+ function useFormResetListener(control, onReset, formId) {
645
+ let target = null;
646
+ function detach() {
647
+ if (!target) return;
648
+ target.removeEventListener("reset", onReset);
649
+ target = null;
650
+ }
651
+ (0, import_vue9.watch)(
652
+ [control, () => (0, import_vue9.toValue)(formId)],
653
+ ([element, nextFormId]) => {
654
+ detach();
655
+ if (!isBrowser) return;
656
+ const form = resolveForm(element, nextFormId);
657
+ if (!form) return;
658
+ form.addEventListener("reset", onReset);
659
+ target = form;
660
+ },
661
+ { flush: "post" }
662
+ );
663
+ (0, import_vue9.onScopeDispose)(detach);
664
+ }
665
+
666
+ // src/utils/useBubbleInput.ts
667
+ function useBubbleInput(options) {
668
+ const inputElement = (0, import_vue10.ref)(null);
669
+ const size = (0, import_vue10.shallowRef)(null);
670
+ const formId = (0, import_vue10.computed)(() => (0, import_vue10.toValue)(options.form));
671
+ const isFormControl = (0, import_vue10.computed)(() => {
672
+ if (formId.value) return true;
673
+ const element = options.control.value;
674
+ if (!element) return true;
675
+ return element.closest("form") !== null;
676
+ });
677
+ const style = (0, import_vue10.computed)(() => (0, import_form.getHiddenInputStyle)(size.value));
678
+ const resize = useResizeObserver(measure);
679
+ function measure() {
680
+ const element = options.control.value;
681
+ if (!element) {
682
+ size.value = null;
683
+ return;
684
+ }
685
+ const rect = element.getBoundingClientRect();
686
+ size.value = { width: rect.width, height: rect.height };
687
+ }
688
+ function syncInput(notify) {
689
+ const input = inputElement.value;
690
+ if (!input) return;
691
+ (0, import_form.writeNativeChecked)(input, options.checked());
692
+ if (notify) input.dispatchEvent(new Event("change", { bubbles: true }));
693
+ }
694
+ useFormResetListener(
695
+ options.control,
696
+ () => options.onReset(),
697
+ () => formId.value
698
+ );
699
+ (0, import_vue10.watch)(
700
+ options.control,
701
+ (element) => {
702
+ resize.disconnect();
703
+ if (!isBrowser) return;
704
+ measure();
705
+ resize.observe(element);
706
+ },
707
+ { flush: "post" }
708
+ );
709
+ (0, import_vue10.watch)(inputElement, (input) => {
710
+ if (!input) return;
711
+ input.defaultChecked = options.checked();
712
+ syncInput(false);
713
+ });
714
+ (0, import_vue10.watch)(
715
+ () => options.checked(),
716
+ () => syncInput(true)
717
+ );
718
+ function setInputElement(node) {
719
+ inputElement.value = node instanceof HTMLInputElement ? node : null;
720
+ }
721
+ return { isFormControl, style, inputElement, setInputElement };
722
+ }
723
+
724
+ // src/useCheckbox/useCheckbox.ts
725
+ function useCheckbox(options = {}) {
726
+ const { defaultChecked = false } = options;
727
+ const state = useControllable({
728
+ value: () => (0, import_vue11.toValue)(options.checked),
729
+ defaultValue: defaultChecked,
730
+ onChange: (next) => options.onCheckedChange?.(next)
731
+ });
732
+ const checked = state.value;
733
+ const isDisabled = (0, import_vue11.computed)(() => (0, import_vue11.toValue)(options.disabled) === true);
734
+ const isRequired = (0, import_vue11.computed)(() => (0, import_vue11.toValue)(options.required) === true);
735
+ const isIndicatorPresent = (0, import_vue11.computed)(() => (0, import_checkbox.isCheckboxIndicatorPresent)(checked.value));
736
+ const control = (0, import_vue11.ref)(null);
737
+ const initialChecked = checked.value;
738
+ const bubble = useBubbleInput({
739
+ control,
740
+ checked: () => checked.value === true,
741
+ onReset: () => setChecked(initialChecked)
742
+ });
743
+ function setChecked(next) {
744
+ state.set(next);
745
+ }
746
+ function toggle() {
747
+ if (isDisabled.value) return;
748
+ setChecked((0, import_checkbox.resolveNextChecked)(checked.value));
749
+ }
750
+ function setControl(node) {
751
+ control.value = node instanceof HTMLElement ? node : null;
752
+ }
753
+ function getRootProps() {
754
+ const id = (0, import_vue11.toValue)(options.id);
755
+ return {
756
+ type: "button",
757
+ role: "checkbox",
758
+ id: id || void 0,
759
+ ...(0, import_checkbox.getCheckboxAttrs)({
760
+ checked: checked.value,
761
+ disabled: isDisabled.value,
762
+ required: isRequired.value
763
+ }),
764
+ disabled: isDisabled.value || void 0
765
+ };
766
+ }
767
+ function getInputProps() {
768
+ if (!bubble.isFormControl.value) return null;
769
+ return {
770
+ ...(0, import_form2.getHiddenInputAttrs)({
771
+ type: "checkbox",
772
+ name: (0, import_vue11.toValue)(options.name),
773
+ value: (0, import_vue11.toValue)(options.value) ?? "on",
774
+ disabled: isDisabled.value,
775
+ required: isRequired.value
776
+ }),
777
+ style: bubble.style.value
778
+ };
779
+ }
780
+ function onRootClick() {
781
+ toggle();
782
+ }
783
+ return {
784
+ checked,
785
+ isDisabled,
786
+ isFormControl: bubble.isFormControl,
787
+ isIndicatorPresent,
788
+ control,
789
+ setControl,
790
+ inputElement: bubble.inputElement,
791
+ setInputElement: bubble.setInputElement,
792
+ setChecked,
793
+ toggle,
794
+ getRootProps,
795
+ getInputProps,
796
+ onRootClick
797
+ };
798
+ }
799
+
800
+ // src/useCheckboxGroup/useCheckboxGroup.ts
801
+ var import_vue12 = require("vue");
802
+ var import_checkbox2 = require("@agile-plus/primitives/checkbox");
803
+ function useCheckboxGroup(options = {}) {
804
+ const { defaultValue = [] } = options;
805
+ const state = useControllable({
806
+ value: () => (0, import_vue12.toValue)(options.modelValue),
807
+ // 拷贝一份:调用方传入的数组不该被当成内部状态持有,否则外部改写会穿透进来。
808
+ defaultValue: [...defaultValue],
809
+ onChange: (next) => options.onValueChange?.(next)
810
+ });
811
+ const values = state.value;
812
+ const isDisabled = (0, import_vue12.computed)(() => (0, import_vue12.toValue)(options.disabled) === true);
813
+ const isRequired = (0, import_vue12.computed)(() => (0, import_vue12.toValue)(options.required) === true);
814
+ const name = (0, import_vue12.computed)(() => (0, import_vue12.toValue)(options.name));
815
+ function setValues(next) {
816
+ state.set(next);
817
+ }
818
+ function setItemChecked(value, checked) {
819
+ setValues((0, import_checkbox2.toggleGroupValue)(values.value, value, checked));
820
+ }
821
+ function isValueChecked(value) {
822
+ return (0, import_checkbox2.isGroupValueChecked)(values.value, value);
823
+ }
824
+ function getRootProps() {
825
+ const labelledby = (0, import_vue12.toValue)(options.ariaLabelledby);
826
+ const describedby = (0, import_vue12.toValue)(options.ariaDescribedby);
827
+ return {
828
+ role: "group",
829
+ "aria-labelledby": labelledby || void 0,
830
+ "aria-describedby": describedby || void 0,
831
+ "aria-required": isRequired.value ? "true" : void 0,
832
+ "aria-disabled": isDisabled.value || void 0,
833
+ "data-disabled": isDisabled.value || void 0
834
+ };
835
+ }
836
+ return {
837
+ values,
838
+ isDisabled,
839
+ name,
840
+ setValues,
841
+ setItemChecked,
842
+ isValueChecked,
843
+ getRootProps
844
+ };
845
+ }
846
+
847
+ // src/useForm/useForm.ts
848
+ var import_vue13 = require("vue");
849
+ var import_form3 = require("@agile-plus/primitives/form");
850
+ function useForm(options = {}) {
851
+ const validityMap = (0, import_vue13.ref)({});
852
+ const customErrorsMap = (0, import_vue13.ref)({});
853
+ const messageIdsMap = (0, import_vue13.ref)({});
854
+ const matcherEntries = /* @__PURE__ */ new Map();
855
+ function getFieldValidity(name) {
856
+ return validityMap.value[name];
857
+ }
858
+ function setFieldValidity(name, validity) {
859
+ validityMap.value = { ...validityMap.value, [name]: validity };
860
+ }
861
+ function clearFieldValidation(name) {
862
+ validityMap.value = { ...validityMap.value, [name]: void 0 };
863
+ customErrorsMap.value = { ...customErrorsMap.value, [name]: {} };
864
+ }
865
+ function getFieldCustomErrors(name) {
866
+ return customErrorsMap.value[name] ?? {};
867
+ }
868
+ function setFieldCustomErrors(name, errors) {
869
+ customErrorsMap.value = {
870
+ ...customErrorsMap.value,
871
+ [name]: { ...customErrorsMap.value[name], ...errors }
872
+ };
873
+ }
874
+ function getFieldMatchers(name) {
875
+ return matcherEntries.get(name) ?? [];
876
+ }
877
+ function addFieldMatcher(name, entry) {
878
+ const entries = matcherEntries.get(name) ?? [];
879
+ const next = entries.filter((item) => item.id !== entry.id);
880
+ matcherEntries.set(name, [...next, entry]);
881
+ }
882
+ function removeFieldMatcher(name, id) {
883
+ const entries = matcherEntries.get(name);
884
+ if (!entries) return;
885
+ const next = entries.filter((item) => item.id !== id);
886
+ if (next.length === 0) matcherEntries.delete(name);
887
+ else matcherEntries.set(name, next);
888
+ }
889
+ function getFieldDescription(name) {
890
+ const ids = messageIdsMap.value[name] ?? [];
891
+ return ids.length > 0 ? ids.join(" ") : void 0;
892
+ }
893
+ function addFieldMessageId(name, id) {
894
+ const ids = messageIdsMap.value[name] ?? [];
895
+ if (ids.includes(id)) return;
896
+ messageIdsMap.value = { ...messageIdsMap.value, [name]: [...ids, id] };
897
+ }
898
+ function removeFieldMessageId(name, id) {
899
+ const ids = messageIdsMap.value[name] ?? [];
900
+ const next = ids.filter((item) => item !== id);
901
+ if (next.length === ids.length) return;
902
+ messageIdsMap.value = { ...messageIdsMap.value, [name]: next };
903
+ }
904
+ function onFormInvalid(event) {
905
+ const form = event.currentTarget;
906
+ if (!(form instanceof HTMLFormElement)) return;
907
+ const controls = Array.from(form.elements).filter(
908
+ (element) => element instanceof HTMLElement
909
+ );
910
+ const firstInvalid = (0, import_form3.getFirstInvalidControl)(controls);
911
+ if (firstInvalid && firstInvalid === event.target) {
912
+ event.target.focus();
913
+ }
914
+ event.preventDefault();
915
+ }
916
+ function onFormSubmit() {
917
+ options.onClearServerErrors?.();
918
+ }
919
+ function onFormReset() {
920
+ options.onClearServerErrors?.();
921
+ }
922
+ return {
923
+ getFieldValidity,
924
+ setFieldValidity,
925
+ clearFieldValidation,
926
+ getFieldCustomErrors,
927
+ setFieldCustomErrors,
928
+ getFieldMatchers,
929
+ addFieldMatcher,
930
+ removeFieldMatcher,
931
+ getFieldDescription,
932
+ addFieldMessageId,
933
+ removeFieldMessageId,
934
+ onFormInvalid,
935
+ onFormSubmit,
936
+ onFormReset
937
+ };
938
+ }
939
+
940
+ // src/useFormField/useFormField.ts
941
+ var import_vue14 = require("vue");
942
+ var import_form4 = require("@agile-plus/primitives/form");
943
+ function useFormField(options, form) {
944
+ const uid = (0, import_vue14.useId)();
945
+ const name = (0, import_vue14.computed)(() => (0, import_vue14.toValue)(options.name));
946
+ const id = (0, import_vue14.computed)(() => (0, import_vue14.toValue)(options.id) ?? `field-${uid}`);
947
+ const serverInvalid = (0, import_vue14.computed)(() => (0, import_vue14.toValue)(options.serverInvalid) === true);
948
+ const validity = (0, import_vue14.computed)(() => form.getFieldValidity(name.value));
949
+ function getStateAttrs() {
950
+ return (0, import_form4.getFieldStateAttrs)({ validity: validity.value, serverInvalid: serverInvalid.value });
951
+ }
952
+ return { id, name, serverInvalid, validity, getStateAttrs };
953
+ }
954
+
955
+ // src/useFormControl/useFormControl.ts
956
+ var import_vue15 = require("vue");
957
+ var import_form5 = require("@agile-plus/primitives/form");
958
+ function useFormControl(options, form, field) {
959
+ const name = (0, import_vue15.toValue)(options.name) ?? field?.name.value ?? "";
960
+ if (!name) {
961
+ throw new Error("useFormControl \u9700\u8981 name\uFF1A\u8BF7\u628A\u5B83\u653E\u8FDB useFormField\uFF0C\u6216\u663E\u5F0F\u63D0\u4F9B name\u3002");
962
+ }
963
+ const id = (0, import_vue15.toValue)(options.id) ?? field?.id.value;
964
+ const validity = (0, import_vue15.computed)(() => form.getFieldValidity(name));
965
+ const serverInvalid = (0, import_vue15.computed)(() => field?.serverInvalid.value === true);
966
+ const controlElement = (0, import_vue15.ref)(null);
967
+ function setControlElement(node) {
968
+ controlElement.value = node instanceof HTMLElement && "validity" in node && "setCustomValidity" in node ? node : null;
969
+ }
970
+ function getAttrs() {
971
+ return {
972
+ id,
973
+ name,
974
+ ...(0, import_form5.getFieldStateAttrs)({ validity: validity.value, serverInvalid: serverInvalid.value }),
975
+ // 原生无效时不写 aria-invalid:浏览器自己会报告状态,重复声明会让读屏播两遍。
976
+ // 服务端错误没有原生状态可依赖,只能由我们显式声明。
977
+ "aria-invalid": serverInvalid.value ? "true" : void 0,
978
+ "aria-describedby": (0, import_form5.concatAriaDescribedby)(
979
+ (0, import_vue15.toValue)(options.describedby),
980
+ form.getFieldDescription(name)
981
+ ),
982
+ // 关掉浏览器在悬停时显示的原生错误提示:文案已经由 Message 呈现。
983
+ title: ""
984
+ };
985
+ }
986
+ async function validate() {
987
+ const control = controlElement.value;
988
+ if (!control) return;
989
+ const snapshot = (0, import_form5.readValiditySnapshot)(control.validity);
990
+ if ((0, import_form5.hasBuiltInError)(snapshot)) {
991
+ form.setFieldValidity(name, snapshot);
992
+ return;
993
+ }
994
+ const formData = control.form ? new FormData(control.form) : new FormData();
995
+ const entries = form.getFieldMatchers(name);
996
+ const syncEntries = entries.filter(
997
+ (entry) => (0, import_form5.isSyncCustomMatcher)(entry.match)
998
+ );
999
+ const asyncEntries = entries.filter(
1000
+ (entry) => (0, import_form5.isAsyncCustomMatcher)(entry.match)
1001
+ );
1002
+ const syncErrors = Object.fromEntries(
1003
+ syncEntries.map((entry) => [entry.id, entry.match(control.value, formData)])
1004
+ );
1005
+ applyErrors(control, syncErrors);
1006
+ if (Object.values(syncErrors).some(Boolean) || asyncEntries.length === 0) return;
1007
+ const asyncErrors = Object.fromEntries(
1008
+ await Promise.all(
1009
+ asyncEntries.map(
1010
+ async (entry) => [entry.id, await entry.match(control.value, formData)]
1011
+ )
1012
+ )
1013
+ );
1014
+ applyErrors(control, asyncErrors);
1015
+ }
1016
+ function applyErrors(control, errors) {
1017
+ const hasError = Object.values(errors).some(Boolean);
1018
+ control.setCustomValidity(hasError ? import_form5.DEFAULT_INVALID_MESSAGE : "");
1019
+ form.setFieldValidity(name, (0, import_form5.readValiditySnapshot)(control.validity));
1020
+ form.setFieldCustomErrors(name, errors);
1021
+ }
1022
+ function resetValidation() {
1023
+ controlElement.value?.setCustomValidity("");
1024
+ form.clearFieldValidation(name);
1025
+ }
1026
+ function onControlInput() {
1027
+ resetValidation();
1028
+ }
1029
+ function onControlInvalid() {
1030
+ void validate();
1031
+ }
1032
+ useFormResetListener(controlElement, resetValidation);
1033
+ return {
1034
+ controlElement,
1035
+ setControlElement,
1036
+ validity,
1037
+ getAttrs,
1038
+ validate,
1039
+ onControlInput,
1040
+ onControlInvalid,
1041
+ resetValidation
1042
+ };
1043
+ }
1044
+
1045
+ // src/useFormMessage/useFormMessage.ts
1046
+ var import_vue16 = require("vue");
1047
+ var import_form6 = require("@agile-plus/primitives/form");
1048
+ function resolveMatch(match) {
1049
+ if (match === void 0) return void 0;
1050
+ return (0, import_vue16.isRef)(match) ? match.value : match;
1051
+ }
1052
+ function useFormMessage(options, form, field) {
1053
+ const name = (0, import_vue16.toValue)(options.name) ?? field?.name.value;
1054
+ if (!name) {
1055
+ throw new Error("useFormMessage \u9700\u8981 name\uFF1A\u8BF7\u628A\u5B83\u653E\u8FDB useFormField\uFF0C\u6216\u663E\u5F0F\u63D0\u4F9B name\u3002");
1056
+ }
1057
+ const uid = (0, import_vue16.useId)();
1058
+ const id = `message-${uid}`;
1059
+ const match = (0, import_vue16.computed)(() => resolveMatch(options.match));
1060
+ const matches = (0, import_vue16.computed)(
1061
+ () => (0, import_form6.getMessageMatch)({
1062
+ match: match.value,
1063
+ validity: form.getFieldValidity(name),
1064
+ customErrors: form.getFieldCustomErrors(name),
1065
+ messageId: id,
1066
+ forceMatch: (0, import_vue16.toValue)(options.forceMatch) === true
1067
+ })
1068
+ );
1069
+ (0, import_vue16.watchEffect)((onCleanup) => {
1070
+ if (!matches.value) return;
1071
+ form.addFieldMessageId(name, id);
1072
+ onCleanup(() => form.removeFieldMessageId(name, id));
1073
+ });
1074
+ (0, import_vue16.watchEffect)((onCleanup) => {
1075
+ const current = match.value;
1076
+ if (typeof current !== "function") return;
1077
+ form.addFieldMatcher(name, { id, match: current });
1078
+ onCleanup(() => form.removeFieldMatcher(name, id));
1079
+ });
1080
+ function getDefaultText() {
1081
+ const current = match.value;
1082
+ if (typeof current !== "string") return import_form6.DEFAULT_INVALID_MESSAGE;
1083
+ return import_form6.BUILT_IN_VALIDITY_MESSAGES[current] ?? import_form6.DEFAULT_INVALID_MESSAGE;
1084
+ }
1085
+ (0, import_vue16.onScopeDispose)(() => {
1086
+ form.removeFieldMessageId(name, id);
1087
+ form.removeFieldMatcher(name, id);
1088
+ });
1089
+ return { id, name: (0, import_vue16.computed)(() => name), matches, getDefaultText };
1090
+ }
1091
+
1092
+ // src/useCollapsible/useCollapsible.ts
1093
+ var import_vue17 = require("vue");
1094
+ var import_collapsible = require("@agile-plus/primitives/collapsible");
1095
+ function useCollapsible(options = {}) {
1096
+ const state = useControllable({
1097
+ value: () => (0, import_vue17.toValue)(options.open),
1098
+ defaultValue: options.defaultOpen ?? false,
1099
+ onChange: (value) => options.onOpenChange?.(value)
1100
+ });
1101
+ const isOpen = state.value;
1102
+ const isDisabled = (0, import_vue17.computed)(() => (0, import_vue17.toValue)(options.disabled) === true);
1103
+ const contentId = `collapsible-${(0, import_vue17.useId)()}`;
1104
+ const contentElement = (0, import_vue17.ref)(null);
1105
+ const size = (0, import_vue17.shallowRef)(null);
1106
+ const preventMountAnimation = (0, import_vue17.ref)(isOpen.value);
1107
+ let originalStyles = null;
1108
+ let frame = 0;
1109
+ if (isBrowser) {
1110
+ frame = requestAnimationFrame(() => {
1111
+ preventMountAnimation.value = false;
1112
+ });
1113
+ }
1114
+ (0, import_vue17.onScopeDispose)(() => {
1115
+ if (isBrowser) cancelAnimationFrame(frame);
1116
+ });
1117
+ function setOpen(value) {
1118
+ state.set(value);
1119
+ }
1120
+ function open() {
1121
+ setOpen(true);
1122
+ }
1123
+ function close() {
1124
+ setOpen(false);
1125
+ }
1126
+ function toggle() {
1127
+ if (isDisabled.value) return;
1128
+ setOpen(!isOpen.value);
1129
+ }
1130
+ function setContentElement(node) {
1131
+ contentElement.value = node instanceof HTMLElement ? node : null;
1132
+ }
1133
+ function measureContent() {
1134
+ const node = contentElement.value;
1135
+ if (!node || !isBrowser) return;
1136
+ originalStyles = originalStyles ?? {
1137
+ transitionDuration: node.style.transitionDuration,
1138
+ animationName: node.style.animationName
1139
+ };
1140
+ node.style.transitionDuration = "0s";
1141
+ node.style.animationName = "none";
1142
+ const rect = node.getBoundingClientRect();
1143
+ size.value = { height: rect.height, width: rect.width };
1144
+ if (!preventMountAnimation.value) {
1145
+ node.style.transitionDuration = originalStyles.transitionDuration;
1146
+ node.style.animationName = originalStyles.animationName;
1147
+ }
1148
+ }
1149
+ function getRootAttrs() {
1150
+ return (0, import_collapsible.getCollapsibleRootAttrs)({ open: isOpen.value, disabled: isDisabled.value });
1151
+ }
1152
+ function getTriggerAttrs() {
1153
+ return (0, import_collapsible.getCollapsibleTriggerAttrs)({
1154
+ open: isOpen.value,
1155
+ disabled: isDisabled.value,
1156
+ contentId
1157
+ });
1158
+ }
1159
+ function getContentAttrs(isPresent) {
1160
+ return (0, import_collapsible.getCollapsibleContentAttrs)({
1161
+ open: isOpen.value,
1162
+ disabled: isDisabled.value,
1163
+ contentId,
1164
+ isPresent
1165
+ });
1166
+ }
1167
+ function getContentVars() {
1168
+ return (0, import_collapsible.getCollapsibleContentVars)(size.value);
1169
+ }
1170
+ return {
1171
+ isOpen,
1172
+ isDisabled,
1173
+ contentId,
1174
+ open,
1175
+ close,
1176
+ toggle,
1177
+ getRootAttrs,
1178
+ getTriggerAttrs,
1179
+ getContentAttrs,
1180
+ contentElement,
1181
+ setContentElement,
1182
+ measureContent,
1183
+ getContentVars
1184
+ };
1185
+ }
1186
+
1187
+ // src/useScrollArea/useScrollArea.ts
1188
+ var import_vue19 = require("vue");
1189
+ var import_scroll_area = require("@agile-plus/primitives/scroll-area");
1190
+
1191
+ // src/utils/usePointerDrag.ts
1192
+ var import_vue18 = require("vue");
1193
+ function usePointerDrag() {
1194
+ let current = null;
1195
+ function start(handlers) {
1196
+ if (!isBrowser) return;
1197
+ current?.("cancel");
1198
+ const onMove = (event) => {
1199
+ handlers.onMove(event);
1200
+ };
1201
+ const onUp = () => finish("up");
1202
+ const onCancel = () => finish("cancel");
1203
+ function finish(reason) {
1204
+ window.removeEventListener("pointermove", onMove);
1205
+ window.removeEventListener("pointerup", onUp);
1206
+ window.removeEventListener("pointercancel", onCancel);
1207
+ if (current === finish) current = null;
1208
+ handlers.onEnd(reason);
1209
+ }
1210
+ current = finish;
1211
+ window.addEventListener("pointermove", onMove);
1212
+ window.addEventListener("pointerup", onUp);
1213
+ window.addEventListener("pointercancel", onCancel);
1214
+ }
1215
+ function stop() {
1216
+ current?.("cancel");
1217
+ }
1218
+ (0, import_vue18.onScopeDispose)(stop);
1219
+ return { start, stop };
1220
+ }
1221
+
1222
+ // src/useScrollArea/useScrollArea.ts
1223
+ var DEFAULT_TYPE = "hover";
1224
+ var DEFAULT_SCROLL_HIDE_DELAY = 600;
1225
+ var EMPTY_METRICS = { size: 0, offset: 0, hasOverflow: false };
1226
+ function useScrollArea(options = {}) {
1227
+ const { scrollHideDelay = DEFAULT_SCROLL_HIDE_DELAY, minThumbSize } = options;
1228
+ const viewportRef = (0, import_vue19.ref)(null);
1229
+ const measureVersion = (0, import_vue19.ref)(0);
1230
+ const hoveringViewport = (0, import_vue19.ref)(false);
1231
+ const focusingViewport = (0, import_vue19.ref)(false);
1232
+ const hoveringScrollbar = (0, import_vue19.ref)({
1233
+ vertical: false,
1234
+ horizontal: false
1235
+ });
1236
+ const draggingOrientation = (0, import_vue19.ref)(null);
1237
+ const recentlyScrolled = (0, import_vue19.ref)(false);
1238
+ const type = (0, import_vue19.computed)(() => (0, import_vue19.toValue)(options.type) ?? DEFAULT_TYPE);
1239
+ let measureFrame = null;
1240
+ let hideTimer = null;
1241
+ let mutationObserver = null;
1242
+ const resize = useResizeObserver(requestMeasure);
1243
+ const drag = usePointerDrag();
1244
+ function requestMeasure() {
1245
+ if (typeof window === "undefined" || typeof window.requestAnimationFrame !== "function") {
1246
+ return;
1247
+ }
1248
+ if (measureFrame !== null) return;
1249
+ measureFrame = window.requestAnimationFrame(() => {
1250
+ measureFrame = null;
1251
+ measureVersion.value += 1;
1252
+ });
1253
+ }
1254
+ function readTrack(orientation) {
1255
+ const el = viewportRef.value;
1256
+ if (!el) return { viewportSize: 0, scrollSize: 0, scrollOffset: 0 };
1257
+ return orientation === "vertical" ? {
1258
+ viewportSize: el.clientHeight,
1259
+ scrollSize: el.scrollHeight,
1260
+ scrollOffset: el.scrollTop
1261
+ } : {
1262
+ viewportSize: el.clientWidth,
1263
+ scrollSize: el.scrollWidth,
1264
+ scrollOffset: el.scrollLeft
1265
+ };
1266
+ }
1267
+ function measureMetrics(orientation) {
1268
+ const { viewportSize, scrollSize, scrollOffset } = readTrack(orientation);
1269
+ return (0, import_scroll_area.getThumbMetrics)({ viewportSize, scrollSize, scrollOffset, minThumbSize });
1270
+ }
1271
+ const verticalMetrics = (0, import_vue19.computed)(() => {
1272
+ void measureVersion.value;
1273
+ return typeof window === "undefined" ? EMPTY_METRICS : measureMetrics("vertical");
1274
+ });
1275
+ const horizontalMetrics = (0, import_vue19.computed)(() => {
1276
+ void measureVersion.value;
1277
+ return typeof window === "undefined" ? EMPTY_METRICS : measureMetrics("horizontal");
1278
+ });
1279
+ function getMetrics(orientation) {
1280
+ return orientation === "vertical" ? verticalMetrics.value : horizontalMetrics.value;
1281
+ }
1282
+ function markRecentlyScrolled() {
1283
+ recentlyScrolled.value = true;
1284
+ if (hideTimer !== null) clearTimeout(hideTimer);
1285
+ hideTimer = setTimeout(() => {
1286
+ hideTimer = null;
1287
+ recentlyScrolled.value = false;
1288
+ }, scrollHideDelay);
1289
+ }
1290
+ function getVisibility(orientation) {
1291
+ const metrics = getMetrics(orientation);
1292
+ return (0, import_scroll_area.resolveScrollbarVisibility)(
1293
+ {
1294
+ interacting: hoveringViewport.value || focusingViewport.value || hoveringScrollbar.value[orientation],
1295
+ dragging: draggingOrientation.value === orientation,
1296
+ recentlyScrolled: recentlyScrolled.value,
1297
+ hasOverflow: metrics.hasOverflow
1298
+ },
1299
+ type.value
1300
+ );
1301
+ }
1302
+ function getRootProps() {
1303
+ return { dir: (0, import_vue19.toValue)(options.dir) || void 0 };
1304
+ }
1305
+ function getViewportProps() {
1306
+ return { tabindex: 0 };
1307
+ }
1308
+ function getScrollbarProps(orientation) {
1309
+ return {
1310
+ "data-orientation": orientation,
1311
+ "data-state": getVisibility(orientation)
1312
+ };
1313
+ }
1314
+ function getThumbProps(orientation) {
1315
+ return {
1316
+ "data-state": getVisibility(orientation),
1317
+ "data-orientation": orientation
1318
+ };
1319
+ }
1320
+ function getThumbStyle(orientation) {
1321
+ const metrics = getMetrics(orientation);
1322
+ return orientation === "vertical" ? { height: `${metrics.size}px`, transform: `translateY(${metrics.offset}px)` } : { width: `${metrics.size}px`, transform: `translateX(${metrics.offset}px)` };
1323
+ }
1324
+ const isCornerVisible = (0, import_vue19.computed)(
1325
+ () => getVisibility("vertical") === "visible" && getVisibility("horizontal") === "visible"
1326
+ );
1327
+ function getCornerProps() {
1328
+ return { "data-state": isCornerVisible.value ? "visible" : "hidden" };
1329
+ }
1330
+ function onViewportScroll() {
1331
+ markRecentlyScrolled();
1332
+ requestMeasure();
1333
+ }
1334
+ function onViewportPointerEnter() {
1335
+ hoveringViewport.value = true;
1336
+ }
1337
+ function onViewportPointerLeave() {
1338
+ hoveringViewport.value = false;
1339
+ }
1340
+ function onViewportFocusin() {
1341
+ focusingViewport.value = true;
1342
+ }
1343
+ function onViewportFocusout() {
1344
+ focusingViewport.value = false;
1345
+ }
1346
+ function onScrollbarPointerEnter(orientation) {
1347
+ hoveringScrollbar.value = { ...hoveringScrollbar.value, [orientation]: true };
1348
+ }
1349
+ function onScrollbarPointerLeave(orientation) {
1350
+ hoveringScrollbar.value = { ...hoveringScrollbar.value, [orientation]: false };
1351
+ }
1352
+ function onThumbPointerDown(event, orientation) {
1353
+ const el = viewportRef.value;
1354
+ if (!el || typeof window === "undefined") return;
1355
+ const metrics = getMetrics(orientation);
1356
+ if (!metrics.hasOverflow) return;
1357
+ const { viewportSize, scrollSize } = readTrack(orientation);
1358
+ const startPointer = orientation === "vertical" ? event.clientY : event.clientX;
1359
+ const startOffset = metrics.offset;
1360
+ draggingOrientation.value = orientation;
1361
+ event.preventDefault();
1362
+ drag.start({
1363
+ onMove: (moveEvent) => {
1364
+ const currentPointer = orientation === "vertical" ? moveEvent.clientY : moveEvent.clientX;
1365
+ const nextOffset = (0, import_scroll_area.clampThumbOffset)(
1366
+ startOffset + (currentPointer - startPointer),
1367
+ viewportSize,
1368
+ metrics.size
1369
+ );
1370
+ const scrollOffset = (0, import_scroll_area.getScrollOffsetFromThumb)({
1371
+ thumbOffset: nextOffset,
1372
+ viewportSize,
1373
+ scrollSize,
1374
+ thumbSize: metrics.size
1375
+ });
1376
+ if (orientation === "vertical") {
1377
+ el.scrollTop = scrollOffset;
1378
+ } else {
1379
+ el.scrollLeft = scrollOffset;
1380
+ }
1381
+ },
1382
+ onEnd: () => {
1383
+ draggingOrientation.value = null;
1384
+ }
1385
+ });
1386
+ }
1387
+ function observeTargets(el) {
1388
+ resize.observe(el);
1389
+ if (el.firstElementChild instanceof HTMLElement) resize.observe(el.firstElementChild);
1390
+ }
1391
+ function detachObservers() {
1392
+ resize.disconnect();
1393
+ mutationObserver?.disconnect();
1394
+ mutationObserver = null;
1395
+ }
1396
+ (0, import_vue19.watch)(viewportRef, (el) => {
1397
+ detachObservers();
1398
+ if (!el || !isObserverAvailable(globalThis.ResizeObserver)) return;
1399
+ observeTargets(el);
1400
+ if (isObserverAvailable(globalThis.MutationObserver)) {
1401
+ mutationObserver = new MutationObserver(() => {
1402
+ observeTargets(el);
1403
+ requestMeasure();
1404
+ });
1405
+ mutationObserver.observe(el, { childList: true });
1406
+ }
1407
+ requestMeasure();
1408
+ });
1409
+ (0, import_vue19.onScopeDispose)(() => {
1410
+ detachObservers();
1411
+ if (measureFrame !== null && isBrowser) {
1412
+ window.cancelAnimationFrame(measureFrame);
1413
+ measureFrame = null;
1414
+ }
1415
+ if (hideTimer !== null) clearTimeout(hideTimer);
1416
+ });
1417
+ return {
1418
+ viewportRef,
1419
+ type,
1420
+ requestMeasure,
1421
+ getRootProps,
1422
+ getViewportProps,
1423
+ getScrollbarProps,
1424
+ getThumbProps,
1425
+ getThumbStyle,
1426
+ getCornerProps,
1427
+ isCornerVisible,
1428
+ getVisibility,
1429
+ onViewportScroll,
1430
+ onViewportPointerEnter,
1431
+ onViewportPointerLeave,
1432
+ onViewportFocusin,
1433
+ onViewportFocusout,
1434
+ onScrollbarPointerEnter,
1435
+ onScrollbarPointerLeave,
1436
+ onThumbPointerDown
1437
+ };
1438
+ }
1439
+
1440
+ // src/usePresence/usePresence.ts
1441
+ var import_vue20 = require("vue");
1442
+ var import_presence = require("@agile-plus/primitives/presence");
1443
+ function usePresence(options) {
1444
+ const state = (0, import_vue20.ref)((0, import_vue20.toValue)(options.present) ? "mounted" : "unmounted");
1445
+ const element = (0, import_vue20.ref)(null);
1446
+ const isPresent = (0, import_vue20.computed)(() => (0, import_presence.isPresencePresent)(state.value));
1447
+ let previousAnimationName = "none";
1448
+ let fillModeTimer = 0;
1449
+ function readStyles() {
1450
+ if (!element.value) return null;
1451
+ return element.value.ownerDocument.defaultView?.getComputedStyle(element.value) ?? null;
1452
+ }
1453
+ function readAnimationName() {
1454
+ return readStyles()?.animationName || "none";
1455
+ }
1456
+ function send(event) {
1457
+ const next = (0, import_presence.sendPresenceEvent)(state.value, event);
1458
+ if (next === state.value) return;
1459
+ state.value = next;
1460
+ previousAnimationName = next === "mounted" ? readAnimationName() : "none";
1461
+ }
1462
+ function handleAnimationStart(event) {
1463
+ if (event.target !== element.value) return;
1464
+ previousAnimationName = readAnimationName();
1465
+ }
1466
+ function handleAnimationFinished(event) {
1467
+ const node = element.value;
1468
+ if (!node || event.target !== node) return;
1469
+ const currentAnimationName = readAnimationName();
1470
+ if (!currentAnimationName.includes(event.animationName)) return;
1471
+ send("ANIMATION_END");
1472
+ if ((0, import_vue20.toValue)(options.present)) return;
1473
+ const previousFillMode = node.style.animationFillMode;
1474
+ node.style.animationFillMode = "forwards";
1475
+ fillModeTimer = window.setTimeout(() => {
1476
+ if (node.style.animationFillMode === "forwards") {
1477
+ node.style.animationFillMode = previousFillMode;
1478
+ }
1479
+ });
1480
+ }
1481
+ function setElement(node) {
1482
+ element.value = node instanceof HTMLElement ? node : null;
1483
+ }
1484
+ (0, import_vue20.watch)(element, (node, previousNode) => {
1485
+ window.clearTimeout(fillModeTimer);
1486
+ previousNode?.removeEventListener("animationstart", handleAnimationStart);
1487
+ previousNode?.removeEventListener("animationcancel", handleAnimationFinished);
1488
+ previousNode?.removeEventListener("animationend", handleAnimationFinished);
1489
+ if (!node) {
1490
+ send("ANIMATION_END");
1491
+ return;
1492
+ }
1493
+ if (state.value === "mounted") previousAnimationName = readAnimationName();
1494
+ node.addEventListener("animationstart", handleAnimationStart);
1495
+ node.addEventListener("animationcancel", handleAnimationFinished);
1496
+ node.addEventListener("animationend", handleAnimationFinished);
1497
+ });
1498
+ (0, import_vue20.watch)(
1499
+ () => (0, import_vue20.toValue)(options.present),
1500
+ (present, wasPresent) => {
1501
+ if (present) {
1502
+ send("MOUNT");
1503
+ return;
1504
+ }
1505
+ const currentAnimationName = readAnimationName();
1506
+ const hasExitAnimation = currentAnimationName !== "none" && readStyles()?.display !== "none";
1507
+ const isAnimating = previousAnimationName !== currentAnimationName;
1508
+ if (!wasPresent || !hasExitAnimation || !isAnimating) {
1509
+ send("UNMOUNT");
1510
+ return;
1511
+ }
1512
+ send("ANIMATION_OUT");
1513
+ },
1514
+ { flush: "post", immediate: true }
1515
+ );
1516
+ (0, import_vue20.onScopeDispose)(() => {
1517
+ window.clearTimeout(fillModeTimer);
1518
+ const node = element.value;
1519
+ if (!node) return;
1520
+ node.removeEventListener("animationstart", handleAnimationStart);
1521
+ node.removeEventListener("animationcancel", handleAnimationFinished);
1522
+ node.removeEventListener("animationend", handleAnimationFinished);
1523
+ });
1524
+ return { isPresent, element, setElement };
1525
+ }
1526
+
1527
+ // src/useToastProvider/useToastProvider.ts
1528
+ var import_vue21 = require("vue");
1529
+ var import_toast = require("@agile-plus/primitives/toast");
1530
+ function useToastProvider(options = {}) {
1531
+ const label = (0, import_vue21.computed)(() => (0, import_vue21.toValue)(options.label) ?? import_toast.DEFAULT_TOAST_LABEL);
1532
+ const duration = (0, import_vue21.computed)(() => (0, import_vue21.toValue)(options.duration) ?? import_toast.DEFAULT_TOAST_DURATION);
1533
+ const swipeDirection = (0, import_vue21.computed)(
1534
+ () => (0, import_vue21.toValue)(options.swipeDirection) ?? import_toast.DEFAULT_TOAST_SWIPE_DIRECTION
1535
+ );
1536
+ const swipeThreshold = (0, import_vue21.computed)(
1537
+ () => (0, import_vue21.toValue)(options.swipeThreshold) ?? import_toast.DEFAULT_TOAST_SWIPE_THRESHOLD
1538
+ );
1539
+ const announceContainer = (0, import_vue21.computed)(() => (0, import_vue21.toValue)(options.announceContainer) ?? null);
1540
+ const collection = useCollection({ key: (entry) => entry.id });
1541
+ const toasts = collection.items;
1542
+ const toastCount = (0, import_vue21.computed)(() => collection.items.value.length);
1543
+ const hasToasts = (0, import_vue21.computed)(() => collection.items.value.length > 0);
1544
+ const viewport = (0, import_vue21.ref)(null);
1545
+ const isPaused = (0, import_vue21.ref)(false);
1546
+ const listeners = /* @__PURE__ */ new Set();
1547
+ if (!label.value.trim()) {
1548
+ console.error("Invalid prop `label` supplied to `ToastProvider`. Expected non-empty `string`.");
1549
+ }
1550
+ function setViewport(node) {
1551
+ viewport.value = node;
1552
+ }
1553
+ function setPaused(next) {
1554
+ if (isPaused.value === next) return;
1555
+ isPaused.value = next;
1556
+ listeners.forEach((listener) => listener(next));
1557
+ }
1558
+ function pauseClosing() {
1559
+ setPaused(true);
1560
+ }
1561
+ function resumeClosing() {
1562
+ setPaused(false);
1563
+ }
1564
+ function subscribeClosing(listener) {
1565
+ listeners.add(listener);
1566
+ return () => {
1567
+ listeners.delete(listener);
1568
+ };
1569
+ }
1570
+ return {
1571
+ label,
1572
+ duration,
1573
+ swipeDirection,
1574
+ swipeThreshold,
1575
+ announceContainer,
1576
+ toasts,
1577
+ toastCount,
1578
+ hasToasts,
1579
+ viewport,
1580
+ setViewport,
1581
+ registerToast: collection.add,
1582
+ isClosePaused: (0, import_vue21.computed)(() => isPaused.value),
1583
+ pauseClosing,
1584
+ resumeClosing,
1585
+ subscribeClosing
1586
+ };
1587
+ }
1588
+
1589
+ // src/useToastViewport/useToastViewport.ts
1590
+ var import_vue22 = require("vue");
1591
+ var import_toast2 = require("@agile-plus/primitives/toast");
1592
+ var import_dom2 = require("@agile-plus/primitives/dom");
1593
+ function asElement(node) {
1594
+ return node instanceof HTMLElement ? node : null;
1595
+ }
1596
+ function useToastViewport(options) {
1597
+ const { provider } = options;
1598
+ const wrapper = (0, import_vue22.ref)(null);
1599
+ const listElement = (0, import_vue22.ref)(null);
1600
+ const headProxy = (0, import_vue22.ref)(null);
1601
+ const tailProxy = (0, import_vue22.ref)(null);
1602
+ const hotkey = (0, import_vue22.computed)(() => (0, import_vue22.toValue)(options.hotkey) ?? import_toast2.DEFAULT_TOAST_VIEWPORT_HOTKEY);
1603
+ const hotkeyLabel = (0, import_vue22.computed)(() => (0, import_toast2.formatToastHotkey)(hotkey.value));
1604
+ const ariaLabel = (0, import_vue22.computed)(
1605
+ () => (0, import_toast2.resolveToastViewportLabel)((0, import_vue22.toValue)(options.label) ?? import_toast2.DEFAULT_TOAST_VIEWPORT_LABEL, hotkey.value)
1606
+ );
1607
+ function getSortedCandidates(direction) {
1608
+ const perToast = provider.toasts.value.map((entry) => {
1609
+ const node = entry.element.value;
1610
+ if (!node) return [];
1611
+ const candidates = [node, ...(0, import_dom2.getTabbableCandidates)(node)];
1612
+ return direction === "forwards" ? candidates : candidates.reverse();
1613
+ });
1614
+ const ordered = direction === "forwards" ? perToast.reverse() : perToast;
1615
+ return ordered.flat();
1616
+ }
1617
+ function focusProxy(position) {
1618
+ (position === "head" ? headProxy.value : tailProxy.value)?.focus();
1619
+ }
1620
+ function handleProxyFocus(event, position) {
1621
+ const previous = event.relatedTarget;
1622
+ if (previous instanceof Node && listElement.value?.contains(previous)) return;
1623
+ (0, import_dom2.focusFirst)(getSortedCandidates(position === "head" ? "forwards" : "backwards"));
1624
+ }
1625
+ function handleEscape(event) {
1626
+ if (!provider.hasToasts.value) return;
1627
+ const activeElement = document.activeElement;
1628
+ const isFocusInsideToast = provider.toasts.value.some(
1629
+ (entry) => entry.element.value?.contains(activeElement)
1630
+ );
1631
+ if (isFocusInsideToast) return;
1632
+ const modal = document.querySelector('[aria-modal="true"]');
1633
+ if (modal?.contains(activeElement)) return;
1634
+ const topmost = provider.toasts.value.at(-1);
1635
+ if (!topmost) return;
1636
+ event.preventDefault();
1637
+ topmost.close();
1638
+ }
1639
+ function handleDocumentKeydown(event) {
1640
+ if ((0, import_toast2.isToastHotkeyPressed)(event, hotkey.value)) {
1641
+ listElement.value?.focus();
1642
+ return;
1643
+ }
1644
+ if (event.key === "Escape") handleEscape(event);
1645
+ }
1646
+ function handleWindowBlur() {
1647
+ provider.pauseClosing();
1648
+ }
1649
+ function handleWindowFocus() {
1650
+ provider.resumeClosing();
1651
+ }
1652
+ let isWindowListening = false;
1653
+ (0, import_vue22.watch)(
1654
+ provider.hasToasts,
1655
+ (hasToasts) => {
1656
+ if (!isBrowser || hasToasts && isWindowListening) return;
1657
+ if (hasToasts) {
1658
+ window.addEventListener("blur", handleWindowBlur);
1659
+ window.addEventListener("focus", handleWindowFocus);
1660
+ isWindowListening = true;
1661
+ return;
1662
+ }
1663
+ window.removeEventListener("blur", handleWindowBlur);
1664
+ window.removeEventListener("focus", handleWindowFocus);
1665
+ isWindowListening = false;
1666
+ },
1667
+ { immediate: true }
1668
+ );
1669
+ (0, import_vue22.onMounted)(() => {
1670
+ if (!isBrowser) return;
1671
+ document.addEventListener("keydown", handleDocumentKeydown);
1672
+ });
1673
+ (0, import_vue22.onScopeDispose)(() => {
1674
+ if (!isBrowser) return;
1675
+ document.removeEventListener("keydown", handleDocumentKeydown);
1676
+ window.removeEventListener("blur", handleWindowBlur);
1677
+ window.removeEventListener("focus", handleWindowFocus);
1678
+ isWindowListening = false;
1679
+ });
1680
+ function bindWrapper(node) {
1681
+ wrapper.value = asElement(node);
1682
+ }
1683
+ function bindList(node) {
1684
+ listElement.value = asElement(node);
1685
+ provider.setViewport(listElement.value);
1686
+ }
1687
+ function bindHeadProxy(node) {
1688
+ headProxy.value = asElement(node);
1689
+ }
1690
+ function bindTailProxy(node) {
1691
+ tailProxy.value = asElement(node);
1692
+ }
1693
+ function getWrapperProps() {
1694
+ return {
1695
+ role: "region",
1696
+ "aria-label": ariaLabel.value,
1697
+ // 列表本身可聚焦:移除条目后焦点要有落脚点,读屏才能播报剩余数量。
1698
+ tabindex: -1,
1699
+ // 空列表也可能有 padding,不关掉 pointer-events 会挡住它覆盖的页面交互。
1700
+ style: { pointerEvents: provider.hasToasts.value ? "auto" : "none" }
1701
+ };
1702
+ }
1703
+ function getListProps() {
1704
+ return { tabindex: -1 };
1705
+ }
1706
+ function getProxyProps(position) {
1707
+ return {
1708
+ tabindex: 0,
1709
+ // position: fixed 防止 Tab 到代理时页面滚动。
1710
+ style: { ...import_toast2.VISUALLY_HIDDEN_STYLE, position: "fixed" },
1711
+ "data-toast-focus-proxy": position
1712
+ };
1713
+ }
1714
+ function onWrapperFocusin() {
1715
+ if (!provider.hasToasts.value) return;
1716
+ provider.pauseClosing();
1717
+ }
1718
+ function onWrapperFocusout(event) {
1719
+ const isMovingOutside = !(event.relatedTarget instanceof Node) || !wrapper.value?.contains(event.relatedTarget);
1720
+ if (isMovingOutside) provider.resumeClosing();
1721
+ }
1722
+ function onWrapperPointermove() {
1723
+ if (!provider.hasToasts.value) return;
1724
+ provider.pauseClosing();
1725
+ }
1726
+ function onWrapperPointerleave() {
1727
+ if (!wrapper.value) return;
1728
+ const isFocusInside = wrapper.value.contains(document.activeElement);
1729
+ if (!isFocusInside) provider.resumeClosing();
1730
+ }
1731
+ function onListKeydown(event) {
1732
+ const list = listElement.value;
1733
+ if (!list) return;
1734
+ const isMetaKey = event.altKey || event.ctrlKey || event.metaKey;
1735
+ if (event.key !== "Tab" || isMetaKey) return;
1736
+ const isTabbingBackwards = event.shiftKey;
1737
+ if (event.target === list && isTabbingBackwards) {
1738
+ focusProxy("head");
1739
+ return;
1740
+ }
1741
+ const direction = isTabbingBackwards ? "backwards" : "forwards";
1742
+ const sorted = getSortedCandidates(direction);
1743
+ const focusedElement = document.activeElement;
1744
+ const index = sorted.findIndex((candidate) => candidate === focusedElement);
1745
+ if ((0, import_dom2.focusFirst)(sorted.slice(index + 1))) {
1746
+ event.preventDefault();
1747
+ return;
1748
+ }
1749
+ focusProxy(isTabbingBackwards ? "head" : "tail");
1750
+ }
1751
+ function onHeadProxyFocus(event) {
1752
+ handleProxyFocus(event, "head");
1753
+ }
1754
+ function onTailProxyFocus(event) {
1755
+ handleProxyFocus(event, "tail");
1756
+ }
1757
+ return {
1758
+ hasToasts: provider.hasToasts,
1759
+ toastCount: provider.toastCount,
1760
+ ariaLabel,
1761
+ hotkeyLabel,
1762
+ listElement,
1763
+ bindWrapper,
1764
+ bindList,
1765
+ bindHeadProxy,
1766
+ bindTailProxy,
1767
+ getWrapperProps,
1768
+ getListProps,
1769
+ getHeadProxyProps: () => getProxyProps("head"),
1770
+ getTailProxyProps: () => getProxyProps("tail"),
1771
+ onWrapperFocusin,
1772
+ onWrapperFocusout,
1773
+ onWrapperPointermove,
1774
+ onWrapperPointerleave,
1775
+ onListKeydown,
1776
+ onHeadProxyFocus,
1777
+ onTailProxyFocus
1778
+ };
1779
+ }
1780
+
1781
+ // src/useToast/useToast.ts
1782
+ var import_vue23 = require("vue");
1783
+ var import_toast3 = require("@agile-plus/primitives/toast");
1784
+ var SWIPE_VARS = {
1785
+ moveX: "--y-toast-swipe-move-x",
1786
+ moveY: "--y-toast-swipe-move-y",
1787
+ endX: "--y-toast-swipe-end-x",
1788
+ endY: "--y-toast-swipe-end-y"
1789
+ };
1790
+ function useToast(options) {
1791
+ const { provider } = options;
1792
+ const id = (0, import_vue23.useId)();
1793
+ const state = useControllable({
1794
+ value: () => (0, import_vue23.toValue)(options.open),
1795
+ defaultValue: options.defaultOpen ?? true,
1796
+ onChange: (value) => options.onOpenChange?.(value)
1797
+ });
1798
+ const isOpen = state.value;
1799
+ const duration = (0, import_vue23.computed)(() => (0, import_vue23.toValue)(options.duration) ?? provider.duration.value);
1800
+ const presence = usePresence({
1801
+ present: () => Boolean((0, import_vue23.toValue)(options.forceMount)) || isOpen.value
1802
+ });
1803
+ const swipePhase = (0, import_vue23.ref)(null);
1804
+ const swipeMove = (0, import_vue23.ref)(null);
1805
+ const swipeEnd = (0, import_vue23.ref)(null);
1806
+ let pointerStart = null;
1807
+ let gestureDelta = null;
1808
+ let timerId = 0;
1809
+ let snapshot = (0, import_toast3.createToastTimerSnapshot)(duration.value, isBrowser ? Date.now() : 0);
1810
+ function setOpen(value) {
1811
+ state.set(value);
1812
+ }
1813
+ function close() {
1814
+ setOpen(false);
1815
+ }
1816
+ function handleClose() {
1817
+ const isFocusInside = presence.element.value?.contains(document.activeElement);
1818
+ if (isFocusInside) provider.viewport.value?.focus();
1819
+ close();
1820
+ }
1821
+ function startTimer(delay) {
1822
+ if ((0, import_toast3.isToastTimerDisabled)(delay)) return;
1823
+ window.clearTimeout(timerId);
1824
+ snapshot = (0, import_toast3.createToastTimerSnapshot)(delay, Date.now());
1825
+ timerId = window.setTimeout(handleClose, delay);
1826
+ }
1827
+ function pauseTimer() {
1828
+ snapshot = (0, import_toast3.pauseToastTimer)(snapshot, Date.now());
1829
+ window.clearTimeout(timerId);
1830
+ options.onPause?.();
1831
+ }
1832
+ function resumeTimer() {
1833
+ snapshot = (0, import_toast3.resumeToastTimer)(snapshot, Date.now());
1834
+ startTimer(snapshot.remaining);
1835
+ options.onResume?.();
1836
+ }
1837
+ const unsubscribeClosing = provider.subscribeClosing((paused) => {
1838
+ if (!isOpen.value) return;
1839
+ if (paused) pauseTimer();
1840
+ else resumeTimer();
1841
+ });
1842
+ (0, import_vue23.watch)(
1843
+ [isOpen, duration],
1844
+ ([open, nextDuration]) => {
1845
+ snapshot = (0, import_toast3.createToastTimerSnapshot)(nextDuration, Date.now());
1846
+ if (!isBrowser) return;
1847
+ if (open && !provider.isClosePaused.value) startTimer(nextDuration);
1848
+ else window.clearTimeout(timerId);
1849
+ },
1850
+ { immediate: true }
1851
+ );
1852
+ let unregister = null;
1853
+ (0, import_vue23.watch)(
1854
+ presence.isPresent,
1855
+ (present) => {
1856
+ if (present) unregister = provider.registerToast({ id, element: presence.element, close });
1857
+ else {
1858
+ unregister?.();
1859
+ unregister = null;
1860
+ }
1861
+ },
1862
+ { immediate: true }
1863
+ );
1864
+ const announcePhase = (0, import_vue23.ref)("pending");
1865
+ let nextFrameId = 0;
1866
+ let lifetimeId = 0;
1867
+ (0, import_vue23.onMounted)(() => {
1868
+ if (!isBrowser) return;
1869
+ nextFrameId = window.requestAnimationFrame(() => {
1870
+ nextFrameId = window.requestAnimationFrame(() => {
1871
+ announcePhase.value = "ready";
1872
+ lifetimeId = window.setTimeout(() => {
1873
+ announcePhase.value = "expired";
1874
+ }, import_toast3.TOAST_ANNOUNCE_LIFETIME);
1875
+ });
1876
+ });
1877
+ });
1878
+ const announceText = (0, import_vue23.computed)(() => {
1879
+ if (announcePhase.value !== "ready" || !presence.element.value) return null;
1880
+ return (0, import_toast3.getToastAnnounceTextContent)(presence.element.value);
1881
+ });
1882
+ const ariaLive = (0, import_vue23.computed)(
1883
+ () => ((0, import_vue23.toValue)(options.type) ?? "foreground") === "foreground" ? "assertive" : "polite"
1884
+ );
1885
+ function emitSwipe(phase, detail) {
1886
+ swipePhase.value = phase;
1887
+ if (phase === "start") {
1888
+ options.onSwipeStart?.(detail);
1889
+ return;
1890
+ }
1891
+ if (phase === "move") options.onSwipeMove?.(detail);
1892
+ if (phase === "cancel") options.onSwipeCancel?.(detail);
1893
+ if (phase === "end") options.onSwipeEnd?.(detail);
1894
+ }
1895
+ function onRootKeydown(event) {
1896
+ if (event.key !== "Escape") return;
1897
+ options.onEscapeKeyDown?.(event);
1898
+ if (!event.defaultPrevented) close();
1899
+ }
1900
+ function onRootPointerdown(event) {
1901
+ if (event.button !== 0) return;
1902
+ pointerStart = { x: event.clientX, y: event.clientY };
1903
+ }
1904
+ function onRootPointermove(event) {
1905
+ if (!pointerStart) return;
1906
+ const result = (0, import_toast3.resolveSwipeMove)({
1907
+ delta: { x: event.clientX - pointerStart.x, y: event.clientY - pointerStart.y },
1908
+ direction: provider.swipeDirection.value,
1909
+ pointerType: event.pointerType,
1910
+ started: gestureDelta !== null
1911
+ });
1912
+ if (result.phase === "idle") return;
1913
+ if (result.phase === "reset") {
1914
+ pointerStart = null;
1915
+ return;
1916
+ }
1917
+ const detail = { originalEvent: event, delta: result.clamped };
1918
+ gestureDelta = result.clamped;
1919
+ if (result.phase === "start") {
1920
+ emitSwipe("start", detail);
1921
+ if (event.target instanceof HTMLElement) event.target.setPointerCapture(event.pointerId);
1922
+ return;
1923
+ }
1924
+ swipeMove.value = result.clamped;
1925
+ emitSwipe("move", detail);
1926
+ }
1927
+ function onRootPointerup(event) {
1928
+ const delta = gestureDelta;
1929
+ const target = event.target instanceof HTMLElement ? event.target : null;
1930
+ if (target?.hasPointerCapture(event.pointerId)) target.releasePointerCapture(event.pointerId);
1931
+ gestureDelta = null;
1932
+ pointerStart = null;
1933
+ if (!delta) return;
1934
+ const detail = { originalEvent: event, delta };
1935
+ const phase = (0, import_toast3.getSwipeEndPhase)(
1936
+ delta,
1937
+ provider.swipeDirection.value,
1938
+ provider.swipeThreshold.value
1939
+ );
1940
+ if (phase === "end") {
1941
+ swipeMove.value = null;
1942
+ swipeEnd.value = delta;
1943
+ emitSwipe("end", detail);
1944
+ close();
1945
+ } else {
1946
+ swipeMove.value = null;
1947
+ swipeEnd.value = null;
1948
+ emitSwipe("cancel", detail);
1949
+ }
1950
+ if (event.currentTarget instanceof HTMLElement) {
1951
+ event.currentTarget.addEventListener("click", (clickEvent) => clickEvent.preventDefault(), {
1952
+ once: true
1953
+ });
1954
+ }
1955
+ }
1956
+ function getRootProps() {
1957
+ return {
1958
+ tabindex: 0,
1959
+ "data-state": isOpen.value ? "open" : "closed",
1960
+ "data-swipe-direction": provider.swipeDirection.value,
1961
+ ...swipePhase.value ? { "data-swipe": swipePhase.value } : {},
1962
+ style: {
1963
+ // 内联而不是写在样式里:滑动手势必须生效,而不依赖消费者有没有引入样式表。
1964
+ userSelect: "none",
1965
+ touchAction: "none",
1966
+ ...swipeMove.value ? { [SWIPE_VARS.moveX]: `${swipeMove.value.x}px` } : null,
1967
+ ...swipeMove.value ? { [SWIPE_VARS.moveY]: `${swipeMove.value.y}px` } : null,
1968
+ ...swipeEnd.value ? { [SWIPE_VARS.endX]: `${swipeEnd.value.x}px` } : null,
1969
+ ...swipeEnd.value ? { [SWIPE_VARS.endY]: `${swipeEnd.value.y}px` } : null
1970
+ }
1971
+ };
1972
+ }
1973
+ function getAnnounceProps() {
1974
+ return {
1975
+ // 永远用 status 而不是 alert:alert 在部分读屏里会造成逐字卡顿。
1976
+ role: "status",
1977
+ "aria-live": ariaLive.value,
1978
+ style: import_toast3.VISUALLY_HIDDEN_STYLE
1979
+ };
1980
+ }
1981
+ function bindElement(node) {
1982
+ presence.setElement(node);
1983
+ }
1984
+ (0, import_vue23.onScopeDispose)(() => {
1985
+ unsubscribeClosing();
1986
+ unregister?.();
1987
+ if (!isBrowser) return;
1988
+ window.clearTimeout(timerId);
1989
+ window.clearTimeout(lifetimeId);
1990
+ if (nextFrameId) window.cancelAnimationFrame(nextFrameId);
1991
+ });
1992
+ return {
1993
+ isOpen,
1994
+ isPresent: presence.isPresent,
1995
+ element: presence.element,
1996
+ bindElement,
1997
+ close,
1998
+ swipePhase: (0, import_vue23.computed)(() => swipePhase.value),
1999
+ swipeDirection: provider.swipeDirection,
2000
+ getRootProps,
2001
+ isAnnounceVisible: (0, import_vue23.computed)(() => announcePhase.value !== "expired"),
2002
+ announceText,
2003
+ announceLabel: provider.label,
2004
+ announceTarget: (0, import_vue23.computed)(() => provider.announceContainer.value ?? "body"),
2005
+ getAnnounceProps,
2006
+ onRootKeydown,
2007
+ onRootPointerdown,
2008
+ onRootPointermove,
2009
+ onRootPointerup
2010
+ };
2011
+ }
2012
+
2013
+ // src/useToggle/useToggle.ts
2014
+ var import_vue24 = require("vue");
2015
+ var import_toggle = require("@agile-plus/primitives/toggle");
2016
+ function useToggle(options = {}) {
2017
+ const state = useControllable({
2018
+ value: () => (0, import_vue24.toValue)(options.pressed),
2019
+ defaultValue: options.defaultPressed ?? false,
2020
+ onChange: (value) => options.onPressedChange?.(value)
2021
+ });
2022
+ const pressed = state.value;
2023
+ const disabled = (0, import_vue24.computed)(() => (0, import_vue24.toValue)(options.disabled) ?? false);
2024
+ function setPressed(value) {
2025
+ state.set(value);
2026
+ }
2027
+ function toggle() {
2028
+ setPressed(!pressed.value);
2029
+ }
2030
+ function onClick() {
2031
+ const next = (0, import_toggle.resolveNextTogglePressed)({ pressed: pressed.value, disabled: disabled.value });
2032
+ if (next !== null) setPressed(next);
2033
+ }
2034
+ function getRootProps() {
2035
+ return {
2036
+ type: "button",
2037
+ // aria-pressed 始终输出:开关的存在本身要靠它表达,缺席会被读成普通按钮。
2038
+ "aria-pressed": pressed.value,
2039
+ "data-state": (0, import_toggle.getToggleDataState)(pressed.value),
2040
+ ...disabled.value ? { disabled: true, "data-disabled": "" } : null
2041
+ };
2042
+ }
2043
+ return { pressed, disabled, setPressed, toggle, getRootProps, onClick };
2044
+ }
2045
+
2046
+ // src/useToggleGroup/useToggleGroup.ts
2047
+ var import_vue25 = require("vue");
2048
+ var import_toggle2 = require("@agile-plus/primitives/toggle");
2049
+ var import_dom3 = require("@agile-plus/primitives/dom");
2050
+ var VALID_TYPES = ["single", "multiple"];
2051
+ function useToggleGroup(options) {
2052
+ const type = (0, import_vue25.computed)(() => {
2053
+ const value2 = (0, import_vue25.toValue)(options.type);
2054
+ if (!VALID_TYPES.includes(value2)) {
2055
+ throw new Error(
2056
+ "Invalid prop `type` expected on `ToggleGroup`. Expected `single` or `multiple`."
2057
+ );
2058
+ }
2059
+ return value2;
2060
+ });
2061
+ const state = useControllable({
2062
+ value: () => {
2063
+ const raw = (0, import_vue25.toValue)(options.value);
2064
+ return raw === void 0 ? void 0 : (0, import_toggle2.normalizeToggleGroupValue)(type.value, raw);
2065
+ },
2066
+ defaultValue: (0, import_toggle2.normalizeToggleGroupValue)(type.value, (0, import_vue25.toValue)(options.defaultValue)),
2067
+ onChange: (next) => options.onValueChange?.((0, import_toggle2.serializeToggleGroupValue)(type.value, next))
2068
+ });
2069
+ const value = state.value;
2070
+ const disabled = (0, import_vue25.computed)(() => (0, import_vue25.toValue)(options.disabled) ?? false);
2071
+ const rovingFocus = (0, import_vue25.computed)(() => (0, import_vue25.toValue)(options.rovingFocus) ?? true);
2072
+ const loop = (0, import_vue25.computed)(() => (0, import_vue25.toValue)(options.loop) ?? true);
2073
+ const orientation = (0, import_vue25.computed)(() => (0, import_vue25.toValue)(options.orientation));
2074
+ const dir = (0, import_vue25.computed)(() => (0, import_vue25.toValue)(options.dir) ?? "ltr");
2075
+ const collection = useCollection({ key: (entry) => entry.id });
2076
+ const currentTabStopId = (0, import_vue25.ref)(null);
2077
+ const isTabbingBackOut = (0, import_vue25.ref)(false);
2078
+ let isClickFocus = false;
2079
+ const focusableEntries = (0, import_vue25.computed)(
2080
+ () => collection.items.value.filter((entry) => entry.focusable.value)
2081
+ );
2082
+ function findEntry(id) {
2083
+ return collection.items.value.find((entry) => entry.id === id);
2084
+ }
2085
+ function isItemPressed(itemValue) {
2086
+ return (0, import_toggle2.isToggleGroupItemPressed)(value.value, itemValue);
2087
+ }
2088
+ function emitValue(next) {
2089
+ state.set(next);
2090
+ }
2091
+ function setItemPressed(itemValue, pressed) {
2092
+ emitValue(
2093
+ (0, import_toggle2.resolveGroupValueAfterToggle)({ type: type.value, value: value.value, itemValue, pressed })
2094
+ );
2095
+ }
2096
+ function handleEntryFocus() {
2097
+ const candidates = focusableEntries.value;
2098
+ if (candidates.length === 0) return;
2099
+ const active = candidates.find((entry) => entry.active.value);
2100
+ const current = candidates.find((entry) => entry.id === currentTabStopId.value);
2101
+ const ordered = [active, current, ...candidates].filter((entry) => Boolean(entry)).map((entry) => entry.element.value).filter((element) => Boolean(element));
2102
+ (0, import_dom3.focusFirst)(ordered);
2103
+ }
2104
+ function getGroupProps() {
2105
+ return {
2106
+ role: type.value === "single" ? "radiogroup" : "toolbar",
2107
+ dir: dir.value,
2108
+ ...rovingFocus.value ? {
2109
+ // 整组只占一个 Tab 停靠点;没有可聚焦项时连这一格也不留。
2110
+ tabindex: isTabbingBackOut.value || focusableEntries.value.length === 0 ? -1 : 0,
2111
+ "data-orientation": orientation.value,
2112
+ style: { outline: "none" }
2113
+ } : null
2114
+ };
2115
+ }
2116
+ function getItemProps(id) {
2117
+ if (!rovingFocus.value) return {};
2118
+ return {
2119
+ tabindex: currentTabStopId.value === id ? 0 : -1,
2120
+ "data-orientation": orientation.value
2121
+ };
2122
+ }
2123
+ function onGroupFocus(event) {
2124
+ if (!rovingFocus.value) return;
2125
+ const isSelfFocus = event.target === event.currentTarget;
2126
+ const isKeyboardFocus = !isClickFocus;
2127
+ if (isSelfFocus && isKeyboardFocus && !isTabbingBackOut.value) handleEntryFocus();
2128
+ isClickFocus = false;
2129
+ }
2130
+ function onGroupMousedown() {
2131
+ isClickFocus = true;
2132
+ }
2133
+ function onGroupBlur() {
2134
+ isTabbingBackOut.value = false;
2135
+ }
2136
+ function onItemFocus(id) {
2137
+ if (!rovingFocus.value) return;
2138
+ currentTabStopId.value = id;
2139
+ }
2140
+ function onItemMousedown(event, id) {
2141
+ if (!rovingFocus.value) return;
2142
+ const entry = findEntry(id);
2143
+ if (!entry) return;
2144
+ if (!entry.focusable.value) {
2145
+ event.preventDefault();
2146
+ return;
2147
+ }
2148
+ currentTabStopId.value = id;
2149
+ }
2150
+ function onItemKeydown(event) {
2151
+ if (!rovingFocus.value) return;
2152
+ if (event.key === "Tab" && event.shiftKey) {
2153
+ isTabbingBackOut.value = true;
2154
+ return;
2155
+ }
2156
+ if (event.target !== event.currentTarget) return;
2157
+ const intent = (0, import_toggle2.resolveRovingFocusIntent)({
2158
+ key: event.key,
2159
+ orientation: orientation.value,
2160
+ dir: dir.value,
2161
+ hasModifierKey: event.shiftKey || event.ctrlKey || event.altKey || event.metaKey
2162
+ });
2163
+ if (!intent) return;
2164
+ event.preventDefault();
2165
+ const candidates = focusableEntries.value;
2166
+ const target = (0, import_toggle2.resolveRovingFocusTargetIndex)({
2167
+ intent,
2168
+ currentIndex: candidates.findIndex((entry) => entry.element.value === event.currentTarget),
2169
+ count: candidates.length,
2170
+ loop: loop.value
2171
+ });
2172
+ if (target === null) return;
2173
+ candidates[target]?.element.value?.focus();
2174
+ }
2175
+ return {
2176
+ type,
2177
+ value,
2178
+ disabled,
2179
+ rovingFocus,
2180
+ orientation,
2181
+ dir,
2182
+ isItemPressed,
2183
+ setItemPressed,
2184
+ registerItem: collection.add,
2185
+ getGroupProps,
2186
+ getItemProps,
2187
+ onGroupFocus,
2188
+ onGroupMousedown,
2189
+ onGroupBlur,
2190
+ onItemFocus,
2191
+ onItemMousedown,
2192
+ onItemKeydown
2193
+ };
2194
+ }
2195
+
2196
+ // src/useSwitch/useSwitch.ts
2197
+ var import_vue26 = require("vue");
2198
+ var import_switch = require("@agile-plus/primitives/switch");
2199
+ var import_form7 = require("@agile-plus/primitives/form");
2200
+ function useSwitch(options = {}) {
2201
+ const state = useControllable({
2202
+ value: () => (0, import_vue26.toValue)(options.checked),
2203
+ defaultValue: options.defaultChecked ?? false,
2204
+ onChange: (value) => options.onCheckedChange?.(value)
2205
+ });
2206
+ const checked = state.value;
2207
+ const isDisabled = (0, import_vue26.computed)(() => (0, import_vue26.toValue)(options.disabled) === true);
2208
+ const isRequired = (0, import_vue26.computed)(() => (0, import_vue26.toValue)(options.required) === true);
2209
+ const formId = (0, import_vue26.computed)(() => (0, import_vue26.toValue)(options.form));
2210
+ const submitValue = (0, import_vue26.computed)(() => (0, import_vue26.toValue)(options.value) ?? "on");
2211
+ const id = (0, import_vue26.computed)(() => (0, import_vue26.toValue)(options.id));
2212
+ const control = (0, import_vue26.ref)(null);
2213
+ const initialChecked = checked.value;
2214
+ const bubble = useBubbleInput({
2215
+ control,
2216
+ form: () => formId.value,
2217
+ checked: () => checked.value,
2218
+ onReset: () => setChecked(initialChecked)
2219
+ });
2220
+ function setChecked(value) {
2221
+ state.set(value);
2222
+ }
2223
+ function toggle() {
2224
+ if (isDisabled.value) return;
2225
+ setChecked(!checked.value);
2226
+ }
2227
+ function onRootClick() {
2228
+ toggle();
2229
+ }
2230
+ function setControl(node) {
2231
+ control.value = node instanceof HTMLElement ? node : null;
2232
+ }
2233
+ function getRootProps() {
2234
+ return {
2235
+ type: "button",
2236
+ id: id.value || void 0,
2237
+ ...(0, import_switch.getSwitchAttrs)({
2238
+ checked: checked.value,
2239
+ disabled: isDisabled.value,
2240
+ required: isRequired.value
2241
+ }),
2242
+ disabled: isDisabled.value || void 0,
2243
+ // Radix 也把提交值写到按钮上:<button name value> 本身就是表单数据。
2244
+ // 本库的按钮不带 name,因此不会与隐藏 input 重复提交。
2245
+ value: submitValue.value
2246
+ };
2247
+ }
2248
+ function getThumbProps() {
2249
+ return {
2250
+ "data-state": (0, import_switch.getSwitchDataState)(checked.value),
2251
+ "data-disabled": isDisabled.value ? "" : void 0
2252
+ };
2253
+ }
2254
+ function getInputProps() {
2255
+ if (!bubble.isFormControl.value) return null;
2256
+ return {
2257
+ ...(0, import_form7.getHiddenInputAttrs)({
2258
+ type: "checkbox",
2259
+ name: (0, import_vue26.toValue)(options.name),
2260
+ value: submitValue.value,
2261
+ disabled: isDisabled.value,
2262
+ required: isRequired.value,
2263
+ form: formId.value
2264
+ }),
2265
+ style: bubble.style.value
2266
+ };
2267
+ }
2268
+ return {
2269
+ checked,
2270
+ isDisabled,
2271
+ isFormControl: bubble.isFormControl,
2272
+ control,
2273
+ setControl,
2274
+ setInputElement: bubble.setInputElement,
2275
+ getRootProps,
2276
+ getThumbProps,
2277
+ getInputProps,
2278
+ setChecked,
2279
+ toggle,
2280
+ onRootClick
2281
+ };
2282
+ }
2283
+
2284
+ // src/useSlider/useSlider.ts
2285
+ var import_vue27 = require("vue");
2286
+ var import_slider = require("@agile-plus/primitives/slider");
2287
+ function formatThumbPosition(percent, offset) {
2288
+ if (offset === 0) return `${percent}%`;
2289
+ const operator = offset > 0 ? "+" : "-";
2290
+ return `calc(${percent}% ${operator} ${Math.abs(offset)}px)`;
2291
+ }
2292
+ function useSlider(options = {}) {
2293
+ const min = (0, import_vue27.computed)(() => (0, import_vue27.toValue)(options.min) ?? 0);
2294
+ const max = (0, import_vue27.computed)(() => (0, import_vue27.toValue)(options.max) ?? 100);
2295
+ const step = (0, import_vue27.computed)(() => (0, import_vue27.toValue)(options.step) ?? 1);
2296
+ const minStepsBetweenThumbs = (0, import_vue27.computed)(() => (0, import_vue27.toValue)(options.minStepsBetweenThumbs) ?? 0);
2297
+ const preserveThumbOrder = (0, import_vue27.computed)(() => (0, import_vue27.toValue)(options.preserveThumbOrder) ?? false);
2298
+ const orientation = (0, import_vue27.computed)(() => (0, import_vue27.toValue)(options.orientation) ?? "horizontal");
2299
+ const dir = (0, import_vue27.computed)(() => (0, import_vue27.toValue)(options.dir) ?? "ltr");
2300
+ const inverted = (0, import_vue27.computed)(() => (0, import_vue27.toValue)(options.inverted) ?? false);
2301
+ const disabled = (0, import_vue27.computed)(() => (0, import_vue27.toValue)(options.disabled) ?? false);
2302
+ function assertRange() {
2303
+ if (!Number.isFinite(min.value) || !Number.isFinite(max.value) || max.value <= min.value) {
2304
+ throw new Error("Slider \u7684 `max` \u5FC5\u987B\u662F\u5927\u4E8E `min` \u7684\u6709\u9650\u6570\u503C\u3002");
2305
+ }
2306
+ if (!Number.isFinite(step.value) || step.value <= 0) {
2307
+ throw new Error("Slider \u7684 `step` \u5FC5\u987B\u662F\u5927\u4E8E 0 \u7684\u6709\u9650\u6570\u503C\u3002");
2308
+ }
2309
+ if (!Number.isFinite(minStepsBetweenThumbs.value) || minStepsBetweenThumbs.value < 0) {
2310
+ throw new Error("Slider \u7684 `minStepsBetweenThumbs` \u4E0D\u80FD\u4E3A\u8D1F\u6570\u3002");
2311
+ }
2312
+ }
2313
+ assertRange();
2314
+ const state = useControllable({
2315
+ value: () => (0, import_vue27.toValue)(options.value),
2316
+ defaultValue: (0, import_slider.normalizeSliderValues)(options.defaultValue, min.value, max.value, step.value),
2317
+ // 回调拿到副本:内部数组之后可能被拖动改写,不能把引用交出去。
2318
+ onChange: (next) => options.onValueChange?.([...next])
2319
+ });
2320
+ const values = (0, import_vue27.computed)(() => {
2321
+ assertRange();
2322
+ return (0, import_slider.normalizeSliderValues)(state.value.value, min.value, max.value, step.value);
2323
+ });
2324
+ const activeIndex = (0, import_vue27.ref)(0);
2325
+ const rootElement = (0, import_vue27.ref)(null);
2326
+ const thumbElements = /* @__PURE__ */ new Map();
2327
+ const thumbSizes = (0, import_vue27.ref)({});
2328
+ const resize = useResizeObserver(() => {
2329
+ for (const index of thumbElements.keys()) {
2330
+ measureThumb(index);
2331
+ }
2332
+ });
2333
+ const drag = usePointerDrag();
2334
+ let valuesBeforeDrag = [];
2335
+ function emitValues(next) {
2336
+ state.set(next);
2337
+ }
2338
+ function applyValue(nextValue, index, commit) {
2339
+ if (disabled.value) return;
2340
+ const result = (0, import_slider.getSliderNextValues)({
2341
+ values: values.value,
2342
+ index,
2343
+ nextValue,
2344
+ min: min.value,
2345
+ max: max.value,
2346
+ step: step.value,
2347
+ minStepsBetweenThumbs: minStepsBetweenThumbs.value,
2348
+ preserveThumbOrder: preserveThumbOrder.value
2349
+ });
2350
+ if (!result.changed) return;
2351
+ const previousIndex = activeIndex.value;
2352
+ activeIndex.value = result.changedIndex;
2353
+ emitValues(result.values);
2354
+ if (result.changedIndex !== previousIndex) {
2355
+ thumbElements.get(result.changedIndex)?.focus({ preventScroll: true });
2356
+ }
2357
+ if (commit) {
2358
+ options.onValueCommit?.([...result.values]);
2359
+ }
2360
+ }
2361
+ function readRootRect() {
2362
+ return rootElement.value?.getBoundingClientRect() ?? null;
2363
+ }
2364
+ function getPointerValue(event, rect) {
2365
+ const isHorizontal = orientation.value === "horizontal";
2366
+ return (0, import_slider.getSliderValueFromPointer)({
2367
+ pointerPosition: isHorizontal ? event.clientX : event.clientY,
2368
+ trackStart: isHorizontal ? rect.left : rect.top,
2369
+ trackLength: isHorizontal ? rect.width : rect.height,
2370
+ min: min.value,
2371
+ max: max.value,
2372
+ step: step.value,
2373
+ orientation: orientation.value,
2374
+ dir: dir.value,
2375
+ inverted: inverted.value
2376
+ });
2377
+ }
2378
+ function beginDrag(event, index, rect) {
2379
+ if (!isBrowser) return;
2380
+ event.preventDefault();
2381
+ activeIndex.value = index;
2382
+ valuesBeforeDrag = [...values.value];
2383
+ thumbElements.get(index)?.focus({ preventScroll: true });
2384
+ drag.start({
2385
+ onMove: (moveEvent) => {
2386
+ applyValue(getPointerValue(moveEvent, rect), activeIndex.value, false);
2387
+ },
2388
+ // commit 只在正常抬起时上报:被新拖拽顶替、系统中断与组件卸载都算取消,
2389
+ // 与 Radix 的 onValueCommit 语义一致。
2390
+ onEnd: (reason) => {
2391
+ if (reason !== "up") return;
2392
+ const changed = valuesBeforeDrag.length !== values.value.length || valuesBeforeDrag.some((value, valueIndex) => value !== values.value[valueIndex]);
2393
+ if (changed) options.onValueCommit?.([...values.value]);
2394
+ }
2395
+ });
2396
+ }
2397
+ function onRootPointerDown(event) {
2398
+ if (disabled.value || event.button !== 0) return;
2399
+ const rect = readRootRect();
2400
+ if (!rect) return;
2401
+ const nextValue = getPointerValue(event, rect);
2402
+ const index = (0, import_slider.getSliderClosestValueIndex)(values.value, nextValue);
2403
+ beginDrag(event, index, rect);
2404
+ applyValue(nextValue, index, false);
2405
+ }
2406
+ function onThumbPointerDown(event, index) {
2407
+ event.stopPropagation();
2408
+ if (disabled.value || event.button !== 0) return;
2409
+ const rect = readRootRect();
2410
+ if (!rect) return;
2411
+ beginDrag(event, index, rect);
2412
+ }
2413
+ function onThumbFocus(index) {
2414
+ activeIndex.value = index;
2415
+ }
2416
+ function onThumbKeydown(event, index) {
2417
+ if (disabled.value) return;
2418
+ if (event.altKey || event.ctrlKey || event.metaKey) return;
2419
+ const intent = (0, import_slider.getSliderKeyboardIntent)({
2420
+ key: event.key,
2421
+ shiftKey: event.shiftKey,
2422
+ orientation: orientation.value,
2423
+ dir: dir.value,
2424
+ inverted: inverted.value
2425
+ });
2426
+ if (!intent) return;
2427
+ event.preventDefault();
2428
+ if (intent.type === "min") {
2429
+ applyValue(min.value, 0, true);
2430
+ return;
2431
+ }
2432
+ if (intent.type === "max") {
2433
+ applyValue(max.value, values.value.length - 1, true);
2434
+ return;
2435
+ }
2436
+ const currentValue = values.value[index] ?? min.value;
2437
+ const nextValue = (0, import_slider.getSliderNextStepValue)({
2438
+ value: currentValue,
2439
+ min: min.value,
2440
+ step: step.value,
2441
+ direction: intent.direction,
2442
+ multiplier: intent.multiplier
2443
+ });
2444
+ applyValue(nextValue, index, true);
2445
+ }
2446
+ function getHiddenInputs() {
2447
+ const name = (0, import_vue27.toValue)(options.name);
2448
+ if (!name) return [];
2449
+ const resolvedName = values.value.length > 1 ? `${name}[]` : name;
2450
+ const form = (0, import_vue27.toValue)(options.form);
2451
+ return values.value.map((value, index) => ({
2452
+ index,
2453
+ name: resolvedName,
2454
+ value: String(value),
2455
+ form
2456
+ }));
2457
+ }
2458
+ function getRootProps() {
2459
+ return {
2460
+ dir: dir.value,
2461
+ "data-part": "root",
2462
+ "data-orientation": orientation.value,
2463
+ "data-disabled": disabled.value ? "" : void 0,
2464
+ "aria-disabled": disabled.value || void 0
2465
+ };
2466
+ }
2467
+ function getTrackProps() {
2468
+ return {
2469
+ "data-part": "track",
2470
+ "data-orientation": orientation.value,
2471
+ "data-disabled": disabled.value ? "" : void 0
2472
+ };
2473
+ }
2474
+ function getRangeProps() {
2475
+ return {
2476
+ "data-part": "range",
2477
+ "data-orientation": orientation.value,
2478
+ "data-disabled": disabled.value ? "" : void 0
2479
+ };
2480
+ }
2481
+ function getRangeStyle() {
2482
+ const style = (0, import_slider.getSliderRangeStyle)(values.value, {
2483
+ min: min.value,
2484
+ max: max.value,
2485
+ step: step.value,
2486
+ orientation: orientation.value,
2487
+ dir: dir.value,
2488
+ inverted: inverted.value
2489
+ });
2490
+ return {
2491
+ left: style.left,
2492
+ right: style.right,
2493
+ top: style.top,
2494
+ bottom: style.bottom
2495
+ };
2496
+ }
2497
+ function getThumbProps(index) {
2498
+ const value = values.value[index] ?? min.value;
2499
+ return {
2500
+ role: "slider",
2501
+ "aria-valuemin": min.value,
2502
+ "aria-valuemax": max.value,
2503
+ "aria-valuenow": value,
2504
+ "aria-orientation": orientation.value,
2505
+ "aria-label": (0, import_slider.getSliderThumbLabel)(index, values.value.length),
2506
+ "aria-disabled": disabled.value || void 0,
2507
+ "data-part": "thumb",
2508
+ "data-orientation": orientation.value,
2509
+ "data-disabled": disabled.value ? "" : void 0,
2510
+ "data-index": index,
2511
+ tabindex: disabled.value ? void 0 : 0
2512
+ };
2513
+ }
2514
+ function getThumbStyle(index) {
2515
+ const value = values.value[index] ?? min.value;
2516
+ const percent = (0, import_slider.getSliderVisualPercent)(value, {
2517
+ min: min.value,
2518
+ max: max.value,
2519
+ step: step.value,
2520
+ orientation: orientation.value,
2521
+ dir: dir.value,
2522
+ inverted: inverted.value
2523
+ });
2524
+ const size = thumbSizes.value[index];
2525
+ const dimension = orientation.value === "horizontal" ? size?.width ?? 0 : size?.height ?? 0;
2526
+ const offset = dimension > 0 ? Math.round((0, import_slider.getSliderThumbInBoundsOffset)(dimension, percent) * 100) / 100 : 0;
2527
+ return orientation.value === "horizontal" ? {
2528
+ position: "absolute",
2529
+ left: formatThumbPosition(percent, offset),
2530
+ transform: "translateX(-50%)"
2531
+ } : {
2532
+ position: "absolute",
2533
+ top: formatThumbPosition(percent, offset),
2534
+ transform: "translateY(-50%)"
2535
+ };
2536
+ }
2537
+ function setRootElement(node) {
2538
+ rootElement.value = isBrowser && node instanceof HTMLElement ? node : null;
2539
+ }
2540
+ function measureThumb(index) {
2541
+ const element = thumbElements.get(index);
2542
+ if (!element) return;
2543
+ const next = { width: element.offsetWidth, height: element.offsetHeight };
2544
+ const current = thumbSizes.value[index];
2545
+ if (current?.width === next.width && current.height === next.height) return;
2546
+ thumbSizes.value = { ...thumbSizes.value, [index]: next };
2547
+ }
2548
+ function setThumbElement(index, node) {
2549
+ const element = isBrowser && node instanceof HTMLElement ? node : null;
2550
+ const previous = thumbElements.get(index);
2551
+ if (previous === element) return;
2552
+ if (previous) {
2553
+ resize.unobserve(previous);
2554
+ thumbElements.delete(index);
2555
+ }
2556
+ if (element) {
2557
+ thumbElements.set(index, element);
2558
+ resize.observe(element);
2559
+ measureThumb(index);
2560
+ return;
2561
+ }
2562
+ if (!(index in thumbSizes.value)) return;
2563
+ const nextSizes = { ...thumbSizes.value };
2564
+ delete nextSizes[index];
2565
+ thumbSizes.value = nextSizes;
2566
+ }
2567
+ (0, import_vue27.onScopeDispose)(() => {
2568
+ thumbElements.clear();
2569
+ });
2570
+ return {
2571
+ values,
2572
+ isDisabled: disabled,
2573
+ getRootProps,
2574
+ getTrackProps,
2575
+ getRangeProps,
2576
+ getRangeStyle,
2577
+ getThumbProps,
2578
+ getThumbStyle,
2579
+ getHiddenInputs,
2580
+ setRootElement,
2581
+ setThumbElement,
2582
+ onRootPointerDown,
2583
+ onThumbPointerDown,
2584
+ onThumbKeydown,
2585
+ onThumbFocus
2586
+ };
2587
+ }
2588
+ // Annotate the CommonJS export names for ESM import in node:
2589
+ 0 && (module.exports = {
2590
+ useCheckbox,
2591
+ useCheckboxGroup,
2592
+ useCollapsible,
2593
+ useDialog,
2594
+ useForm,
2595
+ useFormControl,
2596
+ useFormField,
2597
+ useFormMessage,
2598
+ usePresence,
2599
+ useRadioGroup,
2600
+ useScrollArea,
2601
+ useSlider,
2602
+ useSwitch,
2603
+ useTabs,
2604
+ useToast,
2605
+ useToastProvider,
2606
+ useToastViewport,
2607
+ useToggle,
2608
+ useToggleGroup
2609
+ });
2610
+ //# sourceMappingURL=index.cjs.map