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AAI,CAAC,oBACH;QAEF,oEAAoE;QACpE,UAAU,OAAO,GAAG;QACpB,UAAU,OAAO,GAAG;QACpB,WAAW;IACb;IAEA,IAAI,UAAU;QACZ,IAAI,YAAY,CAAA,GAAA,yCAAa;QAC7B,IAAI,WAAW;YACb,UAAU,OAAO,GAAG;YACpB;QACF;IACF;IAEA,IAAI,SAAS;QACX,UAAU,OAAO,GAAG;QACpB,UAAU,OAAO,GAAG;QACpB,WAAW;IACb;IAEA,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,yCAAO,EAAE;oBAC1B;sBACA;oBACA;IACF;IAEA,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,yCAAW,EAAE;oBAClC;iBACA;gBACA;IACF,GAAG;IAEH,OAAO;QACL,cAAc;YACZ,oBAAoB,MAAM,MAAM,GAAG,YAAY;YAC/C,GAAG,CAAA,GAAA,yCAAS,EAAE,gBAAgB,YAAY;gBACxC,eAAe;gBACf,WAAW;YACb,EAAE;YACF,UAAU;QACZ;QACA,cAAc;YACZ,IAAI;QACN;IACF;AACF","sources":["packages/react-aria/src/tooltip/useTooltipTrigger.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';\nimport {getInteractionModality, isFocusVisible} from '../interactions/useFocusVisible';\nimport {mergeProps} from '../utils/mergeProps';\nimport {TooltipTriggerProps, TooltipTriggerState} from 'react-stately/useTooltipTriggerState';\nimport {useEffect, useRef} from 'react';\nimport {useFocusable} from '../interactions/useFocusable';\nimport {useHover} from '../interactions/useHover';\nimport {useId} from '../utils/useId';\n\nexport interface TooltipTriggerAria {\n  /**\n   * Props for the trigger element.\n   */\n  triggerProps: DOMAttributes,\n\n  /**\n   * Props for the overlay container element.\n   */\n  tooltipProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a tooltip trigger, e.g. a button\n * that shows a description when focused or hovered.\n */\nexport function useTooltipTrigger(props: TooltipTriggerProps, state: TooltipTriggerState, ref: RefObject<FocusableElement | null>) : TooltipTriggerAria {\n  let {\n    isDisabled,\n    trigger,\n    shouldCloseOnPress = true\n  } = props;\n\n  let tooltipId = useId();\n\n  let isHovered = useRef(false);\n  let isFocused = useRef(false);\n\n  let handleShow = () => {\n    if (isHovered.current || isFocused.current) {\n      state.open(isFocused.current);\n    }\n  };\n\n  let handleHide = (immediate?: boolean) => {\n    if (!isHovered.current && !isFocused.current) {\n      state.close(immediate);\n    }\n  };\n\n  useEffect(() => {\n    let onKeyDown = (e) => {\n      if (ref && ref.current) {\n        // Escape after clicking something can give it keyboard focus\n        // dismiss tooltip on esc key press\n        if (e.key === 'Escape') {\n          e.stopPropagation();\n          state.close(true);\n        }\n      }\n    };\n    if (state.isOpen) {\n      document.addEventListener('keydown', onKeyDown, true);\n      return () => {\n        document.removeEventListener('keydown', onKeyDown, true);\n      };\n    }\n  }, [ref, state]);\n\n  let onHoverStart = () => {\n    if (trigger === 'focus') {\n      return;\n    }\n    // In chrome, if you hover a trigger, then another element obscures it, due to keyboard\n    // interactions for example, hover will end. When hover is restored after that element disappears,\n    // focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover\n    // is the result of moving the mouse.\n    if (getInteractionModality() === 'pointer') {\n      isHovered.current = true;\n    } else {\n      isHovered.current = false;\n    }\n    handleShow();\n  };\n\n  let onHoverEnd = () => {\n    if (trigger === 'focus') {\n      return;\n    }\n    // no matter how the trigger is left, we should close the tooltip\n    isFocused.current = false;\n    isHovered.current = false;\n    handleHide();\n  };\n\n  let onPressStart = () => {\n    // if shouldCloseOnPress is false, we should not close the tooltip\n    if (!shouldCloseOnPress) {\n      return;\n    }\n    // no matter how the trigger is pressed, we should close the tooltip\n    isFocused.current = false;\n    isHovered.current = false;\n    handleHide(true);\n  };\n\n  let onFocus = () => {\n    let isVisible = isFocusVisible();\n    if (isVisible) {\n      isFocused.current = true;\n      handleShow();\n    }\n  };\n\n  let onBlur = () => {\n    isFocused.current = false;\n    isHovered.current = false;\n    handleHide(true);\n  };\n\n  let {hoverProps} = useHover({\n    isDisabled,\n    onHoverStart,\n    onHoverEnd\n  });\n\n  let {focusableProps} = useFocusable({\n    isDisabled,\n    onFocus,\n    onBlur\n  }, ref);\n\n  return {\n    triggerProps: {\n      'aria-describedby': state.isOpen ? tooltipId : undefined,\n      ...mergeProps(focusableProps, hoverProps, {\n        onPointerDown: onPressStart,\n        onKeyDown: onPressStart\n      }),\n      tabIndex: undefined\n    },\n    tooltipProps: {\n      id: tooltipId\n    }\n  };\n}\n"],"names":[],"version":3,"file":"useTooltipTrigger.mjs.map"}