Blame view

天文台pc/tianwentai-ui/node_modules/motion-dom/dist/es/projection/animation/mix-values.mjs 2.53 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
  import { mixNumber } from '../../utils/mix/number.mjs';
  import { percent, px } from '../../value/types/numbers/units.mjs';
  import { progress, circOut, noop } from 'motion-utils';
  
  const borderLabels = [
      "borderTopLeftRadius",
      "borderTopRightRadius",
      "borderBottomLeftRadius",
      "borderBottomRightRadius",
  ];
  const numBorders = borderLabels.length;
  const asNumber = (value) => typeof value === "string" ? parseFloat(value) : value;
  const isPx = (value) => typeof value === "number" || px.test(value);
  function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnlyMember) {
      if (shouldCrossfadeOpacity) {
          target.opacity = mixNumber(0, lead.opacity ?? 1, easeCrossfadeIn(progress));
          target.opacityExit = mixNumber(follow.opacity ?? 1, 0, easeCrossfadeOut(progress));
      }
      else if (isOnlyMember) {
          target.opacity = mixNumber(follow.opacity ?? 1, lead.opacity ?? 1, progress);
      }
      /**
       * Mix border radius
       */
      for (let i = 0; i < numBorders; i++) {
          const borderLabel = borderLabels[i];
          let followRadius = getRadius(follow, borderLabel);
          let leadRadius = getRadius(lead, borderLabel);
          if (followRadius === undefined && leadRadius === undefined)
              continue;
          followRadius || (followRadius = 0);
          leadRadius || (leadRadius = 0);
          const canMix = followRadius === 0 ||
              leadRadius === 0 ||
              isPx(followRadius) === isPx(leadRadius);
          if (canMix) {
              target[borderLabel] = Math.max(mixNumber(asNumber(followRadius), asNumber(leadRadius), progress), 0);
              if (percent.test(leadRadius) || percent.test(followRadius)) {
                  target[borderLabel] += "%";
              }
          }
          else {
              target[borderLabel] = leadRadius;
          }
      }
      /**
       * Mix rotation
       */
      if (follow.rotate || lead.rotate) {
          target.rotate = mixNumber(follow.rotate || 0, lead.rotate || 0, progress);
      }
  }
  function getRadius(values, radiusName) {
      return values[radiusName] !== undefined
          ? values[radiusName]
          : values.borderRadius;
  }
  const easeCrossfadeIn = /*@__PURE__*/ compress(0, 0.5, circOut);
  const easeCrossfadeOut = /*@__PURE__*/ compress(0.5, 0.95, noop);
  function compress(min, max, easing) {
      return (p) => {
          // Could replace ifs with clamp
          if (p < min)
              return 0;
          if (p > max)
              return 1;
          return easing(progress(min, max, p));
      };
  }
  
  export { mixValues };
  //# sourceMappingURL=mix-values.mjs.map