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J,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;oBACtC,YAAY,IAAI,SAAS,CAAC;iBAC7B;aACJ;YAAC,IAAI,CAAC,CAAC;gBACJ,EAAE,CAAC,CAAC,YAAY,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;oBACjC,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;oBAC5B,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;oBACxC,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;iBAC1B;gBAAC,IAAI,CAAC,CAAC;oBACJ,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;oBACtC,YAAY,IAAI,SAAS,CAAC;iBAC7B;aACJ;SACJ,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;KACnB;;gBAnGJ,gBAAS,SAAC;oBACP,QAAQ,EAAE,UAAU;iBACvB;;;;;iCAII,aAAM;8BACN,aAAM;6BAON,YAAK;4BAML,YAAK;8BAML,YAAK;yBAML,YAAK;;0BAlCV;;AAMa,0CAAe","sourcesContent":["import { Directive, Input, Output, EventEmitter } from '@angular/core';\n\n@Directive({\n selector: '[counto]'\n})\n\nexport class CountoDirective {\n\n @Output() countoChange = new EventEmitter();\n @Output() countoEnd = new EventEmitter();\n private _timer: any;\n private _duration: number;\n private _countTo: number;\n private _countFrom: number;\n private _step: number;\n\n @Input()\n set duration(duration: string) {\n this._duration = parseFloat(duration);\n this.run();\n }\n\n @Input()\n set countTo(countTo: string) {\n this._countTo = parseFloat(countTo);\n this.run();\n }\n\n @Input()\n set countFrom(countFrom: string) {\n this._countFrom = parseFloat(countFrom);\n this.run();\n }\n\n @Input()\n set step(step: string) {\n this._step = parseFloat(step);\n this.run();\n }\n\n run() {\n var _this = this;\n clearInterval(_this._timer);\n\n if (isNaN(_this._duration)) {\n return false;\n }\n\n if (isNaN(_this._step)) {\n return false;\n }\n\n if (isNaN(_this._countFrom)) {\n return false;\n }\n\n if (isNaN(_this._countTo)) {\n return false;\n }\n\n if (_this._step <= 0) {\n console.info('Step must be greater than 0.');\n return false;\n }\n\n if (_this._duration <= 0) {\n console.info('Duration must be greater than 0.');\n return false;\n }\n\n if (_this._step > _this._duration*1000) {\n console.info('Step must be equal or smaller than duration.');\n return false;\n }\n\n var intermediate = _this._countFrom;\n var increment = Math.abs(_this._countTo - _this._countFrom) / ((_this._duration * 1000) / _this._step);\n\n _this.countoChange.emit(intermediate);\n\n _this._timer = setInterval(function() {\n if (_this._countTo < _this._countFrom) {\n if (intermediate <= _this._countTo) {\n clearInterval(_this._timer);\n _this.countoChange.emit(_this._countTo);\n _this.countoEnd.emit();\n } else {\n _this.countoChange.emit(intermediate);\n intermediate -= increment;\n }\n } else {\n if (intermediate >= _this._countTo) {\n clearInterval(_this._timer);\n _this.countoChange.emit(_this._countTo);\n _this.countoEnd.emit();\n } else {\n _this.countoChange.emit(intermediate);\n intermediate += increment;\n }\n }\n }, _this._step);\n }\n}\n"]}
\No newline at end of file