feat(nodes): move canvas when nodes are at the edge of the canvas #2753

This commit is contained in:
moklick
2023-01-16 18:23:20 +01:00
parent e413bceb19
commit 86f7a9a43d
4 changed files with 118 additions and 68 deletions
+12
View File
@@ -14,6 +14,18 @@ export const clampPosition = (position: XYPosition = { x: 0, y: 0 }, extent: Coo
y: clamp(position.y, extent[0][1], extent[1][1]),
});
// returns a number between 0 and 1 that represents the velocity of the movement
// when the mouse is close to the edge of the canvas
export const getVelocity = (value: number, min: number, max: number): number => {
if (value < min) {
return clamp(Math.abs(value - min), 1, 100) / 100;
} else if (value > max) {
return -clamp(Math.abs(value - max), 1, 100) / 100;
}
return 0;
};
export const getHostForElement = (element: HTMLElement): Document | ShadowRoot =>
(element.getRootNode?.() as Document | ShadowRoot) || window?.document;