UNPKG

substance

Version:

Substance is a JavaScript library for web-based content editing. It provides building blocks for realizing custom text editors and web-based publishing systems.

19 lines (18 loc) 672 B
/** Get bounding bounds for a given mouse event, relative parent element. @param {MouseEvent} mouseEvent the source mouse event @param {DOMElement} containerEl used as a reference point to calculate position @return {object} bound description with left, top, right, bottom */ export default function getRelativeMouseBounds(mouseEvent, containerEl) { let containerElRect = containerEl.getBoundingClientRect() let left = mouseEvent.clientX - containerElRect.left let top = mouseEvent.clientY - containerElRect.top let res = { left: left, right: containerElRect.width - left, top: top, bottom: containerElRect.height - top } return res; }