/*! * artplayer-plugin-danmuku.js v4.3.23 * Github: https://github.com/zhw2590582/ArtPlayer * (c) 2017-2022 Harvey Zack * Released under the MIT License. */ !function(t,e,i,n,s){var r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},o="function"==typeof r.parcelRequire93cf&&r.parcelRequire93cf,a=o.cache||{},l="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function h(e,i){if(!a[e]){if(!t[e]){var n="function"==typeof r.parcelRequire93cf&&r.parcelRequire93cf;if(!i&&n)return n(e,!0);if(o)return o(e,!0);if(l&&"string"==typeof e)return l(e);var s=new Error("Cannot find module '"+e+"'");throw s.code="MODULE_NOT_FOUND",s}u.resolve=function(i){var n=t[e][1][i];return null!=n?n:i},u.cache={};var c=a[e]=new h.Module(e);t[e][0].call(c.exports,u,c,c.exports,this)}return a[e].exports;function u(t){var e=u.resolve(t);return!1===e?{}:h(e)}}h.isParcelRequire=!0,h.Module=function(t){this.id=t,this.bundle=h,this.exports={}},h.modules=t,h.cache=a,h.parent=o,h.register=function(e,i){t[e]=[function(t,e){e.exports=i},{}]},Object.defineProperty(h,"root",{get:function(){return r.parcelRequire93cf}}),r.parcelRequire93cf=h;for(var c=0;c{const i=new r.default(e,t);return a.default(e,i),{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},get isStop(){return i.isStop}}}}i.default=l,window.artplayerPluginDanmuku=l},{"./danmuku":"8Gtnh","@parcel/transformer-js/src/esmodule-helpers.js":"b7MJY","./setting":"jAkJm"}],"8Gtnh":[function(t,e,i){var n=t("@parcel/transformer-js/src/esmodule-helpers.js");n.defineInteropFlag(i);var s=t("./bilibili"),r=t("./getDanmuTop"),o=n.interopDefault(r);class a{constructor(e,i){const{constructor:n,template:s}=e;if(this.utils=n.utils,this.validator=n.validator,this.$danmuku=s.$danmuku,this.$player=s.$player,this.art=e,this.queue=[],this.option={},this.$refs=[],this.isStop=!1,this.isHide=!1,this.timer=null,this.config(i),this.option.useWorker)try{this.worker=new Worker(t("85d40535eae5f839"))}catch(t){}this.start=this.start.bind(this),this.stop=this.stop.bind(this),this.reset=this.reset.bind(this),this.destroy=this.destroy.bind(this),e.on("video:play",this.start),e.on("video:playing",this.start),e.on("video:pause",this.stop),e.on("video:waiting",this.stop),e.on("fullscreen",this.reset),e.on("fullscreenWeb",this.reset),e.on("destroy",this.destroy),this.load()}static get option(){return{danmuku:[],speed:5,margin:["2%","25%"],opacity:1,fontSize:25,filter:()=>!0,antiOverlap:!0,useWorker:!0,synchronousPlayback:!1}}static get scheme(){return{danmuku:"array|function|string",speed:"number",margin:"array",opacity:"number",fontSize:"number|string",filter:"function",antiOverlap:"boolean",useWorker:"boolean",synchronousPlayback:"boolean"}}get isRotate(){return this.art.plugins.autoOrientation&&this.art.plugins.autoOrientation.state}get marginTop(){const{clamp:t}=this.utils,e=this.option.margin[0],{clientHeight:i}=this.$player;if("number"==typeof e)return t(e,0,i);if("string"==typeof e&&e.endsWith("%")){return t(i*(parseFloat(e)/100),0,i)}return a.option.margin[0]}get marginBottom(){const{clamp:t}=this.utils,e=this.option.margin[1],{clientHeight:i}=this.$player;if("number"==typeof e)return t(e,0,i);if("string"==typeof e&&e.endsWith("%")){return t(i*(parseFloat(e)/100),0,i)}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.$refs.pop();if(t)return t;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(){const{currentTime:t}=this.art;return this.queue.filter((e=>"ready"===e.$state||"wait"===e.$state&&t+.1>=e.time&&e.time>=t-.1))}getEmits(){const t=[],{clientWidth:e}=this.$player,i=this.getLeft(this.$player);return this.filter("emit",(n=>{const s=n.$ref.offsetTop,r=this.getLeft(n.$ref)-i,o=n.$ref.clientHeight,a=n.$ref.clientWidth,l=r+a,h=e-l,c=l/n.$restTime,u={};u.top=s,u.left=r,u.height=o,u.width=a,u.right=h,u.speed=c,u.distance=l,u.time=n.$restTime,u.mode=n.mode,t.push(u)})),t}getFontSize(t){const{clamp:e}=this.utils,{clientHeight:i}=this.$player;if("number"==typeof t)return e(t,12,i);if("string"==typeof t&&t.endsWith("%")){return e(i*(parseFloat(t)/100),12,i)}return a.option.fontSize}postMessage(t={}){return new Promise((e=>{if(this.option.useWorker&&this.worker&&this.worker.postMessage)t.id=Date.now(),this.worker.postMessage(t),this.worker.onmessage=i=>{const{data:n}=i;n.id===t.id&&e(n)};else{const i=o.default(t);e({top:i})}}))}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 s.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),this.option.speed=e(this.option.speed,1,10),this.option.opacity=e(this.option.opacity,0,1),t.fontSize&&(this.option.fontSize=this.getFontSize(this.option.fontSize),this.reset()),this.art.emit("artplayerPluginDanmuku:config",this.option),this}makeWait(t){t.$state="wait",t.$ref&&(t.$ref.style.visibility="hidden",t.$ref.style.marginLeft="0px",t.$ref.style.transform="translateX(0px)",t.$ref.style.transition="transform 0s linear 0s",this.$refs.push(t.$ref),t.$ref=null)}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}reset(){return this.queue.forEach((t=>this.makeWait(t))),this}update(){return this.timer=window.requestAnimationFrame((async()=>{if(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)}));const t=this.getReady(),{clientWidth:e,clientHeight:i}=this.$player;for(let n=0;nthis.makeWait(t))),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}destroy(){this.stop(),this.worker&&this.worker.terminate&&this.worker.terminate(),this.art.off("video:play",this.start),this.art.off("video:playing",this.start),this.art.off("video:pause",this.stop),this.art.off("video:waiting",this.stop),this.art.off("fullscreen",this.reset),this.art.off("fullscreenWeb",this.reset),this.art.off("destroy",this.destroy),this.art.emit("artplayerPluginDanmuku:destroy")}}i.default=a},{"./bilibili":"KnwDr","@parcel/transformer-js/src/esmodule-helpers.js":"b7MJY","85d40535eae5f839":"5sXKb","./getDanmuTop":"2Abxf"}],KnwDr:[function(t,e,i){var n=t("@parcel/transformer-js/src/esmodule-helpers.js");function s(t){switch(t){case 1:case 2:case 3:default:return 0;case 4:case 5:return 1}}function r(t){if("string"!=typeof t)return[];const e=t.match(/[\S ]*?)<\/d>/gi);return e&&e.length?e.map((t=>{const[,e,i]=t.match(/(.+)<\/d>/),n=e.split(",");return 8===n.length&&i.trim()?{text:i,time:Number(n[0]),mode:s(Number(n[1])),fontSize:Number(n[2]),color:`#${Number(n[3]).toString(16)}`,timestamp:Number(n[4]),pool:Number(n[5]),userID:n[6],rowID:Number(n[7])}:null})):[]}function o(t){return fetch(t).then((t=>t.text())).then((t=>r(t)))}n.defineInteropFlag(i),n.export(i,"getMode",(()=>s)),n.export(i,"bilibiliDanmuParseFromXml",(()=>r)),n.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})}},{}],"5sXKb":[function(t,e,i){e.exports="data:application/javascript,function%20getDanmuTop%28%7Btarget%3At%2Cemits%3Ae%2CclientWidth%3An%2CclientHeight%3Ai%2CmarginBottom%3As%2CmarginTop%3Ah%2CantiOverlap%3Ao%7D%29%7Bconst%20r%3De.filter%28%28e%3D%3Ee.mode%3D%3D%3Dt.mode%26%26e.top%3C%3Di-s%29%29.sort%28%28%28t%2Ce%29%3D%3Et.top-e.top%29%29%3Bif%280%3D%3D%3Dr.length%29return%20h%3Br.unshift%28%7Btop%3A0%2Cleft%3A0%2Cright%3A0%2Cheight%3Ah%2Cwidth%3An%2Cspeed%3A0%2Cdistance%3An%7D%29%2Cr.push%28%7Btop%3Ai-s%2Cleft%3A0%2Cright%3A0%2Cheight%3As%2Cwidth%3An%2Cspeed%3A0%2Cdistance%3An%7D%29%3Bfor%28let%20e%3D1%3Be%3Cr.length%3Be%2B%3D1%29%7Bconst%20n%3Dr%5Be%5D%2Ci%3Dr%5Be-1%5D%2Cs%3Di.top%2Bi.height%3Bif%28n.top-s%3E%3Dt.height%29return%20s%7Dconst%20p%3D%5B%5D%3Bfor%28let%20t%3D1%3Bt%3Cr.length-1%3Bt%2B%3D1%29%7Bconst%20e%3Dr%5Bt%5D%3Bif%28p.length%29%7Bconst%20t%3Dp%5Bp.length-1%5D%3Bt%5B0%5D.top%3D%3D%3De.top%3Ft.push%28e%29%3Ap.push%28%5Be%5D%29%7Delse%20p.push%28%5Be%5D%29%7Dif%28%21o%29%7Bswitch%28t.mode%29%7Bcase%200%3Ap.sort%28%28%28t%2Ce%29%3D%3E%7Bconst%20n%3DMath.min%28...e.map%28%28t%3D%3Et.right%29%29%29%2Ci%3DMath.min%28...t.map%28%28t%3D%3Et.right%29%29%29%3Breturn%20n%2ae.length-i%2at.length%7D%29%29%3Bbreak%3Bcase%201%3Ap.sort%28%28%28t%2Ce%29%3D%3E%7Bconst%20n%3DMath.max%28...e.map%28%28t%3D%3Et.width%29%29%29%3Breturn%20Math.max%28...t.map%28%28t%3D%3Et.width%29%29%29%2at.length-n%2ae.length%7D%29%29%7Dreturn%20p%5B0%5D%5B0%5D.top%7Dswitch%28t.mode%29%7Bcase%200%3A%7Bconst%20e%3Dp.find%28%28e%3D%3Ee.every%28%28e%3D%3E%7Bif%28n%3Ce.distance%29return%211%3Bif%28t.speed%3Ce.speed%29return%210%3Breturn%20e.right%2F%28t.speed-e.speed%29%3Ee.time%7D%29%29%29%29%3Breturn%20e%26%26e%5B0%5D%3Fe%5B0%5D.top%3Avoid%200%7Dcase%201%3Areturn%7D%7Donmessage%3Dt%3D%3E%7Bconst%7Bdata%3Ae%7D%3Dt%2Cn%3DgetDanmuTop%28e%29%3Bself.postMessage%28%7Btop%3An%2Cid%3Ae.id%7D%29%7D%3B"},{}],"2Abxf":[function(t,e,i){t("@parcel/transformer-js/src/esmodule-helpers.js").defineInteropFlag(i),i.default=function({target:t,emits:e,clientWidth:i,clientHeight:n,marginBottom:s,marginTop:r,antiOverlap:o}){const a=e.filter((e=>e.mode===t.mode&&e.top<=n-s)).sort(((t,e)=>t.top-e.top));if(0===a.length)return r;a.unshift({top:0,left:0,right:0,height:r,width:i,speed:0,distance:i}),a.push({top:n-s,left:0,right:0,height:s,width:i,speed:0,distance:i});for(let e=1;e=t.height)return s}const l=[];for(let t=1;t{const i=Math.min(...e.map((t=>t.right))),n=Math.min(...t.map((t=>t.right)));return i*e.length-n*t.length}));break;case 1:l.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 l[0][0].top}switch(t.mode){case 0:{const e=l.find((e=>e.every((e=>{if(ie.time}))));return e&&e[0]?e[0].top:void 0}case 1:return}}},{"@parcel/transformer-js/src/esmodule-helpers.js":"b7MJY"}],jAkJm:[function(t,e,i){var n=t("@parcel/transformer-js/src/esmodule-helpers.js");n.defineInteropFlag(i);var s=t("bundle-text:./img/danmu-on.svg"),r=n.interopDefault(s),o=t("bundle-text:./img/danmu-off.svg"),a=n.interopDefault(o),l=t("bundle-text:./img/danmu-config.svg"),h=n.interopDefault(l);i.default=function(t,e){const{addClass:i,append:n,setStyle:s,tooltip:o}=t.constructor.utils;function l(t,e){const r=document.createElement("i");return n(r,t),i(r,"art-icon"),i(r,`art-icon-${e}`),s(r,"width","22px"),s(r,"height","22px"),r}const c=l(r.default,"danmu-on"),u=l(a.default,"danmu-off"),p=l(h.default,"danmu-config");t.on("ready",(()=>{t.controls.add({position:"right",name:"danmuku",click:function(){e.isHide?(e.show(),t.notice.show="弹幕显示",s(c,"display",null),s(u,"display","none")):(e.hide(),t.notice.show="弹幕隐藏",s(c,"display","none"),s(u,"display",null))},mounted(t){n(t,c),n(t,u),o(t,"弹幕开关"),s(u,"display","none")}}),t.setting.add({name:"danmuku",html:"弹幕设置",tooltip:"更多",icon:p,selector:[{width:200,html:"播放速度",icon:"",tooltip:"适中",selector:[{html:"极慢",time:10},{html:"较慢",time:7.5},{default:!0,html:"适中",time:5},{html:"较快",time:2.5},{html:"极快",time:1}],onSelect:function(t){return e.config({speed:t.time}),t.html}},{width:200,html:"字体大小",icon:"",tooltip:"适中",selector:[{html:"极小",fontSize:"2%"},{html:"较小",fontSize:"4%"},{default:!0,html:"适中",fontSize:"6%"},{html:"较大",fontSize:"8%"},{html:"极大",fontSize:"10%"}],onSelect:function(t){return e.config({fontSize:t.fontSize}),t.html}},{width:200,html:"不透明度",icon:"",tooltip:"100%",selector:[{default:!0,opacity:1,html:"100%"},{opacity:.75,html:"75%"},{opacity:.5,html:"50%"},{opacity:.25,html:"25%"},{opacity:0,html:"0%"}],onSelect:function(t){return e.config({opacity:t.opacity}),t.html}},{width:200,html:"显示范围",icon:"",tooltip:"3/4",selector:[{html:"1/4",margin:["2%","75%"]},{html:"半屏",margin:["2%","50%"]},{default:!0,html:"3/4",margin:["2%","25%"]},{html:"满屏",margin:["2%","2%"]}],onSelect:function(t){return e.config({margin:t.margin}),t.html}},{html:"弹幕防重叠",icon:"",tooltip:e.option.antiOverlap?"开启":"关闭",switch:e.option.antiOverlap,onSwitch:t=>(e.config({antiOverlap:!t.switch}),t.tooltip=t.switch?"关闭":"开启",!t.switch)},{html:"同步视频速度",icon:"",tooltip:e.option.synchronousPlayback?"开启":"关闭",switch:e.option.synchronousPlayback,onSwitch:t=>(e.config({synchronousPlayback:!t.switch}),t.tooltip=t.switch?"关闭":"开启",!t.switch)}]})}))}},{"bundle-text:./img/danmu-on.svg":"6RWYp","bundle-text:./img/danmu-off.svg":"oGdIw","bundle-text:./img/danmu-config.svg":"RQdxd","@parcel/transformer-js/src/esmodule-helpers.js":"b7MJY"}],"6RWYp":[function(t,e,i){e.exports=''},{}],oGdIw:[function(t,e,i){e.exports=''},{}],RQdxd:[function(t,e,i){e.exports=''},{}]},["E13ST"],"E13ST");