UNPKG

react-pdf-ner-annotator

Version:

A React component to annotate named entities directly onto a PDF.

34 lines 1.78 kB
"use strict"; exports.__esModule = true; exports.findIntersectingChildren = exports.calculateSelectionRectangle = exports.isCoordsEmpty = void 0; var isCoordsEmpty = function (coordinates) { return coordinates.width * coordinates.height <= 25; }; exports.isCoordsEmpty = isCoordsEmpty; var calculateSelectionRectangle = function (startPoint, endPoint) { var x3 = Math.min(startPoint.x, endPoint.x); var x4 = Math.max(startPoint.x, endPoint.x); var y3 = Math.min(startPoint.y, endPoint.y); var y4 = Math.max(startPoint.y, endPoint.y); return { left: x3, top: y3, width: x4 - x3, height: y4 - y3 }; }; exports.calculateSelectionRectangle = calculateSelectionRectangle; var findIntersectingChildren = function (children, selectionRect, offsetX, offsetY) { if (offsetX === void 0) { offsetX = 0; } if (offsetY === void 0) { offsetY = 0; } return Array.from(children).filter(function (child) { return intersects(child, selectionRect, offsetX, offsetY); }); }; exports.findIntersectingChildren = findIntersectingChildren; var intersects = function (child, selectionRect, offsetX, offsetY) { if (Object.values(child.attributes) .map(function (value) { return value.name; }) .includes('data-ignore')) { return false; } var leftX = Math.max(selectionRect.left, child.offsetLeft + offsetX); var rightX = Math.min(selectionRect.left + selectionRect.width, child.offsetLeft + offsetX + child.offsetWidth); var topY = Math.max(selectionRect.top, child.offsetTop + offsetY); var bottomY = Math.min(selectionRect.top + selectionRect.height, child.offsetTop + offsetY + child.offsetHeight); return leftX < rightX && topY < bottomY; }; //# sourceMappingURL=selectionHelpers.js.map