You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

canvas.tsx 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import styled from 'styles'
  2. import { useSelector } from 'state'
  3. import React, { useRef } from 'react'
  4. import useZoomEvents from 'hooks/useZoomEvents'
  5. import useCamera from 'hooks/useCamera'
  6. import Defs from './defs'
  7. import Page from './page'
  8. import Brush from './brush'
  9. import Bounds from './bounds/bounding-box'
  10. import BoundsBg from './bounds/bounds-bg'
  11. import Handles from './bounds/handles'
  12. import useCanvasEvents from 'hooks/useCanvasEvents'
  13. import ContextMenu from './context-menu/context-menu'
  14. export default function Canvas(): JSX.Element {
  15. const rCanvas = useRef<SVGSVGElement>(null)
  16. const rGroup = useRef<SVGGElement>(null)
  17. useCamera(rGroup)
  18. useZoomEvents()
  19. const events = useCanvasEvents(rCanvas)
  20. const isReady = useSelector((s) => s.isIn('ready'))
  21. return (
  22. <ContextMenu>
  23. <MainSVG ref={rCanvas} {...events}>
  24. <Defs />
  25. {isReady && (
  26. <g ref={rGroup} id="shapes">
  27. <BoundsBg />
  28. <Page />
  29. <Bounds />
  30. <Handles />
  31. <Brush />
  32. </g>
  33. )}
  34. </MainSVG>
  35. </ContextMenu>
  36. )
  37. }
  38. const MainSVG = styled('svg', {
  39. position: 'fixed',
  40. overflow: 'hidden',
  41. top: 0,
  42. left: 0,
  43. width: '100%',
  44. height: '100%',
  45. touchAction: 'none',
  46. zIndex: 100,
  47. backgroundColor: '$canvas',
  48. pointerEvents: 'all',
  49. // cursor: 'none',
  50. '& *': {
  51. userSelect: 'none',
  52. },
  53. })