您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

rotate.ts 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. getShapeUtils(shape)
  22. .rotateBy(shape, rotation - shape.rotation)
  23. .translateTo(shape, point)
  24. .onSessionComplete(shape)
  25. }
  26. data.boundsRotation = after.boundsRotation
  27. },
  28. undo(data) {
  29. const { shapes } = getPage(data, before.currentPageId)
  30. for (let { id, point, rotation } of before.initialShapes) {
  31. const shape = shapes[id]
  32. getShapeUtils(shape)
  33. .rotateBy(shape, rotation - shape.rotation)
  34. .translateTo(shape, point)
  35. .onSessionComplete(shape)
  36. }
  37. data.boundsRotation = before.boundsRotation
  38. },
  39. })
  40. )
  41. }