const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/errors-De2cfhQz.js","assets/prod-B4BRG6kn.js","assets/app-taG9CRVs.js","assets/Button-d1z8wTLU.js","assets/app-Vs0ZL9L-.css"])))=>i.map(i=>d[i]);
import{_ as M}from"./app-taG9CRVs.js";import{b as F,p as E}from"./prod-B4BRG6kn.js";import"./Button-d1z8wTLU.js";const b=/^Format:[\s\t]*/,R=/^Style:[\s\t]*/,y=/^Dialogue:[\s\t]*/,d=/[\s\t]*,[\s\t]*/,O=/\{[^}]+\}/g,w=/\\N/g,I=/^\[(.*)[\s\t]?Styles\]$/,S=/^\[(.*)[\s\t]?Events\]$/;class A{h;O=0;c=null;l=[];m=[];N=null;f;P={};async init(t){this.h=t,t.errors&&(this.f=(await M(async()=>{const{ParseErrorBuilder:r}=await import("./errors-De2cfhQz.js");return{ParseErrorBuilder:r}},__vite__mapDeps([0,1,2,3,4]))).ParseErrorBuilder)}parse(t,r){if(this.O)switch(this.O){case 1:if(t==="")this.O=0;else if(R.test(t))if(this.N){const e=t.replace(R,"").split(d);this.S(e)}else this.g(this.f?.T("Style",r));else b.test(t)?this.N=t.replace(b,"").split(d):S.test(t)&&(this.N=null,this.O=2);break;case 2:if(t==="")this.Q();else if(y.test(t))if(this.Q(),this.N){const e=t.replace(y,"").split(d),s=this.U(e,r);s&&(this.c=s)}else this.g(this.f?.T("Dialogue",r));else this.c?this.c.text+=`
`+t.replace(O,"").replace(w,`
`):b.test(t)?this.N=t.replace(b,"").split(d):I.test(t)?(this.N=null,this.O=1):S.test(t)&&(this.N=null)}else t===""||(I.test(t)?(this.N=null,this.O=1):S.test(t)&&(this.N=null,this.O=2))}done(){return{metadata:{},cues:this.l,regions:[],errors:this.m}}Q(){this.c&&(this.l.push(this.c),this.h.onCue?.(this.c),this.c=null)}S(t){let r="Default",e={},s,a="center",l="bottom",g,n=1.2,c,h,o=3,f=[];for(let u=0;u<this.N.length;u++){const x=this.N[u],i=t[u];switch(x){case"Name":r=i;break;case"Fontname":e["font-family"]=i;break;case"Fontsize":e["font-size"]=`calc(${i} / var(--overlay-height))`;break;case"PrimaryColour":const _=k(i);_&&(e["--cue-color"]=_);break;case"BorderStyle":o=parseInt(i,10);break;case"BackColour":h=k(i);break;case"OutlineColour":const N=k(i);N&&(c=N);break;case"Bold":parseInt(i)&&(e["font-weight"]="bold");break;case"Italic":parseInt(i)&&(e["font-style"]="italic");break;case"Underline":parseInt(i)&&(e["text-decoration"]="underline");break;case"StrikeOut":parseInt(i)&&(e["text-decoration"]="line-through");break;case"Spacing":e["letter-spacing"]=i+"px";break;case"AlphaLevel":e.opacity=parseFloat(i);break;case"ScaleX":f.push(`scaleX(${parseFloat(i)/100})`);break;case"ScaleY":f.push(`scaleY(${parseFloat(i)/100})`);break;case"Angle":f.push(`rotate(${i}deg)`);break;case"Shadow":n=parseInt(i,10)*1.2;break;case"MarginL":e["--cue-width"]="auto",e["--cue-left"]=parseFloat(i)+"px";break;case"MarginR":e["--cue-width"]="auto",e["--cue-right"]=parseFloat(i)+"px";break;case"MarginV":g=parseFloat(i);break;case"Outline":s=parseInt(i,10);break;case"Alignment":const m=parseInt(i,10);switch(m>=4&&(l=m>=7?"top":"center"),m%3){case 1:a="start";break;case 2:a="center";break;case 3:a="end";break}}}if(e.R=l,e["--cue-white-space"]="normal",e["--cue-line-height"]="normal",e["--cue-text-align"]=a,l==="center"?(e["--cue-top"]="50%",f.push("translateY(-50%)")):e[`--cue-${l}`]=(g||0)+"px",o===1&&(e["--cue-padding-y"]="0"),(o===1||h)&&(e["--cue-bg-color"]=o===1?"none":h),o===3&&c&&(e["--cue-outline"]=`${s}px solid ${c}`),o===1&&typeof s=="number"){const u=h??"#000";e["--cue-text-shadow"]=[c&&T(s*1.2,n*1.2,c),c?T(s*(s/2),n*(s/2),u):T(s,n,u)].filter(Boolean).join(", ")}f.length&&(e["--cue-transform"]=f.join(" ")),this.P[r]=e}U(t,r){const e=this.V(t),s=this.q(e.Start,e.End,r);if(!s)return;const a=new F(s[0],s[1],""),l={...this.P[e.Style]||{}},g=e.Name?`<v ${e.Name}>`:"",n=l.R,c=e.MarginL&&parseFloat(e.MarginL),h=e.MarginR&&parseFloat(e.MarginR),o=e.MarginV&&parseFloat(e.MarginV);return c&&(l["--cue-width"]="auto",l["--cue-left"]=c+"px"),h&&(l["--cue-width"]="auto",l["--cue-right"]=h+"px"),o&&n!=="center"&&(l[`--cue-${n}`]=o+"px"),a.text=g+t.slice(this.N.length-1).join(", ").replace(O,"").replace(w,`
`),delete l.R,Object.keys(l).length&&(a.style=l),a}V(t){const r={};for(let e=0;e<this.N.length;e++)r[this.N[e]]=t[e];return r}q(t,r,e){const s=E(t),a=E(r);if(s!==null&&a!==null&&a>s)return[s,a];s===null&&this.g(this.f?.s(t,e)),a===null&&this.g(this.f?.t(r,e)),s!=null&&a!==null&&a>s&&this.g(this.f?.u(s,a,e))}g(t){if(t){if(this.m.push(t),this.h.strict)throw this.h.cancel(),t;this.h.onError?.(t)}}}function k(p){const t=parseInt(p.replace("&H",""),16);if(t>=0){const e=(t>>24&255^255)/255,s=t>>16&255,a=t>>8&255;return"rgba("+[t&255,a,s,e].join(",")+")"}return null}function T(p,t,r){const e=Math.ceil(2*Math.PI*p);let s="";for(let a=0;a<e;a++){const l=2*Math.PI*a/e;s+=p*Math.cos(l)+"px "+t*Math.sin(l)+"px 0 "+r+(a==e-1?"":",")}return s}function $(){return new A}export{A as SSAParser,$ as default};
