mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-09 03:46:16 -08:00
8 lines
67 KiB
JavaScript
8 lines
67 KiB
JavaScript
/*!
|
|
* artplayer-plugin-danmuku.js v6.0.0
|
|
* Github: https://github.com/zhw2590582/ArtPlayer
|
|
* (c) 2017-2026 Harvey Zhao
|
|
* Released under the MIT License.
|
|
*/
|
|
!function(t,e){"object"===typeof exports&&"undefined"!==typeof module?module.exports=e():"function"==typeof define&&define.amd?(t.artplayerPluginDanmuku=e(),define(function(){return t.artplayerPluginDanmuku})):(t="undefined"!==typeof globalThis?globalThis:t||self).artplayerPluginDanmuku=e()}(this,function(){"use strict";function t(t){return t instanceof Promise||"[object Promise]"===Object.prototype.toString.call(t)}function e(t){switch(t){case 1:case 2:case 3:default:return 0;case 4:return 2;case 5:return 1}}function i(t){if("string"!==typeof t)return[];const i=t.matchAll(/<d[^>]*?p="(?<p>[^"]+)"[^>]*>(?<text>.*?)<\/d>/gs);return Array.from(i).map(t=>{const i=t.groups.p.split(",");if(i.length>=8){return{text:t.groups.text.trim().replaceAll(""",'"').replaceAll("'","'").replaceAll("<","<").replaceAll(">",">").replaceAll("&","&"),time:Number(i[0]),mode:e(Number(i[1])),fontSize:Number(i[2]),color:`#${Number(i[3]).toString(16)}`,timestamp:Number(i[4]),pool:Number(i[5]),userID:i[6],rowID:Number(i[7])}}return null}).filter(Boolean)}function n({data:t}){const{xml:e,id:n}=t,s=i(e);globalThis.postMessage({danmus:s,id:n})}let s=0;function a(t,{signal:a,onCancel:r}={}){return new Promise((o,l)=>{let d,h,c,p=!1;const u=++s,m=()=>g(void 0,function(t){if(void 0!==t?.reason)return t.reason;const e=new Error("Bilibili Danmu loading cancelled");return e.name="AbortError",e}(a));function f(){let t,e=!1;try{if(d){const t=d;d=void 0,t.onmessage=null,t.onerror=null,t.onmessageerror=null,t.terminate()}}catch(i){t=i,e=!0}if(void 0!==h){const n=h;h=void 0;try{URL.revokeObjectURL(n)}catch(i){e||(t=i),e=!0}}if(e)throw t}function g(t,e){if(p)return;p=!0;let i=arguments.length>1;a?.removeEventListener("abort",m),c?.();try{f()}catch(n){i||(e=n),i=!0}i?l(e):o(t)}function y(t,e){if(!p){console.error("Error parsing Bilibili Danmu:",e);try{g(i(t))}catch(n){g(void 0,n)}}}a?.aborted?m():(a?.addEventListener("abort",m),c=r?.(m),p?c?.():async function(){const s=a?await fetch(t,{signal:a}):await fetch(t);if(p)return;const r=await s.text();if(!p)try{const t=`\n ${e.toString()}\n ${i.toString()}\n onmessage = ${n.toString()}\n `;if(h=URL.createObjectURL(new Blob([t],{type:"application/javascript"})),p)return void f();if(d=new Worker(h),p)return void f();d.onmessage=t=>{if(p||t.data?.id!==u)return;const{danmus:e}=t.data;Array.isArray(e)?g(e):g(void 0,new Error("Invalid Bilibili Danmu worker response"))},d.onerror=t=>{t.preventDefault?.(),y(r,t.error||t)},d.onmessageerror=t=>y(r,t.error||t),d.postMessage({xml:r,id:u})}catch(o){y(r,o)}}().catch(t=>g(void 0,t)))})}const r=new WeakMap,o=Symbol("cancelled danmuku input");function l(t){return r.has(t)||r.set(t,{closed:!1,tasks:new Set,emitting:[]}),r.get(t)}function d(t){const e=l(t),i=e.emitting[e.emitting.length-1];return!e.closed&&!t.art.isDestroy&&(!i||i.active())}function h(t){const e=l(t);e.closed=!0;for(const i of[...e.tasks])i.cancel()}function c(t,e,i){const n=t.states[e]||[];for(let s=0;s<n.length;s++)i(n[s]);return n}class p{constructor(t){this.owner=t,this.nodes=new Set}acquire(){const t=this.owner.$refs.pop()||document.createElement("div");return t.style.cssText=this.owner.constructor.cssText,t.dataset.mode="",t.dataset.id="",t.className="",this.nodes.add(t),t}get visibles(){const t=[],{clientWidth:e}=this.owner.$player,i=this.owner.getLeft(this.owner.$player);return this.owner.filter("emit",n=>{const s=n.$ref.offsetTop,a=this.owner.getLeft(n.$ref)-i,r=n.$ref.clientHeight,o=n.$ref.clientWidth,l=a+o,d=e-l,h=l/n.$restTime,c={};c.top=s,c.left=a,c.height=r,c.width=o,c.right=d,c.speed=h,c.distance=l,c.time=n.$restTime,c.mode=n.mode,t.push(c)}),t}left(t){const e=t.getBoundingClientRect();return this.owner.isRotate?e.top:e.left}makeWait(t){this.owner.setState(t,"wait"),t.$ref&&(t.$ref.style.cssText=this.owner.constructor.cssText,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.owner.$refs.push(t.$ref),t.$ref=null)}resize(){const{clientWidth:t}=this.owner.$player;this.owner.filter("stop",e=>{if(0===e.mode)e.$ref.style.left=`${t}px`}),this.owner.filter("emit",e=>{switch(e.$lastStartTime=Date.now(),e.mode){case 0:{const i=t+e.$ref.clientWidth;e.$ref.style.left=`${t}px`,e.$ref.style.transform=`translateX(${-i}px)`,e.$ref.style.transition=`transform ${e.$restTime}s linear 0s`;break}}})}continue(){const{clientWidth:t}=this.owner.$player;return this.owner.filter("stop",e=>{switch(this.owner.setState(e,"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.owner.$player;return this.owner.filter("emit",e=>{switch(this.owner.setState(e,"stop"),e.mode){case 0:{const i=t-(this.owner.getLeft(e.$ref)-this.owner.getLeft(this.owner.$player));e.$ref.style.transform=`translateX(${-i}px)`,e.$ref.style.transition="transform 0s linear 0s";break}}}),this}prepare(t,e){const i=this.owner,n=i.$ref;return e.danmu=t,e.ref=n,t.$ref=n,n.textContent=t.text,i.$danmuku.appendChild(n),n.style.opacity=i.option.opacity,n.style.fontSize=`${i.fontSize}px`,n.style.color=t.color,n.style.border=t.border?`1px solid ${t.color}`:null,n.style.backgroundColor=t.border?"rgb(0 0 0 / 50%)":null,i.utils.setStyles(n,t.style),n}place(t,e,i,n,s){switch(e.style.top=`${i}px`,e.style.visibility="visible",e.dataset.mode=t.mode,e.dataset.id=t.id||"",t.mode){case 0:e.style.left=`${s}px`,e.style.marginLeft="0px",e.style.transform=`translateX(${-n}px)`,e.style.transition=`transform ${t.$restTime}s linear 0s`;break;case 1:case 2:e.style.left="50%",e.style.marginLeft=`-${e.clientWidth/2}px`}}release(t){const{danmu:e,ref:i}=t;i&&e.$ref===i&&(i.style.cssText=this.owner.constructor.cssText,i.style.visibility="hidden",this.owner.$refs.push(i),e.$ref=null),t.ref=null}clear(){this.destroy(),this.owner.$refs=[],this.owner.$danmuku.textContent=""}destroy(){for(const t of this.nodes)t.parentElement&&t.parentElement.removeChild(t);for(const t of this.owner.queue)t.$ref=null;this.owner.$refs.length=0,this.nodes.clear()}}function u({target:t,visibles:e,clientWidth:i,clientHeight:n,marginBottom:s,marginTop:a,antiOverlap:r}){const o=n-s,l=e.filter(e=>e.mode===t.mode&&e.top<=o).sort((t,e)=>t.top-e.top);if(0===l.length)return 2===t.mode?o-t.height:a;if(l.unshift({type:"top",top:0,left:0,right:0,height:a,width:i,speed:0,distance:i}),l.push({type:"bottom",top:o,left:0,right:0,height:s,width:i,speed:0,distance:i}),2===t.mode)for(let h=l.length-2;h>=0;h-=1){const e=l[h],i=l[h+1],n=e.top+e.height;if(i.top-n>=t.height)return i.top-t.height}else for(let h=1;h<l.length;h+=1){const e=l[h],i=l[h-1],n=i.top+i.height;if(e.top-n>=t.height)return n}const d=[];for(let h=1;h<l.length-1;h+=1){const t=l[h];if(d.length){const e=d[d.length-1];e[0].top===t.top?e.push(t):d.push([t])}else d.push([t])}if(!r){switch(t.mode){case 0:d.sort((t,e)=>{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:case 2:d.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 d[0][0].top}switch(t.mode){case 0:{const e=d.find(e=>e.every(e=>{if(i<e.distance)return!1;if(t.speed<e.speed)return!0;return e.right/(t.speed-e.speed)>e.time}));return e&&e[0]?e[0].top:void 0}case 1:case 2:return}}class m{constructor(){this.rows=new Set,this.waiting=new Set,this.visibility=()=>this.clear()}begin(t){void 0===this.time&&this.capture(t,[],t.art.currentTime)}capture(t,e,i){const n=t.$player.ownerDocument;if(n!==this.document&&(this.document?.removeEventListener("visibilitychange",this.visibility),this.document=n,n?.addEventListener("visibilitychange",this.visibility),this.clear()),!Number.isFinite(i)||"hidden"===n?.visibilityState||t.art.video?.seeking)return this.clear(),e;const s=this.time,a=this.rows,r=this.waiting;if(this.time=i,this.rows=new Set(e),this.waiting=new Set(t.states.wait),void 0===s||i<=s)return e;const o=t.states.wait.filter(t=>r.has(t)&&!a.has(t)&&t.time>=s-.1&&t.time<i-.1);for(const l of o)this.rows.add(l);return[...e.filter(t=>"ready"===t.$state),...o,...e.filter(t=>"ready"!==t.$state)]}clear(){this.time=void 0,this.rows.clear(),this.waiting.clear()}destroy(){this.document?.removeEventListener("visibilitychange",this.visibility),this.document=void 0,this.clear()}}class f{constructor(){this.pending=new Set,this.reserved=new Set}capture(t,e){for(const i of t)this.reserved.has(i)||e.has(i)||this.pending.add(i)}take(){const t=[],e=[];for(const n of this.pending)"ready"===n.$state?t.push(n):"wait"===n.$state&&e.push(n);this.pending.clear();const i=[...t,...e];return this.reserved=new Set(i),i}complete(){this.reserved.clear()}clear(){this.pending.clear(),this.reserved.clear()}}const g=Symbol("cancelled danmuku frame");class y{constructor(t){this.owner=t,this.generation=0,this.starts=0,this.frame=null,this.operation=null,this.closed=!1,this.running=!1,this.fault=!1,this.failedItems=new Set,this.buffer=new f,this.sampling=new m}active(t){const e=this.owner;return!this.closed&&!this.fault&&!e.art.isDestroy&&!e.isStop&&!e.isHide&&t.generation===this.generation}release(t){this.owner.renderer.release(t)}invalidate(){if(this.generation++,null!==this.frame&&window.cancelAnimationFrame(this.frame),this.frame=null,this.owner.timer=null,this.operation){const t=this.operation;this.operation=null,t.cancel(),this.release(t)}this.owner.workerClient?.cancel(),this.failedItems.clear(),this.buffer.clear(),this.sampling.clear()}report(t){try{this.owner.art.emit("artplayerPluginDanmuku:error",t)}catch(e){console.warn("Failed to report danmuku scheduling error:",e)}}fail(t){this.closed||this.fault||(this.fault=!0,this.invalidate(),this.report(t))}recover(){if(!this.closed&&!this.owner.art.isDestroy&&(this.failedItems.clear(),this.fault))try{this.owner.workerClient?.dispose(),this.owner.createWorker(),this.fault=!1}catch(t){this.report(t)}}schedule(){const t=this.owner;if(!(!this.running||this.closed||this.fault||t.art.isDestroy||t.isStop)){try{const e=t.art.video;(t.art.playing||!1===e?.paused&&!e.ended&&e.readyState>2)&&!t.isHide&&this.sampling.begin(t)}catch(e){return void this.fail(e)}null===this.frame&&(this.frame=window.requestAnimationFrame(()=>{if(this.frame=null,t.timer=null,this.closed||this.fault||t.isStop||t.art.isDestroy)return;const i=this.generation;try{if(t.art.playing&&!t.isHide){t.filter("emit",e=>{const i=Date.now();e.$restTime-=(i-e.$lastStartTime)/1e3,e.$lastStartTime=i,e.$restTime<=0&&t.makeWait(e)});const e=t.art.currentTime,n=t.readys;if(i!==this.generation)return;this.buffer.capture(this.sampling.capture(t,n,e),this.failedItems)}}catch(e){return void(i===this.generation&&this.fail(e))}if(this.schedule(),this.operation||!t.art.playing||t.isHide)return;const n=this.buffer.take();if(!n.length)return;let s;const a=new Promise(t=>s=()=>t(g)),r={generation:this.generation,cancel:s,wait:t=>Promise.race([t,a]),ref:null};return this.operation=r,this.run(r,n).catch(t=>{this.active(r)&&this.fail(t)}).finally(()=>{this.release(r),this.operation===r&&(this.operation=null,this.buffer.complete())})}),t.timer=this.frame)}}async run(t,e){const i=this.owner;if(i.art.playing&&this.active(t))for(const s of e){if(!this.active(t))return;if(this.failedItems.has(s))continue;let e;try{e=await t.wait(i.option.beforeVisible(s))}catch(n){if(!this.active(t))return;this.failedItems.add(s),this.report(n);continue}if(!this.active(t))return;if(!e)continue;const{clientWidth:a,clientHeight:r}=i.$player,o=i.renderer.prepare(s,t);if(!this.active(t))return;s.$lastStartTime=Date.now(),s.$restTime=i.speed;const l=a+o.clientWidth,d={type:"getDanmuTop",target:{mode:s.mode,height:o.clientHeight,speed:l/s.$restTime},visibles:i.visibles,antiOverlap:i.option.antiOverlap,clientWidth:a,clientHeight:r,marginBottom:i.marginBottom,marginTop:i.marginTop},h=d.antiOverlap?await t.wait(i.postMessage(d)):{result:u(d)},c="symbol"===typeof h?void 0:h.result;if(!this.active(t)||s.$ref!==o)return;void 0!==c?(s.$lastStartTime=Date.now(),i.setState(s,"emit"),i.renderer.place(s,o,c,l,a),t.ref=null,i.art.emit("artplayerPluginDanmuku:visible",s)):(i.setState(s,"ready"),this.release(t))}}destroy(){this.closed=!0,this.invalidate(),this.sampling.destroy()}}let v=0;class w{constructor(t,e){this.pending=new Map,this.closed=!1,this.failed=!1,this.onFailure=e,this.worker=t();try{this.worker.onmessage=t=>{const e=this.pending.get(t.data?.id);e&&(this.pending.delete(t.data.id),e.resolve(t.data))},this.worker.onerror=t=>{t.preventDefault?.(),this.fail(t.error||t)},this.worker.onmessageerror=t=>this.fail(t.error||t)}catch(i){try{this.dispose()}catch{}throw i}}request(t){t.id=++v;const{id:e}=t;return this.closed||this.failed?Promise.resolve({id:e,result:void 0}):new Promise((i,n)=>{this.pending.set(e,{resolve:i,reject:n});try{this.worker.postMessage(t)}catch(s){this.fail(s)}})}fail(t){if(!this.closed&&!this.failed){this.failed=!0;for(const e of this.pending.values())e.reject(t);this.pending.clear();try{this.dispose()}catch{}this.onFailure(t)}}cancel(){for(const[t,e]of this.pending)e.resolve({id:t,result:void 0});this.pending.clear()}dispose(){if(this.closed)return;this.closed=!0,this.cancel();let t,e=!1;const i=i=>{try{i()}catch(n){e||(t=n),e=!0}};for(const n of["onmessage","onerror","onmessageerror"])i(()=>this.worker[n]=null);if(i(()=>this.worker.terminate()),e)throw t}}const k='/*!\n * artplayer-plugin-danmuku.js v6.0.0\n * Github: https://github.com/zhw2590582/ArtPlayer\n * (c) 2017-2026 Harvey Zhao\n * Released under the MIT License.\n */\nfunction t({target:t,visibles:e,clientWidth:i,clientHeight:h,marginBottom:n,marginTop:o,antiOverlap:s}){const r=h-n,p=e.filter(e=>e.mode===t.mode&&e.top<=r).sort((t,e)=>t.top-e.top);if(0===p.length)return 2===t.mode?r-t.height:o;if(p.unshift({type:"top",top:0,left:0,right:0,height:o,width:i,speed:0,distance:i}),p.push({type:"bottom",top:r,left:0,right:0,height:n,width:i,speed:0,distance:i}),2===t.mode)for(let g=p.length-2;g>=0;g-=1){const e=p[g],i=p[g+1],h=e.top+e.height;if(i.top-h>=t.height)return i.top-t.height}else for(let g=1;g<p.length;g+=1){const e=p[g],i=p[g-1],h=i.top+i.height;if(e.top-h>=t.height)return h}const a=[];for(let g=1;g<p.length-1;g+=1){const t=p[g];if(a.length){const e=a[a.length-1];e[0].top===t.top?e.push(t):a.push([t])}else a.push([t])}if(!s){switch(t.mode){case 0:a.sort((t,e)=>{const i=Math.min(...e.map(t=>t.right)),h=Math.min(...t.map(t=>t.right));return i*e.length-h*t.length});break;case 1:case 2:a.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 a[0][0].top}switch(t.mode){case 0:{const e=a.find(e=>e.every(e=>{if(i<e.distance)return!1;if(t.speed<e.speed)return!0;return e.right/(t.speed-e.speed)>e.time}));return e&&e[0]?e[0].top:void 0}case 1:case 2:return}}onmessage=e=>{const{data:i}=e;if(!i.id||!i.type)return;const h=(0,{getDanmuTop:t}[i.type])(i);globalThis.postMessage({result:h,id:i.id})};\n',x="undefined"!==typeof self&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",k],{type:"text/javascript;charset=utf-8"});function b(t){let e;try{if(e=x&&(self.URL||self.webkitURL).createObjectURL(x),!e)throw"";const i=new Worker(e,{type:"module",name:t?.name});return i.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),i}catch(i){return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(k),{type:"module",name:t?.name})}}class ${constructor(t,e){const{constructor:i,template:n}=t;this.utils=i.utils,this.validator=i.validator,this.$danmuku=n.$danmuku,this.$player=n.$player,this.art=t,this.queue=[],this.$refs=[],this.isStop=!1,this.isHide=!1,this.timer=null,this.index=0,this.worker=null,this.workerClient=null,this.renderer=new p(this),this.scheduler=new y(this),this.option=$.option,this.states={wait:[],ready:[],emit:[],stop:[]},this.start=this.start.bind(this),this.stop=this.stop.bind(this),this.reset=this.reset.bind(this),this.resize=this.resize.bind(this),this.destroy=this.destroy.bind(this),this.seek=this.seek.bind(this),d(this),t.on("destroy",this.destroy);try{if(this.config(e,!0),!d(this))return;this.createWorker()}catch(s){throw t.off("destroy",this.destroy),h(this),this.scheduler.destroy(),s}t.on("video:play",this.start),t.on("video:playing",this.start),t.on("video:pause",this.stop),t.on("video:waiting",this.stop),t.on("resize",this.resize),t.on("video:seeking",this.seek),this.load().catch(t=>console.warn("Failed to load initial danmuku:",t))}static get option(){return{danmuku:[],speed:5,margin:[10,"25%"],opacity:1,color:"#FFFFFF",mode:0,modes:[0,1,2],fontSize:25,antiOverlap:!0,synchronousPlayback:!1,mount:void 0,heatmap:!1,width:512,points:[],filter:()=>!0,beforeEmit:()=>!0,beforeVisible:()=>!0,visible:!0,emitter:!0,maxLength:200,lockTime:5,theme:"dark",OPACITY:{},FONT_SIZE:{},MARGIN:{},SPEED:{},COLOR:[]}}static get scheme(){return{danmuku:"array|function|string|promise",speed:"number",margin:"array",opacity:"number",color:"string",mode:"number",modes:"array",fontSize:"number|string",antiOverlap:"boolean",synchronousPlayback:"boolean",mount:"?htmldivelement|string",heatmap:"object|boolean",width:"number",points:"array",filter:"function",beforeEmit:"function",beforeVisible:"function",visible:"boolean",emitter:"boolean",maxLength:"number",lockTime:"number",theme:"string",OPACITY:"object",FONT_SIZE:"object",MARGIN:"object",SPEED:"object",COLOR:"array"}}static get cssText(){return'\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 '}get isRotate(){return 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*(Number.parseFloat(e)/100),0,i)}return $.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*(Number.parseFloat(e)/100),0,i)}return $.option.margin[1]}get fontSize(){const{clamp:t}=this.utils,{clientHeight:e}=this.$player,i=this.option.fontSize;if("number"===typeof i)return Math.round(t(i,12,e));if("string"===typeof i&&i.endsWith("%")){const n=Number.parseFloat(i)/100;return Math.round(t(e*n,12,e))}return $.option.fontSize}get $ref(){return this.renderer.acquire()}get readys(){return function(t){const{currentTime:e}=t.art,i=[];return c(t,"ready",t=>i.push(t)),c(t,"wait",t=>{e+.1>=t.time&&t.time>=e-.1&&i.push(t)}),i}(this)}get visibles(){return this.renderer.visibles}get speed(){return this.option.synchronousPlayback&&this.art.playbackRate?this.option.speed/Number(this.art.playbackRate):this.option.speed}async load(e){const{errorHandle:i}=this.utils,n=function(t,e){const i=l(t);if(e)for(const o of[...i.tasks])o.replace&&o.cancel();let n,s=i.closed||t.art.isDestroy;const a=new Promise(t=>n=t),r=new Set,d="function"===typeof AbortController?new AbortController:void 0,h={replace:e,signal:d?.signal,active:()=>!s&&!i.closed&&!t.art.isDestroy,onCancel:t=>h.active()?(r.add(t),()=>r.delete(t)):(t(),()=>{}),cancel(){if(!s){s=!0,n(o),d?.abort();for(const t of[...r])t();r.clear()}},wait:t=>Promise.race([t,a]),emit(e){i.emitting.push(h);try{return t.emit(e)}finally{i.emitting.pop()}},finish(){i.tasks.delete(h),r.clear()}};return s?n(o):i.tasks.add(h),h}(this,void 0===e);try{if(!n.active())return this;const s=function(e,i){return"function"===typeof e?{asynchronous:!0,value:e()}:t(e)?{asynchronous:!0,value:e}:"string"===typeof e?{asynchronous:!0,value:a(e,i)}:{asynchronous:!1,value:Array.isArray(e)?e:[]}}(e||this.option.danmuku,n),r=s.asynchronous?await n.wait(s.value):s.value;if(!n.active())return this;i(Array.isArray(r),"Danmuku need return an array as result");const o=r;if(void 0===e){if(this.reset(),!n.active())return this;this.queue=[],this.states={wait:[],ready:[],emit:[],stop:[]},this.renderer.clear()}for(let t=0;t<o.length;t++){if(!n.active())return this;const e=o[t];await n.emit(e)}n.active()&&this.art.emit("artplayerPluginDanmuku:loaded",this.queue)}catch(s){if(!n.active())return this;throw this.art.emit("artplayerPluginDanmuku:error",s),s}finally{n.finish()}return this}async emit(t){const{clamp:e}=this.utils;if(!d(this))return this;if(this.validator(t,{id:"?string",text:"string",mode:"?number",color:"?string",time:"?number",border:"?boolean",style:"?object"}),!t.text.trim())return this;if(t.time||0===t.time?t.time=e(t.time,0,1/0):t.time=this.art.currentTime+.5,void 0===t.mode&&(t.mode=this.option.mode),void 0===t.style&&(t.style={}),void 0===t.color&&(t.color=this.option.color),![0,1,2].includes(t.mode))return this;if(!this.option.filter(t))return this;if(!d(this))return this;const i={...t,$state:"wait",$index:this.index++,$ref:null,$restTime:0,$lastStartTime:0};return this.setState(i,"wait"),this.queue.push(i),this}config(e,i=!1){const{clamp:n}=this.utils,{$controlsCenter:s}=this.art.template;var a,r;if(!(a=this.option,r=e,Object.keys(r).some(e=>{const i=a[e],n=r[e];return"function"===typeof i||"function"===typeof n||t(i)||t(n)?i!==n:JSON.stringify(i)!==JSON.stringify(n)}))&&!i)return this;const o=function(t,e,{defaults:i,validate:n,clamp:s,mount:a}){const r=Object.assign({},i,t,e);return n(r),r.mode=s(r.mode,0,2),r.speed=s(r.speed,1,10),r.opacity=s(r.opacity,0,1),r.lockTime=s(r.lockTime,1,60),r.maxLength=s(r.maxLength,1,1e3),r.mount=r.mount||a,r}(this.option,e,{defaults:$.option,validate:t=>this.validator(t,$.scheme),clamp:n,mount:s});if(!d(this))return this;const l=this.option.beforeVisible!==o.beforeVisible;return this.option=o,l&&(this.scheduler.invalidate(),this.scheduler.schedule()),e.fontSize&&(this.reset(),!d(this))||(this.option.visible?this.show():this.hide(),d(this)&&this.art.emit("artplayerPluginDanmuku:config",this.option)),this}getLeft(t){return this.renderer.left(t)}postMessage(t={}){return this.workerClient.request(t)}createWorker(){this.workerClient=new w(()=>new b,t=>this.scheduler.fail(t)),this.worker=this.workerClient.worker}filter(t,e){return c(this,t,e)}setState(t,e){!function(t,e,i){t.states[e.$state]=t.states[e.$state].filter(t=>t!==e),e.$state=i,e.$ref&&(e.$ref.dataset.state=i),t.states[i].push(e)}(this,t,e)}makeWait(t){this.renderer.makeWait(t)}update(){return this.scheduler.running=!0,this.scheduler.schedule(),this}resize(){this.renderer.resize()}continue(){return this.renderer.continue(),this}suspend(){return this.renderer.suspend(),this}stop(){return this.isStop=!0,this.scheduler.running=!1,this.scheduler.invalidate(),this.suspend(),this.art.emit("artplayerPluginDanmuku:stop"),this}start(){if(this.scheduler.closed||this.art.isDestroy)return this;const t=++this.scheduler.starts,e=this.scheduler.generation;this.isStop=!1,this.scheduler.recover();return this.scheduler.closed||this.art.isDestroy||this.isStop||this.scheduler.fault||e!==this.scheduler.generation||t!==this.scheduler.starts||(this.continue(),this.update(),this.art.emit("artplayerPluginDanmuku:start")),this}reset(){return this.scheduler.invalidate(),this.queue.forEach(t=>this.makeWait(t)),this.art.emit("artplayerPluginDanmuku:reset"),this.scheduler.recover(),this.scheduler.schedule(),this}seek(){this.scheduler.invalidate(),this.scheduler.schedule()}show(){return this.isHide=!1,this.$danmuku.style.opacity=1,this.option.visible=!0,this.art.emit("artplayerPluginDanmuku:show"),this}hide(){return this.isHide=!0,this.scheduler.invalidate(),this.$danmuku.style.opacity=0,this.option.visible=!1,this.art.emit("artplayerPluginDanmuku:hide"),this.scheduler.schedule(),this}destroy(){h(this),this.scheduler.destroy();try{try{this.stop()}finally{this.workerClient?.dispose()}}finally{this.renderer.destroy(),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("resize",this.resize),this.art.off("video:seeking",this.seek),this.art.off("destroy",this.destroy),this.art.emit("artplayerPluginDanmuku:destroy")}}}const M=4294967295;function S(t,e){let i=0,n=t.length;for(;i<n;){const s=Math.floor((i+n)/2);t[s]<=e?i=s+1:n=s}return i}function z(t,e,i,n,s){return(t-e)*(s-n)/(i-e)+n}function E({width:t,height:e,duration:i,queue:n,option:s,points:a=[]}){if(![t,e,i].every(t=>Number.isFinite(t)&&t>0))return null;const r={xMin:0,xMax:t,yMin:0,yMax:128,scale:.25,opacity:.2,minHeight:Math.floor(.05*e),sampling:Math.max(1,Math.floor(t/100)),smoothing:.2,flattening:.2},o=Object.assign({},"object"===typeof s?s:{}),l=Object.assign({},r,o);for(const b of Object.keys(r))Number.isFinite(l[b])||(l[b]=r[b]);if(l.sampling<=0&&(l.sampling=r.sampling),l.xMin===l.xMax||l.yMin===l.yMax)return null;const d=Array.isArray(a)&&a.length>0,h=d?[...a]:function(t,e,i,n){if(!Number.isFinite(e)||e<=0||!Number.isFinite(i)||i<=0||!Number.isFinite(n)||n<=0||Math.floor(e/n)+1>M)return[];const s=t.map(t=>t.time).filter(t=>"number"===typeof t&&!Number.isNaN(t)).sort((t,e)=>t-e),a=[],r=i/e;if(!Number.isFinite(r))return[];for(let o=0;o<=e;o+=n){if(a.length>=M||o+n===o)return[];const t=o*r,e=(o+n)*r;a.push([o,S(s,e)-S(s,t)])}return a}(n,t,i,l.sampling);if(!h.length||!h.every(t=>Array.isArray(t)&&Number.isFinite(t[0])&&Number.isFinite(t[1])))return null;const c=h[h.length-1];if(c[0]!==t){if(h.length===M)return null;h.push([t,c[1]])}let p=1/0,u=-1/0;for(const b of h)p=Math.min(p,b[1]),u=Math.max(u,b[1]);const m=(p+u)/2;for(const b of h){const t=b[1];b[1]=t*(t>m?1+l.scale:1-l.scale)+l.minHeight}const f=!d&&!Number.isFinite(o.yMin)&&!Number.isFinite(o.yMax);let g=0;for(const b of h)g=Math.max(g,b[1]);const y=f&&g>r.yMax/4;y&&(l.yMax=4*g);const v=t=>y?Math.min(e,Math.max(.75*e,t)):t,w=(t,e,i,n)=>{const s=function(t,e){const i=e[0]-t[0],n=e[1]-t[1];return{length:Math.sqrt(i**2+n**2),angle:Math.atan2(n,i)}}(e||t,i||t),a=z(Math.cos(s.angle)*l.flattening,0,1,1,0),r=s.angle*a+(n?Math.PI:0),o=s.length*l.smoothing;return[t[0]+Math.cos(r)*o,v(t[1]+Math.sin(r)*o)]},k=h.map(i=>[z(i[0],l.xMin,l.xMax,0,t),v(z(i[1],l.yMin,l.yMax,e,0))]);if(!k.every(t=>t.every(Number.isFinite)))return null;const x=k.map((t,i,n)=>{if(0===i)return`M ${n[n.length-1][0]},${e} L ${t[0]},${e} L ${t[0]},${t[1]}`;const s=w(n[i-1],n[i-2],t),a=w(t,n[i-1],n[i+1],!0);return`C ${s[0]},${s[1]} ${a[0]},${a[1]} ${t[0]},${t[1]}${i===n.length-1?" z":""}`}).join(" ");return/NaN|Infinity/u.test(x)?null:{path:x,opacity:l.opacity,width:t,height:e}}let F=0;function C(t,e,i){if(t.isDestroy)return;const{query:n}=t.constructor.utils;let s;const a=[];let r,o,l,d=!1;const h=()=>!d&&!t.isDestroy;function c(e,i){const n=i;a.push([e,n]),t.on(e,n)}function p(e){if(d)return;let i;d=!0,o=null,l=null;let n=!1;const s=t=>{try{t()}catch(e){n||(i=e),n=!0}};for(const[r,o]of a.splice(0))s(()=>t.off(r,o));if(e&&r&&t.controls.heatmap===r&&s(()=>t.controls.remove("heatmap")),r=void 0,n)throw i}function u(t){h()&&o&&l&&(o.setAttribute("offset",100*t+"%"),l.setAttribute("offset",100*t+"%"))}function m(a){try{!function(a=[]){if(!h())return;o=null,l=null;const d=r;if(d.innerHTML="",t.option.isLive)return;const c=E({width:d.offsetWidth,height:d.offsetHeight,duration:t.duration,queue:e.queue,option:i,points:a});if(!c||!h())return;const p=d.ownerDocument;for(s||(s=p?"heatmap-solids":"heatmap-solids-"+ ++F);p?.getElementById(s);)s="heatmap-solids-"+ ++F;d.innerHTML=`\n <svg viewBox="0 0 ${c.width} ${c.height}">\n <defs>\n <linearGradient id="${s}" x1="0%" y1="0%" x2="100%" y2="0%">\n <stop offset="0%" style="stop-color:var(--art-theme);stop-opacity:${c.opacity}" />\n <stop offset="0%" style="stop-color:var(--art-theme);stop-opacity:${c.opacity}" id="heatmap-start" />\n <stop offset="0%" style="stop-color:var(--art-progress-color);stop-opacity:1" id="heatmap-stop" />\n <stop offset="100%" style="stop-color:var(--art-progress-color);stop-opacity:1" />\n </linearGradient>\n </defs>\n <path fill="url(#${s})" d="${c.path}"></path>\n </svg>\n `,o=n("#heatmap-start",d),l=n("#heatmap-stop",d),u(t.played)}(a)}catch(d){try{p(!0)}catch{}throw d}}c("destroy",()=>p(!0));try{t.controls.add({name:"heatmap",position:"top",html:"",style:{position:"absolute",top:"-100px",left:"0px",right:"0px",height:"100px",width:"100%",pointerEvents:"none"},beforeUnmount(){p(!1)},mounted(e){if(r=e,d)return t.controls.heatmap===e&&t.controls.remove("heatmap"),void(r=void 0);h()?(c("video:timeupdate",()=>u(t.played)),c("setBar",(t,e)=>{"played"===t&&u(e)}),c("ready",()=>m()),c("resize",()=>m()),c("artplayerPluginDanmuku:loaded",()=>m()),c("artplayerPluginDanmuku:points",t=>m(t))):p(!0)}})}catch(f){try{p(!0)}catch{}throw f}return()=>p(!0)}const D=new WeakMap;class T{constructor(t){this.art=t,this.closed=!1,this.disposers=new Set,this.cancelled=new Promise(t=>this.cancel=t)}get active(){return!this.closed&&!this.art.isDestroy}own(t){this.closed?t():this.disposers.add(t)}write(t,e,i,n=i=>t[e]=i){const s=t;if(!this.active)return;const a=()=>"function"===typeof s.getPropertyPriority?s.getPropertyPriority(e):void 0;let r=D.get(s);r||(r=new Map,D.set(s,r));let o=r.get(e);o||(o={original:s[e],present:e in s||void 0!==s[e],priority:a(),owners:new Map,apply:n},r.set(e,o)),o.owners.has(this)||this.own(()=>{const t=[...o.owners.keys()],i=t[t.length-1]===this;if(o.owners.delete(this),i&&s[e]===o.last&&a()===o.lastPriority){const t=[...o.owners.values()];t.length?(o.apply(t[t.length-1]),o.last=s[e],o.lastPriority=a()):void 0!==o.priority?s.setProperty(e,o.original,o.priority):o.present?o.apply(o.original):delete s[e]}o.owners.size||(r.delete(e),r.size||D.delete(s))}),o.owners.delete(this),o.owners.set(this,i),o.apply(i),o.last=s[e],o.lastPriority=a()}on(t,e){if(!this.active)return;const i=this;function n(...t){if(i.active)return e.apply(this,t)}const s=()=>this.art.off(t,n);this.own(s);try{this.art.on(t,n),this.active||s()}catch(a){throw this.release(s),a}}proxy(t,e,i){if(!this.active)return;const n=this;function s(...t){if(n.active)return i.apply(this,t)}let a;const r=()=>{if("function"===typeof a){const t=this.art.events;"function"===typeof t?.remove&&t.destroyEvents?.has(a)?t.remove(a):a()}else t.removeEventListener?.(e,s)};this.own(r);try{a=this.art.proxy(t,e,s),this.active||r()}catch(o){throw this.release(r),o}}wait(t){return Promise.race([t,this.cancelled])}release(t){try{t()}catch(e){console.warn("Failed to dispose danmuku setting resource:",e)}}close(){if(!this.closed){this.closed=!0,this.cancel();for(const t of this.disposers)this.release(t);this.disposers.clear()}}}function P({min:t,max:e,container:i,findIndex:n,onChange:s,steps:a=[]}){const{lifecycle:r}=this;if(!r.active)return{reset(){}};const{query:o,clamp:l,setStyle:d}=this.utils;d(i,"touch-action","none"),i.innerHTML=`\n <div class="apd-slider-line">\n <div class="apd-slider-points">\n ${a.map(()=>'<div class="apd-slider-point"></div>').join("")}\n </div>\n <div class="apd-slider-progress"></div>\n </div>\n <div class="apd-slider-dot"></div>\n <div class="apd-slider-steps">\n ${a.map(t=>t.hide?"":`<div class="apd-slider-step">${t.name}</div>`).join("")}\n </div>\n `;const h=o(".apd-slider-dot",i),c=o(".apd-slider-progress",i);let p=!1;function u(i){if(!r.active)return;if(void 0===i&&(i=n()),i<t||i>e)return;const o=(i-t)/(e-t);h.style.left=100*o+"%",0===a.length&&(c.style.width=h.style.left),s(i)}function m(n){const{top:s,height:a,left:r,width:o}=i.getBoundingClientRect();if(this.art.isRotate){const i=l(n.clientY-s,0,a);u(Math.round(i/a*(e-t)+t))}else{const i=l(n.clientX-r,0,o);u(Math.round(i/o*(e-t)+t))}}return r.own(()=>p=!1),r.proxy(i,"click",t=>{m.call(this,t)}),r.proxy(i,"pointerdown",t=>{p=0===t.button}),r.on("document:pointermove",t=>{p&&m.call(this,t)}),r.on("document:pointerup",t=>{p&&(p=!1,m.call(this,t))}),{reset:u}}const L='<svg class="apd-icon apd-check-off" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" data-pointer="none" viewBox="0 0 32 32" width="32" height="32" ><path d="M8 6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2H8zm0-2h16c2.21 0 4 1.79 4 4v16c0 2.21-1.79 4-4 4H8c-2.21 0-4-1.79-4-4V8c0-2.21 1.79-4 4-4z" fill="#FFFFFF"></path></svg>',A='<svg class="apd-icon apd-check-on" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" data-pointer="none" viewBox="0 0 32 32" width="32" height="32" ><path d="m13 18.25-1.8-1.8c-.6-.6-1.65-.6-2.25 0s-.6 1.5 0 2.25l2.85 2.85c.318.318.762.468 1.2.448.438.02.882-.13 1.2-.448l8.85-8.85c.6-.6.6-1.65 0-2.25s-1.65-.6-2.25 0l-7.8 7.8zM8 4h16c2.21 0 4 1.79 4 4v16c0 2.21-1.79 4-4 4H8c-2.21 0-4-1.79-4-4V8c0-2.21 1.79-4 4-4z" fill="#00AEEC"></path></svg>',H='<svg class="apd-icon apd-config-icon" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" data-pointer="none" viewBox="0 0 24 24" width="24" height="24" ><path fill-rule="evenodd" d="m15.645 4.881 1.06-1.473a.998.998 0 1 0-1.622-1.166L13.22 4.835a110.67 110.67 0 0 0-1.1-.007h-.131c-.47 0-.975.004-1.515.012L8.783 2.3A.998.998 0 0 0 7.12 3.408l.988 1.484c-.688.019-1.418.042-2.188.069a4.013 4.013 0 0 0-3.83 3.44c-.165 1.15-.245 2.545-.245 4.185 0 1.965.115 3.67.35 5.116a4.012 4.012 0 0 0 3.763 3.363c1.903.094 3.317.141 5.513.141a.988.988 0 0 0 0-1.975 97.58 97.58 0 0 1-5.416-.139 2.037 2.037 0 0 1-1.91-1.708c-.216-1.324-.325-2.924-.325-4.798 0-1.563.076-2.864.225-3.904.14-.977.96-1.713 1.945-1.747 2.444-.087 4.465-.13 6.063-.131 1.598 0 3.62.044 6.064.13.96.034 1.71.81 1.855 1.814.075.524.113 1.962.141 3.065v.002c.005.183.01.07.014-.038.004-.096.008-.189.011-.081a.987.987 0 1 0 1.974-.069c-.004-.105-.007-.009-.011.09-.002.056-.004.112-.007.135l-.002.01a.574.574 0 0 1-.005-.091v-.027c-.03-1.118-.073-2.663-.16-3.276-.273-1.906-1.783-3.438-3.74-3.507-.905-.032-1.752-.058-2.543-.079Zm-3.113 4.703h-1.307v4.643h2.2v.04l.651-1.234c.113-.215.281-.389.482-.509v-.11h.235c.137-.049.283-.074.433-.074h1.553V9.584h-1.264a8.5 8.5 0 0 0 .741-1.405l-1.078-.381c-.24.631-.501 1.23-.806 1.786h-1.503l.686-.305c-.228-.501-.5-.959-.806-1.394l-1.034.348c.294.392.566.839.817 1.35Zm-1.7 5.502h2.16l-.564 1.068h-1.595v-1.068Zm-2.498-1.863.152-1.561h1.96V8.289H7.277v.969h2.048v1.435h-1.84l-.306 3.51h2.254c0 1.155-.043 1.906-.12 2.255-.076.348-.38.523-.925.523-.305 0-.61-.022-.893-.055l.294 1.056.061.005c.282.02.546.039.81.039.991-.065 1.547-.414 1.677-1.046.11-.631.175-1.883.175-3.757H8.334Zm5.09-.8v.85h-1.188v-.85h1.187Zm-1.188-.955h1.187v-.893h-1.187v.893Zm2.322.007v-.893h1.241v.893h-1.241Zm.528 2.757a1.26 1.26 0 0 1 1.087-.627l4.003-.009a1.26 1.26 0 0 1 1.094.63l1.721 2.982c.226.39.225.872-.001 1.263l-1.743 3a1.26 1.26 0 0 1-1.086.628l-4.003.009a1.26 1.26 0 0 1-1.094-.63l-1.722-2.982a1.26 1.26 0 0 1 .002-1.263l1.742-3Zm1.967.858a1.26 1.26 0 0 0-1.08.614l-.903 1.513a1.26 1.26 0 0 0-.002 1.289l.885 1.492c.227.384.64.62 1.086.618l2.192-.005a1.26 1.26 0 0 0 1.08-.615l.904-1.518a1.26 1.26 0 0 0 .001-1.288l-.884-1.489a1.26 1.26 0 0 0-1.086-.616l-2.193.005Zm2.517 2.76a1.4 1.4 0 1 1-2.8 0 1.4 1.4 0 0 1 2.8 0Z" clip-rule="evenodd"></path></svg>',O='<svg class="apd-icon apd-mode-0-off" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" data-pointer="none" style="enable-background:new 0 0 28 28" viewBox="0 0 28 28" width="28" height="28" ><path d="M23 15c1.487 0 2.866.464 4 1.255V7a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v14a4 4 0 0 0 4 4h11.674A7 7 0 0 1 23 15zM11 9h6a1 1 0 0 1 0 2h-6a1 1 0 0 1 0-2zm-3 2H6V9h2v2zm4 4h-2v-2h2v2zm2-1a1 1 0 0 1 1-1h1a1 1 0 0 1 0 2h-1a1 1 0 0 1-1-1z" fill="#00AEEC"></path><path d="M26.536 18.464a5 5 0 0 0-7.071 0 5 5 0 0 0 0 7.071 5 5 0 1 0 7.071-7.071zm-5.657 5.657a3 3 0 0 1-.586-3.415l4.001 4.001a3 3 0 0 1-3.415-.586zm4.829-.827-4.001-4.001a3.002 3.002 0 0 1 4.001 4.001z" fill="#00AEEC"></path></svg>',N='<svg class="apd-icon apd-mode-0-on" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" data-pointer="none" style="enable-background:new 0 0 28 28" viewBox="0 0 28 28" width="28" height="28" ><path d="M23 3H5a4 4 0 0 0-4 4v14a4 4 0 0 0 4 4h18a4 4 0 0 0 4-4V7a4 4 0 0 0-4-4zM11 9h6a1 1 0 0 1 0 2h-6a1 1 0 0 1 0-2zm-3 2H6V9h2v2zm4 4h-2v-2h2v2zm9 0h-6a1 1 0 0 1 0-2h6a1 1 0 0 1 0 2z" fill="#FFFFFF"></path></svg>',V='<svg class="apd-icon apd-mode-1-off" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" data-pointer="none" style="enable-background:new 0 0 28 28" viewBox="0 0 28 28" width="28" height="28" ><path d="M23 15c1.487 0 2.866.464 4 1.255V7a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v14a4 4 0 0 0 4 4h11.674A7 7 0 0 1 23 15zm-4-8h2v2h-2V7zM9 9H7V7h2v2zm4 0h-2V7h2v2zm2-2h2v2h-2V7z" fill="#00AEEC"></path><path d="M26.536 18.464a5 5 0 0 0-7.071 0 5 5 0 0 0 0 7.071 5 5 0 1 0 7.071-7.071zm-5.657 5.657a3 3 0 0 1-.586-3.415l4.001 4.001a3 3 0 0 1-3.415-.586zm4.829-.827-4.001-4.001a3.002 3.002 0 0 1 4.001 4.001z" fill="#00AEEC"></path></svg>',q='<svg class="apd-icon apd-mode-1-on" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" data-pointer="none" style="enable-background:new 0 0 28 28" viewBox="0 0 28 28" width="28" height="28" ><path d="M23 3H5a4 4 0 0 0-4 4v14a4 4 0 0 0 4 4h18a4 4 0 0 0 4-4V7a4 4 0 0 0-4-4zM9 9H7V7h2v2zm4 0h-2V7h2v2zm4 0h-2V7h2v2zm4 0h-2V7h2v2z" fill="#FFFFFF"></path></svg>',I='<svg class="apd-icon apd-mode-2-off" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" data-pointer="none" style="enable-background:new 0 0 28 28" viewBox="0 0 28 28" width="28" height="28" ><path d="M23 15c1.487 0 2.866.464 4 1.255V7a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v14a4 4 0 0 0 4 4h11.674A7 7 0 0 1 23 15zM9 21H7v-2h2v2zm4 0h-2v-2h2v2z" fill="#00AEEC"></path><path d="M26.536 18.464a5 5 0 0 0-7.071 0 5 5 0 0 0 0 7.071 5 5 0 1 0 7.071-7.071zm-5.657 5.657a3 3 0 0 1-.586-3.415l4.001 4.001a3 3 0 0 1-3.415-.586zm4.829-.827-4.001-4.001a3.002 3.002 0 0 1 4.001 4.001z" fill="#00AEEC"></path></svg>',j='<svg class="apd-icon apd-mode-2-on" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" data-pointer="none" style="enable-background:new 0 0 28 28" viewBox="0 0 28 28" width="28" height="28" ><path d="M23 3H5a4 4 0 0 0-4 4v14a4 4 0 0 0 4 4h18a4 4 0 0 0 4-4V7a4 4 0 0 0-4-4zM9 21H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2z" fill="#FFFFFF"></path></svg>',B='<svg class="apd-icon apd-toggle-off" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" data-pointer="none" viewBox="0 0 24 24" width="24" height="24" ><path fill-rule="evenodd" d="m8.085 4.891-.999-1.499a1.008 1.008 0 0 1 1.679-1.118l1.709 2.566c.54-.008 1.045-.012 1.515-.012h.13c.345 0 .707.003 1.088.007l1.862-2.59a1.008 1.008 0 0 1 1.637 1.177l-1.049 1.46c.788.02 1.631.046 2.53.078 1.958.069 3.468 1.6 3.74 3.507.088.613.13 2.158.16 3.276l.001.027c.01.333.017.63.025.856a.987.987 0 0 1-1.974.069c-.008-.23-.016-.539-.025-.881v-.002c-.028-1.103-.066-2.541-.142-3.065-.143-1.004-.895-1.78-1.854-1.813-2.444-.087-4.466-.13-6.064-.131-1.598 0-3.619.044-6.063.13a2.037 2.037 0 0 0-1.945 1.748c-.15 1.04-.225 2.341-.225 3.904 0 1.874.11 3.474.325 4.798.154.949.95 1.66 1.91 1.708a97.58 97.58 0 0 0 5.416.139.988.988 0 0 1 0 1.975c-2.196 0-3.61-.047-5.513-.141A4.012 4.012 0 0 1 2.197 17.7c-.236-1.446-.351-3.151-.351-5.116 0-1.64.08-3.035.245-4.184A4.013 4.013 0 0 1 5.92 4.96c.761-.027 1.483-.05 2.164-.069Zm4.436 4.707h-1.32v4.63h2.222v.848h-2.618v1.078h2.431a5.01 5.01 0 0 1 3.575-3.115V9.598h-1.276a8.59 8.59 0 0 0 .748-1.42l-1.089-.384a14.232 14.232 0 0 1-.814 1.804h-1.518l.693-.308a8.862 8.862 0 0 0-.814-1.408l-1.045.352c.297.396.572.847.825 1.364Zm-4.18 3.564.154-1.485h1.98V8.289h-3.2v.979h2.067v1.43H7.483l-.308 3.454h2.277c0 1.166-.044 1.925-.12 2.277-.078.352-.386.528-.936.528-.308 0-.616-.022-.902-.055l.297 1.067.062.004c.285.02.551.04.818.04 1.001-.066 1.562-.418 1.694-1.056.11-.638.176-1.903.176-3.795h-2.2Zm7.458.11v-.858h-1.254v.858H15.8Zm-2.376-.858v.858h-1.199v-.858h1.2Zm-1.199-.946h1.2v-.902h-1.2v.902Zm2.321 0v-.902H15.8v.902h-1.254Zm3.517 10.594a4 4 0 1 0 0-8 4 4 0 0 0 0 8Zm-.002-1.502a2.5 2.5 0 0 1-2.217-3.657l3.326 3.398a2.49 2.49 0 0 1-1.109.259Zm2.5-2.5c0 .42-.103.815-.286 1.162l-3.328-3.401a2.5 2.5 0 0 1 3.614 2.239Z" clip-rule="evenodd"></path></svg>',R='<svg class="apd-icon apd-toggle-on" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" data-pointer="none" viewBox="0 0 24 24" width="24" height="24" ><path fill-rule="evenodd" d="M11.989 4.828c-.47 0-.975.004-1.515.012l-1.71-2.566a1.008 1.008 0 0 0-1.678 1.118l.999 1.5c-.681.018-1.403.04-2.164.068a4.013 4.013 0 0 0-3.83 3.44c-.165 1.15-.245 2.545-.245 4.185 0 1.965.115 3.67.35 5.116a4.012 4.012 0 0 0 3.763 3.363l.906.046c1.205.063 1.808.095 3.607.095a.988.988 0 0 0 0-1.975c-1.758 0-2.339-.03-3.501-.092l-.915-.047a2.037 2.037 0 0 1-1.91-1.708c-.216-1.324-.325-2.924-.325-4.798 0-1.563.076-2.864.225-3.904.14-.977.96-1.713 1.945-1.747 2.444-.087 4.465-.13 6.063-.131 1.598 0 3.62.044 6.064.13.96.034 1.71.81 1.855 1.814.075.524.113 1.962.141 3.065v.002c.01.342.017.65.025.88a.987.987 0 1 0 1.974-.068c-.008-.226-.016-.523-.025-.856v-.027c-.03-1.118-.073-2.663-.16-3.276-.273-1.906-1.783-3.438-3.74-3.507-.9-.032-1.743-.058-2.531-.078l1.05-1.46a1.008 1.008 0 0 0-1.638-1.177l-1.862 2.59c-.38-.004-.744-.007-1.088-.007h-.13Zm.521 4.775h-1.32v4.631h2.222v.847h-2.618v1.078h2.618l.003.678c.36.026.714.163 1.01.407h.11v-1.085h2.694v-1.078h-2.695v-.847H16.8v-4.63h-1.276a8.59 8.59 0 0 0 .748-1.42L15.183 7.8a14.232 14.232 0 0 1-.814 1.804h-1.518l.693-.308a8.862 8.862 0 0 0-.814-1.408l-1.045.352c.297.396.572.847.825 1.364Zm-4.18 3.564.154-1.485h1.98V8.294h-3.2v.98H9.33v1.43H7.472l-.308 3.453h2.277c0 1.166-.044 1.925-.12 2.277-.078.352-.386.528-.936.528-.308 0-.616-.022-.902-.055l.297 1.067.062.005c.285.02.551.04.818.04 1.001-.067 1.562-.419 1.694-1.057.11-.638.176-1.903.176-3.795h-2.2Zm7.458.11v-.858h-1.254v.858h1.254Zm-2.376-.858v.858h-1.199v-.858h1.2Zm-1.199-.946h1.2v-.902h-1.2v.902Zm2.321 0v-.902h1.254v.902h-1.254Z" clip-rule="evenodd"></path><path fill="#00AEEC" fill-rule="evenodd" d="M22.846 14.627a1 1 0 0 0-1.412.075l-5.091 5.703-2.216-2.275-.097-.086-.008-.005a1 1 0 0 0-1.322 1.493l2.963 3.041.093.083.007.005c.407.315 1 .27 1.354-.124l5.81-6.505.08-.102.005-.008a1 1 0 0 0-.166-1.295Z" clip-rule="evenodd"></path></svg>',Z='<svg class="apd-icon apd-style-icon" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" data-pointer="none" style="enable-background:new 0 0 22 22" viewBox="0 0 22 22" width="36" height="24" ><path d="M17 16H5c-.55 0-1 .45-1 1s.45 1 1 1h12c.55 0 1-.45 1-1s-.45-1-1-1zM6.96 15c.39 0 .74-.24.89-.6l.65-1.6h5l.66 1.6c.15.36.5.6.89.6.69 0 1.15-.71.88-1.34l-3.88-8.97C11.87 4.27 11.46 4 11 4s-.87.27-1.05.69l-3.88 8.97c-.27.63.2 1.34.89 1.34zM11 5.98 12.87 11H9.13L11 5.98z"></path></svg>';function W(){const{option:t}=this;return`\n <div class="apd-toggle">\n ${R}${B}\n </div>\n <div class="apd-config">\n ${H}\n <div class="apd-config-panel">\n <div class="apd-config-panel-inner">\n <div class="apd-config-mode">\n \u6309\u7c7b\u578b\u5c4f\u853d\n <div class="apd-modes">\n <div data-mode="0" class="apd-mode">\n ${O}${N}\n <div>\u6eda\u52a8</div>\n </div>\n <div data-mode="1" class="apd-mode">\n ${V}${q}\n <div>\u9876\u90e8</div>\n </div>\n <div data-mode="2" class="apd-mode">\n ${I}${j}\n <div>\u5e95\u90e8</div>\n </div>\n </div>\n </div>\n <div class="apd-config-other">\n <div class="apd-other apd-anti-overlap">\n ${A}${L}\n \u9632\u6b62\u5f39\u5e55\u91cd\u53e0\n </div>\n <div class="apd-other apd-sync-video">\n ${A}${L}\n \u540c\u6b65\u89c6\u9891\u901f\u5ea6\n </div>\n </div>\n <div class="apd-config-slider apd-config-opacity">\n \u4e0d\u900f\u660e\u5ea6\n <div class="apd-slider"></div>\n <div class="apd-value">\u672a\u77e5</div>\n </div>\n <div class="apd-config-slider apd-config-margin">\n \u663e\u793a\u533a\u57df\n <div class="apd-slider"></div>\n <div class="apd-value">\u672a\u77e5</div>\n </div>\n <div class="apd-config-slider apd-config-fontSize">\n \u5f39\u5e55\u5b57\u53f7\n <div class="apd-slider"></div>\n <div class="apd-value">\u672a\u77e5</div>\n </div>\n <div class="apd-config-slider apd-config-speed">\n \u5f39\u5e55\u901f\u5ea6\n <div class="apd-slider"></div>\n <div class="apd-value">\u672a\u77e5</div>\n </div>\n </div>\n </div>\n </div>\n <div class="apd-emitter">\n <div class="apd-style">\n ${Z}\n <div class="apd-style-panel">\n <div class="apd-style-panel-inner">\n <div class="apd-style-mode">\n \u6a21\u5f0f\n <div class="apd-modes">\n <div data-mode="0" class="apd-mode">\n ${N}\n <div>\u6eda\u52a8</div>\n </div>\n <div data-mode="1" class="apd-mode">\n ${q}\n <div>\u9876\u90e8</div>\n </div>\n <div data-mode="2" class="apd-mode">\n ${j}\n <div>\u5e95\u90e8</div>\n </div>\n </div>\n </div>\n <div class="apd-style-color">\n \u989c\u8272\n <div class="apd-colors">\n ${this.COLOR.map(t=>`<div data-color="${t}" class="apd-color" style="background-color: ${t}"></div>`).join("")}\n </div>\n </div>\n </div>\n </div>\n </div>\n <input class="apd-input" placeholder="\u53d1\u4e2a\u53cb\u5584\u7684\u5f39\u5e55\u89c1\u8bc1\u5f53\u4e0b" autocomplete="off" maxLength="${t.maxLength}" />\n <div class="apd-send">\u53d1\u9001</div>\n </div>\n `}if("undefined"!==typeof document){const t="artplayer-plugin-danmuku",e=Symbol.for("artplayer-plugin-danmuku.pending-style"),i=document;let n=document.getElementById(t)||i[e];if(!n)if(n=document.createElement("style"),n.id=t,"loading"===document.readyState){i[e]=n;const s=()=>{document.removeEventListener("DOMContentLoaded",s),i[e]===n&&delete i[e];const a=document.getElementById(t);a?a.textContent=n.textContent:(document.head||document.documentElement).appendChild(n)};document.addEventListener("DOMContentLoaded",s,{once:!0})}else(document.head||document.documentElement).appendChild(n);n.textContent='.artplayer-plugin-danmuku{display:flex;position:relative;z-index:99;align-items:center;justify-content:center;font-size:12px;height:32px;width:100%;color:#fff;font-weight:300;flex-shrink:0;gap:10px}.artplayer-plugin-danmuku .apd-icon{cursor:pointer;opacity:.75;transition:all .2s ease;fill:#fff}.artplayer-plugin-danmuku .apd-icon:hover{opacity:1}.artplayer-plugin-danmuku .apd-config{display:flex;position:relative}.artplayer-plugin-danmuku .apd-config .apd-config-panel{position:absolute;bottom:24px;left:0;width:320px;padding:10px;opacity:0;pointer-events:none}.artplayer-plugin-danmuku .apd-config .apd-config-panel .apd-config-panel-inner{width:100%;border-radius:3px;background-color:#000000d9;padding:10px}.artplayer-plugin-danmuku .apd-config:hover .apd-config-panel{opacity:100;pointer-events:all}.artplayer-plugin-danmuku .apd-config-mode,.artplayer-plugin-danmuku .apd-config-slider,.artplayer-plugin-danmuku .apd-config-other,.artplayer-plugin-danmuku .apd-style-mode{margin-bottom:15px}.artplayer-plugin-danmuku .apd-modes{display:flex;align-items:center;margin-top:5px;gap:20px}.artplayer-plugin-danmuku .apd-modes .apd-mode{cursor:pointer;text-align:center}.artplayer-plugin-danmuku .apd-modes .apd-mode:hover{color:#00a1d6}.artplayer-plugin-danmuku .apd-config-slider{display:flex;align-items:center;gap:12px}.artplayer-plugin-danmuku .apd-config-slider .apd-value{width:32px;text-align:right}.artplayer-plugin-danmuku .apd-slider{position:relative;flex:1;display:flex;height:20px;align-items:center;justify-content:center;cursor:pointer}.artplayer-plugin-danmuku .apd-slider .apd-slider-line{position:relative;height:2px;width:100%;overflow:hidden;border-radius:3px;background-color:#ffffff40}.artplayer-plugin-danmuku .apd-slider .apd-slider-points{position:absolute;inset:0;display:flex;align-items:center;justify-content:space-between}.artplayer-plugin-danmuku .apd-slider .apd-slider-points .apd-slider-point{width:2px;height:2px;border-radius:50%;background-color:#ffffff80}.artplayer-plugin-danmuku .apd-slider .apd-slider-progress{width:0%;height:100%;background-color:#00a1d6}.artplayer-plugin-danmuku .apd-slider .apd-slider-dot{position:absolute;transform:translate(-6px);left:0%;width:12px;height:12px;border-radius:50%;background-color:#00a1d6}.artplayer-plugin-danmuku .apd-slider .apd-slider-steps{display:flex;align-items:center;justify-content:space-between;position:absolute;bottom:-12px;width:calc(100% + 32px);color:#777}.artplayer-plugin-danmuku .apd-slider .apd-slider-steps .apd-slider-step{flex-shrink:0;width:36px;text-align:center;scale:.95}.artplayer-plugin-danmuku .apd-config-other{display:flex;align-items:center;gap:20px}.artplayer-plugin-danmuku .apd-config-other .apd-check-off,.artplayer-plugin-danmuku .apd-config-other .apd-check-on{width:16px;height:16px}.artplayer-plugin-danmuku .apd-config-other .apd-other{display:flex;align-items:center;cursor:pointer;gap:2px}.artplayer-plugin-danmuku .apd-config-other .apd-other:hover{color:#00a1d6}.artplayer-plugin-danmuku .apd-emitter{display:flex;flex:1;align-items:center;height:100%;background-color:#ffffff40;border-radius:5px}.artplayer-plugin-danmuku .apd-style{position:relative;display:flex;align-items:center;justify-content:center}.artplayer-plugin-danmuku .apd-style .apd-style-panel{position:absolute;bottom:24px;left:0;width:200px;padding:10px;opacity:0;pointer-events:none}.artplayer-plugin-danmuku .apd-style .apd-style-panel .apd-style-panel-inner{width:100%;border-radius:3px;background-color:#000000d9;padding:10px}.artplayer-plugin-danmuku .apd-style:hover .apd-style-panel{opacity:100;pointer-events:all}.artplayer-plugin-danmuku .apd-colors{display:flex;flex-wrap:wrap;margin-top:5px;gap:8px}.artplayer-plugin-danmuku .apd-colors .apd-color{width:16px;height:16px;border-radius:2px;cursor:pointer}.artplayer-plugin-danmuku .apd-colors .apd-color.apd-active{border:1px solid black;box-shadow:0 0 0 1px #fff}.artplayer-plugin-danmuku .apd-input{outline:none;height:100%;flex:1;min-width:0;width:auto;border:none;line-height:1;color:#fff;background-color:transparent}.artplayer-plugin-danmuku .apd-input::placeholder{color:#ffffff80}.artplayer-plugin-danmuku .apd-send{display:flex;align-items:center;justify-content:center;height:100%;width:60px;flex-shrink:0;cursor:pointer;text-shadow:none;border-top-right-radius:5px;border-bottom-right-radius:5px;background-color:#00a1d6}.artplayer-plugin-danmuku .apd-send.apd-lock{cursor:not-allowed;color:#666;background-color:#e7e7e7}.art-controls-center .apd-emitter{width:260px;flex:none}.art-fullscreen .artplayer-plugin-danmuku,.art-fullscreen-web .artplayer-plugin-danmuku{height:38px;gap:16px}.art-fullscreen .artplayer-plugin-danmuku .apd-config-icon,.art-fullscreen-web .artplayer-plugin-danmuku .apd-config-icon,.art-fullscreen .artplayer-plugin-danmuku .apd-toggle-off,.art-fullscreen-web .artplayer-plugin-danmuku .apd-toggle-off,.art-fullscreen .artplayer-plugin-danmuku .apd-toggle-on,.art-fullscreen-web .artplayer-plugin-danmuku .apd-toggle-on{width:28px;height:28px}.art-fullscreen .artplayer-plugin-danmuku .apd-emitter,.art-fullscreen-web .artplayer-plugin-danmuku .apd-emitter{width:400px;flex:none}.art-video-player>.artplayer-plugin-danmuku{position:absolute;left:0;right:0;bottom:-40px;padding:0 10px}.art-video-player:has(>.artplayer-plugin-danmuku){margin-bottom:40px}[data-danmuku-emitter=false] .apd-emitter{display:none!important}[data-danmuku-emitter=false] .art-controls-center .artplayer-plugin-danmuku{justify-content:flex-end;gap:18px}[data-danmuku-emitter=false].art-fullscreen .art-controls-center .artplayer-plugin-danmuku,[data-danmuku-emitter=false].art-fullscreen-web .art-controls-center .artplayer-plugin-danmuku{gap:24px}[data-danmuku-theme=light]>.artplayer-plugin-danmuku .apd-icon{fill:#333}[data-danmuku-theme=light]>.artplayer-plugin-danmuku .apd-emitter{background-color:#f1f2f3}[data-danmuku-theme=light]>.artplayer-plugin-danmuku .apd-input{color:#000}[data-danmuku-theme=light]>.artplayer-plugin-danmuku .apd-input::placeholder{color:#0000004d}[data-danmuku-visible=false] .apd-toggle-off{display:block}[data-danmuku-visible=false] .apd-toggle-on,[data-danmuku-visible=true] .apd-toggle-off{display:none}[data-danmuku-visible=true] .apd-toggle-on{display:block}[data-danmuku-anti-overlap=false] .apd-anti-overlap .apd-check-on{display:none}[data-danmuku-anti-overlap=false] .apd-anti-overlap .apd-check-off,[data-danmuku-anti-overlap=true] .apd-anti-overlap .apd-check-on{display:block}[data-danmuku-anti-overlap=true] .apd-anti-overlap .apd-check-off,[data-danmuku-sync-video=false] .apd-sync-video .apd-check-on{display:none}[data-danmuku-sync-video=false] .apd-sync-video .apd-check-off,[data-danmuku-sync-video=true] .apd-sync-video .apd-check-on{display:block}[data-danmuku-sync-video=true] .apd-sync-video .apd-check-off{display:none}[data-danmuku-mode0=false] .apd-config-mode .apd-mode-0-off{display:block}[data-danmuku-mode0=false] .apd-config-mode .apd-mode-0-on{display:none}[data-danmuku-mode0=false] .art-danmuku [data-mode="0"]{opacity:0!important}[data-danmuku-mode0=true] .apd-config-mode .apd-mode-0-off{display:none}[data-danmuku-mode0=true] .apd-config-mode .apd-mode-0-on{display:block}[data-danmuku-mode="0"] .apd-style-mode [data-mode="0"]{color:#00a1d6}[data-danmuku-mode="0"] .apd-style-mode [data-mode="0"] path{fill:#00a1d6}[data-danmuku-mode1=false] .apd-config-mode .apd-mode-1-off{display:block}[data-danmuku-mode1=false] .apd-config-mode .apd-mode-1-on{display:none}[data-danmuku-mode1=false] .art-danmuku [data-mode="1"]{opacity:0!important}[data-danmuku-mode1=true] .apd-config-mode .apd-mode-1-off{display:none}[data-danmuku-mode1=true] .apd-config-mode .apd-mode-1-on{display:block}[data-danmuku-mode="1"] .apd-style-mode [data-mode="1"]{color:#00a1d6}[data-danmuku-mode="1"] .apd-style-mode [data-mode="1"] path{fill:#00a1d6}[data-danmuku-mode2=false] .apd-config-mode .apd-mode-2-off{display:block}[data-danmuku-mode2=false] .apd-config-mode .apd-mode-2-on{display:none}[data-danmuku-mode2=false] .art-danmuku [data-mode="2"]{opacity:0!important}[data-danmuku-mode2=true] .apd-config-mode .apd-mode-2-off{display:none}[data-danmuku-mode2=true] .apd-config-mode .apd-mode-2-on{display:block}[data-danmuku-mode="2"] .apd-style-mode [data-mode="2"]{color:#00a1d6}[data-danmuku-mode="2"] .apd-style-mode [data-mode="2"] path{fill:#00a1d6}'}class _{constructor(t,e){this.art=t,this.danmuku=e,this.utils=t.constructor.utils;const{setStyle:i}=this.utils,{$controlsCenter:n}=t.template;this.template={$controlsCenter:n,$mount:n,$danmuku:null,$toggle:null,$config:null,$configPanel:null,$configModes:null,$style:null,$stylePanel:null,$styleModes:null,$colors:null,$opacitySlider:null,$opacityValue:null,$marginSlider:null,$marginValue:null,$fontSizeSlider:null,$fontSizeValue:null,$speedSlider:null,$speedValue:null,$input:null,$send:null},this.slider={opacity:null,margin:null,fontSize:null,speed:null},this.emitting=!1,this.isLock=!1,this.timer=null,this.lifecycle=new T(t),this.destroy=this.destroy.bind(this),this.lifecycle.own(()=>t.off("destroy",this.destroy));try{if(t.on("destroy",this.destroy),!this.lifecycle.active)return;if(this.lifecycle.write(n.style,"display","flex",t=>i(n,"display",t)),this.createTemplate(),!this.lifecycle.active)return;if(this.createSliders(),!this.lifecycle.active)return;if(this.createEvents(),this.mount(this.option.mount),!this.lifecycle.active)return;this.lifecycle.on("resize",()=>this.resize()),this.lifecycle.on("fullscreen",t=>this.onFullscreen(t)),this.lifecycle.on("fullscreenWeb",t=>this.onFullscreen(t)),this.lifecycle.proxy(this.template.$config,"mouseenter",()=>{this.onMouseEnter({$control:this.template.$config,$panel:this.template.$configPanel})}),this.lifecycle.proxy(this.template.$style,"mouseenter",()=>{this.onMouseEnter({$control:this.template.$style,$panel:this.template.$stylePanel})})}catch(s){try{this.destroy()}catch(a){console.warn("Failed to roll back danmuku setting:",a)}throw s}}static get icons(){return{$on:R,$off:B,$config:H,$style:Z,$mode_0_off:O,$mode_0_on:N,$mode_1_off:V,$mode_1_on:q,$mode_2_off:I,$mode_2_on:j,$check_on:A,$check_off:L}}get option(){return this.danmuku.option}get outside(){return this.template.$mount!==this.template.$controlsCenter}get TEMPLATE(){return W.call(this)}get OPACITY(){return{min:0,max:100,steps:[],...this.option.OPACITY}}get FONT_SIZE(){return{min:12,max:120,steps:[],...this.option.FONT_SIZE}}get MARGIN(){return{min:0,max:3,steps:[{name:"1/4",value:[10,"75%"]},{name:"\u534a\u5c4f",value:[10,"50%"]},{name:"3/4",value:[10,"25%"]},{name:"\u6ee1\u5c4f",value:[10,10]}],...this.option.MARGIN}}get SPEED(){return{min:0,max:4,steps:[{name:"\u6781\u6162",value:10},{name:"\u8f83\u6162",value:7.5,hide:!0},{name:"\u9002\u4e2d",value:5},{name:"\u8f83\u5feb",value:2.5,hide:!0},{name:"\u6781\u5feb",value:1}],...this.option.SPEED}}get COLOR(){return this.option.COLOR.length?this.option.COLOR:["#FE0302","#FF7204","#FFAA02","#FFD302","#FFFF00","#A0EE00","#00CD00","#019899","#4266BE","#89D5FF","#CC0273","#222222","#9B9B9B","#FFFFFF"]}query(t){const{query:e}=this.utils,{$danmuku:i}=this.template;return e(t,i)}append(t,e){if(!this.lifecycle.active)return;const{append:i}=this.utils;[...t.children].includes(e)||i(t,e)}setData(t,e){if(!this.lifecycle.active)return;const{$player:i}=this.art.template,{$mount:n}=this.template;this.lifecycle.write(i.dataset,t,e),this.outside&&this.lifecycle.write(n.dataset,t,e)}createTemplate(){const{createElement:t,tooltip:e}=this.utils,i=t("div");this.template.$danmuku=i,i.className="artplayer-plugin-danmuku",i.innerHTML=this.TEMPLATE,this.template.$toggle=this.query(".apd-toggle"),this.template.$config=this.query(".apd-config"),this.template.$configPanel=this.query(".apd-config-panel"),this.template.$configModes=this.query(".apd-config-mode .apd-modes"),this.template.$style=this.query(".apd-style"),this.template.$stylePanel=this.query(".apd-style-panel"),this.template.$styleModes=this.query(".apd-style-mode .apd-modes"),this.template.$colors=this.query(".apd-colors"),this.template.$antiOverlap=this.query(".apd-anti-overlap"),this.template.$syncVideo=this.query(".apd-sync-video"),this.template.$opacitySlider=this.query(".apd-config-opacity .apd-slider"),this.template.$opacityValue=this.query(".apd-config-opacity .apd-value"),this.template.$marginSlider=this.query(".apd-config-margin .apd-slider"),this.template.$marginValue=this.query(".apd-config-margin .apd-value"),this.template.$fontSizeSlider=this.query(".apd-config-fontSize .apd-slider"),this.template.$fontSizeValue=this.query(".apd-config-fontSize .apd-value"),this.template.$speedSlider=this.query(".apd-config-speed .apd-slider"),this.template.$speedValue=this.query(".apd-config-speed .apd-value"),this.template.$input=this.query(".apd-input"),this.template.$send=this.query(".apd-send");const{$toggle:n}=this.template;this.lifecycle.on("artplayerPluginDanmuku:show",()=>{e(n,"\u5173\u95ed\u5f39\u5e55")}),this.lifecycle.on("artplayerPluginDanmuku:hide",()=>{e(n,"\u6253\u5f00\u5f39\u5e55")})}createEvents(){const{$toggle:t,$configModes:e,$styleModes:i,$colors:n,$antiOverlap:s,$syncVideo:a,$send:r,$input:o}=this.template;this.lifecycle.proxy(t,"click",()=>{this.danmuku.config({visible:!this.option.visible}),this.reset()}),this.lifecycle.proxy(e,"click",t=>{const e=t.target.closest(".apd-mode");if(!e)return;const i=Number(e.dataset.mode);this.option.modes.includes(i)?this.danmuku.config({modes:this.option.modes.filter(t=>t!==i)}):this.danmuku.config({modes:[...this.option.modes,i]}),this.reset()}),this.lifecycle.proxy(s,"click",()=>{this.danmuku.config({antiOverlap:!this.option.antiOverlap}),this.reset()}),this.lifecycle.proxy(a,"click",()=>{this.danmuku.config({synchronousPlayback:!this.option.synchronousPlayback}),this.reset()}),this.lifecycle.proxy(i,"click",t=>{const e=t.target.closest(".apd-mode");if(!e)return;const i=Number(e.dataset.mode);this.danmuku.config({mode:i}),this.reset()}),this.lifecycle.proxy(n,"click",t=>{const e=t.target.closest(".apd-color");e&&(this.danmuku.config({color:e.dataset.color}),this.reset())}),this.lifecycle.proxy(r,"click",()=>this.emit()),this.lifecycle.proxy(o,"keypress",t=>{"Enter"===t.key&&(t.preventDefault(),this.emit())})}createSliders(){this.slider.opacity=this.createSlider({...this.OPACITY,container:this.template.$opacitySlider,findIndex:()=>Math.round(100*this.option.opacity),onChange:t=>{const{$opacityValue:e}=this.template;e.textContent=`${t}%`,this.danmuku.config({opacity:t/100})}}),this.slider.margin=this.createSlider({...this.MARGIN,container:this.template.$marginSlider,findIndex:()=>this.MARGIN.steps.findIndex(t=>t.value[0]===this.option.margin[0]&&t.value[1]===this.option.margin[1]),onChange:t=>{const e=this.MARGIN.steps[t];if(!e)return;const{$marginValue:i}=this.template;i.textContent=e.name,this.danmuku.config({margin:e.value})}}),this.slider.fontSize=this.createSlider({...this.FONT_SIZE,container:this.template.$fontSizeSlider,findIndex:()=>this.danmuku.fontSize,onChange:t=>{const{$fontSizeValue:e}=this.template;e.textContent=`${t}px`,t!==this.danmuku.fontSize&&this.danmuku.config({fontSize:t})}}),this.slider.speed=this.createSlider({...this.SPEED,container:this.template.$speedSlider,findIndex:()=>this.SPEED.steps.findIndex(t=>t.value===this.option.speed),onChange:t=>{const e=this.SPEED.steps[t];if(!e)return;const{$speedValue:i}=this.template;i.textContent=e.name,this.danmuku.config({speed:e.value})}})}createSlider(t){return P.call(this,t)}onFullscreen(t){if(!this.lifecycle.active)return;const{$danmuku:e,$controlsCenter:i,$mount:n}=this.template;this.outside?t?this.append(i,e):this.append(n,e):this.append(i,e)}onMouseEnter({$control:t,$panel:e}){if(!this.lifecycle.active)return;const{$player:i}=this.art.template,n=t.getBoundingClientRect(),s=e.getBoundingClientRect(),a=i.getBoundingClientRect(),r=s.width/2-n.width/2,o=a.left-(n.left-r),l=n.right+r-a.right;e.style.left=o>0?`${-r+o}px`:l>0?-r-l+"px":-r+"px"}emit(){return async function(t){const{lifecycle:e,template:{$input:i}}=t;if(!e.active)return;const n=i.value.trim();if(!n.length||t.isLock||t.emitting)return;const s={text:n,mode:t.option.mode,color:t.option.color,time:t.art.currentTime},a=t=>{e.active&&console.error("Error emitting danmuku:",t)};try{t.emitting=!0;const n=await e.wait(t.option.beforeEmit(s));if(!e.active)return;if(t.emitting=!1,!0!==n)return;if(s.border=!0,delete s.time,Promise.resolve(t.danmuku.emit(s)).catch(a),!e.active)return;i.value="",t.lock()}catch(r){a(r),e.active&&(t.emitting=!1)}}(this)}lock(){!function(t){if(!t.lifecycle.active)return;const{addClass:e}=t.utils,{$send:i}=t.template;clearTimeout(t.timer),t.isLock=!0;let n=t.option.lockTime;i.textContent=n,e(i,"apd-lock");const s=()=>{t.timer=setTimeout(()=>{t.lifecycle.active&&(0===n?t.unlock():(n-=1,i.textContent=n,s()))},1e3)};s()}(this)}unlock(){!function(t){if(clearTimeout(t.timer),t.timer=null,t.isLock=!1,!t.lifecycle.active)return;const{removeClass:e}=t.utils,{$send:i}=t.template;i.textContent="\u53d1\u9001",e(i,"apd-lock")}(this)}resize(){if(!this.lifecycle.active)return;if(this.outside)return;if(this.art.fullscreen)return;if(this.art.fullscreenWeb)return;const{$player:t,$controlsCenter:e}=this.art.template,{$danmuku:i}=this.template;this.art.width<this.option.width?this.append(t,i):this.append(e,i)}reset(){if(!this.lifecycle.active)return;const{inverseClass:t,tooltip:e}=this.utils,{$toggle:i,$colors:n}=this.template;for(const r of Object.values(this.slider))if(r.reset(),!this.lifecycle.active)return;this.setData("danmukuVisible",this.option.visible),this.setData("danmukuMode",this.option.mode),this.setData("danmukuColor",this.option.color),this.setData("danmukuMode0",this.option.modes.includes(0)),this.setData("danmukuMode1",this.option.modes.includes(1)),this.setData("danmukuMode2",this.option.modes.includes(2)),this.setData("danmukuAntiOverlap",this.option.antiOverlap),this.setData("danmukuSyncVideo",this.option.synchronousPlayback),this.setData("danmukuTheme",this.option.theme),this.setData("danmukuEmitter",this.option.emitter);const s=n.children,a=Array.from(s).find(t=>t.dataset.color===this.option.color.toUpperCase());a&&t(a,"apd-active"),e(i,this.option.visible?"\u5173\u95ed\u5f39\u5e55":"\u6253\u5f00\u5f39\u5e55"),this.resize()}mount(t){if(!this.lifecycle.active)return;const{errorHandle:e}=this.utils,i="string"===typeof t?document.querySelector(t):t;e(i,`Can not find the mount point: ${t}`),this.append(i,this.template.$danmuku),this.template.$mount=i,this.reset()}destroy(){if(this.lifecycle.closed)return;this.lifecycle.close(),clearTimeout(this.timer),this.timer=null,this.emitting=!1,this.isLock=!1;const t=this.template.$danmuku;t?.parentElement&&t.parentElement.removeChild(t)}}function U(t){return e=>{const i=new $(e,t);let n;try{n=e.isDestroy?void 0:new _(e,i),!e.isDestroy&&i.option.heatmap&&C(e,i,i.option.heatmap)}catch(s){try{n?.destroy()}catch{}try{i.destroy()}catch{}throw s}return{name:"artplayerPluginDanmuku",emit:i.emit.bind(i),load:i.load.bind(i),config:i.config.bind(i),hide:i.hide.bind(i),show:i.show.bind(i),reset:i.reset.bind(i),mount:n?n.mount.bind(n):()=>{},get option(){return i.option},get isHide(){return i.isHide},get isStop(){return i.isStop}}}}return U.icons=_.icons,U});
|