var Ze=Object.defineProperty;var He=(r,e,t)=>e in r?Ze(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var p=(r,e,t)=>(He(r,typeof e!="symbol"?e+"":e,t),t),Ne=(r,e,t)=>{if(!e.has(r))throw TypeError("Cannot "+t)};var j=(r,e,t)=>{if(e.has(r))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(r):e.set(r,t)};var D=(r,e,t)=>(Ne(r,e,"access private method"),t);import{_ as Qe}from"../chunks/preload-helper.a4192956.js";import{t as oe,s as je,q as le,e as ae,i as Ge,d as Ve,o as We}from"../chunks/scheduler.afda2bc1.js";import{S as Je,i as Xe,b as ce,d as Ke,m as ue,t as he,c as Ye,a as pe,e as fe,g as et}from"../chunks/index.3b22678c.js";import ge from"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/es/highlight.min.js";import{io as tt}from"https://cdn.socket.io/4.7.2/socket.io.esm.min.js";let P;const nt=new Uint8Array(16);function st(){if(!P&&(P=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!P))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return P(nt)}const m=[];for(let r=0;r<256;++r)m.push((r+256).toString(16).slice(1));function it(r,e=0){return m[r[e+0]]+m[r[e+1]]+m[r[e+2]]+m[r[e+3]]+"-"+m[r[e+4]]+m[r[e+5]]+"-"+m[r[e+6]]+m[r[e+7]]+"-"+m[r[e+8]]+m[r[e+9]]+"-"+m[r[e+10]]+m[r[e+11]]+m[r[e+12]]+m[r[e+13]]+m[r[e+14]]+m[r[e+15]]}const rt=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),de={randomUUID:rt};function ot(r,e,t){if(de.randomUUID&&!e&&!r)return de.randomUUID();r=r||{};const n=r.random||(r.rng||st)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,e){t=t||0;for(let i=0;i<16;++i)e[t+i]=n[i];return e}return it(n)}function G(){}const O=ot,lt=/^\w*(Error|Exception|An error):/,at=/^Traceback \(most recent call last\):/;function ct(r){return lt.test(r)||at.test(r)}function ut(r,e){return r.reduce((t,n)=>(t[n[e]]=n,t),{})}function ht(r,e){r.splice(0,r.length,...e)}function ke(r,e){return new Promise((t,n)=>{const i=new FileReader;i.onload=o=>{var l;const s=(l=o.target)==null?void 0:l.result;s!=null?t(s):n(new Error("File read resulted in null data"))},i.onerror=o=>{var s,l;n(new Error(`Error reading file: ${((l=(s=o.target)==null?void 0:s.error)==null?void 0:l.message)||"Unknown error"}`))},i[`readAs${e}`](r)})}function pt(r,e="",t=!1){let n=document.createElement("input");n.type="file",n.accept=e,n.multiple=t,n.onchange=async i=>{const o=i.target.files;if(o&&o.length>0)return r(t?Array.from(o):o[0])},n.click()}function ft(r){try{const e=localStorage.getItem(r);return JSON.parse(e)}catch{return null}}function gt(r,e){try{localStorage.setItem(r,JSON.stringify(e))}catch(t){console.error(t)}}function J(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}let z=J();function Se(r){z=r}const ze=/[&<>"']/,dt=new RegExp(ze.source,"g"),Re=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,kt=new RegExp(Re.source,"g"),mt={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},me=r=>mt[r];function b(r,e){if(e){if(ze.test(r))return r.replace(dt,me)}else if(Re.test(r))return r.replace(kt,me);return r}const xt=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function bt(r){return r.replace(xt,(e,t)=>(t=t.toLowerCase(),t==="colon"?":":t.charAt(0)==="#"?t.charAt(1)==="x"?String.fromCharCode(parseInt(t.substring(2),16)):String.fromCharCode(+t.substring(1)):""))}const wt=/(^|[^\[])\^/g;function k(r,e){let t=typeof r=="string"?r:r.source;e=e||"";const n={replace:(i,o)=>{let s=typeof o=="string"?o:o.source;return s=s.replace(wt,"$1"),t=t.replace(i,s),n},getRegex:()=>new RegExp(t,e)};return n}function xe(r){try{r=encodeURI(r).replace(/%25/g,"%")}catch{return null}return r}const E={exec:()=>null};function be(r,e){const t=r.replace(/\|/g,(o,s,l)=>{let a=!1,h=s;for(;--h>=0&&l[h]==="\\";)a=!a;return a?"|":" |"}),n=t.split(/ \|/);let i=0;if(n[0].trim()||n.shift(),n.length>0&&!n[n.length-1].trim()&&n.pop(),e)if(n.length>e)n.splice(e);else for(;n.length<e;)n.push("");for(;i<n.length;i++)n[i]=n[i].trim().replace(/\\\|/g,"|");return n}function L(r,e,t){const n=r.length;if(n===0)return"";let i=0;for(;i<n;){const o=r.charAt(n-i-1);if(o===e&&!t)i++;else if(o!==e&&t)i++;else break}return r.slice(0,n-i)}function yt(r,e){if(r.indexOf(e[1])===-1)return-1;let t=0;for(let n=0;n<r.length;n++)if(r[n]==="\\")n++;else if(r[n]===e[0])t++;else if(r[n]===e[1]&&(t--,t<0))return n;return-1}function we(r,e,t,n){const i=e.href,o=e.title?b(e.title):null,s=r[1].replace(/\\([\[\]])/g,"$1");if(r[0].charAt(0)!=="!"){n.state.inLink=!0;const l={type:"link",raw:t,href:i,title:o,text:s,tokens:n.inlineTokens(s)};return n.state.inLink=!1,l}return{type:"image",raw:t,href:i,title:o,text:b(s)}}function _t(r,e){const t=r.match(/^(\s+)(?:```)/);if(t===null)return e;const n=t[1];return e.split(`
`).map(i=>{const o=i.match(/^\s+/);if(o===null)return i;const[s]=o;return s.length>=n.length?i.slice(n.length):i}).join(`
`)}class U{constructor(e){p(this,"options");p(this,"rules");p(this,"lexer");this.options=e||z}space(e){const t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){const t=this.rules.block.code.exec(e);if(t){const n=t[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?n:L(n,`
`)}}}fences(e){const t=this.rules.block.fences.exec(e);if(t){const n=t[0],i=_t(n,t[3]||"");return{type:"code",raw:n,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:i}}}heading(e){const t=this.rules.block.heading.exec(e);if(t){let n=t[2].trim();if(/#$/.test(n)){const i=L(n,"#");(this.options.pedantic||!i||/ $/.test(i))&&(n=i.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:n,tokens:this.lexer.inline(n)}}}hr(e){const t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:t[0]}}blockquote(e){const t=this.rules.block.blockquote.exec(e);if(t){const n=L(t[0].replace(/^ *>[ \t]?/gm,""),`
`),i=this.lexer.state.top;this.lexer.state.top=!0;const o=this.lexer.blockTokens(n);return this.lexer.state.top=i,{type:"blockquote",raw:t[0],tokens:o,text:n}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim();const i=n.length>1,o={type:"list",raw:"",ordered:i,start:i?+n.slice(0,-1):"",loose:!1,items:[]};n=i?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=i?n:"[*+-]");const s=new RegExp(`^( {0,3}${n})((?:[	 ][^\\n]*)?(?:\\n|$))`);let l="",a="",h=!1;for(;e;){let c=!1;if(!(t=s.exec(e))||this.rules.block.hr.test(e))break;l=t[0],e=e.substring(l.length);let f=t[2].split(`
`,1)[0].replace(/^\t+/,N=>" ".repeat(3*N.length)),u=e.split(`
`,1)[0],g=0;this.options.pedantic?(g=2,a=f.trimStart()):(g=t[2].search(/[^ ]/),g=g>4?1:g,a=f.slice(g),g+=t[1].length);let y=!1;if(!f&&/^ *$/.test(u)&&(l+=u+`
`,e=e.substring(u.length+1),c=!0),!c){const N=new RegExp(`^ {0,${Math.min(3,g-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ 	][^\\n]*)?(?:\\n|$))`),se=new RegExp(`^ {0,${Math.min(3,g-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),ie=new RegExp(`^ {0,${Math.min(3,g-1)}}(?:\`\`\`|~~~)`),re=new RegExp(`^ {0,${Math.min(3,g-1)}}#`);for(;e;){const Q=e.split(`
`,1)[0];if(u=Q,this.options.pedantic&&(u=u.replace(/^ {1,4}(?=( {4})*[^ ])/g,"  ")),ie.test(u)||re.test(u)||N.test(u)||se.test(e))break;if(u.search(/[^ ]/)>=g||!u.trim())a+=`
`+u.slice(g);else{if(y||f.search(/[^ ]/)>=4||ie.test(f)||re.test(f)||se.test(f))break;a+=`
`+u}!y&&!u.trim()&&(y=!0),l+=Q+`
`,e=e.substring(Q.length+1),f=u.slice(g)}}o.loose||(h?o.loose=!0:/\n *\n *$/.test(l)&&(h=!0));let x=null,T;this.options.gfm&&(x=/^\[[ xX]\] /.exec(a),x&&(T=x[0]!=="[ ] ",a=a.replace(/^\[[ xX]\] +/,""))),o.items.push({type:"list_item",raw:l,task:!!x,checked:T,loose:!1,text:a,tokens:[]}),o.raw+=l}o.items[o.items.length-1].raw=l.trimEnd(),o.items[o.items.length-1].text=a.trimEnd(),o.raw=o.raw.trimEnd();for(let c=0;c<o.items.length;c++)if(this.lexer.state.top=!1,o.items[c].tokens=this.lexer.blockTokens(o.items[c].text,[]),!o.loose){const f=o.items[c].tokens.filter(g=>g.type==="space"),u=f.length>0&&f.some(g=>/\n.*\n/.test(g.raw));o.loose=u}if(o.loose)for(let c=0;c<o.items.length;c++)o.items[c].loose=!0;return o}}html(e){const t=this.rules.block.html.exec(e);if(t)return{type:"html",block:!0,raw:t[0],pre:t[1]==="pre"||t[1]==="script"||t[1]==="style",text:t[0]}}def(e){const t=this.rules.block.def.exec(e);if(t){const n=t[1].toLowerCase().replace(/\s+/g," "),i=t[2]?t[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",o=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:n,raw:t[0],href:i,title:o}}}table(e){const t=this.rules.block.table.exec(e);if(!t||!/[:|]/.test(t[2]))return;const n=be(t[1]),i=t[2].replace(/^\||\| *$/g,"").split("|"),o=t[3]&&t[3].trim()?t[3].replace(/\n[ \t]*$/,"").split(`
`):[],s={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===i.length){for(const l of i)/^ *-+: *$/.test(l)?s.align.push("right"):/^ *:-+: *$/.test(l)?s.align.push("center"):/^ *:-+ *$/.test(l)?s.align.push("left"):s.align.push(null);for(const l of n)s.header.push({text:l,tokens:this.lexer.inline(l)});for(const l of o)s.rows.push(be(l,s.header.length).map(a=>({text:a,tokens:this.lexer.inline(a)})));return s}}lheading(e){const t=this.rules.block.lheading.exec(e);if(t)return{type:"heading",raw:t[0],depth:t[2].charAt(0)==="="?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}paragraph(e){const t=this.rules.block.paragraph.exec(e);if(t){const n=t[1].charAt(t[1].length-1)===`
`?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:n,tokens:this.lexer.inline(n)}}}text(e){const t=this.rules.block.text.exec(e);if(t)return{type:"text",raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){const t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:b(t[1])}}tag(e){const t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&/^<a /i.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){const t=this.rules.inline.link.exec(e);if(t){const n=t[2].trim();if(!this.options.pedantic&&/^</.test(n)){if(!/>$/.test(n))return;const s=L(n.slice(0,-1),"\\");if((n.length-s.length)%2===0)return}else{const s=yt(t[2],"()");if(s>-1){const a=(t[0].indexOf("!")===0?5:4)+t[1].length+s;t[2]=t[2].substring(0,s),t[0]=t[0].substring(0,a).trim(),t[3]=""}}let i=t[2],o="";if(this.options.pedantic){const s=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(i);s&&(i=s[1],o=s[3])}else o=t[3]?t[3].slice(1,-1):"";return i=i.trim(),/^</.test(i)&&(this.options.pedantic&&!/>$/.test(n)?i=i.slice(1):i=i.slice(1,-1)),we(t,{href:i&&i.replace(this.rules.inline.anyPunctuation,"$1"),title:o&&o.replace(this.rules.inline.anyPunctuation,"$1")},t[0],this.lexer)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){const i=(n[2]||n[1]).replace(/\s+/g," "),o=t[i.toLowerCase()];if(!o){const s=n[0].charAt(0);return{type:"text",raw:s,text:s}}return we(n,o,n[0],this.lexer)}}emStrong(e,t,n=""){let i=this.rules.inline.emStrongLDelim.exec(e);if(!i||i[3]&&n.match(/[\p{L}\p{N}]/u))return;if(!(i[1]||i[2]||"")||!n||this.rules.inline.punctuation.exec(n)){const s=[...i[0]].length-1;let l,a,h=s,c=0;const f=i[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(f.lastIndex=0,t=t.slice(-1*e.length+s);(i=f.exec(t))!=null;){if(l=i[1]||i[2]||i[3]||i[4]||i[5]||i[6],!l)continue;if(a=[...l].length,i[3]||i[4]){h+=a;continue}else if((i[5]||i[6])&&s%3&&!((s+a)%3)){c+=a;continue}if(h-=a,h>0)continue;a=Math.min(a,a+h+c);const u=[...i[0]][0].length,g=e.slice(0,s+i.index+u+a);if(Math.min(s,a)%2){const x=g.slice(1,-1);return{type:"em",raw:g,text:x,tokens:this.lexer.inlineTokens(x)}}const y=g.slice(2,-2);return{type:"strong",raw:g,text:y,tokens:this.lexer.inlineTokens(y)}}}}codespan(e){const t=this.rules.inline.code.exec(e);if(t){let n=t[2].replace(/\n/g," ");const i=/[^ ]/.test(n),o=/^ /.test(n)&&/ $/.test(n);return i&&o&&(n=n.substring(1,n.length-1)),n=b(n,!0),{type:"codespan",raw:t[0],text:n}}}br(e){const t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e){const t=this.rules.inline.del.exec(e);if(t)return{type:"del",raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}autolink(e){const t=this.rules.inline.autolink.exec(e);if(t){let n,i;return t[2]==="@"?(n=b(t[1]),i="mailto:"+n):(n=b(t[1]),i=n),{type:"link",raw:t[0],text:n,href:i,tokens:[{type:"text",raw:n,text:n}]}}}url(e){var n;let t;if(t=this.rules.inline.url.exec(e)){let i,o;if(t[2]==="@")i=b(t[0]),o="mailto:"+i;else{let s;do s=t[0],t[0]=((n=this.rules.inline._backpedal.exec(t[0]))==null?void 0:n[0])??"";while(s!==t[0]);i=b(t[0]),t[1]==="www."?o="http://"+t[0]:o=t[0]}return{type:"link",raw:t[0],text:i,href:o,tokens:[{type:"text",raw:i,text:i}]}}}inlineText(e){const t=this.rules.inline.text.exec(e);if(t){let n;return this.lexer.state.inRawBlock?n=t[0]:n=b(t[0]),{type:"text",raw:t[0],text:n}}}}const $t=/^(?: *(?:\n|$))+/,Tt=/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,St=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,C=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,zt=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,Ie=/(?:[*+-]|\d{1,9}[.)])/,Ee=k(/^(?!bull )((?:.|\n(?!\s*?\n|bull ))+?)\n {0,3}(=+|-+) *(?:\n+|$)/).replace(/bull/g,Ie).getRegex(),X=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Rt=/^[^\n]+/,K=/(?!\s*\])(?:\\.|[^\[\]\\])+/,It=k(/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/).replace("label",K).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Et=k(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,Ie).getRegex(),H="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",Y=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,vt=k("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))","i").replace("comment",Y).replace("tag",H).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),ve=k(X).replace("hr",C).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",H).getRegex(),At=k(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",ve).getRegex(),ee={blockquote:At,code:Tt,def:It,fences:St,heading:zt,hr:C,html:vt,lheading:Ee,list:Et,newline:$t,paragraph:ve,table:E,text:Rt},ye=k("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",C).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",H).getRegex(),Ct={...ee,table:ye,paragraph:k(X).replace("hr",C).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",ye).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",H).getRegex()},Mt={...ee,html:k(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",Y).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:E,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:k(X).replace("hr",C).replace("heading",` *#{1,6} *[^
]`).replace("lheading",Ee).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Ae=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Dt=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Ce=/^( {2,}|\\)\n(?!\s*$)/,Pt=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,M="\\p{P}$+<=>`^|~",Lt=k(/^((?![*_])[\spunctuation])/,"u").replace(/punctuation/g,M).getRegex(),Ft=/\[[^[\]]*?\]\([^\(\)]*?\)|`[^`]*?`|<[^<>]*?>/g,Ot=k(/^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/,"u").replace(/punct/g,M).getRegex(),Ut=k("^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)[punct](\\*+)(?=[\\s]|$)|[^punct\\s](\\*+)(?!\\*)(?=[punct\\s]|$)|(?!\\*)[punct\\s](\\*+)(?=[^punct\\s])|[\\s](\\*+)(?!\\*)(?=[punct])|(?!\\*)[punct](\\*+)(?!\\*)(?=[punct])|[^punct\\s](\\*+)(?=[^punct\\s])","gu").replace(/punct/g,M).getRegex(),qt=k("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\\s]|$)|[^punct\\s](_+)(?!_)(?=[punct\\s]|$)|(?!_)[punct\\s](_+)(?=[^punct\\s])|[\\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])","gu").replace(/punct/g,M).getRegex(),Bt=k(/\\([punct])/,"gu").replace(/punct/g,M).getRegex(),Zt=k(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),Ht=k(Y).replace("(?:-->|$)","-->").getRegex(),Nt=k("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",Ht).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),q=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,Qt=k(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/).replace("label",q).replace("href",/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Me=k(/^!?\[(label)\]\[(ref)\]/).replace("label",q).replace("ref",K).getRegex(),De=k(/^!?\[(ref)\](?:\[\])?/).replace("ref",K).getRegex(),jt=k("reflink|nolink(?!\\()","g").replace("reflink",Me).replace("nolink",De).getRegex(),te={_backpedal:E,anyPunctuation:Bt,autolink:Zt,blockSkip:Ft,br:Ce,code:Dt,del:E,emStrongLDelim:Ot,emStrongRDelimAst:Ut,emStrongRDelimUnd:qt,escape:Ae,link:Qt,nolink:De,punctuation:Lt,reflink:Me,reflinkSearch:jt,tag:Nt,text:Pt,url:E},Gt={...te,link:k(/^!?\[(label)\]\((.*?)\)/).replace("label",q).getRegex(),reflink:k(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",q).getRegex()},V={...te,escape:k(Ae).replace("])","~|])").getRegex(),url:k(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},Vt={...V,br:k(Ce).replace("{2,}","*").getRegex(),text:k(V.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},F={normal:ee,gfm:Ct,pedantic:Mt},I={normal:te,gfm:V,breaks:Vt,pedantic:Gt};class _{constructor(e){p(this,"tokens");p(this,"options");p(this,"state");p(this,"tokenizer");p(this,"inlineQueue");this.tokens=[],this.tokens.links=Object.create(null),this.options=e||z,this.options.tokenizer=this.options.tokenizer||new U,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const t={block:F.normal,inline:I.normal};this.options.pedantic?(t.block=F.pedantic,t.inline=I.pedantic):this.options.gfm&&(t.block=F.gfm,this.options.breaks?t.inline=I.breaks:t.inline=I.gfm),this.tokenizer.rules=t}static get rules(){return{block:F,inline:I}}static lex(e,t){return new _(t).lex(e)}static lexInline(e,t){return new _(t).inlineTokens(e)}lex(e){e=e.replace(/\r\n|\r/g,`
`),this.blockTokens(e,this.tokens);for(let t=0;t<this.inlineQueue.length;t++){const n=this.inlineQueue[t];this.inlineTokens(n.src,n.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[]){this.options.pedantic?e=e.replace(/\t/g,"    ").replace(/^ +$/gm,""):e=e.replace(/^( *)(\t+)/gm,(l,a,h)=>a+"    ".repeat(h.length));let n,i,o,s;for(;e;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some(l=>(n=l.call({lexer:this},e,t))?(e=e.substring(n.raw.length),t.push(n),!0):!1))){if(n=this.tokenizer.space(e)){e=e.substring(n.raw.length),n.raw.length===1&&t.length>0?t[t.length-1].raw+=`
`:t.push(n);continue}if(n=this.tokenizer.code(e)){e=e.substring(n.raw.length),i=t[t.length-1],i&&(i.type==="paragraph"||i.type==="text")?(i.raw+=`
`+n.raw,i.text+=`
`+n.text,this.inlineQueue[this.inlineQueue.length-1].src=i.text):t.push(n);continue}if(n=this.tokenizer.fences(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.heading(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.hr(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.blockquote(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.list(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.html(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.def(e)){e=e.substring(n.raw.length),i=t[t.length-1],i&&(i.type==="paragraph"||i.type==="text")?(i.raw+=`
`+n.raw,i.text+=`
`+n.raw,this.inlineQueue[this.inlineQueue.length-1].src=i.text):this.tokens.links[n.tag]||(this.tokens.links[n.tag]={href:n.href,title:n.title});continue}if(n=this.tokenizer.table(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.lheading(e)){e=e.substring(n.raw.length),t.push(n);continue}if(o=e,this.options.extensions&&this.options.extensions.startBlock){let l=1/0;const a=e.slice(1);let h;this.options.extensions.startBlock.forEach(c=>{h=c.call({lexer:this},a),typeof h=="number"&&h>=0&&(l=Math.min(l,h))}),l<1/0&&l>=0&&(o=e.substring(0,l+1))}if(this.state.top&&(n=this.tokenizer.paragraph(o))){i=t[t.length-1],s&&i.type==="paragraph"?(i.raw+=`
`+n.raw,i.text+=`
`+n.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=i.text):t.push(n),s=o.length!==e.length,e=e.substring(n.raw.length);continue}if(n=this.tokenizer.text(e)){e=e.substring(n.raw.length),i=t[t.length-1],i&&i.type==="text"?(i.raw+=`
`+n.raw,i.text+=`
`+n.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=i.text):t.push(n);continue}if(e){const l="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(l);break}else throw new Error(l)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let n,i,o,s=e,l,a,h;if(this.tokens.links){const c=Object.keys(this.tokens.links);if(c.length>0)for(;(l=this.tokenizer.rules.inline.reflinkSearch.exec(s))!=null;)c.includes(l[0].slice(l[0].lastIndexOf("[")+1,-1))&&(s=s.slice(0,l.index)+"["+"a".repeat(l[0].length-2)+"]"+s.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(l=this.tokenizer.rules.inline.blockSkip.exec(s))!=null;)s=s.slice(0,l.index)+"["+"a".repeat(l[0].length-2)+"]"+s.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;(l=this.tokenizer.rules.inline.anyPunctuation.exec(s))!=null;)s=s.slice(0,l.index)+"++"+s.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;e;)if(a||(h=""),a=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some(c=>(n=c.call({lexer:this},e,t))?(e=e.substring(n.raw.length),t.push(n),!0):!1))){if(n=this.tokenizer.escape(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.tag(e)){e=e.substring(n.raw.length),i=t[t.length-1],i&&n.type==="text"&&i.type==="text"?(i.raw+=n.raw,i.text+=n.text):t.push(n);continue}if(n=this.tokenizer.link(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(n.raw.length),i=t[t.length-1],i&&n.type==="text"&&i.type==="text"?(i.raw+=n.raw,i.text+=n.text):t.push(n);continue}if(n=this.tokenizer.emStrong(e,s,h)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.codespan(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.br(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.del(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.autolink(e)){e=e.substring(n.raw.length),t.push(n);continue}if(!this.state.inLink&&(n=this.tokenizer.url(e))){e=e.substring(n.raw.length),t.push(n);continue}if(o=e,this.options.extensions&&this.options.extensions.startInline){let c=1/0;const f=e.slice(1);let u;this.options.extensions.startInline.forEach(g=>{u=g.call({lexer:this},f),typeof u=="number"&&u>=0&&(c=Math.min(c,u))}),c<1/0&&c>=0&&(o=e.substring(0,c+1))}if(n=this.tokenizer.inlineText(o)){e=e.substring(n.raw.length),n.raw.slice(-1)!=="_"&&(h=n.raw.slice(-1)),a=!0,i=t[t.length-1],i&&i.type==="text"?(i.raw+=n.raw,i.text+=n.text):t.push(n);continue}if(e){const c="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(c);break}else throw new Error(c)}}return t}}class B{constructor(e){p(this,"options");this.options=e||z}code(e,t,n){var o;const i=(o=(t||"").match(/^\S*/))==null?void 0:o[0];return e=e.replace(/\n$/,"")+`
`,i?'<pre><code class="language-'+b(i)+'">'+(n?e:b(e,!0))+`</code></pre>
`:"<pre><code>"+(n?e:b(e,!0))+`</code></pre>
`}blockquote(e){return`<blockquote>
${e}</blockquote>
`}html(e,t){return e}heading(e,t,n){return`<h${t}>${e}</h${t}>
`}hr(){return`<hr>
`}list(e,t,n){const i=t?"ol":"ul",o=t&&n!==1?' start="'+n+'"':"";return"<"+i+o+`>
`+e+"</"+i+`>
`}listitem(e,t,n){return`<li>${e}</li>
`}checkbox(e){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox">'}paragraph(e){return`<p>${e}</p>
`}table(e,t){return t&&(t=`<tbody>${t}</tbody>`),`<table>
<thead>
`+e+`</thead>
`+t+`</table>
`}tablerow(e){return`<tr>
${e}</tr>
`}tablecell(e,t){const n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+e+`</${n}>
`}strong(e){return`<strong>${e}</strong>`}em(e){return`<em>${e}</em>`}codespan(e){return`<code>${e}</code>`}br(){return"<br>"}del(e){return`<del>${e}</del>`}link(e,t,n){const i=xe(e);if(i===null)return n;e=i;let o='<a href="'+e+'"';return t&&(o+=' title="'+t+'"'),o+=">"+n+"</a>",o}image(e,t,n){const i=xe(e);if(i===null)return n;e=i;let o=`<img src="${e}" alt="${n}"`;return t&&(o+=` title="${t}"`),o+=">",o}text(e){return e}}class ne{strong(e){return e}em(e){return e}codespan(e){return e}del(e){return e}html(e){return e}text(e){return e}link(e,t,n){return""+n}image(e,t,n){return""+n}br(){return""}}class ${constructor(e){p(this,"options");p(this,"renderer");p(this,"textRenderer");this.options=e||z,this.options.renderer=this.options.renderer||new B,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new ne}static parse(e,t){return new $(t).parse(e)}static parseInline(e,t){return new $(t).parseInline(e)}parse(e,t=!0){let n="";for(let i=0;i<e.length;i++){const o=e[i];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[o.type]){const s=o,l=this.options.extensions.renderers[s.type].call({parser:this},s);if(l!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(s.type)){n+=l||"";continue}}switch(o.type){case"space":continue;case"hr":{n+=this.renderer.hr();continue}case"heading":{const s=o;n+=this.renderer.heading(this.parseInline(s.tokens),s.depth,bt(this.parseInline(s.tokens,this.textRenderer)));continue}case"code":{const s=o;n+=this.renderer.code(s.text,s.lang,!!s.escaped);continue}case"table":{const s=o;let l="",a="";for(let c=0;c<s.header.length;c++)a+=this.renderer.tablecell(this.parseInline(s.header[c].tokens),{header:!0,align:s.align[c]});l+=this.renderer.tablerow(a);let h="";for(let c=0;c<s.rows.length;c++){const f=s.rows[c];a="";for(let u=0;u<f.length;u++)a+=this.renderer.tablecell(this.parseInline(f[u].tokens),{header:!1,align:s.align[u]});h+=this.renderer.tablerow(a)}n+=this.renderer.table(l,h);continue}case"blockquote":{const s=o,l=this.parse(s.tokens);n+=this.renderer.blockquote(l);continue}case"list":{const s=o,l=s.ordered,a=s.start,h=s.loose;let c="";for(let f=0;f<s.items.length;f++){const u=s.items[f],g=u.checked,y=u.task;let x="";if(u.task){const T=this.renderer.checkbox(!!g);h?u.tokens.length>0&&u.tokens[0].type==="paragraph"?(u.tokens[0].text=T+" "+u.tokens[0].text,u.tokens[0].tokens&&u.tokens[0].tokens.length>0&&u.tokens[0].tokens[0].type==="text"&&(u.tokens[0].tokens[0].text=T+" "+u.tokens[0].tokens[0].text)):u.tokens.unshift({type:"text",text:T+" "}):x+=T+" "}x+=this.parse(u.tokens,h),c+=this.renderer.listitem(x,y,!!g)}n+=this.renderer.list(c,l,a);continue}case"html":{const s=o;n+=this.renderer.html(s.text,s.block);continue}case"paragraph":{const s=o;n+=this.renderer.paragraph(this.parseInline(s.tokens));continue}case"text":{let s=o,l=s.tokens?this.parseInline(s.tokens):s.text;for(;i+1<e.length&&e[i+1].type==="text";)s=e[++i],l+=`
`+(s.tokens?this.parseInline(s.tokens):s.text);n+=t?this.renderer.paragraph(l):l;continue}default:{const s='Token with "'+o.type+'" type was not found.';if(this.options.silent)return console.error(s),"";throw new Error(s)}}}return n}parseInline(e,t){t=t||this.renderer;let n="";for(let i=0;i<e.length;i++){const o=e[i];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[o.type]){const s=this.options.extensions.renderers[o.type].call({parser:this},o);if(s!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(o.type)){n+=s||"";continue}}switch(o.type){case"escape":{const s=o;n+=t.text(s.text);break}case"html":{const s=o;n+=t.html(s.text);break}case"link":{const s=o;n+=t.link(s.href,s.title,this.parseInline(s.tokens,t));break}case"image":{const s=o;n+=t.image(s.href,s.title,s.text);break}case"strong":{const s=o;n+=t.strong(this.parseInline(s.tokens,t));break}case"em":{const s=o;n+=t.em(this.parseInline(s.tokens,t));break}case"codespan":{const s=o;n+=t.codespan(s.text);break}case"br":{n+=t.br();break}case"del":{const s=o;n+=t.del(this.parseInline(s.tokens,t));break}case"text":{const s=o;n+=t.text(s.text);break}default:{const s='Token with "'+o.type+'" type was not found.';if(this.options.silent)return console.error(s),"";throw new Error(s)}}}return n}}class v{constructor(e){p(this,"options");this.options=e||z}preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}}p(v,"passThroughHooks",new Set(["preprocess","postprocess","processAllTokens"]));var A,W,Z,Le;class Pe{constructor(...e){j(this,A);j(this,Z);p(this,"defaults",J());p(this,"options",this.setOptions);p(this,"parse",D(this,A,W).call(this,_.lex,$.parse));p(this,"parseInline",D(this,A,W).call(this,_.lexInline,$.parseInline));p(this,"Parser",$);p(this,"Renderer",B);p(this,"TextRenderer",ne);p(this,"Lexer",_);p(this,"Tokenizer",U);p(this,"Hooks",v);this.use(...e)}walkTokens(e,t){var i,o;let n=[];for(const s of e)switch(n=n.concat(t.call(this,s)),s.type){case"table":{const l=s;for(const a of l.header)n=n.concat(this.walkTokens(a.tokens,t));for(const a of l.rows)for(const h of a)n=n.concat(this.walkTokens(h.tokens,t));break}case"list":{const l=s;n=n.concat(this.walkTokens(l.items,t));break}default:{const l=s;(o=(i=this.defaults.extensions)==null?void 0:i.childTokens)!=null&&o[l.type]?this.defaults.extensions.childTokens[l.type].forEach(a=>{n=n.concat(this.walkTokens(l[a],t))}):l.tokens&&(n=n.concat(this.walkTokens(l.tokens,t)))}}return n}use(...e){const t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(n=>{const i={...n};if(i.async=this.defaults.async||i.async||!1,n.extensions&&(n.extensions.forEach(o=>{if(!o.name)throw new Error("extension name required");if("renderer"in o){const s=t.renderers[o.name];s?t.renderers[o.name]=function(...l){let a=o.renderer.apply(this,l);return a===!1&&(a=s.apply(this,l)),a}:t.renderers[o.name]=o.renderer}if("tokenizer"in o){if(!o.level||o.level!=="block"&&o.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");const s=t[o.level];s?s.unshift(o.tokenizer):t[o.level]=[o.tokenizer],o.start&&(o.level==="block"?t.startBlock?t.startBlock.push(o.start):t.startBlock=[o.start]:o.level==="inline"&&(t.startInline?t.startInline.push(o.start):t.startInline=[o.start]))}"childTokens"in o&&o.childTokens&&(t.childTokens[o.name]=o.childTokens)}),i.extensions=t),n.renderer){const o=this.defaults.renderer||new B(this.defaults);for(const s in n.renderer){if(!(s in o))throw new Error(`renderer '${s}' does not exist`);if(s==="options")continue;const l=s,a=n.renderer[l],h=o[l];o[l]=(...c)=>{let f=a.apply(o,c);return f===!1&&(f=h.apply(o,c)),f||""}}i.renderer=o}if(n.tokenizer){const o=this.defaults.tokenizer||new U(this.defaults);for(const s in n.tokenizer){if(!(s in o))throw new Error(`tokenizer '${s}' does not exist`);if(["options","rules","lexer"].includes(s))continue;const l=s,a=n.tokenizer[l],h=o[l];o[l]=(...c)=>{let f=a.apply(o,c);return f===!1&&(f=h.apply(o,c)),f}}i.tokenizer=o}if(n.hooks){const o=this.defaults.hooks||new v;for(const s in n.hooks){if(!(s in o))throw new Error(`hook '${s}' does not exist`);if(s==="options")continue;const l=s,a=n.hooks[l],h=o[l];v.passThroughHooks.has(s)?o[l]=c=>{if(this.defaults.async)return Promise.resolve(a.call(o,c)).then(u=>h.call(o,u));const f=a.call(o,c);return h.call(o,f)}:o[l]=(...c)=>{let f=a.apply(o,c);return f===!1&&(f=h.apply(o,c)),f}}i.hooks=o}if(n.walkTokens){const o=this.defaults.walkTokens,s=n.walkTokens;i.walkTokens=function(l){let a=[];return a.push(s.call(this,l)),o&&(a=a.concat(o.call(this,l))),a}}this.defaults={...this.defaults,...i}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return _.lex(e,t??this.defaults)}parser(e,t){return $.parse(e,t??this.defaults)}}A=new WeakSet,W=function(e,t){return(n,i)=>{const o={...i},s={...this.defaults,...o};this.defaults.async===!0&&o.async===!1&&(s.silent||console.warn("marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored."),s.async=!0);const l=D(this,Z,Le).call(this,!!s.silent,!!s.async);if(typeof n>"u"||n===null)return l(new Error("marked(): input parameter is undefined or null"));if(typeof n!="string")return l(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));if(s.hooks&&(s.hooks.options=s),s.async)return Promise.resolve(s.hooks?s.hooks.preprocess(n):n).then(a=>e(a,s)).then(a=>s.hooks?s.hooks.processAllTokens(a):a).then(a=>s.walkTokens?Promise.all(this.walkTokens(a,s.walkTokens)).then(()=>a):a).then(a=>t(a,s)).then(a=>s.hooks?s.hooks.postprocess(a):a).catch(l);try{s.hooks&&(n=s.hooks.preprocess(n));let a=e(n,s);s.hooks&&(a=s.hooks.processAllTokens(a)),s.walkTokens&&this.walkTokens(a,s.walkTokens);let h=t(a,s);return s.hooks&&(h=s.hooks.postprocess(h)),h}catch(a){return l(a)}}},Z=new WeakSet,Le=function(e,t){return n=>{if(n.message+=`
Please report this to https://github.com/markedjs/marked.`,e){const i="<p>An error occurred:</p><pre>"+b(n.message+"",!0)+"</pre>";return t?Promise.resolve(i):i}if(t)return Promise.reject(n);throw n}};const S=new Pe;function d(r,e){return S.parse(r,e)}d.options=d.setOptions=function(r){return S.setOptions(r),d.defaults=S.defaults,Se(d.defaults),d};d.getDefaults=J;d.defaults=z;d.use=function(...r){return S.use(...r),d.defaults=S.defaults,Se(d.defaults),d};d.walkTokens=function(r,e){return S.walkTokens(r,e)};d.parseInline=S.parseInline;d.Parser=$;d.parser=$.parse;d.Renderer=B;d.TextRenderer=ne;d.Lexer=_;d.lexer=_.lex;d.Tokenizer=U;d.Hooks=v;d.parse=d;d.options;d.setOptions;d.use;d.walkTokens;d.parseInline;$.parse;_.lex;function Fe(r,e){return e=ge.getLanguage(e)?e:"plaintext",r=ge.highlight(r,{language:e}).value,{language:e,code:`<code class="hljs language-${e}">${r}</code>`}}function Wt(r,e){const{code:t}=Fe(r,e);return`<pre class="markdown-code-block plain">${t}</pre>`}function Jt(r,e){const{language:t,code:n}=Fe(r,e);return t==="plaintext"?`<pre class="markdown-code-block plain">${n}</pre>`:`<div class="wrapped-code-container">
    <div class="lang-banner">
        <span>${t}</span>
    </div>
    <pre class="markdown-code-block wrapped">${n}</pre>
</div>`}function Oe(r=!1){const e=new Pe,t=new e.Renderer;return r?t.code=Jt:t.code=Wt,e.setOptions({renderer:t}),e.parse.bind(e)}const _e=Oe(!1),$e=Oe(!0);function Ue(r,e){let t=null;const n=function(...i){const o=()=>{t=null,r.apply(this,i)};t!==null&&clearTimeout(t),t=setTimeout(o,e)};return n.cancel=function(){t!==null&&(clearTimeout(t),t=null)},n}function Xt(r,e=8){let t=0;return(...n)=>{const i=new Date().getTime();i-t>=e&&(t=i,r(...n))}}const R=[];function Kt(r,e){return r!==r?e===e:r!==e||r&&typeof r=="object"||typeof r=="function"}function w(r,e=G){let t;const n=new Set;function i(a){if(Kt(r,a)&&(r=a,t)){const h=!R.length;for(const c of n)c[1](),R.push(c,r);if(h){for(let c=0;c<R.length;c+=2)R[c][0](R[c+1]);R.length=0}}}function o(a){i(a(r))}function s(a,h=G){const c=[a,h];return n.add(c),n.size===1&&(t=e(i,o)||G),a(r),()=>{n.delete(c),n.size===0&&t&&(t(),t=null)}}const l={_:r,set:i,update:o,subscribe:s};return l.subscribe(a=>l._=a),l}function Yt(r,e){return qe[r](e)}const qe={functions(r){return r?Object.entries(r).reduce((e,[t,n])=>{const i={},{title:o,result_type:s}=n;return o&&(i.title=o),(s==="markdown"||s==="text")&&(i.result_type=s),e[t]=i,e},{}):{}}},en={functions:{}};function tn(){const r={...w({functions:{}}),setAll(e){this.update(t=>{for(const n in qe){const i=n;t[i]=Yt(i,e[i])}return t})}};return r.set({...en}),r}function nn(){return{...w(!1)}}const sn={Server:!0,Client:!0};function rn(){return{...w([]),showType(e){return sn[e]},remove(e){this.update(t=>t.filter(n=>n.text!==e))},add(e,t){this._.some(n=>n.text===t)||(console.error(`${e} Error: ${t}`),this.update(n=>(n.push({type:e,text:t}),n)))}}}class on{constructor(...e){p(this,"instance");this.instance=tt(...e)}on(e,t){this.instance.on(e,t)}emit(e,...t){if(typeof t[t.length-1]=="function"){const n=t.pop();this.instance.emit(e,...t,n)}else this.instance.emit(e,...t)}off(e,t){t?this.instance.off(e,t):this.instance.off(e)}}function ln(r,e){const t="assistant",n="content"in e&&e.content?e.content:"";if(!(e.tool_calls&&e.tool_calls.length>0))return{id:r,role:t,content:n};const o=e.tool_calls[0];if(!o.id)return{error:"Tool call has no id. Received a partial delta for a tool call that does not exist yet."};if(o.type!=="function")return{error:"Currently, only function tool calls are supported."};const s="function";let{id:l,function:{name:a,arguments:h}}=o;return{id:r,role:t,content:n,tool_calls:[{id:l,type:s,function:{name:a||"",arguments:h||""}}]}}function an(r,e){var u;if(r.id!==e.id)throw new Error("Message id and delta id must match");if(e.content&&(r.content=r.content!==null?r.content+e.content:e.content),!(e.tool_calls&&e.tool_calls.length>0))return;const n=e.tool_calls[0],i=n.index;if(typeof i!="number"||!n.function)return;const o=!n.id||!((u=n.function)!=null&&u.name);r.tool_calls||(r.tool_calls=[]);const s=r.tool_calls.length,l=i>s,a=i===s;if(l)return;if(a){if(o)return;const g="function",{id:y,function:{name:x,arguments:T}}=n;return r.tool_calls.push({id:y,type:g,function:{name:x,arguments:T}}),!0}const h=r.tool_calls[i],{function:{name:c,arguments:f}}=n;c&&(h.function.name=c),f&&(h.function.arguments+=f)}const Te={user(r){return{role:"user",id:"id"in r&&r.id?r.id:O(),content:r.content?r.content:""}},assistant(r){var t,n;const e=r.tool_calls&&r.tool_calls.length>0?r.tool_calls:void 0;if(e){for(const i of e)if(!(i.id&&((t=i.function)!=null&&t.name)&&((n=i.function)!=null&&n.arguments)))return null}return{role:"assistant",id:"id"in r&&r.id?r.id:O(),content:r.content??"",tool_calls:e}},tool(r){return r.tool_call_id?{role:"tool",id:"id"in r&&r.id?r.id:O(),content:r.content??"",tool_call_id:r.tool_call_id}:null}};function Be(r){return r.role&&r.role in Te?Te[r.role](r):null}function cn(r){return r.map(e=>Be(e)).filter(e=>e!==null)}function un(r){const e=cn(r);return{order:e.map(t=>t.id),mapping:ut(e,"id")}}const hn={user(r){let e={role:"user",content:""};if(typeof r.content=="string")e.content=r.content;else{e.content=[];for(const t of r.content)t.type!=="binary"&&e.content.push(t)}return e},assistant(r){let e={role:"assistant",content:r.content};return r.tool_calls&&r.tool_calls.length>0&&(e.tool_calls=r.tool_calls),e},tool(r){return{role:"tool",content:r.content,tool_call_id:r.tool_call_id}}};function pn(r){return hn[r.role](r)}function fn(r,e){return e.map(t=>pn(r[t])).filter(t=>t!==null)}class gn{constructor(){p(this,"mapping",w({}));p(this,"order",[])}subscribe(e){return this.mapping.subscribe(t=>e({mapping:t,order:this.order}))}set(e){ht(this.order,e.order),this.mapping.set(e.mapping)}oaiMessages(){return fn(this.mapping._,this.order)}serialize(){return{mapping:this.mapping._,order:this.order}}newUserMessage(e){this.setMessage({id:O(),role:"user",content:e})}updateUserMessageContent(e,t){this.mapping.update(n=>{const i=n[e];if(typeof i.content=="string")return i.content=t,n;for(const o of i.content)if(o.type==="text")return o.text=t,n;throw new Error(`Message ${e} has no text content part.`)})}removeAfterId(e){const t=this.order.indexOf(e);t!==-1&&this.removeAfterIndex(t)}removeAfterIndex(e){if(!this.order[e])return;const n=this.order.splice(e+1);this.mapping.update(i=>{for(const o of n)delete i[o];return i})}handleSetAllEvent(e){const{mapping:t,order:n}=un(e);return this.set({order:n,mapping:t})}handleSetEvent(e){const t=Be(e);if(!t)return`Invalid message: ${e}`;this.setMessage(t)}handleUpdateEvent(e){if(e.role&&e.role!=="assistant")return`Invalid message update: role must be assistant.: ${e}`;const t=e.id;return t?t in this.mapping._?this.updateExistingFromDelta(t,e):this.addNewFromDelta(t,e):`Invalid message update: id not defined.: ${e}`}addNewFromDelta(e,t){const n=ln(e,t);if("error"in n)return n.error;this.setMessage(n)}updateExistingFromDelta(e,t){let n;return this.mapping.update(i=>{const o=i[e];return(o==null?void 0:o.role)==="assistant"?an(o,t):n=`Invalid message update. Existing message '${e}' is not an assistant message.`,i}),n}setMessage(e){e.id in this.mapping._||this.order.push(e.id),this.mapping.update(t=>(t[e.id]=e,t))}}const dn={async binary(r){const e=await ke(r,"ArrayBuffer");return{type:"binary",name:r.name,fileType:r.type,content:e}},async image_url(r){return{type:"image_url",image_url:{url:await ke(r,"DataURL")}}}};function kn(r){return r.type.startsWith("image")?"image_url":"binary"}class mn{constructor(){p(this,"text",w(""));p(this,"images",w([]));p(this,"files",w([]))}serialize(){return{text:this.text._,images:this.images._,files:this.files._}}set(e){this.text.set(e.text),this.images.set(e.images),this.files.set(e.files)}clear(){this.text.set(""),this.files.set([]),this.images.set([])}textContentPart(){return{type:"text",text:this.text._}}isEmpty(){return this.text._.trim()===""&&this.files._.length===0&&this.images._.length===0}removeImage(e){this.images.update(t=>(t.splice(e,1),t))}removeFile(e){this.files.update(t=>(t.splice(e,1),t))}addImage(e){this.images.update(t=>(t.push(e),t))}addFile(e){this.files.update(t=>(t.push(e),t))}textIsEmpty(){return this.text._.trim()===""}async upload(){pt(async e=>{if(!e)return;const t=kn(e);let n;try{n=await dn[t](e)}catch{return}n&&(n.type==="image_url"?this.addImage(n):this.addFile(n))})}getContentParts(){let e=[...this.files._,...this.images._];return this.textIsEmpty()||e.push(this.textContentPart()),e}}class xn{constructor(){p(this,"ghostDiv",w(null));p(this,"containerDiv",w(null));p(this,"autoEnabled",!0);p(this,"lastScrollHeight",0);p(this,"lastScrollTop",0);p(this,"handleUserScrollDebounced",Ue(()=>this.handleUserScroll(),100));p(this,"autoScrollThrottled",Xt(()=>this.autoScroll(),200))}scroll(e){e==="force"?this.forceScroll():this.autoScrollThrottled()}handleUserScroll(){if(!this.containerDiv._)return;const{scrollHeight:e,scrollTop:t,clientHeight:n}=this.containerDiv._;t<this.lastScrollTop?this.autoEnabled=!1:e-t<=n+50&&(this.autoEnabled=!0),this.lastScrollTop=t}scrollChat(e=!1){var n;if(!this.containerDiv._)return;const{scrollHeight:t}=this.containerDiv._;e&&t===this.lastScrollHeight||((n=this.ghostDiv._)==null||n.scrollIntoView({behavior:"smooth",block:"start"}),this.lastScrollHeight=t)}autoScroll(){this.autoEnabled&&oe().then(()=>this.scrollChat(!0))}forceScroll(){oe().then(()=>this.scrollChat()),this.autoEnabled=!0}}class bn{constructor(e){p(this,"scroll",new xn);p(this,"rendered",w([]));p(this,"connected",w(!1));p(this,"prompt",new mn);p(this,"messages",new gn);p(this,"config",tn());p(this,"errors",rn());p(this,"generating",nn());p(this,"defaultMessages",w([]));this.socket=e,this.socket=e,this.socket.on("connect",()=>{console.log("connected"),this.connected.set(!0)}),this.socket.on("disconnect",()=>{console.log("disconnected"),this.connected.set(!1)}),this.connected.subscribe(t=>console.log("connected",t)),this.socket.on("error",t=>this.errors.add("Server",t)),this.socket.on("error",()=>this.generating.set(!1)),this.socket.on("config",t=>this.config.setAll(t)),this.socket.on("generating-started",()=>this.generating.set(!0)),this.socket.on("generating-done",()=>this.generating.set(!1)),this.socket.on("message-set-all",this.handleSetAllEvent.bind(this)),this.socket.on("message-set",this.handleSetEvent.bind(this)),this.socket.on("message-update",this.handleUpdateEvent.bind(this)),this.socket.on("default-messages",t=>{this.defaultMessages.set(t)}),this.defaultMessages.subscribe(()=>this.setMessagesIfDefault()),this.messages.subscribe(()=>this.setMessagesIfDefault()),this.messages.subscribe(({mapping:t,order:n})=>{this.rendered.set(wn(t,n)),this.scroll.scroll("auto")})}setMessagesIfDefault(){this.messages.order.length===0&&this.defaultMessages._.length>0&&this.handleSetAllEvent(this.defaultMessages._)}serialize(){return{prompt:this.prompt.serialize(),messages:this.messages.serialize(),config:this.config._,errors:this.errors._,generating:this.generating._,defaultMessages:this.defaultMessages._}}setFromSerialized(e){e.prompt&&this.prompt.set(e.prompt),e.messages&&this.messages.set(e.messages),e.config&&this.config.set(e.config),e.errors&&this.errors.set(e.errors),e.defaultMessages&&this.defaultMessages.set(e.defaultMessages),e.generating!==void 0&&this.generating.set(e.generating)}handleSetAllEvent(e){this.generating._||(this.messages.handleSetAllEvent(e),this.scroll.scroll("force"))}handleSetEvent(e){if(this.generating._)return;const t=this.messages.handleSetEvent(e);t&&this.errors.add("Client",t)}handleUpdateEvent(e){if(this.generating._)return;const t=this.messages.handleUpdateEvent(e);t&&this.errors.add("Client",t)}reset(){this.messages.handleSetAllEvent([])}upload(){this.prompt.upload()}stopGenerating(){this.generating.set(!1)}sendMessage(){if(this.generating._||this.prompt.isEmpty())return;const e=this.prompt.getContentParts(),t=e.length===1&&e[0].type==="text"?this.prompt.text._:e;this.messages.newUserMessage(t),this.prompt.clear(),this.startGenerating()}changeUserMessageAndSubmit(e,t){this.generating._||(this.messages.updateUserMessageContent(e,t),this.regenerateAfterId(e))}regenerateOnAgentResponse(e){if(this.generating._)return;const t=this.rendered._[e-1];if(!t||t.type!=="user")throw new Error("Tried to regenerate on an index not preceded by a user message");this.regenerateAfterId(t.id)}renderAssistantMarkdown(e){return $e(e)}renderFunctionCallMarkdown(e){return $e(e)}renderFunctionCallArgs(e){if(!e)return"";let t;try{t=JSON.stringify(JSON.parse(e),null,2)}catch{t=e}return _e("```json\n"+t+"\n```")}renderFunctionTitle(e,t){var i;const n=(i=t[e])==null?void 0:i.title;return _e(n??`Function call to **\`${e}()\`**`)}getFunctionResultType(e,t){var n;return((n=t[e])==null?void 0:n.result_type)??"text"}getFunctionCallStatus(e,t){const n=t&&e===null;return e&&ct(e)?"error":n?"progress":"complete"}userContentToText(e){if(typeof e=="string")return e;for(const t of e)if(t.type==="text")return t.text;return""}userContentToFiles(e){return typeof e=="string"?[]:e.filter(t=>t.type!=="text")}regenerateAfterId(e){this.messages.removeAfterId(e),this.startGenerating()}startGenerating(){this.socket.emit("start-generating",{messages:this.messages.oaiMessages()}),this.generating.set(!0),this.scroll.scroll("force")}}function wn(r,e){let t=e.map(o=>r[o]),n,i=[];for(;t.length>0&&(n=t.shift());){if(n.role==="user"){i.push({id:n.id,type:"user",content:n.content});continue}const o={type:"agent",parts:[]};for(t.unshift(n);t[0]&&t[0].role!=="user";){const s=t.shift(),l=s.role,a=s.content??"";if(l==="assistant"){o.parts.push({type:"content",content:a});const{tool_calls:c}=s;if(c&&c.length>0)for(let{id:f,function:{name:u,arguments:g}}of c)u=u??"",g=g??"",o.parts.push({type:"tool_call",id:f,name:u,arguments:g,result:null});continue}const h=s.tool_call_id;for(let c=o.parts.length-1;c>=0;c--){let f=o.parts[c];if(f.type==="tool_call"&&f.id===h){f.result=s.content;break}}}i.push(o)}return i}const yn="dark";function _n(){const r={...w(!1),checkDarkModePreferred(){return!!window.matchMedia("(prefers-color-scheme: dark)").matches},updateDocument(e){document.documentElement.classList[e?"add":"remove"](yn)}};return r.subscribe(r.updateDocument.bind(r)),r.set(r.checkDarkModePreferred()),r}function $n(r){let e,t,n;var i=r[0];function o(s,l){return{props:{chat:s[1]}}}return i&&(e=le(i,o(r))),{c(){e&&ce(e.$$.fragment),t=ae()},l(s){e&&Ke(e.$$.fragment,s),t=ae()},m(s,l){e&&ue(e,s,l),Ge(s,t,l),n=!0},p(s,[l]){if(l&1&&i!==(i=s[0])){if(e){et();const a=e;he(a.$$.fragment,1,0,()=>{fe(a,1)}),Ye()}i?(e=le(i,o(s)),ce(e.$$.fragment),pe(e.$$.fragment,1),ue(e,t.parentNode,t)):e=null}},i(s){n||(e&&pe(e.$$.fragment,s),n=!0)},o(s){e&&he(e.$$.fragment,s),n=!1},d(s){s&&Ve(t),e&&fe(e,s)}}}function Tn(r,e,t){let n;We(async()=>{t(0,n=(await Qe(()=>import("../chunks/Chat.743e41af.js"),["../chunks/Chat.743e41af.js","../chunks/scheduler.afda2bc1.js","../chunks/index.3b22678c.js","../assets/Chat.99a2a00d.css"],import.meta.url)).default)});const i="",o=new on(i,{transports:["websocket"]});o.on("connect",()=>console.log("CONNECTED")),_n();const s=new bn(o),l=ft("chat");l&&s.setFromSerialized(l);const a=Ue(()=>{setTimeout(()=>{gt("chat",s.serialize())})},500);return s.messages.subscribe(a),s.prompt.files.subscribe(a),s.prompt.images.subscribe(a),s.prompt.text.subscribe(a),s.errors.subscribe(a),s.config.subscribe(a),[n,s]}class An extends Je{constructor(e){super(),Xe(this,e,Tn,$n,je,{})}}export{An as component};
