import {handleAlign} from "./handleAlign"; import {iAllRects, iPlainPopperConfig, tAlign, tDirection} from "./type.base"; import {limitBoundary} from "./limitBoundary"; interface iVerticalPositionData { transform: { top: number }, fixed: { top: number } | { bottom: number } } /** * 获取横向位置的时候,transform以及fixed定位的值 * @author 韦胜健 * @date 2022/4/4 19:06 */ export function getVerticalPosition({ align, rects, config, direction }: { align: tAlign, rects: iAllRects, direction: tDirection, config: iPlainPopperConfig }): iVerticalPositionData { return handleAlign(align, { start: () => { const top = limitBoundary({ name: 'top', rects, config, direction, value: rects.reference.top }); return { transform: { top }, fixed: { top } }; }, center: () => { const top = limitBoundary({ name: 'top', rects, config, direction, value: rects.reference.top + rects.reference.height / 2 - rects.body.height / 2 }); return { transform: { top }, fixed: { top } }; }, end: () => { const top = limitBoundary({ name: 'top', rects, config, direction, value: rects.reference.top + rects.reference.height - rects.body.height }); const bottom = limitBoundary({ name: 'bottom', rects, config, direction, value: rects.reference.bottom }); return { transform: { top }, fixed: { bottom }, }; }, }); }