Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import styled from 'styles'
  2. import state, { useSelector } from 'state'
  3. import inputs from 'state/inputs'
  4. import React, { useCallback, useRef } from 'react'
  5. import useZoomEvents from 'hooks/useZoomEvents'
  6. import useCamera from 'hooks/useCamera'
  7. import Defs from './defs'
  8. import Page from './page'
  9. import Brush from './brush'
  10. import Bounds from './bounds/bounding-box'
  11. import BoundsBg from './bounds/bounds-bg'
  12. import Selected from './selected'
  13. export default function Canvas() {
  14. const rCanvas = useRef<SVGSVGElement>(null)
  15. const rGroup = useRef<SVGGElement>(null)
  16. const events = useZoomEvents(rCanvas)
  17. useCamera(rGroup)
  18. const isReady = useSelector((s) => s.isIn('ready'))
  19. const handlePointerDown = useCallback((e: React.PointerEvent) => {
  20. rCanvas.current.setPointerCapture(e.pointerId)
  21. state.send('POINTED_CANVAS', inputs.pointerDown(e, 'canvas'))
  22. }, [])
  23. const handlePointerMove = useCallback((e: React.PointerEvent) => {
  24. state.send('MOVED_POINTER', inputs.pointerMove(e))
  25. }, [])
  26. const handlePointerUp = useCallback((e: React.PointerEvent) => {
  27. rCanvas.current.releasePointerCapture(e.pointerId)
  28. state.send('STOPPED_POINTING', { id: 'canvas', ...inputs.pointerUp(e) })
  29. }, [])
  30. return (
  31. <MainSVG
  32. ref={rCanvas}
  33. {...events}
  34. onPointerDown={handlePointerDown}
  35. onPointerMove={handlePointerMove}
  36. onPointerUp={handlePointerUp}
  37. >
  38. <Defs />
  39. {isReady && (
  40. <g ref={rGroup}>
  41. <BoundsBg />
  42. <Page />
  43. <Bounds />
  44. <Selected />
  45. <Brush />
  46. </g>
  47. )}
  48. </MainSVG>
  49. )
  50. }
  51. const MainSVG = styled('svg', {
  52. position: 'fixed',
  53. top: 0,
  54. left: 0,
  55. width: '100%',
  56. height: '100%',
  57. touchAction: 'none',
  58. zIndex: 100,
  59. '& *': {
  60. userSelect: 'none',
  61. },
  62. })