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AAG;YACvB,cAAc,OAAO;QACvB,GAAG;QAGL,IAAI,2CAAqB;YACvB,aAAa;YACb,4CAAsB;QACxB;QACA,IAAI,sCAAgB;YAClB,IAAI,6CACF,aAAa;YAEf,8CAAwB,WAAW;gBACjC,OAAO,8BAAQ,CAAC,GAAG;gBACnB,8CAAwB;gBACxB,uCAAiB;YACnB,GAAG,KAAK,GAAG,CAAC,wCAAkB;QAChC;IACF;IAEA,IAAI,gBAAgB;QAClB;QACA;QACA,IAAI,CAAC,UAAU,CAAC,sCAAgB;YAC9B,IAAI,2CACF,aAAa;YAGf,4CAAsB,WAAW;gBAC/B,4CAAsB;gBACtB,uCAAiB;gBACjB;YACF,GAAG;QACL,OAAO,IAAI,CAAC,QACV;IAEJ;IAEA,CAAA,GAAA,sBAAQ,EAAE;QACR,cAAc,OAAO,GAAG;IAC1B,GAAG;QAAC;KAAM;IAGV,CAAA,GAAA,sBAAQ,EAAE;QACR,OAAO;YACL,IAAI,aAAa,OAAO,EACtB,aAAa,aAAa,OAAO;YAEnC,IAAI,UAAU,8BAAQ,CAAC,GAAG;YAC1B,IAAI,SACF,OAAO,8BAAQ,CAAC,GAAG;QAEvB;IACF,GAAG;QAAC;KAAG;IAEP,OAAO;gBACL;QACA,MAAM,CAAC;YACL,IAAI,CAAC,aAAa,QAAQ,KAAK,CAAC,aAAa,OAAO,EAClD;iBAEA;QAEJ;QACA,OAAO;IACT;AACF","sources":["packages/react-stately/src/tooltip/useTooltipTriggerState.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 {OverlayTriggerProps, useOverlayTriggerState} from '../overlays/useOverlayTriggerState';\nimport {useEffect, useMemo, useRef} from 'react';\n\nexport interface TooltipTriggerProps extends OverlayTriggerProps {\n  /**\n   * Whether the tooltip should be disabled, independent from the trigger.\n   */\n  isDisabled?: boolean,\n\n  /**\n   * The delay time for the tooltip to show up. [See guidelines](https://spectrum.adobe.com/page/tooltip/#Immediate-or-delayed-appearance).\n   * @default 1500\n   */\n  delay?: number,\n\n  /**\n   * The delay time for the tooltip to close. [See guidelines](https://spectrum.adobe.com/page/tooltip/#Warmup-and-cooldown).\n   * @default 500\n   */\n  closeDelay?: number,\n\n  /**\n   * By default, opens for both focus and hover. Can be made to open only for focus.\n   * @default 'hover'\n   */\n  trigger?: 'hover' | 'focus',\n\n  /**\n   * Whether the tooltip should close when the trigger is pressed.\n   * @default true\n   */\n  shouldCloseOnPress?: boolean\n}\n\nconst TOOLTIP_DELAY = 1500; // this seems to be a 1.5 second delay, check with design\nconst TOOLTIP_COOLDOWN = 500;\n\nexport interface TooltipTriggerState {\n  /** Whether the tooltip is currently showing. */\n  isOpen: boolean,\n  /**\n   * Shows the tooltip. By default, the tooltip becomes visible after a delay\n   * depending on a global warmup timer. The `immediate` option shows the\n   * tooltip immediately instead.\n   */\n  open(immediate?: boolean): void,\n  /** Hides the tooltip. */\n  close(immediate?: boolean): void\n}\n\nlet tooltips = {};\nlet tooltipId = 0;\nlet globalWarmedUp = false;\nlet globalWarmUpTimeout: ReturnType<typeof setTimeout> | null = null;\nlet globalCooldownTimeout: ReturnType<typeof setTimeout> | null = null;\n\n/**\n * Manages state for a tooltip trigger. Tracks whether the tooltip is open, and provides\n * methods to toggle this state. Ensures only one tooltip is open at a time and controls\n * the delay for showing a tooltip.\n */\nexport function useTooltipTriggerState(props: TooltipTriggerProps = {}): TooltipTriggerState {\n  let {delay = TOOLTIP_DELAY, closeDelay = TOOLTIP_COOLDOWN} = props;\n  let {isOpen, open, close} = useOverlayTriggerState(props);\n  let id = useMemo(() => `${++tooltipId}`, []);\n  let closeTimeout = useRef<ReturnType<typeof setTimeout> | null>(null);\n  let closeCallback = useRef<() => void>(close);\n\n  let ensureTooltipEntry = () => {\n    tooltips[id] = hideTooltip;\n  };\n\n  let closeOpenTooltips = () => {\n    for (let hideTooltipId in tooltips) {\n      if (hideTooltipId !== id) {\n        tooltips[hideTooltipId](true);\n        delete tooltips[hideTooltipId];\n      }\n    }\n  };\n\n  let showTooltip = () => {\n    if (closeTimeout.current) {\n      clearTimeout(closeTimeout.current);\n    }\n    closeTimeout.current = null;\n    closeOpenTooltips();\n    ensureTooltipEntry();\n    globalWarmedUp = true;\n    open();\n    if (globalWarmUpTimeout) {\n      clearTimeout(globalWarmUpTimeout);\n      globalWarmUpTimeout = null;\n    }\n    if (globalCooldownTimeout) {\n      clearTimeout(globalCooldownTimeout);\n      globalCooldownTimeout = null;\n    }\n  };\n\n  let hideTooltip = (immediate?: boolean) => {\n    if (immediate || closeDelay <= 0) {\n      if (closeTimeout.current) {\n        clearTimeout(closeTimeout.current);\n      }\n      closeTimeout.current = null;\n      closeCallback.current();\n    } else if (!closeTimeout.current) {\n      closeTimeout.current = setTimeout(() => {\n        closeTimeout.current = null;\n        closeCallback.current();\n      }, closeDelay);\n    }\n\n    if (globalWarmUpTimeout) {\n      clearTimeout(globalWarmUpTimeout);\n      globalWarmUpTimeout = null;\n    }\n    if (globalWarmedUp) {\n      if (globalCooldownTimeout) {\n        clearTimeout(globalCooldownTimeout);\n      }\n      globalCooldownTimeout = setTimeout(() => {\n        delete tooltips[id];\n        globalCooldownTimeout = null;\n        globalWarmedUp = false;\n      }, Math.max(TOOLTIP_COOLDOWN, closeDelay));\n    }\n  };\n\n  let warmupTooltip = () => {\n    closeOpenTooltips();\n    ensureTooltipEntry();\n    if (!isOpen && !globalWarmedUp) {\n      if (globalWarmUpTimeout) {\n        clearTimeout(globalWarmUpTimeout);\n      }\n\n      globalWarmUpTimeout = setTimeout(() => {\n        globalWarmUpTimeout = null;\n        globalWarmedUp = true;\n        showTooltip();\n      }, delay);\n    } else if (!isOpen) {\n      showTooltip();\n    }\n  };\n\n  useEffect(() => {\n    closeCallback.current = close;\n  }, [close]);\n\n\n  useEffect(() => {\n    return () => {\n      if (closeTimeout.current) {\n        clearTimeout(closeTimeout.current);\n      }\n      let tooltip = tooltips[id];\n      if (tooltip) {\n        delete tooltips[id];\n      }\n    };\n  }, [id]);\n\n  return {\n    isOpen,\n    open: (immediate) => {\n      if (!immediate && delay > 0 && !closeTimeout.current) {\n        warmupTooltip();\n      } else {\n        showTooltip();\n      }\n    },\n    close: hideTooltip\n  };\n}\n"],"names":[],"version":3,"file":"useTooltipTriggerState.cjs.map"}