Blame view

天文台pc/tianwentai-ui/node_modules/motion-dom/dist/es/render/utils/resolve-variants.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
  function getValueState(visualElement) {
      const state = [{}, {}];
      visualElement?.values.forEach((value, key) => {
          state[0][key] = value.get();
          state[1][key] = value.getVelocity();
      });
      return state;
  }
  function resolveVariantFromProps(props, definition, custom, visualElement) {
      /**
       * If the variant definition is a function, resolve.
       */
      if (typeof definition === "function") {
          const [current, velocity] = getValueState(visualElement);
          definition = definition(custom !== undefined ? custom : props.custom, current, velocity);
      }
      /**
       * If the variant definition is a variant label, or
       * the function returned a variant label, resolve.
       */
      if (typeof definition === "string") {
          definition = props.variants && props.variants[definition];
      }
      /**
       * At this point we've resolved both functions and variant labels,
       * but the resolved variant label might itself have been a function.
       * If so, resolve. This can only have returned a valid target object.
       */
      if (typeof definition === "function") {
          const [current, velocity] = getValueState(visualElement);
          definition = definition(custom !== undefined ? custom : props.custom, current, velocity);
      }
      return definition;
  }
  
  export { resolveVariantFromProps };
  //# sourceMappingURL=resolve-variants.mjs.map