Blame view

天文台pc/tianwentai-ui/node_modules/framer-motion/dist/es/gestures/focus.mjs 1.36 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
  import { Feature, addDomEvent } from 'motion-dom';
  import { pipe } from 'motion-utils';
  
  class FocusGesture extends Feature {
      constructor() {
          super(...arguments);
          this.isActive = false;
      }
      onFocus() {
          let isFocusVisible = false;
          /**
           * If this element doesn't match focus-visible then don't
           * apply whileHover. But, if matches throws that focus-visible
           * is not a valid selector then in that browser outline styles will be applied
           * to the element by default and we want to match that behaviour with whileFocus.
           */
          try {
              isFocusVisible = this.node.current.matches(":focus-visible");
          }
          catch (e) {
              isFocusVisible = true;
          }
          if (!isFocusVisible || !this.node.animationState)
              return;
          this.node.animationState.setActive("whileFocus", true);
          this.isActive = true;
      }
      onBlur() {
          if (!this.isActive || !this.node.animationState)
              return;
          this.node.animationState.setActive("whileFocus", false);
          this.isActive = false;
      }
      mount() {
          this.unmount = pipe(addDomEvent(this.node.current, "focus", () => this.onFocus()), addDomEvent(this.node.current, "blur", () => this.onBlur()));
      }
      unmount() { }
  }
  
  export { FocusGesture };
  //# sourceMappingURL=focus.mjs.map