Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

transform.ts 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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/shapes"
  6. export default function translateCommand(
  7. data: Data,
  8. before: TransformSnapshot,
  9. after: TransformSnapshot,
  10. anchor: TransformCorner | TransformEdge
  11. ) {
  12. history.execute(
  13. data,
  14. new Command({
  15. name: "translate_shapes",
  16. category: "canvas",
  17. do(data) {
  18. const {
  19. type,
  20. shapeBounds,
  21. initialBounds,
  22. currentPageId,
  23. selectedIds,
  24. } = after
  25. const { shapes } = data.document.pages[currentPageId]
  26. selectedIds.forEach((id) => {
  27. const { initialShape, initialShapeBounds } = shapeBounds[id]
  28. const shape = shapes[id]
  29. getShapeUtils(shape).transform(shape, initialShapeBounds, {
  30. type,
  31. initialShape,
  32. initialShapeBounds,
  33. initialBounds,
  34. isFlippedX: false,
  35. isFlippedY: false,
  36. anchor,
  37. })
  38. })
  39. },
  40. undo(data) {
  41. const {
  42. type,
  43. shapeBounds,
  44. initialBounds,
  45. currentPageId,
  46. selectedIds,
  47. } = before
  48. const { shapes } = data.document.pages[currentPageId]
  49. selectedIds.forEach((id) => {
  50. const { initialShape, initialShapeBounds } = shapeBounds[id]
  51. const shape = shapes[id]
  52. getShapeUtils(shape).transform(shape, initialShapeBounds, {
  53. type,
  54. initialShape,
  55. initialShapeBounds,
  56. initialBounds,
  57. isFlippedX: false,
  58. isFlippedY: false,
  59. anchor: type,
  60. })
  61. })
  62. },
  63. })
  64. )
  65. }