2021-06-21 21:35:28 +00:00
|
|
|
import { getShapeUtils } from 'state/shape-utils'
|
2021-06-28 12:13:34 +00:00
|
|
|
import React from 'react'
|
2021-05-28 16:25:43 +00:00
|
|
|
import { useSelector } from 'state'
|
2021-06-29 12:00:59 +00:00
|
|
|
import tld from 'utils/tld'
|
2021-06-05 06:36:39 +00:00
|
|
|
import { DotCircle, Handle } from './misc'
|
2021-07-03 16:30:06 +00:00
|
|
|
import useShape from 'hooks/useShape'
|
2021-06-27 09:07:20 +00:00
|
|
|
import useShapesToRender from 'hooks/useShapesToRender'
|
2021-06-29 14:54:46 +00:00
|
|
|
import styled from 'styles'
|
2021-05-28 13:08:51 +00:00
|
|
|
|
2021-06-21 21:35:28 +00:00
|
|
|
export default function Defs(): JSX.Element {
|
2021-06-27 09:07:20 +00:00
|
|
|
const shapeIdsToRender = useShapesToRender()
|
2021-05-28 13:08:51 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<defs>
|
2021-06-05 06:36:39 +00:00
|
|
|
<DotCircle id="dot" r={4} />
|
|
|
|
<Handle id="handle" r={4} />
|
2021-06-27 09:07:20 +00:00
|
|
|
<ExpandDef />
|
2021-06-29 14:54:46 +00:00
|
|
|
<ShadowDef />
|
2021-06-28 12:13:34 +00:00
|
|
|
{shapeIdsToRender.map((id) => (
|
|
|
|
<Def key={id} id={id} />
|
|
|
|
))}
|
2021-05-28 13:08:51 +00:00
|
|
|
</defs>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-06-28 12:13:34 +00:00
|
|
|
function Def({ id }: { id: string }) {
|
2021-07-03 16:30:06 +00:00
|
|
|
const shape = useShape(id)
|
2021-05-28 16:25:43 +00:00
|
|
|
if (!shape) return null
|
2021-07-03 16:30:06 +00:00
|
|
|
return getShapeUtils(shape).render(shape, { isEditing: false })
|
2021-06-28 12:13:34 +00:00
|
|
|
}
|
2021-06-27 09:07:20 +00:00
|
|
|
|
|
|
|
function ExpandDef() {
|
2021-06-29 12:00:59 +00:00
|
|
|
const zoom = useSelector((s) => tld.getCurrentCamera(s.data).zoom)
|
2021-06-27 09:07:20 +00:00
|
|
|
return (
|
|
|
|
<filter id="expand">
|
|
|
|
<feMorphology operator="dilate" radius={2 / zoom} />
|
|
|
|
</filter>
|
|
|
|
)
|
|
|
|
}
|
2021-06-29 14:54:46 +00:00
|
|
|
|
|
|
|
function ShadowDef() {
|
|
|
|
return (
|
|
|
|
<filter id="hover">
|
|
|
|
<StyledShadow dx="0" dy="0" stdDeviation="1.2" floodOpacity="1" />
|
|
|
|
</filter>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const StyledShadow = styled('feDropShadow', {
|
|
|
|
floodColor: '$selected',
|
|
|
|
})
|