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AAC,QAAQ,QAAQ;YAE7C,IAAI,CAAC,sCACH,OAAO,mBAAmB,CAAC,UAAU;iBAErC,qCAAe,mBAAmB,CAAC,UAAU;QAEjD;IACF,GAAG,EAAE;IAEL,OAAO;AACT;AAEA;;CAEC,GACD,SAAS;IACP,OAAO;QACL,+FAA+F;QAC/F,OAAO,uCAIH,KAAK,GAAG,CAAC,qCAAe,KAAK,GAAG,qCAAe,KAAK,EAAE,SAAS,eAAe,CAAC,WAAW,IAC1F,SAAS,eAAe,CAAC,WAAW;QACxC,QAAQ,uCACJ,qCAAe,MAAM,GAAG,qCAAe,KAAK,GAC5C,SAAS,eAAe,CAAC,YAAY;IAC3C;AACF","sources":["packages/react-aria/src/utils/useViewportSize.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 {getActiveElement, getEventTarget} from './shadowdom/DOMFunctions';\nimport {isIOS} from './platform';\nimport {useEffect, useState} from 'react';\nimport {useIsSSR} from '../ssr/SSRProvider';\nimport {willOpenKeyboard} from './keyboard';\n\ninterface ViewportSize {\n  width: number,\n  height: number\n}\n\nlet visualViewport = typeof document !== 'undefined' && window.visualViewport;\n\nexport function useViewportSize(): ViewportSize {\n  let isSSR = useIsSSR();\n  let [size, setSize] = useState(() => isSSR ? {width: 0, height: 0} : getViewportSize());\n\n  useEffect(() => {\n    let updateSize = (newSize: ViewportSize) => {\n      setSize(size => {\n        if (newSize.width === size.width && newSize.height === size.height) {\n          return size;\n        }\n        return newSize;\n      });\n    };\n\n    // Use visualViewport api to track available height even on iOS virtual keyboard opening\n    let onResize = () => {\n      // Ignore updates when zoomed.\n      if (visualViewport && visualViewport.scale > 1) {\n        return;\n      }\n\n      updateSize(getViewportSize());\n    };\n\n    // When closing the keyboard, iOS does not fire the visual viewport resize event until the animation is complete.\n    // We can anticipate this and resize early by handling the blur event and using the layout size.\n    let frame: number;\n    let onBlur = (e: FocusEvent) => {\n      if (visualViewport && visualViewport.scale > 1) {\n        return;\n      }\n\n      if (willOpenKeyboard(getEventTarget(e) as Element)) {\n        // Wait one frame to see if a new element gets focused.\n        frame = requestAnimationFrame(() => {\n          let activeElement = getActiveElement();\n          if (!activeElement || !willOpenKeyboard(activeElement)) {\n            updateSize({width: document.documentElement.clientWidth, height: document.documentElement.clientHeight});\n          }\n        });\n      }\n    };\n\n    updateSize(getViewportSize());\n\n    if (isIOS()) {\n      window.addEventListener('blur', onBlur, true);\n    }\n\n    if (!visualViewport) {\n      window.addEventListener('resize', onResize);\n    } else {\n      visualViewport.addEventListener('resize', onResize);\n    }\n\n    return () => {\n      cancelAnimationFrame(frame);\n      if (isIOS()) {\n        window.removeEventListener('blur', onBlur, true);\n      }\n      if (!visualViewport) {\n        window.removeEventListener('resize', onResize);\n      } else {\n        visualViewport.removeEventListener('resize', onResize);\n      }\n    };\n  }, []);\n\n  return size;\n}\n\n/**\n * Get the viewport size without the scrollbar.\n */\nfunction getViewportSize(): ViewportSize {\n  return {\n    // Multiply by the visualViewport scale to get the \"natural\" size, unaffected by pinch zooming.\n    width: visualViewport\n      // The visual viewport width may include the scrollbar gutter. We should use the minimum width between\n      // the visual viewport and the document element to ensure that the scrollbar width is always excluded.\n      // See: https://github.com/w3c/csswg-drafts/issues/8099\n      ? Math.min(visualViewport.width * visualViewport.scale, document.documentElement.clientWidth)\n      : document.documentElement.clientWidth,\n    height: visualViewport\n      ? visualViewport.height * visualViewport.scale\n      : document.documentElement.clientHeight\n  };\n}\n"],"names":[],"version":3,"file":"useViewportSize.cjs.map"}