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.

transform.ts 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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: 'transform_shapes',
  18. category: 'canvas',
  19. do(data) {
  20. const { type, shapeBounds } = after
  21. const { shapes } = getPage(data)
  22. for (let id in shapeBounds) {
  23. const { initialShapeBounds: bounds } = after.shapeBounds[id]
  24. const { initialShape, transformOrigin } = before.shapeBounds[id]
  25. const shape = shapes[id]
  26. getShapeUtils(shape)
  27. .transform(shape, bounds, {
  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 { shapeBounds } = before
  40. const { shapes } = getPage(data)
  41. for (let id in shapeBounds) {
  42. shapes[id] = shapeBounds[id].initialShape
  43. }
  44. updateParents(data, Object.keys(shapeBounds))
  45. },
  46. })
  47. )
  48. }