transform.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { TransCreateFn, TransferCtrl } from "..";
  2. function getTransform(this: TransferCtrl, transType: string) {
  3. const { transEvent } = this;
  4. const { transform = {} } = this.currComp.layout;
  5. const offset = {
  6. x: transform.x || 0,
  7. y: transform.y || 0,
  8. r: transform.r || 0,
  9. s: transform.s || 1,
  10. };
  11. switch (transType) {
  12. case "move":
  13. offset.x += transEvent.offsetX * 2;
  14. offset.y += transEvent.offsetY * 2;
  15. break;
  16. case "rotate":
  17. offset.r = (offset.r + transEvent.offsetX * -1) % 360;
  18. break;
  19. case "scale":
  20. offset.s = +((offset.s * (1 + (transEvent.offsetX * 2) / transEvent.width)).toFixed(2))
  21. console.log(offset.s);
  22. }
  23. return offset;
  24. }
  25. const transform: TransCreateFn = (transType: string) => ({
  26. mousemove() {
  27. const style = this.module.helper.createStyle({
  28. transform: getTransform.call(this, transType),
  29. });
  30. Object.entries(style).forEach(([key, value]: any[]) => {
  31. this.compEl.style[key] = value;
  32. });
  33. },
  34. mouseup() {
  35. this.currComp.layout.transform = getTransform.call(this, transType);
  36. },
  37. });
  38. export const move = transform.bind(null, "move");
  39. export const rotate = transform.bind(null, "rotate");
  40. export const scale = transform.bind(null, "scale");