arrowjoin
Version:
ArrowJoin is a creative and functional React library that effortlessly connects two React components with a sleek arrow.
35 lines • 1.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.calcAnchors = void 0;
var getAnchorsDefaultOffsets = function (width, height) {
return {
middle: { x: width * 0.5, y: height * 0.5 },
left: { x: 0, y: height * 0.5 },
right: { x: width, y: height * 0.5 },
top: { x: width * 0.5, y: 0 },
bottom: { x: width * 0.5, y: height },
};
};
var calcAnchors = function (anchors, anchorPos) {
// now prepare this list of anchors to object expected by the `getShortestLine` function
return anchors.map(function (anchor) {
var defsOffsets = getAnchorsDefaultOffsets(anchorPos.right - anchorPos.x, anchorPos.bottom - anchorPos.y);
var _a = defsOffsets[anchor.position], x = _a.x, y = _a.y;
return {
x: anchorPos.x + x + anchor.offset.x,
y: anchorPos.y + y + anchor.offset.y,
anchor: anchor,
};
});
};
exports.calcAnchors = calcAnchors;
// if (require.main === module) {
// const res = parseAnchor(['auto'], {
// x: 0,
// y: 0,
// bottom: 10,
// right: 20,
// });
// console.log(res);
// }
//# sourceMappingURL=anchors.js.map