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.ts 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import Command from "./command"
  2. import history from "../history"
  3. import { Data, TransformCorner, TransformEdge } from "types"
  4. import { TransformSnapshot } from "state/sessions/transform-session"
  5. import { getShapeUtils } from "lib/shape-utils"
  6. export default function transformCommand(
  7. data: Data,
  8. before: TransformSnapshot,
  9. after: TransformSnapshot,
  10. scaleX: number,
  11. scaleY: number
  12. ) {
  13. history.execute(
  14. data,
  15. new Command({
  16. name: "translate_shapes",
  17. category: "canvas",
  18. do(data) {
  19. const { type, currentPageId, selectedIds } = after
  20. selectedIds.forEach((id) => {
  21. const { initialShape, initialShapeBounds } = after.shapeBounds[id]
  22. const shape = data.document.pages[currentPageId].shapes[id]
  23. getShapeUtils(shape).transform(shape, initialShapeBounds, {
  24. type,
  25. initialShape,
  26. scaleX: 1,
  27. scaleY: 1,
  28. })
  29. })
  30. },
  31. undo(data) {
  32. const { type, currentPageId, selectedIds } = before
  33. selectedIds.forEach((id) => {
  34. const { initialShape, initialShapeBounds } = before.shapeBounds[id]
  35. const shape = data.document.pages[currentPageId].shapes[id]
  36. getShapeUtils(shape).transform(shape, initialShapeBounds, {
  37. type,
  38. initialShape,
  39. scaleX: 1,
  40. scaleY: 1,
  41. })
  42. })
  43. },
  44. })
  45. )
  46. }