@think-apps/vue-chat-sdk
Version:
Vue.js SDK for Think Apps Chat Integration
1,086 lines (1,083 loc) • 165 kB
JavaScript
var On = Object.defineProperty;
var In = (e, t, n) => t in e ? On(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
var H = (e, t, n) => In(e, typeof t != "symbol" ? t + "" : t, n);
import { inject as Ln, computed as ae, ref as W, provide as Bn, nextTick as xe, watch as ht, onMounted as Qe, createElementBlock as $, openBlock as C, createElementVNode as p, createCommentVNode as q, createStaticVNode as Re, toDisplayString as re, Fragment as it, renderList as Gt, normalizeClass as _e, createBlock as Dn, createVNode as ot, withDirectives as zn, normalizeStyle as Pn, vModelText as Hn, onUnmounted as Un, unref as se } from "vue";
function Mt() {
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 Kn() {
typeof window > "u" || window.innerWidth > 640 || (document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", Mt) : Mt());
}
typeof window < "u" && Kn();
function ai() {
return null;
}
const qt = Symbol("chat-config"), Zt = {
baseURL: "",
apiKey: null,
defaultAgentId: null,
timeout: 3e4,
getHeaders: null,
getUserKey: null
};
function jn(e = {}) {
const t = W({
...Zt,
...e
});
function n(i) {
Object.assign(t.value, i);
}
async function s() {
const i = {};
if (t.value.apiKey && (i["X-API-Key"] = t.value.apiKey), t.value.getHeaders) {
const a = await t.value.getHeaders();
Object.assign(i, a);
}
return i;
}
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 o = {
config: t,
updateConfig: n,
getEffectiveHeaders: s,
getEffectiveUserKey: r
};
return Bn(qt, o), o;
}
function Fn(e = {}) {
const t = Ln(qt, null);
if (t) {
if (Object.keys(e).length > 0) {
const i = ae(() => ({
...t.config.value,
...e
}));
return {
config: i,
updateConfig: t.updateConfig,
getEffectiveHeaders: async () => {
const a = {};
if (i.value.apiKey && (a["X-API-Key"] = i.value.apiKey), i.value.getHeaders) {
const l = await i.value.getHeaders();
Object.assign(a, l);
}
return a;
},
getEffectiveUserKey: async () => i.value.userKey ? i.value.userKey : i.value.getUserKey ? await i.value.getUserKey() : `user_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
};
}
return t;
}
const n = W({
...Zt,
...e
});
function s(i) {
Object.assign(n.value, i);
}
async function r() {
const i = {};
if (n.value.apiKey && (i["X-API-Key"] = n.value.apiKey), n.value.getHeaders) {
const a = await n.value.getHeaders();
Object.assign(i, a);
}
return i;
}
async function o() {
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: o
};
}
class $t extends Error {
constructor(t, n, s) {
super(t), this.name = "HttpError", this.status = n, this.response = s;
}
}
function Wt(e = {}) {
const { baseURL: t = "", timeout: n = 3e4, headers: s = {} } = e;
function r(f) {
return f.startsWith("http") ? f : `${t.replace(/\/$/, "")}/${f.replace(/^\//, "")}`;
}
async function o(f) {
if (!f.ok)
throw new $t(
`HTTP ${f.status}: ${f.statusText}`,
f.status,
f
);
return f;
}
function i(f = {}) {
const { method: m = "GET", headers: M = {}, body: N, signal: K, ...G } = f, D = {
method: m.toUpperCase(),
headers: {
...s,
...M
},
signal: K,
...G
};
return N !== void 0 && (typeof N == "object" && !(N instanceof FormData) ? (D.body = JSON.stringify(N), D.headers["Content-Type"] = "application/json") : D.body = N), D;
}
function a(f, m) {
const M = new AbortController();
m && (m.aborted ? M.abort() : m.addEventListener("abort", () => {
M.abort();
}));
const N = setTimeout(() => {
M.abort();
}, f), K = () => {
clearTimeout(N);
};
return { signal: M.signal, cleanup: K };
}
async function l(f, m = {}) {
const M = r(f), N = i(m), { signal: K, cleanup: G } = a(
n,
N.signal
);
N.signal = K;
try {
const D = await fetch(M, N);
return G(), await o(D);
} catch (D) {
throw G(), D.name === "AbortError" ? new $t("Request timeout or cancelled", 0, null) : D;
}
}
async function u(f, m = {}) {
return l(f, { ...m, method: "GET" });
}
async function c(f, m, M = {}) {
return l(f, { ...M, method: "POST", body: m });
}
async function h(f, m, M = {}) {
return l(f, { ...M, method: "PUT", body: m });
}
async function d(f, m = {}) {
return l(f, { ...m, method: "DELETE" });
}
async function v(f, m = {}) {
return await l(f, m);
}
return {
request: l,
get: u,
post: c,
put: h,
delete: d,
stream: v
};
}
Wt();
function Gn(e) {
const { baseURL: t, apiKey: n, timeout: s = 3e4, getHeaders: r, getUserKey: o } = e, i = Wt({
baseURL: t,
timeout: s,
headers: {
"Content-Type": "application/json",
Accept: "text/event-stream",
"Cache-Control": "no-cache"
}
});
function a() {
return `user_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
}
async function l() {
const h = {};
if (n && (h["X-API-Key"] = n), r) {
const d = await r();
Object.assign(h, d);
}
return h;
}
async function u() {
return o ? await o() : a();
}
async function c(h, d = {}) {
try {
const v = await l(), f = await u(), m = {
agent_id: h.agent_id,
message: h.message,
key: h.key || f,
start_new: h.start_new !== void 0 ? h.start_new : !1
};
return await i.stream("/open/chat/stream", {
method: "POST",
headers: v,
body: m,
signal: d.signal
});
} catch (v) {
throw console.error("流式聊天请求失败:", v), v;
}
}
return {
streamChat: c,
getEffectiveHeaders: l,
getEffectiveUserKey: u
};
}
async function ii(e, t, n, s) {
try {
const r = e.body.getReader(), o = new TextDecoder();
let i = "";
for (; ; ) {
const { done: a, value: l } = await r.read();
if (a)
break;
i += o.decode(l, { stream: !0 });
const u = i.split(`
`);
i = u.pop() || "";
for (const c of u)
if (c.trim() !== "" && c.startsWith("data: ")) {
const h = c.slice(6).trim();
if (h === "[DONE]") {
n == null || n();
return;
}
try {
const d = JSON.parse(h);
t == null || t(d);
} catch (d) {
console.warn("解析流式数据失败:", { data: h, error: d.message });
}
}
}
n == null || n();
} catch (r) {
console.error("解析流式响应失败:", r), s == null || s(r);
}
}
function qn(e) {
return {
id: e.id || Date.now().toString(),
content: e.content || e.response || "",
role: e.role || "assistant",
timestamp: e.timestamp || (/* @__PURE__ */ new Date()).toISOString(),
tool_calls: e.tool_calls || [],
metadata: e.metadata || {}
};
}
function oi(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 li(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 ci(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 Zn(e = null, t = {}) {
const n = W([]), s = W(!1), r = W(!1), o = W(null), i = W(null), a = W(null);
let l = null, u = null;
const { config: c, getEffectiveHeaders: h, getEffectiveUserKey: d } = Fn(t), v = ae(() => e || c.value.defaultAgentId), f = ae(() => Gn({
...c.value,
getHeaders: h,
getUserKey: d
}));
function m(L) {
const y = qn(L);
return n.value.push(y), n.value[n.value.length - 1];
}
function M(L) {
if (n.value.length > 0) {
const y = n.value[n.value.length - 1];
Object.assign(y, L);
}
}
async function N(L, y = {}) {
var _, S, A, J;
if (!v.value)
throw new Error("Agent ID 未配置");
if (!c.value.baseURL)
throw new Error("API baseURL 未配置");
try {
o.value = null, s.value = !0, u = L;
const V = n.value.length === 0;
m({
role: "user",
content: L,
timestamp: (/* @__PURE__ */ new Date()).toISOString()
});
const j = m({
role: "assistant",
content: "",
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
tool_calls: [],
streaming: !0
});
l = new AbortController();
const X = {
agent_id: v.value,
message: L,
key: await d(),
start_new: V
};
s.value = !1, r.value = !0;
const g = (await f.value.streamChat(X, {
signal: l.signal
})).body.getReader(), x = new TextDecoder();
let w = "";
try {
for (; ; ) {
if (l != null && l.signal.aborted) {
console.log("流式请求被用户取消");
break;
}
const { done: T, value: P } = await g.read();
if (T) {
console.log("流式响应读取完成");
break;
}
const Z = x.decode(P, { stream: !0 });
w += Z;
const te = w.split(`
`);
w = te.pop() || "";
for (const ie of te)
if (ie.startsWith("data: ")) {
const F = ie.slice(6).trim();
if (F === "[DONE]") {
j.streaming = !1, r.value = !1, (_ = y.onComplete) == null || _.call(y);
return;
}
if (!F) continue;
try {
const z = JSON.parse(F);
if ((S = y.onChunk) == null || S.call(y, z), z.chunk)
await K(z.chunk, j);
else if (z.type)
await K(z, j);
else if (z.error) {
console.error("收到服务端错误:", z.error), j.content += `
❌ **错误**: ${z.error}
`, j.streaming = !1, r.value = !1;
break;
} else {
const Se = z.content || z.message || z.text || "";
Se && (j.content += Se);
}
z.session_id && (i.value = z.session_id), z.conversation_id && (a.value = z.conversation_id);
} catch (z) {
if (console.warn("流式数据解析失败,尝试纯文本处理", {
data: F,
error: z.message
}), F.includes("error") || F.includes("Error") || F.includes("失败")) {
j.content += `
❌ **错误**: ${F}
`, j.streaming = !1, r.value = !1;
break;
} else
j.content += F;
}
}
}
} catch (T) {
throw console.error("流式读取过程中出现错误:", T), T.name !== "AbortError" && (j.content += `
❌ **连接错误**: ${T.message}
`), T;
} finally {
try {
g.releaseLock();
} catch {
}
j.streaming = !1, r.value = !1, (A = y.onComplete) == null || A.call(y);
}
} catch (V) {
if (r.value = !1, s.value = !1, V.name === "AbortError")
return;
throw o.value = V.message, (J = y.onError) == null || J.call(y, V), V;
} finally {
l = null;
}
}
async function K(L, y) {
try {
const { type: _, content: S, meta: A } = L;
switch (_) {
case "text":
S && (y.content += S);
break;
case "tool_call": {
const J = (A == null ? void 0 : A.tool_name) || "未知工具", V = (A == null ? void 0 : A.tool_id) || Date.now().toString();
if (y.tool_calls || (y.tool_calls = []), !y.tool_calls.find((X) => X.id === V)) {
const X = {
id: V,
name: J,
status: "running",
result: null,
error: null,
arguments: (A == null ? void 0 : A.arguments) || null,
timestamp: (/* @__PURE__ */ new Date()).toISOString()
};
y.tool_calls.push(X), y.tool_calls = [...y.tool_calls], await xe();
}
break;
}
case "tool_res": {
const J = (A == null ? void 0 : A.error) || !1, V = A == null ? void 0 : A.tool_id;
if (y.tool_calls && V) {
const j = y.tool_calls.find((X) => X.id === V);
j && (j.status = J ? "error" : "completed", j.result = S, j.completedAt = (/* @__PURE__ */ new Date()).toISOString(), J && (j.error = S), y.tool_calls = [...y.tool_calls], await xe());
}
break;
}
case "final":
y.streaming = !1, r.value = !1;
break;
default:
S && (y.content += S);
break;
}
} catch (_) {
console.error("处理SC chunk失败:", _), L.content && (y.content += L.content);
}
}
function G() {
l && (l.abort(), l = null), r.value = !1, s.value = !1;
}
function D() {
n.value = [], i.value = null, a.value = null, o.value = null;
}
async function ee() {
if (!u)
throw new Error("没有可重试的消息");
n.value.length > 0 && n.value[n.value.length - 1].role === "assistant" && n.value.pop(), await N(u);
}
return {
// 状态
messages: n,
loading: s,
streaming: r,
error: o,
sessionId: i,
conversationId: a,
// 方法
sendMessage: N,
clearMessages: D,
stopStream: G,
retry: ee,
// 工具方法
addMessage: m,
updateLastMessage: M
};
}
function gt() {
return { async: !1, breaks: !1, extensions: null, gfm: !0, hooks: null, pedantic: !1, renderer: null, silent: !1, tokenizer: null, walkTokens: null };
}
var we = gt();
function Vt(e) {
we = e;
}
var Ce = { exec: () => null };
function I(e, t = "") {
let n = typeof e == "string" ? e : e.source, s = { replace: (r, o) => {
let i = typeof o == "string" ? o : o.source;
return i = i.replace(ne.caret, "$1"), n = n.replace(r, i), s;
}, getRegex: () => new RegExp(n, t) };
return s;
}
var ne = { 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") }, Wn = /^(?:[ \t]*(?:\n|$))+/, Vn = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/, Xn = /^ {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+|$)/, Qn = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/, pt = /(?:[*+-]|\d{1,9}[.)])/, Xt = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/, Qt = I(Xt).replace(/bull/g, pt).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(), Jn = I(Xt).replace(/bull/g, pt).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(), ft = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/, Yn = /^[^\n]+/, bt = /(?!\s*\])(?:\\.|[^\[\]\\])+/, es = I(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", bt).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(), ts = I(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g, pt).getRegex(), Je = "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", mt = /<!--(?:-?>|[\s\S]*?(?:-->|$))/, ns = I("^ {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", mt).replace("tag", Je).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(), Jt = I(ft).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", Je).getRegex(), ss = I(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", Jt).getRegex(), xt = { blockquote: ss, code: Vn, def: es, fences: Xn, heading: Qn, hr: Ne, html: ns, lheading: Qt, list: ts, newline: Wn, paragraph: Jt, table: Ce, text: Yn }, Nt = I("^ *([^\\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", Je).getRegex(), rs = { ...xt, lheading: Jn, table: Nt, paragraph: I(ft).replace("hr", Ne).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", Nt).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", Je).getRegex() }, as = { ...xt, html: I(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment", mt).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: Ce, lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/, paragraph: I(ft).replace("hr", Ne).replace("heading", ` *#{1,6} *[^
]`).replace("lheading", Qt).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex() }, is = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/, os = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/, Yt = /^( {2,}|\\)\n(?!\s*$)/, ls = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/, Ye = /[\p{P}\p{S}]/u, kt = /[\s\p{P}\p{S}]/u, en = /[^\s\p{P}\p{S}]/u, cs = I(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, kt).getRegex(), tn = /(?!~)[\p{P}\p{S}]/u, us = /(?!~)[\s\p{P}\p{S}]/u, ds = /(?:[^\s\p{P}\p{S}]|~)/u, hs = /\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g, nn = /^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/, gs = I(nn, "u").replace(/punct/g, Ye).getRegex(), ps = I(nn, "u").replace(/punct/g, tn).getRegex(), sn = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)", fs = I(sn, "gu").replace(/notPunctSpace/g, en).replace(/punctSpace/g, kt).replace(/punct/g, Ye).getRegex(), bs = I(sn, "gu").replace(/notPunctSpace/g, ds).replace(/punctSpace/g, us).replace(/punct/g, tn).getRegex(), ms = I("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)", "gu").replace(/notPunctSpace/g, en).replace(/punctSpace/g, kt).replace(/punct/g, Ye).getRegex(), xs = I(/\\(punct)/, "gu").replace(/punct/g, Ye).getRegex(), ks = I(/^<(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(), ws = I(mt).replace("(?:-->|$)", "-->").getRegex(), ys = I("^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", ws).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(), je = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/, vs = I(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label", je).replace("href", /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(), rn = I(/^!?\[(label)\]\[(ref)\]/).replace("label", je).replace("ref", bt).getRegex(), an = I(/^!?\[(ref)\](?:\[\])?/).replace("ref", bt).getRegex(), _s = I("reflink|nolink(?!\\()", "g").replace("reflink", rn).replace("nolink", an).getRegex(), wt = { _backpedal: Ce, anyPunctuation: xs, autolink: ks, blockSkip: hs, br: Yt, code: os, del: Ce, emStrongLDelim: gs, emStrongRDelimAst: fs, emStrongRDelimUnd: ms, escape: is, link: vs, nolink: an, punctuation: cs, reflink: rn, reflinkSearch: _s, tag: ys, text: ls, url: Ce }, Es = { ...wt, link: I(/^!?\[(label)\]\((.*?)\)/).replace("label", je).getRegex(), reflink: I(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", je).getRegex() }, lt = { ...wt, emStrongRDelimAst: bs, emStrongLDelim: ps, url: I(/^((?: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.!#$%&'*+\/=?_`{\|}~-]+@)))/ }, Ss = { ...lt, br: I(Yt).replace("{2,}", "*").getRegex(), text: I(lt.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex() }, De = { normal: xt, gfm: rs, pedantic: as }, Te = { normal: wt, gfm: lt, breaks: Ss, pedantic: Es }, Ts = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }, Ot = (e) => Ts[e];
function le(e, t) {
if (t) {
if (ne.escapeTest.test(e)) return e.replace(ne.escapeReplace, Ot);
} else if (ne.escapeTestNoEncode.test(e)) return e.replace(ne.escapeReplaceNoEncode, Ot);
return e;
}
function It(e) {
try {
e = encodeURI(e).replace(ne.percentDecode, "%");
} catch {
return null;
}
return e;
}
function Lt(e, t) {
var o;
let n = e.replace(ne.findPipe, (i, a, l) => {
let u = !1, c = a;
for (; --c >= 0 && l[c] === "\\"; ) u = !u;
return u ? "|" : " |";
}), s = n.split(ne.splitPipe), r = 0;
if (s[0].trim() || s.shift(), s.length > 0 && !((o = s.at(-1)) != null && o.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(ne.slashPipe, "|");
return s;
}
function Ae(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 As(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 Bt(e, t, n, s, r) {
let o = t.href, i = t.title || null, a = e[1].replace(r.other.outputLinkReplace, "$1");
s.state.inLink = !0;
let l = { type: e[0].charAt(0) === "!" ? "image" : "link", raw: n, href: o, title: i, text: a, tokens: s.inlineTokens(a) };
return s.state.inLink = !1, l;
}
function Rs(e, t, n) {
let s = e.match(n.other.indentCodeCompensation);
if (s === null) return t;
let r = s[1];
return t.split(`
`).map((o) => {
let i = o.match(n.other.beginningSpace);
if (i === null) return o;
let [a] = i;
return a.length >= r.length ? o.slice(r.length) : o;
}).join(`
`);
}
var Fe = class {
constructor(e) {
H(this, "options");
H(this, "rules");
H(this, "lexer");
this.options = e || we;
}
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 : Ae(n, `
`) };
}
}
fences(e) {
let t = this.rules.block.fences.exec(e);
if (t) {
let n = t[0], s = Rs(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 = Ae(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: Ae(t[0], `
`) };
}
blockquote(e) {
let t = this.rules.block.blockquote.exec(e);
if (t) {
let n = Ae(t[0], `
`).split(`
`), s = "", r = "", o = [];
for (; n.length > 0; ) {
let i = !1, a = [], l;
for (l = 0; l < n.length; l++) if (this.rules.other.blockquoteStart.test(n[l])) a.push(n[l]), i = !0;
else if (!i) a.push(n[l]);
else break;
n = n.slice(l);
let u = a.join(`
`), c = u.replace(this.rules.other.blockquoteSetextReplace, `
$1`).replace(this.rules.other.blockquoteSetextReplace2, "");
s = s ? `${s}
${u}` : u, r = r ? `${r}
${c}` : c;
let h = this.lexer.state.top;
if (this.lexer.state.top = !0, this.lexer.blockTokens(c, o, !0), this.lexer.state.top = h, n.length === 0) break;
let d = o.at(-1);
if ((d == null ? void 0 : d.type) === "code") break;
if ((d == null ? void 0 : d.type) === "blockquote") {
let v = d, f = v.raw + `
` + n.join(`
`), m = this.blockquote(f);
o[o.length - 1] = m, s = s.substring(0, s.length - v.raw.length) + m.raw, r = r.substring(0, r.length - v.text.length) + m.text;
break;
} else if ((d == null ? void 0 : d.type) === "list") {
let v = d, f = v.raw + `
` + n.join(`
`), m = this.list(f);
o[o.length - 1] = m, s = s.substring(0, s.length - d.raw.length) + m.raw, r = r.substring(0, r.length - v.raw.length) + m.raw, n = f.substring(o.at(-1).raw.length).split(`
`);
continue;
}
}
return { type: "blockquote", raw: s, tokens: o, 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 o = this.rules.other.listItemRegex(n), i = !1;
for (; e; ) {
let l = !1, u = "", c = "";
if (!(t = o.exec(e)) || this.rules.block.hr.test(e)) break;
u = t[0], e = e.substring(u.length);
let h = t[2].split(`
`, 1)[0].replace(this.rules.other.listReplaceTabs, (N) => " ".repeat(3 * N.length)), d = e.split(`
`, 1)[0], v = !h.trim(), f = 0;
if (this.options.pedantic ? (f = 2, c = h.trimStart()) : v ? f = t[1].length + 1 : (f = t[2].search(this.rules.other.nonSpaceChar), f = f > 4 ? 1 : f, c = h.slice(f), f += t[1].length), v && this.rules.other.blankLine.test(d) && (u += d + `
`, e = e.substring(d.length + 1), l = !0), !l) {
let N = this.rules.other.nextBulletRegex(f), K = this.rules.other.hrRegex(f), G = this.rules.other.fencesBeginRegex(f), D = this.rules.other.headingBeginRegex(f), ee = this.rules.other.htmlBeginRegex(f);
for (; e; ) {
let L = e.split(`
`, 1)[0], y;
if (d = L, this.options.pedantic ? (d = d.replace(this.rules.other.listReplaceNesting, " "), y = d) : y = d.replace(this.rules.other.tabCharGlobal, " "), G.test(d) || D.test(d) || ee.test(d) || N.test(d) || K.test(d)) break;
if (y.search(this.rules.other.nonSpaceChar) >= f || !d.trim()) c += `
` + y.slice(f);
else {
if (v || h.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4 || G.test(h) || D.test(h) || K.test(h)) break;
c += `
` + d;
}
!v && !d.trim() && (v = !0), u += L + `
`, e = e.substring(L.length + 1), h = y.slice(f);
}
}
r.loose || (i ? r.loose = !0 : this.rules.other.doubleBlankLine.test(u) && (i = !0));
let m = null, M;
this.options.gfm && (m = this.rules.other.listIsTask.exec(c), m && (M = m[0] !== "[ ] ", c = c.replace(this.rules.other.listReplaceTask, ""))), r.items.push({ type: "list_item", raw: u, task: !!m, checked: M, loose: !1, text: c, tokens: [] }), r.raw += u;
}
let a = r.items.at(-1);
if (a) a.raw = a.raw.trimEnd(), a.text = a.text.trimEnd();
else return;
r.raw = r.raw.trimEnd();
for (let l = 0; l < r.items.length; l++) if (this.lexer.state.top = !1, r.items[l].tokens = this.lexer.blockTokens(r.items[l].text, []), !r.loose) {
let u = r.items[l].tokens.filter((h) => h.type === "space"), c = u.length > 0 && u.some((h) => this.rules.other.anyLine.test(h.raw));
r.loose = c;
}
if (r.loose) for (let l = 0; l < r.items.length; l++) r.items[l].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 i;
let t = this.rules.block.table.exec(e);
if (!t || !this.rules.other.tableDelimiter.test(t[2])) return;
let n = Lt(t[1]), s = t[2].replace(this.rules.other.tableAlignChars, "").split("|"), r = (i = t[3]) != null && i.trim() ? t[3].replace(this.rules.other.tableRowBlankLine, "").split(`
`) : [], o = { type: "table", raw: t[0], header: [], align: [], rows: [] };
if (n.length === s.length) {
for (let a of s) this.rules.other.tableAlignRight.test(a) ? o.align.push("right") : this.rules.other.tableAlignCenter.test(a) ? o.align.push("center") : this.rules.other.tableAlignLeft.test(a) ? o.align.push("left") : o.align.push(null);
for (let a = 0; a < n.length; a++) o.header.push({ text: n[a], tokens: this.lexer.inline(n[a]), header: !0, align: o.align[a] });
for (let a of r) o.rows.push(Lt(a, o.header.length).map((l, u) => ({ text: l, tokens: this.lexer.inline(l), header: !1, align: o.align[u] })));
return o;
}
}
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 o = Ae(n.slice(0, -1), "\\");
if ((n.length - o.length) % 2 === 0) return;
} else {
let o = As(t[2], "()");
if (o === -2) return;
if (o > -1) {
let i = (t[0].indexOf("!") === 0 ? 5 : 4) + t[1].length + o;
t[2] = t[2].substring(0, o), t[0] = t[0].substring(0, i).trim(), t[3] = "";
}
}
let s = t[2], r = "";
if (this.options.pedantic) {
let o = this.rules.other.pedanticHrefTitle.exec(s);
o && (s = o[1], r = o[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)), Bt(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 o = n[0].charAt(0);
return { type: "text", raw: o, text: o };
}
return Bt(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, o, i, a = r, l = 0, u = s[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
for (u.lastIndex = 0, t = t.slice(-1 * e.length + r); (s = u.exec(t)) != null; ) {
if (o = s[1] || s[2] || s[3] || s[4] || s[5] || s[6], !o) continue;
if (i = [...o].length, s[3] || s[4]) {
a += i;
continue;
} else if ((s[5] || s[6]) && r % 3 && !((r + i) % 3)) {
l += i;
continue;
}
if (a -= i, a > 0) continue;
i = Math.min(i, i + a + l);
let c = [...s[0]][0].length, h = e.slice(0, r + s.index + c + i);
if (Math.min(r, i) % 2) {
let v = h.slice(1, -1);
return { type: "em", raw: h, text: v, tokens: this.lexer.inlineTokens(v) };
}
let d = h.slice(2, -2);
return { type: "strong", raw: h, text: d, tokens: this.lexer.inlineTokens(d) };
}
}
}
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 o;
do
o = t[0], t[0] = ((n = this.rules.inline._backpedal.exec(t[0])) == null ? void 0 : n[0]) ?? "";
while (o !== 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 };
}
}
}, de = class ct {
constructor(t) {
H(this, "tokens");
H(this, "options");
H(this, "state");
H(this, "tokenizer");
H(this, "inlineQueue");
this.tokens = [], this.tokens.links = /* @__PURE__ */ Object.create(null), this.options = t || we, this.options.tokenizer = this.options.tokenizer || new Fe(), 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: ne, block: De.normal, inline: Te.normal };
this.options.pedantic ? (n.block = De.pedantic, n.inline = Te.pedantic) : this.options.gfm && (n.block = De.gfm, this.options.breaks ? n.inline = Te.breaks : n.inline = Te.gfm), this.tokenizer.rules = n;
}
static get rules() {
return { block: De, inline: Te };
}
static lex(t, n) {
return new ct(n).lex(t);
}
static lexInline(t, n) {
return new ct(n).inlineTokens(t);
}
lex(t) {
t = t.replace(ne.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, o, i;
for (this.options.pedantic && (t = t.replace(ne.tabCharGlobal, " ").replace(ne.spaceLine, "")); t; ) {
let a;
if ((o = (r = this.options.extensions) == null ? void 0 : r.block) != null && o.some((u) => (a = u.call({ lexer: this }, t, n)) ? (t = t.substring(a.raw.length), n.push(a), !0) : !1)) continue;
if (a = this.tokenizer.space(t)) {
t = t.substring(a.raw.length);
let u = n.at(-1);
a.raw.length === 1 && u !== void 0 ? u.raw += `
` : n.push(a);
continue;
}
if (a = this.tokenizer.code(t)) {
t = t.substring(a.raw.length);
let u = n.at(-1);
(u == null ? void 0 : u.type) === "paragraph" || (u == null ? void 0 : u.type) === "text" ? (u.raw += `
` + a.raw, u.text += `
` + a.text, this.inlineQueue.at(-1).src = u.text) : n.push(a);
continue;
}
if (a = this.tokenizer.fences(t)) {
t = t.substring(a.raw.length), n.push(a);
continue;
}
if (a = this.tokenizer.heading(t)) {
t = t.substring(a.raw.length), n.push(a);
continue;
}
if (a = this.tokenizer.hr(t)) {
t = t.substring(a.raw.length), n.push(a);
continue;
}
if (a = this.tokenizer.blockquote(t)) {
t = t.substring(a.raw.length), n.push(a);
continue;
}
if (a = this.tokenizer.list(t)) {
t = t.substring(a.raw.length), n.push(a);
continue;
}
if (a = this.tokenizer.html(t)) {
t = t.substring(a.raw.length), n.push(a);
continue;
}
if (a = this.tokenizer.def(t)) {
t = t.substring(a.raw.length);
let u = n.at(-1);
(u == null ? void 0 : u.type) === "paragraph" || (u == null ? void 0 : u.type) === "text" ? (u.raw += `
` + a.raw, u.text += `
` + a.raw, this.inlineQueue.at(-1).src = u.text) : this.tokens.links[a.tag] || (this.tokens.links[a.tag] = { href: a.href, title: a.title });
continue;
}
if (a = this.tokenizer.table(t)) {
t = t.substring(a.raw.length), n.push(a);
continue;
}
if (a = this.tokenizer.lheading(t)) {
t = t.substring(a.raw.length), n.push(a);
continue;
}
let l = t;
if ((i = this.options.extensions) != null && i.startBlock) {
let u = 1 / 0, c = t.slice(1), h;
this.options.extensions.startBlock.forEach((d) => {
h = d.call({ lexer: this }, c), typeof h == "number" && h >= 0 && (u = Math.min(u, h));
}), u < 1 / 0 && u >= 0 && (l = t.substring(0, u + 1));
}
if (this.state.top && (a = this.tokenizer.paragraph(l))) {
let u = n.at(-1);
s && (u == null ? void 0 : u.type) === "paragraph" ? (u.raw += `
` + a.raw, u.text += `
` + a.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = u.text) : n.push(a), s = l.length !== t.length, t = t.substring(a.raw.length);
continue;
}
if (a = this.tokenizer.text(t)) {
t = t.substring(a.raw.length);
let u = n.at(-1);
(u == null ? void 0 : u.type) === "text" ? (u.raw += `
` + a.raw, u.text += `
` + a.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = u.text) : n.push(a);
continue;
}
if (t) {
let u = "Infinite loop on byte: " + t.charCodeAt(0);
if (this.options.silent) {
console.error(u);
break;
} else throw new Error(u);
}
}
return this.state.top = !0, n;
}
inline(t, n = []) {
return this.inlineQueue.push({ src: t, tokens: n }), n;
}
inlineTokens(t, n = []) {
var a, l, u;
let s = t, r = null;
if (this.tokens.links) {
let c = Object.keys(this.tokens.links);
if (c.length > 0) for (; (r = this.tokenizer.rules.inline.reflinkSearch.exec(s)) != null; ) c.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 o = !1, i = "";
for (; t; ) {
o || (i = ""), o = !1;
let c;
if ((l = (a = this.options.extensions) == null ? void 0 : a.inline) != null && l.some((d) => (c = d.call({ lexer: this }, t, n)) ? (t = t.substring(c.raw.length), n.push(c), !0) : !1)) continue;
if (c = this.tokenizer.escape(t)) {
t = t.substring(c.raw.length), n.push(c);
continue;
}
if (c = this.tokenizer.tag(t)) {
t = t.substring(c.raw.length), n.push(c);
continue;
}
if (c = this.tokenizer.link(t)) {
t = t.substring(c.raw.length), n.push(c);
continue;
}
if (c = this.tokenizer.reflink(t, this.tokens.links)) {
t = t.substring(c.raw.length);
let d = n.at(-1);
c.type === "text" && (d == null ? void 0 : d.type) === "text" ? (d.raw += c.raw, d.text += c.text) : n.push(c);
continue;
}
if (c = this.tokenizer.emStrong(t, s, i)) {
t = t.substring(c.raw.length), n.push(c);
continue;
}
if (c = this.tokenizer.codespan(t)) {
t = t.substring(c.raw.length), n.push(c);
continue;
}
if (c = this.tokenizer.br(t)) {
t = t.substring(c.raw.length), n.push(c);
continue;
}
if (c = this.tokenizer.del(t)) {
t = t.substring(c.raw.length), n.push(c);
continue;
}
if (c = this.tokenizer.autolink(t)) {
t = t.substring(c.raw.length), n.push(c);
continue;
}
if (!this.state.inLink && (c = this.tokenizer.url(t))) {
t = t.substring(c.raw.length), n.push(c);
continue;
}
let h = t;
if ((u = this.options.extensions) != null && u.startInline) {
let d = 1 / 0, v = t.slice(1), f;
this.options.extensions.startInline.forEach((m) => {
f = m.call({ lexer: this }, v), typeof f == "number" && f >= 0 && (d = Math.min(d, f));
}), d < 1 / 0 && d >= 0 && (h = t.substring(0, d + 1));
}
if (c = this.tokenizer.inlineText(h)) {
t = t.substring(c.raw.length), c.raw.slice(-1) !== "_" && (i = c.raw.slice(-1)), o = !0;
let d = n.at(-1);
(d == null ? void 0 : d.type) === "text" ? (d.raw += c.raw, d.text += c.text) : n.push(c);
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 n;
}
}, Ge = class {
constructor(e) {
H(this, "options");
H(this, "parser");
this.options = e || we;
}
space(e) {
return "";
}
code({ text: e, lang: t, escaped: n }) {
var o;
let s = (o = (t || "").match(ne.notSpaceStart)) == null ? void 0 : o[0], r = e.replace(ne.endingNewline, "") + `
`;
return s ? '<pre><code class="language-' + le(s) + '">' + (n ? r : le(r, !0)) + `</code></pre>
` : "<pre><code>" + (n ? r : le(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.parseInlin