import { createSelector } from '@reduxjs/toolkit'; import { useAppSelector } from 'app/storeHooks'; import { canvasSelector } from 'features/canvas/store/canvasSelectors'; import { GroupConfig } from 'konva/lib/Group'; import { isEqual } from 'lodash'; import { Group, Line } from 'react-konva'; import { isCanvasMaskLine } from '../store/canvasTypes'; export const canvasLinesSelector = createSelector( [canvasSelector], (canvas) => { return { objects: canvas.layerState.objects }; }, { memoizeOptions: { resultEqualityCheck: isEqual, }, } ); type InpaintingCanvasLinesProps = GroupConfig; /** * Draws the lines which comprise the mask. * * Uses globalCompositeOperation to handle the brush and eraser tools. */ const IAICanvasLines = (props: InpaintingCanvasLinesProps) => { const { ...rest } = props; const { objects } = useAppSelector(canvasLinesSelector); return ( {objects.filter(isCanvasMaskLine).map((line, i) => ( 0 strokeWidth={line.strokeWidth * 2} tension={0} lineCap="round" lineJoin="round" shadowForStrokeEnabled={false} listening={false} globalCompositeOperation={ line.tool === 'brush' ? 'source-over' : 'destination-out' } /> ))} ); }; export default IAICanvasLines;