UNPKG

@think-apps/vue-chat-sdk

Version:

Vue.js SDK for Think Apps Chat Integration

67 lines (64 loc) 115 kB
"use strict";var Sn=Object.defineProperty;var Nn=(e,t,n)=>t in e?Sn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var z=(e,t,n)=>Nn(e,typeof t!="symbol"?t+"":t,n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("vue");function Xe(){if(window.innerWidth>640)return;document.querySelectorAll("input, textarea, button, span, div, p, a").forEach(t=>{const n=window.getComputedStyle(t);parseFloat(n.fontSize)<14&&(t.style.fontSize="16px")})}function Bt(){typeof window>"u"||window.innerWidth>640||(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Xe):Xe())}typeof window<"u"&&Bt();function Tn(){return null}const $t=Symbol("chat-config"),Ot={baseURL:"",apiKey:null,defaultAgentId:null,timeout:3e4,getHeaders:null,getUserKey:null};function It(e={}){const t=a.ref({...Ot,...e});function n(o){Object.assign(t.value,o)}async function s(){const o={};if(t.value.apiKey&&(o["X-API-Key"]=t.value.apiKey),t.value.getHeaders){const i=await t.value.getHeaders();Object.assign(o,i)}return o}async function r(){return t.value.userKey?t.value.userKey:t.value.getUserKey?await t.value.getUserKey():`user_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}const l={config:t,updateConfig:n,getEffectiveHeaders:s,getEffectiveUserKey:r};return a.provide($t,l),l}function Lt(e={}){const t=a.inject($t,null);if(t){if(Object.keys(e).length>0){const o=a.computed(()=>({...t.config.value,...e}));return{config:o,updateConfig:t.updateConfig,getEffectiveHeaders:async()=>{const i={};if(o.value.apiKey&&(i["X-API-Key"]=o.value.apiKey),o.value.getHeaders){const c=await o.value.getHeaders();Object.assign(i,c)}return i},getEffectiveUserKey:async()=>o.value.userKey?o.value.userKey:o.value.getUserKey?await o.value.getUserKey():`user_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}}return t}const n=a.ref({...Ot,...e});function s(o){Object.assign(n.value,o)}async function r(){const o={};if(n.value.apiKey&&(o["X-API-Key"]=n.value.apiKey),n.value.getHeaders){const i=await n.value.getHeaders();Object.assign(o,i)}return o}async function l(){return n.value.userKey?n.value.userKey:n.value.getUserKey?await n.value.getUserKey():`user_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}return{config:n,updateConfig:s,getEffectiveHeaders:r,getEffectiveUserKey:l}}class kt extends Error{constructor(t,n,s){super(t),this.name="HttpError",this.status=n,this.response=s}}function Dt(e={}){const{baseURL:t="",timeout:n=3e4,headers:s={}}=e;function r(f){return f.startsWith("http")?f:`${t.replace(/\/$/,"")}/${f.replace(/^\//,"")}`}async function l(f){if(!f.ok)throw new kt(`HTTP ${f.status}: ${f.statusText}`,f.status,f);return f}function o(f={}){const{method:b="GET",headers:R={},body:C,signal:H,...K}=f,I={method:b.toUpperCase(),headers:{...s,...R},signal:H,...K};return C!==void 0&&(typeof C=="object"&&!(C instanceof FormData)?(I.body=JSON.stringify(C),I.headers["Content-Type"]="application/json"):I.body=C),I}function i(f,b){const R=new AbortController;b&&(b.aborted?R.abort():b.addEventListener("abort",()=>{R.abort()}));const C=setTimeout(()=>{R.abort()},f),H=()=>{clearTimeout(C)};return{signal:R.signal,cleanup:H}}async function c(f,b={}){const R=r(f),C=o(b),{signal:H,cleanup:K}=i(n,C.signal);C.signal=H;try{const I=await fetch(R,C);return K(),await l(I)}catch(I){throw K(),I.name==="AbortError"?new kt("Request timeout or cancelled",0,null):I}}async function d(f,b={}){return c(f,{...b,method:"GET"})}async function u(f,b,R={}){return c(f,{...R,method:"POST",body:b})}async function g(f,b,R={}){return c(f,{...R,method:"PUT",body:b})}async function h(f,b={}){return c(f,{...b,method:"DELETE"})}async function E(f,b={}){return await c(f,b)}return{request:c,get:d,post:u,put:g,delete:h,stream:E}}Dt();function zt(e){const{baseURL:t,apiKey:n,timeout:s=3e4,getHeaders:r,getUserKey:l}=e,o=Dt({baseURL:t,timeout:s,headers:{"Content-Type":"application/json",Accept:"text/event-stream","Cache-Control":"no-cache"}});function i(){return`user_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}async function c(){const g={};if(n&&(g["X-API-Key"]=n),r){const h=await r();Object.assign(g,h)}return g}async function d(){return l?await l():i()}async function u(g,h={}){try{const E=await c(),f=await d(),b={agent_id:g.agent_id,message:g.message,key:g.key||f,start_new:g.start_new!==void 0?g.start_new:!1};return await o.stream("/open/chat/stream",{method:"POST",headers:E,body:b,signal:h.signal})}catch(E){throw console.error("流式聊天请求失败:",E),E}}return{streamChat:u,getEffectiveHeaders:c,getEffectiveUserKey:d}}async function An(e,t,n,s){try{const r=e.body.getReader(),l=new TextDecoder;let o="";for(;;){const{done:i,value:c}=await r.read();if(i)break;o+=l.decode(c,{stream:!0});const d=o.split(` `);o=d.pop()||"";for(const u of d)if(u.trim()!==""&&u.startsWith("data: ")){const g=u.slice(6).trim();if(g==="[DONE]"){n==null||n();return}try{const h=JSON.parse(g);t==null||t(h)}catch(h){console.warn("解析流式数据失败:",{data:g,error:h.message})}}}n==null||n()}catch(r){console.error("解析流式响应失败:",r),s==null||s(r)}}function Pt(e){return{id:e.id||Date.now().toString(),content:e.content||e.response||"",role:e.role||"assistant",timestamp:e.timestamp||new Date().toISOString(),tool_calls:e.tool_calls||[],metadata:e.metadata||{}}}function Rn(e){if(typeof e=="string")return e;if(e.choices&&e.choices.length>0){const t=e.choices[0];if(t.delta&&t.delta.content)return t.delta.content}return e.content?e.content:""}function Cn(e){if(e.choices&&e.choices.length>0){const t=e.choices[0];if(t.delta&&t.delta.tool_calls)return t.delta.tool_calls}return e.tool_calls?e.tool_calls:[]}function Mn(e){if(e.choices&&e.choices.length>0){const t=e.choices[0];return t.finish_reason==="stop"||t.finish_reason==="tool_calls"}return!1}function Ht(e=null,t={}){const n=a.ref([]),s=a.ref(!1),r=a.ref(!1),l=a.ref(null),o=a.ref(null),i=a.ref(null);let c=null,d=null;const{config:u,getEffectiveHeaders:g,getEffectiveUserKey:h}=Lt(t),E=a.computed(()=>e||u.value.defaultAgentId),f=a.computed(()=>zt({...u.value,getHeaders:g,getUserKey:h}));function b($){const w=Pt($);return n.value.push(w),n.value[n.value.length-1]}function R($){if(n.value.length>0){const w=n.value[n.value.length-1];Object.assign(w,$)}}async function C($,w={}){var v,S,T,Z;if(!E.value)throw new Error("Agent ID 未配置");if(!u.value.baseURL)throw new Error("API baseURL 未配置");try{l.value=null,s.value=!0,d=$;const j=n.value.length===0;b({role:"user",content:$,timestamp:new Date().toISOString()});const V=b({role:"assistant",content:"",timestamp:new Date().toISOString(),tool_calls:[],streaming:!0});c=new AbortController;const G={agent_id:E.value,message:$,key:await h(),start_new:j};s.value=!1,r.value=!0;const p=(await f.value.streamChat(G,{signal:c.signal})).body.getReader(),k=new TextDecoder;let y="";try{for(;;){if(c!=null&&c.signal.aborted){console.log("流式请求被用户取消");break}const{done:N,value:D}=await p.read();if(N){console.log("流式响应读取完成");break}const F=k.decode(D,{stream:!0});y+=F;const Q=y.split(` `);y=Q.pop()||"";for(const ee of Q)if(ee.startsWith("data: ")){const U=ee.slice(6).trim();if(U==="[DONE]"){V.streaming=!1,r.value=!1,(v=w.onComplete)==null||v.call(w);return}if(!U)continue;try{const L=JSON.parse(U);if((S=w.onChunk)==null||S.call(w,L),L.chunk)await H(L.chunk,V);else if(L.type)await H(L,V);else if(L.error){console.error("收到服务端错误:",L.error),V.content+=` ❌ **错误**: ${L.error} `,V.streaming=!1,r.value=!1;break}else{const me=L.content||L.message||L.text||"";me&&(V.content+=me)}L.session_id&&(o.value=L.session_id),L.conversation_id&&(i.value=L.conversation_id)}catch(L){if(console.warn("流式数据解析失败,尝试纯文本处理",{data:U,error:L.message}),U.includes("error")||U.includes("Error")||U.includes("失败")){V.content+=` ❌ **错误**: ${U} `,V.streaming=!1,r.value=!1;break}else V.content+=U}}}}catch(N){throw console.error("流式读取过程中出现错误:",N),N.name!=="AbortError"&&(V.content+=` ❌ **连接错误**: ${N.message} `),N}finally{try{p.releaseLock()}catch{}V.streaming=!1,r.value=!1,(T=w.onComplete)==null||T.call(w)}}catch(j){if(r.value=!1,s.value=!1,j.name==="AbortError")return;throw l.value=j.message,(Z=w.onError)==null||Z.call(w,j),j}finally{c=null}}async function H($,w){try{const{type:v,content:S,meta:T}=$;switch(v){case"text":S&&(w.content+=S);break;case"tool_call":{const Z=(T==null?void 0:T.tool_name)||"未知工具",j=(T==null?void 0:T.tool_id)||Date.now().toString();if(w.tool_calls||(w.tool_calls=[]),!w.tool_calls.find(G=>G.id===j)){const G={id:j,name:Z,status:"running",result:null,error:null,arguments:(T==null?void 0:T.arguments)||null,timestamp:new Date().toISOString()};w.tool_calls.push(G),w.tool_calls=[...w.tool_calls],await a.nextTick()}break}case"tool_res":{const Z=(T==null?void 0:T.error)||!1,j=T==null?void 0:T.tool_id;if(w.tool_calls&&j){const V=w.tool_calls.find(G=>G.id===j);V&&(V.status=Z?"error":"completed",V.result=S,V.completedAt=new Date().toISOString(),Z&&(V.error=S),w.tool_calls=[...w.tool_calls],await a.nextTick())}break}case"final":w.streaming=!1,r.value=!1;break;default:S&&(w.content+=S);break}}catch(v){console.error("处理SC chunk失败:",v),$.content&&(w.content+=$.content)}}function K(){c&&(c.abort(),c=null),r.value=!1,s.value=!1}function I(){n.value=[],o.value=null,i.value=null,l.value=null}async function X(){if(!d)throw new Error("没有可重试的消息");n.value.length>0&&n.value[n.value.length-1].role==="assistant"&&n.value.pop(),await C(d)}return{messages:n,loading:s,streaming:r,error:l,sessionId:o,conversationId:i,sendMessage:C,clearMessages:I,stopStream:K,retry:X,addMessage:b,updateLastMessage:R}}function et(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var he=et();function Vt(e){he=e}var xe={exec:()=>null};function B(e,t=""){let n=typeof e=="string"?e:e.source,s={replace:(r,l)=>{let o=typeof l=="string"?l:l.source;return o=o.replace(J.caret,"$1"),n=n.replace(r,o),s},getRegex:()=>new RegExp(n,t)};return s}var J={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>new RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,"i")},Bn=/^(?:[ \t]*(?:\n|$))+/,$n=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,On=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Ne=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,In=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,tt=/(?:[*+-]|\d{1,9}[.)])/,Ut=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Kt=B(Ut).replace(/bull/g,tt).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),Ln=B(Ut).replace(/bull/g,tt).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),nt=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Dn=/^[^\n]+/,st=/(?!\s*\])(?:\\.|[^\[\]\\])+/,zn=B(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",st).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Pn=B(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,tt).getRegex(),Ue="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|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",rt=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Hn=B("^ {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",rt).replace("tag",Ue).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Ft=B(nt).replace("hr",Ne).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",Ue).getRegex(),Vn=B(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Ft).getRegex(),at={blockquote:Vn,code:$n,def:zn,fences:On,heading:In,hr:Ne,html:Hn,lheading:Kt,list:Pn,newline:Bn,paragraph:Ft,table:xe,text:Dn},xt=B("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Ne).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\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",Ue).getRegex(),Un={...at,lheading:Ln,table:xt,paragraph:B(nt).replace("hr",Ne).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",xt).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",Ue).getRegex()},Kn={...at,html:B(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",rt).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:xe,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:B(nt).replace("hr",Ne).replace("heading",` *#{1,6} *[^ ]`).replace("lheading",Kt).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Fn=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,jn=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,jt=/^( {2,}|\\)\n(?!\s*$)/,Gn=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,Ke=/[\p{P}\p{S}]/u,it=/[\s\p{P}\p{S}]/u,Gt=/[^\s\p{P}\p{S}]/u,qn=B(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,it).getRegex(),qt=/(?!~)[\p{P}\p{S}]/u,Zn=/(?!~)[\s\p{P}\p{S}]/u,Wn=/(?:[^\s\p{P}\p{S}]|~)/u,Xn=/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,Zt=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,Qn=B(Zt,"u").replace(/punct/g,Ke).getRegex(),Jn=B(Zt,"u").replace(/punct/g,qt).getRegex(),Wt="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Yn=B(Wt,"gu").replace(/notPunctSpace/g,Gt).replace(/punctSpace/g,it).replace(/punct/g,Ke).getRegex(),es=B(Wt,"gu").replace(/notPunctSpace/g,Wn).replace(/punctSpace/g,Zn).replace(/punct/g,qt).getRegex(),ts=B("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,Gt).replace(/punctSpace/g,it).replace(/punct/g,Ke).getRegex(),ns=B(/\\(punct)/,"gu").replace(/punct/g,Ke).getRegex(),ss=B(/^<(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(),rs=B(rt).replace("(?:-->|$)","-->").getRegex(),as=B("^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",rs).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),De=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,is=B(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",De).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Xt=B(/^!?\[(label)\]\[(ref)\]/).replace("label",De).replace("ref",st).getRegex(),Qt=B(/^!?\[(ref)\](?:\[\])?/).replace("ref",st).getRegex(),os=B("reflink|nolink(?!\\()","g").replace("reflink",Xt).replace("nolink",Qt).getRegex(),ot={_backpedal:xe,anyPunctuation:ns,autolink:ss,blockSkip:Xn,br:jt,code:jn,del:xe,emStrongLDelim:Qn,emStrongRDelimAst:Yn,emStrongRDelimUnd:ts,escape:Fn,link:is,nolink:Qt,punctuation:qn,reflink:Xt,reflinkSearch:os,tag:as,text:Gn,url:xe},ls={...ot,link:B(/^!?\[(label)\]\((.*?)\)/).replace("label",De).getRegex(),reflink:B(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",De).getRegex()},Qe={...ot,emStrongRDelimAst:es,emStrongLDelim:Jn,url:B(/^((?: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~\\]))\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},cs={...Qe,br:B(jt).replace("{2,}","*").getRegex(),text:B(Qe.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Me={normal:at,gfm:Un,pedantic:Kn},be={normal:ot,gfm:Qe,breaks:cs,pedantic:ls},us={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},yt=e=>us[e];function ne(e,t){if(t){if(J.escapeTest.test(e))return e.replace(J.escapeReplace,yt)}else if(J.escapeTestNoEncode.test(e))return e.replace(J.escapeReplaceNoEncode,yt);return e}function wt(e){try{e=encodeURI(e).replace(J.percentDecode,"%")}catch{return null}return e}function Et(e,t){var l;let n=e.replace(J.findPipe,(o,i,c)=>{let d=!1,u=i;for(;--u>=0&&c[u]==="\\";)d=!d;return d?"|":" |"}),s=n.split(J.splitPipe),r=0;if(s[0].trim()||s.shift(),s.length>0&&!((l=s.at(-1))!=null&&l.trim())&&s.pop(),t)if(s.length>t)s.splice(t);else for(;s.length<t;)s.push("");for(;r<s.length;r++)s[r]=s[r].trim().replace(J.slashPipe,"|");return s}function ke(e,t,n){let s=e.length;if(s===0)return"";let r=0;for(;r<s&&e.charAt(s-r-1)===t;)r++;return e.slice(0,s-r)}function ds(e,t){if(e.indexOf(t[1])===-1)return-1;let n=0;for(let s=0;s<e.length;s++)if(e[s]==="\\")s++;else if(e[s]===t[0])n++;else if(e[s]===t[1]&&(n--,n<0))return s;return n>0?-2:-1}function vt(e,t,n,s,r){let l=t.href,o=t.title||null,i=e[1].replace(r.other.outputLinkReplace,"$1");s.state.inLink=!0;let c={type:e[0].charAt(0)==="!"?"image":"link",raw:n,href:l,title:o,text:i,tokens:s.inlineTokens(i)};return s.state.inLink=!1,c}function hs(e,t,n){let s=e.match(n.other.indentCodeCompensation);if(s===null)return t;let r=s[1];return t.split(` `).map(l=>{let o=l.match(n.other.beginningSpace);if(o===null)return l;let[i]=o;return i.length>=r.length?l.slice(r.length):l}).join(` `)}var ze=class{constructor(e){z(this,"options");z(this,"rules");z(this,"lexer");this.options=e||he}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let n=t[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?n:ke(n,` `)}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let n=t[0],s=hs(n,t[3]||"",this.rules);return{type:"code",raw:n,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:s}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let n=t[2].trim();if(this.rules.other.endingHash.test(n)){let s=ke(n,"#");(this.options.pedantic||!s||this.rules.other.endingSpaceChar.test(s))&&(n=s.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:n,tokens:this.lexer.inline(n)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:ke(t[0],` `)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let n=ke(t[0],` `).split(` `),s="",r="",l=[];for(;n.length>0;){let o=!1,i=[],c;for(c=0;c<n.length;c++)if(this.rules.other.blockquoteStart.test(n[c]))i.push(n[c]),o=!0;else if(!o)i.push(n[c]);else break;n=n.slice(c);let d=i.join(` `),u=d.replace(this.rules.other.blockquoteSetextReplace,` $1`).replace(this.rules.other.blockquoteSetextReplace2,"");s=s?`${s} ${d}`:d,r=r?`${r} ${u}`:u;let g=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(u,l,!0),this.lexer.state.top=g,n.length===0)break;let h=l.at(-1);if((h==null?void 0:h.type)==="code")break;if((h==null?void 0:h.type)==="blockquote"){let E=h,f=E.raw+` `+n.join(` `),b=this.blockquote(f);l[l.length-1]=b,s=s.substring(0,s.length-E.raw.length)+b.raw,r=r.substring(0,r.length-E.text.length)+b.text;break}else if((h==null?void 0:h.type)==="list"){let E=h,f=E.raw+` `+n.join(` `),b=this.list(f);l[l.length-1]=b,s=s.substring(0,s.length-h.raw.length)+b.raw,r=r.substring(0,r.length-E.raw.length)+b.raw,n=f.substring(l.at(-1).raw.length).split(` `);continue}}return{type:"blockquote",raw:s,tokens:l,text:r}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim(),s=n.length>1,r={type:"list",raw:"",ordered:s,start:s?+n.slice(0,-1):"",loose:!1,items:[]};n=s?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=s?n:"[*+-]");let l=this.rules.other.listItemRegex(n),o=!1;for(;e;){let c=!1,d="",u="";if(!(t=l.exec(e))||this.rules.block.hr.test(e))break;d=t[0],e=e.substring(d.length);let g=t[2].split(` `,1)[0].replace(this.rules.other.listReplaceTabs,C=>" ".repeat(3*C.length)),h=e.split(` `,1)[0],E=!g.trim(),f=0;if(this.options.pedantic?(f=2,u=g.trimStart()):E?f=t[1].length+1:(f=t[2].search(this.rules.other.nonSpaceChar),f=f>4?1:f,u=g.slice(f),f+=t[1].length),E&&this.rules.other.blankLine.test(h)&&(d+=h+` `,e=e.substring(h.length+1),c=!0),!c){let C=this.rules.other.nextBulletRegex(f),H=this.rules.other.hrRegex(f),K=this.rules.other.fencesBeginRegex(f),I=this.rules.other.headingBeginRegex(f),X=this.rules.other.htmlBeginRegex(f);for(;e;){let $=e.split(` `,1)[0],w;if(h=$,this.options.pedantic?(h=h.replace(this.rules.other.listReplaceNesting," "),w=h):w=h.replace(this.rules.other.tabCharGlobal," "),K.test(h)||I.test(h)||X.test(h)||C.test(h)||H.test(h))break;if(w.search(this.rules.other.nonSpaceChar)>=f||!h.trim())u+=` `+w.slice(f);else{if(E||g.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||K.test(g)||I.test(g)||H.test(g))break;u+=` `+h}!E&&!h.trim()&&(E=!0),d+=$+` `,e=e.substring($.length+1),g=w.slice(f)}}r.loose||(o?r.loose=!0:this.rules.other.doubleBlankLine.test(d)&&(o=!0));let b=null,R;this.options.gfm&&(b=this.rules.other.listIsTask.exec(u),b&&(R=b[0]!=="[ ] ",u=u.replace(this.rules.other.listReplaceTask,""))),r.items.push({type:"list_item",raw:d,task:!!b,checked:R,loose:!1,text:u,tokens:[]}),r.raw+=d}let i=r.items.at(-1);if(i)i.raw=i.raw.trimEnd(),i.text=i.text.trimEnd();else return;r.raw=r.raw.trimEnd();for(let c=0;c<r.items.length;c++)if(this.lexer.state.top=!1,r.items[c].tokens=this.lexer.blockTokens(r.items[c].text,[]),!r.loose){let d=r.items[c].tokens.filter(g=>g.type==="space"),u=d.length>0&&d.some(g=>this.rules.other.anyLine.test(g.raw));r.loose=u}if(r.loose)for(let c=0;c<r.items.length;c++)r.items[c].loose=!0;return r}}html(e){let 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){let t=this.rules.block.def.exec(e);if(t){let n=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),s=t[2]?t[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",r=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:s,title:r}}}table(e){var o;let t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;let n=Et(t[1]),s=t[2].replace(this.rules.other.tableAlignChars,"").split("|"),r=(o=t[3])!=null&&o.trim()?t[3].replace(this.rules.other.tableRowBlankLine,"").split(` `):[],l={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===s.length){for(let i of s)this.rules.other.tableAlignRight.test(i)?l.align.push("right"):this.rules.other.tableAlignCenter.test(i)?l.align.push("center"):this.rules.other.tableAlignLeft.test(i)?l.align.push("left"):l.align.push(null);for(let i=0;i<n.length;i++)l.header.push({text:n[i],tokens:this.lexer.inline(n[i]),header:!0,align:l.align[i]});for(let i of r)l.rows.push(Et(i,l.header.length).map((c,d)=>({text:c,tokens:this.lexer.inline(c),header:!1,align:l.align[d]})));return l}}lheading(e){let 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){let t=this.rules.block.paragraph.exec(e);if(t){let 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){let 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){let t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.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){let t=this.rules.inline.link.exec(e);if(t){let n=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(n)){if(!this.rules.other.endAngleBracket.test(n))return;let l=ke(n.slice(0,-1),"\\");if((n.length-l.length)%2===0)return}else{let l=ds(t[2],"()");if(l===-2)return;if(l>-1){let o=(t[0].indexOf("!")===0?5:4)+t[1].length+l;t[2]=t[2].substring(0,l),t[0]=t[0].substring(0,o).trim(),t[3]=""}}let s=t[2],r="";if(this.options.pedantic){let l=this.rules.other.pedanticHrefTitle.exec(s);l&&(s=l[1],r=l[3])}else r=t[3]?t[3].slice(1,-1):"";return s=s.trim(),this.rules.other.startAngleBracket.test(s)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(n)?s=s.slice(1):s=s.slice(1,-1)),vt(t,{href:s&&s.replace(this.rules.inline.anyPunctuation,"$1"),title:r&&r.replace(this.rules.inline.anyPunctuation,"$1")},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let s=(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," "),r=t[s.toLowerCase()];if(!r){let l=n[0].charAt(0);return{type:"text",raw:l,text:l}}return vt(n,r,n[0],this.lexer,this.rules)}}emStrong(e,t,n=""){let s=this.rules.inline.emStrongLDelim.exec(e);if(!(!s||s[3]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(s[1]||s[2])||!n||this.rules.inline.punctuation.exec(n))){let r=[...s[0]].length-1,l,o,i=r,c=0,d=s[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(d.lastIndex=0,t=t.slice(-1*e.length+r);(s=d.exec(t))!=null;){if(l=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!l)continue;if(o=[...l].length,s[3]||s[4]){i+=o;continue}else if((s[5]||s[6])&&r%3&&!((r+o)%3)){c+=o;continue}if(i-=o,i>0)continue;o=Math.min(o,o+i+c);let u=[...s[0]][0].length,g=e.slice(0,r+s.index+u+o);if(Math.min(r,o)%2){let E=g.slice(1,-1);return{type:"em",raw:g,text:E,tokens:this.lexer.inlineTokens(E)}}let h=g.slice(2,-2);return{type:"strong",raw:g,text:h,tokens:this.lexer.inlineTokens(h)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let n=t[2].replace(this.rules.other.newLineCharGlobal," "),s=this.rules.other.nonSpaceChar.test(n),r=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return s&&r&&(n=n.substring(1,n.length-1)),{type:"codespan",raw:t[0],text:n}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e){let 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){let t=this.rules.inline.autolink.exec(e);if(t){let n,s;return t[2]==="@"?(n=t[1],s="mailto:"+n):(n=t[1],s=n),{type:"link",raw:t[0],text:n,href:s,tokens:[{type:"text",raw:n,text:n}]}}}url(e){var n;let t;if(t=this.rules.inline.url.exec(e)){let s,r;if(t[2]==="@")s=t[0],r="mailto:"+s;else{let l;do l=t[0],t[0]=((n=this.rules.inline._backpedal.exec(t[0]))==null?void 0:n[0])??"";while(l!==t[0]);s=t[0],t[1]==="www."?r="http://"+t[0]:r=t[0]}return{type:"link",raw:t[0],text:s,href:r,tokens:[{type:"text",raw:s,text:s}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let n=this.lexer.state.inRawBlock;return{type:"text",raw:t[0],text:t[0],escaped:n}}}},ae=class Je{constructor(t){z(this,"tokens");z(this,"options");z(this,"state");z(this,"tokenizer");z(this,"inlineQueue");this.tokens=[],this.tokens.links=Object.create(null),this.options=t||he,this.options.tokenizer=this.options.tokenizer||new ze,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let n={other:J,block:Me.normal,inline:be.normal};this.options.pedantic?(n.block=Me.pedantic,n.inline=be.pedantic):this.options.gfm&&(n.block=Me.gfm,this.options.breaks?n.inline=be.breaks:n.inline=be.gfm),this.tokenizer.rules=n}static get rules(){return{block:Me,inline:be}}static lex(t,n){return new Je(n).lex(t)}static lexInline(t,n){return new Je(n).inlineTokens(t)}lex(t){t=t.replace(J.carriageReturn,` `),this.blockTokens(t,this.tokens);for(let n=0;n<this.inlineQueue.length;n++){let s=this.inlineQueue[n];this.inlineTokens(s.src,s.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(t,n=[],s=!1){var r,l,o;for(this.options.pedantic&&(t=t.replace(J.tabCharGlobal," ").replace(J.spaceLine,""));t;){let i;if((l=(r=this.options.extensions)==null?void 0:r.block)!=null&&l.some(d=>(i=d.call({lexer:this},t,n))?(t=t.substring(i.raw.length),n.push(i),!0):!1))continue;if(i=this.tokenizer.space(t)){t=t.substring(i.raw.length);let d=n.at(-1);i.raw.length===1&&d!==void 0?d.raw+=` `:n.push(i);continue}if(i=this.tokenizer.code(t)){t=t.substring(i.raw.length);let d=n.at(-1);(d==null?void 0:d.type)==="paragraph"||(d==null?void 0:d.type)==="text"?(d.raw+=` `+i.raw,d.text+=` `+i.text,this.inlineQueue.at(-1).src=d.text):n.push(i);continue}if(i=this.tokenizer.fences(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.heading(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.hr(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.blockquote(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.list(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.html(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.def(t)){t=t.substring(i.raw.length);let d=n.at(-1);(d==null?void 0:d.type)==="paragraph"||(d==null?void 0:d.type)==="text"?(d.raw+=` `+i.raw,d.text+=` `+i.raw,this.inlineQueue.at(-1).src=d.text):this.tokens.links[i.tag]||(this.tokens.links[i.tag]={href:i.href,title:i.title});continue}if(i=this.tokenizer.table(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.lheading(t)){t=t.substring(i.raw.length),n.push(i);continue}let c=t;if((o=this.options.extensions)!=null&&o.startBlock){let d=1/0,u=t.slice(1),g;this.options.extensions.startBlock.forEach(h=>{g=h.call({lexer:this},u),typeof g=="number"&&g>=0&&(d=Math.min(d,g))}),d<1/0&&d>=0&&(c=t.substring(0,d+1))}if(this.state.top&&(i=this.tokenizer.paragraph(c))){let d=n.at(-1);s&&(d==null?void 0:d.type)==="paragraph"?(d.raw+=` `+i.raw,d.text+=` `+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=d.text):n.push(i),s=c.length!==t.length,t=t.substring(i.raw.length);continue}if(i=this.tokenizer.text(t)){t=t.substring(i.raw.length);let d=n.at(-1);(d==null?void 0:d.type)==="text"?(d.raw+=` `+i.raw,d.text+=` `+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=d.text):n.push(i);continue}if(t){let d="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(d);break}else throw new Error(d)}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){var i,c,d;let s=t,r=null;if(this.tokens.links){let u=Object.keys(this.tokens.links);if(u.length>0)for(;(r=this.tokenizer.rules.inline.reflinkSearch.exec(s))!=null;)u.includes(r[0].slice(r[0].lastIndexOf("[")+1,-1))&&(s=s.slice(0,r.index)+"["+"a".repeat(r[0].length-2)+"]"+s.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(r=this.tokenizer.rules.inline.anyPunctuation.exec(s))!=null;)s=s.slice(0,r.index)+"++"+s.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;(r=this.tokenizer.rules.inline.blockSkip.exec(s))!=null;)s=s.slice(0,r.index)+"["+"a".repeat(r[0].length-2)+"]"+s.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);let l=!1,o="";for(;t;){l||(o=""),l=!1;let u;if((c=(i=this.options.extensions)==null?void 0:i.inline)!=null&&c.some(h=>(u=h.call({lexer:this},t,n))?(t=t.substring(u.raw.length),n.push(u),!0):!1))continue;if(u=this.tokenizer.escape(t)){t=t.substring(u.raw.length),n.push(u);continue}if(u=this.tokenizer.tag(t)){t=t.substring(u.raw.length),n.push(u);continue}if(u=this.tokenizer.link(t)){t=t.substring(u.raw.length),n.push(u);continue}if(u=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(u.raw.length);let h=n.at(-1);u.type==="text"&&(h==null?void 0:h.type)==="text"?(h.raw+=u.raw,h.text+=u.text):n.push(u);continue}if(u=this.tokenizer.emStrong(t,s,o)){t=t.substring(u.raw.length),n.push(u);continue}if(u=this.tokenizer.codespan(t)){t=t.substring(u.raw.length),n.push(u);continue}if(u=this.tokenizer.br(t)){t=t.substring(u.raw.length),n.push(u);continue}if(u=this.tokenizer.del(t)){t=t.substring(u.raw.length),n.push(u);continue}if(u=this.tokenizer.autolink(t)){t=t.substring(u.raw.length),n.push(u);continue}if(!this.state.inLink&&(u=this.tokenizer.url(t))){t=t.substring(u.raw.length),n.push(u);continue}let g=t;if((d=this.options.extensions)!=null&&d.startInline){let h=1/0,E=t.slice(1),f;this.options.extensions.startInline.forEach(b=>{f=b.call({lexer:this},E),typeof f=="number"&&f>=0&&(h=Math.min(h,f))}),h<1/0&&h>=0&&(g=t.substring(0,h+1))}if(u=this.tokenizer.inlineText(g)){t=t.substring(u.raw.length),u.raw.slice(-1)!=="_"&&(o=u.raw.slice(-1)),l=!0;let h=n.at(-1);(h==null?void 0:h.type)==="text"?(h.raw+=u.raw,h.text+=u.text):n.push(u);continue}if(t){let h="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(h);break}else throw new Error(h)}}return n}},Pe=class{constructor(e){z(this,"options");z(this,"parser");this.options=e||he}space(e){return""}code({text:e,lang:t,escaped:n}){var l;let s=(l=(t||"").match(J.notSpaceStart))==null?void 0:l[0],r=e.replace(J.endingNewline,"")+` `;return s?'<pre><code class="language-'+ne(s)+'">'+(n?r:ne(r,!0))+`</code></pre> `:"<pre><code>"+(n?r:ne(r,!0))+`</code></pre> `}blockquote({tokens:e}){return`<blockquote> ${this.parser.parse(e)}</blockquote> `}html({text:e}){return e}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}> `}hr(e){return`<hr> `}list(e){let t=e.ordered,n=e.start,s="";for(let o=0;o<e.items.length;o++){let i=e.items[o];s+=this.listitem(i)}let r=t?"ol":"ul",l=t&&n!==1?' start="'+n+'"':"";return"<"+r+l+`> `+s+"</"+r+`> `}listitem(e){var n;let t="";if(e.task){let s=this.checkbox({checked:!!e.checked});e.loose?((n=e.tokens[0])==null?void 0:n.type)==="paragraph"?(e.tokens[0].text=s+" "+e.tokens[0].text,e.tokens[0].tokens&&e.tokens[0].tokens.length>0&&e.tokens[0].tokens[0].type==="text"&&(e.tokens[0].tokens[0].text=s+" "+ne(e.tokens[0].tokens[0].text),e.tokens[0].tokens[0].escaped=!0)):e.tokens.unshift({type:"text",raw:s+" ",text:s+" ",escaped:!0}):t+=s+" "}return t+=this.parser.parse(e.tokens,!!e.loose),`<li>${t}</li> `}checkbox({checked:e}){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox">'}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p> `}table(e){let t="",n="";for(let r=0;r<e.header.length;r++)n+=this.tablecell(e.header[r]);t+=this.tablerow({text:n});let s="";for(let r=0;r<e.rows.length;r++){let l=e.rows[r];n="";for(let o=0;o<l.length;o++)n+=this.tablecell(l[o]);s+=this.tablerow({text:n})}return s&&(s=`<tbody>${s}</tbody>`),`<table> <thead> `+t+`</thead> `+s+`</table> `}tablerow({text:e}){return`<tr> ${e}</tr> `}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}> `}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${ne(e,!0)}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let s=this.parser.parseInline(n),r=wt(e);if(r===null)return s;e=r;let l='<a href="'+e+'"';return t&&(l+=' title="'+ne(t)+'"'),l+=">"+s+"</a>",l}image({href:e,title:t,text:n,tokens:s}){s&&(n=this.parser.parseInline(s,this.parser.textRenderer));let r=wt(e);if(r===null)return ne(n);e=r;let l=`<img src="${e}" alt="${n}"`;return t&&(l+=` title="${ne(t)}"`),l+=">",l}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:ne(e.text)}},lt=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return""+e}image({text:e}){return""+e}br(){return""}},ie=class Ye{constructor(t){z(this,"options");z(this,"renderer");z(this,"textRenderer");this.options=t||he,this.options.renderer=this.options.renderer||new Pe,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new lt}static parse(t,n){return new Ye(n).parse(t)}static parseInline(t,n){return new Ye(n).parseInline(t)}parse(t,n=!0){var r,l;let s="";for(let o=0;o<t.length;o++){let i=t[o];if((l=(r=this.options.extensions)==null?void 0:r.renderers)!=null&&l[i.type]){let d=i,u=this.options.extensions.renderers[d.type].call({parser:this},d);if(u!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(d.type)){s+=u||"";continue}}let c=i;switch(c.type){case"space":{s+=this.renderer.space(c);continue}case"hr":{s+=this.renderer.hr(c);continue}case"heading":{s+=this.renderer.heading(c);continue}case"code":{s+=this.renderer.code(c);continue}case"table":{s+=this.renderer.table(c);continue}case"blockquote":{s+=this.renderer.blockquote(c);continue}case"list":{s+=this.renderer.list(c);continue}case"html":{s+=this.renderer.html(c);continue}case"paragraph":{s+=this.renderer.paragraph(c);continue}case"text":{let d=c,u=this.renderer.text(d);for(;o+1<t.length&&t[o+1].type==="text";)d=t[++o],u+=` `+this.renderer.text(d);n?s+=this.renderer.paragraph({type:"paragraph",raw:u,text:u,tokens:[{type:"text",raw:u,text:u,escaped:!0}]}):s+=u;continue}default:{let d='Token with "'+c.type+'" type was not found.';if(this.options.silent)return console.error(d),"";throw new Error(d)}}}return s}parseInline(t,n=this.renderer){var r,l;let s="";for(let o=0;o<t.length;o++){let i=t[o];if((l=(r=this.options.extensions)==null?void 0:r.renderers)!=null&&l[i.type]){let d=this.options.extensions.renderers[i.type].call({parser:this},i);if(d!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(i.type)){s+=d||"";continue}}let c=i;switch(c.type){case"escape":{s+=n.text(c);break}case"html":{s+=n.html(c);break}case"link":{s+=n.link(c);break}case"image":{s+=n.image(c);break}case"strong":{s+=n.strong(c);break}case"em":{s+=n.em(c);break}case"codespan":{s+=n.codespan(c);break}case"br":{s+=n.br(c);break}case"del":{s+=n.del(c);break}case"text":{s+=n.text(c);break}default:{let d='Token with "'+c.type+'" type was not found.';if(this.options.silent)return console.error(d),"";throw new Error(d)}}}return s}},We,Le=(We=class{constructor(e){z(this,"options");z(this,"block");this.options=e||he}preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}provideLexer(){return this.block?ae.lex:ae.lexInline}provideParser(){return this.block?ie.parse:ie.parseInline}},z(We,"passThroughHooks",new Set(["preprocess","postprocess","processAllTokens"])),We),gs=class{constructor(...e){z(this,"defaults",et());z(this,"options",this.setOptions);z(this,"parse",this.parseMarkdown(!0));z(this,"parseInline",this.parseMarkdown(!1));z(this,"Parser",ie);z(this,"Renderer",Pe);z(this,"TextRenderer",lt);z(this,"Lexer",ae);z(this,"Tokenizer",ze);z(this,"Hooks",Le);this.use(...e)}walkTokens(e,t){var s,r;let n=[];for(let l of e)switch(n=n.concat(t.call(this,l)),l.type){case"table":{let o=l;for(let i of o.header)n=n.concat(this.walkTokens(i.tokens,t));for(let i of o.rows)for(let c of i)n=n.concat(this.walkTokens(c.tokens,t));break}case"list":{let o=l;n=n.concat(this.walkTokens(o.items,t));break}default:{let o=l;(r=(s=this.defaults.extensions)==null?void 0:s.childTokens)!=null&&r[o.type]?this.defaults.extensions.childTokens[o.type].forEach(i=>{let c=o[i].flat(1/0);n=n.concat(this.walkTokens(c,t))}):o.tokens&&(n=n.concat(this.walkTokens(o.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(n=>{let s={...n};if(s.async=this.defaults.async||s.async||!1,n.extensions&&(n.extensions.forEach(r=>{if(!r.name)throw new Error("extension name required");if("renderer"in r){let l=t.renderers[r.name];l?t.renderers[r.name]=function(...o){let i=r.renderer.apply(this,o);return i===!1&&(i=l.apply(this,o)),i}:t.renderers[r.name]=r.renderer}if("tokenizer"in r){if(!r.level||r.level!=="block"&&r.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let l=t[r.level];l?l.unshift(r.tokenizer):t[r.level]=[r.tokenizer],r.start&&(r.level==="block"?t.startBlock?t.startBlock.push(r.start):t.startBlock=[r.start]:r.level==="inline"&&(t.startInline?t.startInline.push(r.start):t.startInline=[r.start]))}"childTokens"in r&&r.childTokens&&(t.childTokens[r.name]=r.childTokens)}),s.extensions=t),n.renderer){let r=this.defaults.renderer||new Pe(this.defaults);for(let l in n.renderer){if(!(l in r))throw new Error(`renderer '${l}' does not exist`);if(["options","parser"].includes(l))continue;let o=l,i=n.renderer[o],c=r[o];r[o]=(...d)=>{let u=i.apply(r,d);return u===!1&&(u=c.apply(r,d)),u||""}}s.renderer=r}if(n.tokenizer){let r=this.defaults.tokenizer||new ze(this.defaults);for(let l in n.tokenizer){if(!(l in r))throw new Error(`tokenizer '${l}' does not exist`);if(["options","rules","lexer"].includes(l))continue;let o=l,i=n.tokenizer[o],c=r[o];r[o]=(...d)=>{let u=i.apply(r,d);return u===!1&&(u=c.apply(r,d)),u}}s.tokenizer=r}if(n.hooks){let r=this.defaults.hooks||new Le;for(let l in n.hooks){if(!(l in r))throw new Error(`hook '${l}' does not exist`);if(["options","block"].includes(l))continue;let o=l,i=n.hooks[o],c=r[o];Le.passThroughHooks.has(l)?r[o]=d=>{if(this.defaults.async)return Promise.resolve(i.call(r,d)).then(g=>c.call(r,g));let u=i.call(r,d);return c.call(r,u)}:r[o]=(...d)=>{let u=i.apply(r,d);return u===!1&&(u=c.apply(r,d)),u}}s.hooks=r}if(n.walkTokens){let r=this.defaults.walkTokens,l=n.walkTokens;s.walkTokens=function(o){let i=[];return i.push(l.call(this,o)),r&&(i=i.concat(r.call(this,o))),i}}this.defaults={...this.defaults,...s}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return ae.lex(e,t??this.defaults)}parser(e,t){return ie.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let s={...n},r={...this.defaults,...s},l=this.onError(!!r.silent,!!r.async);if(this.defaults.async===!0&&s.async===!1)return l(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof t>"u"||t===null)return l(new Error("marked(): input parameter is undefined or null"));if(typeof t!="string")return l(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));r.hooks&&(r.hooks.options=r,r.hooks.block=e);let o=r.hooks?r.hooks.provideLexer():e?ae.lex:ae.lexInline,i=r.hooks?r.hooks.provideParser():e?ie.parse:ie.parseInline;if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(t):t).then(c=>o(c,r)).then(c=>r.hooks?r.hooks.processAllTokens(c):c).then(c=>r.walkTokens?Promise.all(this.walkTokens(c,r.walkTokens)).then(()=>c):c).then(c=>i(c,r)).then(c=>r.hooks?r.hooks.postprocess(c):c).catch(l);try{r.hooks&&(t=r.hooks.preprocess(t));let c=o(t,r);r.hooks&&(c=r.hooks.processAllTokens(c)),r.walkTokens&&this.walkTokens(c,r.walkTokens);let d=i(c,r);return r.hooks&&(d=r.hooks.postprocess(d)),d}catch(c){return l(c)}}}onError(e,t){return n=>{if(n.message+=` Please report this to https://github.com/markedjs/marked.`,e){let s="<p>An error occurred:</p><pre>"+ne(n.message+"",!0)+"</pre>";return t?Promise.resolve(s):s}if(t)return Promise.reject(n);throw n}}},de=new gs;function M(e,t){return de.parse(e,t)}M.options=M.setOptions=function(e){return de.setOptions(e),M.defaults=de.defaults,Vt(M.defaults),M};M.getDefaults=et;M.defaults=he;M.use=function(...e){return de.use(...e),M.defaults=de.defaults,Vt(M.defaults),M};M.walkTokens=function(e,t){return de.walkTokens(e,t)};M.parseInline=de.parseInline;M.Parser=ie;M.parser=ie.parse;M.Renderer=Pe;M.TextRenderer=lt;M.Lexer=ae;M.lexer=ae.lex;M.Tokenizer=ze;M.Hooks=Le;M.parse=M;M.options;M.setOptions;M.use;M.walkTokens;M.parseInline;ie.parse;ae.lex;function ps(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Jt(e){return e instanceof Map?e.clear=e.delete=e.set=function(){throw new Error("map is read-only")}:e instanceof Set&&(e.add=e.clear=e.delete=function(){throw new Error("set is read-only")}),Object.freeze(e),Object.getOwnPropertyNames(e).forEach(t=>{const n=e[t],s=typeof n;(s==="object"||s==="function")&&!Object.isFrozen(n)&&Jt(n)}),e}class _t{constructor(t){t.data===void 0&&(t.data={}),this.data=t.data,this.isMatchIgnored=!1}ignoreMatch(){this.isMatchIgnored=!0}}function Yt(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;")}function le(e,...t){const n=Object.create(null);for(const s in e)n[s]=e[s];return t.forEach(function(s){for(const r in s)n[r]=s[r]}),n}const fs="</span>",St=e=>!!e.scope,ms=(e,{prefix:t})=>{if(e.startsWith("language:"))return e.replace("language:","language-");if(e.includes(".")){const n=e.split(".");return[`${t}${n.shift()}`,...n.map((s,r)=>`${s}${"_".repeat(r+1)}`)].join(" ")}return`${t}${e}`};class bs{constructor