Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

bounds-bg.tsx 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { useRef } from "react"
  2. import state, { useSelector } from "state"
  3. import inputs from "state/inputs"
  4. import styled from "styles"
  5. export default function BoundsBg() {
  6. const rBounds = useRef<SVGRectElement>(null)
  7. const bounds = useSelector((state) => state.values.selectedBounds)
  8. const isSelecting = useSelector((s) => s.isIn("selecting"))
  9. const rotation = useSelector((s) => {
  10. if (s.data.selectedIds.size === 1) {
  11. const { shapes } = s.data.document.pages[s.data.currentPageId]
  12. const selected = Array.from(s.data.selectedIds.values())[0]
  13. return shapes[selected].rotation
  14. } else {
  15. return 0
  16. }
  17. })
  18. if (!bounds) return null
  19. if (!isSelecting) return null
  20. const { minX, minY, width, height } = bounds
  21. return (
  22. <StyledBoundsBg
  23. ref={rBounds}
  24. x={minX}
  25. y={minY}
  26. width={Math.max(1, width)}
  27. height={Math.max(1, height)}
  28. onPointerDown={(e) => {
  29. if (e.buttons !== 1) return
  30. e.stopPropagation()
  31. rBounds.current.setPointerCapture(e.pointerId)
  32. state.send("POINTED_BOUNDS", inputs.pointerDown(e, "bounds"))
  33. }}
  34. transform={`rotate(${rotation * (180 / Math.PI)},${minX + width / 2}, ${
  35. minY + height / 2
  36. })`}
  37. />
  38. )
  39. }
  40. const StyledBoundsBg = styled("rect", {
  41. fill: "$boundsBg",
  42. })