Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

canvas.tsx 1.7KB

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. import Handles from './bounds/handles'
  14. import { isMobile, screenToWorld, throttle } from 'utils/utils'
  15. import session from 'state/session'
  16. import { PointerInfo } from 'types'
  17. import { fastDrawUpdate } from 'state/hacks'
  18. import useCanvasEvents from 'hooks/useCanvasEvents'
  19. export default function Canvas() {
  20. const rCanvas = useRef<SVGSVGElement>(null)
  21. const rGroup = useRef<SVGGElement>(null)
  22. useCamera(rGroup)
  23. useZoomEvents()
  24. const events = useCanvasEvents(rCanvas)
  25. const isReady = useSelector((s) => s.isIn('ready'))
  26. return (
  27. <MainSVG ref={rCanvas} {...events}>
  28. <Defs />
  29. {isReady && (
  30. <g ref={rGroup}>
  31. <BoundsBg />
  32. <Page />
  33. <Selected />
  34. <Bounds />
  35. <Handles />
  36. <Brush />
  37. </g>
  38. )}
  39. </MainSVG>
  40. )
  41. }
  42. const MainSVG = styled('svg', {
  43. position: 'fixed',
  44. top: 0,
  45. left: 0,
  46. width: '100%',
  47. height: '100%',
  48. touchAction: 'none',
  49. zIndex: 100,
  50. backgroundColor: '$canvas',
  51. pointerEvents: 'all',
  52. '& *': {
  53. userSelect: 'none',
  54. },
  55. })
  56. // const throttledPointerMove = throttle((payload: any) => {
  57. // state.send('MOVED_POINTER', payload)
  58. // }, 16)
  59. const throttledPointerMove = (payload: any) => {
  60. state.send('MOVED_POINTER', payload)
  61. }