{"version":3,"file":"calculatePosition.mjs","sources":["../../../packages/popover/calculatePosition.ts"],"sourcesContent":["import { CSSProperties } from 'react'\nimport { PopoverPlacements } from './types.js'\n\nexport const calculatePosition = (\n  anchorRect: DOMRect,\n  popoverRect: DOMRect,\n  wrapperRect: DOMRect,\n  placement: PopoverPlacements,\n): CSSProperties => {\n  const position: CSSProperties = {}\n\n  switch (placement) {\n    case 'top':\n    case 'bottom':\n      position.left =\n        (anchorRect.left + anchorRect.right) / 2 - popoverRect.width / 2\n      break\n\n    case 'topLeft':\n    case 'bottomLeft':\n      position.left = anchorRect.left\n      break\n\n    case 'topRight':\n    case 'bottomRight':\n      position.left = anchorRect.right - popoverRect.width\n      break\n\n    case 'rightTop':\n    case 'right':\n    case 'rightBottom':\n      position.left = anchorRect.right\n      break\n\n    case 'leftTop':\n    case 'left':\n    case 'leftBottom':\n      position.left = anchorRect.left - popoverRect.width\n      break\n  }\n\n  switch (placement) {\n    case 'left':\n    case 'right':\n      position.top =\n        (anchorRect.top + anchorRect.bottom) / 2 - popoverRect.height / 2\n      break\n\n    case 'leftTop':\n    case 'rightTop':\n      position.top = anchorRect.top\n      break\n\n    case 'leftBottom':\n    case 'rightBottom':\n      position.top = anchorRect.bottom - popoverRect.height\n      break\n\n    case 'topLeft':\n    case 'top':\n    case 'topRight':\n      position.top = anchorRect.top - popoverRect.height\n      break\n\n    case 'bottomLeft':\n    case 'bottom':\n    case 'bottomRight':\n      position.top = anchorRect.bottom\n      break\n  }\n\n  position.top -= wrapperRect.top\n  position.left -= wrapperRect.left\n\n  return position\n}\n"],"names":["calculatePosition","anchorRect","popoverRect","wrapperRect","placement","position","left","right","width","top","bottom","height"],"mappings":"AAGO,MAAMA,iBAAiB,GAAGA,CAC/BC,UAAmB,EACnBC,WAAoB,EACpBC,WAAoB,EACpBC,SAA4B,KACV;EAClB,MAAMC,QAAuB,GAAG,EAAE,CAAA;AAElC,EAAA,QAAQD,SAAS;AACf,IAAA,KAAK,KAAK,CAAA;AAC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