{"version":3,"file":"useKeyboardHeight.cjs","names":["useState","subscribeKeyboardHeight"],"sources":["../../../src/hooks/useKeyboardHeight/useKeyboardHeight.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { subscribeKeyboardHeight } from '../../utils/subscribeKeyboardHeight/index.ts';\n\ntype UseKeyboardHeightOptions = {\n  /**\n   * If true, the hook will get the initial keyboard height on mount.\n   * @default true\n   */\n  immediate?: boolean;\n};\n\ntype UseKeyboardHeightResult = {\n  /**\n   * The current keyboard height in pixels.\n   */\n  keyboardHeight: number;\n};\n\n/**\n * @description\n * `useKeyboardHeight` is a React hook that tracks the on-screen keyboard height.\n * It returns the current keyboard height in pixels, which updates automatically\n * when the keyboard appears, disappears, or changes size.\n *\n * @param {UseKeyboardHeightOptions} [options] - Configuration options.\n * @param {boolean} [options.immediate=true] - If true, gets the initial keyboard height on mount.\n *\n * @returns {UseKeyboardHeightResult} An object containing the current keyboard height.\n * - keyboardHeight `number` - The current keyboard height in pixels. 0 when the keyboard is hidden;\n *\n * @example\n * function ChatInput() {\n *   const { keyboardHeight } = useKeyboardHeight();\n *\n *   return (\n *     <div style={{ paddingBottom: `${keyboardHeight}px` }}>\n *       <input type=\"text\" placeholder=\"Type a message...\" />\n *     </div>\n *   );\n * }\n */\nexport function useKeyboardHeight(options: UseKeyboardHeightOptions = {}): UseKeyboardHeightResult {\n  const { immediate = true } = options;\n\n  const [keyboardHeight, setKeyboardHeight] = useState(0);\n\n  useEffect(\n    function subscribeToKeyboardHeight() {\n      const { unsubscribe } = subscribeKeyboardHeight({\n        callback: setKeyboardHeight,\n        immediate,\n      });\n\n      return unsubscribe;\n    },\n    [immediate]\n  );\n\n  return { keyboardHeight };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,kBAAkB,UAAoC,CAAC,GAA4B;CACjG,MAAM,EAAE,YAAY,SAAS;CAE7B,MAAM,CAAC,gBAAgB,sBAAA,GAAqBA,MAAAA,SAAAA,CAAS,CAAC;CAEtD,CAAA,GAAA,MAAA,UAAA,CACE,SAAS,4BAA4B;EACnC,MAAM,EAAE,gBAAgBC,gCAAAA,wBAAwB;GAC9C,UAAU;GACV;EACF,CAAC;EAED,OAAO;CACT,GACA,CAAC,SAAS,CACZ;CAEA,OAAO,EAAE,eAAe;AAC1B"}