1 | import { AUTO_STYLE } from '@angular/core';
|
2 | export var MockAnimationPlayer = (function () {
|
3 | function MockAnimationPlayer(startingStyles, keyframes, previousPlayers) {
|
4 | var _this = this;
|
5 | if (startingStyles === void 0) { startingStyles = {}; }
|
6 | if (keyframes === void 0) { keyframes = []; }
|
7 | if (previousPlayers === void 0) { previousPlayers = []; }
|
8 | this.startingStyles = startingStyles;
|
9 | this.keyframes = keyframes;
|
10 | this._onDoneFns = [];
|
11 | this._onStartFns = [];
|
12 | this._finished = false;
|
13 | this._destroyed = false;
|
14 | this._started = false;
|
15 | this.parentPlayer = null;
|
16 | this.previousStyles = {};
|
17 | this.log = [];
|
18 | previousPlayers.forEach(function (player) {
|
19 | if (player instanceof MockAnimationPlayer) {
|
20 | var styles_1 = player._captureStyles();
|
21 | Object.keys(styles_1).forEach(function (prop) { return _this.previousStyles[prop] = styles_1[prop]; });
|
22 | }
|
23 | });
|
24 | }
|
25 | MockAnimationPlayer.prototype._onFinish = function () {
|
26 | if (!this._finished) {
|
27 | this._finished = true;
|
28 | this.log.push('finish');
|
29 | this._onDoneFns.forEach(function (fn) { return fn(); });
|
30 | this._onDoneFns = [];
|
31 | }
|
32 | };
|
33 | MockAnimationPlayer.prototype.init = function () { this.log.push('init'); };
|
34 | MockAnimationPlayer.prototype.onDone = function (fn) { this._onDoneFns.push(fn); };
|
35 | MockAnimationPlayer.prototype.onStart = function (fn) { this._onStartFns.push(fn); };
|
36 | MockAnimationPlayer.prototype.hasStarted = function () { return this._started; };
|
37 | MockAnimationPlayer.prototype.play = function () {
|
38 | if (!this.hasStarted()) {
|
39 | this._onStartFns.forEach(function (fn) { return fn(); });
|
40 | this._onStartFns = [];
|
41 | this._started = true;
|
42 | }
|
43 | this.log.push('play');
|
44 | };
|
45 | MockAnimationPlayer.prototype.pause = function () { this.log.push('pause'); };
|
46 | MockAnimationPlayer.prototype.restart = function () { this.log.push('restart'); };
|
47 | MockAnimationPlayer.prototype.finish = function () { this._onFinish(); };
|
48 | MockAnimationPlayer.prototype.reset = function () {
|
49 | this.log.push('reset');
|
50 | this._destroyed = false;
|
51 | this._finished = false;
|
52 | this._started = false;
|
53 | };
|
54 | MockAnimationPlayer.prototype.destroy = function () {
|
55 | if (!this._destroyed) {
|
56 | this._destroyed = true;
|
57 | this.finish();
|
58 | this.log.push('destroy');
|
59 | }
|
60 | };
|
61 | MockAnimationPlayer.prototype.setPosition = function (p) { };
|
62 | MockAnimationPlayer.prototype.getPosition = function () { return 0; };
|
63 | MockAnimationPlayer.prototype._captureStyles = function () {
|
64 | var _this = this;
|
65 | var captures = {};
|
66 | if (this.hasStarted()) {
|
67 |
|
68 |
|
69 |
|
70 | Object.keys(this.startingStyles).forEach(function (prop) {
|
71 | captures[prop] = _this.startingStyles[prop];
|
72 | });
|
73 | this.keyframes.forEach(function (kf) {
|
74 | var offset = kf[0], styles = kf[1];
|
75 | var newStyles = {};
|
76 | Object.keys(styles).forEach(function (prop) { captures[prop] = _this._finished ? styles[prop] : AUTO_STYLE; });
|
77 | });
|
78 | }
|
79 | Object.keys(this.previousStyles).forEach(function (prop) {
|
80 | captures[prop] = _this.previousStyles[prop];
|
81 | });
|
82 | return captures;
|
83 | };
|
84 | return MockAnimationPlayer;
|
85 | }());
|
86 |
|
\ | No newline at end of file |