From df6a6fe82e25bf7da94b227937ac050123673b74 Mon Sep 17 00:00:00 2001 From: Harvey Zhao Date: Sun, 13 Sep 2026 22:24:09 +0800 Subject: [PATCH] fix(danmuku): [PKG-DANMUKU-11] start visible lifetime after Worker placement --- docs/compiled/artplayer-plugin-danmuku.js | 2 +- .../artplayer-plugin-danmuku.legacy.js | 2 +- docs/compiled/artplayer-plugin-danmuku.mjs | 1 + .../artplayer-plugin-danmuku/index.js | 1 + .../artplayer-plugin-danmuku/ARCHITECTURE.md | 8 + .../dist/artplayer-plugin-danmuku.js | 2 +- .../dist/artplayer-plugin-danmuku.legacy.js | 2 +- .../dist/artplayer-plugin-danmuku.mjs | 1 + .../artplayer-plugin-danmuku/src/scheduler.ts | 2 + .../danmuku-lifetime-validation.json | 3059 +++++++++++++++++ ...6-09-13-PKG-DANMUKU-11-visible-lifetime.md | 43 + refactor/plan.md | 10 +- refactor/progress.md | 12 + refactor/risk-table.md | 1 + refactor/risks.json | 22 + refactor/tasks.json | 22 +- test/browser/danmuku-lifetime.spec.js | 92 + test/danmuku-scheduler.test.js | 55 + 18 files changed, 3328 insertions(+), 9 deletions(-) create mode 100644 refactor/baselines/danmuku-lifetime-validation.json create mode 100644 refactor/changes/2026-09-13-PKG-DANMUKU-11-visible-lifetime.md create mode 100644 test/browser/danmuku-lifetime.spec.js diff --git a/docs/compiled/artplayer-plugin-danmuku.js b/docs/compiled/artplayer-plugin-danmuku.js index 6ae4f81f1..d47db3b7b 100644 --- a/docs/compiled/artplayer-plugin-danmuku.js +++ b/docs/compiled/artplayer-plugin-danmuku.js @@ -4,4 +4,4 @@ * (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(/]*?p="(?

[^"]+)"[^>]*>(?.*?)<\/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,a=i(e);globalThis.postMessage({danmus:a,id:n})}let a=0;function s(t,{signal:s,onCancel:r}={}){return new Promise((o,l)=>{let d,c,p,h=!1;const u=++a,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}(s));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!==c){const n=c;c=void 0;try{URL.revokeObjectURL(n)}catch(i){e||(t=i),e=!0}}if(e)throw t}function g(t,e){if(h)return;h=!0;let i=arguments.length>1;s?.removeEventListener("abort",m),p?.();try{f()}catch(n){i||(e=n),i=!0}i?l(e):o(t)}function y(t,e){if(!h){console.error("Error parsing Bilibili Danmu:",e);try{g(i(t))}catch(n){g(void 0,n)}}}s?.aborted?m():(s?.addEventListener("abort",m),p=r?.(m),h?p?.():async function(){const a=s?await fetch(t,{signal:s}):await fetch(t);if(h)return;const r=await a.text();if(!h)try{const t=`\n ${e.toString()}\n ${i.toString()}\n onmessage = ${n.toString()}\n `;if(c=URL.createObjectURL(new Blob([t],{type:"application/javascript"})),h)return void f();if(d=new Worker(c),h)return void f();d.onmessage=t=>{if(h||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 c(t){const e=l(t);e.closed=!0;for(const i of[...e.tasks])i.cancel()}function p(t,e,i){const n=t.states[e]||[];for(let a=0;a{const a=n.$ref.offsetTop,s=this.owner.getLeft(n.$ref)-i,r=n.$ref.clientHeight,o=n.$ref.clientWidth,l=s+o,d=e-l,c=l/n.$restTime,p={};p.top=a,p.left=s,p.height=r,p.width=o,p.right=d,p.speed=c,p.distance=l,p.time=n.$restTime,p.mode=n.mode,t.push(p)}),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,a){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=`${a}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()}}const u=Symbol("cancelled danmuku frame");class m{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}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()}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;!this.running||this.closed||this.fault||t.art.isDestroy||t.isStop||null!==this.frame||this.operation||(this.frame=window.requestAnimationFrame(()=>{if(this.frame=null,t.timer=null,this.closed||this.fault||t.isStop||t.art.isDestroy)return;let e;const i=new Promise(t=>e=()=>t(u)),n={generation:this.generation,cancel:e,wait:t=>Promise.race([t,i]),ref:null};return this.operation=n,this.run(n).catch(t=>{this.active(n)&&this.fail(t)}).finally(()=>{this.release(n),this.operation===n&&(this.operation=null,this.schedule())})}),t.timer=this.frame)}async run(t){const e=this.owner;if(!e.art.playing||!this.active(t))return;e.filter("emit",t=>{const i=(Date.now()-t.$lastStartTime)/1e3;t.$restTime-=i,t.$lastStartTime=Date.now(),t.$restTime<=0&&e.makeWait(t)});const i=e.readys;for(const a of i){if(!this.active(t))return;if(this.failedItems.has(a))continue;let i;try{i=await t.wait(e.option.beforeVisible(a))}catch(n){if(!this.active(t))return;this.failedItems.add(a),this.report(n);continue}if(!this.active(t))return;if(!i)continue;const{clientWidth:s,clientHeight:r}=e.$player,o=e.renderer.prepare(a,t);if(!this.active(t))return;a.$lastStartTime=Date.now(),a.$restTime=e.speed;const l=s+o.clientWidth,d=await t.wait(e.postMessage({type:"getDanmuTop",target:{mode:a.mode,height:o.clientHeight,speed:l/a.$restTime},visibles:e.visibles,antiOverlap:e.option.antiOverlap,clientWidth:s,clientHeight:r,marginBottom:e.marginBottom,marginTop:e.marginTop})),c="symbol"===typeof d?void 0:d.result;if(!this.active(t)||a.$ref!==o)return;void 0!==c?(e.setState(a,"emit"),e.renderer.place(a,o,c,l,s),t.ref=null,e.art.emit("artplayerPluginDanmuku:visible",a)):(e.setState(a,"ready"),this.release(t))}}destroy(){this.closed=!0,this.invalidate()}}let f=0;class g{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=++f;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(a){this.fail(a)}})}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 y='/*!\n * artplayer-plugin-danmuku.js v5.3.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=t.height)return h}const a=[];for(let g=1;g{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(ie.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',v="undefined"!==typeof self&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",y],{type:"text/javascript;charset=utf-8"});function w(t){let e;try{if(e=v&&(self.URL||self.webkitURL).createObjectURL(v),!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(y),{type:"module",name:t?.name})}}class k{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 h(this),this.scheduler=new m(this),this.option=k.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(a){throw t.off("destroy",this.destroy),c(this),this.scheduler.destroy(),a}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 k.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 k.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 k.option.fontSize}get $ref(){return this.renderer.acquire()}get readys(){return function(t){const{currentTime:e}=t.art,i=[];return p(t,"ready",t=>i.push(t)),p(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,a=i.closed||t.art.isDestroy;const s=new Promise(t=>n=t),r=new Set,d="function"===typeof AbortController?new AbortController:void 0,c={replace:e,signal:d?.signal,active:()=>!a&&!i.closed&&!t.art.isDestroy,onCancel:t=>c.active()?(r.add(t),()=>r.delete(t)):(t(),()=>{}),cancel(){if(!a){a=!0,n(o),d?.abort();for(const t of[...r])t();r.clear()}},wait:t=>Promise.race([t,s]),emit(e){i.emitting.push(c);try{return t.emit(e)}finally{i.emitting.pop()}},finish(){i.tasks.delete(c),r.clear()}};return a?n(o):i.tasks.add(c),c}(this,void 0===e);try{if(!n.active())return this;const a=function(e,i){return"function"===typeof e?{asynchronous:!0,value:e()}:t(e)?{asynchronous:!0,value:e}:"string"===typeof e?{asynchronous:!0,value:s(e,i)}:{asynchronous:!1,value:Array.isArray(e)?e:[]}}(e||this.option.danmuku,n),r=a.asynchronous?await n.wait(a.value):a.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{const i=s[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:a,mount:s}){const r=Object.assign({},i,t,e);return n(r),r.mode=a(r.mode,0,2),r.speed=a(r.speed,1,10),r.opacity=a(r.opacity,0,1),r.lockTime=a(r.lockTime,1,60),r.maxLength=a(r.maxLength,1,1e3),r.mount=r.mount||s,r}(this.option,e,{defaults:k.option,validate:t=>this.validator(t,k.scheme),clamp:n,mount:a});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 g(()=>new w,t=>this.scheduler.fail(t)),this.worker=this.workerClient.worker}filter(t,e){return p(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(){c(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 x=4294967295;function $(t,e){let i=0,n=t.length;for(;iNumber.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 a?a:{}),l=Object.assign({},r,o);for(const x of Object.keys(r))Number.isFinite(l[x])||(l[x]=r[x]);if(l.sampling<=0&&(l.sampling=r.sampling),l.xMin===l.xMax||l.yMin===l.yMax)return null;const d=Array.isArray(s)&&s.length>0,c=d?[...s]: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>x)return[];const a=t.map(t=>t.time).filter(t=>"number"===typeof t&&!Number.isNaN(t)).sort((t,e)=>t-e),s=[],r=i/e;if(!Number.isFinite(r))return[];for(let o=0;o<=e;o+=n){if(s.length>=x||o+n===o)return[];const t=o*r,e=(o+n)*r;s.push([o,$(a,e)-$(a,t)])}return s}(n,t,i,l.sampling);if(!c.length||!c.every(t=>Array.isArray(t)&&Number.isFinite(t[0])&&Number.isFinite(t[1])))return null;const p=c[c.length-1];if(p[0]!==t){if(c.length===x)return null;c.push([t,p[1]])}let h=1/0,u=-1/0;for(const x of c)h=Math.min(h,x[1]),u=Math.max(u,x[1]);const m=(h+u)/2;for(const x of c){const t=x[1];x[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 x of c)g=Math.max(g,x[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 a=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),s=b(Math.cos(a.angle)*l.flattening,0,1,1,0),r=a.angle*s+(n?Math.PI:0),o=a.length*l.smoothing;return[t[0]+Math.cos(r)*o,v(t[1]+Math.sin(r)*o)]},k=c.map(i=>[b(i[0],l.xMin,l.xMax,0,t),v(b(i[1],l.yMin,l.yMax,e,0))]);if(!k.every(t=>t.every(Number.isFinite)))return null;const M=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 a=w(n[i-1],n[i-2],t),s=w(t,n[i-1],n[i+1],!0);return`C ${a[0]},${a[1]} ${s[0]},${s[1]} ${t[0]},${t[1]}${i===n.length-1?" z":""}`}).join(" ");return/NaN|Infinity/u.test(M)?null:{path:M,opacity:l.opacity,width:t,height:e}}let S=0;function z(t,e,i){if(t.isDestroy)return;const{query:n}=t.constructor.utils;let a;const s=[];let r,o,l,d=!1;const c=()=>!d&&!t.isDestroy;function p(e,i){const n=i;s.push([e,n]),t.on(e,n)}function h(e){if(d)return;let i;d=!0,o=null,l=null;let n=!1;const a=t=>{try{t()}catch(e){n||(i=e),n=!0}};for(const[r,o]of s.splice(0))a(()=>t.off(r,o));if(e&&r&&t.controls.heatmap===r&&a(()=>t.controls.remove("heatmap")),r=void 0,n)throw i}function u(t){c()&&o&&l&&(o.setAttribute("offset",100*t+"%"),l.setAttribute("offset",100*t+"%"))}function m(s){try{!function(s=[]){if(!c())return;o=null,l=null;const d=r;if(d.innerHTML="",t.option.isLive)return;const p=M({width:d.offsetWidth,height:d.offsetHeight,duration:t.duration,queue:e.queue,option:i,points:s});if(!p||!c())return;const h=d.ownerDocument;for(a||(a=h?"heatmap-solids":"heatmap-solids-"+ ++S);h?.getElementById(a);)a="heatmap-solids-"+ ++S;d.innerHTML=`\n \n \n \n \n \n \n \n \n \n \n \n `,o=n("#heatmap-start",d),l=n("#heatmap-stop",d),u(t.played)}(s)}catch(d){try{h(!0)}catch{}throw d}}p("destroy",()=>h(!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(){h(!1)},mounted(e){if(r=e,d)return t.controls.heatmap===e&&t.controls.remove("heatmap"),void(r=void 0);c()?(p("video:timeupdate",()=>u(t.played)),p("setBar",(t,e)=>{"played"===t&&u(e)}),p("ready",()=>m()),p("resize",()=>m()),p("artplayerPluginDanmuku:loaded",()=>m()),p("artplayerPluginDanmuku:points",t=>m(t))):h(!0)}})}catch(f){try{h(!0)}catch{}throw f}return()=>h(!0)}const E=new WeakMap;class F{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 a=t;if(!this.active)return;const s=()=>"function"===typeof a.getPropertyPriority?a.getPropertyPriority(e):void 0;let r=E.get(a);r||(r=new Map,E.set(a,r));let o=r.get(e);o||(o={original:a[e],present:e in a||void 0!==a[e],priority:s(),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&&a[e]===o.last&&s()===o.lastPriority){const t=[...o.owners.values()];t.length?(o.apply(t[t.length-1]),o.last=a[e],o.lastPriority=s()):void 0!==o.priority?a.setProperty(e,o.original,o.priority):o.present?o.apply(o.original):delete a[e]}o.owners.size||(r.delete(e),r.size||E.delete(a))}),o.owners.delete(this),o.owners.set(this,i),o.apply(i),o.last=a[e],o.lastPriority=s()}on(t,e){if(!this.active)return;const i=this;function n(...t){if(i.active)return e.apply(this,t)}const a=()=>this.art.off(t,n);this.own(a);try{this.art.on(t,n),this.active||a()}catch(s){throw this.release(a),s}}proxy(t,e,i){if(!this.active)return;const n=this;function a(...t){if(n.active)return i.apply(this,t)}let s;const r=()=>{if("function"===typeof s){const t=this.art.events;"function"===typeof t?.remove&&t.destroyEvents?.has(s)?t.remove(s):s()}else t.removeEventListener?.(e,a)};this.own(r);try{s=this.art.proxy(t,e,a),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 C({min:t,max:e,container:i,findIndex:n,onChange:a,steps:s=[]}){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

\n
\n ${s.map(()=>'
').join("")}\n
\n
\n
\n
\n
\n ${s.map(t=>t.hide?"":`
${t.name}
`).join("")}\n
\n `;const c=o(".apd-slider-dot",i),p=o(".apd-slider-progress",i);let h=!1;function u(i){if(!r.active)return;if(void 0===i&&(i=n()),ie)return;const o=(i-t)/(e-t);c.style.left=100*o+"%",0===s.length&&(p.style.width=c.style.left),a(i)}function m(n){const{top:a,height:s,left:r,width:o}=i.getBoundingClientRect();if(this.art.isRotate){const i=l(n.clientY-a,0,s);u(Math.round(i/s*(e-t)+t))}else{const i=l(n.clientX-r,0,o);u(Math.round(i/o*(e-t)+t))}}return r.own(()=>h=!1),r.proxy(i,"click",t=>{m.call(this,t)}),r.proxy(i,"pointerdown",t=>{h=0===t.button}),r.on("document:pointermove",t=>{h&&m.call(this,t)}),r.on("document:pointerup",t=>{h&&(h=!1,m.call(this,t))}),{reset:u}}const D='',T='',P='',A='',L='',H='',O='',N='',V='',q='',I='',j='';function B(){const{option:t}=this;return`\n
\n ${I}${q}\n
\n
\n ${P}\n
\n
\n
\n \u6309\u7c7b\u578b\u5c4f\u853d\n
\n
\n ${A}${L}\n
\u6eda\u52a8
\n
\n
\n ${H}${O}\n
\u9876\u90e8
\n
\n
\n ${N}${V}\n
\u5e95\u90e8
\n
\n
\n
\n
\n
\n ${T}${D}\n \u9632\u6b62\u5f39\u5e55\u91cd\u53e0\n
\n
\n ${T}${D}\n \u540c\u6b65\u89c6\u9891\u901f\u5ea6\n
\n
\n
\n \u4e0d\u900f\u660e\u5ea6\n
\n
\u672a\u77e5
\n
\n
\n \u663e\u793a\u533a\u57df\n
\n
\u672a\u77e5
\n
\n
\n \u5f39\u5e55\u5b57\u53f7\n
\n
\u672a\u77e5
\n
\n
\n \u5f39\u5e55\u901f\u5ea6\n
\n
\u672a\u77e5
\n
\n
\n
\n
\n
\n
\n ${j}\n
\n
\n
\n \u6a21\u5f0f\n
\n
\n ${L}\n
\u6eda\u52a8
\n
\n
\n ${O}\n
\u9876\u90e8
\n
\n
\n ${V}\n
\u5e95\u90e8
\n
\n
\n
\n
\n \u989c\u8272\n
\n ${this.COLOR.map(t=>`
`).join("")}\n
\n
\n
\n
\n
\n \n
\u53d1\u9001
\n
\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 a=()=>{document.removeEventListener("DOMContentLoaded",a),i[e]===n&&delete i[e];const s=document.getElementById(t);s?s.textContent=n.textContent:(document.head||document.documentElement).appendChild(n)};document.addEventListener("DOMContentLoaded",a,{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 R{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 F(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(a){try{this.destroy()}catch(s){console.warn("Failed to roll back danmuku setting:",s)}throw a}}static get icons(){return{$on:I,$off:q,$config:P,$style:j,$mode_0_off:A,$mode_0_on:L,$mode_1_off:H,$mode_1_on:O,$mode_2_off:N,$mode_2_on:V,$check_on:T,$check_off:D}}get option(){return this.danmuku.option}get outside(){return this.template.$mount!==this.template.$controlsCenter}get TEMPLATE(){return B.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:a,$syncVideo:s,$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(a,"click",()=>{this.danmuku.config({antiOverlap:!this.option.antiOverlap}),this.reset()}),this.lifecycle.proxy(s,"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 C.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(),a=e.getBoundingClientRect(),s=i.getBoundingClientRect(),r=a.width/2-n.width/2,o=s.left-(n.left-r),l=n.right+r-s.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 a={text:n,mode:t.option.mode,color:t.option.color,time:t.art.currentTime},s=t=>{e.active&&console.error("Error emitting danmuku:",t)};try{t.emitting=!0;const n=await e.wait(t.option.beforeEmit(a));if(!e.active)return;if(t.emitting=!1,!0!==n)return;if(a.border=!0,delete a.time,Promise.resolve(t.danmuku.emit(a)).catch(s),!e.active)return;i.value="",t.lock()}catch(r){s(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 a=()=>{t.timer=setTimeout(()=>{t.lifecycle.active&&(0===n?t.unlock():(n-=1,i.textContent=n,a()))},1e3)};a()}(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.widtht.dataset.color===this.option.color.toUpperCase());s&&t(s,"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 Z(t){return e=>{const i=new k(e,t);let n;try{n=e.isDestroy?void 0:new R(e,i),!e.isDestroy&&i.option.heatmap&&z(e,i,i.option.heatmap)}catch(a){try{n?.destroy()}catch{}try{i.destroy()}catch{}throw a}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 Z.icons=R.icons,Z}); +!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(/]*?p="(?

[^"]+)"[^>]*>(?.*?)<\/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,a=i(e);globalThis.postMessage({danmus:a,id:n})}let a=0;function s(t,{signal:s,onCancel:r}={}){return new Promise((o,l)=>{let d,c,p,h=!1;const u=++a,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}(s));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!==c){const n=c;c=void 0;try{URL.revokeObjectURL(n)}catch(i){e||(t=i),e=!0}}if(e)throw t}function g(t,e){if(h)return;h=!0;let i=arguments.length>1;s?.removeEventListener("abort",m),p?.();try{f()}catch(n){i||(e=n),i=!0}i?l(e):o(t)}function y(t,e){if(!h){console.error("Error parsing Bilibili Danmu:",e);try{g(i(t))}catch(n){g(void 0,n)}}}s?.aborted?m():(s?.addEventListener("abort",m),p=r?.(m),h?p?.():async function(){const a=s?await fetch(t,{signal:s}):await fetch(t);if(h)return;const r=await a.text();if(!h)try{const t=`\n ${e.toString()}\n ${i.toString()}\n onmessage = ${n.toString()}\n `;if(c=URL.createObjectURL(new Blob([t],{type:"application/javascript"})),h)return void f();if(d=new Worker(c),h)return void f();d.onmessage=t=>{if(h||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 c(t){const e=l(t);e.closed=!0;for(const i of[...e.tasks])i.cancel()}function p(t,e,i){const n=t.states[e]||[];for(let a=0;a{const a=n.$ref.offsetTop,s=this.owner.getLeft(n.$ref)-i,r=n.$ref.clientHeight,o=n.$ref.clientWidth,l=s+o,d=e-l,c=l/n.$restTime,p={};p.top=a,p.left=s,p.height=r,p.width=o,p.right=d,p.speed=c,p.distance=l,p.time=n.$restTime,p.mode=n.mode,t.push(p)}),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,a){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=`${a}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()}}const u=Symbol("cancelled danmuku frame");class m{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}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()}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;!this.running||this.closed||this.fault||t.art.isDestroy||t.isStop||null!==this.frame||this.operation||(this.frame=window.requestAnimationFrame(()=>{if(this.frame=null,t.timer=null,this.closed||this.fault||t.isStop||t.art.isDestroy)return;let e;const i=new Promise(t=>e=()=>t(u)),n={generation:this.generation,cancel:e,wait:t=>Promise.race([t,i]),ref:null};return this.operation=n,this.run(n).catch(t=>{this.active(n)&&this.fail(t)}).finally(()=>{this.release(n),this.operation===n&&(this.operation=null,this.schedule())})}),t.timer=this.frame)}async run(t){const e=this.owner;if(!e.art.playing||!this.active(t))return;e.filter("emit",t=>{const i=(Date.now()-t.$lastStartTime)/1e3;t.$restTime-=i,t.$lastStartTime=Date.now(),t.$restTime<=0&&e.makeWait(t)});const i=e.readys;for(const a of i){if(!this.active(t))return;if(this.failedItems.has(a))continue;let i;try{i=await t.wait(e.option.beforeVisible(a))}catch(n){if(!this.active(t))return;this.failedItems.add(a),this.report(n);continue}if(!this.active(t))return;if(!i)continue;const{clientWidth:s,clientHeight:r}=e.$player,o=e.renderer.prepare(a,t);if(!this.active(t))return;a.$lastStartTime=Date.now(),a.$restTime=e.speed;const l=s+o.clientWidth,d=await t.wait(e.postMessage({type:"getDanmuTop",target:{mode:a.mode,height:o.clientHeight,speed:l/a.$restTime},visibles:e.visibles,antiOverlap:e.option.antiOverlap,clientWidth:s,clientHeight:r,marginBottom:e.marginBottom,marginTop:e.marginTop})),c="symbol"===typeof d?void 0:d.result;if(!this.active(t)||a.$ref!==o)return;void 0!==c?(a.$lastStartTime=Date.now(),e.setState(a,"emit"),e.renderer.place(a,o,c,l,s),t.ref=null,e.art.emit("artplayerPluginDanmuku:visible",a)):(e.setState(a,"ready"),this.release(t))}}destroy(){this.closed=!0,this.invalidate()}}let f=0;class g{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=++f;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(a){this.fail(a)}})}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 y='/*!\n * artplayer-plugin-danmuku.js v5.3.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=t.height)return h}const a=[];for(let g=1;g{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(ie.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',v="undefined"!==typeof self&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",y],{type:"text/javascript;charset=utf-8"});function w(t){let e;try{if(e=v&&(self.URL||self.webkitURL).createObjectURL(v),!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(y),{type:"module",name:t?.name})}}class k{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 h(this),this.scheduler=new m(this),this.option=k.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(a){throw t.off("destroy",this.destroy),c(this),this.scheduler.destroy(),a}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 k.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 k.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 k.option.fontSize}get $ref(){return this.renderer.acquire()}get readys(){return function(t){const{currentTime:e}=t.art,i=[];return p(t,"ready",t=>i.push(t)),p(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,a=i.closed||t.art.isDestroy;const s=new Promise(t=>n=t),r=new Set,d="function"===typeof AbortController?new AbortController:void 0,c={replace:e,signal:d?.signal,active:()=>!a&&!i.closed&&!t.art.isDestroy,onCancel:t=>c.active()?(r.add(t),()=>r.delete(t)):(t(),()=>{}),cancel(){if(!a){a=!0,n(o),d?.abort();for(const t of[...r])t();r.clear()}},wait:t=>Promise.race([t,s]),emit(e){i.emitting.push(c);try{return t.emit(e)}finally{i.emitting.pop()}},finish(){i.tasks.delete(c),r.clear()}};return a?n(o):i.tasks.add(c),c}(this,void 0===e);try{if(!n.active())return this;const a=function(e,i){return"function"===typeof e?{asynchronous:!0,value:e()}:t(e)?{asynchronous:!0,value:e}:"string"===typeof e?{asynchronous:!0,value:s(e,i)}:{asynchronous:!1,value:Array.isArray(e)?e:[]}}(e||this.option.danmuku,n),r=a.asynchronous?await n.wait(a.value):a.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{const i=s[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:a,mount:s}){const r=Object.assign({},i,t,e);return n(r),r.mode=a(r.mode,0,2),r.speed=a(r.speed,1,10),r.opacity=a(r.opacity,0,1),r.lockTime=a(r.lockTime,1,60),r.maxLength=a(r.maxLength,1,1e3),r.mount=r.mount||s,r}(this.option,e,{defaults:k.option,validate:t=>this.validator(t,k.scheme),clamp:n,mount:a});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 g(()=>new w,t=>this.scheduler.fail(t)),this.worker=this.workerClient.worker}filter(t,e){return p(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(){c(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 x=4294967295;function $(t,e){let i=0,n=t.length;for(;iNumber.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 a?a:{}),l=Object.assign({},r,o);for(const x of Object.keys(r))Number.isFinite(l[x])||(l[x]=r[x]);if(l.sampling<=0&&(l.sampling=r.sampling),l.xMin===l.xMax||l.yMin===l.yMax)return null;const d=Array.isArray(s)&&s.length>0,c=d?[...s]: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>x)return[];const a=t.map(t=>t.time).filter(t=>"number"===typeof t&&!Number.isNaN(t)).sort((t,e)=>t-e),s=[],r=i/e;if(!Number.isFinite(r))return[];for(let o=0;o<=e;o+=n){if(s.length>=x||o+n===o)return[];const t=o*r,e=(o+n)*r;s.push([o,$(a,e)-$(a,t)])}return s}(n,t,i,l.sampling);if(!c.length||!c.every(t=>Array.isArray(t)&&Number.isFinite(t[0])&&Number.isFinite(t[1])))return null;const p=c[c.length-1];if(p[0]!==t){if(c.length===x)return null;c.push([t,p[1]])}let h=1/0,u=-1/0;for(const x of c)h=Math.min(h,x[1]),u=Math.max(u,x[1]);const m=(h+u)/2;for(const x of c){const t=x[1];x[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 x of c)g=Math.max(g,x[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 a=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),s=b(Math.cos(a.angle)*l.flattening,0,1,1,0),r=a.angle*s+(n?Math.PI:0),o=a.length*l.smoothing;return[t[0]+Math.cos(r)*o,v(t[1]+Math.sin(r)*o)]},k=c.map(i=>[b(i[0],l.xMin,l.xMax,0,t),v(b(i[1],l.yMin,l.yMax,e,0))]);if(!k.every(t=>t.every(Number.isFinite)))return null;const M=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 a=w(n[i-1],n[i-2],t),s=w(t,n[i-1],n[i+1],!0);return`C ${a[0]},${a[1]} ${s[0]},${s[1]} ${t[0]},${t[1]}${i===n.length-1?" z":""}`}).join(" ");return/NaN|Infinity/u.test(M)?null:{path:M,opacity:l.opacity,width:t,height:e}}let S=0;function z(t,e,i){if(t.isDestroy)return;const{query:n}=t.constructor.utils;let a;const s=[];let r,o,l,d=!1;const c=()=>!d&&!t.isDestroy;function p(e,i){const n=i;s.push([e,n]),t.on(e,n)}function h(e){if(d)return;let i;d=!0,o=null,l=null;let n=!1;const a=t=>{try{t()}catch(e){n||(i=e),n=!0}};for(const[r,o]of s.splice(0))a(()=>t.off(r,o));if(e&&r&&t.controls.heatmap===r&&a(()=>t.controls.remove("heatmap")),r=void 0,n)throw i}function u(t){c()&&o&&l&&(o.setAttribute("offset",100*t+"%"),l.setAttribute("offset",100*t+"%"))}function m(s){try{!function(s=[]){if(!c())return;o=null,l=null;const d=r;if(d.innerHTML="",t.option.isLive)return;const p=M({width:d.offsetWidth,height:d.offsetHeight,duration:t.duration,queue:e.queue,option:i,points:s});if(!p||!c())return;const h=d.ownerDocument;for(a||(a=h?"heatmap-solids":"heatmap-solids-"+ ++S);h?.getElementById(a);)a="heatmap-solids-"+ ++S;d.innerHTML=`\n \n \n \n \n \n \n \n \n \n \n \n `,o=n("#heatmap-start",d),l=n("#heatmap-stop",d),u(t.played)}(s)}catch(d){try{h(!0)}catch{}throw d}}p("destroy",()=>h(!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(){h(!1)},mounted(e){if(r=e,d)return t.controls.heatmap===e&&t.controls.remove("heatmap"),void(r=void 0);c()?(p("video:timeupdate",()=>u(t.played)),p("setBar",(t,e)=>{"played"===t&&u(e)}),p("ready",()=>m()),p("resize",()=>m()),p("artplayerPluginDanmuku:loaded",()=>m()),p("artplayerPluginDanmuku:points",t=>m(t))):h(!0)}})}catch(f){try{h(!0)}catch{}throw f}return()=>h(!0)}const E=new WeakMap;class F{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 a=t;if(!this.active)return;const s=()=>"function"===typeof a.getPropertyPriority?a.getPropertyPriority(e):void 0;let r=E.get(a);r||(r=new Map,E.set(a,r));let o=r.get(e);o||(o={original:a[e],present:e in a||void 0!==a[e],priority:s(),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&&a[e]===o.last&&s()===o.lastPriority){const t=[...o.owners.values()];t.length?(o.apply(t[t.length-1]),o.last=a[e],o.lastPriority=s()):void 0!==o.priority?a.setProperty(e,o.original,o.priority):o.present?o.apply(o.original):delete a[e]}o.owners.size||(r.delete(e),r.size||E.delete(a))}),o.owners.delete(this),o.owners.set(this,i),o.apply(i),o.last=a[e],o.lastPriority=s()}on(t,e){if(!this.active)return;const i=this;function n(...t){if(i.active)return e.apply(this,t)}const a=()=>this.art.off(t,n);this.own(a);try{this.art.on(t,n),this.active||a()}catch(s){throw this.release(a),s}}proxy(t,e,i){if(!this.active)return;const n=this;function a(...t){if(n.active)return i.apply(this,t)}let s;const r=()=>{if("function"===typeof s){const t=this.art.events;"function"===typeof t?.remove&&t.destroyEvents?.has(s)?t.remove(s):s()}else t.removeEventListener?.(e,a)};this.own(r);try{s=this.art.proxy(t,e,a),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 C({min:t,max:e,container:i,findIndex:n,onChange:a,steps:s=[]}){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

\n
\n ${s.map(()=>'
').join("")}\n
\n
\n
\n
\n
\n ${s.map(t=>t.hide?"":`
${t.name}
`).join("")}\n
\n `;const c=o(".apd-slider-dot",i),p=o(".apd-slider-progress",i);let h=!1;function u(i){if(!r.active)return;if(void 0===i&&(i=n()),ie)return;const o=(i-t)/(e-t);c.style.left=100*o+"%",0===s.length&&(p.style.width=c.style.left),a(i)}function m(n){const{top:a,height:s,left:r,width:o}=i.getBoundingClientRect();if(this.art.isRotate){const i=l(n.clientY-a,0,s);u(Math.round(i/s*(e-t)+t))}else{const i=l(n.clientX-r,0,o);u(Math.round(i/o*(e-t)+t))}}return r.own(()=>h=!1),r.proxy(i,"click",t=>{m.call(this,t)}),r.proxy(i,"pointerdown",t=>{h=0===t.button}),r.on("document:pointermove",t=>{h&&m.call(this,t)}),r.on("document:pointerup",t=>{h&&(h=!1,m.call(this,t))}),{reset:u}}const D='',T='',P='',A='',L='',H='',O='',N='',V='',q='',I='',j='';function B(){const{option:t}=this;return`\n
\n ${I}${q}\n
\n
\n ${P}\n
\n
\n
\n \u6309\u7c7b\u578b\u5c4f\u853d\n
\n
\n ${A}${L}\n
\u6eda\u52a8
\n
\n
\n ${H}${O}\n
\u9876\u90e8
\n
\n
\n ${N}${V}\n
\u5e95\u90e8
\n
\n
\n
\n
\n
\n ${T}${D}\n \u9632\u6b62\u5f39\u5e55\u91cd\u53e0\n
\n
\n ${T}${D}\n \u540c\u6b65\u89c6\u9891\u901f\u5ea6\n
\n
\n
\n \u4e0d\u900f\u660e\u5ea6\n
\n
\u672a\u77e5
\n
\n
\n \u663e\u793a\u533a\u57df\n
\n
\u672a\u77e5
\n
\n
\n \u5f39\u5e55\u5b57\u53f7\n
\n
\u672a\u77e5
\n
\n
\n \u5f39\u5e55\u901f\u5ea6\n
\n
\u672a\u77e5
\n
\n
\n
\n
\n
\n
\n ${j}\n
\n
\n
\n \u6a21\u5f0f\n
\n
\n ${L}\n
\u6eda\u52a8
\n
\n
\n ${O}\n
\u9876\u90e8
\n
\n
\n ${V}\n
\u5e95\u90e8
\n
\n
\n
\n
\n \u989c\u8272\n
\n ${this.COLOR.map(t=>`
`).join("")}\n
\n
\n
\n
\n
\n \n
\u53d1\u9001
\n
\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 a=()=>{document.removeEventListener("DOMContentLoaded",a),i[e]===n&&delete i[e];const s=document.getElementById(t);s?s.textContent=n.textContent:(document.head||document.documentElement).appendChild(n)};document.addEventListener("DOMContentLoaded",a,{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 R{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 F(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(a){try{this.destroy()}catch(s){console.warn("Failed to roll back danmuku setting:",s)}throw a}}static get icons(){return{$on:I,$off:q,$config:P,$style:j,$mode_0_off:A,$mode_0_on:L,$mode_1_off:H,$mode_1_on:O,$mode_2_off:N,$mode_2_on:V,$check_on:T,$check_off:D}}get option(){return this.danmuku.option}get outside(){return this.template.$mount!==this.template.$controlsCenter}get TEMPLATE(){return B.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:a,$syncVideo:s,$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(a,"click",()=>{this.danmuku.config({antiOverlap:!this.option.antiOverlap}),this.reset()}),this.lifecycle.proxy(s,"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 C.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(),a=e.getBoundingClientRect(),s=i.getBoundingClientRect(),r=a.width/2-n.width/2,o=s.left-(n.left-r),l=n.right+r-s.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 a={text:n,mode:t.option.mode,color:t.option.color,time:t.art.currentTime},s=t=>{e.active&&console.error("Error emitting danmuku:",t)};try{t.emitting=!0;const n=await e.wait(t.option.beforeEmit(a));if(!e.active)return;if(t.emitting=!1,!0!==n)return;if(a.border=!0,delete a.time,Promise.resolve(t.danmuku.emit(a)).catch(s),!e.active)return;i.value="",t.lock()}catch(r){s(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 a=()=>{t.timer=setTimeout(()=>{t.lifecycle.active&&(0===n?t.unlock():(n-=1,i.textContent=n,a()))},1e3)};a()}(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.widtht.dataset.color===this.option.color.toUpperCase());s&&t(s,"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 Z(t){return e=>{const i=new k(e,t);let n;try{n=e.isDestroy?void 0:new R(e,i),!e.isDestroy&&i.option.heatmap&&z(e,i,i.option.heatmap)}catch(a){try{n?.destroy()}catch{}try{i.destroy()}catch{}throw a}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 Z.icons=R.icons,Z}); diff --git a/docs/compiled/artplayer-plugin-danmuku.legacy.js b/docs/compiled/artplayer-plugin-danmuku.legacy.js index 4811a82a9..476669bee 100644 --- a/docs/compiled/artplayer-plugin-danmuku.legacy.js +++ b/docs/compiled/artplayer-plugin-danmuku.legacy.js @@ -4,4 +4,4 @@ * (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";var t=Object.defineProperty,e=Object.defineProperties,i=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable,r=Math.pow,o=(e,i,n)=>i in e?t(e,i,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[i]=n,l=(t,e)=>{for(var i in e||(e={}))a.call(e,i)&&o(t,i,e[i]);if(n)for(var i of n(e))s.call(e,i)&&o(t,i,e[i]);return t},d=(t,n)=>e(t,i(n)),c=(t,e,i)=>new Promise((n,a)=>{var s=t=>{try{o(i.next(t))}catch(e){a(e)}},r=t=>{try{o(i.throw(t))}catch(e){a(e)}},o=t=>t.done?n(t.value):Promise.resolve(t.value).then(s,r);o((i=i.apply(t,e)).next())});function p(t){return t instanceof Promise||"[object Promise]"===Object.prototype.toString.call(t)}function h(t){switch(t){case 1:case 2:case 3:default:return 0;case 4:return 2;case 5:return 1}}function u(t){if("string"!==typeof t)return[];const e=new RegExp(']*?p="(?

[^"]+)"[^>]*>(?.*?)<\\/d>',"gs"),i=t.matchAll(e);return Array.from(i).map(t=>{const e=t.groups.p.split(",");if(e.length>=8){return{text:t.groups.text.trim().replaceAll(""",'"').replaceAll("'","'").replaceAll("<","<").replaceAll(">",">").replaceAll("&","&"),time:Number(e[0]),mode:h(Number(e[1])),fontSize:Number(e[2]),color:`#${Number(e[3]).toString(16)}`,timestamp:Number(e[4]),pool:Number(e[5]),userID:e[6],rowID:Number(e[7])}}return null}).filter(Boolean)}function m({data:t}){const{xml:e,id:i}=t,n=u(e);globalThis.postMessage({danmus:n,id:i})}let f=0;function g(t,{signal:e,onCancel:i}={}){return new Promise((n,a)=>{let s,r,o,l=!1;const d=++f,p=()=>y(void 0,function(t){if(void 0!==(null==t?void 0:t.reason))return t.reason;const e=new Error("Bilibili Danmu loading cancelled");return e.name="AbortError",e}(e));function g(){let t,e=!1;try{if(s){const t=s;s=void 0,t.onmessage=null,t.onerror=null,t.onmessageerror=null,t.terminate()}}catch(i){t=i,e=!0}if(void 0!==r){const n=r;r=void 0;try{URL.revokeObjectURL(n)}catch(i){e||(t=i),e=!0}}if(e)throw t}function y(t,i){if(l)return;l=!0;let s=arguments.length>1;null==e||e.removeEventListener("abort",p),null==o||o();try{g()}catch(r){s||(i=r),s=!0}s?a(i):n(t)}function v(t,e){if(!l){console.error("Error parsing Bilibili Danmu:",e);try{y(u(t))}catch(i){y(void 0,i)}}}(null==e?void 0:e.aborted)?p():(null==e||e.addEventListener("abort",p),o=null==i?void 0:i(p),l?null==o||o():function(){return c(this,null,function*(){const i=e?yield fetch(t,{signal:e}):yield fetch(t);if(l)return;const n=yield i.text();if(!l)try{const t=`\n ${h.toString()}\n ${u.toString()}\n onmessage = ${m.toString()}\n `;if(r=URL.createObjectURL(new Blob([t],{type:"application/javascript"})),l)return void g();if(s=new Worker(r),l)return void g();s.onmessage=t=>{var e;if(l||(null==(e=t.data)?void 0:e.id)!==d)return;const{danmus:i}=t.data;Array.isArray(i)?y(i):y(void 0,new Error("Invalid Bilibili Danmu worker response"))},s.onerror=t=>{var e;null==(e=t.preventDefault)||e.call(t),v(n,t.error||t)},s.onmessageerror=t=>v(n,t.error||t),s.postMessage({xml:n,id:d})}catch(a){v(n,a)}})}().catch(t=>y(void 0,t)))})}const y=new WeakMap,v=Symbol("cancelled danmuku input");function w(t){return y.has(t)||y.set(t,{closed:!1,tasks:new Set,emitting:[]}),y.get(t)}function k(t){const e=w(t),i=e.emitting[e.emitting.length-1];return!e.closed&&!t.art.isDestroy&&(!i||i.active())}function x(t){const e=w(t);e.closed=!0;for(const i of[...e.tasks])i.cancel()}function b(t,e,i){const n=t.states[e]||[];for(let a=0;a{const a=n.$ref.offsetTop,s=this.owner.getLeft(n.$ref)-i,r=n.$ref.clientHeight,o=n.$ref.clientWidth,l=s+o,d=e-l,c=l/n.$restTime,p={};p.top=a,p.left=s,p.height=r,p.width=o,p.right=d,p.speed=c,p.distance=l,p.time=n.$restTime,p.mode=n.mode,t.push(p)}),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,a){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=`${a}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()}}const M=Symbol("cancelled danmuku frame");class S{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}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(){var t;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)}null==(t=this.owner.workerClient)||t.cancel(),this.failedItems.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(){var t;if(!this.closed&&!this.owner.art.isDestroy&&(this.failedItems.clear(),this.fault))try{null==(t=this.owner.workerClient)||t.dispose(),this.owner.createWorker(),this.fault=!1}catch(e){this.report(e)}}schedule(){const t=this.owner;!this.running||this.closed||this.fault||t.art.isDestroy||t.isStop||null!==this.frame||this.operation||(this.frame=window.requestAnimationFrame(()=>{if(this.frame=null,t.timer=null,this.closed||this.fault||t.isStop||t.art.isDestroy)return;let e;const i=new Promise(t=>e=()=>t(M)),n={generation:this.generation,cancel:e,wait:t=>Promise.race([t,i]),ref:null};return this.operation=n,this.run(n).catch(t=>{this.active(n)&&this.fail(t)}).finally(()=>{this.release(n),this.operation===n&&(this.operation=null,this.schedule())})}),t.timer=this.frame)}run(t){return c(this,null,function*(){const e=this.owner;if(!e.art.playing||!this.active(t))return;e.filter("emit",t=>{const i=(Date.now()-t.$lastStartTime)/1e3;t.$restTime-=i,t.$lastStartTime=Date.now(),t.$restTime<=0&&e.makeWait(t)});const i=e.readys;for(const a of i){if(!this.active(t))return;if(this.failedItems.has(a))continue;let i;try{i=yield t.wait(e.option.beforeVisible(a))}catch(n){if(!this.active(t))return;this.failedItems.add(a),this.report(n);continue}if(!this.active(t))return;if(!i)continue;const{clientWidth:s,clientHeight:r}=e.$player,o=e.renderer.prepare(a,t);if(!this.active(t))return;a.$lastStartTime=Date.now(),a.$restTime=e.speed;const l=s+o.clientWidth,d=yield t.wait(e.postMessage({type:"getDanmuTop",target:{mode:a.mode,height:o.clientHeight,speed:l/a.$restTime},visibles:e.visibles,antiOverlap:e.option.antiOverlap,clientWidth:s,clientHeight:r,marginBottom:e.marginBottom,marginTop:e.marginTop})),c="symbol"===typeof d?void 0:d.result;if(!this.active(t)||a.$ref!==o)return;void 0!==c?(e.setState(a,"emit"),e.renderer.place(a,o,c,l,s),t.ref=null,e.art.emit("artplayerPluginDanmuku:visible",a)):(e.setState(a,"ready"),this.release(t))}})}destroy(){this.closed=!0,this.invalidate()}}let z=0;class E{constructor(t,e){this.pending=new Map,this.closed=!1,this.failed=!1,this.onFailure=e,this.worker=t();try{this.worker.onmessage=t=>{var e;const i=this.pending.get(null==(e=t.data)?void 0:e.id);i&&(this.pending.delete(t.data.id),i.resolve(t.data))},this.worker.onerror=t=>{var e;null==(e=t.preventDefault)||e.call(t),this.fail(t.error||t)},this.worker.onmessageerror=t=>this.fail(t.error||t)}catch(i){try{this.dispose()}catch(n){}throw i}}request(t){t.id=++z;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(a){this.fail(a)}})}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(e){}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 F='/*!\n * artplayer-plugin-danmuku.js v5.3.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=t.height)return h}const a=[];for(let g=1;g{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(ie.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',C="undefined"!==typeof self&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",F],{type:"text/javascript;charset=utf-8"});function D(t){let e;try{if(e=C&&(self.URL||self.webkitURL).createObjectURL(C),!e)throw"";const i=new Worker(e,{type:"module",name:null==t?void 0: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(F),{type:"module",name:null==t?void 0:t.name})}}class P{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 $(this),this.scheduler=new S(this),this.option=P.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),k(this),t.on("destroy",this.destroy);try{if(this.config(e,!0),!k(this))return;this.createWorker()}catch(a){throw t.off("destroy",this.destroy),x(this),this.scheduler.destroy(),a}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(){var t,e;return null==(e=null==(t=this.art.plugins)?void 0:t.autoOrientation)?void 0:e.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 P.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 P.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 P.option.fontSize}get $ref(){return this.renderer.acquire()}get readys(){return function(t){const{currentTime:e}=t.art,i=[];return b(t,"ready",t=>i.push(t)),b(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}load(t){return c(this,null,function*(){const{errorHandle:e}=this.utils,i=function(t,e){const i=w(t);if(e)for(const d of[...i.tasks])d.replace&&d.cancel();let n,a=i.closed||t.art.isDestroy;const s=new Promise(t=>n=t),r=new Set,o="function"===typeof AbortController?new AbortController:void 0,l={replace:e,signal:null==o?void 0:o.signal,active:()=>!a&&!i.closed&&!t.art.isDestroy,onCancel:t=>l.active()?(r.add(t),()=>r.delete(t)):(t(),()=>{}),cancel(){if(!a){a=!0,n(v),null==o||o.abort();for(const t of[...r])t();r.clear()}},wait:t=>Promise.race([t,s]),emit(e){i.emitting.push(l);try{return t.emit(e)}finally{i.emitting.pop()}},finish(){i.tasks.delete(l),r.clear()}};return a?n(v):i.tasks.add(l),l}(this,void 0===t);try{if(!i.active())return this;const n=function(t,e){return"function"===typeof t?{asynchronous:!0,value:t()}:p(t)?{asynchronous:!0,value:t}:"string"===typeof t?{asynchronous:!0,value:g(t,e)}:{asynchronous:!1,value:Array.isArray(t)?t:[]}}(t||this.option.danmuku,i),a=n.asynchronous?yield i.wait(n.value):n.value;if(!i.active())return this;e(Array.isArray(a),"Danmuku need return an array as result");const s=a;if(void 0===t){if(this.reset(),!i.active())return this;this.queue=[],this.states={wait:[],ready:[],emit:[],stop:[]},this.renderer.clear()}for(let t=0;t{const e=a[t],i=s[t];return"function"===typeof e||"function"===typeof i||p(e)||p(i)?e!==i:JSON.stringify(e)!==JSON.stringify(i)}))&&!e)return this;const r=function(t,e,{defaults:i,validate:n,clamp:a,mount:s}){const r=Object.assign({},i,t,e);return n(r),r.mode=a(r.mode,0,2),r.speed=a(r.speed,1,10),r.opacity=a(r.opacity,0,1),r.lockTime=a(r.lockTime,1,60),r.maxLength=a(r.maxLength,1,1e3),r.mount=r.mount||s,r}(this.option,t,{defaults:P.option,validate:t=>this.validator(t,P.scheme),clamp:i,mount:n});if(!k(this))return this;const o=this.option.beforeVisible!==r.beforeVisible;return this.option=r,o&&(this.scheduler.invalidate(),this.scheduler.schedule()),t.fontSize&&(this.reset(),!k(this))||(this.option.visible?this.show():this.hide(),k(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 E(()=>new D,t=>this.scheduler.fail(t)),this.worker=this.workerClient.worker}filter(t,e){return b(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(){var t;x(this),this.scheduler.destroy();try{try{this.stop()}finally{null==(t=this.workerClient)||t.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 T=4294967295;function A(t,e){let i=0,n=t.length;for(;iNumber.isFinite(t)&&t>0))return null;const o={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},l=Object.assign({},"object"===typeof a?a:{}),d=Object.assign({},o,l);for(const r of Object.keys(o))Number.isFinite(d[r])||(d[r]=o[r]);if(d.sampling<=0&&(d.sampling=o.sampling),d.xMin===d.xMax||d.yMin===d.yMax)return null;const c=Array.isArray(s)&&s.length>0,p=c?[...s]: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>T)return[];const a=t.map(t=>t.time).filter(t=>"number"===typeof t&&!Number.isNaN(t)).sort((t,e)=>t-e),s=[],r=i/e;if(!Number.isFinite(r))return[];for(let o=0;o<=e;o+=n){if(s.length>=T||o+n===o)return[];const t=o*r,e=(o+n)*r;s.push([o,A(a,e)-A(a,t)])}return s}(n,t,i,d.sampling);if(!p.length||!p.every(t=>Array.isArray(t)&&Number.isFinite(t[0])&&Number.isFinite(t[1])))return null;const h=p[p.length-1];if(h[0]!==t){if(p.length===T)return null;p.push([t,h[1]])}let u=1/0,m=-1/0;for(const r of p)u=Math.min(u,r[1]),m=Math.max(m,r[1]);const f=(u+m)/2;for(const r of p){const t=r[1];r[1]=t*(t>f?1+d.scale:1-d.scale)+d.minHeight}const g=!c&&!Number.isFinite(l.yMin)&&!Number.isFinite(l.yMax);let y=0;for(const r of p)y=Math.max(y,r[1]);const v=g&&y>o.yMax/4;v&&(d.yMax=4*y);const w=t=>v?Math.min(e,Math.max(.75*e,t)):t,k=(t,e,i,n)=>{const a=function(t,e){const i=e[0]-t[0],n=e[1]-t[1];return{length:Math.sqrt(r(i,2)+r(n,2)),angle:Math.atan2(n,i)}}(e||t,i||t),s=L(Math.cos(a.angle)*d.flattening,0,1,1,0),o=a.angle*s+(n?Math.PI:0),l=a.length*d.smoothing;return[t[0]+Math.cos(o)*l,w(t[1]+Math.sin(o)*l)]},x=p.map(i=>[L(i[0],d.xMin,d.xMax,0,t),w(L(i[1],d.yMin,d.yMax,e,0))]);if(!x.every(t=>t.every(Number.isFinite)))return null;const b=x.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 a=k(n[i-1],n[i-2],t),s=k(t,n[i-1],n[i+1],!0);return`C ${a[0]},${a[1]} ${s[0]},${s[1]} ${t[0]},${t[1]}${i===n.length-1?" z":""}`}).join(" ");return/NaN|Infinity/u.test(b)?null:{path:b,opacity:d.opacity,width:t,height:e}}let H=0;function N(t,e,i){if(t.isDestroy)return;const{query:n}=t.constructor.utils;let a;const s=[];let r,o,l,d=!1;const c=()=>!d&&!t.isDestroy;function p(e,i){const n=i;s.push([e,n]),t.on(e,n)}function h(e){if(d)return;let i;d=!0,o=null,l=null;let n=!1;const a=t=>{try{t()}catch(e){n||(i=e),n=!0}};for(const[r,o]of s.splice(0))a(()=>t.off(r,o));if(e&&r&&t.controls.heatmap===r&&a(()=>t.controls.remove("heatmap")),r=void 0,n)throw i}function u(t){c()&&o&&l&&(o.setAttribute("offset",100*t+"%"),l.setAttribute("offset",100*t+"%"))}function m(s){try{!function(s=[]){if(!c())return;o=null,l=null;const d=r;if(d.innerHTML="",t.option.isLive)return;const p=O({width:d.offsetWidth,height:d.offsetHeight,duration:t.duration,queue:e.queue,option:i,points:s});if(!p||!c())return;const h=d.ownerDocument;for(a||(a=h?"heatmap-solids":"heatmap-solids-"+ ++H);null==h?void 0:h.getElementById(a);)a="heatmap-solids-"+ ++H;d.innerHTML=`\n \n \n \n \n \n \n \n \n \n \n \n `,o=n("#heatmap-start",d),l=n("#heatmap-stop",d),u(t.played)}(s)}catch(d){try{h(!0)}catch(p){}throw d}}p("destroy",()=>h(!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(){h(!1)},mounted(e){if(r=e,d)return t.controls.heatmap===e&&t.controls.remove("heatmap"),void(r=void 0);c()?(p("video:timeupdate",()=>u(t.played)),p("setBar",(t,e)=>{"played"===t&&u(e)}),p("ready",()=>m()),p("resize",()=>m()),p("artplayerPluginDanmuku:loaded",()=>m()),p("artplayerPluginDanmuku:points",t=>m(t))):h(!0)}})}catch(f){try{h(!0)}catch(g){}throw f}return()=>h(!0)}const V=new WeakMap;class j{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 a=t;if(!this.active)return;const s=()=>"function"===typeof a.getPropertyPriority?a.getPropertyPriority(e):void 0;let r=V.get(a);r||(r=new Map,V.set(a,r));let o=r.get(e);o||(o={original:a[e],present:e in a||void 0!==a[e],priority:s(),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&&a[e]===o.last&&s()===o.lastPriority){const t=[...o.owners.values()];t.length?(o.apply(t[t.length-1]),o.last=a[e],o.lastPriority=s()):void 0!==o.priority?a.setProperty(e,o.original,o.priority):o.present?o.apply(o.original):delete a[e]}o.owners.size||(r.delete(e),r.size||V.delete(a))}),o.owners.delete(this),o.owners.set(this,i),o.apply(i),o.last=a[e],o.lastPriority=s()}on(t,e){if(!this.active)return;const i=this;function n(...t){if(i.active)return e.apply(this,t)}const a=()=>this.art.off(t,n);this.own(a);try{this.art.on(t,n),this.active||a()}catch(s){throw this.release(a),s}}proxy(t,e,i){if(!this.active)return;const n=this;function a(...t){if(n.active)return i.apply(this,t)}let s;const r=()=>{var i,n;if("function"===typeof s){const t=this.art.events;"function"===typeof(null==t?void 0:t.remove)&&(null==(i=t.destroyEvents)?void 0:i.has(s))?t.remove(s):s()}else null==(n=t.removeEventListener)||n.call(t,e,a)};this.own(r);try{s=this.art.proxy(t,e,a),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 q({min:t,max:e,container:i,findIndex:n,onChange:a,steps:s=[]}){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

\n
\n ${s.map(()=>'
').join("")}\n
\n
\n
\n
\n
\n ${s.map(t=>t.hide?"":`
${t.name}
`).join("")}\n
\n `;const c=o(".apd-slider-dot",i),p=o(".apd-slider-progress",i);let h=!1;function u(i){if(!r.active)return;if(void 0===i&&(i=n()),ie)return;const o=(i-t)/(e-t);c.style.left=100*o+"%",0===s.length&&(p.style.width=c.style.left),a(i)}function m(n){const{top:a,height:s,left:r,width:o}=i.getBoundingClientRect();if(this.art.isRotate){const i=l(n.clientY-a,0,s);u(Math.round(i/s*(e-t)+t))}else{const i=l(n.clientX-r,0,o);u(Math.round(i/o*(e-t)+t))}}return r.own(()=>h=!1),r.proxy(i,"click",t=>{m.call(this,t)}),r.proxy(i,"pointerdown",t=>{h=0===t.button}),r.on("document:pointermove",t=>{h&&m.call(this,t)}),r.on("document:pointerup",t=>{h&&(h=!1,m.call(this,t))}),{reset:u}}const I='',R='',B='',Z='',W='',_='',U='',G='',X='',Y='',J='',K='';function Q(){const{option:t}=this;return`\n
\n ${J}${Y}\n
\n
\n ${B}\n
\n
\n
\n \u6309\u7c7b\u578b\u5c4f\u853d\n
\n
\n ${Z}${W}\n
\u6eda\u52a8
\n
\n
\n ${_}${U}\n
\u9876\u90e8
\n
\n
\n ${G}${X}\n
\u5e95\u90e8
\n
\n
\n
\n
\n
\n ${R}${I}\n \u9632\u6b62\u5f39\u5e55\u91cd\u53e0\n
\n
\n ${R}${I}\n \u540c\u6b65\u89c6\u9891\u901f\u5ea6\n
\n
\n
\n \u4e0d\u900f\u660e\u5ea6\n
\n
\u672a\u77e5
\n
\n
\n \u663e\u793a\u533a\u57df\n
\n
\u672a\u77e5
\n
\n
\n \u5f39\u5e55\u5b57\u53f7\n
\n
\u672a\u77e5
\n
\n
\n \u5f39\u5e55\u901f\u5ea6\n
\n
\u672a\u77e5
\n
\n
\n
\n
\n
\n
\n ${K}\n
\n
\n
\n \u6a21\u5f0f\n
\n
\n ${W}\n
\u6eda\u52a8
\n
\n
\n ${U}\n
\u9876\u90e8
\n
\n
\n ${X}\n
\u5e95\u90e8
\n
\n
\n
\n
\n \u989c\u8272\n
\n ${this.COLOR.map(t=>`
`).join("")}\n
\n
\n
\n
\n
\n \n
\u53d1\u9001
\n
\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 a=()=>{document.removeEventListener("DOMContentLoaded",a),i[e]===n&&delete i[e];const s=document.getElementById(t);s?s.textContent=n.textContent:(document.head||document.documentElement).appendChild(n)};document.addEventListener("DOMContentLoaded",a,{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 tt{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 j(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(a){try{this.destroy()}catch(s){console.warn("Failed to roll back danmuku setting:",s)}throw a}}static get icons(){return{$on:J,$off:Y,$config:B,$style:K,$mode_0_off:Z,$mode_0_on:W,$mode_1_off:_,$mode_1_on:U,$mode_2_off:G,$mode_2_on:X,$check_on:R,$check_off:I}}get option(){return this.danmuku.option}get outside(){return this.template.$mount!==this.template.$controlsCenter}get TEMPLATE(){return Q.call(this)}get OPACITY(){return l({min:0,max:100,steps:[]},this.option.OPACITY)}get FONT_SIZE(){return l({min:12,max:120,steps:[]},this.option.FONT_SIZE)}get MARGIN(){return l({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 l({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:a,$syncVideo:s,$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(a,"click",()=>{this.danmuku.config({antiOverlap:!this.option.antiOverlap}),this.reset()}),this.lifecycle.proxy(s,"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(d(l({},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(d(l({},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(d(l({},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(d(l({},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 q.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(),a=e.getBoundingClientRect(),s=i.getBoundingClientRect(),r=a.width/2-n.width/2,o=s.left-(n.left-r),l=n.right+r-s.right;e.style.left=o>0?`${-r+o}px`:l>0?-r-l+"px":-r+"px"}emit(){return function(t){return c(this,null,function*(){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 a={text:n,mode:t.option.mode,color:t.option.color,time:t.art.currentTime},s=t=>{e.active&&console.error("Error emitting danmuku:",t)};try{t.emitting=!0;const n=yield e.wait(t.option.beforeEmit(a));if(!e.active)return;if(t.emitting=!1,!0!==n)return;if(a.border=!0,delete a.time,Promise.resolve(t.danmuku.emit(a)).catch(s),!e.active)return;i.value="",t.lock()}catch(r){s(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 a=()=>{t.timer=setTimeout(()=>{t.lifecycle.active&&(0===n?t.unlock():(n-=1,i.textContent=n,a()))},1e3)};a()}(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.widtht.dataset.color===this.option.color.toUpperCase());s&&t(s,"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;(null==t?void 0:t.parentElement)&&t.parentElement.removeChild(t)}}function et(t){return e=>{const i=new P(e,t);let n;try{n=e.isDestroy?void 0:new tt(e,i),!e.isDestroy&&i.option.heatmap&&N(e,i,i.option.heatmap)}catch(a){try{null==n||n.destroy()}catch(s){}try{i.destroy()}catch(s){}throw a}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 et.icons=tt.icons,et}); +!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";var t=Object.defineProperty,e=Object.defineProperties,i=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable,r=Math.pow,o=(e,i,n)=>i in e?t(e,i,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[i]=n,l=(t,e)=>{for(var i in e||(e={}))a.call(e,i)&&o(t,i,e[i]);if(n)for(var i of n(e))s.call(e,i)&&o(t,i,e[i]);return t},d=(t,n)=>e(t,i(n)),c=(t,e,i)=>new Promise((n,a)=>{var s=t=>{try{o(i.next(t))}catch(e){a(e)}},r=t=>{try{o(i.throw(t))}catch(e){a(e)}},o=t=>t.done?n(t.value):Promise.resolve(t.value).then(s,r);o((i=i.apply(t,e)).next())});function p(t){return t instanceof Promise||"[object Promise]"===Object.prototype.toString.call(t)}function h(t){switch(t){case 1:case 2:case 3:default:return 0;case 4:return 2;case 5:return 1}}function u(t){if("string"!==typeof t)return[];const e=new RegExp(']*?p="(?

[^"]+)"[^>]*>(?.*?)<\\/d>',"gs"),i=t.matchAll(e);return Array.from(i).map(t=>{const e=t.groups.p.split(",");if(e.length>=8){return{text:t.groups.text.trim().replaceAll(""",'"').replaceAll("'","'").replaceAll("<","<").replaceAll(">",">").replaceAll("&","&"),time:Number(e[0]),mode:h(Number(e[1])),fontSize:Number(e[2]),color:`#${Number(e[3]).toString(16)}`,timestamp:Number(e[4]),pool:Number(e[5]),userID:e[6],rowID:Number(e[7])}}return null}).filter(Boolean)}function m({data:t}){const{xml:e,id:i}=t,n=u(e);globalThis.postMessage({danmus:n,id:i})}let f=0;function g(t,{signal:e,onCancel:i}={}){return new Promise((n,a)=>{let s,r,o,l=!1;const d=++f,p=()=>y(void 0,function(t){if(void 0!==(null==t?void 0:t.reason))return t.reason;const e=new Error("Bilibili Danmu loading cancelled");return e.name="AbortError",e}(e));function g(){let t,e=!1;try{if(s){const t=s;s=void 0,t.onmessage=null,t.onerror=null,t.onmessageerror=null,t.terminate()}}catch(i){t=i,e=!0}if(void 0!==r){const n=r;r=void 0;try{URL.revokeObjectURL(n)}catch(i){e||(t=i),e=!0}}if(e)throw t}function y(t,i){if(l)return;l=!0;let s=arguments.length>1;null==e||e.removeEventListener("abort",p),null==o||o();try{g()}catch(r){s||(i=r),s=!0}s?a(i):n(t)}function v(t,e){if(!l){console.error("Error parsing Bilibili Danmu:",e);try{y(u(t))}catch(i){y(void 0,i)}}}(null==e?void 0:e.aborted)?p():(null==e||e.addEventListener("abort",p),o=null==i?void 0:i(p),l?null==o||o():function(){return c(this,null,function*(){const i=e?yield fetch(t,{signal:e}):yield fetch(t);if(l)return;const n=yield i.text();if(!l)try{const t=`\n ${h.toString()}\n ${u.toString()}\n onmessage = ${m.toString()}\n `;if(r=URL.createObjectURL(new Blob([t],{type:"application/javascript"})),l)return void g();if(s=new Worker(r),l)return void g();s.onmessage=t=>{var e;if(l||(null==(e=t.data)?void 0:e.id)!==d)return;const{danmus:i}=t.data;Array.isArray(i)?y(i):y(void 0,new Error("Invalid Bilibili Danmu worker response"))},s.onerror=t=>{var e;null==(e=t.preventDefault)||e.call(t),v(n,t.error||t)},s.onmessageerror=t=>v(n,t.error||t),s.postMessage({xml:n,id:d})}catch(a){v(n,a)}})}().catch(t=>y(void 0,t)))})}const y=new WeakMap,v=Symbol("cancelled danmuku input");function w(t){return y.has(t)||y.set(t,{closed:!1,tasks:new Set,emitting:[]}),y.get(t)}function k(t){const e=w(t),i=e.emitting[e.emitting.length-1];return!e.closed&&!t.art.isDestroy&&(!i||i.active())}function x(t){const e=w(t);e.closed=!0;for(const i of[...e.tasks])i.cancel()}function b(t,e,i){const n=t.states[e]||[];for(let a=0;a{const a=n.$ref.offsetTop,s=this.owner.getLeft(n.$ref)-i,r=n.$ref.clientHeight,o=n.$ref.clientWidth,l=s+o,d=e-l,c=l/n.$restTime,p={};p.top=a,p.left=s,p.height=r,p.width=o,p.right=d,p.speed=c,p.distance=l,p.time=n.$restTime,p.mode=n.mode,t.push(p)}),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,a){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=`${a}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()}}const M=Symbol("cancelled danmuku frame");class S{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}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(){var t;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)}null==(t=this.owner.workerClient)||t.cancel(),this.failedItems.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(){var t;if(!this.closed&&!this.owner.art.isDestroy&&(this.failedItems.clear(),this.fault))try{null==(t=this.owner.workerClient)||t.dispose(),this.owner.createWorker(),this.fault=!1}catch(e){this.report(e)}}schedule(){const t=this.owner;!this.running||this.closed||this.fault||t.art.isDestroy||t.isStop||null!==this.frame||this.operation||(this.frame=window.requestAnimationFrame(()=>{if(this.frame=null,t.timer=null,this.closed||this.fault||t.isStop||t.art.isDestroy)return;let e;const i=new Promise(t=>e=()=>t(M)),n={generation:this.generation,cancel:e,wait:t=>Promise.race([t,i]),ref:null};return this.operation=n,this.run(n).catch(t=>{this.active(n)&&this.fail(t)}).finally(()=>{this.release(n),this.operation===n&&(this.operation=null,this.schedule())})}),t.timer=this.frame)}run(t){return c(this,null,function*(){const e=this.owner;if(!e.art.playing||!this.active(t))return;e.filter("emit",t=>{const i=(Date.now()-t.$lastStartTime)/1e3;t.$restTime-=i,t.$lastStartTime=Date.now(),t.$restTime<=0&&e.makeWait(t)});const i=e.readys;for(const a of i){if(!this.active(t))return;if(this.failedItems.has(a))continue;let i;try{i=yield t.wait(e.option.beforeVisible(a))}catch(n){if(!this.active(t))return;this.failedItems.add(a),this.report(n);continue}if(!this.active(t))return;if(!i)continue;const{clientWidth:s,clientHeight:r}=e.$player,o=e.renderer.prepare(a,t);if(!this.active(t))return;a.$lastStartTime=Date.now(),a.$restTime=e.speed;const l=s+o.clientWidth,d=yield t.wait(e.postMessage({type:"getDanmuTop",target:{mode:a.mode,height:o.clientHeight,speed:l/a.$restTime},visibles:e.visibles,antiOverlap:e.option.antiOverlap,clientWidth:s,clientHeight:r,marginBottom:e.marginBottom,marginTop:e.marginTop})),c="symbol"===typeof d?void 0:d.result;if(!this.active(t)||a.$ref!==o)return;void 0!==c?(a.$lastStartTime=Date.now(),e.setState(a,"emit"),e.renderer.place(a,o,c,l,s),t.ref=null,e.art.emit("artplayerPluginDanmuku:visible",a)):(e.setState(a,"ready"),this.release(t))}})}destroy(){this.closed=!0,this.invalidate()}}let z=0;class E{constructor(t,e){this.pending=new Map,this.closed=!1,this.failed=!1,this.onFailure=e,this.worker=t();try{this.worker.onmessage=t=>{var e;const i=this.pending.get(null==(e=t.data)?void 0:e.id);i&&(this.pending.delete(t.data.id),i.resolve(t.data))},this.worker.onerror=t=>{var e;null==(e=t.preventDefault)||e.call(t),this.fail(t.error||t)},this.worker.onmessageerror=t=>this.fail(t.error||t)}catch(i){try{this.dispose()}catch(n){}throw i}}request(t){t.id=++z;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(a){this.fail(a)}})}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(e){}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 F='/*!\n * artplayer-plugin-danmuku.js v5.3.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=t.height)return h}const a=[];for(let g=1;g{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(ie.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',C="undefined"!==typeof self&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",F],{type:"text/javascript;charset=utf-8"});function D(t){let e;try{if(e=C&&(self.URL||self.webkitURL).createObjectURL(C),!e)throw"";const i=new Worker(e,{type:"module",name:null==t?void 0: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(F),{type:"module",name:null==t?void 0:t.name})}}class P{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 $(this),this.scheduler=new S(this),this.option=P.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),k(this),t.on("destroy",this.destroy);try{if(this.config(e,!0),!k(this))return;this.createWorker()}catch(a){throw t.off("destroy",this.destroy),x(this),this.scheduler.destroy(),a}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(){var t,e;return null==(e=null==(t=this.art.plugins)?void 0:t.autoOrientation)?void 0:e.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 P.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 P.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 P.option.fontSize}get $ref(){return this.renderer.acquire()}get readys(){return function(t){const{currentTime:e}=t.art,i=[];return b(t,"ready",t=>i.push(t)),b(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}load(t){return c(this,null,function*(){const{errorHandle:e}=this.utils,i=function(t,e){const i=w(t);if(e)for(const d of[...i.tasks])d.replace&&d.cancel();let n,a=i.closed||t.art.isDestroy;const s=new Promise(t=>n=t),r=new Set,o="function"===typeof AbortController?new AbortController:void 0,l={replace:e,signal:null==o?void 0:o.signal,active:()=>!a&&!i.closed&&!t.art.isDestroy,onCancel:t=>l.active()?(r.add(t),()=>r.delete(t)):(t(),()=>{}),cancel(){if(!a){a=!0,n(v),null==o||o.abort();for(const t of[...r])t();r.clear()}},wait:t=>Promise.race([t,s]),emit(e){i.emitting.push(l);try{return t.emit(e)}finally{i.emitting.pop()}},finish(){i.tasks.delete(l),r.clear()}};return a?n(v):i.tasks.add(l),l}(this,void 0===t);try{if(!i.active())return this;const n=function(t,e){return"function"===typeof t?{asynchronous:!0,value:t()}:p(t)?{asynchronous:!0,value:t}:"string"===typeof t?{asynchronous:!0,value:g(t,e)}:{asynchronous:!1,value:Array.isArray(t)?t:[]}}(t||this.option.danmuku,i),a=n.asynchronous?yield i.wait(n.value):n.value;if(!i.active())return this;e(Array.isArray(a),"Danmuku need return an array as result");const s=a;if(void 0===t){if(this.reset(),!i.active())return this;this.queue=[],this.states={wait:[],ready:[],emit:[],stop:[]},this.renderer.clear()}for(let t=0;t{const e=a[t],i=s[t];return"function"===typeof e||"function"===typeof i||p(e)||p(i)?e!==i:JSON.stringify(e)!==JSON.stringify(i)}))&&!e)return this;const r=function(t,e,{defaults:i,validate:n,clamp:a,mount:s}){const r=Object.assign({},i,t,e);return n(r),r.mode=a(r.mode,0,2),r.speed=a(r.speed,1,10),r.opacity=a(r.opacity,0,1),r.lockTime=a(r.lockTime,1,60),r.maxLength=a(r.maxLength,1,1e3),r.mount=r.mount||s,r}(this.option,t,{defaults:P.option,validate:t=>this.validator(t,P.scheme),clamp:i,mount:n});if(!k(this))return this;const o=this.option.beforeVisible!==r.beforeVisible;return this.option=r,o&&(this.scheduler.invalidate(),this.scheduler.schedule()),t.fontSize&&(this.reset(),!k(this))||(this.option.visible?this.show():this.hide(),k(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 E(()=>new D,t=>this.scheduler.fail(t)),this.worker=this.workerClient.worker}filter(t,e){return b(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(){var t;x(this),this.scheduler.destroy();try{try{this.stop()}finally{null==(t=this.workerClient)||t.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 T=4294967295;function A(t,e){let i=0,n=t.length;for(;iNumber.isFinite(t)&&t>0))return null;const o={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},l=Object.assign({},"object"===typeof a?a:{}),d=Object.assign({},o,l);for(const r of Object.keys(o))Number.isFinite(d[r])||(d[r]=o[r]);if(d.sampling<=0&&(d.sampling=o.sampling),d.xMin===d.xMax||d.yMin===d.yMax)return null;const c=Array.isArray(s)&&s.length>0,p=c?[...s]: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>T)return[];const a=t.map(t=>t.time).filter(t=>"number"===typeof t&&!Number.isNaN(t)).sort((t,e)=>t-e),s=[],r=i/e;if(!Number.isFinite(r))return[];for(let o=0;o<=e;o+=n){if(s.length>=T||o+n===o)return[];const t=o*r,e=(o+n)*r;s.push([o,A(a,e)-A(a,t)])}return s}(n,t,i,d.sampling);if(!p.length||!p.every(t=>Array.isArray(t)&&Number.isFinite(t[0])&&Number.isFinite(t[1])))return null;const h=p[p.length-1];if(h[0]!==t){if(p.length===T)return null;p.push([t,h[1]])}let u=1/0,m=-1/0;for(const r of p)u=Math.min(u,r[1]),m=Math.max(m,r[1]);const f=(u+m)/2;for(const r of p){const t=r[1];r[1]=t*(t>f?1+d.scale:1-d.scale)+d.minHeight}const g=!c&&!Number.isFinite(l.yMin)&&!Number.isFinite(l.yMax);let y=0;for(const r of p)y=Math.max(y,r[1]);const v=g&&y>o.yMax/4;v&&(d.yMax=4*y);const w=t=>v?Math.min(e,Math.max(.75*e,t)):t,k=(t,e,i,n)=>{const a=function(t,e){const i=e[0]-t[0],n=e[1]-t[1];return{length:Math.sqrt(r(i,2)+r(n,2)),angle:Math.atan2(n,i)}}(e||t,i||t),s=L(Math.cos(a.angle)*d.flattening,0,1,1,0),o=a.angle*s+(n?Math.PI:0),l=a.length*d.smoothing;return[t[0]+Math.cos(o)*l,w(t[1]+Math.sin(o)*l)]},x=p.map(i=>[L(i[0],d.xMin,d.xMax,0,t),w(L(i[1],d.yMin,d.yMax,e,0))]);if(!x.every(t=>t.every(Number.isFinite)))return null;const b=x.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 a=k(n[i-1],n[i-2],t),s=k(t,n[i-1],n[i+1],!0);return`C ${a[0]},${a[1]} ${s[0]},${s[1]} ${t[0]},${t[1]}${i===n.length-1?" z":""}`}).join(" ");return/NaN|Infinity/u.test(b)?null:{path:b,opacity:d.opacity,width:t,height:e}}let H=0;function N(t,e,i){if(t.isDestroy)return;const{query:n}=t.constructor.utils;let a;const s=[];let r,o,l,d=!1;const c=()=>!d&&!t.isDestroy;function p(e,i){const n=i;s.push([e,n]),t.on(e,n)}function h(e){if(d)return;let i;d=!0,o=null,l=null;let n=!1;const a=t=>{try{t()}catch(e){n||(i=e),n=!0}};for(const[r,o]of s.splice(0))a(()=>t.off(r,o));if(e&&r&&t.controls.heatmap===r&&a(()=>t.controls.remove("heatmap")),r=void 0,n)throw i}function u(t){c()&&o&&l&&(o.setAttribute("offset",100*t+"%"),l.setAttribute("offset",100*t+"%"))}function m(s){try{!function(s=[]){if(!c())return;o=null,l=null;const d=r;if(d.innerHTML="",t.option.isLive)return;const p=O({width:d.offsetWidth,height:d.offsetHeight,duration:t.duration,queue:e.queue,option:i,points:s});if(!p||!c())return;const h=d.ownerDocument;for(a||(a=h?"heatmap-solids":"heatmap-solids-"+ ++H);null==h?void 0:h.getElementById(a);)a="heatmap-solids-"+ ++H;d.innerHTML=`\n \n \n \n \n \n \n \n \n \n \n \n `,o=n("#heatmap-start",d),l=n("#heatmap-stop",d),u(t.played)}(s)}catch(d){try{h(!0)}catch(p){}throw d}}p("destroy",()=>h(!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(){h(!1)},mounted(e){if(r=e,d)return t.controls.heatmap===e&&t.controls.remove("heatmap"),void(r=void 0);c()?(p("video:timeupdate",()=>u(t.played)),p("setBar",(t,e)=>{"played"===t&&u(e)}),p("ready",()=>m()),p("resize",()=>m()),p("artplayerPluginDanmuku:loaded",()=>m()),p("artplayerPluginDanmuku:points",t=>m(t))):h(!0)}})}catch(f){try{h(!0)}catch(g){}throw f}return()=>h(!0)}const V=new WeakMap;class j{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 a=t;if(!this.active)return;const s=()=>"function"===typeof a.getPropertyPriority?a.getPropertyPriority(e):void 0;let r=V.get(a);r||(r=new Map,V.set(a,r));let o=r.get(e);o||(o={original:a[e],present:e in a||void 0!==a[e],priority:s(),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&&a[e]===o.last&&s()===o.lastPriority){const t=[...o.owners.values()];t.length?(o.apply(t[t.length-1]),o.last=a[e],o.lastPriority=s()):void 0!==o.priority?a.setProperty(e,o.original,o.priority):o.present?o.apply(o.original):delete a[e]}o.owners.size||(r.delete(e),r.size||V.delete(a))}),o.owners.delete(this),o.owners.set(this,i),o.apply(i),o.last=a[e],o.lastPriority=s()}on(t,e){if(!this.active)return;const i=this;function n(...t){if(i.active)return e.apply(this,t)}const a=()=>this.art.off(t,n);this.own(a);try{this.art.on(t,n),this.active||a()}catch(s){throw this.release(a),s}}proxy(t,e,i){if(!this.active)return;const n=this;function a(...t){if(n.active)return i.apply(this,t)}let s;const r=()=>{var i,n;if("function"===typeof s){const t=this.art.events;"function"===typeof(null==t?void 0:t.remove)&&(null==(i=t.destroyEvents)?void 0:i.has(s))?t.remove(s):s()}else null==(n=t.removeEventListener)||n.call(t,e,a)};this.own(r);try{s=this.art.proxy(t,e,a),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 q({min:t,max:e,container:i,findIndex:n,onChange:a,steps:s=[]}){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

\n
\n ${s.map(()=>'
').join("")}\n
\n
\n
\n
\n
\n ${s.map(t=>t.hide?"":`
${t.name}
`).join("")}\n
\n `;const c=o(".apd-slider-dot",i),p=o(".apd-slider-progress",i);let h=!1;function u(i){if(!r.active)return;if(void 0===i&&(i=n()),ie)return;const o=(i-t)/(e-t);c.style.left=100*o+"%",0===s.length&&(p.style.width=c.style.left),a(i)}function m(n){const{top:a,height:s,left:r,width:o}=i.getBoundingClientRect();if(this.art.isRotate){const i=l(n.clientY-a,0,s);u(Math.round(i/s*(e-t)+t))}else{const i=l(n.clientX-r,0,o);u(Math.round(i/o*(e-t)+t))}}return r.own(()=>h=!1),r.proxy(i,"click",t=>{m.call(this,t)}),r.proxy(i,"pointerdown",t=>{h=0===t.button}),r.on("document:pointermove",t=>{h&&m.call(this,t)}),r.on("document:pointerup",t=>{h&&(h=!1,m.call(this,t))}),{reset:u}}const I='',R='',B='',Z='',W='',_='',U='',G='',X='',Y='',J='',K='';function Q(){const{option:t}=this;return`\n
\n ${J}${Y}\n
\n
\n ${B}\n
\n
\n
\n \u6309\u7c7b\u578b\u5c4f\u853d\n
\n
\n ${Z}${W}\n
\u6eda\u52a8
\n
\n
\n ${_}${U}\n
\u9876\u90e8
\n
\n
\n ${G}${X}\n
\u5e95\u90e8
\n
\n
\n
\n
\n
\n ${R}${I}\n \u9632\u6b62\u5f39\u5e55\u91cd\u53e0\n
\n
\n ${R}${I}\n \u540c\u6b65\u89c6\u9891\u901f\u5ea6\n
\n
\n
\n \u4e0d\u900f\u660e\u5ea6\n
\n
\u672a\u77e5
\n
\n
\n \u663e\u793a\u533a\u57df\n
\n
\u672a\u77e5
\n
\n
\n \u5f39\u5e55\u5b57\u53f7\n
\n
\u672a\u77e5
\n
\n
\n \u5f39\u5e55\u901f\u5ea6\n
\n
\u672a\u77e5
\n
\n
\n
\n
\n
\n
\n ${K}\n
\n
\n
\n \u6a21\u5f0f\n
\n
\n ${W}\n
\u6eda\u52a8
\n
\n
\n ${U}\n
\u9876\u90e8
\n
\n
\n ${X}\n
\u5e95\u90e8
\n
\n
\n
\n
\n \u989c\u8272\n
\n ${this.COLOR.map(t=>`
`).join("")}\n
\n
\n
\n
\n
\n \n
\u53d1\u9001
\n
\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 a=()=>{document.removeEventListener("DOMContentLoaded",a),i[e]===n&&delete i[e];const s=document.getElementById(t);s?s.textContent=n.textContent:(document.head||document.documentElement).appendChild(n)};document.addEventListener("DOMContentLoaded",a,{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 tt{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 j(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(a){try{this.destroy()}catch(s){console.warn("Failed to roll back danmuku setting:",s)}throw a}}static get icons(){return{$on:J,$off:Y,$config:B,$style:K,$mode_0_off:Z,$mode_0_on:W,$mode_1_off:_,$mode_1_on:U,$mode_2_off:G,$mode_2_on:X,$check_on:R,$check_off:I}}get option(){return this.danmuku.option}get outside(){return this.template.$mount!==this.template.$controlsCenter}get TEMPLATE(){return Q.call(this)}get OPACITY(){return l({min:0,max:100,steps:[]},this.option.OPACITY)}get FONT_SIZE(){return l({min:12,max:120,steps:[]},this.option.FONT_SIZE)}get MARGIN(){return l({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 l({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:a,$syncVideo:s,$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(a,"click",()=>{this.danmuku.config({antiOverlap:!this.option.antiOverlap}),this.reset()}),this.lifecycle.proxy(s,"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(d(l({},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(d(l({},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(d(l({},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(d(l({},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 q.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(),a=e.getBoundingClientRect(),s=i.getBoundingClientRect(),r=a.width/2-n.width/2,o=s.left-(n.left-r),l=n.right+r-s.right;e.style.left=o>0?`${-r+o}px`:l>0?-r-l+"px":-r+"px"}emit(){return function(t){return c(this,null,function*(){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 a={text:n,mode:t.option.mode,color:t.option.color,time:t.art.currentTime},s=t=>{e.active&&console.error("Error emitting danmuku:",t)};try{t.emitting=!0;const n=yield e.wait(t.option.beforeEmit(a));if(!e.active)return;if(t.emitting=!1,!0!==n)return;if(a.border=!0,delete a.time,Promise.resolve(t.danmuku.emit(a)).catch(s),!e.active)return;i.value="",t.lock()}catch(r){s(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 a=()=>{t.timer=setTimeout(()=>{t.lifecycle.active&&(0===n?t.unlock():(n-=1,i.textContent=n,a()))},1e3)};a()}(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.widtht.dataset.color===this.option.color.toUpperCase());s&&t(s,"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;(null==t?void 0:t.parentElement)&&t.parentElement.removeChild(t)}}function et(t){return e=>{const i=new P(e,t);let n;try{n=e.isDestroy?void 0:new tt(e,i),!e.isDestroy&&i.option.heatmap&&N(e,i,i.option.heatmap)}catch(a){try{null==n||n.destroy()}catch(s){}try{i.destroy()}catch(s){}throw a}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 et.icons=tt.icons,et}); diff --git a/docs/compiled/artplayer-plugin-danmuku.mjs b/docs/compiled/artplayer-plugin-danmuku.mjs index 560c1e7e2..fc13b77ba 100644 --- a/docs/compiled/artplayer-plugin-danmuku.mjs +++ b/docs/compiled/artplayer-plugin-danmuku.mjs @@ -680,6 +680,7 @@ class Scheduler { if (!this.active(operation) || danmu.$ref !== ref) return; if (top !== void 0) { + danmu.$lastStartTime = Date.now(); owner.setState(danmu, "emit"); owner.renderer.place(danmu, ref, top, distance, clientWidth); operation.ref = null; diff --git a/docs/uncompiled/artplayer-plugin-danmuku/index.js b/docs/uncompiled/artplayer-plugin-danmuku/index.js index 60777ec88..f3ecb87bd 100644 --- a/docs/uncompiled/artplayer-plugin-danmuku/index.js +++ b/docs/uncompiled/artplayer-plugin-danmuku/index.js @@ -676,6 +676,7 @@ var artplayerPluginDanmuku = (function() { if (!this.active(operation) || danmu.$ref !== ref) return; if (top !== void 0) { + danmu.$lastStartTime = Date.now(); owner.setState(danmu, "emit"); owner.renderer.place(danmu, ref, top, distance, clientWidth); operation.ref = null; diff --git a/packages/artplayer-plugin-danmuku/ARCHITECTURE.md b/packages/artplayer-plugin-danmuku/ARCHITECTURE.md index 66631d0e5..3a8d8a0c0 100644 --- a/packages/artplayer-plugin-danmuku/ARCHITECTURE.md +++ b/packages/artplayer-plugin-danmuku/ARCHITECTURE.md @@ -154,6 +154,14 @@ playback enabled, new comments sample speed/playbackRate when allocated; active comments retain their assigned remaining seconds. Do not change these timing rules as incidental cleanup. +Successful Worker placement resets the visible start timestamp. Hidden measurement +and Worker waiting do not consume the CSS-visible duration; recording only before +postMessage can recycle a slow reply's comment on its first visible frame. Keep the +remaining lifetime and geometry speed assigned during preparation, and change only +the visible origin after the cancellation/node-identity checks. The delayed Worker +regression in `test/browser/danmuku-lifetime.spec.js` uses real geometry with a +controlled request delay; it does not claim natural Worker starvation. + A rejected `beforeVisible` reports its original error once and excludes that item from further attempts in the current run. Explicit start, reset, an invalidation or replacement callback permits another attempt if the item is diff --git a/packages/artplayer-plugin-danmuku/dist/artplayer-plugin-danmuku.js b/packages/artplayer-plugin-danmuku/dist/artplayer-plugin-danmuku.js index 6ae4f81f1..d47db3b7b 100644 --- a/packages/artplayer-plugin-danmuku/dist/artplayer-plugin-danmuku.js +++ b/packages/artplayer-plugin-danmuku/dist/artplayer-plugin-danmuku.js @@ -4,4 +4,4 @@ * (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(/]*?p="(?

[^"]+)"[^>]*>(?.*?)<\/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,a=i(e);globalThis.postMessage({danmus:a,id:n})}let a=0;function s(t,{signal:s,onCancel:r}={}){return new Promise((o,l)=>{let d,c,p,h=!1;const u=++a,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}(s));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!==c){const n=c;c=void 0;try{URL.revokeObjectURL(n)}catch(i){e||(t=i),e=!0}}if(e)throw t}function g(t,e){if(h)return;h=!0;let i=arguments.length>1;s?.removeEventListener("abort",m),p?.();try{f()}catch(n){i||(e=n),i=!0}i?l(e):o(t)}function y(t,e){if(!h){console.error("Error parsing Bilibili Danmu:",e);try{g(i(t))}catch(n){g(void 0,n)}}}s?.aborted?m():(s?.addEventListener("abort",m),p=r?.(m),h?p?.():async function(){const a=s?await fetch(t,{signal:s}):await fetch(t);if(h)return;const r=await a.text();if(!h)try{const t=`\n ${e.toString()}\n ${i.toString()}\n onmessage = ${n.toString()}\n `;if(c=URL.createObjectURL(new Blob([t],{type:"application/javascript"})),h)return void f();if(d=new Worker(c),h)return void f();d.onmessage=t=>{if(h||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 c(t){const e=l(t);e.closed=!0;for(const i of[...e.tasks])i.cancel()}function p(t,e,i){const n=t.states[e]||[];for(let a=0;a{const a=n.$ref.offsetTop,s=this.owner.getLeft(n.$ref)-i,r=n.$ref.clientHeight,o=n.$ref.clientWidth,l=s+o,d=e-l,c=l/n.$restTime,p={};p.top=a,p.left=s,p.height=r,p.width=o,p.right=d,p.speed=c,p.distance=l,p.time=n.$restTime,p.mode=n.mode,t.push(p)}),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,a){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=`${a}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()}}const u=Symbol("cancelled danmuku frame");class m{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}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()}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;!this.running||this.closed||this.fault||t.art.isDestroy||t.isStop||null!==this.frame||this.operation||(this.frame=window.requestAnimationFrame(()=>{if(this.frame=null,t.timer=null,this.closed||this.fault||t.isStop||t.art.isDestroy)return;let e;const i=new Promise(t=>e=()=>t(u)),n={generation:this.generation,cancel:e,wait:t=>Promise.race([t,i]),ref:null};return this.operation=n,this.run(n).catch(t=>{this.active(n)&&this.fail(t)}).finally(()=>{this.release(n),this.operation===n&&(this.operation=null,this.schedule())})}),t.timer=this.frame)}async run(t){const e=this.owner;if(!e.art.playing||!this.active(t))return;e.filter("emit",t=>{const i=(Date.now()-t.$lastStartTime)/1e3;t.$restTime-=i,t.$lastStartTime=Date.now(),t.$restTime<=0&&e.makeWait(t)});const i=e.readys;for(const a of i){if(!this.active(t))return;if(this.failedItems.has(a))continue;let i;try{i=await t.wait(e.option.beforeVisible(a))}catch(n){if(!this.active(t))return;this.failedItems.add(a),this.report(n);continue}if(!this.active(t))return;if(!i)continue;const{clientWidth:s,clientHeight:r}=e.$player,o=e.renderer.prepare(a,t);if(!this.active(t))return;a.$lastStartTime=Date.now(),a.$restTime=e.speed;const l=s+o.clientWidth,d=await t.wait(e.postMessage({type:"getDanmuTop",target:{mode:a.mode,height:o.clientHeight,speed:l/a.$restTime},visibles:e.visibles,antiOverlap:e.option.antiOverlap,clientWidth:s,clientHeight:r,marginBottom:e.marginBottom,marginTop:e.marginTop})),c="symbol"===typeof d?void 0:d.result;if(!this.active(t)||a.$ref!==o)return;void 0!==c?(e.setState(a,"emit"),e.renderer.place(a,o,c,l,s),t.ref=null,e.art.emit("artplayerPluginDanmuku:visible",a)):(e.setState(a,"ready"),this.release(t))}}destroy(){this.closed=!0,this.invalidate()}}let f=0;class g{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=++f;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(a){this.fail(a)}})}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 y='/*!\n * artplayer-plugin-danmuku.js v5.3.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=t.height)return h}const a=[];for(let g=1;g{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(ie.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',v="undefined"!==typeof self&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",y],{type:"text/javascript;charset=utf-8"});function w(t){let e;try{if(e=v&&(self.URL||self.webkitURL).createObjectURL(v),!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(y),{type:"module",name:t?.name})}}class k{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 h(this),this.scheduler=new m(this),this.option=k.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(a){throw t.off("destroy",this.destroy),c(this),this.scheduler.destroy(),a}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 k.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 k.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 k.option.fontSize}get $ref(){return this.renderer.acquire()}get readys(){return function(t){const{currentTime:e}=t.art,i=[];return p(t,"ready",t=>i.push(t)),p(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,a=i.closed||t.art.isDestroy;const s=new Promise(t=>n=t),r=new Set,d="function"===typeof AbortController?new AbortController:void 0,c={replace:e,signal:d?.signal,active:()=>!a&&!i.closed&&!t.art.isDestroy,onCancel:t=>c.active()?(r.add(t),()=>r.delete(t)):(t(),()=>{}),cancel(){if(!a){a=!0,n(o),d?.abort();for(const t of[...r])t();r.clear()}},wait:t=>Promise.race([t,s]),emit(e){i.emitting.push(c);try{return t.emit(e)}finally{i.emitting.pop()}},finish(){i.tasks.delete(c),r.clear()}};return a?n(o):i.tasks.add(c),c}(this,void 0===e);try{if(!n.active())return this;const a=function(e,i){return"function"===typeof e?{asynchronous:!0,value:e()}:t(e)?{asynchronous:!0,value:e}:"string"===typeof e?{asynchronous:!0,value:s(e,i)}:{asynchronous:!1,value:Array.isArray(e)?e:[]}}(e||this.option.danmuku,n),r=a.asynchronous?await n.wait(a.value):a.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{const i=s[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:a,mount:s}){const r=Object.assign({},i,t,e);return n(r),r.mode=a(r.mode,0,2),r.speed=a(r.speed,1,10),r.opacity=a(r.opacity,0,1),r.lockTime=a(r.lockTime,1,60),r.maxLength=a(r.maxLength,1,1e3),r.mount=r.mount||s,r}(this.option,e,{defaults:k.option,validate:t=>this.validator(t,k.scheme),clamp:n,mount:a});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 g(()=>new w,t=>this.scheduler.fail(t)),this.worker=this.workerClient.worker}filter(t,e){return p(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(){c(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 x=4294967295;function $(t,e){let i=0,n=t.length;for(;iNumber.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 a?a:{}),l=Object.assign({},r,o);for(const x of Object.keys(r))Number.isFinite(l[x])||(l[x]=r[x]);if(l.sampling<=0&&(l.sampling=r.sampling),l.xMin===l.xMax||l.yMin===l.yMax)return null;const d=Array.isArray(s)&&s.length>0,c=d?[...s]: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>x)return[];const a=t.map(t=>t.time).filter(t=>"number"===typeof t&&!Number.isNaN(t)).sort((t,e)=>t-e),s=[],r=i/e;if(!Number.isFinite(r))return[];for(let o=0;o<=e;o+=n){if(s.length>=x||o+n===o)return[];const t=o*r,e=(o+n)*r;s.push([o,$(a,e)-$(a,t)])}return s}(n,t,i,l.sampling);if(!c.length||!c.every(t=>Array.isArray(t)&&Number.isFinite(t[0])&&Number.isFinite(t[1])))return null;const p=c[c.length-1];if(p[0]!==t){if(c.length===x)return null;c.push([t,p[1]])}let h=1/0,u=-1/0;for(const x of c)h=Math.min(h,x[1]),u=Math.max(u,x[1]);const m=(h+u)/2;for(const x of c){const t=x[1];x[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 x of c)g=Math.max(g,x[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 a=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),s=b(Math.cos(a.angle)*l.flattening,0,1,1,0),r=a.angle*s+(n?Math.PI:0),o=a.length*l.smoothing;return[t[0]+Math.cos(r)*o,v(t[1]+Math.sin(r)*o)]},k=c.map(i=>[b(i[0],l.xMin,l.xMax,0,t),v(b(i[1],l.yMin,l.yMax,e,0))]);if(!k.every(t=>t.every(Number.isFinite)))return null;const M=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 a=w(n[i-1],n[i-2],t),s=w(t,n[i-1],n[i+1],!0);return`C ${a[0]},${a[1]} ${s[0]},${s[1]} ${t[0]},${t[1]}${i===n.length-1?" z":""}`}).join(" ");return/NaN|Infinity/u.test(M)?null:{path:M,opacity:l.opacity,width:t,height:e}}let S=0;function z(t,e,i){if(t.isDestroy)return;const{query:n}=t.constructor.utils;let a;const s=[];let r,o,l,d=!1;const c=()=>!d&&!t.isDestroy;function p(e,i){const n=i;s.push([e,n]),t.on(e,n)}function h(e){if(d)return;let i;d=!0,o=null,l=null;let n=!1;const a=t=>{try{t()}catch(e){n||(i=e),n=!0}};for(const[r,o]of s.splice(0))a(()=>t.off(r,o));if(e&&r&&t.controls.heatmap===r&&a(()=>t.controls.remove("heatmap")),r=void 0,n)throw i}function u(t){c()&&o&&l&&(o.setAttribute("offset",100*t+"%"),l.setAttribute("offset",100*t+"%"))}function m(s){try{!function(s=[]){if(!c())return;o=null,l=null;const d=r;if(d.innerHTML="",t.option.isLive)return;const p=M({width:d.offsetWidth,height:d.offsetHeight,duration:t.duration,queue:e.queue,option:i,points:s});if(!p||!c())return;const h=d.ownerDocument;for(a||(a=h?"heatmap-solids":"heatmap-solids-"+ ++S);h?.getElementById(a);)a="heatmap-solids-"+ ++S;d.innerHTML=`\n \n \n \n \n \n \n \n \n \n \n \n `,o=n("#heatmap-start",d),l=n("#heatmap-stop",d),u(t.played)}(s)}catch(d){try{h(!0)}catch{}throw d}}p("destroy",()=>h(!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(){h(!1)},mounted(e){if(r=e,d)return t.controls.heatmap===e&&t.controls.remove("heatmap"),void(r=void 0);c()?(p("video:timeupdate",()=>u(t.played)),p("setBar",(t,e)=>{"played"===t&&u(e)}),p("ready",()=>m()),p("resize",()=>m()),p("artplayerPluginDanmuku:loaded",()=>m()),p("artplayerPluginDanmuku:points",t=>m(t))):h(!0)}})}catch(f){try{h(!0)}catch{}throw f}return()=>h(!0)}const E=new WeakMap;class F{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 a=t;if(!this.active)return;const s=()=>"function"===typeof a.getPropertyPriority?a.getPropertyPriority(e):void 0;let r=E.get(a);r||(r=new Map,E.set(a,r));let o=r.get(e);o||(o={original:a[e],present:e in a||void 0!==a[e],priority:s(),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&&a[e]===o.last&&s()===o.lastPriority){const t=[...o.owners.values()];t.length?(o.apply(t[t.length-1]),o.last=a[e],o.lastPriority=s()):void 0!==o.priority?a.setProperty(e,o.original,o.priority):o.present?o.apply(o.original):delete a[e]}o.owners.size||(r.delete(e),r.size||E.delete(a))}),o.owners.delete(this),o.owners.set(this,i),o.apply(i),o.last=a[e],o.lastPriority=s()}on(t,e){if(!this.active)return;const i=this;function n(...t){if(i.active)return e.apply(this,t)}const a=()=>this.art.off(t,n);this.own(a);try{this.art.on(t,n),this.active||a()}catch(s){throw this.release(a),s}}proxy(t,e,i){if(!this.active)return;const n=this;function a(...t){if(n.active)return i.apply(this,t)}let s;const r=()=>{if("function"===typeof s){const t=this.art.events;"function"===typeof t?.remove&&t.destroyEvents?.has(s)?t.remove(s):s()}else t.removeEventListener?.(e,a)};this.own(r);try{s=this.art.proxy(t,e,a),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 C({min:t,max:e,container:i,findIndex:n,onChange:a,steps:s=[]}){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

\n
\n ${s.map(()=>'
').join("")}\n
\n
\n
\n
\n
\n ${s.map(t=>t.hide?"":`
${t.name}
`).join("")}\n
\n `;const c=o(".apd-slider-dot",i),p=o(".apd-slider-progress",i);let h=!1;function u(i){if(!r.active)return;if(void 0===i&&(i=n()),ie)return;const o=(i-t)/(e-t);c.style.left=100*o+"%",0===s.length&&(p.style.width=c.style.left),a(i)}function m(n){const{top:a,height:s,left:r,width:o}=i.getBoundingClientRect();if(this.art.isRotate){const i=l(n.clientY-a,0,s);u(Math.round(i/s*(e-t)+t))}else{const i=l(n.clientX-r,0,o);u(Math.round(i/o*(e-t)+t))}}return r.own(()=>h=!1),r.proxy(i,"click",t=>{m.call(this,t)}),r.proxy(i,"pointerdown",t=>{h=0===t.button}),r.on("document:pointermove",t=>{h&&m.call(this,t)}),r.on("document:pointerup",t=>{h&&(h=!1,m.call(this,t))}),{reset:u}}const D='',T='',P='',A='',L='',H='',O='',N='',V='',q='',I='',j='';function B(){const{option:t}=this;return`\n
\n ${I}${q}\n
\n
\n ${P}\n
\n
\n
\n \u6309\u7c7b\u578b\u5c4f\u853d\n
\n
\n ${A}${L}\n
\u6eda\u52a8
\n
\n
\n ${H}${O}\n
\u9876\u90e8
\n
\n
\n ${N}${V}\n
\u5e95\u90e8
\n
\n
\n
\n
\n
\n ${T}${D}\n \u9632\u6b62\u5f39\u5e55\u91cd\u53e0\n
\n
\n ${T}${D}\n \u540c\u6b65\u89c6\u9891\u901f\u5ea6\n
\n
\n
\n \u4e0d\u900f\u660e\u5ea6\n
\n
\u672a\u77e5
\n
\n
\n \u663e\u793a\u533a\u57df\n
\n
\u672a\u77e5
\n
\n
\n \u5f39\u5e55\u5b57\u53f7\n
\n
\u672a\u77e5
\n
\n
\n \u5f39\u5e55\u901f\u5ea6\n
\n
\u672a\u77e5
\n
\n
\n
\n
\n
\n
\n ${j}\n
\n
\n
\n \u6a21\u5f0f\n
\n
\n ${L}\n
\u6eda\u52a8
\n
\n
\n ${O}\n
\u9876\u90e8
\n
\n
\n ${V}\n
\u5e95\u90e8
\n
\n
\n
\n
\n \u989c\u8272\n
\n ${this.COLOR.map(t=>`
`).join("")}\n
\n
\n
\n
\n
\n \n
\u53d1\u9001
\n
\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 a=()=>{document.removeEventListener("DOMContentLoaded",a),i[e]===n&&delete i[e];const s=document.getElementById(t);s?s.textContent=n.textContent:(document.head||document.documentElement).appendChild(n)};document.addEventListener("DOMContentLoaded",a,{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 R{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 F(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(a){try{this.destroy()}catch(s){console.warn("Failed to roll back danmuku setting:",s)}throw a}}static get icons(){return{$on:I,$off:q,$config:P,$style:j,$mode_0_off:A,$mode_0_on:L,$mode_1_off:H,$mode_1_on:O,$mode_2_off:N,$mode_2_on:V,$check_on:T,$check_off:D}}get option(){return this.danmuku.option}get outside(){return this.template.$mount!==this.template.$controlsCenter}get TEMPLATE(){return B.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:a,$syncVideo:s,$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(a,"click",()=>{this.danmuku.config({antiOverlap:!this.option.antiOverlap}),this.reset()}),this.lifecycle.proxy(s,"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 C.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(),a=e.getBoundingClientRect(),s=i.getBoundingClientRect(),r=a.width/2-n.width/2,o=s.left-(n.left-r),l=n.right+r-s.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 a={text:n,mode:t.option.mode,color:t.option.color,time:t.art.currentTime},s=t=>{e.active&&console.error("Error emitting danmuku:",t)};try{t.emitting=!0;const n=await e.wait(t.option.beforeEmit(a));if(!e.active)return;if(t.emitting=!1,!0!==n)return;if(a.border=!0,delete a.time,Promise.resolve(t.danmuku.emit(a)).catch(s),!e.active)return;i.value="",t.lock()}catch(r){s(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 a=()=>{t.timer=setTimeout(()=>{t.lifecycle.active&&(0===n?t.unlock():(n-=1,i.textContent=n,a()))},1e3)};a()}(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.widtht.dataset.color===this.option.color.toUpperCase());s&&t(s,"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 Z(t){return e=>{const i=new k(e,t);let n;try{n=e.isDestroy?void 0:new R(e,i),!e.isDestroy&&i.option.heatmap&&z(e,i,i.option.heatmap)}catch(a){try{n?.destroy()}catch{}try{i.destroy()}catch{}throw a}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 Z.icons=R.icons,Z}); +!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(/]*?p="(?

[^"]+)"[^>]*>(?.*?)<\/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,a=i(e);globalThis.postMessage({danmus:a,id:n})}let a=0;function s(t,{signal:s,onCancel:r}={}){return new Promise((o,l)=>{let d,c,p,h=!1;const u=++a,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}(s));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!==c){const n=c;c=void 0;try{URL.revokeObjectURL(n)}catch(i){e||(t=i),e=!0}}if(e)throw t}function g(t,e){if(h)return;h=!0;let i=arguments.length>1;s?.removeEventListener("abort",m),p?.();try{f()}catch(n){i||(e=n),i=!0}i?l(e):o(t)}function y(t,e){if(!h){console.error("Error parsing Bilibili Danmu:",e);try{g(i(t))}catch(n){g(void 0,n)}}}s?.aborted?m():(s?.addEventListener("abort",m),p=r?.(m),h?p?.():async function(){const a=s?await fetch(t,{signal:s}):await fetch(t);if(h)return;const r=await a.text();if(!h)try{const t=`\n ${e.toString()}\n ${i.toString()}\n onmessage = ${n.toString()}\n `;if(c=URL.createObjectURL(new Blob([t],{type:"application/javascript"})),h)return void f();if(d=new Worker(c),h)return void f();d.onmessage=t=>{if(h||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 c(t){const e=l(t);e.closed=!0;for(const i of[...e.tasks])i.cancel()}function p(t,e,i){const n=t.states[e]||[];for(let a=0;a{const a=n.$ref.offsetTop,s=this.owner.getLeft(n.$ref)-i,r=n.$ref.clientHeight,o=n.$ref.clientWidth,l=s+o,d=e-l,c=l/n.$restTime,p={};p.top=a,p.left=s,p.height=r,p.width=o,p.right=d,p.speed=c,p.distance=l,p.time=n.$restTime,p.mode=n.mode,t.push(p)}),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,a){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=`${a}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()}}const u=Symbol("cancelled danmuku frame");class m{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}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()}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;!this.running||this.closed||this.fault||t.art.isDestroy||t.isStop||null!==this.frame||this.operation||(this.frame=window.requestAnimationFrame(()=>{if(this.frame=null,t.timer=null,this.closed||this.fault||t.isStop||t.art.isDestroy)return;let e;const i=new Promise(t=>e=()=>t(u)),n={generation:this.generation,cancel:e,wait:t=>Promise.race([t,i]),ref:null};return this.operation=n,this.run(n).catch(t=>{this.active(n)&&this.fail(t)}).finally(()=>{this.release(n),this.operation===n&&(this.operation=null,this.schedule())})}),t.timer=this.frame)}async run(t){const e=this.owner;if(!e.art.playing||!this.active(t))return;e.filter("emit",t=>{const i=(Date.now()-t.$lastStartTime)/1e3;t.$restTime-=i,t.$lastStartTime=Date.now(),t.$restTime<=0&&e.makeWait(t)});const i=e.readys;for(const a of i){if(!this.active(t))return;if(this.failedItems.has(a))continue;let i;try{i=await t.wait(e.option.beforeVisible(a))}catch(n){if(!this.active(t))return;this.failedItems.add(a),this.report(n);continue}if(!this.active(t))return;if(!i)continue;const{clientWidth:s,clientHeight:r}=e.$player,o=e.renderer.prepare(a,t);if(!this.active(t))return;a.$lastStartTime=Date.now(),a.$restTime=e.speed;const l=s+o.clientWidth,d=await t.wait(e.postMessage({type:"getDanmuTop",target:{mode:a.mode,height:o.clientHeight,speed:l/a.$restTime},visibles:e.visibles,antiOverlap:e.option.antiOverlap,clientWidth:s,clientHeight:r,marginBottom:e.marginBottom,marginTop:e.marginTop})),c="symbol"===typeof d?void 0:d.result;if(!this.active(t)||a.$ref!==o)return;void 0!==c?(a.$lastStartTime=Date.now(),e.setState(a,"emit"),e.renderer.place(a,o,c,l,s),t.ref=null,e.art.emit("artplayerPluginDanmuku:visible",a)):(e.setState(a,"ready"),this.release(t))}}destroy(){this.closed=!0,this.invalidate()}}let f=0;class g{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=++f;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(a){this.fail(a)}})}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 y='/*!\n * artplayer-plugin-danmuku.js v5.3.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=t.height)return h}const a=[];for(let g=1;g{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(ie.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',v="undefined"!==typeof self&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",y],{type:"text/javascript;charset=utf-8"});function w(t){let e;try{if(e=v&&(self.URL||self.webkitURL).createObjectURL(v),!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(y),{type:"module",name:t?.name})}}class k{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 h(this),this.scheduler=new m(this),this.option=k.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(a){throw t.off("destroy",this.destroy),c(this),this.scheduler.destroy(),a}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 k.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 k.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 k.option.fontSize}get $ref(){return this.renderer.acquire()}get readys(){return function(t){const{currentTime:e}=t.art,i=[];return p(t,"ready",t=>i.push(t)),p(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,a=i.closed||t.art.isDestroy;const s=new Promise(t=>n=t),r=new Set,d="function"===typeof AbortController?new AbortController:void 0,c={replace:e,signal:d?.signal,active:()=>!a&&!i.closed&&!t.art.isDestroy,onCancel:t=>c.active()?(r.add(t),()=>r.delete(t)):(t(),()=>{}),cancel(){if(!a){a=!0,n(o),d?.abort();for(const t of[...r])t();r.clear()}},wait:t=>Promise.race([t,s]),emit(e){i.emitting.push(c);try{return t.emit(e)}finally{i.emitting.pop()}},finish(){i.tasks.delete(c),r.clear()}};return a?n(o):i.tasks.add(c),c}(this,void 0===e);try{if(!n.active())return this;const a=function(e,i){return"function"===typeof e?{asynchronous:!0,value:e()}:t(e)?{asynchronous:!0,value:e}:"string"===typeof e?{asynchronous:!0,value:s(e,i)}:{asynchronous:!1,value:Array.isArray(e)?e:[]}}(e||this.option.danmuku,n),r=a.asynchronous?await n.wait(a.value):a.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{const i=s[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:a,mount:s}){const r=Object.assign({},i,t,e);return n(r),r.mode=a(r.mode,0,2),r.speed=a(r.speed,1,10),r.opacity=a(r.opacity,0,1),r.lockTime=a(r.lockTime,1,60),r.maxLength=a(r.maxLength,1,1e3),r.mount=r.mount||s,r}(this.option,e,{defaults:k.option,validate:t=>this.validator(t,k.scheme),clamp:n,mount:a});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 g(()=>new w,t=>this.scheduler.fail(t)),this.worker=this.workerClient.worker}filter(t,e){return p(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(){c(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 x=4294967295;function $(t,e){let i=0,n=t.length;for(;iNumber.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 a?a:{}),l=Object.assign({},r,o);for(const x of Object.keys(r))Number.isFinite(l[x])||(l[x]=r[x]);if(l.sampling<=0&&(l.sampling=r.sampling),l.xMin===l.xMax||l.yMin===l.yMax)return null;const d=Array.isArray(s)&&s.length>0,c=d?[...s]: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>x)return[];const a=t.map(t=>t.time).filter(t=>"number"===typeof t&&!Number.isNaN(t)).sort((t,e)=>t-e),s=[],r=i/e;if(!Number.isFinite(r))return[];for(let o=0;o<=e;o+=n){if(s.length>=x||o+n===o)return[];const t=o*r,e=(o+n)*r;s.push([o,$(a,e)-$(a,t)])}return s}(n,t,i,l.sampling);if(!c.length||!c.every(t=>Array.isArray(t)&&Number.isFinite(t[0])&&Number.isFinite(t[1])))return null;const p=c[c.length-1];if(p[0]!==t){if(c.length===x)return null;c.push([t,p[1]])}let h=1/0,u=-1/0;for(const x of c)h=Math.min(h,x[1]),u=Math.max(u,x[1]);const m=(h+u)/2;for(const x of c){const t=x[1];x[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 x of c)g=Math.max(g,x[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 a=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),s=b(Math.cos(a.angle)*l.flattening,0,1,1,0),r=a.angle*s+(n?Math.PI:0),o=a.length*l.smoothing;return[t[0]+Math.cos(r)*o,v(t[1]+Math.sin(r)*o)]},k=c.map(i=>[b(i[0],l.xMin,l.xMax,0,t),v(b(i[1],l.yMin,l.yMax,e,0))]);if(!k.every(t=>t.every(Number.isFinite)))return null;const M=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 a=w(n[i-1],n[i-2],t),s=w(t,n[i-1],n[i+1],!0);return`C ${a[0]},${a[1]} ${s[0]},${s[1]} ${t[0]},${t[1]}${i===n.length-1?" z":""}`}).join(" ");return/NaN|Infinity/u.test(M)?null:{path:M,opacity:l.opacity,width:t,height:e}}let S=0;function z(t,e,i){if(t.isDestroy)return;const{query:n}=t.constructor.utils;let a;const s=[];let r,o,l,d=!1;const c=()=>!d&&!t.isDestroy;function p(e,i){const n=i;s.push([e,n]),t.on(e,n)}function h(e){if(d)return;let i;d=!0,o=null,l=null;let n=!1;const a=t=>{try{t()}catch(e){n||(i=e),n=!0}};for(const[r,o]of s.splice(0))a(()=>t.off(r,o));if(e&&r&&t.controls.heatmap===r&&a(()=>t.controls.remove("heatmap")),r=void 0,n)throw i}function u(t){c()&&o&&l&&(o.setAttribute("offset",100*t+"%"),l.setAttribute("offset",100*t+"%"))}function m(s){try{!function(s=[]){if(!c())return;o=null,l=null;const d=r;if(d.innerHTML="",t.option.isLive)return;const p=M({width:d.offsetWidth,height:d.offsetHeight,duration:t.duration,queue:e.queue,option:i,points:s});if(!p||!c())return;const h=d.ownerDocument;for(a||(a=h?"heatmap-solids":"heatmap-solids-"+ ++S);h?.getElementById(a);)a="heatmap-solids-"+ ++S;d.innerHTML=`\n \n \n \n \n \n \n \n \n \n \n \n `,o=n("#heatmap-start",d),l=n("#heatmap-stop",d),u(t.played)}(s)}catch(d){try{h(!0)}catch{}throw d}}p("destroy",()=>h(!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(){h(!1)},mounted(e){if(r=e,d)return t.controls.heatmap===e&&t.controls.remove("heatmap"),void(r=void 0);c()?(p("video:timeupdate",()=>u(t.played)),p("setBar",(t,e)=>{"played"===t&&u(e)}),p("ready",()=>m()),p("resize",()=>m()),p("artplayerPluginDanmuku:loaded",()=>m()),p("artplayerPluginDanmuku:points",t=>m(t))):h(!0)}})}catch(f){try{h(!0)}catch{}throw f}return()=>h(!0)}const E=new WeakMap;class F{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 a=t;if(!this.active)return;const s=()=>"function"===typeof a.getPropertyPriority?a.getPropertyPriority(e):void 0;let r=E.get(a);r||(r=new Map,E.set(a,r));let o=r.get(e);o||(o={original:a[e],present:e in a||void 0!==a[e],priority:s(),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&&a[e]===o.last&&s()===o.lastPriority){const t=[...o.owners.values()];t.length?(o.apply(t[t.length-1]),o.last=a[e],o.lastPriority=s()):void 0!==o.priority?a.setProperty(e,o.original,o.priority):o.present?o.apply(o.original):delete a[e]}o.owners.size||(r.delete(e),r.size||E.delete(a))}),o.owners.delete(this),o.owners.set(this,i),o.apply(i),o.last=a[e],o.lastPriority=s()}on(t,e){if(!this.active)return;const i=this;function n(...t){if(i.active)return e.apply(this,t)}const a=()=>this.art.off(t,n);this.own(a);try{this.art.on(t,n),this.active||a()}catch(s){throw this.release(a),s}}proxy(t,e,i){if(!this.active)return;const n=this;function a(...t){if(n.active)return i.apply(this,t)}let s;const r=()=>{if("function"===typeof s){const t=this.art.events;"function"===typeof t?.remove&&t.destroyEvents?.has(s)?t.remove(s):s()}else t.removeEventListener?.(e,a)};this.own(r);try{s=this.art.proxy(t,e,a),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 C({min:t,max:e,container:i,findIndex:n,onChange:a,steps:s=[]}){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

\n
\n ${s.map(()=>'
').join("")}\n
\n
\n
\n
\n
\n ${s.map(t=>t.hide?"":`
${t.name}
`).join("")}\n
\n `;const c=o(".apd-slider-dot",i),p=o(".apd-slider-progress",i);let h=!1;function u(i){if(!r.active)return;if(void 0===i&&(i=n()),ie)return;const o=(i-t)/(e-t);c.style.left=100*o+"%",0===s.length&&(p.style.width=c.style.left),a(i)}function m(n){const{top:a,height:s,left:r,width:o}=i.getBoundingClientRect();if(this.art.isRotate){const i=l(n.clientY-a,0,s);u(Math.round(i/s*(e-t)+t))}else{const i=l(n.clientX-r,0,o);u(Math.round(i/o*(e-t)+t))}}return r.own(()=>h=!1),r.proxy(i,"click",t=>{m.call(this,t)}),r.proxy(i,"pointerdown",t=>{h=0===t.button}),r.on("document:pointermove",t=>{h&&m.call(this,t)}),r.on("document:pointerup",t=>{h&&(h=!1,m.call(this,t))}),{reset:u}}const D='',T='',P='',A='',L='',H='',O='',N='',V='',q='',I='',j='';function B(){const{option:t}=this;return`\n
\n ${I}${q}\n
\n
\n ${P}\n
\n
\n
\n \u6309\u7c7b\u578b\u5c4f\u853d\n
\n
\n ${A}${L}\n
\u6eda\u52a8
\n
\n
\n ${H}${O}\n
\u9876\u90e8
\n
\n
\n ${N}${V}\n
\u5e95\u90e8
\n
\n
\n
\n
\n
\n ${T}${D}\n \u9632\u6b62\u5f39\u5e55\u91cd\u53e0\n
\n
\n ${T}${D}\n \u540c\u6b65\u89c6\u9891\u901f\u5ea6\n
\n
\n
\n \u4e0d\u900f\u660e\u5ea6\n
\n
\u672a\u77e5
\n
\n
\n \u663e\u793a\u533a\u57df\n
\n
\u672a\u77e5
\n
\n
\n \u5f39\u5e55\u5b57\u53f7\n
\n
\u672a\u77e5
\n
\n
\n \u5f39\u5e55\u901f\u5ea6\n
\n
\u672a\u77e5
\n
\n
\n
\n
\n
\n
\n ${j}\n
\n
\n
\n \u6a21\u5f0f\n
\n
\n ${L}\n
\u6eda\u52a8
\n
\n
\n ${O}\n
\u9876\u90e8
\n
\n
\n ${V}\n
\u5e95\u90e8
\n
\n
\n
\n
\n \u989c\u8272\n
\n ${this.COLOR.map(t=>`
`).join("")}\n
\n
\n
\n
\n
\n \n
\u53d1\u9001
\n
\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 a=()=>{document.removeEventListener("DOMContentLoaded",a),i[e]===n&&delete i[e];const s=document.getElementById(t);s?s.textContent=n.textContent:(document.head||document.documentElement).appendChild(n)};document.addEventListener("DOMContentLoaded",a,{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 R{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 F(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(a){try{this.destroy()}catch(s){console.warn("Failed to roll back danmuku setting:",s)}throw a}}static get icons(){return{$on:I,$off:q,$config:P,$style:j,$mode_0_off:A,$mode_0_on:L,$mode_1_off:H,$mode_1_on:O,$mode_2_off:N,$mode_2_on:V,$check_on:T,$check_off:D}}get option(){return this.danmuku.option}get outside(){return this.template.$mount!==this.template.$controlsCenter}get TEMPLATE(){return B.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:a,$syncVideo:s,$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(a,"click",()=>{this.danmuku.config({antiOverlap:!this.option.antiOverlap}),this.reset()}),this.lifecycle.proxy(s,"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 C.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(),a=e.getBoundingClientRect(),s=i.getBoundingClientRect(),r=a.width/2-n.width/2,o=s.left-(n.left-r),l=n.right+r-s.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 a={text:n,mode:t.option.mode,color:t.option.color,time:t.art.currentTime},s=t=>{e.active&&console.error("Error emitting danmuku:",t)};try{t.emitting=!0;const n=await e.wait(t.option.beforeEmit(a));if(!e.active)return;if(t.emitting=!1,!0!==n)return;if(a.border=!0,delete a.time,Promise.resolve(t.danmuku.emit(a)).catch(s),!e.active)return;i.value="",t.lock()}catch(r){s(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 a=()=>{t.timer=setTimeout(()=>{t.lifecycle.active&&(0===n?t.unlock():(n-=1,i.textContent=n,a()))},1e3)};a()}(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.widtht.dataset.color===this.option.color.toUpperCase());s&&t(s,"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 Z(t){return e=>{const i=new k(e,t);let n;try{n=e.isDestroy?void 0:new R(e,i),!e.isDestroy&&i.option.heatmap&&z(e,i,i.option.heatmap)}catch(a){try{n?.destroy()}catch{}try{i.destroy()}catch{}throw a}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 Z.icons=R.icons,Z}); diff --git a/packages/artplayer-plugin-danmuku/dist/artplayer-plugin-danmuku.legacy.js b/packages/artplayer-plugin-danmuku/dist/artplayer-plugin-danmuku.legacy.js index 4811a82a9..476669bee 100644 --- a/packages/artplayer-plugin-danmuku/dist/artplayer-plugin-danmuku.legacy.js +++ b/packages/artplayer-plugin-danmuku/dist/artplayer-plugin-danmuku.legacy.js @@ -4,4 +4,4 @@ * (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";var t=Object.defineProperty,e=Object.defineProperties,i=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable,r=Math.pow,o=(e,i,n)=>i in e?t(e,i,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[i]=n,l=(t,e)=>{for(var i in e||(e={}))a.call(e,i)&&o(t,i,e[i]);if(n)for(var i of n(e))s.call(e,i)&&o(t,i,e[i]);return t},d=(t,n)=>e(t,i(n)),c=(t,e,i)=>new Promise((n,a)=>{var s=t=>{try{o(i.next(t))}catch(e){a(e)}},r=t=>{try{o(i.throw(t))}catch(e){a(e)}},o=t=>t.done?n(t.value):Promise.resolve(t.value).then(s,r);o((i=i.apply(t,e)).next())});function p(t){return t instanceof Promise||"[object Promise]"===Object.prototype.toString.call(t)}function h(t){switch(t){case 1:case 2:case 3:default:return 0;case 4:return 2;case 5:return 1}}function u(t){if("string"!==typeof t)return[];const e=new RegExp(']*?p="(?

[^"]+)"[^>]*>(?.*?)<\\/d>',"gs"),i=t.matchAll(e);return Array.from(i).map(t=>{const e=t.groups.p.split(",");if(e.length>=8){return{text:t.groups.text.trim().replaceAll(""",'"').replaceAll("'","'").replaceAll("<","<").replaceAll(">",">").replaceAll("&","&"),time:Number(e[0]),mode:h(Number(e[1])),fontSize:Number(e[2]),color:`#${Number(e[3]).toString(16)}`,timestamp:Number(e[4]),pool:Number(e[5]),userID:e[6],rowID:Number(e[7])}}return null}).filter(Boolean)}function m({data:t}){const{xml:e,id:i}=t,n=u(e);globalThis.postMessage({danmus:n,id:i})}let f=0;function g(t,{signal:e,onCancel:i}={}){return new Promise((n,a)=>{let s,r,o,l=!1;const d=++f,p=()=>y(void 0,function(t){if(void 0!==(null==t?void 0:t.reason))return t.reason;const e=new Error("Bilibili Danmu loading cancelled");return e.name="AbortError",e}(e));function g(){let t,e=!1;try{if(s){const t=s;s=void 0,t.onmessage=null,t.onerror=null,t.onmessageerror=null,t.terminate()}}catch(i){t=i,e=!0}if(void 0!==r){const n=r;r=void 0;try{URL.revokeObjectURL(n)}catch(i){e||(t=i),e=!0}}if(e)throw t}function y(t,i){if(l)return;l=!0;let s=arguments.length>1;null==e||e.removeEventListener("abort",p),null==o||o();try{g()}catch(r){s||(i=r),s=!0}s?a(i):n(t)}function v(t,e){if(!l){console.error("Error parsing Bilibili Danmu:",e);try{y(u(t))}catch(i){y(void 0,i)}}}(null==e?void 0:e.aborted)?p():(null==e||e.addEventListener("abort",p),o=null==i?void 0:i(p),l?null==o||o():function(){return c(this,null,function*(){const i=e?yield fetch(t,{signal:e}):yield fetch(t);if(l)return;const n=yield i.text();if(!l)try{const t=`\n ${h.toString()}\n ${u.toString()}\n onmessage = ${m.toString()}\n `;if(r=URL.createObjectURL(new Blob([t],{type:"application/javascript"})),l)return void g();if(s=new Worker(r),l)return void g();s.onmessage=t=>{var e;if(l||(null==(e=t.data)?void 0:e.id)!==d)return;const{danmus:i}=t.data;Array.isArray(i)?y(i):y(void 0,new Error("Invalid Bilibili Danmu worker response"))},s.onerror=t=>{var e;null==(e=t.preventDefault)||e.call(t),v(n,t.error||t)},s.onmessageerror=t=>v(n,t.error||t),s.postMessage({xml:n,id:d})}catch(a){v(n,a)}})}().catch(t=>y(void 0,t)))})}const y=new WeakMap,v=Symbol("cancelled danmuku input");function w(t){return y.has(t)||y.set(t,{closed:!1,tasks:new Set,emitting:[]}),y.get(t)}function k(t){const e=w(t),i=e.emitting[e.emitting.length-1];return!e.closed&&!t.art.isDestroy&&(!i||i.active())}function x(t){const e=w(t);e.closed=!0;for(const i of[...e.tasks])i.cancel()}function b(t,e,i){const n=t.states[e]||[];for(let a=0;a{const a=n.$ref.offsetTop,s=this.owner.getLeft(n.$ref)-i,r=n.$ref.clientHeight,o=n.$ref.clientWidth,l=s+o,d=e-l,c=l/n.$restTime,p={};p.top=a,p.left=s,p.height=r,p.width=o,p.right=d,p.speed=c,p.distance=l,p.time=n.$restTime,p.mode=n.mode,t.push(p)}),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,a){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=`${a}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()}}const M=Symbol("cancelled danmuku frame");class S{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}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(){var t;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)}null==(t=this.owner.workerClient)||t.cancel(),this.failedItems.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(){var t;if(!this.closed&&!this.owner.art.isDestroy&&(this.failedItems.clear(),this.fault))try{null==(t=this.owner.workerClient)||t.dispose(),this.owner.createWorker(),this.fault=!1}catch(e){this.report(e)}}schedule(){const t=this.owner;!this.running||this.closed||this.fault||t.art.isDestroy||t.isStop||null!==this.frame||this.operation||(this.frame=window.requestAnimationFrame(()=>{if(this.frame=null,t.timer=null,this.closed||this.fault||t.isStop||t.art.isDestroy)return;let e;const i=new Promise(t=>e=()=>t(M)),n={generation:this.generation,cancel:e,wait:t=>Promise.race([t,i]),ref:null};return this.operation=n,this.run(n).catch(t=>{this.active(n)&&this.fail(t)}).finally(()=>{this.release(n),this.operation===n&&(this.operation=null,this.schedule())})}),t.timer=this.frame)}run(t){return c(this,null,function*(){const e=this.owner;if(!e.art.playing||!this.active(t))return;e.filter("emit",t=>{const i=(Date.now()-t.$lastStartTime)/1e3;t.$restTime-=i,t.$lastStartTime=Date.now(),t.$restTime<=0&&e.makeWait(t)});const i=e.readys;for(const a of i){if(!this.active(t))return;if(this.failedItems.has(a))continue;let i;try{i=yield t.wait(e.option.beforeVisible(a))}catch(n){if(!this.active(t))return;this.failedItems.add(a),this.report(n);continue}if(!this.active(t))return;if(!i)continue;const{clientWidth:s,clientHeight:r}=e.$player,o=e.renderer.prepare(a,t);if(!this.active(t))return;a.$lastStartTime=Date.now(),a.$restTime=e.speed;const l=s+o.clientWidth,d=yield t.wait(e.postMessage({type:"getDanmuTop",target:{mode:a.mode,height:o.clientHeight,speed:l/a.$restTime},visibles:e.visibles,antiOverlap:e.option.antiOverlap,clientWidth:s,clientHeight:r,marginBottom:e.marginBottom,marginTop:e.marginTop})),c="symbol"===typeof d?void 0:d.result;if(!this.active(t)||a.$ref!==o)return;void 0!==c?(e.setState(a,"emit"),e.renderer.place(a,o,c,l,s),t.ref=null,e.art.emit("artplayerPluginDanmuku:visible",a)):(e.setState(a,"ready"),this.release(t))}})}destroy(){this.closed=!0,this.invalidate()}}let z=0;class E{constructor(t,e){this.pending=new Map,this.closed=!1,this.failed=!1,this.onFailure=e,this.worker=t();try{this.worker.onmessage=t=>{var e;const i=this.pending.get(null==(e=t.data)?void 0:e.id);i&&(this.pending.delete(t.data.id),i.resolve(t.data))},this.worker.onerror=t=>{var e;null==(e=t.preventDefault)||e.call(t),this.fail(t.error||t)},this.worker.onmessageerror=t=>this.fail(t.error||t)}catch(i){try{this.dispose()}catch(n){}throw i}}request(t){t.id=++z;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(a){this.fail(a)}})}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(e){}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 F='/*!\n * artplayer-plugin-danmuku.js v5.3.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=t.height)return h}const a=[];for(let g=1;g{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(ie.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',C="undefined"!==typeof self&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",F],{type:"text/javascript;charset=utf-8"});function D(t){let e;try{if(e=C&&(self.URL||self.webkitURL).createObjectURL(C),!e)throw"";const i=new Worker(e,{type:"module",name:null==t?void 0: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(F),{type:"module",name:null==t?void 0:t.name})}}class P{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 $(this),this.scheduler=new S(this),this.option=P.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),k(this),t.on("destroy",this.destroy);try{if(this.config(e,!0),!k(this))return;this.createWorker()}catch(a){throw t.off("destroy",this.destroy),x(this),this.scheduler.destroy(),a}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(){var t,e;return null==(e=null==(t=this.art.plugins)?void 0:t.autoOrientation)?void 0:e.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 P.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 P.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 P.option.fontSize}get $ref(){return this.renderer.acquire()}get readys(){return function(t){const{currentTime:e}=t.art,i=[];return b(t,"ready",t=>i.push(t)),b(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}load(t){return c(this,null,function*(){const{errorHandle:e}=this.utils,i=function(t,e){const i=w(t);if(e)for(const d of[...i.tasks])d.replace&&d.cancel();let n,a=i.closed||t.art.isDestroy;const s=new Promise(t=>n=t),r=new Set,o="function"===typeof AbortController?new AbortController:void 0,l={replace:e,signal:null==o?void 0:o.signal,active:()=>!a&&!i.closed&&!t.art.isDestroy,onCancel:t=>l.active()?(r.add(t),()=>r.delete(t)):(t(),()=>{}),cancel(){if(!a){a=!0,n(v),null==o||o.abort();for(const t of[...r])t();r.clear()}},wait:t=>Promise.race([t,s]),emit(e){i.emitting.push(l);try{return t.emit(e)}finally{i.emitting.pop()}},finish(){i.tasks.delete(l),r.clear()}};return a?n(v):i.tasks.add(l),l}(this,void 0===t);try{if(!i.active())return this;const n=function(t,e){return"function"===typeof t?{asynchronous:!0,value:t()}:p(t)?{asynchronous:!0,value:t}:"string"===typeof t?{asynchronous:!0,value:g(t,e)}:{asynchronous:!1,value:Array.isArray(t)?t:[]}}(t||this.option.danmuku,i),a=n.asynchronous?yield i.wait(n.value):n.value;if(!i.active())return this;e(Array.isArray(a),"Danmuku need return an array as result");const s=a;if(void 0===t){if(this.reset(),!i.active())return this;this.queue=[],this.states={wait:[],ready:[],emit:[],stop:[]},this.renderer.clear()}for(let t=0;t{const e=a[t],i=s[t];return"function"===typeof e||"function"===typeof i||p(e)||p(i)?e!==i:JSON.stringify(e)!==JSON.stringify(i)}))&&!e)return this;const r=function(t,e,{defaults:i,validate:n,clamp:a,mount:s}){const r=Object.assign({},i,t,e);return n(r),r.mode=a(r.mode,0,2),r.speed=a(r.speed,1,10),r.opacity=a(r.opacity,0,1),r.lockTime=a(r.lockTime,1,60),r.maxLength=a(r.maxLength,1,1e3),r.mount=r.mount||s,r}(this.option,t,{defaults:P.option,validate:t=>this.validator(t,P.scheme),clamp:i,mount:n});if(!k(this))return this;const o=this.option.beforeVisible!==r.beforeVisible;return this.option=r,o&&(this.scheduler.invalidate(),this.scheduler.schedule()),t.fontSize&&(this.reset(),!k(this))||(this.option.visible?this.show():this.hide(),k(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 E(()=>new D,t=>this.scheduler.fail(t)),this.worker=this.workerClient.worker}filter(t,e){return b(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(){var t;x(this),this.scheduler.destroy();try{try{this.stop()}finally{null==(t=this.workerClient)||t.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 T=4294967295;function A(t,e){let i=0,n=t.length;for(;iNumber.isFinite(t)&&t>0))return null;const o={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},l=Object.assign({},"object"===typeof a?a:{}),d=Object.assign({},o,l);for(const r of Object.keys(o))Number.isFinite(d[r])||(d[r]=o[r]);if(d.sampling<=0&&(d.sampling=o.sampling),d.xMin===d.xMax||d.yMin===d.yMax)return null;const c=Array.isArray(s)&&s.length>0,p=c?[...s]: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>T)return[];const a=t.map(t=>t.time).filter(t=>"number"===typeof t&&!Number.isNaN(t)).sort((t,e)=>t-e),s=[],r=i/e;if(!Number.isFinite(r))return[];for(let o=0;o<=e;o+=n){if(s.length>=T||o+n===o)return[];const t=o*r,e=(o+n)*r;s.push([o,A(a,e)-A(a,t)])}return s}(n,t,i,d.sampling);if(!p.length||!p.every(t=>Array.isArray(t)&&Number.isFinite(t[0])&&Number.isFinite(t[1])))return null;const h=p[p.length-1];if(h[0]!==t){if(p.length===T)return null;p.push([t,h[1]])}let u=1/0,m=-1/0;for(const r of p)u=Math.min(u,r[1]),m=Math.max(m,r[1]);const f=(u+m)/2;for(const r of p){const t=r[1];r[1]=t*(t>f?1+d.scale:1-d.scale)+d.minHeight}const g=!c&&!Number.isFinite(l.yMin)&&!Number.isFinite(l.yMax);let y=0;for(const r of p)y=Math.max(y,r[1]);const v=g&&y>o.yMax/4;v&&(d.yMax=4*y);const w=t=>v?Math.min(e,Math.max(.75*e,t)):t,k=(t,e,i,n)=>{const a=function(t,e){const i=e[0]-t[0],n=e[1]-t[1];return{length:Math.sqrt(r(i,2)+r(n,2)),angle:Math.atan2(n,i)}}(e||t,i||t),s=L(Math.cos(a.angle)*d.flattening,0,1,1,0),o=a.angle*s+(n?Math.PI:0),l=a.length*d.smoothing;return[t[0]+Math.cos(o)*l,w(t[1]+Math.sin(o)*l)]},x=p.map(i=>[L(i[0],d.xMin,d.xMax,0,t),w(L(i[1],d.yMin,d.yMax,e,0))]);if(!x.every(t=>t.every(Number.isFinite)))return null;const b=x.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 a=k(n[i-1],n[i-2],t),s=k(t,n[i-1],n[i+1],!0);return`C ${a[0]},${a[1]} ${s[0]},${s[1]} ${t[0]},${t[1]}${i===n.length-1?" z":""}`}).join(" ");return/NaN|Infinity/u.test(b)?null:{path:b,opacity:d.opacity,width:t,height:e}}let H=0;function N(t,e,i){if(t.isDestroy)return;const{query:n}=t.constructor.utils;let a;const s=[];let r,o,l,d=!1;const c=()=>!d&&!t.isDestroy;function p(e,i){const n=i;s.push([e,n]),t.on(e,n)}function h(e){if(d)return;let i;d=!0,o=null,l=null;let n=!1;const a=t=>{try{t()}catch(e){n||(i=e),n=!0}};for(const[r,o]of s.splice(0))a(()=>t.off(r,o));if(e&&r&&t.controls.heatmap===r&&a(()=>t.controls.remove("heatmap")),r=void 0,n)throw i}function u(t){c()&&o&&l&&(o.setAttribute("offset",100*t+"%"),l.setAttribute("offset",100*t+"%"))}function m(s){try{!function(s=[]){if(!c())return;o=null,l=null;const d=r;if(d.innerHTML="",t.option.isLive)return;const p=O({width:d.offsetWidth,height:d.offsetHeight,duration:t.duration,queue:e.queue,option:i,points:s});if(!p||!c())return;const h=d.ownerDocument;for(a||(a=h?"heatmap-solids":"heatmap-solids-"+ ++H);null==h?void 0:h.getElementById(a);)a="heatmap-solids-"+ ++H;d.innerHTML=`\n \n \n \n \n \n \n \n \n \n \n \n `,o=n("#heatmap-start",d),l=n("#heatmap-stop",d),u(t.played)}(s)}catch(d){try{h(!0)}catch(p){}throw d}}p("destroy",()=>h(!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(){h(!1)},mounted(e){if(r=e,d)return t.controls.heatmap===e&&t.controls.remove("heatmap"),void(r=void 0);c()?(p("video:timeupdate",()=>u(t.played)),p("setBar",(t,e)=>{"played"===t&&u(e)}),p("ready",()=>m()),p("resize",()=>m()),p("artplayerPluginDanmuku:loaded",()=>m()),p("artplayerPluginDanmuku:points",t=>m(t))):h(!0)}})}catch(f){try{h(!0)}catch(g){}throw f}return()=>h(!0)}const V=new WeakMap;class j{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 a=t;if(!this.active)return;const s=()=>"function"===typeof a.getPropertyPriority?a.getPropertyPriority(e):void 0;let r=V.get(a);r||(r=new Map,V.set(a,r));let o=r.get(e);o||(o={original:a[e],present:e in a||void 0!==a[e],priority:s(),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&&a[e]===o.last&&s()===o.lastPriority){const t=[...o.owners.values()];t.length?(o.apply(t[t.length-1]),o.last=a[e],o.lastPriority=s()):void 0!==o.priority?a.setProperty(e,o.original,o.priority):o.present?o.apply(o.original):delete a[e]}o.owners.size||(r.delete(e),r.size||V.delete(a))}),o.owners.delete(this),o.owners.set(this,i),o.apply(i),o.last=a[e],o.lastPriority=s()}on(t,e){if(!this.active)return;const i=this;function n(...t){if(i.active)return e.apply(this,t)}const a=()=>this.art.off(t,n);this.own(a);try{this.art.on(t,n),this.active||a()}catch(s){throw this.release(a),s}}proxy(t,e,i){if(!this.active)return;const n=this;function a(...t){if(n.active)return i.apply(this,t)}let s;const r=()=>{var i,n;if("function"===typeof s){const t=this.art.events;"function"===typeof(null==t?void 0:t.remove)&&(null==(i=t.destroyEvents)?void 0:i.has(s))?t.remove(s):s()}else null==(n=t.removeEventListener)||n.call(t,e,a)};this.own(r);try{s=this.art.proxy(t,e,a),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 q({min:t,max:e,container:i,findIndex:n,onChange:a,steps:s=[]}){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

\n
\n ${s.map(()=>'
').join("")}\n
\n
\n
\n
\n
\n ${s.map(t=>t.hide?"":`
${t.name}
`).join("")}\n
\n `;const c=o(".apd-slider-dot",i),p=o(".apd-slider-progress",i);let h=!1;function u(i){if(!r.active)return;if(void 0===i&&(i=n()),ie)return;const o=(i-t)/(e-t);c.style.left=100*o+"%",0===s.length&&(p.style.width=c.style.left),a(i)}function m(n){const{top:a,height:s,left:r,width:o}=i.getBoundingClientRect();if(this.art.isRotate){const i=l(n.clientY-a,0,s);u(Math.round(i/s*(e-t)+t))}else{const i=l(n.clientX-r,0,o);u(Math.round(i/o*(e-t)+t))}}return r.own(()=>h=!1),r.proxy(i,"click",t=>{m.call(this,t)}),r.proxy(i,"pointerdown",t=>{h=0===t.button}),r.on("document:pointermove",t=>{h&&m.call(this,t)}),r.on("document:pointerup",t=>{h&&(h=!1,m.call(this,t))}),{reset:u}}const I='',R='',B='',Z='',W='',_='',U='',G='',X='',Y='',J='',K='';function Q(){const{option:t}=this;return`\n
\n ${J}${Y}\n
\n
\n ${B}\n
\n
\n
\n \u6309\u7c7b\u578b\u5c4f\u853d\n
\n
\n ${Z}${W}\n
\u6eda\u52a8
\n
\n
\n ${_}${U}\n
\u9876\u90e8
\n
\n
\n ${G}${X}\n
\u5e95\u90e8
\n
\n
\n
\n
\n
\n ${R}${I}\n \u9632\u6b62\u5f39\u5e55\u91cd\u53e0\n
\n
\n ${R}${I}\n \u540c\u6b65\u89c6\u9891\u901f\u5ea6\n
\n
\n
\n \u4e0d\u900f\u660e\u5ea6\n
\n
\u672a\u77e5
\n
\n
\n \u663e\u793a\u533a\u57df\n
\n
\u672a\u77e5
\n
\n
\n \u5f39\u5e55\u5b57\u53f7\n
\n
\u672a\u77e5
\n
\n
\n \u5f39\u5e55\u901f\u5ea6\n
\n
\u672a\u77e5
\n
\n
\n
\n
\n
\n
\n ${K}\n
\n
\n
\n \u6a21\u5f0f\n
\n
\n ${W}\n
\u6eda\u52a8
\n
\n
\n ${U}\n
\u9876\u90e8
\n
\n
\n ${X}\n
\u5e95\u90e8
\n
\n
\n
\n
\n \u989c\u8272\n
\n ${this.COLOR.map(t=>`
`).join("")}\n
\n
\n
\n
\n
\n \n
\u53d1\u9001
\n
\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 a=()=>{document.removeEventListener("DOMContentLoaded",a),i[e]===n&&delete i[e];const s=document.getElementById(t);s?s.textContent=n.textContent:(document.head||document.documentElement).appendChild(n)};document.addEventListener("DOMContentLoaded",a,{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 tt{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 j(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(a){try{this.destroy()}catch(s){console.warn("Failed to roll back danmuku setting:",s)}throw a}}static get icons(){return{$on:J,$off:Y,$config:B,$style:K,$mode_0_off:Z,$mode_0_on:W,$mode_1_off:_,$mode_1_on:U,$mode_2_off:G,$mode_2_on:X,$check_on:R,$check_off:I}}get option(){return this.danmuku.option}get outside(){return this.template.$mount!==this.template.$controlsCenter}get TEMPLATE(){return Q.call(this)}get OPACITY(){return l({min:0,max:100,steps:[]},this.option.OPACITY)}get FONT_SIZE(){return l({min:12,max:120,steps:[]},this.option.FONT_SIZE)}get MARGIN(){return l({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 l({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:a,$syncVideo:s,$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(a,"click",()=>{this.danmuku.config({antiOverlap:!this.option.antiOverlap}),this.reset()}),this.lifecycle.proxy(s,"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(d(l({},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(d(l({},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(d(l({},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(d(l({},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 q.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(),a=e.getBoundingClientRect(),s=i.getBoundingClientRect(),r=a.width/2-n.width/2,o=s.left-(n.left-r),l=n.right+r-s.right;e.style.left=o>0?`${-r+o}px`:l>0?-r-l+"px":-r+"px"}emit(){return function(t){return c(this,null,function*(){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 a={text:n,mode:t.option.mode,color:t.option.color,time:t.art.currentTime},s=t=>{e.active&&console.error("Error emitting danmuku:",t)};try{t.emitting=!0;const n=yield e.wait(t.option.beforeEmit(a));if(!e.active)return;if(t.emitting=!1,!0!==n)return;if(a.border=!0,delete a.time,Promise.resolve(t.danmuku.emit(a)).catch(s),!e.active)return;i.value="",t.lock()}catch(r){s(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 a=()=>{t.timer=setTimeout(()=>{t.lifecycle.active&&(0===n?t.unlock():(n-=1,i.textContent=n,a()))},1e3)};a()}(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.widtht.dataset.color===this.option.color.toUpperCase());s&&t(s,"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;(null==t?void 0:t.parentElement)&&t.parentElement.removeChild(t)}}function et(t){return e=>{const i=new P(e,t);let n;try{n=e.isDestroy?void 0:new tt(e,i),!e.isDestroy&&i.option.heatmap&&N(e,i,i.option.heatmap)}catch(a){try{null==n||n.destroy()}catch(s){}try{i.destroy()}catch(s){}throw a}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 et.icons=tt.icons,et}); +!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";var t=Object.defineProperty,e=Object.defineProperties,i=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable,r=Math.pow,o=(e,i,n)=>i in e?t(e,i,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[i]=n,l=(t,e)=>{for(var i in e||(e={}))a.call(e,i)&&o(t,i,e[i]);if(n)for(var i of n(e))s.call(e,i)&&o(t,i,e[i]);return t},d=(t,n)=>e(t,i(n)),c=(t,e,i)=>new Promise((n,a)=>{var s=t=>{try{o(i.next(t))}catch(e){a(e)}},r=t=>{try{o(i.throw(t))}catch(e){a(e)}},o=t=>t.done?n(t.value):Promise.resolve(t.value).then(s,r);o((i=i.apply(t,e)).next())});function p(t){return t instanceof Promise||"[object Promise]"===Object.prototype.toString.call(t)}function h(t){switch(t){case 1:case 2:case 3:default:return 0;case 4:return 2;case 5:return 1}}function u(t){if("string"!==typeof t)return[];const e=new RegExp(']*?p="(?

[^"]+)"[^>]*>(?.*?)<\\/d>',"gs"),i=t.matchAll(e);return Array.from(i).map(t=>{const e=t.groups.p.split(",");if(e.length>=8){return{text:t.groups.text.trim().replaceAll(""",'"').replaceAll("'","'").replaceAll("<","<").replaceAll(">",">").replaceAll("&","&"),time:Number(e[0]),mode:h(Number(e[1])),fontSize:Number(e[2]),color:`#${Number(e[3]).toString(16)}`,timestamp:Number(e[4]),pool:Number(e[5]),userID:e[6],rowID:Number(e[7])}}return null}).filter(Boolean)}function m({data:t}){const{xml:e,id:i}=t,n=u(e);globalThis.postMessage({danmus:n,id:i})}let f=0;function g(t,{signal:e,onCancel:i}={}){return new Promise((n,a)=>{let s,r,o,l=!1;const d=++f,p=()=>y(void 0,function(t){if(void 0!==(null==t?void 0:t.reason))return t.reason;const e=new Error("Bilibili Danmu loading cancelled");return e.name="AbortError",e}(e));function g(){let t,e=!1;try{if(s){const t=s;s=void 0,t.onmessage=null,t.onerror=null,t.onmessageerror=null,t.terminate()}}catch(i){t=i,e=!0}if(void 0!==r){const n=r;r=void 0;try{URL.revokeObjectURL(n)}catch(i){e||(t=i),e=!0}}if(e)throw t}function y(t,i){if(l)return;l=!0;let s=arguments.length>1;null==e||e.removeEventListener("abort",p),null==o||o();try{g()}catch(r){s||(i=r),s=!0}s?a(i):n(t)}function v(t,e){if(!l){console.error("Error parsing Bilibili Danmu:",e);try{y(u(t))}catch(i){y(void 0,i)}}}(null==e?void 0:e.aborted)?p():(null==e||e.addEventListener("abort",p),o=null==i?void 0:i(p),l?null==o||o():function(){return c(this,null,function*(){const i=e?yield fetch(t,{signal:e}):yield fetch(t);if(l)return;const n=yield i.text();if(!l)try{const t=`\n ${h.toString()}\n ${u.toString()}\n onmessage = ${m.toString()}\n `;if(r=URL.createObjectURL(new Blob([t],{type:"application/javascript"})),l)return void g();if(s=new Worker(r),l)return void g();s.onmessage=t=>{var e;if(l||(null==(e=t.data)?void 0:e.id)!==d)return;const{danmus:i}=t.data;Array.isArray(i)?y(i):y(void 0,new Error("Invalid Bilibili Danmu worker response"))},s.onerror=t=>{var e;null==(e=t.preventDefault)||e.call(t),v(n,t.error||t)},s.onmessageerror=t=>v(n,t.error||t),s.postMessage({xml:n,id:d})}catch(a){v(n,a)}})}().catch(t=>y(void 0,t)))})}const y=new WeakMap,v=Symbol("cancelled danmuku input");function w(t){return y.has(t)||y.set(t,{closed:!1,tasks:new Set,emitting:[]}),y.get(t)}function k(t){const e=w(t),i=e.emitting[e.emitting.length-1];return!e.closed&&!t.art.isDestroy&&(!i||i.active())}function x(t){const e=w(t);e.closed=!0;for(const i of[...e.tasks])i.cancel()}function b(t,e,i){const n=t.states[e]||[];for(let a=0;a{const a=n.$ref.offsetTop,s=this.owner.getLeft(n.$ref)-i,r=n.$ref.clientHeight,o=n.$ref.clientWidth,l=s+o,d=e-l,c=l/n.$restTime,p={};p.top=a,p.left=s,p.height=r,p.width=o,p.right=d,p.speed=c,p.distance=l,p.time=n.$restTime,p.mode=n.mode,t.push(p)}),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,a){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=`${a}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()}}const M=Symbol("cancelled danmuku frame");class S{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}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(){var t;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)}null==(t=this.owner.workerClient)||t.cancel(),this.failedItems.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(){var t;if(!this.closed&&!this.owner.art.isDestroy&&(this.failedItems.clear(),this.fault))try{null==(t=this.owner.workerClient)||t.dispose(),this.owner.createWorker(),this.fault=!1}catch(e){this.report(e)}}schedule(){const t=this.owner;!this.running||this.closed||this.fault||t.art.isDestroy||t.isStop||null!==this.frame||this.operation||(this.frame=window.requestAnimationFrame(()=>{if(this.frame=null,t.timer=null,this.closed||this.fault||t.isStop||t.art.isDestroy)return;let e;const i=new Promise(t=>e=()=>t(M)),n={generation:this.generation,cancel:e,wait:t=>Promise.race([t,i]),ref:null};return this.operation=n,this.run(n).catch(t=>{this.active(n)&&this.fail(t)}).finally(()=>{this.release(n),this.operation===n&&(this.operation=null,this.schedule())})}),t.timer=this.frame)}run(t){return c(this,null,function*(){const e=this.owner;if(!e.art.playing||!this.active(t))return;e.filter("emit",t=>{const i=(Date.now()-t.$lastStartTime)/1e3;t.$restTime-=i,t.$lastStartTime=Date.now(),t.$restTime<=0&&e.makeWait(t)});const i=e.readys;for(const a of i){if(!this.active(t))return;if(this.failedItems.has(a))continue;let i;try{i=yield t.wait(e.option.beforeVisible(a))}catch(n){if(!this.active(t))return;this.failedItems.add(a),this.report(n);continue}if(!this.active(t))return;if(!i)continue;const{clientWidth:s,clientHeight:r}=e.$player,o=e.renderer.prepare(a,t);if(!this.active(t))return;a.$lastStartTime=Date.now(),a.$restTime=e.speed;const l=s+o.clientWidth,d=yield t.wait(e.postMessage({type:"getDanmuTop",target:{mode:a.mode,height:o.clientHeight,speed:l/a.$restTime},visibles:e.visibles,antiOverlap:e.option.antiOverlap,clientWidth:s,clientHeight:r,marginBottom:e.marginBottom,marginTop:e.marginTop})),c="symbol"===typeof d?void 0:d.result;if(!this.active(t)||a.$ref!==o)return;void 0!==c?(a.$lastStartTime=Date.now(),e.setState(a,"emit"),e.renderer.place(a,o,c,l,s),t.ref=null,e.art.emit("artplayerPluginDanmuku:visible",a)):(e.setState(a,"ready"),this.release(t))}})}destroy(){this.closed=!0,this.invalidate()}}let z=0;class E{constructor(t,e){this.pending=new Map,this.closed=!1,this.failed=!1,this.onFailure=e,this.worker=t();try{this.worker.onmessage=t=>{var e;const i=this.pending.get(null==(e=t.data)?void 0:e.id);i&&(this.pending.delete(t.data.id),i.resolve(t.data))},this.worker.onerror=t=>{var e;null==(e=t.preventDefault)||e.call(t),this.fail(t.error||t)},this.worker.onmessageerror=t=>this.fail(t.error||t)}catch(i){try{this.dispose()}catch(n){}throw i}}request(t){t.id=++z;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(a){this.fail(a)}})}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(e){}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 F='/*!\n * artplayer-plugin-danmuku.js v5.3.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=t.height)return h}const a=[];for(let g=1;g{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(ie.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',C="undefined"!==typeof self&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",F],{type:"text/javascript;charset=utf-8"});function D(t){let e;try{if(e=C&&(self.URL||self.webkitURL).createObjectURL(C),!e)throw"";const i=new Worker(e,{type:"module",name:null==t?void 0: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(F),{type:"module",name:null==t?void 0:t.name})}}class P{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 $(this),this.scheduler=new S(this),this.option=P.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),k(this),t.on("destroy",this.destroy);try{if(this.config(e,!0),!k(this))return;this.createWorker()}catch(a){throw t.off("destroy",this.destroy),x(this),this.scheduler.destroy(),a}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(){var t,e;return null==(e=null==(t=this.art.plugins)?void 0:t.autoOrientation)?void 0:e.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 P.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 P.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 P.option.fontSize}get $ref(){return this.renderer.acquire()}get readys(){return function(t){const{currentTime:e}=t.art,i=[];return b(t,"ready",t=>i.push(t)),b(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}load(t){return c(this,null,function*(){const{errorHandle:e}=this.utils,i=function(t,e){const i=w(t);if(e)for(const d of[...i.tasks])d.replace&&d.cancel();let n,a=i.closed||t.art.isDestroy;const s=new Promise(t=>n=t),r=new Set,o="function"===typeof AbortController?new AbortController:void 0,l={replace:e,signal:null==o?void 0:o.signal,active:()=>!a&&!i.closed&&!t.art.isDestroy,onCancel:t=>l.active()?(r.add(t),()=>r.delete(t)):(t(),()=>{}),cancel(){if(!a){a=!0,n(v),null==o||o.abort();for(const t of[...r])t();r.clear()}},wait:t=>Promise.race([t,s]),emit(e){i.emitting.push(l);try{return t.emit(e)}finally{i.emitting.pop()}},finish(){i.tasks.delete(l),r.clear()}};return a?n(v):i.tasks.add(l),l}(this,void 0===t);try{if(!i.active())return this;const n=function(t,e){return"function"===typeof t?{asynchronous:!0,value:t()}:p(t)?{asynchronous:!0,value:t}:"string"===typeof t?{asynchronous:!0,value:g(t,e)}:{asynchronous:!1,value:Array.isArray(t)?t:[]}}(t||this.option.danmuku,i),a=n.asynchronous?yield i.wait(n.value):n.value;if(!i.active())return this;e(Array.isArray(a),"Danmuku need return an array as result");const s=a;if(void 0===t){if(this.reset(),!i.active())return this;this.queue=[],this.states={wait:[],ready:[],emit:[],stop:[]},this.renderer.clear()}for(let t=0;t{const e=a[t],i=s[t];return"function"===typeof e||"function"===typeof i||p(e)||p(i)?e!==i:JSON.stringify(e)!==JSON.stringify(i)}))&&!e)return this;const r=function(t,e,{defaults:i,validate:n,clamp:a,mount:s}){const r=Object.assign({},i,t,e);return n(r),r.mode=a(r.mode,0,2),r.speed=a(r.speed,1,10),r.opacity=a(r.opacity,0,1),r.lockTime=a(r.lockTime,1,60),r.maxLength=a(r.maxLength,1,1e3),r.mount=r.mount||s,r}(this.option,t,{defaults:P.option,validate:t=>this.validator(t,P.scheme),clamp:i,mount:n});if(!k(this))return this;const o=this.option.beforeVisible!==r.beforeVisible;return this.option=r,o&&(this.scheduler.invalidate(),this.scheduler.schedule()),t.fontSize&&(this.reset(),!k(this))||(this.option.visible?this.show():this.hide(),k(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 E(()=>new D,t=>this.scheduler.fail(t)),this.worker=this.workerClient.worker}filter(t,e){return b(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(){var t;x(this),this.scheduler.destroy();try{try{this.stop()}finally{null==(t=this.workerClient)||t.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 T=4294967295;function A(t,e){let i=0,n=t.length;for(;iNumber.isFinite(t)&&t>0))return null;const o={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},l=Object.assign({},"object"===typeof a?a:{}),d=Object.assign({},o,l);for(const r of Object.keys(o))Number.isFinite(d[r])||(d[r]=o[r]);if(d.sampling<=0&&(d.sampling=o.sampling),d.xMin===d.xMax||d.yMin===d.yMax)return null;const c=Array.isArray(s)&&s.length>0,p=c?[...s]: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>T)return[];const a=t.map(t=>t.time).filter(t=>"number"===typeof t&&!Number.isNaN(t)).sort((t,e)=>t-e),s=[],r=i/e;if(!Number.isFinite(r))return[];for(let o=0;o<=e;o+=n){if(s.length>=T||o+n===o)return[];const t=o*r,e=(o+n)*r;s.push([o,A(a,e)-A(a,t)])}return s}(n,t,i,d.sampling);if(!p.length||!p.every(t=>Array.isArray(t)&&Number.isFinite(t[0])&&Number.isFinite(t[1])))return null;const h=p[p.length-1];if(h[0]!==t){if(p.length===T)return null;p.push([t,h[1]])}let u=1/0,m=-1/0;for(const r of p)u=Math.min(u,r[1]),m=Math.max(m,r[1]);const f=(u+m)/2;for(const r of p){const t=r[1];r[1]=t*(t>f?1+d.scale:1-d.scale)+d.minHeight}const g=!c&&!Number.isFinite(l.yMin)&&!Number.isFinite(l.yMax);let y=0;for(const r of p)y=Math.max(y,r[1]);const v=g&&y>o.yMax/4;v&&(d.yMax=4*y);const w=t=>v?Math.min(e,Math.max(.75*e,t)):t,k=(t,e,i,n)=>{const a=function(t,e){const i=e[0]-t[0],n=e[1]-t[1];return{length:Math.sqrt(r(i,2)+r(n,2)),angle:Math.atan2(n,i)}}(e||t,i||t),s=L(Math.cos(a.angle)*d.flattening,0,1,1,0),o=a.angle*s+(n?Math.PI:0),l=a.length*d.smoothing;return[t[0]+Math.cos(o)*l,w(t[1]+Math.sin(o)*l)]},x=p.map(i=>[L(i[0],d.xMin,d.xMax,0,t),w(L(i[1],d.yMin,d.yMax,e,0))]);if(!x.every(t=>t.every(Number.isFinite)))return null;const b=x.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 a=k(n[i-1],n[i-2],t),s=k(t,n[i-1],n[i+1],!0);return`C ${a[0]},${a[1]} ${s[0]},${s[1]} ${t[0]},${t[1]}${i===n.length-1?" z":""}`}).join(" ");return/NaN|Infinity/u.test(b)?null:{path:b,opacity:d.opacity,width:t,height:e}}let H=0;function N(t,e,i){if(t.isDestroy)return;const{query:n}=t.constructor.utils;let a;const s=[];let r,o,l,d=!1;const c=()=>!d&&!t.isDestroy;function p(e,i){const n=i;s.push([e,n]),t.on(e,n)}function h(e){if(d)return;let i;d=!0,o=null,l=null;let n=!1;const a=t=>{try{t()}catch(e){n||(i=e),n=!0}};for(const[r,o]of s.splice(0))a(()=>t.off(r,o));if(e&&r&&t.controls.heatmap===r&&a(()=>t.controls.remove("heatmap")),r=void 0,n)throw i}function u(t){c()&&o&&l&&(o.setAttribute("offset",100*t+"%"),l.setAttribute("offset",100*t+"%"))}function m(s){try{!function(s=[]){if(!c())return;o=null,l=null;const d=r;if(d.innerHTML="",t.option.isLive)return;const p=O({width:d.offsetWidth,height:d.offsetHeight,duration:t.duration,queue:e.queue,option:i,points:s});if(!p||!c())return;const h=d.ownerDocument;for(a||(a=h?"heatmap-solids":"heatmap-solids-"+ ++H);null==h?void 0:h.getElementById(a);)a="heatmap-solids-"+ ++H;d.innerHTML=`\n \n \n \n \n \n \n \n \n \n \n \n `,o=n("#heatmap-start",d),l=n("#heatmap-stop",d),u(t.played)}(s)}catch(d){try{h(!0)}catch(p){}throw d}}p("destroy",()=>h(!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(){h(!1)},mounted(e){if(r=e,d)return t.controls.heatmap===e&&t.controls.remove("heatmap"),void(r=void 0);c()?(p("video:timeupdate",()=>u(t.played)),p("setBar",(t,e)=>{"played"===t&&u(e)}),p("ready",()=>m()),p("resize",()=>m()),p("artplayerPluginDanmuku:loaded",()=>m()),p("artplayerPluginDanmuku:points",t=>m(t))):h(!0)}})}catch(f){try{h(!0)}catch(g){}throw f}return()=>h(!0)}const V=new WeakMap;class j{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 a=t;if(!this.active)return;const s=()=>"function"===typeof a.getPropertyPriority?a.getPropertyPriority(e):void 0;let r=V.get(a);r||(r=new Map,V.set(a,r));let o=r.get(e);o||(o={original:a[e],present:e in a||void 0!==a[e],priority:s(),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&&a[e]===o.last&&s()===o.lastPriority){const t=[...o.owners.values()];t.length?(o.apply(t[t.length-1]),o.last=a[e],o.lastPriority=s()):void 0!==o.priority?a.setProperty(e,o.original,o.priority):o.present?o.apply(o.original):delete a[e]}o.owners.size||(r.delete(e),r.size||V.delete(a))}),o.owners.delete(this),o.owners.set(this,i),o.apply(i),o.last=a[e],o.lastPriority=s()}on(t,e){if(!this.active)return;const i=this;function n(...t){if(i.active)return e.apply(this,t)}const a=()=>this.art.off(t,n);this.own(a);try{this.art.on(t,n),this.active||a()}catch(s){throw this.release(a),s}}proxy(t,e,i){if(!this.active)return;const n=this;function a(...t){if(n.active)return i.apply(this,t)}let s;const r=()=>{var i,n;if("function"===typeof s){const t=this.art.events;"function"===typeof(null==t?void 0:t.remove)&&(null==(i=t.destroyEvents)?void 0:i.has(s))?t.remove(s):s()}else null==(n=t.removeEventListener)||n.call(t,e,a)};this.own(r);try{s=this.art.proxy(t,e,a),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 q({min:t,max:e,container:i,findIndex:n,onChange:a,steps:s=[]}){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

\n
\n ${s.map(()=>'
').join("")}\n
\n
\n
\n
\n
\n ${s.map(t=>t.hide?"":`
${t.name}
`).join("")}\n
\n `;const c=o(".apd-slider-dot",i),p=o(".apd-slider-progress",i);let h=!1;function u(i){if(!r.active)return;if(void 0===i&&(i=n()),ie)return;const o=(i-t)/(e-t);c.style.left=100*o+"%",0===s.length&&(p.style.width=c.style.left),a(i)}function m(n){const{top:a,height:s,left:r,width:o}=i.getBoundingClientRect();if(this.art.isRotate){const i=l(n.clientY-a,0,s);u(Math.round(i/s*(e-t)+t))}else{const i=l(n.clientX-r,0,o);u(Math.round(i/o*(e-t)+t))}}return r.own(()=>h=!1),r.proxy(i,"click",t=>{m.call(this,t)}),r.proxy(i,"pointerdown",t=>{h=0===t.button}),r.on("document:pointermove",t=>{h&&m.call(this,t)}),r.on("document:pointerup",t=>{h&&(h=!1,m.call(this,t))}),{reset:u}}const I='',R='',B='',Z='',W='',_='',U='',G='',X='',Y='',J='',K='';function Q(){const{option:t}=this;return`\n
\n ${J}${Y}\n
\n
\n ${B}\n
\n
\n
\n \u6309\u7c7b\u578b\u5c4f\u853d\n
\n
\n ${Z}${W}\n
\u6eda\u52a8
\n
\n
\n ${_}${U}\n
\u9876\u90e8
\n
\n
\n ${G}${X}\n
\u5e95\u90e8
\n
\n
\n
\n
\n
\n ${R}${I}\n \u9632\u6b62\u5f39\u5e55\u91cd\u53e0\n
\n
\n ${R}${I}\n \u540c\u6b65\u89c6\u9891\u901f\u5ea6\n
\n
\n
\n \u4e0d\u900f\u660e\u5ea6\n
\n
\u672a\u77e5
\n
\n
\n \u663e\u793a\u533a\u57df\n
\n
\u672a\u77e5
\n
\n
\n \u5f39\u5e55\u5b57\u53f7\n
\n
\u672a\u77e5
\n
\n
\n \u5f39\u5e55\u901f\u5ea6\n
\n
\u672a\u77e5
\n
\n
\n
\n
\n
\n
\n ${K}\n
\n
\n
\n \u6a21\u5f0f\n
\n
\n ${W}\n
\u6eda\u52a8
\n
\n
\n ${U}\n
\u9876\u90e8
\n
\n
\n ${X}\n
\u5e95\u90e8
\n
\n
\n
\n
\n \u989c\u8272\n
\n ${this.COLOR.map(t=>`
`).join("")}\n
\n
\n
\n
\n
\n \n
\u53d1\u9001
\n
\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 a=()=>{document.removeEventListener("DOMContentLoaded",a),i[e]===n&&delete i[e];const s=document.getElementById(t);s?s.textContent=n.textContent:(document.head||document.documentElement).appendChild(n)};document.addEventListener("DOMContentLoaded",a,{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 tt{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 j(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(a){try{this.destroy()}catch(s){console.warn("Failed to roll back danmuku setting:",s)}throw a}}static get icons(){return{$on:J,$off:Y,$config:B,$style:K,$mode_0_off:Z,$mode_0_on:W,$mode_1_off:_,$mode_1_on:U,$mode_2_off:G,$mode_2_on:X,$check_on:R,$check_off:I}}get option(){return this.danmuku.option}get outside(){return this.template.$mount!==this.template.$controlsCenter}get TEMPLATE(){return Q.call(this)}get OPACITY(){return l({min:0,max:100,steps:[]},this.option.OPACITY)}get FONT_SIZE(){return l({min:12,max:120,steps:[]},this.option.FONT_SIZE)}get MARGIN(){return l({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 l({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:a,$syncVideo:s,$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(a,"click",()=>{this.danmuku.config({antiOverlap:!this.option.antiOverlap}),this.reset()}),this.lifecycle.proxy(s,"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(d(l({},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(d(l({},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(d(l({},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(d(l({},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 q.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(),a=e.getBoundingClientRect(),s=i.getBoundingClientRect(),r=a.width/2-n.width/2,o=s.left-(n.left-r),l=n.right+r-s.right;e.style.left=o>0?`${-r+o}px`:l>0?-r-l+"px":-r+"px"}emit(){return function(t){return c(this,null,function*(){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 a={text:n,mode:t.option.mode,color:t.option.color,time:t.art.currentTime},s=t=>{e.active&&console.error("Error emitting danmuku:",t)};try{t.emitting=!0;const n=yield e.wait(t.option.beforeEmit(a));if(!e.active)return;if(t.emitting=!1,!0!==n)return;if(a.border=!0,delete a.time,Promise.resolve(t.danmuku.emit(a)).catch(s),!e.active)return;i.value="",t.lock()}catch(r){s(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 a=()=>{t.timer=setTimeout(()=>{t.lifecycle.active&&(0===n?t.unlock():(n-=1,i.textContent=n,a()))},1e3)};a()}(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.widtht.dataset.color===this.option.color.toUpperCase());s&&t(s,"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;(null==t?void 0:t.parentElement)&&t.parentElement.removeChild(t)}}function et(t){return e=>{const i=new P(e,t);let n;try{n=e.isDestroy?void 0:new tt(e,i),!e.isDestroy&&i.option.heatmap&&N(e,i,i.option.heatmap)}catch(a){try{null==n||n.destroy()}catch(s){}try{i.destroy()}catch(s){}throw a}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 et.icons=tt.icons,et}); diff --git a/packages/artplayer-plugin-danmuku/dist/artplayer-plugin-danmuku.mjs b/packages/artplayer-plugin-danmuku/dist/artplayer-plugin-danmuku.mjs index 560c1e7e2..fc13b77ba 100644 --- a/packages/artplayer-plugin-danmuku/dist/artplayer-plugin-danmuku.mjs +++ b/packages/artplayer-plugin-danmuku/dist/artplayer-plugin-danmuku.mjs @@ -680,6 +680,7 @@ class Scheduler { if (!this.active(operation) || danmu.$ref !== ref) return; if (top !== void 0) { + danmu.$lastStartTime = Date.now(); owner.setState(danmu, "emit"); owner.renderer.place(danmu, ref, top, distance, clientWidth); operation.ref = null; diff --git a/packages/artplayer-plugin-danmuku/src/scheduler.ts b/packages/artplayer-plugin-danmuku/src/scheduler.ts index 231c61cae..59babd084 100644 --- a/packages/artplayer-plugin-danmuku/src/scheduler.ts +++ b/packages/artplayer-plugin-danmuku/src/scheduler.ts @@ -175,6 +175,8 @@ export default class Scheduler { if (!this.active(operation) || danmu.$ref !== ref) return if (top !== undefined) { + // The hidden Worker wait must not consume the CSS-visible lifetime. + danmu.$lastStartTime = Date.now() owner.setState(danmu, 'emit') owner.renderer.place(danmu, ref, top, distance, clientWidth) operation.ref = null diff --git a/refactor/baselines/danmuku-lifetime-validation.json b/refactor/baselines/danmuku-lifetime-validation.json new file mode 100644 index 000000000..c2bca96b7 --- /dev/null +++ b/refactor/baselines/danmuku-lifetime-validation.json @@ -0,0 +1,3059 @@ +{ + "schemaVersion": 1, + "task": "PKG-DANMUKU-11", + "status": "done", + "capturedAt": "2026-09-13T14:22:20.805Z", + "baselineCommit": "24b883d862e11b96fc2d5888857bacc62a24a94c", + "change": "Reset only the successful visible placement origin after cancellation and node-identity checks; hidden Worker wait no longer consumes configured display lifetime.", + "units": [ + { + "file": "refactor/.cache/danmuku11-source-unit.log", + "sha256": "63e990eb31fcfadf4cdda75522d85344c729d18bd94cc811c56a45174ddfdcee", + "tests": 253 + }, + { + "file": "refactor/.cache/danmuku11-main-unit.log", + "sha256": "5910dceb73c5c400004f35119e96a247fa9571e5024169ffa121f78806f4ef0a", + "tests": 57 + }, + { + "file": "refactor/.cache/danmuku11-legacy-unit.log", + "sha256": "e845dbe004b71ffb61cc88f7babb610b6483be6800549c5b743a6bb21f5c57a0", + "tests": 57 + } + ], + "browsers": [ + { + "format": "source", + "file": "refactor/.cache/danmuku11-source-browser.json", + "sha256": "2f30e9133aa4d7a55918281daf7c323f7d5016d6a0993587dbce19b5a5d69188", + "stats": { + "startTime": "2026-09-13T14:18:26.191Z", + "duration": 139762.33, + "expected": 90, + "skipped": 0, + "unexpected": 0, + "flaky": 0 + }, + "versions": { + "chromium": { + "version": "153.0.8010.12", + "platform": "win32" + }, + "firefox": { + "version": "155.0", + "platform": "win32" + }, + "webkit": { + "version": "26.6", + "platform": "win32" + } + }, + "cases": [ + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / published plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "chromium", + "status": "passed", + "durationMs": 2750, + "lifetime": { + "core": "published", + "implementation": "published", + "mode": 0, + "sha256": "7c8749288711ef97e80b6f9f00981170aa73f62a8ae25d6d663749a4aef62a8f", + "evidence": { + "posts": [ + { + "id": 1789309110414, + "wall": 914.3999999761581 + } + ], + "replies": [ + { + "id": 1789309110414, + "wall": 2415.899999976158 + } + ], + "visible": [ + { + "wall": 2416.199999988079, + "clock": 1789309111916, + "startedAt": 1789309110414, + "rest": 1, + "mode": 0, + "time": 2.205412, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 2429, + "rest": -0.5149999999999999, + "time": 2.217988 + } + ], + "video": { + "width": 640, + "time": 2.344235 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / published plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "chromium", + "status": "passed", + "durationMs": 2603, + "lifetime": { + "core": "published", + "implementation": "published", + "mode": 1, + "sha256": "7c8749288711ef97e80b6f9f00981170aa73f62a8ae25d6d663749a4aef62a8f", + "evidence": { + "posts": [ + { + "id": 1789309113047, + "wall": 837.5 + } + ], + "replies": [ + { + "id": 1789309113047, + "wall": 2339 + } + ], + "visible": [ + { + "wall": 2339.399999976158, + "clock": 1789309114549, + "startedAt": 1789309113047, + "rest": 1, + "mode": 1, + "time": 2.189061, + "transition": "" + } + ], + "recycled": [ + { + "wall": 2351.699999988079, + "rest": -0.5149999999999999, + "time": 2.201526 + } + ], + "video": { + "width": 640, + "time": 2.338725 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / candidate plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "chromium", + "status": "passed", + "durationMs": 3607, + "lifetime": { + "core": "published", + "implementation": "candidate", + "mode": 0, + "sha256": "2d22d12a9da52e1b1164398556e43c9101ef392350311c2499c0ac72c8e7d789", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 835.1000000238419 + } + ], + "replies": [ + { + "id": 1, + "wall": 2337.100000023842 + } + ], + "visible": [ + { + "wall": 2337.300000011921, + "clock": 1789309117166, + "startedAt": 1789309117166, + "rest": 1, + "mode": 0, + "time": 2.174232, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 3349.100000023842, + "rest": -0.012000000000000774, + "time": 3.185465 + } + ], + "video": { + "width": 640, + "time": 3.322828 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / candidate plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "chromium", + "status": "passed", + "durationMs": 3629, + "lifetime": { + "core": "published", + "implementation": "candidate", + "mode": 1, + "sha256": "2d22d12a9da52e1b1164398556e43c9101ef392350311c2499c0ac72c8e7d789", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 851.3000000119209 + } + ], + "replies": [ + { + "id": 1, + "wall": 2352.5 + } + ], + "visible": [ + { + "wall": 2352.599999964237, + "clock": 1789309120798, + "startedAt": 1789309120798, + "rest": 1, + "mode": 1, + "time": 2.186323, + "transition": "" + } + ], + "recycled": [ + { + "wall": 3365.599999964237, + "rest": -0.013000000000000775, + "time": 3.200521 + } + ], + "video": { + "width": 640, + "time": 3.33795 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / published plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "chromium", + "status": "passed", + "durationMs": 2757, + "lifetime": { + "core": "candidate", + "implementation": "published", + "mode": 0, + "sha256": "7c8749288711ef97e80b6f9f00981170aa73f62a8ae25d6d663749a4aef62a8f", + "evidence": { + "posts": [ + { + "id": 1789309110414, + "wall": 915.1000000238419 + } + ], + "replies": [ + { + "id": 1789309110414, + "wall": 2416.699999988079 + } + ], + "visible": [ + { + "wall": 2416.899999976158, + "clock": 1789309111916, + "startedAt": 1789309110414, + "rest": 1, + "mode": 0, + "time": 2.2053, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 2429.600000023842, + "rest": -0.5149999999999999, + "time": 2.217939 + } + ], + "video": { + "width": 640, + "time": 2.345893 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / published plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "chromium", + "status": "passed", + "durationMs": 2618, + "lifetime": { + "core": "candidate", + "implementation": "published", + "mode": 1, + "sha256": "7c8749288711ef97e80b6f9f00981170aa73f62a8ae25d6d663749a4aef62a8f", + "evidence": { + "posts": [ + { + "id": 1789309113080, + "wall": 868.3999999761581 + } + ], + "replies": [ + { + "id": 1789309113080, + "wall": 2369.599999964237 + } + ], + "visible": [ + { + "wall": 2369.800000011921, + "clock": 1789309114582, + "startedAt": 1789309113080, + "rest": 1, + "mode": 1, + "time": 2.189116, + "transition": "" + } + ], + "recycled": [ + { + "wall": 2382.899999976158, + "rest": -0.5149999999999999, + "time": 2.202559 + } + ], + "video": { + "width": 640, + "time": 2.322561 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / candidate plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "chromium", + "status": "passed", + "durationMs": 3657, + "lifetime": { + "core": "candidate", + "implementation": "candidate", + "mode": 0, + "sha256": "2d22d12a9da52e1b1164398556e43c9101ef392350311c2499c0ac72c8e7d789", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 880.1999999880791 + } + ], + "replies": [ + { + "id": 1, + "wall": 2381.599999964237 + } + ], + "visible": [ + { + "wall": 2381.699999988079, + "clock": 1789309117234, + "startedAt": 1789309117233, + "rest": 1, + "mode": 0, + "time": 2.191529, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 3393.099999964237, + "rest": -0.011000000000000742, + "time": 3.203557 + } + ], + "video": { + "width": 640, + "time": 3.342734 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / candidate plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "chromium", + "status": "passed", + "durationMs": 3658, + "lifetime": { + "core": "candidate", + "implementation": "candidate", + "mode": 1, + "sha256": "2d22d12a9da52e1b1164398556e43c9101ef392350311c2499c0ac72c8e7d789", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 877.1999999880791 + } + ], + "replies": [ + { + "id": 1, + "wall": 2378.300000011921 + } + ], + "visible": [ + { + "wall": 2378.599999964237, + "clock": 1789309120898, + "startedAt": 1789309120898, + "rest": 1, + "mode": 1, + "time": 2.188009, + "transition": "" + } + ], + "recycled": [ + { + "wall": 3391.599999964237, + "rest": -0.013000000000000775, + "time": 3.201505 + } + ], + "video": { + "width": 640, + "time": 3.3408 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / published plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "firefox", + "status": "passed", + "durationMs": 3913, + "lifetime": { + "core": "published", + "implementation": "published", + "mode": 0, + "sha256": "7c8749288711ef97e80b6f9f00981170aa73f62a8ae25d6d663749a4aef62a8f", + "evidence": { + "posts": [ + { + "id": 1789309148698, + "wall": 1256 + } + ], + "replies": [ + { + "id": 1789309148698, + "wall": 2758 + } + ], + "visible": [ + { + "wall": 2759, + "clock": 1789309150201, + "startedAt": 1789309148697, + "rest": 1, + "mode": 0, + "time": 2.19407, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 2772, + "rest": -0.518, + "time": 2.19407 + } + ], + "video": { + "width": 640, + "time": 2.395995 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / published plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "firefox", + "status": "passed", + "durationMs": 2830, + "lifetime": { + "core": "published", + "implementation": "published", + "mode": 1, + "sha256": "7c8749288711ef97e80b6f9f00981170aa73f62a8ae25d6d663749a4aef62a8f", + "evidence": { + "posts": [ + { + "id": 1789309151617, + "wall": 941 + } + ], + "replies": [ + { + "id": 1789309151617, + "wall": 2444 + } + ], + "visible": [ + { + "wall": 2444, + "clock": 1789309153121, + "startedAt": 1789309151617, + "rest": 1, + "mode": 1, + "time": 2.203515, + "transition": "" + } + ], + "recycled": [ + { + "wall": 2457, + "rest": -0.516, + "time": 2.203515 + } + ], + "video": { + "width": 640, + "time": 2.324736 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / candidate plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "firefox", + "status": "passed", + "durationMs": 3670, + "lifetime": { + "core": "published", + "implementation": "candidate", + "mode": 0, + "sha256": "2d22d12a9da52e1b1164398556e43c9101ef392350311c2499c0ac72c8e7d789", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 714 + } + ], + "replies": [ + { + "id": 1, + "wall": 2215 + } + ], + "visible": [ + { + "wall": 2216, + "clock": 1789309155722, + "startedAt": 1789309155722, + "rest": 1, + "mode": 0, + "time": 1.960448, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 3231, + "rest": -0.015000000000000721, + "time": 2.976753 + } + ], + "video": { + "width": 640, + "time": 3.182941 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / candidate plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "firefox", + "status": "passed", + "durationMs": 3583, + "lifetime": { + "core": "published", + "implementation": "candidate", + "mode": 1, + "sha256": "2d22d12a9da52e1b1164398556e43c9101ef392350311c2499c0ac72c8e7d789", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 660 + } + ], + "replies": [ + { + "id": 1, + "wall": 2163 + } + ], + "visible": [ + { + "wall": 2163, + "clock": 1789309159343, + "startedAt": 1789309159343, + "rest": 1, + "mode": 1, + "time": 1.960894, + "transition": "" + } + ], + "recycled": [ + { + "wall": 3177, + "rest": -0.014000000000000772, + "time": 2.984423 + } + ], + "video": { + "width": 640, + "time": 3.145992 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / published plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "firefox", + "status": "passed", + "durationMs": 3645, + "lifetime": { + "core": "candidate", + "implementation": "published", + "mode": 0, + "sha256": "7c8749288711ef97e80b6f9f00981170aa73f62a8ae25d6d663749a4aef62a8f", + "evidence": { + "posts": [ + { + "id": 1789309148933, + "wall": 1124 + } + ], + "replies": [ + { + "id": 1789309148933, + "wall": 2629 + } + ], + "visible": [ + { + "wall": 2629, + "clock": 1789309150437, + "startedAt": 1789309148932, + "rest": 1, + "mode": 0, + "time": 1.964281, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 2640, + "rest": -0.516, + "time": 1.964281 + } + ], + "video": { + "width": 640, + "time": 2.168054 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / published plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "firefox", + "status": "passed", + "durationMs": 2851, + "lifetime": { + "core": "candidate", + "implementation": "published", + "mode": 1, + "sha256": "7c8749288711ef97e80b6f9f00981170aa73f62a8ae25d6d663749a4aef62a8f", + "evidence": { + "posts": [ + { + "id": 1789309151851, + "wall": 938 + } + ], + "replies": [ + { + "id": 1789309151851, + "wall": 2457 + } + ], + "visible": [ + { + "wall": 2458, + "clock": 1789309153371, + "startedAt": 1789309151850, + "rest": 1, + "mode": 1, + "time": 2.243228, + "transition": "" + } + ], + "recycled": [ + { + "wall": 2471, + "rest": -0.534, + "time": 2.243228 + } + ], + "video": { + "width": 640, + "time": 2.364522 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / candidate plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "firefox", + "status": "passed", + "durationMs": 3938, + "lifetime": { + "core": "candidate", + "implementation": "candidate", + "mode": 0, + "sha256": "2d22d12a9da52e1b1164398556e43c9101ef392350311c2499c0ac72c8e7d789", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 951 + } + ], + "replies": [ + { + "id": 1, + "wall": 2479 + } + ], + "visible": [ + { + "wall": 2479, + "clock": 1789309156333, + "startedAt": 1789309156332, + "rest": 1, + "mode": 0, + "time": 2.213262, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 3483, + "rest": -0.005000000000000782, + "time": 3.227008 + } + ], + "video": { + "width": 640, + "time": 3.351024 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / candidate plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "firefox", + "status": "passed", + "durationMs": 3833, + "lifetime": { + "core": "candidate", + "implementation": "candidate", + "mode": 1, + "sha256": "2d22d12a9da52e1b1164398556e43c9101ef392350311c2499c0ac72c8e7d789", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 904 + } + ], + "replies": [ + { + "id": 1, + "wall": 2422 + } + ], + "visible": [ + { + "wall": 2423, + "clock": 1789309160124, + "startedAt": 1789309160124, + "rest": 1, + "mode": 1, + "time": 2.202015, + "transition": "" + } + ], + "recycled": [ + { + "wall": 3421, + "rest": -7.181755190543981e-16, + "time": 3.172538 + } + ], + "video": { + "width": 640, + "time": 3.338076 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / published plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "webkit", + "status": "passed", + "durationMs": 3798, + "lifetime": { + "core": "published", + "implementation": "published", + "mode": 0, + "sha256": "7c8749288711ef97e80b6f9f00981170aa73f62a8ae25d6d663749a4aef62a8f", + "evidence": { + "posts": [ + { + "id": 1789309188709, + "wall": 1354 + } + ], + "replies": [ + { + "id": 1789309188709, + "wall": 2871 + } + ], + "visible": [ + { + "wall": 2871, + "clock": 1789309190227, + "startedAt": 1789309188708, + "rest": 1, + "mode": 0, + "time": 2.0022711, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 2886, + "rest": -0.534, + "time": 2.0174169 + } + ], + "video": { + "width": 640, + "time": 2.4219795 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / published plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "webkit", + "status": "passed", + "durationMs": 3517, + "lifetime": { + "core": "published", + "implementation": "published", + "mode": 1, + "sha256": "7c8749288711ef97e80b6f9f00981170aa73f62a8ae25d6d663749a4aef62a8f", + "evidence": { + "posts": [ + { + "id": 1789309192383, + "wall": 1272 + } + ], + "replies": [ + { + "id": 1789309192383, + "wall": 2798 + } + ], + "visible": [ + { + "wall": 2799, + "clock": 1789309193909, + "startedAt": 1789309192382, + "rest": 1, + "mode": 1, + "time": 2.0168128, + "transition": "" + } + ], + "recycled": [ + { + "wall": 2800, + "rest": -0.528, + "time": 2.0175419 + } + ], + "video": { + "width": 640, + "time": 2.3542086 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / candidate plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "webkit", + "status": "passed", + "durationMs": 4634, + "lifetime": { + "core": "published", + "implementation": "candidate", + "mode": 0, + "sha256": "2d22d12a9da52e1b1164398556e43c9101ef392350311c2499c0ac72c8e7d789", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 1172 + } + ], + "replies": [ + { + "id": 1, + "wall": 2688 + } + ], + "visible": [ + { + "wall": 2689, + "clock": 1789309197326, + "startedAt": 1789309197326, + "rest": 1, + "mode": 0, + "time": 2.0251252, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 3733, + "rest": -0.04400000000000037, + "time": 3.0695212 + } + ], + "video": { + "width": 640, + "time": 3.5142505 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / candidate plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "webkit", + "status": "passed", + "durationMs": 4720, + "lifetime": { + "core": "published", + "implementation": "candidate", + "mode": 1, + "sha256": "2d22d12a9da52e1b1164398556e43c9101ef392350311c2499c0ac72c8e7d789", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 1231 + } + ], + "replies": [ + { + "id": 1, + "wall": 2753 + } + ], + "visible": [ + { + "wall": 2753, + "clock": 1789309202034, + "startedAt": 1789309202033, + "rest": 1, + "mode": 1, + "time": 1.9947086, + "transition": "" + } + ], + "recycled": [ + { + "wall": 3769, + "rest": -0.016000000000000236, + "time": 3.0101463 + } + ], + "video": { + "width": 640, + "time": 3.5138755 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / published plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "webkit", + "status": "passed", + "durationMs": 3791, + "lifetime": { + "core": "candidate", + "implementation": "published", + "mode": 0, + "sha256": "7c8749288711ef97e80b6f9f00981170aa73f62a8ae25d6d663749a4aef62a8f", + "evidence": { + "posts": [ + { + "id": 1789309189515, + "wall": 1208 + } + ], + "replies": [ + { + "id": 1789309189515, + "wall": 2734 + } + ], + "visible": [ + { + "wall": 2734, + "clock": 1789309191041, + "startedAt": 1789309189515, + "rest": 1, + "mode": 0, + "time": 1.9772502, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 2735, + "rest": -0.5269999999999999, + "time": 1.9780002 + } + ], + "video": { + "width": 640, + "time": 2.396042 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / published plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "webkit", + "status": "passed", + "durationMs": 3612, + "lifetime": { + "core": "candidate", + "implementation": "published", + "mode": 1, + "sha256": "7c8749288711ef97e80b6f9f00981170aa73f62a8ae25d6d663749a4aef62a8f", + "evidence": { + "posts": [ + { + "id": 1789309193163, + "wall": 1212 + } + ], + "replies": [ + { + "id": 1789309193163, + "wall": 2734 + } + ], + "visible": [ + { + "wall": 2735, + "clock": 1789309194686, + "startedAt": 1789309193163, + "rest": 1, + "mode": 1, + "time": 1.9728753, + "transition": "" + } + ], + "recycled": [ + { + "wall": 2735, + "rest": -0.524, + "time": 1.9734377 + } + ], + "video": { + "width": 640, + "time": 2.3742087 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / candidate plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "webkit", + "status": "passed", + "durationMs": 4661, + "lifetime": { + "core": "candidate", + "implementation": "candidate", + "mode": 0, + "sha256": "2d22d12a9da52e1b1164398556e43c9101ef392350311c2499c0ac72c8e7d789", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 1275 + } + ], + "replies": [ + { + "id": 1, + "wall": 2793 + } + ], + "visible": [ + { + "wall": 2794, + "clock": 1789309198354, + "startedAt": 1789309198354, + "rest": 1, + "mode": 0, + "time": 2.0235419, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 3807, + "rest": -0.013000000000000234, + "time": 3.0366046 + } + ], + "video": { + "width": 640, + "time": 3.481563 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / candidate plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "webkit", + "status": "passed", + "durationMs": 4711, + "lifetime": { + "core": "candidate", + "implementation": "candidate", + "mode": 1, + "sha256": "2d22d12a9da52e1b1164398556e43c9101ef392350311c2499c0ac72c8e7d789", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 1227 + } + ], + "replies": [ + { + "id": 1, + "wall": 2757 + } + ], + "visible": [ + { + "wall": 2758, + "clock": 1789309202989, + "startedAt": 1789309202989, + "rest": 1, + "mode": 1, + "time": 1.9792502, + "transition": "" + } + ], + "recycled": [ + { + "wall": 3793, + "rest": -0.036000000000000074, + "time": 3.0149171 + } + ], + "video": { + "width": 640, + "time": 3.4940421 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: accepted NaN timestamp keeps the historical current-time fallback", + "engine": "chromium", + "status": "passed", + "durationMs": 2265 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: failed recovery respects synchronous destroy from the error listener", + "engine": "chromium", + "status": "passed", + "durationMs": 458 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: failed recovery respects synchronous stop from the error listener", + "engine": "chromium", + "status": "passed", + "durationMs": 493 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: native pause cancels pending visibility without blocking later work", + "engine": "chromium", + "status": "passed", + "durationMs": 2671 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: native reset cancels pending visibility without blocking later work", + "engine": "chromium", + "status": "passed", + "durationMs": 2425 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: native seek cancels pending visibility without blocking later work", + "engine": "chromium", + "status": "passed", + "durationMs": 2415 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: native destroy cancels pending visibility without blocking later work", + "engine": "chromium", + "status": "passed", + "durationMs": 2251 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: native Worker renders three modes with synchronous filter and asynchronous beforeVisible", + "engine": "chromium", + "status": "passed", + "durationMs": 1293 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: six simultaneous fixed comments preserve usable track geometry and input order", + "engine": "chromium", + "status": "passed", + "durationMs": 1393 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: native pause seek rate and public reset/load retain historical pool semantics", + "engine": "chromium", + "status": "passed", + "durationMs": 2312 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: actual settings, asynchronous send lock, external fullscreen mount and two-player destruction", + "engine": "chromium", + "status": "passed", + "durationMs": 4039 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: accepted NaN timestamp keeps the historical current-time fallback", + "engine": "chromium", + "status": "passed", + "durationMs": 2281 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: failed recovery respects synchronous destroy from the error listener", + "engine": "chromium", + "status": "passed", + "durationMs": 458 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: failed recovery respects synchronous stop from the error listener", + "engine": "chromium", + "status": "passed", + "durationMs": 491 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: native pause cancels pending visibility without blocking later work", + "engine": "chromium", + "status": "passed", + "durationMs": 2659 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: native reset cancels pending visibility without blocking later work", + "engine": "chromium", + "status": "passed", + "durationMs": 2440 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: native seek cancels pending visibility without blocking later work", + "engine": "chromium", + "status": "passed", + "durationMs": 2439 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: native destroy cancels pending visibility without blocking later work", + "engine": "chromium", + "status": "passed", + "durationMs": 2291 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: native Worker renders three modes with synchronous filter and asynchronous beforeVisible", + "engine": "chromium", + "status": "passed", + "durationMs": 1310 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: six simultaneous fixed comments preserve usable track geometry and input order", + "engine": "chromium", + "status": "passed", + "durationMs": 1424 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: native pause seek rate and public reset/load retain historical pool semantics", + "engine": "chromium", + "status": "passed", + "durationMs": 2353 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: actual settings, asynchronous send lock, external fullscreen mount and two-player destruction", + "engine": "chromium", + "status": "passed", + "durationMs": 3979 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: accepted NaN timestamp keeps the historical current-time fallback", + "engine": "firefox", + "status": "passed", + "durationMs": 2515 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: failed recovery respects synchronous destroy from the error listener", + "engine": "firefox", + "status": "passed", + "durationMs": 593 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: failed recovery respects synchronous stop from the error listener", + "engine": "firefox", + "status": "passed", + "durationMs": 662 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: native pause cancels pending visibility without blocking later work", + "engine": "firefox", + "status": "passed", + "durationMs": 2781 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: native reset cancels pending visibility without blocking later work", + "engine": "firefox", + "status": "passed", + "durationMs": 2612 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: native seek cancels pending visibility without blocking later work", + "engine": "firefox", + "status": "passed", + "durationMs": 3079 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: native destroy cancels pending visibility without blocking later work", + "engine": "firefox", + "status": "passed", + "durationMs": 2561 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: native Worker renders three modes with synchronous filter and asynchronous beforeVisible", + "engine": "firefox", + "status": "passed", + "durationMs": 1576 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: six simultaneous fixed comments preserve usable track geometry and input order", + "engine": "firefox", + "status": "passed", + "durationMs": 1454 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: native pause seek rate and public reset/load retain historical pool semantics", + "engine": "firefox", + "status": "passed", + "durationMs": 2437 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: actual settings, asynchronous send lock, external fullscreen mount and two-player destruction", + "engine": "firefox", + "status": "passed", + "durationMs": 4452 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: accepted NaN timestamp keeps the historical current-time fallback", + "engine": "firefox", + "status": "passed", + "durationMs": 2405 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: failed recovery respects synchronous destroy from the error listener", + "engine": "firefox", + "status": "passed", + "durationMs": 677 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: failed recovery respects synchronous stop from the error listener", + "engine": "firefox", + "status": "passed", + "durationMs": 678 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: native pause cancels pending visibility without blocking later work", + "engine": "firefox", + "status": "passed", + "durationMs": 2766 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: native reset cancels pending visibility without blocking later work", + "engine": "firefox", + "status": "passed", + "durationMs": 2757 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: native seek cancels pending visibility without blocking later work", + "engine": "firefox", + "status": "passed", + "durationMs": 3059 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: native destroy cancels pending visibility without blocking later work", + "engine": "firefox", + "status": "passed", + "durationMs": 2455 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: native Worker renders three modes with synchronous filter and asynchronous beforeVisible", + "engine": "firefox", + "status": "passed", + "durationMs": 1457 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: six simultaneous fixed comments preserve usable track geometry and input order", + "engine": "firefox", + "status": "passed", + "durationMs": 1479 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: native pause seek rate and public reset/load retain historical pool semantics", + "engine": "firefox", + "status": "passed", + "durationMs": 2497 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: actual settings, asynchronous send lock, external fullscreen mount and two-player destruction", + "engine": "firefox", + "status": "passed", + "durationMs": 4463 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: accepted NaN timestamp keeps the historical current-time fallback", + "engine": "webkit", + "status": "passed", + "durationMs": 3616 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: failed recovery respects synchronous destroy from the error listener", + "engine": "webkit", + "status": "passed", + "durationMs": 1927 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: failed recovery respects synchronous stop from the error listener", + "engine": "webkit", + "status": "passed", + "durationMs": 1986 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: native pause cancels pending visibility without blocking later work", + "engine": "webkit", + "status": "passed", + "durationMs": 4521 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: native reset cancels pending visibility without blocking later work", + "engine": "webkit", + "status": "passed", + "durationMs": 4143 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: native seek cancels pending visibility without blocking later work", + "engine": "webkit", + "status": "passed", + "durationMs": 4177 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: native destroy cancels pending visibility without blocking later work", + "engine": "webkit", + "status": "passed", + "durationMs": 3600 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: native Worker renders three modes with synchronous filter and asynchronous beforeVisible", + "engine": "webkit", + "status": "passed", + "durationMs": 2672 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: six simultaneous fixed comments preserve usable track geometry and input order", + "engine": "webkit", + "status": "passed", + "durationMs": 2869 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: native pause seek rate and public reset/load retain historical pool semantics", + "engine": "webkit", + "status": "passed", + "durationMs": 4068 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "published / Candidate Danmuku candidate: actual settings, asynchronous send lock, external fullscreen mount and two-player destruction", + "engine": "webkit", + "status": "passed", + "durationMs": 6333 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: accepted NaN timestamp keeps the historical current-time fallback", + "engine": "webkit", + "status": "passed", + "durationMs": 3580 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: failed recovery respects synchronous destroy from the error listener", + "engine": "webkit", + "status": "passed", + "durationMs": 1669 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: failed recovery respects synchronous stop from the error listener", + "engine": "webkit", + "status": "passed", + "durationMs": 2027 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: native pause cancels pending visibility without blocking later work", + "engine": "webkit", + "status": "passed", + "durationMs": 4667 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: native reset cancels pending visibility without blocking later work", + "engine": "webkit", + "status": "passed", + "durationMs": 4002 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: native seek cancels pending visibility without blocking later work", + "engine": "webkit", + "status": "passed", + "durationMs": 4112 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: native destroy cancels pending visibility without blocking later work", + "engine": "webkit", + "status": "passed", + "durationMs": 3643 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: native Worker renders three modes with synchronous filter and asynchronous beforeVisible", + "engine": "webkit", + "status": "passed", + "durationMs": 2791 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: six simultaneous fixed comments preserve usable track geometry and input order", + "engine": "webkit", + "status": "passed", + "durationMs": 2994 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: native pause seek rate and public reset/load retain historical pool semantics", + "engine": "webkit", + "status": "passed", + "durationMs": 3946 + }, + { + "file": "danmuku-scheduler.spec.js", + "title": "candidate / Candidate Danmuku candidate: actual settings, asynchronous send lock, external fullscreen mount and two-player destruction", + "engine": "webkit", + "status": "passed", + "durationMs": 6776 + } + ] + }, + { + "format": "main", + "file": "refactor/.cache/danmuku11-main-browser.json", + "sha256": "aacb70a0e8c2f9e4220cb849be369a2a01d9c37d89f9c4654764341c8cc10f15", + "stats": { + "startTime": "2026-09-13T14:20:46.619Z", + "duration": 31967.545, + "expected": 12, + "skipped": 0, + "unexpected": 0, + "flaky": 0 + }, + "versions": { + "chromium": { + "version": "153.0.8010.12", + "platform": "win32" + }, + "firefox": { + "version": "155.0", + "platform": "win32" + }, + "webkit": { + "version": "26.6", + "platform": "win32" + } + }, + "cases": [ + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / candidate plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "chromium", + "status": "passed", + "durationMs": 3753, + "lifetime": { + "core": "published", + "implementation": "candidate", + "mode": 0, + "sha256": "43a5d785210c378a7d06e53bdbd6db0d276e5eac4e4feeabaed4f02ac02f3df0", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 935.4000000357628 + } + ], + "replies": [ + { + "id": 1, + "wall": 2436.600000023842 + } + ], + "visible": [ + { + "wall": 2436.699999988079, + "clock": 1789309252010, + "startedAt": 1789309252010, + "rest": 1, + "mode": 0, + "time": 2.204667, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 3448.699999988079, + "rest": -0.012000000000000774, + "time": 3.216882 + } + ], + "video": { + "width": 640, + "time": 3.354773 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / candidate plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "chromium", + "status": "passed", + "durationMs": 3627, + "lifetime": { + "core": "published", + "implementation": "candidate", + "mode": 1, + "sha256": "43a5d785210c378a7d06e53bdbd6db0d276e5eac4e4feeabaed4f02ac02f3df0", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 862.3000000119209 + } + ], + "replies": [ + { + "id": 1, + "wall": 2362.899999976158 + } + ], + "visible": [ + { + "wall": 2363.099999964237, + "clock": 1789309255676, + "startedAt": 1789309255676, + "rest": 1, + "mode": 1, + "time": 2.188799, + "transition": "" + } + ], + "recycled": [ + { + "wall": 3375.899999976158, + "rest": -0.013000000000000771, + "time": 3.201587 + } + ], + "video": { + "width": 640, + "time": 3.324092 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / candidate plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "chromium", + "status": "passed", + "durationMs": 3791, + "lifetime": { + "core": "candidate", + "implementation": "candidate", + "mode": 0, + "sha256": "43a5d785210c378a7d06e53bdbd6db0d276e5eac4e4feeabaed4f02ac02f3df0", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 940.4000000357628 + } + ], + "replies": [ + { + "id": 1, + "wall": 2441.5 + } + ], + "visible": [ + { + "wall": 2441.699999988079, + "clock": 1789309252010, + "startedAt": 1789309252010, + "rest": 1, + "mode": 0, + "time": 2.205718, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 3453.699999988079, + "rest": -0.012000000000000746, + "time": 3.216897 + } + ], + "video": { + "width": 640, + "time": 3.37352 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / candidate plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "chromium", + "status": "passed", + "durationMs": 3649, + "lifetime": { + "core": "candidate", + "implementation": "candidate", + "mode": 1, + "sha256": "43a5d785210c378a7d06e53bdbd6db0d276e5eac4e4feeabaed4f02ac02f3df0", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 866.9000000357628 + } + ], + "replies": [ + { + "id": 1, + "wall": 2368.100000023842 + } + ], + "visible": [ + { + "wall": 2368.400000035763, + "clock": 1789309255710, + "startedAt": 1789309255709, + "rest": 1, + "mode": 1, + "time": 2.189831, + "transition": "" + } + ], + "recycled": [ + { + "wall": 3381.400000035763, + "rest": -0.01400000000000072, + "time": 3.201943 + } + ], + "video": { + "width": 640, + "time": 3.340104 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / candidate plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "firefox", + "status": "passed", + "durationMs": 4940, + "lifetime": { + "core": "published", + "implementation": "candidate", + "mode": 0, + "sha256": "43a5d785210c378a7d06e53bdbd6db0d276e5eac4e4feeabaed4f02ac02f3df0", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 1324 + } + ], + "replies": [ + { + "id": 1, + "wall": 2834 + } + ], + "visible": [ + { + "wall": 2834, + "clock": 1789309261899, + "startedAt": 1789309261899, + "rest": 1, + "mode": 0, + "time": 2.209763, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 3842, + "rest": -0.009000000000000726, + "time": 3.205177 + } + ], + "video": { + "width": 640, + "time": 3.447448 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / candidate plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "firefox", + "status": "passed", + "durationMs": 3863, + "lifetime": { + "core": "published", + "implementation": "candidate", + "mode": 1, + "sha256": "43a5d785210c378a7d06e53bdbd6db0d276e5eac4e4feeabaed4f02ac02f3df0", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 930 + } + ], + "replies": [ + { + "id": 1, + "wall": 2438 + } + ], + "visible": [ + { + "wall": 2439, + "clock": 1789309265851, + "startedAt": 1789309265850, + "rest": 1, + "mode": 1, + "time": 2.213712, + "transition": "" + } + ], + "recycled": [ + { + "wall": 3448, + "rest": -0.010000000000000717, + "time": 3.228843 + } + ], + "video": { + "width": 640, + "time": 3.391541 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / candidate plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "firefox", + "status": "passed", + "durationMs": 5077, + "lifetime": { + "core": "candidate", + "implementation": "candidate", + "mode": 0, + "sha256": "43a5d785210c378a7d06e53bdbd6db0d276e5eac4e4feeabaed4f02ac02f3df0", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 1364 + } + ], + "replies": [ + { + "id": 1, + "wall": 2886 + } + ], + "visible": [ + { + "wall": 2887, + "clock": 1789309262515, + "startedAt": 1789309262515, + "rest": 1, + "mode": 0, + "time": 2.244616, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 3897, + "rest": -0.009000000000000688, + "time": 3.220611 + } + ], + "video": { + "width": 640, + "time": 3.423031 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / candidate plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "firefox", + "status": "passed", + "durationMs": 3675, + "lifetime": { + "core": "candidate", + "implementation": "candidate", + "mode": 1, + "sha256": "43a5d785210c378a7d06e53bdbd6db0d276e5eac4e4feeabaed4f02ac02f3df0", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 699 + } + ], + "replies": [ + { + "id": 1, + "wall": 2201 + } + ], + "visible": [ + { + "wall": 2201, + "clock": 1789309266231, + "startedAt": 1789309266231, + "rest": 1, + "mode": 1, + "time": 1.964104, + "transition": "" + } + ], + "recycled": [ + { + "wall": 3214, + "rest": -0.012000000000000718, + "time": 2.978202 + } + ], + "video": { + "width": 640, + "time": 3.139033 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / candidate plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "webkit", + "status": "passed", + "durationMs": 4875, + "lifetime": { + "core": "published", + "implementation": "candidate", + "mode": 0, + "sha256": "43a5d785210c378a7d06e53bdbd6db0d276e5eac4e4feeabaed4f02ac02f3df0", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 1335 + } + ], + "replies": [ + { + "id": 1, + "wall": 2854 + } + ], + "visible": [ + { + "wall": 2854, + "clock": 1789309271315, + "startedAt": 1789309271314, + "rest": 1, + "mode": 0, + "time": 2.0577503, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 3862, + "rest": -0.009000000000000313, + "time": 3.0659171 + } + ], + "video": { + "width": 640, + "time": 3.5605005 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / candidate plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "webkit", + "status": "passed", + "durationMs": 4782, + "lifetime": { + "core": "published", + "implementation": "candidate", + "mode": 1, + "sha256": "43a5d785210c378a7d06e53bdbd6db0d276e5eac4e4feeabaed4f02ac02f3df0", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 1328 + } + ], + "replies": [ + { + "id": 1, + "wall": 2850 + } + ], + "visible": [ + { + "wall": 2851, + "clock": 1789309276143, + "startedAt": 1789309276142, + "rest": 1, + "mode": 1, + "time": 2.0572919, + "transition": "" + } + ], + "recycled": [ + { + "wall": 3892, + "rest": -0.042000000000000245, + "time": 3.0985213 + } + ], + "video": { + "width": 640, + "time": 3.5382505 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / candidate plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "webkit", + "status": "passed", + "durationMs": 4848, + "lifetime": { + "core": "candidate", + "implementation": "candidate", + "mode": 0, + "sha256": "43a5d785210c378a7d06e53bdbd6db0d276e5eac4e4feeabaed4f02ac02f3df0", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 1313 + } + ], + "replies": [ + { + "id": 1, + "wall": 2832 + } + ], + "visible": [ + { + "wall": 2832, + "clock": 1789309271621, + "startedAt": 1789309271621, + "rest": 1, + "mode": 0, + "time": 2.0435836, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 3839, + "rest": -0.006000000000000311, + "time": 3.0503963 + } + ], + "video": { + "width": 640, + "time": 3.5013755 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / candidate plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "webkit", + "status": "passed", + "durationMs": 4820, + "lifetime": { + "core": "candidate", + "implementation": "candidate", + "mode": 1, + "sha256": "43a5d785210c378a7d06e53bdbd6db0d276e5eac4e4feeabaed4f02ac02f3df0", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 1318 + } + ], + "replies": [ + { + "id": 1, + "wall": 2843 + } + ], + "visible": [ + { + "wall": 2844, + "clock": 1789309276465, + "startedAt": 1789309276464, + "rest": 1, + "mode": 1, + "time": 2.0192919, + "transition": "" + } + ], + "recycled": [ + { + "wall": 3848, + "rest": -0.005000000000000088, + "time": 3.0231046 + } + ], + "video": { + "width": 640, + "time": 3.5475213 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + } + ] + }, + { + "format": "legacy", + "file": "refactor/.cache/danmuku11-legacy-browser.json", + "sha256": "f63d6735c1d1a94176d57ff6b25865a5b44e382efb7cf99e7f2659cc713bb012", + "stats": { + "startTime": "2026-09-13T14:21:19.082Z", + "duration": 32117.738999999998, + "expected": 12, + "skipped": 0, + "unexpected": 0, + "flaky": 0 + }, + "versions": { + "chromium": { + "version": "153.0.8010.12", + "platform": "win32" + }, + "firefox": { + "version": "155.0", + "platform": "win32" + }, + "webkit": { + "version": "26.6", + "platform": "win32" + } + }, + "cases": [ + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / candidate plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "chromium", + "status": "passed", + "durationMs": 3760, + "lifetime": { + "core": "published", + "implementation": "candidate", + "mode": 0, + "sha256": "d3b8ff3b9fa880336b6fd267dc73894fc546488178513269a62a66711e108ede", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 904.6999999880791 + } + ], + "replies": [ + { + "id": 1, + "wall": 2405.699999988079 + } + ], + "visible": [ + { + "wall": 2406, + "clock": 1789309284527, + "startedAt": 1789309284526, + "rest": 1, + "mode": 0, + "time": 2.205246, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 3418.699999988079, + "rest": -0.013000000000000712, + "time": 3.216793 + } + ], + "video": { + "width": 640, + "time": 3.354641 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / candidate plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "chromium", + "status": "passed", + "durationMs": 3603, + "lifetime": { + "core": "published", + "implementation": "candidate", + "mode": 1, + "sha256": "d3b8ff3b9fa880336b6fd267dc73894fc546488178513269a62a66711e108ede", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 826.4000000357628 + } + ], + "replies": [ + { + "id": 1, + "wall": 2328.100000023842 + } + ], + "visible": [ + { + "wall": 2328.5, + "clock": 1789309288160, + "startedAt": 1789309288160, + "rest": 1, + "mode": 1, + "time": 2.173315, + "transition": "" + } + ], + "recycled": [ + { + "wall": 3340.7000000476837, + "rest": -0.01200000000000066, + "time": 3.187427 + } + ], + "video": { + "width": 640, + "time": 3.324789 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / candidate plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "chromium", + "status": "passed", + "durationMs": 3802, + "lifetime": { + "core": "candidate", + "implementation": "candidate", + "mode": 0, + "sha256": "d3b8ff3b9fa880336b6fd267dc73894fc546488178513269a62a66711e108ede", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 919.1999999880791 + } + ], + "replies": [ + { + "id": 1, + "wall": 2421.100000023842 + } + ], + "visible": [ + { + "wall": 2421.300000011921, + "clock": 1789309284544, + "startedAt": 1789309284544, + "rest": 1, + "mode": 0, + "time": 2.202848, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 3431.199999988079, + "rest": -0.010000000000000717, + "time": 3.212378 + } + ], + "video": { + "width": 640, + "time": 3.370735 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / candidate plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "chromium", + "status": "passed", + "durationMs": 3649, + "lifetime": { + "core": "candidate", + "implementation": "candidate", + "mode": 1, + "sha256": "d3b8ff3b9fa880336b6fd267dc73894fc546488178513269a62a66711e108ede", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 853.6999999880791 + } + ], + "replies": [ + { + "id": 1, + "wall": 2355.899999976158 + } + ], + "visible": [ + { + "wall": 2356.300000011921, + "clock": 1789309288260, + "startedAt": 1789309288260, + "rest": 1, + "mode": 1, + "time": 2.190169, + "transition": "" + } + ], + "recycled": [ + { + "wall": 3367.300000011921, + "rest": -0.011000000000000718, + "time": 3.200492 + } + ], + "video": { + "width": 640, + "time": 3.327724 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / candidate plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "firefox", + "status": "passed", + "durationMs": 5082, + "lifetime": { + "core": "published", + "implementation": "candidate", + "mode": 0, + "sha256": "d3b8ff3b9fa880336b6fd267dc73894fc546488178513269a62a66711e108ede", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 1429 + } + ], + "replies": [ + { + "id": 1, + "wall": 2934 + } + ], + "visible": [ + { + "wall": 2935, + "clock": 1789309294406, + "startedAt": 1789309294406, + "rest": 1, + "mode": 0, + "time": 2.214997, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 3946, + "rest": -0.01100000000000076, + "time": 3.202215 + } + ], + "video": { + "width": 640, + "time": 3.484347 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / candidate plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "firefox", + "status": "passed", + "durationMs": 3629, + "lifetime": { + "core": "published", + "implementation": "candidate", + "mode": 1, + "sha256": "d3b8ff3b9fa880336b6fd267dc73894fc546488178513269a62a66711e108ede", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 692 + } + ], + "replies": [ + { + "id": 1, + "wall": 2194 + } + ], + "visible": [ + { + "wall": 2195, + "clock": 1789309298140, + "startedAt": 1789309298140, + "rest": 1, + "mode": 1, + "time": 1.958091, + "transition": "" + } + ], + "recycled": [ + { + "wall": 3208, + "rest": -0.01400000000000072, + "time": 2.971989 + } + ], + "video": { + "width": 640, + "time": 3.133963 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / candidate plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "firefox", + "status": "passed", + "durationMs": 4834, + "lifetime": { + "core": "candidate", + "implementation": "candidate", + "mode": 0, + "sha256": "d3b8ff3b9fa880336b6fd267dc73894fc546488178513269a62a66711e108ede", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 1070 + } + ], + "replies": [ + { + "id": 1, + "wall": 2576 + } + ], + "visible": [ + { + "wall": 2577, + "clock": 1789309294656, + "startedAt": 1789309294656, + "rest": 1, + "mode": 0, + "time": 1.927643, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 3588, + "rest": -0.011000000000000718, + "time": 2.942477 + } + ], + "video": { + "width": 640, + "time": 3.224983 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / candidate plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "firefox", + "status": "passed", + "durationMs": 3944, + "lifetime": { + "core": "candidate", + "implementation": "candidate", + "mode": 1, + "sha256": "d3b8ff3b9fa880336b6fd267dc73894fc546488178513269a62a66711e108ede", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 979 + } + ], + "replies": [ + { + "id": 1, + "wall": 2480 + } + ], + "visible": [ + { + "wall": 2481, + "clock": 1789309298722, + "startedAt": 1789309298722, + "rest": 1, + "mode": 1, + "time": 2.190933, + "transition": "" + } + ], + "recycled": [ + { + "wall": 3496, + "rest": -0.015000000000000777, + "time": 3.200517 + } + ], + "video": { + "width": 640, + "time": 3.36647 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / candidate plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "webkit", + "status": "passed", + "durationMs": 4990, + "lifetime": { + "core": "published", + "implementation": "candidate", + "mode": 0, + "sha256": "d3b8ff3b9fa880336b6fd267dc73894fc546488178513269a62a66711e108ede", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 1494 + } + ], + "replies": [ + { + "id": 1, + "wall": 3024 + } + ], + "visible": [ + { + "wall": 3024, + "clock": 1789309303675, + "startedAt": 1789309303675, + "rest": 1, + "mode": 0, + "time": 2.0485419, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 4032, + "rest": -0.007000000000000367, + "time": 3.0563129 + } + ], + "video": { + "width": 640, + "time": 3.4431046 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "published core / candidate plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "webkit", + "status": "passed", + "durationMs": 4709, + "lifetime": { + "core": "published", + "implementation": "candidate", + "mode": 1, + "sha256": "d3b8ff3b9fa880336b6fd267dc73894fc546488178513269a62a66711e108ede", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 1274 + } + ], + "replies": [ + { + "id": 1, + "wall": 2803 + } + ], + "visible": [ + { + "wall": 2804, + "clock": 1789309308352, + "startedAt": 1789309308351, + "rest": 1, + "mode": 1, + "time": 2.0574794, + "transition": "" + } + ], + "recycled": [ + { + "wall": 3809, + "rest": -0.005000000000000199, + "time": 3.0620213 + } + ], + "video": { + "width": 640, + "time": 3.496813 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / candidate plugin / mode 0: Worker waiting does not consume visible lifetime", + "engine": "webkit", + "status": "passed", + "durationMs": 5071, + "lifetime": { + "core": "candidate", + "implementation": "candidate", + "mode": 0, + "sha256": "d3b8ff3b9fa880336b6fd267dc73894fc546488178513269a62a66711e108ede", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 1248 + } + ], + "replies": [ + { + "id": 1, + "wall": 2777 + } + ], + "visible": [ + { + "wall": 2777, + "clock": 1789309304285, + "startedAt": 1789309304285, + "rest": 1, + "mode": 0, + "time": 2.0385627, + "transition": "transform 1s linear" + } + ], + "recycled": [ + { + "wall": 3804, + "rest": -0.026000000000000106, + "time": 3.0651254 + } + ], + "video": { + "width": 640, + "time": 3.542313 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + }, + { + "file": "danmuku-lifetime.spec.js", + "title": "candidate core / candidate plugin / mode 1: Worker waiting does not consume visible lifetime", + "engine": "webkit", + "status": "passed", + "durationMs": 4779, + "lifetime": { + "core": "candidate", + "implementation": "candidate", + "mode": 1, + "sha256": "d3b8ff3b9fa880336b6fd267dc73894fc546488178513269a62a66711e108ede", + "evidence": { + "posts": [ + { + "id": 1, + "wall": 1412 + } + ], + "replies": [ + { + "id": 1, + "wall": 2937 + } + ], + "visible": [ + { + "wall": 2937, + "clock": 1789309309221, + "startedAt": 1789309309220, + "rest": 1, + "mode": 1, + "time": 2.0369377, + "transition": "" + } + ], + "recycled": [ + { + "wall": 3957, + "rest": -0.021000000000000213, + "time": 3.0571254 + } + ], + "video": { + "width": 640, + "time": 3.4555005 + } + }, + "scope": "Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation." + } + } + ] + } + ], + "browserScope": "Source: 66 existing scheduling cases plus 24 lifetime cases across two cores, old/new plugins, modes 0/1 and three engines. Main/legacy: each 12 selected candidate lifetime cases, same two cores/modes/engines. Controlled 1500ms delivery delay then actual native Worker geometry. Not evidence of natural Worker starvation, complete load stability or Safari hardware.", + "failures": [ + { + "file": "refactor/.cache/danmuku11-unit-red.log", + "sha256": "99184f9b493ee9d041c0d009e83436a467d66830b7650e9d21253937528d701f" + }, + { + "file": "refactor/.cache/danmuku11-browser-red.json", + "sha256": "5f48b8c7b897c53db8d84973cd449bb34efa905666d2ec5e6fdc2815da3f8860" + }, + { + "file": "refactor/.cache/danmuku11-browser-red-isolated.json", + "sha256": "97f8fd1cb3b8d7ee4179c1af6fb3a151757bcc6035ed84ad2c76f6dd42de259f" + } + ], + "redScope": "Three controlled candidate modes fail visible-start timestamp. First browser run also exposed the separate known published duplicate play/playing loop; isolate one start after native playback. Isolated run preserves four historical defect passes and four candidate lifetime failures without changing lifetime thresholds.", + "checks": [ + { + "file": "refactor/.cache/danmuku11-build.log", + "sha256": "f19dd81f39d43660cfe82a469f1843c5bd54dcf6fec1df48c804abc7f6d04eb9" + }, + { + "file": "refactor/.cache/danmuku11-lint.log", + "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + { + "file": "refactor/.cache/danmuku11-types.log", + "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + } + ], + "fingerprints": [ + { + "file": "packages/artplayer-plugin-danmuku/src/scheduler.ts", + "sha256": "bc5fabee60e2f244e708ddd97ec690393f24be98eb1ffcf9052b42af2db82292" + }, + { + "file": "packages/artplayer-plugin-danmuku/ARCHITECTURE.md", + "sha256": "8609a86e8a89750dcacc65e15967e85caf75240901f69145b41bc2f61b9f5785" + }, + { + "file": "test/danmuku-scheduler.test.js", + "sha256": "814154bcac55cc1cef9804eb03fea11bc75a39c49ad694320777f32b437525be" + }, + { + "file": "test/browser/danmuku-lifetime.spec.js", + "sha256": "99ad1f1be473035f86549290951856fb00b035d88a50ac4b675fd97bebe1280e" + }, + { + "file": "docs/uncompiled/artplayer-plugin-danmuku/index.js", + "sha256": "377b07538c23034a172a02295b494bd9b5a199406aa94ab6c5b904c854512837" + }, + { + "file": "packages/artplayer-plugin-danmuku/dist/artplayer-plugin-danmuku.js", + "sha256": "43a5d785210c378a7d06e53bdbd6db0d276e5eac4e4feeabaed4f02ac02f3df0" + }, + { + "file": "docs/compiled/artplayer-plugin-danmuku.js", + "sha256": "43a5d785210c378a7d06e53bdbd6db0d276e5eac4e4feeabaed4f02ac02f3df0" + }, + { + "file": "packages/artplayer-plugin-danmuku/dist/artplayer-plugin-danmuku.legacy.js", + "sha256": "d3b8ff3b9fa880336b6fd267dc73894fc546488178513269a62a66711e108ede" + }, + { + "file": "docs/compiled/artplayer-plugin-danmuku.legacy.js", + "sha256": "d3b8ff3b9fa880336b6fd267dc73894fc546488178513269a62a66711e108ede" + }, + { + "file": "packages/artplayer-plugin-danmuku/dist/artplayer-plugin-danmuku.mjs", + "sha256": "2bca0ec5cb653e83e87f06261a07a0354c423c4dd91d8a14fc08cde1dfe2b565" + }, + { + "file": "docs/compiled/artplayer-plugin-danmuku.mjs", + "sha256": "2bca0ec5cb653e83e87f06261a07a0354c423c4dd91d8a14fc08cde1dfe2b565" + } + ], + "remaining": [ + "PKG-DANMUKU-07", + "DANMUKU-LOAD-01", + "PKG-DANMUKU-08", + "PKG-DANMUKU-09", + "Release review gates" + ] +} diff --git a/refactor/changes/2026-09-13-PKG-DANMUKU-11-visible-lifetime.md b/refactor/changes/2026-09-13-PKG-DANMUKU-11-visible-lifetime.md new file mode 100644 index 000000000..396dd1153 --- /dev/null +++ b/refactor/changes/2026-09-13-PKG-DANMUKU-11-visible-lifetime.md @@ -0,0 +1,43 @@ +# PKG-DANMUKU-11 Worker 等待与可见寿命 + +07稳定性审查发现独立计时问题,拆为本任务修复;07本身仍未完成。 +配置speed为1秒,Worker回复之前的隐藏等待如果超过1秒,弹幕刚触发visible就会 +在下一调度帧被回收。开始时间原先在postMessage前设置,而CSS显示在回复后才开始。 + +## 兼容范围 + +修复仅把成功放置的可见起点与实际放置时间对齐。保留原speed、Worker几何输入、 +同步/异步门面、事件参数/顺序、状态池、取消与错误行为;不改变公开类型或包入口。 +空轨道/取消不新增visible;暂停后的剩余寿命、播放速度与旧seek/reset行为仍回归。 +这是原来隐藏等待吞掉可见时长的缺陷修正,等待较长的弹幕会获得完整显示时间。 +历史readys的±0.1秒窗口和beforeVisible串行语义不在此任务改变。 + +## 验证 + +受控红测使用真实Worker算法:mode0/1/2、1秒寿命、等待3秒。三个开始时间断言 +均得到1000而非4000,明确复现本问题;修复后的绿测继续验证250ms剩余寿命和一次 +回收断言。原始日志保留在refactor/.cache/danmuku11-unit-red.log。 + +原生测试使用实际视频与真实Worker几何,仅通过观察用Worker子类给请求传递加 +1500ms延迟,记录post/reply/visible/recycle时间。它验证人为注入延迟后的行为, +不声称真实用户环境必然发生相同Worker延迟。 + +完整源码253项通过,正式main/legacy各57项调度与Worker测试通过(包括共同的 +内部WorkerClient测试,不能都算独立产物案例)。构建、目标lint和分包严格TS通过。 +源码浏览器90项:原调度66项加寿命24项,覆盖两核心、新旧插件、mode0/1及三引擎; +main/legacy各选12项候选寿命用例,总114项通过,无重试或跳过。以visible事件到 +节点回收测得生命周期,不把它称为逐帧视觉/自然Worker饥饿或长期吞吐验收。 +相同1秒配置下,旧版测得0–15ms,修复源码998–1044ms,main1004–1041ms、 +legacy1005–1027ms;原生逐帧调度有少量回收延后,受控用例精确验证时间扣减。 +具体环境、字节及时间见[机器证据](../baselines/danmuku-lifetime-validation.json)。 + +首次浏览器运行也触发了旧版已登记的play/playing双循环,历史两次请求与单次计时 +夹具冲突。将插件安装放在原生playing之后并显式启动一次来隔离该已知缺陷,未改变 +被测时钟/队列或寿命阈值。隔离红测4个旧版缺陷观察通过、4个候选寿命断言失败, +再修复生产。第一次失败也留档,没有把夹具故障当成本任务独立红测。 +独立只读复查确认取消/节点检查在时钟更新之前,几何与剩余寿命仍按准备时速度 +计算,setState→place→visible顺序不变;包ARCHITECTURE同步维护计时边界。 +无新依赖、公开类型、版本或分发入口变更;构建产物和docs复制保持相同字节。 + +状态以tasks.json为准。回退本任务独立commit +会恢复旧计时问题,不撤销06类型迁移或10热力图修复。未推送、未发布。 diff --git a/refactor/plan.md b/refactor/plan.md index ff02a27e7..e4e82ca32 100644 --- a/refactor/plan.md +++ b/refactor/plan.md @@ -2,9 +2,9 @@ > 由 tasks.json 生成。请修改数据后运行 `node refactor/scripts/plan.mjs --write`,不要手改本表。 -基线:`40fcda6a37d0049d42e49c1e64e70d4fd9ba5f7f`。总任务 229 项,范围 22 个包及工作区/示例。 +基线:`40fcda6a37d0049d42e49c1e64e70d4fd9ba5f7f`。总任务 230 项,范围 22 个包及工作区/示例。 -状态:todo 68 / doing 15 / blocked 0 / done 146 / deferred 0。风险 L/M/H 表示兼容风险,不表示工期。 +状态:todo 68 / doing 15 / blocked 0 / done 147 / deferred 0。风险 L/M/H 表示兼容风险,不表示工期。 前置依赖是启动条件;验收是完成条件。任务可以继续拆分,但不能复用或悄悄删除旧 ID。 @@ -22,7 +22,7 @@ | artplayer-plugin-auto-thumbnail | 1.1.0 | PKG-AUTO-THUMB-01, PKG-AUTO-THUMB-02, PKG-AUTO-THUMB-03, PKG-AUTO-THUMB-04, PKG-AUTO-THUMB-05, PKG-AUTO-THUMB-06 | | artplayer-plugin-chapter | 1.1.0 | PILOT-01, PKG-CHAPTER-01, PKG-CHAPTER-02, PKG-CHAPTER-03, PKG-CHAPTER-04, PKG-CHAPTER-05, PKG-CHAPTER-06 | | artplayer-plugin-chromecast | 1.1.0 | PKG-CAST-01, PKG-CAST-02, PKG-CAST-03, PKG-CAST-04, PKG-CAST-05, PKG-CAST-06 | -| artplayer-plugin-danmuku | 5.3.0 | PKG-DANMUKU-01, PKG-DANMUKU-02, PKG-DANMUKU-03, PKG-DANMUKU-04, PKG-DANMUKU-05, PKG-DANMUKU-06, PKG-DANMUKU-07, PKG-DANMUKU-08, PKG-DANMUKU-09, PKG-DANMUKU-10 | +| artplayer-plugin-danmuku | 5.3.0 | PKG-DANMUKU-01, PKG-DANMUKU-02, PKG-DANMUKU-03, PKG-DANMUKU-04, PKG-DANMUKU-05, PKG-DANMUKU-06, PKG-DANMUKU-07, PKG-DANMUKU-08, PKG-DANMUKU-09, PKG-DANMUKU-10, PKG-DANMUKU-11 | | artplayer-plugin-danmuku-mask | 1.1.0 | PKG-MASK-01, PKG-MASK-02, PKG-MASK-03, PKG-MASK-04, PKG-MASK-05, PKG-MASK-06 | | artplayer-plugin-dash-control | 1.1.0 | PKG-DASH-01, PKG-DASH-02, PKG-DASH-03, PKG-DASH-04, PKG-DASH-05, PKG-DASH-06 | | artplayer-plugin-document-pip | 1.1.0 | PKG-DPIP-01, PKG-DPIP-02, PKG-DPIP-03, PKG-DPIP-04, PKG-DPIP-05, PKG-DPIP-06 | @@ -315,10 +315,11 @@ | PKG-DANMUKU-04 | artplayer-plugin-danmuku
整理时钟、队列与轨道调度 | PKG-DANMUKU-03, CORE-10 | danmuku 调度器和确定性时钟测试 | seek/暂停/倍率/长时间运行无顺序和碰撞回归 | H | done | | PKG-DANMUKU-05 | artplayer-plugin-danmuku
整理 DOM 渲染、设置、热力图与 worker | PKG-DANMUKU-04, CORE-14, CORE-18 | renderer/setting/heatmap/worker 职责及资源归属 | mount/icons/设置和 worker 协议保持,销毁无后台工作 | H | done | | PKG-DANMUKU-06 | artplayer-plugin-danmuku
迁移 TS 与公开声明 | PKG-DANMUKU-05, ENG-04, ENG-06 | 自有模块、worker 消息、option/item/result 类型 | 旧参数、扩展字段和事件消费通过,vendored 边界清楚 | H | done | -| PKG-DANMUKU-07 | artplayer-plugin-danmuku
弹幕能力稳定性验收 | PKG-DANMUKU-06, PKG-DANMUKU-10 | 负载/渲染/资源对比及 mask 可依赖的稳定边界 | 在试点核心中旧插件 API 与关键帧路径通过 | H | doing | +| PKG-DANMUKU-07 | artplayer-plugin-danmuku
弹幕能力稳定性验收 | PKG-DANMUKU-06, PKG-DANMUKU-10, PKG-DANMUKU-11 | 负载/渲染/资源对比及 mask 可依赖的稳定边界 | 在试点核心中旧插件 API 与关键帧路径通过 | H | doing | | PKG-DANMUKU-08 | artplayer-plugin-danmuku
完成新旧核心与组合验收 | PKG-DANMUKU-07, CORE-22 | 最终核心/旧核心、mask/fullscreen/PiP 组合报告 | 性能无未解释退化,反复装卸无累计资源 | H | todo | | PKG-DANMUKU-09 | artplayer-plugin-danmuku
完成分发、示例与文档 | PKG-DANMUKU-08, ENG-07 | danmuku.js、README、声明、worker 与产物 | tarball 和静态 icons 等旧调用通过,有独立回退版本 | H | todo | | PKG-DANMUKU-10 | artplayer-plugin-danmuku
修复 issue958 密集热力图过高与曲线裁平 | PKG-DANMUKU-05 | 自动密度缩放与曲线边界、历史自定义坐标兼容及真实浏览器红绿证据 | 16000条三种分布在两核心三引擎和source/main/legacy不遮挡;显式轴和自定义points保持旧解释,有单独commit | M | done | +| PKG-DANMUKU-11 | artplayer-plugin-danmuku
修复 Worker 隐藏等待吞掉可见寿命 | PKG-DANMUKU-06 | 成功放置时的可见计时与延迟回复回归 | 真实 Worker 延迟下完整显示寿命;保留暂停/回收/取消和公开契约 | M | done | ## 5 包迁移:artplayer-proxy-canvas @@ -589,3 +590,4 @@ - PKG-ASR-08: [记录](changes/2026-09-13-PKG-ASR-08-capture-output.md) [记录](baselines/asr-fallback-validation.json) - PKG-ASR-09: [记录](changes/2026-09-13-PKG-ASR-09-explicit-capture.md) [记录](baselines/asr-explicit-capture-validation.json) - PKG-DANMUKU-10: [记录](changes/2026-09-13-PKG-DANMUKU-10-heatmap-density.md) [记录](baselines/danmuku-heatmap-density-validation.json) +- PKG-DANMUKU-11: [记录](changes/2026-09-13-PKG-DANMUKU-11-visible-lifetime.md) [记录](baselines/danmuku-lifetime-validation.json) diff --git a/refactor/progress.md b/refactor/progress.md index 379588818..66e2ec434 100644 --- a/refactor/progress.md +++ b/refactor/progress.md @@ -1,5 +1,17 @@ # 进度与证据 +## PKG-DANMUKU-11 Worker 等待寿命修复 + +07负载审查独立发现并复现:隐藏Worker等待超过speed时,刚显示的弹幕下一帧就被 +回收。成功放置时重置可见起点,保留准备时速度、几何、取消检查与事件顺序。 +三模式受控红/绿、两核心与三引擎真实延迟Worker验证通过;完整源码253项、 +main/legacy各57项单测,源码90及两个产物各12共114项浏览器通过。构建/lint/严格 +分包TS通过,见[变更](changes/2026-09-13-PKG-DANMUKU-11-visible-lifetime.md)和 +[机器证据](baselines/danmuku-lifetime-validation.json)。 +这是实际视频/Worker加受控请求延迟,不声称自然饥饿或持续高负载通过。 +230项:147 done、15 doing、68 todo;07继续,DANMUKU-LOAD-01仍开放。 +新增11是独立缺陷任务和本地commit;不推送或发布。 + ## PKG-DANMUKU-06 自有 TS 与公开声明完成 20个自有运行模块完成严格TS,新增内部状态/Worker/parser/UI类型边界;公开运行 diff --git a/refactor/risk-table.md b/refactor/risk-table.md index 7dfa36278..aef2ce779 100644 --- a/refactor/risk-table.md +++ b/refactor/risk-table.md @@ -239,3 +239,4 @@ | DANMUKU-INPUT-02 | resolved / 已复现 | Intermediate explicit-zero correction regressed accepted NaN timestamp fallback | PKG-DANMUKU-04 | | DANMUKU-LOAD-01 | open / 待取证 | Native lifecycle fixtures sometimes miss timestamp eligibility during concurrent workload; real frame/window behavior needs load evidence | PKG-DANMUKU-07 | | DANMUKU-HEATMAP-02 | resolved / 已复现 | Issue958 dense automatic heatmaps exceed the fixed Y domain and flatten across video | PKG-DANMUKU-10 | +| DANMUKU-TIMING-01 | resolved / 已复现 | Hidden Worker wait is deducted from visible lifetime and can recycle a comment immediately after visible | PKG-DANMUKU-11 | diff --git a/refactor/risks.json b/refactor/risks.json index 2c604ef43..6c3f629a5 100644 --- a/refactor/risks.json +++ b/refactor/risks.json @@ -5324,6 +5324,28 @@ "refactor/baselines/danmuku-heatmap-density-validation.json" ], "resolutionRationale": "250 unit tests and 102 native browser cases passed, including source/main/legacy density matrices and main resource regression. No claim of full load or macOS device acceptance." + }, + { + "id": "DANMUKU-TIMING-01", + "title": "Hidden Worker wait is deducted from visible lifetime and can recycle a comment immediately after visible", + "confirmation": "reproduced", + "status": "resolved", + "owners": [ + "PKG-DANMUKU-11" + ], + "evidence": [ + "refactor/changes/2026-09-13-PKG-DANMUKU-11-visible-lifetime.md", + "test/danmuku-scheduler.test.js", + "test/browser/danmuku-lifetime.spec.js", + "refactor/baselines/danmuku-lifetime-validation.json" + ], + "compatibleResolution": "Anchor the lifetime clock to successful placement while preserving speed, Worker geometry, queue ordering and lifecycle cancellation.", + "closureCriteria": "Controlled three-mode regression and native delayed Worker runs distinguish historical immediate recycling from full candidate visible lifetime; ordinary scheduling regressions remain green.", + "resolutionEvidence": [ + "refactor/baselines/danmuku-lifetime-validation.json", + "refactor/changes/2026-09-13-PKG-DANMUKU-11-visible-lifetime.md" + ], + "resolutionRationale": "Three exact controlled modes and real delayed Worker/native video regression establish full visible lifetime, with the unchanged published defect retained and existing scheduling/pause/cancellation checks green." } ] } diff --git a/refactor/tasks.json b/refactor/tasks.json index b6aab4542..25fd15ac4 100644 --- a/refactor/tasks.json +++ b/refactor/tasks.json @@ -3380,7 +3380,8 @@ ], "dependsOn": [ "PKG-DANMUKU-06", - "PKG-DANMUKU-10" + "PKG-DANMUKU-10", + "PKG-DANMUKU-11" ], "status": "doing", "risk": "H", @@ -4681,6 +4682,25 @@ "changes/2026-09-13-PKG-DANMUKU-10-heatmap-density.md", "baselines/danmuku-heatmap-density-validation.json" ] + }, + { + "id": "PKG-DANMUKU-11", + "phase": "5 包迁移:artplayer-plugin-danmuku", + "title": "修复 Worker 隐藏等待吞掉可见寿命", + "scope": [ + "artplayer-plugin-danmuku" + ], + "dependsOn": [ + "PKG-DANMUKU-06" + ], + "status": "done", + "risk": "M", + "deliverable": "成功放置时的可见计时与延迟回复回归", + "acceptance": "真实 Worker 延迟下完整显示寿命;保留暂停/回收/取消和公开契约", + "evidence": [ + "changes/2026-09-13-PKG-DANMUKU-11-visible-lifetime.md", + "baselines/danmuku-lifetime-validation.json" + ] } ] } diff --git a/test/browser/danmuku-lifetime.spec.js b/test/browser/danmuku-lifetime.spec.js new file mode 100644 index 000000000..87d85eedf --- /dev/null +++ b/test/browser/danmuku-lifetime.spec.js @@ -0,0 +1,92 @@ +import assert from 'node:assert/strict' +import fs from 'node:fs' +import process from 'node:process' +import { ensureArchive, hash, readMember } from '../../refactor/scripts/releases.mjs' +import { compilePackage } from '../helpers/load.js' +import { expect, test } from './fixtures.js' + +const implementations = new Map() +test.beforeAll(async () => { + const release = JSON.parse(fs.readFileSync(new URL('../../refactor/baselines/danmuku-release.json', import.meta.url), 'utf8')).release + const member = `package/${release.manifest.main.replace(/^\.\//u, '')}` + const bytes = readMember(await ensureArchive(release), member) + assert.equal(hash(bytes), release.files[member]) + implementations.set('published', bytes.toString()) + implementations.set('candidate', process.env.ARTPLAYER_DANMUKU_ARTIFACT + ? fs.readFileSync(process.env.ARTPLAYER_DANMUKU_ARTIFACT, 'utf8') + : await compilePackage('artplayer-plugin-danmuku', 'umd')) +}) + +for (const core of ['published', 'candidate']) { + for (const implementation of ['published', 'candidate']) { + for (const mode of [0, 1]) { + test(`${core} core / ${implementation} plugin / mode ${mode}: Worker waiting does not consume visible lifetime`, async ({ page }, testInfo) => { + await page.goto(`/test/player.html?core=${core}`) + await page.evaluate(() => { + const evidence = window.lifetimeEvidence = { posts: [], replies: [], visible: [], recycled: [] } + const NativeWorker = window.Worker + window.Worker = class DelayedNativeWorker extends NativeWorker { + constructor(...args) { + super(...args) + this.addEventListener('message', event => evidence.replies.push({ id: event.data.id, wall: performance.now() })) + } + + postMessage(message, ...args) { + evidence.posts.push({ id: message.id, wall: performance.now() }) + // Delay delivery, then execute the actual native Worker and its real geometry. + this.delay = setTimeout(() => super.postMessage(message, ...args), 1500) + } + + terminate() { + clearTimeout(this.delay) + return super.terminate() + } + } + }) + const code = implementations.get(implementation) + await page.addScriptTag({ content: code }) + await page.evaluate(() => window.createPlayer('/assets/sample/video.mp4')) + await page.click('#play') + await expect.poll(() => page.evaluate(() => window.art.currentTime)).toBeGreaterThan(0.1) + // Install after native playing, then start once. The published duplicate + // play/playing loop defect is covered elsewhere and is not this timing case. + await page.evaluate(async (mode) => { + const art = window.art + const evidence = window.lifetimeEvidence + art.on('artplayerPluginDanmuku:visible', row => evidence.visible.push({ wall: performance.now(), clock: Date.now(), startedAt: row.$lastStartTime, rest: row.$restTime, mode: row.mode, time: art.currentTime, transition: row.$ref.style.transition })) + art.plugins.add(window.artplayerPluginDanmuku({ danmuku: [], speed: 1, antiOverlap: false, heatmap: false, emitter: false })) + const plugin = art.plugins.artplayerPluginDanmuku + const owner = plugin.config({}) + const makeWait = owner.makeWait + owner.makeWait = (row) => { + if (row.$state === 'emit') + evidence.recycled.push({ wall: performance.now(), rest: row.$restTime, time: art.currentTime }) + return makeWait.call(owner, row) + } + await plugin.load([{ id: 'delayed', text: 'Full visible lifetime', time: art.currentTime + 0.4, mode }]) + owner.start() + }, mode) + await expect.poll(() => page.evaluate(() => window.lifetimeEvidence.recycled.length)).toBe(1) + await page.click('#pause') + const evidence = await page.evaluate(() => ({ ...window.lifetimeEvidence, video: { width: window.art.video.videoWidth, time: window.art.currentTime } })) + await testInfo.attach('danmuku-lifetime', { contentType: 'application/json', body: JSON.stringify({ core, implementation, mode, sha256: hash(code), evidence, scope: 'Native video and real Worker geometry with controlled 1500ms request delay; does not assert naturally occurring Worker starvation.' }) }) + expect(evidence.posts).toHaveLength(1) + expect(evidence.replies).toHaveLength(1) + expect(evidence.visible).toHaveLength(1) + expect(evidence.video.width).toBeGreaterThan(0) + expect(evidence.replies[0].wall - evidence.posts[0].wall).toBeGreaterThanOrEqual(1400) + const lifetime = evidence.recycled[0].wall - evidence.visible[0].wall + if (implementation === 'published') { + // Preserve the historical defect as explicit evidence, not the candidate contract. + expect(lifetime).toBeLessThan(400) + expect(evidence.visible[0].clock - evidence.visible[0].startedAt).toBeGreaterThanOrEqual(1400) + } + else { + expect(lifetime).toBeGreaterThanOrEqual(900) + expect(evidence.visible[0].rest).toBe(1) + } + await page.evaluate(() => window.art.destroy()) + }) + } + } +} diff --git a/test/danmuku-scheduler.test.js b/test/danmuku-scheduler.test.js index bb0fbb918..87d085c49 100644 --- a/test/danmuku-scheduler.test.js +++ b/test/danmuku-scheduler.test.js @@ -491,6 +491,61 @@ test(`${prefix}: the actual algorithm places three same-time fixed rows on disti env.destroy() }) +for (const mode of [0, 1, 2]) { + test(`${prefix}: delayed Worker reply starts visible lifetime at placement for mode ${mode}`, async (t) => { + const { env, plugin, owner, worker, layer, reply } = await fixture({ speed: 1 }) + t.after(() => env.destroy()) + await plugin.emit({ text: `delayed-${mode}`, time: 10, mode }) + const row = owner.queue[0] + env.art.playing = true + owner.start() + const pendingFrame = env.frame() + await env.flush() + assert.equal(worker.messages.length, 1) + const ref = row.$ref + assert.equal(layer.children.length, 1) + assert.equal(output(env, 'visible').length, 0, 'Measurement before the Worker reply is not visible lifetime') + assert.notEqual(ref.style.visibility, 'visible') + + // The reply uses the real positioning algorithm; only its delivery and the + // wall/media clocks are controlled. No browser animation timing is claimed. + env.tick(3000) + env.art.currentTime += 3 + const placedAt = env.context.Date.now() + reply(0) + await pendingFrame + assert.equal(row.$state, 'emit') + assert.equal(row.$ref, ref) + assert.equal(ref.style.visibility, 'visible') + assert.deepEqual(output(env, 'visible').map(event => event.args[0]), [row]) + assert.equal(row.$restTime, 1) + assert.equal(row.$lastStartTime, placedAt, 'Hidden Worker waiting must not shorten the visible duration') + if (mode === 0) + assert.equal(ref.style.transition, 'transform 1s linear 0s') + + env.tick(250) + env.art.currentTime += 0.25 + await env.frame() + assert.equal(row.$state, 'emit') + assert.equal(row.$ref, ref) + assert.equal(row.$restTime, 0.75, 'Only elapsed time since visible placement consumes lifetime') + assert.equal(owner.$refs.length, 0) + + env.tick(750) + env.art.currentTime += 0.75 + await env.frame() + assert.equal(row.$state, 'wait') + assert.equal(row.$ref, null) + assert.equal(ref.style.visibility, 'hidden') + assert.deepEqual(Array.from(owner.$refs), [ref], 'The expired node returns to its pool exactly once') + await env.frame() + assert.deepEqual(Array.from(owner.$refs), [ref]) + assert.equal(worker.messages.length, 1) + assert.equal(output(env, 'visible').length, 1) + assert.equal(output(env, 'error').length, 0) + }) +} + test(`${prefix}: a sampled three-hour simulated clock preserves batch order, pooled nodes, pause and seek state`, async (t) => { // Advance a controlled clock at lifecycle boundaries; this is not a real-time // endurance, frame-rate, CSS animation or browser memory measurement.