@octanejs/floating-ui 0.1.31 → 0.1.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,709 @@
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
+ var utils_exports = {};
20
+ __export(utils_exports, {
21
+ FOCUSABLE_ATTRIBUTE: () => FOCUSABLE_ATTRIBUTE,
22
+ activeElement: () => activeElement,
23
+ camelCaseToKebabCase: () => camelCaseToKebabCase,
24
+ clearTimeoutIfSet: () => clearTimeoutIfSet,
25
+ contains: () => contains,
26
+ createAttribute: () => createAttribute,
27
+ createGridCellMap: () => createGridCellMap,
28
+ deepEqual: () => deepEqual,
29
+ disableFocusInside: () => disableFocusInside,
30
+ enableFocusInside: () => enableFocusInside,
31
+ enqueueFocus: () => enqueueFocus,
32
+ execWithArgsOrReturn: () => execWithArgsOrReturn,
33
+ findNonDisabledListIndex: () => findNonDisabledListIndex,
34
+ getDPR: () => getDPR,
35
+ getDeepestNode: () => getDeepestNode,
36
+ getDelay: () => getDelay,
37
+ getDocument: () => getDocument,
38
+ getFloatingFocusElement: () => getFloatingFocusElement,
39
+ getGridCellIndexOfCorner: () => getGridCellIndexOfCorner,
40
+ getGridCellIndices: () => getGridCellIndices,
41
+ getGridNavigatedIndex: () => getGridNavigatedIndex,
42
+ getMaxListIndex: () => getMaxListIndex,
43
+ getMinListIndex: () => getMinListIndex,
44
+ getNextTabbable: () => getNextTabbable,
45
+ getNodeAncestors: () => getNodeAncestors,
46
+ getNodeChildren: () => getNodeChildren,
47
+ getPlatform: () => getPlatform,
48
+ getPreviousTabbable: () => getPreviousTabbable,
49
+ getTabbableOptions: () => getTabbableOptions,
50
+ getTarget: () => getTarget,
51
+ getUserAgent: () => getUserAgent,
52
+ isAndroid: () => isAndroid,
53
+ isClient: () => isClient,
54
+ isDifferentGridRow: () => isDifferentGridRow,
55
+ isEventTargetWithin: () => isEventTargetWithin,
56
+ isIndexOutOfListBounds: () => isIndexOutOfListBounds,
57
+ isJSDOM: () => isJSDOM,
58
+ isListIndexDisabled: () => isListIndexDisabled,
59
+ isMac: () => isMac,
60
+ isMacSafari: () => isMacSafari,
61
+ isMouseLikePointerType: () => isMouseLikePointerType,
62
+ isOutsideEvent: () => isOutsideEvent,
63
+ isReactEvent: () => isReactEvent,
64
+ isRootElement: () => isRootElement,
65
+ isSafari: () => isSafari,
66
+ isTypeableCombobox: () => isTypeableCombobox,
67
+ isTypeableElement: () => isTypeableElement,
68
+ isVirtualClick: () => isVirtualClick,
69
+ isVirtualPointerEvent: () => isVirtualPointerEvent,
70
+ matchesFocusVisible: () => matchesFocusVisible,
71
+ roundByDPR: () => roundByDPR,
72
+ stopEvent: () => stopEvent,
73
+ useEffectEvent: () => useEffectEvent,
74
+ useLatestRef: () => useLatestRef,
75
+ useModernLayoutEffect: () => useModernLayoutEffect
76
+ });
77
+ module.exports = __toCommonJS(utils_exports);
78
+ var import_dom = require("@floating-ui/utils/dom");
79
+ var import_utils = require("@floating-ui/utils");
80
+ var import_tabbable = require("tabbable");
81
+ var import_octane = require("octane");
82
+ var import_internal = require("../internal.cjs");
83
+ function getPlatform() {
84
+ const uaData = navigator.userAgentData;
85
+ if (uaData != null && uaData.platform) {
86
+ return uaData.platform;
87
+ }
88
+ return navigator.platform;
89
+ }
90
+ function getUserAgent() {
91
+ const uaData = navigator.userAgentData;
92
+ if (uaData && Array.isArray(uaData.brands)) {
93
+ return uaData.brands.map((b) => b.brand + "/" + b.version).join(" ");
94
+ }
95
+ return navigator.userAgent;
96
+ }
97
+ function isSafari() {
98
+ return /apple/i.test(navigator.vendor);
99
+ }
100
+ function isAndroid() {
101
+ const re = /android/i;
102
+ return re.test(getPlatform()) || re.test(getUserAgent());
103
+ }
104
+ function isMac() {
105
+ return getPlatform().toLowerCase().startsWith("mac") && !navigator.maxTouchPoints;
106
+ }
107
+ function isJSDOM() {
108
+ return getUserAgent().includes("jsdom/");
109
+ }
110
+ function isMacSafari() {
111
+ return isMac() && isSafari();
112
+ }
113
+ function createAttribute(name) {
114
+ return "data-floating-ui-" + name;
115
+ }
116
+ function clearTimeoutIfSet(timeoutRef) {
117
+ if (timeoutRef.current !== -1) {
118
+ clearTimeout(timeoutRef.current);
119
+ timeoutRef.current = -1;
120
+ }
121
+ }
122
+ const FOCUSABLE_ATTRIBUTE = "data-floating-ui-focusable";
123
+ const TYPEABLE_SELECTOR = "input:not([type='hidden']):not([disabled]),[contenteditable]:not([contenteditable='false']),textarea:not([disabled])";
124
+ const ARROW_LEFT = "ArrowLeft";
125
+ const ARROW_RIGHT = "ArrowRight";
126
+ const ARROW_UP = "ArrowUp";
127
+ const ARROW_DOWN = "ArrowDown";
128
+ function activeElement(doc) {
129
+ let active = doc.activeElement;
130
+ while (active?.shadowRoot?.activeElement != null) {
131
+ active = active.shadowRoot.activeElement;
132
+ }
133
+ return active;
134
+ }
135
+ function contains(parent, child) {
136
+ if (!parent || !child) {
137
+ return false;
138
+ }
139
+ const rootNode = child.getRootNode?.();
140
+ if (parent.contains(child)) {
141
+ return true;
142
+ }
143
+ if (rootNode && (0, import_dom.isShadowRoot)(rootNode)) {
144
+ let next = child;
145
+ while (next) {
146
+ if (parent === next) {
147
+ return true;
148
+ }
149
+ next = next.parentNode || next.host;
150
+ }
151
+ }
152
+ return false;
153
+ }
154
+ function getTarget(event) {
155
+ if ("composedPath" in event) {
156
+ return event.composedPath()[0];
157
+ }
158
+ return event.target;
159
+ }
160
+ function isEventTargetWithin(event, node) {
161
+ if (node == null) {
162
+ return false;
163
+ }
164
+ if ("composedPath" in event) {
165
+ return event.composedPath().includes(node);
166
+ }
167
+ const e = event;
168
+ return e.target != null && node.contains(e.target);
169
+ }
170
+ function isRootElement(element) {
171
+ return element.matches("html,body");
172
+ }
173
+ function getDocument(node) {
174
+ return node?.ownerDocument || document;
175
+ }
176
+ function isTypeableElement(element) {
177
+ return (0, import_dom.isHTMLElement)(element) && element.matches(TYPEABLE_SELECTOR);
178
+ }
179
+ function isTypeableCombobox(element) {
180
+ if (!element) return false;
181
+ return element.getAttribute("role") === "combobox" && isTypeableElement(element);
182
+ }
183
+ function matchesFocusVisible(element) {
184
+ if (!element || isJSDOM()) return true;
185
+ try {
186
+ return element.matches(":focus-visible");
187
+ } catch (_e) {
188
+ return true;
189
+ }
190
+ }
191
+ function getFloatingFocusElement(floatingElement) {
192
+ if (!floatingElement) {
193
+ return null;
194
+ }
195
+ return floatingElement.hasAttribute(FOCUSABLE_ATTRIBUTE) ? floatingElement : floatingElement.querySelector("[" + FOCUSABLE_ATTRIBUTE + "]") || floatingElement;
196
+ }
197
+ function getNodeChildren(nodes, id, onlyOpenChildren = true) {
198
+ const directChildren = nodes.filter(
199
+ (node) => node.parentId === id && (!onlyOpenChildren || node.context?.open)
200
+ );
201
+ return directChildren.flatMap((child) => [
202
+ child,
203
+ ...getNodeChildren(nodes, child.id, onlyOpenChildren)
204
+ ]);
205
+ }
206
+ function getDeepestNode(nodes, id) {
207
+ let deepestNodeId;
208
+ let maxDepth = -1;
209
+ function findDeepest(nodeId, depth) {
210
+ if (depth > maxDepth) {
211
+ deepestNodeId = nodeId;
212
+ maxDepth = depth;
213
+ }
214
+ const children = getNodeChildren(nodes, nodeId);
215
+ children.forEach((child) => {
216
+ findDeepest(child.id, depth + 1);
217
+ });
218
+ }
219
+ findDeepest(id, 0);
220
+ return nodes.find((node) => node.id === deepestNodeId);
221
+ }
222
+ function getNodeAncestors(nodes, id) {
223
+ let allAncestors = [];
224
+ let currentParentId = nodes.find((node) => node.id === id)?.parentId;
225
+ while (currentParentId) {
226
+ const currentNode = nodes.find((node) => node.id === currentParentId);
227
+ currentParentId = currentNode?.parentId;
228
+ if (currentNode) {
229
+ allAncestors = allAncestors.concat(currentNode);
230
+ }
231
+ }
232
+ return allAncestors;
233
+ }
234
+ function stopEvent(event) {
235
+ event.preventDefault();
236
+ event.stopPropagation();
237
+ }
238
+ function isReactEvent(event) {
239
+ return "nativeEvent" in event;
240
+ }
241
+ function isVirtualClick(event) {
242
+ if (event.mozInputSource === 0 && event.isTrusted) {
243
+ return true;
244
+ }
245
+ if (isAndroid() && event.pointerType) {
246
+ return event.type === "click" && event.buttons === 1;
247
+ }
248
+ return event.detail === 0 && !event.pointerType;
249
+ }
250
+ function isVirtualPointerEvent(event) {
251
+ if (isJSDOM()) return false;
252
+ return !isAndroid() && event.width === 0 && event.height === 0 || isAndroid() && event.width === 1 && event.height === 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === "mouse" || event.width < 1 && event.height < 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === "touch";
253
+ }
254
+ function isMouseLikePointerType(pointerType, strict) {
255
+ const values = ["mouse", "pen"];
256
+ if (!strict) {
257
+ values.push("", void 0);
258
+ }
259
+ return values.includes(pointerType);
260
+ }
261
+ function getDelay(value, prop, pointerType) {
262
+ if (pointerType && !isMouseLikePointerType(pointerType)) {
263
+ return 0;
264
+ }
265
+ if (typeof value === "number") {
266
+ return value;
267
+ }
268
+ if (typeof value === "function") {
269
+ const result = value();
270
+ if (typeof result === "number") {
271
+ return result;
272
+ }
273
+ return result?.[prop];
274
+ }
275
+ return value?.[prop];
276
+ }
277
+ function camelCaseToKebabCase(str) {
278
+ return str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? "-" : "") + $.toLowerCase());
279
+ }
280
+ function execWithArgsOrReturn(valueOrFn, args) {
281
+ return typeof valueOrFn === "function" ? valueOrFn(args) : valueOrFn;
282
+ }
283
+ function deepEqual(a, b) {
284
+ if (a === b) {
285
+ return true;
286
+ }
287
+ if (typeof a !== typeof b) {
288
+ return false;
289
+ }
290
+ if (typeof a === "function" && a.toString() === b.toString()) {
291
+ return true;
292
+ }
293
+ let length;
294
+ let i;
295
+ let keys;
296
+ if (a && b && typeof a === "object") {
297
+ if (Array.isArray(a)) {
298
+ length = a.length;
299
+ if (length !== b.length) return false;
300
+ for (i = length; i-- !== 0; ) {
301
+ if (!deepEqual(a[i], b[i])) {
302
+ return false;
303
+ }
304
+ }
305
+ return true;
306
+ }
307
+ keys = Object.keys(a);
308
+ length = keys.length;
309
+ if (length !== Object.keys(b).length) {
310
+ return false;
311
+ }
312
+ for (i = length; i-- !== 0; ) {
313
+ if (!{}.hasOwnProperty.call(b, keys[i])) {
314
+ return false;
315
+ }
316
+ }
317
+ for (i = length; i-- !== 0; ) {
318
+ const key = keys[i];
319
+ if (key === "_owner" && a.$$typeof) {
320
+ continue;
321
+ }
322
+ if (!deepEqual(a[key], b[key])) {
323
+ return false;
324
+ }
325
+ }
326
+ return true;
327
+ }
328
+ return a !== a && b !== b;
329
+ }
330
+ function getDPR(element) {
331
+ if (typeof window === "undefined") {
332
+ return 1;
333
+ }
334
+ const win = element.ownerDocument.defaultView || window;
335
+ return win.devicePixelRatio || 1;
336
+ }
337
+ function roundByDPR(element, value) {
338
+ const dpr = getDPR(element);
339
+ return Math.round(value * dpr) / dpr;
340
+ }
341
+ const isClient = typeof document !== "undefined";
342
+ function useModernLayoutEffect(fn, deps, slot) {
343
+ if (isClient) {
344
+ (0, import_octane.useLayoutEffect)(fn, deps, slot);
345
+ }
346
+ }
347
+ function useLatestRef(value, slot) {
348
+ const ref = (0, import_octane.useRef)(value, (0, import_internal.subSlot)(slot, "lr:ref"));
349
+ useModernLayoutEffect(
350
+ () => {
351
+ ref.current = value;
352
+ },
353
+ void 0,
354
+ (0, import_internal.subSlot)(slot, "lr:eff")
355
+ );
356
+ return ref;
357
+ }
358
+ const useSafeInsertionEffect = (fn) => fn();
359
+ function useEffectEvent(callback, slot) {
360
+ const ref = (0, import_octane.useRef)(
361
+ () => {
362
+ throw new Error("Cannot call an event handler while rendering.");
363
+ },
364
+ (0, import_internal.subSlot)(slot, "ee:ref")
365
+ );
366
+ useSafeInsertionEffect(() => {
367
+ ref.current = callback;
368
+ });
369
+ return (0, import_octane.useCallback)(
370
+ (...args) => ref.current == null ? void 0 : ref.current(...args),
371
+ [],
372
+ (0, import_internal.subSlot)(slot, "ee:cb")
373
+ );
374
+ }
375
+ function isDifferentGridRow(index, cols, prevRow) {
376
+ return Math.floor(index / cols) !== prevRow;
377
+ }
378
+ function isIndexOutOfListBounds(listRef, index) {
379
+ return index < 0 || index >= listRef.current.length;
380
+ }
381
+ function getMinListIndex(listRef, disabledIndices) {
382
+ return findNonDisabledListIndex(listRef, { disabledIndices });
383
+ }
384
+ function getMaxListIndex(listRef, disabledIndices) {
385
+ return findNonDisabledListIndex(listRef, {
386
+ decrement: true,
387
+ startingIndex: listRef.current.length,
388
+ disabledIndices
389
+ });
390
+ }
391
+ function findNonDisabledListIndex(listRef, _temp) {
392
+ const {
393
+ startingIndex = -1,
394
+ decrement = false,
395
+ disabledIndices,
396
+ amount = 1
397
+ } = _temp === void 0 ? {} : _temp;
398
+ let index = startingIndex;
399
+ do {
400
+ index += decrement ? -amount : amount;
401
+ } while (index >= 0 && index <= listRef.current.length - 1 && isListIndexDisabled(listRef, index, disabledIndices));
402
+ return index;
403
+ }
404
+ function getGridNavigatedIndex(listRef, _ref) {
405
+ const {
406
+ event,
407
+ orientation,
408
+ loop,
409
+ rtl,
410
+ cols,
411
+ disabledIndices,
412
+ minIndex,
413
+ maxIndex,
414
+ prevIndex,
415
+ stopEvent: stop = false
416
+ } = _ref;
417
+ let nextIndex = prevIndex;
418
+ if (event.key === ARROW_UP) {
419
+ stop && stopEvent(event);
420
+ if (prevIndex === -1) {
421
+ nextIndex = maxIndex;
422
+ } else {
423
+ nextIndex = findNonDisabledListIndex(listRef, {
424
+ startingIndex: nextIndex,
425
+ amount: cols,
426
+ decrement: true,
427
+ disabledIndices
428
+ });
429
+ if (loop && (prevIndex - cols < minIndex || nextIndex < 0)) {
430
+ const col = prevIndex % cols;
431
+ const maxCol = maxIndex % cols;
432
+ const offset = maxIndex - (maxCol - col);
433
+ if (maxCol === col) {
434
+ nextIndex = maxIndex;
435
+ } else {
436
+ nextIndex = maxCol > col ? offset : offset - cols;
437
+ }
438
+ }
439
+ }
440
+ if (isIndexOutOfListBounds(listRef, nextIndex)) {
441
+ nextIndex = prevIndex;
442
+ }
443
+ }
444
+ if (event.key === ARROW_DOWN) {
445
+ stop && stopEvent(event);
446
+ if (prevIndex === -1) {
447
+ nextIndex = minIndex;
448
+ } else {
449
+ nextIndex = findNonDisabledListIndex(listRef, {
450
+ startingIndex: prevIndex,
451
+ amount: cols,
452
+ disabledIndices
453
+ });
454
+ if (loop && prevIndex + cols > maxIndex) {
455
+ nextIndex = findNonDisabledListIndex(listRef, {
456
+ startingIndex: prevIndex % cols - cols,
457
+ amount: cols,
458
+ disabledIndices
459
+ });
460
+ }
461
+ }
462
+ if (isIndexOutOfListBounds(listRef, nextIndex)) {
463
+ nextIndex = prevIndex;
464
+ }
465
+ }
466
+ if (orientation === "both") {
467
+ const prevRow = (0, import_utils.floor)(prevIndex / cols);
468
+ if (event.key === (rtl ? ARROW_LEFT : ARROW_RIGHT)) {
469
+ stop && stopEvent(event);
470
+ if (prevIndex % cols !== cols - 1) {
471
+ nextIndex = findNonDisabledListIndex(listRef, {
472
+ startingIndex: prevIndex,
473
+ disabledIndices
474
+ });
475
+ if (loop && isDifferentGridRow(nextIndex, cols, prevRow)) {
476
+ nextIndex = findNonDisabledListIndex(listRef, {
477
+ startingIndex: prevIndex - prevIndex % cols - 1,
478
+ disabledIndices
479
+ });
480
+ }
481
+ } else if (loop) {
482
+ nextIndex = findNonDisabledListIndex(listRef, {
483
+ startingIndex: prevIndex - prevIndex % cols - 1,
484
+ disabledIndices
485
+ });
486
+ }
487
+ if (isDifferentGridRow(nextIndex, cols, prevRow)) {
488
+ nextIndex = prevIndex;
489
+ }
490
+ }
491
+ if (event.key === (rtl ? ARROW_RIGHT : ARROW_LEFT)) {
492
+ stop && stopEvent(event);
493
+ if (prevIndex % cols !== 0) {
494
+ nextIndex = findNonDisabledListIndex(listRef, {
495
+ startingIndex: prevIndex,
496
+ decrement: true,
497
+ disabledIndices
498
+ });
499
+ if (loop && isDifferentGridRow(nextIndex, cols, prevRow)) {
500
+ nextIndex = findNonDisabledListIndex(listRef, {
501
+ startingIndex: prevIndex + (cols - prevIndex % cols),
502
+ decrement: true,
503
+ disabledIndices
504
+ });
505
+ }
506
+ } else if (loop) {
507
+ nextIndex = findNonDisabledListIndex(listRef, {
508
+ startingIndex: prevIndex + (cols - prevIndex % cols),
509
+ decrement: true,
510
+ disabledIndices
511
+ });
512
+ }
513
+ if (isDifferentGridRow(nextIndex, cols, prevRow)) {
514
+ nextIndex = prevIndex;
515
+ }
516
+ }
517
+ const lastRow = (0, import_utils.floor)(maxIndex / cols) === prevRow;
518
+ if (isIndexOutOfListBounds(listRef, nextIndex)) {
519
+ if (loop && lastRow) {
520
+ nextIndex = event.key === (rtl ? ARROW_RIGHT : ARROW_LEFT) ? maxIndex : findNonDisabledListIndex(listRef, {
521
+ startingIndex: prevIndex - prevIndex % cols - 1,
522
+ disabledIndices
523
+ });
524
+ } else {
525
+ nextIndex = prevIndex;
526
+ }
527
+ }
528
+ }
529
+ return nextIndex;
530
+ }
531
+ function createGridCellMap(sizes, cols, dense) {
532
+ const cellMap = [];
533
+ let startIndex = 0;
534
+ sizes.forEach((_ref2, index) => {
535
+ const { width, height } = _ref2;
536
+ if (width > cols) {
537
+ throw new Error(
538
+ "[Floating UI]: Invalid grid - item width at index " + index + " is greater than grid columns"
539
+ );
540
+ }
541
+ let itemPlaced = false;
542
+ if (dense) {
543
+ startIndex = 0;
544
+ }
545
+ while (!itemPlaced) {
546
+ const targetCells = [];
547
+ for (let i = 0; i < width; i++) {
548
+ for (let j = 0; j < height; j++) {
549
+ targetCells.push(startIndex + i + j * cols);
550
+ }
551
+ }
552
+ if (startIndex % cols + width <= cols && targetCells.every((cell) => cellMap[cell] == null)) {
553
+ targetCells.forEach((cell) => {
554
+ cellMap[cell] = index;
555
+ });
556
+ itemPlaced = true;
557
+ } else {
558
+ startIndex++;
559
+ }
560
+ }
561
+ });
562
+ return [...cellMap];
563
+ }
564
+ function getGridCellIndexOfCorner(index, sizes, cellMap, cols, corner) {
565
+ if (index === -1) return -1;
566
+ const firstCellIndex = cellMap.indexOf(index);
567
+ const sizeItem = sizes[index];
568
+ switch (corner) {
569
+ case "tl":
570
+ return firstCellIndex;
571
+ case "tr":
572
+ if (!sizeItem) {
573
+ return firstCellIndex;
574
+ }
575
+ return firstCellIndex + sizeItem.width - 1;
576
+ case "bl":
577
+ if (!sizeItem) {
578
+ return firstCellIndex;
579
+ }
580
+ return firstCellIndex + (sizeItem.height - 1) * cols;
581
+ case "br":
582
+ return cellMap.lastIndexOf(index);
583
+ }
584
+ return -1;
585
+ }
586
+ function getGridCellIndices(indices, cellMap) {
587
+ return cellMap.flatMap((index, cellIndex) => indices.includes(index) ? [cellIndex] : []);
588
+ }
589
+ function isListIndexDisabled(listRef, index, disabledIndices) {
590
+ if (typeof disabledIndices === "function") {
591
+ return disabledIndices(index);
592
+ } else if (disabledIndices) {
593
+ return disabledIndices.includes(index);
594
+ }
595
+ const element = listRef.current[index];
596
+ return element == null || element.hasAttribute("disabled") || element.getAttribute("aria-disabled") === "true";
597
+ }
598
+ const getTabbableOptions = () => ({
599
+ getShadowRoot: true,
600
+ displayCheck: typeof ResizeObserver === "function" && ResizeObserver.toString().includes("[native code]") ? "full" : "none"
601
+ });
602
+ function getTabbableIn(container, dir) {
603
+ const list = (0, import_tabbable.tabbable)(container, getTabbableOptions());
604
+ const len = list.length;
605
+ if (len === 0) return;
606
+ const active = activeElement(getDocument(container));
607
+ const index = list.indexOf(active);
608
+ const nextIndex = index === -1 ? dir === 1 ? 0 : len - 1 : index + dir;
609
+ return list[nextIndex];
610
+ }
611
+ function getNextTabbable(referenceElement) {
612
+ return getTabbableIn(getDocument(referenceElement).body, 1) || referenceElement;
613
+ }
614
+ function getPreviousTabbable(referenceElement) {
615
+ return getTabbableIn(getDocument(referenceElement).body, -1) || referenceElement;
616
+ }
617
+ let rafId = 0;
618
+ function enqueueFocus(el, options = {}) {
619
+ const { preventScroll = false, cancelPrevious = true, sync = false } = options;
620
+ cancelPrevious && cancelAnimationFrame(rafId);
621
+ const exec = () => el?.focus({ preventScroll });
622
+ if (sync) {
623
+ exec();
624
+ } else {
625
+ rafId = requestAnimationFrame(exec);
626
+ }
627
+ }
628
+ function isOutsideEvent(event, container) {
629
+ const containerElement = container || event.currentTarget;
630
+ const relatedTarget = event.relatedTarget;
631
+ return !relatedTarget || !contains(containerElement, relatedTarget);
632
+ }
633
+ function disableFocusInside(container) {
634
+ const tabbableElements = (0, import_tabbable.tabbable)(container, getTabbableOptions());
635
+ tabbableElements.forEach((element) => {
636
+ element.dataset.tabindex = element.getAttribute("tabindex") || "";
637
+ element.setAttribute("tabindex", "-1");
638
+ });
639
+ }
640
+ function enableFocusInside(container) {
641
+ const elements = container.querySelectorAll("[data-tabindex]");
642
+ elements.forEach((element) => {
643
+ const tabindex = element.dataset.tabindex;
644
+ delete element.dataset.tabindex;
645
+ if (tabindex) {
646
+ element.setAttribute("tabindex", tabindex);
647
+ } else {
648
+ element.removeAttribute("tabindex");
649
+ }
650
+ });
651
+ }
652
+ // Annotate the CommonJS export names for ESM import in node:
653
+ 0 && (module.exports = {
654
+ FOCUSABLE_ATTRIBUTE,
655
+ activeElement,
656
+ camelCaseToKebabCase,
657
+ clearTimeoutIfSet,
658
+ contains,
659
+ createAttribute,
660
+ createGridCellMap,
661
+ deepEqual,
662
+ disableFocusInside,
663
+ enableFocusInside,
664
+ enqueueFocus,
665
+ execWithArgsOrReturn,
666
+ findNonDisabledListIndex,
667
+ getDPR,
668
+ getDeepestNode,
669
+ getDelay,
670
+ getDocument,
671
+ getFloatingFocusElement,
672
+ getGridCellIndexOfCorner,
673
+ getGridCellIndices,
674
+ getGridNavigatedIndex,
675
+ getMaxListIndex,
676
+ getMinListIndex,
677
+ getNextTabbable,
678
+ getNodeAncestors,
679
+ getNodeChildren,
680
+ getPlatform,
681
+ getPreviousTabbable,
682
+ getTabbableOptions,
683
+ getTarget,
684
+ getUserAgent,
685
+ isAndroid,
686
+ isClient,
687
+ isDifferentGridRow,
688
+ isEventTargetWithin,
689
+ isIndexOutOfListBounds,
690
+ isJSDOM,
691
+ isListIndexDisabled,
692
+ isMac,
693
+ isMacSafari,
694
+ isMouseLikePointerType,
695
+ isOutsideEvent,
696
+ isReactEvent,
697
+ isRootElement,
698
+ isSafari,
699
+ isTypeableCombobox,
700
+ isTypeableElement,
701
+ isVirtualClick,
702
+ isVirtualPointerEvent,
703
+ matchesFocusVisible,
704
+ roundByDPR,
705
+ stopEvent,
706
+ useEffectEvent,
707
+ useLatestRef,
708
+ useModernLayoutEffect
709
+ });