Blame view

天文台pc/tianwentai-ui/node_modules/framer-motion/dist/es/gestures/pan/index.mjs 1.7 KB
bc518174   王天杨   提交两个项目文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  import { Feature, frame } from 'motion-dom';
  import { noop } from 'motion-utils';
  import { addPointerEvent } from '../../events/add-pointer-event.mjs';
  import { getContextWindow } from '../../utils/get-context-window.mjs';
  import { PanSession } from './PanSession.mjs';
  
  const asyncHandler = (handler) => (event, info) => {
      if (handler) {
          frame.update(() => handler(event, info), false, true);
      }
  };
  class PanGesture extends Feature {
      constructor() {
          super(...arguments);
          this.removePointerDownListener = noop;
      }
      onPointerDown(pointerDownEvent) {
          this.session = new PanSession(pointerDownEvent, this.createPanHandlers(), {
              transformPagePoint: this.node.getTransformPagePoint(),
              contextWindow: getContextWindow(this.node),
          });
      }
      createPanHandlers() {
          const { onPanSessionStart, onPanStart, onPan, onPanEnd } = this.node.getProps();
          return {
              onSessionStart: asyncHandler(onPanSessionStart),
              onStart: asyncHandler(onPanStart),
              onMove: asyncHandler(onPan),
              onEnd: (event, info) => {
                  delete this.session;
                  if (onPanEnd) {
                      frame.postRender(() => onPanEnd(event, info));
                  }
              },
          };
      }
      mount() {
          this.removePointerDownListener = addPointerEvent(this.node.current, "pointerdown", (event) => this.onPointerDown(event));
      }
      update() {
          this.session && this.session.updateHandlers(this.createPanHandlers());
      }
      unmount() {
          this.removePointerDownListener();
          this.session && this.session.end();
      }
  }
  
  export { PanGesture };
  //# sourceMappingURL=index.mjs.map