/*! * artplayer-tool-thumbnail.js v4.3.12 * Github: https://github.com/zhw2590582/ArtPlayer * (c) 2017-2023 Harvey Zack * Released under the MIT License. */ !function(e,t,r,n,o){var s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},i="function"==typeof s[n]&&s[n],a=i.cache||{},l="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function c(t,r){if(!a[t]){if(!e[t]){var o="function"==typeof s[n]&&s[n];if(!r&&o)return o(t,!0);if(i)return i(t,!0);if(l&&"string"==typeof t)return l(t);var u=new Error("Cannot find module '"+t+"'");throw u.code="MODULE_NOT_FOUND",u}p.resolve=function(r){var n=e[t][1][r];return null!=n?n:r},p.cache={};var f=a[t]=new c.Module(t);e[t][0].call(f.exports,p,f,f.exports,this)}return a[t].exports;function p(e){var t=p.resolve(e);return!1===t?{}:c(t)}}c.isParcelRequire=!0,c.Module=function(e){this.id=e,this.bundle=c,this.exports={}},c.modules=e,c.cache=a,c.parent=i,c.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(c,"root",{get:function(){return s[n]}}),s[n]=c;for(var u=0;u0&&void 0!==arguments[0]?arguments[0]:{};return(0,a.default)(this,r),(e=t.call(this)).processing=!1,e.option={},e.setup(Object.assign({},r.DEFAULTS,n)),e.video=r.creatVideo(),e.duration=0,e.inputChange=e.inputChange.bind((0,s.default)(e)),e.ondrop=e.ondrop.bind((0,s.default)(e)),e.option.fileInput.addEventListener("change",e.inputChange),e.option.fileInput.addEventListener("dragover",r.ondragover),e.option.fileInput.addEventListener("drop",r.ondrop),e}return(0,c.default)(r,[{key:"ondrop",value:function(e){e.preventDefault();var t=e.dataTransfer.files[0];this.loadVideo(t)}},{key:"setup",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this;this.option=Object.assign({},this.option,e);var r=this.option,n=r.fileInput,o=r.number,s=r.width,i=r.column;if(this.errorHandle(n instanceof Element,"The 'fileInput' is not a Element"),"INPUT"!==n.tagName||"file"!==n.type){n.style.position="relative";var a=document.createElement("input");a.type="file",a.style.position="absolute",a.style.width="100%",a.style.height="100%",a.style.left="0",a.style.top="0",a.style.right="0",a.style.bottom="0",a.style.opacity="0",n.appendChild(a),this.option.fileInput=a}return["number","width","column","begin","end"].forEach((function(e){t.errorHandle("number"==typeof t.option[e],"The '".concat(e,"' is not a number"))})),this.option.number=(0,_.clamp)(o,10,1e3),this.option.width=(0,_.clamp)(s,10,1e3),this.option.column=(0,_.clamp)(i,1,1e3),this}},{key:"inputChange",value:function(e){var t=this.option.fileInput.files[0];this.loadVideo(t),e.target.value=""}},{key:"loadVideo",value:function(e){if(e){var t=this.video.canPlayType(e.type);this.errorHandle("maybe"===t||"probably"===t,"Playback of this file format is not supported: ".concat(e.type));var r=URL.createObjectURL(e);this.videoUrl=r,this.file=e,this.emit("file",this.file),this.video.src=r,this.emit("video",this.video)}}},{key:"start",value:function(){var e=this;if(!this.video.duration)return(0,_.sleep)(1e3).then((function(){return e.start()}));var t=this.option,r=t.width,n=t.number,o=t.begin,s=t.end,i=this.video.videoHeight/this.video.videoWidth*r;this.option.height=i,this.option.begin=(0,_.clamp)(o,0,this.video.duration),this.option.end=(0,_.clamp)(s||this.video.duration,o,this.video.duration),this.errorHandle(this.option.end>this.option.begin,"End time must be greater than the start time"),this.duration=this.option.end-this.option.begin,this.density=n/this.duration,this.errorHandle(this.file&&this.video,"Please select the video file first"),this.errorHandle(!this.processing,"There is currently a task in progress, please wait a moment..."),this.errorHandle(this.density<=1,"The preview density cannot be greater than 1, but got ".concat(this.density));var a=this.creatScreenshotDate(),l=this.creatCanvas(),c=l.getContext("2d");this.emit("canvas",l);var u=a.map((function(t,o){return function(){return new Promise((function(s){e.video.oncanplay=function(){c.drawImage(e.video,t.x,t.y,r,i),l.toBlob((function(t){e.thumbnailUrl&&URL.revokeObjectURL(e.thumbnailUrl),e.thumbnailUrl=URL.createObjectURL(t),e.emit("update",e.thumbnailUrl,(o+1)/n),e.video.oncanplay=null,s()}))},e.video.currentTime=t.time}))}}));return this.processing=!0,(0,_.runPromisesInSeries)(u).then((function(){e.processing=!1,e.emit("done")})).catch((function(t){throw e.processing=!1,e.emit("error",t.message),t}))}},{key:"creatScreenshotDate",value:function(){for(var e=this.option,t=e.number,r=e.width,n=e.height,o=e.column,s=e.begin,i=this.duration/t,a=[s+i];a.length1?t-1:0),n=1;n