Blame view

天文台pc/tianwentai-ui/node_modules/motion-dom/dist/es/render/utils/setters.mjs 1.1 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
  import { motionValue } from '../../value/index.mjs';
  import { resolveVariant } from './resolve-dynamic-variants.mjs';
  import { isKeyframesTarget } from './is-keyframes-target.mjs';
  
  /**
   * Set VisualElement's MotionValue, creating a new MotionValue for it if
   * it doesn't exist.
   */
  function setMotionValue(visualElement, key, value) {
      if (visualElement.hasValue(key)) {
          visualElement.getValue(key).set(value);
      }
      else {
          visualElement.addValue(key, motionValue(value));
      }
  }
  function resolveFinalValueInKeyframes(v) {
      // TODO maybe throw if v.length - 1 is placeholder token?
      return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
  }
  function setTarget(visualElement, definition) {
      const resolved = resolveVariant(visualElement, definition);
      let { transitionEnd = {}, transition = {}, ...target } = resolved || {};
      target = { ...target, ...transitionEnd };
      for (const key in target) {
          const value = resolveFinalValueInKeyframes(target[key]);
          setMotionValue(visualElement, key, value);
      }
  }
  
  export { setTarget };
  //# sourceMappingURL=setters.mjs.map