Blame view

天文台pc/tianwentai-ui/node_modules/framer-motion/dist/es/animation/animate/subject.mjs 2.21 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
51
52
53
54
  import { animateSingleValue, visualElementStore, animateTarget, isMotionValue } from 'motion-dom';
  import { invariant } from 'motion-utils';
  import { createDOMVisualElement, createObjectVisualElement } from '../utils/create-visual-element.mjs';
  import { isDOMKeyframes } from '../utils/is-dom-keyframes.mjs';
  import { resolveSubjects } from './resolve-subjects.mjs';
  
  function isSingleValue(subject, keyframes) {
      return (isMotionValue(subject) ||
          typeof subject === "number" ||
          (typeof subject === "string" && !isDOMKeyframes(keyframes)));
  }
  /**
   * Implementation
   */
  function animateSubject(subject, keyframes, options, scope) {
      const animations = [];
      if (isSingleValue(subject, keyframes)) {
          animations.push(animateSingleValue(subject, isDOMKeyframes(keyframes)
              ? keyframes.default || keyframes
              : keyframes, options ? options.default || options : options));
      }
      else {
          // Gracefully handle null/undefined subjects (e.g., from querySelector returning null)
          if (subject == null) {
              return animations;
          }
          const subjects = resolveSubjects(subject, keyframes, scope);
          const numSubjects = subjects.length;
          invariant(Boolean(numSubjects), "No valid elements provided.", "no-valid-elements");
          for (let i = 0; i < numSubjects; i++) {
              const thisSubject = subjects[i];
              const createVisualElement = thisSubject instanceof Element
                  ? createDOMVisualElement
                  : createObjectVisualElement;
              if (!visualElementStore.has(thisSubject)) {
                  createVisualElement(thisSubject);
              }
              const visualElement = visualElementStore.get(thisSubject);
              const transition = { ...options };
              /**
               * Resolve stagger function if provided.
               */
              if ("delay" in transition &&
                  typeof transition.delay === "function") {
                  transition.delay = transition.delay(i, numSubjects);
              }
              animations.push(...animateTarget(visualElement, { ...keyframes, transition }, {}));
          }
      }
      return animations;
  }
  
  export { animateSubject };
  //# sourceMappingURL=subject.mjs.map