Blame view

天文台pc/tianwentai-ui/node_modules/motion-dom/dist/es/utils/mix/complex.mjs 3.34 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
  import { pipe, warning } from 'motion-utils';
  import { isCSSVariableToken } from '../../animation/utils/is-css-variable.mjs';
  import { color } from '../../value/types/color/index.mjs';
  import { complex, analyseComplexValue } from '../../value/types/complex/index.mjs';
  import { mixColor } from './color.mjs';
  import { mixImmediate } from './immediate.mjs';
  import { mixNumber as mixNumber$1 } from './number.mjs';
  import { invisibleValues, mixVisibility } from './visibility.mjs';
  
  function mixNumber(a, b) {
      return (p) => mixNumber$1(a, b, p);
  }
  function getMixer(a) {
      if (typeof a === "number") {
          return mixNumber;
      }
      else if (typeof a === "string") {
          return isCSSVariableToken(a)
              ? mixImmediate
              : color.test(a)
                  ? mixColor
                  : mixComplex;
      }
      else if (Array.isArray(a)) {
          return mixArray;
      }
      else if (typeof a === "object") {
          return color.test(a) ? mixColor : mixObject;
      }
      return mixImmediate;
  }
  function mixArray(a, b) {
      const output = [...a];
      const numValues = output.length;
      const blendValue = a.map((v, i) => getMixer(v)(v, b[i]));
      return (p) => {
          for (let i = 0; i < numValues; i++) {
              output[i] = blendValue[i](p);
          }
          return output;
      };
  }
  function mixObject(a, b) {
      const output = { ...a, ...b };
      const blendValue = {};
      for (const key in output) {
          if (a[key] !== undefined && b[key] !== undefined) {
              blendValue[key] = getMixer(a[key])(a[key], b[key]);
          }
      }
      return (v) => {
          for (const key in blendValue) {
              output[key] = blendValue[key](v);
          }
          return output;
      };
  }
  function matchOrder(origin, target) {
      const orderedOrigin = [];
      const pointers = { color: 0, var: 0, number: 0 };
      for (let i = 0; i < target.values.length; i++) {
          const type = target.types[i];
          const originIndex = origin.indexes[type][pointers[type]];
          const originValue = origin.values[originIndex] ?? 0;
          orderedOrigin[i] = originValue;
          pointers[type]++;
      }
      return orderedOrigin;
  }
  const mixComplex = (origin, target) => {
      const template = complex.createTransformer(target);
      const originStats = analyseComplexValue(origin);
      const targetStats = analyseComplexValue(target);
      const canInterpolate = originStats.indexes.var.length === targetStats.indexes.var.length &&
          originStats.indexes.color.length === targetStats.indexes.color.length &&
          originStats.indexes.number.length >= targetStats.indexes.number.length;
      if (canInterpolate) {
          if ((invisibleValues.has(origin) &&
              !targetStats.values.length) ||
              (invisibleValues.has(target) &&
                  !originStats.values.length)) {
              return mixVisibility(origin, target);
          }
          return pipe(mixArray(matchOrder(originStats, targetStats), targetStats.values), template);
      }
      else {
          warning(true, `Complex values '${origin}' and '${target}' too different to mix. Ensure all colors are of the same type, and that each contains the same quantity of number and color values. Falling back to instant transition.`, "complex-values-different");
          return mixImmediate(origin, target);
      }
  };
  
  export { getMixer, mixArray, mixComplex, mixObject };
  //# sourceMappingURL=complex.mjs.map