🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

danmaku-lite

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

danmaku-lite - npm Package Compare versions

Comparing version
0.2.1
to
0.2.2
+8
-3
dist/canvas.js

@@ -838,3 +838,4 @@ var __typeError = (msg) => {

const scrollSpeed = W / 8 * __privateGet(this, _config).speed;
const th = __privateGet(this, _config).fontSize + __privateGet(this, _config).padding * 2 + 4;
const gap = Math.max(2, Math.ceil(__privateGet(this, _config).fontSize * 0.2));
const th = __privateGet(this, _config).fontSize + __privateGet(this, _config).padding * 2 + gap;
const posMs = pos * 1e3;

@@ -936,3 +937,4 @@ const batch = __privateGet(this, _scheduler).emitBatch(posMs);

const scrollSpeed = W / 8 * __privateGet(this, _config).speed;
const th = __privateGet(this, _config).fontSize + __privateGet(this, _config).padding * 2 + 4;
const gap = Math.max(2, Math.ceil(__privateGet(this, _config).fontSize * 0.2));
const th = __privateGet(this, _config).fontSize + __privateGet(this, _config).padding * 2 + gap;
const sent = { ...item, time: pos };

@@ -1007,2 +1009,3 @@ __privateMethod(this, _CanvasEngine_instances, emit_fn).call(this, sent, pos, scrollSpeed, th, W, H, true);

__privateGet(this, _cache).clearBitmaps();
__privateMethod(this, _CanvasEngine_instances, resizeTracks_fn).call(this);
}

@@ -1029,2 +1032,3 @@ setFontWeight(v) {

__privateGet(this, _cache).clearBitmaps();
__privateMethod(this, _CanvasEngine_instances, resizeTracks_fn).call(this);
}

@@ -1196,3 +1200,4 @@ setDuration(v) {

const cfg = __privateGet(this, _config);
const th = cfg.fontSize + cfg.padding * 2 + 4;
const gap = Math.max(2, Math.ceil(cfg.fontSize * 0.2));
const th = cfg.fontSize + cfg.padding * 2 + gap;
__privateGet(this, _tracks).resize(H, cfg.area, th);

@@ -1199,0 +1204,0 @@ };

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

var kt=h=>{throw TypeError(h)};var pt=(h,t,i)=>t.has(h)||kt("Cannot "+i);var e=(h,t,i)=>(pt(h,t,"read from private field"),i?i.call(h):t.get(h)),d=(h,t,i)=>t.has(h)?kt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(h):t.set(h,i),c=(h,t,i,r)=>(pt(h,t,"write to private field"),t.set(h,i),i),I=(h,t,i)=>(pt(h,t,"access private method"),i);var ft=(h,t,i,r)=>({set _(o){c(h,t,o);},get _(){return e(h,t,r)}});var tt=(r=>(r[r.Scroll=1]="Scroll",r[r.Top=5]="Top",r[r.Bottom=6]="Bottom",r))(tt||{});var et=class{constructor(t){this.W=0;this.H=0;this.dpr=1;this.container=t;let i=document.createElement("canvas");i.style.position="absolute",i.style.inset="0",i.style.width="100%",i.style.height="100%",i.style.pointerEvents="none",t.appendChild(i),this.canvas=i,this.ctx=i.getContext("2d"),this.updateDimensions();}updateDimensions(){let t=window.devicePixelRatio||1,i=this.container.clientWidth,r=this.container.clientHeight;return i===0||r===0?false:(this.dpr=t,this.W=i,this.H=r,this.canvas.width=i*t,this.canvas.height=r*t,this.canvas.style.width=i+"px",this.canvas.style.height=r+"px",this.ctx.setTransform(t,0,0,t,0,0),true)}get width(){return this.W}get height(){return this.H}get devicePixelRatio(){return this.dpr}clear(){this.ctx.clearRect(0,0,this.W,this.H);}setSmoothing(t){this.ctx.imageSmoothingEnabled=t;}setGlobalAlpha(t){this.ctx.globalAlpha=t;}destroy(){this.canvas.remove();}};var it=class{constructor(){this.scrollCount=0;this.scrollFree=[];this.scrollExit=new Float64Array(0);this.topCount=0;this.topFree=[];this.topExit=new Float64Array(0);this.bottomCount=0;this.bottomFree=[];this.bottomExit=new Float64Array(0);this.H=0;this.th=0;this.areaFraction=.75;}resize(t,i,r){this.H=t,this.th=r,this.areaFraction=i;let o=t*i,s=Math.max(1,Math.floor(o/r)),n=Math.max(1,Math.floor(o*.48/r));this.scrollCount=s,this.topCount=n,this.bottomCount=n,this.scrollExit=new Float64Array(s).fill(-1/0),this.topExit=new Float64Array(n).fill(-1/0),this.bottomExit=new Float64Array(n).fill(-1/0),this.scrollFree=Array.from({length:s},(a,l)=>l),this.topFree=Array.from({length:n},(a,l)=>l),this.bottomFree=Array.from({length:n},(a,l)=>l);}acquireScroll(t,i,r,o){let s=[];for(;this.scrollFree.length>0;){let a=this.scrollFree.pop();if(this.scrollExit[a]<=t){this.scrollExit[a]=t+i*1.2/r;for(let l of s)this.scrollFree.push(l);return {track:a,y:this.scrollY(a)}}s.push(a);}for(let a of s)this.scrollFree.push(a);let n=Math.random()*this.scrollCount|0;for(let a=0;a<this.scrollCount;a++){let l=(n+a)%this.scrollCount;if(this.scrollExit[l]<=t){this.scrollExit[l]=t+i*1.2/r;let w=this.scrollFree.indexOf(l);return w!==-1&&this.scrollFree.splice(w,1),{track:l,y:this.scrollY(l)}}}return null}releaseScroll(t){this.scrollExit[t]=-1/0,this.scrollFree.includes(t)||this.scrollFree.push(t);}acquireTop(t,i){let r=[];for(;this.topFree.length>0;){let s=this.topFree.pop();if(this.topExit[s]<=t){this.topExit[s]=t+i;for(let n of r)this.topFree.push(n);return {track:s,y:this.fixedY(s,true)}}r.push(s);}for(let s of r)this.topFree.push(s);let o=Math.random()*this.topCount|0;for(let s=0;s<this.topCount;s++){let n=(o+s)%this.topCount;if(this.topExit[n]<=t){this.topExit[n]=t+i;let a=this.topFree.indexOf(n);return a!==-1&&this.topFree.splice(a,1),{track:n,y:this.fixedY(n,true)}}}return null}releaseTop(t){this.topExit[t]=-1/0,this.topFree.includes(t)||this.topFree.push(t);}acquireBottom(t,i){let r=[];for(;this.bottomFree.length>0;){let s=this.bottomFree.pop();if(this.bottomExit[s]<=t){this.bottomExit[s]=t+i;for(let n of r)this.bottomFree.push(n);return {track:s,y:this.fixedY(s,false)}}r.push(s);}for(let s of r)this.bottomFree.push(s);let o=Math.random()*this.bottomCount|0;for(let s=0;s<this.bottomCount;s++){let n=(o+s)%this.bottomCount;if(this.bottomExit[n]<=t){this.bottomExit[n]=t+i;let a=this.bottomFree.indexOf(n);return a!==-1&&this.bottomFree.splice(a,1),{track:n,y:this.fixedY(n,false)}}}return null}releaseBottom(t){this.bottomExit[t]=-1/0,this.bottomFree.includes(t)||this.bottomFree.push(t);}get scrollTrackCount(){return this.scrollCount}get topTrackCount(){return this.topCount}get bottomTrackCount(){return this.bottomCount}scrollY(t){return (t+.5)*this.th}fixedY(t,i){return i?(t+.5)*this.th:this.H*this.areaFraction-(t+.5)*this.th}};var rt=class{constructor(){this.pool=[];}acquire(){return this.pool.length>0?this.pool.pop():{}}release(t){this.pool.length<512&&(t.bmp=void 0,t.el=void 0,this.pool.push(t));}releaseAll(t){for(let i=0;i<t.length;i++)this.release(t[i]);}get size(){return this.pool.length}};function bt(h){return h<0||h>16777215||!Number.isFinite(h)?"#000000":"#"+h.toString(16).padStart(6,"0")}function vt({fontFamily:h,fontSize:t,fontWeight:i}){return `${i} ${t}px ${h}`}var st=class{constructor(t=500){this.textWidths=new Map;this.bitmaps=new Map;this.aliveBitmaps=new Set;this.accessCounter=0;this.dpr=1;this.cachedFont="";this.fontFamily="";this.fontSize=0;this.fontWeight="";this.maxCache=t;}measure(t,i,r,o,s){let n=`${t}|${i}|${r}|${o}`,a=this.textWidths.get(n);if(a!==void 0)return a;s.font=vt({fontFamily:i,fontSize:r,fontWeight:o});let l=s.measureText(t).width;return this.textWidths.set(n,l),l}invalidateTextCache(){this.textWidths.clear();}getBitmap(t,i,r,o,s,n,a,l,w){let S=`${t}|${i}|${r}|${o}|${s}|${n}|${a}|${l}`,D=this.bitmaps.get(S);if(D)return D.accessId=++this.accessCounter,D.bitmap;(n!==this.fontFamily||i!==this.fontSize||a!==this.fontWeight)&&(this.fontFamily=n,this.fontSize=i,this.fontWeight=a,this.cachedFont=vt({fontFamily:n,fontSize:i,fontWeight:a}));let x=this.textWidths.get(`${t}|${n}|${i}|${a}`);if(x===void 0)throw new Error(`Text width not cached for "${t}". Call measure() first.`);let j=Math.ceil(x)+w*2,G=i+w*2,H=j*l|0,b=G*l|0,u=w*l,T=b/2,y=new OffscreenCanvas(H,b),v=y.getContext("2d");v.font=`${a} ${i*l}px ${n}`,v.lineWidth=o*l,v.lineJoin="round",v.textBaseline="middle",v.textAlign="left",v.strokeStyle=bt(s),v.strokeText(t,u,T),v.fillStyle=bt(r),v.fillText(t,u,T);let P=y.transferToImageBitmap();return this.bitmaps.set(S,{bitmap:P,accessId:++this.accessCounter}),this.aliveBitmaps.add(P),this.bitmaps.size>this.maxCache&&this.evictOne(),P}evictOne(){let t="",i=1/0;for(let[r,o]of this.bitmaps)o.accessId<i&&(i=o.accessId,t=r);if(t){let r=this.bitmaps.get(t);r&&(this.aliveBitmaps.delete(r.bitmap),r.bitmap.close(),this.bitmaps.delete(t));}}isAlive(t){return this.aliveBitmaps.has(t)}setMaxCache(t){for(this.maxCache=t;this.bitmaps.size>this.maxCache;)this.evictOne();}setDpr(t){this.dpr!==t&&(this.dpr=t,this.clearBitmaps());}clearBitmaps(){for(let[,t]of this.bitmaps)this.aliveBitmaps.delete(t.bitmap),t.bitmap.close();this.bitmaps.clear();}clearAll(){this.clearBitmaps(),this.textWidths.clear();}get bitmapCount(){return this.bitmaps.size}};var U,ot=class{constructor(t,i,r=true){this.rafId=0;this.lastFrameTime=-1;this.stopped=false;d(this,U,t=>{this.stopped||(this.tick(t),this.rafId=requestAnimationFrame(e(this,U)));});this.frameInterval=1e3/t,this.callback=i,r&&this.start();}start(){this.rafId!==0||this.stopped||(this.rafId=requestAnimationFrame(e(this,U)));}tick(t){if(this.stopped)return false;if(this.lastFrameTime<0)return this.lastFrameTime=t,this.callback(t),true;let i=t-this.lastFrameTime;return i>=this.frameInterval?(this.lastFrameTime=t-i%this.frameInterval,this.callback(t),true):false}setFps(t){this.frameInterval=1e3/t;}stop(){this.stopped=true,this.rafId!==0&&(cancelAnimationFrame(this.rafId),this.rafId=0);}};U=new WeakMap;function J(h,t,i){return h<t?t:h>i?i:h}function nt(h,t,i,r=0,o=h.length){for(;r<o;){let s=r+o>>1;i(h[s])<=t?r=s+1:o=s;}return r}var at=class{constructor(){this.pool=[];this.cursor=0;}load(t){this.pool=[...t].sort((i,r)=>i.time-r.time),this.cursor=0;}clear(){this.pool=[],this.cursor=0;}emitBatch(t){if(this.pool.length===0)return [];let i=this.cursor<this.pool.length?(this.pool[this.cursor]?.time??0)*1e3:1/0;if(t<i-200&&(this.cursor=nt(this.pool,t,s=>(s.time??0)*1e3)),this.cursor>=this.pool.length)return [];let r=nt(this.pool,t,s=>(s.time??0)*1e3);if(r<=this.cursor)return [];let o=this.pool.slice(this.cursor,r);return this.cursor=r,o}compact(t,i,r,o,s){let n=0;for(let a=0;a<t.length;a++){let l=t[a];if(l.mode===1){if(l.x-=o*r,l.x+l.w<-10){s(l);continue}}else if(i-l.born>=l.duration){s(l);continue}n!==a&&(t[n]=t[a]),n++;}return n}preCacheInfo(){return {pool:this.pool,cursor:this.cursor}}add(t){if(t.length===0)return;let i=new Set;for(let a=0;a<this.pool.length;a++)i.add(this.pool[a].id);let r=[...t].filter(a=>!i.has(a.id)).sort((a,l)=>a.time-l.time);if(r.length===0)return;let o=[],s=0,n=0;for(;s<this.pool.length&&n<r.length;)this.pool[s].time<=r[n].time?(o.push(this.pool[s]),s++):(o.push(r[n]),n++);for(;s<this.pool.length;)o.push(this.pool[s++]);for(;n<r.length;)o.push(r[n++]);this.pool=o;}evictBefore(t){if(this.pool.length===0)return;let i=nt(this.pool,t*1e3-.1,r=>(r.time??0)*1e3);i!==0&&(this.pool.splice(0,i),this.cursor=Math.max(0,this.cursor-i));}};var gt=new Map;typeof window<"u"&&!window.requestIdleCallback&&(window.requestIdleCallback=function(h,t){let i=t?.timeout,r=Date.now(),o=0,s={didTimeout:false,timeRemaining:()=>Math.max(0,50-(Date.now()-r))};i!=null&&(o=setTimeout(()=>{s.didTimeout=true,r=Date.now(),h(s);},i));let n=requestAnimationFrame(()=>{i!=null&&clearTimeout(o),!s.didTimeout&&(r=Date.now(),h(s));}),a=Date.now()+Math.random();return gt.set(a,{rafId:n,timeoutId:o}),a},window.cancelIdleCallback=function(h){let t=gt.get(h);t&&(cancelAnimationFrame(t.rafId),t.timeoutId&&clearTimeout(t.timeoutId),gt.delete(h));});function wt(h,t,i,r){let o=0,s=t;function n(a){let l=Math.min(t+i,h.length),w=0;for(;s<l&&(a.timeRemaining()>1||w<5);){let S=h[s];S&&r(S),s++,w++;}s<l&&(o=requestIdleCallback(n,{timeout:2e3}));}return o=requestIdleCallback(n,{timeout:2e3}),()=>cancelIdleCallback(o)}var It={enabled:true,fps:60,area:.75,fontFamily:"sans-serif",fontSize:25,fontWeight:"bold",opacity:1,padding:4,strokeWidth:1.25,strokeColor:0,speed:1,seekThreshold:.2,duration:4,overflow:"drop",maxVisible:0,maxCache:500,preCacheCount:50,smoothing:true,willChange:true,useTextShadow:true,preBuffer:60,leadTime:0};var X,Z,z,K,N,E,$,B,V,R,Ft,Dt,Tt,ht=class{constructor(t,i,r,o,s){d(this,R);d(this,X);d(this,Z);d(this,z);d(this,K);d(this,N);d(this,E,[]);d(this,$,0);d(this,B,null);d(this,V,-1);c(this,X,t),c(this,Z,Math.max(1,i)),c(this,z,Math.max(0,r)),c(this,K,Math.max(.5,o*2.5)),c(this,N,s);}probe(t,i){if(e(this,V)>=0&&Math.abs(t-e(this,V))>e(this,K)&&this.reset(),c(this,V,t),e(this,z)>0){let s=t-e(this,z);i.evictBefore(s),c(this,E,e(this,E).filter(n=>n.end>s));}if(e(this,B))return;let r=t+e(this,Z),o=I(this,R,Ft).call(this,t,r);o&&I(this,R,Dt).call(this,o.start,o.end,i);}reset(){ft(this,$)._++,c(this,B,null),c(this,E,[]),c(this,V,-1);}destroy(){this.reset();}};X=new WeakMap,Z=new WeakMap,z=new WeakMap,K=new WeakMap,N=new WeakMap,E=new WeakMap,$=new WeakMap,B=new WeakMap,V=new WeakMap,R=new WeakSet,Ft=function(t,i){let r=t;for(let o of e(this,E))if(o.start<=r&&r<o.end){if(r=o.end,r>=i)return null}else if(o.start>r)return {start:r,end:Math.min(o.start,i)};return r<i?{start:r,end:i}:null},Dt=function(t,i,r){let o=++ft(this,$)._;c(this,B,e(this,X).fetch(t,i).then(s=>{o===e(this,$)&&(c(this,B,null),s.length>0&&r.add(s),I(this,R,Tt).call(this,{start:t,end:i}));}).catch(s=>{var n;o===e(this,$)&&(c(this,B,null),(n=e(this,N))==null||n.call(this,s instanceof Error?s:new Error(String(s))));}));},Tt=function(t){e(this,E).push(t),e(this,E).sort((r,o)=>r.start-o.start);let i=[];for(let r of e(this,E)){let o=i[i.length-1];o&&o.end>=r.start?o.end=Math.max(o.end,r.end):i.push({...r});}c(this,E,i);};var p,m,f,C,M,g,_,A,k,L,O,q,W,Y,ct,F,xt,yt,lt,mt=class{constructor(t){d(this,F);d(this,p,false);d(this,m);d(this,f);d(this,C);d(this,M);d(this,g);d(this,_);d(this,A);d(this,k,[]);d(this,L,0);d(this,O,null);d(this,q);d(this,W,null);d(this,Y,-1);d(this,ct,t=>{let i=e(this,q).position,r=e(this,q).paused,o=e(this,f).width,s=e(this,f).height;if(!e(this,m).enabled||o===0){e(this,f).clear();return}if(r)return;let n=Math.abs(i-e(this,Y));if(e(this,Y)>=0&&n>e(this,m).seekThreshold){for(let b=0;b<e(this,k).length;b++){let u=e(this,k)[b];u.mode===1?e(this,C).releaseScroll(u.track):u.mode===5?e(this,C).releaseTop(u.track):u.mode===6&&e(this,C).releaseBottom(u.track),e(this,M).release(u);}c(this,k,[]),e(this,f).clear(),e(this,W)?.reset();}c(this,Y,i);let a=e(this,L)?Math.min((t-e(this,L))/1e3,.05):0;c(this,L,t);let l=o/8*e(this,m).speed,w=e(this,m).fontSize+e(this,m).padding*2+4,S=i*1e3,D=e(this,A).emitBatch(S);for(let b=0;b<D.length;b++)I(this,F,xt).call(this,D[b],i,l,w,o,s);let x=performance.now()/1e3,j=b=>{b.mode===1?e(this,C).releaseScroll(b.track):b.mode===5?e(this,C).releaseTop(b.track):b.mode===6&&e(this,C).releaseBottom(b.track),e(this,M).release(b);};e(this,k).length=e(this,A).compact(e(this,k),x,a,l,j),e(this,f).clear(),e(this,f).setGlobalAlpha(e(this,m).opacity);let G=e(this,f).devicePixelRatio,H=e(this,m).padding;for(let b=0;b<e(this,k).length;b++){let u=e(this,k)[b],T=u.bmp;if(!T)continue;if(!e(this,g).isAlive(T)){u.bmp=void 0;continue}let y=u.x|0,v=u.y|0,P=T.width,ut=T.height,dt=P/G,Q=ut/G,Ct=e(this,f).ctx;u.mode===1?Ct.drawImage(T,0,0,P,ut,y-H,v-Q/2|0,dt,Q):Ct.drawImage(T,0,0,P,ut,y-dt/2|0,v-Q/2|0,dt,Q);}I(this,F,yt).call(this),e(this,W)?.probe(i,e(this,A));});if(!(t.container instanceof HTMLElement))throw new TypeError("container must be an HTMLElement");if(!t.adapter)throw new TypeError("adapter is required");c(this,m,{...It,...t}),c(this,q,t.adapter),c(this,f,new et(t.container)),e(this,f).setSmoothing(e(this,m).smoothing),c(this,C,new it),c(this,M,new rt),c(this,g,new st(e(this,m).maxCache)),c(this,A,new at),t.dataSource&&c(this,W,new ht(t.dataSource,e(this,m).preBuffer,e(this,m).leadTime,e(this,m).seekThreshold,t.onError)),I(this,F,lt).call(this),c(this,_,new ot(e(this,m).fps,e(this,ct)));}get isDestroyed(){return e(this,p)}load(t){var i;e(this,p)||(e(this,M).releaseAll(e(this,k)),c(this,k,[]),e(this,g).clearAll(),e(this,W)?.reset(),e(this,A).load(t),(i=e(this,O))==null||i.call(this),c(this,O,null),I(this,F,yt).call(this));}send(t){if(e(this,p)||!e(this,m).enabled)return;let i=e(this,q).position,r=e(this,f).width,o=e(this,f).height;if(r===0||o===0)return;let s=r/8*e(this,m).speed,n=e(this,m).fontSize+e(this,m).padding*2+4,a={...t,time:i};I(this,F,xt).call(this,a,i,s,n,r,o,true);}clear(){e(this,p)||(e(this,M).releaseAll(e(this,k)),c(this,k,[]),e(this,A).clear(),e(this,g).clearAll(),e(this,f).clear());}resize(){if(e(this,p))return;e(this,f).updateDimensions()&&(e(this,g).setDpr(e(this,f).devicePixelRatio),e(this,g).invalidateTextCache(),I(this,F,lt).call(this));}destroy(){var t;e(this,p)||(c(this,p,true),e(this,_).stop(),(t=e(this,O))==null||t.call(this),e(this,W)?.destroy(),e(this,M).releaseAll(e(this,k)),c(this,k,[]),e(this,g).clearAll(),e(this,f).destroy());}setEnabled(t){e(this,p)||(e(this,m).enabled=t,t||e(this,f).clear());}setFps(t){e(this,p)||(e(this,m).fps=J(t,1,120),e(this,_).setFps(e(this,m).fps));}setArea(t){e(this,p)||(e(this,m).area=J(t,0,1),I(this,F,lt).call(this));}setOpacity(t){e(this,p)||(e(this,m).opacity=J(t,0,1));}setSpeed(t){e(this,p)||(e(this,m).speed=Math.max(.1,t));}setFontFamily(t){e(this,p)||(e(this,m).fontFamily=t,e(this,g).invalidateTextCache(),e(this,g).clearBitmaps());}setFontSize(t){e(this,p)||(e(this,m).fontSize=J(t,8,128),e(this,g).invalidateTextCache(),e(this,g).clearBitmaps());}setFontWeight(t){e(this,p)||(e(this,m).fontWeight=t,e(this,g).invalidateTextCache(),e(this,g).clearBitmaps());}setStrokeWidth(t){e(this,p)||(e(this,m).strokeWidth=Math.max(0,t),e(this,g).clearBitmaps());}setStrokeColor(t){e(this,p)||(e(this,m).strokeColor=t&16777215,e(this,g).clearBitmaps());}setPadding(t){e(this,p)||(e(this,m).padding=Math.max(0,t),e(this,g).clearBitmaps());}setDuration(t){e(this,p)||(e(this,m).duration=Math.max(.5,t));}setOverflow(t){e(this,p)||(e(this,m).overflow=t);}setMaxVisible(t){e(this,p)||(e(this,m).maxVisible=Math.max(0,t));}setMaxCache(t){e(this,p)||(e(this,m).maxCache=Math.max(10,t),e(this,g).setMaxCache(e(this,m).maxCache));}setPreCacheCount(t){e(this,p)||(e(this,m).preCacheCount=Math.max(0,t));}setSmoothing(t){e(this,p)||(e(this,m).smoothing=t,e(this,f).setSmoothing(t));}setWillChange(t){}setUseTextShadow(t){}};p=new WeakMap,m=new WeakMap,f=new WeakMap,C=new WeakMap,M=new WeakMap,g=new WeakMap,_=new WeakMap,A=new WeakMap,k=new WeakMap,L=new WeakMap,O=new WeakMap,q=new WeakMap,W=new WeakMap,Y=new WeakMap,ct=new WeakMap,F=new WeakSet,xt=function(t,i,r,o,s,n,a){let l=t.mode??1,w=t.text??"";if(!w)return;let S=t.color??16777215,D=t.font_size??e(this,m).fontSize,x=e(this,m),j=e(this,f).ctx,H=e(this,g).measure(w,x.fontFamily,D,x.fontWeight,j)+x.padding*2,b=D;if(!a&&x.maxVisible>0&&e(this,k).length>=x.maxVisible&&x.overflow==="drop")return;let u=null;if(l===1){if(u=e(this,C).acquireScroll(i,H,r,s),!u){if(x.overflow==="drop"&&!a)return;let v=Math.random()*e(this,C).scrollTrackCount|0;u={track:v,y:(v+.5)*o};}}else if(l===5){if(u=e(this,C).acquireTop(i,x.duration),!u){if(x.overflow==="drop"&&!a)return;let v=Math.random()*e(this,C).topTrackCount|0;u={track:v,y:(v+.5)*o};}}else if(l===6){if(u=e(this,C).acquireBottom(i,x.duration),!u){if(x.overflow==="drop"&&!a)return;let v=Math.random()*e(this,C).bottomTrackCount|0;u={track:v,y:n*x.area-(v+.5)*o};}}else if(u=e(this,C).acquireScroll(i,H,r,s),!u)if(a){let v=Math.random()*e(this,C).scrollTrackCount|0;u={track:v,y:(v+.5)*o};}else return;let T=e(this,g).getBitmap(w,D,S,x.strokeWidth,x.strokeColor,x.fontFamily,x.fontWeight,e(this,f).devicePixelRatio,x.padding),y=e(this,M).acquire();y.id=t.id,y.text=w,y.mode=l,y.color=S,y.fontSize=D,y.x=l===1?s:s/2,y.y=u.y,y.track=u.track,y.w=H,y.h=b,y.born=performance.now()/1e3,y.duration=x.duration,y.bmp=T,e(this,k).push(y);},yt=function(){if(e(this,O)||e(this,p))return;let{pool:t,cursor:i}=e(this,A).preCacheInfo(),r=e(this,m);c(this,O,wt(t,i,r.preCacheCount,o=>{let s=o.text??"",n=o.font_size??r.fontSize,a=o.color??16777215;e(this,g).measure(s,r.fontFamily,n,r.fontWeight,e(this,f).ctx);try{e(this,g).getBitmap(s,n,a,r.strokeWidth,r.strokeColor,r.fontFamily,r.fontWeight,e(this,f).devicePixelRatio,r.padding);}catch{}}));},lt=function(){let t=e(this,f).height;if(t===0)return;let i=e(this,m),r=i.fontSize+i.padding*2+4;e(this,C).resize(t,i.area,r);};function me(h,t){if(h!=="canvas")throw new TypeError("other engines are not available in canvas-only package");if(!(t.container instanceof HTMLElement))throw new TypeError("container must be an HTMLElement");if(t.container instanceof HTMLVideoElement)throw new TypeError('container cannot be a <video> element. Video uses a native rendering surface that hides child elements. Wrap the video in a <div> and use that as the container. Example: <div style="position:relative"><video .../><div id="overlay"></div></div>');return new mt(t)}export{tt as DanmakuMode,me as createEngine};//# sourceMappingURL=canvas.min.js.map
var wt=h=>{throw TypeError(h)};var ft=(h,t,i)=>t.has(h)||wt("Cannot "+i);var e=(h,t,i)=>(ft(h,t,"read from private field"),i?i.call(h):t.get(h)),p=(h,t,i)=>t.has(h)?wt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(h):t.set(h,i),u=(h,t,i,r)=>(ft(h,t,"write to private field"),t.set(h,i),i),I=(h,t,i)=>(ft(h,t,"access private method"),i);var bt=(h,t,i,r)=>({set _(o){u(h,t,o);},get _(){return e(h,t,r)}});var et=(r=>(r[r.Scroll=1]="Scroll",r[r.Top=5]="Top",r[r.Bottom=6]="Bottom",r))(et||{});var it=class{constructor(t){this.W=0;this.H=0;this.dpr=1;this.container=t;let i=document.createElement("canvas");i.style.position="absolute",i.style.inset="0",i.style.width="100%",i.style.height="100%",i.style.pointerEvents="none",t.appendChild(i),this.canvas=i,this.ctx=i.getContext("2d"),this.updateDimensions();}updateDimensions(){let t=window.devicePixelRatio||1,i=this.container.clientWidth,r=this.container.clientHeight;return i===0||r===0?false:(this.dpr=t,this.W=i,this.H=r,this.canvas.width=i*t,this.canvas.height=r*t,this.canvas.style.width=i+"px",this.canvas.style.height=r+"px",this.ctx.setTransform(t,0,0,t,0,0),true)}get width(){return this.W}get height(){return this.H}get devicePixelRatio(){return this.dpr}clear(){this.ctx.clearRect(0,0,this.W,this.H);}setSmoothing(t){this.ctx.imageSmoothingEnabled=t;}setGlobalAlpha(t){this.ctx.globalAlpha=t;}destroy(){this.canvas.remove();}};var rt=class{constructor(){this.scrollCount=0;this.scrollFree=[];this.scrollExit=new Float64Array(0);this.topCount=0;this.topFree=[];this.topExit=new Float64Array(0);this.bottomCount=0;this.bottomFree=[];this.bottomExit=new Float64Array(0);this.H=0;this.th=0;this.areaFraction=.75;}resize(t,i,r){this.H=t,this.th=r,this.areaFraction=i;let o=t*i,s=Math.max(1,Math.floor(o/r)),n=Math.max(1,Math.floor(o*.48/r));this.scrollCount=s,this.topCount=n,this.bottomCount=n,this.scrollExit=new Float64Array(s).fill(-1/0),this.topExit=new Float64Array(n).fill(-1/0),this.bottomExit=new Float64Array(n).fill(-1/0),this.scrollFree=Array.from({length:s},(a,l)=>l),this.topFree=Array.from({length:n},(a,l)=>l),this.bottomFree=Array.from({length:n},(a,l)=>l);}acquireScroll(t,i,r,o){let s=[];for(;this.scrollFree.length>0;){let a=this.scrollFree.pop();if(this.scrollExit[a]<=t){this.scrollExit[a]=t+i*1.2/r;for(let l of s)this.scrollFree.push(l);return {track:a,y:this.scrollY(a)}}s.push(a);}for(let a of s)this.scrollFree.push(a);let n=Math.random()*this.scrollCount|0;for(let a=0;a<this.scrollCount;a++){let l=(n+a)%this.scrollCount;if(this.scrollExit[l]<=t){this.scrollExit[l]=t+i*1.2/r;let w=this.scrollFree.indexOf(l);return w!==-1&&this.scrollFree.splice(w,1),{track:l,y:this.scrollY(l)}}}return null}releaseScroll(t){this.scrollExit[t]=-1/0,this.scrollFree.includes(t)||this.scrollFree.push(t);}acquireTop(t,i){let r=[];for(;this.topFree.length>0;){let s=this.topFree.pop();if(this.topExit[s]<=t){this.topExit[s]=t+i;for(let n of r)this.topFree.push(n);return {track:s,y:this.fixedY(s,true)}}r.push(s);}for(let s of r)this.topFree.push(s);let o=Math.random()*this.topCount|0;for(let s=0;s<this.topCount;s++){let n=(o+s)%this.topCount;if(this.topExit[n]<=t){this.topExit[n]=t+i;let a=this.topFree.indexOf(n);return a!==-1&&this.topFree.splice(a,1),{track:n,y:this.fixedY(n,true)}}}return null}releaseTop(t){this.topExit[t]=-1/0,this.topFree.includes(t)||this.topFree.push(t);}acquireBottom(t,i){let r=[];for(;this.bottomFree.length>0;){let s=this.bottomFree.pop();if(this.bottomExit[s]<=t){this.bottomExit[s]=t+i;for(let n of r)this.bottomFree.push(n);return {track:s,y:this.fixedY(s,false)}}r.push(s);}for(let s of r)this.bottomFree.push(s);let o=Math.random()*this.bottomCount|0;for(let s=0;s<this.bottomCount;s++){let n=(o+s)%this.bottomCount;if(this.bottomExit[n]<=t){this.bottomExit[n]=t+i;let a=this.bottomFree.indexOf(n);return a!==-1&&this.bottomFree.splice(a,1),{track:n,y:this.fixedY(n,false)}}}return null}releaseBottom(t){this.bottomExit[t]=-1/0,this.bottomFree.includes(t)||this.bottomFree.push(t);}get scrollTrackCount(){return this.scrollCount}get topTrackCount(){return this.topCount}get bottomTrackCount(){return this.bottomCount}scrollY(t){return (t+.5)*this.th}fixedY(t,i){return i?(t+.5)*this.th:this.H*this.areaFraction-(t+.5)*this.th}};var st=class{constructor(){this.pool=[];}acquire(){return this.pool.length>0?this.pool.pop():{}}release(t){this.pool.length<512&&(t.bmp=void 0,t.el=void 0,this.pool.push(t));}releaseAll(t){for(let i=0;i<t.length;i++)this.release(t[i]);}get size(){return this.pool.length}};function vt(h){return h<0||h>16777215||!Number.isFinite(h)?"#000000":"#"+h.toString(16).padStart(6,"0")}function gt({fontFamily:h,fontSize:t,fontWeight:i}){return `${i} ${t}px ${h}`}var ot=class{constructor(t=500){this.textWidths=new Map;this.bitmaps=new Map;this.aliveBitmaps=new Set;this.accessCounter=0;this.dpr=1;this.cachedFont="";this.fontFamily="";this.fontSize=0;this.fontWeight="";this.maxCache=t;}measure(t,i,r,o,s){let n=`${t}|${i}|${r}|${o}`,a=this.textWidths.get(n);if(a!==void 0)return a;s.font=gt({fontFamily:i,fontSize:r,fontWeight:o});let l=s.measureText(t).width;return this.textWidths.set(n,l),l}invalidateTextCache(){this.textWidths.clear();}getBitmap(t,i,r,o,s,n,a,l,w){let T=`${t}|${i}|${r}|${o}|${s}|${n}|${a}|${l}`,S=this.bitmaps.get(T);if(S)return S.accessId=++this.accessCounter,S.bitmap;(n!==this.fontFamily||i!==this.fontSize||a!==this.fontWeight)&&(this.fontFamily=n,this.fontSize=i,this.fontWeight=a,this.cachedFont=gt({fontFamily:n,fontSize:i,fontWeight:a}));let b=this.textWidths.get(`${t}|${n}|${i}|${a}`);if(b===void 0)throw new Error(`Text width not cached for "${t}". Call measure() first.`);let G=Math.ceil(b)+w*2,Q=i+w*2,A=G*l|0,z=Q*l|0,c=w*l,C=z/2,v=new OffscreenCanvas(A,z),g=v.getContext("2d");g.font=`${a} ${i*l}px ${n}`,g.lineWidth=o*l,g.lineJoin="round",g.textBaseline="middle",g.textAlign="left",g.strokeStyle=vt(s),g.strokeText(t,c,C),g.fillStyle=vt(r),g.fillText(t,c,C);let V=v.transferToImageBitmap();return this.bitmaps.set(T,{bitmap:V,accessId:++this.accessCounter}),this.aliveBitmaps.add(V),this.bitmaps.size>this.maxCache&&this.evictOne(),V}evictOne(){let t="",i=1/0;for(let[r,o]of this.bitmaps)o.accessId<i&&(i=o.accessId,t=r);if(t){let r=this.bitmaps.get(t);r&&(this.aliveBitmaps.delete(r.bitmap),r.bitmap.close(),this.bitmaps.delete(t));}}isAlive(t){return this.aliveBitmaps.has(t)}setMaxCache(t){for(this.maxCache=t;this.bitmaps.size>this.maxCache;)this.evictOne();}setDpr(t){this.dpr!==t&&(this.dpr=t,this.clearBitmaps());}clearBitmaps(){for(let[,t]of this.bitmaps)this.aliveBitmaps.delete(t.bitmap),t.bitmap.close();this.bitmaps.clear();}clearAll(){this.clearBitmaps(),this.textWidths.clear();}get bitmapCount(){return this.bitmaps.size}};var U,nt=class{constructor(t,i,r=true){this.rafId=0;this.lastFrameTime=-1;this.stopped=false;p(this,U,t=>{this.stopped||(this.tick(t),this.rafId=requestAnimationFrame(e(this,U)));});this.frameInterval=1e3/t,this.callback=i,r&&this.start();}start(){this.rafId!==0||this.stopped||(this.rafId=requestAnimationFrame(e(this,U)));}tick(t){if(this.stopped)return false;if(this.lastFrameTime<0)return this.lastFrameTime=t,this.callback(t),true;let i=t-this.lastFrameTime;return i>=this.frameInterval?(this.lastFrameTime=t-i%this.frameInterval,this.callback(t),true):false}setFps(t){this.frameInterval=1e3/t;}stop(){this.stopped=true,this.rafId!==0&&(cancelAnimationFrame(this.rafId),this.rafId=0);}};U=new WeakMap;function J(h,t,i){return h<t?t:h>i?i:h}function at(h,t,i,r=0,o=h.length){for(;r<o;){let s=r+o>>1;i(h[s])<=t?r=s+1:o=s;}return r}var ht=class{constructor(){this.pool=[];this.cursor=0;}load(t){this.pool=[...t].sort((i,r)=>i.time-r.time),this.cursor=0;}clear(){this.pool=[],this.cursor=0;}emitBatch(t){if(this.pool.length===0)return [];let i=this.cursor<this.pool.length?(this.pool[this.cursor]?.time??0)*1e3:1/0;if(t<i-200&&(this.cursor=at(this.pool,t,s=>(s.time??0)*1e3)),this.cursor>=this.pool.length)return [];let r=at(this.pool,t,s=>(s.time??0)*1e3);if(r<=this.cursor)return [];let o=this.pool.slice(this.cursor,r);return this.cursor=r,o}compact(t,i,r,o,s){let n=0;for(let a=0;a<t.length;a++){let l=t[a];if(l.mode===1){if(l.x-=o*r,l.x+l.w<-10){s(l);continue}}else if(i-l.born>=l.duration){s(l);continue}n!==a&&(t[n]=t[a]),n++;}return n}preCacheInfo(){return {pool:this.pool,cursor:this.cursor}}add(t){if(t.length===0)return;let i=new Set;for(let a=0;a<this.pool.length;a++)i.add(this.pool[a].id);let r=[...t].filter(a=>!i.has(a.id)).sort((a,l)=>a.time-l.time);if(r.length===0)return;let o=[],s=0,n=0;for(;s<this.pool.length&&n<r.length;)this.pool[s].time<=r[n].time?(o.push(this.pool[s]),s++):(o.push(r[n]),n++);for(;s<this.pool.length;)o.push(this.pool[s++]);for(;n<r.length;)o.push(r[n++]);this.pool=o;}evictBefore(t){if(this.pool.length===0)return;let i=at(this.pool,t*1e3-.1,r=>(r.time??0)*1e3);i!==0&&(this.pool.splice(0,i),this.cursor=Math.max(0,this.cursor-i));}};var xt=new Map;typeof window<"u"&&!window.requestIdleCallback&&(window.requestIdleCallback=function(h,t){let i=t?.timeout,r=Date.now(),o=0,s={didTimeout:false,timeRemaining:()=>Math.max(0,50-(Date.now()-r))};i!=null&&(o=setTimeout(()=>{s.didTimeout=true,r=Date.now(),h(s);},i));let n=requestAnimationFrame(()=>{i!=null&&clearTimeout(o),!s.didTimeout&&(r=Date.now(),h(s));}),a=Date.now()+Math.random();return xt.set(a,{rafId:n,timeoutId:o}),a},window.cancelIdleCallback=function(h){let t=xt.get(h);t&&(cancelAnimationFrame(t.rafId),t.timeoutId&&clearTimeout(t.timeoutId),xt.delete(h));});function It(h,t,i,r){let o=0,s=t;function n(a){let l=Math.min(t+i,h.length),w=0;for(;s<l&&(a.timeRemaining()>1||w<5);){let T=h[s];T&&r(T),s++,w++;}s<l&&(o=requestIdleCallback(n,{timeout:2e3}));}return o=requestIdleCallback(n,{timeout:2e3}),()=>cancelIdleCallback(o)}var Ft={enabled:true,fps:60,area:.75,fontFamily:"sans-serif",fontSize:25,fontWeight:"bold",opacity:1,padding:4,strokeWidth:1.25,strokeColor:0,speed:1,seekThreshold:.2,duration:4,overflow:"drop",maxVisible:0,maxCache:500,preCacheCount:50,smoothing:true,willChange:true,useTextShadow:true,preBuffer:60,leadTime:0};var X,Z,q,K,N,D,H,B,P,R,Dt,Tt,St,lt=class{constructor(t,i,r,o,s){p(this,R);p(this,X);p(this,Z);p(this,q);p(this,K);p(this,N);p(this,D,[]);p(this,H,0);p(this,B,null);p(this,P,-1);u(this,X,t),u(this,Z,Math.max(1,i)),u(this,q,Math.max(0,r)),u(this,K,Math.max(.5,o*2.5)),u(this,N,s);}probe(t,i){if(e(this,P)>=0&&Math.abs(t-e(this,P))>e(this,K)&&this.reset(),u(this,P,t),e(this,q)>0){let s=t-e(this,q);i.evictBefore(s),u(this,D,e(this,D).filter(n=>n.end>s));}if(e(this,B))return;let r=t+e(this,Z),o=I(this,R,Dt).call(this,t,r);o&&I(this,R,Tt).call(this,o.start,o.end,i);}reset(){bt(this,H)._++,u(this,B,null),u(this,D,[]),u(this,P,-1);}destroy(){this.reset();}};X=new WeakMap,Z=new WeakMap,q=new WeakMap,K=new WeakMap,N=new WeakMap,D=new WeakMap,H=new WeakMap,B=new WeakMap,P=new WeakMap,R=new WeakSet,Dt=function(t,i){let r=t;for(let o of e(this,D))if(o.start<=r&&r<o.end){if(r=o.end,r>=i)return null}else if(o.start>r)return {start:r,end:Math.min(o.start,i)};return r<i?{start:r,end:i}:null},Tt=function(t,i,r){let o=++bt(this,H)._;u(this,B,e(this,X).fetch(t,i).then(s=>{o===e(this,H)&&(u(this,B,null),s.length>0&&r.add(s),I(this,R,St).call(this,{start:t,end:i}));}).catch(s=>{var n;o===e(this,H)&&(u(this,B,null),(n=e(this,N))==null||n.call(this,s instanceof Error?s:new Error(String(s))));}));},St=function(t){e(this,D).push(t),e(this,D).sort((r,o)=>r.start-o.start);let i=[];for(let r of e(this,D)){let o=i[i.length-1];o&&o.end>=r.start?o.end=Math.max(o.end,r.end):i.push({...r});}u(this,D,i);};var d,m,f,y,E,x,L,M,k,Y,O,$,W,j,ct,F,yt,Ct,_,mt=class{constructor(t){p(this,F);p(this,d,false);p(this,m);p(this,f);p(this,y);p(this,E);p(this,x);p(this,L);p(this,M);p(this,k,[]);p(this,Y,0);p(this,O,null);p(this,$);p(this,W,null);p(this,j,-1);p(this,ct,t=>{let i=e(this,$).position,r=e(this,$).paused,o=e(this,f).width,s=e(this,f).height;if(!e(this,m).enabled||o===0){e(this,f).clear();return}if(r)return;let n=Math.abs(i-e(this,j));if(e(this,j)>=0&&n>e(this,m).seekThreshold){for(let c=0;c<e(this,k).length;c++){let C=e(this,k)[c];C.mode===1?e(this,y).releaseScroll(C.track):C.mode===5?e(this,y).releaseTop(C.track):C.mode===6&&e(this,y).releaseBottom(C.track),e(this,E).release(C);}u(this,k,[]),e(this,f).clear(),e(this,W)?.reset();}u(this,j,i);let a=e(this,Y)?Math.min((t-e(this,Y))/1e3,.05):0;u(this,Y,t);let l=o/8*e(this,m).speed,w=Math.max(2,Math.ceil(e(this,m).fontSize*.2)),T=e(this,m).fontSize+e(this,m).padding*2+w,S=i*1e3,b=e(this,M).emitBatch(S);for(let c=0;c<b.length;c++)I(this,F,yt).call(this,b[c],i,l,T,o,s);let G=performance.now()/1e3,Q=c=>{c.mode===1?e(this,y).releaseScroll(c.track):c.mode===5?e(this,y).releaseTop(c.track):c.mode===6&&e(this,y).releaseBottom(c.track),e(this,E).release(c);};e(this,k).length=e(this,M).compact(e(this,k),G,a,l,Q),e(this,f).clear(),e(this,f).setGlobalAlpha(e(this,m).opacity);let A=e(this,f).devicePixelRatio,z=e(this,m).padding;for(let c=0;c<e(this,k).length;c++){let C=e(this,k)[c],v=C.bmp;if(!v)continue;if(!e(this,x).isAlive(v)){C.bmp=void 0;continue}let g=C.x|0,V=C.y|0,ut=v.width,pt=v.height,dt=ut/A,tt=pt/A,kt=e(this,f).ctx;C.mode===1?kt.drawImage(v,0,0,ut,pt,g-z,V-tt/2|0,dt,tt):kt.drawImage(v,0,0,ut,pt,g-dt/2|0,V-tt/2|0,dt,tt);}I(this,F,Ct).call(this),e(this,W)?.probe(i,e(this,M));});if(!(t.container instanceof HTMLElement))throw new TypeError("container must be an HTMLElement");if(!t.adapter)throw new TypeError("adapter is required");u(this,m,{...Ft,...t}),u(this,$,t.adapter),u(this,f,new it(t.container)),e(this,f).setSmoothing(e(this,m).smoothing),u(this,y,new rt),u(this,E,new st),u(this,x,new ot(e(this,m).maxCache)),u(this,M,new ht),t.dataSource&&u(this,W,new lt(t.dataSource,e(this,m).preBuffer,e(this,m).leadTime,e(this,m).seekThreshold,t.onError)),I(this,F,_).call(this),u(this,L,new nt(e(this,m).fps,e(this,ct)));}get isDestroyed(){return e(this,d)}load(t){var i;e(this,d)||(e(this,E).releaseAll(e(this,k)),u(this,k,[]),e(this,x).clearAll(),e(this,W)?.reset(),e(this,M).load(t),(i=e(this,O))==null||i.call(this),u(this,O,null),I(this,F,Ct).call(this));}send(t){if(e(this,d)||!e(this,m).enabled)return;let i=e(this,$).position,r=e(this,f).width,o=e(this,f).height;if(r===0||o===0)return;let s=r/8*e(this,m).speed,n=Math.max(2,Math.ceil(e(this,m).fontSize*.2)),a=e(this,m).fontSize+e(this,m).padding*2+n,l={...t,time:i};I(this,F,yt).call(this,l,i,s,a,r,o,true);}clear(){e(this,d)||(e(this,E).releaseAll(e(this,k)),u(this,k,[]),e(this,M).clear(),e(this,x).clearAll(),e(this,f).clear());}resize(){if(e(this,d))return;e(this,f).updateDimensions()&&(e(this,x).setDpr(e(this,f).devicePixelRatio),e(this,x).invalidateTextCache(),I(this,F,_).call(this));}destroy(){var t;e(this,d)||(u(this,d,true),e(this,L).stop(),(t=e(this,O))==null||t.call(this),e(this,W)?.destroy(),e(this,E).releaseAll(e(this,k)),u(this,k,[]),e(this,x).clearAll(),e(this,f).destroy());}setEnabled(t){e(this,d)||(e(this,m).enabled=t,t||e(this,f).clear());}setFps(t){e(this,d)||(e(this,m).fps=J(t,1,120),e(this,L).setFps(e(this,m).fps));}setArea(t){e(this,d)||(e(this,m).area=J(t,0,1),I(this,F,_).call(this));}setOpacity(t){e(this,d)||(e(this,m).opacity=J(t,0,1));}setSpeed(t){e(this,d)||(e(this,m).speed=Math.max(.1,t));}setFontFamily(t){e(this,d)||(e(this,m).fontFamily=t,e(this,x).invalidateTextCache(),e(this,x).clearBitmaps());}setFontSize(t){e(this,d)||(e(this,m).fontSize=J(t,8,128),e(this,x).invalidateTextCache(),e(this,x).clearBitmaps(),I(this,F,_).call(this));}setFontWeight(t){e(this,d)||(e(this,m).fontWeight=t,e(this,x).invalidateTextCache(),e(this,x).clearBitmaps());}setStrokeWidth(t){e(this,d)||(e(this,m).strokeWidth=Math.max(0,t),e(this,x).clearBitmaps());}setStrokeColor(t){e(this,d)||(e(this,m).strokeColor=t&16777215,e(this,x).clearBitmaps());}setPadding(t){e(this,d)||(e(this,m).padding=Math.max(0,t),e(this,x).clearBitmaps(),I(this,F,_).call(this));}setDuration(t){e(this,d)||(e(this,m).duration=Math.max(.5,t));}setOverflow(t){e(this,d)||(e(this,m).overflow=t);}setMaxVisible(t){e(this,d)||(e(this,m).maxVisible=Math.max(0,t));}setMaxCache(t){e(this,d)||(e(this,m).maxCache=Math.max(10,t),e(this,x).setMaxCache(e(this,m).maxCache));}setPreCacheCount(t){e(this,d)||(e(this,m).preCacheCount=Math.max(0,t));}setSmoothing(t){e(this,d)||(e(this,m).smoothing=t,e(this,f).setSmoothing(t));}setWillChange(t){}setUseTextShadow(t){}};d=new WeakMap,m=new WeakMap,f=new WeakMap,y=new WeakMap,E=new WeakMap,x=new WeakMap,L=new WeakMap,M=new WeakMap,k=new WeakMap,Y=new WeakMap,O=new WeakMap,$=new WeakMap,W=new WeakMap,j=new WeakMap,ct=new WeakMap,F=new WeakSet,yt=function(t,i,r,o,s,n,a){let l=t.mode??1,w=t.text??"";if(!w)return;let T=t.color??16777215,S=t.font_size??e(this,m).fontSize,b=e(this,m),G=e(this,f).ctx,A=e(this,x).measure(w,b.fontFamily,S,b.fontWeight,G)+b.padding*2,z=S;if(!a&&b.maxVisible>0&&e(this,k).length>=b.maxVisible&&b.overflow==="drop")return;let c=null;if(l===1){if(c=e(this,y).acquireScroll(i,A,r,s),!c){if(b.overflow==="drop"&&!a)return;let g=Math.random()*e(this,y).scrollTrackCount|0;c={track:g,y:(g+.5)*o};}}else if(l===5){if(c=e(this,y).acquireTop(i,b.duration),!c){if(b.overflow==="drop"&&!a)return;let g=Math.random()*e(this,y).topTrackCount|0;c={track:g,y:(g+.5)*o};}}else if(l===6){if(c=e(this,y).acquireBottom(i,b.duration),!c){if(b.overflow==="drop"&&!a)return;let g=Math.random()*e(this,y).bottomTrackCount|0;c={track:g,y:n*b.area-(g+.5)*o};}}else if(c=e(this,y).acquireScroll(i,A,r,s),!c)if(a){let g=Math.random()*e(this,y).scrollTrackCount|0;c={track:g,y:(g+.5)*o};}else return;let C=e(this,x).getBitmap(w,S,T,b.strokeWidth,b.strokeColor,b.fontFamily,b.fontWeight,e(this,f).devicePixelRatio,b.padding),v=e(this,E).acquire();v.id=t.id,v.text=w,v.mode=l,v.color=T,v.fontSize=S,v.x=l===1?s:s/2,v.y=c.y,v.track=c.track,v.w=A,v.h=z,v.born=performance.now()/1e3,v.duration=b.duration,v.bmp=C,e(this,k).push(v);},Ct=function(){if(e(this,O)||e(this,d))return;let{pool:t,cursor:i}=e(this,M).preCacheInfo(),r=e(this,m);u(this,O,It(t,i,r.preCacheCount,o=>{let s=o.text??"",n=o.font_size??r.fontSize,a=o.color??16777215;e(this,x).measure(s,r.fontFamily,n,r.fontWeight,e(this,f).ctx);try{e(this,x).getBitmap(s,n,a,r.strokeWidth,r.strokeColor,r.fontFamily,r.fontWeight,e(this,f).devicePixelRatio,r.padding);}catch{}}));},_=function(){let t=e(this,f).height;if(t===0)return;let i=e(this,m),r=Math.max(2,Math.ceil(i.fontSize*.2)),o=i.fontSize+i.padding*2+r;e(this,y).resize(t,i.area,o);};function ce(h,t){if(h!=="canvas")throw new TypeError("other engines are not available in canvas-only package");if(!(t.container instanceof HTMLElement))throw new TypeError("container must be an HTMLElement");if(t.container instanceof HTMLVideoElement)throw new TypeError('container cannot be a <video> element. Video uses a native rendering surface that hides child elements. Wrap the video in a <div> and use that as the container. Example: <div style="position:relative"><video .../><div id="overlay"></div></div>');return new mt(t)}export{et as DanmakuMode,ce as createEngine};//# sourceMappingURL=canvas.min.js.map
//# sourceMappingURL=canvas.min.js.map

@@ -689,6 +689,3 @@ var __typeError = (msg) => {

}
if (paused) {
__privateSet(this, _lastPos, -1);
return;
}
if (paused) return;
const posJump = Math.abs(pos - __privateGet(this, _lastPos));

@@ -713,3 +710,4 @@ if (__privateGet(this, _lastPos) >= 0 && posJump > __privateGet(this, _config).seekThreshold) {

const scrollSpeed = W / 8 * __privateGet(this, _config).speed;
const th = __privateGet(this, _config).fontSize + __privateGet(this, _config).padding * 2 + 4;
const gap = Math.max(2, Math.ceil(__privateGet(this, _config).fontSize * 0.2));
const th = __privateGet(this, _config).fontSize + __privateGet(this, _config).padding * 2 + gap;
const posMs = pos * 1e3;

@@ -790,3 +788,4 @@ const batch = __privateGet(this, _scheduler).emitBatch(posMs);

const scrollSpeed = W / 8 * __privateGet(this, _config).speed;
const th = __privateGet(this, _config).fontSize + __privateGet(this, _config).padding * 2 + 4;
const gap = Math.max(2, Math.ceil(__privateGet(this, _config).fontSize * 0.2));
const th = __privateGet(this, _config).fontSize + __privateGet(this, _config).padding * 2 + gap;
const sent = { ...item, time: pos };

@@ -847,3 +846,5 @@ __privateMethod(this, _DOMEngine_instances, emit_fn).call(this, sent, pos, scrollSpeed, th, W, H, true);

setFontSize(v) {
if (__privateGet(this, _destroyed)) return;
__privateGet(this, _config).fontSize = clamp(v, 8, 128);
__privateMethod(this, _DOMEngine_instances, resizeTracks_fn).call(this);
}

@@ -860,3 +861,5 @@ setFontWeight(v) {

setPadding(v) {
if (__privateGet(this, _destroyed)) return;
__privateGet(this, _config).padding = Math.max(0, v);
__privateMethod(this, _DOMEngine_instances, resizeTracks_fn).call(this);
}

@@ -953,3 +956,3 @@ setDuration(v) {

const font = buildDomFont(cfg.fontFamily, fs, cfg.fontWeight);
const textShadow = cfg.useTextShadow ? buildTextShadow(cfg.strokeWidth, toCss(cfg.strokeColor)) : "none";
const textShadow = cfg.useTextShadow ? buildTextShadow(cfg.strokeWidth * 0.7, toCss(cfg.strokeColor)) : "none";
const willChange = cfg.willChange ? "transform" : "auto";

@@ -995,3 +998,4 @@ const el = __privateGet(this, _pool).acquire();

const cfg = __privateGet(this, _config);
const th = cfg.fontSize + cfg.padding * 2 + 4;
const gap = Math.max(2, Math.ceil(cfg.fontSize * 0.2));
const th = cfg.fontSize + cfg.padding * 2 + gap;
__privateGet(this, _tracks).resize(H, cfg.area, th);

@@ -998,0 +1002,0 @@ };

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

var mt=s=>{throw TypeError(s)};var ot=(s,t,e)=>t.has(s)||mt("Cannot "+e);var r=(s,t,e)=>(ot(s,t,"read from private field"),e?e.call(s):t.get(s)),d=(s,t,e)=>t.has(s)?mt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(s):t.set(s,e),u=(s,t,e,i)=>(ot(s,t,"write to private field"),t.set(s,e),e),S=(s,t,e)=>(ot(s,t,"access private method"),e);var nt=(s,t,e,i)=>({set _(n){u(s,t,n);},get _(){return r(s,t,i)}});var U=(i=>(i[i.Scroll=1]="Scroll",i[i.Top=5]="Top",i[i.Bottom=6]="Bottom",i))(U||{});function ut(s,t){let e=s;return [`-${e}px -${e}px 0 ${t}`,`0px -${e}px 0 ${t}`,`${e}px -${e}px 0 ${t}`,`-${e}px 0px 0 ${t}`,`${e}px 0px 0 ${t}`,`-${e}px ${e}px 0 ${t}`,`0px ${e}px 0 ${t}`,`${e}px ${e}px 0 ${t}`].join(",")}function pt(s,t,e){return `${e} ${t}px ${s}`}var X=class{constructor(t){this.container=t;let e=document.createElement("div");e.style.position="absolute",e.style.inset="0",e.style.overflow="hidden",e.style.pointerEvents="none",e.style.userSelect="none",t.appendChild(e),this.root=e;}get width(){return this.container.clientWidth}get height(){return this.container.clientHeight}createElement(t){let e=document.createElement("div");return e.style.position="absolute",e.style.left="0",e.style.top="0",e.style.whiteSpace="nowrap",e.style.font=t.font,e.style.color=t.fillColor,e.style.textShadow=t.textShadow,e.style.willChange=t.willChange,e.style.pointerEvents="none",e.style.userSelect="none",e}configureElement(t,e,i){t.textContent=e,t.style.font=i.font,t.style.color=i.fillColor,t.style.textShadow=i.textShadow,t.style.willChange=i.willChange;}positionElement(t,e,i,n,o){let a=Math.round(e),l=Math.round(i-o/2);n===1?t.style.transform=`translate3d(${a}px, ${l}px, 0)`:t.style.transform=`translate3d(${a}px, ${l}px, 0) translateX(-50%)`;}hideElement(t){t.style.display="none";}showElement(t){t.style.display="";}appendElement(t){this.root.appendChild(t);}removeElement(t){t.parentNode===this.root&&this.root.removeChild(t);}destroy(){this.root.remove();}};var Z=class{constructor(){this.pool=[];}acquire(){return this.pool.length>0?this.pool.pop():document.createElement("div")}release(t){this.pool.length<512&&(t.style.display="none",t.parentNode&&t.parentNode.removeChild(t),t.style.transform="",t.textContent="",this.pool.push(t));}releaseAll(t){for(let e=0;e<t.length;e++)this.release(t[e]);}get size(){return this.pool.length}};var G=class{constructor(){this.scrollCount=0;this.scrollFree=[];this.scrollExit=new Float64Array(0);this.topCount=0;this.topFree=[];this.topExit=new Float64Array(0);this.bottomCount=0;this.bottomFree=[];this.bottomExit=new Float64Array(0);this.H=0;this.th=0;this.areaFraction=.75;}resize(t,e,i){this.H=t,this.th=i,this.areaFraction=e;let n=t*e,o=Math.max(1,Math.floor(n/i)),a=Math.max(1,Math.floor(n*.48/i));this.scrollCount=o,this.topCount=a,this.bottomCount=a,this.scrollExit=new Float64Array(o).fill(-1/0),this.topExit=new Float64Array(a).fill(-1/0),this.bottomExit=new Float64Array(a).fill(-1/0),this.scrollFree=Array.from({length:o},(l,m)=>m),this.topFree=Array.from({length:a},(l,m)=>m),this.bottomFree=Array.from({length:a},(l,m)=>m);}acquireScroll(t,e,i,n){let o=[];for(;this.scrollFree.length>0;){let l=this.scrollFree.pop();if(this.scrollExit[l]<=t){this.scrollExit[l]=t+e*1.2/i;for(let m of o)this.scrollFree.push(m);return {track:l,y:this.scrollY(l)}}o.push(l);}for(let l of o)this.scrollFree.push(l);let a=Math.random()*this.scrollCount|0;for(let l=0;l<this.scrollCount;l++){let m=(a+l)%this.scrollCount;if(this.scrollExit[m]<=t){this.scrollExit[m]=t+e*1.2/i;let F=this.scrollFree.indexOf(m);return F!==-1&&this.scrollFree.splice(F,1),{track:m,y:this.scrollY(m)}}}return null}releaseScroll(t){this.scrollExit[t]=-1/0,this.scrollFree.includes(t)||this.scrollFree.push(t);}acquireTop(t,e){let i=[];for(;this.topFree.length>0;){let o=this.topFree.pop();if(this.topExit[o]<=t){this.topExit[o]=t+e;for(let a of i)this.topFree.push(a);return {track:o,y:this.fixedY(o,true)}}i.push(o);}for(let o of i)this.topFree.push(o);let n=Math.random()*this.topCount|0;for(let o=0;o<this.topCount;o++){let a=(n+o)%this.topCount;if(this.topExit[a]<=t){this.topExit[a]=t+e;let l=this.topFree.indexOf(a);return l!==-1&&this.topFree.splice(l,1),{track:a,y:this.fixedY(a,true)}}}return null}releaseTop(t){this.topExit[t]=-1/0,this.topFree.includes(t)||this.topFree.push(t);}acquireBottom(t,e){let i=[];for(;this.bottomFree.length>0;){let o=this.bottomFree.pop();if(this.bottomExit[o]<=t){this.bottomExit[o]=t+e;for(let a of i)this.bottomFree.push(a);return {track:o,y:this.fixedY(o,false)}}i.push(o);}for(let o of i)this.bottomFree.push(o);let n=Math.random()*this.bottomCount|0;for(let o=0;o<this.bottomCount;o++){let a=(n+o)%this.bottomCount;if(this.bottomExit[a]<=t){this.bottomExit[a]=t+e;let l=this.bottomFree.indexOf(a);return l!==-1&&this.bottomFree.splice(l,1),{track:a,y:this.fixedY(a,false)}}}return null}releaseBottom(t){this.bottomExit[t]=-1/0,this.bottomFree.includes(t)||this.bottomFree.push(t);}get scrollTrackCount(){return this.scrollCount}get topTrackCount(){return this.topCount}get bottomTrackCount(){return this.bottomCount}scrollY(t){return (t+.5)*this.th}fixedY(t,e){return e?(t+.5)*this.th:this.H*this.areaFraction-(t+.5)*this.th}};var V,J=class{constructor(t,e,i=true){this.rafId=0;this.lastFrameTime=-1;this.stopped=false;d(this,V,t=>{this.stopped||(this.tick(t),this.rafId=requestAnimationFrame(r(this,V)));});this.frameInterval=1e3/t,this.callback=e,i&&this.start();}start(){this.rafId!==0||this.stopped||(this.rafId=requestAnimationFrame(r(this,V)));}tick(t){if(this.stopped)return false;if(this.lastFrameTime<0)return this.lastFrameTime=t,this.callback(t),true;let e=t-this.lastFrameTime;return e>=this.frameInterval?(this.lastFrameTime=t-e%this.frameInterval,this.callback(t),true):false}setFps(t){this.frameInterval=1e3/t;}stop(){this.stopped=true,this.rafId!==0&&(cancelAnimationFrame(this.rafId),this.rafId=0);}};V=new WeakMap;function W(s,t,e){return s<t?t:s>e?e:s}function K(s,t,e,i=0,n=s.length){for(;i<n;){let o=i+n>>1;e(s[o])<=t?i=o+1:n=o;}return i}var Q=class{constructor(){this.pool=[];this.cursor=0;}load(t){this.pool=[...t].sort((e,i)=>e.time-i.time),this.cursor=0;}clear(){this.pool=[],this.cursor=0;}emitBatch(t){if(this.pool.length===0)return [];let e=this.cursor<this.pool.length?(this.pool[this.cursor]?.time??0)*1e3:1/0;if(t<e-200&&(this.cursor=K(this.pool,t,o=>(o.time??0)*1e3)),this.cursor>=this.pool.length)return [];let i=K(this.pool,t,o=>(o.time??0)*1e3);if(i<=this.cursor)return [];let n=this.pool.slice(this.cursor,i);return this.cursor=i,n}compact(t,e,i,n,o){let a=0;for(let l=0;l<t.length;l++){let m=t[l];if(m.mode===1){if(m.x-=n*i,m.x+m.w<-10){o(m);continue}}else if(e-m.born>=m.duration){o(m);continue}a!==l&&(t[a]=t[l]),a++;}return a}preCacheInfo(){return {pool:this.pool,cursor:this.cursor}}add(t){if(t.length===0)return;let e=new Set;for(let l=0;l<this.pool.length;l++)e.add(this.pool[l].id);let i=[...t].filter(l=>!e.has(l.id)).sort((l,m)=>l.time-m.time);if(i.length===0)return;let n=[],o=0,a=0;for(;o<this.pool.length&&a<i.length;)this.pool[o].time<=i[a].time?(n.push(this.pool[o]),o++):(n.push(i[a]),a++);for(;o<this.pool.length;)n.push(this.pool[o++]);for(;a<i.length;)n.push(i[a++]);this.pool=n;}evictBefore(t){if(this.pool.length===0)return;let e=K(this.pool,t*1e3-.1,i=>(i.time??0)*1e3);e!==0&&(this.pool.splice(0,e),this.cursor=Math.max(0,this.cursor-e));}};var dt={enabled:true,fps:60,area:.75,fontFamily:"sans-serif",fontSize:25,fontWeight:"bold",opacity:1,padding:4,strokeWidth:1.25,strokeColor:0,speed:1,seekThreshold:.2,duration:4,overflow:"drop",maxVisible:0,maxCache:500,preCacheCount:50,smoothing:true,willChange:true,useTextShadow:true,preBuffer:60,leadTime:0};var q,P,B,Y,j,w,$,T,L,M,ft,ct,bt,tt=class{constructor(t,e,i,n,o){d(this,M);d(this,q);d(this,P);d(this,B);d(this,Y);d(this,j);d(this,w,[]);d(this,$,0);d(this,T,null);d(this,L,-1);u(this,q,t),u(this,P,Math.max(1,e)),u(this,B,Math.max(0,i)),u(this,Y,Math.max(.5,n*2.5)),u(this,j,o);}probe(t,e){if(r(this,L)>=0&&Math.abs(t-r(this,L))>r(this,Y)&&this.reset(),u(this,L,t),r(this,B)>0){let o=t-r(this,B);e.evictBefore(o),u(this,w,r(this,w).filter(a=>a.end>o));}if(r(this,T))return;let i=t+r(this,P),n=S(this,M,ft).call(this,t,i);n&&S(this,M,ct).call(this,n.start,n.end,e);}reset(){nt(this,$)._++,u(this,T,null),u(this,w,[]),u(this,L,-1);}destroy(){this.reset();}};q=new WeakMap,P=new WeakMap,B=new WeakMap,Y=new WeakMap,j=new WeakMap,w=new WeakMap,$=new WeakMap,T=new WeakMap,L=new WeakMap,M=new WeakSet,ft=function(t,e){let i=t;for(let n of r(this,w))if(n.start<=i&&i<n.end){if(i=n.end,i>=e)return null}else if(n.start>i)return {start:i,end:Math.min(n.start,e)};return i<e?{start:i,end:e}:null},ct=function(t,e,i){let n=++nt(this,$)._;u(this,T,r(this,q).fetch(t,e).then(o=>{n===r(this,$)&&(u(this,T,null),o.length>0&&i.add(o),S(this,M,bt).call(this,{start:t,end:e}));}).catch(o=>{var a;n===r(this,$)&&(u(this,T,null),(a=r(this,j))==null||a.call(this,o instanceof Error?o:new Error(String(o))));}));},bt=function(t){r(this,w).push(t),r(this,w).sort((i,n)=>i.start-n.start);let e=[];for(let i of r(this,w)){let n=e[e.length-1];n&&n.end>=i.start?n.end=Math.max(n.end,i.end):e.push({...i});}u(this,w,e);};function st(s){return s<0||s>16777215||!Number.isFinite(s)?"#000000":"#"+s.toString(16).padStart(6,"0")}function yt({fontFamily:s,fontSize:t,fontWeight:e}){return `${e} ${t}px ${s}`}var at=null;function St(){if(!at){let s=document.createElement("canvas");s.width=s.height=1,at=s.getContext("2d");}return at}function vt(s,t,e,i){let n=St();return n.font=yt({fontFamily:t,fontSize:e,fontWeight:i}),n.measureText(s).width}var x,h,y,b,k,R,C,v,z,H,I,O,it,D,lt,et,rt=class{constructor(t){d(this,D);d(this,x,false);d(this,h);d(this,y);d(this,b);d(this,k);d(this,R);d(this,C);d(this,v,[]);d(this,z,0);d(this,H);d(this,I,null);d(this,O,-1);d(this,it,t=>{let e=r(this,H).position,i=r(this,H).paused,n=r(this,y).width,o=r(this,y).height;if(!r(this,h).enabled||n===0)return;if(i){u(this,O,-1);return}let a=Math.abs(e-r(this,O));if(r(this,O)>=0&&a>r(this,h).seekThreshold){for(let f=0;f<r(this,v).length;f++){let p=r(this,v)[f];p.el&&(r(this,y).removeElement(p.el),r(this,k).release(p.el)),p.mode===1?r(this,b).releaseScroll(p.track):p.mode===5?r(this,b).releaseTop(p.track):p.mode===6&&r(this,b).releaseBottom(p.track);}u(this,v,[]),r(this,I)?.reset();}u(this,O,e);let l=r(this,z)?Math.min((t-r(this,z))/1e3,.05):0;u(this,z,t);let m=n/8*r(this,h).speed,F=r(this,h).fontSize+r(this,h).padding*2+4,N=e*1e3,A=r(this,C).emitBatch(N);for(let f=0;f<A.length;f++)S(this,D,lt).call(this,A[f],e,m,F,n,o);let c=performance.now()/1e3,ht=f=>{f.el&&(r(this,y).hideElement(f.el),r(this,y).removeElement(f.el),r(this,k).release(f.el),f.el=void 0),f.mode===1?r(this,b).releaseScroll(f.track):f.mode===5?r(this,b).releaseTop(f.track):f.mode===6&&r(this,b).releaseBottom(f.track);},_=r(this,C).compact(r(this,v),c,l,m,ht);r(this,v).length=_;for(let f=0;f<r(this,v).length;f++){let p=r(this,v)[f];p.el&&r(this,y).positionElement(p.el,p.x,p.y,p.mode,p.h);}r(this,I)?.probe(e,r(this,C));});if(!(t.container instanceof HTMLElement))throw new TypeError("container must be an HTMLElement");if(!t.adapter)throw new TypeError("adapter is required");u(this,h,{...dt,...t}),u(this,H,t.adapter),u(this,y,new X(t.container)),u(this,b,new G),u(this,k,new Z),u(this,C,new Q),t.dataSource&&u(this,I,new tt(t.dataSource,r(this,h).preBuffer,r(this,h).leadTime,r(this,h).seekThreshold,t.onError)),S(this,D,et).call(this),u(this,R,new J(r(this,h).fps,r(this,it)));}get isDestroyed(){return r(this,x)}load(t){r(this,x)||(r(this,k).releaseAll(r(this,v).map(e=>e.el).filter(Boolean)),u(this,v,[]),r(this,I)?.reset(),r(this,C).load(t));}send(t){if(r(this,x)||!r(this,h).enabled)return;let e=r(this,H).position,i=r(this,y).width,n=r(this,y).height;if(i===0||n===0)return;let o=i/8*r(this,h).speed,a=r(this,h).fontSize+r(this,h).padding*2+4,l={...t,time:e};S(this,D,lt).call(this,l,e,o,a,i,n,true);}clear(){r(this,x)||(r(this,k).releaseAll(r(this,v).map(t=>t.el).filter(Boolean)),u(this,v,[]),r(this,C).clear());}resize(){r(this,x)||r(this,y).width>0&&S(this,D,et).call(this);}destroy(){r(this,x)||(u(this,x,true),r(this,R).stop(),r(this,I)?.destroy(),r(this,k).releaseAll(r(this,v).map(t=>t.el).filter(Boolean)),u(this,v,[]),r(this,y).destroy());}setEnabled(t){r(this,x)||(r(this,h).enabled=t,r(this,y).root.style.display=t?"":"none");}setFps(t){r(this,x)||(r(this,h).fps=W(t,1,120),r(this,R).setFps(r(this,h).fps));}setArea(t){r(this,x)||(r(this,h).area=W(t,0,1),S(this,D,et).call(this));}setOpacity(t){r(this,x)||(r(this,h).opacity=W(t,0,1),r(this,y).root.style.opacity=String(r(this,h).opacity));}setSpeed(t){r(this,x)||(r(this,h).speed=Math.max(.1,t));}setFontFamily(t){r(this,h).fontFamily=t;}setFontSize(t){r(this,h).fontSize=W(t,8,128);}setFontWeight(t){r(this,h).fontWeight=t;}setStrokeWidth(t){r(this,h).strokeWidth=Math.max(0,t);}setStrokeColor(t){r(this,h).strokeColor=t&16777215;}setPadding(t){r(this,h).padding=Math.max(0,t);}setDuration(t){r(this,h).duration=Math.max(.5,t);}setOverflow(t){r(this,h).overflow=t;}setMaxVisible(t){r(this,h).maxVisible=Math.max(0,t);}setMaxCache(t){}setPreCacheCount(t){}setSmoothing(t){}setWillChange(t){r(this,x)||(r(this,h).willChange=t);}setUseTextShadow(t){r(this,x)||(r(this,h).useTextShadow=t);}};x=new WeakMap,h=new WeakMap,y=new WeakMap,b=new WeakMap,k=new WeakMap,R=new WeakMap,C=new WeakMap,v=new WeakMap,z=new WeakMap,H=new WeakMap,I=new WeakMap,O=new WeakMap,it=new WeakMap,D=new WeakSet,lt=function(t,e,i,n,o,a,l){let m=t.mode??1,F=t.text??"";if(!F)return;let N=t.color??16777215,A=t.font_size??r(this,h).fontSize,c=r(this,h),_=vt(F,c.fontFamily,A,c.fontWeight)+c.padding*2,f=A;if(!l&&c.maxVisible>0&&r(this,v).length>=c.maxVisible&&c.overflow==="drop")return;let p=null;if(m===1){if(p=r(this,b).acquireScroll(e,_,i,o),!p){if(c.overflow==="drop"&&!l)return;let E=Math.random()*r(this,b).scrollTrackCount|0;p={track:E,y:(E+.5)*n};}}else if(m===5){if(p=r(this,b).acquireTop(e,c.duration),!p){if(c.overflow==="drop"&&!l)return;let E=Math.random()*r(this,b).topTrackCount|0;p={track:E,y:(E+.5)*n};}}else if(m===6){if(p=r(this,b).acquireBottom(e,c.duration),!p){if(c.overflow==="drop"&&!l)return;let E=Math.random()*r(this,b).bottomTrackCount|0;p={track:E,y:a*c.area-(E+.5)*n};}}else if(p=r(this,b).acquireScroll(e,_,i,o),!p)if(l){let E=Math.random()*r(this,b).scrollTrackCount|0;p={track:E,y:(E+.5)*n};}else return;let xt=pt(c.fontFamily,A,c.fontWeight),gt=c.useTextShadow?ut(c.strokeWidth,st(c.strokeColor)):"none",Et=c.willChange?"transform":"auto",g=r(this,k).acquire();g.textContent=F,g.style.font=xt,g.style.color=st(N),g.style.textShadow=gt,g.style.willChange=Et,g.style.position="absolute",g.style.left="0",g.style.top="0",g.style.whiteSpace="nowrap",g.style.pointerEvents="none",g.style.userSelect="none",g.style.display="",g.style.opacity=String(c.opacity),r(this,y).appendElement(g);let wt={id:t.id,text:F,mode:m,color:N,fontSize:A,x:m===1?o:o/2,y:p.y,track:p.track,w:_,h:f,born:performance.now()/1e3,duration:c.duration,el:g};r(this,v).push(wt);},et=function(){let t=r(this,y).height;if(t===0)return;let e=r(this,h),i=e.fontSize+e.padding*2+4;r(this,b).resize(t,e.area,i);};function ie(s,t){if(s!=="dom")throw new TypeError("other engines are not available in dom-only package");if(!(t.container instanceof HTMLElement))throw new TypeError("container must be an HTMLElement");if(t.container instanceof HTMLVideoElement)throw new TypeError('container cannot be a <video> element. Video uses a native rendering surface that hides child elements. Wrap the video in a <div> and use that as the container. Example: <div style="position:relative"><video .../><div id="overlay"></div></div>');return new rt(t)}export{U as DanmakuMode,ie as createEngine};//# sourceMappingURL=dom.min.js.map
var ut=s=>{throw TypeError(s)};var nt=(s,t,r)=>t.has(s)||ut("Cannot "+r);var e=(s,t,r)=>(nt(s,t,"read from private field"),r?r.call(s):t.get(s)),f=(s,t,r)=>t.has(s)?ut("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(s):t.set(s,r),p=(s,t,r,i)=>(nt(s,t,"write to private field"),t.set(s,r),r),E=(s,t,r)=>(nt(s,t,"access private method"),r);var st=(s,t,r,i)=>({set _(n){p(s,t,n);},get _(){return e(s,t,i)}});var X=(i=>(i[i.Scroll=1]="Scroll",i[i.Top=5]="Top",i[i.Bottom=6]="Bottom",i))(X||{});function pt(s,t){let r=s;return [`-${r}px -${r}px 0 ${t}`,`0px -${r}px 0 ${t}`,`${r}px -${r}px 0 ${t}`,`-${r}px 0px 0 ${t}`,`${r}px 0px 0 ${t}`,`-${r}px ${r}px 0 ${t}`,`0px ${r}px 0 ${t}`,`${r}px ${r}px 0 ${t}`].join(",")}function ft(s,t,r){return `${r} ${t}px ${s}`}var Z=class{constructor(t){this.container=t;let r=document.createElement("div");r.style.position="absolute",r.style.inset="0",r.style.overflow="hidden",r.style.pointerEvents="none",r.style.userSelect="none",t.appendChild(r),this.root=r;}get width(){return this.container.clientWidth}get height(){return this.container.clientHeight}createElement(t){let r=document.createElement("div");return r.style.position="absolute",r.style.left="0",r.style.top="0",r.style.whiteSpace="nowrap",r.style.font=t.font,r.style.color=t.fillColor,r.style.textShadow=t.textShadow,r.style.willChange=t.willChange,r.style.pointerEvents="none",r.style.userSelect="none",r}configureElement(t,r,i){t.textContent=r,t.style.font=i.font,t.style.color=i.fillColor,t.style.textShadow=i.textShadow,t.style.willChange=i.willChange;}positionElement(t,r,i,n,o){let a=Math.round(r),l=Math.round(i-o/2);n===1?t.style.transform=`translate3d(${a}px, ${l}px, 0)`:t.style.transform=`translate3d(${a}px, ${l}px, 0) translateX(-50%)`;}hideElement(t){t.style.display="none";}showElement(t){t.style.display="";}appendElement(t){this.root.appendChild(t);}removeElement(t){t.parentNode===this.root&&this.root.removeChild(t);}destroy(){this.root.remove();}};var G=class{constructor(){this.pool=[];}acquire(){return this.pool.length>0?this.pool.pop():document.createElement("div")}release(t){this.pool.length<512&&(t.style.display="none",t.parentNode&&t.parentNode.removeChild(t),t.style.transform="",t.textContent="",this.pool.push(t));}releaseAll(t){for(let r=0;r<t.length;r++)this.release(t[r]);}get size(){return this.pool.length}};var J=class{constructor(){this.scrollCount=0;this.scrollFree=[];this.scrollExit=new Float64Array(0);this.topCount=0;this.topFree=[];this.topExit=new Float64Array(0);this.bottomCount=0;this.bottomFree=[];this.bottomExit=new Float64Array(0);this.H=0;this.th=0;this.areaFraction=.75;}resize(t,r,i){this.H=t,this.th=i,this.areaFraction=r;let n=t*r,o=Math.max(1,Math.floor(n/i)),a=Math.max(1,Math.floor(n*.48/i));this.scrollCount=o,this.topCount=a,this.bottomCount=a,this.scrollExit=new Float64Array(o).fill(-1/0),this.topExit=new Float64Array(a).fill(-1/0),this.bottomExit=new Float64Array(a).fill(-1/0),this.scrollFree=Array.from({length:o},(l,u)=>u),this.topFree=Array.from({length:a},(l,u)=>u),this.bottomFree=Array.from({length:a},(l,u)=>u);}acquireScroll(t,r,i,n){let o=[];for(;this.scrollFree.length>0;){let l=this.scrollFree.pop();if(this.scrollExit[l]<=t){this.scrollExit[l]=t+r*1.2/i;for(let u of o)this.scrollFree.push(u);return {track:l,y:this.scrollY(l)}}o.push(l);}for(let l of o)this.scrollFree.push(l);let a=Math.random()*this.scrollCount|0;for(let l=0;l<this.scrollCount;l++){let u=(a+l)%this.scrollCount;if(this.scrollExit[u]<=t){this.scrollExit[u]=t+r*1.2/i;let C=this.scrollFree.indexOf(u);return C!==-1&&this.scrollFree.splice(C,1),{track:u,y:this.scrollY(u)}}}return null}releaseScroll(t){this.scrollExit[t]=-1/0,this.scrollFree.includes(t)||this.scrollFree.push(t);}acquireTop(t,r){let i=[];for(;this.topFree.length>0;){let o=this.topFree.pop();if(this.topExit[o]<=t){this.topExit[o]=t+r;for(let a of i)this.topFree.push(a);return {track:o,y:this.fixedY(o,true)}}i.push(o);}for(let o of i)this.topFree.push(o);let n=Math.random()*this.topCount|0;for(let o=0;o<this.topCount;o++){let a=(n+o)%this.topCount;if(this.topExit[a]<=t){this.topExit[a]=t+r;let l=this.topFree.indexOf(a);return l!==-1&&this.topFree.splice(l,1),{track:a,y:this.fixedY(a,true)}}}return null}releaseTop(t){this.topExit[t]=-1/0,this.topFree.includes(t)||this.topFree.push(t);}acquireBottom(t,r){let i=[];for(;this.bottomFree.length>0;){let o=this.bottomFree.pop();if(this.bottomExit[o]<=t){this.bottomExit[o]=t+r;for(let a of i)this.bottomFree.push(a);return {track:o,y:this.fixedY(o,false)}}i.push(o);}for(let o of i)this.bottomFree.push(o);let n=Math.random()*this.bottomCount|0;for(let o=0;o<this.bottomCount;o++){let a=(n+o)%this.bottomCount;if(this.bottomExit[a]<=t){this.bottomExit[a]=t+r;let l=this.bottomFree.indexOf(a);return l!==-1&&this.bottomFree.splice(l,1),{track:a,y:this.fixedY(a,false)}}}return null}releaseBottom(t){this.bottomExit[t]=-1/0,this.bottomFree.includes(t)||this.bottomFree.push(t);}get scrollTrackCount(){return this.scrollCount}get topTrackCount(){return this.topCount}get bottomTrackCount(){return this.bottomCount}scrollY(t){return (t+.5)*this.th}fixedY(t,r){return r?(t+.5)*this.th:this.H*this.areaFraction-(t+.5)*this.th}};var W,K=class{constructor(t,r,i=true){this.rafId=0;this.lastFrameTime=-1;this.stopped=false;f(this,W,t=>{this.stopped||(this.tick(t),this.rafId=requestAnimationFrame(e(this,W)));});this.frameInterval=1e3/t,this.callback=r,i&&this.start();}start(){this.rafId!==0||this.stopped||(this.rafId=requestAnimationFrame(e(this,W)));}tick(t){if(this.stopped)return false;if(this.lastFrameTime<0)return this.lastFrameTime=t,this.callback(t),true;let r=t-this.lastFrameTime;return r>=this.frameInterval?(this.lastFrameTime=t-r%this.frameInterval,this.callback(t),true):false}setFps(t){this.frameInterval=1e3/t;}stop(){this.stopped=true,this.rafId!==0&&(cancelAnimationFrame(this.rafId),this.rafId=0);}};W=new WeakMap;function q(s,t,r){return s<t?t:s>r?r:s}function Q(s,t,r,i=0,n=s.length){for(;i<n;){let o=i+n>>1;r(s[o])<=t?i=o+1:n=o;}return i}var tt=class{constructor(){this.pool=[];this.cursor=0;}load(t){this.pool=[...t].sort((r,i)=>r.time-i.time),this.cursor=0;}clear(){this.pool=[],this.cursor=0;}emitBatch(t){if(this.pool.length===0)return [];let r=this.cursor<this.pool.length?(this.pool[this.cursor]?.time??0)*1e3:1/0;if(t<r-200&&(this.cursor=Q(this.pool,t,o=>(o.time??0)*1e3)),this.cursor>=this.pool.length)return [];let i=Q(this.pool,t,o=>(o.time??0)*1e3);if(i<=this.cursor)return [];let n=this.pool.slice(this.cursor,i);return this.cursor=i,n}compact(t,r,i,n,o){let a=0;for(let l=0;l<t.length;l++){let u=t[l];if(u.mode===1){if(u.x-=n*i,u.x+u.w<-10){o(u);continue}}else if(r-u.born>=u.duration){o(u);continue}a!==l&&(t[a]=t[l]),a++;}return a}preCacheInfo(){return {pool:this.pool,cursor:this.cursor}}add(t){if(t.length===0)return;let r=new Set;for(let l=0;l<this.pool.length;l++)r.add(this.pool[l].id);let i=[...t].filter(l=>!r.has(l.id)).sort((l,u)=>l.time-u.time);if(i.length===0)return;let n=[],o=0,a=0;for(;o<this.pool.length&&a<i.length;)this.pool[o].time<=i[a].time?(n.push(this.pool[o]),o++):(n.push(i[a]),a++);for(;o<this.pool.length;)n.push(this.pool[o++]);for(;a<i.length;)n.push(i[a++]);this.pool=n;}evictBefore(t){if(this.pool.length===0)return;let r=Q(this.pool,t*1e3-.1,i=>(i.time??0)*1e3);r!==0&&(this.pool.splice(0,r),this.cursor=Math.max(0,this.cursor-r));}};var dt={enabled:true,fps:60,area:.75,fontFamily:"sans-serif",fontSize:25,fontWeight:"bold",opacity:1,padding:4,strokeWidth:1.25,strokeColor:0,speed:1,seekThreshold:.2,duration:4,overflow:"drop",maxVisible:0,maxCache:500,preCacheCount:50,smoothing:true,willChange:true,useTextShadow:true,preBuffer:60,leadTime:0};var P,Y,O,j,N,S,A,T,$,M,ct,bt,yt,et=class{constructor(t,r,i,n,o){f(this,M);f(this,P);f(this,Y);f(this,O);f(this,j);f(this,N);f(this,S,[]);f(this,A,0);f(this,T,null);f(this,$,-1);p(this,P,t),p(this,Y,Math.max(1,r)),p(this,O,Math.max(0,i)),p(this,j,Math.max(.5,n*2.5)),p(this,N,o);}probe(t,r){if(e(this,$)>=0&&Math.abs(t-e(this,$))>e(this,j)&&this.reset(),p(this,$,t),e(this,O)>0){let o=t-e(this,O);r.evictBefore(o),p(this,S,e(this,S).filter(a=>a.end>o));}if(e(this,T))return;let i=t+e(this,Y),n=E(this,M,ct).call(this,t,i);n&&E(this,M,bt).call(this,n.start,n.end,r);}reset(){st(this,A)._++,p(this,T,null),p(this,S,[]),p(this,$,-1);}destroy(){this.reset();}};P=new WeakMap,Y=new WeakMap,O=new WeakMap,j=new WeakMap,N=new WeakMap,S=new WeakMap,A=new WeakMap,T=new WeakMap,$=new WeakMap,M=new WeakSet,ct=function(t,r){let i=t;for(let n of e(this,S))if(n.start<=i&&i<n.end){if(i=n.end,i>=r)return null}else if(n.start>i)return {start:i,end:Math.min(n.start,r)};return i<r?{start:i,end:r}:null},bt=function(t,r,i){let n=++st(this,A)._;p(this,T,e(this,P).fetch(t,r).then(o=>{n===e(this,A)&&(p(this,T,null),o.length>0&&i.add(o),E(this,M,yt).call(this,{start:t,end:r}));}).catch(o=>{var a;n===e(this,A)&&(p(this,T,null),(a=e(this,N))==null||a.call(this,o instanceof Error?o:new Error(String(o))));}));},yt=function(t){e(this,S).push(t),e(this,S).sort((i,n)=>i.start-n.start);let r=[];for(let i of e(this,S)){let n=r[r.length-1];n&&n.end>=i.start?n.end=Math.max(n.end,i.end):r.push({...i});}p(this,S,r);};function at(s){return s<0||s>16777215||!Number.isFinite(s)?"#000000":"#"+s.toString(16).padStart(6,"0")}function xt({fontFamily:s,fontSize:t,fontWeight:r}){return `${r} ${t}px ${s}`}var lt=null;function St(){if(!lt){let s=document.createElement("canvas");s.width=s.height=1,lt=s.getContext("2d");}return lt}function vt(s,t,r,i){let n=St();return n.font=xt({fontFamily:t,fontSize:r,fontWeight:i}),n.measureText(s).width}var c,h,x,b,F,B,D,v,R,L,I,_,it,k,ht,z,rt=class{constructor(t){f(this,k);f(this,c,false);f(this,h);f(this,x);f(this,b);f(this,F);f(this,B);f(this,D);f(this,v,[]);f(this,R,0);f(this,L);f(this,I,null);f(this,_,-1);f(this,it,t=>{let r=e(this,L).position,i=e(this,L).paused,n=e(this,x).width,o=e(this,x).height;if(!e(this,h).enabled||n===0||i)return;let a=Math.abs(r-e(this,_));if(e(this,_)>=0&&a>e(this,h).seekThreshold){for(let m=0;m<e(this,v).length;m++){let y=e(this,v)[m];y.el&&(e(this,x).removeElement(y.el),e(this,F).release(y.el)),y.mode===1?e(this,b).releaseScroll(y.track):y.mode===5?e(this,b).releaseTop(y.track):y.mode===6&&e(this,b).releaseBottom(y.track);}p(this,v,[]),e(this,I)?.reset();}p(this,_,r);let l=e(this,R)?Math.min((t-e(this,R))/1e3,.05):0;p(this,R,t);let u=n/8*e(this,h).speed,C=Math.max(2,Math.ceil(e(this,h).fontSize*.2)),U=e(this,h).fontSize+e(this,h).padding*2+C,H=r*1e3,d=e(this,D).emitBatch(H);for(let m=0;m<d.length;m++)E(this,k,ht).call(this,d[m],r,u,U,n,o);let mt=performance.now()/1e3,V=m=>{m.el&&(e(this,x).hideElement(m.el),e(this,x).removeElement(m.el),e(this,F).release(m.el),m.el=void 0),m.mode===1?e(this,b).releaseScroll(m.track):m.mode===5?e(this,b).releaseTop(m.track):m.mode===6&&e(this,b).releaseBottom(m.track);},ot=e(this,D).compact(e(this,v),mt,l,u,V);e(this,v).length=ot;for(let m=0;m<e(this,v).length;m++){let y=e(this,v)[m];y.el&&e(this,x).positionElement(y.el,y.x,y.y,y.mode,y.h);}e(this,I)?.probe(r,e(this,D));});if(!(t.container instanceof HTMLElement))throw new TypeError("container must be an HTMLElement");if(!t.adapter)throw new TypeError("adapter is required");p(this,h,{...dt,...t}),p(this,L,t.adapter),p(this,x,new Z(t.container)),p(this,b,new J),p(this,F,new G),p(this,D,new tt),t.dataSource&&p(this,I,new et(t.dataSource,e(this,h).preBuffer,e(this,h).leadTime,e(this,h).seekThreshold,t.onError)),E(this,k,z).call(this),p(this,B,new K(e(this,h).fps,e(this,it)));}get isDestroyed(){return e(this,c)}load(t){e(this,c)||(e(this,F).releaseAll(e(this,v).map(r=>r.el).filter(Boolean)),p(this,v,[]),e(this,I)?.reset(),e(this,D).load(t));}send(t){if(e(this,c)||!e(this,h).enabled)return;let r=e(this,L).position,i=e(this,x).width,n=e(this,x).height;if(i===0||n===0)return;let o=i/8*e(this,h).speed,a=Math.max(2,Math.ceil(e(this,h).fontSize*.2)),l=e(this,h).fontSize+e(this,h).padding*2+a,u={...t,time:r};E(this,k,ht).call(this,u,r,o,l,i,n,true);}clear(){e(this,c)||(e(this,F).releaseAll(e(this,v).map(t=>t.el).filter(Boolean)),p(this,v,[]),e(this,D).clear());}resize(){e(this,c)||e(this,x).width>0&&E(this,k,z).call(this);}destroy(){e(this,c)||(p(this,c,true),e(this,B).stop(),e(this,I)?.destroy(),e(this,F).releaseAll(e(this,v).map(t=>t.el).filter(Boolean)),p(this,v,[]),e(this,x).destroy());}setEnabled(t){e(this,c)||(e(this,h).enabled=t,e(this,x).root.style.display=t?"":"none");}setFps(t){e(this,c)||(e(this,h).fps=q(t,1,120),e(this,B).setFps(e(this,h).fps));}setArea(t){e(this,c)||(e(this,h).area=q(t,0,1),E(this,k,z).call(this));}setOpacity(t){e(this,c)||(e(this,h).opacity=q(t,0,1),e(this,x).root.style.opacity=String(e(this,h).opacity));}setSpeed(t){e(this,c)||(e(this,h).speed=Math.max(.1,t));}setFontFamily(t){e(this,h).fontFamily=t;}setFontSize(t){e(this,c)||(e(this,h).fontSize=q(t,8,128),E(this,k,z).call(this));}setFontWeight(t){e(this,h).fontWeight=t;}setStrokeWidth(t){e(this,h).strokeWidth=Math.max(0,t);}setStrokeColor(t){e(this,h).strokeColor=t&16777215;}setPadding(t){e(this,c)||(e(this,h).padding=Math.max(0,t),E(this,k,z).call(this));}setDuration(t){e(this,h).duration=Math.max(.5,t);}setOverflow(t){e(this,h).overflow=t;}setMaxVisible(t){e(this,h).maxVisible=Math.max(0,t);}setMaxCache(t){}setPreCacheCount(t){}setSmoothing(t){}setWillChange(t){e(this,c)||(e(this,h).willChange=t);}setUseTextShadow(t){e(this,c)||(e(this,h).useTextShadow=t);}};c=new WeakMap,h=new WeakMap,x=new WeakMap,b=new WeakMap,F=new WeakMap,B=new WeakMap,D=new WeakMap,v=new WeakMap,R=new WeakMap,L=new WeakMap,I=new WeakMap,_=new WeakMap,it=new WeakMap,k=new WeakSet,ht=function(t,r,i,n,o,a,l){let u=t.mode??1,C=t.text??"";if(!C)return;let U=t.color??16777215,H=t.font_size??e(this,h).fontSize,d=e(this,h),V=vt(C,d.fontFamily,H,d.fontWeight)+d.padding*2,ot=H;if(!l&&d.maxVisible>0&&e(this,v).length>=d.maxVisible&&d.overflow==="drop")return;let m=null;if(u===1){if(m=e(this,b).acquireScroll(r,V,i,o),!m){if(d.overflow==="drop"&&!l)return;let w=Math.random()*e(this,b).scrollTrackCount|0;m={track:w,y:(w+.5)*n};}}else if(u===5){if(m=e(this,b).acquireTop(r,d.duration),!m){if(d.overflow==="drop"&&!l)return;let w=Math.random()*e(this,b).topTrackCount|0;m={track:w,y:(w+.5)*n};}}else if(u===6){if(m=e(this,b).acquireBottom(r,d.duration),!m){if(d.overflow==="drop"&&!l)return;let w=Math.random()*e(this,b).bottomTrackCount|0;m={track:w,y:a*d.area-(w+.5)*n};}}else if(m=e(this,b).acquireScroll(r,V,i,o),!m)if(l){let w=Math.random()*e(this,b).scrollTrackCount|0;m={track:w,y:(w+.5)*n};}else return;let y=ft(d.fontFamily,H,d.fontWeight),gt=d.useTextShadow?pt(d.strokeWidth*.7,at(d.strokeColor)):"none",Et=d.willChange?"transform":"auto",g=e(this,F).acquire();g.textContent=C,g.style.font=y,g.style.color=at(U),g.style.textShadow=gt,g.style.willChange=Et,g.style.position="absolute",g.style.left="0",g.style.top="0",g.style.whiteSpace="nowrap",g.style.pointerEvents="none",g.style.userSelect="none",g.style.display="",g.style.opacity=String(d.opacity),e(this,x).appendElement(g);let wt={id:t.id,text:C,mode:u,color:U,fontSize:H,x:u===1?o:o/2,y:m.y,track:m.track,w:V,h:ot,born:performance.now()/1e3,duration:d.duration,el:g};e(this,v).push(wt);},z=function(){let t=e(this,x).height;if(t===0)return;let r=e(this,h),i=Math.max(2,Math.ceil(r.fontSize*.2)),n=r.fontSize+r.padding*2+i;e(this,b).resize(t,r.area,n);};function ie(s,t){if(s!=="dom")throw new TypeError("other engines are not available in dom-only package");if(!(t.container instanceof HTMLElement))throw new TypeError("container must be an HTMLElement");if(t.container instanceof HTMLVideoElement)throw new TypeError('container cannot be a <video> element. Video uses a native rendering surface that hides child elements. Wrap the video in a <div> and use that as the container. Example: <div style="position:relative"><video .../><div id="overlay"></div></div>');return new rt(t)}export{X as DanmakuMode,ie as createEngine};//# sourceMappingURL=dom.min.js.map
//# sourceMappingURL=dom.min.js.map

@@ -838,3 +838,4 @@ var __typeError = (msg) => {

const scrollSpeed = W / 8 * __privateGet(this, _config).speed;
const th = __privateGet(this, _config).fontSize + __privateGet(this, _config).padding * 2 + 4;
const gap = Math.max(2, Math.ceil(__privateGet(this, _config).fontSize * 0.2));
const th = __privateGet(this, _config).fontSize + __privateGet(this, _config).padding * 2 + gap;
const posMs = pos * 1e3;

@@ -936,3 +937,4 @@ const batch = __privateGet(this, _scheduler).emitBatch(posMs);

const scrollSpeed = W / 8 * __privateGet(this, _config).speed;
const th = __privateGet(this, _config).fontSize + __privateGet(this, _config).padding * 2 + 4;
const gap = Math.max(2, Math.ceil(__privateGet(this, _config).fontSize * 0.2));
const th = __privateGet(this, _config).fontSize + __privateGet(this, _config).padding * 2 + gap;
const sent = { ...item, time: pos };

@@ -1007,2 +1009,3 @@ __privateMethod(this, _CanvasEngine_instances, emit_fn).call(this, sent, pos, scrollSpeed, th, W, H, true);

__privateGet(this, _cache).clearBitmaps();
__privateMethod(this, _CanvasEngine_instances, resizeTracks_fn).call(this);
}

@@ -1029,2 +1032,3 @@ setFontWeight(v) {

__privateGet(this, _cache).clearBitmaps();
__privateMethod(this, _CanvasEngine_instances, resizeTracks_fn).call(this);
}

@@ -1196,3 +1200,4 @@ setDuration(v) {

const cfg = __privateGet(this, _config);
const th = cfg.fontSize + cfg.padding * 2 + 4;
const gap = Math.max(2, Math.ceil(cfg.fontSize * 0.2));
const th = cfg.fontSize + cfg.padding * 2 + gap;
__privateGet(this, _tracks).resize(H, cfg.area, th);

@@ -1368,6 +1373,3 @@ };

}
if (paused) {
__privateSet(this, _lastPos2, -1);
return;
}
if (paused) return;
const posJump = Math.abs(pos - __privateGet(this, _lastPos2));

@@ -1392,3 +1394,4 @@ if (__privateGet(this, _lastPos2) >= 0 && posJump > __privateGet(this, _config2).seekThreshold) {

const scrollSpeed = W / 8 * __privateGet(this, _config2).speed;
const th = __privateGet(this, _config2).fontSize + __privateGet(this, _config2).padding * 2 + 4;
const gap = Math.max(2, Math.ceil(__privateGet(this, _config2).fontSize * 0.2));
const th = __privateGet(this, _config2).fontSize + __privateGet(this, _config2).padding * 2 + gap;
const posMs = pos * 1e3;

@@ -1469,3 +1472,4 @@ const batch = __privateGet(this, _scheduler2).emitBatch(posMs);

const scrollSpeed = W / 8 * __privateGet(this, _config2).speed;
const th = __privateGet(this, _config2).fontSize + __privateGet(this, _config2).padding * 2 + 4;
const gap = Math.max(2, Math.ceil(__privateGet(this, _config2).fontSize * 0.2));
const th = __privateGet(this, _config2).fontSize + __privateGet(this, _config2).padding * 2 + gap;
const sent = { ...item, time: pos };

@@ -1526,3 +1530,5 @@ __privateMethod(this, _DOMEngine_instances, emit_fn2).call(this, sent, pos, scrollSpeed, th, W, H, true);

setFontSize(v) {
if (__privateGet(this, _destroyed2)) return;
__privateGet(this, _config2).fontSize = clamp(v, 8, 128);
__privateMethod(this, _DOMEngine_instances, resizeTracks_fn2).call(this);
}

@@ -1539,3 +1545,5 @@ setFontWeight(v) {

setPadding(v) {
if (__privateGet(this, _destroyed2)) return;
__privateGet(this, _config2).padding = Math.max(0, v);
__privateMethod(this, _DOMEngine_instances, resizeTracks_fn2).call(this);
}

@@ -1632,3 +1640,3 @@ setDuration(v) {

const font = buildDomFont(cfg.fontFamily, fs, cfg.fontWeight);
const textShadow = cfg.useTextShadow ? buildTextShadow(cfg.strokeWidth, toCss(cfg.strokeColor)) : "none";
const textShadow = cfg.useTextShadow ? buildTextShadow(cfg.strokeWidth * 0.7, toCss(cfg.strokeColor)) : "none";
const willChange = cfg.willChange ? "transform" : "auto";

@@ -1674,3 +1682,4 @@ const el = __privateGet(this, _pool2).acquire();

const cfg = __privateGet(this, _config2);
const th = cfg.fontSize + cfg.padding * 2 + 4;
const gap = Math.max(2, Math.ceil(cfg.fontSize * 0.2));
const th = cfg.fontSize + cfg.padding * 2 + gap;
__privateGet(this, _tracks2).resize(H, cfg.area, th);

@@ -1677,0 +1686,0 @@ };

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

var qt=h=>{throw TypeError(h)};var Ot=(h,t,i)=>t.has(h)||qt("Cannot "+i);var e=(h,t,i)=>(Ot(h,t,"read from private field"),i?i.call(h):t.get(h)),d=(h,t,i)=>t.has(h)?qt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(h):t.set(h,i),c=(h,t,i,s)=>(Ot(h,t,"write to private field"),t.set(h,i),i),E=(h,t,i)=>(Ot(h,t,"access private method"),i);var Rt=(h,t,i,s)=>({set _(o){c(h,t,o);},get _(){return e(h,t,s)}});var dt=(s=>(s[s.Scroll=1]="Scroll",s[s.Top=5]="Top",s[s.Bottom=6]="Bottom",s))(dt||{});var wt=class{constructor(t){this.W=0;this.H=0;this.dpr=1;this.container=t;let i=document.createElement("canvas");i.style.position="absolute",i.style.inset="0",i.style.width="100%",i.style.height="100%",i.style.pointerEvents="none",t.appendChild(i),this.canvas=i,this.ctx=i.getContext("2d"),this.updateDimensions();}updateDimensions(){let t=window.devicePixelRatio||1,i=this.container.clientWidth,s=this.container.clientHeight;return i===0||s===0?false:(this.dpr=t,this.W=i,this.H=s,this.canvas.width=i*t,this.canvas.height=s*t,this.canvas.style.width=i+"px",this.canvas.style.height=s+"px",this.ctx.setTransform(t,0,0,t,0,0),true)}get width(){return this.W}get height(){return this.H}get devicePixelRatio(){return this.dpr}clear(){this.ctx.clearRect(0,0,this.W,this.H);}setSmoothing(t){this.ctx.imageSmoothingEnabled=t;}setGlobalAlpha(t){this.ctx.globalAlpha=t;}destroy(){this.canvas.remove();}};var it=class{constructor(){this.scrollCount=0;this.scrollFree=[];this.scrollExit=new Float64Array(0);this.topCount=0;this.topFree=[];this.topExit=new Float64Array(0);this.bottomCount=0;this.bottomFree=[];this.bottomExit=new Float64Array(0);this.H=0;this.th=0;this.areaFraction=.75;}resize(t,i,s){this.H=t,this.th=s,this.areaFraction=i;let o=t*i,r=Math.max(1,Math.floor(o/s)),n=Math.max(1,Math.floor(o*.48/s));this.scrollCount=r,this.topCount=n,this.bottomCount=n,this.scrollExit=new Float64Array(r).fill(-1/0),this.topExit=new Float64Array(n).fill(-1/0),this.bottomExit=new Float64Array(n).fill(-1/0),this.scrollFree=Array.from({length:r},(a,m)=>m),this.topFree=Array.from({length:n},(a,m)=>m),this.bottomFree=Array.from({length:n},(a,m)=>m);}acquireScroll(t,i,s,o){let r=[];for(;this.scrollFree.length>0;){let a=this.scrollFree.pop();if(this.scrollExit[a]<=t){this.scrollExit[a]=t+i*1.2/s;for(let m of r)this.scrollFree.push(m);return {track:a,y:this.scrollY(a)}}r.push(a);}for(let a of r)this.scrollFree.push(a);let n=Math.random()*this.scrollCount|0;for(let a=0;a<this.scrollCount;a++){let m=(n+a)%this.scrollCount;if(this.scrollExit[m]<=t){this.scrollExit[m]=t+i*1.2/s;let k=this.scrollFree.indexOf(m);return k!==-1&&this.scrollFree.splice(k,1),{track:m,y:this.scrollY(m)}}}return null}releaseScroll(t){this.scrollExit[t]=-1/0,this.scrollFree.includes(t)||this.scrollFree.push(t);}acquireTop(t,i){let s=[];for(;this.topFree.length>0;){let r=this.topFree.pop();if(this.topExit[r]<=t){this.topExit[r]=t+i;for(let n of s)this.topFree.push(n);return {track:r,y:this.fixedY(r,true)}}s.push(r);}for(let r of s)this.topFree.push(r);let o=Math.random()*this.topCount|0;for(let r=0;r<this.topCount;r++){let n=(o+r)%this.topCount;if(this.topExit[n]<=t){this.topExit[n]=t+i;let a=this.topFree.indexOf(n);return a!==-1&&this.topFree.splice(a,1),{track:n,y:this.fixedY(n,true)}}}return null}releaseTop(t){this.topExit[t]=-1/0,this.topFree.includes(t)||this.topFree.push(t);}acquireBottom(t,i){let s=[];for(;this.bottomFree.length>0;){let r=this.bottomFree.pop();if(this.bottomExit[r]<=t){this.bottomExit[r]=t+i;for(let n of s)this.bottomFree.push(n);return {track:r,y:this.fixedY(r,false)}}s.push(r);}for(let r of s)this.bottomFree.push(r);let o=Math.random()*this.bottomCount|0;for(let r=0;r<this.bottomCount;r++){let n=(o+r)%this.bottomCount;if(this.bottomExit[n]<=t){this.bottomExit[n]=t+i;let a=this.bottomFree.indexOf(n);return a!==-1&&this.bottomFree.splice(a,1),{track:n,y:this.fixedY(n,false)}}}return null}releaseBottom(t){this.bottomExit[t]=-1/0,this.bottomFree.includes(t)||this.bottomFree.push(t);}get scrollTrackCount(){return this.scrollCount}get topTrackCount(){return this.topCount}get bottomTrackCount(){return this.bottomCount}scrollY(t){return (t+.5)*this.th}fixedY(t,i){return i?(t+.5)*this.th:this.H*this.areaFraction-(t+.5)*this.th}};var kt=class{constructor(){this.pool=[];}acquire(){return this.pool.length>0?this.pool.pop():{}}release(t){this.pool.length<512&&(t.bmp=void 0,t.el=void 0,this.pool.push(t));}releaseAll(t){for(let i=0;i<t.length;i++)this.release(t[i]);}get size(){return this.pool.length}};function st(h){return h<0||h>16777215||!Number.isFinite(h)?"#000000":"#"+h.toString(16).padStart(6,"0")}function pt({fontFamily:h,fontSize:t,fontWeight:i}){return `${i} ${t}px ${h}`}var Ct=class{constructor(t=500){this.textWidths=new Map;this.bitmaps=new Map;this.aliveBitmaps=new Set;this.accessCounter=0;this.dpr=1;this.cachedFont="";this.fontFamily="";this.fontSize=0;this.fontWeight="";this.maxCache=t;}measure(t,i,s,o,r){let n=`${t}|${i}|${s}|${o}`,a=this.textWidths.get(n);if(a!==void 0)return a;r.font=pt({fontFamily:i,fontSize:s,fontWeight:o});let m=r.measureText(t).width;return this.textWidths.set(n,m),m}invalidateTextCache(){this.textWidths.clear();}getBitmap(t,i,s,o,r,n,a,m,k){let B=`${t}|${i}|${s}|${o}|${r}|${n}|${a}|${m}`,S=this.bitmaps.get(B);if(S)return S.accessId=++this.accessCounter,S.bitmap;(n!==this.fontFamily||i!==this.fontSize||a!==this.fontWeight)&&(this.fontFamily=n,this.fontSize=i,this.fontWeight=a,this.cachedFont=pt({fontFamily:n,fontSize:i,fontWeight:a}));let u=this.textWidths.get(`${t}|${n}|${i}|${a}`);if(u===void 0)throw new Error(`Text width not cached for "${t}". Call measure() first.`);let U=Math.ceil(u)+k*2,R=i+k*2,v=U*m|0,l=R*m|0,g=k*m,H=l/2,C=new OffscreenCanvas(v,l),f=C.getContext("2d");f.font=`${a} ${i*m}px ${n}`,f.lineWidth=o*m,f.lineJoin="round",f.textBaseline="middle",f.textAlign="left",f.strokeStyle=st(r),f.strokeText(t,g,H),f.fillStyle=st(s),f.fillText(t,g,H);let _=C.transferToImageBitmap();return this.bitmaps.set(B,{bitmap:_,accessId:++this.accessCounter}),this.aliveBitmaps.add(_),this.bitmaps.size>this.maxCache&&this.evictOne(),_}evictOne(){let t="",i=1/0;for(let[s,o]of this.bitmaps)o.accessId<i&&(i=o.accessId,t=s);if(t){let s=this.bitmaps.get(t);s&&(this.aliveBitmaps.delete(s.bitmap),s.bitmap.close(),this.bitmaps.delete(t));}}isAlive(t){return this.aliveBitmaps.has(t)}setMaxCache(t){for(this.maxCache=t;this.bitmaps.size>this.maxCache;)this.evictOne();}setDpr(t){this.dpr!==t&&(this.dpr=t,this.clearBitmaps());}clearBitmaps(){for(let[,t]of this.bitmaps)this.aliveBitmaps.delete(t.bitmap),t.bitmap.close();this.bitmaps.clear();}clearAll(){this.clearBitmaps(),this.textWidths.clear();}get bitmapCount(){return this.bitmaps.size}};var ft,rt=class{constructor(t,i,s=true){this.rafId=0;this.lastFrameTime=-1;this.stopped=false;d(this,ft,t=>{this.stopped||(this.tick(t),this.rafId=requestAnimationFrame(e(this,ft)));});this.frameInterval=1e3/t,this.callback=i,s&&this.start();}start(){this.rafId!==0||this.stopped||(this.rafId=requestAnimationFrame(e(this,ft)));}tick(t){if(this.stopped)return false;if(this.lastFrameTime<0)return this.lastFrameTime=t,this.callback(t),true;let i=t-this.lastFrameTime;return i>=this.frameInterval?(this.lastFrameTime=t-i%this.frameInterval,this.callback(t),true):false}setFps(t){this.frameInterval=1e3/t;}stop(){this.stopped=true,this.rafId!==0&&(cancelAnimationFrame(this.rafId),this.rafId=0);}};ft=new WeakMap;function W(h,t,i){return h<t?t:h>i?i:h}function St(h,t,i,s=0,o=h.length){for(;s<o;){let r=s+o>>1;i(h[r])<=t?s=r+1:o=r;}return s}var ot=class{constructor(){this.pool=[];this.cursor=0;}load(t){this.pool=[...t].sort((i,s)=>i.time-s.time),this.cursor=0;}clear(){this.pool=[],this.cursor=0;}emitBatch(t){if(this.pool.length===0)return [];let i=this.cursor<this.pool.length?(this.pool[this.cursor]?.time??0)*1e3:1/0;if(t<i-200&&(this.cursor=St(this.pool,t,r=>(r.time??0)*1e3)),this.cursor>=this.pool.length)return [];let s=St(this.pool,t,r=>(r.time??0)*1e3);if(s<=this.cursor)return [];let o=this.pool.slice(this.cursor,s);return this.cursor=s,o}compact(t,i,s,o,r){let n=0;for(let a=0;a<t.length;a++){let m=t[a];if(m.mode===1){if(m.x-=o*s,m.x+m.w<-10){r(m);continue}}else if(i-m.born>=m.duration){r(m);continue}n!==a&&(t[n]=t[a]),n++;}return n}preCacheInfo(){return {pool:this.pool,cursor:this.cursor}}add(t){if(t.length===0)return;let i=new Set;for(let a=0;a<this.pool.length;a++)i.add(this.pool[a].id);let s=[...t].filter(a=>!i.has(a.id)).sort((a,m)=>a.time-m.time);if(s.length===0)return;let o=[],r=0,n=0;for(;r<this.pool.length&&n<s.length;)this.pool[r].time<=s[n].time?(o.push(this.pool[r]),r++):(o.push(s[n]),n++);for(;r<this.pool.length;)o.push(this.pool[r++]);for(;n<s.length;)o.push(s[n++]);this.pool=o;}evictBefore(t){if(this.pool.length===0)return;let i=St(this.pool,t*1e3-.1,s=>(s.time??0)*1e3);i!==0&&(this.pool.splice(0,i),this.cursor=Math.max(0,this.cursor-i));}};var Lt=new Map;typeof window<"u"&&!window.requestIdleCallback&&(window.requestIdleCallback=function(h,t){let i=t?.timeout,s=Date.now(),o=0,r={didTimeout:false,timeRemaining:()=>Math.max(0,50-(Date.now()-s))};i!=null&&(o=setTimeout(()=>{r.didTimeout=true,s=Date.now(),h(r);},i));let n=requestAnimationFrame(()=>{i!=null&&clearTimeout(o),!r.didTimeout&&(s=Date.now(),h(r));}),a=Date.now()+Math.random();return Lt.set(a,{rafId:n,timeoutId:o}),a},window.cancelIdleCallback=function(h){let t=Lt.get(h);t&&(cancelAnimationFrame(t.rafId),t.timeoutId&&clearTimeout(t.timeoutId),Lt.delete(h));});function Yt(h,t,i,s){let o=0,r=t;function n(a){let m=Math.min(t+i,h.length),k=0;for(;r<m&&(a.timeRemaining()>1||k<5);){let B=h[r];B&&s(B),r++,k++;}r<m&&(o=requestIdleCallback(n,{timeout:2e3}));}return o=requestIdleCallback(n,{timeout:2e3}),()=>cancelIdleCallback(o)}var Dt={enabled:true,fps:60,area:.75,fontFamily:"sans-serif",fontSize:25,fontWeight:"bold",opacity:1,padding:4,strokeWidth:1.25,strokeColor:0,speed:1,seekThreshold:.2,duration:4,overflow:"drop",maxVisible:0,maxCache:500,preCacheCount:50,smoothing:true,willChange:true,useTextShadow:true,preBuffer:60,leadTime:0};var bt,vt,nt,gt,yt,L,J,j,K,X,Ut,jt,Xt,at=class{constructor(t,i,s,o,r){d(this,X);d(this,bt);d(this,vt);d(this,nt);d(this,gt);d(this,yt);d(this,L,[]);d(this,J,0);d(this,j,null);d(this,K,-1);c(this,bt,t),c(this,vt,Math.max(1,i)),c(this,nt,Math.max(0,s)),c(this,gt,Math.max(.5,o*2.5)),c(this,yt,r);}probe(t,i){if(e(this,K)>=0&&Math.abs(t-e(this,K))>e(this,gt)&&this.reset(),c(this,K,t),e(this,nt)>0){let r=t-e(this,nt);i.evictBefore(r),c(this,L,e(this,L).filter(n=>n.end>r));}if(e(this,j))return;let s=t+e(this,vt),o=E(this,X,Ut).call(this,t,s);o&&E(this,X,jt).call(this,o.start,o.end,i);}reset(){Rt(this,J)._++,c(this,j,null),c(this,L,[]),c(this,K,-1);}destroy(){this.reset();}};bt=new WeakMap,vt=new WeakMap,nt=new WeakMap,gt=new WeakMap,yt=new WeakMap,L=new WeakMap,J=new WeakMap,j=new WeakMap,K=new WeakMap,X=new WeakSet,Ut=function(t,i){let s=t;for(let o of e(this,L))if(o.start<=s&&s<o.end){if(s=o.end,s>=i)return null}else if(o.start>s)return {start:s,end:Math.min(o.start,i)};return s<i?{start:s,end:i}:null},jt=function(t,i,s){let o=++Rt(this,J)._;c(this,j,e(this,bt).fetch(t,i).then(r=>{o===e(this,J)&&(c(this,j,null),r.length>0&&s.add(r),E(this,X,Xt).call(this,{start:t,end:i}));}).catch(r=>{var n;o===e(this,J)&&(c(this,j,null),(n=e(this,yt))==null||n.call(this,r instanceof Error?r:new Error(String(r))));}));},Xt=function(t){e(this,L).push(t),e(this,L).sort((s,o)=>s.start-o.start);let i=[];for(let s of e(this,L)){let o=i[i.length-1];o&&o.end>=s.start?o.end=Math.max(o.end,s.end):i.push({...s});}c(this,L,i);};var y,p,x,D,z,w,ht,P,F,lt,N,Q,Z,mt,Ft,O,Wt,zt,Tt,Et=class{constructor(t){d(this,O);d(this,y,false);d(this,p);d(this,x);d(this,D);d(this,z);d(this,w);d(this,ht);d(this,P);d(this,F,[]);d(this,lt,0);d(this,N,null);d(this,Q);d(this,Z,null);d(this,mt,-1);d(this,Ft,t=>{let i=e(this,Q).position,s=e(this,Q).paused,o=e(this,x).width,r=e(this,x).height;if(!e(this,p).enabled||o===0){e(this,x).clear();return}if(s)return;let n=Math.abs(i-e(this,mt));if(e(this,mt)>=0&&n>e(this,p).seekThreshold){for(let l=0;l<e(this,F).length;l++){let g=e(this,F)[l];g.mode===1?e(this,D).releaseScroll(g.track):g.mode===5?e(this,D).releaseTop(g.track):g.mode===6&&e(this,D).releaseBottom(g.track),e(this,z).release(g);}c(this,F,[]),e(this,x).clear(),e(this,Z)?.reset();}c(this,mt,i);let a=e(this,lt)?Math.min((t-e(this,lt))/1e3,.05):0;c(this,lt,t);let m=o/8*e(this,p).speed,k=e(this,p).fontSize+e(this,p).padding*2+4,B=i*1e3,S=e(this,P).emitBatch(B);for(let l=0;l<S.length;l++)E(this,O,Wt).call(this,S[l],i,m,k,o,r);let u=performance.now()/1e3,U=l=>{l.mode===1?e(this,D).releaseScroll(l.track):l.mode===5?e(this,D).releaseTop(l.track):l.mode===6&&e(this,D).releaseBottom(l.track),e(this,z).release(l);};e(this,F).length=e(this,P).compact(e(this,F),u,a,m,U),e(this,x).clear(),e(this,x).setGlobalAlpha(e(this,p).opacity);let R=e(this,x).devicePixelRatio,v=e(this,p).padding;for(let l=0;l<e(this,F).length;l++){let g=e(this,F)[l],H=g.bmp;if(!H)continue;if(!e(this,w).isAlive(H)){g.bmp=void 0;continue}let C=g.x|0,f=g.y|0,_=H.width,$=H.height,Ht=_/R,xt=$/R,_t=e(this,x).ctx;g.mode===1?_t.drawImage(H,0,0,_,$,C-v,f-xt/2|0,Ht,xt):_t.drawImage(H,0,0,_,$,C-Ht/2|0,f-xt/2|0,Ht,xt);}E(this,O,zt).call(this),e(this,Z)?.probe(i,e(this,P));});if(!(t.container instanceof HTMLElement))throw new TypeError("container must be an HTMLElement");if(!t.adapter)throw new TypeError("adapter is required");c(this,p,{...Dt,...t}),c(this,Q,t.adapter),c(this,x,new wt(t.container)),e(this,x).setSmoothing(e(this,p).smoothing),c(this,D,new it),c(this,z,new kt),c(this,w,new Ct(e(this,p).maxCache)),c(this,P,new ot),t.dataSource&&c(this,Z,new at(t.dataSource,e(this,p).preBuffer,e(this,p).leadTime,e(this,p).seekThreshold,t.onError)),E(this,O,Tt).call(this),c(this,ht,new rt(e(this,p).fps,e(this,Ft)));}get isDestroyed(){return e(this,y)}load(t){var i;e(this,y)||(e(this,z).releaseAll(e(this,F)),c(this,F,[]),e(this,w).clearAll(),e(this,Z)?.reset(),e(this,P).load(t),(i=e(this,N))==null||i.call(this),c(this,N,null),E(this,O,zt).call(this));}send(t){if(e(this,y)||!e(this,p).enabled)return;let i=e(this,Q).position,s=e(this,x).width,o=e(this,x).height;if(s===0||o===0)return;let r=s/8*e(this,p).speed,n=e(this,p).fontSize+e(this,p).padding*2+4,a={...t,time:i};E(this,O,Wt).call(this,a,i,r,n,s,o,true);}clear(){e(this,y)||(e(this,z).releaseAll(e(this,F)),c(this,F,[]),e(this,P).clear(),e(this,w).clearAll(),e(this,x).clear());}resize(){if(e(this,y))return;e(this,x).updateDimensions()&&(e(this,w).setDpr(e(this,x).devicePixelRatio),e(this,w).invalidateTextCache(),E(this,O,Tt).call(this));}destroy(){var t;e(this,y)||(c(this,y,true),e(this,ht).stop(),(t=e(this,N))==null||t.call(this),e(this,Z)?.destroy(),e(this,z).releaseAll(e(this,F)),c(this,F,[]),e(this,w).clearAll(),e(this,x).destroy());}setEnabled(t){e(this,y)||(e(this,p).enabled=t,t||e(this,x).clear());}setFps(t){e(this,y)||(e(this,p).fps=W(t,1,120),e(this,ht).setFps(e(this,p).fps));}setArea(t){e(this,y)||(e(this,p).area=W(t,0,1),E(this,O,Tt).call(this));}setOpacity(t){e(this,y)||(e(this,p).opacity=W(t,0,1));}setSpeed(t){e(this,y)||(e(this,p).speed=Math.max(.1,t));}setFontFamily(t){e(this,y)||(e(this,p).fontFamily=t,e(this,w).invalidateTextCache(),e(this,w).clearBitmaps());}setFontSize(t){e(this,y)||(e(this,p).fontSize=W(t,8,128),e(this,w).invalidateTextCache(),e(this,w).clearBitmaps());}setFontWeight(t){e(this,y)||(e(this,p).fontWeight=t,e(this,w).invalidateTextCache(),e(this,w).clearBitmaps());}setStrokeWidth(t){e(this,y)||(e(this,p).strokeWidth=Math.max(0,t),e(this,w).clearBitmaps());}setStrokeColor(t){e(this,y)||(e(this,p).strokeColor=t&16777215,e(this,w).clearBitmaps());}setPadding(t){e(this,y)||(e(this,p).padding=Math.max(0,t),e(this,w).clearBitmaps());}setDuration(t){e(this,y)||(e(this,p).duration=Math.max(.5,t));}setOverflow(t){e(this,y)||(e(this,p).overflow=t);}setMaxVisible(t){e(this,y)||(e(this,p).maxVisible=Math.max(0,t));}setMaxCache(t){e(this,y)||(e(this,p).maxCache=Math.max(10,t),e(this,w).setMaxCache(e(this,p).maxCache));}setPreCacheCount(t){e(this,y)||(e(this,p).preCacheCount=Math.max(0,t));}setSmoothing(t){e(this,y)||(e(this,p).smoothing=t,e(this,x).setSmoothing(t));}setWillChange(t){}setUseTextShadow(t){}};y=new WeakMap,p=new WeakMap,x=new WeakMap,D=new WeakMap,z=new WeakMap,w=new WeakMap,ht=new WeakMap,P=new WeakMap,F=new WeakMap,lt=new WeakMap,N=new WeakMap,Q=new WeakMap,Z=new WeakMap,mt=new WeakMap,Ft=new WeakMap,O=new WeakSet,Wt=function(t,i,s,o,r,n,a){let m=t.mode??1,k=t.text??"";if(!k)return;let B=t.color??16777215,S=t.font_size??e(this,p).fontSize,u=e(this,p),U=e(this,x).ctx,v=e(this,w).measure(k,u.fontFamily,S,u.fontWeight,U)+u.padding*2,l=S;if(!a&&u.maxVisible>0&&e(this,F).length>=u.maxVisible&&u.overflow==="drop")return;let g=null;if(m===1){if(g=e(this,D).acquireScroll(i,v,s,r),!g){if(u.overflow==="drop"&&!a)return;let f=Math.random()*e(this,D).scrollTrackCount|0;g={track:f,y:(f+.5)*o};}}else if(m===5){if(g=e(this,D).acquireTop(i,u.duration),!g){if(u.overflow==="drop"&&!a)return;let f=Math.random()*e(this,D).topTrackCount|0;g={track:f,y:(f+.5)*o};}}else if(m===6){if(g=e(this,D).acquireBottom(i,u.duration),!g){if(u.overflow==="drop"&&!a)return;let f=Math.random()*e(this,D).bottomTrackCount|0;g={track:f,y:n*u.area-(f+.5)*o};}}else if(g=e(this,D).acquireScroll(i,v,s,r),!g)if(a){let f=Math.random()*e(this,D).scrollTrackCount|0;g={track:f,y:(f+.5)*o};}else return;let H=e(this,w).getBitmap(k,S,B,u.strokeWidth,u.strokeColor,u.fontFamily,u.fontWeight,e(this,x).devicePixelRatio,u.padding),C=e(this,z).acquire();C.id=t.id,C.text=k,C.mode=m,C.color=B,C.fontSize=S,C.x=m===1?r:r/2,C.y=g.y,C.track=g.track,C.w=v,C.h=l,C.born=performance.now()/1e3,C.duration=u.duration,C.bmp=H,e(this,F).push(C);},zt=function(){if(e(this,N)||e(this,y))return;let{pool:t,cursor:i}=e(this,P).preCacheInfo(),s=e(this,p);c(this,N,Yt(t,i,s.preCacheCount,o=>{let r=o.text??"",n=o.font_size??s.fontSize,a=o.color??16777215;e(this,w).measure(r,s.fontFamily,n,s.fontWeight,e(this,x).ctx);try{e(this,w).getBitmap(r,n,a,s.strokeWidth,s.strokeColor,s.fontFamily,s.fontWeight,e(this,x).devicePixelRatio,s.padding);}catch{}}));},Tt=function(){let t=e(this,x).height;if(t===0)return;let i=e(this,p),s=i.fontSize+i.padding*2+4;e(this,D).resize(t,i.area,s);};function Nt(h,t){let i=h;return [`-${i}px -${i}px 0 ${t}`,`0px -${i}px 0 ${t}`,`${i}px -${i}px 0 ${t}`,`-${i}px 0px 0 ${t}`,`${i}px 0px 0 ${t}`,`-${i}px ${i}px 0 ${t}`,`0px ${i}px 0 ${t}`,`${i}px ${i}px 0 ${t}`].join(",")}function Zt(h,t,i){return `${i} ${t}px ${h}`}var Mt=class{constructor(t){this.container=t;let i=document.createElement("div");i.style.position="absolute",i.style.inset="0",i.style.overflow="hidden",i.style.pointerEvents="none",i.style.userSelect="none",t.appendChild(i),this.root=i;}get width(){return this.container.clientWidth}get height(){return this.container.clientHeight}createElement(t){let i=document.createElement("div");return i.style.position="absolute",i.style.left="0",i.style.top="0",i.style.whiteSpace="nowrap",i.style.font=t.font,i.style.color=t.fillColor,i.style.textShadow=t.textShadow,i.style.willChange=t.willChange,i.style.pointerEvents="none",i.style.userSelect="none",i}configureElement(t,i,s){t.textContent=i,t.style.font=s.font,t.style.color=s.fillColor,t.style.textShadow=s.textShadow,t.style.willChange=s.willChange;}positionElement(t,i,s,o,r){let n=Math.round(i),a=Math.round(s-r/2);o===1?t.style.transform=`translate3d(${n}px, ${a}px, 0)`:t.style.transform=`translate3d(${n}px, ${a}px, 0) translateX(-50%)`;}hideElement(t){t.style.display="none";}showElement(t){t.style.display="";}appendElement(t){this.root.appendChild(t);}removeElement(t){t.parentNode===this.root&&this.root.removeChild(t);}destroy(){this.root.remove();}};var It=class{constructor(){this.pool=[];}acquire(){return this.pool.length>0?this.pool.pop():document.createElement("div")}release(t){this.pool.length<512&&(t.style.display="none",t.parentNode&&t.parentNode.removeChild(t),t.style.transform="",t.textContent="",this.pool.push(t));}releaseAll(t){for(let i=0;i<t.length;i++)this.release(t[i]);}get size(){return this.pool.length}};var Pt=null;function Jt(){if(!Pt){let h=document.createElement("canvas");h.width=h.height=1,Pt=h.getContext("2d");}return Pt}function Gt(h,t,i,s){let o=Jt();return o.font=pt({fontFamily:t,fontSize:i,fontWeight:s}),o.measureText(h).width}var A,b,M,T,V,ct,q,I,ut,tt,G,et,$t,Y,Vt,At,Bt=class{constructor(t){d(this,Y);d(this,A,false);d(this,b);d(this,M);d(this,T);d(this,V);d(this,ct);d(this,q);d(this,I,[]);d(this,ut,0);d(this,tt);d(this,G,null);d(this,et,-1);d(this,$t,t=>{let i=e(this,tt).position,s=e(this,tt).paused,o=e(this,M).width,r=e(this,M).height;if(!e(this,b).enabled||o===0)return;if(s){c(this,et,-1);return}let n=Math.abs(i-e(this,et));if(e(this,et)>=0&&n>e(this,b).seekThreshold){for(let v=0;v<e(this,I).length;v++){let l=e(this,I)[v];l.el&&(e(this,M).removeElement(l.el),e(this,V).release(l.el)),l.mode===1?e(this,T).releaseScroll(l.track):l.mode===5?e(this,T).releaseTop(l.track):l.mode===6&&e(this,T).releaseBottom(l.track);}c(this,I,[]),e(this,G)?.reset();}c(this,et,i);let a=e(this,ut)?Math.min((t-e(this,ut))/1e3,.05):0;c(this,ut,t);let m=o/8*e(this,b).speed,k=e(this,b).fontSize+e(this,b).padding*2+4,B=i*1e3,S=e(this,q).emitBatch(B);for(let v=0;v<S.length;v++)E(this,Y,Vt).call(this,S[v],i,m,k,o,r);let u=performance.now()/1e3,U=v=>{v.el&&(e(this,M).hideElement(v.el),e(this,M).removeElement(v.el),e(this,V).release(v.el),v.el=void 0),v.mode===1?e(this,T).releaseScroll(v.track):v.mode===5?e(this,T).releaseTop(v.track):v.mode===6&&e(this,T).releaseBottom(v.track);},R=e(this,q).compact(e(this,I),u,a,m,U);e(this,I).length=R;for(let v=0;v<e(this,I).length;v++){let l=e(this,I)[v];l.el&&e(this,M).positionElement(l.el,l.x,l.y,l.mode,l.h);}e(this,G)?.probe(i,e(this,q));});if(!(t.container instanceof HTMLElement))throw new TypeError("container must be an HTMLElement");if(!t.adapter)throw new TypeError("adapter is required");c(this,b,{...Dt,...t}),c(this,tt,t.adapter),c(this,M,new Mt(t.container)),c(this,T,new it),c(this,V,new It),c(this,q,new ot),t.dataSource&&c(this,G,new at(t.dataSource,e(this,b).preBuffer,e(this,b).leadTime,e(this,b).seekThreshold,t.onError)),E(this,Y,At).call(this),c(this,ct,new rt(e(this,b).fps,e(this,$t)));}get isDestroyed(){return e(this,A)}load(t){e(this,A)||(e(this,V).releaseAll(e(this,I).map(i=>i.el).filter(Boolean)),c(this,I,[]),e(this,G)?.reset(),e(this,q).load(t));}send(t){if(e(this,A)||!e(this,b).enabled)return;let i=e(this,tt).position,s=e(this,M).width,o=e(this,M).height;if(s===0||o===0)return;let r=s/8*e(this,b).speed,n=e(this,b).fontSize+e(this,b).padding*2+4,a={...t,time:i};E(this,Y,Vt).call(this,a,i,r,n,s,o,true);}clear(){e(this,A)||(e(this,V).releaseAll(e(this,I).map(t=>t.el).filter(Boolean)),c(this,I,[]),e(this,q).clear());}resize(){e(this,A)||e(this,M).width>0&&E(this,Y,At).call(this);}destroy(){e(this,A)||(c(this,A,true),e(this,ct).stop(),e(this,G)?.destroy(),e(this,V).releaseAll(e(this,I).map(t=>t.el).filter(Boolean)),c(this,I,[]),e(this,M).destroy());}setEnabled(t){e(this,A)||(e(this,b).enabled=t,e(this,M).root.style.display=t?"":"none");}setFps(t){e(this,A)||(e(this,b).fps=W(t,1,120),e(this,ct).setFps(e(this,b).fps));}setArea(t){e(this,A)||(e(this,b).area=W(t,0,1),E(this,Y,At).call(this));}setOpacity(t){e(this,A)||(e(this,b).opacity=W(t,0,1),e(this,M).root.style.opacity=String(e(this,b).opacity));}setSpeed(t){e(this,A)||(e(this,b).speed=Math.max(.1,t));}setFontFamily(t){e(this,b).fontFamily=t;}setFontSize(t){e(this,b).fontSize=W(t,8,128);}setFontWeight(t){e(this,b).fontWeight=t;}setStrokeWidth(t){e(this,b).strokeWidth=Math.max(0,t);}setStrokeColor(t){e(this,b).strokeColor=t&16777215;}setPadding(t){e(this,b).padding=Math.max(0,t);}setDuration(t){e(this,b).duration=Math.max(.5,t);}setOverflow(t){e(this,b).overflow=t;}setMaxVisible(t){e(this,b).maxVisible=Math.max(0,t);}setMaxCache(t){}setPreCacheCount(t){}setSmoothing(t){}setWillChange(t){e(this,A)||(e(this,b).willChange=t);}setUseTextShadow(t){e(this,A)||(e(this,b).useTextShadow=t);}};A=new WeakMap,b=new WeakMap,M=new WeakMap,T=new WeakMap,V=new WeakMap,ct=new WeakMap,q=new WeakMap,I=new WeakMap,ut=new WeakMap,tt=new WeakMap,G=new WeakMap,et=new WeakMap,$t=new WeakMap,Y=new WeakSet,Vt=function(t,i,s,o,r,n,a){let m=t.mode??1,k=t.text??"";if(!k)return;let B=t.color??16777215,S=t.font_size??e(this,b).fontSize,u=e(this,b),R=Gt(k,u.fontFamily,S,u.fontWeight)+u.padding*2,v=S;if(!a&&u.maxVisible>0&&e(this,I).length>=u.maxVisible&&u.overflow==="drop")return;let l=null;if(m===1){if(l=e(this,T).acquireScroll(i,R,s,r),!l){if(u.overflow==="drop"&&!a)return;let $=Math.random()*e(this,T).scrollTrackCount|0;l={track:$,y:($+.5)*o};}}else if(m===5){if(l=e(this,T).acquireTop(i,u.duration),!l){if(u.overflow==="drop"&&!a)return;let $=Math.random()*e(this,T).topTrackCount|0;l={track:$,y:($+.5)*o};}}else if(m===6){if(l=e(this,T).acquireBottom(i,u.duration),!l){if(u.overflow==="drop"&&!a)return;let $=Math.random()*e(this,T).bottomTrackCount|0;l={track:$,y:n*u.area-($+.5)*o};}}else if(l=e(this,T).acquireScroll(i,R,s,r),!l)if(a){let $=Math.random()*e(this,T).scrollTrackCount|0;l={track:$,y:($+.5)*o};}else return;let g=Zt(u.fontFamily,S,u.fontWeight),H=u.useTextShadow?Nt(u.strokeWidth,st(u.strokeColor)):"none",C=u.willChange?"transform":"auto",f=e(this,V).acquire();f.textContent=k,f.style.font=g,f.style.color=st(B),f.style.textShadow=H,f.style.willChange=C,f.style.position="absolute",f.style.left="0",f.style.top="0",f.style.whiteSpace="nowrap",f.style.pointerEvents="none",f.style.userSelect="none",f.style.display="",f.style.opacity=String(u.opacity),e(this,M).appendElement(f);let _={id:t.id,text:k,mode:m,color:B,fontSize:S,x:m===1?r:r/2,y:l.y,track:l.track,w:R,h:v,born:performance.now()/1e3,duration:u.duration,el:f};e(this,I).push(_);},At=function(){let t=e(this,M).height;if(t===0)return;let i=e(this,b),s=i.fontSize+i.padding*2+4;e(this,T).resize(t,i.area,s);};function Kt(h,t){if(!(t.container instanceof HTMLElement))throw new TypeError("container must be an HTMLElement");if(t.container instanceof HTMLVideoElement)throw new TypeError('container cannot be a <video> element. Video uses a native rendering surface that hides child elements. Wrap the video in a <div> and use that as the container. Example: <div style="position:relative"><video .../><div id="overlay"></div></div>');switch(h){case "canvas":return new Et(t);case "dom":return new Bt(t);default:throw new TypeError(`Unknown engine type: "${h}". Use "canvas" or "dom".`)}}export{dt as DanmakuMode,Kt as createEngine};//# sourceMappingURL=index.min.js.map
var Yt=h=>{throw TypeError(h)};var Rt=(h,t,i)=>t.has(h)||Yt("Cannot "+i);var e=(h,t,i)=>(Rt(h,t,"read from private field"),i?i.call(h):t.get(h)),f=(h,t,i)=>t.has(h)?Yt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(h):t.set(h,i),c=(h,t,i,s)=>(Rt(h,t,"write to private field"),t.set(h,i),i),C=(h,t,i)=>(Rt(h,t,"access private method"),i);var Lt=(h,t,i,s)=>({set _(o){c(h,t,o);},get _(){return e(h,t,s)}});var ft=(s=>(s[s.Scroll=1]="Scroll",s[s.Top=5]="Top",s[s.Bottom=6]="Bottom",s))(ft||{});var Ct=class{constructor(t){this.W=0;this.H=0;this.dpr=1;this.container=t;let i=document.createElement("canvas");i.style.position="absolute",i.style.inset="0",i.style.width="100%",i.style.height="100%",i.style.pointerEvents="none",t.appendChild(i),this.canvas=i,this.ctx=i.getContext("2d"),this.updateDimensions();}updateDimensions(){let t=window.devicePixelRatio||1,i=this.container.clientWidth,s=this.container.clientHeight;return i===0||s===0?false:(this.dpr=t,this.W=i,this.H=s,this.canvas.width=i*t,this.canvas.height=s*t,this.canvas.style.width=i+"px",this.canvas.style.height=s+"px",this.ctx.setTransform(t,0,0,t,0,0),true)}get width(){return this.W}get height(){return this.H}get devicePixelRatio(){return this.dpr}clear(){this.ctx.clearRect(0,0,this.W,this.H);}setSmoothing(t){this.ctx.imageSmoothingEnabled=t;}setGlobalAlpha(t){this.ctx.globalAlpha=t;}destroy(){this.canvas.remove();}};var et=class{constructor(){this.scrollCount=0;this.scrollFree=[];this.scrollExit=new Float64Array(0);this.topCount=0;this.topFree=[];this.topExit=new Float64Array(0);this.bottomCount=0;this.bottomFree=[];this.bottomExit=new Float64Array(0);this.H=0;this.th=0;this.areaFraction=.75;}resize(t,i,s){this.H=t,this.th=s,this.areaFraction=i;let o=t*i,r=Math.max(1,Math.floor(o/s)),n=Math.max(1,Math.floor(o*.48/s));this.scrollCount=r,this.topCount=n,this.bottomCount=n,this.scrollExit=new Float64Array(r).fill(-1/0),this.topExit=new Float64Array(n).fill(-1/0),this.bottomExit=new Float64Array(n).fill(-1/0),this.scrollFree=Array.from({length:r},(a,l)=>l),this.topFree=Array.from({length:n},(a,l)=>l),this.bottomFree=Array.from({length:n},(a,l)=>l);}acquireScroll(t,i,s,o){let r=[];for(;this.scrollFree.length>0;){let a=this.scrollFree.pop();if(this.scrollExit[a]<=t){this.scrollExit[a]=t+i*1.2/s;for(let l of r)this.scrollFree.push(l);return {track:a,y:this.scrollY(a)}}r.push(a);}for(let a of r)this.scrollFree.push(a);let n=Math.random()*this.scrollCount|0;for(let a=0;a<this.scrollCount;a++){let l=(n+a)%this.scrollCount;if(this.scrollExit[l]<=t){this.scrollExit[l]=t+i*1.2/s;let k=this.scrollFree.indexOf(l);return k!==-1&&this.scrollFree.splice(k,1),{track:l,y:this.scrollY(l)}}}return null}releaseScroll(t){this.scrollExit[t]=-1/0,this.scrollFree.includes(t)||this.scrollFree.push(t);}acquireTop(t,i){let s=[];for(;this.topFree.length>0;){let r=this.topFree.pop();if(this.topExit[r]<=t){this.topExit[r]=t+i;for(let n of s)this.topFree.push(n);return {track:r,y:this.fixedY(r,true)}}s.push(r);}for(let r of s)this.topFree.push(r);let o=Math.random()*this.topCount|0;for(let r=0;r<this.topCount;r++){let n=(o+r)%this.topCount;if(this.topExit[n]<=t){this.topExit[n]=t+i;let a=this.topFree.indexOf(n);return a!==-1&&this.topFree.splice(a,1),{track:n,y:this.fixedY(n,true)}}}return null}releaseTop(t){this.topExit[t]=-1/0,this.topFree.includes(t)||this.topFree.push(t);}acquireBottom(t,i){let s=[];for(;this.bottomFree.length>0;){let r=this.bottomFree.pop();if(this.bottomExit[r]<=t){this.bottomExit[r]=t+i;for(let n of s)this.bottomFree.push(n);return {track:r,y:this.fixedY(r,false)}}s.push(r);}for(let r of s)this.bottomFree.push(r);let o=Math.random()*this.bottomCount|0;for(let r=0;r<this.bottomCount;r++){let n=(o+r)%this.bottomCount;if(this.bottomExit[n]<=t){this.bottomExit[n]=t+i;let a=this.bottomFree.indexOf(n);return a!==-1&&this.bottomFree.splice(a,1),{track:n,y:this.fixedY(n,false)}}}return null}releaseBottom(t){this.bottomExit[t]=-1/0,this.bottomFree.includes(t)||this.bottomFree.push(t);}get scrollTrackCount(){return this.scrollCount}get topTrackCount(){return this.topCount}get bottomTrackCount(){return this.bottomCount}scrollY(t){return (t+.5)*this.th}fixedY(t,i){return i?(t+.5)*this.th:this.H*this.areaFraction-(t+.5)*this.th}};var St=class{constructor(){this.pool=[];}acquire(){return this.pool.length>0?this.pool.pop():{}}release(t){this.pool.length<512&&(t.bmp=void 0,t.el=void 0,this.pool.push(t));}releaseAll(t){for(let i=0;i<t.length;i++)this.release(t[i]);}get size(){return this.pool.length}};function it(h){return h<0||h>16777215||!Number.isFinite(h)?"#000000":"#"+h.toString(16).padStart(6,"0")}function bt({fontFamily:h,fontSize:t,fontWeight:i}){return `${i} ${t}px ${h}`}var Dt=class{constructor(t=500){this.textWidths=new Map;this.bitmaps=new Map;this.aliveBitmaps=new Set;this.accessCounter=0;this.dpr=1;this.cachedFont="";this.fontFamily="";this.fontSize=0;this.fontWeight="";this.maxCache=t;}measure(t,i,s,o,r){let n=`${t}|${i}|${s}|${o}`,a=this.textWidths.get(n);if(a!==void 0)return a;r.font=bt({fontFamily:i,fontSize:s,fontWeight:o});let l=r.measureText(t).width;return this.textWidths.set(n,l),l}invalidateTextCache(){this.textWidths.clear();}getBitmap(t,i,s,o,r,n,a,l,k){let B=`${t}|${i}|${s}|${o}|${r}|${n}|${a}|${l}`,A=this.bitmaps.get(B);if(A)return A.accessId=++this.accessCounter,A.bitmap;(n!==this.fontFamily||i!==this.fontSize||a!==this.fontWeight)&&(this.fontFamily=n,this.fontSize=i,this.fontWeight=a,this.cachedFont=bt({fontFamily:n,fontSize:i,fontWeight:a}));let u=this.textWidths.get(`${t}|${n}|${i}|${a}`);if(u===void 0)throw new Error(`Text width not cached for "${t}". Call measure() first.`);let Y=Math.ceil(u)+k*2,z=i+k*2,O=Y*l|0,p=z*l|0,m=k*l,S=p/2,x=new OffscreenCanvas(O,p),b=x.getContext("2d");b.font=`${a} ${i*l}px ${n}`,b.lineWidth=o*l,b.lineJoin="round",b.textBaseline="middle",b.textAlign="left",b.strokeStyle=it(r),b.strokeText(t,m,S),b.fillStyle=it(s),b.fillText(t,m,S);let U=x.transferToImageBitmap();return this.bitmaps.set(B,{bitmap:U,accessId:++this.accessCounter}),this.aliveBitmaps.add(U),this.bitmaps.size>this.maxCache&&this.evictOne(),U}evictOne(){let t="",i=1/0;for(let[s,o]of this.bitmaps)o.accessId<i&&(i=o.accessId,t=s);if(t){let s=this.bitmaps.get(t);s&&(this.aliveBitmaps.delete(s.bitmap),s.bitmap.close(),this.bitmaps.delete(t));}}isAlive(t){return this.aliveBitmaps.has(t)}setMaxCache(t){for(this.maxCache=t;this.bitmaps.size>this.maxCache;)this.evictOne();}setDpr(t){this.dpr!==t&&(this.dpr=t,this.clearBitmaps());}clearBitmaps(){for(let[,t]of this.bitmaps)this.aliveBitmaps.delete(t.bitmap),t.bitmap.close();this.bitmaps.clear();}clearAll(){this.clearBitmaps(),this.textWidths.clear();}get bitmapCount(){return this.bitmaps.size}};var vt,st=class{constructor(t,i,s=true){this.rafId=0;this.lastFrameTime=-1;this.stopped=false;f(this,vt,t=>{this.stopped||(this.tick(t),this.rafId=requestAnimationFrame(e(this,vt)));});this.frameInterval=1e3/t,this.callback=i,s&&this.start();}start(){this.rafId!==0||this.stopped||(this.rafId=requestAnimationFrame(e(this,vt)));}tick(t){if(this.stopped)return false;if(this.lastFrameTime<0)return this.lastFrameTime=t,this.callback(t),true;let i=t-this.lastFrameTime;return i>=this.frameInterval?(this.lastFrameTime=t-i%this.frameInterval,this.callback(t),true):false}setFps(t){this.frameInterval=1e3/t;}stop(){this.stopped=true,this.rafId!==0&&(cancelAnimationFrame(this.rafId),this.rafId=0);}};vt=new WeakMap;function W(h,t,i){return h<t?t:h>i?i:h}function Tt(h,t,i,s=0,o=h.length){for(;s<o;){let r=s+o>>1;i(h[r])<=t?s=r+1:o=r;}return s}var rt=class{constructor(){this.pool=[];this.cursor=0;}load(t){this.pool=[...t].sort((i,s)=>i.time-s.time),this.cursor=0;}clear(){this.pool=[],this.cursor=0;}emitBatch(t){if(this.pool.length===0)return [];let i=this.cursor<this.pool.length?(this.pool[this.cursor]?.time??0)*1e3:1/0;if(t<i-200&&(this.cursor=Tt(this.pool,t,r=>(r.time??0)*1e3)),this.cursor>=this.pool.length)return [];let s=Tt(this.pool,t,r=>(r.time??0)*1e3);if(s<=this.cursor)return [];let o=this.pool.slice(this.cursor,s);return this.cursor=s,o}compact(t,i,s,o,r){let n=0;for(let a=0;a<t.length;a++){let l=t[a];if(l.mode===1){if(l.x-=o*s,l.x+l.w<-10){r(l);continue}}else if(i-l.born>=l.duration){r(l);continue}n!==a&&(t[n]=t[a]),n++;}return n}preCacheInfo(){return {pool:this.pool,cursor:this.cursor}}add(t){if(t.length===0)return;let i=new Set;for(let a=0;a<this.pool.length;a++)i.add(this.pool[a].id);let s=[...t].filter(a=>!i.has(a.id)).sort((a,l)=>a.time-l.time);if(s.length===0)return;let o=[],r=0,n=0;for(;r<this.pool.length&&n<s.length;)this.pool[r].time<=s[n].time?(o.push(this.pool[r]),r++):(o.push(s[n]),n++);for(;r<this.pool.length;)o.push(this.pool[r++]);for(;n<s.length;)o.push(s[n++]);this.pool=o;}evictBefore(t){if(this.pool.length===0)return;let i=Tt(this.pool,t*1e3-.1,s=>(s.time??0)*1e3);i!==0&&(this.pool.splice(0,i),this.cursor=Math.max(0,this.cursor-i));}};var zt=new Map;typeof window<"u"&&!window.requestIdleCallback&&(window.requestIdleCallback=function(h,t){let i=t?.timeout,s=Date.now(),o=0,r={didTimeout:false,timeRemaining:()=>Math.max(0,50-(Date.now()-s))};i!=null&&(o=setTimeout(()=>{r.didTimeout=true,s=Date.now(),h(r);},i));let n=requestAnimationFrame(()=>{i!=null&&clearTimeout(o),!r.didTimeout&&(s=Date.now(),h(r));}),a=Date.now()+Math.random();return zt.set(a,{rafId:n,timeoutId:o}),a},window.cancelIdleCallback=function(h){let t=zt.get(h);t&&(cancelAnimationFrame(t.rafId),t.timeoutId&&clearTimeout(t.timeoutId),zt.delete(h));});function Ut(h,t,i,s){let o=0,r=t;function n(a){let l=Math.min(t+i,h.length),k=0;for(;r<l&&(a.timeRemaining()>1||k<5);){let B=h[r];B&&s(B),r++,k++;}r<l&&(o=requestIdleCallback(n,{timeout:2e3}));}return o=requestIdleCallback(n,{timeout:2e3}),()=>cancelIdleCallback(o)}var Et={enabled:true,fps:60,area:.75,fontFamily:"sans-serif",fontSize:25,fontWeight:"bold",opacity:1,padding:4,strokeWidth:1.25,strokeColor:0,speed:1,seekThreshold:.2,duration:4,overflow:"drop",maxVisible:0,maxCache:500,preCacheCount:50,smoothing:true,willChange:true,useTextShadow:true,preBuffer:60,leadTime:0};var gt,xt,ot,yt,wt,R,J,j,K,X,jt,Xt,Nt,nt=class{constructor(t,i,s,o,r){f(this,X);f(this,gt);f(this,xt);f(this,ot);f(this,yt);f(this,wt);f(this,R,[]);f(this,J,0);f(this,j,null);f(this,K,-1);c(this,gt,t),c(this,xt,Math.max(1,i)),c(this,ot,Math.max(0,s)),c(this,yt,Math.max(.5,o*2.5)),c(this,wt,r);}probe(t,i){if(e(this,K)>=0&&Math.abs(t-e(this,K))>e(this,yt)&&this.reset(),c(this,K,t),e(this,ot)>0){let r=t-e(this,ot);i.evictBefore(r),c(this,R,e(this,R).filter(n=>n.end>r));}if(e(this,j))return;let s=t+e(this,xt),o=C(this,X,jt).call(this,t,s);o&&C(this,X,Xt).call(this,o.start,o.end,i);}reset(){Lt(this,J)._++,c(this,j,null),c(this,R,[]),c(this,K,-1);}destroy(){this.reset();}};gt=new WeakMap,xt=new WeakMap,ot=new WeakMap,yt=new WeakMap,wt=new WeakMap,R=new WeakMap,J=new WeakMap,j=new WeakMap,K=new WeakMap,X=new WeakSet,jt=function(t,i){let s=t;for(let o of e(this,R))if(o.start<=s&&s<o.end){if(s=o.end,s>=i)return null}else if(o.start>s)return {start:s,end:Math.min(o.start,i)};return s<i?{start:s,end:i}:null},Xt=function(t,i,s){let o=++Lt(this,J)._;c(this,j,e(this,gt).fetch(t,i).then(r=>{o===e(this,J)&&(c(this,j,null),r.length>0&&s.add(r),C(this,X,Nt).call(this,{start:t,end:i}));}).catch(r=>{var n;o===e(this,J)&&(c(this,j,null),(n=e(this,wt))==null||n.call(this,r instanceof Error?r:new Error(String(r))));}));},Nt=function(t){e(this,R).push(t),e(this,R).sort((s,o)=>s.start-o.start);let i=[];for(let s of e(this,R)){let o=i[i.length-1];o&&o.end>=s.start?o.end=Math.max(o.end,s.end):i.push({...s});}c(this,R,i);};var g,d,y,D,P,w,ht,V,M,lt,N,Q,Z,mt,Ft,H,Wt,Pt,at,Mt=class{constructor(t){f(this,H);f(this,g,false);f(this,d);f(this,y);f(this,D);f(this,P);f(this,w);f(this,ht);f(this,V);f(this,M,[]);f(this,lt,0);f(this,N,null);f(this,Q);f(this,Z,null);f(this,mt,-1);f(this,Ft,t=>{let i=e(this,Q).position,s=e(this,Q).paused,o=e(this,y).width,r=e(this,y).height;if(!e(this,d).enabled||o===0){e(this,y).clear();return}if(s)return;let n=Math.abs(i-e(this,mt));if(e(this,mt)>=0&&n>e(this,d).seekThreshold){for(let m=0;m<e(this,M).length;m++){let S=e(this,M)[m];S.mode===1?e(this,D).releaseScroll(S.track):S.mode===5?e(this,D).releaseTop(S.track):S.mode===6&&e(this,D).releaseBottom(S.track),e(this,P).release(S);}c(this,M,[]),e(this,y).clear(),e(this,Z)?.reset();}c(this,mt,i);let a=e(this,lt)?Math.min((t-e(this,lt))/1e3,.05):0;c(this,lt,t);let l=o/8*e(this,d).speed,k=Math.max(2,Math.ceil(e(this,d).fontSize*.2)),B=e(this,d).fontSize+e(this,d).padding*2+k,A=i*1e3,u=e(this,V).emitBatch(A);for(let m=0;m<u.length;m++)C(this,H,Wt).call(this,u[m],i,l,B,o,r);let Y=performance.now()/1e3,z=m=>{m.mode===1?e(this,D).releaseScroll(m.track):m.mode===5?e(this,D).releaseTop(m.track):m.mode===6&&e(this,D).releaseBottom(m.track),e(this,P).release(m);};e(this,M).length=e(this,V).compact(e(this,M),Y,a,l,z),e(this,y).clear(),e(this,y).setGlobalAlpha(e(this,d).opacity);let O=e(this,y).devicePixelRatio,p=e(this,d).padding;for(let m=0;m<e(this,M).length;m++){let S=e(this,M)[m],x=S.bmp;if(!x)continue;if(!e(this,w).isAlive(x)){S.bmp=void 0;continue}let b=S.x|0,U=S.y|0,$=x.width,Ht=x.height,Ot=$/O,kt=Ht/O,qt=e(this,y).ctx;S.mode===1?qt.drawImage(x,0,0,$,Ht,b-p,U-kt/2|0,Ot,kt):qt.drawImage(x,0,0,$,Ht,b-Ot/2|0,U-kt/2|0,Ot,kt);}C(this,H,Pt).call(this),e(this,Z)?.probe(i,e(this,V));});if(!(t.container instanceof HTMLElement))throw new TypeError("container must be an HTMLElement");if(!t.adapter)throw new TypeError("adapter is required");c(this,d,{...Et,...t}),c(this,Q,t.adapter),c(this,y,new Ct(t.container)),e(this,y).setSmoothing(e(this,d).smoothing),c(this,D,new et),c(this,P,new St),c(this,w,new Dt(e(this,d).maxCache)),c(this,V,new rt),t.dataSource&&c(this,Z,new nt(t.dataSource,e(this,d).preBuffer,e(this,d).leadTime,e(this,d).seekThreshold,t.onError)),C(this,H,at).call(this),c(this,ht,new st(e(this,d).fps,e(this,Ft)));}get isDestroyed(){return e(this,g)}load(t){var i;e(this,g)||(e(this,P).releaseAll(e(this,M)),c(this,M,[]),e(this,w).clearAll(),e(this,Z)?.reset(),e(this,V).load(t),(i=e(this,N))==null||i.call(this),c(this,N,null),C(this,H,Pt).call(this));}send(t){if(e(this,g)||!e(this,d).enabled)return;let i=e(this,Q).position,s=e(this,y).width,o=e(this,y).height;if(s===0||o===0)return;let r=s/8*e(this,d).speed,n=Math.max(2,Math.ceil(e(this,d).fontSize*.2)),a=e(this,d).fontSize+e(this,d).padding*2+n,l={...t,time:i};C(this,H,Wt).call(this,l,i,r,a,s,o,true);}clear(){e(this,g)||(e(this,P).releaseAll(e(this,M)),c(this,M,[]),e(this,V).clear(),e(this,w).clearAll(),e(this,y).clear());}resize(){if(e(this,g))return;e(this,y).updateDimensions()&&(e(this,w).setDpr(e(this,y).devicePixelRatio),e(this,w).invalidateTextCache(),C(this,H,at).call(this));}destroy(){var t;e(this,g)||(c(this,g,true),e(this,ht).stop(),(t=e(this,N))==null||t.call(this),e(this,Z)?.destroy(),e(this,P).releaseAll(e(this,M)),c(this,M,[]),e(this,w).clearAll(),e(this,y).destroy());}setEnabled(t){e(this,g)||(e(this,d).enabled=t,t||e(this,y).clear());}setFps(t){e(this,g)||(e(this,d).fps=W(t,1,120),e(this,ht).setFps(e(this,d).fps));}setArea(t){e(this,g)||(e(this,d).area=W(t,0,1),C(this,H,at).call(this));}setOpacity(t){e(this,g)||(e(this,d).opacity=W(t,0,1));}setSpeed(t){e(this,g)||(e(this,d).speed=Math.max(.1,t));}setFontFamily(t){e(this,g)||(e(this,d).fontFamily=t,e(this,w).invalidateTextCache(),e(this,w).clearBitmaps());}setFontSize(t){e(this,g)||(e(this,d).fontSize=W(t,8,128),e(this,w).invalidateTextCache(),e(this,w).clearBitmaps(),C(this,H,at).call(this));}setFontWeight(t){e(this,g)||(e(this,d).fontWeight=t,e(this,w).invalidateTextCache(),e(this,w).clearBitmaps());}setStrokeWidth(t){e(this,g)||(e(this,d).strokeWidth=Math.max(0,t),e(this,w).clearBitmaps());}setStrokeColor(t){e(this,g)||(e(this,d).strokeColor=t&16777215,e(this,w).clearBitmaps());}setPadding(t){e(this,g)||(e(this,d).padding=Math.max(0,t),e(this,w).clearBitmaps(),C(this,H,at).call(this));}setDuration(t){e(this,g)||(e(this,d).duration=Math.max(.5,t));}setOverflow(t){e(this,g)||(e(this,d).overflow=t);}setMaxVisible(t){e(this,g)||(e(this,d).maxVisible=Math.max(0,t));}setMaxCache(t){e(this,g)||(e(this,d).maxCache=Math.max(10,t),e(this,w).setMaxCache(e(this,d).maxCache));}setPreCacheCount(t){e(this,g)||(e(this,d).preCacheCount=Math.max(0,t));}setSmoothing(t){e(this,g)||(e(this,d).smoothing=t,e(this,y).setSmoothing(t));}setWillChange(t){}setUseTextShadow(t){}};g=new WeakMap,d=new WeakMap,y=new WeakMap,D=new WeakMap,P=new WeakMap,w=new WeakMap,ht=new WeakMap,V=new WeakMap,M=new WeakMap,lt=new WeakMap,N=new WeakMap,Q=new WeakMap,Z=new WeakMap,mt=new WeakMap,Ft=new WeakMap,H=new WeakSet,Wt=function(t,i,s,o,r,n,a){let l=t.mode??1,k=t.text??"";if(!k)return;let B=t.color??16777215,A=t.font_size??e(this,d).fontSize,u=e(this,d),Y=e(this,y).ctx,O=e(this,w).measure(k,u.fontFamily,A,u.fontWeight,Y)+u.padding*2,p=A;if(!a&&u.maxVisible>0&&e(this,M).length>=u.maxVisible&&u.overflow==="drop")return;let m=null;if(l===1){if(m=e(this,D).acquireScroll(i,O,s,r),!m){if(u.overflow==="drop"&&!a)return;let b=Math.random()*e(this,D).scrollTrackCount|0;m={track:b,y:(b+.5)*o};}}else if(l===5){if(m=e(this,D).acquireTop(i,u.duration),!m){if(u.overflow==="drop"&&!a)return;let b=Math.random()*e(this,D).topTrackCount|0;m={track:b,y:(b+.5)*o};}}else if(l===6){if(m=e(this,D).acquireBottom(i,u.duration),!m){if(u.overflow==="drop"&&!a)return;let b=Math.random()*e(this,D).bottomTrackCount|0;m={track:b,y:n*u.area-(b+.5)*o};}}else if(m=e(this,D).acquireScroll(i,O,s,r),!m)if(a){let b=Math.random()*e(this,D).scrollTrackCount|0;m={track:b,y:(b+.5)*o};}else return;let S=e(this,w).getBitmap(k,A,B,u.strokeWidth,u.strokeColor,u.fontFamily,u.fontWeight,e(this,y).devicePixelRatio,u.padding),x=e(this,P).acquire();x.id=t.id,x.text=k,x.mode=l,x.color=B,x.fontSize=A,x.x=l===1?r:r/2,x.y=m.y,x.track=m.track,x.w=O,x.h=p,x.born=performance.now()/1e3,x.duration=u.duration,x.bmp=S,e(this,M).push(x);},Pt=function(){if(e(this,N)||e(this,g))return;let{pool:t,cursor:i}=e(this,V).preCacheInfo(),s=e(this,d);c(this,N,Ut(t,i,s.preCacheCount,o=>{let r=o.text??"",n=o.font_size??s.fontSize,a=o.color??16777215;e(this,w).measure(r,s.fontFamily,n,s.fontWeight,e(this,y).ctx);try{e(this,w).getBitmap(r,n,a,s.strokeWidth,s.strokeColor,s.fontFamily,s.fontWeight,e(this,y).devicePixelRatio,s.padding);}catch{}}));},at=function(){let t=e(this,y).height;if(t===0)return;let i=e(this,d),s=Math.max(2,Math.ceil(i.fontSize*.2)),o=i.fontSize+i.padding*2+s;e(this,D).resize(t,i.area,o);};function Zt(h,t){let i=h;return [`-${i}px -${i}px 0 ${t}`,`0px -${i}px 0 ${t}`,`${i}px -${i}px 0 ${t}`,`-${i}px 0px 0 ${t}`,`${i}px 0px 0 ${t}`,`-${i}px ${i}px 0 ${t}`,`0px ${i}px 0 ${t}`,`${i}px ${i}px 0 ${t}`].join(",")}function Gt(h,t,i){return `${i} ${t}px ${h}`}var It=class{constructor(t){this.container=t;let i=document.createElement("div");i.style.position="absolute",i.style.inset="0",i.style.overflow="hidden",i.style.pointerEvents="none",i.style.userSelect="none",t.appendChild(i),this.root=i;}get width(){return this.container.clientWidth}get height(){return this.container.clientHeight}createElement(t){let i=document.createElement("div");return i.style.position="absolute",i.style.left="0",i.style.top="0",i.style.whiteSpace="nowrap",i.style.font=t.font,i.style.color=t.fillColor,i.style.textShadow=t.textShadow,i.style.willChange=t.willChange,i.style.pointerEvents="none",i.style.userSelect="none",i}configureElement(t,i,s){t.textContent=i,t.style.font=s.font,t.style.color=s.fillColor,t.style.textShadow=s.textShadow,t.style.willChange=s.willChange;}positionElement(t,i,s,o,r){let n=Math.round(i),a=Math.round(s-r/2);o===1?t.style.transform=`translate3d(${n}px, ${a}px, 0)`:t.style.transform=`translate3d(${n}px, ${a}px, 0) translateX(-50%)`;}hideElement(t){t.style.display="none";}showElement(t){t.style.display="";}appendElement(t){this.root.appendChild(t);}removeElement(t){t.parentNode===this.root&&this.root.removeChild(t);}destroy(){this.root.remove();}};var At=class{constructor(){this.pool=[];}acquire(){return this.pool.length>0?this.pool.pop():document.createElement("div")}release(t){this.pool.length<512&&(t.style.display="none",t.parentNode&&t.parentNode.removeChild(t),t.style.transform="",t.textContent="",this.pool.push(t));}releaseAll(t){for(let i=0;i<t.length;i++)this.release(t[i]);}get size(){return this.pool.length}};var Vt=null;function Kt(){if(!Vt){let h=document.createElement("canvas");h.width=h.height=1,Vt=h.getContext("2d");}return Vt}function Jt(h,t,i,s){let o=Kt();return o.font=bt({fontFamily:t,fontSize:i,fontWeight:s}),o.measureText(h).width}var T,v,F,E,_,ut,q,I,dt,tt,G,pt,$t,L,_t,ct,Bt=class{constructor(t){f(this,L);f(this,T,false);f(this,v);f(this,F);f(this,E);f(this,_);f(this,ut);f(this,q);f(this,I,[]);f(this,dt,0);f(this,tt);f(this,G,null);f(this,pt,-1);f(this,$t,t=>{let i=e(this,tt).position,s=e(this,tt).paused,o=e(this,F).width,r=e(this,F).height;if(!e(this,v).enabled||o===0||s)return;let n=Math.abs(i-e(this,pt));if(e(this,pt)>=0&&n>e(this,v).seekThreshold){for(let p=0;p<e(this,I).length;p++){let m=e(this,I)[p];m.el&&(e(this,F).removeElement(m.el),e(this,_).release(m.el)),m.mode===1?e(this,E).releaseScroll(m.track):m.mode===5?e(this,E).releaseTop(m.track):m.mode===6&&e(this,E).releaseBottom(m.track);}c(this,I,[]),e(this,G)?.reset();}c(this,pt,i);let a=e(this,dt)?Math.min((t-e(this,dt))/1e3,.05):0;c(this,dt,t);let l=o/8*e(this,v).speed,k=Math.max(2,Math.ceil(e(this,v).fontSize*.2)),B=e(this,v).fontSize+e(this,v).padding*2+k,A=i*1e3,u=e(this,q).emitBatch(A);for(let p=0;p<u.length;p++)C(this,L,_t).call(this,u[p],i,l,B,o,r);let Y=performance.now()/1e3,z=p=>{p.el&&(e(this,F).hideElement(p.el),e(this,F).removeElement(p.el),e(this,_).release(p.el),p.el=void 0),p.mode===1?e(this,E).releaseScroll(p.track):p.mode===5?e(this,E).releaseTop(p.track):p.mode===6&&e(this,E).releaseBottom(p.track);},O=e(this,q).compact(e(this,I),Y,a,l,z);e(this,I).length=O;for(let p=0;p<e(this,I).length;p++){let m=e(this,I)[p];m.el&&e(this,F).positionElement(m.el,m.x,m.y,m.mode,m.h);}e(this,G)?.probe(i,e(this,q));});if(!(t.container instanceof HTMLElement))throw new TypeError("container must be an HTMLElement");if(!t.adapter)throw new TypeError("adapter is required");c(this,v,{...Et,...t}),c(this,tt,t.adapter),c(this,F,new It(t.container)),c(this,E,new et),c(this,_,new At),c(this,q,new rt),t.dataSource&&c(this,G,new nt(t.dataSource,e(this,v).preBuffer,e(this,v).leadTime,e(this,v).seekThreshold,t.onError)),C(this,L,ct).call(this),c(this,ut,new st(e(this,v).fps,e(this,$t)));}get isDestroyed(){return e(this,T)}load(t){e(this,T)||(e(this,_).releaseAll(e(this,I).map(i=>i.el).filter(Boolean)),c(this,I,[]),e(this,G)?.reset(),e(this,q).load(t));}send(t){if(e(this,T)||!e(this,v).enabled)return;let i=e(this,tt).position,s=e(this,F).width,o=e(this,F).height;if(s===0||o===0)return;let r=s/8*e(this,v).speed,n=Math.max(2,Math.ceil(e(this,v).fontSize*.2)),a=e(this,v).fontSize+e(this,v).padding*2+n,l={...t,time:i};C(this,L,_t).call(this,l,i,r,a,s,o,true);}clear(){e(this,T)||(e(this,_).releaseAll(e(this,I).map(t=>t.el).filter(Boolean)),c(this,I,[]),e(this,q).clear());}resize(){e(this,T)||e(this,F).width>0&&C(this,L,ct).call(this);}destroy(){e(this,T)||(c(this,T,true),e(this,ut).stop(),e(this,G)?.destroy(),e(this,_).releaseAll(e(this,I).map(t=>t.el).filter(Boolean)),c(this,I,[]),e(this,F).destroy());}setEnabled(t){e(this,T)||(e(this,v).enabled=t,e(this,F).root.style.display=t?"":"none");}setFps(t){e(this,T)||(e(this,v).fps=W(t,1,120),e(this,ut).setFps(e(this,v).fps));}setArea(t){e(this,T)||(e(this,v).area=W(t,0,1),C(this,L,ct).call(this));}setOpacity(t){e(this,T)||(e(this,v).opacity=W(t,0,1),e(this,F).root.style.opacity=String(e(this,v).opacity));}setSpeed(t){e(this,T)||(e(this,v).speed=Math.max(.1,t));}setFontFamily(t){e(this,v).fontFamily=t;}setFontSize(t){e(this,T)||(e(this,v).fontSize=W(t,8,128),C(this,L,ct).call(this));}setFontWeight(t){e(this,v).fontWeight=t;}setStrokeWidth(t){e(this,v).strokeWidth=Math.max(0,t);}setStrokeColor(t){e(this,v).strokeColor=t&16777215;}setPadding(t){e(this,T)||(e(this,v).padding=Math.max(0,t),C(this,L,ct).call(this));}setDuration(t){e(this,v).duration=Math.max(.5,t);}setOverflow(t){e(this,v).overflow=t;}setMaxVisible(t){e(this,v).maxVisible=Math.max(0,t);}setMaxCache(t){}setPreCacheCount(t){}setSmoothing(t){}setWillChange(t){e(this,T)||(e(this,v).willChange=t);}setUseTextShadow(t){e(this,T)||(e(this,v).useTextShadow=t);}};T=new WeakMap,v=new WeakMap,F=new WeakMap,E=new WeakMap,_=new WeakMap,ut=new WeakMap,q=new WeakMap,I=new WeakMap,dt=new WeakMap,tt=new WeakMap,G=new WeakMap,pt=new WeakMap,$t=new WeakMap,L=new WeakSet,_t=function(t,i,s,o,r,n,a){let l=t.mode??1,k=t.text??"";if(!k)return;let B=t.color??16777215,A=t.font_size??e(this,v).fontSize,u=e(this,v),z=Jt(k,u.fontFamily,A,u.fontWeight)+u.padding*2,O=A;if(!a&&u.maxVisible>0&&e(this,I).length>=u.maxVisible&&u.overflow==="drop")return;let p=null;if(l===1){if(p=e(this,E).acquireScroll(i,z,s,r),!p){if(u.overflow==="drop"&&!a)return;let $=Math.random()*e(this,E).scrollTrackCount|0;p={track:$,y:($+.5)*o};}}else if(l===5){if(p=e(this,E).acquireTop(i,u.duration),!p){if(u.overflow==="drop"&&!a)return;let $=Math.random()*e(this,E).topTrackCount|0;p={track:$,y:($+.5)*o};}}else if(l===6){if(p=e(this,E).acquireBottom(i,u.duration),!p){if(u.overflow==="drop"&&!a)return;let $=Math.random()*e(this,E).bottomTrackCount|0;p={track:$,y:n*u.area-($+.5)*o};}}else if(p=e(this,E).acquireScroll(i,z,s,r),!p)if(a){let $=Math.random()*e(this,E).scrollTrackCount|0;p={track:$,y:($+.5)*o};}else return;let m=Gt(u.fontFamily,A,u.fontWeight),S=u.useTextShadow?Zt(u.strokeWidth*.7,it(u.strokeColor)):"none",x=u.willChange?"transform":"auto",b=e(this,_).acquire();b.textContent=k,b.style.font=m,b.style.color=it(B),b.style.textShadow=S,b.style.willChange=x,b.style.position="absolute",b.style.left="0",b.style.top="0",b.style.whiteSpace="nowrap",b.style.pointerEvents="none",b.style.userSelect="none",b.style.display="",b.style.opacity=String(u.opacity),e(this,F).appendElement(b);let U={id:t.id,text:k,mode:l,color:B,fontSize:A,x:l===1?r:r/2,y:p.y,track:p.track,w:z,h:O,born:performance.now()/1e3,duration:u.duration,el:b};e(this,I).push(U);},ct=function(){let t=e(this,F).height;if(t===0)return;let i=e(this,v),s=Math.max(2,Math.ceil(i.fontSize*.2)),o=i.fontSize+i.padding*2+s;e(this,E).resize(t,i.area,o);};function Qt(h,t){if(!(t.container instanceof HTMLElement))throw new TypeError("container must be an HTMLElement");if(t.container instanceof HTMLVideoElement)throw new TypeError('container cannot be a <video> element. Video uses a native rendering surface that hides child elements. Wrap the video in a <div> and use that as the container. Example: <div style="position:relative"><video .../><div id="overlay"></div></div>');switch(h){case "canvas":return new Mt(t);case "dom":return new Bt(t);default:throw new TypeError(`Unknown engine type: "${h}". Use "canvas" or "dom".`)}}export{ft as DanmakuMode,Qt as createEngine};//# sourceMappingURL=index.min.js.map
//# sourceMappingURL=index.min.js.map
{
"name": "danmaku-lite",
"version": "0.2.1",
"version": "0.2.2",
"description": "Framework-agnostic, player-agnostic danmaku (bullet chat) rendering engine with dual Canvas/DOM backends",
"type": "module",
"license": "MIT",
"author": "",
"author": "wakanachan",
"repository": "https://github.com/wakanachan/danmaku-lite",
"keywords": [

@@ -9,0 +10,0 @@ "danmaku",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display