UNPKG

@zohodesk/dot

Version:

In this Library, we Provide Some Basic Components to Build Your Application

27 lines 758 B
export function DragPosCalc(_ref) { let { x, y, element, dragWrapper, boundaryLimit } = _ref; let { top, left, right, bottom } = boundaryLimit; const offsetWidth = element ? element.offsetWidth : 0; const offsetHeight = element ? element.offsetHeight : 0; const topOffset = top ? offsetHeight - top : 0; const leftOffset = left ? offsetWidth - left : 0; const rightOffset = right ? offsetWidth - right : 0; const bottomOffset = bottom ? offsetHeight - bottom : 0; x = Math.max(-leftOffset, Math.min(x, dragWrapper.offsetWidth - element.offsetWidth + rightOffset)); y = Math.max(-topOffset, Math.min(y, dragWrapper.offsetHeight - element.offsetHeight + bottomOffset)); return { x, y }; }