Blame view

天文台pc/tianwentai-ui/node_modules/framer-motion/dist/es/motion/utils/use-visual-state.mjs 3.27 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  "use client";
  import { resolveMotionValue, isControllingVariants, isVariantNode, isAnimationControls, resolveVariantFromProps } from 'motion-dom';
  import { useContext } from 'react';
  import { MotionContext } from '../../context/MotionContext/index.mjs';
  import { PresenceContext } from '../../context/PresenceContext.mjs';
  import { useConstant } from '../../utils/use-constant.mjs';
  
  function makeState({ scrapeMotionValuesFromProps, createRenderState, }, props, context, presenceContext) {
      const state = {
          latestValues: makeLatestValues(props, context, presenceContext, scrapeMotionValuesFromProps),
          renderState: createRenderState(),
      };
      return state;
  }
  function makeLatestValues(props, context, presenceContext, scrapeMotionValues) {
      const values = {};
      const motionValues = scrapeMotionValues(props, {});
      for (const key in motionValues) {
          values[key] = resolveMotionValue(motionValues[key]);
      }
      let { initial, animate } = props;
      const isControllingVariants$1 = isControllingVariants(props);
      const isVariantNode$1 = isVariantNode(props);
      if (context &&
          isVariantNode$1 &&
          !isControllingVariants$1 &&
          props.inherit !== false) {
          if (initial === undefined)
              initial = context.initial;
          if (animate === undefined)
              animate = context.animate;
      }
      let isInitialAnimationBlocked = presenceContext
          ? presenceContext.initial === false
          : false;
      isInitialAnimationBlocked = isInitialAnimationBlocked || initial === false;
      const variantToSet = isInitialAnimationBlocked ? animate : initial;
      if (variantToSet &&
          typeof variantToSet !== "boolean" &&
          !isAnimationControls(variantToSet)) {
          const list = Array.isArray(variantToSet) ? variantToSet : [variantToSet];
          for (let i = 0; i < list.length; i++) {
              const resolved = resolveVariantFromProps(props, list[i]);
              if (resolved) {
                  const { transitionEnd, transition, ...target } = resolved;
                  for (const key in target) {
                      let valueTarget = target[key];
                      if (Array.isArray(valueTarget)) {
                          /**
                           * Take final keyframe if the initial animation is blocked because
                           * we want to initialise at the end of that blocked animation.
                           */
                          const index = isInitialAnimationBlocked
                              ? valueTarget.length - 1
                              : 0;
                          valueTarget = valueTarget[index];
                      }
                      if (valueTarget !== null) {
                          values[key] = valueTarget;
                      }
                  }
                  for (const key in transitionEnd) {
                      values[key] = transitionEnd[key];
                  }
              }
          }
      }
      return values;
  }
  const makeUseVisualState = (config) => (props, isStatic) => {
      const context = useContext(MotionContext);
      const presenceContext = useContext(PresenceContext);
      const make = () => makeState(config, props, context, presenceContext);
      return isStatic ? make() : useConstant(make);
  };
  
  export { makeUseVisualState };
  //# sourceMappingURL=use-visual-state.mjs.map