asp-smart-ui-plus-test
Version:
A Component Library for Vue 3
39 lines (37 loc) • 949 B
JavaScript
function getControlPosition(e) {
return offsetXYFromParentOf(e);
}
function offsetXYFromParentOf(evt) {
const t = evt.target;
const offsetParent = t.offsetParent || document.body;
const offsetParentRect = t.offsetParent === document.body ? { left: 0, top: 0 } : offsetParent.getBoundingClientRect();
const x = evt.clientX + offsetParent.scrollLeft - offsetParentRect.left;
const y = evt.clientY + offsetParent.scrollTop - offsetParentRect.top;
return { x, y };
}
function createCoreData(lastX, lastY, x, y) {
const isStart = !isNum(lastX);
if (isStart) {
return {
deltaX: 0,
deltaY: 0,
lastX: x,
lastY: y,
x,
y
};
} else {
return {
deltaX: x - lastX,
deltaY: y - lastY,
lastX,
lastY,
x,
y
};
}
}
function isNum(num) {
return typeof num === "number" && !isNaN(num);
}
export { createCoreData, getControlPosition, offsetXYFromParentOf };