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 4.3.13 to 4.3.14

.parcel-cache/27178d668d7e17f0

4

.parcel-cache/eaec4b5795941a45.txt

@@ -1,2 +0,2 @@

41695976
1651312593119393000
43675060
1651389600619332000
/*!
* artplayer-plugin-danmuku.js v4.3.13
* artplayer-plugin-danmuku.js v4.3.14
* Github: https://github.com/zhw2590582/ArtPlayer

@@ -7,2 +7,2 @@ * (c) 2017-2022 Harvey Zack

*/
!function(t,e,i,r,n){var s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},a="function"==typeof s.parcelRequire93cf&&s.parcelRequire93cf,o=a.cache||{},l="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function u(e,i){if(!o[e]){if(!t[e]){var r="function"==typeof s.parcelRequire93cf&&s.parcelRequire93cf;if(!i&&r)return r(e,!0);if(a)return a(e,!0);if(l&&"string"==typeof e)return l(e);var n=new Error("Cannot find module '"+e+"'");throw n.code="MODULE_NOT_FOUND",n}f.resolve=function(i){var r=t[e][1][i];return null!=r?r:i},f.cache={};var h=o[e]=new u.Module(e);t[e][0].call(h.exports,f,h,h.exports,this)}return o[e].exports;function f(t){var e=f.resolve(t);return!1===e?{}:u(e)}}u.isParcelRequire=!0,u.Module=function(t){this.id=t,this.bundle=u,this.exports={}},u.modules=t,u.cache=o,u.parent=a,u.register=function(e,i){t[e]=[function(t,e){e.exports=i},{}]},Object.defineProperty(u,"root",{get:function(){return s.parcelRequire93cf}}),s.parcelRequire93cf=u;for(var h=0;h<e.length;h++)u(e[h]);var f=u(i);"object"==typeof exports&&"undefined"!=typeof module?module.exports=f:"function"==typeof define&&define.amd&&define((function(){return f}))}({E13ST:[function(t,e,i){var r=t("@parcel/transformer-js/src/esmodule-helpers.js");r.defineInteropFlag(i);var n=t("./danmuku"),s=r.interopDefault(n);function a(t){return e=>{const i=new s.default(e,t);return{name:"artplayerPluginDanmuku",emit:i.emit.bind(i),config:i.config.bind(i),hide:i.hide.bind(i),show:i.show.bind(i),get isHide(){return i.isHide}}}}i.default=a,window.artplayerPluginDanmuku=a},{"./danmuku":"8Gtnh","@parcel/transformer-js/src/esmodule-helpers.js":"b7MJY"}],"8Gtnh":[function(t,e,i){var r=t("@parcel/transformer-js/src/esmodule-helpers.js");r.defineInteropFlag(i);var n=t("./i18n"),s=r.interopDefault(n),a=t("./bilibili"),o=t("./getDanmuTop"),l=r.interopDefault(o);class u{constructor(t,e){t.i18n.update(s.default),this.art=t,this.utils=t.constructor.utils,this.validator=t.constructor.validator,this.queue=[],this.option={},this.config(e),this.isStop=!1,this.isHide=!1,this.animationFrameTimer=null,this.$danmuku=t.template.$danmuku,t.on("video:play",this.start.bind(this)),t.on("video:playing",this.start.bind(this)),t.on("video:pause",this.stop.bind(this)),t.on("video:waiting",this.stop.bind(this)),t.on("resize",this.resize.bind(this)),t.on("destroy",this.stop.bind(this)),t.on("fullscreen",this.reset.bind(this)),t.on("fullscreenWeb",this.reset.bind(this)),this.load()}static get option(){return{danmuku:[],speed:5,margin:[10,100],opacity:1,fontSize:25,filter:()=>!0,synchronousPlayback:!1}}static get scheme(){return{danmuku:"array|function|string",speed:"number",margin:"array",opacity:"number",fontSize:"number",filter:"function",synchronousPlayback:"boolean"}}get isRotate(){return this.art.plugins.autoOrientation&&this.art.plugins.autoOrientation.state}get marginTop(){const{clamp:t}=this.utils,{$player:e}=this.art.template,i=this.option.margin[0];if("number"==typeof i)return t(i,0,e.clientHeight);if("string"==typeof i&&i.endsWith("%")){const r=parseFloat(i)/100;return t(e.clientHeight*r,0,e.clientHeight)}return u.option.margin[0]}get marginBottom(){const{clamp:t}=this.utils,{$player:e}=this.art.template,i=this.option.margin[1];if("number"==typeof i)return t(i,0,e.clientHeight);if("string"==typeof i&&i.endsWith("%")){const r=parseFloat(i)/100;return t(e.clientHeight*r,0,e.clientHeight)}return u.option.margin[1]}filter(t,e){return this.queue.filter((e=>e.$state===t)).map(e)}getRect(t,e){const i=t.getBoundingClientRect(),r=i.bottom,n=i.height,s=i.left,a=i.right,o=i.top,l=i.width,u=i.x,h=i.y,f={bottom:r,height:n,left:s,right:a,top:o,width:l,x:u,y:h};return this.isRotate&&(f.bottom=s,f.left=o,f.top=a,f.right=r,f.height=l,f.width=n,f.x=h,f.y=u),e?f[e]:f}getDanmuRef(){const t=this.queue.find((t=>t.$ref&&"wait"===t.$state));if(t){const{$ref:e}=t;return t.$ref=null,e}const e=document.createElement("div");return e.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 ',e}async load(){this.queue=[],this.$danmuku.innerText="";let t=[];try{t="function"==typeof this.option.danmuku?await this.option.danmuku():"function"==typeof this.option.danmuku.then?await this.option.danmuku:"string"==typeof this.option.danmuku?await a.bilibiliDanmuParseFromUrl(this.option.danmuku):this.option.danmuku,this.utils.errorHandle(Array.isArray(t),"Danmuku need return an array as result"),this.art.emit("artplayerPluginDanmuku:loaded",t),t.forEach(this.emit.bind(this))}catch(t){throw this.art.emit("artplayerPluginDanmuku:error",t),t}return this}config(t){const{clamp:e}=this.utils;return this.option=Object.assign({},u.option,this.option,t),this.validator(this.option,u.scheme),this.option.speed=e(this.option.speed,1,10),this.option.opacity=e(this.option.opacity,0,1),this.option.fontSize=e(this.option.fontSize,0,100),this.art.emit("artplayerPluginDanmuku:config",this.option),this}continue(){const{$player:t}=this.art.template,e=this.getRect(t,"width");return this.filter("stop",(t=>{switch(t.$state="emit",t.$ref.dataset.state="emit",t.$lastStartTime=Date.now(),t.mode){case 0:{const i=this.getRect(t.$ref,"width"),r=e+i;t.$ref.style.transform=`translateX(${-r}px) translateY(0px) translateZ(0px)`,t.$ref.style.transition=`transform ${t.$restTime}s linear 0s`;break}}})),this}suspend(){const{$player:t}=this.art.template;return this.filter("emit",(e=>{switch(e.$state="stop",e.$ref.dataset.state="stop",e.mode){case 0:{const{left:i,width:r}=this.getRect(t),{left:n}=this.getRect(e.$ref),s=r-(n-i);e.$ref.style.transform=`translateX(${-s}px) translateY(0px) translateZ(0px)`,e.$ref.style.transition="transform 0s linear 0s";break}}})),this}resize(){const{$player:t}=this.art.template,{width:e}=this.getRect(t);return this.filter("wait",(t=>{t.$ref&&(t.$ref.style.border="none",t.$ref.style.left=`${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")})),this}reset(){const{$player:t}=this.art.template,{width:e}=this.getRect(t);this.filter("emit",(t=>{t.$ref&&(t.$state="wait",t.$ref.dataset.state="wait",t.$ref.style.border="none",t.$ref.style.visibility="hidden",t.$ref.style.left=`${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")}))}update(){const{$player:t}=this.art.template;return this.animationFrameTimer=window.requestAnimationFrame((()=>{if(this.art.playing&&!this.isHide){const e=this.getRect(t,"width");this.filter("emit",(t=>{const i=(Date.now()-t.$lastStartTime)/1e3;t.$emitTime+=i,t.$restTime-=i,t.$lastStartTime=Date.now(),t.$restTime<=0&&(t.$state="wait",t.$ref.dataset.state="wait",t.$ref.style.border="none",t.$ref.style.visibility="hidden",t.$ref.style.left=`${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")})),this.queue.filter((t=>this.art.currentTime+.1>=t.time&&t.time>=this.art.currentTime-.1&&"wait"===t.$state)).forEach((t=>{t.$ref=this.getDanmuRef(this.queue),this.$danmuku.appendChild(t.$ref),t.$ref.style.visibility="visible",t.$ref.style.opacity=this.option.opacity,t.$ref.style.fontSize=`${this.option.fontSize||t.fontSize}px`,t.$ref.innerText=t.text,t.$ref.style.color=t.color||"#fff",t.$ref.style.border=t.border?`1px solid ${t.color||"#fff"}`:"none",t.$restTime=this.option.synchronousPlayback&&this.art.playbackRate?this.option.speed/Number(this.art.playbackRate):this.option.speed;const i=this.getRect(t.$ref,"width"),r=l.default(this,t);switch(t.$state="emit",t.$ref.dataset.state="emit",t.$lastStartTime=Date.now(),t.mode){case 0:{t.$ref.style.left=`${e}px`,t.$ref.style.top=`${r}px`;const n=e+i;t.$ref.style.transform=`translateX(${-n}px) translateY(0px) translateZ(0px)`,t.$ref.style.transition=`transform ${t.$restTime}s linear 0s`;break}case 1:t.$ref.style.top=`${r}px`,t.$ref.style.left="50%",t.$ref.style.marginLeft=`-${i/2}px`}}))}this.isStop||this.update()})),this}stop(){return this.isStop=!0,this.suspend(),window.cancelAnimationFrame(this.animationFrameTimer),this.art.emit("artplayerPluginDanmuku:stop"),this}start(){return this.isStop=!1,this.continue(),this.update(),this.art.emit("artplayerPluginDanmuku:start"),this}show(){return this.isHide=!1,this.$danmuku.style.display="block",this.art.emit("artplayerPluginDanmuku:show"),this}hide(){return this.isHide=!0,this.$danmuku.style.display="none",this.art.emit("artplayerPluginDanmuku:hide"),this}emit(t){return this.validator(t,{text:"string",mode:"number|undefined",color:"string|undefined",time:"number|undefined",border:"boolean|undefined"}),this.option.filter(t)&&t.text.trim()?(t.time?t.time=this.utils.clamp(t.time,0,1/0):t.time=this.art.currentTime+.5,this.queue.push({mode:0,...t,$state:"wait",$ref:null,$emitTime:0,$restTime:0,$lastStartTime:0}),this):this}}i.default=u},{"./i18n":"hcE1f","./bilibili":"KnwDr","./getDanmuTop":"2Abxf","@parcel/transformer-js/src/esmodule-helpers.js":"b7MJY"}],hcE1f:[function(t,e,i){t("@parcel/transformer-js/src/esmodule-helpers.js").defineInteropFlag(i),i.default={"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":"彈幕速度同步播放倍數"}}},{"@parcel/transformer-js/src/esmodule-helpers.js":"b7MJY"}],b7MJY:[function(t,e,i){i.interopDefault=function(t){return t&&t.__esModule?t:{default:t}},i.defineInteropFlag=function(t){Object.defineProperty(t,"__esModule",{value:!0})},i.exportAll=function(t,e){return Object.keys(t).forEach((function(i){"default"===i||"__esModule"===i||e.hasOwnProperty(i)||Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[i]}})})),e},i.export=function(t,e,i){Object.defineProperty(t,e,{enumerable:!0,get:i})}},{}],KnwDr:[function(t,e,i){var r=t("@parcel/transformer-js/src/esmodule-helpers.js");function n(t){switch(t){case 1:case 2:case 3:default:return 0;case 4:case 5:return 1}}function s(t){if("string"!=typeof t)return[];const e=t.match(/<d([\S ]*?>[\S ]*?)<\/d>/gi);return e&&e.length?e.map((t=>{const[,e,i]=t.match(/<d p="(.+)">(.+)<\/d>/),r=e.split(",");return 8===r.length&&i.trim()?{text:i,time:Number(r[0]),mode:n(Number(r[1])),fontSize:Number(r[2]),color:`#${Number(r[3]).toString(16)}`,timestamp:Number(r[4]),pool:Number(r[5]),userID:r[6],rowID:Number(r[7])}:null})):[]}function a(t){return fetch(t).then((t=>t.text())).then((t=>s(t)))}r.defineInteropFlag(i),r.export(i,"getMode",(()=>n)),r.export(i,"bilibiliDanmuParseFromXml",(()=>s)),r.export(i,"bilibiliDanmuParseFromUrl",(()=>a))},{"@parcel/transformer-js/src/esmodule-helpers.js":"b7MJY"}],"2Abxf":[function(t,e,i){t("@parcel/transformer-js/src/esmodule-helpers.js").defineInteropFlag(i),i.default=function(t,e){const{$player:i}=t.art.template,r=t.queue.filter((r=>r.$ref&&"emit"===r.$state&&r.mode===e.mode&&r.$ref.offsetTop<=i.clientHeight-t.marginBottom)).map((t=>({top:t.$ref.offsetTop,left:t.$ref.offsetLeft,height:t.$ref.clientHeight,width:t.$ref.clientWidth,right:i.clientWidth-t.$ref.offsetLeft-t.$ref.clientWidth}))).sort(((t,e)=>t.top-e.top));return 0===r.length?t.marginTop:(r.unshift({top:0,left:0,right:0,height:t.marginTop,width:i.clientWidth}),r.push({top:i.clientHeight-t.marginBottom,left:0,right:0,height:t.marginBottom,width:i.clientWidth}),function(t,e){for(let i=1;i<t.length;i+=1){const r=t[i],n=t[i-1],s=n.top+n.height;if(r.top-s>=e.$ref.clientHeight)return s}const i=[];for(let e=1;e<t.length-1;e+=1){const r=t[e];if(i.length){const t=i[i.length-1];t[0].top===r.top?t.push(r):i.push([r])}else i.push([r])}switch(e.mode){case 0:i.sort(((t,e)=>{const i=Math.min(...e.map((t=>t.right))),r=Math.min(...t.map((t=>t.right)));return i*e.length-r*t.length}));break;case 1:i.sort(((t,e)=>{const i=Math.max(...e.map((t=>t.width)));return Math.max(...t.map((t=>t.width)))*t.length-i*e.length}))}return i[0][0].top}(r,e))}},{"@parcel/transformer-js/src/esmodule-helpers.js":"b7MJY"}]},["E13ST"],"E13ST");
!function(t,e,i,r,n){var s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},o="function"==typeof s.parcelRequire93cf&&s.parcelRequire93cf,a=o.cache||{},l="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function u(e,i){if(!a[e]){if(!t[e]){var r="function"==typeof s.parcelRequire93cf&&s.parcelRequire93cf;if(!i&&r)return r(e,!0);if(o)return o(e,!0);if(l&&"string"==typeof e)return l(e);var n=new Error("Cannot find module '"+e+"'");throw n.code="MODULE_NOT_FOUND",n}p.resolve=function(i){var r=t[e][1][i];return null!=r?r:i},p.cache={};var h=a[e]=new u.Module(e);t[e][0].call(h.exports,p,h,h.exports,this)}return a[e].exports;function p(t){var e=p.resolve(t);return!1===e?{}:u(e)}}u.isParcelRequire=!0,u.Module=function(t){this.id=t,this.bundle=u,this.exports={}},u.modules=t,u.cache=a,u.parent=o,u.register=function(e,i){t[e]=[function(t,e){e.exports=i},{}]},Object.defineProperty(u,"root",{get:function(){return s.parcelRequire93cf}}),s.parcelRequire93cf=u;for(var h=0;h<e.length;h++)u(e[h]);var p=u(i);"object"==typeof exports&&"undefined"!=typeof module?module.exports=p:"function"==typeof define&&define.amd&&define((function(){return p}))}({E13ST:[function(t,e,i){var r=t("@parcel/transformer-js/src/esmodule-helpers.js");r.defineInteropFlag(i);var n=t("./danmuku"),s=r.interopDefault(n);function o(t){return e=>{const i=new s.default(e,t);return{name:"artplayerPluginDanmuku",emit:i.emit.bind(i),config:i.config.bind(i),hide:i.hide.bind(i),show:i.show.bind(i),get isHide(){return i.isHide}}}}i.default=o,window.artplayerPluginDanmuku=o},{"./danmuku":"8Gtnh","@parcel/transformer-js/src/esmodule-helpers.js":"b7MJY"}],"8Gtnh":[function(t,e,i){var r=t("@parcel/transformer-js/src/esmodule-helpers.js");r.defineInteropFlag(i);var n=t("./bilibili"),s=t("./getDanmuTop"),o=r.interopDefault(s);class a{constructor(t,e){this.art=t,this.utils=t.constructor.utils,this.validator=t.constructor.validator,this.queue=[],this.option={},this.config(e),this.isStop=!1,this.isHide=!1,this.animationFrameTimer=null,this.$danmuku=t.template.$danmuku,this.$player=t.template.$player,t.on("video:play",this.start.bind(this)),t.on("video:playing",this.start.bind(this)),t.on("video:pause",this.stop.bind(this)),t.on("video:waiting",this.stop.bind(this)),t.on("resize",this.resize.bind(this)),t.on("destroy",this.stop.bind(this)),t.on("fullscreen",this.reset.bind(this)),t.on("fullscreenWeb",this.reset.bind(this)),this.load()}static get option(){return{danmuku:[],speed:5,margin:[10,100],opacity:1,fontSize:25,filter:()=>!0,antiOverlap:!0,synchronousPlayback:!1}}static get scheme(){return{danmuku:"array|function|string",speed:"number",margin:"array",opacity:"number",fontSize:"number",filter:"function",antiOverlap:"boolean",synchronousPlayback:"boolean"}}get isRotate(){return this.art.plugins.autoOrientation&&this.art.plugins.autoOrientation.state}get marginTop(){const{clamp:t}=this.utils,{$player:e}=this.art.template,i=this.option.margin[0];if("number"==typeof i)return t(i,0,e.clientHeight);if("string"==typeof i&&i.endsWith("%")){const r=parseFloat(i)/100;return t(e.clientHeight*r,0,e.clientHeight)}return a.option.margin[0]}get marginBottom(){const{clamp:t}=this.utils,{$player:e}=this.art.template,i=this.option.margin[1];if("number"==typeof i)return t(i,0,e.clientHeight);if("string"==typeof i&&i.endsWith("%")){const r=parseFloat(i)/100;return t(e.clientHeight*r,0,e.clientHeight)}return a.option.margin[1]}filter(t,e){return this.queue.filter((e=>e.$state===t)).map(e)}getLeft(t){const e=t.getBoundingClientRect();return this.isRotate?e.top:e.left}getRef(){const t=this.queue.find((t=>t.$ref&&"wait"===t.$state));if(t){const{$ref:e}=t;return t.$ref=null,e}const e=document.createElement("div");return e.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-weight: normal;\n line-height: 1.125;\n visibility: hidden;\n font-family: SimHei, "Microsoft JhengHei", Arial, Helvetica, sans-serif;\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 ',e}getReady(t){const{$state:e,time:i}=t,{currentTime:r}=this.art;return"ready"===e||"wait"===e&&r+.1>=i&&i>=r-.1}async load(){try{let t=[];t="function"==typeof this.option.danmuku?await this.option.danmuku():"function"==typeof this.option.danmuku.then?await this.option.danmuku:"string"==typeof this.option.danmuku?await n.bilibiliDanmuParseFromUrl(this.option.danmuku):this.option.danmuku,this.utils.errorHandle(Array.isArray(t),"Danmuku need return an array as result"),this.art.emit("artplayerPluginDanmuku:loaded",t),this.queue=[],this.$danmuku.innerText="",t.forEach((t=>this.emit(t)))}catch(t){throw this.art.emit("artplayerPluginDanmuku:error",t),t}return this}config(t){const{clamp:e}=this.utils;return this.option=Object.assign({},a.option,this.option,t),this.validator(this.option,a.scheme),t.fontSize&&this.reset(),this.option.speed=e(this.option.speed,1,10),this.option.opacity=e(this.option.opacity,0,1),this.option.fontSize=e(this.option.fontSize,12,100),this.art.emit("artplayerPluginDanmuku:config",this.option),this}makeWait(t){t.$state="wait",t.$ref&&(t.$ref.style.border="none",t.$ref.style.visibility="hidden",t.$ref.style.marginLeft="0px",t.$ref.style.transform="translateX(0px)",t.$ref.style.transition="transform 0s linear 0s")}continue(){const{clientWidth:t}=this.$player;return this.filter("stop",(e=>{switch(e.$state="emit",e.$lastStartTime=Date.now(),e.mode){case 0:{const i=t+e.$ref.clientWidth;e.$ref.style.transform=`translateX(${-i}px)`,e.$ref.style.transition=`transform ${e.$restTime}s linear 0s`;break}}})),this}suspend(){const{clientWidth:t}=this.$player;return this.filter("emit",(e=>{switch(e.$state="stop",e.mode){case 0:{const i=t-(this.getLeft(e.$ref)-this.getLeft(this.$player));e.$ref.style.transform=`translateX(${-i}px)`,e.$ref.style.transition="transform 0s linear 0s";break}}})),this}resize(){return this}reset(){this.queue.forEach((t=>this.makeWait(t)))}update(){const{clientWidth:t}=this.$player;return this.animationFrameTimer=window.requestAnimationFrame((()=>{this.art.playing&&!this.isHide&&(this.filter("emit",(t=>{const e=(Date.now()-t.$lastStartTime)/1e3;t.$restTime-=e,t.$lastStartTime=Date.now(),t.$restTime<=0&&this.makeWait(t)})),this.queue.filter((t=>this.getReady(t))).forEach((e=>{e.$ref=this.getRef(),e.$ref.innerText=e.text,this.$danmuku.appendChild(e.$ref),e.$ref.style.left=`${t}px`,e.$ref.style.opacity=this.option.opacity,e.$ref.style.fontSize=`${this.option.fontSize}px`,e.$ref.style.color=e.color||"#fff",e.$ref.style.border=e.border?`1px solid ${e.color||"#fff"}`:"none",e.$ref.style.marginLeft="0px",e.$lastStartTime=Date.now(),e.$restTime=this.option.synchronousPlayback&&this.art.playbackRate?this.option.speed/Number(this.art.playbackRate):this.option.speed;const i=o.default(this,e);if(void 0!==i)switch(e.$state="emit",e.$ref.style.visibility="visible",e.mode){case 0:{e.$ref.style.top=`${i}px`;const r=t+e.$ref.clientWidth;e.$ref.style.transform=`translateX(${-r}px)`,e.$ref.style.transition=`transform ${e.$restTime}s linear 0s`;break}case 1:e.$ref.style.left="50%",e.$ref.style.top=`${i}px`,e.$ref.style.marginLeft=`-${e.$ref.clientWidth/2}px`}else e.$state="ready",this.$danmuku.removeChild(e.$ref)}))),this.isStop||this.update()})),this}stop(){return this.isStop=!0,this.suspend(),window.cancelAnimationFrame(this.animationFrameTimer),this.art.emit("artplayerPluginDanmuku:stop"),this}start(){return this.isStop=!1,this.continue(),this.update(),this.art.emit("artplayerPluginDanmuku:start"),this}show(){return this.isHide=!1,this.$danmuku.style.display="block",this.art.emit("artplayerPluginDanmuku:show"),this}hide(){return this.isHide=!0,this.$danmuku.style.display="none",this.art.emit("artplayerPluginDanmuku:hide"),this}emit(t){return this.validator(t,{text:"string",mode:"number|undefined",color:"string|undefined",time:"number|undefined",border:"boolean|undefined"}),t.text.trim()&&this.option.filter(t)?(t.time?t.time=this.utils.clamp(t.time,0,1/0):t.time=this.art.currentTime+.5,this.queue.push({mode:0,...t,$state:"wait",$ref:null,$restTime:0,$lastStartTime:0}),this):this}}i.default=a},{"./bilibili":"KnwDr","./getDanmuTop":"2Abxf","@parcel/transformer-js/src/esmodule-helpers.js":"b7MJY"}],KnwDr:[function(t,e,i){var r=t("@parcel/transformer-js/src/esmodule-helpers.js");function n(t){switch(t){case 1:case 2:case 3:default:return 0;case 4:case 5:return 1}}function s(t){if("string"!=typeof t)return[];const e=t.match(/<d([\S ]*?>[\S ]*?)<\/d>/gi);return e&&e.length?e.map((t=>{const[,e,i]=t.match(/<d p="(.+)">(.+)<\/d>/),r=e.split(",");return 8===r.length&&i.trim()?{text:i,time:Number(r[0]),mode:n(Number(r[1])),fontSize:Number(r[2]),color:`#${Number(r[3]).toString(16)}`,timestamp:Number(r[4]),pool:Number(r[5]),userID:r[6],rowID:Number(r[7])}:null})):[]}function o(t){return fetch(t).then((t=>t.text())).then((t=>s(t)))}r.defineInteropFlag(i),r.export(i,"getMode",(()=>n)),r.export(i,"bilibiliDanmuParseFromXml",(()=>s)),r.export(i,"bilibiliDanmuParseFromUrl",(()=>o))},{"@parcel/transformer-js/src/esmodule-helpers.js":"b7MJY"}],b7MJY:[function(t,e,i){i.interopDefault=function(t){return t&&t.__esModule?t:{default:t}},i.defineInteropFlag=function(t){Object.defineProperty(t,"__esModule",{value:!0})},i.exportAll=function(t,e){return Object.keys(t).forEach((function(i){"default"===i||"__esModule"===i||e.hasOwnProperty(i)||Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[i]}})})),e},i.export=function(t,e,i){Object.defineProperty(t,e,{enumerable:!0,get:i})}},{}],"2Abxf":[function(t,e,i){function r(t,e,i,r){const n=r.$ref.offsetTop,s=t.getLeft(r.$ref)-e,o=r.$ref.clientHeight,a=r.$ref.clientWidth,l=s+a,u=i-l,h=l/r.$restTime,p=r.mode,f=r.$restTime;return{$ref:r.$ref,mode:p,time:f,top:n,left:s,height:o,width:a,right:u,speed:h,distance:l}}t("@parcel/transformer-js/src/esmodule-helpers.js").defineInteropFlag(i),i.default=function(t,e){const i=t.getLeft(t.$player),{clientWidth:n,clientHeight:s}=t.$player,{antiOverlap:o}=t.option,{marginBottom:a,marginTop:l}=t,u=r(t,i,n,e),h=t.queue.filter((t=>t.$ref&&"emit"===t.$state&&t.mode===u.mode&&t.$ref.offsetTop<=s-a)).map((e=>r(t,i,n,e))).sort(((t,e)=>t.top-e.top));if(0===h.length)return l;h.unshift({top:0,left:0,right:0,height:l,width:n,speed:0,distance:n}),h.push({top:s-a,left:0,right:0,height:a,width:n,speed:0,distance:n});for(let t=1;t<h.length;t+=1){const e=h[t],i=h[t-1],r=i.top+i.height;if(e.top-r>=u.height)return r}const p=[];for(let t=1;t<h.length-1;t+=1){const e=h[t];if(p.length){const t=p[p.length-1];t[0].top===e.top?t.push(e):p.push([e])}else p.push([e])}if(!o){switch(u.mode){case 0:p.sort(((t,e)=>{const i=Math.min(...e.map((t=>t.right))),r=Math.min(...t.map((t=>t.right)));return i*e.length-r*t.length}));break;case 1:p.sort(((t,e)=>{const i=Math.max(...e.map((t=>t.width)));return Math.max(...t.map((t=>t.width)))*t.length-i*e.length}))}return p[0][0].top}switch(u.mode){case 0:{const t=p.find((t=>t.every((t=>{if(n<t.distance)return!1;if(u.speed<t.speed)return!0;return t.right/(u.speed-t.speed)>t.time}))));return t&&t[0]?t[0].top:void 0}case 1:return}}},{"@parcel/transformer-js/src/esmodule-helpers.js":"b7MJY"}]},["E13ST"],"E13ST");
{
"license": "MIT",
"version": "4.3.13",
"version": "4.3.14",
"name": "artplayer-plugin-danmuku",

@@ -5,0 +5,0 @@ "description": "Danmuku plugin for ArtPlayer",

@@ -1,2 +0,1 @@

import i18n from './i18n';
import { bilibiliDanmuParseFromUrl } from './bilibili';

@@ -7,3 +6,2 @@ import getDanmuTop from './getDanmuTop';

constructor(art, option) {
art.i18n.update(i18n);
this.art = art;

@@ -20,2 +18,3 @@ this.utils = art.constructor.utils;

this.$danmuku = art.template.$danmuku;
this.$player = art.template.$player;

@@ -42,2 +41,3 @@ art.on('video:play', this.start.bind(this));

filter: () => true,
antiOverlap: true,
synchronousPlayback: false,

@@ -55,2 +55,3 @@ };

filter: 'function',
antiOverlap: 'boolean',
synchronousPlayback: 'boolean',

@@ -102,40 +103,8 @@ };

getRect(ref, key) {
const rect = ref.getBoundingClientRect();
const bottom = rect.bottom;
const height = rect.height;
const left = rect.left;
const right = rect.right;
const top = rect.top;
const width = rect.width;
const x = rect.x;
const y = rect.y;
const result = {
bottom,
height,
left,
right,
top,
width,
x,
y,
};
if (this.isRotate) {
result.bottom = left;
result.left = top;
result.top = right;
result.right = bottom;
result.height = width;
result.width = height;
result.x = y;
result.y = x;
}
return key ? result[key] : result;
getLeft($ref) {
const rect = $ref.getBoundingClientRect();
return this.isRotate ? rect.top : rect.left;
}
getDanmuRef() {
getRef() {
const result = this.queue.find((danmu) => {

@@ -152,2 +121,3 @@ return danmu.$ref && danmu.$state === 'wait';

const $ref = document.createElement('div');
$ref.style.cssText = `

@@ -161,5 +131,6 @@ user-select: none;

will-change: transform;
font-family: SimHei, "Microsoft JhengHei", Arial, Helvetica, sans-serif;
font-weight: normal;
line-height: 1.125;
visibility: hidden;
font-family: SimHei, "Microsoft JhengHei", Arial, Helvetica, sans-serif;
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;

@@ -171,8 +142,11 @@ `;

getReady(danmu) {
const { $state, time } = danmu;
const { currentTime } = this.art;
return $state === 'ready' || ($state === 'wait' && currentTime + 0.1 >= time && time >= currentTime - 0.1);
}
async load() {
this.queue = [];
this.$danmuku.innerText = '';
let danmus = [];
try {
let danmus = [];
if (typeof this.option.danmuku === 'function') {

@@ -190,3 +164,6 @@ danmus = await this.option.danmuku();

this.art.emit('artplayerPluginDanmuku:loaded', danmus);
danmus.forEach(this.emit.bind(this));
this.queue = [];
this.$danmuku.innerText = '';
danmus.forEach((danmu) => this.emit(danmu));
} catch (error) {

@@ -205,6 +182,7 @@ this.art.emit('artplayerPluginDanmuku:error', error);

this.validator(this.option, Danmuku.scheme);
if (option.fontSize) this.reset();
this.option.speed = clamp(this.option.speed, 1, 10);
this.option.opacity = clamp(this.option.opacity, 0, 1);
this.option.fontSize = clamp(this.option.fontSize, 0, 100);
this.option.fontSize = clamp(this.option.fontSize, 12, 100);

@@ -216,15 +194,22 @@ this.art.emit('artplayerPluginDanmuku:config', this.option);

makeWait(danmu) {
danmu.$state = 'wait';
if (danmu.$ref) {
danmu.$ref.style.border = 'none';
danmu.$ref.style.visibility = 'hidden';
danmu.$ref.style.marginLeft = '0px';
danmu.$ref.style.transform = 'translateX(0px)';
danmu.$ref.style.transition = 'transform 0s linear 0s';
}
}
continue() {
const { $player } = this.art.template;
const playerWidth = this.getRect($player, 'width');
const { clientWidth } = this.$player;
this.filter('stop', (danmu) => {
danmu.$state = 'emit';
danmu.$ref.dataset.state = 'emit';
danmu.$lastStartTime = Date.now();
switch (danmu.mode) {
case 0: {
const danmuWidth = this.getRect(danmu.$ref, 'width');
const translateX = playerWidth + danmuWidth;
danmu.$ref.style.transform = `translateX(${-translateX}px) translateY(0px) translateZ(0px)`;
const translateX = clientWidth + danmu.$ref.clientWidth;
danmu.$ref.style.transform = `translateX(${-translateX}px)`;
danmu.$ref.style.transition = `transform ${danmu.$restTime}s linear 0s`;

@@ -242,13 +227,9 @@ break;

suspend() {
const { $player } = this.art.template;
const { clientWidth } = this.$player;
this.filter('emit', (danmu) => {
danmu.$state = 'stop';
danmu.$ref.dataset.state = 'stop';
switch (danmu.mode) {
case 0: {
const { left: playerLeft, width: playerWidth } = this.getRect($player);
const { left: danmuLeft } = this.getRect(danmu.$ref);
const translateX = playerWidth - (danmuLeft - playerLeft);
danmu.$ref.style.transform = `translateX(${-translateX}px) translateY(0px) translateZ(0px)`;
const translateX = clientWidth - (this.getLeft(danmu.$ref) - this.getLeft(this.$player));
danmu.$ref.style.transform = `translateX(${-translateX}px)`;
danmu.$ref.style.transition = 'transform 0s linear 0s';

@@ -266,15 +247,2 @@ break;

resize() {
const { $player } = this.art.template;
const { width: playerWidth } = this.getRect($player);
this.filter('wait', (danmu) => {
if (danmu.$ref) {
danmu.$ref.style.border = 'none';
danmu.$ref.style.left = `${playerWidth}px`;
danmu.$ref.style.marginLeft = '0px';
danmu.$ref.style.transform = 'translateX(0px) translateY(0px) translateZ(0px)';
danmu.$ref.style.transition = 'transform 0s linear 0s';
}
});
return this;

@@ -284,39 +252,15 @@ }

reset() {
const { $player } = this.art.template;
const { width: playerWidth } = this.getRect($player);
this.filter('emit', (danmu) => {
if (danmu.$ref) {
danmu.$state = 'wait';
danmu.$ref.dataset.state = 'wait';
danmu.$ref.style.border = 'none';
danmu.$ref.style.visibility = 'hidden';
danmu.$ref.style.left = `${playerWidth}px`;
danmu.$ref.style.marginLeft = '0px';
danmu.$ref.style.transform = 'translateX(0px) translateY(0px) translateZ(0px)';
danmu.$ref.style.transition = 'transform 0s linear 0s';
}
});
this.queue.forEach((danmu) => this.makeWait(danmu));
}
update() {
const { $player } = this.art.template;
const { clientWidth } = this.$player;
this.animationFrameTimer = window.requestAnimationFrame(() => {
if (this.art.playing && !this.isHide) {
const playerWidth = this.getRect($player, 'width');
this.filter('emit', (danmu) => {
const time = (Date.now() - danmu.$lastStartTime) / 1000;
danmu.$emitTime += time;
danmu.$restTime -= time;
const emitTime = (Date.now() - danmu.$lastStartTime) / 1000;
danmu.$restTime -= emitTime;
danmu.$lastStartTime = Date.now();
if (danmu.$restTime <= 0) {
danmu.$state = 'wait';
danmu.$ref.dataset.state = 'wait';
danmu.$ref.style.border = 'none';
danmu.$ref.style.visibility = 'hidden';
danmu.$ref.style.left = `${playerWidth}px`;
danmu.$ref.style.marginLeft = '0px';
danmu.$ref.style.transform = 'translateX(0px) translateY(0px) translateZ(0px)';
danmu.$ref.style.transition = 'transform 0s linear 0s';
this.makeWait(danmu);
}

@@ -326,17 +270,16 @@ });

this.queue
.filter(
(danmu) =>
this.art.currentTime + 0.1 >= danmu.time &&
danmu.time >= this.art.currentTime - 0.1 &&
danmu.$state === 'wait',
)
.filter((danmu) => this.getReady(danmu))
.forEach((danmu) => {
danmu.$ref = this.getDanmuRef(this.queue);
danmu.$ref = this.getRef();
danmu.$ref.innerText = danmu.text;
this.$danmuku.appendChild(danmu.$ref);
danmu.$ref.style.visibility = 'visible';
danmu.$ref.style.left = `${clientWidth}px`;
danmu.$ref.style.opacity = this.option.opacity;
danmu.$ref.style.fontSize = `${this.option.fontSize || danmu.fontSize}px`;
danmu.$ref.innerText = danmu.text;
danmu.$ref.style.fontSize = `${this.option.fontSize}px`;
danmu.$ref.style.color = danmu.color || '#fff';
danmu.$ref.style.border = danmu.border ? `1px solid ${danmu.color || '#fff'}` : 'none';
danmu.$ref.style.marginLeft = '0px';
danmu.$lastStartTime = Date.now();
danmu.$restTime =

@@ -346,23 +289,28 @@ this.option.synchronousPlayback && this.art.playbackRate

: this.option.speed;
const danmuWidth = this.getRect(danmu.$ref, 'width');
const danmuTop = getDanmuTop(this, danmu);
danmu.$state = 'emit';
danmu.$ref.dataset.state = 'emit';
danmu.$lastStartTime = Date.now();
switch (danmu.mode) {
case 0: {
danmu.$ref.style.left = `${playerWidth}px`;
danmu.$ref.style.top = `${danmuTop}px`;
const translateX = playerWidth + danmuWidth;
danmu.$ref.style.transform = `translateX(${-translateX}px) translateY(0px) translateZ(0px)`;
danmu.$ref.style.transition = `transform ${danmu.$restTime}s linear 0s`;
break;
const top = getDanmuTop(this, danmu);
if (top !== undefined) {
danmu.$state = 'emit';
danmu.$ref.style.visibility = 'visible';
switch (danmu.mode) {
case 0: {
danmu.$ref.style.top = `${top}px`;
const translateX = clientWidth + danmu.$ref.clientWidth;
danmu.$ref.style.transform = `translateX(${-translateX}px)`;
danmu.$ref.style.transition = `transform ${danmu.$restTime}s linear 0s`;
break;
}
case 1:
danmu.$ref.style.left = '50%';
danmu.$ref.style.top = `${top}px`;
danmu.$ref.style.marginLeft = `-${danmu.$ref.clientWidth / 2}px`;
break;
default:
break;
}
case 1:
danmu.$ref.style.top = `${danmuTop}px`;
danmu.$ref.style.left = '50%';
danmu.$ref.style.marginLeft = `-${danmuWidth / 2}px`;
break;
default:
break;
} else {
danmu.$state = 'ready';
this.$danmuku.removeChild(danmu.$ref);
}

@@ -418,4 +366,4 @@ });

if (!danmu.text.trim()) return this;
if (!this.option.filter(danmu)) return this;
if (!danmu.text.trim()) return this;

@@ -433,3 +381,2 @@ if (danmu.time) {

$ref: null,
$emitTime: 0,
$restTime: 0,

@@ -436,0 +383,0 @@ $lastStartTime: 0,

@@ -1,53 +0,33 @@

function calculatedTop(danmus, danmu) {
// 方法1:两两对比,只要找到间隔能塞进一条弹幕的高度的,则马上插入
for (let index = 1; index < danmus.length; index += 1) {
const item = danmus[index];
const prev = danmus[index - 1];
const prevBottom = prev.top + prev.height;
const diff = item.top - prevBottom;
if (diff >= danmu.$ref.clientHeight) {
return prevBottom;
}
}
function getData(ins, clientLeft, clientWidth, item) {
const top = item.$ref.offsetTop;
const left = ins.getLeft(item.$ref) - clientLeft;
const height = item.$ref.clientHeight;
const width = item.$ref.clientWidth;
const distance = left + width;
const right = clientWidth - distance;
const speed = distance / item.$restTime;
const mode = item.mode;
const time = item.$restTime;
const $ref = item.$ref;
// 方法2:找出所有弹幕的右侧最多空白的的位置插入
const topMap = [];
for (let index = 1; index < danmus.length - 1; index += 1) {
const item = danmus[index];
if (topMap.length) {
const last = topMap[topMap.length - 1];
if (last[0].top === item.top) {
last.push(item);
} else {
topMap.push([item]);
}
} else {
topMap.push([item]);
}
}
switch (danmu.mode) {
case 0:
topMap.sort((prev, next) => {
const nextMinRight = Math.min(...next.map((item) => item.right));
const prevMinRight = Math.min(...prev.map((item) => item.right));
return nextMinRight * next.length - prevMinRight * prev.length;
});
break;
case 1:
topMap.sort((prev, next) => {
const nextMaxWidth = Math.max(...next.map((item) => item.width));
const prevMaxWidth = Math.max(...prev.map((item) => item.width));
return prevMaxWidth * prev.length - nextMaxWidth * next.length;
});
break;
default:
break;
}
return topMap[0][0].top;
return {
$ref,
mode,
time,
top,
left,
height,
width,
right,
speed,
distance,
};
}
export default function getDanmuTop(ins, danmu) {
const { $player } = ins.art.template;
const clientLeft = ins.getLeft(ins.$player);
const { clientWidth, clientHeight } = ins.$player;
const { antiOverlap } = ins.option;
const { marginBottom, marginTop } = ins;
const target = getData(ins, clientLeft, clientWidth, danmu);

@@ -59,19 +39,11 @@ const danmus = ins.queue

item.$state === 'emit' &&
item.mode === danmu.mode &&
item.$ref.offsetTop <= $player.clientHeight - ins.marginBottom
item.mode === target.mode &&
item.$ref.offsetTop <= clientHeight - marginBottom
);
})
.map((item) => {
return {
top: item.$ref.offsetTop,
left: item.$ref.offsetLeft,
height: item.$ref.clientHeight,
width: item.$ref.clientWidth,
right: $player.clientWidth - item.$ref.offsetLeft - item.$ref.clientWidth,
};
})
.map((item) => getData(ins, clientLeft, clientWidth, item))
.sort((prev, next) => prev.top - next.top);
if (danmus.length === 0) {
return ins.marginTop;
return marginTop;
}

@@ -83,15 +55,85 @@

right: 0,
height: ins.marginTop,
width: $player.clientWidth,
height: marginTop,
width: clientWidth,
speed: 0,
distance: clientWidth,
});
danmus.push({
top: $player.clientHeight - ins.marginBottom,
top: clientHeight - marginBottom,
left: 0,
right: 0,
height: ins.marginBottom,
width: $player.clientWidth,
height: marginBottom,
width: clientWidth,
speed: 0,
distance: clientWidth,
});
return calculatedTop(danmus, danmu);
for (let index = 1; index < danmus.length; index += 1) {
const item = danmus[index];
const prev = danmus[index - 1];
const prevBottom = prev.top + prev.height;
const diff = item.top - prevBottom;
if (diff >= target.height) {
return prevBottom;
}
}
const topMap = [];
for (let index = 1; index < danmus.length - 1; index += 1) {
const item = danmus[index];
if (topMap.length) {
const last = topMap[topMap.length - 1];
if (last[0].top === item.top) {
last.push(item);
} else {
topMap.push([item]);
}
} else {
topMap.push([item]);
}
}
if (antiOverlap) {
switch (target.mode) {
case 0: {
const result = topMap.find((list) => {
return list.every((danmu) => {
if (clientWidth < danmu.distance) return false;
if (target.speed < danmu.speed) return true;
const overlapTime = danmu.right / (target.speed - danmu.speed);
if (overlapTime > danmu.time) return true;
return false;
});
});
return result && result[0] ? result[0].top : undefined;
}
case 1:
return undefined;
default:
break;
}
} else {
switch (target.mode) {
case 0:
topMap.sort((prev, next) => {
const nextMinRight = Math.min(...next.map((item) => item.right));
const prevMinRight = Math.min(...prev.map((item) => item.right));
return nextMinRight * next.length - prevMinRight * prev.length;
});
break;
case 1:
topMap.sort((prev, next) => {
const nextMaxWidth = Math.max(...next.map((item) => item.width));
const prevMaxWidth = Math.max(...prev.map((item) => item.width));
return prevMaxWidth * prev.length - nextMaxWidth * next.length;
});
break;
default:
break;
}
return topMap[0][0].top;
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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