/
tweenable.js
212 lines (177 loc) · 6.7 KB
/
tweenable.js
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _get = function get(_x2, _x3, _x4) { var _again = true; _function: while (_again) { var object = _x2, property = _x3, receiver = _x4; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x2 = parent; _x3 = property; _x4 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
var _tween = require('./tween');
var _tween2 = _interopRequireDefault(_tween);
var _timeline = require('./timeline');
var _timeline2 = _interopRequireDefault(_timeline);
var _module2 = require('../module');
/*
Class to define a module ancestor
with timeline and tween options and functionality.
All runable modules should inherit from this class.
@class Tweenable
*/
var _module3 = _interopRequireDefault(_module2);
var Tweenable = (function (_Module) {
_inherits(Tweenable, _Module);
_createClass(Tweenable, [{
key: 'play',
/*
play method for the timeline.
@public
@param {Number} Time shift.
@returns this.
*/
value: function play() {
this.timeline.play.apply(this.timeline, arguments);
return this;
}
/*
playBackward method for the timeline.
@public
@param {Number} Time shift.
@returns this.
*/
}, {
key: 'playBackward',
value: function playBackward() {
this.timeline.playBackward.apply(this.timeline, arguments);
return this;
}
/*
pause method for the timeline.
@public
@returns this.
*/
}, {
key: 'pause',
value: function pause() {
this.timeline.pause.apply(this.timeline, arguments);
return this;
}
/*
stop method for the timeline.
@public
@param {Number} [0...1] Progress to set on stop.
*Default* is `0` if `play`
and `1` if `playBAckward`.
@returns this.
*/
}, {
key: 'stop',
value: function stop() {
this.timeline.stop.apply(this.timeline, arguments);
return this;
}
/*
replay method for the timeline.
@public
@returns this.
*/
}, {
key: 'replay',
value: function replay() {
this.timeline.replay.apply(this.timeline, arguments);
return this;
}
/*
replay method for the timeline.
@public
@returns this.
*/
}, {
key: 'replayBackward',
value: function replayBackward() {
this.timeline.replayBackward.apply(this.timeline, arguments);
return this;
}
/*
setProgress method for the timeline.
@public
@param {Number} [0...1] Progress value.
@returns this.
*/
}, {
key: 'setProgress',
value: function setProgress() {
this.timeline.setProgress.apply(this.timeline, arguments);
return this;
}
/*
setSpeed method for the timeline.
@param {Number} Speed value.
@returns this.
*/
}, {
key: 'setSpeed',
value: function setSpeed(speed) {
this.timeline.setSpeed.apply(this.timeline, arguments);
return this;
}
// ^ PUBLIC METHOD(S) ^
// v PRIVATE METHOD(S) v
}]);
function Tweenable() {
var o = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
_classCallCheck(this, Tweenable);
// super of Module
_get(Object.getPrototypeOf(Tweenable.prototype), 'constructor', this).call(this, o);
// pipe function for _o object
// before creating tween/timeline
this._transformTweenOptions();
// make tween only if isTweenLess option is not set
!this._o.isTweenLess && this._makeTween();
// make timeline only if isTimelineLess option is not set
!this._o.isTimelineLess && this._makeTimeline();
}
/*
Placeholder method that should be overrided
and will be called before tween/timeline creation.
@private
*/
_createClass(Tweenable, [{
key: '_transformTweenOptions',
value: function _transformTweenOptions() {}
/*
Method to create tween.
@private
*/
}, {
key: '_makeTween',
value: function _makeTween() {
// pass callbacks context
this._o.callbacksContext = this._o.callbacksContext || this;
this.tween = new _tween2['default'](this._o);
// make timeline property point to tween one is "no timeline" mode
this._o.isTimelineLess && (this.timeline = this.tween);
}
/*
Method to create timeline.
@private
@param {Object} Timeline's options.
An object which contains "timeline" property with
timeline options.
*/
}, {
key: '_makeTimeline',
value: function _makeTimeline() {
// pass callbacks context
this._o.timeline = this._o.timeline || {};
this._o.timeline.callbacksContext = this._o.callbacksContext || this;
this.timeline = new _timeline2['default'](this._o.timeline);
// if tween exist - add it to the timeline there is some
// modules like burst and stagger that have no tween
this.tween && this.timeline.add(this.tween);
}
}]);
return Tweenable;
})(_module3['default']);
exports['default'] = Tweenable;
module.exports = exports['default'];