advaisor-chatbot 1.0.0

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.
Files changed (2) hide show
  1. package/dist/testchatbot.js +1519 -0
  2. package/package.json +21 -0
@@ -0,0 +1,1519 @@
1
+ (() => {
2
+ // node_modules/marked/lib/marked.esm.js
3
+ function L() {
4
+ return { async: false, breaks: false, extensions: null, gfm: true, hooks: null, pedantic: false, renderer: null, silent: false, tokenizer: null, walkTokens: null };
5
+ }
6
+ var T = L();
7
+ function Z(u3) {
8
+ T = u3;
9
+ }
10
+ var C = { exec: () => null };
11
+ function k(u3, e = "") {
12
+ let t = typeof u3 == "string" ? u3 : u3.source, n = { replace: (r, i) => {
13
+ let s = typeof i == "string" ? i : i.source;
14
+ return s = s.replace(m.caret, "$1"), t = t.replace(r, s), n;
15
+ }, getRegex: () => new RegExp(t, e) };
16
+ return n;
17
+ }
18
+ var me = (() => {
19
+ try {
20
+ return !!new RegExp("(?<=1)(?<!1)");
21
+ } catch {
22
+ return false;
23
+ }
24
+ })();
25
+ var m = { 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]\] +\S/, listReplaceTask: /^\[[ xX]\] +/, listTaskCheckbox: /\[[ 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: (u3) => new RegExp(`^( {0,3}${u3})((?:[ ][^\\n]*)?(?:\\n|$))`), nextBulletRegex: (u3) => new RegExp(`^ {0,${Math.min(3, u3 - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`), hrRegex: (u3) => new RegExp(`^ {0,${Math.min(3, u3 - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`), fencesBeginRegex: (u3) => new RegExp(`^ {0,${Math.min(3, u3 - 1)}}(?:\`\`\`|~~~)`), headingBeginRegex: (u3) => new RegExp(`^ {0,${Math.min(3, u3 - 1)}}#`), htmlBeginRegex: (u3) => new RegExp(`^ {0,${Math.min(3, u3 - 1)}}<(?:[a-z].*>|!--)`, "i") };
26
+ var xe = /^(?:[ \t]*(?:\n|$))+/;
27
+ var be = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/;
28
+ var Re = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/;
29
+ var I = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
30
+ var Te = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
31
+ var N = /(?:[*+-]|\d{1,9}[.)])/;
32
+ var re = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/;
33
+ var se = k(re).replace(/bull/g, N).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();
34
+ var Oe = k(re).replace(/bull/g, N).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();
35
+ var Q = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/;
36
+ var we = /^[^\n]+/;
37
+ var F = /(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/;
38
+ var ye = k(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", F).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex();
39
+ var Pe = k(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g, N).getRegex();
40
+ var v = "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";
41
+ var j = /<!--(?:-?>|[\s\S]*?(?:-->|$))/;
42
+ var Se = k("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))", "i").replace("comment", j).replace("tag", v).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
43
+ var ie = k(Q).replace("hr", I).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", v).getRegex();
44
+ var $e = k(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", ie).getRegex();
45
+ var U = { blockquote: $e, code: be, def: ye, fences: Re, heading: Te, hr: I, html: Se, lheading: se, list: Pe, newline: xe, paragraph: ie, table: C, text: we };
46
+ var te = k("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr", I).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", v).getRegex();
47
+ var _e = { ...U, lheading: Oe, table: te, paragraph: k(Q).replace("hr", I).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", te).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", v).getRegex() };
48
+ var Le = { ...U, html: k(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment", j).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: C, lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/, paragraph: k(Q).replace("hr", I).replace("heading", ` *#{1,6} *[^
49
+ ]`).replace("lheading", se).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex() };
50
+ var Me = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/;
51
+ var ze = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
52
+ var oe = /^( {2,}|\\)\n(?!\s*$)/;
53
+ var Ae = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/;
54
+ var D = /[\p{P}\p{S}]/u;
55
+ var K = /[\s\p{P}\p{S}]/u;
56
+ var ae = /[^\s\p{P}\p{S}]/u;
57
+ var Ce = k(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, K).getRegex();
58
+ var le = /(?!~)[\p{P}\p{S}]/u;
59
+ var Ie = /(?!~)[\s\p{P}\p{S}]/u;
60
+ var Ee = /(?:[^\s\p{P}\p{S}]|~)/u;
61
+ var Be = k(/link|precode-code|html/, "g").replace("link", /\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-", me ? "(?<!`)()" : "(^^|[^`])").replace("code", /(?<b>`+)[^`]+\k<b>(?!`)/).replace("html", /<(?! )[^<>]*?>/).getRegex();
62
+ var ue = /^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/;
63
+ var qe = k(ue, "u").replace(/punct/g, D).getRegex();
64
+ var ve = k(ue, "u").replace(/punct/g, le).getRegex();
65
+ var pe = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)";
66
+ var De = k(pe, "gu").replace(/notPunctSpace/g, ae).replace(/punctSpace/g, K).replace(/punct/g, D).getRegex();
67
+ var He = k(pe, "gu").replace(/notPunctSpace/g, Ee).replace(/punctSpace/g, Ie).replace(/punct/g, le).getRegex();
68
+ var Ze = k("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)", "gu").replace(/notPunctSpace/g, ae).replace(/punctSpace/g, K).replace(/punct/g, D).getRegex();
69
+ var Ge = k(/\\(punct)/, "gu").replace(/punct/g, D).getRegex();
70
+ var Ne = k(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme", /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email", /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex();
71
+ var Qe = k(j).replace("(?:-->|$)", "-->").getRegex();
72
+ var Fe = k("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment", Qe).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex();
73
+ var q = /(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/;
74
+ var je = k(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label", q).replace("href", /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex();
75
+ var ce = k(/^!?\[(label)\]\[(ref)\]/).replace("label", q).replace("ref", F).getRegex();
76
+ var he = k(/^!?\[(ref)\](?:\[\])?/).replace("ref", F).getRegex();
77
+ var Ue = k("reflink|nolink(?!\\()", "g").replace("reflink", ce).replace("nolink", he).getRegex();
78
+ var ne = /[hH][tT][tT][pP][sS]?|[fF][tT][pP]/;
79
+ var W = { _backpedal: C, anyPunctuation: Ge, autolink: Ne, blockSkip: Be, br: oe, code: ze, del: C, emStrongLDelim: qe, emStrongRDelimAst: De, emStrongRDelimUnd: Ze, escape: Me, link: je, nolink: he, punctuation: Ce, reflink: ce, reflinkSearch: Ue, tag: Fe, text: Ae, url: C };
80
+ var Ke = { ...W, link: k(/^!?\[(label)\]\((.*?)\)/).replace("label", q).getRegex(), reflink: k(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", q).getRegex() };
81
+ var G = { ...W, emStrongRDelimAst: He, emStrongLDelim: ve, url: k(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol", ne).replace("email", /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(), _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/, del: /^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/, text: k(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol", ne).getRegex() };
82
+ var We = { ...G, br: k(oe).replace("{2,}", "*").getRegex(), text: k(G.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex() };
83
+ var E = { normal: U, gfm: _e, pedantic: Le };
84
+ var M = { normal: W, gfm: G, breaks: We, pedantic: Ke };
85
+ var Xe = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" };
86
+ var ke = (u3) => Xe[u3];
87
+ function w(u3, e) {
88
+ if (e) {
89
+ if (m.escapeTest.test(u3)) return u3.replace(m.escapeReplace, ke);
90
+ } else if (m.escapeTestNoEncode.test(u3)) return u3.replace(m.escapeReplaceNoEncode, ke);
91
+ return u3;
92
+ }
93
+ function X(u3) {
94
+ try {
95
+ u3 = encodeURI(u3).replace(m.percentDecode, "%");
96
+ } catch {
97
+ return null;
98
+ }
99
+ return u3;
100
+ }
101
+ function J(u3, e) {
102
+ let t = u3.replace(m.findPipe, (i, s, a) => {
103
+ let o = false, l = s;
104
+ for (; --l >= 0 && a[l] === "\\"; ) o = !o;
105
+ return o ? "|" : " |";
106
+ }), n = t.split(m.splitPipe), r = 0;
107
+ if (n[0].trim() || n.shift(), n.length > 0 && !n.at(-1)?.trim() && n.pop(), e) if (n.length > e) n.splice(e);
108
+ else for (; n.length < e; ) n.push("");
109
+ for (; r < n.length; r++) n[r] = n[r].trim().replace(m.slashPipe, "|");
110
+ return n;
111
+ }
112
+ function z(u3, e, t) {
113
+ let n = u3.length;
114
+ if (n === 0) return "";
115
+ let r = 0;
116
+ for (; r < n; ) {
117
+ let i = u3.charAt(n - r - 1);
118
+ if (i === e && !t) r++;
119
+ else if (i !== e && t) r++;
120
+ else break;
121
+ }
122
+ return u3.slice(0, n - r);
123
+ }
124
+ function de(u3, e) {
125
+ if (u3.indexOf(e[1]) === -1) return -1;
126
+ let t = 0;
127
+ for (let n = 0; n < u3.length; n++) if (u3[n] === "\\") n++;
128
+ else if (u3[n] === e[0]) t++;
129
+ else if (u3[n] === e[1] && (t--, t < 0)) return n;
130
+ return t > 0 ? -2 : -1;
131
+ }
132
+ function ge(u3, e, t, n, r) {
133
+ let i = e.href, s = e.title || null, a = u3[1].replace(r.other.outputLinkReplace, "$1");
134
+ n.state.inLink = true;
135
+ let o = { type: u3[0].charAt(0) === "!" ? "image" : "link", raw: t, href: i, title: s, text: a, tokens: n.inlineTokens(a) };
136
+ return n.state.inLink = false, o;
137
+ }
138
+ function Je(u3, e, t) {
139
+ let n = u3.match(t.other.indentCodeCompensation);
140
+ if (n === null) return e;
141
+ let r = n[1];
142
+ return e.split(`
143
+ `).map((i) => {
144
+ let s = i.match(t.other.beginningSpace);
145
+ if (s === null) return i;
146
+ let [a] = s;
147
+ return a.length >= r.length ? i.slice(r.length) : i;
148
+ }).join(`
149
+ `);
150
+ }
151
+ var y = class {
152
+ options;
153
+ rules;
154
+ lexer;
155
+ constructor(e) {
156
+ this.options = e || T;
157
+ }
158
+ space(e) {
159
+ let t = this.rules.block.newline.exec(e);
160
+ if (t && t[0].length > 0) return { type: "space", raw: t[0] };
161
+ }
162
+ code(e) {
163
+ let t = this.rules.block.code.exec(e);
164
+ if (t) {
165
+ let n = t[0].replace(this.rules.other.codeRemoveIndent, "");
166
+ return { type: "code", raw: t[0], codeBlockStyle: "indented", text: this.options.pedantic ? n : z(n, `
167
+ `) };
168
+ }
169
+ }
170
+ fences(e) {
171
+ let t = this.rules.block.fences.exec(e);
172
+ if (t) {
173
+ let n = t[0], r = Je(n, t[3] || "", this.rules);
174
+ return { type: "code", raw: n, lang: t[2] ? t[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : t[2], text: r };
175
+ }
176
+ }
177
+ heading(e) {
178
+ let t = this.rules.block.heading.exec(e);
179
+ if (t) {
180
+ let n = t[2].trim();
181
+ if (this.rules.other.endingHash.test(n)) {
182
+ let r = z(n, "#");
183
+ (this.options.pedantic || !r || this.rules.other.endingSpaceChar.test(r)) && (n = r.trim());
184
+ }
185
+ return { type: "heading", raw: t[0], depth: t[1].length, text: n, tokens: this.lexer.inline(n) };
186
+ }
187
+ }
188
+ hr(e) {
189
+ let t = this.rules.block.hr.exec(e);
190
+ if (t) return { type: "hr", raw: z(t[0], `
191
+ `) };
192
+ }
193
+ blockquote(e) {
194
+ let t = this.rules.block.blockquote.exec(e);
195
+ if (t) {
196
+ let n = z(t[0], `
197
+ `).split(`
198
+ `), r = "", i = "", s = [];
199
+ for (; n.length > 0; ) {
200
+ let a = false, o = [], l;
201
+ for (l = 0; l < n.length; l++) if (this.rules.other.blockquoteStart.test(n[l])) o.push(n[l]), a = true;
202
+ else if (!a) o.push(n[l]);
203
+ else break;
204
+ n = n.slice(l);
205
+ let p = o.join(`
206
+ `), c = p.replace(this.rules.other.blockquoteSetextReplace, `
207
+ $1`).replace(this.rules.other.blockquoteSetextReplace2, "");
208
+ r = r ? `${r}
209
+ ${p}` : p, i = i ? `${i}
210
+ ${c}` : c;
211
+ let g = this.lexer.state.top;
212
+ if (this.lexer.state.top = true, this.lexer.blockTokens(c, s, true), this.lexer.state.top = g, n.length === 0) break;
213
+ let h = s.at(-1);
214
+ if (h?.type === "code") break;
215
+ if (h?.type === "blockquote") {
216
+ let R = h, f = R.raw + `
217
+ ` + n.join(`
218
+ `), O = this.blockquote(f);
219
+ s[s.length - 1] = O, r = r.substring(0, r.length - R.raw.length) + O.raw, i = i.substring(0, i.length - R.text.length) + O.text;
220
+ break;
221
+ } else if (h?.type === "list") {
222
+ let R = h, f = R.raw + `
223
+ ` + n.join(`
224
+ `), O = this.list(f);
225
+ s[s.length - 1] = O, r = r.substring(0, r.length - h.raw.length) + O.raw, i = i.substring(0, i.length - R.raw.length) + O.raw, n = f.substring(s.at(-1).raw.length).split(`
226
+ `);
227
+ continue;
228
+ }
229
+ }
230
+ return { type: "blockquote", raw: r, tokens: s, text: i };
231
+ }
232
+ }
233
+ list(e) {
234
+ let t = this.rules.block.list.exec(e);
235
+ if (t) {
236
+ let n = t[1].trim(), r = n.length > 1, i = { type: "list", raw: "", ordered: r, start: r ? +n.slice(0, -1) : "", loose: false, items: [] };
237
+ n = r ? `\\d{1,9}\\${n.slice(-1)}` : `\\${n}`, this.options.pedantic && (n = r ? n : "[*+-]");
238
+ let s = this.rules.other.listItemRegex(n), a = false;
239
+ for (; e; ) {
240
+ let l = false, p = "", c = "";
241
+ if (!(t = s.exec(e)) || this.rules.block.hr.test(e)) break;
242
+ p = t[0], e = e.substring(p.length);
243
+ let g = t[2].split(`
244
+ `, 1)[0].replace(this.rules.other.listReplaceTabs, (O) => " ".repeat(3 * O.length)), h = e.split(`
245
+ `, 1)[0], R = !g.trim(), f = 0;
246
+ if (this.options.pedantic ? (f = 2, c = g.trimStart()) : R ? f = t[1].length + 1 : (f = t[2].search(this.rules.other.nonSpaceChar), f = f > 4 ? 1 : f, c = g.slice(f), f += t[1].length), R && this.rules.other.blankLine.test(h) && (p += h + `
247
+ `, e = e.substring(h.length + 1), l = true), !l) {
248
+ let O = this.rules.other.nextBulletRegex(f), V = this.rules.other.hrRegex(f), Y = this.rules.other.fencesBeginRegex(f), ee = this.rules.other.headingBeginRegex(f), fe = this.rules.other.htmlBeginRegex(f);
249
+ for (; e; ) {
250
+ let H = e.split(`
251
+ `, 1)[0], A;
252
+ if (h = H, this.options.pedantic ? (h = h.replace(this.rules.other.listReplaceNesting, " "), A = h) : A = h.replace(this.rules.other.tabCharGlobal, " "), Y.test(h) || ee.test(h) || fe.test(h) || O.test(h) || V.test(h)) break;
253
+ if (A.search(this.rules.other.nonSpaceChar) >= f || !h.trim()) c += `
254
+ ` + A.slice(f);
255
+ else {
256
+ if (R || g.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4 || Y.test(g) || ee.test(g) || V.test(g)) break;
257
+ c += `
258
+ ` + h;
259
+ }
260
+ !R && !h.trim() && (R = true), p += H + `
261
+ `, e = e.substring(H.length + 1), g = A.slice(f);
262
+ }
263
+ }
264
+ i.loose || (a ? i.loose = true : this.rules.other.doubleBlankLine.test(p) && (a = true)), i.items.push({ type: "list_item", raw: p, task: !!this.options.gfm && this.rules.other.listIsTask.test(c), loose: false, text: c, tokens: [] }), i.raw += p;
265
+ }
266
+ let o = i.items.at(-1);
267
+ if (o) o.raw = o.raw.trimEnd(), o.text = o.text.trimEnd();
268
+ else return;
269
+ i.raw = i.raw.trimEnd();
270
+ for (let l of i.items) {
271
+ if (this.lexer.state.top = false, l.tokens = this.lexer.blockTokens(l.text, []), l.task) {
272
+ if (l.text = l.text.replace(this.rules.other.listReplaceTask, ""), l.tokens[0]?.type === "text" || l.tokens[0]?.type === "paragraph") {
273
+ l.tokens[0].raw = l.tokens[0].raw.replace(this.rules.other.listReplaceTask, ""), l.tokens[0].text = l.tokens[0].text.replace(this.rules.other.listReplaceTask, "");
274
+ for (let c = this.lexer.inlineQueue.length - 1; c >= 0; c--) if (this.rules.other.listIsTask.test(this.lexer.inlineQueue[c].src)) {
275
+ this.lexer.inlineQueue[c].src = this.lexer.inlineQueue[c].src.replace(this.rules.other.listReplaceTask, "");
276
+ break;
277
+ }
278
+ }
279
+ let p = this.rules.other.listTaskCheckbox.exec(l.raw);
280
+ if (p) {
281
+ let c = { type: "checkbox", raw: p[0] + " ", checked: p[0] !== "[ ]" };
282
+ l.checked = c.checked, i.loose ? l.tokens[0] && ["paragraph", "text"].includes(l.tokens[0].type) && "tokens" in l.tokens[0] && l.tokens[0].tokens ? (l.tokens[0].raw = c.raw + l.tokens[0].raw, l.tokens[0].text = c.raw + l.tokens[0].text, l.tokens[0].tokens.unshift(c)) : l.tokens.unshift({ type: "paragraph", raw: c.raw, text: c.raw, tokens: [c] }) : l.tokens.unshift(c);
283
+ }
284
+ }
285
+ if (!i.loose) {
286
+ let p = l.tokens.filter((g) => g.type === "space"), c = p.length > 0 && p.some((g) => this.rules.other.anyLine.test(g.raw));
287
+ i.loose = c;
288
+ }
289
+ }
290
+ if (i.loose) for (let l of i.items) {
291
+ l.loose = true;
292
+ for (let p of l.tokens) p.type === "text" && (p.type = "paragraph");
293
+ }
294
+ return i;
295
+ }
296
+ }
297
+ html(e) {
298
+ let t = this.rules.block.html.exec(e);
299
+ if (t) return { type: "html", block: true, raw: t[0], pre: t[1] === "pre" || t[1] === "script" || t[1] === "style", text: t[0] };
300
+ }
301
+ def(e) {
302
+ let t = this.rules.block.def.exec(e);
303
+ if (t) {
304
+ let n = t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal, " "), r = t[2] ? t[2].replace(this.rules.other.hrefBrackets, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "", i = t[3] ? t[3].substring(1, t[3].length - 1).replace(this.rules.inline.anyPunctuation, "$1") : t[3];
305
+ return { type: "def", tag: n, raw: t[0], href: r, title: i };
306
+ }
307
+ }
308
+ table(e) {
309
+ let t = this.rules.block.table.exec(e);
310
+ if (!t || !this.rules.other.tableDelimiter.test(t[2])) return;
311
+ let n = J(t[1]), r = t[2].replace(this.rules.other.tableAlignChars, "").split("|"), i = t[3]?.trim() ? t[3].replace(this.rules.other.tableRowBlankLine, "").split(`
312
+ `) : [], s = { type: "table", raw: t[0], header: [], align: [], rows: [] };
313
+ if (n.length === r.length) {
314
+ for (let a of r) this.rules.other.tableAlignRight.test(a) ? s.align.push("right") : this.rules.other.tableAlignCenter.test(a) ? s.align.push("center") : this.rules.other.tableAlignLeft.test(a) ? s.align.push("left") : s.align.push(null);
315
+ for (let a = 0; a < n.length; a++) s.header.push({ text: n[a], tokens: this.lexer.inline(n[a]), header: true, align: s.align[a] });
316
+ for (let a of i) s.rows.push(J(a, s.header.length).map((o, l) => ({ text: o, tokens: this.lexer.inline(o), header: false, align: s.align[l] })));
317
+ return s;
318
+ }
319
+ }
320
+ lheading(e) {
321
+ let t = this.rules.block.lheading.exec(e);
322
+ if (t) return { type: "heading", raw: t[0], depth: t[2].charAt(0) === "=" ? 1 : 2, text: t[1], tokens: this.lexer.inline(t[1]) };
323
+ }
324
+ paragraph(e) {
325
+ let t = this.rules.block.paragraph.exec(e);
326
+ if (t) {
327
+ let n = t[1].charAt(t[1].length - 1) === `
328
+ ` ? t[1].slice(0, -1) : t[1];
329
+ return { type: "paragraph", raw: t[0], text: n, tokens: this.lexer.inline(n) };
330
+ }
331
+ }
332
+ text(e) {
333
+ let t = this.rules.block.text.exec(e);
334
+ if (t) return { type: "text", raw: t[0], text: t[0], tokens: this.lexer.inline(t[0]) };
335
+ }
336
+ escape(e) {
337
+ let t = this.rules.inline.escape.exec(e);
338
+ if (t) return { type: "escape", raw: t[0], text: t[1] };
339
+ }
340
+ tag(e) {
341
+ let t = this.rules.inline.tag.exec(e);
342
+ if (t) return !this.lexer.state.inLink && this.rules.other.startATag.test(t[0]) ? this.lexer.state.inLink = true : this.lexer.state.inLink && this.rules.other.endATag.test(t[0]) && (this.lexer.state.inLink = false), !this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(t[0]) ? this.lexer.state.inRawBlock = true : this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(t[0]) && (this.lexer.state.inRawBlock = false), { type: "html", raw: t[0], inLink: this.lexer.state.inLink, inRawBlock: this.lexer.state.inRawBlock, block: false, text: t[0] };
343
+ }
344
+ link(e) {
345
+ let t = this.rules.inline.link.exec(e);
346
+ if (t) {
347
+ let n = t[2].trim();
348
+ if (!this.options.pedantic && this.rules.other.startAngleBracket.test(n)) {
349
+ if (!this.rules.other.endAngleBracket.test(n)) return;
350
+ let s = z(n.slice(0, -1), "\\");
351
+ if ((n.length - s.length) % 2 === 0) return;
352
+ } else {
353
+ let s = de(t[2], "()");
354
+ if (s === -2) return;
355
+ if (s > -1) {
356
+ let o = (t[0].indexOf("!") === 0 ? 5 : 4) + t[1].length + s;
357
+ t[2] = t[2].substring(0, s), t[0] = t[0].substring(0, o).trim(), t[3] = "";
358
+ }
359
+ }
360
+ let r = t[2], i = "";
361
+ if (this.options.pedantic) {
362
+ let s = this.rules.other.pedanticHrefTitle.exec(r);
363
+ s && (r = s[1], i = s[3]);
364
+ } else i = t[3] ? t[3].slice(1, -1) : "";
365
+ return r = r.trim(), this.rules.other.startAngleBracket.test(r) && (this.options.pedantic && !this.rules.other.endAngleBracket.test(n) ? r = r.slice(1) : r = r.slice(1, -1)), ge(t, { href: r && r.replace(this.rules.inline.anyPunctuation, "$1"), title: i && i.replace(this.rules.inline.anyPunctuation, "$1") }, t[0], this.lexer, this.rules);
366
+ }
367
+ }
368
+ reflink(e, t) {
369
+ let n;
370
+ if ((n = this.rules.inline.reflink.exec(e)) || (n = this.rules.inline.nolink.exec(e))) {
371
+ let r = (n[2] || n[1]).replace(this.rules.other.multipleSpaceGlobal, " "), i = t[r.toLowerCase()];
372
+ if (!i) {
373
+ let s = n[0].charAt(0);
374
+ return { type: "text", raw: s, text: s };
375
+ }
376
+ return ge(n, i, n[0], this.lexer, this.rules);
377
+ }
378
+ }
379
+ emStrong(e, t, n = "") {
380
+ let r = this.rules.inline.emStrongLDelim.exec(e);
381
+ if (!r || r[3] && n.match(this.rules.other.unicodeAlphaNumeric)) return;
382
+ if (!(r[1] || r[2] || "") || !n || this.rules.inline.punctuation.exec(n)) {
383
+ let s = [...r[0]].length - 1, a, o, l = s, p = 0, c = r[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
384
+ for (c.lastIndex = 0, t = t.slice(-1 * e.length + s); (r = c.exec(t)) != null; ) {
385
+ if (a = r[1] || r[2] || r[3] || r[4] || r[5] || r[6], !a) continue;
386
+ if (o = [...a].length, r[3] || r[4]) {
387
+ l += o;
388
+ continue;
389
+ } else if ((r[5] || r[6]) && s % 3 && !((s + o) % 3)) {
390
+ p += o;
391
+ continue;
392
+ }
393
+ if (l -= o, l > 0) continue;
394
+ o = Math.min(o, o + l + p);
395
+ let g = [...r[0]][0].length, h = e.slice(0, s + r.index + g + o);
396
+ if (Math.min(s, o) % 2) {
397
+ let f = h.slice(1, -1);
398
+ return { type: "em", raw: h, text: f, tokens: this.lexer.inlineTokens(f) };
399
+ }
400
+ let R = h.slice(2, -2);
401
+ return { type: "strong", raw: h, text: R, tokens: this.lexer.inlineTokens(R) };
402
+ }
403
+ }
404
+ }
405
+ codespan(e) {
406
+ let t = this.rules.inline.code.exec(e);
407
+ if (t) {
408
+ let n = t[2].replace(this.rules.other.newLineCharGlobal, " "), r = this.rules.other.nonSpaceChar.test(n), i = this.rules.other.startingSpaceChar.test(n) && this.rules.other.endingSpaceChar.test(n);
409
+ return r && i && (n = n.substring(1, n.length - 1)), { type: "codespan", raw: t[0], text: n };
410
+ }
411
+ }
412
+ br(e) {
413
+ let t = this.rules.inline.br.exec(e);
414
+ if (t) return { type: "br", raw: t[0] };
415
+ }
416
+ del(e) {
417
+ let t = this.rules.inline.del.exec(e);
418
+ if (t) return { type: "del", raw: t[0], text: t[2], tokens: this.lexer.inlineTokens(t[2]) };
419
+ }
420
+ autolink(e) {
421
+ let t = this.rules.inline.autolink.exec(e);
422
+ if (t) {
423
+ let n, r;
424
+ return t[2] === "@" ? (n = t[1], r = "mailto:" + n) : (n = t[1], r = n), { type: "link", raw: t[0], text: n, href: r, tokens: [{ type: "text", raw: n, text: n }] };
425
+ }
426
+ }
427
+ url(e) {
428
+ let t;
429
+ if (t = this.rules.inline.url.exec(e)) {
430
+ let n, r;
431
+ if (t[2] === "@") n = t[0], r = "mailto:" + n;
432
+ else {
433
+ let i;
434
+ do
435
+ i = t[0], t[0] = this.rules.inline._backpedal.exec(t[0])?.[0] ?? "";
436
+ while (i !== t[0]);
437
+ n = t[0], t[1] === "www." ? r = "http://" + t[0] : r = t[0];
438
+ }
439
+ return { type: "link", raw: t[0], text: n, href: r, tokens: [{ type: "text", raw: n, text: n }] };
440
+ }
441
+ }
442
+ inlineText(e) {
443
+ let t = this.rules.inline.text.exec(e);
444
+ if (t) {
445
+ let n = this.lexer.state.inRawBlock;
446
+ return { type: "text", raw: t[0], text: t[0], escaped: n };
447
+ }
448
+ }
449
+ };
450
+ var x = class u {
451
+ tokens;
452
+ options;
453
+ state;
454
+ inlineQueue;
455
+ tokenizer;
456
+ constructor(e) {
457
+ this.tokens = [], this.tokens.links = /* @__PURE__ */ Object.create(null), this.options = e || T, this.options.tokenizer = this.options.tokenizer || new y(), this.tokenizer = this.options.tokenizer, this.tokenizer.options = this.options, this.tokenizer.lexer = this, this.inlineQueue = [], this.state = { inLink: false, inRawBlock: false, top: true };
458
+ let t = { other: m, block: E.normal, inline: M.normal };
459
+ this.options.pedantic ? (t.block = E.pedantic, t.inline = M.pedantic) : this.options.gfm && (t.block = E.gfm, this.options.breaks ? t.inline = M.breaks : t.inline = M.gfm), this.tokenizer.rules = t;
460
+ }
461
+ static get rules() {
462
+ return { block: E, inline: M };
463
+ }
464
+ static lex(e, t) {
465
+ return new u(t).lex(e);
466
+ }
467
+ static lexInline(e, t) {
468
+ return new u(t).inlineTokens(e);
469
+ }
470
+ lex(e) {
471
+ e = e.replace(m.carriageReturn, `
472
+ `), this.blockTokens(e, this.tokens);
473
+ for (let t = 0; t < this.inlineQueue.length; t++) {
474
+ let n = this.inlineQueue[t];
475
+ this.inlineTokens(n.src, n.tokens);
476
+ }
477
+ return this.inlineQueue = [], this.tokens;
478
+ }
479
+ blockTokens(e, t = [], n = false) {
480
+ for (this.options.pedantic && (e = e.replace(m.tabCharGlobal, " ").replace(m.spaceLine, "")); e; ) {
481
+ let r;
482
+ if (this.options.extensions?.block?.some((s) => (r = s.call({ lexer: this }, e, t)) ? (e = e.substring(r.raw.length), t.push(r), true) : false)) continue;
483
+ if (r = this.tokenizer.space(e)) {
484
+ e = e.substring(r.raw.length);
485
+ let s = t.at(-1);
486
+ r.raw.length === 1 && s !== void 0 ? s.raw += `
487
+ ` : t.push(r);
488
+ continue;
489
+ }
490
+ if (r = this.tokenizer.code(e)) {
491
+ e = e.substring(r.raw.length);
492
+ let s = t.at(-1);
493
+ s?.type === "paragraph" || s?.type === "text" ? (s.raw += (s.raw.endsWith(`
494
+ `) ? "" : `
495
+ `) + r.raw, s.text += `
496
+ ` + r.text, this.inlineQueue.at(-1).src = s.text) : t.push(r);
497
+ continue;
498
+ }
499
+ if (r = this.tokenizer.fences(e)) {
500
+ e = e.substring(r.raw.length), t.push(r);
501
+ continue;
502
+ }
503
+ if (r = this.tokenizer.heading(e)) {
504
+ e = e.substring(r.raw.length), t.push(r);
505
+ continue;
506
+ }
507
+ if (r = this.tokenizer.hr(e)) {
508
+ e = e.substring(r.raw.length), t.push(r);
509
+ continue;
510
+ }
511
+ if (r = this.tokenizer.blockquote(e)) {
512
+ e = e.substring(r.raw.length), t.push(r);
513
+ continue;
514
+ }
515
+ if (r = this.tokenizer.list(e)) {
516
+ e = e.substring(r.raw.length), t.push(r);
517
+ continue;
518
+ }
519
+ if (r = this.tokenizer.html(e)) {
520
+ e = e.substring(r.raw.length), t.push(r);
521
+ continue;
522
+ }
523
+ if (r = this.tokenizer.def(e)) {
524
+ e = e.substring(r.raw.length);
525
+ let s = t.at(-1);
526
+ s?.type === "paragraph" || s?.type === "text" ? (s.raw += (s.raw.endsWith(`
527
+ `) ? "" : `
528
+ `) + r.raw, s.text += `
529
+ ` + r.raw, this.inlineQueue.at(-1).src = s.text) : this.tokens.links[r.tag] || (this.tokens.links[r.tag] = { href: r.href, title: r.title }, t.push(r));
530
+ continue;
531
+ }
532
+ if (r = this.tokenizer.table(e)) {
533
+ e = e.substring(r.raw.length), t.push(r);
534
+ continue;
535
+ }
536
+ if (r = this.tokenizer.lheading(e)) {
537
+ e = e.substring(r.raw.length), t.push(r);
538
+ continue;
539
+ }
540
+ let i = e;
541
+ if (this.options.extensions?.startBlock) {
542
+ let s = 1 / 0, a = e.slice(1), o;
543
+ this.options.extensions.startBlock.forEach((l) => {
544
+ o = l.call({ lexer: this }, a), typeof o == "number" && o >= 0 && (s = Math.min(s, o));
545
+ }), s < 1 / 0 && s >= 0 && (i = e.substring(0, s + 1));
546
+ }
547
+ if (this.state.top && (r = this.tokenizer.paragraph(i))) {
548
+ let s = t.at(-1);
549
+ n && s?.type === "paragraph" ? (s.raw += (s.raw.endsWith(`
550
+ `) ? "" : `
551
+ `) + r.raw, s.text += `
552
+ ` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = s.text) : t.push(r), n = i.length !== e.length, e = e.substring(r.raw.length);
553
+ continue;
554
+ }
555
+ if (r = this.tokenizer.text(e)) {
556
+ e = e.substring(r.raw.length);
557
+ let s = t.at(-1);
558
+ s?.type === "text" ? (s.raw += (s.raw.endsWith(`
559
+ `) ? "" : `
560
+ `) + r.raw, s.text += `
561
+ ` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = s.text) : t.push(r);
562
+ continue;
563
+ }
564
+ if (e) {
565
+ let s = "Infinite loop on byte: " + e.charCodeAt(0);
566
+ if (this.options.silent) {
567
+ console.error(s);
568
+ break;
569
+ } else throw new Error(s);
570
+ }
571
+ }
572
+ return this.state.top = true, t;
573
+ }
574
+ inline(e, t = []) {
575
+ return this.inlineQueue.push({ src: e, tokens: t }), t;
576
+ }
577
+ inlineTokens(e, t = []) {
578
+ let n = e, r = null;
579
+ if (this.tokens.links) {
580
+ let o = Object.keys(this.tokens.links);
581
+ if (o.length > 0) for (; (r = this.tokenizer.rules.inline.reflinkSearch.exec(n)) != null; ) o.includes(r[0].slice(r[0].lastIndexOf("[") + 1, -1)) && (n = n.slice(0, r.index) + "[" + "a".repeat(r[0].length - 2) + "]" + n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex));
582
+ }
583
+ for (; (r = this.tokenizer.rules.inline.anyPunctuation.exec(n)) != null; ) n = n.slice(0, r.index) + "++" + n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
584
+ let i;
585
+ for (; (r = this.tokenizer.rules.inline.blockSkip.exec(n)) != null; ) i = r[2] ? r[2].length : 0, n = n.slice(0, r.index + i) + "[" + "a".repeat(r[0].length - i - 2) + "]" + n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
586
+ n = this.options.hooks?.emStrongMask?.call({ lexer: this }, n) ?? n;
587
+ let s = false, a = "";
588
+ for (; e; ) {
589
+ s || (a = ""), s = false;
590
+ let o;
591
+ if (this.options.extensions?.inline?.some((p) => (o = p.call({ lexer: this }, e, t)) ? (e = e.substring(o.raw.length), t.push(o), true) : false)) continue;
592
+ if (o = this.tokenizer.escape(e)) {
593
+ e = e.substring(o.raw.length), t.push(o);
594
+ continue;
595
+ }
596
+ if (o = this.tokenizer.tag(e)) {
597
+ e = e.substring(o.raw.length), t.push(o);
598
+ continue;
599
+ }
600
+ if (o = this.tokenizer.link(e)) {
601
+ e = e.substring(o.raw.length), t.push(o);
602
+ continue;
603
+ }
604
+ if (o = this.tokenizer.reflink(e, this.tokens.links)) {
605
+ e = e.substring(o.raw.length);
606
+ let p = t.at(-1);
607
+ o.type === "text" && p?.type === "text" ? (p.raw += o.raw, p.text += o.text) : t.push(o);
608
+ continue;
609
+ }
610
+ if (o = this.tokenizer.emStrong(e, n, a)) {
611
+ e = e.substring(o.raw.length), t.push(o);
612
+ continue;
613
+ }
614
+ if (o = this.tokenizer.codespan(e)) {
615
+ e = e.substring(o.raw.length), t.push(o);
616
+ continue;
617
+ }
618
+ if (o = this.tokenizer.br(e)) {
619
+ e = e.substring(o.raw.length), t.push(o);
620
+ continue;
621
+ }
622
+ if (o = this.tokenizer.del(e)) {
623
+ e = e.substring(o.raw.length), t.push(o);
624
+ continue;
625
+ }
626
+ if (o = this.tokenizer.autolink(e)) {
627
+ e = e.substring(o.raw.length), t.push(o);
628
+ continue;
629
+ }
630
+ if (!this.state.inLink && (o = this.tokenizer.url(e))) {
631
+ e = e.substring(o.raw.length), t.push(o);
632
+ continue;
633
+ }
634
+ let l = e;
635
+ if (this.options.extensions?.startInline) {
636
+ let p = 1 / 0, c = e.slice(1), g;
637
+ this.options.extensions.startInline.forEach((h) => {
638
+ g = h.call({ lexer: this }, c), typeof g == "number" && g >= 0 && (p = Math.min(p, g));
639
+ }), p < 1 / 0 && p >= 0 && (l = e.substring(0, p + 1));
640
+ }
641
+ if (o = this.tokenizer.inlineText(l)) {
642
+ e = e.substring(o.raw.length), o.raw.slice(-1) !== "_" && (a = o.raw.slice(-1)), s = true;
643
+ let p = t.at(-1);
644
+ p?.type === "text" ? (p.raw += o.raw, p.text += o.text) : t.push(o);
645
+ continue;
646
+ }
647
+ if (e) {
648
+ let p = "Infinite loop on byte: " + e.charCodeAt(0);
649
+ if (this.options.silent) {
650
+ console.error(p);
651
+ break;
652
+ } else throw new Error(p);
653
+ }
654
+ }
655
+ return t;
656
+ }
657
+ };
658
+ var P = class {
659
+ options;
660
+ parser;
661
+ constructor(e) {
662
+ this.options = e || T;
663
+ }
664
+ space(e) {
665
+ return "";
666
+ }
667
+ code({ text: e, lang: t, escaped: n }) {
668
+ let r = (t || "").match(m.notSpaceStart)?.[0], i = e.replace(m.endingNewline, "") + `
669
+ `;
670
+ return r ? '<pre><code class="language-' + w(r) + '">' + (n ? i : w(i, true)) + `</code></pre>
671
+ ` : "<pre><code>" + (n ? i : w(i, true)) + `</code></pre>
672
+ `;
673
+ }
674
+ blockquote({ tokens: e }) {
675
+ return `<blockquote>
676
+ ${this.parser.parse(e)}</blockquote>
677
+ `;
678
+ }
679
+ html({ text: e }) {
680
+ return e;
681
+ }
682
+ def(e) {
683
+ return "";
684
+ }
685
+ heading({ tokens: e, depth: t }) {
686
+ return `<h${t}>${this.parser.parseInline(e)}</h${t}>
687
+ `;
688
+ }
689
+ hr(e) {
690
+ return `<hr>
691
+ `;
692
+ }
693
+ list(e) {
694
+ let t = e.ordered, n = e.start, r = "";
695
+ for (let a = 0; a < e.items.length; a++) {
696
+ let o = e.items[a];
697
+ r += this.listitem(o);
698
+ }
699
+ let i = t ? "ol" : "ul", s = t && n !== 1 ? ' start="' + n + '"' : "";
700
+ return "<" + i + s + `>
701
+ ` + r + "</" + i + `>
702
+ `;
703
+ }
704
+ listitem(e) {
705
+ return `<li>${this.parser.parse(e.tokens)}</li>
706
+ `;
707
+ }
708
+ checkbox({ checked: e }) {
709
+ return "<input " + (e ? 'checked="" ' : "") + 'disabled="" type="checkbox"> ';
710
+ }
711
+ paragraph({ tokens: e }) {
712
+ return `<p>${this.parser.parseInline(e)}</p>
713
+ `;
714
+ }
715
+ table(e) {
716
+ let t = "", n = "";
717
+ for (let i = 0; i < e.header.length; i++) n += this.tablecell(e.header[i]);
718
+ t += this.tablerow({ text: n });
719
+ let r = "";
720
+ for (let i = 0; i < e.rows.length; i++) {
721
+ let s = e.rows[i];
722
+ n = "";
723
+ for (let a = 0; a < s.length; a++) n += this.tablecell(s[a]);
724
+ r += this.tablerow({ text: n });
725
+ }
726
+ return r && (r = `<tbody>${r}</tbody>`), `<table>
727
+ <thead>
728
+ ` + t + `</thead>
729
+ ` + r + `</table>
730
+ `;
731
+ }
732
+ tablerow({ text: e }) {
733
+ return `<tr>
734
+ ${e}</tr>
735
+ `;
736
+ }
737
+ tablecell(e) {
738
+ let t = this.parser.parseInline(e.tokens), n = e.header ? "th" : "td";
739
+ return (e.align ? `<${n} align="${e.align}">` : `<${n}>`) + t + `</${n}>
740
+ `;
741
+ }
742
+ strong({ tokens: e }) {
743
+ return `<strong>${this.parser.parseInline(e)}</strong>`;
744
+ }
745
+ em({ tokens: e }) {
746
+ return `<em>${this.parser.parseInline(e)}</em>`;
747
+ }
748
+ codespan({ text: e }) {
749
+ return `<code>${w(e, true)}</code>`;
750
+ }
751
+ br(e) {
752
+ return "<br>";
753
+ }
754
+ del({ tokens: e }) {
755
+ return `<del>${this.parser.parseInline(e)}</del>`;
756
+ }
757
+ link({ href: e, title: t, tokens: n }) {
758
+ let r = this.parser.parseInline(n), i = X(e);
759
+ if (i === null) return r;
760
+ e = i;
761
+ let s = '<a href="' + e + '"';
762
+ return t && (s += ' title="' + w(t) + '"'), s += ">" + r + "</a>", s;
763
+ }
764
+ image({ href: e, title: t, text: n, tokens: r }) {
765
+ r && (n = this.parser.parseInline(r, this.parser.textRenderer));
766
+ let i = X(e);
767
+ if (i === null) return w(n);
768
+ e = i;
769
+ let s = `<img src="${e}" alt="${n}"`;
770
+ return t && (s += ` title="${w(t)}"`), s += ">", s;
771
+ }
772
+ text(e) {
773
+ return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : "escaped" in e && e.escaped ? e.text : w(e.text);
774
+ }
775
+ };
776
+ var $ = class {
777
+ strong({ text: e }) {
778
+ return e;
779
+ }
780
+ em({ text: e }) {
781
+ return e;
782
+ }
783
+ codespan({ text: e }) {
784
+ return e;
785
+ }
786
+ del({ text: e }) {
787
+ return e;
788
+ }
789
+ html({ text: e }) {
790
+ return e;
791
+ }
792
+ text({ text: e }) {
793
+ return e;
794
+ }
795
+ link({ text: e }) {
796
+ return "" + e;
797
+ }
798
+ image({ text: e }) {
799
+ return "" + e;
800
+ }
801
+ br() {
802
+ return "";
803
+ }
804
+ checkbox({ raw: e }) {
805
+ return e;
806
+ }
807
+ };
808
+ var b = class u2 {
809
+ options;
810
+ renderer;
811
+ textRenderer;
812
+ constructor(e) {
813
+ this.options = e || T, this.options.renderer = this.options.renderer || new P(), this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new $();
814
+ }
815
+ static parse(e, t) {
816
+ return new u2(t).parse(e);
817
+ }
818
+ static parseInline(e, t) {
819
+ return new u2(t).parseInline(e);
820
+ }
821
+ parse(e) {
822
+ let t = "";
823
+ for (let n = 0; n < e.length; n++) {
824
+ let r = e[n];
825
+ if (this.options.extensions?.renderers?.[r.type]) {
826
+ let s = r, a = this.options.extensions.renderers[s.type].call({ parser: this }, s);
827
+ if (a !== false || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "def", "paragraph", "text"].includes(s.type)) {
828
+ t += a || "";
829
+ continue;
830
+ }
831
+ }
832
+ let i = r;
833
+ switch (i.type) {
834
+ case "space": {
835
+ t += this.renderer.space(i);
836
+ break;
837
+ }
838
+ case "hr": {
839
+ t += this.renderer.hr(i);
840
+ break;
841
+ }
842
+ case "heading": {
843
+ t += this.renderer.heading(i);
844
+ break;
845
+ }
846
+ case "code": {
847
+ t += this.renderer.code(i);
848
+ break;
849
+ }
850
+ case "table": {
851
+ t += this.renderer.table(i);
852
+ break;
853
+ }
854
+ case "blockquote": {
855
+ t += this.renderer.blockquote(i);
856
+ break;
857
+ }
858
+ case "list": {
859
+ t += this.renderer.list(i);
860
+ break;
861
+ }
862
+ case "checkbox": {
863
+ t += this.renderer.checkbox(i);
864
+ break;
865
+ }
866
+ case "html": {
867
+ t += this.renderer.html(i);
868
+ break;
869
+ }
870
+ case "def": {
871
+ t += this.renderer.def(i);
872
+ break;
873
+ }
874
+ case "paragraph": {
875
+ t += this.renderer.paragraph(i);
876
+ break;
877
+ }
878
+ case "text": {
879
+ t += this.renderer.text(i);
880
+ break;
881
+ }
882
+ default: {
883
+ let s = 'Token with "' + i.type + '" type was not found.';
884
+ if (this.options.silent) return console.error(s), "";
885
+ throw new Error(s);
886
+ }
887
+ }
888
+ }
889
+ return t;
890
+ }
891
+ parseInline(e, t = this.renderer) {
892
+ let n = "";
893
+ for (let r = 0; r < e.length; r++) {
894
+ let i = e[r];
895
+ if (this.options.extensions?.renderers?.[i.type]) {
896
+ let a = this.options.extensions.renderers[i.type].call({ parser: this }, i);
897
+ if (a !== false || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(i.type)) {
898
+ n += a || "";
899
+ continue;
900
+ }
901
+ }
902
+ let s = i;
903
+ switch (s.type) {
904
+ case "escape": {
905
+ n += t.text(s);
906
+ break;
907
+ }
908
+ case "html": {
909
+ n += t.html(s);
910
+ break;
911
+ }
912
+ case "link": {
913
+ n += t.link(s);
914
+ break;
915
+ }
916
+ case "image": {
917
+ n += t.image(s);
918
+ break;
919
+ }
920
+ case "checkbox": {
921
+ n += t.checkbox(s);
922
+ break;
923
+ }
924
+ case "strong": {
925
+ n += t.strong(s);
926
+ break;
927
+ }
928
+ case "em": {
929
+ n += t.em(s);
930
+ break;
931
+ }
932
+ case "codespan": {
933
+ n += t.codespan(s);
934
+ break;
935
+ }
936
+ case "br": {
937
+ n += t.br(s);
938
+ break;
939
+ }
940
+ case "del": {
941
+ n += t.del(s);
942
+ break;
943
+ }
944
+ case "text": {
945
+ n += t.text(s);
946
+ break;
947
+ }
948
+ default: {
949
+ let a = 'Token with "' + s.type + '" type was not found.';
950
+ if (this.options.silent) return console.error(a), "";
951
+ throw new Error(a);
952
+ }
953
+ }
954
+ }
955
+ return n;
956
+ }
957
+ };
958
+ var S = class {
959
+ options;
960
+ block;
961
+ constructor(e) {
962
+ this.options = e || T;
963
+ }
964
+ static passThroughHooks = /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens", "emStrongMask"]);
965
+ static passThroughHooksRespectAsync = /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens"]);
966
+ preprocess(e) {
967
+ return e;
968
+ }
969
+ postprocess(e) {
970
+ return e;
971
+ }
972
+ processAllTokens(e) {
973
+ return e;
974
+ }
975
+ emStrongMask(e) {
976
+ return e;
977
+ }
978
+ provideLexer() {
979
+ return this.block ? x.lex : x.lexInline;
980
+ }
981
+ provideParser() {
982
+ return this.block ? b.parse : b.parseInline;
983
+ }
984
+ };
985
+ var B = class {
986
+ defaults = L();
987
+ options = this.setOptions;
988
+ parse = this.parseMarkdown(true);
989
+ parseInline = this.parseMarkdown(false);
990
+ Parser = b;
991
+ Renderer = P;
992
+ TextRenderer = $;
993
+ Lexer = x;
994
+ Tokenizer = y;
995
+ Hooks = S;
996
+ constructor(...e) {
997
+ this.use(...e);
998
+ }
999
+ walkTokens(e, t) {
1000
+ let n = [];
1001
+ for (let r of e) switch (n = n.concat(t.call(this, r)), r.type) {
1002
+ case "table": {
1003
+ let i = r;
1004
+ for (let s of i.header) n = n.concat(this.walkTokens(s.tokens, t));
1005
+ for (let s of i.rows) for (let a of s) n = n.concat(this.walkTokens(a.tokens, t));
1006
+ break;
1007
+ }
1008
+ case "list": {
1009
+ let i = r;
1010
+ n = n.concat(this.walkTokens(i.items, t));
1011
+ break;
1012
+ }
1013
+ default: {
1014
+ let i = r;
1015
+ this.defaults.extensions?.childTokens?.[i.type] ? this.defaults.extensions.childTokens[i.type].forEach((s) => {
1016
+ let a = i[s].flat(1 / 0);
1017
+ n = n.concat(this.walkTokens(a, t));
1018
+ }) : i.tokens && (n = n.concat(this.walkTokens(i.tokens, t)));
1019
+ }
1020
+ }
1021
+ return n;
1022
+ }
1023
+ use(...e) {
1024
+ let t = this.defaults.extensions || { renderers: {}, childTokens: {} };
1025
+ return e.forEach((n) => {
1026
+ let r = { ...n };
1027
+ if (r.async = this.defaults.async || r.async || false, n.extensions && (n.extensions.forEach((i) => {
1028
+ if (!i.name) throw new Error("extension name required");
1029
+ if ("renderer" in i) {
1030
+ let s = t.renderers[i.name];
1031
+ s ? t.renderers[i.name] = function(...a) {
1032
+ let o = i.renderer.apply(this, a);
1033
+ return o === false && (o = s.apply(this, a)), o;
1034
+ } : t.renderers[i.name] = i.renderer;
1035
+ }
1036
+ if ("tokenizer" in i) {
1037
+ if (!i.level || i.level !== "block" && i.level !== "inline") throw new Error("extension level must be 'block' or 'inline'");
1038
+ let s = t[i.level];
1039
+ s ? s.unshift(i.tokenizer) : t[i.level] = [i.tokenizer], i.start && (i.level === "block" ? t.startBlock ? t.startBlock.push(i.start) : t.startBlock = [i.start] : i.level === "inline" && (t.startInline ? t.startInline.push(i.start) : t.startInline = [i.start]));
1040
+ }
1041
+ "childTokens" in i && i.childTokens && (t.childTokens[i.name] = i.childTokens);
1042
+ }), r.extensions = t), n.renderer) {
1043
+ let i = this.defaults.renderer || new P(this.defaults);
1044
+ for (let s in n.renderer) {
1045
+ if (!(s in i)) throw new Error(`renderer '${s}' does not exist`);
1046
+ if (["options", "parser"].includes(s)) continue;
1047
+ let a = s, o = n.renderer[a], l = i[a];
1048
+ i[a] = (...p) => {
1049
+ let c = o.apply(i, p);
1050
+ return c === false && (c = l.apply(i, p)), c || "";
1051
+ };
1052
+ }
1053
+ r.renderer = i;
1054
+ }
1055
+ if (n.tokenizer) {
1056
+ let i = this.defaults.tokenizer || new y(this.defaults);
1057
+ for (let s in n.tokenizer) {
1058
+ if (!(s in i)) throw new Error(`tokenizer '${s}' does not exist`);
1059
+ if (["options", "rules", "lexer"].includes(s)) continue;
1060
+ let a = s, o = n.tokenizer[a], l = i[a];
1061
+ i[a] = (...p) => {
1062
+ let c = o.apply(i, p);
1063
+ return c === false && (c = l.apply(i, p)), c;
1064
+ };
1065
+ }
1066
+ r.tokenizer = i;
1067
+ }
1068
+ if (n.hooks) {
1069
+ let i = this.defaults.hooks || new S();
1070
+ for (let s in n.hooks) {
1071
+ if (!(s in i)) throw new Error(`hook '${s}' does not exist`);
1072
+ if (["options", "block"].includes(s)) continue;
1073
+ let a = s, o = n.hooks[a], l = i[a];
1074
+ S.passThroughHooks.has(s) ? i[a] = (p) => {
1075
+ if (this.defaults.async && S.passThroughHooksRespectAsync.has(s)) return (async () => {
1076
+ let g = await o.call(i, p);
1077
+ return l.call(i, g);
1078
+ })();
1079
+ let c = o.call(i, p);
1080
+ return l.call(i, c);
1081
+ } : i[a] = (...p) => {
1082
+ if (this.defaults.async) return (async () => {
1083
+ let g = await o.apply(i, p);
1084
+ return g === false && (g = await l.apply(i, p)), g;
1085
+ })();
1086
+ let c = o.apply(i, p);
1087
+ return c === false && (c = l.apply(i, p)), c;
1088
+ };
1089
+ }
1090
+ r.hooks = i;
1091
+ }
1092
+ if (n.walkTokens) {
1093
+ let i = this.defaults.walkTokens, s = n.walkTokens;
1094
+ r.walkTokens = function(a) {
1095
+ let o = [];
1096
+ return o.push(s.call(this, a)), i && (o = o.concat(i.call(this, a))), o;
1097
+ };
1098
+ }
1099
+ this.defaults = { ...this.defaults, ...r };
1100
+ }), this;
1101
+ }
1102
+ setOptions(e) {
1103
+ return this.defaults = { ...this.defaults, ...e }, this;
1104
+ }
1105
+ lexer(e, t) {
1106
+ return x.lex(e, t ?? this.defaults);
1107
+ }
1108
+ parser(e, t) {
1109
+ return b.parse(e, t ?? this.defaults);
1110
+ }
1111
+ parseMarkdown(e) {
1112
+ return (n, r) => {
1113
+ let i = { ...r }, s = { ...this.defaults, ...i }, a = this.onError(!!s.silent, !!s.async);
1114
+ if (this.defaults.async === true && i.async === false) 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."));
1115
+ if (typeof n > "u" || n === null) return a(new Error("marked(): input parameter is undefined or null"));
1116
+ if (typeof n != "string") return a(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(n) + ", string expected"));
1117
+ if (s.hooks && (s.hooks.options = s, s.hooks.block = e), s.async) return (async () => {
1118
+ let o = s.hooks ? await s.hooks.preprocess(n) : n, p = await (s.hooks ? await s.hooks.provideLexer() : e ? x.lex : x.lexInline)(o, s), c = s.hooks ? await s.hooks.processAllTokens(p) : p;
1119
+ s.walkTokens && await Promise.all(this.walkTokens(c, s.walkTokens));
1120
+ let h = await (s.hooks ? await s.hooks.provideParser() : e ? b.parse : b.parseInline)(c, s);
1121
+ return s.hooks ? await s.hooks.postprocess(h) : h;
1122
+ })().catch(a);
1123
+ try {
1124
+ s.hooks && (n = s.hooks.preprocess(n));
1125
+ let l = (s.hooks ? s.hooks.provideLexer() : e ? x.lex : x.lexInline)(n, s);
1126
+ s.hooks && (l = s.hooks.processAllTokens(l)), s.walkTokens && this.walkTokens(l, s.walkTokens);
1127
+ let c = (s.hooks ? s.hooks.provideParser() : e ? b.parse : b.parseInline)(l, s);
1128
+ return s.hooks && (c = s.hooks.postprocess(c)), c;
1129
+ } catch (o) {
1130
+ return a(o);
1131
+ }
1132
+ };
1133
+ }
1134
+ onError(e, t) {
1135
+ return (n) => {
1136
+ if (n.message += `
1137
+ Please report this to https://github.com/markedjs/marked.`, e) {
1138
+ let r = "<p>An error occurred:</p><pre>" + w(n.message + "", true) + "</pre>";
1139
+ return t ? Promise.resolve(r) : r;
1140
+ }
1141
+ if (t) return Promise.reject(n);
1142
+ throw n;
1143
+ };
1144
+ }
1145
+ };
1146
+ var _ = new B();
1147
+ function d(u3, e) {
1148
+ return _.parse(u3, e);
1149
+ }
1150
+ d.options = d.setOptions = function(u3) {
1151
+ return _.setOptions(u3), d.defaults = _.defaults, Z(d.defaults), d;
1152
+ };
1153
+ d.getDefaults = L;
1154
+ d.defaults = T;
1155
+ d.use = function(...u3) {
1156
+ return _.use(...u3), d.defaults = _.defaults, Z(d.defaults), d;
1157
+ };
1158
+ d.walkTokens = function(u3, e) {
1159
+ return _.walkTokens(u3, e);
1160
+ };
1161
+ d.parseInline = _.parseInline;
1162
+ d.Parser = b;
1163
+ d.parser = b.parse;
1164
+ d.Renderer = P;
1165
+ d.TextRenderer = $;
1166
+ d.Lexer = x;
1167
+ d.lexer = x.lex;
1168
+ d.Tokenizer = y;
1169
+ d.Hooks = S;
1170
+ d.parse = d;
1171
+ var Dt = d.options;
1172
+ var Ht = d.setOptions;
1173
+ var Zt = d.use;
1174
+ var Gt = d.walkTokens;
1175
+ var Nt = d.parseInline;
1176
+ var Ft = b.parse;
1177
+ var jt = x.lex;
1178
+
1179
+ // src/chatbot.js
1180
+ var AdvaisorChatBot = class extends HTMLElement {
1181
+ constructor() {
1182
+ super();
1183
+ this.attachShadow({ mode: "open" });
1184
+ this.isOpen = false;
1185
+ }
1186
+ connectedCallback() {
1187
+ this.apiEndpoint = this.getAttribute("api_endpoint") || "https://silicore.ai:2002/cds_bookshelves/ask_all_bookshelves";
1188
+ this.userName = this.getAttribute("user_name") || "Guest";
1189
+ this.token = this.getAttribute("token") || null;
1190
+ this.render();
1191
+ }
1192
+ render() {
1193
+ this.shadowRoot.innerHTML = `
1194
+ <style>
1195
+ :host {
1196
+ --primary-color: #EC9588;
1197
+ --user-bubble: #f29b8c;
1198
+ --bot-bubble: #e5e7eb;
1199
+ font-family: system-ui, -apple-system, sans-serif;
1200
+ }
1201
+
1202
+ .chat-trigger {
1203
+ position: fixed;
1204
+ bottom: 20px;
1205
+ right: 20px;
1206
+ z-index: 9999;
1207
+ height: 56px;
1208
+ width: 56px;
1209
+ border-radius: 50%;
1210
+ background: var(--primary-color);
1211
+ color: white;
1212
+ display: flex;
1213
+ align-items: center;
1214
+ justify-content: center;
1215
+ box-shadow: 0 4px 12px rgba(0,0,0,0.15);
1216
+ font-size: 24px;
1217
+ cursor: pointer;
1218
+ transition: transform 0.2s;
1219
+ border: none;
1220
+ }
1221
+
1222
+ .chat-trigger:hover { transform: scale(1.05); }
1223
+
1224
+ .chat-window {
1225
+ resize: both;
1226
+ position: fixed;
1227
+ bottom: 20px;
1228
+ right: 20px;
1229
+ z-index: 10000;
1230
+ display: none;
1231
+ flex-direction: column;
1232
+ background: white;
1233
+ box-shadow: 0 10px 25px rgba(0,0,0,0.2);
1234
+ border-radius: 12px;
1235
+ width: 400px;
1236
+ max-width: 90vw;
1237
+ height: 600px;
1238
+ overflow: hidden;
1239
+ min-width: 280px;
1240
+ min-height: 350px;
1241
+ transition: width 0.2s ease, height 0.2s ease;
1242
+ }
1243
+
1244
+ .chat-body {
1245
+ flex: 1;
1246
+ overflow-y: auto;
1247
+ overflow-x: hidden;
1248
+ }
1249
+
1250
+ .message {
1251
+ word-wrap: break-word;
1252
+ overflow-wrap: break-word;
1253
+ }
1254
+
1255
+ .message pre,
1256
+ .message code {
1257
+ white-space: pre-wrap;
1258
+ word-break: break-word;
1259
+ }
1260
+
1261
+ .header {
1262
+ background: var(--primary-color);
1263
+ padding: 12px 16px;
1264
+ color: white;
1265
+ display: flex;
1266
+ justify-content: space-between;
1267
+ align-items: center;
1268
+ }
1269
+
1270
+ .close-btn { background: none; border: none; color: white; cursor: pointer; font-size: 18px; }
1271
+
1272
+ .chat-body {
1273
+ flex: 1;
1274
+ padding: 16px;
1275
+ overflow-y: auto;
1276
+ background: #f9fafb;
1277
+ display: flex;
1278
+ flex-direction: column;
1279
+ gap: 12px;
1280
+ }
1281
+
1282
+ .message {
1283
+ max-width: 75%;
1284
+ padding: 8px 16px;
1285
+ border-radius: 12px;
1286
+ font-size: 15px;
1287
+ line-height: 1.5;
1288
+ }
1289
+
1290
+ .bot { align-self: flex-start; background: var(--bot-bubble); color: #1f2937; }
1291
+ .user { align-self: flex-end; background: var(--user-bubble); color: white; }
1292
+
1293
+ .input-area {
1294
+ border-top: 1px solid #e5e7eb;
1295
+ padding: 12px;
1296
+ display: flex;
1297
+ gap: 8px;
1298
+ }
1299
+
1300
+ input {
1301
+ flex: 1;
1302
+ border: 1px solid #e5e7eb;
1303
+ border-radius: 6px;
1304
+ padding: 8px 12px;
1305
+ outline: none;
1306
+ }
1307
+
1308
+ input:focus { border-color: var(--primary-color); }
1309
+
1310
+ .send-btn {
1311
+ background: var(--user-bubble);
1312
+ color: white;
1313
+ border: none;
1314
+ padding: 0 16px;
1315
+ border-radius: 6px;
1316
+ cursor: pointer;
1317
+ }
1318
+
1319
+
1320
+ .resize-btn {
1321
+ background: none;
1322
+ border: none;
1323
+ color: white;
1324
+ cursor: pointer;
1325
+ font-size: 16px;
1326
+ }
1327
+
1328
+
1329
+ .chat-window.expanded {
1330
+ width: min(700px, 90vw);
1331
+ height: 90vh;
1332
+ }
1333
+
1334
+ .typing {
1335
+ display: flex;
1336
+ gap: 4px;
1337
+ align-items: center;
1338
+ }
1339
+
1340
+ .typing span {
1341
+ width: 6px;
1342
+ height: 6px;
1343
+ background: #999;
1344
+ border-radius: 50%;
1345
+ animation: blink 1.4s infinite;
1346
+ }
1347
+
1348
+ .typing span:nth-child(2) { animation-delay: 0.2s; }
1349
+ .typing span:nth-child(3) { animation-delay: 0.4s; }
1350
+
1351
+ @keyframes blink {
1352
+ 0%, 80%, 100% { opacity: 0.2; transform: scale(1); }
1353
+ 40% { opacity: 1; transform: scale(1.3); }
1354
+ }
1355
+
1356
+ .send-btn:disabled {
1357
+ opacity: 0.6;
1358
+ cursor: not-allowed;
1359
+ }
1360
+
1361
+ .header {
1362
+ cursor: move;
1363
+ user-select: none;
1364
+ }
1365
+ </style>
1366
+
1367
+ <button class="chat-trigger" id="trigger">\u{1F4AC}</button>
1368
+
1369
+ <div class="chat-window" id="window">
1370
+ <div class="header">
1371
+ <div>
1372
+ <div style="font-weight: 600;">advAIsor</div>
1373
+ <div style="font-size: 11px; opacity: 0.9;">AI Bot</div>
1374
+ </div>
1375
+
1376
+ <div style="display:flex; gap:8px;">
1377
+ <button class="resize-btn" id="resize">\u26F6</button>
1378
+ <button class="close-btn" id="close">\u2715</button>
1379
+ </div>
1380
+ </div>
1381
+
1382
+ <div class="chat-body" id="body">
1383
+ <div class="message bot">Hi ${this.userName}! How can I help?</div>
1384
+ </div>
1385
+
1386
+ <div class="input-area">
1387
+ <input type="text" id="input" placeholder="Ask something...">
1388
+ <button class="send-btn" id="send">Send</button>
1389
+ </div>
1390
+ </div>
1391
+ `;
1392
+ this.setupEventListeners();
1393
+ }
1394
+ setupEventListeners() {
1395
+ const trigger = this.shadowRoot.getElementById("trigger");
1396
+ const windowEl = this.shadowRoot.getElementById("window");
1397
+ const closeBtn = this.shadowRoot.getElementById("close");
1398
+ const sendBtn = this.shadowRoot.getElementById("send");
1399
+ const input = this.shadowRoot.getElementById("input");
1400
+ const body = this.shadowRoot.getElementById("body");
1401
+ trigger.onclick = () => {
1402
+ windowEl.style.display = "flex";
1403
+ trigger.style.display = "none";
1404
+ body.scrollTop = body.scrollHeight;
1405
+ };
1406
+ closeBtn.onclick = () => {
1407
+ windowEl.style.display = "none";
1408
+ trigger.style.display = "flex";
1409
+ };
1410
+ const resizeBtn = this.shadowRoot.getElementById("resize");
1411
+ resizeBtn.onclick = () => {
1412
+ windowEl.style.width = "";
1413
+ windowEl.style.height = "";
1414
+ windowEl.classList.toggle("expanded");
1415
+ resizeBtn.textContent = windowEl.classList.contains("expanded") ? "\u{1F5D7}" : "\u26F6";
1416
+ };
1417
+ const sendMessage = async () => {
1418
+ const text = input.value.trim();
1419
+ if (!text) return;
1420
+ input.disabled = true;
1421
+ sendBtn.disabled = true;
1422
+ const userMsg = document.createElement("div");
1423
+ userMsg.className = "message user";
1424
+ userMsg.textContent = text;
1425
+ body.appendChild(userMsg);
1426
+ input.value = "";
1427
+ body.scrollTop = body.scrollHeight;
1428
+ const typingDiv = document.createElement("div");
1429
+ typingDiv.className = "message bot";
1430
+ typingDiv.id = "typing-indicator";
1431
+ typingDiv.innerHTML = `
1432
+ <div class="typing">
1433
+ <span></span><span></span><span></span>
1434
+ </div>
1435
+ `;
1436
+ body.appendChild(typingDiv);
1437
+ body.scrollTop = body.scrollHeight;
1438
+ function fixMarkdown(text2) {
1439
+ return text2.replace(/}```/g, "}\n```").replace(/```(\S)/g, "```\n$1");
1440
+ }
1441
+ try {
1442
+ const res = await fetch(this.apiEndpoint, {
1443
+ method: "POST",
1444
+ headers: {
1445
+ "Content-Type": "application/json",
1446
+ "Authorization": `Bearer ${this.token}`
1447
+ },
1448
+ body: JSON.stringify({
1449
+ question: text,
1450
+ pdf_name: "All Bookshelves",
1451
+ session_id: null,
1452
+ bookshelf_name: "All Bookshelves",
1453
+ package_id: 30,
1454
+ user_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
1455
+ })
1456
+ });
1457
+ const response = await res.json();
1458
+ typingDiv.remove();
1459
+ const botReply = response?.answer || "No response received.";
1460
+ d.setOptions({
1461
+ breaks: true,
1462
+ gfm: true
1463
+ });
1464
+ const cleanReply = fixMarkdown(botReply);
1465
+ const htmlReply = d.parse(cleanReply);
1466
+ const wrapper = document.createElement("div");
1467
+ wrapper.className = "message bot";
1468
+ wrapper.innerHTML = htmlReply;
1469
+ body.appendChild(wrapper);
1470
+ body.scrollTop = body.scrollHeight;
1471
+ } catch (error) {
1472
+ typingDiv.remove();
1473
+ const errorMsg = document.createElement("div");
1474
+ errorMsg.className = "message bot";
1475
+ errorMsg.textContent = "Sorry, something went wrong.";
1476
+ body.appendChild(errorMsg);
1477
+ console.error(error);
1478
+ } finally {
1479
+ input.disabled = false;
1480
+ sendBtn.disabled = false;
1481
+ input.focus();
1482
+ }
1483
+ };
1484
+ sendBtn.onclick = sendMessage;
1485
+ input.onkeydown = (e) => {
1486
+ if (e.key === "Enter") sendMessage();
1487
+ };
1488
+ const header = this.shadowRoot.querySelector(".header");
1489
+ let isDragging = false;
1490
+ let offsetX = 0;
1491
+ let offsetY = 0;
1492
+ header.addEventListener("mousedown", (e) => {
1493
+ isDragging = true;
1494
+ const rect = windowEl.getBoundingClientRect();
1495
+ offsetX = e.clientX - rect.left;
1496
+ offsetY = e.clientY - rect.top;
1497
+ windowEl.style.right = "auto";
1498
+ windowEl.style.bottom = "auto";
1499
+ windowEl.style.left = rect.left + "px";
1500
+ windowEl.style.top = rect.top + "px";
1501
+ });
1502
+ document.addEventListener("mousemove", (e) => {
1503
+ if (!isDragging) return;
1504
+ let x2 = e.clientX - offsetX;
1505
+ let y2 = e.clientY - offsetY;
1506
+ const maxX = window.innerWidth - windowEl.offsetWidth;
1507
+ const maxY = window.innerHeight - windowEl.offsetHeight;
1508
+ x2 = Math.max(0, Math.min(x2, maxX));
1509
+ y2 = Math.max(0, Math.min(y2, maxY));
1510
+ windowEl.style.left = x2 + "px";
1511
+ windowEl.style.top = y2 + "px";
1512
+ });
1513
+ document.addEventListener("mouseup", () => {
1514
+ isDragging = false;
1515
+ });
1516
+ }
1517
+ };
1518
+ customElements.define("advaisor-chatbot", AdvaisorChatBot);
1519
+ })();