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.12 to 4.3.13

.parcel-cache/91a4078b52a7fea4

4

.parcel-cache/eaec4b5795941a45.txt

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

40945239
1651281265625488000
41695976
1651312593119393000
/*!
* artplayer-plugin-danmuku.js v4.3.12
* artplayer-plugin-danmuku.js v4.3.13
* 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}h.resolve=function(i){var r=t[e][1][i];return null!=r?r:i},h.cache={};var f=o[e]=new u.Module(e);t[e][0].call(f.exports,h,f,f.exports,this)}return o[e].exports;function h(t){var e=h.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 f=0;f<e.length;f++)u(e[f]);var h=u(i);"object"==typeof exports&&"undefined"!=typeof module?module.exports=h:"function"==typeof define&&define.amd&&define((function(){return h}))}({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,f=i.y,h={bottom:r,height:n,left:s,right:a,top:o,width:l,x:u,y:f};return this.isRotate&&(h.bottom=s,h.left=o,h.top=a,h.right=r,h.height=l,h.width=n,h.x=f,h.y=u),e?h[e]:h}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,12,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}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.mode===e.mode&&"emit"===r.$state&&r.$ref&&r.$ref.style.fontSize===e.$ref.style.fontSize&&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){for(let e=1;e<t.length;e+=1){const i=t[e],r=t[e-1],n=r.top+r.height;if(i.top-n>=t[1].height)return n}const e=[];for(let i=1;i<t.length-1;i+=1){const r=t[i];if(e.length){const t=e[e.length-1];t[0].top===r.top?t.push(r):e.push([r])}else e.push([r])}return e.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})),e[0][0].top}(r))}},{"@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:{},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");
{
"license": "MIT",
"version": "4.3.12",
"version": "4.3.13",
"name": "artplayer-plugin-danmuku",

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

@@ -199,3 +199,3 @@ import i18n from './i18n';

this.option.opacity = clamp(this.option.opacity, 0, 1);
this.option.fontSize = clamp(this.option.fontSize, 12, 100);
this.option.fontSize = clamp(this.option.fontSize, 0, 100);

@@ -324,3 +324,3 @@ this.art.emit('artplayerPluginDanmuku:config', this.option);

danmu.$ref.style.opacity = this.option.opacity;
danmu.$ref.style.fontSize = `${this.option.fontSize}px`;
danmu.$ref.style.fontSize = `${this.option.fontSize || danmu.fontSize}px`;
danmu.$ref.innerText = danmu.text;

@@ -327,0 +327,0 @@ danmu.$ref.style.color = danmu.color || '#fff';

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

function calculatedTop(danmus) {
function calculatedTop(danmus, danmu) {
// 方法1:两两对比,只要找到间隔能塞进一条弹幕的高度的,则马上插入

@@ -8,3 +8,3 @@ for (let index = 1; index < danmus.length; index += 1) {

const diff = item.top - prevBottom;
if (diff >= danmus[1].height) {
if (diff >= danmu.$ref.clientHeight) {
return prevBottom;

@@ -30,7 +30,20 @@ }

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;
});
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;
}

@@ -46,6 +59,5 @@ return topMap[0][0].top;

return (
item.$ref &&
item.$state === 'emit' &&
item.mode === danmu.mode &&
item.$state === 'emit' &&
item.$ref &&
item.$ref.style.fontSize === danmu.$ref.style.fontSize &&
item.$ref.offsetTop <= $player.clientHeight - ins.marginBottom

@@ -85,3 +97,3 @@ );

return calculatedTop(danmus);
return calculatedTop(danmus, danmu);
}

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

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