Tldraw/examples/core-example-advanced/src/state/actions/erase/eraseShapes.ts

17 wiersze
530 B
TypeScript

import type { TLPointerInfo } from '@tldraw/core'
import type { Action } from 'state/constants'
import { getShapeUtils } from 'shapes'
import { mutables } from 'state/mutables'
export const eraseShapes: Action = (data, payload: TLPointerInfo) => {
const { previousPoint } = mutables
Object.values(data.page.shapes)
.filter((shape) => !shape.isGhost)
.forEach((shape) => {
if (getShapeUtils(shape).hitTestLineSegment(shape, previousPoint, mutables.currentPoint)) {
shape.isGhost = true
}
})
}