Socket
Socket
Sign inDemoInstall

artplayer-plugin-danmuku

Package Overview
Dependencies
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

artplayer-plugin-danmuku - npm Package Compare versions

Comparing version 3.5.31 to 4.1.0

6

dist/artplayer-plugin-danmuku.js
/*!
* artplayer-plugin-danmuku.js v3.5.31
* artplayer-plugin-danmuku.js v4.1.0
* Github: https://github.com/zhw2590582/ArtPlayer#readme
* (c) 2017-2021 Harvey Zack
* (c) 2017-2022 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="undefined"!=typeof globalThis?globalThis:t||self).artplayerPluginDanmuku=e()}(this,(function(){"use strict";var t=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 e=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")};function n(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}var r=function(t,e,r){return e&&n(t.prototype,e),r&&n(t,r),t},i={"zh-cn":{"Danmu opacity":"弹幕透明度","Danmu speed":"弹幕速度","Danmu size":"弹幕大小","Danmu text cannot be empty":"弹幕文本不能为空","The length of the danmu does not exceed":"弹幕文本字数不能超过","Danmu speed synchronous playback multiple":"弹幕速度同步播放倍数"},"zh-tw":{"Danmu opacity":"彈幕透明度","Danmu speed":"彈幕速度","Danmu size":"弹幕大小","Danmu text cannot be empty":"彈幕文本不能為空","The length of the danmu does not exceed":"彈幕文本字數不能超過","Danmu speed synchronous playback multiple":"彈幕速度同步播放倍數"}};function a(t){var e=t.i18n,n=t.events.proxy;return{name:"danmuku-opacity",index:10,html:'<div class="art-setting-header">'.concat(e.get("Danmu opacity"),': <span class="art-value">100</span>%</div><div class="art-setting-range"><input type="range" value="1" min="0.1" max="1" step="0.1"></div>'),mounted:function(e){var r=e.querySelector("input[type=range]"),i=e.querySelector(".art-value");n(r,"change",(function(){var e=r.value;i.innerText=100*Number(e),t.plugins.artplayerPluginDanmuku.config({opacity:Number(e)})})),t.on("artplayerPluginDanmuku:config",(function(t){r.value!==t.opacity&&(r.value=t.opacity,i.innerText=100*t.opacity)}))}}}function o(t){var e=t.i18n,n=t.events.proxy;return{name:"danmuku-size",index:11,html:'<div class="art-setting-header">'.concat(e.get("Danmu size"),': <span class="art-value">25</span>px</div><div class="art-setting-range"><input type="range" value="25" min="14" max="30" step="1"></div>'),mounted:function(e){var r=e.querySelector("input[type=range]"),i=e.querySelector(".art-value");n(r,"change",(function(){var e=r.value;i.innerText=e,t.plugins.artplayerPluginDanmuku.config({fontSize:Number(e)})})),t.on("artplayerPluginDanmuku:config",(function(t){r.value!==t.fontSize&&(r.value=t.fontSize,i.innerText=t.fontSize)}))}}}function u(t){var e=t.i18n,n=t.events.proxy;return{name:"danmuku-speed",index:12,html:'<div class="art-setting-header">'.concat(e.get("Danmu speed"),': <span class="art-value">5</span>s</div><div class="art-setting-range"><input type="range" value="5" min="1" max="10" step="1"></div>'),mounted:function(e){var r=e.querySelector("input[type=range]"),i=e.querySelector(".art-value");n(r,"change",(function(){var e=r.value;i.innerText=e,t.plugins.artplayerPluginDanmuku.config({speed:Number(e)})})),t.on("artplayerPluginDanmuku:config",(function(t){r.value!==t.speed&&(r.value=t.speed,i.innerText=t.speed)}))}}}function s(t){var e=t.i18n,n=t.events.proxy;return{name:"danmuku-synchronousPlayback",index:13,html:'<label class="art-setting-checkbox"><input type="checkbox"/>'.concat(e.get("Danmu speed synchronous playback multiple"),"</label>"),mounted:function(e){var r=e.querySelector("input[type=checkbox]");n(r,"change",(function(){t.plugins.artplayerPluginDanmuku.config({synchronousPlayback:r.checked})})),t.on("artplayerPluginDanmuku:config",(function(t){r.checked!==t.synchronousPlayback&&(r.checked=t.synchronousPlayback)}))}}}function l(t,e,n){return t.filter((function(t){return t.$state===e})).map(n)}function c(t,e){var n=t.getBoundingClientRect();return e?n[e]:n}var p=function(t){if(Array.isArray(t))return t};var f=function(t,e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t)){var n=[],r=!0,i=!1,a=void 0;try{for(var o,u=t[Symbol.iterator]();!(r=(o=u.next()).done)&&(n.push(o.value),!e||n.length!==e);r=!0);}catch(t){i=!0,a=t}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}return n}};var h=function(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r};var m=function(t,e){if(t){if("string"==typeof t)return h(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?h(t,e):void 0}};var d=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")};var y=function(t,e){return p(t)||f(t,e)||m(t,e)||d()};function g(t){switch(t){case 1:case 2:case 3:return 0;case 4:case 5:return 1;default:return 0}}function v(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(/<d([\S ]*?>[\S ]*?)<\/d>/gi);return e&&e.length?e.map((function(t){var e=t.match(/<d p="(.+)">(.+)<\/d>/),n=y(e,3),r=n[1],i=n[2],a=r.split(",");return 8===a.length&&i.trim()?{text:i,time:Number(a[0]),mode:g(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 b(t,e){var n=y(t.option.margin,2),r=n[0],i=n[1],a=c(t.art.template.$player),o=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)<=a.height-i})).map((function(t){var e=c(t.$ref),n=e.width,r=e.height,i=e.top-a.top,o=e.left-a.left;return{top:i,left:o,height:r,width:n,right:a.width-o-n}})).sort((function(t,e){return t.top-e.top}));return 0===o.length?r:(o.unshift({top:0,left:0,right:0,height:r,width:a.width}),o.push({top:a.height-i,left:0,right:0,height:i,width:a.width}),function(t){for(var e=0,n={},r=0;r<t.length;r+=1){var i=t[r];n[i.top]?n[i.top].push(i):n[i.top]=[i]}for(var a=Object.keys(n),o=0,u=1;u<t.length;u+=1){var s=t[u],l=t[u-1],c=l.top+l.height,p=s.top-c;p>o&&(e=c,o=p)}if(0===e)for(var f=0,h=0;h<a.length;h+=1){for(var m=t[0].width,d=a[h],g=n[d],v=0;v<g.length;v+=1){var b=g[v];b.right<m&&(m=b.right)}m>f&&(f=m,e=y(g,1)[0].top)}if(0===e){var x=a.filter((function(t,e){return 0!==e&&e!==a.length-1})).sort((function(t,e){return n[t].length-n[e].length}));e=y(x,1)[0]}return e}(o))}function x(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function $(e){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?x(Object(r),!0).forEach((function(n){t(e,n,r[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):x(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var k=function(){function t(n,r){e(this,t),n.i18n.update(i),n.setting.add(a),n.setting.add(o),n.setting.add(u),n.setting.add(s),this.art=n,this.queue=[],this.option={},this.config(r),this.isStop=!1,this.isHide=!1,this.animationFrameTimer=null,this.$danmuku=n.template.$danmuku,n.on("video:play",this.start.bind(this)),n.on("video:playing",this.start.bind(this)),n.on("video:pause",this.stop.bind(this)),n.on("video:waiting",this.stop.bind(this)),n.on("resize",this.resize.bind(this)),n.on("destroy",this.stop.bind(this)),this.load()}return r(t,[{key:"load",value:function(){var t=this;return"function"==typeof this.option.danmuku?this.option.danmuku().then((function(e){t.queue=[],t.$danmuku.innerText="",e.forEach(t.emit.bind(t)),t.art.emit("artplayerPluginDanmuku:loaded")})):"string"==typeof this.option.danmuku?v(this.option.danmuku).then((function(e){t.queue=[],t.$danmuku.innerText="",e.forEach(t.emit.bind(t)),t.art.emit("artplayerPluginDanmuku:loaded")})):(this.queue=[],this.$danmuku.innerText="",this.option.danmuku.forEach(this.emit.bind(this)),this.art.emit("artplayerPluginDanmuku:loaded")),this}},{key:"config",value:function(e){var n=this.art.constructor,r=n.utils.clamp,i=n.validator;return this.option=Object.assign({},t.option,this.option,e),i(this.option,t.scheme),this.option.speed=r(this.option.speed,1,10),this.option.maxlength=r(this.option.maxlength,10,100),this.option.margin[0]=r(this.option.margin[0],0,100),this.option.margin[1]=r(this.option.margin[1],0,100),this.option.opacity=r(this.option.opacity,0,1),this.option.fontSize=r(this.option.fontSize,12,30),this.art.emit("artplayerPluginDanmuku:config",this.option),this}},{key:"continue",value:function(){return l(this.queue,"stop",(function(t){switch(t.$state="emit",t.$lastStartTime=Date.now(),t.mode){case 0:t.$ref.style.transform="translateX(".concat(-t.$restWidth,"px) translateY(0px) translateZ(0px)"),t.$ref.style.transition="transform ".concat(t.$restTime,"s linear 0s")}})),this}},{key:"suspend",value:function(){var t=this.art.template.$player;return l(this.queue,"emit",(function(e){switch(e.$state="stop",e.mode){case 0:var n=c(t),r=n.left,i=n.width-(c(e.$ref).left-r)+5;e.$ref.style.transform="translateX(".concat(-i,"px) translateY(0px) translateZ(0px)"),e.$ref.style.transition="transform 0s linear 0s"}})),this}},{key:"resize",value:function(){var t=c(this.art.template.$player,"width");return l(this.queue,"wait",(function(e){e.$ref&&(e.$ref.style.border="none",e.$ref.style.left="".concat(t,"px"),e.$ref.style.marginLeft="0px",e.$ref.style.transform="translateX(0px) translateY(0px) translateZ(0px)",e.$ref.style.transition="transform 0s linear 0s")})),this}},{key:"update",value:function(){var t=this,e=this.art,n=e.player,r=e.template.$player;return this.animationFrameTimer=window.requestAnimationFrame((function(){if(n.playing&&!t.isHide){var e=c(r,"width");l(t.queue,"emit",(function(t){t.$restTime-=(Date.now()-t.$lastStartTime)/1e3,t.$lastStartTime=Date.now(),t.$restTime<=0&&(t.$state="wait",t.$ref.style.border="none",t.$ref.style.left="".concat(e,"px"),t.$ref.style.marginLeft="0px",t.$ref.style.transform="translateX(0px) translateY(0px) translateZ(0px)",t.$ref.style.transition="transform 0s linear 0s")})),t.queue.filter((function(t){return n.currentTime+.1>=t.time&&t.time>=n.currentTime-.1&&"wait"===t.$state})).forEach((function(r){r.$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 r=document.createElement("div");return r.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 ',r}(t.queue),t.$danmuku.appendChild(r.$ref),r.$ref.style.opacity=t.option.opacity,r.$ref.style.fontSize="".concat(t.option.fontSize,"px"),r.$ref.innerText=r.text,r.$ref.style.color=r.color||"#fff",r.$ref.style.border=r.border?"1px solid ".concat(r.color||"#fff"):"none",r.$restTime=t.option.synchronousPlayback&&n.playbackRate?t.option.speed/Number(n.playbackRate):t.option.speed,r.$lastStartTime=Date.now();var i=c(r.$ref,"width"),a=b(t,r);switch(r.$state="emit",r.mode){case 0:r.$restWidth=e+i+5,r.$ref.style.left="".concat(e,"px"),r.$ref.style.top="".concat(a,"px"),r.$ref.style.transform="translateX(".concat(-r.$restWidth,"px) translateY(0px) translateZ(0px)"),r.$ref.style.transition="transform ".concat(r.$restTime,"s linear 0s");break;case 1:r.$ref.style.top="".concat(a,"px"),r.$ref.style.left="50%",r.$ref.style.marginLeft="-".concat(i/2,"px")}}))}t.isStop||t.update()})),this}},{key:"stop",value:function(){return this.isStop=!0,this.suspend(),window.cancelAnimationFrame(this.animationFrameTimer),this.art.emit("artplayerPluginDanmuku:stop"),this}},{key:"start",value:function(){return this.isStop=!1,this.continue(),this.update(),this.art.emit("artplayerPluginDanmuku:start"),this}},{key:"show",value:function(){return this.isHide=!1,this.$danmuku.style.display="block",this.art.emit("artplayerPluginDanmuku:show"),this}},{key:"hide",value:function(){return this.isHide=!0,this.$danmuku.style.display="none",this.art.emit("artplayerPluginDanmuku:hide"),this}},{key:"emit",value:function(t){var e=this.art,n=e.notice,r=e.player,i=e.i18n,a=this.art.constructor,o=a.utils.clamp;return(0,a.validator)(t,{text:"string",mode:"number|undefined",color:"string|undefined",time:"number|undefined",border:"boolean|undefined"}),t.text.trim()?t.text.length>this.option.maxlength?(n.show="".concat(i.get("The length of the danmu does not exceed")," ").concat(this.option.maxlength),this):(t.time?t.time=o(t.time,0,1/0):t.time=r.currentTime+.5,this.queue.push($($({mode:0},t),{},{$state:"wait",$ref:null,$restTime:0,$lastStartTime:0,$restWidth:0})),this):(n.show=i.get("Danmu text cannot be empty"),this)}}],[{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"}}}]),t}();return function(t){return function(e){var n=new k(e,t);return{name:"artplayerPluginDanmuku",emit:n.emit.bind(n),config:n.config.bind(n),hide:n.hide.bind(n),show:n.show.bind(n),get isHide(){return n.isHide}}}}}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).artplayerPluginDanmuku=e()}(this,(function(){"use strict";function t(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function e(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}var n={"zh-cn":{"Danmu opacity":"弹幕透明度","Danmu speed":"弹幕速度","Danmu size":"弹幕大小","Danmu text cannot be empty":"弹幕文本不能为空","The length of the danmu does not exceed":"弹幕文本字数不能超过","Danmu speed synchronous playback multiple":"弹幕速度同步播放倍数"},"zh-tw":{"Danmu opacity":"彈幕透明度","Danmu speed":"彈幕速度","Danmu size":"弹幕大小","Danmu text cannot be empty":"彈幕文本不能為空","The length of the danmu does not exceed":"彈幕文本字數不能超過","Danmu speed synchronous playback multiple":"彈幕速度同步播放倍數"}};function r(t){var e=t.i18n,n=t.events.proxy;return{name:"danmuku-opacity",index:10,html:'<div class="art-setting-header">'.concat(e.get("Danmu opacity"),': <span class="art-value">100</span>%</div><div class="art-setting-range"><input type="range" value="1" min="0.1" max="1" step="0.1"></div>'),mounted:function(e){var r=e.querySelector("input[type=range]"),i=e.querySelector(".art-value");n(r,"change",(function(){var e=r.value;i.innerText=100*Number(e),t.plugins.artplayerPluginDanmuku.config({opacity:Number(e)})})),t.on("artplayerPluginDanmuku:config",(function(t){r.value!==t.opacity&&(r.value=t.opacity,i.innerText=100*t.opacity)}))}}}function i(t){var e=t.i18n,n=t.events.proxy;return{name:"danmuku-size",index:11,html:'<div class="art-setting-header">'.concat(e.get("Danmu size"),': <span class="art-value">25</span>px</div><div class="art-setting-range"><input type="range" value="25" min="14" max="30" step="1"></div>'),mounted:function(e){var r=e.querySelector("input[type=range]"),i=e.querySelector(".art-value");n(r,"change",(function(){var e=r.value;i.innerText=e,t.plugins.artplayerPluginDanmuku.config({fontSize:Number(e)})})),t.on("artplayerPluginDanmuku:config",(function(t){r.value!==t.fontSize&&(r.value=t.fontSize,i.innerText=t.fontSize)}))}}}function a(t){var e=t.i18n,n=t.events.proxy;return{name:"danmuku-speed",index:12,html:'<div class="art-setting-header">'.concat(e.get("Danmu speed"),': <span class="art-value">5</span>s</div><div class="art-setting-range"><input type="range" value="5" min="1" max="10" step="1"></div>'),mounted:function(e){var r=e.querySelector("input[type=range]"),i=e.querySelector(".art-value");n(r,"change",(function(){var e=r.value;i.innerText=e,t.plugins.artplayerPluginDanmuku.config({speed:Number(e)})})),t.on("artplayerPluginDanmuku:config",(function(t){r.value!==t.speed&&(r.value=t.speed,i.innerText=t.speed)}))}}}function o(t){var e=t.i18n,n=t.events.proxy;return{name:"danmuku-synchronousPlayback",index:13,html:'<label class="art-setting-checkbox"><input type="checkbox"/>'.concat(e.get("Danmu speed synchronous playback multiple"),"</label>"),mounted:function(e){var r=e.querySelector("input[type=checkbox]");n(r,"change",(function(){t.plugins.artplayerPluginDanmuku.config({synchronousPlayback:r.checked})})),t.on("artplayerPluginDanmuku:config",(function(t){r.checked!==t.synchronousPlayback&&(r.checked=t.synchronousPlayback)}))}}}function u(t,e,n){return t.filter((function(t){return t.$state===e})).map(n)}function s(t,e){var n=t.getBoundingClientRect();return e?n[e]:n}function l(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function c(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var r,i,a=[],o=!0,u=!1;try{for(n=n.call(t);!(o=(r=n.next()).done)&&(a.push(r.value),!e||a.length!==e);o=!0);}catch(t){u=!0,i=t}finally{try{o||null==n.return||n.return()}finally{if(u)throw i}}return a}}(t,e)||function(t,e){if(t){if("string"==typeof t)return l(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?l(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function p(t){switch(t){case 1:case 2:case 3:default:return 0;case 4:case 5:return 1}}function f(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(/<d([\S ]*?>[\S ]*?)<\/d>/gi);return e&&e.length?e.map((function(t){var e=c(t.match(/<d p="(.+)">(.+)<\/d>/),3),n=e[1],r=e[2],i=n.split(",");return 8===i.length&&r.trim()?{text:r,time:Number(i[0]),mode:p(Number(i[1])),fontSize:Number(i[2]),color:"#".concat(Number(i[3]).toString(16)),timestamp:Number(i[4]),pool:Number(i[5]),userID:i[6],rowID:Number(i[7])}:null})):[]}(t)}))}function h(t,e){var n=c(t.option.margin,2),r=n[0],i=n[1],a=s(t.art.template.$player),o=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)<=a.height-i})).map((function(t){var e=s(t.$ref),n=e.width,r=e.height,i=e.top-a.top,o=e.left-a.left;return{top:i,left:o,height:r,width:n,right:a.width-o-n}})).sort((function(t,e){return t.top-e.top}));return 0===o.length?r:(o.unshift({top:0,left:0,right:0,height:r,width:a.width}),o.push({top:a.height-i,left:0,right:0,height:i,width:a.width}),function(t){for(var e=0,n={},r=0;r<t.length;r+=1){var i=t[r];n[i.top]?n[i.top].push(i):n[i.top]=[i]}for(var a=Object.keys(n),o=0,u=1;u<t.length;u+=1){var s=t[u],l=t[u-1],p=l.top+l.height,f=s.top-p;f>o&&(e=p,o=f)}if(0===e)for(var h=0,m=0;m<a.length;m+=1){for(var d=t[0].width,y=a[m],g=n[y],v=0;v<g.length;v+=1){var b=g[v];b.right<d&&(d=b.right)}d>h&&(h=d,e=c(g,1)[0].top)}if(0===e){var x=a.filter((function(t,e){return 0!==e&&e!==a.length-1})).sort((function(t,e){return n[t].length-n[e].length}));e=c(x,1)[0]}return e}(o))}function m(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function d(e){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?m(Object(r),!0).forEach((function(n){t(e,n,r[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):m(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var y=function(){function t(e,u){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),e.i18n.update(n),e.setting.add(r),e.setting.add(i),e.setting.add(a),e.setting.add(o),this.art=e,this.queue=[],this.option={},this.config(u),this.isStop=!1,this.isHide=!1,this.animationFrameTimer=null,this.$danmuku=e.template.$danmuku,e.on("video:play",this.start.bind(this)),e.on("video:playing",this.start.bind(this)),e.on("video:pause",this.stop.bind(this)),e.on("video:waiting",this.stop.bind(this)),e.on("resize",this.resize.bind(this)),e.on("destroy",this.stop.bind(this)),this.load()}var l,c,p;return l=t,c=[{key:"load",value:function(){var t=this;return"function"==typeof this.option.danmuku?this.option.danmuku().then((function(e){t.queue=[],t.$danmuku.innerText="",e.forEach(t.emit.bind(t)),t.art.emit("artplayerPluginDanmuku:loaded")})):"string"==typeof this.option.danmuku?f(this.option.danmuku).then((function(e){t.queue=[],t.$danmuku.innerText="",e.forEach(t.emit.bind(t)),t.art.emit("artplayerPluginDanmuku:loaded")})):(this.queue=[],this.$danmuku.innerText="",this.option.danmuku.forEach(this.emit.bind(this)),this.art.emit("artplayerPluginDanmuku:loaded")),this}},{key:"config",value:function(e){var n=this.art.constructor,r=n.utils.clamp,i=n.validator;return this.option=Object.assign({},t.option,this.option,e),i(this.option,t.scheme),this.option.speed=r(this.option.speed,1,10),this.option.maxlength=r(this.option.maxlength,10,100),this.option.margin[0]=r(this.option.margin[0],0,100),this.option.margin[1]=r(this.option.margin[1],0,100),this.option.opacity=r(this.option.opacity,0,1),this.option.fontSize=r(this.option.fontSize,12,30),this.art.emit("artplayerPluginDanmuku:config",this.option),this}},{key:"continue",value:function(){return u(this.queue,"stop",(function(t){t.$state="emit",t.$lastStartTime=Date.now(),0===t.mode&&(t.$ref.style.transform="translateX(".concat(-t.$restWidth,"px) translateY(0px) translateZ(0px)"),t.$ref.style.transition="transform ".concat(t.$restTime,"s linear 0s"))})),this}},{key:"suspend",value:function(){var t=this.art.template.$player;return u(this.queue,"emit",(function(e){if(e.$state="stop",0===e.mode){var n=s(t),r=n.left,i=n.width-(s(e.$ref).left-r)+5;e.$ref.style.transform="translateX(".concat(-i,"px) translateY(0px) translateZ(0px)"),e.$ref.style.transition="transform 0s linear 0s"}})),this}},{key:"resize",value:function(){var t=s(this.art.template.$player,"width");return u(this.queue,"wait",(function(e){e.$ref&&(e.$ref.style.border="none",e.$ref.style.left="".concat(t,"px"),e.$ref.style.marginLeft="0px",e.$ref.style.transform="translateX(0px) translateY(0px) translateZ(0px)",e.$ref.style.transition="transform 0s linear 0s")})),this}},{key:"update",value:function(){var t=this,e=this.art.template.$player;return this.animationFrameTimer=window.requestAnimationFrame((function(){if(t.art.playing&&!t.isHide){var n=s(e,"width");u(t.queue,"emit",(function(t){t.$restTime-=(Date.now()-t.$lastStartTime)/1e3,t.$lastStartTime=Date.now(),t.$restTime<=0&&(t.$state="wait",t.$ref.style.border="none",t.$ref.style.left="".concat(n,"px"),t.$ref.style.marginLeft="0px",t.$ref.style.transform="translateX(0px) translateY(0px) translateZ(0px)",t.$ref.style.transition="transform 0s linear 0s")})),t.queue.filter((function(e){return t.art.currentTime+.1>=e.time&&e.time>=t.art.currentTime-.1&&"wait"===e.$state})).forEach((function(e){e.$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 r=document.createElement("div");return r.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 ',r}(t.queue),t.$danmuku.appendChild(e.$ref),e.$ref.style.opacity=t.option.opacity,e.$ref.style.fontSize="".concat(t.option.fontSize,"px"),e.$ref.innerText=e.text,e.$ref.style.color=e.color||"#fff",e.$ref.style.border=e.border?"1px solid ".concat(e.color||"#fff"):"none",e.$restTime=t.option.synchronousPlayback&&t.art.playbackRate?t.option.speed/Number(t.art.playbackRate):t.option.speed,e.$lastStartTime=Date.now();var r=s(e.$ref,"width"),i=h(t,e);switch(e.$state="emit",e.mode){case 0:e.$restWidth=n+r+5,e.$ref.style.left="".concat(n,"px"),e.$ref.style.top="".concat(i,"px"),e.$ref.style.transform="translateX(".concat(-e.$restWidth,"px) translateY(0px) translateZ(0px)"),e.$ref.style.transition="transform ".concat(e.$restTime,"s linear 0s");break;case 1:e.$ref.style.top="".concat(i,"px"),e.$ref.style.left="50%",e.$ref.style.marginLeft="-".concat(r/2,"px")}}))}t.isStop||t.update()})),this}},{key:"stop",value:function(){return this.isStop=!0,this.suspend(),window.cancelAnimationFrame(this.animationFrameTimer),this.art.emit("artplayerPluginDanmuku:stop"),this}},{key:"start",value:function(){return this.isStop=!1,this.continue(),this.update(),this.art.emit("artplayerPluginDanmuku:start"),this}},{key:"show",value:function(){return this.isHide=!1,this.$danmuku.style.display="block",this.art.emit("artplayerPluginDanmuku:show"),this}},{key:"hide",value:function(){return this.isHide=!0,this.$danmuku.style.display="none",this.art.emit("artplayerPluginDanmuku:hide"),this}},{key:"emit",value:function(t){var e=this.art,n=e.notice,r=e.i18n,i=this.art.constructor,a=i.utils.clamp;return(0,i.validator)(t,{text:"string",mode:"number|undefined",color:"string|undefined",time:"number|undefined",border:"boolean|undefined"}),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),this):(t.time?t.time=a(t.time,0,1/0):t.time=this.art.currentTime+.5,this.queue.push(d(d({mode:0},t),{},{$state:"wait",$ref:null,$restTime:0,$lastStartTime:0,$restWidth:0})),this):(n.show=r.get("Danmu text cannot be empty"),this)}}],p=[{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"}}}],c&&e(l.prototype,c),p&&e(l,p),t}();return function(t){return function(e){var n=new y(e,t);return{name:"artplayerPluginDanmuku",emit:n.emit.bind(n),config:n.config.bind(n),hide:n.hide.bind(n),show:n.show.bind(n),get isHide(){return n.isHide}}}}}));
{
"name": "artplayer-plugin-danmuku",
"version": "3.5.31",
"version": "4.1.0",
"expose": "artplayerPluginDanmuku",

@@ -24,3 +24,3 @@ "description": "Danmuku plugin for ArtPlayer",

"homepage": "https://github.com/zhw2590582/ArtPlayer#readme",
"gitHead": "af1a116a31b088efdd77afa81c4b6565d12bd162"
"gitHead": "5ea211ef738351668e4acace326af4ff6947e2ee"
}

@@ -148,8 +148,5 @@ import i18n from './i18n';

update() {
const {
player,
template: { $player },
} = this.art;
const { $player } = this.art.template;
this.animationFrameTimer = window.requestAnimationFrame(() => {
if (player.playing && !this.isHide) {
if (this.art.playing && !this.isHide) {
const danmuLeft = getRect($player, 'width');

@@ -173,4 +170,4 @@

(danmu) =>
player.currentTime + 0.1 >= danmu.time &&
danmu.time >= player.currentTime - 0.1 &&
this.art.currentTime + 0.1 >= danmu.time &&
danmu.time >= this.art.currentTime - 0.1 &&
danmu.$state === 'wait',

@@ -187,4 +184,4 @@ )

danmu.$restTime =
this.option.synchronousPlayback && player.playbackRate
? this.option.speed / Number(player.playbackRate)
this.option.synchronousPlayback && this.art.playbackRate
? this.option.speed / Number(this.art.playbackRate)
: this.option.speed;

@@ -253,3 +250,4 @@ danmu.$lastStartTime = Date.now();

emit(danmu) {
const { notice, player, i18n } = this.art;
const { notice, i18n } = this.art;
const {

@@ -281,3 +279,3 @@ utils: { clamp },

} else {
danmu.time = player.currentTime + 0.5;
danmu.time = this.art.currentTime + 0.5;
}

@@ -284,0 +282,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc