"use strict";var e=function(e){return e&&e.__esModule?e["default"]:e},t=function(){function e(e,t){for(var i in t){var o=t[i];o.configurable=!0,o.value&&(o.writable=!0)}Object.defineProperties(e,t)}return function(t,i,o){return i&&e(t.prototype,i),o&&e(t,o),t}}(),i=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(e.__proto__=t)},o=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},n=e(require("react")),a=e(require("../../../ffmpeg/ffmpeg")),r=e(require("path")),s=e(require("fs")),h=e(require("async")),l=require("events").EventEmitter,d="win32"===process.platform?process.env.HOMEPATH:process.env.HOME,f=r.resolve(d,".jibo","temp"),u=void 0,c=void 0,p={},m=function(e){function n(e){o(this,n),this.uri=e,this.fileName=r.parse(this.uri).base,this.folderPath=r.resolve(f,this.fileName),this.imageCache={},this.isLoaded=!1,s.existsSync(f)||s.mkdirSync(f)}return i(n,e),t(n,{_getImageKey:{value:function(e){return this.folderPath+e}},_loadImage:{value:function(e,t,i){var o=new Image;p[this._getImageKey(t)]=o,o.onload=function(){i()};var n=r.resolve(this.folderPath,"image"+e+".png");o.src=n+"?"+t}},_loadImages:{value:function(e,t,i){var o=this;try{a(this.uri).on("filenames",function(){}).on("end",function(){for(var e=[],n=0;n0&&a.push(t._loadImages.bind(t,r,s)),h.series(a,function(){var o=(new Date).getTime()-i;console.log("Video of "+t.duration+" seconds toolk "+o),e()})}})}()}catch(i){console.log(i)}}},getImage:{value:function(e){return p[this._getImageKey(e)]}}}),n}(l);module.exports=n.createClass({displayName:"layout-child",getInitialState:function(){return this.onDataChangedBind=this.onDataChanged.bind(this),this.dataMap={},{}},render:function(){return u&&c&&this.setStyle(),n.createElement("div",{className:"video-container",ref:"content",style:{width:"100%",height:"100%",display:"inline-block"},src:this.props.videoSource,preload:"auto"})},setStyle:function(){var e=u.getImage(c);if(e){var t=1/u.ratio;if(e.style.position="relative",t=0;a--){var s=o[a].value.Video;if(""!==s){var l=r.resolve(this.props.projectRoot,s);this.dataMap[l]||!function(){var e=new m(l);t.dataMap[l]=e,n.push(function(t){e.load(t)})}()}}n.length>0&&h.parallel(n,e)},componentDidMount:function(){var e=this;this.content=n.findDOMNode(this.refs.content),this.loadVideos(function(){e.onDataChanged()}),this.props.animationModel.on("ondatachanged",this.onDataChangedBind)},setChild:function(){var e=u.getImage(c);if(e){for(;this.content.firstChild;)this.content.removeChild(this.content.firstChild);this.content.appendChild(e),this.setStyle(u)}},onDataChanged:function(){var e=this.props.animationModel,t=e.getLayersOfType("Video");if(0!==t.length){this.loadVideos();for(var i=e.uiState.currentKeyframe,o=t[0].keyframes,n=void 0,a=o.length-1;a>=0;a--)if(i>=o[a].time){n=o[a];break}if(n){u=void 0;var s=n.value.Video;if(""!==s){var h=r.resolve(this.props.projectRoot,s);u=this.dataMap[h];var l=(i-n.time)/this.props.animationModel.state.keyframes.framerate;c=Math.round(u.count*l/u.duration),this.setChild()}}else for(;this.content.firstChild;)this.content.removeChild(this.content.firstChild)}}});