tldraw/state/commands/transform-single.ts

48 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-05-19 09:35:00 +00:00
import Command from "./command"
import history from "../history"
import { Data, TransformCorner, TransformEdge } from "types"
import { getShapeUtils } from "lib/shapes"
import { TransformSingleSnapshot } from "state/sessions/transform-single-session"
export default function transformSingleCommand(
data: Data,
before: TransformSingleSnapshot,
after: TransformSingleSnapshot,
scaleX: number,
scaleY: number
2021-05-19 09:35:00 +00:00
) {
history.execute(
data,
new Command({
name: "transform_single_shape",
2021-05-19 09:35:00 +00:00
category: "canvas",
do(data) {
const { id, currentPageId, type, initialShape, initialShapeBounds } =
after
2021-05-19 09:35:00 +00:00
const shape = data.document.pages[currentPageId].shapes[id]
2021-05-19 09:35:00 +00:00
getShapeUtils(shape).transformSingle(shape, initialShapeBounds, {
2021-05-19 09:35:00 +00:00
type,
initialShape,
scaleX,
scaleY,
2021-05-19 09:35:00 +00:00
})
},
undo(data) {
const { id, currentPageId, type, initialShape, initialShapeBounds } =
before
2021-05-19 09:35:00 +00:00
const shape = data.document.pages[currentPageId].shapes[id]
2021-05-19 09:35:00 +00:00
getShapeUtils(shape).transform(shape, initialShapeBounds, {
type,
initialShape: after.initialShape,
scaleX: 1,
scaleY: 1,
2021-05-19 09:35:00 +00:00
})
},
})
)
}