MCPcopy Index your code
hub / github.com/CapSoftware/Cap / onRegionPointerDown

Function onRegionPointerDown

apps/desktop/src/components/Cropper.tsx:643–677  ·  view source on GitHub ↗
(e: PointerEvent)

Source from the content-addressed store, hash-verified

641 });
642
643 function onRegionPointerDown(e: PointerEvent) {
644 if (!containerRef || e.button !== 0) return;
645
646 const target = e.currentTarget as HTMLElement;
647 disposeActivePointerSession();
648 stopAnimation();
649 e.stopPropagation();
650 setMouseState({ drag: "region" });
651 let currentBounds = rawBounds();
652 const containerRect = containerRef.getBoundingClientRect();
653 const startOffset = {
654 x: e.clientX - containerRect.left - currentBounds.x,
655 y: e.clientY - containerRect.top - currentBounds.y,
656 };
657
658 trackPointerSession(
659 target,
660 e.pointerId,
661 (e) => {
662 let newX = e.clientX - containerRect.left - startOffset.x;
663 let newY = e.clientY - containerRect.top - startOffset.y;
664
665 newX = clamp(newX, 0, containerRect.width - currentBounds.width);
666 newY = clamp(newY, 0, containerRect.height - currentBounds.height);
667
668 currentBounds = moveBounds(currentBounds, newX, newY);
669 setRawBounds(currentBounds);
670
671 if (!isAnimating()) setDisplayRawBounds(currentBounds);
672 },
673 () => {
674 setMouseState({ drag: null });
675 },
676 );
677 }
678
679 let activePointerSessionDispose: (() => void) | undefined;
680

Callers

nothing calls this directly

Calls 5

trackPointerSessionFunction · 0.85
moveBoundsFunction · 0.85
stopAnimationFunction · 0.70
clampFunction · 0.70

Tested by

no test coverage detected