@teamturing/react-kit 2.11.0 → 2.13.0

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 (28) hide show
  1. package/dist/core/Button/index.d.ts +2 -2
  2. package/dist/core/IconButton/index.d.ts +2 -2
  3. package/dist/core/Overlay/index.d.ts +18 -0
  4. package/dist/core/OverlayPopper/index.d.ts +16 -0
  5. package/dist/hook/useFocusTrap.d.ts +13 -0
  6. package/dist/hook/useFocusZone.d.ts +15 -0
  7. package/dist/index.d.ts +8 -0
  8. package/dist/index.js +2523 -164
  9. package/esm/core/Button/index.js +2 -2
  10. package/esm/core/Dialog/index.js +8 -36
  11. package/esm/core/IconButton/index.js +1 -1
  12. package/esm/core/Overlay/index.js +92 -0
  13. package/esm/core/OverlayPopper/index.js +69 -0
  14. package/esm/hook/useFocusTrap.js +39 -0
  15. package/esm/hook/useFocusZone.js +35 -0
  16. package/esm/index.js +6 -0
  17. package/esm/node_modules/@floating-ui/core/dist/floating-ui.core.js +475 -0
  18. package/esm/node_modules/@floating-ui/dom/dist/floating-ui.dom.js +599 -0
  19. package/esm/node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.js +229 -0
  20. package/esm/node_modules/@floating-ui/utils/dist/floating-ui.utils.js +121 -0
  21. package/esm/node_modules/@floating-ui/utils/dom/dist/floating-ui.utils.dom.js +128 -0
  22. package/esm/node_modules/@primer/behaviors/dist/esm/focus-trap.js +105 -0
  23. package/esm/node_modules/@primer/behaviors/dist/esm/focus-zone.js +436 -0
  24. package/esm/node_modules/@primer/behaviors/dist/esm/polyfills/event-listener-signal.js +38 -0
  25. package/esm/node_modules/@primer/behaviors/dist/esm/utils/iterate-focusable-elements.js +65 -0
  26. package/esm/node_modules/@primer/behaviors/dist/esm/utils/unique-id.js +6 -0
  27. package/esm/node_modules/@primer/behaviors/dist/esm/utils/user-agent.js +9 -0
  28. package/package.json +5 -2
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  var React = require('react');
4
4
  var styled = require('styled-components');
5
+ var ReactDOM = require('react-dom');
5
6
 
6
7
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
8
 
@@ -25,6 +26,7 @@ function _interopNamespace(e) {
25
26
 
26
27
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
27
28
  var styled__default = /*#__PURE__*/_interopDefault(styled);
29
+ var ReactDOM__namespace = /*#__PURE__*/_interopNamespace(ReactDOM);
28
30
 
29
31
  /**
30
32
  * @public
@@ -509,7 +511,7 @@ const getValueAsType = (value, type) => {
509
511
  : value;
510
512
  };
511
513
 
512
- const clamp = (min, max, v) => Math.min(Math.max(v, min), max);
514
+ const clamp$1 = (min, max, v) => Math.min(Math.max(v, min), max);
513
515
 
514
516
  const number = {
515
517
  test: (v) => typeof v === "number",
@@ -518,7 +520,7 @@ const number = {
518
520
  };
519
521
  const alpha = {
520
522
  ...number,
521
- transform: (v) => clamp(0, 1, v),
523
+ transform: (v) => clamp$1(0, 1, v),
522
524
  };
523
525
  const scale = {
524
526
  ...number,
@@ -1215,7 +1217,7 @@ function makeLatestValues(props, context, presenceContext, scrapeMotionValues) {
1215
1217
  return values;
1216
1218
  }
1217
1219
 
1218
- const noop = (any) => any;
1220
+ const noop$1 = (any) => any;
1219
1221
 
1220
1222
  class Queue {
1221
1223
  constructor() {
@@ -1377,7 +1379,7 @@ function createRenderBatcher(scheduleNextBatch, allowKeepAlive) {
1377
1379
  return { schedule, cancel, state, steps };
1378
1380
  }
1379
1381
 
1380
- const { schedule: frame, cancel: cancelFrame, state: frameData, steps, } = createRenderBatcher(typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : noop, true);
1382
+ const { schedule: frame, cancel: cancelFrame, state: frameData, steps, } = createRenderBatcher(typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : noop$1, true);
1381
1383
 
1382
1384
  const svgMotionConfig = {
1383
1385
  useVisualState: makeUseVisualState({
@@ -1627,9 +1629,9 @@ function fireSyntheticPointerEvent(name, handler) {
1627
1629
  class PressGesture extends Feature {
1628
1630
  constructor() {
1629
1631
  super(...arguments);
1630
- this.removeStartListeners = noop;
1631
- this.removeEndListeners = noop;
1632
- this.removeAccessibleListeners = noop;
1632
+ this.removeStartListeners = noop$1;
1633
+ this.removeEndListeners = noop$1;
1634
+ this.removeAccessibleListeners = noop$1;
1633
1635
  this.startPointerPress = (startEvent, startInfo) => {
1634
1636
  this.removeEndListeners();
1635
1637
  if (this.isPressing)
@@ -1895,8 +1897,8 @@ function resolveVariant(visualElement, definition, custom) {
1895
1897
  const optimizedAppearDataId = "framerAppearId";
1896
1898
  const optimizedAppearDataAttribute = "data-" + camelToDash(optimizedAppearDataId);
1897
1899
 
1898
- let warning = noop;
1899
- let invariant = noop;
1900
+ let warning = noop$1;
1901
+ let invariant = noop$1;
1900
1902
  if (process.env.NODE_ENV !== "production") {
1901
1903
  warning = (check, message) => {
1902
1904
  if (!check && typeof console !== "undefined") {
@@ -2022,7 +2024,7 @@ function binarySubdivide(x, lowerBound, upperBound, mX1, mX2) {
2022
2024
  function cubicBezier(mX1, mY1, mX2, mY2) {
2023
2025
  // If this is a linear gradient, return linear easing
2024
2026
  if (mX1 === mY1 && mX2 === mY2)
2025
- return noop;
2027
+ return noop$1;
2026
2028
  const getTForX = (aX) => binarySubdivide(aX, 0, 1, mX1, mX2);
2027
2029
  // If animation is at start/end, return t without easing
2028
2030
  return (t) => t === 0 || t === 1 ? t : calcBezier(getTForX(t), mY1, mY2);
@@ -2055,7 +2057,7 @@ const backInOut = mirrorEasing(backIn);
2055
2057
  const anticipate = (p) => (p *= 2) < 1 ? 0.5 * backIn(p) : 0.5 * (2 - Math.pow(2, -10 * (p - 1)));
2056
2058
 
2057
2059
  const easingLookup = {
2058
- linear: noop,
2060
+ linear: noop$1,
2059
2061
  easeIn,
2060
2062
  easeInOut,
2061
2063
  easeOut,
@@ -2102,7 +2104,7 @@ const splitColor = (aName, bName, cName) => (v) => {
2102
2104
  };
2103
2105
  };
2104
2106
 
2105
- const clampRgbUnit = (v) => clamp(0, 255, v);
2107
+ const clampRgbUnit = (v) => clamp$1(0, 255, v);
2106
2108
  const rgbUnit = {
2107
2109
  ...number,
2108
2110
  transform: (v) => Math.round(clampRgbUnit(v)),
@@ -2303,7 +2305,7 @@ const cssVarTokeniser = {
2303
2305
  regex: cssVariableRegex,
2304
2306
  countKey: "Vars",
2305
2307
  token: "${v}",
2306
- parse: noop,
2308
+ parse: noop$1,
2307
2309
  };
2308
2310
  const colorTokeniser = {
2309
2311
  regex: colorRegex,
@@ -2472,7 +2474,7 @@ function createMixers(output, ease, customMixer) {
2472
2474
  for (let i = 0; i < numMixers; i++) {
2473
2475
  let mixer = mixerFactory(output[i], output[i + 1]);
2474
2476
  if (ease) {
2475
- const easingFunction = Array.isArray(ease) ? ease[i] || noop : ease;
2477
+ const easingFunction = Array.isArray(ease) ? ease[i] || noop$1 : ease;
2476
2478
  mixer = pipe(easingFunction, mixer);
2477
2479
  }
2478
2480
  mixers.push(mixer);
@@ -2526,7 +2528,7 @@ function interpolate(input, output, { clamp: isClamp = true, ease, mixer } = {})
2526
2528
  return mixers[i](progressInRange);
2527
2529
  };
2528
2530
  return isClamp
2529
- ? (v) => interpolator(clamp(input[0], input[inputLength - 1], v))
2531
+ ? (v) => interpolator(clamp$1(input[0], input[inputLength - 1], v))
2530
2532
  : interpolator;
2531
2533
  }
2532
2534
 
@@ -2620,8 +2622,8 @@ function findSpring({ duration = 800, bounce = 0.25, velocity = 0, mass = 1, })
2620
2622
  /**
2621
2623
  * Restrict dampingRatio and duration to within acceptable ranges.
2622
2624
  */
2623
- dampingRatio = clamp(minDamping, maxDamping, dampingRatio);
2624
- duration = clamp(minDuration, maxDuration$1, millisecondsToSeconds(duration));
2625
+ dampingRatio = clamp$1(minDamping, maxDamping, dampingRatio);
2626
+ duration = clamp$1(minDuration, maxDuration$1, millisecondsToSeconds(duration));
2625
2627
  if (dampingRatio < 1) {
2626
2628
  /**
2627
2629
  * Underdamped spring
@@ -3080,7 +3082,7 @@ function animateValue({ autoplay = true, delay = 0, driver = frameloopDriver, ke
3080
3082
  frameGenerator = mirroredGenerator;
3081
3083
  }
3082
3084
  }
3083
- let p = clamp(0, 1, iterationProgress);
3085
+ let p = clamp$1(0, 1, iterationProgress);
3084
3086
  if (currentTime > totalDuration) {
3085
3087
  p = repeatType === "reverse" && iterationIsOdd ? 1 : 0;
3086
3088
  }
@@ -3363,7 +3365,7 @@ function createAcceleratedAnimation(value, valueName, { onUpdate, onComplete, ..
3363
3365
  attachTimeline(timeline) {
3364
3366
  animation.timeline = timeline;
3365
3367
  animation.onfinish = null;
3366
- return noop;
3368
+ return noop$1;
3367
3369
  },
3368
3370
  get time() {
3369
3371
  return millisecondsToSeconds(animation.currentTime || 0);
@@ -3433,15 +3435,15 @@ function createInstantAnimation({ keyframes, delay, onUpdate, onComplete, }) {
3433
3435
  time: 0,
3434
3436
  speed: 1,
3435
3437
  duration: 0,
3436
- play: (noop),
3437
- pause: (noop),
3438
- stop: (noop),
3438
+ play: (noop$1),
3439
+ pause: (noop$1),
3440
+ stop: (noop$1),
3439
3441
  then: (resolve) => {
3440
3442
  resolve();
3441
3443
  return Promise.resolve();
3442
3444
  },
3443
- cancel: (noop),
3444
- complete: (noop),
3445
+ cancel: (noop$1),
3446
+ complete: (noop$1),
3445
3447
  };
3446
3448
  };
3447
3449
  return delay
@@ -5029,7 +5031,7 @@ function calcOrigin(source, target) {
5029
5031
  else if (sourceLength > targetLength) {
5030
5032
  origin = progress(source.min, source.max - targetLength, target.min);
5031
5033
  }
5032
- return clamp(0, 1, origin);
5034
+ return clamp$1(0, 1, origin);
5033
5035
  }
5034
5036
  /**
5035
5037
  * Rebase the calculated viewport constraints relative to the layout.min point.
@@ -5719,8 +5721,8 @@ function getCurrentDirection(offset, lockThreshold = 10) {
5719
5721
  class DragGesture extends Feature {
5720
5722
  constructor(node) {
5721
5723
  super(node);
5722
- this.removeGroupControls = noop;
5723
- this.removeListeners = noop;
5724
+ this.removeGroupControls = noop$1;
5725
+ this.removeListeners = noop$1;
5724
5726
  this.controls = new VisualElementDragControls(node);
5725
5727
  }
5726
5728
  mount() {
@@ -5730,7 +5732,7 @@ class DragGesture extends Feature {
5730
5732
  if (dragControls) {
5731
5733
  this.removeGroupControls = dragControls.subscribe(this.controls);
5732
5734
  }
5733
- this.removeListeners = this.controls.addListeners() || noop;
5735
+ this.removeListeners = this.controls.addListeners() || noop$1;
5734
5736
  }
5735
5737
  unmount() {
5736
5738
  this.removeGroupControls();
@@ -5746,7 +5748,7 @@ const asyncHandler = (handler) => (event, info) => {
5746
5748
  class PanGesture extends Feature {
5747
5749
  constructor() {
5748
5750
  super(...arguments);
5749
- this.removePointerDownListener = noop;
5751
+ this.removePointerDownListener = noop$1;
5750
5752
  }
5751
5753
  onPointerDown(pointerDownEvent) {
5752
5754
  this.session = new PanSession(pointerDownEvent, this.createPanHandlers(), { transformPagePoint: this.node.getTransformPagePoint() });
@@ -6094,7 +6096,7 @@ function getRadius(values, radiusName) {
6094
6096
  // )(p)
6095
6097
  // }
6096
6098
  const easeCrossfadeIn = compress(0, 0.5, circOut);
6097
- const easeCrossfadeOut = compress(0.5, 0.95, noop);
6099
+ const easeCrossfadeOut = compress(0.5, 0.95, noop$1);
6098
6100
  function compress(min, max, easing) {
6099
6101
  return (p) => {
6100
6102
  // Could replace ifs with clamp
@@ -6767,7 +6769,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
6767
6769
  * to leave a flash of incorrectly styled content.
6768
6770
  */
6769
6771
  const now = performance.now();
6770
- frameData.delta = clamp(0, 1000 / 60, now - frameData.timestamp);
6772
+ frameData.delta = clamp$1(0, 1000 / 60, now - frameData.timestamp);
6771
6773
  frameData.timestamp = now;
6772
6774
  frameData.isProcessing = true;
6773
6775
  steps.update.process(frameData);
@@ -7851,7 +7853,7 @@ const userAgentContains = (string) => typeof navigator !== "undefined" &&
7851
7853
  */
7852
7854
  const roundPoint = userAgentContains("applewebkit/") && !userAgentContains("chrome/")
7853
7855
  ? Math.round
7854
- : noop;
7856
+ : noop$1;
7855
7857
  function roundAxis(axis) {
7856
7858
  // Round to the nearest .5 pixels to support subpixel layouts
7857
7859
  axis.min = roundPoint(axis.min);
@@ -8833,7 +8835,7 @@ class DOMVisualElement extends VisualElement {
8833
8835
  }
8834
8836
  }
8835
8837
 
8836
- function getComputedStyle$1(element) {
8838
+ function getComputedStyle$2(element) {
8837
8839
  return window.getComputedStyle(element);
8838
8840
  }
8839
8841
  class HTMLVisualElement extends DOMVisualElement {
@@ -8843,7 +8845,7 @@ class HTMLVisualElement extends DOMVisualElement {
8843
8845
  return defaultType ? defaultType.default || 0 : 0;
8844
8846
  }
8845
8847
  else {
8846
- const computedStyle = getComputedStyle$1(instance);
8848
+ const computedStyle = getComputedStyle$2(instance);
8847
8849
  const value = (isCSSVariableName(key)
8848
8850
  ? computedStyle.getPropertyValue(key)
8849
8851
  : computedStyle[key]) || 0;
@@ -11862,7 +11864,7 @@ const BreadcrumbsItemWrapper = styled__default.default.span`
11862
11864
  }
11863
11865
  }
11864
11866
  `;
11865
- var index$3 = Object.assign(Breadcrumbs, {
11867
+ var index$4 = Object.assign(Breadcrumbs, {
11866
11868
  Item: BreadcrumbsItem
11867
11869
  });
11868
11870
 
@@ -16001,7 +16003,7 @@ const BaseButton = styled__default.default(UnstyledButton)(({
16001
16003
  }
16002
16004
  } : {})
16003
16005
  },
16004
- tertiary: {
16006
+ neutral: {
16005
16007
  'backgroundColor': color['bg/neutral'],
16006
16008
  'color': color['text/neutral'],
16007
16009
  '& svg': {
@@ -16154,7 +16156,7 @@ const BaseSpinner = styled__default.default(Spinner)(variant({
16154
16156
  secondary: {
16155
16157
  color: color['icon/primary']
16156
16158
  },
16157
- tertiary: {
16159
+ neutral: {
16158
16160
  color: color['icon/accent/gray']
16159
16161
  },
16160
16162
  outlined: {
@@ -16440,7 +16442,7 @@ const BaseIconButton = styled__default.default(UnstyledButton)(({
16440
16442
  color: color['icon/disabled']
16441
16443
  } : {})
16442
16444
  },
16443
- 'tertiary': {
16445
+ 'neutral': {
16444
16446
  'backgroundColor': color['bg/neutral'],
16445
16447
  'color': color['icon/accent/gray'],
16446
16448
  '&:hover:not(:disabled)': {
@@ -16543,15 +16545,695 @@ const BaseIconButton = styled__default.default(UnstyledButton)(({
16543
16545
  }
16544
16546
  }));
16545
16547
 
16546
- const MotionView = motion(View);
16548
+ function* iterateFocusableElements(container, options = {}) {
16549
+ var _a, _b;
16550
+ const strict = (_a = options.strict) !== null && _a !== void 0 ? _a : false;
16551
+ const acceptFn = ((_b = options.onlyTabbable) !== null && _b !== void 0 ? _b : false) ? isTabbable : isFocusable;
16552
+ const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
16553
+ acceptNode: node => node instanceof HTMLElement && acceptFn(node, strict) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
16554
+ });
16555
+ let nextNode = null;
16556
+ if (!options.reverse && acceptFn(container, strict)) {
16557
+ yield container;
16558
+ }
16559
+ if (options.reverse) {
16560
+ let lastChild = walker.lastChild();
16561
+ while (lastChild) {
16562
+ nextNode = lastChild;
16563
+ lastChild = walker.lastChild();
16564
+ }
16565
+ } else {
16566
+ nextNode = walker.firstChild();
16567
+ }
16568
+ while (nextNode instanceof HTMLElement) {
16569
+ yield nextNode;
16570
+ nextNode = options.reverse ? walker.previousNode() : walker.nextNode();
16571
+ }
16572
+ if (options.reverse && acceptFn(container, strict)) {
16573
+ yield container;
16574
+ }
16575
+ return undefined;
16576
+ }
16577
+ function getFocusableChild(container, lastChild = false) {
16578
+ return iterateFocusableElements(container, {
16579
+ reverse: lastChild,
16580
+ strict: true,
16581
+ onlyTabbable: true
16582
+ }).next().value;
16583
+ }
16584
+ function isFocusable(elem, strict = false) {
16585
+ const disabledAttrInert = ['BUTTON', 'INPUT', 'SELECT', 'TEXTAREA', 'OPTGROUP', 'OPTION', 'FIELDSET'].includes(elem.tagName) && elem.disabled;
16586
+ const hiddenInert = elem.hidden;
16587
+ const hiddenInputInert = elem instanceof HTMLInputElement && elem.type === 'hidden';
16588
+ const sentinelInert = elem.classList.contains('sentinel');
16589
+ if (disabledAttrInert || hiddenInert || hiddenInputInert || sentinelInert) {
16590
+ return false;
16591
+ }
16592
+ if (strict) {
16593
+ const sizeInert = elem.offsetWidth === 0 || elem.offsetHeight === 0;
16594
+ const visibilityInert = ['hidden', 'collapse'].includes(getComputedStyle(elem).visibility);
16595
+ const clientRectsInert = elem.getClientRects().length === 0;
16596
+ if (sizeInert || visibilityInert || clientRectsInert) {
16597
+ return false;
16598
+ }
16599
+ }
16600
+ if (elem.getAttribute('tabindex') != null) {
16601
+ return true;
16602
+ }
16603
+ if (elem instanceof HTMLAnchorElement && elem.getAttribute('href') == null) {
16604
+ return false;
16605
+ }
16606
+ return elem.tabIndex !== -1;
16607
+ }
16608
+ function isTabbable(elem, strict = false) {
16609
+ return isFocusable(elem, strict) && elem.getAttribute('tabindex') !== '-1';
16610
+ }
16611
+
16612
+ let signalSupported = false;
16613
+ function noop() {}
16614
+ try {
16615
+ const options = Object.create({}, {
16616
+ signal: {
16617
+ get() {
16618
+ signalSupported = true;
16619
+ }
16620
+ }
16621
+ });
16622
+ window.addEventListener('test', noop, options);
16623
+ window.removeEventListener('test', noop, options);
16624
+ } catch (e) {}
16625
+ function featureSupported() {
16626
+ return signalSupported;
16627
+ }
16628
+ function monkeyPatch() {
16629
+ if (typeof window === 'undefined') {
16630
+ return;
16631
+ }
16632
+ const originalAddEventListener = EventTarget.prototype.addEventListener;
16633
+ EventTarget.prototype.addEventListener = function (name, originalCallback, optionsOrCapture) {
16634
+ if (typeof optionsOrCapture === 'object' && 'signal' in optionsOrCapture && optionsOrCapture.signal instanceof AbortSignal) {
16635
+ originalAddEventListener.call(optionsOrCapture.signal, 'abort', () => {
16636
+ this.removeEventListener(name, originalCallback, optionsOrCapture);
16637
+ });
16638
+ }
16639
+ return originalAddEventListener.call(this, name, originalCallback, optionsOrCapture);
16640
+ };
16641
+ }
16642
+ function polyfill() {
16643
+ if (!featureSupported()) {
16644
+ monkeyPatch();
16645
+ signalSupported = true;
16646
+ }
16647
+ }
16648
+
16649
+ polyfill();
16650
+ const suspendedTrapStack = [];
16651
+ let activeTrap = undefined;
16652
+ function tryReactivate() {
16653
+ const trapToReactivate = suspendedTrapStack.pop();
16654
+ if (trapToReactivate) {
16655
+ focusTrap(trapToReactivate.container, trapToReactivate.initialFocus, trapToReactivate.originalSignal);
16656
+ }
16657
+ }
16658
+ function followSignal(signal) {
16659
+ const controller = new AbortController();
16660
+ signal.addEventListener('abort', () => {
16661
+ controller.abort();
16662
+ });
16663
+ return controller;
16664
+ }
16665
+ function focusTrap(container, initialFocus, abortSignal) {
16666
+ const controller = new AbortController();
16667
+ const signal = abortSignal !== null && abortSignal !== void 0 ? abortSignal : controller.signal;
16668
+ container.setAttribute('data-focus-trap', 'active');
16669
+ const sentinelStart = document.createElement('span');
16670
+ sentinelStart.setAttribute('class', 'sentinel');
16671
+ sentinelStart.setAttribute('tabindex', '0');
16672
+ sentinelStart.setAttribute('aria-hidden', 'true');
16673
+ sentinelStart.onfocus = () => {
16674
+ const lastFocusableChild = getFocusableChild(container, true);
16675
+ lastFocusableChild === null || lastFocusableChild === void 0 ? void 0 : lastFocusableChild.focus();
16676
+ };
16677
+ const sentinelEnd = document.createElement('span');
16678
+ sentinelEnd.setAttribute('class', 'sentinel');
16679
+ sentinelEnd.setAttribute('tabindex', '0');
16680
+ sentinelEnd.setAttribute('aria-hidden', 'true');
16681
+ sentinelEnd.onfocus = () => {
16682
+ const firstFocusableChild = getFocusableChild(container);
16683
+ firstFocusableChild === null || firstFocusableChild === void 0 ? void 0 : firstFocusableChild.focus();
16684
+ };
16685
+ container.prepend(sentinelStart);
16686
+ container.append(sentinelEnd);
16687
+ let lastFocusedChild = undefined;
16688
+ function ensureTrapZoneHasFocus(focusedElement) {
16689
+ if (focusedElement instanceof HTMLElement && document.contains(container)) {
16690
+ if (container.contains(focusedElement)) {
16691
+ lastFocusedChild = focusedElement;
16692
+ return;
16693
+ } else {
16694
+ if (lastFocusedChild && isTabbable(lastFocusedChild) && container.contains(lastFocusedChild)) {
16695
+ lastFocusedChild.focus();
16696
+ return;
16697
+ } else if (initialFocus && container.contains(initialFocus)) {
16698
+ initialFocus.focus();
16699
+ return;
16700
+ } else {
16701
+ const firstFocusableChild = getFocusableChild(container);
16702
+ firstFocusableChild === null || firstFocusableChild === void 0 ? void 0 : firstFocusableChild.focus();
16703
+ return;
16704
+ }
16705
+ }
16706
+ }
16707
+ }
16708
+ const wrappingController = followSignal(signal);
16709
+ if (activeTrap) {
16710
+ const suspendedTrap = activeTrap;
16711
+ activeTrap.container.setAttribute('data-focus-trap', 'suspended');
16712
+ activeTrap.controller.abort();
16713
+ suspendedTrapStack.push(suspendedTrap);
16714
+ }
16715
+ wrappingController.signal.addEventListener('abort', () => {
16716
+ activeTrap = undefined;
16717
+ });
16718
+ signal.addEventListener('abort', () => {
16719
+ container.removeAttribute('data-focus-trap');
16720
+ const sentinels = container.getElementsByClassName('sentinel');
16721
+ while (sentinels.length > 0) sentinels[0].remove();
16722
+ const suspendedTrapIndex = suspendedTrapStack.findIndex(t => t.container === container);
16723
+ if (suspendedTrapIndex >= 0) {
16724
+ suspendedTrapStack.splice(suspendedTrapIndex, 1);
16725
+ }
16726
+ tryReactivate();
16727
+ });
16728
+ document.addEventListener('focus', event => {
16729
+ ensureTrapZoneHasFocus(event.target);
16730
+ }, {
16731
+ signal: wrappingController.signal,
16732
+ capture: true
16733
+ });
16734
+ ensureTrapZoneHasFocus(document.activeElement);
16735
+ activeTrap = {
16736
+ container,
16737
+ controller: wrappingController,
16738
+ initialFocus,
16739
+ originalSignal: signal
16740
+ };
16741
+ const suspendedTrapIndex = suspendedTrapStack.findIndex(t => t.container === container);
16742
+ if (suspendedTrapIndex >= 0) {
16743
+ suspendedTrapStack.splice(suspendedTrapIndex, 1);
16744
+ }
16745
+ if (!abortSignal) {
16746
+ return controller;
16747
+ }
16748
+ }
16547
16749
 
16548
- function visible(el) {
16549
- return !el.hidden && (!el.type || el.type !== 'hidden') && (el.offsetWidth > 0 || el.offsetHeight > 0);
16750
+ let isMac = undefined;
16751
+ function isMacOS() {
16752
+ if (isMac === undefined) {
16753
+ isMac = /^mac/i.test(window.navigator.platform);
16754
+ }
16755
+ return isMac;
16756
+ }
16757
+
16758
+ let idSeed = 10000;
16759
+ function uniqueId() {
16760
+ return `__primer_id_${idSeed++}`;
16761
+ }
16762
+
16763
+ polyfill();
16764
+ var FocusKeys;
16765
+ (function (FocusKeys) {
16766
+ FocusKeys[FocusKeys["ArrowHorizontal"] = 1] = "ArrowHorizontal";
16767
+ FocusKeys[FocusKeys["ArrowVertical"] = 2] = "ArrowVertical";
16768
+ FocusKeys[FocusKeys["JK"] = 4] = "JK";
16769
+ FocusKeys[FocusKeys["HL"] = 8] = "HL";
16770
+ FocusKeys[FocusKeys["HomeAndEnd"] = 16] = "HomeAndEnd";
16771
+ FocusKeys[FocusKeys["PageUpDown"] = 256] = "PageUpDown";
16772
+ FocusKeys[FocusKeys["WS"] = 32] = "WS";
16773
+ FocusKeys[FocusKeys["AD"] = 64] = "AD";
16774
+ FocusKeys[FocusKeys["Tab"] = 128] = "Tab";
16775
+ FocusKeys[FocusKeys["Backspace"] = 512] = "Backspace";
16776
+ FocusKeys[FocusKeys["ArrowAll"] = 3] = "ArrowAll";
16777
+ FocusKeys[FocusKeys["HJKL"] = 12] = "HJKL";
16778
+ FocusKeys[FocusKeys["WASD"] = 96] = "WASD";
16779
+ FocusKeys[FocusKeys["All"] = 511] = "All";
16780
+ })(FocusKeys || (FocusKeys = {}));
16781
+ const KEY_TO_BIT = {
16782
+ ArrowLeft: FocusKeys.ArrowHorizontal,
16783
+ ArrowDown: FocusKeys.ArrowVertical,
16784
+ ArrowUp: FocusKeys.ArrowVertical,
16785
+ ArrowRight: FocusKeys.ArrowHorizontal,
16786
+ h: FocusKeys.HL,
16787
+ j: FocusKeys.JK,
16788
+ k: FocusKeys.JK,
16789
+ l: FocusKeys.HL,
16790
+ a: FocusKeys.AD,
16791
+ s: FocusKeys.WS,
16792
+ w: FocusKeys.WS,
16793
+ d: FocusKeys.AD,
16794
+ Tab: FocusKeys.Tab,
16795
+ Home: FocusKeys.HomeAndEnd,
16796
+ End: FocusKeys.HomeAndEnd,
16797
+ PageUp: FocusKeys.PageUpDown,
16798
+ PageDown: FocusKeys.PageUpDown,
16799
+ Backspace: FocusKeys.Backspace
16800
+ };
16801
+ const KEY_TO_DIRECTION = {
16802
+ ArrowLeft: 'previous',
16803
+ ArrowDown: 'next',
16804
+ ArrowUp: 'previous',
16805
+ ArrowRight: 'next',
16806
+ h: 'previous',
16807
+ j: 'next',
16808
+ k: 'previous',
16809
+ l: 'next',
16810
+ a: 'previous',
16811
+ s: 'next',
16812
+ w: 'previous',
16813
+ d: 'next',
16814
+ Tab: 'next',
16815
+ Home: 'start',
16816
+ End: 'end',
16817
+ PageUp: 'start',
16818
+ PageDown: 'end',
16819
+ Backspace: 'previous'
16820
+ };
16821
+ function getDirection(keyboardEvent) {
16822
+ const direction = KEY_TO_DIRECTION[keyboardEvent.key];
16823
+ if (keyboardEvent.key === 'Tab' && keyboardEvent.shiftKey) {
16824
+ return 'previous';
16825
+ }
16826
+ const isMac = isMacOS();
16827
+ if (isMac && keyboardEvent.metaKey || !isMac && keyboardEvent.ctrlKey) {
16828
+ if (keyboardEvent.key === 'ArrowLeft' || keyboardEvent.key === 'ArrowUp') {
16829
+ return 'start';
16830
+ } else if (keyboardEvent.key === 'ArrowRight' || keyboardEvent.key === 'ArrowDown') {
16831
+ return 'end';
16832
+ }
16833
+ }
16834
+ return direction;
16550
16835
  }
16551
- function focusable(el) {
16552
- const inputEl = el;
16553
- return inputEl.tabIndex >= 0 && !inputEl.disabled && visible(inputEl);
16836
+ function shouldIgnoreFocusHandling(keyboardEvent, activeElement) {
16837
+ const key = keyboardEvent.key;
16838
+ const keyLength = [...key].length;
16839
+ const isTextInput = activeElement instanceof HTMLInputElement && activeElement.type === 'text' || activeElement instanceof HTMLTextAreaElement;
16840
+ if (isTextInput && (keyLength === 1 || key === 'Home' || key === 'End')) {
16841
+ return true;
16842
+ }
16843
+ if (activeElement instanceof HTMLSelectElement) {
16844
+ if (keyLength === 1) {
16845
+ return true;
16846
+ }
16847
+ if (key === 'ArrowDown' && isMacOS() && !keyboardEvent.metaKey) {
16848
+ return true;
16849
+ }
16850
+ if (key === 'ArrowDown' && !isMacOS() && keyboardEvent.altKey) {
16851
+ return true;
16852
+ }
16853
+ }
16854
+ if (activeElement instanceof HTMLTextAreaElement && (key === 'PageUp' || key === 'PageDown')) {
16855
+ return true;
16856
+ }
16857
+ if (isTextInput) {
16858
+ const textInput = activeElement;
16859
+ const cursorAtStart = textInput.selectionStart === 0 && textInput.selectionEnd === 0;
16860
+ const cursorAtEnd = textInput.selectionStart === textInput.value.length && textInput.selectionEnd === textInput.value.length;
16861
+ if (key === 'ArrowLeft' && !cursorAtStart) {
16862
+ return true;
16863
+ }
16864
+ if (key === 'ArrowRight' && !cursorAtEnd) {
16865
+ return true;
16866
+ }
16867
+ if (textInput instanceof HTMLTextAreaElement) {
16868
+ if (key === 'ArrowUp' && !cursorAtStart) {
16869
+ return true;
16870
+ }
16871
+ if (key === 'ArrowDown' && !cursorAtEnd) {
16872
+ return true;
16873
+ }
16874
+ }
16875
+ }
16876
+ return false;
16877
+ }
16878
+ const isActiveDescendantAttribute = 'data-is-active-descendant';
16879
+ const activeDescendantActivatedDirectly = 'activated-directly';
16880
+ const activeDescendantActivatedIndirectly = 'activated-indirectly';
16881
+ const hasActiveDescendantAttribute = 'data-has-active-descendant';
16882
+ function focusZone(container, settings) {
16883
+ var _a, _b, _c, _d, _e;
16884
+ const focusableElements = [];
16885
+ const savedTabIndex = new WeakMap();
16886
+ const bindKeys = (_a = settings === null || settings === void 0 ? void 0 : settings.bindKeys) !== null && _a !== void 0 ? _a : ((settings === null || settings === void 0 ? void 0 : settings.getNextFocusable) ? FocusKeys.ArrowAll : FocusKeys.ArrowVertical) | FocusKeys.HomeAndEnd;
16887
+ const focusOutBehavior = (_b = settings === null || settings === void 0 ? void 0 : settings.focusOutBehavior) !== null && _b !== void 0 ? _b : 'stop';
16888
+ const focusInStrategy = (_c = settings === null || settings === void 0 ? void 0 : settings.focusInStrategy) !== null && _c !== void 0 ? _c : 'previous';
16889
+ const activeDescendantControl = settings === null || settings === void 0 ? void 0 : settings.activeDescendantControl;
16890
+ const activeDescendantCallback = settings === null || settings === void 0 ? void 0 : settings.onActiveDescendantChanged;
16891
+ let currentFocusedElement;
16892
+ const preventScroll = (_d = settings === null || settings === void 0 ? void 0 : settings.preventScroll) !== null && _d !== void 0 ? _d : false;
16893
+ function getFirstFocusableElement() {
16894
+ return focusableElements[0];
16895
+ }
16896
+ function isActiveDescendantInputFocused() {
16897
+ return document.activeElement === activeDescendantControl;
16898
+ }
16899
+ function updateFocusedElement(to, directlyActivated = false) {
16900
+ const from = currentFocusedElement;
16901
+ currentFocusedElement = to;
16902
+ if (activeDescendantControl) {
16903
+ if (to && isActiveDescendantInputFocused()) {
16904
+ setActiveDescendant(from, to, directlyActivated);
16905
+ } else {
16906
+ clearActiveDescendant();
16907
+ }
16908
+ return;
16909
+ }
16910
+ if (from && from !== to && savedTabIndex.has(from)) {
16911
+ from.setAttribute('tabindex', '-1');
16912
+ }
16913
+ to === null || to === void 0 ? void 0 : to.setAttribute('tabindex', '0');
16914
+ }
16915
+ function setActiveDescendant(from, to, directlyActivated = false) {
16916
+ if (!to.id) {
16917
+ to.setAttribute('id', uniqueId());
16918
+ }
16919
+ if (from && from !== to) {
16920
+ from.removeAttribute(isActiveDescendantAttribute);
16921
+ }
16922
+ if (!activeDescendantControl || !directlyActivated && activeDescendantControl.getAttribute('aria-activedescendant') === to.id) {
16923
+ return;
16924
+ }
16925
+ activeDescendantControl.setAttribute('aria-activedescendant', to.id);
16926
+ container.setAttribute(hasActiveDescendantAttribute, to.id);
16927
+ to.setAttribute(isActiveDescendantAttribute, directlyActivated ? activeDescendantActivatedDirectly : activeDescendantActivatedIndirectly);
16928
+ activeDescendantCallback === null || activeDescendantCallback === void 0 ? void 0 : activeDescendantCallback(to, from, directlyActivated);
16929
+ }
16930
+ function clearActiveDescendant(previouslyActiveElement = currentFocusedElement) {
16931
+ if (focusInStrategy === 'first') {
16932
+ currentFocusedElement = undefined;
16933
+ }
16934
+ activeDescendantControl === null || activeDescendantControl === void 0 ? void 0 : activeDescendantControl.removeAttribute('aria-activedescendant');
16935
+ container.removeAttribute(hasActiveDescendantAttribute);
16936
+ previouslyActiveElement === null || previouslyActiveElement === void 0 ? void 0 : previouslyActiveElement.removeAttribute(isActiveDescendantAttribute);
16937
+ activeDescendantCallback === null || activeDescendantCallback === void 0 ? void 0 : activeDescendantCallback(undefined, previouslyActiveElement, false);
16938
+ }
16939
+ function beginFocusManagement(...elements) {
16940
+ const filteredElements = elements.filter(e => {
16941
+ var _a, _b;
16942
+ return (_b = (_a = settings === null || settings === void 0 ? void 0 : settings.focusableElementFilter) === null || _a === void 0 ? void 0 : _a.call(settings, e)) !== null && _b !== void 0 ? _b : true;
16943
+ });
16944
+ if (filteredElements.length === 0) {
16945
+ return;
16946
+ }
16947
+ focusableElements.splice(findInsertionIndex(filteredElements), 0, ...filteredElements);
16948
+ for (const element of filteredElements) {
16949
+ if (!savedTabIndex.has(element)) {
16950
+ savedTabIndex.set(element, element.getAttribute('tabindex'));
16951
+ }
16952
+ element.setAttribute('tabindex', '-1');
16953
+ }
16954
+ if (!currentFocusedElement) {
16955
+ updateFocusedElement(getFirstFocusableElement());
16956
+ }
16957
+ }
16958
+ function findInsertionIndex(elementsToInsert) {
16959
+ const firstElementToInsert = elementsToInsert[0];
16960
+ if (focusableElements.length === 0) return 0;
16961
+ let iMin = 0;
16962
+ let iMax = focusableElements.length - 1;
16963
+ while (iMin <= iMax) {
16964
+ const i = Math.floor((iMin + iMax) / 2);
16965
+ const element = focusableElements[i];
16966
+ if (followsInDocument(firstElementToInsert, element)) {
16967
+ iMax = i - 1;
16968
+ } else {
16969
+ iMin = i + 1;
16970
+ }
16971
+ }
16972
+ return iMin;
16973
+ }
16974
+ function followsInDocument(first, second) {
16975
+ return (second.compareDocumentPosition(first) & Node.DOCUMENT_POSITION_PRECEDING) > 0;
16976
+ }
16977
+ function endFocusManagement(...elements) {
16978
+ for (const element of elements) {
16979
+ const focusableElementIndex = focusableElements.indexOf(element);
16980
+ if (focusableElementIndex >= 0) {
16981
+ focusableElements.splice(focusableElementIndex, 1);
16982
+ }
16983
+ const savedIndex = savedTabIndex.get(element);
16984
+ if (savedIndex !== undefined) {
16985
+ if (savedIndex === null) {
16986
+ element.removeAttribute('tabindex');
16987
+ } else {
16988
+ element.setAttribute('tabindex', savedIndex);
16989
+ }
16990
+ savedTabIndex.delete(element);
16991
+ }
16992
+ if (element === currentFocusedElement) {
16993
+ const nextElementToFocus = getFirstFocusableElement();
16994
+ updateFocusedElement(nextElementToFocus);
16995
+ }
16996
+ }
16997
+ }
16998
+ beginFocusManagement(...iterateFocusableElements(container));
16999
+ const initialElement = typeof focusInStrategy === 'function' ? focusInStrategy(document.body) : getFirstFocusableElement();
17000
+ updateFocusedElement(initialElement);
17001
+ const observer = new MutationObserver(mutations => {
17002
+ for (const mutation of mutations) {
17003
+ for (const removedNode of mutation.removedNodes) {
17004
+ if (removedNode instanceof HTMLElement) {
17005
+ endFocusManagement(...iterateFocusableElements(removedNode));
17006
+ }
17007
+ }
17008
+ }
17009
+ for (const mutation of mutations) {
17010
+ for (const addedNode of mutation.addedNodes) {
17011
+ if (addedNode instanceof HTMLElement) {
17012
+ beginFocusManagement(...iterateFocusableElements(addedNode));
17013
+ }
17014
+ }
17015
+ }
17016
+ });
17017
+ observer.observe(container, {
17018
+ subtree: true,
17019
+ childList: true
17020
+ });
17021
+ const controller = new AbortController();
17022
+ const signal = (_e = settings === null || settings === void 0 ? void 0 : settings.abortSignal) !== null && _e !== void 0 ? _e : controller.signal;
17023
+ signal.addEventListener('abort', () => {
17024
+ endFocusManagement(...focusableElements);
17025
+ });
17026
+ let elementIndexFocusedByClick = undefined;
17027
+ container.addEventListener('mousedown', event => {
17028
+ if (event.target instanceof HTMLElement && event.target !== document.activeElement) {
17029
+ elementIndexFocusedByClick = focusableElements.indexOf(event.target);
17030
+ }
17031
+ }, {
17032
+ signal
17033
+ });
17034
+ if (activeDescendantControl) {
17035
+ container.addEventListener('focusin', event => {
17036
+ if (event.target instanceof HTMLElement && focusableElements.includes(event.target)) {
17037
+ activeDescendantControl.focus({
17038
+ preventScroll
17039
+ });
17040
+ updateFocusedElement(event.target);
17041
+ }
17042
+ });
17043
+ container.addEventListener('mousemove', ({
17044
+ target
17045
+ }) => {
17046
+ if (!(target instanceof Node)) {
17047
+ return;
17048
+ }
17049
+ const focusableElement = focusableElements.find(element => element.contains(target));
17050
+ if (focusableElement) {
17051
+ updateFocusedElement(focusableElement);
17052
+ }
17053
+ }, {
17054
+ signal,
17055
+ capture: true
17056
+ });
17057
+ activeDescendantControl.addEventListener('focusin', () => {
17058
+ if (!currentFocusedElement) {
17059
+ updateFocusedElement(getFirstFocusableElement());
17060
+ } else {
17061
+ setActiveDescendant(undefined, currentFocusedElement);
17062
+ }
17063
+ });
17064
+ activeDescendantControl.addEventListener('focusout', () => {
17065
+ clearActiveDescendant();
17066
+ });
17067
+ } else {
17068
+ container.addEventListener('focusin', event => {
17069
+ if (event.target instanceof HTMLElement) {
17070
+ if (elementIndexFocusedByClick !== undefined) {
17071
+ if (elementIndexFocusedByClick >= 0) {
17072
+ if (focusableElements[elementIndexFocusedByClick] !== currentFocusedElement) {
17073
+ updateFocusedElement(focusableElements[elementIndexFocusedByClick]);
17074
+ }
17075
+ }
17076
+ elementIndexFocusedByClick = undefined;
17077
+ } else {
17078
+ if (focusInStrategy === 'previous') {
17079
+ updateFocusedElement(event.target);
17080
+ } else if (focusInStrategy === 'closest' || focusInStrategy === 'first') {
17081
+ if (event.relatedTarget instanceof Element && !container.contains(event.relatedTarget)) {
17082
+ const targetElementIndex = lastKeyboardFocusDirection === 'previous' ? focusableElements.length - 1 : 0;
17083
+ const targetElement = focusableElements[targetElementIndex];
17084
+ targetElement === null || targetElement === void 0 ? void 0 : targetElement.focus({
17085
+ preventScroll
17086
+ });
17087
+ return;
17088
+ } else {
17089
+ updateFocusedElement(event.target);
17090
+ }
17091
+ } else if (typeof focusInStrategy === 'function') {
17092
+ if (event.relatedTarget instanceof Element && !container.contains(event.relatedTarget)) {
17093
+ const elementToFocus = focusInStrategy(event.relatedTarget);
17094
+ const requestedFocusElementIndex = elementToFocus ? focusableElements.indexOf(elementToFocus) : -1;
17095
+ if (requestedFocusElementIndex >= 0 && elementToFocus instanceof HTMLElement) {
17096
+ elementToFocus.focus({
17097
+ preventScroll
17098
+ });
17099
+ return;
17100
+ } else {
17101
+ console.warn('Element requested is not a known focusable element.');
17102
+ }
17103
+ } else {
17104
+ updateFocusedElement(event.target);
17105
+ }
17106
+ }
17107
+ }
17108
+ }
17109
+ lastKeyboardFocusDirection = undefined;
17110
+ }, {
17111
+ signal
17112
+ });
17113
+ }
17114
+ const keyboardEventRecipient = activeDescendantControl !== null && activeDescendantControl !== void 0 ? activeDescendantControl : container;
17115
+ let lastKeyboardFocusDirection = undefined;
17116
+ if (focusInStrategy === 'closest') {
17117
+ document.addEventListener('keydown', event => {
17118
+ if (event.key === 'Tab') {
17119
+ lastKeyboardFocusDirection = getDirection(event);
17120
+ }
17121
+ }, {
17122
+ signal,
17123
+ capture: true
17124
+ });
17125
+ }
17126
+ function getCurrentFocusedIndex() {
17127
+ if (!currentFocusedElement) {
17128
+ return 0;
17129
+ }
17130
+ const focusedIndex = focusableElements.indexOf(currentFocusedElement);
17131
+ const fallbackIndex = currentFocusedElement === container ? -1 : 0;
17132
+ return focusedIndex !== -1 ? focusedIndex : fallbackIndex;
17133
+ }
17134
+ keyboardEventRecipient.addEventListener('keydown', event => {
17135
+ var _a;
17136
+ if (event.key in KEY_TO_DIRECTION) {
17137
+ const keyBit = KEY_TO_BIT[event.key];
17138
+ if (!event.defaultPrevented && (keyBit & bindKeys) > 0 && !shouldIgnoreFocusHandling(event, document.activeElement)) {
17139
+ const direction = getDirection(event);
17140
+ let nextElementToFocus = undefined;
17141
+ if (settings === null || settings === void 0 ? void 0 : settings.getNextFocusable) {
17142
+ nextElementToFocus = settings.getNextFocusable(direction, (_a = document.activeElement) !== null && _a !== void 0 ? _a : undefined, event);
17143
+ }
17144
+ if (!nextElementToFocus) {
17145
+ const lastFocusedIndex = getCurrentFocusedIndex();
17146
+ let nextFocusedIndex = lastFocusedIndex;
17147
+ if (direction === 'previous') {
17148
+ nextFocusedIndex -= 1;
17149
+ } else if (direction === 'start') {
17150
+ nextFocusedIndex = 0;
17151
+ } else if (direction === 'next') {
17152
+ nextFocusedIndex += 1;
17153
+ } else {
17154
+ nextFocusedIndex = focusableElements.length - 1;
17155
+ }
17156
+ if (nextFocusedIndex < 0) {
17157
+ if (focusOutBehavior === 'wrap' && event.key !== 'Tab') {
17158
+ nextFocusedIndex = focusableElements.length - 1;
17159
+ } else {
17160
+ nextFocusedIndex = 0;
17161
+ }
17162
+ }
17163
+ if (nextFocusedIndex >= focusableElements.length) {
17164
+ if (focusOutBehavior === 'wrap' && event.key !== 'Tab') {
17165
+ nextFocusedIndex = 0;
17166
+ } else {
17167
+ nextFocusedIndex = focusableElements.length - 1;
17168
+ }
17169
+ }
17170
+ if (lastFocusedIndex !== nextFocusedIndex) {
17171
+ nextElementToFocus = focusableElements[nextFocusedIndex];
17172
+ }
17173
+ }
17174
+ if (activeDescendantControl) {
17175
+ updateFocusedElement(nextElementToFocus || currentFocusedElement, true);
17176
+ } else if (nextElementToFocus) {
17177
+ lastKeyboardFocusDirection = direction;
17178
+ nextElementToFocus.focus({
17179
+ preventScroll
17180
+ });
17181
+ }
17182
+ if (event.key !== 'Tab' || nextElementToFocus) {
17183
+ event.preventDefault();
17184
+ }
17185
+ }
17186
+ }
17187
+ }, {
17188
+ signal
17189
+ });
17190
+ return controller;
16554
17191
  }
17192
+
17193
+ /**
17194
+ * 제공된 `ref`가 없는 경우 새로운 `ref`를 만들어 사용하고, 있는 경우 제공된 ref를 사용할 수 있는 훅입니다.
17195
+ */
17196
+ const useProvidedOrCreatedRef = providedRef => {
17197
+ const createdRef = React.useRef(null);
17198
+ return providedRef ?? createdRef;
17199
+ };
17200
+
17201
+ const useFocusTrap = (settings, dependencies = []) => {
17202
+ const containerRef = useProvidedOrCreatedRef(settings?.containerRef);
17203
+ const initialFocusRef = useProvidedOrCreatedRef(settings?.initialFocusRef);
17204
+ const disabled = settings?.disabled;
17205
+ const abortController = React__namespace.default.useRef();
17206
+ const previousFocusedElement = React__namespace.default.useRef(null);
17207
+ if (!previousFocusedElement.current && !settings?.disabled) {
17208
+ previousFocusedElement.current = document.activeElement;
17209
+ }
17210
+ const disableTrap = () => {
17211
+ abortController.current?.abort();
17212
+ if (settings?.restoreFocusOnCleanUp && previousFocusedElement.current instanceof HTMLElement) {
17213
+ previousFocusedElement.current.focus();
17214
+ previousFocusedElement.current = null;
17215
+ }
17216
+ };
17217
+ React__namespace.default.useEffect(() => {
17218
+ if (containerRef.current instanceof HTMLElement) {
17219
+ if (!disabled) {
17220
+ abortController.current = focusTrap(containerRef.current, initialFocusRef.current ?? undefined);
17221
+ return () => {
17222
+ disableTrap();
17223
+ };
17224
+ } else {
17225
+ disableTrap();
17226
+ }
17227
+ }
17228
+ }, [containerRef, initialFocusRef, disabled, ...dependencies]);
17229
+ return {
17230
+ containerRef,
17231
+ initialFocusRef
17232
+ };
17233
+ };
17234
+
17235
+ const MotionView = motion(View);
17236
+
16555
17237
  const Dialog = ({
16556
17238
  children,
16557
17239
  isOpen,
@@ -16571,41 +17253,19 @@ const Dialog = ({
16571
17253
  handleDismiss?.();
16572
17254
  }
16573
17255
  }, [handleDismiss, dialogRef, overlayRef]);
16574
- const getFocusableItem = React.useCallback((e, movement) => {
16575
- if (dialogRef.current) {
16576
- const items = Array.from(dialogRef.current.querySelectorAll('*')).filter(focusable);
16577
- if (items.length === 0) return;
16578
- e.preventDefault();
16579
- const focusedElement = document.activeElement;
16580
- if (!focusedElement) {
16581
- return;
16582
- }
16583
- const index = items.indexOf(focusedElement);
16584
- const offsetIndex = index + movement;
16585
- const fallbackIndex = movement === 1 ? 0 : items.length - 1;
16586
- const focusableItem = items[offsetIndex] || items[fallbackIndex];
16587
- return focusableItem;
16588
- }
16589
- }, [dialogRef]);
16590
- const handleTab = React.useCallback(e => {
16591
- const movement = e.shiftKey ? -1 : 1;
16592
- const focusableItem = getFocusableItem(e, movement);
16593
- if (!focusableItem) {
16594
- return;
16595
- }
16596
- focusableItem.focus();
16597
- }, [getFocusableItem]);
16598
17256
  const handleKeyDown = React.useCallback(event => {
16599
17257
  switch (event.key) {
16600
- case 'Tab':
16601
- handleTab(event);
16602
- break;
16603
17258
  case 'Escape':
16604
17259
  handleDismiss?.();
16605
17260
  event.stopPropagation();
16606
17261
  break;
16607
17262
  }
16608
17263
  }, [handleDismiss]);
17264
+ useFocusTrap({
17265
+ containerRef: dialogRef,
17266
+ initialFocusRef: closeButtonRef,
17267
+ disabled: !isOpen
17268
+ });
16609
17269
  React.useEffect(() => {
16610
17270
  if (isOpen) {
16611
17271
  document.addEventListener('click', handleOutsideClick);
@@ -16651,7 +17311,7 @@ const Dialog = ({
16651
17311
  height: '100%',
16652
17312
  zIndex: 9999
16653
17313
  },
16654
- children: [/*#__PURE__*/jsxRuntimeExports.jsx(Overlay, {
17314
+ children: [/*#__PURE__*/jsxRuntimeExports.jsx(Blanket, {
16655
17315
  ref: overlayRef
16656
17316
  }), /*#__PURE__*/jsxRuntimeExports.jsxs(BaseDialog, {
16657
17317
  ref: dialogRef,
@@ -16695,7 +17355,7 @@ const Dialog = ({
16695
17355
  }) : null
16696
17356
  });
16697
17357
  };
16698
- const Overlay = styled__default.default.span`
17358
+ const Blanket = styled__default.default.span`
16699
17359
  &:before {
16700
17360
  position: fixed;
16701
17361
  top: 0;
@@ -16716,7 +17376,7 @@ const BaseDialog = styled__default.default.div(() => ({
16716
17376
  overflow: 'hidden',
16717
17377
  margin: 'auto'
16718
17378
  }), sx);
16719
- var index$2 = /*#__PURE__*/React.forwardRef(Dialog);
17379
+ var index$3 = /*#__PURE__*/React.forwardRef(Dialog);
16720
17380
 
16721
17381
  const useDialogHandler = () => {
16722
17382
  const [isOpen, setIsOpen] = React.useState(false);
@@ -17041,67 +17701,1789 @@ const ItemList = ({
17041
17701
  });
17042
17702
  };
17043
17703
 
17044
- const Space = styled__default.default.div`
17045
- width: inherit;
17046
- ${space$1};
17047
- ${sx}
17048
- `;
17049
-
17050
- const Stack = /*#__PURE__*/React.forwardRef(({
17051
- gapX = 0,
17052
- gapY = 0,
17053
- children,
17054
- alignItems = 'center',
17055
- ...props
17056
- }, ref) => /*#__PURE__*/jsxRuntimeExports.jsx(BaseStack, {
17057
- ref: ref,
17058
- alignItems: alignItems,
17059
- gapX: gapX,
17060
- gapY: gapY,
17061
- ...props,
17062
- children: children
17063
- }));
17064
- const BaseStack = styled__default.default(View)({
17065
- display: 'flex',
17066
- flexDirection: 'row',
17067
- flexWrap: 'wrap'
17068
- }, variant({
17069
- prop: 'gapX',
17070
- variants: Object.fromEntries(Object.entries(space).map(([key, value]) => {
17071
- const styleValue = {
17072
- '& > *': {
17073
- px: forcePixelValue(value / 2)
17074
- },
17075
- 'mx': forcePixelValue(-value / 2)
17076
- };
17077
- return [key, styleValue];
17078
- }))
17079
- }), variant({
17080
- prop: 'gapY',
17081
- variants: Object.fromEntries(Object.entries(space).map(([key, value]) => {
17082
- const styleValue = {
17083
- '& > *': {
17084
- mt: forcePixelValue(value)
17085
- },
17086
- 'mt': forcePixelValue(-value)
17087
- };
17088
- return [key, styleValue];
17089
- }))
17090
- }));
17091
- const Item = ({
17704
+ const Overlay = ({
17092
17705
  children,
17706
+ isOpen,
17707
+ onDismiss,
17708
+ size = 'm',
17709
+ ignoreOutsideClickRefs = [],
17093
17710
  ...props
17094
- }) => /*#__PURE__*/jsxRuntimeExports.jsx(View, {
17095
- ...props,
17096
- children: children
17097
- });
17098
- var Stack$1 = Object.assign(Stack, {
17099
- Item
17100
- });
17101
-
17102
- const StyledIcon = ({
17103
- icon: Icon,
17104
- sx,
17711
+ }, ref) => {
17712
+ const overlayRef = React.useRef(null);
17713
+ React.useImperativeHandle(ref, () => overlayRef.current);
17714
+ const handleDismiss = React.useCallback(() => onDismiss?.(), [onDismiss]);
17715
+ const handleOutsideClick = React.useCallback(e => {
17716
+ if (overlayRef.current && e.target instanceof Node && !overlayRef.current.contains(e.target) && ignoreOutsideClickRefs && !ignoreOutsideClickRefs.some(({
17717
+ current
17718
+ }) => current?.contains(e.target))) {
17719
+ handleDismiss?.();
17720
+ }
17721
+ }, [handleDismiss, overlayRef]);
17722
+ const handleKeyDown = React.useCallback(event => {
17723
+ switch (event.key) {
17724
+ case 'Escape':
17725
+ handleDismiss?.();
17726
+ event.stopPropagation();
17727
+ break;
17728
+ }
17729
+ }, [handleDismiss]);
17730
+ React.useEffect(() => {
17731
+ if (overlayRef.current) {
17732
+ const firstItem = iterateFocusableElements(overlayRef.current).next().value;
17733
+ firstItem?.focus();
17734
+ }
17735
+ }, [isOpen]);
17736
+ React.useEffect(() => {
17737
+ if (isOpen) {
17738
+ document.addEventListener('keydown', handleKeyDown);
17739
+ return () => {
17740
+ document.removeEventListener('keydown', handleKeyDown);
17741
+ };
17742
+ }
17743
+ }, [isOpen, handleKeyDown]);
17744
+ React.useEffect(() => {
17745
+ if (isOpen) {
17746
+ document.addEventListener('click', handleOutsideClick);
17747
+ return () => {
17748
+ document.removeEventListener('click', handleOutsideClick);
17749
+ };
17750
+ }
17751
+ }, [isOpen, handleOutsideClick]);
17752
+ return isOpen ? /*#__PURE__*/jsxRuntimeExports.jsx(BaseOverlay, {
17753
+ ref: overlayRef,
17754
+ size: size,
17755
+ ...props,
17756
+ children: children
17757
+ }) : null;
17758
+ };
17759
+ const BaseOverlay = styled__default.default.div`
17760
+ position: absolute;
17761
+ box-shadow: ${({
17762
+ theme
17763
+ }) => theme.shadows['shadow/overlay']};
17764
+ background-color: ${({
17765
+ theme
17766
+ }) => theme.colors['surface/overlay']};
17767
+ border-radius: ${({
17768
+ theme
17769
+ }) => forcePixelValue(theme.radii.s)};
17770
+ overflow: hidden;
17771
+ margin: auto;
17772
+ z-index: 99999;
17773
+
17774
+ ${variant({
17775
+ prop: 'size',
17776
+ variants: {
17777
+ m: {
17778
+ width: forcePixelValue(180)
17779
+ }
17780
+ }
17781
+ })}
17782
+ ${sx}
17783
+ `;
17784
+ var Overlay$1 = /*#__PURE__*/React.forwardRef(Overlay);
17785
+
17786
+ const min = Math.min;
17787
+ const max = Math.max;
17788
+ const round = Math.round;
17789
+ const floor = Math.floor;
17790
+ const createCoords = v => ({
17791
+ x: v,
17792
+ y: v
17793
+ });
17794
+ const oppositeSideMap = {
17795
+ left: 'right',
17796
+ right: 'left',
17797
+ bottom: 'top',
17798
+ top: 'bottom'
17799
+ };
17800
+ const oppositeAlignmentMap = {
17801
+ start: 'end',
17802
+ end: 'start'
17803
+ };
17804
+ function clamp(start, value, end) {
17805
+ return max(start, min(value, end));
17806
+ }
17807
+ function evaluate(value, param) {
17808
+ return typeof value === 'function' ? value(param) : value;
17809
+ }
17810
+ function getSide(placement) {
17811
+ return placement.split('-')[0];
17812
+ }
17813
+ function getAlignment(placement) {
17814
+ return placement.split('-')[1];
17815
+ }
17816
+ function getOppositeAxis(axis) {
17817
+ return axis === 'x' ? 'y' : 'x';
17818
+ }
17819
+ function getAxisLength(axis) {
17820
+ return axis === 'y' ? 'height' : 'width';
17821
+ }
17822
+ function getSideAxis(placement) {
17823
+ return ['top', 'bottom'].includes(getSide(placement)) ? 'y' : 'x';
17824
+ }
17825
+ function getAlignmentAxis(placement) {
17826
+ return getOppositeAxis(getSideAxis(placement));
17827
+ }
17828
+ function getAlignmentSides(placement, rects, rtl) {
17829
+ if (rtl === void 0) {
17830
+ rtl = false;
17831
+ }
17832
+ const alignment = getAlignment(placement);
17833
+ const alignmentAxis = getAlignmentAxis(placement);
17834
+ const length = getAxisLength(alignmentAxis);
17835
+ let mainAlignmentSide = alignmentAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';
17836
+ if (rects.reference[length] > rects.floating[length]) {
17837
+ mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
17838
+ }
17839
+ return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
17840
+ }
17841
+ function getExpandedPlacements(placement) {
17842
+ const oppositePlacement = getOppositePlacement(placement);
17843
+ return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
17844
+ }
17845
+ function getOppositeAlignmentPlacement(placement) {
17846
+ return placement.replace(/start|end/g, alignment => oppositeAlignmentMap[alignment]);
17847
+ }
17848
+ function getSideList(side, isStart, rtl) {
17849
+ const lr = ['left', 'right'];
17850
+ const rl = ['right', 'left'];
17851
+ const tb = ['top', 'bottom'];
17852
+ const bt = ['bottom', 'top'];
17853
+ switch (side) {
17854
+ case 'top':
17855
+ case 'bottom':
17856
+ if (rtl) return isStart ? rl : lr;
17857
+ return isStart ? lr : rl;
17858
+ case 'left':
17859
+ case 'right':
17860
+ return isStart ? tb : bt;
17861
+ default:
17862
+ return [];
17863
+ }
17864
+ }
17865
+ function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
17866
+ const alignment = getAlignment(placement);
17867
+ let list = getSideList(getSide(placement), direction === 'start', rtl);
17868
+ if (alignment) {
17869
+ list = list.map(side => side + "-" + alignment);
17870
+ if (flipAlignment) {
17871
+ list = list.concat(list.map(getOppositeAlignmentPlacement));
17872
+ }
17873
+ }
17874
+ return list;
17875
+ }
17876
+ function getOppositePlacement(placement) {
17877
+ return placement.replace(/left|right|bottom|top/g, side => oppositeSideMap[side]);
17878
+ }
17879
+ function expandPaddingObject(padding) {
17880
+ return {
17881
+ top: 0,
17882
+ right: 0,
17883
+ bottom: 0,
17884
+ left: 0,
17885
+ ...padding
17886
+ };
17887
+ }
17888
+ function getPaddingObject(padding) {
17889
+ return typeof padding !== 'number' ? expandPaddingObject(padding) : {
17890
+ top: padding,
17891
+ right: padding,
17892
+ bottom: padding,
17893
+ left: padding
17894
+ };
17895
+ }
17896
+ function rectToClientRect(rect) {
17897
+ return {
17898
+ ...rect,
17899
+ top: rect.y,
17900
+ left: rect.x,
17901
+ right: rect.x + rect.width,
17902
+ bottom: rect.y + rect.height
17903
+ };
17904
+ }
17905
+
17906
+ function computeCoordsFromPlacement(_ref, placement, rtl) {
17907
+ let {
17908
+ reference,
17909
+ floating
17910
+ } = _ref;
17911
+ const sideAxis = getSideAxis(placement);
17912
+ const alignmentAxis = getAlignmentAxis(placement);
17913
+ const alignLength = getAxisLength(alignmentAxis);
17914
+ const side = getSide(placement);
17915
+ const isVertical = sideAxis === 'y';
17916
+ const commonX = reference.x + reference.width / 2 - floating.width / 2;
17917
+ const commonY = reference.y + reference.height / 2 - floating.height / 2;
17918
+ const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
17919
+ let coords;
17920
+ switch (side) {
17921
+ case 'top':
17922
+ coords = {
17923
+ x: commonX,
17924
+ y: reference.y - floating.height
17925
+ };
17926
+ break;
17927
+ case 'bottom':
17928
+ coords = {
17929
+ x: commonX,
17930
+ y: reference.y + reference.height
17931
+ };
17932
+ break;
17933
+ case 'right':
17934
+ coords = {
17935
+ x: reference.x + reference.width,
17936
+ y: commonY
17937
+ };
17938
+ break;
17939
+ case 'left':
17940
+ coords = {
17941
+ x: reference.x - floating.width,
17942
+ y: commonY
17943
+ };
17944
+ break;
17945
+ default:
17946
+ coords = {
17947
+ x: reference.x,
17948
+ y: reference.y
17949
+ };
17950
+ }
17951
+ switch (getAlignment(placement)) {
17952
+ case 'start':
17953
+ coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
17954
+ break;
17955
+ case 'end':
17956
+ coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
17957
+ break;
17958
+ }
17959
+ return coords;
17960
+ }
17961
+
17962
+ /**
17963
+ * Computes the `x` and `y` coordinates that will place the floating element
17964
+ * next to a reference element when it is given a certain positioning strategy.
17965
+ *
17966
+ * This export does not have any `platform` interface logic. You will need to
17967
+ * write one for the platform you are using Floating UI with.
17968
+ */
17969
+ const computePosition$1 = async (reference, floating, config) => {
17970
+ const {
17971
+ placement = 'bottom',
17972
+ strategy = 'absolute',
17973
+ middleware = [],
17974
+ platform
17975
+ } = config;
17976
+ const validMiddleware = middleware.filter(Boolean);
17977
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));
17978
+ let rects = await platform.getElementRects({
17979
+ reference,
17980
+ floating,
17981
+ strategy
17982
+ });
17983
+ let {
17984
+ x,
17985
+ y
17986
+ } = computeCoordsFromPlacement(rects, placement, rtl);
17987
+ let statefulPlacement = placement;
17988
+ let middlewareData = {};
17989
+ let resetCount = 0;
17990
+ for (let i = 0; i < validMiddleware.length; i++) {
17991
+ const {
17992
+ name,
17993
+ fn
17994
+ } = validMiddleware[i];
17995
+ const {
17996
+ x: nextX,
17997
+ y: nextY,
17998
+ data,
17999
+ reset
18000
+ } = await fn({
18001
+ x,
18002
+ y,
18003
+ initialPlacement: placement,
18004
+ placement: statefulPlacement,
18005
+ strategy,
18006
+ middlewareData,
18007
+ rects,
18008
+ platform,
18009
+ elements: {
18010
+ reference,
18011
+ floating
18012
+ }
18013
+ });
18014
+ x = nextX != null ? nextX : x;
18015
+ y = nextY != null ? nextY : y;
18016
+ middlewareData = {
18017
+ ...middlewareData,
18018
+ [name]: {
18019
+ ...middlewareData[name],
18020
+ ...data
18021
+ }
18022
+ };
18023
+ if (reset && resetCount <= 50) {
18024
+ resetCount++;
18025
+ if (typeof reset === 'object') {
18026
+ if (reset.placement) {
18027
+ statefulPlacement = reset.placement;
18028
+ }
18029
+ if (reset.rects) {
18030
+ rects = reset.rects === true ? await platform.getElementRects({
18031
+ reference,
18032
+ floating,
18033
+ strategy
18034
+ }) : reset.rects;
18035
+ }
18036
+ ({
18037
+ x,
18038
+ y
18039
+ } = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
18040
+ }
18041
+ i = -1;
18042
+ continue;
18043
+ }
18044
+ }
18045
+ return {
18046
+ x,
18047
+ y,
18048
+ placement: statefulPlacement,
18049
+ strategy,
18050
+ middlewareData
18051
+ };
18052
+ };
18053
+
18054
+ /**
18055
+ * Resolves with an object of overflow side offsets that determine how much the
18056
+ * element is overflowing a given clipping boundary on each side.
18057
+ * - positive = overflowing the boundary by that number of pixels
18058
+ * - negative = how many pixels left before it will overflow
18059
+ * - 0 = lies flush with the boundary
18060
+ * @see https://floating-ui.com/docs/detectOverflow
18061
+ */
18062
+ async function detectOverflow(state, options) {
18063
+ var _await$platform$isEle;
18064
+ if (options === void 0) {
18065
+ options = {};
18066
+ }
18067
+ const {
18068
+ x,
18069
+ y,
18070
+ platform,
18071
+ rects,
18072
+ elements,
18073
+ strategy
18074
+ } = state;
18075
+ const {
18076
+ boundary = 'clippingAncestors',
18077
+ rootBoundary = 'viewport',
18078
+ elementContext = 'floating',
18079
+ altBoundary = false,
18080
+ padding = 0
18081
+ } = evaluate(options, state);
18082
+ const paddingObject = getPaddingObject(padding);
18083
+ const altContext = elementContext === 'floating' ? 'reference' : 'floating';
18084
+ const element = elements[altBoundary ? altContext : elementContext];
18085
+ const clippingClientRect = rectToClientRect(await platform.getClippingRect({
18086
+ element: ((_await$platform$isEle = await (platform.isElement == null ? void 0 : platform.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || (await (platform.getDocumentElement == null ? void 0 : platform.getDocumentElement(elements.floating))),
18087
+ boundary,
18088
+ rootBoundary,
18089
+ strategy
18090
+ }));
18091
+ const rect = elementContext === 'floating' ? {
18092
+ ...rects.floating,
18093
+ x,
18094
+ y
18095
+ } : rects.reference;
18096
+ const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));
18097
+ const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) ? (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {
18098
+ x: 1,
18099
+ y: 1
18100
+ } : {
18101
+ x: 1,
18102
+ y: 1
18103
+ };
18104
+ const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
18105
+ rect,
18106
+ offsetParent,
18107
+ strategy
18108
+ }) : rect);
18109
+ return {
18110
+ top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
18111
+ bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
18112
+ left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
18113
+ right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
18114
+ };
18115
+ }
18116
+
18117
+ /**
18118
+ * Optimizes the visibility of the floating element by flipping the `placement`
18119
+ * in order to keep it in view when the preferred placement(s) will overflow the
18120
+ * clipping boundary. Alternative to `autoPlacement`.
18121
+ * @see https://floating-ui.com/docs/flip
18122
+ */
18123
+ const flip = function (options) {
18124
+ if (options === void 0) {
18125
+ options = {};
18126
+ }
18127
+ return {
18128
+ name: 'flip',
18129
+ options,
18130
+ async fn(state) {
18131
+ var _middlewareData$arrow, _middlewareData$flip;
18132
+ const {
18133
+ placement,
18134
+ middlewareData,
18135
+ rects,
18136
+ initialPlacement,
18137
+ platform,
18138
+ elements
18139
+ } = state;
18140
+ const {
18141
+ mainAxis: checkMainAxis = true,
18142
+ crossAxis: checkCrossAxis = true,
18143
+ fallbackPlacements: specifiedFallbackPlacements,
18144
+ fallbackStrategy = 'bestFit',
18145
+ fallbackAxisSideDirection = 'none',
18146
+ flipAlignment = true,
18147
+ ...detectOverflowOptions
18148
+ } = evaluate(options, state);
18149
+
18150
+ // If a reset by the arrow was caused due to an alignment offset being
18151
+ // added, we should skip any logic now since `flip()` has already done its
18152
+ // work.
18153
+ // https://github.com/floating-ui/floating-ui/issues/2549#issuecomment-1719601643
18154
+ if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
18155
+ return {};
18156
+ }
18157
+ const side = getSide(placement);
18158
+ const isBasePlacement = getSide(initialPlacement) === initialPlacement;
18159
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
18160
+ const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
18161
+ if (!specifiedFallbackPlacements && fallbackAxisSideDirection !== 'none') {
18162
+ fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
18163
+ }
18164
+ const placements = [initialPlacement, ...fallbackPlacements];
18165
+ const overflow = await detectOverflow(state, detectOverflowOptions);
18166
+ const overflows = [];
18167
+ let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
18168
+ if (checkMainAxis) {
18169
+ overflows.push(overflow[side]);
18170
+ }
18171
+ if (checkCrossAxis) {
18172
+ const sides = getAlignmentSides(placement, rects, rtl);
18173
+ overflows.push(overflow[sides[0]], overflow[sides[1]]);
18174
+ }
18175
+ overflowsData = [...overflowsData, {
18176
+ placement,
18177
+ overflows
18178
+ }];
18179
+
18180
+ // One or more sides is overflowing.
18181
+ if (!overflows.every(side => side <= 0)) {
18182
+ var _middlewareData$flip2, _overflowsData$filter;
18183
+ const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
18184
+ const nextPlacement = placements[nextIndex];
18185
+ if (nextPlacement) {
18186
+ // Try next placement and re-run the lifecycle.
18187
+ return {
18188
+ data: {
18189
+ index: nextIndex,
18190
+ overflows: overflowsData
18191
+ },
18192
+ reset: {
18193
+ placement: nextPlacement
18194
+ }
18195
+ };
18196
+ }
18197
+
18198
+ // First, find the candidates that fit on the mainAxis side of overflow,
18199
+ // then find the placement that fits the best on the main crossAxis side.
18200
+ let resetPlacement = (_overflowsData$filter = overflowsData.filter(d => d.overflows[0] <= 0).sort((a, b) => a.overflows[1] - b.overflows[1])[0]) == null ? void 0 : _overflowsData$filter.placement;
18201
+
18202
+ // Otherwise fallback.
18203
+ if (!resetPlacement) {
18204
+ switch (fallbackStrategy) {
18205
+ case 'bestFit':
18206
+ {
18207
+ var _overflowsData$map$so;
18208
+ const placement = (_overflowsData$map$so = overflowsData.map(d => [d.placement, d.overflows.filter(overflow => overflow > 0).reduce((acc, overflow) => acc + overflow, 0)]).sort((a, b) => a[1] - b[1])[0]) == null ? void 0 : _overflowsData$map$so[0];
18209
+ if (placement) {
18210
+ resetPlacement = placement;
18211
+ }
18212
+ break;
18213
+ }
18214
+ case 'initialPlacement':
18215
+ resetPlacement = initialPlacement;
18216
+ break;
18217
+ }
18218
+ }
18219
+ if (placement !== resetPlacement) {
18220
+ return {
18221
+ reset: {
18222
+ placement: resetPlacement
18223
+ }
18224
+ };
18225
+ }
18226
+ }
18227
+ return {};
18228
+ }
18229
+ };
18230
+ };
18231
+
18232
+ // For type backwards-compatibility, the `OffsetOptions` type was also
18233
+ // Derivable.
18234
+ async function convertValueToCoords(state, options) {
18235
+ const {
18236
+ placement,
18237
+ platform,
18238
+ elements
18239
+ } = state;
18240
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
18241
+ const side = getSide(placement);
18242
+ const alignment = getAlignment(placement);
18243
+ const isVertical = getSideAxis(placement) === 'y';
18244
+ const mainAxisMulti = ['left', 'top'].includes(side) ? -1 : 1;
18245
+ const crossAxisMulti = rtl && isVertical ? -1 : 1;
18246
+ const rawValue = evaluate(options, state);
18247
+
18248
+ // eslint-disable-next-line prefer-const
18249
+ let {
18250
+ mainAxis,
18251
+ crossAxis,
18252
+ alignmentAxis
18253
+ } = typeof rawValue === 'number' ? {
18254
+ mainAxis: rawValue,
18255
+ crossAxis: 0,
18256
+ alignmentAxis: null
18257
+ } : {
18258
+ mainAxis: 0,
18259
+ crossAxis: 0,
18260
+ alignmentAxis: null,
18261
+ ...rawValue
18262
+ };
18263
+ if (alignment && typeof alignmentAxis === 'number') {
18264
+ crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;
18265
+ }
18266
+ return isVertical ? {
18267
+ x: crossAxis * crossAxisMulti,
18268
+ y: mainAxis * mainAxisMulti
18269
+ } : {
18270
+ x: mainAxis * mainAxisMulti,
18271
+ y: crossAxis * crossAxisMulti
18272
+ };
18273
+ }
18274
+
18275
+ /**
18276
+ * Modifies the placement by translating the floating element along the
18277
+ * specified axes.
18278
+ * A number (shorthand for `mainAxis` or distance), or an axes configuration
18279
+ * object may be passed.
18280
+ * @see https://floating-ui.com/docs/offset
18281
+ */
18282
+ const offset = function (options) {
18283
+ if (options === void 0) {
18284
+ options = 0;
18285
+ }
18286
+ return {
18287
+ name: 'offset',
18288
+ options,
18289
+ async fn(state) {
18290
+ const {
18291
+ x,
18292
+ y
18293
+ } = state;
18294
+ const diffCoords = await convertValueToCoords(state, options);
18295
+ return {
18296
+ x: x + diffCoords.x,
18297
+ y: y + diffCoords.y,
18298
+ data: diffCoords
18299
+ };
18300
+ }
18301
+ };
18302
+ };
18303
+
18304
+ /**
18305
+ * Optimizes the visibility of the floating element by shifting it in order to
18306
+ * keep it in view when it will overflow the clipping boundary.
18307
+ * @see https://floating-ui.com/docs/shift
18308
+ */
18309
+ const shift = function (options) {
18310
+ if (options === void 0) {
18311
+ options = {};
18312
+ }
18313
+ return {
18314
+ name: 'shift',
18315
+ options,
18316
+ async fn(state) {
18317
+ const {
18318
+ x,
18319
+ y,
18320
+ placement
18321
+ } = state;
18322
+ const {
18323
+ mainAxis: checkMainAxis = true,
18324
+ crossAxis: checkCrossAxis = false,
18325
+ limiter = {
18326
+ fn: _ref => {
18327
+ let {
18328
+ x,
18329
+ y
18330
+ } = _ref;
18331
+ return {
18332
+ x,
18333
+ y
18334
+ };
18335
+ }
18336
+ },
18337
+ ...detectOverflowOptions
18338
+ } = evaluate(options, state);
18339
+ const coords = {
18340
+ x,
18341
+ y
18342
+ };
18343
+ const overflow = await detectOverflow(state, detectOverflowOptions);
18344
+ const crossAxis = getSideAxis(getSide(placement));
18345
+ const mainAxis = getOppositeAxis(crossAxis);
18346
+ let mainAxisCoord = coords[mainAxis];
18347
+ let crossAxisCoord = coords[crossAxis];
18348
+ if (checkMainAxis) {
18349
+ const minSide = mainAxis === 'y' ? 'top' : 'left';
18350
+ const maxSide = mainAxis === 'y' ? 'bottom' : 'right';
18351
+ const min = mainAxisCoord + overflow[minSide];
18352
+ const max = mainAxisCoord - overflow[maxSide];
18353
+ mainAxisCoord = clamp(min, mainAxisCoord, max);
18354
+ }
18355
+ if (checkCrossAxis) {
18356
+ const minSide = crossAxis === 'y' ? 'top' : 'left';
18357
+ const maxSide = crossAxis === 'y' ? 'bottom' : 'right';
18358
+ const min = crossAxisCoord + overflow[minSide];
18359
+ const max = crossAxisCoord - overflow[maxSide];
18360
+ crossAxisCoord = clamp(min, crossAxisCoord, max);
18361
+ }
18362
+ const limitedCoords = limiter.fn({
18363
+ ...state,
18364
+ [mainAxis]: mainAxisCoord,
18365
+ [crossAxis]: crossAxisCoord
18366
+ });
18367
+ return {
18368
+ ...limitedCoords,
18369
+ data: {
18370
+ x: limitedCoords.x - x,
18371
+ y: limitedCoords.y - y
18372
+ }
18373
+ };
18374
+ }
18375
+ };
18376
+ };
18377
+
18378
+ function getNodeName(node) {
18379
+ if (isNode(node)) {
18380
+ return (node.nodeName || '').toLowerCase();
18381
+ }
18382
+ // Mocked nodes in testing environments may not be instances of Node. By
18383
+ // returning `#document` an infinite loop won't occur.
18384
+ // https://github.com/floating-ui/floating-ui/issues/2317
18385
+ return '#document';
18386
+ }
18387
+ function getWindow(node) {
18388
+ var _node$ownerDocument;
18389
+ return (node == null ? void 0 : (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
18390
+ }
18391
+ function getDocumentElement(node) {
18392
+ var _ref;
18393
+ return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
18394
+ }
18395
+ function isNode(value) {
18396
+ return value instanceof Node || value instanceof getWindow(value).Node;
18397
+ }
18398
+ function isElement(value) {
18399
+ return value instanceof Element || value instanceof getWindow(value).Element;
18400
+ }
18401
+ function isHTMLElement(value) {
18402
+ return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
18403
+ }
18404
+ function isShadowRoot(value) {
18405
+ // Browsers without `ShadowRoot` support.
18406
+ if (typeof ShadowRoot === 'undefined') {
18407
+ return false;
18408
+ }
18409
+ return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
18410
+ }
18411
+ function isOverflowElement(element) {
18412
+ const {
18413
+ overflow,
18414
+ overflowX,
18415
+ overflowY,
18416
+ display
18417
+ } = getComputedStyle$1(element);
18418
+ return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !['inline', 'contents'].includes(display);
18419
+ }
18420
+ function isTableElement(element) {
18421
+ return ['table', 'td', 'th'].includes(getNodeName(element));
18422
+ }
18423
+ function isContainingBlock(element) {
18424
+ const webkit = isWebKit();
18425
+ const css = getComputedStyle$1(element);
18426
+
18427
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
18428
+ return css.transform !== 'none' || css.perspective !== 'none' || (css.containerType ? css.containerType !== 'normal' : false) || !webkit && (css.backdropFilter ? css.backdropFilter !== 'none' : false) || !webkit && (css.filter ? css.filter !== 'none' : false) || ['transform', 'perspective', 'filter'].some(value => (css.willChange || '').includes(value)) || ['paint', 'layout', 'strict', 'content'].some(value => (css.contain || '').includes(value));
18429
+ }
18430
+ function getContainingBlock(element) {
18431
+ let currentNode = getParentNode(element);
18432
+ while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
18433
+ if (isContainingBlock(currentNode)) {
18434
+ return currentNode;
18435
+ } else {
18436
+ currentNode = getParentNode(currentNode);
18437
+ }
18438
+ }
18439
+ return null;
18440
+ }
18441
+ function isWebKit() {
18442
+ if (typeof CSS === 'undefined' || !CSS.supports) return false;
18443
+ return CSS.supports('-webkit-backdrop-filter', 'none');
18444
+ }
18445
+ function isLastTraversableNode(node) {
18446
+ return ['html', 'body', '#document'].includes(getNodeName(node));
18447
+ }
18448
+ function getComputedStyle$1(element) {
18449
+ return getWindow(element).getComputedStyle(element);
18450
+ }
18451
+ function getNodeScroll(element) {
18452
+ if (isElement(element)) {
18453
+ return {
18454
+ scrollLeft: element.scrollLeft,
18455
+ scrollTop: element.scrollTop
18456
+ };
18457
+ }
18458
+ return {
18459
+ scrollLeft: element.pageXOffset,
18460
+ scrollTop: element.pageYOffset
18461
+ };
18462
+ }
18463
+ function getParentNode(node) {
18464
+ if (getNodeName(node) === 'html') {
18465
+ return node;
18466
+ }
18467
+ const result =
18468
+ // Step into the shadow DOM of the parent of a slotted node.
18469
+ node.assignedSlot ||
18470
+ // DOM Element detected.
18471
+ node.parentNode ||
18472
+ // ShadowRoot detected.
18473
+ isShadowRoot(node) && node.host ||
18474
+ // Fallback.
18475
+ getDocumentElement(node);
18476
+ return isShadowRoot(result) ? result.host : result;
18477
+ }
18478
+ function getNearestOverflowAncestor(node) {
18479
+ const parentNode = getParentNode(node);
18480
+ if (isLastTraversableNode(parentNode)) {
18481
+ return node.ownerDocument ? node.ownerDocument.body : node.body;
18482
+ }
18483
+ if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
18484
+ return parentNode;
18485
+ }
18486
+ return getNearestOverflowAncestor(parentNode);
18487
+ }
18488
+ function getOverflowAncestors(node, list, traverseIframes) {
18489
+ var _node$ownerDocument2;
18490
+ if (list === void 0) {
18491
+ list = [];
18492
+ }
18493
+ if (traverseIframes === void 0) {
18494
+ traverseIframes = true;
18495
+ }
18496
+ const scrollableAncestor = getNearestOverflowAncestor(node);
18497
+ const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
18498
+ const win = getWindow(scrollableAncestor);
18499
+ if (isBody) {
18500
+ return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], win.frameElement && traverseIframes ? getOverflowAncestors(win.frameElement) : []);
18501
+ }
18502
+ return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
18503
+ }
18504
+
18505
+ function getCssDimensions(element) {
18506
+ const css = getComputedStyle$1(element);
18507
+ // In testing environments, the `width` and `height` properties are empty
18508
+ // strings for SVG elements, returning NaN. Fallback to `0` in this case.
18509
+ let width = parseFloat(css.width) || 0;
18510
+ let height = parseFloat(css.height) || 0;
18511
+ const hasOffset = isHTMLElement(element);
18512
+ const offsetWidth = hasOffset ? element.offsetWidth : width;
18513
+ const offsetHeight = hasOffset ? element.offsetHeight : height;
18514
+ const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
18515
+ if (shouldFallback) {
18516
+ width = offsetWidth;
18517
+ height = offsetHeight;
18518
+ }
18519
+ return {
18520
+ width,
18521
+ height,
18522
+ $: shouldFallback
18523
+ };
18524
+ }
18525
+
18526
+ function unwrapElement(element) {
18527
+ return !isElement(element) ? element.contextElement : element;
18528
+ }
18529
+
18530
+ function getScale(element) {
18531
+ const domElement = unwrapElement(element);
18532
+ if (!isHTMLElement(domElement)) {
18533
+ return createCoords(1);
18534
+ }
18535
+ const rect = domElement.getBoundingClientRect();
18536
+ const {
18537
+ width,
18538
+ height,
18539
+ $
18540
+ } = getCssDimensions(domElement);
18541
+ let x = ($ ? round(rect.width) : rect.width) / width;
18542
+ let y = ($ ? round(rect.height) : rect.height) / height;
18543
+
18544
+ // 0, NaN, or Infinity should always fallback to 1.
18545
+
18546
+ if (!x || !Number.isFinite(x)) {
18547
+ x = 1;
18548
+ }
18549
+ if (!y || !Number.isFinite(y)) {
18550
+ y = 1;
18551
+ }
18552
+ return {
18553
+ x,
18554
+ y
18555
+ };
18556
+ }
18557
+
18558
+ const noOffsets = /*#__PURE__*/createCoords(0);
18559
+ function getVisualOffsets(element) {
18560
+ const win = getWindow(element);
18561
+ if (!isWebKit() || !win.visualViewport) {
18562
+ return noOffsets;
18563
+ }
18564
+ return {
18565
+ x: win.visualViewport.offsetLeft,
18566
+ y: win.visualViewport.offsetTop
18567
+ };
18568
+ }
18569
+ function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
18570
+ if (isFixed === void 0) {
18571
+ isFixed = false;
18572
+ }
18573
+ if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
18574
+ return false;
18575
+ }
18576
+ return isFixed;
18577
+ }
18578
+
18579
+ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
18580
+ if (includeScale === void 0) {
18581
+ includeScale = false;
18582
+ }
18583
+ if (isFixedStrategy === void 0) {
18584
+ isFixedStrategy = false;
18585
+ }
18586
+ const clientRect = element.getBoundingClientRect();
18587
+ const domElement = unwrapElement(element);
18588
+ let scale = createCoords(1);
18589
+ if (includeScale) {
18590
+ if (offsetParent) {
18591
+ if (isElement(offsetParent)) {
18592
+ scale = getScale(offsetParent);
18593
+ }
18594
+ } else {
18595
+ scale = getScale(element);
18596
+ }
18597
+ }
18598
+ const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
18599
+ let x = (clientRect.left + visualOffsets.x) / scale.x;
18600
+ let y = (clientRect.top + visualOffsets.y) / scale.y;
18601
+ let width = clientRect.width / scale.x;
18602
+ let height = clientRect.height / scale.y;
18603
+ if (domElement) {
18604
+ const win = getWindow(domElement);
18605
+ const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
18606
+ let currentIFrame = win.frameElement;
18607
+ while (currentIFrame && offsetParent && offsetWin !== win) {
18608
+ const iframeScale = getScale(currentIFrame);
18609
+ const iframeRect = currentIFrame.getBoundingClientRect();
18610
+ const css = getComputedStyle$1(currentIFrame);
18611
+ const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
18612
+ const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
18613
+ x *= iframeScale.x;
18614
+ y *= iframeScale.y;
18615
+ width *= iframeScale.x;
18616
+ height *= iframeScale.y;
18617
+ x += left;
18618
+ y += top;
18619
+ currentIFrame = getWindow(currentIFrame).frameElement;
18620
+ }
18621
+ }
18622
+ return rectToClientRect({
18623
+ width,
18624
+ height,
18625
+ x,
18626
+ y
18627
+ });
18628
+ }
18629
+
18630
+ function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
18631
+ let {
18632
+ rect,
18633
+ offsetParent,
18634
+ strategy
18635
+ } = _ref;
18636
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
18637
+ const documentElement = getDocumentElement(offsetParent);
18638
+ if (offsetParent === documentElement) {
18639
+ return rect;
18640
+ }
18641
+ let scroll = {
18642
+ scrollLeft: 0,
18643
+ scrollTop: 0
18644
+ };
18645
+ let scale = createCoords(1);
18646
+ const offsets = createCoords(0);
18647
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && strategy !== 'fixed') {
18648
+ if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
18649
+ scroll = getNodeScroll(offsetParent);
18650
+ }
18651
+ if (isHTMLElement(offsetParent)) {
18652
+ const offsetRect = getBoundingClientRect(offsetParent);
18653
+ scale = getScale(offsetParent);
18654
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
18655
+ offsets.y = offsetRect.y + offsetParent.clientTop;
18656
+ }
18657
+ }
18658
+ return {
18659
+ width: rect.width * scale.x,
18660
+ height: rect.height * scale.y,
18661
+ x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x,
18662
+ y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y
18663
+ };
18664
+ }
18665
+
18666
+ function getClientRects(element) {
18667
+ return Array.from(element.getClientRects());
18668
+ }
18669
+
18670
+ function getWindowScrollBarX(element) {
18671
+ // If <html> has a CSS width greater than the viewport, then this will be
18672
+ // incorrect for RTL.
18673
+ return getBoundingClientRect(getDocumentElement(element)).left + getNodeScroll(element).scrollLeft;
18674
+ }
18675
+
18676
+ // Gets the entire size of the scrollable document area, even extending outside
18677
+ // of the `<html>` and `<body>` rect bounds if horizontally scrollable.
18678
+ function getDocumentRect(element) {
18679
+ const html = getDocumentElement(element);
18680
+ const scroll = getNodeScroll(element);
18681
+ const body = element.ownerDocument.body;
18682
+ const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
18683
+ const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
18684
+ let x = -scroll.scrollLeft + getWindowScrollBarX(element);
18685
+ const y = -scroll.scrollTop;
18686
+ if (getComputedStyle$1(body).direction === 'rtl') {
18687
+ x += max(html.clientWidth, body.clientWidth) - width;
18688
+ }
18689
+ return {
18690
+ width,
18691
+ height,
18692
+ x,
18693
+ y
18694
+ };
18695
+ }
18696
+
18697
+ function getViewportRect(element, strategy) {
18698
+ const win = getWindow(element);
18699
+ const html = getDocumentElement(element);
18700
+ const visualViewport = win.visualViewport;
18701
+ let width = html.clientWidth;
18702
+ let height = html.clientHeight;
18703
+ let x = 0;
18704
+ let y = 0;
18705
+ if (visualViewport) {
18706
+ width = visualViewport.width;
18707
+ height = visualViewport.height;
18708
+ const visualViewportBased = isWebKit();
18709
+ if (!visualViewportBased || visualViewportBased && strategy === 'fixed') {
18710
+ x = visualViewport.offsetLeft;
18711
+ y = visualViewport.offsetTop;
18712
+ }
18713
+ }
18714
+ return {
18715
+ width,
18716
+ height,
18717
+ x,
18718
+ y
18719
+ };
18720
+ }
18721
+
18722
+ // Returns the inner client rect, subtracting scrollbars if present.
18723
+ function getInnerBoundingClientRect(element, strategy) {
18724
+ const clientRect = getBoundingClientRect(element, true, strategy === 'fixed');
18725
+ const top = clientRect.top + element.clientTop;
18726
+ const left = clientRect.left + element.clientLeft;
18727
+ const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
18728
+ const width = element.clientWidth * scale.x;
18729
+ const height = element.clientHeight * scale.y;
18730
+ const x = left * scale.x;
18731
+ const y = top * scale.y;
18732
+ return {
18733
+ width,
18734
+ height,
18735
+ x,
18736
+ y
18737
+ };
18738
+ }
18739
+ function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
18740
+ let rect;
18741
+ if (clippingAncestor === 'viewport') {
18742
+ rect = getViewportRect(element, strategy);
18743
+ } else if (clippingAncestor === 'document') {
18744
+ rect = getDocumentRect(getDocumentElement(element));
18745
+ } else if (isElement(clippingAncestor)) {
18746
+ rect = getInnerBoundingClientRect(clippingAncestor, strategy);
18747
+ } else {
18748
+ const visualOffsets = getVisualOffsets(element);
18749
+ rect = {
18750
+ ...clippingAncestor,
18751
+ x: clippingAncestor.x - visualOffsets.x,
18752
+ y: clippingAncestor.y - visualOffsets.y
18753
+ };
18754
+ }
18755
+ return rectToClientRect(rect);
18756
+ }
18757
+ function hasFixedPositionAncestor(element, stopNode) {
18758
+ const parentNode = getParentNode(element);
18759
+ if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
18760
+ return false;
18761
+ }
18762
+ return getComputedStyle$1(parentNode).position === 'fixed' || hasFixedPositionAncestor(parentNode, stopNode);
18763
+ }
18764
+
18765
+ // A "clipping ancestor" is an `overflow` element with the characteristic of
18766
+ // clipping (or hiding) child elements. This returns all clipping ancestors
18767
+ // of the given element up the tree.
18768
+ function getClippingElementAncestors(element, cache) {
18769
+ const cachedResult = cache.get(element);
18770
+ if (cachedResult) {
18771
+ return cachedResult;
18772
+ }
18773
+ let result = getOverflowAncestors(element, [], false).filter(el => isElement(el) && getNodeName(el) !== 'body');
18774
+ let currentContainingBlockComputedStyle = null;
18775
+ const elementIsFixed = getComputedStyle$1(element).position === 'fixed';
18776
+ let currentNode = elementIsFixed ? getParentNode(element) : element;
18777
+
18778
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
18779
+ while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
18780
+ const computedStyle = getComputedStyle$1(currentNode);
18781
+ const currentNodeIsContaining = isContainingBlock(currentNode);
18782
+ if (!currentNodeIsContaining && computedStyle.position === 'fixed') {
18783
+ currentContainingBlockComputedStyle = null;
18784
+ }
18785
+ const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === 'static' && !!currentContainingBlockComputedStyle && ['absolute', 'fixed'].includes(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
18786
+ if (shouldDropCurrentNode) {
18787
+ // Drop non-containing blocks.
18788
+ result = result.filter(ancestor => ancestor !== currentNode);
18789
+ } else {
18790
+ // Record last containing block for next iteration.
18791
+ currentContainingBlockComputedStyle = computedStyle;
18792
+ }
18793
+ currentNode = getParentNode(currentNode);
18794
+ }
18795
+ cache.set(element, result);
18796
+ return result;
18797
+ }
18798
+
18799
+ // Gets the maximum area that the element is visible in due to any number of
18800
+ // clipping ancestors.
18801
+ function getClippingRect(_ref) {
18802
+ let {
18803
+ element,
18804
+ boundary,
18805
+ rootBoundary,
18806
+ strategy
18807
+ } = _ref;
18808
+ const elementClippingAncestors = boundary === 'clippingAncestors' ? getClippingElementAncestors(element, this._c) : [].concat(boundary);
18809
+ const clippingAncestors = [...elementClippingAncestors, rootBoundary];
18810
+ const firstClippingAncestor = clippingAncestors[0];
18811
+ const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
18812
+ const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
18813
+ accRect.top = max(rect.top, accRect.top);
18814
+ accRect.right = min(rect.right, accRect.right);
18815
+ accRect.bottom = min(rect.bottom, accRect.bottom);
18816
+ accRect.left = max(rect.left, accRect.left);
18817
+ return accRect;
18818
+ }, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
18819
+ return {
18820
+ width: clippingRect.right - clippingRect.left,
18821
+ height: clippingRect.bottom - clippingRect.top,
18822
+ x: clippingRect.left,
18823
+ y: clippingRect.top
18824
+ };
18825
+ }
18826
+
18827
+ function getDimensions(element) {
18828
+ return getCssDimensions(element);
18829
+ }
18830
+
18831
+ function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
18832
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
18833
+ const documentElement = getDocumentElement(offsetParent);
18834
+ const isFixed = strategy === 'fixed';
18835
+ const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
18836
+ let scroll = {
18837
+ scrollLeft: 0,
18838
+ scrollTop: 0
18839
+ };
18840
+ const offsets = createCoords(0);
18841
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
18842
+ if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
18843
+ scroll = getNodeScroll(offsetParent);
18844
+ }
18845
+ if (isOffsetParentAnElement) {
18846
+ const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
18847
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
18848
+ offsets.y = offsetRect.y + offsetParent.clientTop;
18849
+ } else if (documentElement) {
18850
+ offsets.x = getWindowScrollBarX(documentElement);
18851
+ }
18852
+ }
18853
+ return {
18854
+ x: rect.left + scroll.scrollLeft - offsets.x,
18855
+ y: rect.top + scroll.scrollTop - offsets.y,
18856
+ width: rect.width,
18857
+ height: rect.height
18858
+ };
18859
+ }
18860
+
18861
+ function getTrueOffsetParent(element, polyfill) {
18862
+ if (!isHTMLElement(element) || getComputedStyle$1(element).position === 'fixed') {
18863
+ return null;
18864
+ }
18865
+ if (polyfill) {
18866
+ return polyfill(element);
18867
+ }
18868
+ return element.offsetParent;
18869
+ }
18870
+
18871
+ // Gets the closest ancestor positioned element. Handles some edge cases,
18872
+ // such as table ancestors and cross browser bugs.
18873
+ function getOffsetParent(element, polyfill) {
18874
+ const window = getWindow(element);
18875
+ if (!isHTMLElement(element)) {
18876
+ return window;
18877
+ }
18878
+ let offsetParent = getTrueOffsetParent(element, polyfill);
18879
+ while (offsetParent && isTableElement(offsetParent) && getComputedStyle$1(offsetParent).position === 'static') {
18880
+ offsetParent = getTrueOffsetParent(offsetParent, polyfill);
18881
+ }
18882
+ if (offsetParent && (getNodeName(offsetParent) === 'html' || getNodeName(offsetParent) === 'body' && getComputedStyle$1(offsetParent).position === 'static' && !isContainingBlock(offsetParent))) {
18883
+ return window;
18884
+ }
18885
+ return offsetParent || getContainingBlock(element) || window;
18886
+ }
18887
+
18888
+ const getElementRects = async function (_ref) {
18889
+ let {
18890
+ reference,
18891
+ floating,
18892
+ strategy
18893
+ } = _ref;
18894
+ const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
18895
+ const getDimensionsFn = this.getDimensions;
18896
+ return {
18897
+ reference: getRectRelativeToOffsetParent(reference, await getOffsetParentFn(floating), strategy),
18898
+ floating: {
18899
+ x: 0,
18900
+ y: 0,
18901
+ ...(await getDimensionsFn(floating))
18902
+ }
18903
+ };
18904
+ };
18905
+
18906
+ function isRTL(element) {
18907
+ return getComputedStyle$1(element).direction === 'rtl';
18908
+ }
18909
+
18910
+ const platform = {
18911
+ convertOffsetParentRelativeRectToViewportRelativeRect,
18912
+ getDocumentElement,
18913
+ getClippingRect,
18914
+ getOffsetParent,
18915
+ getElementRects,
18916
+ getClientRects,
18917
+ getDimensions,
18918
+ getScale,
18919
+ isElement,
18920
+ isRTL
18921
+ };
18922
+
18923
+ // https://samthor.au/2021/observing-dom/
18924
+ function observeMove(element, onMove) {
18925
+ let io = null;
18926
+ let timeoutId;
18927
+ const root = getDocumentElement(element);
18928
+ function cleanup() {
18929
+ clearTimeout(timeoutId);
18930
+ io && io.disconnect();
18931
+ io = null;
18932
+ }
18933
+ function refresh(skip, threshold) {
18934
+ if (skip === void 0) {
18935
+ skip = false;
18936
+ }
18937
+ if (threshold === void 0) {
18938
+ threshold = 1;
18939
+ }
18940
+ cleanup();
18941
+ const {
18942
+ left,
18943
+ top,
18944
+ width,
18945
+ height
18946
+ } = element.getBoundingClientRect();
18947
+ if (!skip) {
18948
+ onMove();
18949
+ }
18950
+ if (!width || !height) {
18951
+ return;
18952
+ }
18953
+ const insetTop = floor(top);
18954
+ const insetRight = floor(root.clientWidth - (left + width));
18955
+ const insetBottom = floor(root.clientHeight - (top + height));
18956
+ const insetLeft = floor(left);
18957
+ const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
18958
+ const options = {
18959
+ rootMargin,
18960
+ threshold: max(0, min(1, threshold)) || 1
18961
+ };
18962
+ let isFirstUpdate = true;
18963
+ function handleObserve(entries) {
18964
+ const ratio = entries[0].intersectionRatio;
18965
+ if (ratio !== threshold) {
18966
+ if (!isFirstUpdate) {
18967
+ return refresh();
18968
+ }
18969
+ if (!ratio) {
18970
+ timeoutId = setTimeout(() => {
18971
+ refresh(false, 1e-7);
18972
+ }, 100);
18973
+ } else {
18974
+ refresh(false, ratio);
18975
+ }
18976
+ }
18977
+ isFirstUpdate = false;
18978
+ }
18979
+
18980
+ // Older browsers don't support a `document` as the root and will throw an
18981
+ // error.
18982
+ try {
18983
+ io = new IntersectionObserver(handleObserve, {
18984
+ ...options,
18985
+ // Handle <iframe>s
18986
+ root: root.ownerDocument
18987
+ });
18988
+ } catch (e) {
18989
+ io = new IntersectionObserver(handleObserve, options);
18990
+ }
18991
+ io.observe(element);
18992
+ }
18993
+ refresh(true);
18994
+ return cleanup;
18995
+ }
18996
+
18997
+ /**
18998
+ * Automatically updates the position of the floating element when necessary.
18999
+ * Should only be called when the floating element is mounted on the DOM or
19000
+ * visible on the screen.
19001
+ * @returns cleanup function that should be invoked when the floating element is
19002
+ * removed from the DOM or hidden from the screen.
19003
+ * @see https://floating-ui.com/docs/autoUpdate
19004
+ */
19005
+ function autoUpdate(reference, floating, update, options) {
19006
+ if (options === void 0) {
19007
+ options = {};
19008
+ }
19009
+ const {
19010
+ ancestorScroll = true,
19011
+ ancestorResize = true,
19012
+ elementResize = typeof ResizeObserver === 'function',
19013
+ layoutShift = typeof IntersectionObserver === 'function',
19014
+ animationFrame = false
19015
+ } = options;
19016
+ const referenceEl = unwrapElement(reference);
19017
+ const ancestors = ancestorScroll || ancestorResize ? [...(referenceEl ? getOverflowAncestors(referenceEl) : []), ...getOverflowAncestors(floating)] : [];
19018
+ ancestors.forEach(ancestor => {
19019
+ ancestorScroll && ancestor.addEventListener('scroll', update, {
19020
+ passive: true
19021
+ });
19022
+ ancestorResize && ancestor.addEventListener('resize', update);
19023
+ });
19024
+ const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
19025
+ let reobserveFrame = -1;
19026
+ let resizeObserver = null;
19027
+ if (elementResize) {
19028
+ resizeObserver = new ResizeObserver(_ref => {
19029
+ let [firstEntry] = _ref;
19030
+ if (firstEntry && firstEntry.target === referenceEl && resizeObserver) {
19031
+ // Prevent update loops when using the `size` middleware.
19032
+ // https://github.com/floating-ui/floating-ui/issues/1740
19033
+ resizeObserver.unobserve(floating);
19034
+ cancelAnimationFrame(reobserveFrame);
19035
+ reobserveFrame = requestAnimationFrame(() => {
19036
+ resizeObserver && resizeObserver.observe(floating);
19037
+ });
19038
+ }
19039
+ update();
19040
+ });
19041
+ if (referenceEl && !animationFrame) {
19042
+ resizeObserver.observe(referenceEl);
19043
+ }
19044
+ resizeObserver.observe(floating);
19045
+ }
19046
+ let frameId;
19047
+ let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
19048
+ if (animationFrame) {
19049
+ frameLoop();
19050
+ }
19051
+ function frameLoop() {
19052
+ const nextRefRect = getBoundingClientRect(reference);
19053
+ if (prevRefRect && (nextRefRect.x !== prevRefRect.x || nextRefRect.y !== prevRefRect.y || nextRefRect.width !== prevRefRect.width || nextRefRect.height !== prevRefRect.height)) {
19054
+ update();
19055
+ }
19056
+ prevRefRect = nextRefRect;
19057
+ frameId = requestAnimationFrame(frameLoop);
19058
+ }
19059
+ update();
19060
+ return () => {
19061
+ ancestors.forEach(ancestor => {
19062
+ ancestorScroll && ancestor.removeEventListener('scroll', update);
19063
+ ancestorResize && ancestor.removeEventListener('resize', update);
19064
+ });
19065
+ cleanupIo && cleanupIo();
19066
+ resizeObserver && resizeObserver.disconnect();
19067
+ resizeObserver = null;
19068
+ if (animationFrame) {
19069
+ cancelAnimationFrame(frameId);
19070
+ }
19071
+ };
19072
+ }
19073
+
19074
+ /**
19075
+ * Computes the `x` and `y` coordinates that will place the floating element
19076
+ * next to a reference element when it is given a certain CSS positioning
19077
+ * strategy.
19078
+ */
19079
+ const computePosition = (reference, floating, options) => {
19080
+ // This caches the expensive `getClippingElementAncestors` function so that
19081
+ // multiple lifecycle resets re-use the same result. It only lives for a
19082
+ // single call. If other functions become expensive, we can add them as well.
19083
+ const cache = new Map();
19084
+ const mergedOptions = {
19085
+ platform,
19086
+ ...options
19087
+ };
19088
+ const platformWithCache = {
19089
+ ...mergedOptions.platform,
19090
+ _c: cache
19091
+ };
19092
+ return computePosition$1(reference, floating, {
19093
+ ...mergedOptions,
19094
+ platform: platformWithCache
19095
+ });
19096
+ };
19097
+
19098
+ var index$2 = typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect;
19099
+
19100
+ // Fork of `fast-deep-equal` that only does the comparisons we need and compares
19101
+ // functions
19102
+ function deepEqual(a, b) {
19103
+ if (a === b) {
19104
+ return true;
19105
+ }
19106
+ if (typeof a !== typeof b) {
19107
+ return false;
19108
+ }
19109
+ if (typeof a === 'function' && a.toString() === b.toString()) {
19110
+ return true;
19111
+ }
19112
+ let length, i, keys;
19113
+ if (a && b && typeof a == 'object') {
19114
+ if (Array.isArray(a)) {
19115
+ length = a.length;
19116
+ if (length != b.length) return false;
19117
+ for (i = length; i-- !== 0;) {
19118
+ if (!deepEqual(a[i], b[i])) {
19119
+ return false;
19120
+ }
19121
+ }
19122
+ return true;
19123
+ }
19124
+ keys = Object.keys(a);
19125
+ length = keys.length;
19126
+ if (length !== Object.keys(b).length) {
19127
+ return false;
19128
+ }
19129
+ for (i = length; i-- !== 0;) {
19130
+ if (!{}.hasOwnProperty.call(b, keys[i])) {
19131
+ return false;
19132
+ }
19133
+ }
19134
+ for (i = length; i-- !== 0;) {
19135
+ const key = keys[i];
19136
+ if (key === '_owner' && a.$$typeof) {
19137
+ continue;
19138
+ }
19139
+ if (!deepEqual(a[key], b[key])) {
19140
+ return false;
19141
+ }
19142
+ }
19143
+ return true;
19144
+ }
19145
+ return a !== a && b !== b;
19146
+ }
19147
+
19148
+ function getDPR(element) {
19149
+ if (typeof window === 'undefined') {
19150
+ return 1;
19151
+ }
19152
+ const win = element.ownerDocument.defaultView || window;
19153
+ return win.devicePixelRatio || 1;
19154
+ }
19155
+
19156
+ function roundByDPR(element, value) {
19157
+ const dpr = getDPR(element);
19158
+ return Math.round(value * dpr) / dpr;
19159
+ }
19160
+
19161
+ function useLatestRef(value) {
19162
+ const ref = React__namespace.useRef(value);
19163
+ index$2(() => {
19164
+ ref.current = value;
19165
+ });
19166
+ return ref;
19167
+ }
19168
+
19169
+ /**
19170
+ * Provides data to position a floating element.
19171
+ * @see https://floating-ui.com/docs/react
19172
+ */
19173
+ function useFloating(options) {
19174
+ if (options === void 0) {
19175
+ options = {};
19176
+ }
19177
+ const {
19178
+ placement = 'bottom',
19179
+ strategy = 'absolute',
19180
+ middleware = [],
19181
+ platform,
19182
+ elements: {
19183
+ reference: externalReference,
19184
+ floating: externalFloating
19185
+ } = {},
19186
+ transform = true,
19187
+ whileElementsMounted,
19188
+ open
19189
+ } = options;
19190
+ const [data, setData] = React__namespace.useState({
19191
+ x: 0,
19192
+ y: 0,
19193
+ strategy,
19194
+ placement,
19195
+ middlewareData: {},
19196
+ isPositioned: false
19197
+ });
19198
+ const [latestMiddleware, setLatestMiddleware] = React__namespace.useState(middleware);
19199
+ if (!deepEqual(latestMiddleware, middleware)) {
19200
+ setLatestMiddleware(middleware);
19201
+ }
19202
+ const [_reference, _setReference] = React__namespace.useState(null);
19203
+ const [_floating, _setFloating] = React__namespace.useState(null);
19204
+ const setReference = React__namespace.useCallback(node => {
19205
+ if (node != referenceRef.current) {
19206
+ referenceRef.current = node;
19207
+ _setReference(node);
19208
+ }
19209
+ }, [_setReference]);
19210
+ const setFloating = React__namespace.useCallback(node => {
19211
+ if (node !== floatingRef.current) {
19212
+ floatingRef.current = node;
19213
+ _setFloating(node);
19214
+ }
19215
+ }, [_setFloating]);
19216
+ const referenceEl = externalReference || _reference;
19217
+ const floatingEl = externalFloating || _floating;
19218
+ const referenceRef = React__namespace.useRef(null);
19219
+ const floatingRef = React__namespace.useRef(null);
19220
+ const dataRef = React__namespace.useRef(data);
19221
+ const whileElementsMountedRef = useLatestRef(whileElementsMounted);
19222
+ const platformRef = useLatestRef(platform);
19223
+ const update = React__namespace.useCallback(() => {
19224
+ if (!referenceRef.current || !floatingRef.current) {
19225
+ return;
19226
+ }
19227
+ const config = {
19228
+ placement,
19229
+ strategy,
19230
+ middleware: latestMiddleware
19231
+ };
19232
+ if (platformRef.current) {
19233
+ config.platform = platformRef.current;
19234
+ }
19235
+ computePosition(referenceRef.current, floatingRef.current, config).then(data => {
19236
+ const fullData = {
19237
+ ...data,
19238
+ isPositioned: true
19239
+ };
19240
+ if (isMountedRef.current && !deepEqual(dataRef.current, fullData)) {
19241
+ dataRef.current = fullData;
19242
+ ReactDOM__namespace.flushSync(() => {
19243
+ setData(fullData);
19244
+ });
19245
+ }
19246
+ });
19247
+ }, [latestMiddleware, placement, strategy, platformRef]);
19248
+ index$2(() => {
19249
+ if (open === false && dataRef.current.isPositioned) {
19250
+ dataRef.current.isPositioned = false;
19251
+ setData(data => ({
19252
+ ...data,
19253
+ isPositioned: false
19254
+ }));
19255
+ }
19256
+ }, [open]);
19257
+ const isMountedRef = React__namespace.useRef(false);
19258
+ index$2(() => {
19259
+ isMountedRef.current = true;
19260
+ return () => {
19261
+ isMountedRef.current = false;
19262
+ };
19263
+ }, []);
19264
+ index$2(() => {
19265
+ if (referenceEl) referenceRef.current = referenceEl;
19266
+ if (floatingEl) floatingRef.current = floatingEl;
19267
+ if (referenceEl && floatingEl) {
19268
+ if (whileElementsMountedRef.current) {
19269
+ return whileElementsMountedRef.current(referenceEl, floatingEl, update);
19270
+ } else {
19271
+ update();
19272
+ }
19273
+ }
19274
+ }, [referenceEl, floatingEl, update, whileElementsMountedRef]);
19275
+ const refs = React__namespace.useMemo(() => ({
19276
+ reference: referenceRef,
19277
+ floating: floatingRef,
19278
+ setReference,
19279
+ setFloating
19280
+ }), [setReference, setFloating]);
19281
+ const elements = React__namespace.useMemo(() => ({
19282
+ reference: referenceEl,
19283
+ floating: floatingEl
19284
+ }), [referenceEl, floatingEl]);
19285
+ const floatingStyles = React__namespace.useMemo(() => {
19286
+ const initialStyles = {
19287
+ position: strategy,
19288
+ left: 0,
19289
+ top: 0
19290
+ };
19291
+ if (!elements.floating) {
19292
+ return initialStyles;
19293
+ }
19294
+ const x = roundByDPR(elements.floating, data.x);
19295
+ const y = roundByDPR(elements.floating, data.y);
19296
+ if (transform) {
19297
+ return {
19298
+ ...initialStyles,
19299
+ transform: "translate(" + x + "px, " + y + "px)",
19300
+ ...(getDPR(elements.floating) >= 1.5 && {
19301
+ willChange: 'transform'
19302
+ })
19303
+ };
19304
+ }
19305
+ return {
19306
+ position: strategy,
19307
+ left: x,
19308
+ top: y
19309
+ };
19310
+ }, [strategy, transform, elements.floating, data.x, data.y]);
19311
+ return React__namespace.useMemo(() => ({
19312
+ ...data,
19313
+ update,
19314
+ refs,
19315
+ elements,
19316
+ floatingStyles
19317
+ }), [data, update, refs, elements, floatingStyles]);
19318
+ }
19319
+
19320
+ const useFocusZone = (settings = {}, dependencies = []) => {
19321
+ const containerRef = useProvidedOrCreatedRef(settings.containerRef);
19322
+ const useActiveDescendant = !!settings.activeDescendantFocus;
19323
+ const passedActiveDescendantRef = typeof settings.activeDescendantFocus === 'boolean' || !settings.activeDescendantFocus ? undefined : settings.activeDescendantFocus;
19324
+ const activeDescendantControlRef = useProvidedOrCreatedRef(passedActiveDescendantRef);
19325
+ const disabled = settings.disabled;
19326
+ const abortController = React.useRef();
19327
+ React.useEffect(() => {
19328
+ if (containerRef.current instanceof HTMLElement && (!useActiveDescendant || activeDescendantControlRef.current instanceof HTMLElement)) {
19329
+ if (!disabled) {
19330
+ const defaultSettings = {
19331
+ ...settings,
19332
+ activeDescendantControl: activeDescendantControlRef.current ?? undefined
19333
+ };
19334
+ abortController.current = focusZone(containerRef.current, defaultSettings);
19335
+ return () => {
19336
+ abortController.current?.abort();
19337
+ };
19338
+ } else {
19339
+ abortController.current?.abort();
19340
+ }
19341
+ }
19342
+ }, [disabled, ...dependencies]);
19343
+ return {
19344
+ containerRef,
19345
+ activeDescendantControlRef
19346
+ };
19347
+ };
19348
+
19349
+ const useToggleHandler = ({
19350
+ initialState = false
19351
+ }) => {
19352
+ const [state, setState] = React.useState(initialState);
19353
+ const on = () => {
19354
+ setState(true);
19355
+ };
19356
+ const off = () => {
19357
+ setState(false);
19358
+ };
19359
+ const toggle = React.useCallback(() => {
19360
+ setState(prev => !prev);
19361
+ }, []);
19362
+ return {
19363
+ state,
19364
+ on,
19365
+ off,
19366
+ toggle
19367
+ };
19368
+ };
19369
+
19370
+ const OverlayPopper = ({
19371
+ children: propChildren,
19372
+ renderOverlay,
19373
+ placement = 'bottom-start',
19374
+ focusZoneSettings,
19375
+ focusTrapSettings
19376
+ }) => {
19377
+ const {
19378
+ refs,
19379
+ floatingStyles,
19380
+ isPositioned
19381
+ } = useFloating({
19382
+ placement,
19383
+ whileElementsMounted: autoUpdate,
19384
+ middleware: [offset(space[1]), flip(), shift()],
19385
+ strategy: 'fixed'
19386
+ });
19387
+ const {
19388
+ state: isOpen,
19389
+ toggle: toggleOverlay,
19390
+ off: closeOverlay
19391
+ } = useToggleHandler({
19392
+ initialState: false
19393
+ });
19394
+ const children = React.Children.map(propChildren, child => /*#__PURE__*/React.cloneElement(child, {
19395
+ onClick: toggleOverlay,
19396
+ tabIndex: 0,
19397
+ ...{
19398
+ ref: refs.setReference
19399
+ }
19400
+ }));
19401
+ useFocusZone({
19402
+ containerRef: refs.floating,
19403
+ disabled: !isOpen || !isPositioned,
19404
+ ...focusZoneSettings
19405
+ });
19406
+ useFocusTrap({
19407
+ containerRef: refs.floating,
19408
+ disabled: !isOpen || !isPositioned,
19409
+ ...focusTrapSettings
19410
+ });
19411
+ return /*#__PURE__*/jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, {
19412
+ children: [children, /*#__PURE__*/jsxRuntimeExports.jsx(Overlay$1, {
19413
+ ref: refs.setFloating,
19414
+ isOpen: isOpen,
19415
+ onDismiss: closeOverlay,
19416
+ ignoreOutsideClickRefs: [refs.reference],
19417
+ style: floatingStyles,
19418
+ children: renderOverlay({
19419
+ isOpen,
19420
+ closeOverlay
19421
+ })
19422
+ })]
19423
+ });
19424
+ };
19425
+
19426
+ const Space = styled__default.default.div`
19427
+ width: inherit;
19428
+ ${space$1};
19429
+ ${sx}
19430
+ `;
19431
+
19432
+ const Stack = /*#__PURE__*/React.forwardRef(({
19433
+ gapX = 0,
19434
+ gapY = 0,
19435
+ children,
19436
+ alignItems = 'center',
19437
+ ...props
19438
+ }, ref) => /*#__PURE__*/jsxRuntimeExports.jsx(BaseStack, {
19439
+ ref: ref,
19440
+ alignItems: alignItems,
19441
+ gapX: gapX,
19442
+ gapY: gapY,
19443
+ ...props,
19444
+ children: children
19445
+ }));
19446
+ const BaseStack = styled__default.default(View)({
19447
+ display: 'flex',
19448
+ flexDirection: 'row',
19449
+ flexWrap: 'wrap'
19450
+ }, variant({
19451
+ prop: 'gapX',
19452
+ variants: Object.fromEntries(Object.entries(space).map(([key, value]) => {
19453
+ const styleValue = {
19454
+ '& > *': {
19455
+ px: forcePixelValue(value / 2)
19456
+ },
19457
+ 'mx': forcePixelValue(-value / 2)
19458
+ };
19459
+ return [key, styleValue];
19460
+ }))
19461
+ }), variant({
19462
+ prop: 'gapY',
19463
+ variants: Object.fromEntries(Object.entries(space).map(([key, value]) => {
19464
+ const styleValue = {
19465
+ '& > *': {
19466
+ mt: forcePixelValue(value)
19467
+ },
19468
+ 'mt': forcePixelValue(-value)
19469
+ };
19470
+ return [key, styleValue];
19471
+ }))
19472
+ }));
19473
+ const Item = ({
19474
+ children,
19475
+ ...props
19476
+ }) => /*#__PURE__*/jsxRuntimeExports.jsx(View, {
19477
+ ...props,
19478
+ children: children
19479
+ });
19480
+ var Stack$1 = Object.assign(Stack, {
19481
+ Item
19482
+ });
19483
+
19484
+ const StyledIcon = ({
19485
+ icon: Icon,
19486
+ sx,
17105
19487
  ...props
17106
19488
  }) => /*#__PURE__*/jsxRuntimeExports.jsx(View, {
17107
19489
  ...props,
@@ -18292,14 +20674,6 @@ var index$1 = Object.assign(Tab, {
18292
20674
  Item: TabItem
18293
20675
  });
18294
20676
 
18295
- /**
18296
- * 제공된 `ref`가 없는 경우 새로운 `ref`를 만들어 사용하고, 있는 경우 제공된 ref를 사용할 수 있는 훅입니다.
18297
- */
18298
- const useProvidedOrCreatedRef = providedRef => {
18299
- const createdRef = React.useRef(null);
18300
- return providedRef ?? createdRef;
18301
- };
18302
-
18303
20677
  const Textarea = /*#__PURE__*/React.forwardRef(({
18304
20678
  disabled,
18305
20679
  ...props
@@ -19427,32 +21801,11 @@ const useOutsideClick = ({
19427
21801
  });
19428
21802
  };
19429
21803
 
19430
- const useToggleHandler = ({
19431
- initialState = false
19432
- }) => {
19433
- const [state, setState] = React.useState(initialState);
19434
- const on = () => {
19435
- setState(true);
19436
- };
19437
- const off = () => {
19438
- setState(false);
19439
- };
19440
- const toggle = React.useCallback(() => {
19441
- setState(prev => !prev);
19442
- }, []);
19443
- return {
19444
- state,
19445
- on,
19446
- off,
19447
- toggle
19448
- };
19449
- };
19450
-
19451
21804
  exports.AnimatePresence = AnimatePresence;
19452
- exports.Breadcrumbs = index$3;
21805
+ exports.Breadcrumbs = index$4;
19453
21806
  exports.Button = Button;
19454
21807
  exports.Chip = Chip;
19455
- exports.Dialog = index$2;
21808
+ exports.Dialog = index$3;
19456
21809
  exports.DialogHandler = DialogHandler;
19457
21810
  exports.EnigmaUI = index;
19458
21811
  exports.GradientText = GradientText;
@@ -19463,6 +21816,8 @@ exports.IconToggleButton = IconToggleButton;
19463
21816
  exports.Image = Image;
19464
21817
  exports.ItemList = ItemList;
19465
21818
  exports.MotionView = MotionView;
21819
+ exports.Overlay = Overlay$1;
21820
+ exports.OverlayPopper = OverlayPopper;
19466
21821
  exports.Space = Space;
19467
21822
  exports.Spinner = Spinner;
19468
21823
  exports.Stack = Stack$1;
@@ -19481,6 +21836,10 @@ exports.sx = sx;
19481
21836
  exports.textDecoration = textDecoration;
19482
21837
  exports.theme = theme;
19483
21838
  exports.useDevice = useDevice;
21839
+ exports.useDialogHandler = useDialogHandler;
21840
+ exports.useFocusTrap = useFocusTrap;
21841
+ exports.useFocusZone = useFocusZone;
21842
+ exports.useMediaQuery = useMediaQuery;
19484
21843
  exports.useOutsideClick = useOutsideClick;
19485
21844
  exports.useProvidedOrCreatedRef = useProvidedOrCreatedRef;
19486
21845
  exports.useResize = useResize;