{"version":3,"file":"useVisualViewportSize.mjs","names":[],"sources":["../../../../package/common/hooks/useVisualViewportSize.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { getVisualViewportRect } from 'components/common/utils/visualViewport';\n\nexport interface VisualViewportSize {\n  /** Height of the actually-visible viewport in px — shrinks when a mobile on-screen keyboard\n   * opens, unlike `window.innerHeight` / CSS `vh`, which stay pinned to the full layout viewport. */\n  height: number;\n  /** Vertical offset of the visible viewport's top edge within the layout viewport — non-zero once\n   * the page has scrolled to keep a focused field above the keyboard. */\n  offsetTop: number;\n}\n\n/**\n * Tracks `window.visualViewport` so layout can react to the on-screen keyboard opening/closing.\n * Falls back to `window.innerHeight`/0 in browsers without the API.\n */\nexport function useVisualViewportSize(): VisualViewportSize {\n  const [size, setSize] = useState<VisualViewportSize>(() => {\n    const rect = getVisualViewportRect();\n    return { height: rect.height, offsetTop: rect.top };\n  });\n\n  useEffect(() => {\n    const vv = window.visualViewport;\n    if (!vv) return;\n\n    function update() {\n      const rect = getVisualViewportRect();\n      setSize({ height: rect.height, offsetTop: rect.top });\n    }\n\n    update();\n    vv.addEventListener('resize', update);\n    vv.addEventListener('scroll', update);\n    return () => {\n      vv.removeEventListener('resize', update);\n      vv.removeEventListener('scroll', update);\n    };\n  }, []);\n\n  return size;\n}\n"],"mappings":"iIAgBA,SAAgB,GAA4C,CAC1D,GAAM,CAAC,EAAM,GAAW,MAAmC,CACzD,IAAM,EAAO,EAAsB,EACnC,MAAO,CAAE,OAAQ,EAAK,OAAQ,UAAW,EAAK,GAAI,CACpD,CAAC,EAoBD,OAlBA,MAAgB,CACd,IAAM,EAAK,OAAO,eAClB,GAAI,CAAC,EAAI,OAET,SAAS,GAAS,CAChB,IAAM,EAAO,EAAsB,EACnC,EAAQ,CAAE,OAAQ,EAAK,OAAQ,UAAW,EAAK,GAAI,CAAC,CACtD,CAKA,OAHA,EAAO,EACP,EAAG,iBAAiB,SAAU,CAAM,EACpC,EAAG,iBAAiB,SAAU,CAAM,MACvB,CACX,EAAG,oBAAoB,SAAU,CAAM,EACvC,EAAG,oBAAoB,SAAU,CAAM,CACzC,CACF,EAAG,CAAC,CAAC,EAEE,CACT"}