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.

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