Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

transform.ts 1.8KB

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