awv3
Version:
AWV client CAD framework
1 lines • 6.96 kB
JavaScript
"use strict";function _interopRequireDefault(t){return t&&t.__esModule?t:{"default":t}}function flatten(t,e,i,r){Array.isArray(e)&&1==e.length&&"object"===(0,_typeof3["default"])(e[0])&&(e=mergeArray(t,i.join("."),e[0],!0)),i="undefined"==typeof i?[]:i,r="undefined"==typeof r?{}:r;var a=void 0,n=void 0,s=void 0;for(var o in e)e.hasOwnProperty(o)&&(a=o,n=e[o],i.push(a),"object"===("undefined"==typeof n?"undefined":(0,_typeof3["default"])(n))&&null!==n?n instanceof _three2["default"].Euler?(r[a+".x"]=n.x,r[a+".y"]=n.y,r[a+".z"]=n.z):r=flatten(t,n,i,r):"number"==typeof n&&(s=i.join("."),r[s]=n),i.pop());return r}function ref(t,e){return e.split(".").reduce(function(t,e){return t[e]},t)}function returnValue(t,e){var i=e.split(/\.(?=[^.]+$)/);return 1==i.length?[t,i[0],i.length]:[ref(t,i[0]),i[1],i.length]}function mergeArray(t,e,i,r){var a={},n=[],s=returnValue(t,e);return s[0][s[1]].forEach(function(t){Array.isArray(i)?!function(){var e={};i.forEach(function(i){var r={};r[i]=t[i],(0,_assign2["default"])(e,r)}),n.push(e)}():"object"===("undefined"==typeof i?"undefined":(0,_typeof3["default"])(i))&&n.push(i)}),1==s[2]||r?a=n:a[s[1]]=n,a}exports.__esModule=!0;var _assign=require("babel-runtime/core-js/object/assign"),_assign2=_interopRequireDefault(_assign),_typeof2=require("babel-runtime/helpers/typeof"),_typeof3=_interopRequireDefault(_typeof2),_promise=require("babel-runtime/core-js/promise"),_promise2=_interopRequireDefault(_promise),_getIterator2=require("babel-runtime/core-js/get-iterator"),_getIterator3=_interopRequireDefault(_getIterator2),_keys=require("babel-runtime/core-js/object/keys"),_keys2=_interopRequireDefault(_keys),_classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_three=require("three"),_three2=_interopRequireDefault(_three),_easing2=require("../animation/easing"),tweens=[],Tween=function(){function t(e,i){(0,_classCallCheck3["default"])(this,t),this.parent=e,this.internalUpdate=null,this.isPlaying=!1,this.paused=!1,this.duration=0,this.repeatTimes=0,this.repeatMode=t.Repeat.Normal,this.reversed=!1,this.delayTime=0,this.onStartCallbackFired=!1,this.easingFunction=_easing2.exponential.out,this.startTime=null,this.onStartCallback=null,this.onUpdateCallback=null,this.onCompleteCallback=null,this.thenCallback=null,this.onStopCallback=null,this.valuesEnd=flatten(e,i),this.valuesStart={},this.valuesStartRepeat={},this.object={},this.map={};for(var r in this.valuesEnd){var a=this.map[r]=returnValue(e,r),n=a[0][a[1]];this.object[r]=n,this.valuesStart[r]=n,this.valuesStartRepeat[r]=n}}return t.prototype.hasProperty=function(t){return this.object.hasOwnProperty(t)},t.prototype.getProperties=function(){return this.valuesStart},t.prototype.removeProperty=function(t){return delete this.valuesStart[t],delete this.valuesEnd[t],delete this.object[t],delete this.map[t],0===(0,_keys2["default"])(this.object).length&&this.stop(),this},t.prototype.from=function(t){if(!t)return this;var e=flatten(this.parent,t),i=void 0;for(var r in e){var a=returnValue(t,r);a[0]&&(i=a[0]),a[0]=a[0]||i;var n=a[0][a[1]],s=this.map[r];s[0][s[1]]=n,this.object[r]=n,this.valuesStart[r]=n}return this},t.prototype.start=function(e){this.duration=e||0,t.add(this),this.isPlaying=!0,this.paused=!1,this.onStartCallbackFired=!1,this.startTime=null;for(var i=t.getAll(),r=Array.isArray(i),a=0,i=r?i:(0,_getIterator3["default"])(i);;){var n;if(r){if(a>=i.length)break;n=i[a++]}else{if(a=i.next(),a.done)break;n=a.value}var s=n;if(s!==this&&s.isPlaying&&s.parent==this.parent)for(var o in this.object)s.hasProperty(o)&&s.removeProperty(o)}if(0==this.duration)for(var l in this.valuesEnd){var u=this.valuesEnd[l],h=this.map[l];this.object[l]=u,h[0][h[1]]=u}return this.parent.view&&this.parent.view.invalidate(),this},t.prototype.now=function(){return this.start(0)},t.prototype.stop=function(){return this.isPlaying=!1,this.paused=!1,null!==this.onStopCallback&&this.onStopCallback.call(this.object),null!==this.thenCallback&&(this.thenCallback.call(this.object),this.thenCallback=null),this},t.prototype.pause=function(){return this.paused=!0,this},t.prototype["continue"]=function(){return this.paused=!1,this},t.prototype.toggle=function(){return this.paused=!this.paused,this},t.prototype.delay=function(t){return this.delayTime=t,this},t.prototype.repeat=function(){var e=arguments.length<=0||void 0===arguments[0]?0:arguments[0],i=arguments.length<=1||void 0===arguments[1]?t.Repeat.Normal:arguments[1];return this.repeatTimes=e,this.repeatMode=i,this},t.prototype.easing=function(t){return this.easingFunction=t,this},t.prototype.onStart=function(t){return this.onStartCallback=t,this},t.prototype.onUpdate=function(t){return this.onUpdateCallback=t,this},t.prototype.onComplete=function(t){return this.onCompleteCallback=t,this},t.prototype.wait=function(){var t=this;return this.isPlaying?new _promise2["default"](function(e){return t.thenCallback=e}):_promise2["default"].resolve()},t.prototype.onStop=function(t){return this.onStopCallback=t,this},t.prototype.update=function(e){if(this.paused)return!0;if(!this.isPlaying)return!1;null==this.startTime&&(this.startTime=window.performance.now(),this.startTime+=this.delayTime);var i=void 0;if(e<this.startTime)return!0;this.onStartCallbackFired===!1&&(null!==this.onStartCallback&&this.onStartCallback.call(this.object),this.onStartCallbackFired=!0);var r=(e-this.startTime)/this.duration;r=r>1?1:r;var a=this.easingFunction(r);for(i in this.valuesEnd){var n=this.valuesStart[i],s=this.valuesEnd[i],o=n+(s-n)*a,l=this.map[i];this.object[i]=o,l[0][l[1]]=o}if(null!==this.onUpdateCallback&&this.onUpdateCallback.call(this.object,a,e),1==r){if(this.repeatTimes>0){isFinite(this.repeatTimes)&&this.repeatTimes--;for(i in this.valuesStartRepeat){if("string"==typeof this.valuesEnd[i]&&(this.valuesStartRepeat[i]=this.valuesStartRepeat[i]+parseFloat(this.valuesEnd[i],10)),this.repeatMode===t.Repeat.Yoyo){var u=this.valuesStartRepeat[i];this.valuesStartRepeat[i]=this.valuesEnd[i],this.valuesEnd[i]=u}this.valuesStart[i]=this.valuesStartRepeat[i]}return this.repeatMode===t.Repeat.Yoyo&&(this.reversed=!this.reversed),this.startTime=e+this.delayTime,!0}return null!==this.onCompleteCallback&&this.onCompleteCallback.call(this.object),null!==this.thenCallback&&(this.thenCallback.call(this.object),this.thenCallback=null),!1}return!0},t.getAll=function(){return tweens},t.removeAll=function(){tweens=[]},t.add=function(t){tweens.push(t)},t.remove=function(t){var e=tweens.indexOf(t);e!==-1&&tweens.splice(e,1)},t.removeObjectTweens=function(e){t.getAll().forEach(function(t){t.parent==e&&t.stop()})},t.update=function(t){if(t=void 0!==t?t:window.performance.now(),0===tweens.length)return!1;var e=0,i=tweens.length;for(e;e<i;e++){var r=tweens[e];r.update(t)?!r.paused&&r.parent.view&&r.parent.view.invalidate():(tweens.splice(e--,1),i--)}return!0},t}();exports["default"]=Tween,Tween.Repeat={Normal:1,Yoyo:2};