@guruhotel/aura-hooks
Version:
🪝 Hooks library designed by the Guruhotel team for Aura UI
1 lines • 750 B
JavaScript
export const getRelativePosition=({axis:t,target:e,parent:n,alignment:i,offset:r,isList:o})=>{if(!e||!n&&"undefined"==typeof document)return 0;const d=!!n,h=(n||document.body).getBoundingClientRect(),s=e.getBoundingClientRect(),c=t=>s[t]-h[t];if("y"===t){const t=c("top");if(0===t)return 0;if("start"===i){const e=t-r;return e<=s.height*(o?0:1)||!o?e:0}const e=d?h.height:window.innerHeight;if("end"===i){const n=t+r-e+s.height;return n>=-s.height*(o?0:1)||!o?n:0}return"center"===i?t-e/2+s.height/2:0}if("x"===t){const t=c("left");if(0===t)return 0;if("start"===i){const e=t-r;return e<=s.width||!o?e:0}const e=d?h.width:window.innerWidth;if("end"===i){const n=t+r-e+s.width;return n>=-s.width||!o?n:0}return"center"===i?t-e/2+s.width/2:0}return 0};