Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

transform.ts 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. isSingle,
  25. boundsRotation,
  26. } = after
  27. const { shapes } = data.document.pages[currentPageId]
  28. selectedIds.forEach((id) => {
  29. const { initialShape, initialShapeBounds } = shapeBounds[id]
  30. const shape = shapes[id]
  31. getShapeUtils(shape).transform(shape, initialShapeBounds, {
  32. type,
  33. initialShape,
  34. initialShapeBounds,
  35. initialBounds,
  36. boundsRotation,
  37. isFlippedX: false,
  38. isFlippedY: false,
  39. isSingle,
  40. anchor,
  41. })
  42. })
  43. },
  44. undo(data) {
  45. const {
  46. type,
  47. shapeBounds,
  48. initialBounds,
  49. currentPageId,
  50. selectedIds,
  51. isSingle,
  52. boundsRotation,
  53. } = before
  54. const { shapes } = data.document.pages[currentPageId]
  55. selectedIds.forEach((id) => {
  56. const { initialShape, initialShapeBounds } = shapeBounds[id]
  57. const shape = shapes[id]
  58. getShapeUtils(shape).transform(shape, initialShapeBounds, {
  59. type,
  60. initialShape,
  61. initialShapeBounds,
  62. initialBounds,
  63. boundsRotation,
  64. isFlippedX: false,
  65. isFlippedY: false,
  66. isSingle,
  67. anchor: type,
  68. })
  69. })
  70. },
  71. })
  72. )
  73. }