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.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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/shape-utils'
  6. import { getPage } from 'utils/utils'
  7. export default function transformCommand(
  8. data: Data,
  9. before: TransformSnapshot,
  10. after: TransformSnapshot
  11. ) {
  12. history.execute(
  13. data,
  14. new Command({
  15. name: 'translate_shapes',
  16. category: 'canvas',
  17. do(data) {
  18. const { type, shapeBounds } = after
  19. const { shapes } = getPage(data)
  20. for (let id in shapeBounds) {
  21. const { initialShape, initialShapeBounds, transformOrigin } =
  22. shapeBounds[id]
  23. const shape = shapes[id]
  24. getShapeUtils(shape).transform(shape, initialShapeBounds, {
  25. type,
  26. initialShape,
  27. transformOrigin,
  28. scaleX: 1,
  29. scaleY: 1,
  30. })
  31. }
  32. },
  33. undo(data) {
  34. const { type, shapeBounds } = before
  35. const { shapes } = getPage(data)
  36. for (let id in shapeBounds) {
  37. const { initialShape, initialShapeBounds, transformOrigin } =
  38. shapeBounds[id]
  39. const shape = shapes[id]
  40. getShapeUtils(shape).transform(shape, initialShapeBounds, {
  41. type,
  42. initialShape,
  43. transformOrigin,
  44. scaleX: 1,
  45. scaleY: 1,
  46. })
  47. }
  48. },
  49. })
  50. )
  51. }