Blame view

天文台pc/tianwentai-ui/node_modules/motion-dom/dist/es/animation/GroupAnimation.mjs 2.13 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
  class GroupAnimation {
      constructor(animations) {
          // Bound to accomadate common `return animation.stop` pattern
          this.stop = () => this.runAll("stop");
          this.animations = animations.filter(Boolean);
      }
      get finished() {
          return Promise.all(this.animations.map((animation) => animation.finished));
      }
      /**
       * TODO: Filter out cancelled or stopped animations before returning
       */
      getAll(propName) {
          return this.animations[0][propName];
      }
      setAll(propName, newValue) {
          for (let i = 0; i < this.animations.length; i++) {
              this.animations[i][propName] = newValue;
          }
      }
      attachTimeline(timeline) {
          const subscriptions = this.animations.map((animation) => animation.attachTimeline(timeline));
          return () => {
              subscriptions.forEach((cancel, i) => {
                  cancel && cancel();
                  this.animations[i].stop();
              });
          };
      }
      get time() {
          return this.getAll("time");
      }
      set time(time) {
          this.setAll("time", time);
      }
      get speed() {
          return this.getAll("speed");
      }
      set speed(speed) {
          this.setAll("speed", speed);
      }
      get state() {
          return this.getAll("state");
      }
      get startTime() {
          return this.getAll("startTime");
      }
      get duration() {
          return getMax(this.animations, "duration");
      }
      get iterationDuration() {
          return getMax(this.animations, "iterationDuration");
      }
      runAll(methodName) {
          this.animations.forEach((controls) => controls[methodName]());
      }
      play() {
          this.runAll("play");
      }
      pause() {
          this.runAll("pause");
      }
      cancel() {
          this.runAll("cancel");
      }
      complete() {
          this.runAll("complete");
      }
  }
  function getMax(animations, propName) {
      let max = 0;
      for (let i = 0; i < animations.length; i++) {
          const value = animations[i][propName];
          if (value !== null && value > max) {
              max = value;
          }
      }
      return max;
  }
  
  export { GroupAnimation };
  //# sourceMappingURL=GroupAnimation.mjs.map