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.

rotate.ts 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import Command from './command'
  2. import history from '../history'
  3. import { Data } from 'types'
  4. import { RotateSnapshot } from 'state/sessions/rotate-session'
  5. import { getPage } from 'utils/utils'
  6. import { getShapeUtils } from 'lib/shape-utils'
  7. export default function rotateCommand(
  8. data: Data,
  9. before: RotateSnapshot,
  10. after: RotateSnapshot
  11. ) {
  12. history.execute(
  13. data,
  14. new Command({
  15. name: 'translate_shapes',
  16. category: 'canvas',
  17. do(data) {
  18. const { shapes } = getPage(data)
  19. for (let { id, point, rotation } of after.initialShapes) {
  20. const shape = shapes[id]
  21. const utils = getShapeUtils(shape)
  22. utils.rotateTo(shape, rotation).translateTo(shape, point)
  23. }
  24. data.boundsRotation = after.boundsRotation
  25. },
  26. undo(data) {
  27. const { shapes } = getPage(data, before.currentPageId)
  28. for (let { id, point, rotation } of before.initialShapes) {
  29. const shape = shapes[id]
  30. const utils = getShapeUtils(shape)
  31. utils.rotateTo(shape, rotation).translateTo(shape, point)
  32. }
  33. data.boundsRotation = before.boundsRotation
  34. },
  35. })
  36. )
  37. }