!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.NDanmaku=e():t.NDanmaku=e()}(self,(function(){return function(){"use strict";var t={421:function(t,e,n){var i=n(81),r=n.n(i),s=n(645),a=n.n(s)()(r());a.push([t.id,"@-webkit-keyframes Ndm-forward{0%{left:100%}to{left:0;-webkit-transform:translateX(-100%);transform:translateX(-100%)}}@keyframes Ndm-forward{0%{left:100%}to{left:0;-webkit-transform:translateX(-100%);transform:translateX(-100%)}}@-webkit-keyframes Ndm-reversed{0%{right:100%}to{right:0;-webkit-transform:translateX(100%);transform:translateX(100%)}}@keyframes Ndm-reversed{0%{right:100%}to{right:0;-webkit-transform:translateX(100%);transform:translateX(100%)}}.N-outline{text-shadow:#000 .5px 0 0,#000 0 .5px 0,#000 -.5px 0 0,#000 0 -.5px 0}.N-scroll{-webkit-animation-fill-mode:forwards;animation-fill-mode:forwards;-webkit-animation-timing-function:linear;animation-timing-function:linear;z-index:1}.N-hanging{left:50%;-webkit-transform:translateX(-50%);transform:translateX(-50%);z-index:2}.N-scroll-forward{-webkit-animation-name:Ndm-forward;animation-name:Ndm-forward}.N-scroll-reversed{-webkit-animation-name:Ndm-reversed;animation-name:Ndm-reversed}.N-scroll-playing{-webkit-animation-play-state:running;animation-play-state:running}.N-scroll-paused,.N-scroll-paused>.N-scroll{-webkit-animation-play-state:paused;animation-play-state:paused}.N-dmLayer{left:0;overflow:hidden;pointer-events:none;position:absolute;top:0}",""]),e.Z=a},645:function(t){t.exports=function(t){var e=[];return e.toString=function(){return this.map((function(e){var n="",i=void 0!==e[5];return e[4]&&(n+="@supports (".concat(e[4],") {")),e[2]&&(n+="@media ".concat(e[2]," {")),i&&(n+="@layer".concat(e[5].length>0?" ".concat(e[5]):""," {")),n+=t(e),i&&(n+="}"),e[2]&&(n+="}"),e[4]&&(n+="}"),n})).join("")},e.i=function(t,n,i,r,s){"string"==typeof t&&(t=[[null,t,void 0]]);var a={};if(i)for(var o=0;o0?" ".concat(h[5]):""," {").concat(h[1],"}")),h[5]=s),n&&(h[2]?(h[1]="@media ".concat(h[2]," {").concat(h[1],"}"),h[2]=n):h[2]=n),r&&(h[4]?(h[1]="@supports (".concat(h[4],") {").concat(h[1],"}"),h[4]=r):h[4]="".concat(r)),e.push(h))}},e}},81:function(t){t.exports=function(t){return t[1]}},379:function(t){var e=[];function n(t){for(var n=-1,i=0;i0?" ".concat(n.layer):""," {")),i+=n.css,r&&(i+="}"),n.media&&(i+="}"),n.supports&&(i+="}");var s=n.sourceMap;s&&"undefined"!=typeof btoa&&(i+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(s))))," */")),e.styleTagTransform(i,t,e.options)}(e,t,n)},remove:function(){!function(t){if(null===t.parentNode)return!1;t.parentNode.removeChild(t)}(e)}}}},589:function(t){t.exports=function(t,e){if(e.styleSheet)e.styleSheet.cssText=t;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(t))}}}},e={};function n(i){var r=e[i];if(void 0!==r)return r.exports;var s=e[i]={id:i,exports:{}};return t[i](s,s.exports,n),s.exports}n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,{a:e}),e},n.d=function(t,e){for(var i in e)n.o(e,i)&&!n.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.nc=void 0;var i={};return function(){n.d(i,{default:function(){return C}});var t=n(379),e=n.n(t),r=n(795),s=n.n(r),a=n(569),o=n.n(a),l=n(565),c=n.n(l),h=n(216),u=n.n(h),d=n(589),m=n.n(d),f=n(421),g={};function p(t,e,n){t instanceof Array||(t=[t]),"string"==typeof e&&(e=[e]),n instanceof Array||(n=[n]);for(let i=0,r=t.length;i0&&"paused"==this.state&&(this.state="running",this.start=w(),this.timer=setTimeout(this.finished.bind(this),this.remaining))}}const L={animation:"animationend",OAnimation:"oAnimationEnd",MozAnimation:"animationend",WebkitAnimation:"webkitAnimationEnd"},x={color:"white",size:null,scale:1,opacity:100,weight:"normal",bottom_space:2,outline:!0,reverse:!1,type:"scroll",life:5e3,pointer_events:!0,custom_css:{},carry_sheet:""},N={top:0,bottom:0,scroll:0,random:0},A={top:70,bottom:70,scroll:100,random:100};class E{constructor(t){this.target=t,this.hitSets={top:[],bottom:[],scroll:[]},this.resetHitSets()}resetHitSets(){this.danmakuMinHeight=N,this.danmakuMaxHeight=A,this.refreshHitSets()}getMinHeight(t){return.01*this.danmakuMinHeight[t]*this.target.getBoundingClientRect().height}getMaxHeight(t){return.01*this.danmakuMaxHeight[t]*this.target.getBoundingClientRect().height}refreshHitSets(t=""){if("random"==t)return;let e=this,n=t=>{e.hitSets[t].length=0,e.hitSets[t][0]={from:Math.floor(100*e.getMinHeight(t)),to:Math.floor(100*e.getMaxHeight(t)),available:!0,dm:null}};if(t)n(t);else for(let t in this.hitSets)n(t)}setDanmakuPos(t,e){switch(e.type){case"midscroll":case"midhang":p(t,"top",`calc(50% - ${t.offsetHeight/2}px)`);break;case"random":p(t,"top",`${this.danmakuRandom(t)}px`);break;case"top":case"scroll":p(t,"top",`${this.danmakuAnchor(t,e)}px`);break;case"bottom":p(t,"bottom",`${this.danmakuAnchor(t,e)}px`)}}danmakuRandom(t){return this.target.offsetHeight,e=this.getMinHeight("random"),n=this.getMaxHeight("random")-t.offsetHeight,Math.random()*(n-e)+e;var e,n}danmakuAnchor(t,e,n=!1){let i=this.target.getBoundingClientRect(),r=t.getBoundingClientRect().height,s=this.hitSets[e.type],a=e.bottom_space,o=-1;for(let n=0,l=s.length;n=l){let i=Object.assign({},c),r=c.from+l;o=c.from/100,c.to=r-1,c.available=!1,c.dm={start:w(),life:e.life,reversed:e.reverse,element:t},i.from=r,s.splice(n+1,0,i)}}else{let t=c.dm.start,r=c.dm.life,a=c.dm.reversed,o=c.dm.element,h=o.getBoundingClientRect(),u=!1;switch(e.type){case"scroll":u=a?h.left-i.left>0:h.left+h.width=r}if(0!=o.offsetWidth&&null!=o.parentNode||(u=!0),u){let t=s[n-1]||{},e=s[n+1]||{};t.available&&e.available?(t.to=e.to,s.splice(n,2),n--,l-=2):t.available?(t.to=c.to,s.splice(n,1),n--,l--):e.available?(c.to=e.to,c.available=!0,c.dm=null,s.splice(n+1,1),l--):(c.available=!0,c.dm=null),n--}}}if(-1===o){if(!n)return this.refreshHitSets(e.type),this.danmakuAnchor(t,e,!0);o=0}return o}}const H="N-scroll-paused",$="N-scroll-playing";class D{constructor(t,e,n,i){this.id=t,this.element=e,this.allDanmaku=i;for(let t in n)this[t]=n[t];i[t]=this}revoke(t=!1){let e=this.element;switch(this.category){case"hanging":case"freeing":this.timer.pause(),e.parentNode&&e.parentNode.removeChild(e);break;case"scrolling":t?e.dispatchEvent(new Event(this.clearEvent)):e.dispatchEvent(new Event(this.endEvent))}delete this.allDanmaku[this.id]}pause(){let t=this.element;switch(this.category){case"hanging":case"freeing":return this.timer.pause(),!0;case"scrolling":if(t.classList.contains($))return t.classList.replace($,H),!0}return!1}resume(){let t=this.element;switch(this.category){case"hanging":case"freeing":return this.timer.resume(),!0;case"scrolling":if(t.classList.contains(H))return t.classList.replace(H,$),!0}return!1}get finished(){if(["hanging","freeing"].includes(this.category)){if("done"===this.timer.state)return!0}else if(this.element.offsetWidth<=0||null==this.element.parentNode)return!0;return!1}}console.log("Hey there!👋 Thank you for using %cN.js%c - SomeBottle","color:#81BEF7;font-weight:bold","");var C=class{constructor(t,e="",n="auto"){const i=t instanceof Element?t:document.getElementById(t);if(!i)return b("Error: container element not found",3),null;let r;this.target=i,this.prefix=e,this.resetAttrs(),this.state="running",p(i,"position","relative"),i.querySelector(".N-dmLayer")?r=i.querySelector(".N-dmLayer"):(r=document.createElement("div"),p(r,["width","height","top","left"],["100%","100%","0px","0px"]),r.className="N-dmLayer",i.appendChild(r)),p(r,"z-index",n),this.dmLayer=r,this.hitBox=new E(r),this.monitor=new class{constructor(){this.dmSerial=0,this.allDanmaku=new Object,this.hanging=[],this.scrolling=[],this.freeing=[],this.createdReport={total:0,scrolling:{total:0,scroll:{total:0},random:{total:0},midscroll:{total:0}},hanging:{total:0,top:{total:0},bottom:{total:0},midhang:{total:0}},freeing:{total:0}}}resetStatistics(t=""){"created"===t&&v(this.createdReport)}statistics(){let t={total:0,garbages:0,freeing:{total:0,garbages:0},scrolling:{total:0,reversed:0,garbages:0,scroll:{total:0,reversed:0,garbages:0},random:{total:0,reversed:0,garbages:0},midscroll:{total:0,reversed:0,garbages:0}},hanging:{total:0,garbages:0,top:{total:0,garbages:0},bottom:{total:0,garbages:0},midhang:{total:0,garbages:0}}};for(let e in this.allDanmaku){let n=this.allDanmaku[e],i=n.category,r=n.type;n.finished?(t.garbages++,t[i].garbages++,n.type&&t[i][r].garbages++):(t.total++,t[i].total++,n.type&&t[i][r].total++,n.reversed&&(t.scrolling.reversed++,t.scrolling[r].reversed++))}return{current:t,created:this.createdReport}}garbageCollect(t=""){let e=t=>{for(let e=0,n=t.length;e{t.parentNode.removeChild(t),i&&i(r)}),n),a=this.hanging,o=this.createdReport;this.garbageCollect("hanging");let l=new D(r,t,{category:"hanging",timer:s,type:e},this.allDanmaku);return a.push(l),this.dmSerial++,o.total++,o.hanging.total++,o.hanging[e].total++,r}newFree(t,e,n=null){let i=this.dmSerial,r=new S((()=>{t.parentNode.removeChild(t),n&&n(i)}),e),s=this.freeing,a=this.createdReport;this.garbageCollect("freeing");let o=new D(i,t,{category:"freeing",timer:r,type:null},this.allDanmaku);return s.push(o),this.dmSerial++,a.total++,a.freeing.total++,i}clearSomeScrolling(t="",e=!1){let n=this.scrolling;for(let i=0,r=n.length;i{for(let n=0,i=e.length;n=0?this.usingList.uncertainty=t:b("Uncertainty should be a positive number",2)}load(t){if(this.usingList){for(let e=0,n=t.length;e=0&&l<0){let t=o+1;t>i?(a+=t-i,r=a):r+=t}let c=0,h=n.length-1,u=[];for(;c<=h;){let e=Math.floor((c+h)/2),i=n[e][0],s=n[e][1];if(i==t){r<=t&&u.push(s),c=e+1,h=e-1;break}it&&(h=e-1)}for(let t=n.length;c=0&&n[h][0]>=r;h--)u.unshift(n[h][1]);this.lastTickRange=[r,s];let d=e.danmakuLine;for(let t=0,e=u.length;t=0))return b("Invalid parameters!",3),null;if(!t.hasOwnProperty("text"))return b("Lack of necessary properties in danmakuData!",3),null;let i=`ld${n.dmSerial}`;e=Math.round(e),n.danmakuLine[i]=t;let r=0,s=n.timeLine.length,a=!1;do{let t=n.timeLine[r];if(!t||t[0]>e){n.timeLine.splice(r,0,[e,i]),a=!0;break}r++}while(r5?e:5}(this.target);i.scale>0&&(t*=i.scale),a=`${t}px`}p(r,{position:"absolute","pointer-events":h?"auto":"none","font-size":a,color:i.color,"font-weight":i.weight,opacity:.01*i.opacity,"word-break":"keep-all","white-space":"pre"}),"free"!==i.type&&p(r,{"animation-duration":`${l}ms`,"-webkit-animation-duration":`${l}ms`,"-moz-animation-duration":`${l}ms`,"-o-animation-duration":`${l}ms`}),i.outline&&r.classList.add("N-outline"),p(r,i.custom_css),this.dmLayer.appendChild(r);let u=null;switch(i.type){case"scroll":case"random":case"midscroll":r.classList.add("N-scroll-playing",c?"N-scroll-reversed":"N-scroll-forward","N-scroll"),u=this.monitor.newScroll(r,i.type,c,n);break;case"top":case"bottom":case"midhang":r.classList.add("N-hanging"),u=this.monitor.newHang(r,i.type,i.life,n);break;case"free":u=this.monitor.newFree(r,i.life,n);break;default:return b("Error: Unknown danmaku type.",3),this.dmLayer.removeChild(r),this}this.hitBox.setDanmakuPos(r,i);let d="";if(this.prefix&&(d=`N-danmaku-${this.prefix}-${u}`,r.id=d),o){let t=document.createElement("style");d&&(o=o.replace(/\[selfId\]/g,d)),t.appendChild(document.createTextNode(o)),r.appendChild(t)}return"function"==typeof e&&e(r,u),this}clearSome(t="",e="all"){switch(t){case"random":case"scroll":case"midscroll":this.monitor.clearSomeScrolling(t,e);break;case"top":case"bottom":case"midhang":this.monitor.clearSomeHanging(t);break;case"all":this.monitor.clearSomeScrolling("all",e),this.monitor.clearSomeHanging("all");break;case"scrolling":this.monitor.clearSomeScrolling("all",e);break;case"hanging":this.monitor.clearSomeHanging();break;case"free":case"freeing":this.monitor.clearFreeing();break;default:this.monitor.clearSomeScrolling(),this.monitor.clearSomeHanging(),this.monitor.clearFreeing()}return this}clearStyled(t){this.monitor.clearStyled(t)}clear(t=null){return"number"==typeof t?this.monitor.clearSingle(t):this.clearSome(),this}pause(t=null){return"number"==typeof t?(this.monitor.pauseSingle(t),this):("running"==this.state&&(this.dmLayer.classList.add("N-scroll-paused"),this.monitor.pauseAll("hanging"),this.monitor.pauseAll("freeing"),this.state="paused"),this)}resume(t=null){return"number"==typeof t?(this.monitor.resumeSingle(t),this):("paused"==this.state&&(this.dmLayer.classList.remove("N-scroll-paused"),this.monitor.resumeAll("hanging"),this.monitor.resumeAll("freeing"),this.state="running"),this)}attrs(t,e=null){if(t instanceof Object)for(let e in t)this.currentAttrs[e]=t[e];else void 0!==this.currentAttrs[t]?this.currentAttrs[t]=e:b(`Error: Danmaku attribute not found: ${t}`,3);return this}ranges(t,e=null){let n=this.hitBox.danmakuMaxHeight,i=this.hitBox.danmakuMinHeight;if(t instanceof Object)for(let e in t)void 0!==n[e]&&(i[e]=t[e][0],n[e]=t[e][1],this.hitBox.refreshHitSets(e));else void 0!==n[t]?(i[t]=e[0],n[t]=e[1],this.hitBox.refreshHitSets(t)):b(`Error: Danmaku type not found: ${t}`,3);return this}}}(),i.default}()}));