Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

transform-single.ts 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import Command from "./command"
  2. import history from "../history"
  3. import { Data, TransformCorner, TransformEdge } from "types"
  4. import { getShapeUtils } from "lib/shapes"
  5. import { current } from "immer"
  6. import { TransformSingleSnapshot } from "state/sessions/transform-single-session"
  7. export default function transformSingleCommand(
  8. data: Data,
  9. before: TransformSingleSnapshot,
  10. after: TransformSingleSnapshot,
  11. scaleX: number,
  12. scaleY: number,
  13. isCreating: boolean
  14. ) {
  15. const shape =
  16. current(data).document.pages[after.currentPageId].shapes[after.id]
  17. history.execute(
  18. data,
  19. new Command({
  20. name: "transform_single_shape",
  21. category: "canvas",
  22. manualSelection: true,
  23. do(data) {
  24. const { id, currentPageId, type, initialShape, initialShapeBounds } =
  25. after
  26. data.selectedIds.clear()
  27. data.selectedIds.add(id)
  28. if (isCreating) {
  29. data.document.pages[currentPageId].shapes[id] = shape
  30. } else {
  31. getShapeUtils(shape).transformSingle(shape, initialShapeBounds, {
  32. type,
  33. initialShape,
  34. scaleX,
  35. scaleY,
  36. })
  37. }
  38. },
  39. undo(data) {
  40. const { id, currentPageId, type, initialShapeBounds } = before
  41. data.selectedIds.clear()
  42. if (isCreating) {
  43. delete data.document.pages[currentPageId].shapes[id]
  44. } else {
  45. const shape = data.document.pages[currentPageId].shapes[id]
  46. data.selectedIds.add(id)
  47. getShapeUtils(shape).transform(shape, initialShapeBounds, {
  48. type,
  49. initialShape: after.initialShape,
  50. scaleX: 1,
  51. scaleY: 1,
  52. })
  53. }
  54. },
  55. })
  56. )
  57. }