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.

inputs.tsx 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { PointerInfo } from "types"
  2. import { isDarwin } from "utils/utils"
  3. class Inputs {
  4. points: Record<string, PointerInfo> = {}
  5. pointerDown(e: PointerEvent | React.PointerEvent, target: string) {
  6. const { shiftKey, ctrlKey, metaKey, altKey } = e
  7. const info = {
  8. target,
  9. pointerId: e.pointerId,
  10. origin: [e.clientX, e.clientY],
  11. point: [e.clientX, e.clientY],
  12. shiftKey,
  13. ctrlKey,
  14. metaKey: isDarwin() ? metaKey : ctrlKey,
  15. altKey,
  16. }
  17. this.points[e.pointerId] = info
  18. return info
  19. }
  20. pointerMove(e: PointerEvent | React.PointerEvent) {
  21. const { shiftKey, ctrlKey, metaKey, altKey } = e
  22. const prev = this.points[e.pointerId]
  23. const info = {
  24. ...prev,
  25. pointerId: e.pointerId,
  26. point: [e.clientX, e.clientY],
  27. shiftKey,
  28. ctrlKey,
  29. metaKey: isDarwin() ? metaKey : ctrlKey,
  30. altKey,
  31. }
  32. if (this.points[e.pointerId]) {
  33. this.points[e.pointerId] = info
  34. }
  35. return info
  36. }
  37. pointerUp(e: PointerEvent | React.PointerEvent) {
  38. const { shiftKey, ctrlKey, metaKey, altKey } = e
  39. const prev = this.points[e.pointerId]
  40. const info = {
  41. ...prev,
  42. origin: prev?.origin || [e.clientX, e.clientY],
  43. point: [e.clientX, e.clientY],
  44. shiftKey,
  45. ctrlKey,
  46. metaKey: isDarwin() ? metaKey : ctrlKey,
  47. altKey,
  48. }
  49. delete this.points[e.pointerId]
  50. return info
  51. }
  52. wheel(e: WheelEvent) {
  53. const { shiftKey, ctrlKey, metaKey, altKey } = e
  54. return { point: [e.clientX, e.clientY], shiftKey, ctrlKey, metaKey, altKey }
  55. }
  56. }
  57. export default new Inputs()