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.

rotate.ts 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import Command from "./command"
  2. import history from "../history"
  3. import { Data } from "types"
  4. import { RotateSnapshot } from "state/sessions/rotate-session"
  5. import { getPage } from "utils/utils"
  6. export default function rotateCommand(
  7. data: Data,
  8. before: RotateSnapshot,
  9. after: RotateSnapshot
  10. ) {
  11. history.execute(
  12. data,
  13. new Command({
  14. name: "translate_shapes",
  15. category: "canvas",
  16. do(data) {
  17. const { shapes } = getPage(data)
  18. for (let { id, point, rotation } of after.shapes) {
  19. const shape = shapes[id]
  20. shape.rotation = rotation
  21. shape.point = point
  22. }
  23. data.boundsRotation = after.boundsRotation
  24. },
  25. undo(data) {
  26. const { shapes } = getPage(data, before.currentPageId)
  27. for (let { id, point, rotation } of before.shapes) {
  28. const shape = shapes[id]
  29. shape.rotation = rotation
  30. shape.point = point
  31. }
  32. data.boundsRotation = before.boundsRotation
  33. },
  34. })
  35. )
  36. }