UNPKG

@zohodesk/dot

Version:

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

30 lines (28 loc) 991 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DragPosCalc = DragPosCalc; function DragPosCalc(_ref) { var x = _ref.x, y = _ref.y, element = _ref.element, dragWrapper = _ref.dragWrapper, boundaryLimit = _ref.boundaryLimit; var top = boundaryLimit.top, left = boundaryLimit.left, right = boundaryLimit.right, bottom = boundaryLimit.bottom; var offsetWidth = element ? element.offsetWidth : 0; var offsetHeight = element ? element.offsetHeight : 0; var topOffset = top ? offsetHeight - top : 0; var leftOffset = left ? offsetWidth - left : 0; var rightOffset = right ? offsetWidth - right : 0; var 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: x, y: y }; }