2021-05-28 14:37:23 +00:00
|
|
|
import styled from 'styles'
|
2021-05-28 16:25:43 +00:00
|
|
|
import state, { useSelector } from 'state'
|
2021-05-28 14:37:23 +00:00
|
|
|
import inputs from 'state/inputs'
|
|
|
|
import React, { useCallback, useRef } from 'react'
|
|
|
|
import useZoomEvents from 'hooks/useZoomEvents'
|
|
|
|
import useCamera from 'hooks/useCamera'
|
|
|
|
import Defs from './defs'
|
|
|
|
import Page from './page'
|
|
|
|
import Brush from './brush'
|
|
|
|
import Bounds from './bounds/bounding-box'
|
|
|
|
import BoundsBg from './bounds/bounds-bg'
|
2021-05-28 16:25:43 +00:00
|
|
|
import Selected from './selected'
|
2021-05-31 19:13:43 +00:00
|
|
|
import Handles from './bounds/handles'
|
2021-06-06 10:50:01 +00:00
|
|
|
import { isMobile, screenToWorld, throttle } from 'utils/utils'
|
|
|
|
import session from 'state/session'
|
|
|
|
import { PointerInfo } from 'types'
|
|
|
|
import { fastDrawUpdate } from 'state/hacks'
|
|
|
|
import useCanvasEvents from 'hooks/useCanvasEvents'
|
2021-05-09 13:04:42 +00:00
|
|
|
|
|
|
|
export default function Canvas() {
|
|
|
|
const rCanvas = useRef<SVGSVGElement>(null)
|
|
|
|
const rGroup = useRef<SVGGElement>(null)
|
|
|
|
|
2021-05-09 21:22:25 +00:00
|
|
|
useCamera(rGroup)
|
2021-05-28 16:25:43 +00:00
|
|
|
|
2021-06-06 10:50:01 +00:00
|
|
|
useZoomEvents()
|
2021-05-30 13:14:35 +00:00
|
|
|
|
2021-06-06 10:50:01 +00:00
|
|
|
const events = useCanvasEvents(rCanvas)
|
2021-05-10 12:16:57 +00:00
|
|
|
|
2021-06-06 10:50:01 +00:00
|
|
|
const isReady = useSelector((s) => s.isIn('ready'))
|
2021-05-10 12:16:57 +00:00
|
|
|
|
2021-05-09 13:04:42 +00:00
|
|
|
return (
|
2021-06-06 10:50:01 +00:00
|
|
|
<MainSVG ref={rCanvas} {...events}>
|
2021-05-28 14:37:23 +00:00
|
|
|
<Defs />
|
2021-05-28 16:25:43 +00:00
|
|
|
{isReady && (
|
|
|
|
<g ref={rGroup}>
|
|
|
|
<BoundsBg />
|
|
|
|
<Page />
|
2021-06-05 06:36:39 +00:00
|
|
|
<Selected />
|
2021-05-30 13:14:35 +00:00
|
|
|
<Bounds />
|
2021-05-31 19:13:43 +00:00
|
|
|
<Handles />
|
2021-05-28 16:25:43 +00:00
|
|
|
<Brush />
|
|
|
|
</g>
|
|
|
|
)}
|
2021-05-09 13:04:42 +00:00
|
|
|
</MainSVG>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-05-28 14:37:23 +00:00
|
|
|
const MainSVG = styled('svg', {
|
|
|
|
position: 'fixed',
|
2021-05-09 13:04:42 +00:00
|
|
|
top: 0,
|
|
|
|
left: 0,
|
2021-05-28 14:37:23 +00:00
|
|
|
width: '100%',
|
|
|
|
height: '100%',
|
|
|
|
touchAction: 'none',
|
2021-05-09 13:04:42 +00:00
|
|
|
zIndex: 100,
|
2021-05-30 13:49:33 +00:00
|
|
|
backgroundColor: '$canvas',
|
2021-06-03 16:13:23 +00:00
|
|
|
pointerEvents: 'all',
|
2021-05-23 13:46:04 +00:00
|
|
|
|
2021-05-28 14:37:23 +00:00
|
|
|
'& *': {
|
|
|
|
userSelect: 'none',
|
2021-05-23 13:46:04 +00:00
|
|
|
},
|
2021-05-09 13:04:42 +00:00
|
|
|
})
|
2021-06-03 16:13:23 +00:00
|
|
|
|
|
|
|
// const throttledPointerMove = throttle((payload: any) => {
|
|
|
|
// state.send('MOVED_POINTER', payload)
|
|
|
|
// }, 16)
|
|
|
|
|
|
|
|
const throttledPointerMove = (payload: any) => {
|
|
|
|
state.send('MOVED_POINTER', payload)
|
|
|
|
}
|