@soomo/react-text-annotator 3.1.0-staging.21 → 3.1.0-staging.23

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 (45) hide show
  1. package/dist/TextAnnotationPopup/TextAnnotationPopup.d.ts.map +1 -1
  2. package/dist/hooks/useAnnotationQuoteIdling.d.ts.map +1 -1
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/react-text-annotator.es.js +1 -1
  6. package/dist/react-text-annotator.es10.js +490 -0
  7. package/dist/react-text-annotator.es10.js.map +1 -0
  8. package/dist/react-text-annotator.es11.js +78 -483
  9. package/dist/react-text-annotator.es11.js.map +1 -1
  10. package/dist/react-text-annotator.es12.js +40 -77
  11. package/dist/react-text-annotator.es12.js.map +1 -1
  12. package/dist/react-text-annotator.es13.js +21 -41
  13. package/dist/react-text-annotator.es13.js.map +1 -1
  14. package/dist/react-text-annotator.es14.js +1629 -19
  15. package/dist/react-text-annotator.es14.js.map +1 -1
  16. package/dist/react-text-annotator.es15.js +8 -1596
  17. package/dist/react-text-annotator.es15.js.map +1 -1
  18. package/dist/react-text-annotator.es17.js +285 -0
  19. package/dist/react-text-annotator.es17.js.map +1 -0
  20. package/dist/react-text-annotator.es18.js +559 -244
  21. package/dist/react-text-annotator.es18.js.map +1 -1
  22. package/dist/react-text-annotator.es19.js +12 -584
  23. package/dist/react-text-annotator.es19.js.map +1 -1
  24. package/dist/react-text-annotator.es2.js +7 -4
  25. package/dist/react-text-annotator.es2.js.map +1 -1
  26. package/dist/react-text-annotator.es22.js.map +1 -1
  27. package/dist/react-text-annotator.es3.js +5 -5
  28. package/dist/react-text-annotator.es3.js.map +1 -1
  29. package/dist/react-text-annotator.es4.js +2 -2
  30. package/dist/react-text-annotator.es4.js.map +1 -1
  31. package/dist/react-text-annotator.es5.js +1 -1
  32. package/dist/react-text-annotator.es5.js.map +1 -1
  33. package/dist/react-text-annotator.es6.js +2 -2
  34. package/dist/react-text-annotator.es7.js +14 -11
  35. package/dist/react-text-annotator.es7.js.map +1 -1
  36. package/dist/react-text-annotator.es8.js +3 -559
  37. package/dist/react-text-annotator.es8.js.map +1 -1
  38. package/dist/tei/CETEIcean.d.ts +1 -0
  39. package/dist/tei/CETEIcean.d.ts.map +1 -1
  40. package/dist/tei/TEIAnnotator.d.ts.map +1 -1
  41. package/package.json +11 -11
  42. package/dist/react-text-annotator.es16.js +0 -12
  43. package/dist/react-text-annotator.es16.js.map +0 -1
  44. package/dist/react-text-annotator.es9.js +0 -13
  45. package/dist/react-text-annotator.es9.js.map +0 -1
@@ -1,28 +1,1638 @@
1
- var has = Object.prototype.hasOwnProperty;
2
- function dequal(foo, bar) {
3
- var ctor, len;
4
- if (foo === bar) return true;
5
- if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
6
- if (ctor === Date) return foo.getTime() === bar.getTime();
7
- if (ctor === RegExp) return foo.toString() === bar.toString();
8
- if (ctor === Array) {
9
- if ((len = foo.length) === bar.length) {
10
- while (len-- && dequal(foo[len], bar[len])) ;
1
+ import * as React from "react";
2
+ import { useLayoutEffect, useEffect, useRef } from "react";
3
+ import { isTypeableCombobox, getDocument, activeElement, contains, isVirtualClick, isVirtualPointerEvent, isSafari, stopEvent, getTarget, isReactEvent, isRootElement, isEventTargetWithin } from "./react-text-annotator.es29.js";
4
+ import { getComputedStyle, isHTMLElement, isElement, getOverflowAncestors, getNodeName, isLastTraversableNode, getParentNode, isWebKit } from "./react-text-annotator.es30.js";
5
+ import { isTabbable, tabbable } from "./react-text-annotator.es31.js";
6
+ import * as ReactDOM from "react-dom";
7
+ import { useFloating as useFloating$1 } from "./react-text-annotator.es17.js";
8
+ import { arrow, flip, inline, offset, shift } from "./react-text-annotator.es17.js";
9
+ function useMergeRefs(refs) {
10
+ return React.useMemo(() => {
11
+ if (refs.every((ref) => ref == null)) {
12
+ return null;
13
+ }
14
+ return (value) => {
15
+ refs.forEach((ref) => {
16
+ if (typeof ref === "function") {
17
+ ref(value);
18
+ } else if (ref != null) {
19
+ ref.current = value;
20
+ }
21
+ });
22
+ };
23
+ }, refs);
24
+ }
25
+ const SafeReact = {
26
+ ...React
27
+ };
28
+ const useInsertionEffect = SafeReact.useInsertionEffect;
29
+ const useSafeInsertionEffect = useInsertionEffect || ((fn) => fn());
30
+ function useEffectEvent(callback) {
31
+ const ref = React.useRef(() => {
32
+ if (process.env.NODE_ENV !== "production") {
33
+ throw new Error("Cannot call an event handler while rendering.");
34
+ }
35
+ });
36
+ useSafeInsertionEffect(() => {
37
+ ref.current = callback;
38
+ });
39
+ return React.useCallback(function() {
40
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
41
+ args[_key] = arguments[_key];
42
+ }
43
+ return ref.current == null ? void 0 : ref.current(...args);
44
+ }, []);
45
+ }
46
+ var index = typeof document !== "undefined" ? useLayoutEffect : useEffect;
47
+ function _extends() {
48
+ _extends = Object.assign ? Object.assign.bind() : function(target) {
49
+ for (var i = 1; i < arguments.length; i++) {
50
+ var source = arguments[i];
51
+ for (var key in source) {
52
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
53
+ target[key] = source[key];
54
+ }
55
+ }
56
+ }
57
+ return target;
58
+ };
59
+ return _extends.apply(this, arguments);
60
+ }
61
+ let serverHandoffComplete = false;
62
+ let count = 0;
63
+ const genId = () => (
64
+ // Ensure the id is unique with multiple independent versions of Floating UI
65
+ // on <React 18
66
+ "floating-ui-" + Math.random().toString(36).slice(2, 6) + count++
67
+ );
68
+ function useFloatingId() {
69
+ const [id, setId] = React.useState(() => serverHandoffComplete ? genId() : void 0);
70
+ index(() => {
71
+ if (id == null) {
72
+ setId(genId());
73
+ }
74
+ }, []);
75
+ React.useEffect(() => {
76
+ serverHandoffComplete = true;
77
+ }, []);
78
+ return id;
79
+ }
80
+ const useReactId = SafeReact.useId;
81
+ const useId = useReactId || useFloatingId;
82
+ let devMessageSet;
83
+ if (process.env.NODE_ENV !== "production") {
84
+ devMessageSet = /* @__PURE__ */ new Set();
85
+ }
86
+ function warn() {
87
+ var _devMessageSet;
88
+ for (var _len = arguments.length, messages = new Array(_len), _key = 0; _key < _len; _key++) {
89
+ messages[_key] = arguments[_key];
90
+ }
91
+ const message = "Floating UI: " + messages.join(" ");
92
+ if (!((_devMessageSet = devMessageSet) != null && _devMessageSet.has(message))) {
93
+ var _devMessageSet2;
94
+ (_devMessageSet2 = devMessageSet) == null || _devMessageSet2.add(message);
95
+ console.warn(message);
96
+ }
97
+ }
98
+ function error() {
99
+ var _devMessageSet3;
100
+ for (var _len2 = arguments.length, messages = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
101
+ messages[_key2] = arguments[_key2];
102
+ }
103
+ const message = "Floating UI: " + messages.join(" ");
104
+ if (!((_devMessageSet3 = devMessageSet) != null && _devMessageSet3.has(message))) {
105
+ var _devMessageSet4;
106
+ (_devMessageSet4 = devMessageSet) == null || _devMessageSet4.add(message);
107
+ console.error(message);
108
+ }
109
+ }
110
+ const FloatingArrow = /* @__PURE__ */ React.forwardRef(function FloatingArrow2(props, ref) {
111
+ const {
112
+ context: {
113
+ placement,
114
+ elements: {
115
+ floating
116
+ },
117
+ middlewareData: {
118
+ arrow: arrow2,
119
+ shift: shift2
120
+ }
121
+ },
122
+ width = 14,
123
+ height = 7,
124
+ tipRadius = 0,
125
+ strokeWidth = 0,
126
+ staticOffset,
127
+ stroke,
128
+ d,
129
+ style: {
130
+ transform,
131
+ ...restStyle
132
+ } = {},
133
+ ...rest
134
+ } = props;
135
+ if (process.env.NODE_ENV !== "production") {
136
+ if (!ref) {
137
+ warn("The `ref` prop is required for `FloatingArrow`.");
138
+ }
139
+ }
140
+ const clipPathId = useId();
141
+ const [isRTL, setIsRTL] = React.useState(false);
142
+ index(() => {
143
+ if (!floating) return;
144
+ const isRTL2 = getComputedStyle(floating).direction === "rtl";
145
+ if (isRTL2) {
146
+ setIsRTL(true);
147
+ }
148
+ }, [floating]);
149
+ if (!floating) {
150
+ return null;
151
+ }
152
+ const [side, alignment] = placement.split("-");
153
+ const isVerticalSide = side === "top" || side === "bottom";
154
+ let computedStaticOffset = staticOffset;
155
+ if (isVerticalSide && shift2 != null && shift2.x || !isVerticalSide && shift2 != null && shift2.y) {
156
+ computedStaticOffset = null;
157
+ }
158
+ const computedStrokeWidth = strokeWidth * 2;
159
+ const halfStrokeWidth = computedStrokeWidth / 2;
160
+ const svgX = width / 2 * (tipRadius / -8 + 1);
161
+ const svgY = height / 2 * tipRadius / 4;
162
+ const isCustomShape = !!d;
163
+ const yOffsetProp = computedStaticOffset && alignment === "end" ? "bottom" : "top";
164
+ let xOffsetProp = computedStaticOffset && alignment === "end" ? "right" : "left";
165
+ if (computedStaticOffset && isRTL) {
166
+ xOffsetProp = alignment === "end" ? "left" : "right";
167
+ }
168
+ const arrowX = (arrow2 == null ? void 0 : arrow2.x) != null ? computedStaticOffset || arrow2.x : "";
169
+ const arrowY = (arrow2 == null ? void 0 : arrow2.y) != null ? computedStaticOffset || arrow2.y : "";
170
+ const dValue = d || "M0,0" + (" H" + width) + (" L" + (width - svgX) + "," + (height - svgY)) + (" Q" + width / 2 + "," + height + " " + svgX + "," + (height - svgY)) + " Z";
171
+ const rotation = {
172
+ top: isCustomShape ? "rotate(180deg)" : "",
173
+ left: isCustomShape ? "rotate(90deg)" : "rotate(-90deg)",
174
+ bottom: isCustomShape ? "" : "rotate(180deg)",
175
+ right: isCustomShape ? "rotate(-90deg)" : "rotate(90deg)"
176
+ }[side];
177
+ return /* @__PURE__ */ React.createElement("svg", _extends({}, rest, {
178
+ "aria-hidden": true,
179
+ ref,
180
+ width: isCustomShape ? width : width + computedStrokeWidth,
181
+ height: width,
182
+ viewBox: "0 0 " + width + " " + (height > width ? height : width),
183
+ style: {
184
+ position: "absolute",
185
+ pointerEvents: "none",
186
+ [xOffsetProp]: arrowX,
187
+ [yOffsetProp]: arrowY,
188
+ [side]: isVerticalSide || isCustomShape ? "100%" : "calc(100% - " + computedStrokeWidth / 2 + "px)",
189
+ transform: [rotation, transform].filter((t) => !!t).join(" "),
190
+ ...restStyle
191
+ }
192
+ }), computedStrokeWidth > 0 && /* @__PURE__ */ React.createElement("path", {
193
+ clipPath: "url(#" + clipPathId + ")",
194
+ fill: "none",
195
+ stroke,
196
+ strokeWidth: computedStrokeWidth + (d ? 0 : 1),
197
+ d: dValue
198
+ }), /* @__PURE__ */ React.createElement("path", {
199
+ stroke: computedStrokeWidth && !d ? rest.fill : "none",
200
+ d: dValue
201
+ }), /* @__PURE__ */ React.createElement("clipPath", {
202
+ id: clipPathId
203
+ }, /* @__PURE__ */ React.createElement("rect", {
204
+ x: -halfStrokeWidth,
205
+ y: halfStrokeWidth * (isCustomShape ? -1 : 1),
206
+ width: width + computedStrokeWidth,
207
+ height: width
208
+ })));
209
+ });
210
+ function createPubSub() {
211
+ const map = /* @__PURE__ */ new Map();
212
+ return {
213
+ emit(event, data) {
214
+ var _map$get;
215
+ (_map$get = map.get(event)) == null || _map$get.forEach((handler) => handler(data));
216
+ },
217
+ on(event, listener) {
218
+ map.set(event, [...map.get(event) || [], listener]);
219
+ },
220
+ off(event, listener) {
221
+ var _map$get2;
222
+ map.set(event, ((_map$get2 = map.get(event)) == null ? void 0 : _map$get2.filter((l) => l !== listener)) || []);
223
+ }
224
+ };
225
+ }
226
+ const FloatingNodeContext = /* @__PURE__ */ React.createContext(null);
227
+ const FloatingTreeContext = /* @__PURE__ */ React.createContext(null);
228
+ const useFloatingParentNodeId = () => {
229
+ var _React$useContext;
230
+ return ((_React$useContext = React.useContext(FloatingNodeContext)) == null ? void 0 : _React$useContext.id) || null;
231
+ };
232
+ const useFloatingTree = () => React.useContext(FloatingTreeContext);
233
+ function createAttribute(name) {
234
+ return "data-floating-ui-" + name;
235
+ }
236
+ function useLatestRef(value) {
237
+ const ref = useRef(value);
238
+ index(() => {
239
+ ref.current = value;
240
+ });
241
+ return ref;
242
+ }
243
+ let rafId = 0;
244
+ function enqueueFocus(el, options) {
245
+ if (options === void 0) {
246
+ options = {};
247
+ }
248
+ const {
249
+ preventScroll = false,
250
+ cancelPrevious = true,
251
+ sync = false
252
+ } = options;
253
+ cancelPrevious && cancelAnimationFrame(rafId);
254
+ const exec = () => el == null ? void 0 : el.focus({
255
+ preventScroll
256
+ });
257
+ if (sync) {
258
+ exec();
259
+ } else {
260
+ rafId = requestAnimationFrame(exec);
261
+ }
262
+ }
263
+ function getAncestors(nodes, id) {
264
+ var _nodes$find;
265
+ let allAncestors = [];
266
+ let currentParentId = (_nodes$find = nodes.find((node) => node.id === id)) == null ? void 0 : _nodes$find.parentId;
267
+ while (currentParentId) {
268
+ const currentNode = nodes.find((node) => node.id === currentParentId);
269
+ currentParentId = currentNode == null ? void 0 : currentNode.parentId;
270
+ if (currentNode) {
271
+ allAncestors = allAncestors.concat(currentNode);
272
+ }
273
+ }
274
+ return allAncestors;
275
+ }
276
+ function getChildren(nodes, id) {
277
+ let allChildren = nodes.filter((node) => {
278
+ var _node$context;
279
+ return node.parentId === id && ((_node$context = node.context) == null ? void 0 : _node$context.open);
280
+ });
281
+ let currentChildren = allChildren;
282
+ while (currentChildren.length) {
283
+ currentChildren = nodes.filter((node) => {
284
+ var _currentChildren;
285
+ return (_currentChildren = currentChildren) == null ? void 0 : _currentChildren.some((n) => {
286
+ var _node$context2;
287
+ return node.parentId === n.id && ((_node$context2 = node.context) == null ? void 0 : _node$context2.open);
288
+ });
289
+ });
290
+ allChildren = allChildren.concat(currentChildren);
291
+ }
292
+ return allChildren;
293
+ }
294
+ let counterMap = /* @__PURE__ */ new WeakMap();
295
+ let uncontrolledElementsSet = /* @__PURE__ */ new WeakSet();
296
+ let markerMap = {};
297
+ let lockCount$1 = 0;
298
+ const supportsInert = () => typeof HTMLElement !== "undefined" && "inert" in HTMLElement.prototype;
299
+ const unwrapHost = (node) => node && (node.host || unwrapHost(node.parentNode));
300
+ const correctElements = (parent, targets) => targets.map((target) => {
301
+ if (parent.contains(target)) {
302
+ return target;
303
+ }
304
+ const correctedTarget = unwrapHost(target);
305
+ if (parent.contains(correctedTarget)) {
306
+ return correctedTarget;
307
+ }
308
+ return null;
309
+ }).filter((x) => x != null);
310
+ function applyAttributeToOthers(uncorrectedAvoidElements, body, ariaHidden, inert) {
311
+ const markerName = "data-floating-ui-inert";
312
+ const controlAttribute = inert ? "inert" : ariaHidden ? "aria-hidden" : null;
313
+ const avoidElements = correctElements(body, uncorrectedAvoidElements);
314
+ const elementsToKeep = /* @__PURE__ */ new Set();
315
+ const elementsToStop = new Set(avoidElements);
316
+ const hiddenElements = [];
317
+ if (!markerMap[markerName]) {
318
+ markerMap[markerName] = /* @__PURE__ */ new WeakMap();
319
+ }
320
+ const markerCounter = markerMap[markerName];
321
+ avoidElements.forEach(keep);
322
+ deep(body);
323
+ elementsToKeep.clear();
324
+ function keep(el) {
325
+ if (!el || elementsToKeep.has(el)) {
326
+ return;
327
+ }
328
+ elementsToKeep.add(el);
329
+ el.parentNode && keep(el.parentNode);
330
+ }
331
+ function deep(parent) {
332
+ if (!parent || elementsToStop.has(parent)) {
333
+ return;
334
+ }
335
+ [].forEach.call(parent.children, (node) => {
336
+ if (getNodeName(node) === "script") return;
337
+ if (elementsToKeep.has(node)) {
338
+ deep(node);
339
+ } else {
340
+ const attr2 = controlAttribute ? node.getAttribute(controlAttribute) : null;
341
+ const alreadyHidden = attr2 !== null && attr2 !== "false";
342
+ const currentCounterValue = counterMap.get(node) || 0;
343
+ const counterValue = controlAttribute ? currentCounterValue + 1 : currentCounterValue;
344
+ const markerValue = (markerCounter.get(node) || 0) + 1;
345
+ counterMap.set(node, counterValue);
346
+ markerCounter.set(node, markerValue);
347
+ hiddenElements.push(node);
348
+ if (counterValue === 1 && alreadyHidden) {
349
+ uncontrolledElementsSet.add(node);
350
+ }
351
+ if (markerValue === 1) {
352
+ node.setAttribute(markerName, "");
353
+ }
354
+ if (!alreadyHidden && controlAttribute) {
355
+ node.setAttribute(controlAttribute, "true");
356
+ }
357
+ }
358
+ });
359
+ }
360
+ lockCount$1++;
361
+ return () => {
362
+ hiddenElements.forEach((element) => {
363
+ const currentCounterValue = counterMap.get(element) || 0;
364
+ const counterValue = controlAttribute ? currentCounterValue - 1 : currentCounterValue;
365
+ const markerValue = (markerCounter.get(element) || 0) - 1;
366
+ counterMap.set(element, counterValue);
367
+ markerCounter.set(element, markerValue);
368
+ if (!counterValue) {
369
+ if (!uncontrolledElementsSet.has(element) && controlAttribute) {
370
+ element.removeAttribute(controlAttribute);
371
+ }
372
+ uncontrolledElementsSet.delete(element);
373
+ }
374
+ if (!markerValue) {
375
+ element.removeAttribute(markerName);
376
+ }
377
+ });
378
+ lockCount$1--;
379
+ if (!lockCount$1) {
380
+ counterMap = /* @__PURE__ */ new WeakMap();
381
+ counterMap = /* @__PURE__ */ new WeakMap();
382
+ uncontrolledElementsSet = /* @__PURE__ */ new WeakSet();
383
+ markerMap = {};
384
+ }
385
+ };
386
+ }
387
+ function markOthers(avoidElements, ariaHidden, inert) {
388
+ if (ariaHidden === void 0) {
389
+ ariaHidden = false;
390
+ }
391
+ if (inert === void 0) {
392
+ inert = false;
393
+ }
394
+ const body = getDocument(avoidElements[0]).body;
395
+ return applyAttributeToOthers(avoidElements.concat(Array.from(body.querySelectorAll("[aria-live]"))), body, ariaHidden, inert);
396
+ }
397
+ const getTabbableOptions = () => ({
398
+ getShadowRoot: true,
399
+ displayCheck: (
400
+ // JSDOM does not support the `tabbable` library. To solve this we can
401
+ // check if `ResizeObserver` is a real function (not polyfilled), which
402
+ // determines if the current environment is JSDOM-like.
403
+ typeof ResizeObserver === "function" && ResizeObserver.toString().includes("[native code]") ? "full" : "none"
404
+ )
405
+ });
406
+ function getTabbableIn(container, direction) {
407
+ const allTabbable = tabbable(container, getTabbableOptions());
408
+ if (direction === "prev") {
409
+ allTabbable.reverse();
410
+ }
411
+ const activeIndex = allTabbable.indexOf(activeElement(getDocument(container)));
412
+ const nextTabbableElements = allTabbable.slice(activeIndex + 1);
413
+ return nextTabbableElements[0];
414
+ }
415
+ function getNextTabbable() {
416
+ return getTabbableIn(document.body, "next");
417
+ }
418
+ function getPreviousTabbable() {
419
+ return getTabbableIn(document.body, "prev");
420
+ }
421
+ function isOutsideEvent(event, container) {
422
+ const containerElement = container || event.currentTarget;
423
+ const relatedTarget = event.relatedTarget;
424
+ return !relatedTarget || !contains(containerElement, relatedTarget);
425
+ }
426
+ function disableFocusInside(container) {
427
+ const tabbableElements = tabbable(container, getTabbableOptions());
428
+ tabbableElements.forEach((element) => {
429
+ element.dataset.tabindex = element.getAttribute("tabindex") || "";
430
+ element.setAttribute("tabindex", "-1");
431
+ });
432
+ }
433
+ function enableFocusInside(container) {
434
+ const elements = container.querySelectorAll("[data-tabindex]");
435
+ elements.forEach((element) => {
436
+ const tabindex = element.dataset.tabindex;
437
+ delete element.dataset.tabindex;
438
+ if (tabindex) {
439
+ element.setAttribute("tabindex", tabindex);
440
+ } else {
441
+ element.removeAttribute("tabindex");
442
+ }
443
+ });
444
+ }
445
+ const HIDDEN_STYLES = {
446
+ border: 0,
447
+ clip: "rect(0 0 0 0)",
448
+ height: "1px",
449
+ margin: "-1px",
450
+ overflow: "hidden",
451
+ padding: 0,
452
+ position: "fixed",
453
+ whiteSpace: "nowrap",
454
+ width: "1px",
455
+ top: 0,
456
+ left: 0
457
+ };
458
+ let timeoutId;
459
+ function setActiveElementOnTab(event) {
460
+ if (event.key === "Tab") {
461
+ event.target;
462
+ clearTimeout(timeoutId);
463
+ }
464
+ }
465
+ const FocusGuard = /* @__PURE__ */ React.forwardRef(function FocusGuard2(props, ref) {
466
+ const [role, setRole] = React.useState();
467
+ index(() => {
468
+ if (isSafari()) {
469
+ setRole("button");
470
+ }
471
+ document.addEventListener("keydown", setActiveElementOnTab);
472
+ return () => {
473
+ document.removeEventListener("keydown", setActiveElementOnTab);
474
+ };
475
+ }, []);
476
+ const restProps = {
477
+ ref,
478
+ tabIndex: 0,
479
+ // Role is only for VoiceOver
480
+ role,
481
+ "aria-hidden": role ? void 0 : true,
482
+ [createAttribute("focus-guard")]: "",
483
+ style: HIDDEN_STYLES
484
+ };
485
+ return /* @__PURE__ */ React.createElement("span", _extends({}, props, restProps));
486
+ });
487
+ const PortalContext = /* @__PURE__ */ React.createContext(null);
488
+ const attr = /* @__PURE__ */ createAttribute("portal");
489
+ function useFloatingPortalNode(props) {
490
+ if (props === void 0) {
491
+ props = {};
492
+ }
493
+ const {
494
+ id,
495
+ root
496
+ } = props;
497
+ const uniqueId = useId();
498
+ const portalContext = usePortalContext();
499
+ const [portalNode, setPortalNode] = React.useState(null);
500
+ const portalNodeRef = React.useRef(null);
501
+ index(() => {
502
+ return () => {
503
+ portalNode == null || portalNode.remove();
504
+ queueMicrotask(() => {
505
+ portalNodeRef.current = null;
506
+ });
507
+ };
508
+ }, [portalNode]);
509
+ index(() => {
510
+ if (!uniqueId) return;
511
+ if (portalNodeRef.current) return;
512
+ const existingIdRoot = id ? document.getElementById(id) : null;
513
+ if (!existingIdRoot) return;
514
+ const subRoot = document.createElement("div");
515
+ subRoot.id = uniqueId;
516
+ subRoot.setAttribute(attr, "");
517
+ existingIdRoot.appendChild(subRoot);
518
+ portalNodeRef.current = subRoot;
519
+ setPortalNode(subRoot);
520
+ }, [id, uniqueId]);
521
+ index(() => {
522
+ if (root === null) return;
523
+ if (!uniqueId) return;
524
+ if (portalNodeRef.current) return;
525
+ let container = root || (portalContext == null ? void 0 : portalContext.portalNode);
526
+ if (container && !isElement(container)) container = container.current;
527
+ container = container || document.body;
528
+ let idWrapper = null;
529
+ if (id) {
530
+ idWrapper = document.createElement("div");
531
+ idWrapper.id = id;
532
+ container.appendChild(idWrapper);
533
+ }
534
+ const subRoot = document.createElement("div");
535
+ subRoot.id = uniqueId;
536
+ subRoot.setAttribute(attr, "");
537
+ container = idWrapper || container;
538
+ container.appendChild(subRoot);
539
+ portalNodeRef.current = subRoot;
540
+ setPortalNode(subRoot);
541
+ }, [id, root, uniqueId, portalContext]);
542
+ return portalNode;
543
+ }
544
+ function FloatingPortal(props) {
545
+ const {
546
+ children,
547
+ id,
548
+ root,
549
+ preserveTabOrder = true
550
+ } = props;
551
+ const portalNode = useFloatingPortalNode({
552
+ id,
553
+ root
554
+ });
555
+ const [focusManagerState, setFocusManagerState] = React.useState(null);
556
+ const beforeOutsideRef = React.useRef(null);
557
+ const afterOutsideRef = React.useRef(null);
558
+ const beforeInsideRef = React.useRef(null);
559
+ const afterInsideRef = React.useRef(null);
560
+ const modal = focusManagerState == null ? void 0 : focusManagerState.modal;
561
+ const open = focusManagerState == null ? void 0 : focusManagerState.open;
562
+ const shouldRenderGuards = (
563
+ // The FocusManager and therefore floating element are currently open/
564
+ // rendered.
565
+ !!focusManagerState && // Guards are only for non-modal focus management.
566
+ !focusManagerState.modal && // Don't render if unmount is transitioning.
567
+ focusManagerState.open && preserveTabOrder && !!(root || portalNode)
568
+ );
569
+ React.useEffect(() => {
570
+ if (!portalNode || !preserveTabOrder || modal) {
571
+ return;
572
+ }
573
+ function onFocus(event) {
574
+ if (portalNode && isOutsideEvent(event)) {
575
+ const focusing = event.type === "focusin";
576
+ const manageFocus = focusing ? enableFocusInside : disableFocusInside;
577
+ manageFocus(portalNode);
578
+ }
579
+ }
580
+ portalNode.addEventListener("focusin", onFocus, true);
581
+ portalNode.addEventListener("focusout", onFocus, true);
582
+ return () => {
583
+ portalNode.removeEventListener("focusin", onFocus, true);
584
+ portalNode.removeEventListener("focusout", onFocus, true);
585
+ };
586
+ }, [portalNode, preserveTabOrder, modal]);
587
+ React.useEffect(() => {
588
+ if (!portalNode) return;
589
+ if (open) return;
590
+ enableFocusInside(portalNode);
591
+ }, [open, portalNode]);
592
+ return /* @__PURE__ */ React.createElement(PortalContext.Provider, {
593
+ value: React.useMemo(() => ({
594
+ preserveTabOrder,
595
+ beforeOutsideRef,
596
+ afterOutsideRef,
597
+ beforeInsideRef,
598
+ afterInsideRef,
599
+ portalNode,
600
+ setFocusManagerState
601
+ }), [preserveTabOrder, portalNode])
602
+ }, shouldRenderGuards && portalNode && /* @__PURE__ */ React.createElement(FocusGuard, {
603
+ "data-type": "outside",
604
+ ref: beforeOutsideRef,
605
+ onFocus: (event) => {
606
+ if (isOutsideEvent(event, portalNode)) {
607
+ var _beforeInsideRef$curr;
608
+ (_beforeInsideRef$curr = beforeInsideRef.current) == null || _beforeInsideRef$curr.focus();
609
+ } else {
610
+ const prevTabbable = getPreviousTabbable() || (focusManagerState == null ? void 0 : focusManagerState.refs.domReference.current);
611
+ prevTabbable == null || prevTabbable.focus();
612
+ }
613
+ }
614
+ }), shouldRenderGuards && portalNode && /* @__PURE__ */ React.createElement("span", {
615
+ "aria-owns": portalNode.id,
616
+ style: HIDDEN_STYLES
617
+ }), portalNode && /* @__PURE__ */ ReactDOM.createPortal(children, portalNode), shouldRenderGuards && portalNode && /* @__PURE__ */ React.createElement(FocusGuard, {
618
+ "data-type": "outside",
619
+ ref: afterOutsideRef,
620
+ onFocus: (event) => {
621
+ if (isOutsideEvent(event, portalNode)) {
622
+ var _afterInsideRef$curre;
623
+ (_afterInsideRef$curre = afterInsideRef.current) == null || _afterInsideRef$curre.focus();
624
+ } else {
625
+ const nextTabbable = getNextTabbable() || (focusManagerState == null ? void 0 : focusManagerState.refs.domReference.current);
626
+ nextTabbable == null || nextTabbable.focus();
627
+ (focusManagerState == null ? void 0 : focusManagerState.closeOnFocusOut) && (focusManagerState == null ? void 0 : focusManagerState.onOpenChange(false, event.nativeEvent, "focus-out"));
628
+ }
629
+ }
630
+ }));
631
+ }
632
+ const usePortalContext = () => React.useContext(PortalContext);
633
+ const FOCUSABLE_ATTRIBUTE = "data-floating-ui-focusable";
634
+ function getFloatingFocusElement(floatingElement) {
635
+ if (!floatingElement) {
636
+ return null;
637
+ }
638
+ return floatingElement.hasAttribute(FOCUSABLE_ATTRIBUTE) ? floatingElement : floatingElement.querySelector("[" + FOCUSABLE_ATTRIBUTE + "]") || floatingElement;
639
+ }
640
+ const LIST_LIMIT = 20;
641
+ let previouslyFocusedElements = [];
642
+ function addPreviouslyFocusedElement(element) {
643
+ previouslyFocusedElements = previouslyFocusedElements.filter((el) => el.isConnected);
644
+ if (element && getNodeName(element) !== "body") {
645
+ previouslyFocusedElements.push(element);
646
+ if (previouslyFocusedElements.length > LIST_LIMIT) {
647
+ previouslyFocusedElements = previouslyFocusedElements.slice(-LIST_LIMIT);
648
+ }
649
+ }
650
+ }
651
+ function getPreviouslyFocusedElement() {
652
+ return previouslyFocusedElements.slice().reverse().find((el) => el.isConnected);
653
+ }
654
+ function getFirstTabbableElement(container) {
655
+ const tabbableOptions = getTabbableOptions();
656
+ if (isTabbable(container, tabbableOptions)) {
657
+ return container;
658
+ }
659
+ return tabbable(container, tabbableOptions)[0] || container;
660
+ }
661
+ const VisuallyHiddenDismiss = /* @__PURE__ */ React.forwardRef(function VisuallyHiddenDismiss2(props, ref) {
662
+ return /* @__PURE__ */ React.createElement("button", _extends({}, props, {
663
+ type: "button",
664
+ ref,
665
+ tabIndex: -1,
666
+ style: HIDDEN_STYLES
667
+ }));
668
+ });
669
+ function FloatingFocusManager(props) {
670
+ const {
671
+ context,
672
+ children,
673
+ disabled = false,
674
+ order = ["content"],
675
+ guards: _guards = true,
676
+ initialFocus = 0,
677
+ returnFocus = true,
678
+ restoreFocus = false,
679
+ modal = true,
680
+ visuallyHiddenDismiss = false,
681
+ closeOnFocusOut = true,
682
+ outsideElementsInert = false
683
+ } = props;
684
+ const {
685
+ open,
686
+ refs,
687
+ nodeId,
688
+ onOpenChange,
689
+ events,
690
+ dataRef,
691
+ elements: {
692
+ domReference,
693
+ floating
694
+ }
695
+ } = context;
696
+ const ignoreInitialFocus = typeof initialFocus === "number" && initialFocus < 0;
697
+ const isUntrappedTypeableCombobox = isTypeableCombobox(domReference) && ignoreInitialFocus;
698
+ const inertSupported = supportsInert();
699
+ const guards = inertSupported ? _guards : true;
700
+ const useInert = !guards || inertSupported && outsideElementsInert;
701
+ const orderRef = useLatestRef(order);
702
+ const initialFocusRef = useLatestRef(initialFocus);
703
+ const returnFocusRef = useLatestRef(returnFocus);
704
+ const tree = useFloatingTree();
705
+ const portalContext = usePortalContext();
706
+ const startDismissButtonRef = React.useRef(null);
707
+ const endDismissButtonRef = React.useRef(null);
708
+ const preventReturnFocusRef = React.useRef(false);
709
+ const isPointerDownRef = React.useRef(false);
710
+ const tabbableIndexRef = React.useRef(-1);
711
+ const isInsidePortal = portalContext != null;
712
+ const floatingFocusElement = getFloatingFocusElement(floating);
713
+ const getTabbableContent = useEffectEvent(function(container) {
714
+ if (container === void 0) {
715
+ container = floatingFocusElement;
716
+ }
717
+ return container ? tabbable(container, getTabbableOptions()) : [];
718
+ });
719
+ const getTabbableElements = useEffectEvent((container) => {
720
+ const content = getTabbableContent(container);
721
+ return orderRef.current.map((type) => {
722
+ if (domReference && type === "reference") {
723
+ return domReference;
724
+ }
725
+ if (floatingFocusElement && type === "floating") {
726
+ return floatingFocusElement;
727
+ }
728
+ return content;
729
+ }).filter(Boolean).flat();
730
+ });
731
+ React.useEffect(() => {
732
+ if (disabled) return;
733
+ if (!modal) return;
734
+ function onKeyDown(event) {
735
+ if (event.key === "Tab") {
736
+ if (contains(floatingFocusElement, activeElement(getDocument(floatingFocusElement))) && getTabbableContent().length === 0 && !isUntrappedTypeableCombobox) {
737
+ stopEvent(event);
738
+ }
739
+ const els = getTabbableElements();
740
+ const target = getTarget(event);
741
+ if (orderRef.current[0] === "reference" && target === domReference) {
742
+ stopEvent(event);
743
+ if (event.shiftKey) {
744
+ enqueueFocus(els[els.length - 1]);
745
+ } else {
746
+ enqueueFocus(els[1]);
747
+ }
748
+ }
749
+ if (orderRef.current[1] === "floating" && target === floatingFocusElement && event.shiftKey) {
750
+ stopEvent(event);
751
+ enqueueFocus(els[0]);
752
+ }
753
+ }
754
+ }
755
+ const doc = getDocument(floatingFocusElement);
756
+ doc.addEventListener("keydown", onKeyDown);
757
+ return () => {
758
+ doc.removeEventListener("keydown", onKeyDown);
759
+ };
760
+ }, [disabled, domReference, floatingFocusElement, modal, orderRef, isUntrappedTypeableCombobox, getTabbableContent, getTabbableElements]);
761
+ React.useEffect(() => {
762
+ if (disabled) return;
763
+ if (!floating) return;
764
+ function handleFocusIn(event) {
765
+ const target = getTarget(event);
766
+ const tabbableContent = getTabbableContent();
767
+ const tabbableIndex = tabbableContent.indexOf(target);
768
+ if (tabbableIndex !== -1) {
769
+ tabbableIndexRef.current = tabbableIndex;
770
+ }
771
+ }
772
+ floating.addEventListener("focusin", handleFocusIn);
773
+ return () => {
774
+ floating.removeEventListener("focusin", handleFocusIn);
775
+ };
776
+ }, [disabled, floating, getTabbableContent]);
777
+ React.useEffect(() => {
778
+ if (disabled) return;
779
+ if (!closeOnFocusOut) return;
780
+ function handlePointerDown() {
781
+ isPointerDownRef.current = true;
782
+ setTimeout(() => {
783
+ isPointerDownRef.current = false;
784
+ });
785
+ }
786
+ function handleFocusOutside(event) {
787
+ const relatedTarget = event.relatedTarget;
788
+ queueMicrotask(() => {
789
+ const movedToUnrelatedNode = !(contains(domReference, relatedTarget) || contains(floating, relatedTarget) || contains(relatedTarget, floating) || contains(portalContext == null ? void 0 : portalContext.portalNode, relatedTarget) || relatedTarget != null && relatedTarget.hasAttribute(createAttribute("focus-guard")) || tree && (getChildren(tree.nodesRef.current, nodeId).find((node) => {
790
+ var _node$context, _node$context2;
791
+ return contains((_node$context = node.context) == null ? void 0 : _node$context.elements.floating, relatedTarget) || contains((_node$context2 = node.context) == null ? void 0 : _node$context2.elements.domReference, relatedTarget);
792
+ }) || getAncestors(tree.nodesRef.current, nodeId).find((node) => {
793
+ var _node$context3, _node$context4, _node$context5;
794
+ return [(_node$context3 = node.context) == null ? void 0 : _node$context3.elements.floating, getFloatingFocusElement((_node$context4 = node.context) == null ? void 0 : _node$context4.elements.floating)].includes(relatedTarget) || ((_node$context5 = node.context) == null ? void 0 : _node$context5.elements.domReference) === relatedTarget;
795
+ })));
796
+ if (restoreFocus && movedToUnrelatedNode && activeElement(getDocument(floatingFocusElement)) === getDocument(floatingFocusElement).body) {
797
+ if (isHTMLElement(floatingFocusElement)) {
798
+ floatingFocusElement.focus();
799
+ }
800
+ const prevTabbableIndex = tabbableIndexRef.current;
801
+ const tabbableContent = getTabbableContent();
802
+ const nodeToFocus = tabbableContent[prevTabbableIndex] || tabbableContent[tabbableContent.length - 1] || floatingFocusElement;
803
+ if (isHTMLElement(nodeToFocus)) {
804
+ nodeToFocus.focus();
805
+ }
806
+ }
807
+ if ((isUntrappedTypeableCombobox ? true : !modal) && relatedTarget && movedToUnrelatedNode && !isPointerDownRef.current && // Fix React 18 Strict Mode returnFocus due to double rendering.
808
+ relatedTarget !== getPreviouslyFocusedElement()) {
809
+ preventReturnFocusRef.current = true;
810
+ onOpenChange(false, event, "focus-out");
811
+ }
812
+ });
813
+ }
814
+ if (floating && isHTMLElement(domReference)) {
815
+ domReference.addEventListener("focusout", handleFocusOutside);
816
+ domReference.addEventListener("pointerdown", handlePointerDown);
817
+ floating.addEventListener("focusout", handleFocusOutside);
818
+ return () => {
819
+ domReference.removeEventListener("focusout", handleFocusOutside);
820
+ domReference.removeEventListener("pointerdown", handlePointerDown);
821
+ floating.removeEventListener("focusout", handleFocusOutside);
822
+ };
823
+ }
824
+ }, [disabled, domReference, floating, floatingFocusElement, modal, nodeId, tree, portalContext, onOpenChange, closeOnFocusOut, restoreFocus, getTabbableContent, isUntrappedTypeableCombobox]);
825
+ const beforeGuardRef = React.useRef(null);
826
+ const afterGuardRef = React.useRef(null);
827
+ const mergedBeforeGuardRef = useMergeRefs([beforeGuardRef, portalContext == null ? void 0 : portalContext.beforeInsideRef]);
828
+ const mergedAfterGuardRef = useMergeRefs([afterGuardRef, portalContext == null ? void 0 : portalContext.afterInsideRef]);
829
+ React.useEffect(() => {
830
+ var _portalContext$portal;
831
+ if (disabled) return;
832
+ if (!floating) return;
833
+ const portalNodes = Array.from((portalContext == null || (_portalContext$portal = portalContext.portalNode) == null ? void 0 : _portalContext$portal.querySelectorAll("[" + createAttribute("portal") + "]")) || []);
834
+ const ancestorFloatingNodes = tree && !modal ? getAncestors(tree == null ? void 0 : tree.nodesRef.current, nodeId).map((node) => {
835
+ var _node$context6;
836
+ return (_node$context6 = node.context) == null ? void 0 : _node$context6.elements.floating;
837
+ }) : [];
838
+ const insideElements = [floating, ...portalNodes, ...ancestorFloatingNodes, startDismissButtonRef.current, endDismissButtonRef.current, beforeGuardRef.current, afterGuardRef.current, portalContext == null ? void 0 : portalContext.beforeOutsideRef.current, portalContext == null ? void 0 : portalContext.afterOutsideRef.current, orderRef.current.includes("reference") || isUntrappedTypeableCombobox ? domReference : null].filter((x) => x != null);
839
+ const cleanup = modal || isUntrappedTypeableCombobox ? markOthers(insideElements, !useInert, useInert) : markOthers(insideElements);
840
+ return () => {
841
+ cleanup();
842
+ };
843
+ }, [disabled, domReference, floating, modal, orderRef, portalContext, isUntrappedTypeableCombobox, guards, useInert, tree, nodeId]);
844
+ index(() => {
845
+ if (disabled || !isHTMLElement(floatingFocusElement)) return;
846
+ const doc = getDocument(floatingFocusElement);
847
+ const previouslyFocusedElement = activeElement(doc);
848
+ queueMicrotask(() => {
849
+ const focusableElements = getTabbableElements(floatingFocusElement);
850
+ const initialFocusValue = initialFocusRef.current;
851
+ const elToFocus = (typeof initialFocusValue === "number" ? focusableElements[initialFocusValue] : initialFocusValue.current) || floatingFocusElement;
852
+ const focusAlreadyInsideFloatingEl = contains(floatingFocusElement, previouslyFocusedElement);
853
+ if (!ignoreInitialFocus && !focusAlreadyInsideFloatingEl && open) {
854
+ enqueueFocus(elToFocus, {
855
+ preventScroll: elToFocus === floatingFocusElement
856
+ });
11
857
  }
12
- return len === -1;
858
+ });
859
+ }, [disabled, open, floatingFocusElement, ignoreInitialFocus, getTabbableElements, initialFocusRef]);
860
+ index(() => {
861
+ if (disabled || !floatingFocusElement) return;
862
+ let preventReturnFocusScroll = false;
863
+ const doc = getDocument(floatingFocusElement);
864
+ const previouslyFocusedElement = activeElement(doc);
865
+ const contextData = dataRef.current;
866
+ let openEvent = contextData.openEvent;
867
+ addPreviouslyFocusedElement(previouslyFocusedElement);
868
+ function onOpenChange2(_ref) {
869
+ let {
870
+ open: open2,
871
+ reason,
872
+ event,
873
+ nested
874
+ } = _ref;
875
+ if (open2) {
876
+ openEvent = event;
877
+ }
878
+ if (reason === "escape-key" && refs.domReference.current) {
879
+ addPreviouslyFocusedElement(refs.domReference.current);
880
+ }
881
+ if (["hover", "safe-polygon"].includes(reason) && event.type === "mouseleave") {
882
+ preventReturnFocusRef.current = true;
883
+ }
884
+ if (reason !== "outside-press") return;
885
+ if (nested) {
886
+ preventReturnFocusRef.current = false;
887
+ preventReturnFocusScroll = true;
888
+ } else {
889
+ preventReturnFocusRef.current = !(isVirtualClick(event) || isVirtualPointerEvent(event));
890
+ }
891
+ }
892
+ events.on("openchange", onOpenChange2);
893
+ const fallbackEl = doc.createElement("span");
894
+ fallbackEl.setAttribute("tabindex", "-1");
895
+ fallbackEl.setAttribute("aria-hidden", "true");
896
+ Object.assign(fallbackEl.style, HIDDEN_STYLES);
897
+ if (isInsidePortal && domReference) {
898
+ domReference.insertAdjacentElement("afterend", fallbackEl);
13
899
  }
14
- if (!ctor || typeof foo === "object") {
15
- len = 0;
16
- for (ctor in foo) {
17
- if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
18
- if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
900
+ function getReturnElement() {
901
+ if (typeof returnFocusRef.current === "boolean") {
902
+ return getPreviouslyFocusedElement() || fallbackEl;
19
903
  }
20
- return Object.keys(bar).length === len;
904
+ return returnFocusRef.current.current || fallbackEl;
21
905
  }
906
+ return () => {
907
+ events.off("openchange", onOpenChange2);
908
+ const activeEl = activeElement(doc);
909
+ const isFocusInsideFloatingTree = contains(floating, activeEl) || tree && getChildren(tree.nodesRef.current, nodeId).some((node) => {
910
+ var _node$context7;
911
+ return contains((_node$context7 = node.context) == null ? void 0 : _node$context7.elements.floating, activeEl);
912
+ });
913
+ const shouldFocusReference = isFocusInsideFloatingTree || openEvent && ["click", "mousedown"].includes(openEvent.type);
914
+ if (shouldFocusReference && refs.domReference.current) {
915
+ addPreviouslyFocusedElement(refs.domReference.current);
916
+ }
917
+ const returnElement = getReturnElement();
918
+ queueMicrotask(() => {
919
+ const tabbableReturnElement = getFirstTabbableElement(returnElement);
920
+ if (
921
+ // eslint-disable-next-line react-hooks/exhaustive-deps
922
+ returnFocusRef.current && !preventReturnFocusRef.current && isHTMLElement(tabbableReturnElement) && // If the focus moved somewhere else after mount, avoid returning focus
923
+ // since it likely entered a different element which should be
924
+ // respected: https://github.com/floating-ui/floating-ui/issues/2607
925
+ (tabbableReturnElement !== activeEl && activeEl !== doc.body ? isFocusInsideFloatingTree : true)
926
+ ) {
927
+ tabbableReturnElement.focus({
928
+ preventScroll: preventReturnFocusScroll
929
+ });
930
+ }
931
+ fallbackEl.remove();
932
+ });
933
+ };
934
+ }, [disabled, floating, floatingFocusElement, returnFocusRef, dataRef, refs, events, tree, nodeId, isInsidePortal, domReference]);
935
+ React.useEffect(() => {
936
+ queueMicrotask(() => {
937
+ preventReturnFocusRef.current = false;
938
+ });
939
+ }, [disabled]);
940
+ index(() => {
941
+ if (disabled) return;
942
+ if (!portalContext) return;
943
+ portalContext.setFocusManagerState({
944
+ modal,
945
+ closeOnFocusOut,
946
+ open,
947
+ onOpenChange,
948
+ refs
949
+ });
950
+ return () => {
951
+ portalContext.setFocusManagerState(null);
952
+ };
953
+ }, [disabled, portalContext, modal, open, onOpenChange, refs, closeOnFocusOut]);
954
+ index(() => {
955
+ if (disabled) return;
956
+ if (!floatingFocusElement) return;
957
+ if (typeof MutationObserver !== "function") return;
958
+ if (ignoreInitialFocus) return;
959
+ const handleMutation = () => {
960
+ const tabIndex = floatingFocusElement.getAttribute("tabindex");
961
+ const tabbableContent = getTabbableContent();
962
+ const activeEl = activeElement(getDocument(floating));
963
+ const tabbableIndex = tabbableContent.indexOf(activeEl);
964
+ if (tabbableIndex !== -1) {
965
+ tabbableIndexRef.current = tabbableIndex;
966
+ }
967
+ if (orderRef.current.includes("floating") || activeEl !== refs.domReference.current && tabbableContent.length === 0) {
968
+ if (tabIndex !== "0") {
969
+ floatingFocusElement.setAttribute("tabindex", "0");
970
+ }
971
+ } else if (tabIndex !== "-1") {
972
+ floatingFocusElement.setAttribute("tabindex", "-1");
973
+ }
974
+ };
975
+ handleMutation();
976
+ const observer = new MutationObserver(handleMutation);
977
+ observer.observe(floatingFocusElement, {
978
+ childList: true,
979
+ subtree: true,
980
+ attributes: true
981
+ });
982
+ return () => {
983
+ observer.disconnect();
984
+ };
985
+ }, [disabled, floating, floatingFocusElement, refs, orderRef, getTabbableContent, ignoreInitialFocus]);
986
+ function renderDismissButton(location) {
987
+ if (disabled || !visuallyHiddenDismiss || !modal) {
988
+ return null;
989
+ }
990
+ return /* @__PURE__ */ React.createElement(VisuallyHiddenDismiss, {
991
+ ref: location === "start" ? startDismissButtonRef : endDismissButtonRef,
992
+ onClick: (event) => onOpenChange(false, event.nativeEvent)
993
+ }, typeof visuallyHiddenDismiss === "string" ? visuallyHiddenDismiss : "Dismiss");
22
994
  }
23
- return foo !== foo && bar !== bar;
995
+ const shouldRenderGuards = !disabled && guards && (modal ? !isUntrappedTypeableCombobox : true) && (isInsidePortal || modal);
996
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, shouldRenderGuards && /* @__PURE__ */ React.createElement(FocusGuard, {
997
+ "data-type": "inside",
998
+ ref: mergedBeforeGuardRef,
999
+ onFocus: (event) => {
1000
+ if (modal) {
1001
+ const els = getTabbableElements();
1002
+ enqueueFocus(order[0] === "reference" ? els[0] : els[els.length - 1]);
1003
+ } else if (portalContext != null && portalContext.preserveTabOrder && portalContext.portalNode) {
1004
+ preventReturnFocusRef.current = false;
1005
+ if (isOutsideEvent(event, portalContext.portalNode)) {
1006
+ const nextTabbable = getNextTabbable() || domReference;
1007
+ nextTabbable == null || nextTabbable.focus();
1008
+ } else {
1009
+ var _portalContext$before;
1010
+ (_portalContext$before = portalContext.beforeOutsideRef.current) == null || _portalContext$before.focus();
1011
+ }
1012
+ }
1013
+ }
1014
+ }), !isUntrappedTypeableCombobox && renderDismissButton("start"), children, renderDismissButton("end"), shouldRenderGuards && /* @__PURE__ */ React.createElement(FocusGuard, {
1015
+ "data-type": "inside",
1016
+ ref: mergedAfterGuardRef,
1017
+ onFocus: (event) => {
1018
+ if (modal) {
1019
+ enqueueFocus(getTabbableElements()[0]);
1020
+ } else if (portalContext != null && portalContext.preserveTabOrder && portalContext.portalNode) {
1021
+ if (closeOnFocusOut) {
1022
+ preventReturnFocusRef.current = true;
1023
+ }
1024
+ if (isOutsideEvent(event, portalContext.portalNode)) {
1025
+ const prevTabbable = getPreviousTabbable() || domReference;
1026
+ prevTabbable == null || prevTabbable.focus();
1027
+ } else {
1028
+ var _portalContext$afterO;
1029
+ (_portalContext$afterO = portalContext.afterOutsideRef.current) == null || _portalContext$afterO.focus();
1030
+ }
1031
+ }
1032
+ }
1033
+ }));
1034
+ }
1035
+ const bubbleHandlerKeys = {
1036
+ pointerdown: "onPointerDown",
1037
+ mousedown: "onMouseDown",
1038
+ click: "onClick"
1039
+ };
1040
+ const captureHandlerKeys = {
1041
+ pointerdown: "onPointerDownCapture",
1042
+ mousedown: "onMouseDownCapture",
1043
+ click: "onClickCapture"
1044
+ };
1045
+ const normalizeProp = (normalizable) => {
1046
+ var _normalizable$escapeK, _normalizable$outside;
1047
+ return {
1048
+ escapeKey: typeof normalizable === "boolean" ? normalizable : (_normalizable$escapeK = normalizable == null ? void 0 : normalizable.escapeKey) != null ? _normalizable$escapeK : false,
1049
+ outsidePress: typeof normalizable === "boolean" ? normalizable : (_normalizable$outside = normalizable == null ? void 0 : normalizable.outsidePress) != null ? _normalizable$outside : true
1050
+ };
1051
+ };
1052
+ function useDismiss(context, props) {
1053
+ if (props === void 0) {
1054
+ props = {};
1055
+ }
1056
+ const {
1057
+ open,
1058
+ onOpenChange,
1059
+ elements,
1060
+ dataRef
1061
+ } = context;
1062
+ const {
1063
+ enabled = true,
1064
+ escapeKey = true,
1065
+ outsidePress: unstable_outsidePress = true,
1066
+ outsidePressEvent = "pointerdown",
1067
+ referencePress = false,
1068
+ referencePressEvent = "pointerdown",
1069
+ ancestorScroll = false,
1070
+ bubbles,
1071
+ capture
1072
+ } = props;
1073
+ const tree = useFloatingTree();
1074
+ const outsidePressFn = useEffectEvent(typeof unstable_outsidePress === "function" ? unstable_outsidePress : () => false);
1075
+ const outsidePress = typeof unstable_outsidePress === "function" ? outsidePressFn : unstable_outsidePress;
1076
+ const insideReactTreeRef = React.useRef(false);
1077
+ const endedOrStartedInsideRef = React.useRef(false);
1078
+ const {
1079
+ escapeKey: escapeKeyBubbles,
1080
+ outsidePress: outsidePressBubbles
1081
+ } = normalizeProp(bubbles);
1082
+ const {
1083
+ escapeKey: escapeKeyCapture,
1084
+ outsidePress: outsidePressCapture
1085
+ } = normalizeProp(capture);
1086
+ const isComposingRef = React.useRef(false);
1087
+ const closeOnEscapeKeyDown = useEffectEvent((event) => {
1088
+ var _dataRef$current$floa;
1089
+ if (!open || !enabled || !escapeKey || event.key !== "Escape") {
1090
+ return;
1091
+ }
1092
+ if (isComposingRef.current) {
1093
+ return;
1094
+ }
1095
+ const nodeId = (_dataRef$current$floa = dataRef.current.floatingContext) == null ? void 0 : _dataRef$current$floa.nodeId;
1096
+ const children = tree ? getChildren(tree.nodesRef.current, nodeId) : [];
1097
+ if (!escapeKeyBubbles) {
1098
+ event.stopPropagation();
1099
+ if (children.length > 0) {
1100
+ let shouldDismiss = true;
1101
+ children.forEach((child) => {
1102
+ var _child$context;
1103
+ if ((_child$context = child.context) != null && _child$context.open && !child.context.dataRef.current.__escapeKeyBubbles) {
1104
+ shouldDismiss = false;
1105
+ return;
1106
+ }
1107
+ });
1108
+ if (!shouldDismiss) {
1109
+ return;
1110
+ }
1111
+ }
1112
+ }
1113
+ onOpenChange(false, isReactEvent(event) ? event.nativeEvent : event, "escape-key");
1114
+ });
1115
+ const closeOnEscapeKeyDownCapture = useEffectEvent((event) => {
1116
+ var _getTarget2;
1117
+ const callback = () => {
1118
+ var _getTarget;
1119
+ closeOnEscapeKeyDown(event);
1120
+ (_getTarget = getTarget(event)) == null || _getTarget.removeEventListener("keydown", callback);
1121
+ };
1122
+ (_getTarget2 = getTarget(event)) == null || _getTarget2.addEventListener("keydown", callback);
1123
+ });
1124
+ const closeOnPressOutside = useEffectEvent((event) => {
1125
+ var _dataRef$current$floa2;
1126
+ const insideReactTree = insideReactTreeRef.current;
1127
+ insideReactTreeRef.current = false;
1128
+ const endedOrStartedInside = endedOrStartedInsideRef.current;
1129
+ endedOrStartedInsideRef.current = false;
1130
+ if (outsidePressEvent === "click" && endedOrStartedInside) {
1131
+ return;
1132
+ }
1133
+ if (insideReactTree) {
1134
+ return;
1135
+ }
1136
+ if (typeof outsidePress === "function" && !outsidePress(event)) {
1137
+ return;
1138
+ }
1139
+ const target = getTarget(event);
1140
+ const inertSelector = "[" + createAttribute("inert") + "]";
1141
+ const markers = getDocument(elements.floating).querySelectorAll(inertSelector);
1142
+ let targetRootAncestor = isElement(target) ? target : null;
1143
+ while (targetRootAncestor && !isLastTraversableNode(targetRootAncestor)) {
1144
+ const nextParent = getParentNode(targetRootAncestor);
1145
+ if (isLastTraversableNode(nextParent) || !isElement(nextParent)) {
1146
+ break;
1147
+ }
1148
+ targetRootAncestor = nextParent;
1149
+ }
1150
+ if (markers.length && isElement(target) && !isRootElement(target) && // Clicked on a direct ancestor (e.g. FloatingOverlay).
1151
+ !contains(target, elements.floating) && // If the target root element contains none of the markers, then the
1152
+ // element was injected after the floating element rendered.
1153
+ Array.from(markers).every((marker) => !contains(targetRootAncestor, marker))) {
1154
+ return;
1155
+ }
1156
+ if (isHTMLElement(target) && floating) {
1157
+ const lastTraversableNode = isLastTraversableNode(target);
1158
+ const style = getComputedStyle(target);
1159
+ const scrollRe = /auto|scroll/;
1160
+ const isScrollableX = lastTraversableNode || scrollRe.test(style.overflowX);
1161
+ const isScrollableY = lastTraversableNode || scrollRe.test(style.overflowY);
1162
+ const canScrollX = isScrollableX && target.clientWidth > 0 && target.scrollWidth > target.clientWidth;
1163
+ const canScrollY = isScrollableY && target.clientHeight > 0 && target.scrollHeight > target.clientHeight;
1164
+ const isRTL = style.direction === "rtl";
1165
+ const pressedVerticalScrollbar = canScrollY && (isRTL ? event.offsetX <= target.offsetWidth - target.clientWidth : event.offsetX > target.clientWidth);
1166
+ const pressedHorizontalScrollbar = canScrollX && event.offsetY > target.clientHeight;
1167
+ if (pressedVerticalScrollbar || pressedHorizontalScrollbar) {
1168
+ return;
1169
+ }
1170
+ }
1171
+ const nodeId = (_dataRef$current$floa2 = dataRef.current.floatingContext) == null ? void 0 : _dataRef$current$floa2.nodeId;
1172
+ const targetIsInsideChildren = tree && getChildren(tree.nodesRef.current, nodeId).some((node) => {
1173
+ var _node$context;
1174
+ return isEventTargetWithin(event, (_node$context = node.context) == null ? void 0 : _node$context.elements.floating);
1175
+ });
1176
+ if (isEventTargetWithin(event, elements.floating) || isEventTargetWithin(event, elements.domReference) || targetIsInsideChildren) {
1177
+ return;
1178
+ }
1179
+ const children = tree ? getChildren(tree.nodesRef.current, nodeId) : [];
1180
+ if (children.length > 0) {
1181
+ let shouldDismiss = true;
1182
+ children.forEach((child) => {
1183
+ var _child$context2;
1184
+ if ((_child$context2 = child.context) != null && _child$context2.open && !child.context.dataRef.current.__outsidePressBubbles) {
1185
+ shouldDismiss = false;
1186
+ return;
1187
+ }
1188
+ });
1189
+ if (!shouldDismiss) {
1190
+ return;
1191
+ }
1192
+ }
1193
+ onOpenChange(false, event, "outside-press");
1194
+ });
1195
+ const closeOnPressOutsideCapture = useEffectEvent((event) => {
1196
+ var _getTarget4;
1197
+ const callback = () => {
1198
+ var _getTarget3;
1199
+ closeOnPressOutside(event);
1200
+ (_getTarget3 = getTarget(event)) == null || _getTarget3.removeEventListener(outsidePressEvent, callback);
1201
+ };
1202
+ (_getTarget4 = getTarget(event)) == null || _getTarget4.addEventListener(outsidePressEvent, callback);
1203
+ });
1204
+ React.useEffect(() => {
1205
+ if (!open || !enabled) {
1206
+ return;
1207
+ }
1208
+ dataRef.current.__escapeKeyBubbles = escapeKeyBubbles;
1209
+ dataRef.current.__outsidePressBubbles = outsidePressBubbles;
1210
+ let compositionTimeout = -1;
1211
+ function onScroll(event) {
1212
+ onOpenChange(false, event, "ancestor-scroll");
1213
+ }
1214
+ function handleCompositionStart() {
1215
+ window.clearTimeout(compositionTimeout);
1216
+ isComposingRef.current = true;
1217
+ }
1218
+ function handleCompositionEnd() {
1219
+ compositionTimeout = window.setTimeout(
1220
+ () => {
1221
+ isComposingRef.current = false;
1222
+ },
1223
+ // 0ms or 1ms don't work in Safari. 5ms appears to consistently work.
1224
+ // Only apply to WebKit for the test to remain 0ms.
1225
+ isWebKit() ? 5 : 0
1226
+ );
1227
+ }
1228
+ const doc = getDocument(elements.floating);
1229
+ if (escapeKey) {
1230
+ doc.addEventListener("keydown", escapeKeyCapture ? closeOnEscapeKeyDownCapture : closeOnEscapeKeyDown, escapeKeyCapture);
1231
+ doc.addEventListener("compositionstart", handleCompositionStart);
1232
+ doc.addEventListener("compositionend", handleCompositionEnd);
1233
+ }
1234
+ outsidePress && doc.addEventListener(outsidePressEvent, outsidePressCapture ? closeOnPressOutsideCapture : closeOnPressOutside, outsidePressCapture);
1235
+ let ancestors = [];
1236
+ if (ancestorScroll) {
1237
+ if (isElement(elements.domReference)) {
1238
+ ancestors = getOverflowAncestors(elements.domReference);
1239
+ }
1240
+ if (isElement(elements.floating)) {
1241
+ ancestors = ancestors.concat(getOverflowAncestors(elements.floating));
1242
+ }
1243
+ if (!isElement(elements.reference) && elements.reference && elements.reference.contextElement) {
1244
+ ancestors = ancestors.concat(getOverflowAncestors(elements.reference.contextElement));
1245
+ }
1246
+ }
1247
+ ancestors = ancestors.filter((ancestor) => {
1248
+ var _doc$defaultView;
1249
+ return ancestor !== ((_doc$defaultView = doc.defaultView) == null ? void 0 : _doc$defaultView.visualViewport);
1250
+ });
1251
+ ancestors.forEach((ancestor) => {
1252
+ ancestor.addEventListener("scroll", onScroll, {
1253
+ passive: true
1254
+ });
1255
+ });
1256
+ return () => {
1257
+ if (escapeKey) {
1258
+ doc.removeEventListener("keydown", escapeKeyCapture ? closeOnEscapeKeyDownCapture : closeOnEscapeKeyDown, escapeKeyCapture);
1259
+ doc.removeEventListener("compositionstart", handleCompositionStart);
1260
+ doc.removeEventListener("compositionend", handleCompositionEnd);
1261
+ }
1262
+ outsidePress && doc.removeEventListener(outsidePressEvent, outsidePressCapture ? closeOnPressOutsideCapture : closeOnPressOutside, outsidePressCapture);
1263
+ ancestors.forEach((ancestor) => {
1264
+ ancestor.removeEventListener("scroll", onScroll);
1265
+ });
1266
+ window.clearTimeout(compositionTimeout);
1267
+ };
1268
+ }, [dataRef, elements, escapeKey, outsidePress, outsidePressEvent, open, onOpenChange, ancestorScroll, enabled, escapeKeyBubbles, outsidePressBubbles, closeOnEscapeKeyDown, escapeKeyCapture, closeOnEscapeKeyDownCapture, closeOnPressOutside, outsidePressCapture, closeOnPressOutsideCapture]);
1269
+ React.useEffect(() => {
1270
+ insideReactTreeRef.current = false;
1271
+ }, [outsidePress, outsidePressEvent]);
1272
+ const reference = React.useMemo(() => ({
1273
+ onKeyDown: closeOnEscapeKeyDown,
1274
+ ...referencePress && {
1275
+ [bubbleHandlerKeys[referencePressEvent]]: (event) => {
1276
+ onOpenChange(false, event.nativeEvent, "reference-press");
1277
+ },
1278
+ ...referencePressEvent !== "click" && {
1279
+ onClick(event) {
1280
+ onOpenChange(false, event.nativeEvent, "reference-press");
1281
+ }
1282
+ }
1283
+ }
1284
+ }), [closeOnEscapeKeyDown, onOpenChange, referencePress, referencePressEvent]);
1285
+ const floating = React.useMemo(() => ({
1286
+ onKeyDown: closeOnEscapeKeyDown,
1287
+ onMouseDown() {
1288
+ endedOrStartedInsideRef.current = true;
1289
+ },
1290
+ onMouseUp() {
1291
+ endedOrStartedInsideRef.current = true;
1292
+ },
1293
+ [captureHandlerKeys[outsidePressEvent]]: () => {
1294
+ insideReactTreeRef.current = true;
1295
+ }
1296
+ }), [closeOnEscapeKeyDown, outsidePressEvent]);
1297
+ return React.useMemo(() => enabled ? {
1298
+ reference,
1299
+ floating
1300
+ } : {}, [enabled, reference, floating]);
1301
+ }
1302
+ function useFloatingRootContext(options) {
1303
+ const {
1304
+ open = false,
1305
+ onOpenChange: onOpenChangeProp,
1306
+ elements: elementsProp
1307
+ } = options;
1308
+ const floatingId = useId();
1309
+ const dataRef = React.useRef({});
1310
+ const [events] = React.useState(() => createPubSub());
1311
+ const nested = useFloatingParentNodeId() != null;
1312
+ if (process.env.NODE_ENV !== "production") {
1313
+ const optionDomReference = elementsProp.reference;
1314
+ if (optionDomReference && !isElement(optionDomReference)) {
1315
+ error("Cannot pass a virtual element to the `elements.reference` option,", "as it must be a real DOM element. Use `refs.setPositionReference()`", "instead.");
1316
+ }
1317
+ }
1318
+ const [positionReference, setPositionReference] = React.useState(elementsProp.reference);
1319
+ const onOpenChange = useEffectEvent((open2, event, reason) => {
1320
+ dataRef.current.openEvent = open2 ? event : void 0;
1321
+ events.emit("openchange", {
1322
+ open: open2,
1323
+ event,
1324
+ reason,
1325
+ nested
1326
+ });
1327
+ onOpenChangeProp == null || onOpenChangeProp(open2, event, reason);
1328
+ });
1329
+ const refs = React.useMemo(() => ({
1330
+ setPositionReference
1331
+ }), []);
1332
+ const elements = React.useMemo(() => ({
1333
+ reference: positionReference || elementsProp.reference || null,
1334
+ floating: elementsProp.floating || null,
1335
+ domReference: elementsProp.reference
1336
+ }), [positionReference, elementsProp.reference, elementsProp.floating]);
1337
+ return React.useMemo(() => ({
1338
+ dataRef,
1339
+ open,
1340
+ onOpenChange,
1341
+ elements,
1342
+ events,
1343
+ floatingId,
1344
+ refs
1345
+ }), [open, onOpenChange, elements, events, floatingId, refs]);
1346
+ }
1347
+ function useFloating(options) {
1348
+ if (options === void 0) {
1349
+ options = {};
1350
+ }
1351
+ const {
1352
+ nodeId
1353
+ } = options;
1354
+ const internalRootContext = useFloatingRootContext({
1355
+ ...options,
1356
+ elements: {
1357
+ reference: null,
1358
+ floating: null,
1359
+ ...options.elements
1360
+ }
1361
+ });
1362
+ const rootContext = options.rootContext || internalRootContext;
1363
+ const computedElements = rootContext.elements;
1364
+ const [_domReference, setDomReference] = React.useState(null);
1365
+ const [positionReference, _setPositionReference] = React.useState(null);
1366
+ const optionDomReference = computedElements == null ? void 0 : computedElements.domReference;
1367
+ const domReference = optionDomReference || _domReference;
1368
+ const domReferenceRef = React.useRef(null);
1369
+ const tree = useFloatingTree();
1370
+ index(() => {
1371
+ if (domReference) {
1372
+ domReferenceRef.current = domReference;
1373
+ }
1374
+ }, [domReference]);
1375
+ const position = useFloating$1({
1376
+ ...options,
1377
+ elements: {
1378
+ ...computedElements,
1379
+ ...positionReference && {
1380
+ reference: positionReference
1381
+ }
1382
+ }
1383
+ });
1384
+ const setPositionReference = React.useCallback((node) => {
1385
+ const computedPositionReference = isElement(node) ? {
1386
+ getBoundingClientRect: () => node.getBoundingClientRect(),
1387
+ contextElement: node
1388
+ } : node;
1389
+ _setPositionReference(computedPositionReference);
1390
+ position.refs.setReference(computedPositionReference);
1391
+ }, [position.refs]);
1392
+ const setReference = React.useCallback((node) => {
1393
+ if (isElement(node) || node === null) {
1394
+ domReferenceRef.current = node;
1395
+ setDomReference(node);
1396
+ }
1397
+ if (isElement(position.refs.reference.current) || position.refs.reference.current === null || // Don't allow setting virtual elements using the old technique back to
1398
+ // `null` to support `positionReference` + an unstable `reference`
1399
+ // callback ref.
1400
+ node !== null && !isElement(node)) {
1401
+ position.refs.setReference(node);
1402
+ }
1403
+ }, [position.refs]);
1404
+ const refs = React.useMemo(() => ({
1405
+ ...position.refs,
1406
+ setReference,
1407
+ setPositionReference,
1408
+ domReference: domReferenceRef
1409
+ }), [position.refs, setReference, setPositionReference]);
1410
+ const elements = React.useMemo(() => ({
1411
+ ...position.elements,
1412
+ domReference
1413
+ }), [position.elements, domReference]);
1414
+ const context = React.useMemo(() => ({
1415
+ ...position,
1416
+ ...rootContext,
1417
+ refs,
1418
+ elements,
1419
+ nodeId
1420
+ }), [position, refs, elements, nodeId, rootContext]);
1421
+ index(() => {
1422
+ rootContext.dataRef.current.floatingContext = context;
1423
+ const node = tree == null ? void 0 : tree.nodesRef.current.find((node2) => node2.id === nodeId);
1424
+ if (node) {
1425
+ node.context = context;
1426
+ }
1427
+ });
1428
+ return React.useMemo(() => ({
1429
+ ...position,
1430
+ context,
1431
+ refs,
1432
+ elements
1433
+ }), [position, refs, elements, context]);
1434
+ }
1435
+ const ACTIVE_KEY = "active";
1436
+ const SELECTED_KEY = "selected";
1437
+ function mergeProps(userProps, propsList, elementKey) {
1438
+ const map = /* @__PURE__ */ new Map();
1439
+ const isItem = elementKey === "item";
1440
+ let domUserProps = userProps;
1441
+ if (isItem && userProps) {
1442
+ const {
1443
+ [ACTIVE_KEY]: _,
1444
+ [SELECTED_KEY]: __,
1445
+ ...validProps
1446
+ } = userProps;
1447
+ domUserProps = validProps;
1448
+ }
1449
+ return {
1450
+ ...elementKey === "floating" && {
1451
+ tabIndex: -1,
1452
+ [FOCUSABLE_ATTRIBUTE]: ""
1453
+ },
1454
+ ...domUserProps,
1455
+ ...propsList.map((value) => {
1456
+ const propsOrGetProps = value ? value[elementKey] : null;
1457
+ if (typeof propsOrGetProps === "function") {
1458
+ return userProps ? propsOrGetProps(userProps) : null;
1459
+ }
1460
+ return propsOrGetProps;
1461
+ }).concat(userProps).reduce((acc, props) => {
1462
+ if (!props) {
1463
+ return acc;
1464
+ }
1465
+ Object.entries(props).forEach((_ref) => {
1466
+ let [key, value] = _ref;
1467
+ if (isItem && [ACTIVE_KEY, SELECTED_KEY].includes(key)) {
1468
+ return;
1469
+ }
1470
+ if (key.indexOf("on") === 0) {
1471
+ if (!map.has(key)) {
1472
+ map.set(key, []);
1473
+ }
1474
+ if (typeof value === "function") {
1475
+ var _map$get;
1476
+ (_map$get = map.get(key)) == null || _map$get.push(value);
1477
+ acc[key] = function() {
1478
+ var _map$get2;
1479
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1480
+ args[_key] = arguments[_key];
1481
+ }
1482
+ return (_map$get2 = map.get(key)) == null ? void 0 : _map$get2.map((fn) => fn(...args)).find((val) => val !== void 0);
1483
+ };
1484
+ }
1485
+ } else {
1486
+ acc[key] = value;
1487
+ }
1488
+ });
1489
+ return acc;
1490
+ }, {})
1491
+ };
1492
+ }
1493
+ function useInteractions(propsList) {
1494
+ if (propsList === void 0) {
1495
+ propsList = [];
1496
+ }
1497
+ const referenceDeps = propsList.map((key) => key == null ? void 0 : key.reference);
1498
+ const floatingDeps = propsList.map((key) => key == null ? void 0 : key.floating);
1499
+ const itemDeps = propsList.map((key) => key == null ? void 0 : key.item);
1500
+ const getReferenceProps = React.useCallback(
1501
+ (userProps) => mergeProps(userProps, propsList, "reference"),
1502
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1503
+ referenceDeps
1504
+ );
1505
+ const getFloatingProps = React.useCallback(
1506
+ (userProps) => mergeProps(userProps, propsList, "floating"),
1507
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1508
+ floatingDeps
1509
+ );
1510
+ const getItemProps = React.useCallback(
1511
+ (userProps) => mergeProps(userProps, propsList, "item"),
1512
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1513
+ itemDeps
1514
+ );
1515
+ return React.useMemo(() => ({
1516
+ getReferenceProps,
1517
+ getFloatingProps,
1518
+ getItemProps
1519
+ }), [getReferenceProps, getFloatingProps, getItemProps]);
1520
+ }
1521
+ const componentRoleToAriaRoleMap = /* @__PURE__ */ new Map([["select", "listbox"], ["combobox", "listbox"], ["label", false]]);
1522
+ function useRole(context, props) {
1523
+ var _componentRoleToAriaR;
1524
+ if (props === void 0) {
1525
+ props = {};
1526
+ }
1527
+ const {
1528
+ open,
1529
+ floatingId
1530
+ } = context;
1531
+ const {
1532
+ enabled = true,
1533
+ role = "dialog"
1534
+ } = props;
1535
+ const ariaRole = (_componentRoleToAriaR = componentRoleToAriaRoleMap.get(role)) != null ? _componentRoleToAriaR : role;
1536
+ const referenceId = useId();
1537
+ const parentId = useFloatingParentNodeId();
1538
+ const isNested = parentId != null;
1539
+ const reference = React.useMemo(() => {
1540
+ if (ariaRole === "tooltip" || role === "label") {
1541
+ return {
1542
+ ["aria-" + (role === "label" ? "labelledby" : "describedby")]: open ? floatingId : void 0
1543
+ };
1544
+ }
1545
+ return {
1546
+ "aria-expanded": open ? "true" : "false",
1547
+ "aria-haspopup": ariaRole === "alertdialog" ? "dialog" : ariaRole,
1548
+ "aria-controls": open ? floatingId : void 0,
1549
+ ...ariaRole === "listbox" && {
1550
+ role: "combobox"
1551
+ },
1552
+ ...ariaRole === "menu" && {
1553
+ id: referenceId
1554
+ },
1555
+ ...ariaRole === "menu" && isNested && {
1556
+ role: "menuitem"
1557
+ },
1558
+ ...role === "select" && {
1559
+ "aria-autocomplete": "none"
1560
+ },
1561
+ ...role === "combobox" && {
1562
+ "aria-autocomplete": "list"
1563
+ }
1564
+ };
1565
+ }, [ariaRole, floatingId, isNested, open, referenceId, role]);
1566
+ const floating = React.useMemo(() => {
1567
+ const floatingProps = {
1568
+ id: floatingId,
1569
+ ...ariaRole && {
1570
+ role: ariaRole
1571
+ }
1572
+ };
1573
+ if (ariaRole === "tooltip" || role === "label") {
1574
+ return floatingProps;
1575
+ }
1576
+ return {
1577
+ ...floatingProps,
1578
+ ...ariaRole === "menu" && {
1579
+ "aria-labelledby": referenceId
1580
+ }
1581
+ };
1582
+ }, [ariaRole, floatingId, referenceId, role]);
1583
+ const item = React.useCallback((_ref) => {
1584
+ let {
1585
+ active,
1586
+ selected
1587
+ } = _ref;
1588
+ const commonProps = {
1589
+ role: "option",
1590
+ ...active && {
1591
+ id: floatingId + "-option"
1592
+ }
1593
+ };
1594
+ switch (role) {
1595
+ case "select":
1596
+ return {
1597
+ ...commonProps,
1598
+ "aria-selected": active && selected
1599
+ };
1600
+ case "combobox": {
1601
+ return {
1602
+ ...commonProps,
1603
+ ...active && {
1604
+ "aria-selected": true
1605
+ }
1606
+ };
1607
+ }
1608
+ }
1609
+ return {};
1610
+ }, [floatingId, role]);
1611
+ return React.useMemo(() => enabled ? {
1612
+ reference,
1613
+ floating,
1614
+ item
1615
+ } : {}, [enabled, reference, floating, item]);
24
1616
  }
25
1617
  export {
26
- dequal
1618
+ FloatingArrow,
1619
+ FloatingFocusManager,
1620
+ FloatingPortal,
1621
+ arrow,
1622
+ flip,
1623
+ getOverflowAncestors,
1624
+ inline,
1625
+ offset,
1626
+ shift,
1627
+ useDismiss,
1628
+ useFloating,
1629
+ useFloatingParentNodeId,
1630
+ useFloatingPortalNode,
1631
+ useFloatingRootContext,
1632
+ useFloatingTree,
1633
+ useId,
1634
+ useInteractions,
1635
+ useMergeRefs,
1636
+ useRole
27
1637
  };
28
1638
  //# sourceMappingURL=react-text-annotator.es14.js.map