import { useRef } from 'react' import state, { useSelector } from 'state' import inputs from 'state/inputs' import styled from 'styles' import tld from 'utils/tld' function handlePointerDown(e: React.PointerEvent) { if (!inputs.canAccept(e.pointerId)) return e.stopPropagation() e.currentTarget.setPointerCapture(e.pointerId) const info = inputs.pointerDown(e, 'bounds') if (e.button === 0) { state.send('POINTED_BOUNDS', info) } else if (e.button === 2) { state.send('RIGHT_POINTED', info) } } function handlePointerUp(e: React.PointerEvent) { if (!inputs.canAccept(e.pointerId)) return e.stopPropagation() e.currentTarget.releasePointerCapture(e.pointerId) state.send('STOPPED_POINTING', inputs.pointerUp(e, 'bounds')) } export default function BoundsBg(): JSX.Element { const rBounds = useRef(null) const bounds = useSelector((state) => state.values.selectedBounds) const shouldDisplay = useSelector((s) => s.isInAny('selecting', 'selectPinching') ) const rotation = useSelector((s) => s.values.selectedRotation) const isAllHandles = useSelector((s) => { const selectedIds = s.values.selectedIds if (selectedIds.length === 1) { const page = tld.getPage(s.data) const selected = selectedIds[0] return ( selectedIds.length === 1 && page.shapes[selected]?.handles !== undefined ) } }) if (isAllHandles) return null if (!bounds) return null if (!shouldDisplay) return null const { width, height } = bounds return ( ) } const StyledBoundsBg = styled('rect', { fill: '$boundsBg', })