{"size": 7965, "ext": "js", "max_stars_repo_path": "min/danmaku-converter.min.js", "max_stars_repo_name": "3179341937/Bilibili-Evolved", "max_stars_repo_stars_event_min_datetime": "2020-05-06T08:07:36.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-06T08:07:36.000Z", "max_issues_repo_path": "min/danmaku-converter.min.js", "max_issues_repo_name": "Ddecade196/Bilibili-Evolved", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "min/danmaku-converter.min.js", "max_forks_repo_name": "Ddecade196/Bilibili-Evolved", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 7965.0, "max_line_length": 7965, "alphanum_fraction": 0.7155053358}
(()=>{return(t,e)=>{class i{constructor({content:t,time:e,type:i,fontSize:r,color:a}){this.content=t;this.time=e;this.startTime=parseFloat(e);this.type=parseInt(i);this.fontSize=parseFloat(r);this.color=parseInt(a)}}class r extends i{constructor({content:t,time:e,type:i,fontSize:r,color:a,timeStamp:s,pool:n,userHash:o,rowId:l}){super({content:t,time:e,type:i,fontSize:r,color:a});this.timeStamp=parseInt(s);this.pool=parseInt(n);this.userHash=o;this.rowId=parseInt(l);this.pDataArray=[e,i,r,a,s,n,o,l]}text(){const t=this.pDataArray.join(",");return`<d p="${t}">${this.content}</d>`}static parse(t){const e=t.getAttribute("p");const[i,a,s,n,o,l,h,c]=e.split(",");const u=t.innerHTML;return new r({content:u,time:i,type:a,fontSize:s,color:n,timeStamp:o,pool:l,userHash:h,rowId:c})}}class a{constructor(t){this.xml=t;const e=(new DOMParser).parseFromString(t,"application/xml").documentElement;this.danmakus=[...e.querySelectorAll("d[p]")].map(t=>r.parse(t))}}var s;(function(t){t[t["Normal"]=1]="Normal";t[t["Normal2"]=2]="Normal2";t[t["Normal3"]=3]="Normal3";t[t["Bottom"]=4]="Bottom";t[t["Top"]=5]="Top";t[t["Reversed"]=6]="Reversed";t[t["Special"]=7]="Special";t[t["Special2"]=8]="Special2"})(s||(s={}));class n extends i{constructor({content:t,time:e,type:i,fontSize:r,color:a,typeTag:s,colorTag:n,endTime:o}){super({content:t,time:e,type:i,fontSize:r,color:a});this.typeTag=s;this.colorTag=n;this.endTime=o}text(t){let e=t[this.fontSize];if(!e){e=t[25]}const i=e.match(/Style:(.*?),/)[1].trim();return`Dialogue: 0,${this.time},${this.endTime},${i},,0,0,0,,{${this.typeTag}${this.colorTag}}${this.content}`}}class o{constructor(t,e,i,r,a){this.danmakus=t;this.title=e;this.fontStyles=i;this.blockTypes=r;this.resolution=a}generateAss(){const t=`\n[Script Info]\n; Script generated by Bilibili Evolved Danmaku Converter\n; https://github.com/the1812/Bilibili-Evolved/\nTitle: ${this.title}\nScriptType: v4.00+\nPlayResX: ${this.resolution.x}\nPlayResY: ${this.resolution.y}\nTimer: 10.0000\nWrapStyle: 2\nScaledBorderAndShadow: no\n\n[V4+ Styles]\nFormat: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding\n${Object.values(this.fontStyles).join("\n")}\n\n[Events]\nFormat: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\n`.trim();return t+"\n"+this.danmakus.map(t=>t.text(this.fontStyles)).filter(t=>t!=="").join("\n")}}class l{constructor(t,e,i,r){this.horizontalStack=[];this.horizontalTrack=[];this.verticalStack=[];this.verticalTrack=[];this.resolution=e;this.duration=i;this.canvas=document.createElement("canvas");this.context=this.canvas.getContext("2d");this.fontSizes={30:`64px ${t}`,25:`52px ${t}`,18:`36px ${t}`,45:`90px ${t}`};this.bottomMarginPercent=r;this.generateTracks()}generateTracks(){const t=52;this.danmakuHeight=t;this.trackHeight=l.margin*2+t;this.trackCount=parseInt(fixed(this.resolution.y*(1-this.bottomMarginPercent)/this.trackHeight,0))}getTextSize(t){this.context.font=this.fontSizes[t.fontSize];const e=this.context.measureText(t.content);const i=e.width/2;return[i,this.danmakuHeight/2]}getTags(t,{targetTrack:e,initTrackNumber:i,nextTrackNumber:r,willOverlay:a,getTrackItem:s,getTag:n}){const[o,h]=this.getTextSize(t);const c=o*2;const u=this.duration(t)*c/(this.resolution.x+c)+l.nextDanmakuDelay;let m=i;let p=null;do{p=e.find(t=>a(t,m,c));m+=r}while(p&&m<=this.trackCount&&m>=0);if(m>this.trackCount||m<0){return`\\pos(0,-999)`}m-=r;e.push(s(m,c,u));return n({trackNumber:m,x:o,y:h})}getHorizontalTags(t){return this.getTags(t,{targetTrack:this.horizontalTrack,initTrackNumber:0,nextTrackNumber:1,willOverlay:(e,i,r)=>{if(e.trackNumber!==i){return false}if(e.width<r){return this.duration(t)*this.resolution.x/(this.resolution.x+r)<=e.end-t.startTime}else{return e.visible>t.startTime}},getTrackItem:(e,i,r)=>{return{width:i,start:t.startTime,visible:t.startTime+r,end:t.startTime+this.duration(t),trackNumber:e}},getTag:({trackNumber:e,x:i,y:r})=>{return`\\move(${this.resolution.x+i},${e*this.trackHeight+l.margin+r},${-i},${e*this.trackHeight+l.margin+r},0,${this.duration(t)*1e3})`}})}getVerticalTags(t){const e=l.danmakuType[t.type]==="top";return this.getTags(t,{targetTrack:this.verticalTrack,initTrackNumber:e?0:this.trackCount-1,nextTrackNumber:e?1:-1,willOverlay:(e,i)=>{if(e.trackNumber!==i){return false}return e.end>t.startTime},getTrackItem:e=>{return{start:t.startTime,end:t.startTime+this.duration(t),trackNumber:e}},getTag:({trackNumber:t,y:i})=>{if(e){return`\\pos(${this.resolution.x/2},${t*this.trackHeight+l.margin+i})`}else{return`\\pos(${this.resolution.x/2},${this.resolution.y-l.margin-i-(this.trackCount-1-t)*this.trackHeight})`}}})}push(t){let e="";let i=[];switch(l.danmakuType[t.type]){case"normal":case"reversed":{e=this.getHorizontalTags(t);i=this.horizontalStack;break}case"top":case"bottom":{e=this.getVerticalTags(t);i=this.verticalStack;break}case"special":default:{return{tags:`\\pos(0,-999)`}}}const r={tags:e};i.push(r);return r}}l.danmakuType={[s.Normal]:"normal",[s.Normal2]:"normal",[s.Normal3]:"normal",[s.Bottom]:"bottom",[s.Top]:"top",[s.Reversed]:"reversed",[s.Special]:"special",[s.Special2]:"special"};l.margin=4;l.nextDanmakuDelay=.05;class h{constructor({title:t,font:e,alpha:i,duration:r,blockTypes:a,resolution:s,bottomMarginPercent:n,bold:o}){this.title=t;this.font=e;this.alpha=Math.round(i*255).toString(16).toUpperCase().padStart(2,"0");this.duration=r;this.blockTypes=a;this.resolution=s;this.bold=o;this.danmakuStack=new l(e,s,r,n)}get fontStyles(){return{36:`Style: Larger,${this.font},72,&H${this.alpha}FFFFFF,&H${this.alpha}FFFFFF,&H${this.alpha}000000,&H${this.alpha}000000,${this.bold?"1":"0"},0,0,0,100,100,0,0,1,1.2,0,5,0,0,0,0`,30:`Style: Large,${this.font},64,&H${this.alpha}FFFFFF,&H${this.alpha}FFFFFF,&H${this.alpha}000000,&H${this.alpha}000000,${this.bold?"1":"0"},0,0,0,100,100,0,0,1,1.2,0,5,0,0,0,0`,25:`Style: Medium,${this.font},52,&H${this.alpha}FFFFFF,&H${this.alpha}FFFFFF,&H${this.alpha}000000,&H${this.alpha}000000,${this.bold?"1":"0"},0,0,0,100,100,0,0,1,1.2,0,5,0,0,0,0`,18:`Style: Small,${this.font},36,&H${this.alpha}FFFFFF,&H${this.alpha}FFFFFF,&H${this.alpha}000000,&H${this.alpha}000000,${this.bold?"1":"0"},0,0,0,100,100,0,0,1,1.2,0,5,0,0,0,0`,45:`Style: ExtraLarge,${this.font},90,&H${this.alpha}FFFFFF,&H${this.alpha}FFFFFF,&H${this.alpha}000000,&H${this.alpha}000000,${this.bold?"1":"0"},0,0,0,100,100,0,0,1,1.2,0,5,0,0,0,0`}}convertToAssDocument(t){const e=new a(t);const i=[];for(const t of e.danmakus.sort((t,e)=>t.startTime-e.startTime)){if(this.blockTypes.indexOf(t.type)!==-1||this.blockTypes.indexOf("color")!==-1&&t.color!==h.white){continue}const[e,r]=this.convertTime(t.startTime,this.duration(t));i.push(new n({content:this.convertText(t.content),time:e,endTime:r,type:t.type.valueOf().toString(),fontSize:t.fontSize.toString(),color:t.color.toString(),typeTag:this.convertType(t),colorTag:this.convertColor(t.color)}))}return new o(i,this.title,this.fontStyles,this.blockTypes,this.resolution)}convertText(t){const e={"{":"｛","}":"｝","&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&apos;":"'"};for(const[i,r]of Object.entries(e)){t=t.replace(new RegExp(i,"g"),r)}return t}convertType(t){return this.danmakuStack.push(t).tags}convertColor(t){if(t===h.white){return""}const e=t.toString(16);const i=e.substring(0,2);const r=e.substring(2,4);const a=e.substring(4,6);return`\\c&H${a}${r}${i}&`}convertTime(t,e){function i(t){const[e,i="00"]=String(t).split(".");return`${e.padStart(2,"0")}.${i.substr(0,2).padEnd(2,"0")}`}function r(t){let e=0;let r=0;while(t>=60){t-=60;r++}while(r>=60){r-=60;e++}return`${e}:${String(r).padStart(2,"0")}:${i(t)}`}return[r(t),r(t+e)]}}h.white=16777215;return{export:{AssDanmaku:n,AssDanmakuDocument:o,Danmaku:i,DanmakuConverter:h,DanmakuStack:l,XmlDanmaku:r,XmlDanmakuDocument:a}}}})();