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

rotate.ts 1.1KB

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.shapes) {
  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.shapes) {
  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. }