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.

transform-command.ts 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import Command from "./command"
  2. import history from "../history"
  3. import { Data } from "types"
  4. import { TransformSnapshot } from "state/sessions/transform-session"
  5. import { getShapeUtils } from "lib/shapes"
  6. export default function translateCommand(
  7. data: Data,
  8. before: TransformSnapshot,
  9. after: TransformSnapshot
  10. ) {
  11. history.execute(
  12. data,
  13. new Command({
  14. name: "translate_shapes",
  15. category: "canvas",
  16. do(data) {
  17. const { shapeBounds, initialBounds, currentPageId, selectedIds } = after
  18. const { shapes } = data.document.pages[currentPageId]
  19. selectedIds.forEach((id) => {
  20. const { initialShape, initialShapeBounds } = shapeBounds[id]
  21. const shape = shapes[id]
  22. getShapeUtils(shape).transform(
  23. shape,
  24. {
  25. ...initialShapeBounds,
  26. isFlippedX: false,
  27. isFlippedY: false,
  28. },
  29. initialShape,
  30. initialShapeBounds,
  31. initialBounds
  32. )
  33. })
  34. },
  35. undo(data) {
  36. const {
  37. shapeBounds,
  38. initialBounds,
  39. currentPageId,
  40. selectedIds,
  41. } = before
  42. const { shapes } = data.document.pages[currentPageId]
  43. selectedIds.forEach((id) => {
  44. const { initialShape, initialShapeBounds } = shapeBounds[id]
  45. const shape = shapes[id]
  46. getShapeUtils(shape).transform(
  47. shape,
  48. {
  49. ...initialShapeBounds,
  50. isFlippedX: false,
  51. isFlippedY: false,
  52. },
  53. initialShape,
  54. initialShapeBounds,
  55. initialBounds
  56. )
  57. })
  58. },
  59. })
  60. )
  61. }