{"version":3,"file":"useAvoidKeyboard.mjs","names":[],"sources":["../../../src/hooks/useAvoidKeyboard/useAvoidKeyboard.ts"],"sourcesContent":["import type { CSSProperties } from 'react';\nimport { useMemo } from 'react';\n\nimport { useKeyboardHeight } from '../useKeyboardHeight/useKeyboardHeight.ts';\n\ntype UseAvoidKeyboardOptions = {\n  /**\n   * Base bottom offset in pixels when keyboard is hidden.\n   * @default 0\n   */\n  safeAreaBottom?: number;\n  /**\n   * Transition duration in milliseconds for smooth animation.\n   * @default 200\n   */\n  transitionDuration?: number;\n  /**\n   * Transition timing function for the animation.\n   * @default 'ease-out'\n   */\n  transitionTimingFunction?: CSSProperties['transitionTimingFunction'];\n  /**\n   * If true, the hook will get the initial keyboard height on mount.\n   * @default true\n   */\n  immediate?: boolean;\n};\n\ntype UseAvoidKeyboardResult = {\n  /**\n   * CSS style object to apply to the fixed bottom element.\n   * Contains transform and transition properties.\n   */\n  style: CSSProperties;\n};\n\n/**\n * @description\n * `useAvoidKeyboard` is a React hook that helps fixed-bottom elements avoid the on-screen keyboard.\n * It returns a CSS style that can be applied to `position: fixed` elements\n * to smoothly move them above the keyboard when it appears.\n *\n * @param {UseAvoidKeyboardOptions} [options] - Configuration options.\n * @param {number} [options.safeAreaBottom=0] - Base bottom offset in pixels when the keyboard is hidden. Useful for accounting for the iPhone home indicator area.\n * @param {number} [options.transitionDuration=200] - Transition duration in milliseconds for smooth animation.\n * @param {CSSProperties['transitionTimingFunction']} [options.transitionTimingFunction='ease-out'] - Transition timing function for the animation.\n * @param {boolean} [options.immediate=true] - If true, gets the initial keyboard height on mount.\n *\n * @returns {UseAvoidKeyboardResult} An object containing the CSS style for keyboard avoidance.\n * - style `CSSProperties` - CSS style object to apply to the fixed bottom element. Contains `transform` and `transition` properties;\n *\n * @example\n * function FixedBottomCTA() {\n *   const { style } = useAvoidKeyboard();\n *\n *   return (\n *     <div\n *       style={{\n *         position: 'fixed',\n *         bottom: 0,\n *         left: 0,\n *         right: 0,\n *         ...style,\n *       }}\n *     >\n *       <button>Submit</button>\n *     </div>\n *   );\n * }\n *\n * @example\n * // With safe area bottom offset (e.g., for iPhone home indicator)\n * function FixedBottomCTA() {\n *   const { style } = useAvoidKeyboard({ safeAreaBottom: 34 });\n *\n *   return (\n *     <div\n *       style={{\n *         position: 'fixed',\n *         bottom: 0,\n *         left: 0,\n *         right: 0,\n *         ...style,\n *       }}\n *     >\n *       <button>Submit</button>\n *     </div>\n *   );\n * }\n */\nexport function useAvoidKeyboard(options: UseAvoidKeyboardOptions = {}): UseAvoidKeyboardResult {\n  const {\n    safeAreaBottom = 0,\n    transitionDuration = 200,\n    transitionTimingFunction = 'ease-out',\n    immediate = true,\n  } = options;\n\n  const { keyboardHeight } = useKeyboardHeight({ immediate });\n\n  const style = useMemo<CSSProperties>(() => {\n    const translateY = keyboardHeight > 0 ? -(keyboardHeight + safeAreaBottom) : 0;\n\n    return {\n      transform: `translateY(${translateY}px)`,\n      transition: `transform ${transitionDuration}ms ${transitionTimingFunction}`,\n    };\n  }, [keyboardHeight, safeAreaBottom, transitionDuration, transitionTimingFunction]);\n\n  return { style };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0FA,SAAgB,iBAAiB,UAAmC,CAAC,GAA2B;CAC9F,MAAM,EACJ,iBAAiB,GACjB,qBAAqB,KACrB,2BAA2B,YAC3B,YAAY,SACV;CAEJ,MAAM,EAAE,mBAAmB,kBAAkB,EAAE,UAAU,CAAC;CAW1D,OAAO,EAAE,OATK,cAA6B;EAGzC,OAAO;GACL,WAAW,cAHM,iBAAiB,IAAI,EAAE,iBAAiB,kBAAkB,EAGvC;GACpC,YAAY,aAAa,mBAAmB,KAAK;EACnD;CACF,GAAG;EAAC;EAAgB;EAAgB;EAAoB;CAAwB,CAEnE,EAAE;AACjB"}