@liip/liipgpt 0.0.3 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2308 @@
1
+ var Ot = Object.defineProperty;
2
+ var Bt = (h, e, t) => e in h ? Ot(h, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : h[e] = t;
3
+ var R = (h, e, t) => Bt(h, typeof e != "symbol" ? e + "" : e, t);
4
+ const pe = /* @__PURE__ */ new Map();
5
+ class qt {
6
+ get length() {
7
+ return pe.size;
8
+ }
9
+ clear() {
10
+ pe.clear();
11
+ }
12
+ getItem(e) {
13
+ return pe.get(e) || null;
14
+ }
15
+ key(e) {
16
+ return Array.from(pe.keys())[e] || null;
17
+ }
18
+ removeItem(e) {
19
+ pe.delete(e);
20
+ }
21
+ setItem(e, t) {
22
+ pe.set(e, String(t));
23
+ }
24
+ }
25
+ const ot = globalThis.localStorage ?? new qt();
26
+ function Ge() {
27
+ return {
28
+ async: !1,
29
+ breaks: !1,
30
+ extensions: null,
31
+ gfm: !0,
32
+ hooks: null,
33
+ pedantic: !1,
34
+ renderer: null,
35
+ silent: !1,
36
+ tokenizer: null,
37
+ walkTokens: null
38
+ };
39
+ }
40
+ let ie = Ge();
41
+ function bt(h) {
42
+ ie = h;
43
+ }
44
+ const Se = { exec: () => null };
45
+ function _(h, e = "") {
46
+ let t = typeof h == "string" ? h : h.source;
47
+ const n = {
48
+ replace: (s, r) => {
49
+ let i = typeof r == "string" ? r : r.source;
50
+ return i = i.replace(B.caret, "$1"), t = t.replace(s, i), n;
51
+ },
52
+ getRegex: () => new RegExp(t, e)
53
+ };
54
+ return n;
55
+ }
56
+ const B = {
57
+ codeRemoveIndent: /^(?: {1,4}| {0,3}\t)/gm,
58
+ outputLinkReplace: /\\([\[\]])/g,
59
+ indentCodeCompensation: /^(\s+)(?:```)/,
60
+ beginningSpace: /^\s+/,
61
+ endingHash: /#$/,
62
+ startingSpaceChar: /^ /,
63
+ endingSpaceChar: / $/,
64
+ nonSpaceChar: /[^ ]/,
65
+ newLineCharGlobal: /\n/g,
66
+ tabCharGlobal: /\t/g,
67
+ multipleSpaceGlobal: /\s+/g,
68
+ blankLine: /^[ \t]*$/,
69
+ doubleBlankLine: /\n[ \t]*\n[ \t]*$/,
70
+ blockquoteStart: /^ {0,3}>/,
71
+ blockquoteSetextReplace: /\n {0,3}((?:=+|-+) *)(?=\n|$)/g,
72
+ blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm,
73
+ listReplaceTabs: /^\t+/,
74
+ listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g,
75
+ listIsTask: /^\[[ xX]\] /,
76
+ listReplaceTask: /^\[[ xX]\] +/,
77
+ anyLine: /\n.*\n/,
78
+ hrefBrackets: /^<(.*)>$/,
79
+ tableDelimiter: /[:|]/,
80
+ tableAlignChars: /^\||\| *$/g,
81
+ tableRowBlankLine: /\n[ \t]*$/,
82
+ tableAlignRight: /^ *-+: *$/,
83
+ tableAlignCenter: /^ *:-+: *$/,
84
+ tableAlignLeft: /^ *:-+ *$/,
85
+ startATag: /^<a /i,
86
+ endATag: /^<\/a>/i,
87
+ startPreScriptTag: /^<(pre|code|kbd|script)(\s|>)/i,
88
+ endPreScriptTag: /^<\/(pre|code|kbd|script)(\s|>)/i,
89
+ startAngleBracket: /^</,
90
+ endAngleBracket: />$/,
91
+ pedanticHrefTitle: /^([^'"]*[^\s])\s+(['"])(.*)\2/,
92
+ unicodeAlphaNumeric: /[\p{L}\p{N}]/u,
93
+ escapeTest: /[&<>"']/,
94
+ escapeReplace: /[&<>"']/g,
95
+ escapeTestNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,
96
+ escapeReplaceNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,
97
+ unescapeTest: /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,
98
+ caret: /(^|[^\[])\^/g,
99
+ percentDecode: /%25/g,
100
+ findPipe: /\|/g,
101
+ splitPipe: / \|/,
102
+ slashPipe: /\\\|/g,
103
+ carriageReturn: /\r\n|\r/g,
104
+ spaceLine: /^ +$/gm,
105
+ notSpaceStart: /^\S*/,
106
+ endingNewline: /\n$/,
107
+ listItemRegex: (h) => new RegExp(`^( {0,3}${h})((?:[ ][^\\n]*)?(?:\\n|$))`),
108
+ nextBulletRegex: (h) => new RegExp(`^ {0,${Math.min(3, h - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),
109
+ hrRegex: (h) => new RegExp(`^ {0,${Math.min(3, h - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),
110
+ fencesBeginRegex: (h) => new RegExp(`^ {0,${Math.min(3, h - 1)}}(?:\`\`\`|~~~)`),
111
+ headingBeginRegex: (h) => new RegExp(`^ {0,${Math.min(3, h - 1)}}#`),
112
+ htmlBeginRegex: (h) => new RegExp(`^ {0,${Math.min(3, h - 1)}}<(?:[a-z].*>|!--)`, "i")
113
+ }, Ft = /^(?:[ \t]*(?:\n|$))+/, Ht = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/, Mt = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/, Te = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/, jt = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/, wt = /(?:[*+-]|\d{1,9}[.)])/, xt = _(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/).replace(/bull/g, wt).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/).getRegex(), Qe = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/, Ut = /^[^\n]+/, Xe = /(?!\s*\])(?:\\.|[^\[\]\\])+/, Zt = _(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", Xe).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(), Gt = _(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g, wt).getRegex(), ze = "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", We = /<!--(?:-?>|[\s\S]*?(?:-->|$))/, Qt = _("^ {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", We).replace("tag", ze).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(), yt = _(Qe).replace("hr", Te).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", ze).getRegex(), Xt = _(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", yt).getRegex(), Ke = {
114
+ blockquote: Xt,
115
+ code: Ht,
116
+ def: Zt,
117
+ fences: Mt,
118
+ heading: jt,
119
+ hr: Te,
120
+ html: Qt,
121
+ lheading: xt,
122
+ list: Gt,
123
+ newline: Ft,
124
+ paragraph: yt,
125
+ table: Se,
126
+ text: Ut
127
+ }, lt = _("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr", Te).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", ze).getRegex(), Wt = {
128
+ ...Ke,
129
+ table: lt,
130
+ paragraph: _(Qe).replace("hr", Te).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", lt).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", ze).getRegex()
131
+ }, Kt = {
132
+ ...Ke,
133
+ html: _(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment", We).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(),
134
+ def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
135
+ heading: /^(#{1,6})(.*)(?:\n+|$)/,
136
+ fences: Se,
137
+ // fences not supported
138
+ lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
139
+ paragraph: _(Qe).replace("hr", Te).replace("heading", ` *#{1,6} *[^
140
+ ]`).replace("lheading", xt).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex()
141
+ }, Vt = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/, Jt = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/, vt = /^( {2,}|\\)\n(?!\s*$)/, Yt = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/, De = /[\p{P}\p{S}]/u, Ve = /[\s\p{P}\p{S}]/u, St = /[^\s\p{P}\p{S}]/u, en = _(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, Ve).getRegex(), tn = /(?!~)[\p{P}\p{S}]/u, nn = /(?!~)[\s\p{P}\p{S}]/u, rn = /(?:[^\s\p{P}\p{S}]|~)/u, sn = /\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g, an = _(/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/, "u").replace(/punct/g, De).getRegex(), Rt = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)", on = _(Rt, "gu").replace(/notPunctSpace/g, St).replace(/punctSpace/g, Ve).replace(/punct/g, De).getRegex(), ln = _(Rt, "gu").replace(/notPunctSpace/g, rn).replace(/punctSpace/g, nn).replace(/punct/g, tn).getRegex(), cn = _("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)", "gu").replace(/notPunctSpace/g, St).replace(/punctSpace/g, Ve).replace(/punct/g, De).getRegex(), un = _(/\\(punct)/, "gu").replace(/punct/g, De).getRegex(), hn = _(/^<(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(), pn = _(We).replace("(?:-->|$)", "-->").getRegex(), fn = _("^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", pn).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(), Ce = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/, dn = _(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/).replace("label", Ce).replace("href", /<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(), Tt = _(/^!?\[(label)\]\[(ref)\]/).replace("label", Ce).replace("ref", Xe).getRegex(), Et = _(/^!?\[(ref)\](?:\[\])?/).replace("ref", Xe).getRegex(), gn = _("reflink|nolink(?!\\()", "g").replace("reflink", Tt).replace("nolink", Et).getRegex(), Je = {
142
+ _backpedal: Se,
143
+ // only used for GFM url
144
+ anyPunctuation: un,
145
+ autolink: hn,
146
+ blockSkip: sn,
147
+ br: vt,
148
+ code: Jt,
149
+ del: Se,
150
+ emStrongLDelim: an,
151
+ emStrongRDelimAst: on,
152
+ emStrongRDelimUnd: cn,
153
+ escape: Vt,
154
+ link: dn,
155
+ nolink: Et,
156
+ punctuation: en,
157
+ reflink: Tt,
158
+ reflinkSearch: gn,
159
+ tag: fn,
160
+ text: Yt,
161
+ url: Se
162
+ }, kn = {
163
+ ...Je,
164
+ link: _(/^!?\[(label)\]\((.*?)\)/).replace("label", Ce).getRegex(),
165
+ reflink: _(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", Ce).getRegex()
166
+ }, Ue = {
167
+ ...Je,
168
+ emStrongRDelimAst: ln,
169
+ url: _(/^((?: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(),
170
+ _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
171
+ del: /^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,
172
+ text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/
173
+ }, mn = {
174
+ ...Ue,
175
+ br: _(vt).replace("{2,}", "*").getRegex(),
176
+ text: _(Ue.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex()
177
+ }, Ae = {
178
+ normal: Ke,
179
+ gfm: Wt,
180
+ pedantic: Kt
181
+ }, ye = {
182
+ normal: Je,
183
+ gfm: Ue,
184
+ breaks: mn,
185
+ pedantic: kn
186
+ }, bn = {
187
+ "&": "&amp;",
188
+ "<": "&lt;",
189
+ ">": "&gt;",
190
+ '"': "&quot;",
191
+ "'": "&#39;"
192
+ }, ct = (h) => bn[h];
193
+ function W(h, e) {
194
+ if (e) {
195
+ if (B.escapeTest.test(h))
196
+ return h.replace(B.escapeReplace, ct);
197
+ } else if (B.escapeTestNoEncode.test(h))
198
+ return h.replace(B.escapeReplaceNoEncode, ct);
199
+ return h;
200
+ }
201
+ function ut(h) {
202
+ try {
203
+ h = encodeURI(h).replace(B.percentDecode, "%");
204
+ } catch {
205
+ return null;
206
+ }
207
+ return h;
208
+ }
209
+ function ht(h, e) {
210
+ var r;
211
+ const t = h.replace(B.findPipe, (i, a, u) => {
212
+ let o = !1, l = a;
213
+ for (; --l >= 0 && u[l] === "\\"; )
214
+ o = !o;
215
+ return o ? "|" : " |";
216
+ }), n = t.split(B.splitPipe);
217
+ let s = 0;
218
+ if (n[0].trim() || n.shift(), n.length > 0 && !((r = n.at(-1)) != null && r.trim()) && n.pop(), e)
219
+ if (n.length > e)
220
+ n.splice(e);
221
+ else
222
+ for (; n.length < e; )
223
+ n.push("");
224
+ for (; s < n.length; s++)
225
+ n[s] = n[s].trim().replace(B.slashPipe, "|");
226
+ return n;
227
+ }
228
+ function ve(h, e, t) {
229
+ const n = h.length;
230
+ if (n === 0)
231
+ return "";
232
+ let s = 0;
233
+ for (; s < n && (h.charAt(n - s - 1) === e && !t); )
234
+ s++;
235
+ return h.slice(0, n - s);
236
+ }
237
+ function wn(h, e) {
238
+ if (h.indexOf(e[1]) === -1)
239
+ return -1;
240
+ let t = 0;
241
+ for (let n = 0; n < h.length; n++)
242
+ if (h[n] === "\\")
243
+ n++;
244
+ else if (h[n] === e[0])
245
+ t++;
246
+ else if (h[n] === e[1] && (t--, t < 0))
247
+ return n;
248
+ return -1;
249
+ }
250
+ function pt(h, e, t, n, s) {
251
+ const r = e.href, i = e.title || null, a = h[1].replace(s.other.outputLinkReplace, "$1");
252
+ if (h[0].charAt(0) !== "!") {
253
+ n.state.inLink = !0;
254
+ const u = {
255
+ type: "link",
256
+ raw: t,
257
+ href: r,
258
+ title: i,
259
+ text: a,
260
+ tokens: n.inlineTokens(a)
261
+ };
262
+ return n.state.inLink = !1, u;
263
+ }
264
+ return {
265
+ type: "image",
266
+ raw: t,
267
+ href: r,
268
+ title: i,
269
+ text: a
270
+ };
271
+ }
272
+ function xn(h, e, t) {
273
+ const n = h.match(t.other.indentCodeCompensation);
274
+ if (n === null)
275
+ return e;
276
+ const s = n[1];
277
+ return e.split(`
278
+ `).map((r) => {
279
+ const i = r.match(t.other.beginningSpace);
280
+ if (i === null)
281
+ return r;
282
+ const [a] = i;
283
+ return a.length >= s.length ? r.slice(s.length) : r;
284
+ }).join(`
285
+ `);
286
+ }
287
+ class Ie {
288
+ // set by the lexer
289
+ constructor(e) {
290
+ R(this, "options");
291
+ R(this, "rules");
292
+ // set by the lexer
293
+ R(this, "lexer");
294
+ this.options = e || ie;
295
+ }
296
+ space(e) {
297
+ const t = this.rules.block.newline.exec(e);
298
+ if (t && t[0].length > 0)
299
+ return {
300
+ type: "space",
301
+ raw: t[0]
302
+ };
303
+ }
304
+ code(e) {
305
+ const t = this.rules.block.code.exec(e);
306
+ if (t) {
307
+ const n = t[0].replace(this.rules.other.codeRemoveIndent, "");
308
+ return {
309
+ type: "code",
310
+ raw: t[0],
311
+ codeBlockStyle: "indented",
312
+ text: this.options.pedantic ? n : ve(n, `
313
+ `)
314
+ };
315
+ }
316
+ }
317
+ fences(e) {
318
+ const t = this.rules.block.fences.exec(e);
319
+ if (t) {
320
+ const n = t[0], s = xn(n, t[3] || "", this.rules);
321
+ return {
322
+ type: "code",
323
+ raw: n,
324
+ lang: t[2] ? t[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : t[2],
325
+ text: s
326
+ };
327
+ }
328
+ }
329
+ heading(e) {
330
+ const t = this.rules.block.heading.exec(e);
331
+ if (t) {
332
+ let n = t[2].trim();
333
+ if (this.rules.other.endingHash.test(n)) {
334
+ const s = ve(n, "#");
335
+ (this.options.pedantic || !s || this.rules.other.endingSpaceChar.test(s)) && (n = s.trim());
336
+ }
337
+ return {
338
+ type: "heading",
339
+ raw: t[0],
340
+ depth: t[1].length,
341
+ text: n,
342
+ tokens: this.lexer.inline(n)
343
+ };
344
+ }
345
+ }
346
+ hr(e) {
347
+ const t = this.rules.block.hr.exec(e);
348
+ if (t)
349
+ return {
350
+ type: "hr",
351
+ raw: ve(t[0], `
352
+ `)
353
+ };
354
+ }
355
+ blockquote(e) {
356
+ const t = this.rules.block.blockquote.exec(e);
357
+ if (t) {
358
+ let n = ve(t[0], `
359
+ `).split(`
360
+ `), s = "", r = "";
361
+ const i = [];
362
+ for (; n.length > 0; ) {
363
+ let a = !1;
364
+ const u = [];
365
+ let o;
366
+ for (o = 0; o < n.length; o++)
367
+ if (this.rules.other.blockquoteStart.test(n[o]))
368
+ u.push(n[o]), a = !0;
369
+ else if (!a)
370
+ u.push(n[o]);
371
+ else
372
+ break;
373
+ n = n.slice(o);
374
+ const l = u.join(`
375
+ `), g = l.replace(this.rules.other.blockquoteSetextReplace, `
376
+ $1`).replace(this.rules.other.blockquoteSetextReplace2, "");
377
+ s = s ? `${s}
378
+ ${l}` : l, r = r ? `${r}
379
+ ${g}` : g;
380
+ const m = this.lexer.state.top;
381
+ if (this.lexer.state.top = !0, this.lexer.blockTokens(g, i, !0), this.lexer.state.top = m, n.length === 0)
382
+ break;
383
+ const x = i.at(-1);
384
+ if ((x == null ? void 0 : x.type) === "code")
385
+ break;
386
+ if ((x == null ? void 0 : x.type) === "blockquote") {
387
+ const A = x, S = A.raw + `
388
+ ` + n.join(`
389
+ `), q = this.blockquote(S);
390
+ i[i.length - 1] = q, s = s.substring(0, s.length - A.raw.length) + q.raw, r = r.substring(0, r.length - A.text.length) + q.text;
391
+ break;
392
+ } else if ((x == null ? void 0 : x.type) === "list") {
393
+ const A = x, S = A.raw + `
394
+ ` + n.join(`
395
+ `), q = this.list(S);
396
+ i[i.length - 1] = q, s = s.substring(0, s.length - x.raw.length) + q.raw, r = r.substring(0, r.length - A.raw.length) + q.raw, n = S.substring(i.at(-1).raw.length).split(`
397
+ `);
398
+ continue;
399
+ }
400
+ }
401
+ return {
402
+ type: "blockquote",
403
+ raw: s,
404
+ tokens: i,
405
+ text: r
406
+ };
407
+ }
408
+ }
409
+ list(e) {
410
+ let t = this.rules.block.list.exec(e);
411
+ if (t) {
412
+ let n = t[1].trim();
413
+ const s = n.length > 1, r = {
414
+ type: "list",
415
+ raw: "",
416
+ ordered: s,
417
+ start: s ? +n.slice(0, -1) : "",
418
+ loose: !1,
419
+ items: []
420
+ };
421
+ n = s ? `\\d{1,9}\\${n.slice(-1)}` : `\\${n}`, this.options.pedantic && (n = s ? n : "[*+-]");
422
+ const i = this.rules.other.listItemRegex(n);
423
+ let a = !1;
424
+ for (; e; ) {
425
+ let o = !1, l = "", g = "";
426
+ if (!(t = i.exec(e)) || this.rules.block.hr.test(e))
427
+ break;
428
+ l = t[0], e = e.substring(l.length);
429
+ let m = t[2].split(`
430
+ `, 1)[0].replace(this.rules.other.listReplaceTabs, (ge) => " ".repeat(3 * ge.length)), x = e.split(`
431
+ `, 1)[0], A = !m.trim(), S = 0;
432
+ if (this.options.pedantic ? (S = 2, g = m.trimStart()) : A ? S = t[1].length + 1 : (S = t[2].search(this.rules.other.nonSpaceChar), S = S > 4 ? 1 : S, g = m.slice(S), S += t[1].length), A && this.rules.other.blankLine.test(x) && (l += x + `
433
+ `, e = e.substring(x.length + 1), o = !0), !o) {
434
+ const ge = this.rules.other.nextBulletRegex(S), F = this.rules.other.hrRegex(S), X = this.rules.other.fencesBeginRegex(S), ke = this.rules.other.headingBeginRegex(S), Ee = this.rules.other.htmlBeginRegex(S);
435
+ for (; e; ) {
436
+ const ae = e.split(`
437
+ `, 1)[0];
438
+ let ee;
439
+ if (x = ae, this.options.pedantic ? (x = x.replace(this.rules.other.listReplaceNesting, " "), ee = x) : ee = x.replace(this.rules.other.tabCharGlobal, " "), X.test(x) || ke.test(x) || Ee.test(x) || ge.test(x) || F.test(x))
440
+ break;
441
+ if (ee.search(this.rules.other.nonSpaceChar) >= S || !x.trim())
442
+ g += `
443
+ ` + ee.slice(S);
444
+ else {
445
+ if (A || m.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4 || X.test(m) || ke.test(m) || F.test(m))
446
+ break;
447
+ g += `
448
+ ` + x;
449
+ }
450
+ !A && !x.trim() && (A = !0), l += ae + `
451
+ `, e = e.substring(ae.length + 1), m = ee.slice(S);
452
+ }
453
+ }
454
+ r.loose || (a ? r.loose = !0 : this.rules.other.doubleBlankLine.test(l) && (a = !0));
455
+ let q = null, de;
456
+ this.options.gfm && (q = this.rules.other.listIsTask.exec(g), q && (de = q[0] !== "[ ] ", g = g.replace(this.rules.other.listReplaceTask, ""))), r.items.push({
457
+ type: "list_item",
458
+ raw: l,
459
+ task: !!q,
460
+ checked: de,
461
+ loose: !1,
462
+ text: g,
463
+ tokens: []
464
+ }), r.raw += l;
465
+ }
466
+ const u = r.items.at(-1);
467
+ if (u)
468
+ u.raw = u.raw.trimEnd(), u.text = u.text.trimEnd();
469
+ else
470
+ return;
471
+ r.raw = r.raw.trimEnd();
472
+ for (let o = 0; o < r.items.length; o++)
473
+ if (this.lexer.state.top = !1, r.items[o].tokens = this.lexer.blockTokens(r.items[o].text, []), !r.loose) {
474
+ const l = r.items[o].tokens.filter((m) => m.type === "space"), g = l.length > 0 && l.some((m) => this.rules.other.anyLine.test(m.raw));
475
+ r.loose = g;
476
+ }
477
+ if (r.loose)
478
+ for (let o = 0; o < r.items.length; o++)
479
+ r.items[o].loose = !0;
480
+ return r;
481
+ }
482
+ }
483
+ html(e) {
484
+ const t = this.rules.block.html.exec(e);
485
+ if (t)
486
+ return {
487
+ type: "html",
488
+ block: !0,
489
+ raw: t[0],
490
+ pre: t[1] === "pre" || t[1] === "script" || t[1] === "style",
491
+ text: t[0]
492
+ };
493
+ }
494
+ def(e) {
495
+ const t = this.rules.block.def.exec(e);
496
+ if (t) {
497
+ const 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];
498
+ return {
499
+ type: "def",
500
+ tag: n,
501
+ raw: t[0],
502
+ href: s,
503
+ title: r
504
+ };
505
+ }
506
+ }
507
+ table(e) {
508
+ var a;
509
+ const t = this.rules.block.table.exec(e);
510
+ if (!t || !this.rules.other.tableDelimiter.test(t[2]))
511
+ return;
512
+ const n = ht(t[1]), s = t[2].replace(this.rules.other.tableAlignChars, "").split("|"), r = (a = t[3]) != null && a.trim() ? t[3].replace(this.rules.other.tableRowBlankLine, "").split(`
513
+ `) : [], i = {
514
+ type: "table",
515
+ raw: t[0],
516
+ header: [],
517
+ align: [],
518
+ rows: []
519
+ };
520
+ if (n.length === s.length) {
521
+ for (const u of s)
522
+ this.rules.other.tableAlignRight.test(u) ? i.align.push("right") : this.rules.other.tableAlignCenter.test(u) ? i.align.push("center") : this.rules.other.tableAlignLeft.test(u) ? i.align.push("left") : i.align.push(null);
523
+ for (let u = 0; u < n.length; u++)
524
+ i.header.push({
525
+ text: n[u],
526
+ tokens: this.lexer.inline(n[u]),
527
+ header: !0,
528
+ align: i.align[u]
529
+ });
530
+ for (const u of r)
531
+ i.rows.push(ht(u, i.header.length).map((o, l) => ({
532
+ text: o,
533
+ tokens: this.lexer.inline(o),
534
+ header: !1,
535
+ align: i.align[l]
536
+ })));
537
+ return i;
538
+ }
539
+ }
540
+ lheading(e) {
541
+ const t = this.rules.block.lheading.exec(e);
542
+ if (t)
543
+ return {
544
+ type: "heading",
545
+ raw: t[0],
546
+ depth: t[2].charAt(0) === "=" ? 1 : 2,
547
+ text: t[1],
548
+ tokens: this.lexer.inline(t[1])
549
+ };
550
+ }
551
+ paragraph(e) {
552
+ const t = this.rules.block.paragraph.exec(e);
553
+ if (t) {
554
+ const n = t[1].charAt(t[1].length - 1) === `
555
+ ` ? t[1].slice(0, -1) : t[1];
556
+ return {
557
+ type: "paragraph",
558
+ raw: t[0],
559
+ text: n,
560
+ tokens: this.lexer.inline(n)
561
+ };
562
+ }
563
+ }
564
+ text(e) {
565
+ const t = this.rules.block.text.exec(e);
566
+ if (t)
567
+ return {
568
+ type: "text",
569
+ raw: t[0],
570
+ text: t[0],
571
+ tokens: this.lexer.inline(t[0])
572
+ };
573
+ }
574
+ escape(e) {
575
+ const t = this.rules.inline.escape.exec(e);
576
+ if (t)
577
+ return {
578
+ type: "escape",
579
+ raw: t[0],
580
+ text: t[1]
581
+ };
582
+ }
583
+ tag(e) {
584
+ const t = this.rules.inline.tag.exec(e);
585
+ if (t)
586
+ 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), {
587
+ type: "html",
588
+ raw: t[0],
589
+ inLink: this.lexer.state.inLink,
590
+ inRawBlock: this.lexer.state.inRawBlock,
591
+ block: !1,
592
+ text: t[0]
593
+ };
594
+ }
595
+ link(e) {
596
+ const t = this.rules.inline.link.exec(e);
597
+ if (t) {
598
+ const n = t[2].trim();
599
+ if (!this.options.pedantic && this.rules.other.startAngleBracket.test(n)) {
600
+ if (!this.rules.other.endAngleBracket.test(n))
601
+ return;
602
+ const i = ve(n.slice(0, -1), "\\");
603
+ if ((n.length - i.length) % 2 === 0)
604
+ return;
605
+ } else {
606
+ const i = wn(t[2], "()");
607
+ if (i > -1) {
608
+ const u = (t[0].indexOf("!") === 0 ? 5 : 4) + t[1].length + i;
609
+ t[2] = t[2].substring(0, i), t[0] = t[0].substring(0, u).trim(), t[3] = "";
610
+ }
611
+ }
612
+ let s = t[2], r = "";
613
+ if (this.options.pedantic) {
614
+ const i = this.rules.other.pedanticHrefTitle.exec(s);
615
+ i && (s = i[1], r = i[3]);
616
+ } else
617
+ r = t[3] ? t[3].slice(1, -1) : "";
618
+ 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)), pt(t, {
619
+ href: s && s.replace(this.rules.inline.anyPunctuation, "$1"),
620
+ title: r && r.replace(this.rules.inline.anyPunctuation, "$1")
621
+ }, t[0], this.lexer, this.rules);
622
+ }
623
+ }
624
+ reflink(e, t) {
625
+ let n;
626
+ if ((n = this.rules.inline.reflink.exec(e)) || (n = this.rules.inline.nolink.exec(e))) {
627
+ const s = (n[2] || n[1]).replace(this.rules.other.multipleSpaceGlobal, " "), r = t[s.toLowerCase()];
628
+ if (!r) {
629
+ const i = n[0].charAt(0);
630
+ return {
631
+ type: "text",
632
+ raw: i,
633
+ text: i
634
+ };
635
+ }
636
+ return pt(n, r, n[0], this.lexer, this.rules);
637
+ }
638
+ }
639
+ emStrong(e, t, n = "") {
640
+ let s = this.rules.inline.emStrongLDelim.exec(e);
641
+ if (!s || s[3] && n.match(this.rules.other.unicodeAlphaNumeric))
642
+ return;
643
+ if (!(s[1] || s[2] || "") || !n || this.rules.inline.punctuation.exec(n)) {
644
+ const i = [...s[0]].length - 1;
645
+ let a, u, o = i, l = 0;
646
+ const g = s[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
647
+ for (g.lastIndex = 0, t = t.slice(-1 * e.length + i); (s = g.exec(t)) != null; ) {
648
+ if (a = s[1] || s[2] || s[3] || s[4] || s[5] || s[6], !a)
649
+ continue;
650
+ if (u = [...a].length, s[3] || s[4]) {
651
+ o += u;
652
+ continue;
653
+ } else if ((s[5] || s[6]) && i % 3 && !((i + u) % 3)) {
654
+ l += u;
655
+ continue;
656
+ }
657
+ if (o -= u, o > 0)
658
+ continue;
659
+ u = Math.min(u, u + o + l);
660
+ const m = [...s[0]][0].length, x = e.slice(0, i + s.index + m + u);
661
+ if (Math.min(i, u) % 2) {
662
+ const S = x.slice(1, -1);
663
+ return {
664
+ type: "em",
665
+ raw: x,
666
+ text: S,
667
+ tokens: this.lexer.inlineTokens(S)
668
+ };
669
+ }
670
+ const A = x.slice(2, -2);
671
+ return {
672
+ type: "strong",
673
+ raw: x,
674
+ text: A,
675
+ tokens: this.lexer.inlineTokens(A)
676
+ };
677
+ }
678
+ }
679
+ }
680
+ codespan(e) {
681
+ const t = this.rules.inline.code.exec(e);
682
+ if (t) {
683
+ let n = t[2].replace(this.rules.other.newLineCharGlobal, " ");
684
+ const s = this.rules.other.nonSpaceChar.test(n), r = this.rules.other.startingSpaceChar.test(n) && this.rules.other.endingSpaceChar.test(n);
685
+ return s && r && (n = n.substring(1, n.length - 1)), {
686
+ type: "codespan",
687
+ raw: t[0],
688
+ text: n
689
+ };
690
+ }
691
+ }
692
+ br(e) {
693
+ const t = this.rules.inline.br.exec(e);
694
+ if (t)
695
+ return {
696
+ type: "br",
697
+ raw: t[0]
698
+ };
699
+ }
700
+ del(e) {
701
+ const t = this.rules.inline.del.exec(e);
702
+ if (t)
703
+ return {
704
+ type: "del",
705
+ raw: t[0],
706
+ text: t[2],
707
+ tokens: this.lexer.inlineTokens(t[2])
708
+ };
709
+ }
710
+ autolink(e) {
711
+ const t = this.rules.inline.autolink.exec(e);
712
+ if (t) {
713
+ let n, s;
714
+ return t[2] === "@" ? (n = t[1], s = "mailto:" + n) : (n = t[1], s = n), {
715
+ type: "link",
716
+ raw: t[0],
717
+ text: n,
718
+ href: s,
719
+ tokens: [
720
+ {
721
+ type: "text",
722
+ raw: n,
723
+ text: n
724
+ }
725
+ ]
726
+ };
727
+ }
728
+ }
729
+ url(e) {
730
+ var n;
731
+ let t;
732
+ if (t = this.rules.inline.url.exec(e)) {
733
+ let s, r;
734
+ if (t[2] === "@")
735
+ s = t[0], r = "mailto:" + s;
736
+ else {
737
+ let i;
738
+ do
739
+ i = t[0], t[0] = ((n = this.rules.inline._backpedal.exec(t[0])) == null ? void 0 : n[0]) ?? "";
740
+ while (i !== t[0]);
741
+ s = t[0], t[1] === "www." ? r = "http://" + t[0] : r = t[0];
742
+ }
743
+ return {
744
+ type: "link",
745
+ raw: t[0],
746
+ text: s,
747
+ href: r,
748
+ tokens: [
749
+ {
750
+ type: "text",
751
+ raw: s,
752
+ text: s
753
+ }
754
+ ]
755
+ };
756
+ }
757
+ }
758
+ inlineText(e) {
759
+ const t = this.rules.inline.text.exec(e);
760
+ if (t) {
761
+ const n = this.lexer.state.inRawBlock;
762
+ return {
763
+ type: "text",
764
+ raw: t[0],
765
+ text: t[0],
766
+ escaped: n
767
+ };
768
+ }
769
+ }
770
+ }
771
+ class U {
772
+ constructor(e) {
773
+ R(this, "tokens");
774
+ R(this, "options");
775
+ R(this, "state");
776
+ R(this, "tokenizer");
777
+ R(this, "inlineQueue");
778
+ this.tokens = [], this.tokens.links = /* @__PURE__ */ Object.create(null), this.options = e || ie, this.options.tokenizer = this.options.tokenizer || new Ie(), this.tokenizer = this.options.tokenizer, this.tokenizer.options = this.options, this.tokenizer.lexer = this, this.inlineQueue = [], this.state = {
779
+ inLink: !1,
780
+ inRawBlock: !1,
781
+ top: !0
782
+ };
783
+ const t = {
784
+ other: B,
785
+ block: Ae.normal,
786
+ inline: ye.normal
787
+ };
788
+ this.options.pedantic ? (t.block = Ae.pedantic, t.inline = ye.pedantic) : this.options.gfm && (t.block = Ae.gfm, this.options.breaks ? t.inline = ye.breaks : t.inline = ye.gfm), this.tokenizer.rules = t;
789
+ }
790
+ /**
791
+ * Expose Rules
792
+ */
793
+ static get rules() {
794
+ return {
795
+ block: Ae,
796
+ inline: ye
797
+ };
798
+ }
799
+ /**
800
+ * Static Lex Method
801
+ */
802
+ static lex(e, t) {
803
+ return new U(t).lex(e);
804
+ }
805
+ /**
806
+ * Static Lex Inline Method
807
+ */
808
+ static lexInline(e, t) {
809
+ return new U(t).inlineTokens(e);
810
+ }
811
+ /**
812
+ * Preprocessing
813
+ */
814
+ lex(e) {
815
+ e = e.replace(B.carriageReturn, `
816
+ `), this.blockTokens(e, this.tokens);
817
+ for (let t = 0; t < this.inlineQueue.length; t++) {
818
+ const n = this.inlineQueue[t];
819
+ this.inlineTokens(n.src, n.tokens);
820
+ }
821
+ return this.inlineQueue = [], this.tokens;
822
+ }
823
+ blockTokens(e, t = [], n = !1) {
824
+ var s, r, i;
825
+ for (this.options.pedantic && (e = e.replace(B.tabCharGlobal, " ").replace(B.spaceLine, "")); e; ) {
826
+ let a;
827
+ if ((r = (s = this.options.extensions) == null ? void 0 : s.block) != null && r.some((o) => (a = o.call({ lexer: this }, e, t)) ? (e = e.substring(a.raw.length), t.push(a), !0) : !1))
828
+ continue;
829
+ if (a = this.tokenizer.space(e)) {
830
+ e = e.substring(a.raw.length);
831
+ const o = t.at(-1);
832
+ a.raw.length === 1 && o !== void 0 ? o.raw += `
833
+ ` : t.push(a);
834
+ continue;
835
+ }
836
+ if (a = this.tokenizer.code(e)) {
837
+ e = e.substring(a.raw.length);
838
+ const o = t.at(-1);
839
+ (o == null ? void 0 : o.type) === "paragraph" || (o == null ? void 0 : o.type) === "text" ? (o.raw += `
840
+ ` + a.raw, o.text += `
841
+ ` + a.text, this.inlineQueue.at(-1).src = o.text) : t.push(a);
842
+ continue;
843
+ }
844
+ if (a = this.tokenizer.fences(e)) {
845
+ e = e.substring(a.raw.length), t.push(a);
846
+ continue;
847
+ }
848
+ if (a = this.tokenizer.heading(e)) {
849
+ e = e.substring(a.raw.length), t.push(a);
850
+ continue;
851
+ }
852
+ if (a = this.tokenizer.hr(e)) {
853
+ e = e.substring(a.raw.length), t.push(a);
854
+ continue;
855
+ }
856
+ if (a = this.tokenizer.blockquote(e)) {
857
+ e = e.substring(a.raw.length), t.push(a);
858
+ continue;
859
+ }
860
+ if (a = this.tokenizer.list(e)) {
861
+ e = e.substring(a.raw.length), t.push(a);
862
+ continue;
863
+ }
864
+ if (a = this.tokenizer.html(e)) {
865
+ e = e.substring(a.raw.length), t.push(a);
866
+ continue;
867
+ }
868
+ if (a = this.tokenizer.def(e)) {
869
+ e = e.substring(a.raw.length);
870
+ const o = t.at(-1);
871
+ (o == null ? void 0 : o.type) === "paragraph" || (o == null ? void 0 : o.type) === "text" ? (o.raw += `
872
+ ` + a.raw, o.text += `
873
+ ` + a.raw, this.inlineQueue.at(-1).src = o.text) : this.tokens.links[a.tag] || (this.tokens.links[a.tag] = {
874
+ href: a.href,
875
+ title: a.title
876
+ });
877
+ continue;
878
+ }
879
+ if (a = this.tokenizer.table(e)) {
880
+ e = e.substring(a.raw.length), t.push(a);
881
+ continue;
882
+ }
883
+ if (a = this.tokenizer.lheading(e)) {
884
+ e = e.substring(a.raw.length), t.push(a);
885
+ continue;
886
+ }
887
+ let u = e;
888
+ if ((i = this.options.extensions) != null && i.startBlock) {
889
+ let o = 1 / 0;
890
+ const l = e.slice(1);
891
+ let g;
892
+ this.options.extensions.startBlock.forEach((m) => {
893
+ g = m.call({ lexer: this }, l), typeof g == "number" && g >= 0 && (o = Math.min(o, g));
894
+ }), o < 1 / 0 && o >= 0 && (u = e.substring(0, o + 1));
895
+ }
896
+ if (this.state.top && (a = this.tokenizer.paragraph(u))) {
897
+ const o = t.at(-1);
898
+ n && (o == null ? void 0 : o.type) === "paragraph" ? (o.raw += `
899
+ ` + a.raw, o.text += `
900
+ ` + a.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = o.text) : t.push(a), n = u.length !== e.length, e = e.substring(a.raw.length);
901
+ continue;
902
+ }
903
+ if (a = this.tokenizer.text(e)) {
904
+ e = e.substring(a.raw.length);
905
+ const o = t.at(-1);
906
+ (o == null ? void 0 : o.type) === "text" ? (o.raw += `
907
+ ` + a.raw, o.text += `
908
+ ` + a.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = o.text) : t.push(a);
909
+ continue;
910
+ }
911
+ if (e) {
912
+ const o = "Infinite loop on byte: " + e.charCodeAt(0);
913
+ if (this.options.silent) {
914
+ console.error(o);
915
+ break;
916
+ } else
917
+ throw new Error(o);
918
+ }
919
+ }
920
+ return this.state.top = !0, t;
921
+ }
922
+ inline(e, t = []) {
923
+ return this.inlineQueue.push({ src: e, tokens: t }), t;
924
+ }
925
+ /**
926
+ * Lexing/Compiling
927
+ */
928
+ inlineTokens(e, t = []) {
929
+ var a, u, o;
930
+ let n = e, s = null;
931
+ if (this.tokens.links) {
932
+ const l = Object.keys(this.tokens.links);
933
+ if (l.length > 0)
934
+ for (; (s = this.tokenizer.rules.inline.reflinkSearch.exec(n)) != null; )
935
+ l.includes(s[0].slice(s[0].lastIndexOf("[") + 1, -1)) && (n = n.slice(0, s.index) + "[" + "a".repeat(s[0].length - 2) + "]" + n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex));
936
+ }
937
+ for (; (s = this.tokenizer.rules.inline.blockSkip.exec(n)) != null; )
938
+ n = n.slice(0, s.index) + "[" + "a".repeat(s[0].length - 2) + "]" + n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
939
+ for (; (s = this.tokenizer.rules.inline.anyPunctuation.exec(n)) != null; )
940
+ n = n.slice(0, s.index) + "++" + n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
941
+ let r = !1, i = "";
942
+ for (; e; ) {
943
+ r || (i = ""), r = !1;
944
+ let l;
945
+ if ((u = (a = this.options.extensions) == null ? void 0 : a.inline) != null && u.some((m) => (l = m.call({ lexer: this }, e, t)) ? (e = e.substring(l.raw.length), t.push(l), !0) : !1))
946
+ continue;
947
+ if (l = this.tokenizer.escape(e)) {
948
+ e = e.substring(l.raw.length), t.push(l);
949
+ continue;
950
+ }
951
+ if (l = this.tokenizer.tag(e)) {
952
+ e = e.substring(l.raw.length), t.push(l);
953
+ continue;
954
+ }
955
+ if (l = this.tokenizer.link(e)) {
956
+ e = e.substring(l.raw.length), t.push(l);
957
+ continue;
958
+ }
959
+ if (l = this.tokenizer.reflink(e, this.tokens.links)) {
960
+ e = e.substring(l.raw.length);
961
+ const m = t.at(-1);
962
+ l.type === "text" && (m == null ? void 0 : m.type) === "text" ? (m.raw += l.raw, m.text += l.text) : t.push(l);
963
+ continue;
964
+ }
965
+ if (l = this.tokenizer.emStrong(e, n, i)) {
966
+ e = e.substring(l.raw.length), t.push(l);
967
+ continue;
968
+ }
969
+ if (l = this.tokenizer.codespan(e)) {
970
+ e = e.substring(l.raw.length), t.push(l);
971
+ continue;
972
+ }
973
+ if (l = this.tokenizer.br(e)) {
974
+ e = e.substring(l.raw.length), t.push(l);
975
+ continue;
976
+ }
977
+ if (l = this.tokenizer.del(e)) {
978
+ e = e.substring(l.raw.length), t.push(l);
979
+ continue;
980
+ }
981
+ if (l = this.tokenizer.autolink(e)) {
982
+ e = e.substring(l.raw.length), t.push(l);
983
+ continue;
984
+ }
985
+ if (!this.state.inLink && (l = this.tokenizer.url(e))) {
986
+ e = e.substring(l.raw.length), t.push(l);
987
+ continue;
988
+ }
989
+ let g = e;
990
+ if ((o = this.options.extensions) != null && o.startInline) {
991
+ let m = 1 / 0;
992
+ const x = e.slice(1);
993
+ let A;
994
+ this.options.extensions.startInline.forEach((S) => {
995
+ A = S.call({ lexer: this }, x), typeof A == "number" && A >= 0 && (m = Math.min(m, A));
996
+ }), m < 1 / 0 && m >= 0 && (g = e.substring(0, m + 1));
997
+ }
998
+ if (l = this.tokenizer.inlineText(g)) {
999
+ e = e.substring(l.raw.length), l.raw.slice(-1) !== "_" && (i = l.raw.slice(-1)), r = !0;
1000
+ const m = t.at(-1);
1001
+ (m == null ? void 0 : m.type) === "text" ? (m.raw += l.raw, m.text += l.text) : t.push(l);
1002
+ continue;
1003
+ }
1004
+ if (e) {
1005
+ const m = "Infinite loop on byte: " + e.charCodeAt(0);
1006
+ if (this.options.silent) {
1007
+ console.error(m);
1008
+ break;
1009
+ } else
1010
+ throw new Error(m);
1011
+ }
1012
+ }
1013
+ return t;
1014
+ }
1015
+ }
1016
+ class Le {
1017
+ // set by the parser
1018
+ constructor(e) {
1019
+ R(this, "options");
1020
+ R(this, "parser");
1021
+ this.options = e || ie;
1022
+ }
1023
+ space(e) {
1024
+ return "";
1025
+ }
1026
+ code({ text: e, lang: t, escaped: n }) {
1027
+ var i;
1028
+ const s = (i = (t || "").match(B.notSpaceStart)) == null ? void 0 : i[0], r = e.replace(B.endingNewline, "") + `
1029
+ `;
1030
+ return s ? '<pre><code class="language-' + W(s) + '">' + (n ? r : W(r, !0)) + `</code></pre>
1031
+ ` : "<pre><code>" + (n ? r : W(r, !0)) + `</code></pre>
1032
+ `;
1033
+ }
1034
+ blockquote({ tokens: e }) {
1035
+ return `<blockquote>
1036
+ ${this.parser.parse(e)}</blockquote>
1037
+ `;
1038
+ }
1039
+ html({ text: e }) {
1040
+ return e;
1041
+ }
1042
+ heading({ tokens: e, depth: t }) {
1043
+ return `<h${t}>${this.parser.parseInline(e)}</h${t}>
1044
+ `;
1045
+ }
1046
+ hr(e) {
1047
+ return `<hr>
1048
+ `;
1049
+ }
1050
+ list(e) {
1051
+ const t = e.ordered, n = e.start;
1052
+ let s = "";
1053
+ for (let a = 0; a < e.items.length; a++) {
1054
+ const u = e.items[a];
1055
+ s += this.listitem(u);
1056
+ }
1057
+ const r = t ? "ol" : "ul", i = t && n !== 1 ? ' start="' + n + '"' : "";
1058
+ return "<" + r + i + `>
1059
+ ` + s + "</" + r + `>
1060
+ `;
1061
+ }
1062
+ listitem(e) {
1063
+ var n;
1064
+ let t = "";
1065
+ if (e.task) {
1066
+ const s = this.checkbox({ checked: !!e.checked });
1067
+ 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 + " " + W(e.tokens[0].tokens[0].text), e.tokens[0].tokens[0].escaped = !0)) : e.tokens.unshift({
1068
+ type: "text",
1069
+ raw: s + " ",
1070
+ text: s + " ",
1071
+ escaped: !0
1072
+ }) : t += s + " ";
1073
+ }
1074
+ return t += this.parser.parse(e.tokens, !!e.loose), `<li>${t}</li>
1075
+ `;
1076
+ }
1077
+ checkbox({ checked: e }) {
1078
+ return "<input " + (e ? 'checked="" ' : "") + 'disabled="" type="checkbox">';
1079
+ }
1080
+ paragraph({ tokens: e }) {
1081
+ return `<p>${this.parser.parseInline(e)}</p>
1082
+ `;
1083
+ }
1084
+ table(e) {
1085
+ let t = "", n = "";
1086
+ for (let r = 0; r < e.header.length; r++)
1087
+ n += this.tablecell(e.header[r]);
1088
+ t += this.tablerow({ text: n });
1089
+ let s = "";
1090
+ for (let r = 0; r < e.rows.length; r++) {
1091
+ const i = e.rows[r];
1092
+ n = "";
1093
+ for (let a = 0; a < i.length; a++)
1094
+ n += this.tablecell(i[a]);
1095
+ s += this.tablerow({ text: n });
1096
+ }
1097
+ return s && (s = `<tbody>${s}</tbody>`), `<table>
1098
+ <thead>
1099
+ ` + t + `</thead>
1100
+ ` + s + `</table>
1101
+ `;
1102
+ }
1103
+ tablerow({ text: e }) {
1104
+ return `<tr>
1105
+ ${e}</tr>
1106
+ `;
1107
+ }
1108
+ tablecell(e) {
1109
+ const t = this.parser.parseInline(e.tokens), n = e.header ? "th" : "td";
1110
+ return (e.align ? `<${n} align="${e.align}">` : `<${n}>`) + t + `</${n}>
1111
+ `;
1112
+ }
1113
+ /**
1114
+ * span level renderer
1115
+ */
1116
+ strong({ tokens: e }) {
1117
+ return `<strong>${this.parser.parseInline(e)}</strong>`;
1118
+ }
1119
+ em({ tokens: e }) {
1120
+ return `<em>${this.parser.parseInline(e)}</em>`;
1121
+ }
1122
+ codespan({ text: e }) {
1123
+ return `<code>${W(e, !0)}</code>`;
1124
+ }
1125
+ br(e) {
1126
+ return "<br>";
1127
+ }
1128
+ del({ tokens: e }) {
1129
+ return `<del>${this.parser.parseInline(e)}</del>`;
1130
+ }
1131
+ link({ href: e, title: t, tokens: n }) {
1132
+ const s = this.parser.parseInline(n), r = ut(e);
1133
+ if (r === null)
1134
+ return s;
1135
+ e = r;
1136
+ let i = '<a href="' + e + '"';
1137
+ return t && (i += ' title="' + W(t) + '"'), i += ">" + s + "</a>", i;
1138
+ }
1139
+ image({ href: e, title: t, text: n }) {
1140
+ const s = ut(e);
1141
+ if (s === null)
1142
+ return W(n);
1143
+ e = s;
1144
+ let r = `<img src="${e}" alt="${n}"`;
1145
+ return t && (r += ` title="${W(t)}"`), r += ">", r;
1146
+ }
1147
+ text(e) {
1148
+ return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : "escaped" in e && e.escaped ? e.text : W(e.text);
1149
+ }
1150
+ }
1151
+ class Ye {
1152
+ // no need for block level renderers
1153
+ strong({ text: e }) {
1154
+ return e;
1155
+ }
1156
+ em({ text: e }) {
1157
+ return e;
1158
+ }
1159
+ codespan({ text: e }) {
1160
+ return e;
1161
+ }
1162
+ del({ text: e }) {
1163
+ return e;
1164
+ }
1165
+ html({ text: e }) {
1166
+ return e;
1167
+ }
1168
+ text({ text: e }) {
1169
+ return e;
1170
+ }
1171
+ link({ text: e }) {
1172
+ return "" + e;
1173
+ }
1174
+ image({ text: e }) {
1175
+ return "" + e;
1176
+ }
1177
+ br() {
1178
+ return "";
1179
+ }
1180
+ }
1181
+ class Z {
1182
+ constructor(e) {
1183
+ R(this, "options");
1184
+ R(this, "renderer");
1185
+ R(this, "textRenderer");
1186
+ this.options = e || ie, this.options.renderer = this.options.renderer || new Le(), this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new Ye();
1187
+ }
1188
+ /**
1189
+ * Static Parse Method
1190
+ */
1191
+ static parse(e, t) {
1192
+ return new Z(t).parse(e);
1193
+ }
1194
+ /**
1195
+ * Static Parse Inline Method
1196
+ */
1197
+ static parseInline(e, t) {
1198
+ return new Z(t).parseInline(e);
1199
+ }
1200
+ /**
1201
+ * Parse Loop
1202
+ */
1203
+ parse(e, t = !0) {
1204
+ var s, r;
1205
+ let n = "";
1206
+ for (let i = 0; i < e.length; i++) {
1207
+ const a = e[i];
1208
+ if ((r = (s = this.options.extensions) == null ? void 0 : s.renderers) != null && r[a.type]) {
1209
+ const o = a, l = this.options.extensions.renderers[o.type].call({ parser: this }, o);
1210
+ if (l !== !1 || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "paragraph", "text"].includes(o.type)) {
1211
+ n += l || "";
1212
+ continue;
1213
+ }
1214
+ }
1215
+ const u = a;
1216
+ switch (u.type) {
1217
+ case "space": {
1218
+ n += this.renderer.space(u);
1219
+ continue;
1220
+ }
1221
+ case "hr": {
1222
+ n += this.renderer.hr(u);
1223
+ continue;
1224
+ }
1225
+ case "heading": {
1226
+ n += this.renderer.heading(u);
1227
+ continue;
1228
+ }
1229
+ case "code": {
1230
+ n += this.renderer.code(u);
1231
+ continue;
1232
+ }
1233
+ case "table": {
1234
+ n += this.renderer.table(u);
1235
+ continue;
1236
+ }
1237
+ case "blockquote": {
1238
+ n += this.renderer.blockquote(u);
1239
+ continue;
1240
+ }
1241
+ case "list": {
1242
+ n += this.renderer.list(u);
1243
+ continue;
1244
+ }
1245
+ case "html": {
1246
+ n += this.renderer.html(u);
1247
+ continue;
1248
+ }
1249
+ case "paragraph": {
1250
+ n += this.renderer.paragraph(u);
1251
+ continue;
1252
+ }
1253
+ case "text": {
1254
+ let o = u, l = this.renderer.text(o);
1255
+ for (; i + 1 < e.length && e[i + 1].type === "text"; )
1256
+ o = e[++i], l += `
1257
+ ` + this.renderer.text(o);
1258
+ t ? n += this.renderer.paragraph({
1259
+ type: "paragraph",
1260
+ raw: l,
1261
+ text: l,
1262
+ tokens: [{ type: "text", raw: l, text: l, escaped: !0 }]
1263
+ }) : n += l;
1264
+ continue;
1265
+ }
1266
+ default: {
1267
+ const o = 'Token with "' + u.type + '" type was not found.';
1268
+ if (this.options.silent)
1269
+ return console.error(o), "";
1270
+ throw new Error(o);
1271
+ }
1272
+ }
1273
+ }
1274
+ return n;
1275
+ }
1276
+ /**
1277
+ * Parse Inline Tokens
1278
+ */
1279
+ parseInline(e, t = this.renderer) {
1280
+ var s, r;
1281
+ let n = "";
1282
+ for (let i = 0; i < e.length; i++) {
1283
+ const a = e[i];
1284
+ if ((r = (s = this.options.extensions) == null ? void 0 : s.renderers) != null && r[a.type]) {
1285
+ const o = this.options.extensions.renderers[a.type].call({ parser: this }, a);
1286
+ if (o !== !1 || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(a.type)) {
1287
+ n += o || "";
1288
+ continue;
1289
+ }
1290
+ }
1291
+ const u = a;
1292
+ switch (u.type) {
1293
+ case "escape": {
1294
+ n += t.text(u);
1295
+ break;
1296
+ }
1297
+ case "html": {
1298
+ n += t.html(u);
1299
+ break;
1300
+ }
1301
+ case "link": {
1302
+ n += t.link(u);
1303
+ break;
1304
+ }
1305
+ case "image": {
1306
+ n += t.image(u);
1307
+ break;
1308
+ }
1309
+ case "strong": {
1310
+ n += t.strong(u);
1311
+ break;
1312
+ }
1313
+ case "em": {
1314
+ n += t.em(u);
1315
+ break;
1316
+ }
1317
+ case "codespan": {
1318
+ n += t.codespan(u);
1319
+ break;
1320
+ }
1321
+ case "br": {
1322
+ n += t.br(u);
1323
+ break;
1324
+ }
1325
+ case "del": {
1326
+ n += t.del(u);
1327
+ break;
1328
+ }
1329
+ case "text": {
1330
+ n += t.text(u);
1331
+ break;
1332
+ }
1333
+ default: {
1334
+ const o = 'Token with "' + u.type + '" type was not found.';
1335
+ if (this.options.silent)
1336
+ return console.error(o), "";
1337
+ throw new Error(o);
1338
+ }
1339
+ }
1340
+ }
1341
+ return n;
1342
+ }
1343
+ }
1344
+ class Re {
1345
+ constructor(e) {
1346
+ R(this, "options");
1347
+ R(this, "block");
1348
+ this.options = e || ie;
1349
+ }
1350
+ /**
1351
+ * Process markdown before marked
1352
+ */
1353
+ preprocess(e) {
1354
+ return e;
1355
+ }
1356
+ /**
1357
+ * Process HTML after marked is finished
1358
+ */
1359
+ postprocess(e) {
1360
+ return e;
1361
+ }
1362
+ /**
1363
+ * Process all tokens before walk tokens
1364
+ */
1365
+ processAllTokens(e) {
1366
+ return e;
1367
+ }
1368
+ /**
1369
+ * Provide function to tokenize markdown
1370
+ */
1371
+ provideLexer() {
1372
+ return this.block ? U.lex : U.lexInline;
1373
+ }
1374
+ /**
1375
+ * Provide function to parse tokens
1376
+ */
1377
+ provideParser() {
1378
+ return this.block ? Z.parse : Z.parseInline;
1379
+ }
1380
+ }
1381
+ R(Re, "passThroughHooks", /* @__PURE__ */ new Set([
1382
+ "preprocess",
1383
+ "postprocess",
1384
+ "processAllTokens"
1385
+ ]));
1386
+ class _t {
1387
+ constructor(...e) {
1388
+ R(this, "defaults", Ge());
1389
+ R(this, "options", this.setOptions);
1390
+ R(this, "parse", this.parseMarkdown(!0));
1391
+ R(this, "parseInline", this.parseMarkdown(!1));
1392
+ R(this, "Parser", Z);
1393
+ R(this, "Renderer", Le);
1394
+ R(this, "TextRenderer", Ye);
1395
+ R(this, "Lexer", U);
1396
+ R(this, "Tokenizer", Ie);
1397
+ R(this, "Hooks", Re);
1398
+ this.use(...e);
1399
+ }
1400
+ /**
1401
+ * Run callback for every token
1402
+ */
1403
+ walkTokens(e, t) {
1404
+ var s, r;
1405
+ let n = [];
1406
+ for (const i of e)
1407
+ switch (n = n.concat(t.call(this, i)), i.type) {
1408
+ case "table": {
1409
+ const a = i;
1410
+ for (const u of a.header)
1411
+ n = n.concat(this.walkTokens(u.tokens, t));
1412
+ for (const u of a.rows)
1413
+ for (const o of u)
1414
+ n = n.concat(this.walkTokens(o.tokens, t));
1415
+ break;
1416
+ }
1417
+ case "list": {
1418
+ const a = i;
1419
+ n = n.concat(this.walkTokens(a.items, t));
1420
+ break;
1421
+ }
1422
+ default: {
1423
+ const a = i;
1424
+ (r = (s = this.defaults.extensions) == null ? void 0 : s.childTokens) != null && r[a.type] ? this.defaults.extensions.childTokens[a.type].forEach((u) => {
1425
+ const o = a[u].flat(1 / 0);
1426
+ n = n.concat(this.walkTokens(o, t));
1427
+ }) : a.tokens && (n = n.concat(this.walkTokens(a.tokens, t)));
1428
+ }
1429
+ }
1430
+ return n;
1431
+ }
1432
+ use(...e) {
1433
+ const t = this.defaults.extensions || { renderers: {}, childTokens: {} };
1434
+ return e.forEach((n) => {
1435
+ const s = { ...n };
1436
+ if (s.async = this.defaults.async || s.async || !1, n.extensions && (n.extensions.forEach((r) => {
1437
+ if (!r.name)
1438
+ throw new Error("extension name required");
1439
+ if ("renderer" in r) {
1440
+ const i = t.renderers[r.name];
1441
+ i ? t.renderers[r.name] = function(...a) {
1442
+ let u = r.renderer.apply(this, a);
1443
+ return u === !1 && (u = i.apply(this, a)), u;
1444
+ } : t.renderers[r.name] = r.renderer;
1445
+ }
1446
+ if ("tokenizer" in r) {
1447
+ if (!r.level || r.level !== "block" && r.level !== "inline")
1448
+ throw new Error("extension level must be 'block' or 'inline'");
1449
+ const i = t[r.level];
1450
+ i ? i.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]));
1451
+ }
1452
+ "childTokens" in r && r.childTokens && (t.childTokens[r.name] = r.childTokens);
1453
+ }), s.extensions = t), n.renderer) {
1454
+ const r = this.defaults.renderer || new Le(this.defaults);
1455
+ for (const i in n.renderer) {
1456
+ if (!(i in r))
1457
+ throw new Error(`renderer '${i}' does not exist`);
1458
+ if (["options", "parser"].includes(i))
1459
+ continue;
1460
+ const a = i, u = n.renderer[a], o = r[a];
1461
+ r[a] = (...l) => {
1462
+ let g = u.apply(r, l);
1463
+ return g === !1 && (g = o.apply(r, l)), g || "";
1464
+ };
1465
+ }
1466
+ s.renderer = r;
1467
+ }
1468
+ if (n.tokenizer) {
1469
+ const r = this.defaults.tokenizer || new Ie(this.defaults);
1470
+ for (const i in n.tokenizer) {
1471
+ if (!(i in r))
1472
+ throw new Error(`tokenizer '${i}' does not exist`);
1473
+ if (["options", "rules", "lexer"].includes(i))
1474
+ continue;
1475
+ const a = i, u = n.tokenizer[a], o = r[a];
1476
+ r[a] = (...l) => {
1477
+ let g = u.apply(r, l);
1478
+ return g === !1 && (g = o.apply(r, l)), g;
1479
+ };
1480
+ }
1481
+ s.tokenizer = r;
1482
+ }
1483
+ if (n.hooks) {
1484
+ const r = this.defaults.hooks || new Re();
1485
+ for (const i in n.hooks) {
1486
+ if (!(i in r))
1487
+ throw new Error(`hook '${i}' does not exist`);
1488
+ if (["options", "block"].includes(i))
1489
+ continue;
1490
+ const a = i, u = n.hooks[a], o = r[a];
1491
+ Re.passThroughHooks.has(i) ? r[a] = (l) => {
1492
+ if (this.defaults.async)
1493
+ return Promise.resolve(u.call(r, l)).then((m) => o.call(r, m));
1494
+ const g = u.call(r, l);
1495
+ return o.call(r, g);
1496
+ } : r[a] = (...l) => {
1497
+ let g = u.apply(r, l);
1498
+ return g === !1 && (g = o.apply(r, l)), g;
1499
+ };
1500
+ }
1501
+ s.hooks = r;
1502
+ }
1503
+ if (n.walkTokens) {
1504
+ const r = this.defaults.walkTokens, i = n.walkTokens;
1505
+ s.walkTokens = function(a) {
1506
+ let u = [];
1507
+ return u.push(i.call(this, a)), r && (u = u.concat(r.call(this, a))), u;
1508
+ };
1509
+ }
1510
+ this.defaults = { ...this.defaults, ...s };
1511
+ }), this;
1512
+ }
1513
+ setOptions(e) {
1514
+ return this.defaults = { ...this.defaults, ...e }, this;
1515
+ }
1516
+ lexer(e, t) {
1517
+ return U.lex(e, t ?? this.defaults);
1518
+ }
1519
+ parser(e, t) {
1520
+ return Z.parse(e, t ?? this.defaults);
1521
+ }
1522
+ parseMarkdown(e) {
1523
+ return (n, s) => {
1524
+ const r = { ...s }, i = { ...this.defaults, ...r }, a = this.onError(!!i.silent, !!i.async);
1525
+ if (this.defaults.async === !0 && r.async === !1)
1526
+ return a(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."));
1527
+ if (typeof n > "u" || n === null)
1528
+ return a(new Error("marked(): input parameter is undefined or null"));
1529
+ if (typeof n != "string")
1530
+ return a(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(n) + ", string expected"));
1531
+ i.hooks && (i.hooks.options = i, i.hooks.block = e);
1532
+ const u = i.hooks ? i.hooks.provideLexer() : e ? U.lex : U.lexInline, o = i.hooks ? i.hooks.provideParser() : e ? Z.parse : Z.parseInline;
1533
+ if (i.async)
1534
+ return Promise.resolve(i.hooks ? i.hooks.preprocess(n) : n).then((l) => u(l, i)).then((l) => i.hooks ? i.hooks.processAllTokens(l) : l).then((l) => i.walkTokens ? Promise.all(this.walkTokens(l, i.walkTokens)).then(() => l) : l).then((l) => o(l, i)).then((l) => i.hooks ? i.hooks.postprocess(l) : l).catch(a);
1535
+ try {
1536
+ i.hooks && (n = i.hooks.preprocess(n));
1537
+ let l = u(n, i);
1538
+ i.hooks && (l = i.hooks.processAllTokens(l)), i.walkTokens && this.walkTokens(l, i.walkTokens);
1539
+ let g = o(l, i);
1540
+ return i.hooks && (g = i.hooks.postprocess(g)), g;
1541
+ } catch (l) {
1542
+ return a(l);
1543
+ }
1544
+ };
1545
+ }
1546
+ onError(e, t) {
1547
+ return (n) => {
1548
+ if (n.message += `
1549
+ Please report this to https://github.com/markedjs/marked.`, e) {
1550
+ const s = "<p>An error occurred:</p><pre>" + W(n.message + "", !0) + "</pre>";
1551
+ return t ? Promise.resolve(s) : s;
1552
+ }
1553
+ if (t)
1554
+ return Promise.reject(n);
1555
+ throw n;
1556
+ };
1557
+ }
1558
+ }
1559
+ const se = new _t();
1560
+ function E(h, e) {
1561
+ return se.parse(h, e);
1562
+ }
1563
+ E.options = E.setOptions = function(h) {
1564
+ return se.setOptions(h), E.defaults = se.defaults, bt(E.defaults), E;
1565
+ };
1566
+ E.getDefaults = Ge;
1567
+ E.defaults = ie;
1568
+ E.use = function(...h) {
1569
+ return se.use(...h), E.defaults = se.defaults, bt(E.defaults), E;
1570
+ };
1571
+ E.walkTokens = function(h, e) {
1572
+ return se.walkTokens(h, e);
1573
+ };
1574
+ E.parseInline = se.parseInline;
1575
+ E.Parser = Z;
1576
+ E.parser = Z.parse;
1577
+ E.Renderer = Le;
1578
+ E.TextRenderer = Ye;
1579
+ E.Lexer = U;
1580
+ E.lexer = U.lex;
1581
+ E.Tokenizer = Ie;
1582
+ E.Hooks = Re;
1583
+ E.parse = E;
1584
+ E.options;
1585
+ E.setOptions;
1586
+ E.use;
1587
+ E.walkTokens;
1588
+ E.parseInline;
1589
+ Z.parse;
1590
+ U.lex;
1591
+ const yn = (h) => ({
1592
+ extensions: [
1593
+ {
1594
+ name: "footnote",
1595
+ level: "inline",
1596
+ start(e) {
1597
+ var t;
1598
+ return (t = e.match(/\[\^(\d+)\]/)) == null ? void 0 : t.index;
1599
+ },
1600
+ tokenizer(e) {
1601
+ const n = /^\[\^(\d+)\]/.exec(e);
1602
+ if (n) {
1603
+ const [s, r] = n;
1604
+ return {
1605
+ type: "footnote",
1606
+ raw: s,
1607
+ refNumber: r
1608
+ };
1609
+ }
1610
+ },
1611
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1612
+ renderer(e) {
1613
+ if (e.type === "footnote") {
1614
+ const t = parseInt(e.refNumber), n = h.sources.all.find((r) => r.referenceNumber == t);
1615
+ n || console.error("Could not find ref with number", t);
1616
+ let s;
1617
+ return n != null && n.usedNumber ? s = n.usedNumber : (s = h.sources.used.push(n), n.usedNumber = s), `<liipgpt-reference-number data-ref-number="${e.refNumber}" data-used-number="${s}" data-source="${JSON.stringify(
1618
+ n
1619
+ ).replace(/"/g, "&quot;")}"></liipgpt-reference-number>`;
1620
+ }
1621
+ }
1622
+ }
1623
+ ]
1624
+ }), ft = (h, e) => new _t().use(yn(e)).parse(h);
1625
+ var vn = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, Ze = { exports: {} };
1626
+ /** @license
1627
+ * eventsource.js
1628
+ * Available under MIT License (MIT)
1629
+ * https://github.com/Yaffle/EventSource/
1630
+ */
1631
+ (function(h, e) {
1632
+ (function(t) {
1633
+ var n = t.setTimeout, s = t.clearTimeout, r = t.XMLHttpRequest, i = t.XDomainRequest, a = t.ActiveXObject, u = t.EventSource, o = t.document, l = t.Promise, g = t.fetch, m = t.Response, x = t.TextDecoder, A = t.TextEncoder, S = t.AbortController;
1634
+ if (typeof window < "u" && typeof o < "u" && !("readyState" in o) && o.body == null && (o.readyState = "loading", window.addEventListener("load", function(c) {
1635
+ o.readyState = "complete";
1636
+ }, !1)), r == null && a != null && (r = function() {
1637
+ return new a("Microsoft.XMLHTTP");
1638
+ }), Object.create == null && (Object.create = function(c) {
1639
+ function f() {
1640
+ }
1641
+ return f.prototype = c, new f();
1642
+ }), Date.now || (Date.now = function() {
1643
+ return (/* @__PURE__ */ new Date()).getTime();
1644
+ }), S == null) {
1645
+ var q = g;
1646
+ g = function(c, f) {
1647
+ var d = f.signal;
1648
+ return q(c, { headers: f.headers, credentials: f.credentials, cache: f.cache }).then(function(p) {
1649
+ var b = p.body.getReader();
1650
+ return d._reader = b, d._aborted && d._reader.cancel(), {
1651
+ status: p.status,
1652
+ statusText: p.statusText,
1653
+ headers: p.headers,
1654
+ body: {
1655
+ getReader: function() {
1656
+ return b;
1657
+ }
1658
+ }
1659
+ };
1660
+ });
1661
+ }, S = function() {
1662
+ this.signal = {
1663
+ _reader: null,
1664
+ _aborted: !1
1665
+ }, this.abort = function() {
1666
+ this.signal._reader != null && this.signal._reader.cancel(), this.signal._aborted = !0;
1667
+ };
1668
+ };
1669
+ }
1670
+ function de() {
1671
+ this.bitsNeeded = 0, this.codePoint = 0;
1672
+ }
1673
+ de.prototype.decode = function(c) {
1674
+ function f(T, $, w) {
1675
+ if (w === 1)
1676
+ return T >= 128 >> $ && T << $ <= 2047;
1677
+ if (w === 2)
1678
+ return T >= 2048 >> $ && T << $ <= 55295 || T >= 57344 >> $ && T << $ <= 65535;
1679
+ if (w === 3)
1680
+ return T >= 65536 >> $ && T << $ <= 1114111;
1681
+ throw new Error();
1682
+ }
1683
+ function d(T, $) {
1684
+ if (T === 6 * 1)
1685
+ return $ >> 6 > 15 ? 3 : $ > 31 ? 2 : 1;
1686
+ if (T === 6 * 2)
1687
+ return $ > 15 ? 3 : 2;
1688
+ if (T === 6 * 3)
1689
+ return 3;
1690
+ throw new Error();
1691
+ }
1692
+ for (var p = 65533, b = "", k = this.bitsNeeded, y = this.codePoint, C = 0; C < c.length; C += 1) {
1693
+ var v = c[C];
1694
+ k !== 0 && (v < 128 || v > 191 || !f(y << 6 | v & 63, k - 6, d(k, y))) && (k = 0, y = p, b += String.fromCharCode(y)), k === 0 ? (v >= 0 && v <= 127 ? (k = 0, y = v) : v >= 192 && v <= 223 ? (k = 6 * 1, y = v & 31) : v >= 224 && v <= 239 ? (k = 6 * 2, y = v & 15) : v >= 240 && v <= 247 ? (k = 6 * 3, y = v & 7) : (k = 0, y = p), k !== 0 && !f(y, k, d(k, y)) && (k = 0, y = p)) : (k -= 6, y = y << 6 | v & 63), k === 0 && (y <= 65535 ? b += String.fromCharCode(y) : (b += String.fromCharCode(55296 + (y - 65535 - 1 >> 10)), b += String.fromCharCode(56320 + (y - 65535 - 1 & 1023))));
1695
+ }
1696
+ return this.bitsNeeded = k, this.codePoint = y, b;
1697
+ };
1698
+ var ge = function() {
1699
+ try {
1700
+ return new x().decode(new A().encode("test"), { stream: !0 }) === "test";
1701
+ } catch (c) {
1702
+ console.debug("TextDecoder does not support streaming option. Using polyfill instead: " + c);
1703
+ }
1704
+ return !1;
1705
+ };
1706
+ (x == null || A == null || !ge()) && (x = de);
1707
+ var F = function() {
1708
+ };
1709
+ function X(c) {
1710
+ this.withCredentials = !1, this.readyState = 0, this.status = 0, this.statusText = "", this.responseText = "", this.onprogress = F, this.onload = F, this.onerror = F, this.onreadystatechange = F, this._contentType = "", this._xhr = c, this._sendTimeout = 0, this._abort = F;
1711
+ }
1712
+ X.prototype.open = function(c, f) {
1713
+ this._abort(!0);
1714
+ var d = this, p = this._xhr, b = 1, k = 0;
1715
+ this._abort = function(w) {
1716
+ d._sendTimeout !== 0 && (s(d._sendTimeout), d._sendTimeout = 0), (b === 1 || b === 2 || b === 3) && (b = 4, p.onload = F, p.onerror = F, p.onabort = F, p.onprogress = F, p.onreadystatechange = F, p.abort(), k !== 0 && (s(k), k = 0), w || (d.readyState = 4, d.onabort(null), d.onreadystatechange())), b = 0;
1717
+ };
1718
+ var y = function() {
1719
+ if (b === 1) {
1720
+ var w = 0, I = "", K = void 0;
1721
+ if ("contentType" in p)
1722
+ w = 200, I = "OK", K = p.contentType;
1723
+ else
1724
+ try {
1725
+ w = p.status, I = p.statusText, K = p.getResponseHeader("Content-Type");
1726
+ } catch {
1727
+ w = 0, I = "", K = void 0;
1728
+ }
1729
+ w !== 0 && (b = 2, d.readyState = 2, d.status = w, d.statusText = I, d._contentType = K, d.onreadystatechange());
1730
+ }
1731
+ }, C = function() {
1732
+ if (y(), b === 2 || b === 3) {
1733
+ b = 3;
1734
+ var w = "";
1735
+ try {
1736
+ w = p.responseText;
1737
+ } catch {
1738
+ }
1739
+ d.readyState = 3, d.responseText = w, d.onprogress();
1740
+ }
1741
+ }, v = function(w, I) {
1742
+ if ((I == null || I.preventDefault == null) && (I = {
1743
+ preventDefault: F
1744
+ }), C(), b === 1 || b === 2 || b === 3) {
1745
+ if (b = 4, k !== 0 && (s(k), k = 0), d.readyState = 4, w === "load")
1746
+ d.onload(I);
1747
+ else if (w === "error")
1748
+ d.onerror(I);
1749
+ else if (w === "abort")
1750
+ d.onabort(I);
1751
+ else
1752
+ throw new TypeError();
1753
+ d.onreadystatechange();
1754
+ }
1755
+ }, T = function(w) {
1756
+ p != null && (p.readyState === 4 ? (!("onload" in p) || !("onerror" in p) || !("onabort" in p)) && v(p.responseText === "" ? "error" : "load", w) : p.readyState === 3 ? "onprogress" in p || C() : p.readyState === 2 && y());
1757
+ }, $ = function() {
1758
+ k = n(function() {
1759
+ $();
1760
+ }, 500), p.readyState === 3 && C();
1761
+ };
1762
+ "onload" in p && (p.onload = function(w) {
1763
+ v("load", w);
1764
+ }), "onerror" in p && (p.onerror = function(w) {
1765
+ v("error", w);
1766
+ }), "onabort" in p && (p.onabort = function(w) {
1767
+ v("abort", w);
1768
+ }), "onprogress" in p && (p.onprogress = C), "onreadystatechange" in p && (p.onreadystatechange = function(w) {
1769
+ T(w);
1770
+ }), ("contentType" in p || !("ontimeout" in r.prototype)) && (f += (f.indexOf("?") === -1 ? "?" : "&") + "padding=true"), p.open(c, f, !0), "readyState" in p && (k = n(function() {
1771
+ $();
1772
+ }, 0));
1773
+ }, X.prototype.abort = function() {
1774
+ this._abort(!1);
1775
+ }, X.prototype.getResponseHeader = function(c) {
1776
+ return this._contentType;
1777
+ }, X.prototype.setRequestHeader = function(c, f) {
1778
+ var d = this._xhr;
1779
+ "setRequestHeader" in d && d.setRequestHeader(c, f);
1780
+ }, X.prototype.getAllResponseHeaders = function() {
1781
+ return this._xhr.getAllResponseHeaders != null && this._xhr.getAllResponseHeaders() || "";
1782
+ }, X.prototype.send = function() {
1783
+ if ((!("ontimeout" in r.prototype) || !("sendAsBinary" in r.prototype) && !("mozAnon" in r.prototype)) && o != null && o.readyState != null && o.readyState !== "complete") {
1784
+ var c = this;
1785
+ c._sendTimeout = n(function() {
1786
+ c._sendTimeout = 0, c.send();
1787
+ }, 4);
1788
+ return;
1789
+ }
1790
+ var f = this._xhr;
1791
+ "withCredentials" in f && (f.withCredentials = this.withCredentials);
1792
+ try {
1793
+ f.send(void 0);
1794
+ } catch (d) {
1795
+ throw d;
1796
+ }
1797
+ };
1798
+ function ke(c) {
1799
+ return c.replace(/[A-Z]/g, function(f) {
1800
+ return String.fromCharCode(f.charCodeAt(0) + 32);
1801
+ });
1802
+ }
1803
+ function Ee(c) {
1804
+ for (var f = /* @__PURE__ */ Object.create(null), d = c.split(`\r
1805
+ `), p = 0; p < d.length; p += 1) {
1806
+ var b = d[p], k = b.split(": "), y = k.shift(), C = k.join(": ");
1807
+ f[ke(y)] = C;
1808
+ }
1809
+ this._map = f;
1810
+ }
1811
+ Ee.prototype.get = function(c) {
1812
+ return this._map[ke(c)];
1813
+ }, r != null && r.HEADERS_RECEIVED == null && (r.HEADERS_RECEIVED = 2);
1814
+ function ae() {
1815
+ }
1816
+ ae.prototype.open = function(c, f, d, p, b, k, y) {
1817
+ c.open("GET", b);
1818
+ var C = 0;
1819
+ c.onprogress = function() {
1820
+ var T = c.responseText, $ = T.slice(C);
1821
+ C += $.length, d($);
1822
+ }, c.onerror = function(T) {
1823
+ T.preventDefault(), p(new Error("NetworkError"));
1824
+ }, c.onload = function() {
1825
+ p(null);
1826
+ }, c.onabort = function() {
1827
+ p(null);
1828
+ }, c.onreadystatechange = function() {
1829
+ if (c.readyState === r.HEADERS_RECEIVED) {
1830
+ var T = c.status, $ = c.statusText, w = c.getResponseHeader("Content-Type"), I = c.getAllResponseHeaders();
1831
+ f(T, $, w, new Ee(I));
1832
+ }
1833
+ }, c.withCredentials = k;
1834
+ for (var v in y)
1835
+ Object.prototype.hasOwnProperty.call(y, v) && c.setRequestHeader(v, y[v]);
1836
+ return c.send(), c;
1837
+ };
1838
+ function ee(c) {
1839
+ this._headers = c;
1840
+ }
1841
+ ee.prototype.get = function(c) {
1842
+ return this._headers.get(c);
1843
+ };
1844
+ function et() {
1845
+ }
1846
+ et.prototype.open = function(c, f, d, p, b, k, y) {
1847
+ var C = null, v = new S(), T = v.signal, $ = new x();
1848
+ return g(b, {
1849
+ headers: y,
1850
+ credentials: k ? "include" : "same-origin",
1851
+ signal: T,
1852
+ cache: "no-store"
1853
+ }).then(function(w) {
1854
+ return C = w.body.getReader(), f(w.status, w.statusText, w.headers.get("Content-Type"), new ee(w.headers)), new l(function(I, K) {
1855
+ var we = function() {
1856
+ C.read().then(function(H) {
1857
+ if (H.done)
1858
+ I(void 0);
1859
+ else {
1860
+ var P = $.decode(H.value, { stream: !0 });
1861
+ d(P), we();
1862
+ }
1863
+ }).catch(function(H) {
1864
+ K(H);
1865
+ });
1866
+ };
1867
+ we();
1868
+ });
1869
+ }).catch(function(w) {
1870
+ if (w.name !== "AbortError")
1871
+ return w;
1872
+ }).then(function(w) {
1873
+ p(w);
1874
+ }), {
1875
+ abort: function() {
1876
+ C != null && C.cancel(), v.abort();
1877
+ }
1878
+ };
1879
+ };
1880
+ function me() {
1881
+ this._listeners = /* @__PURE__ */ Object.create(null);
1882
+ }
1883
+ function tt(c) {
1884
+ n(function() {
1885
+ throw c;
1886
+ }, 0);
1887
+ }
1888
+ me.prototype.dispatchEvent = function(c) {
1889
+ c.target = this;
1890
+ var f = this._listeners[c.type];
1891
+ if (f != null)
1892
+ for (var d = f.length, p = 0; p < d; p += 1) {
1893
+ var b = f[p];
1894
+ try {
1895
+ typeof b.handleEvent == "function" ? b.handleEvent(c) : b.call(this, c);
1896
+ } catch (k) {
1897
+ tt(k);
1898
+ }
1899
+ }
1900
+ }, me.prototype.addEventListener = function(c, f) {
1901
+ c = String(c);
1902
+ var d = this._listeners, p = d[c];
1903
+ p == null && (p = [], d[c] = p);
1904
+ for (var b = !1, k = 0; k < p.length; k += 1)
1905
+ p[k] === f && (b = !0);
1906
+ b || p.push(f);
1907
+ }, me.prototype.removeEventListener = function(c, f) {
1908
+ c = String(c);
1909
+ var d = this._listeners, p = d[c];
1910
+ if (p != null) {
1911
+ for (var b = [], k = 0; k < p.length; k += 1)
1912
+ p[k] !== f && b.push(p[k]);
1913
+ b.length === 0 ? delete d[c] : d[c] = b;
1914
+ }
1915
+ };
1916
+ function oe(c) {
1917
+ this.type = c, this.target = void 0;
1918
+ }
1919
+ function nt(c, f) {
1920
+ oe.call(this, c), this.data = f.data, this.lastEventId = f.lastEventId;
1921
+ }
1922
+ nt.prototype = Object.create(oe.prototype);
1923
+ function Pe(c, f) {
1924
+ oe.call(this, c), this.status = f.status, this.statusText = f.statusText, this.headers = f.headers;
1925
+ }
1926
+ Pe.prototype = Object.create(oe.prototype);
1927
+ function rt(c, f) {
1928
+ oe.call(this, c), this.error = f.error;
1929
+ }
1930
+ rt.prototype = Object.create(oe.prototype);
1931
+ var Ne = -1, te = 0, le = 1, be = 2, Oe = -1, ne = 0, Be = 1, st = 2, $t = 3, At = /^text\/event\-stream(;.*)?$/i, Ct = 1e3, It = 18e6, qe = function(c, f) {
1932
+ var d = c == null ? f : parseInt(c, 10);
1933
+ return d !== d && (d = f), Fe(d);
1934
+ }, Fe = function(c) {
1935
+ return Math.min(Math.max(c, Ct), It);
1936
+ }, ce = function(c, f, d) {
1937
+ try {
1938
+ typeof f == "function" && f.call(c, d);
1939
+ } catch (p) {
1940
+ tt(p);
1941
+ }
1942
+ };
1943
+ function G(c, f) {
1944
+ me.call(this), f = f || {}, this.onopen = void 0, this.onmessage = void 0, this.onerror = void 0, this.url = void 0, this.readyState = void 0, this.withCredentials = void 0, this.headers = void 0, this._close = void 0, Dt(this, c, f);
1945
+ }
1946
+ function Lt() {
1947
+ return r != null && "withCredentials" in r.prototype || i == null ? new r() : new i();
1948
+ }
1949
+ var zt = g != null && m != null && "body" in m.prototype;
1950
+ function Dt(c, f, d) {
1951
+ f = String(f);
1952
+ var p = !!d.withCredentials, b = d.lastEventIdQueryParameterName || "lastEventId", k = Fe(1e3), y = qe(d.heartbeatTimeout, 45e3), C = "", v = k, T = !1, $ = 0, w = d.headers || {}, I = d.Transport, K = zt && I == null ? void 0 : new X(I != null ? new I() : Lt()), we = I != null && typeof I != "string" ? new I() : K == null ? new et() : new ae(), H = void 0, P = 0, Q = Ne, ue = "", _e = "", V = "", $e = "", N = ne, He = 0, re = 0, Pt = function(z, L, M, j) {
1953
+ if (Q === te)
1954
+ if (z === 200 && M != null && At.test(M)) {
1955
+ Q = le, T = Date.now(), v = k, c.readyState = le;
1956
+ var O = new Pe("open", {
1957
+ status: z,
1958
+ statusText: L,
1959
+ headers: j
1960
+ });
1961
+ c.dispatchEvent(O), ce(c, c.onopen, O);
1962
+ } else {
1963
+ var D = "";
1964
+ z !== 200 ? (L && (L = L.replace(/\s+/g, " ")), D = "EventSource's response has a status " + z + " " + L + " that is not 200. Aborting the connection.") : D = "EventSource's response has a Content-Type specifying an unsupported type: " + (M == null ? "-" : M.replace(/\s+/g, " ")) + ". Aborting the connection.", Me();
1965
+ var O = new Pe("error", {
1966
+ status: z,
1967
+ statusText: L,
1968
+ headers: j
1969
+ });
1970
+ c.dispatchEvent(O), ce(c, c.onerror, O), console.error(D);
1971
+ }
1972
+ }, Nt = function(z) {
1973
+ if (Q === le) {
1974
+ for (var L = -1, M = 0; M < z.length; M += 1) {
1975
+ var j = z.charCodeAt(M);
1976
+ (j === 10 || j === 13) && (L = M);
1977
+ }
1978
+ var O = (L !== -1 ? $e : "") + z.slice(0, L + 1);
1979
+ $e = (L === -1 ? $e : "") + z.slice(L + 1), z !== "" && (T = Date.now(), $ += z.length);
1980
+ for (var D = 0; D < O.length; D += 1) {
1981
+ var j = O.charCodeAt(D);
1982
+ if (N === Oe && j === 10)
1983
+ N = ne;
1984
+ else if (N === Oe && (N = ne), j === 13 || j === 10) {
1985
+ if (N !== ne) {
1986
+ N === Be && (re = D + 1);
1987
+ var J = O.slice(He, re - 1), Y = O.slice(re + (re < D && O.charCodeAt(re) === 32 ? 1 : 0), D);
1988
+ J === "data" ? (ue += `
1989
+ `, ue += Y) : J === "id" ? _e = Y : J === "event" ? V = Y : J === "retry" ? (k = qe(Y, k), v = k) : J === "heartbeatTimeout" && (y = qe(Y, y), P !== 0 && (s(P), P = n(function() {
1990
+ xe();
1991
+ }, y)));
1992
+ }
1993
+ if (N === ne) {
1994
+ if (ue !== "") {
1995
+ C = _e, V === "" && (V = "message");
1996
+ var he = new nt(V, {
1997
+ data: ue.slice(1),
1998
+ lastEventId: _e
1999
+ });
2000
+ if (c.dispatchEvent(he), V === "open" ? ce(c, c.onopen, he) : V === "message" ? ce(c, c.onmessage, he) : V === "error" && ce(c, c.onerror, he), Q === be)
2001
+ return;
2002
+ }
2003
+ ue = "", V = "";
2004
+ }
2005
+ N = j === 13 ? Oe : ne;
2006
+ } else
2007
+ N === ne && (He = D, N = Be), N === Be ? j === 58 && (re = D + 1, N = st) : N === st && (N = $t);
2008
+ }
2009
+ }
2010
+ }, at = function(z) {
2011
+ if (Q === le || Q === te) {
2012
+ Q = Ne, P !== 0 && (s(P), P = 0), P = n(function() {
2013
+ xe();
2014
+ }, v), v = Fe(Math.min(k * 16, v * 2)), c.readyState = te;
2015
+ var L = new rt("error", { error: z });
2016
+ c.dispatchEvent(L), ce(c, c.onerror, L), z != null && console.error(z);
2017
+ }
2018
+ }, Me = function() {
2019
+ Q = be, H != null && (H.abort(), H = void 0), P !== 0 && (s(P), P = 0), c.readyState = be;
2020
+ }, xe = function() {
2021
+ if (P = 0, Q !== Ne) {
2022
+ if (!T && H != null)
2023
+ at(new Error("No activity within " + y + " milliseconds. " + (Q === te ? "No response received." : $ + " chars received.") + " Reconnecting.")), H != null && (H.abort(), H = void 0);
2024
+ else {
2025
+ var z = Math.max((T || Date.now()) + y - Date.now(), 1);
2026
+ T = !1, P = n(function() {
2027
+ xe();
2028
+ }, z);
2029
+ }
2030
+ return;
2031
+ }
2032
+ T = !1, $ = 0, P = n(function() {
2033
+ xe();
2034
+ }, y), Q = te, ue = "", V = "", _e = C, $e = "", He = 0, re = 0, N = ne;
2035
+ var L = f;
2036
+ if (f.slice(0, 5) !== "data:" && f.slice(0, 5) !== "blob:" && C !== "") {
2037
+ var M = f.indexOf("?");
2038
+ L = M === -1 ? f : f.slice(0, M + 1) + f.slice(M + 1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g, function(Y, he) {
2039
+ return he === b ? "" : Y;
2040
+ }), L += (f.indexOf("?") === -1 ? "?" : "&") + b + "=" + encodeURIComponent(C);
2041
+ }
2042
+ var j = c.withCredentials, O = {};
2043
+ O.Accept = "text/event-stream";
2044
+ var D = c.headers;
2045
+ if (D != null)
2046
+ for (var J in D)
2047
+ Object.prototype.hasOwnProperty.call(D, J) && (O[J] = D[J]);
2048
+ try {
2049
+ H = we.open(K, Pt, Nt, at, L, j, O);
2050
+ } catch (Y) {
2051
+ throw Me(), Y;
2052
+ }
2053
+ };
2054
+ c.url = f, c.readyState = te, c.withCredentials = p, c.headers = w, c._close = Me, xe();
2055
+ }
2056
+ G.prototype = Object.create(me.prototype), G.prototype.CONNECTING = te, G.prototype.OPEN = le, G.prototype.CLOSED = be, G.prototype.close = function() {
2057
+ this._close();
2058
+ }, G.CONNECTING = te, G.OPEN = le, G.CLOSED = be, G.prototype.withCredentials = void 0;
2059
+ var it = u;
2060
+ r != null && (u == null || !("withCredentials" in u.prototype)) && (it = G), function(c) {
2061
+ {
2062
+ var f = c(e);
2063
+ f !== void 0 && (h.exports = f);
2064
+ }
2065
+ }(function(c) {
2066
+ c.EventSourcePolyfill = G, c.NativeEventSource = u, c.EventSource = it;
2067
+ });
2068
+ })(typeof globalThis > "u" ? typeof window < "u" ? window : typeof self < "u" ? self : vn : globalThis);
2069
+ })(Ze, Ze.exports);
2070
+ var dt = Ze.exports;
2071
+ const je = () => {
2072
+ };
2073
+ function Sn(h, e) {
2074
+ return h != h ? e == e : h !== e || h !== null && typeof h == "object" || typeof h == "function";
2075
+ }
2076
+ const fe = [];
2077
+ function Rn(h, e = je) {
2078
+ let t = null;
2079
+ const n = /* @__PURE__ */ new Set();
2080
+ function s(a) {
2081
+ if (Sn(h, a) && (h = a, t)) {
2082
+ const u = !fe.length;
2083
+ for (const o of n)
2084
+ o[1](), fe.push(o, h);
2085
+ if (u) {
2086
+ for (let o = 0; o < fe.length; o += 2)
2087
+ fe[o][0](fe[o + 1]);
2088
+ fe.length = 0;
2089
+ }
2090
+ }
2091
+ }
2092
+ function r(a) {
2093
+ s(a(
2094
+ /** @type {T} */
2095
+ h
2096
+ ));
2097
+ }
2098
+ function i(a, u = je) {
2099
+ const o = [a, u];
2100
+ return n.add(o), n.size === 1 && (t = e(s, r) || je), a(
2101
+ /** @type {T} */
2102
+ h
2103
+ ), () => {
2104
+ n.delete(o), n.size === 0 && t && (t(), t = null);
2105
+ };
2106
+ }
2107
+ return { set: s, update: r, subscribe: i };
2108
+ }
2109
+ const gt = (h) => Object.fromEntries(Object.entries(h).filter(([e, t]) => t != null)), Tn = (h) => {
2110
+ try {
2111
+ return new URL(h).hostname;
2112
+ } catch {
2113
+ return h;
2114
+ }
2115
+ }, En = (h) => ({
2116
+ url: h.usedLinks.url,
2117
+ title: h.usedLinks.title,
2118
+ referenceNumber: h.usedLinks.number,
2119
+ domainName: Tn(h.usedLinks.url),
2120
+ breadcrumb: [],
2121
+ // TODO: use Title ans split > to create this breadcrumb
2122
+ generated: {
2123
+ title: h.usedLinks.title ?? "",
2124
+ // TODO: Exclude the breadcrumbs
2125
+ summary: h.usedLinks.content
2126
+ // TODO: use summary (available at alva endpoint) or strip content of markdown and titles
2127
+ }
2128
+ }), kt = (h, e) => {
2129
+ const t = h.all.length, n = En(e);
2130
+ return n.referenceNumber = t + 1, h.all.push(n), h;
2131
+ }, _n = dt.NativeEventSource || dt.EventSourcePolyfill;
2132
+ let mt;
2133
+ class An {
2134
+ constructor({ apiUrl: e, apiKey: t = "X9hL4Gp5W2D7eRtF" }) {
2135
+ R(this, "apiUrl");
2136
+ R(this, "apiKey");
2137
+ R(this, "metadata");
2138
+ this.apiUrl = e, this.apiKey = t, this.metadata = this.getUserData(), mt = this;
2139
+ }
2140
+ async getUserData() {
2141
+ var n;
2142
+ const e = ot.getItem("uID"), t = await this.fetchData(
2143
+ "/log",
2144
+ {},
2145
+ {
2146
+ method: "POST",
2147
+ headers: {
2148
+ Accept: "application/json",
2149
+ "Content-Type": "application/json"
2150
+ },
2151
+ body: JSON.stringify({
2152
+ referrer: ((n = globalThis == null ? void 0 : globalThis.document) == null ? void 0 : n.referrer) || null,
2153
+ // initialQuery: initialQuery, TODO
2154
+ uID: e
2155
+ })
2156
+ }
2157
+ );
2158
+ if ("maintenance" in t && t.maintenance)
2159
+ return {
2160
+ mode: "maintenance"
2161
+ };
2162
+ if (!("id" in t)) throw new Error("Could not retrieve a user id");
2163
+ return ot.setItem("uID", t.id), {
2164
+ mode: "ready",
2165
+ userId: t.id,
2166
+ conversationId: t.cID
2167
+ };
2168
+ }
2169
+ static getInstance() {
2170
+ return mt;
2171
+ }
2172
+ async fetchData(e, t = {}, n = {}) {
2173
+ return (await fetch(
2174
+ `${this.apiUrl}${e}?${new URLSearchParams(gt(t)).toString()}`,
2175
+ {
2176
+ ...n,
2177
+ headers: {
2178
+ ...(n == null ? void 0 : n.headers) || {},
2179
+ "api-key": this.apiKey
2180
+ }
2181
+ }
2182
+ )).json();
2183
+ }
2184
+ async fetchSSE(e, t = {}) {
2185
+ return new _n(
2186
+ `${this.apiUrl}${e}?${new URLSearchParams({
2187
+ ...gt(t),
2188
+ key: this.apiKey
2189
+ }).toString()}`
2190
+ );
2191
+ }
2192
+ async getPredefinedQuestions(e) {
2193
+ return (await this.fetchData("/topics/questions", e)).predefinedQuestions;
2194
+ }
2195
+ async chatInternal(e, t = {}) {
2196
+ const n = await this.metadata;
2197
+ if (n.mode === "maintenance")
2198
+ throw new Error("Can not chat in maintenance mode");
2199
+ return this.fetchSSE("/assistant/sse", {
2200
+ query: e,
2201
+ uID: n.userId,
2202
+ cID: n.conversationId,
2203
+ lang: t.lang,
2204
+ model: t.model
2205
+ });
2206
+ }
2207
+ chat(e, t = {}) {
2208
+ const n = Rn({ state: "loading" });
2209
+ let s = !0, r = !1;
2210
+ const i = (/* @__PURE__ */ new Date()).toISOString();
2211
+ return this.chatInternal(e, t).then((a) => {
2212
+ a.onmessage = (u) => {
2213
+ const o = JSON.parse(u.data);
2214
+ "response" in o ? o.response === "__CLR__" ? s = !1 : o.response === "__THIS_IS_THE_ANSWER_END__" ? (r = !0, n.update((l) => {
2215
+ if (l.state !== "streaming") throw new Error("Invalid state transition to done");
2216
+ return { payload: { ...l.payload, partial: !1 }, state: "done" };
2217
+ })) : s === !1 && r === !1 && n.update((l) => {
2218
+ if (l.state === "streaming") {
2219
+ const g = l.payload.message.markdown + o.response;
2220
+ return {
2221
+ state: "streaming",
2222
+ payload: {
2223
+ ...l.payload,
2224
+ partial: !0,
2225
+ message: {
2226
+ markdown: g,
2227
+ html: ft(g, l.payload)
2228
+ }
2229
+ }
2230
+ };
2231
+ }
2232
+ if (l.state === "loading") {
2233
+ const g = o.response;
2234
+ return {
2235
+ state: "streaming",
2236
+ payload: {
2237
+ type: "bot",
2238
+ time: i,
2239
+ partial: !0,
2240
+ sources: { all: [], used: [] },
2241
+ message: {
2242
+ markdown: g,
2243
+ html: ft(g, {
2244
+ type: "bot",
2245
+ time: i,
2246
+ partial: !0,
2247
+ sources: { all: [], used: [] },
2248
+ message: {
2249
+ markdown: "",
2250
+ html: ""
2251
+ }
2252
+ })
2253
+ }
2254
+ }
2255
+ };
2256
+ } else
2257
+ throw console.error("Invalid message state", l), new Error("Invalid message state");
2258
+ }) : "usedLinks" in o && n.update((l) => {
2259
+ var g;
2260
+ if (l.state === "loading")
2261
+ return {
2262
+ state: "streaming",
2263
+ payload: {
2264
+ type: "bot",
2265
+ time: i,
2266
+ partial: !0,
2267
+ message: {
2268
+ markdown: "",
2269
+ html: ""
2270
+ },
2271
+ sources: kt({ all: [], used: [] }, o)
2272
+ }
2273
+ };
2274
+ if (l.state === "streaming")
2275
+ return {
2276
+ state: "streaming",
2277
+ payload: {
2278
+ ...l.payload,
2279
+ partial: !0,
2280
+ sources: kt((g = l.payload) == null ? void 0 : g.sources, o)
2281
+ }
2282
+ };
2283
+ throw console.error("Invalid source state", l), new Error("Invalid source state");
2284
+ });
2285
+ }, a.onerror = () => {
2286
+ a.close(), n.set({
2287
+ state: "error",
2288
+ errorMessage: "EventSource error"
2289
+ });
2290
+ };
2291
+ }).catch((a) => {
2292
+ console.error(a), n.set({ state: "error", errorMessage: a.message });
2293
+ }), n;
2294
+ }
2295
+ search(e, t = {}) {
2296
+ return this.metadata = this.getUserData(), this.chat(`prompt:SEARCH ${e}`, t);
2297
+ }
2298
+ transformURL(e) {
2299
+ if (e.startsWith("file://")) {
2300
+ const t = e.replace("file://", `${this.apiUrl}/files/`), n = new URL(t);
2301
+ return n.searchParams.append("key", this.apiKey), n.toString();
2302
+ }
2303
+ return e;
2304
+ }
2305
+ }
2306
+ export {
2307
+ An as LiipGPTClient
2308
+ };