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.

12345678910111213141516171819202122232425262728293031
  1. import { getShapeUtils } from 'lib/shape-utils'
  2. import { memo } from 'react'
  3. import { useSelector } from 'state'
  4. import { deepCompareArrays, getPage } from 'utils/utils'
  5. export default function Defs() {
  6. const zoom = useSelector((s) => s.data.camera.zoom)
  7. const currentPageShapeIds = useSelector(({ data }) => {
  8. return Object.values(getPage(data).shapes)
  9. .sort((a, b) => a.childIndex - b.childIndex)
  10. .map((shape) => shape.id)
  11. }, deepCompareArrays)
  12. return (
  13. <defs>
  14. {currentPageShapeIds.map((id) => (
  15. <Def key={id} id={id} />
  16. ))}
  17. <filter id="expand">
  18. <feMorphology operator="dilate" radius={2 / zoom} />
  19. </filter>
  20. </defs>
  21. )
  22. }
  23. const Def = memo(({ id }: { id: string }) => {
  24. const shape = useSelector(({ data }) => getPage(data).shapes[id])
  25. if (!shape) return null
  26. return getShapeUtils(shape).render(shape)
  27. })