/*! * artplayer-plugin-danmuku.js v3.1.9 * Github: https://github.com/zhw2590582/ArtPlayer#readme * (c) 2017-2019 Harvey Zack * Released under the MIT License. */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).artplayerPluginDanmuku=e()}(this,function(){"use strict";var r=function(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t};var a=function(e){for(var t=1;t\n '.concat(t.get("Danmu opacity"),': 100%\n \n
\n \n
\n '),mounted:function(t){var e=t.querySelector("input[type=range]"),n=t.querySelector(".art-value");r(e,"change",function(){var t=e.value;n.innerText=100*Number(t),i.plugins.artplayerPluginDanmuku.config({opacity:Number(t)})}),i.on("artplayerPluginDanmuku:config",function(t){e.value!==t.opacity&&(e.value=t.opacity,n.innerText=100*t.opacity)})}}}function l(i){var t=i.i18n,r=i.events.proxy;return{name:"danmuku-size",index:11,html:'\n
\n '.concat(t.get("Danmu size"),': 25px\n
\n
\n \n
\n '),mounted:function(t){var e=t.querySelector("input[type=range]"),n=t.querySelector(".art-value");r(e,"change",function(){var t=e.value;n.innerText=t,i.plugins.artplayerPluginDanmuku.config({fontSize:Number(t)})}),i.on("artplayerPluginDanmuku:config",function(t){e.value!==t.fontSize&&(e.value=t.fontSize,n.innerText=t.fontSize)})}}}function c(i){var t=i.i18n,r=i.events.proxy;return{name:"danmuku-speed",index:12,html:'\n
\n '.concat(t.get("Danmu speed"),': 5s\n
\n
\n \n
\n '),mounted:function(t){var e=t.querySelector("input[type=range]"),n=t.querySelector(".art-value");r(e,"change",function(){var t=e.value;n.innerText=t,i.plugins.artplayerPluginDanmuku.config({speed:Number(t)})}),i.on("artplayerPluginDanmuku:config",function(t){e.value!==t.speed&&(e.value=t.speed,n.innerText=t.speed)})}}}function p(n){var t=n.i18n,i=n.events.proxy;return{name:"danmuku-synchronousPlayback",index:13,html:'\n \n "),mounted:function(t){var e=t.querySelector("input[type=checkbox]");i(e,"change",function(){n.plugins.artplayerPluginDanmuku.config({synchronousPlayback:e.checked})}),n.on("artplayerPluginDanmuku:config",function(t){e.checked!==t.synchronousPlayback&&(e.checked=t.synchronousPlayback)})}}}function n(t,e,n){return t.filter(function(t){return t.$state===e}).map(n)}function f(t,e){var n=t.getBoundingClientRect();return e?n[e]:n}var m=function(t){if(Array.isArray(t))return t};var h=function(t,e){var n=[],i=!0,r=!1,a=void 0;try{for(var o,u=t[Symbol.iterator]();!(i=(o=u.next()).done)&&(n.push(o.value),!e||n.length!==e);i=!0);}catch(t){r=!0,a=t}finally{try{i||null==u.return||u.return()}finally{if(r)throw a}}return n};var d=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")};var x=function(t,e){return m(t)||h(t,e)||d()};function y(t){return fetch(t).then(function(t){return t.text()}).then(function(t){return function(t){if("string"!=typeof t)return[];var e=t.match(/[\S ]*?)<\/d>/gi);return e.length?e.map(function(t){var e=t.match(/(.+)<\/d>/),n=x(e,3),i=n[1],r=n[2],a=i.split(",");return 8===a.length&&r.trim()?{text:r,time:Number(a[0]),mode:function(t){switch(t){case 1:case 2:case 3:return"scroll";case 4:case 5:return"static";default:return null}}(Number(a[1])),fontSize:Number(a[2]),color:"#".concat(Number(a[3]).toString(16)),timestamp:Number(a[4]),pool:Number(a[5]),userID:a[6],rowID:Number(a[7])}:null}):[]}(t)})}function g(t,e){var n=x(t.option.margin,2),i=n[0],r=n[1],o=f(t.art.template.$player),a=t.queue.filter(function(t){return t.mode===e.mode&&"emit"===t.$state&&t.$ref&&t.$ref.style.fontSize===e.$ref.style.fontSize&&parseFloat(t.$ref.style.top)<=o.height-r}).map(function(t){var e=f(t.$ref),n=e.width,i=e.height,r=e.top-o.top,a=e.left-o.left;return{top:r,left:a,height:i,width:n,right:o.width-a-n}}).sort(function(t,e){return t.top-e.top});return 0===a.length?i:(a.unshift({top:0,left:0,right:0,height:i,width:o.width}),a.push({top:o.height-r,left:0,right:0,height:r,width:o.width}),function(t){for(var e=0,n={},i=0;i=t.time&&t.time>=a.currentTime-.1&&"wait"===t.$state}).forEach(function(t){t.$ref=function(t){var e=t.find(function(t){return t.$ref&&"wait"===t.$state});if(e){var n=e.$ref;return e.$ref=null,n}var i=document.createElement("div");return i.style.cssText='\n user-select: none;\n position: absolute;\n white-space: pre;\n pointer-events: none;\n perspective: 500px;\n display: inline-block;\n will-change: transform;\n font-family: SimHei, "Microsoft JhengHei", Arial, Helvetica, sans-serif;\n font-weight: normal;\n line-height: 1.125;\n text-shadow: rgb(0, 0, 0) 1px 0px 1px, rgb(0, 0, 0) 0px 1px 1px, rgb(0, 0, 0) 0px -1px 1px, rgb(0, 0, 0) -1px 0px 1px;\n ',i}(r.queue),r.$danmuku.appendChild(t.$ref),t.$ref.style.opacity=r.option.opacity,t.$ref.style.fontSize="".concat(r.option.fontSize,"px"),t.$ref.innerText=t.text,t.$ref.style.color=t.color,t.$ref.style.border=t.border?"1px solid ".concat(t.color):"none",t.$restTime=r.option.synchronousPlayback&&a.playbackRate?r.option.speed/Number(a.playbackRate):r.option.speed,t.$lastStartTime=Date.now();var e=f(t.$ref,"width"),n=g(r,t);switch(t.$state="emit",t.mode){case"scroll":t.$restWidth=i+e+5,t.$ref.style.left="".concat(i,"px"),t.$ref.style.top="".concat(n,"px"),t.$ref.style.transform="translateX(".concat(-t.$restWidth,"px) translateY(0px) translateZ(0px)"),t.$ref.style.transition="transform ".concat(t.$restTime,"s linear 0s");break;case"static":t.$ref.style.top="".concat(n,"px"),t.$ref.style.left="50%",t.$ref.style.marginLeft="-".concat(e/2,"px")}})}r.isStop||r.update()})}},{key:"stop",value:function(){this.isStop=!0,this.suspend(),window.cancelAnimationFrame(this.animationFrameTimer),this.art.emit("artplayerPluginDanmuku:stop")}},{key:"start",value:function(){this.isStop=!1,this.continue(),this.update(),this.art.emit("artplayerPluginDanmuku:start")}},{key:"show",value:function(){this.$danmuku.style="block",this.art.emit("artplayerPluginDanmuku:show")}},{key:"hide",value:function(){this.$danmuku.style="none",this.art.emit("artplayerPluginDanmuku:hide")}},{key:"emit",value:function(t){var e=this.art,n=e.notice,i=e.player,r=e.i18n;t.text.trim()?t.text.length>this.option.maxlength?n.show("".concat(r.get("The length of the danmu does not exceed")," ").concat(this.option.maxlength)):("number"!=typeof t.time&&(t.time=i.currentTime),this.queue.push(a({mode:"scroll"},t,{$state:"wait",$ref:null,$restTime:0,$lastStartTime:0,$restWidth:0}))):n.show(r.get("Danmu text cannot be empty"))}}],[{key:"option",get:function(){return{danmuku:[],speed:5,maxlength:50,margin:[10,100],opacity:1,fontSize:25,synchronousPlayback:!1}}},{key:"scheme",get:function(){return{danmuku:"array|function|string",speed:"number",maxlength:"number",margin:"array",opacity:"number",fontSize:"number",synchronousPlayback:"boolean"}}}]),r}();return function(n){return function(t){var e=new v(t,n);return{name:"artplayerPluginDanmuku",emit:e.emit.bind(e),config:e.config.bind(e),hide:e.hide.bind(e),show:e.show.bind(e)}}}});