mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 10:56:15 -08:00
- Created a new documentation file for the danmuku plugin, detailing its usage and providing code examples. - Added a comprehensive guide for language settings (i18n), including instructions for importing languages, setting default languages, and modifying language options. - Included code snippets for initializing the Artplayer with different languages and examples for adding new languages.
8 lines
12 KiB
JavaScript
8 lines
12 KiB
JavaScript
|
|
/*!
|
|
* artplayer-tool-thumbnail.js v4.3.12
|
|
* Github: https://github.com/zhw2590582/ArtPlayer
|
|
* (c) 2017-2025 Harvey Zack
|
|
* Released under the MIT License.
|
|
*/
|
|
!function(e,t,n,r,i,o,s,c){var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},u="function"==typeof a[r]&&a[r],l=u.i||{},f=u.cache||{},h="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function p(t,n){if(!f[t]){if(!e[t]){if(i[t])return i[t];var o="function"==typeof a[r]&&a[r];if(!n&&o)return o(t,!0);if(u)return u(t,!0);if(h&&"string"==typeof t)return h(t);var s=Error("Cannot find module '"+t+"'");throw s.code="MODULE_NOT_FOUND",s}l.resolve=function(n){var r=e[t][1][n];return null!=r?r:n},l.cache={};var c=f[t]=new p.Module(t);e[t][0].call(c.exports,l,c,c.exports,a)}return f[t].exports;function l(e){var t=l.resolve(e);return!1===t?{}:p(t)}}p.isParcelRequire=!0,p.Module=function(e){this.id=e,this.bundle=p,this.require=h,this.exports={}},p.modules=e,p.cache=f,p.parent=u,p.distDir=void 0,p.publicUrl=void 0,p.devServer=void 0,p.i=l,p.register=function(t,n){e[t]=[function(e,t){t.exports=n},{}]},Object.defineProperty(p,"root",{get:function(){return a[r]}}),a[r]=p;for(var d=0;d<t.length;d++)p(t[d]);if(n){var v=p(n);"object"==typeof exports&&"undefined"!=typeof module?module.exports=v:"function"==typeof define&&define.amd&&define(function(){return v})}}({bzF6W:[function(e,t,n,r){var i=e("@parcel/transformer-js/src/esmodule-helpers.js");i.defineInteropFlag(n),i.export(n,"default",function(){return h});var o=e("@swc/helpers/cjs/_call_super.cjs"),s=e("@swc/helpers/cjs/_class_call_check.cjs"),c=e("@swc/helpers/cjs/_create_class.cjs"),a=e("@swc/helpers/cjs/_inherits.cjs"),u=e("./emitter"),l=i.interopDefault(u),f=e("./utils"),h=function(e){"use strict";function t(){var e,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return(0,s._)(this,t),(e=(0,o._)(this,t)).processing=!1,e.option={},e.setup(Object.assign({},t.DEFAULTS,n)),e.video=t.creatVideo(),e.duration=0,e.inputChange=e.inputChange.bind(e),e.ondrop=e.ondrop.bind(e),e.option.fileInput.addEventListener("change",e.inputChange),e.option.fileInput.addEventListener("dragover",t.ondragover),e.option.fileInput.addEventListener("drop",t.ondrop),e}return(0,a._)(t,e),(0,c._)(t,[{key:"ondrop",value:function(e){e.preventDefault();var t=e.dataTransfer.files[0];this.loadVideo(t)}},{key:"setup",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.option=Object.assign({},this.option,t);var n=this.option,r=n.fileInput,i=n.number,o=n.width,s=n.column;if(this.errorHandle(r instanceof Element,"The 'fileInput' is not a Element"),"INPUT"!==r.tagName||"file"!==r.type){r.style.position="relative";var c=document.createElement("input");c.type="file",c.style.position="absolute",c.style.width="100%",c.style.height="100%",c.style.left="0",c.style.top="0",c.style.right="0",c.style.bottom="0",c.style.opacity="0",r.appendChild(c),this.option.fileInput=c}return["number","width","column","begin","end"].forEach(function(t){e.errorHandle("number"==typeof e.option[t],"The '".concat(t,"' is not a number"))}),this.option.number=(0,f.clamp)(i,10,1e3),this.option.width=(0,f.clamp)(o,10,1e3),this.option.column=(0,f.clamp)(s,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 n=URL.createObjectURL(e);this.videoUrl=n,this.file=e,this.emit("file",this.file),this.video.src=n,this.emit("video",this.video)}}},{key:"start",value:function(){var e=this;if(!this.video.duration)return(0,f.sleep)(1e3).then(function(){return e.start()});var t=this.option,n=t.width,r=t.number,i=t.begin,o=t.end,s=this.video.videoHeight/this.video.videoWidth*n;this.option.height=s,this.option.begin=(0,f.clamp)(i,0,this.video.duration),this.option.end=(0,f.clamp)(o||this.video.duration,i,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=r/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 c=this.creatScreenshotDate(),a=this.creatCanvas(),u=a.getContext("2d");this.emit("canvas",a);var l=c.map(function(t,i){return function(){return new Promise(function(o){e.video.oncanplay=function(){u.drawImage(e.video,t.x,t.y,n,s),a.toBlob(function(t){e.thumbnailUrl&&URL.revokeObjectURL(e.thumbnailUrl),e.thumbnailUrl=URL.createObjectURL(t),e.emit("update",e.thumbnailUrl,(i+1)/r),e.video.oncanplay=null,o()})},e.video.currentTime=t.time})}});return this.processing=!0,(0,f.runPromisesInSeries)(l).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,n=e.width,r=e.height,i=e.column,o=e.begin,s=this.duration/t,c=[o+s];c.length<t;){var a=c[c.length-1];c.push(a+s)}return c.map(function(e,t){return{time:e-s/2,x:t%i*n,y:Math.floor(t/i)*r}})}},{key:"creatCanvas",value:function(){var e=this.option,t=e.number,n=e.width,r=e.height,i=e.column,o=document.createElement("canvas"),s=o.getContext("2d");return o.width=n*i,o.height=Math.ceil(t/i)*r+30,s.fillStyle="black",s.fillRect(0,0,o.width,o.height),s.font="14px Georgia",s.fillStyle="#fff",s.fillText("From: https://artplayer.org/, Number: ".concat(t,", Width: ").concat(n,", Height: ").concat(r,", Column: ").concat(i),10,o.height-11),o}},{key:"download",value:function(){this.errorHandle(this.file&&this.thumbnailUrl,"Download does not seem to be ready, please create preview first"),this.errorHandle(!this.processing,"There is currently a task in progress, please wait a moment...");var e=document.createElement("a"),t="".concat((0,f.getFileName)(this.file.name),".png");return e.download=t,e.href=this.thumbnailUrl,document.body.appendChild(e),e.click(),document.body.removeChild(e),this.emit("download",t),this}},{key:"errorHandle",value:function(e,t){if(!e)throw this.emit("error",t),Error(t)}},{key:"destroy",value:function(){this.option.fileInput.removeEventListener("change",this.inputChange),this.option.fileInput.removeEventListener("dragover",t.ondragover),this.option.fileInput.removeEventListener("drop",t.ondrop),document.body.removeChild(this.video),this.videoUrl&&URL.revokeObjectURL(this.videoUrl),this.thumbnailUrl&&URL.revokeObjectURL(this.thumbnailUrl),this.emit("destroy")}}],[{key:"DEFAULTS",get:function(){return{number:60,width:160,height:90,column:10,begin:0,end:NaN}}},{key:"ondragover",value:function(e){e.preventDefault()}},{key:"creatVideo",value:function(){var e=document.createElement("video");return e.style.position="absolute",e.style.top="-9999px",e.style.left="-9999px",e.muted=!0,e.controls=!0,document.body.appendChild(e),e}}]),t}(l.default);window.ArtplayerToolThumbnail=h},{"@swc/helpers/cjs/_call_super.cjs":"aFrVF","@swc/helpers/cjs/_class_call_check.cjs":"5Lt2s","@swc/helpers/cjs/_create_class.cjs":"fExy2","@swc/helpers/cjs/_inherits.cjs":"8c2nw","./emitter":"1vMbl","./utils":"gG4jP","@parcel/transformer-js/src/esmodule-helpers.js":"ihnSZ"}],aFrVF:[function(e,t,n,r){"use strict";var i=e("206ae600478262e1"),o=e("e9be447e8b980fc1"),s=e("3357997583474f25");n._=function(e,t,n){return t=i._(t),s._(e,o._()?Reflect.construct(t,n||[],i._(e).constructor):t.apply(e,n))}},{"206ae600478262e1":"cAaXX",e9be447e8b980fc1:"6eqqS","3357997583474f25":"fa3rG"}],cAaXX:[function(e,t,n,r){"use strict";function i(e){return n._=i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},i(e)}n._=i},{}],"6eqqS":[function(e,t,n,r){"use strict";function i(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(n._=i=function(){return!!e})()}n._=i},{}],fa3rG:[function(e,t,n,r){"use strict";var i=e("2f044ca51fa80bb1"),o=e("95fbded20695b6ea");n._=function(e,t){return t&&("object"===o._(t)||"function"==typeof t)?t:i._(e)}},{"2f044ca51fa80bb1":"ckXPU","95fbded20695b6ea":"9vrOw"}],ckXPU:[function(e,t,n,r){"use strict";n._=function(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}},{}],"9vrOw":[function(e,t,n,r){"use strict";n._=function(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}},{}],"5Lt2s":[function(e,t,n,r){"use strict";n._=function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}},{}],fExy2:[function(e,t,n,r){"use strict";function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}n._=function(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}},{}],"8c2nw":[function(e,t,n,r){"use strict";var i=e("1736e5513da71c03");n._=function(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&i._(e,t)}},{"1736e5513da71c03":"gBKVY"}],gBKVY:[function(e,t,n,r){"use strict";function i(e,t){return n._=i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},i(e,t)}n._=i},{}],"1vMbl":[function(e,t,n,r){var i=e("@parcel/transformer-js/src/esmodule-helpers.js");i.defineInteropFlag(n),i.export(n,"default",function(){return c});var o=e("@swc/helpers/cjs/_class_call_check.cjs"),s=e("@swc/helpers/cjs/_create_class.cjs"),c=function(){"use strict";function e(){(0,o._)(this,e)}return(0,s._)(e,[{key:"on",value:function(e,t,n){var r=this.e||(this.e={});return(r[e]||(r[e]=[])).push({fn:t,ctx:n}),this}},{key:"once",value:function(e,t,n){var r=this;function i(){for(var o=arguments.length,s=Array(o),c=0;c<o;c++)s[c]=arguments[c];r.off(e,i),t.apply(n,s)}return i._=t,this.on(e,i,n)}},{key:"emit",value:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];for(var i=((this.e||(this.e={}))[e]||[]).slice(),o=0;o<i.length;o+=1)i[o].fn.apply(i[o].ctx,n);return this}},{key:"off",value:function(e,t){var n=this.e||(this.e={}),r=n[e],i=[];if(r&&t)for(var o=0,s=r.length;o<s;o+=1)r[o].fn!==t&&r[o].fn._!==t&&i.push(r[o]);return i.length?n[e]=i:delete n[e],this}}]),e}()},{"@swc/helpers/cjs/_class_call_check.cjs":"5Lt2s","@swc/helpers/cjs/_create_class.cjs":"fExy2","@parcel/transformer-js/src/esmodule-helpers.js":"ihnSZ"}],ihnSZ:[function(e,t,n,r){n.interopDefault=function(e){return e&&e.__esModule?e:{default:e}},n.defineInteropFlag=function(e){Object.defineProperty(e,"__esModule",{value:!0})},n.exportAll=function(e,t){return Object.keys(e).forEach(function(n){"default"===n||"__esModule"===n||Object.prototype.hasOwnProperty.call(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[n]}})}),t},n.export=function(e,t,n){Object.defineProperty(e,t,{enumerable:!0,get:n})}},{}],gG4jP:[function(e,t,n,r){var i=e("@parcel/transformer-js/src/esmodule-helpers.js");function o(e){return new Promise(function(t){return setTimeout(t,e)})}function s(e){return e.reduce(function(e,t){return e.then(t)},Promise.resolve())}function c(e){var t=e.split(".");return t.pop(),t.join(".")}function a(e,t,n){return Math.max(Math.min(e,Math.max(t,n)),Math.min(t,n))}i.defineInteropFlag(n),i.export(n,"sleep",function(){return o}),i.export(n,"runPromisesInSeries",function(){return s}),i.export(n,"getFileName",function(){return c}),i.export(n,"clamp",function(){return a})},{"@parcel/transformer-js/src/esmodule-helpers.js":"ihnSZ"}]},["bzF6W"],"bzF6W","parcelRequire7b4c",{}); |