scrapbox-tikz
code:mod.js
var ht=Object.defineProperty;var Ge=(t,e)=>{for(var r in e)ht(t,r,{get:er,enumerable:!0})};var be={};Ge(be,{close:()=>Et,deleteEverything:()=>ue,eof:()=>Rt,eoln:()=>$t,erstat:()=>Lt,executeAsync:()=>xe,get:()=>At,inputln:()=>Mt,pages:()=>C,printBoolean:()=>Pt,printChar:()=>Ut,printFloat:()=>St,printInteger:()=>vt,printNewline:()=>kt,printString:()=>Tt,put:()=>Nt,readFileSync:()=>se,reset:()=>Ft,rewrite:()=>Ct,setConsole:()=>de,setFileLoader:()=>ge,setInput:()=>he,setMemory:()=>me,tex_final_end:()=>ye,writeFileSync:()=>fe});var X={},m=[],re,O="",P=null,G=null,N=null,F=null,W=null,He=null,H=null,C=1100,z=(C-100)*1024*64,gt=C*1024*64,oe=0,I=!1,xt=()=>{W&&(Wz>>2=z+8,Wz+4>>2=gt),F.asyncify_start_unwind(z),oe=oe+1},yt=()=>{F.asyncify_start_rewind(z),F.main()},bt=()=>{oe=oe-1,F.asyncify_stop_rewind()},ue=()=>{m=[],X={},P=null,G=null,N=null,re=void 0,H=null,F=null,W=null,I=!1},fe=(t,e)=>{Xt=e},se=t=>{for(let e of m)if(e.filename==t)return e.content.slice(0,e.position);throw Error(Could not find file ${t})},Be=(t,e)=>{let r=I;I&&(bt(),I=!1);let n=new Uint8Array;if(Xt)n=Xt;else if(e=="r"&&m.findIndex(s=>s.filename==t&&!s.erstat)==-1)return r||t.match(/\.(aux|log|dvi)$/)?(m.push({filename:t,erstat:1}),m.length-1):(xt(),I=!0,setTimeout(async()=>{try{let s=await He(t);Xt=s}catch{}yt()},0),-1);return m.push({filename:t,position:0,position2:0,erstat:0,eoln:!1,content:n,descriptor:m.length}),m.length-1},wt=()=>{},$=(t,e,r,n)=>{for(r===void 0&&(r=0),n===void 0&&(n=e.length-r);n>t.content.length-t.position;){let o=new Uint8Array(1+t.content.length*2);o.set(t.content),t.content=o}t.content.subarray(t.position).set(e.subarray(r,r+n)),t.position+=n},_t=(t,e,r,n,o)=>(r===void 0&&(r=0),n===void 0&&(n=e.length-r),n>t.content.length-o&&(n=t.content.length-o),e.subarray(r).set(t.content.subarray(o,o+n)),n),M=t=>{if(re&&(O+=t,O.indexOf(` )>=0)){let e=O.split(
);O=e.pop();for(let r of e)r.length&&re(r)}},de=t=>{re=t},me=t=>{P=t,W=new Int32Array(t)},he=(t,e)=>{G=t,e&&(N=e)},ge=t=>{He=t},xe=t=>(F=t,H=Promise.withResolvers(),F.main(),F.asyncify_stop_unwind(),H.promise),Tt=(t,e)=>{let r=t<0?{stdout:!0}:m[t],n=new Uint8Array(P,e,1)[0],o=new Uint8Array(P,e+1,n),s=String.fromCharCode.apply(null,o);if(r.stdout){M(s);return}$(r,new TextEncoder().encode(s))},Pt=(t,e)=>{let r=t<0?{stdout:!0}:m[t],n=e?"TRUE":"FALSE";if(r.stdout){M(n);return}$(r,new TextEncoder().encode(n))},Ut=(t,e)=>{let r=t<0?{stdout:!0}:m[t];if(r.stdout){M(String.fromCharCode(e));return}let n=new Uint8Array(1);n[0]=e,$(r,n)},vt=(t,e)=>{let r=t<0?{stdout:!0}:m[t];if(r.stdout){M(e.toString());return}$(r,new TextEncoder().encode(${e}))},St=(t,e)=>{let r=t<0?{stdout:!0}:m[t];if(r.stdout){M(e.toString());return}$(r,new TextEncoder().encode(${e}))},kt=(t,e)=>{let r=t<0?{stdout:!0}:m[t];if(r.stdout){M(
);return}$(r,new TextEncoder().encode(
))},Ft=(t,e)=>{let r=new Uint8Array(P,e,t),n=String.fromCharCode.apply(null,r);return n=n.replace(/\000+$/g,""),n.startsWith("{")&&(n=n.replace(/^{/g,""),n=n.replace(/}.*/g,"")),n.startsWith('"')&&(n=n.replace(/^"/g,""),n=n.replace(/".*/g,"")),n=n.replace(/ +$/g,""),n=n.replace(/^\*/,""),n=n.replace(/^TeXfonts:/,""),n=="TeXformats:TEX.POOL"&&(n="tex.pool"),n=="TTY:"?(m.push({filename:"stdin",stdin:!0,position:0,position2:0,erstat:0,eoln:!1,content:new TextEncoder().encode(G)}),m.length-1):Be(n,"r")},Ct=(t,e)=>{let r=new Uint8Array(P,e,t),n=String.fromCharCode.apply(null,r);return n=n.replace(/ +$/g,""),n.startsWith('"')&&(n=n.replace(/^"/g,""),n=n.replace(/".*/g,"")),n=="TTY:"?(m.push({filename:"stdout",stdout:!0,erstat:0}),m.length-1):Be(n,"w")},Et=t=>{let e=m[t];e.descriptor&&wt(e.descriptor)},Rt=t=>m[t].eof?1:0,Lt=t=>m[t].erstat,$t=t=>m[t].eoln?1:0,Mt=(t,e,r,n,o,s,a)=>{let i=m[t],c=new Uint8Array(P,r,a),d=new Uint32Array(P,n,4),l=new Uint32Array(P,o,4);l[0]=d[0],e&&!i.eof&&i.eoln&&(i.position2=i.position2+1);let h=i.content.indexOf(10,i.position2);if(h<0&&(h=i.content.length),i.position2>=i.content.length)return i.stdin&&(N&&N(),ye()),i.eof=!0,!1;for(c.subarray(d[0]).set(i.content.subarray(i.position2,h)),l[0]=d[0]+h-i.position2;c[l[0]-1]==32;)l[0]=l[0]-1;return i.position2=h,i.eoln=!0,!0},At=(t,e,r)=>{let n=m[t],o=new Uint8Array(P);if(n.stdin)n.position>=G.length?(o[e]=13,n.eof=!0,N&&N(),ye()):o[e]=G[n.position].charCodeAt(0);else if(n.descriptor){if(_t(n,o,e,r,n.position)==0){o[e]=0,n.eof=!0,n.eoln=!0;return}}else{n.eof=!0,n.eoln=!0;return}n.eoln=!1,o[e]==10&&(n.eoln=!0),o[e]==13&&(n.eoln=!0),n.position=n.position+r},Nt=(t,e,r)=>{let n=m[t],o=new Uint8Array(P);$(n,o,e,r)},ye=()=>{O.length&&M(
),H&&H.resolve()};var we={};Ge(we,{getCurrentDay:()=>Ot,getCurrentMinutes:()=>Dt,getCurrentMonth:()=>zt,getCurrentYear:()=>It});var Dt=()=>{let t=new Date;return 60*t.getHours()+t.getMinutes()},Ot=()=>new Date().getDate(),zt=()=>new Date().getMonth()+1,It=()=>new Date().getFullYear();var Ve,Ye,Ze=async(t,e)=>{Ye??=await e.fileLoader("tex.wasm"),Ve??=new Uint8Array(await e.fileLoader("core.dump"),0,C*65536),fe("input.tex",new TextEncoder().encode(t));let r=new WebAssembly.Memory({initial:C,maximum:C});new Uint8Array(r.buffer,0,C*65536).set(Ve.slice(0)),me(r.buffer),he( input.tex
\\end
),ge(e.fileLoader),e.console&&de(e.console);let o=await WebAssembly.instantiate(Ye,{library:{...be,...we},env:{memory:r}});await xe(o.instance.exports);let s=se("input.log");try{return{dvi:se("input.dvi"),log:s}}catch{return{log:s}}finally{ue()}};async function*qe(t){let e=await new Response(t).arrayBuffer(),r=new DataView(e),n=e.byteLength-4;for(;r.getUint32(n,!0)!==101010256;)n--;let o=n;o+=4,o+=4;let s=r.getUint16(o,!0);o+=2,o+=2,o+=4;let a=r.getUint32(o,!0);o+=4,o=a;for(let i=0;i<s;i++){o+=4,o+=4,o+=4,o+=4,o+=4;let c=r.getUint32(o,!0);o+=4;let d=r.getUint32(o,!0);o+=4;let l=r.getUint16(o,!0);o+=2;let h=r.getUint16(o,!0);o+=2;let w=r.getUint16(o,!0);o+=2,o+=8;let _=r.getUint32(o,!0);o+=4,o+=l+h+w,yield Xt(r,_,c,d)}}var Xt=(t,e,r,n)=>{e+=4,e+=2,e+=2;let o=t.getUint16(e,!0);e+=2,e+=4,e+=4,e+=8;let s=t.getUint16(e,!0);e+=2;let a=t.getUint16(e,!0);e+=2;let i=new TextDecoder().decode(new Uint8Array(t.buffer,t.byteOffset+e,s));e+=s,e+=a;let c=new Uint8Array(t.buffer,t.byteOffset+e,r);if(o==0)return Ke(i,r,n,c,!0);if(o==8)return Ke(i,r,n,c,!1);throw"unknown compression method: "+o},Ke=(t,e,r,n,o)=>{if(o)return{name:t,csize:e,usize:r,arrayBuffer:()=>Promise.resolve(n),file:()=>Promise.resolve(new File([n],t)),text:()=>Promise.resolve(new TextDecoder().decode(n))};let s,a=async()=>(s??=await Wt(n),s);return{name:t,csize:e,usize:r,arrayBuffer:a,file:async()=>new File([await a()],t),text:async()=>new TextDecoder().decode(await a())}};var zn=(()=>{let t=new Uint32Array(256);for(let e=0;e<256;e++){let r=e;for(let n=0;n<8;n++)r&1?r=3988292384^r>>>1:r=r>>>1;t[e]=r}return t})();var Wt=t=>new Response(new Response(t).body.pipeThrough(new DecompressionStream("deflate-raw"))).arrayBuffer();var je=async(t,e)=>{let r=await globalThis.caches.keys();for(let n of r.sort().reverse()){let s=await(await caches.open(n)).match(t,e);if(s)return s}},Qe=async(t,e)=>{let n=(await globalThis.caches.keys()).filter(s=>s.startsWith("api")).sort().reverse().at(0);if(!n)return;await(await caches.open(n)).put(t,e.clone())};var Je=[1,0,0,1,0,0],Gt=t=>Math.abs(t[0]-1)<Number.EPSILON&&Math.abs(t[1])<Number.EPSILON&&Math.abs(t[2])<Number.EPSILON&&Math.abs(t[3]-1)<Number.EPSILON&&Math.abs(t[4])<Number.EPSILON&&Math.abs(t[5])<Number.EPSILON;var _e=(t,e,r)=>[t[0]*e,t[1]*e,t[2]*r,t[3]*r,t[4],t[5]],Te=(t,e,r)=>[t[0],t[1],t[2],t[3],t[0]*e+t[2]*r+t[4],t[1]*e+t[3]*r+t[5]],Pe=(t,e)=>{let r=e*Math.PI/180,n=Math.cos(r),o=Math.sin(r);return[t[0]*n+t[2]*o,t[1]*n+t[3]*o,-t[0]*o+t[2]*n,-t[1]*o+t[3]*n,t[4],t[5]]},Ue=t=>Gt(t)?"":transform="matrix(${t.join(" ")})";var et=t=>{let e=new FileReader,r=new Promise(n=>e.onload=()=>n(e.result));return e.readAsDataURL(t),r};var tt=async(t,e)=>(await Promise.all([...t].sort().map(async r=>[r.slice(0,-4),await et(new Blob([await e(r)],{type:"font/truetype"}))]))).map(([r,n])=>@font-face{font-family:${r};src:local(${r}),url(${n})format("truetype");}.${r}{font-family:${r};}).join("");var nt=async(t,e)=>{let r=0,n="black",o=e.svg?1:0,s=[...Je],a="",i=0,c="",d=0,l=0,h=0,w=0,_=new Set;for(let u of t)switch(u.type){case"text":{let p=0,b=0,f="";for(let L of u.text){let y=L.codePointAt(0)??0,pe=u.font.metrics.characters.at(y);if(pe===void 0)throw Error(Could not find font metric for ${y});p+=pe.width,b=Math.max(b,pe.height),f+=String.fromCodePoint(y>=0&&y<=9?161+y:y>=10&&y<=19?173+y-10:y===20?8729:y>=21&&y<=32?184+y-21:y===127?196:y)}let T=u.font.metrics.design_size/1048576*65536/1048576,g=u.left*r,x=p*r*T,v=b*r*T,le=u.top*r;a=u.font.name,i=u.font.metrics.design_size/1048576*u.font.scaleFactor/u.font.designSize;let ne=["#000","black"].includes(n)?"CanvasText":n;if(_.add(${a}.ttf),o<=0){let L=d==u.top&&g>l+2;c+=<span class="text ${a}" style="top:${le-v}pt;left:${g}pt;color:${ne};font-size:${i}pt;"><span ${L?'class="has-space" ':""} style="vertical-align:${-v}pt;">${f}</span></span>
,d=u.top,l=g+x}else{let L=u.top*r;c+=<text alignment-baseline="baseline" y="${L}" x="${g}" fill="${ne}" font-size="${i}" font-family="${a}">${f}</text>
}break}case"rect":{let p=u.height*r,b=u.width*r,f=u.left*r,g=u.top*r-p,x=["#000","black"].includes(n)?"CanvasText":n;c+=o>0?<rect x="${f}" y="${g}" width="${b}" height="${p}" fill="${x}" ${Ue(s)}></rect>
:<span class="rect" style="background: ${x}; top: ${g}pt; left: ${f}pt; width: ${b}pt; height: ${p}pt;"></span>
;break}case"special":break;case"info":{r=u.magnification*u.numerator/1e3/u.denominator*72.27/1e5/2.54;break}case"svg":{let p=u.svg;for(let T of u.svg.matchAll(/<svg\s[^>]+>/g)){let g=T[0];g==="<svg beginpicture>"&&(p=p.replace(g,o>0?"":ve(h,w))),o++}for(let T of u.svg.matchAll(/<\/svg\s[^>]+>/g)){let g=T[0];g==="</svg endpicture>"&&(p=p.replace(g,o===1?"</svg>":"")),o=Math.max(0,o-1)}let b=u.top*r,f=u.left*r;c+=p.replaceAll("{?x}",${f}).replaceAll("{?y}",${b});break}case"papersize":w=u.height,h=u.width;break;case"color":n=u.color;break;case"ps":s=u.interpret(s);break;case"psfile":c+=o>0?u.toSVG(s):${ve(h,w)}${u.toSVG(s)}</svg>};break}for(let u=o;u>0;u--)c+="</svg>";let k=<title>${e.title??"input.tex"}</title>,U=<style>${await tt(_,e.fileLoader)}:root{color-scheme:light dark;background-color:Canvas;color:CanvasText;}.page{position:relative;width:100%;}.text{line-height:0;position:absolute;overflow:visible;}.rect{position:absolute;min-width:1px;min-height:1px;}</style>;return c=c.replace(/("#000"|"black")/g,'"CanvasText"').replace(/("#fff"|"white")/g,'"var(--background-primary, Canvas)"'),e.svg?${ve(h,w)}${k}${U}${c}:<!DOCTYPE html><html><head><meta charset="UTF-8">${k}${U}</head><body>${c}</body></html>},ve=(t,e)=><svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="${t}pt" height="${e}pt" viewBox="-72 -72 ${t} ${e}">;var rt=t=>{let e=new DataView(t.buffer,t.byteOffset,t.byteLength),r=e.getUint16(0),n=e.getUint16(2),o=e.getUint16(4),s=e.getUint16(6),a={header:Math.max(18,n),character_info:s-o+1,width:e.getUint16(8),height:e.getUint16(10),depth:e.getUint16(12),italic_correction:e.getUint16(14),lig_kern:e.getUint16(16),kern:e.getUint16(18),extensible_character:e.getUint16(20),font_parameter:e.getUint16(22)};if(!(o<=s+1&&s<256))throw new Error(Smallest character code (${o}) must be larger than largest character code (${s}) and largest character code must be less than 256 (actual: ${s}));if(a.extensible_character>256)throw new Error(Extensible character must be less than 256 (actual: ${a.extensible_character}));{let x=6+n+a.character_info+a.width+a.height+a.depth+a.italic_correction+a.lig_kern+a.kern+a.extensible_character+a.font_parameter;if(r!==x)throw new Error(entire_file_length must be ${x} (actual: ${r}))}let i=24,c=x=>[...Array(x).keys()].map(v=>e.getUint32(i+v*4)),d=e.buffer.slice(i,i+a.header*4);i+=a.header*4;let l=c(a.character_info);i+=a.character_info*4;let h=c(a.width);i+=a.width*4;let w=c(a.height);i+=a.height*4;let _=c(a.depth);i+=a.depth*4;let k=c(a.italic_correction);i+=a.italic_correction*4;let U=c(a.lig_kern);i+=a.lig_kern*4;let u=c(a.kern);i+=a.kern*4;let p=c(a.extensible_character);i+=a.extensible_character*4;let b=c(a.font_parameter);i+=a.font_parameter*4;let f=Ht(d),T=Bt(l),g=Yt(b,f.coding_scheme);return{checksum:f.checksum,design_size:f.design_size,family:f.family,face:f.face,ligKernPrograms:Vt(U),characters:T.map(x=>{let{width_index:v,height_index:le,depth_index:ne,italic_index:L}=x,y={width:h[v],height:w.at(le)??0,depth:_.at(ne)??0,italic_correction:k.at(L)??0};switch(x.type){case"lig":y.lig_kern_program=U[x.lig_kern_index];break;case"link":y.next_larger_char=x.next_larger_char;break;case"ext":y.extensible_recipe=p[x.extensible_index];break;default:break}return y}),...g}},Ht=t=>{let e=new DataView(t),r=e.getUint32(0),n=e.getUint32(4),o=e.getUint8(8);if(o>39)throw new Error("Invalid TFM file");let s=new TextDecoder().decode(t.slice(9,9+o)),a=e.getUint8(48);if(a>20)throw new Error("Invalid TFM file");let i=new TextDecoder().decode(t.slice(49,49+a)),c=new Uint8Array(t,68,4),d=c[0],l=c[3];return{checksum:r,design_size:n,coding_scheme:s,family:i,seven_bit_safe_flag:d,face:l}},Bt=t=>t.map(e=>{let r=e>>24,n=e>>20&15,o=e>>16&15,s=e>>10&1118481,a=e>>8&3,i=e&255;switch(a){case 1:return{type:"lig",width_index:r,height_index:n,depth_index:o,italic_index:s,lig_kern_index:i};case 2:return{type:"link",width_index:r,height_index:n,depth_index:o,italic_index:s,next_larger_char:i};case 3:return{type:"ext",width_index:r,height_index:n,depth_index:o,italic_index:s,extensible_index:i};default:return{width_index:r,height_index:n,depth_index:o,italic_index:s}}}),Vt=t=>t.map((e,r)=>{let n=e>>24;if((r===0||r===t.length)&&n===255)throw Error(Font has ${r===0?"right":"left"} boundary char. This is not supported yet.);let o=e>>16&255,s=e>>8&255,a=e&255;if(s>=128){let h=256*(s-128)+a;return{skip_byte:n,next_char:o,op_byte:s,kern:a}}let i=s>>2,c=(s&2)==0,d=(s&1)==0,l=a;return n>=128?{skip_byte:n,next_char:o,op_byte:s,remainder:a}:{skip_byte:n,next_char:o,op_byte:s,kern:a}}),Yt=(t,e)=>{let r=t[0],n=t[1],o=t[2],s=t[3],a=t[4],i=t[5];if(e==="TeX math italic")return{coding_scheme:e,slant:r,spacing:n,space_stretch:o,space_shrink:s,x_height:a,quad:i};let c=t[6];if(e==="TeX math symbols"){let d=t[7],l=t[8],h=t[9],w=t[10],_=t[11],k=t[12],U=t[13],u=t[14],p=t[15],b=t[16],f=t[17],T=t[18],g=t[19],x=t[20],v=t[21];return{coding_scheme:e,slant:r,spacing:n,space_stretch:o,space_shrink:s,x_height:a,quad:i,extra_space:c,num1:d,num2:l,num3:h,denom1:w,denom2:_,sup1:k,sup2:U,sup3:u,sub1:p,sub2:b,supdrop:f,subdrop:T,delim1:g,delim2:x,axis_height:v}}if(e==="TeX math extension"||e==="euler substitutions only"){let d=t[7],l=t.slice(8,8+5);return{coding_scheme:e,slant:r,spacing:n,space_stretch:o,space_shrink:s,x_height:a,quad:i,extra_space:c,default_rule_thickness:d,big_op_spacing:l}}return{coding_scheme:e,slant:r,spacing:n,space_stretch:o,space_shrink:s,x_height:a,quad:i,extra_space:c}};var Cn=t=>{let e=t[0];if(0<=e&&e<128)return[{opcode:0,c:e},1];if(171<=e&&e<235)return[{opcode:171,k:e-171},1];if(249<e&&e<=255)return[{opcode:138},1];let r=new DataView(t.buffer,t.byteOffset,t.byteLength);switch(e){case 128:case 129:case 130:case 131:{let n=e-128+1;return t.byteLength<n+1?void 0:[{opcode:0,c:Se(t,1,n)},n+1]}case 132:case 137:return t.byteLength<9?void 0:[{opcode:e,a:r.getInt32(1),b:r.getInt32(5)},9];case 133:case 134:case 135:case 136:{let n=e-128+1;return t.byteLength<n+1?void 0:[{opcode:133,c:Se(t,1,n)},n+1]}case 138:case 140:case 141:case 142:return[{opcode:e},1];case 139:return t.byteLength<45?void 0:[{opcode:e,c_0:r.getUint32(1),c_1:r.getUint32(5),c_2:r.getUint32(9),c_3:r.getUint32(13),c_4:r.getUint32(17),c_5:r.getUint32(21),c_6:r.getUint32(25),c_7:r.getUint32(29),c_8:r.getUint32(33),c_9:r.getUint32(37),p:r.getInt32(41)},45];case 143:case 144:case 145:case 146:{let n=e-143+1;return t.byteLength<n+1?void 0:[{opcode:143,b:E(t,1,n)},n+1]}case 147:case 152:return[{opcode:e,b:0},1];case 148:case 149:case 150:case 151:{let n=e-147;return t.byteLength<n+1?void 0:[{opcode:147,b:E(t,1,n)},n+1]}case 153:case 154:case 155:case 156:{let n=e-152;return t.byteLength<n+1?void 0:[{opcode:152,b:E(t,1,n)},n+1]}case 157:case 158:case 159:case 160:{let n=e-157+1;return t.byteLength<n+1?void 0:[{opcode:157,a:E(t,1,n)},n+1]}case 161:case 166:return[{opcode:e,a:0},1];case 162:case 163:case 164:case 165:{let n=e-161;return t.byteLength<n+1?void 0:[{opcode:161,a:E(t,1,n)},n+1]}case 167:case 168:case 169:case 170:{let n=e-166;return t.byteLength<n+1?void 0:[{opcode:166,a:E(t,1,n)},n+1]}case 235:case 236:case 237:case 238:{let n=e-235+1;return t.byteLength<n+1?void 0:[{opcode:171,k:E(t,1,n)},n+1]}case 239:case 240:case 241:case 242:{let n=e-239+1;if(t.byteLength<n+1)return;let o=Se(t,1,n);return t.byteLength<n+1+o?void 0:[{opcode:239,x:t.subarray(n+1,n+1+o),k:o},n+1+o]}case 243:case 244:case 245:case 246:{let n=e-243+1;if(t.byteLength<n+1)return;let o=E(t,1,n);if(t.byteLength<n+15)return;let s=t[n+13],a=t[n+14];return t.byteLength<n+15+s+a?void 0:[{opcode:243,k:o,c:r.getUint32(n+1),s:r.getUint32(n+5),d:r.getUint32(n+9),a:s,l:a,n:new TextDecoder().decode(t.subarray(n+15,n+15+s+a))},n+15+s+a]}case 247:{if(t.byteLength<15)return;let n=t[1],o=t[14];return t.byteLength<15+o?void 0:[{opcode:e,i:n,num:r.getUint32(2),den:r.getUint32(6),mag:r.getUint32(10),x:new TextDecoder().decode(t.subarray(15,15+o)),k:o},15+o]}case 248:return t.byteLength<29?void 0:[{opcode:e,p:r.getUint32(1),num:r.getUint32(5),den:r.getUint32(9),mag:r.getUint32(13),l:r.getUint32(17),u:r.getUint32(21),s:r.getUint16(25),t:r.getUint16(27)},29];case 249:return t.byteLength<6?void 0:[{opcode:e,q:r.getUint32(1),i:r.getUint8(5)},6]}};function*ot(t){let e=t,r=0;for(;r<t.byteLength;){let[n,o]=Cn(e)??[,0];if(r+=o,e=e.subarray(o),!n)break;if(n.opcode===249){if(e.every(s=>s===223))break;throw Error("Only 223 bytes are permitted after the post-postamble.")}yield n}}var Se=(t,e,r)=>[...t.subarray(e,e+r)].reduce((n,o,s)=>n+o*256**(r-s-1),0),E=(t,e,r)=>{switch(r){case 1:return t[e];case 2:{let n=t[e]*256+t[e+1];return n|(n&2**15)*131070}case 3:{let n=t[e]*65536+t[e+1]*256+t[e+2];return n|(n&2**23)*510}case 4:return(t[e]<<24)+t[e+1]*2**16+t[e+2]*2**8+t[e+3]}};var st=()=>{let t=[],e="black";return r=>{let n=new TextDecoder().decode(r.data);if(n.startsWith("color push "))return t.push(e),e=it(n.slice(11)),{type:"color",color:e};if(n.startsWith("color pop")){let o=t.pop();if(!o)throw new Error("Popped from empty color stack");return e=o,{type:"color",color:e}}}},En=t=>${Math.round(t).toString(16)}.padStart(2,"0"),it=t=>{if(t==="gray 0")return"black";if(t==="gray 1")return"white";if(t.startsWith("rgb "))return#${t.split(" ").slice(1).map(e=>En(parseFloat(e)*255)).join("")};if(t.startsWith("gray ")){let e=t.split(" ")[1];return it(rgb ${e} ${e} ${e})}return"black"};var at=()=>{let t="";return(e,r)=>{let n=new TextDecoder().decode(e.data);if(!n.startsWith("dvisvgm:raw "))return;if(t+=n.slice(12),r?.type==="special"){let s=new TextDecoder().decode(r.data);if(e.horizontal===r.horizontal&&e.vertical===r.vertical&&s.startsWith("dvisvgm:raw "))return null}let o=t.replaceAll("{?nl}", );return t="",{type:"svg",svg:o,left:e.horizontal,top:e.vertical}}};var ct=t=>{let e=new TextDecoder().decode(t.data);if(!e.startsWith("papersize="))return;let[r,n]=e.slice(10).split(",");if(r===void 0||n===void 0)throw Error("Papersize special requires two arguments.");if(!r.endsWith("pt"))throw Error("Papersize special width must be in points.");if(!n.endsWith("pt"))throw Error("Papersize special height must be in points.");return{type:"papersize",width:parseFloat(r.slice(0,-2)),height:parseFloat(n.slice(0,-2))}};var lt=[],pt=(t,e,r,n)=>{let o=[],s={matrix:e,horizontal:r,vertical:n},a={pop:()=>o.pop(),exch:()=>{let i=o.pop(),c=o.pop();i&&o.push(i),c&&o.push(c)},dup:()=>{o.push(o[o.length-1])},mark:()=>o.push(new ze),neg:()=>{let i=o.pop();i&&o.push(new S(-i.value))},add:()=>{let i=o.pop(),c=o.pop();i&&c&&o.push(new S(i.value+c.value))},sub:()=>{let i=o.pop(),c=o.pop();i&&c&&o.push(new S(c.value-i.value))},mul:()=>{let i=o.pop(),c=o.pop();i&&c&&o.push(new S(i.value*c.value))},div:()=>{let i=o.pop(),c=o.pop();i&&c&&o.push(new S(c.value/i.value))},gsave:()=>lt.push([...e]),grestore:()=>{let i=lt.pop();i&&(s.matrix=i)},currentpoint:()=>o.push(new S(s.horizontal),new S(s.vertical)),moveto:()=>{let i=o.pop(),c=o.pop();s.horizontal=c?.value,s.vertical=i?.value},scale:()=>{let i=o.pop(),c=o.pop();c&&i&&(s.matrix=_e(s.matrix,c.value,i.value))},translate:()=>{let i=o.pop(),c=o.pop();c&&i&&(s.matrix=Te(s.matrix,c.value,i.value))},rotate:()=>{let i=o.pop();i&&(s.matrix=Pe(s.matrix,i.value))}};for(let i of Rn(t)){if(/^[+-]?\d+(\.\d*)?$/.test(i)){o.push(new S(i));continue}if(i[0]==="("){o.push(new De(i));continue}if(i==="["){a.mark();continue}if(i==="]"){let c=new Oe,d=o.pop();if(!d)continue;for(;d.name!=="mark";)c.push(d);o.push(c)}if(i[0]==="/"&&o.push(new Ie(i)),i[0]==="{"&&o.push(new Xe(i)),i in a){a[i](void 0);continue}throw Error("Invalid or unimplemented postscript expression")}return s};function*Rn(t){let e="",r=0,n=0,o=t[Symbol.iterator]();for(let s of o){let a;switch(s){case" ":case" ":case
:if(n){e[e.length-1]!==" "&&(e+=" ");continue}if(r){switch(s){case" ":e+=" ";break;case
:e+="\\n";break;case" ":e+="\\t";break}continue}e&&(yield e,e="");continue;case"[":case"]":if(!n&&!r){e&&(yield e),e="",yield s;continue}e+=s;continue;case"{":r||(n==0&&e&&(yield e),++n),e+=s;continue;case"}":if(e+=s,r||(--n,n))continue;yield e,e="";continue;case"(":++r,e&&!n&&r==1&&(yield e),r>1&&(e+="\\"),e+=s;continue;case")":if(--r,r&&(e+="\\"),e+=s,n||r)continue;yield e,e="";continue;case"\\":if(e+=s,a=o.next(),a.done)throw Error("Invalid escape character.");a.done||(e+=a.value);continue;case"/":!n&&!r&&e&&(yield e),e+=s;continue;case"%":do a=o.next();while(!a.done&&a.value!==
);continue;default:e+=s}}e&&(yield e)}var R=class{name;value;constructor(e){this.name=e}},S=class extends R{constructor(e){super("number"),this.value=typeof e=="number"?e:parseFloat(e)}},De=class extends R{constructor(e){super("string"),this.value=e.replace(/^\(|\)$/g,"")}},Oe=class extends R{constructor(e){super("array"),this.value=e||[]}push(e){this.value.push(e)}pop(){return this.value.pop()}},ze=class extends R{constructor(){super("mark"),this.value="-mark-"}},Ie=class extends R{constructor(e){super("identifier"),this.value=e.replace(/^\//,"")}},Xe=class extends R{constructor(e){super("procedure"),this.value=e}};var ut=()=>{let t="";return(e,r)=>{let n=new TextDecoder().decode(e.data);if(!n.startsWith("ps: "))return;if(t+=n.slice(4),r?.type==="special"&&new TextDecoder().decode(r.data).startsWith("ps: "))return null;let o=s=>{let a=pt(t,s,e.horizontal,e.vertical);return e.emitChange({horizontal:a.horizontal,vertical:a.vertical,w:e.w,x:e.x,y:e.y,z:e.z}),a.matrix};return t="",{type:"ps",ps:t,interpret:o}}};async function*ft(t,e){let r=Ln(t,e.tfmLoader),n=await r.next(),o=n.done?void 0:n.value;for(;o;){let s=o,a=await r.next();if(o=a.done?void 0:a.value,s.type==="special"&&e.plugins){let i=!1;for(let c of e.plugins){let d=c(s,o);if(d!==void 0){d!==null&&(yield d),i=!0;break}}i||(yield s);continue}yield s}}async function*Ln(t,e){let r=2,n=254e5,o=473628672,s=1e3,a="",i=0,c=0,d=0,l={horizontal:0,vertical:0,w:0,x:0,y:0,z:0,fontNum:0},h=[],w=new Map,_="",k=ot(t),U=k.next(),u=U.done?void 0:U.value;for(;u;){let p=u,b=k.next();switch(u=b.done?void 0:b.value,p.opcode){case 0:case 133:if(_+=String.fromCharCode(p.c),u?.opcode!==0&&u?.opcode!==133||!u){let f=w.get(l.fontNum);if(!f)throw Error(Font "${l.fontNum}" is not loaded);yield{type:"text",text:_,font:f,top:l.vertical,left:l.horizontal},p.opcode===0&&(l.horizontal+=$n(_,f)),_=""}break;case 132:case 137:p.a>0&&p.b>0&&(yield{type:"rect",left:l.horizontal,top:l.vertical,height:p.a,width:p.b}),p.opcode===132&&(l.horizontal+=p.b);break;case 138:case 140:break;case 139:l.horizontal=0,l.vertical=0,l.w=0,l.x=0,l.y=0,l.z=0,l.fontNum=0,h.splice(0,h.length);break;case 141:h.push({...l});break;case 142:{let f=h.pop();f&&(l.horizontal=f.horizontal,l.vertical=f.vertical,l.w=f.w,l.x=f.x,l.y=f.y,l.z=f.z);break}case 143:l.horizontal+=p.b;break;case 147:p.b!==0&&(l.w=p.b),l.horizontal+=l.w;break;case 152:p.b!==0&&(l.x=p.b),l.horizontal+=l.x;break;case 157:l.vertical+=p.a;break;case 161:p.a!==0&&(l.y=p.a),l.vertical+=l.y;break;case 166:p.a!==0&&(l.z=p.a),l.vertical+=l.z;break;case 171:case 235:case 236:case 237:case 238:l.fontNum=p.k;break;case 239:yield{type:"special",data:p.x,...l,emitChange:f=>{l.horizontal=f.horizontal,l.vertical=f.vertical,l.w=f.w,l.x=f.x,l.y=f.y,l.z=f.z}};break;case 243:{if(w.has(p.k))break;let f=p.n,T=p.s,g=p.d,x=p.c,v=rt(new Uint32Array((await e(${p.n}.tfm)).buffer));w.set(p.k,{name:f,checksum:x,scaleFactor:T,designSize:g,metrics:v});break}case 247:r=p.i,n=p.num,o=p.den,s=p.mag,a=p.x,yield{type:"info",version:r,numerator:n,denominator:o,magnification:s,comment:a};break;case 248:i=p.l,c=p.u,d=p.t;break;case 249:yield{type:"info",version:r,numerator:n,denominator:o,magnification:s,comment:a,maxHeight:i,maxWidth:c,pages:d,dviVersion:p.i};break}}}var $n=(t,e)=>{let r=0;for(let o of t){let s=o.codePointAt(0)??0,a=e.metrics.characters.at(s);if(a===void 0)throw Error(Could not find font metric for ${s});r+=a.width}let n=e.metrics.design_size/1048576*65536/1048576;return r*n*e.scaleFactor/e.designSize};globalThis.onmessage=async t=>{let e=t.data;switch(e.type){case"asset-url":{mt=e.url;let r={type:e.type};globalThis.postMessage(r)}break;case"compile":{let{dvi:r,log:n}=await Ze(e.input,{fileLoader:We,console:c=>{let d={type:"stdout",message:c};globalThis.postMessage(d)}});if(!r){let c={type:e.type,log:n};globalThis.postMessage(c,[n.buffer]);return}let o=[],s=new Set;for await(let c of ft(r,{plugins:[ct,ut(),at(),st()],tfmLoader:We}))o.push(c),c.type==="text"&&s.add(c.font.name);let a=await nt(o,{fileLoader:We,svg:!0}),i={type:e.type,svg:a,log:n};globalThis.postMessage(i,[n.buffer])}break}};var dt,We=async t=>{dt??=await Mn();let e=dt.get(t);if(!e){let r=new Error(File ${t} not found in assets`);throw console.log(r),r}return new Uint8Array(await e())},mt="",Mn=async()=>{let t=new Request(mt),e=await je(t,{ignoreSearch:!0}),r=e??await fetch(t);e||await Qe(t,r);let n=new Map;for await(let{name:o,arrayBuffer:s}of qe(await r.arrayBuffer()))n.set(o,s);return n};