From b97d69715c89761ae526c245871e059b115b6ec4 Mon Sep 17 00:00:00 2001 From: Cain Martin Date: Wed, 13 Apr 2016 11:41:28 +0900 Subject: [PATCH 01/18] Implemented a basic CSSTween mechanism in tina. Supports tweens for the following CSS attributes: top, bottom, left, right, height, width, opacity. Caveats: Does not currently support relativeTransitions - this may require a refactor of the way coordinates are handled for CSS objects (vs sprites). There is also currently no support for transforms. --- build/tina.js | 201 +++++++++++++++++++++++++++++++--------- build/tina.min.js | 60 ++++++------ examples/css/index.html | 29 ++++++ examples/css/index.js | 32 +++++++ examples/styles.css | 7 ++ src/AbstractTween.js | 9 +- src/CSSMap.js | 27 ++++++ src/CSSTween.js | 10 +- src/Transition.js | 89 ++++++++++++++---- src/index.js | 2 +- 10 files changed, 371 insertions(+), 95 deletions(-) create mode 100644 examples/css/index.html create mode 100644 examples/css/index.js create mode 100644 src/CSSMap.js diff --git a/build/tina.js b/build/tina.js index 88442db..8161e9e 100644 --- a/build/tina.js +++ b/build/tina.js @@ -1,6 +1,7 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o Using linear easing @@ -2671,7 +2786,7 @@ function Transition(properties, from, to, start, duration, easing, easingParam, } module.exports = Transition; -},{}],17:[function(require,module,exports){ +},{}],19:[function(require,module,exports){ // One property function update(object, t) { @@ -2824,7 +2939,7 @@ function Transition(properties, from, to, start, duration, easing, easingParam, } module.exports = Transition; -},{}],18:[function(require,module,exports){ +},{}],20:[function(require,module,exports){ var BriefPlayable = require('./BriefPlayable'); var AbstractTween = require('./AbstractTween'); @@ -2867,7 +2982,7 @@ Tween.prototype.wait = function (duration) { } return this; }; -},{"./AbstractTween":1,"./BriefPlayable":3,"./inherit":22}],19:[function(require,module,exports){ +},{"./AbstractTween":1,"./BriefPlayable":3,"./inherit":24}],21:[function(require,module,exports){ var Player = require('./Player'); var TINA = require('./TINA'); @@ -2894,7 +3009,7 @@ Tweener.prototype.useAsDefault = function () { TINA.setDefaultTweener(this); return this; }; -},{"./Player":9,"./TINA":12}],20:[function(require,module,exports){ +},{"./Player":11,"./TINA":14}],22:[function(require,module,exports){ /** * * @file A set of ease functions @@ -3157,10 +3272,10 @@ exports.backInOut = function (t, e) { return 0.5 * (t * t * ((e + 1) * t + e)) + 1; }; -},{}],21:[function(require,module,exports){ +},{}],23:[function(require,module,exports){ var TINA = require('./TINA.js'); -// TINA.CSSTween = require('./CSSTween'); +TINA.CSSTween = require('./CSSTween'); TINA.Delay = require('./Delay'); TINA.BriefExtension = require('./BriefExtension'); TINA.BriefPlayable = require('./BriefPlayable'); @@ -3181,7 +3296,7 @@ TINA.Tweener = require('./Tweener'); module.exports = TINA; -},{"./BriefExtension":2,"./BriefPlayable":3,"./BriefPlayer":4,"./Delay":5,"./NestedTween":7,"./Playable":8,"./Player":9,"./Recorder":10,"./Sequence":11,"./TINA.js":12,"./Ticker":13,"./Timeline":14,"./Timer":15,"./Tween":18,"./Tweener":19,"./easing":20,"./interpolation":23}],22:[function(require,module,exports){ +},{"./BriefExtension":2,"./BriefPlayable":3,"./BriefPlayer":4,"./CSSTween":6,"./Delay":7,"./NestedTween":9,"./Playable":10,"./Player":11,"./Recorder":12,"./Sequence":13,"./TINA.js":14,"./Ticker":15,"./Timeline":16,"./Timer":17,"./Tween":20,"./Tweener":21,"./easing":22,"./interpolation":25}],24:[function(require,module,exports){ module.exports = function (subobject, superobject) { var prototypes = Object.keys(superobject.prototype); for (var p = 0; p < prototypes.length; p += 1) { @@ -3189,7 +3304,7 @@ module.exports = function (subobject, superobject) { subobject.prototype[prototypeName] = superobject.prototype[prototypeName]; } }; -},{}],23:[function(require,module,exports){ +},{}],25:[function(require,module,exports){ /** * * @file A set of interpolation functions @@ -3681,4 +3796,4 @@ exports.simplex2d = (function () { return a * (1 - t) + b * t; }; })(); -},{}]},{},[21]); +},{}]},{},[23]); diff --git a/build/tina.min.js b/build/tina.min.js index d18fb18..3ac847b 100644 --- a/build/tina.min.js +++ b/build/tina.min.js @@ -1,71 +1,77 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o0&&(this._transitions[0].from=t),this},AbstractTween.prototype._setFrom=function(){this._from={};for(var t=0;t0?this._relative===!0?this._setFrom():this._transitions[this._transitions.length-1].to:null===this._from?this._setFrom():this._from},AbstractTween.prototype.to=function(t,i,n,s,e){"string"==typeof n&&(void 0===easingFunctions[n]?(console.warn("[AbstractTween.to] Given easing does not exist"),n=void 0):n=easingFunctions[n]);var r=this._getLastTransitionEnding(),o=this._relative===!0?TransitionRelative:Transition,a=new o(this._properties,r,t,this._duration,i,n,s,this._interpolations,e);return this._transitions.push(a),this._duration+=i,this},AbstractTween.prototype.wait=function(t){var i=this._getLastTransitionEnding();return this._transitions.push(new Temporisation(this._duration,t,i,this._properties)),this._duration+=t,this},AbstractTween.prototype._update=function(){for(var t=this._transitions[this._index];t.end<=this._time;){if(this._index===this._transitions.length-1)return void t.update(this._object,1);this._relative===!0&&t.update(this._object,1),t=this._transitions[++this._index]}for(;this._time<=t.start;){if(0===this._index)return void t.update(this._object,0);this._relative===!0&&t.update(this._object,0),t=this._transitions[--this._index]}t.update(this._object,(this._time-t.start)/t.duration)},AbstractTween.prototype._validate=function(){return 0===this._transitions.length?(console.warn("[AbstractTween._validate] Cannot start a tween with no transition:",this),!1):!0}; +function Temporisation(t,i,n,s){this.start=t,this.end=t+i,this.duration=i,this.properties=s,this.to=n}function AbstractTween(t,i){if(this._object=t,(null===i||void 0===i)&&t instanceof Array){i=[];for(var n=0;n0&&(this._transitions[0].from=t),this},AbstractTween.prototype._setFrom=function(){this._from={};for(var t=0;t0?this._relative===!0?this._setFrom():this._transitions[this._transitions.length-1].to:null===this._from?this._setFrom():this._from},AbstractTween.prototype.to=function(t,i,n,s,e){"string"==typeof n&&(void 0===easingFunctions[n]?(console.warn("[AbstractTween.to] Given easing does not exist"),n=void 0):n=easingFunctions[n]);var r=this._getLastTransitionEnding(),o=this._relative===!0?TransitionRelative:Transition,a=new o(this._properties,r,t,this._duration,i,n,s,this._interpolations,e,this._suffixMap);return this._transitions.push(a),this._duration+=i,this},AbstractTween.prototype.wait=function(t){var i=this._getLastTransitionEnding();return this._transitions.push(new Temporisation(this._duration,t,i,this._properties)),this._duration+=t,this},AbstractTween.prototype._update=function(){for(var t=this._transitions[this._index];t.end<=this._time;){if(this._index===this._transitions.length-1)return void t.update(this._object,1);this._relative===!0&&t.update(this._object,1),t=this._transitions[++this._index]}for(;this._time<=t.start;){if(0===this._index)return void t.update(this._object,0);this._relative===!0&&t.update(this._object,0),t=this._transitions[--this._index]}t.update(this._object,(this._time-t.start)/t.duration)},AbstractTween.prototype._validate=function(){return 0===this._transitions.length?(console.warn("[AbstractTween._validate] Cannot start a tween with no transition:",this),!1):!0}; -},{"./Transition":16,"./TransitionRelative":17,"./easing":20,"./interpolation":23}],2:[function(require,module,exports){ +},{"./CSSMap":5,"./Transition":18,"./TransitionRelative":19,"./easing":22,"./interpolation":25}],2:[function(require,module,exports){ function BriefExtension(){this._duration=0,this._onComplete=null,this._iterations=1,this._pingpong=!1,this._persist=!1}module.exports=BriefExtension,BriefExtension.prototype.setSpeed=function(t){0===t?0!==this._speed&&(this._startTime+=this._time/this._speed-this._time):0===this._speed?this._startTime+=this._time-this._time/t:this._startTime+=this._time/this._speed-this._time/t,this._speed=t,null!==this._player&&this._player._onPlayableChanged(this)},BriefExtension.prototype.onComplete=function(t){return this._onComplete=t,this},BriefExtension.prototype.getDuration=function(){return this._duration*this._iterations/this._speed},BriefExtension.prototype._setDuration=function(t){this._duration=t,null!==this._player&&this._player._onPlayableChanged(this)},BriefExtension.prototype._extendDuration=function(t){this._duration+=t,null!==this._player&&this._player._onPlayableChanged(this)},BriefExtension.prototype._getEndTime=function(){return this._speed>0?this._startTime+this.getDuration():this._speed<0?this._startTime:1/0},BriefExtension.prototype._setStartTime=function(t){this._speed>0?this._startTime=t:this._speed<0?this._startTime=t-this.getDuration():this._startTime=1/0},BriefExtension.prototype._getStartTime=function(){return this._speed>0?this._startTime:this._speed<0?this._startTime+this.getDuration():-(1/0)},BriefExtension.prototype._isTimeWithin=function(t){return this._speed>0?this._startTime0?(this._startTime-i)*(this._startTime+this.getDuration()-t)<=0:this._speed<0?(this._startTime+this.getDuration()-i)*(this._startTime-t)<=0:!0},BriefExtension.prototype.goToEnd=function(){return this.goTo(this.getDuration(),this._iterations-1)},BriefExtension.prototype.loop=function(){return this.iterations(1/0)},BriefExtension.prototype.iterations=function(t){return 0>t?(console.warn("[BriefExtension.iterations] Number of iterations cannot be negative"),this):(this._iterations=t,null!==this._player&&this._player._onPlayableChanged(this),this)},BriefExtension.prototype.persist=function(t){return this._persist=t,this},BriefExtension.prototype.pingpong=function(t){return this._pingpong=t,null!==this._player&&this._player._onPlayableChanged(this),this},BriefExtension.prototype._complete=function(t){return this._persist===!0?(this._startTime+=t,void this._player._onPlayableChanged(this)):this._player._inactivate(this)===!1?this:void(null!==this._onComplete&&this._onComplete(t))};var epsilon=1e-6;BriefExtension.prototype._moveTo=function(t,i,e){i*=this._speed;var s;if(0!==i)if(1===this._iterations)this._time=(t-this._startTime)*this._speed,i>0?this._time>=this._duration?(s=this._time-this._duration,this._time=this._duration):this._time<0:0>i&&this._time<=0&&(s=this._time,this._time=0);else{t=(t-this._startTime)*this._speed;var n=t/this._duration;i>0?n>0&&ni&&(n>0&&n0&&this.duration-this._timei&&this._timei&&(i=t);for(e=this._inactivePlayables.first;null!==e;e=e.next)r=e.object,t=r._getStartTime()+r.getDuration(),t>i&&(i=t);this._setDuration(i)},BriefPlayer.prototype._onPlayableChanged=BriefPlayer.prototype._updateDuration,BriefPlayer.prototype._onPlayableRemoved=BriefPlayer.prototype._updateDuration; -},{"./BriefExtension":2,"./Player":9,"./inherit":22}],5:[function(require,module,exports){ +},{"./BriefExtension":2,"./Player":11,"./inherit":24}],5:[function(require,module,exports){ +module.exports=function(t){for(var p={height:"px",width:"px",top:"px",left:"px",bottom:"px",right:"px",opacity:""},o={},i=0;iw;w+=1)_=_[p[w]];r=p[a],_[r]instanceof Array?(i[h]=null,s[h]=_[r],this._propertyChainStrings.push(h),this._propertyChains[h]=p):(i[n]=[r],s[n]=_,this._propertyChainStrings.push(n),p.pop(),this._propertyChains[n]=p)}else r=h.substring(h.lastIndexOf(".")+1),i[n].push(r)}for(n in s){var f=s[n],l=i[n],u=new AbstractTween(f,l);this._tweens.push(u),this._tweensPerObject[n]=u}}var BriefPlayable=require("./BriefPlayable"),AbstractTween=require("./AbstractTween");NestedTween.prototype=Object.create(BriefPlayable.prototype),NestedTween.prototype.constructor=NestedTween,module.exports=NestedTween,NestedTween.prototype.relative=function(e){for(var t=0;to&&void 0!==i;o+=1)i=i[n[o]];void 0!==i&&this._tweensPerObject[r].interpolations(i)}return this},NestedTween.prototype.from=function(e){for(var t=0;to&&void 0!==i;o+=1)i=i[n[o]];void 0!==i&&this._tweensPerObject[r].from(i)}return this},NestedTween.prototype.to=function(e,t,r,n,s){for(var i=0;i_;_+=1)a=a[h[_]];var w=s;for(_=0;p>_&&void 0!==w;_+=1)w=w[h[_]];this._tweensPerObject[o].to(a,t,r,n,w)}return this._extendDuration(t),this},NestedTween.prototype.wait=function(e){for(var t=0;tt?void console.warn("[Playable.speed] This playable cannot have negative speed"):(0===t?0!==this._speed&&(this._startTime+=this._time/this._speed-this._time):0===this._speed?this._startTime+=this._time-this._time/t:this._startTime+=this._time/this._speed-this._time/t,this._speed=t,void(null!==this._player&&this._player._onPlayableChanged(this)))},Playable.prototype.goTo=function(t,e){return 1===this._iterations?0===this._speed?this._startTime+=this._time-t:this._startTime+=(this._time-t)/this._speed:(e=e||0,0===this._speed?this._startTime+=this._time-t-e*this._duration:this._startTime+=(this._time-t-e*this._duration)/this._speed),this._time=t,null!==this._player&&this._player._onPlayableChanged(this),this},Playable.prototype.goToBeginning=function(){return this.goTo(0,0)},Playable.prototype.getDuration=function(){return 1/0},Playable.prototype._getEndTime=function(){return 1/0},Playable.prototype._setStartTime=function(t){this._startTime=t},Playable.prototype._getStartTime=function(){return this._startTime},Playable.prototype._isWithin=function(t){return this._startTimet?void console.warn("[Playable.speed] This playable cannot have negative speed"):(0===t?0!==this._speed&&(this._startTime+=this._time/this._speed-this._time):0===this._speed?this._startTime+=this._time-this._time/t:this._startTime+=this._time/this._speed-this._time/t,this._speed=t,void(null!==this._player&&this._player._onPlayableChanged(this)))},Playable.prototype.goTo=function(t,e){return 1===this._iterations?0===this._speed?this._startTime+=this._time-t:this._startTime+=(this._time-t)/this._speed:(e=e||0,0===this._speed?this._startTime+=this._time-t-e*this._duration:this._startTime+=(this._time-t-e*this._duration)/this._speed),this._time=t,null!==this._player&&this._player._onPlayableChanged(this),this},Playable.prototype.goToBeginning=function(){return this.goTo(0,0)},Playable.prototype.getDuration=function(){return 1/0},Playable.prototype._getEndTime=function(){return 1/0},Playable.prototype._setStartTime=function(t){this._startTime=t},Playable.prototype._getStartTime=function(){return this._startTime},Playable.prototype._isWithin=function(t){return this._startTime0;){var e=this._playablesToRemove.pop(),a=e.object;a._handle=this._activePlayables.removeByReference(e)}0===this._activePlayables.length&&0===this._inactivePlayables.length&&this._onAllPlayablesRemoved()},Player.prototype.clear=function(){return this._activePlayables.clear(),this._inactivePlayables.clear(),this._playablesToRemove.clear(),this._controls.clear(),this},Player.prototype._warn=function(e){this._silent===!1&&console.warn(e),this._debug===!0},Player.prototype.silent=function(e){return this._silent=e||!1,this},Player.prototype.debug=function(e){return this._debug=e||!1,this},Player.prototype.stop=function(){for(var e=this._activePlayables.first;null!==e;){var a=e.next,t=e.object;t.stop(),e=a}this._handlePlayablesToRemove(),Playable.prototype.stop.call(this)},Player.prototype._activate=function(e){this._inactivePlayables.removeByReference(e._handle),e._handle=this._activePlayables.addBack(e)},Player.prototype._inactivate=function(e){return null===e._handle?void this._warn("[Playable.stop] Cannot stop a playable that is not running"):(this._activePlayables.removeByReference(e._handle),void(e._handle=this._inactivePlayables.addBack(e)))},Player.prototype._updatePlayableList=function(e){this._handlePlayablesToRemove();var a,t;e>0?(a=this._time-e,t=this._time):(a=this._time,t=this._time-e);for(var l=this._inactivePlayables.first;null!==l;){var i=l.object;l=l.next,i._overlaps(a,t)&&(this._activate(i),i._start())}},Player.prototype._update=function(e,a){this._updatePlayableList(e);for(var t=this._activePlayables.first;null!==t;t=t.next)void 0===a?t.object._moveTo(this._time,e):t.object._moveTo(this._time,e,a)},Player.prototype._onPlayableChanged=function(){},Player.prototype._onPlayableRemoved=function(){},Player.prototype._onAllPlayablesRemoved=function(){}; -},{"./DoublyList":6,"./Playable":8}],10:[function(require,module,exports){ +},{"./DoublyList":8,"./Playable":10}],12:[function(require,module,exports){ function Record(t,e){this.time=t,this.values=e}function ObjectRecorder(t,e,r,i){this.object=t,this.properties=e,this.records=new DoublyList,this.currentRecord=null,this.isIn=!1,this.onIn=r||null,this.onOut=i||null}function Recorder(t){return this instanceof Recorder==!1?new Recorder:(BriefPlayable.call(this),this._duration=1/0,this._slackTime=0,this._maxRecordingDuration=t||1/0,this._recordedObjects=[],this._recordingObjects={},this._recordingObjectLabels=[],this._recording=!0,this._playing=!1,this._smooth=!1,this._onStartRecording=null,this._onStopRecording=null,this._onStartPlaying=null,void(this._onStopPlaying=null))}var BriefPlayable=require("./BriefPlayable"),DoublyList=require("./DoublyList");ObjectRecorder.prototype.erase=function(t,e){if(t>e){var r=t;t=e,e=r}var i=this.records.last;if(i.object.time<=e){for(;null!==i&&i.object.time>=t;){var o=i.previous;this.records.removeBeReference(i),i=o}return void(null===this.currentRecord.container&&(this.currentRecord=i))}for(var n=this.records.first;null!==n&&n.object.time<=e;){var s=n.next;n.object.time>=t&&this.records.removeBeReference(n),n=s}null===this.currentRecord.container&&(this.currentRecord=n)},ObjectRecorder.prototype.record=function(t,e){if(0!==e||null===this.currentRecord||this.currentRecord.time!==t){for(var r=[],i=0;il;l+=1)this.object[this.properties[l]]=_[l]*b+g[l]*j}else{var y=this.currentRecord.object.values;for(l=0;n>l;l+=1)this.object[this.properties[l]]=y[l]}o===!1&&null!==this.onOut&&this.onOut()},Recorder.prototype=Object.create(BriefPlayable.prototype),Recorder.prototype.constructor=Recorder,module.exports=Recorder,Recorder.prototype.getDuration=function(){var t;return t=this._playing===!0?this._time>this._maxRecordingDuration?this._maxRecordingDuration:this._time:1/0,t*this._iterations/this._speed},Recorder.prototype.smooth=function(t){return this._smooth=t,this},Recorder.prototype.onStartRecording=function(t){return this._onStartRecording=t,this},Recorder.prototype.onStopRecording=function(t){return this._onStopRecording=t,this},Recorder.prototype.onStartPlaying=function(t){return this._onStartPlaying=t,this},Recorder.prototype.onStopPlaying=function(t){return this._onStopPlaying=t,this},Recorder.prototype.reset=function(){return this._recordedObjects=[],this._recordingObjects={},this._recordingObjectLabels=[],this},Recorder.prototype.record=function(t,e,r,i,o){var n=new ObjectRecorder(e,r,i,o);return this._recordingObjects[t]=n,this._recordedObjects.push(n),this._recordingObjectLabels.push(t),this},Recorder.prototype.stopRecordingObject=function(t){delete this._recordingObjects[t];var e=this._recordingObjectLabels.indexOf(t);return-1===e?(console.warn("[Recorder.stopRecordingObject] Trying to stop recording an object that is not being recording:",t),this):(this._recordingObjectLabels.splice(e,1),this)},Recorder.prototype.removeRecordedObject=function(t){var e=this._recordingObjects[t];delete this._recordingObjects[t];var r=this._recordingObjectLabels.indexOf(t);-1!==r&&this._recordingObjectLabels.splice(r,1);var i=this._recordedObjects.indexOf(e);return-1===i?(console.warn("[Recorder.removeRecordedObject] Trying to remove an object that was not recorded:",t),this):(this._recordingObjectLabels.splice(i,1),this)},Recorder.prototype.recording=function(t){return this._recording!==t&&(this._recording=t,this._recording===!0?(this._playing===!0&&(null!==this._onStopPlaying&&this._onStopPlaying(),this._playing=!1),this._duration=1/0,null!==this._player&&this._player._onPlayableChanged(this),null!==this._onStartRecording&&this._onStartRecording()):null!==this._onStopRecording&&this._onStopRecording()),this},Recorder.prototype.playing=function(t){return this._playing!==t&&(this._playing=t,this._playing===!0?(this._recording===!0&&(null!==this._onStopRecording&&this._onStopRecording(),this._recording=!1),this._duration=this._time,this.goToBeginning(this._startTime+this.getDuration()),null!==this._onStartPlaying&&this._onStartPlaying()):null!==this._onStopPlaying&&this._onStopPlaying()),this},Recorder.prototype._update=function(t){var e,r=this._slackTime+this._time;if(this._recording===!0){var i,o;t>0?(i=this._time-this._maxRecordingDuration,o=i>0):(i=this._time,o=0>i);var n=this._recordingObjectLabels.length;for(e=0;n>e;e+=1){var s=this._recordingObjectLabels[e],c=this._recordingObjects[s];c.record(r,t),o===!0&&c.erase(0,i)}i>0&&(this._slackTime+=i,this._setStartTime(this._startTime+i),this._player._onPlayableChanged(this))}else if(this._playing===!0){var h=this._recordedObjects.length;for(e=0;h>e;e+=1)this._recordedObjects[e].play(r,t,this._smooth)}}; -},{"./BriefPlayable":3,"./DoublyList":6}],11:[function(require,module,exports){ +},{"./BriefPlayable":3,"./DoublyList":8}],13:[function(require,module,exports){ function Sequence(){return this instanceof Sequence==!1?new Sequence:(this._sequencedPlayables=new DoublyList,void Timeline.call(this))}var Timeline=require("./Timeline"),Delay=require("./Delay"),DoublyList=require("./DoublyList");Sequence.prototype=Object.create(Timeline.prototype),Sequence.prototype.constructor=Sequence,module.exports=Sequence,Sequence.prototype.add=function(e){return this._sequencedPlayables.addBack(e),Timeline.prototype.add.call(this,e,this._duration)},Sequence.prototype.addDelay=function(e){return this.add(new Delay(e))},Sequence.prototype._reconstruct=function(){var e,t,n=this._activePlayables.first;null!==n&&(e=n.object,t=this._time-e._getStartTime());for(var i=0,s=this._sequencedPlayables.first;null!==s;s=s.next){var a=s.object;a._setStartTime(i),i=a._getEndTime()}if(null!==n){var r=(this._getStartTime(),this._time-e._getStartTime()),u=t-r;this._startTime+=u}this._duration=i,null!==this._player&&this._player._onPlayableChanged(this)},Sequence.prototype.substitute=function(e,t){if(0===this._sequencedPlayables.length)return void this._warn("[Sequence.substitute] The sequence is empty!");var n=this._sequencedPlayables.getNode(e);this._sequencedPlayables.addAfter(n,t),this._add(t),this.remove(e)},Sequence.prototype._onPlayableRemoved=function(e){this._sequencedPlayables.remove(e),0!==this._sequencedPlayables.length&&this._reconstruct()},Sequence.prototype._onPlayableChanged=Sequence.prototype._reconstruct; -},{"./Delay":5,"./DoublyList":6,"./Timeline":14}],12:[function(require,module,exports){ +},{"./Delay":7,"./DoublyList":8,"./Timeline":16}],14:[function(require,module,exports){ (function (global){ var DoublyList=require("./DoublyList"),root;"undefined"!=typeof window?root=window:"undefined"!=typeof global?root=global:(console.warn("[TINA] Your environment might not support TINA."),root=this);var requestAnimFrame=function(){return root.requestAnimationFrame||root.webkitRequestAnimationFrame||root.mozRequestAnimationFrame||root.oRequestAnimationFrame||root.msRequestAnimationFrame||function(e){root.setTimeout(e,1e3/60)}}(),clock=root.performance||Date,TINA={_activeTweeners:new DoublyList,_inactiveTweeners:new DoublyList,_tweenersToRemove:new DoublyList,_defaultTweener:null,_startTime:0,_time:0,_running:!1,_onStart:null,_onPause:null,_onResume:null,_onUpdate:null,_onStop:null,_pauseOnLostFocus:!1,_pauseOnLostFocusInitialised:!1,onStart:function(e){return this._onStart=e,this},onUpdate:function(e){return this._onUpdate=e,this},onStop:function(e){return this._onStop=e,this},onPause:function(e){return this._onPause=e,this},isRunning:function(){return this._running===!0},update:function(){var e=clock.now()-this._startTime,t=e-this._time;for(0>t?(t=1,this._startTime-=1,this._time+=1):this._time=e;this._tweenersToRemove.length>0;){var n=this._tweenersToRemove.pop();n._handle=this._activeTweeners.removeByReference(n._handle)}for(;this._inactiveTweeners.length>0;){var i=this._inactiveTweeners.pop();i._handle=this._activeTweeners.addBack(i),i._start()}for(var s=this._activeTweeners.first;null!==s;s=s.next)s.object._moveTo(this._time,t);null!==this._onUpdate&&this._onUpdate(this._time,t)},reset:function(){var e=clock.now(),t=e-this._time;this._startTime+=t,this._time=0},start:function(){if(this._startAutomaticUpdate()!==!1){for(null!==this._onStart&&this._onStart();this._inactiveTweeners.length>0;){var e=this._inactiveTweeners.first;this._activate(e.object)}return this}},stop:function(){if(this._stopAutomaticUpdate()!==!1){for(;this._activePlayables.length>0;){var e=this._activePlayables.first;e.object.stop()}return null!==this._onStop&&this._onStop(),this}},_startAutomaticUpdate:function(){function e(){TINA._running===!0&&(TINA.update(),requestAnimFrame(e))}return this._running===!0?(console.warn("[TINA.start] TINA is already running"),!1):(this.reset(),this._running=!0,requestAnimFrame(e),!0)},_stopAutomaticUpdate:function(){return this._running===!1?(console.warn("[TINA.pause] TINA is not running"),!1):(this._running=!1,!0)},pause:function(){if(this._stopAutomaticUpdate()!==!1){for(var e=this._activeTweeners.first;null!==e;e=e.next)e.object._pause();return null!==this._onPause&&this._onPause(),this}},resume:function(){if(this._startAutomaticUpdate()!==!1){null!==this._onResume&&this._onResume();for(var e=this._activeTweeners.first;null!==e;e=e.next)e.object._resume();return this}},_initialisePauseOnLostFocus:function(){if(this._pauseOnLostFocusInitialised!==!0){if(void 0===document)return void console.warn("[TINA.pauseOnLostFocus] Cannot pause on lost focus because TINA is not running in a webpage (node.js does not allow this functionality)");var e,t;if("undefined"!=typeof document.hidden?(e="hidden",t="visibilitychange"):"undefined"!=typeof document.mozHidden?(e="mozHidden",t="mozvisibilitychange"):"undefined"!=typeof document.msHidden?(e="msHidden",t="msvisibilitychange"):"undefined"!=typeof document.webkitHidden&&(e="webkitHidden",t="webkitvisibilitychange"),"undefined"==typeof document[e])return void console.warn("[Tweener] Cannot pause on lost focus because the browser does not support the Page Visibility API");this._pauseOnLostFocusInitialised=!0;var n=!1;document.addEventListener(t,function(){document[e]&&(n=TINA.isRunning(),n&&TINA._pauseOnLostFocus&&TINA.pause()),document[e]||n&&TINA._pauseOnLostFocus&&TINA.resume()},!1)}},pauseOnLostFocus:function(e){return e===!0&&this._pauseOnLostFocusInitialised===!1&&this._initialisePauseOnLostFocus(),this._pauseOnLostFocus=e,this},_add:function(e){return this._running===!1&&this.start(),null===e._handle?(e._handle=this._inactiveTweeners.add(e),void(e._player=this)):e._handle.container===this._tweenersToRemove?void(e._handle=this._tweenersToRemove.removeByReference(e._handle)):void 0},add:function(e){return this._add(e),this},_inactivate:function(e){null!==e._handle&&this._activePlayables.removeByReference(e._handle),e._handle=this._inactivePlayables.addBack(e)},_remove:function(e){return null!==e._handle?e._handle.container===this._activeTweeners?void(e._handle=this._tweenersToRemove.add(e._handle)):e._handle.container===this._inactiveTweeners?void(e._handle=this._inactiveTweeners.removeByReference(e._handle)):void 0:void 0},remove:function(e){return this._remove(e),this},setDefaultTweener:function(e){return this._defaultTweener=e,this},getDefaultTweener:function(){if(null===this._defaultTweener){var e=this.Timer;this._defaultTweener=new e}return this._defaultTweener},_startDefaultTweener:function(){var e=this.getDefaultTweener();return this._add(e),e}};module.exports=root.TINA=TINA; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./DoublyList":6}],13:[function(require,module,exports){ +},{"./DoublyList":8}],15:[function(require,module,exports){ function Ticker(t){return this instanceof Ticker==!1?new Ticker(t):(Tweener.call(this),void(this.tupt=t||1))}var Tweener=require("./Tweener");Ticker.prototype=Object.create(Tweener.prototype),Ticker.prototype.constructor=Ticker,module.exports=Ticker,Ticker.prototype._moveTo=function(t,e){this._time+=this.tupt,e=this.tupt,this._update(e),null!==this._onUpdate&&this._onUpdate(this._time,e)},Ticker.prototype.convertToTicks=function(t){return t/this.tupt},Ticker.prototype.convertToTimeUnits=function(t){return t*this.tupt}; -},{"./Tweener":19}],14:[function(require,module,exports){ -function Timeline(){return this instanceof Timeline==!1?new Timeline:void BriefPlayer.call(this)}var BriefPlayer=require("./BriefPlayer");Timeline.prototype=Object.create(BriefPlayer.prototype),Timeline.prototype.constructor=Timeline,module.exports=Timeline,Timeline.prototype.add=function(e,i){(null===i||void 0===i)&&(i=0),e._setStartTime(i),this._add(e);var t=e._getEndTime();return t>this._duration&&this._setDuration(t),this}; +},{"./Tweener":21}],16:[function(require,module,exports){ +function Timeline(){return this instanceof Timeline==!1?new Timeline:void BriefPlayer.call(this)}var BriefPlayer=require("./BriefPlayer");Timeline.prototype=Object.create(BriefPlayer.prototype),Timeline.prototype.constructor=Timeline,module.exports=Timeline,Timeline.prototype.add=function(e,i){null!==i&&void 0!==i||(i=0),e._setStartTime(i),this._add(e);var t=e._getEndTime();return t>this._duration&&this._setDuration(t),this}; -},{"./BriefPlayer":4}],15:[function(require,module,exports){ +},{"./BriefPlayer":4}],17:[function(require,module,exports){ function Timer(e){return this instanceof Timer==!1?new Timer(e):(Tweener.call(this),void(this._speed=e/1e3||1))}var Tweener=require("./Tweener");Timer.prototype=Object.create(Tweener.prototype),Timer.prototype.constructor=Timer,module.exports=Timer,Object.defineProperty(Timer.prototype,"tups",{get:function(){return 1e3*this._speed},set:function(e){this.speed=e/1e3}}),Timer.prototype.convertToSeconds=function(e){return e/(1e3*this._speed)},Timer.prototype.convertToTimeUnits=function(e){return e*this._speed*1e3}; -},{"./Tweener":19}],16:[function(require,module,exports){ -function update(t,i){var s=this.prop;t[s]=this.from[s]*(1-i)+this.to[s]*i}function updateP(t,i){for(var s=this.props,a=0;at?2*t*t:2*(2*t-t*t)-1},exports.cubicIn=function(t){return t*t*t},exports.cubicOut=function(t){return 3*t-3*t*t+t*t*t},exports.cubicInOut=function(t){return.5>t?4*t*t*t:4*(3*t-3*t*t+t*t*t)-3},exports.quarticIn=function(t){return t*t*t*t},exports.quarticOut=function(t){var n=t*t;return 4*t-6*n+4*n*t-n*n},exports.quarticInOut=function(t){if(.5>t)return 8*t*t*t*t;var n=t*t;return 8*(4*t-6*n+4*n*t-n*n)-7},exports.polyIn=function(t,n){return Math.pow(t,n)},exports.polyOut=function(t,n){return 1-Math.pow(1-t,n)},exports.polyInOut=function(t,n){return.5>t?Math.pow(2*t,n)/2:(2-Math.pow(2*(1-t),n))/2},exports.sineIn=function(t){return 1-Math.cos(PI_OVER_TWO*t)},exports.sineOut=function(t){return Math.sin(PI_OVER_TWO*t)},exports.sineInOut=function(t){return.5>t?(1-Math.cos(PI*t))/2:(1+Math.sin(PI*(t-.5)))/2},exports.expIn=function(t,n){return(1-Math.pow(EXP,n*t))/(1-Math.pow(EXP,n))},exports.expOut=function(t,n){return(1-Math.pow(EXP,-n*t))/(1-Math.pow(EXP,-n))},exports.expInOut=function(t,n){return.5>t?(1-Math.pow(EXP,2*n*t))/(1-Math.pow(EXP,n))/2:.5+(1-Math.pow(EXP,n-2*n*t))/(1-Math.pow(EXP,-n))/2},exports.circIn=function(t){return 1-Math.sqrt(1-Math.pow(t,2))},exports.circOut=function(t){return Math.sqrt(1-Math.pow(1-t,2))},exports.circInOut=function(t){return.5>t?(1-Math.sqrt(1-4*t*t))/2:(1+Math.sqrt(-3+8*t-4*t*t))/2},exports.elasticIn=function(t,n){if(0===t)return 0;n/=n+1;var r=(1+n)*Math.log(t)/Math.log(n);return Math.cos(r)*Math.pow(n,r)},exports.elasticOut=function(t,n){if(1===t)return 1;n/=n+1;var r=(1+n)*Math.log(1-t)/Math.log(n);return 1-Math.cos(r)*Math.pow(n,r)},exports.elasticInOut=function(t,n){var r;return.5>t?0===t?0:(n/=n+1,r=(1+n)*Math.log(2*t)/Math.log(n),.5*Math.cos(r)*Math.pow(n,r)):1===t?1:(n/=n+1,r=(1+n)*Math.log(2-2*t)/Math.log(n),.5+.5*(1-Math.cos(r)*Math.pow(n,r)))},exports.bounceIn=function(t,n){if(0===t)return 0;n/=n+1;var r=(1+n)*Math.log(t)/Math.log(n);return Math.abs(Math.cos(r)*Math.pow(n,r))},exports.bounceOut=function(t,n){if(1===t)return 1;n/=n+1;var r=(1+n)*Math.log(1-t)/Math.log(n);return 1-Math.abs(Math.cos(r)*Math.pow(n,r))},exports.bounceInOut=function(t,n){var r;return.5>t?0===t?0:(n/=n+1,r=(1+n)*Math.log(2*t)/Math.log(n),Math.abs(.5*Math.cos(r)*Math.pow(n,r))):1===t?1:(n/=n+1,r=(1+n)*Math.log(2-2*t)/Math.log(n),.5+.5*(1-Math.abs(Math.cos(r)*Math.pow(n,r))))},exports.backIn=function(t,n){return t*t*((n+1)*t-n)},exports.backOut=function(t,n){return t-=1,t*t*((n+1)*t+n)+1},exports.backInOut=function(t,n){return.5>t?(t*=2,.5*(t*t*((n+1)*t-n))):(t=2*t-2,.5*(t*t*((n+1)*t+n))+1)}; -},{}],21:[function(require,module,exports){ -var TINA=require("./TINA.js");TINA.Delay=require("./Delay"),TINA.BriefExtension=require("./BriefExtension"),TINA.BriefPlayable=require("./BriefPlayable"),TINA.BriefPlayer=require("./BriefPlayer"),TINA.easing=require("./easing"),TINA.interpolation=require("./interpolation"),TINA.NestedTween=require("./NestedTween"),TINA.PixiTween=require("./NestedTween"),TINA.Playable=require("./Playable"),TINA.Player=require("./Player"),TINA.Recorder=require("./Recorder"),TINA.Sequence=require("./Sequence"),TINA.Ticker=require("./Ticker"),TINA.Timeline=require("./Timeline"),TINA.Timer=require("./Timer"),TINA.Tween=require("./Tween"),TINA.Tweener=require("./Tweener"),module.exports=TINA; -},{"./BriefExtension":2,"./BriefPlayable":3,"./BriefPlayer":4,"./Delay":5,"./NestedTween":7,"./Playable":8,"./Player":9,"./Recorder":10,"./Sequence":11,"./TINA.js":12,"./Ticker":13,"./Timeline":14,"./Timer":15,"./Tween":18,"./Tweener":19,"./easing":20,"./interpolation":23}],22:[function(require,module,exports){ +},{}],23:[function(require,module,exports){ +var TINA=require("./TINA.js");TINA.CSSTween=require("./CSSTween"),TINA.Delay=require("./Delay"),TINA.BriefExtension=require("./BriefExtension"),TINA.BriefPlayable=require("./BriefPlayable"),TINA.BriefPlayer=require("./BriefPlayer"),TINA.easing=require("./easing"),TINA.interpolation=require("./interpolation"),TINA.NestedTween=require("./NestedTween"),TINA.PixiTween=require("./NestedTween"),TINA.Playable=require("./Playable"),TINA.Player=require("./Player"),TINA.Recorder=require("./Recorder"),TINA.Sequence=require("./Sequence"),TINA.Ticker=require("./Ticker"),TINA.Timeline=require("./Timeline"),TINA.Timer=require("./Timer"),TINA.Tween=require("./Tween"),TINA.Tweener=require("./Tweener"),module.exports=TINA; +},{"./BriefExtension":2,"./BriefPlayable":3,"./BriefPlayer":4,"./CSSTween":6,"./Delay":7,"./NestedTween":9,"./Playable":10,"./Player":11,"./Recorder":12,"./Sequence":13,"./TINA.js":14,"./Ticker":15,"./Timeline":16,"./Timer":17,"./Tween":20,"./Tweener":21,"./easing":22,"./interpolation":25}],24:[function(require,module,exports){ module.exports=function(o,t){for(var e=Object.keys(t.prototype),p=0;pa?t:a>=e-1?o:n[a-1]},exports.colorRGB=function(r,t,o){return{r:t.r*(1-r)+o.r*r,g:t.g*(1-r)+o.g*r,b:t.b*(1-r)+o.b*r}},exports.colorRGBA=function(r,t,o){return{r:t.r*(1-r)+o.r*r,g:t.g*(1-r)+o.g*r,b:t.b*(1-r)+o.b*r,a:t.a*(1-r)+o.a*r}},exports.colorRGBToHexa=function(r,t,o){var n=Math.round(t.r*(1-r)+o.r*r),e=Math.round(t.g*(1-r)+o.g*r),a=Math.round(t.b*(1-r)+o.b*r);return"#"+n.toString(16)+e.toString(16)+a.toString(16)},exports.colorRGBToString=function(r,t,o){var n=Math.round(t.r*(1-r)+o.r*r),e=Math.round(t.g*(1-r)+o.g*r),a=Math.round(t.b*(1-r)+o.b*r);return"rgb("+n.toString(16)+","+e.toString(16)+","+a.toString(16)+")"},exports.colorRGBAToString=function(r,t,o){var n=Math.round(t.r*(1-r)+o.r*r),e=Math.round(t.g*(1-r)+o.g*r),a=Math.round(t.b*(1-r)+o.b*r),u=Math.round(t.a*(1-r)+o.a*r);return"rgba("+n.toString(16)+","+e.toString(16)+","+a.toString(16)+","+u+")"},exports.string=function(r,t,o){for(var n=t.length,e=o.length,a="",u=0;e>u;u+=1){var i=o.charCodeAt(u),f=u>=n?97>i?65:97:t.charCodeAt(u),c=Math.round(f*(1-r)+i*r);a+=String.fromCharCode(c)}return a},exports.bezierQuadratic=function(r,t,o,n){var e=1-r;return e*e*t+r*(2*e*n[0]+r*o)},exports.bezierCubic=function(r,t,o,n){var e=1-r;return e*e*e*t+r*(3*e*e*n[0]+r*(3*e*n[1]+r*o))},exports.bezierQuartic=function(r,t,o,n){var e=1-r,a=2*e;return a*a*t+r*(4*e*a*n[0]+r*(6*a*n[1]+r*(4*e*n[2]+r*o)))},exports.bezierQuintic=function(r,t,o,n){var e=1-r,a=2*e;return a*a*e*t+r*(5*a*a*n[0]+r*(10*e*a*n[1]+r*(10*a*n[2]+r*(5*e*n[3]+r*o))))},exports.bezier=function(r,t,o,n){var e=n.length,a=1-r,u=o,i=e;for(k=1;kg;g-=1)e=h*Math.pow(i,g),a=n[u-g],f=f*r+e*a[0],c=c*r+e*a[1],h*=(u-g)/(g+1);return e=Math.pow(i,u),[f*r+t[0]*e,c*r+t[1]*e]},exports.bezier3d=function(r,t,o,n){for(var e,a,u=n.length,i=1-r,f=o[0],c=o[1],h=o[2],g=u,x=1;u>x;x-=1)e=g*Math.pow(i,x),a=n[u-x],f=f*r+e*a[0],c=c*r+e*a[1],h=h*r+e*a[2],g*=(u-x)/(x+1);return e=Math.pow(i,u),[f*r+t[0]*e,c*r+t[1]*e,h*r+t[2]*e]},exports.bezierKd=function(r,t,o,n){for(var e=n.length,a=1-r,u=t.length,i=[],f=0;u>f;f+=1)i[f]=o[f];for(var c,h,g=e,x=1;e>x;x-=1){for(c=g*Math.pow(a,x),h=n[e-x],f=0;u>f;f+=1)i[f]=i[f]*r+c*h[f];g*=(e-x)/(x+1)}for(c=Math.pow(a,e),f=0;u>f;f+=1)i[f]=i[f]*r+t[f]*c;return i},exports.catmullRom=function(r,t,o,n){if(1===r)return n;var e=t.length,a=o.length+1;r*=a;var u=Math.floor(r);r-=u;for(var i=r*r,f=r*i,c=-.5*f+1*i-.5*r,h=1.5*f-2.5*i+1,g=-1.5*f+2*i+.5*r,x=.5*f-.5*i,p=u-2,v=u-1,s=u,l=u+1,M=0>p?t:o[p],b=0>v?t:o[v],d=a-2>l?o[s]:n,S=a-2>l?o[l]:n,y=[],z=0;e>z;z+=1)y[z]=M[z]*c+b[z]*h+d[z]*g+S[z]*x;return y},exports.noise=function(){var r=[182,235,131,26,88,132,100,117,202,176,10,19,83,243,75,52,252,194,32,30,72,15,124,53,236,183,121,103,175,39,253,120,166,33,237,141,99,180,18,143,69,136,173,21,210,189,16,142,190,130,109,186,104,80,62,51,165,25,122,119,42,219,146,61,149,177,54,158,27,170,60,201,159,193,203,58,154,222,78,138,220,41,98,14,156,31,29,246,81,181,40,161,192,227,35,241,135,150,89,68,134,114,230,123,187,179,67,217,71,218,7,148,228,251,93,8,140,125,73,37,82,28,112,24,174,118,232,137,191,133,147,245,6,172,95,113,185,205,254,116,55,198,57,152,128,233,74,225,34,223,79,111,215,85,200,9,242,12,167,44,20,110,107,126,86,231,234,76,207,102,214,238,221,145,213,64,197,38,168,157,87,92,255,212,49,196,240,90,63,0,77,94,1,108,91,17,224,188,153,250,249,199,127,59,46,184,36,43,209,206,248,4,56,47,226,13,144,22,11,247,70,244,48,97,151,195,96,101,45,66,239,178,171,160,84,65,23,3,211,162,163,50,105,129,155,169,115,5,106,2,208,204,139,229,164,216,182],t=[-1,1];return function(o,n,e,a){for(var u=2,i=a.per||1,f=a.frq||2,c=a.oct||4,h=a.off||0,g=0,x=a.x+h,p=0;c>p;p+=1){var v=255&(x|x),s=x-(x|x),l=1-s;g+=u*(l*l*s*(3-2*l)*t[1&r[v]]-s*s*l*(3-2*s)*t[1&r[v+1]]),x*=(x-h)*f+h,u*=i}var M=1===i?1/c:.5*(1-i)/(1-Math.pow(i,c));return o+=g*M,n*(1-o)+e*o}}(),exports.simplex2d=function(){function r(r,t,o){return r[0]*t+r[1]*o}var t=[182,235,131,26,88,132,100,117,202,176,10,19,83,243,75,52,252,194,32,30,72,15,124,53,236,183,121,103,175,39,253,120,166,33,237,141,99,180,18,143,69,136,173,21,210,189,16,142,190,130,109,186,104,80,62,51,165,25,122,119,42,219,146,61,149,177,54,158,27,170,60,201,159,193,203,58,154,222,78,138,220,41,98,14,156,31,29,246,81,181,40,161,192,227,35,241,135,150,89,68,134,114,230,123,187,179,67,217,71,218,7,148,228,251,93,8,140,125,73,37,82,28,112,24,174,118,232,137,191,133,147,245,6,172,95,113,185,205,254,116,55,198,57,152,128,233,74,225,34,223,79,111,215,85,200,9,242,12,167,44,20,110,107,126,86,231,234,76,207,102,214,238,221,145,213,64,197,38,168,157,87,92,255,212,49,196,240,90,63,0,77,94,1,108,91,17,224,188,153,250,249,199,127,59,46,184,36,43,209,206,248,4,56,47,226,13,144,22,11,247,70,244,48,97,151,195,96,101,45,66,239,178,171,160,84,65,23,3,211,162,163,50,105,129,155,169,115,5,106,2,208,204,139,229,164,216,182,235,131,26,88,132,100,117,202,176,10,19,83,243,75,52,252,194,32,30,72,15,124,53,236,183,121,103,175,39,253,120,166,33,237,141,99,180,18,143,69,136,173,21,210,189,16,142,190,130,109,186,104,80,62,51,165,25,122,119,42,219,146,61,149,177,54,158,27,170,60,201,159,193,203,58,154,222,78,138,220,41,98,14,156,31,29,246,81,181,40,161,192,227,35,241,135,150,89,68,134,114,230,123,187,179,67,217,71,218,7,148,228,251,93,8,140,125,73,37,82,28,112,24,174,118,232,137,191,133,147,245,6,172,95,113,185,205,254,116,55,198,57,152,128,233,74,225,34,223,79,111,215,85,200,9,242,12,167,44,20,110,107,126,86,231,234,76,207,102,214,238,221,145,213,64,197,38,168,157,87,92,255,212,49,196,240,90,63,0,77,94,1,108,91,17,224,188,153,250,249,199,127,59,46,184,36,43,209,206,248,4,56,47,226,13,144,22,11,247,70,244,48,97,151,195,96,101,45,66,239,178,171,160,84,65,23,3,211,162,163,50,105,129,155,169,115,5,106,2,208,204,139,229,164,216],o=[[1,1],[-1,1],[1,-1],[-1,-1],[1,0],[-1,0],[1,0],[-1,0],[0,1],[0,-1],[0,1],[0,-1],[1,1],[-1,1],[1,-1],[-1,-1]];return function(n,e,a,u){for(var i=2,f=u.per||1,c=u.frq||2,h=u.oct||4,g=u.off||{x:0,y:0},x=x,p=u.x+g.x,v=u.y+g.y,s=0;h>s;s+=1){var l,M,b,d=.5*(Math.sqrt(3)-1),S=(p+v)*d,y=Math.floor(p+S),z=Math.floor(v+S),w=(3-Math.sqrt(3))/6,k=(y+z)*w,R=y-k,B=z-k;R=p-R,B=v-B;var C,G;R>B?(C=1,G=0):(C=0,G=1);var m=R-C+w,q=B-G+w,A=R-1+2*w,Q=B-1+2*w,T=255&y,X=255&z,Y=.5-R*R-B*B,H=.5-m*m-q*q,K=.5-A*A-Q*Q;if(0>Y)l=0;else{var Z=15&t[T+t[X]];Y*=Y,l=Y*Y*r(o[Z],R,B)}if(0>H)M=0;else{var j=15&t[T+C+t[X+G]];H*=H,M=H*H*r(o[j],m,q)}if(0>K)b=0;else{var D=15&t[T+1+t[X+1]];K*=K,b=K*K*r(o[D],A,Q)}x+=70*i*(l+M+b),p*=(p-g.x)*c+g.x,v*=(v-g.y)*c+g.y,i*=f}var E=1===f?1/h:.5*(1-f)/(1-Math.pow(f,h));return n+=x*E,e*(1-n)+a*n}}(); -},{}]},{},[21]); +},{}]},{},[23]); diff --git a/examples/css/index.html b/examples/css/index.html new file mode 100644 index 0000000..d375eb9 --- /dev/null +++ b/examples/css/index.html @@ -0,0 +1,29 @@ + + + + Tina - CSS + + + + + + tina - CSS +
+
+
+ + + + + jsfiddle + + \ No newline at end of file diff --git a/examples/css/index.js b/examples/css/index.js new file mode 100644 index 0000000..e46ca93 --- /dev/null +++ b/examples/css/index.js @@ -0,0 +1,32 @@ + +var demoDiv = document.getElementById('demodiv'); + +//â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„ + +TINA.onUpdate(function update(t, dt) { + // At this point, all my tweens are up to date for the current iteration +}); + +//â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„ + +var duration = 2000; +var bouncing = 4; + +// NOTE: The available CSS properties options are currently: +// top, bottom, left, right, width, height and opacity +var csstween = new TINA.CSSTween(demodiv, ['top', 'width', 'opacity', 'height']) +.from({ + top: 50, + width: 100, + height: 100, + opacity: 1 +}) +.to({ + top: 200, + width: 200, + height: 200, + opacity: 0 +}, 2000) +.iterations(Infinity) +.pingpong(true) +.start(); diff --git a/examples/styles.css b/examples/styles.css index 63d12b7..d5a8bf9 100644 --- a/examples/styles.css +++ b/examples/styles.css @@ -4,6 +4,7 @@ body { font-family: verdana; } +.democontainer, canvas { margin: 20px auto; border-radius: 5px; @@ -11,6 +12,12 @@ canvas { display: block; } +.democontainer { + position: relative; + width: 400px; + height: 400px; +} + a { color: #AAA; } diff --git a/src/AbstractTween.js b/src/AbstractTween.js index c4ffa84..fb33607 100644 --- a/src/AbstractTween.js +++ b/src/AbstractTween.js @@ -1,5 +1,6 @@ var Transition = require('./Transition'); var TransitionRelative = require('./TransitionRelative'); +var CSSMap = require('./CSSMap'); var easingFunctions = require('./easing'); var interpolationFunctions = require('./interpolation'); @@ -44,10 +45,13 @@ function AbstractTween(object, properties) { properties[p] = p; } } - + // Properties to tween this._properties = properties; + // If we are dealing with a CSS style object, detetermine which suffixes to use + this._suffixMap = (object instanceof CSSStyleDeclaration) ? CSSMap(this._properties) : {}; + // Starting property values // By default is a copy of given object property values this._from = null; @@ -165,7 +169,8 @@ AbstractTween.prototype.to = function (toObject, duration, easing, easingParam, easing, easingParam, this._interpolations, - interpolationParams + interpolationParams, + this._suffixMap ); this._transitions.push(transition); diff --git a/src/CSSMap.js b/src/CSSMap.js new file mode 100644 index 0000000..462691c --- /dev/null +++ b/src/CSSMap.js @@ -0,0 +1,27 @@ +/** + * + * Maps the given properties to a unit type + * + * Currently only supports basic CSS methods - in order to support more advance CSS3 properties, such as + * transform, we will need to modify the way the properties array is handled and moved through the system. + * In the case of CSS methods such as "transform: rotate(Xdeg)" - the mapping will need to be more advanced, + * possibly adding a prefix / suffix mapping. + * + * @param {array} properties - Properties of the object to tween + * @returns {array} - The suffix mapped to the property name + * + */ +module.exports = function (properties) { + + var cssMap = { height: 'px', width: 'px', top: 'px', left: 'px', bottom: 'px', right: 'px', opacity: '' }; + var mapping = {}; + + for (var i = 0; i < properties.length; i++) { + if (properties[i] in cssMap) { + var property = properties[i]; + mapping[property] = cssMap[property]; + } + } + + return mapping; +}; \ No newline at end of file diff --git a/src/CSSTween.js b/src/CSSTween.js index db4a41e..88a01af 100644 --- a/src/CSSTween.js +++ b/src/CSSTween.js @@ -1,4 +1,4 @@ -var Tween = require('./Tween'); +var NestedTween = require('./NestedTween'); /** * @@ -17,10 +17,10 @@ function CSSTween(object, properties) { var tweenedObject = (typeof object === 'string') ? document.querySelector(object) : object; - // TODO: change inheritance to NestedTween for support of css transform properties - // and add an internal method for replacing unprefixed properties by prefixed properties when necessary - Tween.call(this, tweenedObject.style, properties); + // DONE: Changed inheritance to NestedTween for support of css transform properties + // TODO: Add an internal method for replacing unprefixed properties by prefixed properties when necessary + NestedTween.call(this, tweenedObject.style, properties); } -CSSTween.prototype = Object.create(Tween.prototype); +CSSTween.prototype = Object.create(NestedTween.prototype); CSSTween.prototype.constructor = CSSTween; module.exports = CSSTween; \ No newline at end of file diff --git a/src/Transition.js b/src/Transition.js index b96c179..db12d11 100644 --- a/src/Transition.js +++ b/src/Transition.js @@ -8,39 +8,71 @@ // One property function update(object, t) { var p = this.prop; - object[p] = this.from[p] * (1 - t) + this.to[p] * t; + + var suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; + if (suffix) { + object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + suffix; + } else { + object[p] = this.from[p] * (1 - t) + this.to[p] * t; + } } // Several Properties function updateP(object, t) { var q = this.props; - for (var i = 0; i < this.props.length; i += 1) { + var suffix = null; + + for (var i = 0; i < this.props.length; i += 1) { var p = q[i]; - object[p] = this.from[p] * (1 - t) + this.to[p] * t; + suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; + if (suffix) { + object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + suffix; + } else { + object[p] = this.from[p] * (1 - t) + this.to[p] * t; + } } } // Interpolation function updateI(object, t) { var p = this.prop; - object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]); + + var suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; + if (suffix) { + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]) + suffix; + } else { + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]); + } } // Interpolation // Several Properties function updatePI(object, t) { var q = this.props; + var suffix = null; + for (var i = 0; i < q.length; i += 1) { var p = q[i]; - object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]); + suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; + if (suffix) { + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]) + suffix; + } else { + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]); + } } } // Easing function updateE(object, t) { t = this.easing(t, this.easingParam); - var p = this.prop; - object[p] = this.from[p] * (1 - t) + this.to[p] * t; + var p = this.prop; + + var suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; + if (suffix) { + object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + suffix; + } else { + object[p] = this.from[p] * (1 - t) + this.to[p] * t; + } } // Easing @@ -48,9 +80,16 @@ function updateE(object, t) { function updatePE(object, t) { var q = this.props; t = this.easing(t, this.easingParam); + var suffix = null; + for (var i = 0; i < q.length; i += 1) { var p = q[i]; - object[p] = this.from[p] * (1 - t) + this.to[p] * t; + suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; + if (suffix) { + object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + suffix; + } else { + object[p] = this.from[p] * (1 - t) + this.to[p] * t; + } } } @@ -58,7 +97,15 @@ function updatePE(object, t) { // Interpolation function updateIE(object, t) { var p = this.prop; - object[p] = this.interps[p](this.easing(t, this.easingParam), this.from[p], this.to[p], this.interpParams[p]); + var suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; + + if (suffix) { + object[p] = this.interps[p](this.easing(t, this.easingParam), + this.from[p], this.to[p], this.interpParams[p]) + suffix; + } else { + object[p] = this.interps[p](this.easing(t, this.easingParam), + this.from[p], this.to[p], this.interpParams[p]); + } } // Easing @@ -66,10 +113,17 @@ function updateIE(object, t) { // Several Properties function updatePIE(object, t) { var q = this.props; + var suffix = null; t = this.easing(t, this.easingParam); + for (var i = 0; i < q.length; i += 1) { var p = q[i]; - object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]); + suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; + if (suffix) { + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]) + suffix; + } else { + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]); + } } } @@ -83,13 +137,14 @@ var updateMethods = [ ] ]; -function Transition(properties, from, to, start, duration, easing, easingParam, interpolations, interpolationParams) { - this.start = start; - this.end = start + duration; - this.duration = duration; - - this.from = from; - this.to = to; +function Transition(properties, from, to, start, duration, easing, + easingParam, interpolations, interpolationParams, suffixMap) { + this.start = start; + this.end = start + duration; + this.duration = duration; + this.suffixMap = suffixMap; + this.from = from; + this.to = to; // Easing flag - Whether an easing function is used // 0 => Using linear easing diff --git a/src/index.js b/src/index.js index d00e31e..ab04630 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,6 @@ var TINA = require('./TINA.js'); -// TINA.CSSTween = require('./CSSTween'); +TINA.CSSTween = require('./CSSTween'); TINA.Delay = require('./Delay'); TINA.BriefExtension = require('./BriefExtension'); TINA.BriefPlayable = require('./BriefPlayable'); From 1dd07c0e1dca56fdc03308dc1f416b5bb8cc1298 Mon Sep 17 00:00:00 2001 From: Cain Martin Date: Wed, 13 Apr 2016 12:00:24 +0900 Subject: [PATCH 02/18] Update AbstractTween.js Fixed formatting --- src/AbstractTween.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/AbstractTween.js b/src/AbstractTween.js index fb33607..8bca2a2 100644 --- a/src/AbstractTween.js +++ b/src/AbstractTween.js @@ -49,8 +49,8 @@ function AbstractTween(object, properties) { // Properties to tween this._properties = properties; - // If we are dealing with a CSS style object, detetermine which suffixes to use - this._suffixMap = (object instanceof CSSStyleDeclaration) ? CSSMap(this._properties) : {}; + // If we are dealing with a CSS style object, detetermine which suffixes to use + this._suffixMap = (object instanceof CSSStyleDeclaration) ? CSSMap(this._properties) : {}; // Starting property values // By default is a copy of given object property values @@ -170,7 +170,7 @@ AbstractTween.prototype.to = function (toObject, duration, easing, easingParam, easingParam, this._interpolations, interpolationParams, - this._suffixMap + this._suffixMap ); this._transitions.push(transition); @@ -225,4 +225,4 @@ AbstractTween.prototype._validate = function () { } return true; -}; \ No newline at end of file +}; From 06bf5ca5d30c82eec77e7a2f831432130ca5bc23 Mon Sep 17 00:00:00 2001 From: Cain Martin Date: Wed, 13 Apr 2016 12:02:20 +0900 Subject: [PATCH 03/18] Update CSSMap.js Fixed formatting --- src/CSSMap.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/CSSMap.js b/src/CSSMap.js index 462691c..cb886e2 100644 --- a/src/CSSMap.js +++ b/src/CSSMap.js @@ -13,15 +13,15 @@ */ module.exports = function (properties) { - var cssMap = { height: 'px', width: 'px', top: 'px', left: 'px', bottom: 'px', right: 'px', opacity: '' }; - var mapping = {}; + var cssMap = { height: 'px', width: 'px', top: 'px', left: 'px', bottom: 'px', right: 'px', opacity: '' }; + var mapping = {}; - for (var i = 0; i < properties.length; i++) { - if (properties[i] in cssMap) { - var property = properties[i]; - mapping[property] = cssMap[property]; + for (var i = 0; i < properties.length; i++) { + if (properties[i] in cssMap) { + var property = properties[i]; + mapping[property] = cssMap[property]; + } } - } - return mapping; -}; \ No newline at end of file + return mapping; +}; From cc56fddadc17fca76f774402d5db267dcde6369e Mon Sep 17 00:00:00 2001 From: Cain Martin Date: Wed, 13 Apr 2016 12:03:58 +0900 Subject: [PATCH 04/18] Update CSSTween.js Fixed formatting --- src/CSSTween.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CSSTween.js b/src/CSSTween.js index 88a01af..79a9f17 100644 --- a/src/CSSTween.js +++ b/src/CSSTween.js @@ -18,9 +18,9 @@ function CSSTween(object, properties) { var tweenedObject = (typeof object === 'string') ? document.querySelector(object) : object; // DONE: Changed inheritance to NestedTween for support of css transform properties - // TODO: Add an internal method for replacing unprefixed properties by prefixed properties when necessary + // TODO: Add an internal method for replacing unprefixed properties by prefixed properties when necessary NestedTween.call(this, tweenedObject.style, properties); } CSSTween.prototype = Object.create(NestedTween.prototype); CSSTween.prototype.constructor = CSSTween; -module.exports = CSSTween; \ No newline at end of file +module.exports = CSSTween; From 759db7cbcc7b5744a0e8acbd4b08d00ceef1d28f Mon Sep 17 00:00:00 2001 From: Cain Martin Date: Wed, 13 Apr 2016 12:08:30 +0900 Subject: [PATCH 05/18] Update Transition.js Fixed formatting --- src/Transition.js | 118 +++++++++++++++++++++++----------------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/src/Transition.js b/src/Transition.js index db12d11..d32c65b 100644 --- a/src/Transition.js +++ b/src/Transition.js @@ -9,27 +9,27 @@ function update(object, t) { var p = this.prop; - var suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; - if (suffix) { - object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + suffix; - } else { - object[p] = this.from[p] * (1 - t) + this.to[p] * t; - } + var suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; + if (suffix) { + object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + suffix; + } else { + object[p] = this.from[p] * (1 - t) + this.to[p] * t; + } } // Several Properties function updateP(object, t) { var q = this.props; - var suffix = null; + var suffix = null; - for (var i = 0; i < this.props.length; i += 1) { + for (var i = 0; i < this.props.length; i += 1) { var p = q[i]; - suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; - if (suffix) { - object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + suffix; - } else { - object[p] = this.from[p] * (1 - t) + this.to[p] * t; - } + suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; + if (suffix) { + object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + suffix; + } else { + object[p] = this.from[p] * (1 - t) + this.to[p] * t; + } } } @@ -37,42 +37,42 @@ function updateP(object, t) { function updateI(object, t) { var p = this.prop; - var suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; - if (suffix) { - object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]) + suffix; - } else { - object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]); - } + var suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; + if (suffix) { + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]) + suffix; + } else { + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]); + } } // Interpolation // Several Properties function updatePI(object, t) { var q = this.props; - var suffix = null; + var suffix = null; for (var i = 0; i < q.length; i += 1) { var p = q[i]; - suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; - if (suffix) { - object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]) + suffix; - } else { - object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]); - } + suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; + if (suffix) { + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]) + suffix; + } else { + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]); + } } } // Easing function updateE(object, t) { t = this.easing(t, this.easingParam); - var p = this.prop; + var p = this.prop; - var suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; - if (suffix) { - object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + suffix; - } else { - object[p] = this.from[p] * (1 - t) + this.to[p] * t; - } + var suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; + if (suffix) { + object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + suffix; + } else { + object[p] = this.from[p] * (1 - t) + this.to[p] * t; + } } // Easing @@ -80,16 +80,16 @@ function updateE(object, t) { function updatePE(object, t) { var q = this.props; t = this.easing(t, this.easingParam); - var suffix = null; + var suffix = null; for (var i = 0; i < q.length; i += 1) { var p = q[i]; - suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; - if (suffix) { - object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + suffix; - } else { - object[p] = this.from[p] * (1 - t) + this.to[p] * t; - } + suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; + if (suffix) { + object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + suffix; + } else { + object[p] = this.from[p] * (1 - t) + this.to[p] * t; + } } } @@ -97,15 +97,15 @@ function updatePE(object, t) { // Interpolation function updateIE(object, t) { var p = this.prop; - var suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; - - if (suffix) { - object[p] = this.interps[p](this.easing(t, this.easingParam), - this.from[p], this.to[p], this.interpParams[p]) + suffix; - } else { - object[p] = this.interps[p](this.easing(t, this.easingParam), - this.from[p], this.to[p], this.interpParams[p]); - } + var suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; + + if (suffix) { + object[p] = this.interps[p](this.easing(t, this.easingParam), + this.from[p], this.to[p], this.interpParams[p]) + suffix; + } else { + object[p] = this.interps[p](this.easing(t, this.easingParam), + this.from[p], this.to[p], this.interpParams[p]); + } } // Easing @@ -113,17 +113,17 @@ function updateIE(object, t) { // Several Properties function updatePIE(object, t) { var q = this.props; - var suffix = null; + var suffix = null; t = this.easing(t, this.easingParam); for (var i = 0; i < q.length; i += 1) { var p = q[i]; - suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; - if (suffix) { - object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]) + suffix; - } else { - object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]); - } + suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; + if (suffix) { + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]) + suffix; + } else { + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]); + } } } @@ -142,7 +142,7 @@ function Transition(properties, from, to, start, duration, easing, this.start = start; this.end = start + duration; this.duration = duration; - this.suffixMap = suffixMap; + this.suffixMap = suffixMap; this.from = from; this.to = to; @@ -187,4 +187,4 @@ function Transition(properties, from, to, start, duration, easing, this.update = updateMethods[easingFlag][interpFlag][propsFlag]; } -module.exports = Transition; \ No newline at end of file +module.exports = Transition; From d388fc38416d552ae48d02e4b5dd18d99c1065f7 Mon Sep 17 00:00:00 2001 From: Cain Martin Date: Wed, 13 Apr 2016 12:12:02 +0900 Subject: [PATCH 06/18] Update index.js Fixed formatting --- examples/css/index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/css/index.js b/examples/css/index.js index e46ca93..3e3706b 100644 --- a/examples/css/index.js +++ b/examples/css/index.js @@ -16,16 +16,16 @@ var bouncing = 4; // top, bottom, left, right, width, height and opacity var csstween = new TINA.CSSTween(demodiv, ['top', 'width', 'opacity', 'height']) .from({ - top: 50, - width: 100, - height: 100, - opacity: 1 + top: 50, + width: 100, + height: 100, + opacity: 1 }) .to({ - top: 200, - width: 200, - height: 200, - opacity: 0 + top: 200, + width: 200, + height: 200, + opacity: 0 }, 2000) .iterations(Infinity) .pingpong(true) From 0e25774a21275849270b805013ec9650f68e60fd Mon Sep 17 00:00:00 2001 From: Cain Martin Date: Wed, 13 Apr 2016 12:13:55 +0900 Subject: [PATCH 07/18] Update index.html Fixed formatting Uncommented the script link to point to the main repository --- examples/css/index.html | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/css/index.html b/examples/css/index.html index d375eb9..9a3a775 100644 --- a/examples/css/index.html +++ b/examples/css/index.html @@ -4,26 +4,26 @@ Tina - CSS - + tina - CSS -
-
-
+
+
+
- - + + --> jsfiddle - \ No newline at end of file + From 19fcce5bff930ef5807103f35f2810606c791783 Mon Sep 17 00:00:00 2001 From: Cain Martin Date: Wed, 13 Apr 2016 12:14:33 +0900 Subject: [PATCH 08/18] Update styles.css Fixed formatting --- examples/styles.css | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/styles.css b/examples/styles.css index d5a8bf9..f27f3d6 100644 --- a/examples/styles.css +++ b/examples/styles.css @@ -13,9 +13,9 @@ canvas { } .democontainer { - position: relative; - width: 400px; - height: 400px; + position: relative; + width: 400px; + height: 400px; } a { @@ -47,4 +47,4 @@ a:active { .hidden { display: none; -} \ No newline at end of file +} From 77b6c198d8f175622d8b06ba6ef5dbdcbea4b961 Mon Sep 17 00:00:00 2001 From: Cain Martin Date: Tue, 10 May 2016 12:52:19 +0900 Subject: [PATCH 09/18] Changed the method by which CSS transitions are determined. There is no longer a per frame check for the CSS Map on non-CSS transitions. Instead, a transition function is selected at the time the transition is created and is passed to the update each frame. While this adds an additional function call - it reduces the memory overhead, and has the advantage of centralising the transition function code. --- build/tina.min.js | 4 +- src/AbstractTween.js | 20 +++--- src/Transition.js | 147 +++++++++++++++++++++---------------------- 3 files changed, 84 insertions(+), 87 deletions(-) diff --git a/build/tina.min.js b/build/tina.min.js index 3ac847b..00e87fa 100644 --- a/build/tina.min.js +++ b/build/tina.min.js @@ -1,5 +1,5 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o0&&(this._transitions[0].from=t),this},AbstractTween.prototype._setFrom=function(){this._from={};for(var t=0;t0?this._relative===!0?this._setFrom():this._transitions[this._transitions.length-1].to:null===this._from?this._setFrom():this._from},AbstractTween.prototype.to=function(t,i,n,s,e){"string"==typeof n&&(void 0===easingFunctions[n]?(console.warn("[AbstractTween.to] Given easing does not exist"),n=void 0):n=easingFunctions[n]);var r=this._getLastTransitionEnding(),o=this._relative===!0?TransitionRelative:Transition,a=new o(this._properties,r,t,this._duration,i,n,s,this._interpolations,e,this._suffixMap);return this._transitions.push(a),this._duration+=i,this},AbstractTween.prototype.wait=function(t){var i=this._getLastTransitionEnding();return this._transitions.push(new Temporisation(this._duration,t,i,this._properties)),this._duration+=t,this},AbstractTween.prototype._update=function(){for(var t=this._transitions[this._index];t.end<=this._time;){if(this._index===this._transitions.length-1)return void t.update(this._object,1);this._relative===!0&&t.update(this._object,1),t=this._transitions[++this._index]}for(;this._time<=t.start;){if(0===this._index)return void t.update(this._object,0);this._relative===!0&&t.update(this._object,0),t=this._transitions[--this._index]}t.update(this._object,(this._time-t.start)/t.duration)},AbstractTween.prototype._validate=function(){return 0===this._transitions.length?(console.warn("[AbstractTween._validate] Cannot start a tween with no transition:",this),!1):!0}; +function Temporisation(t,i,n,s){this.start=t,this.end=t+i,this.duration=i,this.properties=s,this.to=n}function AbstractTween(t,i){if(this._object=t,(null===i||void 0===i)&&t instanceof Array){i=[];for(var n=0;n0&&(this._transitions[0].from=t),this},AbstractTween.prototype._setFrom=function(){this._from={};for(var t=0;t0?this._relative===!0?this._setFrom():this._transitions[this._transitions.length-1].to:null===this._from?this._setFrom():this._from},AbstractTween.prototype.to=function(t,i,n,s,e){"string"==typeof n&&(void 0===easingFunctions[n]?(console.warn("[AbstractTween.to] Given easing does not exist"),n=void 0):n=easingFunctions[n]);var r=this._getLastTransitionEnding(),o=this._relative===!0?TransitionRelative:Transition,a=new o(this._properties,r,t,this._duration,i,n,s,this._interpolations,e,this._cssMap);return this._transitions.push(a),this._duration+=i,this},AbstractTween.prototype.wait=function(t){var i=this._getLastTransitionEnding();return this._transitions.push(new Temporisation(this._duration,t,i,this._properties)),this._duration+=t,this},AbstractTween.prototype._update=function(){for(var t=this._transitions[this._index];t.end<=this._time;){if(this._index===this._transitions.length-1)return void t.update(this._object,1,t.transFunc);this._relative===!0&&t.update(this._object,1,t.transFunc),t=this._transitions[++this._index]}for(;this._time<=t.start;){if(0===this._index)return void t.update(this._object,0,t.transFunc);this._relative===!0&&t.update(this._object,0,t.transFunc),t=this._transitions[--this._index]}t.update(this._object,(this._time-t.start)/t.duration,t.transFunc)},AbstractTween.prototype._validate=function(){return 0===this._transitions.length?(console.warn("[AbstractTween._validate] Cannot start a tween with no transition:",this),!1):!0}; },{"./CSSMap":5,"./Transition":18,"./TransitionRelative":19,"./easing":22,"./interpolation":25}],2:[function(require,module,exports){ function BriefExtension(){this._duration=0,this._onComplete=null,this._iterations=1,this._pingpong=!1,this._persist=!1}module.exports=BriefExtension,BriefExtension.prototype.setSpeed=function(t){0===t?0!==this._speed&&(this._startTime+=this._time/this._speed-this._time):0===this._speed?this._startTime+=this._time-this._time/t:this._startTime+=this._time/this._speed-this._time/t,this._speed=t,null!==this._player&&this._player._onPlayableChanged(this)},BriefExtension.prototype.onComplete=function(t){return this._onComplete=t,this},BriefExtension.prototype.getDuration=function(){return this._duration*this._iterations/this._speed},BriefExtension.prototype._setDuration=function(t){this._duration=t,null!==this._player&&this._player._onPlayableChanged(this)},BriefExtension.prototype._extendDuration=function(t){this._duration+=t,null!==this._player&&this._player._onPlayableChanged(this)},BriefExtension.prototype._getEndTime=function(){return this._speed>0?this._startTime+this.getDuration():this._speed<0?this._startTime:1/0},BriefExtension.prototype._setStartTime=function(t){this._speed>0?this._startTime=t:this._speed<0?this._startTime=t-this.getDuration():this._startTime=1/0},BriefExtension.prototype._getStartTime=function(){return this._speed>0?this._startTime:this._speed<0?this._startTime+this.getDuration():-(1/0)},BriefExtension.prototype._isTimeWithin=function(t){return this._speed>0?this._startTime0?(this._startTime-i)*(this._startTime+this.getDuration()-t)<=0:this._speed<0?(this._startTime+this.getDuration()-i)*(this._startTime-t)<=0:!0},BriefExtension.prototype.goToEnd=function(){return this.goTo(this.getDuration(),this._iterations-1)},BriefExtension.prototype.loop=function(){return this.iterations(1/0)},BriefExtension.prototype.iterations=function(t){return 0>t?(console.warn("[BriefExtension.iterations] Number of iterations cannot be negative"),this):(this._iterations=t,null!==this._player&&this._player._onPlayableChanged(this),this)},BriefExtension.prototype.persist=function(t){return this._persist=t,this},BriefExtension.prototype.pingpong=function(t){return this._pingpong=t,null!==this._player&&this._player._onPlayableChanged(this),this},BriefExtension.prototype._complete=function(t){return this._persist===!0?(this._startTime+=t,void this._player._onPlayableChanged(this)):this._player._inactivate(this)===!1?this:void(null!==this._onComplete&&this._onComplete(t))};var epsilon=1e-6;BriefExtension.prototype._moveTo=function(t,i,e){i*=this._speed;var s;if(0!==i)if(1===this._iterations)this._time=(t-this._startTime)*this._speed,i>0?this._time>=this._duration?(s=this._time-this._duration,this._time=this._duration):this._time<0:0>i&&this._time<=0&&(s=this._time,this._time=0);else{t=(t-this._startTime)*this._speed;var n=t/this._duration;i>0?n>0&&ni&&(n>0&&n0&&this.duration-this._timei&&this._time Using linear easing @@ -185,6 +174,14 @@ function Transition(properties, from, to, start, duration, easing, } this.update = updateMethods[easingFlag][interpFlag][propsFlag]; + // Select the appropriate transition function based on the mappings + this.transFunc = transFunctions[easingFlag][interpFlag][propsFlag]; + + if (cssMap) { + this.transFunc = transFunctionsCSS[easingFlag][interpFlag][propsFlag]; + } else { + this.transFunc = transFunctions[easingFlag][interpFlag][propsFlag]; + } } module.exports = Transition; From 7156fd1e64fe20b65ceeb7db03b030f158761aac Mon Sep 17 00:00:00 2001 From: Cain Martin Date: Tue, 10 May 2016 13:03:09 +0900 Subject: [PATCH 10/18] Fixed bug where some of the interpolation functions still referred to this, instead of the context variable --- src/Transition.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Transition.js b/src/Transition.js index 6026ab1..5914993 100644 --- a/src/Transition.js +++ b/src/Transition.js @@ -15,80 +15,80 @@ function standardTransCSS(context, p, t) { } function interpTrans(context, p, t) { - return this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]); + return context.interps[p](t, context.from[p], context.to[p], context.interpParams[p]); } function interpTransCSS(context, p, t) { - return this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]) + context.cssMap[p]; + return context.interps[p](t, context.from[p], context.to[p], context.interpParams[p]) + context.cssMap[p]; } // One property -function update(object, t, fn) { +function update(object, t, interpFunc) { var p = this.prop; - object[p] = fn(this, p, t); + object[p] = interpFunc(this, p, t); } // Several Properties -function updateP(object, t, fn) { +function updateP(object, t, interpFunc) { var q = this.props; for (var i = 0; i < this.props.length; i += 1) { var p = q[i]; - object[p] = fn(this, p, t); + object[p] = interpFunc(this, p, t); } } // Interpolation -function updateI(object, t, fn) { +function updateI(object, t, interpFunc) { var p = this.prop; - object[p] = fn(context, p, t); + object[p] = interpFunc(this, p, t); } // Interpolation // Several Properties -function updatePI(object, t, fn) { +function updatePI(object, t, interpFunc) { var q = this.props; for (var i = 0; i < q.length; i += 1) { var p = q[i]; - object[p] = fn(context, p, t); + object[p] = interpFunc(this, p, t); } } // Easing -function updateE(object, t, fn) { +function updateE(object, t, interpFunc) { t = this.easing(t, this.easingParam); var p = this.prop; - object[p] = fn(this, p, t); + object[p] = interpFunc(this, p, t); } // Easing // Several Properties -function updatePE(object, t, fn) { +function updatePE(object, t, interpFunc) { var q = this.props; t = this.easing(t, this.easingParam); for (var i = 0; i < q.length; i += 1) { var p = q[i]; - object[p] = fn(this, p, t); + object[p] = interpFunc(this, p, t); } } // Easing // Interpolation -function updateIE(object, t, fn) { +function updateIE(object, t, interpFunc) { var p = this.prop; t = this.easing(t, this.easingParam); - object[p] = fn(this, p, t); + object[p] = interpFunc(this, p, t); } // Easing // Interpolation // Several Properties -function updatePIE(object, t, fn) { +function updatePIE(object, t, interpFunc) { var q = this.props; t = this.easing(t, this.easingParam); for (var i = 0; i < q.length; i += 1) { var p = q[i]; - object[p] = fn(this, p, t); + object[p] = interpFunc(this, p, t); } } From b40500f18257cf879c968d80ca1803156abee12a Mon Sep 17 00:00:00 2001 From: Cain Martin Date: Tue, 10 May 2016 13:07:17 +0900 Subject: [PATCH 11/18] Adding the built versions of tina --- build/tina.js | 195 +++++++++++++++++++++++----------------------- build/tina.min.js | 2 +- 2 files changed, 99 insertions(+), 98 deletions(-) diff --git a/build/tina.js b/build/tina.js index 8161e9e..3b42658 100644 --- a/build/tina.js +++ b/build/tina.js @@ -46,13 +46,13 @@ function AbstractTween(object, properties) { properties[p] = p; } } - + + // Determine if we are are tweening a CSS object + this._cssMap = (object instanceof CSSStyleDeclaration) ? CSSMap(properties) : null; + // Properties to tween this._properties = properties; - // If we are dealing with a CSS style object, detetermine which suffixes to use - this._suffixMap = (object instanceof CSSStyleDeclaration) ? CSSMap(this._properties) : {}; - // Starting property values // By default is a copy of given object property values this._from = null; @@ -171,7 +171,7 @@ AbstractTween.prototype.to = function (toObject, duration, easing, easingParam, easingParam, this._interpolations, interpolationParams, - this._suffixMap + this._cssMap ); this._transitions.push(transition); @@ -191,12 +191,12 @@ AbstractTween.prototype._update = function () { var transition = this._transitions[this._index]; while (transition.end <= this._time) { if (this._index === (this._transitions.length - 1)) { - transition.update(this._object, 1); + transition.update(this._object, 1, transition.transFunc); return; } if (this._relative === true ) { - transition.update(this._object, 1); + transition.update(this._object, 1, transition.transFunc); } transition = this._transitions[++this._index]; @@ -204,19 +204,19 @@ AbstractTween.prototype._update = function () { while (this._time <= transition.start) { if (this._index === 0) { - transition.update(this._object, 0); + transition.update(this._object, 0, transition.transFunc); return; } if (this._relative === true ) { - transition.update(this._object, 0); + transition.update(this._object, 0, transition.transFunc); } transition = this._transitions[--this._index]; } // Updating the object with respect to the current transition and time - transition.update(this._object, (this._time - transition.start) / transition.duration); + transition.update(this._object, (this._time - transition.start) / transition.duration, transition.transFunc); }; AbstractTween.prototype._validate = function () { @@ -226,7 +226,8 @@ AbstractTween.prototype._validate = function () { } return true; -}; +}; + },{"./CSSMap":5,"./Transition":18,"./TransitionRelative":19,"./easing":22,"./interpolation":25}],2:[function(require,module,exports){ function BriefExtension() { @@ -572,18 +573,19 @@ BriefPlayer.prototype._onPlayableRemoved = BriefPlayer.prototype._updateDuration */ module.exports = function (properties) { - var cssMap = { height: 'px', width: 'px', top: 'px', left: 'px', bottom: 'px', right: 'px', opacity: '' }; - var mapping = {}; + var cssMap = { height: 'px', width: 'px', top: 'px', left: 'px', bottom: 'px', right: 'px', opacity: '' }; + var mapping = {}; - for (var i = 0; i < properties.length; i++) { - if (properties[i] in cssMap) { - var property = properties[i]; - mapping[property] = cssMap[property]; + for (var i = 0; i < properties.length; i++) { + if (properties[i] in cssMap) { + var property = properties[i]; + mapping[property] = cssMap[property]; + } } - } - return mapping; + return mapping; }; + },{}],6:[function(require,module,exports){ var NestedTween = require('./NestedTween'); @@ -605,12 +607,13 @@ function CSSTween(object, properties) { var tweenedObject = (typeof object === 'string') ? document.querySelector(object) : object; // DONE: Changed inheritance to NestedTween for support of css transform properties - // TODO: Add an internal method for replacing unprefixed properties by prefixed properties when necessary + // TODO: Add an internal method for replacing unprefixed properties by prefixed properties when necessary NestedTween.call(this, tweenedObject.style, properties); } CSSTween.prototype = Object.create(NestedTween.prototype); CSSTween.prototype.constructor = CSSTween; -module.exports = CSSTween; +module.exports = CSSTween; + },{"./NestedTween":9}],7:[function(require,module,exports){ var BriefPlayable = require('./BriefPlayable'); @@ -2603,128 +2606,94 @@ Timer.prototype.convertToTimeUnits = function(seconds) { // - Whether or not an easing is being used // - Whether or not an interpolation is being used +// Interpolation functions +function standardTrans(context, p, t) { + return context.from[p] * (1 - t) + context.to[p] * t; +} + +function standardTransCSS(context, p, t) { + return (context.from[p] * (1 - t) + context.to[p] * t) + context.cssMap[p]; +} + +function interpTrans(context, p, t) { + return context.interps[p](t, context.from[p], context.to[p], context.interpParams[p]); +} + +function interpTransCSS(context, p, t) { + return context.interps[p](t, context.from[p], context.to[p], context.interpParams[p]) + context.cssMap[p]; +} + // One property -function update(object, t) { +function update(object, t, interpFunc) { var p = this.prop; - - var suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; - if (suffix) { - object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + suffix; - } else { - object[p] = this.from[p] * (1 - t) + this.to[p] * t; - } + object[p] = interpFunc(this, p, t); } // Several Properties -function updateP(object, t) { +function updateP(object, t, interpFunc) { var q = this.props; - var suffix = null; - - for (var i = 0; i < this.props.length; i += 1) { + + for (var i = 0; i < this.props.length; i += 1) { var p = q[i]; - suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; - if (suffix) { - object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + suffix; - } else { - object[p] = this.from[p] * (1 - t) + this.to[p] * t; - } + object[p] = interpFunc(this, p, t); } } // Interpolation -function updateI(object, t) { +function updateI(object, t, interpFunc) { var p = this.prop; - - var suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; - if (suffix) { - object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]) + suffix; - } else { - object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]); - } + object[p] = interpFunc(this, p, t); } // Interpolation // Several Properties -function updatePI(object, t) { +function updatePI(object, t, interpFunc) { var q = this.props; - var suffix = null; - for (var i = 0; i < q.length; i += 1) { var p = q[i]; - suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; - if (suffix) { - object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]) + suffix; - } else { - object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]); - } + object[p] = interpFunc(this, p, t); } } // Easing -function updateE(object, t) { +function updateE(object, t, interpFunc) { t = this.easing(t, this.easingParam); - var p = this.prop; - - var suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; - if (suffix) { - object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + suffix; - } else { - object[p] = this.from[p] * (1 - t) + this.to[p] * t; - } + var p = this.prop; + object[p] = interpFunc(this, p, t); } // Easing // Several Properties -function updatePE(object, t) { +function updatePE(object, t, interpFunc) { var q = this.props; t = this.easing(t, this.easingParam); - var suffix = null; - for (var i = 0; i < q.length; i += 1) { var p = q[i]; - suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; - if (suffix) { - object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + suffix; - } else { - object[p] = this.from[p] * (1 - t) + this.to[p] * t; - } + object[p] = interpFunc(this, p, t); } } // Easing // Interpolation -function updateIE(object, t) { +function updateIE(object, t, interpFunc) { var p = this.prop; - var suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; - - if (suffix) { - object[p] = this.interps[p](this.easing(t, this.easingParam), - this.from[p], this.to[p], this.interpParams[p]) + suffix; - } else { - object[p] = this.interps[p](this.easing(t, this.easingParam), - this.from[p], this.to[p], this.interpParams[p]); - } + t = this.easing(t, this.easingParam); + object[p] = interpFunc(this, p, t); } // Easing // Interpolation // Several Properties -function updatePIE(object, t) { +function updatePIE(object, t, interpFunc) { var q = this.props; - var suffix = null; t = this.easing(t, this.easingParam); - for (var i = 0; i < q.length; i += 1) { var p = q[i]; - suffix = (p in this.suffixMap) ? this.suffixMap[p] : null; - if (suffix) { - object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]) + suffix; - } else { - object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]); - } + object[p] = interpFunc(this, p, t); } } + var updateMethods = [ [ [update, updateP], @@ -2735,14 +2704,37 @@ var updateMethods = [ ] ]; -function Transition(properties, from, to, start, duration, easing, - easingParam, interpolations, interpolationParams, suffixMap) { +// A mapping of transition functions to updatemethods +var transFunctions = [ + [ + [standardTrans, standardTrans], + [interpTrans, interpTrans] + ], [ + [standardTrans, standardTrans], + [interpTrans, interpTrans] + ] +]; + +// A mapping of transition functions to update methods: +// If we have A CSS Object we select a CSS version of the tranition function +var transFunctionsCSS = [ + [ + [standardTransCSS, standardTransCSS], + [interpTransCSS, interpTransCSS] + ], [ + [standardTransCSS, standardTransCSS], + [interpTransCSS, interpTransCSS] + ] +]; + +function Transition(properties, from, to, start, duration, easing, + easingParam, interpolations, interpolationParams, cssMap) { this.start = start; this.end = start + duration; this.duration = duration; - this.suffixMap = suffixMap; this.from = from; this.to = to; + this.cssMap = cssMap ? cssMap : null; // Easing flag - Whether an easing function is used // 0 => Using linear easing @@ -2783,9 +2775,18 @@ function Transition(properties, from, to, start, duration, easing, } this.update = updateMethods[easingFlag][interpFlag][propsFlag]; + // Select the appropriate transition function based on the mappings + this.transFunc = transFunctions[easingFlag][interpFlag][propsFlag]; + + if (cssMap) { + this.transFunc = transFunctionsCSS[easingFlag][interpFlag][propsFlag]; + } else { + this.transFunc = transFunctions[easingFlag][interpFlag][propsFlag]; + } } -module.exports = Transition; +module.exports = Transition; + },{}],19:[function(require,module,exports){ // One property diff --git a/build/tina.min.js b/build/tina.min.js index 00e87fa..c561dff 100644 --- a/build/tina.min.js +++ b/build/tina.min.js @@ -52,7 +52,7 @@ function Timeline(){return this instanceof Timeline==!1?new Timeline:void BriefP function Timer(e){return this instanceof Timer==!1?new Timer(e):(Tweener.call(this),void(this._speed=e/1e3||1))}var Tweener=require("./Tweener");Timer.prototype=Object.create(Tweener.prototype),Timer.prototype.constructor=Timer,module.exports=Timer,Object.defineProperty(Timer.prototype,"tups",{get:function(){return 1e3*this._speed},set:function(e){this.speed=e/1e3}}),Timer.prototype.convertToSeconds=function(e){return e/(1e3*this._speed)},Timer.prototype.convertToTimeUnits=function(e){return e*this._speed*1e3}; },{"./Tweener":21}],18:[function(require,module,exports){ -function standardTrans(t,s,n){return t.from[s]*(1-n)+t.to[s]*n}function standardTransCSS(t,s,n){return t.from[s]*(1-n)+t.to[s]*n+t.cssMap[s]}function interpTrans(t,s,n){return this.interps[s](n,this.from[s],this.to[s],this.interpParams[s])}function interpTransCSS(t,s,n){return this.interps[s](n,this.from[s],this.to[s],this.interpParams[s])+t.cssMap[s]}function update(t,s,n){var a=this.prop;t[a]=n(this,a,s)}function updateP(t,s,n){for(var a=this.props,r=0;r Date: Thu, 12 May 2016 13:54:00 +0900 Subject: [PATCH 12/18] Fixed issue where CSSStyleObject was causing an error because it was not recognised in node --- build/tina.js | 6 ++++-- build/tina.min.js | 2 +- src/AbstractTween.js | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/build/tina.js b/build/tina.js index 3b42658..e9997ea 100644 --- a/build/tina.js +++ b/build/tina.js @@ -48,8 +48,10 @@ function AbstractTween(object, properties) { } // Determine if we are are tweening a CSS object - this._cssMap = (object instanceof CSSStyleDeclaration) ? CSSMap(properties) : null; - + if (typeof CSSStyleDeclaration !== 'undefined') { + this._cssMap = (object instanceof CSSStyleDeclaration) ? CSSMap(properties) : null; + } + // Properties to tween this._properties = properties; diff --git a/build/tina.min.js b/build/tina.min.js index c561dff..ad783f1 100644 --- a/build/tina.min.js +++ b/build/tina.min.js @@ -1,5 +1,5 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o0&&(this._transitions[0].from=t),this},AbstractTween.prototype._setFrom=function(){this._from={};for(var t=0;t0?this._relative===!0?this._setFrom():this._transitions[this._transitions.length-1].to:null===this._from?this._setFrom():this._from},AbstractTween.prototype.to=function(t,i,n,s,e){"string"==typeof n&&(void 0===easingFunctions[n]?(console.warn("[AbstractTween.to] Given easing does not exist"),n=void 0):n=easingFunctions[n]);var r=this._getLastTransitionEnding(),o=this._relative===!0?TransitionRelative:Transition,a=new o(this._properties,r,t,this._duration,i,n,s,this._interpolations,e,this._cssMap);return this._transitions.push(a),this._duration+=i,this},AbstractTween.prototype.wait=function(t){var i=this._getLastTransitionEnding();return this._transitions.push(new Temporisation(this._duration,t,i,this._properties)),this._duration+=t,this},AbstractTween.prototype._update=function(){for(var t=this._transitions[this._index];t.end<=this._time;){if(this._index===this._transitions.length-1)return void t.update(this._object,1,t.transFunc);this._relative===!0&&t.update(this._object,1,t.transFunc),t=this._transitions[++this._index]}for(;this._time<=t.start;){if(0===this._index)return void t.update(this._object,0,t.transFunc);this._relative===!0&&t.update(this._object,0,t.transFunc),t=this._transitions[--this._index]}t.update(this._object,(this._time-t.start)/t.duration,t.transFunc)},AbstractTween.prototype._validate=function(){return 0===this._transitions.length?(console.warn("[AbstractTween._validate] Cannot start a tween with no transition:",this),!1):!0}; +function Temporisation(t,i,n,s){this.start=t,this.end=t+i,this.duration=i,this.properties=s,this.to=n}function AbstractTween(t,i){if(this._object=t,(null===i||void 0===i)&&t instanceof Array){i=[];for(var n=0;n0&&(this._transitions[0].from=t),this},AbstractTween.prototype._setFrom=function(){this._from={};for(var t=0;t0?this._relative===!0?this._setFrom():this._transitions[this._transitions.length-1].to:null===this._from?this._setFrom():this._from},AbstractTween.prototype.to=function(t,i,n,s,e){"string"==typeof n&&(void 0===easingFunctions[n]?(console.warn("[AbstractTween.to] Given easing does not exist"),n=void 0):n=easingFunctions[n]);var r=this._getLastTransitionEnding(),o=this._relative===!0?TransitionRelative:Transition,a=new o(this._properties,r,t,this._duration,i,n,s,this._interpolations,e,this._cssMap);return this._transitions.push(a),this._duration+=i,this},AbstractTween.prototype.wait=function(t){var i=this._getLastTransitionEnding();return this._transitions.push(new Temporisation(this._duration,t,i,this._properties)),this._duration+=t,this},AbstractTween.prototype._update=function(){for(var t=this._transitions[this._index];t.end<=this._time;){if(this._index===this._transitions.length-1)return void t.update(this._object,1,t.transFunc);this._relative===!0&&t.update(this._object,1,t.transFunc),t=this._transitions[++this._index]}for(;this._time<=t.start;){if(0===this._index)return void t.update(this._object,0,t.transFunc);this._relative===!0&&t.update(this._object,0,t.transFunc),t=this._transitions[--this._index]}t.update(this._object,(this._time-t.start)/t.duration,t.transFunc)},AbstractTween.prototype._validate=function(){return 0===this._transitions.length?(console.warn("[AbstractTween._validate] Cannot start a tween with no transition:",this),!1):!0}; },{"./CSSMap":5,"./Transition":18,"./TransitionRelative":19,"./easing":22,"./interpolation":25}],2:[function(require,module,exports){ function BriefExtension(){this._duration=0,this._onComplete=null,this._iterations=1,this._pingpong=!1,this._persist=!1}module.exports=BriefExtension,BriefExtension.prototype.setSpeed=function(t){0===t?0!==this._speed&&(this._startTime+=this._time/this._speed-this._time):0===this._speed?this._startTime+=this._time-this._time/t:this._startTime+=this._time/this._speed-this._time/t,this._speed=t,null!==this._player&&this._player._onPlayableChanged(this)},BriefExtension.prototype.onComplete=function(t){return this._onComplete=t,this},BriefExtension.prototype.getDuration=function(){return this._duration*this._iterations/this._speed},BriefExtension.prototype._setDuration=function(t){this._duration=t,null!==this._player&&this._player._onPlayableChanged(this)},BriefExtension.prototype._extendDuration=function(t){this._duration+=t,null!==this._player&&this._player._onPlayableChanged(this)},BriefExtension.prototype._getEndTime=function(){return this._speed>0?this._startTime+this.getDuration():this._speed<0?this._startTime:1/0},BriefExtension.prototype._setStartTime=function(t){this._speed>0?this._startTime=t:this._speed<0?this._startTime=t-this.getDuration():this._startTime=1/0},BriefExtension.prototype._getStartTime=function(){return this._speed>0?this._startTime:this._speed<0?this._startTime+this.getDuration():-(1/0)},BriefExtension.prototype._isTimeWithin=function(t){return this._speed>0?this._startTime0?(this._startTime-i)*(this._startTime+this.getDuration()-t)<=0:this._speed<0?(this._startTime+this.getDuration()-i)*(this._startTime-t)<=0:!0},BriefExtension.prototype.goToEnd=function(){return this.goTo(this.getDuration(),this._iterations-1)},BriefExtension.prototype.loop=function(){return this.iterations(1/0)},BriefExtension.prototype.iterations=function(t){return 0>t?(console.warn("[BriefExtension.iterations] Number of iterations cannot be negative"),this):(this._iterations=t,null!==this._player&&this._player._onPlayableChanged(this),this)},BriefExtension.prototype.persist=function(t){return this._persist=t,this},BriefExtension.prototype.pingpong=function(t){return this._pingpong=t,null!==this._player&&this._player._onPlayableChanged(this),this},BriefExtension.prototype._complete=function(t){return this._persist===!0?(this._startTime+=t,void this._player._onPlayableChanged(this)):this._player._inactivate(this)===!1?this:void(null!==this._onComplete&&this._onComplete(t))};var epsilon=1e-6;BriefExtension.prototype._moveTo=function(t,i,e){i*=this._speed;var s;if(0!==i)if(1===this._iterations)this._time=(t-this._startTime)*this._speed,i>0?this._time>=this._duration?(s=this._time-this._duration,this._time=this._duration):this._time<0:0>i&&this._time<=0&&(s=this._time,this._time=0);else{t=(t-this._startTime)*this._speed;var n=t/this._duration;i>0?n>0&&ni&&(n>0&&n0&&this.duration-this._timei&&this._time Date: Tue, 17 May 2016 20:24:18 +0900 Subject: [PATCH 13/18] Removed the additional function calls in the update method - added new transition type, TransitionCSS - this is responsible for managing transitions for CSS objects, and is only created when a CSS object is presented. The CSS map (provides suffixes for CSS properties) is now a property of the TransitionCSS object. --- src/TransitionCSS.js | 135 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 src/TransitionCSS.js diff --git a/src/TransitionCSS.js b/src/TransitionCSS.js new file mode 100644 index 0000000..574553d --- /dev/null +++ b/src/TransitionCSS.js @@ -0,0 +1,135 @@ +// Provides transitions for CSS style objects +var CSSMap = require('./CSSMap'); + +// One property +function update(object, t) { + var p = this.prop; + object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + this.cssMap[p]; +} + +// Several Properties +function updateP(object, t) { + var q = this.props; + for (var i = 0; i < this.props.length; i += 1) { + var p = q[i]; + object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + this.cssMap[p]; + } +} + +// Interpolation +function updateI(object, t) { + var p = this.prop; + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]) + this.cssMap[p]; +} + +// Interpolation +// Several Properties +function updatePI(object, t) { + var q = this.props; + for (var i = 0; i < q.length; i += 1) { + var p = q[i]; + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]) + this.cssMap[p]; + } +} + +// Easing +function updateE(object, t) { + t = this.easing(t, this.easingParam); + var p = this.prop; + object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + this.cssMap[p]; +} + +// Easing +// Several Properties +function updatePE(object, t, interpFunc) { + var q = this.props; + t = this.easing(t, this.easingParam); + for (var i = 0; i < q.length; i += 1) { + var p = q[i]; + object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + this.cssMap[p]; + } +} + +// Easing +// Interpolation +function updateIE(object, t, interpFunc) { + var p = this.prop; + t = this.easing(t, this.easingParam); + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]) + this.cssMap[p]; +} + +// Easing +// Interpolation +// Several Properties +function updatePIE(object, t, interpFunc) { + var q = this.props; + t = this.easing(t, this.easingParam); + for (var i = 0; i < q.length; i += 1) { + var p = q[i]; + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]) + this.cssMap[p]; + } +} + + +var updateMethods = [ + [ + [update, updateP], + [updateI, updatePI] + ], [ + [updateE, updatePE], + [updateIE, updatePIE] + ] +]; + +function TransitionCSS(properties, from, to, start, duration, easing, + easingParam, interpolations, interpolationParams) { + + this.start = start; + this.end = start + duration; + this.duration = duration; + this.from = from; + this.to = to; + this.cssMap = CSSMap(properties); + + // Easing flag - Whether an easing function is used + // 0 => Using linear easing + // 1 => Using custom easing + var easingFlag; + if (easing) { + easingFlag = 1; + this.easing = easing; + this.easingParam = easingParam; + } else { + easingFlag = 0; + } + + // Interpolation flag - Whether an interpolation function is used + // 0 => No Interpolation + // 1 => At least one interpolation + var interpFlag; + if (interpolations === null) { + interpFlag = 0; + } else { + interpFlag = 1; + this.interps = interpolations; + this.interpParams = interpolationParams || {}; + } + + // Property flag - Whether the transition has several properties + // 0 => Only one property + // 1 => Several properties + var propsFlag; + if (properties.length === 1) { + propsFlag = 0; + this.prop = properties[0]; // string + this.props = null; + } else { + propsFlag = 1; + this.prop = null; + this.props = properties; // array + } + + this.update = updateMethods[easingFlag][interpFlag][propsFlag]; +} + +module.exports = TransitionCSS; From 2bd2fa7f22ad88407d9cd06c70cbdad36357767b Mon Sep 17 00:00:00 2001 From: Cain Martin Date: Tue, 17 May 2016 20:31:09 +0900 Subject: [PATCH 14/18] Removed the additional function calls in the update method - added new transition type, 'TransitionCSS' - this is responsible for managing transitions for CSS objects, and is only created when a CSS object is presented. The CSS map (provides suffixes for CSS properties) is now a property of the TransitionCSS object. --- build/tina.js | 271 +++++++++++++++++++++++++++++-------------- build/tina.min.js | 31 ++--- src/AbstractTween.js | 37 +++--- src/CSSTween.js | 5 +- src/Transition.js | 78 +++---------- 5 files changed, 237 insertions(+), 185 deletions(-) diff --git a/build/tina.js b/build/tina.js index e9997ea..81abba8 100644 --- a/build/tina.js +++ b/build/tina.js @@ -1,10 +1,9 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o Using linear easing + // 1 => Using custom easing + var easingFlag; + if (easing) { + easingFlag = 1; + this.easing = easing; + this.easingParam = easingParam; + } else { + easingFlag = 0; + } + + // Interpolation flag - Whether an interpolation function is used + // 0 => No Interpolation + // 1 => At least one interpolation + var interpFlag; + if (interpolations === null) { + interpFlag = 0; + } else { + interpFlag = 1; + this.interps = interpolations; + this.interpParams = interpolationParams || {}; + } + + // Property flag - Whether the transition has several properties + // 0 => Only one property + // 1 => Several properties + var propsFlag; + if (properties.length === 1) { + propsFlag = 0; + this.prop = properties[0]; // string + this.props = null; + } else { + propsFlag = 1; + this.prop = null; + this.props = properties; // array + } + + this.update = updateMethods[easingFlag][interpFlag][propsFlag]; +} + +module.exports = Transition; + +},{}],19:[function(require,module,exports){ +// Provides transitions for CSS style objects +var CSSMap = require('./CSSMap'); +// One property +function update(object, t) { + var p = this.prop; + object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + this.cssMap[p]; +} + +// Several Properties +function updateP(object, t) { + var q = this.props; for (var i = 0; i < this.props.length; i += 1) { var p = q[i]; - object[p] = interpFunc(this, p, t); + object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + this.cssMap[p]; } } // Interpolation -function updateI(object, t, interpFunc) { +function updateI(object, t) { var p = this.prop; - object[p] = interpFunc(this, p, t); + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]) + this.cssMap[p]; } // Interpolation // Several Properties -function updatePI(object, t, interpFunc) { +function updatePI(object, t) { var q = this.props; for (var i = 0; i < q.length; i += 1) { var p = q[i]; - object[p] = interpFunc(this, p, t); + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]) + this.cssMap[p]; } } // Easing -function updateE(object, t, interpFunc) { +function updateE(object, t) { t = this.easing(t, this.easingParam); var p = this.prop; - object[p] = interpFunc(this, p, t); + object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + this.cssMap[p]; } // Easing @@ -2671,7 +2794,7 @@ function updatePE(object, t, interpFunc) { t = this.easing(t, this.easingParam); for (var i = 0; i < q.length; i += 1) { var p = q[i]; - object[p] = interpFunc(this, p, t); + object[p] = (this.from[p] * (1 - t) + this.to[p] * t) + this.cssMap[p]; } } @@ -2680,7 +2803,7 @@ function updatePE(object, t, interpFunc) { function updateIE(object, t, interpFunc) { var p = this.prop; t = this.easing(t, this.easingParam); - object[p] = interpFunc(this, p, t); + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]) + this.cssMap[p]; } // Easing @@ -2691,7 +2814,7 @@ function updatePIE(object, t, interpFunc) { t = this.easing(t, this.easingParam); for (var i = 0; i < q.length; i += 1) { var p = q[i]; - object[p] = interpFunc(this, p, t); + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]) + this.cssMap[p]; } } @@ -2706,37 +2829,15 @@ var updateMethods = [ ] ]; -// A mapping of transition functions to updatemethods -var transFunctions = [ - [ - [standardTrans, standardTrans], - [interpTrans, interpTrans] - ], [ - [standardTrans, standardTrans], - [interpTrans, interpTrans] - ] -]; - -// A mapping of transition functions to update methods: -// If we have A CSS Object we select a CSS version of the tranition function -var transFunctionsCSS = [ - [ - [standardTransCSS, standardTransCSS], - [interpTransCSS, interpTransCSS] - ], [ - [standardTransCSS, standardTransCSS], - [interpTransCSS, interpTransCSS] - ] -]; +function TransitionCSS(properties, from, to, start, duration, easing, + easingParam, interpolations, interpolationParams) { -function Transition(properties, from, to, start, duration, easing, - easingParam, interpolations, interpolationParams, cssMap) { this.start = start; this.end = start + duration; this.duration = duration; this.from = from; this.to = to; - this.cssMap = cssMap ? cssMap : null; + this.cssMap = CSSMap(properties); // Easing flag - Whether an easing function is used // 0 => Using linear easing @@ -2777,19 +2878,11 @@ function Transition(properties, from, to, start, duration, easing, } this.update = updateMethods[easingFlag][interpFlag][propsFlag]; - // Select the appropriate transition function based on the mappings - this.transFunc = transFunctions[easingFlag][interpFlag][propsFlag]; - - if (cssMap) { - this.transFunc = transFunctionsCSS[easingFlag][interpFlag][propsFlag]; - } else { - this.transFunc = transFunctions[easingFlag][interpFlag][propsFlag]; - } } -module.exports = Transition; +module.exports = TransitionCSS; -},{}],19:[function(require,module,exports){ +},{"./CSSMap":5}],20:[function(require,module,exports){ // One property function update(object, t) { @@ -2942,7 +3035,7 @@ function Transition(properties, from, to, start, duration, easing, easingParam, } module.exports = Transition; -},{}],20:[function(require,module,exports){ +},{}],21:[function(require,module,exports){ var BriefPlayable = require('./BriefPlayable'); var AbstractTween = require('./AbstractTween'); @@ -2985,7 +3078,7 @@ Tween.prototype.wait = function (duration) { } return this; }; -},{"./AbstractTween":1,"./BriefPlayable":3,"./inherit":24}],21:[function(require,module,exports){ +},{"./AbstractTween":1,"./BriefPlayable":3,"./inherit":25}],22:[function(require,module,exports){ var Player = require('./Player'); var TINA = require('./TINA'); @@ -3012,7 +3105,7 @@ Tweener.prototype.useAsDefault = function () { TINA.setDefaultTweener(this); return this; }; -},{"./Player":11,"./TINA":14}],22:[function(require,module,exports){ +},{"./Player":11,"./TINA":14}],23:[function(require,module,exports){ /** * * @file A set of ease functions @@ -3275,7 +3368,7 @@ exports.backInOut = function (t, e) { return 0.5 * (t * t * ((e + 1) * t + e)) + 1; }; -},{}],23:[function(require,module,exports){ +},{}],24:[function(require,module,exports){ var TINA = require('./TINA.js'); TINA.CSSTween = require('./CSSTween'); @@ -3299,7 +3392,7 @@ TINA.Tweener = require('./Tweener'); module.exports = TINA; -},{"./BriefExtension":2,"./BriefPlayable":3,"./BriefPlayer":4,"./CSSTween":6,"./Delay":7,"./NestedTween":9,"./Playable":10,"./Player":11,"./Recorder":12,"./Sequence":13,"./TINA.js":14,"./Ticker":15,"./Timeline":16,"./Timer":17,"./Tween":20,"./Tweener":21,"./easing":22,"./interpolation":25}],24:[function(require,module,exports){ +},{"./BriefExtension":2,"./BriefPlayable":3,"./BriefPlayer":4,"./CSSTween":6,"./Delay":7,"./NestedTween":9,"./Playable":10,"./Player":11,"./Recorder":12,"./Sequence":13,"./TINA.js":14,"./Ticker":15,"./Timeline":16,"./Timer":17,"./Tween":21,"./Tweener":22,"./easing":23,"./interpolation":26}],25:[function(require,module,exports){ module.exports = function (subobject, superobject) { var prototypes = Object.keys(superobject.prototype); for (var p = 0; p < prototypes.length; p += 1) { @@ -3307,7 +3400,7 @@ module.exports = function (subobject, superobject) { subobject.prototype[prototypeName] = superobject.prototype[prototypeName]; } }; -},{}],25:[function(require,module,exports){ +},{}],26:[function(require,module,exports){ /** * * @file A set of interpolation functions @@ -3799,4 +3892,4 @@ exports.simplex2d = (function () { return a * (1 - t) + b * t; }; })(); -},{}]},{},[23]); +},{}]},{},[24]); diff --git a/build/tina.min.js b/build/tina.min.js index ad783f1..7c7dba4 100644 --- a/build/tina.min.js +++ b/build/tina.min.js @@ -1,16 +1,16 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o0&&(this._transitions[0].from=t),this},AbstractTween.prototype._setFrom=function(){this._from={};for(var t=0;t0?this._relative===!0?this._setFrom():this._transitions[this._transitions.length-1].to:null===this._from?this._setFrom():this._from},AbstractTween.prototype.to=function(t,i,n,s,e){"string"==typeof n&&(void 0===easingFunctions[n]?(console.warn("[AbstractTween.to] Given easing does not exist"),n=void 0):n=easingFunctions[n]);var r=this._getLastTransitionEnding(),o=this._relative===!0?TransitionRelative:Transition,a=new o(this._properties,r,t,this._duration,i,n,s,this._interpolations,e,this._cssMap);return this._transitions.push(a),this._duration+=i,this},AbstractTween.prototype.wait=function(t){var i=this._getLastTransitionEnding();return this._transitions.push(new Temporisation(this._duration,t,i,this._properties)),this._duration+=t,this},AbstractTween.prototype._update=function(){for(var t=this._transitions[this._index];t.end<=this._time;){if(this._index===this._transitions.length-1)return void t.update(this._object,1,t.transFunc);this._relative===!0&&t.update(this._object,1,t.transFunc),t=this._transitions[++this._index]}for(;this._time<=t.start;){if(0===this._index)return void t.update(this._object,0,t.transFunc);this._relative===!0&&t.update(this._object,0,t.transFunc),t=this._transitions[--this._index]}t.update(this._object,(this._time-t.start)/t.duration,t.transFunc)},AbstractTween.prototype._validate=function(){return 0===this._transitions.length?(console.warn("[AbstractTween._validate] Cannot start a tween with no transition:",this),!1):!0}; +function Temporisation(t,i,n,s){this.start=t,this.end=t+i,this.duration=i,this.properties=s,this.to=n}function AbstractTween(t,i){if(this._object=t,(null===i||void 0===i)&&t instanceof Array){i=[];for(var n=0;n0&&(this._transitions[0].from=t),this},AbstractTween.prototype._setFrom=function(){this._from={};for(var t=0;t0?this._relative===!0?this._setFrom():this._transitions[this._transitions.length-1].to:null===this._from?this._setFrom():this._from},AbstractTween.prototype.to=function(t,i,n,s,e){"string"==typeof n&&(void 0===easingFunctions[n]?(console.warn("[AbstractTween.to] Given easing does not exist"),n=void 0):n=easingFunctions[n]);var r=this._getLastTransitionEnding(),o=null;o=this._relative===!0?TransitionRelative:this._css===!0?TransitionCSS:Transition;var a=new o(this._properties,r,t,this._duration,i,n,s,this._interpolations,e);return this._transitions.push(a),this._duration+=i,this},AbstractTween.prototype.wait=function(t){var i=this._getLastTransitionEnding();return this._transitions.push(new Temporisation(this._duration,t,i,this._properties)),this._duration+=t,this},AbstractTween.prototype._update=function(){for(var t=this._transitions[this._index];t.end<=this._time;){if(this._index===this._transitions.length-1)return void t.update(this._object,1);this._relative===!0&&t.update(this._object,1),t=this._transitions[++this._index]}for(;this._time<=t.start;){if(0===this._index)return void t.update(this._object,0);this._relative===!0&&t.update(this._object,0),t=this._transitions[--this._index]}t.update(this._object,(this._time-t.start)/t.duration)},AbstractTween.prototype._validate=function(){return 0===this._transitions.length?(console.warn("[AbstractTween._validate] Cannot start a tween with no transition:",this),!1):!0}; -},{"./CSSMap":5,"./Transition":18,"./TransitionRelative":19,"./easing":22,"./interpolation":25}],2:[function(require,module,exports){ +},{"./Transition":18,"./TransitionCSS":19,"./TransitionRelative":20,"./easing":23,"./interpolation":26}],2:[function(require,module,exports){ function BriefExtension(){this._duration=0,this._onComplete=null,this._iterations=1,this._pingpong=!1,this._persist=!1}module.exports=BriefExtension,BriefExtension.prototype.setSpeed=function(t){0===t?0!==this._speed&&(this._startTime+=this._time/this._speed-this._time):0===this._speed?this._startTime+=this._time-this._time/t:this._startTime+=this._time/this._speed-this._time/t,this._speed=t,null!==this._player&&this._player._onPlayableChanged(this)},BriefExtension.prototype.onComplete=function(t){return this._onComplete=t,this},BriefExtension.prototype.getDuration=function(){return this._duration*this._iterations/this._speed},BriefExtension.prototype._setDuration=function(t){this._duration=t,null!==this._player&&this._player._onPlayableChanged(this)},BriefExtension.prototype._extendDuration=function(t){this._duration+=t,null!==this._player&&this._player._onPlayableChanged(this)},BriefExtension.prototype._getEndTime=function(){return this._speed>0?this._startTime+this.getDuration():this._speed<0?this._startTime:1/0},BriefExtension.prototype._setStartTime=function(t){this._speed>0?this._startTime=t:this._speed<0?this._startTime=t-this.getDuration():this._startTime=1/0},BriefExtension.prototype._getStartTime=function(){return this._speed>0?this._startTime:this._speed<0?this._startTime+this.getDuration():-(1/0)},BriefExtension.prototype._isTimeWithin=function(t){return this._speed>0?this._startTime0?(this._startTime-i)*(this._startTime+this.getDuration()-t)<=0:this._speed<0?(this._startTime+this.getDuration()-i)*(this._startTime-t)<=0:!0},BriefExtension.prototype.goToEnd=function(){return this.goTo(this.getDuration(),this._iterations-1)},BriefExtension.prototype.loop=function(){return this.iterations(1/0)},BriefExtension.prototype.iterations=function(t){return 0>t?(console.warn("[BriefExtension.iterations] Number of iterations cannot be negative"),this):(this._iterations=t,null!==this._player&&this._player._onPlayableChanged(this),this)},BriefExtension.prototype.persist=function(t){return this._persist=t,this},BriefExtension.prototype.pingpong=function(t){return this._pingpong=t,null!==this._player&&this._player._onPlayableChanged(this),this},BriefExtension.prototype._complete=function(t){return this._persist===!0?(this._startTime+=t,void this._player._onPlayableChanged(this)):this._player._inactivate(this)===!1?this:void(null!==this._onComplete&&this._onComplete(t))};var epsilon=1e-6;BriefExtension.prototype._moveTo=function(t,i,e){i*=this._speed;var s;if(0!==i)if(1===this._iterations)this._time=(t-this._startTime)*this._speed,i>0?this._time>=this._duration?(s=this._time-this._duration,this._time=this._duration):this._time<0:0>i&&this._time<=0&&(s=this._time,this._time=0);else{t=(t-this._startTime)*this._speed;var n=t/this._duration;i>0?n>0&&ni&&(n>0&&n0&&this.duration-this._timei&&this._timei&&(i=t);for(e=this._inactivePlayables.first;null!==e;e=e.next)r=e.object,t=r._getStartTime()+r.getDuration(),t>i&&(i=t);this._setDuration(i)},BriefPlayer.prototype._onPlayableChanged=BriefPlayer.prototype._updateDuration,BriefPlayer.prototype._onPlayableRemoved=BriefPlayer.prototype._updateDuration; -},{"./BriefExtension":2,"./Player":11,"./inherit":24}],5:[function(require,module,exports){ +},{"./BriefExtension":2,"./Player":11,"./inherit":25}],5:[function(require,module,exports){ module.exports=function(t){for(var p={height:"px",width:"px",top:"px",left:"px",bottom:"px",right:"px",opacity:""},o={},i=0;ithis._duration&&this._setDuration(t),this}; },{"./BriefPlayer":4}],17:[function(require,module,exports){ function Timer(e){return this instanceof Timer==!1?new Timer(e):(Tweener.call(this),void(this._speed=e/1e3||1))}var Tweener=require("./Tweener");Timer.prototype=Object.create(Tweener.prototype),Timer.prototype.constructor=Timer,module.exports=Timer,Object.defineProperty(Timer.prototype,"tups",{get:function(){return 1e3*this._speed},set:function(e){this.speed=e/1e3}}),Timer.prototype.convertToSeconds=function(e){return e/(1e3*this._speed)},Timer.prototype.convertToTimeUnits=function(e){return e*this._speed*1e3}; -},{"./Tweener":21}],18:[function(require,module,exports){ -function standardTrans(t,n,s){return t.from[n]*(1-s)+t.to[n]*s}function standardTransCSS(t,n,s){return t.from[n]*(1-s)+t.to[n]*s+t.cssMap[n]}function interpTrans(t,n,s){return t.interps[n](s,t.from[n],t.to[n],t.interpParams[n])}function interpTransCSS(t,n,s){return t.interps[n](s,t.from[n],t.to[n],t.interpParams[n])+t.cssMap[n]}function update(t,n,s){var a=this.prop;t[a]=s(this,a,n)}function updateP(t,n,s){for(var a=this.props,r=0;rt?2*t*t:2*(2*t-t*t)-1},exports.cubicIn=function(t){return t*t*t},exports.cubicOut=function(t){return 3*t-3*t*t+t*t*t},exports.cubicInOut=function(t){return.5>t?4*t*t*t:4*(3*t-3*t*t+t*t*t)-3},exports.quarticIn=function(t){return t*t*t*t},exports.quarticOut=function(t){var n=t*t;return 4*t-6*n+4*n*t-n*n},exports.quarticInOut=function(t){if(.5>t)return 8*t*t*t*t;var n=t*t;return 8*(4*t-6*n+4*n*t-n*n)-7},exports.polyIn=function(t,n){return Math.pow(t,n)},exports.polyOut=function(t,n){return 1-Math.pow(1-t,n)},exports.polyInOut=function(t,n){return.5>t?Math.pow(2*t,n)/2:(2-Math.pow(2*(1-t),n))/2},exports.sineIn=function(t){return 1-Math.cos(PI_OVER_TWO*t)},exports.sineOut=function(t){return Math.sin(PI_OVER_TWO*t)},exports.sineInOut=function(t){return.5>t?(1-Math.cos(PI*t))/2:(1+Math.sin(PI*(t-.5)))/2},exports.expIn=function(t,n){return(1-Math.pow(EXP,n*t))/(1-Math.pow(EXP,n))},exports.expOut=function(t,n){return(1-Math.pow(EXP,-n*t))/(1-Math.pow(EXP,-n))},exports.expInOut=function(t,n){return.5>t?(1-Math.pow(EXP,2*n*t))/(1-Math.pow(EXP,n))/2:.5+(1-Math.pow(EXP,n-2*n*t))/(1-Math.pow(EXP,-n))/2},exports.circIn=function(t){return 1-Math.sqrt(1-Math.pow(t,2))},exports.circOut=function(t){return Math.sqrt(1-Math.pow(1-t,2))},exports.circInOut=function(t){return.5>t?(1-Math.sqrt(1-4*t*t))/2:(1+Math.sqrt(-3+8*t-4*t*t))/2},exports.elasticIn=function(t,n){if(0===t)return 0;n/=n+1;var r=(1+n)*Math.log(t)/Math.log(n);return Math.cos(r)*Math.pow(n,r)},exports.elasticOut=function(t,n){if(1===t)return 1;n/=n+1;var r=(1+n)*Math.log(1-t)/Math.log(n);return 1-Math.cos(r)*Math.pow(n,r)},exports.elasticInOut=function(t,n){var r;return.5>t?0===t?0:(n/=n+1,r=(1+n)*Math.log(2*t)/Math.log(n),.5*Math.cos(r)*Math.pow(n,r)):1===t?1:(n/=n+1,r=(1+n)*Math.log(2-2*t)/Math.log(n),.5+.5*(1-Math.cos(r)*Math.pow(n,r)))},exports.bounceIn=function(t,n){if(0===t)return 0;n/=n+1;var r=(1+n)*Math.log(t)/Math.log(n);return Math.abs(Math.cos(r)*Math.pow(n,r))},exports.bounceOut=function(t,n){if(1===t)return 1;n/=n+1;var r=(1+n)*Math.log(1-t)/Math.log(n);return 1-Math.abs(Math.cos(r)*Math.pow(n,r))},exports.bounceInOut=function(t,n){var r;return.5>t?0===t?0:(n/=n+1,r=(1+n)*Math.log(2*t)/Math.log(n),Math.abs(.5*Math.cos(r)*Math.pow(n,r))):1===t?1:(n/=n+1,r=(1+n)*Math.log(2-2*t)/Math.log(n),.5+.5*(1-Math.abs(Math.cos(r)*Math.pow(n,r))))},exports.backIn=function(t,n){return t*t*((n+1)*t-n)},exports.backOut=function(t,n){return t-=1,t*t*((n+1)*t+n)+1},exports.backInOut=function(t,n){return.5>t?(t*=2,.5*(t*t*((n+1)*t-n))):(t=2*t-2,.5*(t*t*((n+1)*t+n))+1)}; -},{}],23:[function(require,module,exports){ +},{}],24:[function(require,module,exports){ var TINA=require("./TINA.js");TINA.CSSTween=require("./CSSTween"),TINA.Delay=require("./Delay"),TINA.BriefExtension=require("./BriefExtension"),TINA.BriefPlayable=require("./BriefPlayable"),TINA.BriefPlayer=require("./BriefPlayer"),TINA.easing=require("./easing"),TINA.interpolation=require("./interpolation"),TINA.NestedTween=require("./NestedTween"),TINA.PixiTween=require("./NestedTween"),TINA.Playable=require("./Playable"),TINA.Player=require("./Player"),TINA.Recorder=require("./Recorder"),TINA.Sequence=require("./Sequence"),TINA.Ticker=require("./Ticker"),TINA.Timeline=require("./Timeline"),TINA.Timer=require("./Timer"),TINA.Tween=require("./Tween"),TINA.Tweener=require("./Tweener"),module.exports=TINA; -},{"./BriefExtension":2,"./BriefPlayable":3,"./BriefPlayer":4,"./CSSTween":6,"./Delay":7,"./NestedTween":9,"./Playable":10,"./Player":11,"./Recorder":12,"./Sequence":13,"./TINA.js":14,"./Ticker":15,"./Timeline":16,"./Timer":17,"./Tween":20,"./Tweener":21,"./easing":22,"./interpolation":25}],24:[function(require,module,exports){ +},{"./BriefExtension":2,"./BriefPlayable":3,"./BriefPlayer":4,"./CSSTween":6,"./Delay":7,"./NestedTween":9,"./Playable":10,"./Player":11,"./Recorder":12,"./Sequence":13,"./TINA.js":14,"./Ticker":15,"./Timeline":16,"./Timer":17,"./Tween":21,"./Tweener":22,"./easing":23,"./interpolation":26}],25:[function(require,module,exports){ module.exports=function(o,t){for(var e=Object.keys(t.prototype),p=0;pa?t:a>=e-1?o:n[a-1]},exports.colorRGB=function(r,t,o){return{r:t.r*(1-r)+o.r*r,g:t.g*(1-r)+o.g*r,b:t.b*(1-r)+o.b*r}},exports.colorRGBA=function(r,t,o){return{r:t.r*(1-r)+o.r*r,g:t.g*(1-r)+o.g*r,b:t.b*(1-r)+o.b*r,a:t.a*(1-r)+o.a*r}},exports.colorRGBToHexa=function(r,t,o){var n=Math.round(t.r*(1-r)+o.r*r),e=Math.round(t.g*(1-r)+o.g*r),a=Math.round(t.b*(1-r)+o.b*r);return"#"+n.toString(16)+e.toString(16)+a.toString(16)},exports.colorRGBToString=function(r,t,o){var n=Math.round(t.r*(1-r)+o.r*r),e=Math.round(t.g*(1-r)+o.g*r),a=Math.round(t.b*(1-r)+o.b*r);return"rgb("+n.toString(16)+","+e.toString(16)+","+a.toString(16)+")"},exports.colorRGBAToString=function(r,t,o){var n=Math.round(t.r*(1-r)+o.r*r),e=Math.round(t.g*(1-r)+o.g*r),a=Math.round(t.b*(1-r)+o.b*r),u=Math.round(t.a*(1-r)+o.a*r);return"rgba("+n.toString(16)+","+e.toString(16)+","+a.toString(16)+","+u+")"},exports.string=function(r,t,o){for(var n=t.length,e=o.length,a="",u=0;e>u;u+=1){var i=o.charCodeAt(u),f=u>=n?97>i?65:97:t.charCodeAt(u),c=Math.round(f*(1-r)+i*r);a+=String.fromCharCode(c)}return a},exports.bezierQuadratic=function(r,t,o,n){var e=1-r;return e*e*t+r*(2*e*n[0]+r*o)},exports.bezierCubic=function(r,t,o,n){var e=1-r;return e*e*e*t+r*(3*e*e*n[0]+r*(3*e*n[1]+r*o))},exports.bezierQuartic=function(r,t,o,n){var e=1-r,a=2*e;return a*a*t+r*(4*e*a*n[0]+r*(6*a*n[1]+r*(4*e*n[2]+r*o)))},exports.bezierQuintic=function(r,t,o,n){var e=1-r,a=2*e;return a*a*e*t+r*(5*a*a*n[0]+r*(10*e*a*n[1]+r*(10*a*n[2]+r*(5*e*n[3]+r*o))))},exports.bezier=function(r,t,o,n){var e=n.length,a=1-r,u=o,i=e;for(k=1;kg;g-=1)e=h*Math.pow(i,g),a=n[u-g],f=f*r+e*a[0],c=c*r+e*a[1],h*=(u-g)/(g+1);return e=Math.pow(i,u),[f*r+t[0]*e,c*r+t[1]*e]},exports.bezier3d=function(r,t,o,n){for(var e,a,u=n.length,i=1-r,f=o[0],c=o[1],h=o[2],g=u,x=1;u>x;x-=1)e=g*Math.pow(i,x),a=n[u-x],f=f*r+e*a[0],c=c*r+e*a[1],h=h*r+e*a[2],g*=(u-x)/(x+1);return e=Math.pow(i,u),[f*r+t[0]*e,c*r+t[1]*e,h*r+t[2]*e]},exports.bezierKd=function(r,t,o,n){for(var e=n.length,a=1-r,u=t.length,i=[],f=0;u>f;f+=1)i[f]=o[f];for(var c,h,g=e,x=1;e>x;x-=1){for(c=g*Math.pow(a,x),h=n[e-x],f=0;u>f;f+=1)i[f]=i[f]*r+c*h[f];g*=(e-x)/(x+1)}for(c=Math.pow(a,e),f=0;u>f;f+=1)i[f]=i[f]*r+t[f]*c;return i},exports.catmullRom=function(r,t,o,n){if(1===r)return n;var e=t.length,a=o.length+1;r*=a;var u=Math.floor(r);r-=u;for(var i=r*r,f=r*i,c=-.5*f+1*i-.5*r,h=1.5*f-2.5*i+1,g=-1.5*f+2*i+.5*r,x=.5*f-.5*i,p=u-2,v=u-1,s=u,l=u+1,M=0>p?t:o[p],b=0>v?t:o[v],d=a-2>l?o[s]:n,S=a-2>l?o[l]:n,y=[],z=0;e>z;z+=1)y[z]=M[z]*c+b[z]*h+d[z]*g+S[z]*x;return y},exports.noise=function(){var r=[182,235,131,26,88,132,100,117,202,176,10,19,83,243,75,52,252,194,32,30,72,15,124,53,236,183,121,103,175,39,253,120,166,33,237,141,99,180,18,143,69,136,173,21,210,189,16,142,190,130,109,186,104,80,62,51,165,25,122,119,42,219,146,61,149,177,54,158,27,170,60,201,159,193,203,58,154,222,78,138,220,41,98,14,156,31,29,246,81,181,40,161,192,227,35,241,135,150,89,68,134,114,230,123,187,179,67,217,71,218,7,148,228,251,93,8,140,125,73,37,82,28,112,24,174,118,232,137,191,133,147,245,6,172,95,113,185,205,254,116,55,198,57,152,128,233,74,225,34,223,79,111,215,85,200,9,242,12,167,44,20,110,107,126,86,231,234,76,207,102,214,238,221,145,213,64,197,38,168,157,87,92,255,212,49,196,240,90,63,0,77,94,1,108,91,17,224,188,153,250,249,199,127,59,46,184,36,43,209,206,248,4,56,47,226,13,144,22,11,247,70,244,48,97,151,195,96,101,45,66,239,178,171,160,84,65,23,3,211,162,163,50,105,129,155,169,115,5,106,2,208,204,139,229,164,216,182],t=[-1,1];return function(o,n,e,a){for(var u=2,i=a.per||1,f=a.frq||2,c=a.oct||4,h=a.off||0,g=0,x=a.x+h,p=0;c>p;p+=1){var v=255&(x|x),s=x-(x|x),l=1-s;g+=u*(l*l*s*(3-2*l)*t[1&r[v]]-s*s*l*(3-2*s)*t[1&r[v+1]]),x*=(x-h)*f+h,u*=i}var M=1===i?1/c:.5*(1-i)/(1-Math.pow(i,c));return o+=g*M,n*(1-o)+e*o}}(),exports.simplex2d=function(){function r(r,t,o){return r[0]*t+r[1]*o}var t=[182,235,131,26,88,132,100,117,202,176,10,19,83,243,75,52,252,194,32,30,72,15,124,53,236,183,121,103,175,39,253,120,166,33,237,141,99,180,18,143,69,136,173,21,210,189,16,142,190,130,109,186,104,80,62,51,165,25,122,119,42,219,146,61,149,177,54,158,27,170,60,201,159,193,203,58,154,222,78,138,220,41,98,14,156,31,29,246,81,181,40,161,192,227,35,241,135,150,89,68,134,114,230,123,187,179,67,217,71,218,7,148,228,251,93,8,140,125,73,37,82,28,112,24,174,118,232,137,191,133,147,245,6,172,95,113,185,205,254,116,55,198,57,152,128,233,74,225,34,223,79,111,215,85,200,9,242,12,167,44,20,110,107,126,86,231,234,76,207,102,214,238,221,145,213,64,197,38,168,157,87,92,255,212,49,196,240,90,63,0,77,94,1,108,91,17,224,188,153,250,249,199,127,59,46,184,36,43,209,206,248,4,56,47,226,13,144,22,11,247,70,244,48,97,151,195,96,101,45,66,239,178,171,160,84,65,23,3,211,162,163,50,105,129,155,169,115,5,106,2,208,204,139,229,164,216,182,235,131,26,88,132,100,117,202,176,10,19,83,243,75,52,252,194,32,30,72,15,124,53,236,183,121,103,175,39,253,120,166,33,237,141,99,180,18,143,69,136,173,21,210,189,16,142,190,130,109,186,104,80,62,51,165,25,122,119,42,219,146,61,149,177,54,158,27,170,60,201,159,193,203,58,154,222,78,138,220,41,98,14,156,31,29,246,81,181,40,161,192,227,35,241,135,150,89,68,134,114,230,123,187,179,67,217,71,218,7,148,228,251,93,8,140,125,73,37,82,28,112,24,174,118,232,137,191,133,147,245,6,172,95,113,185,205,254,116,55,198,57,152,128,233,74,225,34,223,79,111,215,85,200,9,242,12,167,44,20,110,107,126,86,231,234,76,207,102,214,238,221,145,213,64,197,38,168,157,87,92,255,212,49,196,240,90,63,0,77,94,1,108,91,17,224,188,153,250,249,199,127,59,46,184,36,43,209,206,248,4,56,47,226,13,144,22,11,247,70,244,48,97,151,195,96,101,45,66,239,178,171,160,84,65,23,3,211,162,163,50,105,129,155,169,115,5,106,2,208,204,139,229,164,216],o=[[1,1],[-1,1],[1,-1],[-1,-1],[1,0],[-1,0],[1,0],[-1,0],[0,1],[0,-1],[0,1],[0,-1],[1,1],[-1,1],[1,-1],[-1,-1]];return function(n,e,a,u){for(var i=2,f=u.per||1,c=u.frq||2,h=u.oct||4,g=u.off||{x:0,y:0},x=x,p=u.x+g.x,v=u.y+g.y,s=0;h>s;s+=1){var l,M,b,d=.5*(Math.sqrt(3)-1),S=(p+v)*d,y=Math.floor(p+S),z=Math.floor(v+S),w=(3-Math.sqrt(3))/6,k=(y+z)*w,R=y-k,B=z-k;R=p-R,B=v-B;var C,G;R>B?(C=1,G=0):(C=0,G=1);var m=R-C+w,q=B-G+w,A=R-1+2*w,Q=B-1+2*w,T=255&y,X=255&z,Y=.5-R*R-B*B,H=.5-m*m-q*q,K=.5-A*A-Q*Q;if(0>Y)l=0;else{var Z=15&t[T+t[X]];Y*=Y,l=Y*Y*r(o[Z],R,B)}if(0>H)M=0;else{var j=15&t[T+C+t[X+G]];H*=H,M=H*H*r(o[j],m,q)}if(0>K)b=0;else{var D=15&t[T+1+t[X+1]];K*=K,b=K*K*r(o[D],A,Q)}x+=70*i*(l+M+b),p*=(p-g.x)*c+g.x,v*=(v-g.y)*c+g.y,i*=f}var E=1===f?1/h:.5*(1-f)/(1-Math.pow(f,h));return n+=x*E,e*(1-n)+a*n}}(); -},{}]},{},[23]); +},{}]},{},[24]); diff --git a/src/AbstractTween.js b/src/AbstractTween.js index 7e81dc4..a2204bc 100644 --- a/src/AbstractTween.js +++ b/src/AbstractTween.js @@ -1,9 +1,8 @@ -var Transition = require('./Transition'); -var TransitionRelative = require('./TransitionRelative'); -var CSSMap = require('./CSSMap'); - -var easingFunctions = require('./easing'); -var interpolationFunctions = require('./interpolation'); +var Transition = require('./Transition'); +var TransitionCSS = require('./TransitionCSS'); +var TransitionRelative = require('./TransitionRelative'); +var easingFunctions = require('./easing'); +var interpolationFunctions = require('./interpolation'); // Temporisation, used for waiting @@ -48,7 +47,7 @@ function AbstractTween(object, properties) { // Determine if we are are tweening a CSS object if (typeof CSSStyleDeclaration !== 'undefined') { - this._cssMap = (object instanceof CSSStyleDeclaration) ? CSSMap(properties) : null; + this._css = (object instanceof CSSStyleDeclaration) ? true : false; } // Properties to tween @@ -161,7 +160,16 @@ AbstractTween.prototype.to = function (toObject, duration, easing, easingParam, // Getting previous transition ending as the beginning for the new transition var fromObject = this._getLastTransitionEnding(); - var TransitionConstructor = (this._relative === true) ? TransitionRelative : Transition; + // Determine the appropriate transition constructor for the given object + var TransitionConstructor = null; + if (this._relative === true) { + TransitionConstructor = TransitionRelative; + } else if (this._css === true) { + TransitionConstructor = TransitionCSS; + } else { + TransitionConstructor = Transition; + } + var transition = new TransitionConstructor( this._properties, fromObject, @@ -171,8 +179,7 @@ AbstractTween.prototype.to = function (toObject, duration, easing, easingParam, easing, easingParam, this._interpolations, - interpolationParams, - this._cssMap + interpolationParams ); this._transitions.push(transition); @@ -192,12 +199,12 @@ AbstractTween.prototype._update = function () { var transition = this._transitions[this._index]; while (transition.end <= this._time) { if (this._index === (this._transitions.length - 1)) { - transition.update(this._object, 1, transition.transFunc); + transition.update(this._object, 1); return; } if (this._relative === true ) { - transition.update(this._object, 1, transition.transFunc); + transition.update(this._object, 1); } transition = this._transitions[++this._index]; @@ -205,19 +212,19 @@ AbstractTween.prototype._update = function () { while (this._time <= transition.start) { if (this._index === 0) { - transition.update(this._object, 0, transition.transFunc); + transition.update(this._object, 0); return; } if (this._relative === true ) { - transition.update(this._object, 0, transition.transFunc); + transition.update(this._object, 0); } transition = this._transitions[--this._index]; } // Updating the object with respect to the current transition and time - transition.update(this._object, (this._time - transition.start) / transition.duration, transition.transFunc); + transition.update(this._object, (this._time - transition.start) / transition.duration); }; AbstractTween.prototype._validate = function () { diff --git a/src/CSSTween.js b/src/CSSTween.js index 79a9f17..accfd49 100644 --- a/src/CSSTween.js +++ b/src/CSSTween.js @@ -1,5 +1,4 @@ var NestedTween = require('./NestedTween'); - /** * * @classdesc @@ -17,10 +16,10 @@ function CSSTween(object, properties) { var tweenedObject = (typeof object === 'string') ? document.querySelector(object) : object; - // DONE: Changed inheritance to NestedTween for support of css transform properties - // TODO: Add an internal method for replacing unprefixed properties by prefixed properties when necessary + // TODO: Add an internal method for replacing unprefixed properties by prefixed properties when necessary NestedTween.call(this, tweenedObject.style, properties); } + CSSTween.prototype = Object.create(NestedTween.prototype); CSSTween.prototype.constructor = CSSTween; module.exports = CSSTween; diff --git a/src/Transition.js b/src/Transition.js index 5914993..e637196 100644 --- a/src/Transition.js +++ b/src/Transition.js @@ -5,60 +5,43 @@ // - Whether or not an easing is being used // - Whether or not an interpolation is being used -// Interpolation functions -function standardTrans(context, p, t) { - return context.from[p] * (1 - t) + context.to[p] * t; -} - -function standardTransCSS(context, p, t) { - return (context.from[p] * (1 - t) + context.to[p] * t) + context.cssMap[p]; -} - -function interpTrans(context, p, t) { - return context.interps[p](t, context.from[p], context.to[p], context.interpParams[p]); -} - -function interpTransCSS(context, p, t) { - return context.interps[p](t, context.from[p], context.to[p], context.interpParams[p]) + context.cssMap[p]; -} - // One property -function update(object, t, interpFunc) { +function update(object, t) { var p = this.prop; - object[p] = interpFunc(this, p, t); + object[p] = this.from[p] * (1 - t) + this.to[p] * t; } // Several Properties -function updateP(object, t, interpFunc) { +function updateP(object, t) { var q = this.props; for (var i = 0; i < this.props.length; i += 1) { var p = q[i]; - object[p] = interpFunc(this, p, t); + object[p] = this.from[p] * (1 - t) + this.to[p] * t; } } // Interpolation -function updateI(object, t, interpFunc) { +function updateI(object, t) { var p = this.prop; - object[p] = interpFunc(this, p, t); + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]); } // Interpolation // Several Properties -function updatePI(object, t, interpFunc) { +function updatePI(object, t) { var q = this.props; for (var i = 0; i < q.length; i += 1) { var p = q[i]; - object[p] = interpFunc(this, p, t); + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]); } } // Easing -function updateE(object, t, interpFunc) { +function updateE(object, t) { t = this.easing(t, this.easingParam); var p = this.prop; - object[p] = interpFunc(this, p, t); + object[p] = this.from[p] * (1 - t) + this.to[p] * t; } // Easing @@ -68,7 +51,7 @@ function updatePE(object, t, interpFunc) { t = this.easing(t, this.easingParam); for (var i = 0; i < q.length; i += 1) { var p = q[i]; - object[p] = interpFunc(this, p, t); + object[p] = this.from[p] * (1 - t) + this.to[p] * t; } } @@ -77,7 +60,7 @@ function updatePE(object, t, interpFunc) { function updateIE(object, t, interpFunc) { var p = this.prop; t = this.easing(t, this.easingParam); - object[p] = interpFunc(this, p, t); + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]); } // Easing @@ -88,11 +71,10 @@ function updatePIE(object, t, interpFunc) { t = this.easing(t, this.easingParam); for (var i = 0; i < q.length; i += 1) { var p = q[i]; - object[p] = interpFunc(this, p, t); + object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]); } } - var updateMethods = [ [ [update, updateP], @@ -103,37 +85,13 @@ var updateMethods = [ ] ]; -// A mapping of transition functions to updatemethods -var transFunctions = [ - [ - [standardTrans, standardTrans], - [interpTrans, interpTrans] - ], [ - [standardTrans, standardTrans], - [interpTrans, interpTrans] - ] -]; - -// A mapping of transition functions to update methods: -// If we have A CSS Object we select a CSS version of the tranition function -var transFunctionsCSS = [ - [ - [standardTransCSS, standardTransCSS], - [interpTransCSS, interpTransCSS] - ], [ - [standardTransCSS, standardTransCSS], - [interpTransCSS, interpTransCSS] - ] -]; - function Transition(properties, from, to, start, duration, easing, - easingParam, interpolations, interpolationParams, cssMap) { + easingParam, interpolations, interpolationParams) { this.start = start; this.end = start + duration; this.duration = duration; this.from = from; this.to = to; - this.cssMap = cssMap ? cssMap : null; // Easing flag - Whether an easing function is used // 0 => Using linear easing @@ -174,14 +132,6 @@ function Transition(properties, from, to, start, duration, easing, } this.update = updateMethods[easingFlag][interpFlag][propsFlag]; - // Select the appropriate transition function based on the mappings - this.transFunc = transFunctions[easingFlag][interpFlag][propsFlag]; - - if (cssMap) { - this.transFunc = transFunctionsCSS[easingFlag][interpFlag][propsFlag]; - } else { - this.transFunc = transFunctions[easingFlag][interpFlag][propsFlag]; - } } module.exports = Transition; From 8585d80314f98db34189e89fa540ea63d664b209 Mon Sep 17 00:00:00 2001 From: Cain Martin Date: Wed, 18 May 2016 20:03:23 +0900 Subject: [PATCH 15/18] Reverted Transition.js to version 09477cc - removing all of my changes (which are unecessary given the addition of TransitionCSS. --- src/Transition.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/Transition.js b/src/Transition.js index e637196..b96c179 100644 --- a/src/Transition.js +++ b/src/Transition.js @@ -14,7 +14,6 @@ function update(object, t) { // Several Properties function updateP(object, t) { var q = this.props; - for (var i = 0; i < this.props.length; i += 1) { var p = q[i]; object[p] = this.from[p] * (1 - t) + this.to[p] * t; @@ -46,7 +45,7 @@ function updateE(object, t) { // Easing // Several Properties -function updatePE(object, t, interpFunc) { +function updatePE(object, t) { var q = this.props; t = this.easing(t, this.easingParam); for (var i = 0; i < q.length; i += 1) { @@ -57,16 +56,15 @@ function updatePE(object, t, interpFunc) { // Easing // Interpolation -function updateIE(object, t, interpFunc) { +function updateIE(object, t) { var p = this.prop; - t = this.easing(t, this.easingParam); - object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]); + object[p] = this.interps[p](this.easing(t, this.easingParam), this.from[p], this.to[p], this.interpParams[p]); } // Easing // Interpolation // Several Properties -function updatePIE(object, t, interpFunc) { +function updatePIE(object, t) { var q = this.props; t = this.easing(t, this.easingParam); for (var i = 0; i < q.length; i += 1) { @@ -85,13 +83,13 @@ var updateMethods = [ ] ]; -function Transition(properties, from, to, start, duration, easing, - easingParam, interpolations, interpolationParams) { - this.start = start; - this.end = start + duration; - this.duration = duration; - this.from = from; - this.to = to; +function Transition(properties, from, to, start, duration, easing, easingParam, interpolations, interpolationParams) { + this.start = start; + this.end = start + duration; + this.duration = duration; + + this.from = from; + this.to = to; // Easing flag - Whether an easing function is used // 0 => Using linear easing @@ -134,4 +132,4 @@ function Transition(properties, from, to, start, duration, easing, this.update = updateMethods[easingFlag][interpFlag][propsFlag]; } -module.exports = Transition; +module.exports = Transition; \ No newline at end of file From d8c49932aa806ebccef59817b7ba0cd6907909f7 Mon Sep 17 00:00:00 2001 From: Cain Martin Date: Wed, 18 May 2016 20:47:12 +0900 Subject: [PATCH 16/18] Added better explanation in comment for the undefined check of CSSStyleDeclaration object --- build/tina.js | 29 ++++++++++++++--------------- build/tina.min.js | 2 +- src/AbstractTween.js | 2 ++ 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/build/tina.js b/build/tina.js index 81abba8..e96023a 100644 --- a/build/tina.js +++ b/build/tina.js @@ -47,6 +47,8 @@ function AbstractTween(object, properties) { } // Determine if we are are tweening a CSS object + // NOTE: The undefined check is to avoid a crash when running Tina in + // environments where the DOM is not available, such as in node. if (typeof CSSStyleDeclaration !== 'undefined') { this._css = (object instanceof CSSStyleDeclaration) ? true : false; } @@ -2623,7 +2625,6 @@ function update(object, t) { // Several Properties function updateP(object, t) { var q = this.props; - for (var i = 0; i < this.props.length; i += 1) { var p = q[i]; object[p] = this.from[p] * (1 - t) + this.to[p] * t; @@ -2655,7 +2656,7 @@ function updateE(object, t) { // Easing // Several Properties -function updatePE(object, t, interpFunc) { +function updatePE(object, t) { var q = this.props; t = this.easing(t, this.easingParam); for (var i = 0; i < q.length; i += 1) { @@ -2666,16 +2667,15 @@ function updatePE(object, t, interpFunc) { // Easing // Interpolation -function updateIE(object, t, interpFunc) { +function updateIE(object, t) { var p = this.prop; - t = this.easing(t, this.easingParam); - object[p] = this.interps[p](t, this.from[p], this.to[p], this.interpParams[p]); + object[p] = this.interps[p](this.easing(t, this.easingParam), this.from[p], this.to[p], this.interpParams[p]); } // Easing // Interpolation // Several Properties -function updatePIE(object, t, interpFunc) { +function updatePIE(object, t) { var q = this.props; t = this.easing(t, this.easingParam); for (var i = 0; i < q.length; i += 1) { @@ -2694,13 +2694,13 @@ var updateMethods = [ ] ]; -function Transition(properties, from, to, start, duration, easing, - easingParam, interpolations, interpolationParams) { - this.start = start; - this.end = start + duration; - this.duration = duration; - this.from = from; - this.to = to; +function Transition(properties, from, to, start, duration, easing, easingParam, interpolations, interpolationParams) { + this.start = start; + this.end = start + duration; + this.duration = duration; + + this.from = from; + this.to = to; // Easing flag - Whether an easing function is used // 0 => Using linear easing @@ -2743,8 +2743,7 @@ function Transition(properties, from, to, start, duration, easing, this.update = updateMethods[easingFlag][interpFlag][propsFlag]; } -module.exports = Transition; - +module.exports = Transition; },{}],19:[function(require,module,exports){ // Provides transitions for CSS style objects var CSSMap = require('./CSSMap'); diff --git a/build/tina.min.js b/build/tina.min.js index 7c7dba4..2cf9385 100644 --- a/build/tina.min.js +++ b/build/tina.min.js @@ -52,7 +52,7 @@ function Timeline(){return this instanceof Timeline==!1?new Timeline:void BriefP function Timer(e){return this instanceof Timer==!1?new Timer(e):(Tweener.call(this),void(this._speed=e/1e3||1))}var Tweener=require("./Tweener");Timer.prototype=Object.create(Tweener.prototype),Timer.prototype.constructor=Timer,module.exports=Timer,Object.defineProperty(Timer.prototype,"tups",{get:function(){return 1e3*this._speed},set:function(e){this.speed=e/1e3}}),Timer.prototype.convertToSeconds=function(e){return e/(1e3*this._speed)},Timer.prototype.convertToTimeUnits=function(e){return e*this._speed*1e3}; },{"./Tweener":22}],18:[function(require,module,exports){ -function update(t,i){var s=this.prop;t[s]=this.from[s]*(1-i)+this.to[s]*i}function updateP(t,i){for(var s=this.props,a=0;a Date: Wed, 18 May 2016 21:00:21 +0900 Subject: [PATCH 17/18] Fixed formatting --- src/AbstractTween.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/AbstractTween.js b/src/AbstractTween.js index 271e1f4..db4628f 100644 --- a/src/AbstractTween.js +++ b/src/AbstractTween.js @@ -1,8 +1,8 @@ -var Transition = require('./Transition'); -var TransitionCSS = require('./TransitionCSS'); -var TransitionRelative = require('./TransitionRelative'); -var easingFunctions = require('./easing'); -var interpolationFunctions = require('./interpolation'); +var Transition = require('./Transition'); +var TransitionCSS = require('./TransitionCSS'); +var TransitionRelative = require('./TransitionRelative'); +var easingFunctions = require('./easing'); +var interpolationFunctions = require('./interpolation'); // Temporisation, used for waiting @@ -46,7 +46,7 @@ function AbstractTween(object, properties) { } // Determine if we are are tweening a CSS object - // NOTE: The undefined check is to avoid a crash when running Tina in + // The undefined check is to avoid a crash when running Tina in // environments where the DOM is not available, such as in node. if (typeof CSSStyleDeclaration !== 'undefined') { this._css = (object instanceof CSSStyleDeclaration) ? true : false; From 908bcf65789a8994161500d5c17913e67280e10b Mon Sep 17 00:00:00 2001 From: Cain Martin Date: Wed, 18 May 2016 21:04:53 +0900 Subject: [PATCH 18/18] More formatting fixes --- src/AbstractTween.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/AbstractTween.js b/src/AbstractTween.js index db4628f..c87370a 100644 --- a/src/AbstractTween.js +++ b/src/AbstractTween.js @@ -1,8 +1,8 @@ -var Transition = require('./Transition'); -var TransitionCSS = require('./TransitionCSS'); -var TransitionRelative = require('./TransitionRelative'); -var easingFunctions = require('./easing'); -var interpolationFunctions = require('./interpolation'); +var Transition = require('./Transition'); +var TransitionCSS = require('./TransitionCSS'); +var TransitionRelative = require('./TransitionRelative'); +var easingFunctions = require('./easing'); +var interpolationFunctions = require('./interpolation'); // Temporisation, used for waiting